unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.89k stars 496 forks source link

ObjectExpression AST - Keys without .name property result in undefined #2564

Closed Saganic closed 3 months ago

Saganic commented 3 months ago

Environment

Nitro: Nightly Node: v21.7.3

Reproduction

The easiest way to replicate this issue is

  1. Create a new Nitro or Nuxt project
  2. Create a new api route
  3. Use defineRouteMeta and define a key that is 'number-like',

For example: defineRouteMeta({ "myKey": "this works!", "200": "this does not", 200: "neither does this" })

Describe the bug

After doing the repro

  1. npm run dev

  2. Inspect the built code at .nitro/dev/index.mjs and notice that your handlersMeta.meta looks like this: const [handlerUid] = {"myKey":"this works!","undefined":"neither does this"};

Additional context

The issue appears to be from this line: https://github.com/unjs/nitro/blob/5bcc0a2b951cbcafb9eec9fe62ddb949d1accad8/src/rollup/plugins/handlers-meta.ts#L84

Where ObjectExpressions that don't return a .name property are keyed as undefined. A possible fix could be to check for .value as well.