-
-
Notifications
You must be signed in to change notification settings - Fork 75
declare global causing parse errors #570
Comments
Probably more related to Here's the index file: https://github.com/milesj/beemo/blob/master/packages/core/src/index.ts#L17 And types file: https://github.com/milesj/beemo/blob/master/packages/core/src/types.ts#L62 |
@milesj this issue is in https://github.com/benmosher/eslint-plugin-import this plugin is not supporting typescript https://github.com/benmosher/eslint-plugin-import/issues?q=is%3Aopen+is%3Aissue+label%3Atypescript can you report this issue there? |
This was working before a recent parser upgrade though. Do you know exactly what changed that may have caused this? |
@milesj hmm i did some testing with plain eslint configuration, without your wrappers, on core package from your repository. And i was not able to reproduce this issue. {
"parser": "typescript-eslint-parser",
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module",
"jsx": true,
"useJSXTextNode": true
},
"env": {
"browser": true,
"node": true
},
"settings": {
"import/resolver": {
"node": {
"extensions": [
".js",
".jsx",
".ts",
".tsx"
]
}
}
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"plugins": [
"import",
"typescript"
],
"rules": {
"no-unused-vars": "off",
"no-undef": "off",
"import/export": "error"
}
}
|
This is the eslint config I'm using: https://github.com/milesj/build-tool-config/blob/master/packages/config/configs/eslint.js Nothing atm stands out, except for.
|
yea i found it, and looks like its issue in AST after all xd |
TypeError: Cannot read property '0' of undefined
at isGlobalAugmentation (******\typescript-eslint-parser\analyze-scope.js:32:26)
at Referencer.TSModuleDeclaration (******\typescript-eslint-parser\analyze-scope.js:578:13)
at Referencer.Visitor.visit (******\typescript-eslint-parser\node_modules\esrecurse\esrecurse.js:104:34)
at Referencer.Visitor.visitChildren (******\typescript-eslint-parser\node_modules\esrecurse\esrecurse.js:83:38)
at Referencer.Program (******\typescript-eslint-parser\node_modules\eslint-scope\lib\referencer.js:423:14)
at Referencer.Visitor.visit (******\typescript-eslint-parser\node_modules\esrecurse\esrecurse.js:104:34)
at module.exports (******\typescript-eslint-parser\analyze-scope.js:685:16)
at Object.parseForESLint (******\typescript-eslint-parser\parser.js:74:26)
at Object.exports.parse (******\typescript-eslint-parser\parser.js:79:17)
at parse (******\test\node_modules\eslint-module-utils\parse.js:36:17) |
Oh nice! Luckily we found it. |
this is related to JamesHenry/typescript-estree#27 |
The cause seems that |
yes, and no issue is most likely somewhere in parser when i have export and declare in one file tokens are empty export const foo = "";
declare global {
} but when only one of them tokens are present |
ESLint gives some implicit options: https://github.com/eslint/eslint/blob/5d451c510c15abc41b5bb14b4955a7db96aeb100/lib/linter.js#L436 {
loc: true,
range: true,
raw: true,
tokens: true,
comment: true,
eslintVisitorKeys: true,
eslintScopeManager: true,
filePath
}
// always include and attach comments
parserOptions.comment = true
parserOptions.attachComment = true
// attach node locations
parserOptions.loc = true
// provide the `filePath` like eslint itself does, in `parserOptions`
// https://github.com/eslint/eslint/blob/3ec436ee/lib/linter.js#L637
parserOptions.filePath = path This difference is the cause. However, probably we should not assume those options. |
ok, i tested it, |
@mysticatea why do check it there anyway? we can do if (node.declare && node.id && node.id.type === 'Identifier' && node.id.name === 'global') {
} |
@milesj for now you can patch it by adding |
Thanks both for the deep debugging! Will give that patch a try. |
@platinumazure this issue got fixed in last release |
Thanks @armano2, next time you can ensure this happens yourself by including "fixes ####" in the commit summary, commit message, or PR body 😄 Closing as this is resolved. |
What version of TypeScript are you using?
3.0
What version of
typescript-eslint-parser
are you using?21.0.1
What code were you trying to parse?
What did you expect to happen?
It parse.
What happened?
It fails with this error.
This has happened on 2 projects now, both because of
declare global
.The text was updated successfully, but these errors were encountered: