|
|
@ -1,9 +1,8 @@
|
|
|
|
import read_context from '../read/context.js';
|
|
|
|
import read_pattern from '../read/context.js';
|
|
|
|
import read_expression from '../read/expression.js';
|
|
|
|
import read_expression from '../read/expression.js';
|
|
|
|
import { error } from '../../../errors.js';
|
|
|
|
import { error } from '../../../errors.js';
|
|
|
|
import { create_fragment } from '../utils/create.js';
|
|
|
|
import { create_fragment } from '../utils/create.js';
|
|
|
|
import { walk } from 'zimmerframe';
|
|
|
|
import { walk } from 'zimmerframe';
|
|
|
|
import { parse } from '../acorn.js';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const regex_whitespace_with_closing_curly_brace = /^\s*}/;
|
|
|
|
const regex_whitespace_with_closing_curly_brace = /^\s*}/;
|
|
|
|
|
|
|
|
|
|
|
@ -24,8 +23,8 @@ export default function mustache(parser) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').ExpressionTag>>} */
|
|
|
|
/** @type {import('#compiler').ExpressionTag} */ ({
|
|
|
|
parser.append({
|
|
|
|
type: 'ExpressionTag',
|
|
|
|
type: 'ExpressionTag',
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: parser.index,
|
|
|
|
end: parser.index,
|
|
|
@ -34,8 +33,7 @@ export default function mustache(parser) {
|
|
|
|
contains_call_expression: false,
|
|
|
|
contains_call_expression: false,
|
|
|
|
dynamic: false
|
|
|
|
dynamic: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @param {import('../index.js').Parser} parser */
|
|
|
|
/** @param {import('../index.js').Parser} parser */
|
|
|
@ -45,8 +43,8 @@ function open(parser) {
|
|
|
|
if (parser.eat('if')) {
|
|
|
|
if (parser.eat('if')) {
|
|
|
|
parser.require_whitespace();
|
|
|
|
parser.require_whitespace();
|
|
|
|
|
|
|
|
|
|
|
|
const block = parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').IfBlock>>} */
|
|
|
|
/** @type {import('#compiler').IfBlock} */ ({
|
|
|
|
const block = parser.append({
|
|
|
|
type: 'IfBlock',
|
|
|
|
type: 'IfBlock',
|
|
|
|
elseif: false,
|
|
|
|
elseif: false,
|
|
|
|
start,
|
|
|
|
start,
|
|
|
@ -54,8 +52,7 @@ function open(parser) {
|
|
|
|
test: read_expression(parser),
|
|
|
|
test: read_expression(parser),
|
|
|
|
consequent: create_fragment(),
|
|
|
|
consequent: create_fragment(),
|
|
|
|
alternate: null
|
|
|
|
alternate: null
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
@ -139,7 +136,7 @@ function open(parser) {
|
|
|
|
parser.eat('as', true);
|
|
|
|
parser.eat('as', true);
|
|
|
|
parser.require_whitespace();
|
|
|
|
parser.require_whitespace();
|
|
|
|
|
|
|
|
|
|
|
|
const context = read_context(parser);
|
|
|
|
const context = read_pattern(parser);
|
|
|
|
|
|
|
|
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
|
|
|
|
|
|
|
@ -167,8 +164,8 @@ function open(parser) {
|
|
|
|
|
|
|
|
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
const block = parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').EachBlock>>} */
|
|
|
|
/** @type {Omit<import('#compiler').EachBlock, 'parent'>} */ ({
|
|
|
|
const block = parser.append({
|
|
|
|
type: 'EachBlock',
|
|
|
|
type: 'EachBlock',
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: -1,
|
|
|
|
end: -1,
|
|
|
@ -178,8 +175,7 @@ function open(parser) {
|
|
|
|
index,
|
|
|
|
index,
|
|
|
|
key,
|
|
|
|
key,
|
|
|
|
metadata: /** @type {any} */ (null) // filled in later
|
|
|
|
metadata: /** @type {any} */ (null) // filled in later
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.stack.push(block);
|
|
|
|
parser.stack.push(block);
|
|
|
|
parser.fragments.push(block.body);
|
|
|
|
parser.fragments.push(block.body);
|
|
|
@ -192,8 +188,8 @@ function open(parser) {
|
|
|
|
const expression = read_expression(parser);
|
|
|
|
const expression = read_expression(parser);
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
|
|
|
|
|
|
|
|
const block = parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').AwaitBlock>>} */
|
|
|
|
/** @type {import('#compiler').AwaitBlock} */ ({
|
|
|
|
const block = parser.append({
|
|
|
|
type: 'AwaitBlock',
|
|
|
|
type: 'AwaitBlock',
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: -1,
|
|
|
|
end: -1,
|
|
|
@ -203,15 +199,14 @@ function open(parser) {
|
|
|
|
pending: null,
|
|
|
|
pending: null,
|
|
|
|
then: null,
|
|
|
|
then: null,
|
|
|
|
catch: null
|
|
|
|
catch: null
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parser.eat('then')) {
|
|
|
|
if (parser.eat('then')) {
|
|
|
|
if (parser.match_regex(regex_whitespace_with_closing_curly_brace)) {
|
|
|
|
if (parser.match_regex(regex_whitespace_with_closing_curly_brace)) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
parser.require_whitespace();
|
|
|
|
parser.require_whitespace();
|
|
|
|
block.value = read_context(parser);
|
|
|
|
block.value = read_pattern(parser);
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -222,7 +217,7 @@ function open(parser) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
parser.require_whitespace();
|
|
|
|
parser.require_whitespace();
|
|
|
|
block.error = read_context(parser);
|
|
|
|
block.error = read_pattern(parser);
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -247,15 +242,14 @@ function open(parser) {
|
|
|
|
|
|
|
|
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
const block = parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').KeyBlock>>} */
|
|
|
|
/** @type {import('#compiler').KeyBlock} */ ({
|
|
|
|
const block = parser.append({
|
|
|
|
type: 'KeyBlock',
|
|
|
|
type: 'KeyBlock',
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: -1,
|
|
|
|
end: -1,
|
|
|
|
expression,
|
|
|
|
expression,
|
|
|
|
fragment: create_fragment()
|
|
|
|
fragment: create_fragment()
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.stack.push(block);
|
|
|
|
parser.stack.push(block);
|
|
|
|
parser.fragments.push(block.fragment);
|
|
|
|
parser.fragments.push(block.fragment);
|
|
|
@ -270,6 +264,10 @@ function open(parser) {
|
|
|
|
const name = parser.read_identifier();
|
|
|
|
const name = parser.read_identifier();
|
|
|
|
const name_end = parser.index;
|
|
|
|
const name_end = parser.index;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (name === null) {
|
|
|
|
|
|
|
|
error(parser.index, 'expected-identifier');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parser.eat('(', true);
|
|
|
|
parser.eat('(', true);
|
|
|
|
|
|
|
|
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
@ -278,7 +276,7 @@ function open(parser) {
|
|
|
|
const parameters = [];
|
|
|
|
const parameters = [];
|
|
|
|
|
|
|
|
|
|
|
|
while (!parser.match(')')) {
|
|
|
|
while (!parser.match(')')) {
|
|
|
|
let pattern = read_context(parser);
|
|
|
|
let pattern = read_pattern(parser);
|
|
|
|
|
|
|
|
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
if (parser.eat('=')) {
|
|
|
|
if (parser.eat('=')) {
|
|
|
@ -301,9 +299,8 @@ function open(parser) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
const block = parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').SnippetBlock>>} */
|
|
|
|
/** @type {Omit<import('#compiler').SnippetBlock, 'parent'>} */
|
|
|
|
const block = parser.append({
|
|
|
|
({
|
|
|
|
|
|
|
|
type: 'SnippetBlock',
|
|
|
|
type: 'SnippetBlock',
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: -1,
|
|
|
|
end: -1,
|
|
|
@ -315,8 +312,7 @@ function open(parser) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
parameters,
|
|
|
|
parameters,
|
|
|
|
body: create_fragment()
|
|
|
|
body: create_fragment()
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.stack.push(block);
|
|
|
|
parser.stack.push(block);
|
|
|
|
parser.fragments.push(block.body);
|
|
|
|
parser.fragments.push(block.body);
|
|
|
@ -353,8 +349,8 @@ function next(parser) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
const child = parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').IfBlock>>} */
|
|
|
|
/** @type {import('#compiler').IfBlock} */ ({
|
|
|
|
const child = parser.append({
|
|
|
|
start: parser.index,
|
|
|
|
start: parser.index,
|
|
|
|
end: -1,
|
|
|
|
end: -1,
|
|
|
|
type: 'IfBlock',
|
|
|
|
type: 'IfBlock',
|
|
|
@ -362,8 +358,7 @@ function next(parser) {
|
|
|
|
test: expression,
|
|
|
|
test: expression,
|
|
|
|
consequent: create_fragment(),
|
|
|
|
consequent: create_fragment(),
|
|
|
|
alternate: null
|
|
|
|
alternate: null
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parser.stack.push(child);
|
|
|
|
parser.stack.push(child);
|
|
|
|
parser.fragments.pop();
|
|
|
|
parser.fragments.pop();
|
|
|
@ -399,7 +394,7 @@ function next(parser) {
|
|
|
|
|
|
|
|
|
|
|
|
if (!parser.eat('}')) {
|
|
|
|
if (!parser.eat('}')) {
|
|
|
|
parser.require_whitespace();
|
|
|
|
parser.require_whitespace();
|
|
|
|
block.value = read_context(parser);
|
|
|
|
block.value = read_pattern(parser);
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -418,7 +413,7 @@ function next(parser) {
|
|
|
|
|
|
|
|
|
|
|
|
if (!parser.eat('}')) {
|
|
|
|
if (!parser.eat('}')) {
|
|
|
|
parser.require_whitespace();
|
|
|
|
parser.require_whitespace();
|
|
|
|
block.error = read_context(parser);
|
|
|
|
block.error = read_pattern(parser);
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -498,14 +493,13 @@ function special(parser) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').HtmlTag>>} */
|
|
|
|
/** @type {import('#compiler').HtmlTag} */ ({
|
|
|
|
parser.append({
|
|
|
|
type: 'HtmlTag',
|
|
|
|
type: 'HtmlTag',
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: parser.index,
|
|
|
|
end: parser.index,
|
|
|
|
expression
|
|
|
|
expression
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -537,14 +531,13 @@ function special(parser) {
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').DebugTag>>} */
|
|
|
|
/** @type {import('#compiler').DebugTag} */ ({
|
|
|
|
parser.append({
|
|
|
|
type: 'DebugTag',
|
|
|
|
type: 'DebugTag',
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: parser.index,
|
|
|
|
end: parser.index,
|
|
|
|
identifiers
|
|
|
|
identifiers
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -552,7 +545,7 @@ function special(parser) {
|
|
|
|
if (parser.eat('const')) {
|
|
|
|
if (parser.eat('const')) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
|
|
|
|
|
|
|
|
const id = read_context(parser);
|
|
|
|
const id = read_pattern(parser);
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
|
|
|
|
|
|
|
|
parser.eat('=', true);
|
|
|
|
parser.eat('=', true);
|
|
|
@ -563,8 +556,8 @@ function special(parser) {
|
|
|
|
|
|
|
|
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').ConstTag>>} */
|
|
|
|
/** @type {import('#compiler').ConstTag} */ ({
|
|
|
|
parser.append({
|
|
|
|
type: 'ConstTag',
|
|
|
|
type: 'ConstTag',
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: parser.index,
|
|
|
|
end: parser.index,
|
|
|
@ -575,8 +568,7 @@ function special(parser) {
|
|
|
|
start: start + 1,
|
|
|
|
start: start + 1,
|
|
|
|
end: parser.index - 1
|
|
|
|
end: parser.index - 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (parser.eat('render')) {
|
|
|
|
if (parser.eat('render')) {
|
|
|
@ -592,14 +584,13 @@ function special(parser) {
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.allow_whitespace();
|
|
|
|
parser.eat('}', true);
|
|
|
|
parser.eat('}', true);
|
|
|
|
|
|
|
|
|
|
|
|
parser.append(
|
|
|
|
/** @type {ReturnType<typeof parser.append<import('#compiler').RenderTag>>} */
|
|
|
|
/** @type {import('#compiler').RenderTag} */ ({
|
|
|
|
parser.append({
|
|
|
|
type: 'RenderTag',
|
|
|
|
type: 'RenderTag',
|
|
|
|
start,
|
|
|
|
start,
|
|
|
|
end: parser.index,
|
|
|
|
end: parser.index,
|
|
|
|
expression: expression.callee,
|
|
|
|
expression: expression.callee,
|
|
|
|
arguments: expression.arguments
|
|
|
|
arguments: expression.arguments
|
|
|
|
})
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|