removing obvious redundant parentheses.

This commit is contained in:
Jeremy Ashkenas
2010-06-27 23:55:18 -04:00
parent a810eb29db
commit 08ab4abd43
11 changed files with 37 additions and 29 deletions

View File

@@ -193,11 +193,14 @@ exports.Expressions: class Expressions extends BaseNode
# If we happen to be the top-level **Expressions**, wrap everything in
# a safety closure, unless requested not to.
# It would be better not to generate them in the first place, but for now,
# clean up obvious double-parentheses.
compileRoot: (o) ->
o.indent: @tab: if o.noWrap then '' else TAB
o.scope: new Scope(null, this, null)
code: if o.globals then @compileNode(o) else @compileWithDeclarations(o)
code: code.replace(TRAILING_WHITESPACE, '')
code: code.replace(DOUBLE_PARENS, '($1)')
if o.noWrap then code else "(function(){\n$code\n})();\n"
# Compile the expressions body for the contents of a function, with
@@ -1422,6 +1425,9 @@ TAB: ' '
# with Git.
TRAILING_WHITESPACE: /[ \t]+$/gm
# Obvious redundant parentheses should be removed.
DOUBLE_PARENS: /\(\(([^\(\)\n]*)\)\)/g
# Keep these identifier regexes in sync with the Lexer.
IDENTIFIER: /^[a-zA-Z\$_](\w|\$)*$/
NUMBER : /^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b$/i