Skip to content

Commit 65a641f

Browse files
committed
[Transforms] Fix other sourcemaps (microsoft#8721)
* Update correct sourcemaps * Fix emit BOM in sourcemap * Stop emit .js.map when no .js is emitted * verify and update sourcemaps and sourcemap.txt * Verify and update systemjs sourcemaps
1 parent 9cd96e6 commit 65a641f

20 files changed

Lines changed: 79 additions & 190 deletions

src/compiler/printer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ const _super = (function (geti, seti) {
218218

219219
// Write the source map
220220
if (compilerOptions.sourceMap && !compilerOptions.inlineSourceMap) {
221-
writeFile(host, emitterDiagnostics, sourceMapFilePath, sourceMap.getText(), compilerOptions.emitBOM);
221+
writeFile(host, emitterDiagnostics, sourceMapFilePath, sourceMap.getText(), /*writeByteOrderMark*/ false);
222222
}
223223

224224
// Record source map data for the test harness.

src/harness/compilerRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class CompilerBaselineRunner extends RunnerBase {
156156
if (options.sourceMap || options.inlineSourceMap) {
157157
Harness.Baseline.runBaseline("Correct sourcemap content for " + fileName, justName.replace(/\.tsx?$/, ".sourcemap.txt"), () => {
158158
const record = result.getSourceMapRecord();
159-
if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) {
159+
if ((options.noEmitOnError && result.errors.length !== 0) || record === undefined) {
160160
// Because of the noEmitOnError option no files are created. We need to return null because baselining isn"t required.
161161
return null;
162162
}
@@ -232,7 +232,7 @@ class CompilerBaselineRunner extends RunnerBase {
232232
}
233233

234234
Harness.Baseline.runBaseline("Correct Sourcemap output for " + fileName, justName.replace(/\.tsx?/, ".js.map"), () => {
235-
if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) {
235+
if ((options.noEmitOnError && result.errors.length !== 0) || result.sourceMaps.length === 0) {
236236
// We need to return null here or the runBaseLine will actually create a empty file.
237237
// Baselining isn't required here because there is no output.
238238
return null;

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ namespace Harness {
14321432
}
14331433

14341434
public getSourceMapRecord() {
1435-
if (this.sourceMapData) {
1435+
if (this.sourceMapData.length > 0) {
14361436
return Harness.SourceMapRecorder.getSourceMapRecord(this.sourceMapData, this.program, this.files);
14371437
}
14381438
}

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,28 @@ sourceFile:computedPropertyNamesSourceMap2_ES5.ts
1212
1 >
1313
2 >^^^^
1414
3 > ^
15-
4 > ^^^
16-
5 > ^^^^^^^^^^^^^^^^^^^^^^^^->
15+
4 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1716
1 >
1817
2 >var
1918
3 > v
20-
4 > =
2119
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2220
2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
2321
3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0)
24-
4 >Emitted(1, 9) Source(1, 9) + SourceIndex(0)
2522
---
2623
>>> _a["hello"] = function () {
2724
1->^^^^
2825
2 > ^^^
2926
3 > ^^^^^^^
30-
4 > ^
31-
5 > ^^^
32-
1->{
27+
4 > ^^^^
28+
1-> = {
3329
>
3430
2 > [
3531
3 > "hello"
36-
4 > ]
37-
5 >
32+
4 >
3833
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0)
3934
2 >Emitted(2, 8) Source(2, 6) + SourceIndex(0)
4035
3 >Emitted(2, 15) Source(2, 13) + SourceIndex(0)
41-
4 >Emitted(2, 16) Source(2, 14) + SourceIndex(0)
42-
5 >Emitted(2, 19) Source(2, 5) + SourceIndex(0)
36+
4 >Emitted(2, 19) Source(2, 5) + SourceIndex(0)
4337
---
4438
>>> debugger;
4539
1 >^^^^^^^^

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: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,28 +1116,31 @@ sourceFile:contextualTyping.ts
11161116
---
11171117
>>> C5T5.foo = function (i, s) {
11181118
1->^^^^
1119-
2 > ^^^^^^^^
1120-
3 > ^^^
1121-
4 > ^^^^^^^^^^
1122-
5 > ^
1123-
6 > ^^
1124-
7 > ^
1119+
2 > ^^^^^
1120+
3 > ^^^
1121+
4 > ^^^
1122+
5 > ^^^^^^^^^^
1123+
6 > ^
1124+
7 > ^^
1125+
8 > ^
11251126
1->
11261127
> export var foo: (i: number, s: string) => string;
11271128
>
1128-
2 > foo
1129-
3 > =
1130-
4 > function(
1131-
5 > i
1132-
6 > ,
1133-
7 > s
1129+
2 >
1130+
3 > foo
1131+
4 > =
1132+
5 > function(
1133+
6 > i
1134+
7 > ,
1135+
8 > s
11341136
1->Emitted(52, 5) Source(68, 5) + SourceIndex(0)
1135-
2 >Emitted(52, 13) Source(68, 8) + SourceIndex(0)
1136-
3 >Emitted(52, 16) Source(68, 11) + SourceIndex(0)
1137-
4 >Emitted(52, 26) Source(68, 20) + SourceIndex(0)
1138-
5 >Emitted(52, 27) Source(68, 21) + SourceIndex(0)
1139-
6 >Emitted(52, 29) Source(68, 23) + SourceIndex(0)
1140-
7 >Emitted(52, 30) Source(68, 24) + SourceIndex(0)
1137+
2 >Emitted(52, 10) Source(68, 5) + SourceIndex(0)
1138+
3 >Emitted(52, 13) Source(68, 8) + SourceIndex(0)
1139+
4 >Emitted(52, 16) Source(68, 11) + SourceIndex(0)
1140+
5 >Emitted(52, 26) Source(68, 20) + SourceIndex(0)
1141+
6 >Emitted(52, 27) Source(68, 21) + SourceIndex(0)
1142+
7 >Emitted(52, 29) Source(68, 23) + SourceIndex(0)
1143+
8 >Emitted(52, 30) Source(68, 24) + SourceIndex(0)
11411144
---
11421145
>>> return s;
11431146
1 >^^^^^^^^

tests/baselines/reference/getEmitOutputTsxFile_React.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare class Bar {
1717

1818
EmitSkipped: false
1919
FileName : tests/cases/fourslash/inputFile2.js.map
20-
{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AACA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,qBAAC,GAAG,IAAC,IAAI,EAAG,CAAE,EAAG,CAAA"}FileName : tests/cases/fourslash/inputFile2.js
20+
{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AACA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,6BAAK,IAAI,EAAG,CAAC,GAAI,CAAA"}FileName : tests/cases/fourslash/inputFile2.js
2121
var y = "my div";
2222
var x = React.createElement("div", { name: y });
2323
//# sourceMappingURL=inputFile2.js.mapFileName : tests/cases/fourslash/inputFile2.d.ts

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,11 @@ sourceFile:tests/cases/compiler/ref/a.ts
6262
---
6363
>>> exports.A = A;
6464
1->^^^^
65-
2 > ^^^^^^^^^
66-
3 > ^^^^
67-
4 > ^
65+
2 > ^^^^^^^^^^^^^^
6866
1->
69-
2 > A
70-
3 > { }
71-
4 >
72-
1->Emitted(13, 5) Source(2, 14) + SourceIndex(0)
73-
2 >Emitted(13, 14) Source(2, 15) + SourceIndex(0)
74-
3 >Emitted(13, 18) Source(2, 19) + SourceIndex(0)
75-
4 >Emitted(13, 19) Source(2, 19) + SourceIndex(0)
67+
2 > export class A { }
68+
1->Emitted(13, 5) Source(2, 1) + SourceIndex(0)
69+
2 >Emitted(13, 19) Source(2, 19) + SourceIndex(0)
7670
---
7771
-------------------------------------------------------------------
7872
emittedFile:all.js
@@ -150,17 +144,11 @@ sourceFile:tests/cases/compiler/b.ts
150144
---
151145
>>> exports.B = B;
152146
1->^^^^
153-
2 > ^^^^^^^^^
154-
3 > ^^^^
155-
4 > ^
147+
2 > ^^^^^^^^^^^^^^
156148
1->
157-
2 > B
158-
3 > extends A { }
159-
4 >
160-
1->Emitted(24, 5) Source(2, 14) + SourceIndex(1)
161-
2 >Emitted(24, 14) Source(2, 15) + SourceIndex(1)
162-
3 >Emitted(24, 18) Source(2, 29) + SourceIndex(1)
163-
4 >Emitted(24, 19) Source(2, 29) + SourceIndex(1)
149+
2 > export class B extends A { }
150+
1->Emitted(24, 5) Source(2, 1) + SourceIndex(1)
151+
2 >Emitted(24, 19) Source(2, 29) + SourceIndex(1)
164152
---
165153
>>>});
166154
>>>//# sourceMappingURL=all.js.map

0 commit comments

Comments
 (0)