Skip to content

Commit 9c731e9

Browse files
committed
Combine tsx case into regex
1 parent 1c03288 commit 9c731e9

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

tslib.es6.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,9 @@ export function __disposeResources(env) {
349349
}
350350

351351
export function __rewriteRelativeImportExtension(path, preserveJsx) {
352-
if (typeof path === "string" && path[0] === "." && (path[1] === "/" || path[1] === "." && path[2] === "/")) {
353-
if (path.substring(path.length - 4).toLowerCase() === ".tsx") {
354-
return path.substring(0, path.length - 4) + (preserveJsx ? ".jsx" : ".js");
355-
}
356-
return path.replace(/(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, d, ext, cm) {
357-
return d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
352+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
353+
return path.replace(/\.(tsx)$|(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, tsx, d, ext, cm) {
354+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
358355
});
359356
}
360357
return path;

tslib.es6.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,9 @@ export function __disposeResources(env) {
348348
}
349349

350350
export function __rewriteRelativeImportExtension(path, preserveJsx) {
351-
if (typeof path === "string" && path[0] === "." && (path[1] === "/" || path[1] === "." && path[2] === "/")) {
352-
if (path.substring(path.length - 4).toLowerCase() === ".tsx") {
353-
return path.substring(0, path.length - 4) + (preserveJsx ? ".jsx" : ".js");
354-
}
355-
return path.replace(/(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, d, ext, cm) {
356-
return d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
351+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
352+
return path.replace(/\.(tsx)$|(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, tsx, d, ext, cm) {
353+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
357354
});
358355
}
359356
return path;

tslib.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,9 @@ var __rewriteRelativeImportExtension;
397397
};
398398

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

0 commit comments

Comments
 (0)