Skip to content

Commit

Permalink
Refactor registerExtensions to reduce conditional branches
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed May 29, 2019
1 parent 56fe604 commit 28f22c9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,21 +436,21 @@ function registerExtensions (
register: Register,
originalJsHandler: (m: NodeModule, filename: string) => any
) {
if (!opts.preferTsExts) {
return extensions.forEach(ext => registerExtension(ext, ignore, register, originalJsHandler))
if (opts.preferTsExts) {
extensions.unshift(
'.ts',
'.tsx',
...Object.keys(require.extensions), // tslint:disable-line
)
}

// @todo a better way with options
Array.from(new Set([
'.ts',
'.tsx',
...Object.keys(require.extensions), // tslint:disable-line
...extensions
])).forEach(ext => {
registerExtension(ext, ignore, register, originalJsHandler)

if (ext in require.extensions) refreshRequireExtension(ext) // tslint:disable-line
})
Array.from(new Set(extensions))
.forEach(ext => {
registerExtension(ext, ignore, register, originalJsHandler)

if (ext in require.extensions) refreshRequireExtension(ext) // tslint:disable-line
})
}

/**
Expand Down

0 comments on commit 28f22c9

Please sign in to comment.