-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: disallow invalid attributes for
<svelte:window>
and `<svelte:d…
…ocument>` (#14228)
- Loading branch information
Showing
10 changed files
with
85 additions
and
0 deletions.
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 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: disallow invalid attributes for `<svelte:window>` and `<svelte:document>` |
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
12 changes: 12 additions & 0 deletions
12
packages/svelte/src/compiler/phases/2-analyze/visitors/SvelteDocument.js
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 |
---|---|---|
@@ -1,12 +1,24 @@ | ||
/** @import { AST } from '#compiler' */ | ||
/** @import { Context } from '../types' */ | ||
import { disallow_children } from './shared/special-element.js'; | ||
import * as e from '../../../errors.js'; | ||
import { is_event_attribute } from '../../../utils/ast.js'; | ||
|
||
/** | ||
* @param {AST.SvelteDocument} node | ||
* @param {Context} context | ||
*/ | ||
export function SvelteDocument(node, context) { | ||
disallow_children(node); | ||
|
||
for (const attribute of node.attributes) { | ||
if ( | ||
attribute.type === 'SpreadAttribute' || | ||
(attribute.type === 'Attribute' && !is_event_attribute(attribute)) | ||
) { | ||
e.illegal_element_attribute(attribute, 'svelte:document'); | ||
} | ||
} | ||
|
||
context.next(); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/svelte/src/compiler/phases/2-analyze/visitors/SvelteWindow.js
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 |
---|---|---|
@@ -1,12 +1,24 @@ | ||
/** @import { AST } from '#compiler' */ | ||
/** @import { Context } from '../types' */ | ||
import { disallow_children } from './shared/special-element.js'; | ||
import * as e from '../../../errors.js'; | ||
import { is_event_attribute } from '../../../utils/ast.js'; | ||
|
||
/** | ||
* @param {AST.SvelteWindow} node | ||
* @param {Context} context | ||
*/ | ||
export function SvelteWindow(node, context) { | ||
disallow_children(node); | ||
|
||
for (const attribute of node.attributes) { | ||
if ( | ||
attribute.type === 'SpreadAttribute' || | ||
(attribute.type === 'Attribute' && !is_event_attribute(attribute)) | ||
) { | ||
e.illegal_element_attribute(attribute, 'svelte:window'); | ||
} | ||
} | ||
|
||
context.next(); | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/svelte/tests/validator/samples/illegal_spread_element-document/errors.json
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,14 @@ | ||
[ | ||
{ | ||
"code": "illegal_element_attribute", | ||
"message": "`<svelte:document>` does not support non-event attributes or spread attributes", | ||
"start": { | ||
"line": 4, | ||
"column": 17 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 23 | ||
} | ||
} | ||
] |
4 changes: 4 additions & 0 deletions
4
packages/svelte/tests/validator/samples/illegal_spread_element-document/input.svelte
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,4 @@ | ||
<script> | ||
let a = {}; | ||
</script> | ||
<svelte:document {...a}></svelte:document> |
14 changes: 14 additions & 0 deletions
14
packages/svelte/tests/validator/samples/illegal_spread_element-window/errors.json
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,14 @@ | ||
[ | ||
{ | ||
"code": "illegal_element_attribute", | ||
"message": "`<svelte:window>` does not support non-event attributes or spread attributes", | ||
"start": { | ||
"line": 4, | ||
"column": 15 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 21 | ||
} | ||
} | ||
] |
4 changes: 4 additions & 0 deletions
4
packages/svelte/tests/validator/samples/illegal_spread_element-window/input.svelte
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,4 @@ | ||
<script> | ||
let a = {}; | ||
</script> | ||
<svelte:window {...a}></svelte:window> |