-
-
Save paulshen/7c13f7059615d95022c98e817cae8c01 to your computer and use it in GitHub Desktop.
Natto Solid imports transformation plugin
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
export default function transformImportsPlugin({ types }) { | |
return { | |
visitor: { | |
ImportDeclaration(path) { | |
const importSource = path.node.source.value | |
if (importSource !== "solid-js/web") return | |
const solidWebIdentifier = types.Identifier("solidjsWeb") | |
for (const specifier of path.node.specifiers) { | |
const specifierName = specifier.imported.name; | |
for (const referencePath of path.scope.bindings[specifierName].referencePaths) { | |
referencePath.replaceWith( | |
types.MemberExpression(solidWebIdentifier, referencePath.node) | |
) | |
} | |
} | |
path.remove() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment