Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Enables using enum members and const variables as computed keys in associative array literals via bracket syntax [expr]: value, similar to JavaScript/TypeScript computed property names.

Changes

AST & Parser

  • New AAIndexedMemberExpression node type for bracketed AA members
  • Parser handles [expression]: value syntax alongside existing identifier: value
  • Updated AALiteralExpression to accept both member types
  • Type guards and visitor support for new node

Validation & Resolution

  • Compile-time validation restricts bracket expressions to enum members and const variables only
  • Enum member values resolved via parser.references.enumStatementLookup
  • Const values resolved via parser.references.constStatementLookup
  • Diagnostic messages for invalid expressions and unresolvable keys (codes 1143, 1144)

Transpilation

  • Bracketed expressions transpile to string literal keys using resolved values
  • Comma handling for indexed members
  • Fallback error recovery if resolution fails

Example

enum Keys
    USER = "user_id"
    SESSION = "session_token"
end enum

const API_KEY = "api_key"

config = {
    [Keys.USER]: getUserId(),
    [Keys.SESSION]: getSession(),
    [API_KEY]: getApiKey(),
    timeout: 5000
}

Transpiles to:

config = {
    "user_id": getUserId(),
    "session_token": getSession(),
    "api_key": getApiKey(),
    timeout: 5000
}

Testing

  • 14 parser tests (syntax variations, nesting, error cases)
  • 9 validation tests (resolution, diagnostics)
  • 4 transpilation tests (output correctness)
Original prompt

This section details on the original issue you should resolve

<issue_title>Using Enums and constants as keys when explicitly declaring AAs</issue_title>
<issue_description>It would be very useful to be able to use enums or constants as keys when explicitly declaring AAs
for example

enum myEnum 
    KEY = "key1"
end enum 

myAA = { 
    myEnum.KEY: "value1"
} 

I know some languages use the following syntax, so it may be convenient to follow suit

myAA = { 
    [myEnum.KEY]: "value1"
} 
```</issue_description>

<agent_instructions>
Considerations:
- the only expressions we should currently support are: enums and consts. all other expressions are NOT permitted inside the brackets of an AA
- those expressions must be resolved at compile time
- let's make a new ast node type called AAIndexedMemberExpression so we don't break backwards compatibility with the existing AAMemberExpression
- we need explicit validation around only using enum members and consts inside those brackets at validation time
- we need compile-time resolution of the expressions in brackets
- extensive uint tests verifying AA literals work in all sorts of situations with these. (brackets at the start, brackets in the middle, brackets in the end, aa inside aa inside aa with brackets the whole way down, etc
- hover support for the expressions inside those brackets</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits October 30, 2025 20:04
… syntax in AA literals

Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
…solution

Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for enums and constants as keys in AAs Support enum members and const variables as AA literal keys with bracket syntax Oct 30, 2025
Copilot AI requested a review from TwitchBronBron October 30, 2025 20:31
@TwitchBronBron TwitchBronBron added the create-package create a temporary npm package on every commit label Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-package create a temporary npm package on every commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using Enums and constants as keys when explicitly declaring AAs

2 participants