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

Function transformJavaScript

src/index.ts:613–682  ·  view source on GitHub ↗
(ast: import('@babel/types').Node, env: TransformerEnv)

Source from the content-addressed store, hash-verified

611// We cross several parsers that share roughly the same shape so things are
612// good enough. The actual AST we should be using is probably estree + ts.
613function transformJavaScript(ast: import('@babel/types').Node, env: TransformerEnv) {
614 let { matcher } = env
615
616 function sortInside(ast: import('@babel/types').Node) {
617 visit(ast, (node, path) => {
618 let collapseWhitespace = canCollapseWhitespaceIn(path, env)
619
620 if (isStringLiteral(node)) {
621 sortStringLiteral(node, { env, collapseWhitespace })
622 } else if (node.type === 'TemplateLiteral') {
623 sortTemplateLiteral(node, { env, collapseWhitespace })
624 } else if (node.type === 'TaggedTemplateExpression') {
625 if (isSortableTemplateExpression(node, matcher)) {
626 sortTemplateLiteral(node.quasi, { env, collapseWhitespace })
627 }
628 }
629 })
630 }
631
632 visit(ast, {
633 JSXAttribute(node) {
634 node = node as import('@babel/types').JSXAttribute
635
636 if (!node.value) {
637 return
638 }
639
640 // We don't want to support namespaced attributes (e.g. `somens:class`)
641 // React doesn't support them and most tools don't either
642 if (typeof node.name.name !== 'string') {
643 return
644 }
645
646 if (!matcher.hasStaticAttr(node.name.name)) {
647 return
648 }
649
650 if (isStringLiteral(node.value)) {
651 sortStringLiteral(node.value, { env })
652 } else if (node.value.type === 'JSXExpressionContainer') {
653 sortInside(node.value)
654 }
655 },
656
657 CallExpression(node) {
658 node = node as import('@babel/types').CallExpression
659
660 if (!isSortableCallExpression(node, matcher)) {
661 return
662 }
663
664 node.arguments.forEach((arg) => sortInside(arg))
665 },
666
667 TaggedTemplateExpression(node, path) {
668 node = node as import('@babel/types').TaggedTemplateExpression
669
670 if (!isSortableTemplateExpression(node, matcher)) {

Callers

nothing calls this directly

Calls 1

visitFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…