Skip to content

Commit c34f927

Browse files
committed
Sync latest surface syntax.
1 parent 485e537 commit c34f927

File tree

3 files changed

+57
-41
lines changed

3 files changed

+57
-41
lines changed

lib/4.06.1/unstable/js_playground_compiler.ml

+28-20
Original file line numberDiff line numberDiff line change
@@ -269919,7 +269919,6 @@ val hasOptionalAttribute : Parsetree.attributes -> bool
269919269919
val shouldIndentBinaryExpr : Parsetree.expression -> bool
269920269920
val shouldInlineRhsBinaryExpr : Parsetree.expression -> bool
269921269921
val hasPrintableAttributes : Parsetree.attributes -> bool
269922-
val filterPrintableAttributes : Parsetree.attributes -> Parsetree.attributes
269923269922
val partitionPrintableAttributes :
269924269923
Parsetree.attributes -> Parsetree.attributes * Parsetree.attributes
269925269924

@@ -270169,9 +270168,9 @@ let filterParsingAttrs attrs =
270169270168
match attr with
270170270169
| ( {
270171270170
Location.txt =
270172-
( "ns.ternary" | "ns.braces" | "res.template" | "res.await"
270173-
| "res.async" | "bs" | "ns.iflet" | "ns.namedArgLoc"
270174-
| "ns.optional" );
270171+
( "bs" | "ns.braces" | "ns.iflet" | "ns.namedArgLoc"
270172+
| "ns.optional" | "ns.ternary" | "res.async" | "res.await"
270173+
| "res.template" );
270175270174
},
270176270175
_ ) ->
270177270176
false
@@ -270318,8 +270317,8 @@ let hasAttributes attrs =
270318270317
match attr with
270319270318
| ( {
270320270319
Location.txt =
270321-
( "bs" | "res.async" | "res.await" | "res.template" | "ns.ternary"
270322-
| "ns.braces" | "ns.iflet" );
270320+
( "bs" | "ns.braces" | "ns.iflet" | "ns.ternary" | "res.async"
270321+
| "res.await" | "res.template" );
270323270322
},
270324270323
_ ) ->
270325270324
false
@@ -270500,17 +270499,15 @@ let isPrintableAttribute attr =
270500270499
match attr with
270501270500
| ( {
270502270501
Location.txt =
270503-
( "bs" | "res.template" | "ns.ternary" | "ns.braces" | "ns.iflet"
270504-
| "JSX" );
270502+
( "bs" | "ns.iflet" | "ns.braces" | "JSX" | "res.async" | "res.await"
270503+
| "res.template" | "ns.ternary" );
270505270504
},
270506270505
_ ) ->
270507270506
false
270508270507
| _ -> true
270509270508

270510270509
let hasPrintableAttributes attrs = List.exists isPrintableAttribute attrs
270511270510

270512-
let filterPrintableAttributes attrs = List.filter isPrintableAttribute attrs
270513-
270514270511
let partitionPrintableAttributes attrs =
270515270512
List.partition isPrintableAttribute attrs
270516270513

