@useinsider/ab-components 0.0.164 → 0.0.165
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/ab-components.cjs.js +1 -1
- package/dist/ab-components.cjs.js.map +1 -1
- package/dist/ab-components.es.js +1 -1
- package/dist/ab-components.iife.js +1 -1
- package/dist/ab-components.iife.js.map +1 -1
- package/dist/ab-components.umd.js +1 -1
- package/dist/ab-components.umd.js.map +1 -1
- package/dist/{index-BZUS_VPR.js → index-BxIHyFOY.js} +4 -3
- package/dist/index-BxIHyFOY.js.map +1 -0
- package/dist/index.d.ts +11 -1
- package/dist/{liquid-CT8iyeJr.js → liquid-DiX-YF4w.js} +2 -2
- package/dist/{liquid-CT8iyeJr.js.map → liquid-DiX-YF4w.js.map} +1 -1
- package/package.json +1 -1
- package/dist/index-BZUS_VPR.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -2483,6 +2483,7 @@ placeholder: string;
|
|
|
2483
2483
|
language: keyof ReturnType<typeof useValidators>;
|
|
2484
2484
|
disableValidation: boolean;
|
|
2485
2485
|
liquidVariables: LiquidVariable[];
|
|
2486
|
+
liquidCompletionVariables: LiquidVariable[];
|
|
2486
2487
|
editorOptions: editor.IStandaloneEditorConstructionOptions;
|
|
2487
2488
|
errorGlyph: boolean;
|
|
2488
2489
|
}, {}, {}, {}, string, ComponentProvideOptions, false, {
|
|
@@ -2499,9 +2500,16 @@ export declare interface MonacoEditorProps {
|
|
|
2499
2500
|
*/
|
|
2500
2501
|
monacoVsPath?: string;
|
|
2501
2502
|
/**
|
|
2502
|
-
*
|
|
2503
|
+
* Known dynamic variables when `language` is `liquid`. The unknown-variable check
|
|
2504
|
+
* uses them, and autocomplete suggests them when `liquidCompletionVariables` is omitted.
|
|
2503
2505
|
*/
|
|
2504
2506
|
liquidVariables?: LiquidVariable[];
|
|
2507
|
+
/**
|
|
2508
|
+
* Variables suggested by autocomplete when `language` is `liquid`. When omitted,
|
|
2509
|
+
* autocomplete suggests `liquidVariables`. An empty list suggests no variable.
|
|
2510
|
+
* The unknown-variable check always uses `liquidVariables`.
|
|
2511
|
+
*/
|
|
2512
|
+
liquidCompletionVariables?: LiquidVariable[];
|
|
2505
2513
|
/**
|
|
2506
2514
|
* Per-consumer Monaco options merged over the shared defaults (e.g. disabling
|
|
2507
2515
|
* the minimap). `language`/`value` are always owned by the component.
|
|
@@ -2974,6 +2982,7 @@ placeholder: string;
|
|
|
2974
2982
|
language: keyof ReturnType<useValidators>;
|
|
2975
2983
|
disableValidation: boolean;
|
|
2976
2984
|
liquidVariables: LiquidVariable[];
|
|
2985
|
+
liquidCompletionVariables: LiquidVariable[];
|
|
2977
2986
|
editorOptions: editor.IStandaloneEditorConstructionOptions;
|
|
2978
2987
|
errorGlyph: boolean;
|
|
2979
2988
|
}, false, {}, {}, GlobalComponents, GlobalDirectives, string, {
|
|
@@ -3002,6 +3011,7 @@ placeholder: string;
|
|
|
3002
3011
|
language: keyof ReturnType<useValidators>;
|
|
3003
3012
|
disableValidation: boolean;
|
|
3004
3013
|
liquidVariables: LiquidVariable[];
|
|
3014
|
+
liquidCompletionVariables: LiquidVariable[];
|
|
3005
3015
|
editorOptions: editor.IStandaloneEditorConstructionOptions;
|
|
3006
3016
|
errorGlyph: boolean;
|
|
3007
3017
|
}> | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as f } from "./index-
|
|
1
|
+
import { L as f } from "./index-BxIHyFOY.js";
|
|
2
2
|
const g = new f(), h = /* @__PURE__ */ new Set(["if", "unless", "for", "case", "capture", "comment", "raw", "tablerow"]), w = {
|
|
3
3
|
endif: "if",
|
|
4
4
|
endunless: "unless",
|
|
@@ -149,4 +149,4 @@ export {
|
|
|
149
149
|
S as findUnknownVariables,
|
|
150
150
|
u as positionAt
|
|
151
151
|
};
|
|
152
|
-
//# sourceMappingURL=liquid-
|
|
152
|
+
//# sourceMappingURL=liquid-DiX-YF4w.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liquid-CT8iyeJr.js","sources":["../src/components/MonacoEditor/validators/liquid.ts"],"sourcesContent":["// cspell:ignore liquidjs endunless endcapture endcomment endraw tablerow endtablerow elsif forloop tablerowloop\nimport type { editor as Editor } from 'monaco-editor';\nimport { Liquid } from 'liquidjs';\n\n// Parse-only engine: validates Liquid syntax, mirroring the liquid.js grammar\n// Pandora renders with. Used as a fallback for expression/filter errors that the\n// structural scan below doesn't cover. Undefined variables/filters are NOT errors\n// here — those only surface server-side at render time.\nconst engine = new Liquid();\n\ninterface LiquidErrorInfo {\n line: number;\n column: number;\n message: string;\n}\n\ninterface LiquidLikeError {\n message?: string;\n token?: { getPosition?: () => [number, number] };\n}\n\n// Block tags that must be closed by a matching `end<tag>`.\nconst BLOCK_OPENERS = new Set(['if', 'unless', 'for', 'case', 'capture', 'comment', 'raw', 'tablerow']);\nconst BLOCK_CLOSERS: Record<string, string> = {\n endif: 'if',\n endunless: 'unless',\n endfor: 'for',\n endcase: 'case',\n endcapture: 'capture',\n endcomment: 'comment',\n endraw: 'raw',\n endtablerow: 'tablerow',\n};\n\nexport function positionAt(value: string, index: number): { line: number; column: number } {\n let line = 1;\n let lastBreak = -1;\n\n for (let i = 0; i < index; i += 1) {\n if (value[i] === '\\n') {\n line += 1;\n lastBreak = i;\n }\n }\n\n return { line, column: index - lastBreak };\n}\n\n/**\n * Structural scan reporting EVERY broken delimiter and unbalanced block tag, so\n * each faulty line gets its own marker. `liquidjs.parse` only throws on the\n * first error, which is why we can't rely on it for multi-error highlighting.\n */\nexport function findStructuralErrors(value: string): LiquidErrorInfo[] {\n const errors: LiquidErrorInfo[] = [];\n const blockStack: { tag: string; index: number }[] = [];\n const delimiters = /\\{\\{|\\}\\}|\\{%|%\\}/g;\n\n let openType: '{{' | '{%' | null = null;\n let openIndex = -1;\n // While inside `{% comment %}`/`{% raw %}`, ignore inner block tags.\n let rawBlock: string | null = null;\n let match = delimiters.exec(value);\n\n while (match !== null) {\n const token = match[0];\n\n if (token === '{{' || token === '{%') {\n if (openType) {\n const pos = positionAt(value, openIndex);\n\n errors.push({ ...pos, message: `Unclosed ${openType} — '${openType === '{{' ? '}}' : '%}'}' expected.` });\n }\n\n openType = token;\n openIndex = match.index;\n } else if (openType) {\n const expected = openType === '{{' ? '}}' : '%}';\n\n if (token !== expected) {\n const pos = positionAt(value, openIndex);\n\n errors.push({ ...pos, message: `Mismatched delimiter — '${expected}' expected.` });\n } else if (openType === '{%') {\n const word = value.slice(openIndex + 2, match.index).trim().split(/\\s+/)[0] ?? '';\n\n if (rawBlock) {\n if (word === `end${rawBlock}`) {\n blockStack.pop();\n rawBlock = null;\n }\n } else if (BLOCK_OPENERS.has(word)) {\n blockStack.push({ tag: word, index: openIndex });\n\n if (word === 'comment' || word === 'raw') {\n rawBlock = word;\n }\n } else {\n const opener = BLOCK_CLOSERS[word];\n\n if (opener) {\n if (blockStack.length > 0 && blockStack[blockStack.length - 1].tag === opener) {\n blockStack.pop();\n } else {\n const pos = positionAt(value, openIndex);\n\n errors.push({ ...pos, message: `Unexpected {% ${word} %}.` });\n }\n }\n }\n }\n\n openType = null;\n openIndex = -1;\n }\n\n match = delimiters.exec(value);\n }\n\n if (openType) {\n const pos = positionAt(value, openIndex);\n\n errors.push({ ...pos, message: `Unclosed ${openType}.` });\n }\n\n blockStack.forEach(block => {\n const pos = positionAt(value, block.index);\n\n errors.push({ ...pos, message: `Unclosed {% ${block.tag} %} — '{% end${block.tag} %}' missing.` });\n });\n\n return errors;\n}\n\n// Liquid built-ins / literals that are valid inside `{{ }}` without being a\n// dynamic-content variable or a locally-assigned one.\nconst BUILTIN_VARS = new Set(['true', 'false', 'nil', 'null', 'empty', 'blank', 'forloop', 'tablerowloop']);\n\n// Variables introduced locally by the template itself (so they're not \"unknown\").\nexport function collectLocalVariables(value: string): Set<string> {\n const locals = new Set<string>();\n const assignRe = /\\{%-?\\s*(?:assign|capture)\\s+([a-zA-Z_]\\w*)/g;\n const loopRe = /\\{%-?\\s*(?:for|tablerow)\\s+([a-zA-Z_]\\w*)\\s+in\\b/g;\n\n let match = assignRe.exec(value);\n\n while (match !== null) {\n locals.add(match[1]);\n match = assignRe.exec(value);\n }\n\n match = loopRe.exec(value);\n\n while (match !== null) {\n locals.add(match[1]);\n match = loopRe.exec(value);\n }\n\n return locals;\n}\n\n/**\n * Flags `{{ output }}` whose variable is neither a known dynamic-content key, a\n * locally-assigned variable, nor a built-in/literal. Skipped entirely when no\n * known keys are supplied (e.g. the dynamic-content list hasn't loaded yet), to\n * avoid false positives.\n */\nexport function findUnknownVariables(value: string, knownKeys: string[]): LiquidErrorInfo[] {\n const errors: LiquidErrorInfo[] = [];\n const known = new Set<string>(BUILTIN_VARS);\n\n knownKeys.forEach(key => {\n known.add(key);\n\n const [root] = key.split('.');\n\n if (root) {\n known.add(root);\n }\n });\n\n collectLocalVariables(value).forEach(local => known.add(local));\n\n const outputRe = /\\{\\{-?([\\s\\S]*?)-?\\}\\}/g;\n let match = outputRe.exec(value);\n\n while (match !== null) {\n const expression = (match[1].split('|')[0] ?? '').trim();\n const token = expression.match(/^[a-zA-Z_][\\w.]*/)?.[0];\n\n if (token) {\n const [root] = token.split('.');\n\n if (!known.has(token) && !known.has(root)) {\n errors.push({ ...positionAt(value, match.index), message: `Unknown dynamic content variable: ${token}` });\n }\n }\n\n match = outputRe.exec(value);\n }\n\n return errors;\n}\n\nfunction getEnginePosition(error: unknown): { line: number; column: number } {\n const token = (error as LiquidLikeError)?.token;\n\n if (token && typeof token.getPosition === 'function') {\n const [line, column] = token.getPosition();\n\n return { line: line || 1, column: column || 1 };\n }\n\n const message = (error as LiquidLikeError)?.message ?? '';\n const match = message.match(/line:(\\d+),\\s*col:(\\d+)/);\n\n if (match) {\n return { line: Number(match[1]), column: Number(match[2]) };\n }\n\n return { line: 1, column: 1 };\n}\n\nconst liquidValidator = (\n editor: Editor.IStandaloneCodeEditor,\n monaco: typeof import('monaco-editor/esm/vs/editor/editor.api'),\n knownKeys: string[] = []\n) => {\n const model = editor.getModel();\n\n if (!model) {\n return {\n valid: true,\n results: [],\n };\n }\n\n const value = editor.getValue();\n const toMarker = (info: LiquidErrorInfo): Editor.IMarkerData => ({\n startLineNumber: info.line,\n endLineNumber: info.line,\n startColumn: info.column,\n endColumn: info.column + 1,\n message: info.message,\n severity: monaco.MarkerSeverity.Error,\n });\n\n // 1. Structural scan + unknown-variable scan — one marker per broken line.\n const structural = [\n ...findStructuralErrors(value),\n ...(knownKeys.length > 0 ? findUnknownVariables(value, knownKeys) : []),\n ];\n\n if (structural.length > 0) {\n const markers = structural.map(toMarker);\n\n monaco.editor.setModelMarkers(model, 'owner', markers);\n\n return {\n valid: false,\n results: markers,\n };\n }\n\n // 2. Fallback: liquidjs catches expression/filter errors (single error).\n try {\n engine.parse(value);\n\n monaco.editor.setModelMarkers(model, 'owner', []);\n\n return {\n valid: true,\n results: [],\n };\n } catch (error) {\n const marker = toMarker({\n ...getEnginePosition(error),\n message: (error as LiquidLikeError)?.message ?? 'Invalid Liquid syntax',\n });\n\n monaco.editor.setModelMarkers(model, 'owner', [marker]);\n\n return {\n valid: false,\n results: [marker],\n };\n }\n};\n\nexport default liquidValidator;\n"],"names":["engine","Liquid","BLOCK_OPENERS","BLOCK_CLOSERS","positionAt","value","index","line","lastBreak","i","findStructuralErrors","errors","blockStack","delimiters","openType","openIndex","rawBlock","match","token","pos","expected","word","opener","block","BUILTIN_VARS","collectLocalVariables","locals","assignRe","loopRe","findUnknownVariables","knownKeys","known","key","root","local","outputRe","_a","getEnginePosition","error","column","liquidValidator","editor","monaco","model","toMarker","info","structural","markers","marker"],"mappings":";AAQA,MAAMA,IAAS,IAAIC,EAAA,GAcbC,IAAgB,oBAAI,IAAI,CAAC,MAAM,UAAU,OAAO,QAAQ,WAAW,WAAW,OAAO,UAAU,CAAC,GAChGC,IAAwC;AAAA,EAC1C,OAAO;AAAA,EACP,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,Y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AASJ,EAAS;AAAA,MACpB,GAAGP,EAAkBC,CAAK;AAAA,MAC1B,UAAUA,KAAA,gBAAAA,EAA2B,YAAW;AAAA,IAAA,CACnD;AAED,WAAAI,EAAO,OAAO,gBAAgBC,GAAO,SAAS,CAACK,CAAM,CAAC,GAE/C;AAAA,MACH,OAAO;AAAA,MACP,SAAS,CAACA,CAAM;AAAA,IAAA;AAAA,EAExB;AACJ;"}
|
|
1
|
+
{"version":3,"file":"liquid-DiX-YF4w.js","sources":["../src/components/MonacoEditor/validators/liquid.ts"],"sourcesContent":["// cspell:ignore liquidjs endunless endcapture endcomment endraw tablerow endtablerow elsif forloop tablerowloop\nimport type { editor as Editor } from 'monaco-editor';\nimport { Liquid } from 'liquidjs';\n\n// Parse-only engine: validates Liquid syntax, mirroring the liquid.js grammar\n// Pandora renders with. Used as a fallback for expression/filter errors that the\n// structural scan below doesn't cover. Undefined variables/filters are NOT errors\n// here — those only surface server-side at render time.\nconst engine = new Liquid();\n\ninterface LiquidErrorInfo {\n line: number;\n column: number;\n message: string;\n}\n\ninterface LiquidLikeError {\n message?: string;\n token?: { getPosition?: () => [number, number] };\n}\n\n// Block tags that must be closed by a matching `end<tag>`.\nconst BLOCK_OPENERS = new Set(['if', 'unless', 'for', 'case', 'capture', 'comment', 'raw', 'tablerow']);\nconst BLOCK_CLOSERS: Record<string, string> = {\n endif: 'if',\n endunless: 'unless',\n endfor: 'for',\n endcase: 'case',\n endcapture: 'capture',\n endcomment: 'comment',\n endraw: 'raw',\n endtablerow: 'tablerow',\n};\n\nexport function positionAt(value: string, index: number): { line: number; column: number } {\n let line = 1;\n let lastBreak = -1;\n\n for (let i = 0; i < index; i += 1) {\n if (value[i] === '\\n') {\n line += 1;\n lastBreak = i;\n }\n }\n\n return { line, column: index - lastBreak };\n}\n\n/**\n * Structural scan reporting EVERY broken delimiter and unbalanced block tag, so\n * each faulty line gets its own marker. `liquidjs.parse` only throws on the\n * first error, which is why we can't rely on it for multi-error highlighting.\n */\nexport function findStructuralErrors(value: string): LiquidErrorInfo[] {\n const errors: LiquidErrorInfo[] = [];\n const blockStack: { tag: string; index: number }[] = [];\n const delimiters = /\\{\\{|\\}\\}|\\{%|%\\}/g;\n\n let openType: '{{' | '{%' | null = null;\n let openIndex = -1;\n // While inside `{% comment %}`/`{% raw %}`, ignore inner block tags.\n let rawBlock: string | null = null;\n let match = delimiters.exec(value);\n\n while (match !== null) {\n const token = match[0];\n\n if (token === '{{' || token === '{%') {\n if (openType) {\n const pos = positionAt(value, openIndex);\n\n errors.push({ ...pos, message: `Unclosed ${openType} — '${openType === '{{' ? '}}' : '%}'}' expected.` });\n }\n\n openType = token;\n openIndex = match.index;\n } else if (openType) {\n const expected = openType === '{{' ? '}}' : '%}';\n\n if (token !== expected) {\n const pos = positionAt(value, openIndex);\n\n errors.push({ ...pos, message: `Mismatched delimiter — '${expected}' expected.` });\n } else if (openType === '{%') {\n const word = value.slice(openIndex + 2, match.index).trim().split(/\\s+/)[0] ?? '';\n\n if (rawBlock) {\n if (word === `end${rawBlock}`) {\n blockStack.pop();\n rawBlock = null;\n }\n } else if (BLOCK_OPENERS.has(word)) {\n blockStack.push({ tag: word, index: openIndex });\n\n if (word === 'comment' || word === 'raw') {\n rawBlock = word;\n }\n } else {\n const opener = BLOCK_CLOSERS[word];\n\n if (opener) {\n if (blockStack.length > 0 && blockStack[blockStack.length - 1].tag === opener) {\n blockStack.pop();\n } else {\n const pos = positionAt(value, openIndex);\n\n errors.push({ ...pos, message: `Unexpected {% ${word} %}.` });\n }\n }\n }\n }\n\n openType = null;\n openIndex = -1;\n }\n\n match = delimiters.exec(value);\n }\n\n if (openType) {\n const pos = positionAt(value, openIndex);\n\n errors.push({ ...pos, message: `Unclosed ${openType}.` });\n }\n\n blockStack.forEach(block => {\n const pos = positionAt(value, block.index);\n\n errors.push({ ...pos, message: `Unclosed {% ${block.tag} %} — '{% end${block.tag} %}' missing.` });\n });\n\n return errors;\n}\n\n// Liquid built-ins / literals that are valid inside `{{ }}` without being a\n// dynamic-content variable or a locally-assigned one.\nconst BUILTIN_VARS = new Set(['true', 'false', 'nil', 'null', 'empty', 'blank', 'forloop', 'tablerowloop']);\n\n// Variables introduced locally by the template itself (so they're not \"unknown\").\nexport function collectLocalVariables(value: string): Set<string> {\n const locals = new Set<string>();\n const assignRe = /\\{%-?\\s*(?:assign|capture)\\s+([a-zA-Z_]\\w*)/g;\n const loopRe = /\\{%-?\\s*(?:for|tablerow)\\s+([a-zA-Z_]\\w*)\\s+in\\b/g;\n\n let match = assignRe.exec(value);\n\n while (match !== null) {\n locals.add(match[1]);\n match = assignRe.exec(value);\n }\n\n match = loopRe.exec(value);\n\n while (match !== null) {\n locals.add(match[1]);\n match = loopRe.exec(value);\n }\n\n return locals;\n}\n\n/**\n * Flags `{{ output }}` whose variable is neither a known dynamic-content key, a\n * locally-assigned variable, nor a built-in/literal. Skipped entirely when no\n * known keys are supplied (e.g. the dynamic-content list hasn't loaded yet), to\n * avoid false positives.\n */\nexport function findUnknownVariables(value: string, knownKeys: string[]): LiquidErrorInfo[] {\n const errors: LiquidErrorInfo[] = [];\n const known = new Set<string>(BUILTIN_VARS);\n\n knownKeys.forEach(key => {\n known.add(key);\n\n const [root] = key.split('.');\n\n if (root) {\n known.add(root);\n }\n });\n\n collectLocalVariables(value).forEach(local => known.add(local));\n\n const outputRe = /\\{\\{-?([\\s\\S]*?)-?\\}\\}/g;\n let match = outputRe.exec(value);\n\n while (match !== null) {\n const expression = (match[1].split('|')[0] ?? '').trim();\n const token = expression.match(/^[a-zA-Z_][\\w.]*/)?.[0];\n\n if (token) {\n const [root] = token.split('.');\n\n if (!known.has(token) && !known.has(root)) {\n errors.push({ ...positionAt(value, match.index), message: `Unknown dynamic content variable: ${token}` });\n }\n }\n\n match = outputRe.exec(value);\n }\n\n return errors;\n}\n\nfunction getEnginePosition(error: unknown): { line: number; column: number } {\n const token = (error as LiquidLikeError)?.token;\n\n if (token && typeof token.getPosition === 'function') {\n const [line, column] = token.getPosition();\n\n return { line: line || 1, column: column || 1 };\n }\n\n const message = (error as LiquidLikeError)?.message ?? '';\n const match = message.match(/line:(\\d+),\\s*col:(\\d+)/);\n\n if (match) {\n return { line: Number(match[1]), column: Number(match[2]) };\n }\n\n return { line: 1, column: 1 };\n}\n\nconst liquidValidator = (\n editor: Editor.IStandaloneCodeEditor,\n monaco: typeof import('monaco-editor/esm/vs/editor/editor.api'),\n knownKeys: string[] = []\n) => {\n const model = editor.getModel();\n\n if (!model) {\n return {\n valid: true,\n results: [],\n };\n }\n\n const value = editor.getValue();\n const toMarker = (info: LiquidErrorInfo): Editor.IMarkerData => ({\n startLineNumber: info.line,\n endLineNumber: info.line,\n startColumn: info.column,\n endColumn: info.column + 1,\n message: info.message,\n severity: monaco.MarkerSeverity.Error,\n });\n\n // 1. Structural scan + unknown-variable scan — one marker per broken line.\n const structural = [\n ...findStructuralErrors(value),\n ...(knownKeys.length > 0 ? findUnknownVariables(value, knownKeys) : []),\n ];\n\n if (structural.length > 0) {\n const markers = structural.map(toMarker);\n\n monaco.editor.setModelMarkers(model, 'owner', markers);\n\n return {\n valid: false,\n results: markers,\n };\n }\n\n // 2. Fallback: liquidjs catches expression/filter errors (single error).\n try {\n engine.parse(value);\n\n monaco.editor.setModelMarkers(model, 'owner', []);\n\n return {\n valid: true,\n results: [],\n };\n } catch (error) {\n const marker = toMarker({\n ...getEnginePosition(error),\n message: (error as LiquidLikeError)?.message ?? 'Invalid Liquid syntax',\n });\n\n monaco.editor.setModelMarkers(model, 'owner', [marker]);\n\n return {\n valid: false,\n results: [marker],\n };\n }\n};\n\nexport default liquidValidator;\n"],"names":["engine","Liquid","BLOCK_OPENERS","BLOCK_CLOSERS","positionAt","value","index","line","lastBreak","i","findStructuralErrors","errors","blockStack","delimiters","openType","openIndex","rawBlock","match","token","pos","expected","word","opener","block","BUILTIN_VARS","collectLocalVariables","locals","assignRe","loopRe","findUnknownVariables","knownKeys","known","key","root","local","outputRe","_a","getEnginePosition","error","column","liquidValidator","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