Add __createBinding and __setModuleDefault helpers#89
Add __createBinding and __setModuleDefault helpers#89
Conversation
|
cc @rbuckton do you have any feedback here, too? |
tslib.js
Outdated
| exporter("__classPrivateFieldGet", __classPrivateFieldGet); | ||
| exporter("__classPrivateFieldSet", __classPrivateFieldSet); | ||
| exporter("__createBinding", __createBinding); | ||
| exporter("__setModuleDefault", __setModuleDefault) |
There was a problem hiding this comment.
I'm not sure this actually needs to be exposed, since no TypeScript code will emit tslib_1.__setModuleDefault (since its only used by __importStar).
… directly referenced
ExE-Boss
left a comment
There was a problem hiding this comment.
You forgot to remove __setModuleDefault from one more location.
| var __classPrivateFieldGet; | ||
| var __classPrivateFieldSet; | ||
| var __createBinding; | ||
| var __setModuleDefault; |
There was a problem hiding this comment.
| var __setModuleDefault; |
| o[k2] = m[k]; | ||
| }); | ||
|
|
||
| __setModuleDefault = Object.create ? (function(o, v) { |
There was a problem hiding this comment.
| __setModuleDefault = Object.create ? (function(o, v) { | |
| var __setModuleDefault = Object.create ? (function(o, v) { |
| 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; |
There was a problem hiding this comment.
This should probably be:
| 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
| 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; |
|
|
||
| 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); |
There was a problem hiding this comment.
exports.hasOwnProperty(p) won’t work in case exports has a null prototype or has overridden hasOwnProperty(…): microsoft/TypeScript#37013 and #92.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
That said, we do call Object.hasOwnProperty.call in __importStar below this.
Mmmm yes and no - the helper TS emits without |
We could always change that to the way that we define |
|
#99 now includes this, plus feedback~ |
This is the
tslibPR for microsoft/TypeScript#35967