Skip to content

Commit

Permalink
fix: source import aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
johngeorgewright committed Jul 19, 2021
1 parent a19fe05 commit 49139e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export default async function* generate(
path.relative(targetDir, sourceDir) || '.'
}/${sourceBaseName}`
targetFile.addImportDeclaration({
namedImports: [...sourceImports],
namedImports: [...sourceImports].map((name) => ({
name,
alias: `_${name}`,
})),
moduleSpecifier,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/writeRuntype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function* generateEnumType(type: Type): RuntypeGenerator {
yield [ImportFromSource, name]
yield [
Write,
`Guard((x: any): x is ${name} => Object.values(${name}).includes(x))`,
`Guard((x: any): x is _${name} => Object.values(_${name}).includes(x))`,
]
}

Expand Down
6 changes: 3 additions & 3 deletions test/enum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import generateFixture from './generateFixture'
test('enum', async () => {
expect((await generateFixture('enum', ['A', 'B'])).getText())
.toMatchInlineSnapshot(`
"import { A, B } from './enum';
"import { A as _A, B as _B } from './enum';
import { Guard, Static } from 'runtypes';
export const A = Guard((x: any): x is A => Object.values(A).includes(x));
export const A = Guard((x: any): x is _A => Object.values(_A).includes(x));
export type A = Static<typeof A>;
export const B = Guard((x: any): x is B => Object.values(B).includes(x));
export const B = Guard((x: any): x is _B => Object.values(_B).includes(x));
export type B = Static<typeof B>;
"
Expand Down

0 comments on commit 49139e1

Please sign in to comment.