New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript keyword in ES6 export list causes a parse error #2005
Comments
Using Using the 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 |
@dimvar thanks for the repro, I'm not familiar with the Closure ecosystem. Here's an extended version with |
We just ran into this trying to compile
https://github.com/d3/d3-transition/blob/master/src/transition/attr.js#L2
closure-compiler/src/com/google/javascript/jscomp/parsing/parser/Keywords.java Lines 83 to 87 in 424e341
|
Also hitting errors on TypeScript-specific keywords, in the same place as @thheller, when compiling D3. Example: $ cat a.js
$ cat lint_6.json
$ eslint --no-eslintrc --config lint_6.json a.js
$ java -jar target/closure-compiler-1.0-SNAPSHOT.jar a.js
|
Default behavior forbids the use of TypeScript keywords in import and export statements: modify scanner to emit IdentifierTokens when parseTypeSyntax is false. Export decl parser coerces identifiers in exports to keywords: check there also. Addresses #2005 Closes #2835 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=188511416
Default behavior forbids the use of TypeScript keywords in import and export statements: modify scanner to emit IdentifierTokens when parseTypeSyntax is false. Export decl parser coerces identifiers in exports to keywords: check there also. Addresses google#2005 Closes google#2835 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=188511416
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.
The text was updated successfully, but these errors were encountered: