Skip to content
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

Merged
merged 3 commits into from Sep 2, 2022

Conversation

wnayes
Copy link
Contributor

@wnayes wnayes commented Jul 30, 2022

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.

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jul 30, 2022
// @isolatedModules: true
// @target: es6
Copy link
Contributor

@Andarist Andarist Jul 30, 2022

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)

Copy link
Contributor Author

@wnayes wnayes Jul 30, 2022

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {

Copy link
Member

@sandersn sandersn Sep 2, 2022

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)

@wnayes wnayes requested a review from Andarist Aug 4, 2022
@sandersn sandersn added this to Not started in PR Backlog Aug 8, 2022
PR Backlog automation moved this from Not started to Needs merge Sep 2, 2022
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) {
Copy link
Member

@sandersn sandersn Sep 2, 2022

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)

@sandersn sandersn merged commit fd3a84c into microsoft:main Sep 2, 2022
10 checks passed
PR Backlog automation moved this from Needs merge to Done Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

Report every instance of TS1208 (global scripts not allowed under isolatedModules)
5 participants