This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Render options in callbacks as this.options #686
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we just say
error.call(options, ...)
and removeoptions.context
?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.
I don't think that would be a good idea. It would paint us into a bit of a corner if we need to surface any additional environment information from libsass or node-sass to callbacks.
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.
Since we are not cloning
options
oncontext
instantiation, I think one problem with this approach would be the shallow copy dropping functions definitions (importer
et al.).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.
I'm sorry @am11, I don't think I understand here. I wrote a test locally to see if anything was being dropped from the options object or we were somehow losing our function definitions.
Because we are mutating objects by reference, everything seems to arrive as expected in the callbacks. Should I change something in the above test to capture your concerns? Thanks!
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.
Oh nice! I thought it will drop those. Thanks for the example! (we can add this test to the mix as well) 👍
Separately, are you suggesting if we drop
options.context
, then any new member tooptions
set by node-sass will be lost in callbacks? Can you please provide a concrete example for this, which shows that it will fail on some account in case we drop.call(options.context, ...)
in favour of.call(options, ...)
?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.
Sure.
I'm worried about the case where we write this as
importer.call(options, ...)
. For this, options such asfile
will be accessible asthis.file
. It will work as long both libsass and node-sass do not need to share any additional information with custom importers and functions.In ruby-sass which libsass seeks parity with, there is a concept of a global environment. I can see us providing this in a more node-like way as opposed to the ruby pattern of creating a global. If we are currently binding to
options
, then we would be unable to add this environment information without a breaking change (as references tothis.file
would suddenly fail). Thecontext
object fulfills this role, allowing us to later add environment information{ options: options, env: getEnvironment() }
without breaking anyone's code.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.
Thanks and points for future consideration. 👍
TBH, I haven't delve into global environment, I cannot say for a fact whether it will land in libsass world or not. Maybe @xzyfer can confirm it.
However, I do think that it will not break the user code in this case even if global environment is introduced in libsass. This is because whatever libsass is sharing with node-sass, it arrives via the binding layer which uses v8 lib (via nan wrapper). That allows us to assign / inject any object to a
persistent
(v8 terminology) JS object. So this sharing with custom imports or functions is taken care by the binding code, where we can alter the state of other objects in the current loop (libuv'suv_loop
).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.
Either way it does not hurt to keep the context. If you can rebase out the package.json change, we can merge this. :)