js-maker simpeler

This commit is contained in:
2026-06-08 12:15:04 +02:00
parent cffb5ec91a
commit a9610e6e0c
5 changed files with 92 additions and 1003 deletions
+29
View File
@@ -0,0 +1,29 @@
#lang racket/base
(require rackunit
"main.rkt")
(define ordinary
(js (define (ordinary-let x)
(let ([x 1] [y x])
(return y)))))
(define sequential
(js (define (sequential-let x)
(let* ([x 1] [y x])
(return y)))))
(define looped
(js (define (sum-to n)
(let loop ([i 0] [acc 0])
(if (> i n)
(return acc)
(loop (+ i 1) (+ acc i)))))))
(check-regexp-match #rx"function ordinary_let" ordinary)
(check-regexp-match #rx"const [A-Za-z0-9_]+ = x;" ordinary)
(check-regexp-match #rx"let y = [A-Za-z0-9_]+;" ordinary)
(check-regexp-match #rx"let y = x;" sequential)
(check-regexp-match #rx"while \\(true\\)" looped)
(check-regexp-match #rx"continue;" looped)
(check-equal? (js1 (+ 1 2)) "1 + 2")