@htmlplus/element 2.12.0 → 2.13.1
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/README.md +2 -2
- package/bundlers.d.ts +19 -0
- package/bundlers.js +75 -0
- package/client-5FqNUiuz.d.ts +309 -0
- package/client-By_MTZkm.js +1796 -0
- package/client.d.ts +1 -0
- package/client.js +3 -0
- package/constants.d.ts +50 -0
- package/constants.js +62 -0
- package/internal.d.ts +1 -0
- package/internal.js +3 -0
- package/package.json +9 -4
- package/transformer.d.ts +137 -0
- package/transformer.js +1253 -0
- package/bundlers/rollup.d.ts +0 -7
- package/bundlers/rollup.js +0 -23
- package/bundlers/vite.d.ts +0 -8
- package/bundlers/vite.js +0 -52
- package/client/decorators/bind.d.ts +0 -8
- package/client/decorators/bind.js +0 -21
- package/client/decorators/context.d.ts +0 -3
- package/client/decorators/context.js +0 -121
- package/client/decorators/direction.d.ts +0 -5
- package/client/decorators/direction.js +0 -8
- package/client/decorators/element.d.ts +0 -7
- package/client/decorators/element.js +0 -65
- package/client/decorators/event.d.ts +0 -35
- package/client/decorators/event.js +0 -53
- package/client/decorators/host.d.ts +0 -4
- package/client/decorators/host.js +0 -7
- package/client/decorators/index.d.ts +0 -15
- package/client/decorators/index.js +0 -15
- package/client/decorators/isRTL.d.ts +0 -4
- package/client/decorators/isRTL.js +0 -7
- package/client/decorators/listen.d.ts +0 -52
- package/client/decorators/listen.js +0 -37
- package/client/decorators/method.d.ts +0 -6
- package/client/decorators/method.js +0 -15
- package/client/decorators/property.d.ts +0 -25
- package/client/decorators/property.js +0 -94
- package/client/decorators/query.d.ts +0 -9
- package/client/decorators/query.js +0 -12
- package/client/decorators/queryAll.d.ts +0 -12
- package/client/decorators/queryAll.js +0 -15
- package/client/decorators/slots.d.ts +0 -4
- package/client/decorators/slots.js +0 -7
- package/client/decorators/state.d.ts +0 -6
- package/client/decorators/state.js +0 -23
- package/client/decorators/watch.d.ts +0 -11
- package/client/decorators/watch.js +0 -31
- package/client/index.d.ts +0 -2
- package/client/index.js +0 -2
- package/client/utils/appendToMethod.d.ts +0 -1
- package/client/utils/appendToMethod.js +0 -15
- package/client/utils/attributes.d.ts +0 -2
- package/client/utils/attributes.js +0 -33
- package/client/utils/call.d.ts +0 -1
- package/client/utils/call.js +0 -3
- package/client/utils/classes.d.ts +0 -4
- package/client/utils/classes.js +0 -45
- package/client/utils/config.d.ts +0 -39
- package/client/utils/config.js +0 -28
- package/client/utils/defineProperty.d.ts +0 -1
- package/client/utils/defineProperty.js +0 -1
- package/client/utils/direction.d.ts +0 -6
- package/client/utils/direction.js +0 -8
- package/client/utils/event.d.ts +0 -13
- package/client/utils/event.js +0 -48
- package/client/utils/getFramework.d.ts +0 -2
- package/client/utils/getFramework.js +0 -20
- package/client/utils/getStyles.d.ts +0 -2
- package/client/utils/getStyles.js +0 -4
- package/client/utils/getTag.d.ts +0 -2
- package/client/utils/getTag.js +0 -4
- package/client/utils/host.d.ts +0 -5
- package/client/utils/host.js +0 -12
- package/client/utils/index.d.ts +0 -32
- package/client/utils/index.js +0 -32
- package/client/utils/isCSSColor.d.ts +0 -5
- package/client/utils/isCSSColor.js +0 -9
- package/client/utils/isEvent.d.ts +0 -1
- package/client/utils/isEvent.js +0 -3
- package/client/utils/isRTL.d.ts +0 -5
- package/client/utils/isRTL.js +0 -5
- package/client/utils/isServer.d.ts +0 -4
- package/client/utils/isServer.js +0 -6
- package/client/utils/merge.d.ts +0 -1
- package/client/utils/merge.js +0 -22
- package/client/utils/query.d.ts +0 -5
- package/client/utils/query.js +0 -7
- package/client/utils/queryAll.d.ts +0 -5
- package/client/utils/queryAll.js +0 -7
- package/client/utils/request.d.ts +0 -9
- package/client/utils/request.js +0 -106
- package/client/utils/shadowRoot.d.ts +0 -2
- package/client/utils/shadowRoot.js +0 -4
- package/client/utils/slots.d.ts +0 -9
- package/client/utils/slots.js +0 -18
- package/client/utils/styles.d.ts +0 -4
- package/client/utils/styles.js +0 -10
- package/client/utils/task.d.ts +0 -6
- package/client/utils/task.js +0 -34
- package/client/utils/toBoolean.d.ts +0 -1
- package/client/utils/toBoolean.js +0 -3
- package/client/utils/toDecorator.d.ts +0 -2
- package/client/utils/toDecorator.js +0 -10
- package/client/utils/toEvent.d.ts +0 -1
- package/client/utils/toEvent.js +0 -3
- package/client/utils/toProperty.d.ts +0 -1
- package/client/utils/toProperty.js +0 -55
- package/client/utils/toUnit.d.ts +0 -4
- package/client/utils/toUnit.js +0 -10
- package/client/utils/typeOf.d.ts +0 -3
- package/client/utils/typeOf.js +0 -6
- package/client/utils/uhtml.d.ts +0 -22
- package/client/utils/uhtml.js +0 -703
- package/client/utils/updateAttribute.d.ts +0 -2
- package/client/utils/updateAttribute.js +0 -10
- package/constants/index.d.ts +0 -48
- package/constants/index.js +0 -60
- package/transformer/index.d.ts +0 -3
- package/transformer/index.js +0 -3
- package/transformer/plugins/assets.d.ts +0 -7
- package/transformer/plugins/assets.js +0 -26
- package/transformer/plugins/copy.d.ts +0 -9
- package/transformer/plugins/copy.js +0 -29
- package/transformer/plugins/customElement.d.ts +0 -7
- package/transformer/plugins/customElement.js +0 -392
- package/transformer/plugins/document.d.ts +0 -7
- package/transformer/plugins/document.js +0 -206
- package/transformer/plugins/extract.d.ts +0 -2
- package/transformer/plugins/extract.js +0 -22
- package/transformer/plugins/index.d.ts +0 -12
- package/transformer/plugins/index.js +0 -12
- package/transformer/plugins/parse.d.ts +0 -6
- package/transformer/plugins/parse.js +0 -13
- package/transformer/plugins/read.d.ts +0 -7
- package/transformer/plugins/read.js +0 -19
- package/transformer/plugins/readme.d.ts +0 -6
- package/transformer/plugins/readme.js +0 -24
- package/transformer/plugins/style.d.ts +0 -6
- package/transformer/plugins/style.js +0 -42
- package/transformer/plugins/validate.d.ts +0 -2
- package/transformer/plugins/validate.js +0 -40
- package/transformer/plugins/visualStudioCode.d.ts +0 -8
- package/transformer/plugins/visualStudioCode.js +0 -73
- package/transformer/plugins/webTypes.d.ts +0 -10
- package/transformer/plugins/webTypes.js +0 -74
- package/transformer/transformer.d.ts +0 -8
- package/transformer/transformer.js +0 -78
- package/transformer/transformer.types.d.ts +0 -52
- package/transformer/transformer.types.js +0 -1
- package/transformer/utils/addDependency.d.ts +0 -7
- package/transformer/utils/addDependency.js +0 -64
- package/transformer/utils/extractAttribute.d.ts +0 -2
- package/transformer/utils/extractAttribute.js +0 -10
- package/transformer/utils/extractFromComment.d.ts +0 -4
- package/transformer/utils/extractFromComment.js +0 -51
- package/transformer/utils/getInitializer.d.ts +0 -2
- package/transformer/utils/getInitializer.js +0 -3
- package/transformer/utils/getType.d.ts +0 -2
- package/transformer/utils/getType.js +0 -89
- package/transformer/utils/getTypeReference.d.ts +0 -2
- package/transformer/utils/getTypeReference.js +0 -33
- package/transformer/utils/hasDecorator.d.ts +0 -1
- package/transformer/utils/hasDecorator.js +0 -5
- package/transformer/utils/index.d.ts +0 -10
- package/transformer/utils/index.js +0 -10
- package/transformer/utils/print.d.ts +0 -2
- package/transformer/utils/print.js +0 -5
- package/transformer/utils/printType.d.ts +0 -1
- package/transformer/utils/printType.js +0 -69
- package/transformer/utils/visitor.d.ts +0 -2
- package/transformer/utils/visitor.js +0 -5
- package/types/index.d.ts +0 -2
- package/types/index.js +0 -1
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import ora from 'ora';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
const logger = ora({
|
|
4
|
-
color: 'yellow'
|
|
5
|
-
});
|
|
6
|
-
const log = (message, persist) => {
|
|
7
|
-
const content = `${new Date().toLocaleTimeString()} [HTMLPLUS] ${message}`;
|
|
8
|
-
const log = logger.start(content);
|
|
9
|
-
if (!persist)
|
|
10
|
-
return;
|
|
11
|
-
log.succeed();
|
|
12
|
-
};
|
|
13
|
-
export const transformer = (...plugins) => {
|
|
14
|
-
let global = {
|
|
15
|
-
contexts: []
|
|
16
|
-
};
|
|
17
|
-
const start = async () => {
|
|
18
|
-
log(`Started.`, true);
|
|
19
|
-
log(`${plugins.length} plugins found.`, true);
|
|
20
|
-
log(`Plugins are starting.`, true);
|
|
21
|
-
for (const plugin of plugins) {
|
|
22
|
-
if (!plugin.start)
|
|
23
|
-
continue;
|
|
24
|
-
log(`Plugin '${plugin.name}' is starting.`);
|
|
25
|
-
global = (await plugin.start(global)) || global;
|
|
26
|
-
log(`Plugin '${plugin.name}' started successfully.`);
|
|
27
|
-
}
|
|
28
|
-
log(`Plugins started successfully.`, true);
|
|
29
|
-
};
|
|
30
|
-
const run = async (filePath) => {
|
|
31
|
-
const key = path.join(filePath).split(path.sep).pop();
|
|
32
|
-
let context = {
|
|
33
|
-
filePath
|
|
34
|
-
};
|
|
35
|
-
const parsed = path.parse(filePath);
|
|
36
|
-
for (const plugin of plugins) {
|
|
37
|
-
if (!plugin.run)
|
|
38
|
-
continue;
|
|
39
|
-
const source = path.join(parsed.dir).split(path.sep).slice(-2).concat(parsed.base).join('/');
|
|
40
|
-
log(`Plugin '${plugin.name}' is executing on '${source}' file.`);
|
|
41
|
-
try {
|
|
42
|
-
context = (await plugin.run(context, global)) || context;
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
log(`Error in '${plugin.name}' plugin on '${source}' file.\n`, true);
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
48
|
-
global.contexts = global.contexts
|
|
49
|
-
.filter((current) => {
|
|
50
|
-
return current.filePath != context.filePath;
|
|
51
|
-
})
|
|
52
|
-
.concat(context);
|
|
53
|
-
log(`Plugin '${plugin.name}' executed successfully on '${source}' file.`);
|
|
54
|
-
}
|
|
55
|
-
logger.stop();
|
|
56
|
-
return context;
|
|
57
|
-
};
|
|
58
|
-
const finish = async () => {
|
|
59
|
-
log(`Plugins are finishing.`, true);
|
|
60
|
-
for (const plugin of plugins) {
|
|
61
|
-
if (!plugin.finish)
|
|
62
|
-
continue;
|
|
63
|
-
log(`Plugin '${plugin.name}' is finishing.`);
|
|
64
|
-
global = (await plugin.finish(global)) || global;
|
|
65
|
-
log(`Plugin '${plugin.name}' finished successfully.`);
|
|
66
|
-
}
|
|
67
|
-
log(`Plugins finished successfully.`, true);
|
|
68
|
-
log(`Finished.`, true);
|
|
69
|
-
};
|
|
70
|
-
const write = async () => {
|
|
71
|
-
for (const plugin of plugins) {
|
|
72
|
-
if (!plugin.write)
|
|
73
|
-
continue;
|
|
74
|
-
global = (await plugin.write(global)) || global;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
return { global, start, run, finish, write };
|
|
78
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ClassBody, ClassDeclaration, ClassMethod, ClassProperty, File } from '@babel/types';
|
|
2
|
-
type Return<T> = void | T | Promise<void | T>;
|
|
3
|
-
export interface TransformerPluginContext {
|
|
4
|
-
skipped?: boolean;
|
|
5
|
-
script?: string;
|
|
6
|
-
assetsDestination?: string;
|
|
7
|
-
assetsSource?: string;
|
|
8
|
-
class?: ClassDeclaration;
|
|
9
|
-
classEvents?: Array<ClassProperty>;
|
|
10
|
-
classMembers?: ClassBody['body'];
|
|
11
|
-
classMethods?: Array<ClassMethod>;
|
|
12
|
-
className?: string;
|
|
13
|
-
classProperties?: Array<ClassProperty>;
|
|
14
|
-
classStates?: Array<ClassProperty>;
|
|
15
|
-
directoryName?: string;
|
|
16
|
-
directoryPath?: string;
|
|
17
|
-
elementKey?: string;
|
|
18
|
-
elementInterfaceName?: string;
|
|
19
|
-
elementTagName?: string;
|
|
20
|
-
fileAST?: File;
|
|
21
|
-
fileContent?: string;
|
|
22
|
-
fileExtension?: string;
|
|
23
|
-
fileName?: string;
|
|
24
|
-
filePath?: string;
|
|
25
|
-
metadata?: {
|
|
26
|
-
[key: string]: any;
|
|
27
|
-
};
|
|
28
|
-
readmeContent?: string;
|
|
29
|
-
readmeExtension?: string;
|
|
30
|
-
readmeName?: string;
|
|
31
|
-
readmePath?: string;
|
|
32
|
-
styleContent?: string;
|
|
33
|
-
styleContentTransformed?: string;
|
|
34
|
-
styleExtension?: string;
|
|
35
|
-
styleName?: string;
|
|
36
|
-
stylePath?: string;
|
|
37
|
-
}
|
|
38
|
-
export interface TransformerPluginGlobal {
|
|
39
|
-
contexts: Array<TransformerPluginContext>;
|
|
40
|
-
metadata?: {
|
|
41
|
-
[key: string]: any;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export interface TransformerPlugin {
|
|
45
|
-
name: string;
|
|
46
|
-
options?: any;
|
|
47
|
-
start?: (global: TransformerPluginGlobal) => Return<TransformerPluginGlobal>;
|
|
48
|
-
run?: (context: TransformerPluginContext, global: TransformerPluginGlobal) => Return<TransformerPluginContext>;
|
|
49
|
-
finish?: (global: TransformerPluginGlobal) => Return<TransformerPluginGlobal>;
|
|
50
|
-
write?: (global: TransformerPluginGlobal) => Return<TransformerPluginGlobal>;
|
|
51
|
-
}
|
|
52
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import t from '@babel/types';
|
|
2
|
-
interface AddDependencyReturns {
|
|
3
|
-
local?: string;
|
|
4
|
-
node: t.ImportDeclaration;
|
|
5
|
-
}
|
|
6
|
-
export declare function addDependency(path: t.File | any, source: string, local?: string, imported?: string, comment?: boolean): AddDependencyReturns;
|
|
7
|
-
export {};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import t from '@babel/types';
|
|
2
|
-
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
-
import { visitor } from './visitor.js';
|
|
4
|
-
export function addDependency(path, source, local, imported, comment) {
|
|
5
|
-
const isDefault = local && !imported;
|
|
6
|
-
const isImport = local && imported;
|
|
7
|
-
const isNormal = !local && !imported;
|
|
8
|
-
let declaration;
|
|
9
|
-
let file = path;
|
|
10
|
-
while (file.parentPath)
|
|
11
|
-
file = file.parentPath;
|
|
12
|
-
file = file.node || file;
|
|
13
|
-
visitor(file, {
|
|
14
|
-
ImportDeclaration(path) {
|
|
15
|
-
if (path.node.source.value != source)
|
|
16
|
-
return;
|
|
17
|
-
declaration = path.node;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
if (isNormal && declaration)
|
|
21
|
-
return {
|
|
22
|
-
node: declaration
|
|
23
|
-
};
|
|
24
|
-
let specifier = declaration?.specifiers.find((specifier) => {
|
|
25
|
-
if (isDefault) {
|
|
26
|
-
return specifier.type == 'ImportDefaultSpecifier';
|
|
27
|
-
}
|
|
28
|
-
else if (isImport) {
|
|
29
|
-
return specifier.imported?.name == imported;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
if (specifier)
|
|
33
|
-
return {
|
|
34
|
-
local: specifier.local.name,
|
|
35
|
-
node: declaration
|
|
36
|
-
};
|
|
37
|
-
if (isDefault) {
|
|
38
|
-
specifier = t.importDefaultSpecifier(t.identifier(local));
|
|
39
|
-
}
|
|
40
|
-
else if (isImport) {
|
|
41
|
-
specifier = t.importSpecifier(t.identifier(local), t.identifier(imported));
|
|
42
|
-
}
|
|
43
|
-
if (declaration) {
|
|
44
|
-
if (isDefault) {
|
|
45
|
-
declaration.specifiers.unshift(specifier);
|
|
46
|
-
}
|
|
47
|
-
else if (isImport) {
|
|
48
|
-
declaration.specifiers.push(specifier);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
declaration = t.importDeclaration(specifier ? [specifier] : [], t.stringLiteral(source));
|
|
53
|
-
// TODO
|
|
54
|
-
(file.program || file).body.unshift(declaration);
|
|
55
|
-
// TODO
|
|
56
|
-
if (comment) {
|
|
57
|
-
t.addComment(declaration, 'leading', CONSTANTS.COMMENT_AUTO_ADDED, true);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
local,
|
|
62
|
-
node: declaration
|
|
63
|
-
};
|
|
64
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
export const extractAttribute = (property) => {
|
|
3
|
-
try {
|
|
4
|
-
return property.decorators
|
|
5
|
-
.find((decorator) => decorator.expression.callee.name == CONSTANTS.DECORATOR_PROPERTY)
|
|
6
|
-
.expression.arguments[0].properties.find((property) => property.key.name == 'attribute').value
|
|
7
|
-
.value;
|
|
8
|
-
}
|
|
9
|
-
catch { }
|
|
10
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export const extractFromComment = (node, whitelist) => {
|
|
2
|
-
const normalized = [];
|
|
3
|
-
const result = {
|
|
4
|
-
description: ''
|
|
5
|
-
};
|
|
6
|
-
const lines = node.leadingComments
|
|
7
|
-
?.map((comment) => {
|
|
8
|
-
if (comment.type == 'CommentLine')
|
|
9
|
-
return comment.value;
|
|
10
|
-
return comment.value.split('\n');
|
|
11
|
-
})
|
|
12
|
-
?.flat()
|
|
13
|
-
?.map((line) => line.trim().replace(/^\*/, '').trim())
|
|
14
|
-
?.filter((line) => line.trim());
|
|
15
|
-
for (const line of lines || []) {
|
|
16
|
-
if (line.startsWith('@')) {
|
|
17
|
-
normalized.push(line);
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
if (!normalized.length)
|
|
21
|
-
normalized.push('');
|
|
22
|
-
normalized[normalized.length - 1] += ' ' + line;
|
|
23
|
-
}
|
|
24
|
-
for (const line of normalized) {
|
|
25
|
-
if (!line.startsWith('@')) {
|
|
26
|
-
result.description = line.trim();
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const regex = /@(\w+)(?:\s*({\w+})\s*)?(?:\s*([-a-zA-Z\s]+)\s*-\s*)?(.*)/;
|
|
30
|
-
const groups = regex.exec(line);
|
|
31
|
-
if (!groups)
|
|
32
|
-
continue;
|
|
33
|
-
const tag = groups[1]?.trim();
|
|
34
|
-
const type = groups[2]?.trim().slice(1, -1);
|
|
35
|
-
const name = groups[3]?.trim();
|
|
36
|
-
const description = groups[4]?.trim();
|
|
37
|
-
if (name && description) {
|
|
38
|
-
const key = tag + 's';
|
|
39
|
-
if (whitelist && !whitelist.includes(key))
|
|
40
|
-
continue;
|
|
41
|
-
(result[key] ||= []).push({ name, type, description });
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const key = tag;
|
|
45
|
-
if (whitelist && !whitelist.includes(key))
|
|
46
|
-
continue;
|
|
47
|
-
result[key] = description || true;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { parse } from '@babel/parser';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { glob } from 'glob';
|
|
4
|
-
import { dirname, resolve } from 'path';
|
|
5
|
-
import { join } from 'path';
|
|
6
|
-
import { visitor } from './visitor.js';
|
|
7
|
-
export const getType = (directory, file, node) => {
|
|
8
|
-
if (!node)
|
|
9
|
-
return node;
|
|
10
|
-
if (node.type != 'TSTypeReference')
|
|
11
|
-
return node;
|
|
12
|
-
let result;
|
|
13
|
-
visitor(file, {
|
|
14
|
-
ClassDeclaration(path) {
|
|
15
|
-
if (path.node.id.name != node.typeName['name'])
|
|
16
|
-
return;
|
|
17
|
-
result = path.node;
|
|
18
|
-
path.stop();
|
|
19
|
-
},
|
|
20
|
-
ImportDeclaration(path) {
|
|
21
|
-
for (const specifier of path.node.specifiers) {
|
|
22
|
-
const alias = specifier.local.name;
|
|
23
|
-
if (alias != node.typeName['name'])
|
|
24
|
-
continue;
|
|
25
|
-
let key;
|
|
26
|
-
switch (specifier.type) {
|
|
27
|
-
case 'ImportNamespaceSpecifier':
|
|
28
|
-
key = '*';
|
|
29
|
-
break;
|
|
30
|
-
case 'ImportDefaultSpecifier':
|
|
31
|
-
key = 'default';
|
|
32
|
-
break;
|
|
33
|
-
case 'ImportSpecifier':
|
|
34
|
-
key = specifier.imported.name;
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const reference = glob
|
|
39
|
-
.sync(['.ts*', '/index.ts*'].map((key) => {
|
|
40
|
-
return join(directory, path.node.source.value).replace(/\\/g, '/') + key;
|
|
41
|
-
}))
|
|
42
|
-
.find((reference) => fs.existsSync(reference));
|
|
43
|
-
const content = fs.readFileSync(reference, 'utf8');
|
|
44
|
-
const filePath = resolve(directory, path.node.source.value + '.ts');
|
|
45
|
-
path.$ast ||= parse(content, {
|
|
46
|
-
allowImportExportEverywhere: true,
|
|
47
|
-
plugins: ['typescript'],
|
|
48
|
-
ranges: false
|
|
49
|
-
});
|
|
50
|
-
result = getType(dirname(filePath), path.$ast, node);
|
|
51
|
-
}
|
|
52
|
-
catch { }
|
|
53
|
-
path.stop();
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
TSInterfaceDeclaration(path) {
|
|
58
|
-
if (path.node.id.name != node.typeName['name'])
|
|
59
|
-
return;
|
|
60
|
-
result = path.node;
|
|
61
|
-
path.stop();
|
|
62
|
-
},
|
|
63
|
-
TSTypeAliasDeclaration(path) {
|
|
64
|
-
if (path.node.id.name != node.typeName['name'])
|
|
65
|
-
return;
|
|
66
|
-
result = path.node.typeAnnotation;
|
|
67
|
-
switch (result.type) {
|
|
68
|
-
case 'TSUnionType':
|
|
69
|
-
const types = [];
|
|
70
|
-
for (const prev of result.types) {
|
|
71
|
-
const next = getType(directory, file, prev);
|
|
72
|
-
if (next.type == 'TSUnionType') {
|
|
73
|
-
next.types.forEach((type) => types.push(type));
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
types.push(next);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
result.types = types;
|
|
80
|
-
break;
|
|
81
|
-
default:
|
|
82
|
-
result = getType(directory, file, result);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
path.stop();
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return result || node;
|
|
89
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { visitor } from './visitor.js';
|
|
2
|
-
export const getTypeReference = (file, node) => {
|
|
3
|
-
if (!node)
|
|
4
|
-
return;
|
|
5
|
-
if (node.type != 'TSTypeReference')
|
|
6
|
-
return;
|
|
7
|
-
let result;
|
|
8
|
-
visitor(file, {
|
|
9
|
-
ImportDeclaration(path) {
|
|
10
|
-
for (const specifier of path.node.specifiers) {
|
|
11
|
-
const alias = specifier.local.name;
|
|
12
|
-
if (alias != node.typeName['name'])
|
|
13
|
-
continue;
|
|
14
|
-
let key;
|
|
15
|
-
switch (specifier.type) {
|
|
16
|
-
case 'ImportNamespaceSpecifier':
|
|
17
|
-
key = '*';
|
|
18
|
-
break;
|
|
19
|
-
case 'ImportDefaultSpecifier':
|
|
20
|
-
key = 'default';
|
|
21
|
-
break;
|
|
22
|
-
case 'ImportSpecifier':
|
|
23
|
-
key = specifier.imported.name;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
result = path.node.source.value;
|
|
27
|
-
path.stop();
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const hasDecorator: (node: any, name: string) => boolean;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './addDependency.js';
|
|
2
|
-
export * from './extractAttribute.js';
|
|
3
|
-
export * from './extractFromComment.js';
|
|
4
|
-
export * from './getInitializer.js';
|
|
5
|
-
export * from './getType.js';
|
|
6
|
-
export * from './getTypeReference.js';
|
|
7
|
-
export * from './hasDecorator.js';
|
|
8
|
-
export * from './printType.js';
|
|
9
|
-
export * from './print.js';
|
|
10
|
-
export * from './visitor.js';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './addDependency.js';
|
|
2
|
-
export * from './extractAttribute.js';
|
|
3
|
-
export * from './extractFromComment.js';
|
|
4
|
-
export * from './getInitializer.js';
|
|
5
|
-
export * from './getType.js';
|
|
6
|
-
export * from './getTypeReference.js';
|
|
7
|
-
export * from './hasDecorator.js';
|
|
8
|
-
export * from './printType.js';
|
|
9
|
-
export * from './print.js';
|
|
10
|
-
export * from './visitor.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const printType: (ast: any) => any;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { print } from './print.js';
|
|
2
|
-
// TODO
|
|
3
|
-
// args types
|
|
4
|
-
// return type
|
|
5
|
-
// elements\grid-item\grid-item.types.ts
|
|
6
|
-
// elements\portal\portal.tsx
|
|
7
|
-
export const printType = (ast) => {
|
|
8
|
-
if (!ast)
|
|
9
|
-
return ast;
|
|
10
|
-
let result = {};
|
|
11
|
-
switch (ast.type) {
|
|
12
|
-
case 'BooleanLiteral':
|
|
13
|
-
case 'NumericLiteral':
|
|
14
|
-
case 'StringLiteral': {
|
|
15
|
-
result.key = ast.value;
|
|
16
|
-
result.type = ast.type.replace('Literal', '').toLowerCase();
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
case 'TSBooleanKeyword':
|
|
20
|
-
case 'TSNumberKeyword':
|
|
21
|
-
case 'TSStringKeyword': {
|
|
22
|
-
const type = ast.type.replace('TS', '').replace('Keyword', '').toLowerCase();
|
|
23
|
-
result.key = type;
|
|
24
|
-
result.type = type;
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
case 'TSAnyKeyword': {
|
|
28
|
-
result.type = 'any';
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
case 'TSArrayType': {
|
|
32
|
-
const type = print(ast.elementType) + '[]';
|
|
33
|
-
result.key = type;
|
|
34
|
-
result.type = type;
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
case 'TSInterfaceDeclaration': {
|
|
38
|
-
result.type = ast.id.name;
|
|
39
|
-
result.members = ast.body.body.map((body) => printType(body));
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
case 'TSLiteralType': {
|
|
43
|
-
result = printType(ast.literal);
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
case 'TSPropertySignature': {
|
|
47
|
-
const { typeAnnotation } = ast;
|
|
48
|
-
result.key = ast.key.name;
|
|
49
|
-
if (typeAnnotation && typeAnnotation.typeAnnotation)
|
|
50
|
-
result.type = printType(ast.typeAnnotation.typeAnnotation).type;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
case 'TSTypeAliasDeclaration': {
|
|
54
|
-
result = printType(ast.typeAnnotation);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
case 'TSTypeReference': {
|
|
58
|
-
result.key = ast.typeName.name;
|
|
59
|
-
result.type = ast.typeName.name;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
case 'TSUnionType': {
|
|
63
|
-
result.type = print(ast);
|
|
64
|
-
result.members = ast.types.map((type) => printType(type));
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
};
|
package/types/index.d.ts
DELETED
package/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|