Skip to content

Commit

Permalink
feat(api): indicate properties in localized tree
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsdev committed Oct 18, 2022
1 parent 2613e19 commit 349cc3b
Show file tree
Hide file tree
Showing 31 changed files with 485 additions and 1,439 deletions.
9 changes: 7 additions & 2 deletions packages/api/src/localizedTree.ts
Expand Up @@ -63,7 +63,7 @@ function generateTypeInfoMap(tree: TypeInfo, cache?: TypeInfoMap): TypeInfoMap {
export type TypePurpose = 'return'|'index_type'|'index_value_type'|'conditional_check'|'conditional_extends'|'conditional_true'|'conditional_false'|'keyof'|'indexed_access_index'|'indexed_access_base'|'parameter_default'|'parameter_base_constraint'|'class_constructor'|'class_base_type'|'class_implementations'|'object_class'|'type_parameter_list'|'type_argument_list'|'parameter_value'

type ResolvedTypeInfo = Exclude<TypeInfo, {kind: 'reference'}>
type LocalizedSymbolInfo = { name: string, anonymous?: boolean, locations?: SourceFileLocation[] }
type LocalizedSymbolInfo = { name: string, anonymous?: boolean, insideClassOrInterface?: boolean, property?: boolean, locations?: SourceFileLocation[], isArgument?: boolean }

type TypeInfoChildren = ({ info?: TypeInfo, localizedInfo?: LocalizedTypeInfo, opts?: LocalizeOpts })[]

Expand Down Expand Up @@ -99,7 +99,6 @@ function _localizeTypeInfo(info: TypeInfo, data: LocalizeData, opts: LocalizeOpt
const { purpose, optional, name, includeIds } = opts

const symbol = wrapSafe(localizeSymbol)(info.symbolMeta)
// const purpose = wrapSafe(localizePurpose)(purposeKind)

const resolved = resolveInfo(info)

Expand Down Expand Up @@ -355,9 +354,15 @@ function getChildren(info: ResolvedTypeInfo, { typeArguments: contextualTypeArgu
function localizeSymbol(symbolInfo: SymbolInfo): LocalizedSymbolInfo {
const locations = getLocations(symbolInfo)

const property = symbolInfo.flags & ts.SymbolFlags.Property
const isArgument = symbolInfo.flags & ts.SymbolFlags.FunctionScopedVariable

return {
name: symbolInfo.name,
...symbolInfo.anonymous && { anonymous: symbolInfo.anonymous },
...symbolInfo.insideClassOrInterface && { insideClassOrInterface: symbolInfo.insideClassOrInterface },
...property && { property: true },
...isArgument && { isArgument: true },
locations,
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/tree.ts
Expand Up @@ -124,7 +124,7 @@ function _generateTypeTree({ symbol, type, node }: SymbolOrType, ctx: TypeTreeCo
kind: 'type_parameter',
baseConstraint: wrapSafe(parseType)(typeChecker.getBaseConstraintOfType(type)),
defaultType: wrapSafe(parseType)(typeChecker.getDefaultFromTypeParameter(type)),
typeSymbolMeta: wrapSafe(getSymbolInfo)(type.symbol)
...type.symbol && type.symbol !== symbol && type.symbol !== type.aliasSymbol && { typeSymbolMeta: getSymbolInfo(type.symbol) }
}
} else if(flags & ts.TypeFlags.Any) {
if((type as IntrinsicTypeInternal).intrinsicName === "intrinsic") {
Expand Down
8 changes: 8 additions & 0 deletions tests/baselines/reference/arrayObjectAlias.localized.tree
Expand Up @@ -44,6 +44,7 @@ type Obj = { a: string, b: number }
"primitiveKind": "string",
"symbol": {
"name": "a",
"property": true,
"locations": [
{
"fileName": "cases/arrayObjectAlias.ts",
Expand Down Expand Up @@ -84,6 +85,7 @@ type Obj = { a: string, b: number }
"primitiveKind": "number",
"symbol": {
"name": "b",
"property": true,
"locations": [
{
"fileName": "cases/arrayObjectAlias.ts",
Expand Down Expand Up @@ -130,6 +132,7 @@ type Obj = { a: string, b: number }
"primitiveKind": "string",
"symbol": {
"name": "a",
"property": true,
"locations": [
{
"fileName": "cases/arrayObjectAlias.ts",
Expand Down Expand Up @@ -171,6 +174,7 @@ type Obj = { a: string, b: number }
"primitiveKind": "number",
"symbol": {
"name": "b",
"property": true,
"locations": [
{
"fileName": "cases/arrayObjectAlias.ts",
Expand Down Expand Up @@ -252,6 +256,7 @@ type arrObj = Obj[]
"primitiveKind": "string",
"symbol": {
"name": "a",
"property": true,
"locations": [
{
"fileName": "cases/arrayObjectAlias.ts",
Expand Down Expand Up @@ -292,6 +297,7 @@ type arrObj = Obj[]
"primitiveKind": "number",
"symbol": {
"name": "b",
"property": true,
"locations": [
{
"fileName": "cases/arrayObjectAlias.ts",
Expand Down Expand Up @@ -374,6 +380,7 @@ type arrObj = Obj[]
"primitiveKind": "string",
"symbol": {
"name": "a",
"property": true,
"locations": [
{
"fileName": "cases/arrayObjectAlias.ts",
Expand Down Expand Up @@ -414,6 +421,7 @@ type arrObj = Obj[]
"primitiveKind": "number",
"symbol": {
"name": "b",
"property": true,
"locations": [
{
"fileName": "cases/arrayObjectAlias.ts",
Expand Down
20 changes: 20 additions & 0 deletions tests/baselines/reference/class.localized.tree
Expand Up @@ -45,6 +45,7 @@ interface TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -98,6 +99,7 @@ interface TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -232,6 +234,7 @@ class TestClass implements TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -306,6 +309,7 @@ class TestClass implements TestInterface {
"primitiveKind": "string",
"symbol": {
"name": "param",
"isArgument": true,
"locations": [
{
"fileName": "cases/class.ts",
Expand Down Expand Up @@ -348,6 +352,7 @@ class TestClass implements TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -472,6 +477,7 @@ class TestClass implements TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -546,6 +552,7 @@ class TestClass implements TestInterface {
"primitiveKind": "string",
"symbol": {
"name": "param",
"isArgument": true,
"locations": [
{
"fileName": "cases/class.ts",
Expand Down Expand Up @@ -588,6 +595,7 @@ class TestClass implements TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -675,6 +683,7 @@ class TestClass implements TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -810,6 +819,7 @@ class TestClass implements TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -884,6 +894,7 @@ class TestClass implements TestInterface {
"primitiveKind": "string",
"symbol": {
"name": "param",
"isArgument": true,
"locations": [
{
"fileName": "cases/class.ts",
Expand Down Expand Up @@ -926,6 +937,7 @@ class TestClass implements TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -975,6 +987,7 @@ class TestClass implements TestInterface {
"primitiveKind": "string",
"symbol": {
"name": "param",
"isArgument": true,
"locations": [
{
"fileName": "cases/class.ts",
Expand Down Expand Up @@ -1017,6 +1030,7 @@ class TestClass implements TestInterface {
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -1186,6 +1200,7 @@ const _a = new TestClass("param")
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -1260,6 +1275,7 @@ const _a = new TestClass("param")
"primitiveKind": "string",
"symbol": {
"name": "param",
"isArgument": true,
"locations": [
{
"fileName": "cases/class.ts",
Expand Down Expand Up @@ -1302,6 +1318,7 @@ const _a = new TestClass("param")
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "cases/class.ts",
Expand Down Expand Up @@ -1393,6 +1410,7 @@ const _a = new TestClass("param")
"primitiveKind": "string",
"symbol": {
"name": "param",
"isArgument": true,
"locations": [
{
"fileName": "cases/class.ts",
Expand Down Expand Up @@ -1511,6 +1529,7 @@ const _a = new TestClass("param")
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down Expand Up @@ -1590,6 +1609,7 @@ const _a = new TestClass("param")
"kind": "function",
"symbol": {
"name": "getThing",
"insideClassOrInterface": true,
"locations": [
{
"fileName": "../cases/class.ts",
Expand Down

0 comments on commit 349cc3b

Please sign in to comment.