Skip to content

Commit 68aa646

Browse files
committed
Additional source map fixes for initializers and arrow functions.
1 parent b69e65f commit 68aa646

9 files changed

Lines changed: 93 additions & 85 deletions

src/compiler/printer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,15 +1345,15 @@ const _super = (function (geti, seti) {
13451345
}
13461346

13471347
function emitIfStatement(node: IfStatement) {
1348-
const openParenPos = writeToken(SyntaxKind.IfKeyword, node.pos);
1348+
const openParenPos = writeToken(SyntaxKind.IfKeyword, node.pos, node);
13491349
write(" ");
1350-
writeToken(SyntaxKind.OpenParenToken, openParenPos);
1350+
writeToken(SyntaxKind.OpenParenToken, openParenPos, node);
13511351
emitExpression(node.expression);
1352-
writeToken(SyntaxKind.CloseParenToken, node.expression.end);
1352+
writeToken(SyntaxKind.CloseParenToken, node.expression.end, node);
13531353
emitEmbeddedStatement(node.thenStatement);
13541354
if (node.elseStatement) {
13551355
writeLine();
1356-
writeToken(SyntaxKind.ElseKeyword, node.thenStatement.end);
1356+
writeToken(SyntaxKind.ElseKeyword, node.thenStatement.end, node);
13571357
if (node.elseStatement.kind === SyntaxKind.IfStatement) {
13581358
write(" ");
13591359
emit(node.elseStatement);

src/compiler/transformers/es6.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -949,28 +949,30 @@ namespace ts {
949949
* @param initializer The initializer for the parameter.
950950
*/
951951
function addDefaultValueAssignmentForInitializer(statements: Statement[], parameter: ParameterDeclaration, name: Identifier, initializer: Expression): void {
952-
statements.push(
953-
createIf(
954-
createStrictEquality(
955-
getSynthesizedClone(name),
956-
createVoidZero()
957-
),
958-
setNodeEmitFlags(
959-
createBlock([
960-
createStatement(
961-
createAssignment(
962-
getSynthesizedClone(name),
963-
visitNode(initializer, visitor, isExpression)
964-
)
952+
const statement = createIf(
953+
createStrictEquality(
954+
getSynthesizedClone(name),
955+
createVoidZero()
956+
),
957+
setNodeEmitFlags(
958+
createBlock([
959+
createStatement(
960+
createAssignment(
961+
setNodeEmitFlags(getMutableClone(name), NodeEmitFlags.NoSourceMap),
962+
setNodeEmitFlags(visitNode(initializer, visitor, isExpression), NodeEmitFlags.NoSourceMap),
963+
/*location*/ parameter
965964
)
966-
]),
967-
NodeEmitFlags.SingleLine
968-
),
969-
/*elseStatement*/ undefined,
970-
/*location*/ undefined,
971-
{ startOnNewLine: true }
972-
)
965+
)
966+
], /*location*/ parameter),
967+
NodeEmitFlags.SingleLine | NodeEmitFlags.NoTrailingSourceMap | NodeEmitFlags.NoTokenSourceMaps
968+
),
969+
/*elseStatement*/ undefined,
970+
/*location*/ parameter,
971+
{ startOnNewLine: true }
973972
);
973+
974+
setNodeEmitFlags(statement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoTrailingSourceMap);
975+
statements.push(statement);
974976
}
975977

976978
/**
@@ -1365,9 +1367,8 @@ namespace ts {
13651367
}
13661368

13671369
const expression = visitNode(body, visitor, isExpression);
1368-
const returnStatement = createReturn(expression);
1369-
setSourceMapRange(returnStatement, body);
1370-
setNodeEmitFlags(returnStatement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoTrailingSourceMap);
1370+
const returnStatement = createReturn(expression, /*location*/ body);
1371+
setNodeEmitFlags(returnStatement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoTrailingSourceMap | NodeEmitFlags.NoTrailingComments);
13711372
statements.push(returnStatement);
13721373

13731374
// To align with the source map emit for the old emitter, we set a custom
@@ -2364,7 +2365,7 @@ namespace ts {
23642365
// Methods on classes are handled in visitClassDeclaration/visitClassExpression.
23652366
// Methods with computed property names are handled in visitObjectLiteralExpression.
23662367
Debug.assert(!isComputedPropertyName(node.name));
2367-
const functionExpression = transformFunctionLikeToExpression(node, /*location*/ node, /*name*/ undefined);
2368+
const functionExpression = transformFunctionLikeToExpression(node, /*location*/ moveRangePos(node, -1), /*name*/ undefined);
23682369
setNodeEmitFlags(functionExpression, NodeEmitFlags.NoLeadingComments | getNodeEmitFlags(functionExpression));
23692370
return createPropertyAssignment(
23702371
node.name,

src/compiler/transformers/module/module.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,22 +219,23 @@ namespace ts {
219219
/*location*/ exportEquals
220220
);
221221

222-
setNodeEmitFlags(statement, NodeEmitFlags.NoTokenSourceMaps);
222+
setNodeEmitFlags(statement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoComments);
223223
statements.push(statement);
224224
}
225225
else {
226-
statements.push(
227-
createStatement(
228-
createAssignment(
229-
createPropertyAccess(
230-
createIdentifier("module"),
231-
"exports"
232-
),
233-
exportEquals.expression
226+
const statement = createStatement(
227+
createAssignment(
228+
createPropertyAccess(
229+
createIdentifier("module"),
230+
"exports"
234231
),
235-
/*location*/ exportEquals
236-
)
232+
exportEquals.expression
233+
),
234+
/*location*/ exportEquals
237235
);
236+
237+
setNodeEmitFlags(statement, NodeEmitFlags.NoComments);
238+
statements.push(statement);
238239
}
239240
}
240241
}

tests/baselines/reference/ES5For-of26.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/ES5For-of26.sourcemap.txt

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,35 +58,38 @@ sourceFile:ES5For-of26.ts
5858
---
5959
>>> var _b = _a[_i], _c = _b[0], a = _c === void 0 ? 0 : _c, _d = _b[1], b = _d === void 0 ? 1 : _d;
6060
1->^^^^
61-
2 > ^^^^^^^^^^^^^^^
62-
3 > ^^
63-
4 > ^^^^^^^^^^
64-
5 > ^^
65-
6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^
66-
7 > ^^
67-
8 > ^^^^^^^^^^
68-
9 > ^^
69-
10> ^^^^^^^^^^^^^^^^^^^^^^^^^^
61+
2 > ^^^^
62+
3 > ^^^^^^^^^^^
63+
4 > ^^
64+
5 > ^^^^^^^^^^
65+
6 > ^^
66+
7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^
67+
8 > ^^
68+
9 > ^^^^^^^^^^
69+
10> ^^
70+
11> ^^^^^^^^^^^^^^^^^^^^^^^^^^
7071
1->
71-
2 > var [a = 0, b = 1]
72-
3 >
73-
4 > a = 0
74-
5 >
75-
6 > a = 0
76-
7 > ,
77-
8 > b = 1
78-
9 >
79-
10> b = 1
80-
1->Emitted(2, 5) Source(1, 6) + SourceIndex(0)
81-
2 >Emitted(2, 20) Source(1, 24) + SourceIndex(0)
82-
3 >Emitted(2, 22) Source(1, 11) + SourceIndex(0)
83-
4 >Emitted(2, 32) Source(1, 16) + SourceIndex(0)
84-
5 >Emitted(2, 34) Source(1, 11) + SourceIndex(0)
85-
6 >Emitted(2, 60) Source(1, 16) + SourceIndex(0)
86-
7 >Emitted(2, 62) Source(1, 18) + SourceIndex(0)
87-
8 >Emitted(2, 72) Source(1, 23) + SourceIndex(0)
88-
9 >Emitted(2, 74) Source(1, 18) + SourceIndex(0)
89-
10>Emitted(2, 100) Source(1, 23) + SourceIndex(0)
72+
2 >
73+
3 > [a = 0, b = 1]
74+
4 >
75+
5 > a = 0
76+
6 >
77+
7 > a = 0
78+
8 > ,
79+
9 > b = 1
80+
10>
81+
11> b = 1
82+
1->Emitted(2, 5) Source(1, 10) + SourceIndex(0)
83+
2 >Emitted(2, 9) Source(1, 10) + SourceIndex(0)
84+
3 >Emitted(2, 20) Source(1, 24) + SourceIndex(0)
85+
4 >Emitted(2, 22) Source(1, 11) + SourceIndex(0)
86+
5 >Emitted(2, 32) Source(1, 16) + SourceIndex(0)
87+
6 >Emitted(2, 34) Source(1, 11) + SourceIndex(0)
88+
7 >Emitted(2, 60) Source(1, 16) + SourceIndex(0)
89+
8 >Emitted(2, 62) Source(1, 18) + SourceIndex(0)
90+
9 >Emitted(2, 72) Source(1, 23) + SourceIndex(0)
91+
10>Emitted(2, 74) Source(1, 18) + SourceIndex(0)
92+
11>Emitted(2, 100) Source(1, 23) + SourceIndex(0)
9093
---
9194
>>> a;
9295
1 >^^^^

tests/baselines/reference/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.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/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.sourcemap.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ sourceFile:sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatemen
5858
6 > ^^^^^
5959
7 > ^
6060
8 > ^
61-
9 > ^^^
62-
10> ^
61+
9 > ^^
62+
10> ^
63+
11> ^
6364
1->
6465
> public
6566
2 > returnA
@@ -70,7 +71,8 @@ sourceFile:sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatemen
7071
7 > .
7172
8 > a
7273
9 >
73-
10> ;
74+
10> this.a
75+
11> ;
7476
1->Emitted(5, 9) Source(3, 12) + SourceIndex(0)
7577
2 >Emitted(5, 21) Source(3, 19) + SourceIndex(0)
7678
3 >Emitted(5, 24) Source(3, 22) + SourceIndex(0)
@@ -79,8 +81,9 @@ sourceFile:sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatemen
7981
6 >Emitted(5, 50) Source(3, 32) + SourceIndex(0)
8082
7 >Emitted(5, 51) Source(3, 33) + SourceIndex(0)
8183
8 >Emitted(5, 52) Source(3, 34) + SourceIndex(0)
82-
9 >Emitted(5, 55) Source(3, 34) + SourceIndex(0)
83-
10>Emitted(5, 56) Source(3, 35) + SourceIndex(0)
84+
9 >Emitted(5, 54) Source(3, 28) + SourceIndex(0)
85+
10>Emitted(5, 55) Source(3, 34) + SourceIndex(0)
86+
11>Emitted(5, 56) Source(3, 35) + SourceIndex(0)
8487
---
8588
>>> }
8689
1 >^^^^

tests/baselines/reference/sourceMapValidationFunctions.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/sourceMapValidationFunctions.sourcemap.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ sourceFile:sourceMapValidationFunctions.ts
112112
---
113113
>>> if (n === void 0) { n = 10; }
114114
1->^^^^
115-
2 > ^^^^^^^^^^^^^^^^^
116-
3 > ^^^
115+
2 > ^^^^^^^^^^^^^^^^^^
116+
3 > ^^
117117
4 > ^^^^^^
118118
1->
119-
2 > n = 10
120-
3 >
119+
2 >
120+
3 >
121121
4 > n = 10
122122
1->Emitted(7, 5) Source(6, 35) + SourceIndex(0)
123-
2 >Emitted(7, 22) Source(6, 41) + SourceIndex(0)
123+
2 >Emitted(7, 23) Source(6, 35) + SourceIndex(0)
124124
3 >Emitted(7, 25) Source(6, 35) + SourceIndex(0)
125125
4 >Emitted(7, 31) Source(6, 41) + SourceIndex(0)
126126
---
@@ -233,15 +233,15 @@ sourceFile:sourceMapValidationFunctions.ts
233233
---
234234
>>> if (n === void 0) { n = 10; }
235235
1->^^^^
236-
2 > ^^^^^^^^^^^^^^^^^
237-
3 > ^^^
236+
2 > ^^^^^^^^^^^^^^^^^^
237+
3 > ^^
238238
4 > ^^^^^^
239239
1->
240-
2 > n = 10
241-
3 >
240+
2 >
241+
3 >
242242
4 > n = 10
243243
1->Emitted(16, 5) Source(10, 32) + SourceIndex(0)
244-
2 >Emitted(16, 22) Source(10, 38) + SourceIndex(0)
244+
2 >Emitted(16, 23) Source(10, 32) + SourceIndex(0)
245245
3 >Emitted(16, 25) Source(10, 32) + SourceIndex(0)
246246
4 >Emitted(16, 31) Source(10, 38) + SourceIndex(0)
247247
---

0 commit comments

Comments
 (0)