-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3435 from masatake/js--destructural-binding
JavaScript: destructuring binding
- Loading branch information
Showing
14 changed files
with
476 additions
and
29 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
Units/parser-javascript.r/js-destructural-binding-todo.b/args.ctags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--sort=no |
Empty file.
3 changes: 3 additions & 0 deletions
3
Units/parser-javascript.r/js-destructural-binding-todo.b/input-1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// See #3435. | ||
// f should be tagged with function kind. | ||
let [f] = [function() {}]; |
9 changes: 9 additions & 0 deletions
9
Units/parser-javascript.r/js-destructural-binding-todo.b/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// See #3435. | ||
// If an object literal is specified as a default value in object restructuring, | ||
// the parser may fail to extract the variable (or constant): | ||
var{ c = {a: 1} } = { c: undefined }; | ||
var{ d = {a: 1} } = {d: 3}; | ||
var a = 1 | ||
var [x = {a: 2}, y] = [, 4]; | ||
var [x = [a, 2], z] = [, 4]; | ||
var { 'alpha': q = {'x': 9} } = {'alpha': 3}; |
2 changes: 2 additions & 0 deletions
2
Units/parser-javascript.r/js-destructural-binding.d/args.ctags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--sort=no | ||
--fields=+S |
80 changes: 80 additions & 0 deletions
80
Units/parser-javascript.r/js-destructural-binding.d/expected.tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
x input.js /^const [x] = [1];$/;" C | ||
y input.js /^const [y, z] = [1, 2, 3, 4, 5];$/;" C | ||
z input.js /^const [y, z] = [1, 2, 3, 4, 5];$/;" C | ||
a input.js /^let [a=5, b=7] = [1];$/;" v | ||
b input.js /^let [a=5, b=7] = [1];$/;" v | ||
c input.js /^let [c, , d] = [1, 2, 3];$/;" v | ||
d input.js /^let [c, , d] = [1, 2, 3];$/;" v | ||
e input.js /^let [e, f = 0, , g] = [1, 2, 3, 4];$/;" v | ||
f input.js /^let [e, f = 0, , g] = [1, 2, 3, 4];$/;" v | ||
g input.js /^let [e, f = 0, , g] = [1, 2, 3, 4];$/;" v | ||
h input.js /^const [h, i, ...[j, k]] = [1, 2, 3, 4];$/;" C | ||
i input.js /^const [h, i, ...[j, k]] = [1, 2, 3, 4];$/;" C | ||
j input.js /^const [h, i, ...[j, k]] = [1, 2, 3, 4];$/;" C | ||
k input.js /^const [h, i, ...[j, k]] = [1, 2, 3, 4];$/;" C | ||
l input.js /^const [l, m, ...[n, o, ...[p, q]]] = [1, 2, 3, 4, 5, 6];$/;" C | ||
m input.js /^const [l, m, ...[n, o, ...[p, q]]] = [1, 2, 3, 4, 5, 6];$/;" C | ||
n input.js /^const [l, m, ...[n, o, ...[p, q]]] = [1, 2, 3, 4, 5, 6];$/;" C | ||
o input.js /^const [l, m, ...[n, o, ...[p, q]]] = [1, 2, 3, 4, 5, 6];$/;" C | ||
p input.js /^const [l, m, ...[n, o, ...[p, q]]] = [1, 2, 3, 4, 5, 6];$/;" C | ||
q input.js /^const [l, m, ...[n, o, ...[p, q]]] = [1, 2, 3, 4, 5, 6];$/;" C | ||
A input.js /^const [A, B, ...{ C, D }] = []$/;" C | ||
B input.js /^const [A, B, ...{ C, D }] = []$/;" C | ||
C input.js /^const [A, B, ...{ C, D }] = []$/;" C | ||
D input.js /^const [A, B, ...{ C, D }] = []$/;" C | ||
E input.js /^ E: 42,$/;" p variable:user | ||
F input.js /^ F: true$/;" p variable:user | ||
user input.js /^const user = {$/;" v | ||
E input.js /^const {E, F} = user;$/;" C | ||
F input.js /^const {E, F} = user;$/;" C | ||
G input.js /^const {E: G, F: H} = user;$/;" C | ||
H input.js /^const {E: G, F: H} = user;$/;" C | ||
I input.js /^const {I = 10, J = 5} = {I: 3};$/;" C | ||
J input.js /^const {I = 10, J = 5} = {I: 3};$/;" C | ||
I input.js /^const {I = 10, J = 5} = {I: 3};$/;" p variable:anonymousObject785a93f40105 | ||
anonymousObject785a93f40105 input.js /^const {I = 10, J = 5} = {I: 3};$/;" v | ||
K input.js /^let {a: K = 10, b: L = 5} = {a: 3};$/;" v | ||
L input.js /^let {a: K = 10, b: L = 5} = {a: 3};$/;" v | ||
a input.js /^let {a: K = 10, b: L = 5} = {a: 3};$/;" p variable:anonymousObject785a93f40205 | ||
anonymousObject785a93f40205 input.js /^let {a: K = 10, b: L = 5} = {a: 3};$/;" v | ||
M input.js /^let {M, N, ...O} = {M: 10, N: 20, c: 30, d: 40}$/;" v | ||
N input.js /^let {M, N, ...O} = {M: 10, N: 20, c: 30, d: 40}$/;" v | ||
O input.js /^let {M, N, ...O} = {M: 10, N: 20, c: 30, d: 40}$/;" v | ||
M input.js /^let {M, N, ...O} = {M: 10, N: 20, c: 30, d: 40}$/;" p variable:anonymousObject785a93f40305 | ||
N input.js /^let {M, N, ...O} = {M: 10, N: 20, c: 30, d: 40}$/;" p variable:anonymousObject785a93f40305 | ||
c input.js /^let {M, N, ...O} = {M: 10, N: 20, c: 30, d: 40}$/;" p variable:anonymousObject785a93f40305 | ||
d input.js /^let {M, N, ...O} = {M: 10, N: 20, c: 30, d: 40}$/;" p variable:anonymousObject785a93f40305 | ||
anonymousObject785a93f40305 input.js /^let {M, N, ...O} = {M: 10, N: 20, c: 30, d: 40}$/;" v | ||
title input.js /^ title: 'Scratchpad',$/;" p variable:metadata | ||
anonymousObject785a93f40405 input.js /^ {$/;" v variable:metadata | ||
locale input.js /^ locale: 'de',$/;" p variable:metadata.anonymousObject785a93f40405 | ||
localization_tags input.js /^ localization_tags: [],$/;" p variable:metadata.anonymousObject785a93f40405 | ||
last_edit input.js /^ last_edit: '2014-04-14T08:43:37',$/;" p variable:metadata.anonymousObject785a93f40405 | ||
url input.js /^ url: '\/de\/docs\/Tools\/Scratchpad',$/;" p variable:metadata.anonymousObject785a93f40405 | ||
title input.js /^ title: 'JavaScript-Umgebung'$/;" p variable:metadata.anonymousObject785a93f40405 | ||
translations input.js /^ translations: [$/;" p variable:metadata | ||
url input.js /^ url: '\/en-US\/docs\/Tools\/Scratchpad'$/;" p variable:metadata | ||
metadata input.js /^const metadata = {$/;" v | ||
englishTitle input.js /^ title: englishTitle, \/\/ rename$/;" v | ||
localeTitle input.js /^ title: localeTitle, \/\/ rename$/;" v | ||
userDisplayName input-0.js /^function userDisplayName({displayName: dname}) {$/;" f signature:({displayName: dname}) | ||
whois input-0.js /^function whois({displayName, fullName: {firstName: name}}) {$/;" f signature:({displayName, fullName: {firstName: name}}) | ||
drawChart input-0.js /^function drawChart({size = 'big', coords = {x: 0, y: 0}, radius = 25} = {}) {$/;" f signature:({size = 'big', coords = {x: 0, y: 0}, radius = 25} = {}) | ||
f input-1.js /^function f({ u, x }) {$/;" f signature:({ u, x }) | ||
anonymousObjectf91cef720105 input-1.js /^f({u: 1, x: 2})$/;" v | ||
u input-1.js /^f({u: 1, x: 2})$/;" p variable:anonymousObjectf91cef720105 | ||
x input-1.js /^f({u: 1, x: 2})$/;" p variable:anonymousObjectf91cef720105 | ||
f input-2.js /^function f(x, y, z) {$/;" f signature:(x, y, z) | ||
anonymousObjectf91d7bd30105 input-2.js /^f({x, y, z})$/;" v | ||
x input-2.js /^f({x, y, z})$/;" p variable:anonymousObjectf91d7bd30105 | ||
y input-2.js /^f({x, y, z})$/;" p variable:anonymousObjectf91d7bd30105 | ||
z input-2.js /^f({x, y, z})$/;" p variable:anonymousObjectf91d7bd30105 | ||
key0 input-3.js /^let key0 = 'z';$/;" v | ||
foo input-3.js /^let {[key0]: foo} = {z: 'alpha'};$/;" v | ||
z input-3.js /^let {[key0]: foo} = {z: 'alpha'};$/;" p variable:anonymousObjectf91e08340105 | ||
anonymousObjectf91e08340105 input-3.js /^let {[key0]: foo} = {z: 'alpha'};$/;" v | ||
key1 input-3.js /^let key1 = 'x';$/;" v | ||
bar input-3.js /^let {[key0]: bar = 'X', [key1]: baz} = {x: 'beta'};$/;" v | ||
baz input-3.js /^let {[key0]: bar = 'X', [key1]: baz} = {x: 'beta'};$/;" v | ||
x input-3.js /^let {[key0]: bar = 'X', [key1]: baz} = {x: 'beta'};$/;" p variable:anonymousObjectf91e08340205 | ||
anonymousObjectf91e08340205 input-3.js /^let {[key0]: bar = 'X', [key1]: baz} = {x: 'beta'};$/;" v |
13 changes: 13 additions & 0 deletions
13
Units/parser-javascript.r/js-destructural-binding.d/input-0.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Derrived from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment | ||
function userDisplayName({displayName: dname}) { | ||
return dname; | ||
} | ||
|
||
function whois({displayName, fullName: {firstName: name}}) { | ||
return `${displayName} is ${name}`; | ||
} | ||
|
||
function drawChart({size = 'big', coords = {x: 0, y: 0}, radius = 25} = {}) { | ||
console.log(size, coords, radius); | ||
// do some chart drawing | ||
} |
5 changes: 5 additions & 0 deletions
5
Units/parser-javascript.r/js-destructural-binding.d/input-1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function f({ u, x }) { | ||
return (u + x) | ||
} | ||
|
||
f({u: 1, x: 2}) |
8 changes: 8 additions & 0 deletions
8
Units/parser-javascript.r/js-destructural-binding.d/input-2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function f(x, y, z) { | ||
return x + y + z | ||
} | ||
|
||
x = 1 | ||
y = 1 | ||
z = 1 | ||
f({x, y, z}) |
7 changes: 7 additions & 0 deletions
7
Units/parser-javascript.r/js-destructural-binding.d/input-3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment | ||
// - Computed object property names and destructuring | ||
let key0 = 'z'; | ||
let {[key0]: foo} = {z: 'alpha'}; | ||
|
||
let key1 = 'x'; | ||
let {[key0]: bar = 'X', [key1]: baz} = {x: 'beta'}; |
56 changes: 56 additions & 0 deletions
56
Units/parser-javascript.r/js-destructural-binding.d/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Derrived from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment | ||
const [x] = [1]; | ||
const [y, z] = [1, 2, 3, 4, 5]; | ||
let [a=5, b=7] = [1]; | ||
|
||
let [c, , d] = [1, 2, 3]; | ||
let [e, f = 0, , g] = [1, 2, 3, 4]; | ||
|
||
let [,,] = [1, 2, 3]; | ||
let [,] = [1, 2, 3]; | ||
let [] = [1, 2, 3]; | ||
|
||
const [h, i, ...[j, k]] = [1, 2, 3, 4]; | ||
const [l, m, ...[n, o, ...[p, q]]] = [1, 2, 3, 4, 5, 6]; | ||
|
||
const [A, B, ...{ C, D }] = [] | ||
|
||
const user = { | ||
E: 42, | ||
F: true | ||
}; | ||
|
||
const {E, F} = user; | ||
|
||
const {E: G, F: H} = user; | ||
|
||
|
||
const {I = 10, J = 5} = {I: 3}; | ||
|
||
let {a: K = 10, b: L = 5} = {a: 3}; | ||
|
||
let {M, N, ...O} = {M: 10, N: 20, c: 30, d: 40} | ||
|
||
|
||
const metadata = { | ||
title: 'Scratchpad', | ||
translations: [ | ||
{ | ||
locale: 'de', | ||
localization_tags: [], | ||
last_edit: '2014-04-14T08:43:37', | ||
url: '/de/docs/Tools/Scratchpad', | ||
title: 'JavaScript-Umgebung' | ||
} | ||
], | ||
url: '/en-US/docs/Tools/Scratchpad' | ||
}; | ||
|
||
let { | ||
title: englishTitle, // rename | ||
translations: [ | ||
{ | ||
title: localeTitle, // rename | ||
}, | ||
], | ||
} = metadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
prop input.js /^var {prop} = { prop: "value" };$/;" v | ||
prop input.js /^var {prop} = { prop: "value" };$/;" p variable:anonymousObject4ca5b60a0105 | ||
anonymousObject4ca5b60a0105 input.js /^var {prop} = { prop: "value" };$/;" v |
Oops, something went wrong.