Skip to content

Commit 294bb47

Browse files
Fix #5112: A string of ', ' in an array should not be detected as an elision (#5113)
1 parent 6e86b67 commit 294bb47

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

lib/coffeescript/nodes.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

+4-3
Original file line numberDiff line numberDiff line change
@@ -1644,8 +1644,9 @@ exports.Arr = class Arr extends Base
16441644
compileNode: (o) ->
16451645
return [@makeCode '[]'] unless @objects.length
16461646
o.indent += TAB
1647-
fragmentIsElision = (fragment) -> fragmentsToText(fragment).trim() is ','
1648-
# Detect if `Elisions` at the beginning of the array are processed (e.g. [, , , a]).
1647+
fragmentIsElision = ([ fragment ]) ->
1648+
fragment.type is 'Elision' and fragment.code.trim() is ','
1649+
# Detect if `Elision`s at the beginning of the array are processed (e.g. [, , , a]).
16491650
passedElision = no
16501651

16511652
answer = []
@@ -1687,7 +1688,7 @@ exports.Arr = class Arr extends Base
16871688
for fragment, fragmentIndex in answer
16881689
if fragment.isHereComment
16891690
fragment.code = "#{multident(fragment.code, o.indent, no)}\n#{o.indent}"
1690-
else if fragment.code is ', ' and not fragment?.isElision
1691+
else if fragment.code is ', ' and not fragment?.isElision and fragment.type isnt 'StringLiteral'
16911692
fragment.code = ",\n#{o.indent}"
16921693
answer.unshift @makeCode "[\n#{o.indent}"
16931694
answer.push @makeCode "\n#{@tab}]"

test/arrays.coffee

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ test "array elisions nested destructuring", ->
115115
deepEqual d, {x:2}
116116
arrayEq w, [1,2,4]
117117

118+
test "#5112: array elisions not detected inside strings", ->
119+
arr = [
120+
str: ", #{3}"
121+
]
122+
eq arr[0].str, ', 3'
123+
118124
# Splats in Array Literals
119125

120126
test "array splat expansions with assignments", ->

0 commit comments

Comments
 (0)