@@ -279172,28 +279169,28 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
279172279169
then
279173279170
let leftPrinted = flatten ~isLhs:true left operator in
279174279171
let rightPrinted =
279175-
let _, rightAttrs =
279172+
let rightPrinteableAttrs, rightInternalAttrs =
279176279173
ParsetreeViewer.partitionPrintableAttributes
279177279174
right.pexp_attributes
279178279175
in
279179279176
let doc =
279180279177
printExpressionWithComments ~customLayout
279181-
{right with pexp_attributes = rightAttrs}
279178+
{right with pexp_attributes = rightInternalAttrs}
279182279179
cmtTbl
279183279180
in
279184279181
let doc =
279185279182
if Parens.flattenOperandRhs parentOperator right then
279186279183
Doc.concat [Doc.lparen; doc; Doc.rparen]
279187279184
else doc
279188279185
in
279189-
let printableAttrs =
279190-
ParsetreeViewer.filterPrintableAttributes right.pexp_attributes
279191-
in
279192279186
let doc =
279193279187
Doc.concat
279194-
[printAttributes ~customLayout printableAttrs cmtTbl; doc]
279188+
[
279189+
printAttributes ~customLayout rightPrinteableAttrs cmtTbl;
279190+
doc;
279191+
]
279195279192
in
279196-
match printableAttrs with
279193+
match rightPrinteableAttrs with
279197279194
| [] -> doc
279198279195
| _ -> addParens doc
279199279196
in
@@ -279212,22 +279209,25 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
279212279209
in
279213279210
printComments doc cmtTbl expr.pexp_loc
279214279211
else
279212+
let printeableAttrs, internalAttrs =
279213+
ParsetreeViewer.partitionPrintableAttributes expr.pexp_attributes
279214+
in
279215279215
let doc =
279216279216
printExpressionWithComments ~customLayout
279217-
{expr with pexp_attributes = []}
279217+
{expr with pexp_attributes = internalAttrs}
279218279218
cmtTbl
279219279219
in
279220279220
let doc =
279221279221
if
279222279222
Parens.subBinaryExprOperand parentOperator operator
279223-
|| expr.pexp_attributes <> []
279223+
|| printeableAttrs <> []
279224279224
&& (ParsetreeViewer.isBinaryExpression expr
279225279225
|| ParsetreeViewer.isTernaryExpr expr)
279226279226
then Doc.concat [Doc.lparen; doc; Doc.rparen]
279227279227
else doc
279228279228
in
279229279229
Doc.concat
279230-
[printAttributes ~customLayout expr.pexp_attributes cmtTbl; doc]
279230+
[printAttributes ~customLayout printeableAttrs cmtTbl; doc]
279231279231
| _ -> assert false
279232279232
else
279233279233
match expr.pexp_desc with
@@ -283841,6 +283841,14 @@ and parseBracedOrRecordExpr p =
283841283841
let expr = parseRecordExpr ~startPos [] p in
283842283842
Parser.expect Rbrace p;
283843283843
expr
283844+
(*
283845+
The branch below takes care of the "braced" expression {async}.
283846+
The big reason that we need all these branches is that {x} isn't a record with a punned field x, but a braced expression… There's lots of "ambiguity" between a record with a single punned field and a braced expression…
283847+
What is {x}?
283848+
1) record {x: x}
283849+
2) expression x which happens to wrapped in braces
283850+
Due to historical reasons, we always follow 2
283851+
*)
283844283852
| Lident "async" when isEs6ArrowExpression ~inTernary:false p ->
283845283853
let expr = parseAsyncArrowExpression p in
283846283854
let expr = parseExprBlock ~first:expr p in

lib/4.06.1/whole_compiler.ml

+28-20
Original file line numberDiff line numberDiff line change
@@ -275664,7 +275664,6 @@ val hasOptionalAttribute : Parsetree.attributes -> bool
275664275664
val shouldIndentBinaryExpr : Parsetree.expression -> bool
275665275665
val shouldInlineRhsBinaryExpr : Parsetree.expression -> bool
275666275666
val hasPrintableAttributes : Parsetree.attributes -> bool
275667-
val filterPrintableAttributes : Parsetree.attributes -> Parsetree.attributes
275668275667
val partitionPrintableAttributes :
275669275668
Parsetree.attributes -> Parsetree.attributes * Parsetree.attributes
275670275669

@@ -275914,9 +275913,9 @@ let filterParsingAttrs attrs =
275914275913
match attr with
275915275914
| ( {
275916275915
Location.txt =
275917-
( "ns.ternary" | "ns.braces" | "res.template" | "res.await"
275918-
| "res.async" | "bs" | "ns.iflet" | "ns.namedArgLoc"
275919-
| "ns.optional" );
275916+
( "bs" | "ns.braces" | "ns.iflet" | "ns.namedArgLoc"
275917+
| "ns.optional" | "ns.ternary" | "res.async" | "res.await"
275918+
| "res.template" );
275920275919
},
275921275920
_ ) ->
275922275921
false
@@ -276063,8 +276062,8 @@ let hasAttributes attrs =
276063276062
match attr with
276064276063
| ( {
276065276064
Location.txt =
276066-
( "bs" | "res.async" | "res.await" | "res.template" | "ns.ternary"
276067-
| "ns.braces" | "ns.iflet" );
276065+
( "bs" | "ns.braces" | "ns.iflet" | "ns.ternary" | "res.async"
276066+
| "res.await" | "res.template" );
276068276067
},
276069276068
_ ) ->
276070276069
false
@@ -276245,17 +276244,15 @@ let isPrintableAttribute attr =
276245276244
match attr with
276246276245
| ( {
276247276246
Location.txt =
276248-
( "bs" | "res.template" | "ns.ternary" | "ns.braces" | "ns.iflet"
276249-
| "JSX" );
276247+
( "bs" | "ns.iflet" | "ns.braces" | "JSX" | "res.async" | "res.await"
276248+
| "res.template" | "ns.ternary" );
276250276249
},
276251276250
_ ) ->
276252276251
false
276253276252
| _ -> true
276254276253

