Skip to content

Commit ef86f7d

Browse files
committed
Adjust source map offsets for variables in downlevel async funcs and generators
1 parent b94c513 commit ef86f7d

8 files changed

+101
-8
lines changed

src/compiler/transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ namespace ts {
239239
function hoistVariableDeclaration(name: Identifier): void {
240240
Debug.assert(state > TransformationState.Uninitialized, "Cannot modify the lexical environment during initialization.");
241241
Debug.assert(state < TransformationState.Completed, "Cannot modify the lexical environment after transformation has completed.");
242-
const decl = createVariableDeclaration(name);
242+
const decl = setEmitFlags(createVariableDeclaration(name), EmitFlags.NoNestedSourceMaps);
243243
if (!lexicalEnvironmentVariableDeclarations) {
244244
lexicalEnvironmentVariableDeclarations = [decl];
245245
}

src/compiler/transformers/generators.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,13 @@ namespace ts {
640640
return undefined;
641641
}
642642

643-
return createStatement(
644-
inlineExpressions(
645-
map(variables, transformInitializedVariable)
646-
)
643+
return setSourceMapRange(
644+
createStatement(
645+
inlineExpressions(
646+
map(variables, transformInitializedVariable)
647+
)
648+
),
649+
node
647650
);
648651
}
649652
}
@@ -1281,9 +1284,12 @@ namespace ts {
12811284
}
12821285

12831286
function transformInitializedVariable(node: VariableDeclaration) {
1284-
return createAssignment(
1285-
<Identifier>getSynthesizedClone(node.name),
1286-
visitNode(node.initializer, visitor, isExpression)
1287+
return setSourceMapRange(
1288+
createAssignment(
1289+
setSourceMapRange(<Identifier>getSynthesizedClone(node.name), node.name),
1290+
visitNode(node.initializer, visitor, isExpression)
1291+
),
1292+
node
12871293
);
12881294
}
12891295

tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.js

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/sourceMapValidationVarInDownLevelGenerator.js.map

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
===================================================================
2+
JsFile: sourceMapValidationVarInDownLevelGenerator.js
3+
mapUrl: sourceMapValidationVarInDownLevelGenerator.js.map
4+
sourceRoot:
5+
sources: sourceMapValidationVarInDownLevelGenerator.ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:tests/cases/compiler/sourceMapValidationVarInDownLevelGenerator.js
9+
sourceFile:sourceMapValidationVarInDownLevelGenerator.ts
10+
-------------------------------------------------------------------
11+
>>>function f() {
12+
1 >
13+
2 >^^^^^^^^^^^^^^->
14+
1 >
15+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
16+
---
17+
>>> var x, y;
18+
>>> return __generator(this, function (_a) {
19+
>>> x = 1;
20+
1->^^^^^^^^
21+
2 > ^
22+
3 > ^^^
23+
4 > ^
24+
5 > ^
25+
6 > ^^^^^^^^^^^^^^^^^->
26+
1->function * f() {
27+
> var
28+
2 > x
29+
3 > =
30+
4 > 1
31+
5 > , y;
32+
1->Emitted(4, 9) Source(2, 9) + SourceIndex(0)
33+
2 >Emitted(4, 10) Source(2, 10) + SourceIndex(0)
34+
3 >Emitted(4, 13) Source(2, 13) + SourceIndex(0)
35+
4 >Emitted(4, 14) Source(2, 14) + SourceIndex(0)
36+
5 >Emitted(4, 15) Source(2, 18) + SourceIndex(0)
37+
---
38+
>>> return [2 /*return*/];
39+
>>> });
40+
>>>}
41+
1->^
42+
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
43+
1->
44+
>}
45+
1->Emitted(7, 2) Source(3, 2) + SourceIndex(0)
46+
---
47+
>>>//# sourceMappingURL=sourceMapValidationVarInDownLevelGenerator.js.map
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/sourceMapValidationVarInDownLevelGenerator.ts ===
2+
function * f() {
3+
>f : Symbol(f, Decl(sourceMapValidationVarInDownLevelGenerator.ts, 0, 0))
4+
5+
var x = 1, y;
6+
>x : Symbol(x, Decl(sourceMapValidationVarInDownLevelGenerator.ts, 1, 7))
7+
>y : Symbol(y, Decl(sourceMapValidationVarInDownLevelGenerator.ts, 1, 14))
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/sourceMapValidationVarInDownLevelGenerator.ts ===
2+
function * f() {
3+
>f : () => IterableIterator<any>
4+
5+
var x = 1, y;
6+
>x : number
7+
>1 : 1
8+
>y : any
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @sourcemap: true
2+
// @downlevelIteration: true
3+
// @noEmitHelpers: true
4+
// @lib: es2015
5+
function * f() {
6+
var x = 1, y;
7+
}

0 commit comments

Comments
 (0)