Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CS2] Fix #2998: Object literal with inconsistent indentation should throw an error #4630

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/coffeescript/rewriter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/rewriter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,12 @@ exports.Rewriter = class Rewriter
if (stackTag is '{' or stackTag is 'INDENT' and @tag(stackIdx - 1) is '{') and
(startsLine or @tag(s - 1) is ',' or @tag(s - 1) is '{')
return forward(1)
# Is this an indentation error within what was intended to be one object?
else if s > 3 and @tag(s - 1) in LINEBREAKS and @tag(s - 2) in LINEBREAKS and
@tag(s - 3) is '}' and @tokens[s - 3].generated
throwSyntaxError 'unexpected indentation', @tokens[s - 1][2]

startImplicitObject(s, !!startsLine)
startImplicitObject s, startsLine?
return forward(2)

# End implicit calls when chaining method calls
Expand Down
14 changes: 14 additions & 0 deletions test/error_messages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1742,3 +1742,17 @@ test "#3199: error message for throw indented comprehension", ->
x for x in [1, 2, 3]
^
'''

test "#2998: Indentation mismatch in object shouldn’t produce two objects", ->
assertErrorFormat '''
colors =
45: 'cyan'
52: 'sepia'
100: 'olive'
124: 'red'
''', '''
[stdin]:4:3: error: unexpected indentation
100: 'olive'
^
'''

5 changes: 2 additions & 3 deletions test/objects.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ ok obj.misdent.toString() is ',,,'
# String-keyed objects shouldn't suppress newlines.
one =
'>!': 3
six: -> 10
ok not one.six
six: -> 10
eq one.six(), 10

# Shorthand objects with property references.
obj =
Expand Down Expand Up @@ -696,4 +696,3 @@ test "#4579: Postfix for/while/until in first line of implicit object literals",
baz: 1337
arrayEq [4, 3, 2, 1, 0], six.foo.bar
eq 1337, six.foo.baz