From cd43f05505ac56665ca966b0395ddc0794cf67cc Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 12 Nov 2020 17:40:06 -0800 Subject: [PATCH 1/3] Update tslib to support new __spreadArray helper --- tslib.d.ts | 3 +++ tslib.es6.js | 10 +++++++++- tslib.js | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tslib.d.ts b/tslib.d.ts index 9e43edc..3ad370a 100644 --- a/tslib.d.ts +++ b/tslib.d.ts @@ -23,8 +23,11 @@ export declare function __generator(thisArg: any, body: Function): any; export declare function __exportStar(m: any, o: any): void; export declare function __values(o: any): any; export declare function __read(o: any, n?: number): any[]; +/** @deprecated since TypeScript 4.2 */ export declare function __spread(...args: any[][]): any[]; +/** @deprecated since TypeScript 4.2 */ export declare function __spreadArrays(...args: any[][]): any[]; +export declare function __spreadArray(to: any[], from: any[]): any[]; export declare function __await(v: any): any; export declare function __asyncGenerator(thisArg: any, _arguments: any, generator: Function): any; export declare function __asyncDelegator(o: any): any; diff --git a/tslib.es6.js b/tslib.es6.js index c60aa60..f51d815 100644 --- a/tslib.es6.js +++ b/tslib.es6.js @@ -144,19 +144,27 @@ export function __read(o, n) { return ar; } +/** @deprecated */ export function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } +/** @deprecated */ export function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; -}; +} + +export function __spreadArray(to, from) { + for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) + to[j] = from[i]; + return to; +} export function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); diff --git a/tslib.js b/tslib.js index fcf619a..529c6c2 100644 --- a/tslib.js +++ b/tslib.js @@ -26,6 +26,7 @@ var __values; var __read; var __spread; var __spreadArrays; +var __spreadArray; var __await; var __asyncGenerator; var __asyncDelegator; @@ -184,12 +185,14 @@ var __createBinding; return ar; }; + /** @deprecated */ __spread = function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; + /** @deprecated */ __spreadArrays = function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) @@ -198,6 +201,12 @@ var __createBinding; return r; }; + __spreadArray = function (to, from) { + for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) + to[j] = from[i]; + return to; + }; + __await = function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }; @@ -280,6 +289,7 @@ var __createBinding; exporter("__read", __read); exporter("__spread", __spread); exporter("__spreadArrays", __spreadArrays); + exporter("__spreadArray", __spreadArray); exporter("__await", __await); exporter("__asyncGenerator", __asyncGenerator); exporter("__asyncDelegator", __asyncDelegator); From be654a5062c8eb051f1e72251c8e37f8ce6581e1 Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 18 Nov 2020 11:33:09 -0500 Subject: [PATCH 2/3] Ensure that the modules exports are validated in tests --- .github/workflows/CI.yml | 3 +++ test/validateModuleExportsMatchCommonJS/index.js | 8 +------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a020565..6114ef1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -21,3 +21,6 @@ jobs: - name: Run tests run: node ./test/runTests.js + - name: Run tests + run: node ./test/validateModuleExportsMatchCommonJS/index.js + if: matrix.node-version == '14.x' diff --git a/test/validateModuleExportsMatchCommonJS/index.js b/test/validateModuleExportsMatchCommonJS/index.js index 0c1b613..2ff703b 100644 --- a/test/validateModuleExportsMatchCommonJS/index.js +++ b/test/validateModuleExportsMatchCommonJS/index.js @@ -1,12 +1,6 @@ -// When on node 14, it validates that all of the commonjs exports +// This file can only run on node 14+, it validates that all of the commonjs exports // are correctly re-exported for es modules importers. -const nodeMajor = Number(process.version.split(".")[0].slice(1)) -if (nodeMajor < 14) { - console.log("Skipping because node does not support module exports.") - process.exit(0) -} - // ES Modules import via the ./modules folder import * as esTSLib from "../../modules/index.js" From 2c150dfa28c3e4b84c9d693007cd235e28f8d7cd Mon Sep 17 00:00:00 2001 From: Orta Date: Wed, 18 Nov 2020 11:45:22 -0500 Subject: [PATCH 3/3] Adds spreadArray to the module exports --- modules/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/index.js b/modules/index.js index d241d04..c5afe4f 100644 --- a/modules/index.js +++ b/modules/index.js @@ -14,6 +14,7 @@ const { __read, __spread, __spreadArrays, + __spreadArray, __await, __asyncGenerator, __asyncDelegator, @@ -39,6 +40,7 @@ export { __read, __spread, __spreadArrays, + __spreadArray, __await, __asyncGenerator, __asyncDelegator,