Skip to content

Commit c6c4299

Browse files
authored
Fixed a crash when transforming modules with top-level labels (#59374)
1 parent a4ae3c4 commit c6c4299

15 files changed

+204
-2
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
993993
return factory.updateLabeledStatement(
994994
node,
995995
node.label,
996-
Debug.checkDefined(visitNode(node.statement, topLevelNestedVisitor, isStatement, factory.liftToBlock)),
996+
visitNode(node.statement, topLevelNestedVisitor, isStatement, factory.liftToBlock) ?? factory.createExpressionStatement(factory.createIdentifier("")),
997997
);
998998
}
999999

src/compiler/transformers/module/system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc
14191419
return factory.updateLabeledStatement(
14201420
node,
14211421
node.label,
1422-
Debug.checkDefined(visitNode(node.statement, topLevelNestedVisitor, isStatement, factory.liftToBlock)),
1422+
visitNode(node.statement, topLevelNestedVisitor, isStatement, factory.liftToBlock) ?? factory.createExpressionStatement(factory.createIdentifier("")),
14231423
);
14241424
}
14251425

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
labeledStatementExportDeclarationNoCrash1.ts(3,14): error TS1155: 'const' declarations must be initialized.
2+
labeledStatementExportDeclarationNoCrash1.ts(5,1): error TS1184: Modifiers cannot appear here.
3+
labeledStatementExportDeclarationNoCrash1.ts(5,14): error TS1155: 'const' declarations must be initialized.
4+
5+
6+
==== labeledStatementExportDeclarationNoCrash1.ts (3 errors) ====
7+
// https://github.com/microsoft/TypeScript/issues/59372
8+
9+
export const box: string
10+
~~~
11+
!!! error TS1155: 'const' declarations must be initialized.
12+
subTitle:
13+
export const title: string
14+
~~~~~~
15+
!!! error TS1184: Modifiers cannot appear here.
16+
~~~~~
17+
!!! error TS1155: 'const' declarations must be initialized.
18+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/conformance/statements/labeledStatements/labeledStatementExportDeclarationNoCrash1.ts] ////
2+
3+
//// [labeledStatementExportDeclarationNoCrash1.ts]
4+
// https://github.com/microsoft/TypeScript/issues/59372
5+
6+
export const box: string
7+
subTitle:
8+
export const title: string
9+
10+
11+
//// [labeledStatementExportDeclarationNoCrash1.js]
12+
"use strict";
13+
// https://github.com/microsoft/TypeScript/issues/59372
14+
Object.defineProperty(exports, "__esModule", { value: true });
15+
exports.box = void 0;
16+
subTitle: ;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/conformance/statements/labeledStatements/labeledStatementExportDeclarationNoCrash1.ts] ////
2+
3+
=== labeledStatementExportDeclarationNoCrash1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/59372
5+
6+
export const box: string
7+
>box : Symbol(box, Decl(labeledStatementExportDeclarationNoCrash1.ts, 2, 12))
8+
9+
subTitle:
10+
export const title: string
11+
>title : Symbol(title, Decl(labeledStatementExportDeclarationNoCrash1.ts, 4, 12))
12+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [tests/cases/conformance/statements/labeledStatements/labeledStatementExportDeclarationNoCrash1.ts] ////
2+
3+
=== labeledStatementExportDeclarationNoCrash1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/59372
5+
6+
export const box: string
7+
>box : string
8+
> : ^^^^^^
9+
10+
subTitle:
11+
>subTitle : any
12+
> : ^^^
13+
14+
export const title: string
15+
>title : string
16+
> : ^^^^^^
17+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
labeledStatementExportDeclarationNoCrash1.ts(3,14): error TS1155: 'const' declarations must be initialized.
2+
labeledStatementExportDeclarationNoCrash1.ts(5,1): error TS1184: Modifiers cannot appear here.
3+
labeledStatementExportDeclarationNoCrash1.ts(5,14): error TS1155: 'const' declarations must be initialized.
4+
5+
6+
==== labeledStatementExportDeclarationNoCrash1.ts (3 errors) ====
7+
// https://github.com/microsoft/TypeScript/issues/59372
8+
9+
export const box: string
10+
~~~
11+
!!! error TS1155: 'const' declarations must be initialized.
12+
subTitle:
13+
export const title: string
14+
~~~~~~
15+
!!! error TS1184: Modifiers cannot appear here.
16+
~~~~~
17+
!!! error TS1155: 'const' declarations must be initialized.
18+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/conformance/statements/labeledStatements/labeledStatementExportDeclarationNoCrash1.ts] ////
2+
3+
//// [labeledStatementExportDeclarationNoCrash1.ts]
4+
// https://github.com/microsoft/TypeScript/issues/59372
5+
6+
export const box: string
7+
subTitle:
8+
export const title: string
9+
10+
11+
//// [labeledStatementExportDeclarationNoCrash1.js]
12+
// https://github.com/microsoft/TypeScript/issues/59372
13+
export var box;
14+
subTitle: export var title;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [tests/cases/conformance/statements/labeledStatements/labeledStatementExportDeclarationNoCrash1.ts] ////
2+
3+
=== labeledStatementExportDeclarationNoCrash1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/59372
5+
6+
export const box: string
7+
>box : Symbol(box, Decl(labeledStatementExportDeclarationNoCrash1.ts, 2, 12))
8+
9+
subTitle:
10+
export const title: string
11+
>title : Symbol(title, Decl(labeledStatementExportDeclarationNoCrash1.ts, 4, 12))
12+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [tests/cases/conformance/statements/labeledStatements/labeledStatementExportDeclarationNoCrash1.ts] ////
2+
3+
=== labeledStatementExportDeclarationNoCrash1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/59372
5+
6+
export const box: string
7+
>box : string
8+
> : ^^^^^^
9+
10+
subTitle:
11+
>subTitle : any
12+
> : ^^^
13+
14+
export const title: string
15+
>title : string
16+
> : ^^^^^^
17+

0 commit comments

Comments
 (0)