From 69f5ded6d1cd6dc50b558c714ca7b06705bc85fc Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 21 Jan 2025 21:37:17 -0800 Subject: [PATCH 01/12] Implementation of erasableSyntaxOnly --- src/compiler/checker.ts | 11 +++++++++++ src/compiler/commandLineParser.ts | 9 +++++++++ src/compiler/diagnosticMessages.json | 10 ++++++++-- src/compiler/types.ts | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5eb14081e2a3c..359ff49f1e10c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -41290,6 +41290,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { checkVariableLikeDeclaration(node); const func = getContainingFunction(node)!; if (hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) { + if (compilerOptions.erasableSyntaxOnly) { + error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled); + } if (!(func.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) { error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } @@ -47504,6 +47507,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { checkExportsOnMergedDeclarations(node); node.members.forEach(checkEnumMember); + if (compilerOptions.erasableSyntaxOnly && (node.flags & NodeFlags.Ambient) === 0) { + error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled); + } + computeEnumMemberValues(node); // Spec 2014 - Section 9.3: @@ -47643,6 +47650,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { && !inAmbientContext && isInstantiatedModule(node, shouldPreserveConstEnums(compilerOptions)) ) { + if (compilerOptions.erasableSyntaxOnly) { + error(node.name, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled); + } + if (getIsolatedModules(compilerOptions) && !getSourceFileOfNode(node).externalModuleIndicator) { // 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, diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index ff95389e60974..fa670d5b52b74 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -855,6 +855,15 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [ affectsBuildInfo: true, affectsSemanticDiagnostics: true, }, + { + name: "erasableSyntaxOnly", + type: "boolean", + category: Diagnostics.Interop_Constraints, + description: Diagnostics.Do_not_allow_runtime_constructs_that_are_not_part_of_ECMAScript, + defaultValueDescription: false, + affectsBuildInfo: true, + affectsSemanticDiagnostics: true, + }, // Strict Type Checks { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index d757b34d5c384..9d2b384d17a2d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -971,7 +971,10 @@ "category": "Error", "code": 1293 }, - + "This syntax is not allowed when 'erasableSyntaxOnly' is enabled.": { + "category": "Error", + "code": 1294 + }, "'with' statements are not allowed in an async function block.": { "category": "Error", "code": 1300 @@ -6467,11 +6470,14 @@ "category": "Message", "code": 6719 }, - "Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'.": { "category": "Message", "code": 6720 }, + "Do not allow runtime constructs that are not part of ECMAScript.": { + "category": "Message", + "code": 6721 + }, "Default catch clause variables as 'unknown' instead of 'any'.": { "category": "Message", "code": 6803 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ad915af32ee83..e53ad2226a34d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7502,6 +7502,7 @@ export interface CompilerOptions { /** Paths used to compute primary types search locations */ typeRoots?: string[]; verbatimModuleSyntax?: boolean; + erasableSyntaxOnly?: boolean; /** @internal */ version?: boolean; /** @internal */ watch?: boolean; esModuleInterop?: boolean; From 8ee35e5a57dd80856b7a5d7299857ef25adcff13 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 21 Jan 2025 21:37:34 -0800 Subject: [PATCH 02/12] Test + baseline --- .../reference/erasableSyntaxOnly.errors.txt | 67 ++++++++++ .../baselines/reference/erasableSyntaxOnly.js | 84 ++++++++++++ .../reference/erasableSyntaxOnly.symbols | 89 +++++++++++++ .../reference/erasableSyntaxOnly.types | 121 ++++++++++++++++++ tests/cases/compiler/erasableSyntaxOnly.ts | 50 ++++++++ 5 files changed, 411 insertions(+) create mode 100644 tests/baselines/reference/erasableSyntaxOnly.errors.txt create mode 100644 tests/baselines/reference/erasableSyntaxOnly.js create mode 100644 tests/baselines/reference/erasableSyntaxOnly.symbols create mode 100644 tests/baselines/reference/erasableSyntaxOnly.types create mode 100644 tests/cases/compiler/erasableSyntaxOnly.ts diff --git a/tests/baselines/reference/erasableSyntaxOnly.errors.txt b/tests/baselines/reference/erasableSyntaxOnly.errors.txt new file mode 100644 index 0000000000000..83ad15aec09b5 --- /dev/null +++ b/tests/baselines/reference/erasableSyntaxOnly.errors.txt @@ -0,0 +1,67 @@ +erasableSyntaxOnly.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(16,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(20,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. + + +==== erasableSyntaxOnly.ts (5 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 { + + } + } + + enum NotLegalEnum { + ~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. + B = 1 + } + + const enum NotLegalConstEnum { + ~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. + C = 2 + } + + // No errors after this point + class MyClassOk { + // Not a parameter property, ok + constructor(foo: string) { } + } + namespace NotInstantiated { + export interface JustAType { } + export type ATypeInANamespace = {}; + } + declare namespace AmbientIsNotInstantiated { + export const stillOk = 12; + } + + declare enum LegalEnum { + A = 1 + } + + declare namespace AmbientStuff { + namespace Nested { + export const stillOk = 12; + } + enum EnumInAmbientContext { + B = 1 + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/erasableSyntaxOnly.js b/tests/baselines/reference/erasableSyntaxOnly.js new file mode 100644 index 0000000000000..a5771dd7c1055 --- /dev/null +++ b/tests/baselines/reference/erasableSyntaxOnly.js @@ -0,0 +1,84 @@ +//// [tests/cases/compiler/erasableSyntaxOnly.ts] //// + +//// [erasableSyntaxOnly.ts] +class MyClassErr { + // No parameter properties + constructor(public foo: string) { } +} + +namespace IllegalBecauseInstantiated { + export const m = 1; +} + +namespace AlsoIllegalBecauseInstantiated { + class PrivateClass { + + } +} + +enum NotLegalEnum { + B = 1 +} + +const enum NotLegalConstEnum { + C = 2 +} + +// No errors after this point +class MyClassOk { + // Not a parameter property, ok + constructor(foo: string) { } +} +namespace NotInstantiated { + export interface JustAType { } + export type ATypeInANamespace = {}; +} +declare namespace AmbientIsNotInstantiated { + export const stillOk = 12; +} + +declare enum LegalEnum { + A = 1 +} + +declare namespace AmbientStuff { + namespace Nested { + export const stillOk = 12; + } + enum EnumInAmbientContext { + B = 1 + } +} + + +//// [erasableSyntaxOnly.js] +var MyClassErr = /** @class */ (function () { + // No parameter properties + function MyClassErr(foo) { + this.foo = foo; + } + return MyClassErr; +}()); +var IllegalBecauseInstantiated; +(function (IllegalBecauseInstantiated) { + IllegalBecauseInstantiated.m = 1; +})(IllegalBecauseInstantiated || (IllegalBecauseInstantiated = {})); +var AlsoIllegalBecauseInstantiated; +(function (AlsoIllegalBecauseInstantiated) { + var PrivateClass = /** @class */ (function () { + function PrivateClass() { + } + return PrivateClass; + }()); +})(AlsoIllegalBecauseInstantiated || (AlsoIllegalBecauseInstantiated = {})); +var NotLegalEnum; +(function (NotLegalEnum) { + NotLegalEnum[NotLegalEnum["B"] = 1] = "B"; +})(NotLegalEnum || (NotLegalEnum = {})); +// No errors after this point +var MyClassOk = /** @class */ (function () { + // Not a parameter property, ok + function MyClassOk(foo) { + } + return MyClassOk; +}()); diff --git a/tests/baselines/reference/erasableSyntaxOnly.symbols b/tests/baselines/reference/erasableSyntaxOnly.symbols new file mode 100644 index 0000000000000..d1a0c94c3c7dd --- /dev/null +++ b/tests/baselines/reference/erasableSyntaxOnly.symbols @@ -0,0 +1,89 @@ +//// [tests/cases/compiler/erasableSyntaxOnly.ts] //// + +=== erasableSyntaxOnly.ts === +class MyClassErr { +>MyClassErr : Symbol(MyClassErr, Decl(erasableSyntaxOnly.ts, 0, 0)) + + // No parameter properties + constructor(public foo: string) { } +>foo : Symbol(MyClassErr.foo, Decl(erasableSyntaxOnly.ts, 2, 16)) +} + +namespace IllegalBecauseInstantiated { +>IllegalBecauseInstantiated : Symbol(IllegalBecauseInstantiated, Decl(erasableSyntaxOnly.ts, 3, 1)) + + export const m = 1; +>m : Symbol(m, Decl(erasableSyntaxOnly.ts, 6, 16)) +} + +namespace AlsoIllegalBecauseInstantiated { +>AlsoIllegalBecauseInstantiated : Symbol(AlsoIllegalBecauseInstantiated, Decl(erasableSyntaxOnly.ts, 7, 1)) + + class PrivateClass { +>PrivateClass : Symbol(PrivateClass, Decl(erasableSyntaxOnly.ts, 9, 42)) + + } +} + +enum NotLegalEnum { +>NotLegalEnum : Symbol(NotLegalEnum, Decl(erasableSyntaxOnly.ts, 13, 1)) + + B = 1 +>B : Symbol(NotLegalEnum.B, Decl(erasableSyntaxOnly.ts, 15, 19)) +} + +const enum NotLegalConstEnum { +>NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(erasableSyntaxOnly.ts, 17, 1)) + + C = 2 +>C : Symbol(NotLegalConstEnum.C, Decl(erasableSyntaxOnly.ts, 19, 30)) +} + +// No errors after this point +class MyClassOk { +>MyClassOk : Symbol(MyClassOk, Decl(erasableSyntaxOnly.ts, 21, 1)) + + // Not a parameter property, ok + constructor(foo: string) { } +>foo : Symbol(foo, Decl(erasableSyntaxOnly.ts, 26, 16)) +} +namespace NotInstantiated { +>NotInstantiated : Symbol(NotInstantiated, Decl(erasableSyntaxOnly.ts, 27, 1)) + + export interface JustAType { } +>JustAType : Symbol(JustAType, Decl(erasableSyntaxOnly.ts, 28, 27)) + + export type ATypeInANamespace = {}; +>ATypeInANamespace : Symbol(ATypeInANamespace, Decl(erasableSyntaxOnly.ts, 29, 34)) +} +declare namespace AmbientIsNotInstantiated { +>AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(erasableSyntaxOnly.ts, 31, 1)) + + export const stillOk = 12; +>stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 33, 16)) +} + +declare enum LegalEnum { +>LegalEnum : Symbol(LegalEnum, Decl(erasableSyntaxOnly.ts, 34, 1)) + + A = 1 +>A : Symbol(LegalEnum.A, Decl(erasableSyntaxOnly.ts, 36, 24)) +} + +declare namespace AmbientStuff { +>AmbientStuff : Symbol(AmbientStuff, Decl(erasableSyntaxOnly.ts, 38, 1)) + + namespace Nested { +>Nested : Symbol(Nested, Decl(erasableSyntaxOnly.ts, 40, 32)) + + export const stillOk = 12; +>stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 42, 20)) + } + enum EnumInAmbientContext { +>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(erasableSyntaxOnly.ts, 43, 5)) + + B = 1 +>B : Symbol(EnumInAmbientContext.B, Decl(erasableSyntaxOnly.ts, 44, 31)) + } +} + diff --git a/tests/baselines/reference/erasableSyntaxOnly.types b/tests/baselines/reference/erasableSyntaxOnly.types new file mode 100644 index 0000000000000..f67c7a8062cb0 --- /dev/null +++ b/tests/baselines/reference/erasableSyntaxOnly.types @@ -0,0 +1,121 @@ +//// [tests/cases/compiler/erasableSyntaxOnly.ts] //// + +=== erasableSyntaxOnly.ts === +class MyClassErr { +>MyClassErr : MyClassErr +> : ^^^^^^^^^^ + + // No parameter properties + constructor(public foo: string) { } +>foo : string +> : ^^^^^^ +} + +namespace IllegalBecauseInstantiated { +>IllegalBecauseInstantiated : typeof IllegalBecauseInstantiated +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + export const m = 1; +>m : 1 +> : ^ +>1 : 1 +> : ^ +} + +namespace AlsoIllegalBecauseInstantiated { +>AlsoIllegalBecauseInstantiated : typeof AlsoIllegalBecauseInstantiated +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + class PrivateClass { +>PrivateClass : PrivateClass +> : ^^^^^^^^^^^^ + + } +} + +enum NotLegalEnum { +>NotLegalEnum : NotLegalEnum +> : ^^^^^^^^^^^^ + + B = 1 +>B : NotLegalEnum.B +> : ^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +} + +const enum NotLegalConstEnum { +>NotLegalConstEnum : NotLegalConstEnum +> : ^^^^^^^^^^^^^^^^^ + + C = 2 +>C : NotLegalConstEnum.C +> : ^^^^^^^^^^^^^^^^^^^ +>2 : 2 +> : ^ +} + +// No errors after this point +class MyClassOk { +>MyClassOk : MyClassOk +> : ^^^^^^^^^ + + // Not a parameter property, ok + constructor(foo: string) { } +>foo : string +> : ^^^^^^ +} +namespace NotInstantiated { + export interface JustAType { } + export type ATypeInANamespace = {}; +>ATypeInANamespace : ATypeInANamespace +> : ^^^^^^^^^^^^^^^^^ +} +declare namespace AmbientIsNotInstantiated { +>AmbientIsNotInstantiated : typeof AmbientIsNotInstantiated +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + export const stillOk = 12; +>stillOk : 12 +> : ^^ +>12 : 12 +> : ^^ +} + +declare enum LegalEnum { +>LegalEnum : LegalEnum +> : ^^^^^^^^^ + + A = 1 +>A : LegalEnum.A +> : ^^^^^^^^^^^ +>1 : 1 +> : ^ +} + +declare namespace AmbientStuff { +>AmbientStuff : typeof AmbientStuff +> : ^^^^^^^^^^^^^^^^^^^ + + namespace Nested { +>Nested : typeof Nested +> : ^^^^^^^^^^^^^ + + export const stillOk = 12; +>stillOk : 12 +> : ^^ +>12 : 12 +> : ^^ + } + enum EnumInAmbientContext { +>EnumInAmbientContext : EnumInAmbientContext +> : ^^^^^^^^^^^^^^^^^^^^ + + B = 1 +>B : EnumInAmbientContext.B +> : ^^^^^^^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ + } +} + diff --git a/tests/cases/compiler/erasableSyntaxOnly.ts b/tests/cases/compiler/erasableSyntaxOnly.ts new file mode 100644 index 0000000000000..8f29060165477 --- /dev/null +++ b/tests/cases/compiler/erasableSyntaxOnly.ts @@ -0,0 +1,50 @@ +// @erasableSyntaxOnly: true + +class MyClassErr { + // No parameter properties + constructor(public foo: string) { } +} + +namespace IllegalBecauseInstantiated { + export const m = 1; +} + +namespace AlsoIllegalBecauseInstantiated { + class PrivateClass { + + } +} + +enum NotLegalEnum { + B = 1 +} + +const enum NotLegalConstEnum { + C = 2 +} + +// No errors after this point +class MyClassOk { + // Not a parameter property, ok + constructor(foo: string) { } +} +namespace NotInstantiated { + export interface JustAType { } + export type ATypeInANamespace = {}; +} +declare namespace AmbientIsNotInstantiated { + export const stillOk = 12; +} + +declare enum LegalEnum { + A = 1 +} + +declare namespace AmbientStuff { + namespace Nested { + export const stillOk = 12; + } + enum EnumInAmbientContext { + B = 1 + } +} From ac1bb335cec5c2d9f4a22802599e7babf8c61196 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 21 Jan 2025 21:37:43 -0800 Subject: [PATCH 03/12] Other baseline changes --- tests/baselines/reference/api/typescript.d.ts | 1 + .../initTSConfig/Default initialized TSConfig/tsconfig.json | 1 + .../Initialized TSConfig with --help/tsconfig.json | 1 + .../Initialized TSConfig with --watch/tsconfig.json | 1 + .../Initialized TSConfig with advanced options/tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../Initialized TSConfig with files options/tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../erasableSyntaxOnly/tsconfig.json | 5 +++++ tests/baselines/reference/tsc/commandLine/help-all.js | 5 +++++ 14 files changed, 22 insertions(+) create mode 100644 tests/baselines/reference/config/showConfig/Shows tsconfig for single option/erasableSyntaxOnly/tsconfig.json diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 2f7870cfad96f..45e82d6549c03 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -7102,6 +7102,7 @@ declare namespace ts { /** Paths used to compute primary types search locations */ typeRoots?: string[]; verbatimModuleSyntax?: boolean; + erasableSyntaxOnly?: boolean; esModuleInterop?: boolean; useDefineForClassFields?: boolean; [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined; diff --git a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json index c9c555d96f35d..13f3dfe3454f6 100644 --- a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json index c9c555d96f35d..13f3dfe3454f6 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json index c9c555d96f35d..13f3dfe3454f6 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json index 57d57797e5c65..c11ae3207e6ec 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 6f40fa430a101..82a1acd3aa21f 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index c0898eedb6c94..cdf7f38a4376d 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json index 23354c3f64a09..63e2ed1543406 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index acfcbb5bfad84..9af39e4fb164c 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index c9c555d96f35d..13f3dfe3454f6 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index 4c0ff4bb1cb43..18027a41049bf 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json index c61179ba4d047..1821b4b80c7ad 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -77,6 +77,7 @@ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */ + // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ diff --git a/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/erasableSyntaxOnly/tsconfig.json b/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/erasableSyntaxOnly/tsconfig.json new file mode 100644 index 0000000000000..6983abf529f83 --- /dev/null +++ b/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/erasableSyntaxOnly/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "erasableSyntaxOnly": true + } +} diff --git a/tests/baselines/reference/tsc/commandLine/help-all.js b/tests/baselines/reference/tsc/commandLine/help-all.js index a758fb9b2102a..88b85cf44949d 100644 --- a/tests/baselines/reference/tsc/commandLine/help-all.js +++ b/tests/baselines/reference/tsc/commandLine/help-all.js @@ -167,6 +167,11 @@ Allow 'import x from y' when a module doesn't have a default export. type: boolean default: module === "system" or esModuleInterop +--erasableSyntaxOnly +Do not allow runtime constructs that are not part of ECMAScript. +type: boolean +default: false + --esModuleInterop Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. type: boolean From 6aee14c7a3c7df4c830e3ed3ee0efec0b28c17d0 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 22 Jan 2025 08:31:36 -0800 Subject: [PATCH 04/12] Add noEmit to test --- .../baselines/reference/erasableSyntaxOnly.js | 84 ------------------- tests/cases/compiler/erasableSyntaxOnly.ts | 1 + .../compiler/erasableSyntaxOnlyDeclaration.ts | 50 +++++++++++ 3 files changed, 51 insertions(+), 84 deletions(-) delete mode 100644 tests/baselines/reference/erasableSyntaxOnly.js create mode 100644 tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts diff --git a/tests/baselines/reference/erasableSyntaxOnly.js b/tests/baselines/reference/erasableSyntaxOnly.js deleted file mode 100644 index a5771dd7c1055..0000000000000 --- a/tests/baselines/reference/erasableSyntaxOnly.js +++ /dev/null @@ -1,84 +0,0 @@ -//// [tests/cases/compiler/erasableSyntaxOnly.ts] //// - -//// [erasableSyntaxOnly.ts] -class MyClassErr { - // No parameter properties - constructor(public foo: string) { } -} - -namespace IllegalBecauseInstantiated { - export const m = 1; -} - -namespace AlsoIllegalBecauseInstantiated { - class PrivateClass { - - } -} - -enum NotLegalEnum { - B = 1 -} - -const enum NotLegalConstEnum { - C = 2 -} - -// No errors after this point -class MyClassOk { - // Not a parameter property, ok - constructor(foo: string) { } -} -namespace NotInstantiated { - export interface JustAType { } - export type ATypeInANamespace = {}; -} -declare namespace AmbientIsNotInstantiated { - export const stillOk = 12; -} - -declare enum LegalEnum { - A = 1 -} - -declare namespace AmbientStuff { - namespace Nested { - export const stillOk = 12; - } - enum EnumInAmbientContext { - B = 1 - } -} - - -//// [erasableSyntaxOnly.js] -var MyClassErr = /** @class */ (function () { - // No parameter properties - function MyClassErr(foo) { - this.foo = foo; - } - return MyClassErr; -}()); -var IllegalBecauseInstantiated; -(function (IllegalBecauseInstantiated) { - IllegalBecauseInstantiated.m = 1; -})(IllegalBecauseInstantiated || (IllegalBecauseInstantiated = {})); -var AlsoIllegalBecauseInstantiated; -(function (AlsoIllegalBecauseInstantiated) { - var PrivateClass = /** @class */ (function () { - function PrivateClass() { - } - return PrivateClass; - }()); -})(AlsoIllegalBecauseInstantiated || (AlsoIllegalBecauseInstantiated = {})); -var NotLegalEnum; -(function (NotLegalEnum) { - NotLegalEnum[NotLegalEnum["B"] = 1] = "B"; -})(NotLegalEnum || (NotLegalEnum = {})); -// No errors after this point -var MyClassOk = /** @class */ (function () { - // Not a parameter property, ok - function MyClassOk(foo) { - } - return MyClassOk; -}()); diff --git a/tests/cases/compiler/erasableSyntaxOnly.ts b/tests/cases/compiler/erasableSyntaxOnly.ts index 8f29060165477..759b89a8c0e33 100644 --- a/tests/cases/compiler/erasableSyntaxOnly.ts +++ b/tests/cases/compiler/erasableSyntaxOnly.ts @@ -1,4 +1,5 @@ // @erasableSyntaxOnly: true +// @noEmit: true class MyClassErr { // No parameter properties diff --git a/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts new file mode 100644 index 0000000000000..f22265b4f170b --- /dev/null +++ b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts @@ -0,0 +1,50 @@ +// @erasableSyntaxOnly: true +// @noEmit: true +// @filename: decl.d.ts + +// Diffs from the other test: +// - Parameter properties are already banned in .d.ts files + +namespace IllegalBecauseInstantiated { + export const m = 1; +} + +namespace AlsoIllegalBecauseInstantiated { + class PrivateClass { + + } +} + +enum NotLegalEnum { + B = 1 +} + +const enum NotLegalConstEnum { + C = 2 +} + +// No errors after this point +class MyClassOk { + // Not a parameter property, ok + constructor(foo: string); +} +namespace NotInstantiated { + export interface JustAType { } + export type ATypeInANamespace = {}; +} +declare namespace AmbientIsNotInstantiated { + export const stillOk = 12; +} + +declare enum LegalEnum { + A = 1 +} + +declare namespace AmbientStuff { + namespace Nested { + export const stillOk = 12; + } + enum EnumInAmbientContext { + B = 1 + } +} From 52a5578ef9d593104562e830a037be5516121070 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 22 Jan 2025 08:31:45 -0800 Subject: [PATCH 05/12] Add declaration file version of this test --- .../erasableSyntaxOnlyDeclaration.errors.txt | 61 +++++++++ .../erasableSyntaxOnlyDeclaration.symbols | 89 +++++++++++++ .../erasableSyntaxOnlyDeclaration.types | 121 ++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt create mode 100644 tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols create mode 100644 tests/baselines/reference/erasableSyntaxOnlyDeclaration.types diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt new file mode 100644 index 0000000000000..172e183b773a9 --- /dev/null +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt @@ -0,0 +1,61 @@ +decl.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. +decl.d.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +decl.d.ts(3,17): error TS2369: A parameter property is only allowed in a constructor implementation. + + +==== decl.d.ts (3 errors) ==== + class MyClassErr { + ~~~~~ +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. + // No parameter properties + constructor(public foo: string); + ~~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. + ~~~~~~~~~~~~~~~~~~ +!!! error TS2369: A parameter property is only allowed in a constructor implementation. + } + + namespace IllegalBecauseInstantiated { + export const m = 1; + } + + namespace AlsoIllegalBecauseInstantiated { + class PrivateClass { + + } + } + + enum NotLegalEnum { + B = 1 + } + + const enum NotLegalConstEnum { + C = 2 + } + + // No errors after this point + class MyClassOk { + // Not a parameter property, ok + constructor(foo: string); + } + namespace NotInstantiated { + export interface JustAType { } + export type ATypeInANamespace = {}; + } + declare namespace AmbientIsNotInstantiated { + export const stillOk = 12; + } + + declare enum LegalEnum { + A = 1 + } + + declare namespace AmbientStuff { + namespace Nested { + export const stillOk = 12; + } + enum EnumInAmbientContext { + B = 1 + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols new file mode 100644 index 0000000000000..bf84a5ff6c0a9 --- /dev/null +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols @@ -0,0 +1,89 @@ +//// [tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts] //// + +=== decl.d.ts === +class MyClassErr { +>MyClassErr : Symbol(MyClassErr, Decl(decl.d.ts, 0, 0)) + + // No parameter properties + constructor(public foo: string); +>foo : Symbol(MyClassErr.foo, Decl(decl.d.ts, 2, 16)) +} + +namespace IllegalBecauseInstantiated { +>IllegalBecauseInstantiated : Symbol(IllegalBecauseInstantiated, Decl(decl.d.ts, 3, 1)) + + export const m = 1; +>m : Symbol(m, Decl(decl.d.ts, 6, 16)) +} + +namespace AlsoIllegalBecauseInstantiated { +>AlsoIllegalBecauseInstantiated : Symbol(AlsoIllegalBecauseInstantiated, Decl(decl.d.ts, 7, 1)) + + class PrivateClass { +>PrivateClass : Symbol(PrivateClass, Decl(decl.d.ts, 9, 42)) + + } +} + +enum NotLegalEnum { +>NotLegalEnum : Symbol(NotLegalEnum, Decl(decl.d.ts, 13, 1)) + + B = 1 +>B : Symbol(NotLegalEnum.B, Decl(decl.d.ts, 15, 19)) +} + +const enum NotLegalConstEnum { +>NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(decl.d.ts, 17, 1)) + + C = 2 +>C : Symbol(NotLegalConstEnum.C, Decl(decl.d.ts, 19, 30)) +} + +// No errors after this point +class MyClassOk { +>MyClassOk : Symbol(MyClassOk, Decl(decl.d.ts, 21, 1)) + + // Not a parameter property, ok + constructor(foo: string); +>foo : Symbol(foo, Decl(decl.d.ts, 26, 16)) +} +namespace NotInstantiated { +>NotInstantiated : Symbol(NotInstantiated, Decl(decl.d.ts, 27, 1)) + + export interface JustAType { } +>JustAType : Symbol(JustAType, Decl(decl.d.ts, 28, 27)) + + export type ATypeInANamespace = {}; +>ATypeInANamespace : Symbol(ATypeInANamespace, Decl(decl.d.ts, 29, 34)) +} +declare namespace AmbientIsNotInstantiated { +>AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(decl.d.ts, 31, 1)) + + export const stillOk = 12; +>stillOk : Symbol(stillOk, Decl(decl.d.ts, 33, 16)) +} + +declare enum LegalEnum { +>LegalEnum : Symbol(LegalEnum, Decl(decl.d.ts, 34, 1)) + + A = 1 +>A : Symbol(LegalEnum.A, Decl(decl.d.ts, 36, 24)) +} + +declare namespace AmbientStuff { +>AmbientStuff : Symbol(AmbientStuff, Decl(decl.d.ts, 38, 1)) + + namespace Nested { +>Nested : Symbol(Nested, Decl(decl.d.ts, 40, 32)) + + export const stillOk = 12; +>stillOk : Symbol(stillOk, Decl(decl.d.ts, 42, 20)) + } + enum EnumInAmbientContext { +>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(decl.d.ts, 43, 5)) + + B = 1 +>B : Symbol(EnumInAmbientContext.B, Decl(decl.d.ts, 44, 31)) + } +} + diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types new file mode 100644 index 0000000000000..f3a963e3643ec --- /dev/null +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types @@ -0,0 +1,121 @@ +//// [tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts] //// + +=== decl.d.ts === +class MyClassErr { +>MyClassErr : MyClassErr +> : ^^^^^^^^^^ + + // No parameter properties + constructor(public foo: string); +>foo : string +> : ^^^^^^ +} + +namespace IllegalBecauseInstantiated { +>IllegalBecauseInstantiated : typeof IllegalBecauseInstantiated +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + export const m = 1; +>m : 1 +> : ^ +>1 : 1 +> : ^ +} + +namespace AlsoIllegalBecauseInstantiated { +>AlsoIllegalBecauseInstantiated : typeof AlsoIllegalBecauseInstantiated +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + class PrivateClass { +>PrivateClass : PrivateClass +> : ^^^^^^^^^^^^ + + } +} + +enum NotLegalEnum { +>NotLegalEnum : NotLegalEnum +> : ^^^^^^^^^^^^ + + B = 1 +>B : NotLegalEnum.B +> : ^^^^^^^^^^^^^^ +>1 : 1 +> : ^ +} + +const enum NotLegalConstEnum { +>NotLegalConstEnum : NotLegalConstEnum +> : ^^^^^^^^^^^^^^^^^ + + C = 2 +>C : NotLegalConstEnum.C +> : ^^^^^^^^^^^^^^^^^^^ +>2 : 2 +> : ^ +} + +// No errors after this point +class MyClassOk { +>MyClassOk : MyClassOk +> : ^^^^^^^^^ + + // Not a parameter property, ok + constructor(foo: string); +>foo : string +> : ^^^^^^ +} +namespace NotInstantiated { + export interface JustAType { } + export type ATypeInANamespace = {}; +>ATypeInANamespace : ATypeInANamespace +> : ^^^^^^^^^^^^^^^^^ +} +declare namespace AmbientIsNotInstantiated { +>AmbientIsNotInstantiated : typeof AmbientIsNotInstantiated +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + export const stillOk = 12; +>stillOk : 12 +> : ^^ +>12 : 12 +> : ^^ +} + +declare enum LegalEnum { +>LegalEnum : LegalEnum +> : ^^^^^^^^^ + + A = 1 +>A : LegalEnum.A +> : ^^^^^^^^^^^ +>1 : 1 +> : ^ +} + +declare namespace AmbientStuff { +>AmbientStuff : typeof AmbientStuff +> : ^^^^^^^^^^^^^^^^^^^ + + namespace Nested { +>Nested : typeof Nested +> : ^^^^^^^^^^^^^ + + export const stillOk = 12; +>stillOk : 12 +> : ^^ +>12 : 12 +> : ^^ + } + enum EnumInAmbientContext { +>EnumInAmbientContext : EnumInAmbientContext +> : ^^^^^^^^^^^^^^^^^^^^ + + B = 1 +>B : EnumInAmbientContext.B +> : ^^^^^^^^^^^^^^^^^^^^^^ +>1 : 1 +> : ^ + } +} + From 173c7850782e37980e217c88e77b9c0d6cb4cd33 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 22 Jan 2025 08:49:09 -0800 Subject: [PATCH 06/12] Also ban `import =` --- src/compiler/checker.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 359ff49f1e10c..174dd27f49797 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -47507,7 +47507,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { checkExportsOnMergedDeclarations(node); node.members.forEach(checkEnumMember); - if (compilerOptions.erasableSyntaxOnly && (node.flags & NodeFlags.Ambient) === 0) { + if (compilerOptions.erasableSyntaxOnly && !(node.flags & NodeFlags.Ambient)) { error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled); } @@ -48166,7 +48166,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } checkGrammarModifiers(node); - if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { + const isImportEquals = isInternalModuleImportEqualsDeclaration(node); + if (compilerOptions.erasableSyntaxOnly && isImportEquals && !(node.flags & NodeFlags.Ambient)) { + error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled); + } + if (isImportEquals || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); markLinkedReferences(node, ReferenceHint.ExportImportEquals); if (node.moduleReference.kind !== SyntaxKind.ExternalModuleReference) { From 213d91baa0cbe7e54473c73bb89004957a11b6d7 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 22 Jan 2025 08:49:15 -0800 Subject: [PATCH 07/12] Update test --- .../reference/erasableSyntaxOnly.errors.txt | 11 +++- .../reference/erasableSyntaxOnly.symbols | 44 +++++++++------ .../reference/erasableSyntaxOnly.types | 16 ++++++ .../erasableSyntaxOnlyDeclaration.errors.txt | 20 +++---- .../erasableSyntaxOnlyDeclaration.symbols | 53 +++++++++---------- .../erasableSyntaxOnlyDeclaration.types | 11 +--- tests/cases/compiler/erasableSyntaxOnly.ts | 4 ++ 7 files changed, 88 insertions(+), 71 deletions(-) diff --git a/tests/baselines/reference/erasableSyntaxOnly.errors.txt b/tests/baselines/reference/erasableSyntaxOnly.errors.txt index 83ad15aec09b5..1f53a955e38a0 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnly.errors.txt @@ -2,10 +2,11 @@ erasableSyntaxOnly.ts(3,17): error TS1294: This syntax is not allowed when 'eras erasableSyntaxOnly.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. erasableSyntaxOnly.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. erasableSyntaxOnly.ts(16,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -erasableSyntaxOnly.ts(20,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(20,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(22,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -==== erasableSyntaxOnly.ts (5 errors) ==== +==== erasableSyntaxOnly.ts (6 errors) ==== class MyClassErr { // No parameter properties constructor(public foo: string) { } @@ -33,6 +34,10 @@ erasableSyntaxOnly.ts(20,12): error TS1294: This syntax is not allowed when 'era 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. @@ -63,5 +68,7 @@ erasableSyntaxOnly.ts(20,12): error TS1294: This syntax is not allowed when 'era enum EnumInAmbientContext { B = 1 } + + import FineAlias = EnumInAmbientContext.B; } \ No newline at end of file diff --git a/tests/baselines/reference/erasableSyntaxOnly.symbols b/tests/baselines/reference/erasableSyntaxOnly.symbols index d1a0c94c3c7dd..2632c7b6edaed 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.symbols +++ b/tests/baselines/reference/erasableSyntaxOnly.symbols @@ -29,61 +29,71 @@ enum NotLegalEnum { >NotLegalEnum : Symbol(NotLegalEnum, Decl(erasableSyntaxOnly.ts, 13, 1)) B = 1 ->B : Symbol(NotLegalEnum.B, Decl(erasableSyntaxOnly.ts, 15, 19)) +>B : Symbol(NoGoodAlias, Decl(erasableSyntaxOnly.ts, 15, 19)) } +import NoGoodAlias = NotLegalEnum.B; +>NoGoodAlias : Symbol(NoGoodAlias, Decl(erasableSyntaxOnly.ts, 17, 1)) +>NotLegalEnum : Symbol(NotLegalEnum, Decl(erasableSyntaxOnly.ts, 13, 1)) +>B : Symbol(NoGoodAlias, Decl(erasableSyntaxOnly.ts, 15, 19)) + const enum NotLegalConstEnum { ->NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(erasableSyntaxOnly.ts, 17, 1)) +>NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(erasableSyntaxOnly.ts, 19, 36)) C = 2 ->C : Symbol(NotLegalConstEnum.C, Decl(erasableSyntaxOnly.ts, 19, 30)) +>C : Symbol(NotLegalConstEnum.C, Decl(erasableSyntaxOnly.ts, 21, 30)) } // No errors after this point class MyClassOk { ->MyClassOk : Symbol(MyClassOk, Decl(erasableSyntaxOnly.ts, 21, 1)) +>MyClassOk : Symbol(MyClassOk, Decl(erasableSyntaxOnly.ts, 23, 1)) // Not a parameter property, ok constructor(foo: string) { } ->foo : Symbol(foo, Decl(erasableSyntaxOnly.ts, 26, 16)) +>foo : Symbol(foo, Decl(erasableSyntaxOnly.ts, 28, 16)) } namespace NotInstantiated { ->NotInstantiated : Symbol(NotInstantiated, Decl(erasableSyntaxOnly.ts, 27, 1)) +>NotInstantiated : Symbol(NotInstantiated, Decl(erasableSyntaxOnly.ts, 29, 1)) export interface JustAType { } ->JustAType : Symbol(JustAType, Decl(erasableSyntaxOnly.ts, 28, 27)) +>JustAType : Symbol(JustAType, Decl(erasableSyntaxOnly.ts, 30, 27)) export type ATypeInANamespace = {}; ->ATypeInANamespace : Symbol(ATypeInANamespace, Decl(erasableSyntaxOnly.ts, 29, 34)) +>ATypeInANamespace : Symbol(ATypeInANamespace, Decl(erasableSyntaxOnly.ts, 31, 34)) } declare namespace AmbientIsNotInstantiated { ->AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(erasableSyntaxOnly.ts, 31, 1)) +>AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(erasableSyntaxOnly.ts, 33, 1)) export const stillOk = 12; ->stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 33, 16)) +>stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 35, 16)) } declare enum LegalEnum { ->LegalEnum : Symbol(LegalEnum, Decl(erasableSyntaxOnly.ts, 34, 1)) +>LegalEnum : Symbol(LegalEnum, Decl(erasableSyntaxOnly.ts, 36, 1)) A = 1 ->A : Symbol(LegalEnum.A, Decl(erasableSyntaxOnly.ts, 36, 24)) +>A : Symbol(LegalEnum.A, Decl(erasableSyntaxOnly.ts, 38, 24)) } declare namespace AmbientStuff { ->AmbientStuff : Symbol(AmbientStuff, Decl(erasableSyntaxOnly.ts, 38, 1)) +>AmbientStuff : Symbol(AmbientStuff, Decl(erasableSyntaxOnly.ts, 40, 1)) namespace Nested { ->Nested : Symbol(Nested, Decl(erasableSyntaxOnly.ts, 40, 32)) +>Nested : Symbol(Nested, Decl(erasableSyntaxOnly.ts, 42, 32)) export const stillOk = 12; ->stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 42, 20)) +>stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 44, 20)) } enum EnumInAmbientContext { ->EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(erasableSyntaxOnly.ts, 43, 5)) +>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(erasableSyntaxOnly.ts, 45, 5)) B = 1 ->B : Symbol(EnumInAmbientContext.B, Decl(erasableSyntaxOnly.ts, 44, 31)) +>B : Symbol(FineAlias, Decl(erasableSyntaxOnly.ts, 46, 31)) } + + import FineAlias = EnumInAmbientContext.B; +>FineAlias : Symbol(FineAlias, Decl(erasableSyntaxOnly.ts, 48, 5)) +>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(erasableSyntaxOnly.ts, 45, 5)) +>B : Symbol(FineAlias, Decl(erasableSyntaxOnly.ts, 46, 31)) } diff --git a/tests/baselines/reference/erasableSyntaxOnly.types b/tests/baselines/reference/erasableSyntaxOnly.types index f67c7a8062cb0..07b8585787deb 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.types +++ b/tests/baselines/reference/erasableSyntaxOnly.types @@ -44,6 +44,14 @@ enum NotLegalEnum { > : ^ } +import NoGoodAlias = NotLegalEnum.B; +>NoGoodAlias : NotLegalEnum.B +> : ^^^^^^^^^^^^^^ +>NotLegalEnum : NotLegalEnum +> : ^^^^^^^^^^^^ +>B : NotLegalEnum.B +> : ^^^^^^^^^^^^^^ + const enum NotLegalConstEnum { >NotLegalConstEnum : NotLegalConstEnum > : ^^^^^^^^^^^^^^^^^ @@ -117,5 +125,13 @@ declare namespace AmbientStuff { >1 : 1 > : ^ } + + import FineAlias = EnumInAmbientContext.B; +>FineAlias : EnumInAmbientContext.B +> : ^^^^^^^^^^^^^^^^^^^^^^ +>EnumInAmbientContext : EnumInAmbientContext +> : ^^^^^^^^^^^^^^^^^^^^ +>B : EnumInAmbientContext.B +> : ^^^^^^^^^^^^^^^^^^^^^^ } diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt index 172e183b773a9..999cf9c8d7cb9 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt @@ -1,21 +1,13 @@ -decl.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. -decl.d.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -decl.d.ts(3,17): error TS2369: A parameter property is only allowed in a constructor implementation. +decl.d.ts(4,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. -==== decl.d.ts (3 errors) ==== - class MyClassErr { - ~~~~~ -!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. - // No parameter properties - constructor(public foo: string); - ~~~~~~~~~~~~~~~~~~ -!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - ~~~~~~~~~~~~~~~~~~ -!!! error TS2369: A parameter property is only allowed in a constructor implementation. - } +==== decl.d.ts (1 errors) ==== + // Diffs from the other test: + // - Parameter properties are already banned in .d.ts files namespace IllegalBecauseInstantiated { + ~~~~~~~~~ +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. export const m = 1; } diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols index bf84a5ff6c0a9..7957cd6709fe4 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols @@ -1,89 +1,84 @@ //// [tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts] //// === decl.d.ts === -class MyClassErr { ->MyClassErr : Symbol(MyClassErr, Decl(decl.d.ts, 0, 0)) - - // No parameter properties - constructor(public foo: string); ->foo : Symbol(MyClassErr.foo, Decl(decl.d.ts, 2, 16)) -} +// Diffs from the other test: +// - Parameter properties are already banned in .d.ts files namespace IllegalBecauseInstantiated { ->IllegalBecauseInstantiated : Symbol(IllegalBecauseInstantiated, Decl(decl.d.ts, 3, 1)) +>IllegalBecauseInstantiated : Symbol(IllegalBecauseInstantiated, Decl(decl.d.ts, 0, 0)) export const m = 1; ->m : Symbol(m, Decl(decl.d.ts, 6, 16)) +>m : Symbol(m, Decl(decl.d.ts, 4, 16)) } namespace AlsoIllegalBecauseInstantiated { ->AlsoIllegalBecauseInstantiated : Symbol(AlsoIllegalBecauseInstantiated, Decl(decl.d.ts, 7, 1)) +>AlsoIllegalBecauseInstantiated : Symbol(AlsoIllegalBecauseInstantiated, Decl(decl.d.ts, 5, 1)) class PrivateClass { ->PrivateClass : Symbol(PrivateClass, Decl(decl.d.ts, 9, 42)) +>PrivateClass : Symbol(PrivateClass, Decl(decl.d.ts, 7, 42)) } } enum NotLegalEnum { ->NotLegalEnum : Symbol(NotLegalEnum, Decl(decl.d.ts, 13, 1)) +>NotLegalEnum : Symbol(NotLegalEnum, Decl(decl.d.ts, 11, 1)) B = 1 ->B : Symbol(NotLegalEnum.B, Decl(decl.d.ts, 15, 19)) +>B : Symbol(NotLegalEnum.B, Decl(decl.d.ts, 13, 19)) } const enum NotLegalConstEnum { ->NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(decl.d.ts, 17, 1)) +>NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(decl.d.ts, 15, 1)) C = 2 ->C : Symbol(NotLegalConstEnum.C, Decl(decl.d.ts, 19, 30)) +>C : Symbol(NotLegalConstEnum.C, Decl(decl.d.ts, 17, 30)) } // No errors after this point class MyClassOk { ->MyClassOk : Symbol(MyClassOk, Decl(decl.d.ts, 21, 1)) +>MyClassOk : Symbol(MyClassOk, Decl(decl.d.ts, 19, 1)) // Not a parameter property, ok constructor(foo: string); ->foo : Symbol(foo, Decl(decl.d.ts, 26, 16)) +>foo : Symbol(foo, Decl(decl.d.ts, 24, 16)) } namespace NotInstantiated { ->NotInstantiated : Symbol(NotInstantiated, Decl(decl.d.ts, 27, 1)) +>NotInstantiated : Symbol(NotInstantiated, Decl(decl.d.ts, 25, 1)) export interface JustAType { } ->JustAType : Symbol(JustAType, Decl(decl.d.ts, 28, 27)) +>JustAType : Symbol(JustAType, Decl(decl.d.ts, 26, 27)) export type ATypeInANamespace = {}; ->ATypeInANamespace : Symbol(ATypeInANamespace, Decl(decl.d.ts, 29, 34)) +>ATypeInANamespace : Symbol(ATypeInANamespace, Decl(decl.d.ts, 27, 34)) } declare namespace AmbientIsNotInstantiated { ->AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(decl.d.ts, 31, 1)) +>AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(decl.d.ts, 29, 1)) export const stillOk = 12; ->stillOk : Symbol(stillOk, Decl(decl.d.ts, 33, 16)) +>stillOk : Symbol(stillOk, Decl(decl.d.ts, 31, 16)) } declare enum LegalEnum { ->LegalEnum : Symbol(LegalEnum, Decl(decl.d.ts, 34, 1)) +>LegalEnum : Symbol(LegalEnum, Decl(decl.d.ts, 32, 1)) A = 1 ->A : Symbol(LegalEnum.A, Decl(decl.d.ts, 36, 24)) +>A : Symbol(LegalEnum.A, Decl(decl.d.ts, 34, 24)) } declare namespace AmbientStuff { ->AmbientStuff : Symbol(AmbientStuff, Decl(decl.d.ts, 38, 1)) +>AmbientStuff : Symbol(AmbientStuff, Decl(decl.d.ts, 36, 1)) namespace Nested { ->Nested : Symbol(Nested, Decl(decl.d.ts, 40, 32)) +>Nested : Symbol(Nested, Decl(decl.d.ts, 38, 32)) export const stillOk = 12; ->stillOk : Symbol(stillOk, Decl(decl.d.ts, 42, 20)) +>stillOk : Symbol(stillOk, Decl(decl.d.ts, 40, 20)) } enum EnumInAmbientContext { ->EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(decl.d.ts, 43, 5)) +>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(decl.d.ts, 41, 5)) B = 1 ->B : Symbol(EnumInAmbientContext.B, Decl(decl.d.ts, 44, 31)) +>B : Symbol(EnumInAmbientContext.B, Decl(decl.d.ts, 42, 31)) } } diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types index f3a963e3643ec..53ba9aa148cb3 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types @@ -1,15 +1,8 @@ //// [tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts] //// === decl.d.ts === -class MyClassErr { ->MyClassErr : MyClassErr -> : ^^^^^^^^^^ - - // No parameter properties - constructor(public foo: string); ->foo : string -> : ^^^^^^ -} +// Diffs from the other test: +// - Parameter properties are already banned in .d.ts files namespace IllegalBecauseInstantiated { >IllegalBecauseInstantiated : typeof IllegalBecauseInstantiated diff --git a/tests/cases/compiler/erasableSyntaxOnly.ts b/tests/cases/compiler/erasableSyntaxOnly.ts index 759b89a8c0e33..5fdc510b66e7f 100644 --- a/tests/cases/compiler/erasableSyntaxOnly.ts +++ b/tests/cases/compiler/erasableSyntaxOnly.ts @@ -20,6 +20,8 @@ enum NotLegalEnum { B = 1 } +import NoGoodAlias = NotLegalEnum.B; + const enum NotLegalConstEnum { C = 2 } @@ -48,4 +50,6 @@ declare namespace AmbientStuff { enum EnumInAmbientContext { B = 1 } + + import FineAlias = EnumInAmbientContext.B; } From c0cdb9a196008679dc51262438a5aa61f9f8abd8 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 23 Jan 2025 15:19:51 -0800 Subject: [PATCH 08/12] Update other test --- .../erasableSyntaxOnlyDeclaration.errors.txt | 4 ++ .../erasableSyntaxOnlyDeclaration.symbols | 44 ++++++++++++------- .../erasableSyntaxOnlyDeclaration.types | 16 +++++++ .../compiler/erasableSyntaxOnlyDeclaration.ts | 4 ++ 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt index 999cf9c8d7cb9..c2848cc7f8c46 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt @@ -21,6 +21,8 @@ decl.d.ts(4,1): error TS1046: Top-level declarations in .d.ts files must start w B = 1 } + import NoGoodAlias = NotLegalEnum.B; + const enum NotLegalConstEnum { C = 2 } @@ -49,5 +51,7 @@ decl.d.ts(4,1): error TS1046: Top-level declarations in .d.ts files must start w enum EnumInAmbientContext { B = 1 } + + import FineAlias = EnumInAmbientContext.B; } \ No newline at end of file diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols index 7957cd6709fe4..86c78be82de7e 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols @@ -24,61 +24,71 @@ enum NotLegalEnum { >NotLegalEnum : Symbol(NotLegalEnum, Decl(decl.d.ts, 11, 1)) B = 1 ->B : Symbol(NotLegalEnum.B, Decl(decl.d.ts, 13, 19)) +>B : Symbol(NoGoodAlias, Decl(decl.d.ts, 13, 19)) } +import NoGoodAlias = NotLegalEnum.B; +>NoGoodAlias : Symbol(NoGoodAlias, Decl(decl.d.ts, 15, 1)) +>NotLegalEnum : Symbol(NotLegalEnum, Decl(decl.d.ts, 11, 1)) +>B : Symbol(NoGoodAlias, Decl(decl.d.ts, 13, 19)) + const enum NotLegalConstEnum { ->NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(decl.d.ts, 15, 1)) +>NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(decl.d.ts, 17, 36)) C = 2 ->C : Symbol(NotLegalConstEnum.C, Decl(decl.d.ts, 17, 30)) +>C : Symbol(NotLegalConstEnum.C, Decl(decl.d.ts, 19, 30)) } // No errors after this point class MyClassOk { ->MyClassOk : Symbol(MyClassOk, Decl(decl.d.ts, 19, 1)) +>MyClassOk : Symbol(MyClassOk, Decl(decl.d.ts, 21, 1)) // Not a parameter property, ok constructor(foo: string); ->foo : Symbol(foo, Decl(decl.d.ts, 24, 16)) +>foo : Symbol(foo, Decl(decl.d.ts, 26, 16)) } namespace NotInstantiated { ->NotInstantiated : Symbol(NotInstantiated, Decl(decl.d.ts, 25, 1)) +>NotInstantiated : Symbol(NotInstantiated, Decl(decl.d.ts, 27, 1)) export interface JustAType { } ->JustAType : Symbol(JustAType, Decl(decl.d.ts, 26, 27)) +>JustAType : Symbol(JustAType, Decl(decl.d.ts, 28, 27)) export type ATypeInANamespace = {}; ->ATypeInANamespace : Symbol(ATypeInANamespace, Decl(decl.d.ts, 27, 34)) +>ATypeInANamespace : Symbol(ATypeInANamespace, Decl(decl.d.ts, 29, 34)) } declare namespace AmbientIsNotInstantiated { ->AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(decl.d.ts, 29, 1)) +>AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(decl.d.ts, 31, 1)) export const stillOk = 12; ->stillOk : Symbol(stillOk, Decl(decl.d.ts, 31, 16)) +>stillOk : Symbol(stillOk, Decl(decl.d.ts, 33, 16)) } declare enum LegalEnum { ->LegalEnum : Symbol(LegalEnum, Decl(decl.d.ts, 32, 1)) +>LegalEnum : Symbol(LegalEnum, Decl(decl.d.ts, 34, 1)) A = 1 ->A : Symbol(LegalEnum.A, Decl(decl.d.ts, 34, 24)) +>A : Symbol(LegalEnum.A, Decl(decl.d.ts, 36, 24)) } declare namespace AmbientStuff { ->AmbientStuff : Symbol(AmbientStuff, Decl(decl.d.ts, 36, 1)) +>AmbientStuff : Symbol(AmbientStuff, Decl(decl.d.ts, 38, 1)) namespace Nested { ->Nested : Symbol(Nested, Decl(decl.d.ts, 38, 32)) +>Nested : Symbol(Nested, Decl(decl.d.ts, 40, 32)) export const stillOk = 12; ->stillOk : Symbol(stillOk, Decl(decl.d.ts, 40, 20)) +>stillOk : Symbol(stillOk, Decl(decl.d.ts, 42, 20)) } enum EnumInAmbientContext { ->EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(decl.d.ts, 41, 5)) +>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(decl.d.ts, 43, 5)) B = 1 ->B : Symbol(EnumInAmbientContext.B, Decl(decl.d.ts, 42, 31)) +>B : Symbol(FineAlias, Decl(decl.d.ts, 44, 31)) } + + import FineAlias = EnumInAmbientContext.B; +>FineAlias : Symbol(FineAlias, Decl(decl.d.ts, 46, 5)) +>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(decl.d.ts, 43, 5)) +>B : Symbol(FineAlias, Decl(decl.d.ts, 44, 31)) } diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types index 53ba9aa148cb3..4560d040581d6 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types @@ -37,6 +37,14 @@ enum NotLegalEnum { > : ^ } +import NoGoodAlias = NotLegalEnum.B; +>NoGoodAlias : NotLegalEnum.B +> : ^^^^^^^^^^^^^^ +>NotLegalEnum : NotLegalEnum +> : ^^^^^^^^^^^^ +>B : NotLegalEnum.B +> : ^^^^^^^^^^^^^^ + const enum NotLegalConstEnum { >NotLegalConstEnum : NotLegalConstEnum > : ^^^^^^^^^^^^^^^^^ @@ -110,5 +118,13 @@ declare namespace AmbientStuff { >1 : 1 > : ^ } + + import FineAlias = EnumInAmbientContext.B; +>FineAlias : EnumInAmbientContext.B +> : ^^^^^^^^^^^^^^^^^^^^^^ +>EnumInAmbientContext : EnumInAmbientContext +> : ^^^^^^^^^^^^^^^^^^^^ +>B : EnumInAmbientContext.B +> : ^^^^^^^^^^^^^^^^^^^^^^ } diff --git a/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts index f22265b4f170b..cf1ad5132e204 100644 --- a/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts +++ b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts @@ -19,6 +19,8 @@ enum NotLegalEnum { B = 1 } +import NoGoodAlias = NotLegalEnum.B; + const enum NotLegalConstEnum { C = 2 } @@ -47,4 +49,6 @@ declare namespace AmbientStuff { enum EnumInAmbientContext { B = 1 } + + import FineAlias = EnumInAmbientContext.B; } From 5042fc10123ca74ff4153e17621d02f31f424d59 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 23 Jan 2025 15:30:08 -0800 Subject: [PATCH 09/12] Update tests/cases/compiler/erasableSyntaxOnly.ts Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com> --- tests/cases/compiler/erasableSyntaxOnly.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cases/compiler/erasableSyntaxOnly.ts b/tests/cases/compiler/erasableSyntaxOnly.ts index 5fdc510b66e7f..f05b2d3717977 100644 --- a/tests/cases/compiler/erasableSyntaxOnly.ts +++ b/tests/cases/compiler/erasableSyntaxOnly.ts @@ -16,6 +16,12 @@ namespace AlsoIllegalBecauseInstantiated { } } +namespace IllegalBecauseNestedInstantiated { + namespace Nested { + export const m = 1; + } +} + enum NotLegalEnum { B = 1 } From 313beee34bd72bcd59c62a9f8f01273b0a370ea3 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 23 Jan 2025 15:30:52 -0800 Subject: [PATCH 10/12] Update tests/cases/compiler/erasableSyntaxOnly.ts Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com> --- tests/cases/compiler/erasableSyntaxOnly.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/cases/compiler/erasableSyntaxOnly.ts b/tests/cases/compiler/erasableSyntaxOnly.ts index f05b2d3717977..9ab7227427dde 100644 --- a/tests/cases/compiler/erasableSyntaxOnly.ts +++ b/tests/cases/compiler/erasableSyntaxOnly.ts @@ -40,6 +40,9 @@ class MyClassOk { namespace NotInstantiated { export interface JustAType { } export type ATypeInANamespace = {}; + namespace Nested { + export type ATypeInANamespace = {}; + } } declare namespace AmbientIsNotInstantiated { export const stillOk = 12; From be992fa05ec116cdbfbba2e89dd57fb5c2d4471e Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 23 Jan 2025 15:32:41 -0800 Subject: [PATCH 11/12] Update tests --- .../reference/erasableSyntaxOnly.errors.txt | 26 +++++-- .../reference/erasableSyntaxOnly.symbols | 69 ++++++++++++------- .../reference/erasableSyntaxOnly.types | 25 +++++++ tests/cases/compiler/erasableSyntaxOnly.ts | 3 + 4 files changed, 95 insertions(+), 28 deletions(-) diff --git a/tests/baselines/reference/erasableSyntaxOnly.errors.txt b/tests/baselines/reference/erasableSyntaxOnly.errors.txt index 1f53a955e38a0..ceb1a3a9d9466 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnly.errors.txt @@ -1,12 +1,14 @@ erasableSyntaxOnly.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. erasableSyntaxOnly.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. erasableSyntaxOnly.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -erasableSyntaxOnly.ts(16,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -erasableSyntaxOnly.ts(20,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -erasableSyntaxOnly.ts(22,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(16,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(17,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(22,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(26,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -==== erasableSyntaxOnly.ts (6 errors) ==== +==== erasableSyntaxOnly.ts (8 errors) ==== class MyClassErr { // No parameter properties constructor(public foo: string) { } @@ -28,6 +30,16 @@ erasableSyntaxOnly.ts(22,12): error TS1294: This syntax is not allowed when 'era } } + 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. @@ -49,9 +61,15 @@ erasableSyntaxOnly.ts(22,12): error TS1294: This syntax is not allowed when 'era // Not a parameter property, ok constructor(foo: string) { } } + + // Note for implementors: This should not be an error + // as this entire namespace block is fully erased namespace NotInstantiated { export interface JustAType { } export type ATypeInANamespace = {}; + namespace Nested { + export type ATypeInANamespace = {}; + } } declare namespace AmbientIsNotInstantiated { export const stillOk = 12; diff --git a/tests/baselines/reference/erasableSyntaxOnly.symbols b/tests/baselines/reference/erasableSyntaxOnly.symbols index 2632c7b6edaed..27e4938a13dce 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.symbols +++ b/tests/baselines/reference/erasableSyntaxOnly.symbols @@ -25,75 +25,96 @@ namespace AlsoIllegalBecauseInstantiated { } } +namespace IllegalBecauseNestedInstantiated { +>IllegalBecauseNestedInstantiated : Symbol(IllegalBecauseNestedInstantiated, Decl(erasableSyntaxOnly.ts, 13, 1)) + + namespace Nested { +>Nested : Symbol(Nested, Decl(erasableSyntaxOnly.ts, 15, 44)) + + export const m = 1; +>m : Symbol(m, Decl(erasableSyntaxOnly.ts, 17, 14)) + } +} + enum NotLegalEnum { ->NotLegalEnum : Symbol(NotLegalEnum, Decl(erasableSyntaxOnly.ts, 13, 1)) +>NotLegalEnum : Symbol(NotLegalEnum, Decl(erasableSyntaxOnly.ts, 19, 1)) B = 1 ->B : Symbol(NoGoodAlias, Decl(erasableSyntaxOnly.ts, 15, 19)) +>B : Symbol(NoGoodAlias, Decl(erasableSyntaxOnly.ts, 21, 19)) } import NoGoodAlias = NotLegalEnum.B; ->NoGoodAlias : Symbol(NoGoodAlias, Decl(erasableSyntaxOnly.ts, 17, 1)) ->NotLegalEnum : Symbol(NotLegalEnum, Decl(erasableSyntaxOnly.ts, 13, 1)) ->B : Symbol(NoGoodAlias, Decl(erasableSyntaxOnly.ts, 15, 19)) +>NoGoodAlias : Symbol(NoGoodAlias, Decl(erasableSyntaxOnly.ts, 23, 1)) +>NotLegalEnum : Symbol(NotLegalEnum, Decl(erasableSyntaxOnly.ts, 19, 1)) +>B : Symbol(NoGoodAlias, Decl(erasableSyntaxOnly.ts, 21, 19)) const enum NotLegalConstEnum { ->NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(erasableSyntaxOnly.ts, 19, 36)) +>NotLegalConstEnum : Symbol(NotLegalConstEnum, Decl(erasableSyntaxOnly.ts, 25, 36)) C = 2 ->C : Symbol(NotLegalConstEnum.C, Decl(erasableSyntaxOnly.ts, 21, 30)) +>C : Symbol(NotLegalConstEnum.C, Decl(erasableSyntaxOnly.ts, 27, 30)) } // No errors after this point class MyClassOk { ->MyClassOk : Symbol(MyClassOk, Decl(erasableSyntaxOnly.ts, 23, 1)) +>MyClassOk : Symbol(MyClassOk, Decl(erasableSyntaxOnly.ts, 29, 1)) // Not a parameter property, ok constructor(foo: string) { } ->foo : Symbol(foo, Decl(erasableSyntaxOnly.ts, 28, 16)) +>foo : Symbol(foo, Decl(erasableSyntaxOnly.ts, 34, 16)) } + +// Note for implementors: This should not be an error +// as this entire namespace block is fully erased namespace NotInstantiated { ->NotInstantiated : Symbol(NotInstantiated, Decl(erasableSyntaxOnly.ts, 29, 1)) +>NotInstantiated : Symbol(NotInstantiated, Decl(erasableSyntaxOnly.ts, 35, 1)) export interface JustAType { } ->JustAType : Symbol(JustAType, Decl(erasableSyntaxOnly.ts, 30, 27)) +>JustAType : Symbol(JustAType, Decl(erasableSyntaxOnly.ts, 39, 27)) export type ATypeInANamespace = {}; ->ATypeInANamespace : Symbol(ATypeInANamespace, Decl(erasableSyntaxOnly.ts, 31, 34)) +>ATypeInANamespace : Symbol(ATypeInANamespace, Decl(erasableSyntaxOnly.ts, 40, 34)) + + namespace Nested { +>Nested : Symbol(Nested, Decl(erasableSyntaxOnly.ts, 41, 39)) + + export type ATypeInANamespace = {}; +>ATypeInANamespace : Symbol(ATypeInANamespace, Decl(erasableSyntaxOnly.ts, 42, 22)) + } } declare namespace AmbientIsNotInstantiated { ->AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(erasableSyntaxOnly.ts, 33, 1)) +>AmbientIsNotInstantiated : Symbol(AmbientIsNotInstantiated, Decl(erasableSyntaxOnly.ts, 45, 1)) export const stillOk = 12; ->stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 35, 16)) +>stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 47, 16)) } declare enum LegalEnum { ->LegalEnum : Symbol(LegalEnum, Decl(erasableSyntaxOnly.ts, 36, 1)) +>LegalEnum : Symbol(LegalEnum, Decl(erasableSyntaxOnly.ts, 48, 1)) A = 1 ->A : Symbol(LegalEnum.A, Decl(erasableSyntaxOnly.ts, 38, 24)) +>A : Symbol(LegalEnum.A, Decl(erasableSyntaxOnly.ts, 50, 24)) } declare namespace AmbientStuff { ->AmbientStuff : Symbol(AmbientStuff, Decl(erasableSyntaxOnly.ts, 40, 1)) +>AmbientStuff : Symbol(AmbientStuff, Decl(erasableSyntaxOnly.ts, 52, 1)) namespace Nested { ->Nested : Symbol(Nested, Decl(erasableSyntaxOnly.ts, 42, 32)) +>Nested : Symbol(Nested, Decl(erasableSyntaxOnly.ts, 54, 32)) export const stillOk = 12; ->stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 44, 20)) +>stillOk : Symbol(stillOk, Decl(erasableSyntaxOnly.ts, 56, 20)) } enum EnumInAmbientContext { ->EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(erasableSyntaxOnly.ts, 45, 5)) +>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(erasableSyntaxOnly.ts, 57, 5)) B = 1 ->B : Symbol(FineAlias, Decl(erasableSyntaxOnly.ts, 46, 31)) +>B : Symbol(FineAlias, Decl(erasableSyntaxOnly.ts, 58, 31)) } import FineAlias = EnumInAmbientContext.B; ->FineAlias : Symbol(FineAlias, Decl(erasableSyntaxOnly.ts, 48, 5)) ->EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(erasableSyntaxOnly.ts, 45, 5)) ->B : Symbol(FineAlias, Decl(erasableSyntaxOnly.ts, 46, 31)) +>FineAlias : Symbol(FineAlias, Decl(erasableSyntaxOnly.ts, 60, 5)) +>EnumInAmbientContext : Symbol(EnumInAmbientContext, Decl(erasableSyntaxOnly.ts, 57, 5)) +>B : Symbol(FineAlias, Decl(erasableSyntaxOnly.ts, 58, 31)) } diff --git a/tests/baselines/reference/erasableSyntaxOnly.types b/tests/baselines/reference/erasableSyntaxOnly.types index 07b8585787deb..a6b7d53c8550f 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.types +++ b/tests/baselines/reference/erasableSyntaxOnly.types @@ -33,6 +33,22 @@ namespace AlsoIllegalBecauseInstantiated { } } +namespace IllegalBecauseNestedInstantiated { +>IllegalBecauseNestedInstantiated : typeof IllegalBecauseNestedInstantiated +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + namespace Nested { +>Nested : typeof Nested +> : ^^^^^^^^^^^^^ + + export const m = 1; +>m : 1 +> : ^ +>1 : 1 +> : ^ + } +} + enum NotLegalEnum { >NotLegalEnum : NotLegalEnum > : ^^^^^^^^^^^^ @@ -73,11 +89,20 @@ class MyClassOk { >foo : string > : ^^^^^^ } + +// Note for implementors: This should not be an error +// as this entire namespace block is fully erased namespace NotInstantiated { export interface JustAType { } export type ATypeInANamespace = {}; >ATypeInANamespace : ATypeInANamespace > : ^^^^^^^^^^^^^^^^^ + + namespace Nested { + export type ATypeInANamespace = {}; +>ATypeInANamespace : ATypeInANamespace +> : ^^^^^^^^^^^^^^^^^ + } } declare namespace AmbientIsNotInstantiated { >AmbientIsNotInstantiated : typeof AmbientIsNotInstantiated diff --git a/tests/cases/compiler/erasableSyntaxOnly.ts b/tests/cases/compiler/erasableSyntaxOnly.ts index 9ab7227427dde..5e7cfe697502c 100644 --- a/tests/cases/compiler/erasableSyntaxOnly.ts +++ b/tests/cases/compiler/erasableSyntaxOnly.ts @@ -37,6 +37,9 @@ class MyClassOk { // Not a parameter property, ok constructor(foo: string) { } } + +// Note for implementors: This should not be an error +// as this entire namespace block is fully erased namespace NotInstantiated { export interface JustAType { } export type ATypeInANamespace = {}; From 0d6a34e1ba6e0d85cf311d7d94fd1411079e9eaf Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Thu, 23 Jan 2025 15:35:46 -0800 Subject: [PATCH 12/12] tabs lol --- .../baselines/reference/erasableSyntaxOnly.errors.txt | 10 +++++----- tests/baselines/reference/erasableSyntaxOnly.symbols | 8 ++++---- tests/baselines/reference/erasableSyntaxOnly.types | 6 +++--- tests/cases/compiler/erasableSyntaxOnly.ts | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/baselines/reference/erasableSyntaxOnly.errors.txt b/tests/baselines/reference/erasableSyntaxOnly.errors.txt index ceb1a3a9d9466..275430c4361f6 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnly.errors.txt @@ -2,7 +2,7 @@ erasableSyntaxOnly.ts(3,17): error TS1294: This syntax is not allowed when 'eras erasableSyntaxOnly.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. erasableSyntaxOnly.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. erasableSyntaxOnly.ts(16,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -erasableSyntaxOnly.ts(17,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +erasableSyntaxOnly.ts(17,15): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. erasableSyntaxOnly.ts(22,6): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. erasableSyntaxOnly.ts(26,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. erasableSyntaxOnly.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. @@ -33,11 +33,11 @@ erasableSyntaxOnly.ts(28,12): error TS1294: This syntax is not allowed when 'era namespace IllegalBecauseNestedInstantiated { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - namespace Nested { - ~~~~~~ + namespace Nested { + ~~~~~~ !!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. - export const m = 1; - } + export const m = 1; + } } enum NotLegalEnum { diff --git a/tests/baselines/reference/erasableSyntaxOnly.symbols b/tests/baselines/reference/erasableSyntaxOnly.symbols index 27e4938a13dce..508f70b1fad0a 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.symbols +++ b/tests/baselines/reference/erasableSyntaxOnly.symbols @@ -28,12 +28,12 @@ namespace AlsoIllegalBecauseInstantiated { namespace IllegalBecauseNestedInstantiated { >IllegalBecauseNestedInstantiated : Symbol(IllegalBecauseNestedInstantiated, Decl(erasableSyntaxOnly.ts, 13, 1)) - namespace Nested { + namespace Nested { >Nested : Symbol(Nested, Decl(erasableSyntaxOnly.ts, 15, 44)) - export const m = 1; ->m : Symbol(m, Decl(erasableSyntaxOnly.ts, 17, 14)) - } + export const m = 1; +>m : Symbol(m, Decl(erasableSyntaxOnly.ts, 17, 20)) + } } enum NotLegalEnum { diff --git a/tests/baselines/reference/erasableSyntaxOnly.types b/tests/baselines/reference/erasableSyntaxOnly.types index a6b7d53c8550f..70cd9cbd6f9cf 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.types +++ b/tests/baselines/reference/erasableSyntaxOnly.types @@ -37,16 +37,16 @@ namespace IllegalBecauseNestedInstantiated { >IllegalBecauseNestedInstantiated : typeof IllegalBecauseNestedInstantiated > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - namespace Nested { + namespace Nested { >Nested : typeof Nested > : ^^^^^^^^^^^^^ - export const m = 1; + export const m = 1; >m : 1 > : ^ >1 : 1 > : ^ - } + } } enum NotLegalEnum { diff --git a/tests/cases/compiler/erasableSyntaxOnly.ts b/tests/cases/compiler/erasableSyntaxOnly.ts index 5e7cfe697502c..57aea66db7d64 100644 --- a/tests/cases/compiler/erasableSyntaxOnly.ts +++ b/tests/cases/compiler/erasableSyntaxOnly.ts @@ -17,9 +17,9 @@ namespace AlsoIllegalBecauseInstantiated { } namespace IllegalBecauseNestedInstantiated { - namespace Nested { - export const m = 1; - } + namespace Nested { + export const m = 1; + } } enum NotLegalEnum {