@htmlplus/element 0.4.5 → 0.4.8
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/bundlers/index.d.ts +2 -0
- package/bundlers/index.js +2 -0
- package/bundlers/rollup.d.ts +7 -0
- package/bundlers/rollup.js +21 -0
- package/bundlers/vite.d.ts +7 -0
- package/bundlers/vite.js +25 -0
- package/client/decorators/attributes.d.ts +1 -1
- package/client/decorators/attributes.js +4 -4
- package/client/decorators/element.d.ts +1 -1
- package/client/decorators/element.js +14 -22
- package/client/decorators/event.d.ts +1 -1
- package/client/decorators/listen.d.ts +1 -1
- package/client/decorators/method.d.ts +1 -1
- package/client/decorators/property.d.ts +1 -1
- package/client/decorators/property.js +4 -4
- package/client/decorators/state.d.ts +1 -1
- package/client/decorators/state.js +4 -4
- package/client/decorators/watch.d.ts +1 -1
- package/client/helpers/direction.d.ts +1 -1
- package/client/helpers/isRTL.d.ts +1 -1
- package/client/helpers/slots.d.ts +1 -1
- package/client/utils/getMemberType.d.ts +1 -1
- package/client/utils/getMemberType.js +2 -2
- package/client/utils/getMembersKey.d.ts +1 -1
- package/client/utils/getStyles.d.ts +1 -1
- package/client/utils/host.d.ts +1 -1
- package/client/utils/index.d.ts +1 -1
- package/client/utils/index.js +1 -1
- package/client/utils/request.d.ts +1 -1
- package/client/utils/request.js +3 -3
- package/client/utils/syncAttributes.d.ts +1 -0
- package/client/utils/{sync.js → syncAttributes.js} +1 -1
- package/client/{vendor → vendors}/uhtml.d.ts +7 -0
- package/client/{vendor → vendors}/uhtml.js +1 -0
- package/compiler/compiler.d.ts +1 -1
- package/compiler/plugins/assets.d.ts +1 -1
- package/compiler/plugins/copy.d.ts +13 -0
- package/compiler/plugins/copy.js +26 -0
- package/compiler/plugins/customElement.d.ts +1 -1
- package/compiler/plugins/customElement.js +31 -38
- package/compiler/plugins/customElementReact/customElementReact.d.ts +1 -1
- package/compiler/plugins/document.d.ts +1 -1
- package/compiler/plugins/document.js +37 -35
- package/compiler/plugins/extract.d.ts +1 -1
- package/compiler/plugins/index.d.ts +1 -0
- package/compiler/plugins/index.js +1 -0
- package/compiler/plugins/parse.d.ts +1 -1
- package/compiler/plugins/read.d.ts +1 -1
- package/compiler/plugins/style.d.ts +2 -2
- package/compiler/plugins/style.js +6 -2
- package/compiler/plugins/validate.d.ts +1 -1
- package/compiler/plugins/visualStudioCode.d.ts +1 -1
- package/compiler/plugins/webTypes.d.ts +2 -2
- package/compiler/plugins/webTypes.js +75 -51
- package/compiler/utils/addDependency.d.ts +9 -2
- package/compiler/utils/addDependency.js +35 -16
- package/compiler/utils/getInitializer.d.ts +1 -1
- package/compiler/utils/getInitializer.js +2 -8
- package/compiler/utils/index.d.ts +1 -0
- package/compiler/utils/index.js +1 -0
- package/compiler/utils/removeUnusedImport.d.ts +1 -0
- package/compiler/utils/removeUnusedImport.js +49 -0
- package/constants/index.d.ts +9 -2
- package/constants/index.js +10 -2
- package/package.json +5 -11
- package/types/global.d.ts +1 -1
- package/types/index.d.ts +4 -4
- package/types/index.js +4 -4
- package/types/plugin.d.ts +1 -1
- package/client/utils/sync.d.ts +0 -1
|
@@ -13,9 +13,10 @@ export const document = (options) => {
|
|
|
13
13
|
components: []
|
|
14
14
|
};
|
|
15
15
|
for (const context of global.contexts) {
|
|
16
|
+
const deprecated = hasTag(context.class, 'deprecated');
|
|
16
17
|
const events = context.classEvents.map((event) => {
|
|
17
18
|
var _a, _b, _c;
|
|
18
|
-
const
|
|
19
|
+
const cancelable = (() => {
|
|
19
20
|
if (!event.decorators)
|
|
20
21
|
return false;
|
|
21
22
|
try {
|
|
@@ -36,27 +37,28 @@ export const document = (options) => {
|
|
|
36
37
|
catch (_a) { }
|
|
37
38
|
return false;
|
|
38
39
|
})();
|
|
40
|
+
const deprecated = hasTag(event, 'deprecated');
|
|
39
41
|
const description = (_a = getTags(event).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
|
|
40
42
|
const detail = print((_b = event.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation']);
|
|
41
43
|
const detailReference = getTypeReference(context.fileAST, (_c = event.typeAnnotation) === null || _c === void 0 ? void 0 : _c['typeAnnotation'].typeParameters.params[0]);
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
+
const experimental = hasTag(event, 'experimental');
|
|
45
|
+
const model = hasTag(event, 'model');
|
|
44
46
|
const name = event.key['name'];
|
|
45
47
|
const tags = getTags(event);
|
|
46
48
|
return {
|
|
49
|
+
cancelable,
|
|
50
|
+
deprecated,
|
|
47
51
|
description,
|
|
48
52
|
detail,
|
|
49
53
|
detailReference,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
isModel,
|
|
54
|
+
experimental,
|
|
55
|
+
model,
|
|
53
56
|
name,
|
|
54
57
|
tags
|
|
55
58
|
};
|
|
56
59
|
});
|
|
60
|
+
const experimental = hasTag(context.class, 'experimental');
|
|
57
61
|
const group = (_a = getTag(context.class, 'group')) === null || _a === void 0 ? void 0 : _a.value;
|
|
58
|
-
const isDeprecated = hasTag(context.class, 'deprecated');
|
|
59
|
-
const isExperimental = hasTag(context.class, 'experimental');
|
|
60
62
|
const lastModified = glob
|
|
61
63
|
.sync(path.join(context.directoryPath, '**/*.*'))
|
|
62
64
|
.map((file) => fs.statSync(file).mtime)
|
|
@@ -64,14 +66,11 @@ export const document = (options) => {
|
|
|
64
66
|
.pop();
|
|
65
67
|
const methods = context.classMethods.map((method) => {
|
|
66
68
|
var _a, _b, _c;
|
|
69
|
+
const async = method.async;
|
|
67
70
|
const description = (_a = getTags(method).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const isExperimental = hasTag(method, 'experimental');
|
|
71
|
+
const deprecated = hasTag(method, 'deprecated');
|
|
72
|
+
const experimental = hasTag(method, 'experimental');
|
|
71
73
|
const name = method.key['name'];
|
|
72
|
-
const returns = print((_b = method.returnType) === null || _b === void 0 ? void 0 : _b['typeAnnotation']) || 'void';
|
|
73
|
-
const returnsReference = getTypeReference(context.fileAST, (_c = method.returnType) === null || _c === void 0 ? void 0 : _c['typeAnnotation']);
|
|
74
|
-
const tags = getTags(method);
|
|
75
74
|
// TODO
|
|
76
75
|
const parameters = method.params.map((param) => {
|
|
77
76
|
var _a, _b, _c;
|
|
@@ -79,12 +78,15 @@ export const document = (options) => {
|
|
|
79
78
|
description: (_a = getTags(method, 'param')
|
|
80
79
|
.map((tag) => parseTag(tag, ' '))
|
|
81
80
|
.find((tag) => tag.name == param['name'])) === null || _a === void 0 ? void 0 : _a.description,
|
|
82
|
-
|
|
81
|
+
required: !param['optional'],
|
|
83
82
|
name: param['name'],
|
|
84
83
|
type: print((_b = param === null || param === void 0 ? void 0 : param['typeAnnotation']) === null || _b === void 0 ? void 0 : _b.typeAnnotation) || undefined,
|
|
85
84
|
typeReference: getTypeReference(context.fileAST, (_c = param === null || param === void 0 ? void 0 : param['typeAnnotation']) === null || _c === void 0 ? void 0 : _c.typeAnnotation)
|
|
86
85
|
});
|
|
87
86
|
});
|
|
87
|
+
const returns = print((_b = method.returnType) === null || _b === void 0 ? void 0 : _b['typeAnnotation']) || 'void';
|
|
88
|
+
const returnsReference = getTypeReference(context.fileAST, (_c = method.returnType) === null || _c === void 0 ? void 0 : _c['typeAnnotation']);
|
|
89
|
+
const tags = getTags(method);
|
|
88
90
|
const signature = [
|
|
89
91
|
method.key['name'],
|
|
90
92
|
'(',
|
|
@@ -93,7 +95,7 @@ export const document = (options) => {
|
|
|
93
95
|
var _a;
|
|
94
96
|
let string = '';
|
|
95
97
|
string += parameter.name;
|
|
96
|
-
string += parameter.
|
|
98
|
+
string += parameter.required ? '' : '?';
|
|
97
99
|
string += parameter.type ? ': ' : '';
|
|
98
100
|
string += (_a = parameter.type) !== null && _a !== void 0 ? _a : '';
|
|
99
101
|
return string;
|
|
@@ -104,15 +106,15 @@ export const document = (options) => {
|
|
|
104
106
|
returns
|
|
105
107
|
].join('');
|
|
106
108
|
return {
|
|
109
|
+
async,
|
|
107
110
|
description,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
isExperimental,
|
|
111
|
+
deprecated,
|
|
112
|
+
experimental,
|
|
111
113
|
name,
|
|
114
|
+
parameters,
|
|
112
115
|
returns,
|
|
113
116
|
returnsReference,
|
|
114
117
|
tags,
|
|
115
|
-
parameters,
|
|
116
118
|
signature
|
|
117
119
|
};
|
|
118
120
|
});
|
|
@@ -120,9 +122,15 @@ export const document = (options) => {
|
|
|
120
122
|
const properties = context.classProperties.map((property) => {
|
|
121
123
|
var _a, _b, _c;
|
|
122
124
|
const attribute = paramCase(property.key['name']);
|
|
125
|
+
const deprecated = hasTag(property, 'deprecated');
|
|
123
126
|
const description = (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
|
|
127
|
+
const experimental = hasTag(property, 'experimental');
|
|
128
|
+
// TODO
|
|
129
|
+
const initializer = getInitializer(property.value);
|
|
130
|
+
const model = hasTag(property, 'model');
|
|
131
|
+
const name = property.key['name'];
|
|
124
132
|
// TODO
|
|
125
|
-
const
|
|
133
|
+
const reflects = (() => {
|
|
126
134
|
if (!property.decorators)
|
|
127
135
|
return false;
|
|
128
136
|
try {
|
|
@@ -143,26 +151,20 @@ export const document = (options) => {
|
|
|
143
151
|
catch (_a) { }
|
|
144
152
|
return false;
|
|
145
153
|
})();
|
|
146
|
-
|
|
147
|
-
const initializer = getInitializer(property.value);
|
|
148
|
-
const isDeprecated = hasTag(property, 'deprecated');
|
|
149
|
-
const isExperimental = hasTag(property, 'experimental');
|
|
150
|
-
const isModel = hasTag(property, 'model');
|
|
151
|
-
const isRequired = !property.optional;
|
|
152
|
-
const name = property.key['name'];
|
|
154
|
+
const required = !property.optional;
|
|
153
155
|
const tags = getTags(property);
|
|
154
156
|
const type = print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation']);
|
|
155
157
|
const typeReference = getTypeReference(context.fileAST, (_c = property.typeAnnotation) === null || _c === void 0 ? void 0 : _c['typeAnnotation']);
|
|
156
158
|
return {
|
|
157
159
|
attribute,
|
|
160
|
+
deprecated,
|
|
158
161
|
description,
|
|
159
|
-
|
|
162
|
+
experimental,
|
|
160
163
|
initializer,
|
|
161
|
-
|
|
162
|
-
isExperimental,
|
|
163
|
-
isModel,
|
|
164
|
-
isRequired,
|
|
164
|
+
model,
|
|
165
165
|
name,
|
|
166
|
+
reflects,
|
|
167
|
+
required,
|
|
166
168
|
tags,
|
|
167
169
|
type,
|
|
168
170
|
typeReference
|
|
@@ -222,8 +224,8 @@ export const document = (options) => {
|
|
|
222
224
|
// source
|
|
223
225
|
events,
|
|
224
226
|
group,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
deprecated,
|
|
228
|
+
experimental,
|
|
227
229
|
key: context.componentKey,
|
|
228
230
|
lastModified,
|
|
229
231
|
methods,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Context } from '../../types
|
|
1
|
+
import { Context } from '../../types';
|
|
2
2
|
export declare type StyleOptions = {
|
|
3
|
-
references?: (context: Context) => string[];
|
|
3
|
+
references?: (context: Context) => string | string[];
|
|
4
4
|
};
|
|
5
5
|
export declare const style: (options: StyleOptions) => {
|
|
6
6
|
name: string;
|
|
@@ -18,16 +18,20 @@ export const style = (options) => {
|
|
|
18
18
|
const name = 'style';
|
|
19
19
|
options = Object.assign({}, defaults, options);
|
|
20
20
|
const next = (context) => {
|
|
21
|
-
const references = options.references(context);
|
|
21
|
+
const references = [options.references(context)].flat();
|
|
22
22
|
for (const reference of references) {
|
|
23
23
|
if (!fs.existsSync(reference))
|
|
24
24
|
continue;
|
|
25
25
|
context.stylePath = reference;
|
|
26
|
+
break;
|
|
26
27
|
}
|
|
27
28
|
if (!context.stylePath)
|
|
28
29
|
return;
|
|
29
|
-
const local = addDependency(context.fileAST, context.stylePath,
|
|
30
|
+
const { local, node } = addDependency(context.fileAST, context.stylePath, CONSTANTS.AUTO_IMPORT_STYLE);
|
|
31
|
+
t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_DEPENDENCY, true);
|
|
32
|
+
// TODO: remove 'local!'
|
|
30
33
|
const property = t.classProperty(t.identifier(CONSTANTS.STATIC_STYLES), t.identifier(local), undefined, null, undefined, true);
|
|
34
|
+
t.addComment(property, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_PROPERTY, true);
|
|
31
35
|
context.class.body.body.unshift(property);
|
|
32
36
|
};
|
|
33
37
|
return { name, next };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Global } from '../../types
|
|
1
|
+
import { Global } from '../../types';
|
|
2
2
|
export interface WebTypesOptions {
|
|
3
3
|
destination: string;
|
|
4
4
|
packageName: string;
|
|
5
5
|
packageVersion: string;
|
|
6
|
-
|
|
6
|
+
reference?: (componentTag: string) => string;
|
|
7
7
|
}
|
|
8
8
|
export declare const webTypes: (options: WebTypesOptions) => {
|
|
9
9
|
name: string;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { paramCase } from 'change-case';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { getTags, print } from '../utils/index.js';
|
|
4
|
+
import { getInitializer, getTags, hasTag, parseTag, print } from '../utils/index.js';
|
|
5
5
|
const defaults = {};
|
|
6
6
|
export const webTypes = (options) => {
|
|
7
7
|
const name = 'webTypes';
|
|
8
8
|
options = Object.assign({}, defaults, options);
|
|
9
9
|
const finish = (global) => {
|
|
10
|
+
var _a, _b, _c, _d, _e;
|
|
10
11
|
const json = {
|
|
11
12
|
'$schema': 'http://json.schemastore.org/web-types',
|
|
12
13
|
'name': options.packageName,
|
|
@@ -19,58 +20,81 @@ export const webTypes = (options) => {
|
|
|
19
20
|
},
|
|
20
21
|
'contributions': {
|
|
21
22
|
html: {
|
|
22
|
-
elements:
|
|
23
|
-
.sort((a, b) => ((a.componentTag || '') > (b.componentTag || '') ? 1 : -1))
|
|
24
|
-
.map((context) => {
|
|
25
|
-
var _a, _b;
|
|
26
|
-
return ({
|
|
27
|
-
'name': context.componentTag,
|
|
28
|
-
'description': '',
|
|
29
|
-
'doc-url': options.docUrl(),
|
|
30
|
-
'js': {
|
|
31
|
-
properties: [
|
|
32
|
-
...(context.classProperties || []).map((property) => {
|
|
33
|
-
var _a, _b;
|
|
34
|
-
return ({
|
|
35
|
-
name: camelCase(property.key['name']),
|
|
36
|
-
description: (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
37
|
-
value: {
|
|
38
|
-
type: print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation'])
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}),
|
|
42
|
-
...(context.classMethods || []).map((method) => {
|
|
43
|
-
var _a;
|
|
44
|
-
return ({
|
|
45
|
-
name: camelCase(method.key['name']),
|
|
46
|
-
description: (_a = getTags(method).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
47
|
-
value: {}
|
|
48
|
-
});
|
|
49
|
-
})
|
|
50
|
-
],
|
|
51
|
-
events: (_a = context.classEvents) === null || _a === void 0 ? void 0 : _a.map((event) => {
|
|
52
|
-
var _a;
|
|
53
|
-
return ({
|
|
54
|
-
name: paramCase(event.key['name']),
|
|
55
|
-
description: (_a = getTags(event).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value
|
|
56
|
-
});
|
|
57
|
-
})
|
|
58
|
-
},
|
|
59
|
-
'attributes': (_b = context.classProperties) === null || _b === void 0 ? void 0 : _b.map((property) => {
|
|
60
|
-
var _a, _b;
|
|
61
|
-
return ({
|
|
62
|
-
name: paramCase(property.key['name']),
|
|
63
|
-
description: (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
64
|
-
value: {
|
|
65
|
-
type: print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation'])
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
})
|
|
69
|
-
});
|
|
70
|
-
})
|
|
23
|
+
elements: []
|
|
71
24
|
}
|
|
72
25
|
}
|
|
73
26
|
};
|
|
27
|
+
const extract = (member) => {
|
|
28
|
+
var _a;
|
|
29
|
+
return ({
|
|
30
|
+
name: member.key['name'],
|
|
31
|
+
description: (_a = getTags(member).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
32
|
+
deprecated: hasTag(member, 'deprecated'),
|
|
33
|
+
experimental: hasTag(member, 'experimental')
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
for (const context of global.contexts) {
|
|
37
|
+
const attributes = (_a = context.classProperties) === null || _a === void 0 ? void 0 : _a.map((property) => {
|
|
38
|
+
var _a;
|
|
39
|
+
return Object.assign({}, extract(property), {
|
|
40
|
+
name: paramCase(property.key['name']),
|
|
41
|
+
value: {
|
|
42
|
+
// kind: TODO
|
|
43
|
+
/**
|
|
44
|
+
* For Example
|
|
45
|
+
* 01) type: "''"
|
|
46
|
+
* 02) type: "null"
|
|
47
|
+
* 03) type: "undefined"
|
|
48
|
+
* 04) type: "boolean"
|
|
49
|
+
* 05) type: "string"
|
|
50
|
+
* 06) type: "number"
|
|
51
|
+
* 07) type: "boolean | string | number"
|
|
52
|
+
* 08) type: "string[]"
|
|
53
|
+
* 09) type: "1 | 2 | 3"
|
|
54
|
+
* 10) type: "'Value-1' | 'Value-2'"
|
|
55
|
+
*/
|
|
56
|
+
type: print((_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a['typeAnnotation'])
|
|
57
|
+
// required: TODO
|
|
58
|
+
// default: TODO
|
|
59
|
+
},
|
|
60
|
+
default: getInitializer(property.value)
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
const events = (_b = context.classEvents) === null || _b === void 0 ? void 0 : _b.map((event) => Object.assign({}, extract(event), {
|
|
64
|
+
name: paramCase(event.key['name']) // TODO
|
|
65
|
+
// 'value': TODO
|
|
66
|
+
}));
|
|
67
|
+
const methods = (_c = context.classMethods) === null || _c === void 0 ? void 0 : _c.map((method) => Object.assign({}, extract(method), {
|
|
68
|
+
// 'value': TODO
|
|
69
|
+
}));
|
|
70
|
+
const properties = (_d = context.classProperties) === null || _d === void 0 ? void 0 : _d.map((property) => Object.assign({}, extract(property), {
|
|
71
|
+
// 'value': TODO
|
|
72
|
+
default: getInitializer(property.value)
|
|
73
|
+
}));
|
|
74
|
+
const slots = getTags(context.class, 'slot').map((tag) => {
|
|
75
|
+
const { description, name } = parseTag(tag);
|
|
76
|
+
return {
|
|
77
|
+
'name': name,
|
|
78
|
+
'description': description,
|
|
79
|
+
'doc-url': undefined,
|
|
80
|
+
'deprecated': false,
|
|
81
|
+
'experimental': false
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
json.contributions.html.elements.push({
|
|
85
|
+
'name': context.componentTag,
|
|
86
|
+
'description': 'TODO',
|
|
87
|
+
'doc-url': (_e = options.reference) === null || _e === void 0 ? void 0 : _e.call(options, context.componentTag),
|
|
88
|
+
'deprecated': hasTag(context.class, 'deprecated'),
|
|
89
|
+
'experimental': hasTag(context.class, 'experimental'),
|
|
90
|
+
'js': {
|
|
91
|
+
events,
|
|
92
|
+
properties: [].concat(properties, methods)
|
|
93
|
+
},
|
|
94
|
+
attributes,
|
|
95
|
+
slots
|
|
96
|
+
});
|
|
97
|
+
}
|
|
74
98
|
const dirname = path.dirname(options.destination);
|
|
75
99
|
fs.ensureDirSync(dirname);
|
|
76
100
|
fs.writeJSONSync(options.destination, json, { encoding: 'utf8', spaces: 2 });
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import { File } from '@babel/types';
|
|
2
|
-
|
|
1
|
+
import { File, ImportDeclaration } from '@babel/types';
|
|
2
|
+
interface AddDependencyReturns {
|
|
3
|
+
local?: string;
|
|
4
|
+
node: ImportDeclaration;
|
|
5
|
+
}
|
|
6
|
+
export declare function addDependency(path: File | any, source: string): AddDependencyReturns;
|
|
7
|
+
export declare function addDependency(path: File | any, source: string, local: string): AddDependencyReturns;
|
|
8
|
+
export declare function addDependency(path: File | any, source: string, local: string, imported: string): AddDependencyReturns;
|
|
9
|
+
export {};
|
|
@@ -1,41 +1,60 @@
|
|
|
1
1
|
import t from '@babel/types';
|
|
2
2
|
import { visitor } from './visitor.js';
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export function addDependency(path, source, local, imported) {
|
|
4
|
+
const isDefault = local && !imported;
|
|
5
|
+
const isImport = local && imported;
|
|
6
|
+
const isNormal = !local && !imported;
|
|
7
|
+
let declaration;
|
|
8
|
+
let file = path;
|
|
9
|
+
while (file.parentPath)
|
|
10
|
+
file = file.parentPath;
|
|
11
|
+
file = file.node || file;
|
|
5
12
|
visitor(file, {
|
|
6
13
|
ImportDeclaration(path) {
|
|
7
14
|
if (path.node.source.value != source)
|
|
8
15
|
return;
|
|
9
|
-
|
|
16
|
+
declaration = path.node;
|
|
10
17
|
}
|
|
11
18
|
});
|
|
12
|
-
|
|
19
|
+
if (isNormal && declaration)
|
|
20
|
+
return {
|
|
21
|
+
node: declaration
|
|
22
|
+
};
|
|
23
|
+
let specifier = declaration === null || declaration === void 0 ? void 0 : declaration.specifiers.find((specifier) => {
|
|
13
24
|
var _a;
|
|
14
25
|
if (isDefault) {
|
|
15
26
|
return specifier.type == 'ImportDefaultSpecifier';
|
|
16
27
|
}
|
|
17
|
-
else {
|
|
28
|
+
else if (isImport) {
|
|
18
29
|
return ((_a = specifier.imported) === null || _a === void 0 ? void 0 : _a.name) == imported;
|
|
19
30
|
}
|
|
20
31
|
});
|
|
21
32
|
if (specifier)
|
|
22
|
-
return
|
|
33
|
+
return {
|
|
34
|
+
local: specifier.local.name,
|
|
35
|
+
node: declaration
|
|
36
|
+
};
|
|
23
37
|
if (isDefault) {
|
|
24
|
-
specifier = t.importDefaultSpecifier(t.identifier(
|
|
38
|
+
specifier = t.importDefaultSpecifier(t.identifier(local));
|
|
25
39
|
}
|
|
26
|
-
else {
|
|
27
|
-
specifier = t.importSpecifier(t.identifier(local
|
|
40
|
+
else if (isImport) {
|
|
41
|
+
specifier = t.importSpecifier(t.identifier(local), t.identifier(imported));
|
|
28
42
|
}
|
|
29
|
-
if (
|
|
43
|
+
if (declaration) {
|
|
30
44
|
if (isDefault) {
|
|
31
|
-
|
|
45
|
+
declaration.specifiers.unshift(specifier);
|
|
32
46
|
}
|
|
33
|
-
else {
|
|
34
|
-
|
|
47
|
+
else if (isImport) {
|
|
48
|
+
declaration.specifiers.push(specifier);
|
|
35
49
|
}
|
|
36
50
|
}
|
|
37
51
|
else {
|
|
38
|
-
|
|
52
|
+
declaration = t.importDeclaration(specifier ? [specifier] : [], t.stringLiteral(source));
|
|
53
|
+
// TODO
|
|
54
|
+
(file.program || file).body.unshift(declaration);
|
|
39
55
|
}
|
|
40
|
-
return
|
|
41
|
-
|
|
56
|
+
return {
|
|
57
|
+
local,
|
|
58
|
+
node: declaration
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Expression } from '@babel/types';
|
|
2
|
-
export declare const getInitializer: (node: Expression) =>
|
|
2
|
+
export declare const getInitializer: (node: Expression) => string | undefined;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
// TODO: return type
|
|
2
1
|
export const getInitializer = (node) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const value = node;
|
|
6
|
-
if (!value)
|
|
7
|
-
return;
|
|
8
|
-
const extra = value.extra || {};
|
|
9
|
-
return extra.raw || value['value'];
|
|
2
|
+
var _a;
|
|
3
|
+
return ((_a = node === null || node === void 0 ? void 0 : node.extra) === null || _a === void 0 ? void 0 : _a.raw) || (node === null || node === void 0 ? void 0 : node['value']);
|
|
10
4
|
};
|
|
@@ -7,6 +7,7 @@ export * from './hasDecorator.js';
|
|
|
7
7
|
export * from './isDirectoryEmpty.js';
|
|
8
8
|
export * from './printType.js';
|
|
9
9
|
export * from './print.js';
|
|
10
|
+
export * from './removeUnusedImport.js';
|
|
10
11
|
export * from './renderTemplate.js';
|
|
11
12
|
export * from './tags.js';
|
|
12
13
|
export * from './visitor.js';
|
package/compiler/utils/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from './hasDecorator.js';
|
|
|
7
7
|
export * from './isDirectoryEmpty.js';
|
|
8
8
|
export * from './printType.js';
|
|
9
9
|
export * from './print.js';
|
|
10
|
+
export * from './removeUnusedImport.js';
|
|
10
11
|
export * from './renderTemplate.js';
|
|
11
12
|
export * from './tags.js';
|
|
12
13
|
export * from './visitor.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const removeUnusedImport: (ast: any) => void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import t from '@babel/types';
|
|
2
|
+
import { visitor } from './visitor.js';
|
|
3
|
+
// TODO
|
|
4
|
+
export const removeUnusedImport = (ast) => {
|
|
5
|
+
visitor(ast, {
|
|
6
|
+
Program: {
|
|
7
|
+
exit(path) {
|
|
8
|
+
for (const entry of Object.entries(path.scope.bindings)) {
|
|
9
|
+
let { kind, path, referenced, referencePaths } = entry[1];
|
|
10
|
+
if (kind !== 'module')
|
|
11
|
+
continue;
|
|
12
|
+
if (referenced) {
|
|
13
|
+
referenced = false;
|
|
14
|
+
for (const referencePath of referencePaths) {
|
|
15
|
+
let find = true;
|
|
16
|
+
let parent = referencePath;
|
|
17
|
+
while (parent) {
|
|
18
|
+
if (!parent.node) {
|
|
19
|
+
find = false;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
parent = parent.parentPath;
|
|
23
|
+
}
|
|
24
|
+
if (!find)
|
|
25
|
+
continue;
|
|
26
|
+
referenced = true;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (referenced)
|
|
31
|
+
continue;
|
|
32
|
+
const source = path.parentPath.get('source');
|
|
33
|
+
if (!t.isStringLiteral(source))
|
|
34
|
+
continue;
|
|
35
|
+
if (path.isImportSpecifier()) {
|
|
36
|
+
path.remove();
|
|
37
|
+
if (path.parentPath.node.specifiers.length)
|
|
38
|
+
continue;
|
|
39
|
+
path.parentPath.remove();
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (!path.parentPath)
|
|
43
|
+
continue;
|
|
44
|
+
path.parentPath.remove();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
package/constants/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const PACKAGE_NAME = "@htmlplus/element";
|
|
2
|
-
export declare const API_HOST
|
|
3
|
-
export declare const
|
|
2
|
+
export declare const API_HOST: unique symbol;
|
|
3
|
+
export declare const API_INSTANCE: unique symbol;
|
|
4
|
+
export declare const API_STATUS: unique symbol;
|
|
4
5
|
export declare const DECORATOR_ELEMENT = "Element";
|
|
5
6
|
export declare const DECORATOR_EVENT = "Event";
|
|
6
7
|
export declare const DECORATOR_PROPERTY = "Property";
|
|
@@ -14,6 +15,8 @@ export declare const LIFECYCLE_UPDATE = "updateCallback";
|
|
|
14
15
|
export declare const LIFECYCLE_UPDATED = "updatedCallback";
|
|
15
16
|
export declare const METHOD_RENDER = "render";
|
|
16
17
|
export declare const STATIC_MEMBERS = "members";
|
|
18
|
+
export declare const STATIC_MEMBERS_INITIALIZER = "default";
|
|
19
|
+
export declare const STATIC_MEMBERS_TYPE = "type";
|
|
17
20
|
export declare const STATIC_STYLES = "styles";
|
|
18
21
|
export declare const TYPE_BOOLEAN = "boolean";
|
|
19
22
|
export declare const TYPE_DATE = "date";
|
|
@@ -21,3 +24,7 @@ export declare const TYPE_FUNCTION = "function";
|
|
|
21
24
|
export declare const TYPE_STRING = "string";
|
|
22
25
|
export declare const TYPE_NUMBER = "number";
|
|
23
26
|
export declare const UTILS_STYLE_MAP = "styles";
|
|
27
|
+
export declare const VENDOR_UHTML = "@htmlplus/element/client/vendors/uhtml.js";
|
|
28
|
+
export declare const AUTO_IMPORT_STYLE = "AUTO_IMPORT_STYLE";
|
|
29
|
+
export declare const COMMENT_AUTO_ADDED_DEPENDENCY = " THIS DEPENDENCY IS AUTO-ADDED, DO NOT EDIT MANUALY";
|
|
30
|
+
export declare const COMMENT_AUTO_ADDED_PROPERTY = " THIS PROPERTY IS AUTO-ADDED, DO NOT EDIT MANUALY";
|
package/constants/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export const PACKAGE_NAME = '@htmlplus/element';
|
|
2
2
|
// apis
|
|
3
|
-
export const API_HOST =
|
|
3
|
+
export const API_HOST = Symbol();
|
|
4
|
+
export const API_INSTANCE = Symbol();
|
|
4
5
|
// TODO
|
|
5
|
-
export const API_STATUS =
|
|
6
|
+
export const API_STATUS = Symbol();
|
|
6
7
|
// decorators
|
|
7
8
|
export const DECORATOR_ELEMENT = 'Element';
|
|
8
9
|
export const DECORATOR_EVENT = 'Event';
|
|
@@ -20,6 +21,8 @@ export const LIFECYCLE_UPDATED = 'updatedCallback';
|
|
|
20
21
|
export const METHOD_RENDER = 'render';
|
|
21
22
|
// statics
|
|
22
23
|
export const STATIC_MEMBERS = 'members';
|
|
24
|
+
export const STATIC_MEMBERS_INITIALIZER = 'default';
|
|
25
|
+
export const STATIC_MEMBERS_TYPE = 'type';
|
|
23
26
|
export const STATIC_STYLES = 'styles';
|
|
24
27
|
// types
|
|
25
28
|
export const TYPE_BOOLEAN = 'boolean';
|
|
@@ -29,3 +32,8 @@ export const TYPE_STRING = 'string';
|
|
|
29
32
|
export const TYPE_NUMBER = 'number';
|
|
30
33
|
// utils
|
|
31
34
|
export const UTILS_STYLE_MAP = 'styles';
|
|
35
|
+
// TODO
|
|
36
|
+
export const VENDOR_UHTML = '@htmlplus/element/client/vendors/uhtml.js';
|
|
37
|
+
export const AUTO_IMPORT_STYLE = 'AUTO_IMPORT_STYLE';
|
|
38
|
+
export const COMMENT_AUTO_ADDED_DEPENDENCY = ' THIS DEPENDENCY IS AUTO-ADDED, DO NOT EDIT MANUALY';
|
|
39
|
+
export const COMMENT_AUTO_ADDED_PROPERTY = ' THIS PROPERTY IS AUTO-ADDED, DO NOT EDIT MANUALY';
|