From 745df1efa28a64514cb0d5b0d853a0d25392a22d Mon Sep 17 00:00:00 2001 From: yoav-steinberg Date: Sun, 25 Feb 2024 12:55:39 +0200 Subject: [PATCH] fix(compiler): methods on tokenized strings used inflight use lifted non evaluated string (#5766) See #4292. We now special case access to phase independent properties of string objects. Such properties will get the phase of the execution environment so when used inflight we'll use the evaluated tokenized string. ## 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)*. --- .../phase_independent_method_on_string.test.w | 22 ++ .../access_property_on_primitive.snap | 10 +- ...rty_on_value_returned_from_collection.snap | 10 +- ...er_from_preflight_scope_with_property.snap | 10 +- .../snapshots/preflight_value_field.snap | 9 +- .../snapshots/reference_preflight_fields.snap | 12 +- libs/wingc/src/type_check.rs | 10 +- .../inflight_concat.test.w_compile_tf-aws.md | 12 +- ..._method_on_string.test.w_compile_tf-aws.md | 198 ++++++++++++++++++ ...endent_method_on_string.test.w_test_sim.md | 12 ++ .../valid/std_string.test.w_compile_tf-aws.md | 23 +- 11 files changed, 280 insertions(+), 48 deletions(-) create mode 100644 examples/tests/valid/phase_independent_method_on_string.test.w create mode 100644 tools/hangar/__snapshots__/test_corpus/valid/phase_independent_method_on_string.test.w_compile_tf-aws.md create mode 100644 tools/hangar/__snapshots__/test_corpus/valid/phase_independent_method_on_string.test.w_test_sim.md diff --git a/examples/tests/valid/phase_independent_method_on_string.test.w b/examples/tests/valid/phase_independent_method_on_string.test.w new file mode 100644 index 00000000000..0032f666629 --- /dev/null +++ b/examples/tests/valid/phase_independent_method_on_string.test.w @@ -0,0 +1,22 @@ +bring cloud; +bring regex; + +let api = new cloud.Api(); +let url_regex = "https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]\{1,256\}\\.[a-zA-Z0-9()]\{1,6\}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)"; + +// Verify the url is not a valid url (because it's a token) +assert(!regex.match(url_regex, api.url)); + +let token_len = api.url.length; + + +test "phase independent method on string evaluated inflight" { + // Make sure api.url isn't a token but evaled inflight + assert(regex.match(url_regex, api.url)); + + // Call a method on the url (should be called inflight) + assert(api.url.startsWith("http")); + + // Call the length property (should be called inflight) and make sure it's different than the preflight length + assert(api.url.length != token_len); +} \ No newline at end of file diff --git a/libs/wingc/src/jsify/snapshots/access_property_on_primitive.snap b/libs/wingc/src/jsify/snapshots/access_property_on_primitive.snap index db063717aed..550ac55b8dc 100644 --- a/libs/wingc/src/jsify/snapshots/access_property_on_primitive.snap +++ b/libs/wingc/src/jsify/snapshots/access_property_on_primitive.snap @@ -18,7 +18,7 @@ source: libs/wingc/src/jsify/tests.rs ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $s_length }) { +module.exports = function({ $s }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -26,7 +26,7 @@ module.exports = function({ $s_length }) { return $obj; } async handle() { - $helpers.assert($helpers.eq($s_length, 5), "s.length == 5"); + $helpers.assert($helpers.eq($s.length, 5), "s.length == 5"); } } return $Closure1; @@ -56,7 +56,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType() { return ` require("${$helpers.normalPath(__dirname)}/inflight.$Closure1-1.js")({ - $s_length: ${$stdlib.core.liftObject(s.length)}, + $s: ${$stdlib.core.liftObject(s)}, }) `; } @@ -74,10 +74,10 @@ class $Root extends $stdlib.std.Resource { get _liftMap() { return ({ "handle": [ - [s.length, []], + [s, ["length"]], ], "$inflight_init": [ - [s.length, []], + [s, []], ], }); } diff --git a/libs/wingc/src/jsify/snapshots/access_property_on_value_returned_from_collection.snap b/libs/wingc/src/jsify/snapshots/access_property_on_value_returned_from_collection.snap index e7564f13536..8ea6b38c994 100644 --- a/libs/wingc/src/jsify/snapshots/access_property_on_value_returned_from_collection.snap +++ b/libs/wingc/src/jsify/snapshots/access_property_on_value_returned_from_collection.snap @@ -18,7 +18,7 @@ source: libs/wingc/src/jsify/tests.rs ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $__obj__key_______if____key_in_obj___throw_new_Error__Map_does_not_contain_key_____key______return_obj_key______s___hello___length }) { +module.exports = function({ $__obj__key_______if____key_in_obj___throw_new_Error__Map_does_not_contain_key_____key______return_obj_key______s___hello__ }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -26,7 +26,7 @@ module.exports = function({ $__obj__key_______if____key_in_obj___throw_new_Error return $obj; } async handle() { - $helpers.assert($helpers.eq($__obj__key_______if____key_in_obj___throw_new_Error__Map_does_not_contain_key_____key______return_obj_key______s___hello___length, 3), "s.get(\"hello\").length == 3"); + $helpers.assert($helpers.eq($__obj__key_______if____key_in_obj___throw_new_Error__Map_does_not_contain_key_____key______return_obj_key______s___hello__.length, 3), "s.get(\"hello\").length == 3"); } } return $Closure1; @@ -56,7 +56,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType() { return ` require("${$helpers.normalPath(__dirname)}/inflight.$Closure1-1.js")({ - $__obj__key_______if____key_in_obj___throw_new_Error__Map_does_not_contain_key_____key______return_obj_key______s___hello___length: ${$stdlib.core.liftObject(((obj, key) => { if (!(key in obj)) throw new Error(`Map does not contain key: "${key}"`); return obj[key]; })(s, "hello").length)}, + $__obj__key_______if____key_in_obj___throw_new_Error__Map_does_not_contain_key_____key______return_obj_key______s___hello__: ${$stdlib.core.liftObject(((obj, key) => { if (!(key in obj)) throw new Error(`Map does not contain key: "${key}"`); return obj[key]; })(s, "hello"))}, }) `; } @@ -74,10 +74,10 @@ class $Root extends $stdlib.std.Resource { get _liftMap() { return ({ "handle": [ - [((obj, key) => { if (!(key in obj)) throw new Error(`Map does not contain key: "${key}"`); return obj[key]; })(s, "hello").length, []], + [((obj, key) => { if (!(key in obj)) throw new Error(`Map does not contain key: "${key}"`); return obj[key]; })(s, "hello"), ["length"]], ], "$inflight_init": [ - [((obj, key) => { if (!(key in obj)) throw new Error(`Map does not contain key: "${key}"`); return obj[key]; })(s, "hello").length, []], + [((obj, key) => { if (!(key in obj)) throw new Error(`Map does not contain key: "${key}"`); return obj[key]; })(s, "hello"), []], ], }); } diff --git a/libs/wingc/src/jsify/snapshots/capture_identifier_from_preflight_scope_with_property.snap b/libs/wingc/src/jsify/snapshots/capture_identifier_from_preflight_scope_with_property.snap index 15c8d5d6bd3..cd88ea97ffd 100644 --- a/libs/wingc/src/jsify/snapshots/capture_identifier_from_preflight_scope_with_property.snap +++ b/libs/wingc/src/jsify/snapshots/capture_identifier_from_preflight_scope_with_property.snap @@ -17,7 +17,7 @@ source: libs/wingc/src/jsify/tests.rs ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $x_length }) { +module.exports = function({ $x }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -25,7 +25,7 @@ module.exports = function({ $x_length }) { return $obj; } async handle() { - $helpers.assert(($x_length > 0), "x.length > 0"); + $helpers.assert(($x.length > 0), "x.length > 0"); } } return $Closure1; @@ -55,7 +55,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType() { return ` require("${$helpers.normalPath(__dirname)}/inflight.$Closure1-1.js")({ - $x_length: ${$stdlib.core.liftObject(x.length)}, + $x: ${$stdlib.core.liftObject(x)}, }) `; } @@ -73,10 +73,10 @@ class $Root extends $stdlib.std.Resource { get _liftMap() { return ({ "handle": [ - [x.length, []], + [x, ["length"]], ], "$inflight_init": [ - [x.length, []], + [x, []], ], }); } diff --git a/libs/wingc/src/jsify/snapshots/preflight_value_field.snap b/libs/wingc/src/jsify/snapshots/preflight_value_field.snap index 5503e35e0d7..185a9759082 100644 --- a/libs/wingc/src/jsify/snapshots/preflight_value_field.snap +++ b/libs/wingc/src/jsify/snapshots/preflight_value_field.snap @@ -30,7 +30,7 @@ source: libs/wingc/src/jsify/tests.rs ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $t_last, $t_name, $t_name_length }) { +module.exports = function({ $t_last, $t_name }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -39,7 +39,7 @@ module.exports = function({ $t_last, $t_name, $t_name_length }) { } async handle() { console.log($t_name); - $helpers.assert(($t_name_length > 0), "t.name.length > 0"); + $helpers.assert(($t_name.length > 0), "t.name.length > 0"); console.log($t_last); } } @@ -117,7 +117,6 @@ class $Root extends $stdlib.std.Resource { require("${$helpers.normalPath(__dirname)}/inflight.$Closure1-1.js")({ $t_last: ${$stdlib.core.liftObject(t.last)}, $t_name: ${$stdlib.core.liftObject(t.name)}, - $t_name_length: ${$stdlib.core.liftObject(t.name.length)}, }) `; } @@ -136,13 +135,11 @@ class $Root extends $stdlib.std.Resource { return ({ "handle": [ [t.last, []], - [t.name, []], - [t.name.length, []], + [t.name, ["length"]], ], "$inflight_init": [ [t.last, []], [t.name, []], - [t.name.length, []], ], }); } diff --git a/libs/wingc/src/jsify/snapshots/reference_preflight_fields.snap b/libs/wingc/src/jsify/snapshots/reference_preflight_fields.snap index d91319998b0..e388418ee39 100644 --- a/libs/wingc/src/jsify/snapshots/reference_preflight_fields.snap +++ b/libs/wingc/src/jsify/snapshots/reference_preflight_fields.snap @@ -36,12 +36,12 @@ source: libs/wingc/src/jsify/tests.rs const $helpers = require("@winglang/sdk/lib/helpers"); module.exports = function({ }) { class MyType { - constructor({ $this_b, $this_s_length }) { + constructor({ $this_b, $this_s }) { this.$this_b = $this_b; - this.$this_s_length = $this_s_length; + this.$this_s = $this_s; } async boom() { - $helpers.assert((this.$this_s_length > 0), "this.s.length > 0"); + $helpers.assert((this.$this_s.length > 0), "this.s.length > 0"); $helpers.assert(((await this.$this_b.list()).length > 0), "this.b.list().length > 0"); } async bam() { @@ -86,7 +86,7 @@ class $Root extends $stdlib.std.Resource { const MyTypeClient = ${MyType._toInflightType()}; const client = new MyTypeClient({ $this_b: ${$stdlib.core.liftObject(this.b)}, - $this_s_length: ${$stdlib.core.liftObject(this.s.length)}, + $this_s: ${$stdlib.core.liftObject(this.s)}, }); if (client.$inflight_init) { await client.$inflight_init(); } return client; @@ -97,14 +97,14 @@ class $Root extends $stdlib.std.Resource { return ({ "boom": [ [this.b, ["list"]], - [this.s.length, []], + [this.s, ["length"]], ], "bam": [ [this.b, ["get", "put"]], ], "$inflight_init": [ [this.b, []], - [this.s.length, []], + [this.s, []], ], }); } diff --git a/libs/wingc/src/type_check.rs b/libs/wingc/src/type_check.rs index 6d408e9010b..81d0dd91e6b 100644 --- a/libs/wingc/src/type_check.rs +++ b/libs/wingc/src/type_check.rs @@ -5481,9 +5481,15 @@ impl<'a> TypeChecker<'a> { // Try to resolve phase independent property's actual phase property_phase = if property_phase == Phase::Independent { + // If the object is a string we treat the phase independent property based on our env. + // Strings might be tokens and not evaluated yet. Tokenized strings accessed inflight + // must be evaluated in inflight. + if instance_type.is_string() { + env.phase + } // When the property is phase independent and either the object phase is inflight or we're - // passing inflight args to the method call, then we need treat the property as inflight too - if instance_phase == Phase::Inflight || callee_with_inflight_args { + // passing inflight args to the method call, then we need treat the property as inflight too. + else if instance_phase == Phase::Inflight || callee_with_inflight_args { Phase::Inflight } else { // Default to instance phase diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inflight_concat.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/inflight_concat.test.w_compile_tf-aws.md index 40f6627bfc9..850fc6800c2 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inflight_concat.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inflight_concat.test.w_compile_tf-aws.md @@ -6,11 +6,11 @@ const $helpers = require("@winglang/sdk/lib/helpers"); module.exports = function({ }) { class R { - constructor({ $_this_s1_concat___world___ }) { - this.$_this_s1_concat___world___ = $_this_s1_concat___world___; + constructor({ $this_s1 }) { + this.$this_s1 = $this_s1; } async foo() { - console.log(this.$_this_s1_concat___world___); + console.log((await this.$this_s1.concat(" world"))); } } return R; @@ -66,7 +66,7 @@ class $Root extends $stdlib.std.Resource { (await (async () => { const RClient = ${R._toInflightType()}; const client = new RClient({ - $_this_s1_concat___world___: ${$stdlib.core.liftObject((this.s1.concat(" world")))}, + $this_s1: ${$stdlib.core.liftObject(this.s1)}, }); if (client.$inflight_init) { await client.$inflight_init(); } return client; @@ -76,10 +76,10 @@ class $Root extends $stdlib.std.Resource { get _liftMap() { return ({ "foo": [ - [(this.s1.concat(" world")), []], + [this.s1, ["concat"]], ], "$inflight_init": [ - [(this.s1.concat(" world")), []], + [this.s1, []], ], }); } diff --git a/tools/hangar/__snapshots__/test_corpus/valid/phase_independent_method_on_string.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/phase_independent_method_on_string.test.w_compile_tf-aws.md new file mode 100644 index 00000000000..c0208f67097 --- /dev/null +++ b/tools/hangar/__snapshots__/test_corpus/valid/phase_independent_method_on_string.test.w_compile_tf-aws.md @@ -0,0 +1,198 @@ +# [phase_independent_method_on_string.test.w](../../../../../examples/tests/valid/phase_independent_method_on_string.test.w) | compile | tf-aws + +## inflight.$Closure1-1.js +```js +"use strict"; +const $helpers = require("@winglang/sdk/lib/helpers"); +module.exports = function({ $api_url, $regex_Util, $token_len, $url_regex }) { + class $Closure1 { + constructor({ }) { + const $obj = (...args) => this.handle(...args); + Object.setPrototypeOf($obj, this); + return $obj; + } + async handle() { + $helpers.assert((await $regex_Util.match($url_regex, $api_url)), "regex.match(url_regex, api.url)"); + $helpers.assert($api_url.startsWith("http"), "api.url.startsWith(\"http\")"); + $helpers.assert($helpers.neq($api_url.length, $token_len), "api.url.length != token_len"); + } + } + return $Closure1; +} +//# sourceMappingURL=inflight.$Closure1-1.js.map +``` + +## main.tf.json +```json +{ + "//": { + "metadata": { + "backend": "local", + "stackName": "root", + "version": "0.20.3" + }, + "outputs": { + "root": { + "Default": { + "Default": { + "cloud.Api": { + "Endpoint": { + "Url": "cloudApi_Endpoint_Url_CD8AC9A6" + } + } + } + } + } + } + }, + "data": { + "aws_caller_identity": { + "account": { + "//": { + "metadata": { + "path": "root/Default/account", + "uniqueId": "account" + } + } + } + }, + "aws_region": { + "Region": { + "//": { + "metadata": { + "path": "root/Default/Region", + "uniqueId": "Region" + } + } + } + } + }, + "output": { + "cloudApi_Endpoint_Url_CD8AC9A6": { + "value": "https://${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}.execute-api.${data.aws_region.Region.name}.amazonaws.com/${aws_api_gateway_stage.cloudApi_api_stage_BBB283E4.stage_name}" + } + }, + "provider": { + "aws": [ + {} + ] + }, + "resource": { + "aws_api_gateway_deployment": { + "cloudApi_api_deployment_545514BF": { + "//": { + "metadata": { + "path": "root/Default/Default/cloud.Api/api/deployment", + "uniqueId": "cloudApi_api_deployment_545514BF" + } + }, + "lifecycle": { + "create_before_destroy": true + }, + "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", + "triggers": { + "redeployment": "${sha256(aws_api_gateway_rest_api.cloudApi_api_2B334D75.body)}" + } + } + }, + "aws_api_gateway_rest_api": { + "cloudApi_api_2B334D75": { + "//": { + "metadata": { + "path": "root/Default/Default/cloud.Api/api/api", + "uniqueId": "cloudApi_api_2B334D75" + } + }, + "body": "{\"openapi\":\"3.0.3\",\"paths\":{\"/{proxy+}\":{\"x-amazon-apigateway-any-method\":{\"produces\":[\"application/json\"],\"x-amazon-apigateway-integration\":{\"type\":\"mock\",\"requestTemplates\":{\"application/json\":\"\\n {\\\"statusCode\\\": 404}\\n \"},\"passthroughBehavior\":\"never\",\"responses\":{\"404\":{\"statusCode\":\"404\",\"responseParameters\":{\"method.response.header.Content-Type\":\"'application/json'\"},\"responseTemplates\":{\"application/json\":\"{\\\"statusCode\\\": 404, \\\"message\\\": \\\"Error: Resource not found\\\"}\"}},\"default\":{\"statusCode\":\"404\",\"responseParameters\":{\"method.response.header.Content-Type\":\"'application/json'\"},\"responseTemplates\":{\"application/json\":\"{\\\"statusCode\\\": 404, \\\"message\\\": \\\"Error: Resource not found\\\"}\"}}}},\"responses\":{\"404\":{\"description\":\"404 response\",\"headers\":{\"Content-Type\":{\"type\":\"string\"}}}}}}}}", + "lifecycle": { + "create_before_destroy": true + }, + "name": "api-c895068c" + } + }, + "aws_api_gateway_stage": { + "cloudApi_api_stage_BBB283E4": { + "//": { + "metadata": { + "path": "root/Default/Default/cloud.Api/api/stage", + "uniqueId": "cloudApi_api_stage_BBB283E4" + } + }, + "deployment_id": "${aws_api_gateway_deployment.cloudApi_api_deployment_545514BF.id}", + "rest_api_id": "${aws_api_gateway_rest_api.cloudApi_api_2B334D75.id}", + "stage_name": "prod" + } + } + } +} +``` + +## preflight.js +```js +"use strict"; +const $stdlib = require('@winglang/sdk'); +const $platforms = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLATFORMS); +const $outdir = process.env.WING_SYNTH_DIR ?? "."; +const $wing_is_test = process.env.WING_IS_TEST === "true"; +const std = $stdlib.std; +const $helpers = $stdlib.helpers; +const cloud = $stdlib.cloud; +const regex = $stdlib.regex; +class $Root extends $stdlib.std.Resource { + constructor($scope, $id) { + super($scope, $id); + class $Closure1 extends $stdlib.std.AutoIdResource { + _id = $stdlib.core.closureId(); + constructor($scope, $id, ) { + super($scope, $id); + $helpers.nodeof(this).hidden = true; + } + static _toInflightType() { + return ` + require("${$helpers.normalPath(__dirname)}/inflight.$Closure1-1.js")({ + $api_url: ${$stdlib.core.liftObject(api.url)}, + $regex_Util: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(regex.Util, "@winglang/sdk/regex", "Util"))}, + $token_len: ${$stdlib.core.liftObject(token_len)}, + $url_regex: ${$stdlib.core.liftObject(url_regex)}, + }) + `; + } + _toInflight() { + return ` + (await (async () => { + const $Closure1Client = ${$Closure1._toInflightType()}; + const client = new $Closure1Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `; + } + get _liftMap() { + return ({ + "handle": [ + [api.url, ["length", "startsWith"]], + [token_len, []], + [url_regex, []], + ], + "$inflight_init": [ + [api.url, []], + [token_len, []], + [url_regex, []], + ], + }); + } + } + const api = this.node.root.new("@winglang/sdk.cloud.Api", cloud.Api, this, "cloud.Api"); + const url_regex = "https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256\}\\.[a-zA-Z0-9()]{1,6\}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)"; + $helpers.assert((!(regex.Util.match(url_regex, api.url))), "!regex.match(url_regex, api.url)"); + const token_len = api.url.length; + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:phase independent method on string evaluated inflight", new $Closure1(this, "$Closure1")); + } +} +const $PlatformManager = new $stdlib.platform.PlatformManager({platformPaths: $platforms}); +const $APP = $PlatformManager.createApp({ outdir: $outdir, name: "phase_independent_method_on_string.test", rootConstruct: $Root, isTestEnvironment: $wing_is_test, entrypointDir: process.env['WING_SOURCE_DIR'], rootId: process.env['WING_ROOT_ID'] }); +$APP.synth(); +//# sourceMappingURL=preflight.js.map +``` + diff --git a/tools/hangar/__snapshots__/test_corpus/valid/phase_independent_method_on_string.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/valid/phase_independent_method_on_string.test.w_test_sim.md new file mode 100644 index 00000000000..0ef6bf95f57 --- /dev/null +++ b/tools/hangar/__snapshots__/test_corpus/valid/phase_independent_method_on_string.test.w_test_sim.md @@ -0,0 +1,12 @@ +# [phase_independent_method_on_string.test.w](../../../../../examples/tests/valid/phase_independent_method_on_string.test.w) | test | sim + +## stdout.log +```log +pass ─ phase_independent_method_on_string.test.wsim » root/env0/test:phase independent method on string evaluated inflight + + +Tests 1 passed (1) +Test Files 1 passed (1) +Duration +``` + diff --git a/tools/hangar/__snapshots__/test_corpus/valid/std_string.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/std_string.test.w_compile_tf-aws.md index e4a31388c64..dc3d682f55e 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/std_string.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/std_string.test.w_compile_tf-aws.md @@ -4,7 +4,7 @@ ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $__arr__index_______if__index___0____index____arr_length__throw_new_Error__Index_out_of_bounds____return_arr_index_______s1_split________1_, $_s1_concat_s2__, $s1_indexOf__s__ }) { +module.exports = function({ $s1, $s2 }) { class $Closure1 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -12,9 +12,9 @@ module.exports = function({ $__arr__index_______if__index___0____index____arr_le return $obj; } async handle() { - console.log(String.raw({ raw: ["index of \"s\" in s1 is ", ""] }, $s1_indexOf__s__)); - console.log($__arr__index_______if__index___0____index____arr_length__throw_new_Error__Index_out_of_bounds____return_arr_index_______s1_split________1_); - console.log($_s1_concat_s2__); + console.log(String.raw({ raw: ["index of \"s\" in s1 is ", ""] }, $s1.indexOf("s"))); + console.log(((arr, index) => { if (index < 0 || index >= arr.length) throw new Error("Index out of bounds"); return arr[index]; })((await $s1.split(" ")), 1)); + console.log((await $s1.concat($s2))); } } return $Closure1; @@ -62,9 +62,8 @@ class $Root extends $stdlib.std.Resource { static _toInflightType() { return ` require("${$helpers.normalPath(__dirname)}/inflight.$Closure1-1.js")({ - $__arr__index_______if__index___0____index____arr_length__throw_new_Error__Index_out_of_bounds____return_arr_index_______s1_split________1_: ${$stdlib.core.liftObject(((arr, index) => { if (index < 0 || index >= arr.length) throw new Error("Index out of bounds"); return arr[index]; })((s1.split(" ")), 1))}, - $_s1_concat_s2__: ${$stdlib.core.liftObject((s1.concat(s2)))}, - $s1_indexOf__s__: ${$stdlib.core.liftObject(s1.indexOf("s"))}, + $s1: ${$stdlib.core.liftObject(s1)}, + $s2: ${$stdlib.core.liftObject(s2)}, }) `; } @@ -82,14 +81,12 @@ class $Root extends $stdlib.std.Resource { get _liftMap() { return ({ "handle": [ - [((arr, index) => { if (index < 0 || index >= arr.length) throw new Error("Index out of bounds"); return arr[index]; })((s1.split(" ")), 1), []], - [(s1.concat(s2)), []], - [s1.indexOf("s"), []], + [s1, ["concat", "indexOf", "split"]], + [s2, []], ], "$inflight_init": [ - [((arr, index) => { if (index < 0 || index >= arr.length) throw new Error("Index out of bounds"); return arr[index]; })((s1.split(" ")), 1), []], - [(s1.concat(s2)), []], - [s1.indexOf("s"), []], + [s1, []], + [s2, []], ], }); }