Skip to content

Commit 016e90f

Browse files
committed
schema-codegen: fix generating for new schema({}) definition syntax
1 parent 1bbdcf1 commit 016e90f

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@colyseus/schema",
3-
"version": "3.0.69",
3+
"version": "3.0.70",
44
"description": "Binary state serializer with delta encoding for games",
55
"bin": {
66
"schema-codegen": "bin/schema-codegen",

src/codegen/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function inspectNode(node: ts.Node, context: Context, decoratorName: string) {
186186
// skip if no className is provided
187187
if (!className) { break; }
188188

189-
if (currentStructure.name !== className) {
189+
if (currentStructure?.name !== className) {
190190
currentStructure = new Class();
191191
}
192192
context.addStructure(currentStructure);
@@ -277,7 +277,7 @@ function inspectNode(node: ts.Node, context: Context, decoratorName: string) {
277277
// skip if no className is provided
278278
if (!className) { break; }
279279

280-
if (currentStructure.name !== className) {
280+
if (currentStructure?.name !== className) {
281281
currentStructure = new Class();
282282
context.addStructure(currentStructure);
283283
}

test/codegen/Codegen.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ describe("schema-codegen", () => {
109109

110110
assert.strictEqual(3, outputFiles.length);
111111
});
112+
113+
it("with map", () => {
114+
const inputFiles = glob.sync(path.resolve(INPUT_DIR, "PlainSchemaMap.ts"));
115+
116+
generate("ts", { files: inputFiles, output: OUTPUT_DIR, });
117+
118+
const outputFiles = glob.sync(path.resolve(OUTPUT_DIR, "*.ts"));
119+
120+
assert.strictEqual(2, outputFiles.length);
121+
});
112122
});
113123

114124
describe("invalid/error", () => {

0 commit comments

Comments
 (0)