From 68aa646f0f895a93ec23ebe2edf19a4f7957c527 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 11 May 2016 19:25:31 -0700 Subject: [PATCH] Additional source map fixes for initializers and arrow functions. --- src/compiler/printer.ts | 8 +-- src/compiler/transformers/es6.ts | 49 +++++++-------- src/compiler/transformers/module/module.ts | 23 ++++---- tests/baselines/reference/ES5For-of26.js.map | 2 +- .../reference/ES5For-of26.sourcemap.txt | 59 ++++++++++--------- ...ConstructorAndCapturedThisStatement.js.map | 2 +- ...ctorAndCapturedThisStatement.sourcemap.txt | 13 ++-- .../sourceMapValidationFunctions.js.map | 2 +- ...sourceMapValidationFunctions.sourcemap.txt | 20 +++---- 9 files changed, 93 insertions(+), 85 deletions(-) diff --git a/src/compiler/printer.ts b/src/compiler/printer.ts index 5425d6e72cf..5f574e7cfb0 100644 --- a/src/compiler/printer.ts +++ b/src/compiler/printer.ts @@ -1345,15 +1345,15 @@ const _super = (function (geti, seti) { } function emitIfStatement(node: IfStatement) { - const openParenPos = writeToken(SyntaxKind.IfKeyword, node.pos); + const openParenPos = writeToken(SyntaxKind.IfKeyword, node.pos, node); write(" "); - writeToken(SyntaxKind.OpenParenToken, openParenPos); + writeToken(SyntaxKind.OpenParenToken, openParenPos, node); emitExpression(node.expression); - writeToken(SyntaxKind.CloseParenToken, node.expression.end); + writeToken(SyntaxKind.CloseParenToken, node.expression.end, node); emitEmbeddedStatement(node.thenStatement); if (node.elseStatement) { writeLine(); - writeToken(SyntaxKind.ElseKeyword, node.thenStatement.end); + writeToken(SyntaxKind.ElseKeyword, node.thenStatement.end, node); if (node.elseStatement.kind === SyntaxKind.IfStatement) { write(" "); emit(node.elseStatement); diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 55f74094076..4c4e65e7910 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -949,28 +949,30 @@ namespace ts { * @param initializer The initializer for the parameter. */ function addDefaultValueAssignmentForInitializer(statements: Statement[], parameter: ParameterDeclaration, name: Identifier, initializer: Expression): void { - statements.push( - createIf( - createStrictEquality( - getSynthesizedClone(name), - createVoidZero() - ), - setNodeEmitFlags( - createBlock([ - createStatement( - createAssignment( - getSynthesizedClone(name), - visitNode(initializer, visitor, isExpression) - ) + const statement = createIf( + createStrictEquality( + getSynthesizedClone(name), + createVoidZero() + ), + setNodeEmitFlags( + createBlock([ + createStatement( + createAssignment( + setNodeEmitFlags(getMutableClone(name), NodeEmitFlags.NoSourceMap), + setNodeEmitFlags(visitNode(initializer, visitor, isExpression), NodeEmitFlags.NoSourceMap), + /*location*/ parameter ) - ]), - NodeEmitFlags.SingleLine - ), - /*elseStatement*/ undefined, - /*location*/ undefined, - { startOnNewLine: true } - ) + ) + ], /*location*/ parameter), + NodeEmitFlags.SingleLine | NodeEmitFlags.NoTrailingSourceMap | NodeEmitFlags.NoTokenSourceMaps + ), + /*elseStatement*/ undefined, + /*location*/ parameter, + { startOnNewLine: true } ); + + setNodeEmitFlags(statement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoTrailingSourceMap); + statements.push(statement); } /** @@ -1365,9 +1367,8 @@ namespace ts { } const expression = visitNode(body, visitor, isExpression); - const returnStatement = createReturn(expression); - setSourceMapRange(returnStatement, body); - setNodeEmitFlags(returnStatement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoTrailingSourceMap); + const returnStatement = createReturn(expression, /*location*/ body); + setNodeEmitFlags(returnStatement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoTrailingSourceMap | NodeEmitFlags.NoTrailingComments); statements.push(returnStatement); // To align with the source map emit for the old emitter, we set a custom @@ -2364,7 +2365,7 @@ namespace ts { // Methods on classes are handled in visitClassDeclaration/visitClassExpression. // Methods with computed property names are handled in visitObjectLiteralExpression. Debug.assert(!isComputedPropertyName(node.name)); - const functionExpression = transformFunctionLikeToExpression(node, /*location*/ node, /*name*/ undefined); + const functionExpression = transformFunctionLikeToExpression(node, /*location*/ moveRangePos(node, -1), /*name*/ undefined); setNodeEmitFlags(functionExpression, NodeEmitFlags.NoLeadingComments | getNodeEmitFlags(functionExpression)); return createPropertyAssignment( node.name, diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 3e2edfb1426..cd84a68ea49 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -219,22 +219,23 @@ namespace ts { /*location*/ exportEquals ); - setNodeEmitFlags(statement, NodeEmitFlags.NoTokenSourceMaps); + setNodeEmitFlags(statement, NodeEmitFlags.NoTokenSourceMaps | NodeEmitFlags.NoComments); statements.push(statement); } else { - statements.push( - createStatement( - createAssignment( - createPropertyAccess( - createIdentifier("module"), - "exports" - ), - exportEquals.expression + const statement = createStatement( + createAssignment( + createPropertyAccess( + createIdentifier("module"), + "exports" ), - /*location*/ exportEquals - ) + exportEquals.expression + ), + /*location*/ exportEquals ); + + setNodeEmitFlags(statement, NodeEmitFlags.NoComments); + statements.push(statement); } } } diff --git a/tests/baselines/reference/ES5For-of26.js.map b/tests/baselines/reference/ES5For-of26.js.map index 0e8145e4a35..0afbe7ec42e 100644 --- a/tests/baselines/reference/ES5For-of26.js.map +++ b/tests/baselines/reference/ES5For-of26.js.map @@ -1,2 +1,2 @@ //// [ES5For-of26.js.map] -{"version":3,"file":"ES5For-of26.js","sourceRoot":"","sources":["ES5For-of26.ts"],"names":[],"mappings":"AAAA,GAAG,CAAC,CAAuB,UAAM,EAAN,MAAC,CAAC,EAAE,CAAC,CAAC,EAAN,cAAM,EAAN,IAAM;IAA5B,eAAkB,EAAb,UAAK,EAAL,0BAAK,EAAE,UAAK,EAAL,0BAAK;IAClB,CAAC,CAAC;IACF,CAAC,CAAC;CACL"} \ No newline at end of file +{"version":3,"file":"ES5For-of26.js","sourceRoot":"","sources":["ES5For-of26.ts"],"names":[],"mappings":"AAAA,GAAG,CAAC,CAAuB,UAAM,EAAN,MAAC,CAAC,EAAE,CAAC,CAAC,EAAN,cAAM,EAAN,IAAM;IAAxB,IAAA,WAAc,EAAb,UAAK,EAAL,0BAAK,EAAE,UAAK,EAAL,0BAAK;IAClB,CAAC,CAAC;IACF,CAAC,CAAC;CACL"} \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of26.sourcemap.txt b/tests/baselines/reference/ES5For-of26.sourcemap.txt index 50966d5a9df..ce13a75e5cf 100644 --- a/tests/baselines/reference/ES5For-of26.sourcemap.txt +++ b/tests/baselines/reference/ES5For-of26.sourcemap.txt @@ -58,35 +58,38 @@ sourceFile:ES5For-of26.ts --- >>> var _b = _a[_i], _c = _b[0], a = _c === void 0 ? 0 : _c, _d = _b[1], b = _d === void 0 ? 1 : _d; 1->^^^^ -2 > ^^^^^^^^^^^^^^^ -3 > ^^ -4 > ^^^^^^^^^^ -5 > ^^ -6 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ -7 > ^^ -8 > ^^^^^^^^^^ -9 > ^^ -10> ^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 > ^^^^ +3 > ^^^^^^^^^^^ +4 > ^^ +5 > ^^^^^^^^^^ +6 > ^^ +7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ +8 > ^^ +9 > ^^^^^^^^^^ +10> ^^ +11> ^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> -2 > var [a = 0, b = 1] -3 > -4 > a = 0 -5 > -6 > a = 0 -7 > , -8 > b = 1 -9 > -10> b = 1 -1->Emitted(2, 5) Source(1, 6) + SourceIndex(0) -2 >Emitted(2, 20) Source(1, 24) + SourceIndex(0) -3 >Emitted(2, 22) Source(1, 11) + SourceIndex(0) -4 >Emitted(2, 32) Source(1, 16) + SourceIndex(0) -5 >Emitted(2, 34) Source(1, 11) + SourceIndex(0) -6 >Emitted(2, 60) Source(1, 16) + SourceIndex(0) -7 >Emitted(2, 62) Source(1, 18) + SourceIndex(0) -8 >Emitted(2, 72) Source(1, 23) + SourceIndex(0) -9 >Emitted(2, 74) Source(1, 18) + SourceIndex(0) -10>Emitted(2, 100) Source(1, 23) + SourceIndex(0) +2 > +3 > [a = 0, b = 1] +4 > +5 > a = 0 +6 > +7 > a = 0 +8 > , +9 > b = 1 +10> +11> b = 1 +1->Emitted(2, 5) Source(1, 10) + SourceIndex(0) +2 >Emitted(2, 9) Source(1, 10) + SourceIndex(0) +3 >Emitted(2, 20) Source(1, 24) + SourceIndex(0) +4 >Emitted(2, 22) Source(1, 11) + SourceIndex(0) +5 >Emitted(2, 32) Source(1, 16) + SourceIndex(0) +6 >Emitted(2, 34) Source(1, 11) + SourceIndex(0) +7 >Emitted(2, 60) Source(1, 16) + SourceIndex(0) +8 >Emitted(2, 62) Source(1, 18) + SourceIndex(0) +9 >Emitted(2, 72) Source(1, 23) + SourceIndex(0) +10>Emitted(2, 74) Source(1, 18) + SourceIndex(0) +11>Emitted(2, 100) Source(1, 23) + SourceIndex(0) --- >>> a; 1 >^^^^ diff --git a/tests/baselines/reference/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.js.map b/tests/baselines/reference/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.js.map index 3f0d6bda29e..00bdfcdba60 100644 --- a/tests/baselines/reference/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.js.map +++ b/tests/baselines/reference/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.js.map] -{"version":3,"file":"sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.js","sourceRoot":"","sources":["sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.ts"],"names":[],"mappings":"AAAA;IAAA;QAAA,iBAGC;QAFU,MAAC,GAAG,EAAE,CAAC;QACP,YAAO,GAAG,cAAM,OAAA,KAAI,CAAC,CAAC,GAAA,CAAC;IAClC,CAAC;IAAD,cAAC;AAAD,CAAC,AAHD,IAGC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.js","sourceRoot":"","sources":["sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.ts"],"names":[],"mappings":"AAAA;IAAA;QAAA,iBAGC;QAFU,MAAC,GAAG,EAAE,CAAC;QACP,YAAO,GAAG,cAAM,OAAA,KAAI,CAAC,CAAC,EAAN,CAAM,CAAC;IAClC,CAAC;IAAD,cAAC;AAAD,CAAC,AAHD,IAGC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.sourcemap.txt b/tests/baselines/reference/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.sourcemap.txt index 5b4d7442130..d5cb74636e7 100644 --- a/tests/baselines/reference/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatement.sourcemap.txt @@ -58,8 +58,9 @@ sourceFile:sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatemen 6 > ^^^^^ 7 > ^ 8 > ^ -9 > ^^^ -10> ^ +9 > ^^ +10> ^ +11> ^ 1-> > public 2 > returnA @@ -70,7 +71,8 @@ sourceFile:sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatemen 7 > . 8 > a 9 > -10> ; +10> this.a +11> ; 1->Emitted(5, 9) Source(3, 12) + SourceIndex(0) 2 >Emitted(5, 21) Source(3, 19) + SourceIndex(0) 3 >Emitted(5, 24) Source(3, 22) + SourceIndex(0) @@ -79,8 +81,9 @@ sourceFile:sourceMapValidationClassWithDefaultConstructorAndCapturedThisStatemen 6 >Emitted(5, 50) Source(3, 32) + SourceIndex(0) 7 >Emitted(5, 51) Source(3, 33) + SourceIndex(0) 8 >Emitted(5, 52) Source(3, 34) + SourceIndex(0) -9 >Emitted(5, 55) Source(3, 34) + SourceIndex(0) -10>Emitted(5, 56) Source(3, 35) + SourceIndex(0) +9 >Emitted(5, 54) Source(3, 28) + SourceIndex(0) +10>Emitted(5, 55) Source(3, 34) + SourceIndex(0) +11>Emitted(5, 56) Source(3, 35) + SourceIndex(0) --- >>> } 1 >^^^^ diff --git a/tests/baselines/reference/sourceMapValidationFunctions.js.map b/tests/baselines/reference/sourceMapValidationFunctions.js.map index 7578efc11f8..2aaa87c4fe7 100644 --- a/tests/baselines/reference/sourceMapValidationFunctions.js.map +++ b/tests/baselines/reference/sourceMapValidationFunctions.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationFunctions.js.map] -{"version":3,"file":"sourceMapValidationFunctions.js","sourceRoot":"","sources":["sourceMapValidationFunctions.ts"],"names":[],"mappings":"AAAA,IAAI,SAAS,GAAG,CAAC,CAAC;AAClB,eAAe,QAAgB;IAC3B,SAAS,EAAE,CAAC;IACZ,MAAM,CAAC,SAAS,CAAC;AACrB,CAAC;AACD,gBAAgB,QAAgB,EAAE,CAAM,EAAE,CAAU;IAAlB,iBAAM,GAAN,MAAM;IAAc,oBAAuB;SAAvB,WAAuB,CAAvB,sBAAuB,CAAvB,IAAuB;QAAvB,mCAAuB;;IACzE,SAAS,EAAE,CAAC;IACZ,MAAM,CAAC,SAAS,CAAC;AACrB,CAAC;AACD,aAAa,QAAgB,EAAE,CAAM,EAAE,CAAU;IAAlB,iBAAM,GAAN,MAAM;IAAc,oBAAuB;SAAvB,WAAuB,CAAvB,sBAAuB,CAAvB,IAAuB;QAAvB,mCAAuB;;IAEtE,MAAM,CAAC;AACX,CAAC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationFunctions.js","sourceRoot":"","sources":["sourceMapValidationFunctions.ts"],"names":[],"mappings":"AAAA,IAAI,SAAS,GAAG,CAAC,CAAC;AAClB,eAAe,QAAgB;IAC3B,SAAS,EAAE,CAAC;IACZ,MAAM,CAAC,SAAS,CAAC;AACrB,CAAC;AACD,gBAAgB,QAAgB,EAAE,CAAM,EAAE,CAAU;IAAlB,kBAAA,EAAA,MAAM;IAAc,oBAAuB;SAAvB,WAAuB,CAAvB,sBAAuB,CAAvB,IAAuB;QAAvB,mCAAuB;;IACzE,SAAS,EAAE,CAAC;IACZ,MAAM,CAAC,SAAS,CAAC;AACrB,CAAC;AACD,aAAa,QAAgB,EAAE,CAAM,EAAE,CAAU;IAAlB,kBAAA,EAAA,MAAM;IAAc,oBAAuB;SAAvB,WAAuB,CAAvB,sBAAuB,CAAvB,IAAuB;QAAvB,mCAAuB;;IAEtE,MAAM,CAAC;AACX,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationFunctions.sourcemap.txt b/tests/baselines/reference/sourceMapValidationFunctions.sourcemap.txt index 95759f76f16..96fd9009739 100644 --- a/tests/baselines/reference/sourceMapValidationFunctions.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationFunctions.sourcemap.txt @@ -112,15 +112,15 @@ sourceFile:sourceMapValidationFunctions.ts --- >>> if (n === void 0) { n = 10; } 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^ -3 > ^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^^ 4 > ^^^^^^ 1-> -2 > n = 10 -3 > +2 > +3 > 4 > n = 10 1->Emitted(7, 5) Source(6, 35) + SourceIndex(0) -2 >Emitted(7, 22) Source(6, 41) + SourceIndex(0) +2 >Emitted(7, 23) Source(6, 35) + SourceIndex(0) 3 >Emitted(7, 25) Source(6, 35) + SourceIndex(0) 4 >Emitted(7, 31) Source(6, 41) + SourceIndex(0) --- @@ -233,15 +233,15 @@ sourceFile:sourceMapValidationFunctions.ts --- >>> if (n === void 0) { n = 10; } 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^ -3 > ^^^ +2 > ^^^^^^^^^^^^^^^^^^ +3 > ^^ 4 > ^^^^^^ 1-> -2 > n = 10 -3 > +2 > +3 > 4 > n = 10 1->Emitted(16, 5) Source(10, 32) + SourceIndex(0) -2 >Emitted(16, 22) Source(10, 38) + SourceIndex(0) +2 >Emitted(16, 23) Source(10, 32) + SourceIndex(0) 3 >Emitted(16, 25) Source(10, 32) + SourceIndex(0) 4 >Emitted(16, 31) Source(10, 38) + SourceIndex(0) ---