lang-feel 2.0.0 → 2.1.1

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.
@@ -0,0 +1,2 @@
1
+ import { EditorState } from '@codemirror/state';
2
+ export declare function getContextAtPos(state: EditorState, variables: Record<string, any>, pos: number): null | undefined;
package/dist/index.cjs CHANGED
@@ -69,7 +69,7 @@ const keywordCompletions = [contextualKeyword({
69
69
  after: 'InExpressions',
70
70
  keyword: 'return'
71
71
  })];
72
- const dontComplete = ['StringLiteral', 'Identifier', 'LineComment', 'BlockComment'];
72
+ const dontComplete = ['StringLiteral', 'Identifier', 'LineComment', 'BlockComment', 'PathExpression'];
73
73
  function snippetCompletion(snippets) {
74
74
  return autocomplete.ifNotIn(dontComplete, autocomplete.completeFromList(snippets.map(s => ({
75
75
  ...s,
@@ -193,13 +193,13 @@ const feelLanguage = language.LRLanguage.define({
193
193
  */
194
194
  const unaryTestsLanguage = feelLanguage.configure({
195
195
  top: 'UnaryTests'
196
- });
196
+ }, 'FEEL unary tests');
197
197
  /**
198
198
  * Language provider for FEEL Expression
199
199
  */
200
200
  const expressionLanguage = feelLanguage.configure({
201
201
  top: 'Expression'
202
- });
202
+ }, 'FEEL expression');
203
203
  /**
204
204
  * Feel language support for CodeMirror.
205
205
  *
@@ -211,7 +211,7 @@ function feel(config = {}) {
211
211
  contextTracker: lezerFeel.trackVariables(config.context)
212
212
  });
213
213
  const completions = config.completions || [snippetCompletion(snippets), keywordCompletions].flat();
214
- return new language.LanguageSupport(contextualLang, [...completions.map(autocomplete => feelLanguage.data.of({
214
+ return new language.LanguageSupport(contextualLang, [...completions.map(autocomplete => contextualLang.data.of({
215
215
  autocomplete
216
216
  }))]);
217
217
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/snippets.ts","../src/completion.ts","../src/feel.ts"],"sourcesContent":["import { Completion, snippetCompletion } from '@codemirror/autocomplete';\n\n/**\n * A collection of FEEL-related [snippets](#autocomplete.snippet).\n */\nexport const snippets: readonly Completion[] = [\n snippetCompletion('function(${params}) ${body}', {\n label: 'function',\n detail: 'definition',\n type: 'keyword'\n }),\n snippetCompletion('for ${var} in ${collection} return ${value}', {\n label: 'for',\n detail: 'expression',\n type: 'keyword'\n }),\n snippetCompletion('every ${var} in ${collection} satisfies ${condition}', {\n label: 'every',\n detail: 'quantified expression',\n type: 'keyword'\n }),\n snippetCompletion('some ${var} in ${collection} satisfies ${condition}', {\n label: 'some',\n detail: 'quantified expression',\n type: 'keyword'\n }),\n snippetCompletion('if ${condition} then ${value} else ${other value}', {\n label: 'if',\n detail: 'block',\n type: 'keyword'\n }),\n snippetCompletion('{ ${key}: ${value} }', {\n label: 'context',\n detail: 'block',\n type: 'keyword'\n })\n];\n","import { syntaxTree } from '@codemirror/language';\nimport { SyntaxNode } from '@lezer/common';\n\nimport {\n CompletionSource,\n Completion,\n completeFromList,\n ifNotIn\n} from '@codemirror/autocomplete';\n\n\nexport function contextualKeyword(options: {\n before?: string,\n after?: string,\n context: string,\n keyword: string\n}) : CompletionSource {\n\n const {\n context: nodes,\n after,\n before,\n keyword\n } = options;\n\n return ifInside({ nodes, before, after, keyword }, completeFromList([\n { label: keyword, type: 'keyword', boost: 10 }\n ]));\n}\n\nexport const keywordCompletions = [\n contextualKeyword({\n context: 'InExpression',\n keyword: 'in'\n }),\n contextualKeyword({\n context: 'IfExpression',\n keyword: 'then',\n after: 'if',\n before: 'else'\n }),\n contextualKeyword({\n context: 'IfExpression',\n keyword: 'else',\n after: 'then'\n }),\n contextualKeyword({\n context: 'QuantifiedExpression',\n keyword: 'satisfies'\n }),\n contextualKeyword({\n context: 'ForExpression',\n after: 'InExpressions',\n keyword: 'return'\n })\n];\n\nexport const dontComplete = [\n 'StringLiteral', 'Identifier',\n 'LineComment', 'BlockComment'\n];\n\nexport function snippetCompletion(snippets: readonly Completion[]) : CompletionSource {\n return ifNotIn(\n dontComplete, completeFromList(snippets.map(s => ({ ...s, type: 'text' })))\n );\n}\n\nexport function matchLeft(node: SyntaxNode, position: number, nodes: (string|undefined)[]) : SyntaxNode | null {\n return matchChildren(node, position, nodes, -1);\n}\n\nexport function matchRight(node: SyntaxNode, position: number, nodes: (string|undefined)[]) : SyntaxNode | null {\n return matchChildren(node, position, nodes, 1);\n}\n\nexport function matchChildren(node: SyntaxNode, position: number, nodes: (string|undefined)[], direction: 1 | -1) : SyntaxNode | null {\n\n let child = node[direction > 0 ? 'childAfter' : 'childBefore'](position);\n\n while (child) {\n if (nodes.includes(child.name)) {\n return child;\n }\n\n if (child.type.isError && child.firstChild) {\n if (nodes.includes(child.firstChild.name)) {\n return child.firstChild;\n }\n }\n\n child = child[direction > 0 ? 'nextSibling' : 'prevSibling'];\n }\n\n return null;\n}\n\nfunction matchUp(node: SyntaxNode, nodeNames: string | undefined | (string | undefined)[]) {\n\n if (!Array.isArray(nodeNames)) {\n nodeNames = [ nodeNames ];\n }\n\n for (; node; node = node.parent!) {\n if (nodeNames.includes(node.name)) {\n return node;\n }\n\n if (node.type.isTop) {\n break;\n }\n }\n\n return null;\n}\n\nexport function ifInside(options: {\n nodes: string | string[],\n keyword: string,\n before?: string,\n after?: string\n}, source: CompletionSource): CompletionSource {\n\n const {\n nodes,\n before,\n after,\n keyword\n } = options;\n\n return (context) => {\n\n const { state, pos } = context;\n\n const node = matchUp(syntaxTree(state).resolveInner(pos, -1), nodes);\n\n if (!node) {\n return null;\n }\n\n if (matchLeft(node, pos, [ keyword, before ])) {\n return null;\n }\n\n if (matchRight(node, pos, [ keyword, after ])) {\n return null;\n }\n\n if (after && !matchLeft(node, pos, [ after ])) {\n return null;\n }\n\n return source(context);\n };\n}","import {\n parser,\n trackVariables\n} from 'lezer-feel';\n\nimport {\n LRLanguage,\n LanguageSupport,\n delimitedIndent,\n continuedIndent,\n indentNodeProp,\n foldNodeProp,\n foldInside\n} from '@codemirror/language';\n\nimport {\n snippets\n} from './snippets';\n\nimport {\n keywordCompletions,\n snippetCompletion\n} from './completion';\n\nimport {\n CompletionSource\n} from '@codemirror/autocomplete';\n\n\n/**\n * A FEEL language provider based on the\n * [Lezer FEEL parser](https://github.com/nikku/lezer-feel),\n * extended with highlighting and indentation information.\n */\nexport const feelLanguage = LRLanguage.define({\n parser: parser.configure({\n props: [\n indentNodeProp.add({\n 'Context': delimitedIndent({\n closing: '}'\n }),\n 'List FilterExpression': delimitedIndent({\n closing: ']'\n }),\n 'ParenthesizedExpression FunctionInvocation': continuedIndent({\n except: /^\\s*\\)/\n }),\n 'ForExpression QuantifiedExpression IfExpression': continuedIndent({\n except: /^\\s*(then|else|return|satisfies)\\b/\n }),\n 'FunctionDefinition': continuedIndent({\n except: /^\\s*(\\(|\\))/\n })\n }),\n foldNodeProp.add({\n Context: foldInside,\n List: foldInside,\n ParenthesizedExpression: foldInside,\n FunctionDefinition(node) {\n const last = node.getChild(')');\n\n if (!last) return null;\n\n return {\n from: last.to,\n to: node.to\n };\n }\n })\n ]\n }),\n languageData: {\n indentOnInput: /^\\s*(\\)|\\}|\\]|then|else|return|satisfies)$/,\n commentTokens: {\n line: '//',\n block: {\n open: '/*',\n close: '*/'\n }\n }\n }\n});\n\n/**\n * A language provider for FEEL Unary Tests\n */\nexport const unaryTestsLanguage = feelLanguage.configure({ top: 'UnaryTests' });\n\n/**\n * Language provider for FEEL Expression\n */\nexport const expressionLanguage = feelLanguage.configure({ top: 'Expression' });\n\n\n\n/**\n * Feel language support for CodeMirror.\n *\n * Includes [snippet](#lang-feel.snippets)\n */\nexport function feel(config: {\n dialect?: 'expression' | 'unaryTests',\n completions?: CompletionSource[],\n context?: Record<string, any>\n} = {}) {\n const lang = config.dialect === 'unaryTests' ? unaryTestsLanguage : expressionLanguage;\n\n const contextualLang = lang.configure({\n contextTracker: trackVariables(config.context)\n });\n\n const completions = config.completions || [\n snippetCompletion(snippets),\n keywordCompletions,\n ].flat();\n\n return new LanguageSupport(contextualLang, [\n ...(\n completions.map(autocomplete => feelLanguage.data.of({\n autocomplete\n }))\n )\n ]);\n\n}"],"names":["snippets","snippetCompletion","label","detail","type","contextualKeyword","options","context","nodes","after","before","keyword","ifInside","completeFromList","boost","keywordCompletions","dontComplete","ifNotIn","map","s","matchLeft","node","position","matchChildren","matchRight","direction","child","includes","name","isError","firstChild","matchUp","nodeNames","Array","isArray","parent","isTop","source","state","pos","syntaxTree","resolveInner","feelLanguage","LRLanguage","define","parser","configure","props","indentNodeProp","add","delimitedIndent","closing","continuedIndent","except","foldNodeProp","Context","foldInside","List","ParenthesizedExpression","FunctionDefinition","last","getChild","from","to","languageData","indentOnInput","commentTokens","line","block","open","close","unaryTestsLanguage","top","expressionLanguage","feel","config","lang","dialect","contextualLang","contextTracker","trackVariables","completions","flat","LanguageSupport","autocomplete","data","of"],"mappings":";;;;AAEA;;AAEG;MACUA,QAAQ,GAA0B,CAC7CC,8BAAiB,CAAC,6BAA6B,EAAE;AAC/CC,EAAAA,KAAK,EAAE,UAAU;AACjBC,EAAAA,MAAM,EAAE,YAAY;AACpBC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,8BAAiB,CAAC,6CAA6C,EAAE;AAC/DC,EAAAA,KAAK,EAAE,KAAK;AACZC,EAAAA,MAAM,EAAE,YAAY;AACpBC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,8BAAiB,CAAC,sDAAsD,EAAE;AACxEC,EAAAA,KAAK,EAAE,OAAO;AACdC,EAAAA,MAAM,EAAE,uBAAuB;AAC/BC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,8BAAiB,CAAC,qDAAqD,EAAE;AACvEC,EAAAA,KAAK,EAAE,MAAM;AACbC,EAAAA,MAAM,EAAE,uBAAuB;AAC/BC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,8BAAiB,CAAC,mDAAmD,EAAE;AACrEC,EAAAA,KAAK,EAAE,IAAI;AACXC,EAAAA,MAAM,EAAE,OAAO;AACfC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH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AC;AACnDF,IAAAA,YAAAA;GACD,CAAC,CACH,CACF,CAAC,CAAA;AAEJ;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/snippets.ts","../src/completion.ts","../src/feel.ts"],"sourcesContent":["import { Completion, snippetCompletion } from '@codemirror/autocomplete';\n\n/**\n * A collection of FEEL-related [snippets](#autocomplete.snippet).\n */\nexport const snippets: readonly Completion[] = [\n snippetCompletion('function(${params}) ${body}', {\n label: 'function',\n detail: 'definition',\n type: 'keyword'\n }),\n snippetCompletion('for ${var} in ${collection} return ${value}', {\n label: 'for',\n detail: 'expression',\n type: 'keyword'\n }),\n snippetCompletion('every ${var} in ${collection} satisfies ${condition}', {\n label: 'every',\n detail: 'quantified expression',\n type: 'keyword'\n }),\n snippetCompletion('some ${var} in ${collection} satisfies ${condition}', {\n label: 'some',\n detail: 'quantified expression',\n type: 'keyword'\n }),\n snippetCompletion('if ${condition} then ${value} else ${other value}', {\n label: 'if',\n detail: 'block',\n type: 'keyword'\n }),\n snippetCompletion('{ ${key}: ${value} }', {\n label: 'context',\n detail: 'block',\n type: 'keyword'\n })\n];\n","import { syntaxTree } from '@codemirror/language';\nimport { SyntaxNode } from '@lezer/common';\n\nimport {\n CompletionSource,\n Completion,\n completeFromList,\n ifNotIn\n} from '@codemirror/autocomplete';\n\n\nexport function contextualKeyword(options: {\n before?: string,\n after?: string,\n context: string,\n keyword: string\n}) : CompletionSource {\n\n const {\n context: nodes,\n after,\n before,\n keyword\n } = options;\n\n return ifInside({ nodes, before, after, keyword }, completeFromList([\n { label: keyword, type: 'keyword', boost: 10 }\n ]));\n}\n\nexport const keywordCompletions = [\n contextualKeyword({\n context: 'InExpression',\n keyword: 'in'\n }),\n contextualKeyword({\n context: 'IfExpression',\n keyword: 'then',\n after: 'if',\n before: 'else'\n }),\n contextualKeyword({\n context: 'IfExpression',\n keyword: 'else',\n after: 'then'\n }),\n contextualKeyword({\n context: 'QuantifiedExpression',\n keyword: 'satisfies'\n }),\n contextualKeyword({\n context: 'ForExpression',\n after: 'InExpressions',\n keyword: 'return'\n })\n];\n\nexport const dontComplete = [\n 'StringLiteral', 'Identifier',\n 'LineComment', 'BlockComment',\n 'PathExpression'\n];\n\nexport function snippetCompletion(snippets: readonly Completion[]) : CompletionSource {\n return ifNotIn(\n dontComplete, completeFromList(snippets.map(s => ({ ...s, type: 'text' })))\n );\n}\n\nexport function matchLeft(node: SyntaxNode, position: number, nodes: (string|undefined)[]) : SyntaxNode | null {\n return matchChildren(node, position, nodes, -1);\n}\n\nexport function matchRight(node: SyntaxNode, position: number, nodes: (string|undefined)[]) : SyntaxNode | null {\n return matchChildren(node, position, nodes, 1);\n}\n\nexport function matchChildren(node: SyntaxNode, position: number, nodes: (string|undefined)[], direction: 1 | -1) : SyntaxNode | null {\n\n let child = node[direction > 0 ? 'childAfter' : 'childBefore'](position);\n\n while (child) {\n if (nodes.includes(child.name)) {\n return child;\n }\n\n if (child.type.isError && child.firstChild) {\n if (nodes.includes(child.firstChild.name)) {\n return child.firstChild;\n }\n }\n\n child = child[direction > 0 ? 'nextSibling' : 'prevSibling'];\n }\n\n return null;\n}\n\nfunction matchUp(node: SyntaxNode, nodeNames: string | undefined | (string | undefined)[]) {\n\n if (!Array.isArray(nodeNames)) {\n nodeNames = [ nodeNames ];\n }\n\n for (; node; node = node.parent!) {\n if (nodeNames.includes(node.name)) {\n return node;\n }\n\n if (node.type.isTop) {\n break;\n }\n }\n\n return null;\n}\n\nexport function ifInside(options: {\n nodes: string | string[],\n keyword: string,\n before?: string,\n after?: string\n}, source: CompletionSource): CompletionSource {\n\n const {\n nodes,\n before,\n after,\n keyword\n } = options;\n\n return (context) => {\n\n const { state, pos } = context;\n\n const node = matchUp(syntaxTree(state).resolveInner(pos, -1), nodes);\n\n if (!node) {\n return null;\n }\n\n if (matchLeft(node, pos, [ keyword, before ])) {\n return null;\n }\n\n if (matchRight(node, pos, [ keyword, after ])) {\n return null;\n }\n\n if (after && !matchLeft(node, pos, [ after ])) {\n return null;\n }\n\n return source(context);\n };\n}","import {\n parser,\n trackVariables\n} from 'lezer-feel';\n\nimport {\n LRLanguage,\n LanguageSupport,\n delimitedIndent,\n continuedIndent,\n indentNodeProp,\n foldNodeProp,\n foldInside\n} from '@codemirror/language';\n\nimport {\n snippets\n} from './snippets';\n\nimport {\n keywordCompletions,\n snippetCompletion\n} from './completion';\n\nimport {\n CompletionSource\n} from '@codemirror/autocomplete';\n\n\n/**\n * A FEEL language provider based on the\n * [Lezer FEEL parser](https://github.com/nikku/lezer-feel),\n * extended with highlighting and indentation information.\n */\nexport const feelLanguage = LRLanguage.define({\n parser: parser.configure({\n props: [\n indentNodeProp.add({\n 'Context': delimitedIndent({\n closing: '}'\n }),\n 'List FilterExpression': delimitedIndent({\n closing: ']'\n }),\n 'ParenthesizedExpression FunctionInvocation': continuedIndent({\n except: /^\\s*\\)/\n }),\n 'ForExpression QuantifiedExpression IfExpression': continuedIndent({\n except: /^\\s*(then|else|return|satisfies)\\b/\n }),\n 'FunctionDefinition': continuedIndent({\n except: /^\\s*(\\(|\\))/\n })\n }),\n foldNodeProp.add({\n Context: foldInside,\n List: foldInside,\n ParenthesizedExpression: foldInside,\n FunctionDefinition(node) {\n const last = node.getChild(')');\n\n if (!last) return null;\n\n return {\n from: last.to,\n to: node.to\n };\n }\n })\n ]\n }),\n languageData: {\n indentOnInput: /^\\s*(\\)|\\}|\\]|then|else|return|satisfies)$/,\n commentTokens: {\n line: '//',\n block: {\n open: '/*',\n close: '*/'\n }\n }\n }\n});\n\n/**\n * A language provider for FEEL Unary Tests\n */\nexport const unaryTestsLanguage = feelLanguage.configure({\n top: 'UnaryTests',\n}, 'FEEL unary tests');\n\n/**\n * Language provider for FEEL Expression\n */\nexport const expressionLanguage = feelLanguage.configure({\n top: 'Expression'\n}, 'FEEL expression');\n\n\n\n/**\n * Feel language support for CodeMirror.\n *\n * Includes [snippet](#lang-feel.snippets)\n */\nexport function feel(config: {\n dialect?: 'expression' | 'unaryTests',\n completions?: CompletionSource[],\n context?: Record<string, any>\n} = {}) {\n const lang = config.dialect === 'unaryTests' ? unaryTestsLanguage : expressionLanguage;\n\n const contextualLang = lang.configure({\n contextTracker: trackVariables(config.context)\n });\n\n const completions = config.completions || [\n snippetCompletion(snippets),\n keywordCompletions,\n ].flat();\n\n return new LanguageSupport(contextualLang, [\n ...(\n completions.map(autocomplete => contextualLang.data.of({\n autocomplete\n }))\n )\n ]);\n\n}"],"names":["snippets","snippetCompletion","label","detail","type","contextualKeyword","options","context","nodes","after","before","keyword","ifInside","completeFromList","boost","keywordCompletions","dontComplete","ifNotIn","map","s","matchLeft","node","position","matchChildren","matchRight","direction","child","includes","name","isError","firstChild","matchUp","nodeNames","Array","isArray","parent","isTop","source","state","pos","syntaxTree","resolveInner","feelLanguage","LRLanguage","define","parser","configure","props","indentNodeProp","add","delimitedIndent","closing","continuedIndent","except","foldNodeProp","Context","foldInside","List","ParenthesizedExpression","FunctionDefinition","last","getChild","from","to","languageData","indentOnInput","commentTokens","line","block","open","close","unaryTestsLanguage","top","expressionLanguage","feel","config","lang","dialect","contextualLang","contextTracker","trackVariables","completions","flat","LanguageSupport","autocomplete","data","of"],"mappings":";;;;AAEA;;AAEG;MACUA,QAAQ,GAA0B,CAC7CC,8BAAiB,CAAC,6BAA6B,EAAE;AAC/CC,EAAAA,KAAK,EAAE,UAAU;AACjBC,EAAAA,MAAM,EAAE,YAAY;AACpBC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,8BAAiB,CAAC,6CAA6C,EAAE;AAC/DC,EAAAA,KAAK,EAAE,KAAK;AACZC,EAAAA,MAAM,EAAE,YAAY;AACpBC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,8BAAiB,CAAC,sDAAsD,EAAE;AACxEC,EAAAA,KAAK,EAAE,OAAO;AACdC,EAAAA,MAAM,EAAE,uBAAuB;AAC/BC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,8BAAiB,CAAC,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9C,GAAA,CAAC,CAAA;AAEF,EAAA,MAAM0E,WAAW,GAAGN,MAAM,CAACM,WAAW,IAAI,CACxChF,iBAAiB,CAACD,QAAQ,CAAC,EAC3Be,kBAAkB,CACnB,CAACmE,IAAI,EAAE,CAAA;AAER,EAAA,OAAO,IAAIC,wBAAe,CAACL,cAAc,EAAE,CACzC,GACEG,WAAW,CAAC/D,GAAG,CAACkE,YAAY,IAAIN,cAAc,CAACO,IAAI,CAACC,EAAE,CAAC;AACrDF,IAAAA,YAAAA;GACD,CAAC,CACH,CACF,CAAC,CAAA;AAEJ;;;;;;;;;;;;;;;;"}
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ const keywordCompletions = [contextualKeyword({
84
84
  after: 'InExpressions',
85
85
  keyword: 'return'
86
86
  })];
