Move abstract removal ClassDeclaration > Class. (#9693)
Usage of "@babel/plugin-proposal-decorators" with legacy support causes "abstract" keyword to be preserved. This fixes it by moving "abstract" node property removal from "ClassDeclaration" visitor to "Class". Resolves #8172
This commit is contained in:
parent
a35e5a314a
commit
efd2ca9040
@ -137,7 +137,6 @@ export default declare((api, { jsxPragma = "React" }) => {
|
|||||||
path.remove();
|
path.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node.abstract) node.abstract = null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
Class(path) {
|
Class(path) {
|
||||||
@ -146,6 +145,7 @@ export default declare((api, { jsxPragma = "React" }) => {
|
|||||||
if (node.typeParameters) node.typeParameters = null;
|
if (node.typeParameters) node.typeParameters = null;
|
||||||
if (node.superTypeParameters) node.superTypeParameters = null;
|
if (node.superTypeParameters) node.superTypeParameters = null;
|
||||||
if (node.implements) node.implements = null;
|
if (node.implements) node.implements = null;
|
||||||
|
if (node.abstract) node.abstract = null;
|
||||||
|
|
||||||
// Similar to the logic in `transform-flow-strip-types`, we need to
|
// Similar to the logic in `transform-flow-strip-types`, we need to
|
||||||
// handle `TSParameterProperty` and `ClassProperty` here because the
|
// handle `TSParameterProperty` and `ClassProperty` here because the
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
import { computed } from 'mobx';
|
||||||
|
|
||||||
|
abstract class Foo {
|
||||||
|
@computed get id() {}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"transform-typescript",
|
||||||
|
[
|
||||||
|
"proposal-decorators",
|
||||||
|
{
|
||||||
|
"legacy": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
var _class;
|
||||||
|
|
||||||
|
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; }
|
||||||
|
|
||||||
|
import { computed } from 'mobx';
|
||||||
|
let Foo = (_class = class Foo {
|
||||||
|
get id() {}
|
||||||
|
|
||||||
|
}, (_applyDecoratedDescriptor(_class.prototype, "id", [computed], Object.getOwnPropertyDescriptor(_class.prototype, "id"), _class.prototype)), _class);
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
import { observable } from 'mobx';
|
||||||
|
|
||||||
|
abstract class Foo {
|
||||||
|
@observable id = null;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"transform-typescript",
|
||||||
|
[
|
||||||
|
"proposal-decorators",
|
||||||
|
{
|
||||||
|
"legacy": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
var _class, _descriptor;
|
||||||
|
|
||||||
|
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 _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.'); }
|
||||||
|
|
||||||
|
import { observable } from 'mobx';
|
||||||
|
let Foo = (_class = class Foo {
|
||||||
|
id = _initializerWarningHelper(_descriptor, this);
|
||||||
|
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "id", [observable], {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: true,
|
||||||
|
writable: true,
|
||||||
|
initializer: function () {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})), _class);
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
import { observer } from 'mobx-react';
|
||||||
|
|
||||||
|
@observer
|
||||||
|
abstract class Foo {}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"transform-typescript",
|
||||||
|
[
|
||||||
|
"proposal-decorators",
|
||||||
|
{
|
||||||
|
"legacy": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
var _class;
|
||||||
|
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
|
||||||
|
let Foo = observer(_class = class Foo {}) || _class;
|
||||||
Loading…
x
Reference in New Issue
Block a user