Skip to content

Plugin loading is incorrectly memoized #13235

@thorn0

Description

@thorn0

Environments:

  • Prettier Version: next
  • Running Prettier via: API
  • Runtime: Node 18
  • Operating System: WSL
  • Prettier plugins (if any): custom

Steps to reproduce:

import * as prettier from "prettier";

console.log(
  await prettier.format(".", {
    plugins: [
      { parsers: { baz: { parse: () => ({}), astFormat: "baz-ast" } } },
      { printers: { "baz-ast": { print: () => "1" } } },
    ],
    parser: "baz",
  }),
  await prettier.format(".", {
    plugins: [
      { parsers: { baz: { parse: () => ({}), astFormat: "baz-ast" } } },
      { printers: { "baz-ast": { print: () => "2" } } },
    ],
    parser: "baz",
  })
);

The problem is here:

const memoizedLoad = mem(load, { cacheKey: JSON.stringify });

Both plugins are serialized to the same string by JSON.stringify.

Expected output: 1 2

Actual output: 1 1

Metadata

Metadata

Assignees

Labels

area:apiIssues with Prettier's Application Programming Interfacearea:plugin apilocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions