Skip to content

CSP build: wire:click="delete" fails, reserved words can't be used as method names #4904

Closed

Description

@MaxencePaulin

Alpine.js version

v3.17.2

Browser and operating system

Brave on Windows

Describe the issue you're experiencing

In the CSP-safe build, reserved words like delete, new, true, null, undefined etc. cannot be used as property or method names after a . or as object literal keys, even though this is valid in normal JavaScript.

This breaks Livewire's wire:click="delete" directive, which Alpine/Livewire's integration compiles down to x-on:click="$wire.delete", calling .delete on $wire fails to parse under CSP.

Code snippets to reproduce the issue

With the CSP build, this throws a parse error instead of calling the method.

<div x-data="test">
    <button x-on:click="obj.delete()">Delete</button>
</div>

<script>
    document.addEventListener('alpine:init', () => {
        Alpine.data('test', () => ({
            obj: {
                delete: () => console.log('deleted')
            }
        }))
    })
</script>

Screenshots/screen recordings

//

How do you expect it to work?

Reserved words should be usable as property/method names via dot access and as object literal keys i guess.

Please confirm (incomplete submissions will not be addressed)

  • I have provided easy and step-by-step instructions to reproduce the bug.
  • I have provided code samples as text and NOT images.
  • I understand my bug report will be removed if I haven't met the criteria above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions