This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
Implement sass value operations and stringification #1478
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.
Brings recently added functions for sass values from libsass C-API to node-sass. I guess it was partly due to missing libsass documentation, which was not updated in this regard (until some time earlier this day). Was a pitty that so far only perl-libsass implemented them and it was pretty straight forward to do so for node.js (very first time that I'm really doing something in node.js, beside being a day time js programmer).
Each and every sass value type get these methods via their protoype:
I also hope that this may bring some value back to libsass in general, as these functions expose quite a low level API, as concatenation or equality tests are the same as libsass uses internally. One big open question is still how we gonna test the API on the libsass side. So far we rely on our implementors to add some unit test. So we pretty much need a full featured test suite for sass operation and stringification. Altough I would much better like to have this directly in libsass (so it is run with our CI), but node-sass seems a good place to get something started. Specially since @chriseppstein seems to use it himself. And I consider him the authority to know how these operations should behave. I am for the most part just reverse engineering the existing 😄 Anyway, that would be one long-term goal here.
On the other hand they are also usefull for end users. Unfortunately it looks that v8 has decided to not support any kind of custom operator overloading. The closest thing I could find in this direction is a patch that looks to come from QT. Not a compelling sign, and all other sources point to "no, can't do". So the next best thing is probably to use methods (I mean the language even has java in its name, so ...).
I figured this could go two ways. Either have multiple methods for each operation: a bit more well defined but cluttering the prototype. Use only one method with switch argument: the string argument feels a bit quirky but works and also adds some versatility (can easly be stored/passed). The first idea could also be implemented around the second approach.
Also not 100% sure if a node.js library should overload
toString
. But I don't see why we shouldn't do that for our own custom objects, until you need it for some ubique equality test. Didn't bother to add any documentation up to this point as I first want to gather some feedback!