Change nodejs codegen to use coalescing operator when when default values are present (#6496)

This commit is contained in:
Paul Stack 2021-03-10 21:16:18 +00:00 committed by GitHub
parent c48ba37fcf
commit 1f16423ede
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View file

@ -62,10 +62,10 @@ export class RubberTree extends pulumi.CustomResource {
throw new Error("Missing required property 'type'");
}
inputs["container"] = args ? args.container : undefined;
inputs["diameter"] = (args ? args.diameter : undefined) || 6;
inputs["farm"] = (args ? args.farm : undefined) || "(unknown)";
inputs["size"] = (args ? args.size : undefined) || "medium";
inputs["type"] = (args ? args.type : undefined) || "Burgundy";
inputs["diameter"] = (args ? args.diameter : undefined) ?? 6;
inputs["farm"] = (args ? args.farm : undefined) ?? "(unknown)";
inputs["size"] = (args ? args.size : undefined) ?? "medium";
inputs["type"] = (args ? args.type : undefined) ?? "Burgundy";
}
if (!opts.version) {
opts = pulumi.mergeOptions(opts, { version: utilities.getVersion()});

View file

@ -583,13 +583,8 @@ func (mod *modContext) genResource(w io.Writer, r *schema.Resource) error {
if err != nil {
return err
}
// Note: this logic isn't quite correct, but already exists in all of the TF-based providers.
// Specifically, this doesn't work right if the first value is set to false but the default value
// is true. The Kubernetes provider didn't include this logic, so use the correct ?? operator there.
arg = fmt.Sprintf("(%s) || %s", arg, dv)
if mod.compatibility == kubernetes20 {
arg = fmt.Sprintf("(%s) ?? %s", arg, dv)
}
arg = fmt.Sprintf("(%s) ?? %s", arg, dv)
}
// provider properties must be marshaled as JSON strings.