-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent <style>
from getting moved in <html>
#974
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6970684
chore: `only` helper for json test
MoustaphaDev 045f4c0
fix: remove divergence from html spec
MoustaphaDev 1d077f8
test: add test for #712
MoustaphaDev 69e4d4a
`addLoc` before popping the stack of oe
MoustaphaDev 851a128
test: add test
MoustaphaDev 261d7d3
literal parsing after `body` and `html`
MoustaphaDev b951379
test: add test for style tag after body
MoustaphaDev 4f8f51a
test: add tsx tests
MoustaphaDev 4519556
test: add missing semicolon in test
MoustaphaDev 15aa45e
Merge branch 'main' into mk/fix-712
MoustaphaDev e7d3931
test: add more tests from duplicates
MoustaphaDev a147f86
Merge branch 'main' into mk/fix-712
natemoo-re 3512dad
Merge branch 'main' into mk/fix-712
Princesseuh 2b7c576
Merge branch 'main' into mk/fix-712
Princesseuh d3f1bca
Merge branch 'main' into mk/fix-712
Princesseuh 551f81c
nit: formatting
Princesseuh 06f7785
chore: changeset
Princesseuh 858e178
test: add AST tests
Princesseuh 8ec1d44
Merge branch 'main' into mk/fix-712
Princesseuh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@astrojs/compiler": patch | ||
--- | ||
|
||
Fixes style and script tags sometimes being forcefully put into the body / head tags in the AST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { parse } from '@astrojs/compiler'; | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import type { ElementNode } from '../../types.js'; | ||
|
||
test('preserve style tag position I', async () => { | ||
const input = `<html><body><h1>Hello world!</h1></body></html> | ||
<style></style>`; | ||
const { ast } = await parse(input); | ||
|
||
const lastChildren = ast.children.at(-1) as ElementNode; | ||
|
||
assert.equal(lastChildren.type, 'element', 'Expected last child node to be of type "element"'); | ||
assert.equal(lastChildren.name, 'style', 'Expected last child node to be of type "style"'); | ||
}); | ||
|
||
test('preserve style tag position II', async () => { | ||
const input = `<html></html> | ||
<style></style>`; | ||
const { ast } = await parse(input); | ||
|
||
const lastChildren = ast.children.at(-1) as ElementNode; | ||
|
||
assert.equal(lastChildren.type, 'element', 'Expected last child node to be of type "element"'); | ||
assert.equal(lastChildren.name, 'style', 'Expected last child node to be of type "style"'); | ||
}); | ||
|
||
test('preserve style tag position III', async () => { | ||
const input = `<html lang="en"><head><BaseHead /></head></html> | ||
<style>@use "../styles/global.scss";</style>`; | ||
const { ast } = await parse(input); | ||
|
||
const lastChildren = ast.children.at(-1) as ElementNode; | ||
|
||
assert.equal(lastChildren.type, 'element', 'Expected last child node to be of type "element"'); | ||
assert.equal(lastChildren.name, 'style', 'Expected last child node to be of type "style"'); | ||
assert.equal( | ||
lastChildren.children[0].type, | ||
'text', | ||
'Expected last child node to be of type "text"' | ||
); | ||
}); | ||
|
||
test('preserve style tag position IV', async () => { | ||
const input = `<html lang="en"><head><BaseHead /></head><body><Header /></body></html> | ||
<style>@use "../styles/global.scss";</style>`; | ||
const { ast } = await parse(input); | ||
|
||
const lastChildren = ast.children.at(-1) as ElementNode; | ||
|
||
assert.equal(lastChildren.type, 'element', 'Expected last child node to be of type "element"'); | ||
assert.equal(lastChildren.name, 'style', 'Expected last child node to be of type "style"'); | ||
assert.equal( | ||
lastChildren.children[0].type, | ||
'text', | ||
'Expected last child node to be of type "text"' | ||
); | ||
}); | ||
|
||
test('preserve style tag position V', async () => { | ||
const input = `<html lang="en"><head><BaseHead /></head><body><Header /></body><style>@use "../styles/global.scss";</style></html>`; | ||
const { ast } = await parse(input); | ||
|
||
const firstChild = ast.children.at(0) as ElementNode; | ||
const lastChild = firstChild.children.at(-1) as ElementNode; | ||
|
||
assert.equal(lastChild.type, 'element', 'Expected last child node to be of type "element"'); | ||
assert.equal(lastChild.name, 'style', 'Expected last child node to be of type "style"'); | ||
assert.equal(lastChild.children[0].type, 'text', 'Expected last child node to be of type "text"'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { convertToTSX } from '@astrojs/compiler'; | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import { TSXPrefix } from '../utils.js'; | ||
|
||
test('preserve style tag position I', async () => { | ||
const input = `<html><body><h1>Hello world!</h1></body></html> | ||
<style></style>`; | ||
const output = `${TSXPrefix}<Fragment> | ||
<html><body><h1>Hello world!</h1></body></html> | ||
<style></style> | ||
</Fragment> | ||
export default function __AstroComponent_(_props: Record<string, any>): any {}\n`; | ||
const { code } = await convertToTSX(input, { sourcemap: 'external' }); | ||
assert.snapshot(code, output, 'expected code to match snapshot'); | ||
}); | ||
|
||
test('preserve style tag position II', async () => { | ||
const input = `<html></html> | ||
<style></style>`; | ||
const output = `${TSXPrefix}<Fragment> | ||
<html></html> | ||
<style></style> | ||
</Fragment> | ||
export default function __AstroComponent_(_props: Record<string, any>): any {}\n`; | ||
const { code } = await convertToTSX(input, { sourcemap: 'external' }); | ||
assert.snapshot(code, output, 'expected code to match snapshot'); | ||
}); | ||
|
||
test('preserve style tag position III', async () => { | ||
const input = `<html lang="en"><head><BaseHead /></head></html> | ||
<style>@use "../styles/global.scss";</style>`; | ||
const output = `${TSXPrefix}<Fragment> | ||
<html lang="en"><head><BaseHead /></head></html> | ||
<style>{\`@use "../styles/global.scss";\`}</style> | ||
</Fragment> | ||
export default function __AstroComponent_(_props: Record<string, any>): any {}\n`; | ||
const { code } = await convertToTSX(input, { sourcemap: 'external' }); | ||
assert.snapshot(code, output, 'expected code to match snapshot'); | ||
}); | ||
|
||
test('preserve style tag position IV', async () => { | ||
const input = `<html lang="en"><head><BaseHead /></head><body><Header /></body></html> | ||
<style>@use "../styles/global.scss";</style>`; | ||
const output = `${TSXPrefix}<Fragment> | ||
<html lang="en"><head><BaseHead /></head><body><Header /></body></html> | ||
<style>{\`@use "../styles/global.scss";\`}</style> | ||
</Fragment> | ||
export default function __AstroComponent_(_props: Record<string, any>): any {}\n`; | ||
const { code } = await convertToTSX(input, { sourcemap: 'external' }); | ||
assert.snapshot(code, output, 'expected code to match snapshot'); | ||
}); | ||
|
||
test('preserve style tag position V', async () => { | ||
const input = `<html lang="en"><head><BaseHead /></head><body><Header /></body><style>@use "../styles/global.scss";</style></html>`; | ||
const output = `${TSXPrefix}<Fragment> | ||
<html lang="en"><head><BaseHead /></head><body><Header /></body><style>{\`@use "../styles/global.scss";\`}</style></html> | ||
</Fragment> | ||
export default function __AstroComponent_(_props: Record<string, any>): any {}\n`; | ||
const { code } = await convertToTSX(input, { sourcemap: 'external' }); | ||
assert.snapshot(code, output, 'expected code to match snapshot'); | ||
}); | ||
|
||
test.run(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix was to remove this divergence from the html spec in the
inHead
insertion mode, see the "anything else" section to find the correct steps to be performed