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

Support for css #950

Closed
wants to merge 129 commits into from
Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
f0037cd
Initialize css module
kdy1 Aug 9, 2020
19910b3
WIP
kdy1 Aug 9, 2020
2597a11
More crates
kdy1 Aug 9, 2020
76e2a53
WIP: ast
kdy1 Aug 11, 2020
ec34386
WIP: ast
kdy1 Aug 17, 2020
2d86ef7
WIP
kdy1 Aug 22, 2020
db341a5
More ast work
kdy1 Aug 22, 2020
9e2c99d
More ast nodes
kdy1 Aug 26, 2020
be3dc68
Let's not specify version while development
kdy1 Aug 26, 2020
936dd36
tag
kdy1 Aug 26, 2020
092b368
WIP: css parser
kdy1 Aug 27, 2020
bd296c2
take_ws
kdy1 Aug 27, 2020
6ad2a0b
More work for parser
kdy1 Aug 27, 2020
baad044
WIP: Selector
kdy1 Aug 27, 2020
3bbe8cb
Move take_ws
kdy1 Aug 27, 2020
36858e9
skip_ws
kdy1 Aug 27, 2020
5803d51
parse_selectors
kdy1 Aug 27, 2020
8f63e02
Add spec module
kdy1 Aug 27, 2020
5b1d117
spec -> lexer
kdy1 Aug 27, 2020
b5085b8
lexer::parse_name
kdy1 Aug 27, 2020
e332edc
ast was wrong
kdy1 Aug 27, 2020
1847fc0
ast is very complex than I thought
kdy1 Aug 27, 2020
6be06a4
Switch to logos
kdy1 Sep 7, 2020
f4edb1f
WIP: Parser
kdy1 Sep 7, 2020
a7b5027
Need a wrapper for lexer
kdy1 Sep 7, 2020
ec1d44a
More ast work
kdy1 Sep 13, 2020
8e5b8bc
MediaQuery
kdy1 Sep 13, 2020
e5132dd
AST
kdy1 Sep 13, 2020
17e5a24
More ast work
kdy1 Sep 13, 2020
66796a6
Add HashValue
kdy1 Sep 13, 2020
0897ca6
Token
kdy1 Sep 13, 2020
b360916
Document
kdy1 Sep 13, 2020
00f6e13
WIP: parser
kdy1 Sep 13, 2020
93f40b3
ast: expose all
kdy1 Sep 13, 2020
d6a9cc2
Bump swc_atoms
kdy1 Sep 13, 2020
b1c0a0e
More atoms
kdy1 Sep 13, 2020
2039452
WIP: Parser: at rules
kdy1 Sep 13, 2020
94f6149
Add TODO
kdy1 Sep 13, 2020
02db306
More methods
kdy1 Sep 13, 2020
7fc7a47
Move some codes
kdy1 Sep 13, 2020
abf35fc
More work for parser
kdy1 Sep 13, 2020
e212ed0
Move code
kdy1 Sep 13, 2020
a404776
parse_str
kdy1 Sep 13, 2020
1d66084
parse_import_rule
kdy1 Sep 13, 2020
5dbdb5a
parse_keyframes_rule
kdy1 Sep 13, 2020
974698e
Fix macro
kdy1 Sep 13, 2020
b0bf5e1
expect! and is!
kdy1 Sep 13, 2020
f8bdbb4
Fix macros
kdy1 Sep 13, 2020
de8abc4
SyntaxError
kdy1 Sep 13, 2020
339ec4f
Again, fix macros
kdy1 Sep 13, 2020
6ce2a5b
parse_opt_word
kdy1 Sep 13, 2020
da43091
parse_keyframe_selector
kdy1 Sep 13, 2020
004cfb1
DeclBlock instead of Vec<Property>
kdy1 Sep 13, 2020
f733c20
parse_decl_block
kdy1 Sep 13, 2020
65c5334
parse_keyframe_element
kdy1 Sep 13, 2020
7284d6c
Remove duplicate
kdy1 Sep 13, 2020
e6d1d29
More media query types
kdy1 Sep 13, 2020
fb1b5af
parse_media_rule
kdy1 Sep 13, 2020
7637871
Add value.rs
kdy1 Sep 13, 2020
29a3418
More atoms
kdy1 Sep 14, 2020
ff40a6b
parse_media_query
kdy1 Sep 14, 2020
afd938c
fixup! parse_media_query
kdy1 Sep 14, 2020
2fb8692
error
kdy1 Sep 14, 2020
f1ba736
fixup! error
kdy1 Sep 14, 2020
347d220
parse_one_media_query_element
kdy1 Sep 14, 2020
a39554c
parse_font_face_rule
kdy1 Sep 14, 2020
42839aa
Add unimplemented
kdy1 Sep 14, 2020
05d8029
parse_supports_rule
kdy1 Sep 14, 2020
b15df24
parse_supports_query
kdy1 Sep 14, 2020
a820851
Add selector module
kdy1 Sep 14, 2020
2f9332b
parse_selectors
kdy1 Sep 14, 2020
7c98c9d
parse_style_rule
kdy1 Sep 14, 2020
0c0c7ff
parse_property
kdy1 Sep 14, 2020
e90fde0
WIP: parse_value
kdy1 Sep 14, 2020
03049cb
fixup! WIP: parse_value
kdy1 Sep 14, 2020
0a31322
Fix
kdy1 Sep 14, 2020
8a9aa17
as_word
kdy1 Sep 14, 2020
5d5e1a3
parse_paren_value
kdy1 Sep 14, 2020
db2d4dd
unimplemented!
kdy1 Sep 14, 2020
57805f4
Fix visibility issues
kdy1 Sep 14, 2020
0ec55f9
WIP: Adding tests
kdy1 Sep 14, 2020
b2b0f5e
Fix compilation
kdy1 Sep 15, 2020
c62947c
Css test
kdy1 Sep 15, 2020
d44198d
typo
kdy1 Sep 15, 2020
6ef7cc7
More ast work
kdy1 Sep 15, 2020
78d0bff
Bit more
kdy1 Sep 15, 2020
428fff6
More tokens
kdy1 Sep 15, 2020
7c687c2
WIP: parse_selector
kdy1 Sep 15, 2020
3193ee5
More parser work
kdy1 Sep 15, 2020
93bb30a
parse_tag_selector
kdy1 Sep 15, 2020
657cd55
Selector
kdy1 Sep 15, 2020
ff67444
More work for selector parser
kdy1 Sep 15, 2020
88b9370
Fix compilation
kdy1 Sep 15, 2020
9f2b796
trace_cur!
kdy1 Sep 16, 2020
79a67d0
WIP: Selector
kdy1 Sep 16, 2020
4d57ceb
Fix expect!
kdy1 Sep 17, 2020
26119d9
parse_class_selector
kdy1 Sep 17, 2020
0f60c6b
parse_id_selector
kdy1 Sep 17, 2020
7124558
Pretty json
kdy1 Sep 17, 2020
8658f50
Fix serde of css ast nodes
kdy1 Sep 17, 2020
b8d0ebc
Test refs
kdy1 Sep 17, 2020
8dcebe0
Be consitant with ast nodes
kdy1 Sep 17, 2020
b9523a8
Let's test using grass
kdy1 Sep 19, 2020
ad50e99
Rename
kdy1 Sep 19, 2020
e4937e4
Rename macros to grass_macros
kdy1 Sep 19, 2020
390a364
Rename macros
kdy1 Sep 19, 2020
1879404
Borrowed lots of tests from grass
kdy1 Sep 19, 2020
89e2d22
Print source code
kdy1 Sep 19, 2020
e4bc0f6
Reorder
kdy1 Sep 19, 2020
6561c0c
More tokens
kdy1 Sep 19, 2020
311ce47
parse_attribute_selector
kdy1 Sep 19, 2020
8b6ef8f
parse_attribute_selector should eat ]
kdy1 Sep 19, 2020
f55aee6
Fix parse_attribute_selector_operator
kdy1 Sep 19, 2020
14abb71
Value of attribute selector is optional
kdy1 Sep 19, 2020
bd3539d
Fix parse_attribute_selector_operator
kdy1 Sep 19, 2020
7dcdc49
Rename
kdy1 Sep 19, 2020
a0c2727
Fix parse_decl_block
kdy1 Sep 19, 2020
34ff27d
Handle whitespace
kdy1 Sep 19, 2020
348db57
parse mutliple selectors
kdy1 Sep 19, 2020
11685bf
parse_universal_selector
kdy1 Sep 19, 2020
a031aa0
PseudoSelector
kdy1 Sep 19, 2020
dec0b75
parse_pseudo_selector_args
kdy1 Sep 19, 2020
3fd3125
`:` starts a simple selector
kdy1 Sep 19, 2020
751ae26
parse_pseudo_selector_args for text args
kdy1 Sep 19, 2020
f96ac25
~ and + is selector operator
kdy1 Sep 19, 2020
a6ff411
parse_selector_combinator
kdy1 Sep 19, 2020
3891ef4
parse_selector
kdy1 Sep 19, 2020
4416e33
lint
kdy1 Sep 19, 2020
3bf2d18
reset extras
kdy1 Sep 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ name = "swc"
[dependencies]
swc_atoms = { path ="./atoms" }
swc_common = { path ="./common", features = ["sourcemap", "concurrent"] }
swc_css = { path ="./css" }
swc_ecma_ast = { path ="./ecmascript/ast" }
swc_ecma_codegen = { path ="./ecmascript/codegen" }
swc_ecma_parser = { path ="./ecmascript/parser" }
Expand Down
4 changes: 2 additions & 2 deletions atoms/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "swc_atoms"
build = "build.rs"
version = "0.2.2"
version = "0.2.3"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
license = "Apache-2.0/MIT"
repository = "https://github.com/swc-project/swc.git"
Expand All @@ -13,4 +13,4 @@ edition = "2018"
string_cache = "0.8"

