@@ -648,7 +648,15 @@ describe('TSRX parser', () => {
648648 } ) ;
649649
650650 it ( 'starts an element after comments on the line after a semicolon-less statement' , ( ) => {
651- for ( const comment of [ '/* render */' , '/* a */ /* b */' , '// note\n /* render */' ] ) {
651+ for ( const comment of [
652+ '/* render */' ,
653+ '/* a */ /* b */' ,
654+ '// note\n /* render */' ,
655+ // A `/*` inside the comment is text. The opener is the outer `/*`.
656+ '/* mention /* here */' ,
657+ '/** jsdoc mentions /* */' ,
658+ '/* a */ /* mention /* here */' ,
659+ ] ) {
652660 const block = findNode (
653661 `export function App() @{\n const x = a\n ${ comment } <div />\n}` ,
654662 'JSXCodeBlock' ,
@@ -666,12 +674,15 @@ describe('TSRX parser', () => {
666674 expect ( program . body . map ( ( node ) => node . type ) ) . toEqual ( [ 'ExpressionStatement' , 'JSXElement' ] ) ;
667675 }
668676
669- // A comment that spans lines separates the statements like a line break.
670- const block = findNode (
677+ // A comment that spans lines separates the statements like a line break,
678+ // including when a `/*` in the comment sits after that line break.
679+ for ( const source of [
671680 'export function App() @{\n const x = a /* a\n b */ <div />\n}' ,
672- 'JSXCodeBlock' ,
673- ) ;
674- expect ( codeBlockRender ( block ) . type ) . toBe ( 'JSXElement' ) ;
681+ 'export function App() @{\n const x = a /* mention\n still /* here */ <div />\n}' ,
682+ ] ) {
683+ const block = findNode ( source , 'JSXCodeBlock' ) ;
684+ expect ( codeBlockRender ( block ) . type ) . toBe ( 'JSXElement' ) ;
685+ }
675686 } ) ;
676687
677688 it ( 'keeps a `<` after a comment on the same line as the previous value a comparison' , ( ) => {
@@ -683,6 +694,25 @@ describe('TSRX parser', () => {
683694 expect ( ( ) =>
684695 parseModule ( 'export function App() @{\n const x = a /* note */ <div />\n}' , 'App.tsrx' ) ,
685696 ) . toThrow ( ) ;
697+ expect ( ( ) =>
698+ parseModule ( 'export function App() @{\n const x = a /* note /* x */ <div />\n}' , 'App.tsrx' ) ,
699+ ) . toThrow ( ) ;
700+ // A `/*` inside an earlier string is not the comment opener, so a `<div />`
701+ // on the same line as the value is still not an element.
702+ expect ( ( ) =>
703+ parseModule (
704+ 'export function App() @{\n const x = "/*" +\n a /* note /* x */ <div />\n}' ,
705+ 'App.tsrx' ,
706+ ) ,
707+ ) . toThrow ( ) ;
708+ const compared = firstStatement (
709+ parseModule ( 'x = "/*" +\na /* note /* x */ < b' , 'App.tsrx' ) ,
710+ 'ExpressionStatement' ,
711+ ) ;
712+ expect (
713+ as_type ( as_type ( compared . expression , 'AssignmentExpression' ) . right , 'BinaryExpression' )
714+ . operator ,
715+ ) . toBe ( '<' ) ;
686716 } ) ;
687717
688718 it ( 'parses mixed scalar and JSX return branches' , ( ) => {
0 commit comments