Skip to content

Commit

Permalink
refactor isFile to canPrint in parameter node
Browse files Browse the repository at this point in the history
  • Loading branch information
Angry-Potato committed Jul 19, 2019
1 parent a55cd32 commit 608f6ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 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 isParameter = node => node.mods && node.name && node.type;

const isModifier = node => node.keyword || node.anns;

const isAnnotation = node => node.names && node.typeArgs && node.args;
Expand Down Expand Up @@ -85,7 +83,7 @@ const assignType = node => {
return { ...node, astType: NODE_TYPES.CLASS_DECLARATION };
} else if (nodes[NODE_TYPES.PRIMARY_CONSTRUCTOR].canPrint(node)) {
return { ...node, astType: NODE_TYPES.PRIMARY_CONSTRUCTOR };
} else if (isParameter(node)) {
} else if (nodes[NODE_TYPES.PARAMETER].canPrint(node)) {
return { ...node, astType: NODE_TYPES.PARAMETER };
} else if (isModifier(node)) {
return { ...node, astType: NODE_TYPES.MODIFIER };
Expand Down
27 changes: 15 additions & 12 deletions src/nodes/parameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ const {
}
} = require("prettier");

module.exports = (path, opts, print) => {
const node = path.getValue();
const { mods, name } = node;
module.exports = {
canPrint: node => node.mods && node.name && node.type,
print: (path, opts, print) => {
const node = path.getValue();
const { mods, name } = node;

const type = node.type ? concat([": ", path.call(print, "type")]) : "";
const varType = node.hasOwnProperty("readOnly")
? node.readOnly
? "val "
: "var "
: "";
const type = node.type ? concat([": ", path.call(print, "type")]) : "";
const varType = node.hasOwnProperty("readOnly")
? node.readOnly
? "val "
: "var "
: "";

const prefix =
mods.length == 0 ? "" : concat([...path.map(print, "mods"), " "]);
const prefix =
mods.length == 0 ? "" : concat([...path.map(print, "mods"), " "]);

return concat([prefix, varType, name, type]);
return concat([prefix, varType, name, type]);
}
};

0 comments on commit 608f6ab

Please sign in to comment.