From 3348b1a6117be25ac3ecaba78ee24d2dfc9e1bb6 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Wed, 7 Feb 2024 10:57:01 +0700 Subject: [PATCH] move `Promise.try` to stage 2 --- CHANGELOG.md | 1 + README.md | 49 +++++++++++++++++++------------------ packages/core-js/stage/1.js | 1 - packages/core-js/stage/2.js | 1 + 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f59692ab4473..35f8ce39937b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Changelog ##### Unreleased +- [`Promise.try` proposal](https://github.com/tc39/proposal-promise-try) has been resurrected and [moved to stage 2](https://github.com/tc39/proposal-promise-try/issues/15) - Fixed regression in `Set#intersection` feature detection - Fixed a missed check in `Array#{ indexOf, lastIndexOf, includes }`, [#1325](https://github.com/zloirock/core-js/issues/1325), thanks [**@minseok-choe**](https://github.com/minseok-choe) - Fixed a missed check in `Array#{ reduce, reduceRight }`, [#1327](https://github.com/zloirock/core-js/issues/1327), thanks [**@minseok-choe**](https://github.com/minseok-choe) diff --git a/README.md b/README.md index 4629c6535e17..246464c7e889 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3]) - [`Array.isTemplateObject`](#arrayistemplateobject) - [`String.dedent`](#stringdedent) - [`RegExp` escaping](#regexp-escaping) + - [`Promise.try`](#promisetry) - [`Symbol` predicates](#symbol-predicates) - [`Uint8Array` to / from base64 and hex](#uint8array-to-from-base64-and-hex) - [Stage 1 proposals](#stage-1-proposals) @@ -178,7 +179,6 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3]) - [`compositeKey` and `compositeSymbol`](#compositekey-and-compositesymbol) - [`Array` filtering](#array-filtering) - [`Array` deduplication](#array-deduplication) - - [`Promise.try`](#promisetry) - [`DataView` get / set `Uint8Clamped` methods](#dataview-get-set-iint8clamped-methods) - [`Number.fromString`](#numberfromstring) - [`Math` extensions](#math-extensions) @@ -2680,6 +2680,30 @@ console.log(RegExp.escape('10$')); // => '\\x310\\$' console.log(RegExp.escape('abcdefg_123456')); // => 'abcdefg_123456' console.log(RegExp.escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`')); // => '\\(\\)\\{\\}\\[\\]\\|\\,\\.\\?\\*\\+\\-\\^\\$\\=\\<\\>\\\\\\/\\#\\&\\!\\%\\:\\;\\@\\~\\\'\\"\\`' ``` + +##### [`Promise.try`](https://github.com/tc39/proposal-promise-try) +Module [`esnext.promise.try`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.promise.try.js) +```js +class Promise { + static try(callbackfn: Function): Promise; +} +``` +[*CommonJS entry points:*](#commonjs-api) +```js +core-js/proposals/promise-try +core-js(-pure)/full/promise/try +``` +[*Examples*](https://goo.gl/k5GGRo): +```js +Promise.try(() => 42).then(it => console.log(`Promise, resolved as ${it}`)); + +Promise.try(() => { throw 42; }).catch(it => console.log(`Promise, rejected as ${it}`)); + +Promise.try(async () => 42).then(it => console.log(`Promise, resolved as ${it}`)); + +Promise.try(async () => { throw 42; }).catch(it => console.log(`Promise, rejected as ${it}`)); +``` + ##### [`Symbol` predicates](https://github.com/tc39/proposal-symbol-predicates)[⬆](#index) Modules [`esnext.symbol.is-registered-symbol`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.is-registered-symbol.js), [`esnext.symbol.is-well-known-symbol`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.is-well-known-symbol.js). ```js @@ -2952,29 +2976,6 @@ core-js/full/typed-array/unique-by ].uniqueBy(it => it.uid); // => [{ id: 1, uid: 10000 }, { id: 3, uid: 10001 }] ``` -##### [`Promise.try`](https://github.com/tc39/proposal-promise-try) -Module [`esnext.promise.try`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.promise.try.js) -```js -class Promise { - static try(callbackfn: Function): Promise; -} -``` -[*CommonJS entry points:*](#commonjs-api) -```js -core-js/proposals/promise-try -core-js(-pure)/full/promise/try -``` -[*Examples*](https://goo.gl/k5GGRo): -```js -Promise.try(() => 42).then(it => console.log(`Promise, resolved as ${it}`)); - -Promise.try(() => { throw 42; }).catch(it => console.log(`Promise, rejected as ${it}`)); - -Promise.try(async () => 42).then(it => console.log(`Promise, resolved as ${it}`)); - -Promise.try(async () => { throw 42; }).catch(it => console.log(`Promise, rejected as ${it}`)); -``` - ##### [`DataView` get / set `Uint8Clamped` methods](https://github.com/tc39/proposal-dataview-get-set-uint8clamped)[⬆](#index) Modules [`esnext.data-view.get-uint8-clamped`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.data-view.get-uint8-clamped.js) and [`esnext.data-view.set-uint8-clamped`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.data-view.set-uint8-clamped.js) ```js diff --git a/packages/core-js/stage/1.js b/packages/core-js/stage/1.js index 86010e6e6dda..eb2371ea872b 100644 --- a/packages/core-js/stage/1.js +++ b/packages/core-js/stage/1.js @@ -14,7 +14,6 @@ require('../proposals/number-from-string'); require('../proposals/object-iteration'); require('../proposals/observable'); require('../proposals/pattern-matching'); -require('../proposals/promise-try'); require('../proposals/seeded-random'); require('../proposals/string-code-points'); require('../proposals/string-cooked'); diff --git a/packages/core-js/stage/2.js b/packages/core-js/stage/2.js index 18a0f73af914..cb32a447d776 100644 --- a/packages/core-js/stage/2.js +++ b/packages/core-js/stage/2.js @@ -6,6 +6,7 @@ require('../proposals/array-is-template-object'); require('../proposals/async-iterator-helpers'); require('../proposals/iterator-range'); require('../proposals/map-upsert-stage-2'); +require('../proposals/promise-try'); require('../proposals/regexp-escaping'); require('../proposals/string-dedent'); require('../proposals/symbol-predicates-v2');