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

Introduce prePrint property to plugin #13827

Open
fisker opened this issue Nov 11, 2022 · 0 comments
Open

Introduce prePrint property to plugin #13827

fisker opened this issue Nov 11, 2022 · 0 comments
Labels
area:api Issues with Prettier's Application Programming Interface area:plugin api status:needs discussion Issues needing discussion and a decision to be made before action can be taken

Comments

@fisker
Copy link
Member

fisker commented Nov 11, 2022

Plugins can have a prePrint property, which replaces current embed, and it works same as embed. Only difference we'll traverse AST and call prePrint.print of ALL plugins that matches the astFormat.

Before calling printer.print, we traverse AST, and collect all functions returned by prePrint.print, then call them in order, use the first doc these functions returns.

A plugin with prePrint looks like this.

export default {
	prePrint: {
		estree: {
			print(path, print, textToDoc, options) {
				if (isRustTemplate(path)) {
					return () => textToDoc(text, {parser: 'rust'})
				}
			},
		},
	},
};

I think this will partly solve #10803.

This still not allow multiple plugins format the same node.

@fisker fisker added status:needs discussion Issues needing discussion and a decision to be made before action can be taken area:api Issues with Prettier's Application Programming Interface area:plugin api labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Issues with Prettier's Application Programming Interface area:plugin api status:needs discussion Issues needing discussion and a decision to be made before action can be taken
Projects
None yet
Development

No branches or pull requests

1 participant