Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseModule does not include object properties with quotes in their names #93

Closed
AriPerkkio opened this issue Nov 9, 2023 · 0 comments · Fixed by #94
Closed

parseModule does not include object properties with quotes in their names #93

AriPerkkio opened this issue Nov 9, 2023 · 0 comments · Fixed by #94

Comments

@AriPerkkio
Copy link
Contributor

Environment

$ node -v
v18.17.1

$ pnpm -v
8.7.5

$ cat package.json | grep magicast
    "magicast": "^0.3.1",

Reproduction

import { parseModule } from "magicast";

const mod = parseModule(`
export default defineConfig({
  test: {
    thisIsOk: {
      key: 111,
    },

    "thisIsBroken": {
      key: 222,
    },

    'thisIsAlsoBroken': {
      key: 333,
    },
  },
});
`);

const options =
  mod.exports.default.$type === "function-call"
    ? mod.exports.default.$args[0]
    : mod.exports.default;

console.log("test.thisIsOk", options.test.thisIsOk?.key); // ✅
console.log("test.thisIsBroken", options.test.thisIsBroken?.key); // ❌
console.log("test.thisIsAlsoBroken", options.test.thisIsAlsoBroken?.key); // ❌

// Let's see if quotes are included in key names...
console.log("test.thisIsBroken#2", options.test['"thisIsBroken"']?.key); // ❌
console.log("test.thisIsAlsoBroken#2", options.test["'thisIsAlsoBroken'"]?.key); // ❌
test.thisIsOk 111
test.thisIsBroken undefined
test.thisIsAlsoBroken undefined
test.thisIsBroken#2 undefined
test.thisIsAlsoBroken#2 undefined

Describe the bug

It's not possible to access object properties that have quotes in their property names. Properties without quotes work fine.

In my use-case object properties can be glob-patterns so they need to be wrapped. Object keys like "**/utils/**" must be wrapped:

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    coverage: {
      thresholds: {
        // Thresholds for all files
        lines: 100,
        functions: 100,
        branches: 80,
        statements: 90,

        // Thresholds for utilities
        "**/utils/**": {
          lines: 80,
          statements: 50,
        },
      },
    },
  },
});

Additional context

vitest-dev/vitest#4442

Logs

No response

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 a pull request may close this issue.

1 participant