| ... | ... | @@ -151,7 +151,6 @@ pub fn parse_open(src: &str) -> Result<Open, OxcDiagnostic> { |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // in any order: parameters, arguments, variable |
| 154 | | // TODO: create errors when things repeat |
| 155 | 154 | let mut has_js_arguments = false; |
| 156 | 155 | let mut has_js_params = false; |
| 157 | 156 | let mut has_js_variable = false; |
| ... | ... | @@ -182,13 +181,31 @@ pub fn parse_open(src: &str) -> Result<Open, OxcDiagnostic> { |
| 182 | 181 | has_js_params = true; |
| 183 | 182 | } |
| 184 | 183 | b'(' => { |
| 185 | | // arguments |
| 186 | 184 | if has_js_arguments { |
| 187 | 185 | return Err(err("Function call already specified", offset, 1)); |
| 188 | 186 | } |
| 189 | | // TODO: METHOD SHORTHAND |
| 190 | | println!("{}", l.peek_rest()); |
| 191 | | parse_call_arguments(&mut l)?; |
| 187 | |
| 188 | let start_offset = l.offset; |
| 189 | if parse_call_arguments(&mut l).is_ok() { |
| 190 | let after_call = l.peek_rest().trim_start(); |
| 191 | if after_call.starts_with('{') { |
| 192 | l.offset = start_offset; |
| 193 | l.skip_whitespace(); |
| 194 | if l.peek_byte() == Some(b'=') { |
| 195 | l.offset += 1; |
| 196 | l.skip_whitespace(); |
| 197 | } |
| 198 | parse_fn_params_and_body(&mut l)?; |
| 199 | } |
| 200 | } else { |
| 201 | l.offset = start_offset; |
| 202 | l.skip_whitespace(); |
| 203 | if l.peek_byte() == Some(b'=') { |
| 204 | l.offset += 1; |
| 205 | l.skip_whitespace(); |
| 206 | } |
| 207 | parse_fn_params_and_body(&mut l)?; |
| 208 | } |
| 192 | 209 | l.skip_whitespace(); |
| 193 | 210 | has_js_arguments = true; |
| 194 | 211 | } |
| ... | ... | @@ -1081,6 +1098,42 @@ mod tests { |
| 1081 | 1098 | ); |
| 1082 | 1099 | } |
| 1083 | 1100 | |
| 1101 | #[test] |
| 1102 | fn test_value_method_shorthand() { |
| 1103 | assert_eq!( |
| 1104 | parse_open("<my-tag() { console.log(\"hi\") }>"), |
| 1105 | Ok(Open { |
| 1106 | tag_name: "my-tag", |
| 1107 | content: "<my-tag() { console.log(\"hi\") }>", |
| 1108 | self_closing: false, |
| 1109 | }) |
| 1110 | ); |
| 1111 | } |
| 1112 | |
| 1113 | #[test] |
| 1114 | fn test_value_method_shorthand_self_closing() { |
| 1115 | assert_eq!( |
| 1116 | parse_open("<my-tag() { console.log(\"hi\") }/>"), |
| 1117 | Ok(Open { |
| 1118 | tag_name: "my-tag", |
| 1119 | content: "<my-tag() { console.log(\"hi\") }/>", |
| 1120 | self_closing: true, |
| 1121 | }) |
| 1122 | ); |
| 1123 | } |
| 1124 | |
| 1125 | #[test] |
| 1126 | fn test_value_method_shorthand_with_param() { |
| 1127 | assert_eq!( |
| 1128 | parse_open("<my-tag(e) { console.log(e) }>"), |
| 1129 | Ok(Open { |
| 1130 | tag_name: "my-tag", |
| 1131 | content: "<my-tag(e) { console.log(e) }>", |
| 1132 | self_closing: false, |
| 1133 | }) |
| 1134 | ); |
| 1135 | } |
| 1136 | |
| 1084 | 1137 | #[test] |
| 1085 | 1138 | fn test_combined_variable_and_args() { |
| 1086 | 1139 | assert_eq!( |