Skip to content

quoted method names are treated as undefined when validating / checking for duplicates #914

@m59peacemaker

Description

@m59peacemaker

This is broken:

methods: {
  'foo': () => {},
  'bar': () => {}
}

REPL

Stack Trace bundle.35d793bc40a79d89436e63d8b274bfd88d0208bd.js:1 ValidationError: Duplicate property 'undefined' at ValidationError.CompileError [as constructor] (https://unpkg.com/[email protected]/compiler/svelte.js:11347:28) at new ValidationError (https://unpkg.com/[email protected]/compiler/svelte.js:12555:28) at Validator.error (https://unpkg.com/[email protected]/compiler/svelte.js:12576:15) at https://unpkg.com/[email protected]/compiler/svelte.js:11501:23 at Array.forEach () at checkForDupes (https://unpkg.com/[email protected]/compiler/svelte.js:11499:16) at methods (https://unpkg.com/[email protected]/compiler/svelte.js:11685:5) at https://unpkg.com/[email protected]/compiler/svelte.js:12067:21 at Array.forEach () at https://unpkg.com/[email protected]/compiler/svelte.js:12064:41

Admittedly, I encountered this whilst trying to hack svelte's static analysis of my method names. So, perhaps it is best that method names are not permitted to be quoted. I need to call some functions that are created at runtime, so I did this in oncreate this.someFunctions = makeSomeFunctions(args), in the view on:stuff="someFunctions.foo()", and methods: { 'someFunctions.foo': noop }`. It was just a thought to get svelte to stop yelling at me. But quite hacky. Maybe it is good to prevent me and everyone from doing this.

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