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

When injecting a falsey export, it shouldn't fall back to real module #15

Closed
Aaronius opened this issue Aug 25, 2016 · 6 comments
Closed

Comments

@Aaronius
Copy link
Contributor

In one of my tests, I wish to inject an falsey export. That is, I want to see what module A does when it requires module B and module B exports undefined, null, or false. Unfortunately, inject-loader outputs something like this:

var visitorIdInstance = (injections['../sharedModules/mcidInstance'] || __webpack_require__(47));

Given that the injection is falsey, it doesn't use my injection and instead uses the real module which makes my test useless.

@Aaronius
Copy link
Contributor Author

@plasticine would you be open to a PR for this? I'm thinking of changing this line:

src.replace(regex, "(injections[$1] || $&)"),

src.replace(regex, "(injections[$1] || $&)"),

to something like:

src.replace(regex, "(injections.hasOwnProperty($1) ? injections[$1] : $&)"),

@Aaronius
Copy link
Contributor Author

@plasticine I could really use this, but it was released as part of 3.x which is blocked due to #18. How can we help? Do you need a PR or something?

@Aaronius
Copy link
Contributor Author

Aaronius commented Oct 13, 2017

@plasticine this is broken again in 3.x. The output in 3.x looks like:

...
	  function __getInjection(dependency) {
	    return __injections.hasOwnProperty(dependency) ? __injections[dependency] : null;
	  }

	  (function () {
	    var mcidInstance = __getInjection("../sharedModules/mcidInstance") || __webpack_require__(4); /**
...

So even though __getInjection returns null, || __webpack_require__(4); overrides it anyway.

@plasticine
Copy link
Owner

@Aaronius Hrm—yeah looks like we might’ve regressed this in the re-write to using Babel to parse modules, which happened in 3.x.

Could I get you to raise a new issue and I’ll try and tackle it soon.

@Aaronius
Copy link
Contributor Author

Sure! If I get a moment I might try tackling it myself.

@plasticine
Copy link
Owner

plasticine commented Oct 13, 2017

Sure! If I get a moment I might try tackling it myself.

@Aaronius That would be amazing 💖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants