Skip to content

Commit b3fe199

Browse files
author
Alan Wang
authored
fix: not run new-component-api transformation in main.js (#67)
1 parent 4454d94 commit b3fe199

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

transformations/__tests__/new-component-api.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,19 @@ export default {
1717
};;`,
1818
'transform global component registration'
1919
)
20+
21+
defineInlineTest(
22+
transform,
23+
{},
24+
`import Vue from 'vue'
25+
import App from './App.vue'
26+
import MyComponent from './MyComponent'
27+
Vue.component('my-component', MyComponent)
28+
new Vue(App).$mount('app')`,
29+
`import Vue from 'vue'
30+
import App from './App.vue'
31+
import MyComponent from './MyComponent'
32+
Vue.component('my-component', MyComponent)
33+
new Vue(App).$mount('app')`,
34+
`don't transform global component api when there are other expression statements`
35+
)

transformations/new-component-api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import * as _ from 'lodash'
66

77
export const transformAST: ASTTransformation = context => {
88
const { root, j, filename } = context
9+
const rootExpressionStatement = root
10+
.find(j.ExpressionStatement)
11+
.filter(path => path.parent.value.type === 'Program')
12+
if (rootExpressionStatement.length > 1) {
13+
return
14+
}
915
// find Vue.component
1016
const componentRegistration = root
1117
.find(j.CallExpression, {

0 commit comments

Comments
 (0)