authorgravatar for git@paperclover.netclover caruso <git@paperclover.net> 2026-02-13 22:33:32-08:00
committergravatar for git@paperclover.netclover caruso <git@paperclover.net> 2026-02-14 00:45:48-08:00
log58a283e05798c101249323984c79a9ba0c02d1cc
treef19a7f20a5a65d75329b7f2de11c01764336f202
parent53c5bb422209c15c3f82a8ec510b084ca3f47878
signaturebadge-check Signed by SSH key SHA256:xbd+BjjhyBfwk7GVoURf9Yx0gzDerHbvYv7SddNWmAs

feat: method shorthand


1 files changed, 58 insertions(+), 5 deletions(-)

src/marko.rs+58-5
...@@ -151,7 +151,6 @@ pub fn parse_open(src: &str) -> Result<Open, OxcDiagnostic> {...@@ -151,7 +151,6 @@ pub fn parse_open(src: &str) -> Result<Open, OxcDiagnostic> {
151 }151 }
152152
153 // in any order: parameters, arguments, variable153 // in any order: parameters, arguments, variable
154 // TODO: create errors when things repeat
155 let mut has_js_arguments = false;154 let mut has_js_arguments = false;
156 let mut has_js_params = false;155 let mut has_js_params = false;
157 let mut has_js_variable = false;156 let mut has_js_variable = false;
...@@ -182,13 +181,31 @@ pub fn parse_open(src: &str) -> Result<Open, OxcDiagnostic> {...@@ -182,13 +181,31 @@ pub fn parse_open(src: &str) -> Result<Open, OxcDiagnostic> {
182 has_js_params = true;181 has_js_params = true;
183 }182 }
184 b'(' => {183 b'(' => {
185 // arguments
186 if has_js_arguments {184 if has_js_arguments {
187 return Err(err("Function call already specified", offset, 1));185 return Err(err("Function call already specified", offset, 1));
188 }186 }
189 // TODO: METHOD SHORTHAND187
190 println!("{}", l.peek_rest());188 let start_offset = l.offset;
191 parse_call_arguments(&mut l)?;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 l.skip_whitespace();209 l.skip_whitespace();
193 has_js_arguments = true;210 has_js_arguments = true;
194 }211 }
...@@ -1081,6 +1098,42 @@ mod tests {...@@ -1081,6 +1098,42 @@ mod tests {
1081 );1098 );
1082 }1099 }
10831100
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 #[test]1137 #[test]
1085 fn test_combined_variable_and_args() {1138 fn test_combined_variable_and_args() {
1086 assert_eq!(1139 assert_eq!(