Skip to content

Commit

Permalink
WIP 3
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Dec 4, 2023
1 parent f871333 commit 7a69f0a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/instrument/visitors/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const {
createThisBinding, createArgumentsBinding, createNewTargetBinding
} = require('../blocks.js'),
{insertTrackerCodeIntoFunction} = require('../tracking.js'),
{visitKey, visitKeyContainer} = require('../visit.js'),
{visitKey, visitKeyMaybe, visitKeyContainer} = require('../visit.js'),
{createTempVarNode} = require('../internalVars.js'),
{FN_TYPE_CLASS} = require('../../shared/constants.js');

Expand Down Expand Up @@ -111,8 +111,7 @@ function visitClass(classNode, parent, key, className, state) {
state.isStrict = true;

// Visit `extends` clause
const hasSuperClass = !!classNode.superClass;
if (hasSuperClass) {
if (classNode.superClass) {
fn.hasSuperClass = true;
visitKey(classNode, 'superClass', Expression, state);
}
Expand Down Expand Up @@ -208,14 +207,13 @@ function visitClass(classNode, parent, key, className, state) {
createNewTargetBinding(protoThisBlock);
state.currentThisBlock = protoThisBlock;

// If class does not extend a super class, prototype properties will be evaluated
// before class constructor, so tracker needs to go in 1st proto property which has a value
for (const index of protoPropertyIndexes) {
const propNode = memberNodes[index];
if (!propNode.value) continue;
visitKey(memberNodes, index, ClassPropertyMaybePrivate, state);
if (!hasSuperClass && !propForTrackerNode) propForTrackerNode = propNode;
}

// If class does not extend a super class, prototype properties will be evaluated
// before class constructor, so tracker needs to go in 1st proto property
if (!classNode.superClass) propForTrackerNode = memberNodes[protoPropertyIndexes[0]];
}

// Exit function
Expand Down Expand Up @@ -355,7 +353,7 @@ function ClassMethodMaybePrivate(node, state, parent, key) {
function ClassStaticPropertyOrBlock(node, state) {
if (node.type === 'StaticBlock') {
StaticBlock(node, state);
} else if (node.value) {
} else {
ClassPropertyMaybePrivate(node, state);
}
}
Expand All @@ -369,7 +367,7 @@ function ClassStaticPropertyOrBlock(node, state) {
*/
function ClassPropertyMaybePrivate(node, state) {
// Don't visit `key` as has been dealt with separately above
visitKey(node, 'value', Expression, state);
visitKeyMaybe(node, 'value', Expression, state);
}

/**
Expand Down Expand Up @@ -439,7 +437,9 @@ function instrumentClass(

if (propForTrackerNode) {
// Insert tracker into property
propForTrackerNode.value = t.sequenceExpression([trackerNode, propForTrackerNode.value]);
propForTrackerNode.value = propForTrackerNode.value
? t.sequenceExpression([trackerNode, propForTrackerNode.value])
: t.unaryExpression('void', trackerNode);
trackerNode = undefined;
} else if (!constructorNode) {
// Class has no constructor - create one for tracker code to be inserted in
Expand Down

0 comments on commit 7a69f0a

Please sign in to comment.