-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tailwind styling support to resolvedNode rendering
- Loading branch information
Showing
8 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/noya-compiler/src/__tests__/__snapshots__/compile.test.ts.snap
This file contains 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
This file contains 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
This file contains 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
40 changes: 40 additions & 0 deletions
40
packages/noya-compiler/src/passes/removeEmptyClassNames.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as ts from 'typescript'; | ||
|
||
export function removeEmptyClassNames( | ||
sourceFile: ts.SourceFile, | ||
): ts.SourceFile { | ||
const transformer: ts.TransformerFactory<ts.SourceFile> = (context) => { | ||
const visitor: ts.Visitor = (node: ts.Node): ts.VisitResult<ts.Node> => { | ||
// Check if the node is a JSX attribute | ||
if (ts.isJsxAttribute(node)) { | ||
// Check if the attribute name is 'className' | ||
if (node.name.escapedText === 'className') { | ||
// Check if the initializer is a string literal with an empty value | ||
if ( | ||
node.initializer && | ||
ts.isStringLiteral(node.initializer) && | ||
node.initializer.text === '' | ||
) { | ||
// Return nothing to remove the attribute | ||
return; | ||
} | ||
} | ||
} | ||
|
||
// Visit children of the node | ||
return ts.visitEachChild(node, visitor, context); | ||
}; | ||
|
||
// Apply the visitor to the source file | ||
return (node) => ts.visitNode(node, visitor); | ||
}; | ||
|
||
// Perform the transformation | ||
const result = ts.transform<ts.SourceFile>(sourceFile, [transformer]); | ||
const transformedSourceFile = result.transformed[0]; | ||
|
||
// Clean up | ||
result.dispose(); | ||
|
||
return transformedSourceFile; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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