Skip to content

Commit e47c94e

Browse files
committed
Fix source map emit for imports, accepts several baselines.
1 parent 68aa646 commit e47c94e

6 files changed

Lines changed: 307 additions & 244 deletions

File tree

src/compiler/factory.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,13 +1170,18 @@ namespace ts {
11701170
return reduceLeft(expressions, createComma);
11711171
}
11721172

1173-
export function createExpressionFromEntityName(node: EntityName | Expression): Expression {
1174-
return isQualifiedName(node)
1175-
? createPropertyAccess(
1176-
createExpressionFromEntityName(node.left),
1177-
getSynthesizedClone(node.right)
1178-
)
1179-
: getSynthesizedClone(node);
1173+
export function createExpressionFromEntityName(node: EntityName | Expression, emitOptions?: NodeEmitOptions): Expression {
1174+
if (isQualifiedName(node)) {
1175+
const left = createExpressionFromEntityName(node.left, emitOptions);
1176+
const right = getMutableClone(node.right, emitOptions && clone(emitOptions));
1177+
return createPropertyAccess(left, right, /*location*/ node, emitOptions && clone(emitOptions));
1178+
}
1179+
else if (isIdentifier(node)) {
1180+
return getMutableClone(node, emitOptions && clone(emitOptions));
1181+
}
1182+
else {
1183+
return getMutableClone(node, emitOptions && clone(emitOptions));
1184+
}
11801185
}
11811186

11821187
export function createExpressionForPropertyName(memberName: PropertyName, emitOptions?: NodeEmitOptions): Expression {

src/compiler/transformers/ts.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,14 +2256,15 @@ namespace ts {
22562256
context,
22572257
node,
22582258
hoistVariableDeclaration,
2259-
getNamespaceMemberName,
2259+
getNamespaceMemberNameWithSourceMapsAndWithoutComments,
22602260
visitor
22612261
);
22622262
}
22632263
else {
22642264
return createAssignment(
2265-
getNamespaceMemberName(name),
2266-
visitNode(node.initializer, visitor, isExpression)
2265+
getNamespaceMemberNameWithSourceMapsAndWithoutComments(name),
2266+
visitNode(node.initializer, visitor, isExpression),
2267+
/*location*/ node
22672268
);
22682269
}
22692270
}
@@ -2726,15 +2727,18 @@ namespace ts {
27262727
return undefined;
27272728
}
27282729

2729-
const moduleReference = createExpressionFromEntityName(<EntityName>node.moduleReference);
2730+
const moduleReference = createExpressionFromEntityName(<EntityName>node.moduleReference, { flags: NodeEmitFlags.NoComments });
27302731
if (isNamedExternalModuleExport(node) || !isNamespaceExport(node)) {
27312732
// export var ${name} = ${moduleReference};
27322733
// var ${name} = ${moduleReference};
27332734
return setOriginalNode(
27342735
createVariableStatement(
27352736
visitNodes(node.modifiers, visitor, isModifier),
27362737
createVariableDeclarationList([
2737-
createVariableDeclaration(node.name, moduleReference)
2738+
createVariableDeclaration(
2739+
node.name,
2740+
moduleReference
2741+
)
27382742
]),
27392743
node
27402744
),
@@ -2745,7 +2749,7 @@ namespace ts {
27452749
// exports.${name} = ${moduleReference};
27462750
return setOriginalNode(
27472751
createNamespaceExport(
2748-
getSynthesizedClone(node.name),
2752+
node.name,
27492753
moduleReference,
27502754
node
27512755
),
@@ -2845,6 +2849,10 @@ namespace ts {
28452849
return qualifiedName;
28462850
}
28472851

2852+
function getNamespaceMemberNameWithSourceMapsAndWithoutComments(name: Identifier) {
2853+
return getNamespaceMemberName(name, /*allowComments*/ false, /*allowSourceMaps*/ true);
2854+
}
2855+
28482856
/**
28492857
* Gets the declaration name used inside of a namespace or enum.
28502858
*/

tests/baselines/reference/sourceMapValidationImport.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/sourceMapValidationImport.sourcemap.txt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,28 +171,31 @@ sourceFile:sourceMapValidationImport.ts
171171
---
172172
>>>exports.b = m.c;
173173
1->
174-
2 >^^^^^^^^^
175-
3 > ^^^
176-
4 > ^
177-
5 > ^
178-
6 > ^
179-
7 > ^
180-
8 > ^->
174+
2 >^^^^^^^^
175+
3 > ^
176+
4 > ^^^
177+
5 > ^
178+
6 > ^
179+
7 > ^
180+
8 > ^
181+
9 > ^->
181182
1->
182183
>export import
183-
2 >b
184-
3 > =
185-
4 > m
186-
5 > .
187-
6 > c
188-
7 > ;
184+
2 >
185+
3 > b
186+
4 > =
187+
5 > m
188+
6 > .
189+
7 > c
190+
8 > ;
189191
1->Emitted(12, 1) Source(6, 15) + SourceIndex(0)
190-
2 >Emitted(12, 10) Source(6, 16) + SourceIndex(0)
191-
3 >Emitted(12, 13) Source(6, 19) + SourceIndex(0)
192-
4 >Emitted(12, 14) Source(6, 20) + SourceIndex(0)
193-
5 >Emitted(12, 15) Source(6, 21) + SourceIndex(0)
194-
6 >Emitted(12, 16) Source(6, 22) + SourceIndex(0)
195-
7 >Emitted(12, 17) Source(6, 23) + SourceIndex(0)
192+
2 >Emitted(12, 9) Source(6, 15) + SourceIndex(0)
193+
3 >Emitted(12, 10) Source(6, 16) + SourceIndex(0)
194+
4 >Emitted(12, 13) Source(6, 19) + SourceIndex(0)
195+
5 >Emitted(12, 14) Source(6, 20) + SourceIndex(0)
196+
6 >Emitted(12, 15) Source(6, 21) + SourceIndex(0)
197+
7 >Emitted(12, 16) Source(6, 22) + SourceIndex(0)
198+
8 >Emitted(12, 17) Source(6, 23) + SourceIndex(0)
196199
---
197200
>>>var x = new a();
198201
1->

tests/baselines/reference/tsxEmit3.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)