Skip to content

Commit

Permalink
chore: use findNodeAt
Browse files Browse the repository at this point in the history
  • Loading branch information
gtm-nayan committed Nov 25, 2022
1 parent bf5975a commit a53b633
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
TemplateLiteral
} from 'estree'
import { parseExpressionAt } from 'acorn'
import { findNodeAt } from 'acorn-walk'
import MagicString from 'magic-string'
import fg from 'fast-glob'
import { stringifyQuery } from 'ufo'
Expand Down Expand Up @@ -154,15 +155,10 @@ export async function parseImportGlob(
}
}

if (ast.type === 'SequenceExpression')
ast = ast.expressions[0] as CallExpression
const callExpr = findNodeAt(ast, start, undefined, 'CallExpression')
if (!callExpr) throw err(`Expect CallExpression, got ${ast.type}`)

// immediate property access, call expression is nested
// import.meta.glob(...)['prop']
if (ast.type === 'MemberExpression') ast = ast.object as CallExpression

if (ast.type !== 'CallExpression')
throw err(`Expect CallExpression, got ${ast.type}`)
ast = callExpr.node as CallExpression

if (ast.arguments.length < 1 || ast.arguments.length > 2)
throw err(`Expected 1-2 arguments, but got ${ast.arguments.length}`)
Expand Down

0 comments on commit a53b633

Please sign in to comment.