typescript-parser-deluxe
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -27,3 +27,4 @@ import { AbstractDeclaration, AsyncDeclaration, CallableDeclaration, OptionalDeclaration, ScopedDeclaration, StaticDeclaration, TypedDeclaration } from './Declaration'; | ||
variables: VariableDeclaration[]; | ||
typeArguments: ParameterDeclaration[]; | ||
constructor(name: string, isAbstract: boolean, visibility: DeclarationVisibility | undefined, type: string | undefined, isOptional: boolean, isStatic: boolean, isAsync: boolean, start?: number | undefined, end?: number | undefined); | ||
} |
@@ -26,4 +26,5 @@ "use strict"; | ||
this.variables = []; | ||
this.typeArguments = []; | ||
} | ||
} | ||
exports.MethodDeclaration = MethodDeclaration; |
import { OptionalDeclaration, ScopedDeclaration, StaticDeclaration, TypedDeclaration } from './Declaration'; | ||
import { DeclarationVisibility } from './DeclarationVisibility'; | ||
import { ParameterDeclaration } from './ParameterDeclaration'; | ||
/** | ||
@@ -19,3 +20,4 @@ * Property declaration that contains its visibility. | ||
end?: number | undefined; | ||
typeArguments: ParameterDeclaration[]; | ||
constructor(name: string, visibility: DeclarationVisibility | undefined, type: string | undefined, isOptional: boolean, isStatic: boolean, start?: number | undefined, end?: number | undefined); | ||
} |
@@ -20,4 +20,5 @@ "use strict"; | ||
this.end = end; | ||
this.typeArguments = []; | ||
} | ||
} | ||
exports.PropertyDeclaration = PropertyDeclaration; |
@@ -1,4 +0,6 @@ | ||
import { ClassDeclaration, ConstructorDeclaration, Node } from 'typescript'; | ||
import { ClassDeclaration, ConstructorDeclaration, MethodDeclaration, Node, PropertyDeclaration } from 'typescript'; | ||
import { ClassDeclaration as TshClass } from '../declarations/ClassDeclaration'; | ||
import { ConstructorDeclaration as TshConstructor } from '../declarations/ConstructorDeclaration'; | ||
import { ParameterDeclaration as TshParameter } from '../declarations/ParameterDeclaration'; | ||
import { PropertyDeclaration as TshProperty } from '../declarations/PropertyDeclaration'; | ||
import { Resource } from '../resources/Resource'; | ||
@@ -14,2 +16,10 @@ /** | ||
/** | ||
* Parse method parameters. | ||
* | ||
* @export | ||
* @param {(FunctionDeclaration | MethodDeclaration | MethodSignature)} node | ||
* @returns {TshParameter[]} | ||
*/ | ||
export declare function parseTypeArguments(node: TshParameter | TshProperty | PropertyDeclaration | MethodDeclaration): TshParameter[] | string; | ||
/** | ||
* Parse information about a constructor. Contains parameters and used modifiers | ||
@@ -16,0 +26,0 @@ * (i.e. constructor(private name: string)). |
@@ -36,2 +36,52 @@ "use strict"; | ||
/** | ||
* Parse method parameters. | ||
* | ||
* @export | ||
* @param {(FunctionDeclaration | MethodDeclaration | MethodSignature)} node | ||
* @returns {TshParameter[]} | ||
*/ | ||
function parseTypeArguments(node) { | ||
if (!node.type) | ||
return []; | ||
if ((!node.type.typeArguments || !node.type.typeArguments.length) | ||
&& !node.type.members) | ||
return []; | ||
let target; | ||
if (node.type.typeArguments && node.type.typeArguments.length) { | ||
if (node.type.typeArguments[0].constructor.name === 'TokenObject') { | ||
if (node.type.typeArguments[0].kind === 119) { | ||
return 'any'; | ||
} | ||
return []; | ||
} | ||
if (!node.type.typeArguments[0].members) { | ||
return []; | ||
} | ||
target = node.type.typeArguments[0].members; | ||
} | ||
else if (node.type.members) { | ||
target = node.type.members; | ||
} | ||
else { | ||
return []; | ||
} | ||
return target.reduce((all, cur) => { | ||
const params = all; | ||
if (cur.type && cur.type.members) { | ||
if (!cur.name) { | ||
return params; | ||
} | ||
params.push(new ParameterDeclaration_1.ParameterDeclaration(cur.name.escapedText, parseTypeArguments(cur.type.members), cur.getStart(), cur.getEnd())); | ||
} | ||
else { | ||
if (!cur.name) { | ||
return params; | ||
} | ||
params.push(new ParameterDeclaration_1.ParameterDeclaration(cur.name.escapedText, parse_utilities_1.getNodeType(cur.type), cur.getStart(), cur.getEnd())); | ||
} | ||
return params; | ||
}, []); | ||
} | ||
exports.parseTypeArguments = parseTypeArguments; | ||
/** | ||
* Parse information about a constructor. Contains parameters and used modifiers | ||
@@ -92,6 +142,10 @@ * (i.e. constructor(private name: string)). | ||
if (o.modifiers) { | ||
classDeclaration.properties.push(new PropertyDeclaration_1.PropertyDeclaration(o.name.text, parse_utilities_1.getNodeVisibility(o), parse_utilities_1.getNodeType(o.type), !!o.questionToken, parse_utilities_1.containsModifier(o, typescript_1.SyntaxKind.StaticKeyword), o.getStart(), o.getEnd())); | ||
const newProperty = new PropertyDeclaration_1.PropertyDeclaration(o.name.text, parse_utilities_1.getNodeVisibility(o), parse_utilities_1.getNodeType(o.type), !!o.questionToken, parse_utilities_1.containsModifier(o, typescript_1.SyntaxKind.StaticKeyword), o.getStart(), o.getEnd()); | ||
newProperty.typeArguments = parseTypeArguments(o); | ||
classDeclaration.properties.push(newProperty); | ||
} | ||
if (actualCount === classDeclaration.properties.length) { | ||
classDeclaration.properties.push(new PropertyDeclaration_1.PropertyDeclaration(o.name.text, parse_utilities_1.getNodeVisibility(o), parse_utilities_1.getNodeType(o.type), !!o.questionToken, parse_utilities_1.containsModifier(o, typescript_1.SyntaxKind.StaticKeyword), o.getStart(), o.getEnd())); | ||
const newProperty = new PropertyDeclaration_1.PropertyDeclaration(o.name.text, parse_utilities_1.getNodeVisibility(o), parse_utilities_1.getNodeType(o.type), !!o.questionToken, parse_utilities_1.containsModifier(o, typescript_1.SyntaxKind.StaticKeyword), o.getStart(), o.getEnd()); | ||
newProperty.typeArguments = parseTypeArguments(o); | ||
classDeclaration.properties.push(newProperty); | ||
} | ||
@@ -115,2 +169,3 @@ return; | ||
method.parameters = function_parser_1.parseMethodParams(o); | ||
method.typeArguments = parseTypeArguments(o); | ||
classDeclaration.methods.push(method); | ||
@@ -117,0 +172,0 @@ function_parser_1.parseFunctionParts(tsResource, method, o); |
{ | ||
"name": "typescript-parser-deluxe", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Parser for typescript (and javascript) files, that compiles those files and generates a human understandable AST.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
177130
4820