Skip to content

Commit cab75a0

Browse files
CopilotElMassimo
andauthored
fix: address review feedback and sanitize vue listener wrapping
Agent-Logs-Url: https://github.com/ElMassimo/iles/sessions/64e6d452-d6f0-447a-9605-2933041a844f Co-authored-by: ElMassimo <1158253+ElMassimo@users.noreply.github.com>
1 parent e182ca4 commit cab75a0

7 files changed

Lines changed: 8 additions & 10 deletions

File tree

packages/iles/jsx-runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function wrapListeners (props, type) {
4242
args[0],
4343
{
4444
source: 'mdx',
45-
event: key.slice(2).toLowerCase(),
45+
event: key.slice(2),
4646
tag: typeof type === 'string' ? type : type?.name || 'Component',
4747
},
4848
)

packages/iles/src/client/app/components/DebugPanel.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default defineComponent({
1212
const open = ref(false)
1313
const buttonLabel = computed(() => message.value || 'Debug')
1414
const listenerWarnings = computed(() => (window as any).__ILE_DEVTOOLS__?.getListenerWarnings?.() || [])
15+
const formattedListenerWarnings = computed(() => listenerWarnings.value.map((item: any) => item.message).join('\n\n'))
1516
1617
const cleanPage = computed(() => {
1718
const layout = page.value.layoutName || 'false'
@@ -56,6 +57,7 @@ export default defineComponent({
5657
copyAll,
5758
content,
5859
listenerWarnings,
60+
formattedListenerWarnings,
5961
}
6062
},
6163
})
@@ -66,7 +68,7 @@ export default defineComponent({
6668
<p class="title">{{ buttonLabel }}<span class="info">Open DevTools to inspect <b>islands</b> 🏝</span></p>
6769
<pre ref="content" class="block">{{ cleanPage }}</pre>
6870
<pre v-if="listenerWarnings.length" class="block warning">
69-
{{ listenerWarnings.map((item: any) => item.message).join('\n\n') }}
71+
{{ formattedListenerWarnings }}
7072
</pre>
7173
<button v-show="open" class="debug title" @click="copyAll(content)">Copy to Clipboard</button>
7274
</div>

packages/iles/src/client/app/listenerGuard.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,3 @@ export function guardListenerCall<T> (handler: () => T, event: Event, details: L
4646

4747
if (typeof window !== 'undefined')
4848
(window as any).__ILE_GUARD_LISTENER_CALL__ = guardListenerCall
49-

packages/iles/src/node/plugin/wrap.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function processSFCListeners (elements: ElementNode[], s: MagicString, filename:
135135
options.warn?.(warning)
136136

137137
if (options.wrapListeners && prop.exp?.loc?.source)
138-
s.overwrite(prop.exp.loc.start.offset, prop.exp.loc.end.offset, guardedVueExpression(prop.exp.loc.source, warning))
138+
wrapVueExpression(s, prop.exp.loc.start.offset, prop.exp.loc.end.offset, warning)
139139
}
140140

141141
for (const child of node.children || []) {
@@ -148,13 +148,13 @@ function processSFCListeners (elements: ElementNode[], s: MagicString, filename:
148148
walk(element)
149149
}
150150

151-
function guardedVueExpression (expression: string, warning: ListenerWarning) {
151+
function wrapVueExpression (s: MagicString, start: number, end: number, warning: ListenerWarning) {
152152
const details = JSON.stringify({
153153
source: 'vue',
154154
...warning,
155155
})
156-
const run = `{ const __ile_handler = (${expression}); return typeof __ile_handler === 'function' ? __ile_handler($event) : __ile_handler }`
157-
return `($event) => (window.__ILE_GUARD_LISTENER_CALL__ ? window.__ILE_GUARD_LISTENER_CALL__(() => ${run}, $event, ${details}) : (() => ${run})())`
156+
s.appendLeft(start, `($event) => window.__ILE_GUARD_LISTENER_CALL__(() => { const _ileHandler = (`)
157+
s.appendRight(end, `); return typeof _ileHandler === 'function' ? _ileHandler($event) : _ileHandler }, $event, ${details})`)
158158
}
159159

160160
function isOnDirective (prop: any): prop is DirectiveNode {

packages/iles/tests/listener-guard.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ describe('listener guard', () => {
3737
expect(errors.length).toBe(0)
3838
})
3939
})
40-

packages/iles/tests/remark-wrap-islands.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ describe('remarkWrapIslands listener diagnostics', () => {
3131
expect(warnings[0]).toContain('/src/pages/demo.mdx')
3232
})
3333
})
34-

packages/iles/tests/wrap.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ describe('wrapIslandsInSFC listener diagnostics', () => {
3434
expect(result?.code).toContain('__ILE_GUARD_LISTENER_CALL__')
3535
})
3636
})
37-

0 commit comments

Comments
 (0)