Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Pick PR #61210 (Fix mistakenly disallowed default e...) into release-5.8 #61237

Open
wants to merge 1 commit into
base: release-5.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;