Remove use of constructor binding
MODIFY
packages/@romejs/js-analysis/evaluators/classes/ClassExpression.ts
packages/@romejs/js-analysis/evaluators/classes/ClassExpression.ts
@@ -40,13 +40,13 @@ export default function ClassExpression(node: AnyNode, scope: Scope) {
bodyScope.evaluate(node.meta.typeParameters);
}
- let constructor: undefined | T = undefined;
+ let _constructor: undefined | T = undefined;
for (const bodyNode of node.meta.body) {
const type = bodyScope.evaluate(bodyNode);
if (bodyNode.type === 'ClassMethod' && bodyNode.kind === 'constructor') {
- constructor = type;
+ _constructor = type;
} else {
if (
bodyNode.type !== 'TSIndexSignature' &&
@@ -62,7 +62,7 @@ export default function ClassExpression(node: AnyNode, scope: Scope) {
//
const classOrigin = node.id ? node.id : node;
let type = new ClassT(scope, classOrigin, {
- constructor,
+ _constructor,
instances,
statics,
extends: node.meta.superClass

MODIFY
packages/@romejs/js-analysis/evaluators/flow/FlowDeclareClass.ts
packages/@romejs/js-analysis/evaluators/flow/FlowDeclareClass.ts
@@ -40,7 +40,7 @@ export default function FlowDeclareClass(node: AnyNode, scope: Scope) {
}
const type = new ClassT(bodyScope, node.id, {
- constructor: undefined,
+ _constructor: undefined,
instances,
statics,
extends: xtends,

MODIFY
packages/@romejs/js-analysis/types/ClassT.ts
packages/@romejs/js-analysis/types/ClassT.ts
@@ -21,7 +21,7 @@ export default class ClassT extends ObjT {
scope: Scope,
originNode: undefined | AnyNode,
opts: {
- constructor: undefined | T;
+ _constructor: undefined | T;
statics: Array<T>;
instances: Array<T>;
extends?: T;
@@ -68,7 +68,7 @@ export default class ClassT extends ObjT {
constructorOpen.shouldMatch(this);
- this._constructor = opts.constructor;
+ this._constructor = opts._constructor;
this._statics = opts.statics;
this._instances = opts.instances;
this._extends = opts.extends;
@@ -100,7 +100,7 @@ export default class ClassT extends ObjT {
getType: HydrateTypeFactory,
): T {
return new ClassT(scope, originNode, {
- constructor:
+ _constructor:
data.constructor === undefined ? undefined : getType(data.constructor),
statics: Array(data.statics).map(id => getType(id)),
instances: Array(data.instances).map(id => getType(id)),

MODIFY
packages/@romejs/js-compiler/transforms/compile/transpile/classProperties.ts
packages/@romejs/js-compiler/transforms/compile/transpile/classProperties.ts
@@ -80,11 +80,11 @@ function transformClass(
const className: string =
node.id === undefined ? scope.generateUid('class') : node.id.name;
- let constructor: undefined | ClassMethod = undefined;
+ let _constructor: undefined | ClassMethod = undefined;
const filteredClassBody = [];
for (const bodyNode of node.meta.body) {
if (bodyNode.type === 'ClassMethod' && bodyNode.kind === 'constructor') {
- constructor = bodyNode;
+ _constructor = bodyNode;
continue;
}
@@ -121,11 +121,11 @@ function transformClass(
if (constructorAssignments.length) {
if (node.meta.superClass !== undefined) {
- if (constructor) {
+ if (_constructor) {
const visited = new Set();
// find super() and insert assignments
- const reducedConstructor = context.reduce(constructor, [
+ const reducedConstructor = context.reduce(_constructor, [
{
name: 'classPropertiesInjector',
enter(path) {
@@ -163,30 +163,30 @@ function transformClass(
},
},
]);
- constructor = classMethod.assert(reducedConstructor);
+ _constructor = classMethod.assert(reducedConstructor);
} else {
// create new constructor with a super() call and assignments
- constructor = createConstructor(bindingIdentifier.quick('args'), [
+ _constructor = createConstructor(bindingIdentifier.quick('args'), [
template.statement`super(...args);`,
...toExpressionStatements(constructorAssignments),
]);
}
} else {
- if (constructor) {
+ if (_constructor) {
// add assignments to end of constructor
- constructor = {
- ...constructor,
+ _constructor = {
+ ..._constructor,
body: {
- ...constructor.body,
+ ..._constructor.body,
body: [
...toExpressionStatements(constructorAssignments),
- ...constructor.body.body,
+ ..._constructor.body.body,
],
},
};
} else {
// create new constructor with just the assignments
- constructor = createConstructor(
+ _constructor = createConstructor(
undefined,
toExpressionStatements(constructorAssignments),
);
@@ -194,8 +194,8 @@ function transformClass(
}
}
- if (constructor !== undefined) {
- filteredClassBody.unshift(constructor);
+ if (_constructor !== undefined) {
+ filteredClassBody.unshift(_constructor);
}
const newClass: ClassDeclaration = {

MODIFY
packages/@romejs/js-compiler/transforms/compile/transpile/classes.ts
packages/@romejs/js-compiler/transforms/compile/transpile/classes.ts
@@ -39,7 +39,7 @@ function transformClass(
path: Path,
context: Context,
): {
- constructor: FunctionDeclaration;
+ _constructor: FunctionDeclaration;
prependDeclarations: Array<AnyStatement>;
declarations: Array<AnyStatement>;
} {
@@ -257,26 +257,26 @@ function transformClass(
}
// create the constructor method
- let constructor: FunctionDeclaration;
+ let _constructor: FunctionDeclaration;
if (constructorMethod === undefined) {
if (superClassRef === undefined) {
- constructor = functionDeclaration.assert(
+ _constructor = functionDeclaration.assert(
template.statement`function ${className}() {}`,
);
} else {
- constructor = functionDeclaration.assert(
+ _constructor = functionDeclaration.assert(
template.statement`function ${className}(...args) {${superClassRef}.apply(this, args);}`,
);
}
} else {
- constructor = functionDeclaration.create({
+ _constructor = functionDeclaration.create({
id: bindingIdentifier.quick(className),
head: constructorMethod.head,
body: constructorMethod.body,
});
}
- return {constructor, prependDeclarations, declarations};
+ return {_constructor, prependDeclarations, declarations};
}
export default {
@@ -291,7 +291,7 @@ export default {
node.declaration !== undefined &&
node.declaration.type === 'ClassDeclaration'
) {
- const {constructor, declarations, prependDeclarations} = transformClass(
+ const {_constructor, declarations, prependDeclarations} = transformClass(
node.declaration,
path.getChildPath('declaration'),
context,
@@ -300,7 +300,7 @@ export default {
...prependDeclarations,
{
...node,
- declaration: constructor,
+ declaration: _constructor,
},
...declarations,
];
@@ -308,12 +308,12 @@ export default {
}
if (node.type === 'ClassDeclaration') {
- const {constructor, prependDeclarations, declarations} = transformClass(
+ const {_constructor, prependDeclarations, declarations} = transformClass(
node,
path,
context,
);
- return [...prependDeclarations, constructor, ...declarations];
+ return [...prependDeclarations, _constructor, ...declarations];
}
// turn a class expression into an IIFE that returns a class declaration

Remove use of constructor binding