i-slint-compiler 1.18.0

Internal Slint Compiler Library
Documentation
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

// cSpell: ignore badcolor
export component X {
    property <styled-text> t1: @markdown("Foo\invalid");
//                                           ><error{Unknown escape sequence. Use '\\' to escape a literal backslash}
    property <styled-text> t2: @markdown("Foo\u{e541}Bar");
//                                           > <error{\u{e541} is reserved for @markdown interpolation}
    property <styled-text> t2b: @markdown("Foo\u{e541}Bar \{some-prop}");
//                                            > <error{\u{e541} is reserved for @markdown interpolation}
    property <styled-text> t3: @markdown("XXX"  "TTT \{12px} ZZZ");
//                                                     >  <error{Cannot convert length to string. Divide by 1px to convert to a plain number}
    property <styled-text> t9: @markdown("{");
    property <styled-text> t10: @markdown("}");
    property <styled-text> t11: @markdown("{abc}");
    property <styled-text> t12: @markdown("{0");
    property <styled-text> t13: @markdown("> quote");
//                                         >     <error{Markdown block quotes are not supported}
    property <styled-text> t14: @markdown("![alt](image.png)");
//                                         >               <error{Markdown images are not supported}
    property <styled-text> t15: @markdown("---");
//                                         > <error{Markdown horizontal rules are not supported}
    property <styled-text> t16: @markdown("<span>text</span>");
//                                         >   <error{HTML tag <span> is not supported}
    property <styled-text> t17: @markdown("<div>text</div>");
//                                         >             <error{Markdown HTML blocks (<div>text</div>) are not supported}
    property <styled-text> t18: @markdown("<u>unclosed");
//                              >                      <error{Unterminated tag}
    property <styled-text> t19: @markdown("<font color='red'>unclosed");
//                              >                                     <error{Unterminated tag}
    property <styled-text> t20: @markdown("<u>text</font>");
//                                                >     <error{Closing html tag doesn't match the opening tag. Expected </u>, got </font>}
    property <styled-text> t21: @markdown("<font>text</font>");
//                                         >    <error{Missing color attribute in html <font>}
    property <styled-text> t22: @markdown("<font size='12'>text</font>");
//                                               >       <error{Unexpected size attribute in html <font size='12'>}
    property <styled-text> t23: @markdown("<u class='test'>text</u>");
//                                            >          <error{Unexpected class attribute in html <u class='test'>}
    property <styled-text> t24: @markdown("<font color='#q'>text</font>");
//                                               >        <error{Invalid color value '#q'}
    property <styled-text> t24b: @markdown("<font color='zzz'>text</font>");
//                                                >         <error{Invalid color value 'zzz'}

    // --- Comprehensive error location tests ---

    property <string> some-prop: "hello";

    // Multiple unrelated errors in one expression: each should point to its own tag
    property <styled-text> m1: @markdown("<xyz>text</xyz> *ok* <abc>text</abc>");
//                                        >  <error{HTML tag <xyz> is not supported}
//                                                             >  <^error{HTML tag <abc> is not supported}

    // Error in second string literal: should point to that literal
    property <styled-text> m2: @markdown("*hello* " "<xyz>world</xyz>");
//                                                   >  <error{HTML tag <xyz> is not supported}

    // Error with interpolation before it
    property <styled-text> m3: @markdown("hello \{some-prop} " "<xyz>oops</xyz>");
//                                                              >  <error{HTML tag <xyz> is not supported}

    // Multiple string literals, error in middle one
    property <styled-text> m4: @markdown("aaa" "<xyz>ccc</xyz>" " ddd");
//                                              >  <error{HTML tag <xyz> is not supported}

    // Valid markdown mixed with errors in different literals
    property <styled-text> m5: @markdown("**bold** " "<xyz>bad</xyz>" " *italic*");
//                                                    >  <error{HTML tag <xyz> is not supported}

    // Block quote error in a multi-line expression
    property <styled-text> m6: @markdown("text"
                                         "\n> block quote");
//                                          >           <error{Markdown block quotes are not supported}

    // Multiple errors on different lines
    property <styled-text> m7: @markdown("--- "
                                         "<span>text</span>");
//                                        >   <error{HTML tag <span> is not supported}

    // Error after interpolation in multi-line
    property <styled-text> m8: @markdown("hello \{some-prop}"
                                         " <xyz>bad</xyz>");
//                                         >  <error{HTML tag <xyz> is not supported}

    // Invalid color in second literal
    property <styled-text> m9: @markdown("hello "
                                         "<font color='invalid'>colored</font>");
//                                              >             <error{Invalid color value 'invalid'}

    // Two errors in two different literals
    property <styled-text> m10: @markdown("<xyz>aa</xyz>"
//                                         >  <error{HTML tag <xyz> is not supported}
                                          " <abc>bb</abc>");
//                                          >  <error{HTML tag <abc> is not supported}

    // Longer markdown with error in the middle
    property <styled-text> m11: @markdown("*bold* normal **strong** <xyz>bad</xyz> _italic_");
//                                                                  >  <error{HTML tag <xyz> is not supported}

    // Literal invalid color alongside an interpolation (should still report the error)
    property <styled-text> m12: @markdown("<font color='badcolor'>\{some-prop}</font>");
//                                               >              <error{Invalid color value 'badcolor'}

    // Valid interpolated color with a color property (should not report error)
    property <color> some-color: red;
    property <styled-text> m13: @markdown("<font color='\{some-color}'>text</font>");

    // Multiple attributes and tags in longer content
    property <styled-text> m14: @markdown("hello *world* "
                                          "<font color='invalid'>colored</font>"
//                                               >             <error{Invalid color value 'invalid'}
                                          " **more** text");

    // Error in tag after valid content and interpolation
    property <styled-text> m15: @markdown("prefix \{some-prop} middle "
                                          "<abc>bad</abc>"
//                                         >  <error{HTML tag <abc> is not supported}
                                          " suffix");

    // --- Color interpolation type checking ---

    // String cannot convert to color
    property <styled-text> c1: @markdown("<font color='\{some-prop}'>text</font>");
//                                                       >       <error{Cannot convert string to color}

    // Integer cannot convert to color
    property <styled-text> c2: @markdown("<font color='\{42}'>text</font>");
//                                                       ><error{Cannot convert float to color}

    // Length cannot convert to color
    property <styled-text> c3: @markdown("<font color='\{12px}'>text</font>");
//                                                       >  <error{Cannot convert length to color}

    // Brush converts to color (narrowing)
    property <brush> some-brush: red;
    property <styled-text> c4: @markdown("<font color='\{some-brush}'>text</font>");

    // Color property works
    property <color> my-color: blue;
    property <styled-text> c5: @markdown("<font color='\{my-color}'>text</font>");

    // Color literal works
    property <styled-text> c6: @markdown("<font color='\{Colors.red}'>text</font>");

    // Non-color interpolation still requires string conversion (length fails)
    property <styled-text> c7: @markdown("value: \{12px}");
//                                                 >  <error{Cannot convert length to string. Divide by 1px to convert to a plain number}

    // --- Edge cases: interpolation inside HTML tag structure is not allowed ---

    // Interpolated tag name
    property <styled-text> e1: @markdown("interpolation <\{"u"}>tags</\{"u"}>");
//                                                      >  <error{Interpolation (`\{}`) is not allowed inside HTML tags}

    // Interpolated whole attribute
    property <styled-text> e2: @markdown("or argument <font \{"color='blue'"}>xx</font>");
//                                                    >        <error{Interpolation (`\{}`) is not allowed inside HTML tags}

    // Interpolated attribute name
    property <styled-text> e3: @markdown("<font \{"color"}='red'>text</font>");
//                                                >       <error{Interpolation (`\{}`) is not allowed inside HTML tags}

    // Interpolation appended to tag name
    property <styled-text> e4: @markdown("<u\{""}>xx</u>");
//                                        >   <error{Interpolation (`\{}`) is not allowed inside HTML tags}
    // Interpolation in closing tag
    property <styled-text> e5: @markdown("<u>xx</u \{""}>");
//                             >                          <error{Unterminated tag}
    // Interpolation mixed with literal in color value
    property <styled-text> e6: @markdown("<font color='\{""}blue'>xx</font>");
//                                              >             <error{Interpolation (`\{}`) is not allowed inside HTML tags}
    // Extra attribute after color
    property <styled-text> e7: @markdown("<font color='blue' \{""}>xx</u \{""}>");
//                                        >                     <error{Interpolation (`\{}`) is not allowed inside HTML tags}
//                             >                                                <^error{Unterminated tag}

    // Interleaved HTML and markdown styles (#11563)
    property <styled-text> t26: @markdown("<u>*</u>*");
//                                             >  <error{HTML tag </u> overlaps with markdown formatting}
    property <styled-text> t27: @markdown("<u>*hello</u> world*");
//                                                  >  <error{HTML tag </u> overlaps with markdown formatting}
    // Interleaving plus a genuinely unclosed tag
    property <styled-text> t29: @markdown("<u>*</u>*<font color=\"red\">text");
//                                             >  <error{HTML tag </u> overlaps with markdown formatting}
//                              >                                            <^error{Unterminated tag}
    property <styled-text> t28: @markdown("<u><font color=\"red\"></u></font>");
//                                                                >  <error{Closing html tag doesn't match the opening tag. Expected </font>, got </u>}
//                                                                    >     <^error{Closing html tag doesn't match the opening tag. Expected </u>, got </font>}

    // Combined errors from different markdown features in a single string with escape sequences
    property <styled-text> t25: @markdown("---\n\n> quote\n\n<span>text</span>");
//                                         >  <error{Markdown horizontal rules are not supported}
//                                                >      <^error{Markdown block quotes are not supported}
//                                                           >   <^^error{HTML tag <span> is not supported}
}