mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
forcing spaces for implicit calls ... making '@ name' a call instead of an access. Ticket #353
This commit is contained in:
parent
1a03e98057
commit
6222ed622f
3 changed files with 5 additions and 6 deletions
|
@ -162,7 +162,7 @@
|
||||||
stack[stack.length - 2] += stack.pop();
|
stack[stack.length - 2] += stack.pop();
|
||||||
}
|
}
|
||||||
open = stack[stack.length - 1] > 0;
|
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]]);
|
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
||||||
stack[stack.length - 1] += 1;
|
stack[stack.length - 1] += 1;
|
||||||
if (include(EXPRESSION_START, tag)) {
|
if (include(EXPRESSION_START, tag)) {
|
||||||
|
@ -380,7 +380,7 @@
|
||||||
// Tokens that indicate the close of a clause of an expression.
|
// Tokens that indicate the close of a clause of an expression.
|
||||||
EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
|
EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
|
||||||
// Tokens that, if followed by an `IMPLICIT_CALL`, indicate a function invocation.
|
// 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.
|
// 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', '@', '->', '=>', '[', '(', '{'];
|
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.
|
// Tokens indicating that the implicit call must enclose a block of expressions.
|
||||||
|
|
|
@ -122,7 +122,7 @@ exports.Rewriter: class Rewriter
|
||||||
tag: token[0]
|
tag: token[0]
|
||||||
stack[stack.length - 2]: + stack.pop() if tag is 'OUTDENT'
|
stack[stack.length - 2]: + stack.pop() if tag is 'OUTDENT'
|
||||||
open: stack[stack.length - 1] > 0
|
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]]
|
@tokens.splice i, 0, ['CALL_START', '(', token[2]]
|
||||||
stack[stack.length - 1]: + 1
|
stack[stack.length - 1]: + 1
|
||||||
stack.push 0 if include(EXPRESSION_START, tag)
|
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
|
EXPRESSION_CLOSE: ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat EXPRESSION_END
|
||||||
|
|
||||||
# Tokens that, if followed by an `IMPLICIT_CALL`, indicate a function invocation.
|
# 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.
|
# If preceded by an `IMPLICIT_FUNC`, indicates a function invocation.
|
||||||
IMPLICIT_CALL: ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START',
|
IMPLICIT_CALL: ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START',
|
||||||
|
|
|
@ -77,7 +77,7 @@ fn: (arg) -> arg
|
||||||
ok fn(fn {prop: 101}).prop is 101
|
ok fn(fn {prop: 101}).prop is 101
|
||||||
|
|
||||||
# Function calls sans-spacing.
|
# Function calls sans-spacing.
|
||||||
ok((fn(x) ->
|
ok((fn (x) ->
|
||||||
3
|
3
|
||||||
)() is 3)
|
)() is 3)
|
||||||
|
|
||||||
|
@ -156,4 +156,3 @@ result: sum ->
|
||||||
, ->
|
, ->
|
||||||
1 + 3
|
1 + 3
|
||||||
ok result is 20
|
ok result is 20
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue