@appthen/cli 1.2.3 → 1.2.4
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 +847 -342
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37880,37 +37880,7 @@ function create(options) {
|
|
|
37880
37880
|
console.log('[e] ', e_1);
|
|
37881
37881
|
// return {} as any;
|
|
37882
37882
|
throw e_1;
|
|
37883
|
-
case 7:
|
|
37884
|
-
// await createProjectFromTemplate(options.template);
|
|
37885
|
-
// await createProjectFromTemplate('https://cdn.appthen.cn/templates/appthen-vite-starter.zip', 'my-new-project');
|
|
37886
|
-
// const { projectType } = await inquirer.prompt([
|
|
37887
|
-
// {
|
|
37888
|
-
// type: 'list',
|
|
37889
|
-
// name: 'projectType',
|
|
37890
|
-
// message: 'Which type of project do you want to initialize?',
|
|
37891
|
-
// choices: ['Vite Project', 'Taro Project', 'Asset Package Project'],
|
|
37892
|
-
// },
|
|
37893
|
-
// ]);
|
|
37894
|
-
// switch (projectType) {
|
|
37895
|
-
// case 'Vite Project':
|
|
37896
|
-
// console.log('projectType: ', projectType);
|
|
37897
|
-
// // Initialize a Vite project
|
|
37898
|
-
// // await require('../dist/index.js').initViteProject(options);
|
|
37899
|
-
// break;
|
|
37900
|
-
// case 'Taro Project':
|
|
37901
|
-
// console.log('projectType: ', projectType);
|
|
37902
|
-
// // Initialize a Taro project
|
|
37903
|
-
// // await require('../dist/index.js').initTaroProject(options);
|
|
37904
|
-
// break;
|
|
37905
|
-
// case 'Asset Package Project':
|
|
37906
|
-
// console.log('projectType: ', projectType);
|
|
37907
|
-
// // Initialize an asset package project
|
|
37908
|
-
// // await require('../dist/index.js').initAssetPackageProject(options);
|
|
37909
|
-
// break;
|
|
37910
|
-
// default:
|
|
37911
|
-
// console.error('Unknown project type');
|
|
37912
|
-
// }
|
|
37913
|
-
return [2 /*return*/, 1];
|
|
37883
|
+
case 7: return [2 /*return*/, 1];
|
|
37914
37884
|
}
|
|
37915
37885
|
});
|
|
37916
37886
|
});
|
|
@@ -41243,7 +41213,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41243
41213
|
return !!this.state.files[filePath];
|
|
41244
41214
|
};
|
|
41245
41215
|
/**
|
|
41246
|
-
* 🆕
|
|
41216
|
+
* 🆕 读取影子空间中的文件内容(带缓存)
|
|
41247
41217
|
*/
|
|
41248
41218
|
ShadowSpace.prototype.readFile = function (filePath) {
|
|
41249
41219
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -41273,6 +41243,38 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41273
41243
|
});
|
|
41274
41244
|
});
|
|
41275
41245
|
};
|
|
41246
|
+
/**
|
|
41247
|
+
* 🆕 实时读取文件内容(直接从文件系统,不使用缓存)
|
|
41248
|
+
*/
|
|
41249
|
+
ShadowSpace.prototype.readRealTimeFile = function (filePath) {
|
|
41250
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
41251
|
+
var fullPath, content, error_4;
|
|
41252
|
+
return __generator(this, function (_a) {
|
|
41253
|
+
switch (_a.label) {
|
|
41254
|
+
case 0:
|
|
41255
|
+
_a.trys.push([0, 3, , 4]);
|
|
41256
|
+
fullPath = path__default["default"].join(this.config.projectRoot, filePath);
|
|
41257
|
+
// 检查文件是否存在
|
|
41258
|
+
return [4 /*yield*/, fs__default$1["default"].access(fullPath)];
|
|
41259
|
+
case 1:
|
|
41260
|
+
// 检查文件是否存在
|
|
41261
|
+
_a.sent();
|
|
41262
|
+
return [4 /*yield*/, fs__default$1["default"].readFile(fullPath, 'utf8')];
|
|
41263
|
+
case 2:
|
|
41264
|
+
content = _a.sent();
|
|
41265
|
+
console.log("[ShadowSpace] \u5B9E\u65F6\u8BFB\u53D6\u6587\u4EF6\u6210\u529F: ".concat(filePath, ", \u957F\u5EA6: ").concat(content.length));
|
|
41266
|
+
// 可选:更新内存缓存以确保一致性
|
|
41267
|
+
this.contentCache.set(filePath, content);
|
|
41268
|
+
return [2 /*return*/, content];
|
|
41269
|
+
case 3:
|
|
41270
|
+
error_4 = _a.sent();
|
|
41271
|
+
console.warn("[ShadowSpace] \u5B9E\u65F6\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25: ".concat(filePath), error_4);
|
|
41272
|
+
return [2 /*return*/, null];
|
|
41273
|
+
case 4: return [2 /*return*/];
|
|
41274
|
+
}
|
|
41275
|
+
});
|
|
41276
|
+
});
|
|
41277
|
+
};
|
|
41276
41278
|
/**
|
|
41277
41279
|
* 标记文件为远程修改
|
|
41278
41280
|
* 当编辑器通过WebSocket修改文件后调用此方法
|
|
@@ -41280,7 +41282,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41280
41282
|
ShadowSpace.prototype.markAsRemoteModified = function (filePaths) {
|
|
41281
41283
|
var _a;
|
|
41282
41284
|
return __awaiter(this, void 0, void 0, function () {
|
|
41283
|
-
var now, hasChanges, filePaths_1, filePaths_1_1, filePath, fullPath, stats, content, hash, existingFile, remoteHash,
|
|
41285
|
+
var now, hasChanges, filePaths_1, filePaths_1_1, filePath, fullPath, stats, content, hash, existingFile, remoteHash, error_5, e_6_1;
|
|
41284
41286
|
var e_6, _b;
|
|
41285
41287
|
return __generator(this, function (_c) {
|
|
41286
41288
|
switch (_c.label) {
|
|
@@ -41330,8 +41332,8 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41330
41332
|
});
|
|
41331
41333
|
return [3 /*break*/, 7];
|
|
41332
41334
|
case 6:
|
|
41333
|
-
|
|
41334
|
-
console.warn("\u6807\u8BB0\u8FDC\u7A0B\u4FEE\u6539\u5931\u8D25 ".concat(filePath, ":"),
|
|
41335
|
+
error_5 = _c.sent();
|
|
41336
|
+
console.warn("\u6807\u8BB0\u8FDC\u7A0B\u4FEE\u6539\u5931\u8D25 ".concat(filePath, ":"), error_5);
|
|
41335
41337
|
return [3 /*break*/, 7];
|
|
41336
41338
|
case 7:
|
|
41337
41339
|
filePaths_1_1 = filePaths_1.next();
|
|
@@ -41408,7 +41410,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41408
41410
|
*/
|
|
41409
41411
|
ShadowSpace.prototype.getSpaceSnapshots = function (_spaceId) {
|
|
41410
41412
|
return __awaiter(this, void 0, void 0, function () {
|
|
41411
|
-
var snapshots, _a, _b, _c, filePath, shadowEntry,
|
|
41413
|
+
var snapshots, _a, _b, _c, filePath, shadowEntry, error_6;
|
|
41412
41414
|
var e_8, _d;
|
|
41413
41415
|
return __generator(this, function (_e) {
|
|
41414
41416
|
switch (_e.label) {
|
|
@@ -41448,8 +41450,8 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41448
41450
|
console.log("[ShadowSpace] \u83B7\u53D6\u7A7A\u95F4\u5FEB\u7167: ".concat(snapshots.length, " \u4E2A\u6587\u4EF6"));
|
|
41449
41451
|
return [2 /*return*/, snapshots];
|
|
41450
41452
|
case 2:
|
|
41451
|
-
|
|
41452
|
-
console.error("[ShadowSpace] \u83B7\u53D6\u7A7A\u95F4\u5FEB\u7167\u5931\u8D25:",
|
|
41453
|
+
error_6 = _e.sent();
|
|
41454
|
+
console.error("[ShadowSpace] \u83B7\u53D6\u7A7A\u95F4\u5FEB\u7167\u5931\u8D25:", error_6);
|
|
41453
41455
|
return [2 /*return*/, []]; // 返回空数组而不是 undefined
|
|
41454
41456
|
case 3: return [2 /*return*/];
|
|
41455
41457
|
}
|
|
@@ -41510,7 +41512,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41510
41512
|
*/
|
|
41511
41513
|
ShadowSpace.prototype.saveSpaceConfig = function () {
|
|
41512
41514
|
return __awaiter(this, void 0, void 0, function () {
|
|
41513
|
-
var configFile, config,
|
|
41515
|
+
var configFile, config, error_8;
|
|
41514
41516
|
return __generator(this, function (_a) {
|
|
41515
41517
|
switch (_a.label) {
|
|
41516
41518
|
case 0:
|
|
@@ -41535,8 +41537,8 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41535
41537
|
console.log("[ShadowSpace] \u7A7A\u95F4\u914D\u7F6E\u5DF2\u4FDD\u5B58: ".concat(configFile));
|
|
41536
41538
|
return [3 /*break*/, 5];
|
|
41537
41539
|
case 4:
|
|
41538
|
-
|
|
41539
|
-
console.warn("[ShadowSpace] \u4FDD\u5B58\u7A7A\u95F4\u914D\u7F6E\u5931\u8D25:",
|
|
41540
|
+
error_8 = _a.sent();
|
|
41541
|
+
console.warn("[ShadowSpace] \u4FDD\u5B58\u7A7A\u95F4\u914D\u7F6E\u5931\u8D25:", error_8);
|
|
41540
41542
|
return [3 /*break*/, 5];
|
|
41541
41543
|
case 5: return [2 /*return*/];
|
|
41542
41544
|
}
|
|
@@ -41548,7 +41550,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41548
41550
|
*/
|
|
41549
41551
|
ShadowSpace.prototype.migrateOldStateFiles = function () {
|
|
41550
41552
|
return __awaiter(this, void 0, void 0, function () {
|
|
41551
|
-
var appthenDir, files, oldStateFiles, oldStateFiles_1, oldStateFiles_1_1, oldFile, oldFilePath, oldState, backupFile, e_9_1,
|
|
41553
|
+
var appthenDir, files, oldStateFiles, oldStateFiles_1, oldStateFiles_1_1, oldFile, oldFilePath, oldState, backupFile, e_9_1, error_9;
|
|
41552
41554
|
var e_9, _a;
|
|
41553
41555
|
var _this = this;
|
|
41554
41556
|
return __generator(this, function (_b) {
|
|
@@ -41614,8 +41616,8 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41614
41616
|
return [7 /*endfinally*/];
|
|
41615
41617
|
case 11: return [3 /*break*/, 13];
|
|
41616
41618
|
case 12:
|
|
41617
|
-
|
|
41618
|
-
console.warn("[ShadowSpace] \u8FC1\u79FB\u65E7\u72B6\u6001\u6587\u4EF6\u5931\u8D25:",
|
|
41619
|
+
error_9 = _b.sent();
|
|
41620
|
+
console.warn("[ShadowSpace] \u8FC1\u79FB\u65E7\u72B6\u6001\u6587\u4EF6\u5931\u8D25:", error_9);
|
|
41619
41621
|
return [3 /*break*/, 13];
|
|
41620
41622
|
case 13: return [2 /*return*/];
|
|
41621
41623
|
}
|
|
@@ -41624,7 +41626,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41624
41626
|
};
|
|
41625
41627
|
ShadowSpace.prototype.getShadowContent = function (filePath) {
|
|
41626
41628
|
return __awaiter(this, void 0, void 0, function () {
|
|
41627
|
-
var localPath, content,
|
|
41629
|
+
var localPath, content, error_10;
|
|
41628
41630
|
return __generator(this, function (_a) {
|
|
41629
41631
|
switch (_a.label) {
|
|
41630
41632
|
case 0:
|
|
@@ -41642,8 +41644,8 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41642
41644
|
this.contentCache.set(filePath, content);
|
|
41643
41645
|
return [2 /*return*/, content];
|
|
41644
41646
|
case 3:
|
|
41645
|
-
|
|
41646
|
-
console.warn("\u65E0\u6CD5\u83B7\u53D6\u5F71\u5B50\u5185\u5BB9: ".concat(filePath),
|
|
41647
|
+
error_10 = _a.sent();
|
|
41648
|
+
console.warn("\u65E0\u6CD5\u83B7\u53D6\u5F71\u5B50\u5185\u5BB9: ".concat(filePath), error_10);
|
|
41647
41649
|
return [2 /*return*/, ''];
|
|
41648
41650
|
case 4: return [2 /*return*/];
|
|
41649
41651
|
}
|
|
@@ -41717,7 +41719,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41717
41719
|
};
|
|
41718
41720
|
ShadowSpace.prototype.writeLocalFile = function (filePath, content) {
|
|
41719
41721
|
return __awaiter(this, void 0, void 0, function () {
|
|
41720
|
-
var fullPath,
|
|
41722
|
+
var fullPath, error_11;
|
|
41721
41723
|
return __generator(this, function (_a) {
|
|
41722
41724
|
switch (_a.label) {
|
|
41723
41725
|
case 0:
|
|
@@ -41740,9 +41742,9 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41740
41742
|
console.log("[ShadowSpace] \u6587\u4EF6\u5199\u5165\u6210\u529F: ".concat(fullPath));
|
|
41741
41743
|
return [3 /*break*/, 5];
|
|
41742
41744
|
case 4:
|
|
41743
|
-
|
|
41744
|
-
console.error("[ShadowSpace] \u6587\u4EF6\u5199\u5165\u5931\u8D25: ".concat(fullPath),
|
|
41745
|
-
throw
|
|
41745
|
+
error_11 = _a.sent();
|
|
41746
|
+
console.error("[ShadowSpace] \u6587\u4EF6\u5199\u5165\u5931\u8D25: ".concat(fullPath), error_11);
|
|
41747
|
+
throw error_11;
|
|
41746
41748
|
case 5: return [2 /*return*/];
|
|
41747
41749
|
}
|
|
41748
41750
|
});
|
|
@@ -41750,7 +41752,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41750
41752
|
};
|
|
41751
41753
|
ShadowSpace.prototype.scanLocalFiles = function () {
|
|
41752
41754
|
return __awaiter(this, void 0, void 0, function () {
|
|
41753
|
-
var files, pattern, options, filePaths, filePaths_2, filePaths_2_1, filePath, fullPath, content, stats,
|
|
41755
|
+
var files, pattern, options, filePaths, filePaths_2, filePaths_2_1, filePath, fullPath, content, stats, error_12, e_11_1;
|
|
41754
41756
|
var e_11, _a;
|
|
41755
41757
|
return __generator(this, function (_b) {
|
|
41756
41758
|
switch (_b.label) {
|
|
@@ -41790,8 +41792,8 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41790
41792
|
});
|
|
41791
41793
|
return [3 /*break*/, 7];
|
|
41792
41794
|
case 6:
|
|
41793
|
-
|
|
41794
|
-
console.warn("\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25: ".concat(filePath),
|
|
41795
|
+
error_12 = _b.sent();
|
|
41796
|
+
console.warn("\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25: ".concat(filePath), error_12);
|
|
41795
41797
|
return [3 /*break*/, 7];
|
|
41796
41798
|
case 7:
|
|
41797
41799
|
filePaths_2_1 = filePaths_2.next();
|
|
@@ -41992,7 +41994,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
41992
41994
|
*/
|
|
41993
41995
|
ShadowSpace.prototype.onFileChanged = function (filePath) {
|
|
41994
41996
|
return __awaiter(this, void 0, void 0, function () {
|
|
41995
|
-
var relativePath, shadowEntry, content, hash, stats,
|
|
41997
|
+
var relativePath, shadowEntry, content, hash, stats, error_14;
|
|
41996
41998
|
return __generator(this, function (_a) {
|
|
41997
41999
|
switch (_a.label) {
|
|
41998
42000
|
case 0:
|
|
@@ -42026,8 +42028,8 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
42026
42028
|
});
|
|
42027
42029
|
return [3 /*break*/, 6];
|
|
42028
42030
|
case 5:
|
|
42029
|
-
|
|
42030
|
-
console.error("[ShadowSpace] \u5904\u7406\u6587\u4EF6\u53D8\u66F4\u5931\u8D25: ".concat(relativePath),
|
|
42031
|
+
error_14 = _a.sent();
|
|
42032
|
+
console.error("[ShadowSpace] \u5904\u7406\u6587\u4EF6\u53D8\u66F4\u5931\u8D25: ".concat(relativePath), error_14);
|
|
42031
42033
|
return [3 /*break*/, 6];
|
|
42032
42034
|
case 6: return [2 /*return*/];
|
|
42033
42035
|
}
|
|
@@ -42039,7 +42041,7 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
42039
42041
|
*/
|
|
42040
42042
|
ShadowSpace.prototype.onFileAdded = function (filePath) {
|
|
42041
42043
|
return __awaiter(this, void 0, void 0, function () {
|
|
42042
|
-
var relativePath, content, hash, stats,
|
|
42044
|
+
var relativePath, content, hash, stats, error_15;
|
|
42043
42045
|
return __generator(this, function (_a) {
|
|
42044
42046
|
switch (_a.label) {
|
|
42045
42047
|
case 0:
|
|
@@ -42066,8 +42068,8 @@ var ShadowSpace = /** @class */ (function () {
|
|
|
42066
42068
|
});
|
|
42067
42069
|
return [3 /*break*/, 5];
|
|
42068
42070
|
case 4:
|
|
42069
|
-
|
|
42070
|
-
console.error("[ShadowSpace] \u5904\u7406\u6587\u4EF6\u65B0\u589E\u5931\u8D25: ".concat(relativePath),
|
|
42071
|
+
error_15 = _a.sent();
|
|
42072
|
+
console.error("[ShadowSpace] \u5904\u7406\u6587\u4EF6\u65B0\u589E\u5931\u8D25: ".concat(relativePath), error_15);
|
|
42071
42073
|
return [3 /*break*/, 5];
|
|
42072
42074
|
case 5: return [2 /*return*/];
|
|
42073
42075
|
}
|
|
@@ -42199,6 +42201,8 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42199
42201
|
this.currentUserId = null;
|
|
42200
42202
|
// 🆕 变更聚合器
|
|
42201
42203
|
this.changeAggregator = null;
|
|
42204
|
+
// 🆕 实时读取配置
|
|
42205
|
+
this.useRealtimeFileRead = true;
|
|
42202
42206
|
this.shadowSpace = shadowSpace;
|
|
42203
42207
|
this.socketStore = socketStore;
|
|
42204
42208
|
}
|
|
@@ -42209,6 +42213,13 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42209
42213
|
this.currentUserId = userId;
|
|
42210
42214
|
console.log("[ShadowSpace] \u8BBE\u7F6E\u5F53\u524D\u7528\u6237ID: ".concat(userId));
|
|
42211
42215
|
};
|
|
42216
|
+
/**
|
|
42217
|
+
* 设置是否使用实时文件读取
|
|
42218
|
+
*/
|
|
42219
|
+
ShadowSpaceCommandHandler.prototype.setRealtimeFileRead = function (enabled) {
|
|
42220
|
+
this.useRealtimeFileRead = enabled;
|
|
42221
|
+
console.log("[ShadowSpace] \u5B9E\u65F6\u6587\u4EF6\u8BFB\u53D6\u5DF2".concat(enabled ? '启用' : '禁用'));
|
|
42222
|
+
};
|
|
42212
42223
|
/**
|
|
42213
42224
|
* 处理WebSocket消息
|
|
42214
42225
|
*/
|
|
@@ -42271,14 +42282,14 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42271
42282
|
console.log('[ShadowSpaceCommandHandler] 获取文件内容 - message:', JSON.stringify(message, null, 2));
|
|
42272
42283
|
console.log('[ShadowSpaceCommandHandler] 获取文件内容 - message.path:', message.path);
|
|
42273
42284
|
console.log('[ShadowSpaceCommandHandler] 获取文件内容 - message.message.path:', (_b = message.message) === null || _b === void 0 ? void 0 : _b.path);
|
|
42274
|
-
return [4 /*yield*/, this.getFileContent(((_c = message.message) === null || _c === void 0 ? void 0 : _c.path) || message.path)];
|
|
42285
|
+
return [4 /*yield*/, this.getFileContent(((_c = message.message) === null || _c === void 0 ? void 0 : _c.path) || message.path, this.useRealtimeFileRead)];
|
|
42275
42286
|
case 5:
|
|
42276
|
-
// 🆕 修复:路径在 message.message.path
|
|
42287
|
+
// 🆕 修复:路径在 message.message.path 中,使用配置的实时读取选项
|
|
42277
42288
|
result = _j.sent();
|
|
42278
42289
|
return [3 /*break*/, 27];
|
|
42279
|
-
case 6: return [4 /*yield*/, this.getFilesContent(((_d = message.message) === null || _d === void 0 ? void 0 : _d.paths) || message.paths)];
|
|
42290
|
+
case 6: return [4 /*yield*/, this.getFilesContent(((_d = message.message) === null || _d === void 0 ? void 0 : _d.paths) || message.paths, this.useRealtimeFileRead)];
|
|
42280
42291
|
case 7:
|
|
42281
|
-
// 🆕 修复:路径在 message.message.paths
|
|
42292
|
+
// 🆕 修复:路径在 message.message.paths 中,使用配置的实时读取选项
|
|
42282
42293
|
result = _j.sent();
|
|
42283
42294
|
return [3 /*break*/, 27];
|
|
42284
42295
|
case 8: return [4 /*yield*/, this.applyChanges(message.changes)];
|
|
@@ -42387,9 +42398,10 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42387
42398
|
/**
|
|
42388
42399
|
* 2. 获取单个文件内容
|
|
42389
42400
|
*/
|
|
42390
|
-
ShadowSpaceCommandHandler.prototype.getFileContent = function (filePath) {
|
|
42401
|
+
ShadowSpaceCommandHandler.prototype.getFileContent = function (filePath, readRealtime) {
|
|
42402
|
+
if (readRealtime === void 0) { readRealtime = true; }
|
|
42391
42403
|
return __awaiter(this, void 0, void 0, function () {
|
|
42392
|
-
var normalizedPath, changes, change, fileContent,
|
|
42404
|
+
var normalizedPath, realTimeContent, result_1, readError_1, changes, change, fileContent, result_2, readError_2, result;
|
|
42393
42405
|
return __generator(this, function (_a) {
|
|
42394
42406
|
switch (_a.label) {
|
|
42395
42407
|
case 0:
|
|
@@ -42399,25 +42411,59 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42399
42411
|
normalizedPath = filePath.startsWith('/')
|
|
42400
42412
|
? filePath.substring(1)
|
|
42401
42413
|
: filePath;
|
|
42402
|
-
console.log("[ShadowSpace] \u83B7\u53D6\u6587\u4EF6\u5185\u5BB9: ".concat(filePath, " -> \u6807\u51C6\u5316\u4E3A: ").concat(normalizedPath));
|
|
42403
|
-
return [
|
|
42414
|
+
console.log("[ShadowSpace] \u83B7\u53D6\u6587\u4EF6\u5185\u5BB9: ".concat(filePath, " -> \u6807\u51C6\u5316\u4E3A: ").concat(normalizedPath, ", \u5B9E\u65F6\u8BFB\u53D6: ").concat(readRealtime));
|
|
42415
|
+
if (!readRealtime) return [3 /*break*/, 4];
|
|
42416
|
+
_a.label = 1;
|
|
42404
42417
|
case 1:
|
|
42418
|
+
_a.trys.push([1, 3, , 4]);
|
|
42419
|
+
return [4 /*yield*/, this.shadowSpace.readRealTimeFile(normalizedPath)];
|
|
42420
|
+
case 2:
|
|
42421
|
+
realTimeContent = _a.sent();
|
|
42422
|
+
if (realTimeContent !== null) {
|
|
42423
|
+
console.log("[ShadowSpace] \u6210\u529F\u8BFB\u53D6\u5B9E\u65F6\u6587\u4EF6: ".concat(normalizedPath));
|
|
42424
|
+
result_1 = {
|
|
42425
|
+
path: normalizedPath,
|
|
42426
|
+
action: 'read',
|
|
42427
|
+
version: 1,
|
|
42428
|
+
timestamp: Date.now(),
|
|
42429
|
+
diff: {
|
|
42430
|
+
before: '',
|
|
42431
|
+
after: realTimeContent,
|
|
42432
|
+
},
|
|
42433
|
+
metadata: {
|
|
42434
|
+
beforeSize: 0,
|
|
42435
|
+
afterSize: Buffer.byteLength(realTimeContent, 'utf8'),
|
|
42436
|
+
encoding: 'utf8',
|
|
42437
|
+
},
|
|
42438
|
+
};
|
|
42439
|
+
console.log("[ShadowSpace] \u5B9E\u65F6\u8BFB\u53D6\u6587\u4EF6\u6210\u529F: ".concat(normalizedPath, ", \u5927\u5C0F: ").concat(result_1.metadata.afterSize, " \u5B57\u8282"));
|
|
42440
|
+
return [2 /*return*/, result_1];
|
|
42441
|
+
}
|
|
42442
|
+
return [3 /*break*/, 4];
|
|
42443
|
+
case 3:
|
|
42444
|
+
readError_1 = _a.sent();
|
|
42445
|
+
console.warn("[ShadowSpace] \u5B9E\u65F6\u8BFB\u53D6\u5931\u8D25\uFF0C\u56DE\u9000\u5230\u7F13\u5B58: ".concat(normalizedPath), readError_1);
|
|
42446
|
+
return [3 /*break*/, 4];
|
|
42447
|
+
case 4: return [4 /*yield*/, this.shadowSpace.detectChanges()];
|
|
42448
|
+
case 5:
|
|
42405
42449
|
changes = _a.sent();
|
|
42406
42450
|
change = changes.find(function (c) { return c.path === normalizedPath; });
|
|
42407
|
-
|
|
42451
|
+
console.log('change: ', change);
|
|
42452
|
+
if (!change) return [3 /*break*/, 6];
|
|
42408
42453
|
console.log("[ShadowSpace] \u5728\u53D8\u66F4\u5217\u8868\u4E2D\u627E\u5230\u6587\u4EF6: ".concat(normalizedPath));
|
|
42409
|
-
return [3 /*break*/,
|
|
42410
|
-
case
|
|
42454
|
+
return [3 /*break*/, 11];
|
|
42455
|
+
case 6:
|
|
42411
42456
|
console.log("[ShadowSpace] \u6587\u4EF6\u4E0D\u5728\u53D8\u66F4\u5217\u8868\u4E2D\uFF0C\u5C1D\u8BD5\u76F4\u63A5\u4ECE\u5F71\u5B50\u7A7A\u95F4\u8BFB\u53D6: ".concat(normalizedPath));
|
|
42412
|
-
_a.label =
|
|
42413
|
-
case
|
|
42414
|
-
_a.trys.push([
|
|
42457
|
+
_a.label = 7;
|
|
42458
|
+
case 7:
|
|
42459
|
+
_a.trys.push([7, 9, , 10]);
|
|
42415
42460
|
return [4 /*yield*/, this.shadowSpace.readFile(normalizedPath)];
|
|
42416
|
-
case
|
|
42461
|
+
case 8:
|
|
42417
42462
|
fileContent = _a.sent();
|
|
42463
|
+
console.log('fileContent: ', fileContent);
|
|
42418
42464
|
if (fileContent !== null) {
|
|
42419
42465
|
console.log("[ShadowSpace] \u6210\u529F\u4ECE\u5F71\u5B50\u7A7A\u95F4\u8BFB\u53D6\u6587\u4EF6: ".concat(normalizedPath));
|
|
42420
|
-
|
|
42466
|
+
result_2 = {
|
|
42421
42467
|
path: normalizedPath,
|
|
42422
42468
|
action: 'read',
|
|
42423
42469
|
version: 1,
|
|
@@ -42432,19 +42478,19 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42432
42478
|
encoding: 'utf8',
|
|
42433
42479
|
},
|
|
42434
42480
|
};
|
|
42435
|
-
console.log("[ShadowSpace] \u76F4\u63A5\u8BFB\u53D6\u6587\u4EF6\u6210\u529F: ".concat(normalizedPath, ", \u5927\u5C0F: ").concat(
|
|
42436
|
-
return [2 /*return*/,
|
|
42481
|
+
console.log("[ShadowSpace] \u76F4\u63A5\u8BFB\u53D6\u6587\u4EF6\u6210\u529F: ".concat(normalizedPath, ", \u5927\u5C0F: ").concat(result_2.metadata.afterSize, " \u5B57\u8282"));
|
|
42482
|
+
return [2 /*return*/, result_2];
|
|
42437
42483
|
}
|
|
42438
|
-
return [3 /*break*/,
|
|
42439
|
-
case
|
|
42440
|
-
|
|
42441
|
-
console.error("[ShadowSpace] \u76F4\u63A5\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25: ".concat(normalizedPath),
|
|
42442
|
-
return [3 /*break*/,
|
|
42443
|
-
case
|
|
42484
|
+
return [3 /*break*/, 10];
|
|
42485
|
+
case 9:
|
|
42486
|
+
readError_2 = _a.sent();
|
|
42487
|
+
console.error("[ShadowSpace] \u76F4\u63A5\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25: ".concat(normalizedPath), readError_2);
|
|
42488
|
+
return [3 /*break*/, 10];
|
|
42489
|
+
case 10:
|
|
42444
42490
|
// 如果都失败了,抛出错误
|
|
42445
42491
|
console.error("[ShadowSpace] \u83B7\u53D6\u6587\u4EF6\u5185\u5BB9\u5931\u8D25: \u6587\u4EF6\u672A\u627E\u5230: ".concat(normalizedPath));
|
|
42446
42492
|
throw new Error("File not found in shadow space: ".concat(normalizedPath));
|
|
42447
|
-
case
|
|
42493
|
+
case 11:
|
|
42448
42494
|
result = {
|
|
42449
42495
|
path: normalizedPath,
|
|
42450
42496
|
action: change.action,
|
|
@@ -42473,9 +42519,10 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42473
42519
|
/**
|
|
42474
42520
|
* 3. 批量获取文件内容
|
|
42475
42521
|
*/
|
|
42476
|
-
ShadowSpaceCommandHandler.prototype.getFilesContent = function (filePaths) {
|
|
42522
|
+
ShadowSpaceCommandHandler.prototype.getFilesContent = function (filePaths, readRealtime) {
|
|
42523
|
+
if (readRealtime === void 0) { readRealtime = true; }
|
|
42477
42524
|
return __awaiter(this, void 0, void 0, function () {
|
|
42478
|
-
var
|
|
42525
|
+
var results, filePaths_1, filePaths_1_1, filePath, normalizedPath, realTimeContent, shadowContent, error_2, e_1_1, result;
|
|
42479
42526
|
var e_1, _a;
|
|
42480
42527
|
return __generator(this, function (_b) {
|
|
42481
42528
|
switch (_b.label) {
|
|
@@ -42483,48 +42530,79 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42483
42530
|
if (!Array.isArray(filePaths) || filePaths.length === 0) {
|
|
42484
42531
|
throw new Error('File paths array is required');
|
|
42485
42532
|
}
|
|
42486
|
-
console.log("[ShadowSpace] \u6279\u91CF\u83B7\u53D6\u6587\u4EF6\u5185\u5BB9: ".concat(filePaths.length, " \u4E2A\u6587\u4EF6"));
|
|
42487
|
-
console.log("[ShadowSpace] \u6279\u91CF\u83B7\u53D6\u6587\u4EF6\u8DEF\u5F84:", filePaths.slice(0, 5)); // 显示前5个路径
|
|
42488
|
-
return [4 /*yield*/, this.shadowSpace.detectChanges()];
|
|
42489
|
-
case 1:
|
|
42490
|
-
changes = _b.sent();
|
|
42533
|
+
console.log("[ShadowSpace] \u6279\u91CF\u83B7\u53D6\u6587\u4EF6\u5185\u5BB9: ".concat(filePaths.length, " \u4E2A\u6587\u4EF6, \u5B9E\u65F6\u8BFB\u53D6: ").concat(readRealtime));
|
|
42491
42534
|
results = [];
|
|
42492
|
-
|
|
42493
|
-
|
|
42494
|
-
|
|
42495
|
-
|
|
42496
|
-
|
|
42497
|
-
|
|
42498
|
-
|
|
42499
|
-
|
|
42500
|
-
|
|
42501
|
-
|
|
42502
|
-
|
|
42503
|
-
|
|
42504
|
-
|
|
42505
|
-
|
|
42506
|
-
|
|
42507
|
-
|
|
42508
|
-
|
|
42509
|
-
|
|
42510
|
-
|
|
42511
|
-
|
|
42512
|
-
|
|
42513
|
-
|
|
42514
|
-
|
|
42515
|
-
|
|
42516
|
-
|
|
42517
|
-
|
|
42518
|
-
|
|
42519
|
-
|
|
42535
|
+
_b.label = 1;
|
|
42536
|
+
case 1:
|
|
42537
|
+
_b.trys.push([1, 10, 11, 12]);
|
|
42538
|
+
filePaths_1 = __values(filePaths), filePaths_1_1 = filePaths_1.next();
|
|
42539
|
+
_b.label = 2;
|
|
42540
|
+
case 2:
|
|
42541
|
+
if (!!filePaths_1_1.done) return [3 /*break*/, 9];
|
|
42542
|
+
filePath = filePaths_1_1.value;
|
|
42543
|
+
normalizedPath = filePath.startsWith('/')
|
|
42544
|
+
? filePath.substring(1)
|
|
42545
|
+
: filePath;
|
|
42546
|
+
console.log("[ShadowSpace] \u6279\u91CF\u5904\u7406: ".concat(filePath, " -> ").concat(normalizedPath));
|
|
42547
|
+
_b.label = 3;
|
|
42548
|
+
case 3:
|
|
42549
|
+
_b.trys.push([3, 7, , 8]);
|
|
42550
|
+
if (!readRealtime) return [3 /*break*/, 5];
|
|
42551
|
+
return [4 /*yield*/, this.shadowSpace.readRealTimeFile(normalizedPath)];
|
|
42552
|
+
case 4:
|
|
42553
|
+
realTimeContent = _b.sent();
|
|
42554
|
+
if (realTimeContent !== null) {
|
|
42555
|
+
results.push({
|
|
42556
|
+
path: normalizedPath,
|
|
42557
|
+
action: 'read',
|
|
42558
|
+
version: 1,
|
|
42559
|
+
timestamp: Date.now(),
|
|
42560
|
+
diff: {
|
|
42561
|
+
before: '',
|
|
42562
|
+
after: realTimeContent,
|
|
42563
|
+
},
|
|
42564
|
+
});
|
|
42565
|
+
return [3 /*break*/, 8];
|
|
42520
42566
|
}
|
|
42521
|
-
|
|
42522
|
-
|
|
42523
|
-
|
|
42524
|
-
|
|
42525
|
-
|
|
42526
|
-
|
|
42567
|
+
_b.label = 5;
|
|
42568
|
+
case 5: return [4 /*yield*/, this.shadowSpace.readFile(normalizedPath)];
|
|
42569
|
+
case 6:
|
|
42570
|
+
shadowContent = _b.sent();
|
|
42571
|
+
if (shadowContent !== null) {
|
|
42572
|
+
results.push({
|
|
42573
|
+
path: normalizedPath,
|
|
42574
|
+
action: 'read',
|
|
42575
|
+
version: 1,
|
|
42576
|
+
timestamp: Date.now(),
|
|
42577
|
+
diff: {
|
|
42578
|
+
before: '',
|
|
42579
|
+
after: shadowContent,
|
|
42580
|
+
},
|
|
42581
|
+
});
|
|
42527
42582
|
}
|
|
42583
|
+
else {
|
|
42584
|
+
console.warn("[ShadowSpace] \u6279\u91CF\u83B7\u53D6\u4E2D\u672A\u627E\u5230\u6587\u4EF6: ".concat(normalizedPath));
|
|
42585
|
+
}
|
|
42586
|
+
return [3 /*break*/, 8];
|
|
42587
|
+
case 7:
|
|
42588
|
+
error_2 = _b.sent();
|
|
42589
|
+
console.warn("[ShadowSpace] \u6279\u91CF\u8BFB\u53D6\u6587\u4EF6\u5931\u8D25: ".concat(normalizedPath), error_2);
|
|
42590
|
+
return [3 /*break*/, 8];
|
|
42591
|
+
case 8:
|
|
42592
|
+
filePaths_1_1 = filePaths_1.next();
|
|
42593
|
+
return [3 /*break*/, 2];
|
|
42594
|
+
case 9: return [3 /*break*/, 12];
|
|
42595
|
+
case 10:
|
|
42596
|
+
e_1_1 = _b.sent();
|
|
42597
|
+
e_1 = { error: e_1_1 };
|
|
42598
|
+
return [3 /*break*/, 12];
|
|
42599
|
+
case 11:
|
|
42600
|
+
try {
|
|
42601
|
+
if (filePaths_1_1 && !filePaths_1_1.done && (_a = filePaths_1.return)) _a.call(filePaths_1);
|
|
42602
|
+
}
|
|
42603
|
+
finally { if (e_1) throw e_1.error; }
|
|
42604
|
+
return [7 /*endfinally*/];
|
|
42605
|
+
case 12:
|
|
42528
42606
|
result = {
|
|
42529
42607
|
files: results,
|
|
42530
42608
|
requestedCount: filePaths.length,
|
|
@@ -42652,9 +42730,9 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42652
42730
|
}
|
|
42653
42731
|
console.log("[ShadowSpace] \u5220\u9664\u6587\u4EF6: ".concat(filePath));
|
|
42654
42732
|
allFiles = this.shadowSpace.getAllFilePaths();
|
|
42655
|
-
console.log(
|
|
42733
|
+
console.log('[ShadowSpace] 当前影子空间中的文件: ', allFiles);
|
|
42656
42734
|
console.log("[ShadowSpace] \u8981\u5220\u9664\u7684\u6587\u4EF6\u8DEF\u5F84: \"".concat(filePath, "\""));
|
|
42657
|
-
console.log(
|
|
42735
|
+
console.log('[ShadowSpace] 文件是否存在:', this.shadowSpace.hasFile(filePath) ? '是' : '否');
|
|
42658
42736
|
return [4 /*yield*/, this.shadowSpace.deleteFile(filePath)];
|
|
42659
42737
|
case 1:
|
|
42660
42738
|
deleted = _a.sent();
|
|
@@ -42810,7 +42888,7 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42810
42888
|
*/
|
|
42811
42889
|
ShadowSpaceCommandHandler.prototype.detectEditorChanges = function (spaceId, editorSnapshots) {
|
|
42812
42890
|
return __awaiter(this, void 0, void 0, function () {
|
|
42813
|
-
var safeEditorSnapshots, spaceSnapshots, changes, summary,
|
|
42891
|
+
var safeEditorSnapshots, spaceSnapshots, changes, summary, error_3;
|
|
42814
42892
|
return __generator(this, function (_a) {
|
|
42815
42893
|
switch (_a.label) {
|
|
42816
42894
|
case 0:
|
|
@@ -42846,11 +42924,11 @@ var ShadowSpaceCommandHandler = /** @class */ (function () {
|
|
|
42846
42924
|
},
|
|
42847
42925
|
}];
|
|
42848
42926
|
case 3:
|
|
42849
|
-
|
|
42850
|
-
console.error("[ShadowSpace] \u68C0\u6D4B\u53D8\u66F4\u5931\u8D25:",
|
|
42927
|
+
error_3 = _a.sent();
|
|
42928
|
+
console.error("[ShadowSpace] \u68C0\u6D4B\u53D8\u66F4\u5931\u8D25:", error_3);
|
|
42851
42929
|
return [2 /*return*/, {
|
|
42852
42930
|
success: false,
|
|
42853
|
-
error:
|
|
42931
|
+
error: error_3 instanceof Error ? error_3.message : '检测变更失败',
|
|
42854
42932
|
}];
|
|
42855
42933
|
case 4: return [2 /*return*/];
|
|
42856
42934
|
}
|
|
@@ -47578,186 +47656,411 @@ function executeShadowSpaceDebug(options) {
|
|
|
47578
47656
|
});
|
|
47579
47657
|
}
|
|
47580
47658
|
|
|
47581
|
-
|
|
47582
|
-
|
|
47659
|
+
/**
|
|
47660
|
+
* 统一的TSX/JSX验证器
|
|
47661
|
+
* 同时支持CLI和编辑器使用
|
|
47662
|
+
*/
|
|
47663
|
+
var UnifiedTSXValidator = /** @class */ (function () {
|
|
47664
|
+
function UnifiedTSXValidator(debug) {
|
|
47665
|
+
if (debug === void 0) { debug = false; }
|
|
47666
|
+
this.debug = false;
|
|
47667
|
+
this.debug = debug;
|
|
47583
47668
|
}
|
|
47584
47669
|
/**
|
|
47585
|
-
*
|
|
47670
|
+
* 验证TSX文件内容
|
|
47586
47671
|
*/
|
|
47587
|
-
|
|
47672
|
+
UnifiedTSXValidator.prototype.validate = function (content, filename) {
|
|
47673
|
+
var _this = this;
|
|
47674
|
+
if (filename === void 0) { filename = 'unknown.tsx'; }
|
|
47675
|
+
this.content = content;
|
|
47676
|
+
this.filename = filename;
|
|
47588
47677
|
var issues = [];
|
|
47589
47678
|
try {
|
|
47590
|
-
|
|
47591
|
-
var ast = parser$1.parse(content, {
|
|
47679
|
+
var ast_1 = parser$1.parse(content, {
|
|
47592
47680
|
sourceType: 'module',
|
|
47593
47681
|
plugins: ['jsx', 'typescript', 'decorators-legacy', 'classProperties'],
|
|
47594
47682
|
errorRecovery: true,
|
|
47683
|
+
allowReturnOutsideFunction: true,
|
|
47595
47684
|
});
|
|
47596
|
-
|
|
47597
|
-
|
|
47598
|
-
|
|
47599
|
-
|
|
47600
|
-
|
|
47601
|
-
|
|
47602
|
-
|
|
47603
|
-
|
|
47604
|
-
|
|
47605
|
-
|
|
47606
|
-
|
|
47607
|
-
|
|
47608
|
-
|
|
47609
|
-
|
|
47610
|
-
|
|
47611
|
-
|
|
47612
|
-
|
|
47613
|
-
},
|
|
47614
|
-
});
|
|
47615
|
-
// 检查必需的结构
|
|
47616
|
-
this.checkRequiredStructures(ast, content, issues);
|
|
47685
|
+
this.log('AST解析完成');
|
|
47686
|
+
// 执行所有检查,每个检查都包装在try-catch中
|
|
47687
|
+
this.safeCheck('checkFileStructure', function () { return _this.checkFileStructure(ast_1, issues); });
|
|
47688
|
+
this.safeCheck('checkComponentDefinition', function () { return _this.checkComponentDefinition(ast_1, issues); });
|
|
47689
|
+
this.safeCheck('checkRenderMethod', function () { return _this.checkRenderMethod(ast_1, issues); });
|
|
47690
|
+
this.safeCheck('checkVariableDeclarations', function () { return _this.checkVariableDeclarations(ast_1, issues); });
|
|
47691
|
+
this.safeCheck('checkConditionalRendering', function () { return _this.checkConditionalRendering(ast_1, issues); });
|
|
47692
|
+
this.safeCheck('checkListRendering', function () { return _this.checkListRendering(ast_1, issues); });
|
|
47693
|
+
this.safeCheck('checkStyleUsage', function () { return _this.checkStyleUsage(ast_1, issues); });
|
|
47694
|
+
this.safeCheck('checkStateManagement', function () { return _this.checkStateManagement(ast_1, issues); });
|
|
47695
|
+
this.safeCheck('checkDataSourceUsage', function () { return _this.checkDataSourceUsage(ast_1, issues); });
|
|
47696
|
+
this.safeCheck('checkTypeScriptSyntaxInMethods', function () { return _this.checkTypeScriptSyntaxInMethods(ast_1, issues); });
|
|
47697
|
+
this.log("\u68C0\u67E5\u5B8C\u6210\uFF0C\u53D1\u73B0 ".concat(issues.length, " \u4E2A\u95EE\u9898"));
|
|
47698
|
+
return {
|
|
47699
|
+
isCompliant: issues.filter(function (issue) { return issue.type === 'error'; }).length === 0,
|
|
47700
|
+
issues: issues,
|
|
47701
|
+
};
|
|
47617
47702
|
}
|
|
47618
47703
|
catch (error) {
|
|
47619
|
-
|
|
47620
|
-
|
|
47621
|
-
|
|
47622
|
-
|
|
47623
|
-
|
|
47624
|
-
|
|
47704
|
+
this.log("\u89E3\u6790\u9519\u8BEF: ".concat(error.message));
|
|
47705
|
+
return {
|
|
47706
|
+
isCompliant: false,
|
|
47707
|
+
issues: [{
|
|
47708
|
+
type: 'error',
|
|
47709
|
+
code: 'PARSE_ERROR',
|
|
47710
|
+
message: "\u4EE3\u7801\u89E3\u6790\u5931\u8D25: ".concat(error.message),
|
|
47711
|
+
suggestion: '检查代码语法是否正确',
|
|
47712
|
+
line: 1,
|
|
47713
|
+
column: 0,
|
|
47714
|
+
}],
|
|
47715
|
+
};
|
|
47625
47716
|
}
|
|
47626
|
-
return {
|
|
47627
|
-
isCompliant: issues.filter(function (issue) { return issue.type === 'error'; }).length === 0,
|
|
47628
|
-
issues: issues,
|
|
47629
|
-
};
|
|
47630
47717
|
};
|
|
47631
47718
|
/**
|
|
47632
|
-
*
|
|
47719
|
+
* 检查文件结构
|
|
47633
47720
|
*/
|
|
47634
|
-
|
|
47635
|
-
|
|
47636
|
-
|
|
47637
|
-
var
|
|
47638
|
-
|
|
47639
|
-
|
|
47640
|
-
|
|
47721
|
+
UnifiedTSXValidator.prototype.checkFileStructure = function (ast, issues) {
|
|
47722
|
+
var _this = this;
|
|
47723
|
+
this.log('开始检查文件结构');
|
|
47724
|
+
var hasReactComponent = false;
|
|
47725
|
+
traverse__default["default"](ast, {
|
|
47726
|
+
ClassDeclaration: function (path) {
|
|
47727
|
+
var _a;
|
|
47728
|
+
var className = (_a = path.node.id) === null || _a === void 0 ? void 0 : _a.name;
|
|
47729
|
+
_this.log("\u53D1\u73B0\u7C7B: ".concat(className));
|
|
47730
|
+
// 检查是否有继承自React.Component的类(支持 extends Component 和 extends React.Component)
|
|
47731
|
+
if (_this.isReactComponent(path.node.superClass)) {
|
|
47732
|
+
hasReactComponent = true;
|
|
47733
|
+
_this.log("\u53D1\u73B0React\u7EC4\u4EF6\u7C7B: ".concat(className));
|
|
47734
|
+
}
|
|
47735
|
+
},
|
|
47641
47736
|
});
|
|
47642
|
-
|
|
47643
|
-
|
|
47644
|
-
|
|
47645
|
-
var isInEventHandler = this.isInEventHandler(path);
|
|
47646
|
-
if (isInEventHandler)
|
|
47647
|
-
return;
|
|
47648
|
-
// 检查是否在非 JSX 返回的回调函数中
|
|
47649
|
-
var isInNonJSXCallback = this.isInNonJSXCallback(path);
|
|
47650
|
-
if (isInNonJSXCallback)
|
|
47651
|
-
return;
|
|
47652
|
-
// 检查是否在返回 JSX 的回调函数中(如 .map())
|
|
47653
|
-
var isInJSXCallback = this.isInJSXCallback(path);
|
|
47654
|
-
if (isInJSXCallback) {
|
|
47655
|
-
// 这种情况需要报错
|
|
47656
|
-
var _a = this.getLocation(path, content), line_1 = _a.line, column_1 = _a.column;
|
|
47657
|
-
var snippet_1 = this.extractCodeSnippet(content, line_1);
|
|
47658
|
-
issues.push({
|
|
47659
|
-
type: 'error',
|
|
47660
|
-
code: 'CALLBACK_VARIABLE_DECLARATION',
|
|
47661
|
-
message: '返回 JSX 的回调函数中不能包含变量声明',
|
|
47662
|
-
suggestion: '将变量声明移到回调函数外部,或使用内联表达式',
|
|
47663
|
-
line: line_1,
|
|
47664
|
-
column: column_1,
|
|
47665
|
-
codeSnippet: snippet_1.snippet,
|
|
47666
|
-
snippetStartLine: snippet_1.startLine,
|
|
47667
|
-
snippetEndLine: snippet_1.endLine,
|
|
47668
|
-
});
|
|
47669
|
-
return;
|
|
47737
|
+
// 不再强制要求Document类,只要有React组件类即可
|
|
47738
|
+
if (!hasReactComponent) {
|
|
47739
|
+
issues.push(this.createIssue('MISSING_REACT_COMPONENT', 'error', '缺少React组件类定义,必须定义一个继承自React.Component的类', '请定义组件类,如: class MyComponent extends React.Component 或 class MyComponent extends Component', 1));
|
|
47670
47740
|
}
|
|
47671
|
-
|
|
47672
|
-
|
|
47673
|
-
|
|
47674
|
-
|
|
47675
|
-
|
|
47676
|
-
|
|
47677
|
-
|
|
47678
|
-
|
|
47679
|
-
|
|
47680
|
-
|
|
47681
|
-
|
|
47682
|
-
|
|
47683
|
-
|
|
47741
|
+
};
|
|
47742
|
+
/**
|
|
47743
|
+
* 检查组件定义
|
|
47744
|
+
*/
|
|
47745
|
+
UnifiedTSXValidator.prototype.checkComponentDefinition = function (ast, issues) {
|
|
47746
|
+
var _this = this;
|
|
47747
|
+
this.log('开始检查组件定义');
|
|
47748
|
+
traverse__default["default"](ast, {
|
|
47749
|
+
ClassDeclaration: function (path) {
|
|
47750
|
+
var e_1, _a;
|
|
47751
|
+
var _b;
|
|
47752
|
+
// 检查所有继承自React.Component的类
|
|
47753
|
+
if (_this.isReactComponent(path.node.superClass)) {
|
|
47754
|
+
var className = (_b = path.node.id) === null || _b === void 0 ? void 0 : _b.name;
|
|
47755
|
+
_this.log("\u68C0\u67E5React\u7EC4\u4EF6\u7C7B: ".concat(className));
|
|
47756
|
+
// 检查render方法
|
|
47757
|
+
var hasRender = false;
|
|
47758
|
+
try {
|
|
47759
|
+
for (var _c = __values(path.node.body.body), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
47760
|
+
var member = _d.value;
|
|
47761
|
+
if (member.type === 'ClassMethod' && member.key.name === 'render') {
|
|
47762
|
+
hasRender = true;
|
|
47763
|
+
}
|
|
47764
|
+
// 检查constructor
|
|
47765
|
+
if (member.type === 'ClassMethod' && member.key.name === 'constructor') {
|
|
47766
|
+
issues.push(_this.createIssueFromNode('CONSTRUCTOR_NOT_ALLOWED', 'error', "".concat(className, "\u7C7B\u4E2D\u4E0D\u5141\u8BB8\u4F7F\u7528constructor"), '请使用state属性直接定义状态,使用componentDidMount进行初始化', member));
|
|
47767
|
+
}
|
|
47768
|
+
}
|
|
47769
|
+
}
|
|
47770
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
47771
|
+
finally {
|
|
47772
|
+
try {
|
|
47773
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
47774
|
+
}
|
|
47775
|
+
finally { if (e_1) throw e_1.error; }
|
|
47776
|
+
}
|
|
47777
|
+
// 移除对state属性的强制检查,React组件可以不定义state
|
|
47778
|
+
if (!hasRender) {
|
|
47779
|
+
issues.push(_this.createIssueFromNode('MISSING_RENDER_METHOD', 'error', "".concat(className, "\u7C7B\u5FC5\u987B\u5B9A\u4E49render\u65B9\u6CD5"), '请添加: render() { return <View>...</View> }', path.node));
|
|
47780
|
+
}
|
|
47781
|
+
}
|
|
47782
|
+
},
|
|
47684
47783
|
});
|
|
47685
47784
|
};
|
|
47686
47785
|
/**
|
|
47687
|
-
*
|
|
47786
|
+
* 检查render方法
|
|
47688
47787
|
*/
|
|
47689
|
-
|
|
47690
|
-
|
|
47788
|
+
UnifiedTSXValidator.prototype.checkRenderMethod = function (ast, issues) {
|
|
47789
|
+
var _this = this;
|
|
47790
|
+
this.log('开始检查render方法');
|
|
47791
|
+
traverse__default["default"](ast, {
|
|
47792
|
+
ClassMethod: function (path) {
|
|
47793
|
+
var e_2, _a, e_3, _b;
|
|
47794
|
+
if (path.node.key.name === 'render') {
|
|
47795
|
+
var body = path.node.body.body;
|
|
47796
|
+
try {
|
|
47797
|
+
// 检查变量声明
|
|
47798
|
+
for (var body_1 = __values(body), body_1_1 = body_1.next(); !body_1_1.done; body_1_1 = body_1.next()) {
|
|
47799
|
+
var statement = body_1_1.value;
|
|
47800
|
+
if (statement.type === 'VariableDeclaration') {
|
|
47801
|
+
// 检查是否在事件处理函数中
|
|
47802
|
+
if (!_this.isInEventHandler(path)) {
|
|
47803
|
+
issues.push(_this.createIssueFromNode('RENDER_VARIABLE_DECLARATION', 'error', 'render方法中不允许声明变量', '直接使用this.state访问状态', statement));
|
|
47804
|
+
}
|
|
47805
|
+
}
|
|
47806
|
+
// 检查函数声明
|
|
47807
|
+
if (statement.type === 'FunctionDeclaration') {
|
|
47808
|
+
issues.push(_this.createIssueFromNode('RENDER_FUNCTION_DECLARATION', 'error', 'render方法中不允许声明函数', '将函数声明移到render方法外部', statement));
|
|
47809
|
+
}
|
|
47810
|
+
// 检查if语句
|
|
47811
|
+
if (statement.type === 'IfStatement') {
|
|
47812
|
+
issues.push(_this.createIssueFromNode('RENDER_IF_STATEMENT', 'error', 'render方法中不允许使用if语句进行条件渲染', '请使用JSX中的条件渲染语法 {condition && <View>}', statement));
|
|
47813
|
+
}
|
|
47814
|
+
}
|
|
47815
|
+
}
|
|
47816
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
47817
|
+
finally {
|
|
47818
|
+
try {
|
|
47819
|
+
if (body_1_1 && !body_1_1.done && (_a = body_1.return)) _a.call(body_1);
|
|
47820
|
+
}
|
|
47821
|
+
finally { if (e_2) throw e_2.error; }
|
|
47822
|
+
}
|
|
47823
|
+
// 检查是否有return语句
|
|
47824
|
+
var hasReturn = false;
|
|
47825
|
+
try {
|
|
47826
|
+
for (var body_2 = __values(body), body_2_1 = body_2.next(); !body_2_1.done; body_2_1 = body_2.next()) {
|
|
47827
|
+
var statement = body_2_1.value;
|
|
47828
|
+
if (statement.type === 'ReturnStatement') {
|
|
47829
|
+
hasReturn = true;
|
|
47830
|
+
break;
|
|
47831
|
+
}
|
|
47832
|
+
}
|
|
47833
|
+
}
|
|
47834
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
47835
|
+
finally {
|
|
47836
|
+
try {
|
|
47837
|
+
if (body_2_1 && !body_2_1.done && (_b = body_2.return)) _b.call(body_2);
|
|
47838
|
+
}
|
|
47839
|
+
finally { if (e_3) throw e_3.error; }
|
|
47840
|
+
}
|
|
47841
|
+
if (!hasReturn) {
|
|
47842
|
+
issues.push(_this.createIssueFromNode('MISSING_RETURN', 'error', 'render方法必须返回JSX元素', '请在render方法末尾添加return语句', path.node));
|
|
47843
|
+
}
|
|
47844
|
+
}
|
|
47845
|
+
},
|
|
47846
|
+
});
|
|
47847
|
+
};
|
|
47848
|
+
/**
|
|
47849
|
+
* 检查变量声明 - 兼容TSXComplianceChecker的逻辑
|
|
47850
|
+
*/
|
|
47851
|
+
UnifiedTSXValidator.prototype.checkVariableDeclarations = function (ast, issues) {
|
|
47852
|
+
var _this = this;
|
|
47853
|
+
this.log('开始检查变量声明');
|
|
47854
|
+
traverse__default["default"](ast, {
|
|
47855
|
+
VariableDeclarator: function (path) {
|
|
47856
|
+
// 检查是否在 render 方法中
|
|
47857
|
+
var renderMethod = path.findParent(function (p) {
|
|
47858
|
+
return p.isClassMethod() &&
|
|
47859
|
+
t__namespace.isIdentifier(p.node.key) &&
|
|
47860
|
+
p.node.key.name === 'render';
|
|
47861
|
+
});
|
|
47862
|
+
if (!renderMethod)
|
|
47863
|
+
return;
|
|
47864
|
+
// 检查是否在事件处理函数中
|
|
47865
|
+
if (_this.isInEventHandler(path))
|
|
47866
|
+
return;
|
|
47867
|
+
// 检查是否在非JSX回调函数中
|
|
47868
|
+
if (_this.isInNonJSXCallback(path))
|
|
47869
|
+
return;
|
|
47870
|
+
// 检查是否在返回JSX的回调函数中
|
|
47871
|
+
if (_this.isInJSXCallback(path)) {
|
|
47872
|
+
issues.push(_this.createIssueFromNode('CALLBACK_VARIABLE_DECLARATION', 'error', '返回JSX的回调函数中不能包含变量声明', '将变量声明移到回调函数外部,或使用内联表达式', path.node));
|
|
47873
|
+
return;
|
|
47874
|
+
}
|
|
47875
|
+
// 其他在render方法中的变量声明都是错误的
|
|
47876
|
+
issues.push(_this.createIssueFromNode('RENDER_VARIABLE_DECLARATION', 'error', 'render()方法中不能包含变量声明', '移除所有const/let/var声明,直接使用this.state.xxx', path.node));
|
|
47877
|
+
},
|
|
47878
|
+
});
|
|
47879
|
+
};
|
|
47880
|
+
/**
|
|
47881
|
+
* 检查条件渲染
|
|
47882
|
+
*/
|
|
47883
|
+
UnifiedTSXValidator.prototype.checkConditionalRendering = function (ast, issues) {
|
|
47884
|
+
var _this = this;
|
|
47885
|
+
this.log('开始检查条件渲染');
|
|
47886
|
+
traverse__default["default"](ast, {
|
|
47887
|
+
JSXExpressionContainer: function (path) {
|
|
47888
|
+
var expression = path.node.expression;
|
|
47889
|
+
if (expression.type === 'LogicalExpression') {
|
|
47890
|
+
// 检查右侧是否包含JSX元素
|
|
47891
|
+
var hasJSXInRight = _this.hasJSXInNode(expression.right);
|
|
47892
|
+
if (hasJSXInRight && expression.operator !== '&&') {
|
|
47893
|
+
issues.push(_this.createIssueFromNode('INVALID_CONDITIONAL_OPERATOR', 'error', '条件渲染必须使用&&运算符,不支持其他运算符', '请使用 && 运算符进行条件渲染', path.node));
|
|
47894
|
+
}
|
|
47895
|
+
if (hasJSXInRight && expression.left.type === 'Identifier') {
|
|
47896
|
+
issues.push(_this.createIssueFromNode('VARIABLE_IN_CONDITIONAL', 'error', '条件渲染中不允许使用变量', '请直接使用this.state访问状态', path.node));
|
|
47897
|
+
}
|
|
47898
|
+
}
|
|
47899
|
+
},
|
|
47900
|
+
});
|
|
47901
|
+
};
|
|
47902
|
+
/**
|
|
47903
|
+
* 检查列表渲染
|
|
47904
|
+
*/
|
|
47905
|
+
UnifiedTSXValidator.prototype.checkListRendering = function (ast, issues) {
|
|
47906
|
+
var _this = this;
|
|
47907
|
+
this.log('开始检查列表渲染');
|
|
47908
|
+
traverse__default["default"](ast, {
|
|
47909
|
+
CallExpression: function (path) {
|
|
47910
|
+
if (path.node.callee.type === 'MemberExpression' &&
|
|
47911
|
+
path.node.callee.property.name === 'map') {
|
|
47912
|
+
// 检查是否在render方法的JSX中使用
|
|
47913
|
+
if (_this.isInRenderJSX(path)) {
|
|
47914
|
+
var parent_1 = path.parentPath;
|
|
47915
|
+
if (parent_1.node.type === 'VariableDeclaration') {
|
|
47916
|
+
issues.push(_this.createIssueFromNode('LIST_RENDER_VARIABLE', 'error', '列表渲染中不允许使用变量', '请直接使用map方法渲染', path.node));
|
|
47917
|
+
}
|
|
47918
|
+
}
|
|
47919
|
+
}
|
|
47920
|
+
},
|
|
47921
|
+
});
|
|
47922
|
+
};
|
|
47923
|
+
/**
|
|
47924
|
+
* 检查样式使用
|
|
47925
|
+
*/
|
|
47926
|
+
UnifiedTSXValidator.prototype.checkStyleUsage = function (ast, issues) {
|
|
47927
|
+
var _this = this;
|
|
47928
|
+
this.log('开始检查样式使用');
|
|
47929
|
+
traverse__default["default"](ast, {
|
|
47930
|
+
JSXAttribute: function (path) {
|
|
47931
|
+
var _a;
|
|
47932
|
+
if (path.node.name.name === 'inlineStyle') {
|
|
47933
|
+
var parent_2 = path.parentPath.node;
|
|
47934
|
+
var componentName = (_a = parent_2.name) === null || _a === void 0 ? void 0 : _a.name;
|
|
47935
|
+
if (componentName !== 'View' && componentName !== 'Text') {
|
|
47936
|
+
issues.push(_this.createIssueFromNode('INVALID_INLINE_STYLE', 'error', 'inlineStyle属性仅支持View和Text组件使用', '请检查组件类型或使用其他样式属性', path.node));
|
|
47937
|
+
}
|
|
47938
|
+
}
|
|
47939
|
+
},
|
|
47940
|
+
});
|
|
47941
|
+
};
|
|
47942
|
+
/**
|
|
47943
|
+
* 检查状态管理
|
|
47944
|
+
*/
|
|
47945
|
+
UnifiedTSXValidator.prototype.checkStateManagement = function (ast, issues) {
|
|
47946
|
+
var _this = this;
|
|
47947
|
+
this.log('开始检查状态管理');
|
|
47948
|
+
traverse__default["default"](ast, {
|
|
47949
|
+
AssignmentExpression: function (path) {
|
|
47950
|
+
if (_this.isDirectStateMutation(path.node.left)) {
|
|
47951
|
+
issues.push(_this.createIssueFromNode('DIRECT_STATE_MUTATION', 'error', '不允许直接修改state', '请使用this.setState方法', path.node));
|
|
47952
|
+
}
|
|
47953
|
+
},
|
|
47954
|
+
});
|
|
47955
|
+
};
|
|
47956
|
+
/**
|
|
47957
|
+
* 检查数据源使用
|
|
47958
|
+
*/
|
|
47959
|
+
UnifiedTSXValidator.prototype.checkDataSourceUsage = function (ast, issues) {
|
|
47960
|
+
var _this = this;
|
|
47961
|
+
this.log('开始检查数据源使用');
|
|
47962
|
+
traverse__default["default"](ast, {
|
|
47963
|
+
CallExpression: function (path) {
|
|
47964
|
+
var _a;
|
|
47965
|
+
if (_this.isDataSourceLoadCall(path.node)) {
|
|
47966
|
+
var isInRender = false;
|
|
47967
|
+
var isInCallback = false;
|
|
47968
|
+
var currentPath = path;
|
|
47969
|
+
while (currentPath) {
|
|
47970
|
+
var node = currentPath.node;
|
|
47971
|
+
if (node.type === 'ClassMethod' && ((_a = node.key) === null || _a === void 0 ? void 0 : _a.name) === 'render') {
|
|
47972
|
+
isInRender = true;
|
|
47973
|
+
}
|
|
47974
|
+
if ((node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression')) {
|
|
47975
|
+
var parentPath = currentPath.parentPath;
|
|
47976
|
+
if ((parentPath === null || parentPath === void 0 ? void 0 : parentPath.node.type) === 'JSXExpressionContainer') {
|
|
47977
|
+
isInCallback = true;
|
|
47978
|
+
break;
|
|
47979
|
+
}
|
|
47980
|
+
}
|
|
47981
|
+
currentPath = currentPath.parentPath;
|
|
47982
|
+
}
|
|
47983
|
+
if (isInRender && !isInCallback) {
|
|
47984
|
+
issues.push(_this.createIssueFromNode('DATA_SOURCE_IN_RENDER', 'error', 'render方法中不允许直接调用数据源', '请在回调函数中调用数据源', path.node));
|
|
47985
|
+
}
|
|
47986
|
+
}
|
|
47987
|
+
},
|
|
47988
|
+
});
|
|
47989
|
+
};
|
|
47990
|
+
// ========== 辅助方法 ==========
|
|
47991
|
+
UnifiedTSXValidator.prototype.isReactComponent = function (superClass) {
|
|
47992
|
+
if (!superClass)
|
|
47993
|
+
return false;
|
|
47994
|
+
// 支持 extends React.Component
|
|
47995
|
+
if (superClass.type === 'MemberExpression' &&
|
|
47996
|
+
superClass.object.name === 'React' &&
|
|
47997
|
+
superClass.property.name === 'Component') {
|
|
47998
|
+
return true;
|
|
47999
|
+
}
|
|
48000
|
+
// 支持 extends Component 和 extends Component<IProps, IState>
|
|
48001
|
+
// 泛型参数不会影响标识符本身的识别
|
|
48002
|
+
if (superClass.type === 'Identifier' &&
|
|
48003
|
+
superClass.name === 'Component') {
|
|
48004
|
+
return true;
|
|
48005
|
+
}
|
|
48006
|
+
// 额外检查:如果父节点是TSExpressionWithTypeArguments,检查其expression
|
|
48007
|
+
// 这种情况出现在 extends Component<IProps, IState> 中
|
|
48008
|
+
if (superClass.type === 'TSExpressionWithTypeArguments' &&
|
|
48009
|
+
superClass.expression &&
|
|
48010
|
+
superClass.expression.type === 'Identifier' &&
|
|
48011
|
+
superClass.expression.name === 'Component') {
|
|
48012
|
+
return true;
|
|
48013
|
+
}
|
|
48014
|
+
return false;
|
|
48015
|
+
};
|
|
48016
|
+
UnifiedTSXValidator.prototype.isReactComponentSuperClass = function (path) {
|
|
48017
|
+
var superClass = path.node.superClass;
|
|
48018
|
+
return this.isReactComponent(superClass);
|
|
48019
|
+
};
|
|
48020
|
+
UnifiedTSXValidator.prototype.hasJSXInNode = function (node) {
|
|
48021
|
+
if (!node)
|
|
48022
|
+
return false;
|
|
48023
|
+
if (node.type === 'JSXElement' || node.type === 'JSXFragment')
|
|
48024
|
+
return true;
|
|
48025
|
+
if (node.type === 'ConditionalExpression') {
|
|
48026
|
+
return this.hasJSXInNode(node.consequent) || this.hasJSXInNode(node.alternate);
|
|
48027
|
+
}
|
|
48028
|
+
return false;
|
|
48029
|
+
};
|
|
48030
|
+
UnifiedTSXValidator.prototype.isInEventHandler = function (path) {
|
|
47691
48031
|
var jsxAttribute = path.findParent(function (p) { return p.isJSXAttribute(); });
|
|
47692
48032
|
if (jsxAttribute && t__namespace.isJSXIdentifier(jsxAttribute.node.name)) {
|
|
47693
48033
|
var attrName = jsxAttribute.node.name.name;
|
|
47694
|
-
// 检查是否是事件处理属性(onXxx)
|
|
47695
48034
|
if (/^on[A-Z]/.test(attrName)) {
|
|
47696
48035
|
return true;
|
|
47697
48036
|
}
|
|
47698
48037
|
}
|
|
47699
|
-
// 检查是否在 addEventListener 回调中
|
|
47700
|
-
var callExpression = path.findParent(function (p) { return p.isCallExpression(); });
|
|
47701
|
-
if (callExpression && t__namespace.isMemberExpression(callExpression.node.callee)) {
|
|
47702
|
-
var memberExpr = callExpression.node.callee;
|
|
47703
|
-
if (t__namespace.isIdentifier(memberExpr.property) &&
|
|
47704
|
-
memberExpr.property.name === 'addEventListener') {
|
|
47705
|
-
return true;
|
|
47706
|
-
}
|
|
47707
|
-
}
|
|
47708
48038
|
return false;
|
|
47709
48039
|
};
|
|
47710
|
-
|
|
47711
|
-
* 检查是否在非 JSX 返回的回调函数中
|
|
47712
|
-
*/
|
|
47713
|
-
TSXComplianceChecker.isInNonJSXCallback = function (path) {
|
|
47714
|
-
// 查找父级函数
|
|
48040
|
+
UnifiedTSXValidator.prototype.isInNonJSXCallback = function (path) {
|
|
47715
48041
|
var parentFunction = path.findParent(function (p) { return p.isArrowFunctionExpression() || p.isFunctionExpression(); });
|
|
47716
48042
|
if (!parentFunction)
|
|
47717
48043
|
return false;
|
|
47718
|
-
|
|
47719
|
-
var jsxAttribute = parentFunction.findParent(function (p) {
|
|
47720
|
-
return p.isJSXAttribute();
|
|
47721
|
-
});
|
|
48044
|
+
var jsxAttribute = parentFunction.findParent(function (p) { return p.isJSXAttribute(); });
|
|
47722
48045
|
if (jsxAttribute && t__namespace.isJSXIdentifier(jsxAttribute.node.name)) {
|
|
47723
48046
|
var attrName = jsxAttribute.node.name.name;
|
|
47724
|
-
// 这些属性通常不返回 JSX
|
|
47725
48047
|
var nonJSXAttributes = [
|
|
47726
|
-
'beforeUpload',
|
|
47727
|
-
'
|
|
47728
|
-
'onChange',
|
|
47729
|
-
'onFinish',
|
|
47730
|
-
'onSubmit',
|
|
47731
|
-
'onSuccess',
|
|
47732
|
-
'onError',
|
|
47733
|
-
'onProgress',
|
|
47734
|
-
'request',
|
|
47735
|
-
'dataHandler',
|
|
48048
|
+
'beforeUpload', 'customRequest', 'onChange', 'onFinish',
|
|
48049
|
+
'onSubmit', 'onSuccess', 'onError', 'onProgress', 'request', 'dataHandler'
|
|
47736
48050
|
];
|
|
47737
48051
|
if (nonJSXAttributes.includes(attrName)) {
|
|
47738
48052
|
return true;
|
|
47739
48053
|
}
|
|
47740
48054
|
}
|
|
47741
|
-
|
|
47742
|
-
var returnsJSX = this.functionReturnsJSX(parentFunction);
|
|
47743
|
-
// 如果不返回 JSX,则认为是非 JSX 回调
|
|
47744
|
-
return !returnsJSX;
|
|
48055
|
+
return !this.functionReturnsJSX(parentFunction);
|
|
47745
48056
|
};
|
|
47746
|
-
|
|
47747
|
-
* 检查是否在返回 JSX 的回调函数中
|
|
47748
|
-
*/
|
|
47749
|
-
TSXComplianceChecker.isInJSXCallback = function (path) {
|
|
47750
|
-
// 查找父级函数
|
|
48057
|
+
UnifiedTSXValidator.prototype.isInJSXCallback = function (path) {
|
|
47751
48058
|
var parentFunction = path.findParent(function (p) { return p.isArrowFunctionExpression() || p.isFunctionExpression(); });
|
|
47752
48059
|
if (!parentFunction)
|
|
47753
48060
|
return false;
|
|
47754
|
-
// 检查函数是否返回 JSX
|
|
47755
48061
|
return this.functionReturnsJSX(parentFunction);
|
|
47756
48062
|
};
|
|
47757
|
-
|
|
47758
|
-
* 检查函数是否返回 JSX
|
|
47759
|
-
*/
|
|
47760
|
-
TSXComplianceChecker.functionReturnsJSX = function (functionPath) {
|
|
48063
|
+
UnifiedTSXValidator.prototype.functionReturnsJSX = function (functionPath) {
|
|
47761
48064
|
var returnsJSX = false;
|
|
47762
48065
|
functionPath.traverse({
|
|
47763
48066
|
ReturnStatement: function (path) {
|
|
@@ -47766,7 +48069,6 @@ var TSXComplianceChecker = /** @class */ (function () {
|
|
|
47766
48069
|
}
|
|
47767
48070
|
},
|
|
47768
48071
|
JSXElement: function (path) {
|
|
47769
|
-
// 如果函数体直接包含 JSX(箭头函数的隐式返回)
|
|
47770
48072
|
if (path.parent === functionPath.node.body) {
|
|
47771
48073
|
returnsJSX = true;
|
|
47772
48074
|
}
|
|
@@ -47774,76 +48076,280 @@ var TSXComplianceChecker = /** @class */ (function () {
|
|
|
47774
48076
|
});
|
|
47775
48077
|
return returnsJSX;
|
|
47776
48078
|
};
|
|
48079
|
+
UnifiedTSXValidator.prototype.isInRenderJSX = function (path) {
|
|
48080
|
+
var isInRender = false;
|
|
48081
|
+
var isInJSX = false;
|
|
48082
|
+
var currentPath = path;
|
|
48083
|
+
while (currentPath) {
|
|
48084
|
+
if (currentPath.node.type === 'ClassMethod' && currentPath.node.key.name === 'render') {
|
|
48085
|
+
isInRender = true;
|
|
48086
|
+
}
|
|
48087
|
+
if (currentPath.node.type === 'JSXExpressionContainer') {
|
|
48088
|
+
isInJSX = true;
|
|
48089
|
+
}
|
|
48090
|
+
currentPath = currentPath.parentPath;
|
|
48091
|
+
}
|
|
48092
|
+
return isInRender && isInJSX;
|
|
48093
|
+
};
|
|
48094
|
+
UnifiedTSXValidator.prototype.isDirectStateMutation = function (left) {
|
|
48095
|
+
return (left.type === 'MemberExpression' &&
|
|
48096
|
+
left.object.type === 'MemberExpression' &&
|
|
48097
|
+
left.object.object.type === 'ThisExpression' &&
|
|
48098
|
+
left.object.property.name === 'state');
|
|
48099
|
+
};
|
|
48100
|
+
UnifiedTSXValidator.prototype.isDataSourceLoadCall = function (node) {
|
|
48101
|
+
return (node.callee.type === 'MemberExpression' &&
|
|
48102
|
+
node.callee.object.type === 'MemberExpression' &&
|
|
48103
|
+
node.callee.object.object.type === 'MemberExpression' &&
|
|
48104
|
+
node.callee.object.object.object.type === 'ThisExpression' &&
|
|
48105
|
+
node.callee.object.object.property.name === 'dataSourceMap' &&
|
|
48106
|
+
node.callee.property.name === 'load');
|
|
48107
|
+
};
|
|
48108
|
+
UnifiedTSXValidator.prototype.createIssueFromNode = function (code, type, message, suggestion, node) {
|
|
48109
|
+
var loc = node.loc;
|
|
48110
|
+
return {
|
|
48111
|
+
type: type,
|
|
48112
|
+
code: code,
|
|
48113
|
+
message: message,
|
|
48114
|
+
suggestion: suggestion,
|
|
48115
|
+
line: loc ? loc.start.line : 1,
|
|
48116
|
+
column: loc ? loc.start.column : 0,
|
|
48117
|
+
};
|
|
48118
|
+
};
|
|
48119
|
+
UnifiedTSXValidator.prototype.createIssue = function (code, type, message, suggestion, line, column) {
|
|
48120
|
+
if (column === void 0) { column = 0; }
|
|
48121
|
+
return {
|
|
48122
|
+
type: type,
|
|
48123
|
+
code: code,
|
|
48124
|
+
message: message,
|
|
48125
|
+
suggestion: suggestion,
|
|
48126
|
+
line: line,
|
|
48127
|
+
column: column,
|
|
48128
|
+
};
|
|
48129
|
+
};
|
|
47777
48130
|
/**
|
|
47778
|
-
*
|
|
48131
|
+
* 检查TypeScript语法在组件方法中
|
|
47779
48132
|
*/
|
|
47780
|
-
|
|
47781
|
-
var
|
|
47782
|
-
|
|
47783
|
-
|
|
47784
|
-
|
|
47785
|
-
|
|
47786
|
-
|
|
47787
|
-
|
|
47788
|
-
|
|
47789
|
-
|
|
47790
|
-
|
|
47791
|
-
|
|
47792
|
-
|
|
48133
|
+
UnifiedTSXValidator.prototype.checkTypeScriptSyntaxInMethods = function (ast, issues) {
|
|
48134
|
+
var _this = this;
|
|
48135
|
+
this.log('开始检查TypeScript语法在组件方法中');
|
|
48136
|
+
// 找到React组件类并检查方法
|
|
48137
|
+
traverse__default["default"](ast, {
|
|
48138
|
+
ClassDeclaration: function (path) {
|
|
48139
|
+
var _a;
|
|
48140
|
+
if (_this.isReactComponent(path.node.superClass)) {
|
|
48141
|
+
var className = (_a = path.node.id) === null || _a === void 0 ? void 0 : _a.name;
|
|
48142
|
+
_this.log("\u68C0\u67E5TypeScript\u8BED\u6CD5\u5728\u7EC4\u4EF6\u7C7B: ".concat(className));
|
|
48143
|
+
// 检查类中的所有方法
|
|
48144
|
+
path.node.body.body.forEach(function (member) {
|
|
48145
|
+
var _a;
|
|
48146
|
+
if (member.type === 'ClassMethod') {
|
|
48147
|
+
var methodName_1 = (_a = member.key) === null || _a === void 0 ? void 0 : _a.name;
|
|
48148
|
+
// 跳过render方法的TypeScript语法检查(render方法本身已经单独处理)
|
|
48149
|
+
if (methodName_1 === 'render')
|
|
48150
|
+
return;
|
|
48151
|
+
// 检查方法参数中的TypeScript语法
|
|
48152
|
+
member.params.forEach(function (param, index) {
|
|
48153
|
+
// 检查是否有类型注解
|
|
48154
|
+
if (param.typeAnnotation) {
|
|
48155
|
+
issues.push(_this.createIssueFromNode('TYPESCRIPT_IN_METHOD_PARAMS', 'error', "\u65B9\u6CD5 ".concat(methodName_1, " \u7684\u7B2C ").concat(index + 1, " \u4E2A\u53C2\u6570\u5305\u542BTypeScript\u7C7B\u578B\u6CE8\u89E3"), "\u8BF7\u79FB\u9664\u53C2\u6570\u7684\u7C7B\u578B\u6CE8\u89E3\uFF0C\u4F7F\u7528\u7EAFJavaScript\u8BED\u6CD5\uFF0C\u5982\u5C06 '".concat(param.name.name || param.name, ": string' \u6539\u4E3A '").concat(param.name.name || param.name, "'"), param));
|
|
48156
|
+
}
|
|
48157
|
+
});
|
|
48158
|
+
// 检查方法返回值的TypeScript语法
|
|
48159
|
+
if (member.returnType) {
|
|
48160
|
+
issues.push(_this.createIssueFromNode('TYPESCRIPT_IN_RETURN_TYPE', 'error', "\u65B9\u6CD5 ".concat(methodName_1, " \u5305\u542BTypeScript\u8FD4\u56DE\u503C\u7C7B\u578B\u6CE8\u89E3"), "\u8BF7\u79FB\u9664\u8FD4\u56DE\u503C\u7684\u7C7B\u578B\u6CE8\u89E3\uFF0C\u4F7F\u7528\u7EAFJavaScript\u8BED\u6CD5", member));
|
|
48161
|
+
}
|
|
48162
|
+
// 检查方法中是否包含JSX返回
|
|
48163
|
+
if (_this.methodContainsJSX(member)) {
|
|
48164
|
+
issues.push(_this.createIssueFromNode('METHOD_CONTAINS_JSX', 'error', "\u65B9\u6CD5 ".concat(methodName_1, " \u4E0D\u80FD\u5305\u542B JSX \u8BED\u6CD5"), '只有 render() 方法可以包含 JSX,其他方法只处理逻辑', member));
|
|
48165
|
+
}
|
|
48166
|
+
// 检查方法体中的变量声明的TypeScript语法
|
|
48167
|
+
// 直接遍历AST节点而不使用traverse
|
|
48168
|
+
_this.checkVariableTypeAnnotationsInNode(member, methodName_1, issues);
|
|
48169
|
+
}
|
|
48170
|
+
});
|
|
48171
|
+
}
|
|
48172
|
+
},
|
|
48173
|
+
});
|
|
48174
|
+
};
|
|
48175
|
+
/**
|
|
48176
|
+
* 检查方法中是否包含JSX语法
|
|
48177
|
+
*/
|
|
48178
|
+
UnifiedTSXValidator.prototype.methodContainsJSX = function (methodNode) {
|
|
48179
|
+
var e_4, _a;
|
|
48180
|
+
if (!methodNode || !methodNode.body)
|
|
48181
|
+
return false;
|
|
48182
|
+
var containsJSX = false;
|
|
48183
|
+
var checkJSX = function (node) {
|
|
48184
|
+
if (!node)
|
|
47793
48185
|
return;
|
|
47794
|
-
|
|
47795
|
-
|
|
47796
|
-
|
|
47797
|
-
|
|
47798
|
-
|
|
47799
|
-
|
|
47800
|
-
|
|
47801
|
-
|
|
47802
|
-
|
|
47803
|
-
|
|
47804
|
-
|
|
47805
|
-
|
|
47806
|
-
|
|
47807
|
-
|
|
47808
|
-
|
|
47809
|
-
|
|
47810
|
-
|
|
47811
|
-
|
|
47812
|
-
|
|
47813
|
-
|
|
47814
|
-
|
|
48186
|
+
if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
|
|
48187
|
+
containsJSX = true;
|
|
48188
|
+
return true; // 找到JSX,停止递归
|
|
48189
|
+
}
|
|
48190
|
+
// 递归检查子节点
|
|
48191
|
+
for (var key in node) {
|
|
48192
|
+
if (node[key] && typeof node[key] === 'object') {
|
|
48193
|
+
if (checkJSX(node[key])) {
|
|
48194
|
+
return true;
|
|
48195
|
+
}
|
|
48196
|
+
}
|
|
48197
|
+
}
|
|
48198
|
+
return false;
|
|
48199
|
+
};
|
|
48200
|
+
// 检查方法体中的所有语句
|
|
48201
|
+
if (Array.isArray(methodNode.body.body)) {
|
|
48202
|
+
try {
|
|
48203
|
+
for (var _b = __values(methodNode.body.body), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
48204
|
+
var statement = _c.value;
|
|
48205
|
+
if (checkJSX(statement)) {
|
|
48206
|
+
return true;
|
|
48207
|
+
}
|
|
48208
|
+
}
|
|
48209
|
+
}
|
|
48210
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
48211
|
+
finally {
|
|
48212
|
+
try {
|
|
48213
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
48214
|
+
}
|
|
48215
|
+
finally { if (e_4) throw e_4.error; }
|
|
47815
48216
|
}
|
|
47816
48217
|
}
|
|
48218
|
+
else if (methodNode.body) {
|
|
48219
|
+
if (checkJSX(methodNode.body)) {
|
|
48220
|
+
return true;
|
|
48221
|
+
}
|
|
48222
|
+
}
|
|
48223
|
+
return containsJSX;
|
|
47817
48224
|
};
|
|
47818
48225
|
/**
|
|
47819
|
-
*
|
|
48226
|
+
* 递归检查节点中的变量类型注解
|
|
47820
48227
|
*/
|
|
47821
|
-
|
|
47822
|
-
|
|
48228
|
+
UnifiedTSXValidator.prototype.checkVariableTypeAnnotationsInNode = function (node, methodName, issues) {
|
|
48229
|
+
var _this = this;
|
|
48230
|
+
if (!node)
|
|
48231
|
+
return;
|
|
48232
|
+
// 如果是数组,遍历每个元素
|
|
48233
|
+
if (Array.isArray(node)) {
|
|
48234
|
+
node.forEach(function (item) { return _this.checkVariableTypeAnnotationsInNode(item, methodName, issues); });
|
|
48235
|
+
return;
|
|
48236
|
+
}
|
|
48237
|
+
// 检查变量声明
|
|
48238
|
+
if (node.type === 'VariableDeclaration') {
|
|
48239
|
+
node.declarations.forEach(function (declaration) {
|
|
48240
|
+
if (declaration.id && declaration.id.typeAnnotation) {
|
|
48241
|
+
issues.push(_this.createIssueFromNode('TYPESCRIPT_IN_VARIABLES', 'error', "\u65B9\u6CD5 ".concat(methodName, " \u4E2D\u7684\u53D8\u91CF\u58F0\u660E\u5305\u542BTypeScript\u7C7B\u578B\u6CE8\u89E3"), "\u8BF7\u79FB\u9664\u53D8\u91CF\u7684\u7C7B\u578B\u6CE8\u89E3\uFF0C\u4F7F\u7528\u7EAFJavaScript\u8BED\u6CD5\uFF0C\u5982\u5C06 'let name: string' \u6539\u4E3A 'let name'", declaration));
|
|
48242
|
+
}
|
|
48243
|
+
});
|
|
48244
|
+
}
|
|
48245
|
+
// 递归检查子节点
|
|
48246
|
+
if (node.body && Array.isArray(node.body)) {
|
|
48247
|
+
node.body.forEach(function (child) { return _this.checkVariableTypeAnnotationsInNode(child, methodName, issues); });
|
|
48248
|
+
}
|
|
48249
|
+
else if (node.body) {
|
|
48250
|
+
this.checkVariableTypeAnnotationsInNode(node.body, methodName, issues);
|
|
48251
|
+
}
|
|
48252
|
+
if (node.consequent) {
|
|
48253
|
+
this.checkVariableTypeAnnotationsInNode(node.consequent, methodName, issues);
|
|
48254
|
+
}
|
|
48255
|
+
if (node.alternate) {
|
|
48256
|
+
this.checkVariableTypeAnnotationsInNode(node.alternate, methodName, issues);
|
|
48257
|
+
}
|
|
48258
|
+
if (node.expression) {
|
|
48259
|
+
this.checkVariableTypeAnnotationsInNode(node.expression, methodName, issues);
|
|
48260
|
+
}
|
|
47823
48261
|
};
|
|
47824
48262
|
/**
|
|
47825
|
-
*
|
|
48263
|
+
* 安全地执行检查方法,避免异常传播
|
|
47826
48264
|
*/
|
|
47827
|
-
|
|
47828
|
-
|
|
48265
|
+
UnifiedTSXValidator.prototype.safeCheck = function (methodName, checkFunction) {
|
|
48266
|
+
try {
|
|
48267
|
+
checkFunction();
|
|
48268
|
+
}
|
|
48269
|
+
catch (error) {
|
|
48270
|
+
this.log("".concat(methodName, " \u68C0\u67E5\u65F6\u53D1\u751F\u9519\u8BEF: ").concat(error.message));
|
|
48271
|
+
// 不抛出异常,只记录日志
|
|
48272
|
+
}
|
|
48273
|
+
};
|
|
48274
|
+
UnifiedTSXValidator.prototype.log = function (message) {
|
|
48275
|
+
if (this.debug) {
|
|
48276
|
+
console.log("[UnifiedTSXValidator] ".concat(message));
|
|
48277
|
+
}
|
|
47829
48278
|
};
|
|
47830
48279
|
/**
|
|
47831
|
-
*
|
|
48280
|
+
* 生成简化的错误信息(兼容编辑器使用)
|
|
47832
48281
|
*/
|
|
47833
|
-
|
|
47834
|
-
|
|
47835
|
-
|
|
48282
|
+
UnifiedTSXValidator.prototype.generateSimpleErrors = function (result) {
|
|
48283
|
+
return result.issues
|
|
48284
|
+
.filter(function (issue) { return issue.type === 'error'; })
|
|
48285
|
+
.map(function (issue) {
|
|
48286
|
+
var location = issue.line ? " (\u7B2C".concat(issue.line, "\u884C)") : '';
|
|
48287
|
+
return "[".concat(issue.code, "] ").concat(issue.message).concat(location);
|
|
48288
|
+
});
|
|
47836
48289
|
};
|
|
47837
48290
|
/**
|
|
47838
|
-
*
|
|
48291
|
+
* 生成详细报告(兼容CLI使用)
|
|
47839
48292
|
*/
|
|
47840
|
-
|
|
47841
|
-
var
|
|
47842
|
-
|
|
47843
|
-
|
|
47844
|
-
|
|
47845
|
-
|
|
48293
|
+
UnifiedTSXValidator.prototype.generateReport = function (result) {
|
|
48294
|
+
var isCompliant = result.isCompliant, issues = result.issues;
|
|
48295
|
+
var report = '=== TSX 规范检查报告 ===\n';
|
|
48296
|
+
report += "\u6587\u4EF6: ".concat(this.filename, "\n");
|
|
48297
|
+
if (isCompliant) {
|
|
48298
|
+
report += '✅ 检查通过:文件符合 TSX 规范\n';
|
|
48299
|
+
}
|
|
48300
|
+
else {
|
|
48301
|
+
var errorCount = issues.filter(function (issue) { return issue.type === 'error'; }).length;
|
|
48302
|
+
report += "\u274C \u68C0\u67E5\u5931\u8D25\uFF1A\u53D1\u73B0 ".concat(errorCount, " \u4E2A\u9519\u8BEF\n\n");
|
|
48303
|
+
report += '--- 问题详情 ---\n';
|
|
48304
|
+
issues.forEach(function (issue, index) {
|
|
48305
|
+
var icon = issue.type === 'error' ? '❌' : '⚠️';
|
|
48306
|
+
report += "".concat(index + 1, ". ").concat(icon, " [").concat(issue.code, "] ").concat(issue.message, "\n");
|
|
48307
|
+
if (issue.line) {
|
|
48308
|
+
report += " \uD83D\uDCCD \u4F4D\u7F6E: \u7B2C ".concat(issue.line, " \u884C\n");
|
|
48309
|
+
}
|
|
48310
|
+
report += " \uD83D\uDCA1 \u5EFA\u8BAE: ".concat(issue.suggestion, "\n\n");
|
|
48311
|
+
});
|
|
48312
|
+
}
|
|
48313
|
+
return report;
|
|
47846
48314
|
};
|
|
48315
|
+
return UnifiedTSXValidator;
|
|
48316
|
+
}());
|
|
48317
|
+
|
|
48318
|
+
var TSXComplianceChecker = /** @class */ (function () {
|
|
48319
|
+
function TSXComplianceChecker() {
|
|
48320
|
+
}
|
|
48321
|
+
/**
|
|
48322
|
+
* 使用统一验证器检查 TSX 规范
|
|
48323
|
+
*/
|
|
48324
|
+
TSXComplianceChecker.checkTSXCompliance = function (content, filename) {
|
|
48325
|
+
var _this = this;
|
|
48326
|
+
try {
|
|
48327
|
+
var result = this.validator.validate(content, filename);
|
|
48328
|
+
// 转换为兼容的格式
|
|
48329
|
+
var compliantIssues = result.issues.map(function (issue) { return (__assign(__assign({}, issue), {
|
|
48330
|
+
// 为CLI添加代码片段
|
|
48331
|
+
codeSnippet: issue.line ? _this.extractCodeSnippet(content, issue.line).snippet : undefined, snippetStartLine: issue.line ? _this.extractCodeSnippet(content, issue.line).startLine : undefined, snippetEndLine: issue.line ? _this.extractCodeSnippet(content, issue.line).endLine : undefined })); });
|
|
48332
|
+
return {
|
|
48333
|
+
isCompliant: result.isCompliant,
|
|
48334
|
+
issues: compliantIssues,
|
|
48335
|
+
};
|
|
48336
|
+
}
|
|
48337
|
+
catch (error) {
|
|
48338
|
+
// 捕获任何异常并返回合规结果,而不是让异常向上传播
|
|
48339
|
+
return {
|
|
48340
|
+
isCompliant: false,
|
|
48341
|
+
issues: [{
|
|
48342
|
+
type: 'error',
|
|
48343
|
+
code: 'VALIDATION_ERROR',
|
|
48344
|
+
message: "\u9A8C\u8BC1\u8FC7\u7A0B\u53D1\u751F\u9519\u8BEF: ".concat(error.message),
|
|
48345
|
+
suggestion: '请检查代码语法或联系开发团队',
|
|
48346
|
+
line: 1,
|
|
48347
|
+
column: 0,
|
|
48348
|
+
}],
|
|
48349
|
+
};
|
|
48350
|
+
}
|
|
48351
|
+
};
|
|
48352
|
+
// 移除了所有旧的检查方法,现在使用UnifiedTSXValidator
|
|
47847
48353
|
/**
|
|
47848
48354
|
* 提取代码片段
|
|
47849
48355
|
*/
|
|
@@ -47865,34 +48371,33 @@ var TSXComplianceChecker = /** @class */ (function () {
|
|
|
47865
48371
|
};
|
|
47866
48372
|
};
|
|
47867
48373
|
/**
|
|
47868
|
-
*
|
|
48374
|
+
* 生成检查报告(使用统一验证器)
|
|
47869
48375
|
*/
|
|
47870
48376
|
TSXComplianceChecker.generateReport = function (result, filename) {
|
|
47871
|
-
|
|
47872
|
-
|
|
47873
|
-
|
|
47874
|
-
|
|
47875
|
-
|
|
47876
|
-
|
|
47877
|
-
|
|
47878
|
-
|
|
47879
|
-
|
|
47880
|
-
|
|
47881
|
-
|
|
47882
|
-
|
|
47883
|
-
|
|
47884
|
-
|
|
47885
|
-
|
|
47886
|
-
|
|
47887
|
-
report += " \uD83D\uDCA1 \u5EFA\u8BAE: ".concat(issue.suggestion, "\n");
|
|
47888
|
-
if (issue.codeSnippet) {
|
|
47889
|
-
report += " \uD83D\uDCDD \u4EE3\u7801\u7247\u6BB5:\n".concat(issue.codeSnippet, "\n");
|
|
47890
|
-
}
|
|
47891
|
-
report += '\n';
|
|
47892
|
-
});
|
|
48377
|
+
this.validator = new UnifiedTSXValidator(false);
|
|
48378
|
+
return this.validator.generateReport(result);
|
|
48379
|
+
};
|
|
48380
|
+
/**
|
|
48381
|
+
* 提取代码片段(保留原有逻辑)
|
|
48382
|
+
*/
|
|
48383
|
+
TSXComplianceChecker.extractCodeSnippet = function (content, lineNumber, contextLines) {
|
|
48384
|
+
if (contextLines === void 0) { contextLines = 3; }
|
|
48385
|
+
var lines = content.split('\n');
|
|
48386
|
+
var startLine = Math.max(1, lineNumber - contextLines);
|
|
48387
|
+
var endLine = Math.min(lines.length, lineNumber + contextLines);
|
|
48388
|
+
var snippetLines = [];
|
|
48389
|
+
for (var i = startLine; i <= endLine; i++) {
|
|
48390
|
+
var line = lines[i - 1] || '';
|
|
48391
|
+
var prefix = i === lineNumber ? '>>> ' : ' ';
|
|
48392
|
+
snippetLines.push("".concat(prefix).concat(i.toString().padStart(3), ": ").concat(line));
|
|
47893
48393
|
}
|
|
47894
|
-
return
|
|
48394
|
+
return {
|
|
48395
|
+
snippet: snippetLines.join('\n'),
|
|
48396
|
+
startLine: startLine,
|
|
48397
|
+
endLine: endLine,
|
|
48398
|
+
};
|
|
47895
48399
|
};
|
|
48400
|
+
TSXComplianceChecker.validator = new UnifiedTSXValidator(false);
|
|
47896
48401
|
return TSXComplianceChecker;
|
|
47897
48402
|
}());
|
|
47898
48403
|
|