This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: update default slot content properly * fix: ensure correct children index * fix: allow multiple jsx elements at root level * fix: make sure single child slots work properly * feat: allow slots in default values * fix: restore essentials library * fix: remove stray debug text * fix: refactor slot content analyzing * feat: open slots by default * test: write unit tests for slot default adjustments
- Loading branch information
Showing
17 changed files
with
384 additions
and
154 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,38 @@ | ||
// tslint:disable:no-bitwise | ||
import * as TypeScript from 'typescript'; | ||
import { isTypeReference } from '../typescript-utils/is-type-reference'; | ||
|
||
const REACT_SLOT_TYPES_SINGLE = ['Element', 'ReactElement', 'ReactChild']; | ||
|
||
export function getReactSlotType( | ||
type: TypeScript.Type, | ||
ctx: { program: TypeScript.Program } | ||
): string | undefined { | ||
const typechecker = ctx.program.getTypeChecker(); | ||
const symbol = type.aliasSymbol || type.symbol || type.getSymbol(); | ||
|
||
if (!symbol) { | ||
return; | ||
} | ||
|
||
const resolvedSymbol = | ||
(symbol.flags & TypeScript.SymbolFlags.AliasExcludes) === TypeScript.SymbolFlags.AliasExcludes | ||
? typechecker.getAliasedSymbol(symbol) | ||
: symbol; | ||
|
||
if (resolvedSymbol.name === 'Array' && isTypeReference(type) && type.typeArguments) { | ||
const arg = type.typeArguments[0]!; | ||
|
||
if (!arg) { | ||
return; | ||
} | ||
|
||
return getReactSlotType(arg, ctx); | ||
} | ||
|
||
if (REACT_SLOT_TYPES_SINGLE.includes(resolvedSymbol.name)) { | ||
return 'single'; | ||
} | ||
|
||
return 'multiple'; | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './find-react-component-type'; | ||
export * from './is-react-event-handler-type'; | ||
export * from './is-react-slot-type'; | ||
export * from './get-react-slot-type'; | ||
export * from './get-event-type'; |
2 changes: 1 addition & 1 deletion
2
packages/analyzer/src/typescript-react-analyzer/slot-analyzer.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
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.
6ffb90d
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-6ffb9.surge.sh