diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/interfaces.ts | 36 | ||||
-rw-r--r-- | src/compiler/parse/index.ts | 33 | ||||
-rw-r--r-- | src/compiler/parse/read/script.ts | 13 | ||||
-rw-r--r-- | src/compiler/parse/state/tag.ts | 42 |
4 files changed, 49 insertions, 75 deletions
diff --git a/src/compiler/interfaces.ts b/src/compiler/interfaces.ts index bedb29cda..b77357d23 100644 --- a/src/compiler/interfaces.ts +++ b/src/compiler/interfaces.ts @@ -58,7 +58,7 @@ export interface Parser { export interface Script extends BaseNode { type: 'Script'; - context: string; + context: 'runtime' | 'setup'; content: string; } @@ -75,8 +75,8 @@ export interface Style extends BaseNode { export interface Ast { html: TemplateNode; css: Style; - instance: Script; module: Script; + // instance: Script; } export interface Warning { @@ -94,38 +94,6 @@ export type ModuleFormat = 'esm' | 'cjs'; export type CssHashGetter = (args: { name: string; filename: string | undefined; css: string; hash: (input: string) => string }) => string; -export interface CompileOptions { - format?: ModuleFormat; - name?: string; - filename?: string; - generate?: 'dom' | 'ssr' | false; - - sourcemap?: object | string; - outputFilename?: string; - cssOutputFilename?: string; - sveltePath?: string; - - dev?: boolean; - accessors?: boolean; - immutable?: boolean; - hydratable?: boolean; - legacy?: boolean; - customElement?: boolean; - tag?: string; - css?: boolean; - loopGuardTimeout?: number; - namespace?: string; - cssHash?: CssHashGetter; - - preserveComments?: boolean; - preserveWhitespace?: boolean; -} - -export interface ParserOptions { - filename?: string; - customElement?: boolean; -} - export interface Visitor { enter: (node: Node) => void; leave?: (node: Node) => void; diff --git a/src/compiler/parse/index.ts b/src/compiler/parse/index.ts index eab2c42c5..f98119d73 100644 --- a/src/compiler/parse/index.ts +++ b/src/compiler/parse/index.ts @@ -232,33 +232,34 @@ export default function parse(template: string, options: ParserOptions = {}): As ); } - const instance_scripts = parser.js.filter((script) => script.context === 'default'); - const module_scripts = parser.js.filter((script) => script.context === 'module'); + // const instance_scripts = parser.js.filter((script) => script.context === 'default'); + // const module_scripts = parser.js.filter((script) => script.context === 'module'); + const hmx_scripts = parser.js.filter((script) => script.context === 'setup'); - if (instance_scripts.length > 1) { + if (hmx_scripts.length > 1) { parser.error( { code: 'invalid-script', - message: 'A component can only have one instance-level <script> element', + message: 'A component can only have one <script astro> element', }, - instance_scripts[1].start + hmx_scripts[1].start ); } - if (module_scripts.length > 1) { - parser.error( - { - code: 'invalid-script', - message: 'A component can only have one <script context="module"> element', - }, - module_scripts[1].start - ); - } + // if (module_scripts.length > 1) { + // parser.error( + // { + // code: 'invalid-script', + // message: 'A component can only have one <script context="module"> element', + // }, + // module_scripts[1].start + // ); + // } return { html: parser.html, css: parser.css[0], - instance: instance_scripts[0], - module: module_scripts[0], + // instance: instance_scripts[0], + module: hmx_scripts[0], }; } diff --git a/src/compiler/parse/read/script.ts b/src/compiler/parse/read/script.ts index eb7a8c5b3..7afbfb08f 100644 --- a/src/compiler/parse/read/script.ts +++ b/src/compiler/parse/read/script.ts @@ -7,15 +7,16 @@ import { Node, Program } from 'estree'; const script_closing_tag = '</script>'; -function get_context(parser: Parser, attributes: any[], start: number): string { - const context = attributes.find((attribute) => attribute.name === 'context'); - if (!context) return 'default'; +function get_context(parser: Parser, attributes: any[], start: number): 'runtime' | 'setup' { + const context = attributes.find((attribute) => attribute.name === 'astro'); + if (!context) return 'runtime'; + if (context.value === true) return 'setup'; if (context.value.length !== 1 || context.value[0].type !== 'Text') { parser.error( { code: 'invalid-script', - message: 'context attribute must be static', + message: 'astro attribute must be static', }, start ); @@ -23,11 +24,11 @@ function get_context(parser: Parser, attributes: any[], start: number): string { const value = context.value[0].data; - if (value !== 'module') { + if (value !== 'setup') { parser.error( { code: 'invalid-script', - message: 'If the context attribute is supplied, its value must be "module"', + message: 'If the "astro" attribute has a value, its value must be "setup"', }, context.start ); diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index fa5ccb6e3..e1dbcab42 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -14,13 +14,14 @@ import list from '../../utils/list.js'; const valid_tag_name = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/; const meta_tags = new Map([ - ['svelte:head', 'Head'], - ['svelte:options', 'Options'], - ['svelte:window', 'Window'], - ['svelte:body', 'Body'], + ['slot:head', 'Head'], + ['slot:body', 'Body'], + // ['astro:options', 'Options'], + // ['astro:window', 'Window'], + // ['astro:body', 'Body'], ]); -const valid_meta_tags = Array.from(meta_tags.keys()).concat('svelte:self', 'svelte:component', 'svelte:fragment'); +const valid_meta_tags = Array.from(meta_tags.keys()); //.concat('astro:self', 'astro:component', 'astro:fragment'); const specials = new Map([ [ @@ -39,9 +40,10 @@ const specials = new Map([ ], ]); -const SELF = /^svelte:self(?=[\s/>])/; -const COMPONENT = /^svelte:component(?=[\s/>])/; -const SLOT = /^svelte:fragment(?=[\s/>])/; +const SELF = /^astro:self(?=[\s/>])/; +const COMPONENT = /^astro:component(?=[\s/>])/; +const SLOT = /^astro:fragment(?=[\s/>])/; +const HEAD = /^head(?=[\s/>])/; function parent_is_head(stack) { let i = stack.length; @@ -79,7 +81,7 @@ export default function tag(parser: Parser) { if (meta_tags.has(name)) { const slug = meta_tags.get(name).toLowerCase(); if (is_closing_tag) { - if ((name === 'svelte:window' || name === 'svelte:body') && parser.current().children.length) { + if ((name === 'astro:window' || name === 'astro:body') && parser.current().children.length) { parser.error( { code: `invalid-${slug}-content`, @@ -115,9 +117,9 @@ export default function tag(parser: Parser) { const type = meta_tags.has(name) ? meta_tags.get(name) - : /[A-Z]/.test(name[0]) || name === 'svelte:self' || name === 'svelte:component' + : /[A-Z]/.test(name[0]) || name === 'astro:self' || name === 'astro:component' ? 'InlineComponent' - : name === 'svelte:fragment' + : name === 'astro:fragment' ? 'SlotTemplate' : name === 'title' && parent_is_head(parser.stack) ? 'Title' @@ -197,13 +199,13 @@ export default function tag(parser: Parser) { parser.allow_whitespace(); } - if (name === 'svelte:component') { + if (name === 'astro:component') { const index = element.attributes.findIndex((attr) => attr.type === 'Attribute' && attr.name === 'this'); if (!~index) { parser.error( { code: 'missing-component-definition', - message: "<svelte:component> must have a 'this' attribute", + message: "<astro:component> must have a 'this' attribute", }, start ); @@ -281,27 +283,29 @@ function read_tag_name(parser: Parser) { parser.error( { code: 'invalid-self-placement', - message: '<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components', + message: '<astro:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components', }, start ); } - return 'svelte:self'; + return 'astro:self'; } - if (parser.read(COMPONENT)) return 'svelte:component'; + if (parser.read(COMPONENT)) return 'astro:component'; - if (parser.read(SLOT)) return 'svelte:fragment'; + if (parser.read(SLOT)) return 'astro:fragment'; + + if (parser.read(HEAD)) return 'head'; const name = parser.read_until(/(\s|\/|>)/); if (meta_tags.has(name)) return name; - if (name.startsWith('svelte:')) { + if (name.startsWith('astro:')) { const match = fuzzymatch(name.slice(7), valid_meta_tags); - let message = `Valid <svelte:...> tag names are ${list(valid_meta_tags)}`; + let message = `Valid <astro:...> tag names are ${list(valid_meta_tags)}`; if (match) message += ` (did you mean '${match}'?)`; parser.error( |