whitespace cleanup

This commit is contained in:
Michael Ficarra
2011-12-24 07:04:34 -05:00
parent 0c4cb309b0
commit 46b34d4b43
11 changed files with 100 additions and 100 deletions

View File

@@ -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 File

@@ -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 File

@@ -70,14 +70,14 @@ 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
@@ -85,13 +85,13 @@ class exports.Rewriter
# 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
@@ -99,28 +99,28 @@ class exports.Rewriter
# 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]