Skip to content

Commit

Permalink
feat(css/ast): Add raw to Text (#2361)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Oct 7, 2021
1 parent d65ce85 commit 4ff1b75
Show file tree
Hide file tree
Showing 429 changed files with 11,319 additions and 1,375 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions css/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_css"
repository = "https://github.com/swc-project/swc.git"
version = "0.9.0"
version = "0.10.0"

[dependencies]
swc_css_ast = {version = "0.8.0", path = "./ast"}
swc_css_codegen = {version = "0.7.0", path = "./codegen"}
swc_css_parser = {version = "0.9.0", path = "./parser"}
swc_css_utils = {version = "0.5.0", path = "./utils/"}
swc_css_visit = {version = "0.7.0", path = "./visit"}
swc_css_ast = {version = "0.9.0", path = "./ast"}
swc_css_codegen = {version = "0.8.0", path = "./codegen"}
swc_css_parser = {version = "0.10.0", path = "./parser"}
swc_css_utils = {version = "0.6.0", path = "./utils/"}
swc_css_visit = {version = "0.8.0", path = "./visit"}
2 changes: 1 addition & 1 deletion css/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_css_ast"
repository = "https://github.com/swc-project/swc.git"
version = "0.8.0"
version = "0.9.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions css/ast/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use swc_common::{ast_node, Span};
pub struct Text {
pub span: Span,
pub value: JsWord,
pub raw: JsWord,
}

/// Quoted string.
Expand Down
11 changes: 9 additions & 2 deletions css/ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ pub struct TokenAndSpan {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Token {
/// `@`
AtKeyword(JsWord),
AtKeyword {
value: JsWord,
raw: JsWord,
},

/// `(`
LParen,
Expand All @@ -37,7 +40,10 @@ pub enum Token {

Num(NumToken),

Ident(JsWord),
Ident {
value: JsWord,
raw: JsWord,
},

Str {
value: JsWord,
Expand Down Expand Up @@ -76,6 +82,7 @@ pub enum Token {
Hash {
is_id: bool,
value: JsWord,
raw: JsWord,
},

/// One or more whitespace.
Expand Down
8 changes: 4 additions & 4 deletions css/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_css_codegen"
repository = "https://github.com/swc-project/swc.git"
version = "0.7.0"
version = "0.8.0"

[dependencies]
auto_impl = "0.4.1"
bitflags = "1.3.2"
swc_atoms = {version = "0.2.7", path = "../../atoms"}
swc_common = {version = "0.13.0", path = "../../common"}
swc_css_ast = {version = "0.8.0", path = "../ast/"}
swc_css_ast = {version = "0.9.0", path = "../ast/"}
swc_css_codegen_macros = {version = "0.2.0", path = "macros/"}

[dev-dependencies]
swc_css_parser = {version = "0.9.0", path = "../parser"}
swc_css_visit = {version = "0.7.0", path = "../visit"}
swc_css_parser = {version = "0.10.0", path = "../parser"}
swc_css_visit = {version = "0.8.0", path = "../visit"}
testing = {version = "0.14.0", path = "../../testing"}
1 change: 0 additions & 1 deletion css/codegen/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ where
#[derive(Debug, Default, Clone, Copy)]
pub(crate) struct Ctx {
pub semi_after_property: bool,
pub escape_first_dash: bool,
}

pub(super) struct WithCtx<'w, I: 'w + CssWriter> {
Expand Down
29 changes: 8 additions & 21 deletions css/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ where

#[emitter]
fn emit_text(&mut self, n: &Text) -> Result {
self.wr
.write_ident(Some(n.span), &n.value, self.ctx.escape_first_dash)?;
self.wr.write_raw(Some(n.span), &n.raw)?;
}

#[emitter]
Expand Down Expand Up @@ -485,10 +484,9 @@ where
for TokenAndSpan { span, token } in &n.tokens {
let span = *span;
match token {
Token::AtKeyword(name) => {
Token::AtKeyword { raw, .. } => {
punct!(self, span, "@");
punct!(self, span, "@");
self.wr.write_ident(Some(span), &name, false)?;
self.wr.write_raw(Some(n.span), &raw)?;
}
Token::LParen => {
punct!(self, span, "(");
Expand All @@ -508,8 +506,8 @@ where
Token::Num(n) => {
self.wr.write_raw(Some(span), &n.value.to_string())?;
}
Token::Ident(n) => {
self.wr.write_ident(Some(span), &n, true)?;
Token::Ident { raw, .. } => {
self.wr.write_raw(Some(n.span), &raw)?;
}
Token::Str { value } => {
punct!(self, "'");
Expand Down Expand Up @@ -712,10 +710,7 @@ where
self.wr.write_punct(None, combinator.as_str())?;
}

let ctx = Ctx {
escape_first_dash: true,
..self.ctx
};
let ctx = Ctx { ..self.ctx };
emit!(&mut *self.with_ctx(ctx), n.type_selector);

self.emit_list(&n.subclass_selectors, ListFormat::NotDelimited)?;
Expand Down Expand Up @@ -754,20 +749,14 @@ where
#[emitter]
fn emit_id_selector(&mut self, n: &IdSelector) -> Result {
punct!(self, "#");
let ctx = Ctx {
escape_first_dash: true,
..self.ctx
};
let ctx = Ctx { ..self.ctx };
emit!(&mut *self.with_ctx(ctx), n.text);
}

#[emitter]
fn emit_class_selector(&mut self, n: &ClassSelector) -> Result {
punct!(self, ".");
let ctx = Ctx {
escape_first_dash: true,
..self.ctx
};
let ctx = Ctx { ..self.ctx };
emit!(&mut *self.with_ctx(ctx), n.text);
}

Expand All @@ -778,9 +767,7 @@ where
emit!(self, n.name);

if let Some(op) = n.op {
space!(self);
self.wr.write_punct(None, op.as_str())?;
space!(self);
}

emit!(self, n.value);
Expand Down
6 changes: 3 additions & 3 deletions css/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_css_parser"
repository = "https://github.com/swc-project/swc.git"
version = "0.9.0"
version = "0.10.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
Expand All @@ -17,11 +17,11 @@ bitflags = "1.2.1"
lexical = "5.2.2"
swc_atoms = {version = "0.2.7", path = "../../atoms"}
swc_common = {version = "0.13.0", path = "../../common"}
swc_css_ast = {version = "0.8.0", path = "../ast"}
swc_css_ast = {version = "0.9.0", path = "../ast"}
unicode-xid = "0.2.2"

[dev-dependencies]
serde = "1.0.127"
serde_json = "1.0.66"
swc_css_visit = {version = "0.7.0", path = "../visit"}
swc_css_visit = {version = "0.8.0", path = "../visit"}
testing = {version = "0.14.0", path = "../../testing"}
Loading

0 comments on commit 4ff1b75

Please sign in to comment.