Skip to content

Commit dac1874

Browse files
committed
Merge pull request #5713 from Microsoft/noSourcemapNames
Do not emit names and name index mapping in source map
2 parents b40079e + f315fc1 commit dac1874

File tree

1,194 files changed

+15703
-15808
lines changed

Some content is hidden

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

1,194 files changed

+15703
-15808
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
465465
const { write, writeTextOfNode, writeLine, increaseIndent, decreaseIndent } = writer;
466466

467467
const sourceMap = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? createSourceMapWriter(host, writer) : getNullSourceMapWriter();
468-
const { setSourceFile, emitStart, emitEnd, emitPos, pushScope, popScope } = sourceMap;
468+
const { setSourceFile, emitStart, emitEnd, emitPos } = sourceMap;
469469

470470
let currentSourceFile: SourceFile;
471471
let currentText: string;
@@ -2700,7 +2700,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
27002700

27012701
emitToken(SyntaxKind.OpenBraceToken, node.pos);
27022702
increaseIndent();
2703-
pushScope(node.parent);
27042703
if (node.kind === SyntaxKind.ModuleBlock) {
27052704
Debug.assert(node.parent.kind === SyntaxKind.ModuleDeclaration);
27062705
emitCaptureThisForNodeIfNecessary(node.parent);
@@ -2712,7 +2711,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
27122711
decreaseIndent();
27132712
writeLine();
27142713
emitToken(SyntaxKind.CloseBraceToken, node.statements.end);
2715-
popScope();
27162714
}
27172715

27182716
function emitEmbeddedStatement(node: Node) {
@@ -4578,8 +4576,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
45784576

45794577
function emitDownLevelExpressionFunctionBody(node: FunctionLikeDeclaration, body: Expression) {
45804578
write(" {");
4581-
pushScope(node);
4582-
45834579
increaseIndent();
45844580
const outPos = writer.getTextPos();
45854581
emitDetachedCommentsAndUpdateCommentsInfo(node.body);
@@ -4618,14 +4614,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
46184614
emitStart(node.body);
46194615
write("}");
46204616
emitEnd(node.body);
4621-
4622-
popScope();
46234617
}
46244618

46254619
function emitBlockFunctionBody(node: FunctionLikeDeclaration, body: Block) {
46264620
write(" {");
4627-
pushScope(node);
4628-
46294621
const initialTextPos = writer.getTextPos();
46304622

46314623
increaseIndent();
@@ -4659,7 +4651,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
46594651
}
46604652

46614653
emitToken(SyntaxKind.CloseBraceToken, body.statements.end);
4662-
popScope();
46634654
}
46644655

