@@ -1966,13 +1966,22 @@ static bool parseMethods (tokenInfo *const token, int class_index,
1966
1966
* field1 = 1
1967
1967
* The parser extracts field0 as a method because the left value
1968
1968
* is a function (kind propagation), and field1 as a field.
1969
+ *
1970
+ * static methods and static initialization blocks
1971
+ * - ref. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks
1972
+ *
1973
+ * static func() {}
1974
+ * static {}
1975
+ * static prop;
1976
+ * static prop = val;
1969
1977
*/
1970
1978
1971
1979
bool dont_read = false;
1972
1980
do
1973
1981
{
1974
1982
bool is_setter = false;
1975
1983
bool is_getter = false;
1984
+ bool is_static = false; /* For recognizing static {...} block. */
1976
1985
1977
1986
if (!dont_read )
1978
1987
readToken (token );
@@ -1985,6 +1994,8 @@ static bool parseMethods (tokenInfo *const token, int class_index,
1985
1994
1986
1995
if (isKeyword (token , KEYWORD_async ))
1987
1996
readToken (token );
1997
+ else if (isKeyword (token , KEYWORD_static ))
1998
+ is_static = true;
1988
1999
else if (isType (token , TOKEN_KEYWORD ) &&
1989
2000
(isKeyword (token , KEYWORD_get ) || isKeyword (token , KEYWORD_set )))
1990
2001
{
@@ -2014,8 +2025,9 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2014
2025
continue ;
2015
2026
}
2016
2027
2017
- if (! isType (token , TOKEN_KEYWORD ) &&
2018
- ! isType (token , TOKEN_SEMICOLON ))
2028
+ if ((! isType (token , TOKEN_KEYWORD ) &&
2029
+ ! isType (token , TOKEN_SEMICOLON ))
2030
+ || is_static )
2019
2031
{
2020
2032
bool is_generator = false;
2021
2033
bool is_shorthand = false; /* ES6 shorthand syntax */
@@ -2190,6 +2202,15 @@ static bool parseMethods (tokenInfo *const token, int class_index,
2190
2202
2191
2203
vStringDelete (signature );
2192
2204
}
2205
+ else if (is_static )
2206
+ {
2207
+ if (isType (token , TOKEN_OPEN_CURLY ))
2208
+ /* static initialization block */
2209
+ parseBlock (token , class_index );
2210
+ else
2211
+ dont_read = true;
2212
+ continue ;
2213
+ }
2193
2214
else
2194
2215
{
2195
2216
bool is_property = isType (token , TOKEN_COMMA );
0 commit comments