-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
refactor(interface): Use default export for implementation #141
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,52 @@ const namedSetNew = Symbol("named property set new"); | |
const namedSetExisting = Symbol("named property set existing"); | ||
const namedDelete = Symbol("named property delete"); | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not interested in this addition. Please remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which? The JSDoc or the entire There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The importStar function itself. |
||
* Used to cache importStar results. | ||
*/ | ||
const importStarCache = new WeakMap(); | ||
|
||
/** | ||
* Mostly copied from TypeScript and Babel. | ||
* | ||
* @template T | ||
* @param {T} obj | ||
* @return {T extends { default: any } | ||
* ? T : T extends string | number | bigint | boolean | symbol | null | undefined | ||
* ? { default: T } : { default: T } & { [K in keyof T]: T[K] }} | ||
*/ | ||
function importStar(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj; | ||
} | ||
|
||
if (obj === null || (typeof obj !== "object" && typeof obj !== "function")) { | ||
return { default: obj }; | ||
} | ||
|
||
if (importStarCache.has(obj)) { | ||
return importStarCache.get(obj); | ||
} | ||
|
||
const newObj = {}; | ||
|
||
for (const key in obj) { | ||
if (hasOwn(obj, key) && key !== "default") { | ||
Object.defineProperty( | ||
newObj, | ||
key, | ||
Object.getOwnPropertyDescriptor(obj, key) | ||
); | ||
} | ||
} | ||
|
||
newObj.default = obj; | ||
|
||
importStarCache.set(obj, newObj); | ||
|
||
return newObj; | ||
} | ||
|
||
module.exports = exports = { | ||
isObject, | ||
hasOwn, | ||
|
@@ -97,5 +143,6 @@ module.exports = exports = { | |
namedGet, | ||
namedSetNew, | ||
namedSetExisting, | ||
namedDelete | ||
namedDelete, | ||
importStar | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true; jsdom only operates on CommonJS modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you do need to transpile ES2015 modules to be able to use them in Node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That is not a supported scenario, so please remove it.