-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Closed
Support for css #950
Changes from 37 commits
Commits
Show all changes
129 commits
Select commit
Hold shift + click to select a range
f0037cd
Initialize css module
kdy1 19910b3
WIP
kdy1 2597a11
More crates
kdy1 76e2a53
WIP: ast
kdy1 ec34386
WIP: ast
kdy1 2d86ef7
WIP
kdy1 db341a5
More ast work
kdy1 9e2c99d
More ast nodes
kdy1 be3dc68
Let's not specify version while development
kdy1 936dd36
tag
kdy1 092b368
WIP: css parser
kdy1 bd296c2
take_ws
kdy1 6ad2a0b
More work for parser
kdy1 baad044
WIP: Selector
kdy1 3bbe8cb
Move take_ws
kdy1 36858e9
skip_ws
kdy1 5803d51
parse_selectors
kdy1 8f63e02
Add spec module
kdy1 5b1d117
spec -> lexer
kdy1 b5085b8
lexer::parse_name
kdy1 e332edc
ast was wrong
kdy1 1847fc0
ast is very complex than I thought
kdy1 6be06a4
Switch to logos
kdy1 f4edb1f
WIP: Parser
kdy1 a7b5027
Need a wrapper for lexer
kdy1 ec1d44a
More ast work
kdy1 8e5b8bc
MediaQuery
kdy1 e5132dd
AST
kdy1 17e5a24
More ast work
kdy1 66796a6
Add HashValue
kdy1 0897ca6
Token
kdy1 b360916
Document
kdy1 00f6e13
WIP: parser
kdy1 93f40b3
ast: expose all
kdy1 d6a9cc2
Bump swc_atoms
kdy1 b1c0a0e
More atoms
kdy1 2039452
WIP: Parser: at rules
kdy1 94f6149
Add TODO
kdy1 02db306
More methods
kdy1 7fc7a47
Move some codes
kdy1 abf35fc
More work for parser
kdy1 e212ed0
Move code
kdy1 a404776
parse_str
kdy1 1d66084
parse_import_rule
kdy1 5dbdb5a
parse_keyframes_rule
kdy1 974698e
Fix macro
kdy1 b0bf5e1
expect! and is!
kdy1 f8bdbb4
Fix macros
kdy1 de8abc4
SyntaxError
kdy1 339ec4f
Again, fix macros
kdy1 6ce2a5b
parse_opt_word
kdy1 da43091
parse_keyframe_selector
kdy1 004cfb1
DeclBlock instead of Vec<Property>
kdy1 f733c20
parse_decl_block
kdy1 65c5334
parse_keyframe_element
kdy1 7284d6c
Remove duplicate
kdy1 e6d1d29
More media query types
kdy1 fb1b5af
parse_media_rule
kdy1 7637871
Add value.rs
kdy1 29a3418
More atoms
kdy1 ff40a6b
parse_media_query
kdy1 afd938c
fixup! parse_media_query
kdy1 2fb8692
error
kdy1 f1ba736
fixup! error
kdy1 347d220
parse_one_media_query_element
kdy1 a39554c
parse_font_face_rule
kdy1 42839aa
Add unimplemented
kdy1 05d8029
parse_supports_rule
kdy1 b15df24
parse_supports_query
kdy1 a820851
Add selector module
kdy1 2f9332b
parse_selectors
kdy1 7c98c9d
parse_style_rule
kdy1 0c0c7ff
parse_property
kdy1 e90fde0
WIP: parse_value
kdy1 03049cb
fixup! WIP: parse_value
kdy1 0a31322
Fix
kdy1 8a9aa17
as_word
kdy1 5d5e1a3
parse_paren_value
kdy1 db2d4dd
unimplemented!
kdy1 57805f4
Fix visibility issues
kdy1 0ec55f9
WIP: Adding tests
kdy1 b2b0f5e
Fix compilation
kdy1 c62947c
Css test
kdy1 d44198d
typo
kdy1 6ef7cc7
More ast work
kdy1 78d0bff
Bit more
kdy1 428fff6
More tokens
kdy1 7c687c2
WIP: parse_selector
kdy1 3193ee5
More parser work
kdy1 93bb30a
parse_tag_selector
kdy1 657cd55
Selector
kdy1 ff67444
More work for selector parser
kdy1 88b9370
Fix compilation
kdy1 9f2b796
trace_cur!
kdy1 79a67d0
WIP: Selector
kdy1 4d57ceb
Fix expect!
kdy1 26119d9
parse_class_selector
kdy1 0f60c6b
parse_id_selector
kdy1 7124558
Pretty json
kdy1 8658f50
Fix serde of css ast nodes
kdy1 b8d0ebc
Test refs
kdy1 8dcebe0
Be consitant with ast nodes
kdy1 b9523a8
Let's test using grass
kdy1 ad50e99
Rename
kdy1 e4937e4
Rename macros to grass_macros
kdy1 390a364
Rename macros
kdy1 1879404
Borrowed lots of tests from grass
kdy1 89e2d22
Print source code
kdy1 e4bc0f6
Reorder
kdy1 6561c0c
More tokens
kdy1 311ce47
parse_attribute_selector
kdy1 8b6ef8f
parse_attribute_selector should eat ]
kdy1 f55aee6
Fix parse_attribute_selector_operator
kdy1 14abb71
Value of attribute selector is optional
kdy1 bd3539d
Fix parse_attribute_selector_operator
kdy1 7dcdc49
Rename
kdy1 a0c2727
Fix parse_decl_block
kdy1 34ff27d
Handle whitespace
kdy1 348db57
parse mutliple selectors
kdy1 11685bf
parse_universal_selector
kdy1 a031aa0
PseudoSelector
kdy1 dec0b75
parse_pseudo_selector_args
kdy1 3fd3125
`:` starts a simple selector
kdy1 751ae26
parse_pseudo_selector_args for text args
kdy1 f96ac25
~ and + is selector operator
kdy1 a6ff411
parse_selector_combinator
kdy1 3891ef4
parse_selector
kdy1 4416e33
lint
kdy1 3bf2d18
reset extras
kdy1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
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>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.