276255276254
let hasPrintableAttributes attrs = List.exists isPrintableAttribute attrs
276256276255

276257-
let filterPrintableAttributes attrs = List.filter isPrintableAttribute attrs
276258-
276259276256
let partitionPrintableAttributes attrs =
276260276257
List.partition isPrintableAttribute attrs
276261276258

@@ -284917,28 +284914,28 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
284917284914
then
284918284915
let leftPrinted = flatten ~isLhs:true left operator in
284919284916
let rightPrinted =
284920-
let _, rightAttrs =
284917+
let rightPrinteableAttrs, rightInternalAttrs =
284921284918
ParsetreeViewer.partitionPrintableAttributes
284922284919
right.pexp_attributes
284923284920
in
284924284921
let doc =
284925284922
printExpressionWithComments ~customLayout
284926-
{right with pexp_attributes = rightAttrs}
284923+
{right with pexp_attributes = rightInternalAttrs}
284927284924
cmtTbl
284928284925
in
284929284926
let doc =
284930284927
if Parens.flattenOperandRhs parentOperator right then
284931284928
Doc.concat [Doc.lparen; doc; Doc.rparen]
284932284929
else doc
284933284930
in
284934-
let printableAttrs =
284935-
ParsetreeViewer.filterPrintableAttributes right.pexp_attributes
284936-
in
284937284931
let doc =
284938284932
Doc.concat
284939-
[printAttributes ~customLayout printableAttrs cmtTbl; doc]
284933+
[
284934+
printAttributes ~customLayout rightPrinteableAttrs cmtTbl;
284935+
doc;
284936+
]
284940284937
in
284941-
match printableAttrs with
284938+
match rightPrinteableAttrs with
284942284939
| [] -> doc
284943284940
| _ -> addParens doc
284944284941
in
@@ -284957,22 +284954,25 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
284957284954
in
284958284955
printComments doc cmtTbl expr.pexp_loc
284959284956
else
284957+
let printeableAttrs, internalAttrs =
284958+
ParsetreeViewer.partitionPrintableAttributes expr.pexp_attributes
284959+
in
284960284960
let doc =
284961284961
printExpressionWithComments ~customLayout
284962-
{expr with pexp_attributes = []}
284962+
{expr with pexp_attributes = internalAttrs}
284963284963
cmtTbl
284964284964
in
284965284965
let doc =
284966284966
if
284967284967
Parens.subBinaryExprOperand parentOperator operator
284968-
|| expr.pexp_attributes <> []
284968+
|| printeableAttrs <> []
284969284969
&& (ParsetreeViewer.isBinaryExpression expr
284970284970
|| ParsetreeViewer.isTernaryExpr expr)
284971284971
then Doc.concat [Doc.lparen; doc; Doc.rparen]
284972284972
else doc
284973284973
in
284974284974
Doc.concat
284975-
[printAttributes ~customLayout expr.pexp_attributes cmtTbl; doc]
284975+
[printAttributes ~customLayout printeableAttrs cmtTbl; doc]
284976284976
| _ -> assert false
284977284977
else
284978284978
match expr.pexp_desc with
@@ -289586,6 +289586,14 @@ and parseBracedOrRecordExpr p =
289586289586
let expr = parseRecordExpr ~startPos [] p in
289587289587
Parser.expect Rbrace p;
289588289588
expr
289589+
(*
289590+
The branch below takes care of the "braced" expression {async}.
289591+
The big reason that we need all these branches is that {x} isn't a record with a punned field x, but a braced expression… There's lots of "ambiguity" between a record with a single punned field and a braced expression…
289592+
What is {x}?
289593+
1) record {x: x}
289594+
2) expression x which happens to wrapped in braces
289595+
Due to historical reasons, we always follow 2
289596+
*)
289589289597
| Lident "async" when isEs6ArrowExpression ~inTernary:false p ->
289590289598
let expr = parseAsyncArrowExpression p in
289591289599
let expr = parseExprBlock ~first:expr p in

0 commit comments

Comments
 (0)