janja 2.1.3 → 2.2.0

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 CHANGED
@@ -2602,8 +2602,8 @@ class Parser extends Tokenizer {
2602
2602
  }
2603
2603
  let parser = this.options.parsers[token.name?.toLowerCase() ??
2604
2604
  token.type?.toLowerCase()];
2605
- if (parser === 'unexpected') {
2606
- parser = this.options.parsers['unexpected'];
2605
+ if (typeof parser === 'string') {
2606
+ parser = this.options.parsers[parser];
2607
2607
  }
2608
2608
  if (!parser) {
2609
2609
  parser = this.options.parsers['unknown'];
@@ -2780,7 +2780,13 @@ class Compiler extends Context {
2780
2780
  await this.compileNodes(node.body);
2781
2781
  return;
2782
2782
  }
2783
- const compiler = this.options.compilers[node.type] || this.options.compilers['UNKNOWN'];
2783
+ let compiler = this.options.compilers[node.type];
2784
+ if (typeof compiler === 'string') {
2785
+ compiler = this.options.compilers[compiler];
2786
+ }
2787
+ if (!compiler) {
2788
+ compiler = this.options.compilers['UNKNOWN'];
2789
+ }
2784
2790
  await compiler?.(node, this);
2785
2791
  }
2786
2792
  async compileNodes(nodes) {
package/dist/index.d.ts CHANGED
@@ -226,9 +226,9 @@ interface Plugin {
226
226
  compilers?: CompilerMap;
227
227
  }
228
228
  type ParserFn<T extends Token = any, U extends SyntaxNode = any> = (token: T, parser: Parser) => AsyncGenerator<U | 'NEXT' | void>;
229
- type ParserMap = Record<string, 'unexpected' | ParserFn>;
229
+ type ParserMap = Record<string, string | ParserFn>;
230
230
  type CompilerFn<T extends SyntaxNode = any> = (node: T, compiler: Compiler) => MaybePromise<void>;
231
- type CompilerMap = Record<string, CompilerFn>;
231
+ type CompilerMap = Record<string, string | CompilerFn>;
232
232
 
233
233
  interface BaseOptions {
234
234
  debug?: (error: Error) => any;
package/dist/index.esm.js CHANGED
@@ -2600,8 +2600,8 @@ class Parser extends Tokenizer {
2600
2600
  }
2601
2601
  let parser = this.options.parsers[token.name?.toLowerCase() ??
2602
2602
  token.type?.toLowerCase()];
2603
- if (parser === 'unexpected') {
2604
- parser = this.options.parsers['unexpected'];
2603
+ if (typeof parser === 'string') {
2604
+ parser = this.options.parsers[parser];
2605
2605
  }
2606
2606
  if (!parser) {
2607
2607
  parser = this.options.parsers['unknown'];
@@ -2778,7 +2778,13 @@ class Compiler extends Context {
2778
2778
  await this.compileNodes(node.body);
2779
2779
  return;
2780
2780
  }
2781
- const compiler = this.options.compilers[node.type] || this.options.compilers['UNKNOWN'];
2781
+ let compiler = this.options.compilers[node.type];
2782
+ if (typeof compiler === 'string') {
2783
+ compiler = this.options.compilers[compiler];
2784
+ }
2785
+ if (!compiler) {
2786
+ compiler = this.options.compilers['UNKNOWN'];
2787
+ }
2782
2788
  await compiler?.(node, this);
2783
2789
  }
2784
2790
  async compileNodes(nodes) {
package/dist/index.js CHANGED
@@ -2603,8 +2603,8 @@ ${output
2603
2603
  }
2604
2604
  let parser = this.options.parsers[token.name?.toLowerCase() ??
2605
2605
  token.type?.toLowerCase()];
2606
- if (parser === 'unexpected') {
2607
- parser = this.options.parsers['unexpected'];
2606
+ if (typeof parser === 'string') {
2607
+ parser = this.options.parsers[parser];
2608
2608
  }
2609
2609
  if (!parser) {
2610
2610
  parser = this.options.parsers['unknown'];
@@ -2781,7 +2781,13 @@ ${output
2781
2781
  await this.compileNodes(node.body);
2782
2782
  return;
2783
2783
  }
2784
- const compiler = this.options.compilers[node.type] || this.options.compilers['UNKNOWN'];
2784
+ let compiler = this.options.compilers[node.type];
2785
+ if (typeof compiler === 'string') {
2786
+ compiler = this.options.compilers[compiler];
2787
+ }
2788
+ if (!compiler) {
2789
+ compiler = this.options.compilers['UNKNOWN'];
2790
+ }
2785
2791
  await compiler?.(node, this);
2786
2792
  }
2787
2793
  async compileNodes(nodes) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "janja",
3
3
  "type": "module",
4
- "version": "2.1.3",
4
+ "version": "2.2.0",
5
5
  "packageManager": "yarn@4.9.2",
6
6
  "description": "A simple, fast, lightweight, and extensible template engine for Node.js and browsers.",
7
7
  "license": "MIT",