Skip to content

Commit

Permalink
refactor(xml/parser): Simplify logic for parsing elements (#6557)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Dec 1, 2022
1 parent 967a9dc commit 85a03e7
Show file tree
Hide file tree
Showing 10 changed files with 759 additions and 433 deletions.
10 changes: 5 additions & 5 deletions crates/swc_html_parser/src/lexer/mod.rs
Expand Up @@ -1067,16 +1067,16 @@ where
State::TagOpen => {
// Consume the next input character:
match self.consume_next_char() {
// U+0021 EXCLAMATION MARK (!)
// Switch to the markup declaration open state.
Some('!') => {
self.state = State::MarkupDeclarationOpen;
}
// U+002F SOLIDUS (/)
// Switch to the end tag open state.
Some('/') => {
self.state = State::EndTagOpen;
}
// U+0021 EXCLAMATION MARK (!)
// Switch to the markup declaration open state.
Some('!') => {
self.state = State::MarkupDeclarationOpen;
}
// ASCII alpha
// Create a new start tag token, set its tag name to the empty string.
// Reconsume in the tag name state.
Expand Down
4 changes: 0 additions & 4 deletions crates/swc_xml_ast/src/token.rs
Expand Up @@ -40,10 +40,6 @@ pub enum Token {
tag_name: JsWord,
attributes: Vec<AttributeToken>,
},
ShortTag {
tag_name: JsWord,
attributes: Vec<AttributeToken>,
},
EmptyTag {
tag_name: JsWord,
attributes: Vec<AttributeToken>,
Expand Down
1 change: 0 additions & 1 deletion crates/swc_xml_codegen/src/lib.rs
Expand Up @@ -462,7 +462,6 @@ fn escape_string(value: &str, is_attribute_mode: bool) -> String {
'&' => {
result.push_str("&amp;");
}
'\u{00A0}' => result.push_str("&nbsp;"),
'"' if is_attribute_mode => result.push_str("&quot;"),
'<' if !is_attribute_mode => {
result.push_str("&lt;");
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_xml_parser/src/error.rs
Expand Up @@ -80,6 +80,7 @@ impl Error {
ErrorKind::MissingWhitespaceBetweenDoctypePublicAndSystemIdentifiers => {
"Missing whitespace between doctype public and system identifiers".into()
}
ErrorKind::MissingEndTagName => "Missing end tag name".into(),
ErrorKind::NestedComment => "Nested comment".into(),
ErrorKind::DoubleHyphenWithInComment => "Double hyper within comment".into(),
ErrorKind::NoncharacterInInputStream => "Noncharacter in input stream".into(),
Expand Down Expand Up @@ -150,6 +151,7 @@ pub enum ErrorKind {
MissingWhitespaceAfterDoctypeSystemKeyword,
MissingWhitespaceBeforeDoctypeName,
MissingWhitespaceBetweenDoctypePublicAndSystemIdentifiers,
MissingEndTagName,
NestedComment,
DoubleHyphenWithInComment,
NoncharacterInInputStream,
Expand Down

1 comment on commit 85a03e7

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 85a03e7 Previous: 8587589 Ratio
es/full/bugs-1 370458 ns/iter (± 27704) 360417 ns/iter (± 33466) 1.03
es/full/minify/libraries/antd 2126071308 ns/iter (± 107396193) 2167405158 ns/iter (± 73929486) 0.98
es/full/minify/libraries/d3 444563274 ns/iter (± 14763351) 521107751 ns/iter (± 33102309) 0.85
es/full/minify/libraries/echarts 1908154550 ns/iter (± 60956281) 1910686182 ns/iter (± 108465239) 1.00
es/full/minify/libraries/jquery 138430308 ns/iter (± 4781748) 123375656 ns/iter (± 22418352) 1.12
es/full/minify/libraries/lodash 156331538 ns/iter (± 8091552) 142647163 ns/iter (± 12670541) 1.10
es/full/minify/libraries/moment 79124443 ns/iter (± 4906774) 71919387 ns/iter (± 3575082) 1.10
es/full/minify/libraries/react 25589507 ns/iter (± 578651) 24503182 ns/iter (± 880294) 1.04
es/full/minify/libraries/terser 406248367 ns/iter (± 21821112) 378318075 ns/iter (± 39827738) 1.07
es/full/minify/libraries/three 706062144 ns/iter (± 23583724) 685640247 ns/iter (± 104136558) 1.03
es/full/minify/libraries/typescript 4221221627 ns/iter (± 121685963) 4052237645 ns/iter (± 153348857) 1.04
es/full/minify/libraries/victory 1024790720 ns/iter (± 19998090) 957717635 ns/iter (± 103297817) 1.07
es/full/minify/libraries/vue 188582772 ns/iter (± 5843675) 162582568 ns/iter (± 9303358) 1.16
es/full/codegen/es3 34636 ns/iter (± 3755) 32916 ns/iter (± 1234) 1.05
es/full/codegen/es5 34774 ns/iter (± 4538) 32833 ns/iter (± 1286) 1.06
es/full/codegen/es2015 35947 ns/iter (± 3677) 33064 ns/iter (± 1783) 1.09
es/full/codegen/es2016 35631 ns/iter (± 3634) 32998 ns/iter (± 1452) 1.08
es/full/codegen/es2017 36075 ns/iter (± 6066) 33132 ns/iter (± 1260) 1.09
es/full/codegen/es2018 34889 ns/iter (± 2152) 33167 ns/iter (± 1748) 1.05
es/full/codegen/es2019 35648 ns/iter (± 4410) 32964 ns/iter (± 1267) 1.08
es/full/codegen/es2020 35419 ns/iter (± 3829) 32928 ns/iter (± 3363) 1.08
es/full/all/es3 209952966 ns/iter (± 11101178) 187886747 ns/iter (± 6571520) 1.12
es/full/all/es5 198033056 ns/iter (± 13179985) 178318446 ns/iter (± 6800383) 1.11
es/full/all/es2015 158388755 ns/iter (± 13187496) 144149868 ns/iter (± 9395850) 1.10
es/full/all/es2016 154823462 ns/iter (± 8485256) 143293434 ns/iter (± 5463236) 1.08
es/full/all/es2017 152894154 ns/iter (± 9587760) 143052243 ns/iter (± 4937879) 1.07
es/full/all/es2018 166113519 ns/iter (± 15015915) 141652076 ns/iter (± 5061229) 1.17
es/full/all/es2019 151687336 ns/iter (± 10630000) 139558971 ns/iter (± 3978065) 1.09
es/full/all/es2020 146928926 ns/iter (± 10998217) 134793159 ns/iter (± 5523055) 1.09
es/full/parser 757962 ns/iter (± 48486) 706950 ns/iter (± 29387) 1.07
es/full/base/fixer 28470 ns/iter (± 3668) 26105 ns/iter (± 2823) 1.09
es/full/base/resolver_and_hygiene 96228 ns/iter (± 11167) 90271 ns/iter (± 6723) 1.07
serialization of ast node 227 ns/iter (± 37) 205 ns/iter (± 14) 1.11
serialization of serde 225 ns/iter (± 24) 218 ns/iter (± 8) 1.03

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.