Skip to content

Commit

Permalink
Fix fast instantiator failing to compile when the typename has newlin…
Browse files Browse the repository at this point in the history
…es in it
  • Loading branch information
airhorns committed Apr 25, 2024
1 parent 23a9806 commit f59ec62
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/fast-instantiator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyType>, an
segments.push(this.assignmentExpressionForMapType(key, type));
} else {
segments.push(`
// instantiate fallback for ${key} of type ${type.name}
// instantiate fallback for ${key} of type ${safeTypeName(type)}
this["${key}"] = ${this.alias(`model.properties["${key}"]`)}.instantiate(
snapshot?.["${key}"],
context,
Expand Down Expand Up @@ -255,7 +255,7 @@ class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyType>, an
private assignmentExpressionForArrayType(key: string, type: ArrayType<any>): string {
if (!isDirectlyAssignableType(type.childrenType) || type.childrenType instanceof DateType) {
return `
// instantiate fallback for ${key} of type ${type.name}
// instantiate fallback for ${key} of type ${safeTypeName(type)}
this["${key}"] = ${this.alias(`model.properties["${key}"]`)}.instantiate(
snapshot?.["${key}"],
context,
Expand Down Expand Up @@ -308,3 +308,5 @@ class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyType>, an
return alias;
}
}

const safeTypeName = (type: IAnyType) => type.name.replace(/\n/g, "");

0 comments on commit f59ec62

Please sign in to comment.