Implement AST-based dependency extraction in FormulaVisitor.calculateDependencies (markdown-template)

Abierto
#679 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
typescript
Área
backend, tooling

Línea de trabajo

Start by reading packages/markdown-template/src/FormulaVisitor.ts and trace how calculateDependencies is called from templatemarkutil.ts and how dependencies is serialized and read back. The issue leaves the runtime parser and which identifiers count unresolved, so first settle those decisions in the discussion before implementing. Done means extracting the agreed dependencies from formula TypeScript while respecting the agreed handling of bindings and parse failures.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Stale

Summary

FormulaVisitor.calculateDependencies(tsCode) in packages/markdown-template/src/FormulaVisitor.ts is a stub (// TODO!!) that always returns []. It's invoked during TemplateMark typing (templatemarkutil.ts → templateMarkTypingGen), which sets dependencies on every FormulaDefinition / ConditionalDefinition, and the value is serialized through markdown-html (ToHtmlStringVisitor.ts writes the dependencies attribute, rules.ts reads it back). Today that attribute is always an empty array.

Continuing the working discussion with @mttrbrts

Current state / safety

Traced consumers of the field across the org:

  • markdown-transform: only written (HTML attr), read back (rules.ts), or stripped (markdown-cicero/ToCommonMarkVisitor.ts deletes it).
  • template-engine: only TemplateMarkInterpreter.ts does delete context.dependencies.

No code branches on the values, so implementing real extraction is self-contained with no regression surface — it only populates a field that is currently always empty.

Proposed approach

Extract root identifiers from the formula's TypeScript source (the param is named tsCode) via the AST rather than regex:

  • Collect root identifiers that reference template variables / model, excluding locally-bound names, function params, and built-ins.
  • Handle optional chaining (a?.b?.c → root a).
  • Return [] on parse failure or unrecognized constructs (note: this changes the current catch, which throws — flagging so it's an explicit decision).

Open questions to scope before implementation

  1. Runtime parser: typescript is currently a devDependency of markdown-template. Preference for promoting the TS compiler API to a runtime dep vs. a lighter parser (e.g. @typescript-eslint/typescript-estree)?
  2. Dependency definition: which identifier classes count — model/variable refs only, and are locally-declared bindings and function params always excluded?
  3. Cross-formula references: Devanshi noted formulas lack stable user-facing names, so these look out-of-scope for v1 — agreed to defer?

I can't make the Wednesday call, so opening this for async discussion per your
suggestion. Once (1) the runtime parser and (2) the dependency-definition
question are settled here, I'll scope the PR to those decisions.

Lenguaje dominante
TypeScript
Estrellas
86
Forks
69
Merge medio
6 min
PR fusionados (30 d)
3

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de accordproject/markdown-transform

Todos los issues de accordproject/markdown-transform

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.