I just upgraded my Meteor app from 1.10.2 and noticed that it broke compilation of a file under node_modules
. It appears in the file cumsum.js
of d3-array
. This package is used by three.js
.
The error reported is:
=> Errors prevented startup:
While building for web.browser:
node_modules/d3-array/src/cumsum.js:4:15: Unexpected token (4:15)
=> Your application has errors. Waiting for file change.
The file is actually pretty short:
export default function cumsum(values, valueof) {
var sum = 0, index = 0;
return Float64Array.from(values, valueof === undefined
? v => (sum += +v || 0)
: v => (sum += +valueof(v, index++, values) || 0));
}
Line 4:15 refers to the “m” of the token sum
in the first line. How can this cause an error?!
I saw a couple of babel
updates between 1.10.1 and 2.2.1, might this be related here?
1 Like
Okay, that’s actually a bug in the Babel compiler that also affects TypeScript projects:
opened 06:09PM - 21 Jan 20 UTC
closed 07:46PM - 05 Aug 21 UTC
i: bug
pkg: parser
outdated
## Bug Report
- [x] I would like to work on a fix!
I have close to zero … experience with Babel's internals though. I would not be offended, if you think you can fix it yourself quicklier.
<!--
@babel/eslint-parser:
If you are having issues with JSX you might want to check out eslint-plugin-react. If there's an issue with new experimental syntax you might need check if it's supported by @babel/eslint-plugin.
-->
**Current Behavior**
The `typescript` preset is incompatible with [`d3-array/cumsum.js`](https://github.com/d3/d3-array/blob/master/src/cumsum.js). The issue seems to only occur for arrow functions using the `+=` operator, nested inside a ternary. When `typescript` is disabled, the code compiled without any issues.
**Input Code**
- Original broken `d3-array/cumsum.js`: [REPL](https://babeljs.io/en/repl#?browsers=&build=&builtIns=false&spec=false&loose=true&code_lz=KYDwDg9gTgLgBAE2AMwIYFcA29noHYDGMAlhHnAegLYDO1AFAG6qbrA0A0czrwEyASjgBvAFBxuqKHDpU4AXjgAGLsTxIQC5QG5xcKMBjoo5AGKYIqGADYALAEEoUVAE8AdMigQqTFm06SvPwK8or4SMhqwAh6EgD83AoAfHD0snAA1IoZjHAAPnnKArFwAFyJ8ilp1JnZPGz8TKrqoBkZXPXsQgVFAroAvkA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Ctypescript&prettier=true&targets=&version=7.8.3&externalPlugins=)
- Minimal reproduction: [REPL](https://babeljs.io/en/repl#?browsers=&build=&builtIns=false&spec=false&loose=true&code_lz=AwAg_CBuILwHwgBQGcCuBbEBqGUCUIAXFLAsANxA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Ctypescript&prettier=true&targets=&version=7.8.3&externalPlugins=)
```js
0 ? v => (sum += v) : v => 0;
```
> /repl.ts: Only '=' operator can be used for specifying default value. (1:13)
>
> > 1 | 0 ? v => (sum += v) : v => 0;
**Expected behavior/code**
Babel should compile the above code with `typescript` enabled.
opened 03:17PM - 01 Jun 20 UTC
closed 03:20PM - 01 Jun 20 UTC
When trying to transpile "d3-array" with babel 6 + babel-preset-react, babel fai… ls with a syntax error on "cumsum.js"
How to repeat:
Run:
npm install d3-array
npm install babel-cli
npm install babel-preset-react
node node_modules\babel-cli\bin\babel.js --presets babel-preset-react .\node_modules\d3-array\src\cumsum.js
Result:
```
SyntaxError: ./node_modules/d3-array/src/cumsum.js: Only '=' operator can be used for specifying default value. (4:15)
2 | var sum = 0, index = 0;
3 | return Float64Array.from(values, valueof === undefined
> 4 | ? v => (sum += +v || 0)
| ^
5 | : v => (sum += +valueof(v, index++, values) || 0));
6 | }
```
Omitting "--presets babel-preset-react" and transpiling with e.g. preset-env works:
npm install babel-preset-env
node node_modules\babel-cli\bin\babel.js --presets babel-preset-env .\node_modules\d3-array\src\cumsum.js
Results in:
```
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = cumsum;
function cumsum(values, valueof) {
var sum = 0,
index = 0;
return Float64Array.from(values, valueof === undefined ? function (v) {
return sum += +v || 0;
} : function (v) {
return sum += +valueof(v, index++, values) || 0;
});
}
```
1 Like
The best workaround I could find for the time being is to copy d3-array to a local folder, patch it and reference it from package.json
as described here:
opened 06:09PM - 21 Jan 20 UTC
closed 07:46PM - 05 Aug 21 UTC
i: bug
pkg: parser
outdated
## Bug Report
- [x] I would like to work on a fix!
I have close to zero … experience with Babel's internals though. I would not be offended, if you think you can fix it yourself quicklier.
<!--
@babel/eslint-parser:
If you are having issues with JSX you might want to check out eslint-plugin-react. If there's an issue with new experimental syntax you might need check if it's supported by @babel/eslint-plugin.
-->
**Current Behavior**
The `typescript` preset is incompatible with [`d3-array/cumsum.js`](https://github.com/d3/d3-array/blob/master/src/cumsum.js). The issue seems to only occur for arrow functions using the `+=` operator, nested inside a ternary. When `typescript` is disabled, the code compiled without any issues.
**Input Code**
- Original broken `d3-array/cumsum.js`: [REPL](https://babeljs.io/en/repl#?browsers=&build=&builtIns=false&spec=false&loose=true&code_lz=KYDwDg9gTgLgBAE2AMwIYFcA29noHYDGMAlhHnAegLYDO1AFAG6qbrA0A0czrwEyASjgBvAFBxuqKHDpU4AXjgAGLsTxIQC5QG5xcKMBjoo5AGKYIqGADYALAEEoUVAE8AdMigQqTFm06SvPwK8or4SMhqwAh6EgD83AoAfHD0snAA1IoZjHAAPnnKArFwAFyJ8ilp1JnZPGz8TKrqoBkZXPXsQgVFAroAvkA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Ctypescript&prettier=true&targets=&version=7.8.3&externalPlugins=)
- Minimal reproduction: [REPL](https://babeljs.io/en/repl#?browsers=&build=&builtIns=false&spec=false&loose=true&code_lz=AwAg_CBuILwHwgBQGcCuBbEBqGUCUIAXFLAsANxA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Ctypescript&prettier=true&targets=&version=7.8.3&externalPlugins=)
```js
0 ? v => (sum += v) : v => 0;
```
> /repl.ts: Only '=' operator can be used for specifying default value. (1:13)
>
> > 1 | 0 ? v => (sum += v) : v => 0;
**Expected behavior/code**
Babel should compile the above code with `typescript` enabled.
It’s weird, but it works. I hope the Babel project will release a fix soon.
1 Like
The question is: Does this also apply to ES6 projects? It’s referring to TypeScript.
I confirm it works for me with meteor@2.2.3.