[build-dependencies]
string_cache_codegen = "0.5"
string_cache_codegen = "0.5"
6 changes: 6 additions & 0 deletions atoms/words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ break
call
case
catch
charset
class
concat
const
Expand All @@ -607,6 +608,7 @@ export
extends
false
finally
font-face
for
from
function
Expand All @@ -615,16 +617,19 @@ global
if
implements
import
important
in
infer
instanceof
interface
is
iterator
key
keyframes
keyof
length
let
media
meta
module
namespace
Expand All @@ -646,6 +651,7 @@ set
static
string
super
supports
switch
symbol
target
Expand Down
11 changes: 11 additions & 0 deletions css/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
edition = "2018"
name = "swc_css"
version = "0.1.0"

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

[dependencies]
swc_css_ast = {path = "./ast"}
swc_css_parser = {path = "./parser"}
13 changes: 13 additions & 0 deletions css/ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "swc_css_ast"
version = "0.1.0"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
edition = "2018"

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

[dependencies]
swc_atoms = { path = "../../atoms" }
swc_common = { path = "../../common" }
swc_visit = { path = "../../visit" }
serde = { version = "1", features = ["derive"] }
115 changes: 115 additions & 0 deletions css/ast/src/at_rule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
use crate::{media_query::MediaQuery, Number, Property, Text};
use swc_common::{ast_node, Span};
#[ast_node]
pub enum AtRule {
#[tag("CharsetRule")]
Charset(CharsetRule),
#[tag("MediaRule")]
Media(MediaRule),
#[tag("ImportRule")]
Import(ImportRule),
#[tag("SupportsRule")]
Supports(SupportsRule),
#[tag("KeyframesRule")]
Keyframes(KeyframesRule),
#[tag("FontFaceRule")]
FontFace(FontFaceRule),
#[tag("*")]
Unknown(UnknownAtRule),
}

