lwc icon indicating copy to clipboard operation
lwc copied to clipboard

[Complex expressions] Duplicate `$cmp.$cmp.prop` generated

Open nolanlawson opened this issue 1 year ago • 1 comments

Repro

<template>
    <template for:each={rows} for:item="row">
        <div key={row}>
            <a onclick={() => one(row)}>
                one
            </a>
            <a onclick={() => two(row)}>
                two
            </a>
        </div>
    </template>
</template>

Generates:

function tmpl($api, $cmp, $slotset, $ctx) {
    /* ... */
    return api_iterator($cmp.rows, function(row) {
        return api_element("tr", {
            key: api_key(0, row.id)
        }, [api_element("td", stc0, [api_element("a", {
            key: 2,
            on: {
                "click": _m0 || ($ctx._m0 = api_bind(() => $cmp.select(row.id)))
            }
        }, [api_text(api_dynamic_text(row.label))])]), api_element("td", stc1, [api_static_fragment($fragment1(), 5, {
            on: {
                "click": _m2 || ($ctx._m2 = api_bind(() => $cmp.$cmp.remove(row.id)))
            }
        })])]);
    });
}

The problem is this line:

"click": _m2 || ($ctx._m2 = api_bind(() => $cmp.$cmp.remove(row.id)))

Note the duplicate $cmp.$cmp.remove rather than just $cmp.remove. This is the wrong method to call on the component.

nolanlawson avatar Jul 12 '23 16:07 nolanlawson

This may be related to https://github.com/salesforce/lwc/issues/3808

nolanlawson avatar Oct 19 '23 15:10 nolanlawson