Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __createBinding and __setModuleDefault helpers #89

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: WeakMap<T, V>): V;
export declare function __classPrivateFieldSet<T extends object, V>(receiver: T, privateMap: WeakMap<T, V>, value: V): V;
export declare function __createBinding(t: any, mod: any, k: string, k2?: string): void;
Copy link
Contributor

@ExE-Boss ExE-Boss Feb 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be:

Suggested change
export declare function __createBinding(t: any, mod: any, k: string, k2?: string): void;
export declare function __createBinding(t: object, mod: object, k: string, k2?: string): void;

or

Suggested change
export declare function __createBinding(t: any, mod: any, k: string, k2?: string): void;
export declare function __createBinding(t: object, mod: object, k: PropertyKey, k2?: PropertyKey): void;

26 changes: 23 additions & 3 deletions tslib.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function __generator(thisArg, body) {
}

export function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
for (var p in m) if (!exports.hasOwnProperty(p)) __createBinding(exports, m, p);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exports.hasOwnProperty(p) won’t work in case exports has a null prototype or has overridden hasOwnProperty(…): microsoft/TypeScript#37013 and #92.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably get in the habit of saving off intrinsics like this (i.e. var hasOwn = Object.prototype.hasOwnProperty and hasOwn.call(exports, p)), but we don't necessarily want to have to introduce a __hasOwn helper for that kind of case.

That said, its up to @weswigham if he wants to take on that change for tslib right now, since it's out of scope for this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, we do call Object.hasOwnProperty.call in __importStar below this.

}

export function __values(o) {
Expand Down Expand Up @@ -188,8 +188,8 @@ export function __makeTemplateObject(cooked, raw) {
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);
__setModuleDefault(result, mod);
return result;
}

Expand All @@ -211,3 +211,23 @@ export function __classPrivateFieldSet(receiver, privateMap, value) {
privateMap.set(receiver, value);
return value;
}

export const __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];
});

const __setModuleDefault = Object.create ? (function(o, v) {
Object.defineProperty(o, "default", {
enumerable: true,
value: v
});
}) : function(o, v) {
o["default"] = v;
};
29 changes: 26 additions & 3 deletions tslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var __importStar;
var __importDefault;
var __classPrivateFieldGet;
var __classPrivateFieldSet;
var __createBinding;
var __setModuleDefault;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var __setModuleDefault;

(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 @@ -143,7 +145,7 @@ var __classPrivateFieldSet;
};

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

__values = function (o) {
Expand Down Expand Up @@ -227,8 +229,8 @@ var __classPrivateFieldSet;
__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 All @@ -251,6 +253,26 @@ var __classPrivateFieldSet;
return value;
}

__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];
});

__setModuleDefault = Object.create ? (function(o, v) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__setModuleDefault = Object.create ? (function(o, v) {
var __setModuleDefault = Object.create ? (function(o, v) {

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

exporter("__extends", __extends);
exporter("__assign", __assign);
exporter("__rest", __rest);
Expand All @@ -273,4 +295,5 @@ var __classPrivateFieldSet;
exporter("__importDefault", __importDefault);
exporter("__classPrivateFieldGet", __classPrivateFieldGet);
exporter("__classPrivateFieldSet", __classPrivateFieldSet);
exporter("__createBinding", __createBinding);
});