parse <:Window> tags

pull/391/head
Rich-Harris 8 years ago
parent efce7acabe
commit 4360a03ffd

@ -32,6 +32,7 @@ export default function parse ( template, options = {} ) {
index: 0,
template,
stack: [],
metaTags: {},
current () {
return this.stack[ this.stack.length - 1 ];

@ -11,6 +11,10 @@ const invalidUnquotedAttributeCharacters = /[\s"'=<>\/`]/;
const SELF = ':Self';
const metaTags = {
':Window': true
};
const specials = {
script: {
read: readScript,
@ -81,6 +85,22 @@ export default function tag ( parser ) {
const name = readTagName( parser );
if ( name in metaTags ) {
if ( name in parser.metaTags ) {
if ( isClosingTag && parser.current().children.length ) {
parser.error( `<${name}> cannot have children`, parser.current().children[0].start );
}
parser.error( `A component can only have one <${name}> tag`, start );
}
parser.metaTags[ name ] = true;
if ( parser.stack.length > 1 ) {
parser.error( `<${name}> tags cannot be inside elements or blocks`, start );
}
}
parser.allowWhitespace();
if ( isClosingTag ) {
@ -194,6 +214,9 @@ function readTagName ( parser ) {
}
const name = parser.readUntil( /(\s|\/|>)/ );
if ( name in metaTags ) return name;
if ( !validTagName.test( name ) ) {
parser.error( `Expected valid tag name`, start );
}

@ -0,0 +1,8 @@
{
"message": "<:Window> cannot have children",
"loc": {
"line": 1,
"column": 9
},
"pos": 9
}

@ -0,0 +1,8 @@
{
"message": "A component can only have one <:Window> tag",
"loc": {
"line": 2,
"column": 0
},
"pos": 11
}

@ -0,0 +1,8 @@
{
"message": "<:Window> tags cannot be inside elements or blocks",
"loc": {
"line": 2,
"column": 1
},
"pos": 13
}

@ -0,0 +1,8 @@
{
"message": "<:Window> tags cannot be inside elements or blocks",
"loc": {
"line": 2,
"column": 1
},
"pos": 7
}
Loading…
Cancel
Save