Merge pull request #189 from FnControlOption/destructuring-to-new-variable-with-default-value

Fix destructuring assignment to new variable with default value
pull/70/head
Martin Jambon 2021-08-13 14:29:43 +07:00 committed by GitHub
commit bc2eb3994f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26412 additions and 26583 deletions

@ -1119,7 +1119,7 @@ module.exports = grammar({
pair_pattern: $ => seq(
field('key', $._property_name),
':',
field('value', $.pattern)
field('value', choice($.pattern, $.assignment_pattern))
),
_property_name: $ => choice(

13
src/grammar.json vendored

@ -6189,8 +6189,17 @@
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "pattern"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "pattern"
},
{
"type": "SYMBOL",
"name": "assignment_pattern"
}
]
}
}
]

@ -2193,6 +2193,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "assignment_pattern",
"named": true
},
{
"type": "pattern",
"named": true

52963
src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -77,12 +77,25 @@ Array destructuring assignments
Object destructuring patterns w/ default values
================================================
let {a: b = c} = object;
for await (var {a: {b} = object} of asyncIter) {}
function a({b = true}, [c, d = false]) {}
function b({c} = {}) {}
---
(program
(lexical_declaration (variable_declarator
(object_pattern (pair_pattern
(property_identifier)
(assignment_pattern (identifier) (identifier))))
(identifier)))
(for_in_statement
(object_pattern (pair_pattern
(property_identifier)
(assignment_pattern (object_pattern (shorthand_property_identifier_pattern)) (identifier))))
(identifier)
(statement_block))
(function_declaration (identifier)
(formal_parameters
(object_pattern (object_assignment_pattern (shorthand_property_identifier_pattern) (true)))