Allow self-closing />
on HTML via a flag or feature
#8424
Replies: 2 comments 20 replies
-
@alexander-akait Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Relevant place in Vue docs: https://vuejs.org/guide/essentials/component-basics.html#self-closing-tags. I managed to get it working for "other" start tags (e.g. swc/crates/swc_html_parser/src/parser/mod.rs Lines 4115 to 4118 in c39e75c Regarding normal HTML tags like Which is why I think it's better to do this, since it can be neatly organized as a macro and accurately added where necessary: if self.config.allow_self_closing && *is_self_closing {
let mut end_token_and_info = TokenAndInfo {
span: token_and_info.span,
acknowledged: false,
token: Token::EndTag {
tag_name: tag_name.to_owned(),
raw_tag_name: None,
is_self_closing: false,
attributes: vec![],
},
};
self.process_token(&mut end_token_and_info, None)?;
} To make it possible, I changed the signatures of swc/crates/swc_html_parser/src/parser/mod.rs Lines 8337 to 8376 in c39e75c @alexander-akait Could you please comment on that? |
Beta Was this translation helpful? Give feedback.
-
Syntax like that is often used in Vue templates:
Since
swc_html_parser
is spec-compliant, it acknowledges the<slot />
and<div />
, but does not actually pop the DOM Tree stack.It makes parsing such templates impossible: phoenix-ru/fervid#6
Can we add a flag to
ParserConfig
or a crate feature to treat such starting tags as self-closing? I can open a ticket and work on a PR.Beta Was this translation helpful? Give feedback.
All reactions