Skip to content

Preserve decorator ordering, remove restrictions on decorator-before-export in JavaScript files #52578

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

As per conclusions we arrived at in the January 2023 meeting

  1. we should allow decorators before and after export/export default, but not around both.
  2. our down-level emit and printing should preserve the ordering of where decorators are placed.
declare function decorator(...args: any[]): any;

// ✅ Works!
@decorator export class Foo {}

// ✅ Works!
export @decorator class Bar {}

// ❌ You have to pick *one or the other*.
@decorator export @decorator class Baz {}
declare function decorator(...args: any[]): any;

// ✅ Works!
@decorator export default class Foo {}

// ✅ Works!
export default @decorator class default Bar {}

// ❌ Not in between.
export @decorator default class Baz {}

// ❌ Not around both.
@decorator export default @decorator class Biz {}

// ❌ DEFINITELY not interleaved.
@decorator export @decorator default @decorator class Wat {}

Activity

added
Domain: DecoratorsThe issue relates to the decorator syntax
ES NextNew featurers for ECMAScript (a.k.a. ESNext)
Domain: JavaScriptThe issue relates to JavaScript specifically
on Feb 2, 2023
changed the title [-]Remove restrictions on decorator-before-export in JavaScript files[/-] [+]Preserve decorator ordering, remove restrictions on decorator-before-export in JavaScript files[/+] on Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Domain: DecoratorsThe issue relates to the decorator syntaxDomain: JS EmitThe issue relates to the emission of JavaScriptDomain: JavaScriptThe issue relates to JavaScript specificallyES NextNew featurers for ECMAScript (a.k.a. ESNext)Fix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @DanielRosenwasser@rbuckton@typescript-bot

    Issue actions

      Preserve decorator ordering, remove restrictions on decorator-before-export in JavaScript files · Issue #52578 · microsoft/TypeScript