46654656
function findInitialSuperCall(ctor: ConstructorDeclaration): ExpressionStatement {
@@ -4945,7 +4936,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
49454936
let startIndex = 0;
49464937

49474938
write(" {");
4948-
pushScope(node, "constructor");
49494939
increaseIndent();
49504940
if (ctor) {
49514941
// Emit all the directive prologues (like "use strict"). These have to come before
@@ -4995,7 +4985,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
49954985
}
49964986
decreaseIndent();
49974987
emitToken(SyntaxKind.CloseBraceToken, ctor ? (<Block>ctor.body).statements.end : node.members.end);
4998-
popScope();
49994988
emitEnd(<Node>ctor || node);
50004989
if (ctor) {
50014990
emitTrailingComments(ctor);
@@ -5132,14 +5121,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
51325121

51335122
write(" {");
51345123
increaseIndent();
5135-
pushScope(node);
51365124
writeLine();
51375125
emitConstructor(node, baseTypeNode);
51385126
emitMemberFunctionsForES6AndHigher(node);
51395127
decreaseIndent();
51405128
writeLine();
51415129
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
5142-
popScope();
51435130

51445131
// TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now.
51455132

@@ -5241,7 +5228,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
52415228
tempParameters = undefined;
52425229
computedPropertyNamesToGeneratedNames = undefined;
52435230
increaseIndent();
5244-
pushScope(node);
52455231
if (baseTypeNode) {
52465232
writeLine();
52475233
emitStart(baseTypeNode);
@@ -5274,7 +5260,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
52745260
decreaseIndent();
52755261
writeLine();
52765262
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
5277-
popScope();
52785263
emitStart(node);
52795264
write(")(");
52805265
if (baseTypeNode) {
@@ -5831,12 +5816,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
58315816
emitEnd(node.name);
58325817
write(") {");
58335818
increaseIndent();
5834-
pushScope(node);
58355819
emitLines(node.members);
58365820
decreaseIndent();
58375821
writeLine();
58385822
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
5839-
popScope();
58405823
write(")(");
58415824
emitModuleMemberName(node);
58425825
write(" || (");
@@ -5960,15 +5943,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
59605943
else {
59615944
write("{");
59625945
increaseIndent();
5963-
pushScope(node);
59645946
emitCaptureThisForNodeIfNecessary(node);
59655947
writeLine();
59665948
emit(node.body);
59675949
decreaseIndent();
59685950
writeLine();
59695951
const moduleBlock = <ModuleBlock>getInnerMostModuleDeclarationFromDottedModule(node).body;
59705952
emitToken(SyntaxKind.CloseBraceToken, moduleBlock.statements.end);
5971-
popScope();
59725953
}
59735954
write(")(");
59745955
// write moduleDecl = containingModule.m only if it is not exported es6 module member

src/compiler/sourcemap.ts

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace ts {
88
emitPos(pos: number): void;
99
emitStart(range: TextRange): void;
1010
emitEnd(range: TextRange): void;
11-
pushScope(scopeDeclaration: Node, scopeName?: string): void;
12-
popScope(): void;
1311
getText(): string;
1412
getSourceMappingURL(): string;
1513
initialize(filePath: string, sourceMapFilePath: string, sourceFiles: SourceFile[], isBundledEmit: boolean): void;
@@ -27,8 +25,6 @@ namespace ts {
2725
emitStart(range: TextRange): void { },
2826
emitEnd(range: TextRange): void { },
2927
emitPos(pos: number): void { },
30-
pushScope(scopeDeclaration: Node, scopeName?: string): void { },
31-
popScope(): void { },
3228
getText(): string { return undefined; },
3329
getSourceMappingURL(): string { return undefined; },
3430
initialize(filePath: string, sourceMapFilePath: string, sourceFiles: SourceFile[], isBundledEmit: boolean): void { },
@@ -47,10 +43,6 @@ namespace ts {
4743
// Current source map file and its index in the sources list
4844
let sourceMapSourceIndex: number;
4945

50-
// Names and its index map
51-
let sourceMapNameIndexMap: Map<number>;
52-
let sourceMapNameIndices: number[];
53-
5446
// Last recorded and encoded spans
5547
let lastRecordedSourceMapSpan: SourceMapSpan;
5648
let lastEncodedSourceMapSpan: SourceMapSpan;
@@ -65,8 +57,6 @@ namespace ts {
6557
emitPos,
6658
emitStart,
6759
emitEnd,
68-
pushScope,
69-
popScope,
7060
getText,
7161
getSourceMappingURL,
7262
initialize,
@@ -83,10 +73,6 @@ namespace ts {
8373
// Current source map file and its index in the sources list
8474
sourceMapSourceIndex = -1;
8575

86-
// Names and its index map
87-
sourceMapNameIndexMap = {};
88-
sourceMapNameIndices = [];
89-
9076
// Last recorded and encoded spans
9177
lastRecordedSourceMapSpan = undefined;
9278
lastEncodedSourceMapSpan = {
@@ -151,18 +137,12 @@ namespace ts {
151137
currentSourceFile = undefined;
152138
sourceMapDir = undefined;
153139
sourceMapSourceIndex = undefined;
154-
sourceMapNameIndexMap = undefined;
155-
sourceMapNameIndices = undefined;
156140
lastRecordedSourceMapSpan = undefined;
157141
lastEncodedSourceMapSpan = undefined;
158142
lastEncodedNameIndex = undefined;
159143
sourceMapData = undefined;
160144
}
161145

162-
function getSourceMapNameIndex() {
163-
return sourceMapNameIndices.length ? lastOrUndefined(sourceMapNameIndices) : -1;
164-
}
165-
166146
// Encoding for sourcemap span
167147
function encodeLastRecordedSourceMapSpan() {
168148
if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) {
@@ -238,7 +218,6 @@ namespace ts {
238218
emittedColumn: emittedColumn,
239219
sourceLine: sourceLinePos.line,
240220
sourceColumn: sourceLinePos.character,
241-
nameIndex: getSourceMapNameIndex(),
242221
sourceIndex: sourceMapSourceIndex
243222
};
244223
}
@@ -287,70 +266,6 @@ namespace ts {
287266
}
288267
}
289268

290-
function recordScopeNameIndex(scopeNameIndex: number) {
291-
sourceMapNameIndices.push(scopeNameIndex);
292-
}
293-
294-
function recordScopeNameStart(scopeDeclaration: Node, scopeName: string) {
295-
let scopeNameIndex = -1;
296-
if (scopeName) {
297-
const parentIndex = getSourceMapNameIndex();
298-
if (parentIndex !== -1) {
299-
// Child scopes are always shown with a dot (even if they have no name),
300-
// unless it is a computed property. Then it is shown with brackets,
301-
// but the brackets are included in the name.
302-
const name = (<Declaration>scopeDeclaration).name;
303-
if (!name || name.kind !== SyntaxKind.ComputedPropertyName) {
304-
scopeName = "." + scopeName;
305-
}
306-
scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName;
307-
}
308-
309-
scopeNameIndex = getProperty(sourceMapNameIndexMap, scopeName);
310-
if (scopeNameIndex === undefined) {
311-
scopeNameIndex = sourceMapData.sourceMapNames.length;
312-
sourceMapData.sourceMapNames.push(scopeName);
313-
sourceMapNameIndexMap[scopeName] = scopeNameIndex;
314-
}
315-
}
316-
recordScopeNameIndex(scopeNameIndex);
317-
}
318-
319-
function pushScope(scopeDeclaration: Node, scopeName?: string) {
320-
if (scopeName) {
321-
// The scope was already given a name use it
322-
recordScopeNameStart(scopeDeclaration, scopeName);
323-
}
324-
else if (scopeDeclaration.kind === SyntaxKind.FunctionDeclaration ||
325-
scopeDeclaration.kind === SyntaxKind.FunctionExpression ||
326-
scopeDeclaration.kind === SyntaxKind.MethodDeclaration ||
327-
scopeDeclaration.kind === SyntaxKind.MethodSignature ||
328-
scopeDeclaration.kind === SyntaxKind.GetAccessor ||
329-
scopeDeclaration.kind === SyntaxKind.SetAccessor ||
330-
scopeDeclaration.kind === SyntaxKind.ModuleDeclaration ||
331-
scopeDeclaration.kind === SyntaxKind.ClassDeclaration ||
332-
scopeDeclaration.kind === SyntaxKind.EnumDeclaration) {
333-
// Declaration and has associated name use it
334-
if ((<Declaration>scopeDeclaration).name) {
335-
const name = (<Declaration>scopeDeclaration).name;
336-
// For computed property names, the text will include the brackets
337-
scopeName = name.kind === SyntaxKind.ComputedPropertyName
338-
? getTextOfNode(name)
339-
: (<Identifier>(<Declaration>scopeDeclaration).name).text;
340-
}
341-
342-
recordScopeNameStart(scopeDeclaration, scopeName);
343-
}
344-
else {
345-
// Block just use the name from upper level scope
346-
recordScopeNameIndex(getSourceMapNameIndex());
347-
}
348-
}
349-
350-
function popScope() {
351-
sourceMapNameIndices.pop();
352-
}
353-
354269
function getText() {
355270
encodeLastRecordedSourceMapSpan();
356271

src/harness/sourceMapRecorder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ namespace Harness.SourceMapRecoder {
172172
return { error: errorDecodeOfEncodedMapping, sourceMapSpan: decodeOfEncodedMapping };
173173
}
174174
// 5. Check if there is name:
175-
decodeOfEncodedMapping.nameIndex = -1;
176175
if (!isSourceMappingSegmentEnd()) {
177176
prevNameIndex += base64VLQFormatDecode();
178177
decodeOfEncodedMapping.nameIndex = prevNameIndex;
@@ -249,7 +248,7 @@ namespace Harness.SourceMapRecoder {
249248
mapString += " name (" + sourceMapNames[mapEntry.nameIndex] + ")";
250249
}
251250
else {
252-
if (mapEntry.nameIndex !== -1 || getAbsentNameIndex) {
251+
if ((mapEntry.nameIndex && mapEntry.nameIndex !== -1) || getAbsentNameIndex) {
253252
mapString += " nameIndex (" + mapEntry.nameIndex + ")";
254253
}
255254
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ sourceFile:ES5For-of8.ts
3434
7 > 0
3535
8 > }
3636
9 > ;
37-
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) name (foo)
38-
2 >Emitted(2, 11) Source(2, 11) + SourceIndex(0) name (foo)
39-
3 >Emitted(2, 12) Source(2, 12) + SourceIndex(0) name (foo)
40-
4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) name (foo)
41-
5 >Emitted(2, 15) Source(2, 15) + SourceIndex(0) name (foo)
42-
6 >Emitted(2, 17) Source(2, 17) + SourceIndex(0) name (foo)
43-
7 >Emitted(2, 18) Source(2, 18) + SourceIndex(0) name (foo)
44-
8 >Emitted(2, 20) Source(2, 20) + SourceIndex(0) name (foo)
45-
9 >Emitted(2, 21) Source(2, 21) + SourceIndex(0) name (foo)
37+
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0)
38+
2 >Emitted(2, 11) Source(2, 11) + SourceIndex(0)
39+
3 >Emitted(2, 12) Source(2, 12) + SourceIndex(0)
40+
4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0)
41+
5 >Emitted(2, 15) Source(2, 15) + SourceIndex(0)
42+
6 >Emitted(2, 17) Source(2, 17) + SourceIndex(0)
43+
7 >Emitted(2, 18) Source(2, 18) + SourceIndex(0)
44+
8 >Emitted(2, 20) Source(2, 20) + SourceIndex(0)
45+
9 >Emitted(2, 21) Source(2, 21) + SourceIndex(0)
4646
---
4747
>>>}
4848
1 >
@@ -51,8 +51,8 @@ sourceFile:ES5For-of8.ts
5151
1 >
5252
>
5353
2 >}
54-
1 >Emitted(3, 1) Source(3, 1) + SourceIndex(0) name (foo)
55-
2 >Emitted(3, 2) Source(3, 2) + SourceIndex(0) name (foo)
54+
1 >Emitted(3, 1) Source(3, 1) + SourceIndex(0)
55+
2 >Emitted(3, 2) Source(3, 2) + SourceIndex(0)
5656
---
5757
>>>for (var _i = 0, _a = ['a', 'b', 'c']; _i < _a.length; _i++) {
5858
1->

tests/baselines/reference/computedPropertyNamesSourceMap1_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.

0 commit comments

Comments
 (0)