Skip to content

fix: keep the import attributes of an import type - #250

Open
GBra-4-669 wants to merge 1 commit into
sveltejs:mainfrom
GBra-4-669:fix/import-type-attributes
Open

GBra-4-669 wants to merge 1 commit into
sveltejs:mainfrom
GBra-4-669:fix/import-type-attributes

Conversation

@GBra-4-669

Copy link
Copy Markdown

Closes #231

TSImportType never visits options, so import attributes are dropped:

type B = import("pkg", { with: { "resolution-mode": "require" } }).Mode<string>;
// printed as: type B = import("pkg").Mode<string>;

That changes the meaning, not just the formatting, since resolution-mode affects which declarations TypeScript resolves.

The fix prints options inside the parens, same as the ImportExpression visitor already does. I also checked it against typescript-estree (the reporter's parser), not just oxc. The repro goes from 1 identical / 4 wrong to 5 identical / 0 wrong.

The tests use oxc-parser because acorn-typescript can't parse attributes on an import type.

@pkg-svelte-dev

Copy link
Copy Markdown

Install the latest version of esrap from 265c754:

pnpm add https://pkg.svelte.dev/esrap/c/265c75452192b644474127a3f9d04abe97a7b02e

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/esrap/pr/250

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TSImportType drops the import attributes (options)

1 participant