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

Check return value of define factory before setting module.exports #26

Merged
merged 4 commits into from
Dec 19, 2017

Conversation

msrose
Copy link
Owner

@msrose msrose commented Sep 24, 2017

This PR takes care of the behaviour described at the end of the readme on master.

There's no pressing reason to address this; I just want to do it for complete correctness.

I remember seeing webpack taking care of AMD by doing a check like this on the return value of the factory function, so that offers a bit of validation on the strategy used.

I've chosen to use babel's utilities for generating unique variables in scope for creating the temporary variable used. The other option is wrapping everything in another IIFE but since that adds up to one extra function call per modue at runtime, I figured generating a unique variable at compile time is a better option.

It's possible to use this pattern for every single transformation made, but doing it on a need-only basis makes updating the test suite easier. Also the output is a bit more understandable without the extra code in there, which makes debugging easier.

@captbaritone I'd appreciate your review for this. I'd also like to release a 1.0.0 after this gets merged - is there anything else you think we should take care of before doing that?

@codecov-io
Copy link

codecov-io commented Sep 24, 2017

Codecov Report

Merging #26 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #26   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           3      3           
  Lines          82     89    +7     
  Branches       23     27    +4     
=====================================
+ Hits           82     89    +7
Impacted Files Coverage Δ
src/constants.js 100% <ø> (ø) ⬆️
src/helpers.js 100% <100%> (ø) ⬆️
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ac6666...ce80445. Read the comment docs.

exports.hey = stuff.boi;
})(require, exports, module)
`,
`_${AMD_DEFINE_RESULT}`
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test depends on how babel internally generates unique variable names, which isn't great, but can't really think of another way to test this other than doing some funky regex stuff that just doesn't seem worth it.

@msrose msrose requested a review from captbaritone September 24, 2017 20:31
@msrose
Copy link
Owner Author

msrose commented Oct 27, 2017

@captbaritone just wondering if you saw this? No worries if you don't have time to review, just let me know and I'll seek an alternative :)

@captbaritone
Copy link
Collaborator

Oh! I did see it, but then I put it on a todo list and promptly forgot about that list. I'll try to take a look later today.

@captbaritone
Copy link
Collaborator

Didn't get to it this weekend, sorry.

@msrose
Copy link
Owner Author

msrose commented Oct 30, 2017

No worries :)

@captbaritone
Copy link
Collaborator

I think it's time I admitted that I'm probably not going to get to this. Sorry!

@msrose
Copy link
Owner Author

msrose commented Dec 11, 2017

No problem, going to do a bit more testing and merge, and next release will be 1.0.0 so not worried about it breaking anything for existing users :)

@msrose msrose force-pushed the define-result-check branch from bb68a11 to dbd1aa8 Compare December 19, 2017 01:33
@msrose msrose merged commit 30b95f3 into master Dec 19, 2017
@msrose msrose deleted the define-result-check branch December 19, 2017 01:53
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

Successfully merging this pull request may close these issues.

3 participants