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, the default specifier is merged into it. Duplicate imports are skipped.

createNamedImport(ast, moduleSpecifier, importName, localName)

Adds a named import to a script AST. If an import declaration for the module already exists, the new specifier is merged into it. Duplicate imports are skipped.

createNamespaceImport(ast, moduleSpecifier, namespaceName)

Adds a namespace (star) import to a script AST. If an import declaration for the module already exists, the namespace specifier is merged into it. Duplicate imports are skipped.

findAll(ast, matcher)

Finds all nodes in an AST that match a partial node using deep partial matching. Works with both script ASTs (ESTree) and template ASTs (vue-eslint-parser).

findFirst(ast, matcher)

Finds the first node in an AST that matches a partial node using deep partial matching. Works with both script ASTs (ESTree) and template ASTs (vue-eslint-parser).

findImportDeclaration(ast, moduleSpecifier)

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

findVueComponentOptions(ast, isSfc)

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.