Skip to content

Commit

Permalink
fix: propagate syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gtm-nayan committed Nov 24, 2022
1 parent f292b8c commit 39b428f
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,11 @@ export async function parseImportGlob(
root: string,
resolveId: IdResolver
): Promise<ParsedImportGlob[]> {
let ast: acorn.Node

try {
ast = parse(code, {
ecmaVersion: 'latest',
sourceType: 'module',
ranges: true
})
} catch {
// skip invalid js code
return []
}
const ast = parse(code, {
ecmaVersion: 'latest',
sourceType: 'module',
ranges: true
})

const globCalls: {
start: number
Expand Down Expand Up @@ -140,7 +133,7 @@ export async function parseImportGlob(

const start = node.range![0]

const parent = ancestors.at(-2)
const parent = ancestors[ancestors.length - 2]

if (parent?.type !== 'CallExpression') {
throw globImportError(
Expand Down

0 comments on commit 39b428f

Please sign in to comment.