Skip to content

Commit

Permalink
refactor: Do not shadow sucrase.transform()
Browse files Browse the repository at this point in the history
  • Loading branch information
Septh committed Jun 22, 2024
1 parent 55a01b3 commit 9f83ef7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions source/transform.cts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { transform as parse, type Transform, type TransformResult } from 'sucrase'
import * as sucrase from 'sucrase'

const transforms: Record<NodeJS.ModuleType, Transform[]> = {
const transforms: Record<NodeJS.ModuleType, sucrase.Transform[]> = {
commonjs: [ 'typescript', 'imports' ],
module: [ 'typescript' ]
}

export function transform(source: string, format: NodeJS.ModuleType, filePath: string) {
const { code, sourceMap } = parse(source, {
const { code, sourceMap } = sucrase.transform(source, {
filePath,
transforms: transforms[format],
preserveDynamicImport: true,
Expand All @@ -15,7 +15,7 @@ export function transform(source: string, format: NodeJS.ModuleType, filePath: s
sourceMapOptions: {
compiledFilename: filePath
}
}) as Required<TransformResult>
}) as Required<sucrase.TransformResult>

sourceMap.sourceRoot = ''
sourceMap.sources = [ filePath ]
Expand Down

0 comments on commit 9f83ef7

Please sign in to comment.