Skip to content

Commit

Permalink
Test and fix invalid declaration-looking extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Sep 24, 2024
1 parent a55e9f7 commit 1c03288
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions test/node/rewriteRelativeImportExtension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ testHelper("__rewriteRelativeImportExtension", __rewriteRelativeImportExtension
assert.equal(__rewriteRelativeImportExtension("../../foo.ts"), "../../foo.js");
assert.equal(__rewriteRelativeImportExtension("./foo.TS"), "./foo.js");
assert.equal(__rewriteRelativeImportExtension("./foo.Ts"), "./foo.js");
assert.equal(__rewriteRelativeImportExtension("./foo/.hidden/foo.ts"), "./foo/.hidden/foo.js");
});

test("rewrites other TypeScript extensions", () => {
Expand All @@ -17,6 +18,8 @@ testHelper("__rewriteRelativeImportExtension", __rewriteRelativeImportExtension
assert.equal(__rewriteRelativeImportExtension("./foo.tsx"), "./foo.js");
assert.equal(__rewriteRelativeImportExtension("./foo.tsx", true), "./foo.jsx");
assert.equal(__rewriteRelativeImportExtension("./foo.Tsx", true), "./foo.jsx");
assert.equal(__rewriteRelativeImportExtension("./foo.d.css.mts"), "./foo.d.css.mjs");
assert.equal(__rewriteRelativeImportExtension("./foo.d.tsx"), "./foo.d.js");
});

test("does not rewrite other extensions", () => {
Expand Down
2 changes: 1 addition & 1 deletion tslib.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export function __rewriteRelativeImportExtension(path, preserveJsx) {
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 : ("." + (cm || "").toLowerCase() + "js");
return d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
});
}
return path;
Expand Down
2 changes: 1 addition & 1 deletion tslib.es6.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export function __rewriteRelativeImportExtension(path, preserveJsx) {
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 : ("." + (cm || "").toLowerCase() + "js");
return d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
});
}
return path;
Expand Down
2 changes: 1 addition & 1 deletion tslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ var __rewriteRelativeImportExtension;
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 : ("." + (cm || "").toLowerCase() + "js");
return d && (ext && !cm || !ext) ? m : ((d || "") + (ext || "") + "." + (cm || "").toLowerCase() + "js");
});
}
return path;
Expand Down

0 comments on commit 1c03288

Please sign in to comment.