Skip to content

Commit

Permalink
fix: fix import replacement for jsx elements
Browse files Browse the repository at this point in the history
  • Loading branch information
finkef committed Oct 27, 2021
1 parent 08098af commit 35adec3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/__tests__/__fixtures__/provider-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { TailwindProvider } from "../../macro"

;<TailwindProvider />
14 changes: 14 additions & 0 deletions src/__tests__/__snapshots__/macro.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,20 @@ const _useStyles = _ReactNativeTailwindMacro.createUseTailwindStyles({
})
`;
exports[`react-native-tailwind.macro provider-import.js: provider-import.js 1`] = `
import { TailwindProvider } from "../../macro"
;<TailwindProvider />
↓ ↓ ↓ ↓ ↓ ↓
import * as _ReactNativeTailwindMacro from "../../macro/exports"
;<_ReactNativeTailwindMacro.TailwindProvider />
`;
exports[`react-native-tailwind.macro reference-style-prop.js: reference-style-prop.js 1`] = `
Expand Down
18 changes: 13 additions & 5 deletions src/macro/handle-lib-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ export function handleLibImport(params: HandlerParams<Node>) {
throw new MacroError(`Invalid import "${importName}"`)

// Replace with imported version
path.replaceWith(
t.memberExpression(
t.identifier(program.state.importIdentifier),
t.identifier(importName)
if (path.isJSXIdentifier())
path.replaceWith(
t.jsxMemberExpression(
t.jsxIdentifier(program.state.importIdentifier),
t.jsxIdentifier(importName)
)
)
else
path.replaceWith(
t.memberExpression(
t.identifier(program.state.importIdentifier),
t.identifier(importName)
)
)
)
}

0 comments on commit 35adec3

Please sign in to comment.