-
-
Notifications
You must be signed in to change notification settings - Fork 75
Fix: sourceType not correctly set in AST when provided in options. #583
Conversation
Should this also try to guess a sourceType if one isn’t passed? It should be pretty easy to check if the source contains import or export statements. Also, if they’re present and |
guessing is build in into https://github.com/JamesHenry/typescript-estree/blob/master/src/convert.ts#L511 |
Could I get some background on the difference between
|
typescript-estree uses autodetection to determine what is sourceType of parsed file, this data does not come from typescript. eslint provides
i intended to make this change non breaking that's why i added check for that a lot of plugins are some core rules are using this field to determine behavior of rule:
if we want to release this change with next major update we can cut off fixes for autodetection in // Import/Export declarations cannot appear in script.
// But if those appear only in namespace/module blocks, `ast.sourceType` was `"script"`.
// This doesn't modify `ast.sourceType` directly for backward compatibility.
case "ImportDeclaration":
case "ExportAllDeclaration":
case "ExportDefaultDeclaration":
case "ExportNamedDeclaration":
extraOptions.sourceType = "module";
break; |
@armano2 When you say it doesn't come from TypeScript, I'm not sure exactly what you mean. We convert it from a property in the TypeScript AST like we do with many other things:
|
sourceType should be readed from ts config, but we not always have access to it, in there there is field called module, and there can be alot of values for it:
that's why i'm saying this is broken for now, let say i'm compiling everything to commonjs, |
ok, i updated this PR with changes from typescript-estree and i added 2nd run on scope analysis
scope analysis behave in different way for them. |
Even if sourceType is provided to
typescript-estree
its not taken into account and its always doing "autodetection".Typescript is not using this option anyway, there is no concept of script/module there
fixes: https://github.com/bradzacher/eslint-plugin-typescript/issues/255