Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis/src/completion_front_end.ml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ let rec expr_to_context_path_inner ~(in_jsx_context : bool)
(e : Parsetree.expression) =
match e.pexp_desc with
| Pexp_braces {expr} -> expr_to_context_path_inner ~in_jsx_context expr
| Pexp_constant (Pconst_string _ | Pconst_json _ | Pconst_raw_source _) ->
| Pexp_constant (Pconst_string _ | Pconst_raw_source _) ->
Some Completable.CPString
| Pexp_template _ -> Some Completable.CPString
| Pexp_tagged_template {tag} -> (
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/document_symbol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let get_symbols ~source ~kind_file =
| Pexp_fun _ -> Lsp.Types.SymbolKind.Function
| Pexp_braces {expr} -> expr_kind expr
| Pexp_constraint (e, _) -> expr_kind e
| Pexp_constant (Pconst_string _ | Pconst_json _ | Pconst_raw_source _) ->
| Pexp_constant (Pconst_string _ | Pconst_raw_source _) ->
Lsp.Types.SymbolKind.String
| Pexp_template _ -> Lsp.Types.SymbolKind.String
| Pexp_constant (Pconst_float _ | Pconst_integer _) ->
Expand Down
1 change: 0 additions & 1 deletion analysis/src/dump_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ let print_constant const =
^ ", semantic="
^ String_literal.string_semantic payload
^ ")"
| Pconst_json source -> "Pconst_json(" ^ source ^ ")"
| Pconst_raw_source source -> "Pconst_raw_source(" ^ source ^ ")"
| Pconst_float (s, _) -> "Pconst_float(" ^ s ^ ")"

Expand Down
59 changes: 32 additions & 27 deletions analysis/src/signature_help.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,33 +114,38 @@ let extract_parameters ~signature ~type_str_for_parser ~label_prefix_len =
Psig_value {pval_type = {ptyp_desc = Ptyp_arrow {params = args}}};
};
] ->
List.map
(fun (arg : Parsetree.arg) ->
let start_loc =
(* For a labeled argument the label precedes the type. *)
match arg.lbl with
| Asttypes.Labelled {loc} | Optional {loc} -> loc |> Loc.start
| Nolabel -> arg.typ.ptyp_loc |> Loc.start
in
let start_offset =
start_loc |> Pos.position_to_offset type_str_for_parser |> Option.get
in
let end_offset =
arg.typ.ptyp_loc |> Loc.end_
|> Pos.position_to_offset type_str_for_parser
|> Option.get
in
(* The AST locations does not account for "=?" of optional arguments, so add that to the offset here if needed. *)
let end_offset =
match arg.lbl with
| Asttypes.Optional _ -> end_offset + 2
| _ -> end_offset
in
( arg.lbl,
(* Remove the label prefix offset here, since we're not
showing that to the end user. *)
start_offset - label_prefix_len,
end_offset - label_prefix_len ))
List.filter_map
(function
| Parsetree.Parg_fixed _ -> None
| Parsetree.Parg_type {lbl; typ; _} ->
let start_loc =
(* For a labeled argument the label precedes the type. *)
match lbl with
| Asttypes.Labelled {loc} | Optional {loc} -> loc |> Loc.start
| Nolabel -> typ.ptyp_loc |> Loc.start
in
let start_offset =
start_loc
|> Pos.position_to_offset type_str_for_parser
|> Option.get
in
let end_offset =
typ.ptyp_loc |> Loc.end_
|> Pos.position_to_offset type_str_for_parser
|> Option.get
in
(* The AST locations does not account for "=?" of optional arguments, so add that to the offset here if needed. *)
let end_offset =
match lbl with
| Asttypes.Optional _ -> end_offset + 2
| _ -> end_offset
in
Some
( lbl,
(* Remove the label prefix offset here, since we're not
showing that to the end user. *)
start_offset - label_prefix_len,
end_offset - label_prefix_len ))
args
| _ -> []

Expand Down
1 change: 1 addition & 0 deletions changes/fixed-external-args-parsetree.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Represent fixed external arguments, written `@as(value) _`, with a dedicated parsetree node. https://github.com/rescript-lang/rescript/pull/8875
1 change: 1 addition & 0 deletions changes/json-tagged-template.polish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Treat `json` template literals outside `` @as(json`...`) _ `` as ordinary tagged templates instead of rejecting them. https://github.com/rescript-lang/rescript/pull/8875
8 changes: 4 additions & 4 deletions compiler/ext/config.ml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
let cmi_magic_number = "Caml1999I036"
let cmi_magic_number = "Caml1999I037"

(* Magic numbers for marshaled values of the *current* parsetree, whose layout
changes across compiler versions. *)
and ast_impl_magic_number = "ResImpl01315"
and ast_impl_magic_number = "ResImpl01316"

and ast_intf_magic_number = "ResIntf01315"
and ast_intf_magic_number = "ResIntf01316"

