Skip to content

Commit ddb1ebb

Browse files
authored
feat(911): erasableSyntaxOnly not supported (#1068)
1 parent 8284004 commit ddb1ebb

File tree

5 files changed

+100
-176
lines changed

5 files changed

+100
-176
lines changed

internal/checker/checker.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,9 @@ func (c *Checker) checkParameter(node *ast.Node) {
24702470
paramName = node.Name().Text()
24712471
}
24722472
if ast.HasSyntacticModifier(node, ast.ModifierFlagsParameterPropertyModifier) {
2473+
if c.compilerOptions.ErasableSyntaxOnly.IsTrue() {
2474+
c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
2475+
}
24732476
if !(ast.IsConstructorDeclaration(fn) && ast.NodeIsPresent(fn.Body())) {
24742477
c.error(node, diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation)
24752478
}
@@ -4785,6 +4788,11 @@ func (c *Checker) checkEnumDeclaration(node *ast.Node) {
47854788
c.checkCollisionsForDeclarationName(node, node.Name())
47864789
c.checkExportsOnMergedDeclarations(node)
47874790
c.checkSourceElements(node.Members())
4791+
4792+
if c.compilerOptions.ErasableSyntaxOnly.IsTrue() && node.Flags&ast.NodeFlagsAmbient == 0 {
4793+
c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
4794+
}
4795+
47884796
c.computeEnumMemberValues(node)
47894797
// Spec 2014 - Section 9.3:
47904798
// 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) {
48714879
symbol := c.getSymbolOfDeclaration(node)
48724880
// The following checks only apply on a non-ambient instantiated module declaration.
48734881
if symbol.Flags&ast.SymbolFlagsValueModule != 0 && !inAmbientContext && isInstantiatedModule(node, c.compilerOptions.ShouldPreserveConstEnums()) {
4882+
if c.compilerOptions.ErasableSyntaxOnly.IsTrue() {
4883+
c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
4884+
}
48744885
if c.compilerOptions.GetIsolatedModules() && ast.GetSourceFileOfNode(node).ExternalModuleIndicator == nil {
48754886
// This could be loosened a little if needed. The only problem we are trying to avoid is unqualified
48764887
// 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) {
51615172
return // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
51625173
}
51635174
c.checkGrammarModifiers(node)
5175+
if c.compilerOptions.ErasableSyntaxOnly.IsTrue() && node.Flags&ast.NodeFlagsAmbient == 0 {
5176+
c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
5177+
}
51645178
if ast.IsInternalModuleImportEqualsDeclaration(node) || c.checkExternalImportOrExportDeclaration(node) {
51655179
c.checkImportBinding(node)
51665180
c.markLinkedReferences(node, ReferenceHintExportImportEquals, nil, nil)
@@ -5260,6 +5274,9 @@ func (c *Checker) checkExportAssignment(node *ast.Node) {
52605274
if c.checkGrammarModuleElementContext(node, illegalContextMessage) {
52615275
return // If we hit an export assignment in an illegal context, just bail out to avoid cascading errors.
52625276
}
5277+
if c.compilerOptions.ErasableSyntaxOnly.IsTrue() && node.AsExportAssignment().IsExportEquals && node.Flags&ast.NodeFlagsAmbient == 0 {
5278+
c.error(node, diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled)
5279+
}
52635280
container := node.Parent
52645281
if !ast.IsSourceFile(container) {
52655282
container = container.Parent
@@ -11653,6 +11670,11 @@ func (c *Checker) classDeclarationExtendsNull(classDecl *ast.Node) bool {
1165311670
}
1165411671

1165511672
func (c *Checker) checkAssertion(node *ast.Node, checkMode CheckMode) *Type {
11673+
if node.Kind == ast.KindTypeAssertionExpression {
11674+
if c.compilerOptions.ErasableSyntaxOnly.IsTrue() {
11675+
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))
11676+
}
11677+
}
1165611678
typeNode := node.Type()
1165711679
exprType := c.checkExpressionEx(node.Expression(), checkMode)
1165811680
if isConstTypeReference(typeNode) {

testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly.errors.txt

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,74 @@
11
error TS2318: Cannot find global type 'IterableIterator'.
2+
commonjs.cts(1,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
3+
commonjs.cts(2,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
4+
index.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
5+
index.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
6+
index.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
7+
index.ts(16,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
8+
index.ts(17,15): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
9+
index.ts(22,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
10+
index.ts(26,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
11+
index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
12+
index.ts(67,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
13+
index.ts(68,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
14+
index.ts(69,7): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
15+
index.ts(72,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
16+
index.ts(73,7): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
17+
index.ts(74,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
18+
index.ts(79,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
19+
index.ts(81,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
20+
index.ts(86,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
21+
index.ts(89,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
22+
index.ts(90,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
23+
index.ts(94,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
224

325

426
!!! error TS2318: Cannot find global type 'IterableIterator'.
5-
==== index.ts (0 errors) ====
27+
==== index.ts (20 errors) ====
628
class MyClassErr {
729
// No parameter properties
830
constructor(public foo: string) { }
31+
~~~~~~~~~~~~~~~~~~
32+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
933
}
1034

1135
namespace IllegalBecauseInstantiated {
36+
~~~~~~~~~~~~~~~~~~~~~~~~~~
37+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1238
export const m = 1;
1339
}
1440

1541
namespace AlsoIllegalBecauseInstantiated {
42+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1644
class PrivateClass {
1745

1846
}
1947
}
2048

2149
namespace IllegalBecauseNestedInstantiated {
50+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
2252
namespace Nested {
53+
~~~~~~
54+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
2355
export const m = 1;
2456
}
2557
}
2658

2759
enum NotLegalEnum {
60+
~~~~~~~~~~~~
61+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
2862
B = 1
2963
}
3064

3165
import NoGoodAlias = NotLegalEnum.B;
66+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
3268

3369
const enum NotLegalConstEnum {
70+
~~~~~~~~~~~~~~~~~
71+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
3472
C = 2
3573
}
3674

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

71109
// Not erasable
72110
(()=><any>{})();
111+
~~~~~
112+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
73113
(()=>< any >{})();
114+
~~~~~~~
115+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
74116
(()=> < any > {})();
117+
~~~~~~~
118+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
75119

76120
// Erasable
77121
(()=><any>({}))();
122+
~~~~~
123+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
78124
(()=>(<any>{}))();
125+
~~~~~
126+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
79127
<any>{};
128+
~~~~~
129+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
80130

81131

82132
// return and yield ASI
83133
function *gen() {
84134
yield <any>
135+
~~~~~
136+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
85137
1;
86138
return <any>
139+
~~~~~
140+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
87141
1;
88142
}
89143

90144
// at the start of an ExpressionStatement if followed by an object literal; though I'm not sure why one would use it there
91145
<unknown>{foo() {}}.foo();
146+
~~~~~~~~~
147+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
92148

93149
// at the start of an ExpressionStatement if followed by function keyword
94150
<unknown>function() {}();
151+
~~~~~~~~~
152+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
95153
<unknown>function() {};
154+
~~~~~~~~~
155+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
96156

97157
// at the start of an ExpressionStatement if followed by an anonymous class expression
98158
// note that this exact syntax currently emits invalid JS (no parenthesis added like for function above)
99159
<unknown>class {}
160+
~~~~~~~~~
161+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
100162

101-
==== commonjs.cts (0 errors) ====
163+
==== commonjs.cts (2 errors) ====
102164
import foo = require("./other.cjs");
165+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
166+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
103167
export = foo;
168+
~~~~~~~~~~~~~
169+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
104170

105171

106172
==== other.d.cts (0 errors) ====

testdata/baselines/reference/submodule/compiler/erasableSyntaxOnly.errors.txt.diff

Lines changed: 0 additions & 145 deletions
This file was deleted.
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1+
index.ts(1,10): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
12
index.ts(1,19): error TS1005: '>' expected.
3+
index.ts(2,9): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
24
index.ts(2,18): error TS1005: '>' expected.
5+
index.ts(3,9): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
36
index.ts(3,17): error TS1005: '>' expected.
47

58

6-
==== index.ts (3 errors) ====
9+
==== index.ts (6 errors) ====
710
let a = (<unknown function foo() {});
11+
~~~~~~~~
12+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
813
~~~~~~~~
914
!!! error TS1005: '>' expected.
1015
let b = <unknown 123;
16+
~~~~~~~~
17+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1118
~~~
1219
!!! error TS1005: '>' expected.
1320
let c = <unknown
21+
~~~~~~~~
22+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1423

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

0 commit comments

Comments
 (0)