@@ -512,8 +512,8 @@ exports.Value = class Value extends Base
512
512
last (@properties ) instanceof Slice
513
513
514
514
looksStatic : (className ) ->
515
- @base .value is className and @properties .length and
516
- @properties [0 ]. name ? . value isnt ' prototype'
515
+ @base .value is className and @properties .length is 1 and
516
+ propertyName ( @properties [0 ]) isnt ' prototype'
517
517
518
518
# The value can be unwrapped as its inner node, if there are no attached
519
519
# properties.
@@ -613,10 +613,21 @@ exports.Call = class Call extends Base
613
613
superReference : (o ) ->
614
614
method = o .scope .namedMethod ()
615
615
if method ? .klass
616
- accesses = [new Access (new Literal ' __super__' )]
616
+ {klass , name , variable } = method
617
+ if klass .isComplex ()
618
+ bref = new Literal o .scope .parent .freeVariable ' base'
619
+ base = new Value new Parens new Assign bref, klass
620
+ variable .base = base
621
+ variable .properties .splice 0 , klass .properties .length
622
+ if name .isComplex () or (name instanceof Index and name .index .isAssignable ())
623
+ nref = new Literal o .scope .parent .freeVariable ' name'
624
+ name = new Index new Assign nref, name .index
625
+ variable .properties .pop ()
626
+ variable .properties .push name
627
+ accesses = [new Access new Literal ' __super__' ]
617
628
accesses .push new Access new Literal ' constructor' if method .static
618
- accesses .push new Access new Literal method . name
619
- (new Value ( new Literal method . klass ) , accesses).compile o
629
+ accesses .push if nref ? then new Index nref else name
630
+ (new Value bref ? klass, accesses).compile o
620
631
else if method ? .ctor
621
632
" #{ method .name } .__super__.constructor"
622
633
else
@@ -1009,7 +1020,7 @@ exports.Class = class Class extends Base
1009
1020
if node instanceof Literal and node .value is ' this'
1010
1021
node .value = name
1011
1022
else if node instanceof Code
1012
- node .klass = name
1023
+ node .klass = new Value new Literal name
1013
1024
node .context = name if node .bound
1014
1025
1015
1026
# Ensure that all functions bound to the instance are proxied in the
@@ -1160,21 +1171,27 @@ exports.Assign = class Assign extends Base
1160
1171
return @ compileSplice o if @variable .isSplice ()
1161
1172
return @ compileConditional o if @context in [' ||=' , ' &&=' , ' ?=' ]
1162
1173
return @ compileSpecialMath o if @context in [' **=' , ' //=' , ' %%=' ]
1163
- compiledName = @variable .compileToFragments o, LEVEL_LIST
1164
- name = fragmentsToText compiledName
1174
+ if @value instanceof Code
1175
+ if @value .static
1176
+ @value .name = @variable .properties [0 ]
1177
+ @value .variable = @variable
1178
+ else if @variable .properties ? .length >= 2
1179
+ [properties ... , prototype , name ] = @variable .properties
1180
+ if propertyName (prototype) is ' prototype'
1181
+ @value .klass = new Value @variable .base , properties
1182
+ @value .name = name
1183
+ @value .variable = @variable
1165
1184
unless @context
1166
1185
varBase = @variable .unwrapAll ()
1167
1186
unless varBase .isAssignable ()
1168
1187
@variable .error " \" #{ @variable .compile o} \" cannot be assigned"
1169
1188
unless varBase .hasProperties ? ()
1170
1189
if @param
1171
- o .scope .add name , ' var'
1190
+ o .scope .add varBase . value , ' var'
1172
1191
else
1173
- o .scope .find name
1174
- if @value instanceof Code and match = METHOD_DEF .exec name
1175
- @value .klass = match[1 ] if match[2 ]
1176
- @value .name = match[3 ] ? match[4 ] ? match[5 ]
1192
+ o .scope .find varBase .value
1177
1193
val = @value .compileToFragments o, LEVEL_LIST
1194
+ compiledName = @variable .compileToFragments o, LEVEL_LIST
1178
1195
return (compiledName .concat @ makeCode (" : " ), val) if @context is ' object'
1179
1196
answer = compiledName .concat @ makeCode (" #{ @context or ' =' } " ), val
1180
1197
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 = / ^ \/ /
@@ -2296,3 +2303,10 @@ unfoldSoak = (o, parent, name) ->
2296
2303
parent[name] = ifn .body
2297
2304
ifn .body = new Value parent
2298
2305
ifn
2306
+
2307
+ # Extract `name` from `.name` or `["name"]`.
2308
+ propertyName = (property ) -> switch
2309
+ when property instanceof Access
2310
+ property .name .value
2311
+ when property instanceof Index and property .index instanceof Value and property .index .isString ()
2312
+ property .index .base .value [1 ... - 1 ]
0 commit comments