Skip to content

Commit 990e130

Browse files
authored
Merge pull request #9884 from Microsoft/transforms-sourceMapTodo
[Transforms] Finish up TODO's for source maps
2 parents ffc5541 + 561104f commit 990e130

38 files changed

+155
-415
lines changed

src/compiler/emitter.ts

Lines changed: 13 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -314,25 +314,6 @@ const _super = (function (geti, seti) {
314314
emitNodeWithNotification(node, emitWithComments);
315315
}
316316

317-
/**
318-
* Emits a node with specialized emit flags.
319-
*/
320-
// TODO(rbuckton): This should be removed once source maps are aligned with the old
321-
// emitter and new baselines are taken. This exists solely to
322-
// align with the old emitter.
323-
function emitSpecialized(node: Node, flags: NodeEmitFlags) {
324-
if (node) {
325-
const flagsToAdd = flags & ~node.emitFlags;
326-
if (flagsToAdd) {
327-
node.emitFlags |= flagsToAdd;
328-
emit(node);
329-
node.emitFlags &= ~flagsToAdd;
330-
return;
331-
}
332-
333-
emit(node);
334-
}
335-
}
336317

337318
/**
338319
* Emits a node with comments.
@@ -354,6 +335,16 @@ const _super = (function (geti, seti) {
354335
emitNodeWithSourceMap(node, emitWorker);
355336
}
356337

338+
function emitIdentifierName(node: Identifier) {
339+
if (node) {
340+
emitNodeWithNotification(node, emitIdentifierNameWithComments);
341+
}
342+
}
343+
344+
function emitIdentifierNameWithComments(node: Identifier) {
345+
emitNodeWithComments(node, emitWorker);
346+
}
347+
357348
/**
358349
* Emits an expression node.
359350
*/
@@ -1443,31 +1434,6 @@ const _super = (function (geti, seti) {
14431434
}
14441435

14451436
function emitForStatement(node: ForStatement) {
1446-
if (node.emitFlags & NodeEmitFlags.SourceMapAdjustRestParameterLoop) {
1447-
// TODO(rbuckton): This should be removed once source maps are aligned with the old
1448-
// emitter and new baselines are taken. This exists solely to
1449-
// align with the old emitter.
1450-
const openParenPos = writeToken(SyntaxKind.ForKeyword, node.pos);
1451-
write(" ");
1452-
writeToken(SyntaxKind.OpenParenToken, openParenPos);
1453-
const initializer = node.initializer;
1454-
initializer.emitFlags |= NodeEmitFlags.NoTrailingSourceMap;
1455-
emitForBinding(initializer);
1456-
write(";");
1457-
emitEnd(initializer);
1458-
const condition = node.condition;
1459-
condition.emitFlags |= NodeEmitFlags.NoTrailingSourceMap;
1460-
write(" ");
1461-
emitExpression(condition);
1462-
write(";");
1463-
emitEnd(condition);
1464-
write(" ");
1465-
emitExpression(node.incrementor);
1466-
write(")");
1467-
emitEmbeddedStatement(node.statement);
1468-
return;
1469-
}
1470-
14711437
const openParenPos = writeToken(SyntaxKind.ForKeyword, node.pos);
14721438
write(" ");
14731439
writeToken(SyntaxKind.OpenParenToken, openParenPos, /*contextNode*/ node);
@@ -1598,7 +1564,7 @@ const _super = (function (geti, seti) {
15981564
emitDecorators(node, node.decorators);
15991565
emitModifiers(node, node.modifiers);
16001566
write(node.asteriskToken ? "function* " : "function ");
1601-
emitSpecialized(node.name, NodeEmitFlags.NoSourceMap);
1567+
emitIdentifierName(node.name);
16021568
emitSignatureAndBody(node, emitSignatureHead);
16031569
}
16041570

@@ -1685,17 +1651,7 @@ const _super = (function (geti, seti) {
16851651
}
16861652

16871653
function emitBlockFunctionBody(parentNode: Node, body: Block) {
1688-
// TODO(rbuckton): This should be removed once source maps are aligned with the old
1689-
// emitter and new baselines are taken. This exists solely to
1690-
// align with the old emitter.
1691-
if (body.emitFlags & NodeEmitFlags.SourceMapEmitOpenBraceAsToken) {
1692-
write(" ");
1693-
writeToken(SyntaxKind.OpenBraceToken, body.pos);
1694-
}
1695-
else {
1696-
write(" {");
1697-
}
1698-
1654+
write(" {");
16991655
increaseIndent();
17001656

17011657
emitBodyWithDetachedComments(body, body.statements,
@@ -1734,7 +1690,7 @@ const _super = (function (geti, seti) {
17341690
emitDecorators(node, node.decorators);
17351691
emitModifiers(node, node.modifiers);
17361692
write("class");
1737-
emitSpecializedWithPrefix(" ", node.name, NodeEmitFlags.NoSourceMap);
1693+
emitNodeWithPrefix(" ", node.name, emitIdentifierName);
17381694

17391695
const indentedFlag = node.emitFlags & NodeEmitFlags.Indented;
17401696
if (indentedFlag) {
@@ -2262,16 +2218,6 @@ const _super = (function (geti, seti) {
22622218
emitNodeWithPrefix(prefix, node, emit);
22632219
}
22642220

2265-
// TODO(rbuckton): This should be removed once source maps are aligned with the old
2266-
// emitter and new baselines are taken. This exists solely to
2267-
// align with the old emitter.
2268-
function emitSpecializedWithPrefix(prefix: string, node: Node, flags: NodeEmitFlags) {
2269-
if (node) {
2270-
write(prefix);
2271-
emitSpecialized(node, flags);
2272-
}
2273-
}
2274-
22752221
function emitExpressionWithPrefix(prefix: string, node: Node) {
22762222
emitNodeWithPrefix(prefix, node, emitExpression);
22772223
}

src/compiler/transformers/es6.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ namespace ts {
10741074
])
10751075
);
10761076

1077-
setNodeEmitFlags(forStatement, NodeEmitFlags.SourceMapAdjustRestParameterLoop | NodeEmitFlags.CustomPrologue);
1077+
setNodeEmitFlags(forStatement, NodeEmitFlags.CustomPrologue);
10781078
startOnNewLine(forStatement);
10791079
statements.push(forStatement);
10801080
}

src/compiler/transformers/ts.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,14 +2836,6 @@ namespace ts {
28362836
/*location*/ blockLocation,
28372837
/*multiLine*/ true
28382838
);
2839-
2840-
// TODO(rbuckton): This should be removed once source maps are aligned with the old
2841-
// emitter and new baselines are taken. This exists solely to
2842-
// align with the old emitter.
2843-
if (body.kind === SyntaxKind.ModuleBlock) {
2844-
setNodeEmitFlags(block, NodeEmitFlags.SourceMapEmitOpenBraceAsToken);
2845-
}
2846-
28472839
return block;
28482840
}
28492841

src/compiler/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,13 +3110,6 @@ namespace ts {
31103110
AsyncFunctionBody = 1 << 21,
31113111
ReuseTempVariableScope = 1 << 22, // Reuse the existing temp variable scope during emit.
31123112
CustomPrologue = 1 << 23, // Treat the statement as if it were a prologue directive (NOTE: Prologue directives are *not* transformed).
3113-
3114-
// SourceMap Specialization.
3115-
// TODO(rbuckton): These should be removed once source maps are aligned with the old
3116-
// emitter and new baselines are taken. This exists solely to
3117-
// align with the old emitter.
3118-
SourceMapEmitOpenBraceAsToken = 1 << 24, // Emits the open brace of a block function body as a source mapped token.
3119-
SourceMapAdjustRestParameterLoop = 1 << 25, // Emits adjusted source map positions for a ForStatement generated when transforming a rest parameter for ES5/3.
31203113
}
31213114

31223115
/** Additional context provided to `visitEachChild` */

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,21 @@ sourceFile:contextualTyping.ts
160160
1->
161161
2 >^^^^^^^^^^^
162162
3 > ^^^^
163-
4 > ^^
164-
5 > ^
165-
6 > ^^^^^^^^^^^^->
163+
4 > ^^^^^^^^^^^^^^^->
166164
1->
167165
2 >module
168166
3 > C2T5
169-
4 >
170-
5 > {
171167
1->Emitted(12, 1) Source(21, 1) + SourceIndex(0)
172168
2 >Emitted(12, 12) Source(21, 8) + SourceIndex(0)
173169
3 >Emitted(12, 16) Source(21, 12) + SourceIndex(0)
174-
4 >Emitted(12, 18) Source(21, 13) + SourceIndex(0)
175-
5 >Emitted(12, 19) Source(21, 14) + SourceIndex(0)
176170
---
177171
>>> C2T5.foo = function (i) {
178172
1->^^^^
179173
2 > ^^^^^^^^
180174
3 > ^^^
181175
4 > ^^^^^^^^^^
182176
5 > ^
183-
1->
177+
1-> {
184178
> export var
185179
2 > foo
186180
3 > : (i: number, s: string) => number =
@@ -1100,19 +1094,13 @@ sourceFile:contextualTyping.ts
11001094
1->
11011095
2 >^^^^^^^^^^^
11021096
3 > ^^^^
1103-
4 > ^^
1104-
5 > ^
1105-
6 > ^^^^^^^^^^^^^^^->
1097+
4 > ^^^^^^^^^^^^^^^^^^->
11061098
1->
11071099
2 >module
11081100
3 > C5T5
1109-
4 >
1110-
5 > {
11111101
1->Emitted(51, 1) Source(66, 1) + SourceIndex(0)
11121102
2 >Emitted(51, 12) Source(66, 8) + SourceIndex(0)
11131103
3 >Emitted(51, 16) Source(66, 12) + SourceIndex(0)
1114-
4 >Emitted(51, 18) Source(66, 13) + SourceIndex(0)
1115-
5 >Emitted(51, 19) Source(66, 14) + SourceIndex(0)
11161104
---
11171105
>>> C5T5.foo = function (i, s) {
11181106
1->^^^^
@@ -1123,7 +1111,7 @@ sourceFile:contextualTyping.ts
11231111
6 > ^
11241112
7 > ^^
11251113
8 > ^
1126-
1->
1114+
1-> {
11271115
> export var foo: (i: number, s: string) => string;
11281116
>
11291117
2 >

0 commit comments

Comments
 (0)