Skip to content

Commit

Permalink
feat(html/ast): Add raw to comment tokens (#6202)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Oct 19, 2022
1 parent 6008995 commit 99ea286
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/swc_html_ast/src/token.rs
Expand Up @@ -72,7 +72,7 @@ pub enum Token {
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
data: JsWord,
#[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))]
raw: JsWord,
raw: Option<JsWord>,
},
Character {
value: char,
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_html_parser/src/lexer/mod.rs
Expand Up @@ -826,7 +826,7 @@ where

self.emit_token(Token::Comment {
data: comment.data.into(),
raw: comment.raw.into(),
raw: Some(comment.raw.into()),
});
}

Expand Down
6 changes: 3 additions & 3 deletions crates/swc_html_parser/src/parser/mod.rs
Expand Up @@ -8388,7 +8388,7 @@ where
// node document is the same as that of the node in which the adjusted
// insertion location finds itself.
let (data, raw) = match &token_and_info.token {
Token::Comment { data, raw } => (data.clone(), Some(raw.clone())),
Token::Comment { data, raw } => (data.clone(), raw.clone()),
_ => {
unreachable!()
}
Expand All @@ -8407,7 +8407,7 @@ where
token_and_info: &mut TokenAndInfo,
) -> PResult<()> {
let (data, raw) = match &token_and_info.token {
Token::Comment { data, raw } => (data.clone(), Some(raw.clone())),
Token::Comment { data, raw } => (data.clone(), raw.clone()),
_ => {
unreachable!()
}
Expand All @@ -8427,7 +8427,7 @@ where
token_and_info: &mut TokenAndInfo,
) -> PResult<()> {
let (data, raw) = match &token_and_info.token {
Token::Comment { data, raw } => (data.clone(), Some(raw.clone())),
Token::Comment { data, raw } => (data.clone(), raw.clone()),
_ => {
unreachable!()
}
Expand Down
6 changes: 3 additions & 3 deletions crates/swc_html_parser/tests/html5lib_tests.rs
Expand Up @@ -2,7 +2,7 @@ use std::{fs, mem::take, path::PathBuf};

use common::{document_span_visualizer, DomVisualizer};
use serde_json::Value;
use swc_atoms::{js_word, JsWord};
use swc_atoms::JsWord;
use swc_common::{
collections::AHashSet,
input::{SourceFileInput, StringInput},
Expand Down Expand Up @@ -210,7 +210,7 @@ fn html5lib_test_tokenizer(input: PathBuf) {
*raw = None;
}
Token::Comment { ref mut raw, .. } => {
*raw = js_word!("");
*raw = None;
}
_ => {}
}
Expand Down Expand Up @@ -355,7 +355,7 @@ fn html5lib_test_tokenizer(input: PathBuf) {

vec![Token::Comment {
data: data.into(),
raw: js_word!(""),
raw: None,
}]
}
_ => {
Expand Down

1 comment on commit 99ea286

@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: 99ea286 Previous: 27896f4 Ratio
es/full/bugs-1 389601 ns/iter (± 57281) 374708 ns/iter (± 32750) 1.04
es/full/minify/libraries/antd 1920340028 ns/iter (± 61967826) 1895751577 ns/iter (± 21523509) 1.01
es/full/minify/libraries/d3 408312388 ns/iter (± 48265823) 494192137 ns/iter (± 93926042) 0.83
es/full/minify/libraries/echarts 1629107642 ns/iter (± 62234232) 1800190141 ns/iter (± 152745755) 0.90
es/full/minify/libraries/jquery 112639741 ns/iter (± 4041419) 113958951 ns/iter (± 10620325) 0.99
es/full/minify/libraries/lodash 125585395 ns/iter (± 10837244) 127087182 ns/iter (± 49398199) 0.99
es/full/minify/libraries/moment 65491558 ns/iter (± 7286557) 65646363 ns/iter (± 11151521) 1.00
es/full/minify/libraries/react 22407665 ns/iter (± 1357996) 21744994 ns/iter (± 1479840) 1.03
es/full/minify/libraries/terser 358743346 ns/iter (± 69821294) 340289446 ns/iter (± 30887387) 1.05
es/full/minify/libraries/three 588175705 ns/iter (± 35605830) 614909961 ns/iter (± 71872684) 0.96
es/full/minify/libraries/typescript 3763382371 ns/iter (± 198175943) 3611576399 ns/iter (± 147913647) 1.04
es/full/minify/libraries/victory 846620655 ns/iter (± 47875327) 854858180 ns/iter (± 29740583) 0.99
es/full/minify/libraries/vue 167705638 ns/iter (± 8230891) 160368182 ns/iter (± 11836301) 1.05
es/full/codegen/es3 33756 ns/iter (± 735) 35754 ns/iter (± 3321) 0.94
es/full/codegen/es5 34505 ns/iter (± 2419) 35284 ns/iter (± 1226) 0.98
es/full/codegen/es2015 34584 ns/iter (± 3165) 36706 ns/iter (± 4245) 0.94
es/full/codegen/es2016 34227 ns/iter (± 2982) 35260 ns/iter (± 3008) 0.97
es/full/codegen/es2017 34470 ns/iter (± 3113) 35248 ns/iter (± 2495) 0.98
es/full/codegen/es2018 34696 ns/iter (± 4977) 35005 ns/iter (± 1762) 0.99
es/full/codegen/es2019 34694 ns/iter (± 6109) 35585 ns/iter (± 2862) 0.97
es/full/codegen/es2020 33731 ns/iter (± 1060) 35796 ns/iter (± 10968) 0.94
es/full/all/es3 230068765 ns/iter (± 28754522) 227973473 ns/iter (± 25303507) 1.01
es/full/all/es5 212593710 ns/iter (± 26997668) 204443882 ns/iter (± 16966537) 1.04
es/full/all/es2015 165119079 ns/iter (± 21217551) 158674105 ns/iter (± 20111933) 1.04
es/full/all/es2016 165672284 ns/iter (± 22713903) 180409133 ns/iter (± 19006825) 0.92
es/full/all/es2017 167045055 ns/iter (± 18041469) 171952464 ns/iter (± 19818755) 0.97
es/full/all/es2018 159941886 ns/iter (± 15168167) 161231415 ns/iter (± 13632694) 0.99
es/full/all/es2019 150383439 ns/iter (± 23045898) 143038346 ns/iter (± 12052467) 1.05
es/full/all/es2020 161355544 ns/iter (± 16117223) 139128608 ns/iter (± 4637336) 1.16
es/full/parser 761642 ns/iter (± 183940) 761644 ns/iter (± 97451) 1.00
es/full/base/fixer 27322 ns/iter (± 2183) 27025 ns/iter (± 2956) 1.01
es/full/base/resolver_and_hygiene 96613 ns/iter (± 8781) 96477 ns/iter (± 5171) 1.00
serialization of ast node 215 ns/iter (± 7) 216 ns/iter (± 7) 1.00
serialization of serde 222 ns/iter (± 9) 219 ns/iter (± 8) 1.01

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

Please sign in to comment.