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

Undefined variables results in the rule just not being outputted #34

Closed
sunjay opened this issue Jan 18, 2019 · 6 comments
Closed

Undefined variables results in the rule just not being outputted #34

sunjay opened this issue Jan 18, 2019 · 6 comments

Comments

@sunjay
Copy link

sunjay commented Jan 18, 2019

Thanks for working on this crate!

This is a case where I would expect an error to be produced, but instead I just get nothing at all.

Here's an example program with rsass 0.9.6 and Rust 1.32.0:

fn main() {
    println!("{:?}", rsass::compile_scss(b"h1 { color: #fff; }", rsass::OutputStyle::Expanded));
    println!("{:?}", rsass::compile_scss(b"h1 { color: $does-not-exist; }", rsass::OutputStyle::Expanded));
}

It prints:

Ok([104, 49, 32, 123, 10, 32, 32, 99, 111, 108, 111, 114, 58, 32, 35, 102, 102, 102, 59, 10, 125, 10])
Ok([])

Despite the $does-not-exist variable not being defined, I get no error. The rule just isn't produced.

I would really like it if errors like this were made part of the Error enum so I could handle them properly instead of being surprized when things suddenly don't work because of something like this. If ignoring malformed rules is expected behaviour, it would be nice to at least make that configurable in case that isn't desired.

@kaj
Copy link
Owner

kaj commented Jan 20, 2019

The "not being printed" part is because sass considers a property being set to a null value being equivalent to a property not being set at all, and an empty rule should not be printed. So that part reflects the specification.

I agree that having an error returned when trying to use an undefined variable would be helpfull, but I'm afraid it would go against the sass specification. Or would it? The first step here should probably be to find an example of an undefined variable in the sass specification test suite, then we "just" have to make sure that rsass passes that test ...

Maybe the proper thing to do would be to print a warning?

@sunjay
Copy link
Author

sunjay commented Jan 20, 2019

I found a couple of tests here: https://github.com/sass/sass-spec/search?q=undefined+variable

It does seem to be an error case when a variable ends up undefined.

@sunjay
Copy link
Author

sunjay commented Jan 20, 2019

I also checked with several of the existing implementations and they all appear to produce errors for when a variable is not defined.

@kaj
Copy link
Owner

kaj commented Jan 20, 2019

Great, then rsass should indeed also produce an error on use of an undefined variable. Do you want to write the changes?

Note: the automatic test-converter spectest.rs won't be able to convert these tests, as it don't handle any tests with expected errors. Instead, a manual test will have to be written.

@sunjay
Copy link
Author

sunjay commented Jan 20, 2019

I would need some mentoring instructions to get started. :)

If we reach out to the broader community (and we have some instructions), someone may volunteer to help out. I'd be happy to help get the word out. :)

glebm added a commit to glebm/rsass that referenced this issue Feb 3, 2019
@glebm
Copy link
Contributor

glebm commented Feb 3, 2019

@sunjay I've given it a go at #35

glebm added a commit to glebm/rsass that referenced this issue Feb 3, 2019
@kaj kaj closed this as completed in #35 Feb 3, 2019
kaj added a commit that referenced this issue Feb 10, 2019
Sass-spec reports 1645 of 3440 tests for sass 3.6 passed.

* Improve support for `transparent`.
* PR #45 from @glebm: Automatically update passing / failing tests
  Hardkoded skiplists in spectest.rs is cleared apart for tests where
  rsass panics.
* Issue 43: Normalize newlines in tests.
* PR #44 from @glebm: Update to Rust 2018 Edition, Rust v1.31.0+
* Issue #39, PR #40 from @glebm: Parser CallArgs: Allow trailing
  spacelike sans ","
* Issue #32: Make the selectors module pub.
* Issue #34, PR #35 from @glebm: Accessing an undefined variable is an error.
* Allow input starting with UTF-8 U+FEFF BOM.
* Target sass spec version 3.6.

Thanks to contributors @glebm, @maxbrunsfeld and @sunjay for code and
suggestions.
kaj added a commit that referenced this issue Feb 10, 2019
Sass-spec reports 1645 of 3440 tests for sass 3.6 passed.

* Improve support for `transparent`.
* PR #45 from @glebm: Automatically update passing / failing tests
  Hardkoded skiplists in spectest.rs is cleared apart for tests where
  rsass panics.
* Issue 43: Normalize newlines in tests.
* PR #44 from @glebm: Update to Rust 2018 Edition, Rust v1.31.0+
* Issue #39, PR #40 from @glebm: Parser CallArgs: Allow trailing
  spacelike sans ","
* Issue #32: Make the selectors module pub.
* Issue #34, PR #35 from @glebm: Accessing an undefined variable is an error.
* Allow input starting with UTF-8 U+FEFF BOM.
* Target sass spec version 3.6.

Thanks to contributors @glebm, @maxbrunsfeld and @sunjay for code and
suggestions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants