adding analyzis of callbacks etc.
This commit is contained in:
parent
829a860c22
commit
b5694723d2
@ -176,7 +176,7 @@ function _getType(node: Node, inputType: Type, text: string) {
|
|||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
|
|
||||||
// Update the Imported Types.
|
// Update the Imported Types.
|
||||||
typeImports = result.map(item => {
|
typeImports.push(... result.map(item => {
|
||||||
const text = item.toString();
|
const text = item.toString();
|
||||||
|
|
||||||
// Regex, to extract the path of the Import.
|
// Regex, to extract the path of the Import.
|
||||||
@ -189,10 +189,24 @@ function _getType(node: Node, inputType: Type, text: string) {
|
|||||||
path,
|
path,
|
||||||
identifier
|
identifier
|
||||||
};
|
};
|
||||||
});
|
}));
|
||||||
|
|
||||||
} else if (Node.isFunctionDeclaration(node) || Node.isFunctionTypeNode(node) || Node.isFunctionLikeDeclaration(node)) {
|
} else if (Node.isFunctionDeclaration(node) || Node.isFunctionTypeNode(node) || Node.isFunctionLikeDeclaration(node)) {
|
||||||
baseType = "function"
|
baseType = "function";
|
||||||
|
|
||||||
|
// Iterate over the parameter
|
||||||
|
node.getParameters().map(parameter => {
|
||||||
|
const defintion = _getType(
|
||||||
|
parameter.getTypeNode(),
|
||||||
|
parameter.getType(),
|
||||||
|
parameter.getType().getText()
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!defintion.isBaseType) {
|
||||||
|
// Add the Elements to the Import.
|
||||||
|
typeImports.push(...defintion.typeImports)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the a Simplified Subtype.
|
// Define the a Simplified Subtype.
|
||||||
@ -206,7 +220,8 @@ function _getType(node: Node, inputType: Type, text: string) {
|
|||||||
const ret: TypeInformation = {
|
const ret: TypeInformation = {
|
||||||
isBaseType: !!(inputType.compilerType as any).intrinsicName,
|
isBaseType: !!(inputType.compilerType as any).intrinsicName,
|
||||||
baseType,
|
baseType,
|
||||||
originalCode
|
originalCode,
|
||||||
|
typeImports
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the Additional elements if required.
|
// Add the Additional elements if required.
|
||||||
@ -297,18 +312,11 @@ export function getDescription(declaration: PropertyDeclaration | InterfaceDecla
|
|||||||
typeImports,
|
typeImports,
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Add the Additional elements if required.
|
// Return the Type.
|
||||||
// if (!ret.isBaseType) {
|
|
||||||
// ret.simplifiedType = simplifiedType;
|
|
||||||
// ret.simplifiedSubType = simplifiedSubType;
|
|
||||||
// ret.typeImports = typeImports;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Return the Type.
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
} else if (Node.isFunctionDeclaration(declaration)) {
|
} else if (Node.isParameterDeclaration(declaration)) {
|
||||||
|
//
|
||||||
} else if (Node.isMethodDeclaration(declaration)) {
|
} else if (Node.isMethodDeclaration(declaration)) {
|
||||||
const isAbstract = declaration.isAbstract();
|
const isAbstract = declaration.isAbstract();
|
||||||
const isAsync = declaration.isAsync();
|
const isAsync = declaration.isAsync();
|
||||||
|
@ -51,23 +51,61 @@ export function transformClasses(sourceFiles: SourceFile[], options: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileWithTypesForClass = ''
|
// Iterate over the Methods
|
||||||
|
for (const method of relevantClass.methods){
|
||||||
|
if (!method.returnType.isBaseType) {
|
||||||
|
for (const {identifier, path} of (method.returnType.typeImports || [])){
|
||||||
|
|
||||||
|
// Only if the import isnt the Base Type, add it to the List.
|
||||||
|
if (identifier !== options.propertyType) {
|
||||||
|
// Check if the Imported Type has been Adden multiple Times.
|
||||||
|
if (mappingTypeToImport[identifier] === undefined) {
|
||||||
|
mappingTypeToImport[identifier] = new Set<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
mappingTypeToImport[identifier].add(path);
|
||||||
|
requiredImports.add(identifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const parm of method.params){
|
||||||
|
if (!parm.isBaseType){
|
||||||
|
for (const {identifier, path} of (parm.typeImports || [])){
|
||||||
|
|
||||||
|
// Only if the import isnt the Base Type, add it to the List.
|
||||||
|
if (identifier !== options.propertyType) {
|
||||||
|
// Check if the Imported Type has been Adden multiple Times.
|
||||||
|
if (mappingTypeToImport[identifier] === undefined) {
|
||||||
|
mappingTypeToImport[identifier] = new Set<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
mappingTypeToImport[identifier].add(path);
|
||||||
|
requiredImports.add(identifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let fileWithTypesForClass = `// Automatic extracted Interfaces for the Class "` + relevantClass.className + `"\n// Generated on: ` + (new Date()).toISOString();
|
||||||
|
|
||||||
|
// List containing the already used Types
|
||||||
|
const importedBaseTypes = new Set<string>();
|
||||||
|
|
||||||
|
// Iterate over the Imports
|
||||||
for (const reqType of requiredImports) {
|
for (const reqType of requiredImports) {
|
||||||
if (mappingTypeToImport[reqType] && mappingTypeToImport[reqType].size === 1) {
|
if (mappingTypeToImport[reqType] && mappingTypeToImport[reqType].size === 1) {
|
||||||
// Extract the Path of the File
|
// Extract the Path of the File
|
||||||
const pathToFile = Array.from(mappingTypeToImport[reqType].values())[0] + '.ts';
|
const pathToFile = Array.from(mappingTypeToImport[reqType].values())[0] + '.ts';
|
||||||
|
|
||||||
const declarations = getDeclarationByName(fileMapping, pathToFile, reqType);
|
const declarations = getDeclarationByName(fileMapping, pathToFile, reqType).filter(item => !importedBaseTypes.has(item.baseType));
|
||||||
|
declarations.map(item => importedBaseTypes.add(item.baseType));
|
||||||
|
|
||||||
fileWithTypesForClass += declarations.map(item =>
|
fileWithTypesForClass += declarations.map(item =>
|
||||||
item.originalCode
|
item.originalCode
|
||||||
).reduce(
|
).reduce(
|
||||||
(prev, current, idx) =>
|
(prev, current, idx) => prev + '\n\n' + current, ''
|
||||||
// If it is the First Element => Skipp the New Line Property idx === 0 ? current:
|
|
||||||
prev + '\n\n' + current,
|
|
||||||
`// Automatic extracted Interfaces for the Class "` + relevantClass.className + `"
|
|
||||||
// Generated on: ` + (new Date()).toISOString()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
} else if (mappingTypeToImport[reqType].size > 1) {
|
} else if (mappingTypeToImport[reqType].size > 1) {
|
||||||
|
@ -3,6 +3,10 @@ import { exportsElementsToDispatcher, exportMethodToDispatcher, exportPropertyTo
|
|||||||
import { IF01 } from "./testExternalDescriptor";
|
import { IF01 } from "./testExternalDescriptor";
|
||||||
import { IF02 } from "./testExternalDescriptorReference";
|
import { IF02 } from "./testExternalDescriptorReference";
|
||||||
|
|
||||||
|
export interface IF00 {
|
||||||
|
hello: 'world'
|
||||||
|
}
|
||||||
|
|
||||||
exportsElementsToDispatcher('test-api')
|
exportsElementsToDispatcher('test-api')
|
||||||
export class CLWithInterface {
|
export class CLWithInterface {
|
||||||
@exportPropertyToDispatcher
|
@exportPropertyToDispatcher
|
||||||
@ -10,18 +14,15 @@ export class CLWithInterface {
|
|||||||
|
|
||||||
@exportPropertyToDispatcher
|
@exportPropertyToDispatcher
|
||||||
exportedAttributeComplex = new nopeObservable<{
|
exportedAttributeComplex = new nopeObservable<{
|
||||||
element01: IF02,
|
element01: number,
|
||||||
num: number
|
num: number
|
||||||
}>({
|
}>({
|
||||||
element01: {
|
element01: 0,
|
||||||
name: '',
|
|
||||||
num: 0
|
|
||||||
},
|
|
||||||
num: 0
|
num: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
@exportMethodToDispatcher()
|
@exportMethodToDispatcher()
|
||||||
async exportedFunction(a: number, b: number, operator: (a: number,b: number) => Promise<number>){
|
async exportedFunction(a: number, b: number, operator: (a: IF00,b: IF01) => Promise<IF02>){
|
||||||
return await operator(a,b);
|
return await operator(a,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user