<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong><br>
I have this legacy parameter decorator</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function logProperty(target: any, property: string) {
  var _val = this[property];
 
  var getter = function () {
    console.log(`Get: ${property} =&gt; ${_val}`);
    return _val;
  };
 
  var setter = function (newVal) {
    console.log(`Set: ${property} =&gt; ${newVal}`);
    _val = newVal;
  };
 
  if (delete this[property]) {
    Object.defineProperty(target, property, {
      get: getter,
      set: setter,
      enumerable: true,
      configurable: true
    });
  }
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">logProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span>: <span class="pl-smi">any</span><span class="pl-kos">,</span> <span class="pl-s1">property</span>: <span class="pl-smi">string</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">_val</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">[</span><span class="pl-s1">property</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
 
  <span class="pl-k">var</span> <span class="pl-en">getter</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`Get: <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">property</span><span class="pl-kos">}</span></span> =&gt; <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">_val</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-s1">_val</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">;</span>
 
  <span class="pl-k">var</span> <span class="pl-en">setter</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">newVal</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`Set: <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">property</span><span class="pl-kos">}</span></span> =&gt; <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">newVal</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-s1">_val</span> <span class="pl-c1">=</span> <span class="pl-s1">newVal</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">;</span>
 
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-k">delete</span> <span class="pl-smi">this</span><span class="pl-kos">[</span><span class="pl-s1">property</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
      <span class="pl-c1">get</span>: <span class="pl-s1">getter</span><span class="pl-kos">,</span>
      <span class="pl-c1">set</span>: <span class="pl-s1">setter</span><span class="pl-kos">,</span>
      <span class="pl-c1">enumerable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
      <span class="pl-c1">configurable</span>: <span class="pl-c1">true</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">depending on how I initialise a decorated property inside a class, it can be defined or undefined:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// Case 1
class Foo {
  @logProperty public myProp: string = 'foo';
}

console.log((new Foo()).myProp)); // =&gt; undefined"><pre class="notranslate"><span class="pl-c">// Case 1</span>
<span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
  @<span class="pl-s1">logProperty</span> <span class="pl-k">public</span> <span class="pl-c1">myProp</span>: <span class="pl-smi">string</span> <span class="pl-c1">=</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">myProp</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// =&gt; undefined</span></pre></div>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// Case 2
class Foo {
  @logProperty public myProp: string;

  constructor() {
    this.myProp = 'foo';
  }
}

console.log((new Foo()).myProp)); // =&gt; 'foo'"><pre class="notranslate"><span class="pl-c">// Case 2</span>
<span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
  @<span class="pl-s1">logProperty</span> <span class="pl-k">public</span> <span class="pl-c1">myProp</span>: <span class="pl-smi">string</span><span class="pl-kos">;</span>

  <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">myProp</span> <span class="pl-c1">=</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">myProp</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// =&gt; 'foo'</span></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong><br>
The <code class="notranslate">console.log</code> outputs of both test cases should be defined. In my case both should be <code class="notranslate">'foo'</code>.</p>
<p dir="auto"><strong>Babel Configuration (.babelrc, package.json, cli command)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;presets&quot;: [
    &quot;@babel/env&quot;,
    &quot;@babel/preset-typescript&quot;
  ],
  &quot;plugins&quot;: [
    [&quot;@babel/plugin-proposal-decorators&quot;, { &quot;legacy&quot;: true }],
    [&quot;@babel/plugin-proposal-class-properties&quot;, { &quot;loose&quot; : true }]
  ]
}
"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-s">"presets"</span>: <span class="pl-kos">[</span>
    <span class="pl-s">"@babel/env"</span><span class="pl-kos">,</span>
    <span class="pl-s">"@babel/preset-typescript"</span>
  <span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-s">"plugins"</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">"@babel/plugin-proposal-decorators"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-s">"legacy"</span>: <span class="pl-c1">true</span> <span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
    <span class="pl-kos">[</span><span class="pl-s">"@babel/plugin-proposal-class-properties"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-s">"loose"</span> : <span class="pl-c1">true</span> <span class="pl-kos">}</span><span class="pl-kos">]</span>
  <span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version: 7.1.2</li>
<li>Node/npm version: Node 10.12.0/npm 6.4.1</li>
<li>OS: OSX 10.14</li>
<li>Monorepo no</li>
<li>How you are using Babel: tried with cli and loader</li>
</ul>
<p dir="auto"><strong>Possible Solution</strong><br>
I have no solution, but here are the compiled version of both test cases.<br>
One has a class property, the other one defines the initial value in the initializer. Maybe that causes the issue.</p>
<details>
<summary>Compiled code: Testcase 1</summary>
<p dir="auto">
</p><div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

var _class, _descriptor;

function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(&quot;Cannot call a class as a function&quot;); } }

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object['ke' + 'ys'](descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context &amp;&amp; desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object['define' + 'Property'](target, property, desc); desc = null; } return desc; }

