Skip to content

Commit

Permalink
Update helpers for TS 3.9 (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed May 5, 2020
1 parent 3d93421 commit 6975099
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions tslib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ export declare function __importStar<T>(mod: T): T;
export declare function __importDefault<T>(mod: T): T | { default: T };
export declare function __classPrivateFieldGet<T extends object, V>(receiver: T, privateMap: { has(o: T): boolean, get(o: T): V | undefined }): V;
export declare function __classPrivateFieldSet<T extends object, V>(receiver: T, privateMap: { has(o: T): boolean, set(o: T, value: V): any }, value: V): V;
export declare function __createBinding(object: object, target: object, key: PropertyKey, objectKey?: PropertyKey);
20 changes: 17 additions & 3 deletions tslib.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,16 @@ export function __generator(thisArg, body) {
}
}

export const __createBinding = Object.create ? (function(o, m, k, k2) {

This comment has been minimized.

Copy link
@timocov

timocov May 13, 2020

Hey @weswigham @DanielRosenwasser shouldn't it be var instead? The same as export var __assign

This comment has been minimized.

Copy link
@weswigham

weswigham May 13, 2020

Author Member

Since we don't reassign it within the file, it honestly doesn't matter much, afaik. But there is a consistency argument to be had, I suppose.

This comment has been minimized.

Copy link
@HolgerJeromin

HolgerJeromin May 13, 2020

IMHO it does matter for browsers which does not support modern features like let and const. which is the whole point of this file.

This comment has been minimized.

Copy link
@weswigham

weswigham May 13, 2020

Author Member

Eh? This is the .es6 file. It assumes the presence of es6 features in many cases and uses module syntax. The other file is the compat file, not this one.

This comment has been minimized.

Copy link
@DanielRosenwasser

DanielRosenwasser May 13, 2020

Member

The point is one uses ES modules, the other is UMD - and the purpose for the separation was for bundlers. It's not about other ES syntax because otherwise many of these helpers wouldn't even be in the ES6 file, or they would use arrow functions and the like.

So the short story is that at least for the near future we're switching these to var so that they can work with older tools like Uglify.

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});

export function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
}

export function __values(o) {
Expand Down Expand Up @@ -185,11 +193,17 @@ export function __makeTemplateObject(cooked, raw) {
return cooked;
};

const __setModuleDefault = Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
};

export function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);

This comment has been minimized.

Copy link
@twtaylorbitgo

twtaylorbitgo May 12, 2020

an if, for and if statement on the same line? That's fairly ugly

__setModuleDefault(result, mod);
return result;
}

Expand Down
26 changes: 21 additions & 5 deletions tslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var __importStar;
var __importDefault;
var __classPrivateFieldGet;
var __classPrivateFieldSet;
var __createBinding;
(function (factory) {
var root = typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : {};
if (typeof define === "function" && define.amd) {
Expand Down Expand Up @@ -142,9 +143,17 @@ var __classPrivateFieldSet;
}
};

__exportStar = function (m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
};
__exportStar = function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
}

__createBinding = Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
});

__values = function (o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
Expand Down Expand Up @@ -224,11 +233,17 @@ var __classPrivateFieldSet;
return cooked;
};

var __setModuleDefault = Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
};

__importStar = function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};

Expand Down Expand Up @@ -260,6 +275,7 @@ var __classPrivateFieldSet;
exporter("__awaiter", __awaiter);
exporter("__generator", __generator);
exporter("__exportStar", __exportStar);
exporter("__createBinding", __createBinding);
exporter("__values", __values);
exporter("__read", __read);
exporter("__spread", __spread);
Expand Down

0 comments on commit 6975099

Please sign in to comment.