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

feat: Support for export declarations #1157

Merged
merged 19 commits into from
Jan 12, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: Properly inherit exported flag
  • Loading branch information
Gerrit0 committed Jan 5, 2020

Verified

This commit was signed with the committer’s verified signature.
fwyzard Andrea Bocci
commit ca25b5021007906d5861b37421b52c752c8df102
1 change: 1 addition & 0 deletions src/lib/converter/factories/parameter.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ export function createParameter(context: Context, node: ts.ParameterDeclaration)
}

const parameter = new ParameterReflection(node.symbol.name, ReflectionKind.Parameter, signature);
parameter.flags.setFlag(ReflectionFlag.Exported, context.scope.flags.isExported);
context.registerReflection(parameter, node);
context.withScope(parameter, () => {
if (ts.isArrayBindingPattern(node.name) || ts.isObjectBindingPattern(node.name)) {
3 changes: 2 additions & 1 deletion src/lib/converter/factories/reference.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from 'typescript';

import { ReferenceType, ReferenceReflection, ContainerReflection } from '../../models';
import { ReferenceType, ReferenceReflection, ContainerReflection, ReflectionFlag } from '../../models';
import { Context } from '../context';
import { ReferenceState } from '../../models/reflections/reference';
import { Converter } from '../converter';
@@ -35,6 +35,7 @@ export function createReferenceReflection(context: Context, source: ts.Symbol, t
}

const reflection = new ReferenceReflection(source.name, [ReferenceState.Unresolved, context.getSymbolID(target)!], context.scope);
reflection.flags.setFlag(ReflectionFlag.Exported, true); // References are exported by necessity
if (!context.scope.children) {
context.scope.children = [];
}
3 changes: 2 additions & 1 deletion src/lib/converter/factories/signature.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from 'typescript';

import { ReflectionKind, SignatureReflection, ContainerReflection, DeclarationReflection, Type } from '../../models/index';
import { ReflectionKind, SignatureReflection, ContainerReflection, DeclarationReflection, Type, ReflectionFlag } from '../../models/index';
import { Context } from '../context';
import { Converter } from '../converter';
import { createParameter } from './parameter';
@@ -22,6 +22,7 @@ export function createSignature(context: Context, node: ts.SignatureDeclaration,
}

const signature = new SignatureReflection(name, kind, container);
signature.flags.setFlag(ReflectionFlag.Exported, container.flags.isExported);
context.registerReflection(signature, node);
context.withScope(signature, node.typeParameters, true, () => {
node.parameters.forEach((parameter: ts.ParameterDeclaration) => {
3 changes: 2 additions & 1 deletion src/lib/converter/factories/type-parameter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from 'typescript';

import { TypeParameterContainer, TypeParameterReflection, TypeParameterType } from '../../models/index';
import { TypeParameterContainer, TypeParameterReflection, TypeParameterType, ReflectionFlag } from '../../models/index';
import { Context } from '../context';
import { Converter } from '../converter';

@@ -23,6 +23,7 @@ export function createTypeParameter(context: Context, node: ts.TypeParameterDecl

const reflection = <TypeParameterContainer> context.scope;
const typeParameterReflection = new TypeParameterReflection(typeParameter, reflection);
typeParameterReflection.flags.setFlag(ReflectionFlag.Exported, reflection.flags.isExported);

if (!reflection.typeParameters) {
reflection.typeParameters = [];
3 changes: 2 additions & 1 deletion src/lib/converter/types/binding-object.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from 'typescript';

import { Type, ReflectionKind, DeclarationReflection, ReflectionType } from '../../models/index';
import { Type, ReflectionKind, DeclarationReflection, ReflectionType, ReflectionFlag } from '../../models/index';
import { Component, ConverterTypeComponent, TypeNodeConverter } from '../components';
import { Context } from '../context';
import { Converter } from '../converter';
@@ -23,6 +23,7 @@ export class BindingObjectConverter extends ConverterTypeComponent implements Ty
*/
convertNode(context: Context, node: ts.BindingPattern): Type {
const declaration = new DeclarationReflection('__type', ReflectionKind.TypeLiteral, context.scope);
declaration.flags.setFlag(ReflectionFlag.Exported, context.scope.flags.isExported);

context.registerReflection(declaration);
context.trigger(Converter.EVENT_CREATE_DECLARATION, declaration, node);
9 changes: 4 additions & 5 deletions src/lib/converter/types/reference.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ts from 'typescript';

import { Type, IntrinsicType, ReflectionType } from '../../models/types/index';
import { ReflectionKind, DeclarationReflection } from '../../models/reflections/index';
import { ReflectionKind, DeclarationReflection, ReflectionFlag } from '../../models/reflections/index';
import { createReferenceType } from '../factories/index';
import { Component, ConverterTypeComponent, TypeNodeConverter } from '../components';
import { Context } from '../context';
@@ -115,16 +115,15 @@ export class ReferenceConverter extends ConverterTypeComponent implements TypeNo
if (context.visitStack.includes(declaration)) {
if (declaration.kind === ts.SyntaxKind.TypeLiteral ||
declaration.kind === ts.SyntaxKind.ObjectLiteralExpression) {
// TODO: Check if this type assertion is safe and document.
return createReferenceType(context, declaration.parent.symbol!);
return createReferenceType(context, declaration.parent.symbol);
} else {
// TODO: Check if this type assertion is safe and document.
return createReferenceType(context, declaration.symbol!);
return createReferenceType(context, declaration.symbol);
}
}
}

const declaration = new DeclarationReflection('__type', ReflectionKind.TypeLiteral, context.scope);
declaration.flags.setFlag(ReflectionFlag.Exported, context.scope.flags.isExported);

context.registerReflection(declaration, undefined, symbol);
context.trigger(Converter.EVENT_CREATE_DECLARATION, declaration, node);
12 changes: 8 additions & 4 deletions src/test/converter/access/specs.json
Original file line number Diff line number Diff line change
@@ -91,7 +91,8 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {
"isPrivate": true
"isPrivate": true,
"isExported": true
},
"comment": {
"shortText": "A function that is made private via comment."
@@ -126,7 +127,8 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {
"isProtected": true
"isProtected": true,
"isExported": true
},
"comment": {
"shortText": "A function that is made protected via comment."
@@ -240,7 +242,8 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {
"isPrivate": true
"isPrivate": true,
"isExported": true
},
"comment": {
"shortText": "A function that is made private via comment."
@@ -275,7 +278,8 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {
"isProtected": true
"isProtected": true,
"isExported": true
},
"comment": {
"shortText": "A function that is made protected via comment."
78 changes: 59 additions & 19 deletions src/test/converter/alias/specs.json
Original file line number Diff line number Diff line change
@@ -31,7 +31,9 @@
"name": "T",
"kind": 131072,
"kindString": "Type parameter",
"flags": {},
"flags": {
"isExported": true
},
"type": {
"type": "array",
"elementType": {
@@ -45,7 +47,9 @@
"name": "R",
"kind": 131072,
"kindString": "Type parameter",
"flags": {}
"flags": {
"isExported": true
}
}
],
"sources": [
@@ -64,14 +68,18 @@
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"flags": {
"isExported": true
},
"children": [
{
"id": 26,
"name": "0",
"kind": 32,
"kindString": "Variable",
"flags": {},
"flags": {
"isExported": true
},
"sources": [
{
"fileName": "alias.ts",
@@ -89,7 +97,9 @@
"name": "1",
"kind": 32,
"kindString": "Variable",
"flags": {},
"flags": {
"isExported": true
},
"sources": [
{
"fileName": "alias.ts",
@@ -127,7 +137,9 @@
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"flags": {
"isExported": true
},
"sources": [
{
"fileName": "alias.ts",
@@ -212,7 +224,9 @@
"name": "T",
"kind": 131072,
"kindString": "Type parameter",
"flags": {}
"flags": {
"isExported": true
}
}
],
"sources": [
@@ -259,7 +273,9 @@
"name": "T",
"kind": 131072,
"kindString": "Type parameter",
"flags": {},
"flags": {
"isExported": true
},
"type": {
"type": "array",
"elementType": {
@@ -285,21 +301,26 @@
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"flags": {
"isExported": true
},
"signatures": [
{
"id": 16,
"name": "__call",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"flags": {
"isExported": true
},
"parameters": [
{
"id": 17,
"name": "args",
"kind": 32768,
"kindString": "Parameter",
"flags": {
"isExported": true,
"isRest": true
},
"type": {
@@ -337,21 +358,27 @@
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"flags": {
"isExported": true
},
"signatures": [
{
"id": 19,
"name": "__call",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"flags": {
"isExported": true
},
"parameters": [
{
"id": 20,
"name": "a",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"flags": {
"isExported": true
},
"type": {
"type": "intrinsic",
"name": "any"
@@ -363,6 +390,7 @@
"kind": 32768,
"kindString": "Parameter",
"flags": {
"isExported": true,
"isRest": true
},
"type": {
@@ -413,7 +441,9 @@
"name": "T",
"kind": 131072,
"kindString": "Type parameter",
"flags": {}
"flags": {
"isExported": true
}
}
],
"sources": [
@@ -466,7 +496,9 @@
"name": "T",
"kind": 131072,
"kindString": "Type parameter",
"flags": {}
"flags": {
"isExported": true
}
}
],
"sources": [
@@ -483,21 +515,27 @@
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"flags": {
"isExported": true
},
"signatures": [
{
"id": 5,
"name": "__call",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"flags": {
"isExported": true
},
"parameters": [
{
"id": 6,
"name": "a",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"flags": {
"isExported": true
},
"type": {
"type": "typeParameter",
"name": "T"
@@ -508,7 +546,9 @@
"name": "b",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"flags": {
"isExported": true
},
"type": {
"type": "typeParameter",
"name": "T"
Loading