mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
* chore: bundle babel-cli and babel-node * chore: bundle babel-helper-builder-react-jsx * refactor: unify extra entrypoints handling * chore: bundle babel-helper-transform-fixture-test-runner * chore: bundle babel-helper-fixtures * build: bundle babel-helpers * build: bundle babel-build-external-helpers * refactor: reuse pkgJSON in PackageInfo * refactor: skip inputs path normalization * build: bundle babel-eslint-parser * fixup babel-helpers * revert babel-cli bin changes * update npm-ignore generators * cleanup outdated comments * test(eslint): avoid private sub imports * chore: bundle babel-eslint-* * chore: bundle babel-register * chore: skip rollup for private packages
118 lines
3.4 KiB
JavaScript
118 lines
3.4 KiB
JavaScript
import tsRewriteRelativeImportExtensions from "../../lib/helpers/tsRewriteRelativeImportExtensions.js";
|
|
|
|
describe("tsRewriteRelativeImportExtensions", () => {
|
|
it.each([
|
|
// rewrite relative import
|
|
["./a.ts", "./a.js"],
|
|
["./a.cts", "./a.cjs"],
|
|
["./a.mts", "./a.mjs"],
|
|
["./a.tsx", "./a.js"],
|
|
|
|
// rewrite relative import from parent directory
|
|
["../a.ts", "../a.js"],
|
|
["../a.cts", "../a.cjs"],
|
|
["../a.mts", "../a.mjs"],
|
|
["../a.tsx", "../a.js"],
|
|
|
|
// rewrite transforms uppercase to lowercase
|
|
["./a.Ts", "./a.js"],
|
|
["./a.CTS", "./a.cjs"],
|
|
["./a.MTs", "./a.mjs"],
|
|
["./a.tSx", "./a.js"],
|
|
|
|
// keep .d.css.ts
|
|
["./.d.css.ts", "./.d.css.ts"],
|
|
// rewrite relative import containing .d
|
|
["./.d.css.cts", "./.d.css.cjs"],
|
|
["./.d.css.mts", "./.d.css.mjs"],
|
|
["./.d.css.tsx", "./.d.css.js"],
|
|
|
|
// rewrite relative import starting with .d
|
|
["./.dcss.ts", "./.dcss.js"],
|
|
["./.dcss.cts", "./.dcss.cjs"],
|
|
["./.dcss.mts", "./.dcss.mjs"],
|
|
["./.dcss.tsx", "./.dcss.js"],
|
|
|
|
// rewrite relative import containing .d and 3 extra extensions
|
|
["./.d.a.css.ts", "./.d.a.css.js"],
|
|
["./.d.a.css.cts", "./.d.a.css.cjs"],
|
|
["./.d.a.css.mts", "./.d.a.css.mjs"],
|
|
["./.d.a.css.tsx", "./.d.a.css.js"],
|
|
|
|
// rewrite relative import directory containing .d
|
|
["./.d/.css.ts", "./.d/.css.js"],
|
|
["./.d/.css.cts", "./.d/.css.cjs"],
|
|
["./.d/.css.mts", "./.d/.css.mjs"],
|
|
["./.d/.css.tsx", "./.d/.css.js"],
|
|
|
|
// skip d.ts, d.cts, and d.mts
|
|
["./a.d.ts", "./a.d.ts"],
|
|
["./a.d.cts", "./a.d.cts"],
|
|
["./a.d.mts", "./a.d.mts"],
|
|
// transform d.tsx
|
|
["./a.d.tsx", "./a.d.js"],
|
|
|
|
// skip bare .d.ts, .d.cts, and .d.mts
|
|
["./.d.ts", "./.d.ts"],
|
|
["./.d.cts", "./.d.cts"],
|
|
["./.d.mts", "./.d.mts"],
|
|
// transform bare .d.tsx
|
|
["./.d.tsx", "./.d.js"],
|
|
|
|
// skip absolute
|
|
["/a.ts", "/a.ts"],
|
|
["/a.cts", "/a.cts"],
|
|
["/a.mts", "/a.mts"],
|
|
["/a.tsx", "/a.tsx"],
|
|
|
|
// skip library
|
|
["a.ts", "a.ts"],
|
|
["a.cts", "a.cts"],
|
|
["a.mts", "a.mts"],
|
|
["a.tsx", "a.tsx"],
|
|
|
|
// skip dot-leading library
|
|
[".a.ts", ".a.ts"],
|
|
[".a.cts", ".a.cts"],
|
|
[".a.mts", ".a.mts"],
|
|
[".a.tsx", ".a.tsx"],
|
|
|
|
// skip non-terminal
|
|
["./a.ts.foo", "./a.ts.foo"],
|
|
["./a.cts.foo", "./a.cts.foo"],
|
|
["./a.mts.foo", "./a.mts.foo"],
|
|
["./a.tsx.foo", "./a.tsx.foo"],
|
|
|
|
// skip import path with windows path separator
|
|
// Node.js ESM does not support them either
|
|
[".\\a.ts", ".\\a.ts"],
|
|
[".\\a.cts", ".\\a.cts"],
|
|
[".\\a.mts", ".\\a.mts"],
|
|
[".\\a.tsx", ".\\a.tsx"],
|
|
])("%p -> %p", (input, result) => {
|
|
expect(tsRewriteRelativeImportExtensions(input)).toBe(result);
|
|
});
|
|
|
|
it.each([
|
|
// skip string wrapper object
|
|
[new String("./a.ts")],
|
|
[new String("./a.cts")],
|
|
[new String("./a.mts")],
|
|
[new String("./a.tsx")],
|
|
|
|
// skip toString() transforms
|
|
[{ [Symbol.toStringTag]: "./a.ts" }],
|
|
[{ [Symbol.toStringTag]: "./a.cts" }],
|
|
[{ [Symbol.toStringTag]: "./a.mts" }],
|
|
[{ [Symbol.toStringTag]: "./a.tsx" }],
|
|
|
|
// skip toPrimitive() calls
|
|
[{ [Symbol.toPrimitive]: () => "./a.ts" }],
|
|
[{ [Symbol.toPrimitive]: () => "./a.cts" }],
|
|
[{ [Symbol.toPrimitive]: () => "./a.mts" }],
|
|
[{ [Symbol.toPrimitive]: () => "./a.tsx" }],
|
|
])("should skip %p", input => {
|
|
expect(tsRewriteRelativeImportExtensions(input)).toBe(input);
|
|
});
|
|
});
|