js-on-sx: ASI — :nl token flag + return restricted production (525/526 unit, 148/148 slice)
Lexer: adds :nl (newline-before) boolean to every token. scan! resets the flag before each skip-ws! call; skip-ws! sets it true when it consumes \n or \r. Parser: jp-token-nl? reads the flag; jp-parse-return-stmt stops before the expression when a newline precedes it (return\n42 → return undefined). Four new tests cover the restricted production and the raw flag. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1323,6 +1323,16 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 3505)
|
||||
(eval "(js-eval \"var a = {length: 3, 0: 10, 1: 20, 2: 30}; var sum = 0; Array.prototype.forEach.call(a, function(x){sum += x;}); sum\")")
|
||||
|
||||
;; ── Phase 1.ASI: automatic semicolon insertion ─────────────────
|
||||
(epoch 4200)
|
||||
(eval "(js-eval \"function f() { return\n42\n} f()\")")
|
||||
(epoch 4201)
|
||||
(eval "(js-eval \"function g() { return 42 } g()\")")
|
||||
(epoch 4202)
|
||||
(eval "(let ((toks (js-tokenize \"a\nb\"))) (get (nth toks 1) :nl))")
|
||||
(epoch 4203)
|
||||
(eval "(let ((toks (js-tokenize \"a b\"))) (get (nth toks 1) :nl))")
|
||||
|
||||
EPOCHS
|
||||
|
||||
|
||||
@@ -2042,6 +2052,12 @@ check 3503 "indexOf.call arrLike" '1'
|
||||
check 3504 "filter.call arrLike" '"2,3"'
|
||||
check 3505 "forEach.call arrLike sum" '60'
|
||||
|
||||
# ── Phase 1.ASI: automatic semicolon insertion ────────────────────
|
||||
check 4200 "return+newline → undefined" '"js-undefined"'
|
||||
check 4201 "return+space+val → val" '42'
|
||||
check 4202 "nl-before flag set after newline" 'true'
|
||||
check 4203 "nl-before flag false on same line" 'false'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user