@wc-toolkit/cem-generator-vue 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +43 -14
- package/package.json +15 -15
package/dist/index.js
CHANGED
|
@@ -6,8 +6,7 @@ export function vuePlugin() {
|
|
|
6
6
|
return {
|
|
7
7
|
name: "vue",
|
|
8
8
|
shouldAnalyze(sourceText) {
|
|
9
|
-
return /from\s+["']vue["']/.test(sourceText) &&
|
|
10
|
-
/\bdefineCustomElement\s*\(/.test(sourceText);
|
|
9
|
+
return /from\s+["']vue["']/.test(sourceText) && /\bdefineCustomElement\s*\(/.test(sourceText);
|
|
11
10
|
},
|
|
12
11
|
onFile(context) {
|
|
13
12
|
const fragment = {};
|
|
@@ -19,7 +18,9 @@ export function vuePlugin() {
|
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
20
|
const declaration = findContainingVariable(node);
|
|
22
|
-
const name = declaration?.name && ts.isIdentifier(declaration.name)
|
|
21
|
+
const name = declaration?.name && ts.isIdentifier(declaration.name)
|
|
22
|
+
? declaration.name.text
|
|
23
|
+
: undefined;
|
|
23
24
|
if (!name) {
|
|
24
25
|
ts.forEachChild(node, visit);
|
|
25
26
|
return;
|
|
@@ -28,7 +29,9 @@ export function vuePlugin() {
|
|
|
28
29
|
const options = resolveComponentOptions(component, context);
|
|
29
30
|
const classDoc = declaration ? parseCemClassTags(declaration) : {};
|
|
30
31
|
const props = options ? getProps(options, context) : undefined;
|
|
31
|
-
const discovered = options
|
|
32
|
+
const discovered = options
|
|
33
|
+
? discoverFrameworkApis(options, context.sourceFile, context.checker)
|
|
34
|
+
: {};
|
|
32
35
|
const attributes = props?.map(({ name: fieldName, ...member }) => ({
|
|
33
36
|
name: fieldName,
|
|
34
37
|
type: member.type,
|
|
@@ -40,11 +43,14 @@ export function vuePlugin() {
|
|
|
40
43
|
name,
|
|
41
44
|
exportName: getExportName(declaration),
|
|
42
45
|
module: context.filePath,
|
|
43
|
-
description: (declaration ? getJSDocInfo(declaration).description : undefined) ||
|
|
46
|
+
description: (declaration ? getJSDocInfo(declaration).description : undefined) ||
|
|
47
|
+
(options ? getJSDocInfo(options).description || undefined : undefined),
|
|
44
48
|
summary: classDoc.summary,
|
|
45
49
|
deprecated: classDoc.deprecated,
|
|
46
50
|
tagName: classDoc.tagName ?? tags.get(name),
|
|
47
|
-
members: props?.length
|
|
51
|
+
members: props?.length
|
|
52
|
+
? props.map(({ name: _name, ...member }) => ({ name: _name, ...member }))
|
|
53
|
+
: undefined,
|
|
48
54
|
attributes: attributes?.length ? attributes : undefined,
|
|
49
55
|
events: mergeEvents(mergeEvents(events, discovered.events), classDoc.events),
|
|
50
56
|
slots: mergeNamed(discovered.slots, classDoc.slots),
|
|
@@ -71,7 +77,9 @@ function mergeNamed(discovered, documented) {
|
|
|
71
77
|
function getDefineCustomElementNames(sourceFile) {
|
|
72
78
|
const names = new Set();
|
|
73
79
|
for (const statement of sourceFile.statements) {
|
|
74
|
-
if (!ts.isImportDeclaration(statement) ||
|
|
80
|
+
if (!ts.isImportDeclaration(statement) ||
|
|
81
|
+
!ts.isStringLiteral(statement.moduleSpecifier) ||
|
|
82
|
+
statement.moduleSpecifier.text !== "vue")
|
|
75
83
|
continue;
|
|
76
84
|
const bindings = statement.importClause?.namedBindings;
|
|
77
85
|
if (!bindings || !ts.isNamedImports(bindings))
|
|
@@ -89,7 +97,8 @@ function isDefineCustomElementCall(node, names) {
|
|
|
89
97
|
function getCustomElementRegistrations(sourceFile) {
|
|
90
98
|
const tags = new Map();
|
|
91
99
|
function visit(node) {
|
|
92
|
-
if (ts.isCallExpression(node) &&
|
|
100
|
+
if (ts.isCallExpression(node) &&
|
|
101
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
93
102
|
node.expression.getText(sourceFile) === "customElements.define") {
|
|
94
103
|
const tag = node.arguments[0];
|
|
95
104
|
const constructor = node.arguments[1];
|
|
@@ -118,13 +127,20 @@ function resolveComponentOptions(component, context) {
|
|
|
118
127
|
if (!ts.isIdentifier(component))
|
|
119
128
|
return undefined;
|
|
120
129
|
const symbol = context.checker.getSymbolAtLocation(component);
|
|
121
|
-
const resolved = symbol && symbol.flags & ts.SymbolFlags.Alias
|
|
130
|
+
const resolved = symbol && symbol.flags & ts.SymbolFlags.Alias
|
|
131
|
+
? context.checker.getAliasedSymbol(symbol)
|
|
132
|
+
: symbol;
|
|
122
133
|
const declaration = resolved?.declarations?.find(ts.isVariableDeclaration);
|
|
123
134
|
const initializer = declaration?.initializer;
|
|
124
135
|
if (initializer && ts.isObjectLiteralExpression(initializer))
|
|
125
136
|
return initializer;
|
|
126
|
-
if (initializer &&
|
|
127
|
-
|
|
137
|
+
if (initializer &&
|
|
138
|
+
ts.isCallExpression(initializer) &&
|
|
139
|
+
ts.isIdentifier(initializer.expression) &&
|
|
140
|
+
initializer.expression.text === "defineComponent") {
|
|
141
|
+
return initializer.arguments[0] && ts.isObjectLiteralExpression(initializer.arguments[0])
|
|
142
|
+
? initializer.arguments[0]
|
|
143
|
+
: undefined;
|
|
128
144
|
}
|
|
129
145
|
return undefined;
|
|
130
146
|
}
|
|
@@ -139,14 +155,25 @@ function getProps(options, context) {
|
|
|
139
155
|
if (!name)
|
|
140
156
|
return [];
|
|
141
157
|
const metadata = getPropMetadata(property.initializer, context);
|
|
142
|
-
return [
|
|
158
|
+
return [
|
|
159
|
+
{
|
|
160
|
+
name,
|
|
161
|
+
kind: "field",
|
|
162
|
+
type: metadata.type,
|
|
163
|
+
description: getJSDocInfo(property).description || undefined,
|
|
164
|
+
default: metadata.default,
|
|
165
|
+
},
|
|
166
|
+
];
|
|
143
167
|
});
|
|
144
168
|
}
|
|
145
169
|
function getPropMetadata(initializer, context) {
|
|
146
170
|
if (ts.isObjectLiteralExpression(initializer)) {
|
|
147
171
|
const type = getObjectProperty(initializer, "type");
|
|
148
172
|
const defaultValue = getObjectProperty(initializer, "default");
|
|
149
|
-
return {
|
|
173
|
+
return {
|
|
174
|
+
type: type && getVueType(type.initializer, context),
|
|
175
|
+
default: defaultValue?.initializer.getText(),
|
|
176
|
+
};
|
|
150
177
|
}
|
|
151
178
|
return { type: getVueType(initializer, context) };
|
|
152
179
|
}
|
|
@@ -200,5 +227,7 @@ function getExportName(node) {
|
|
|
200
227
|
const modifiers = ts.canHaveModifiers(declaration) ? ts.getModifiers(declaration) : undefined;
|
|
201
228
|
if (!modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword))
|
|
202
229
|
return undefined;
|
|
203
|
-
return modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword)
|
|
230
|
+
return modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword)
|
|
231
|
+
? "default"
|
|
232
|
+
: node?.name.getText();
|
|
204
233
|
}
|
package/package.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wc-toolkit/cem-generator-vue",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Vue detector plugin for generating Custom Elements Manifests.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"custom-elements",
|
|
7
|
+
"custom-elements-manifest",
|
|
8
|
+
"vue",
|
|
9
|
+
"web-components"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://cem-generator.wc-toolkit.com/plugins/vue/",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/wc-toolkit/cem-generator/issues"
|
|
14
|
+
},
|
|
5
15
|
"license": "MIT",
|
|
6
16
|
"repository": {
|
|
7
17
|
"type": "git",
|
|
8
18
|
"url": "git+https://github.com/wc-toolkit/cem-generator.git",
|
|
9
19
|
"directory": "packages/plugins/vue"
|
|
10
20
|
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
},
|
|
14
|
-
"homepage": "https://wc-toolkit.github.io/cem-generator/plugins/vue/",
|
|
15
|
-
"keywords": [
|
|
16
|
-
"custom-elements",
|
|
17
|
-
"custom-elements-manifest",
|
|
18
|
-
"web-components",
|
|
19
|
-
"vue"
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
20
23
|
],
|
|
21
24
|
"type": "module",
|
|
22
25
|
"main": "./dist/index.js",
|
|
23
26
|
"types": "./dist/index.d.ts",
|
|
24
|
-
"files": [
|
|
25
|
-
"dist"
|
|
26
|
-
],
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public",
|
|
29
29
|
"provenance": true
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"typescript": "^5.9.0",
|
|
33
|
-
"@wc-toolkit/cem-generator": "0.1.
|
|
34
|
-
"@wc-toolkit/cem-generator-utils": "0.1.
|
|
33
|
+
"@wc-toolkit/cem-generator": "0.1.7",
|
|
34
|
+
"@wc-toolkit/cem-generator-utils": "0.1.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"vue": "^3.5.0"
|