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/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, 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" 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 bae9845..bd73dce 100644 --- a/tslib.es6.js +++ b/tslib.es6.js @@ -146,19 +146,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 b56c529..4e2462e 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; @@ -186,12 +187,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++) @@ -200,6 +203,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); }; @@ -282,6 +291,7 @@ var __createBinding; exporter("__read", __read); exporter("__spread", __spread); exporter("__spreadArrays", __spreadArrays); + exporter("__spreadArray", __spreadArray); exporter("__await", __await); exporter("__asyncGenerator", __asyncGenerator); exporter("__asyncDelegator", __asyncDelegator);