-
Notifications
You must be signed in to change notification settings - Fork 38
Done, but do not merge yet: Async/Await syntax. #600
Changes from all commits
21c01e6
5995738
454d5b6
686fa53
5c91bc4
03db389
9e711a4
d0b7cb1
0283e8d
dc85c21
66defd5
ff69dfa
3d5af74
702d586
046d1e3
41844e6
fcd3c32
d20b149
3b17a08
bff364e
c15dee0
5e9b914
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ let callExpr expr = | |
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ ); | ||
} -> | ||
Parenthesized | ||
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> | ||
Parenthesized | ||
| _ -> Nothing) | ||
|
||
let structureExpr expr = | ||
|
@@ -96,6 +98,8 @@ let unaryExprOperand expr = | |
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ ); | ||
} -> | ||
Parenthesized | ||
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> | ||
Parenthesized | ||
| _ -> Nothing) | ||
|
||
let binaryExprOperand ~isLhs expr = | ||
|
@@ -120,6 +124,8 @@ let binaryExprOperand ~isLhs expr = | |
| expr when ParsetreeViewer.isBinaryExpression expr -> Parenthesized | ||
| expr when ParsetreeViewer.isTernaryExpr expr -> Parenthesized | ||
| {pexp_desc = Pexp_lazy _ | Pexp_assert _} when isLhs -> Parenthesized | ||
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> | ||
Parenthesized | ||
| {Parsetree.pexp_attributes = attrs} -> | ||
if ParsetreeViewer.hasPrintableAttributes attrs then Parenthesized | ||
else Nothing) | ||
|
@@ -169,7 +175,7 @@ let flattenOperandRhs parentOperator rhs = | |
| _ when ParsetreeViewer.isTernaryExpr rhs -> true | ||
| _ -> false | ||
|
||
let lazyOrAssertExprRhs expr = | ||
let lazyOrAssertOrAwaitExprRhs expr = | ||
let optBraces, _ = ParsetreeViewer.processBracesAttr expr in | ||
match optBraces with | ||
| Some ({Location.loc = bracesLoc}, _) -> Braced bracesLoc | ||
|
@@ -196,6 +202,8 @@ let lazyOrAssertExprRhs expr = | |
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ ); | ||
} -> | ||
Parenthesized | ||
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> | ||
Parenthesized | ||
| _ -> Nothing) | ||
|
||
let isNegativeConstant constant = | ||
|
@@ -240,6 +248,8 @@ let fieldExpr expr = | |
| Pexp_ifthenelse _ ); | ||
} -> | ||
Parenthesized | ||
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> | ||
Parenthesized | ||
| _ -> Nothing) | ||
|
||
let setFieldExprRhs expr = | ||
|
@@ -302,6 +312,8 @@ let jsxPropExpr expr = | |
} | ||
when startsWithMinus x -> | ||
Parenthesized | ||
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> | ||
Parenthesized | ||
| { | ||
Parsetree.pexp_desc = | ||
( Pexp_ident _ | Pexp_constant _ | Pexp_field _ | Pexp_construct _ | ||
|
@@ -338,6 +350,8 @@ let jsxChildExpr expr = | |
} | ||
when startsWithMinus x -> | ||
Parenthesized | ||
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a lot of these. Should there be a generic concept of which this is an instance so all these calls are moved to a single place? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you give an example of what you mean by this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can move to a helper function, though the difference is minimal. Just easier to make sure all the instances are updated at once if something changes in future. Another thing I was wondering is: this case seems to often go where there is also |
||
Parenthesized | ||
| { | ||
Parsetree.pexp_desc = | ||
( Pexp_ident _ | Pexp_constant _ | Pexp_field _ | Pexp_construct _ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ let arrowType ct = | |
process attrsBefore (arg :: acc) typ2 | ||
| { | ||
ptyp_desc = Ptyp_arrow ((Nolabel as lbl), typ1, typ2); | ||
ptyp_attributes = [({txt = "bs"}, _)] as attrs; | ||
ptyp_attributes = [({txt = "bs" | "res.async"}, _)] as attrs; | ||
} -> | ||
let arg = (attrs, lbl, typ1) in | ||
process attrsBefore (arg :: acc) typ2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there a separate case for process attributes? |
||
|
@@ -55,6 +55,30 @@ let processUncurriedAttribute attrs = | |
in | ||
process false [] attrs | ||
|
||
type functionAttributesInfo = { | ||
async: bool; | ||
uncurried: bool; | ||
attributes: Parsetree.attributes; | ||
} | ||
|
||
let processFunctionAttributes attrs = | ||
let rec process async uncurried acc attrs = | ||
match attrs with | ||
| [] -> {async; uncurried; attributes = List.rev acc} | ||
| ({Location.txt = "bs"}, _) :: rest -> process async true acc rest | ||
| ({Location.txt = "res.async"}, _) :: rest -> | ||
process true uncurried acc rest | ||
| attr :: rest -> process async uncurried (attr :: acc) rest | ||
in | ||
process false false [] attrs | ||
|
||
let hasAwaitAttribute attrs = | ||
List.exists | ||
(function | ||
| {Location.txt = "res.await"}, _ -> true | ||
| _ -> false) | ||
attrs | ||
|
||
let collectListExpressions expr = | ||
let rec collect acc expr = | ||
match expr.pexp_desc with | ||
|
@@ -168,8 +192,9 @@ let filterParsingAttrs attrs = | |
match attr with | ||
| ( { | ||
Location.txt = | ||
( "ns.ternary" | "ns.braces" | "res.template" | "bs" | "ns.iflet" | ||
| "ns.namedArgLoc" | "ns.optional" ); | ||
( "bs" | "ns.braces" | "ns.iflet" | "ns.namedArgLoc" | ||
| "ns.optional" | "ns.ternary" | "res.async" | "res.await" | ||
| "res.template" ); | ||
}, | ||
_ ) -> | ||
false | ||
|
@@ -316,7 +341,8 @@ let hasAttributes attrs = | |
match attr with | ||
| ( { | ||
Location.txt = | ||
"bs" | "res.template" | "ns.ternary" | "ns.braces" | "ns.iflet"; | ||
( "bs" | "ns.braces" | "ns.iflet" | "ns.ternary" | "res.async" | ||
| "res.await" | "res.template" ); | ||
}, | ||
_ ) -> | ||
false | ||
|
@@ -497,8 +523,8 @@ let isPrintableAttribute attr = | |
match attr with | ||
| ( { | ||
Location.txt = | ||
( "bs" | "res.template" | "ns.ternary" | "ns.braces" | "ns.iflet" | ||
| "JSX" ); | ||
( "bs" | "ns.iflet" | "ns.braces" | "JSX" | "res.async" | "res.await" | ||
| "res.template" | "ns.ternary" ); | ||
}, | ||
_ ) -> | ||
false | ||
|
Uh oh!
There was an error while loading. Please reload this page.