Better the sourcemap for array binding pattern

This commit is contained in:
Sheetal Nandi 2015-12-04 13:18:31 -08:00
parent 0532e8cb11
commit 7c618a494d
3 changed files with 27 additions and 7 deletions

View file

@ -4007,7 +4007,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
else {
let nodeForSourceMap: Node;
// If binding element is part of binding pattern with single element, use binding pattern
if (target.kind === SyntaxKind.BindingElement && (<BindingPattern>target.parent).elements.length === 1) {
if (target.kind === SyntaxKind.BindingElement && hasSingleBindingElement(<BindingPattern>target.parent)) {
nodeForSourceMap = (target.parent.parent.kind === SyntaxKind.VariableDeclaration || target.parent.parent.kind === SyntaxKind.Parameter) ?
target.parent.parent : // Set sourcemap as whole variable declaration
target.parent; // Only binding Pattern
@ -4018,6 +4018,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
emitAssignment(<Identifier>target.name, value, /*shouldEmitCommaBeforeAssignment*/ emitCount > 0, nodeForSourceMap);
emitCount++;
}
function hasSingleBindingElement(pattern: BindingPattern) {
if (pattern.kind === SyntaxKind.ObjectBindingPattern) {
return pattern.elements.length === 1;
}
let hasFoundEmittingElement = false;
for (const element of pattern.elements) {
if (element.kind !== SyntaxKind.OmittedExpression) {
if (hasFoundEmittingElement) {
// More than one elements are going to be emitted
return false;
}
hasFoundEmittingElement = true;
}
}
// If we found exactly one emitting element
return hasFoundEmittingElement;
}
}
}

View file

@ -1,2 +1,2 @@
//// [sourceMapValidationDestructuringVariableStatementArrayBindingPattern.js.map]
{"version":3,"file":"sourceMapValidationDestructuringVariableStatementArrayBindingPattern.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementArrayBindingPattern.ts"],"names":[],"mappings":"AAIA,IAAI,MAAM,GAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC3C,IAAI,MAAM,GAAU,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAG/C,IAAO,iBAAK,CAAW;AACvB,IAAI,mBAAkB,CAAC;AACvB,IAAK,oBAAQ,EAAE,kBAAM,EAAE,mBAAO,CAAW;AAEzC,IAAI,6CAA4C,CAAC;AACjD,IAA+B,oCAA+B,EAAzD,eAAO,EAAE,aAAK,EAAE,cAAM,CAAoC;AAE/D,IAAK,oBAAQ,EAAE,4BAAa,CAAW;AAEvC,EAAE,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC;IAClB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC"}
{"version":3,"file":"sourceMapValidationDestructuringVariableStatementArrayBindingPattern.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementArrayBindingPattern.ts"],"names":[],"mappings":"AAIA,IAAI,MAAM,GAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC3C,IAAI,MAAM,GAAU,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAG/C,IAAI,iBAAkB,CAAC;AACvB,IAAI,mBAAkB,CAAC;AACvB,IAAK,oBAAQ,EAAE,kBAAM,EAAE,mBAAO,CAAW;AAEzC,IAAI,6CAA4C,CAAC;AACjD,IAA+B,oCAA+B,EAAzD,eAAO,EAAE,aAAK,EAAE,cAAM,CAAoC;AAE/D,IAAK,oBAAQ,EAAE,4BAAa,CAAW;AAEvC,EAAE,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC;IAClB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC"}

View file

@ -100,12 +100,12 @@ sourceFile:sourceMapValidationDestructuringVariableStatementArrayBindingPattern.
>
>
>
2 >let [,
3 > nameA
4 > ] = robotA;
2 >let
3 > [, nameA] = robotA
4 > ;
1 >Emitted(3, 1) Source(9, 1) + SourceIndex(0)
2 >Emitted(3, 5) Source(9, 8) + SourceIndex(0)
3 >Emitted(3, 22) Source(9, 13) + SourceIndex(0)
2 >Emitted(3, 5) Source(9, 5) + SourceIndex(0)
3 >Emitted(3, 22) Source(9, 23) + SourceIndex(0)
4 >Emitted(3, 23) Source(9, 24) + SourceIndex(0)
---
>>>var numberB = robotB[0];