Skip to content

Do not emit names and name index mapping in source map #5713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 1 addition & 20 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
const { write, writeTextOfNode, writeLine, increaseIndent, decreaseIndent } = writer;

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

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

emitToken(SyntaxKind.OpenBraceToken, node.pos);
increaseIndent();
pushScope(node.parent);
if (node.kind === SyntaxKind.ModuleBlock) {
Debug.assert(node.parent.kind === SyntaxKind.ModuleDeclaration);
emitCaptureThisForNodeIfNecessary(node.parent);
Expand All @@ -2712,7 +2711,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
decreaseIndent();
writeLine();
emitToken(SyntaxKind.CloseBraceToken, node.statements.end);
popScope();
}

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

function emitDownLevelExpressionFunctionBody(node: FunctionLikeDeclaration, body: Expression) {
write(" {");
pushScope(node);

increaseIndent();
const outPos = writer.getTextPos();
emitDetachedCommentsAndUpdateCommentsInfo(node.body);
Expand Down Expand Up @@ -4618,14 +4614,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emitStart(node.body);
write("}");
emitEnd(node.body);

popScope();
}

function emitBlockFunctionBody(node: FunctionLikeDeclaration, body: Block) {
write(" {");
pushScope(node);

const initialTextPos = writer.getTextPos();

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

emitToken(SyntaxKind.CloseBraceToken, body.statements.end);
popScope();
}

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

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

write(" {");
increaseIndent();
pushScope(node);
writeLine();
emitConstructor(node, baseTypeNode);
emitMemberFunctionsForES6AndHigher(node);
decreaseIndent();
writeLine();
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
popScope();

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

