mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
allow indented property index (#5193)
This commit is contained in:
parent
ada35d8951
commit
82f92fea97
5 changed files with 270 additions and 205 deletions
|
@ -446,6 +446,10 @@
|
|||
o('INDEX_START IndexValue INDEX_END',
|
||||
function() {
|
||||
return $2;
|
||||
}),
|
||||
o('INDEX_START INDENT IndexValue OUTDENT INDEX_END',
|
||||
function() {
|
||||
return $3;
|
||||
})
|
||||
],
|
||||
// A return statement from a function body.
|
||||
|
@ -689,6 +693,13 @@
|
|||
[],
|
||||
false,
|
||||
$1);
|
||||
}),
|
||||
o('SUPER INDEX_START INDENT Expression OUTDENT INDEX_END',
|
||||
function() {
|
||||
return new Super(LOC(4)(new Index($4)),
|
||||
[],
|
||||
false,
|
||||
$1);
|
||||
})
|
||||
],
|
||||
// A "meta-property" access e.g. `new.target`
|
||||
|
@ -757,6 +768,10 @@
|
|||
function() {
|
||||
return $2;
|
||||
}),
|
||||
o('INDEX_START INDENT IndexValue OUTDENT INDEX_END',
|
||||
function() {
|
||||
return $3;
|
||||
}),
|
||||
o('INDEX_SOAK Index',
|
||||
function() {
|
||||
return extend($2,
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -280,8 +280,9 @@ grammar =
|
|||
]
|
||||
|
||||
ObjSpreadAccessor: [
|
||||
o '. Property', -> new Access $2
|
||||
o 'INDEX_START IndexValue INDEX_END', -> $2
|
||||
o '. Property', -> new Access $2
|
||||
o 'INDEX_START IndexValue INDEX_END', -> $2
|
||||
o 'INDEX_START INDENT IndexValue OUTDENT INDEX_END', -> $3
|
||||
]
|
||||
|
||||
# A return statement from a function body.
|
||||
|
@ -392,8 +393,9 @@ grammar =
|
|||
|
||||
# A `super`-based expression that can be used as a value.
|
||||
Super: [
|
||||
o 'SUPER . Property', -> new Super LOC(3)(new Access $3), [], no, $1
|
||||
o 'SUPER INDEX_START Expression INDEX_END', -> new Super LOC(3)(new Index $3), [], no, $1
|
||||
o 'SUPER . Property', -> new Super LOC(3)(new Access $3), [], no, $1
|
||||
o 'SUPER INDEX_START Expression INDEX_END', -> new Super LOC(3)(new Index $3), [], no, $1
|
||||
o 'SUPER INDEX_START INDENT Expression OUTDENT INDEX_END', -> new Super LOC(4)(new Index $4), [], no, $1
|
||||
]
|
||||
|
||||
# A "meta-property" access e.g. `new.target`
|
||||
|
@ -415,8 +417,9 @@ grammar =
|
|||
|
||||
# Indexing into an object or array using bracket notation.
|
||||
Index: [
|
||||
o 'INDEX_START IndexValue INDEX_END', -> $2
|
||||
o 'INDEX_SOAK Index', -> extend $2, soak: yes
|
||||
o 'INDEX_START IndexValue INDEX_END', -> $2
|
||||
o 'INDEX_START INDENT IndexValue OUTDENT INDEX_END', -> $3
|
||||
o 'INDEX_SOAK Index', -> extend $2, soak: yes
|
||||
]
|
||||
|
||||
IndexValue: [
|
||||
|
|
|
@ -470,3 +470,29 @@ test "#3736: chaining after do IIFE", ->
|
|||
eq 4,
|
||||
do b
|
||||
.c
|
||||
|
||||
test "#5168: allow indented property index", ->
|
||||
a = b: 3
|
||||
|
||||
eq 3, a[
|
||||
if yes
|
||||
'b'
|
||||
else
|
||||
'c'
|
||||
]
|
||||
|
||||
d = [1, 2, 3]
|
||||
arrayEq [1, 2], d[
|
||||
...2
|
||||
]
|
||||
|
||||
class A
|
||||
b: -> 3
|
||||
|
||||
class B extends A
|
||||
c: ->
|
||||
super[
|
||||
'b'
|
||||
]()
|
||||
|
||||
eq 3, new B().c()
|
||||
|
|
|
@ -428,3 +428,15 @@ test "#4834: dynamic import can technically be object spread", ->
|
|||
|
||||
x = {...import('module')};
|
||||
"""
|
||||
|
||||
test "#5168: allow indented property index", ->
|
||||
a = b: c: 3
|
||||
|
||||
eq 3, {
|
||||
...a[
|
||||
if yes
|
||||
'b'
|
||||
else
|
||||
'c'
|
||||
]
|
||||
}.c
|
||||
|
|
Loading…
Reference in a new issue