Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/facebook/flow into module…
Browse files Browse the repository at this point in the history
…-typings
  • Loading branch information
gorakong committed Dec 10, 2020
2 parents 184b590 + 215ac06 commit a6825b1
Show file tree
Hide file tree
Showing 120 changed files with 2,396 additions and 1,424 deletions.
16 changes: 16 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
### 0.139.0

New Features:
* Support for `this` annotations in functions, like `function f(this: {foo: string}, param1: string): string { return this.foo; }`
* The `experimental.abstract_locations` config option is now `true` by default, as it enables significant performance improvements. This option is now deprecated and will be removed in a coming version.

Notable bug fixes:
* Fixed a false positive when a bounded generic like `K: string` flows into `$Keys<{[K]: ...}>`
* Fixed a false positive when a bounded generic like `K: 'literal'` is checked against itself like `k === 'literal'`
* Fixed autocomplete inside of JSX attribute values
* Fixed autocomplete of properties of interfaces

Misc:
* Updated `flow-remove-types` to support `this` parameters
* Added SpeechRecognition definitions (thanks @ayshiff)

### 0.138.0

Likely to cause new Flow errors:
Expand Down
2 changes: 1 addition & 1 deletion flow_parser.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
name: "flow_parser"
version: "0.138.0"
version: "0.139.0"
maintainer: "[email protected]"
authors: ["Flow Team <[email protected]>"]
homepage: "https://github.com/facebook/flow/tree/master/src/parser"
Expand Down
2 changes: 1 addition & 1 deletion flowtype.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
name: "flowtype"
version: "0.138.0"
version: "0.139.0"
maintainer: "[email protected]"
authors: "Flow Team <[email protected]>"
license: "MIT"
Expand Down
4 changes: 3 additions & 1 deletion lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ declare interface CustomElementRegistry {
}

declare interface ShadowRoot extends DocumentFragment {
host: Element;
+delegatesFocus: boolean;
+host: Element;
innerHTML: string;
+mode: ShadowRootMode;
}

declare type ShadowRootMode = 'open'|'closed';
Expand Down
2 changes: 1 addition & 1 deletion lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ declare class events$EventEmitter {
rawListeners(event: string): Array<Function>;
}


