Skip to content

Commit

Permalink
fix: support auto import for variables
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 29, 2022
1 parent a8d17c2 commit 4059581
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function createUnimport (opts: Partial<UnimportOptions>) {
.filter(i => !i.disabled)

// Create regex
ctx.matchRE = new RegExp(`(?:\\b|^)(${imports.map(i => escapeRE(i.as)).join('|')})(?:[.(\\)\\[\\]])`, 'g')
ctx.matchRE = new RegExp(`(?:\\b|^)(${imports.map(i => escapeRE(i.as)).join('|')})(?:[.(\\)\\[\\];])`, 'g')

// Create map
ctx.map.clear()
Expand All @@ -65,7 +65,10 @@ export function createUnimport (opts: Partial<UnimportOptions>) {
detectImports: (code: string) => detectImports(code, ctx),
injectImports: (code: string, mergeExisting?: boolean) => injectImports(code, ctx, mergeExisting),
toExports: () => toExports(ctx.imports),
generateTypeDecarations: (options?: TypeDeclrationOptions) => toTypeDeclrationFile(ctx.imports, options)
generateTypeDecarations: (options?: TypeDeclrationOptions) => toTypeDeclrationFile(ctx.imports, {
resolvePath: i => i.from.replace(/\.ts$/, ''),
...options
})
}
}

Expand Down

0 comments on commit 4059581

Please sign in to comment.