scope.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _scope = require("../../util/scope");
  7. var _scopeflags = require("../../util/scopeflags");
  8. class FlowScope extends _scope.Scope {
  9. constructor(...args) {
  10. super(...args);
  11. this.declareFunctions = new Set();
  12. }
  13. }
  14. class FlowScopeHandler extends _scope.default {
  15. createScope(flags) {
  16. return new FlowScope(flags);
  17. }
  18. declareName(name, bindingType, loc) {
  19. const scope = this.currentScope();
  20. if (bindingType & _scopeflags.BIND_FLAGS_FLOW_DECLARE_FN) {
  21. this.checkRedeclarationInScope(scope, name, bindingType, loc);
  22. this.maybeExportDefined(scope, name);
  23. scope.declareFunctions.add(name);
  24. return;
  25. }
  26. super.declareName(name, bindingType, loc);
  27. }
  28. isRedeclaredInScope(scope, name, bindingType) {
  29. if (super.isRedeclaredInScope(scope, name, bindingType)) return true;
  30. if (bindingType & _scopeflags.BIND_FLAGS_FLOW_DECLARE_FN) {
  31. return !scope.declareFunctions.has(name) && (scope.lexical.has(name) || scope.functions.has(name));
  32. }
  33. return false;
  34. }
  35. checkLocalExport(id) {
  36. if (!this.scopeStack[0].declareFunctions.has(id.name)) {
  37. super.checkLocalExport(id);
  38. }
  39. }
  40. }
  41. exports.default = FlowScopeHandler;
  42. //# sourceMappingURL=scope.js.map