Skip to content

Commit

Permalink
Combine tsx case into regex
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Sep 24, 2024
1 parent 1c03288 commit 9c731e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
9 changes: 3 additions & 6 deletions tslib.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,9 @@ export function __disposeResources(env) {
}

export function __rewriteRelativeImportExtension(path, preserveJsx) {
if (typeof path === "string" && path[0] === "." && (path[1] === "/" || path[1] === "." && path[2] === "/")) {
if (path.substring(path.length - 4).toLowerCase() === ".tsx") {
return path.substring(0, path.length - 4) + (preserveJsx ? ".jsx" : ".js");
}
return path.replace(/(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, d, ext, cm) {
return d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
if (typeof path === "string" && /^\.\.?\//.test(path)) {
return path.replace(/\.(tsx)$|(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, tsx, d, ext, cm) {
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
});
}
return path;
Expand Down
9 changes: 3 additions & 6 deletions tslib.es6.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,9 @@ export function __disposeResources(env) {
}

export function __rewriteRelativeImportExtension(path, preserveJsx) {
if (typeof path === "string" && path[0] === "." && (path[1] === "/" || path[1] === "." && path[2] === "/")) {
if (path.substring(path.length - 4).toLowerCase() === ".tsx") {
return path.substring(0, path.length - 4) + (preserveJsx ? ".jsx" : ".js");
}
return path.replace(/(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, d, ext, cm) {
return d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
if (typeof path === "string" && /^\.\.?\//.test(path)) {
return path.replace(/\.(tsx)$|(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, tsx, d, ext, cm) {
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
});
}
return path;
Expand Down
9 changes: 3 additions & 6 deletions tslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,9 @@ var __rewriteRelativeImportExtension;
};

__rewriteRelativeImportExtension = function (path, preserveJsx) {
if (typeof path === "string" && path[0] === "." && (path[1] === "/" || path[1] === "." && path[2] === "/")) {
if (path.substring(path.length - 4).toLowerCase() === ".tsx") {
return path.substring(0, path.length - 4) + (preserveJsx ? ".jsx" : ".js");
}
return path.replace(/(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, d, ext, cm) {
return d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
if (typeof path === "string" && /^\.\.?\//.test(path)) {
return path.replace(/\.(tsx)$|(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, tsx, d, ext, cm) {
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
});
}
return path;
Expand Down

0 comments on commit 9c731e9

Please sign in to comment.