js-on-sx: parse-time SyntaxError on illegal break/continue/return; void evaluates expr
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
This commit is contained in:
@@ -165,7 +165,7 @@
|
||||
(let
|
||||
((params (jp-parse-param-list st)))
|
||||
(let
|
||||
((body (jp-parse-block st)))
|
||||
((body (jp-parse-fn-body st)))
|
||||
(list (quote js-funcexpr) nm params body))))))
|
||||
((and (= (get t :type) "keyword") (= (get t :value) "true"))
|
||||
(do (jp-advance! st) (list (quote js-bool) true)))
|
||||
@@ -237,7 +237,7 @@
|
||||
(let
|
||||
((params (jp-parse-param-list st)))
|
||||
(let
|
||||
((body (jp-parse-block st)))
|
||||
((body (jp-parse-fn-body st)))
|
||||
(list (quote js-funcexpr-async) nm params body))))))
|
||||
((= (get t :type) "ident")
|
||||
(do
|
||||
@@ -389,7 +389,7 @@
|
||||
(let
|
||||
((params (jp-parse-param-list st)))
|
||||
(let
|
||||
((body (jp-parse-block st)))
|
||||
((body (jp-parse-fn-body st)))
|
||||
(list (quote js-funcexpr) nm params body))))))
|
||||
((= (get t :type) "ident")
|
||||
(do
|
||||
@@ -1153,6 +1153,18 @@
|
||||
(list (quote js-if) c t (jp-parse-stmt st)))
|
||||
(list (quote js-if) c t nil))))))))
|
||||
|
||||
(define
|
||||
jp-bump!
|
||||
(fn
|
||||
(st key)
|
||||
(dict-set! st key (+ (get st key) 1))))
|
||||
|
||||
(define
|
||||
jp-decr!
|
||||
(fn
|
||||
(st key)
|
||||
(dict-set! st key (- (get st key) 1))))
|
||||
|
||||
(define
|
||||
jp-parse-while-stmt
|
||||
(fn
|
||||
@@ -1164,7 +1176,10 @@
|
||||
((c (jp-parse-assignment st)))
|
||||
(do
|
||||
(jp-expect! st "punct" ")")
|
||||
(let ((body (jp-parse-stmt st))) (list (quote js-while) c body)))))))
|
||||
(jp-bump! st :loop-depth)
|
||||
(let ((body (jp-parse-stmt st)))
|
||||
(jp-decr! st :loop-depth)
|
||||
(list (quote js-while) c body)))))))
|
||||
|
||||
(define
|
||||
jp-parse-do-while-stmt
|
||||
@@ -1172,8 +1187,10 @@
|
||||
(st)
|
||||
(do
|
||||
(jp-advance! st)
|
||||
(jp-bump! st :loop-depth)
|
||||
(let
|
||||
((body (jp-parse-stmt st)))
|
||||
(jp-decr! st :loop-depth)
|
||||
(do
|
||||
(if
|
||||
(jp-at? st "keyword" "while")
|
||||
@@ -1218,8 +1235,10 @@
|
||||
(let
|
||||
((iter (jp-parse-assignment st)))
|
||||
(jp-expect! st "punct" ")")
|
||||
(jp-bump! st :loop-depth)
|
||||
(let
|
||||
((body (jp-parse-stmt st)))
|
||||
(jp-decr! st :loop-depth)
|
||||
(list (quote js-for-of-in) iter-kind ident iter body)))))))
|
||||
(else
|
||||
(let
|
||||
@@ -1230,8 +1249,10 @@
|
||||
(let
|
||||
((step (if (jp-at? st "punct" ")") nil (jp-parse-assignment st))))
|
||||
(jp-expect! st "punct" ")")
|
||||
(jp-bump! st :loop-depth)
|
||||
(let
|
||||
((body (jp-parse-stmt st)))
|
||||
(jp-decr! st :loop-depth)
|
||||
(list (quote js-for) init cond-ast step body)))))))))))
|
||||
|
||||
(define
|
||||
@@ -1254,6 +1275,9 @@
|
||||
(st)
|
||||
(do
|
||||
(jp-advance! st)
|
||||
(when
|
||||
(= (get st :fn-depth) 0)
|
||||
(error "SyntaxError: Illegal return statement"))
|
||||
(if
|
||||
(or
|
||||
(jp-at? st "punct" ";")
|
||||
@@ -1281,7 +1305,7 @@
|
||||
(let
|
||||
((params (jp-parse-param-list st)))
|
||||
(let
|
||||
((body (jp-parse-block st)))
|
||||
((body (jp-parse-fn-body st)))
|
||||
(list (quote js-funcdecl) nm params body))))))))
|
||||
|
||||
(define
|
||||
@@ -1300,7 +1324,7 @@
|
||||
(let
|
||||
((params (jp-parse-param-list st)))
|
||||
(let
|
||||
((body (jp-parse-block st)))
|
||||
((body (jp-parse-fn-body st)))
|
||||
(list (quote js-funcdecl-async) nm params body))))))))
|
||||
|
||||
(define
|
||||
@@ -1349,7 +1373,7 @@
|
||||
(let
|
||||
((params (jp-parse-param-list st)))
|
||||
(let
|
||||
((body (jp-parse-block st)))
|
||||
((body (jp-parse-fn-body st)))
|
||||
(list
|
||||
(quote js-method)
|
||||
(if static? "static" "instance")
|
||||
@@ -1377,9 +1401,11 @@
|
||||
((disc (jp-parse-assignment st)))
|
||||
(jp-expect! st "punct" ")")
|
||||
(jp-expect! st "punct" "{")
|
||||
(jp-bump! st :switch-depth)
|
||||
(let
|
||||
((cases (list)))
|
||||
(jp-parse-switch-cases st cases)
|
||||
(jp-decr! st :switch-depth)
|
||||
(jp-expect! st "punct" "}")
|
||||
(list (quote js-switch) disc cases)))))
|
||||
|
||||
@@ -1460,14 +1486,26 @@
|
||||
(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)))))))
|
||||
(else
|
||||
(do
|
||||
(when
|
||||
(and (= (get st :loop-depth) 0) (= (get st :switch-depth) 0))
|
||||
(error "SyntaxError: Illegal break statement"))
|
||||
(jp-eat-semi st)
|
||||
(list (quote js-break)))))))
|
||||
((jp-at? st "keyword" "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)))))))
|
||||
(else
|
||||
(do
|
||||
(when
|
||||
(= (get st :loop-depth) 0)
|
||||
(error "SyntaxError: Illegal continue statement"))
|
||||
(jp-eat-semi st)
|
||||
(list (quote js-continue)))))))
|
||||
((and
|
||||
(= (get (jp-peek st) :type) "ident")
|
||||
(= (get (jp-peek-at st 1) :type) "punct")
|
||||
@@ -1511,10 +1549,33 @@
|
||||
jp-parse-arrow-body
|
||||
(fn
|
||||
(st)
|
||||
(if
|
||||
(jp-at? st "punct" "{")
|
||||
(jp-parse-block st)
|
||||
(jp-parse-assignment st))))
|
||||
(jp-bump! st :fn-depth)
|
||||
(let
|
||||
((saved-loop (get st :loop-depth)) (saved-switch (get st :switch-depth)))
|
||||
(dict-set! st :loop-depth 0)
|
||||
(dict-set! st :switch-depth 0)
|
||||
(let
|
||||
((body (if (jp-at? st "punct" "{") (jp-parse-block st) (jp-parse-assignment st))))
|
||||
(jp-decr! st :fn-depth)
|
||||
(dict-set! st :loop-depth saved-loop)
|
||||
(dict-set! st :switch-depth saved-switch)
|
||||
body))))
|
||||
|
||||
(define
|
||||
jp-parse-fn-body
|
||||
(fn
|
||||
(st)
|
||||
(jp-bump! st :fn-depth)
|
||||
(let
|
||||
((saved-loop (get st :loop-depth)) (saved-switch (get st :switch-depth)))
|
||||
(dict-set! st :loop-depth 0)
|
||||
(dict-set! st :switch-depth 0)
|
||||
(let
|
||||
((body (jp-parse-block st)))
|
||||
(jp-decr! st :fn-depth)
|
||||
(dict-set! st :loop-depth saved-loop)
|
||||
(dict-set! st :switch-depth saved-switch)
|
||||
body))))
|
||||
|
||||
(define
|
||||
js-parse
|
||||
@@ -1525,7 +1586,7 @@
|
||||
(= (len tokens) 0)
|
||||
(and (= (len tokens) 1) (= (get (nth tokens 0) :type) "eof")))
|
||||
(list (quote js-program) (list))
|
||||
(let ((st {:idx 0 :tokens tokens :arrow-candidate true})) (jp-parse-program st)))))
|
||||
(let ((st {:idx 0 :tokens tokens :arrow-candidate true :loop-depth 0 :switch-depth 0 :fn-depth 0})) (jp-parse-program st)))))
|
||||
|
||||
(define
|
||||
js-parse-expr
|
||||
@@ -1538,4 +1599,4 @@
|
||||
(= (len tokens) 0)
|
||||
(and (= (len tokens) 1) (= (get (nth tokens 0) :type) "eof")))
|
||||
(list)
|
||||
(let ((st {:idx 0 :tokens tokens :arrow-candidate true})) (jp-parse-assignment st))))))
|
||||
(let ((st {:idx 0 :tokens tokens :arrow-candidate true :loop-depth 0 :switch-depth 0 :fn-depth 0})) (jp-parse-assignment st))))))
|
||||
|
||||
@@ -251,7 +251,8 @@
|
||||
((= op "!") (list (js-sym "js-not") a))
|
||||
((= op "~") (list (js-sym "js-bitnot") a))
|
||||
((= op "typeof") (list (js-sym "js-typeof") a))
|
||||
((= op "void") (list (js-sym "quote") :js-undefined))
|
||||
((= op "void")
|
||||
(list (js-sym "begin") a (list (js-sym "quote") :js-undefined)))
|
||||
(else (error (str "js-transpile-unop: unsupported op: " op)))))))))
|
||||
|
||||
;; ── Array literal ─────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user