s2cfgtojson 4.4.0 → 4.5.0
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 +55 -1
- package/Struct.test.mts +8 -0
- package/package.json +1 -1
- package/readme.md +1 -1
- package/types.mts +4886 -3467
package/Struct.mts
CHANGED
|
@@ -345,7 +345,8 @@ export function createDynamicClassInstance<T extends Struct = Struct>(
|
|
|
345
345
|
rawName: string,
|
|
346
346
|
index?: number,
|
|
347
347
|
): T {
|
|
348
|
-
const
|
|
348
|
+
const parsedName = parseStructName(rawName) || `UnnamedStruct${index}`;
|
|
349
|
+
const name = makeSafeClassName(parsedName);
|
|
349
350
|
return new (new Function(
|
|
350
351
|
"parent",
|
|
351
352
|
"Refs",
|
|
@@ -492,6 +493,59 @@ function parseStructName(name: string): string {
|
|
|
492
493
|
.replace(/^_+/, "");
|
|
493
494
|
}
|
|
494
495
|
|
|
496
|
+
const RESERVED_IDENTIFIERS = new Set([
|
|
497
|
+
"break",
|
|
498
|
+
"case",
|
|
499
|
+
"catch",
|
|
500
|
+
"class",
|
|
501
|
+
"const",
|
|
502
|
+
"continue",
|
|
503
|
+
"debugger",
|
|
504
|
+
"default",
|
|
505
|
+
"delete",
|
|
506
|
+
"do",
|
|
507
|
+
"else",
|
|
508
|
+
"export",
|
|
509
|
+
"extends",
|
|
510
|
+
"finally",
|
|
511
|
+
"for",
|
|
512
|
+
"function",
|
|
513
|
+
"if",
|
|
514
|
+
"import",
|
|
515
|
+
"in",
|
|
516
|
+
"instanceof",
|
|
517
|
+
"new",
|
|
518
|
+
"return",
|
|
519
|
+
"super",
|
|
520
|
+
"switch",
|
|
521
|
+
"this",
|
|
522
|
+
"throw",
|
|
523
|
+
"try",
|
|
524
|
+
"typeof",
|
|
525
|
+
"var",
|
|
526
|
+
"void",
|
|
527
|
+
"while",
|
|
528
|
+
"with",
|
|
529
|
+
"yield",
|
|
530
|
+
"enum",
|
|
531
|
+
"await",
|
|
532
|
+
"implements",
|
|
533
|
+
"package",
|
|
534
|
+
"protected",
|
|
535
|
+
"static",
|
|
536
|
+
"interface",
|
|
537
|
+
"private",
|
|
538
|
+
"public",
|
|
539
|
+
"let",
|
|
540
|
+
]);
|
|
541
|
+
|
|
542
|
+
function makeSafeClassName(name: string): string {
|
|
543
|
+
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) || RESERVED_IDENTIFIERS.has(name)) {
|
|
544
|
+
return `_${name}`;
|
|
545
|
+
}
|
|
546
|
+
return name;
|
|
547
|
+
}
|
|
548
|
+
|
|
495
549
|
function maybeMinifyKey(key: string, minify: boolean) {
|
|
496
550
|
return minify &&
|
|
497
551
|
(INTERNAL_PROPS.has(key as any) || REF_INTERNAL_PROPS.has(key as any))
|
package/Struct.test.mts
CHANGED
|
@@ -91,6 +91,14 @@ struct.end`,
|
|
|
91
91
|
`DynamicClass : struct.begin\n\nstruct.end`,
|
|
92
92
|
);
|
|
93
93
|
});
|
|
94
|
+
|
|
95
|
+
test("reserved keyword name", () => {
|
|
96
|
+
const instance = createDynamicClassInstance("default");
|
|
97
|
+
instance.__internal__.isRoot = true;
|
|
98
|
+
|
|
99
|
+
expect(instance).toBeInstanceOf(Struct);
|
|
100
|
+
expect(instance.toString()).toBe(`default : struct.begin\n\nstruct.end`);
|
|
101
|
+
});
|
|
94
102
|
});
|
|
95
103
|
|
|
96
104
|
describe("fromString()", () => {
|
package/package.json
CHANGED
package/readme.md
CHANGED