function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and set to use loose mode. ' + 'To use proposal-class-properties in spec mode with decorators, wait for ' + 'the next major version of decorators in stage 2.'); }

function logProperty(target, property) {
  var _val = this[property];

  var getter = function getter() {
    console.log(&quot;Get: &quot;.concat(property, &quot; =&gt; &quot;).concat(_val));
    return _val;
  };

  var setter = function setter(newVal) {
    console.log(&quot;Set: &quot;.concat(property, &quot; =&gt; &quot;).concat(newVal));
    _val = newVal;
  };

  if (delete this[property]) {
    Object.defineProperty(target, property, {
      get: getter,
      set: setter,
      enumerable: true,
      configurable: true
    });
  }
}

var Foo = (_class = function Foo() {
  _classCallCheck(this, Foo);

  _initializerDefineProperty(this, &quot;myProp&quot;, _descriptor, this);
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, &quot;myProp&quot;, [logProperty], {
  configurable: true,
  enumerable: true,
  writable: true,
  initializer: function initializer() {
    return 'foo';
  }
})), _class);
console.log(new Foo().myProp);"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-k">var</span> <span class="pl-s1">_class</span><span class="pl-kos">,</span> <span class="pl-s1">_descriptor</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">_initializerDefineProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s1">descriptor</span><span class="pl-kos">,</span> <span class="pl-s1">context</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">descriptor</span><span class="pl-kos">)</span> <span class="pl-k">return</span><span class="pl-kos">;</span> <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">enumerable</span>: <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">enumerable</span><span class="pl-kos">,</span> <span class="pl-c1">configurable</span>: <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">configurable</span><span class="pl-kos">,</span> <span class="pl-c1">writable</span>: <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">writable</span><span class="pl-kos">,</span> <span class="pl-c1">value</span>: <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> ? <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">context</span><span class="pl-kos">)</span> : <span class="pl-k">void</span> <span class="pl-c1">0</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">_classCallCheck</span><span class="pl-kos">(</span><span class="pl-s1">instance</span><span class="pl-kos">,</span> <span class="pl-v">Constructor</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-kos">(</span><span class="pl-s1">instance</span> <span class="pl-k">instanceof</span> <span class="pl-v">Constructor</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">TypeError</span><span class="pl-kos">(</span><span class="pl-s">"Cannot call a class as a function"</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> <span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">_applyDecoratedDescriptor</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s1">decorators</span><span class="pl-kos">,</span> <span class="pl-s1">descriptor</span><span class="pl-kos">,</span> <span class="pl-s1">context</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">var</span> <span class="pl-s1">desc</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">;</span> <span class="pl-v">Object</span><span class="pl-kos">[</span><span class="pl-s">'ke'</span> <span class="pl-c1">+</span> <span class="pl-s">'ys'</span><span class="pl-kos">]</span><span class="pl-kos">(</span><span class="pl-s1">descriptor</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">forEach</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">key</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-s1">desc</span><span class="pl-kos">[</span><span class="pl-s1">key</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">descriptor</span><span class="pl-kos">[</span><span class="pl-s1">key</span><span class="pl-kos">]</span><span class="pl-kos">;</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">enumerable</span> <span class="pl-c1">=</span> <span class="pl-c1">!</span><span class="pl-c1">!</span><span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">enumerable</span><span class="pl-kos">;</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">configurable</span> <span class="pl-c1">=</span> <span class="pl-c1">!</span><span class="pl-c1">!</span><span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">configurable</span><span class="pl-kos">;</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s">'value'</span> <span class="pl-k">in</span> <span class="pl-s1">desc</span> <span class="pl-c1">||</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">writable</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> <span class="pl-s1">desc</span> <span class="pl-c1">=</span> <span class="pl-s1">decorators</span><span class="pl-kos">.</span><span class="pl-en">slice</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">reverse</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">reduce</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">desc</span><span class="pl-kos">,</span> <span class="pl-s1">decorator</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">return</span> <span class="pl-s1">decorator</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s1">desc</span><span class="pl-kos">)</span> <span class="pl-c1">||</span> <span class="pl-s1">desc</span><span class="pl-kos">;</span> <span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-s1">desc</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">context</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> <span class="pl-c1">!==</span> <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">value</span> <span class="pl-c1">=</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> ? <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">context</span><span class="pl-kos">)</span> : <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> <span class="pl-c1">=</span> <span class="pl-c1">undefined</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> <span class="pl-c1">===</span> <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-v">Object</span><span class="pl-kos">[</span><span class="pl-s">'define'</span> <span class="pl-c1">+</span> <span class="pl-s">'Property'</span><span class="pl-kos">]</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s1">desc</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-s1">desc</span> <span class="pl-c1">=</span> <span class="pl-c1">null</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> <span class="pl-k">return</span> <span class="pl-s1">desc</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">_initializerWarningHelper</span><span class="pl-kos">(</span><span class="pl-s1">descriptor</span><span class="pl-kos">,</span> <span class="pl-s1">context</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s">'Decorating class property failed. Please ensure that '</span> <span class="pl-c1">+</span> <span class="pl-s">'proposal-class-properties is enabled and set to use loose mode. '</span> <span class="pl-c1">+</span> <span class="pl-s">'To use proposal-class-properties in spec mode with decorators, wait for '</span> <span class="pl-c1">+</span> <span class="pl-s">'the next major version of decorators in stage 2.'</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>

<span class="pl-k">function</span> <span class="pl-en">logProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">_val</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">[</span><span class="pl-s1">property</span><span class="pl-kos">]</span><span class="pl-kos">;</span>

  <span class="pl-k">var</span> <span class="pl-en">getter</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-en">getter</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"Get: "</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s">" =&gt; "</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">_val</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-s1">_val</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">;</span>

  <span class="pl-k">var</span> <span class="pl-en">setter</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-en">setter</span><span class="pl-kos">(</span><span class="pl-s1">newVal</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"Set: "</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s">" =&gt; "</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">newVal</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-s1">_val</span> <span class="pl-c1">=</span> <span class="pl-s1">newVal</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">;</span>

  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-k">delete</span> <span class="pl-smi">this</span><span class="pl-kos">[</span><span class="pl-s1">property</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
      <span class="pl-c1">get</span>: <span class="pl-en">getter</span><span class="pl-kos">,</span>
      <span class="pl-c1">set</span>: <span class="pl-en">setter</span><span class="pl-kos">,</span>
      <span class="pl-c1">enumerable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
      <span class="pl-c1">configurable</span>: <span class="pl-c1">true</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">var</span> <span class="pl-v">Foo</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">_class</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-v">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-en">_classCallCheck</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">,</span> <span class="pl-v">Foo</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

  <span class="pl-en">_initializerDefineProperty</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">,</span> <span class="pl-s">"myProp"</span><span class="pl-kos">,</span> <span class="pl-s1">_descriptor</span><span class="pl-kos">,</span> <span class="pl-smi">this</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">_descriptor</span> <span class="pl-c1">=</span> <span class="pl-en">_applyDecoratedDescriptor</span><span class="pl-kos">(</span><span class="pl-s1">_class</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"myProp"</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-s1">logProperty</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">configurable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
  <span class="pl-c1">enumerable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
  <span class="pl-c1">writable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
  <span class="pl-en">initializer</span>: <span class="pl-k">function</span> <span class="pl-en">initializer</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-s1">_class</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-v">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">myProp</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"></p>
</details>
<details>
<summary>Compiled code: Testcase 2</summary>
<p dir="auto">
</p><div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=" &quot;use strict&quot;;
 
 var _class, _descriptor;
 
 function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
 
 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(&quot;Cannot call a class as a function&quot;); } }
 
 function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object['ke' + 'ys'](descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context &amp;&amp; desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object['define' + 'Property'](target, property, desc); desc = null; } return desc; }
 
 function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and set to use loose mode. ' + 'To use proposal-class-properties in spec mode with decorators, wait for ' + 'the next major version of decorators in stage 2.'); }
 
 function logProperty(target, property) {
   var _val = this[property];
 
   var getter = function getter() {
     console.log(&quot;Get: &quot;.concat(property, &quot; =&gt; &quot;).concat(_val));
     return _val;
   };
 
   var setter = function setter(newVal) {
     console.log(&quot;Set: &quot;.concat(property, &quot; =&gt; &quot;).concat(newVal));
     _val = newVal;
   };
 
   if (delete this[property]) {
     Object.defineProperty(target, property, {
       get: getter,
       set: setter,
       enumerable: true,
       configurable: true
     });
   }
 }
 
 var Foo = (_class = function Foo() {
   _classCallCheck(this, Foo);
 
   _initializerDefineProperty(this, &quot;myProp&quot;, _descriptor, this);
 
   this.myProp = 'foo';
 }, (_descriptor = _applyDecoratedDescriptor(_class.prototype, &quot;myProp&quot;, [logProperty], {
   configurable: true,
   enumerable: true,
   writable: true,
   initializer: null
 })), _class);
 console.log(new Foo().myProp); "><pre class="notranslate"> <span class="pl-s">"use strict"</span><span class="pl-kos">;</span>
 
 <span class="pl-k">var</span> <span class="pl-s1">_class</span><span class="pl-kos">,</span> <span class="pl-s1">_descriptor</span><span class="pl-kos">;</span>
 
 <span class="pl-k">function</span> <span class="pl-en">_initializerDefineProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s1">descriptor</span><span class="pl-kos">,</span> <span class="pl-s1">context</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">descriptor</span><span class="pl-kos">)</span> <span class="pl-k">return</span><span class="pl-kos">;</span> <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">enumerable</span>: <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">enumerable</span><span class="pl-kos">,</span> <span class="pl-c1">configurable</span>: <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">configurable</span><span class="pl-kos">,</span> <span class="pl-c1">writable</span>: <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">writable</span><span class="pl-kos">,</span> <span class="pl-c1">value</span>: <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> ? <span class="pl-s1">descriptor</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">context</span><span class="pl-kos">)</span> : <span class="pl-k">void</span> <span class="pl-c1">0</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>
 
 <span class="pl-k">function</span> <span class="pl-en">_classCallCheck</span><span class="pl-kos">(</span><span class="pl-s1">instance</span><span class="pl-kos">,</span> <span class="pl-v">Constructor</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-kos">(</span><span class="pl-s1">instance</span> <span class="pl-k">instanceof</span> <span class="pl-v">Constructor</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">TypeError</span><span class="pl-kos">(</span><span class="pl-s">"Cannot call a class as a function"</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> <span class="pl-kos">}</span>
 
 <span class="pl-k">function</span> <span class="pl-en">_applyDecoratedDescriptor</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s1">decorators</span><span class="pl-kos">,</span> <span class="pl-s1">descriptor</span><span class="pl-kos">,</span> <span class="pl-s1">context</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">var</span> <span class="pl-s1">desc</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">;</span> <span class="pl-v">Object</span><span class="pl-kos">[</span><span class="pl-s">'ke'</span> <span class="pl-c1">+</span> <span class="pl-s">'ys'</span><span class="pl-kos">]</span><span class="pl-kos">(</span><span class="pl-s1">descriptor</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">forEach</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">key</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-s1">desc</span><span class="pl-kos">[</span><span class="pl-s1">key</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">descriptor</span><span class="pl-kos">[</span><span class="pl-s1">key</span><span class="pl-kos">]</span><span class="pl-kos">;</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">enumerable</span> <span class="pl-c1">=</span> <span class="pl-c1">!</span><span class="pl-c1">!</span><span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">enumerable</span><span class="pl-kos">;</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">configurable</span> <span class="pl-c1">=</span> <span class="pl-c1">!</span><span class="pl-c1">!</span><span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">configurable</span><span class="pl-kos">;</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s">'value'</span> <span class="pl-k">in</span> <span class="pl-s1">desc</span> <span class="pl-c1">||</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">writable</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> <span class="pl-s1">desc</span> <span class="pl-c1">=</span> <span class="pl-s1">decorators</span><span class="pl-kos">.</span><span class="pl-en">slice</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">reverse</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">reduce</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">desc</span><span class="pl-kos">,</span> <span class="pl-s1">decorator</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">return</span> <span class="pl-s1">decorator</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s1">desc</span><span class="pl-kos">)</span> <span class="pl-c1">||</span> <span class="pl-s1">desc</span><span class="pl-kos">;</span> <span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-s1">desc</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">context</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> <span class="pl-c1">!==</span> <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">value</span> <span class="pl-c1">=</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> ? <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span><span class="pl-kos">.</span><span class="pl-en">call</span><span class="pl-kos">(</span><span class="pl-s1">context</span><span class="pl-kos">)</span> : <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> <span class="pl-c1">=</span> <span class="pl-c1">undefined</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">desc</span><span class="pl-kos">.</span><span class="pl-c1">initializer</span> <span class="pl-c1">===</span> <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-v">Object</span><span class="pl-kos">[</span><span class="pl-s">'define'</span> <span class="pl-c1">+</span> <span class="pl-s">'Property'</span><span class="pl-kos">]</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s1">desc</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-s1">desc</span> <span class="pl-c1">=</span> <span class="pl-c1">null</span><span class="pl-kos">;</span> <span class="pl-kos">}</span> <span class="pl-k">return</span> <span class="pl-s1">desc</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>
 
 <span class="pl-k">function</span> <span class="pl-en">_initializerWarningHelper</span><span class="pl-kos">(</span><span class="pl-s1">descriptor</span><span class="pl-kos">,</span> <span class="pl-s1">context</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-k">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s">'Decorating class property failed. Please ensure that '</span> <span class="pl-c1">+</span> <span class="pl-s">'proposal-class-properties is enabled and set to use loose mode. '</span> <span class="pl-c1">+</span> <span class="pl-s">'To use proposal-class-properties in spec mode with decorators, wait for '</span> <span class="pl-c1">+</span> <span class="pl-s">'the next major version of decorators in stage 2.'</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>
 
 <span class="pl-k">function</span> <span class="pl-en">logProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
   <span class="pl-k">var</span> <span class="pl-s1">_val</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">[</span><span class="pl-s1">property</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
 
   <span class="pl-k">var</span> <span class="pl-en">getter</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-en">getter</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
     <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"Get: "</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s">" =&gt; "</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">_val</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
     <span class="pl-k">return</span> <span class="pl-s1">_val</span><span class="pl-kos">;</span>
   <span class="pl-kos">}</span><span class="pl-kos">;</span>
 
   <span class="pl-k">var</span> <span class="pl-en">setter</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-en">setter</span><span class="pl-kos">(</span><span class="pl-s1">newVal</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
     <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"Set: "</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-s">" =&gt; "</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">concat</span><span class="pl-kos">(</span><span class="pl-s1">newVal</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
     <span class="pl-s1">_val</span> <span class="pl-c1">=</span> <span class="pl-s1">newVal</span><span class="pl-kos">;</span>
   <span class="pl-kos">}</span><span class="pl-kos">;</span>
 
   <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-k">delete</span> <span class="pl-smi">this</span><span class="pl-kos">[</span><span class="pl-s1">property</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
     <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">property</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
       <span class="pl-c1">get</span>: <span class="pl-en">getter</span><span class="pl-kos">,</span>
       <span class="pl-c1">set</span>: <span class="pl-en">setter</span><span class="pl-kos">,</span>
       <span class="pl-c1">enumerable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
       <span class="pl-c1">configurable</span>: <span class="pl-c1">true</span>
     <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
   <span class="pl-kos">}</span>
 <span class="pl-kos">}</span>
 
 <span class="pl-k">var</span> <span class="pl-v">Foo</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">_class</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-v">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
   <span class="pl-en">_classCallCheck</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">,</span> <span class="pl-v">Foo</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
 
   <span class="pl-en">_initializerDefineProperty</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">,</span> <span class="pl-s">"myProp"</span><span class="pl-kos">,</span> <span class="pl-s1">_descriptor</span><span class="pl-kos">,</span> <span class="pl-smi">this</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
 
   <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">myProp</span> <span class="pl-c1">=</span> <span class="pl-s">'foo'</span><span class="pl-kos">;</span>
 <span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-s1">_descriptor</span> <span class="pl-c1">=</span> <span class="pl-en">_applyDecoratedDescriptor</span><span class="pl-kos">(</span><span class="pl-s1">_class</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-s">"myProp"</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-s1">logProperty</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
   <span class="pl-c1">configurable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
   <span class="pl-c1">enumerable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
   <span class="pl-c1">writable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
   <span class="pl-c1">initializer</span>: <span class="pl-c1">null</span>
 <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-s1">_class</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
 <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-v">Foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">myProp</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </pre></div>
