@melt-js/libs-core 2026.11.15 → 2026.11.16-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 +45 -4
- package/dist/browser.d.mts +3 -0
- package/dist/browser.mjs +1 -50
- package/dist/browser.mjs.gz +0 -0
- package/dist/cdn/browser.umd.cjs +2 -0
- package/dist/cdn/browser.umd.cjs.gz +0 -0
- package/dist/cdn/demo-browser.umd.cjs +2 -0
- package/dist/cdn/demo-browser.umd.cjs.gz +0 -0
- package/dist/cdn/demo.umd.cjs +2 -0
- package/dist/cdn/demo.umd.cjs.gz +0 -0
- package/dist/cdn/example-esm.html +1 -0
- package/dist/cdn/example-umd.html +1 -0
- package/dist/cdn/index.umd.cjs +2 -0
- package/dist/cdn/index.umd.cjs.gz +0 -0
- package/dist/cdn/manifest.json +129 -0
- package/dist/cdn/vendor.umd.cjs +50 -0
- package/dist/cdn/vendor.umd.cjs.gz +0 -0
- package/dist/cdn.d.mts +3 -0
- package/dist/cdn.mjs +1 -0
- package/dist/demo/browser.mjs +1 -0
- package/dist/demo/browser.mjs.gz +0 -0
- package/dist/demo/clipboard.d.mts +6 -0
- package/dist/demo/clipboard.mjs +1 -0
- package/{src → dist}/demo/docs.d.mts +28 -25
- package/dist/demo/docs.mjs +1 -0
- package/dist/demo/docs.mjs.gz +0 -0
- package/{src → dist}/demo/download.d.mts +7 -2
- package/dist/demo/download.mjs +1 -0
- package/dist/demo/download.mjs.gz +0 -0
- package/{src → dist}/demo/fullscreen.d.mts +8 -8
- package/dist/demo/fullscreen.mjs +1 -0
- package/dist/demo/index.d.mts +9 -0
- package/dist/demo/index.mjs +1 -0
- package/{src → dist}/demo/model.d.mts +12 -12
- package/dist/demo/model.mjs +1 -0
- package/dist/demo/remote-debug.d.mts +11 -0
- package/dist/demo/remote-debug.mjs +1 -0
- package/{src → dist}/demo/runtime.mjs +92 -104
- package/dist/demo/split-pane.d.mts +8 -0
- package/dist/demo/split-pane.mjs +1 -0
- package/dist/demo/standalone.d.mts +9 -0
- package/dist/demo/standalone.mjs +1 -0
- package/dist/demo/tabs.d.mts +15 -0
- package/dist/demo/tabs.mjs +1 -0
- package/{src/index.ts → dist/index.d.ts} +1 -1
- package/dist/loading.mjs +1 -0
- package/dist/remote-address.cjs +2 -0
- package/{src → dist}/remote.d.mts +110 -96
- package/dist/remote.mjs +1 -0
- package/dist/remote.mjs.gz +0 -0
- package/dist/vendor/hel-runtime.mjs +50 -0
- package/dist/vendor/hel-runtime.mjs.gz +0 -0
- package/package.json +41 -25
- package/scripts/browser-formats.mjs +355 -0
- package/scripts/build-browser.mjs +59 -13
- package/scripts/build-protected-esm.mjs +51 -0
- package/scripts/cdn-runtime.cjs +30 -0
- package/scripts/check-tdz.mjs +327 -324
- package/scripts/client-build-security.cjs +48 -0
- package/scripts/component-events.mjs +57 -57
- package/scripts/comps-bundle-obfuscation.cjs +266 -262
- package/scripts/hel-build-paths.cjs +49 -48
- package/scripts/package-artifacts.mjs +206 -0
- package/scripts/package-env.cjs +200 -193
- package/scripts/publish-stage.mjs +50 -42
- package/{src → 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 +123 -121
- package/demo/index.js +0 -1
- package/dist/hel-deployment.json +0 -8
- package/src/browser.d.mts +0 -2
- package/src/browser.mjs +0 -3
- package/src/demo/docs.mjs +0 -75
- package/src/demo/download.mjs +0 -118
- package/src/demo/fullscreen.mjs +0 -80
- package/src/demo/index.d.mts +0 -4
- package/src/demo/index.mjs +0 -4
- package/src/demo/model.mjs +0 -203
- package/src/remote.mjs +0 -286
- package/tsconfig.json +0 -13
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
/** Options and output shapes retained from vdoc-parser 1.2.0 (ISC). */
|
|
3
|
-
export interface Options {
|
|
4
|
-
exportType?: 'named' | 'default';
|
|
5
|
-
exportName?: string;
|
|
6
|
-
type?: 'component' | 'props';
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface InternalOptions extends Options {
|
|
10
|
-
setup?: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface BuiltinResult {
|
|
14
|
-
name: string;
|
|
15
|
-
type: string;
|
|
16
|
-
description: string;
|
|
17
|
-
default: string;
|
|
18
|
-
version: string;
|
|
19
|
-
required: 'true' | 'false';
|
|
20
|
-
isEvent: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type ParsedResult<T extends Record<string, string> = {}> = BuiltinResult & T;
|
|
24
|
-
|
|
25
|
-
export interface ParseTypesOptions {
|
|
26
|
-
names?: string[];
|
|
27
|
-
excludeNames?: string[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function parseCode(code: string, options?: InternalOptions): ParsedResult[];
|
|
31
|
-
export function parseFile(filePath: string, options?: Options): Promise<ParsedResult[]>;
|
|
32
|
-
export function parseFileSync(filePath: string, options?: Options): ParsedResult[];
|
|
33
|
-
export function parseTypes(code: string, options?: ParseTypesOptions): string | undefined;
|
|
34
|
-
export function parseTypesFile(filePath: string, options?: ParseTypesOptions): Promise<string | undefined>;
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
/** Options and output shapes retained from vdoc-parser 1.2.0 (ISC). */
|
|
3
|
+
export interface Options {
|
|
4
|
+
exportType?: 'named' | 'default';
|
|
5
|
+
exportName?: string;
|
|
6
|
+
type?: 'component' | 'props';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface InternalOptions extends Options {
|
|
10
|
+
setup?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface BuiltinResult {
|
|
14
|
+
name: string;
|
|
15
|
+
type: string;
|
|
16
|
+
description: string;
|
|
17
|
+
default: string;
|
|
18
|
+
version: string;
|
|
19
|
+
required: 'true' | 'false';
|
|
20
|
+
isEvent: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ParsedResult<T extends Record<string, string> = {}> = BuiltinResult & T;
|
|
24
|
+
|
|
25
|
+
export interface ParseTypesOptions {
|
|
26
|
+
names?: string[];
|
|
27
|
+
excludeNames?: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function parseCode(code: string, options?: InternalOptions): ParsedResult[];
|
|
31
|
+
export function parseFile(filePath: string, options?: Options): Promise<ParsedResult[]>;
|
|
32
|
+
export function parseFileSync(filePath: string, options?: Options): ParsedResult[];
|
|
33
|
+
export function parseTypes(code: string, options?: ParseTypesOptions): string | undefined;
|
|
34
|
+
export function parseTypesFile(filePath: string, options?: ParseTypesOptions): Promise<string | undefined>;
|
|
35
35
|
export function parseTypesFileSync(filePath: string, options?: ParseTypesOptions): string | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
export { parseCode, parseFile, parseFileSync, parseTypes, parseTypesFileSync, parseTypesFile, } from './parsers/index.mjs';
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
export { parseCode, parseFile, parseFileSync, parseTypes, parseTypesFileSync, parseTypesFile, } from './parsers/index.mjs';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
export { parseCommentBlock } from './parseCommentBlock.mjs';
|
|
3
|
-
export { parseComponentOptions } from './parseComponentOptions.mjs';
|
|
4
|
-
export { parsePropType } from './parsePropType.mjs';
|
|
5
|
-
export { parseExport } from './parseExport.mjs';
|
|
6
|
-
export { parseSfc } from './parseSfc.mjs';
|
|
7
|
-
export { parseSetupScript } from './parseSetupScript.mjs';
|
|
8
|
-
export { parseProps } from './parseProps.mjs';
|
|
9
|
-
export { parseCode } from './parseCode.mjs';
|
|
10
|
-
export { parseFile } from './parseFile.mjs';
|
|
11
|
-
export { parseFileSync } from './parseFileSync.mjs';
|
|
12
|
-
export { parseTypes } from './parseTypes.mjs';
|
|
13
|
-
export { parseTypesFileSync } from './parseTypesFileSync.mjs';
|
|
14
|
-
export { parseTypesFile } from './parseTypesFile.mjs';
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
export { parseCommentBlock } from './parseCommentBlock.mjs';
|
|
3
|
+
export { parseComponentOptions } from './parseComponentOptions.mjs';
|
|
4
|
+
export { parsePropType } from './parsePropType.mjs';
|
|
5
|
+
export { parseExport } from './parseExport.mjs';
|
|
6
|
+
export { parseSfc } from './parseSfc.mjs';
|
|
7
|
+
export { parseSetupScript } from './parseSetupScript.mjs';
|
|
8
|
+
export { parseProps } from './parseProps.mjs';
|
|
9
|
+
export { parseCode } from './parseCode.mjs';
|
|
10
|
+
export { parseFile } from './parseFile.mjs';
|
|
11
|
+
export { parseFileSync } from './parseFileSync.mjs';
|
|
12
|
+
export { parseTypes } from './parseTypes.mjs';
|
|
13
|
+
export { parseTypesFileSync } from './parseTypesFileSync.mjs';
|
|
14
|
+
export { parseTypesFile } from './parseTypesFile.mjs';
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { parse as babelParse } from '@babel/parser';
|
|
3
|
-
import { parseExport } from './parseExport.mjs';
|
|
4
|
-
import { parseComponentOptions } from './parseComponentOptions.mjs';
|
|
5
|
-
import { parseSetupScript } from './parseSetupScript.mjs';
|
|
6
|
-
import { parseProps } from './parseProps.mjs';
|
|
7
|
-
export function parseCode(code, { exportType = 'default', exportName, type = 'component', setup = false, } = {
|
|
8
|
-
exportType: 'default',
|
|
9
|
-
type: 'component',
|
|
10
|
-
setup: false,
|
|
11
|
-
}) {
|
|
12
|
-
const res = babelParse(code, {
|
|
13
|
-
sourceType: 'module',
|
|
14
|
-
plugins: [
|
|
15
|
-
'typescript',
|
|
16
|
-
'jsx',
|
|
17
|
-
]
|
|
18
|
-
});
|
|
19
|
-
let propInfo;
|
|
20
|
-
if (setup) {
|
|
21
|
-
propInfo = parseSetupScript(res.program.body);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
if (type === 'props') {
|
|
25
|
-
const props = parseExport(res.program.body, exportType, type, exportName);
|
|
26
|
-
if (props) {
|
|
27
|
-
propInfo = parseProps(props);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else if (type === 'component') {
|
|
31
|
-
// 这里遵循一个文件只写一个组件的原则,不支持通过 exportName 查找导出的组件
|
|
32
|
-
const options = parseExport(res.program.body, exportType, type);
|
|
33
|
-
propInfo = options
|
|
34
|
-
? parseComponentOptions(options)
|
|
35
|
-
: undefined;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
throw new Error('Unknow parseType:' + type);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return propInfo || [];
|
|
42
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { parse as babelParse } from '@babel/parser';
|
|
3
|
+
import { parseExport } from './parseExport.mjs';
|
|
4
|
+
import { parseComponentOptions } from './parseComponentOptions.mjs';
|
|
5
|
+
import { parseSetupScript } from './parseSetupScript.mjs';
|
|
6
|
+
import { parseProps } from './parseProps.mjs';
|
|
7
|
+
export function parseCode(code, { exportType = 'default', exportName, type = 'component', setup = false, } = {
|
|
8
|
+
exportType: 'default',
|
|
9
|
+
type: 'component',
|
|
10
|
+
setup: false,
|
|
11
|
+
}) {
|
|
12
|
+
const res = babelParse(code, {
|
|
13
|
+
sourceType: 'module',
|
|
14
|
+
plugins: [
|
|
15
|
+
'typescript',
|
|
16
|
+
'jsx',
|
|
17
|
+
]
|
|
18
|
+
});
|
|
19
|
+
let propInfo;
|
|
20
|
+
if (setup) {
|
|
21
|
+
propInfo = parseSetupScript(res.program.body);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (type === 'props') {
|
|
25
|
+
const props = parseExport(res.program.body, exportType, type, exportName);
|
|
26
|
+
if (props) {
|
|
27
|
+
propInfo = parseProps(props);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (type === 'component') {
|
|
31
|
+
// 这里遵循一个文件只写一个组件的原则,不支持通过 exportName 查找导出的组件
|
|
32
|
+
const options = parseExport(res.program.body, exportType, type);
|
|
33
|
+
propInfo = options
|
|
34
|
+
? parseComponentOptions(options)
|
|
35
|
+
: undefined;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error('Unknow parseType:' + type);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return propInfo || [];
|
|
42
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import doctrine from 'doctrine';
|
|
3
|
-
export function parseCommentBlock(comment) {
|
|
4
|
-
const { tags } = doctrine.parse(`/*${comment.value}*/`, { unwrap: true });
|
|
5
|
-
return tags.reduce((acc, tag) => {
|
|
6
|
-
acc[tag.title] = tag.description || '';
|
|
7
|
-
return acc;
|
|
8
|
-
}, {});
|
|
9
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import doctrine from 'doctrine';
|
|
3
|
+
export function parseCommentBlock(comment) {
|
|
4
|
+
const { tags } = doctrine.parse(`/*${comment.value}*/`, { unwrap: true });
|
|
5
|
+
return tags.reduce((acc, tag) => {
|
|
6
|
+
acc[tag.title] = tag.description || '';
|
|
7
|
+
return acc;
|
|
8
|
+
}, {});
|
|
9
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
-
import { isObjectExpression, } from '@babel/types';
|
|
3
|
-
import { getPropertyByExpression } from '../utils.mjs';
|
|
4
|
-
import { parseProps } from './parseProps.mjs';
|
|
5
|
-
export function parseComponentOptions(options) {
|
|
6
|
-
const props = getPropertyByExpression(options, 'props');
|
|
7
|
-
if (!props)
|
|
8
|
-
return;
|
|
9
|
-
if (isObjectExpression(props.value)) {
|
|
10
|
-
return parseProps(props.value);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
// Derived from vdoc-parser 1.2.0 by kennys wang (ISC); see NOTICE.md.
|
|
2
|
+
import { isObjectExpression, } from '@babel/types';
|
|
3
|
+
import { getPropertyByExpression } from '../utils.mjs';
|
|
4
|
+
import { parseProps } from './parseProps.mjs';
|
|
5
|
+
export function parseComponentOptions(options) {
|
|
6
|
+
const props = getPropertyByExpression(options, 'props');
|
|
7
|
+
if (!props)
|
|
8
|
+
return;
|
|
9
|
+
if (isObjectExpression(props.value)) {
|
|
10
|
+
return parseProps(props.value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -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
|
+
}
|