Skip to content

Commit

Permalink
fix object literals with null value + unit tests #264
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 14, 2024
1 parent e8bb82a commit 841dcdd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* fix resolving promises inside quoted promise realm
* fix undocumented symbol syntax extensions
* fix odd? even? on non integers
* fix object literals with null value [#264](https://github.com/jcubic/lips/issues/264)

## 1.0.0-beta.17
### Breaking
Expand Down
2 changes: 1 addition & 1 deletion dist/std.min.scm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions dist/std.scm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/std.xcb
Binary file not shown.
7 changes: 4 additions & 3 deletions lib/bootstrap.scm
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,17 @@
,@(let loop ((lst expr) (result nil))
(if (null? lst)
(reverse result)
(let ((first (car lst))
(second (if (null? (cdr lst)) nil (cadr lst))))
(let* ((first (car lst))
(no-second (null? (cdr lst)))
(second (if no-second nil (cadr lst))))
(if (not (key? first))
(let ((msg (string-append (type first)
" "
(repr first)
" is not a symbol!")))
(throw msg))
(let ((prop (key->string first)))
(if (or (key? second) (null? second))
(if (or (key? second) no-second)
(let ((code `(set-obj! ,name ,prop undefined)))
(loop (cdr lst) (cons code result)))
(let ((code (if readonly
Expand Down
11 changes: 11 additions & 0 deletions tests/core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@
(t.is (to.throw (set! x.foo "hey")) true)
(t.is (to.throw (set! x.bar "hey")) true))))

(test "core: it should create object literals without values"
(lambda (t)
(let ((x &(:foo :bar)))
(t.is x &(:foo undefined :bar undefined)))))

(test "core: it should create object with null value (#264)"
(lambda (t)
(let ((x &(:foo null :bar null)))
(t.is (eq? x.foo null) #t)
(t.is (eq? x.bar null) #t))))

(test "core: it should allow change shorthand object literals"
(lambda (t)
(let ((obj &(:x :y)))
Expand Down

0 comments on commit 841dcdd

Please sign in to comment.