Skip to content

Instantly share code, notes, and snippets.

@geraldalewis
Created August 12, 2011 17:42
Show Gist options
  • Save geraldalewis/1142542 to your computer and use it in GitHub Desktop.
Save geraldalewis/1142542 to your computer and use it in GitHub Desktop.
Full diff of src/ for patch #1590 for issue #1234
diff --git a/src/grammar.coffee b/src/grammar.coffee
index e57ab39..035e168 100644
--- a/src/grammar.coffee
+++ b/src/grammar.coffee
@@ -217,7 +217,7 @@ grammar =
# Variables and properties that can be assigned to.
SimpleAssignable: [
o 'Identifier', -> new Value $1
- o 'Value Accessor', -> $1.push $2
+ o 'Value Accessor', -> $1.add $2
o 'Invocation Accessor', -> new Value $1, [$2]
o 'ThisProperty'
]
@@ -244,7 +244,7 @@ grammar =
Accessor: [
o '. Identifier', -> new Access $2
o '?. Identifier', -> new Access $2, 'soak'
- o ':: Identifier', -> new Access $2, 'proto'
+ o ':: Identifier', -> [(new Access new Literal 'prototype'), new Access $2]
o '::', -> new Access new Literal 'prototype'
o 'Index'
]
@@ -253,7 +253,6 @@ grammar =
Index: [
o 'INDEX_START IndexValue INDEX_END', -> $2
o 'INDEX_SOAK Index', -> extend $2, soak : yes
- o 'INDEX_PROTO Index', -> extend $2, proto: yes
]
IndexValue: [
diff --git a/src/lexer.coffee b/src/lexer.coffee
index 2f73c8b..8800fe6 100644
--- a/src/lexer.coffee
+++ b/src/lexer.coffee
@@ -336,7 +336,6 @@ exports.Lexer = class Lexer
tag = 'INDEX_START'
switch prev[0]
when '?' then prev[0] = 'INDEX_SOAK'
- when '::' then prev[0] = 'INDEX_PROTO'
@token tag, value
value.length
diff --git a/src/nodes.coffee b/src/nodes.coffee
index 3fdc435..a84c10f 100644
--- a/src/nodes.coffee
+++ b/src/nodes.coffee
@@ -344,9 +344,9 @@ exports.Value = class Value extends Base
children: ['base', 'properties']
- # Add a property access to the list.
- push: (prop) ->
- @properties.push prop
+ # Add a property (or *properties* ) `Access` to the list.
+ add: (props) ->
+ @properties = @properties.concat props
this
hasProperties: ->
@@ -397,7 +397,7 @@ exports.Value = class Value extends Base
nref = new Literal o.scope.freeVariable 'name'
name = new Index new Assign nref, name.index
nref = new Index nref
- [base.push(name), new Value(bref or base.base, [nref or name])]
+ [base.add(name), new Value(bref or base.base, [nref or name])]
# We compile a value to JavaScript by compiling and joining each property.
# Things get much more interesting if the chain of properties has *soak*
@@ -596,14 +596,13 @@ exports.Extends = class Extends extends Base
exports.Access = class Access extends Base
constructor: (@name, tag) ->
@name.asKey = yes
- @proto = if tag is 'proto' then '.prototype' else ''
@soak = tag is 'soak'
children: ['name']
compile: (o) ->
name = @name.compile o
- @proto + if IDENTIFIER.test name then ".#{name}" else "[#{name}]"
+ if IDENTIFIER.test name then ".#{name}" else "[#{name}]"
isComplex: NO
@@ -616,7 +615,7 @@ exports.Index = class Index extends Base
children: ['index']
compile: (o) ->
- (if @proto then '.prototype' else '') + "[#{ @index.compile o, LEVEL_PAREN }]"
+ "[#{ @index.compile o, LEVEL_PAREN }]"
isComplex: ->
@index.isComplex()
@@ -857,10 +856,10 @@ exports.Class = class Class extends Base
assign = new Assign new Literal(@externalCtor), func
else
unless assign.variable.this
- assign.variable = new Value(new Literal(name), [new Access(base, 'proto')])
- if func instanceof Code and func.bound and not assign.variable.this
- @boundFuncs.push base
- func.bound = no
+ assign.variable = new Value(new Literal(name), [(new Access new Literal 'prototype'), new Access base ])
+ if func instanceof Code and func.bound
+ @boundFuncs.push base
+ func.bound = no
assign
compact exprs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment