Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paulshen/7c13f7059615d95022c98e817cae8c01 to your computer and use it in GitHub Desktop.
Save paulshen/7c13f7059615d95022c98e817cae8c01 to your computer and use it in GitHub Desktop.
Natto Solid imports transformation plugin
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