<p dir="auto"></p>
</details>
<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong><br>
Babel 7 emits code with broken property injection.</p>
<p dir="auto"><strong>Input Code</strong></p>
<ul dir="auto">
<li><a href="https://github.com/elderapo/babel-7-property-decorator-issue">Reproducible repo</a></li>
</ul>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const LogUpdate = () =&gt; {
  return (target: Object, key: string | symbol) =&gt; {
    let val = target[key];

    const getter = () =&gt; {
      return val;
    };

    const setter = next =&gt; {
      console.log(`Updating: ${val} =&gt; ${next}...`);
      val = next;
    };

    Object.defineProperty(target, key, {
      get: getter,
      set: setter,
      enumerable: true,
      configurable: true
    });
  };
};

class Something {
  @LogUpdate()
  public count: number = 0;
}

const something = new Something();
something.count++;
something.count = 123;
something.count = -1;"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-smi">LogUpdate</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-kos">(</span><span class="pl-s1">target</span>: <span class="pl-smi">Object</span><span class="pl-kos">,</span> <span class="pl-s1">key</span>: <span class="pl-smi">string</span> <span class="pl-c1">|</span> <span class="pl-smi">symbol</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-s1">val</span> <span class="pl-c1">=</span> <span class="pl-s1">target</span><span class="pl-kos">[</span><span class="pl-s1">key</span><span class="pl-kos">]</span><span class="pl-kos">;</span>

    <span class="pl-k">const</span> <span class="pl-en">getter</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-k">return</span> <span class="pl-s1">val</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">;</span>

    <span class="pl-k">const</span> <span class="pl-en">setter</span> <span class="pl-c1">=</span> <span class="pl-s1">next</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`Updating: <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">val</span><span class="pl-kos">}</span></span> =&gt; <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">next</span><span class="pl-kos">}</span></span>...`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
      <span class="pl-s1">val</span> <span class="pl-c1">=</span> <span class="pl-s1">next</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">;</span>

    <span class="pl-smi">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">target</span><span class="pl-kos">,</span> <span class="pl-s1">key</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
      <span class="pl-c1">get</span>: <span class="pl-s1">getter</span><span class="pl-kos">,</span>
      <span class="pl-c1">set</span>: <span class="pl-s1">setter</span><span class="pl-kos">,</span>
      <span class="pl-c1">enumerable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
      <span class="pl-c1">configurable</span>: <span class="pl-c1">true</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-k">class</span> <span class="pl-smi">Something</span> <span class="pl-kos">{</span>
  @<span class="pl-smi">LogUpdate</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
  <span class="pl-k">public</span> <span class="pl-c1">count</span>: <span class="pl-smi">number</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">const</span> <span class="pl-s1">something</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Something</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">something</span><span class="pl-kos">.</span><span class="pl-c1">count</span><span class="pl-c1">++</span><span class="pl-kos">;</span>
