Uh oh!
There was an error while loading. Please reload this page.
Bugfix/require module regexp - #368
Conversation
* handle cases where space occurs before, after and on either side of dep
amasad
commented
Mar 28, 2015
Awesome, thanks! |
tadeuzagallo
commented
Mar 28, 2015
I think the regex should be /\brequire\s*?\(\s*?([\'"])([^"\']+)\1\s*?\)/gand then code.replace(REL_REQUIRE_STMT,function(codeMatch,_,depName){Even before this diff it already accepted |
daviskoh
commented
Mar 28, 2015
👍 updated |
amasad
commented
Mar 28, 2015
If you updated this, let's update the one in DependencyGraph/index.js as well. Ideally let's export it from DependencyGraph as a a constant to be used here |
daviskoh
commented
Mar 28, 2015
Hmm. Maybe I am missing something, but I am facing some issues when I try to export the requireRe regex from DependencyGraph and into DependencyResolver. I changed the requireRe in the DependencyGraph to Then changed the exports Then in the DependencyResolver/index.js The requireRe regex does not seem to be importing properly as you can see in the Jest output. I will keep digging into this. Any help would be appreciated as well! |
daviskoh
commented
Mar 28, 2015
I changed the requireRe in the DependencyGraph to match REL_REQUIRE_STMT. As noted above, I was having issues when I tried to import regex into the DependencyResolver. As @amasad said, ideally we would export the const, however in the meantime this should provide a fix for the whitespace issues. I can submit another PR later exporting the requireRe when I can look at this code more objectively than I can now. What do you think? |
amasad
commented
Mar 28, 2015
That's strange, maybe the problem is with jest console.log. Can you try |
daviskoh
commented
Mar 28, 2015
This is the output from DependencyResolver/index.js: It does not seem limited to importing from DependencyGraph either. I tried creating a dummy file that exports only that regex and I get the same issue. I also tried exporting some simple regex: but it seems to get imported as as well. T.T |
daviskoh
commented
Mar 28, 2015
* don't mock regex.js in jest tests
daviskoh
commented
Mar 30, 2015
The issue was related to how Jest seems to auto-mock its dependencies (though I am not too familiar w/ Jest). When I tried to export the regex, jest would try to mock it and resulting in that strange looking regex that broke unit tests (even when I tried mocking it as a function that returns the regex). However, I tested the regex exporting manually and it was working just fine. I decided that the regex value should not be mocked in the unit tests. However, keeping this value inside the DependencyGraph/index.js was problematic as we still want to mock the rest of the DependencyGraph when testing the HasteDependencyResolver. Thus, I decided to move the regex value into a separate file that gets imported by both DependencyGraph/index.js & DependencyResolver/index.js allowing me to prevent the value from being mocked using jest.dontMock. I named it regex.js as I thought there may be other regex where sharing across files is desired. The shared regex is now successfully exported and the unit tests are now passing. @amasad thoughts? |
pilwon
commented
Mar 31, 2015
Related to #386 |
amasad
commented
Mar 31, 2015
That looks good, I'll pull it. |
daviskoh
commented
Mar 31, 2015
👍 |
pilwon
commented
Apr 1, 2015
Do we really need to force convert quotation style ( |
amasad
commented
Apr 1, 2015
@pilwon why do you care about generated code? |
pilwon
commented
Apr 1, 2015
@amasad I agree it doesn't matter for code that is never meant to be read by humans. I imagined more potential complex case similar to and developed from how I implemented #386. The original code passes through multiple replace steps until it reaches the final relativized code. The complexity in this replace pipeline could potentially grow (though it's highly unlikely beyond supporting |
amasad
commented
Apr 1, 2015
OK, this already landed internally though. @pilwon you can fix it in your "import" syntax pull requests because I haven't looked at it yet. |
daviskoh
commented
Apr 1, 2015
Hmm...that explains the merge conflicts lol. I guess there must be a problem w/ Legal when taking PR's from random internet guys ☔ hehe |
pilwon
commented
Apr 1, 2015
@amasad |
sahrens
commented
Apr 1, 2015
Merged internally and synced. |
Summary: Resolvesreact/react-native#316. Also updated the spec for the Haste Dependency Resolver. Not sure if these changes are the ones desired so feedback would be welcome! Closesreact/react-native#368 Github Author: daviskoh <koh.davis.0@gmail.com> Test Plan: ./runJestTests



Resolves#316. Also updated the spec for the Haste Dependency Resolver. Not sure if these changes are the ones desired so feedback would be welcome!