s2cfgtojson 1.0.2 → 1.0.3
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/Struct.mts +9 -6
- package/package.json +1 -1
package/Struct.mts
CHANGED
|
@@ -68,9 +68,11 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
68
68
|
if (Struct.isNumber(Struct.extractKeyFromBrackets(name))) {
|
|
69
69
|
return `_${name.match(/\[(\d+)]/)[1]}`; // Special case for indexed structs
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
return name
|
|
72
|
+
.replace(/\W/g, "_")
|
|
73
|
+
.replace(/^\d+/, "_")
|
|
74
|
+
.replace(/_+/g, "_")
|
|
75
|
+
.replace(/^_+/, "");
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
static createDynamicClass = (name: string): new () => Struct =>
|
|
@@ -150,14 +152,15 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
150
152
|
): IntendedType[] {
|
|
151
153
|
const lines = text.trim().split("\n");
|
|
152
154
|
|
|
153
|
-
const parseHead = (line: string): Struct => {
|
|
155
|
+
const parseHead = (line: string, index: number): Struct => {
|
|
154
156
|
const match = line.match(
|
|
155
157
|
/^(.*)\s*:\s*struct\.begin\s*({\s*((refurl|refkey|bskipref)\s*(=.+)?)\s*})?/,
|
|
156
158
|
);
|
|
157
159
|
if (!match) {
|
|
158
160
|
throw new Error(`Invalid struct head: ${line}`);
|
|
159
161
|
}
|
|
160
|
-
let name =
|
|
162
|
+
let name =
|
|
163
|
+
Struct.parseStructName(match[1].trim()) || `UnnamedStruct${index}`;
|
|
161
164
|
|
|
162
165
|
const dummy = new (Struct.createDynamicClass(name))();
|
|
163
166
|
dummy._id = match[1];
|
|
@@ -202,7 +205,7 @@ export abstract class Struct<T extends Entries = {}> {
|
|
|
202
205
|
}
|
|
203
206
|
const current = stack[stack.length - 1];
|
|
204
207
|
if (line.includes("struct.begin")) {
|
|
205
|
-
const newStruct = parseHead(line);
|
|
208
|
+
const newStruct = parseHead(line, index);
|
|
206
209
|
if (current) {
|
|
207
210
|
const key = Struct.renderStructName(newStruct.constructor.name);
|
|
208
211
|
Struct.addEntry(current, key, newStruct, index);
|