@melt-js/libs-core 2026.11.16-1 → 2026.11.16-2
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 +38 -22
- package/dist/browser.d.mts +3 -3
- package/dist/browser.mjs +1 -1
- package/dist/browser.mjs.gz +0 -0
- package/dist/cdn/browser.umd.cjs +1 -1
- package/dist/cdn/browser.umd.cjs.gz +0 -0
- package/dist/cdn/demo-browser.umd.cjs +1 -1
- package/dist/cdn/demo-browser.umd.cjs.gz +0 -0
- package/dist/cdn/demo.umd.cjs +1 -1
- package/dist/cdn/demo.umd.cjs.gz +0 -0
- package/dist/cdn/example-esm.html +1 -1
- package/dist/cdn/index.umd.cjs +1 -1
- package/dist/cdn/index.umd.cjs.gz +0 -0
- package/dist/cdn/manifest.json +17 -5
- package/dist/cdn/vendor.umd.cjs +0 -34
- package/dist/cdn/vendor.umd.cjs.gz +0 -0
- package/dist/cdn.d.mts +3 -3
- package/dist/cdn.mjs +1 -1
- package/dist/demo/browser.d.mts +1 -0
- package/dist/demo/browser.mjs +1 -1
- package/dist/demo/browser.mjs.gz +0 -0
- package/dist/demo/clipboard.d.mts +6 -6
- package/dist/demo/clipboard.mjs +1 -1
- package/dist/demo/docs.d.mts +28 -28
- package/dist/demo/docs.mjs +1 -1
- package/dist/demo/docs.mjs.gz +0 -0
- package/dist/demo/download.d.mts +3 -0
- package/dist/demo/download.mjs +1 -1
- package/dist/demo/download.mjs.gz +0 -0
- package/dist/demo/fullscreen.d.mts +8 -8
- package/dist/demo/fullscreen.mjs +1 -1
- package/dist/demo/highlight.d.mts +2 -0
- package/dist/demo/highlight.mjs +1 -0
- package/dist/demo/index.d.mts +1 -0
- package/dist/demo/index.mjs +1 -1
- package/dist/demo/model.d.mts +12 -12
- package/dist/demo/remote-debug.d.mts +9 -11
- package/dist/demo/remote-debug.mjs +1 -1
- package/dist/demo/split-pane.d.mts +8 -8
- package/dist/demo/split-pane.mjs +1 -1
- package/dist/demo/standalone.d.mts +3 -0
- package/dist/demo/standalone.mjs +1 -1
- package/dist/demo/standalone.mjs.gz +0 -0
- package/dist/demo/tabs.d.mts +15 -15
- package/dist/demo/tabs.mjs +1 -1
- package/dist/loading.mjs +1 -1
- package/dist/loading.mjs.gz +0 -0
- package/dist/remote.d.mts +114 -110
- package/dist/remote.mjs +1 -1
- package/dist/remote.mjs.gz +0 -0
- package/dist/vendor/hel-runtime.mjs +0 -34
- package/dist/vendor/hel-runtime.mjs.gz +0 -0
- package/package.json +1 -1
- package/scripts/browser-formats.mjs +8 -6
- package/scripts/build-browser.mjs +2 -2
- package/scripts/build-protected-esm.mjs +54 -51
- package/scripts/cdn-runtime.cjs +30 -30
- package/scripts/client-build-security.cjs +48 -48
- package/scripts/component-events.mjs +57 -57
- package/scripts/comps-bundle-obfuscation.cjs +4 -1
- package/scripts/comps-obfuscator-options.cjs +7 -1
- package/scripts/obfuscator-split-strings.cjs +22 -0
- package/scripts/package-artifacts.mjs +3 -3
- package/scripts/package-env.cjs +46 -90
- package/scripts/remote-address.cjs +30 -30
- package/scripts/vdoc-parser/NOTICE.md +13 -13
- package/scripts/vdoc-parser/constants.mjs +3 -3
- package/scripts/vdoc-parser/index.d.mts +34 -34
- package/scripts/vdoc-parser/index.mjs +2 -2
- package/scripts/vdoc-parser/parsers/index.mjs +14 -14
- package/scripts/vdoc-parser/parsers/parseCode.mjs +42 -42
- package/scripts/vdoc-parser/parsers/parseCommentBlock.mjs +9 -9
- package/scripts/vdoc-parser/parsers/parseComponentOptions.mjs +12 -12
- package/scripts/vdoc-parser/parsers/parseDefaultValue.mjs +57 -57
- package/scripts/vdoc-parser/parsers/parseDefineProps.mjs +33 -33
- package/scripts/vdoc-parser/parsers/parseExport.mjs +93 -93
- package/scripts/vdoc-parser/parsers/parseFile.mjs +22 -22
- package/scripts/vdoc-parser/parsers/parseFileSync.mjs +22 -22
- package/scripts/vdoc-parser/parsers/parsePropType.mjs +32 -32
- package/scripts/vdoc-parser/parsers/parseProps.mjs +90 -90
- package/scripts/vdoc-parser/parsers/parseSetupScript.mjs +14 -14
- package/scripts/vdoc-parser/parsers/parseSfc.mjs +21 -21
- package/scripts/vdoc-parser/parsers/parseTSTypeLiteral.mjs +48 -48
- package/scripts/vdoc-parser/parsers/parseTypes.mjs +53 -53
- package/scripts/vdoc-parser/parsers/parseTypesFile.mjs +22 -22
- package/scripts/vdoc-parser/parsers/parseTypesFileSync.mjs +22 -22
- package/scripts/vdoc-parser/resolvers/index.mjs +2 -2
- package/scripts/vdoc-parser/resolvers/resolveSpreadElements.mjs +51 -51
- package/scripts/vdoc-parser/utils.mjs +52 -52
- package/scripts/webpack-bundle-obfuscation.cjs +3 -1
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { isArrowFunctionExpression, isBooleanLiteral, isNumericLiteral, isStringLiteral, isObjectPattern, isObjectProperty, isAssignmentPattern, isIdentifier, isArrayExpression, isObjectExpression, isLiteral, isTemplateLiteral, isRegExpLiteral, isNullLiteral, } from '@babel/types';
|
|
3
|
-
import generator from '@babel/generator';
|
|
4
|
-
// Babel 7 is CommonJS: its default export is nested when loaded from native ESM.
|
|
5
|
-
const generate = generator.default;
|
|
6
|
-
export function parseDefaultValue(defaultValue) {
|
|
7
|
-
if (isArrowFunctionExpression(defaultValue.value)) {
|
|
8
|
-
try {
|
|
9
|
-
const { code } = generate(defaultValue.value.body);
|
|
10
|
-
return code;
|
|
11
|
-
}
|
|
12
|
-
catch { }
|
|
13
|
-
}
|
|
14
|
-
if (isBooleanLiteral(defaultValue.value)
|
|
15
|
-
|| isNumericLiteral(defaultValue.value)) {
|
|
16
|
-
return String(defaultValue.value.value);
|
|
17
|
-
}
|
|
18
|
-
if (isStringLiteral(defaultValue.value)) {
|
|
19
|
-
return `"${defaultValue.value.value}"`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 解析解构赋值语句获取默认值
|
|
24
|
-
*/
|
|
25
|
-
export function parseDefaultValuesFromObjectPattern(id) {
|
|
26
|
-
if (!isObjectPattern(id)) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
return id.properties.reduce((acc, prop) => {
|
|
30
|
-
if (isObjectProperty(prop) && isAssignmentPattern(prop.value)) {
|
|
31
|
-
if (isIdentifier(prop.value.left)) {
|
|
32
|
-
if (isArrayExpression(prop.value.right) || isObjectExpression(prop.value.right)) {
|
|
33
|
-
try {
|
|
34
|
-
const { code } = generate(prop.value.right);
|
|
35
|
-
acc[prop.value.left.name] = code;
|
|
36
|
-
}
|
|
37
|
-
catch { }
|
|
38
|
-
}
|
|
39
|
-
else if (isLiteral(prop.value.right)) {
|
|
40
|
-
if (isTemplateLiteral(prop.value.right)) {
|
|
41
|
-
// do nothing
|
|
42
|
-
}
|
|
43
|
-
else if (isRegExpLiteral(prop.value.right)) {
|
|
44
|
-
// do nothing
|
|
45
|
-
}
|
|
46
|
-
else if (isNullLiteral(prop.value.right)) {
|
|
47
|
-
acc[prop.value.left.name] = 'null';
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
acc[prop.value.left.name] = JSON.stringify(prop.value.right.value);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return acc;
|
|
56
|
-
}, {});
|
|
57
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { isArrowFunctionExpression, isBooleanLiteral, isNumericLiteral, isStringLiteral, isObjectPattern, isObjectProperty, isAssignmentPattern, isIdentifier, isArrayExpression, isObjectExpression, isLiteral, isTemplateLiteral, isRegExpLiteral, isNullLiteral, } from '@babel/types';
|
|
3
|
+
import generator from '@babel/generator';
|
|
4
|
+
// Babel 7 is CommonJS: its default export is nested when loaded from native ESM.
|
|
5
|
+
const generate = generator.default;
|
|
6
|
+
export function parseDefaultValue(defaultValue) {
|
|
7
|
+
if (isArrowFunctionExpression(defaultValue.value)) {
|
|
8
|
+
try {
|
|
9
|
+
const { code } = generate(defaultValue.value.body);
|
|
10
|
+
return code;
|
|
11
|
+
}
|
|
12
|
+
catch { }
|
|
13
|
+
}
|
|
14
|
+
if (isBooleanLiteral(defaultValue.value)
|
|
15
|
+
|| isNumericLiteral(defaultValue.value)) {
|
|
16
|
+
return String(defaultValue.value.value);
|
|
17
|
+
}
|
|
18
|
+
if (isStringLiteral(defaultValue.value)) {
|
|
19
|
+
return `"${defaultValue.value.value}"`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 解析解构赋值语句获取默认值
|
|
24
|
+
*/
|
|
25
|
+
export function parseDefaultValuesFromObjectPattern(id) {
|
|
26
|
+
if (!isObjectPattern(id)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
return id.properties.reduce((acc, prop) => {
|
|
30
|
+
if (isObjectProperty(prop) && isAssignmentPattern(prop.value)) {
|
|
31
|
+
if (isIdentifier(prop.value.left)) {
|
|
32
|
+
if (isArrayExpression(prop.value.right) || isObjectExpression(prop.value.right)) {
|
|
33
|
+
try {
|
|
34
|
+
const { code } = generate(prop.value.right);
|
|
35
|
+
acc[prop.value.left.name] = code;
|
|
36
|
+
}
|
|
37
|
+
catch { }
|
|
38
|
+
}
|
|
39
|
+
else if (isLiteral(prop.value.right)) {
|
|
40
|
+
if (isTemplateLiteral(prop.value.right)) {
|
|
41
|
+
// do nothing
|
|
42
|
+
}
|
|
43
|
+
else if (isRegExpLiteral(prop.value.right)) {
|
|
44
|
+
// do nothing
|
|
45
|
+
}
|
|
46
|
+
else if (isNullLiteral(prop.value.right)) {
|
|
47
|
+
acc[prop.value.left.name] = 'null';
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
acc[prop.value.left.name] = JSON.stringify(prop.value.right.value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
57
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { getCallExpressionArguments } from '../utils.mjs';
|
|
3
|
-
import { isCallExpression, isIdentifier, isObjectExpression, isTSInterfaceDeclaration, isTSTypeLiteral, isTSTypeReference, } from '@babel/types';
|
|
4
|
-
import { parseProps } from './parseProps.mjs';
|
|
5
|
-
import { parseTSTypeLiteral } from './parseTSTypeLiteral.mjs';
|
|
6
|
-
export function parseDefineProps(expression, statements, id) {
|
|
7
|
-
const args = getCallExpressionArguments(expression, 'defineProps');
|
|
8
|
-
/**
|
|
9
|
-
* 解析 defineProps 运行时参数
|
|
10
|
-
*/
|
|
11
|
-
if (args.length && isObjectExpression(args[0])) {
|
|
12
|
-
return parseProps(args[0]);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 解析 defineProps 泛型参数
|
|
16
|
-
*/
|
|
17
|
-
if (isCallExpression(expression) && expression.typeParameters) {
|
|
18
|
-
const { params } = expression.typeParameters;
|
|
19
|
-
const typeParam = params[0];
|
|
20
|
-
if (isTSTypeLiteral(typeParam)) {
|
|
21
|
-
return parseTSTypeLiteral(typeParam.members, id);
|
|
22
|
-
}
|
|
23
|
-
else if (isTSTypeReference(typeParam) && isIdentifier(typeParam.typeName)) {
|
|
24
|
-
const typeName = typeParam.typeName.name;
|
|
25
|
-
const typeDeclaration = statements.find(s => {
|
|
26
|
-
return isTSInterfaceDeclaration(s) && isIdentifier(s.id) && s.id.name === typeName;
|
|
27
|
-
});
|
|
28
|
-
if (typeDeclaration) {
|
|
29
|
-
return parseTSTypeLiteral(typeDeclaration.body.body, id);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { getCallExpressionArguments } from '../utils.mjs';
|
|
3
|
+
import { isCallExpression, isIdentifier, isObjectExpression, isTSInterfaceDeclaration, isTSTypeLiteral, isTSTypeReference, } from '@babel/types';
|
|
4
|
+
import { parseProps } from './parseProps.mjs';
|
|
5
|
+
import { parseTSTypeLiteral } from './parseTSTypeLiteral.mjs';
|
|
6
|
+
export function parseDefineProps(expression, statements, id) {
|
|
7
|
+
const args = getCallExpressionArguments(expression, 'defineProps');
|
|
8
|
+
/**
|
|
9
|
+
* 解析 defineProps 运行时参数
|
|
10
|
+
*/
|
|
11
|
+
if (args.length && isObjectExpression(args[0])) {
|
|
12
|
+
return parseProps(args[0]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 解析 defineProps 泛型参数
|
|
16
|
+
*/
|
|
17
|
+
if (isCallExpression(expression) && expression.typeParameters) {
|
|
18
|
+
const { params } = expression.typeParameters;
|
|
19
|
+
const typeParam = params[0];
|
|
20
|
+
if (isTSTypeLiteral(typeParam)) {
|
|
21
|
+
return parseTSTypeLiteral(typeParam.members, id);
|
|
22
|
+
}
|
|
23
|
+
else if (isTSTypeReference(typeParam) && isIdentifier(typeParam.typeName)) {
|
|
24
|
+
const typeName = typeParam.typeName.name;
|
|
25
|
+
const typeDeclaration = statements.find(s => {
|
|
26
|
+
return isTSInterfaceDeclaration(s) && isIdentifier(s.id) && s.id.name === typeName;
|
|
27
|
+
});
|
|
28
|
+
if (typeDeclaration) {
|
|
29
|
+
return parseTSTypeLiteral(typeDeclaration.body.body, id);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { getStatementExportType, getExportDeclaration, getComponentOptions, getCallExpressionArguments, } from '../utils.mjs';
|
|
3
|
-
import { resolveSpreadElements } from '../resolvers/index.mjs';
|
|
4
|
-
import { isVariableDeclaration, isObjectExpression, isCallExpression, isIdentifier, isArrowFunctionExpression, isSpreadElement, } from '@babel/types';
|
|
5
|
-
export function parseExport(statements, exportType, type, exportName) {
|
|
6
|
-
const statementExportType = getStatementExportType(exportType);
|
|
7
|
-
const declarations = getExportDeclaration(statements, statementExportType);
|
|
8
|
-
for (const exportDeclaration of declarations) {
|
|
9
|
-
if (isVariableDeclaration(exportDeclaration.declaration)) {
|
|
10
|
-
/** export const Comp = defineComponent({}) or export const Comp = {} */
|
|
11
|
-
if (type === 'component') {
|
|
12
|
-
const options = getComponentOptions(exportDeclaration.declaration.declarations);
|
|
13
|
-
return isObjectExpression(options)
|
|
14
|
-
? options
|
|
15
|
-
: undefined;
|
|
16
|
-
}
|
|
17
|
-
const declarator = exportName
|
|
18
|
-
? exportDeclaration.declaration.declarations.find(d => {
|
|
19
|
-
return isIdentifier(d.id) && d.id.name === exportName;
|
|
20
|
-
})
|
|
21
|
-
: exportDeclaration.declaration.declarations[0];
|
|
22
|
-
if (declarator) {
|
|
23
|
-
/**export const props = {} */
|
|
24
|
-
if (isObjectExpression(declarator.init)) {
|
|
25
|
-
const spreadElements = declarator.init.properties.filter(p => isSpreadElement(p));
|
|
26
|
-
const spreadInits = resolveSpreadElements(spreadElements, statements);
|
|
27
|
-
if (spreadInits.length) {
|
|
28
|
-
declarator.init.properties = [
|
|
29
|
-
...spreadInits.reduce((acc, init) => {
|
|
30
|
-
acc = [...acc, ...init.properties];
|
|
31
|
-
return acc;
|
|
32
|
-
}, []),
|
|
33
|
-
...declarator.init.properties,
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
return declarator.init;
|
|
37
|
-
/**export const props = () => ({}) */
|
|
38
|
-
}
|
|
39
|
-
else if (isArrowFunctionExpression(declarator.init) && isObjectExpression(declarator.init.body)) {
|
|
40
|
-
const spreadElements = declarator.init.body.properties.filter(p => isSpreadElement(p));
|
|
41
|
-
const spreadInits = resolveSpreadElements(spreadElements, statements);
|
|
42
|
-
if (spreadInits.length) {
|
|
43
|
-
declarator.init.body.properties = [
|
|
44
|
-
...spreadInits.reduce((acc, init) => {
|
|
45
|
-
acc = [...acc, ...init.properties];
|
|
46
|
-
return acc;
|
|
47
|
-
}, []),
|
|
48
|
-
...declarator.init.body.properties,
|
|
49
|
-
];
|
|
50
|
-
}
|
|
51
|
-
return declarator.init.body;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/** export default defineComponent({}) */
|
|
55
|
-
}
|
|
56
|
-
else if (isCallExpression(exportDeclaration.declaration)) {
|
|
57
|
-
const args = getCallExpressionArguments(exportDeclaration.declaration);
|
|
58
|
-
const options = args[0];
|
|
59
|
-
return isObjectExpression(options)
|
|
60
|
-
? options
|
|
61
|
-
: undefined;
|
|
62
|
-
/** export default {} */
|
|
63
|
-
}
|
|
64
|
-
else if (isObjectExpression(exportDeclaration.declaration)) {
|
|
65
|
-
return exportDeclaration.declaration;
|
|
66
|
-
/**
|
|
67
|
-
* const Comp = {} or const Comp = defineComponent({})
|
|
68
|
-
* export default Comp
|
|
69
|
-
**/
|
|
70
|
-
}
|
|
71
|
-
else if (isIdentifier(exportDeclaration.declaration)) {
|
|
72
|
-
const { name } = exportDeclaration.declaration;
|
|
73
|
-
const variableDeclaration = statements.find(s => isVariableDeclaration(s));
|
|
74
|
-
if (!variableDeclaration)
|
|
75
|
-
return;
|
|
76
|
-
const variableDeclarator = variableDeclaration.declarations.find(d => {
|
|
77
|
-
return isIdentifier(d.id) && d.id.name === name;
|
|
78
|
-
});
|
|
79
|
-
if (!variableDeclarator)
|
|
80
|
-
return;
|
|
81
|
-
if (isObjectExpression(variableDeclarator.init)) {
|
|
82
|
-
return variableDeclarator.init;
|
|
83
|
-
}
|
|
84
|
-
else if (isCallExpression(variableDeclarator.init)) {
|
|
85
|
-
const args = getCallExpressionArguments(variableDeclarator.init);
|
|
86
|
-
const options = args[0];
|
|
87
|
-
return isObjectExpression(options)
|
|
88
|
-
? options
|
|
89
|
-
: undefined;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { getStatementExportType, getExportDeclaration, getComponentOptions, getCallExpressionArguments, } from '../utils.mjs';
|
|
3
|
+
import { resolveSpreadElements } from '../resolvers/index.mjs';
|
|
4
|
+
import { isVariableDeclaration, isObjectExpression, isCallExpression, isIdentifier, isArrowFunctionExpression, isSpreadElement, } from '@babel/types';
|
|
5
|
+
export function parseExport(statements, exportType, type, exportName) {
|
|
6
|
+
const statementExportType = getStatementExportType(exportType);
|
|
7
|
+
const declarations = getExportDeclaration(statements, statementExportType);
|
|
8
|
+
for (const exportDeclaration of declarations) {
|
|
9
|
+
if (isVariableDeclaration(exportDeclaration.declaration)) {
|
|
10
|
+
/** export const Comp = defineComponent({}) or export const Comp = {} */
|
|
11
|
+
if (type === 'component') {
|
|
12
|
+
const options = getComponentOptions(exportDeclaration.declaration.declarations);
|
|
13
|
+
return isObjectExpression(options)
|
|
14
|
+
? options
|
|
15
|
+
: undefined;
|
|
16
|
+
}
|
|
17
|
+
const declarator = exportName
|
|
18
|
+
? exportDeclaration.declaration.declarations.find(d => {
|
|
19
|
+
return isIdentifier(d.id) && d.id.name === exportName;
|
|
20
|
+
})
|
|
21
|
+
: exportDeclaration.declaration.declarations[0];
|
|
22
|
+
if (declarator) {
|
|
23
|
+
/**export const props = {} */
|
|
24
|
+
if (isObjectExpression(declarator.init)) {
|
|
25
|
+
const spreadElements = declarator.init.properties.filter(p => isSpreadElement(p));
|
|
26
|
+
const spreadInits = resolveSpreadElements(spreadElements, statements);
|
|
27
|
+
if (spreadInits.length) {
|
|
28
|
+
declarator.init.properties = [
|
|
29
|
+
...spreadInits.reduce((acc, init) => {
|
|
30
|
+
acc = [...acc, ...init.properties];
|
|
31
|
+
return acc;
|
|
32
|
+
}, []),
|
|
33
|
+
...declarator.init.properties,
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
return declarator.init;
|
|
37
|
+
/**export const props = () => ({}) */
|
|
38
|
+
}
|
|
39
|
+
else if (isArrowFunctionExpression(declarator.init) && isObjectExpression(declarator.init.body)) {
|
|
40
|
+
const spreadElements = declarator.init.body.properties.filter(p => isSpreadElement(p));
|
|
41
|
+
const spreadInits = resolveSpreadElements(spreadElements, statements);
|
|
42
|
+
if (spreadInits.length) {
|
|
43
|
+
declarator.init.body.properties = [
|
|
44
|
+
...spreadInits.reduce((acc, init) => {
|
|
45
|
+
acc = [...acc, ...init.properties];
|
|
46
|
+
return acc;
|
|
47
|
+
}, []),
|
|
48
|
+
...declarator.init.body.properties,
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
return declarator.init.body;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** export default defineComponent({}) */
|
|
55
|
+
}
|
|
56
|
+
else if (isCallExpression(exportDeclaration.declaration)) {
|
|
57
|
+
const args = getCallExpressionArguments(exportDeclaration.declaration);
|
|
58
|
+
const options = args[0];
|
|
59
|
+
return isObjectExpression(options)
|
|
60
|
+
? options
|
|
61
|
+
: undefined;
|
|
62
|
+
/** export default {} */
|
|
63
|
+
}
|
|
64
|
+
else if (isObjectExpression(exportDeclaration.declaration)) {
|
|
65
|
+
return exportDeclaration.declaration;
|
|
66
|
+
/**
|
|
67
|
+
* const Comp = {} or const Comp = defineComponent({})
|
|
68
|
+
* export default Comp
|
|
69
|
+
**/
|
|
70
|
+
}
|
|
71
|
+
else if (isIdentifier(exportDeclaration.declaration)) {
|
|
72
|
+
const { name } = exportDeclaration.declaration;
|
|
73
|
+
const variableDeclaration = statements.find(s => isVariableDeclaration(s));
|
|
74
|
+
if (!variableDeclaration)
|
|
75
|
+
return;
|
|
76
|
+
const variableDeclarator = variableDeclaration.declarations.find(d => {
|
|
77
|
+
return isIdentifier(d.id) && d.id.name === name;
|
|
78
|
+
});
|
|
79
|
+
if (!variableDeclarator)
|
|
80
|
+
return;
|
|
81
|
+
if (isObjectExpression(variableDeclarator.init)) {
|
|
82
|
+
return variableDeclarator.init;
|
|
83
|
+
}
|
|
84
|
+
else if (isCallExpression(variableDeclarator.init)) {
|
|
85
|
+
const args = getCallExpressionArguments(variableDeclarator.init);
|
|
86
|
+
const options = args[0];
|
|
87
|
+
return isObjectExpression(options)
|
|
88
|
+
? options
|
|
89
|
+
: undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { extname } from 'node:path';
|
|
4
|
-
import { legalExtsReg, vueExtReg } from '../constants.mjs';
|
|
5
|
-
import { parseSfc } from './parseSfc.mjs';
|
|
6
|
-
import { parseCode } from './parseCode.mjs';
|
|
7
|
-
export async function parseFile(filePath, options) {
|
|
8
|
-
if (!legalExtsReg.test(filePath)) {
|
|
9
|
-
return Promise.reject(new Error(`[parseFile] Unexcept file extension: ${extname(filePath)}`));
|
|
10
|
-
}
|
|
11
|
-
const source = await readFile(filePath, 'utf8');
|
|
12
|
-
if (vueExtReg.test(filePath)) {
|
|
13
|
-
const script = parseSfc(source);
|
|
14
|
-
if (script) {
|
|
15
|
-
return parseCode(script.content, {
|
|
16
|
-
...options,
|
|
17
|
-
setup: script.setup,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return parseCode(source, options);
|
|
22
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { extname } from 'node:path';
|
|
4
|
+
import { legalExtsReg, vueExtReg } from '../constants.mjs';
|
|
5
|
+
import { parseSfc } from './parseSfc.mjs';
|
|
6
|
+
import { parseCode } from './parseCode.mjs';
|
|
7
|
+
export async function parseFile(filePath, options) {
|
|
8
|
+
if (!legalExtsReg.test(filePath)) {
|
|
9
|
+
return Promise.reject(new Error(`[parseFile] Unexcept file extension: ${extname(filePath)}`));
|
|
10
|
+
}
|
|
11
|
+
const source = await readFile(filePath, 'utf8');
|
|
12
|
+
if (vueExtReg.test(filePath)) {
|
|
13
|
+
const script = parseSfc(source);
|
|
14
|
+
if (script) {
|
|
15
|
+
return parseCode(script.content, {
|
|
16
|
+
...options,
|
|
17
|
+
setup: script.setup,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return parseCode(source, options);
|
|
22
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { extname } from 'node:path';
|
|
4
|
-
import { legalExtsReg, vueExtReg } from '../constants.mjs';
|
|
5
|
-
import { parseSfc } from './parseSfc.mjs';
|
|
6
|
-
import { parseCode } from './parseCode.mjs';
|
|
7
|
-
export function parseFileSync(filePath, options) {
|
|
8
|
-
if (!legalExtsReg.test(filePath)) {
|
|
9
|
-
throw new Error(`[parseFileSync] Unexcept file extension: ${extname(filePath)}`);
|
|
10
|
-
}
|
|
11
|
-
const source = readFileSync(filePath, 'utf8');
|
|
12
|
-
if (vueExtReg.test(filePath)) {
|
|
13
|
-
const script = parseSfc(source);
|
|
14
|
-
if (script) {
|
|
15
|
-
return parseCode(script.content, {
|
|
16
|
-
...options,
|
|
17
|
-
setup: script.setup,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return parseCode(source, options);
|
|
22
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { extname } from 'node:path';
|
|
4
|
+
import { legalExtsReg, vueExtReg } from '../constants.mjs';
|
|
5
|
+
import { parseSfc } from './parseSfc.mjs';
|
|
6
|
+
import { parseCode } from './parseCode.mjs';
|
|
7
|
+
export function parseFileSync(filePath, options) {
|
|
8
|
+
if (!legalExtsReg.test(filePath)) {
|
|
9
|
+
throw new Error(`[parseFileSync] Unexcept file extension: ${extname(filePath)}`);
|
|
10
|
+
}
|
|
11
|
+
const source = readFileSync(filePath, 'utf8');
|
|
12
|
+
if (vueExtReg.test(filePath)) {
|
|
13
|
+
const script = parseSfc(source);
|
|
14
|
+
if (script) {
|
|
15
|
+
return parseCode(script.content, {
|
|
16
|
+
...options,
|
|
17
|
+
setup: script.setup,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return parseCode(source, options);
|
|
22
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { isArrayExpression, isIdentifier, isTSAsExpression, isTSTypeReference, } from '@babel/types';
|
|
3
|
-
import generator from '@babel/generator';
|
|
4
|
-
// Babel 7 is CommonJS: its default export is nested when loaded from native ESM.
|
|
5
|
-
const generate = generator.default;
|
|
6
|
-
export function parsePropType(node) {
|
|
7
|
-
if (isArrayExpression(node.value)) {
|
|
8
|
-
return node.value.elements.reduce((acc, el) => {
|
|
9
|
-
if (el?.type === 'Identifier') {
|
|
10
|
-
acc.push(el.name.toLowerCase());
|
|
11
|
-
}
|
|
12
|
-
return acc;
|
|
13
|
-
}, []).join(' | ');
|
|
14
|
-
}
|
|
15
|
-
if (isIdentifier(node.value)) {
|
|
16
|
-
return node.value.name.toLowerCase();
|
|
17
|
-
}
|
|
18
|
-
if (isTSAsExpression(node.value)) {
|
|
19
|
-
if (isTSTypeReference(node.value.typeAnnotation)) {
|
|
20
|
-
if (node.value.typeAnnotation.typeParameters) {
|
|
21
|
-
const typeParam = node.value.typeAnnotation.typeParameters.params[0];
|
|
22
|
-
if (typeParam) {
|
|
23
|
-
try {
|
|
24
|
-
const { code } = generate(typeParam);
|
|
25
|
-
return code;
|
|
26
|
-
}
|
|
27
|
-
catch { }
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { isArrayExpression, isIdentifier, isTSAsExpression, isTSTypeReference, } from '@babel/types';
|
|
3
|
+
import generator from '@babel/generator';
|
|
4
|
+
// Babel 7 is CommonJS: its default export is nested when loaded from native ESM.
|
|
5
|
+
const generate = generator.default;
|
|
6
|
+
export function parsePropType(node) {
|
|
7
|
+
if (isArrayExpression(node.value)) {
|
|
8
|
+
return node.value.elements.reduce((acc, el) => {
|
|
9
|
+
if (el?.type === 'Identifier') {
|
|
10
|
+
acc.push(el.name.toLowerCase());
|
|
11
|
+
}
|
|
12
|
+
return acc;
|
|
13
|
+
}, []).join(' | ');
|
|
14
|
+
}
|
|
15
|
+
if (isIdentifier(node.value)) {
|
|
16
|
+
return node.value.name.toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
if (isTSAsExpression(node.value)) {
|
|
19
|
+
if (isTSTypeReference(node.value.typeAnnotation)) {
|
|
20
|
+
if (node.value.typeAnnotation.typeParameters) {
|
|
21
|
+
const typeParam = node.value.typeAnnotation.typeParameters.params[0];
|
|
22
|
+
if (typeParam) {
|
|
23
|
+
try {
|
|
24
|
+
const { code } = generate(typeParam);
|
|
25
|
+
return code;
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|