From 5b088445c68729f2af2f08d4ee1be8ef8977c7fb Mon Sep 17 00:00:00 2001 From: Marcio Cruz de Almeida Date: Fri, 18 Aug 2023 15:03:51 -0300 Subject: [PATCH 1/8] feat(compiler): elif let statement --- examples/tests/valid/optionals.w | 11 ++ libs/tree-sitter-wing/grammar.js | 11 ++ .../test/corpus/statements/statements.txt | 21 +++ libs/wingc/src/ast.rs | 9 + libs/wingc/src/fold.rs | 18 +- libs/wingc/src/jsify.rs | 23 +++ libs/wingc/src/lsp/hover.rs | 6 + libs/wingc/src/parser.rs | 21 ++- libs/wingc/src/type_check.rs | 160 ++++++++++-------- libs/wingc/src/visit.rs | 6 + .../valid/optionals.w_compile_tf-aws.md | 21 +++ .../test_corpus/valid/optionals.w_test_sim.md | 1 + 12 files changed, 230 insertions(+), 78 deletions(-) diff --git a/examples/tests/valid/optionals.w b/examples/tests/valid/optionals.w index 0ca09eb0423..5e42973939e 100644 --- a/examples/tests/valid/optionals.w +++ b/examples/tests/valid/optionals.w @@ -58,6 +58,17 @@ let tryParseName = (fullName: str): Name? => { }; }; +let json_obj = Json { ghost: "spooky" }; +if let y = json_obj.tryAsBool() { + log("it's a boolean!"); +} elif let y = json_obj.tryAsNum() { + log("it's a number!"); +} elif let y = json_obj.tryAsStr() { + log("it's a str!"); +} else { + log("it's something else!"); +} + // if lets reassignable let a: num? = 1; if let var z = a { diff --git a/libs/tree-sitter-wing/grammar.js b/libs/tree-sitter-wing/grammar.js index c9d8ae40ad5..da70cb6f296 100644 --- a/libs/tree-sitter-wing/grammar.js +++ b/libs/tree-sitter-wing/grammar.js @@ -280,9 +280,20 @@ module.exports = grammar({ "=", field("value", $.expression), field("block", $.block), + repeat(field("elif_let_block", $.elif_let_block)), optional(seq("else", field("else_block", $.block))) ), + elif_let_block: ($) => + seq( + "elif let", + optional(field("reassignable", $.reassignable)), + field("name", $.identifier), + "=", + field("value", $.expression), + field("block", $.block) + ), + if_statement: ($) => seq( "if", diff --git a/libs/tree-sitter-wing/test/corpus/statements/statements.txt b/libs/tree-sitter-wing/test/corpus/statements/statements.txt index db2456efda2..43635bfb719 100644 --- a/libs/tree-sitter-wing/test/corpus/statements/statements.txt +++ b/libs/tree-sitter-wing/test/corpus/statements/statements.txt @@ -401,6 +401,27 @@ if let x = y {} else {} block: (block) else_block: (block))) +================================================================================ +If Let Elif Let Else +================================================================================ + +if let x = y {} elif let x = z {} else {} + +-------------------------------------------------------------------------------- + +(source + (if_let_statement + name: (identifier) + value: (reference + (reference_identifier)) + block: (block) + elif_let_block: (elif_let_block + name: (identifier) + value: (reference + (reference_identifier)) + block: (block)) + else_block: (block))) + ================================================================================ If Let Var ================================================================================ diff --git a/libs/wingc/src/ast.rs b/libs/wingc/src/ast.rs index c3c203b0443..cc5a61787e2 100644 --- a/libs/wingc/src/ast.rs +++ b/libs/wingc/src/ast.rs @@ -338,6 +338,14 @@ pub struct ElifBlock { pub statements: Scope, } +#[derive(Debug)] +pub struct ElifLetBlock { + pub reassignable: bool, + pub var_name: Symbol, + pub value: Expr, + pub statements: Scope, +} + #[derive(Debug)] pub struct Class { pub name: Symbol, @@ -456,6 +464,7 @@ pub enum StmtKind { var_name: Symbol, value: Expr, statements: Scope, + elif_statements: Vec, else_statements: Option, }, If { diff --git a/libs/wingc/src/fold.rs b/libs/wingc/src/fold.rs index c424fc50f31..9264ae7e934 100644 --- a/libs/wingc/src/fold.rs +++ b/libs/wingc/src/fold.rs @@ -1,9 +1,9 @@ use crate::{ ast::{ - ArgList, BringSource, CalleeKind, CatchBlock, Class, ClassField, ElifBlock, Expr, ExprKind, FunctionBody, - FunctionDefinition, FunctionParameter, FunctionSignature, Interface, InterpolatedString, InterpolatedStringPart, - Literal, NewExpr, Reference, Scope, Stmt, StmtKind, StructField, Symbol, TypeAnnotation, TypeAnnotationKind, - UserDefinedType, + ArgList, BringSource, CalleeKind, CatchBlock, Class, ClassField, ElifBlock, ElifLetBlock, Expr, ExprKind, + FunctionBody, FunctionDefinition, FunctionParameter, FunctionSignature, Interface, InterpolatedString, + InterpolatedStringPart, Literal, NewExpr, Reference, Scope, Stmt, StmtKind, StructField, Symbol, TypeAnnotation, + TypeAnnotationKind, UserDefinedType, }, dbg_panic, }; @@ -118,12 +118,22 @@ where statements, reassignable, var_name, + elif_statements, else_statements, } => StmtKind::IfLet { value: f.fold_expr(value), statements: f.fold_scope(statements), reassignable, var_name: f.fold_symbol(var_name), + elif_statements: elif_statements + .into_iter() + .map(|elif_let_block| ElifLetBlock { + reassignable: elif_let_block.reassignable, + statements: f.fold_scope(elif_let_block.statements), + value: f.fold_expr(elif_let_block.value), + var_name: f.fold_symbol(elif_let_block.var_name), + }) + .collect(), else_statements: else_statements.map(|statements| f.fold_scope(statements)), }, StmtKind::If { diff --git a/libs/wingc/src/jsify.rs b/libs/wingc/src/jsify.rs index f2805ead5e1..4d399cacb02 100644 --- a/libs/wingc/src/jsify.rs +++ b/libs/wingc/src/jsify.rs @@ -859,6 +859,7 @@ impl<'a> JSifier<'a> { value, statements, var_name, + elif_statements, else_statements, } => { let mut code = CodeMaker::default(); @@ -896,6 +897,15 @@ impl<'a> JSifier<'a> { if_let_value, self.jsify_expression(value, ctx) )); + let elif_let_value = "$ELIF_LET_VALUE"; + for i in 0..elif_statements.len() { + let value = format!("{}{}", elif_let_value, i); + code.line(format!( + "const {} = {};", + value, + self.jsify_expression(&elif_statements.get(i).unwrap().value, ctx) + )); + } code.open(format!("if ({if_let_value} != undefined) {{")); if *reassignable { code.line(format!("let {} = {};", var_name, if_let_value)); @@ -905,6 +915,19 @@ impl<'a> JSifier<'a> { code.add_code(self.jsify_scope_body(statements, ctx)); code.close("}"); + for i in 0..elif_statements.len() { + let value = format!("{}{}", elif_let_value, i); + code.open(format!("else if ({value} != undefined) {{")); + let elif_block = elif_statements.get(i).unwrap(); + if elif_block.reassignable { + code.line(format!("let {} = {};", elif_block.var_name, value)); + } else { + code.line(format!("const {} = {};", elif_block.var_name, value)); + } + code.add_code(self.jsify_scope_body(&elif_block.statements, ctx)); + code.close("}"); + } + if let Some(else_scope) = else_statements { code.open("else {"); code.add_code(self.jsify_scope_body(else_scope, ctx)); diff --git a/libs/wingc/src/lsp/hover.rs b/libs/wingc/src/lsp/hover.rs index 377adda20f0..dbed00f678c 100644 --- a/libs/wingc/src/lsp/hover.rs +++ b/libs/wingc/src/lsp/hover.rs @@ -169,6 +169,7 @@ impl<'a> Visit<'a> for HoverVisitor<'a> { value, statements, reassignable: _, + elif_statements, else_statements, } => { self.with_scope(statements, |v| { @@ -176,6 +177,11 @@ impl<'a> Visit<'a> for HoverVisitor<'a> { }); self.visit_expr(value); self.visit_scope(statements); + for elif in elif_statements { + self.visit_symbol(&elif.var_name); + self.visit_expr(&elif.value); + self.visit_scope(&elif.statements); + } if let Some(else_statements) = else_statements { self.visit_scope(else_statements); } diff --git a/libs/wingc/src/parser.rs b/libs/wingc/src/parser.rs index 6789f1d2112..d509522d234 100644 --- a/libs/wingc/src/parser.rs +++ b/libs/wingc/src/parser.rs @@ -8,8 +8,8 @@ use tree_sitter::Node; use tree_sitter_traversal::{traverse, Order}; use crate::ast::{ - ArgList, BinaryOperator, BringSource, CalleeKind, CatchBlock, Class, ClassField, ElifBlock, Expr, ExprKind, - FunctionBody, FunctionDefinition, FunctionParameter, FunctionSignature, Interface, InterpolatedString, + ArgList, BinaryOperator, BringSource, CalleeKind, CatchBlock, Class, ClassField, ElifBlock, ElifLetBlock, Expr, + ExprKind, FunctionBody, FunctionDefinition, FunctionParameter, FunctionSignature, Interface, InterpolatedString, InterpolatedStringPart, Literal, NewExpr, Phase, Reference, Scope, Stmt, StmtKind, StructField, Symbol, TypeAnnotation, TypeAnnotationKind, UnaryOperator, UserDefinedType, }; @@ -571,6 +571,22 @@ impl<'s> Parser<'s> { let reassignable = statement_node.child_by_field_name("reassignable").is_some(); let value = self.build_expression(&statement_node.child_by_field_name("value").unwrap(), phase)?; let name = self.check_reserved_symbol(&statement_node.child_by_field_name("name").unwrap())?; + + let mut elif_vec = vec![]; + let mut cursor = statement_node.walk(); + for node in statement_node.children_by_field_name("elif_let_block", &mut cursor) { + let statements = self.build_scope(&node.child_by_field_name("block").unwrap(), phase); + let value = self.build_expression(&node.child_by_field_name("value").unwrap(), phase)?; + let name = self.check_reserved_symbol(&statement_node.child_by_field_name("name").unwrap())?; + let elif = ElifLetBlock { + reassignable: node.child_by_field_name("reassignable").is_some(), + statements: statements, + value: value, + var_name: name, + }; + elif_vec.push(elif); + } + let else_block = if let Some(else_block) = statement_node.child_by_field_name("else_block") { Some(self.build_scope(&else_block, phase)) } else { @@ -581,6 +597,7 @@ impl<'s> Parser<'s> { reassignable, value, statements: if_block, + elif_statements: elif_vec, else_statements: else_block, }) } diff --git a/libs/wingc/src/type_check.rs b/libs/wingc/src/type_check.rs index 4264bb328c2..6177792be5c 100644 --- a/libs/wingc/src/type_check.rs +++ b/libs/wingc/src/type_check.rs @@ -3049,57 +3049,22 @@ impl<'a> TypeChecker<'a> { statements, reassignable, var_name, + elif_statements, else_statements, } => { - let (mut cond_type, _) = self.type_check_exp(value, env); - - if let Type::Inferred(n) = *cond_type { - // If the type is inferred and unlinked, we must make sure that the type is also optional - // So let's make a new inference, but this time optional - if self.types.get_inference_by_id(n).is_none() { - let new_inference = self.types.make_inference(); - cond_type = self.types.make_option(new_inference); - self.types.update_inferred_type(n, cond_type, &value.span); - } - } - - if !cond_type.is_option() { - report_diagnostic(Diagnostic { - message: format!("Expected type to be optional, but got \"{}\" instead", cond_type), - span: Some(value.span()), - }); - } - - // Technically we only allow if let statements to be used with optionals - // and above validate_type_is_optional method will attach a diagnostic error if it is not. - // However for the sake of verbose diagnostics we'll allow the code to continue if the type is not an optional - // and complete the type checking process for additional errors. - let var_type = *cond_type.maybe_unwrap_option(); - - let mut stmt_env = self.types.add_symbol_env(SymbolEnv::new( - Some(env.get_ref()), - env.return_type, - false, - false, - env.phase, - stmt.idx, - )); + self.type_check_if_let_statement(value, statements, reassignable, var_name, stmt, env); - // Add the variable to if block scope - match stmt_env.define( - var_name, - SymbolKind::make_free_variable(var_name.clone(), var_type, *reassignable, env.phase), - StatementIdx::Top, - ) { - Err(type_error) => { - self.type_error(type_error); - } - _ => {} + for elif_scope in elif_statements { + self.type_check_if_let_statement( + &elif_scope.value, + &elif_scope.statements, + &elif_scope.reassignable, + &elif_scope.var_name, + stmt, + env, + ); } - self.types.set_scope_env(statements, stmt_env); - self.inner_scopes.push(statements); - if let Some(else_scope) = else_statements { let else_scope_env = self.types.add_symbol_env(SymbolEnv::new( Some(env.get_ref()), @@ -3119,34 +3084,10 @@ impl<'a> TypeChecker<'a> { elif_statements, else_statements, } => { - let (cond_type, _) = self.type_check_exp(condition, env); - self.validate_type(cond_type, self.types.bool(), condition); - - let if_scope_env = self.types.add_symbol_env(SymbolEnv::new( - Some(env.get_ref()), - env.return_type, - false, - false, - env.phase, - stmt.idx, - )); - self.types.set_scope_env(statements, if_scope_env); - self.inner_scopes.push(statements); + self.type_check_if_statement(condition, statements, stmt, env); for elif_scope in elif_statements { - let (cond_type, _) = self.type_check_exp(&elif_scope.condition, env); - self.validate_type(cond_type, self.types.bool(), condition); - - let elif_scope_env = self.types.add_symbol_env(SymbolEnv::new( - Some(env.get_ref()), - env.return_type, - false, - false, - env.phase, - stmt.idx, - )); - self.types.set_scope_env(&elif_scope.statements, elif_scope_env); - self.inner_scopes.push(&elif_scope.statements); + self.type_check_if_statement(&elif_scope.condition, &elif_scope.statements, stmt, env); } if let Some(else_scope) = else_statements { @@ -3728,6 +3669,81 @@ impl<'a> TypeChecker<'a> { } } + fn type_check_if_let_statement( + &mut self, + value: &Expr, + statements: &Scope, + reassignable: &bool, + var_name: &Symbol, + stmt: &Stmt, + env: &mut SymbolEnv, + ) { + let (mut cond_type, _) = self.type_check_exp(value, env); + + if let Type::Inferred(n) = *cond_type { + // If the type is inferred and unlinked, we must make sure that the type is also optional + // So let's make a new inference, but this time optional + if self.types.get_inference_by_id(n).is_none() { + let new_inference = self.types.make_inference(); + cond_type = self.types.make_option(new_inference); + self.types.update_inferred_type(n, cond_type, &value.span); + } + } + + if !cond_type.is_option() { + report_diagnostic(Diagnostic { + message: format!("Expected type to be optional, but got \"{}\" instead", cond_type), + span: Some(value.span()), + }); + } + + // Technically we only allow if let statements to be used with optionals + // and above validate_type_is_optional method will attach a diagnostic error if it is not. + // However for the sake of verbose diagnostics we'll allow the code to continue if the type is not an optional + // and complete the type checking process for additional errors. + let var_type = *cond_type.maybe_unwrap_option(); + + let mut stmt_env = self.types.add_symbol_env(SymbolEnv::new( + Some(env.get_ref()), + env.return_type, + false, + false, + env.phase, + stmt.idx, + )); + + // Add the variable to if block scope + match stmt_env.define( + var_name, + SymbolKind::make_free_variable(var_name.clone(), var_type, *reassignable, env.phase), + StatementIdx::Top, + ) { + Err(type_error) => { + self.type_error(type_error); + } + _ => {} + } + + self.types.set_scope_env(statements, stmt_env); + self.inner_scopes.push(statements); + } + + fn type_check_if_statement(&mut self, condition: &Expr, statements: &Scope, stmt: &Stmt, env: &mut SymbolEnv) { + let (cond_type, _) = self.type_check_exp(condition, env); + self.validate_type(cond_type, self.types.bool(), condition); + + let if_scope_env = self.types.add_symbol_env(SymbolEnv::new( + Some(env.get_ref()), + env.return_type, + false, + false, + env.phase, + stmt.idx, + )); + self.types.set_scope_env(statements, if_scope_env); + self.inner_scopes.push(statements); + } + fn type_check_super_constructor_against_parent_initializer( &mut self, scope: &Scope, diff --git a/libs/wingc/src/visit.rs b/libs/wingc/src/visit.rs index 9e9214808b7..57c00e0e171 100644 --- a/libs/wingc/src/visit.rs +++ b/libs/wingc/src/visit.rs @@ -136,11 +136,17 @@ where statements, reassignable: _, var_name, + elif_statements, else_statements, } => { v.visit_symbol(var_name); v.visit_expr(value); v.visit_scope(statements); + for elif in elif_statements { + v.visit_symbol(&elif.var_name); + v.visit_expr(&elif.value); + v.visit_scope(&elif.statements); + } if let Some(statements) = else_statements { v.visit_scope(statements); } diff --git a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md index 738f4856944..69fc33cec4f 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md @@ -481,6 +481,27 @@ class $Root extends $stdlib.std.Resource { } return ({"first": (parts.at(0)),"last": (parts.at(1))}); }); + const json_obj = ({"ghost": "spooky"}); + { + const $IF_LET_VALUE = ((arg) => { return (typeof arg === "boolean") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); + const $ELIF_LET_VALUE0 = ((arg) => { return (typeof arg === "number") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); + const $ELIF_LET_VALUE1 = ((arg) => { return (typeof arg === "string") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); + if ($IF_LET_VALUE != undefined) { + const y = $IF_LET_VALUE; + {console.log("it's a boolean!")}; + } + else if ($ELIF_LET_VALUE0 != undefined) { + const y = $ELIF_LET_VALUE0; + {console.log("it's a number!")}; + } + else if ($ELIF_LET_VALUE1 != undefined) { + const y = $ELIF_LET_VALUE1; + {console.log("it's a str!")}; + } + else { + {console.log("it's something else!")}; + } + } const a = 1; { const $IF_LET_VALUE = a; diff --git a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_test_sim.md index 67b48e49dd3..75e0ff13ada 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_test_sim.md @@ -2,6 +2,7 @@ ## stdout.log ```log +it's something else! pass ─ optionals.wsim » root/env0/test:t From 962bfb3e9985610b7f312da3923c4f6019bb3472 Mon Sep 17 00:00:00 2001 From: Marcio Cruz de Almeida <67694075+marciocadev@users.noreply.github.com> Date: Mon, 21 Aug 2023 10:52:16 -0300 Subject: [PATCH 2/8] Update examples/tests/valid/optionals.w Co-authored-by: yoav-steinberg --- examples/tests/valid/optionals.w | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/tests/valid/optionals.w b/examples/tests/valid/optionals.w index 5e42973939e..df40b4e5a23 100644 --- a/examples/tests/valid/optionals.w +++ b/examples/tests/valid/optionals.w @@ -59,15 +59,17 @@ let tryParseName = (fullName: str): Name? => { }; let json_obj = Json { ghost: "spooky" }; +var let something_else = false; if let y = json_obj.tryAsBool() { - log("it's a boolean!"); + assert(y == true || y == false); } elif let y = json_obj.tryAsNum() { - log("it's a number!"); + assert(y + 0 == y); } elif let y = json_obj.tryAsStr() { - log("it's a str!"); + assert(y.len >= 0); } else { - log("it's something else!"); + something_else = true; } +assert(something_else); // if lets reassignable let a: num? = 1; From 22ae52b66454bc103dbd19a6ed751d92c916e877 Mon Sep 17 00:00:00 2001 From: Marcio Cruz de Almeida Date: Mon, 21 Aug 2023 11:14:58 -0300 Subject: [PATCH 3/8] test refactoring --- examples/tests/valid/optionals.w | 4 ++-- .../test_corpus/valid/optionals.w_compile_tf-aws.md | 10 ++++++---- .../test_corpus/valid/optionals.w_test_sim.md | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/tests/valid/optionals.w b/examples/tests/valid/optionals.w index df40b4e5a23..4b29ca67efd 100644 --- a/examples/tests/valid/optionals.w +++ b/examples/tests/valid/optionals.w @@ -59,13 +59,13 @@ let tryParseName = (fullName: str): Name? => { }; let json_obj = Json { ghost: "spooky" }; -var let something_else = false; +let var something_else = false; if let y = json_obj.tryAsBool() { assert(y == true || y == false); } elif let y = json_obj.tryAsNum() { assert(y + 0 == y); } elif let y = json_obj.tryAsStr() { - assert(y.len >= 0); + assert(y.length >= 0); } else { something_else = true; } diff --git a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md index 69fc33cec4f..7fe915497de 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md @@ -482,26 +482,28 @@ class $Root extends $stdlib.std.Resource { return ({"first": (parts.at(0)),"last": (parts.at(1))}); }); const json_obj = ({"ghost": "spooky"}); + let something_else = false; { const $IF_LET_VALUE = ((arg) => { return (typeof arg === "boolean") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); const $ELIF_LET_VALUE0 = ((arg) => { return (typeof arg === "number") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); const $ELIF_LET_VALUE1 = ((arg) => { return (typeof arg === "string") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); if ($IF_LET_VALUE != undefined) { const y = $IF_LET_VALUE; - {console.log("it's a boolean!")}; + {((cond) => {if (!cond) throw new Error("assertion failed: y == true || y == false")})(((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(y,true)) || (((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(y,false))))}; } else if ($ELIF_LET_VALUE0 != undefined) { const y = $ELIF_LET_VALUE0; - {console.log("it's a number!")}; + {((cond) => {if (!cond) throw new Error("assertion failed: y + 0 == y")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((y + 0),y)))}; } else if ($ELIF_LET_VALUE1 != undefined) { const y = $ELIF_LET_VALUE1; - {console.log("it's a str!")}; + {((cond) => {if (!cond) throw new Error("assertion failed: y.length >= 0")})((y.length >= 0))}; } else { - {console.log("it's something else!")}; + something_else = true; } } + {((cond) => {if (!cond) throw new Error("assertion failed: something_else")})(something_else)}; const a = 1; { const $IF_LET_VALUE = a; diff --git a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_test_sim.md index 75e0ff13ada..67b48e49dd3 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_test_sim.md @@ -2,7 +2,6 @@ ## stdout.log ```log -it's something else! pass ─ optionals.wsim » root/env0/test:t From 5ce65aabad8877fc8fca38ade7a406fdcafd60c0 Mon Sep 17 00:00:00 2001 From: Marcio Cruz de Almeida Date: Wed, 23 Aug 2023 20:03:06 -0300 Subject: [PATCH 4/8] refactoring --- libs/wingc/src/jsify.rs | 103 +++++++++++++---- .../valid/container_types.w_compile_tf-aws.md | 12 +- .../valid/inference.w_compile_tf-aws.md | 6 +- ...nflight_capture_static.w_compile_tf-aws.md | 6 +- .../valid/json.w_compile_tf-aws.md | 42 +++---- .../valid/optionals.w_compile_tf-aws.md | 104 +++++++++--------- .../struct_from_json.w_compile_tf-aws.md | 42 +++---- 7 files changed, 187 insertions(+), 128 deletions(-) diff --git a/libs/wingc/src/jsify.rs b/libs/wingc/src/jsify.rs index 4d399cacb02..467af6b68b4 100644 --- a/libs/wingc/src/jsify.rs +++ b/libs/wingc/src/jsify.rs @@ -16,7 +16,7 @@ use std::{ use crate::{ ast::{ - ArgList, BinaryOperator, BringSource, CalleeKind, Class as AstClass, Expr, ExprKind, FunctionBody, + ArgList, BinaryOperator, BringSource, CalleeKind, Class as AstClass, ElifLetBlock, Expr, ExprKind, FunctionBody, FunctionDefinition, InterpolatedStringPart, Literal, NewExpr, Phase, Reference, Scope, Stmt, StmtKind, StructField, Symbol, TypeAnnotationKind, UnaryOperator, UserDefinedType, }, @@ -788,6 +788,78 @@ impl<'a> JSifier<'a> { code } + // To avoid a performance penalty when evaluating assignments made in the elif statement, + // it was necessary to nest the if statements. + // + // Thus, this code in Wing: + // + // if let x = tryA() { + // ... + // } elif let x = tryB() { + // ... + // } elif let x = TryC() { + // ... + // } else { + // ... + // } + // + // In JavaScript, will become this: + // + // const $if_let_value = tryA(); + // if ($if_let_value !== undefined) { + // ... + // } else { + // let $elif_let_value0 = tryB(); + // if ($elif_let_value0 !== undefined) { + // ... + // } else { + // let $elif_let_value1 = tryC(); + // if ($elif_let_value1 !== undefined) { + // ... + // } else { + // ... + // } + // } + // } + fn jsify_elif_statements( + &self, + code: &mut CodeMaker, + elif_statements: &Vec, + index: usize, + else_statements: &Option, + ctx: &mut JSifyContext, + ) { + let elif_let_value = "$elif_let_value"; + + let value = format!("{}{}", elif_let_value, index); + code.line(format!( + "const {} = {};", + value, + self.jsify_expression(&elif_statements.get(index).unwrap().value, ctx) + )); + let value = format!("{}{}", elif_let_value, index); + code.open(format!("if ({value} != undefined) {{")); + let elif_block = elif_statements.get(index).unwrap(); + if elif_block.reassignable { + code.line(format!("let {} = {};", elif_block.var_name, value)); + } else { + code.line(format!("const {} = {};", elif_block.var_name, value)); + } + code.add_code(self.jsify_scope_body(&elif_block.statements, ctx)); + code.close("}"); + + if index < elif_statements.len() - 1 { + code.open("else {"); + self.jsify_elif_statements(code, elif_statements, index + 1, else_statements, ctx); + code.close("}"); + } else if let Some(else_scope) = else_statements { + code.open("else {"); + code.add_code(self.jsify_scope_body(else_scope, ctx)); + code.close("}"); + } + return; + } + fn jsify_statement(&self, env: &SymbolEnv, statement: &Stmt, ctx: &mut JSifyContext) -> CodeMaker { CompilationContext::set(CompilationPhase::Jsifying, &statement.span); match &statement.kind { @@ -891,21 +963,13 @@ impl<'a> JSifier<'a> { // The temporary scope is created so that intermediate variables created by consecutive `if let` clauses // do not interfere with each other. code.open("{"); - let if_let_value = "$IF_LET_VALUE".to_string(); + let if_let_value = "$if_let_value".to_string(); code.line(format!( "const {} = {};", if_let_value, self.jsify_expression(value, ctx) )); - let elif_let_value = "$ELIF_LET_VALUE"; - for i in 0..elif_statements.len() { - let value = format!("{}{}", elif_let_value, i); - code.line(format!( - "const {} = {};", - value, - self.jsify_expression(&elif_statements.get(i).unwrap().value, ctx) - )); - } + code.open(format!("if ({if_let_value} != undefined) {{")); if *reassignable { code.line(format!("let {} = {};", var_name, if_let_value)); @@ -915,20 +979,11 @@ impl<'a> JSifier<'a> { code.add_code(self.jsify_scope_body(statements, ctx)); code.close("}"); - for i in 0..elif_statements.len() { - let value = format!("{}{}", elif_let_value, i); - code.open(format!("else if ({value} != undefined) {{")); - let elif_block = elif_statements.get(i).unwrap(); - if elif_block.reassignable { - code.line(format!("let {} = {};", elif_block.var_name, value)); - } else { - code.line(format!("const {} = {};", elif_block.var_name, value)); - } - code.add_code(self.jsify_scope_body(&elif_block.statements, ctx)); + if elif_statements.len() > 0 { + code.open("else {"); + self.jsify_elif_statements(&mut code, elif_statements, 0, else_statements, ctx); code.close("}"); - } - - if let Some(else_scope) = else_statements { + } else if let Some(else_scope) = else_statements { code.open("else {"); code.add_code(self.jsify_scope_body(else_scope, ctx)); code.close("}"); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/container_types.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/container_types.w_compile_tf-aws.md index d1b5a74d286..36ba7fe629a 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/container_types.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/container_types.w_compile_tf-aws.md @@ -196,16 +196,16 @@ class $Root extends $stdlib.std.Resource { {((cond) => {if (!cond) throw new Error("assertion failed: arr7.length == 3")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(arr7.length,3)))}; {((cond) => {if (!cond) throw new Error("assertion failed: arr7.at(1) == 2")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((arr7.at(1)),2)))}; { - const $IF_LET_VALUE = (emptyArray.at(0)); - if ($IF_LET_VALUE != undefined) { - const val = $IF_LET_VALUE; + const $if_let_value = (emptyArray.at(0)); + if ($if_let_value != undefined) { + const val = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: false")})(false)}; } } { - const $IF_LET_VALUE = (arr1.at(0)); - if ($IF_LET_VALUE != undefined) { - const val = $IF_LET_VALUE; + const $if_let_value = (arr1.at(0)); + if ($if_let_value != undefined) { + const val = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: val == 1")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(val,1)))}; } else { diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inference.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/inference.w_compile_tf-aws.md index 5b638af6996..524d2e83c3d 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inference.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inference.w_compile_tf-aws.md @@ -275,9 +275,9 @@ class $Root extends $stdlib.std.Resource { const stringArray = [shouldBeString]; const closureWithUnwrapping = ((optionalString) => { { - const $IF_LET_VALUE = optionalString; - if ($IF_LET_VALUE != undefined) { - const justString = $IF_LET_VALUE; + const $if_let_value = optionalString; + if ($if_let_value != undefined) { + const justString = $if_let_value; {console.log(justString)}; } } diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inflight_capture_static.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/inflight_capture_static.w_compile_tf-aws.md index 0a55c09f826..c26e8fb939b 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inflight_capture_static.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inflight_capture_static.w_compile_tf-aws.md @@ -70,9 +70,9 @@ module.exports = function({ $util_Util }) { } async handle() { { - const $IF_LET_VALUE = (await $util_Util.tryEnv("WING_TARGET")); - if ($IF_LET_VALUE != undefined) { - const target = $IF_LET_VALUE; + const $if_let_value = (await $util_Util.tryEnv("WING_TARGET")); + if ($if_let_value != undefined) { + const target = $if_let_value; {console.log(String.raw({ raw: ["WING_TARGET=", ""] }, target))}; } else { diff --git a/tools/hangar/__snapshots__/test_corpus/valid/json.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/json.w_compile_tf-aws.md index 5f3bfb7255f..b0510a8dcec 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/json.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/json.w_compile_tf-aws.md @@ -368,9 +368,9 @@ class $Root extends $stdlib.std.Resource { {((cond) => {if (!cond) throw new Error("assertion failed: unestedJsonArr.getAt(0) == 1")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((unestedJsonArr)[0],1)))}; const jsonElements = ({"strings": ({"single": "Hello","array": ["Hello", "World", "!"]}),"numbers": ({"one": 1,"two": 2,"three": 3}),"bools": ({"t": true,"f": false})}); { - const $IF_LET_VALUE = ((arg) => { if (typeof arg !== "string") {throw new Error("unable to parse " + typeof arg + " " + arg + " as a string")}; return JSON.parse(JSON.stringify(arg)) })(((jsonElements)?.["strings"])?.["single"]); - if ($IF_LET_VALUE != undefined) { - const val = $IF_LET_VALUE; + const $if_let_value = ((arg) => { if (typeof arg !== "string") {throw new Error("unable to parse " + typeof arg + " " + arg + " as a string")}; return JSON.parse(JSON.stringify(arg)) })(((jsonElements)?.["strings"])?.["single"]); + if ($if_let_value != undefined) { + const val = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: val == \"Hello\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(val,"Hello")))}; } else { @@ -378,13 +378,13 @@ class $Root extends $stdlib.std.Resource { } } { - const $IF_LET_VALUE = ((jsonElements)?.["strings"])?.["array"]; - if ($IF_LET_VALUE != undefined) { - const vals = $IF_LET_VALUE; + const $if_let_value = ((jsonElements)?.["strings"])?.["array"]; + if ($if_let_value != undefined) { + const vals = $if_let_value; { - const $IF_LET_VALUE = (vals)?.[0]; - if ($IF_LET_VALUE != undefined) { - const hello = $IF_LET_VALUE; + const $if_let_value = (vals)?.[0]; + if ($if_let_value != undefined) { + const hello = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: hello == \"Hello\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(hello,"Hello")))}; } else { @@ -397,9 +397,9 @@ class $Root extends $stdlib.std.Resource { } } { - const $IF_LET_VALUE = ((arg) => { return (typeof arg === "number") ? JSON.parse(JSON.stringify(arg)) : undefined })(((jsonElements)?.["numbers"])?.["two"]); - if ($IF_LET_VALUE != undefined) { - const two = $IF_LET_VALUE; + const $if_let_value = ((arg) => { return (typeof arg === "number") ? JSON.parse(JSON.stringify(arg)) : undefined })(((jsonElements)?.["numbers"])?.["two"]); + if ($if_let_value != undefined) { + const two = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: two + 2 == 4")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((two + 2),4)))}; } else { @@ -407,9 +407,9 @@ class $Root extends $stdlib.std.Resource { } } { - const $IF_LET_VALUE = ((arg) => { return (typeof arg === "boolean") ? JSON.parse(JSON.stringify(arg)) : undefined })(((jsonElements)?.["bools"])?.["t"]); - if ($IF_LET_VALUE != undefined) { - const truth = $IF_LET_VALUE; + const $if_let_value = ((arg) => { return (typeof arg === "boolean") ? JSON.parse(JSON.stringify(arg)) : undefined })(((jsonElements)?.["bools"])?.["t"]); + if ($if_let_value != undefined) { + const truth = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: truth")})(truth)}; } else { @@ -417,16 +417,16 @@ class $Root extends $stdlib.std.Resource { } } { - const $IF_LET_VALUE = ((((jsonElements)?.["strings"])?.["non"])?.["existant"])?.["element"]; - if ($IF_LET_VALUE != undefined) { - const val = $IF_LET_VALUE; + const $if_let_value = ((((jsonElements)?.["strings"])?.["non"])?.["existant"])?.["element"]; + if ($if_let_value != undefined) { + const val = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: false")})(false)}; } } { - const $IF_LET_VALUE = (((jsonElements)?.["cant"])?.[1000])?.[42]; - if ($IF_LET_VALUE != undefined) { - const val = $IF_LET_VALUE; + const $if_let_value = (((jsonElements)?.["cant"])?.[1000])?.[42]; + if ($if_let_value != undefined) { + const val = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: false")})(false)}; } } diff --git a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md index 7fe915497de..d8a3611ea81 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/optionals.w_compile_tf-aws.md @@ -457,17 +457,17 @@ class $Root extends $stdlib.std.Resource { const Name = require("./Name.Struct.js")($stdlib.std.Struct, $stdlib.core.NodeJsCode.fromInline); let name = ({"first": "John","last": "Doe"}); { - const $IF_LET_VALUE = name; - if ($IF_LET_VALUE != undefined) { - const n = $IF_LET_VALUE; + const $if_let_value = name; + if ($if_let_value != undefined) { + const n = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: n.first == \"John\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(n.first,"John")))}; } } name = undefined; { - const $IF_LET_VALUE = name; - if ($IF_LET_VALUE != undefined) { - const n = $IF_LET_VALUE; + const $if_let_value = name; + if ($if_let_value != undefined) { + const n = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: false")})(false)}; } else { @@ -484,45 +484,49 @@ class $Root extends $stdlib.std.Resource { const json_obj = ({"ghost": "spooky"}); let something_else = false; { - const $IF_LET_VALUE = ((arg) => { return (typeof arg === "boolean") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); - const $ELIF_LET_VALUE0 = ((arg) => { return (typeof arg === "number") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); - const $ELIF_LET_VALUE1 = ((arg) => { return (typeof arg === "string") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); - if ($IF_LET_VALUE != undefined) { - const y = $IF_LET_VALUE; + const $if_let_value = ((arg) => { return (typeof arg === "boolean") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); + if ($if_let_value != undefined) { + const y = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: y == true || y == false")})(((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(y,true)) || (((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(y,false))))}; } - else if ($ELIF_LET_VALUE0 != undefined) { - const y = $ELIF_LET_VALUE0; - {((cond) => {if (!cond) throw new Error("assertion failed: y + 0 == y")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((y + 0),y)))}; - } - else if ($ELIF_LET_VALUE1 != undefined) { - const y = $ELIF_LET_VALUE1; - {((cond) => {if (!cond) throw new Error("assertion failed: y.length >= 0")})((y.length >= 0))}; - } else { - something_else = true; + const $elif_let_value0 = ((arg) => { return (typeof arg === "number") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); + if ($elif_let_value0 != undefined) { + const y = $elif_let_value0; + {((cond) => {if (!cond) throw new Error("assertion failed: y + 0 == y")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })((y + 0),y)))}; + } + else { + const $elif_let_value1 = ((arg) => { return (typeof arg === "string") ? JSON.parse(JSON.stringify(arg)) : undefined })(json_obj); + if ($elif_let_value1 != undefined) { + const y = $elif_let_value1; + {((cond) => {if (!cond) throw new Error("assertion failed: y.length >= 0")})((y.length >= 0))}; + } + else { + something_else = true; + } + } } } {((cond) => {if (!cond) throw new Error("assertion failed: something_else")})(something_else)}; const a = 1; { - const $IF_LET_VALUE = a; - if ($IF_LET_VALUE != undefined) { - let z = $IF_LET_VALUE; + const $if_let_value = a; + if ($if_let_value != undefined) { + let z = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: z == 1")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(z,1)))}; z = 2; {((cond) => {if (!cond) throw new Error("assertion failed: z == 2")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(z,2)))}; } } { - const $IF_LET_VALUE = (tryParseName("Good Name")); - if ($IF_LET_VALUE != undefined) { - const parsedName = $IF_LET_VALUE; + const $if_let_value = (tryParseName("Good Name")); + if ($if_let_value != undefined) { + const parsedName = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: parsedName.first == \"Good\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(parsedName.first,"Good")))}; { - const $IF_LET_VALUE = parsedName.last; - if ($IF_LET_VALUE != undefined) { - const lastName = $IF_LET_VALUE; + const $if_let_value = parsedName.last; + if ($if_let_value != undefined) { + const lastName = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: lastName == \"Name\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(lastName,"Name")))}; } else { @@ -532,14 +536,14 @@ class $Root extends $stdlib.std.Resource { } } { - const $IF_LET_VALUE = (tryParseName("BadName")); - if ($IF_LET_VALUE != undefined) { - const parsedName = $IF_LET_VALUE; + const $if_let_value = (tryParseName("BadName")); + if ($if_let_value != undefined) { + const parsedName = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: parsedName.first == \"BadName\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(parsedName.first,"BadName")))}; { - const $IF_LET_VALUE = parsedName.last; - if ($IF_LET_VALUE != undefined) { - const lastName = $IF_LET_VALUE; + const $if_let_value = parsedName.last; + if ($if_let_value != undefined) { + const lastName = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: false")})(false)}; } } @@ -547,9 +551,9 @@ class $Root extends $stdlib.std.Resource { } const falsy = false; { - const $IF_LET_VALUE = falsy; - if ($IF_LET_VALUE != undefined) { - const f = $IF_LET_VALUE; + const $if_let_value = falsy; + if ($if_let_value != undefined) { + const f = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: f == false")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(f,false)))}; } else { @@ -558,15 +562,15 @@ class $Root extends $stdlib.std.Resource { } const shadow = "root"; { - const $IF_LET_VALUE = shadow; - if ($IF_LET_VALUE != undefined) { - const shadow = $IF_LET_VALUE; + const $if_let_value = shadow; + if ($if_let_value != undefined) { + const shadow = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: shadow == \"root\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(shadow,"root")))}; const shadow1 = "nested"; { - const $IF_LET_VALUE = shadow1; - if ($IF_LET_VALUE != undefined) { - const shadow1 = $IF_LET_VALUE; + const $if_let_value = shadow1; + if ($if_let_value != undefined) { + const shadow1 = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: shadow1 == \"nested\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(shadow1,"nested")))}; } else { @@ -577,9 +581,9 @@ class $Root extends $stdlib.std.Resource { } const fun = ((a) => { { - const $IF_LET_VALUE = a; - if ($IF_LET_VALUE != undefined) { - const y = $IF_LET_VALUE; + const $if_let_value = a; + if ($if_let_value != undefined) { + const y = $if_let_value; return y; } else { @@ -595,9 +599,9 @@ class $Root extends $stdlib.std.Resource { {((cond) => {if (!cond) throw new Error("assertion failed: thirteen == 13")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(thirteen,13)))}; {((cond) => {if (!cond) throw new Error("assertion failed: notThere == nil")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(notThere,undefined)))}; { - const $IF_LET_VALUE = tree.left?.left; - if ($IF_LET_VALUE != undefined) { - const o = $IF_LET_VALUE; + const $if_let_value = tree.left?.left; + if ($if_let_value != undefined) { + const o = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: o.value == 1")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(o.value,1)))}; } } diff --git a/tools/hangar/__snapshots__/test_corpus/valid/struct_from_json.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/struct_from_json.w_compile_tf-aws.md index 1b4f392312e..401aecf5a4f 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/struct_from_json.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/struct_from_json.w_compile_tf-aws.md @@ -324,9 +324,9 @@ module.exports = function({ $Student }) { {((cond) => {if (!cond) throw new Error("assertion failed: studentInflight1.dob.day == 1")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(studentInflight1.dob.day,1)))}; {((cond) => {if (!cond) throw new Error("assertion failed: studentInflight1.dob.year == 1999")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(studentInflight1.dob.year,1999)))}; { - const $IF_LET_VALUE = studentInflight1.coursesTaken; - if ($IF_LET_VALUE != undefined) { - const coursesTaken = $IF_LET_VALUE; + const $if_let_value = studentInflight1.coursesTaken; + if ($if_let_value != undefined) { + const coursesTaken = $if_let_value; const course1 = (await coursesTaken.at(0)); const course2 = (await coursesTaken.at(1)); {((cond) => {if (!cond) throw new Error("assertion failed: course1.grade == \"B\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(course1.grade,"B")))}; @@ -628,16 +628,16 @@ class $Root extends $stdlib.std.Resource { const jFoosible = ({}); const jFoosible2 = ({"f": "bar"}); { - const $IF_LET_VALUE = (Foosible.fromJson(jFoosible)).f; - if ($IF_LET_VALUE != undefined) { - const f = $IF_LET_VALUE; + const $if_let_value = (Foosible.fromJson(jFoosible)).f; + if ($if_let_value != undefined) { + const f = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: false")})(false)}; } } { - const $IF_LET_VALUE = (Foosible.fromJson(jFoosible2)).f; - if ($IF_LET_VALUE != undefined) { - const f = $IF_LET_VALUE; + const $if_let_value = (Foosible.fromJson(jFoosible2)).f; + if ($if_let_value != undefined) { + const f = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: f == \"bar\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(f,"bar")))}; } else { @@ -674,9 +674,9 @@ class $Root extends $stdlib.std.Resource { {((cond) => {if (!cond) throw new Error("assertion failed: student2.dob.day == 31")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(student2.dob.day,31)))}; {((cond) => {if (!cond) throw new Error("assertion failed: student2.dob.year == 1987")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(student2.dob.year,1987)))}; { - const $IF_LET_VALUE = student2.enrolledCourses; - if ($IF_LET_VALUE != undefined) { - const enrolledCourses = $IF_LET_VALUE; + const $if_let_value = student2.enrolledCourses; + if ($if_let_value != undefined) { + const enrolledCourses = $if_let_value; const courses = [...(enrolledCourses)]; const s2Course1 = (courses.at(0)); const s2Course2 = (courses.at(1)); @@ -692,9 +692,9 @@ class $Root extends $stdlib.std.Resource { const jStudent3 = ({"enrolled": false,"schoolId": "w/e","firstName": student2.firstName,"lastName": student2.lastName,"dob": ({"month": 1,"day": 1,"year": 1959}),"additionalData": ({"notes": "wow such notes","legacy": false,"emergencyContactsNumbers": ["123-345-9928"]})}); const student3 = (Student.fromJson(jStudent3)); { - const $IF_LET_VALUE = student3.additionalData; - if ($IF_LET_VALUE != undefined) { - const additionalData = $IF_LET_VALUE; + const $if_let_value = student3.additionalData; + if ($if_let_value != undefined) { + const additionalData = $if_let_value; const notes = (additionalData)["notes"]; {((cond) => {if (!cond) throw new Error("assertion failed: notes == \"wow such notes\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(notes,"wow such notes")))}; } @@ -704,9 +704,9 @@ class $Root extends $stdlib.std.Resource { } const invalidStudent = ({"firstName": "I dont have","lastName": "Any other info"}); { - const $IF_LET_VALUE = (() => { try { return Student.fromJson(invalidStudent); } catch { return undefined; }})();; - if ($IF_LET_VALUE != undefined) { - const student = $IF_LET_VALUE; + const $if_let_value = (() => { try { return Student.fromJson(invalidStudent); } catch { return undefined; }})();; + if ($if_let_value != undefined) { + const student = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: false")})(false)}; } else { @@ -714,9 +714,9 @@ class $Root extends $stdlib.std.Resource { } } { - const $IF_LET_VALUE = (() => { try { return Student.fromJson(jStudent2); } catch { return undefined; }})();; - if ($IF_LET_VALUE != undefined) { - const student = $IF_LET_VALUE; + const $if_let_value = (() => { try { return Student.fromJson(jStudent2); } catch { return undefined; }})();; + if ($if_let_value != undefined) { + const student = $if_let_value; {((cond) => {if (!cond) throw new Error("assertion failed: student.firstName == \"Sally\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(student.firstName,"Sally")))}; {((cond) => {if (!cond) throw new Error("assertion failed: student.lastName == \"Reynolds\"")})((((a,b) => { try { return require('assert').deepStrictEqual(a,b) === undefined; } catch { return false; } })(student.lastName,"Reynolds")))}; {((cond) => {if (!cond) throw new Error("assertion failed: !student.enrolled")})((!student.enrolled))}; From d70486bc6a4606d23b54029aac715fde51470009 Mon Sep 17 00:00:00 2001 From: "monada-bot[bot]" Date: Wed, 23 Aug 2023 23:27:39 +0000 Subject: [PATCH 5/8] Merge branch 'main' into marciocadev/elif-let Signed-off-by: monada-bot[bot] --- .github/workflows/build.yml | 94 +- .github/workflows/mutation.yml | 34 +- .github/workflows/pull-request-lint.yml | 2 +- apps/jsii-docgen/{LICENSE.md => LICENSE} | 0 apps/vscode-wing/.projen/tasks.json | 2 +- apps/vscode-wing/.projenrc.ts | 4 +- apps/vscode-wing/turbo.json | 2 +- apps/wing-api-checker/.projenrc.ts | 4 +- .../LICENSE.md => wing-api-checker/LICENSE} | 0 apps/wing-api-checker/LICENSE.md | 19 - apps/wing-api-checker/package.json | 2 +- apps/wing-console/console/app/demo/index.w | 4 +- .../design-system/src/toolbar-button.tsx | 2 +- .../console/design-system/src/toolbar.tsx | 9 +- .../console/server/src/utils/createRouter.ts | 7 +- apps/wing-console/console/ui/src/Console.tsx | 44 +- .../console/ui/src/features/map-view.tsx | 41 +- .../console/ui/src/layout/default-layout.tsx | 151 +- .../console/ui/src/layout/layout-provider.tsx | 12 +- .../console/ui/src/layout/status-bar.tsx | 2 +- .../console/ui/src/ui/edge-metadata.tsx | 2 +- .../console/ui/src/ui/elk-map-nodes.tsx | 26 +- .../console/ui/src/ui/map-controls.tsx | 42 +- .../console/ui/src/ui/test-tree.tsx | 5 +- docs/docs/03-language-reference.md | 4 +- .../04-standard-library/01-cloud/bucket.md | 35 + .../04-standard-library/01-cloud/queue.md | 4 +- .../02-std/api-reference.md | 63 +- examples/tests/sdk_tests/bucket/add_file.w | 12 + .../sdk_tests/bucket/testFiles/test1.txt | 1 + .../sdk_tests/bucket/testFiles/test2.txt | 1 + examples/tests/sdk_tests/queue/pop.w | 19 +- examples/tests/sdk_tests/std/array.w | 60 +- examples/tests/sdk_tests/std/json.w | 13 + .../tests/sdk_tests/website/two_websites.w | 13 +- examples/tests/sdk_tests/website/website.w | 11 +- examples/tests/valid/deep_equality.w | 15 +- examples/tests/valid/json_static.w | 2 +- examples/tests/valid/std_containers.w | 24 +- .../src/jsify/snapshots/json_object.snap | 2 +- .../snapshots/completions/json_statics.snap | 4 +- .../static_completions_after_expression.snap | 4 +- .../static_json_after_expression.snap | 4 +- ...tatic_json_after_expression_statement.snap | 4 +- .../hovers/static_stdtype_method.snap | 2 +- libs/wingc/src/type_check.rs | 223 +- libs/wingcompiler/package.json | 2 +- libs/wingcompiler/turbo.json | 2 +- libs/wingsdk/LICENSE.md | 19 - libs/wingsdk/src/cloud/bucket.ts | 30 + libs/wingsdk/src/cloud/queue.md | 4 +- .../wingsdk/src/shared-aws/bucket.inflight.ts | 73 +- libs/wingsdk/src/std/array.ts | 15 + libs/wingsdk/src/std/json.ts | 19 +- libs/wingsdk/src/std/struct.ts | 2 +- libs/wingsdk/src/target-tf-aws/bucket.ts | 8 - libs/wingsdk/src/target-tf-aws/website.ts | 2 +- .../test/shared-aws/bucket.inflight.test.ts | 41 +- libs/wingsdk/test/sim-app.ts | 2 +- .../__snapshots__/bucket.test.ts.snap | 340 + .../wingsdk/test/target-awscdk/bucket.test.ts | 14 + .../__snapshots__/bucket.test.ts.snap | 85 + .../__snapshots__/queue.test.ts.snap | 29 - libs/wingsdk/test/target-sim/bucket.test.ts | 28 + libs/wingsdk/test/target-sim/queue.test.ts | 6 +- .../__snapshots__/bucket.test.ts.snap | 234 +- .../__snapshots__/captures.test.ts.snap | 9 - .../__snapshots__/on-deploy.test.ts.snap | 38 - .../__snapshots__/website.test.ts.snap | 34 - .../wingsdk/test/target-tf-aws/bucket.test.ts | 22 +- .../test/target-tf-aws/captures.test.ts | 1 - .../test/target-tf-aws/website.test.ts | 2 - .../__snapshots__/bucket.test.ts.snap | 151 + .../test/target-tf-azure/bucket.test.ts | 37 +- .../__snapshots__/bucket.test.ts.snap | 138 + .../wingsdk/test/target-tf-gcp/bucket.test.ts | 20 + libs/wingsdk/test/testFiles/test1.txt | 1 + libs/wingsdk/test/testFiles/test2.txt | 1 + package.json | 2 +- pnpm-lock.yaml | 9004 +++++++++-------- tools/hangar/__snapshots__/error.ts.snap | 10 +- tools/hangar/__snapshots__/invalid.ts.snap | 34 +- tools/hangar/__snapshots__/plugins.ts.snap | 75 - .../sdk_tests/api/patch.w_compile_tf-aws.md | 6 +- .../sdk_tests/api/post.w_compile_tf-aws.md | 10 +- .../sdk_tests/api/put.w_compile_tf-aws.md | 6 +- .../bucket/add_file.w_compile_tf-aws.md | 246 + .../sdk_tests/bucket/add_file.w_test_sim.md | 12 + .../bucket/add_object.w_compile_tf-aws.md | 19 +- .../bucket/bucket_list.w_compile_tf-aws.md | 15 - .../bucket/delete.w_compile_tf-aws.md | 15 - .../bucket/events.w_compile_tf-aws.md | 15 - .../bucket/exists.w_compile_tf-aws.md | 15 - .../bucket/public_url.w_compile_tf-aws.md | 13 - .../sdk_tests/bucket/put.w_compile_tf-aws.md | 15 - .../bucket/put_json.w_compile_tf-aws.md | 15 - .../bucket/try_delete.w_compile_tf-aws.md | 15 - .../bucket/try_get.w_compile_tf-aws.md | 15 - .../bucket/try_get_json.w_compile_tf-aws.md | 19 +- .../memory_and_env.w_compile_tf-aws.md | 15 - .../sdk_tests/queue/pop.w_compile_tf-aws.md | 22 +- .../sdk_tests/std/array.w_compile_tf-aws.md | 183 +- .../sdk_tests/std/array.w_test_sim.md | 3 +- .../sdk_tests/std/json.w_compile_tf-aws.md | 116 +- .../sdk_tests/std/json.w_test_sim.md | 7 +- .../website/two_websites.w_compile_tf-aws.md | 48 +- .../website/website.w_compile_tf-aws.md | 29 +- .../test_corpus/valid/api.w_compile_tf-aws.md | 2 +- .../valid/api_path_vars.w_compile_tf-aws.md | 2 +- .../valid/bring_local.w_compile_tf-aws.md | 15 - .../valid/bucket_events.w_compile_tf-aws.md | 28 - .../valid/bucket_keys.w_compile_tf-aws.md | 15 - .../capture_in_binary.w_compile_tf-aws.md | 15 - ...eassigable_class_field.w_compile_tf-aws.md | 15 - ...ture_resource_and_data.w_compile_tf-aws.md | 15 - .../valid/captures.w_compile_tf-aws.md | 28 +- .../valid/container_types.w_compile_tf-aws.md | 41 - .../valid/deep_equality.w_compile_tf-aws.md | 48 +- .../valid/doubler.w_compile_tf-aws.md | 2 +- .../valid/file_counter.w_compile_tf-aws.md | 15 - ...ion_variadic_arguments.w_compile_tf-aws.md | 41 - .../valid/hello.w_compile_tf-aws.md | 15 - ...nside_inflight_closure.w_compile_tf-aws.md | 15 - ...ghts_calling_inflights.w_compile_tf-aws.md | 15 - .../valid/issue_2889.w_compile_tf-aws.md | 2 +- .../valid/json.w_compile_tf-aws.md | 15 - .../valid/json_bucket.w_compile_tf-aws.md | 15 - .../valid/json_static.w_compile_tf-aws.md | 6 +- .../lift_via_closure.w_compile_tf-aws.md | 28 - .../mut_container_types.w_compile_tf-aws.md | 41 - .../valid/optionals.w_compile_tf-aws.md | 15 - .../valid/resource.w_compile_tf-aws.md | 41 - .../resource_captures.w_compile_tf-aws.md | 41 - ...ource_captures_globals.w_compile_tf-aws.md | 28 - .../valid/std_containers.w_compile_tf-aws.md | 113 + .../valid/super_call.w_compile_tf-aws.md | 15 - .../valid/test_bucket.w_compile_tf-aws.md | 15 - .../website_with_api.w_compile_tf-aws.md | 27 +- tools/hangar/__snapshots__/tree_json.ts.snap | 24 - tools/hangar/src/package.setup.ts | 2 +- tools/hangar/turbo.json | 2 +- turbo.json | 39 +- 142 files changed, 7054 insertions(+), 6180 deletions(-) rename apps/jsii-docgen/{LICENSE.md => LICENSE} (100%) rename apps/{vscode-wing/LICENSE.md => wing-api-checker/LICENSE} (100%) delete mode 100644 apps/wing-api-checker/LICENSE.md create mode 100644 examples/tests/sdk_tests/bucket/add_file.w create mode 100644 examples/tests/sdk_tests/bucket/testFiles/test1.txt create mode 100644 examples/tests/sdk_tests/bucket/testFiles/test2.txt delete mode 100644 libs/wingsdk/LICENSE.md create mode 100644 libs/wingsdk/test/testFiles/test1.txt create mode 100644 libs/wingsdk/test/testFiles/test2.txt create mode 100644 tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/add_file.w_compile_tf-aws.md create mode 100644 tools/hangar/__snapshots__/test_corpus/sdk_tests/bucket/add_file.w_test_sim.md diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 272376e4abc..d9c6bd3f256 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,16 +22,15 @@ env: RUST_VERSION: "1.67.1" NODE_VERSION: "18.16.0" PNPM_VERSION: "8.6.3" + CARGO_TERM_COLOR: always + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} jobs: build: name: "Build" timeout-minutes: 30 runs-on: ubuntu-latest - env: - CARGO_TERM_COLOR: always - TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} - TURBO_TEAM: ${{ vars.TURBO_TEAM }} outputs: version: ${{ fromJson(steps.changelog.outputs.data).newVersion }} last-version: ${{ fromJson(steps.changelog.outputs.data).lastVersion }} @@ -66,6 +65,9 @@ jobs: - name: Setup Cargo Cache uses: Swatinem/rust-cache@v2 + with: + # Don't save cache here, to avoid thrashing with test job + save-if: false - name: Install Dependencies run: pnpm install --frozen-lockfile @@ -81,18 +83,6 @@ jobs: env: SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }} - - name: Upload Artifacts - uses: actions/upload-artifact@v3 - with: - name: dist - path: dist/*.tgz - - - name: Upload WingC WASM - uses: actions/upload-artifact@v3 - with: - name: wingc - path: libs/wingcompiler/wingc.wasm - - name: Derive appropriate SHAs for base and head id: setSHAs uses: nrwl/nx-set-shas@v3 @@ -106,35 +96,38 @@ jobs: echo "diff=true" >> "$GITHUB_OUTPUT" fi - - name: Upload Extension + - name: Upload Artifacts uses: actions/upload-artifact@v3 with: - name: vscode-wing - path: apps/vscode-wing/vscode-wing.vsix + name: dist + path: dist/* - - name: Compress Docs - run: tar -czvf docs.tgz docs/* + # Create patch to go from the PR head to the merge commit + - name: Create git patch for merge + if: github.event_name == 'pull_request' + id: diff + run: | + git diff --binary --patch ${{ github.event.pull_request.head.sha }} ${{ github.sha }} > update.diff + if [ -s update.diff ]; then + echo "Diff found, creating a patch to apply later" + cat update.diff + echo "diff=true" >> $GITHUB_OUTPUT + fi - - name: Upload Docs + - name: Upload patch + if: steps.diff.outputs.diff == 'true' uses: actions/upload-artifact@v3 with: - name: docs - path: docs.tgz + name: update.diff + path: update.diff test: name: Test timeout-minutes: 30 runs-on: ubuntu-latest - env: - CARGO_TERM_COLOR: always - TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} - TURBO_TEAM: ${{ vars.TURBO_TEAM }} - steps: - name: Checkout uses: actions/checkout@v3 - with: - fetch-depth: 1 - name: Setup pnpm uses: pnpm/action-setup@v2.2.4 @@ -227,7 +220,7 @@ jobs: path: tools/hangar/results/report.json - name: Create Markdown report - run: node scripts/benchmark_json_to_table.mjs + run: scripts/benchmark_json_to_table.mjs e2e-test: name: "E2E / ${{ matrix.runner }} + Node${{ matrix.node }} [${{ matrix.shard }}]" @@ -254,8 +247,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - with: - fetch-depth: 1 - name: Setup pnpm uses: pnpm/action-setup@v2.2.4 @@ -321,8 +312,11 @@ jobs: run: | PATCH_COUNT=0 for f in $(find ./*.diff/*.diff); do - PATCH_COUNT=$((PATCH_COUNT + 1)) - cat $f + # Exclude update.diff since we don't want to fail if the PR is just not up to date + if [ "$f" != "./update.diff/update.diff" ]; then + PATCH_COUNT=$((PATCH_COUNT + 1)) + cat $f + fi done if [ $PATCH_COUNT -gt 0 ]; then echo "Found $PATCH_COUNT patches, build failed. A self-mutation should happen soon." @@ -349,25 +343,28 @@ jobs: repo-token: "${{ secrets.PROJEN_GITHUB_TOKEN }}" tag: "v${{ needs.build.outputs.version }}" + - name: Login to NPM registry + run: npm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_PUBLISH_TOKEN }} + + - name: Publish npm packages + working-directory: dist + env: + PACKAGE_VERSION: ${{ needs.build.outputs.version }} + run: | + PACKAGES=("winglang-sdk" "winglang-compiler" "wingconsole-design-system" "wingconsole-ui" "wingconsole-server" "wingconsole-app") + for PACKAGE in $PACKAGES; do + npm publish "$PACKAGE-$PACKAGE_VERSION.tgz" --access public + done + - name: Publish Extension to Visual Studio Marketplace if: needs.build.outputs.vscode-wing-changed == 'true' uses: "HaaLeo/publish-vscode-extension@v1" with: pat: ${{ secrets.VS_MARKETPLACE_TOKEN }} registryUrl: "https://marketplace.visualstudio.com" - extensionFile: "vscode-wing/vscode-wing.vsix" + extensionFile: "dist/vscode-wing.vsix" dependencies: false - - name: Login to NPM registry - run: npm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_PUBLISH_TOKEN }} - - - name: Publish npm packages - run: | - for file in *.tgz; do - npm publish "$file" --access public - done - working-directory: dist - - name: Write Changelog uses: DamianReeves/write-file-action@v1.2 with: @@ -377,9 +374,6 @@ jobs: - name: Compute Checksums run: | - mv ./docs/*.tgz ./dist - mv ./*/*.vsix ./dist - mv ./*/*.wasm ./dist mv ./benchmarks/* ./dist cd dist diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index b5d45018da3..b1a9fe408e1 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -70,11 +70,35 @@ jobs: if: steps.download-artifacts.outputs.found_artifact == 'true' name: Apply downloaded pathes working-directory: repo + env: + HEAD_REF: ${{ github.event.workflow_run.head_branch }} run: | + git config user.name "monada-bot[bot]" + git config user.email "monabot@monada.co" + + # if ../patches/update.diff/update.diff exists, apply it first + UPDATE_PATCH_FILE="../patches/update.diff/update.diff" + if [ -f $UPDATE_PATCH_FILE ]; then + echo "Updating branch" + git apply --binary $UPDATE_PATCH_FILE + if [ $? -eq 0 ]; then + git add --all + git commit -s -m "Merge branch 'main' into $HEAD_REF" + echo "Patch applied successfully" + rm $UPDATE_PATCH_FILE + else + echo "Patch failed to apply" + cat $UPDATE_PATCH_FILE + exit 1 + fi + fi + for f in $(find ../patches/*.diff/*.diff); do echo "Applying $f" git apply --binary $f if [ $? -eq 0 ]; then + git add --all + git commit -s -m "chore: self mutation ($f)" echo "Patch applied successfully" rm $f else @@ -84,16 +108,6 @@ jobs: fi done - - name: Push changes - if: steps.download-artifacts.outputs.found_artifact == 'true' - working-directory: repo - env: - HEAD_REF: ${{ github.event.workflow_run.head_branch }} - run: | - git config user.name "monada-bot[bot]" - git config user.email "monabot@monada.co" - git add --all - git commit -s -m "chore: self mutation" git push origin HEAD:$HEAD_REF - name: Add label to block auto merge diff --git a/.github/workflows/pull-request-lint.yml b/.github/workflows/pull-request-lint.yml index b0e6b6fe2ac..8d5152f6581 100644 --- a/.github/workflows/pull-request-lint.yml +++ b/.github/workflows/pull-request-lint.yml @@ -8,7 +8,7 @@ on: - reopened - edited branches-ignore: - - mergify/merge-queue/** + - "mergify/merge-queue/*" jobs: validate: diff --git a/apps/jsii-docgen/LICENSE.md b/apps/jsii-docgen/LICENSE similarity index 100% rename from apps/jsii-docgen/LICENSE.md rename to apps/jsii-docgen/LICENSE diff --git a/apps/vscode-wing/.projen/tasks.json b/apps/vscode-wing/.projen/tasks.json index 3f734dbdf18..acba9e455ff 100644 --- a/apps/vscode-wing/.projen/tasks.json +++ b/apps/vscode-wing/.projen/tasks.json @@ -129,7 +129,7 @@ "exec": "pnpm version ${PROJEN_BUMP_VERSION:-0.0.0} --allow-same-version" }, { - "exec": "vsce package --no-dependencies -o vscode-wing.vsix" + "exec": "vsce package --no-dependencies -o ../../dist/vscode-wing.vsix" } ] }, diff --git a/apps/vscode-wing/.projenrc.ts b/apps/vscode-wing/.projenrc.ts index 881625f2ea3..153c2c3c3e8 100644 --- a/apps/vscode-wing/.projenrc.ts +++ b/apps/vscode-wing/.projenrc.ts @@ -237,7 +237,9 @@ project.watchTask.reset("tsup --watch"); project.packageTask.reset( "pnpm version ${PROJEN_BUMP_VERSION:-0.0.0} --allow-same-version" ); -project.packageTask.exec("vsce package --no-dependencies -o vscode-wing.vsix"); +project.packageTask.exec( + "vsce package --no-dependencies -o ../../dist/vscode-wing.vsix" +); project.addFields({ volta: { diff --git a/apps/vscode-wing/turbo.json b/apps/vscode-wing/turbo.json index 111f4fe2ca0..1dd1dd3b453 100644 --- a/apps/vscode-wing/turbo.json +++ b/apps/vscode-wing/turbo.json @@ -12,7 +12,7 @@ }, "package": { "inputs": ["syntaxes/**", "resources/**"], - "outputs": ["vscode-wing.vsix"] + "outputs": ["../../dist/vscode-wing.vsix"] } } } diff --git a/apps/wing-api-checker/.projenrc.ts b/apps/wing-api-checker/.projenrc.ts index 899a96c7905..3e0268cd960 100644 --- a/apps/wing-api-checker/.projenrc.ts +++ b/apps/wing-api-checker/.projenrc.ts @@ -8,8 +8,8 @@ const project = new typescript.TypeScriptProject({ "wing-api-check": "bin/wing-api-check", }, license: "MIT", - authorName: "Monada", - authorEmail: "ping@monada.co", + authorName: "Wing Cloud", + authorEmail: "ping@wing.cloud", authorOrganization: true, authorUrl: "https://wing.cloud", repository: "https://github.com/winglang/wing.git", diff --git a/apps/vscode-wing/LICENSE.md b/apps/wing-api-checker/LICENSE similarity index 100% rename from apps/vscode-wing/LICENSE.md rename to apps/wing-api-checker/LICENSE diff --git a/apps/wing-api-checker/LICENSE.md b/apps/wing-api-checker/LICENSE.md deleted file mode 100644 index 7265dc9aa7b..00000000000 --- a/apps/wing-api-checker/LICENSE.md +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2023 Wing Cloud, Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/apps/wing-api-checker/package.json b/apps/wing-api-checker/package.json index db2ada7b39c..3920459a1b4 100644 --- a/apps/wing-api-checker/package.json +++ b/apps/wing-api-checker/package.json @@ -29,7 +29,7 @@ }, "author": { "name": "Wing Cloud", - "email": "ping@monada.co", + "email": "ping@wing.cloud", "url": "https://wing.cloud", "organization": true }, diff --git a/apps/wing-console/console/app/demo/index.w b/apps/wing-console/console/app/demo/index.w index e125faf9350..c75e994ed23 100644 --- a/apps/wing-console/console/app/demo/index.w +++ b/apps/wing-console/console/app/demo/index.w @@ -8,9 +8,7 @@ let api = new cloud.Api(); api.get("/test-get", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { return cloud.ApiResponse { status: 200, - body: Json.stringify({ - query: Json (Json req).get("query"), - }) + body: Json.stringify(req.query) }; }); api.post("/test-post", inflight (req: cloud.ApiRequest): cloud.ApiResponse => { diff --git a/apps/wing-console/console/design-system/src/toolbar-button.tsx b/apps/wing-console/console/design-system/src/toolbar-button.tsx index 4383445a586..7a1ab6fdca4 100644 --- a/apps/wing-console/console/design-system/src/toolbar-button.tsx +++ b/apps/wing-console/console/design-system/src/toolbar-button.tsx @@ -19,7 +19,7 @@ export const ToolbarButton = ({ return (