@proteinjs/reflection-build 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/modules/typescript-parser/.appveyor.yml +22 -0
- package/dist/modules/typescript-parser/DeclarationIndex.d.ts +217 -0
- package/dist/modules/typescript-parser/DeclarationIndex.js +441 -0
- package/dist/modules/typescript-parser/LICENSE +21 -0
- package/dist/modules/typescript-parser/Node.d.ts +23 -0
- package/dist/modules/typescript-parser/Node.js +2 -0
- package/dist/modules/typescript-parser/README.md +51 -0
- package/dist/modules/typescript-parser/SymbolSpecifier.d.ts +22 -0
- package/dist/modules/typescript-parser/SymbolSpecifier.js +28 -0
- package/dist/modules/typescript-parser/TypescriptParser.d.ts +68 -0
- package/dist/modules/typescript-parser/TypescriptParser.js +191 -0
- package/dist/modules/typescript-parser/clonable/Clonable.d.ts +17 -0
- package/dist/modules/typescript-parser/clonable/Clonable.js +2 -0
- package/dist/modules/typescript-parser/code-generators/TypescriptCodeGenerator.d.ts +39 -0
- package/dist/modules/typescript-parser/code-generators/TypescriptCodeGenerator.js +66 -0
- package/dist/modules/typescript-parser/code-generators/TypescriptGenerationOptions.d.ts +69 -0
- package/dist/modules/typescript-parser/code-generators/TypescriptGenerationOptions.js +9 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/accessorDeclaration.d.ts +11 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/accessorDeclaration.js +34 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/externalModuleImport.d.ts +11 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/externalModuleImport.js +15 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/methodDeclaration.d.ts +11 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/methodDeclaration.js +23 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/namedImport.d.ts +11 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/namedImport.js +94 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/namespaceImport.d.ts +11 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/namespaceImport.js +15 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/parameterDeclaration.d.ts +9 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/parameterDeclaration.js +14 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/propertyDeclaration.d.ts +11 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/propertyDeclaration.js +18 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/stringImport.d.ts +11 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/stringImport.js +15 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/symbolSpecifier.d.ts +9 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/symbolSpecifier.js +14 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/variableDeclaration.d.ts +9 -0
- package/dist/modules/typescript-parser/code-generators/typescript-generators/variableDeclaration.js +14 -0
- package/dist/modules/typescript-parser/declarations/AccessorDeclaration.d.ts +40 -0
- package/dist/modules/typescript-parser/declarations/AccessorDeclaration.js +45 -0
- package/dist/modules/typescript-parser/declarations/ClassDeclaration.d.ts +34 -0
- package/dist/modules/typescript-parser/declarations/ClassDeclaration.js +26 -0
- package/dist/modules/typescript-parser/declarations/ConstructorDeclaration.d.ts +18 -0
- package/dist/modules/typescript-parser/declarations/ConstructorDeclaration.js +20 -0
- package/dist/modules/typescript-parser/declarations/Declaration.d.ts +215 -0
- package/dist/modules/typescript-parser/declarations/Declaration.js +2 -0
- package/dist/modules/typescript-parser/declarations/DeclarationInfo.d.ts +13 -0
- package/dist/modules/typescript-parser/declarations/DeclarationInfo.js +17 -0
- package/dist/modules/typescript-parser/declarations/DeclarationVisibility.d.ts +18 -0
- package/dist/modules/typescript-parser/declarations/DeclarationVisibility.js +22 -0
- package/dist/modules/typescript-parser/declarations/DefaultDeclaration.d.ts +21 -0
- package/dist/modules/typescript-parser/declarations/DefaultDeclaration.js +28 -0
- package/dist/modules/typescript-parser/declarations/EnumDeclaration.d.ts +16 -0
- package/dist/modules/typescript-parser/declarations/EnumDeclaration.js +20 -0
- package/dist/modules/typescript-parser/declarations/FunctionDeclaration.d.ts +23 -0
- package/dist/modules/typescript-parser/declarations/FunctionDeclaration.js +25 -0
- package/dist/modules/typescript-parser/declarations/InterfaceDeclaration.d.ts +27 -0
- package/dist/modules/typescript-parser/declarations/InterfaceDeclaration.js +24 -0
- package/dist/modules/typescript-parser/declarations/MethodDeclaration.d.ts +28 -0
- package/dist/modules/typescript-parser/declarations/MethodDeclaration.js +29 -0
- package/dist/modules/typescript-parser/declarations/ModuleDeclaration.d.ts +15 -0
- package/dist/modules/typescript-parser/declarations/ModuleDeclaration.js +19 -0
- package/dist/modules/typescript-parser/declarations/ParameterDeclaration.d.ts +33 -0
- package/dist/modules/typescript-parser/declarations/ParameterDeclaration.js +54 -0
- package/dist/modules/typescript-parser/declarations/PropertyDeclaration.d.ts +20 -0
- package/dist/modules/typescript-parser/declarations/PropertyDeclaration.js +23 -0
- package/dist/modules/typescript-parser/declarations/TypeAliasDeclaration.d.ts +19 -0
- package/dist/modules/typescript-parser/declarations/TypeAliasDeclaration.js +22 -0
- package/dist/modules/typescript-parser/declarations/VariableDeclaration.d.ts +19 -0
- package/dist/modules/typescript-parser/declarations/VariableDeclaration.js +22 -0
- package/dist/modules/typescript-parser/declarations/index.d.ts +16 -0
- package/dist/modules/typescript-parser/declarations/index.js +19 -0
- package/dist/modules/typescript-parser/errors/NotGeneratableYetError.d.ts +11 -0
- package/dist/modules/typescript-parser/errors/NotGeneratableYetError.js +17 -0
- package/dist/modules/typescript-parser/exports/AllExport.d.ts +14 -0
- package/dist/modules/typescript-parser/exports/AllExport.js +18 -0
- package/dist/modules/typescript-parser/exports/AssignedExport.d.ts +26 -0
- package/dist/modules/typescript-parser/exports/AssignedExport.js +38 -0
- package/dist/modules/typescript-parser/exports/Export.d.ts +10 -0
- package/dist/modules/typescript-parser/exports/Export.js +2 -0
- package/dist/modules/typescript-parser/exports/NamedExport.d.ts +16 -0
- package/dist/modules/typescript-parser/exports/NamedExport.js +18 -0
- package/dist/modules/typescript-parser/exports/index.d.ts +4 -0
- package/dist/modules/typescript-parser/exports/index.js +7 -0
- package/dist/modules/typescript-parser/imports/ExternalModuleImport.d.ts +25 -0
- package/dist/modules/typescript-parser/imports/ExternalModuleImport.js +33 -0
- package/dist/modules/typescript-parser/imports/Import.d.ts +43 -0
- package/dist/modules/typescript-parser/imports/Import.js +2 -0
- package/dist/modules/typescript-parser/imports/NamedImport.d.ts +29 -0
- package/dist/modules/typescript-parser/imports/NamedImport.js +38 -0
- package/dist/modules/typescript-parser/imports/NamespaceImport.d.ts +24 -0
- package/dist/modules/typescript-parser/imports/NamespaceImport.js +32 -0
- package/dist/modules/typescript-parser/imports/StringImport.d.ts +23 -0
- package/dist/modules/typescript-parser/imports/StringImport.js +31 -0
- package/dist/modules/typescript-parser/imports/index.d.ts +5 -0
- package/dist/modules/typescript-parser/imports/index.js +8 -0
- package/dist/modules/typescript-parser/index.d.ts +12 -0
- package/dist/modules/typescript-parser/index.js +14 -0
- package/dist/modules/typescript-parser/node-parser/changes/parseType.d.ts +14 -0
- package/dist/modules/typescript-parser/node-parser/changes/parseType.js +35 -0
- package/dist/modules/typescript-parser/node-parser/class-parser.d.ts +30 -0
- package/dist/modules/typescript-parser/node-parser/class-parser.js +143 -0
- package/dist/modules/typescript-parser/node-parser/enum-parser.d.ts +10 -0
- package/dist/modules/typescript-parser/node-parser/enum-parser.js +18 -0
- package/dist/modules/typescript-parser/node-parser/export-parser.d.ts +10 -0
- package/dist/modules/typescript-parser/node-parser/export-parser.js +58 -0
- package/dist/modules/typescript-parser/node-parser/function-parser.d.ts +33 -0
- package/dist/modules/typescript-parser/node-parser/function-parser.js +101 -0
- package/dist/modules/typescript-parser/node-parser/identifier-parser.d.ts +10 -0
- package/dist/modules/typescript-parser/node-parser/identifier-parser.js +81 -0
- package/dist/modules/typescript-parser/node-parser/import-parser.d.ts +10 -0
- package/dist/modules/typescript-parser/node-parser/import-parser.js +54 -0
- package/dist/modules/typescript-parser/node-parser/index.d.ts +0 -0
- package/dist/modules/typescript-parser/node-parser/index.js +11 -0
- package/dist/modules/typescript-parser/node-parser/interface-parser.d.ts +11 -0
- package/dist/modules/typescript-parser/node-parser/interface-parser.js +57 -0
- package/dist/modules/typescript-parser/node-parser/module-parser.d.ts +12 -0
- package/dist/modules/typescript-parser/node-parser/module-parser.js +23 -0
- package/dist/modules/typescript-parser/node-parser/parse-utilities.d.ts +55 -0
- package/dist/modules/typescript-parser/node-parser/parse-utilities.js +96 -0
- package/dist/modules/typescript-parser/node-parser/traverse-ast.d.ts +1 -0
- package/dist/modules/typescript-parser/node-parser/traverse-ast.js +14 -0
- package/dist/modules/typescript-parser/node-parser/type-alias-parser.d.ts +10 -0
- package/dist/modules/typescript-parser/node-parser/type-alias-parser.js +20 -0
- package/dist/modules/typescript-parser/node-parser/variable-parser.d.ts +11 -0
- package/dist/modules/typescript-parser/node-parser/variable-parser.js +30 -0
- package/dist/modules/typescript-parser/package-lock.json +16793 -0
- package/dist/modules/typescript-parser/package.json +55 -0
- package/dist/modules/typescript-parser/resources/File.d.ts +45 -0
- package/dist/modules/typescript-parser/resources/File.js +58 -0
- package/dist/modules/typescript-parser/resources/Module.d.ts +35 -0
- package/dist/modules/typescript-parser/resources/Module.js +50 -0
- package/dist/modules/typescript-parser/resources/Namespace.d.ts +35 -0
- package/dist/modules/typescript-parser/resources/Namespace.js +50 -0
- package/dist/modules/typescript-parser/resources/Resource.d.ts +64 -0
- package/dist/modules/typescript-parser/resources/Resource.js +2 -0
- package/dist/modules/typescript-parser/resources/index.d.ts +4 -0
- package/dist/modules/typescript-parser/resources/index.js +7 -0
- package/dist/modules/typescript-parser/type-guards/TypescriptGuards.d.ts +153 -0
- package/dist/modules/typescript-parser/type-guards/TypescriptGuards.js +213 -0
- package/dist/modules/typescript-parser/type-guards/TypescriptHeroGuards.d.ts +26 -0
- package/dist/modules/typescript-parser/type-guards/TypescriptHeroGuards.js +36 -0
- package/dist/modules/typescript-parser/utilities/PathHelpers.d.ts +22 -0
- package/dist/modules/typescript-parser/utilities/PathHelpers.js +42 -0
- package/dist/modules/typescript-parser/utilities/StringTemplate.d.ts +9 -0
- package/dist/modules/typescript-parser/utilities/StringTemplate.js +21 -0
- package/dist/src/tsconfigTemplate.json +18 -0
- package/package.json +3 -3
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./ExternalModuleImport"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./Import"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./NamedImport"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./NamespaceImport"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./StringImport"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './TypescriptParser';
|
|
2
|
+
export * from './Node';
|
|
3
|
+
export * from './SymbolSpecifier';
|
|
4
|
+
export * from './DeclarationIndex';
|
|
5
|
+
export * from './code-generators/TypescriptGenerationOptions';
|
|
6
|
+
export * from './code-generators/TypescriptCodeGenerator';
|
|
7
|
+
export * from './declarations';
|
|
8
|
+
export * from './exports';
|
|
9
|
+
export * from './imports';
|
|
10
|
+
export * from './resources';
|
|
11
|
+
export * from './type-guards/TypescriptHeroGuards';
|
|
12
|
+
export { Type, TypeAlias } from './node-parser/changes/parseType';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./TypescriptParser"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./Node"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./SymbolSpecifier"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./DeclarationIndex"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./code-generators/TypescriptGenerationOptions"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./code-generators/TypescriptCodeGenerator"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./declarations"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./exports"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./imports"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./resources"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./type-guards/TypescriptHeroGuards"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TypeAliasDeclaration, VariableDeclaration } from 'typescript';
|
|
2
|
+
export declare type TypeAlias = {
|
|
3
|
+
name: string;
|
|
4
|
+
typeParameters: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare type Type = {
|
|
7
|
+
text: string;
|
|
8
|
+
parentTypes: TypeAlias[];
|
|
9
|
+
};
|
|
10
|
+
export declare function parseType(declaration: VariableDeclaration | TypeAliasDeclaration): Type;
|
|
11
|
+
export declare function parseTypeAndParameters(expression: string): {
|
|
12
|
+
name: string;
|
|
13
|
+
typeParameters: string[];
|
|
14
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTypeAndParameters = exports.parseType = void 0;
|
|
4
|
+
function parseType(declaration) {
|
|
5
|
+
const typeText = declaration.type ? declaration.type.getText() : null;
|
|
6
|
+
if (!typeText)
|
|
7
|
+
return { text: '', parentTypes: [] };
|
|
8
|
+
const serializedChildTypes = typeText.split('&');
|
|
9
|
+
const parentTypes = [];
|
|
10
|
+
for (const serializedChildType of serializedChildTypes) {
|
|
11
|
+
let name = serializedChildType.trim();
|
|
12
|
+
let typeParameters = [];
|
|
13
|
+
if (name.startsWith('{')) {
|
|
14
|
+
parentTypes.push({ name, typeParameters });
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
parentTypes.push(parseTypeAndParameters(name));
|
|
18
|
+
}
|
|
19
|
+
return { text: typeText, parentTypes: parentTypes };
|
|
20
|
+
}
|
|
21
|
+
exports.parseType = parseType;
|
|
22
|
+
function parseTypeAndParameters(expression) {
|
|
23
|
+
let name = expression.trim();
|
|
24
|
+
let typeParameters = [];
|
|
25
|
+
if (name.includes('<')) {
|
|
26
|
+
typeParameters = parseTypeParameters(name);
|
|
27
|
+
name = name.slice(0, name.indexOf('<'));
|
|
28
|
+
}
|
|
29
|
+
return { name, typeParameters };
|
|
30
|
+
}
|
|
31
|
+
exports.parseTypeAndParameters = parseTypeAndParameters;
|
|
32
|
+
function parseTypeParameters(typeParameterExpression) {
|
|
33
|
+
let serialiedTypeParameters = typeParameterExpression.slice(typeParameterExpression.indexOf('<') + 1, typeParameterExpression.length - 1);
|
|
34
|
+
return serialiedTypeParameters.split(',').map((typeParameter) => typeParameter.trim());
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ClassDeclaration, ConstructorDeclaration, Node } from 'typescript';
|
|
2
|
+
import { ClassDeclaration as TshClass } from '../declarations/ClassDeclaration';
|
|
3
|
+
import { ConstructorDeclaration as TshConstructor } from '../declarations/ConstructorDeclaration';
|
|
4
|
+
import { Resource } from '../resources/Resource';
|
|
5
|
+
/**
|
|
6
|
+
* Parses the identifiers of a class (usages).
|
|
7
|
+
*
|
|
8
|
+
* @export
|
|
9
|
+
* @param {Resource} tsResource
|
|
10
|
+
* @param {Node} node
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseClassIdentifiers(tsResource: Resource, node: Node): void;
|
|
13
|
+
/**
|
|
14
|
+
* Parse information about a constructor. Contains parameters and used modifiers
|
|
15
|
+
* (i.e. constructor(private name: string)).
|
|
16
|
+
*
|
|
17
|
+
* @export
|
|
18
|
+
* @param {TshClass} parent
|
|
19
|
+
* @param {TshConstructor} ctor
|
|
20
|
+
* @param {ConstructorDeclaration} node
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseCtorParams(parent: TshClass, ctor: TshConstructor, node: ConstructorDeclaration): void;
|
|
23
|
+
/**
|
|
24
|
+
* Parses a class node into its declaration. Calculates the properties, constructors and methods of the class.
|
|
25
|
+
*
|
|
26
|
+
* @export
|
|
27
|
+
* @param {Resource} tsResource
|
|
28
|
+
* @param {ClassDeclaration} node
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseClass(tsResource: Resource, node: ClassDeclaration): void;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseClass = exports.parseCtorParams = exports.parseClassIdentifiers = void 0;
|
|
4
|
+
const typescript_1 = require("typescript");
|
|
5
|
+
const AccessorDeclaration_1 = require("../declarations/AccessorDeclaration");
|
|
6
|
+
const ClassDeclaration_1 = require("../declarations/ClassDeclaration");
|
|
7
|
+
const ConstructorDeclaration_1 = require("../declarations/ConstructorDeclaration");
|
|
8
|
+
const DefaultDeclaration_1 = require("../declarations/DefaultDeclaration");
|
|
9
|
+
const MethodDeclaration_1 = require("../declarations/MethodDeclaration");
|
|
10
|
+
const ParameterDeclaration_1 = require("../declarations/ParameterDeclaration");
|
|
11
|
+
const PropertyDeclaration_1 = require("../declarations/PropertyDeclaration");
|
|
12
|
+
const TypescriptGuards_1 = require("../type-guards/TypescriptGuards");
|
|
13
|
+
const function_parser_1 = require("./function-parser");
|
|
14
|
+
const identifier_parser_1 = require("./identifier-parser");
|
|
15
|
+
const parse_utilities_1 = require("./parse-utilities");
|
|
16
|
+
const parseType_1 = require("./changes/parseType");
|
|
17
|
+
/**
|
|
18
|
+
* Parses the identifiers of a class (usages).
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @param {Resource} tsResource
|
|
22
|
+
* @param {Node} node
|
|
23
|
+
*/
|
|
24
|
+
function parseClassIdentifiers(tsResource, node) {
|
|
25
|
+
for (const child of node.getChildren()) {
|
|
26
|
+
switch (child.kind) {
|
|
27
|
+
case typescript_1.SyntaxKind.Identifier:
|
|
28
|
+
identifier_parser_1.parseIdentifier(tsResource, child);
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
parseClassIdentifiers(tsResource, child);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.parseClassIdentifiers = parseClassIdentifiers;
|
|
37
|
+
/**
|
|
38
|
+
* Parse information about a constructor. Contains parameters and used modifiers
|
|
39
|
+
* (i.e. constructor(private name: string)).
|
|
40
|
+
*
|
|
41
|
+
* @export
|
|
42
|
+
* @param {TshClass} parent
|
|
43
|
+
* @param {TshConstructor} ctor
|
|
44
|
+
* @param {ConstructorDeclaration} node
|
|
45
|
+
*/
|
|
46
|
+
function parseCtorParams(parent, ctor, node) {
|
|
47
|
+
if (!node.parameters) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
node.parameters.forEach((o) => {
|
|
51
|
+
if (TypescriptGuards_1.isIdentifier(o.name)) {
|
|
52
|
+
ctor.parameters.push(new ParameterDeclaration_1.ParameterDeclaration(o.name.text, parse_utilities_1.getNodeType(o.type), o.getStart(), o.getEnd()));
|
|
53
|
+
if (!o.modifiers) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
parent.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()));
|
|
57
|
+
}
|
|
58
|
+
else if (TypescriptGuards_1.isObjectBindingPattern(o.name) || TypescriptGuards_1.isArrayBindingPattern(o.name)) {
|
|
59
|
+
const identifiers = o.name;
|
|
60
|
+
const elements = [...identifiers.elements];
|
|
61
|
+
// TODO: BindingElement
|
|
62
|
+
ctor.parameters = ctor.parameters.concat(elements.map((bind) => {
|
|
63
|
+
if (TypescriptGuards_1.isIdentifier(bind.name)) {
|
|
64
|
+
return new ParameterDeclaration_1.ParameterDeclaration(bind.name.text, undefined, bind.getStart(), bind.getEnd());
|
|
65
|
+
}
|
|
66
|
+
}).filter(Boolean));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.parseCtorParams = parseCtorParams;
|
|
71
|
+
/**
|
|
72
|
+
* Parses a class node into its declaration. Calculates the properties, constructors and methods of the class.
|
|
73
|
+
*
|
|
74
|
+
* @export
|
|
75
|
+
* @param {Resource} tsResource
|
|
76
|
+
* @param {ClassDeclaration} node
|
|
77
|
+
*/
|
|
78
|
+
function parseClass(tsResource, node) {
|
|
79
|
+
const name = node.name ? node.name.text : parse_utilities_1.getDefaultResourceIdentifier(tsResource);
|
|
80
|
+
const classDeclaration = new ClassDeclaration_1.ClassDeclaration(name, parse_utilities_1.isNodeExported(node), node.getStart(), node.getEnd());
|
|
81
|
+
if (parse_utilities_1.isNodeDefaultExported(node)) {
|
|
82
|
+
classDeclaration.isExported = false;
|
|
83
|
+
tsResource.declarations.push(new DefaultDeclaration_1.DefaultDeclaration(classDeclaration.name, tsResource));
|
|
84
|
+
}
|
|
85
|
+
if (node.typeParameters) {
|
|
86
|
+
classDeclaration.typeParameters = node.typeParameters.map(param => param.getText());
|
|
87
|
+
}
|
|
88
|
+
if (node.members) {
|
|
89
|
+
node.members.forEach((o) => {
|
|
90
|
+
if (TypescriptGuards_1.isPropertyDeclaration(o)) {
|
|
91
|
+
const actualCount = classDeclaration.properties.length;
|
|
92
|
+
if (o.modifiers) {
|
|
93
|
+
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()));
|
|
94
|
+
}
|
|
95
|
+
if (actualCount === classDeclaration.properties.length) {
|
|
96
|
+
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()));
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (TypescriptGuards_1.isGetAccessorDeclaration(o)) {
|
|
101
|
+
classDeclaration.accessors.push(new AccessorDeclaration_1.GetterDeclaration(o.name.text, parse_utilities_1.getNodeVisibility(o), parse_utilities_1.getNodeType(o.type), o.modifiers !== undefined && o.modifiers.some(m => m.kind === typescript_1.SyntaxKind.AbstractKeyword), parse_utilities_1.containsModifier(o, typescript_1.SyntaxKind.StaticKeyword), o.getStart(), o.getEnd()));
|
|
102
|
+
}
|
|
103
|
+
if (TypescriptGuards_1.isSetAccessorDeclaration(o)) {
|
|
104
|
+
classDeclaration.accessors.push(new AccessorDeclaration_1.SetterDeclaration(o.name.text, parse_utilities_1.getNodeVisibility(o), parse_utilities_1.getNodeType(o.type), o.modifiers !== undefined && o.modifiers.some(m => m.kind === typescript_1.SyntaxKind.AbstractKeyword), parse_utilities_1.containsModifier(o, typescript_1.SyntaxKind.StaticKeyword), o.getStart(), o.getEnd()));
|
|
105
|
+
}
|
|
106
|
+
if (TypescriptGuards_1.isConstructorDeclaration(o)) {
|
|
107
|
+
const ctor = new ConstructorDeclaration_1.ConstructorDeclaration(classDeclaration.name, o.getStart(), o.getEnd());
|
|
108
|
+
parseCtorParams(classDeclaration, ctor, o);
|
|
109
|
+
classDeclaration.ctor = ctor;
|
|
110
|
+
function_parser_1.parseFunctionParts(tsResource, ctor, o);
|
|
111
|
+
}
|
|
112
|
+
else if (TypescriptGuards_1.isMethodDeclaration(o)) {
|
|
113
|
+
const method = new MethodDeclaration_1.MethodDeclaration(o.name.text, o.modifiers !== undefined && o.modifiers.some(m => m.kind === typescript_1.SyntaxKind.AbstractKeyword), parse_utilities_1.getNodeVisibility(o), parse_utilities_1.getNodeType(o.type), !!o.questionToken, parse_utilities_1.containsModifier(o, typescript_1.SyntaxKind.StaticKeyword), parse_utilities_1.containsModifier(o, typescript_1.SyntaxKind.AsyncKeyword), o.getStart(), o.getEnd());
|
|
114
|
+
method.parameters = function_parser_1.parseMethodParams(o);
|
|
115
|
+
classDeclaration.methods.push(method);
|
|
116
|
+
function_parser_1.parseFunctionParts(tsResource, method, o);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (node.heritageClauses) {
|
|
121
|
+
for (const heritageClause of node.heritageClauses) {
|
|
122
|
+
if (heritageClause.token == typescript_1.SyntaxKind.ExtendsKeyword) {
|
|
123
|
+
for (let heritageType of heritageClause.getChildren()) {
|
|
124
|
+
const expressionText = heritageType.getText().trim();
|
|
125
|
+
if (expressionText == 'extends')
|
|
126
|
+
continue;
|
|
127
|
+
classDeclaration.extends.push(parseType_1.parseTypeAndParameters(expressionText));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (heritageClause.token == typescript_1.SyntaxKind.ImplementsKeyword) {
|
|
131
|
+
for (let heritageType of heritageClause.getChildren()) {
|
|
132
|
+
const expressionText = heritageType.getText().trim();
|
|
133
|
+
if (expressionText == 'implements')
|
|
134
|
+
continue;
|
|
135
|
+
classDeclaration.implements.push(parseType_1.parseTypeAndParameters(expressionText));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
parseClassIdentifiers(tsResource, node);
|
|
141
|
+
tsResource.declarations.push(classDeclaration);
|
|
142
|
+
}
|
|
143
|
+
exports.parseClass = parseClass;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EnumDeclaration } from 'typescript';
|
|
2
|
+
import { Resource } from '../resources/Resource';
|
|
3
|
+
/**
|
|
4
|
+
* Parses an enum node into the declaration.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @param {resource} resource
|
|
8
|
+
* @param {EnumDeclaration} node
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseEnum(resource: Resource, node: EnumDeclaration): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseEnum = void 0;
|
|
4
|
+
const EnumDeclaration_1 = require("../declarations/EnumDeclaration");
|
|
5
|
+
const parse_utilities_1 = require("./parse-utilities");
|
|
6
|
+
/**
|
|
7
|
+
* Parses an enum node into the declaration.
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @param {resource} resource
|
|
11
|
+
* @param {EnumDeclaration} node
|
|
12
|
+
*/
|
|
13
|
+
function parseEnum(resource, node) {
|
|
14
|
+
const declaration = new EnumDeclaration_1.EnumDeclaration(node.name.text, parse_utilities_1.isNodeExported(node), node.getStart(), node.getEnd());
|
|
15
|
+
declaration.members = node.members.map(o => o.name.getText());
|
|
16
|
+
resource.declarations.push(declaration);
|
|
17
|
+
}
|
|
18
|
+
exports.parseEnum = parseEnum;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExportAssignment, ExportDeclaration } from 'typescript';
|
|
2
|
+
import { Resource } from '../resources/Resource';
|
|
3
|
+
/**
|
|
4
|
+
* Parses an export node into the declaration.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @param {Resource} resource
|
|
8
|
+
* @param {(ExportDeclaration | ExportAssignment)} node
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseExport(resource: Resource, node: ExportDeclaration | ExportAssignment): void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseExport = void 0;
|
|
4
|
+
const DefaultDeclaration_1 = require("../declarations/DefaultDeclaration");
|
|
5
|
+
const AllExport_1 = require("../exports/AllExport");
|
|
6
|
+
const AssignedExport_1 = require("../exports/AssignedExport");
|
|
7
|
+
const NamedExport_1 = require("../exports/NamedExport");
|
|
8
|
+
const SymbolSpecifier_1 = require("../SymbolSpecifier");
|
|
9
|
+
const TypescriptGuards_1 = require("../type-guards/TypescriptGuards");
|
|
10
|
+
const parse_utilities_1 = require("./parse-utilities");
|
|
11
|
+
/**
|
|
12
|
+
* Parses an export node into the declaration.
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @param {Resource} resource
|
|
16
|
+
* @param {(ExportDeclaration | ExportAssignment)} node
|
|
17
|
+
*/
|
|
18
|
+
function parseExport(resource, node) {
|
|
19
|
+
if (TypescriptGuards_1.isExportDeclaration(node)) {
|
|
20
|
+
const tsExport = node;
|
|
21
|
+
if (!TypescriptGuards_1.isStringLiteral(tsExport.moduleSpecifier) && !tsExport.exportClause) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (tsExport.getText().indexOf('*') > -1) {
|
|
25
|
+
resource.exports.push(new AllExport_1.AllExport(node.getStart(), node.getEnd(), tsExport.moduleSpecifier.text));
|
|
26
|
+
}
|
|
27
|
+
else if (tsExport.exportClause && TypescriptGuards_1.isNamedExports(tsExport.exportClause)) {
|
|
28
|
+
const lib = tsExport.moduleSpecifier;
|
|
29
|
+
const ex = new NamedExport_1.NamedExport(node.getStart(), node.getEnd(), lib ? lib.text : parse_utilities_1.getDefaultResourceIdentifier(resource));
|
|
30
|
+
ex.specifiers = tsExport.exportClause.elements.map(o => o.propertyName && o.name ?
|
|
31
|
+
new SymbolSpecifier_1.SymbolSpecifier(o.propertyName.text, o.name.text) :
|
|
32
|
+
new SymbolSpecifier_1.SymbolSpecifier(o.name.text));
|
|
33
|
+
for (const spec of ex.specifiers) {
|
|
34
|
+
if (resource.usages.indexOf(spec.alias || spec.specifier) === -1) {
|
|
35
|
+
resource.usages.push(spec.alias || spec.specifier);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
resource.exports.push(ex);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const literal = node.expression;
|
|
43
|
+
if (node.isExportEquals) {
|
|
44
|
+
resource.exports.push(new AssignedExport_1.AssignedExport(node.getStart(), node.getEnd(), literal.text, resource));
|
|
45
|
+
if (resource.usages.indexOf(literal.text) === -1) {
|
|
46
|
+
resource.usages.push(literal.text);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const name = (literal && literal.text) ? literal.text : parse_utilities_1.getDefaultResourceIdentifier(resource);
|
|
51
|
+
if (resource.usages.indexOf(name) === -1) {
|
|
52
|
+
resource.usages.push(name);
|
|
53
|
+
}
|
|
54
|
+
resource.declarations.push(new DefaultDeclaration_1.DefaultDeclaration(name, resource));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.parseExport = parseExport;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { FunctionDeclaration, MethodDeclaration, MethodSignature, Node } from 'typescript';
|
|
2
|
+
import { ConstructorDeclaration as TshConstructor } from '../declarations/ConstructorDeclaration';
|
|
3
|
+
import { FunctionDeclaration as TshFunction } from '../declarations/FunctionDeclaration';
|
|
4
|
+
import { MethodDeclaration as TshMethod } from '../declarations/MethodDeclaration';
|
|
5
|
+
import { ParameterDeclaration as TshParameter } from '../declarations/ParameterDeclaration';
|
|
6
|
+
import { Resource } from '../resources/Resource';
|
|
7
|
+
/**
|
|
8
|
+
* Parse the parts of a function. All functions / methods contain various information about used variables
|
|
9
|
+
* and parameters.
|
|
10
|
+
*
|
|
11
|
+
* @export
|
|
12
|
+
* @param {Resource} resource
|
|
13
|
+
* @param {(TshConstructor | TshMethod | TshFunction)} parent
|
|
14
|
+
* @param {Node} node
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseFunctionParts(resource: Resource, parent: TshConstructor | TshMethod | TshFunction, node: Node): void;
|
|
17
|
+
/**
|
|
18
|
+
* Parse method parameters.
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @param {(FunctionDeclaration | MethodDeclaration | MethodSignature)} node
|
|
22
|
+
* @returns {TshParameter[]}
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseMethodParams(node: FunctionDeclaration | MethodDeclaration | MethodSignature): TshParameter[];
|
|
25
|
+
/**
|
|
26
|
+
* Parses a function into its declaration.
|
|
27
|
+
* Parses the functions sub information like parameters and variables.
|
|
28
|
+
*
|
|
29
|
+
* @export
|
|
30
|
+
* @param {Resource} resource
|
|
31
|
+
* @param {FunctionDeclaration} node
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseFunction(resource: Resource, node: FunctionDeclaration): void;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseFunction = exports.parseMethodParams = exports.parseFunctionParts = void 0;
|
|
4
|
+
const typescript_1 = require("typescript");
|
|
5
|
+
const DefaultDeclaration_1 = require("../declarations/DefaultDeclaration");
|
|
6
|
+
const FunctionDeclaration_1 = require("../declarations/FunctionDeclaration");
|
|
7
|
+
const ParameterDeclaration_1 = require("../declarations/ParameterDeclaration");
|
|
8
|
+
const TypescriptGuards_1 = require("../type-guards/TypescriptGuards");
|
|
9
|
+
const identifier_parser_1 = require("./identifier-parser");
|
|
10
|
+
const parse_utilities_1 = require("./parse-utilities");
|
|
11
|
+
const variable_parser_1 = require("./variable-parser");
|
|
12
|
+
/**
|
|
13
|
+
* Parse the parts of a function. All functions / methods contain various information about used variables
|
|
14
|
+
* and parameters.
|
|
15
|
+
*
|
|
16
|
+
* @export
|
|
17
|
+
* @param {Resource} resource
|
|
18
|
+
* @param {(TshConstructor | TshMethod | TshFunction)} parent
|
|
19
|
+
* @param {Node} node
|
|
20
|
+
*/
|
|
21
|
+
function parseFunctionParts(resource, parent, node) {
|
|
22
|
+
for (const child of node.getChildren()) {
|
|
23
|
+
switch (child.kind) {
|
|
24
|
+
case typescript_1.SyntaxKind.Identifier:
|
|
25
|
+
identifier_parser_1.parseIdentifier(resource, child);
|
|
26
|
+
break;
|
|
27
|
+
case typescript_1.SyntaxKind.VariableStatement:
|
|
28
|
+
variable_parser_1.parseVariable(parent, child);
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
parseFunctionParts(resource, parent, child);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.parseFunctionParts = parseFunctionParts;
|
|
37
|
+
/**
|
|
38
|
+
* Parse method parameters.
|
|
39
|
+
*
|
|
40
|
+
* @export
|
|
41
|
+
* @param {(FunctionDeclaration | MethodDeclaration | MethodSignature)} node
|
|
42
|
+
* @returns {TshParameter[]}
|
|
43
|
+
*/
|
|
44
|
+
function parseMethodParams(node) {
|
|
45
|
+
return node.parameters.reduce((all, cur) => {
|
|
46
|
+
const params = all;
|
|
47
|
+
if (TypescriptGuards_1.isIdentifier(cur.name)) {
|
|
48
|
+
params.push(new ParameterDeclaration_1.ParameterDeclaration(cur.name.text, parse_utilities_1.getNodeType(cur.type), cur.getStart(), cur.getEnd()));
|
|
49
|
+
}
|
|
50
|
+
else if (TypescriptGuards_1.isObjectBindingPattern(cur.name)) {
|
|
51
|
+
const elements = cur.name.elements;
|
|
52
|
+
let types = [];
|
|
53
|
+
const boundParam = new ParameterDeclaration_1.ObjectBoundParameterDeclaration(cur.getStart(), cur.getEnd());
|
|
54
|
+
if (cur.type && typescript_1.isTypeReferenceNode(cur.type)) {
|
|
55
|
+
boundParam.typeReference = parse_utilities_1.getNodeType(cur.type);
|
|
56
|
+
}
|
|
57
|
+
else if (cur.type && typescript_1.isTypeLiteralNode(cur.type)) {
|
|
58
|
+
types = cur.type.members
|
|
59
|
+
.filter(member => TypescriptGuards_1.isPropertySignature(member))
|
|
60
|
+
.map((signature) => parse_utilities_1.getNodeType(signature.type));
|
|
61
|
+
}
|
|
62
|
+
boundParam.parameters = elements.map((bindingElement, index) => new ParameterDeclaration_1.ParameterDeclaration(bindingElement.name.getText(), types[index], bindingElement.getStart(), bindingElement.getEnd()));
|
|
63
|
+
params.push(boundParam);
|
|
64
|
+
}
|
|
65
|
+
else if (TypescriptGuards_1.isArrayBindingPattern(cur.name)) {
|
|
66
|
+
const elements = cur.name.elements;
|
|
67
|
+
let types = [];
|
|
68
|
+
const boundParam = new ParameterDeclaration_1.ArrayBoundParameterDeclaration(cur.getStart(), cur.getEnd());
|
|
69
|
+
if (cur.type && typescript_1.isTypeReferenceNode(cur.type)) {
|
|
70
|
+
boundParam.typeReference = parse_utilities_1.getNodeType(cur.type);
|
|
71
|
+
}
|
|
72
|
+
else if (cur.type && typescript_1.isTupleTypeNode(cur.type)) {
|
|
73
|
+
types = cur.type.elementTypes.map(type => parse_utilities_1.getNodeType(type));
|
|
74
|
+
}
|
|
75
|
+
boundParam.parameters = elements.map((bindingElement, index) => new ParameterDeclaration_1.ParameterDeclaration(bindingElement.getText(), types[index], bindingElement.getStart(), bindingElement.getEnd()));
|
|
76
|
+
params.push(boundParam);
|
|
77
|
+
}
|
|
78
|
+
return params;
|
|
79
|
+
}, []);
|
|
80
|
+
}
|
|
81
|
+
exports.parseMethodParams = parseMethodParams;
|
|
82
|
+
/**
|
|
83
|
+
* Parses a function into its declaration.
|
|
84
|
+
* Parses the functions sub information like parameters and variables.
|
|
85
|
+
*
|
|
86
|
+
* @export
|
|
87
|
+
* @param {Resource} resource
|
|
88
|
+
* @param {FunctionDeclaration} node
|
|
89
|
+
*/
|
|
90
|
+
function parseFunction(resource, node) {
|
|
91
|
+
const name = node.name ? node.name.text : parse_utilities_1.getDefaultResourceIdentifier(resource);
|
|
92
|
+
const func = new FunctionDeclaration_1.FunctionDeclaration(name, parse_utilities_1.isNodeExported(node), parse_utilities_1.containsModifier(node, typescript_1.SyntaxKind.AsyncKeyword), parse_utilities_1.getNodeType(node.type), node.getStart(), node.getEnd());
|
|
93
|
+
if (parse_utilities_1.isNodeDefaultExported(node)) {
|
|
94
|
+
func.isExported = false;
|
|
95
|
+
resource.declarations.push(new DefaultDeclaration_1.DefaultDeclaration(func.name, resource));
|
|
96
|
+
}
|
|
97
|
+
func.parameters = parseMethodParams(node);
|
|
98
|
+
resource.declarations.push(func);
|
|
99
|
+
parseFunctionParts(resource, func, node);
|
|
100
|
+
}
|
|
101
|
+
exports.parseFunction = parseFunction;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Identifier } from 'typescript';
|
|
2
|
+
import { Resource } from '../resources/Resource';
|
|
3
|
+
/**
|
|
4
|
+
* Parses an identifier into a usage of a resource if the predicates are true.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @param {Resource} resource
|
|
8
|
+
* @param {Identifier} node
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseIdentifier(resource: Resource, node: Identifier): void;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseIdentifier = void 0;
|
|
4
|
+
const typescript_1 = require("typescript");
|
|
5
|
+
const usageNotAllowedParents = [
|
|
6
|
+
typescript_1.SyntaxKind.ImportEqualsDeclaration,
|
|
7
|
+
typescript_1.SyntaxKind.ImportSpecifier,
|
|
8
|
+
typescript_1.SyntaxKind.NamespaceImport,
|
|
9
|
+
typescript_1.SyntaxKind.ClassDeclaration,
|
|
10
|
+
typescript_1.SyntaxKind.ImportEqualsDeclaration,
|
|
11
|
+
typescript_1.SyntaxKind.ImportClause,
|
|
12
|
+
typescript_1.SyntaxKind.ImportDeclaration,
|
|
13
|
+
typescript_1.SyntaxKind.InterfaceDeclaration,
|
|
14
|
+
typescript_1.SyntaxKind.ExportDeclaration,
|
|
15
|
+
typescript_1.SyntaxKind.ExportSpecifier,
|
|
16
|
+
typescript_1.SyntaxKind.ImportSpecifier,
|
|
17
|
+
typescript_1.SyntaxKind.FunctionDeclaration,
|
|
18
|
+
typescript_1.SyntaxKind.EnumDeclaration,
|
|
19
|
+
typescript_1.SyntaxKind.TypeAliasDeclaration,
|
|
20
|
+
typescript_1.SyntaxKind.MethodDeclaration,
|
|
21
|
+
];
|
|
22
|
+
const usageAllowedIfLast = [
|
|
23
|
+
typescript_1.SyntaxKind.Parameter,
|
|
24
|
+
typescript_1.SyntaxKind.PropertyDeclaration,
|
|
25
|
+
typescript_1.SyntaxKind.VariableDeclaration,
|
|
26
|
+
typescript_1.SyntaxKind.BinaryExpression,
|
|
27
|
+
];
|
|
28
|
+
const usagePredicates = [
|
|
29
|
+
(o) => o.parent !== undefined && usageNotAllowedParents.indexOf(o.parent.kind) === -1,
|
|
30
|
+
allowedIfLastIdentifier,
|
|
31
|
+
allowedIfPropertyAccessFirst,
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* Predicate function to determine if the node is possible as a "usage".
|
|
35
|
+
* Checks for the node identifier to be the last of the identifier list.
|
|
36
|
+
*
|
|
37
|
+
* @param {Node} node
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
function allowedIfLastIdentifier(node) {
|
|
41
|
+
if (!node.parent) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (usageAllowedIfLast.indexOf(node.parent.kind) === -1) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
const children = node.parent.getChildren().filter(o => o.kind === typescript_1.SyntaxKind.Identifier);
|
|
48
|
+
return children.length === 1 || children.indexOf(node) === 1;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Predicate function to determine if the node is possible as a "usage".
|
|
52
|
+
* Checks if the identifier is on the lefthand side of a property access.
|
|
53
|
+
*
|
|
54
|
+
* @param {Node} node
|
|
55
|
+
* @returns {boolean}
|
|
56
|
+
*/
|
|
57
|
+
function allowedIfPropertyAccessFirst(node) {
|
|
58
|
+
if (!node.parent) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (node.parent.kind !== typescript_1.SyntaxKind.PropertyAccessExpression) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const children = node.parent.getChildren();
|
|
65
|
+
return children.indexOf(node) === 0;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Parses an identifier into a usage of a resource if the predicates are true.
|
|
69
|
+
*
|
|
70
|
+
* @export
|
|
71
|
+
* @param {Resource} resource
|
|
72
|
+
* @param {Identifier} node
|
|
73
|
+
*/
|
|
74
|
+
function parseIdentifier(resource, node) {
|
|
75
|
+
if (node.parent && usagePredicates.every(predicate => predicate(node))) {
|
|
76
|
+
if (resource.usages.indexOf(node.text) === -1) {
|
|
77
|
+
resource.usages.push(node.text);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.parseIdentifier = parseIdentifier;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ImportDeclaration, ImportEqualsDeclaration } from 'typescript';
|
|
2
|
+
import { Resource } from '../resources/Resource';
|
|
3
|
+
/**
|
|
4
|
+
* Parses an import node into the declaration.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @param {Resource} resource
|
|
8
|
+
* @param {(ImportDeclaration | ImportEqualsDeclaration)} node
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseImport(resource: Resource, node: ImportDeclaration | ImportEqualsDeclaration): void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseImport = void 0;
|
|
4
|
+
const ExternalModuleImport_1 = require("../imports/ExternalModuleImport");
|
|
5
|
+
const NamedImport_1 = require("../imports/NamedImport");
|
|
6
|
+
const NamespaceImport_1 = require("../imports/NamespaceImport");
|
|
7
|
+
const StringImport_1 = require("../imports/StringImport");
|
|
8
|
+
const SymbolSpecifier_1 = require("../SymbolSpecifier");
|
|
9
|
+
const TypescriptGuards_1 = require("../type-guards/TypescriptGuards");
|
|
10
|
+
/**
|
|
11
|
+
* Parses an import node into the declaration.
|
|
12
|
+
*
|
|
13
|
+
* @export
|
|
14
|
+
* @param {Resource} resource
|
|
15
|
+
* @param {(ImportDeclaration | ImportEqualsDeclaration)} node
|
|
16
|
+
*/
|
|
17
|
+
function parseImport(resource, node) {
|
|
18
|
+
if (TypescriptGuards_1.isImportDeclaration(node)) {
|
|
19
|
+
if (node.importClause && TypescriptGuards_1.isNamespaceImport(node.importClause.namedBindings)) {
|
|
20
|
+
const lib = node.moduleSpecifier;
|
|
21
|
+
const alias = node.importClause.namedBindings.name;
|
|
22
|
+
resource.imports.push(new NamespaceImport_1.NamespaceImport(lib.text, alias.text, node.getStart(), node.getEnd()));
|
|
23
|
+
}
|
|
24
|
+
else if (node.importClause && (TypescriptGuards_1.isNamedImports(node.importClause.namedBindings) || node.importClause.name)) {
|
|
25
|
+
const lib = node.moduleSpecifier;
|
|
26
|
+
const tsImport = new NamedImport_1.NamedImport(lib.text, node.getStart(), node.getEnd());
|
|
27
|
+
if (node.importClause.name) {
|
|
28
|
+
tsImport.defaultAlias = node.importClause.name.text;
|
|
29
|
+
}
|
|
30
|
+
if (node.importClause.namedBindings) {
|
|
31
|
+
const bindings = node.importClause.namedBindings;
|
|
32
|
+
tsImport.specifiers = bindings.elements.map(o => o.propertyName && o.name ?
|
|
33
|
+
new SymbolSpecifier_1.SymbolSpecifier(o.propertyName.text, o.name.text) :
|
|
34
|
+
new SymbolSpecifier_1.SymbolSpecifier(o.name.text));
|
|
35
|
+
const defaultImport = tsImport.specifiers.find(imp => imp.specifier === 'default' && !!imp.alias);
|
|
36
|
+
if (defaultImport) {
|
|
37
|
+
tsImport.specifiers.splice(tsImport.specifiers.indexOf(defaultImport), 1);
|
|
38
|
+
tsImport.defaultAlias = defaultImport.alias;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
resource.imports.push(tsImport);
|
|
42
|
+
}
|
|
43
|
+
else if (node.moduleSpecifier && TypescriptGuards_1.isStringLiteral(node.moduleSpecifier)) {
|
|
44
|
+
const lib = node.moduleSpecifier;
|
|
45
|
+
resource.imports.push(new StringImport_1.StringImport(lib.text, node.getStart(), node.getEnd()));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (TypescriptGuards_1.isExternalModuleReference(node.moduleReference)) {
|
|
49
|
+
const alias = node.name;
|
|
50
|
+
const lib = node.moduleReference.expression;
|
|
51
|
+
resource.imports.push(new ExternalModuleImport_1.ExternalModuleImport(lib.text, alias.text, node.getStart(), node.getEnd()));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.parseImport = parseImport;
|