Run prettier

This commit is contained in:
Brian Ng
2017-06-27 12:15:00 -05:00
parent 93cc22dae1
commit e4b35f680d
307 changed files with 6742 additions and 4080 deletions

View File

@@ -1,13 +1,16 @@
import syntaxFlow from "babel-plugin-syntax-flow";
export default function ({ types: t }) {
export default function({ types: t }) {
function wrapInFlowComment(path, parent) {
path.addComment("trailing", generateComment(path, parent));
path.replaceWith(t.noop());
}
function generateComment(path, parent) {
let comment = path.getSource().replace(/\*-\//g, "*-ESCAPED/").replace(/\*\//g, "*-/");
let comment = path
.getSource()
.replace(/\*-\//g, "*-ESCAPED/")
.replace(/\*\//g, "*-/");
if (parent && parent.optional) comment = "?" + comment;
if (comment[0] !== ":") comment = ":: " + comment;
return comment;
@@ -19,7 +22,9 @@ export default function ({ types: t }) {
visitor: {
TypeCastExpression(path) {
const { node } = path;
path.get("expression").addComment("trailing", generateComment(path.get("typeAnnotation")));
path
.get("expression")
.addComment("trailing", generateComment(path.get("typeAnnotation")));
path.replaceWith(t.parenthesizedExpression(node.expression));
},
@@ -41,7 +46,7 @@ export default function ({ types: t }) {
// strip optional property from function params - facebook/fbjs#17
Function: {
exit({ node }) {
node.params.forEach((param) => param.optional = false);
node.params.forEach(param => (param.optional = false));
},
},
@@ -54,7 +59,11 @@ export default function ({ types: t }) {
// support `export type a = {}` - #8 Error: You passed path.replaceWith() a falsy node
"ExportNamedDeclaration|Flow"(path) {
const { node, parent } = path;
if (t.isExportNamedDeclaration(node) && node.exportKind !== "type" && !t.isFlow(node.declaration)) {
if (
t.isExportNamedDeclaration(node) &&
node.exportKind !== "type" &&
!t.isFlow(node.declaration)
) {
return;
}
wrapInFlowComment(path, parent);
@@ -63,7 +72,11 @@ export default function ({ types: t }) {
// support `import type A` and `import typeof A` #10
ImportDeclaration(path) {
const { node, parent } = path;
if (t.isImportDeclaration(node) && node.importKind !== "type" && node.importKind !== "typeof") {
if (
t.isImportDeclaration(node) &&
node.importKind !== "type" &&
node.importKind !== "typeof"
) {
return;
}
wrapInFlowComment(path, parent);