Git Product home page Git Product logo

Comments (3)

osi-oswald avatar osi-oswald commented on June 12, 2024

Just figured, buildInitializerDefineProperty could be changed to this:

const buildInitializerDefineProperty = template(`
    function NAME(target, property, descriptor, context){
        if (!descriptor || !descriptor.initializer) return;
        context[property] = descriptor.initializer.call(context);
    }
`);

That way a setter defined on the prototype has a chance to react to the initialization assignment, whereas using Object.defineProperty will just skip the setter on the prototype :-/

from babel-plugin-transform-decorators-legacy.

osi-oswald avatar osi-oswald commented on June 12, 2024

If I take a closer look at babel-plugin-transform-class-properties, I can see it has an option spec, which by default is false. If option spec is false (default), an assignment is emitted. And only of if spec is true, it will use Object.defineProperty to initialize.

Therefore: The default should be what I proposed in my last comment. And if one would be fancy, either read somehow the spec option from transform-class-properties or provide an own spec option to still emit Object.defineProperty for initialization.

from babel-plugin-transform-decorators-legacy.

loganfsmyth avatar loganfsmyth commented on June 12, 2024

spec exists because it is what the spec dictates, and it will default to true in future versions of Babel. The goal of this plugin is to mimic the behavior of decorators as they were implemented in Babel 5. I'm not looking to add enhancements like this.

What you want should be doable in future versions of the decorators spec, but implementing that is beyond the scope of this plugin. Until then, maybe you can get what you want by defining it as @syncFromFoo instead?

from babel-plugin-transform-decorators-legacy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.