scancscode 1.0.19 → 1.0.20

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.
@@ -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*=(?![=>])\s*)([^;]+)\s*;/mg;
9
+ static assignmentPattern = /([\w\.\u4e00-\u9fff]+\.text\s*=(?![=>])\s*|return\s+)([^;]+)\s*;/mg;
10
10
  // 正则表达式匹配 匹配每个字符串
11
11
  static stringPattern = /\$?"([^"]*)"/mg;
12
12
  // 正则表达式匹配 匹配获取成员值的表达式
@@ -188,16 +188,19 @@ class CSCodeScanner {
188
188
  }
189
189
  else {
190
190
  let memberLines = bodyLine.split("+");
191
- if (memberLines.length > 0) {
191
+ if (assignHead != 'return ' && memberLines.length > 0) {
192
192
  for (let i = 0; i < memberLines.length; i++) {
193
193
  let memberLine = memberLines[i];
194
194
  let regex = this.getMemberValuePattern(trmethodname);
195
195
  let match = memberLine.match(regex);
196
196
  if (match != null) {
197
- memberLines[i] = match[1] + match[2] + `.${trmethodname}()` + match[4];
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
+ }
198
201
  }
199
202
  }
200
- convertedAssignLine = assignHead + memberLines.join("+") + ";";
203
+ convertedAssignLine = (assignHead ?? "") + memberLines.join("+") + ";";
201
204
  }
202
205
  else {
203
206
  convertedAssignLine = assignLine;
@@ -214,6 +217,12 @@ class CSCodeScanner {
214
217
  }
215
218
  return snippets;
216
219
  }
220
+ static isNumericString(str) {
221
+ if (typeof str !== 'string')
222
+ return false;
223
+ const num = Number(str);
224
+ return Number.isFinite(num) && String(num) === str.trim(); // 防止 ' 123 ' → 误判(可选严格匹配)
225
+ }
217
226
  static replaceStringsTR(stringMatch, stringLine, bodyLine, trmethodname) {
218
227
  if (this.isNativeString(stringLine)) {
219
228
  return stringLine;
@@ -46,8 +46,8 @@ class LiteralCollector {
46
46
  return;
47
47
  }
48
48
  let files = glob_1.glob.sync("**/*.cs", { cwd: folder });
49
- let testFullPath = "@";
50
- // let testFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/FGUI/TopRank/Comp/SubTopRankSelfComp.cs";
49
+ // let testFullPath = "@";
50
+ let testFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/Functional/Rune/Model/RuneExt.cs";
51
51
  for (const filePath of files) {
52
52
  let fullPath = folder + filePath;
53
53
  if (testFullPath != "@") {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const CmdExecutor_1 = require("./CmdExecutor");
4
- CmdExecutor_1.CmdExecutor.runConvertWithCmdOptions();
5
- // CmdExecutor.testConvert()
4
+ // CmdExecutor.runConvertWithCmdOptions()
5
+ CmdExecutor_1.CmdExecutor.testConvert();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scancscode",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {
@@ -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*=(?![=>])\s*)([^;]+)\s*;/mg;
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;
@@ -196,16 +196,19 @@ export class CSCodeScanner {
196
196
  }
197
197
  } else {
198
198
  let memberLines = bodyLine.split("+");
199
- if (memberLines.length > 0) {
199
+ if (assignHead != 'return ' && memberLines.length > 0) {
200
200
  for (let i = 0; i < memberLines.length; i++) {
201
201
  let memberLine = memberLines[i];
202
202
  let regex = this.getMemberValuePattern(trmethodname);
203
203
  let match = memberLine.match(regex);
204
204
  if (match != null) {
205
- memberLines[i] = match[1] + match[2] + `.${trmethodname}()` + match[4];
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
+ }
206
209
  }
207
210
  }
208
- convertedAssignLine = assignHead + memberLines.join("+") + ";";
211
+ convertedAssignLine = (assignHead ?? "") + memberLines.join("+") + ";";
209
212
  } else {
210
213
  convertedAssignLine = assignLine;
211
214
  }
@@ -224,7 +227,11 @@ export class CSCodeScanner {
224
227
 
225
228
  return snippets;
226
229
  }
227
-
230
+ static isNumericString(str: string) {
231
+ if (typeof str !== 'string') return false;
232
+ const num = Number(str);
233
+ return Number.isFinite(num) && String(num) === str.trim(); // 防止 ' 123 ' → 误判(可选严格匹配)
234
+ }
228
235
  public static replaceStringsTR(stringMatch: RegExpExecArray, stringLine: string, bodyLine: string, trmethodname: string): string {
229
236
  if (this.isNativeString(stringLine)) {
230
237
  return stringLine;
@@ -14,8 +14,8 @@ export class LiteralCollector {
14
14
  }
15
15
 
16
16
  let files = glob.sync("**/*.cs", { cwd: folder });
17
- let testFullPath = "@";
18
- // let testFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/FGUI/TopRank/Comp/SubTopRankSelfComp.cs";
17
+ // let testFullPath = "@";
18
+ let testFullPath = "E:/DATA/Projects/ZhiYou/ProjectFClient/GameClient/Assets/Bundles/Functional/Rune/Model/RuneExt.cs";
19
19
  for (const filePath of files) {
20
20
  let fullPath = folder + filePath;
21
21
  if (testFullPath != "@") {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { CmdExecutor } from "./CmdExecutor";
2
2
 
3
- CmdExecutor.runConvertWithCmdOptions()
4
- // CmdExecutor.testConvert()
3
+ // CmdExecutor.runConvertWithCmdOptions()
4
+ CmdExecutor.testConvert()