Skip to content

Commit 19622b4

Browse files
committed
feat(importStar): Cache non‑module results
1 parent ec58992 commit 19622b4

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

tslib.es6.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,23 @@ export function __makeTemplateObject(cooked, raw) {
185185
return cooked;
186186
};
187187

188+
var __getImportStarCache = function () {
189+
if (typeof WeakMap !== "function") return null;
190+
191+
var cache = new WeakMap();
192+
__getImportStarCache = function () { return cache; }
193+
return cache;
194+
};
195+
188196
export function __importStar(mod) {
189197
if (mod && mod.__esModule) return mod;
198+
if (mod === null || (typeof mod !== "object" && typeof mod !== "function")) return { default: mod }
199+
var cache = __getImportStarCache();
200+
if (cache && cache.has(mod)) return cache.get(mod);
190201
var result = {};
191-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
202+
for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
192203
result.default = mod;
204+
if (cache) cache.set(mod, result);
193205
return result;
194206
}
195207

tslib.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,23 @@ var __importDefault;
222222
return cooked;
223223
};
224224

225+
var __getImportStarCache = function () {
226+
if (typeof WeakMap !== "function") return null;
227+
228+
var cache = new WeakMap();
229+
__getImportStarCache = function () { return cache; }
230+
return cache;
231+
};
232+
225233
__importStar = function (mod) {
226234
if (mod && mod.__esModule) return mod;
235+
if (mod === null || (typeof mod !== "object" && typeof mod !== "function")) return { "default": mod }
236+
var cache = __getImportStarCache();
237+
if (cache && cache.has(mod)) return cache.get(mod);
227238
var result = {};
228-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
239+
for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
229240
result["default"] = mod;
241+
if (cache) cache.set(mod, result);
230242
return result;
231243
};
232244

0 commit comments

Comments
 (0)