Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 595012b

Browse files
marcogallo566jasonLaster
authored andcommitted
[Preview] destructured variables (#5853)
1 parent 55207d2 commit 595012b

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/workers/parser/getSymbols.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,29 @@ function extractSymbol(path: SimplePath, symbols) {
256256
}
257257

258258
if (t.isVariableDeclarator(path)) {
259-
const node = path.node.id;
260-
const { start, end } = path.node.loc;
261-
if (t.isArrayPattern(node)) {
259+
const nodeId = path.node.id;
260+
261+
if (t.isArrayPattern(nodeId)) {
262262
return;
263263
}
264264

265-
symbols.identifiers.push({
266-
name: node.name,
267-
expression: node.name,
268-
location: { start, end }
265+
const properties =
266+
nodeId.properties && t.objectPattern(nodeId.properties)
267+
? nodeId.properties
268+
: [
269+
{
270+
value: { name: nodeId.name },
271+
loc: path.node.loc
272+
}
273+
];
274+
275+
properties.forEach(function(property) {
276+
const { start, end } = property.loc;
277+
symbols.identifiers.push({
278+
name: property.value.name,
279+
expression: property.value.name,
280+
location: { start, end }
281+
});
269282
});
270283
}
271284
}

src/workers/parser/tests/__snapshots__/getSymbols.spec.js.snap

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,16 @@ comments:
483483
484484
485485
identifiers:
486-
[(1, 6), (1, 35)]
486+
[(1, 8), (1, 9)] b b
487+
[(1, 11), (1, 16)] resty resty
487488
[(1, 8), (1, 9)] b b
488489
[(1, 8), (1, 9)] b b
489490
[(1, 11), (1, 16)] resty resty
490491
[(1, 11), (1, 16)] resty resty
491492
[(1, 21), (1, 28)] compute compute
492493
[(1, 29), (1, 34)] stuff stuff
493-
[(2, 6), (2, 33)]
494+
[(2, 8), (2, 16)] f f
495+
[(2, 18), (2, 25)] l l
494496
[(2, 8), (2, 13)] f first
495497
[(2, 15), (2, 16)] f f
496498
[(2, 18), (2, 22)] l last
@@ -509,20 +511,21 @@ identifiers:
509511
[(8, 10), (8, 13)] log log
510512
[(8, 14), (8, 19)] index index
511513
[(8, 21), (8, 28)] element element
512-
[(11, 6), (11, 42)]
514+
[(11, 8), (11, 18)]
515+
[(11, 20), (11, 29)]
513516
[(11, 8), (11, 9)] aa = 10 a
514517
[(11, 11), (11, 13)] aa aa
515518
[(11, 20), (11, 21)] bb = 5 b
516519
[(11, 23), (11, 25)] bb bb
517520
[(11, 36), (11, 37)] 3 a
518-
[(12, 6), (12, 38)]
521+
[(12, 8), (12, 30)]
519522
[(12, 8), (12, 12)] [{
520523
foo: foooo
521524
}] temp
522525
[(12, 17), (12, 20)] foooo foo
523526
[(12, 22), (12, 27)] foooo foooo
524527
[(12, 35), (12, 38)] obj obj
525-
[(14, 4), (14, 33)]
528+
[(14, 6), (14, 16)] foo foo
526529
[(14, 7), (14, 10)] foo key
527530
[(14, 13), (14, 16)] foo foo
528531
[(14, 23), (14, 24)] \\"bar\\" z
@@ -1108,7 +1111,7 @@ identifiers:
11081111
[(16, 4), (16, 22)] foo foo
11091112
[(16, 4), (16, 7)] foo foo
11101113
[(17, 5), (17, 8)] foo foo
1111-
[(18, 4), (18, 29)]
1114+
[(18, 5), (18, 23)]
11121115
[(18, 5), (18, 8)] foo = function () {} foo
11131116
[(18, 5), (18, 8)] foo foo
11141117
[(20, 1), (20, 4)] foo foo

0 commit comments

Comments
 (0)