Skip to content

Commit

Permalink
fix: repair more problem with default imports
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Aug 11, 2024
1 parent c66f44c commit 9986655
Showing 1 changed file with 12 additions and 2 deletions.
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';
```

0 comments on commit 9986655

Please sign in to comment.