Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jun 30, 2022
1 parent 315ead7 commit 17e04f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
26 changes: 15 additions & 11 deletions packages/babel-generator/src/node/index.ts
Expand Up @@ -56,7 +56,7 @@ function expandAliases<R>(obj: NodeHandlers<R>) {
// into concrete types so that the 'find' call below can be as fast as possible.
const expandedParens = expandAliases(parens);
const expandedWhitespaceNodes = expandAliases(whitespace.nodes);
const expandedWhitespaceList = expandAliases(whitespace.list);
//const expandedWhitespaceList = expandAliases(whitespace.list);

function find<R>(
obj: NodeHandlers<R>,
Expand Down Expand Up @@ -87,19 +87,23 @@ export function needsWhitespace(
node = node.expression;
}

if ((find(expandedWhitespaceNodes, node, parent) & type) !== 0) {
return true;
}
const flag = find(expandedWhitespaceNodes, node, parent);

const items = find(expandedWhitespaceList, node, parent);
if (items) {
for (let i = 0; i < items.length; i++) {
if (needsWhitespace(items[i], node, type)) {
return true;
}
}
if (typeof flag === "number") {
return (flag & type) !== 0;
}

// A bug that existed before, commenting out it will cause the test to fail.

// const items = find(expandedWhitespaceList, node, parent);
// if (items) {
// for (let i = 0; i < items.length; i++) {
// if (needsWhitespace(items[i], node, type)) {
// return true;
// }
// }
// }

return false;
}

Expand Down
11 changes: 0 additions & 11 deletions packages/babel-generator/src/node/whitespace.ts
Expand Up @@ -118,7 +118,6 @@ export const nodes: NodeHandlers<WhitespaceFlag> = {
? WhitespaceFlag.before | WhitespaceFlag.after
: WhitespaceFlag.after;
}
return 0;
},

/**
Expand All @@ -144,7 +143,6 @@ export const nodes: NodeHandlers<WhitespaceFlag> = {
if (isFunction(node.left) || isFunction(node.right)) {
return WhitespaceFlag.after;
}
return 0;
},

/**
Expand All @@ -155,7 +153,6 @@ export const nodes: NodeHandlers<WhitespaceFlag> = {
if (isStringLiteral(node) && node.value === "use strict") {
return WhitespaceFlag.after;
}
return 0;
},

/**
Expand All @@ -166,14 +163,12 @@ export const nodes: NodeHandlers<WhitespaceFlag> = {
if (isFunction(node.callee) || isHelper(node)) {
return WhitespaceFlag.before | WhitespaceFlag.after;
}
return 0;
},

OptionalCallExpression(node: t.OptionalCallExpression): WhitespaceFlag {
if (isFunction(node.callee)) {
return WhitespaceFlag.before | WhitespaceFlag.after;
}
return 0;
},

/**
Expand All @@ -194,7 +189,6 @@ export const nodes: NodeHandlers<WhitespaceFlag> = {
return WhitespaceFlag.before | WhitespaceFlag.after;
}
}
return 0;
},

/**
Expand All @@ -205,7 +199,6 @@ export const nodes: NodeHandlers<WhitespaceFlag> = {
if (isBlockStatement(node.consequent)) {
return WhitespaceFlag.before | WhitespaceFlag.after;
}
return 0;
},
};

Expand All @@ -223,7 +216,6 @@ nodes.ObjectProperty =
if (parent.properties[0] === node) {
return WhitespaceFlag.before;
}
return 0;
};

nodes.ObjectTypeCallProperty = function (
Expand All @@ -233,7 +225,6 @@ nodes.ObjectTypeCallProperty = function (
if (parent.callProperties[0] === node && !parent.properties?.length) {
return WhitespaceFlag.before;
}
return 0;
};

nodes.ObjectTypeIndexer = function (
Expand All @@ -247,7 +238,6 @@ nodes.ObjectTypeIndexer = function (
) {
return WhitespaceFlag.before;
}
return 0;
};

nodes.ObjectTypeInternalSlot = function (
Expand All @@ -262,7 +252,6 @@ nodes.ObjectTypeInternalSlot = function (
) {
return WhitespaceFlag.before;
}
return 0;
};

/**
Expand Down

0 comments on commit 17e04f9

Please sign in to comment.