summaryrefslogtreecommitdiff
path: root/packages/astro/src/internal/__astro_component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/astro/src/internal/__astro_component.ts')
-rw-r--r--packages/astro/src/internal/__astro_component.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/packages/astro/src/internal/__astro_component.ts b/packages/astro/src/internal/__astro_component.ts
index 9470e5b14..0543df203 100644
--- a/packages/astro/src/internal/__astro_component.ts
+++ b/packages/astro/src/internal/__astro_component.ts
@@ -1,12 +1,26 @@
import type { Renderer, AstroComponentMetadata } from '../@types/astro';
import hash from 'shorthash';
import { valueToEstree, Value } from 'estree-util-value-to-estree';
-import { generate } from 'astring';
+import { generate, GENERATOR, Generator } from 'astring';
import * as astroHtml from './renderer-html';
// A more robust version alternative to `JSON.stringify` that can handle most values
// see https://github.com/remcohaszing/estree-util-value-to-estree#readme
-const serialize = (value: Value) => generate(valueToEstree(value));
+const customGenerator: Generator = {
+ ...GENERATOR,
+ Literal(node, state) {
+ if (node.raw != null) {
+ // escape closing script tags in strings so browsers wouldn't interpret them as
+ // closing the actual end tag in HTML
+ state.write(node.raw.replace('</script>', '<\\/script>'));
+ } else {
+ GENERATOR.Literal(node, state);
+ }
+ },
+};
+const serialize = (value: Value) => generate(valueToEstree(value), {
+ generator: customGenerator,
+});
export interface RendererInstance {
source: string | null;