diff --git a/crates/swc_html_ast/src/base.rs b/crates/swc_html_ast/src/base.rs index b4436f31b41..6b8ced94ae2 100644 --- a/crates/swc_html_ast/src/base.rs +++ b/crates/swc_html_ast/src/base.rs @@ -82,6 +82,8 @@ pub struct Element { #[derive(Eq, Hash, EqIgnoreSpan)] pub struct Attribute { pub span: Span, + pub namespace: Option, + pub prefix: Option, pub name: JsWord, pub value: Option, } diff --git a/crates/swc_html_codegen/src/lib.rs b/crates/swc_html_codegen/src/lib.rs index b18ae38aa83..64dc244e04a 100644 --- a/crates/swc_html_codegen/src/lib.rs +++ b/crates/swc_html_codegen/src/lib.rs @@ -103,6 +103,12 @@ where for attribute in &n.attributes { start_tag.push(' '); + + if let Some(prefix) = &attribute.prefix { + start_tag.push_str(prefix); + start_tag.push(':'); + } + start_tag.push_str(&attribute.name); if let Some(value) = &attribute.value { diff --git a/crates/swc_html_codegen/tests/fixture/comment/basic/input.html b/crates/swc_html_codegen/tests/fixture/comment/basic/input.html new file mode 100644 index 00000000000..a3b99c6a08f --- /dev/null +++ b/crates/swc_html_codegen/tests/fixture/comment/basic/input.html @@ -0,0 +1,60 @@ + + + + + + + Document + + + + + + + +
+ + test + +
+

+ + + + + + + + + + + According to the conditional comment this is not IE 5-9
+ +

+ + \ No newline at end of file diff --git a/crates/swc_html_codegen/tests/fixture/comment/basic/output.html b/crates/swc_html_codegen/tests/fixture/comment/basic/output.html new file mode 100644 index 00000000000..9cbdd769c41 --- /dev/null +++ b/crates/swc_html_codegen/tests/fixture/comment/basic/output.html @@ -0,0 +1,57 @@ + + + + + Document + + + + + + + +
+ + test + +
+

+ + + + + + + + + + + According to the conditional comment this is not IE 5-9
+ +

+ + diff --git a/crates/swc_html_codegen/tests/fixture/comment/basic/output.min.html b/crates/swc_html_codegen/tests/fixture/comment/basic/output.min.html new file mode 100644 index 00000000000..9cbdd769c41 --- /dev/null +++ b/crates/swc_html_codegen/tests/fixture/comment/basic/output.min.html @@ -0,0 +1,57 @@ + + + + + Document + + + + + + + +
+ + test + +
+

+ + + + + + + + + + + According to the conditional comment this is not IE 5-9
+ +

+ + diff --git a/crates/swc_html_codegen/tests/fixture/comment/ie/input.html b/crates/swc_html_codegen/tests/fixture/comment/ie/input.html new file mode 100644 index 00000000000..21ec66d46b9 --- /dev/null +++ b/crates/swc_html_codegen/tests/fixture/comment/ie/input.html @@ -0,0 +1,16 @@ + + + + + + + Document + + + +

This is shown in downlevel browsers.

+ + + + \ No newline at end of file diff --git a/crates/swc_html_codegen/tests/fixture/comment/ie/output.html b/crates/swc_html_codegen/tests/fixture/comment/ie/output.html new file mode 100644 index 00000000000..048b0ef1272 --- /dev/null +++ b/crates/swc_html_codegen/tests/fixture/comment/ie/output.html @@ -0,0 +1,13 @@ + + + + + Document + + + +

This is shown in downlevel browsers.

+ + + + diff --git a/crates/swc_html_codegen/tests/fixture/comment/ie/output.min.html b/crates/swc_html_codegen/tests/fixture/comment/ie/output.min.html new file mode 100644 index 00000000000..048b0ef1272 --- /dev/null +++ b/crates/swc_html_codegen/tests/fixture/comment/ie/output.min.html @@ -0,0 +1,13 @@ + + + + + Document + + + +

This is shown in downlevel browsers.

+ + + + diff --git a/crates/swc_html_codegen/tests/fixture/svg-tag/input.html b/crates/swc_html_codegen/tests/fixture/svg-tag/input.html new file mode 100644 index 00000000000..c80a900fdf0 --- /dev/null +++ b/crates/swc_html_codegen/tests/fixture/svg-tag/input.html @@ -0,0 +1,18 @@ + + + + + + + Document + + + + + + + \ No newline at end of file diff --git a/crates/swc_html_codegen/tests/fixture/svg-tag/output.html b/crates/swc_html_codegen/tests/fixture/svg-tag/output.html new file mode 100644 index 00000000000..994f3e7f359 --- /dev/null +++ b/crates/swc_html_codegen/tests/fixture/svg-tag/output.html @@ -0,0 +1,12 @@ + + + + + Document + + + + + + + diff --git a/crates/swc_html_codegen/tests/fixture/svg-tag/output.min.html b/crates/swc_html_codegen/tests/fixture/svg-tag/output.min.html new file mode 100644 index 00000000000..994f3e7f359 --- /dev/null +++ b/crates/swc_html_codegen/tests/fixture/svg-tag/output.min.html @@ -0,0 +1,12 @@ + + + + + Document + + + + + + + diff --git a/crates/swc_html_parser/src/parser/mod.rs b/crates/swc_html_parser/src/parser/mod.rs index 91033a1b464..051bcce1a2f 100644 --- a/crates/swc_html_parser/src/parser/mod.rs +++ b/crates/swc_html_parser/src/parser/mod.rs @@ -4,7 +4,6 @@ use active_formatting_element_stack::*; use doctypes::*; use node::*; use open_elements_stack::*; -use swc_atoms::JsWord; use swc_common::Span; use swc_html_ast::*; @@ -30,6 +29,11 @@ pub struct ParserConfig { pub scripting_enabled: bool, } +enum AdjustAttributes { + MathML, + Svg, +} + #[derive(Debug, Clone)] pub struct TokenAndInfo { pub span: Span, @@ -646,7 +650,7 @@ where attributes, .. } if tag_name == "html" => { - let element = create_node_for_element(Element { + let element = Node::new(Data::Element(Element { span: span!(self, token_and_info.span.lo), namespace: Namespace::HTML, tag_name: tag_name.into(), @@ -654,13 +658,15 @@ where .iter() .map(|attribute| Attribute { span: Default::default(), + namespace: None, + prefix: None, name: attribute.name.clone(), value: attribute.value.clone(), }) .collect(), children: vec![], content: None, - }); + })); self.open_elements_stack.push(element.clone()); @@ -988,11 +994,12 @@ where let last_pos = self.input.last_pos()?; let adjusted_insertion_location = self.get_appropriate_place_for_inserting_node(None); - let node = create_node_for_element(create_element_for_token( + let node = Node::new(Data::Element(self.create_element_for_token( token_and_info.token.clone(), Span::new(token_and_info.span.lo, last_pos, Default::default()), Some(Namespace::HTML), - )?); + None, + ))); // Skip script handling @@ -3104,9 +3111,11 @@ where let is_self_closing = *self_closing; self.reconstruct_active_formatting_elements()?; - self.adjust_math_ml_attributes(token_and_info); - self.adjust_foreign_attributes_for_the_token(token_and_info); - self.insert_foreign_element(token_and_info, Namespace::MATHML)?; + self.insert_foreign_element( + token_and_info, + Namespace::SVG, + Some(AdjustAttributes::MathML), + )?; if is_self_closing { token_and_info.acknowledged = true; @@ -3134,9 +3143,11 @@ where let is_self_closing = *self_closing; self.reconstruct_active_formatting_elements()?; - self.adjust_svg_attributes(token_and_info); - self.adjust_foreign_attributes_for_the_token(token_and_info); - self.insert_foreign_element(token_and_info, Namespace::SVG)?; + self.insert_foreign_element( + token_and_info, + Namespace::SVG, + Some(AdjustAttributes::Svg), + )?; if is_self_closing { token_and_info.acknowledged = true; @@ -5472,96 +5483,290 @@ where Ok(()) } - fn adjust_attributes(&mut self, token_and_info: &mut TokenAndInfo, mut map: F) - where - F: FnMut(JsWord) -> Option, - { - let attributes = match &mut token_and_info.token { - Token::StartTag { attributes, .. } => attributes, - _ => { - unreachable!(); - } - }; - - for &mut AttributeToken { ref mut name, .. } in attributes { - if let Some(replacement) = map(name.clone()) { - *name = replacement; - } + // When the steps below require the user agent to adjust MathML attributes for a + // token, then, if the token has an attribute named definitionurl, change its + // name to definitionURL (note the case difference). + fn adjust_math_ml_attribute(&self, attribute: &mut Attribute) { + if &*attribute.name == "definitionurl" { + attribute.name = "definitionURL".into(); } } - fn adjust_math_ml_attributes(&mut self, token_and_info: &mut TokenAndInfo) { - self.adjust_attributes(token_and_info, |attribute| match &*attribute { - "definitionurl" => Some("definitionURL".into()), - _ => None, - }); + // When the steps below require the user agent to adjust SVG attributes for a + // token, then, for each attribute on the token whose attribute name is one of + // the ones in the first column of the following table, change the attribute's + // name to the name given in the corresponding cell in the second column. (This + // fixes the case of SVG attributes that are not all lowercase.) + // + // Attribute name on token Attribute name on element + // attributename attributeName + // attributetype attributeType + // basefrequency baseFrequency + // baseprofile baseProfile + // calcmode calcMode + // clippathunits clipPathUnits + // diffuseconstant diffuseConstant + // edgemode edgeMode + // filterunits filterUnits + // glyphref glyphRef + // gradienttransform gradientTransform + // gradientunits gradientUnits + // kernelmatrix kernelMatrix + // kernelunitlength kernelUnitLength + // keypoints keyPoints + // keysplines keySplines + // keytimes keyTimes + // lengthadjust lengthAdjust + // limitingconeangle limitingConeAngle + // markerheight markerHeight + // markerunits markerUnits + // markerwidth markerWidth + // maskcontentunits maskContentUnits + // maskunits maskUnits + // numoctaves numOctaves + // pathlength pathLength + // patterncontentunits patternContentUnits + // patterntransform patternTransform + // patternunits patternUnits + // pointsatx pointsAtX + // pointsaty pointsAtY + // pointsatz pointsAtZ + // preservealpha preserveAlpha + // preserveaspectratio preserveAspectRatio + // primitiveunits primitiveUnits + // refx refX + // refy refY + // repeatcount repeatCount + // repeatdur repeatDur + // requiredextensions requiredExtensions + // requiredfeatures requiredFeatures + // specularconstant specularConstant + // specularexponent specularExponent + // spreadmethod spreadMethod + // startoffset startOffset + // stddeviation stdDeviation + // stitchtiles stitchTiles + // surfacescale surfaceScale + // systemlanguage systemLanguage + // tablevalues tableValues + // targetx targetX + // targety targetY + // textlength textLength + // viewbox viewBox + // viewtarget viewTarget + // xchannelselector xChannelSelector + // ychannelselector yChannelSelector + // zoomandpan zoomAndPan + fn adjust_svg_attribute(&self, attribute: &mut Attribute) { + match &*attribute.name { + "attributename" => { + attribute.name = "attributeName".into(); + } + "attributetype" => attribute.name = "attributeType".into(), + "basefrequency" => attribute.name = "baseFrequency".into(), + "baseprofile" => attribute.name = "baseProfile".into(), + "calcmode" => attribute.name = "calcMode".into(), + "clippathunits" => attribute.name = "clipPathUnits".into(), + "diffuseconstant" => attribute.name = "diffuseConstant".into(), + "edgemode" => attribute.name = "edgeMode".into(), + "filterunits" => attribute.name = "filterUnits".into(), + "glyphref" => attribute.name = "glyphRef".into(), + "gradienttransform" => attribute.name = "gradientTransform".into(), + "gradientunits" => attribute.name = "gradientUnits".into(), + "kernelmatrix" => attribute.name = "kernelMatrix".into(), + "kernelunitlength" => attribute.name = "kernelUnitLength".into(), + "keypoints" => attribute.name = "keyPoints".into(), + "keysplines" => attribute.name = "keySplines".into(), + "keytimes" => attribute.name = "keyTimes".into(), + "lengthadjust" => attribute.name = "lengthAdjust".into(), + "limitingconeangle" => attribute.name = "limitingConeAngle".into(), + "markerheight" => attribute.name = "markerHeight".into(), + "markerunits" => attribute.name = "markerUnits".into(), + "markerwidth" => attribute.name = "markerWidth".into(), + "maskcontentunits" => attribute.name = "maskContentUnits".into(), + "maskunits" => attribute.name = "maskUnits".into(), + "numoctaves" => attribute.name = "numOctaves".into(), + "pathlength" => attribute.name = "pathLength".into(), + "patterncontentunits" => attribute.name = "patternContentUnits".into(), + "patterntransform" => attribute.name = "patternTransform".into(), + "patternunits" => attribute.name = "patternUnits".into(), + "pointsatx" => attribute.name = "pointsAtX".into(), + "pointsaty" => attribute.name = "pointsAtY".into(), + "pointsatz" => attribute.name = "pointsAtZ".into(), + "preservealpha" => attribute.name = "preserveAlpha".into(), + "preserveaspectratio" => attribute.name = "preserveAspectRatio".into(), + "primitiveunits" => attribute.name = "primitiveUnits".into(), + "refx" => attribute.name = "refX".into(), + "refy" => attribute.name = "refY".into(), + "repeatcount" => attribute.name = "repeatCount".into(), + "repeatdur" => attribute.name = "repeatDur".into(), + "requiredextensions" => attribute.name = "requiredExtensions".into(), + "requiredfeatures" => attribute.name = "requiredFeatures".into(), + "specularconstant" => attribute.name = "specularConstant".into(), + "specularexponent" => attribute.name = "specularExponent".into(), + "spreadmethod" => attribute.name = "spreadMethod".into(), + "startoffset" => attribute.name = "startOffset".into(), + "stddeviation" => attribute.name = "stdDeviation".into(), + "stitchtiles" => attribute.name = "stitchTiles".into(), + "surfacescale" => attribute.name = "surfaceScale".into(), + "systemlanguage" => attribute.name = "systemLanguage".into(), + "tablevalues" => attribute.name = "tableValues".into(), + "targetx" => attribute.name = "targetX".into(), + "targety" => attribute.name = "targetY".into(), + "textlength" => attribute.name = "textLength".into(), + "viewbox" => attribute.name = "viewBox".into(), + "viewtarget" => attribute.name = "viewTarget".into(), + "xchannelselector" => attribute.name = "xChannelSelector".into(), + "ychannelselector" => attribute.name = "yChannelSelector".into(), + "zoomandpan" => attribute.name = "zoomAndPan".into(), + _ => {} + } } - fn adjust_svg_attributes(&mut self, token_and_info: &mut TokenAndInfo) { - self.adjust_attributes(token_and_info, |attribute| match &*attribute { - "attributename" => Some("attributeName".into()), - "attributetype" => Some("attributeType".into()), - "basefrequency" => Some("baseFrequency".into()), - "baseprofile" => Some("baseProfile".into()), - "calcmode" => Some("calcMode".into()), - "clippathunits" => Some("clipPathUnits".into()), - "diffuseconstant" => Some("diffuseConstant".into()), - "edgemode" => Some("edgeMode".into()), - "filterunits" => Some("filterUnits".into()), - "glyphref" => Some("glyphRef".into()), - "gradienttransform" => Some("gradientTransform".into()), - "gradientunits" => Some("gradientUnits".into()), - "kernelmatrix" => Some("kernelMatrix".into()), - "kernelunitlength" => Some("kernelUnitLength".into()), - "keypoints" => Some("keyPoints".into()), - "keysplines" => Some("keySplines".into()), - "keytimes" => Some("keyTimes".into()), - "lengthadjust" => Some("lengthAdjust".into()), - "limitingconeangle" => Some("limitingConeAngle".into()), - "markerheight" => Some("markerHeight".into()), - "markerunits" => Some("markerUnits".into()), - "markerwidth" => Some("markerWidth".into()), - "maskcontentunits" => Some("maskContentUnits".into()), - "maskunits" => Some("maskUnits".into()), - "numoctaves" => Some("numOctaves".into()), - "pathlength" => Some("pathLength".into()), - "patterncontentunits" => Some("patternContentUnits".into()), - "patterntransform" => Some("patternTransform".into()), - "patternunits" => Some("patternUnits".into()), - "pointsatx" => Some("pointsAtX".into()), - "pointsaty" => Some("pointsAtY".into()), - "pointsatz" => Some("pointsAtZ".into()), - "preservealpha" => Some("preserveAlpha".into()), - "preserveaspectratio" => Some("preserveAspectRatio".into()), - "primitiveunits" => Some("primitiveUnits".into()), - "refx" => Some("refX".into()), - "refy" => Some("refY".into()), - "repeatcount" => Some("repeatCount".into()), - "repeatdur" => Some("repeatDur".into()), - "requiredextensions" => Some("requiredExtensions".into()), - "requiredfeatures" => Some("requiredFeatures".into()), - "specularconstant" => Some("specularConstant".into()), - "specularexponent" => Some("specularExponent".into()), - "spreadmethod" => Some("spreadMethod".into()), - "startoffset" => Some("startOffset".into()), - "stddeviation" => Some("stdDeviation".into()), - "stitchtiles" => Some("stitchTiles".into()), - "surfacescale" => Some("surfaceScale".into()), - "systemlanguage" => Some("systemLanguage".into()), - "tablevalues" => Some("tableValues".into()), - "targetx" => Some("targetX".into()), - "targety" => Some("targetY".into()), - "textlength" => Some("textLength".into()), - "viewbox" => Some("viewBox".into()), - "viewtarget" => Some("viewTarget".into()), - "xchannelselector" => Some("xChannelSelector".into()), - "ychannelselector" => Some("yChannelSelector".into()), - "zoomandpan" => Some("zoomAndPan".into()), - _ => None, - }); + // When the steps below require the user agent to adjust foreign attributes for + // a token, then, if any of the attributes on the token match the strings given + // in the first column of the following table, let the attribute be a namespaced + // attribute, with the prefix being the string given in the corresponding cell + // in the second column, the local name being the string given in the + // corresponding cell in the third column, and the namespace being the namespace + // given in the corresponding cell in the fourth column. (This fixes the use of + // namespaced attributes, in particular lang attributes in the XML namespace.) + // + // + // Attribute name Prefix Local name Namespace + // + // xlink:actuate xlink actuate XLink namespace + // xlink:arcrole xlink arcrole XLink namespace + // xlink:href xlink href XLink namespace + // xlink:role xlink role XLink namespace + // xlink:show xlink show XLink namespace + // xlink:title xlink title XLink namespace + // xlink:type xlink type XLink namespace + // xml:lang xml lang XML namespace + // xml:space xml space XML namespace + // xmlns (none) xmlns XMLNS namespace + // xmlns:xlink xmlns xlink XMLNS namespace + fn adjust_foreign_attribute(&self, attribute: &mut Attribute) { + match &*attribute.name { + "xlink:actuate" => { + attribute.namespace = Some(Namespace::XLINK); + attribute.prefix = Some("xlink".into()); + attribute.name = "actuate".into(); + } + "xlink:arcrole" => { + attribute.namespace = Some(Namespace::XLINK); + attribute.prefix = Some("xlink".into()); + attribute.name = "arcrole".into(); + } + "xlink:href" => { + attribute.namespace = Some(Namespace::XLINK); + attribute.prefix = Some("xlink".into()); + attribute.name = "href".into(); + } + "xlink:role" => { + attribute.namespace = Some(Namespace::XLINK); + attribute.prefix = Some("xlink".into()); + attribute.name = "role".into(); + } + "xlink:show" => { + attribute.namespace = Some(Namespace::XLINK); + attribute.prefix = Some("xlink".into()); + attribute.name = "show".into(); + } + "xlink:title" => { + attribute.namespace = Some(Namespace::XLINK); + attribute.prefix = Some("xlink".into()); + attribute.name = "title".into(); + } + "xlink:type" => { + attribute.namespace = Some(Namespace::XLINK); + attribute.prefix = Some("xlink".into()); + attribute.name = "type".into(); + } + "xml:lang" => { + attribute.namespace = Some(Namespace::XML); + attribute.prefix = Some("xml".into()); + attribute.name = "lang".into(); + } + "xml:space" => { + attribute.namespace = Some(Namespace::XML); + attribute.prefix = Some("xml".into()); + attribute.name = "space".into(); + } + "xmlns" => { + attribute.namespace = Some(Namespace::XMLNS); + attribute.prefix = None; + attribute.name = "xmlns".into(); + } + "xmlns:xlink" => { + attribute.namespace = Some(Namespace::XMLNS); + attribute.prefix = Some("xmlns".into()); + attribute.name = "xlink".into(); + } + _ => {} + } } - fn adjust_foreign_attributes_for_the_token(&mut self, _token_and_info: &mut TokenAndInfo) {} + fn create_element_for_token( + &self, + token: Token, + span: Span, + namespace: Option, + adjust_attributes: Option, + ) -> Element { + match token { + Token::StartTag { + tag_name, + attributes, + .. + } + | Token::EndTag { + tag_name, + attributes, + .. + } => { + // TODO span + let attributes = attributes + .into_iter() + .map(|attribute_token| { + let mut attribute = Attribute { + span: Default::default(), + namespace: None, + prefix: None, + name: attribute_token.name.clone(), + value: attribute_token.value, + }; + + match adjust_attributes { + Some(AdjustAttributes::MathML) => { + self.adjust_math_ml_attribute(&mut attribute); + self.adjust_foreign_attribute(&mut attribute); + } + Some(AdjustAttributes::Svg) => { + self.adjust_svg_attribute(&mut attribute); + self.adjust_foreign_attribute(&mut attribute); + } + None => {} + } + + attribute + }) + .collect(); + + Element { + span, + tag_name, + namespace: namespace.unwrap(), + attributes, + children: vec![], + content: None, + } + } + _ => { + unreachable!(); + } + } + } // The adoption agency algorithm, which takes as its only argument a token token // for which the algorithm is being run, consists of the following steps: @@ -6395,13 +6600,14 @@ where } fn insert_html_element(&mut self, token_and_info: &mut TokenAndInfo) -> PResult { - self.insert_foreign_element(token_and_info, Namespace::HTML) + self.insert_foreign_element(token_and_info, Namespace::HTML, None) } fn insert_foreign_element( &mut self, token_and_info: &mut TokenAndInfo, namespace: Namespace, + adjust_attributes: Option, ) -> PResult { // Let the adjusted insertion location be the appropriate place for // inserting a node. @@ -6420,12 +6626,13 @@ where // intended parent being the element in which the adjusted insertion // location finds itself. let last_pos = self.input.last_pos()?; - let element = create_element_for_token( + let element = self.create_element_for_token( token_and_info.token.clone(), Span::new(token_and_info.span.lo, last_pos, Default::default()), Some(namespace), - )?; - let node = create_node_for_element(element); + adjust_attributes, + ); + let node = Node::new(Data::Element(element)); // If it is possible to insert an element at the adjusted insertion // location, then insert the newly created element at the adjusted @@ -6521,56 +6728,11 @@ where } } -fn create_node_for_element(element: Element) -> RcNode { - Node::new(Data::Element(element)) -} - // TODO eq with/without span? fn is_same_node(a: &RcNode, b: &RcNode) -> bool { Rc::ptr_eq(a, b) } -fn create_element_for_token( - token: Token, - span: Span, - namespace: Option, -) -> PResult { - let element = match token { - Token::StartTag { - tag_name, - attributes, - .. - } - | Token::EndTag { - tag_name, - attributes, - .. - } => { - Element { - span, - tag_name, - namespace: namespace.unwrap(), - // TODO span - attributes: attributes - .into_iter() - .map(|attribute| Attribute { - span: Default::default(), - name: attribute.name.clone(), - value: attribute.value, - }) - .collect(), - children: vec![], - content: None, - } - } - _ => { - unreachable!(); - } - }; - - Ok(element) -} - impl Parse for Parser where I: ParserInput, diff --git a/crates/swc_html_parser/tests/fixture/attribute-without-quotes/output.json b/crates/swc_html_parser/tests/fixture/attribute-without-quotes/output.json index 4e7ce2bbc08..d2cc9a20986 100644 --- a/crates/swc_html_parser/tests/fixture/attribute-without-quotes/output.json +++ b/crates/swc_html_parser/tests/fixture/attribute-without-quotes/output.json @@ -79,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "href", "value": "https://www.w3schools.com" } diff --git a/crates/swc_html_parser/tests/fixture/attributes/output.json b/crates/swc_html_parser/tests/fixture/attributes/output.json index 74ae67cb572..e4069f7e300 100644 --- a/crates/swc_html_parser/tests/fixture/attributes/output.json +++ b/crates/swc_html_parser/tests/fixture/attributes/output.json @@ -59,6 +59,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "0", "value": null }, @@ -69,6 +71,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "1", "value": null }, @@ -79,6 +83,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "2", "value": null }, @@ -89,6 +95,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "3", "value": null }, @@ -99,6 +107,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "4", "value": null }, @@ -109,6 +119,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "5", "value": null }, @@ -119,6 +131,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "6", "value": null }, @@ -129,6 +143,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "7", "value": null }, @@ -139,6 +155,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "8", "value": null }, @@ -149,6 +167,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "9", "value": null }, @@ -159,6 +179,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "a", "value": null }, @@ -169,6 +191,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "b", "value": null }, @@ -179,6 +203,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "c", "value": null }, @@ -189,6 +215,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "d", "value": null }, @@ -199,6 +227,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "e", "value": null }, @@ -209,6 +239,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "f", "value": null }, @@ -219,6 +251,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "g", "value": null }, @@ -229,6 +263,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "h", "value": null }, @@ -239,6 +275,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "i", "value": null }, @@ -249,6 +287,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "j", "value": null }, @@ -259,6 +299,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "k", "value": null }, @@ -269,6 +311,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "l", "value": null }, @@ -279,6 +323,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "m", "value": null }, @@ -289,6 +335,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "n", "value": null }, @@ -299,6 +347,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "o", "value": null }, @@ -309,6 +359,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "p", "value": null }, @@ -319,6 +371,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "q", "value": null }, @@ -329,6 +383,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "r", "value": null }, @@ -339,6 +395,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "s", "value": null }, @@ -349,6 +407,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "t", "value": null }, @@ -359,6 +419,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "u", "value": null }, @@ -369,6 +431,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "v", "value": null }, @@ -379,6 +443,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "w", "value": null }, @@ -389,6 +455,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "x", "value": null }, @@ -399,6 +467,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "y", "value": null }, @@ -409,6 +479,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "z", "value": null } @@ -440,6 +512,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "title", "value": " " } @@ -483,6 +557,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "title", "value": " " } @@ -526,6 +602,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "v-ref:vm_pv", "value": null }, @@ -536,6 +614,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": ":imgs", "value": " objpicsurl_ " } @@ -569,6 +649,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "a", "value": "\\u00A0" }, @@ -579,6 +661,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "b", "value": " " }, @@ -589,6 +673,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "c", "value": "\\u00A0" } @@ -622,6 +708,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "src", "value": "test" } diff --git a/crates/swc_html_parser/tests/fixture/broken-br/output.json b/crates/swc_html_parser/tests/fixture/broken-br/output.json index 14340229fec..b196f25cebc 100644 --- a/crates/swc_html_parser/tests/fixture/broken-br/output.json +++ b/crates/swc_html_parser/tests/fixture/broken-br/output.json @@ -35,6 +35,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "lang", "value": "en" } @@ -77,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "charset", "value": "UTF-8" } @@ -110,6 +114,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "viewport" }, @@ -120,6 +126,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" } @@ -153,6 +161,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "http-equiv", "value": "X-UA-Compatible" }, @@ -163,6 +173,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "ie=edge" } diff --git a/crates/swc_html_parser/tests/fixture/broken-doctype/output.json b/crates/swc_html_parser/tests/fixture/broken-doctype/output.json index b73aaadccb0..41ef53cbfa2 100644 --- a/crates/swc_html_parser/tests/fixture/broken-doctype/output.json +++ b/crates/swc_html_parser/tests/fixture/broken-doctype/output.json @@ -79,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "href", "value": "https://www.w3schools.com" } diff --git a/crates/swc_html_parser/tests/fixture/class-attribute/output.json b/crates/swc_html_parser/tests/fixture/class-attribute/output.json index 0ce6548b983..157d97e4902 100644 --- a/crates/swc_html_parser/tests/fixture/class-attribute/output.json +++ b/crates/swc_html_parser/tests/fixture/class-attribute/output.json @@ -59,6 +59,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z" } @@ -90,6 +92,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "add sort keys createSorter" } @@ -121,6 +125,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "sprite sprite-{{sprite}}" } @@ -154,6 +160,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "{{sprite}}-sprite sprite" } @@ -187,6 +195,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "sprite-{{sprite}}-sprite" } @@ -220,6 +230,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "{{sprite}}" } @@ -253,6 +265,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "{{sprite}}" } @@ -286,6 +300,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": null } @@ -319,6 +335,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "nav_sv_fo_v_column <#=(j === 0) ? 'nav_sv_fo_v_first' : '' #> foo_bar" } @@ -352,6 +370,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "moo bar foo baz" } diff --git a/crates/swc_html_parser/tests/fixture/comment/after-body/output.json b/crates/swc_html_parser/tests/fixture/comment/after-body/output.json index a747c7deca2..0a029959d8e 100644 --- a/crates/swc_html_parser/tests/fixture/comment/after-body/output.json +++ b/crates/swc_html_parser/tests/fixture/comment/after-body/output.json @@ -35,6 +35,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "lang", "value": "en" } @@ -77,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "charset", "value": "UTF-8" } @@ -110,6 +114,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "viewport" }, @@ -120,6 +126,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" } @@ -153,6 +161,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "http-equiv", "value": "X-UA-Compatible" }, @@ -163,6 +173,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "ie=edge" } diff --git a/crates/swc_html_parser/tests/fixture/cr-charref-novalid/html/output.json b/crates/swc_html_parser/tests/fixture/cr-charref-novalid/html/output.json index cd11d99b267..512ae3e418a 100644 --- a/crates/swc_html_parser/tests/fixture/cr-charref-novalid/html/output.json +++ b/crates/swc_html_parser/tests/fixture/cr-charref-novalid/html/output.json @@ -57,6 +57,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "charset", "value": "utf-8" } diff --git a/crates/swc_html_parser/tests/fixture/html-entity/output.json b/crates/swc_html_parser/tests/fixture/html-entity/output.json index 438b5b6d95b..78d31152baf 100644 --- a/crates/swc_html_parser/tests/fixture/html-entity/output.json +++ b/crates/swc_html_parser/tests/fixture/html-entity/output.json @@ -1135,6 +1135,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "href", "value": "http://lmgtfy.com/?l=1&q=rick+roll" } @@ -1166,6 +1168,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "href", "value": "#" }, @@ -1176,6 +1180,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "onclick", "value": "window.location='?l=1&q=rick+roll';return false" } diff --git a/crates/swc_html_parser/tests/fixture/missing-doctype-name/output.json b/crates/swc_html_parser/tests/fixture/missing-doctype-name/output.json index 0d73fc0f84a..83079fe131c 100644 --- a/crates/swc_html_parser/tests/fixture/missing-doctype-name/output.json +++ b/crates/swc_html_parser/tests/fixture/missing-doctype-name/output.json @@ -79,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "href", "value": "https://www.w3schools.com" } diff --git a/crates/swc_html_parser/tests/fixture/range-charref-novalid/html/output.json b/crates/swc_html_parser/tests/fixture/range-charref-novalid/html/output.json index 19c7cce350f..6ec01c90efb 100644 --- a/crates/swc_html_parser/tests/fixture/range-charref-novalid/html/output.json +++ b/crates/swc_html_parser/tests/fixture/range-charref-novalid/html/output.json @@ -57,6 +57,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "charset", "value": "utf-8" } diff --git a/crates/swc_html_parser/tests/fixture/script-cdata/output.json b/crates/swc_html_parser/tests/fixture/script-cdata/output.json index c5d21c25970..5d2a554b352 100644 --- a/crates/swc_html_parser/tests/fixture/script-cdata/output.json +++ b/crates/swc_html_parser/tests/fixture/script-cdata/output.json @@ -46,6 +46,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "text/javascript" } diff --git a/crates/swc_html_parser/tests/fixture/tag/basic/output.json b/crates/swc_html_parser/tests/fixture/tag/basic/output.json index 849b216f7c5..b724a0c81ed 100644 --- a/crates/swc_html_parser/tests/fixture/tag/basic/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/basic/output.json @@ -218,6 +218,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "⚡", "value": null } @@ -286,6 +288,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "href", "value": "test.html" } @@ -439,6 +443,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-test", "value": "a" } @@ -472,6 +478,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-test", "value": "a" } @@ -505,6 +513,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-test", "value": "a" } @@ -538,6 +548,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-test", "value": "a" } diff --git a/crates/swc_html_parser/tests/fixture/tag/custom-element/output.json b/crates/swc_html_parser/tests/fixture/tag/custom-element/output.json index 157ce8564f4..42a08763e48 100644 --- a/crates/swc_html_parser/tests/fixture/tag/custom-element/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/custom-element/output.json @@ -59,6 +59,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "img", "value": "img/alt.png" }, @@ -69,6 +71,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-text", "value": "Your card validation code (CVC)\n is an extra security feature — it is the last 3 or 4 numbers on the\n back of your card." } @@ -102,6 +106,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "l", "value": "100" }, @@ -112,6 +118,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "c", "value": "red" } @@ -145,6 +153,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "open", "value": null }, @@ -155,6 +165,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "disabled", "value": null } @@ -208,6 +220,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "twitter" } @@ -230,6 +244,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "href", "value": "..." } @@ -276,6 +292,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "fb" } @@ -298,6 +316,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "href", "value": "..." } @@ -344,6 +364,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "plus" } @@ -366,6 +388,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "href", "value": "..." } @@ -479,6 +503,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "x-foo-from-template" } diff --git a/crates/swc_html_parser/tests/fixture/tag/embed/output.json b/crates/swc_html_parser/tests/fixture/tag/embed/output.json index 92c25319e5e..adf1f3964f3 100644 --- a/crates/swc_html_parser/tests/fixture/tag/embed/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/embed/output.json @@ -35,6 +35,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "lang", "value": "en" } @@ -141,6 +143,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "vide/webm" }, @@ -151,6 +155,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "src", "value": "/media/examples/flower.mp4" }, @@ -161,6 +167,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "width", "value": "200" }, @@ -171,6 +179,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "height", "value": "200" } diff --git a/crates/swc_html_parser/tests/fixture/tag/frameset/output.json b/crates/swc_html_parser/tests/fixture/tag/frameset/output.json index aa8b7441a66..f8fecbfa164 100644 --- a/crates/swc_html_parser/tests/fixture/tag/frameset/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/frameset/output.json @@ -66,6 +66,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "http-equiv", "value": "Content-Type" }, @@ -76,6 +78,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "text/html; charset=utf-8" } @@ -153,6 +157,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "rows", "value": "80,*" }, @@ -163,6 +169,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "cols", "value": "*" } @@ -194,6 +202,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "src", "value": "top.html" }, @@ -204,6 +214,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "topFrame" }, @@ -214,6 +226,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "scrolling", "value": "no" }, @@ -224,6 +238,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "noresize", "value": null } @@ -257,6 +273,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "cols", "value": "80,*" } @@ -288,6 +306,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "src", "value": "left.html" }, @@ -298,6 +318,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "leftFrame" }, @@ -308,6 +330,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "scrolling", "value": "no" }, @@ -318,6 +342,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "noresize", "value": null } @@ -351,6 +377,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "src", "value": "main.html" }, @@ -361,6 +389,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "mainFrame" } diff --git a/crates/swc_html_parser/tests/fixture/tag/img/output.json b/crates/swc_html_parser/tests/fixture/tag/img/output.json index 4f00b910bfb..c6446bc7e3e 100644 --- a/crates/swc_html_parser/tests/fixture/tag/img/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/img/output.json @@ -143,6 +143,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "src", "value": "w3schools.jpg" }, @@ -153,6 +155,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "alt", "value": "W3Schools.com" }, @@ -163,6 +167,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "width", "value": "104" }, @@ -173,6 +179,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "height", "value": "142" } diff --git a/crates/swc_html_parser/tests/fixture/tag/lists/output.json b/crates/swc_html_parser/tests/fixture/tag/lists/output.json index 8ba798598cf..a8ab676e5d9 100644 --- a/crates/swc_html_parser/tests/fixture/tag/lists/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/lists/output.json @@ -79,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-test", "value": "test" } diff --git a/crates/swc_html_parser/tests/fixture/tag/marquee/output.json b/crates/swc_html_parser/tests/fixture/tag/marquee/output.json index 6aa2a394221..e4d041dca09 100644 --- a/crates/swc_html_parser/tests/fixture/tag/marquee/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/marquee/output.json @@ -35,6 +35,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "lang", "value": "en" } @@ -161,6 +163,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "direction", "value": "up" } @@ -192,6 +196,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "direction", "value": "down" }, @@ -202,6 +208,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "width", "value": "250" }, @@ -212,6 +220,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "height", "value": "200" }, @@ -222,6 +232,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "behavior", "value": "alternate" }, @@ -232,6 +244,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "style", "value": "border:solid" } @@ -263,6 +277,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "behavior", "value": "alternate" } diff --git a/crates/swc_html_parser/tests/fixture/tag/math/output.json b/crates/swc_html_parser/tests/fixture/tag/math/output.json index a29f7ff3320..938178d81f8 100644 --- a/crates/swc_html_parser/tests/fixture/tag/math/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/math/output.json @@ -121,7 +121,7 @@ "ctxt": 0 }, "tagName": "math", - "namespace": "http://www.w3.org/1998/Math/MathML", + "namespace": "http://www.w3.org/2000/svg", "attributes": [], "children": [ { diff --git a/crates/swc_html_parser/tests/fixture/tag/object/output.json b/crates/swc_html_parser/tests/fixture/tag/object/output.json index 5716005e64a..e345b6049f6 100644 --- a/crates/swc_html_parser/tests/fixture/tag/object/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/object/output.json @@ -35,6 +35,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "lang", "value": "en" } @@ -141,6 +143,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "image/svg+xml" }, @@ -151,6 +155,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data", "value": "image.svg" } diff --git a/crates/swc_html_parser/tests/fixture/tag/plaintext/output.json b/crates/swc_html_parser/tests/fixture/tag/plaintext/output.json index 84cd8e4bc13..7cbe434b1ec 100644 --- a/crates/swc_html_parser/tests/fixture/tag/plaintext/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/plaintext/output.json @@ -66,6 +66,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "http-equiv", "value": "Content-Type" }, @@ -76,6 +78,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "text/html; charset=utf-8" } diff --git a/crates/swc_html_parser/tests/fixture/tag/pre/output.json b/crates/swc_html_parser/tests/fixture/tag/pre/output.json index b37d629bde1..13cb36dcbc0 100644 --- a/crates/swc_html_parser/tests/fixture/tag/pre/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/pre/output.json @@ -35,6 +35,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "lang", "value": "en" } @@ -77,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "charset", "value": "UTF-8" } @@ -110,6 +114,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "viewport" }, @@ -120,6 +126,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" } @@ -153,6 +161,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "http-equiv", "value": "X-UA-Compatible" }, @@ -163,6 +173,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "ie=edge" } diff --git a/crates/swc_html_parser/tests/fixture/tag/svg/input.html b/crates/swc_html_parser/tests/fixture/tag/svg/input.html index 6c62fffb434..00d14801293 100644 --- a/crates/swc_html_parser/tests/fixture/tag/svg/input.html +++ b/crates/swc_html_parser/tests/fixture/tag/svg/input.html @@ -49,5 +49,28 @@ + + This is some English text + + + + + + + + Default spacing + Preserved spacing + + + + This is some English text + + An example link. + + + \ No newline at end of file diff --git a/crates/swc_html_parser/tests/fixture/tag/svg/output.json b/crates/swc_html_parser/tests/fixture/tag/svg/output.json index 9f03fb18c57..77525b7a434 100644 --- a/crates/swc_html_parser/tests/fixture/tag/svg/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/svg/output.json @@ -2,7 +2,7 @@ "type": "Document", "span": { "start": 0, - "end": 1954, + "end": 2925, "ctxt": 0 }, "mode": "no-quirks", @@ -11,7 +11,7 @@ "type": "Element", "span": { "start": 0, - "end": 1947, + "end": 2918, "ctxt": 0 }, "tagName": "html", @@ -24,6 +24,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "xmlns", "value": "http://www.w3.org/1999/xhtml" } @@ -174,6 +176,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "body" }, @@ -184,6 +188,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "style", "value": "position:absolute; z-index:0; border:1px solid black; left:5%; top:5%; width:90%; height:90%;" } @@ -330,6 +336,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "text" } @@ -363,6 +371,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "err" } @@ -420,6 +430,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "button" }, @@ -430,6 +442,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "value", "value": "Activate!" }, @@ -440,6 +454,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "onclick", "value": "signalError();" } @@ -490,7 +506,7 @@ "type": "Element", "span": { "start": 913, - "end": 1947, + "end": 2918, "ctxt": 0 }, "tagName": "svg", @@ -503,6 +519,8 @@ "end": 0, "ctxt": 0 }, + "namespace": "http://www.w3.org/2000/xmlns/", + "prefix": null, "name": "xmlns", "value": "http://www.w3.org/2000/svg" }, @@ -513,6 +531,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "version", "value": "1.1" }, @@ -523,6 +543,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "viewBox", "value": "0 0 100 100" }, @@ -533,6 +555,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "preserveAspectRatio", "value": "xMidYMid slice" }, @@ -543,6 +567,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "style", "value": "width:100%; height:100%; position:absolute; top:0; left:0; z-index:-1;" }, @@ -553,6 +579,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "baseProfile", "value": "test" } @@ -584,6 +612,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "gradient" } @@ -615,6 +645,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "begin" }, @@ -625,6 +657,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "offset", "value": "0%" } @@ -656,6 +690,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "end" }, @@ -666,6 +702,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "offset", "value": "100%" } @@ -702,7 +740,7 @@ "type": "Element", "span": { "start": 1280, - "end": 1947, + "end": 2918, "ctxt": 0 }, "tagName": "rect", @@ -715,6 +753,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "x", "value": "0" }, @@ -725,6 +765,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "y", "value": "0" }, @@ -735,6 +777,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "width", "value": "100" }, @@ -745,6 +789,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "height", "value": "100" }, @@ -755,6 +801,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "style", "value": "fill:url(#gradient)" } @@ -773,7 +821,7 @@ "type": "Element", "span": { "start": 1358, - "end": 1947, + "end": 2918, "ctxt": 0 }, "tagName": "circle", @@ -786,6 +834,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "cx", "value": "50" }, @@ -796,6 +846,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "cy", "value": "50" }, @@ -806,6 +858,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "r", "value": "30" }, @@ -816,6 +870,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "style", "value": "fill:url(#gradient)" } @@ -834,7 +890,7 @@ "type": "Element", "span": { "start": 1428, - "end": 1947, + "end": 2918, "ctxt": 0 }, "tagName": "svg", @@ -847,6 +903,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "viewBox", "value": "0 0 420 200" }, @@ -857,6 +915,8 @@ "end": 0, "ctxt": 0 }, + "namespace": "http://www.w3.org/2000/xmlns/", + "prefix": null, "name": "xmlns", "value": "http://www.w3.org/2000/svg" } @@ -888,6 +948,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "noise1" }, @@ -898,6 +960,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "x", "value": "0" }, @@ -908,6 +972,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "y", "value": "0" }, @@ -918,6 +984,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "width", "value": "100%" }, @@ -928,6 +996,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "height", "value": "100%" } @@ -959,6 +1029,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "basefrequency", "value": "0.025" } @@ -1005,6 +1077,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "noise2" }, @@ -1015,6 +1089,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "x", "value": "0" }, @@ -1025,6 +1101,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "y", "value": "0" }, @@ -1035,6 +1113,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "width", "value": "100%" }, @@ -1045,6 +1125,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "height", "value": "100%" } @@ -1076,6 +1158,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "basefrequency", "value": "0.05" } @@ -1109,7 +1193,7 @@ "type": "Element", "span": { "start": 1745, - "end": 1947, + "end": 2918, "ctxt": 0 }, "tagName": "rect", @@ -1122,6 +1206,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "x", "value": "0" }, @@ -1132,6 +1218,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "y", "value": "0" }, @@ -1142,6 +1230,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "width", "value": "200" }, @@ -1152,6 +1242,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "height", "value": "200" }, @@ -1162,6 +1254,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "style", "value": "filter: url(#noise1);" } @@ -1180,7 +1274,7 @@ "type": "Element", "span": { "start": 1825, - "end": 1947, + "end": 2918, "ctxt": 0 }, "tagName": "rect", @@ -1193,6 +1287,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "x", "value": "0" }, @@ -1203,6 +1299,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "y", "value": "0" }, @@ -1213,6 +1311,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "width", "value": "200" }, @@ -1223,6 +1323,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "height", "value": "200" }, @@ -1233,6 +1335,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "style", "value": "filter: url(#noise2); transform: translateX(220px);" } @@ -1242,10 +1346,642 @@ "type": "Text", "span": { "start": 1930, - "end": 1947, + "end": 1939, "ctxt": 0 }, - "value": "\n\n\n\n" + "value": "\n\n\n" + }, + { + "type": "Element", + "span": { + "start": 1939, + "end": 2918, + "ctxt": 0 + }, + "tagName": "svg", + "namespace": "http://www.w3.org/2000/svg", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "viewBox", + "value": "0 0 200 100" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": "http://www.w3.org/2000/xmlns/", + "prefix": null, + "name": "xmlns", + "value": "http://www.w3.org/2000/svg" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2001, + "end": 2006, + "ctxt": 0 + }, + "value": "\n " + }, + { + "type": "Element", + "span": { + "start": 2006, + "end": 2054, + "ctxt": 0 + }, + "tagName": "text", + "namespace": "http://www.w3.org/1999/xhtml", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "xml:lang", + "value": "en-US" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2029, + "end": 2054, + "ctxt": 0 + }, + "value": "This is some English text" + } + ], + "content": null + }, + { + "type": "Text", + "span": { + "start": 2061, + "end": 2070, + "ctxt": 0 + }, + "value": "\n\n\n" + }, + { + "type": "Element", + "span": { + "start": 2070, + "end": 2918, + "ctxt": 0 + }, + "tagName": "svg", + "namespace": "http://www.w3.org/2000/svg", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "version", + "value": "1.1" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": "http://www.w3.org/2000/xmlns/", + "prefix": null, + "name": "xmlns", + "value": "http://www.w3.org/2000/svg" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": "http://www.w3.org/2000/xmlns/", + "prefix": "xmlns", + "name": "xlink", + "value": "http://www.w3.org/1999/xlink" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "width", + "value": "200" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "height", + "value": "200" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2202, + "end": 2207, + "ctxt": 0 + }, + "value": "\n " + }, + { + "type": "Element", + "span": { + "start": 2207, + "end": 2389, + "ctxt": 0 + }, + "tagName": "img", + "namespace": "http://www.w3.org/1999/xhtml", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "x", + "value": "90" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "y", + "value": "-65" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "width", + "value": "128" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "height", + "value": "146" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "transform", + "value": "rotate(45)" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "xlink:href", + "value": "https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image/mdn_logo_only_color.png" + } + ], + "children": [], + "content": null + }, + { + "type": "Text", + "span": { + "start": 2389, + "end": 2398, + "ctxt": 0 + }, + "value": "\n\n\n" + }, + { + "type": "Element", + "span": { + "start": 2398, + "end": 2918, + "ctxt": 0 + }, + "tagName": "svg", + "namespace": "http://www.w3.org/2000/svg", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "viewBox", + "value": "0 0 140 50" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": "http://www.w3.org/2000/xmlns/", + "prefix": null, + "name": "xmlns", + "value": "http://www.w3.org/2000/svg" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2459, + "end": 2464, + "ctxt": 0 + }, + "value": "\n " + }, + { + "type": "Element", + "span": { + "start": 2464, + "end": 2514, + "ctxt": 0 + }, + "tagName": "text", + "namespace": "http://www.w3.org/1999/xhtml", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "y", + "value": "20" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "xml:space", + "value": "default" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2497, + "end": 2514, + "ctxt": 0 + }, + "value": "Default spacing" + } + ], + "content": null + }, + { + "type": "Text", + "span": { + "start": 2521, + "end": 2526, + "ctxt": 0 + }, + "value": "\n " + }, + { + "type": "Element", + "span": { + "start": 2526, + "end": 2579, + "ctxt": 0 + }, + "tagName": "text", + "namespace": "http://www.w3.org/1999/xhtml", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "y", + "value": "40" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "xml:space", + "value": "preserve" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2560, + "end": 2579, + "ctxt": 0 + }, + "value": "Preserved spacing" + } + ], + "content": null + }, + { + "type": "Text", + "span": { + "start": 2586, + "end": 2595, + "ctxt": 0 + }, + "value": "\n\n\n" + }, + { + "type": "Element", + "span": { + "start": 2595, + "end": 2918, + "ctxt": 0 + }, + "tagName": "svg", + "namespace": "http://www.w3.org/2000/svg", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "viewBox", + "value": "0 0 200 100" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": "http://www.w3.org/2000/xmlns/", + "prefix": null, + "name": "xmlns", + "value": "http://www.w3.org/2000/svg" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2657, + "end": 2662, + "ctxt": 0 + }, + "value": "\n " + }, + { + "type": "Element", + "span": { + "start": 2662, + "end": 2710, + "ctxt": 0 + }, + "tagName": "text", + "namespace": "http://www.w3.org/1999/xhtml", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "xml:lang", + "value": "en-US" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2685, + "end": 2710, + "ctxt": 0 + }, + "value": "This is some English text" + } + ], + "content": null + }, + { + "type": "Text", + "span": { + "start": 2717, + "end": 2722, + "ctxt": 0 + }, + "value": "\n " + }, + { + "type": "Element", + "span": { + "start": 2722, + "end": 2918, + "ctxt": 0 + }, + "tagName": "a", + "namespace": "http://www.w3.org/1999/xhtml", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "xlink:href", + "value": "http://example.com/link/" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "xlink:title", + "value": "The link leads to an example page that is of little interest" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2839, + "end": 2848, + "ctxt": 0 + }, + "value": "\n " + }, + { + "type": "Element", + "span": { + "start": 2848, + "end": 2885, + "ctxt": 0 + }, + "tagName": "text", + "namespace": "http://www.w3.org/1999/xhtml", + "attributes": [ + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "x", + "value": "10" + }, + { + "type": "Attribute", + "span": { + "start": 0, + "end": 0, + "ctxt": 0 + }, + "namespace": null, + "prefix": null, + "name": "y", + "value": "25" + } + ], + "children": [ + { + "type": "Text", + "span": { + "start": 2869, + "end": 2885, + "ctxt": 0 + }, + "value": "An example link." + } + ], + "content": null + }, + { + "type": "Text", + "span": { + "start": 2892, + "end": 2918, + "ctxt": 0 + }, + "value": "\n \n\n\n\n" + } + ], + "content": null + } + ], + "content": null + } + ], + "content": null + } + ], + "content": null + } + ], + "content": null } ], "content": null diff --git a/crates/swc_html_parser/tests/fixture/tag/svg/span.rust-debug b/crates/swc_html_parser/tests/fixture/tag/svg/span.rust-debug index 4f31e84d9d2..c9f9c93fb61 100644 --- a/crates/swc_html_parser/tests/fixture/tag/svg/span.rust-debug +++ b/crates/swc_html_parser/tests/fixture/tag/svg/span.rust-debug @@ -52,8 +52,31 @@ 49 | | 50 | | 51 | | - 52 | | - 53 | `-> + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | | + 76 | `-> `---- x Child @@ -109,8 +132,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Element @@ -166,8 +212,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Attribute @@ -733,8 +802,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Element @@ -762,8 +854,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Child @@ -886,8 +1001,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Element @@ -908,8 +1046,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Child @@ -941,8 +1102,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Element @@ -962,8 +1146,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Child @@ -996,8 +1203,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Element @@ -1014,8 +1244,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Child @@ -1162,8 +1415,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Element @@ -1172,8 +1448,31 @@ 49 | | 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Child @@ -1193,8 +1492,31 @@ 49 | ,-> 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Element @@ -1202,24 +1524,521 @@ 49 | ,-> 50 | | 51 | | - 52 | `-> - 53 | + 52 | | + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- x Child ,-[$DIR/tests/fixture/tag/svg/input.html:49:5] 49 | ,-> 50 | | - 51 | | - 52 | `-> - 53 | + 51 | `-> + 52 | `---- x Text ,-[$DIR/tests/fixture/tag/svg/input.html:49:5] 49 | ,-> 50 | | - 51 | | - 52 | `-> - 53 | + 51 | `-> + 52 | + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:52:1] + 52 | ,-> + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:52:1] + 52 | ,-> + 53 | | This is some English text + 54 | | + 55 | | + 56 | | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:52:1] + 52 | ,-> + 53 | `-> This is some English text + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:52:1] + 52 | ,-> + 53 | `-> This is some English text + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:53:5] + 53 | This is some English text + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:53:5] + 53 | This is some English text + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:53:5] + 53 | This is some English text + : ^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:53:5] + 53 | This is some English text + : ^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:53:5] + 53 | ,-> This is some English text + 54 | | + 55 | `-> + 56 | This is some English text + 54 | | + 55 | `-> + 56 | + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:56:1] + 56 | ,-> + 59 | | + 61 | | + 62 | | + 63 | | + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:58:6] + 58 | ,-> width="200" height="200"> + 59 | `-> width="200" height="200"> + 59 | `-> xlink:href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image/mdn_logo_only_color.png"/> + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:59:5] + 59 | ,-> xlink:href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image/mdn_logo_only_color.png"/> + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:60:12] + 60 | ,-> xlink:href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image/mdn_logo_only_color.png"/> + 61 | | + 62 | `-> + 63 | + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:60:12] + 60 | ,-> xlink:href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image/mdn_logo_only_color.png"/> + 61 | | + 62 | `-> + 63 | + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:63:1] + 63 | ,-> + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:63:1] + 63 | ,-> + 64 | | Default spacing + 65 | | Preserved spacing + 66 | | + 67 | | + 68 | | + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:63:1] + 63 | ,-> + 64 | `-> Default spacing + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:63:1] + 63 | ,-> + 64 | `-> Default spacing + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:64:5] + 64 | Default spacing + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:64:5] + 64 | Default spacing + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:64:5] + 64 | Default spacing + : ^^^^^^^^^^^^^^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:64:5] + 64 | Default spacing + : ^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:64:5] + 64 | ,-> Default spacing + 65 | `-> Preserved spacing + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:64:5] + 64 | ,-> Default spacing + 65 | `-> Preserved spacing + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:65:5] + 65 | Preserved spacing + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:65:5] + 65 | Preserved spacing + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:65:5] + 65 | Preserved spacing + : ^^^^^^^^^^^^^^^^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:65:5] + 65 | Preserved spacing + : ^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:65:5] + 65 | ,-> Preserved spacing + 66 | | + 67 | `-> + 68 | + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:65:5] + 65 | ,-> Preserved spacing + 66 | | + 67 | `-> + 68 | + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:68:1] + 68 | ,-> + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:68:1] + 68 | ,-> + 69 | | This is some English text + 70 | | + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:68:1] + 68 | ,-> + 69 | `-> This is some English text + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:68:1] + 68 | ,-> + 69 | `-> This is some English text + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:69:5] + 69 | This is some English text + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:69:5] + 69 | This is some English text + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:69:5] + 69 | This is some English text + : ^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:69:5] + 69 | This is some English text + : ^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:69:5] + 69 | ,-> This is some English text + 70 | `-> + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:69:5] + 69 | ,-> This is some English text + 70 | `-> + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:70:5] + 70 | ,-> + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:70:5] + 70 | ,-> + 71 | | An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:70:5] + 70 | ,-> + 71 | `-> An example link. + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:70:5] + 70 | ,-> + 71 | `-> An example link. + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:71:9] + 71 | An example link. + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Element + ,-[$DIR/tests/fixture/tag/svg/input.html:71:9] + 71 | An example link. + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:71:9] + 71 | An example link. + : ^^^^^^^^^^^^^^^^ + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:71:9] + 71 | An example link. + : ^^^^^^^^^^^^^^^^ + `---- + + x Child + ,-[$DIR/tests/fixture/tag/svg/input.html:71:9] + 71 | ,-> An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | + `---- + + x Text + ,-[$DIR/tests/fixture/tag/svg/input.html:71:9] + 71 | ,-> An example link. + 72 | | + 73 | | + 74 | | + 75 | `-> + 76 | `---- diff --git a/crates/swc_html_parser/tests/fixture/tag/table/output.json b/crates/swc_html_parser/tests/fixture/tag/table/output.json index ca6f5dd38af..3b49e6e90fc 100644 --- a/crates/swc_html_parser/tests/fixture/tag/table/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/table/output.json @@ -35,6 +35,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "lang", "value": "en" } @@ -77,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "charset", "value": "UTF-8" } @@ -110,6 +114,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "viewport" }, @@ -120,6 +126,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" } @@ -153,6 +161,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "http-equiv", "value": "X-UA-Compatible" }, @@ -163,6 +173,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "ie=edge" } diff --git a/crates/swc_html_parser/tests/fixture/tag/template/output.json b/crates/swc_html_parser/tests/fixture/tag/template/output.json index b14cf393634..0f4d7739466 100644 --- a/crates/swc_html_parser/tests/fixture/tag/template/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/template/output.json @@ -46,6 +46,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "element-details-template" } @@ -149,6 +151,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "name" } @@ -180,6 +184,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "element-name" } @@ -223,6 +229,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "desc" } @@ -245,6 +253,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "description" } @@ -306,6 +316,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "class", "value": "attributes" } @@ -369,6 +381,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "attributes" } diff --git a/crates/swc_html_parser/tests/fixture/tag/textarea/output.json b/crates/swc_html_parser/tests/fixture/tag/textarea/output.json index b0728bf992c..f056bc3d992 100644 --- a/crates/swc_html_parser/tests/fixture/tag/textarea/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/textarea/output.json @@ -35,6 +35,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "lang", "value": "en" } @@ -141,6 +143,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "for", "value": "story" } @@ -184,6 +188,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "story" }, @@ -194,6 +200,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "story" }, @@ -204,6 +212,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "rows", "value": "5" }, @@ -214,6 +224,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "cols", "value": "33" } diff --git a/crates/swc_html_parser/tests/fixture/tag/unknown-end/output.json b/crates/swc_html_parser/tests/fixture/tag/unknown-end/output.json index b71698b4c29..11dad31cb46 100644 --- a/crates/swc_html_parser/tests/fixture/tag/unknown-end/output.json +++ b/crates/swc_html_parser/tests/fixture/tag/unknown-end/output.json @@ -35,6 +35,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "lang", "value": "en" } @@ -77,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "charset", "value": "UTF-8" } @@ -110,6 +114,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "name", "value": "viewport" }, @@ -120,6 +126,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" } @@ -153,6 +161,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "http-equiv", "value": "X-UA-Compatible" }, @@ -163,6 +173,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "content", "value": "ie=edge" } diff --git a/crates/swc_html_parser/tests/fixture/text/cr/output.json b/crates/swc_html_parser/tests/fixture/text/cr/output.json index 85549880e4c..73e28fabcab 100644 --- a/crates/swc_html_parser/tests/fixture/text/cr/output.json +++ b/crates/swc_html_parser/tests/fixture/text/cr/output.json @@ -207,6 +207,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "test", "value": "test" } @@ -250,6 +252,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-q", "value": "test" } @@ -293,6 +297,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-q", "value": "test" } @@ -336,6 +342,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-q", "value": "test" } diff --git a/crates/swc_html_parser/tests/fixture/text/lf/output.json b/crates/swc_html_parser/tests/fixture/text/lf/output.json index a508597e528..f7c499f9ed1 100644 --- a/crates/swc_html_parser/tests/fixture/text/lf/output.json +++ b/crates/swc_html_parser/tests/fixture/text/lf/output.json @@ -207,6 +207,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "test", "value": "test" } @@ -250,6 +252,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-q", "value": "test" } @@ -293,6 +297,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-q", "value": "test" } @@ -336,6 +342,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data-q", "value": "test" } diff --git a/crates/swc_html_parser/tests/fixture/title-attribute/output.json b/crates/swc_html_parser/tests/fixture/title-attribute/output.json index 9e89fe3f4e5..3562b79c537 100644 --- a/crates/swc_html_parser/tests/fixture/title-attribute/output.json +++ b/crates/swc_html_parser/tests/fixture/title-attribute/output.json @@ -79,6 +79,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "title", "value": "I'm a header" } @@ -122,6 +124,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "title", "value": "I'm a tooltip" } diff --git a/crates/swc_html_parser/tests/fixture/u000b-charref-novalid/html/output.json b/crates/swc_html_parser/tests/fixture/u000b-charref-novalid/html/output.json index f8a2d583e10..61882183f23 100644 --- a/crates/swc_html_parser/tests/fixture/u000b-charref-novalid/html/output.json +++ b/crates/swc_html_parser/tests/fixture/u000b-charref-novalid/html/output.json @@ -57,6 +57,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "charset", "value": "utf-8" } diff --git a/crates/swc_html_parser/tests/fixture/unassigned-charref-novalid/output.json b/crates/swc_html_parser/tests/fixture/unassigned-charref-novalid/output.json index 22451f65b0d..5ca952d1dbb 100644 --- a/crates/swc_html_parser/tests/fixture/unassigned-charref-novalid/output.json +++ b/crates/swc_html_parser/tests/fixture/unassigned-charref-novalid/output.json @@ -57,6 +57,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "charset", "value": "utf-8" } diff --git a/crates/swc_html_parser/tests/fixture/xhtml/output.json b/crates/swc_html_parser/tests/fixture/xhtml/output.json index b6fe3b6919c..188271a2308 100644 --- a/crates/swc_html_parser/tests/fixture/xhtml/output.json +++ b/crates/swc_html_parser/tests/fixture/xhtml/output.json @@ -44,6 +44,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "xmlns", "value": "http://www.w3.org/1999/xhtml" }, @@ -54,6 +56,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "xml:lang", "value": "en" } @@ -128,6 +132,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "application/javascript" } @@ -183,6 +189,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "onload", "value": "loadpdf()" } @@ -234,6 +242,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "title", "value": "Extensible HyperText Markup Language" } @@ -299,6 +309,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "validation-icon" }, @@ -309,6 +321,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "src", "value": "http://www.w3.org/Icons/valid-xhtml10" }, @@ -319,6 +333,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "alt", "value": "Valid XHTML 1.0 Strict" } @@ -365,6 +381,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "id", "value": "pdf-object" }, @@ -375,6 +393,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "type", "value": "application/pdf" }, @@ -385,6 +405,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "data", "value": "http://www.w3.org/TR/xhtml1/xhtml1.pdf" }, @@ -395,6 +417,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "width", "value": "100%" }, @@ -405,6 +429,8 @@ "end": 0, "ctxt": 0 }, + "namespace": null, + "prefix": null, "name": "height", "value": "500" } diff --git a/crates/swc_html_visit/src/lib.rs b/crates/swc_html_visit/src/lib.rs index 0bad79bc163..e092cadb20e 100644 --- a/crates/swc_html_visit/src/lib.rs +++ b/crates/swc_html_visit/src/lib.rs @@ -61,6 +61,8 @@ define!({ pub struct Attribute { pub span: Span, + pub namespace: Option, + pub prefix: Option, pub name: JsWord, pub value: Option, }