Skip to content
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
4 changes: 4 additions & 0 deletions tsc/internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ func (tx *DeclarationTransformer) transformExportAssignment(input *ast.Node, ass
tx.resultHasScopeMarker = true
if ast.IsIdentifier(expression) && (ast.IsSourceFile(input.Parent) || ast.IsModuleBlock(input.Parent)) {
exportAssignment := tx.Factory().NewExportAssignment(nil, isExportEquals, nil, expression)
tx.EmitContext().AssignSourceMapRange(exportAssignment, input)
tx.preserveJsDoc(exportAssignment, input)
return exportAssignment
}
Expand All @@ -1247,6 +1248,7 @@ func (tx *DeclarationTransformer) transformExportAssignment(input *ast.Node, ass
tx.preserveJsDoc(classDecl, input)
// Reuse the same name node for the export so unique names resolve consistently
exportAssignment := tx.Factory().NewExportAssignment(nil, isExportEquals, nil, newId)
tx.EmitContext().AssignSourceMapRange(exportAssignment, input)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@microsoft-github-policy-service agree

tx.removeAllComments(exportAssignment)
return tx.Factory().NewSyntaxList([]*ast.Node{exportAssignment, classDecl})
} else if ast.IsFunctionLike(unwrapped) {
Expand All @@ -1260,6 +1262,7 @@ func (tx *DeclarationTransformer) transformExportAssignment(input *ast.Node, ass
tx.preserveJsDoc(funcDecl, input)
// Reuse the same name node for the export so unique names resolve consistently
exportAssignment := tx.Factory().NewExportAssignment(nil, isExportEquals, nil, newId)
tx.EmitContext().AssignSourceMapRange(exportAssignment, input)
tx.removeAllComments(exportAssignment)
return tx.Factory().NewSyntaxList([]*ast.Node{exportAssignment, funcDecl})
}
Expand Down Expand Up @@ -1290,6 +1293,7 @@ func (tx *DeclarationTransformer) transformExportAssignment(input *ast.Node, ass
}
statement := tx.Factory().NewVariableStatement(modList, tx.Factory().NewVariableDeclarationList(tx.Factory().NewNodeList([]*ast.Node{varDecl}), ast.NodeFlagsConst))
exportAssignment := tx.Factory().NewExportAssignment(nil, isExportEquals, nil, newId)
tx.EmitContext().AssignSourceMapRange(exportAssignment, input)
// Remove comments from the export declaration and copy them onto the synthetic _default declaration
tx.preserveJsDoc(statement, input)
return tx.Factory().NewSyntaxList([]*ast.Node{statement, exportAssignment})
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,20 @@ sourceFile:declarationMaps.ts
2 >Emitted(14, 3) Source(16, 3) + SourceIndex(0)
---
>>>export = m2;
1->^^^^^^^^^
2 > ^^
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1->
2 >^^^^^^^^^
3 > ^^
4 > ^
5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1->
>
>export =
2 > m2
1->Emitted(15, 10) Source(18, 10) + SourceIndex(0)
2 >Emitted(15, 12) Source(18, 12) + SourceIndex(0)
>
2 >export =
3 > m2
4 > ;
1->Emitted(15, 1) Source(18, 1) + SourceIndex(0)
2 >Emitted(15, 10) Source(18, 10) + SourceIndex(0)
3 >Emitted(15, 12) Source(18, 12) + SourceIndex(0)
4 >Emitted(15, 13) Source(18, 13) + SourceIndex(0)
---
>>>//# sourceMappingURL=declarationMaps.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
===================================================================
JsFile: exportDefault.d.ts
mapUrl: exportDefault.d.ts.map
sourceRoot:
sources: exportDefault.ts
===================================================================
-------------------------------------------------------------------
emittedFile:exportDefault.d.ts
sourceFile:exportDefault.ts
-------------------------------------------------------------------
>>>declare const _default: {
>>> b: number;
>>> d: number;
>>>};
>>>export default _default;
1 >
2 >^^^^^^^^^^^^^^^^^^^^^^^^
3 > ^^^^^^^^^^^^^^^^^^->
1 >const b = 1;
>const d = 2;
>
2 >export default { b, d };
1 >Emitted(5, 1) Source(3, 1) + SourceIndex(0)
2 >Emitted(5, 25) Source(3, 25) + SourceIndex(0)
---
>>>//# sourceMappingURL=exportDefault.d.ts.map===================================================================
JsFile: exportEquals.d.ts
mapUrl: exportEquals.d.ts.map
sourceRoot:
sources: exportEquals.ts
===================================================================
-------------------------------------------------------------------
emittedFile:exportEquals.d.ts
sourceFile:exportEquals.ts
-------------------------------------------------------------------
>>>declare const _default: {
>>> a: number;
>>>};
>>>export = _default;
1 >
2 >^^^^^^^^^^^^^^^^^^
3 > ^^^^^^^^^^^^^^^^^^^^^^^->
1 >const a = 1;
>
2 >export = { a };
1 >Emitted(4, 1) Source(2, 1) + SourceIndex(0)
2 >Emitted(4, 19) Source(2, 16) + SourceIndex(0)
---
>>>//# sourceMappingURL=exportEquals.d.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/declarationMapsExportAssignmentExpression.ts] ////

=== exportDefault.ts ===
const b = 1;
>b : Symbol(b, Decl(exportDefault.ts, 0, 5))

const d = 2;
>d : Symbol(d, Decl(exportDefault.ts, 1, 5))

export default { b, d };
>b : Symbol(b, Decl(exportDefault.ts, 2, 16))
>d : Symbol(d, Decl(exportDefault.ts, 2, 19))

=== exportEquals.ts ===
const a = 1;
>a : Symbol(a, Decl(exportEquals.ts, 0, 5))

export = { a };
>a : Symbol(a, Decl(exportEquals.ts, 1, 10))

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/compiler/declarationMapsExportAssignmentExpression.ts] ////

=== exportDefault.ts ===
const b = 1;
>b : 1
>1 : 1

const d = 2;
>d : 2
>2 : 2

export default { b, d };
>{ b, d } : { b: number; d: number; }
>b : number
>d : number

=== exportEquals.ts ===
const a = 1;
>a : 1
>1 : 1

export = { a };
>{ a } : { a: number; }
>a : number

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @module: commonjs
// @declaration: true
// @declarationMap: true

// @filename: exportDefault.ts
const b = 1;
const d = 2;
export default { b, d };

// @filename: exportEquals.ts
const a = 1;
export = { a };