@@ -513,7 +513,7 @@ exports.Value = class Value extends Base
513
513
last (@properties ) instanceof Slice
514
514
515
515
looksStatic : (className ) ->
516
- @base .value is className and @properties .length and
516
+ @base .value is className and @properties .length is 1 and
517
517
@properties [0 ].name ? .value isnt ' prototype'
518
518
519
519
# The value can be unwrapped as its inner node, if there are no attached
@@ -614,10 +614,21 @@ exports.Call = class Call extends Base
614
614
superReference : (o ) ->
615
615
method = o .scope .namedMethod ()
616
616
if method ? .klass
617
- accesses = [new Access (new Literal ' __super__' )]
617
+ {klass , name , variable } = method
618
+ if klass .isComplex ()
619
+ bref = new Literal o .scope .parent .freeVariable ' base'
620
+ base = new Value new Parens new Assign bref, klass
621
+ variable .base = base
622
+ variable .properties .splice 0 , klass .properties .length
623
+ if name .isComplex () or (name instanceof Index and name .index .isAssignable ())
624
+ nref = new Literal o .scope .parent .freeVariable ' name'
625
+ name = new Index new Assign nref, name .index
626
+ variable .properties .pop ()
627
+ variable .properties .push name
628
+ accesses = [new Access new Literal ' __super__' ]
618
629
accesses .push new Access new Literal ' constructor' if method .static
619
- accesses .push new Access new Literal method . name
620
- (new Value ( new Literal method . klass ) , accesses).compile o
630
+ accesses .push if nref ? then new Index nref else name
631
+ (new Value bref ? klass, accesses).compile o
621
632
else if method ? .ctor
622
633
" #{ method .name } .__super__.constructor"
623
634
else
@@ -1011,7 +1022,6 @@ exports.Class = class Class extends Base
1011
1022
if node instanceof Literal and node .value is ' this'
1012
1023
node .value = name
1013
1024
else if node instanceof Code
1014
- node .klass = name
1015
1025
node .context = name if node .bound
1016
1026
1017
1027
# Ensure that all functions bound to the instance are proxied in the
@@ -1162,21 +1172,28 @@ exports.Assign = class Assign extends Base
1162
1172
return @ compileSplice o if @variable .isSplice ()
1163
1173
return @ compileConditional o if @context in [' ||=' , ' &&=' , ' ?=' ]
1164
1174
return @ compileSpecialMath o if @context in [' **=' , ' //=' , ' %%=' ]
1165
- compiledName = @variable .compileToFragments o, LEVEL_LIST
1166
- name = fragmentsToText compiledName
1175
+ if @value instanceof Code
1176
+ if @value .static
1177
+ @value .klass = @variable .base
1178
+ @value .name = @variable .properties [0 ]
1179
+ @value .variable = @variable
1180
+ else if @variable .properties ? .length >= 2
1181
+ [properties ... , prototype , name ] = @variable .properties
1182
+ if prototype .name ? .value is ' prototype'
1183
+ @value .klass = new Value @variable .base , properties
1184
+ @value .name = name
1185
+ @value .variable = @variable
1167
1186
unless @context
1168
1187
varBase = @variable .unwrapAll ()
1169
1188
unless varBase .isAssignable ()
1170
1189
@variable .error " \" #{ @variable .compile o} \" cannot be assigned"
1171
1190
unless varBase .hasProperties ? ()
1172
1191
if @param
1173
- o .scope .add name , ' var'
1192
+ o .scope .add varBase . value , ' var'
1174
1193
else
1175
- o .scope .find name
1176
- if @value instanceof Code and match = METHOD_DEF .exec name
1177
- @value .klass = match[1 ] if match[2 ]
1178
- @value .name = match[3 ] ? match[4 ] ? match[5 ]
1194
+ o .scope .find varBase .value
1179
1195
val = @value .compileToFragments o, LEVEL_LIST
1196
+ compiledName = @variable .compileToFragments o, LEVEL_LIST
1180
1197
return (compiledName .concat @ makeCode (" : " ), val) if @context is ' object'
1181
1198
answer = compiledName .concat @ makeCode (" #{ @context or ' =' } " ), val
1182
1199
if o .level <= LEVEL_LIST then answer else @ wrapInBraces answer
@@ -2237,24 +2254,14 @@ LEVEL_ACCESS = 6 # ...[0]
2237
2254
# Tabs are two spaces for pretty printing.
2238
2255
TAB = ' '
2239
2256
2240
- IDENTIFIER_STR = " [$A-Za-z_\\ x7f-\\ uffff][$\\ w\\ x7f-\\ uffff]*"
2241
- IDENTIFIER = /// ^ #{ IDENTIFIER_STR} $ ///
2257
+ IDENTIFIER = /// ^ (?!\d ) [$\w \x7f -\uffff ] + $ ///
2242
2258
SIMPLENUM = / ^ [+-] ? \d + $ /
2243
2259
HEXNUM = / ^ [+-] ? 0x[\d a-f ] + / i
2244
2260
NUMBER = /// ^ [+-] ? (?:
2245
2261
0x[\d a-f ] + | # hex
2246
2262
\d * \. ? \d + (?:e[+-] ? \d + )? # decimal
2247
2263
)$ /// i
2248
2264
2249
- METHOD_DEF = /// ^
2250
- (#{ IDENTIFIER_STR} )
2251
- (\. prototype)?
2252
- (?: \. (#{ IDENTIFIER_STR} )
2253
- | \[ ("(?:[^ \\ "\r\n ] | \\ . )* "| '(?:[^ \\ '\r\n ] | \\ . )* ')\]
2254
- | \[ (0x[\d a-fA-F ] + | \d * \. ? \d + (?:[eE][+-] ? \d + )? )\]
2255
- )
2256
- $ ///
2257
-
2258
2265
# Is a literal value a string/regex?
2259
2266
IS_STRING = / ^ ['"] /
2260
2267
IS_REGEX = / ^ \/ /
0 commit comments