Closed pygy closed 6 years ago
Using type
in import statements is also problematic:
Using the closure-compiler-js
(but AFAICT it is a core issue):
let compile = require("google-closure-compiler-js").compile;
console.log(compile({jsCode: [
{
path:"./foo.js",
src:"const type = 5; export {type};"
}, {
src:"import {type} from './foo.js';"
}
]});
gives
{ compiledCode: '',
errors:
[ { file: './foo.js',
description: 'Parse error. cannot use keyword \'type\' here.',
type: 'JSC_PARSE_ERROR',
lineNo: 1,
charNo: 24 },
{ file: 'Input_1',
description: 'Parse error. \'as\' expected',
type: 'JSC_PARSE_ERROR',
lineNo: 1,
charNo: 12 } ],
warnings: [] }
AFAIU, the bug is that we should warn only when the input language is ECMASCRIPT6_TYPED
.
@dimvar thanks for the repro, I'm not familiar with the Closure ecosystem. Here's an extended version with import {type}
as well.
We just ran into this trying to compile d3
ES6 from npm
.
import {namespace} from "d3-selection";
https://github.com/d3/d3-transition/blob/master/src/transition/attr.js#L2 https://github.com/d3/d3-transition/blob/master/src/transition/attrTween.js#L1
namespace
is another of those TypeScript only keywords.
https://github.com/google/closure-compiler/blob/424e341b5def61dac73ad39adb1b7c78ca9e9716/src/com/google/javascript/jscomp/parsing/parser/Keywords.java#L83-L87
Also hitting errors on TypeScript-specific keywords, in the same place as @thheller, when compiling D3. Example:
$ cat a.js
var namespace = 42;
export { namespace }
$ cat lint_6.json
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
}
}
$ eslint --no-eslintrc --config lint_6.json a.js
(no output)
$ java -jar target/closure-compiler-1.0-SNAPSHOT.jar a.js
a.js:3: ERROR - Parse error. cannot use keyword 'namespace' here.
export { namespace }
^
1 error(s), 0 warning(s)
It looks like this is fixed now? (If you put "Closes #xx" or "Fixes #xx" instead of "Addresses #xx" then Github should close it automatically.)
If there are other spots where we're treating TS keywords as though they were JS keywords, please file another bug for that.
type
is a valid ES6 identifier yet the Closure compiler will refuse to compile files that try to use it as a variable.It would be nice if the restriction was either lifted in ES6 input mode or at least documented. The docs currently say:Searching for "TypeScript" doesn't return any page that mentions the language.Edit: This bug may have a narrower scope than I initially thought... The problematic construct is
I'll check later today if there are other issues but right now I must leave.