@vtj/parser 0.17.7 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +29 -18
- package/dist/index.mjs +2021 -1168
- package/package.json +8 -6
- package/types/shared/utils.d.ts +6 -0
- package/types/version.d.ts +2 -2
- package/types/vue/composition/index.d.ts +3 -0
- package/types/vue/composition/reverseGlobalApi.d.ts +30 -0
- package/types/vue/composition/reverseSymbolTable.d.ts +35 -0
- package/types/vue/composition/reverseTransformer.d.ts +2 -0
- package/types/vue/compositionPatch.d.ts +46 -0
- package/types/vue/scriptSetup.d.ts +31 -0
- package/types/vue/utils.d.ts +0 -20
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/parser",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.18.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
|
+
"AI低代码",
|
|
8
|
+
"AI编程",
|
|
7
9
|
"低代码引擎",
|
|
8
10
|
"LowCode Engine",
|
|
9
11
|
"Vue3低代码",
|
|
@@ -12,7 +14,7 @@
|
|
|
12
14
|
"代码生成器",
|
|
13
15
|
"代码可视化"
|
|
14
16
|
],
|
|
15
|
-
"description": "VTJ
|
|
17
|
+
"description": "VTJ.PRO 是一个开源的、AI 驱动的 Vue3 企业级应用开发平台,通过 AI 智能体与可视化编排实现高效开发,并支持导出标准 Vue 代码以避免平台锁定。",
|
|
16
18
|
"repository": {
|
|
17
19
|
"type": "git",
|
|
18
20
|
"url": "https://gitee.com/newgateway/vtj.git"
|
|
@@ -30,12 +32,12 @@
|
|
|
30
32
|
"htmlparser2": "~10.0.0",
|
|
31
33
|
"postcss": "~8.5.0",
|
|
32
34
|
"sass": "~1.97.1",
|
|
33
|
-
"@vtj/base": "~0.
|
|
34
|
-
"@vtj/coder": "~0.
|
|
35
|
-
"@vtj/core": "~0.
|
|
35
|
+
"@vtj/base": "~0.13.0",
|
|
36
|
+
"@vtj/coder": "~0.18.0",
|
|
37
|
+
"@vtj/core": "~0.18.0"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
|
-
"@vtj/cli": "~0.
|
|
40
|
+
"@vtj/cli": "~0.13.0"
|
|
39
41
|
},
|
|
40
42
|
"exports": {
|
|
41
43
|
".": {
|
package/types/shared/utils.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare function parseSFC(source: string): {
|
|
|
8
8
|
script: string;
|
|
9
9
|
styles: string[];
|
|
10
10
|
errors: ( CompilerError | SyntaxError)[];
|
|
11
|
+
isScriptSetup: boolean;
|
|
11
12
|
};
|
|
12
13
|
export declare function parseScript(script: string): ParseResult<File>;
|
|
13
14
|
export declare function traverseAST(ast: ReturnType<typeof parseScript>, options: TraverseOptions): any;
|
|
@@ -17,4 +18,9 @@ export declare function isJSFunction(x: any): x is JSFunction;
|
|
|
17
18
|
export declare function isJSCode(data: unknown): data is JSExpression | JSFunction;
|
|
18
19
|
export declare function isNodeSchema(node: NodeSchema | JSExpression | string | null): node is NodeSchema;
|
|
19
20
|
export declare function transformScript(script: string, visitor: Visitor): any;
|
|
21
|
+
/**
|
|
22
|
+
* 将 TypeScript 代码转为 JavaScript(剥离类型标注)
|
|
23
|
+
* 使用 @babel/traverse 执行 AST 变换,后续解析以纯 JS 为基础
|
|
24
|
+
*/
|
|
25
|
+
export declare function stripTypeScript(script: string): string;
|
|
20
26
|
export declare function compileValidator(source: string, filename: string): string[] | null;
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/parser
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.17.
|
|
5
|
+
* @version 0.17.8
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.17.
|
|
8
|
+
export declare const version = "0.17.8";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface ReverseGlobalApiMaps {
|
|
2
|
+
/** 裸标识符映射:{ 变量名: '$xxx' } */
|
|
3
|
+
simple: Record<string, string>;
|
|
4
|
+
/** 成员访问映射:{ 对象名: { 属性名: '$xxx' } } */
|
|
5
|
+
member: Record<string, Record<string, string>>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 从 coder 的全局 API 映射构建反向映射
|
|
9
|
+
*
|
|
10
|
+
* 分为两类:
|
|
11
|
+
* - simple: replace 为裸标识符的,如 router → $router
|
|
12
|
+
* - member: replace 为成员访问的,如 __i18n.t → $t, ElMessageBox.confirm → $confirm
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildReverseGlobalApiMap(uiPackage?: string): ReverseGlobalApiMaps;
|
|
15
|
+
/**
|
|
16
|
+
* 从 import 语句列表探测当前使用的 UI 库包名
|
|
17
|
+
*/
|
|
18
|
+
export declare function detectUIPackage(imports: Array<{
|
|
19
|
+
from: string;
|
|
20
|
+
}>): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* 构建 composable 函数名 → { 解构属性名: DSL API名 } 映射
|
|
23
|
+
*
|
|
24
|
+
* 用于解构形式的全局 API 精确反向映射。
|
|
25
|
+
* 例如:const { t, n } = useI18n() 中,t → '$t',n → '$n'
|
|
26
|
+
*
|
|
27
|
+
* 产出示例:
|
|
28
|
+
* { useI18n: { t: '$t', n: '$n', d: '$d', rt: '$rt', te: '$te', tm: '$tm' } }
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildComposableMemberMap(uiPackage?: string): Record<string, Record<string, string>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ParseScriptSetupResult } from '../scriptSetup';
|
|
2
|
+
/**
|
|
3
|
+
* 反向符号表:描述 <script setup> 中各类标识符的分类
|
|
4
|
+
* 用于将 Composition API 代码反向转换为 DSL 中的 this.xxx 形态
|
|
5
|
+
*
|
|
6
|
+
* 与 @vtj/coder 的 SymbolTable 形成镜像关系。
|
|
7
|
+
*/
|
|
8
|
+
export interface ReverseSymbolTable {
|
|
9
|
+
/** ref 声明集 */
|
|
10
|
+
refs: Set<string>;
|
|
11
|
+
/** reactive 声明集(含 state) */
|
|
12
|
+
reactives: Set<string>;
|
|
13
|
+
/** computed 声明集 */
|
|
14
|
+
computed: Set<string>;
|
|
15
|
+
/** methods 声明集 */
|
|
16
|
+
methods: Set<string>;
|
|
17
|
+
/** props 名集 */
|
|
18
|
+
props: Set<string>;
|
|
19
|
+
/** composables 暴露的名集(包含 destructure) */
|
|
20
|
+
composables: Set<string>;
|
|
21
|
+
/** inject 名集 */
|
|
22
|
+
injects: Set<string>;
|
|
23
|
+
/** dataSources 名集 */
|
|
24
|
+
dataSources: Set<string>;
|
|
25
|
+
/** 是否存在 state reactive */
|
|
26
|
+
hasState: boolean;
|
|
27
|
+
/** 裸标识符全局 API 反向映射:{ 变量名: '$xxx' } */
|
|
28
|
+
reverseApiMap: Record<string, string>;
|
|
29
|
+
/** 成员访问全局 API 反向映射:{ 对象名: { 属性名: '$xxx' } } */
|
|
30
|
+
reverseMemberApiMap: Record<string, Record<string, string>>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 从 ParseScriptSetupResult 构建反向符号表
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildReverseSymbolTable(result: ParseScriptSetupResult): ReverseSymbolTable;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* compositionPatch 选项(向后兼容)
|
|
3
|
+
* 描述当前 <script setup> 中各类标识符的分类
|
|
4
|
+
*/
|
|
5
|
+
export interface CompositionPatchOptions {
|
|
6
|
+
/** ref 变量名列表 */
|
|
7
|
+
refs: string[];
|
|
8
|
+
/** reactive 变量名列表(不含 'state') */
|
|
9
|
+
reactives: string[];
|
|
10
|
+
/** 是否存在 state reactive */
|
|
11
|
+
hasState: boolean;
|
|
12
|
+
/** computed 变量名列表 */
|
|
13
|
+
computed: string[];
|
|
14
|
+
/** method 函数名列表 */
|
|
15
|
+
methods: string[];
|
|
16
|
+
/** props 字段名列表 */
|
|
17
|
+
props: string[];
|
|
18
|
+
/** 用户自定义 composable 赋值变量名(含解构字段) */
|
|
19
|
+
composables: string[];
|
|
20
|
+
/** inject 变量名 */
|
|
21
|
+
injects: string[];
|
|
22
|
+
/** dataSource 函数名 */
|
|
23
|
+
dataSources: string[];
|
|
24
|
+
/**
|
|
25
|
+
* 全局 API 变量名 → this.$xxx 的映射
|
|
26
|
+
* 例如 { router: '$router', route: '$route', t: '$t', store: '$store' }
|
|
27
|
+
*/
|
|
28
|
+
globalApiVars: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* 第三方库标识符映射,例如 { ElButton: 'ElementPlus', useDark: 'VueUse' }
|
|
31
|
+
* 替换为 this.$libs.ElementPlus.ElButton 等
|
|
32
|
+
*/
|
|
33
|
+
libs: Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* 成员访问形式的全局 API 反向映射
|
|
36
|
+
* 例如 { __i18n: { t: '$t', n: '$n' }, ElMessageBox: { confirm: '$confirm' } }
|
|
37
|
+
* 若未提供,将自动从 coder 的 GLOBAL_API_MAP 推导
|
|
38
|
+
*/
|
|
39
|
+
reverseMemberApiMap?: Record<string, Record<string, string>>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Composition 模式反向 this 注入
|
|
43
|
+
*
|
|
44
|
+
* 现在委托给 reverseTransformExpression,保留此函数以维持向后兼容。
|
|
45
|
+
*/
|
|
46
|
+
export declare function compositionPatch(content: string, options: CompositionPatchOptions): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BlockState, JSFunction, JSExpression, JSONValue, BlockWatch, BlockProp, BlockEmit, BlockInject, BlockComposable, DataSourceSchema, ProjectSchema } from '@vtj/core';
|
|
2
|
+
import { ImportStatement } from './scripts';
|
|
3
|
+
export interface GlobalApiDestructured {
|
|
4
|
+
/** composable 函数名(如 useI18n) */
|
|
5
|
+
callee: string;
|
|
6
|
+
/** 解构字段列表(如 ['t', 'n']) */
|
|
7
|
+
destructure: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface ParseScriptSetupResult {
|
|
10
|
+
imports: ImportStatement[];
|
|
11
|
+
refs: Record<string, JSONValue | JSExpression>;
|
|
12
|
+
reactives: Record<string, JSONValue | JSExpression>;
|
|
13
|
+
state: BlockState;
|
|
14
|
+
computed: Record<string, JSFunction>;
|
|
15
|
+
methods: Record<string, JSFunction>;
|
|
16
|
+
watch: BlockWatch[];
|
|
17
|
+
lifeCycles: Record<string, JSFunction>;
|
|
18
|
+
props: Array<string | BlockProp>;
|
|
19
|
+
emits: BlockEmit[];
|
|
20
|
+
expose: string[];
|
|
21
|
+
inject: BlockInject[];
|
|
22
|
+
provide: Record<string, JSONValue | JSExpression | JSFunction>;
|
|
23
|
+
composables: BlockComposable[];
|
|
24
|
+
/** 全局 composable 的解构字段(如 const { t } = useI18n()) */
|
|
25
|
+
globalApiDestructured?: GlobalApiDestructured[];
|
|
26
|
+
setup: JSFunction | undefined;
|
|
27
|
+
handlers: Record<string, JSFunction>;
|
|
28
|
+
dataSources: Record<string, DataSourceSchema>;
|
|
29
|
+
directives: Record<string, JSExpression>;
|
|
30
|
+
}
|
|
31
|
+
export declare function parseScriptSetup(content: string, project: ProjectSchema): ParseScriptSetupResult;
|
package/types/vue/utils.d.ts
CHANGED
|
@@ -9,26 +9,6 @@ export interface ExpressionOptions {
|
|
|
9
9
|
members: string[];
|
|
10
10
|
props: string[];
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* 检查标识符是否在函数参数位置
|
|
14
|
-
* 包括:function(key)、 (key) =>、 key =>、 (a, key, b) => 等
|
|
15
|
-
* 不包括:函数调用参数如 obj.method(key) 中的 key
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* 判断当前位置是否处于 ES6 对象字面量简写属性位置
|
|
19
|
-
* 例如 { key } 或 { a, key } 中的 key
|
|
20
|
-
* 特点:key 前面是 { 或 ,,后面紧跟 , 或 }
|
|
21
|
-
* 如果后面紧跟 : 则为普通属性名,不算简写
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* 简化的字符串替换函数,遵循以下规则:
|
|
25
|
-
* 1. 字符串中的 key 不替换(包括模板字符串普通文本,但 ${key} 中的 key 要替换)
|
|
26
|
-
* 2. 对象属性访问 obj.key 不替换(. 前)
|
|
27
|
-
* 3. 变量声明(const/let/var/function 后)不替换
|
|
28
|
-
* 4. 对象属性名 {key: value} 或 {key} 不替换
|
|
29
|
-
* 5. 前后有单词字符(a-zA-Z0-9_$@-)不替换
|
|
30
|
-
* 6. 其他情况替换:赋值、函数调用、数组元素、模板表达式等
|
|
31
|
-
*/
|
|
32
12
|
export declare function patchCode(content: string, id: string, options: ExpressionOptions): string;
|
|
33
13
|
export declare function getJSExpression(content: string): JSExpression;
|
|
34
14
|
export declare function getJSFunction(content: string): JSFunction;
|