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

Proposal: Decorators #4626

Closed
stevefan1999-personal opened this issue Jul 30, 2017 · 3 comments
Closed

Proposal: Decorators #4626

stevefan1999-personal opened this issue Jul 30, 2017 · 3 comments

Comments

@stevefan1999-personal
Copy link

stevefan1999-personal commented Jul 30, 2017

babel/proposals#11

babel/proposals#13

Sample input:

decorateClass = klass -> klass.isDecorated = yes, klass

@decorateClass
class DecorateMe
  constructor: ->

console.log new DecorateMe().isDecorated // true

Expected output (Babel):

const decorateClass = klass => {
  klass.isDecorated = true
  return klass
}
@decorateClass
class DecorateMe {
  constructor() {
  }
}

console.log(new DecorateMe().isDecorated) // true

Current workaround: Apply the decorate as a high-order function like in ES5

decorateClass = klass -> klass.isDecorated = yes, klass

decorateClass class DecorateMe
  constructor: ->

console.log new DecorateMe().isDecorated // true

Or:

decorateClass = klass -> klass.isDecorated = yes, klass

class DecorateMe
  constructor: ->

DecorateMe = decorateClass DecorateMe

console.log new DecorateMe().isDecorated // true

You may find it difficult to understand, but please proof-read as much. I'm not English-native.

@GeoffreyBooth
Copy link
Collaborator

It is our policy to not support outputting any ES syntax that has yet to reach stage 4 (i.e. finalized). See http://coffeescript.org/v2/#contributing. We can support the feature, like we support object spread syntax, but the compiler’s output would need to use finalized ES syntax. What this means in practice is that if support for the feature is added, the CoffeeScript compiler’s output would generally be similar or identical to Babel’s output for that feature.

See related #4552.

@GeoffreyBooth GeoffreyBooth changed the title [CS2] Support decorator [CS2] Proposal: Decorators Jul 30, 2017
@GeoffreyBooth GeoffreyBooth changed the title [CS2] Proposal: Decorators Proposal: Decorators Sep 8, 2017
@unadlib
Copy link

unadlib commented Sep 16, 2017

const decorateClass = klass => {
klass.isDecorated = true
return klass
}
@decorateclass
class DecorateMe {
constructor() {
}
}
// use babel-plugin-transform-decorators-legacy
console.log(DecorateMe().isDecorated) //true
console.log(new DecorateMe().isDecorated)//undefined

@GeoffreyBooth
Copy link
Collaborator

Closing due to lack of interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants