Skip to content

Commit 16fcfde

Browse files
committed
upgrade parser for bug fixes #28af6d5
1 parent 43eaf75 commit 16fcfde

File tree

7 files changed

+95
-21
lines changed

7 files changed

+95
-21
lines changed

jscomp/common/bs_version.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* You should have received a copy of the GNU Lesser General Public License
2323
* along with this program; if not, write to the Free Software
2424
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
25-
let version = "9.1.2"
25+
let version = "9.1.3"
2626
let header =
2727
"// Generated by ReScript, PLEASE EDIT WITH CARE"
2828
let package_name = ref "rescript"

lib/4.06.1/bsb.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ end = struct
5555
* You should have received a copy of the GNU Lesser General Public License
5656
* along with this program; if not, write to the Free Software
5757
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
58-
let version = "9.1.2"
58+
let version = "9.1.3"
5959
let header =
6060
"// Generated by ReScript, PLEASE EDIT WITH CARE"
6161
let package_name = ref "rescript"

lib/4.06.1/rescript.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5940,7 +5940,7 @@ end = struct
59405940
* You should have received a copy of the GNU Lesser General Public License
59415941
* along with this program; if not, write to the Free Software
59425942
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
5943-
let version = "9.1.2"
5943+
let version = "9.1.3"
59445944
let header =
59455945
"// Generated by ReScript, PLEASE EDIT WITH CARE"
59465946
let package_name = ref "rescript"

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18039,7 +18039,7 @@ end = struct
1803918039
* You should have received a copy of the GNU Lesser General Public License
1804018040
* along with this program; if not, write to the Free Software
1804118041
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
18042-
let version = "9.1.2"
18042+
let version = "9.1.3"
1804318043
let header =
1804418044
"// Generated by ReScript, PLEASE EDIT WITH CARE"
1804518045
let package_name = ref "rescript"

lib/4.06.1/whole_compiler.ml

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -304481,7 +304481,7 @@ end = struct
304481304481
* You should have received a copy of the GNU Lesser General Public License
304482304482
* along with this program; if not, write to the Free Software
304483304483
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
304484-
let version = "9.1.2"
304484+
let version = "9.1.3"
304485304485
let header =
304486304486
"// Generated by ReScript, PLEASE EDIT WITH CARE"
304487304487
let package_name = ref "rescript"
@@ -414723,6 +414723,8 @@ val isUnderscoreApplySugar: Parsetree.expression -> bool
414723414723

414724414724
val hasIfLetAttribute: Parsetree.attributes -> bool
414725414725

414726+
val isRewrittenUnderscoreApplySugar: Parsetree.expression -> bool
414727+
414726414728
end = struct
414727414729
#1 "res_parsetree_viewer.ml"
414728414730
open Parsetree
@@ -415297,6 +415299,11 @@ let isUnderscoreApplySugar expr =
415297415299
) -> true
415298415300
| _ -> false
415299415301

