ts-proto 1.181.0 → 1.181.1

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.
Files changed (2) hide show
  1. package/build/main.js +5 -5
  2. package/package.json +1 -1
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.1",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",