-
Notifications
You must be signed in to change notification settings - Fork 55
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
determining if value should be treated as a CSS value or a string #70
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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.
What's
$foo
? I think this needs some explanation... what's the idea behindshouldBeStringified
? What are the criteria?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.
@pmowrer if you haven't already please read my comments starting from here: #5 (comment) - you can follow the process that led me to this solution.
The idea behind the
shouldBeStringified
function is that it attempts to determine whether a value passed toparseValue
should treated as a string and returned as"${value}"
.$foo
is just a placeholder variable we attempt to assign the non-stringified value to. If this breaks the Sass compiler, we know that Sass needs it to be a string to compile, hence we returnshouldBeStringified
as true.Been using this branch on my side project since opening it and I've had no issues - and I have a plethora of various JSON values of different types.
I'm happy to make whatever improvements you need.
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.
@pmowrer it's probably also worth you checking this out sasstools/json-importer#3
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.
It seems a bit crude to just do a
try/catch
... do we know it's backwards compatible? Would you mind summarizing your reasoning from your discussions in these other tickets?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 you elaborate on why using a
try/catch
here seems crude? It seems like an appropriate use of it to me. The only way we can know for sure if a value will compile in Sass is to simply "try" it, and "catch" whether it errors or not; that's what makes this solution so simple. We don't have to try and preempt whether a value should be returned as"${value}"
based off some logic, we can literally just try it, and catch the error before it actually happens, and then manipulate the value when needed.As far as compatibility is concerned, I am not aware of any compatibility issues with
try/catch
, at least for basic usage such as this case.I can't really summarize any more than I already have:
@xyfer said (in this thread sasstools/json-importer#3) "The inefficiency is executing Node Sass for each value in shouldBeStringified. What I was suggesting is I think there is why to achieve the same behaviour without this overhead."
So whilst the implementation of the solution may not be as efficient as it could be, the solution itself seems good, and I can't say I've noticed any significant time overhead since using it.
To be clear, my experience from this solution is that I'm able to import any valid JSON file into my Sass without it ever erroring and without any unexpected behaviour in my Sass, and without having to format my JSON in a special way.