Skip to content

Commit 27c4b32

Browse files
committed
feat(importStar): Cache non‑module results
1 parent 54a056a commit 27c4b32

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

tslib.es6.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,20 @@ var __setModuleDefault = Object.create ? (function(o, v) {
209209
o["default"] = v;
210210
};
211211

212-
export function __importStar(mod) {
213-
if (mod && mod.__esModule) return mod;
214-
var result = {};
215-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
216-
__setModuleDefault(result, mod);
217-
return result;
218-
}
212+
export var __importStar = function (mod) {
213+
var cache = typeof WeakMap === "function" ? new WeakMap() : null;
214+
__importStar = function (mod) {
215+
if (mod === null || (typeof mod !== "object" && typeof mod !== "function")) return { default: mod };
216+
if (mod.__esModule) return mod;
217+
if (cache && cache.has(mod)) return cache.get(mod);
218+
var result = {};
219+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
220+
__setModuleDefault(result, mod);
221+
if (cache) cache.set(mod, result);
222+
return result;
223+
}
224+
return __importStar(mod);
225+
};
219226

220227
export function __importDefault(mod) {
221228
return (mod && mod.__esModule) ? mod : { default: mod };

tslib.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,18 @@ var __createBinding;
251251
};
252252

253253
__importStar = function (mod) {
254-
if (mod && mod.__esModule) return mod;
255-
var result = {};
256-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
257-
__setModuleDefault(result, mod);
258-
return result;
254+
var cache = typeof WeakMap === "function" ? new WeakMap() : null;
255+
__importStar = function (mod) {
256+
if (mod === null || (typeof mod !== "object" && typeof mod !== "function")) return { default: mod };
257+
if (mod.__esModule) return mod;
258+
if (cache && cache.has(mod)) return cache.get(mod);
259+
var result = {};
260+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
261+
__setModuleDefault(result, mod);
262+
if (cache) cache.set(mod, result);
263+
return result;
264+
}
265+
return __importStar(mod);
259266
};
260267

261268
__importDefault = function (mod) {

0 commit comments

Comments
 (0)