mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Fix #3926: Disallow implicit objects as parameter destructuring
This commit is contained in:
parent
c0c13c1977
commit
2c4d437e98
7 changed files with 42 additions and 10 deletions
|
@ -105,9 +105,13 @@
|
|||
o('ObjAssignable', function() {
|
||||
return new Value($1);
|
||||
}), o('ObjAssignable : Expression', function() {
|
||||
return new Assign(LOC(1)(new Value($1)), $3, 'object');
|
||||
return new Assign(LOC(1)(new Value($1)), $3, 'object', {
|
||||
operatorToken: LOC(2)(new Literal($2))
|
||||
});
|
||||
}), o('ObjAssignable : INDENT Expression OUTDENT', function() {
|
||||
return new Assign(LOC(1)(new Value($1)), $4, 'object');
|
||||
return new Assign(LOC(1)(new Value($1)), $4, 'object', {
|
||||
operatorToken: LOC(2)(new Literal($2))
|
||||
});
|
||||
}), o('SimpleObjAssignable = Expression', function() {
|
||||
return new Assign(LOC(1)(new Value($1)), $3, null, {
|
||||
operatorToken: LOC(2)(new Literal($2))
|
||||
|
|
|
@ -2090,13 +2090,17 @@
|
|||
extend1(Param, superClass1);
|
||||
|
||||
function Param(name1, value1, splat) {
|
||||
var name, ref3;
|
||||
var name, ref3, token;
|
||||
this.name = name1;
|
||||
this.value = value1;
|
||||
this.splat = splat;
|
||||
if (ref3 = (name = this.name.unwrapAll().value), indexOf.call(STRICT_PROSCRIBED, ref3) >= 0) {
|
||||
this.name.error("parameter name \"" + name + "\" is not allowed");
|
||||
}
|
||||
if (this.name instanceof Obj && this.name.generated) {
|
||||
token = this.name.objects[0].operatorToken;
|
||||
token.error("unexpected " + token.value);
|
||||
}
|
||||
}
|
||||
|
||||
Param.prototype.children = ['name', 'value'];
|
||||
|
|
|
@ -135,10 +135,14 @@ case 42: case 75: case 80: case 81: case 83: case 84: case 85: case 171: case 17
|
|||
this.$ = yy.addLocationDataFn(_$[$0], _$[$0])(new yy.Value($$[$0]));
|
||||
break;
|
||||
case 43:
|
||||
this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Assign(yy.addLocationDataFn(_$[$0-2])(new yy.Value($$[$0-2])), $$[$0], 'object'));
|
||||
this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Assign(yy.addLocationDataFn(_$[$0-2])(new yy.Value($$[$0-2])), $$[$0], 'object', {
|
||||
operatorToken: yy.addLocationDataFn(_$[$0-1])(new yy.Literal($$[$0-1]))
|
||||
}));
|
||||
break;
|
||||
case 44:
|
||||
this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Assign(yy.addLocationDataFn(_$[$0-4])(new yy.Value($$[$0-4])), $$[$0-1], 'object'));
|
||||
this.$ = yy.addLocationDataFn(_$[$0-4], _$[$0])(new yy.Assign(yy.addLocationDataFn(_$[$0-4])(new yy.Value($$[$0-4])), $$[$0-1], 'object', {
|
||||
operatorToken: yy.addLocationDataFn(_$[$0-3])(new yy.Literal($$[$0-3]))
|
||||
}));
|
||||
break;
|
||||
case 45:
|
||||
this.$ = yy.addLocationDataFn(_$[$0-2], _$[$0])(new yy.Assign(yy.addLocationDataFn(_$[$0-2])(new yy.Value($$[$0-2])), $$[$0], null, {
|
||||
|
|
|
@ -168,9 +168,11 @@ grammar =
|
|||
# the ordinary **Assign** is that these allow numbers and strings as keys.
|
||||
AssignObj: [
|
||||
o 'ObjAssignable', -> new Value $1
|
||||
o 'ObjAssignable : Expression', -> new Assign LOC(1)(new Value $1), $3, 'object'
|
||||
o 'ObjAssignable : Expression', -> new Assign LOC(1)(new Value $1), $3, 'object',
|
||||
operatorToken: LOC(2)(new Literal $2)
|
||||
o 'ObjAssignable :
|
||||
INDENT Expression OUTDENT', -> new Assign LOC(1)(new Value $1), $4, 'object'
|
||||
INDENT Expression OUTDENT', -> new Assign LOC(1)(new Value $1), $4, 'object',
|
||||
operatorToken: LOC(2)(new Literal $2)
|
||||
o 'SimpleObjAssignable = Expression', -> new Assign LOC(1)(new Value $1), $3, null,
|
||||
operatorToken: LOC(2)(new Literal $2)
|
||||
o 'SimpleObjAssignable =
|
||||
|
|
|
@ -1482,6 +1482,9 @@ exports.Param = class Param extends Base
|
|||
constructor: (@name, @value, @splat) ->
|
||||
if (name = @name.unwrapAll().value) in STRICT_PROSCRIBED
|
||||
@name.error "parameter name \"#{name}\" is not allowed"
|
||||
if @name instanceof Obj and @name.generated
|
||||
token = @name.objects[0].operatorToken
|
||||
token.error "unexpected #{token.value}"
|
||||
|
||||
children: ['name', 'value']
|
||||
|
||||
|
|
|
@ -808,3 +808,19 @@ test "#4070: lone expansion", ->
|
|||
[ ..., ] = a
|
||||
^^^
|
||||
'''
|
||||
|
||||
test "#3926: implicit object in parameter list", ->
|
||||
assertErrorFormat '''
|
||||
(a: b) ->
|
||||
''', '''
|
||||
[stdin]:1:3: error: unexpected :
|
||||
(a: b) ->
|
||||
^
|
||||
'''
|
||||
assertErrorFormat '''
|
||||
(one, two, {three, four: five}, key: value) ->
|
||||
''', '''
|
||||
[stdin]:1:36: error: unexpected :
|
||||
(one, two, {three, four: five}, key: value) ->
|
||||
^
|
||||
'''
|
||||
|
|
|
@ -93,7 +93,6 @@ test "duplicate formal parameters are prohibited", ->
|
|||
strict '(_,[_,{__}])->', 'param, [param, {param2}]'
|
||||
strict '(_,[__,{_}])->', 'param, [param2, {param}]'
|
||||
strict '(__,[_,{_}])->', 'param, [param2, {param2}]'
|
||||
strict '(0:a,1:a)->', '0:param,1:param'
|
||||
strict '({0:a,1:a})->', '{0:param,1:param}'
|
||||
# the following function expressions should **not** throw errors
|
||||
strictOk '(_,@_)->'
|
||||
|
@ -115,8 +114,8 @@ test "duplicate formal parameters are prohibited", ->
|
|||
strictOk '(@case...,_case)->'
|
||||
strictOk '(_case,@case)->'
|
||||
strictOk '(_case,@case...)->'
|
||||
strictOk '(a:a)->'
|
||||
strictOk '(a:a,a:b)->'
|
||||
strictOk '({a:a})->'
|
||||
strictOk '({a:a,a:b})->'
|
||||
|
||||
test "`delete` operand restrictions", ->
|
||||
strict 'a = 1; delete a'
|
||||
|
|
Loading…
Reference in a new issue