Skip to content

Commit

Permalink
feat(importStar): Cache non‑module results
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Oct 24, 2019
1 parent ec58992 commit 19622b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion tslib.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,23 @@ export function __makeTemplateObject(cooked, raw) {
return cooked;
};

var __getImportStarCache = function () {
if (typeof WeakMap !== "function") return null;

var cache = new WeakMap();
__getImportStarCache = function () { return cache; }
return cache;
};

export function __importStar(mod) {
if (mod && mod.__esModule) return mod;
if (mod === null || (typeof mod !== "object" && typeof mod !== "function")) return { default: mod }
var cache = __getImportStarCache();
if (cache && cache.has(mod)) return cache.get(mod);
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
if (cache) cache.set(mod, result);
return result;
}

Expand Down
14 changes: 13 additions & 1 deletion tslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,23 @@ var __importDefault;
return cooked;
};

var __getImportStarCache = function () {
if (typeof WeakMap !== "function") return null;

var cache = new WeakMap();
__getImportStarCache = function () { return cache; }
return cache;
};

__importStar = function (mod) {
if (mod && mod.__esModule) return mod;
if (mod === null || (typeof mod !== "object" && typeof mod !== "function")) return { "default": mod }
var cache = __getImportStarCache();
if (cache && cache.has(mod)) return cache.get(mod);
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (cache) cache.set(mod, result);
return result;
};

Expand Down

0 comments on commit 19622b4

Please sign in to comment.