#[ast_node]
pub struct CharsetRule {
pub span: Span,
pub charset: Text,
}
#[ast_node]
pub struct MediaRule {
pub span: Span,
pub query: Box<MediaQuery>,
}

#[ast_node]
pub struct ImportRule {
pub span: Span,
/// This field includes quotes.
pub src: Text,
}

#[ast_node]
pub struct PageRule {
pub span: Span,
/// TODO: Create a dedicated ast type.
pub selector: Option<Text>,
}

#[ast_node]
pub struct SupportsRule {
pub span: Span,
/// TODO: Create a dedicated ast type.
pub query: Box<SupportsQuery>,
}

#[ast_node]
pub enum SupportsQuery {
#[tag("Property")]
Property(Property),

#[tag("AndSupportsQuery")]
And(AndSupportsQuery),

#[tag("OrSupportsQuery")]
Or(OrSupportsQuery),
}

#[ast_node]
pub struct AndSupportsQuery {
pub span: Span,
pub queries: Vec<SupportsQuery>,
}

#[ast_node]
pub struct OrSupportsQuery {
pub span: Span,
pub queries: Vec<SupportsQuery>,
}

#[ast_node]
pub struct KeyframesRule {
pub span: Span,
pub keyframe: Vec<KeyframeElement>,
}