declare module "events" {
// TODO: See the comment above the events$EventEmitter declaration
declare class EventEmitter extends events$EventEmitter {
Expand Down Expand Up @@ -2613,7 +2614,6 @@ declare module "v8" {
declare function getHeapStatistics() : HeapStatistics;
declare function getHeapSpaceStatistics() : Array<HeapSpaceStatistics>
declare function setFlagsFromString(flags: string) : void;
declare function deserialize(buffer: Buffer): mixed;
}

type repl$DefineCommandOptions =
Expand Down
42 changes: 0 additions & 42 deletions newtests/lsp/completion/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,34 +162,6 @@ export default (suite(
newText: 'foo',
},
},
{
label: 'anInterface',
kind: 8,
detail: 'interface anInterface',
sortText: '00000000000000000000',
insertTextFormat: 1,
textEdit: {
range: {
start: {line: 13, character: 15},
end: {line: 13, character: 15},
},
newText: 'anInterface',
},
},
{
label: 'aUnion',
kind: 13,
detail: 'type aUnion = "a" | "b"',
sortText: '00000000000000000000',
insertTextFormat: 1,
textEdit: {
range: {
start: {line: 13, character: 15},
end: {line: 13, character: 15},
},
newText: 'aUnion',
},
},
{
label: 'aNumber',
kind: 6,
Expand Down Expand Up @@ -412,20 +384,6 @@ export default (suite(
newText: 'React',
},
},
{
label: 'Props',
kind: 13,
detail: 'type Props = {a: number, ...}',
sortText: '00000000000000000000',
insertTextFormat: 1,
textEdit: {
range: {
start: {line: 11, character: 1},
end: {line: 11, character: 1},
},
newText: 'Props',
},
},
{
label: 'D',
kind: 3,
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-parser-bin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flow-parser-bin",
"version": "0.138.0",
"version": "0.139.0",
"description": "The Flow JavaScript parser, via bindings to the native OCaml implementation",
"main": "index.js",
"repository": "https://github.com/facebook/flow.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flow-parser",
"version": "0.138.0",
"version": "0.139.0",
"description": "JavaScript parser written in OCaml. Produces ESTree AST",
"homepage": "https://flow.org",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/flow-remove-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flow-remove-types",
"version": "2.138.0",
"version": "2.139.0",
"description": "Removes Flow type annotations from JavaScript files with speed and simplicity.",
"author": {
"name": "Flow Team",
Expand Down Expand Up @@ -43,7 +43,7 @@
"es6"
],
"dependencies": {
"flow-parser": "^0.138.0",
"flow-parser": "^0.139.0",
"pirates": "^3.0.2",
"vlq": "^0.2.1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/codemods/utils/codemod_runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ module TypedRunnerWithPrepass (C : TYPED_RUNNER_WITH_PREPASS_CONFIG) : TYPED_RUN
(* Calculate dependencies that need to be merged *)
let%lwt (sig_dependency_graph, component_map, files_to_merge, files_to_check) =
let get_dependent_files sig_dependency_graph implementation_dependency_graph roots =
SharedMem_js.with_memory_timer_lwt ~options "AllDependentFiles" profiling (fun () ->
Memory_utils.with_memory_timer_lwt ~options "AllDependentFiles" profiling (fun () ->
Lwt.return
(Pure_dep_graph_operations.calc_all_dependents
~sig_dependency_graph
Expand Down
2 changes: 1 addition & 1 deletion src/codemods/utils/codemod_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module MakeMain (Runner : Codemod_runner.RUNNABLE) = struct
let initial_lwt_thread () =
let genv =
let num_workers = Options.max_workers options in
let handle = SharedMem_js.init ~num_workers shared_mem_config in
let handle = SharedMem.init ~num_workers shared_mem_config in
ServerEnvBuild.make_genv ~init_id ~options handle
in
Runner.run ~genv ~write ~repeat roots
Expand Down
23 changes: 12 additions & 11 deletions src/commands/autocompleteCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ let autocomplete_response_to_json ~strip_root response =
("result", JSON_Array []);
(* TODO: remove this? kept for BC *)
]
| Ok completions ->
let results = Base.List.map ~f:(autocomplete_result_to_json ~strip_root) completions in
| Ok { ServerProt.Response.Completion.items; is_incomplete = _ } ->
let results = Base.List.map ~f:(autocomplete_result_to_json ~strip_root) items in
JSON_Object [("result", JSON_Array results)])

let main base_flags option_values json pretty root strip_root wait_for_recheck lsp args () =
Expand Down Expand Up @@ -147,25 +147,26 @@ let main base_flags option_values json pretty root strip_root wait_for_recheck l
if lsp then
Base.Result.iter
results
~f:
(List.iter
( Flow_lsp_conversions.flow_completion_to_lsp
~is_snippet_supported:true
~is_preselect_supported:true
%> Lsp_fmt.print_completionItem ~key:(Path.to_string root)
%> Hh_json.print_json_endline ~pretty:true ))
~f:(fun { ServerProt.Response.Completion.items; is_incomplete = _ } ->
List.iter
( Flow_lsp_conversions.flow_completion_item_to_lsp
~is_snippet_supported:true
~is_preselect_supported:true
%> Lsp_fmt.print_completionItem ~key:(Path.to_string root)
%> Hh_json.print_json_endline ~pretty:true )
items)
else if json || pretty then
results |> autocomplete_response_to_json ~strip_root |> Hh_json.print_json_endline ~pretty
else (
match results with
| Error error -> prerr_endlinef "Error: %s" error
| Ok completions ->
| Ok { ServerProt.Response.Completion.items; is_incomplete = _ } ->
List.iter
(fun res ->
let name = res.ServerProt.Response.Completion.name in
let detail = res.ServerProt.Response.Completion.detail in
print_endline (Printf.sprintf "%s %s" name detail))
completions
items
)

let command = CommandSpec.command spec main
14 changes: 9 additions & 5 deletions src/commands/commandUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ let shm_config shm_flags flowconfig =
let log_level =
Base.Option.value shm_flags.shm_log_level ~default:(FlowConfig.shm_log_level flowconfig)
in
{ SharedMem_js.heap_size = FlowConfig.shm_heap_size flowconfig; hash_table_pow; log_level }
{ SharedMem.heap_size = FlowConfig.shm_heap_size flowconfig; hash_table_pow; log_level }

let from_flag =
let collector main from =
Expand Down Expand Up @@ -539,13 +539,15 @@ let remove_exclusion pattern =

let file_options =
let default_lib_dir ~no_flowlib tmp_dir =
let lib_dir = Flowlib.mkdir ~no_flowlib tmp_dir in
try
let lib_dir = Flowlib.mkdir ~no_flowlib tmp_dir in
Flowlib.extract ~no_flowlib lib_dir;
lib_dir
with _ ->
let msg = "Could not locate flowlib files" in
FlowExitStatus.(exit ~msg Could_not_find_flowconfig)
with e ->
let e = Exception.wrap e in
let err = Exception.get_ctor_string e in
let msg = Printf.sprintf "Could not locate flowlib files: %s" err in
FlowExitStatus.(exit ~msg Could_not_extract_flowlibs)
in
let ignores_of_arg root patterns extras =
let expand_project_root_token = Files.expand_project_root_token ~root in
Expand Down Expand Up @@ -1244,6 +1246,8 @@ let make_options
opt_enabled_rollouts = FlowConfig.enabled_rollouts flowconfig;
opt_enforce_local_inference_annotations =
FlowConfig.enforce_local_inference_annotations flowconfig;
opt_run_post_inference_implicit_instantiation =
FlowConfig.run_post_inference_implicit_instantiation flowconfig;
opt_enforce_strict_call_arity = FlowConfig.enforce_strict_call_arity flowconfig;
opt_enforce_well_formed_exports;
opt_enums = FlowConfig.enums flowconfig;
Expand Down
12 changes: 11 additions & 1 deletion src/commands/config/flowConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ module Opts = struct
react_runtime: Options.react_runtime;
recursion_limit: int;
root_name: string option;
run_post_inference_implicit_instantiation: bool;
saved_state_fetcher: Options.saved_state_fetcher;
shm_hash_table_pow: int;
shm_heap_size: int;
Expand Down Expand Up @@ -163,7 +164,7 @@ module Opts = struct
enums_with_unknown_members = false;
this_annot = false;
exact_by_default = false;
generate_tests = true;
generate_tests = false;
facebook_fbs = None;
facebook_fbt = None;
facebook_module_interop = false;
Expand Down Expand Up @@ -205,6 +206,7 @@ module Opts = struct
react_runtime = Options.ReactRuntimeClassic;
recursion_limit = 10000;
root_name = None;
run_post_inference_implicit_instantiation = false;
saved_state_fetcher = Options.Dummy_fetcher;
shm_hash_table_pow = 19;
shm_heap_size = 1024 * 1024 * 1024 * 25;
Expand Down Expand Up @@ -403,6 +405,9 @@ module Opts = struct
let local_inference_annotations =
boolean (fun opts v -> Ok { opts with enforce_local_inference_annotations = v })

let post_inference_implicit_instantiation =
boolean (fun opts v -> Ok { opts with run_post_inference_implicit_instantiation = v })

type deprecated_esproposal_setting =
| Enable
| Ignore
Expand Down Expand Up @@ -595,6 +600,8 @@ module Opts = struct
("types_first", types_first_parser);
("experimental.new_signatures", new_signatures_parser);
("experimental.enforce_local_inference_annotations", local_inference_annotations);
( "experimental.run_post_inference_implicit_instantiation",
post_inference_implicit_instantiation );
( "experimental.abstract_locations",
boolean (fun opts v -> Ok { opts with abstract_locations = v }) );
( "experimental.disable_live_non_parse_errors",
Expand Down Expand Up @@ -1273,6 +1280,9 @@ let new_signatures c = c.options.Opts.new_signatures

let required_version c = c.version

let run_post_inference_implicit_instantiation c =
c.options.Opts.run_post_inference_implicit_instantiation

let wait_for_recheck c = c.options.Opts.wait_for_recheck

let weak c = c.options.Opts.weak
Expand Down
2 changes: 2 additions & 0 deletions src/commands/config/flowConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ val recursion_limit : config -> int

val root_name : config -> string option

val run_post_inference_implicit_instantiation : config -> bool

val saved_state_fetcher : config -> Options.saved_state_fetcher

val shm_hash_table_pow : config -> int
Expand Down
5 changes: 5 additions & 0 deletions src/common/exit_status/flowExitStatus.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type t =
| Lock_stolen
(* Specific error for not being able to find a .flowconfig *)
| Could_not_find_flowconfig
(* Failed to extract flowlibs into temp dir *)
| Could_not_extract_flowlibs
(* Generic out-of-date error. This could be a version thing or maybe
* something changed and Flow can't handle it incrementally yet *)
| Server_out_of_date
Expand Down Expand Up @@ -113,6 +115,7 @@ let error_code = function
| Killed_by_monitor -> 19
| Invalid_saved_state -> 20
| Restart -> 21
| Could_not_extract_flowlibs -> 22
| Commandline_usage_error -> 64
| No_input -> 66
| Server_start_failed _ -> 78
Expand Down Expand Up @@ -150,6 +153,7 @@ let error_type = function
| 19 -> Killed_by_monitor
| 20 -> Invalid_saved_state
| 21 -> Restart
| 22 -> Could_not_extract_flowlibs
| 64 -> Commandline_usage_error
| 66 -> No_input
(* The process status is made up *)
Expand All @@ -176,6 +180,7 @@ let to_string = function
| No_error -> "Ok"
| Input_error -> "Input_error"
| Could_not_find_flowconfig -> "Could_not_find_flowconfig"
| Could_not_extract_flowlibs -> "Could_not_extract_flowlibs"
| Server_out_of_date -> "Server_out_of_date"
| Server_client_directory_mismatch -> "Server_client_directory_mismatch"
| Out_of_shared_memory -> "Out_of_shared_memory"
Expand Down
1 change: 1 addition & 0 deletions src/common/exit_status/flowExitStatus.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type t =
| Input_error
| Lock_stolen
| Could_not_find_flowconfig
| Could_not_extract_flowlibs
| Server_out_of_date
| Out_of_shared_memory
| Flowconfig_changed
Expand Down
14 changes: 13 additions & 1 deletion src/common/flow_lsp_conversions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let flow_signature_help_to_lsp
in
Some { signatures; activeSignature = 0; activeParameter = active_parameter }

let flow_completion_to_lsp
let flow_completion_item_to_lsp
~is_snippet_supported:(_ : bool)
~(is_preselect_supported : bool)
(item : ServerProt.Response.Completion.completion_item) : Lsp.Completion.completionItem =
Expand Down Expand Up @@ -115,6 +115,18 @@ let flow_completion_to_lsp
data = None;
}

let flow_completions_to_lsp
~(is_snippet_supported : bool)
~(is_preselect_supported : bool)
(completions : ServerProt.Response.Completion.t) : Lsp.Completion.result =
let { ServerProt.Response.Completion.items; is_incomplete } = completions in
let items =
Base.List.map
~f:(flow_completion_item_to_lsp ~is_snippet_supported ~is_preselect_supported)
items
in
{ Lsp.Completion.isIncomplete = is_incomplete; items }

let file_key_to_uri (file_key_opt : File_key.t option) : (Lsp.DocumentUri.t, string) result =
let ( >>| ) = Base.Result.( >>| ) in
let ( >>= ) = Base.Result.( >>= ) in
Expand Down
2 changes: 1 addition & 1 deletion src/common/flow_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* LICENSE file in the root directory of this source tree.
*)

let version = "0.138.0"
let version = "0.139.0"
Loading

0 comments on commit a6825b1

Please sign in to comment.