Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Sep 8, 2023
1 parent 17c8ce4 commit 48d5a27
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/babel-preset-typescript/src/plugin-rewrite-ts-imports.ts
Expand Up @@ -2,18 +2,20 @@ import { declare } from "@babel/helper-plugin-utils";
import type { types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";

export default declare(function () {
export default declare(function ({ types: t }) {
return {
name: "preset-typescript/plugin-rewrite-ts-imports",
visitor: {
"ImportDeclaration|ExportAllDeclaration|ExportNamedDeclaration"(
path: NodePath<
| t.ImportDeclaration
| t.ExportAllDeclaration
| t.ExportNamedDeclaration
>,
) {
const { source } = path.node;
if (source) {
"ImportDeclaration|ExportAllDeclaration|ExportNamedDeclaration"({
node,
}: NodePath<
t.ImportDeclaration | t.ExportAllDeclaration | t.ExportNamedDeclaration
>) {
const { source } = node;
const kind = t.isImportDeclaration(node)
? node.importKind
: node.exportKind;
if (kind === "value" && source && /[\\/]/.test(source.value)) {
source.value = source.value.replace(/(\.[mc]?)ts$/, "$1js");
}
},
Expand Down
@@ -1,3 +1,6 @@
import "./a.ts";
import "./a.mts";
import "./a.cts";
import "a-package/file.ts";
// Bare import, it's either a node package or remapped by an import map
import "soundcloud.ts";
@@ -1,3 +1,6 @@
import "./a.js";
import "./a.mjs";
import "./a.cjs";
import "a-package/file.js";
// Bare import, it's either a node package or remapped by an import map
import "soundcloud.ts";

0 comments on commit 48d5a27

Please sign in to comment.