Skip to content

Commit

Permalink
chore: code format
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Aug 26, 2023
1 parent c1e1ceb commit 61a9fe5
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/generate-import.ts
Expand Up @@ -35,17 +35,15 @@ export function generateImport(analyzed: Analyzed, id: string, rules?: ImportTyp
${'^'.repeat(codeSnippets.length)}`)
}

// This is probably less accurate but is much cheaper than a full AST parse.
// This is probably less accurate, but is much cheaper than a full AST parse.
let importType: ImportType = 'defaultFirst'
if (rules) {
if (typeof rules === 'string') {
importType = rules
}
if (typeof rules === 'function') {
importType = rules(id) || 'defaultFirst'
}
if (typeof rules === 'string') {
importType = rules
} else if (typeof rules === 'function') {
importType = rules(id) || 'defaultFirst'
}
impt.importExpression = `import * as ${importName} from '${requireId}'`

impt.importExpression = `import * as ${importName} from "${requireId}"`
switch (importType) {
case 'defaultFirst':
impt.importedName = `${importName}.default || ${importName}`
Expand All @@ -54,7 +52,7 @@ export function generateImport(analyzed: Analyzed, id: string, rules?: ImportTyp
impt.importedName = `Object.keys(${importName}).join('') !== 'default' ? ${importName} : ${importName}.default`
break
case 'merge':
impt.importedName = `${importName}.default ? Object.assign(${importName}.default, ${importName}) : ${importName}`;
impt.importedName = `${importName}.default ? Object.assign(${importName}.default, ${importName}) : ${importName}`
break
default:
throw new Error(`Unknown import type: ${importType} for ${id}`)
Expand Down

0 comments on commit 61a9fe5

Please sign in to comment.