@@ -509,6 +509,10 @@ exports.Value = class Value extends Base
509
509
isSplice : ->
510
510
last (@properties ) instanceof Slice
511
511
512
+ looksStatic : (className ) ->
513
+ @base .value is className and @properties .length and
514
+ @properties [0 ].name ? .value isnt ' prototype'
515
+
512
516
# The value can be unwrapped as its inner node, if there are no attached
513
517
# properties.
514
518
unwrap : ->
@@ -1036,8 +1040,6 @@ exports.Class = class Class extends Base
1036
1040
else
1037
1041
if assign .variable .this
1038
1042
func .static = yes
1039
- if func .bound
1040
- func .context = name
1041
1043
else
1042
1044
assign .variable = new Value (new Literal (name), [(new Access new Literal ' prototype' ), new Access base])
1043
1045
if func instanceof Code and func .bound
@@ -1046,14 +1048,17 @@ exports.Class = class Class extends Base
1046
1048
assign
1047
1049
compact exprs
1048
1050
1049
- # Walk the body of the class, looking for prototype properties to be converted.
1051
+ # Walk the body of the class, looking for prototype properties to be converted
1052
+ # and tagging static assignments.
1050
1053
walkBody : (name , o ) ->
1051
1054
@ traverseChildren false , (child ) =>
1052
1055
cont = true
1053
1056
return false if child instanceof Class
1054
1057
if child instanceof Block
1055
1058
for node, i in exps = child .expressions
1056
- if node instanceof Value and node .isObject (true )
1059
+ if node instanceof Assign and node .variable .looksStatic name
1060
+ node .value .static = yes
1061
+ else if node instanceof Value and node .isObject (true )
1057
1062
cont = false
1058
1063
exps[i] = @ addProperties node, name, o
1059
1064
child .expressions = exps = flatten exps
@@ -1164,8 +1169,8 @@ exports.Assign = class Assign extends Base
1164
1169
else
1165
1170
o .scope .find name
1166
1171
if @value instanceof Code and match = METHOD_DEF .exec name
1167
- @value .klass = match[1 ] if match[1 ]
1168
- @value .name = match[2 ] ? match[ 3 ] ? match[4 ] ? match[5 ]
1172
+ @value .klass = match[1 ] if match[2 ]
1173
+ @value .name = match[3 ] ? match[4 ] ? match[5 ]
1169
1174
val = @value .compileToFragments o, LEVEL_LIST
1170
1175
return (compiledName .concat @ makeCode (" : " ), val) if @context is ' object'
1171
1176
answer = compiledName .concat @ makeCode (" #{ @context or ' =' } " ), val
@@ -2141,21 +2146,14 @@ NUMBER = ///^[+-]?(?:
2141
2146
\d * \. ? \d + (?:e[+-] ? \d + )? # decimal
2142
2147
)$ /// i
2143
2148
2144
- METHOD_DEF = ///
2145
- ^
2146
- (?:
2147
- (#{ IDENTIFIER_STR} )
2148
- \. prototype
2149
- (?:
2150
- \. (#{ IDENTIFIER_STR} )
2151
- | \[ ("(?:[^ \\ "\r\n ] | \\ . )* "| '(?:[^ \\ '\r\n ] | \\ . )* ')\]
2152
- | \[ (0x[\d a-fA-F ] + | \d * \. ? \d + (?:[eE][+-] ? \d + )? )\]
2153
- )
2154
- )
2155
- |
2156
- (#{ IDENTIFIER_STR} )
2157
- $
2158
- ///
2149
+ METHOD_DEF = /// ^
2150
+ (#{ IDENTIFIER_STR} )
2151
+ (\. prototype)?
2152
+ (?: \. (#{ IDENTIFIER_STR} )
2153
+ | \[ ("(?:[^ \\ "\r\n ] | \\ . )* "| '(?:[^ \\ '\r\n ] | \\ . )* ')\]
2154
+ | \[ (0x[\d a-fA-F ] + | \d * \. ? \d + (?:[eE][+-] ? \d + )? )\]
2155
+ )
2156
+ $ ///
2159
2157
2160
2158
# Is a literal value a string/regex?
2161
2159
IS_STRING = / ^ ['"] /
0 commit comments