87
- const dontComplete = ['StringLiteral', 'Identifier', 'LineComment', 'BlockComment'];
87
+ const dontComplete = ['StringLiteral', 'Identifier', 'LineComment', 'BlockComment', 'PathExpression'];
88
88
  function snippetCompletion(snippets) {
89
89
  return ifNotIn(dontComplete, completeFromList(snippets.map(s => _extends({}, s, {
90
90
  type: 'text'
@@ -207,13 +207,13 @@ const feelLanguage = LRLanguage.define({
207
207
  */
208
208
  const unaryTestsLanguage = feelLanguage.configure({
209
209
  top: 'UnaryTests'
210
- });
210
+ }, 'FEEL unary tests');
211
211
  /**
212
212
  * Language provider for FEEL Expression
213
213
  */
214
214
  const expressionLanguage = feelLanguage.configure({
215
215
  top: 'Expression'
216
- });
216
+ }, 'FEEL expression');
217
217
  /**
218
218
  * Feel language support for CodeMirror.
219
219
  *
@@ -225,7 +225,7 @@ function feel(config = {}) {
225
225
  contextTracker: trackVariables(config.context)
226
226
  });
227
227
  const completions = config.completions || [snippetCompletion(snippets), keywordCompletions].flat();
228
- return new LanguageSupport(contextualLang, [...completions.map(autocomplete => feelLanguage.data.of({
228
+ return new LanguageSupport(contextualLang, [...completions.map(autocomplete => contextualLang.data.of({
229
229
  autocomplete
230
230
  }))]);
231
231
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/snippets.ts","../src/completion.ts","../src/feel.ts"],"sourcesContent":["import { Completion, snippetCompletion } from '@codemirror/autocomplete';\n\n/**\n * A collection of FEEL-related [snippets](#autocomplete.snippet).\n */\nexport const snippets: readonly Completion[] = [\n snippetCompletion('function(${params}) ${body}', {\n label: 'function',\n detail: 'definition',\n type: 'keyword'\n }),\n snippetCompletion('for ${var} in ${collection} return ${value}', {\n label: 'for',\n detail: 'expression',\n type: 'keyword'\n }),\n snippetCompletion('every ${var} in ${collection} satisfies ${condition}', {\n label: 'every',\n detail: 'quantified expression',\n type: 'keyword'\n }),\n snippetCompletion('some ${var} in ${collection} satisfies ${condition}', {\n label: 'some',\n detail: 'quantified expression',\n type: 'keyword'\n }),\n snippetCompletion('if ${condition} then ${value} else ${other value}', {\n label: 'if',\n detail: 'block',\n type: 'keyword'\n }),\n snippetCompletion('{ ${key}: ${value} }', {\n label: 'context',\n detail: 'block',\n type: 'keyword'\n })\n];\n","import { syntaxTree } from '@codemirror/language';\nimport { SyntaxNode } from '@lezer/common';\n\nimport {\n CompletionSource,\n Completion,\n completeFromList,\n ifNotIn\n} from '@codemirror/autocomplete';\n\n\nexport function contextualKeyword(options: {\n before?: string,\n after?: string,\n context: string,\n keyword: string\n}) : CompletionSource {\n\n const {\n context: nodes,\n after,\n before,\n keyword\n } = options;\n\n return ifInside({ nodes, before, after, keyword }, completeFromList([\n { label: keyword, type: 'keyword', boost: 10 }\n ]));\n}\n\nexport const keywordCompletions = [\n contextualKeyword({\n context: 'InExpression',\n keyword: 'in'\n }),\n contextualKeyword({\n context: 'IfExpression',\n keyword: 'then',\n after: 'if',\n before: 'else'\n }),\n contextualKeyword({\n context: 'IfExpression',\n keyword: 'else',\n after: 'then'\n }),\n contextualKeyword({\n context: 'QuantifiedExpression',\n keyword: 'satisfies'\n }),\n contextualKeyword({\n context: 'ForExpression',\n after: 'InExpressions',\n keyword: 'return'\n })\n];\n\nexport const dontComplete = [\n 'StringLiteral', 'Identifier',\n 'LineComment', 'BlockComment'\n];\n\nexport function snippetCompletion(snippets: readonly Completion[]) : CompletionSource {\n return ifNotIn(\n dontComplete, completeFromList(snippets.map(s => ({ ...s, type: 'text' })))\n );\n}\n\nexport function matchLeft(node: SyntaxNode, position: number, nodes: (string|undefined)[]) : SyntaxNode | null {\n return matchChildren(node, position, nodes, -1);\n}\n\nexport function matchRight(node: SyntaxNode, position: number, nodes: (string|undefined)[]) : SyntaxNode | null {\n return matchChildren(node, position, nodes, 1);\n}\n\nexport function matchChildren(node: SyntaxNode, position: number, nodes: (string|undefined)[], direction: 1 | -1) : SyntaxNode | null {\n\n let child = node[direction > 0 ? 'childAfter' : 'childBefore'](position);\n\n while (child) {\n if (nodes.includes(child.name)) {\n return child;\n }\n\n if (child.type.isError && child.firstChild) {\n if (nodes.includes(child.firstChild.name)) {\n return child.firstChild;\n }\n }\n\n child = child[direction > 0 ? 'nextSibling' : 'prevSibling'];\n }\n\n return null;\n}\n\nfunction matchUp(node: SyntaxNode, nodeNames: string | undefined | (string | undefined)[]) {\n\n if (!Array.isArray(nodeNames)) {\n nodeNames = [ nodeNames ];\n }\n\n for (; node; node = node.parent!) {\n if (nodeNames.includes(node.name)) {\n return node;\n }\n\n if (node.type.isTop) {\n break;\n }\n }\n\n return null;\n}\n\nexport function ifInside(options: {\n nodes: string | string[],\n keyword: string,\n before?: string,\n after?: string\n}, source: CompletionSource): CompletionSource {\n\n const {\n nodes,\n before,\n after,\n keyword\n } = options;\n\n return (context) => {\n\n const { state, pos } = context;\n\n const node = matchUp(syntaxTree(state).resolveInner(pos, -1), nodes);\n\n if (!node) {\n return null;\n }\n\n if (matchLeft(node, pos, [ keyword, before ])) {\n return null;\n }\n\n if (matchRight(node, pos, [ keyword, after ])) {\n return null;\n }\n\n if (after && !matchLeft(node, pos, [ after ])) {\n return null;\n }\n\n return source(context);\n };\n}","import {\n parser,\n trackVariables\n} from 'lezer-feel';\n\nimport {\n LRLanguage,\n LanguageSupport,\n delimitedIndent,\n continuedIndent,\n indentNodeProp,\n foldNodeProp,\n foldInside\n} from '@codemirror/language';\n\nimport {\n snippets\n} from './snippets';\n\nimport {\n keywordCompletions,\n snippetCompletion\n} from './completion';\n\nimport {\n CompletionSource\n} from '@codemirror/autocomplete';\n\n\n/**\n * A FEEL language provider based on the\n * [Lezer FEEL parser](https://github.com/nikku/lezer-feel),\n * extended with highlighting and indentation information.\n */\nexport const feelLanguage = LRLanguage.define({\n parser: parser.configure({\n props: [\n indentNodeProp.add({\n 'Context': delimitedIndent({\n closing: '}'\n }),\n 'List FilterExpression': delimitedIndent({\n closing: ']'\n }),\n 'ParenthesizedExpression FunctionInvocation': continuedIndent({\n except: /^\\s*\\)/\n }),\n 'ForExpression QuantifiedExpression IfExpression': continuedIndent({\n except: /^\\s*(then|else|return|satisfies)\\b/\n }),\n 'FunctionDefinition': continuedIndent({\n except: /^\\s*(\\(|\\))/\n })\n }),\n foldNodeProp.add({\n Context: foldInside,\n List: foldInside,\n ParenthesizedExpression: foldInside,\n FunctionDefinition(node) {\n const last = node.getChild(')');\n\n if (!last) return null;\n\n return {\n from: last.to,\n to: node.to\n };\n }\n })\n ]\n }),\n languageData: {\n indentOnInput: /^\\s*(\\)|\\}|\\]|then|else|return|satisfies)$/,\n commentTokens: {\n line: '//',\n block: {\n open: '/*',\n close: '*/'\n }\n }\n }\n});\n\n/**\n * A language provider for FEEL Unary Tests\n */\nexport const unaryTestsLanguage = feelLanguage.configure({ top: 'UnaryTests' });\n\n/**\n * Language provider for FEEL Expression\n */\nexport const expressionLanguage = feelLanguage.configure({ top: 'Expression' });\n\n\n\n/**\n * Feel language support for CodeMirror.\n *\n * Includes [snippet](#lang-feel.snippets)\n */\nexport function feel(config: {\n dialect?: 'expression' | 'unaryTests',\n completions?: CompletionSource[],\n context?: Record<string, any>\n} = {}) {\n const lang = config.dialect === 'unaryTests' ? unaryTestsLanguage : expressionLanguage;\n\n const contextualLang = lang.configure({\n contextTracker: trackVariables(config.context)\n });\n\n const completions = config.completions || [\n snippetCompletion(snippets),\n keywordCompletions,\n ].flat();\n\n return new LanguageSupport(contextualLang, [\n ...(\n completions.map(autocomplete => feelLanguage.data.of({\n autocomplete\n }))\n )\n ]);\n\n}"],"names":["snippets","snippetCompletion","label","detail","type","contextualKeyword","options","context","nodes","after","before","keyword","ifInside","completeFromList","boost","keywordCompletions","dontComplete","ifNotIn","map","s","_extends","matchLeft","node","position","matchChildren","matchRight","direction","child","includes","name","isError","firstChild","matchUp","nodeNames","Array","isArray","parent","isTop","source","state","pos","syntaxTree","resolveInner","feelLanguage","LRLanguage","define","parser","configure","props","indentNodeProp","add","delimitedIndent","closing","continuedIndent","except","foldNodeProp","Context","foldInside","List","ParenthesizedExpression","FunctionDefinition","last","getChild","from","to","languageData","indentOnInput","commentTokens","line","block","open","close","unaryTestsLanguage","top","expressionLanguage","feel","config","lang","dialect","contextualLang","contextTracker","trackVariables","completions","flat","LanguageSupport","autocomplete","data","of"],"mappings":";;;;AAEA;;AAEG;MACUA,QAAQ,GAA0B,CAC7CC,mBAAiB,CAAC,6BAA6B,EAAE;AAC/CC,EAAAA,KAAK,EAAE,UAAU;AACjBC,EAAAA,MAAM,EAAE,YAAY;AACpBC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,mBAAiB,CAAC,6CAA6C,EAAE;AAC/DC,EAAAA,KAAK,EAAE,KAAK;AACZC,EAAAA,MAAM,EAAE,YAAY;AACpBC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,mBAAiB,CAAC,sDAAsD,EAAE;AACxEC,EAAAA,KAAK,EAAE,OAAO;AACdC,EAAAA,MAAM,EAAE,uBAAuB;AAC/BC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,mBAAiB,CAAC,qDAAqD,EAAE;AACvEC,EAAAA,KAAK,EAAE,MAAM;AACbC,EAAAA,MAAM,EAAE,uBAAuB;AAC/BC,EAAAA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,EAC3Be,kBAAkB,CACnB,CAACoE,IAAI,EAAE,CAAA;AAER,EAAA,OAAO,IAAIC,eAAe,CAACL,cAAc,EAAE,CACzC,GACEG,WAAW,CAAChE,GAAG,CAACmE,YAAY,IAAI1C,YAAY,CAAC2C,IAAI,CAACC,EAAE,CAAC;AACnDF,IAAAA,YAAAA;GACD,CAAC,CACH,CACF,CAAC,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/snippets.ts","../src/completion.ts","../src/feel.ts"],"sourcesContent":["import { Completion, snippetCompletion } from '@codemirror/autocomplete';\n\n/**\n * A collection of FEEL-related [snippets](#autocomplete.snippet).\n */\nexport const snippets: readonly Completion[] = [\n snippetCompletion('function(${params}) ${body}', {\n label: 'function',\n detail: 'definition',\n type: 'keyword'\n }),\n snippetCompletion('for ${var} in ${collection} return ${value}', {\n label: 'for',\n detail: 'expression',\n type: 'keyword'\n }),\n snippetCompletion('every ${var} in ${collection} satisfies ${condition}', {\n label: 'every',\n detail: 'quantified expression',\n type: 'keyword'\n }),\n snippetCompletion('some ${var} in ${collection} satisfies ${condition}', {\n label: 'some',\n detail: 'quantified expression',\n type: 'keyword'\n }),\n snippetCompletion('if ${condition} then ${value} else ${other value}', {\n label: 'if',\n detail: 'block',\n type: 'keyword'\n }),\n snippetCompletion('{ ${key}: ${value} }', {\n label: 'context',\n detail: 'block',\n type: 'keyword'\n })\n];\n","import { syntaxTree } from '@codemirror/language';\nimport { SyntaxNode } from '@lezer/common';\n\nimport {\n CompletionSource,\n Completion,\n completeFromList,\n ifNotIn\n} from '@codemirror/autocomplete';\n\n\nexport function contextualKeyword(options: {\n before?: string,\n after?: string,\n context: string,\n keyword: string\n}) : CompletionSource {\n\n const {\n context: nodes,\n after,\n before,\n keyword\n } = options;\n\n return ifInside({ nodes, before, after, keyword }, completeFromList([\n { label: keyword, type: 'keyword', boost: 10 }\n ]));\n}\n\nexport const keywordCompletions = [\n contextualKeyword({\n context: 'InExpression',\n keyword: 'in'\n }),\n contextualKeyword({\n context: 'IfExpression',\n keyword: 'then',\n after: 'if',\n before: 'else'\n }),\n contextualKeyword({\n context: 'IfExpression',\n keyword: 'else',\n after: 'then'\n }),\n contextualKeyword({\n context: 'QuantifiedExpression',\n keyword: 'satisfies'\n }),\n contextualKeyword({\n context: 'ForExpression',\n after: 'InExpressions',\n keyword: 'return'\n })\n];\n\nexport const dontComplete = [\n 'StringLiteral', 'Identifier',\n 'LineComment', 'BlockComment',\n 'PathExpression'\n];\n\nexport function snippetCompletion(snippets: readonly Completion[]) : CompletionSource {\n return ifNotIn(\n dontComplete, completeFromList(snippets.map(s => ({ ...s, type: 'text' })))\n );\n}\n\nexport function matchLeft(node: SyntaxNode, position: number, nodes: (string|undefined)[]) : SyntaxNode | null {\n return matchChildren(node, position, nodes, -1);\n}\n\nexport function matchRight(node: SyntaxNode, position: number, nodes: (string|undefined)[]) : SyntaxNode | null {\n return matchChildren(node, position, nodes, 1);\n}\n\nexport function matchChildren(node: SyntaxNode, position: number, nodes: (string|undefined)[], direction: 1 | -1) : SyntaxNode | null {\n\n let child = node[direction > 0 ? 'childAfter' : 'childBefore'](position);\n\n while (child) {\n if (nodes.includes(child.name)) {\n return child;\n }\n\n if (child.type.isError && child.firstChild) {\n if (nodes.includes(child.firstChild.name)) {\n return child.firstChild;\n }\n }\n\n child = child[direction > 0 ? 'nextSibling' : 'prevSibling'];\n }\n\n return null;\n}\n\nfunction matchUp(node: SyntaxNode, nodeNames: string | undefined | (string | undefined)[]) {\n\n if (!Array.isArray(nodeNames)) {\n nodeNames = [ nodeNames ];\n }\n\n for (; node; node = node.parent!) {\n if (nodeNames.includes(node.name)) {\n return node;\n }\n\n if (node.type.isTop) {\n break;\n }\n }\n\n return null;\n}\n\nexport function ifInside(options: {\n nodes: string | string[],\n keyword: string,\n before?: string,\n after?: string\n}, source: CompletionSource): CompletionSource {\n\n const {\n nodes,\n before,\n after,\n keyword\n } = options;\n\n return (context) => {\n\n const { state, pos } = context;\n\n const node = matchUp(syntaxTree(state).resolveInner(pos, -1), nodes);\n\n if (!node) {\n return null;\n }\n\n if (matchLeft(node, pos, [ keyword, before ])) {\n return null;\n }\n\n if (matchRight(node, pos, [ keyword, after ])) {\n return null;\n }\n\n if (after && !matchLeft(node, pos, [ after ])) {\n return null;\n }\n\n return source(context);\n };\n}","import {\n parser,\n trackVariables\n} from 'lezer-feel';\n\nimport {\n LRLanguage,\n LanguageSupport,\n delimitedIndent,\n continuedIndent,\n indentNodeProp,\n foldNodeProp,\n foldInside\n} from '@codemirror/language';\n\nimport {\n snippets\n} from './snippets';\n\nimport {\n keywordCompletions,\n snippetCompletion\n} from './completion';\n\nimport {\n CompletionSource\n} from '@codemirror/autocomplete';\n\n\n/**\n * A FEEL language provider based on the\n * [Lezer FEEL parser](https://github.com/nikku/lezer-feel),\n * extended with highlighting and indentation information.\n */\nexport const feelLanguage = LRLanguage.define({\n parser: parser.configure({\n props: [\n indentNodeProp.add({\n 'Context': delimitedIndent({\n closing: '}'\n }),\n 'List FilterExpression': delimitedIndent({\n closing: ']'\n }),\n 'ParenthesizedExpression FunctionInvocation': continuedIndent({\n except: /^\\s*\\)/\n }),\n 'ForExpression QuantifiedExpression IfExpression': continuedIndent({\n except: /^\\s*(then|else|return|satisfies)\\b/\n }),\n 'FunctionDefinition': continuedIndent({\n except: /^\\s*(\\(|\\))/\n })\n }),\n foldNodeProp.add({\n Context: foldInside,\n List: foldInside,\n ParenthesizedExpression: foldInside,\n FunctionDefinition(node) {\n const last = node.getChild(')');\n\n if (!last) return null;\n\n return {\n from: last.to,\n to: node.to\n };\n }\n })\n ]\n }),\n languageData: {\n indentOnInput: /^\\s*(\\)|\\}|\\]|then|else|return|satisfies)$/,\n commentTokens: {\n line: '//',\n block: {\n open: '/*',\n close: '*/'\n }\n }\n }\n});\n\n/**\n * A language provider for FEEL Unary Tests\n */\nexport const unaryTestsLanguage = feelLanguage.configure({\n top: 'UnaryTests',\n}, 'FEEL unary tests');\n\n/**\n * Language provider for FEEL Expression\n */\nexport const expressionLanguage = feelLanguage.configure({\n top: 'Expression'\n}, 'FEEL expression');\n\n\n\n/**\n * Feel language support for CodeMirror.\n *\n * Includes [snippet](#lang-feel.snippets)\n */\nexport function feel(config: {\n dialect?: 'expression' | 'unaryTests',\n completions?: CompletionSource[],\n context?: Record<string, any>\n} = {}) {\n const lang = config.dialect === 'unaryTests' ? unaryTestsLanguage : expressionLanguage;\n\n const contextualLang = lang.configure({\n contextTracker: trackVariables(config.context)\n });\n\n const completions = config.completions || [\n snippetCompletion(snippets),\n keywordCompletions,\n ].flat();\n\n return new LanguageSupport(contextualLang, [\n ...(\n completions.map(autocomplete => contextualLang.data.of({\n autocomplete\n }))\n )\n ]);\n\n}"],"names":["snippets","snippetCompletion","label","detail","type","contextualKeyword","options","context","nodes","after","before","keyword","ifInside","completeFromList","boost","keywordCompletions","dontComplete","ifNotIn","map","s","_extends","matchLeft","node","position","matchChildren","matchRight","direction","child","includes","name","isError","firstChild","matchUp","nodeNames","Array","isArray","parent","isTop","source","state","pos","syntaxTree","resolveInner","feelLanguage","LRLanguage","define","parser","configure","props","indentNodeProp","add","delimitedIndent","closing","continuedIndent","except","foldNodeProp","Context","foldInside","List","ParenthesizedExpression","FunctionDefinition","last","getChild","from","to","languageData","indentOnInput","commentTokens","line","block","open","close","unaryTestsLanguage","top","expressionLanguage","feel","config","lang","dialect","contextualLang","contextTracker","trackVariables","completions","flat","LanguageSupport","autocomplete","data","of"],"mappings":";;;;AAEA;;AAEG;MACUA,QAAQ,GAA0B,CAC7CC,mBAAiB,CAAC,6BAA6B,EAAE;AAC/CC,EAAAA,KAAK,EAAE,UAAU;AACjBC,EAAAA,MAAM,EAAE,YAAY;AACpBC,EAAAA,IAAI,EAAE,SAAA;CACP,CAAC,EACFH,mBAAiB,CAAC,6CAA6C,EAAE;AAC/DC,EAAAA,KAAK,EAAE,KAAK;AACZC,EAAAA,MAAM,EAAE,YAAY;AACpBC,EAAAA,IAAI,EAAE,SAAA;CACP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AAO,KAAK,YAAY,GAAGN,kBAAkB,GAAGE,kBAAkB,CAAA;AAEtF,EAAA,MAAMK,cAAc,GAAGF,IAAI,CAAC9B,SAAS,CAAC;AACpCiC,IAAAA,cAAc,EAAEC,cAAc,CAACL,MAAM,CAACrE,OAAO,CAAA;AAC9C,GAAA,CAAC,CAAA;AAEF,EAAA,MAAM2E,WAAW,GAAGN,MAAM,CAACM,WAAW,IAAI,CACxCjF,iBAAiB,CAACD,QAAQ,CAAC,EAC3Be,kBAAkB,CACnB,CAACoE,IAAI,EAAE,CAAA;AAER,EAAA,OAAO,IAAIC,eAAe,CAACL,cAAc,EAAE,CACzC,GACEG,WAAW,CAAChE,GAAG,CAACmE,YAAY,IAAIN,cAAc,CAACO,IAAI,CAACC,EAAE,CAAC;AACrDF,IAAAA,YAAAA;GACD,CAAC,CACH,CACF,CAAC,CAAA;AAEJ;;;;"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "lang-feel",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "FEEL language support for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "all": "run-s lint build test",
7
7
  "test": "karma start karma.conf.cjs",
