MCPcopy Index your code
hub / github.com/tailwindlabs/prettier-plugin-tailwindcss / createParser

Function createParser

src/create-plugin.ts:55–106  ·  view source on GitHub ↗
({
  name,
  original,
  opts,
}: {
  name: string
  original: Parser<any>
  opts: TransformOptions<any>
})

Source from the content-addressed store, hash-verified

53}
54
55async function createParser({
56 name,
57 original,
58 opts,
59}: {
60 name: string
61 original: Parser<any>
62 opts: TransformOptions<any>
63}) {
64 let parser: Parser<any> = { ...original }
65
66 async function load(options: ParserOptions<any>) {
67 let parser: Parser<any> = { ...original }
68
69 for (const pluginName of opts.compatible || []) {
70 let plugin = await findEnabledPlugin(options, pluginName)
71 if (plugin?.parsers?.[name]) Object.assign(parser, plugin.parsers[name])
72 }
73
74 return parser
75 }
76
77 parser.preprocess = async (code: string, options: ParserOptions) => {
78 let parser = await load(options)
79 return parser.preprocess ? parser.preprocess(code, options) : code
80 }
81
82 parser.parse = async (code, options) => {
83 let original = await load(options)
84
85 // @ts-expect-error: `options` is passed twice for compat with older plugins that were written
86 // for Prettier v2 but still work with v3.
87 //
88 // Currently only the Twig plugin requires this.
89 let ast = await original.parse(code, options, options)
90
91 let env = await loadTailwindCSS({ opts, options })
92
93 transformAst({
94 ast,
95 env,
96 opts,
97 options,
98 })
99
100 options.__tailwindcss__ = env
101
102 return ast
103 }
104
105 return parser
106}
107
108function createPrinter({
109 original,

Callers 1

createPluginFunction · 0.85

Calls 3

loadTailwindCSSFunction · 0.85
transformAstFunction · 0.85
loadFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…