Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly update bindings of decorated class declarations
This commit adds a small utility (Scope#updateOwnBinding) which should be used whenever you replace a declaration with a new delaration which defines the same binding (e.g. `class Foo {}` -> `let Foo = class Foo {}`). Since our scope system isn't currently synchrinized with the AST, doing this automatically would add too much overhead to the `replaceWith*` functions. That function probably needs to be used in many more places, but we can add them when users find bugs related to non-updated bingins.
- Loading branch information
1 parent
d45ea2e
commit c4dec1c
Showing
5 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/input.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {autobind} from 'core-decorators'; | ||
|
||
export default function wrap() { | ||
return function() { | ||
class Foo { | ||
@autobind | ||
method() {} | ||
} | ||
|
||
return Foo; | ||
}; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"plugins": [ | ||
["proposal-decorators", { "legacy": true }] | ||
], | ||
"presets": [ | ||
["env", { | ||
"targets": { | ||
"node": 8 | ||
} | ||
}] | ||
] | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/babel-plugin-proposal-decorators/test/fixtures/legacy-regression/8559/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = wrap; | ||
|
||
var _coreDecorators = require("core-decorators"); | ||
|
||
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 && 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 wrap() { | ||
return function () { | ||
var _class; | ||
|
||
let Foo = (_class = class Foo { | ||
method() {} | ||
|
||
}, (_applyDecoratedDescriptor(_class.prototype, "method", [_coreDecorators.autobind], Object.getOwnPropertyDescriptor(_class.prototype, "method"), _class.prototype)), _class); | ||
return Foo; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters