MCPcopy
hub / github.com/tailwindlabs/prettier-plugin-tailwindcss / transformLiquid

Function transformLiquid

src/index.ts:308–404  ·  view source on GitHub ↗
(ast: any, env: TransformerEnv)

Source from the content-addressed store, hash-verified

306}
307
308function transformLiquid(ast: any, env: TransformerEnv) {
309 let { matcher } = env
310
311 function isClassAttr(node: { name: string | { type: string; value: string }[] }) {
312 return Array.isArray(node.name)
313 ? node.name.every((n) => n.type === 'TextNode' && matcher.hasStaticAttr(n.value))
314 : matcher.hasStaticAttr(node.name)
315 }
316
317 function hasSurroundingQuotes(str: string) {
318 let start = str[0]
319 let end = str[str.length - 1]
320
321 return start === end && (start === '"' || start === "'" || start === '`')
322 }
323
324 let sources: { type: string; source: string }[] = []
325
326 let changes: StringChange[] = []
327
328 function sortAttribute(attr: Liquid.AttrSingleQuoted | Liquid.AttrDoubleQuoted) {
329 for (let i = 0; i < attr.value.length; i++) {
330 let node = attr.value[i]
331 if (node.type === 'TextNode') {
332 let after = sortClasses(node.value, {
333 env,
334 ignoreFirst: i > 0 && !/^\s/.test(node.value),
335 ignoreLast: i < attr.value.length - 1 && !/\s$/.test(node.value),
336 removeDuplicates: false,
337 collapseWhitespace: false,
338 })
339
340 changes.push({
341 start: node.position.start,
342 end: node.position.end,
343 before: node.value,
344 after,
345 })
346 } else if (
347 // @ts-ignore: `LiquidDrop` is for older versions of the liquid plugin (1.2.x)
348 (node.type === 'LiquidDrop' || node.type === 'LiquidVariableOutput') &&
349 typeof node.markup === 'object' &&
350 node.markup.type === 'LiquidVariable'
351 ) {
352 visit(node.markup.expression, {
353 String(node: any) {
354 let pos = { ...node.position }
355
356 // We have to offset the position ONLY when quotes are part of the String node
357 // This is because `value` does NOT include quotes
358 if (hasSurroundingQuotes(node.source.slice(pos.start, pos.end))) {
359 pos.start += 1
360 pos.end -= 1
361 }
362
363 let after = sortClasses(node.value, { env })
364
365 changes.push({

Callers

nothing calls this directly

Calls 2

visitFunction · 0.85
spliceChangesIntoStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…