return and export default can now accept implicit objects (#4532)

This commit is contained in:
Geoffrey Booth
2017-05-01 19:31:17 -07:00
parent ac1b2b5c30
commit 26cb24acc8
6 changed files with 45 additions and 13 deletions

View File

@@ -378,7 +378,7 @@ exports.Lexer = class Lexer
return indent.length
if size > @indent
if noNewlines
if noNewlines or @tag() is 'RETURN'
@indebt = size - @indent
@suppressNewlines()
return indent.length
@@ -430,7 +430,7 @@ exports.Lexer = class Lexer
this
# Matches and consumes non-meaningful whitespace. Tag the previous token
# as being "spaced", because there are some cases where it makes a difference.
# as being spaced, because there are some cases where it makes a difference.
whitespaceToken: ->
return 0 unless (match = WHITESPACE.exec @chunk) or
(nline = @chunk.charAt(0) is '\n')
@@ -761,7 +761,7 @@ exports.Lexer = class Lexer
LINE_CONTINUER.test(@chunk) or
@tag() in ['\\', '.', '?.', '?::', 'UNARY', 'MATH', 'UNARY_MATH', '+', '-',
'**', 'SHIFT', 'RELATION', 'COMPARE', '&', '^', '|', '&&', '||',
'BIN?', 'THROW', 'EXTENDS']
'BIN?', 'THROW', 'EXTENDS', 'DEFAULT']
formatString: (str, options) ->
@replaceUnicodeCodePointEscapes str.replace(STRING_OMIT, '$1'), options

View File

@@ -14,11 +14,7 @@ generate = (tag, value, origin) ->
# The **Rewriter** class is used by the [Lexer](lexer.html), directly against
# its internal array of tokens.
class exports.Rewriter
# Helpful snippet for debugging:
#
# console.log (t[0] + '/' + t[1] for t in @tokens).join ' '
exports.Rewriter = class Rewriter
# Rewrite the token stream in multiple passes, one logical filter at
# a time. This could certainly be changed into a single pass through the
@@ -26,6 +22,8 @@ class exports.Rewriter
# like this. The order of these passes matters -- indentation must be
# corrected before implicit parentheses can be wrapped around blocks of code.
rewrite: (@tokens) ->
# Helpful snippet for debugging:
# console.log (t[0] + '/' + t[1] for t in @tokens).join ' '
@removeLeadingNewlines()
@closeOpenCalls()
@closeOpenIndexes()
@@ -186,7 +184,7 @@ class exports.Rewriter
# Don't end an implicit call on next indent if any of these are in an argument
if inImplicitCall() and tag in ['IF', 'TRY', 'FINALLY', 'CATCH',
'CLASS', 'SWITCH']
stack.push ['CONTROL', i, ours: true]
stack.push ['CONTROL', i, ours: yes]
return forward(1)
if tag is 'INDENT' and inImplicit()