fix: allow duplicate selectors in scope, coz its safe to have them, coz hashing isnt affected by selector position
This commit is contained in:
parent
9a8544d425
commit
337a866bfb
10 changed files with 68 additions and 11 deletions
|
|
@ -28,12 +28,7 @@ impl CompilerAdapter {
|
||||||
) -> Result<String, SabryCompilerError> {
|
) -> Result<String, SabryCompilerError> {
|
||||||
let options = grass::Options::from(&self.config).input_syntax(syntax.into());
|
let options = grass::Options::from(&self.config).input_syntax(syntax.into());
|
||||||
|
|
||||||
let mut css = grass::from_string(code, &options)?;
|
let css = self.lightningcss(&grass::from_string(code, &options)?)?;
|
||||||
|
|
||||||
css = match self.lightningcss(&css) {
|
|
||||||
Ok(c) => c,
|
|
||||||
Err(e) => return Err(e),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(css)
|
Ok(css)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@ impl<'s> HashedScope<'s> {
|
||||||
/// Struct which represents hashed selector inside of [HashedScope].
|
/// Struct which represents hashed selector inside of [HashedScope].
|
||||||
///
|
///
|
||||||
/// Does not hold information about hash itself, as meant to be inside of scope.
|
/// Does not hold information about hash itself, as meant to be inside of scope.
|
||||||
|
#[derive(PartialEq, Eq, Hash)]
|
||||||
pub struct HashedSelector {
|
pub struct HashedSelector {
|
||||||
/// Basic unrelated to hash info about this selector
|
/// Basic unrelated to hash info about this selector
|
||||||
pub sel: ScopedSelector,
|
pub sel: ScopedSelector,
|
||||||
|
|
@ -258,6 +259,7 @@ impl HashedSelector {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Just any unary CSS-ish selector
|
/// Just any unary CSS-ish selector
|
||||||
|
#[derive(PartialEq, Eq, Hash)]
|
||||||
pub struct ArbitrarySelector {
|
pub struct ArbitrarySelector {
|
||||||
/// CSS-ish identifier
|
/// CSS-ish identifier
|
||||||
pub ident: String,
|
pub ident: String,
|
||||||
|
|
@ -266,6 +268,7 @@ pub struct ArbitrarySelector {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Any unary CSS-ish selector, that's able to be scoped, and then hashed
|
/// Any unary CSS-ish selector, that's able to be scoped, and then hashed
|
||||||
|
#[derive(PartialEq, Eq, Hash)]
|
||||||
pub enum ScopedSelector {
|
pub enum ScopedSelector {
|
||||||
Class(ArbitrarySelector),
|
Class(ArbitrarySelector),
|
||||||
Id(ArbitrarySelector),
|
Id(ArbitrarySelector),
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ quote = {version = "^1.0"}
|
||||||
proc-macro2 = {version = "^1.0", features = ["span-locations"]}
|
proc-macro2 = {version = "^1.0", features = ["span-locations"]}
|
||||||
raffia = {version = "^0.9"}
|
raffia = {version = "^0.9"}
|
||||||
regex = {version = "^1.11"}
|
regex = {version = "^1.11"}
|
||||||
|
itertools = {version = "^0.13"}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
nightly = []
|
nightly = []
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use sabry_intrnl::{
|
use sabry_intrnl::{
|
||||||
|
|
@ -94,6 +95,7 @@ pub fn styly_macro_impl(input: TokenStream, source_path: Option<PathBuf>) -> Tok
|
||||||
interp
|
interp
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.unique()
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
let ident = apply_basic_rusty_member_gen_rules(&s);
|
let ident = apply_basic_rusty_member_gen_rules(&s);
|
||||||
let fnident = syn::parse_str::<Ident>(format!("_{ident}").as_str())
|
let fnident = syn::parse_str::<Ident>(format!("_{ident}").as_str())
|
||||||
|
|
@ -110,6 +112,7 @@ pub fn styly_macro_impl(input: TokenStream, source_path: Option<PathBuf>) -> Tok
|
||||||
let scope_members = scope
|
let scope_members = scope
|
||||||
.hashed_selectors
|
.hashed_selectors
|
||||||
.iter()
|
.iter()
|
||||||
|
.unique()
|
||||||
.filter_map(|hs| {
|
.filter_map(|hs| {
|
||||||
hs.html_ident.clone().map(|html| {
|
hs.html_ident.clone().map(|html| {
|
||||||
let name = match hs.sel {
|
let name = match hs.sel {
|
||||||
|
|
|
||||||
17
tests/assets/repeating-selector.sass
Normal file
17
tests/assets/repeating-selector.sass
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
.el1
|
||||||
|
color: red
|
||||||
|
&-mob
|
||||||
|
color: blue
|
||||||
|
|
||||||
|
&__blist
|
||||||
|
list-style: none
|
||||||
|
|
||||||
|
.el2
|
||||||
|
color: white
|
||||||
|
&-mob
|
||||||
|
color: black
|
||||||
|
|
||||||
|
&__blist
|
||||||
|
background: white
|
||||||
|
&-mob
|
||||||
|
background: black
|
||||||
24
tests/assets/repeating-selector.scss
Normal file
24
tests/assets/repeating-selector.scss
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
.el1 {
|
||||||
|
color: red;
|
||||||
|
&-mob {
|
||||||
|
color: blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__blist {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.el2 {
|
||||||
|
color: white;
|
||||||
|
&-mob {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__blist {
|
||||||
|
background: white;
|
||||||
|
&-mob {
|
||||||
|
background: black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -82,6 +82,8 @@ styly!(module_usage_sass:sass "tests/assets/module-usage.sass");
|
||||||
styly!(module_usage_scss:scss "tests/assets/module-usage.scss");
|
styly!(module_usage_scss:scss "tests/assets/module-usage.scss");
|
||||||
styly!(use_forwarded_sass:sass "tests/assets/use-forwarded.sass");
|
styly!(use_forwarded_sass:sass "tests/assets/use-forwarded.sass");
|
||||||
styly!(use_forwarded_scss:scss "tests/assets/use-forwarded.scss");
|
styly!(use_forwarded_scss:scss "tests/assets/use-forwarded.scss");
|
||||||
|
styly!(repeating_selector_sass:sass "tests/assets/repeating-selector.sass");
|
||||||
|
styly!(repeating_selector_scss:scss "tests/assets/repeating-selector.scss");
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ensure_inline_matches_file() {
|
fn ensure_inline_matches_file() {
|
||||||
|
|
@ -154,9 +156,7 @@ mod build_tests {
|
||||||
|
|
||||||
fn gen_builder() -> SabryBuilder {
|
fn gen_builder() -> SabryBuilder {
|
||||||
let config = gen_config();
|
let config = gen_config();
|
||||||
let builder = SabryBuilder::new(config);
|
SabryBuilder::new(config)
|
||||||
|
|
||||||
builder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
source: tests/macros.rs
|
||||||
|
assertion_line: 183
|
||||||
|
input_file: tests/sabry_output/scopes/repeating_selector_sass.css
|
||||||
|
snapshot_kind: text
|
||||||
|
---
|
||||||
|
.rWkBO00R__2y_lbRfXlyg.el1{color:red}.rWkBO00R__2y_lbRfXlyg.el1-mob{color:#00f}.rWkBO00R__2y_lbRfXlyg.el1__blist{list-style:none}.rWkBO00R__2y_lbRfXlyg.el2{color:#fff}.rWkBO00R__2y_lbRfXlyg.el2-mob{color:#000}.rWkBO00R__2y_lbRfXlyg.el2__blist{background:#fff}.rWkBO00R__2y_lbRfXlyg.el2__blist-mob{background:#000}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
source: tests/macros.rs
|
||||||
|
assertion_line: 183
|
||||||
|
input_file: tests/sabry_output/scopes/repeating_selector_scss.css
|
||||||
|
snapshot_kind: text
|
||||||
|
---
|
||||||
|
.YYYksiQMfU3exD720ckMbA.el1{color:red}.YYYksiQMfU3exD720ckMbA.el1-mob{color:#00f}.YYYksiQMfU3exD720ckMbA.el1__blist{list-style:none}.YYYksiQMfU3exD720ckMbA.el2{color:#fff}.YYYksiQMfU3exD720ckMbA.el2-mob{color:#000}.YYYksiQMfU3exD720ckMbA.el2__blist{background:#fff}.YYYksiQMfU3exD720ckMbA.el2__blist-mob{background:#000}
|
||||||
Loading…
Reference in a new issue