When running the compiler with this input (Run with deno but should be the same):
import {transform} from 'https://cdn.jsdelivr.net/gh/withastro/compiler@main/lib/compiler/deno/mod.ts'
let compiled = (await transform(`---
---
<script src="https://example.com" this-makes-the-script-not-show="true">
console.log('This will not show because it has a prop that is set to "true" and a src prop')
</script>
<script src="https://example.com" this-also-hides-the-script={true}>
console.log('This will not show because it has a prop that is set to {true} and a src prop')
</script>
<script src="https://example.com" this-too-hides-the-script=true>
console.log('This will not show because it has a prop that is set to true and a src prop')
</script>
<script src="https://example.com" this-shows-the-script-but-removes-this-prop={false}>
console.log('This will show becuase the prop is set to {false} and not true, but the prop is removed')
</script>
<script src="https://example.com" this-also-shows-the-script-but-removes-this-prop=false>
console.log('This will show becuase the prop is set to false and not true, but the prop is removed')
</script>
<script src="https://example.com" this-makes-the-script-show={"true"}>
console.log('This will show because the prop is set to {"true"} instead of "true"')
</script>
<script src="https://example.com">
console.log('This will show because it doesn\'t have a prop set to "true"')
</script>
<script>
console.log('This will show')
</script>
<script without-the-src-prop-it-also-shows="true">
console.log('This will show because it doesn\'t have a src prop')
</script>`))
console.log(compiled.code)
Produces this output:
import {
Fragment,
render as $$render,
createAstro as $$createAstro,
createComponent as $$createComponent,
renderComponent as $$renderComponent,
renderSlot as $$renderSlot,
addAttribute as $$addAttribute,
spreadAttributes as $$spreadAttributes,
defineStyleVars as $$defineStyleVars,
defineScriptVars as $$defineScriptVars,
createMetadata as $$createMetadata
} from "https://cdn.jsdelivr.net/gh/withastro/compiler@main/lib/compiler/deno/internal.ts";
export const $$metadata = $$createMetadata("<stdin>", { modules: [], hydratedComponents: [], hydrationDirectives: new Set([]), hoisted: [{ type: 'inline', value: `
console.log('This will show because it doesn't have a src prop')
` }, { type: 'remote', src: 'https://example.com' }, { type: 'remote', src: 'https://example.com' }, { type: 'remote', src: 'https://example.com' }] });
const $$Astro = $$createAstro(import.meta.url, 'https://astro.build', '.');
const Astro = $$Astro;
//@ts-ignore
const $$Component = $$createComponent(async ($$result, $$props, $$slots) => {
const Astro = $$result.createAstro($$Astro, $$props, $$slots);
const SCRIPTS = [
{props:{"without-the-src-prop-it-also-shows":"true"},children:`console.log('This will show because it doesn't have a src prop')`},
{props:{"src":"https://example.com","this-too-hides-the-script":"true"},children:`console.log('This will not show because it has a prop that is set to true and a src prop')`},
{props:{"src":"https://example.com","this-also-hides-the-script":(true)},children:`console.log('This will not show because it has a prop that is set to {true} and a src prop')`},
{props:{"src":"https://example.com","this-makes-the-script-not-show":"true"},children:`console.log('This will not show because it has a prop that is set to "true" and a src prop')`},
];
for (const SCRIPT of SCRIPTS) $$result.scripts.add(SCRIPT);
return $$render`<html><head>
<script src="https://example.com"${$$addAttribute(false, "this-shows-the-script-but-removes-this-prop")}>
console.log('This will show becuase the prop is set to {false} and not true, but the prop is removed')
</script>
<script src="https://example.com" this-also-shows-the-script-but-removes-this-prop="false">
console.log('This will show becuase the prop is set to false and not true, but the prop is removed')
</script>
<script src="https://example.com"${$$addAttribute("true", "this-makes-the-script-show")}>
console.log('This will show because the prop is set to {"true"} instead of "true"')
</script>
<script src="https://example.com">
console.log('This will show because it doesn't have a prop set to "true"')
</script>
<script>
console.log('This will show')
</script>
</head><body></body></html>`;
});
export default $$Component;