@bpmn-io/feel-analyzer

中文文档
0.5.1发布于 2026/09/08MITTypeScriptES Module近 30 天下载 30.7万

Static FEEL expression analyzer

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. Builtins
  4. Input Variables
  5. Invoked Functions
  6. Analyzing an Already-Parsed Tree
  7. Related
  8. License

FEEL Analyzer

A library for analyzing FEEL (Friendly Enough Expression Language) expressions.

CI

Installation

npm install @bpmn-io/feel-analyzer

Usage

To get started, create a FeelAnalyzer instance:

import { FeelAnalyzer } from '@bpmn-io/feel-analyzer';

const analyzer = new FeelAnalyzer();

Analyze a FEEL expression to extract input variables:

const result = analyzer.analyzeExpression('x + y');

console.log(result.valid); // true
console.log(result.inputs);
// [
//   { name: 'x' },
//   { name: 'y' }
// ]

Configure the FEEL dialect (expression or unary tests):

const analyzer = new FeelAnalyzer({
  dialect: 'unaryTests' // defaults to 'expression'
});

Builtins

You can provide builtins and reservedNameBuiltins to exclude built-in names from input detection. Use @camunda/feel-builtins to supply these:

import { FeelAnalyzer } from '@bpmn-io/feel-analyzer';
import { builtins, reservedNameBuiltins } from '@camunda/feel-builtins';

const analyzer = new FeelAnalyzer({
  dialect: 'expression',
  parserDialect: 'camunda',
  builtins,
  reservedNameBuiltins
});

const result = analyzer.analyzeExpression('sum(orders.amount) > 100');

console.log(result.inputs);
// [
//   {
//     name: 'orders',
//     type: 'List',
//     entries: [
//       { name: 'amount' }
//     ]
//   }
// ]

Input Variables

The analyzer extracts input variables with type information, including nested structures. The data model is aligned with variable-resolver:

const result = analyzer.analyzeExpression('person.name = "John" and scores[1] > 10');

console.log(result.inputs);
// [
//   {
//     name: 'person',
//     type: 'Context',
//     entries: [
//       { name: 'name' }
//     ]
//   },
//   {
//     name: 'scores',
//     type: 'List'
//   }
// ]

Invoked Functions

The analyzer extracts all function invocations from the expression, sorted by name and deduplicated. Each function is classified as builtin or user based on the provided builtins list:

import { FeelAnalyzer } from '@bpmn-io/feel-analyzer';
import { camundaBuiltins, camundaReservedNameBuiltins } from '@camunda/feel-builtins';

const analyzer = new FeelAnalyzer({
  parserDialect: 'camunda',
  builtins: camundaBuiltins,
  reservedNameBuiltins: camundaReservedNameBuiltins
});

const result = analyzer.analyzeExpression('from json(sum(myHelper(x)))');

console.log(result.functions);
// [
//   { name: 'from json', type: 'builtin' },
//   { name: 'myHelper', type: 'user' },
//   { name: 'sum', type: 'builtin' }
// ]

Analyzing an Already-Parsed Tree

If you already have a parsed syntax tree—for example from a CodeMirror editor using the same parser—you can analyze it directly with analyzeTree, avoiding a redundant parse:

const analyzer = new FeelAnalyzer();

const expression = 'x + y';
const tree = analyzer.parser.parse(expression);

const result = analyzer.analyzeTree(tree, expression);

The tree must come from a parser configured consistently with the analyzer (same dialect, parserDialect, and reservedNameBuiltins) - such as the provided analyzer.parser. A tree parsed with a different configuration may yield incorrect results.

License

MIT

版本与发布记录

@bpmn-io/feel-analyzer 共发布 8 个版本,首次发布于 2026/02/19;过去 12 个月发布了 8 个版本。

版本发布日期距今
0.5.1latest2026/09/082 个月前
0.5.02026/07/084 个月前
0.4.02026/07/014 个月前
0.3.02026/05/195 个月前
0.2.22026/05/125 个月前
0.2.12026/05/086 个月前

关于 @bpmn-io/feel-analyzer 的常见问题

@bpmn-io/feel-analyzer 是什么?

Static FEEL expression analyzer

如何安装 @bpmn-io/feel-analyzer?

在项目目录运行 npm install @bpmn-io/feel-analyzer,或使用 pnpm add / yarn add / bun add。

@bpmn-io/feel-analyzer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bpmn-io/feel-analyzer 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bpmn-io/feel-analyzer 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bpmn-io/feel-analyzer 可以商用吗?

@bpmn-io/feel-analyzer 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bpmn-io/feel-analyzer 的下载量有多少?

根据 npm 官方下载统计,@bpmn-io/feel-analyzer 在 2026/10/09 – 2026/11/07 这 30 天内被下载 306,931 次,日均约 10,231 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bpmn-io/feel-analyzer 还在维护吗?

最新版本 0.5.1 发布于 2026/09/08(2 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 8 个;首次发布于 2026/02/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。