-
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix resolving of more than two Flow Utility types (#345)
* Refactor code to do unwrapping of flow utility types in one place * Simplify unwrapping of utility types * Restore old functionality of returning falsey value
- Loading branch information
Showing
7 changed files
with
138 additions
and
49 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/handlers/__tests__/__snapshots__/flowTypeHandler-test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`flowTypeHandler does support utility types inline 1`] = ` | ||
Object { | ||
"foo": Object { | ||
"description": "", | ||
"flowType": Object {}, | ||
"required": true, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
|
||
/*global describe, it, expect*/ | ||
|
||
import { unwrapUtilityType, isSupportedUtilityType } from '../flowUtilityTypes'; | ||
|
||
import { statement } from '../../../tests/utils'; | ||
|
||
describe('flowTypeUtilities', () => { | ||
describe('unwrapUtilityType', () => { | ||
it('correctly unwraps', () => { | ||
const def = statement(` | ||
type A = $ReadOnly<{ foo: string }> | ||
`); | ||
|
||
expect(unwrapUtilityType(def.get('right'))).toBe( | ||
def.get('right', 'typeParameters', 'params', 0), | ||
); | ||
}); | ||
|
||
it('correctly unwraps double', () => { | ||
const def = statement(` | ||
type A = $ReadOnly<$ReadOnly<{ foo: string }>> | ||
`); | ||
|
||
expect(unwrapUtilityType(def.get('right'))).toBe( | ||
def.get( | ||
'right', | ||
'typeParameters', | ||
'params', | ||
0, | ||
'typeParameters', | ||
'params', | ||
0, | ||
), | ||
); | ||
}); | ||
|
||
it('correctly unwraps triple', () => { | ||
const def = statement(` | ||
type A = $ReadOnly<$ReadOnly<$ReadOnly<{ foo: string }>>> | ||
`); | ||
|
||
expect(unwrapUtilityType(def.get('right'))).toBe( | ||
def.get( | ||
'right', | ||
'typeParameters', | ||
'params', | ||
0, | ||
'typeParameters', | ||
'params', | ||
0, | ||
'typeParameters', | ||
'params', | ||
0, | ||
), | ||
); | ||
}); | ||
}); | ||
|
||
describe('isSupportedUtilityType', () => { | ||
it('correctly returns true for valid type', () => { | ||
const def = statement(` | ||
type A = $Exact<{ foo: string }> | ||
`); | ||
|
||
expect(isSupportedUtilityType(def.get('right'))).toBe(true); | ||
}); | ||
|
||
it('correctly returns false for invalid type', () => { | ||
const def = statement(` | ||
type A = $Homer<{ foo: string }> | ||
`); | ||
|
||
expect(isSupportedUtilityType(def.get('right'))).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters