This repository was archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- v1.0.0-alpha.66
- v1.0.0-alpha.65
- v1.0.0-alpha.64
- v1.0.0-alpha.63
- v1.0.0-alpha.62
- v1.0.0-alpha.61
- v1.0.0-alpha.60
- v1.0.0-alpha.59
- v1.0.0-alpha.58
- v1.0.0-alpha.57
- v1.0.0-alpha.56
- v1.0.0-alpha.55
- v1.0.0-alpha.54
- v1.0.0-alpha.53
- v1.0.0-alpha.52
- v1.0.0-alpha.51
- v1.0.0-alpha.50
- v1.0.0-alpha.49
- v1.0.0-alpha.48
- v1.0.0-alpha.47
- v1.0.0-alpha.46
- v1.0.0-alpha.45
- v1.0.0-alpha.44
- v1.0.0-alpha.43
- v1.0.0-alpha.42
- v1.0.0-alpha.41
- v1.0.0-alpha.40
- v1.0.0-alpha.39
- v1.0.0-alpha.38
- v1.0.0-alpha.37
- v1.0.0-alpha.36
- v1.0.0-alpha.35
- v1.0.0-alpha.34
- v1.0.0-alpha.33
Showing
6 changed files
with
155 additions
and
6 deletions.
There are no files selected for viewing
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,19 @@ | ||
import * as React from 'react'; | ||
|
||
export interface PropsWithSlots { | ||
reactNode: React.ReactNode; | ||
reactNodeArray: React.ReactNode[]; | ||
explicitReactNodeArray: React.ReactNodeArray; | ||
reactChild: React.ReactChild; | ||
reactChildArray: React.ReactChild[]; | ||
reactElement: React.ReactElement<any>; | ||
reactElementArray: React.ReactElement<any>[]; | ||
jsxElement: JSX.Element; | ||
jsxElementArray: JSX.Element[]; | ||
union: React.ReactChild | React.ReactElement<any> | JSX.Element | string; | ||
unionArray: (React.ReactChild | React.ReactElement<any> | JSX.Element | string)[]; | ||
disjunct: string | any; | ||
disjunctArray: string[]; | ||
} | ||
|
||
export const ReactElement: React.SFC<PropsWithSlots> = () => null; |
75 changes: 75 additions & 0 deletions
75
packages/analyzer/src/react-utils/is-react-slot-type.test.ts
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,75 @@ | ||
import * as TestUtils from '../test-utils'; | ||
import { isReactSlotType } from './is-react-slot-type'; | ||
|
||
const fixtures = require('fixturez')(__dirname); | ||
|
||
let ctx: ReturnType<typeof TestUtils.getFixtureSourceFile>; | ||
|
||
beforeAll(() => { | ||
ctx = TestUtils.getFixtureSourceFile('prop-slots.tsx', { fixtures }); | ||
}); | ||
|
||
test('returns true for React.ReactNode', () => { | ||
const prop = TestUtils.getNamedPropType('reactNode', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for React.ReactNodeArray', () => { | ||
const prop = TestUtils.getNamedPropType('explicitReactNodeArray', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for React.ReactChild', () => { | ||
const prop = TestUtils.getNamedPropType('reactChild', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for React.ReactElement', () => { | ||
const prop = TestUtils.getNamedPropType('reactElement', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for JSX.Element', () => { | ||
const prop = TestUtils.getNamedPropType('jsxElement', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for union type with slot members', () => { | ||
const prop = TestUtils.getNamedPropType('union', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for union type with only disjunct members', () => { | ||
const prop = TestUtils.getNamedPropType('disjunct', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(false); | ||
}); | ||
|
||
test('returns true for React.ReactNode[]', () => { | ||
const prop = TestUtils.getNamedPropType('reactNodeArray', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for React.ReactChild[]', () => { | ||
const prop = TestUtils.getNamedPropType('reactChildArray', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for React.ReactElement[]', () => { | ||
const prop = TestUtils.getNamedPropType('reactElementArray', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for JSX.Element[]', () => { | ||
const prop = TestUtils.getNamedPropType('jsxElementArray', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for Union[]', () => { | ||
const prop = TestUtils.getNamedPropType('unionArray', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).toBe(true); | ||
}); | ||
|
||
test('returns true for Disjunct[]', () => { | ||
const prop = TestUtils.getNamedPropType('disjunctArray', ctx); | ||
expect(isReactSlotType(prop.type, ctx)).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
15 changes: 15 additions & 0 deletions
15
packages/analyzer/src/typescript-utils/is-type-reference.ts
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,15 @@ | ||
import * as TypeScript from 'typescript'; | ||
|
||
export function isTypeReference(t: TypeScript.Type): t is TypeScript.TypeReference { | ||
if (!isObjectType(t)) { | ||
return false; | ||
} | ||
|
||
// tslint:disable-next-line:no-bitwise | ||
return (t.objectFlags & TypeScript.ObjectFlags.Reference) === TypeScript.ObjectFlags.Reference; | ||
} | ||
|
||
function isObjectType(t: TypeScript.Type): t is TypeScript.ObjectType { | ||
// tslint:disable-next-line:no-bitwise | ||
return (t.flags & TypeScript.TypeFlags.Object) === TypeScript.TypeFlags.Object; | ||
} |
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,6 @@ | ||
import * as TypeScript from 'typescript'; | ||
|
||
export function isUnionType(t: TypeScript.Type): t is TypeScript.UnionType { | ||
// tslint:disable-next-line:no-bitwise | ||
return (t.flags & TypeScript.TypeFlags.Union) === TypeScript.TypeFlags.Union; | ||
} |
f2fc8e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deployed at: https://alva-commits-f2fc8.surge.sh