|
|
|
@ -33,6 +33,8 @@ function trim_whitespace(block: TemplateNode, trim_before: boolean, trim_after:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const regex_whitespace_with_closing_curly_brace = /\s*}/;
|
|
|
|
|
|
|
|
|
|
|
|
export default function mustache(parser: Parser) {
|
|
|
|
export default function mustache(parser: Parser) {
|
|
|
|
const start = parser.index;
|
|
|
|
const start = parser.index;
|
|
|
|
parser.index += 1;
|
|
|
|
parser.index += 1;
|
|
|
|
@ -106,8 +108,8 @@ export default function mustache(parser: Parser) {
|
|
|
|
const block = parser.current();
|
|
|
|
const block = parser.current();
|
|
|
|
if (block.type !== 'IfBlock') {
|
|
|
|
if (block.type !== 'IfBlock') {
|
|
|
|
parser.error(
|
|
|
|
parser.error(
|
|
|
|
parser.stack.some(block => block.type === 'IfBlock')
|
|
|
|
parser.stack.some(block => block.type === 'IfBlock')
|
|
|
|
? parser_errors.invalid_elseif_placement_unclosed_block(to_string(block))
|
|
|
|
? parser_errors.invalid_elseif_placement_unclosed_block(to_string(block))
|
|
|
|
: parser_errors.invalid_elseif_placement_outside_if
|
|
|
|
: parser_errors.invalid_elseif_placement_outside_if
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -141,8 +143,8 @@ export default function mustache(parser: Parser) {
|
|
|
|
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(
|
|
|
|
parser.stack.some(block => block.type === 'IfBlock' || block.type === 'EachBlock')
|
|
|
|
parser.stack.some(block => block.type === 'IfBlock' || block.type === 'EachBlock')
|
|
|
|
? parser_errors.invalid_else_placement_unclosed_block(to_string(block))
|
|
|
|
? parser_errors.invalid_else_placement_unclosed_block(to_string(block))
|
|
|
|
: parser_errors.invalid_else_placement_outside_if
|
|
|
|
: parser_errors.invalid_else_placement_outside_if
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -167,15 +169,15 @@ export default function mustache(parser: Parser) {
|
|
|
|
if (block.type !== 'PendingBlock') {
|
|
|
|
if (block.type !== 'PendingBlock') {
|
|
|
|
parser.error(
|
|
|
|
parser.error(
|
|
|
|
parser.stack.some(block => block.type === 'PendingBlock')
|
|
|
|
parser.stack.some(block => block.type === 'PendingBlock')
|
|
|
|
? parser_errors.invalid_then_placement_unclosed_block(to_string(block))
|
|
|
|
? parser_errors.invalid_then_placement_unclosed_block(to_string(block))
|
|
|
|
: parser_errors.invalid_then_placement_without_await
|
|
|
|
: parser_errors.invalid_then_placement_without_await
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (block.type !== 'ThenBlock' && block.type !== 'PendingBlock') {
|
|
|
|
if (block.type !== 'ThenBlock' && block.type !== 'PendingBlock') {
|
|
|
|
parser.error(parser.stack.some(block => block.type === 'ThenBlock' || block.type === 'PendingBlock')
|
|
|
|
parser.error(parser.stack.some(block => block.type === 'ThenBlock' || block.type === 'PendingBlock')
|
|
|
|
? parser_errors.invalid_catch_placement_unclosed_block(to_string(block))
|
|
|
|
? parser_errors.invalid_catch_placement_unclosed_block(to_string(block))
|
|
|
|
: parser_errors.invalid_catch_placement_without_await
|
|
|
|
: parser_errors.invalid_catch_placement_without_await
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -290,7 +292,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
|
|
|
|
|
|
|
|
const await_block_shorthand = type === 'AwaitBlock' && parser.eat('then');
|
|
|
|
const await_block_shorthand = type === 'AwaitBlock' && parser.eat('then');
|
|
|
|
if (await_block_shorthand) {
|
|
|
|
if (await_block_shorthand) {
|
|
|
|
if (parser.match_regex(/\s*}/)) {
|
|
|
|
if (parser.match_regex(regex_whitespace_with_closing_curly_brace)) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
parser.require_whitespace();
|
|
|
|
parser.require_whitespace();
|
|
|
|
@ -301,7 +303,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
|
|
|
|
|
|
|
|
const await_block_catch_shorthand = !await_block_shorthand && type === 'AwaitBlock' && parser.eat('catch');
|
|
|
|
const await_block_catch_shorthand = !await_block_shorthand && type === 'AwaitBlock' && parser.eat('catch');
|
|
|
|
if (await_block_catch_shorthand) {
|
|
|
|
if (await_block_catch_shorthand) {
|
|
|
|
if (parser.match_regex(/\s*}/)) {
|
|
|
|
if (parser.match_regex(regex_whitespace_with_closing_curly_brace)) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
parser.require_whitespace();
|
|
|
|
parser.require_whitespace();
|
|
|
|
@ -350,7 +352,7 @@ export default function mustache(parser: Parser) {
|
|
|
|
let identifiers;
|
|
|
|
let identifiers;
|
|
|
|
|
|
|
|
|
|
|
|
// Implies {@debug} which indicates "debug all"
|
|
|
|
// Implies {@debug} which indicates "debug all"
|
|
|
|
if (parser.read(/\s*}/)) {
|
|
|
|
if (parser.read(regex_whitespace_with_closing_curly_brace)) {
|
|
|
|
identifiers = [];
|
|
|
|
identifiers = [];
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const expression = read_expression(parser);
|
|
|
|
const expression = read_expression(parser);
|
|
|
|
|