|
|
@ -18,7 +18,7 @@ const meta_tags = new Map([
|
|
|
|
['svelte:body', 'Body']
|
|
|
|
['svelte:body', 'Body']
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
const valid_meta_tags = Array.from(meta_tags.keys()).concat('svelte:self', 'svelte:component');
|
|
|
|
const valid_meta_tags = Array.from(meta_tags.keys()).concat('svelte:self', 'svelte:component', 'svelte:element');
|
|
|
|
|
|
|
|
|
|
|
|
const specials = new Map([
|
|
|
|
const specials = new Map([
|
|
|
|
[
|
|
|
|
[
|
|
|
@ -39,6 +39,7 @@ const specials = new Map([
|
|
|
|
|
|
|
|
|
|
|
|
const SELF = /^svelte:self(?=[\s/>])/;
|
|
|
|
const SELF = /^svelte:self(?=[\s/>])/;
|
|
|
|
const COMPONENT = /^svelte:component(?=[\s/>])/;
|
|
|
|
const COMPONENT = /^svelte:component(?=[\s/>])/;
|
|
|
|
|
|
|
|
const ELEMENT = /^svelte:element(?=[\s/>])/;
|
|
|
|
|
|
|
|
|
|
|
|
function parent_is_head(stack) {
|
|
|
|
function parent_is_head(stack) {
|
|
|
|
let i = stack.length;
|
|
|
|
let i = stack.length;
|
|
|
@ -182,6 +183,24 @@ export default function tag(parser: Parser) {
|
|
|
|
element.expression = definition.value[0].expression;
|
|
|
|
element.expression = definition.value[0].expression;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (name === 'svelte:element') {
|
|
|
|
|
|
|
|
const index = element.attributes.findIndex(attr => attr.type === 'Attribute' && attr.name === 'tag');
|
|
|
|
|
|
|
|
if (!~index) {
|
|
|
|
|
|
|
|
parser.error({
|
|
|
|
|
|
|
|
code: `missing-component-definition`,
|
|
|
|
|
|
|
|
message: `<svelte:element> must have a 'tag' attribute`
|
|
|
|
|
|
|
|
}, start);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const definition = element.attributes[index];
|
|
|
|
|
|
|
|
if (definition.value === true || definition.value.length !== 1 || (definition.value[0].type !== 'Text' && definition.value[0].type !== 'MustacheTag')) {
|
|
|
|
|
|
|
|
parser.error({
|
|
|
|
|
|
|
|
code: `invalid-tag-definition`,
|
|
|
|
|
|
|
|
message: `invalid tag definition`
|
|
|
|
|
|
|
|
}, definition.start);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// special cases – top-level <script> and <style>
|
|
|
|
// special cases – top-level <script> and <style>
|
|
|
|
if (specials.has(name) && parser.stack.length === 1) {
|
|
|
|
if (specials.has(name) && parser.stack.length === 1) {
|
|
|
|
const special = specials.get(name);
|
|
|
|
const special = specials.get(name);
|
|
|
@ -259,6 +278,8 @@ function read_tag_name(parser: Parser) {
|
|
|
|
|
|
|
|
|
|
|
|
if (parser.read(COMPONENT)) return 'svelte:component';
|
|
|
|
if (parser.read(COMPONENT)) return 'svelte:component';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parser.read(ELEMENT)) return 'svelte:element';
|
|
|
|
|
|
|
|
|
|
|
|
const name = parser.read_until(/(\s|\/|>)/);
|
|
|
|
const name = parser.read_until(/(\s|\/|>)/);
|
|
|
|
|
|
|
|
|
|
|
|
if (meta_tags.has(name)) return name;
|
|
|
|
if (meta_tags.has(name)) return name;
|
|
|
|