@dimina/compiler 1.0.14-beta.0 → 1.0.14
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/bin/index.cjs +16 -17
- package/dist/bin/index.js +16 -17
- package/dist/compatibility-B_5UilxZ.js +165 -0
- package/dist/compatibility-DCnJNS-s.cjs +183 -0
- package/dist/core/logic-compiler.cjs +166 -82
- package/dist/core/logic-compiler.js +166 -81
- package/dist/core/view-compiler.cjs +200 -122
- package/dist/core/view-compiler.js +199 -118
- package/dist/index.cjs +30 -7
- package/dist/index.js +31 -8
- package/package.json +12 -14
package/dist/bin/index.cjs
CHANGED
|
@@ -10,7 +10,7 @@ chokidar = require_env.__toESM(chokidar, 1);
|
|
|
10
10
|
let commander = require("commander");
|
|
11
11
|
var package_default = {
|
|
12
12
|
name: "@dimina/compiler",
|
|
13
|
-
version: "1.0.14
|
|
13
|
+
version: "1.0.14",
|
|
14
14
|
description: "星河编译工具",
|
|
15
15
|
main: "./dist/index.cjs",
|
|
16
16
|
module: "./dist/index.js",
|
|
@@ -36,10 +36,14 @@ var package_default = {
|
|
|
36
36
|
},
|
|
37
37
|
bin: { "dmcc": "dist/bin/index.js" },
|
|
38
38
|
scripts: {
|
|
39
|
+
"prebuild": "node scripts/sync-compatibility-reference.js",
|
|
39
40
|
"build": "vite build",
|
|
41
|
+
"sync:compat": "node scripts/sync-compatibility-reference.js",
|
|
42
|
+
"pretest": "node scripts/sync-compatibility-reference.js",
|
|
40
43
|
"test": "vitest run",
|
|
41
44
|
"test:dev": "vitest",
|
|
42
45
|
"coverage": "vitest run --coverage",
|
|
46
|
+
"prepack": "npm run build",
|
|
43
47
|
"release:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
|
|
44
48
|
"release": "npm version patch && npm publish"
|
|
45
49
|
},
|
|
@@ -53,29 +57,23 @@ var package_default = {
|
|
|
53
57
|
"星河"
|
|
54
58
|
],
|
|
55
59
|
dependencies: {
|
|
56
|
-
"@
|
|
57
|
-
"
|
|
58
|
-
"@babel/plugin-transform-modules-commonjs": "^7.28.6",
|
|
59
|
-
"@babel/traverse": "^7.29.0",
|
|
60
|
-
"@babel/types": "^7.29.0",
|
|
61
|
-
"@vue/compiler-sfc": "^3.5.32",
|
|
62
|
-
"autoprefixer": "^10.4.27",
|
|
60
|
+
"@vue/compiler-sfc": "^3.5.34",
|
|
61
|
+
"autoprefixer": "^10.5.0",
|
|
63
62
|
"cheerio": "^1.2.0",
|
|
64
63
|
"chokidar": "^4.0.3",
|
|
65
64
|
"commander": "^14.0.3",
|
|
66
|
-
"cssnano": "^
|
|
67
|
-
"esbuild": "^0.
|
|
65
|
+
"cssnano": "^8.0.1",
|
|
66
|
+
"esbuild": "^0.28.0",
|
|
68
67
|
"htmlparser2": "^10.1.0",
|
|
69
68
|
"less": "^4.6.4",
|
|
70
69
|
"listr2": "^9.0.5",
|
|
71
70
|
"magic-string": "^0.30.21",
|
|
72
|
-
"oxc-parser": "^0.
|
|
73
|
-
"oxc-transform": "^0.124.0",
|
|
71
|
+
"oxc-parser": "^0.129.0",
|
|
74
72
|
"oxc-walker": "^0.7.0",
|
|
75
|
-
"postcss": "^8.5.
|
|
73
|
+
"postcss": "^8.5.14",
|
|
76
74
|
"postcss-selector-parser": "^7.1.1",
|
|
77
75
|
"sass": "^1.99.0",
|
|
78
|
-
"
|
|
76
|
+
"source-map-js": "^1.2.1"
|
|
79
77
|
},
|
|
80
78
|
publishConfig: {
|
|
81
79
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -84,18 +82,19 @@ var package_default = {
|
|
|
84
82
|
};
|
|
85
83
|
//#endregion
|
|
86
84
|
//#region src/bin/index.js
|
|
87
|
-
commander.program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").action(async (options) => {
|
|
85
|
+
commander.program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").option("--sourcemap", "生成 sourcemap 文件用于调试").action(async (options) => {
|
|
88
86
|
const workPath = options.workPath ? node_path.default.resolve(options.workPath) : node_process.default.cwd();
|
|
89
87
|
const targetPath = options.targetPath ? node_path.default.resolve(options.targetPath) : node_process.default.cwd();
|
|
90
88
|
const useAppIdDir = options.appIdDir !== false;
|
|
91
|
-
|
|
89
|
+
const sourcemap = !!options.sourcemap;
|
|
90
|
+
await require_index(targetPath, workPath, useAppIdDir, { sourcemap });
|
|
92
91
|
if (options.watch) chokidar.default.watch(workPath, {
|
|
93
92
|
persistent: true,
|
|
94
93
|
ignoreInitial: true
|
|
95
94
|
}).on("all", async (event, path) => {
|
|
96
95
|
if (event === "change") {
|
|
97
96
|
console.log(`${path} 改动,重新编译`);
|
|
98
|
-
await require_index(targetPath, workPath, useAppIdDir);
|
|
97
|
+
await require_index(targetPath, workPath, useAppIdDir, { sourcemap });
|
|
99
98
|
}
|
|
100
99
|
});
|
|
101
100
|
});
|
package/dist/bin/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import chokidar from "chokidar";
|
|
|
6
6
|
import { program } from "commander";
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@dimina/compiler",
|
|
9
|
-
version: "1.0.14
|
|
9
|
+
version: "1.0.14",
|
|
10
10
|
description: "星河编译工具",
|
|
11
11
|
main: "./dist/index.cjs",
|
|
12
12
|
module: "./dist/index.js",
|
|
@@ -32,10 +32,14 @@ var package_default = {
|
|
|
32
32
|
},
|
|
33
33
|
bin: { "dmcc": "dist/bin/index.js" },
|
|
34
34
|
scripts: {
|
|
35
|
+
"prebuild": "node scripts/sync-compatibility-reference.js",
|
|
35
36
|
"build": "vite build",
|
|
37
|
+
"sync:compat": "node scripts/sync-compatibility-reference.js",
|
|
38
|
+
"pretest": "node scripts/sync-compatibility-reference.js",
|
|
36
39
|
"test": "vitest run",
|
|
37
40
|
"test:dev": "vitest",
|
|
38
41
|
"coverage": "vitest run --coverage",
|
|
42
|
+
"prepack": "npm run build",
|
|
39
43
|
"release:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
|
|
40
44
|
"release": "npm version patch && npm publish"
|
|
41
45
|
},
|
|
@@ -49,29 +53,23 @@ var package_default = {
|
|
|
49
53
|
"星河"
|
|
50
54
|
],
|
|
51
55
|
dependencies: {
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
54
|
-
"@babel/plugin-transform-modules-commonjs": "^7.28.6",
|
|
55
|
-
"@babel/traverse": "^7.29.0",
|
|
56
|
-
"@babel/types": "^7.29.0",
|
|
57
|
-
"@vue/compiler-sfc": "^3.5.32",
|
|
58
|
-
"autoprefixer": "^10.4.27",
|
|
56
|
+
"@vue/compiler-sfc": "^3.5.34",
|
|
57
|
+
"autoprefixer": "^10.5.0",
|
|
59
58
|
"cheerio": "^1.2.0",
|
|
60
59
|
"chokidar": "^4.0.3",
|
|
61
60
|
"commander": "^14.0.3",
|
|
62
|
-
"cssnano": "^
|
|
63
|
-
"esbuild": "^0.
|
|
61
|
+
"cssnano": "^8.0.1",
|
|
62
|
+
"esbuild": "^0.28.0",
|
|
64
63
|
"htmlparser2": "^10.1.0",
|
|
65
64
|
"less": "^4.6.4",
|
|
66
65
|
"listr2": "^9.0.5",
|
|
67
66
|
"magic-string": "^0.30.21",
|
|
68
|
-
"oxc-parser": "^0.
|
|
69
|
-
"oxc-transform": "^0.124.0",
|
|
67
|
+
"oxc-parser": "^0.129.0",
|
|
70
68
|
"oxc-walker": "^0.7.0",
|
|
71
|
-
"postcss": "^8.5.
|
|
69
|
+
"postcss": "^8.5.14",
|
|
72
70
|
"postcss-selector-parser": "^7.1.1",
|
|
73
71
|
"sass": "^1.99.0",
|
|
74
|
-
"
|
|
72
|
+
"source-map-js": "^1.2.1"
|
|
75
73
|
},
|
|
76
74
|
publishConfig: {
|
|
77
75
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -80,18 +78,19 @@ var package_default = {
|
|
|
80
78
|
};
|
|
81
79
|
//#endregion
|
|
82
80
|
//#region src/bin/index.js
|
|
83
|
-
program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").action(async (options) => {
|
|
81
|
+
program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").option("--sourcemap", "生成 sourcemap 文件用于调试").action(async (options) => {
|
|
84
82
|
const workPath = options.workPath ? path.resolve(options.workPath) : process.cwd();
|
|
85
83
|
const targetPath = options.targetPath ? path.resolve(options.targetPath) : process.cwd();
|
|
86
84
|
const useAppIdDir = options.appIdDir !== false;
|
|
87
|
-
|
|
85
|
+
const sourcemap = !!options.sourcemap;
|
|
86
|
+
await build(targetPath, workPath, useAppIdDir, { sourcemap });
|
|
88
87
|
if (options.watch) chokidar.watch(workPath, {
|
|
89
88
|
persistent: true,
|
|
90
89
|
ignoreInitial: true
|
|
91
90
|
}).on("all", async (event, path) => {
|
|
92
91
|
if (event === "change") {
|
|
93
92
|
console.log(`${path} 改动,重新编译`);
|
|
94
|
-
await build(targetPath, workPath, useAppIdDir);
|
|
93
|
+
await build(targetPath, workPath, useAppIdDir, { sourcemap });
|
|
95
94
|
}
|
|
96
95
|
});
|
|
97
96
|
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Parser } from "htmlparser2";
|
|
2
|
+
//#region src/common/compatibility-reference.js
|
|
3
|
+
var supportedBuiltinComponents = [
|
|
4
|
+
"block",
|
|
5
|
+
"button",
|
|
6
|
+
"checkbox",
|
|
7
|
+
"checkbox-group",
|
|
8
|
+
"cover-image",
|
|
9
|
+
"cover-view",
|
|
10
|
+
"form",
|
|
11
|
+
"icon",
|
|
12
|
+
"image",
|
|
13
|
+
"input",
|
|
14
|
+
"label",
|
|
15
|
+
"movable-area",
|
|
16
|
+
"movable-view",
|
|
17
|
+
"navigation-bar",
|
|
18
|
+
"navigator",
|
|
19
|
+
"picker",
|
|
20
|
+
"picker-view",
|
|
21
|
+
"picker-view-column",
|
|
22
|
+
"progress",
|
|
23
|
+
"radio",
|
|
24
|
+
"radio-group",
|
|
25
|
+
"rich-text",
|
|
26
|
+
"scroll-view",
|
|
27
|
+
"slider",
|
|
28
|
+
"slot",
|
|
29
|
+
"swiper",
|
|
30
|
+
"swiper-item",
|
|
31
|
+
"switch",
|
|
32
|
+
"template",
|
|
33
|
+
"text",
|
|
34
|
+
"textarea",
|
|
35
|
+
"view",
|
|
36
|
+
"web-view",
|
|
37
|
+
"wxs",
|
|
38
|
+
"include",
|
|
39
|
+
"import"
|
|
40
|
+
];
|
|
41
|
+
var supportedWxApis = [
|
|
42
|
+
"env",
|
|
43
|
+
"canIUse",
|
|
44
|
+
"openSystemBluetoothSetting",
|
|
45
|
+
"getWindowInfo",
|
|
46
|
+
"getSystemSetting",
|
|
47
|
+
"getSystemInfoSync",
|
|
48
|
+
"getSystemInfoAsync",
|
|
49
|
+
"getSystemInfo",
|
|
50
|
+
"reLaunch",
|
|
51
|
+
"redirectTo",
|
|
52
|
+
"navigateTo",
|
|
53
|
+
"navigateBack",
|
|
54
|
+
"showToast",
|
|
55
|
+
"showModal",
|
|
56
|
+
"showLoading",
|
|
57
|
+
"showActionSheet",
|
|
58
|
+
"hideToast",
|
|
59
|
+
"hideLoading",
|
|
60
|
+
"setNavigationBarTitle",
|
|
61
|
+
"setNavigationBarColor",
|
|
62
|
+
"pageScrollTo",
|
|
63
|
+
"getMenuButtonBoundingClientRect",
|
|
64
|
+
"createAnimation",
|
|
65
|
+
"createSelectorQuery",
|
|
66
|
+
"createIntersectionObserver",
|
|
67
|
+
"request",
|
|
68
|
+
"downloadFile",
|
|
69
|
+
"uploadFile",
|
|
70
|
+
"setStorageSync",
|
|
71
|
+
"getStorageSync",
|
|
72
|
+
"removeStorageSync",
|
|
73
|
+
"clearStorageSync",
|
|
74
|
+
"setStorage",
|
|
75
|
+
"getStorage",
|
|
76
|
+
"removeStorage",
|
|
77
|
+
"clearStorage",
|
|
78
|
+
"getStorageInfoSync",
|
|
79
|
+
"getStorageInfo",
|
|
80
|
+
"saveImageToPhotosAlbum",
|
|
81
|
+
"previewImage",
|
|
82
|
+
"compressImage",
|
|
83
|
+
"chooseImage",
|
|
84
|
+
"chooseMedia",
|
|
85
|
+
"chooseContact",
|
|
86
|
+
"addPhoneContact",
|
|
87
|
+
"setClipboardData",
|
|
88
|
+
"getClipboardData",
|
|
89
|
+
"vibrateShort",
|
|
90
|
+
"vibrateLong",
|
|
91
|
+
"hideKeyboard",
|
|
92
|
+
"getNetworkType",
|
|
93
|
+
"makePhoneCall",
|
|
94
|
+
"extBridge",
|
|
95
|
+
"extOnBridge",
|
|
96
|
+
"extOffBridge"
|
|
97
|
+
];
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/common/compatibility.js
|
|
100
|
+
var cachedReference = null;
|
|
101
|
+
var warnedItems = /* @__PURE__ */ new Set();
|
|
102
|
+
function loadReference() {
|
|
103
|
+
if (cachedReference) return cachedReference;
|
|
104
|
+
cachedReference = {
|
|
105
|
+
supportedBuiltinComponents: new Set(supportedBuiltinComponents),
|
|
106
|
+
supportedWxApis: new Set(supportedWxApis)
|
|
107
|
+
};
|
|
108
|
+
return cachedReference;
|
|
109
|
+
}
|
|
110
|
+
function getWxMemberName(node) {
|
|
111
|
+
if (node?.type !== "MemberExpression") return null;
|
|
112
|
+
if (node.object?.type !== "Identifier" || node.object.name !== "wx") return null;
|
|
113
|
+
if (!node.computed && node.property?.type === "Identifier") return node.property.name;
|
|
114
|
+
if (node.computed && (node.property?.type === "StringLiteral" || node.property?.type === "Literal") && typeof node.property.value === "string") return node.property.value;
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
function warnUnsupportedWxApi(apiName, filePath, line) {
|
|
118
|
+
const { supportedWxApis } = loadReference();
|
|
119
|
+
if (!apiName || supportedWxApis.has(apiName)) return;
|
|
120
|
+
const location = formatLocation(filePath, line);
|
|
121
|
+
warnOnce("api", apiName, location, `[compat] Unsupported wx API: wx.${apiName}${location}`);
|
|
122
|
+
}
|
|
123
|
+
function warnUnsupportedComponent(tagName, filePath, line) {
|
|
124
|
+
const { supportedBuiltinComponents } = loadReference();
|
|
125
|
+
if (!tagName || supportedBuiltinComponents.has(tagName)) return;
|
|
126
|
+
const location = formatLocation(filePath, line);
|
|
127
|
+
warnOnce("component", tagName, location, `[compat] Unsupported or undeclared component: <${tagName}>${location}`);
|
|
128
|
+
}
|
|
129
|
+
function checkTemplateCompatibility(content, filePath, components = {}) {
|
|
130
|
+
let parser;
|
|
131
|
+
parser = new Parser({
|
|
132
|
+
onopentag(tagName) {
|
|
133
|
+
if (components?.[tagName]) return;
|
|
134
|
+
warnUnsupportedComponent(tagName, filePath, getLineByIndex(content, parser.startIndex));
|
|
135
|
+
},
|
|
136
|
+
onerror(error) {
|
|
137
|
+
console.warn("[compat]", `Failed to parse template for compatibility diagnostics: ${filePath}`, error.message);
|
|
138
|
+
}
|
|
139
|
+
}, {
|
|
140
|
+
xmlMode: true,
|
|
141
|
+
lowerCaseTags: false,
|
|
142
|
+
lowerCaseAttributeNames: false,
|
|
143
|
+
withStartIndices: true
|
|
144
|
+
});
|
|
145
|
+
parser.write(content);
|
|
146
|
+
parser.end();
|
|
147
|
+
}
|
|
148
|
+
function getLineByIndex(content, index) {
|
|
149
|
+
if (typeof index !== "number" || index < 0) return null;
|
|
150
|
+
let line = 1;
|
|
151
|
+
for (let i = 0; i < index; i++) if (content.charCodeAt(i) === 10) line++;
|
|
152
|
+
return line;
|
|
153
|
+
}
|
|
154
|
+
function formatLocation(filePath, line) {
|
|
155
|
+
if (!filePath) return "";
|
|
156
|
+
return line ? ` (${filePath}:${line})` : ` (${filePath})`;
|
|
157
|
+
}
|
|
158
|
+
function warnOnce(type, name, location, message) {
|
|
159
|
+
const key = `${type}:${name}:${location}`;
|
|
160
|
+
if (warnedItems.has(key)) return;
|
|
161
|
+
warnedItems.add(key);
|
|
162
|
+
console.warn(message);
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
export { getWxMemberName as n, warnUnsupportedWxApi as r, checkTemplateCompatibility as t };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
require("./env-M-7lpbHL.cjs");
|
|
2
|
+
let htmlparser2 = require("htmlparser2");
|
|
3
|
+
//#region src/common/compatibility-reference.js
|
|
4
|
+
var supportedBuiltinComponents = [
|
|
5
|
+
"block",
|
|
6
|
+
"button",
|
|
7
|
+
"checkbox",
|
|
8
|
+
"checkbox-group",
|
|
9
|
+
"cover-image",
|
|
10
|
+
"cover-view",
|
|
11
|
+
"form",
|
|
12
|
+
"icon",
|
|
13
|
+
"image",
|
|
14
|
+
"input",
|
|
15
|
+
"label",
|
|
16
|
+
"movable-area",
|
|
17
|
+
"movable-view",
|
|
18
|
+
"navigation-bar",
|
|
19
|
+
"navigator",
|
|
20
|
+
"picker",
|
|
21
|
+
"picker-view",
|
|
22
|
+
"picker-view-column",
|
|
23
|
+
"progress",
|
|
24
|
+
"radio",
|
|
25
|
+
"radio-group",
|
|
26
|
+
"rich-text",
|
|
27
|
+
"scroll-view",
|
|
28
|
+
"slider",
|
|
29
|
+
"slot",
|
|
30
|
+
"swiper",
|
|
31
|
+
"swiper-item",
|
|
32
|
+
"switch",
|
|
33
|
+
"template",
|
|
34
|
+
"text",
|
|
35
|
+
"textarea",
|
|
36
|
+
"view",
|
|
37
|
+
"web-view",
|
|
38
|
+
"wxs",
|
|
39
|
+
"include",
|
|
40
|
+
"import"
|
|
41
|
+
];
|
|
42
|
+
var supportedWxApis = [
|
|
43
|
+
"env",
|
|
44
|
+
"canIUse",
|
|
45
|
+
"openSystemBluetoothSetting",
|
|
46
|
+
"getWindowInfo",
|
|
47
|
+
"getSystemSetting",
|
|
48
|
+
"getSystemInfoSync",
|
|
49
|
+
"getSystemInfoAsync",
|
|
50
|
+
"getSystemInfo",
|
|
51
|
+
"reLaunch",
|
|
52
|
+
"redirectTo",
|
|
53
|
+
"navigateTo",
|
|
54
|
+
"navigateBack",
|
|
55
|
+
"showToast",
|
|
56
|
+
"showModal",
|
|
57
|
+
"showLoading",
|
|
58
|
+
"showActionSheet",
|
|
59
|
+
"hideToast",
|
|
60
|
+
"hideLoading",
|
|
61
|
+
"setNavigationBarTitle",
|
|
62
|
+
"setNavigationBarColor",
|
|
63
|
+
"pageScrollTo",
|
|
64
|
+
"getMenuButtonBoundingClientRect",
|
|
65
|
+
"createAnimation",
|
|
66
|
+
"createSelectorQuery",
|
|
67
|
+
"createIntersectionObserver",
|
|
68
|
+
"request",
|
|
69
|
+
"downloadFile",
|
|
70
|
+
"uploadFile",
|
|
71
|
+
"setStorageSync",
|
|
72
|
+
"getStorageSync",
|
|
73
|
+
"removeStorageSync",
|
|
74
|
+
"clearStorageSync",
|
|
75
|
+
"setStorage",
|
|
76
|
+
"getStorage",
|
|
77
|
+
"removeStorage",
|
|
78
|
+
"clearStorage",
|
|
79
|
+
"getStorageInfoSync",
|
|
80
|
+
"getStorageInfo",
|
|
81
|
+
"saveImageToPhotosAlbum",
|
|
82
|
+
"previewImage",
|
|
83
|
+
"compressImage",
|
|
84
|
+
"chooseImage",
|
|
85
|
+
"chooseMedia",
|
|
86
|
+
"chooseContact",
|
|
87
|
+
"addPhoneContact",
|
|
88
|
+
"setClipboardData",
|
|
89
|
+
"getClipboardData",
|
|
90
|
+
"vibrateShort",
|
|
91
|
+
"vibrateLong",
|
|
92
|
+
"hideKeyboard",
|
|
93
|
+
"getNetworkType",
|
|
94
|
+
"makePhoneCall",
|
|
95
|
+
"extBridge",
|
|
96
|
+
"extOnBridge",
|
|
97
|
+
"extOffBridge"
|
|
98
|
+
];
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/common/compatibility.js
|
|
101
|
+
var cachedReference = null;
|
|
102
|
+
var warnedItems = /* @__PURE__ */ new Set();
|
|
103
|
+
function loadReference() {
|
|
104
|
+
if (cachedReference) return cachedReference;
|
|
105
|
+
cachedReference = {
|
|
106
|
+
supportedBuiltinComponents: new Set(supportedBuiltinComponents),
|
|
107
|
+
supportedWxApis: new Set(supportedWxApis)
|
|
108
|
+
};
|
|
109
|
+
return cachedReference;
|
|
110
|
+
}
|
|
111
|
+
function getWxMemberName(node) {
|
|
112
|
+
if (node?.type !== "MemberExpression") return null;
|
|
113
|
+
if (node.object?.type !== "Identifier" || node.object.name !== "wx") return null;
|
|
114
|
+
if (!node.computed && node.property?.type === "Identifier") return node.property.name;
|
|
115
|
+
if (node.computed && (node.property?.type === "StringLiteral" || node.property?.type === "Literal") && typeof node.property.value === "string") return node.property.value;
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
function warnUnsupportedWxApi(apiName, filePath, line) {
|
|
119
|
+
const { supportedWxApis } = loadReference();
|
|
120
|
+
if (!apiName || supportedWxApis.has(apiName)) return;
|
|
121
|
+
const location = formatLocation(filePath, line);
|
|
122
|
+
warnOnce("api", apiName, location, `[compat] Unsupported wx API: wx.${apiName}${location}`);
|
|
123
|
+
}
|
|
124
|
+
function warnUnsupportedComponent(tagName, filePath, line) {
|
|
125
|
+
const { supportedBuiltinComponents } = loadReference();
|
|
126
|
+
if (!tagName || supportedBuiltinComponents.has(tagName)) return;
|
|
127
|
+
const location = formatLocation(filePath, line);
|
|
128
|
+
warnOnce("component", tagName, location, `[compat] Unsupported or undeclared component: <${tagName}>${location}`);
|
|
129
|
+
}
|
|
130
|
+
function checkTemplateCompatibility(content, filePath, components = {}) {
|
|
131
|
+
let parser;
|
|
132
|
+
parser = new htmlparser2.Parser({
|
|
133
|
+
onopentag(tagName) {
|
|
134
|
+
if (components?.[tagName]) return;
|
|
135
|
+
warnUnsupportedComponent(tagName, filePath, getLineByIndex(content, parser.startIndex));
|
|
136
|
+
},
|
|
137
|
+
onerror(error) {
|
|
138
|
+
console.warn("[compat]", `Failed to parse template for compatibility diagnostics: ${filePath}`, error.message);
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
xmlMode: true,
|
|
142
|
+
lowerCaseTags: false,
|
|
143
|
+
lowerCaseAttributeNames: false,
|
|
144
|
+
withStartIndices: true
|
|
145
|
+
});
|
|
146
|
+
parser.write(content);
|
|
147
|
+
parser.end();
|
|
148
|
+
}
|
|
149
|
+
function getLineByIndex(content, index) {
|
|
150
|
+
if (typeof index !== "number" || index < 0) return null;
|
|
151
|
+
let line = 1;
|
|
152
|
+
for (let i = 0; i < index; i++) if (content.charCodeAt(i) === 10) line++;
|
|
153
|
+
return line;
|
|
154
|
+
}
|
|
155
|
+
function formatLocation(filePath, line) {
|
|
156
|
+
if (!filePath) return "";
|
|
157
|
+
return line ? ` (${filePath}:${line})` : ` (${filePath})`;
|
|
158
|
+
}
|
|
159
|
+
function warnOnce(type, name, location, message) {
|
|
160
|
+
const key = `${type}:${name}:${location}`;
|
|
161
|
+
if (warnedItems.has(key)) return;
|
|
162
|
+
warnedItems.add(key);
|
|
163
|
+
console.warn(message);
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
Object.defineProperty(exports, "checkTemplateCompatibility", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
get: function() {
|
|
169
|
+
return checkTemplateCompatibility;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(exports, "getWxMemberName", {
|
|
173
|
+
enumerable: true,
|
|
174
|
+
get: function() {
|
|
175
|
+
return getWxMemberName;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(exports, "warnUnsupportedWxApi", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: function() {
|
|
181
|
+
return warnUnsupportedWxApi;
|
|
182
|
+
}
|
|
183
|
+
});
|