From 63fc29fc9f774ec24132d4d16568632e0541e635 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 18 Feb 2025 00:25:07 -0800 Subject: [PATCH 1/3] Add test --- .../reference/erasableSyntaxOnly.errors.txt | 8 ++++++++ tests/baselines/reference/erasableSyntaxOnly.js | 8 ++++++++ tests/baselines/reference/erasableSyntaxOnly.symbols | 8 ++++++++ tests/baselines/reference/erasableSyntaxOnly.types | 12 ++++++++++++ .../erasableSyntaxOnlyDeclaration.errors.txt | 8 ++++++++ .../reference/erasableSyntaxOnlyDeclaration.symbols | 8 ++++++++ .../reference/erasableSyntaxOnlyDeclaration.types | 12 ++++++++++++ tests/cases/compiler/erasableSyntaxOnly.ts | 5 +++++ .../cases/compiler/erasableSyntaxOnlyDeclaration.ts | 5 +++++ 9 files changed, 74 insertions(+) diff --git a/tests/baselines/reference/erasableSyntaxOnly.errors.txt b/tests/baselines/reference/erasableSyntaxOnly.errors.txt index 39a724aa00c51..a94bdf85bdc57 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnly.errors.txt @@ -1,5 +1,6 @@ commonjs.cts(1,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. commonjs.cts(2,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. +esm.mts(2,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. index.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. index.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. index.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. @@ -104,4 +105,11 @@ index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOn ==== other.d.cts (0 errors) ==== declare function foo(): void; export = foo; + + +==== esm.mts (1 errors) ==== + const foo = 1234; + export default foo; + ~~~~~~~~~~~~~~~~~~~ +!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. \ No newline at end of file diff --git a/tests/baselines/reference/erasableSyntaxOnly.js b/tests/baselines/reference/erasableSyntaxOnly.js index 1d7393620df4d..9edf749d7b038 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.js +++ b/tests/baselines/reference/erasableSyntaxOnly.js @@ -74,6 +74,11 @@ export = foo; //// [other.d.cts] declare function foo(): void; export = foo; + + +//// [esm.mts] +const foo = 1234; +export default foo; //// [index.js] @@ -119,3 +124,6 @@ var MyClassOk = /** @class */ (function () { "use strict"; var foo = require("./other.cjs"); module.exports = foo; +//// [esm.mjs] +var foo = 1234; +export default foo; diff --git a/tests/baselines/reference/erasableSyntaxOnly.symbols b/tests/baselines/reference/erasableSyntaxOnly.symbols index f0220004341b3..8e057dc990217 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.symbols +++ b/tests/baselines/reference/erasableSyntaxOnly.symbols @@ -133,3 +133,11 @@ declare function foo(): void; export = foo; >foo : Symbol(foo, Decl(other.d.cts, 0, 0)) + +=== esm.mts === +const foo = 1234; +>foo : Symbol(foo, Decl(esm.mts, 0, 5)) + +export default foo; +>foo : Symbol(foo, Decl(esm.mts, 0, 5)) + diff --git a/tests/baselines/reference/erasableSyntaxOnly.types b/tests/baselines/reference/erasableSyntaxOnly.types index 599a8d2125ead..4d4ddaea49701 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.types +++ b/tests/baselines/reference/erasableSyntaxOnly.types @@ -179,3 +179,15 @@ export = foo; >foo : () => void > : ^^^^^^ + +=== esm.mts === +const foo = 1234; +>foo : 1234 +> : ^^^^ +>1234 : 1234 +> : ^^^^ + +export default foo; +>foo : 1234 +> : ^^^^ + diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt index 7bc78e382b7ed..02d2bddd18059 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt @@ -1,3 +1,4 @@ +esm.d.mts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. index.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. @@ -65,4 +66,11 @@ index.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start ==== other.d.cts (0 errors) ==== declare function foo(): void; export = foo; + + +==== esm.d.mts (1 errors) ==== + const foo = 1234; + ~~~~~ +!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. + export default foo; \ No newline at end of file diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols index 4f439b211c5c3..522c073fdb591 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols @@ -112,3 +112,11 @@ declare function foo(): void; export = foo; >foo : Symbol(foo, Decl(other.d.cts, 0, 0)) + +=== esm.d.mts === +const foo = 1234; +>foo : Symbol(foo, Decl(esm.d.mts, 0, 5)) + +export default foo; +>foo : Symbol(foo, Decl(esm.d.mts, 0, 5)) + diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types index 031eb9bbb59cb..02de7adb4bc74 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types @@ -154,3 +154,15 @@ export = foo; >foo : () => void > : ^^^^^^ + +=== esm.d.mts === +const foo = 1234; +>foo : 1234 +> : ^^^^ +>1234 : 1234 +> : ^^^^ + +export default foo; +>foo : 1234 +> : ^^^^ + diff --git a/tests/cases/compiler/erasableSyntaxOnly.ts b/tests/cases/compiler/erasableSyntaxOnly.ts index 6a76e80337e11..d2ff6d72ce8f3 100644 --- a/tests/cases/compiler/erasableSyntaxOnly.ts +++ b/tests/cases/compiler/erasableSyntaxOnly.ts @@ -74,3 +74,8 @@ export = foo; // @filename: other.d.cts declare function foo(): void; export = foo; + + +// @filename: esm.mts +const foo = 1234; +export default foo; diff --git a/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts index f87e2346f094b..cca51e140b65f 100644 --- a/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts +++ b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts @@ -66,3 +66,8 @@ export = foo; // @filename: other.d.cts declare function foo(): void; export = foo; + + +// @filename: esm.d.mts +const foo = 1234; +export default foo; From 636e028e6b9bb21bf3a1999c6394ff3592e7cd2d Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 18 Feb 2025 00:28:51 -0800 Subject: [PATCH 2/3] Fix mistakenly disallowed default export under erasableSyntaxOnly --- src/compiler/checker.ts | 2 +- tests/baselines/reference/erasableSyntaxOnly.errors.txt | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index abd6fd4bf2e8d..8797dbbf80137 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -47974,7 +47974,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return; } - if (compilerOptions.erasableSyntaxOnly && !(node.flags & NodeFlags.Ambient)) { + if (compilerOptions.erasableSyntaxOnly && node.isExportEquals && !(node.flags & NodeFlags.Ambient)) { error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled); } const container = node.parent.kind === SyntaxKind.SourceFile ? node.parent : node.parent.parent as ModuleDeclaration; diff --git a/tests/baselines/reference/erasableSyntaxOnly.errors.txt b/tests/baselines/reference/erasableSyntaxOnly.errors.txt index a94bdf85bdc57..2005ef65de8e7 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnly.errors.txt @@ -1,6 +1,5 @@ commonjs.cts(1,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. commonjs.cts(2,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. -esm.mts(2,1): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. index.ts(3,17): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. index.ts(6,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. index.ts(10,11): error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. @@ -107,9 +106,7 @@ index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOn export = foo; -==== esm.mts (1 errors) ==== +==== esm.mts (0 errors) ==== const foo = 1234; export default foo; - ~~~~~~~~~~~~~~~~~~~ -!!! error TS1294: This syntax is not allowed when 'erasableSyntaxOnly' is enabled. \ No newline at end of file From 32ca1b741816f30fddeab64d86b8d90e5181f327 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Tue, 18 Feb 2025 07:45:54 -0800 Subject: [PATCH 3/3] Fix error in test --- .../reference/erasableSyntaxOnlyDeclaration.errors.txt | 7 ++----- .../reference/erasableSyntaxOnlyDeclaration.symbols | 6 +++--- .../reference/erasableSyntaxOnlyDeclaration.types | 2 +- tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt index 02d2bddd18059..fdb4d96f8498b 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt @@ -1,4 +1,3 @@ -esm.d.mts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. index.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. @@ -68,9 +67,7 @@ index.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start export = foo; -==== esm.d.mts (1 errors) ==== - const foo = 1234; - ~~~~~ -!!! error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. +==== esm.d.mts (0 errors) ==== + declare const foo = 1234; export default foo; \ No newline at end of file diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols index 522c073fdb591..2763999d6468b 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols @@ -114,9 +114,9 @@ export = foo; === esm.d.mts === -const foo = 1234; ->foo : Symbol(foo, Decl(esm.d.mts, 0, 5)) +declare const foo = 1234; +>foo : Symbol(foo, Decl(esm.d.mts, 0, 13)) export default foo; ->foo : Symbol(foo, Decl(esm.d.mts, 0, 5)) +>foo : Symbol(foo, Decl(esm.d.mts, 0, 13)) diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types index 02de7adb4bc74..053aa1b60d2e4 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types @@ -156,7 +156,7 @@ export = foo; === esm.d.mts === -const foo = 1234; +declare const foo = 1234; >foo : 1234 > : ^^^^ >1234 : 1234 diff --git a/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts index cca51e140b65f..3a986719a160c 100644 --- a/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts +++ b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts @@ -69,5 +69,5 @@ export = foo; // @filename: esm.d.mts -const foo = 1234; +declare const foo = 1234; export default foo;