Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: repair more problem with default imports #234

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .grit/patterns/js/_convert_default_imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ pattern replace_default_import($source, $new_name) {
$imports <: contains `default` => $new_name
},
`import $alias, { $imports } from $source` => `import { $imports } from $source` where {
$alias <: not .,
if ($alias <: $new_name) {
$imports += `, $new_name`,
} else {
$imports += `, $new_name as $alias`
}
},
`import $alias from $source` as $import where {
if ($alias <: contains $new_name) {
`import $clause from $source` as $import where {
$clause <: import_clause(default=$alias),
$alias <: not .,
if ($alias <: $new_name) {
$import => `import { $new_name } from $source`
} else {
$import => `import { $new_name as $alias } from $source`
Expand Down Expand Up @@ -193,3 +196,10 @@ export { namedImport as name1 } from 'here';
export { namedImport, otherImport } from 'here';
export { otherImport, namedImport as name2 } from 'here';
```

## Leave non-default imports unchanged

```ts
import { namedImport } from 'here';
import { twoPartImport, namedImport as alias } from 'here';
```
Loading