Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: register inserted class declaration #10302

Merged
merged 2 commits into from Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -237,15 +237,18 @@ export default {

const replacement = decoratedClassToExpression(decl);
if (replacement) {
path.replaceWithMultiple([
replacement,
path.replaceWith(replacement);
path.insertAfter(
thiagoarrais marked this conversation as resolved.
Show resolved Hide resolved
t.exportNamedDeclaration(null, [
t.exportSpecifier(
t.cloneNode(replacement.declarations[0].id),
t.identifier("default"),
),
]),
]);
);
if (!decl.node.id) {
path.scope.registerDeclaration(path.get("declarations.0"));
}
}
},
ClassDeclaration(path) {
Expand Down
@@ -1,7 +1,7 @@
var _class, _class2;

let A = dec(_class2 = class A {}) || _class2;
let A = dec(_class = class A {}) || _class;

export { A as default };

let B = dec(_class = class B {}) || _class;
let B = dec(_class2 = class B {}) || _class2;
Expand Up @@ -2,12 +2,12 @@ var _class, _class2;

function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(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.defineProperty(target, property, desc); desc = null; } return desc; }

let A = (_class2 = class A {
let A = (_class = class A {
thiagoarrais marked this conversation as resolved.
Show resolved Hide resolved
foo() {}

}, (_applyDecoratedDescriptor(_class2.prototype, "foo", [dec], Object.getOwnPropertyDescriptor(_class2.prototype, "foo"), _class2.prototype)), _class2);
}, (_applyDecoratedDescriptor(_class.prototype, "foo", [dec], Object.getOwnPropertyDescriptor(_class.prototype, "foo"), _class.prototype)), _class);
export { A as default };
let B = (_class = class B {
let B = (_class2 = class B {
foo() {}

}, (_applyDecoratedDescriptor(_class.prototype, "foo", [dec], Object.getOwnPropertyDescriptor(_class.prototype, "foo"), _class.prototype)), _class);
}, (_applyDecoratedDescriptor(_class2.prototype, "foo", [dec], Object.getOwnPropertyDescriptor(_class2.prototype, "foo"), _class2.prototype)), _class2);
@@ -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 };