ts-proto 1.181.0 → 1.181.2

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/build/enums.d.ts CHANGED
@@ -7,6 +7,7 @@ type UnrecognizedEnum = {
7
7
  } | {
8
8
  present: true;
9
9
  name: string;
10
+ originalName: string;
10
11
  };
11
12
  export declare function generateEnum(ctx: Context, fullName: string, enumDesc: EnumDescriptorProto, sourceInfo: SourceInfo): Code;
12
13
  /** Generates a function with a big switch statement to decode JSON -> our enum. */
package/build/enums.js CHANGED
@@ -23,7 +23,7 @@ function generateEnum(ctx, fullName, enumDesc, sourceInfo) {
23
23
  const valueName = getValueName(ctx, fullName, valueDesc);
24
24
  const memberName = getMemberName(ctx, enumDesc, valueDesc);
25
25
  if (valueDesc.number === options.unrecognizedEnumValue) {
26
- unrecognizedEnum = { present: true, name: memberName };
26
+ unrecognizedEnum = { present: true, name: memberName, originalName: valueName };
27
27
  }
28
28
  (0, utils_1.maybeAddComment)(options, info, chunks, valueDesc.options?.deprecated, `${memberName} - `);
29
29
  chunks.push((0, ts_poet_1.code) `${memberName} ${delimiter} ${options.stringEnums ? `"${valueName}"` : valueDesc.number.toString()},`);
@@ -155,7 +155,7 @@ function generateEnumToJson(ctx, fullName, enumDesc, unrecognizedEnum) {
155
155
  else {
156
156
  chunks.push((0, ts_poet_1.code) `
157
157
  default:
158
- return "${unrecognizedEnum.name}";
158
+ return "${unrecognizedEnum.originalName}";
159
159
  `);
160
160
  }
161
161
  }
package/build/main.js CHANGED
@@ -1750,14 +1750,14 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
1750
1750
  }
1751
1751
  else {
1752
1752
  const fallback = noDefaultValue ? (0, utils_1.nullOrUndefined)(options) : "[]";
1753
- const readValueSnippet = readSnippet("e");
1754
- if (readValueSnippet.toString() === (0, ts_poet_1.code) `e`.toString()) {
1753
+ const needMap = readSnippet("e").toString() !== (0, ts_poet_1.code) `e`.toString();
1754
+ if (!needMap) {
1755
1755
  chunks.push((0, ts_poet_1.code) `${fieldKey}: ${ctx.utils.globalThis}.Array.isArray(${jsonPropertyOptional}) ? [...${jsonProperty}] : [],`);
1756
1756
  }
1757
1757
  else {
1758
1758
  // Explicit `any` type required to make TS with noImplicitAny happy. `object` is also `any` here.
1759
1759
  chunks.push((0, ts_poet_1.code) `
1760
- ${fieldKey}: ${ctx.utils.globalThis}.Array.isArray(${jsonPropertyOptional}) ? ${jsonProperty}.map((e: any) => ${readValueSnippet}): ${fallback},
1760
+ ${fieldKey}: ${ctx.utils.globalThis}.Array.isArray(${jsonPropertyOptional}) ? ${jsonProperty}.map((e: any) => ${readSnippet("e")}): ${fallback},
1761
1761
  `);
1762
1762
  }
1763
1763
  }
@@ -1969,8 +1969,8 @@ function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
1969
1969
  }
1970
1970
  else if ((0, types_1.isRepeated)(field)) {
1971
1971
  // Arrays might need their elements transformed
1972
- const transformElement = readSnippet("e");
1973
- const maybeMap = transformElement.toCodeString([]) !== "e" ? (0, ts_poet_1.code) `.map(e => ${transformElement})` : "";
1972
+ const needMap = readSnippet("e").toCodeString([]) !== "e";
1973
+ const maybeMap = needMap ? (0, ts_poet_1.code) `.map(e => ${readSnippet("e")})` : "";
1974
1974
  chunks.push((0, ts_poet_1.code) `
1975
1975
  if (${messageProperty}?.length) {
1976
1976
  ${jsonProperty} = ${messageProperty}${maybeMap};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.181.0",
3
+ "version": "1.181.2",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",