Skip to content

Commit

Permalink
fix #22
Browse files Browse the repository at this point in the history
  • Loading branch information
mashaal committed Feb 19, 2022
1 parent ad06802 commit 4f26ac4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const transform = async (
(o.init as CallExpression)!.arguments?.forEach(({ expression }) => {
// @ts-ignore deno_swc doesn't have generics
const expressionBody = expression.body;

// inline imports
if (expressionBody?.callee?.value?.toLowerCase() === "import") {
expressionBody?.arguments?.forEach(
(b: {
Expand All @@ -63,6 +63,32 @@ const transform = async (
},
);
}
// function imports
const statements = expressionBody.stmts || [];
// @ts-ignore add typings for swc argument
statements.forEach(({ argument }) => {
if (argument?.callee?.value?.toLowerCase() === "import") {
argument?.arguments?.forEach(
(b: {
expression: {
value: string;
} & HasSpan;
}) => {
const { value, span } = b?.expression;
c += code.substring(offset - length, span.start - length);
c += `"${
value.replace(/\.(j|t)sx?/gi, () =>
`.js${
cacheBuster
? `?ts=${cacheBuster}`
: ""
}`)
}"`;
offset = span.end;
},
);
}
});
})
);
}
Expand Down

0 comments on commit 4f26ac4

Please sign in to comment.