fix: register inserted class declaration (#10302)

* Decorators legacy: register inserted declaration

For compatibility with the Typescript plugin

Fixes #10264

* Register declaration but also keep replaceWithMultiple
This commit is contained in:
Thiago Arrais 2019-08-08 02:14:23 -03:00 committed by Nicolò Ribaudo
parent 5fb4d84a33
commit ba2c0f7adf
4 changed files with 22 additions and 1 deletions

View File

@ -237,7 +237,7 @@ export default {
const replacement = decoratedClassToExpression(decl);
if (replacement) {
path.replaceWithMultiple([
const [varDeclPath] = path.replaceWithMultiple([
replacement,
t.exportNamedDeclaration(null, [
t.exportSpecifier(
@ -246,6 +246,10 @@ export default {
),
]),
]);
if (!decl.node.id) {
path.scope.registerDeclaration(varDeclPath);
}
}
},
ClassDeclaration(path) {

View File

@ -0,0 +1,4 @@
function myDecorator(decoratee) {}
@myDecorator
export default class {}

View File

@ -0,0 +1,6 @@
{
"plugins": [
"transform-typescript",
[ "proposal-decorators", { "legacy": true } ]
]
}

View File

@ -0,0 +1,7 @@
var _class2;
function myDecorator(decoratee) {}
let _class = myDecorator(_class2 = class {}) || _class2;
export { _class as default };