include spread with other attributes

pull/1289/head
Rich-Harris 7 years ago
parent d0c696bb2b
commit 416fc0c81b

@ -178,8 +178,6 @@ export default function tag(parser: Parser) {
parser.allowWhitespace();
}
element.spread = readSpread(parser);
const uniqueNames = new Set();
let attribute;
@ -291,6 +289,23 @@ function readTagName(parser: Parser) {
function readAttribute(parser: Parser, uniqueNames: Set<string>) {
const start = parser.index;
if (parser.eat('{{')) {
parser.allowWhitespace();
parser.eat('...', true, 'Expected spread operator (...)');
const expression = readExpression(parser);
parser.allowWhitespace();
parser.eat('}}', true);
return {
start,
end: parser.index,
type: 'Spread',
expression
};
}
let name = parser.readUntil(/(\s|=|\/|>)/);
if (!name) return null;
if (uniqueNames.has(name)) {
@ -386,27 +401,3 @@ function readSequence(parser: Parser, done: () => boolean) {
parser.error(`Unexpected end of input`);
}
function readSpread(parser: Parser) {
const start = parser.index;
if (parser.eat('{{...')) {
const expression = readExpression(parser);
parser.allowWhitespace();
if (!parser.eat('}}')) {
parser.error(`Expected }}`);
}
parser.allowWhitespace();
return {
start,
end: parser.index,
type: 'Spread',
expression,
};
}
return null;
}

@ -10,9 +10,8 @@
"end": 24,
"type": "Element",
"name": "div",
"attributes": [],
"children": [],
"spread": {
"attributes": [
{
"start": 5,
"end": 17,
"type": "Spread",
@ -23,6 +22,8 @@
"name": "props"
}
}
],
"children": []
}
]
},

Loading…
Cancel
Save