diff --git a/internal/checker/checker.go b/internal/checker/checker.go index c23d77a906..6f94c558b3 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -2470,6 +2470,9 @@ func (c *Checker) checkParameter(node *ast.Node) { paramName = node.Name().Text() } if ast.HasSyntacticModifier(node, ast.ModifierFlagsParameterPropertyModifier) { + if c.compilerOptions.ErasableSyntaxOnly.IsTrue() { + c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled) + } if !(ast.IsConstructorDeclaration(fn) && ast.NodeIsPresent(fn.Body())) { c.error(node, diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation) } @@ -4785,6 +4788,11 @@ func (c *Checker) checkEnumDeclaration(node *ast.Node) { c.checkCollisionsForDeclarationName(node, node.Name()) c.checkExportsOnMergedDeclarations(node) c.checkSourceElements(node.Members()) + + if c.compilerOptions.ErasableSyntaxOnly.IsTrue() && node.Flags&ast.NodeFlagsAmbient == 0 { + c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled) + } + c.computeEnumMemberValues(node) // Spec 2014 - Section 9.3: // It isn't possible for one enum declaration to continue the automatic numbering sequence of another, @@ -4871,6 +4879,9 @@ func (c *Checker) checkModuleDeclaration(node *ast.Node) { symbol := c.getSymbolOfDeclaration(node) // The following checks only apply on a non-ambient instantiated module declaration. if symbol.Flags&ast.SymbolFlagsValueModule != 0 && !inAmbientContext && isInstantiatedModule(node, c.compilerOptions.ShouldPreserveConstEnums()) { + if c.compilerOptions.ErasableSyntaxOnly.IsTrue() { + c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled) + } if c.compilerOptions.GetIsolatedModules() && ast.GetSourceFileOfNode(node).ExternalModuleIndicator == nil { // This could be loosened a little if needed. The only problem we are trying to avoid is unqualified // references to namespace members declared in other files. But use of namespaces is discouraged anyway, @@ -5161,6 +5172,9 @@ func (c *Checker) checkImportEqualsDeclaration(node *ast.Node) { return // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors. } c.checkGrammarModifiers(node) + if c.compilerOptions.ErasableSyntaxOnly.IsTrue() && node.Flags&ast.NodeFlagsAmbient == 0 { + c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled) + } if ast.IsInternalModuleImportEqualsDeclaration(node) || c.checkExternalImportOrExportDeclaration(node) { c.checkImportBinding(node) c.markLinkedReferences(node, ReferenceHintExportImportEquals, nil, nil) @@ -5260,6 +5274,9 @@ func (c *Checker) checkExportAssignment(node *ast.Node) { if c.checkGrammarModuleElementContext(node, illegalContextMessage) { return // If we hit an export assignment in an illegal context, just bail out to avoid cascading errors. } + if c.compilerOptions.ErasableSyntaxOnly.IsTrue() && node.AsExportAssignment().IsExportEquals && node.Flags&ast.NodeFlagsAmbient == 0 { + c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled) + } container := node.Parent if !ast.IsSourceFile(container) { container = container.Parent @@ -11653,6 +11670,11 @@ func (c *Checker) classDeclarationExtendsNull(classDecl *ast.Node) bool { } func (c *Checker) checkAssertion(node *ast.Node, checkMode CheckMode) *Type { + if node.Kind == ast.KindTypeAssertionExpression { + if c.compilerOptions.ErasableSyntaxOnly.IsTrue() { + c.diagnostics.Add(ast.NewDiagnostic(ast.GetSourceFileOfNode(node), core.NewTextRange(scanner.SkipTrivia(ast.GetSourceFileOfNode(node).Text(), node.Pos()), node.Expression().Pos()), diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)) + } + } typeNode := node.Type() exprType := c.checkExpressionEx(node.Expression(), checkMode) if isConstTypeReference(typeNode) { diff --git a/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly.errors.txt b/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly.errors.txt index 3a52cdce31..523da93fd9 100644 --- a/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly.errors.txt @@ -1,36 +1,74 @@ error TS2318: Cannot find global type 'IterableIterator'. +commonjs.cts(1,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +commonjs.cts(2,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(16,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(17,15): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(22,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(26,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(67,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(68,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(69,7): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(72,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(73,7): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(74,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(79,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(81,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(86,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(89,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(90,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +index.ts(94,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. !!! error TS2318: Cannot find global type 'IterableIterator'. -==== index.ts (0 errors) ==== +==== index.ts (20 errors) ==== class MyClassErr { // No parameter properties constructor(public foo: string) { } + ~~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. } namespace IllegalBecauseInstantiated { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. export const m = 1; } namespace AlsoIllegalBecauseInstantiated { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. class PrivateClass { } } namespace IllegalBecauseNestedInstantiated { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. namespace Nested { + ~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. export const m = 1; } } enum NotLegalEnum { + ~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. B = 1 } import NoGoodAlias = NotLegalEnum.B; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. const enum NotLegalConstEnum { + ~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. C = 2 } @@ -70,37 +108,65 @@ error TS2318: Cannot find global type 'IterableIterator'. // Not erasable (()=>{})(); + ~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. (()=>< any >{})(); + ~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. (()=> < any > {})(); + ~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. // Erasable (()=>({}))(); + ~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. (()=>({}))(); + ~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. {}; + ~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. // return and yield ASI function *gen() { yield + ~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. 1; return + ~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. 1; } // at the start of an ExpressionStatement if followed by an object literal; though I'm not sure why one would use it there {foo() {}}.foo(); + ~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. // at the start of an ExpressionStatement if followed by function keyword function() {}(); + ~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. function() {}; + ~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. // at the start of an ExpressionStatement if followed by an anonymous class expression // note that this exact syntax currently emits invalid JS (no parenthesis added like for function above) class {} + ~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -==== commonjs.cts (0 errors) ==== +==== commonjs.cts (2 errors) ==== import foo = require("./other.cjs"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. export = foo; + ~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. ==== other.d.cts (0 errors) ==== diff --git a/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly.errors.txt.diff deleted file mode 100644 index 778088ae90..0000000000 --- a/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly.errors.txt.diff +++ /dev/null @@ -1,145 +0,0 @@ ---- old.erasableSyntaxOnly.errors.txt -+++ new.erasableSyntaxOnly.errors.txt -@@= skipped -0, +0 lines =@@ - error TS2318: Cannot find global type 'IterableIterator'. --commonjs.cts(1,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --commonjs.cts(2,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(16,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(17,15): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(22,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(26,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(67,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(68,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(69,7): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(72,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(73,7): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(74,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(79,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(81,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(86,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(89,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(90,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. --index.ts(94,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - - - !!! error TS2318: Cannot find global type 'IterableIterator'. --==== index.ts (20 errors) ==== -+==== index.ts (0 errors) ==== - class MyClassErr { - // No parameter properties - constructor(public foo: string) { } -- ~~~~~~~~~~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - } - - namespace IllegalBecauseInstantiated { -- ~~~~~~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - export const m = 1; - } - - namespace AlsoIllegalBecauseInstantiated { -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - class PrivateClass { - - } - } - - namespace IllegalBecauseNestedInstantiated { -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - namespace Nested { -- ~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - export const m = 1; - } - } - - enum NotLegalEnum { -- ~~~~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - B = 1 - } - - import NoGoodAlias = NotLegalEnum.B; -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - - const enum NotLegalConstEnum { -- ~~~~~~~~~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - C = 2 - } - -@@= skipped -107, +69 lines =@@ - - // Not erasable - (()=>{})(); -- ~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - (()=>< any >{})(); -- ~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - (()=> < any > {})(); -- ~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - - // Erasable - (()=>({}))(); -- ~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - (()=>({}))(); -- ~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - {}; -- ~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - - - // return and yield ASI - function *gen() { - yield -- ~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - 1; - return -- ~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - 1; - } - - // at the start of an ExpressionStatement if followed by an object literal; though I'm not sure why one would use it there - {foo() {}}.foo(); -- ~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - - // at the start of an ExpressionStatement if followed by function keyword - function() {}(); -- ~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - function() {}; -- ~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - - // at the start of an ExpressionStatement if followed by an anonymous class expression - // note that this exact syntax currently emits invalid JS (no parenthesis added like for function above) - class {} -- ~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - --==== commonjs.cts (2 errors) ==== -+==== commonjs.cts (0 errors) ==== - import foo = require("./other.cjs"); -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - export = foo; -- ~~~~~~~~~~~~~ --!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - - - ==== other.d.cts (0 errors) ==== \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly2.errors.txt b/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly2.errors.txt index e4d89e9053..4ceb70cc1d 100644 --- a/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly2.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly2.errors.txt @@ -1,15 +1,24 @@ +index.ts(1,10): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. index.ts(1,19): error TS1005: '>' expected. +index.ts(2,9): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. index.ts(2,18): error TS1005: '>' expected. +index.ts(3,9): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. index.ts(3,17): error TS1005: '>' expected. -==== index.ts (3 errors) ==== +==== index.ts (6 errors) ==== let a = (' expected. let b = ' expected. let c = ' expected. \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly2.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly2.errors.txt.diff deleted file mode 100644 index 996c8aa1f5..0000000000 --- a/testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly2.errors.txt.diff +++ /dev/null @@ -1,28 +0,0 @@ ---- old.erasableSyntaxOnly2.errors.txt -+++ new.erasableSyntaxOnly2.errors.txt -@@= skipped -0, +0 lines =@@ --index.ts(1,10): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - index.ts(1,19): error TS1005: '>' expected. --index.ts(2,9): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - index.ts(2,18): error TS1005: '>' expected. --index.ts(3,9): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - index.ts(3,17): error TS1005: '>' expected. - - --==== index.ts (6 errors) ==== -+==== index.ts (3 errors) ==== - let a = (' expected. - let b = ' expected. - let c = ' expected. \ No newline at end of file