Skip to content

Commit

Permalink
Compiler: js-parser, support ?.#privateName
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Dec 13, 2023
1 parent 22b307b commit be64ea4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion compiler/lib/javascript.ml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ and expression =
| ECallTemplate of expression * template * location
| EAccess of expression * access_kind * expression
| EDot of expression * access_kind * identifier
| EDotPrivate of expression * identifier
| EDotPrivate of expression * access_kind * identifier
| ENew of expression * arguments option
| EVar of ident
| EFun of ident option * function_declaration
Expand Down
2 changes: 1 addition & 1 deletion compiler/lib/javascript.mli
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ and expression =
| ECallTemplate of expression * template * location
| EAccess of expression * access_kind * expression
| EDot of expression * access_kind * identifier
| EDotPrivate of expression * identifier
| EDotPrivate of expression * access_kind * identifier
| ENew of expression * arguments option
| EVar of ident
| EFun of ident option * function_declaration
Expand Down
8 changes: 5 additions & 3 deletions compiler/lib/js_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ struct
| ECall (e, _, _, _)
| EAccess (e, _, _)
| EDot (e, _, _)
| EDotPrivate (e, _) -> traverse CallOrMemberExpression e
| EDotPrivate (e, _, _) -> traverse CallOrMemberExpression e
| EArrow _
| EVar _
| EStr _
Expand Down Expand Up @@ -775,7 +775,7 @@ struct
| ANormal -> PP.string f "."
| ANullish -> PP.string f "?.");
PP.string f nm
| EDotPrivate (e, Utf8 nm) ->
| EDotPrivate (e, access_kind, Utf8 nm) ->
(* We keep tracks of whether call expression are allowed
without parentheses within this expression *)
let l' =
Expand All @@ -784,7 +784,9 @@ struct
| _ -> CallOrMemberExpression
in
expression l' f e;
PP.string f ".#";
(match access_kind with
| ANormal -> PP.string f ".#"
| ANullish -> PP.string f "?.#");
PP.string f nm
| ENew (e, None) ->
if Prec.(l > NewExpression)
Expand Down
4 changes: 3 additions & 1 deletion compiler/lib/js_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,9 @@ member_expr(x):
| T_NEW "." T_TARGET
{ (EDot(vartok $startpos($1) T_NEW,ANormal,Stdlib.Utf8_string.of_string_exn "target")) }
| e1=member_expr(x) "." T_POUND i=field_name
{ (EDotPrivate(e1,i)) }
{ (EDotPrivate(e1,ANormal,i)) }
| e1=member_expr(x) T_PLING_PERIOD T_POUND i=field_name
{ (EDotPrivate(e1,ANullish,i)) }
primary_expr(x):
| e=primary_expr_no_braces
| e=x { e }
Expand Down
4 changes: 2 additions & 2 deletions compiler/lib/js_traverse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class map : mapper =
ECall (m#expression e1, ak, List.map e2 ~f:m#argument, m#loc loc)
| EAccess (e1, ak, e2) -> EAccess (m#expression e1, ak, m#expression e2)
| EDot (e1, ak, id) -> EDot (m#expression e1, ak, id)
| EDotPrivate (e1, id) -> EDotPrivate (m#expression e1, id)
| EDotPrivate (e1, ak, id) -> EDotPrivate (m#expression e1, ak, id)
| ENew (e1, args) ->
ENew (m#expression e1, Option.map ~f:(List.map ~f:m#argument) args)
| EVar v -> EVar (m#ident v)
Expand Down Expand Up @@ -657,7 +657,7 @@ class iter : iterator =
m#expression e1;
m#expression e2
| EDot (e1, _ak, _) -> m#expression e1
| EDotPrivate (e1, _) -> m#expression e1
| EDotPrivate (e1, _, _) -> m#expression e1
| ENew (e1, Some args) ->
m#expression e1;
List.iter args ~f:m#argument
Expand Down

0 comments on commit be64ea4

Please sign in to comment.