Skip to content

Instantly share code, notes, and snippets.

@orenelbaum
Last active October 13, 2021 15:55
Show Gist options
  • Save orenelbaum/797fdf33244efceae0da52663ed0c090 to your computer and use it in GitHub Desktop.
Save orenelbaum/797fdf33244efceae0da52663ed0c090 to your computer and use it in GitHub Desktop.
Natto Solid imports transformation plugin
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