Skip to content

Commit d6a5144

Browse files
authored
Changed to detect defineComponent ({}) as Vue component. (#52)
1 parent afd9aea commit d6a5144

File tree

4 files changed

+127
-477
lines changed

4 files changed

+127
-477
lines changed

lib/styles/context/vue-components/find-vue.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ function getVueComponentObject(
1818
if (declaration.type === "ObjectExpression") {
1919
return declaration
2020
}
21-
if (declaration.type === "CallExpression") {
21+
if (
22+
declaration.type === "CallExpression" &&
23+
declaration.arguments.length >= 1
24+
) {
2225
const callee = declaration.callee
2326

2427
if (callee.type === "MemberExpression") {
@@ -28,9 +31,20 @@ function getVueComponentObject(
2831
calleeObject.type === "Identifier" &&
2932
calleeObject.name === "Vue" &&
3033
callee.property.type === "Identifier" &&
31-
callee.property.name === "extend" &&
32-
declaration.arguments.length >= 1
34+
callee.property.name === "extend"
3335
) {
36+
// for Vue.js 2.x
37+
// Vue.extend({})
38+
const object = unwrapTypesExpression(declaration.arguments[0])
39+
if (object.type === "ObjectExpression") {
40+
return object
41+
}
42+
}
43+
}
44+
if (callee.type === "Identifier") {
45+
if (callee.name === "defineComponent") {
46+
// for Vue.js 3.x
47+
// defineComponent({})
3448
const object = unwrapTypesExpression(declaration.arguments[0])
3549
if (object.type === "ObjectExpression") {
3650
return object

0 commit comments

Comments
 (0)