From 0cbd61d1d7509738c8a9b294c4f96bbbcc198e64 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Wed, 26 Feb 2025 16:33:19 -0800 Subject: [PATCH] [flow] Rollback ability to create userland react module typing and kill unreleased declare global support Summary: Unfortunately, the userland typing for the react module has caused too many reliability issues, so this diff rolls back all the risky part of the changes, including - declare global support - making every module depend on react: for places where we do the `Context.find_require` lookup, we now change it to just builtin lookup. This means we cannot completely ban override. However, it's less of an issue for multiplatform work, since the override we really need to ban is a directory-scoped overriding the builtin + common libdefs. We should still issue errors on these overrides to prevent surprises. Changelog: [internal] The ability to have userland React module type definition is never announced. Reviewed By: gkz Differential Revision: D70270290 fbshipit-source-id: 54212086b31b3f4bd907d0ba8fd2d841a8931e33 --- src/analysis/env_builder/name_resolver.ml | 51 ++------- src/analysis/scope_builder.ml | 40 +------ src/codemods/annotate_exports.ml | 1 - src/commands/commandUtils.ml | 1 - src/commands/config/flowConfig.ml | 7 -- src/commands/config/flowConfig.mli | 2 - src/common/options.ml | 3 - src/flow_dot_js.ml | 2 - src/parser_utils/__tests__/file_sig_test.ml | 76 ++++++------- .../exports/__tests__/exports_tests.ml | 1 - src/parser_utils/file_sig.ml | 1 - .../type_sig/__tests__/type_sig_tests.ml | 76 ------------- src/parser_utils/type_sig/type_sig_options.ml | 3 - src/parser_utils/type_sig/type_sig_parse.ml | 54 +-------- .../__tests__/refactor_extract_utils_tests.ml | 15 ++- src/services/inference/check_service.ml | 55 ++------- src/typing/__tests__/type_hint_test.ml | 2 - src/typing/__tests__/typed_ast_test.ml | 1 - src/typing/context.ml | 4 - src/typing/context.mli | 3 - src/typing/flow_js_utils.ml | 27 ++--- src/typing/statement.ml | 13 +-- .../.flowconfig | 7 -- ...declare_global_in_react_declare_module.exp | 89 --------------- .../react.js | 19 ---- .../test.js | 9 -- .../.flowconfig | 4 - .../@flowtyped/react.js.flow | 17 --- .../declare_global_in_react_module.exp | 104 ------------------ tests/declare_global_in_react_module/test.js | 9 -- .../test_no_explicit_react_import.js | 1 - .../saved_state_userland_react_lib.exp | 2 +- 32 files changed, 84 insertions(+), 615 deletions(-) delete mode 100644 tests/declare_global_in_react_declare_module/.flowconfig delete mode 100644 tests/declare_global_in_react_declare_module/declare_global_in_react_declare_module.exp delete mode 100644 tests/declare_global_in_react_declare_module/react.js delete mode 100644 tests/declare_global_in_react_declare_module/test.js delete mode 100644 tests/declare_global_in_react_module/.flowconfig delete mode 100644 tests/declare_global_in_react_module/@flowtyped/react.js.flow delete mode 100644 tests/declare_global_in_react_module/declare_global_in_react_module.exp delete mode 100644 tests/declare_global_in_react_module/test.js delete mode 100644 tests/declare_global_in_react_module/test_no_explicit_react_import.js diff --git a/src/analysis/env_builder/name_resolver.ml b/src/analysis/env_builder/name_resolver.ml index 109b067fdca..40c33ad6727 100644 --- a/src/analysis/env_builder/name_resolver.ml +++ b/src/analysis/env_builder/name_resolver.ml @@ -6400,51 +6400,18 @@ module Make (Context : C) (FlowAPIUtils : F with type cx = Context.t) : let v = val_simplify def_loc (Val.SourceLevelBinding kind) (Some name) v in v - method! declare_module loc ({ Ast.Statement.DeclareModule.id = _; body; _ } as m) = + method! declare_module _loc ({ Ast.Statement.DeclareModule.id = _; body; _ } as m) = let (block_loc, { Ast.Statement.Block.body = statements; comments = _ }) = body in - let within_possible_declare_globals ~f = - let declare_global_bodies = - Base.List.filter_map statements ~f:(function - | ( _, - Ast.Statement.DeclareNamespace - { - Ast.Statement.DeclareNamespace.id = Ast.Statement.DeclareNamespace.Global _; - body; - comments = _; - } - ) -> - Some body - | _ -> None - ) + let bindings = + let hoist = + new Hoister.hoister ~flowmin_compatibility:false ~enable_enums ~with_types:true in - if Base.List.is_empty declare_global_bodies then - f () - else - let hoist = new hoister ~flowmin_compatibility:false ~enable_enums ~with_types:true in - Base.List.iter declare_global_bodies ~f:(fun (loc, body) -> - Flow_ast_visitor.run (hoist#block loc) body - ); - let global_bindings = hoist#acc in - this#with_bindings loc global_bindings (fun () -> - Base.List.iter declare_global_bodies ~f:(fun (loc, body) -> - Flow_ast_visitor.run (this#block loc) body - ); - f () - ); - () + hoist#eval hoist#statement_list statements in - within_possible_declare_globals ~f:(fun () -> - let bindings = - let hoist = - new Hoister.hoister ~flowmin_compatibility:false ~enable_enums ~with_types:true - in - hoist#eval hoist#statement_list statements - in - let saved_exclude_syms = env_state.exclude_syms in - env_state <- { env_state with exclude_syms = SSet.empty }; - ignore @@ this#statements_with_bindings block_loc bindings statements; - env_state <- { env_state with exclude_syms = saved_exclude_syms } - ); + let saved_exclude_syms = env_state.exclude_syms in + env_state <- { env_state with exclude_syms = SSet.empty }; + ignore @@ this#statements_with_bindings block_loc bindings statements; + env_state <- { env_state with exclude_syms = saved_exclude_syms }; m method! declare_namespace loc ({ Ast.Statement.DeclareNamespace.id; body; _ } as m) = diff --git a/src/analysis/scope_builder.ml b/src/analysis/scope_builder.ml index 628a8d9ecac..e909ba473ad 100644 --- a/src/analysis/scope_builder.ml +++ b/src/analysis/scope_builder.ml @@ -574,42 +574,12 @@ module Make (L : Loc_sig.S) (Api : Scope_api_sig.S with module L = L) : let open Ast.Statement.DeclareModule in let { id = _; body; comments = _ } = m in let (loc, body) = body in - let within_possible_declare_globals ~f = - let declare_global_bodies = - Base.List.filter_map body.Ast.Statement.Block.body ~f:(function - | ( _, - Ast.Statement.DeclareNamespace - { - Ast.Statement.DeclareNamespace.id = Ast.Statement.DeclareNamespace.Global _; - body; - comments = _; - } - ) -> - Some body - | _ -> None - ) - in - if Base.List.is_empty declare_global_bodies then - f () - else - let hoist = new hoister ~flowmin_compatibility ~enable_enums ~with_types in - Base.List.iter declare_global_bodies ~f:(fun (loc, body) -> run (hoist#block loc) body); - let global_bindings = hoist#acc in - this#with_bindings loc global_bindings (fun () -> - Base.List.iter declare_global_bodies ~f:(fun (loc, body) -> - run (this#block loc) body - ); - f () - ) + let bindings = + let hoist = new hoister ~flowmin_compatibility ~enable_enums ~with_types in + run (hoist#block loc) body; + hoist#acc in - within_possible_declare_globals ~f:(fun () -> - let bindings = - let hoist = new hoister ~flowmin_compatibility ~enable_enums ~with_types in - run (hoist#block loc) body; - hoist#acc - in - this#with_bindings loc bindings (fun () -> run (this#block loc) body) - ); + this#with_bindings loc bindings (fun () -> run (this#block loc) body); m method! declare_namespace _loc n = diff --git a/src/codemods/annotate_exports.ml b/src/codemods/annotate_exports.ml index 17e6b35e651..4abadf99a8d 100644 --- a/src/codemods/annotate_exports.ml +++ b/src/codemods/annotate_exports.ml @@ -70,7 +70,6 @@ module SignatureVerification = struct facebook_fbt = Options.facebook_fbt options; max_literal_len = Options.max_literal_length options; exact_by_default = Options.exact_by_default options; - enable_declare_global = Options.enable_declare_global options; enable_enums = Options.enums options; enable_component_syntax = Options.typecheck_component_syntax_in_file options file; component_syntax_enabled_in_config = Options.component_syntax options; diff --git a/src/commands/commandUtils.ml b/src/commands/commandUtils.ml index a3bdeecf5d8..7473cb83b5b 100644 --- a/src/commands/commandUtils.ml +++ b/src/commands/commandUtils.ml @@ -1411,7 +1411,6 @@ let make_options FlowConfig.dev_only_refinement_info_as_errors flowconfig; opt_enable_const_params = Base.Option.value (FlowConfig.enable_const_params flowconfig) ~default:false; - opt_enable_declare_global = FlowConfig.enable_declare_global flowconfig; opt_enable_jest_integration = FlowConfig.jest_integration flowconfig; opt_enable_pattern_matching = Base.Option.value ~default:false (FlowConfig.pattern_matching flowconfig); diff --git a/src/commands/config/flowConfig.ml b/src/commands/config/flowConfig.ml index 71f718e5149..454bb6820f7 100644 --- a/src/commands/config/flowConfig.ml +++ b/src/commands/config/flowConfig.ml @@ -57,7 +57,6 @@ module Opts = struct dev_only_refinement_info_as_errors: bool; emoji: bool option; enable_const_params: bool option; - enable_declare_global: bool; enums: bool; estimate_recheck_time: bool option; exact_by_default: bool option; @@ -194,7 +193,6 @@ module Opts = struct dev_only_refinement_info_as_errors = false; emoji = None; enable_const_params = None; - enable_declare_global = false; enums = false; estimate_recheck_time = None; exact_by_default = None; @@ -1029,9 +1027,6 @@ module Opts = struct ( "experimental.component_syntax.hooklike_functions.excludes", hook_compatibility_excludes_parser ); - ( "experimental.declare_global", - boolean (fun opts v -> Ok { opts with enable_declare_global = v }) - ); ("this_type_guards", boolean (fun opts v -> Ok { opts with this_type_guards = v })); ("experimental.facebook_module_interop", facebook_module_interop_parser); ("experimental.channel_mode", channel_mode_parser ~enabled:true); @@ -1745,8 +1740,6 @@ let emoji c = c.options.Opts.emoji let enable_const_params c = c.options.Opts.enable_const_params -let enable_declare_global c = c.options.Opts.enable_declare_global - let enums c = c.options.Opts.enums let estimate_recheck_time c = c.options.Opts.estimate_recheck_time diff --git a/src/commands/config/flowConfig.mli b/src/commands/config/flowConfig.mli index f305085546d..a6b3a171885 100644 --- a/src/commands/config/flowConfig.mli +++ b/src/commands/config/flowConfig.mli @@ -92,8 +92,6 @@ val emoji : config -> bool option val enable_const_params : config -> bool option -val enable_declare_global : config -> bool - val enums : config -> bool val estimate_recheck_time : config -> bool option diff --git a/src/common/options.ml b/src/common/options.ml index 76667b89dd2..94865cf973e 100644 --- a/src/common/options.ml +++ b/src/common/options.ml @@ -88,7 +88,6 @@ type t = { opt_debug: bool; opt_dev_only_refinement_info_as_errors: bool; opt_enable_const_params: bool; - opt_enable_declare_global: bool; opt_enable_jest_integration: bool; opt_enable_pattern_matching: bool; opt_enable_relay_integration: bool; @@ -223,8 +222,6 @@ let dev_only_refinement_info_as_errors opts = opts.opt_dev_only_refinement_info_ let enable_const_params opts = opts.opt_enable_const_params -let enable_declare_global opts = opts.opt_enable_declare_global - let enable_jest_integration opts = opts.opt_enable_jest_integration let enable_pattern_matching opts = opts.opt_enable_pattern_matching diff --git a/src/flow_dot_js.ml b/src/flow_dot_js.ml index 47038a12889..842739b26d0 100644 --- a/src/flow_dot_js.ml +++ b/src/flow_dot_js.ml @@ -73,7 +73,6 @@ let load_lib_files files = facebook_fbt = None; max_literal_len = 100; exact_by_default = true; - enable_declare_global = false; enable_enums = true; enable_component_syntax = true; component_syntax_enabled_in_config = true; @@ -112,7 +111,6 @@ let stub_metadata ~root ~checked = react_rules_always = false; dev_only_refinement_info_as_errors = false; enable_const_params = false; - enable_declare_global = false; enable_enums = true; enable_jest_integration = false; enable_pattern_matching = true; diff --git a/src/parser_utils/__tests__/file_sig_test.ml b/src/parser_utils/__tests__/file_sig_test.ml index 0caeac502dc..63afb4ecbe1 100644 --- a/src/parser_utils/__tests__/file_sig_test.ml +++ b/src/parser_utils/__tests__/file_sig_test.ml @@ -54,20 +54,12 @@ let assert_substrings_equal ~ctxt expected_remote expected_local source { remote assert_substring_equal ~ctxt expected_remote source remote_loc; assert_substring_equal ~ctxt expected_local source local_loc -let requires_without_implicit_react_import file_sig = - file_sig - |> File_sig.requires - |> List.filter (function - | ImportSynthetic { source = "react" } -> false - | _ -> true - ) - let tests = "require" >::: [ ( "cjs_require" >:: fun ctxt -> let source = "const Foo = require('foo')" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [ Require @@ -85,7 +77,7 @@ let tests = ); ( "cjs_deep_requires" >:: fun ctxt -> let source = "let foo = {x: require('bar')}; func(foo, require('baz'));" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [ Require @@ -101,7 +93,7 @@ let tests = ); ( "cjs_deep_requires_plus_bindings" >:: fun ctxt -> let source = "const Foo = require('foo'); func(Foo, require('bar'));" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [ Require @@ -123,7 +115,7 @@ let tests = ); ( "cjs_require_template_literal" >:: fun ctxt -> let source = "const Foo = require(`foo`)" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [ Require @@ -141,7 +133,7 @@ let tests = ); ( "cjs_require_named" >:: fun ctxt -> let source = "const {foo, bar: baz} = require('foo');" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [ Require @@ -173,7 +165,7 @@ let tests = ); ( "cjs_require_duplicate_remote" >:: fun ctxt -> let source = "const {foo: bar, foo: baz} = require('foo');" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [ Require @@ -204,7 +196,7 @@ let tests = ); ( "cjs_require_duplicate_local" >:: fun ctxt -> let source = "const {foo: bar, baz: bar} = require('foo');" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [ Require @@ -231,7 +223,7 @@ let tests = (* An initial version of the change to ban non-toplevel exports failed to descend into the RHS * of export statements *) let source = "module.exports.foo = require('foo');" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Require { source = (source_loc, "foo"); require_loc; bindings = None; prefix = _ }] -> assert_substring_equal ~ctxt "'foo'" source source_loc; @@ -240,7 +232,7 @@ let tests = ); ( "cjs_require_typeapp" >:: fun _ctxt -> let source = "const Foo = require('foo')" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [] -> () | _ -> assert_failure "Unexpected requires" @@ -250,7 +242,7 @@ let tests = let parse_options = { Parser_env.default_parse_options with Parser_env.module_ref_prefix = Some "m#" } in - let requires = visit source ~parse_options |> requires_without_implicit_react_import in + let requires = visit source ~parse_options |> File_sig.requires in match requires with | [Require { source = (source_loc, "foo"); require_loc; bindings = _; prefix }] -> assert_substring_equal ~ctxt "'m#foo'" source source_loc; @@ -262,7 +254,7 @@ let tests = let source = "graphql`query foo {}`" in let requires = visit source ~opts:{ default_opts with enable_relay_integration = true } - |> requires_without_implicit_react_import + |> File_sig.requires in match requires with | [Require { source = (source_loc, "foo.graphql"); require_loc; _ }] -> @@ -281,7 +273,7 @@ let tests = enable_relay_integration = true; relay_integration_module_prefix = Some "./__generated__/"; } - |> requires_without_implicit_react_import + |> File_sig.requires in match requires with | [Require { source = (source_loc, "./__generated__/foo.graphql"); require_loc; _ }] -> @@ -291,7 +283,7 @@ let tests = ); ( "dynamic_import" >:: fun ctxt -> let source = "import('foo')" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [ImportDynamic { source = (source_loc, "foo"); import_loc }] -> assert_substring_equal ~ctxt "'foo'" source source_loc; @@ -300,7 +292,7 @@ let tests = ); ( "dynamic_import_template_literal" >:: fun ctxt -> let source = "import(`foo`)" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [ImportDynamic { source = (source_loc, "foo"); import_loc }] -> assert_substring_equal ~ctxt "`foo`" source source_loc; @@ -309,14 +301,14 @@ let tests = ); ( "es_import" >:: fun ctxt -> let source = "import 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import0 { source = (loc, "foo") }] -> assert_substring_equal ~ctxt "'foo'" source loc | _ -> assert_failure "Unexpected requires" ); ( "es_import_default" >:: fun ctxt -> let source = "import Foo from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); named; _ }] -> named @@ -328,7 +320,7 @@ let tests = ); ( "es_import_named" >:: fun ctxt -> let source = "import {A} from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); named; _ }] -> named @@ -340,7 +332,7 @@ let tests = ); ( "es_import_renamed" >:: fun ctxt -> let source = "import {A as B} from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); named; _ }] -> named @@ -352,7 +344,7 @@ let tests = ); ( "es_import_named_type" >:: fun ctxt -> let source = "import {type A} from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); types; _ }] -> types @@ -364,7 +356,7 @@ let tests = ); ( "es_import_named_typeof" >:: fun ctxt -> let source = "import {typeof A} from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); typesof; _ }] -> typesof @@ -376,7 +368,7 @@ let tests = ); ( "es_import_ns" >:: fun ctxt -> let source = "import * as Foo from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); ns = Some (loc, "Foo"); _ }] -> assert_substring_equal ~ctxt "Foo" source loc @@ -384,7 +376,7 @@ let tests = ); ( "es_import_type" >:: fun ctxt -> let source = "import type A from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); types; _ }] -> types @@ -396,7 +388,7 @@ let tests = ); ( "es_import_type_named" >:: fun ctxt -> let source = "import type {A} from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); types; _ }] -> types @@ -408,7 +400,7 @@ let tests = ); ( "es_import_type_renamed" >:: fun ctxt -> let source = "import type {A as B} from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); types; _ }] -> types @@ -420,7 +412,7 @@ let tests = ); ( "es_import_typeof" >:: fun ctxt -> let source = "import typeof A from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); typesof; _ }] -> typesof @@ -432,7 +424,7 @@ let tests = ); ( "es_import_typeof_named" >:: fun ctxt -> let source = "import typeof {A} from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); typesof; _ }] -> typesof @@ -444,7 +436,7 @@ let tests = ); ( "es_import_typeof_renamed" >:: fun ctxt -> let source = "import typeof {A as B} from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); typesof; _ }] -> typesof @@ -456,7 +448,7 @@ let tests = ); ( "es_import_typesof_ns" >:: fun ctxt -> let source = "import typeof * as Foo from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); typesof_ns = Some (loc, "Foo"); _ }] -> assert_substring_equal ~ctxt "Foo" source loc @@ -464,7 +456,7 @@ let tests = ); ( "es_import_type_ns" >:: fun ctxt -> let source = "import type * as Foo from 'foo'" in - let requires = visit source |> requires_without_implicit_react_import in + let requires = visit source |> File_sig.requires in match requires with | [Import { source = (_, "foo"); ns; typesof_ns; _ }] -> assert_equal ~ctxt None ns; @@ -474,7 +466,7 @@ let tests = ( "export_star" >:: fun ctxt -> let source = "export * from 'foo'" in let file_sig = visit source in - let requires = requires_without_implicit_react_import file_sig in + let requires = File_sig.requires file_sig in match requires with | [ExportFrom { source = (source_loc, "foo") }] -> assert_substring_equal ~ctxt "'foo'" source source_loc @@ -483,7 +475,7 @@ let tests = ( "export_type_star" >:: fun ctxt -> let source = "export type * from 'foo'" in let file_sig = visit source in - let requires = requires_without_implicit_react_import file_sig in + let requires = File_sig.requires file_sig in match requires with | [ExportFrom { source = (source_loc, "foo") }] -> assert_substring_equal ~ctxt "'foo'" source source_loc @@ -493,7 +485,7 @@ let tests = let source = "export * as ns from 'foo'" in let parse_options = Parser_env.default_parse_options in let file_sig = visit ~parse_options source in - let requires = requires_without_implicit_react_import file_sig in + let requires = File_sig.requires file_sig in match requires with | [ExportFrom { source = (source_loc, "foo") }] -> assert_substring_equal ~ctxt "'foo'" source source_loc @@ -502,7 +494,7 @@ let tests = ( "declare_export_star" >:: fun ctxt -> let source = "declare export * from 'foo'" in let file_sig = visit source in - let requires = requires_without_implicit_react_import file_sig in + let requires = File_sig.requires file_sig in match requires with | [ExportFrom { source = (source_loc, "foo") }] -> assert_substring_equal ~ctxt "'foo'" source source_loc @@ -512,7 +504,7 @@ let tests = let source = "declare export * as ns from 'foo'" in let parse_options = Parser_env.default_parse_options in let file_sig = visit ~parse_options source in - let requires = requires_without_implicit_react_import file_sig in + let requires = File_sig.requires file_sig in match requires with | [ExportFrom { source = (source_loc, "foo") }] -> assert_substring_equal ~ctxt "'foo'" source source_loc diff --git a/src/parser_utils/exports/__tests__/exports_tests.ml b/src/parser_utils/exports/__tests__/exports_tests.ml index 381a09f6bb0..c289539e6a9 100644 --- a/src/parser_utils/exports/__tests__/exports_tests.ml +++ b/src/parser_utils/exports/__tests__/exports_tests.ml @@ -55,7 +55,6 @@ let sig_opts = facebook_fbt = None; max_literal_len = 100; exact_by_default = true; - enable_declare_global = true; enable_enums = true; enable_component_syntax = true; component_syntax_enabled_in_config = true; diff --git a/src/parser_utils/file_sig.ml b/src/parser_utils/file_sig.ml index fc5f044037c..8cde5c0f615 100644 --- a/src/parser_utils/file_sig.ml +++ b/src/parser_utils/file_sig.ml @@ -539,7 +539,6 @@ class requires_calculator ~file_key ~ast ~opts = let program ~file_key ~ast ~opts = let walk = new requires_calculator ~file_key ~ast ~opts in - walk#add_require (ImportSynthetic { source = "react" }); (match file_key with | File_key.LibFile _ -> () | _ -> diff --git a/src/parser_utils/type_sig/__tests__/type_sig_tests.ml b/src/parser_utils/type_sig/__tests__/type_sig_tests.ml index f39fecd07ac..64f300a11bc 100644 --- a/src/parser_utils/type_sig/__tests__/type_sig_tests.ml +++ b/src/parser_utils/type_sig/__tests__/type_sig_tests.ml @@ -213,7 +213,6 @@ let sig_options ?facebook_fbt ?(max_literal_len = 100) ?(exact_by_default = false) - ?(enable_declare_global = true) ?(enable_enums = true) ?(enable_component_syntax = true) ?(enable_ts_syntax = true) @@ -231,7 +230,6 @@ let sig_options facebook_fbt; max_literal_len; exact_by_default; - enable_declare_global; enable_enums; enable_component_syntax; component_syntax_enabled_in_config = true; @@ -4916,80 +4914,6 @@ let%expect_test "builtin_cjs_module_used_type_exported" = module_globals = ModuleGlobals {global_types = [||]; global_types_keys = [||]}; strict = true; platform_availability_set = None}} |}] -let%expect_test "declare_global_within_declare_module" = -print_builtins [{| - declare module foo { - declare global { - type Foo = string; - type Bar = Foo; - } - type Bar = number; - type Baz = number; - declare const baz: [Foo, Bar, Baz]; - declare global { - type Foo = string; - } - } - |}]; - [%expect {| - Local defs: - 0. TypeAlias {id_loc = [3:9-12]; - name = "Foo"; tparams = Mono; - body = (Annot (String [3:15-21]))} - 1. TypeAlias {id_loc = [4:9-12]; - name = "Bar"; tparams = Mono; - body = (TyRef (Unqualified LocalRef {ref_loc = [4:15-18]; index = 0}))} - 2. TypeAlias {id_loc = [6:7-10]; - name = "Bar"; tparams = Mono; - body = (Annot (Number [6:13-19]))} - 3. TypeAlias {id_loc = [7:7-10]; - name = "Baz"; tparams = Mono; - body = (Annot (Number [7:13-19]))} - 4. Variable {id_loc = [8:16-19]; - name = "baz"; - def = - (Annot - Tuple {loc = [8:21-36]; - elems_rev = - [TupleElement {loc = [8:32-35]; - name = None; t = (TyRef (Unqualified LocalRef {ref_loc = [8:32-35]; index = 3})); - polarity = Polarity.Neutral; - optional = false}; - TupleElement {loc = [8:27-30]; - name = None; t = (TyRef (Unqualified LocalRef {ref_loc = [8:27-30]; index = 2})); - polarity = Polarity.Neutral; - optional = false}; - TupleElement {loc = [8:22-25]; - name = None; t = (TyRef (Unqualified LocalRef {ref_loc = [8:22-25]; index = 0})); - polarity = Polarity.Neutral; - optional = false} - ]; - inexact = false})} - 5. NamespaceBinding {id_loc = [0:0]; - name = "globalThis"; - values = { "globalThis" -> ([0:0], (Ref LocalRef {ref_loc = [0:0]; index = 5})) }; - types = {}} - - Builtin global value globalThis - Builtin module foo: - [1:15-18] CJSModule {type_exports = [|(ExportTypeBinding 2); (ExportTypeBinding 3)|]; - exports = - (Some (Value - DeclareModuleImplicitlyExportedObject { - loc = [1:15-18]; - module_name = "foo"; - props = - { "baz" -> - (ObjValueField ([1:15-18], - (Ref LocalRef {ref_loc = [1:15-18]; index = 4}), Polarity.Positive - )) }})); - info = - CJSModuleInfo {type_export_keys = [|"Bar"; "Baz"|]; - type_stars = []; - module_globals = - ModuleGlobals {global_types = [|1; 0|]; global_types_keys = [|"Bar"; "Foo"|]}; - strict = true; platform_availability_set = None}} |}] - let%expect_test "builtin_cjs_module_with_implicit_exports" = (* when a `declare module` doesn't have explicit value exports via `declare export` (which makes it an ES module) or `declare module.exports = ...` (which makes it a CJS module), diff --git a/src/parser_utils/type_sig/type_sig_options.ml b/src/parser_utils/type_sig/type_sig_options.ml index 2b4cd1bb943..20780e91c26 100644 --- a/src/parser_utils/type_sig/type_sig_options.ml +++ b/src/parser_utils/type_sig/type_sig_options.ml @@ -12,7 +12,6 @@ type t = { facebook_fbt: string option; max_literal_len: int; exact_by_default: bool; - enable_declare_global: bool; enable_enums: bool; enable_component_syntax: bool; component_syntax_enabled_in_config: bool; @@ -57,7 +56,6 @@ let of_options options docblock locs_to_dirtify file = facebook_fbt = Options.facebook_fbt options; max_literal_len = Options.max_literal_length options; exact_by_default = Options.exact_by_default options; - enable_declare_global = Options.enable_declare_global options; enable_enums = Options.enums options; enable_component_syntax = Options.typecheck_component_syntax_in_file options file; component_syntax_enabled_in_config = Options.component_syntax options; @@ -82,7 +80,6 @@ let builtin_options options = exact_by_default = Options.exact_by_default options; enable_enums = Options.enums options; enable_component_syntax = true; - enable_declare_global = Options.enable_declare_global options; component_syntax_enabled_in_config = Options.component_syntax options; enable_ts_syntax = false; hook_compatibility = Options.hook_compatibility options; diff --git a/src/parser_utils/type_sig/type_sig_parse.ml b/src/parser_utils/type_sig/type_sig_parse.ml index a62080fcd11..3d75ba93274 100644 --- a/src/parser_utils/type_sig/type_sig_parse.ml +++ b/src/parser_utils/type_sig/type_sig_parse.ml @@ -156,7 +156,6 @@ and 'loc scope = mutable types: 'loc binding_node SMap.t; exports: 'loc exports; } - | DeclareGlobal of { parent: 'loc scope } | Lexical of { mutable values: 'loc binding_node SMap.t; mutable types: 'loc binding_node SMap.t; @@ -538,8 +537,7 @@ module Scope = struct | DeclareModule { parent; _ } | Lexical { parent; _ } | ConditionalTypeExtends { parent; _ } - | DeclareNamespace { parent; _ } - | DeclareGlobal { parent } -> + | DeclareNamespace { parent; _ } -> Some parent | Global _ | Module _ -> @@ -548,7 +546,6 @@ module Scope = struct let modify_exports f = function | Module scope -> f scope.exports | DeclareModule scope -> f scope.exports - | DeclareGlobal _ | DeclareNamespace _ | Global _ | Lexical _ @@ -559,7 +556,6 @@ module Scope = struct | Global { values; types; modules } -> (values, types, modules) | DeclareModule _ | DeclareNamespace _ - | DeclareGlobal _ | Module _ | Lexical _ | ConditionalTypeExtends _ -> @@ -570,7 +566,6 @@ module Scope = struct | Global _ | DeclareModule _ | DeclareNamespace _ - | DeclareGlobal _ | Lexical _ | ConditionalTypeExtends _ -> raise Not_found @@ -635,11 +630,6 @@ module Scope = struct | Global scope -> scope.types <- bind_type scope.values scope.types | DeclareModule scope -> scope.types <- bind_type scope.values scope.types | DeclareNamespace scope -> scope.types <- bind_type scope.values scope.types - | DeclareGlobal { parent = DeclareModule { exports; _ } | Module { exports; _ } } -> - let (Exports e) = exports in - e.global_types <- bind_type SMap.empty e.global_types - | DeclareGlobal { parent = _ } -> - failwith "DeclareGlobal can only have DeclareModule or Module as parent." | Module scope -> scope.types <- bind_type scope.values scope.types | Lexical scope -> scope.types <- bind_type scope.values scope.types | ConditionalTypeExtends _ -> () @@ -648,8 +638,6 @@ module Scope = struct | Global scope -> scope.values <- bind_value scope.values scope.types | DeclareModule scope -> scope.values <- bind_value scope.values scope.types | DeclareNamespace scope -> scope.values <- bind_value scope.values scope.types - (* Only type_only bindings are allowed in declare global *) - | DeclareGlobal { parent = _ } -> () | Module scope -> scope.values <- bind_value scope.values scope.types | Lexical scope -> scope.values <- bind_value scope.values scope.types | ConditionalTypeExtends _ -> () @@ -666,7 +654,6 @@ module Scope = struct (match SMap.find_opt name values with | Some binding -> Some (binding, scope) | None -> lookup_value parent name) - | DeclareGlobal { parent } -> lookup_value parent name let rec lookup_type scope name = let lookup_scope name values types = @@ -696,21 +683,13 @@ module Scope = struct (match lookup_scope name SMap.empty global_types with | Some binding -> Some (binding, scope) | None -> lookup_type parent name)) - | DeclareGlobal { parent = (DeclareModule { exports; _ } | Module { exports; _ }) as parent } -> - let (Exports { global_types; _ }) = exports in - (match lookup_scope name SMap.empty global_types with - | Some binding -> Some (binding, scope) - | None -> lookup_type parent name) - | DeclareGlobal { parent = _ } -> - failwith "DeclareGlobal can only have DeclareModule or Module as parent." let rec find_host scope b = match scope with | Global _ | DeclareModule _ | DeclareNamespace _ - | Module _ - | DeclareGlobal _ -> + | Module _ -> scope | ConditionalTypeExtends { parent; _ } -> find_host parent b | Lexical { parent; _ } -> @@ -724,8 +703,7 @@ module Scope = struct | Global _ | DeclareModule _ | DeclareNamespace _ - | Module _ - | DeclareGlobal _ -> + | Module _ -> None | Lexical { parent; _ } -> scope_of_infer_name parent name loc | ConditionalTypeExtends ({ infer_type_names; _ } as scope) -> @@ -1051,7 +1029,6 @@ module Scope = struct (* is already the right kind? shouldn't happen *) failwith "only call finalize_declare_module_exports_exn once per DeclareModule") | DeclareNamespace _ - | DeclareGlobal _ | Global _ | Module _ | Lexical _ @@ -1125,16 +1102,6 @@ module Scope = struct (NamespaceBinding { id_loc; name; values; types }) | _ -> failwith "The scope must be lexical" - let within_declare_global scope ~f = - match scope with - | Module _ -> - let scope = DeclareGlobal { parent = scope } in - f scope - | DeclareModule _ -> - let scope = DeclareGlobal { parent = scope } in - f scope - | _ -> () - let bind_globalThis scope tbls ~global_this_loc = match scope with | Global global_scope -> @@ -4205,20 +4172,7 @@ let namespace_decl comments = _; } = match id with - | Ast.Statement.DeclareNamespace.Global _ -> - if opts.enable_declare_global then - Scope.within_declare_global scope ~f:(fun scope -> - let stmts = - Base.List.filter stmts ~f:(fun (_, stmt) -> - Flow_ast_utils.acceptable_statement_in_declaration_context - ~in_declare_namespace:true - stmt - |> Base.Result.is_ok - ) - in - List.iter (visit_statement opts scope tbls) stmts - ); - ignore + | Ast.Statement.DeclareNamespace.Global _ -> ignore | Ast.Statement.DeclareNamespace.Local (id_loc, { Ast.Identifier.name; _ }) -> let id_loc = push_loc tbls id_loc in let stmts = diff --git a/src/services/code_action/__tests__/refactor_extract_utils_tests.ml b/src/services/code_action/__tests__/refactor_extract_utils_tests.ml index 6495271e16c..1758a6d9697 100644 --- a/src/services/code_action/__tests__/refactor_extract_utils_tests.ml +++ b/src/services/code_action/__tests__/refactor_extract_utils_tests.ml @@ -10,10 +10,6 @@ open Ast_extraction_utils open Refactor_extract_utils open Loc_collections -let parse contents = - let (ast, _) = Parser_flow.program contents in - ast - let pretty_print layout = let source = Pretty_printer.print ~source_maps:None ~skip_endline:true layout in Source.contents source @@ -44,7 +40,6 @@ let stub_metadata ~root ~checked = react_rules_always = false; dev_only_refinement_info_as_errors = false; enable_const_params = false; - enable_declare_global = true; enable_enums = true; enable_jest_integration = false; enable_pattern_matching = false; @@ -80,8 +75,14 @@ let stub_metadata ~root ~checked = let dummy_filename = File_key.SourceFile "" +let parse contents = + let (ast, _) = Parser_flow.program_file contents (Some dummy_filename) in + ast + let file_sig_of_ast ast = File_sig.program ~file_key:dummy_filename ~ast ~opts:File_sig.default_opts +let mk_loc = Loc.mk_loc ~source:dummy_filename + let dummy_context () = let root = File_path.dummy_path in let reason = @@ -165,14 +166,12 @@ let typed_ast_of_ast cx ast = comments aloc_ast -let mk_loc = Loc.mk_loc - let extract_tests = let assert_extracted ~ctxt ?expected_statements ?expected_expression ?expected_type source extract_range = let ast = parse source in let parse_options = Parser_env.default_parse_options in - let tokens = AstExtractor.tokens ~parse_options None source in + let tokens = AstExtractor.tokens ~parse_options (Some dummy_filename) source in let { AstExtractor.extracted_statements; extracted_expression; extracted_type } = AstExtractor.extract tokens ast extract_range in diff --git a/src/services/inference/check_service.ml b/src/services/inference/check_service.ml index 8229a88609b..3b5eaeaff74 100644 --- a/src/services/inference/check_service.ml +++ b/src/services/inference/check_service.ml @@ -324,52 +324,17 @@ let mk_check_file ~reader ~options ~master_cx ~cache () = let rec file_rec = lazy - ( extend_local_globals cx ~resolved_requires:!resolved_requires; - { - Type_sig_merge.cx; - dependencies; - exports = exports file_rec; - local_defs = local_defs file_rec; - remote_refs = remote_refs file_rec; - pattern_defs = pattern_defs file_rec; - patterns = patterns file_rec; - } - ) + { + Type_sig_merge.cx; + dependencies; + exports = exports file_rec; + local_defs = local_defs file_rec; + remote_refs = remote_refs file_rec; + pattern_defs = pattern_defs file_rec; + patterns = patterns file_rec; + } in Lazy.force file_rec - and extend_local_globals cx ~resolved_requires = - if Context.enable_declare_global cx && not (File_key.is_lib_file (Context.file cx)) then - let local_builtins = - lazy - (let global_types = - (* For now, we limit the effect of global-modifying after import to react only, - * since doing it for all modules, especially cyclic ones, can trigger infinite - * recursion. *) - match SMap.find_opt "react" resolved_requires with - | None -> SMap.empty - | Some m -> - (match Lazy.force m with - | Context.UncheckedModule _ -> SMap.empty - | Context.MissingModule _ -> SMap.empty - | Context.TypedModule f -> - (match f () with - | Error _ -> SMap.empty - | Ok { Type.module_global_types_tmap = module_global_types; _ } -> - (* Since we are only getting extra globals from one module, - * we don't need to worry about globals from different modules overlap. *) - module_global_types)) - in - Builtins.of_name_map - ~type_mapper:Base.Fn.id - ~module_type_mapper:Base.Fn.id - ~values:SMap.empty - ~types:global_types - ~modules:SMap.empty - ) - in - Context.extend_local_builtins cx local_builtins - else - () in let check_file file_key resolved_modules ast file_sig docblock aloc_table find_ref_request = let (_, { Flow_ast.Program.all_comments = comments; _ }) = ast in @@ -381,7 +346,6 @@ let mk_check_file ~reader ~options ~master_cx ~cache () = let cx = Context.make ccx metadata file_key aloc_table resolve_require mk_builtins in resolved_requires := SMap.mapi (dep_module_t cx) resolved_modules; ConsGen.set_dst_cx cx; - extend_local_globals cx ~resolved_requires:(SMap.map Lazy.from_val !resolved_requires); let (typed_ast, obj_to_obj_map) = Obj_to_obj_hook.with_obj_to_obj_hook ~enabled: @@ -416,7 +380,6 @@ let mk_check_file ~reader ~options ~master_cx ~cache () = let cx = Context.make ccx metadata file_key aloc_table resolve_require mk_builtins in resolved_requires := SMap.mapi (dep_module_t cx) resolved_modules; ConsGen.set_dst_cx cx; - extend_local_globals cx ~resolved_requires:(SMap.map Lazy.from_val !resolved_requires); let () = Type_inference_js.initialize_env cx aloc_ast in (cx, aloc_ast) in diff --git a/src/typing/__tests__/type_hint_test.ml b/src/typing/__tests__/type_hint_test.ml index 65a2649a6b9..5ea3d37cf0e 100644 --- a/src/typing/__tests__/type_hint_test.ml +++ b/src/typing/__tests__/type_hint_test.ml @@ -35,7 +35,6 @@ let metadata = react_rules_always = false; dev_only_refinement_info_as_errors = false; enable_const_params = false; - enable_declare_global = true; enable_enums = true; enable_jest_integration = false; enable_pattern_matching = false; @@ -172,7 +171,6 @@ end = struct facebook_fbt = None; max_literal_len = 100; exact_by_default = true; - enable_declare_global = true; enable_enums = true; enable_component_syntax = true; component_syntax_enabled_in_config = true; diff --git a/src/typing/__tests__/typed_ast_test.ml b/src/typing/__tests__/typed_ast_test.ml index 8986296ef83..bf4eeeea10b 100644 --- a/src/typing/__tests__/typed_ast_test.ml +++ b/src/typing/__tests__/typed_ast_test.ml @@ -33,7 +33,6 @@ let metadata = react_rules_always = false; dev_only_refinement_info_as_errors = false; enable_const_params = false; - enable_declare_global = true; enable_enums = true; enable_jest_integration = false; enable_pattern_matching = false; diff --git a/src/typing/context.ml b/src/typing/context.ml index a10321bb793..920858087f7 100644 --- a/src/typing/context.ml +++ b/src/typing/context.ml @@ -44,7 +44,6 @@ type metadata = { react_rules_always: bool; dev_only_refinement_info_as_errors: bool; enable_const_params: bool; - enable_declare_global: bool; enable_enums: bool; enable_jest_integration: bool; enable_pattern_matching: bool; @@ -273,7 +272,6 @@ let metadata_of_options options = react_rules_always = false; dev_only_refinement_info_as_errors = Options.dev_only_refinement_info_as_errors options; enable_const_params = Options.enable_const_params options; - enable_declare_global = Options.enable_declare_global options; enable_enums = Options.enums options; enable_jest_integration = Options.enable_jest_integration options; enable_pattern_matching = Options.enable_pattern_matching options; @@ -501,8 +499,6 @@ let dev_only_refinement_info_as_errors cx = cx.metadata.dev_only_refinement_info let enable_const_params cx = cx.metadata.enable_const_params || cx.metadata.strict || cx.metadata.strict_local -let enable_declare_global cx = cx.metadata.enable_declare_global - let enable_enums cx = cx.metadata.enable_enums let enable_jest_integration cx = cx.metadata.enable_jest_integration diff --git a/src/typing/context.mli b/src/typing/context.mli index cad8637171d..2ca9067b9b5 100644 --- a/src/typing/context.mli +++ b/src/typing/context.mli @@ -88,7 +88,6 @@ type metadata = { react_rules_always: bool; dev_only_refinement_info_as_errors: bool; enable_const_params: bool; - enable_declare_global: bool; enable_enums: bool; enable_jest_integration: bool; enable_pattern_matching: bool; @@ -191,8 +190,6 @@ val dev_only_refinement_info_as_errors : t -> bool val enable_const_params : t -> bool -val enable_declare_global : t -> bool - val enable_enums : t -> bool val enable_jest_integration : t -> bool diff --git a/src/typing/flow_js_utils.ml b/src/typing/flow_js_utils.ml index 91e9ad9d3f8..366b1fcb693 100644 --- a/src/typing/flow_js_utils.ml +++ b/src/typing/flow_js_utils.ml @@ -909,18 +909,6 @@ let lookup_builtin_typeapp cx reason x targs = let t = lookup_builtin_type cx x reason in typeapp ~from_value:false ~use_desc:false reason t targs -let get_implicitly_imported_module cx module_name ~expected_module_purpose reason = - match Context.find_require cx module_name with - | Context.UncheckedModule _ -> Error (AnyT.untyped reason) - | Context.TypedModule f -> f () - | Context.MissingModule _ -> - add_output - cx - (Error_message.EExpectedModuleLookupFailed - { loc = loc_of_reason reason; name = module_name; expected_module_purpose } - ); - Error (AnyT.error reason) - let builtin_promise_class_id cx = match Context.builtin_value_opt cx "Promise" with | Some (_, OpenT (_, id)) -> @@ -2355,11 +2343,16 @@ end = struct let get_implicitly_imported_react_type cx loc ~singleton_concretize_type_for_imports_exports ~purpose = let source_module = - get_implicitly_imported_module - cx - "react" - ~expected_module_purpose:purpose - (mk_reason (RModule "react") loc) + match Context.builtin_module_opt cx "react" with + | Some (_, (lazy module_type)) -> Ok module_type + | None -> + let reason = mk_reason (RModule "react") loc in + add_output + cx + (Error_message.EExpectedModuleLookupFailed + { loc; name = "react"; expected_module_purpose = purpose } + ); + Error (AnyT.error reason) in let (name, import_kind) = match purpose with diff --git a/src/typing/statement.ml b/src/typing/statement.ml index ac491eb103f..25b5c0545f6 100644 --- a/src/typing/statement.ml +++ b/src/typing/statement.ml @@ -2157,14 +2157,11 @@ module Make body_statements in let () = - match (Context.enable_declare_global cx, prev_scope_kind) with - | (true, (Name_def.DeclareModule | Name_def.Module)) -> () - | (_, _) -> - Flow.add_output - cx - (Error_message.EUnsupportedSyntax - (name_loc, Flow_intermediate_error_types.DeclareGlobal) - ) + Flow.add_output + cx + (Error_message.EUnsupportedSyntax + (name_loc, Flow_intermediate_error_types.DeclareGlobal) + ) in Flow.add_output cx (Error_message.EUndocumentedFeature { loc = name_loc }); (t, Ast.Statement.DeclareNamespace.Global id) diff --git a/tests/declare_global_in_react_declare_module/.flowconfig b/tests/declare_global_in_react_declare_module/.flowconfig deleted file mode 100644 index e9844ca1977..00000000000 --- a/tests/declare_global_in_react_declare_module/.flowconfig +++ /dev/null @@ -1,7 +0,0 @@ -[libs] -react.js - -[options] -all=true -experimental.declare_global=true -no_flowlib=false diff --git a/tests/declare_global_in_react_declare_module/declare_global_in_react_declare_module.exp b/tests/declare_global_in_react_declare_module/declare_global_in_react_declare_module.exp deleted file mode 100644 index 225eb0da042..00000000000 --- a/tests/declare_global_in_react_declare_module/declare_global_in_react_declare_module.exp +++ /dev/null @@ -1,89 +0,0 @@ -Error --------------------------------------------------------------------------------------------------- react.js:10:10 - -Cannot redeclare global `React.Node` [1] because the global is already declared in another file. [name-already-bound] - - react.js:10:10 - 10| type React$Node = 1; // bad-shadow - ^^^^^^^^^^ - -References: - /react.js:15:14 - 15| declare type React$Node = - ^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------------------ test.js:2:1 - -Cannot cast `2` to `React.Node` because number [1] is incompatible with number literal `1` [2]. [incompatible-cast] - - test.js:2:1 - 2| 2 as React$Node; // error: 2 ~> 1: The bad shadow wins over the real global. - ^ [1] - -References: - test.js:2:6 - 2| 2 as React$Node; // error: 2 ~> 1: The bad shadow wins over the real global. - ^^^^^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------------------ test.js:3:1 - -Cannot cast empty string to `MyReact` because string [1] is incompatible with string literal `react` [2]. -[incompatible-cast] - - test.js:3:1 - 3| '' as ReactTypes.MyReact; // error: '' ~> 'react' - ^^ [1] - -References: - test.js:3:7 - 3| '' as ReactTypes.MyReact; // error: '' ~> 'react' - ^^^^^^^^^^^^^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------------------ test.js:4:1 - -Cannot resolve name `ReactValue`. [cannot-resolve-name] - - 4| ReactValue; // error: value-namespaces in declare global are completely ignored - ^^^^^^^^^^ - - -Error ------------------------------------------------------------------------------------------------------ test.js:5:1 - -Cannot resolve name `willBeIgnored`. [cannot-resolve-name] - - 5| willBeIgnored; // error: values in declare global are completely ignored - ^^^^^^^^^^^^^ - - -Error ------------------------------------------------------------------------------------------------------ test.js:8:1 - -Cannot cast empty string to `T1` because string [1] is incompatible with string literal `react` [2]. [incompatible-cast] - - test.js:8:1 - 8| '' as T1; // error: '' ~> 'react' - ^^ [1] - -References: - test.js:8:7 - 8| '' as T1; // error: '' ~> 'react' - ^^ [2] - - -Error ------------------------------------------------------------------------------------------------------ test.js:9:1 - -Cannot cast empty string to `T2` because string [1] is incompatible with number literal `3` [2]. [incompatible-cast] - - test.js:9:1 - 9| '' as T2 // error: '' ~> 3 - ^^ [1] - -References: - test.js:9:7 - 9| '' as T2 // error: '' ~> 3 - ^^ [2] - - - -Found 7 errors diff --git a/tests/declare_global_in_react_declare_module/react.js b/tests/declare_global_in_react_declare_module/react.js deleted file mode 100644 index e8fbba9da7c..00000000000 --- a/tests/declare_global_in_react_declare_module/react.js +++ /dev/null @@ -1,19 +0,0 @@ -declare module 'react' { - // $FlowExpectedError[undocumented-feature] - declare global { - declare namespace ReactTypes { - type MyReact = 'react'; - } - declare namespace ReactValue { // TODO error: error on ignored value defs in declare global - declare const willBeIgnored: string; - } - type React$Node = 1; // bad-shadow - type ReactGlobalType = 3; - declare const willBeIgnored: string; - } - - export type Node = any; - export type RefSetter<-T> = any; - export type T1 = ReactTypes.MyReact; - export type T2 = ReactGlobalType; -} diff --git a/tests/declare_global_in_react_declare_module/test.js b/tests/declare_global_in_react_declare_module/test.js deleted file mode 100644 index c6529945ab9..00000000000 --- a/tests/declare_global_in_react_declare_module/test.js +++ /dev/null @@ -1,9 +0,0 @@ -// $FlowExpectedError[internal-type] -2 as React$Node; // error: 2 ~> 1: The bad shadow wins over the real global. -'' as ReactTypes.MyReact; // error: '' ~> 'react' -ReactValue; // error: value-namespaces in declare global are completely ignored -willBeIgnored; // error: values in declare global are completely ignored - -import type {T1, T2} from 'react'; // test that the normal exported types can reference names within declare global -'' as T1; // error: '' ~> 'react' -'' as T2 // error: '' ~> 3 diff --git a/tests/declare_global_in_react_module/.flowconfig b/tests/declare_global_in_react_module/.flowconfig deleted file mode 100644 index a67b6af08ae..00000000000 --- a/tests/declare_global_in_react_module/.flowconfig +++ /dev/null @@ -1,4 +0,0 @@ -[options] -all=true -experimental.declare_global=true -no_flowlib=false diff --git a/tests/declare_global_in_react_module/@flowtyped/react.js.flow b/tests/declare_global_in_react_module/@flowtyped/react.js.flow deleted file mode 100644 index 0eded47825b..00000000000 --- a/tests/declare_global_in_react_module/@flowtyped/react.js.flow +++ /dev/null @@ -1,17 +0,0 @@ -// $FlowExpectedError[undocumented-feature] -declare global { - declare namespace ReactTypes { - type MyReact = 'react'; - } - declare namespace ReactValue { // TODO error: error on ignored value defs in declare global - declare const willBeIgnored: string; - } - type React$Node = 1; // bad-shadow - type ReactGlobalType = 3; - declare const willBeIgnored: string; -} - -export type Node = any; -export type RefSetter<-T> = any; -export type T1 = ReactTypes.MyReact; -export type T2 = ReactGlobalType; diff --git a/tests/declare_global_in_react_module/declare_global_in_react_module.exp b/tests/declare_global_in_react_module/declare_global_in_react_module.exp deleted file mode 100644 index 00d8aa02fb6..00000000000 --- a/tests/declare_global_in_react_module/declare_global_in_react_module.exp +++ /dev/null @@ -1,104 +0,0 @@ -Error ------------------------------------------------------------------------------------- @flowtyped/react.js.flow:9:8 - -Cannot redeclare global `React.Node` [1] because the global is already declared in another file. [name-already-bound] - - @flowtyped/react.js.flow:9:8 - 9| type React$Node = 1; // bad-shadow - ^^^^^^^^^^ - -References: - /react.js:15:14 - 15| declare type React$Node = - ^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------------------ test.js:2:1 - -Cannot cast `2` to `React.Node` because number [1] is incompatible with number literal `1` [2]. [incompatible-cast] - - test.js:2:1 - 2| 2 as React$Node; // error: 2 ~> 1: The bad shadow wins over the real global. - ^ [1] - -References: - test.js:2:6 - 2| 2 as React$Node; // error: 2 ~> 1: The bad shadow wins over the real global. - ^^^^^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------------------ test.js:3:1 - -Cannot cast empty string to `MyReact` because string [1] is incompatible with string literal `react` [2]. -[incompatible-cast] - - test.js:3:1 - 3| '' as ReactTypes.MyReact; // error: '' ~> 'react' - ^^ [1] - -References: - test.js:3:7 - 3| '' as ReactTypes.MyReact; // error: '' ~> 'react' - ^^^^^^^^^^^^^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------------------ test.js:4:1 - -Cannot resolve name `ReactValue`. [cannot-resolve-name] - - 4| ReactValue; // error: value-namespaces in declare global are completely ignored - ^^^^^^^^^^ - - -Error ------------------------------------------------------------------------------------------------------ test.js:5:1 - -Cannot resolve name `willBeIgnored`. [cannot-resolve-name] - - 5| willBeIgnored; // error: values in declare global are completely ignored - ^^^^^^^^^^^^^ - - -Error ------------------------------------------------------------------------------------------------------ test.js:8:1 - -Cannot cast empty string to `T1` because string [1] is incompatible with string literal `react` [2]. [incompatible-cast] - - test.js:8:1 - 8| '' as T1; // error: '' ~> 'react' - ^^ [1] - -References: - test.js:8:7 - 8| '' as T1; // error: '' ~> 'react' - ^^ [2] - - -Error ------------------------------------------------------------------------------------------------------ test.js:9:1 - -Cannot cast empty string to `T2` because string [1] is incompatible with number literal `3` [2]. [incompatible-cast] - - test.js:9:1 - 9| '' as T2 // error: '' ~> 3 - ^^ [1] - -References: - test.js:9:7 - 9| '' as T2 // error: '' ~> 3 - ^^ [2] - - -Error ----------------------------------------------------------------------------- test_no_explicit_react_import.js:1:1 - -Cannot cast empty string to `MyReact` because string [1] is incompatible with string literal `react` [2]. -[incompatible-cast] - - test_no_explicit_react_import.js:1:1 - 1| '' as ReactTypes.MyReact; // error: '' ~> 'react' - ^^ [1] - -References: - test_no_explicit_react_import.js:1:7 - 1| '' as ReactTypes.MyReact; // error: '' ~> 'react' - ^^^^^^^^^^^^^^^^^^ [2] - - - -Found 8 errors diff --git a/tests/declare_global_in_react_module/test.js b/tests/declare_global_in_react_module/test.js deleted file mode 100644 index c6529945ab9..00000000000 --- a/tests/declare_global_in_react_module/test.js +++ /dev/null @@ -1,9 +0,0 @@ -// $FlowExpectedError[internal-type] -2 as React$Node; // error: 2 ~> 1: The bad shadow wins over the real global. -'' as ReactTypes.MyReact; // error: '' ~> 'react' -ReactValue; // error: value-namespaces in declare global are completely ignored -willBeIgnored; // error: values in declare global are completely ignored - -import type {T1, T2} from 'react'; // test that the normal exported types can reference names within declare global -'' as T1; // error: '' ~> 'react' -'' as T2 // error: '' ~> 3 diff --git a/tests/declare_global_in_react_module/test_no_explicit_react_import.js b/tests/declare_global_in_react_module/test_no_explicit_react_import.js deleted file mode 100644 index b41d475fbb6..00000000000 --- a/tests/declare_global_in_react_module/test_no_explicit_react_import.js +++ /dev/null @@ -1 +0,0 @@ -'' as ReactTypes.MyReact; // error: '' ~> 'react' diff --git a/tests/saved_state_userland_react_lib/saved_state_userland_react_lib.exp b/tests/saved_state_userland_react_lib/saved_state_userland_react_lib.exp index 0b80bcbfa4c..990738b89de 100644 --- a/tests/saved_state_userland_react_lib/saved_state_userland_react_lib.exp +++ b/tests/saved_state_userland_react_lib/saved_state_userland_react_lib.exp @@ -2,5 +2,5 @@ Generate saved-state Use saved state No errors! -The Flow server is currently in lazy mode and is only checking 2/3 files. +The Flow server is currently in lazy mode and is only checking 1/3 files. To learn more, visit flow.org/en/docs/lang/lazy-modes