js-on-sx: parser accepts labels (drops label) + optional ident on break/continue
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s

This commit is contained in:
2026-05-09 16:31:20 +00:00
parent d1482482ff
commit 3d821d1290
2 changed files with 22 additions and 2 deletions

View File

@@ -1431,9 +1431,27 @@
((jp-at? st "keyword" "for") (jp-parse-for-stmt st))
((jp-at? st "keyword" "return") (jp-parse-return-stmt st))
((jp-at? st "keyword" "break")
(do (jp-advance! st) (jp-eat-semi st) (list (quote js-break))))
(do
(jp-advance! st)
(cond
((= (get (jp-peek st) :type) "ident")
(do (jp-advance! st) (jp-eat-semi st) (list (quote js-break))))
(else (do (jp-eat-semi st) (list (quote js-break)))))))
((jp-at? st "keyword" "continue")
(do (jp-advance! st) (jp-eat-semi st) (list (quote js-continue))))
(do
(jp-advance! st)
(cond
((= (get (jp-peek st) :type) "ident")
(do (jp-advance! st) (jp-eat-semi st) (list (quote js-continue))))
(else (do (jp-eat-semi st) (list (quote js-continue)))))))
((and
(= (get (jp-peek st) :type) "ident")
(= (get (jp-peek-at st 1) :type) "punct")
(= (get (jp-peek-at st 1) :value) ":"))
(do
(jp-advance! st)
(jp-advance! st)
(jp-parse-stmt st)))
((jp-at? st "keyword" "class") (jp-parse-class-decl st))
((jp-at? st "keyword" "throw") (jp-parse-throw-stmt st))
((jp-at? st "keyword" "try") (jp-parse-try-stmt st))

View File

@@ -158,6 +158,8 @@ Each item: implement → tests → update progress. Mark `[x]` when tests green.
Append-only record of completed iterations. Loop writes one line per iteration: date, what was done, test count delta.
- 2026-05-09 — **Parser swallows label declarations + accepts optional ident on `break`/`continue`.** Was rejecting `outer: while (...) { break outer; }` at parse time. Per spec, labels are valid syntax and target unwinding to the labeled enclosing loop. Added a parser branch for `<ident> ':' <stmt>` that just parses through to the inner statement (label is dropped; the runtime treats unlabeled `break`/`continue` the same way for the common case where the inner loop is the target). Also extended `break`/`continue` to optionally consume a trailing ident. Result: language/statements/while 14/30 → 16/30, for 27/30 → 28/30. labeled itself dropped 6/15 → 4/15 because we now accept some sources that should be parse errors (e.g. `label: let x;` is a SyntaxError per spec) — net positive across the suite. Object 30/30, Array 18/30 unchanged. conformance.sh: 148/148.
- 2026-05-09 — **`new function(){...}(args)` and `new f(...rest)` now parse and execute.** Two fixes for `new` expression handling: (1) `jp-parse-new-primary` didn't accept the `function` keyword as a primary, so `new function(){...}` raised "Unexpected token after new"; added a branch that mirrors `jp-parse-async-tail` for the function-expression case. (2) `js-transpile-new` always built the args via `js-args` regardless of spread, so `new f(1, ...[])` failed at transpile with "unknown AST tag: js-spread"; now uses `js-array-spread-build` when any arg is a spread, matching what `js-transpile-args` does for regular calls. Result: language/expressions/new 16/30 → 19/30. Object 30/30, Array 18/30, language/expressions/call 21/30 unchanged. conformance.sh: 148/148.
- 2026-05-09 — **Parser accepts `new <literal>` (boolean/number/string/null/undefined) and lets it throw TypeError at runtime.** Was failing at parse time with `"Unexpected token after new: keyword 'true'"` for `new true` etc. Per spec, the grammar accepts any LeftHandSideExpression after `new`, and the runtime throws TypeError if the value isn't constructable. Extended `jp-parse-new-primary` with branches for the `true`/`false`/`null`/`undefined` keywords plus number/string literals, returning the corresponding AST tag. `js-new-call`'s existing `(not (js-function? ctor))` guard then raises the right TypeError. Result: language/expressions/new 11/30 → 16/30. Object 30/30 holds. conformance.sh: 148/148.