You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
3.4 KiB
1 lines
3.4 KiB
{"version":3,"names":["_scope","require","_scopeflags","FlowScope","Scope","constructor","args","declareFunctions","Set","FlowScopeHandler","ScopeHandler","createScope","flags","declareName","name","bindingType","loc","scope","currentScope","BIND_FLAGS_FLOW_DECLARE_FN","checkRedeclarationInScope","maybeExportDefined","add","isRedeclaredInScope","has","lexical","functions","checkLocalExport","id","scopeStack","exports","default"],"sources":["../../../src/plugins/flow/scope.ts"],"sourcesContent":["import type { Position } from \"../../util/location\";\nimport ScopeHandler, { Scope } from \"../../util/scope\";\nimport {\n BIND_FLAGS_FLOW_DECLARE_FN,\n type ScopeFlags,\n type BindingTypes,\n} from \"../../util/scopeflags\";\nimport type * as N from \"../../types\";\n\n// Reference implementation: https://github.com/facebook/flow/blob/23aeb2a2ef6eb4241ce178fde5d8f17c5f747fb5/src/typing/env.ml#L536-L584\nclass FlowScope extends Scope {\n // declare function foo(): type;\n declareFunctions: Set<string> = new Set();\n}\n\nexport default class FlowScopeHandler extends ScopeHandler<FlowScope> {\n createScope(flags: ScopeFlags): FlowScope {\n return new FlowScope(flags);\n }\n\n declareName(name: string, bindingType: BindingTypes, loc: Position) {\n const scope = this.currentScope();\n if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {\n this.checkRedeclarationInScope(scope, name, bindingType, loc);\n this.maybeExportDefined(scope, name);\n scope.declareFunctions.add(name);\n return;\n }\n\n super.declareName(name, bindingType, loc);\n }\n\n isRedeclaredInScope(\n scope: FlowScope,\n name: string,\n bindingType: BindingTypes,\n ): boolean {\n if (super.isRedeclaredInScope(scope, name, bindingType)) return true;\n\n if (bindingType & BIND_FLAGS_FLOW_DECLARE_FN) {\n return (\n !scope.declareFunctions.has(name) &&\n (scope.lexical.has(name) || scope.functions.has(name))\n );\n }\n\n return false;\n }\n\n checkLocalExport(id: N.Identifier) {\n if (!this.scopeStack[0].declareFunctions.has(id.name)) {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