File tree Expand file tree Collapse file tree
src/compiler/phases/3-transform/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2328,10 +2328,15 @@ const visitors = {
23282328 let alternate_id ;
23292329
23302330 if ( node . alternate !== null ) {
2331- const alternate = /** @type {AST.BlockStatement | AST.IfStatement } */ ( node . alternate ) ;
2331+ const alternate = /** @type {AST.Statement } */ ( node . alternate ) ;
23322332 const alternate_scope = context . state . scopes . get ( alternate ) || context . state . scope ;
23332333 /** @type {AST.Node[] } */
2334- let alternate_body = alternate . type === 'IfStatement' ? [ alternate ] : alternate . body ;
2334+ let alternate_body =
2335+ alternate . type === 'IfStatement'
2336+ ? [ alternate ]
2337+ : alternate . type === 'BlockStatement'
2338+ ? alternate . body
2339+ : [ alternate ] ;
23352340 const alternate_block = b . block (
23362341 transform_body ( alternate_body , {
23372342 ...context ,
@@ -2940,10 +2945,14 @@ function transform_ts_child(node, context) {
29402945 let alternate ;
29412946
29422947 if ( node . alternate !== null ) {
2943- const alternate_node = /** @type {AST.BlockStatement | AST.IfStatement } */ ( node . alternate ) ;
2948+ const alternate_node = /** @type {AST.Statement } */ ( node . alternate ) ;
29442949 const alternate_scope = context . state . scopes . get ( alternate_node ) || context . state . scope ;
29452950 const alternate_body =
2946- alternate_node . type === 'IfStatement' ? [ alternate_node ] : alternate_node . body ;
2951+ alternate_node . type === 'IfStatement'
2952+ ? [ alternate_node ]
2953+ : alternate_node . type === 'BlockStatement'
2954+ ? alternate_node . body
2955+ : [ alternate_node ] ;
29472956 alternate = b . block (
29482957 transform_body ( alternate_body , {
29492958 ...context ,
Original file line number Diff line number Diff line change @@ -340,6 +340,26 @@ export component App(props: Props) {
340340 expect(result).toContain('extends PolymorphicProps<\'div\'>');
341341 });
342342
343+ it('handles if-else expression statements in Volar mappings', () => {
344+ const source = `
345+ export component App() {
346+ let level = #ripple.track(1);
347+
348+ <button
349+ onClick={() => {
350+ if (@level === 1) @level = 2;
351+ else if (@level === 2) @level = 3;
352+ else @level = 1;
353+ }}
354+ >
355+ {'Toggle'}
356+ </button>
357+ }
358+ `;
359+
360+ expect(() => compile_to_volar_mappings(source, 'test.ripple')).not.toThrow();
361+ });
362+
343363 it('should not error on having js below markup in the same scope', () => {
344364 const code = `
345365component Card(props) {
You can’t perform that action at this time.
0 commit comments