<span class="pl-s1">something</span><span class="pl-kos">.</span><span class="pl-c1">count</span> <span class="pl-c1">=</span> <span class="pl-c1">123</span><span class="pl-kos">;</span>
<span class="pl-s1">something</span><span class="pl-kos">.</span><span class="pl-c1">count</span> <span class="pl-c1">=</span> <span class="pl-c1">-</span><span class="pl-c1">1</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong><br>
Code compiled with babel doesn't trigger logger:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="elderapo@******:~/nodejs/babel-7-property-decorator-issue$ yarn babel-start
yarn run v1.13.0
$ yarn babel-build &amp;&amp; node ./compiled-with-babel/index.js
$ babel src --out-dir compiled-with-babel --extensions &quot;.ts,.tsx&quot; --source-maps inline
Successfully compiled 1 file with Babel.
Done in 0.70s."><pre class="notranslate">elderapo@<span class="pl-k">******</span>:<span class="pl-k">~</span>/nodejs/babel-7-property-decorator-issue$ yarn babel-start
yarn run v1.13.0
$ yarn babel-build <span class="pl-k">&amp;&amp;</span> node ./compiled-with-babel/index.js
$ babel src --out-dir compiled-with-babel --extensions <span class="pl-s"><span class="pl-pds">"</span>.ts,.tsx<span class="pl-pds">"</span></span> --source-maps inline
Successfully compiled 1 file with Babel.
Done <span class="pl-k">in</span> 0.70s.</pre></div>
<p dir="auto">On the other hand code compipled with <code class="notranslate">tsc</code> works just fine:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="elderapo@******:~/nodejs/babel-7-property-decorator-issue$ yarn ts-node-start
yarn run v1.13.0
$ ts-node ./src/index.ts
Updating: undefined =&gt; 0...
Updating: 0 =&gt; 1...
Updating: 1 =&gt; 123...
Updating: 123 =&gt; -1...
Done in 1.17s."><pre class="notranslate">elderapo@<span class="pl-k">******</span>:<span class="pl-k">~</span>/nodejs/babel-7-property-decorator-issue$ yarn ts-node-start
yarn run v1.13.0
$ ts-node ./src/index.ts
Updating: undefined =<span class="pl-k">&gt;</span> 0...
Updating: 0 =<span class="pl-k">&gt;</span> 1...
Updating: 1 =<span class="pl-k">&gt;</span> 123...
Updating: 123 =<span class="pl-k">&gt;</span> -1...
Done <span class="pl-k">in</span> 1.17s.</pre></div>
<p dir="auto"><strong>Babel Configuration (.babelrc, package.json, cli command)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;plugins&quot;: [
    [&quot;@babel/plugin-proposal-decorators&quot;, { &quot;legacy&quot;: true }],
    [&quot;@babel/plugin-proposal-class-properties&quot;, { &quot;loose&quot;: true }]
  ],
  &quot;presets&quot;: [&quot;@babel/env&quot;, &quot;@babel/preset-typescript&quot;]
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-s">"plugins"</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">"@babel/plugin-proposal-decorators"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-s">"legacy"</span>: <span class="pl-c1">true</span> <span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
    <span class="pl-kos">[</span><span class="pl-s">"@babel/plugin-proposal-class-properties"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-s">"loose"</span>: <span class="pl-c1">true</span> <span class="pl-kos">}</span><span class="pl-kos">]</span>
  <span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-s">"presets"</span>: <span class="pl-kos">[</span><span class="pl-s">"@babel/env"</span><span class="pl-kos">,</span> <span class="pl-s">"@babel/preset-typescript"</span><span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): 7.4.0</li>
<li>Node/npm version: doesn't matter</li>
<li>OS: doesn't matter</li>
<li>Monorepo: doesn't matter</li>
<li>How you are using Babel: doesn't matter</li>
</ul>
<p dir="auto"><strong>Possible Solution</strong></p>

<p dir="auto"><strong>Additional context/Screenshots</strong><br>
This example is pretty trivial but property decorators are often used in dependency injection. It's possible to use <a href="https://github.com/inversify/InversifyJS">https://github.com/inversify/InversifyJS</a> to get stuff injected into constructor but it's not always possible. One of the examples is react ecosystem where it's really hard to use constructor injection and property injection comes in handy.</p>