Skip to content

Commit b365550

Browse files
committed
feat(911): add erasableSyntaxOnly
1 parent e58aed7 commit b365550

File tree

3 files changed

+48
-55
lines changed

3 files changed

+48
-55
lines changed

internal/checker/checker.go

Lines changed: 14 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() && ast.IsInternalModuleImportEqualsDeclaration(node) && 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)

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,60 @@
11
error TS2318: Cannot find global type 'IterableIterator'.
2+
index.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
3+
index.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
4+
index.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
5+
index.ts(16,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
6+
index.ts(17,15): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
7+
index.ts(22,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
8+
index.ts(26,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
9+
index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
210

311

412
!!! error TS2318: Cannot find global type 'IterableIterator'.
5-
==== index.ts (0 errors) ====
13+
==== index.ts (8 errors) ====
614
class MyClassErr {
715
// No parameter properties
816
constructor(public foo: string) { }
17+
~~~~~~~~~~~~~~~~~~
18+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
919
}
1020

1121
namespace IllegalBecauseInstantiated {
22+
~~~~~~~~~~~~~~~~~~~~~~~~~~
23+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1224
export const m = 1;
1325
}
1426

1527
namespace AlsoIllegalBecauseInstantiated {
28+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1630
class PrivateClass {
1731

1832
}
1933
}
2034

2135
namespace IllegalBecauseNestedInstantiated {
36+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
2238
namespace Nested {
39+
~~~~~~
40+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
2341
export const m = 1;
2442
}
2543
}
2644

2745
enum NotLegalEnum {
46+
~~~~~~~~~~~~
47+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
2848
B = 1
2949
}
3050

3151
import NoGoodAlias = NotLegalEnum.B;
52+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
3254

3355
const enum NotLegalConstEnum {
56+
~~~~~~~~~~~~~~~~~
57+
!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
3458
C = 2
3559
}
3660

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

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
error TS2318: Cannot find global type 'IterableIterator'.
55
-commonjs.cts(1,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
66
-commonjs.cts(2,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
7-
-index.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
8-
-index.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
9-
-index.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
10-
-index.ts(16,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
11-
-index.ts(17,15): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
12-
-index.ts(22,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
13-
-index.ts(26,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
14-
-index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
7+
index.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
8+
index.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
9+
index.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
10+
@@= skipped -8, +6 lines =@@
11+
index.ts(22,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
12+
index.ts(26,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
13+
index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1514
-index.ts(67,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1615
-index.ts(68,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
1716
-index.ts(69,7): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
@@ -28,55 +27,11 @@
2827

2928
!!! error TS2318: Cannot find global type 'IterableIterator'.
3029
-==== index.ts (20 errors) ====
31-
+==== index.ts (0 errors) ====
30+
+==== index.ts (8 errors) ====
3231
class MyClassErr {
3332
// No parameter properties
3433
constructor(public foo: string) { }
35-
- ~~~~~~~~~~~~~~~~~~
36-
-!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
37-
}
38-
39-
namespace IllegalBecauseInstantiated {
40-
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
41-
-!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
42-
export const m = 1;
43-
}
44-
45-
namespace AlsoIllegalBecauseInstantiated {
46-
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47-
-!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
48-
class PrivateClass {
49-
50-
}
51-
}
52-
53-
namespace IllegalBecauseNestedInstantiated {
54-
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55-
-!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
56-
namespace Nested {
57-
- ~~~~~~
58-
-!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
59-
export const m = 1;
60-
}
61-
}
62-
63-
enum NotLegalEnum {
64-
- ~~~~~~~~~~~~
65-
-!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
66-
B = 1
67-
}
68-
69-
import NoGoodAlias = NotLegalEnum.B;
70-
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71-
-!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
72-
73-
const enum NotLegalConstEnum {
74-
- ~~~~~~~~~~~~~~~~~
75-
-!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled.
76-
C = 2
77-
}
78-
79-
@@= skipped -107, +69 lines =@@
34+
@@= skipped -99, +87 lines =@@
8035

8136
// Not erasable
8237
(()=><any>{})();

0 commit comments

Comments
 (0)