Skip to content

Commit

Permalink
fix: register inserted class declaration (#10302)
Browse files Browse the repository at this point in the history
* Decorators legacy: register inserted declaration

For compatibility with the Typescript plugin

Fixes #10264

* Register declaration but also keep replaceWithMultiple
  • Loading branch information
thiagoarrais authored and nicolo-ribaudo committed Aug 8, 2019
1 parent 5fb4d84 commit ba2c0f7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Expand Up @@ -237,7 +237,7 @@ export default {

const replacement = decoratedClassToExpression(decl);
if (replacement) {
path.replaceWithMultiple([
const [varDeclPath] = path.replaceWithMultiple([
replacement,
t.exportNamedDeclaration(null, [
t.exportSpecifier(
Expand All @@ -246,6 +246,10 @@ export default {
),
]),
]);

if (!decl.node.id) {
path.scope.registerDeclaration(varDeclPath);
}
}
},
ClassDeclaration(path) {
Expand Down
@@ -0,0 +1,4 @@
function myDecorator(decoratee) {}

@myDecorator
export default class {}
@@ -0,0 +1,6 @@
{
"plugins": [
"transform-typescript",
[ "proposal-decorators", { "legacy": true } ]
]
}
@@ -0,0 +1,7 @@
var _class2;

function myDecorator(decoratee) {}

let _class = myDecorator(_class2 = class {}) || _class2;

export { _class as default };

0 comments on commit ba2c0f7

Please sign in to comment.