microsoft / microsoft/typespec

[core] `templateNode` is not set on declaration types until decorators are already run

Open
#6,680 0 comments 0 reactions 0 assignees View on GitHub
compiler:core design:needed triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

All templateable types declare a `templateNode` field that refers to the original template declaration AST node that defined the template an instantiation comes from.

This node would be useful in some cases where you need to get the diagnostic target for a specific template arguments by name, using logic like:

- Look through the arguments in `templateMapper.source.node`, if any are named template arguments that have the name you're looking for, you have a reference to the argument target node.
- If not, look through `templateNode.templateParameters` and find the _index_ of the argument with the name you are looking for. If the arguments array has this index, then check if that argument is named. If it is, the argument you are looking for was not specified. If it wasn't named, it must be the argument you were looking for.

It's complex logic that I'd like to add to the templateMapper as a helper, but because the `templateNode` is not set until after the node is fully checked and decorators have run, this method can't be used inside decorator implementations, defeating the purpose.

**Solution**: find a way to set templateNode on templateable declaration types before running decorators.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.