Fix "Missing visitor keys for 'undefined'" error with multiple Prettier copies - #470
Open
Mohith26 wants to merge 2 commits into
Open
Fix "Missing visitor keys for 'undefined'" error with multiple Prettier copies#470Mohith26 wants to merge 2 commits into
Mohith26 wants to merge 2 commits into
Conversation
…er copies The plugin resolves `prettier/plugins/html` from its own dependency tree to obtain the parsers it wraps, but it did not export a matching printer, so the AST was printed by the running Prettier's builtin HTML printer. When a dependency tree contains more than one copy of Prettier straddling the v3.7 boundary (where the HTML AST discriminator was renamed from `type` to `kind`), the printer receives nodes whose discriminator it cannot read and throws "Missing visitor keys for 'undefined'". Export the HTML printer from the same `prettier/plugins/html` module the parsers are loaded from - mirroring the existing `svelte-ast` printer export - so the parser and printer always agree on the AST shape. Fixes tailwindlabs#469
…dlabs#469) Adds a fixture with its own `prettier@3.6.2` install. The test copies the built plugin next to it so the plugin resolves the fixture's Prettier copy while the repo's Prettier CLI formats the file, reproducing the mismatched setup from the issue. Without the fix this fails with "Missing visitor keys for 'undefined'".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #469, reported by @leonwissenberg, with the key reproduction detail from @ChrisMBarr's report in prettier/eslint-plugin-prettier#771.
The plugin wraps parsers it loads from
prettier/plugins/htmlresolved from its own dependency tree, but exported no printer, so the AST was printed by the running Prettier's builtin HTML printer. Prettier 3.7 renamed the HTML AST discriminator fromtypetokind, so any node_modules tree containing two Prettier copies straddling that boundary makes the printer see undefined node types and throw "Missing visitor keys for 'undefined'". That is why the error appeared after a 3.6 -> 3.7 upgrade and vanished on fresh installs.The fix adds the html printer to the plugin's exports (mirroring the existing
svelte-astpattern), so parser and printer always come from the sameprettier/plugins/htmlmodule instance regardless of which Prettier copy the plugin resolves.CHANGELOG entry added under Unreleased. A new fixture test reproduces the real-world mismatch (repo CLI Prettier vs a fixture-local
prettier@3.6.2) and fails with the exact reported error without the fix. Suite: 112 passed, zero new failures; knip/oxlint clean.