# Computing a Facet depending on syntaxTree

**URL:** <https://discuss.codemirror.net/t/computing-a-facet-depending-on-syntaxtree/9695>\
**Category:** v6\
**Created:** [March 25, 2026, 5:17am UTC](https://discuss.codemirror.net/t/computing-a-facet-depending-on-syntaxtree/9695 "2026-03-25T05:17:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![push-f](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/p/ce73a5/32.png) [@push-f](https://discuss.codemirror.net/u/push-f)\
**Post date:** [March 25, 2026, 5:17am UTC](https://discuss.codemirror.net/t/computing-a-facet-depending-on-syntaxtree/9695/1 "2026-03-25T05:17:57Z")

</div>

My app is reparsing the Lezer tree into a more high-level AST (without punctuation). I guess it would make sense to store this AST in a Facet and derive it with [Facet.compute](https://codemirror.net/docs/ref/#state.Facet.compute)? For this I’d declare a dependency on `Language.state` however the static property is internal and thus not exposed in the TypeScript definitions:

```auto
  /// @internal
  static state: StateField<LanguageState>

```

Would it make sense to expose this?

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [March 25, 2026, 6:41am UTC](https://discuss.codemirror.net/t/computing-a-facet-depending-on-syntaxtree/9695/2 "2026-03-25T06:41:14Z")

</div>

Would it work to define this as a state field, and do a `syntaxTree(tr.startState) != syntaxTree(tr.state)` check to determine whether to recompute it?

---

<div class="post-metadata">

**Author:** ![push-f](https://discuss.codemirror.net/letter_avatar_proxy/v4/letter/p/ce73a5/32.png) [@push-f](https://discuss.codemirror.net/u/push-f)\
**Post date:** [March 25, 2026, 7:58am UTC](https://discuss.codemirror.net/t/computing-a-facet-depending-on-syntaxtree/9695/3 "2026-03-25T07:58:38Z")

</div>

Yes that should work. Thanks! I guess I should also check `syntaxTreeAvailable(tr.state)`?

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [March 25, 2026, 9:23am UTC](https://discuss.codemirror.net/t/computing-a-facet-depending-on-syntaxtree/9695/4 "2026-03-25T09:23:38Z")

</div>

Yes, if it’s important that some part of the doc is fully parsed, you can use that. But note that in a big document, the editor may never decide to parse the entire document unless you tell it to (with `forceParsing` or `ensureSyntaxTree`).
