mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 16:42:28 +03:00
fix(html/codegen): Expand elements before which body isn’t elided (#8877)
**Description:** For example, transforming `<body><noscript>` to `<noscript>` would incorrectly change the meaning so `<noscript>` is parsed as a child of `<head>`. Reference: [§13.2.6.4.4 The "in head" insertion mode](https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead), [13.2.6.4.6 The "after head" insertion mode](https://html.spec.whatwg.org/multipage/parsing.html#the-after-head-insertion-mode). **Related issue:** - Closes #8876. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
a4d3b26217
commit
5419a9477f
@ -234,8 +234,7 @@ where
|
||||
}
|
||||
// A body element's start tag can be omitted if the element is empty, or if the
|
||||
// first thing inside the body element is not ASCII whitespace or a comment, except
|
||||
// if the first thing inside the body element is a meta, link, script, style, or
|
||||
// template element.
|
||||
// if the first thing inside the body element would be parsed differently outside.
|
||||
"body"
|
||||
if n.children.is_empty()
|
||||
|| (match n.children.first() {
|
||||
@ -253,14 +252,17 @@ where
|
||||
})) if *namespace == Namespace::HTML
|
||||
&& matches!(
|
||||
&**tag_name,
|
||||
"meta"
|
||||
"base"
|
||||
| "basefont"
|
||||
| "bgsound"
|
||||
| "frameset"
|
||||
| "link"
|
||||
| "meta"
|
||||
| "noframes"
|
||||
| "noscript"
|
||||
| "script"
|
||||
| "style"
|
||||
| "template"
|
||||
| "bgsound"
|
||||
| "basefont"
|
||||
| "base"
|
||||
| "title"
|
||||
) =>
|
||||
{
|
||||
|
@ -0,0 +1,8 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Test</title>
|
||||
</head>
|
||||
<body><noscript>This app requires JavaScript.</noscript></body>
|
||||
</html>
|
@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Test</title>
|
||||
</head>
|
||||
<body><noscript>This app requires JavaScript.</noscript>
|
||||
|
||||
</body></html>
|
@ -0,0 +1,6 @@
|
||||
<!doctype html><html lang=en><head>
|
||||
<meta charset=utf-8>
|
||||
<title>Test</title>
|
||||
</head>
|
||||
<body><noscript>This app requires JavaScript.</noscript>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<!doctype html><html lang=en><meta charset=UTF-8><meta name=viewport content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><noscript>
|
||||
<!doctype html><html lang=en><meta charset=UTF-8><meta name=viewport content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><body><noscript>
|
||||
|
||||
<a href=https://www.mozilla.com/>External Link</a>
|
||||
</noscript>
|
||||
|
Loading…
Reference in New Issue
Block a user