Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/svelte2tsx/src/svelte2tsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ function processSvelteTemplate(
handleStyleTag(node);
break;
case 'Element':
scripts.handleScriptTag(node, parent);
scripts.checkIfElementIsScriptTag(node, parent);
break;
case 'RawMustacheTag':
scripts.checkIfContainsScriptTag(node);
break;
case 'BlockStatement':
scopeStack.push();
Expand Down
10 changes: 8 additions & 2 deletions packages/svelte2tsx/src/svelte2tsx/nodes/Scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ export class Scripts {

constructor(private htmlxAst: Node) {}

handleScriptTag = (node: Node, parent: Node) => {
checkIfElementIsScriptTag(node: Node, parent: Node) {
if (parent !== this.htmlxAst && node.name === 'script') {
this.topLevelScripts = this.topLevelScripts.filter(
(tag) => tag.start !== node.start || tag.end !== node.end
);
}
};
}

checkIfContainsScriptTag(node: Node) {
this.topLevelScripts = this.topLevelScripts.filter(
(tag) => !(node.start <= tag.start && node.end >= tag.end)
);
}

getTopLevelScriptTags(): { scriptTag: Node; moduleScriptTag: Node } {
let scriptTag: Node = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
///<reference types="svelte" />
<></>;function render() {

const schema = {
key: "value"
};
;
() => (<>

{ ``}</>);
return { props: {}, slots: {}, getters: {}, events: {} }}

export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
///<reference types="svelte" />
;function render() {

const schema = {
key: "value"
};
;
async () => {

``;};
return { props: {}, slots: {}, getters: {}, events: {} }}

export default class Input__SvelteComponent_ extends __sveltets_1_createSvelte2TsxComponent(__sveltets_1_partial(__sveltets_1_with_any_event(render()))) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
const schema = {
key: "value"
};
</script>

{@html `<script type="application/ld+json">${JSON.stringify(schema)}</script>`}