How to use the ImportDeclaration function from @babel/types
Find comprehensive JavaScript @babel/types.ImportDeclaration code examples handpicked from public code repositorys.
53 54 55 56 57 58 59 60 61 62
traverse(jsAst, { // 监听整个ast节点 Program(path) { // 添加import导入 const importDefaultSpecifier = [types.ImportDefaultSpecifier(types.Identifier('PageMixins'))]; const importDeclaration = types.ImportDeclaration(importDefaultSpecifier, types.StringLiteral('@/mixins/PageMixins')); path.get('body')[0].insertBefore(importDeclaration); }, // export的监听 ExportDefaultDeclaration(path) {
1
2
0
@babel/types.identifier is the most popular function in @babel/types (20936 examples)