,
}
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 @@
+
+
+
+
+
+
+
+