I get a syntax error when I try to use the pipeline operator |> in a test file
How to reproduce
Create a new project with just 3 files in it:
test.js
import test from 'ava';
test('the code is transpiled', t => {
0 |> (x => x);
t.pass();
})
.babelrc
{
"plugins": [
[
"@babel/plugin-proposal-pipeline-operator",
{"proposal": "minimal"}
]
]
}
package.json
{
"type": "module",
"ava": {
"babel": true
},
"devDependencies": {
"@ava/babel": "^2.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.15.0",
"ava": "^3.15.0"
}
}
run npx ava:
$ npx ava
× No tests found in test.js
─
Uncaught exception in test.js
SyntaxError: Unexpected token '>'
─
1 uncaught exception
debugging
The problem can be "fixed" like so:
- remove
"type": "module" from package.json
- replace the
import by a require in the test file
ideas
It reminds me of this, from the @rollup/plugin-babel doc
When using @rollup/plugin-babel with @rollup/plugin-commonjs in the same Rollup configuration, it's important to note that @rollup/plugin-commonjs must be placed before this plugin in the plugins array for the two to work together properly. e.g.
import { babel } from '@rollup/> plugin-babel';
import commonjs from '@rollup/> plugin-commonjs';
const config = {
...
plugins: [
commonjs(),
babel({ babelHelpers: 'bundled' })
],
};
In a different project bundled with rollup, I had to place commonjs() after babel(), contrary what was recommended, because otherwise I would have got a syntax error for the pipeline operator, originating from @rollup/plugin-commonjs.
I get a syntax error when I try to use the pipeline operator
|>in a test fileHow to reproduce
Create a new project with just 3 files in it:
test.js
.babelrc
package.json
run
npx ava:debugging
The problem can be "fixed" like so:
"type": "module"from package.jsonimportby arequirein the test fileideas
It reminds me of this, from the @rollup/plugin-babel doc
In a different project bundled with rollup, I had to place
commonjs()afterbabel(), contrary what was recommended, because otherwise I would have got a syntax error for the pipeline operator, originating from@rollup/plugin-commonjs.