mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 10:29:01 -06:00
Make nested object literal destructuring pattern better
This commit is contained in:
parent
b497cbc635
commit
8af2160922
@ -1979,16 +1979,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
|
||||
function createPropertyAccessExpression(expression: Expression, name: Identifier): PropertyAccessExpression {
|
||||
const result = <PropertyAccessExpression>createSynthesizedNode(SyntaxKind.PropertyAccessExpression);
|
||||
const result = <PropertyAccessExpression>createSourceMappedSynthesizedNode(SyntaxKind.PropertyAccessExpression, name);
|
||||
result.expression = parenthesizeForAccess(expression);
|
||||
result.dotToken = createSynthesizedNode(SyntaxKind.DotToken);
|
||||
result.name = name;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function createElementAccessExpression(expression: Expression, argumentExpression: Expression): ElementAccessExpression {
|
||||
const result = <ElementAccessExpression>createSynthesizedNode(SyntaxKind.ElementAccessExpression);
|
||||
const result = <ElementAccessExpression>createSourceMappedSynthesizedNode(SyntaxKind.ElementAccessExpression, argumentExpression);
|
||||
result.expression = parenthesizeForAccess(expression);
|
||||
result.argumentExpression = argumentExpression;
|
||||
|
||||
@ -2016,7 +2015,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
return <LeftHandSideExpression>expr;
|
||||
}
|
||||
const node = <ParenthesizedExpression>createSynthesizedNode(SyntaxKind.ParenthesizedExpression);
|
||||
const node = <ParenthesizedExpression>createSourceMappedSynthesizedNode(SyntaxKind.ParenthesizedExpression, expr);
|
||||
node.expression = expr;
|
||||
return node;
|
||||
}
|
||||
@ -3862,7 +3861,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
else {
|
||||
// We create a synthetic copy of the identifier in order to avoid the rewriting that might
|
||||
// otherwise occur when the identifier is emitted.
|
||||
index = <Identifier | LiteralExpression>createSynthesizedNode(propName.kind);
|
||||
index = <Identifier | LiteralExpression>createSourceMappedSynthesizedNode(propName.kind, propName);
|
||||
(<Identifier | LiteralExpression>index).text = (<Identifier | LiteralExpression>propName).text;
|
||||
}
|
||||
|
||||
|
||||
@ -232,12 +232,21 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getSourceMapRange(range: TextRange) {
|
||||
while ((range as SynthesizedNode).sourceMapNode) {
|
||||
range = (range as SynthesizedNode).sourceMapNode;
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
||||
function emitStart(range: TextRange) {
|
||||
range = getSourceMapRange(range);
|
||||
const rangeHasDecorators = !!(range as Node).decorators;
|
||||
emitPos(range.pos !== -1 ? skipTrivia(currentSourceFile.text, rangeHasDecorators ? (range as Node).decorators.end : range.pos) : -1);
|
||||
}
|
||||
|
||||
function emitEnd(range: TextRange, stopOverridingEnd?: boolean) {
|
||||
range = getSourceMapRange(range);
|
||||
emitPos(range.end);
|
||||
stopOverridingSpan = stopOverridingEnd;
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ namespace ts {
|
||||
leadingCommentRanges?: CommentRange[];
|
||||
trailingCommentRanges?: CommentRange[];
|
||||
startsOnNewLine: boolean;
|
||||
sourceMapNode?: Node;
|
||||
}
|
||||
|
||||
export function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration {
|
||||
@ -1626,6 +1627,12 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
export function createSourceMappedSynthesizedNode(kind: SyntaxKind, sourceMapNode: Node, startsOnNewLine?: boolean): Node {
|
||||
const synthesizedNode = <SynthesizedNode>createSynthesizedNode(kind, startsOnNewLine);
|
||||
synthesizedNode.sourceMapNode = sourceMapNode;
|
||||
return synthesizedNode;
|
||||
}
|
||||
|
||||
export function createSynthesizedNodeArray(): NodeArray<any> {
|
||||
const array = <NodeArray<any>>[];
|
||||
array.pos = -1;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
//// [sourceMapValidationDestructuringVariableStatementNestedObjectBindingPattern.js.map]
|
||||
{"version":3,"file":"sourceMapValidationDestructuringVariableStatementNestedObjectBindingPattern.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementNestedObjectBindingPattern.ts"],"names":[],"mappings":"AAUA,IAAI,MAAM,GAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC;AACxF,IAAI,MAAM,GAAU,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC;AAE9F,IAAI,oBAAY,qBAAiB,EAAE,yBAAqB,CAAc;AACtE,IAAM,mBAAW,sBAAY,qBAAiB,EAAE,yBAAqB,CAAc;AACnF,IAA4E,mFAA8E,EAApJ,eAAW,kBAAY,qBAAiB,EAAE,yBAAqB,CAAsF;AAE3J,EAAE,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,IAAI,CAAC,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
||||
{"version":3,"file":"sourceMapValidationDestructuringVariableStatementNestedObjectBindingPattern.js","sourceRoot":"","sources":["sourceMapValidationDestructuringVariableStatementNestedObjectBindingPattern.ts"],"names":[],"mappings":"AAUA,IAAI,MAAM,GAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC;AACxF,IAAI,MAAM,GAAU,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC;AAE9F,IAAM,kBAAM,EAAI,qBAAiB,EAAE,yBAAqB,CAAc;AACtE,IAAM,mBAAW,EAAE,kBAAM,EAAI,qBAAiB,EAAE,yBAAqB,CAAc;AACnF,IAA4E,mFAA8E,EAApJ,eAAW,EAAE,cAAM,EAAI,qBAAiB,EAAE,yBAAqB,CAAsF;AAE3J,EAAE,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AACD,IAAI,CAAC,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
||||
@ -159,56 +159,65 @@ sourceFile:sourceMapValidationDestructuringVariableStatementNestedObjectBindingP
|
||||
>>>var _a = robotA.skills, primaryA = _a.primary, secondaryA = _a.secondary;
|
||||
1 >
|
||||
2 >^^^^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^
|
||||
4 > ^^^^^^^^^^^^^^^^^^^^^
|
||||
5 > ^^
|
||||
6 > ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
7 > ^
|
||||
8 > ^^^^^^^^^^^^^^^^^^^^^^->
|
||||
3 > ^^^^^^^^^^^^^^^^^^
|
||||
4 > ^^
|
||||
5 > ^^^^^^^^^^^^^^^^^^^^^
|
||||
6 > ^^
|
||||
7 > ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
8 > ^
|
||||
9 > ^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1 >
|
||||
>
|
||||
>
|
||||
2 >var
|
||||
3 > { skills: {
|
||||
4 > primary: primaryA
|
||||
5 > ,
|
||||
6 > secondary: secondaryA
|
||||
7 > } } = robotA;
|
||||
2 >var {
|
||||
3 > skills
|
||||
4 > : {
|
||||
5 > primary: primaryA
|
||||
6 > ,
|
||||
7 > secondary: secondaryA
|
||||
8 > } } = robotA;
|
||||
1 >Emitted(3, 1) Source(14, 1) + SourceIndex(0)
|
||||
2 >Emitted(3, 5) Source(14, 5) + SourceIndex(0)
|
||||
3 >Emitted(3, 25) Source(14, 17) + SourceIndex(0)
|
||||
4 >Emitted(3, 46) Source(14, 34) + SourceIndex(0)
|
||||
5 >Emitted(3, 48) Source(14, 36) + SourceIndex(0)
|
||||
6 >Emitted(3, 73) Source(14, 57) + SourceIndex(0)
|
||||
7 >Emitted(3, 74) Source(14, 71) + SourceIndex(0)
|
||||
2 >Emitted(3, 5) Source(14, 7) + SourceIndex(0)
|
||||
3 >Emitted(3, 23) Source(14, 13) + SourceIndex(0)
|
||||
4 >Emitted(3, 25) Source(14, 17) + SourceIndex(0)
|
||||
5 >Emitted(3, 46) Source(14, 34) + SourceIndex(0)
|
||||
6 >Emitted(3, 48) Source(14, 36) + SourceIndex(0)
|
||||
7 >Emitted(3, 73) Source(14, 57) + SourceIndex(0)
|
||||
8 >Emitted(3, 74) Source(14, 71) + SourceIndex(0)
|
||||
---
|
||||
>>>var nameB = robotB.name, _b = robotB.skills, primaryB = _b.primary, secondaryB = _b.secondary;
|
||||
1->
|
||||
2 >^^^^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^
|
||||
4 > ^^^^^^^^^^^^^^^^^^^^^^
|
||||
5 > ^^^^^^^^^^^^^^^^^^^^^
|
||||
6 > ^^
|
||||
7 > ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
8 > ^
|
||||
9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
4 > ^^
|
||||
5 > ^^^^^^^^^^^^^^^^^^
|
||||
6 > ^^
|
||||
7 > ^^^^^^^^^^^^^^^^^^^^^
|
||||
8 > ^^
|
||||
9 > ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
10> ^
|
||||
11> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1->
|
||||
>
|
||||
2 >var {
|
||||
3 > name: nameB
|
||||
4 > , skills: {
|
||||
5 > primary: primaryB
|
||||
6 > ,
|
||||
7 > secondary: secondaryB
|
||||
8 > } } = robotB;
|
||||
4 > ,
|
||||
5 > skills
|
||||
6 > : {
|
||||
7 > primary: primaryB
|
||||
8 > ,
|
||||
9 > secondary: secondaryB
|
||||
10> } } = robotB;
|
||||
1->Emitted(4, 1) Source(15, 1) + SourceIndex(0)
|
||||
2 >Emitted(4, 5) Source(15, 7) + SourceIndex(0)
|
||||
3 >Emitted(4, 24) Source(15, 18) + SourceIndex(0)
|
||||
4 >Emitted(4, 46) Source(15, 30) + SourceIndex(0)
|
||||
5 >Emitted(4, 67) Source(15, 47) + SourceIndex(0)
|
||||
6 >Emitted(4, 69) Source(15, 49) + SourceIndex(0)
|
||||
7 >Emitted(4, 94) Source(15, 70) + SourceIndex(0)
|
||||
8 >Emitted(4, 95) Source(15, 84) + SourceIndex(0)
|
||||
4 >Emitted(4, 26) Source(15, 20) + SourceIndex(0)
|
||||
5 >Emitted(4, 44) Source(15, 26) + SourceIndex(0)
|
||||
6 >Emitted(4, 46) Source(15, 30) + SourceIndex(0)
|
||||
7 >Emitted(4, 67) Source(15, 47) + SourceIndex(0)
|
||||
8 >Emitted(4, 69) Source(15, 49) + SourceIndex(0)
|
||||
9 >Emitted(4, 94) Source(15, 70) + SourceIndex(0)
|
||||
10>Emitted(4, 95) Source(15, 84) + SourceIndex(0)
|
||||
---
|
||||
>>>var _c = { name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }, nameC = _c.name, _d = _c.skills, primaryB = _d.primary, secondaryB = _d.secondary;
|
||||
1->
|
||||
@ -216,32 +225,38 @@ sourceFile:sourceMapValidationDestructuringVariableStatementNestedObjectBindingP
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
4 > ^^
|
||||
5 > ^^^^^^^^^^^^^^^
|
||||
6 > ^^^^^^^^^^^^^^^^^^
|
||||
7 > ^^^^^^^^^^^^^^^^^^^^^
|
||||
8 > ^^
|
||||
9 > ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
10> ^
|
||||
6 > ^^
|
||||
7 > ^^^^^^^^^^^^^^
|
||||
8 > ^^
|
||||
9 > ^^^^^^^^^^^^^^^^^^^^^
|
||||
10> ^^
|
||||
11> ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
12> ^
|
||||
1->
|
||||
>
|
||||
2 >var { name: nameC, skills: { primary: primaryB, secondary: secondaryB } } =
|
||||
3 > { name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }
|
||||
4 >
|
||||
5 > name: nameC
|
||||
6 > , skills: {
|
||||
7 > primary: primaryB
|
||||
8 > ,
|
||||
9 > secondary: secondaryB
|
||||
10> } } = { name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } };
|
||||
6 > ,
|
||||
7 > skills
|
||||
8 > : {
|
||||
9 > primary: primaryB
|
||||
10> ,
|
||||
11> secondary: secondaryB
|
||||
12> } } = { name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } };
|
||||
1->Emitted(5, 1) Source(16, 1) + SourceIndex(0)
|
||||
2 >Emitted(5, 5) Source(16, 77) + SourceIndex(0)
|
||||
3 >Emitted(5, 88) Source(16, 155) + SourceIndex(0)
|
||||
4 >Emitted(5, 90) Source(16, 7) + SourceIndex(0)
|
||||
5 >Emitted(5, 105) Source(16, 18) + SourceIndex(0)
|
||||
6 >Emitted(5, 123) Source(16, 30) + SourceIndex(0)
|
||||
7 >Emitted(5, 144) Source(16, 47) + SourceIndex(0)
|
||||
8 >Emitted(5, 146) Source(16, 49) + SourceIndex(0)
|
||||
9 >Emitted(5, 171) Source(16, 70) + SourceIndex(0)
|
||||
10>Emitted(5, 172) Source(16, 156) + SourceIndex(0)
|
||||
6 >Emitted(5, 107) Source(16, 20) + SourceIndex(0)
|
||||
7 >Emitted(5, 121) Source(16, 26) + SourceIndex(0)
|
||||
8 >Emitted(5, 123) Source(16, 30) + SourceIndex(0)
|
||||
9 >Emitted(5, 144) Source(16, 47) + SourceIndex(0)
|
||||
10>Emitted(5, 146) Source(16, 49) + SourceIndex(0)
|
||||
11>Emitted(5, 171) Source(16, 70) + SourceIndex(0)
|
||||
12>Emitted(5, 172) Source(16, 156) + SourceIndex(0)
|
||||
---
|
||||
>>>if (nameB == nameB) {
|
||||
1 >
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user