Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typescript-parser-deluxe

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-parser-deluxe - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

1

declarations/FunctionDeclaration.d.ts

@@ -21,3 +21,4 @@ import { CallableDeclaration, ExportableDeclaration } from './Declaration';

variables: VariableDeclaration[];
typeArguments: ParameterDeclaration[];
constructor(name: string, isExported: boolean, type?: string | undefined, start?: number | undefined, end?: number | undefined);
}

@@ -21,4 +21,5 @@ "use strict";

this.variables = [];
this.typeArguments = [];
}
}
exports.FunctionDeclaration = FunctionDeclaration;

4

declarations/ParameterDeclaration.d.ts

@@ -12,6 +12,6 @@ import { TypedDeclaration } from './Declaration';

name: string;
type: string | undefined;
type: any | undefined;
start?: number | undefined;
end?: number | undefined;
constructor(name: string, type: string | undefined, start?: number | undefined, end?: number | undefined);
constructor(name: string, type: any | undefined, start?: number | undefined, end?: number | undefined);
}

@@ -24,2 +24,10 @@ import { FunctionDeclaration, MethodDeclaration, MethodSignature, Node } from 'typescript';

*/
export declare function parseTypeArguments(node: FunctionDeclaration | MethodDeclaration | MethodSignature): TshParameter[];
/**
* Parse method parameters.
*
* @export
* @param {(FunctionDeclaration | MethodDeclaration | MethodSignature)} node
* @returns {TshParameter[]}
*/
export declare function parseMethodParams(node: FunctionDeclaration | MethodDeclaration | MethodSignature): TshParameter[];

@@ -26,0 +34,0 @@ /**

@@ -43,5 +43,46 @@ "use strict";

*/
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') {
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) {
params.push(new ParameterDeclaration_1.ParameterDeclaration(cur.name.escapedText, parseTypeArguments(cur.type.members), cur.getStart(), cur.getEnd()));
}
else {
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 method parameters.
*
* @export
* @param {(FunctionDeclaration | MethodDeclaration | MethodSignature)} node
* @returns {TshParameter[]}
*/
function parseMethodParams(node) {
return node.parameters.reduce((all, cur) => {
let params = all;
const params = all;
if (TypescriptGuards_1.isIdentifier(cur.name)) {

@@ -80,2 +121,3 @@ params.push(new ParameterDeclaration_1.ParameterDeclaration(cur.name.text, parse_utilities_1.getNodeType(cur.type), cur.getStart(), cur.getEnd()));

func.parameters = parseMethodParams(node);
func.typeArguments = parseTypeArguments(node);
resource.declarations.push(func);

@@ -82,0 +124,0 @@ parseFunctionParts(resource, func, node);

{
"name": "typescript-parser-deluxe",
"version": "1.0.1",
"version": "1.1.0",
"description": "Parser for typescript (and javascript) files, that compiles those files and generates a human understandable AST.",

@@ -19,3 +19,3 @@ "main": "index.js",

"type": "git",
"url": "https://github.com/TypeScript-Heroes/node-typescript-parser.git"
"url": "https://github.com/streaka/node-typescript-parser.git"
},

@@ -57,4 +57,4 @@ "keywords": [

"tslib": "^1.9.0",
"typescript": "^2.8.1"
"typescript": "^3.1.1"
}
}

@@ -17,2 +17,3 @@ import { CallableDeclaration, ExportableDeclaration } from './Declaration';

public variables: VariableDeclaration[] = [];
public typeArguments: ParameterDeclaration[] = [];

@@ -19,0 +20,0 @@ constructor(

@@ -12,3 +12,3 @@ import { TypedDeclaration } from './Declaration';

export class ParameterDeclaration implements TypedDeclaration {
constructor(public name: string, public type: string | undefined, public start?: number, public end?: number) { }
constructor(public name: string, public type: any | undefined, public start?: number, public end?: number) { }
}

@@ -62,2 +62,51 @@ import {

*/
export function parseTypeArguments(
node: FunctionDeclaration | MethodDeclaration | MethodSignature,
): TshParameter[] {
if (!node.type) return [];
if ((!(<any>node.type).typeArguments || !(<any>node.type).typeArguments.length)
&& !(<any>node.type).members) return [];
let target;
if ((<any>node.type).typeArguments && (<any>node.type).typeArguments.length) {
if ((<any>node.type).typeArguments[0].constructor.name === 'TokenObject') {
return [];
}
if (!(<any>node.type).typeArguments[0].members) {
return [];
}
target = (<any>node.type).typeArguments[0].members;
} else if ((<any>node.type).members) {
target = (<any>node.type).members;
} else {
return [];
}
return target.reduce(
(all: TshParameter[], cur: ParameterDeclaration) => {
const params = all;
if (cur.type && (<any>cur.type).members) {
params.push(new TshParameter(
<string>(cur.name as Identifier).escapedText, parseTypeArguments((<any>cur.type).members),
cur.getStart(), cur.getEnd(),
));
} else {
params.push(new TshParameter(
<string>(cur.name as Identifier).escapedText, getNodeType(cur.type), cur.getStart(), cur.getEnd(),
));
}
return params;
},
[]);
}
/**
* Parse method parameters.
*
* @export
* @param {(FunctionDeclaration | MethodDeclaration | MethodSignature)} node
* @returns {TshParameter[]}
*/
export function parseMethodParams(

@@ -68,3 +117,3 @@ node: FunctionDeclaration | MethodDeclaration | MethodSignature,

(all: TshParameter[], cur: ParameterDeclaration) => {
let params = all;
const params = all;
if (isIdentifier(cur.name)) {

@@ -107,4 +156,5 @@ params.push(new TshParameter(

func.parameters = parseMethodParams(node);
func.typeArguments = parseTypeArguments(node);
resource.declarations.push(func);
parseFunctionParts(resource, func, node);
}

@@ -1,2 +0,2 @@

import { getCombinedModifierFlags, ModifierFlags, Node, SyntaxKind, TypeNode } from 'typescript';
import { getCombinedModifierFlags, ModifierFlags, Node, SyntaxKind, TypeNode, Declaration } from 'typescript';

@@ -16,3 +16,3 @@ import { DeclarationVisibility } from '../declarations/DeclarationVisibility';

export function isNodeExported(node: Node): boolean {
const flags = getCombinedModifierFlags(node);
const flags = getCombinedModifierFlags(<Declaration>node);
return (flags & ModifierFlags.Export) === ModifierFlags.Export;

@@ -30,3 +30,3 @@ }

export function isNodeDefaultExported(node: Node): boolean {
const flags = getCombinedModifierFlags(node);
const flags = getCombinedModifierFlags(<Declaration>node);
return (flags & ModifierFlags.Default) === ModifierFlags.Default;

@@ -33,0 +33,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc