diff --git a/internal/compiler/grammarchecks.go b/internal/compiler/grammarchecks.go index cc778b906a..0d6348347a 100644 --- a/internal/compiler/grammarchecks.go +++ b/internal/compiler/grammarchecks.go @@ -1219,7 +1219,7 @@ func (c *Checker) checkGrammarForInOrForOfStatement(forInOrOfStatement *ast.ForI c.diagnostics.add(createDiagnosticForNode(forInOrOfStatement.AwaitModifier, diagnostics.X_for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module)) } switch c.moduleKind { - case core.ModuleKindNode16, core.ModuleKindNodeNext: + case core.ModuleKindNode16, core.ModuleKindNode18, core.ModuleKindNodeNext: if sourceFile.ImpliedNodeFormat == core.ModuleKindCommonJS { c.diagnostics.add(createDiagnosticForNode(forInOrOfStatement.AwaitModifier, diagnostics.The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level)) break @@ -1723,6 +1723,7 @@ func (c *Checker) checkGrammarAwaitOrAwaitUsing(node *ast.Node) bool { } switch c.moduleKind { case core.ModuleKindNode16, + core.ModuleKindNode18, core.ModuleKindNodeNext: if sourceFile.ImpliedNodeFormat == core.ModuleKindCommonJS { if !spanCalculated { @@ -2176,7 +2177,7 @@ func (c *Checker) checkGrammarImportCallExpression(node *ast.Node) bool { nodeArguments := nodeAsCall.Arguments argumentNodes := nodeArguments.Nodes - if c.moduleKind != core.ModuleKindESNext && c.moduleKind != core.ModuleKindNodeNext && c.moduleKind != core.ModuleKindNode16 && c.moduleKind != core.ModuleKindPreserve { + if c.moduleKind != core.ModuleKindESNext && c.moduleKind != core.ModuleKindPreserve && !(core.ModuleKindNode16 <= c.moduleKind && c.moduleKind <= core.ModuleKindNodeNext) { // We are allowed trailing comma after proposal-import-assertions. c.checkGrammarForDisallowedTrailingComma(nodeArguments, diagnostics.Trailing_comma_not_allowed) diff --git a/internal/compiler/utilities.go b/internal/compiler/utilities.go index f548d890a1..9ecb4e1ab9 100644 --- a/internal/compiler/utilities.go +++ b/internal/compiler/utilities.go @@ -158,7 +158,7 @@ func isEffectiveModuleDeclaration(node *ast.Node) bool { } func isCommonJSContainingModuleKind(kind core.ModuleKind) bool { - return kind == core.ModuleKindCommonJS || kind == core.ModuleKindNode16 || kind == core.ModuleKindNodeNext + return kind == core.ModuleKindCommonJS || core.ModuleKindNode16 <= kind && kind <= core.ModuleKindNodeNext } /** @internal */ diff --git a/internal/core/compileroptions.go b/internal/core/compileroptions.go index 5bfda24078..4b5d1db5e1 100644 --- a/internal/core/compileroptions.go +++ b/internal/core/compileroptions.go @@ -79,7 +79,7 @@ func (options *CompilerOptions) GetModuleResolutionKind() ModuleResolutionKind { return options.ModuleResolution } switch options.GetEmitModuleKind() { - case ModuleKindNode16: + case ModuleKindNode16, ModuleKindNode18: return ModuleResolutionKindNode16 case ModuleKindNodeNext: return ModuleResolutionKindNodeNext @@ -93,7 +93,7 @@ func (options *CompilerOptions) GetESModuleInterop() bool { return options.ESModuleInterop == TSTrue } switch options.GetEmitModuleKind() { - case ModuleKindNode16, ModuleKindNodeNext, ModuleKindPreserve: + case ModuleKindNode16, ModuleKindNode18, ModuleKindNodeNext, ModuleKindPreserve: return true } return false @@ -176,6 +176,7 @@ const ( ModuleKindESNext ModuleKind = 99 // Node16+ is an amalgam of commonjs (albeit updated) and es2022+, and represents a distinct module system from es2020/esnext ModuleKindNode16 ModuleKind = 100 + ModuleKindNode18 ModuleKind = 101 ModuleKindNodeNext ModuleKind = 199 // Emit as written ModuleKindPreserve ModuleKind = 200 diff --git a/internal/core/compileroptions_stringer_generated.go b/internal/core/compileroptions_stringer_generated.go index add7adb822..7f8f27a0b6 100644 --- a/internal/core/compileroptions_stringer_generated.go +++ b/internal/core/compileroptions_stringer_generated.go @@ -18,19 +18,20 @@ func _() { _ = x[ModuleKindES2022-7] _ = x[ModuleKindESNext-99] _ = x[ModuleKindNode16-100] + _ = x[ModuleKindNode18-101] _ = x[ModuleKindNodeNext-199] _ = x[ModuleKindPreserve-200] } const ( _ModuleKind_name_0 = "ModuleKindNoneModuleKindCommonJSModuleKindAMDModuleKindUMDModuleKindSystemModuleKindES2015ModuleKindES2020ModuleKindES2022" - _ModuleKind_name_1 = "ModuleKindESNextModuleKindNode16" + _ModuleKind_name_1 = "ModuleKindESNextModuleKindNode16ModuleKindNode18" _ModuleKind_name_2 = "ModuleKindNodeNextModuleKindPreserve" ) var ( _ModuleKind_index_0 = [...]uint8{0, 14, 32, 45, 58, 74, 90, 106, 122} - _ModuleKind_index_1 = [...]uint8{0, 16, 32} + _ModuleKind_index_1 = [...]uint8{0, 16, 32, 48} _ModuleKind_index_2 = [...]uint8{0, 18, 36} ) @@ -38,7 +39,7 @@ func (i ModuleKind) String() string { switch { case 0 <= i && i <= 7: return _ModuleKind_name_0[_ModuleKind_index_0[i]:_ModuleKind_index_0[i+1]] - case 99 <= i && i <= 100: + case 99 <= i && i <= 101: i -= 99 return _ModuleKind_name_1[_ModuleKind_index_1[i]:_ModuleKind_index_1[i+1]] case 199 <= i && i <= 200: