Skip to content

Commit

Permalink
fix calling Promise methods on quoted Promises #155 + fix set-obj!
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Apr 9, 2021
1 parent 7fa02c7 commit 1c0db78
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.12-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&e9681dedb755926b716caa2820e013b61f757bf3)](https://travis-ci.org/jcubic/lips)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&6904201de0d2f47e4a0faf6c2e3973cc)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&7fa02c740e903c66a59a36272e7dbd93d2339db8)](https://travis-ci.org/jcubic/lips)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&a3a139eee91421821fbe40e312bdb04a)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
[![GitHub license](https://img.shields.io/github/license/jcubic/lips.svg)](https://github.com/jcubic/lips/blob/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/jcubic/lips.svg?style=social&label=Star&maxAge=2592000)](https://github.com/jcubic/lips/stargazers/)
Expand Down
22 changes: 16 additions & 6 deletions dist/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Copyright (c) 2014-present, Facebook, Inc.
* released under MIT license
*
* build: Fri, 09 Apr 2021 15:58:19 +0000
* build: Fri, 09 Apr 2021 16:12:10 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -6739,6 +6739,10 @@
return object.map(unbox);
}

if (object instanceof QuotedPromise) {
delete object.then;
}

if (is_plain_object(object)) {
return map_object(object, unbox);
}
Expand Down Expand Up @@ -11003,8 +11007,14 @@
}), "(define name expression)\n (define (function-name . args) body)\n\n Macro for defining values. It can be used to define variables,\n or function. If first argument is list it will create function\n with name beeing first element of the list. The macro evalute\n code `(define function (lambda args body))`"),
// ------------------------------------------------------------------
'set-obj!': doc('set-obj!', function (obj, key, value) {
typecheck('set-obj!', obj, ['function', 'object']);
typecheck('set-obj!', key, ['string', 'symbol']);
var obj_type = _typeof_1(obj);

if (is_null(obj) || obj_type !== 'object' && obj_type !== 'function') {
var msg = typeErrorMessage('set-obj!', type(obj), ['object', 'function']);
throw new Error(msg);
}

typecheck('set-obj!', key, ['string', 'symbol', 'number']);
obj = unbind(obj);
key = key.valueOf();

Expand Down Expand Up @@ -13967,10 +13977,10 @@

var banner = function () {
// Rollup tree-shaking is removing the variable if it's normal string because
// obviously 'Fri, 09 Apr 2021 15:58:19 +0000' == '{{' + 'DATE}}'; can be removed
// obviously 'Fri, 09 Apr 2021 16:12:10 +0000' == '{{' + 'DATE}}'; can be removed
// but disablig Tree-shaking is adding lot of not used code so we use this
// hack instead
var date = LString('Fri, 09 Apr 2021 15:58:19 +0000').valueOf();
var date = LString('Fri, 09 Apr 2021 16:12:10 +0000').valueOf();

var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date);

Expand Down Expand Up @@ -14010,7 +14020,7 @@
var lips = {
version: 'DEV',
banner: banner,
date: 'Fri, 09 Apr 2021 15:58:19 +0000',
date: 'Fri, 09 Apr 2021 16:12:10 +0000',
exec: exec,
// unwrap async generator into Promise<Array>
parse: compose(uniterate_async, parse),
Expand Down
4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -4052,6 +4052,9 @@
if (object instanceof Array) {
return object.map(unbox);
}
if (object instanceof QuotedPromise) {
delete object.then;
}
if (is_plain_object(object)) {
return map_object(object, unbox);
}
Expand Down Expand Up @@ -7214,8 +7217,12 @@
code \`(define function (lambda args body))\``),
// ------------------------------------------------------------------
'set-obj!': doc('set-obj!', function(obj, key, value) {
typecheck('set-obj!', obj, ['function', 'object']);
typecheck('set-obj!', key, ['string', 'symbol']);
var obj_type = typeof obj;
if (is_null(obj) || (obj_type !== 'object' && obj_type !== 'function')) {
var msg = typeErrorMessage('set-obj!', type(obj), ['object', 'function']);
throw new Error(msg);
}
typecheck('set-obj!', key, ['string', 'symbol', 'number']);
obj = unbind(obj);
key = key.valueOf();
if (arguments.length === 2) {
Expand Down
6 changes: 6 additions & 0 deletions tests/core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@
(t.is (repr promise) "#<js-promise (rejected)>")
(t.is (not (null? (promise.__reason__.message.match #/ZONK/))) true))))

(test "core: Promise.all on quoted promises"
(lambda (t)
(let ((expected #(10 20))
(result (vector '>(wait 1000 10) '>(wait 1000 20))))
(t.is (Promise.all result) expected))))

(test "core: quoted promise in let"
(lambda (t)

Expand Down

0 comments on commit 1c0db78

Please sign in to comment.