blogger-hbs 0.0.6 → 0.0.7

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.
Files changed (47) hide show
  1. package/dist/compiler/ast/imports.js +5 -24
  2. package/dist/compiler/ast/imports.js.map +1 -1
  3. package/dist/compiler/ast/walk.d.ts +2 -2
  4. package/dist/compiler/ast/walk.js +5 -21
  5. package/dist/compiler/ast/walk.js.map +1 -1
  6. package/dist/compiler/compile.d.ts +9 -1
  7. package/dist/compiler/compile.js +18 -13
  8. package/dist/compiler/compile.js.map +1 -1
  9. package/dist/compiler/evaluate.d.ts +8 -0
  10. package/dist/compiler/evaluate.js +13 -0
  11. package/dist/compiler/evaluate.js.map +1 -0
  12. package/dist/compiler/index.d.ts +2 -2
  13. package/dist/compiler/index.js +2 -2
  14. package/dist/compiler/plugins.d.ts +1 -1
  15. package/dist/compiler/plugins.js +162 -142
  16. package/dist/compiler/plugins.js.map +1 -1
  17. package/dist/compiler/precompile.js +2 -2
  18. package/dist/compiler/precompile.js.map +1 -1
  19. package/dist/compiler/rsbuild.d.ts +20 -1
  20. package/dist/compiler/rsbuild.js +55 -28
  21. package/dist/compiler/rsbuild.js.map +1 -1
  22. package/dist/compiler/runtimes.js +10 -24
  23. package/dist/compiler/runtimes.js.map +1 -1
  24. package/dist/compiler/scan.d.ts +1 -1
  25. package/dist/compiler/scan.js +12 -7
  26. package/dist/compiler/scan.js.map +1 -1
  27. package/dist/compiler/watch.js +9 -2
  28. package/dist/compiler/watch.js.map +1 -1
  29. package/dist/constants.d.ts +8 -0
  30. package/dist/constants.js +23 -1
  31. package/dist/constants.js.map +1 -1
  32. package/dist/plugins/index.d.ts +9 -0
  33. package/dist/plugins/index.js +24 -1
  34. package/dist/plugins/index.js.map +1 -1
  35. package/dist/runtime/import.js +69 -40
  36. package/dist/runtime/import.js.map +1 -1
  37. package/dist/runtime/linebreaks.js +6 -4
  38. package/dist/runtime/linebreaks.js.map +1 -1
  39. package/dist/runtime/render.js +4 -20
  40. package/dist/runtime/render.js.map +1 -1
  41. package/dist/runtime/tags.d.ts +3 -2
  42. package/dist/runtime/tags.js +8 -18
  43. package/dist/runtime/tags.js.map +1 -1
  44. package/dist/utils/resolver.d.ts +5 -0
  45. package/dist/utils/resolver.js +80 -8
  46. package/dist/utils/resolver.js.map +1 -1
  47. package/package.json +1 -1
@@ -1,27 +1,8 @@
1
- import { ATTRIBUTE_NAME_REGEX } from "../../constants.js";
1
+ import { ATTRIBUTE_NAME_REGEX, OUTPUT_FLAGS } from "../../constants.js";
2
2
  import { walk } from "./walk.js";
3
3
  //#region src/compiler/ast/imports.ts
4
4
  const ASSET_KEYS = /* @__PURE__ */ new Set(["script", "style"]);
5
5
  const ASSET_ATTRIBUTE_REGEX = /^(?:script|style):(.+)$/s;