(* Magic numbers of the frozen Parsetree0 (OCaml 4.06) layout used on the
external-PPX wire. They must never be written in front of a
Expand All @@ -13,7 +13,7 @@ and ast0_impl_magic_number = "Caml1999M022"

and ast0_intf_magic_number = "Caml1999N022"

and cmt_magic_number = "Caml1999T043"
and cmt_magic_number = "Caml1999T044"

let get_load_path () = (Compiler_request_state.current ()).load_path
let set_load_path path = (Compiler_request_state.current ()).load_path <- path
12 changes: 11 additions & 1 deletion compiler/frontend/ast_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,17 @@ let as_const (attrs : t) =
{
pstr_desc =
Pstr_eval
({pexp_desc = Pexp_constant (Pconst_json s); pexp_loc}, _);
( {
pexp_desc =
Pexp_tagged_template
{
tag =
{pexp_desc = Pexp_ident {txt = Lident "json"}};
raw_sources = [{txt = s; loc = pexp_loc}];
values = [];
};
},
_ );
};
] -> (
(* Check that it is a valid object literal. *)
Expand Down
1 change: 0 additions & 1 deletion compiler/frontend/ast_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ let process_directives str =
|> List.iter (fun (item : Parsetree.structure_item) ->
match item.pstr_desc with
| Pstr_attribute ({txt = "directive"}, payload) -> (
Ast_payload.reject_json_literal_payload payload;
match Ast_payload.semantic_string_of_payload payload with
| Some d ->
(Js_config.current ()).directives :=
Expand Down
8 changes: 5 additions & 3 deletions compiler/frontend/ast_derive_projector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ let init () =
Ext_list.map label_declarations (fun {pld_name; pld_type} ->
Ast_comb.single_non_rec_val ?attrs:gentype_attrs pld_name
(Ast_helper.Typ.arrow
[{attrs = []; lbl = Nolabel; typ = core_type}]
[
Parg_type {attrs = []; lbl = Nolabel; typ = core_type};
]
pld_type
(*arity will alwys be 1 since these are single param functions*)))
| Ptype_variant constructor_declarations ->
Expand Down Expand Up @@ -160,8 +162,8 @@ let init () =
{loc; txt = Ext_string.uncapitalize_ascii con_name}
(match
Ext_list.map pcd_args (fun x ->
({attrs = []; lbl = Nolabel; typ = x}
: Parsetree.arg))
Parsetree.Parg_type
{attrs = []; lbl = Nolabel; typ = x})
with
| [] ->
(* zero-argument constructor: the accessor is a value *)
Expand Down
1 change: 0 additions & 1 deletion compiler/frontend/ast_exp_extension.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ let handle_extension e (_self : Ast_mapper.mapper)
(({txt; loc}, payload) : Parsetree.extension) =
match txt with
| "todo" ->
Ast_payload.reject_json_literal_payload payload;
let todo_message =
match Ast_payload.semantic_string_of_payload payload with
| Some s -> Some s
Expand Down
19 changes: 14 additions & 5 deletions compiler/frontend/ast_exp_handle_external.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let handle_debugger loc (payload : Ast_payload.t) =
Ast_external_mk.local_external_apply loc ~pval_prim:(Prim_name "%debugger")
~pval_type:
(Ast_helper.Typ.arrow
[{attrs = []; lbl = Nolabel; typ = Ast_helper.Typ.any ()}]
[Parg_type {attrs = []; lbl = Nolabel; typ = Ast_helper.Typ.any ()}]
(Ast_literal.type_unit ()))
[Ast_literal.val_unit ~loc ()]
| _ ->
Expand All @@ -49,7 +49,10 @@ let handle_raw loc payload =
~pval_prim:(Prim_name "#raw_expr")
~pval_type:
(Ast_helper.Typ.arrow
[{attrs = []; lbl = Nolabel; typ = Ast_helper.Typ.any ()}]
[
Parg_type
{attrs = []; lbl = Nolabel; typ = Ast_helper.Typ.any ()};
]
(Ast_helper.Typ.any ()))
[exp];
pexp_attributes =
Expand Down Expand Up @@ -79,7 +82,7 @@ let handle_ffi ~loc ~payload =
let effective_arity = if arity = 0 then 1 else arity in
let args =
Ext_list.init effective_arity (fun _ ->
({attrs = []; lbl = Nolabel; typ = any} : Parsetree.arg))
Parsetree.Parg_type {attrs = []; lbl = Nolabel; typ = any})
in
Ast_helper.Typ.arrow ~loc args any
in
Expand All @@ -95,7 +98,10 @@ let handle_ffi ~loc ~payload =
~pval_prim:(Prim_name "#raw_expr")
~pval_type:
(Ast_helper.Typ.arrow
[{attrs = []; lbl = Nolabel; typ = Ast_helper.Typ.any ()}]
[
Parg_type
{attrs = []; lbl = Nolabel; typ = Ast_helper.Typ.any ()};
]
(Ast_helper.Typ.any ()))
[exp];
pexp_attributes =
Expand All @@ -115,7 +121,10 @@ let handle_raw_structure loc payload =
~pval_prim:(Prim_name "#raw_stmt")
~pval_type:
(Ast_helper.Typ.arrow
[{attrs = []; lbl = Nolabel; typ = Ast_helper.Typ.any ()}]
[
Parg_type
{attrs = []; lbl = Nolabel; typ = Ast_helper.Typ.any ()};
]
(Ast_helper.Typ.any ()))
[exp];
}
Expand Down
Loading
Loading