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

ECMA 6 - Test Destructuring Assigment #126

Open
emravera opened this issue Apr 16, 2018 · 0 comments
Open

ECMA 6 - Test Destructuring Assigment #126

emravera opened this issue Apr 16, 2018 · 0 comments

Comments

@emravera
Copy link
Collaborator

emravera commented Apr 16, 2018

Generate test suite for:

// Array matching
var list = [ 1, 2, 3 ]
var [ a, , b ] = list
[ b, a ] = [ a, b ]

// Object matching
var { op, lhs, rhs } = getASTNode()

// Deep matching for objects
var { op: a, lhs: { op: b }, rhs: c } = getASTNode()

// Object and Array matching + Default values
var obj = { a: 1 }
var list = [ 1 ]
var { a, b = 2 } = obj
var [ x, y = 2 ] = list

// Parameter context matching
function f ([ name, val ]) {
    console.log(name, val)
}
function g ({ name: n, val: v }) {
    console.log(n, v)
}
function h ({ name, val }) {
    console.log(name, val)
}
f([ "bar", 42 ])
g({ name: "foo", val:  7 })
h({ name: "bar", val: 42 })

// Fail soft destructuring -> Do not throw error just undefined
var list = [ 7, 42 ]
var [ a = 1, b = 2, c = 3, d ] = list
a === 7
b === 42
c === 3
d === undefined

More info at:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant