Fix #5128: parens around default param (#5167)

* compile params at LEVEL_PAREN

* test
This commit is contained in:
Julian Rosse 2019-03-14 21:14:35 -04:00 committed by Geoffrey Booth
parent 63ffe0aead
commit ca275c2a1c
3 changed files with 7 additions and 3 deletions

View File

@ -282,7 +282,7 @@
// Occasionally it may be useful to make an expression behave as if it was 'hoisted', whereby the
// result of the expression is available before its location in the source, but the expression's
// variable scope corresponds the source position. This is used extensively to deal with executable
// variable scope corresponds to the source position. This is used extensively to deal with executable
// class bodies in classes.
// Calling this method mutates the node, proxying the `compileNode` and `compileToFragments`
@ -4058,7 +4058,7 @@
// (e.g. `ref`), shift those into the parent scope since we cant put a
// `var` line inside a function parameter list.
scopeVariablesCount = o.scope.variables.length;
signature.push(...param.compileToFragments(o));
signature.push(...param.compileToFragments(o, LEVEL_PAREN));
if (scopeVariablesCount !== o.scope.variables.length) {
generatedVariables = o.scope.variables.splice(scopeVariablesCount);
o.scope.parent.variables.push(...generatedVariables);

View File

@ -2744,7 +2744,7 @@ exports.Code = class Code extends Base
# (e.g. `ref`), shift those into the parent scope since we cant put a
# `var` line inside a function parameter list.
scopeVariablesCount = o.scope.variables.length
signature.push param.compileToFragments(o)...
signature.push param.compileToFragments(o, LEVEL_PAREN)...
if scopeVariablesCount isnt o.scope.variables.length
generatedVariables = o.scope.variables.splice scopeVariablesCount
o.scope.parent.variables.push generatedVariables...

View File

@ -493,3 +493,7 @@ test "#4657: destructured array parameters", ->
result = f [1, 2, 3, 4]
arrayEq result.a, [1, 2, 3]
eq result.b, 4
test "#5128: default parameters of function in binary operation", ->
foo = yes or (a, b = {}) -> null
eq foo, yes