-
Notifications
You must be signed in to change notification settings - Fork 142
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
Single-layer property replacement is inappropriate for ES modules #262
Labels
Comments
Here's some pseudocode for what I'm thinking. This'll be a new freshly-driven If we do it right, it will:
Psuedocomments export default (original, target, encounteredObjects = []) => {
// 1. function, object, and constructor all immediately bail out to imitiate after creating their top-level thing (func, empty obj, func, respectively)
// 2. guard: return original if not isObjectLike or isFunction
// 2a. guard: return original if already encounteredObjects includes it
// 3. gather all props on original
// 4. copy all props to target
// 5. for each prop:
// - if isConstructor, call constructor()
// - else if function call function()
// - else empty {}
// - call self(prop, +that new thing, encounteredObjects.concat(original)
} |
10 tasks
Landed in 3.2.0 |
searls
added a commit
that referenced
this issue
Jul 21, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RIght now,
td.replace
'd CJS modules enjoy a single-layer of additional properties (say, a function with other static functions as properties) being faked along with the top-level export.This is incongruent with ES modules, because that first layer of replacements typically is just enough to cover the
default
property on the exported object (which is how transpilers translate those imports to CJS), which means the same module will be faked differently if all a person does is convert it a CJS module to an ES module.Going forward I think we need to do one of two things:
default
Option 2 is probably more appropriate for simplicity & consistency sake, but it also runs the risk of encouraging folks to return deeply-nested mocks, which is separately a little worrying. That said, even that would be better than the current state: accidentally returning people partial mocks that have some properties that are still real (or missing)
The text was updated successfully, but these errors were encountered: