Skip to content

Block-level /*flow-disable*/ and /*flow-enable*/Β #740

@agentcooper

Description

@agentcooper

Will something like conditional comments make sense for Flow? There are some use cases (custom template inlines [1] or #718 [2]) when stripping some lines will allow Flow to understand the file.

Basic implementation I tested:

diff --git a/src/parsing/parsing_service_js.ml b/src/parsing/parsing_service_js.ml
index 8458cbc..a61b134 100644
--- a/src/parsing/parsing_service_js.ml
+++ b/src/parsing/parsing_service_js.ml
@@ -86,7 +86,7 @@ let do_parse ?(keep_errors=false) content file =
  * Add success/error info to passed accumulator. *)
 let reducer init_modes (ok, fails, errors) file =
   init_modes ();
-  let content = cat file in
+  let content = Str.global_replace (Str.regexp "/\\*flow-disable\\*/.+/\\*flow-enable\\*/") "" (cat file) in
   match (do_parse content file) with
   | OK ast ->
       ParserHeap.add file ast;

[1]

(function() {
  /*flow-disable*/{% include "lib.js" %}/*flow-enable*/
  lib.someFunction();
})();

[2]

// Flow will treat module as CommonJS

/*flow-disable*/define('banana', function(require, exports, module) {/*flow-enable*/
    module.exports = {
        render: function()/*: string*/ {
            return (
                '<p>banana</p>'
            );
        }
    };
/*flow-disable*/});/*flow-enable*/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions