Skip to content

Commit

Permalink
improve resolving issue of QuotedPromises #153
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Apr 6, 2021
1 parent ca667fe commit 8910dd1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![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&512c43bd4c78b47ea0e9b9c685e8914227b0af0c)](https://travis-ci.org/jcubic/lips)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&ca667feeaec1b0caea9aef462318747067d67119)](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)
[![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)
Expand Down
40 changes: 13 additions & 27 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: Tue, 06 Apr 2021 09:41:27 +0000
* build: Tue, 06 Apr 2021 11:22:24 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -2226,7 +2226,9 @@
}
});
});
read_only(this, '__promise__', promise);
read_only(this, '__promise__', promise); // prevent resolving when returned from real promise #153

this.then = false;
} // ----------------------------------------------------------------------


Expand Down Expand Up @@ -3610,27 +3612,8 @@
};
var error = arguments.length > 2 && arguments[2] !== undefined$1 ? arguments[2] : null;

if (value instanceof QuotedPromise) {
return fn(value);
}

if (is_promise(value)) {
var ret = value.then(function (value) {
// escape QuotedPromise because JS handle primise like objects
// like real promises and next `then` get the value
// not promise like object #153
if (value instanceof Value) {
value = value.valueOf();
}

var ret = fn(value);

if (ret instanceof QuotedPromise) {
return new Value(ret);
}

return ret;
});
var ret = value.then(fn);

if (error === null) {
return ret;
Expand Down Expand Up @@ -10090,9 +10073,12 @@

while (args.length) {
var arg = args.shift();
var name = unbox(arg);
var name = unbox(arg); // the value was set to false to prevent resolving
// by Real Promises #153

if (name === '__code__' && is_function(object) && typeof object.__code__ === 'undefined') {
if (name === 'then' && object instanceof QuotedPromise) {
value = QuotedPromise.prototype.then;
} else if (name === '__code__' && is_function(object) && typeof object.__code__ === 'undefined') {
value = native_lambda;
} else {
value = object[name];
Expand Down Expand Up @@ -13986,10 +13972,10 @@

var banner = function () {
// Rollup tree-shaking is removing the variable if it's normal string because
// obviously 'Tue, 06 Apr 2021 09:41:27 +0000' == '{{' + 'DATE}}'; can be removed
// obviously 'Tue, 06 Apr 2021 11:22:24 +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('Tue, 06 Apr 2021 09:41:27 +0000').valueOf();
var date = LString('Tue, 06 Apr 2021 11:22:24 +0000').valueOf();

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

Expand Down Expand Up @@ -14029,7 +14015,7 @@
var lips = {
version: 'DEV',
banner: banner,
date: 'Tue, 06 Apr 2021 09:41:27 +0000',
date: 'Tue, 06 Apr 2021 11:22:24 +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.

25 changes: 8 additions & 17 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@
});
});
read_only(this, '__promise__', promise);
// prevent resolving when returned from real promise #153
this.then = false;
}
// ----------------------------------------------------------------------
QuotedPromise.prototype.then = function(fn) {
Expand Down Expand Up @@ -1640,23 +1642,8 @@
}
// ----------------------------------------------------------------------
function unpromise(value, fn = x => x, error = null) {
if (value instanceof QuotedPromise) {
return fn(value);
}
if (is_promise(value)) {
var ret = value.then(function(value) {
// escape QuotedPromise because JS handle primise like objects
// like real promises and next `then` get the value
// not promise like object #153
if (value instanceof Value) {
value = value.valueOf();
}
var ret = fn(value);
if (ret instanceof QuotedPromise) {
return new Value(ret);
}
return ret;
});
var ret = value.then(fn);
if (error === null) {
return ret;
} else {
Expand Down Expand Up @@ -6523,7 +6510,11 @@
while (args.length) {
var arg = args.shift();
var name = unbox(arg);
if (name === '__code__' && is_function(object) &&
// the value was set to false to prevent resolving
// by Real Promises #153
if (name === 'then' && object instanceof QuotedPromise) {
value = QuotedPromise.prototype.then;
} else if (name === '__code__' && is_function(object) &&
typeof object.__code__ === 'undefined') {
value = native_lambda;
} else {
Expand Down

0 comments on commit 8910dd1

Please sign in to comment.