Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions src/converters/discover-branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,6 @@ const computeArmRanges = (currentNode: Node): readonly AstArmRange[] => {
}));
}

if (
currentNode.type === 'MemberExpression' &&
astWalk.isOptionalChaining(currentNode)
) {
const objectNode = getChildNode(currentNode, 'object');
const propertyNode = getChildNode(currentNode, 'property');

if (objectNode === null || propertyNode === null) return [];
return [
{ armStart: objectNode.start, armEnd: objectNode.end },
{ armStart: propertyNode.start, armEnd: propertyNode.end },
];
}

if (
currentNode.type === 'CallExpression' &&
astWalk.isOptionalChaining(currentNode)
) {
const calleeNode = getChildNode(currentNode, 'callee');
if (calleeNode === null) return [];

return [
{ armStart: calleeNode.start, armEnd: calleeNode.end },
{ armStart: calleeNode.end, armEnd: currentNode.end },
];
}

return [];
};

Expand Down
9 changes: 1 addition & 8 deletions src/converters/shared/ast-walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ const isNodeLike = (candidate: unknown): candidate is Node => {
return typeof typed.type === 'string' && typeof typed.start === 'number';
};

const isOptionalChaining = (candidate: Node): boolean =>
(candidate.type === 'MemberExpression' ||
candidate.type === 'CallExpression') &&
Reflect.get(candidate, 'optional') === true;

const isBranchNode = (candidate: Node): boolean =>
candidate.type === 'LogicalExpression' ||
candidate.type === 'ConditionalExpression' ||
candidate.type === 'AssignmentPattern' ||
candidate.type === 'IfStatement' ||
candidate.type === 'SwitchStatement' ||
isOptionalChaining(candidate);
candidate.type === 'SwitchStatement';

const forEachNode = (root: Node, visitor: (current: Node) => void): void => {
const walkNode = (currentNode: Node): void => {
Expand Down Expand Up @@ -56,7 +50,6 @@ const forEachNode = (root: Node, visitor: (current: Node) => void): void => {

export const astWalk = {
isBranchNode,
isOptionalChaining,
isNodeLike,
forEachNode,
} as const;
31 changes: 0 additions & 31 deletions src/converters/shared/branch-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ const getChildren = (node: Node, property: string): Node[] => {
return value.filter(astWalk.isNodeLike);
};

const isOptionalChainMember = (node: Node): boolean =>
node.type === 'MemberExpression' && astWalk.isOptionalChaining(node);

const isOptionalChainCall = (node: Node): boolean =>
node.type === 'CallExpression' && astWalk.isOptionalChaining(node);

const describeBlock = (node: Node): BlockTemplate | null => {
if (node.type === 'IfStatement') {
const consequent = getChild(node, 'consequent');
Expand Down Expand Up @@ -140,31 +134,6 @@ const describeBlock = (node: Node): BlockTemplate | null => {
};
}

if (isOptionalChainMember(node)) {
const object = getChild(node, 'object');
const property = getChild(node, 'property');

if (object === null || property === null) return null;
return {
nodeStart: node.start,
nodeEnd: node.end,
expectedArms: [{ armStart: property.start, armEnd: property.end }],
inferMissingAsComplement: true,
};
}

if (isOptionalChainCall(node)) {
const callee = getChild(node, 'callee');
if (callee === null) return null;

return {
nodeStart: node.start,
nodeEnd: node.end,
expectedArms: [{ armStart: callee.end, armEnd: node.end }],
inferMissingAsComplement: true,
};
}

return null;
};

Expand Down
72 changes: 22 additions & 50 deletions test/__snapshots__/e2e/lcov/deno/darwin/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"pct": "96.48 %"
},
"branches": {
"total": 65,
"covered": 59,
"total": 61,
"covered": 55,
"missed": 6,
"pct": "90.77 %"
"pct": "90.16 %"
},
"functions": {
"total": 27,
Expand Down Expand Up @@ -112,8 +112,8 @@
"pct": "100.00 %"
},
"branches": {
"total": 50,
"covered": 50,
"total": 46,
"covered": 46,
"missed": 0,
"pct": "100.00 %"
},
Expand Down Expand Up @@ -392,14 +392,14 @@
"taken": 1
},
{
"line": 31,
"line": 32,
"block": 14,
"branch": 0,
"hit": 1,
"taken": 2
},
{
"line": 31,
"line": 32,
"block": 14,
"branch": 1,
"hit": 1,
Expand All @@ -410,137 +410,109 @@
"block": 15,
"branch": 0,
"hit": 1,
"taken": 2
},
{
"line": 32,
"block": 15,
"branch": 1,
"hit": 1,
"taken": 1
},
{
"line": 32,
"block": 16,
"branch": 0,
"hit": 1,
"taken": 1
},
{
"line": 32,
"block": 16,
"block": 15,
"branch": 1,
"hit": 1,
"taken": 2
},
{
"line": 33,
"block": 17,
"branch": 0,
"hit": 1,
"taken": 2
},
{
"line": 33,
"block": 17,
"branch": 1,
"hit": 1,
"taken": 1
},
{
"line": 38,
"block": 18,
"block": 16,
"branch": 0,
"hit": 1,
"taken": 2
},
{
"line": 38,
"block": 18,
"block": 16,
"branch": 1,
"hit": 1,
"taken": 1
},
{
"line": 38,
"block": 19,
"block": 17,
"branch": 0,
"hit": 1,
"taken": 1
},
{
"line": 38,
"block": 19,
"block": 17,
"branch": 1,
"hit": 1,
"taken": 2
},
{
"line": 42,
"block": 20,
"block": 18,
"branch": 0,
"hit": 1,
"taken": 1
},
{
"line": 42,
"block": 20,
"block": 18,
"branch": 1,
"hit": 1,
"taken": 1
},
{
"line": 47,
"block": 21,
"block": 19,
"branch": 0,
"hit": 1,
"taken": 1
},
{
"line": 47,
"block": 21,
"block": 19,
"branch": 1,
"hit": 1,
"taken": 1
},
{
"line": 52,
"block": 22,
"block": 20,
"branch": 0,
"hit": 1,
"taken": 2
},
{
"line": 52,
"block": 22,
"block": 20,
"branch": 1,
"hit": 1,
"taken": 1
},
{
"line": 57,
"block": 23,
"block": 21,
"branch": 0,
"hit": 1,
"taken": 1
},
{
"line": 57,
"block": 23,
"block": 21,
"branch": 1,
"hit": 1,
"taken": 1
},
{
"line": 65,
"block": 24,
"block": 22,
"branch": 0,
"hit": 1,
"taken": 1
},
{
"line": 65,
"block": 24,
"block": 22,
"branch": 1,
"hit": 1,
"taken": 1
Expand Down
Loading
Loading