Skip to content

Commit dd7abb2

Browse files
committed
Recognize static initialization blocks
Closes #594
1 parent 7d92827 commit dd7abb2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# History of user-visible changes
22

3+
## Next
4+
5+
* Support for static initialization blocks
6+
([#594](https://github.com/mooz/js2-mode/issues/594)).
7+
38
## 2023-04-08
49

510
* Support top-level await

js2-mode.el

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2339,7 +2339,7 @@ If any given node in NODES is nil, doesn't record that link."
23392339
top) ; top-level `js2-scope' (script/function)
23402340

23412341
(js2--struct-put 'js2-scope 'js2-visitor 'js2-visit-block)
2342-
(js2--struct-put 'js2-scope 'js2-printer 'js2-print-none)
2342+
(js2--struct-put 'js2-scope 'js2-printer 'js2-print-block)
23432343

23442344
(defun js2-node-get-enclosing-scope (node)
23452345
"Return the innermost `js2-scope' node surrounding NODE.
@@ -11146,6 +11146,10 @@ expression)."
1114611146
((and class-p
1114711147
(= tt js2-SEMI))
1114811148
nil)
11149+
((and class-p
11150+
(eq tt js2-LC))
11151+
(setq after-comma nil
11152+
elem (js2-parse-block)))
1114911153
(t
1115011154
(js2-report-error "msg.bad.prop")
1115111155
(unless js2-recover-from-parse-errors

tests/parser.el

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,9 @@ the test."
10581058
(js2-deftest-parse parse-class-static-fields-no-semi
10591059
"class C {\n static a\n static b = 42\n}")
10601060

1061+
(js2-deftest-parse parse-class-static-block
1062+
"class Foo {\n static {\n a = 4;\n}\n}")
1063+
10611064
;;; Private names
10621065

10631066
(js2-deftest-parse parse-class-private-field-with-init

0 commit comments

Comments
 (0)