Skip to content

Commit

Permalink
Fix mistakenly disallowed default export under erasableSyntaxOnly (#6…
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Feb 18, 2025
1 parent 0f4737e commit c9cb6c3
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions tests/baselines/reference/erasableSyntaxOnly.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ 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 (0 errors) ====
const foo = 1234;
export default foo;

8 changes: 8 additions & 0 deletions tests/baselines/reference/erasableSyntaxOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
8 changes: 8 additions & 0 deletions tests/baselines/reference/erasableSyntaxOnly.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))

12 changes: 12 additions & 0 deletions tests/baselines/reference/erasableSyntaxOnly.types
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,15 @@ export = foo;
>foo : () => void
> : ^^^^^^


=== esm.mts ===
const foo = 1234;
>foo : 1234
> : ^^^^
>1234 : 1234
> : ^^^^

export default foo;
>foo : 1234
> : ^^^^

Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ 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 (0 errors) ====
declare const foo = 1234;
export default foo;

Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,11 @@ declare function foo(): void;
export = foo;
>foo : Symbol(foo, Decl(other.d.cts, 0, 0))


=== esm.d.mts ===
declare const foo = 1234;
>foo : Symbol(foo, Decl(esm.d.mts, 0, 13))

export default foo;
>foo : Symbol(foo, Decl(esm.d.mts, 0, 13))

12 changes: 12 additions & 0 deletions tests/baselines/reference/erasableSyntaxOnlyDeclaration.types
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,15 @@ export = foo;
>foo : () => void
> : ^^^^^^


=== esm.d.mts ===
declare const foo = 1234;
>foo : 1234
> : ^^^^
>1234 : 1234
> : ^^^^

export default foo;
>foo : 1234
> : ^^^^

5 changes: 5 additions & 0 deletions tests/cases/compiler/erasableSyntaxOnly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 5 additions & 0 deletions tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ export = foo;
// @filename: other.d.cts
declare function foo(): void;
export = foo;


// @filename: esm.d.mts
declare const foo = 1234;
export default foo;

0 comments on commit c9cb6c3

Please sign in to comment.