Skip to content

Commit 738dde1

Browse files
committed
Merge pull request #6745 from Microsoft/fix6637
Fix6637
2 parents 3865e71 + 695e58b commit 738dde1

File tree

49 files changed

+570
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+570
-9
lines changed

src/compiler/sourcemap.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ namespace ts {
1616
}
1717

1818
let nullSourceMapWriter: SourceMapWriter;
19+
// Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans
20+
const defaultLastEncodedSourceMapSpan: SourceMapSpan = {
21+
emittedLine: 1,
22+
emittedColumn: 1,
23+
sourceLine: 1,
24+
sourceColumn: 1,
25+
sourceIndex: 0
26+
};
1927

2028
export function getNullSourceMapWriter(): SourceMapWriter {
2129
if (nullSourceMapWriter === undefined) {
@@ -79,13 +87,7 @@ namespace ts {
7987

8088
// Last recorded and encoded spans
8189
lastRecordedSourceMapSpan = undefined;
82-
lastEncodedSourceMapSpan = {
83-
emittedLine: 1,
84-
emittedColumn: 1,
85-
sourceLine: 1,
86-
sourceColumn: 1,
87-
sourceIndex: 0
88-
};
90+
lastEncodedSourceMapSpan = defaultLastEncodedSourceMapSpan;
8991
lastEncodedNameIndex = 0;
9092

9193
// Initialize source map data
@@ -159,10 +161,12 @@ namespace ts {
159161
// Pop sourceMapDecodedMappings to remove last entry
160162
sourceMapData.sourceMapDecodedMappings.pop();
161163

162-
// Change the last encoded source map
164+
// Point the lastEncodedSourceMapSpace to the previous encoded sourceMapSpan
165+
// If the list is empty which indicates that we are at the beginning of the file,
166+
// we have to reset it to default value (same value when we first initialize sourceMapWriter)
163167
lastEncodedSourceMapSpan = sourceMapData.sourceMapDecodedMappings.length ?
164168
sourceMapData.sourceMapDecodedMappings[sourceMapData.sourceMapDecodedMappings.length - 1] :
165-
undefined;
169+
defaultLastEncodedSourceMapSpan;
166170

167171
// TODO: Update lastEncodedNameIndex
168172
// Since we dont support this any more, lets not worry about it right now.

tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js

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

tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
===================================================================
2+
JsFile: sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js
3+
mapUrl: sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js.map
4+
sourceRoot:
5+
sources: sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js
9+
sourceFile:sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts
10+
-------------------------------------------------------------------
11+
>>>var x = [1, 2][0];
12+
1 >
13+
2 >^^^^^^^^^^^^^^^^^
14+
3 > ^
15+
4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
16+
1 >
17+
>var [
18+
2 >x
19+
3 > ] = [1, 2];
20+
1 >Emitted(1, 1) Source(2, 6) + SourceIndex(0)
21+
2 >Emitted(1, 18) Source(2, 7) + SourceIndex(0)
22+
3 >Emitted(1, 19) Source(2, 18) + SourceIndex(0)
23+
---
24+
>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.js.map
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts ===
2+
3+
var [x] = [1, 2];
4+
>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts, 1, 5))
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern4.ts ===
2+
3+
var [x] = [1, 2];
4+
>x : number
5+
>[1, 2] : [number, number]
6+
>1 : number
7+
>2 : number
8+

tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js

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

tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
===================================================================
2+
JsFile: sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js
3+
mapUrl: sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js.map
4+
sourceRoot:
5+
sources: sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js
9+
sourceFile:sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts
10+
-------------------------------------------------------------------
11+
>>>var x = [1, 2][0];
12+
1 >
13+
2 >^^^^^^^^^^^^^^^^^
14+
3 > ^
15+
4 > ^^^^^^^^^^^^^^^^^^^^^->
16+
1 >
17+
>var [
18+
2 >x
19+
3 > ] = [1, 2];
20+
1 >Emitted(1, 1) Source(2, 6) + SourceIndex(0)
21+
2 >Emitted(1, 18) Source(2, 7) + SourceIndex(0)
22+
3 >Emitted(1, 19) Source(2, 18) + SourceIndex(0)
23+
---
24+
>>>var _a = [1, 2], y = _a[0], z = _a[1];
25+
1->
26+
2 >^^^^
27+
3 > ^^^^^^^^^^^
28+
4 > ^^
29+
5 > ^^^^^^^^^
30+
6 > ^^
31+
7 > ^^^^^^^^^
32+
8 > ^
33+
9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
34+
1->
35+
>
36+
2 >
37+
3 > var [y, z] = [1, 2]
38+
4 >
39+
5 > y
40+
6 > ,
41+
7 > z
42+
8 > ] = [1, 2];
43+
1->Emitted(2, 1) Source(3, 1) + SourceIndex(0)
44+
2 >Emitted(2, 5) Source(3, 1) + SourceIndex(0)
45+
3 >Emitted(2, 16) Source(3, 20) + SourceIndex(0)
46+
4 >Emitted(2, 18) Source(3, 6) + SourceIndex(0)
47+
5 >Emitted(2, 27) Source(3, 7) + SourceIndex(0)
48+
6 >Emitted(2, 29) Source(3, 9) + SourceIndex(0)
49+
7 >Emitted(2, 38) Source(3, 10) + SourceIndex(0)
50+
8 >Emitted(2, 39) Source(3, 21) + SourceIndex(0)
51+
---
52+
>>>//# sourceMappingURL=sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.js.map
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts ===
2+
3+
var [x] = [1, 2];
4+
>x : Symbol(x, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts, 1, 5))
5+
6+
var [y, z] = [1, 2];
7+
>y : Symbol(y, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts, 2, 5))
8+
>z : Symbol(z, Decl(sourceMapValidationDestructuringVariableStatementArrayBindingPattern5.ts, 2, 7))
9+

0 commit comments

Comments
 (0)