Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript: destructuring binding #3435

Merged
merged 7 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
Empty file.
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() {}];
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};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields=+S
80 changes: 80 additions & 0 deletions Units/parser-javascript.r/js-destructural-binding.d/expected.tags
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 Units/parser-javascript.r/js-destructural-binding.d/input-0.js
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
}
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})
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})
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 Units/parser-javascript.r/js-destructural-binding.d/input.js
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;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node
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
Loading
Loading