dillon1000/react
Commit
Browse files Allow accessing properties of globals in switch test values
We limit the types of expressions allowed as switch case test values because we
our HIR doesn't yet preserve order-of-evaluation for switch test values (we
model them as being evaluated prior to entering the switch, as opposed to
lazily, when the case is reached). One common pattern internally is test case
values that are properties of a global, eg you have some bag of enum values and
are comparing against that:
```javascript
// at module scope, or imported from another module:
const OPTIONS = {FOO: 'foo'};
// in a component
switch (value) {
case OPTIONS.FOO: { ... }
}
```
This PR allows this specific case, ie member expressions where the innermost
object is a global identifier.Changed paths3 files
First-parent comparisoncompiler/forget/src/HIR/BuildHIR.ts ModifiedA compiler/forget/src/__tests__/fixtures/compiler/switch-global-propertyload-case-test.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/switch-global-propertyload-case-test.js AddedPatch
Files changed
Rendering syntax-highlighted changes…