Skip to content

Home > vue-metamorph > astHelpers > findVueComponentOptions

astHelpers.findVueComponentOptions() function

Finds all Vue Options API object expressions in a script AST.

Detects objects passed to defineComponent(), Vue.extend(), Vue.component(), Vue.mixin(), and new Vue(). When isSfc is true, also treats the default export as an options object.

Signature:

typescript
export declare function findVueComponentOptions(ast: namedTypes.Program, isSfc: boolean): namedTypes.ObjectExpression[];

Parameters

Parameter

Type

Description

ast

namedTypes.Program

The script AST

isSfc

boolean

If true, treat the default export as an options api object

Returns:

namedTypes.ObjectExpression[]

Array of ObjectExpression nodes

Example

ts
for (const scriptAST of scriptASTs) {
  const options = findVueComponentOptions(scriptAST, sfcAST !== null);
  for (const obj of options) {
    // obj is an ObjectExpression — the { ... } passed to defineComponent(), etc.
  }
}