swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.26k stars 1.23k forks source link

Incorrectly allowing parameter decorators in JavaScript when `decorators` parser option is set to true #9661

Open rwalle opened 1 month ago

rwalle commented 1 month ago

Describe the bug

Parameter decorator is part of TypeScript experimental decorator implementation, and is not in the tc39 decorator proposal that is at stage 3. While they could potentially be added in the future, they should not be allowed along with other "planned" decorator feature like class/method/function decorators.

Input code

class ExampleClass {
  method(@deprecated x = 3) {}
}

Config

No response

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.36&code=H4sIAAAAAAAAA0vOSSwuVnCtSMwtyEl1BnOquRQUclNLMvJTNBxSUguKUpMTS1JTFCoUbBWMNRWqa7lqAQKoNJE1AAAA&config=H4sIAAAAAAAAA42VwY4aMQyG7%2FsUaM490F2pqvoAvfUZopA4Q2gmHsUOC1rx7vUEhtLFM%2BoFMf5ix3Z%2BJx8vm013INf92HzIX%2FkYbSEo92%2Bx0DmzPYmlAzdYciWO3H2Z6YEmFGwiuNs8OCyWsZAgLhUauFx5x7b0wC0evW5ft7dYXUIk%2BDdWN8Qcw%2FkxG4fDWIDowSZWCVkHyEyfc2ms4PucyYN9h5jA5hViLJmYGXooWmCHKdmRwBxtUaJMmdoSCbUtJlgZvBkLjirPPnLELHs%2BUw%2FWG4ceFBQLOI5H0NxkL3HLJOUp9TTsYVf7vingkzccbaqWlT3h1I5EslWi7jESm1Cz1sIrXOjBFd6a%2B9kzBlOAa8nPfgeMeeFMfgNIB5IlynYALW5bEURPS95h1TPmIJLls8JF31qVGXppqokxKJ2dOgOFo3aaBXx1MHXWaenc8EL7KHowEIJoRQlN75HdXtuUzyNgUICcrw2aqq7A3KdwgU8DsYJ%2FSpWsC%2By2YrC8X6Z0HnaYVjYYgPfoVxbIUTAu4yK3xGlc5jV7EGmAV5dUauD5EpABYDSp3ZdP2pDxkIimT7hTr4lRdN4O8e1mu9yv6MHmvl0CD5co45jgCGlJ2%2F8xN6tUEj5OUp%2FH%2FWmk4bumVCvTGL9uZzSX8jL%2FtqK6AX19KKgJ9frGfOv%2BLpqfk7lRXaRfs2N7qC5%2FACIzE1gSBwAA

SWC Info output

No response

Expected behavior

An error will be emitted.

Actual behavior

An AST is generated using TypeScript experimental decorator behavior

Version

1.7.36

Additional context

No response