Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit deb47a7

Browse files
authored
refactor: updated astq typings (#221)
1 parent 0f7024a commit deb47a7

File tree

5 files changed

+25
-29
lines changed

5 files changed

+25
-29
lines changed

src/analyzer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as astqts from 'astq';
2-
const ASTQ: typeof astqts.ASTQ = astqts as any;
1+
import * as ASTQ from 'astq';
32

43
import { InstanceOfResolver } from './index';
54
import { IPropTypes, IProp } from './deprecated';

src/deprecated.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as astqts from 'astq';
2-
const ASTQ: typeof astqts.ASTQ = astqts as any;
1+
import * as ASTQ from 'astq';
32
import { IOptions, InstanceOfResolver } from './index';
43
import { Generator } from './generator';
54
import { parsePropTypes } from './analyzer';

src/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as astqts from 'astq';
1+
import * as ASTQ from 'astq';
22
import * as dom from 'dts-dom';
33
import { propTypeQueryExpression } from './typings';
44

@@ -14,7 +14,7 @@ function getTypeDeclaration(type: any, optional: boolean): TypeDeclaration {
1414
};
1515
}
1616

17-
export function get(astq: astqts.ASTQ, propertyAst: any, propTypesName: string|undefined): TypeDeclaration {
17+
export function get(astq: ASTQ, propertyAst: any, propTypesName: string|undefined): TypeDeclaration {
1818
const [required, simpleTypeName] = getSimpleTypeName(astq, propertyAst, propTypesName);
1919
switch (simpleTypeName) {
2020
case 'any':
@@ -74,7 +74,7 @@ export function get(astq: astqts.ASTQ, propertyAst: any, propTypesName: string|u
7474
};
7575
}
7676

77-
function isRequired(astq: astqts.ASTQ, propertyAst: any): [boolean, any] {
77+
function isRequired(astq: ASTQ, propertyAst: any): [boolean, any] {
7878
const required = astq.query(propertyAst, `
7979
MemberExpression /:property Identifier[@name == 'isRequired']
8080
`);
@@ -84,7 +84,7 @@ function isRequired(astq: astqts.ASTQ, propertyAst: any): [boolean, any] {
8484
return [false, propertyAst];
8585
}
8686

87-
function getSimpleTypeName(astq: astqts.ASTQ, propertyAst: any,
87+
function getSimpleTypeName(astq: ASTQ, propertyAst: any,
8888
propTypesName: string|undefined): [boolean, string|undefined] {
8989
const [required, typeAst] = isRequired(astq, propertyAst);
9090
const res = astq.query(typeAst, `
@@ -97,7 +97,7 @@ function getSimpleTypeName(astq: astqts.ASTQ, propertyAst: any,
9797
return [required, res.length > 0 ? res[0].property.name : undefined];
9898
}
9999

100-
function getComplexTypeName(astq: astqts.ASTQ, propertyAst: any,
100+
function getComplexTypeName(astq: ASTQ, propertyAst: any,
101101
propTypesName: string|undefined): [boolean, string|undefined, any] {
102102
const [required, typeAst] = isRequired(astq, propertyAst);
103103
if (typeAst.type === 'CallExpression') {

src/typings.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as astqts from 'astq';
2-
const ASTQ: typeof astqts.ASTQ = astqts as any;
1+
import * as ASTQ from 'astq';
32
import * as dom from 'dts-dom';
43
import { InstanceOfResolver } from './index';
54
import * as types from './types';
@@ -69,7 +68,7 @@ export function createTypings(moduleName: string|null, ast: any,
6968
}
7069
};
7170

72-
function createPropTypeTypings(interf: dom.InterfaceDeclaration, astq: astqts.ASTQ, propTypes: any,
71+
function createPropTypeTypings(interf: dom.InterfaceDeclaration, astq: ASTQ, propTypes: any,
7372
propTypesName: string|undefined): void {
7473
const res = astq.query(propTypes, `
7574
/ ObjectProperty
@@ -117,7 +116,7 @@ export function propTypeQueryExpression(propTypesName: string|undefined): string
117116
`;
118117
}
119118

120-
function getReactComponentName(astq: astqts.ASTQ, ast: any): string|undefined {
119+
function getReactComponentName(astq: ASTQ, ast: any): string|undefined {
121120
const res = astq.query(ast, `
122121
// ImportDeclaration[
123122
/:source StringLiteral[@value == 'react']
@@ -133,7 +132,7 @@ function getReactComponentName(astq: astqts.ASTQ, ast: any): string|undefined {
133132
return undefined;
134133
}
135134

136-
function getPropTypesName(astq: astqts.ASTQ, ast: any): string|undefined {
135+
function getPropTypesName(astq: ASTQ, ast: any): string|undefined {
137136
const res = astq.query(ast, `
138137
// ImportDeclaration[
139138
/:source StringLiteral[@value == 'react']
@@ -149,7 +148,7 @@ function getPropTypesName(astq: astqts.ASTQ, ast: any): string|undefined {
149148
return undefined;
150149
}
151150

152-
function hasReactClass(astq: astqts.ASTQ, ast: any, reactComponentName: string|undefined): boolean {
151+
function hasReactClass(astq: ASTQ, ast: any, reactComponentName: string|undefined): boolean {
153152
const res = astq.query(ast, `
154153
// ClassDeclaration[
155154
'${reactComponentName}' == 'undefined'
@@ -179,7 +178,7 @@ function hasReactClass(astq: astqts.ASTQ, ast: any, reactComponentName: string|u
179178
return res.length > 0;
180179
}
181180

182-
function getInstanceOfPropTypes(astq: astqts.ASTQ, ast: any, propTypesName: string|undefined): string[] {
181+
function getInstanceOfPropTypes(astq: ASTQ, ast: any, propTypesName: string|undefined): string[] {
183182
const res = astq.query(ast, `
184183
// CallExpression[
185184
/:callee MemberExpression[
@@ -198,7 +197,7 @@ interface ImportStatement {
198197
local: string;
199198
path: string;
200199
}
201-
function getImportStatements(astq: astqts.ASTQ, ast: any, typeNames: string[],
200+
function getImportStatements(astq: ASTQ, ast: any, typeNames: string[],
202201
instanceOfResolver: InstanceOfResolver | undefined): ImportStatement[] {
203202
return typeNames.map(name => {
204203
const res = astq.query(ast, `
@@ -228,7 +227,7 @@ function getImportStatements(astq: astqts.ASTQ, ast: any, typeNames: string[],
228227
.filter(importStatement => Boolean(importStatement.path));
229228
}
230229

231-
function getComponentNamesByPropTypeAssignment(astq: astqts.ASTQ, ast: any): string[] {
230+
function getComponentNamesByPropTypeAssignment(astq: ASTQ, ast: any): string[] {
232231
const res = astq.query(ast, `
233232
//AssignmentExpression
234233
/:left MemberExpression[
@@ -242,7 +241,7 @@ function getComponentNamesByPropTypeAssignment(astq: astqts.ASTQ, ast: any): str
242241
return [];
243242
}
244243

245-
function getComponentNamesByStaticPropTypeAttribute(astq: astqts.ASTQ, ast: any): string[] {
244+
function getComponentNamesByStaticPropTypeAttribute(astq: ASTQ, ast: any): string[] {
246245
const res = astq.query(ast, `
247246
//ClassDeclaration[
248247
/:body * //ClassProperty /:key Identifier[@name == 'propTypes']
@@ -254,7 +253,7 @@ function getComponentNamesByStaticPropTypeAttribute(astq: astqts.ASTQ, ast: any)
254253
return [];
255254
}
256255

257-
function getComponentNamesByJsxInBody(astq: astqts.ASTQ, ast: any): string[] {
256+
function getComponentNamesByJsxInBody(astq: ASTQ, ast: any): string[] {
258257
const res = astq.query(ast, `
259258
// ClassDeclaration[
260259
/:body * //JSXElement
@@ -273,7 +272,7 @@ function getComponentNamesByJsxInBody(astq: astqts.ASTQ, ast: any): string[] {
273272
return [];
274273
}
275274

276-
function getPropTypesFromAssignment(astq: astqts.ASTQ, ast: any, componentName: string): any|undefined {
275+
function getPropTypesFromAssignment(astq: ASTQ, ast: any, componentName: string): any|undefined {
277276
const res = astq.query(ast, `
278277
//AssignmentExpression[
279278
/:left MemberExpression[
@@ -288,7 +287,7 @@ function getPropTypesFromAssignment(astq: astqts.ASTQ, ast: any, componentName:
288287
return undefined;
289288
}
290289

291-
function getPropTypesFromStaticAttribute(astq: astqts.ASTQ, ast: any, componentName: string): any|undefined {
290+
function getPropTypesFromStaticAttribute(astq: ASTQ, ast: any, componentName: string): any|undefined {
292291
const res = astq.query(ast, `
293292
//ClassDeclaration[
294293
/:id Identifier[@name == '${componentName}']
@@ -305,7 +304,7 @@ function getPropTypesFromStaticAttribute(astq: astqts.ASTQ, ast: any, componentN
305304
return undefined;
306305
}
307306

308-
function getComponentExportType(astq: astqts.ASTQ, ast: any, componentName: string): dom.DeclarationFlags|undefined {
307+
function getComponentExportType(astq: ASTQ, ast: any, componentName: string): dom.DeclarationFlags|undefined {
309308
let res = astq.query(ast, `
310309
// ExportDefaultDeclaration[
311310
// ClassDeclaration
@@ -351,7 +350,7 @@ function getComponentExportType(astq: astqts.ASTQ, ast: any, componentName: stri
351350
return undefined;
352351
}
353352

354-
function isClassComponent(astq: astqts.ASTQ, ast: any, componentName: string,
353+
function isClassComponent(astq: ASTQ, ast: any, componentName: string,
355354
reactComponentName: string|undefined): boolean {
356355
const res = astq.query(ast, `
357356
// ClassDeclaration

typings/astq.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
declare module 'astq' {
22

3-
namespace astq {
4-
class ASTQ {
5-
public query(ast: any, query: string): any[];
6-
}
3+
namespace ASTQ {}
4+
class ASTQ {
5+
public query(ast: any, query: string): any[];
76
}
87

9-
export = astq;
8+
export = ASTQ;
109

1110
}

0 commit comments

Comments
 (0)