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
Report every instance of TS1208 #50101
Conversation
// @isolatedModules: true | ||
// @target: es6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a test with moduleDetection: force
? Optionally you could also try to add a test moduleDetection: auto
and with package.json
containing {"type":"module"}
. Note that I'm not super familiar with this new option and the latter proposed test might also require moduleResolution: node16
(but I'm not sure about it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test case with isolatedModules
+ moduleDetection: force
. I don't expect a regression in this area from the primary fix here, but it seems like a good test to have.
Did not add other test cases beyond that; I am not too familiar with the newer Node-related resolution behaviors, and I don't expect any regression around those.
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, | ||
Diagnostics._0_cannot_be_compiled_under_isolatedModules_because_it_is_considered_a_global_script_file_Add_an_import_export_or_an_empty_export_statement_to_make_it_a_module, getBaseFileName(firstNonExternalModuleSourceFile.fileName))); | ||
for (const file of files) { | ||
if (!isExternalModule(file) && !isSourceFileJS(file) && !file.isDeclarationFile && file.scriptKind !== ScriptKind.JSON) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!isExternalModule(file) && !isSourceFileJS(file) && !file.isDeclarationFile && file.scriptKind !== ScriptKind.JSON) { | |
const isIsolatedModules = !isExternalModule(file) && !isSourceFileJS(file) && !file.isDeclarationFile && file.scriptKind !== ScriptKind.JSON; | |
if (isIsolatedModules) { | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the predicate indicates that the file is a global (non-module) file, not that it's building under isolated modules.
There's enough context that I don't really think the predicate needs a name at all, really, but if you want one, it should be isNonModuleSourceFile
. ('External' is obsolete)
programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, | ||
Diagnostics._0_cannot_be_compiled_under_isolatedModules_because_it_is_considered_a_global_script_file_Add_an_import_export_or_an_empty_export_statement_to_make_it_a_module, getBaseFileName(firstNonExternalModuleSourceFile.fileName))); | ||
for (const file of files) { | ||
if (!isExternalModule(file) && !isSourceFileJS(file) && !file.isDeclarationFile && file.scriptKind !== ScriptKind.JSON) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the predicate indicates that the file is a global (non-module) file, not that it's building under isolated modules.
There's enough context that I don't really think the predicate needs a name at all, really, but if you want one, it should be isNonModuleSourceFile
. ('External' is obsolete)
Fixes #49995
Previously, many files could be considered global scripts during a compile with
isolatedModules
, but only one TS1208 error would be generated.Now, there is one TS1208 error raised per file.
This is a simple change to loop over each file and emit TS1208 if necessary. A new test was added to confirm that multiple TS1208 errors are generated. The test failed prior to this change.