Skip to content

Commit

Permalink
Compiler: remove Parse_info.t from TAnnot token
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Jun 13, 2022
1 parent 1b348d6 commit ee5c335
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion compiler/lib/javascript.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion compiler/lib/javascript.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions compiler/lib/js_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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)

%}

Expand Down Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions compiler/lib/js_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/lib/js_token.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion compiler/lib/linker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions compiler/lib/parse_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion compiler/tests-compiler/js_parser_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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" =
Expand Down

0 comments on commit ee5c335

Please sign in to comment.