8
8
  "dev": "run-p 'build -- watch' 'test -- --no-single-run --auto-watch'",
9
9
  "lint": "eslint . --ext ts",
10
- "build": "microbundle src/index.ts -f modern,cjs --target node",
10
+ "build": "microbundle -f modern,cjs --target node",
11
11
  "prepare": "npm run build"
12
12
  },
13
13
  "keywords": [
@@ -19,6 +19,7 @@
19
19
  "url": "https://github.com/nikku"
20
20
  },
21
21
  "type": "module",
22
+ "source": "src/index.ts",
22
23
  "main": "dist/index.cjs",
23
24
  "exports": {
24
25
  "import": "./dist/index.js",
@@ -29,37 +30,37 @@
29
30
  "sideEffects": false,
30
31
  "license": "MIT",
31
32
  "dependencies": {
32
- "@codemirror/autocomplete": "^6.9.1",
33
- "@codemirror/language": "^6.9.1",
34
- "@codemirror/state": "^6.2.1",
35
- "@codemirror/view": "^6.21.0",
36
- "@lezer/common": "^1.1.2",
37
- "lezer-feel": "^1.2.0"
33
+ "@codemirror/autocomplete": "^6.16.2",
34
+ "@codemirror/language": "^6.10.2",
35
+ "@codemirror/state": "^6.4.1",
36
+ "@codemirror/view": "^6.28.1",
37
+ "@lezer/common": "^1.2.1",
38
+ "lezer-feel": "^1.2.9"
38
39
  },
39
40
  "devDependencies": {
40
- "@lezer/lr": "^1.3.12",
41
+ "@lezer/lr": "^1.4.1",
41
42
  "@types/karma-chai": "^0.1.6",
42
43
  "@types/karma-mocha": "^1.3.4",
43
44
  "@types/mocha": "^10.0.6",
44
- "@typescript-eslint/eslint-plugin": "^6.14.0",
45
- "@typescript-eslint/parser": "^6.14.0",
46
- "chai": "^4.3.10",
45
+ "@typescript-eslint/eslint-plugin": "^7.13.0",
46
+ "@typescript-eslint/parser": "^7.13.0",
47
+ "chai": "^4.4.1",
47
48
  "codemirror": "^6.0.1",
48
- "eslint": "^8.55.0",
49
+ "eslint": "^8.57.0",
49
50
  "eslint-plugin-bpmn-io": "^1.0.0",
50
- "karma": "^6.4.2",
51
+ "karma": "^6.4.3",
51
52
  "karma-chai": "^0.1.0",
52
53
  "karma-chrome-launcher": "^3.2.0",
53
54
  "karma-debug-launcher": "^0.0.5",
54
55
  "karma-mocha": "^2.0.1",
55
- "karma-webpack": "^5.0.0",
56
+ "karma-webpack": "^5.0.1",
56
57
  "microbundle": "^0.15.1",
57
- "mocha": "^10.2.0",
58
- "npm-run-all": "^4.1.5",
59
- "puppeteer": "^21.6.0",
58
+ "mocha": "^10.4.0",
59
+ "npm-run-all2": "^6.2.0",
60
+ "puppeteer": "^22.11.0",
60
61
  "ts-loader": "^9.5.1",
61
- "typescript": "^5.3.3",
62
- "webpack": "^5.89.0"
62
+ "typescript": "^5.4.5",
63
+ "webpack": "^5.92.0"
63
64
  },
64
65
  "repository": {
65
66
  "type": "git",