Skip to content

Commit

Permalink
refactor isFile to canPrint in operator node
Browse files Browse the repository at this point in the history
  • Loading branch information
Angry-Potato committed Jul 19, 2019
1 parent 18b9b52 commit 4f28afa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ const nodes = {
[NODE_TYPES.FUNCTION_CALL]: require(`./nodes/${NODE_TYPES.FUNCTION_CALL}`)
};

const isOperator = node => node.token;

const isFunctionCall = node => node.expr && node.typeArgs && node.args;

const assignType = node => {
Expand Down Expand Up @@ -77,7 +75,7 @@ const assignType = node => {
return { ...node, astType: NODE_TYPES.TYPE };
} else if (nodes[NODE_TYPES.INTEGER].canPrint(node)) {
return { ...node, astType: NODE_TYPES.INTEGER };
} else if (isOperator(node)) {
} else if (nodes[NODE_TYPES.OPERATOR].canPrint(node)) {
return { ...node, astType: NODE_TYPES.OPERATOR };
} else if (isFunctionCall(node)) {
return { ...node, astType: NODE_TYPES.FUNCTION_CALL };
Expand Down
21 changes: 12 additions & 9 deletions src/nodes/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ const {
}
} = require("prettier");

module.exports = (path, opts, print) => {
const node = path.getValue();
switch (node.token.toLowerCase()) {
case "eq":
return " == ";
case "dot":
return ".";
default:
throw new Error(`UNKNOWN_OPERATOR = ${node.token.toLowerCase()}`);
module.exports = {
canPrint: node => node.token,
print: (path, opts, print) => {
const node = path.getValue();
switch (node.token.toLowerCase()) {
case "eq":
return " == ";
case "dot":
return ".";
default:
throw new Error(`UNKNOWN_OPERATOR = ${node.token.toLowerCase()}`);
}
}
};

0 comments on commit 4f28afa

Please sign in to comment.