Repository navigation
TypeScript: each key of a module-level const object literal is a declaration - #1829
Conversation
|
Two things to fix before this can merge:
|
1e015c3 to
6a36a93
Compare
|
CI fix: 78-cross-process-destinations and 80-object-literal-member-receivers failed with "fields-oracle changed".
|
|
#1826 has merged, so this now conflicts in |
…aration
`export const TOPICS = { orderEvents: '…' } as const` names topics, routes,
event types and DI tokens, and `TOPICS.orderEvents` is how every user reads
one. The keys were declared nowhere: `impact TOPICS.orderEvents` answered
"nothing named", and the readers of one key could not be told from another's.
- parser: an unannotated module-level `const` whose value is an object
literal (through `as const`, `satisfies`, parentheses, `Object.freeze`)
emits each data key as an OBJECT_LITERAL_PROPERTY field owned by the
variable; a nested literal's keys are owned by the key that holds it.
Function-valued keys stay methods.
- field_access.dl: `X.a` resolves to that field when X is the variable, an
import of it, a namespace import's export of it, or a key of an outer
table, and only when the typed lookup found nothing (`satisfies T` keeps
T's member). A read inside a method's decorator is that method's.
- index: a field whose owner is no type is displayed after the module
(`ROUTES.admin.users`).
- impact.dl: for a module-owned key, a line declaring another field of the
same name is not a read (two route tables in one file with the same key).
Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
`TOKENS.Relay` (a key of a module-level const table) also matched class Relay by dropping the table's name, and impact answered 'more than one kind'. A field whose display is the spelling now wins over a type found only by dropping the leading segment, as a method already did. Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
`constructor(@Inject(TOKENS.Store) store)` binds the constructor to the token, but the read was credited to the module that evaluates the decorator, so `impact TOKENS.Store` named the file instead of the class. A parameter decorator's owner is the parameter; its method is the reader, as for a method's own decorator. Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
`constructor(topic = TOPICS.payments)` evaluates the default on every call that omits it, but the read was placed in the module initializer, so the constructor was missing from the key's readers. A parameter's default expression is now its method's, unless a function written as the default already owns the read. Reads in a decorator no longer also add a module row. Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
…the compiler names it
The fields scorer labelled a key of a module-level `const X = { a: … }` as
`X#a` (its owner is the variable, which is no type). The compiler side names
the nearest enclosing named declaration and the module otherwise, so every
correct read scored as one wrong plus one missing. Label it by its module.
- 78-cross-process-destinations: fields 0/1 -> 1/1 correct, 0 wrong
- 80-object-literal-member-receivers: fields 0/9 -> 3/9 correct, 0 wrong
Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
…eclaration landed The index declared data keys of TypeScript const literals too, so after merging, an annotated const's keys were declared a second time beside the type's member. The parser now owns TypeScript's keys; the index keeps them for JavaScript. - index: no TypeScript consts predicate (the parser declares those keys) - parser: a const annotated with a type that names no member (Record<K, V>, through Readonly/Partial/Required, or index signatures only) declares its literal's keys, as an unannotated one does - impact.dl: keep both the key-declaration-line and other-table-line rules - suite: fixture 86's const-table reads now resolve (fields recall 0.50 -> 0.92) Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
6a36a93 to
47bcadc
Compare
|
Rebased on apps/integration-0.1.9, which had meanwhile gained an index-side declaration of const-literal keys.
Checked: TS cases 243/243, JS cases 285/285, TS suite 100/100, parser TS tests 49/49. On the product, probes were 52/74 before and after. Field reads at known_edge went from 2160 to 2417, and index time was 29.3s before and 29.2s after. |
Keys of
export const TOPICS = { a: '…' } as const(topic, route, event-type and token tables) were declared nowhere:impact TOPICS.aanswered "nothing named" and readers of one key could not be told from another's.as const,satisfies, parens,Object.freeze) emits each data key as a field of the variable; nested literals nest.X.aresolves to that key through the variable, an import, a namespace import or an outer key, only when the typed lookup found nothing (satisfies Tkeeps T's member).TOKENS.Relay) answers as the key; two tables with the same key in one file stay apart.Checked: TS engine suite 99/99; golden cases TS 225/225, JS 277, Python 278, Java 306, C# 207 all pass. Product probes 47 → 52/74, 0 regressed; call edges unchanged (10045), field reads resolved 2196 → 2453.