-
Notifications
You must be signed in to change notification settings - Fork 2k
Handle implicit object as end of outer implicit object property value #5296
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
Handle implicit object as end of outer implicit object property value #5296
Conversation
| if (stackTag is '{' or stackTag is 'INDENT' and @tag(stackIdx - 1) is '{') and | ||
| (startsLine or @tag(s - 1) is ',' or @tag(s - 1) is '{') | ||
| (startsLine or @tag(s - 1) is ',' or @tag(s - 1) is '{') and | ||
| @tag(s - 1) not in UNFINISHED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting it to parse the nested object as a separate object wasn't that hard...
| stackItem[2].sameLine = no if isImplicitObject stackItem | ||
|
|
||
| # End indented-continuation-line implicit objects once that indentation is over. | ||
| if tag is 'TERMINATOR' and token.endsContinuationLineIndentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...the hard part was to then parse additional properties of the outer object as belonging to the outer (not inner) object, eg:
a: b or
b: 1
c: 2 # this belongs to the top-level object, not the nested b: 1 object
In order to accomplish that, I added extra token data for "indented line continuations" like this to allow comparing the indentation levels to know when the nested line continuation indent is done (thus when the nested object is done)
| ].concat IMPLICIT_UNSPACED_CALL.concat IMPLICIT_END.concat CALL_CLOSERS.concat CONTROL_IN_IMPLICIT | ||
|
|
||
| # Tokens that, when appearing at the end of a line, suppress a following TERMINATOR/INDENT token | ||
| exports.UNFINISHED = UNFINISHED = ['\\', '.', '?.', '?::', 'UNARY', 'DO', 'DO_IIFE', 'MATH', 'UNARY_MATH', '+', '-', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this here to avoid a circular dependency between lexer.coffee and rewriter.coffee
src/lexer.coffee
Outdated
| if size > @indent | ||
| if noNewlines | ||
| @indebt = size - @indent unless backslash | ||
| if @indebt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to additionally rename @indebt to something more descriptive like @continuationLineAdditionalIndent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, indebt is a pretty bad name (too close to indent).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok renamed indebt -> continuationLineAdditionalIndent
Fixes #5292
This PR updates
addImplicitBracesAndParens()to correctly parse things like: