scancscode 1.0.22 → 1.0.24
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/CSCodeScanner.js +29 -18
- package/package.json +1 -1
- package/src/CSCodeScanner.ts +30 -19
package/dist/CSCodeScanner.js
CHANGED
|
@@ -6,7 +6,7 @@ exports.CSCodeScanner = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
class CSCodeScanner {
|
|
8
8
|
// 正则表达式匹配 uictrl.text = $"..."; 的模式
|
|
9
|
-
static assignmentPattern = /([\w\.\u4e00-\u9fff]+\.text\s
|
|
9
|
+
static assignmentPattern = /([\w\.\u4e00-\u9fff]+\.text\s*\+?=(?![=>])\s*|return\s+)([^;]+)\s*;/mg;
|
|
10
10
|
// 正则表达式匹配 匹配每个字符串
|
|
11
11
|
static stringPattern = /\$?"([^"]*)"/mg;
|
|
12
12
|
// 正则表达式匹配 匹配获取成员值的表达式
|
|
@@ -83,15 +83,15 @@ class CSCodeScanner {
|
|
|
83
83
|
let prefix = bodyLine.substring(0, stringLineIndex);
|
|
84
84
|
let stringLineFirst = stringMatchFirst[0];
|
|
85
85
|
if (this.isNativeString(stringLineFirst)) {
|
|
86
|
-
convertedAssignLine =
|
|
86
|
+
convertedAssignLine = assignHead + prefix + stringMatchFirst[0] + ";";
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
|
-
convertedAssignLine =
|
|
89
|
+
convertedAssignLine = assignHead + prefix + stringMatchFirst[0] + `.${trmethodname}();`;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
else {
|
|
93
93
|
let stringLines = [];
|
|
94
|
-
stringLines.push(
|
|
94
|
+
stringLines.push(assignHead);
|
|
95
95
|
let lastIndex = 0;
|
|
96
96
|
for (let i = 0; i < stringMatchs.length; i++) {
|
|
97
97
|
let stringMatch = stringMatchs[i];
|
|
@@ -187,20 +187,9 @@ class CSCodeScanner {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
else {
|
|
190
|
-
let
|
|
191
|
-
if (
|
|
192
|
-
|
|
193
|
-
let memberLine = memberLines[i];
|
|
194
|
-
let regex = this.getMemberValuePattern(trmethodname);
|
|
195
|
-
let match = memberLine.match(regex);
|
|
196
|
-
if (match != null) {
|
|
197
|
-
let value = match[2];
|
|
198
|
-
if (value != 'null' && value != 'true' && value != 'false' && !this.isNumericString(value)) {
|
|
199
|
-
memberLines[i] = match[1] + match[2] + `.${trmethodname}()` + match[4];
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
convertedAssignLine = (assignHead ?? "") + memberLines.join("+") + ";";
|
|
190
|
+
let convertBodyLine = CSCodeScanner.handleMembersConvert(bodyLine, assignHead, trmethodname);
|
|
191
|
+
if (convertBodyLine != null) {
|
|
192
|
+
convertedAssignLine = (assignHead ?? "") + convertBodyLine;
|
|
204
193
|
}
|
|
205
194
|
else {
|
|
206
195
|
convertedAssignLine = assignLine;
|
|
@@ -217,6 +206,28 @@ class CSCodeScanner {
|
|
|
217
206
|
}
|
|
218
207
|
return snippets;
|
|
219
208
|
}
|
|
209
|
+
static handleMembersConvert(bodyLine, assignHead, trmethodname) {
|
|
210
|
+
let convertedAssignLine;
|
|
211
|
+
let memberLines = bodyLine.split("+");
|
|
212
|
+
if (assignHead != 'return ' && memberLines.length > 0) {
|
|
213
|
+
for (let i = 0; i < memberLines.length; i++) {
|
|
214
|
+
let memberLine = memberLines[i];
|
|
215
|
+
let regex = this.getMemberValuePattern(trmethodname);
|
|
216
|
+
let match = memberLine.match(regex);
|
|
217
|
+
if (match != null) {
|
|
218
|
+
let value = match[2];
|
|
219
|
+
if (value != 'null' && value != 'true' && value != 'false' && !this.isNumericString(value)) {
|
|
220
|
+
memberLines[i] = match[1] + match[2] + `.${trmethodname}()` + match[4];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
convertedAssignLine = memberLines.join("+") + ";";
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
convertedAssignLine = null;
|
|
228
|
+
}
|
|
229
|
+
return convertedAssignLine;
|
|
230
|
+
}
|
|
220
231
|
static isNumericString(str) {
|
|
221
232
|
if (typeof str !== 'string')
|
|
222
233
|
return false;
|
package/package.json
CHANGED
package/src/CSCodeScanner.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { CodeSnippet } from "./CodeSnippet";
|
|
|
6
6
|
|
|
7
7
|
export class CSCodeScanner {
|
|
8
8
|
// 正则表达式匹配 uictrl.text = $"..."; 的模式
|
|
9
|
-
private static readonly assignmentPattern = /([\w\.\u4e00-\u9fff]+\.text\s
|
|
9
|
+
private static readonly assignmentPattern = /([\w\.\u4e00-\u9fff]+\.text\s*\+?=(?![=>])\s*|return\s+)([^;]+)\s*;/mg;
|
|
10
10
|
|
|
11
11
|
// 正则表达式匹配 匹配每个字符串
|
|
12
12
|
private static readonly stringPattern = /\$?"([^"]*)"/mg;
|
|
@@ -91,13 +91,13 @@ export class CSCodeScanner {
|
|
|
91
91
|
let prefix = bodyLine.substring(0, stringLineIndex);
|
|
92
92
|
let stringLineFirst = stringMatchFirst[0];
|
|
93
93
|
if (this.isNativeString(stringLineFirst)) {
|
|
94
|
-
convertedAssignLine =
|
|
94
|
+
convertedAssignLine = assignHead + prefix + stringMatchFirst[0] + ";";
|
|
95
95
|
} else {
|
|
96
|
-
convertedAssignLine =
|
|
96
|
+
convertedAssignLine = assignHead + prefix + stringMatchFirst[0] + `.${trmethodname}();`;
|
|
97
97
|
}
|
|
98
98
|
} else {
|
|
99
99
|
let stringLines: string[] = [];
|
|
100
|
-
stringLines.push(
|
|
100
|
+
stringLines.push(assignHead);
|
|
101
101
|
let lastIndex = 0;
|
|
102
102
|
for (let i = 0; i < stringMatchs.length; i++) {
|
|
103
103
|
let stringMatch = stringMatchs[i];
|
|
@@ -195,22 +195,11 @@ export class CSCodeScanner {
|
|
|
195
195
|
convertedAssignLine = stringLines.join("");
|
|
196
196
|
}
|
|
197
197
|
} else {
|
|
198
|
-
let
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
let memberLine = memberLines[i];
|
|
202
|
-
let regex = this.getMemberValuePattern(trmethodname);
|
|
203
|
-
let match = memberLine.match(regex);
|
|
204
|
-
if (match != null) {
|
|
205
|
-
let value = match[2]
|
|
206
|
-
if (value != 'null' && value != 'true' && value != 'false' && !this.isNumericString(value)) {
|
|
207
|
-
memberLines[i] = match[1] + match[2] + `.${trmethodname}()` + match[4];
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
convertedAssignLine = (assignHead ?? "") + memberLines.join("+") + ";";
|
|
198
|
+
let convertBodyLine = CSCodeScanner.handleMembersConvert(bodyLine, assignHead, trmethodname)
|
|
199
|
+
if (convertBodyLine != null) {
|
|
200
|
+
convertedAssignLine = (assignHead ?? "") + convertBodyLine;
|
|
212
201
|
} else {
|
|
213
|
-
convertedAssignLine = assignLine
|
|
202
|
+
convertedAssignLine = assignLine
|
|
214
203
|
}
|
|
215
204
|
}
|
|
216
205
|
|
|
@@ -227,6 +216,28 @@ export class CSCodeScanner {
|
|
|
227
216
|
|
|
228
217
|
return snippets;
|
|
229
218
|
}
|
|
219
|
+
private static handleMembersConvert(bodyLine: string, assignHead: string, trmethodname: string) {
|
|
220
|
+
let convertedAssignLine: string | null
|
|
221
|
+
let memberLines = bodyLine.split("+");
|
|
222
|
+
if (assignHead != 'return ' && memberLines.length > 0) {
|
|
223
|
+
for (let i = 0; i < memberLines.length; i++) {
|
|
224
|
+
let memberLine = memberLines[i];
|
|
225
|
+
let regex = this.getMemberValuePattern(trmethodname);
|
|
226
|
+
let match = memberLine.match(regex);
|
|
227
|
+
if (match != null) {
|
|
228
|
+
let value = match[2];
|
|
229
|
+
if (value != 'null' && value != 'true' && value != 'false' && !this.isNumericString(value)) {
|
|
230
|
+
memberLines[i] = match[1] + match[2] + `.${trmethodname}()` + match[4];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
convertedAssignLine = memberLines.join("+") + ";";
|
|
235
|
+
} else {
|
|
236
|
+
convertedAssignLine = null;
|
|
237
|
+
}
|
|
238
|
+
return convertedAssignLine;
|
|
239
|
+
}
|
|
240
|
+
|
|
230
241
|
static isNumericString(str: string) {
|
|
231
242
|
if (typeof str !== 'string') return false;
|
|
232
243
|
const num = Number(str);
|