Skip to content

Home > vue-metamorph > astHelpers > findVueComponentOptions

astHelpers.findVueComponentOptions() function

Finds every Vue Options API object expression in a script AST.

This function detects the objects that are passed to defineComponent(), Vue.extend(), Vue.component(), Vue.mixin(), and new Vue(). When isSfc is true, it 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[]

An 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.
  }
}