Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot name a decorator flags lib linter or onEmit (special exports) #3719

Closed
timotheeguerin opened this issue Jul 1, 2024 · 3 comments · Fixed by #4139
Closed

Cannot name a decorator flags lib linter or onEmit (special exports) #3719

timotheeguerin opened this issue Jul 1, 2024 · 3 comments · Fixed by #4139
Assignees
Labels
bug Something isn't working compiler:core Issues for @typespec/compiler design:accepted Proposal for design has been discussed and accepted. triaged:core

Comments

@timotheeguerin
Copy link
Member

timotheeguerin commented Jul 1, 2024

Problem

Cannot name a decorator flags lib linter or onEmit (special exports)
Due to how to use certain reserved name in JS we cannot name a decorator with those names

Add a new $decorators export

export const $decorators = {
  Azure.Core: {
    flags: $flags,
    "foo-bar": fooBarDecorator
  }
}

we can additionally provide a typed helper

function defineDecorators(decorators: Record<string, Record<string, DecoratorFunction>>) {
   return decorators;
}
export const $decorators = defineDecorators({
  Azure.Core: {
    flags: $flags,
    "foo-bar": fooBarDecorator
  }
})

Additional items

  • Update docs to recommend this approach
  • Update tspd to only support this new approach. This isn't breaking as tspd is not published yet.
@timotheeguerin timotheeguerin added the bug Something isn't working label Jul 1, 2024
@timotheeguerin timotheeguerin changed the title Cannot name a decorator flags lib or onEmit (special exports) Cannot name a decorator flags lib linter or onEmit (special exports) Jul 1, 2024
@timotheeguerin timotheeguerin added the design:needed A design request has been raised that needs a proposal label Jul 1, 2024
@timotheeguerin
Copy link
Member Author

timotheeguerin commented Jul 1, 2024

Option 1: USe $$ for known configs

This would reserve $ for decorators. For back compat we would still check if the $ variant of $lib, $flags, etc. is a config object and use that instead.

Issues with this approach:

  1. Still cannot exports reserved js names or non js identifiers that could technically be valid decorator names(e.g. foo-bar)
  2. Subset of above How do I name a decorator @$flags

Option 2: Dedicated $decorators export

this allows to exports all decorators

export const $decorators = {
  flags: $flags,
  "foo-bar": fooBarDecorator
}

this could even solve the confusing way namespace are defined in JS

export const $decorators = {
  Azure.Core: {
    flags: $flags,
    "foo-bar": fooBarDecorator
  }
}

@markcowl markcowl added this to the [2024] August milestone Jul 15, 2024
@markcowl markcowl added triaged:core compiler:core Issues for @typespec/compiler and removed needs-area labels Jul 15, 2024
@timotheeguerin timotheeguerin added design:accepted Proposal for design has been discussed and accepted. and removed design:needed A design request has been raised that needs a proposal labels Jul 17, 2024
@markcowl markcowl removed this from the [2024] August milestone Jul 19, 2024
@markcowl
Copy link
Contributor

  • Need to triage for scheduled changes

@markcowl
Copy link
Contributor

est: 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler:core Issues for @typespec/compiler design:accepted Proposal for design has been discussed and accepted. triaged:core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants