-
Notifications
You must be signed in to change notification settings - Fork 28
Fix for issue #13: Stylesheet paths are not always relative #14
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
Conversation
I'm not clear on what the problem and what the fix does. Also, is there anyway to add tests for this? |
Sure thing. I've just added a test that hopefully explains the issue. (Take out JSON.parse/JSON.stringify in index.js to see the test fail.) I'm personally not sure how on how to add a test that in effect says, "also don't do this other thing that was never expected in the first place," but for now I've just added it as a second test case with its own fixtures. I welcome any suggestions on how to do this better. |
return through.obj(function (file, enc, cb) { | ||
opt = opt || {}; | ||
var opt = JSON.parse(JSON.stringify(main_opt || {})); | ||
|
||
// 'url' option is required | ||
// set it automatically if not provided |
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.
Line 12 mutates opt
. Because opt was scoped to the exported module itself and not to each call of that module, the first call will mutate the opt.url
and the second call will never care about file.path
. This change fixes that by keeping main_opt
distinct from opt
and cloning it rather than mutating a reference.
Ah, I see what the issue is. Thanks for pointing that out. I don't see the need to immediately stringify and then parse the args. Why did you add that? |
JSON.parse(JSON.stringify(object)) is just the 5-cent way to clone an object in JavaScript. Objects are passed by reference, so if I do:
...you will see that foo.a is not 2, because
...and I would be happy to do that here instead if you prefer. |
Ok. Please squash the commits. Then I'll merge it. |
Thanks for tracking this down and providing a fix. This issue has been resolved outside of this PR however, so this is no longer needed. Closing. |
Ah, sorry I forgot to get to it. Thanks for closing! |
No description provided.