415302+
let isRewrittenUnderscoreApplySugar expr =
415303+
match expr.pexp_desc with
415304+
| Pexp_ident {txt = Longident.Lident "_"} -> true
415305+
| _ -> false
415306+
415300415307
end
415301415308
module Res_comments_table
415302415309
= struct
@@ -423680,7 +423687,8 @@ and printPexpApply expr cmtTbl =
423680423687
| Pexp_apply (
423681423688
{pexp_desc = Pexp_ident {txt = Longident.Ldot (Lident "Array", "get")}},
423682423689
[Nolabel, parentExpr; Nolabel, memberExpr]
423683-
) ->
423690+
) when not (ParsetreeViewer.isRewrittenUnderscoreApplySugar parentExpr) ->
423691+
(* Don't print the Array.get(_, 0) sugar a.k.a. (__x) => Array.get(__x, 0) as _[0] *)
423684423692
let member =
423685423693
let memberDoc =
423686423694
let doc = printExpressionWithComments memberExpr cmtTbl in
@@ -425346,7 +425354,7 @@ Explanation: since records have a known, fixed shape, a spread like `{a, ...b}`
425346425354
Explanation: lists are singly-linked list, where a node contains a value and points to the next node. `list[a, ...bc]` efficiently creates a new item and links `bc` as its next nodes. `[...bc, a]` would be expensive, as it'd need to traverse `bc` and prepend each item to `a` one by one. We therefore disallow such syntax sugar.\n\
425347425355
Solution: directly use `concat`."
425348425356

425349-
let variantIdent = "A polymorphic variant (e.g. #id) must start with an alphabetical letter."
425357+
let variantIdent = "A polymorphic variant (e.g. #id) must start with an alphabetical letter or be a number (e.g. #742)"
425350425358

425351425359
let experimentalIfLet expr =
425352425360
let switchExpr = {expr with Parsetree.pexp_attributes = []} in
@@ -425393,6 +425401,9 @@ Solution: directly use `concat`."
425393425401

425394425402
let sameTypeSpread =
425395425403
"You're using a ... spread without extra fields. This is the same type."
425404+
425405+
let polyVarIntWithSuffix number =
425406+
"A numeric polymorphic variant cannot be followed by a letter. Did you mean `#" ^ number ^ "`?"
425396425407
end
425397425408

425398425409

@@ -425427,14 +425438,15 @@ let getClosingToken = function
425427425438
| Lbrace -> Rbrace
425428425439
| Lbracket -> Rbracket
425429425440
| List -> Rbrace
425441+
| LessThan -> GreaterThan
425430425442
| _ -> assert false
425431425443

425432425444
let rec goToClosing closingToken state =
425433425445
match (state.Parser.token, closingToken) with
425434-
| (Rparen, Token.Rparen) | (Rbrace, Rbrace) | (Rbracket, Rbracket) ->
425446+
| (Rparen, Token.Rparen) | (Rbrace, Rbrace) | (Rbracket, Rbracket) | (GreaterThan, GreaterThan) ->
425435425447
Parser.next state;
425436425448
()
425437-
| (Token.Lbracket | Lparen | Lbrace | List) as t, _ ->
425449+
| (Token.Lbracket | Lparen | Lbrace | List | LessThan) as t, _ ->
425438425450
Parser.next state;
425439425451
goToClosing (getClosingToken t) state;
425440425452
goToClosing closingToken state
@@ -425463,10 +425475,32 @@ let isEs6ArrowExpression ~inTernary p =
425463425475
let prevEndPos = state.prevEndPos in
425464425476
Parser.next state;
425465425477
begin match state.token with
425478+
(* arrived at `()` here *)
425466425479
| Rparen ->
425467425480
Parser.next state;
425468425481
begin match state.Parser.token with
425469-
| Colon when not inTernary -> true
425482+
(* arrived at `() :` here *)
425483+
| Colon when not inTernary ->
425484+
Parser.next state;
425485+
begin match state.Parser.token with
425486+
(* arrived at `() :typ` here *)
425487+
| Lident _ ->
425488+
Parser.next state;
425489+
begin match state.Parser.token with
425490+
(* arrived at `() :typ<` here *)
425491+
| LessThan ->
425492+
Parser.next state;
425493+
goToClosing GreaterThan state;
425494+
| _ -> ()
425495+
end;
425496+
begin match state.Parser.token with
425497+
(* arrived at `() :typ =>` or `() :typ<'a,'b> =>` here *)
425498+
| EqualGreater ->
425499+
true
425500+
| _ -> false
425501+
end
425502+
| _ -> true
425503+
end
425470425504
| EqualGreater -> true
425471425505
| _ -> false
425472425506
end
@@ -425942,7 +425976,12 @@ let parseHashIdent ~startPos p =
425942425976
Parser.next p;
425943425977
let text = if p.mode = ParseForTypeChecker then parseStringLiteral text else text in
425944425978
(text, mkLoc startPos p.prevEndPos)
425945-
| Int {i} ->
425979+
| Int {i; suffix} ->
425980+
let () = match suffix with
425981+
| Some _ ->
425982+
Parser.err p (Diagnostics.message (ErrorMessages.polyVarIntWithSuffix i))
425983+
| None -> ()
425984+
in
425946425985
Parser.next p;
425947425986
(i, mkLoc startPos p.prevEndPos)
425948425987
| _ ->
@@ -426448,7 +426487,12 @@ let rec parsePattern ?(alias=true) ?(or_=true) p =
426448426487
Parser.next p;
426449426488
let text = if p.mode = ParseForTypeChecker then parseStringLiteral text else text in
426450426489
(text, mkLoc startPos p.prevEndPos)
426451-
| Int {i} ->
426490+
| Int {i; suffix} ->
426491+
let () = match suffix with
426492+
| Some _ ->
426493+
Parser.err p (Diagnostics.message (ErrorMessages.polyVarIntWithSuffix i))
426494+
| None -> ()
426495+
in
426452426496
Parser.next p;
426453426497
(i, mkLoc startPos p.prevEndPos)
426454426498
| _ ->
@@ -429642,7 +429686,11 @@ and parseConstrDeclArgs p =
429642429686
) in
429643429687
Parser.expect Rbrace p;
429644429688
let loc = mkLoc startPos p.prevEndPos in
429645-
let typ = Ast_helper.Typ.object_ ~loc ~attrs:[] fields closedFlag in
429689+
let typ =
429690+
Ast_helper.Typ.object_ ~loc ~attrs:[] fields closedFlag
429691+
|> parseTypeAlias p
429692+
in
429693+
let typ = parseArrowTypeRest ~es6Arrow:true ~startPos typ p in
429646429694
Parser.optional p Comma |> ignore;
429647429695
let moreArgs =
429648429696
parseCommaDelimitedRegion
@@ -433164,8 +433212,34 @@ let printPolyVarIdent txt =
433164433212
)
433165433213
| Otyp_arrow _ as typ ->
433166433214
printOutArrowType ~uncurried:false typ
433167-
| Otyp_module (_modName, _stringList, _outTypes) ->
433168-
Doc.nil
433215+
| Otyp_module (modName, stringList, outTypes) ->
433216+
let packageTypeDoc = match (stringList, outTypes) with
433217+
| [], [] -> Doc.nil
433218+
| labels, types ->
433219+
let i = ref 0 in
433220+
let package = Doc.join ~sep:Doc.line (List.map2 (fun lbl typ ->
433221+
Doc.concat [
433222+
Doc.text (if i.contents > 0 then "and " else "with ");
433223+
Doc.text lbl;
433224+
Doc.text " = ";
433225+
printOutTypeDoc typ;
433226+
]
433227+
) labels types)
433228+
in
433229+
Doc.indent (
433230+
Doc.concat [
433231+
Doc.line;
433232+
package
433233+
]
433234+
)
433235+
in
433236+
Doc.concat [
433237+
Doc.text "module";
433238+
Doc.lparen;
433239+
Doc.text modName;
433240+
packageTypeDoc;
433241+
Doc.rparen;
433242+
]
433169433243

