mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
removing arguments as a keyword -- we can detect its use at code-generation time.
This commit is contained in:
parent
dc7d0f1568
commit
b795ae7fe1
6 changed files with 1385 additions and 1400 deletions
|
@ -13,7 +13,6 @@ token FOR IN OF BY WHEN WHILE
|
|||
token SWITCH LEADING_WHEN
|
||||
token DELETE INSTANCEOF TYPEOF
|
||||
token SUPER EXTENDS
|
||||
token ARGUMENTS
|
||||
token NEWLINE
|
||||
token COMMENT
|
||||
token JS
|
||||
|
@ -102,7 +101,6 @@ rule
|
|||
| REGEX { result = LiteralNode.new(val[0]) }
|
||||
| BREAK { result = LiteralNode.new(val[0]) }
|
||||
| CONTINUE { result = LiteralNode.new(val[0]) }
|
||||
| ARGUMENTS { result = LiteralNode.new(val[0]) }
|
||||
| TRUE { result = LiteralNode.new(Value.new(true)) }
|
||||
| FALSE { result = LiteralNode.new(Value.new(false)) }
|
||||
| YES { result = LiteralNode.new(Value.new(true)) }
|
||||
|
|
|
@ -15,8 +15,7 @@ module CoffeeScript
|
|||
"for", "in", "of", "by", "where", "while",
|
||||
"delete", "instanceof", "typeof",
|
||||
"switch", "when",
|
||||
"super", "extends",
|
||||
"arguments"]
|
||||
"super", "extends"]
|
||||
|
||||
# Token matching regexes.
|
||||
IDENTIFIER = /\A([a-zA-Z$_](\w|\$)*)/
|
||||
|
|
|
@ -153,7 +153,7 @@ module CoffeeScript
|
|||
# at the top.
|
||||
def compile_with_declarations(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 '
|
||||
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)
|
||||
|
@ -203,10 +203,6 @@ module CoffeeScript
|
|||
end
|
||||
alias_method :statement_only?, :statement?
|
||||
|
||||
def arguments?
|
||||
@value.to_s == 'arguments'
|
||||
end
|
||||
|
||||
def compile_node(o)
|
||||
indent = statement? ? idt : ''
|
||||
ending = statement? ? ';' : ''
|
||||
|
@ -361,6 +357,10 @@ module CoffeeScript
|
|||
properties? && @properties.last.is_a?(SliceNode)
|
||||
end
|
||||
|
||||
def arguments?
|
||||
@base.to_s == 'arguments'
|
||||
end
|
||||
|
||||
def unwrap
|
||||
@properties.empty? ? @base : self
|
||||
end
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,9 +22,9 @@ module CoffeeScript
|
|||
IMPLICIT_FUNC = [:IDENTIFIER, :SUPER, ')', :CALL_END, ']', :INDEX_END]
|
||||
IMPLICIT_END = [:IF, :UNLESS, :FOR, :WHILE, "\n", :OUTDENT]
|
||||
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,
|
||||
'->', '=>', '[', '(', '{']
|
||||
'@', '->', '=>', '[', '(', '{']
|
||||
|
||||
# The inverse mappings of token pairs we're trying to fix up.
|
||||
INVERSES = BALANCED_PAIRS.inject({}) do |memo, pair|
|
||||
|
|
|
@ -30,3 +30,8 @@ func: ->
|
|||
arguments
|
||||
|
||||
print func(100) is 25
|
||||
|
||||
|
||||
# Arguments can be accessed as a property.
|
||||
this.arguments: 10
|
||||
print @arguments is 10
|
||||
|
|
Loading…
Reference in a new issue