Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle React.ReactChild correctly #402

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/uxpin-merge-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uxpin/merge-cli",
"version": "3.3.0",
"version": "3.3.0-atlas",
"description": "The Command-line tool integrates the Design System repository with: https://www.uxpin.com/merge",
"repository": {
"type": "git",
Expand Down Expand Up @@ -133,7 +133,7 @@
"sortobject": "^1.1.1",
"source-map-support": "^0.4.18",
"tslib": "^1.9.0",
"typescript": "4.4.2",
"typescript": "4.8.4",
Evomatic marked this conversation as resolved.
Show resolved Hide resolved
"uuid": "^3.3.2",
"webpack-merge": "^4.1.2",
"webpack-virtual-modules": "^0.5.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as ts from 'typescript';

import { KNOWN_TYPES_MAP } from './node/serializeKnownPropertyType';

export function isAny(type: ts.Type): boolean {
return Boolean(type.flags & ts.TypeFlags.Any);
}

export function isBooleanLike(type: ts.Type): boolean {
return Boolean(type.flags & ts.TypeFlags.BooleanLike);
}

export function isCallable(type: ts.Type): boolean {
return isObjectLike(type) && !!type.getCallSignatures().length;
}

export function isEnum(type: ts.Type): type is ts.LiteralType {
if (type.symbol?.valueDeclaration) {
return ts.isEnumMember(type.symbol.valueDeclaration);
}

return false;
}

export function isKnownPropertyType(type: ts.Type): boolean {
const typeSymbol: ts.Symbol = type.symbol || type.aliasSymbol;

return (
(isAny(type) || isObjectLike(type) || isUnion(type)) &&
Evomatic marked this conversation as resolved.
Show resolved Hide resolved
typeSymbol &&
typeSymbol.escapedName.toString() in KNOWN_TYPES_MAP
);
}

export function isIntersection(type: ts.Type): type is ts.IntersectionType {
return type.isIntersection();
}

export function isIntersectionOfObjects(type: ts.Type): boolean {
return isIntersection(type) && type.types.every(isObjectLike);
}

export function isLiteral(type: ts.Type): type is ts.LiteralType {
return type.isLiteral();
}

export function isObject(type: ts.Type): boolean {
return Boolean(type.flags & ts.TypeFlags.Object || type.flags & ts.TypeFlags.NonPrimitive);
}

export function isObjectLike(type: ts.Type): boolean {
return isObject(type) || isIntersectionOfObjects(type);
}

export function isUnion(type: ts.Type): type is ts.UnionType {
return type.isUnion();
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import * as ts from 'typescript';
import { PropertyType } from '../../../../ComponentPropertyDefinition';
import { TSSerializationContext } from '../../../context/getSerializationContext';
import { isBooleanLike } from '../checker/isBooleanLike';
import { isCallable } from '../checker/isCallable';
import { isEnum } from '../checker/isEnum';
import { isKnownPropertyType } from '../checker/isKnownPropertyType';
import { isLiteral } from '../checker/isLiteral';
import { isObjectLike } from '../checker/isObjectLike';
import { isUnion } from '../checker/isUnion';
import {
isAny,
isBooleanLike,
isCallable,
isEnum,
isKnownPropertyType,
isLiteral,
isObjectLike,
isUnion,
} from '../checker';
import { serializeAsUnsupportedType } from './serializeAsUnsupportedType';
import { serializeEnumType } from './serializeEnumType';
import { serializeKnownPropertyType } from './serializeKnownPropertyType';
Expand All @@ -28,12 +31,12 @@ export function convertTypeToPropertyType(
if (isBooleanLike(type)) {
return { name: 'boolean', structure: {} };
}
if (type.flags & ts.TypeFlags.Any) {
return { name: 'any', structure: {} };
}
if (isKnownPropertyType(type)) {
return serializeKnownPropertyType(type);
}
if (isAny(type)) {
return { name: 'any', structure: {} };
}
if (isCallable(type)) {
return { name: 'func', structure: {} };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const KNOWN_TYPES_MAP: { [typeName: string]: PropertyType } = {
Date: { name: 'date', structure: {} },
ReactElement: { name: 'element', structure: {} },
ReactNode: { name: 'node', structure: {} },
ReactChild: { name: 'node', structure: {} },
};

export function serializeKnownPropertyType(type: ts.Type): PropertyType {
Expand Down
8 changes: 4 additions & 4 deletions packages/uxpin-merge-cli/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7290,10 +7290,10 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86"
integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==
typescript@4.8.4:
version "4.8.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6"
integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==

typescript@>=5.0.2:
version "5.0.4"
Expand Down