The design language that makes your AI harness better at design.
JavaScript
Fix: live-wrap matches a capitalised component to its rendered tag (#875)
Abdul Wahabac2ee4231132
diff --git a/crates/live/src/wrap_common.rs b/crates/live/src/wrap_common.rsindex 5961aa3ea..71f1b6a4e 100644--- a/crates/live/src/wrap_common.rs+++ b/crates/live/src/wrap_common.rs@@ -228,11 +228,12 @@ pub fn filter_by_text(}/// JS: findOpenerLine(lines, matchLine, tag)+/// The browser reports the rendered tag lowercased, so a source `<Input>` matches `input`.pub fn find_opener_line(lines: &[String], match_line: usize, tag: Option<&str>) -> Option<usize> {if let Some(t) = opener_tag(&lines[match_line]) {return match tag {None => Some(match_line),- Some(want) if want == t => Some(match_line),+ Some(want) if want.eq_ignore_ascii_case(&t) => Some(match_line),_ => None,};}@@ -246,7 +247,7 @@ pub fn find_opener_line(lines: &[String], match_line: usize, tag: Option<&str>)};return match tag {None => Some(i),- Some(want) if want == t => Some(i),+ Some(want) if want.eq_ignore_ascii_case(&t) => Some(i),_ => None,};}@@ -404,3 +405,22 @@ pub fn count_len(count: i64) -> i64 {count}}++#[cfg(test)]+mod tests {+ use super::*;++ fn lines(src: &[&str]) -> Vec<String> {+ src.iter().map(|l| l.to_string()).collect()+ }++ #[test]+ fn find_opener_line_ignores_tag_case() {+ let one_line = lines(&[r#"<Input id="password" type="password" required />"#]);+ assert_eq!(find_opener_line(&one_line, 0, Some("input")), Some(0));+ let multi_line = lines(&["<Input", r#" id="email""#, "/>"]);+ assert_eq!(find_opener_line(&multi_line, 1, Some("input")), Some(0));+ let other = lines(&[r#"<Label id="email" />"#]);+ assert_eq!(find_opener_line(&other, 0, Some("input")), None);+ }+}diff --git a/docs/CLI-CONTRACT.md b/docs/CLI-CONTRACT.mdindex befe49683..a7496732b 100644--- a/docs/CLI-CONTRACT.md+++ b/docs/CLI-CONTRACT.md@@ -1660,7 +1660,7 @@ Param kinds: `range` `{id,kind:'range',min,max,step,default,label}` → CSS varSource search (`live/source-search.mjs`): dirs in order `src, app, pages, components, public, views, templates, lib, .`; skip `node_modules, .git, .impeccable` (accept also skips `dist, build`); depth ≤5; realpath cycle guard; files before dirs; extensions = `LIVE_TEMPLATE_EXTENSIONS` (`.html,.jsx,.tsx,.vue,.svelte,.astro,.ex,.heex,.eex`) + `.impeccable/config.json`/`config.local.json` `detector.extensions`; suffix match. Wrap additionally rejects generated files (`isGeneratedFile`: `git check-ignore --quiet` exit 0 **[spawns git]** or first 300 bytes match `/@generated\b/i`, `/\bGENERATED\s+FILE\b/`, `/\bAUTO-?GENERATED\b/i`, `/\bDO\s+NOT\s+EDIT\b/i`).-Search queries built from flags in order: `id="<id>"`; if multiple classes: `class="<joined>"`, `className="<joined>"`, then each class longest-first; single class: the class; `<tag class="<first>` and `<tag className="<first>` when tag+classes; raw `--query`. Element location: first line containing query (skipping lines starting with `<!--`,`{/*`,`//` or containing `data-impeccable-variant`), resolve opener (`/<([A-Za-z][A-Za-z0-9]*)(?=[\s/>]|$)/` on the line, else walk back ≤10 lines; a differently-named opener aborts), closer by depth counting (`<tag`, `<tag …/>`, `</tag>`), fallback `min(start+50, last)`. With `--text` (≥8 normalized chars): all candidates, filter by text (spaced or compact normalization of tag/JSX-stripped body).+Search queries built from flags in order: `id="<id>"`; if multiple classes: `class="<joined>"`, `className="<joined>"`, then each class longest-first; single class: the class; `<tag class="<first>` and `<tag className="<first>` when tag+classes; raw `--query`. Element location: first line containing query (skipping lines starting with `<!--`,`{/*`,`//` or containing `data-impeccable-variant`), resolve opener (`/<([A-Za-z][A-Za-z0-9]*)(?=[\s/>]|$)/` on the line, else walk back ≤10 lines; a differently-named opener aborts; the opener name is compared to `--tag` ignoring ASCII case, so `--tag input` matches an `<Input>` component), closer by depth counting (`<tag`, `<tag …/>`, `</tag>`), fallback `min(start+50, last)`. With `--text` (≥8 normalized chars): all candidates, filter by text (spaced or compact normalization of tag/JSX-stripped body).#### 8. Svelte component preview (`live/svelte-component.mjs`, `live/svelte-ast.mjs`)diff --git a/tests/oracle/cases/live-wrap.mjs b/tests/oracle/cases/live-wrap.mjsindex da210757c..136553a3b 100644--- a/tests/oracle/cases/live-wrap.mjs+++ b/tests/oracle/cases/live-wrap.mjs@@ -40,6 +40,10 @@ export default [W('live-wrap-jsx-deferred', 'live-vite', ['--id', 'ab12cd34', '--classes', 'hero-title', '--tag', 'h1', '--defer-source-write'], { snap: ['src/**'] }),W('live-wrap-jsx-mapped-item', 'live-vite', ['--id', 'ab12cd34', '--classes', 'item-row', '--tag', 'li', '--text', 'First'], { snap: ['src/**'] }),W('live-wrap-tsx-multiline', 'live-vite', ['--id', 'ab12cd34', '--classes', 'panel', '--tag', 'section'], { snap: ['src/**'] }),+ W('live-wrap-tsx-component-tag-case', 'live-vite', ['--id', 'ab12cd34', '--count', '1', '--element-id', 'password', '--tag', 'input', '--file', 'src/Login.tsx', '--defer-source-write'], {+ snap: ['src/Login.tsx'],+ setup: (ws) => write(ws, 'src/Login.tsx', 'export function Login() {\n return (\n <form>\n <Input id="password" type="password" required />\n </form>\n );\n}\n'),+ }),W('live-wrap-astro', 'live-astro', ['--id', 'ab12cd34', '--classes', 'hero-title', '--tag', 'h1'], { snap: ['src/**'] }),W('live-wrap-astro-deferred', 'live-astro', ['--id', 'ab12cd34', '--element-id', 'features', '--defer-source-write'], { snap: ['src/**'] }),W('live-wrap-vue', 'live-nuxt', ['--id', 'ab12cd34', '--classes', 'hero-title', '--tag', 'h1'], { snap: ['pages/**'] }),diff --git a/tests/oracle/golden/live-wrap-tsx-component-tag-case.json b/tests/oracle/golden/live-wrap-tsx-component-tag-case.jsonnew file mode 100644index 000000000..9997b52a0--- /dev/null+++ b/tests/oracle/golden/live-wrap-tsx-component-tag-case.json@@ -0,0 +1,10 @@+{+ "stdout": "{\"file\":\"src/Login.tsx\",\"sourceWritten\":false,\"wrapperBlock\":\" <div data-impeccable-variants=\\\"ab12cd34\\\" data-impeccable-variant-count=\\\"1\\\" style={{ display: \\\"contents\\\" }}>\\n {/* impeccable-variants-start ab12cd34 */}\\n {/* Original */}\\n <div data-impeccable-variant=\\\"original\\\">\\n <Input id=\\\"password\\\" type=\\\"password\\\" required />\\n </div>\\n {/* Variants: insert below this line */}\\n {/* impeccable-variants-end ab12cd34 */}\\n </div>\",\"replaceStartLine\":4,\"replaceEndLine\":4,\"startLine\":4,\"endLine\":12,\"insertLine\":10,\"commentSyntax\":{\"open\":\"{/*\",\"close\":\"*/}\"},\"styleMode\":\"scoped\",\"styleTag\":\"<style data-impeccable-css=\\\"SESSION_ID\\\">\",\"cssSelectorPrefixExamples\":[],\"cssAuthoring\":{\"mode\":\"scoped\",\"styleTag\":\"<style data-impeccable-css=\\\"SESSION_ID\\\">\",\"strategy\":\"scope-rule\",\"rulePattern\":\"@scope ([data-impeccable-variant=\\\"N\\\"]) { :scope > .variant-class { ... } }\",\"selectorExamples\":[\"@scope ([data-impeccable-variant=\\\"1\\\"]) { :scope > .variant-class { ... } }\"],\"requirements\":[\"Use @scope blocks keyed to each [data-impeccable-variant=\\\"N\\\"] wrapper.\",\"Inside each @scope block, make :scope rules step into the replacement element with a descendant combinator.\",\"Use the styleTag exactly; do not add framework-specific style attributes unless this object says to.\"],\"forbidden\":[\"Do not use global [data-impeccable-variant=\\\"N\\\"] selector prefixes for this styleMode.\",\"Do not add is:inline to the style tag for this styleMode.\"]},\"originalLineCount\":1}\n",+ "stderr": "",+ "exit": 0,+ "signal": null,+ "files": {+ ".impeccable/live/config.json": "{\n \"files\": [\"index.html\"],\n \"insertBefore\": \"</body>\",\n \"commentSyntax\": \"html\"\n}\n",+ "src/Login.tsx": "export function Login() {\n return (\n <form>\n <Input id=\"password\" type=\"password\" required />\n </form>\n );\n}\n"+ }+}