433170433244
and printOutArrowType ~uncurried typ =
433171433245
let (typArgs, typ) = collectArrowArgs typ [] in
@@ -433419,8 +433493,8 @@ let printPolyVarIdent txt =
433419433493
Doc.text " =";
433420433494
Doc.line;
433421433495
Doc.group (
433422-
Doc.join ~sep:Doc.line (List.map (fun prim ->
433423-
let prim = if prim <> "" && prim.[0] = '\132' then "#rescript-external" else prim in
433496+
Doc.join ~sep:Doc.line (List.map (fun prim ->
433497+
let prim = if prim <> "" && (prim.[0] [@doesNotRaise]) = '\132' then "#rescript-external" else prim in
433424433498
(* not display those garbage '\132' is a magic number for marshal *)
433425433499
Doc.text ("\"" ^ prim ^ "\"")) primitives)
433426433500
)
@@ -433461,10 +433535,10 @@ let printPolyVarIdent txt =
433461433535
match outRecStatus with
433462433536
| Orec_not -> "module "
433463433537
| Orec_first -> "module rec "
433464-
| Orec_next -> "and"
433538+
| Orec_next -> "and "
433465433539
);
433466433540
Doc.text modName;
433467-
Doc.text " = ";
433541+
Doc.text ": ";
433468433542
printOutModuleTypeDoc outModType;
433469433543
]
433470433544
)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"coverage": "nyc --timeout=3000 --reporter=html mocha jscomp/test/*test.js && open ./coverage/index.html"
1919
},
2020
"name": "rescript",
21-
"version": "9.1.2",
21+
"version": "9.1.3",
2222
"description": "ReScript toolchain",
2323
"repository": {
2424
"type": "git",

0 commit comments

Comments
 (0)