From ee5c335882aab362e66f5993d2a97bf7886cd247 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 13 Jun 2022 10:18:49 +0200 Subject: [PATCH] Compiler: remove Parse_info.t from TAnnot token --- compiler/lib/javascript.ml | 3 ++- compiler/lib/javascript.mli | 3 ++- compiler/lib/js_parser.mly | 6 ++++-- compiler/lib/js_token.ml | 4 ++-- compiler/lib/js_token.mli | 2 +- compiler/lib/linker.ml | 2 +- compiler/lib/parse_js.ml | 4 ++-- compiler/tests-compiler/js_parser_printer.ml | 3 ++- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/compiler/lib/javascript.ml b/compiler/lib/javascript.ml index d0fcf11fdc..9e7eedab73 100644 --- a/compiler/lib/javascript.ml +++ b/compiler/lib/javascript.ml @@ -280,7 +280,8 @@ and function_body = source_elements and program = source_elements -and program_with_annots = ((source_element * location) * Js_token.Annot.t list) list +and program_with_annots = + ((source_element * location) * (Js_token.Annot.t * Parse_info.t) list) list and source_elements = (source_element * location) list diff --git a/compiler/lib/javascript.mli b/compiler/lib/javascript.mli index 6ba77e7438..c748157b50 100644 --- a/compiler/lib/javascript.mli +++ b/compiler/lib/javascript.mli @@ -232,7 +232,8 @@ and program = source_elements and source_elements = (source_element * location) list -and program_with_annots = ((source_element * location) * Js_token.Annot.t list) list +and program_with_annots = + ((source_element * location) * (Js_token.Annot.t * Parse_info.t) list) list and source_element = | Statement of statement diff --git a/compiler/lib/js_parser.mly b/compiler/lib/js_parser.mly index f14d68670d..df3fa43fa3 100644 --- a/compiler/lib/js_parser.mly +++ b/compiler/lib/js_parser.mly @@ -33,7 +33,9 @@ open Javascript let var pi name = ident ~loc:(pi) name -let p pos = Pi (Parse_info.t_of_pos pos) +let pi pos = (Parse_info.t_of_pos pos) + +let p pos = Pi (pi pos) %} @@ -149,7 +151,7 @@ standalone_expression: | e=expression EOF { e } annot: - | a=TAnnot { a } + | a=TAnnot { a, pi $symbolstartpos } source_element_with_annot: | annots=annot* s=source_element {s,annots} diff --git a/compiler/lib/js_token.ml b/compiler/lib/js_token.ml index 870f4fc489..2b83ace531 100644 --- a/compiler/lib/js_token.ml +++ b/compiler/lib/js_token.ml @@ -20,7 +20,7 @@ open! Stdlib module Annot = struct - type t = string * Parse_info.t * Primitive.t + type t = string * Primitive.t end type t = @@ -118,7 +118,7 @@ type t = type token = t let to_string = function - | TAnnot (s, _, _) -> s + | TAnnot (s, _) -> s | TUnknown s -> s | TComment s -> s | TCommentLineDirective s -> s diff --git a/compiler/lib/js_token.mli b/compiler/lib/js_token.mli index 85c5b99f8f..ad3ed88205 100644 --- a/compiler/lib/js_token.mli +++ b/compiler/lib/js_token.mli @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) module Annot : sig - type t = string * Parse_info.t * Primitive.t + type t = string * Primitive.t end type t = diff --git a/compiler/lib/linker.ml b/compiler/lib/linker.ml index 2ce9f60beb..098664d2bd 100644 --- a/compiler/lib/linker.ml +++ b/compiler/lib/linker.ml @@ -233,7 +233,7 @@ module Fragment = struct List.fold_left annot ~init:initial_fragment - ~f:(fun (fragment : fragment_) (_, pi, a) -> + ~f:(fun (fragment : fragment_) ((_, a), pi) -> match a with | `Provides (name, kind, ka) -> { fragment with diff --git a/compiler/lib/parse_js.ml b/compiler/lib/parse_js.ml index 5a568a5ea3..18ef34edbb 100644 --- a/compiler/lib/parse_js.ml +++ b/compiler/lib/parse_js.ml @@ -98,7 +98,7 @@ let parse_aux the_parser lexbuf = match parse_annot s with | None -> read_one ((tok, pi) :: prev_with_comment) lexbuf | Some annot -> - let tok = Js_token.TAnnot (s, pi, annot) in + let tok = Js_token.TAnnot (s, annot) in (tok, pi), prev_with_comment else read_one ((tok, pi) :: prev_with_comment) lexbuf | TAnnot _ -> assert false @@ -181,7 +181,7 @@ let parse_aux the_parser lexbuf = in let drop_annot_or_error () = match prev with - | (TAnnot (s, _, _), i) :: _ -> + | (TAnnot (s, _), i) :: _ -> let prev, prev_with_comment, checkpoint = last_checkpoint in let t = Js_token.TComment s in loop prev ((t, i) :: prev_with_comment) (last_checkpoint, checkpoint) diff --git a/compiler/tests-compiler/js_parser_printer.ml b/compiler/tests-compiler/js_parser_printer.ml index 3087224b9f..00242e055e 100644 --- a/compiler/tests-compiler/js_parser_printer.ml +++ b/compiler/tests-compiler/js_parser_printer.ml @@ -101,7 +101,8 @@ let%expect_test "preserve number literals" = let%expect_test "preserve number literals in property_name" = print ~compact:false {| var number_as_key = { 100000000000000000000 : 2 }; |}; - [%expect {| + [%expect + {| /*<< 2 4>>*/ /*<< 2 22>>*/ var number_as_key={100000000000000000000:2}; |}] let%expect_test "error reporting" =