Skip to content

Commit

Permalink
Do more with a regex
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Sep 24, 2024
1 parent e828dac commit a55e9f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
11 changes: 3 additions & 8 deletions tslib.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,9 @@ export function __rewriteRelativeImportExtension(path, preserveJsx) {
if (path.substring(path.length - 4).toLowerCase() === ".tsx") {
return path.substring(0, path.length - 4) + (preserveJsx ? ".jsx" : ".js");
}
var extMatch = path.match(/\.[cm]?ts$/i);
if (extMatch) {
var ext = extMatch[0].toLowerCase();
var dot = path.lastIndexOf(".", path.length - (ext.length + 1));
if (dot < 0 || !(path.substring(dot - 2, dot).toLowerCase() === ".d" || path.substring(dot, dot + 2).toLowerCase() === ".d")) {
return path.substring(0, path.length - ext.length) + (ext === ".mts" ? ".mjs" : ext === ".cts" ? ".cjs" : ".js");
}
}
return path.replace(/(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, d, ext, cm) {
return d && (ext && !cm || !ext) ? m : ("." + (cm || "").toLowerCase() + "js");
});
}
return path;
}
Expand Down
11 changes: 3 additions & 8 deletions tslib.es6.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,9 @@ export function __rewriteRelativeImportExtension(path, preserveJsx) {
if (path.substring(path.length - 4).toLowerCase() === ".tsx") {
return path.substring(0, path.length - 4) + (preserveJsx ? ".jsx" : ".js");
}
var extMatch = path.match(/\.[cm]?ts$/i);
if (extMatch) {
var ext = extMatch[0].toLowerCase();
var dot = path.lastIndexOf(".", path.length - (ext.length + 1));
if (dot < 0 || !(path.substring(dot - 2, dot).toLowerCase() === ".d" || path.substring(dot, dot + 2).toLowerCase() === ".d")) {
return path.substring(0, path.length - ext.length) + (ext === ".mts" ? ".mjs" : ext === ".cts" ? ".cjs" : ".js");
}
}
return path.replace(/(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, d, ext, cm) {
return d && (ext && !cm || !ext) ? m : ("." + (cm || "").toLowerCase() + "js");
});
}
return path;
}
Expand Down
11 changes: 3 additions & 8 deletions tslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,9 @@ var __rewriteRelativeImportExtension;
if (path.substring(path.length - 4).toLowerCase() === ".tsx") {
return path.substring(0, path.length - 4) + (preserveJsx ? ".jsx" : ".js");
}
var extMatch = path.match(/\.[cm]?ts$/i);
if (extMatch) {
var ext = extMatch[0].toLowerCase();
var dot = path.lastIndexOf(".", path.length - (ext.length + 1));
if (dot < 0 || !(path.substring(dot - 2, dot).toLowerCase() === ".d" || path.substring(dot, dot + 2).toLowerCase() === ".d")) {
return path.substring(0, path.length - ext.length) + (ext === ".mts" ? ".mjs" : ext === ".cts" ? ".cjs" : ".js");
}
}
return path.replace(/(\.d)?(\.[^./]+?)?\.([cm])?ts$/i, function (m, d, ext, cm) {
return d && (ext && !cm || !ext) ? m : ("." + (cm || "").toLowerCase() + "js");
});
}
return path;
};
Expand Down

0 comments on commit a55e9f7

Please sign in to comment.