[parser] Fix scope handling of Flow declared functions (#12735)

This commit is contained in:
Nicolò Ribaudo
2021-02-10 21:07:14 +01:00
committed by GitHub
parent f1a327506e
commit c07185207c
7 changed files with 212 additions and 27 deletions

View File

@@ -28,20 +28,21 @@ export type ScopeFlags =
// These flags are meant to be _only_ used inside the Scope class (or subclasses).
// prettier-ignore
export const BIND_KIND_VALUE = 0b00000_0000_01,
BIND_KIND_TYPE = 0b00000_0000_10,
export const BIND_KIND_VALUE = 0b000000_0000_01,
BIND_KIND_TYPE = 0b000000_0000_10,
// Used in checkLVal and declareName to determine the type of a binding
BIND_SCOPE_VAR = 0b00000_0001_00, // Var-style binding
BIND_SCOPE_LEXICAL = 0b00000_0010_00, // Let- or const-style binding
BIND_SCOPE_FUNCTION = 0b00000_0100_00, // Function declaration
BIND_SCOPE_OUTSIDE = 0b00000_1000_00, // Special case for function names as
BIND_SCOPE_VAR = 0b000000_0001_00, // Var-style binding
BIND_SCOPE_LEXICAL = 0b000000_0010_00, // Let- or const-style binding
BIND_SCOPE_FUNCTION = 0b000000_0100_00, // Function declaration
BIND_SCOPE_OUTSIDE = 0b000000_1000_00, // Special case for function names as
// bound inside the function
// Misc flags
BIND_FLAGS_NONE = 0b00001_0000_00,
BIND_FLAGS_CLASS = 0b00010_0000_00,
BIND_FLAGS_TS_ENUM = 0b00100_0000_00,
BIND_FLAGS_TS_CONST_ENUM = 0b01000_0000_00,
BIND_FLAGS_TS_EXPORT_ONLY = 0b10000_0000_00;
BIND_FLAGS_NONE = 0b000001_0000_00,
BIND_FLAGS_CLASS = 0b000010_0000_00,
BIND_FLAGS_TS_ENUM = 0b000100_0000_00,
BIND_FLAGS_TS_CONST_ENUM = 0b001000_0000_00,
BIND_FLAGS_TS_EXPORT_ONLY = 0b010000_0000_00,
BIND_FLAGS_FLOW_DECLARE_FN = 0b100000_0000_00;
// These flags are meant to be _only_ used by Scope consumers
// prettier-ignore
@@ -60,7 +61,9 @@ export const BIND_CLASS = BIND_KIND_VALUE | BIND_KIND_TYPE | BIND_SCOPE_
BIND_OUTSIDE = BIND_KIND_VALUE | 0 | 0 | BIND_FLAGS_NONE ,
BIND_TS_CONST_ENUM = BIND_TS_ENUM | BIND_FLAGS_TS_CONST_ENUM,
BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY;
BIND_TS_NAMESPACE = 0 | 0 | 0 | BIND_FLAGS_TS_EXPORT_ONLY,
BIND_FLOW_DECLARE_FN = BIND_FLAGS_FLOW_DECLARE_FN;
export type BindingTypes =
| typeof BIND_NONE