|
|
@ -32,7 +32,7 @@ function trimWhitespace(block: Node, trimBefore: boolean, trimAfter: boolean) {
|
|
|
|
|
|
|
|
|
|
|
|
export default function mustache(parser: Parser) {
|
|
|
|
export default function mustache(parser: Parser) {
|
|
|
|
const start = parser.index;
|
|
|
|
const start = parser.index;
|
|
|
|
parser.index += parser.v2 ? 1 : 2;
|
|
|
|
parser.index += 1;
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
|
|
|
|
|
|
|
@ -64,7 +64,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
|
|
|
|
|
|
|
|
parser.eat(expected, true);
|
|
|
|
parser.eat(expected, true);
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.eat(parser.v2 ? '}' : '}}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
while (block.elseif) {
|
|
|
|
while (block.elseif) {
|
|
|
|
block.end = parser.index;
|
|
|
|
block.end = parser.index;
|
|
|
@ -86,7 +86,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
|
|
|
|
|
|
|
|
block.end = parser.index;
|
|
|
|
block.end = parser.index;
|
|
|
|
parser.stack.pop();
|
|
|
|
parser.stack.pop();
|
|
|
|
} else if (parser.eat(parser.v2 ? ':elseif' : 'elseif')) {
|
|
|
|
} else if (parser.eat(':elseif')) {
|
|
|
|
const block = parser.current();
|
|
|
|
const block = parser.current();
|
|
|
|
if (block.type !== 'IfBlock')
|
|
|
|
if (block.type !== 'IfBlock')
|
|
|
|
parser.error({
|
|
|
|
parser.error({
|
|
|
@ -99,7 +99,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
const expression = readExpression(parser);
|
|
|
|
const expression = readExpression(parser);
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.eat(parser.v2 ? '}' : '}}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
block.else = {
|
|
|
|
block.else = {
|
|
|
|
start: parser.index,
|
|
|
|
start: parser.index,
|
|
|
@ -118,7 +118,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
parser.stack.push(block.else.children[0]);
|
|
|
|
parser.stack.push(block.else.children[0]);
|
|
|
|
} else if (parser.eat(parser.v2 ? ':else' : 'else')) {
|
|
|
|
} else if (parser.eat(':else')) {
|
|
|
|
const block = parser.current();
|
|
|
|
const block = parser.current();
|
|
|
|
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
|
|
|
|
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
|
|
|
|
parser.error({
|
|
|
|
parser.error({
|
|
|
@ -128,7 +128,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.eat(parser.v2 ? '}' : '}}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
block.else = {
|
|
|
|
block.else = {
|
|
|
|
start: parser.index,
|
|
|
|
start: parser.index,
|
|
|
@ -138,7 +138,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
parser.stack.push(block.else);
|
|
|
|
parser.stack.push(block.else);
|
|
|
|
} else if (parser.eat(parser.v2 ? ':then' : 'then')) {
|
|
|
|
} else if (parser.eat(':then')) {
|
|
|
|
// TODO DRY out this and the next section
|
|
|
|
// TODO DRY out this and the next section
|
|
|
|
const pendingBlock = parser.current();
|
|
|
|
const pendingBlock = parser.current();
|
|
|
|
if (pendingBlock.type === 'PendingBlock') {
|
|
|
|
if (pendingBlock.type === 'PendingBlock') {
|
|
|
@ -150,7 +150,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
awaitBlock.value = parser.readIdentifier();
|
|
|
|
awaitBlock.value = parser.readIdentifier();
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.eat(parser.v2 ? '}' : '}}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
const thenBlock: Node = {
|
|
|
|
const thenBlock: Node = {
|
|
|
|
start,
|
|
|
|
start,
|
|
|
@ -162,7 +162,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
awaitBlock.then = thenBlock;
|
|
|
|
awaitBlock.then = thenBlock;
|
|
|
|
parser.stack.push(thenBlock);
|
|
|
|
parser.stack.push(thenBlock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (parser.eat(parser.v2 ? ':catch' : 'catch')) {
|
|
|
|
} else if (parser.eat(':catch')) {
|
|
|
|
const thenBlock = parser.current();
|
|
|
|
const thenBlock = parser.current();
|
|
|
|
if (thenBlock.type === 'ThenBlock') {
|
|
|
|
if (thenBlock.type === 'ThenBlock') {
|
|
|
|
thenBlock.end = start;
|
|
|
|
thenBlock.end = start;
|
|
|
@ -173,7 +173,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
awaitBlock.error = parser.readIdentifier();
|
|
|
|
awaitBlock.error = parser.readIdentifier();
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.eat(parser.v2 ? '}' : '}}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
const catchBlock: Node = {
|
|
|
|
const catchBlock: Node = {
|
|
|
|
start,
|
|
|
|
start,
|
|
|
@ -336,7 +336,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parser.eat(parser.v2 ? '}' : '}}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
parser.current().children.push(block);
|
|
|
|
parser.current().children.push(block);
|
|
|
|
parser.stack.push(block);
|
|
|
|
parser.stack.push(block);
|
|
|
@ -346,44 +346,12 @@ export default function mustache(parser: Parser) {
|
|
|
|
childBlock.start = parser.index;
|
|
|
|
childBlock.start = parser.index;
|
|
|
|
parser.stack.push(childBlock);
|
|
|
|
parser.stack.push(childBlock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (parser.eat('yield')) {
|
|
|
|
} else if (parser.eat('@html')) {
|
|
|
|
// {{yield}}
|
|
|
|
|
|
|
|
// TODO deprecate
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parser.v2) {
|
|
|
|
|
|
|
|
const expressionEnd = parser.index;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
parser.current().children.push({
|
|
|
|
|
|
|
|
start,
|
|
|
|
|
|
|
|
end: parser.index,
|
|
|
|
|
|
|
|
type: 'MustacheTag',
|
|
|
|
|
|
|
|
expression: {
|
|
|
|
|
|
|
|
start: expressionEnd - 5,
|
|
|
|
|
|
|
|
end: expressionEnd,
|
|
|
|
|
|
|
|
type: 'Identifier',
|
|
|
|
|
|
|
|
name: 'yield'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
parser.eat('}}', true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.current().children.push({
|
|
|
|
|
|
|
|
start,
|
|
|
|
|
|
|
|
end: parser.index,
|
|
|
|
|
|
|
|
type: 'Element',
|
|
|
|
|
|
|
|
name: 'slot',
|
|
|
|
|
|
|
|
attributes: [],
|
|
|
|
|
|
|
|
children: []
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (parser.eat(parser.v2 ? '@html' : '{')) {
|
|
|
|
|
|
|
|
// {{{raw}}} mustache
|
|
|
|
// {{{raw}}} mustache
|
|
|
|
const expression = readExpression(parser);
|
|
|
|
const expression = readExpression(parser);
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.eat(parser.v2 ? '}' : '}}}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
parser.current().children.push({
|
|
|
|
parser.current().children.push({
|
|
|
|
start,
|
|
|
|
start,
|
|
|
@ -395,7 +363,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
const expression = readExpression(parser);
|
|
|
|
const expression = readExpression(parser);
|
|
|
|
|
|
|
|
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.allowWhitespace();
|
|
|
|
parser.eat(parser.v2 ? '}' : '}}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
parser.current().children.push({
|
|
|
|
parser.current().children.push({
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|