From f30b02c4bf363b797de39ae63375a4f357718ae9 Mon Sep 17 00:00:00 2001 From: Marcio Cruz de Almeida <67694075+marciocadev@users.noreply.github.com> Date: Thu, 17 Aug 2023 23:32:47 -0300 Subject: [PATCH] fix(compiler): != deep inequality (#3868) The comparison below didn't show an error because it treated them as different objects. Now, the values will be compared, resulting in an error ```ts (wing) let cat1 = Cat { name: "Mittens", age: 3 }; let cat2 = Cat { name: "Mittens", age: 3 }; assert(cat1 != cat2); ``` Closes #3831 ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*. --- examples/tests/valid/deep_equality.w | 5 +++ examples/tests/valid/json_static.w | 2 +- libs/wingc/src/jsify.rs | 4 +- .../wingc/src/jsify/snapshots/enum_value.snap | 2 +- .../bucket/events.w_compile_tf-aws.md | 2 +- .../bucket/public_url.w_compile_tf-aws.md | 4 +- .../sdk_tests/util/env.w_compile_tf-aws.md | 2 +- .../valid/assert.w_compile_tf-aws.md | 12 +++--- .../valid/bring_local.w_compile_tf-aws.md | 2 +- .../valid/bring_projen.w_compile_tf-aws.md | 2 +- .../valid/deep_equality.w_compile_tf-aws.md | 39 +++++++++++++------ .../valid/json_static.w_compile_tf-aws.md | 2 +- .../test_corpus/valid/nil.w_compile_tf-aws.md | 2 +- .../valid/redis.w_compile_tf-aws.md | 2 +- 14 files changed, 52 insertions(+), 30 deletions(-) diff --git a/examples/tests/valid/deep_equality.w b/examples/tests/valid/deep_equality.w index f4c5d084494..5f63bd6b0cf 100644 --- a/examples/tests/valid/deep_equality.w +++ b/examples/tests/valid/deep_equality.w @@ -36,6 +36,7 @@ test "Json with the same value" { test "Json with different values" { assert(jsonA != jsonC); + assert(!(jsonA != jsonB)); } //----------------------------------------------------------------------------- @@ -53,6 +54,7 @@ test "Set types with the same value" { test "Set types with different values" { assert(setA != setC); + assert(!(setA != setB.copy())); } //----------------------------------------------------------------------------- @@ -69,6 +71,7 @@ test "Map with the same value" { test "Map with different values" { assert(mapA != mapC); + assert(!(mapA != mapB.copy())); } //----------------------------------------------------------------------------- @@ -85,6 +88,7 @@ test "Array with the same value" { test "Array with different values" { assert(arrayA != arrayC); + assert(!(arrayA != arrayB.copy())); } //----------------------------------------------------------------------------- @@ -106,4 +110,5 @@ test "Struct with the same value" { test "Struct with different values" { assert(cat1 != cat3); + assert(!(cat1 != cat2)); } \ No newline at end of file diff --git a/examples/tests/valid/json_static.w b/examples/tests/valid/json_static.w index bea716ce4d9..5a2b753a71a 100644 --- a/examples/tests/valid/json_static.w +++ b/examples/tests/valid/json_static.w @@ -16,7 +16,7 @@ assert(m.get("a") == 321); // Immutable Deep Copy let n = Json.deepCopy(m); -assert(m != n); +assert(m == n); // Deleting keys let var k2 = Json.keys(m); diff --git a/libs/wingc/src/jsify.rs b/libs/wingc/src/jsify.rs index fe47e9d60ba..f2805ead5e1 100644 --- a/libs/wingc/src/jsify.rs +++ b/libs/wingc/src/jsify.rs @@ -601,7 +601,9 @@ impl<'a> JSifier<'a> { BinaryOperator::Equal => { return format!("(((a,b) => {{ try {{ return require('assert').deepStrictEqual(a,b) === undefined; }} catch {{ return false; }} }})({},{}))", js_left, js_right) }, - BinaryOperator::NotEqual => "!==", + BinaryOperator::NotEqual => { + return format!("(((a,b) => {{ try {{ return require('assert').notDeepStrictEqual(a,b) === undefined; }} catch {{ return false; }} }})({},{}))", js_left, js_right) + }, BinaryOperator::LogicalAnd => "&&", BinaryOperator::LogicalOr => "||", BinaryOperator::UnwrapOr => { diff --git a/libs/wingc/src/jsify/snapshots/enum_value.snap b/libs/wingc/src/jsify/snapshots/enum_value.snap index d9bf2653085..a5145c2282b 100644 --- a/libs/wingc/src/jsify/snapshots/enum_value.snap +++ b/libs/wingc/src/jsify/snapshots/enum_value.snap @@ -26,7 +26,7 @@ module.exports = function({ $MyEnum, $x }) { return $obj; } async handle() { - {((cond) => {if (!cond) throw new Error("assertion failed: MyEnum.B != MyEnum.C")})(($MyEnum.B !== $MyEnum.C))}; + {((cond) => {if (!cond) throw new Error("assertion failed: MyEnum.B != MyEnum.C")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($MyEnum.B,$MyEnum.C)))}; {((cond) => {if (!cond) throw new Error("assertion failed: x == MyEnum.C")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })($x,$MyEnum.C)))}; } } diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/events.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/events.w_compile_tf-aws.md index 4ffe326a213..1659079abbe 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/events.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/events.w_compile_tf-aws.md @@ -195,7 +195,7 @@ module.exports = function({ $Source, $b, $checkHitCount, $util_Util, $wait }) { (await $b.put("c","1")); (await $b.put("b","100")); (await $b.delete("c")); - if (((await $util_Util.env("WING_TARGET")) !== "tf-aws")) { + if ((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })((await $util_Util.env("WING_TARGET")),"tf-aws"))) { {((cond) => {if (!cond) throw new Error("assertion failed: wait(checkHitCount(key: \"a\", type: \"onCreate()\", source: Source.anyEvent, count: 1))")})((await $wait((await $checkHitCount({ key: "a", type: "onCreate()", source: $Source.anyEvent, count: 1 })))))}; {((cond) => {if (!cond) throw new Error("assertion failed: wait(checkHitCount(key: \"b\", type: \"onCreate()\", source: Source.anyEvent, count: 1))")})((await $wait((await $checkHitCount({ key: "b", type: "onCreate()", source: $Source.anyEvent, count: 1 })))))}; {((cond) => {if (!cond) throw new Error("assertion failed: wait(checkHitCount(key: \"c\", type: \"onCreate()\", source: Source.anyEvent, count: 1))")})((await $wait((await $checkHitCount({ key: "c", type: "onCreate()", source: $Source.anyEvent, count: 1 })))))}; diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/public_url.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/public_url.w_compile_tf-aws.md index eab48ff979d..0e7cf41563f 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/public_url.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/public_url.w_compile_tf-aws.md @@ -14,8 +14,8 @@ module.exports = function({ $http_Util, $privateBucket, $publicBucket, $util_Uti (await $publicBucket.put("file1.txt","Foo")); (await $privateBucket.put("file2.txt","Bar")); const publicUrl = (await $publicBucket.publicUrl("file1.txt")); - {((cond) => {if (!cond) throw new Error("assertion failed: publicUrl != \"\"")})((publicUrl !== ""))}; - if (((await $util_Util.env("WING_TARGET")) !== "sim")) { + {((cond) => {if (!cond) throw new Error("assertion failed: publicUrl != \"\"")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(publicUrl,"")))}; + if ((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })((await $util_Util.env("WING_TARGET")),"sim"))) { {((cond) => {if (!cond) throw new Error("assertion failed: http.get(publicUrl).body == \"Foo\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((await $http_Util.get(publicUrl)).body,"Foo")))}; } try { diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/util/env.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/util/env.w_compile_tf-aws.md index 73aa4ea096a..e993670b792 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/util/env.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/util/env.w_compile_tf-aws.md @@ -188,7 +188,7 @@ class $Root extends $stdlib.std.Resource { const RANDOM = "RANDOM123412121212kjhkjskdjkj"; const NIL = "<>"; {((cond) => {if (!cond) throw new Error("assertion failed: util.env(\"PATH\").length > 0")})(((util.Util.env("PATH")).length > 0))}; - if (((util.Util.tryEnv("MY_VAR")) !== undefined)) { + if ((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })((util.Util.tryEnv("MY_VAR")),undefined))) { {((cond) => {if (!cond) throw new Error("assertion failed: util.env(\"MY_VAR\") == \"my value\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((util.Util.env("MY_VAR")),"my value")))}; } let failed = false; diff --git a/tools/hangar/__snapshots__/test_corpus/valid/assert.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/assert.w_compile_tf-aws.md index ebfddc7d047..a412abedb07 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/assert.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/assert.w_compile_tf-aws.md @@ -18,11 +18,11 @@ module.exports = function({ $s1, $s2 }) { {((cond) => {if (!cond) throw new Error("assertion failed: \"`s1`\" == \"`s1`\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })("`s1`","`s1`")))}; {((cond) => {if (!cond) throw new Error("assertion failed: s1 == s1")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })($s1,$s1)))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}\" == \"${s1}\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["", ""] }, $s1),String.raw({ raw: ["", ""] }, $s1))))}; - {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}\" != \"${s2}\"")})((String.raw({ raw: ["", ""] }, $s1) !== String.raw({ raw: ["", ""] }, $s2)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}\" != \"${s2}\"")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["", ""] }, $s1),String.raw({ raw: ["", ""] }, $s2))))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"a${s1}\" == \"a${s1}\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["a", ""] }, $s1),String.raw({ raw: ["a", ""] }, $s1))))}; - {((cond) => {if (!cond) throw new Error("assertion failed: \"a${s1}\" != \"b${s1}\"")})((String.raw({ raw: ["a", ""] }, $s1) !== String.raw({ raw: ["b", ""] }, $s1)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: \"a${s1}\" != \"b${s1}\"")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["a", ""] }, $s1),String.raw({ raw: ["b", ""] }, $s1))))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}a\" == \"${s1}a\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["", "a"] }, $s1),String.raw({ raw: ["", "a"] }, $s1))))}; - {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}a\" != \"${s1}b\"")})((String.raw({ raw: ["", "a"] }, $s1) !== String.raw({ raw: ["", "b"] }, $s1)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}a\" != \"${s1}b\"")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["", "a"] }, $s1),String.raw({ raw: ["", "b"] }, $s1))))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"`\'${s1}\" == \"`\'${s1}\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["`'", ""] }, $s1),String.raw({ raw: ["`'", ""] }, $s1))))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"a${s1}b${s2}c\" == \"a${s1}b${s2}c\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["a", "b", "c"] }, $s1, $s2),String.raw({ raw: ["a", "b", "c"] }, $s1, $s2))))}; } @@ -205,11 +205,11 @@ class $Root extends $stdlib.std.Resource { {((cond) => {if (!cond) throw new Error("assertion failed: \"`s1`\" == \"`s1`\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })("`s1`","`s1`")))}; {((cond) => {if (!cond) throw new Error("assertion failed: s1 == s1")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(s1,s1)))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}\" == \"${s1}\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["", ""] }, s1),String.raw({ raw: ["", ""] }, s1))))}; - {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}\" != \"${s2}\"")})((String.raw({ raw: ["", ""] }, s1) !== String.raw({ raw: ["", ""] }, s2)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}\" != \"${s2}\"")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["", ""] }, s1),String.raw({ raw: ["", ""] }, s2))))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"a${s1}\" == \"a${s1}\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["a", ""] }, s1),String.raw({ raw: ["a", ""] }, s1))))}; - {((cond) => {if (!cond) throw new Error("assertion failed: \"a${s1}\" != \"b${s1}\"")})((String.raw({ raw: ["a", ""] }, s1) !== String.raw({ raw: ["b", ""] }, s1)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: \"a${s1}\" != \"b${s1}\"")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["a", ""] }, s1),String.raw({ raw: ["b", ""] }, s1))))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}a\" == \"${s1}a\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["", "a"] }, s1),String.raw({ raw: ["", "a"] }, s1))))}; - {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}a\" != \"${s1}b\"")})((String.raw({ raw: ["", "a"] }, s1) !== String.raw({ raw: ["", "b"] }, s1)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: \"${s1}a\" != \"${s1}b\"")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["", "a"] }, s1),String.raw({ raw: ["", "b"] }, s1))))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"`\'${s1}\" == \"`\'${s1}\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["`'", ""] }, s1),String.raw({ raw: ["`'", ""] }, s1))))}; {((cond) => {if (!cond) throw new Error("assertion failed: \"a${s1}b${s2}c\" == \"a${s1}b${s2}c\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(String.raw({ raw: ["a", "b", "c"] }, s1, s2),String.raw({ raw: ["a", "b", "c"] }, s1, s2))))}; this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:assert works inflight",new $Closure1(this,"$Closure1")); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/bring_local.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/bring_local.w_compile_tf-aws.md index 0599af1b4d0..a835b86382e 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/bring_local.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/bring_local.w_compile_tf-aws.md @@ -486,7 +486,7 @@ class $Root extends $stdlib.std.Resource { this.node.root.new("@winglang/sdk.std.Test",std.Test,this,"test:add data to store",new $Closure1(this,"$Closure1")); const s = ({"x": 1,"y": 2}); const c = file1.Color.BLUE; - {((cond) => {if (!cond) throw new Error("assertion failed: c != file1.Color.RED")})((c !== file1.Color.RED))}; + {((cond) => {if (!cond) throw new Error("assertion failed: c != file1.Color.RED")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(c,file1.Color.RED)))}; const t = new Triangle(this,"Triangle"); } } diff --git a/tools/hangar/__snapshots__/test_corpus/valid/bring_projen.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/bring_projen.w_compile_tf-aws.md index c6f7e240c06..efb0e108d3e 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/bring_projen.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/bring_projen.w_compile_tf-aws.md @@ -42,7 +42,7 @@ const projen = require("projen"); class $Root extends $stdlib.std.Resource { constructor(scope, id) { super(scope, id); - {((cond) => {if (!cond) throw new Error("assertion failed: projen.LogLevel.OFF != projen.LogLevel.VERBOSE")})((projen.LogLevel.OFF !== projen.LogLevel.VERBOSE))}; + {((cond) => {if (!cond) throw new Error("assertion failed: projen.LogLevel.OFF != projen.LogLevel.VERBOSE")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })(projen.LogLevel.OFF,projen.LogLevel.VERBOSE)))}; } } const $App = $stdlib.core.App.for(process.env.WING_TARGET); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.w_compile_tf-aws.md index f63bd87ec8e..1857c237048 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.w_compile_tf-aws.md @@ -55,7 +55,7 @@ module.exports = function({ $numA, $numB, $strA, $strB }) { ## inflight.$Closure10-1.js ```js -module.exports = function({ $arrayA, $arrayC }) { +module.exports = function({ $_____arrayB__, $arrayA, $arrayC }) { class $Closure10 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -63,7 +63,8 @@ module.exports = function({ $arrayA, $arrayC }) { return $obj; } async handle() { - {((cond) => {if (!cond) throw new Error("assertion failed: arrayA != arrayC")})(($arrayA !== $arrayC))}; + {((cond) => {if (!cond) throw new Error("assertion failed: arrayA != arrayC")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($arrayA,$arrayC)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: !(arrayA != arrayB.copy())")})((!(((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($arrayA,$_____arrayB__))))}; } } return $Closure10; @@ -92,7 +93,7 @@ module.exports = function({ $cat1, $cat2 }) { ## inflight.$Closure12-1.js ```js -module.exports = function({ $cat1, $cat3 }) { +module.exports = function({ $cat1, $cat2, $cat3 }) { class $Closure12 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -100,7 +101,8 @@ module.exports = function({ $cat1, $cat3 }) { return $obj; } async handle() { - {((cond) => {if (!cond) throw new Error("assertion failed: cat1 != cat3")})(($cat1 !== $cat3))}; + {((cond) => {if (!cond) throw new Error("assertion failed: cat1 != cat3")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($cat1,$cat3)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: !(cat1 != cat2)")})((!(((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($cat1,$cat2))))}; } } return $Closure12; @@ -118,8 +120,8 @@ module.exports = function({ $numA, $numC, $strA, $strC }) { return $obj; } async handle() { - {((cond) => {if (!cond) throw new Error("assertion failed: numA != numC")})(($numA !== $numC))}; - {((cond) => {if (!cond) throw new Error("assertion failed: strA != strC")})(($strA !== $strC))}; + {((cond) => {if (!cond) throw new Error("assertion failed: numA != numC")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($numA,$numC)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: strA != strC")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($strA,$strC)))}; } } return $Closure2; @@ -148,7 +150,7 @@ module.exports = function({ $jsonA, $jsonB }) { ## inflight.$Closure4-1.js ```js -module.exports = function({ $jsonA, $jsonC }) { +module.exports = function({ $jsonA, $jsonB, $jsonC }) { class $Closure4 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -156,7 +158,8 @@ module.exports = function({ $jsonA, $jsonC }) { return $obj; } async handle() { - {((cond) => {if (!cond) throw new Error("assertion failed: jsonA != jsonC")})(($jsonA !== $jsonC))}; + {((cond) => {if (!cond) throw new Error("assertion failed: jsonA != jsonC")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($jsonA,$jsonC)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: !(jsonA != jsonB)")})((!(((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($jsonA,$jsonB))))}; } } return $Closure4; @@ -185,7 +188,7 @@ module.exports = function({ $new_Set_setB_, $setA }) { ## inflight.$Closure6-1.js ```js -module.exports = function({ $setA, $setC }) { +module.exports = function({ $new_Set_setB_, $setA, $setC }) { class $Closure6 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -193,7 +196,8 @@ module.exports = function({ $setA, $setC }) { return $obj; } async handle() { - {((cond) => {if (!cond) throw new Error("assertion failed: setA != setC")})(($setA !== $setC))}; + {((cond) => {if (!cond) throw new Error("assertion failed: setA != setC")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($setA,$setC)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: !(setA != setB.copy())")})((!(((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($setA,$new_Set_setB_))))}; } } return $Closure6; @@ -222,7 +226,7 @@ module.exports = function({ $______mapB___, $mapA }) { ## inflight.$Closure8-1.js ```js -module.exports = function({ $mapA, $mapC }) { +module.exports = function({ $______mapB___, $mapA, $mapC }) { class $Closure8 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -230,7 +234,8 @@ module.exports = function({ $mapA, $mapC }) { return $obj; } async handle() { - {((cond) => {if (!cond) throw new Error("assertion failed: mapA != mapC")})(($mapA !== $mapC))}; + {((cond) => {if (!cond) throw new Error("assertion failed: mapA != mapC")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($mapA,$mapC)))}; + {((cond) => {if (!cond) throw new Error("assertion failed: !(mapA != mapB.copy())")})((!(((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })($mapA,$______mapB___))))}; } } return $Closure8; @@ -1230,6 +1235,7 @@ class $Root extends $stdlib.std.Resource { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure4-1.js")({ $jsonA: ${context._lift(jsonA)}, + $jsonB: ${context._lift(jsonB)}, $jsonC: ${context._lift(jsonC)}, }) `); @@ -1248,6 +1254,7 @@ class $Root extends $stdlib.std.Resource { _registerBind(host, ops) { if (ops.includes("handle")) { $Closure4._registerBindObject(jsonA, host, []); + $Closure4._registerBindObject(jsonB, host, []); $Closure4._registerBindObject(jsonC, host, []); } super._registerBind(host, ops); @@ -1295,6 +1302,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType(context) { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure6-1.js")({ + $new_Set_setB_: ${context._lift(new Set(setB))}, $setA: ${context._lift(setA)}, $setC: ${context._lift(setC)}, }) @@ -1313,6 +1321,7 @@ class $Root extends $stdlib.std.Resource { } _registerBind(host, ops) { if (ops.includes("handle")) { + $Closure6._registerBindObject(new Set(setB), host, []); $Closure6._registerBindObject(setA, host, []); $Closure6._registerBindObject(setC, host, []); } @@ -1361,6 +1370,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType(context) { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure8-1.js")({ + $______mapB___: ${context._lift(({...(mapB)}))}, $mapA: ${context._lift(mapA)}, $mapC: ${context._lift(mapC)}, }) @@ -1379,6 +1389,7 @@ class $Root extends $stdlib.std.Resource { } _registerBind(host, ops) { if (ops.includes("handle")) { + $Closure8._registerBindObject(({...(mapB)}), host, []); $Closure8._registerBindObject(mapA, host, []); $Closure8._registerBindObject(mapC, host, []); } @@ -1427,6 +1438,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType(context) { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure10-1.js")({ + $_____arrayB__: ${context._lift([...(arrayB)])}, $arrayA: ${context._lift(arrayA)}, $arrayC: ${context._lift(arrayC)}, }) @@ -1445,6 +1457,7 @@ class $Root extends $stdlib.std.Resource { } _registerBind(host, ops) { if (ops.includes("handle")) { + $Closure10._registerBindObject([...(arrayB)], host, []); $Closure10._registerBindObject(arrayA, host, []); $Closure10._registerBindObject(arrayC, host, []); } @@ -1494,6 +1507,7 @@ class $Root extends $stdlib.std.Resource { return $stdlib.core.NodeJsCode.fromInline(` require("./inflight.$Closure12-1.js")({ $cat1: ${context._lift(cat1)}, + $cat2: ${context._lift(cat2)}, $cat3: ${context._lift(cat3)}, }) `); @@ -1512,6 +1526,7 @@ class $Root extends $stdlib.std.Resource { _registerBind(host, ops) { if (ops.includes("handle")) { $Closure12._registerBindObject(cat1, host, []); + $Closure12._registerBindObject(cat2, host, []); $Closure12._registerBindObject(cat3, host, []); } super._registerBind(host, ops); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/json_static.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/json_static.w_compile_tf-aws.md index 02375306157..fb852946d35 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/json_static.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/json_static.w_compile_tf-aws.md @@ -302,7 +302,7 @@ class $Root extends $stdlib.std.Resource { ((obj, args) => { obj[args[0]] = args[1]; })(m, ["a",321]); {((cond) => {if (!cond) throw new Error("assertion failed: m.get(\"a\") == 321")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((m)["a"],321)))}; const n = JSON.parse(JSON.stringify(m)); - {((cond) => {if (!cond) throw new Error("assertion failed: m != n")})((m !== n))}; + {((cond) => {if (!cond) throw new Error("assertion failed: m == n")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(m,n)))}; let k2 = (Object.keys(m)); {((cond) => {if (!cond) throw new Error("assertion failed: k2.length == 2")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(k2.length,2)))}; ((args) => { delete (args[0])[args[1]]; })([m,"b"]); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/nil.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/nil.w_compile_tf-aws.md index bd40c2f3a44..41596c3afa9 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/nil.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/nil.w_compile_tf-aws.md @@ -32,7 +32,7 @@ module.exports = function({ $foo }) { {((cond) => {if (!cond) throw new Error("assertion failed: foo.getOptionalValue()? == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((((await $foo.getOptionalValue())) != null),false)))}; (await $foo.setOptionalValue("hello")); {((cond) => {if (!cond) throw new Error("assertion failed: foo.getOptionalValue()? == true")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((((await $foo.getOptionalValue())) != null),true)))}; - {((cond) => {if (!cond) throw new Error("assertion failed: foo.getOptionalValue() != nil")})(((await $foo.getOptionalValue()) !== undefined))}; + {((cond) => {if (!cond) throw new Error("assertion failed: foo.getOptionalValue() != nil")})((((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })((await $foo.getOptionalValue()),undefined)))}; (await $foo.setOptionalValue(undefined)); {((cond) => {if (!cond) throw new Error("assertion failed: foo.getOptionalValue()? == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((((await $foo.getOptionalValue())) != null),false)))}; {((cond) => {if (!cond) throw new Error("assertion failed: foo.getOptionalValue() == nil")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((await $foo.getOptionalValue()),undefined)))}; diff --git a/tools/hangar/__snapshots__/test_corpus/valid/redis.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/redis.w_compile_tf-aws.md index 451cba7d702..0daf2c3c215 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/redis.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/redis.w_compile_tf-aws.md @@ -37,7 +37,7 @@ module.exports = function({ $queue, $r, $r2, $util_Util }) { {((cond) => {if (!cond) throw new Error("assertion failed: value2 == \"does redis again\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(value2,"does redis again")))}; (await $queue.push("world!")); (await $util_Util.waitUntil(async () => { - return ((await $r.get("hello")) !== undefined); + return (((a,b) => { try { return require('assert').notDeepStrictEqual(a,b) === undefined; } catch { return false; } })((await $r.get("hello")),undefined)); } )); {((cond) => {if (!cond) throw new Error("assertion failed: \"world!\" == \"${r.get(\"hello\")}\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })("world!",String.raw({ raw: ["", ""] }, (await $r.get("hello"))))))};