Skip to content

Commit 130a137

Browse files
committed
feat: support omitting ts/js extensions
1 parent 1810ce6 commit 130a137

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/output/moduleCompiler.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,19 @@ function processModule(store: Store, src: string, filename: string) {
121121
const importedFiles = new Set<string>()
122122
const importToIdMap = new Map<string, string>()
123123

124+
function resolveImport(raw: string): string | undefined {
125+
const files = store.state.files
126+
let resolved = raw
127+
const file =
128+
files[resolved] ||
129+
files[(resolved = raw + '.ts')] ||
130+
files[(resolved = raw + '.js')]
131+
return file ? resolved : undefined
132+
}
133+
124134
function defineImport(node: Node, source: string) {
125-
const filename = source.replace(/^\.\/+/, '')
126-
if (!(filename in store.state.files)) {
135+
const filename = resolveImport(source.replace(/^\.\/+/, ''))
136+
if (!filename) {
127137
throw new Error(`File "${filename}" does not exist.`)
128138
}
129139
if (importedFiles.has(filename)) {

0 commit comments

Comments
 (0)