removing arguments as a keyword -- we can detect its use at code-generation time.

This commit is contained in:
Jeremy Ashkenas
2010-02-05 22:01:11 -05:00
parent dc7d0f1568
commit b795ae7fe1
6 changed files with 1385 additions and 1400 deletions

View File

@@ -13,7 +13,6 @@ token FOR IN OF BY WHEN WHILE
token SWITCH LEADING_WHEN token SWITCH LEADING_WHEN
token DELETE INSTANCEOF TYPEOF token DELETE INSTANCEOF TYPEOF
token SUPER EXTENDS token SUPER EXTENDS
token ARGUMENTS
token NEWLINE token NEWLINE
token COMMENT token COMMENT
token JS token JS
@@ -102,7 +101,6 @@ rule
| REGEX { result = LiteralNode.new(val[0]) } | REGEX { result = LiteralNode.new(val[0]) }
| BREAK { result = LiteralNode.new(val[0]) } | BREAK { result = LiteralNode.new(val[0]) }
| CONTINUE { result = LiteralNode.new(val[0]) } | CONTINUE { result = LiteralNode.new(val[0]) }
| ARGUMENTS { result = LiteralNode.new(val[0]) }
| TRUE { result = LiteralNode.new(Value.new(true)) } | TRUE { result = LiteralNode.new(Value.new(true)) }
| FALSE { result = LiteralNode.new(Value.new(false)) } | FALSE { result = LiteralNode.new(Value.new(false)) }
| YES { result = LiteralNode.new(Value.new(true)) } | YES { result = LiteralNode.new(Value.new(true)) }

View File

@@ -15,8 +15,7 @@ module CoffeeScript
"for", "in", "of", "by", "where", "while", "for", "in", "of", "by", "where", "while",
"delete", "instanceof", "typeof", "delete", "instanceof", "typeof",
"switch", "when", "switch", "when",
"super", "extends", "super", "extends"]
"arguments"]
# Token matching regexes. # Token matching regexes.
IDENTIFIER = /\A([a-zA-Z$_](\w|\$)*)/ IDENTIFIER = /\A([a-zA-Z$_](\w|\$)*)/

View File

@@ -153,7 +153,7 @@ module CoffeeScript
# at the top. # at the top.
def compile_with_declarations(o={}) def compile_with_declarations(o={})
code = compile_node(o) code = compile_node(o)
args = self.contains? {|n| n.is_a?(LiteralNode) && n.arguments? } args = self.contains? {|n| n.is_a?(ValueNode) && n.arguments? }
argv = args && o[:scope].check('arguments') ? '' : 'var ' argv = args && o[:scope].check('arguments') ? '' : 'var '
code = "#{idt}#{argv}arguments = Array.prototype.slice.call(arguments, 0);\n#{code}" if args code = "#{idt}#{argv}arguments = Array.prototype.slice.call(arguments, 0);\n#{code}" if args
code = "#{idt}var #{o[:scope].compiled_assignments};\n#{code}" if o[:scope].assignments?(self) code = "#{idt}var #{o[:scope].compiled_assignments};\n#{code}" if o[:scope].assignments?(self)
@@ -203,10 +203,6 @@ module CoffeeScript
end end
alias_method :statement_only?, :statement? alias_method :statement_only?, :statement?
def arguments?
@value.to_s == 'arguments'
end
def compile_node(o) def compile_node(o)
indent = statement? ? idt : '' indent = statement? ? idt : ''
ending = statement? ? ';' : '' ending = statement? ? ';' : ''
@@ -361,6 +357,10 @@ module CoffeeScript
properties? && @properties.last.is_a?(SliceNode) properties? && @properties.last.is_a?(SliceNode)
end end
def arguments?
@base.to_s == 'arguments'
end
def unwrap def unwrap
@properties.empty? ? @base : self @properties.empty? ? @base : self
end end

File diff suppressed because it is too large Load Diff

View File

@@ -22,9 +22,9 @@ module CoffeeScript
IMPLICIT_FUNC = [:IDENTIFIER, :SUPER, ')', :CALL_END, ']', :INDEX_END] IMPLICIT_FUNC = [:IDENTIFIER, :SUPER, ')', :CALL_END, ']', :INDEX_END]
IMPLICIT_END = [:IF, :UNLESS, :FOR, :WHILE, "\n", :OUTDENT] IMPLICIT_END = [:IF, :UNLESS, :FOR, :WHILE, "\n", :OUTDENT]
IMPLICIT_CALL = [:IDENTIFIER, :NUMBER, :STRING, :JS, :REGEX, :NEW, :PARAM_START, IMPLICIT_CALL = [:IDENTIFIER, :NUMBER, :STRING, :JS, :REGEX, :NEW, :PARAM_START,
:TRY, :DELETE, :TYPEOF, :SWITCH, :ARGUMENTS, :TRY, :DELETE, :TYPEOF, :SWITCH,
:TRUE, :FALSE, :YES, :NO, :ON, :OFF, '!', '!!', :NOT, :TRUE, :FALSE, :YES, :NO, :ON, :OFF, '!', '!!', :NOT,
'->', '=>', '[', '(', '{'] '@', '->', '=>', '[', '(', '{']
# The inverse mappings of token pairs we're trying to fix up. # The inverse mappings of token pairs we're trying to fix up.
INVERSES = BALANCED_PAIRS.inject({}) do |memo, pair| INVERSES = BALANCED_PAIRS.inject({}) do |memo, pair|

View File

@@ -30,3 +30,8 @@ func: ->
arguments arguments
print func(100) is 25 print func(100) is 25
# Arguments can be accessed as a property.
this.arguments: 10
print @arguments is 10