js-on-sx: reject unary-op directly before ** per spec (parens still allowed)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

This commit is contained in:
2026-05-10 10:47:56 +00:00
parent 551c24c5a0
commit e93e1eeab1
3 changed files with 20 additions and 2 deletions

View File

@@ -446,14 +446,23 @@
(let
((e (jp-parse-comma-seq st)))
(jp-expect! st "punct" ")")
e)))
(jp-paren-wrap e))))
(do
(dict-set! st :idx saved)
(jp-advance! st)
(let
((e (jp-parse-comma-seq st)))
(jp-expect! st "punct" ")")
e)))))))
(jp-paren-wrap e))))))))
(define
jp-paren-wrap
(fn
(e)
(cond
((and (list? e) (= (first e) (quote js-unop)))
(list (quote js-paren) e))
(else e))))
(define
jp-parse-comma-seq
@@ -753,6 +762,12 @@
(cond
((< prec 0) left)
((< prec min-prec) left)
((and (= op "**") (list? left) (= (first left) (quote js-unop)))
(error
(str
"SyntaxError: Unary operator '"
(nth left 1)
"' used immediately before exponentiation expression")))
(else
(do
(jp-advance! st)

View File

@@ -98,6 +98,7 @@
(list (js-sym "js-regex-new") (nth ast 1) (nth ast 2)))
((js-tag? ast "js-null") nil)
((js-tag? ast "js-undef") (list (js-sym "quote") :js-undefined))
((js-tag? ast "js-paren") (js-transpile (nth ast 1)))
((js-tag? ast "js-ident") (js-transpile-ident (nth ast 1)))
((js-tag? ast "js-unop")
(js-transpile-unop (nth ast 1) (nth ast 2)))