6
- /** Options rendering only the script or the styles of an import, raw without a tag. */
7
- const FLAG_KEYS = /* @__PURE__ */ new Map([
8
- ["script:raw", {
9
- tag: "script",
10
- raw: true
11
- }],
12
- ["style:raw", {
13
- tag: "style",
14
- raw: true
15
- }],
16
- ["script:only", {
17
- tag: "script",
18
- raw: false
19
- }],
20
- ["style:only", {
21
- tag: "style",
22
- raw: false
23
- }]
24
- ]);
25
6
  function extractImports(node) {
26
7
  const imports = [];
27
8
  for (const importNode of extractImportNodes(node)) {
@@ -73,7 +54,7 @@ function extractImports(node) {
73
54
  }
74
55
  continue;
75
56
  }
76
- if (FLAG_KEYS.has(key)) {
57
+ if (OUTPUT_FLAGS.has(key)) {
77
58
  if (!isFlagValue(value)) {
78
59
  reason = `'import' option '${key}' must be true, 'true' or '', got: ${describeValue(value)}`;
79
60
  break;
@@ -88,11 +69,11 @@ function extractImports(node) {
88
69
  reason = `'import' received an invalid option '${key}'`;
89
70
  break;
90
71
  }
91
- const flag = hashKeys.find((key) => FLAG_KEYS.has(key));
92
- const mode = flag === void 0 ? void 0 : FLAG_KEYS.get(flag);
72
+ const flag = hashKeys.find((key) => OUTPUT_FLAGS.has(key));
73
+ const mode = flag === void 0 ? void 0 : OUTPUT_FLAGS.get(flag);
93
74
  if (reason === void 0 && flag !== void 0 && mode !== void 0) {
94
75
  const omitted = mode.tag === "script" ? "style" : "script";
95
- const conflict = hashKeys.find((key) => key !== flag && (mode.raw || FLAG_KEYS.has(key) || key === omitted || key.startsWith(`${omitted}:`)));
76
+ const conflict = hashKeys.find((key) => key !== flag && (mode.raw || OUTPUT_FLAGS.has(key) || key === omitted || key.startsWith(`${omitted}:`)));
96
77
  if (conflict !== void 0) reason = `'import' option '${flag}' cannot be combined with '${conflict}'`;
97
78
  }
98
79
  if (reason !== void 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"imports.js","names":[],"sources":["../../../src/compiler/ast/imports.ts"],"sourcesContent":["import { ATTRIBUTE_NAME_REGEX } from '../../constants';\nimport type {\n\tBlockStatement,\n\tExpression,\n\tMustacheStatement,\n\tNode,\n\tPathExpression,\n\tSubExpression,\n} from './types';\nimport { walk } from './walk';\n\nconst ASSET_KEYS = new Set(['script', 'style']);\nconst ASSET_ATTRIBUTE_REGEX = /^(?:script|style):(.+)$/s;\n/** Options rendering only the script or the styles of an import, raw without a tag. */\nconst FLAG_KEYS = new Map<string, { tag: 'script' | 'style'; raw: boolean }>([\n\t['script:raw', { tag: 'script', raw: true }],\n\t['style:raw', { tag: 'style', raw: true }],\n\t['script:only', { tag: 'script', raw: false }],\n\t['style:only', { tag: 'style', raw: false }],\n]);\n\ninterface Location {\n\tstart: [number, number];\n\tend: [number, number];\n\tnode: ImportNode;\n}\n\nexport interface ValidImport extends Location {\n\tvalid: true;\n\tspecifier: string;\n\tdependsOn: string[];\n\thashKeys: string[];\n}\n\nexport interface InvalidImport extends Location {\n\tvalid: false;\n\treason: string;\n}\n\nexport type Import = ValidImport | InvalidImport;\n\nexport function extractImports(node: Node): Import[] {\n\tconst imports: Import[] = [];\n\n\tfor (const importNode of extractImportNodes(node)) {\n\t\tconst { params, loc, hash } = importNode;\n\t\tconst location: Location = {\n\t\t\tstart: [loc.start.line, loc.start.column],\n\t\t\tend: [loc.end.line, loc.end.column],\n\t\t\tnode: importNode,\n\t\t};\n\n\t\tconst invalid = (reason: string): void => {\n\t\t\timports.push({\n\t\t\t\t...location,\n\t\t\t\tvalid: false,\n\t\t\t\treason,\n\t\t\t});\n\t\t};\n\n\t\tif (params.length === 0) {\n\t\t\tinvalid(\"'import' expects a string literal argument\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (params.length > 1) {\n\t\t\tinvalid(\"'import' accepts only one argument\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst specifier = params[0];\n\t\tif (specifier.type !== 'StringLiteral') {\n\t\t\tinvalid(\"First argument to 'import' must be a string literal\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet dependsOn: string[] = [];\n\t\tconst hashKeys: string[] = [];\n\t\tconst seenKeys = new Set<string>();\n\t\tlet reason: string | undefined;\n\n\t\tfor (const { key, value } of hash?.pairs || []) {\n\t\t\tif (seenKeys.has(key)) {\n\t\t\t\treason = `'import' option '${key}' was specified more than once`;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tseenKeys.add(key);\n\n\t\t\tif (key === 'depends-on') {\n\t\t\t\tif (value.type !== 'StringLiteral') {\n\t\t\t\t\treason = \"'import' 'depends-on' must be a string literal\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdependsOn = value.value\n\t\t\t\t\t.split(',')\n\t\t\t\t\t.map((item) => item.trim())\n\t\t\t\t\t.filter(Boolean);\n\t\t\t\t// an empty list would let the option pass where it is not supported\n\t\t\t\tif (dependsOn.length === 0) {\n\t\t\t\t\treason =\n\t\t\t\t\t\t\"'import' 'depends-on' must list at least one script or style\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (FLAG_KEYS.has(key)) {\n\t\t\t\tif (!isFlagValue(value)) {\n\t\t\t\t\treason = `'import' option '${key}' must be true, 'true' or '', got: ${describeValue(value)}`;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\thashKeys.push(key);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (ASSET_KEYS.has(key) || isAssetAttribute(key)) {\n\t\t\t\thashKeys.push(key);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\treason = `'import' received an invalid option '${key}'`;\n\t\t\tbreak;\n\t\t}\n\n\t\t// raw output has no tag, so there is nothing other options could apply to,\n\t\t// and the options of the tag left out by `only` would be ignored\n\t\tconst flag = hashKeys.find((key) => FLAG_KEYS.has(key));\n\t\tconst mode = flag === undefined ? undefined : FLAG_KEYS.get(flag);\n\t\tif (reason === undefined && flag !== undefined && mode !== undefined) {\n\t\t\tconst omitted = mode.tag === 'script' ? 'style' : 'script';\n\t\t\tconst conflict = hashKeys.find(\n\t\t\t\t(key) =>\n\t\t\t\t\tkey !== flag &&\n\t\t\t\t\t(mode.raw ||\n\t\t\t\t\t\tFLAG_KEYS.has(key) ||\n\t\t\t\t\t\tkey === omitted ||\n\t\t\t\t\t\tkey.startsWith(`${omitted}:`)),\n\t\t\t);\n\t\t\tif (conflict !== undefined) {\n\t\t\t\treason = `'import' option '${flag}' cannot be combined with '${conflict}'`;\n\t\t\t}\n\t\t}\n\n\t\tif (reason !== undefined) {\n\t\t\tinvalid(reason);\n\t\t\tcontinue;\n\t\t}\n\n\t\timports.push({\n\t\t\t...location,\n\t\t\tvalid: true,\n\t\t\tspecifier: specifier.value,\n\t\t\tdependsOn,\n\t\t\thashKeys,\n\t\t});\n\t}\n\n\treturn imports;\n}\n\nfunction extractImportNodes(node: Node): ImportNode[] {\n\tconst nodes: ImportNode[] = [];\n\twalk(node, (node) => {\n\t\tif (isImportNode(node)) {\n\t\t\tnodes.push(node);\n\t\t}\n\t});\n\treturn nodes;\n}\n\nexport type ImportNode = (\n\t| MustacheStatement\n\t| BlockStatement\n\t| SubExpression\n) & {\n\tpath: PathExpression;\n};\n\nexport function isImportNode(node: Node): node is ImportNode {\n\treturn (\n\t\t(node.type === 'MustacheStatement' ||\n\t\t\tnode.type === 'BlockStatement' ||\n\t\t\tnode.type === 'SubExpression') &&\n\t\tnode.path.type === 'PathExpression' &&\n\t\tnode.path.parts.length === 1 &&\n\t\tnode.path.parts[0] === 'import'\n\t);\n}\n\n/** `script:raw` / `style:raw` / `script:only` / `style:only` take `true`, `'true'` or an empty string. */\nfunction isFlagValue(value: Expression): boolean {\n\treturn (\n\t\t(value.type === 'BooleanLiteral' && value.value) ||\n\t\t(value.type === 'StringLiteral' &&\n\t\t\t(value.value === 'true' || value.value === ''))\n\t);\n}\n\nfunction describeValue(value: Expression): string {\n\tswitch (value.type) {\n\t\tcase 'StringLiteral':\n\t\t\treturn `'${value.value}'`;\n\t\tcase 'BooleanLiteral':\n\t\tcase 'NumberLiteral':\n\t\t\treturn String(value.value);\n\t\tcase 'NullLiteral':\n\t\t\treturn 'null';\n\t\tcase 'UndefinedLiteral':\n\t\t\treturn 'undefined';\n\t\tcase 'PathExpression':\n\t\t\treturn `variable '${value.original}'`;\n\t\tcase 'SubExpression':\n\t\t\treturn `subexpression '${value.path.original}'`;\n\t}\n}\n\nfunction isAssetAttribute(key: string): boolean {\n\tconst name = ASSET_ATTRIBUTE_REGEX.exec(key)?.[1];\n\treturn name !== undefined && ATTRIBUTE_NAME_REGEX.test(name);\n}\n"],"mappings":";;;AAWA,MAAM,6BAAa,IAAI,IAAI,CAAC,UAAU,OAAO,CAAC;AAC9C,MAAM,wBAAwB;;AAE9B,MAAM,4BAAY,IAAI,IAAuD;CAC5E,CAAC,cAAc;EAAE,KAAK;EAAU,KAAK;CAAK,CAAC;CAC3C,CAAC,aAAa;EAAE,KAAK;EAAS,KAAK;CAAK,CAAC;CACzC,CAAC,eAAe;EAAE,KAAK;EAAU,KAAK;CAAM,CAAC;CAC7C,CAAC,cAAc;EAAE,KAAK;EAAS,KAAK;CAAM,CAAC;AAC5C,CAAC;AAsBD,SAAgB,eAAe,MAAsB;CACpD,MAAM,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iBACJ,OAAO,IAAI,MAAM,MAAM;EACxB,KAAK;EACL,KAAK,iBACJ,OAAO,OAAO,MAAM,KAAK;EAC1B,KAAK,eACJ,OAAO;EACR,KAAK,oBACJ,OAAO;EACR,KAAK,kBACJ,OAAO,aAAa,MAAM,SAAS;EACpC,KAAK,iBACJ,OAAO,kBAAkB,MAAM,KAAK,SAAS;CAC/C;AACD;AAEA,SAAS,iBAAiB,KAAsB;CAC/C,MAAM,OAAO,sBAAsB,KAAK,GAAG,CAAC,GAAG;CAC/C,OAAO,SAAS,KAAA,KAAa,qBAAqB,KAAK,IAAI;AAC5D"}
1
+ {"version":3,"file":"imports.js","names":[],"sources":["../../../src/compiler/ast/imports.ts"],"sourcesContent":["import { ATTRIBUTE_NAME_REGEX, OUTPUT_FLAGS } from '../../constants';\nimport type {\n\tBlockStatement,\n\tExpression,\n\tMustacheStatement,\n\tNode,\n\tPathExpression,\n\tSubExpression,\n} from './types';\nimport { walk } from './walk';\n\nconst ASSET_KEYS = new Set(['script', 'style']);\nconst ASSET_ATTRIBUTE_REGEX = /^(?:script|style):(.+)$/s;\n\ninterface Location {\n\tstart: [number, number];\n\tend: [number, number];\n\tnode: ImportNode;\n}\n\nexport interface ValidImport extends Location {\n\tvalid: true;\n\tspecifier: string;\n\tdependsOn: string[];\n\thashKeys: string[];\n}\n\nexport interface InvalidImport extends Location {\n\tvalid: false;\n\treason: string;\n}\n\nexport type Import = ValidImport | InvalidImport;\n\nexport function extractImports(node: Node): Import[] {\n\tconst imports: Import[] = [];\n\n\tfor (const importNode of extractImportNodes(node)) {\n\t\tconst { params, loc, hash } = importNode;\n\t\tconst location: Location = {\n\t\t\tstart: [loc.start.line, loc.start.column],\n\t\t\tend: [loc.end.line, loc.end.column],\n\t\t\tnode: importNode,\n\t\t};\n\n\t\tconst invalid = (reason: string): void => {\n\t\t\timports.push({\n\t\t\t\t...location,\n\t\t\t\tvalid: false,\n\t\t\t\treason,\n\t\t\t});\n\t\t};\n\n\t\tif (params.length === 0) {\n\t\t\tinvalid(\"'import' expects a string literal argument\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (params.length > 1) {\n\t\t\tinvalid(\"'import' accepts only one argument\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst specifier = params[0];\n\t\tif (specifier.type !== 'StringLiteral') {\n\t\t\tinvalid(\"First argument to 'import' must be a string literal\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet dependsOn: string[] = [];\n\t\tconst hashKeys: string[] = [];\n\t\tconst seenKeys = new Set<string>();\n\t\tlet reason: string | undefined;\n\n\t\tfor (const { key, value } of hash?.pairs || []) {\n\t\t\tif (seenKeys.has(key)) {\n\t\t\t\treason = `'import' option '${key}' was specified more than once`;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tseenKeys.add(key);\n\n\t\t\tif (key === 'depends-on') {\n\t\t\t\tif (value.type !== 'StringLiteral') {\n\t\t\t\t\treason = \"'import' 'depends-on' must be a string literal\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdependsOn = value.value\n\t\t\t\t\t.split(',')\n\t\t\t\t\t.map((item) => item.trim())\n\t\t\t\t\t.filter(Boolean);\n\t\t\t\t// an empty list would let the option pass where it is not supported\n\t\t\t\tif (dependsOn.length === 0) {\n\t\t\t\t\treason =\n\t\t\t\t\t\t\"'import' 'depends-on' must list at least one script or style\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (OUTPUT_FLAGS.has(key)) {\n\t\t\t\tif (!isFlagValue(value)) {\n\t\t\t\t\treason = `'import' option '${key}' must be true, 'true' or '', got: ${describeValue(value)}`;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\thashKeys.push(key);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (ASSET_KEYS.has(key) || isAssetAttribute(key)) {\n\t\t\t\thashKeys.push(key);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\treason = `'import' received an invalid option '${key}'`;\n\t\t\tbreak;\n\t\t}\n\n\t\t// raw output has no tag, so there is nothing other options could apply to,\n\t\t// and the options of the tag left out by `only` would be ignored\n\t\tconst flag = hashKeys.find((key) => OUTPUT_FLAGS.has(key));\n\t\tconst mode = flag === undefined ? undefined : OUTPUT_FLAGS.get(flag);\n\t\tif (reason === undefined && flag !== undefined && mode !== undefined) {\n\t\t\tconst omitted = mode.tag === 'script' ? 'style' : 'script';\n\t\t\tconst conflict = hashKeys.find(\n\t\t\t\t(key) =>\n\t\t\t\t\tkey !== flag &&\n\t\t\t\t\t(mode.raw ||\n\t\t\t\t\t\tOUTPUT_FLAGS.has(key) ||\n\t\t\t\t\t\tkey === omitted ||\n\t\t\t\t\t\tkey.startsWith(`${omitted}:`)),\n\t\t\t);\n\t\t\tif (conflict !== undefined) {\n\t\t\t\treason = `'import' option '${flag}' cannot be combined with '${conflict}'`;\n\t\t\t}\n\t\t}\n\n\t\tif (reason !== undefined) {\n\t\t\tinvalid(reason);\n\t\t\tcontinue;\n\t\t}\n\n\t\timports.push({\n\t\t\t...location,\n\t\t\tvalid: true,\n\t\t\tspecifier: specifier.value,\n\t\t\tdependsOn,\n\t\t\thashKeys,\n\t\t});\n\t}\n\n\treturn imports;\n}\n\nfunction extractImportNodes(node: Node): ImportNode[] {\n\tconst nodes: ImportNode[] = [];\n\twalk(node, (node) => {\n\t\tif (isImportNode(node)) {\n\t\t\tnodes.push(node);\n\t\t}\n\t});\n\treturn nodes;\n}\n\nexport type ImportNode = (\n\t| MustacheStatement\n\t| BlockStatement\n\t| SubExpression\n) & {\n\tpath: PathExpression;\n};\n\nexport function isImportNode(node: Node): node is ImportNode {\n\treturn (\n\t\t(node.type === 'MustacheStatement' ||\n\t\t\tnode.type === 'BlockStatement' ||\n\t\t\tnode.type === 'SubExpression') &&\n\t\tnode.path.type === 'PathExpression' &&\n\t\tnode.path.parts.length === 1 &&\n\t\tnode.path.parts[0] === 'import'\n\t);\n}\n\n/** `script:raw` / `style:raw` / `script:only` / `style:only` take `true`, `'true'` or an empty string. */\nfunction isFlagValue(value: Expression): boolean {\n\treturn (\n\t\t(value.type === 'BooleanLiteral' && value.value) ||\n\t\t(value.type === 'StringLiteral' &&\n\t\t\t(value.value === 'true' || value.value === ''))\n\t);\n}\n\nfunction describeValue(value: Expression): string {\n\tswitch (value.type) {\n\t\tcase 'StringLiteral':\n\t\t\treturn `'${value.value}'`;\n\t\tcase 'BooleanLiteral':\n\t\tcase 'NumberLiteral':\n\t\t\treturn String(value.value);\n\t\tcase 'NullLiteral':\n\t\t\treturn 'null';\n\t\tcase 'UndefinedLiteral':\n\t\t\treturn 'undefined';\n\t\tcase 'PathExpression':\n\t\t\treturn `variable '${value.original}'`;\n\t\tcase 'SubExpression':\n\t\t\treturn `subexpression '${value.path.original}'`;\n\t}\n}\n\nfunction isAssetAttribute(key: string): boolean {\n\tconst name = ASSET_ATTRIBUTE_REGEX.exec(key)?.[1];\n\treturn name !== undefined && ATTRIBUTE_NAME_REGEX.test(name);\n}\n"],"mappings":";;;AAWA,MAAM,6BAAa,IAAI,IAAI,CAAC,UAAU,OAAO,CAAC;AAC9C,MAAM,wBAAwB;AAsB9B,SAAgB,eAAe,MAAsB;CACpD,MAAM,UAAoB,CAAC;CAE3B,KAAK,MAAM,cAAc,mBAAmB,IAAI,GAAG;EAClD,MAAM,EAAE,QAAQ,KAAK,SAAS;EAC9B,MAAM,WAAqB;GAC1B,OAAO,CAAC,IAAI,MAAM,MAAM,IAAI,MAAM,MAAM;GACxC,KAAK,CAAC,IAAI,IAAI,MAAM,IAAI,IAAI,MAAM;GAClC,MAAM;EACP;EAEA,MAAM,WAAW,WAAyB;GACzC,QAAQ,KAAK;IACZ,GAAG;IACH,OAAO;IACP;GACD,CAAC;EACF;EAEA,IAAI,OAAO,WAAW,GAAG;GACxB,QAAQ,4CAA4C;GACpD;EACD;EAEA,IAAI,OAAO,SAAS,GAAG;GACtB,QAAQ,oCAAoC;GAC5C;EACD;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lock, Expression, Hash, HashPair, Literal, MustacheStatement, Node, NullLiteral, NumberLiteral, PartialBlockStatement, PartialStatement, PathExpression, Position, Program, SourceLocation, Statement, StringLiteral, StripFlags, SubExpression, UndefinedLiteral } from "./types.js";
1
+ import { Node } from "./types.js";
2
2
  //#region src/compiler/ast/walk.d.ts
3
+ /** Calls `callback` with `node` and every node in it, parents first. */
3
4
  export declare function walk(node: Node, callback: (node: Node) => void): void;
4
5
  //#endregion
5
- export { BlockStatement, BooleanLiteral, CommentStatement, ContentStatement, Decorator, DecoratorBlock, Expression, Hash, HashPair, Literal, MustacheStatement, Node, NullLiteral, NumberLiteral, PartialBlockStatement, PartialStatement, PathExpression, Position, Program, SourceLocation, Statement, StringLiteral, StripFlags, SubExpression, UndefinedLiteral };
6
6
  //# sourceMappingURL=walk.d.ts.map
@@ -1,4 +1,5 @@
1
1
  //#region src/compiler/ast/walk.ts
2
+ /** Calls `callback` with `node` and every node in it, parents first. */
2
3
  function walk(node, callback) {
3
4
  callback(node);
4
5
  switch (node.type) {
@@ -7,33 +8,16 @@ function walk(node, callback) {
7
8
  break;
8
9
  case "MustacheStatement":
9
10
  case "Decorator":
10
- walk(node.path, callback);
11
- for (const param of node.params) walk(param, callback);
12
- if (node.hash) walk(node.hash, callback);
13
- break;
11
+ case "SubExpression":
14
12
  case "BlockStatement":
15
13
  case "DecoratorBlock":
16
- walk(node.path, callback);
17
- for (const param of node.params) walk(param, callback);
18
- if (node.hash) walk(node.hash, callback);
19
- walk(node.program, callback);
20
- if (node.inverse) walk(node.inverse, callback);
21
- break;
22
14
  case "PartialStatement":
23
- walk(node.name, callback);
24
- for (const param of node.params) walk(param, callback);
25
- if (node.hash) walk(node.hash, callback);
26
- break;
27
15
  case "PartialBlockStatement":
28
- walk(node.name, callback);
29
- for (const param of node.params) walk(param, callback);
30
- if (node.hash) walk(node.hash, callback);
31
- walk(node.program, callback);
32
- break;
33
- case "SubExpression":
34
- walk(node.path, callback);
16
+ walk("path" in node ? node.path : node.name, callback);
35
17
  for (const param of node.params) walk(param, callback);
36
18
  if (node.hash) walk(node.hash, callback);
19
+ if ("program" in node && node.program) walk(node.program, callback);
20
+ if ("inverse" in node && node.inverse) walk(node.inverse, callback);
37
21
  break;
38
22
  case "Hash":
39
23
  for (const pair of node.pairs) walk(pair, callback);
@@ -1 +1 @@
1
- {"version":3,"file":"walk.js","names":[],"sources":["../../../src/compiler/ast/walk.ts"],"sourcesContent":["import type { Node } from './types';\n\nexport function walk(node: Node, callback: (node: Node) => void): void {\n\tcallback(node);\n\n\tswitch (node.type) {\n\t\tcase 'Program':\n\t\t\tfor (const statement of node.body) {\n\t\t\t\twalk(statement, callback);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 'MustacheStatement':\n\t\tcase 'Decorator':\n\t\t\twalk(node.path, callback);\n\t\t\tfor (const param of node.params) {\n\t\t\t\twalk(param, callback);\n\t\t\t}\n\t\t\tif (node.hash) {\n\t\t\t\twalk(node.hash, callback);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 'BlockStatement':\n\t\tcase 'DecoratorBlock':\n\t\t\twalk(node.path, callback);\n\t\t\tfor (const param of node.params) {\n\t\t\t\twalk(param, callback);\n\t\t\t}\n\t\t\tif (node.hash) {\n\t\t\t\twalk(node.hash, callback);\n\t\t\t}\n\t\t\twalk(node.program, callback);\n\n\t\t\tif (node.inverse) {\n\t\t\t\twalk(node.inverse, callback);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 'PartialStatement':\n\t\t\twalk(node.name, callback);\n\t\t\tfor (const param of node.params) {\n\t\t\t\twalk(param, callback);\n\t\t\t}\n\t\t\tif (node.hash) {\n\t\t\t\twalk(node.hash, callback);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 'PartialBlockStatement':\n\t\t\twalk(node.name, callback);\n\t\t\tfor (const param of node.params) {\n\t\t\t\twalk(param, callback);\n\t\t\t}\n\t\t\tif (node.hash) {\n\t\t\t\twalk(node.hash, callback);\n\t\t\t}\n\t\t\twalk(node.program, callback);\n\t\t\tbreak;\n\n\t\tcase 'SubExpression':\n\t\t\twalk(node.path, callback);\n\t\t\tfor (const param of node.params) {\n\t\t\t\twalk(param, callback);\n\t\t\t}\n\t\t\tif (node.hash) {\n\t\t\t\twalk(node.hash, callback);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 'Hash':\n\t\t\tfor (const pair of node.pairs) {\n\t\t\t\twalk(pair, callback);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 'HashPair':\n\t\t\twalk(node.value, callback);\n\t\t\tbreak;\n\t}\n}\n\nexport * from './types';\n"],"mappings":";AAEA,SAAgB,KAAK,MAAY,UAAsC;CACtE,SAAS,IAAI;CAEb,QAAQ,KAAK,MAAb;EACC,KAAK;GACJ,KAAK,MAAM,aAAa,KAAK,MAC5B,KAAK,WAAW,QAAQ;GAEzB;EAED,KAAK;EACL,KAAK;GACJ,KAAK,KAAK,MAAM,QAAQ;GACxB,KAAK,MAAM,SAAS,KAAK,QACxB,KAAK,OAAO,QAAQ;GAErB,IAAI,KAAK,MACR,KAAK,KAAK,MAAM,QAAQ;GAEzB;EAED,KAAK;EACL,KAAK;GACJ,KAAK,KAAK,MAAM,QAAQ;GACxB,KAAK,MAAM,SAAS,KAAK,QACxB,KAAK,OAAO,QAAQ;GAErB,IAAI,KAAK,MACR,KAAK,KAAK,MAAM,QAAQ;GAEzB,KAAK,KAAK,SAAS,QAAQ;GAE3B,IAAI,KAAK,SACR,KAAK,KAAK,SAAS,QAAQ;GAE5B;EAED,KAAK;GACJ,KAAK,KAAK,MAAM,QAAQ;GACxB,KAAK,MAAM,SAAS,KAAK,QACxB,KAAK,OAAO,QAAQ;GAErB,IAAI,KAAK,MACR,KAAK,KAAK,MAAM,QAAQ;GAEzB;EAED,KAAK;GACJ,KAAK,KAAK,MAAM,QAAQ;GACxB,KAAK,MAAM,SAAS,KAAK,QACxB,KAAK,OAAO,QAAQ;GAErB,IAAI,KAAK,MACR,KAAK,KAAK,MAAM,QAAQ;GAEzB,KAAK,KAAK,SAAS,QAAQ;GAC3B;EAED,KAAK;GACJ,KAAK,KAAK,MAAM,QAAQ;GACxB,KAAK,MAAM,SAAS,KAAK,QACxB,KAAK,OAAO,QAAQ;GAErB,IAAI,KAAK,MACR,KAAK,KAAK,MAAM,QAAQ;GAEzB;EAED,KAAK;GACJ,KAAK,MAAM,QAAQ,KAAK,OACvB,KAAK,MAAM,QAAQ;GAEpB;EAED,KAAK,YACJ,KAAK,KAAK,OAAO,QAAQ;CAE3B;AACD"}
1
+ {"version":3,"file":"walk.js","names":[],"sources":["../../../src/compiler/ast/walk.ts"],"sourcesContent":["import type { Node } from './types';\n\n/** Calls `callback` with `node` and every node in it, parents first. */\nexport function walk(node: Node, callback: (node: Node) => void): void {\n\tcallback(node);\n\n\tswitch (node.type) {\n\t\tcase 'Program':\n\t\t\tfor (const statement of node.body) {\n\t\t\t\twalk(statement, callback);\n\t\t\t}\n\t\t\tbreak;\n\n\t\t// a call: its name, its arguments and its hash, and the blocks of a block\n\t\tcase 'MustacheStatement':\n\t\tcase 'Decorator':\n\t\tcase 'SubExpression':\n\t\tcase 'BlockStatement':\n\t\tcase 'DecoratorBlock':\n\t\tcase 'PartialStatement':\n\t\tcase 'PartialBlockStatement':\n\t\t\twalk('path' in node ? node.path : node.name, callback);\n\t\t\tfor (const param of node.params) {\n\t\t\t\twalk(param, callback);\n\t\t\t}\n\t\t\tif (node.hash) {\n\t\t\t\twalk(node.hash, callback);\n\t\t\t}\n\t\t\tif ('program' in node && node.program) {\n\t\t\t\twalk(node.program, callback);\n\t\t\t}\n\t\t\tif ('inverse' in node && node.inverse) {\n\t\t\t\twalk(node.inverse, callback);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 'Hash':\n\t\t\tfor (const pair of node.pairs) {\n\t\t\t\twalk(pair, callback);\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase 'HashPair':\n\t\t\twalk(node.value, callback);\n\t\t\tbreak;\n\t}\n}\n"],"mappings":";;AAGA,SAAgB,KAAK,MAAY,UAAsC;CACtE,SAAS,IAAI;CAEb,QAAQ,KAAK,MAAb;EACC,KAAK;GACJ,KAAK,MAAM,aAAa,KAAK,MAC5B,KAAK,WAAW,QAAQ;GAEzB;EAGD,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;GACJ,KAAK,UAAU,OAAO,KAAK,OAAO,KAAK,MAAM,QAAQ;GACrD,KAAK,MAAM,SAAS,KAAK,QACxB,KAAK,OAAO,QAAQ;GAErB,IAAI,KAAK,MACR,KAAK,KAAK,MAAM,QAAQ;GAEzB,IAAI,aAAa,QAAQ,KAAK,SAC7B,KAAK,KAAK,SAAS,QAAQ;GAE5B,IAAI,aAAa,QAAQ,KAAK,SAC7B,KAAK,KAAK,SAAS,QAAQ;GAE5B;EAED,KAAK;GACJ,KAAK,MAAM,QAAQ,KAAK,OACvB,KAAK,MAAM,QAAQ;GAEpB;EAED,KAAK,YACJ,KAAK,KAAK,OAAO,QAAQ;CAE3B;AACD"}
@@ -1,5 +1,6 @@
1
1
  import { CompilePlugin } from "../plugins/index.js";
2
2
  import { PluginData } from "../runtime/chunks.js";
3
+ import { Resolver } from "../utils/resolver.js";
3
4
  import { Chunks, PartialChunk } from "./chunks.js";
4
5
  import { RuntimeRequest } from "./plugins.js";
5
6
  import { RsbuildOptions } from "./rsbuild.js";
@@ -55,9 +56,16 @@ export interface PrepareOptions {
55
56
  onRead?: (file: string) => void;
56
57
  /** Whether the template is compiled again on changes, told to plugins. */
57
58
  watch?: boolean;
59
+ /**
60
+ * The resolver to reuse between compilations, cleared when files change,
61
+ * see `createTemplateResolver`. A new one without it.
62
+ */
63
+ resolver?: Resolver;
58
64
  }
65
+ /** The resolver of the imports of the templates, for the root and aliases of the options. */
66
+ export declare function createTemplateResolver(options: CompileTemplateOptions): Resolver;
59
67
  /** Everything but bundling the scripts, styles and plugin runtimes, for validated options. */
60
- export declare function prepareTemplate(options?: CompileTemplateOptions, { onRead, watch }?: PrepareOptions): Promise<PreparedTemplate>;
68
+ export declare function prepareTemplate(options?: CompileTemplateOptions, { onRead, watch, resolver }?: PrepareOptions): Promise<PreparedTemplate>;
61
69
  /** Emits the module source of a template whose scripts, styles and runtimes are bundled. */
62
70
  export declare function finishTemplate({ entry, chunks, partials, pluginData }: PreparedTemplate, bundle: RuntimeBundle | undefined): CompiledTemplate;
63
71
  //#endregion
@@ -19,25 +19,30 @@ async function compileTemplate(options = {}) {
19
19
  assertCompileOptions(options);
20
20
  await assertDirectories(options);
21
21
  const prepared = await prepareTemplate(options);
22
- await bundleAssets(prepared.chunks, prepared.root, options.rsbuild, prepared.dependencies);
23
- return finishTemplate(prepared, await bundleRuntimes(prepared.root, prepared.runtimes));
22
+ const [assets, runtimes] = await Promise.allSettled([bundleAssets(prepared.chunks, prepared.root, options.rsbuild, prepared.dependencies), bundleRuntimes(prepared.root, prepared.runtimes)]);
23
+ if (assets.status === "rejected") throw assets.reason;
24
+ if (runtimes.status === "rejected") throw runtimes.reason;
25
+ return finishTemplate(prepared, runtimes.value);
24
26
  }
25
- /** Everything but bundling the scripts, styles and plugin runtimes, for validated options. */
26
- async function prepareTemplate(options = {}, { onRead, watch = false } = {}) {
27
- const { root, entry } = resolvePaths(options);
28
- const { alias = {}, onWarn = console.warn } = options;
29
- const plugins = sortPlugins(options.plugins ?? []);
30
- onRead?.(entry);
31
- await assertEntry(options);
32
- const resolver = createResolver({
33
- root,
34
- alias,
27
+ /** The resolver of the imports of the templates, for the root and aliases of the options. */
28
+ function createTemplateResolver(options) {
29
+ return createResolver({
30
+ root: resolvePaths(options).root,
31
+ alias: options.alias ?? {},
35
32
  extensions: {
36
33
  index: [...INDEX_EXTENSIONS],
37
34
  file: [...FILE_EXTENSIONS],
38
35
  resolve: [...RESOLVE_EXTENSIONS]
39
36
  }
40
37
  });
38
+ }
39
+ /** Everything but bundling the scripts, styles and plugin runtimes, for validated options. */
40
+ async function prepareTemplate(options = {}, { onRead, watch = false, resolver = createTemplateResolver(options) } = {}) {
41
+ const { root, entry } = resolvePaths(options);
42
+ const { onWarn = console.warn } = options;
43
+ const plugins = sortPlugins(options.plugins ?? []);
44
+ onRead?.(entry);
45
+ await assertEntry(options);
41
46
  const contexts = createPluginContexts(plugins, {
42
47
  root,
43
48
  entry,
@@ -93,6 +98,6 @@ function finishTemplate({ entry, chunks, partials, pluginData }, bundle) {
93
98
  };
94
99
  }
95
100
  //#endregion
96
- export { compileTemplate, finishTemplate, prepareTemplate };
101
+ export { compileTemplate, createTemplateResolver, finishTemplate, prepareTemplate };
97
102
 
98
103
  //# sourceMappingURL=compile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.js","names":[],"sources":["../../src/compiler/compile.ts"],"sourcesContent":["import {\n\tFILE_EXTENSIONS,\n\tINDEX_EXTENSIONS,\n\tRESOLVE_EXTENSIONS,\n\tTEMPLATE_FORMAT,\n} from '../constants';\nimport type { CompilePlugin } from '../plugins';\nimport type { PluginData } from '../runtime/chunks';\nimport { toSpecifier } from '../utils/path';\nimport { createResolver } from '../utils/resolver';\nimport { bundleAssets } from './bundle';\nimport type { Chunks, PartialChunk } from './chunks';\nimport { linkDependencies } from './dependencies';\nimport { emitSource } from './emit';\nimport {\n\tassertCompileOptions,\n\tassertDirectories,\n\tassertEntry,\n\tresolvePaths,\n} from './options';\nimport {\n\tcreatePluginContexts,\n\tendCompilePlugins,\n\ttype RuntimeRequest,\n\trunCompilePlugins,\n\tsortPlugins,\n} from './plugins';\nimport { precompileTemplates } from './precompile';\nimport type { RsbuildOptions } from './rsbuild';\nimport {\n\ttype BundledRuntime,\n\tbundleRuntimes,\n\ttype RuntimeBundle,\n} from './runtimes';\nimport { scan } from './scan';\nimport { validateTemplateXml } from './validate';\n\nexport interface CompileTemplateOptions {\n\troot?: string;\n\tentry?: string;\n\talias?: Record<string, string>;\n\tplugins?: CompilePlugin[];\n\t/** Rsbuild config for bundling scripts and styles, merged over the defaults. */\n\trsbuild?: RsbuildOptions;\n\t/** Called with the warnings of plugins, `console.warn` by default. */\n\tonWarn?: (message: string) => void;\n}\n\nexport interface CompiledTemplate {\n\t/** Version of the compiled output, checked by the runtime. */\n\tformat: number;\n\tchunks: Chunks;\n\t/** Templates provided by plugins, by partial name. */\n\tpluginPartials: Map<string, object>;\n\t/** Data provided by plugins, by plugin name and data name. */\n\tpluginData: PluginData;\n\t/** Runtime halves of the plugins, bundled. */\n\tbundledPlugins: BundledRuntime[];\n\tentry: string;\n\t/** The ES module to render the template with, it imports nothing. */\n\tsource: string;\n}\n\n/**\n * scan imports -> compile plugins -> validate dependencies -> precompile\n * templates -> bundle assets and plugin runtimes -> emit module source.\n */\nexport async function compileTemplate(\n\toptions: CompileTemplateOptions = {},\n): Promise<CompiledTemplate> {\n\tassertCompileOptions(options);\n\tawait assertDirectories(options);\n\n\tconst prepared = await prepareTemplate(options);\n\tawait bundleAssets(\n\t\tprepared.chunks,\n\t\tprepared.root,\n\t\toptions.rsbuild,\n\t\tprepared.dependencies,\n\t);\n\tconst bundle = await bundleRuntimes(prepared.root, prepared.runtimes);\n\treturn finishTemplate(prepared, bundle);\n}\n\n/** A template compiled up to the bundling of its scripts, styles and plugin runtimes. */\nexport interface PreparedTemplate {\n\troot: string;\n\t/** Id of the entry template. */\n\tentry: string;\n\tchunks: Chunks;\n\tpartials: PartialChunk[];\n\tpluginData: PluginData;\n\t/** The runtime halves of the plugins, to bundle. */\n\truntimes: RuntimeRequest[];\n\t/** The entries each script entry depends on. */\n\tdependencies: Map<string, string[]>;\n}\n\nexport interface PrepareOptions {\n\t/**\n\t * Called with every template and json file before it is read, and the files\n\t * plugins add, even when compiling fails.\n\t */\n\tonRead?: (file: string) => void;\n\t/** Whether the template is compiled again on changes, told to plugins. */\n\twatch?: boolean;\n}\n\n/** Everything but bundling the scripts, styles and plugin runtimes, for validated options. */\nexport async function prepareTemplate(\n\toptions: CompileTemplateOptions = {},\n\t{ onRead, watch = false }: PrepareOptions = {},\n): Promise<PreparedTemplate> {\n\tconst { root, entry } = resolvePaths(options);\n\tconst { alias = {}, onWarn = console.warn } = options;\n\tconst plugins = sortPlugins(options.plugins ?? []);\n\n\tonRead?.(entry);\n\tawait assertEntry(options);\n\n\tconst resolver = createResolver({\n\t\troot,\n\t\talias,\n\t\textensions: {\n\t\t\tindex: [...INDEX_EXTENSIONS],\n\t\t\tfile: [...FILE_EXTENSIONS],\n\t\t\tresolve: [...RESOLVE_EXTENSIONS],\n\t\t},\n\t});\n\n\tconst contexts = createPluginContexts(plugins, {\n\t\troot,\n\t\tentry,\n\t\twatch,\n\t\tresolver,\n\t\tonRead,\n\t\tonWarn,\n\t});\n\n\tlet prepared: PreparedTemplate;\n\ttry {\n\t\tconst { chunks, templates, requirements } = await scan(entry, {\n\t\t\troot,\n\t\t\tresolver,\n\t\t\tonRead,\n\t\t});\n\n\t\tconst {\n\t\t\tpartials,\n\t\t\tdata: pluginData,\n\t\t\truntimes,\n\t\t} = await runCompilePlugins(plugins, chunks, contexts);\n\t\tconst dependencies = linkDependencies(chunks, requirements);\n\n\t\t// always, after the plugins changed the templates and provided theirs, the\n\t\t// options of the rendered output do not turn it off\n\t\tfor (const template of templates) {\n\t\t\tvalidateTemplateXml(template.parsed, toSpecifier(root, template.path));\n\t\t}\n\t\tfor (const partial of partials) {\n\t\t\tvalidateTemplateXml(partial.parsed, partial.name, partial.plugin);\n\t\t}\n\n\t\tprecompileTemplates([...templates, ...partials]);\n\n\t\tprepared = {\n\t\t\troot,\n\t\t\tentry: toSpecifier(root, entry),\n\t\t\tchunks,\n\t\t\tpartials,\n\t\t\tpluginData,\n\t\t\truntimes,\n\t\t\tdependencies,\n\t\t};\n\t} catch (error) {\n\t\tawait endCompilePlugins(plugins, contexts, error);\n\t\tthrow error;\n\t}\n\n\tawait endCompilePlugins(plugins, contexts);\n\treturn prepared;\n}\n\n/** Emits the module source of a template whose scripts, styles and runtimes are bundled. */\nexport function finishTemplate(\n\t{ entry, chunks, partials, pluginData }: PreparedTemplate,\n\tbundle: RuntimeBundle | undefined,\n): CompiledTemplate {\n\tconst pluginPartials = new Map(\n\t\tpartials.map((partial) => [partial.name, partial.spec as object]),\n\t);\n\n\treturn {\n\t\tformat: TEMPLATE_FORMAT,\n\t\tchunks,\n\t\tpluginPartials,\n\t\tpluginData,\n\t\tbundledPlugins: bundle?.plugins ?? [],\n\t\tentry,\n\t\tsource: emitSource({\n\t\t\tchunks,\n\t\t\tpartials: new Map(\n\t\t\t\tpartials.map((partial) => [partial.name, partial.compiled as string]),\n\t\t\t),\n\t\t\tpluginData,\n\t\t\tbundle,\n\t\t\tentry,\n\t\t}),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmEA,eAAsB,gBACrB,UAAkC,CAAC,GACP;CAC5B,qBAAqB,OAAO;CAC5B,MAAM,kBAAkB,OAAO;CAE/B,MAAM,WAAW,MAAM,gBAAgB,OAAO;CAC9C,MAAM,aACL,SAAS,QACT,SAAS,MACT,QAAQ,SACR,SAAS,YACV;CAEA,OAAO,eAAe,UAAU,MADX,eAAe,SAAS,MAAM,SAAS,QAAQ,CAC9B;AACvC;;AA2BA,eAAsB,gBACrB,UAAkC,CAAC,GACnC,EAAE,QAAQ,QAAQ,UAA0B,CAAC,GACjB;CAC5B,MAAM,EAAE,MAAM,UAAU,aAAa,OAAO;CAC5C,MAAM,EAAE,QAAQ,CAAC,GAAG,SAAS,QAAQ,SAAS;CAC9C,MAAM,UAAU,YAAY,QAAQ,WAAW,CAAC,CAAC;CAEjD,SAAS,KAAK;CACd,MAAM,YAAY,OAAO;CAEzB,MAAM,WAAW,eAAe;EAC/B;EACA;EACA,YAAY;GACX,OAAO,CAAC,GAAG,gBAAgB;GAC3B,MAAM,CAAC,GAAG,eAAe;GACzB,SAAS,CAAC,GAAG,kBAAkB;EAChC;CACD,CAAC;CAED,MAAM,WAAW,qBAAqB,SAAS;EAC9C;EACA;EACA;EACA;EACA;EACA;CACD,CAAC;CAED,IAAI;CACJ,IAAI;EACH,MAAM,EAAE,QAAQ,WAAW,iBAAiB,MAAM,KAAK,OAAO;GAC7D;GACA;GACA;EACD,CAAC;EAED,MAAM,EACL,UACA,MAAM,YACN,aACG,MAAM,kBAAkB,SAAS,QAAQ,QAAQ;EACrD,MAAM,eAAe,iBAAiB,QAAQ,YAAY;EAI1D,KAAK,MAAM,YAAY,WACtB,oBAAoB,SAAS,QAAQ,YAAY,MAAM,SAAS,IAAI,CAAC;EAEtE,KAAK,MAAM,WAAW,UACrB,oBAAoB,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,MAAM;EAGjE,oBAAoB,CAAC,GAAG,WAAW,GAAG,QAAQ,CAAC;EAE/C,WAAW;GACV;GACA,OAAO,YAAY,MAAM,KAAK;GAC9B;GACA;GACA;GACA;GACA;EACD;CACD,SAAS,OAAO;EACf,MAAM,kBAAkB,SAAS,UAAU,KAAK;EAChD,MAAM;CACP;CAEA,MAAM,kBAAkB,SAAS,QAAQ;CACzC,OAAO;AACR;;AAGA,SAAgB,eACf,EAAE,OAAO,QAAQ,UAAU,cAC3B,QACmB;CAKnB,OAAO;EACN,QAAA;EACA;EACA,oBAP0B,IAC1B,SAAS,KAAK,YAAY,CAAC,QAAQ,MAAM,QAAQ,IAAc,CAAC,CAMhE;EACA;EACA,gBAAgB,QAAQ,WAAW,CAAC;EACpC;EACA,QAAQ,WAAW;GAClB;GACA,UAAU,IAAI,IACb,SAAS,KAAK,YAAY,CAAC,QAAQ,MAAM,QAAQ,QAAkB,CAAC,CACrE;GACA;GACA;GACA;EACD,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"compile.js","names":[],"sources":["../../src/compiler/compile.ts"],"sourcesContent":["import {\n\tFILE_EXTENSIONS,\n\tINDEX_EXTENSIONS,\n\tRESOLVE_EXTENSIONS,\n\tTEMPLATE_FORMAT,\n} from '../constants';\nimport type { CompilePlugin } from '../plugins';\nimport type { PluginData } from '../runtime/chunks';\nimport { toSpecifier } from '../utils/path';\nimport { createResolver, type Resolver } from '../utils/resolver';\nimport { bundleAssets } from './bundle';\nimport type { Chunks, PartialChunk } from './chunks';\nimport { linkDependencies } from './dependencies';\nimport { emitSource } from './emit';\nimport {\n\tassertCompileOptions,\n\tassertDirectories,\n\tassertEntry,\n\tresolvePaths,\n} from './options';\nimport {\n\tcreatePluginContexts,\n\tendCompilePlugins,\n\ttype RuntimeRequest,\n\trunCompilePlugins,\n\tsortPlugins,\n} from './plugins';\nimport { precompileTemplates } from './precompile';\nimport type { RsbuildOptions } from './rsbuild';\nimport {\n\ttype BundledRuntime,\n\tbundleRuntimes,\n\ttype RuntimeBundle,\n} from './runtimes';\nimport { scan } from './scan';\nimport { validateTemplateXml } from './validate';\n\nexport interface CompileTemplateOptions {\n\troot?: string;\n\tentry?: string;\n\talias?: Record<string, string>;\n\tplugins?: CompilePlugin[];\n\t/** Rsbuild config for bundling scripts and styles, merged over the defaults. */\n\trsbuild?: RsbuildOptions;\n\t/** Called with the warnings of plugins, `console.warn` by default. */\n\tonWarn?: (message: string) => void;\n}\n\nexport interface CompiledTemplate {\n\t/** Version of the compiled output, checked by the runtime. */\n\tformat: number;\n\tchunks: Chunks;\n\t/** Templates provided by plugins, by partial name. */\n\tpluginPartials: Map<string, object>;\n\t/** Data provided by plugins, by plugin name and data name. */\n\tpluginData: PluginData;\n\t/** Runtime halves of the plugins, bundled. */\n\tbundledPlugins: BundledRuntime[];\n\tentry: string;\n\t/** The ES module to render the template with, it imports nothing. */\n\tsource: string;\n}\n\n/**\n * scan imports -> compile plugins -> validate dependencies -> precompile\n * templates -> bundle assets and plugin runtimes -> emit module source.\n */\nexport async function compileTemplate(\n\toptions: CompileTemplateOptions = {},\n): Promise<CompiledTemplate> {\n\tassertCompileOptions(options);\n\tawait assertDirectories(options);\n\n\tconst prepared = await prepareTemplate(options);\n\t// two builds of their own, side by side, an error of the scripts and styles first\n\tconst [assets, runtimes] = await Promise.allSettled([\n\t\tbundleAssets(\n\t\t\tprepared.chunks,\n\t\t\tprepared.root,\n\t\t\toptions.rsbuild,\n\t\t\tprepared.dependencies,\n\t\t),\n\t\tbundleRuntimes(prepared.root, prepared.runtimes),\n\t]);\n\tif (assets.status === 'rejected') {\n\t\tthrow assets.reason;\n\t}\n\tif (runtimes.status === 'rejected') {\n\t\tthrow runtimes.reason;\n\t}\n\treturn finishTemplate(prepared, runtimes.value);\n}\n\n/** A template compiled up to the bundling of its scripts, styles and plugin runtimes. */\nexport interface PreparedTemplate {\n\troot: string;\n\t/** Id of the entry template. */\n\tentry: string;\n\tchunks: Chunks;\n\tpartials: PartialChunk[];\n\tpluginData: PluginData;\n\t/** The runtime halves of the plugins, to bundle. */\n\truntimes: RuntimeRequest[];\n\t/** The entries each script entry depends on. */\n\tdependencies: Map<string, string[]>;\n}\n\nexport interface PrepareOptions {\n\t/**\n\t * Called with every template and json file before it is read, and the files\n\t * plugins add, even when compiling fails.\n\t */\n\tonRead?: (file: string) => void;\n\t/** Whether the template is compiled again on changes, told to plugins. */\n\twatch?: boolean;\n\t/**\n\t * The resolver to reuse between compilations, cleared when files change,\n\t * see `createTemplateResolver`. A new one without it.\n\t */\n\tresolver?: Resolver;\n}\n\n/** The resolver of the imports of the templates, for the root and aliases of the options. */\nexport function createTemplateResolver(\n\toptions: CompileTemplateOptions,\n): Resolver {\n\treturn createResolver({\n\t\troot: resolvePaths(options).root,\n\t\talias: options.alias ?? {},\n\t\textensions: {\n\t\t\tindex: [...INDEX_EXTENSIONS],\n\t\t\tfile: [...FILE_EXTENSIONS],\n\t\t\tresolve: [...RESOLVE_EXTENSIONS],\n\t\t},\n\t});\n}\n\n/** Everything but bundling the scripts, styles and plugin runtimes, for validated options. */\nexport async function prepareTemplate(\n\toptions: CompileTemplateOptions = {},\n\t{\n\t\tonRead,\n\t\twatch = false,\n\t\tresolver = createTemplateResolver(options),\n\t}: PrepareOptions = {},\n): Promise<PreparedTemplate> {\n\tconst { root, entry } = resolvePaths(options);\n\tconst { onWarn = console.warn } = options;\n\tconst plugins = sortPlugins(options.plugins ?? []);\n\n\tonRead?.(entry);\n\tawait assertEntry(options);\n\n\tconst contexts = createPluginContexts(plugins, {\n\t\troot,\n\t\tentry,\n\t\twatch,\n\t\tresolver,\n\t\tonRead,\n\t\tonWarn,\n\t});\n\n\tlet prepared: PreparedTemplate;\n\ttry {\n\t\tconst { chunks, templates, requirements } = await scan(entry, {\n\t\t\troot,\n\t\t\tresolver,\n\t\t\tonRead,\n\t\t});\n\n\t\tconst {\n\t\t\tpartials,\n\t\t\tdata: pluginData,\n\t\t\truntimes,\n\t\t} = await runCompilePlugins(plugins, chunks, contexts);\n\t\tconst dependencies = linkDependencies(chunks, requirements);\n\n\t\t// always, after the plugins changed the templates and provided theirs, the\n\t\t// options of the rendered output do not turn it off\n\t\tfor (const template of templates) {\n\t\t\tvalidateTemplateXml(template.parsed, toSpecifier(root, template.path));\n\t\t}\n\t\tfor (const partial of partials) {\n\t\t\tvalidateTemplateXml(partial.parsed, partial.name, partial.plugin);\n\t\t}\n\n\t\tprecompileTemplates([...templates, ...partials]);\n\n\t\tprepared = {\n\t\t\troot,\n\t\t\tentry: toSpecifier(root, entry),\n\t\t\tchunks,\n\t\t\tpartials,\n\t\t\tpluginData,\n\t\t\truntimes,\n\t\t\tdependencies,\n\t\t};\n\t} catch (error) {\n\t\tawait endCompilePlugins(plugins, contexts, error);\n\t\tthrow error;\n\t}\n\n\tawait endCompilePlugins(plugins, contexts);\n\treturn prepared;\n}\n\n/** Emits the module source of a template whose scripts, styles and runtimes are bundled. */\nexport function finishTemplate(\n\t{ entry, chunks, partials, pluginData }: PreparedTemplate,\n\tbundle: RuntimeBundle | undefined,\n): CompiledTemplate {\n\tconst pluginPartials = new Map(\n\t\tpartials.map((partial) => [partial.name, partial.spec as object]),\n\t);\n\n\treturn {\n\t\tformat: TEMPLATE_FORMAT,\n\t\tchunks,\n\t\tpluginPartials,\n\t\tpluginData,\n\t\tbundledPlugins: bundle?.plugins ?? [],\n\t\tentry,\n\t\tsource: emitSource({\n\t\t\tchunks,\n\t\t\tpartials: new Map(\n\t\t\t\tpartials.map((partial) => [partial.name, partial.compiled as string]),\n\t\t\t),\n\t\t\tpluginData,\n\t\t\tbundle,\n\t\t\tentry,\n\t\t}),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmEA,eAAsB,gBACrB,UAAkC,CAAC,GACP;CAC5B,qBAAqB,OAAO;CAC5B,MAAM,kBAAkB,OAAO;CAE/B,MAAM,WAAW,MAAM,gBAAgB,OAAO;CAE9C,MAAM,CAAC,QAAQ,YAAY,MAAM,QAAQ,WAAW,CACnD,aACC,SAAS,QACT,SAAS,MACT,QAAQ,SACR,SAAS,YACV,GACA,eAAe,SAAS,MAAM,SAAS,QAAQ,CAChD,CAAC;CACD,IAAI,OAAO,WAAW,YACrB,MAAM,OAAO;CAEd,IAAI,SAAS,WAAW,YACvB,MAAM,SAAS;CAEhB,OAAO,eAAe,UAAU,SAAS,KAAK;AAC/C;;AAgCA,SAAgB,uBACf,SACW;CACX,OAAO,eAAe;EACrB,MAAM,aAAa,OAAO,CAAC,CAAC;EAC5B,OAAO,QAAQ,SAAS,CAAC;EACzB,YAAY;GACX,OAAO,CAAC,GAAG,gBAAgB;GAC3B,MAAM,CAAC,GAAG,eAAe;GACzB,SAAS,CAAC,GAAG,kBAAkB;EAChC;CACD,CAAC;AACF;;AAGA,eAAsB,gBACrB,UAAkC,CAAC,GACnC,EACC,QACA,QAAQ,OACR,WAAW,uBAAuB,OAAO,MACtB,CAAC,GACO;CAC5B,MAAM,EAAE,MAAM,UAAU,aAAa,OAAO;CAC5C,MAAM,EAAE,SAAS,QAAQ,SAAS;CAClC,MAAM,UAAU,YAAY,QAAQ,WAAW,CAAC,CAAC;CAEjD,SAAS,KAAK;CACd,MAAM,YAAY,OAAO;CAEzB,MAAM,WAAW,qBAAqB,SAAS;EAC9C;EACA;EACA;EACA;EACA;EACA;CACD,CAAC;CAED,IAAI;CACJ,IAAI;EACH,MAAM,EAAE,QAAQ,WAAW,iBAAiB,MAAM,KAAK,OAAO;GAC7D;GACA;GACA;EACD,CAAC;EAED,MAAM,EACL,UACA,MAAM,YACN,aACG,MAAM,kBAAkB,SAAS,QAAQ,QAAQ;EACrD,MAAM,eAAe,iBAAiB,QAAQ,YAAY;EAI1D,KAAK,MAAM,YAAY,WACtB,oBAAoB,SAAS,QAAQ,YAAY,MAAM,SAAS,IAAI,CAAC;EAEtE,KAAK,MAAM,WAAW,UACrB,oBAAoB,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,MAAM;EAGjE,oBAAoB,CAAC,GAAG,WAAW,GAAG,QAAQ,CAAC;EAE/C,WAAW;GACV;GACA,OAAO,YAAY,MAAM,KAAK;GAC9B;GACA;GACA;GACA;GACA;EACD;CACD,SAAS,OAAO;EACf,MAAM,kBAAkB,SAAS,UAAU,KAAK;EAChD,MAAM;CACP;CAEA,MAAM,kBAAkB,SAAS,QAAQ;CACzC,OAAO;AACR;;AAGA,SAAgB,eACf,EAAE,OAAO,QAAQ,UAAU,cAC3B,QACmB;CAKnB,OAAO;EACN,QAAA;EACA;EACA,oBAP0B,IAC1B,SAAS,KAAK,YAAY,CAAC,QAAQ,MAAM,QAAQ,IAAc,CAAC,CAMhE;EACA;EACA,gBAAgB,QAAQ,WAAW,CAAC;EACpC;EACA,QAAQ,WAAW;GAClB;GACA,UAAU,IAAI,IACb,SAAS,KAAK,YAAY,CAAC,QAAQ,MAAM,QAAQ,QAAkB,CAAC,CACrE;GACA;GACA;GACA;EACD,CAAC;CACF;AACD"}
@@ -0,0 +1,8 @@
1
+ //#region src/compiler/evaluate.d.ts
2
+ /**
3
+ * The value of a JavaScript expression generated by the compiler, a
4
+ * Handlebars spec or the bundled runtimes, as the compiled module has it.
5
+ */
6
+ export declare function evaluate<T>(expression: string): T;
7
+ //#endregion
8
+ //# sourceMappingURL=evaluate.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { compileFunction } from "node:vm";
2
+ //#region src/compiler/evaluate.ts
3
+ /**
4
+ * The value of a JavaScript expression generated by the compiler, a
5
+ * Handlebars spec or the bundled runtimes, as the compiled module has it.
6
+ */
7
+ function evaluate(expression) {
8
+ return compileFunction(`return ${expression};`, []).apply(null);
9
+ }
10
+ //#endregion
11
+ export { evaluate };
12
+
13
+ //# sourceMappingURL=evaluate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.js","names":[],"sources":["../../src/compiler/evaluate.ts"],"sourcesContent":["import { compileFunction } from 'node:vm';\n\n/**\n * The value of a JavaScript expression generated by the compiler, a\n * Handlebars spec or the bundled runtimes, as the compiled module has it.\n */\nexport function evaluate<T>(expression: string): T {\n\treturn compileFunction(`return ${expression};`, []).apply(null) as T;\n}\n"],"mappings":";;;;;;AAMA,SAAgB,SAAY,YAAuB;CAClD,OAAO,gBAAgB,UAAU,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI;AAC/D"}
@@ -1,5 +1,5 @@
1
1
  import { RsbuildOptions } from "./rsbuild.js";
2
- import { CompileTemplateOptions, CompiledTemplate, PrepareOptions, PreparedTemplate, compileTemplate, finishTemplate, prepareTemplate } from "./compile.js";
2
+ import { CompileTemplateOptions, CompiledTemplate, PrepareOptions, PreparedTemplate, compileTemplate, createTemplateResolver, finishTemplate, prepareTemplate } from "./compile.js";
3
3
  import { CompileError } from "./errors.js";
4
4
  import { TemplateWatcher, WatchTemplateOptions, watchTemplate } from "./watch.js";
5
- export { CompileError, CompileTemplateOptions, CompiledTemplate, PrepareOptions, PreparedTemplate, type RsbuildOptions, TemplateWatcher, WatchTemplateOptions, compileTemplate, finishTemplate, prepareTemplate, watchTemplate };
5
+ export { CompileError, CompileTemplateOptions, CompiledTemplate, PrepareOptions, PreparedTemplate, type RsbuildOptions, TemplateWatcher, WatchTemplateOptions, compileTemplate, createTemplateResolver, finishTemplate, prepareTemplate, watchTemplate };
@@ -1,4 +1,4 @@
1
1
  import { CompileError } from "./errors.js";
2
- import { compileTemplate, finishTemplate, prepareTemplate } from "./compile.js";
2
+ import { compileTemplate, createTemplateResolver, finishTemplate, prepareTemplate } from "./compile.js";
3
3
  import { watchTemplate } from "./watch.js";
4
- export { CompileError, compileTemplate, finishTemplate, prepareTemplate, watchTemplate };
4
+ export { CompileError, compileTemplate, createTemplateResolver, finishTemplate, prepareTemplate, watchTemplate };
@@ -1,7 +1,7 @@
1
1
  import { CompilePlugin, JsonValue, PluginContext } from "../plugins/index.js";
2
2
  import { PluginData } from "../runtime/chunks.js";
3
- import { Chunks, PartialChunk } from "./chunks.js";
4
3
  import { Resolver } from "../utils/resolver.js";
4
+ import { Chunks, PartialChunk } from "./chunks.js";
5
5
  //#region src/compiler/plugins.d.ts
6
6
  /** The runtime half of a compile plugin, to be bundled. */
7
7
  export interface RuntimeRequest {