Skip to content

Home > vue-metamorph > astHelpers

astHelpers namespace ​

Functions ​

Function

Description

createDefaultImport(ast, moduleSpecifier, importName)

Adds a default import to a script AST. If an import declaration for the module already exists, this function merges the default specifier into that declaration. It doesn't create duplicate imports.

createNamedImport(ast, moduleSpecifier, importName, localName)

Adds a named import to a script AST. If an import declaration for the module already exists, this function merges the new specifier into that declaration. It doesn't create duplicate imports.

createNamespaceImport(ast, moduleSpecifier, namespaceName)

Adds a namespace import to a script AST. If an import declaration for the module already exists, this function merges the namespace specifier into that declaration. It doesn't create duplicate imports.

findAll(ast, matcher)

Finds every node in an AST that matches a partial node, using deep partial matching. This function works with both script ASTs from ESTree and template ASTs from vue-eslint-parser.

findFirst(ast, matcher)

Finds the first node in an AST that matches a partial node, using deep partial matching. This function works with both script ASTs from ESTree and template ASTs from vue-eslint-parser.

findImportDeclaration(ast, moduleSpecifier)

Finds an existing import declaration for a module in a script AST.

findVueComponentOptions(ast, isSfc)

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.