Skip to content

feat: resolve file-scope string consts in decorator metadata#271

Open
ashley-hunter wants to merge 1 commit into
voidzero-dev:mainfrom
ashley-hunter:feat/resolve-string-consts-in-decorator-metadata
Open

feat: resolve file-scope string consts in decorator metadata#271
ashley-hunter wants to merge 1 commit into
voidzero-dev:mainfrom
ashley-hunter:feat/resolve-string-consts-in-decorator-metadata

Conversation

@ashley-hunter
Copy link
Copy Markdown
Contributor

@ashley-hunter ashley-hunter commented May 13, 2026

The use of variables within decorators is not currently supported - this PR provides basic support for the use of variables in decorators. Currently this supports variables defined within the same file, e.g.

const ATTR = 'data-foo';
@Directive({ selector: '[d]', host: { [ATTR]: '' } })
class D {}

For full equivalent to Angular we would need to add resolving across multiple files, i.e. following imports - but that could be covered by a separate PR - this provides the initial basic support.

Introduce `StringConsts` (a `HashMap<&str, Ident>`) and `collect_string_consts`
to walk a program's top-level `const` declarations and capture literal string
values. Pass the map through `extract_directive_metadata`,
`extract_component_metadata`, and all helper functions so that identifier
references used as host-binding keys or values (e.g. `host: { [MARKER_ATTR]: '' }`)
are resolved to their string values at compile time, matching the official
Angular compiler's constant-folding behaviour.

Add integration tests covering identifier keys and identifier values in host
bindings for both directives and components.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Brooooooklyn
Copy link
Copy Markdown
Member

@ashley-hunter run cargo fmt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants