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

[lint.Plugin] Pattern { a = b } is parsed as { a: b } #28399

Closed
phaux opened this issue Mar 5, 2025 · 0 comments · Fixed by #28402
Closed

[lint.Plugin] Pattern { a = b } is parsed as { a: b } #28399

phaux opened this issue Mar 5, 2025 · 0 comments · Fixed by #28402
Assignees
Labels
lint Issues related to deno lint

Comments

@phaux
Copy link

phaux commented Mar 5, 2025

Version: canary

import { assertEquals } from "jsr:@std/[email protected]";

Deno.test("default", () => {
  const diagnostics = Deno.lint.runPlugin(
    {
      name: "test",
      rules: {
        "rule": {
          create: (ctx) => ({
            Property(node) {
              console.log(node);
              if (node.value.type === "AssignmentPattern") {
                ctx.report({ node, message: "Unexpected =" });
              }
            },
          }),
        },
      },
    },
    "test.ts",
    "({ a = b } = {})",
  );
  assertEquals(diagnostics.length, 1);
});

Run with deno test.

Correct AST should be same as for { a: a = b } where both a's are the same node:

{
  "type": "ObjectPattern",
  "properties": [
    {
      "type": "Property",
      "key": {
        "type": "Identifier",
        "name": "a",
      },
      "kind": "init",
      "shorthand": true,
      "value": {
        "type": "AssignmentPattern",
        "left": {
          "type": "Identifier",
          "name": "a",
        },
        "optional": false,
        "right": {
          "type": "Identifier",
          "name": "b",
        }
      }
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lint Issues related to deno lint
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants