Skip to content

Commit

Permalink
fix(resolver): directory import nested ".."
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Aug 1, 2024
1 parent 3cf0b6a commit 2fada74
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const createImplicitResolver = (
): SimpleResolve => (
request,
) => {
if (request === '.' || request === '..') {
if (request === '.' || request === '..' || request.endsWith('/..')) {
request += '/';
}

Expand Down
2 changes: 1 addition & 1 deletion src/esm/hook/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const resolveDirectory: ResolveHook = async (
context,
nextResolve,
) => {
if (specifier === '.' || specifier === '..') {
if (specifier === '.' || specifier === '..' || specifier.endsWith('/..')) {
specifier += '/';
}

Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ export const files = {
`,

'period.in.name.ts': 'export { a } from "."',
'dotdot/index.ts': 'export { a } from ".."',
dotdot: {
'index.ts': 'export { a } from ".."',
'dotdot/index.ts': 'export { a } from "../.."',
},

'index.js': 'throw new Error("should not be loaded")',
},
Expand Down
1 change: 1 addition & 0 deletions tests/specs/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export default testSuite(async ({ describe }, { tsx, supports, version }: NodeAp
import './ts/period.in.name';
import '@/ts/period.in.name';
import './ts/dotdot';
import './ts/dotdot/dotdot';
// .jsx
import * as jsx from './jsx/index.jsx';
Expand Down

0 comments on commit 2fada74

Please sign in to comment.