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

Distinguish between quoted and unquoted strings #10

Open
h-3-0 opened this issue Feb 27, 2018 · 2 comments
Open

Distinguish between quoted and unquoted strings #10

h-3-0 opened this issue Feb 27, 2018 · 2 comments

Comments

@h-3-0
Copy link
Contributor

h-3-0 commented Feb 27, 2018

Say that I have the function foo and the following sass

h1::before {
    content: foo()
}

What might I want foo to return? I either want what libsass considers to be an unquoted string, e.g. open-quote, or a quoted string, e.g. 'foo'.

Similarly, if a function takes a string as a parameter, it should be able to distinguish between foo(foo) and foo('foo').

Mirroring how libsass works (where quoted is a boolean field of Sass_String), I'm thinking of adding a parameter to the SassString data constructor like so

data SassValue = SassString Quoted String
    ...
    
data Quoted = Quoted | Unquoted

and adding support for this in hlibsass.

@jakubfijalkowski
Copy link
Owner

I'm trying to remember why I decided to ignore the quoted/unquoted distinction, because I do remember that I wasn't sure what to do about it. My only guess is that I haven't seen any valid usage for unquoted strings, especially at hsass level. I still don't get what the difference is, but I don't do front-end dev much these days, so could you point me to some explanation or explain me what is the benefit of using unquoted strings over quoted ones?

@h-3-0
Copy link
Contributor Author

h-3-0 commented Mar 16, 2018

On the CSS side of things,

h1::before {
    content: open-quote
}

and

h1::before {
    content: 'open-quote'
}

mean different things (the first places open quotes before headings, the second literally prefixes headings with the string 'open-quote'). That was my motivation in creating this issue.

However, I misunderstood how libsass actually works. I've tested it now — the boring details are here. This behaviour might be familiar to you, but to summarise, a function taking a string can only determine if it is quoted by inspecting the quoted field. But when returning a string, the quoted field seems not to matter, and libsass will render the string exactly according to its value (so sass_make_qstring("open-quote") is rendered without quotes). Confusing, unless I'm missing something!

So, for the user of hsass, you can effectively produce quoted and unquoted strings, but you can't tell if a string that you're consuming is quoted or not. I don't actually have a use case for determining if a function's argument is quoted or not, so I don't mind if you consider this behaviour acceptable and close the issue.

It would still be possible to make this more consistant on the hsass/hlibsass side of things (I'd be tempted to define data SassValue = SassString String | SassKeyword String | ... since I think string vs. keyword is more clear than quoted string vs. unquoted string) but it would mean less closely mirroring the way libsass works. I don't know if that would be an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants