Permalink
Browse files

whitespace cleanup

  • Loading branch information...
1 parent 0c4cb30 commit 46b34d4b435d66cfd13b759c4560b2b277391dc8 @michaelficarra michaelficarra committed Dec 24, 2011
View
@@ -335,7 +335,7 @@ exports.Lexer = class Lexer
prev[0] = 'COMPOUND_ASSIGN'
prev[1] += '='
return value.length
- if value is ';'
+ if value is ';'
@seenFor = no
tag = 'TERMINATOR'
else if value in MATH then tag = 'MATH'
@@ -528,9 +528,9 @@ exports.Lexer = class Lexer
if contents in ['\n', quote] then contents else match
body = body.replace /// #{quote} ///g, '\\$&'
quote + @escapeLines(body, heredoc) + quote
-
+
# Throws a syntax error on the current `@line`.
- error: (message) ->
+ error: (message) ->
throw SyntaxError "#{message} on line #{ @line + 1}"
# Constants
View
@@ -948,13 +948,13 @@ exports.Class = class Class extends Base
@addBoundFunctions o
call = Closure.wrap @body
-
+
if @parent
@superClass = new Literal o.scope.freeVariable 'super', no
@body.expressions.unshift new Extends lname, @superClass
call.args.push @parent
call.variable.params.push new Param @superClass
-
+
klass = new Parens call, yes
klass = new Assign @variable, klass if @variable
klass.compile o
@@ -1228,7 +1228,7 @@ exports.Splat = class Splat extends Base
compile: (o) ->
if @index? then @compileParam o else @name.compile o
-
+
unwrap: -> @name
# Utility function that converts an arbitrary number of elements, mixed with
@@ -1379,12 +1379,12 @@ exports.Op = class Op extends Base
unfoldSoak: (o) ->
@operator in ['++', '--', 'delete'] and unfoldSoak o, this, 'first'
-
+
generateDo: (exp) ->
passedParams = []
func = if exp instanceof Assign and (ref = exp.value.unwrap()) instanceof Code
ref
- else
+ else
exp
for param in func.params or []
if param.value
@@ -1396,9 +1396,9 @@ exports.Op = class Op extends Base
call.do = yes
call
- compileNode: (o) ->
+ compileNode: (o) ->
isChain = @isChainable() and @first.isChainable()
- # In chains, there's no need to wrap bare obj literals in parens,
+ # In chains, there's no need to wrap bare obj literals in parens,
# as the chained expression is wrapped.
@first.front = @front unless isChain
return @compileUnary o if @isUnary()
@@ -1435,7 +1435,7 @@ exports.Op = class Op extends Base
parts.push ' ' if op in ['new', 'typeof', 'delete'] or
plusMinus and @first instanceof Op and @first.operator is op
if (plusMinus && @first instanceof Op) or (op is 'new' and @first.isStatement o)
- @first = new Parens @first
+ @first = new Parens @first
parts.push @first.compile o, LEVEL_OP
parts.reverse() if @flip
parts.join ''
@@ -1503,15 +1503,15 @@ exports.Try = class Try extends Base
o.indent += TAB
errorPart = if @error then " (#{ @error.compile o }) " else ' '
tryPart = @attempt.compile o, LEVEL_TOP
-
+
catchPart = if @recovery
o.scope.add @error.value, 'param' unless o.scope.check @error.value
" catch#{errorPart}{\n#{ @recovery.compile o, LEVEL_TOP }\n#{@tab}}"
else unless @ensure or @recovery
' catch (_error) {}'
-
+
ensurePart = if @ensure then " finally {\n#{ @ensure.compile o, LEVEL_TOP }\n#{@tab}}" else ''
-
+
"""#{@tab}try {
#{tryPart}
#{@tab}}#{ catchPart or '' }#{ensurePart}"""
@@ -1844,7 +1844,7 @@ Closure =
literalArgs: (node) ->
node instanceof Literal and node.value is 'arguments' and not node.asKey
-
+
literalThis: (node) ->
(node instanceof Literal and node.value is 'this' and not node.asKey) or
(node instanceof Code and node.bound)
View
@@ -70,57 +70,57 @@ class exports.Rewriter
# its paired close. We have the mis-nested outdent case included here for
# calls that close on the same line, just before their outdent.
closeOpenCalls: ->
-
+
condition = (token, i) ->
token[0] in [')', 'CALL_END'] or
token[0] is 'OUTDENT' and @tag(i - 1) is ')'
-
+
action = (token, i) ->
@tokens[if token[0] is 'OUTDENT' then i - 1 else i][0] = 'CALL_END'
-
+
@scanTokens (token, i) ->
@detectEnd i + 1, condition, action if token[0] is 'CALL_START'
1
# The lexer has tagged the opening parenthesis of an indexing operation call.
# Match it with its paired close.
closeOpenIndexes: ->
-
- condition = (token, i) ->
+
+ condition = (token, i) ->
token[0] in [']', 'INDEX_END']
-
- action = (token, i) ->
+
+ action = (token, i) ->
token[0] = 'INDEX_END'
-
+
@scanTokens (token, i) ->
@detectEnd i + 1, condition, action if token[0] is 'INDEX_START'
1
# Object literals may be written with implicit braces, for simple cases.
# Insert the missing braces here, so that the parser doesn't have to.
addImplicitBraces: ->
-
+
stack = []
start = null
startsLine = null
sameLine = yes
startIndent = 0
-
+
condition = (token, i) ->
[one, two, three] = @tokens[i + 1 .. i + 3]
return no if 'HERECOMMENT' is one?[0]
[tag] = token
sameLine = no if tag in LINEBREAKS
((tag in ['TERMINATOR', 'OUTDENT'] or (tag in IMPLICIT_END and sameLine)) and
- ((!startsLine and @tag(i - 1) isnt ',') or
+ ((!startsLine and @tag(i - 1) isnt ',') or
not (two?[0] is ':' or one?[0] is '@' and three?[0] is ':'))) or
(tag is ',' and one and
one[0] not in ['IDENTIFIER', 'NUMBER', 'STRING', '@', 'TERMINATOR', 'OUTDENT'])
-
+
action = (token, i) ->
tok = @generate '}', '}', token[2]
@tokens.splice i, 0, tok
-
+
@scanTokens (token, i, tokens) ->
if (tag = token[0]) in EXPRESSION_START
stack.push [(if tag is 'INDENT' and @tag(i - 1) is '{' then '{' else tag), i]
@@ -147,9 +147,9 @@ class exports.Rewriter
# Insert the implicit parentheses here, so that the parser doesn't have to
# deal with them.
addImplicitParentheses: ->
-
+
noCall = seenSingle = seenControl = no
-
+
condition = (token, i) ->
[tag] = token
return yes if not seenSingle and token.fromThen
@@ -161,10 +161,10 @@ class exports.Rewriter
(tag isnt 'INDENT' or
(@tag(i - 2) not in ['CLASS', 'EXTENDS'] and @tag(i - 1) not in IMPLICIT_BLOCK and
not ((post = @tokens[i + 1]) and post.generated and post[0] is '{')))
-
- action = (token, i) ->
+
+ action = (token, i) ->
@tokens.splice i, 0, @generate 'CALL_END', ')', token[2]
-
+
@scanTokens (token, i, tokens) ->
tag = token[0]
noCall = yes if tag in ['CLASS', 'IF']
@@ -190,16 +190,16 @@ class exports.Rewriter
# blocks, so it doesn't need to. ')' can close a single-line block,
# but we need to make sure it's balanced.
addImplicitIndentation: ->
-
+
starter = indent = outdent = null
-
+
condition = (token, i) ->
token[1] isnt ';' and token[0] in SINGLE_CLOSERS and
not (token[0] is 'ELSE' and starter not in ['IF', 'THEN'])
-
+
action = (token, i) ->
@tokens.splice (if @tag(i - 1) is ',' then i - 1 else i), 0, outdent
-
+
@scanTokens (token, i, tokens) ->
[tag] = token
if tag is 'TERMINATOR' and @tag(i + 1) is 'THEN'
@@ -225,16 +225,16 @@ class exports.Rewriter
# Tag postfix conditionals as such, so that we can parse them with a
# different precedence.
tagPostfixConditionals: ->
-
+
original = null
-
- condition = (token, i) ->
+
+ condition = (token, i) ->
token[0] in ['TERMINATOR', 'INDENT']
-
+
action = (token, i) ->
if token[0] isnt 'INDENT' or (token.generated and not token.fromThen)
- original[0] = 'POST_' + original[0]
-
+ original[0] = 'POST_' + original[0]
+
@scanTokens (token, i) ->
return 1 unless token[0] is 'IF'
original = token
@@ -247,7 +247,7 @@ class exports.Rewriter
outdent = ['OUTDENT', 2, token[2]]
indent.generated = outdent.generated = yes if implicit
[indent, outdent]
-
+
# Create a generated token: one that exists due to a use of implicit syntax.
generate: (tag, value, line) ->
tok = [tag, value, line]
View
@@ -291,14 +291,14 @@ test "#1348, #1216: existential assignment compilation", ->
eq nonce, b
#the first ?= compiles into a statement; the second ?= compiles to a ternary expression
eq a ?= b ?= 1, nonce
-
+
e ?= f ?= g ?= 1
eq e + g, 2
-
+
#need to ensure the two vars are not defined, hence the strange names;
# broke earlier when using c ?= d ?= 1 because `d` is declared elsewhere
eq und1_1348 ?= und2_1348 ?= 1, 1
-
+
if a then a ?= 2 else a = 3
eq a, nonce
@@ -307,14 +307,14 @@ test "#1591, #1101: splatted expressions in destructuring assignment must be ass
for nonref in ['', '""', '0', 'f()', '(->)'].concat CoffeeScript.RESERVED
eq nonce, (try CoffeeScript.compile "[#{nonref}...] = v" catch e then nonce)
-test "#1643: splatted accesses in destructuring assignments should not be declared as variables", ->
+test "#1643: splatted accesses in destructuring assignments should not be declared as variables", ->
nonce = {}
accesses = ['o.a', 'o["a"]', '(o.a)', '(o.a).a', '@o.a', 'C::a', 'C::', 'f().a', 'o?.a', 'o?.a.b', 'f?().a']
for access in accesses
for i,j in [1,2,3] #position can matter
- code =
+ code =
"""
- nonce = {}; nonce2 = {}; nonce3 = {};
+ nonce = {}; nonce2 = {}; nonce3 = {};
@o = o = new (class C then a:{}); f = -> o
[#{new Array(i).join('x,')}#{access}...] = [#{new Array(i).join('0,')}nonce, nonce2, nonce3]
unless #{access}[0] is nonce and #{access}[1] is nonce2 and #{access}[2] is nonce3 then throw new Error('[...]')
@@ -326,7 +326,7 @@ test "#1643: splatted accesses in destructuring assignments should not be declar
for i,j in [1,2,3]
code =
"""
- nonce = {}; nonce2 = {}; nonce3 = {};
+ nonce = {}; nonce2 = {}; nonce3 = {};
[#{new Array(i).join('x,')}#{subpattern}...] = [#{new Array(i).join('0,')}nonce, nonce2, nonce3]
unless sub is nonce and sub2 is nonce2 and sub3 is nonce3 then throw new Error('[sub...]')
"""
@@ -335,5 +335,5 @@ test "#1643: splatted accesses in destructuring assignments should not be declar
test "#1838: Regression with variable assignment", ->
name =
'dave'
-
- eq name, 'dave'
+
+ eq name, 'dave'
Oops, something went wrong.

0 comments on commit 46b34d4

Please sign in to comment.