Fix #3935: Implicit calls + obj key interpolation
Allow implicit calls when the first key of an implicit object has interpolation.
This commit is contained in:
parent
4e6b6678f7
commit
ebc172d1ee
|
@ -1311,7 +1311,7 @@
|
||||||
indent += TAB;
|
indent += TAB;
|
||||||
}
|
}
|
||||||
if (prop instanceof Assign && prop.variable instanceof Value && prop.variable.hasProperties()) {
|
if (prop instanceof Assign && prop.variable instanceof Value && prop.variable.hasProperties()) {
|
||||||
prop.variable.error('Invalid object key');
|
prop.variable.error('invalid object key');
|
||||||
}
|
}
|
||||||
if (prop instanceof Value && prop["this"]) {
|
if (prop instanceof Value && prop["this"]) {
|
||||||
prop = new Assign(prop.properties[0].name, prop, 'object');
|
prop = new Assign(prop.properties[0].name, prop, 'object');
|
||||||
|
|
|
@ -284,7 +284,7 @@
|
||||||
startImplicitCall(i + 1);
|
startImplicitCall(i + 1);
|
||||||
return forward(2);
|
return forward(2);
|
||||||
}
|
}
|
||||||
if (indexOf.call(IMPLICIT_FUNC, tag) >= 0 && this.indexOfTag(i + 1, 'INDENT', null, ':') > -1 && !this.findTagsBackwards(i, ['CLASS', 'EXTENDS', 'IF', 'CATCH', 'SWITCH', 'LEADING_WHEN', 'FOR', 'WHILE', 'UNTIL'])) {
|
if (indexOf.call(IMPLICIT_FUNC, tag) >= 0 && this.indexOfTag(i + 1, 'INDENT') > -1 && this.looksObjectish(i + 2) && !this.findTagsBackwards(i, ['CLASS', 'EXTENDS', 'IF', 'CATCH', 'SWITCH', 'LEADING_WHEN', 'FOR', 'WHILE', 'UNTIL'])) {
|
||||||
startImplicitCall(i + 1);
|
startImplicitCall(i + 1);
|
||||||
stack.push(['INDENT', i + 2]);
|
stack.push(['INDENT', i + 2]);
|
||||||
return forward(3);
|
return forward(3);
|
||||||
|
|
|
@ -952,7 +952,7 @@ exports.Obj = class Obj extends Base
|
||||||
indent = if prop instanceof Comment then '' else idt
|
indent = if prop instanceof Comment then '' else idt
|
||||||
indent += TAB if hasDynamic and i < dynamicIndex
|
indent += TAB if hasDynamic and i < dynamicIndex
|
||||||
if prop instanceof Assign and prop.variable instanceof Value and prop.variable.hasProperties()
|
if prop instanceof Assign and prop.variable instanceof Value and prop.variable.hasProperties()
|
||||||
prop.variable.error 'Invalid object key'
|
prop.variable.error 'invalid object key'
|
||||||
if prop instanceof Value and prop.this
|
if prop instanceof Value and prop.this
|
||||||
prop = new Assign prop.properties[0].name, prop, 'object'
|
prop = new Assign prop.properties[0].name, prop, 'object'
|
||||||
if prop not instanceof Comment
|
if prop not instanceof Comment
|
||||||
|
|
|
@ -254,7 +254,7 @@ class exports.Rewriter
|
||||||
# Furthermore don't allow this in literal arrays, as
|
# Furthermore don't allow this in literal arrays, as
|
||||||
# that creates grammatical ambiguities.
|
# that creates grammatical ambiguities.
|
||||||
if tag in IMPLICIT_FUNC and
|
if tag in IMPLICIT_FUNC and
|
||||||
@indexOfTag(i + 1, 'INDENT', null, ':') > -1 and
|
@indexOfTag(i + 1, 'INDENT') > -1 and @looksObjectish(i + 2) and
|
||||||
not @findTagsBackwards(i, ['CLASS', 'EXTENDS', 'IF', 'CATCH',
|
not @findTagsBackwards(i, ['CLASS', 'EXTENDS', 'IF', 'CATCH',
|
||||||
'SWITCH', 'LEADING_WHEN', 'FOR', 'WHILE', 'UNTIL'])
|
'SWITCH', 'LEADING_WHEN', 'FOR', 'WHILE', 'UNTIL'])
|
||||||
startImplicitCall i + 1
|
startImplicitCall i + 1
|
||||||
|
|
|
@ -751,3 +751,20 @@ test "unexpected object keys", ->
|
||||||
{a: 1, [[]]: 2}
|
{a: 1, [[]]: 2}
|
||||||
^
|
^
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
test "invalid object keys", ->
|
||||||
|
assertErrorFormat '''
|
||||||
|
@a: 1
|
||||||
|
''', '''
|
||||||
|
[stdin]:1:1: error: invalid object key
|
||||||
|
@a: 1
|
||||||
|
^^
|
||||||
|
'''
|
||||||
|
assertErrorFormat '''
|
||||||
|
f
|
||||||
|
@a: 1
|
||||||
|
''', '''
|
||||||
|
[stdin]:2:3: error: invalid object key
|
||||||
|
@a: 1
|
||||||
|
^^
|
||||||
|
'''
|
||||||
|
|
|
@ -695,3 +695,14 @@ test 'implicit invocation with implicit object literal', ->
|
||||||
else
|
else
|
||||||
"a": 1
|
"a": 1
|
||||||
eq 2, obj.a
|
eq 2, obj.a
|
||||||
|
|
||||||
|
# #3935: Implicit call when the first key of an implicit object has interpolation.
|
||||||
|
a = 'a'
|
||||||
|
f
|
||||||
|
"#{a}": 1
|
||||||
|
obj =
|
||||||
|
if f
|
||||||
|
"#{a}": 2
|
||||||
|
else
|
||||||
|
"#{a}": 1
|
||||||
|
eq 2, obj.a
|
||||||
|
|
Loading…
Reference in New Issue