Skip to content

feat(911): erasableSyntaxOnly not supported #1068

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

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down Expand Up @@ -70,37 +108,65 @@ error TS2318: Cannot find global type 'IterableIterator'.

// Not erasable
(()=><any>{})();
~~~~~
!!! 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
(()=><any>({}))();
~~~~~
!!! 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.


// return and yield ASI
function *gen() {
yield <any>
~~~~~
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1;
return <any>
~~~~~
!!! 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
<unknown>{foo() {}}.foo();
~~~~~~~~~
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.

// at the start of an ExpressionStatement if followed by function keyword
<unknown>function() {}();
~~~~~~~~~
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
<unknown>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)
<unknown>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) ====
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 = (<unknown function foo() {});
~~~~~~~~
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
~~~~~~~~
!!! error TS1005: '>' expected.
let b = <unknown 123;
~~~~~~~~
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
~~~
!!! error TS1005: '>' expected.
let c = <unknown
~~~~~~~~
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.

!!! error TS1005: '>' expected.
Loading