@proteus-vue/compiler 0.3.0-beta.8 → 0.3.0-beta.9
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.js +81 -2
- package/dist/script.d.ts +11 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -19592,6 +19592,44 @@ function isReactiveRuntimeInit(init) {
|
|
|
19592
19592
|
return m ? REACTIVE_SRC_TYPE[init.match(/^(reactive|readonly|shallowReactive|shallowReadonly)/)?.[1] ?? ""] ?? "reactive" : null;
|
|
19593
19593
|
}
|
|
19594
19594
|
var REACTIVITY_RUNTIME_GUARDS = /* @__PURE__ */ new Set(["isReactive", "isReadonly", "isProxy", "isShallow", "toRaw"]);
|
|
19595
|
+
function stripParamTypeAnnotation(paramText) {
|
|
19596
|
+
const parts = [];
|
|
19597
|
+
let depth = 0;
|
|
19598
|
+
let cur = "";
|
|
19599
|
+
for (let i = 0; i < paramText.length; i++) {
|
|
19600
|
+
const c = paramText[i];
|
|
19601
|
+
if (c === "{" || c === "[" || c === "(" || c === "<") depth++;
|
|
19602
|
+
else if (c === "}" || c === "]" || c === ")" || c === ">") depth--;
|
|
19603
|
+
if (c === "," && depth === 0) {
|
|
19604
|
+
parts.push(cur);
|
|
19605
|
+
cur = "";
|
|
19606
|
+
continue;
|
|
19607
|
+
}
|
|
19608
|
+
cur += c;
|
|
19609
|
+
}
|
|
19610
|
+
if (cur.trim()) parts.push(cur);
|
|
19611
|
+
const cleaned = parts.map((p) => {
|
|
19612
|
+
const s = p.trim();
|
|
19613
|
+
if (!s) return "";
|
|
19614
|
+
const m = /^([A-Za-z_$][\w$]*)(\?)?\s*:/.exec(s);
|
|
19615
|
+
if (!m) return s;
|
|
19616
|
+
const name = m[1];
|
|
19617
|
+
let rest = s.slice(m[0].length);
|
|
19618
|
+
let depth2 = 0;
|
|
19619
|
+
let eq = -1;
|
|
19620
|
+
for (let i = 0; i < rest.length; i++) {
|
|
19621
|
+
const c = rest[i];
|
|
19622
|
+
if (c === "{" || c === "[" || c === "(" || c === "<") depth2++;
|
|
19623
|
+
else if (c === "}" || c === "]" || c === ")" || c === ">") depth2--;
|
|
19624
|
+
else if (c === "=" && depth2 === 0 && rest[i + 1] !== "=" && rest[i - 1] !== "=" && rest[i - 1] !== "!" && rest[i - 1] !== "<" && rest[i - 1] !== ">") {
|
|
19625
|
+
eq = i;
|
|
19626
|
+
break;
|
|
19627
|
+
}
|
|
19628
|
+
}
|
|
19629
|
+
return eq >= 0 ? `${name} = ${rest.slice(eq + 1).trim()}` : name;
|
|
19630
|
+
}).filter(Boolean);
|
|
19631
|
+
return cleaned.join(", ");
|
|
19632
|
+
}
|
|
19595
19633
|
function topLevelAst(source) {
|
|
19596
19634
|
if (astCacheSrc === source) return astCacheBody;
|
|
19597
19635
|
astCacheSrc = source;
|
|
@@ -20310,8 +20348,8 @@ function extractComputedFromInit(name, init, data, warnings, computedNames, prop
|
|
|
20310
20348
|
const getM = body.match(/\bget\s*:\s*\(\)\s*=>\s*([\s\S]*?)(?=,\s*\bset\s*:|$)/);
|
|
20311
20349
|
rawExpr = getM?.[1]?.trim();
|
|
20312
20350
|
if (!rawExpr || rawExpr.startsWith("{")) return null;
|
|
20313
|
-
const setM = body.match(/\bset\s*:\s*\(([^)]*)\)\s*=>\s*\{([\s\S]*?)\}/);
|
|
20314
|
-
if (setM) setter = { param: setM[1].trim(), body: setM[2] };
|
|
20351
|
+
const setM = body.match(/\bset\s*:\s*\(([^)]*)\)\s*=>\s*\{([\s\S]*?)\}/) ?? body.match(/\bset\s*:\s*function\s*(?:[A-Za-z_$][\w$]*)?\s*\(([^)]*)\)\s*\{([\s\S]*?)\}/) ?? body.match(/\bset\s*\(([^)]*)\)\s*\{([\s\S]*?)\}/);
|
|
20352
|
+
if (setM) setter = { param: stripParamTypeAnnotation(setM[1].trim()), body: setM[2] };
|
|
20315
20353
|
}
|
|
20316
20354
|
const refValueRe = /(?<!\w)([A-Za-z_$][\w$]*)\.value\b/g;
|
|
20317
20355
|
const isPropRef = (id) => propsVar !== void 0 && id === propsVar;
|
|
@@ -20799,6 +20837,47 @@ function rewriteInstanceRefsSafe(call, names, prefix = "this.") {
|
|
|
20799
20837
|
prevIdent = null;
|
|
20800
20838
|
continue;
|
|
20801
20839
|
}
|
|
20840
|
+
if (ch === "/" && call[i + 1] === "*") {
|
|
20841
|
+
const end = call.indexOf("*/", i + 2);
|
|
20842
|
+
const j = end < 0 ? len : end + 2;
|
|
20843
|
+
out += call.slice(i, j);
|
|
20844
|
+
i = j;
|
|
20845
|
+
prevSig = "/";
|
|
20846
|
+
prevIdent = null;
|
|
20847
|
+
continue;
|
|
20848
|
+
}
|
|
20849
|
+
if (ch === "/") {
|
|
20850
|
+
const isDivision = prevSig !== "" && /[\w$)\]}'"`]/.test(prevSig) && !/^(?:return|typeof|instanceof|in|of|new|delete|void|case|do|else)$/.test(prevIdent ?? "");
|
|
20851
|
+
if (!isDivision) {
|
|
20852
|
+
let j = i + 1;
|
|
20853
|
+
let inClass = false;
|
|
20854
|
+
let closed = false;
|
|
20855
|
+
while (j < len) {
|
|
20856
|
+
const c = call[j];
|
|
20857
|
+
if (c === "\\") {
|
|
20858
|
+
j += 2;
|
|
20859
|
+
continue;
|
|
20860
|
+
}
|
|
20861
|
+
if (c === "\n") break;
|
|
20862
|
+
if (c === "[") inClass = true;
|
|
20863
|
+
else if (c === "]") inClass = false;
|
|
20864
|
+
else if (c === "/" && !inClass) {
|
|
20865
|
+
closed = true;
|
|
20866
|
+
j++;
|
|
20867
|
+
break;
|
|
20868
|
+
}
|
|
20869
|
+
j++;
|
|
20870
|
+
}
|
|
20871
|
+
if (closed) {
|
|
20872
|
+
while (j < len && /[a-z]/i.test(call[j])) j++;
|
|
20873
|
+
out += call.slice(i, j);
|
|
20874
|
+
i = j;
|
|
20875
|
+
prevSig = "/";
|
|
20876
|
+
prevIdent = null;
|
|
20877
|
+
continue;
|
|
20878
|
+
}
|
|
20879
|
+
}
|
|
20880
|
+
}
|
|
20802
20881
|
if (ch === "{" || ch === "[" || ch === "(") {
|
|
20803
20882
|
let obj = true;
|
|
20804
20883
|
if (ch === "{") {
|
package/dist/script.d.ts
CHANGED
|
@@ -6,6 +6,17 @@ export declare const REACTIVE_SRC_TYPE: Record<string, string>;
|
|
|
6
6
|
export declare function isReactiveRuntimeInit(init: string): string | null;
|
|
7
7
|
/** 运行时守卫(读 ReactiveFlags 标记位,需 reactive 族真 Proxy 才有语义)——走 runtime-init 但在「函数调用初始化」警告里改准确地说明 */
|
|
8
8
|
export declare const REACTIVITY_RUNTIME_GUARDS: Set<string>;
|
|
9
|
+
/**
|
|
10
|
+
* ★2026-09-20(外部实战报告第十三节 Bug A):剥离**参数位**的 TS 类型注解,只留参数名。
|
|
11
|
+
*
|
|
12
|
+
* 产物是 JS——签名里带注解即语法错误(`proteusSetC(v: string) {` → `Unexpected token ':'`)。
|
|
13
|
+
* 这里处理的是正则捕获出来的**片段文本**(非完整可解析源码),故按参数位的有限语法形态剥离:
|
|
14
|
+
* `v: string` → `v` `v?: T` → `v` `v = 1` → `v = 1`(默认值属 JS 语法,保留)
|
|
15
|
+
* `v: T = 1` → `v = 1` `v: { a: number }` → `v`(对象/联合/泛型里的 `:` 由深度跟踪跳过)
|
|
16
|
+
* 带 `?`(可选参数)时同时去掉 `?`——JS 无该语法。
|
|
17
|
+
* 逗号分隔的多参数逐个处理(`(a: string, b: number)`)。
|
|
18
|
+
*/
|
|
19
|
+
export declare function stripParamTypeAnnotation(paramText: string): string;
|
|
9
20
|
/** 方法参数 AST → 产物参数文本(类型注解天然剔除;保留 ? 可选 / 默认值 / 展开;解构参数剥类型注解切片) */
|
|
10
21
|
export declare function astParamText(source: string, p: any): string;
|
|
11
22
|
/** ★2026-09-08 修复:runtime-init call 内裸 runtimeInit 名 → this.<name> 的**安全**改写。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteus-vue/compiler",
|
|
3
|
-
"version": "0.3.0-beta.
|
|
3
|
+
"version": "0.3.0-beta.9",
|
|
4
4
|
"description": "Proteus 编译引擎 —— 标准 Vue SFC → 小程序四件套(纯函数、零运行时依赖、规则注册表 + AI 说明书)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"@babel/plugin-transform-numeric-separator": "^8.0.1",
|
|
41
41
|
"@babel/plugin-transform-object-rest-spread": "^7.29.0",
|
|
42
42
|
"@babel/plugin-transform-optional-chaining": "^7.29.0",
|
|
43
|
-
"@proteus-vue/component-ir": "0.3.0-beta.
|
|
44
|
-
"@proteus-vue/contracts": "0.3.0-beta.
|
|
45
|
-
"@proteus-vue/types": "0.3.0-beta.
|
|
43
|
+
"@proteus-vue/component-ir": "0.3.0-beta.9",
|
|
44
|
+
"@proteus-vue/contracts": "0.3.0-beta.9",
|
|
45
|
+
"@proteus-vue/types": "0.3.0-beta.9"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsc -p tsconfig.build.json --emitDeclarationOnly && esbuild src/index.ts src/style-safety/index.ts --bundle --format=esm --platform=node --outdir=dist --external:@vue/compiler-sfc --external:@vue/compiler-dom --external:@proteus-vue/contracts --external:@proteus-vue/component-ir --external:@babel/core --external:@babel/plugin-transform-nullish-coalescing-operator --external:@babel/plugin-transform-optional-chaining --external:@babel/plugin-transform-logical-assignment-operators --external:@babel/plugin-transform-object-rest-spread"
|