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(); parser.allowWhitespace();
} }
element.spread = readSpread(parser);
const uniqueNames = new Set(); const uniqueNames = new Set();
let attribute; let attribute;
@ -291,6 +289,23 @@ function readTagName(parser: Parser) {
function readAttribute(parser: Parser, uniqueNames: Set<string>) { function readAttribute(parser: Parser, uniqueNames: Set<string>) {
const start = parser.index; 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|=|\/|>)/); let name = parser.readUntil(/(\s|=|\/|>)/);
if (!name) return null; if (!name) return null;
if (uniqueNames.has(name)) { if (uniqueNames.has(name)) {
@ -385,28 +400,4 @@ function readSequence(parser: Parser, done: () => boolean) {
} }
parser.error(`Unexpected end of input`); 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,19 +10,20 @@
"end": 24, "end": 24,
"type": "Element", "type": "Element",
"name": "div", "name": "div",
"attributes": [], "attributes": [
"children": [], {
"spread": { "start": 5,
"start": 5, "end": 17,
"end": 17, "type": "Spread",
"type": "Spread", "expression": {
"expression": { "type": "Identifier",
"type": "Identifier", "start": 10,
"start": 10, "end": 15,
"end": 15, "name": "props"
"name": "props" }
} }
} ],
"children": []
} }
] ]
}, },

Loading…
Cancel
Save