#[ast_node]
pub struct KeyframeElement {
pub span: Span,
pub selector: KeyframeSelector,
pub properties: Vec<Property>,
}

#[ast_node]
pub enum KeyframeSelector {
#[tag("KeyframePercentSelector")]
Percent(KeyframePercentSelector),
#[tag("Text")]
Extra(Text),
}

#[ast_node]
pub struct KeyframePercentSelector {
pub span: Span,
pub percent: Number,
}

#[ast_node]
pub struct FontFaceRule {
pub span: Span,
pub properties: Vec<Property>,
}

#[ast_node]
pub struct UnknownAtRule {
pub span: Span,
pub name: Text,
pub extras: Text,
}
132 changes: 132 additions & 0 deletions css/ast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#![deny(unused)]

pub use self::{at_rule::*, media_query::*};
pub use at_rule::AtRule;
use serde::{Deserialize, Serialize};
use swc_atoms::JsWord;
use swc_common::{ast_node, Span};

mod at_rule;
mod media_query;

#[ast_node]
pub struct Text {
pub span: Span,
pub sym: JsWord,
}

#[ast_node]
pub struct Number {
pub span: Span,
pub value: Box<Value>,
}

#[ast_node]
pub struct Stylesheet {
pub span: Span,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kdy1 Does swc usually keep span for all the struct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, many operations related to comment or a source map depend on the span.

pub rules: Vec<Rule>,
}

#[ast_node]
pub enum Rule {
#[tag("AtRule")]
At(AtRule),
#[tag("StyleRule")]
Style(StyleRule),
}

#[ast_node]
pub struct StyleRule {
pub span: Span,
pub selectors: Vec<Selector>,
pub properties: Vec<Property>,
}

#[ast_node]
pub struct Selector {
pub span: Span,
pub tag: Option<TagSelector>,
pub base: Vec<BaseSelector>,
pub pseudo_class: Option<Text>,
pub pseudo_element: Option<Text>,
}

#[ast_node]
pub struct IdSelector {
pub span: Span,
/// Does not include `#`
pub text: Text,
}

#[ast_node]
pub struct ClassSelector {
pub span: Span,
/// Does not include `.`
pub text: Text,
}

#[ast_node]
pub struct TagSelector {
pub span: Span,
pub text: Text,
}

#[ast_node]
pub enum BaseSelector {
#[tag("IdSelector")]
Id(IdSelector),
#[tag("ClassSelector")]
Class(ClassSelector),
}

#[ast_node]
pub struct Property {
pub span: Span,
pub name: Text,
pub value: Value,
/// The span includes `!`
pub important: Option<Span>,
}

#[ast_node]
pub enum Value {
#[tag("ParenValue")]
Paren(ParenValue),
#[tag("UnitValue")]
Unit(UnitValue),
#[tag("Number")]
Number(Number),
#[tag("HashValue")]
Hash(HashValue),
}

#[ast_node]
pub struct HashValue {
/// Includes `#`
pub span: Span,
/// Does **not** include `#`
pub value: Text,
}

#[ast_node]
pub struct UnitValue {
pub span: Span,
pub value: Text,
pub unit: SpannedUnit,
}

#[ast_node]
pub struct SpannedUnit {
pub span: Span,
pub unit: Unit,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Unit {
Px,
}

#[ast_node]
pub struct ParenValue {
pub span: Span,
pub value: Box<Value>,
}
21 changes: 21 additions & 0 deletions css/ast/src/media_query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use swc_common::{ast_node, Span};

#[ast_node]
pub enum MediaQuery {
#[tag("AndMediaQuery")]
And(AndMediaQuery),
#[tag("OrMediaQuery")]
Or(OrMediaQuery),
}

#[ast_node]
pub struct AndMediaQuery {
pub span: Span,
pub queries: Vec<MediaQuery>,
}

#[ast_node]
pub struct OrMediaQuery {
pub span: Span,
pub queries: Vec<MediaQuery>,
}
15 changes: 15 additions & 0 deletions css/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
edition = "2018"
name = "swc_css_parser"
version = "0.1.0"

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

[dependencies]
logos = "0.11.4"
matches = "0.1.8"
serde = {version = "1", features = ["derive"]}
swc_atoms = {path = "../../atoms"}
swc_common = {path = "../../common"}
swc_css_ast = {path = "../ast"}
Loading