Skip to content

Commit

Permalink
Accept sass interpolation syntax in most places.
Browse files Browse the repository at this point in the history
  • Loading branch information
basro committed May 21, 2024
1 parent a1a3854 commit 4513433
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
37 changes: 36 additions & 1 deletion internal/stylance-core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ fn block_comment<'s>(input: &mut &'s str) -> PResult<&'s str> {
.parse_next(input)
}

// matches a sass interpolation of the form #{...}
fn sass_interpolation<'s>(input: &mut &'s str) -> PResult<&'s str> {
(
"#{",
cut_err(terminated(take_till(1.., ('{', '}', '\n')), '}')),
)
.recognize()
.parse_next(input)
}

fn identifier<'s>(input: &mut &'s str) -> PResult<&'s str> {
(
one_of(('_', '-', AsChar::is_alpha)),
Expand Down Expand Up @@ -114,8 +124,10 @@ pub fn stuff_till<'s>(
string.void(),
block_comment.void(),
line_comment.void(),
sass_interpolation.void(),
'/'.void(),
take_till(1.., ('\'', '"', '/', list)).void(),
'#'.void(),
take_till(1.., ('\'', '"', '/', '#', list)).void(),
)),
)
}
Expand Down Expand Up @@ -462,4 +474,27 @@ mod tests {
println!("{input}");
assert!(input.is_empty());
}

#[test]
fn test_sass_interpolation() {
let mut input = "#{$test-test}END";

let r = sass_interpolation.parse_next(&mut input);
assert_eq!(r, Ok("#{$test-test}"));

assert_eq!(input, "END");

let mut input = "#{$test-test
}END";
let r = sass_interpolation.parse_next(&mut input);
assert!(r.is_err());

let mut input = "#{$test-test";
let r = sass_interpolation.parse_next(&mut input);
assert!(r.is_err());

let mut input = "#{$test-te{st}";
let r = sass_interpolation.parse_next(&mut input);
assert!(r.is_err());
}
}
2 changes: 1 addition & 1 deletion stylance/tests/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ $some-scss-variable: 10px; // Scss variable declarations in top scope.

@layer;

@container (width > 400px) {
@container (min-width: #{$screen-md}) {
h2 {
font-size: 1.5em;
}
Expand Down

0 comments on commit 4513433

Please sign in to comment.