Expand Down Expand Up @@ -5241,7 +5228,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
tempParameters = undefined;
computedPropertyNamesToGeneratedNames = undefined;
increaseIndent();
pushScope(node);
if (baseTypeNode) {
writeLine();
emitStart(baseTypeNode);
Expand Down Expand Up @@ -5274,7 +5260,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
decreaseIndent();
writeLine();
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
popScope();
emitStart(node);
write(")(");
if (baseTypeNode) {
Expand Down Expand Up @@ -5831,12 +5816,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emitEnd(node.name);
write(") {");
increaseIndent();
pushScope(node);
emitLines(node.members);
decreaseIndent();
writeLine();
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
popScope();
write(")(");
emitModuleMemberName(node);
write(" || (");
Expand Down Expand Up @@ -5960,15 +5943,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
else {
write("{");
increaseIndent();
pushScope(node);
emitCaptureThisForNodeIfNecessary(node);
writeLine();
emit(node.body);
decreaseIndent();
writeLine();
const moduleBlock = <ModuleBlock>getInnerMostModuleDeclarationFromDottedModule(node).body;
emitToken(SyntaxKind.CloseBraceToken, moduleBlock.statements.end);
popScope();
}
write(")(");
// write moduleDecl = containingModule.m only if it is not exported es6 module member
Expand Down
85 changes: 0 additions & 85 deletions src/compiler/sourcemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace ts {
emitPos(pos: number): void;
emitStart(range: TextRange): void;
emitEnd(range: TextRange): void;
pushScope(scopeDeclaration: Node, scopeName?: string): void;
popScope(): void;
getText(): string;
getSourceMappingURL(): string;
initialize(filePath: string, sourceMapFilePath: string, sourceFiles: SourceFile[], isBundledEmit: boolean): void;
Expand All @@ -27,8 +25,6 @@ namespace ts {
emitStart(range: TextRange): void { },
emitEnd(range: TextRange): void { },
emitPos(pos: number): void { },
pushScope(scopeDeclaration: Node, scopeName?: string): void { },
popScope(): void { },
getText(): string { return undefined; },
getSourceMappingURL(): string { return undefined; },
initialize(filePath: string, sourceMapFilePath: string, sourceFiles: SourceFile[], isBundledEmit: boolean): void { },
Expand All @@ -47,10 +43,6 @@ namespace ts {
// Current source map file and its index in the sources list
let sourceMapSourceIndex: number;

// Names and its index map
let sourceMapNameIndexMap: Map<number>;
let sourceMapNameIndices: number[];

// Last recorded and encoded spans
let lastRecordedSourceMapSpan: SourceMapSpan;
let lastEncodedSourceMapSpan: SourceMapSpan;
Expand All @@ -65,8 +57,6 @@ namespace ts {
emitPos,
emitStart,
emitEnd,
pushScope,
popScope,
getText,
getSourceMappingURL,
initialize,
Expand All @@ -83,10 +73,6 @@ namespace ts {
// Current source map file and its index in the sources list
sourceMapSourceIndex = -1;

// Names and its index map
sourceMapNameIndexMap = {};
sourceMapNameIndices = [];

// Last recorded and encoded spans
lastRecordedSourceMapSpan = undefined;
lastEncodedSourceMapSpan = {
Expand Down Expand Up @@ -151,18 +137,12 @@ namespace ts {
currentSourceFile = undefined;
sourceMapDir = undefined;
sourceMapSourceIndex = undefined;
sourceMapNameIndexMap = undefined;
sourceMapNameIndices = undefined;
lastRecordedSourceMapSpan = undefined;
lastEncodedSourceMapSpan = undefined;
lastEncodedNameIndex = undefined;
sourceMapData = undefined;
}

function getSourceMapNameIndex() {
return sourceMapNameIndices.length ? lastOrUndefined(sourceMapNameIndices) : -1;
}

// Encoding for sourcemap span
function encodeLastRecordedSourceMapSpan() {
if (!lastRecordedSourceMapSpan || lastRecordedSourceMapSpan === lastEncodedSourceMapSpan) {
Expand Down Expand Up @@ -238,7 +218,6 @@ namespace ts {
emittedColumn: emittedColumn,
sourceLine: sourceLinePos.line,
sourceColumn: sourceLinePos.character,
nameIndex: getSourceMapNameIndex(),
sourceIndex: sourceMapSourceIndex
};
}
Expand Down Expand Up @@ -287,70 +266,6 @@ namespace ts {
}
}

function recordScopeNameIndex(scopeNameIndex: number) {
sourceMapNameIndices.push(scopeNameIndex);
}

function recordScopeNameStart(scopeDeclaration: Node, scopeName: string) {
let scopeNameIndex = -1;
if (scopeName) {
const parentIndex = getSourceMapNameIndex();
if (parentIndex !== -1) {
// Child scopes are always shown with a dot (even if they have no name),
// unless it is a computed property. Then it is shown with brackets,
// but the brackets are included in the name.
const name = (<Declaration>scopeDeclaration).name;
if (!name || name.kind !== SyntaxKind.ComputedPropertyName) {
scopeName = "." + scopeName;
}
scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName;
}

scopeNameIndex = getProperty(sourceMapNameIndexMap, scopeName);
if (scopeNameIndex === undefined) {
scopeNameIndex = sourceMapData.sourceMapNames.length;
sourceMapData.sourceMapNames.push(scopeName);
sourceMapNameIndexMap[scopeName] = scopeNameIndex;
}
}
recordScopeNameIndex(scopeNameIndex);
}

function pushScope(scopeDeclaration: Node, scopeName?: string) {
if (scopeName) {
// The scope was already given a name use it
recordScopeNameStart(scopeDeclaration, scopeName);
}
else if (scopeDeclaration.kind === SyntaxKind.FunctionDeclaration ||
scopeDeclaration.kind === SyntaxKind.FunctionExpression ||
scopeDeclaration.kind === SyntaxKind.MethodDeclaration ||
scopeDeclaration.kind === SyntaxKind.MethodSignature ||
scopeDeclaration.kind === SyntaxKind.GetAccessor ||
scopeDeclaration.kind === SyntaxKind.SetAccessor ||
scopeDeclaration.kind === SyntaxKind.ModuleDeclaration ||
scopeDeclaration.kind === SyntaxKind.ClassDeclaration ||
scopeDeclaration.kind === SyntaxKind.EnumDeclaration) {
// Declaration and has associated name use it
if ((<Declaration>scopeDeclaration).name) {
const name = (<Declaration>scopeDeclaration).name;
// For computed property names, the text will include the brackets
scopeName = name.kind === SyntaxKind.ComputedPropertyName
? getTextOfNode(name)
: (<Identifier>(<Declaration>scopeDeclaration).name).text;
}

recordScopeNameStart(scopeDeclaration, scopeName);
}
else {
// Block just use the name from upper level scope
recordScopeNameIndex(getSourceMapNameIndex());
}
}

function popScope() {
sourceMapNameIndices.pop();
}

function getText() {
encodeLastRecordedSourceMapSpan();

Expand Down
3 changes: 1 addition & 2 deletions src/harness/sourceMapRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ namespace Harness.SourceMapRecoder {
return { error: errorDecodeOfEncodedMapping, sourceMapSpan: decodeOfEncodedMapping };
}
// 5. Check if there is name:
decodeOfEncodedMapping.nameIndex = -1;
if (!isSourceMappingSegmentEnd()) {
prevNameIndex += base64VLQFormatDecode();
decodeOfEncodedMapping.nameIndex = prevNameIndex;
Expand Down Expand Up @@ -249,7 +248,7 @@ namespace Harness.SourceMapRecoder {
mapString += " name (" + sourceMapNames[mapEntry.nameIndex] + ")";
}
else {
if (mapEntry.nameIndex !== -1 || getAbsentNameIndex) {
if ((mapEntry.nameIndex && mapEntry.nameIndex !== -1) || getAbsentNameIndex) {
mapString += " nameIndex (" + mapEntry.nameIndex + ")";
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ES5For-of8.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions tests/baselines/reference/ES5For-of8.sourcemap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ sourceFile:ES5For-of8.ts
7 > 0
8 > }
9 > ;
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) name (foo)
2 >Emitted(2, 11) Source(2, 11) + SourceIndex(0) name (foo)
3 >Emitted(2, 12) Source(2, 12) + SourceIndex(0) name (foo)
4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) name (foo)
5 >Emitted(2, 15) Source(2, 15) + SourceIndex(0) name (foo)
6 >Emitted(2, 17) Source(2, 17) + SourceIndex(0) name (foo)
7 >Emitted(2, 18) Source(2, 18) + SourceIndex(0) name (foo)
8 >Emitted(2, 20) Source(2, 20) + SourceIndex(0) name (foo)
9 >Emitted(2, 21) Source(2, 21) + SourceIndex(0) name (foo)
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0)
2 >Emitted(2, 11) Source(2, 11) + SourceIndex(0)
3 >Emitted(2, 12) Source(2, 12) + SourceIndex(0)
4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0)
5 >Emitted(2, 15) Source(2, 15) + SourceIndex(0)
6 >Emitted(2, 17) Source(2, 17) + SourceIndex(0)
7 >Emitted(2, 18) Source(2, 18) + SourceIndex(0)
8 >Emitted(2, 20) Source(2, 20) + SourceIndex(0)
9 >Emitted(2, 21) Source(2, 21) + SourceIndex(0)
---
>>>}
1 >
Expand All @@ -51,8 +51,8 @@ sourceFile:ES5For-of8.ts
1 >
>
2 >}
1 >Emitted(3, 1) Source(3, 1) + SourceIndex(0) name (foo)
2 >Emitted(3, 2) Source(3, 2) + SourceIndex(0) name (foo)
1 >Emitted(3, 1) Source(3, 1) + SourceIndex(0)
2 >Emitted(3, 2) Source(3, 2) + SourceIndex(0)
---
>>>for (var _i = 0, _a = ['a', 'b', 'c']; _i < _a.length; _i++) {
1->
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading