From 959403f46855edea171bddaa7ae513b79e899c4a Mon Sep 17 00:00:00 2001 From: Vincent Siles Date: Sun, 23 May 2021 06:01:39 -0700 Subject: [PATCH] thread the `disallow hash comments` option to the facts parser Summary: Now that disallow hash comments is on in www, we need to thread that information to the facts parser Reviewed By: jthemphill Differential Revision: D28601444 fbshipit-source-id: bbfd01bebd20275260cdb7aeafa48184d159dc91 --- hphp/hack/src/client/ide_service/clientIdeIncremental.ml | 1 + hphp/hack/src/facts/facts_parser.ml | 6 +++++- hphp/hack/src/facts/facts_parser.mli | 2 ++ hphp/hack/src/facts/facts_parser.rs | 3 +++ hphp/hack/src/facts/rust_facts_ffi.rs | 4 ++++ hphp/hack/src/facts/symbols/indexBuilder.ml | 1 + hphp/hack/src/hh_single_compile.ml | 1 + hphp/hack/src/server/serverRpc.ml | 1 + hphp/hack/test/rust/facts_parse.rs | 1 + 9 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hphp/hack/src/client/ide_service/clientIdeIncremental.ml b/hphp/hack/src/client/ide_service/clientIdeIncremental.ml index 8f1171b596f..c3690705372 100644 --- a/hphp/hack/src/client/ide_service/clientIdeIncremental.ml +++ b/hphp/hack/src/client/ide_service/clientIdeIncremental.ml @@ -70,6 +70,7 @@ let compute_fileinfo_for_path (ParserOptions.enable_xhp_class_modifier popt) ~disable_xhp_element_mangling: (ParserOptions.disable_xhp_element_mangling popt) + ~disallow_hash_comments:(ParserOptions.disallow_hash_comments popt) ~filename:path ~text:contents in diff --git a/hphp/hack/src/facts/facts_parser.ml b/hphp/hack/src/facts/facts_parser.ml index 563570fa010..09c76a224fb 100644 --- a/hphp/hack/src/facts/facts_parser.ml +++ b/hphp/hack/src/facts/facts_parser.ml @@ -25,6 +25,7 @@ let extract_as_json_string ~(disable_legacy_attribute_syntax : bool) ~(enable_xhp_class_modifier : bool) ~(disable_xhp_element_mangling : bool) + ~(disallow_hash_comments : bool) ~(filename : Relative_path.t) ~(text : string) = (* return empty string if file has syntax errors *) @@ -42,7 +43,8 @@ let extract_as_json_string lor (bool2int hhvm_compat_mode lsl 1) lor (bool2int allow_new_attribute_syntax lsl 2) lor (bool2int enable_xhp_class_modifier lsl 3) - lor (bool2int disable_xhp_element_mangling lsl 4) ) + lor (bool2int disable_xhp_element_mangling lsl 4) + lor (bool2int disallow_hash_comments lsl 5) ) filename text !mangle_xhp_mode @@ -60,6 +62,7 @@ let from_text ~(disable_legacy_attribute_syntax : bool) ~(enable_xhp_class_modifier : bool) ~(disable_xhp_element_mangling : bool) + ~(disallow_hash_comments : bool) ~(filename : Relative_path.t) ~(text : string) = Option.bind @@ -72,6 +75,7 @@ let from_text ~disable_legacy_attribute_syntax ~enable_xhp_class_modifier ~disable_xhp_element_mangling + ~disallow_hash_comments ~filename ~text |> Option.map ~f:Hh_json.json_of_string ) diff --git a/hphp/hack/src/facts/facts_parser.mli b/hphp/hack/src/facts/facts_parser.mli index 2b7fb9f2fac..01f95ea4327 100644 --- a/hphp/hack/src/facts/facts_parser.mli +++ b/hphp/hack/src/facts/facts_parser.mli @@ -21,6 +21,7 @@ val extract_as_json_string : disable_legacy_attribute_syntax:bool -> enable_xhp_class_modifier:bool -> disable_xhp_element_mangling:bool -> + disallow_hash_comments:bool -> filename:Relative_path.t -> text:string -> string option @@ -34,6 +35,7 @@ val from_text : disable_legacy_attribute_syntax:bool -> enable_xhp_class_modifier:bool -> disable_xhp_element_mangling:bool -> + disallow_hash_comments:bool -> filename:Relative_path.t -> text:string -> Facts.facts option diff --git a/hphp/hack/src/facts/facts_parser.rs b/hphp/hack/src/facts/facts_parser.rs index 481e72f7ccd..1a2c118e388 100644 --- a/hphp/hack/src/facts/facts_parser.rs +++ b/hphp/hack/src/facts/facts_parser.rs @@ -21,6 +21,7 @@ pub struct ExtractAsJsonOpts { pub enable_xhp_class_modifier: bool, pub disable_xhp_element_mangling: bool, pub filename: RelativePath, + pub disallow_hash_comments: bool, } pub fn extract_as_json(text: &[u8], opts: ExtractAsJsonOpts) -> Option { @@ -35,6 +36,7 @@ pub fn from_text(text: &[u8], opts: ExtractAsJsonOpts) -> Option { enable_xhp_class_modifier, disable_xhp_element_mangling, filename, + disallow_hash_comments, } = opts; let text = SourceText::make(RcOc::new(filename), text); let env = ParserEnv { @@ -43,6 +45,7 @@ pub fn from_text(text: &[u8], opts: ExtractAsJsonOpts) -> Option { allow_new_attribute_syntax, enable_xhp_class_modifier, disable_xhp_element_mangling, + disallow_hash_comments, ..ParserEnv::default() }; let (root, errors, has_script_content) = facts_parser::parse_script(&text, env, None); diff --git a/hphp/hack/src/facts/rust_facts_ffi.rs b/hphp/hack/src/facts/rust_facts_ffi.rs index 9e16fb45229..1f0cb00e150 100644 --- a/hphp/hack/src/facts/rust_facts_ffi.rs +++ b/hphp/hack/src/facts/rust_facts_ffi.rs @@ -40,6 +40,7 @@ unsafe extern "C" fn hackc_extract_as_json_cpp_ffi( ((1 << 2) & flags) != 0, // allow_new_attribute_syntax ((1 << 3) & flags) != 0, // enable_xhp_class_modifier ((1 << 4) & flags) != 0, // disable_xhp_element_mangling + ((1 << 5) & flags) != 0, // disallow_hash_comments filename, text, mangle_xhp, @@ -88,6 +89,7 @@ ocaml_ffi! { ((1 << 2) & flags) != 0, // allow_new_attribute_syntax ((1 << 3) & flags) != 0, // enable_xhp_class_modifier ((1 << 4) & flags) != 0, // disable_xhp_element_mangling + ((1 << 5) & flags) != 0, // disallow_hash_comments filename, text, mangle_xhp, @@ -101,6 +103,7 @@ fn extract_as_json_ffi0( allow_new_attribute_syntax: bool, enable_xhp_class_modifier: bool, disable_xhp_element_mangling: bool, + disallow_hash_comments: bool, filename: RelativePath, text: &[u8], mangle_xhp: bool, @@ -112,6 +115,7 @@ fn extract_as_json_ffi0( enable_xhp_class_modifier, disable_xhp_element_mangling, filename, + disallow_hash_comments, }; if mangle_xhp { extract_as_json(text, opts) diff --git a/hphp/hack/src/facts/symbols/indexBuilder.ml b/hphp/hack/src/facts/symbols/indexBuilder.ml index e9544bc00bb..c20d0792356 100644 --- a/hphp/hack/src/facts/symbols/indexBuilder.ml +++ b/hphp/hack/src/facts/symbols/indexBuilder.ml @@ -113,6 +113,7 @@ let parse_one_file ~(path : Relative_path.t) : si_capture = ~disable_legacy_attribute_syntax:false ~enable_xhp_class_modifier:false ~disable_xhp_element_mangling:false + ~disallow_hash_comments:true ~filename:path ~text in diff --git a/hphp/hack/src/hh_single_compile.ml b/hphp/hack/src/hh_single_compile.ml index d74380aee4d..940553666ed 100644 --- a/hphp/hack/src/hh_single_compile.ml +++ b/hphp/hack/src/hh_single_compile.ml @@ -447,6 +447,7 @@ let extract_facts ~compiler_options ~config_jsons ~filename text = ~disable_legacy_attribute_syntax:(disable_legacy_attribute_syntax co) ~enable_xhp_class_modifier:(enable_xhp_class_modifier co) ~disable_xhp_element_mangling:(disable_xhp_element_mangling co) + ~disallow_hash_comments:(disallow_hash_comments co) ~filename ~text |> Option.value ~default:""); diff --git a/hphp/hack/src/server/serverRpc.ml b/hphp/hack/src/server/serverRpc.ml index 37d3fc505bb..7229ade62d7 100644 --- a/hphp/hack/src/server/serverRpc.ml +++ b/hphp/hack/src/server/serverRpc.ml @@ -192,6 +192,7 @@ let handle : type a. genv -> env -> is_stale:bool -> a t -> env * a = ~disable_legacy_attribute_syntax:false ~enable_xhp_class_modifier:false ~disable_xhp_element_mangling:false + ~disallow_hash_comments:true ~filename:Relative_path.default ~text:contents in diff --git a/hphp/hack/test/rust/facts_parse.rs b/hphp/hack/test/rust/facts_parse.rs index c162ab40809..2881e0af866 100644 --- a/hphp/hack/test/rust/facts_parse.rs +++ b/hphp/hack/test/rust/facts_parse.rs @@ -42,6 +42,7 @@ fn parse(file_path: String, parse_only: bool) { allow_new_attribute_syntax: false, enable_xhp_class_modifier: false, disable_xhp_element_mangling: false, + disallow_hash_comments: true, filename: path, }; -- 2.11.4.GIT