forcing spaces for implicit calls ... making '@ name' a call instead of an access. Ticket #353

This commit is contained in:
Jeremy Ashkenas 2010-05-04 23:44:54 -04:00
parent 1a03e98057
commit 6222ed622f
3 changed files with 5 additions and 6 deletions

View File

@ -162,7 +162,7 @@
stack[stack.length - 2] += stack.pop();
}
open = stack[stack.length - 1] > 0;
if (prev && include(IMPLICIT_FUNC, prev[0]) && include(IMPLICIT_CALL, tag)) {
if (prev && prev.spaced && include(IMPLICIT_FUNC, prev[0]) && include(IMPLICIT_CALL, tag)) {
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
stack[stack.length - 1] += 1;
if (include(EXPRESSION_START, tag)) {
@ -380,7 +380,7 @@
// Tokens that indicate the close of a clause of an expression.
EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
// Tokens that, if followed by an `IMPLICIT_CALL`, indicate a function invocation.
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '<-'];
IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '<-', '@'];
// If preceded by an `IMPLICIT_FUNC`, indicates a function invocation.
IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'EXTENSION', 'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT', 'THIS', 'NULL', '@', '->', '=>', '[', '(', '{'];
// Tokens indicating that the implicit call must enclose a block of expressions.

View File

@ -122,7 +122,7 @@ exports.Rewriter: class Rewriter
tag: token[0]
stack[stack.length - 2]: + stack.pop() if tag is 'OUTDENT'
open: stack[stack.length - 1] > 0
if prev and include(IMPLICIT_FUNC, prev[0]) and include(IMPLICIT_CALL, tag)
if prev and prev.spaced and include(IMPLICIT_FUNC, prev[0]) and include(IMPLICIT_CALL, tag)
@tokens.splice i, 0, ['CALL_START', '(', token[2]]
stack[stack.length - 1]: + 1
stack.push 0 if include(EXPRESSION_START, tag)
@ -274,7 +274,7 @@ EXPRESSION_END: pair[1] for pair in BALANCED_PAIRS
EXPRESSION_CLOSE: ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat EXPRESSION_END
# Tokens that, if followed by an `IMPLICIT_CALL`, indicate a function invocation.
IMPLICIT_FUNC: ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '<-']
IMPLICIT_FUNC: ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '<-', '@']
# If preceded by an `IMPLICIT_FUNC`, indicates a function invocation.
IMPLICIT_CALL: ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START',

View File

@ -77,7 +77,7 @@ fn: (arg) -> arg
ok fn(fn {prop: 101}).prop is 101
# Function calls sans-spacing.
ok((fn(x) ->
ok((fn (x) ->
3
)() is 3)
@ -156,4 +156,3 @@ result: sum ->
, ->
1 + 3
ok result is 20