janja 2.4.0 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +143 -69
- package/dist/index.d.ts +81 -3
- package/dist/index.esm.js +131 -70
- package/dist/index.js +143 -69
- package/package.json +7 -7
package/dist/index.cjs.js
CHANGED
|
@@ -884,7 +884,6 @@ class CommentNode extends Traversal {
|
|
|
884
884
|
}
|
|
885
885
|
|
|
886
886
|
async function* parseComment({ val, loc, strip }) {
|
|
887
|
-
console.log(val);
|
|
888
887
|
yield 'NEXT';
|
|
889
888
|
yield new CommentNode(val, loc, strip);
|
|
890
889
|
}
|
|
@@ -1345,17 +1344,22 @@ const plugin$6 = {
|
|
|
1345
1344
|
parsers: parsers$6,
|
|
1346
1345
|
};
|
|
1347
1346
|
|
|
1348
|
-
async function compileMacro({ val
|
|
1347
|
+
async function compileMacro({ val, loc, body }, compiler) {
|
|
1349
1348
|
const { context } = compiler;
|
|
1350
|
-
const { elements } = right;
|
|
1351
1349
|
const expCompiler = new ExpCompiler();
|
|
1352
|
-
|
|
1353
|
-
.
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
.
|
|
1358
|
-
|
|
1350
|
+
if (val.type === 'ID') {
|
|
1351
|
+
compiler.pushRaw(loc, `${expCompiler.compile(val)}=()=>async(_c)=>{`, `const ${compiler.in()}={`, `...${context},`, '};');
|
|
1352
|
+
}
|
|
1353
|
+
else {
|
|
1354
|
+
const { left, right: { elements }, } = val;
|
|
1355
|
+
compiler.pushRaw(loc, `${expCompiler.compile(left)}=(${elements
|
|
1356
|
+
.map((el) => el.type === 'ASSIGN'
|
|
1357
|
+
? `${el.left.value}=${expCompiler.compile(el.right)}`
|
|
1358
|
+
: el.value)
|
|
1359
|
+
.join(',')})=>async(_c)=>{`, `const ${compiler.in()}={`, `...${context},`, elements
|
|
1360
|
+
.map((el) => (el.type === 'ASSIGN' ? el.left.value : el.value))
|
|
1361
|
+
.join(','), '};');
|
|
1362
|
+
}
|
|
1359
1363
|
await compiler.compileNodes(body);
|
|
1360
1364
|
compiler.out();
|
|
1361
1365
|
compiler.pushRaw(null, '};');
|
|
@@ -1449,7 +1453,36 @@ async function* parseMacro(token, parser) {
|
|
|
1449
1453
|
else {
|
|
1450
1454
|
throw parser.options.debug?.(new CompileError(`Unclosed "${token.name}"`, parser.template, token.loc));
|
|
1451
1455
|
}
|
|
1452
|
-
|
|
1456
|
+
const val = parser.parseExp(token.expression);
|
|
1457
|
+
if (val.type === 'ASSIGN') {
|
|
1458
|
+
if (val.left.type !== 'ID') {
|
|
1459
|
+
parser.options.debug?.(new CompileError('Invalid macro name', parser.template, token.loc));
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
if (val.right.type !== 'SEQ') {
|
|
1463
|
+
parser.options.debug?.(new CompileError('Invalid macro parameters', parser.template, token.loc));
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
else {
|
|
1467
|
+
for (const element of val.right.elements) {
|
|
1468
|
+
if (element.type === 'ASSIGN') {
|
|
1469
|
+
if (element.left.type !== 'ID') {
|
|
1470
|
+
parser.options.debug?.(new CompileError('Invalid parameter name', parser.template, token.loc));
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
else if (element.type !== 'ID') {
|
|
1475
|
+
parser.options.debug?.(new CompileError('Invalid macro parameter', parser.template, token.loc));
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
else if (val.type !== 'ID') {
|
|
1482
|
+
parser.options.debug?.(new CompileError('Invalid macro definition', parser.template, token.loc));
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
yield new MacroNode(val, body, token.loc, token.strip);
|
|
1453
1486
|
}
|
|
1454
1487
|
async function* parseCaller(token, parser) {
|
|
1455
1488
|
if (token.expression) {
|
|
@@ -1817,6 +1850,20 @@ const mergeOptions = (defaultOptions, options) => {
|
|
|
1817
1850
|
return mergedOptions;
|
|
1818
1851
|
};
|
|
1819
1852
|
|
|
1853
|
+
class ExpError extends SyntaxError {
|
|
1854
|
+
constructor(message, loc) {
|
|
1855
|
+
super(message);
|
|
1856
|
+
Object.defineProperty(this, "loc", {
|
|
1857
|
+
enumerable: true,
|
|
1858
|
+
configurable: true,
|
|
1859
|
+
writable: true,
|
|
1860
|
+
value: loc
|
|
1861
|
+
});
|
|
1862
|
+
this.name = 'ExpError';
|
|
1863
|
+
ExpError.captureStackTrace?.(this, this.constructor);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1820
1867
|
function updatePosition(str, pos) {
|
|
1821
1868
|
const newlines = (str.match(/\n/g) || []).length;
|
|
1822
1869
|
if (newlines > 0) {
|
|
@@ -1865,14 +1912,22 @@ const expTokenTypes = {
|
|
|
1865
1912
|
',': 'COMMA',
|
|
1866
1913
|
'.': 'DOT',
|
|
1867
1914
|
};
|
|
1915
|
+
function normalizeLitValue(value) {
|
|
1916
|
+
switch (value) {
|
|
1917
|
+
case 'true':
|
|
1918
|
+
return true;
|
|
1919
|
+
case 'false':
|
|
1920
|
+
return false;
|
|
1921
|
+
case 'null':
|
|
1922
|
+
return null;
|
|
1923
|
+
case 'undefined':
|
|
1924
|
+
return undefined;
|
|
1925
|
+
default:
|
|
1926
|
+
return value;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1868
1929
|
class ExpTokenizer {
|
|
1869
|
-
constructor(
|
|
1870
|
-
Object.defineProperty(this, "template", {
|
|
1871
|
-
enumerable: true,
|
|
1872
|
-
configurable: true,
|
|
1873
|
-
writable: true,
|
|
1874
|
-
value: template
|
|
1875
|
-
});
|
|
1930
|
+
constructor() {
|
|
1876
1931
|
Object.defineProperty(this, "val", {
|
|
1877
1932
|
enumerable: true,
|
|
1878
1933
|
configurable: true,
|
|
@@ -1927,19 +1982,19 @@ class ExpTokenizer {
|
|
|
1927
1982
|
this.readString(char);
|
|
1928
1983
|
continue;
|
|
1929
1984
|
}
|
|
1930
|
-
if (
|
|
1931
|
-
this.readNumber();
|
|
1985
|
+
if (isDigitStart(char)) {
|
|
1986
|
+
this.readNumber(char);
|
|
1932
1987
|
continue;
|
|
1933
1988
|
}
|
|
1934
|
-
if (
|
|
1935
|
-
this.readIdentifier();
|
|
1989
|
+
if (isIdentifierStart(char)) {
|
|
1990
|
+
this.readIdentifier(char);
|
|
1936
1991
|
continue;
|
|
1937
1992
|
}
|
|
1938
1993
|
if (isSymbol(char)) {
|
|
1939
1994
|
this.readSymbol(char);
|
|
1940
1995
|
continue;
|
|
1941
1996
|
}
|
|
1942
|
-
throw new
|
|
1997
|
+
throw new ExpError(`Unexpect "${char}"`, {
|
|
1943
1998
|
start: { line: this.line, column: this.column },
|
|
1944
1999
|
end: { line: this.line, column: this.column + 1 },
|
|
1945
2000
|
});
|
|
@@ -1982,10 +2037,11 @@ class ExpTokenizer {
|
|
|
1982
2037
|
raw: `${quoteChar}${value}${quoteChar}`,
|
|
1983
2038
|
});
|
|
1984
2039
|
}
|
|
1985
|
-
readNumber() {
|
|
1986
|
-
let value =
|
|
2040
|
+
readNumber(startChar) {
|
|
2041
|
+
let value = startChar;
|
|
1987
2042
|
let hasDot = false;
|
|
1988
2043
|
const start = { line: this.line, column: this.column };
|
|
2044
|
+
this.index++;
|
|
1989
2045
|
while (this.index < this.val.length) {
|
|
1990
2046
|
const char = this.val[this.index];
|
|
1991
2047
|
if (isDigit(char)) {
|
|
@@ -2010,12 +2066,13 @@ class ExpTokenizer {
|
|
|
2010
2066
|
raw: value,
|
|
2011
2067
|
});
|
|
2012
2068
|
}
|
|
2013
|
-
readIdentifier() {
|
|
2014
|
-
let value =
|
|
2069
|
+
readIdentifier(startChar) {
|
|
2070
|
+
let value = startChar;
|
|
2015
2071
|
const start = { line: this.line, column: this.column };
|
|
2072
|
+
this.index++;
|
|
2016
2073
|
while (this.index < this.val.length) {
|
|
2017
2074
|
const char = this.val[this.index];
|
|
2018
|
-
if (
|
|
2075
|
+
if (isIdentifier(char)) {
|
|
2019
2076
|
value += char;
|
|
2020
2077
|
this.index++;
|
|
2021
2078
|
continue;
|
|
@@ -2027,17 +2084,7 @@ class ExpTokenizer {
|
|
|
2027
2084
|
: 'ID';
|
|
2028
2085
|
this.tokens.push({
|
|
2029
2086
|
type,
|
|
2030
|
-
value: type === 'LIT'
|
|
2031
|
-
? value === 'true'
|
|
2032
|
-
? true
|
|
2033
|
-
: value === 'false'
|
|
2034
|
-
? false
|
|
2035
|
-
: value === 'null'
|
|
2036
|
-
? null
|
|
2037
|
-
: value === 'undefined'
|
|
2038
|
-
? undefined
|
|
2039
|
-
: value
|
|
2040
|
-
: value,
|
|
2087
|
+
value: type === 'LIT' ? normalizeLitValue(value) : value,
|
|
2041
2088
|
loc: {
|
|
2042
2089
|
start,
|
|
2043
2090
|
end: updatePosition(value, this),
|
|
@@ -2065,13 +2112,16 @@ function isWhitespace(char) {
|
|
|
2065
2112
|
function isSymbol(char) {
|
|
2066
2113
|
return /[+\-*/%|=(),.]/.test(char);
|
|
2067
2114
|
}
|
|
2068
|
-
function
|
|
2115
|
+
function isDigitStart(char) {
|
|
2069
2116
|
return /[-\d]/.test(char);
|
|
2070
2117
|
}
|
|
2071
|
-
function
|
|
2118
|
+
function isDigit(char) {
|
|
2119
|
+
return /\d/.test(char);
|
|
2120
|
+
}
|
|
2121
|
+
function isIdentifierStart(char) {
|
|
2072
2122
|
return /[a-z_$]/i.test(char);
|
|
2073
2123
|
}
|
|
2074
|
-
function
|
|
2124
|
+
function isIdentifier(char) {
|
|
2075
2125
|
return /[\w$]/.test(char);
|
|
2076
2126
|
}
|
|
2077
2127
|
|
|
@@ -2106,13 +2156,7 @@ const expTokenPrecedences = {
|
|
|
2106
2156
|
LIT: 90,
|
|
2107
2157
|
};
|
|
2108
2158
|
class ExpParser {
|
|
2109
|
-
constructor(
|
|
2110
|
-
Object.defineProperty(this, "template", {
|
|
2111
|
-
enumerable: true,
|
|
2112
|
-
configurable: true,
|
|
2113
|
-
writable: true,
|
|
2114
|
-
value: template
|
|
2115
|
-
});
|
|
2159
|
+
constructor() {
|
|
2116
2160
|
Object.defineProperty(this, "val", {
|
|
2117
2161
|
enumerable: true,
|
|
2118
2162
|
configurable: true,
|
|
@@ -2149,7 +2193,7 @@ class ExpParser {
|
|
|
2149
2193
|
this.index = 0;
|
|
2150
2194
|
this.line = loc.start.line;
|
|
2151
2195
|
this.column = loc.start.column;
|
|
2152
|
-
this.tokens = new ExpTokenizer(
|
|
2196
|
+
this.tokens = new ExpTokenizer().tokenize(val, loc);
|
|
2153
2197
|
return this.val ? this.parseExp() : null;
|
|
2154
2198
|
}
|
|
2155
2199
|
parseExp(checker) {
|
|
@@ -2169,12 +2213,12 @@ class ExpParser {
|
|
|
2169
2213
|
}
|
|
2170
2214
|
if (token.type === 'LP') {
|
|
2171
2215
|
if (!this.peek()) {
|
|
2172
|
-
throw new
|
|
2216
|
+
throw new ExpError('Unexpected end of expression', token.loc);
|
|
2173
2217
|
}
|
|
2174
2218
|
const elements = this.parseSequence();
|
|
2175
2219
|
const rp = this.consume('RP');
|
|
2176
2220
|
if (!rp) {
|
|
2177
|
-
throw new
|
|
2221
|
+
throw new ExpError('Expected "RP" after "LP"', token.loc);
|
|
2178
2222
|
}
|
|
2179
2223
|
left = {
|
|
2180
2224
|
...token,
|
|
@@ -2189,7 +2233,7 @@ class ExpParser {
|
|
|
2189
2233
|
}
|
|
2190
2234
|
if (token.type === 'NOT') {
|
|
2191
2235
|
if (!this.peek()) {
|
|
2192
|
-
throw new
|
|
2236
|
+
throw new ExpError('Unexpected end of expression', token.loc);
|
|
2193
2237
|
}
|
|
2194
2238
|
left = {
|
|
2195
2239
|
...token,
|
|
@@ -2211,7 +2255,7 @@ class ExpParser {
|
|
|
2211
2255
|
if (lp) {
|
|
2212
2256
|
left.args = this.parseSequence();
|
|
2213
2257
|
if (!this.consume('RP')) {
|
|
2214
|
-
throw new
|
|
2258
|
+
throw new ExpError('Expected "RP" after "LP"', lp.loc);
|
|
2215
2259
|
}
|
|
2216
2260
|
continue;
|
|
2217
2261
|
}
|
|
@@ -2227,7 +2271,7 @@ class ExpParser {
|
|
|
2227
2271
|
if (token.type === 'IF') {
|
|
2228
2272
|
const test = this.parseExp((t) => t.type === 'ELSE' ? 'BACK' : isHigher(token, t) ? 'BACK' : undefined);
|
|
2229
2273
|
if (!test) {
|
|
2230
|
-
throw new
|
|
2274
|
+
throw new ExpError('Expected test expression', token.loc);
|
|
2231
2275
|
}
|
|
2232
2276
|
left = {
|
|
2233
2277
|
...token,
|
|
@@ -2238,7 +2282,7 @@ class ExpParser {
|
|
|
2238
2282
|
if (this.consume('ELSE')) {
|
|
2239
2283
|
const alternative = this.parseExp((t) => isHigher(token, t) ? 'BACK' : undefined);
|
|
2240
2284
|
if (!alternative) {
|
|
2241
|
-
throw new
|
|
2285
|
+
throw new ExpError('Expected alternative expression', token.loc);
|
|
2242
2286
|
}
|
|
2243
2287
|
left.alternative = alternative;
|
|
2244
2288
|
}
|
|
@@ -2263,11 +2307,21 @@ class ExpParser {
|
|
|
2263
2307
|
token.type === 'MOD' ||
|
|
2264
2308
|
token.type === 'ASSIGN') {
|
|
2265
2309
|
if (!left) {
|
|
2266
|
-
throw new
|
|
2310
|
+
throw new ExpError(`No left operand for "${token.type}"`, token.loc);
|
|
2311
|
+
}
|
|
2312
|
+
if (token.type === 'ASSIGN') {
|
|
2313
|
+
if (left.type === 'SEQ') {
|
|
2314
|
+
if (left.elements.some((el) => el.type !== 'ID')) {
|
|
2315
|
+
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
else if (left.type !== 'ID') {
|
|
2319
|
+
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
2320
|
+
}
|
|
2267
2321
|
}
|
|
2268
2322
|
const right = this.parseExp((t) => isHigher(token, t) ? 'BACK' : undefined);
|
|
2269
2323
|
if (!right) {
|
|
2270
|
-
throw new
|
|
2324
|
+
throw new ExpError(`No right operand for "${token.type}"`, token.loc);
|
|
2271
2325
|
}
|
|
2272
2326
|
left = {
|
|
2273
2327
|
...token,
|
|
@@ -2279,10 +2333,10 @@ class ExpParser {
|
|
|
2279
2333
|
}
|
|
2280
2334
|
if (token.type === 'PIPE') {
|
|
2281
2335
|
if (!left) {
|
|
2282
|
-
throw new
|
|
2336
|
+
throw new ExpError(`No left operand for "${token.type}"`, token.loc);
|
|
2283
2337
|
}
|
|
2284
2338
|
if (!this.match('ID')) {
|
|
2285
|
-
throw new
|
|
2339
|
+
throw new ExpError('Expected "ID" after "PIPE"', token.loc);
|
|
2286
2340
|
}
|
|
2287
2341
|
left = {
|
|
2288
2342
|
...token,
|
|
@@ -2306,10 +2360,10 @@ class ExpParser {
|
|
|
2306
2360
|
}
|
|
2307
2361
|
const token = this.next();
|
|
2308
2362
|
if (!token) {
|
|
2309
|
-
throw new
|
|
2363
|
+
throw new ExpError('Expected "ID" after "DOT"', dot.loc);
|
|
2310
2364
|
}
|
|
2311
2365
|
if (token.type !== 'ID') {
|
|
2312
|
-
throw new
|
|
2366
|
+
throw new ExpError('Expected "ID" after "DOT"', dot.loc);
|
|
2313
2367
|
}
|
|
2314
2368
|
ids.push({
|
|
2315
2369
|
...token,
|
|
@@ -2346,7 +2400,7 @@ class ExpParser {
|
|
|
2346
2400
|
right.args = args;
|
|
2347
2401
|
}
|
|
2348
2402
|
if (!this.consume('RP')) {
|
|
2349
|
-
throw new
|
|
2403
|
+
throw new ExpError('Expected "RP" after "LP"', lp.loc);
|
|
2350
2404
|
}
|
|
2351
2405
|
}
|
|
2352
2406
|
return right;
|
|
@@ -2578,7 +2632,7 @@ class Parser extends Tokenizer {
|
|
|
2578
2632
|
this.tokenize(template);
|
|
2579
2633
|
const start = this.tokens[0]?.loc.start ?? { line: 1, column: 1 };
|
|
2580
2634
|
const end = this.tokens.at(-1)?.loc.end ?? { line: 1, column: 1 };
|
|
2581
|
-
this.expParser = new ExpParser(
|
|
2635
|
+
this.expParser = new ExpParser();
|
|
2582
2636
|
this.cursor = 0;
|
|
2583
2637
|
return new RootNode(await this.parseUntil(), { start, end });
|
|
2584
2638
|
}
|
|
@@ -2627,7 +2681,14 @@ class Parser extends Tokenizer {
|
|
|
2627
2681
|
return nodes;
|
|
2628
2682
|
}
|
|
2629
2683
|
parseExp({ val, loc }) {
|
|
2630
|
-
|
|
2684
|
+
try {
|
|
2685
|
+
return this.expParser.parse(val, loc);
|
|
2686
|
+
}
|
|
2687
|
+
catch (error) {
|
|
2688
|
+
this.options.debug(error.loc
|
|
2689
|
+
? new CompileError(error.message, this.template, error.loc)
|
|
2690
|
+
: error);
|
|
2691
|
+
}
|
|
2631
2692
|
}
|
|
2632
2693
|
peek() {
|
|
2633
2694
|
return this.tokens.at(this.cursor) ?? null;
|
|
@@ -2639,7 +2700,7 @@ class Parser extends Tokenizer {
|
|
|
2639
2700
|
return names.includes(token?.name);
|
|
2640
2701
|
}
|
|
2641
2702
|
emitExpErr({ name, loc }, required = true) {
|
|
2642
|
-
this.options.debug
|
|
2703
|
+
this.options.debug(new CompileError(required
|
|
2643
2704
|
? `"${name}" requires expression`
|
|
2644
2705
|
: `"${name}" should not have expression`, this.template, loc));
|
|
2645
2706
|
}
|
|
@@ -2738,7 +2799,7 @@ class Compiler extends Context {
|
|
|
2738
2799
|
template = await this.options.loader(path);
|
|
2739
2800
|
}
|
|
2740
2801
|
catch {
|
|
2741
|
-
this.options.debug
|
|
2802
|
+
this.options.debug(new CompileError(`Failed to load template from "${path}"`, this.template, node.loc));
|
|
2742
2803
|
return;
|
|
2743
2804
|
}
|
|
2744
2805
|
if (template) {
|
|
@@ -2799,7 +2860,7 @@ class Compiler extends Context {
|
|
|
2799
2860
|
this.partials.set(path, code);
|
|
2800
2861
|
}
|
|
2801
2862
|
catch {
|
|
2802
|
-
this.options.debug
|
|
2863
|
+
this.options.debug(new CompileError('Failed to compile template', this.template, node.loc));
|
|
2803
2864
|
}
|
|
2804
2865
|
}
|
|
2805
2866
|
}
|
|
@@ -2819,7 +2880,7 @@ class RenderError extends CompileError {
|
|
|
2819
2880
|
writable: true,
|
|
2820
2881
|
value: getLoc
|
|
2821
2882
|
});
|
|
2822
|
-
this.name = '
|
|
2883
|
+
this.name = 'RenderError';
|
|
2823
2884
|
RenderError.captureStackTrace?.(this, this.constructor);
|
|
2824
2885
|
}
|
|
2825
2886
|
get details() {
|
|
@@ -2881,6 +2942,19 @@ async function renderFile(filepath, data, options) {
|
|
|
2881
2942
|
return new Renderer(options).renderFile(filepath, data);
|
|
2882
2943
|
}
|
|
2883
2944
|
|
|
2945
|
+
exports.CompileError = CompileError;
|
|
2946
|
+
exports.Compiler = Compiler;
|
|
2947
|
+
exports.ExpCompiler = ExpCompiler;
|
|
2948
|
+
exports.ExpError = ExpError;
|
|
2949
|
+
exports.ExpParser = ExpParser;
|
|
2950
|
+
exports.ExpTokenizer = ExpTokenizer;
|
|
2951
|
+
exports.Parser = Parser;
|
|
2952
|
+
exports.RenderError = RenderError;
|
|
2884
2953
|
exports.Renderer = Renderer;
|
|
2954
|
+
exports.RootNode = RootNode;
|
|
2955
|
+
exports.Safe = Safe;
|
|
2956
|
+
exports.Tokenizer = Tokenizer;
|
|
2957
|
+
exports.Traversal = Traversal;
|
|
2958
|
+
exports.expTokenTypes = expTokenTypes;
|
|
2885
2959
|
exports.render = render;
|
|
2886
2960
|
exports.renderFile = renderFile;
|
package/dist/index.d.ts
CHANGED
|
@@ -163,7 +163,7 @@ declare class Parser extends Tokenizer {
|
|
|
163
163
|
protected cursor: number;
|
|
164
164
|
parse(template: string): Promise<RootNode>;
|
|
165
165
|
parseUntil(names?: string[]): Promise<SyntaxNode[]>;
|
|
166
|
-
parseExp<T extends Exp = Exp>({ val, loc }: DirectiveExpression): T;
|
|
166
|
+
parseExp<T extends Exp = Exp>({ val, loc }: DirectiveExpression): T | undefined;
|
|
167
167
|
peek(): Token | null;
|
|
168
168
|
private advance;
|
|
169
169
|
match(names: string[], token?: Token | null): boolean;
|
|
@@ -255,6 +255,20 @@ interface RendererOptions extends CompilerOptions {
|
|
|
255
255
|
autoEscape?: boolean;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
declare class CompileError extends SyntaxError {
|
|
259
|
+
protected src: string;
|
|
260
|
+
protected loc?: Loc | undefined;
|
|
261
|
+
constructor(message: string, src: string, loc?: Loc | undefined);
|
|
262
|
+
get details(): string;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
declare class RenderError extends CompileError {
|
|
266
|
+
protected src: string;
|
|
267
|
+
protected getLoc: () => Loc;
|
|
268
|
+
constructor(message: string, src: string, getLoc: () => Loc);
|
|
269
|
+
get details(): string;
|
|
270
|
+
}
|
|
271
|
+
|
|
258
272
|
declare class Renderer {
|
|
259
273
|
protected options: Required<RendererOptions>;
|
|
260
274
|
constructor(options?: RendererOptions);
|
|
@@ -262,8 +276,72 @@ declare class Renderer {
|
|
|
262
276
|
renderFile(filepath: string, globals: ObjectType): Promise<string>;
|
|
263
277
|
}
|
|
264
278
|
|
|
279
|
+
declare class Safe extends String {
|
|
280
|
+
constructor(value: unknown);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
declare class ExpCompiler {
|
|
284
|
+
private context;
|
|
285
|
+
private filters;
|
|
286
|
+
compile(expression: Exp | null, context?: string, filters?: string): string;
|
|
287
|
+
private compileExp;
|
|
288
|
+
private compileNot;
|
|
289
|
+
private compileId;
|
|
290
|
+
private compileLit;
|
|
291
|
+
private compileSeq;
|
|
292
|
+
private compilePipe;
|
|
293
|
+
private compileAssign;
|
|
294
|
+
private compileIs;
|
|
295
|
+
private compileBinary;
|
|
296
|
+
private compileTernary;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
declare class ExpError extends SyntaxError {
|
|
300
|
+
loc: Loc;
|
|
301
|
+
constructor(message: string, loc: Loc);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
interface ExpToken<T = ExpTokenType> {
|
|
305
|
+
type: T;
|
|
306
|
+
value: Primitive;
|
|
307
|
+
loc: Loc;
|
|
308
|
+
raw?: string;
|
|
309
|
+
}
|
|
310
|
+
declare const expTokenTypes: Record<string, ExpTokenType>;
|
|
311
|
+
declare class ExpTokenizer implements Pos {
|
|
312
|
+
val: string;
|
|
313
|
+
tokens: ExpToken[];
|
|
314
|
+
index: number;
|
|
315
|
+
line: number;
|
|
316
|
+
column: number;
|
|
317
|
+
tokenize(val: string, loc: Loc): ExpToken<ExpTokenType>[];
|
|
318
|
+
private readString;
|
|
319
|
+
private readNumber;
|
|
320
|
+
private readIdentifier;
|
|
321
|
+
private readSymbol;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
type Checker = (token: ExpToken) => 'BACK' | 'BREAK' | undefined;
|
|
325
|
+
declare class ExpParser implements Pos {
|
|
326
|
+
val: string;
|
|
327
|
+
tokens: ExpToken[];
|
|
328
|
+
index: number;
|
|
329
|
+
line: number;
|
|
330
|
+
column: number;
|
|
331
|
+
parse(val: string, loc: Loc): Exp | null;
|
|
332
|
+
private parseExp;
|
|
333
|
+
private parsePath;
|
|
334
|
+
private parseSequence;
|
|
335
|
+
private parsePipe;
|
|
336
|
+
private next;
|
|
337
|
+
private back;
|
|
338
|
+
private peek;
|
|
339
|
+
private match;
|
|
340
|
+
private consume;
|
|
341
|
+
}
|
|
342
|
+
|
|
265
343
|
declare function render(template: string, data: ObjectType, options?: RendererOptions): Promise<string>;
|
|
266
344
|
declare function renderFile(filepath: string, data: ObjectType, options?: RendererOptions): Promise<string>;
|
|
267
345
|
|
|
268
|
-
export { Renderer, TokenType, render, renderFile };
|
|
269
|
-
export type { BinaryExp, BinaryExpTokenType, BinaryExpType, CommentToken, CompilerFn, CompilerMap, DirectiveExpression, DirectiveToken, Exp, ExpBase, ExpTokenType, ExpType, Filters, IdExp, IfExp, LitExp, Loc, MaybePromise, NotExp, ObjectType, OutputToken, ParserFn, ParserMap, Plugin, Pos, Primitive, Script, SeqExp, Strip, TernaryExpTokenType, TernaryExpType, TextToken, Token, TokenBase, UnaryExpTokenType, UnaryExpType };
|
|
346
|
+
export { CompileError, Compiler, ExpCompiler, ExpError, ExpParser, ExpTokenizer, Parser, RenderError, Renderer, RootNode, Safe, TokenType, Tokenizer, Traversal, expTokenTypes, render, renderFile };
|
|
347
|
+
export type { BinaryExp, BinaryExpTokenType, BinaryExpType, Checker, CommentToken, CompilerFn, CompilerMap, DirectiveExpression, DirectiveToken, Exp, ExpBase, ExpToken, ExpTokenType, ExpType, Filters, IdExp, IfExp, LitExp, Loc, MaybePromise, NotExp, ObjectType, OutputToken, ParserFn, ParserMap, Plugin, Pos, Primitive, Script, SeqExp, Strip, SyntaxNode, TernaryExpTokenType, TernaryExpType, TextToken, Token, TokenBase, UnaryExpTokenType, UnaryExpType };
|