@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,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 TypeScript Heroes
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all nodes / declarations / imports / etc. in the extension.
|
|
3
|
+
* Contains basic information about the node.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @interface Node
|
|
7
|
+
*/
|
|
8
|
+
export interface Node {
|
|
9
|
+
/**
|
|
10
|
+
* The starting character of the node in the document.
|
|
11
|
+
*
|
|
12
|
+
* @type {number}
|
|
13
|
+
* @memberof Node
|
|
14
|
+
*/
|
|
15
|
+
start?: number;
|
|
16
|
+
/**
|
|
17
|
+
* The ending character of the node in the document.
|
|
18
|
+
*
|
|
19
|
+
* @type {number}
|
|
20
|
+
* @memberof Node
|
|
21
|
+
*/
|
|
22
|
+
end?: number;
|
|
23
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# node typescript parser
|
|
2
|
+
|
|
3
|
+
This package is a TypeScript and ECMAScript parser. It uses the underlying typescript parser to generate
|
|
4
|
+
a more or less human readable AST out of .js or .ts files.
|
|
5
|
+
|
|
6
|
+
[](https://travis-ci.org/buehler/node-typescript-parser)
|
|
7
|
+
[](https://ci.appveyor.com/project/buehler/node-typescript-parser)
|
|
8
|
+
[](https://www.npmjs.com/package/typescript-parser)
|
|
9
|
+
[](https://codecov.io/gh/buehler/node-typescript-parser)
|
|
10
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
11
|
+
[](https://greenkeeper.io/)
|
|
12
|
+
[](https://gitter.im/node-typescript-parser/Lobby)
|
|
13
|
+
|
|
14
|
+
## How to use
|
|
15
|
+
|
|
16
|
+
After you install the package via:
|
|
17
|
+
|
|
18
|
+
[](https://nodei.co/npm/typescript-parser/)
|
|
19
|
+
|
|
20
|
+
### [View Source Docs](https://buehler.github.io/node-typescript-parser/)
|
|
21
|
+
|
|
22
|
+
You can use the parser with:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
const parser = new TypescriptParser();
|
|
26
|
+
|
|
27
|
+
// either:
|
|
28
|
+
const parsed = await parser.parseSource(/* typescript source code as string */);
|
|
29
|
+
|
|
30
|
+
// or a filepath
|
|
31
|
+
const parsed = await parser.parseFile('/user/myfile.ts', 'workspace root');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
You can also parse multiple files at ones.
|
|
35
|
+
|
|
36
|
+
To use the declaration index (which is basically a list of symbols for your files)
|
|
37
|
+
instantiate an index first and throw him some files.
|
|
38
|
+
|
|
39
|
+
After the parsing is done, you'll get an index with resolved
|
|
40
|
+
exports and declarations.
|
|
41
|
+
|
|
42
|
+
Keep in mind, that the index'll only contain exported declarations.
|
|
43
|
+
|
|
44
|
+
## Changelog
|
|
45
|
+
|
|
46
|
+
The changelog is generated by [semantic release](https://github.com/semantic-release/semantic-release) and is located under the
|
|
47
|
+
[release section](https://github.com/buehler/node-typescript-parser/releases).
|
|
48
|
+
|
|
49
|
+
## Licence
|
|
50
|
+
|
|
51
|
+
This software is licenced under the [MIT](LICENSE) licence.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Clonable } from './clonable/Clonable';
|
|
2
|
+
/**
|
|
3
|
+
* Class for symbols that are contained in a named import or export or anywhere. Basically an aliased object.
|
|
4
|
+
* (i.e. import {SYMBOL} from '...').
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class SymbolSpecifier
|
|
8
|
+
* @implements {Clonable}
|
|
9
|
+
*/
|
|
10
|
+
export declare class SymbolSpecifier implements Clonable<SymbolSpecifier> {
|
|
11
|
+
specifier: string;
|
|
12
|
+
alias?: string | undefined;
|
|
13
|
+
constructor(specifier: string, alias?: string | undefined);
|
|
14
|
+
/**
|
|
15
|
+
* Clones the current resolve specifier and returns a new instance with the same properties.
|
|
16
|
+
*
|
|
17
|
+
* @returns {SymbolSpecifier}
|
|
18
|
+
*
|
|
19
|
+
* @memberof SymbolSpecifier
|
|
20
|
+
*/
|
|
21
|
+
clone(): SymbolSpecifier;
|
|
22
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SymbolSpecifier = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Class for symbols that are contained in a named import or export or anywhere. Basically an aliased object.
|
|
6
|
+
* (i.e. import {SYMBOL} from '...').
|
|
7
|
+
*
|
|
8
|
+
* @export
|
|
9
|
+
* @class SymbolSpecifier
|
|
10
|
+
* @implements {Clonable}
|
|
11
|
+
*/
|
|
12
|
+
class SymbolSpecifier {
|
|
13
|
+
constructor(specifier, alias) {
|
|
14
|
+
this.specifier = specifier;
|
|
15
|
+
this.alias = alias;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Clones the current resolve specifier and returns a new instance with the same properties.
|
|
19
|
+
*
|
|
20
|
+
* @returns {SymbolSpecifier}
|
|
21
|
+
*
|
|
22
|
+
* @memberof SymbolSpecifier
|
|
23
|
+
*/
|
|
24
|
+
clone() {
|
|
25
|
+
return new SymbolSpecifier(this.specifier, this.alias);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.SymbolSpecifier = SymbolSpecifier;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ScriptKind } from 'typescript';
|
|
2
|
+
import { File } from './resources/File';
|
|
3
|
+
/**
|
|
4
|
+
* Magic.happens('here');
|
|
5
|
+
* This class is the parser of the whole extension. It uses the typescript compiler to parse a file or given
|
|
6
|
+
* source code into the token stream and therefore into the AST of the source. Afterwards an array of
|
|
7
|
+
* resources is generated and returned.
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @class TypescriptParser
|
|
11
|
+
*/
|
|
12
|
+
export declare class TypescriptParser {
|
|
13
|
+
/**
|
|
14
|
+
* Parses the given source into an anonymous File resource.
|
|
15
|
+
* Mainly used to parse source code of a document.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} source
|
|
18
|
+
* @param {ScriptKind} [scriptKind=ScriptKind.TS]
|
|
19
|
+
* @returns {Promise<File>}
|
|
20
|
+
*
|
|
21
|
+
* @memberof TsResourceParser
|
|
22
|
+
*/
|
|
23
|
+
parseSource(source: string, scriptKind?: ScriptKind): Promise<File>;
|
|
24
|
+
/**
|
|
25
|
+
* Parses a single file into a parsed file.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} filePath
|
|
28
|
+
* @param {string} rootPath
|
|
29
|
+
* @returns {Promise<File>}
|
|
30
|
+
*
|
|
31
|
+
* @memberof TsResourceParser
|
|
32
|
+
*/
|
|
33
|
+
parseFile(filePath: string, rootPath: string): Promise<File>;
|
|
34
|
+
/**
|
|
35
|
+
* Parses multiple files into parsed files.
|
|
36
|
+
*
|
|
37
|
+
* @param {string[]} filePathes
|
|
38
|
+
* @param {string} rootPath
|
|
39
|
+
* @returns {Promise<File[]>}
|
|
40
|
+
*
|
|
41
|
+
* @memberof TsResourceParser
|
|
42
|
+
*/
|
|
43
|
+
parseFiles(filePathes: string[], rootPath: string): Promise<File[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Parses the typescript source into the file instance. Calls .parse afterwards to
|
|
46
|
+
* get the declarations and other information about the source.
|
|
47
|
+
*
|
|
48
|
+
* @private
|
|
49
|
+
* @param {SourceFile} source
|
|
50
|
+
* @param {string} rootPath
|
|
51
|
+
* @returns {TsFile}
|
|
52
|
+
*
|
|
53
|
+
* @memberof TsResourceParser
|
|
54
|
+
*/
|
|
55
|
+
private parseTypescript;
|
|
56
|
+
/**
|
|
57
|
+
* Recursive function that runs through the AST of a source and parses the nodes.
|
|
58
|
+
* Creates the class / function / etc declarations and instanciates a new module / namespace
|
|
59
|
+
* resource if needed.
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
* @param {Resource} resource
|
|
63
|
+
* @param {Node} node
|
|
64
|
+
*
|
|
65
|
+
* @memberof TsResourceParser
|
|
66
|
+
*/
|
|
67
|
+
private parse;
|
|
68
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypescriptParser = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const typescript_1 = require("typescript");
|
|
8
|
+
const class_parser_1 = require("./node-parser/class-parser");
|
|
9
|
+
const enum_parser_1 = require("./node-parser/enum-parser");
|
|
10
|
+
const export_parser_1 = require("./node-parser/export-parser");
|
|
11
|
+
const function_parser_1 = require("./node-parser/function-parser");
|
|
12
|
+
const identifier_parser_1 = require("./node-parser/identifier-parser");
|
|
13
|
+
const import_parser_1 = require("./node-parser/import-parser");
|
|
14
|
+
const interface_parser_1 = require("./node-parser/interface-parser");
|
|
15
|
+
const module_parser_1 = require("./node-parser/module-parser");
|
|
16
|
+
const traverse_ast_1 = require("./node-parser/traverse-ast");
|
|
17
|
+
const type_alias_parser_1 = require("./node-parser/type-alias-parser");
|
|
18
|
+
const variable_parser_1 = require("./node-parser/variable-parser");
|
|
19
|
+
const File_1 = require("./resources/File");
|
|
20
|
+
/**
|
|
21
|
+
* Magic.happens('here');
|
|
22
|
+
* This class is the parser of the whole extension. It uses the typescript compiler to parse a file or given
|
|
23
|
+
* source code into the token stream and therefore into the AST of the source. Afterwards an array of
|
|
24
|
+
* resources is generated and returned.
|
|
25
|
+
*
|
|
26
|
+
* @export
|
|
27
|
+
* @class TypescriptParser
|
|
28
|
+
*/
|
|
29
|
+
class TypescriptParser {
|
|
30
|
+
/**
|
|
31
|
+
* Parses the given source into an anonymous File resource.
|
|
32
|
+
* Mainly used to parse source code of a document.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} source
|
|
35
|
+
* @param {ScriptKind} [scriptKind=ScriptKind.TS]
|
|
36
|
+
* @returns {Promise<File>}
|
|
37
|
+
*
|
|
38
|
+
* @memberof TsResourceParser
|
|
39
|
+
*/
|
|
40
|
+
parseSource(source, scriptKind = typescript_1.ScriptKind.TS) {
|
|
41
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
return yield this.parseTypescript(typescript_1.createSourceFile('inline.tsx', source, typescript_1.ScriptTarget.ES2015, true, scriptKind), '/');
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parses a single file into a parsed file.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} filePath
|
|
49
|
+
* @param {string} rootPath
|
|
50
|
+
* @returns {Promise<File>}
|
|
51
|
+
*
|
|
52
|
+
* @memberof TsResourceParser
|
|
53
|
+
*/
|
|
54
|
+
parseFile(filePath, rootPath) {
|
|
55
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const parse = yield this.parseFiles([filePath], rootPath);
|
|
57
|
+
return parse[0];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// public async parseFilesNew(filePaths: string[], rootPath: string): Promise<File[]> {
|
|
61
|
+
// const compilerOptions = {
|
|
62
|
+
// target: ScriptTarget.ES5
|
|
63
|
+
// };
|
|
64
|
+
// const compilerHost = createCompilerHost(compilerOptions);
|
|
65
|
+
// const program = createProgram(filePaths, compilerOptions, compilerHost);
|
|
66
|
+
// const typeChecker = program.getTypeChecker();
|
|
67
|
+
// const files: File[] = [];
|
|
68
|
+
// for (const sourceFile of program.getSourceFiles())
|
|
69
|
+
// files.push(this.parseTypescript(sourceFile, rootPath, typeChecker));
|
|
70
|
+
// return files;
|
|
71
|
+
// }
|
|
72
|
+
/**
|
|
73
|
+
* Parses multiple files into parsed files.
|
|
74
|
+
*
|
|
75
|
+
* @param {string[]} filePathes
|
|
76
|
+
* @param {string} rootPath
|
|
77
|
+
* @returns {Promise<File[]>}
|
|
78
|
+
*
|
|
79
|
+
* @memberof TsResourceParser
|
|
80
|
+
*/
|
|
81
|
+
parseFiles(filePathes, rootPath) {
|
|
82
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return filePathes
|
|
84
|
+
.map((o) => {
|
|
85
|
+
let scriptKind = typescript_1.ScriptKind.Unknown;
|
|
86
|
+
const parsed = path_1.parse(o);
|
|
87
|
+
switch (parsed.ext.toLowerCase()) {
|
|
88
|
+
case 'js':
|
|
89
|
+
scriptKind = typescript_1.ScriptKind.JS;
|
|
90
|
+
break;
|
|
91
|
+
case 'jsx':
|
|
92
|
+
scriptKind = typescript_1.ScriptKind.JSX;
|
|
93
|
+
break;
|
|
94
|
+
case 'ts':
|
|
95
|
+
scriptKind = typescript_1.ScriptKind.TS;
|
|
96
|
+
break;
|
|
97
|
+
case 'tsx':
|
|
98
|
+
scriptKind = typescript_1.ScriptKind.TSX;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
return typescript_1.createSourceFile(o, fs_1.readFileSync(o).toString(), typescript_1.ScriptTarget.ES2015, true, scriptKind);
|
|
102
|
+
})
|
|
103
|
+
.map(o => this.parseTypescript(o, rootPath));
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Parses the typescript source into the file instance. Calls .parse afterwards to
|
|
108
|
+
* get the declarations and other information about the source.
|
|
109
|
+
*
|
|
110
|
+
* @private
|
|
111
|
+
* @param {SourceFile} source
|
|
112
|
+
* @param {string} rootPath
|
|
113
|
+
* @returns {TsFile}
|
|
114
|
+
*
|
|
115
|
+
* @memberof TsResourceParser
|
|
116
|
+
*/
|
|
117
|
+
parseTypescript(source, rootPath) {
|
|
118
|
+
const file = new File_1.File(source.fileName, rootPath, source.getStart(), source.getEnd());
|
|
119
|
+
const syntaxList = source.getChildAt(0);
|
|
120
|
+
this.parse(file, syntaxList);
|
|
121
|
+
return file;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Recursive function that runs through the AST of a source and parses the nodes.
|
|
125
|
+
* Creates the class / function / etc declarations and instanciates a new module / namespace
|
|
126
|
+
* resource if needed.
|
|
127
|
+
*
|
|
128
|
+
* @private
|
|
129
|
+
* @param {Resource} resource
|
|
130
|
+
* @param {Node} node
|
|
131
|
+
*
|
|
132
|
+
* @memberof TsResourceParser
|
|
133
|
+
*/
|
|
134
|
+
parse(resource, root) {
|
|
135
|
+
const modules = [{ moduleRoot: root, moduleResource: resource }];
|
|
136
|
+
for (let iter = modules.shift(); iter !== undefined; iter = modules.shift()) {
|
|
137
|
+
const { moduleRoot, moduleResource } = iter;
|
|
138
|
+
traverse_ast_1.traverseAst(moduleRoot, (node) => {
|
|
139
|
+
switch (node.kind) {
|
|
140
|
+
case typescript_1.SyntaxKind.ImportDeclaration:
|
|
141
|
+
case typescript_1.SyntaxKind.ImportEqualsDeclaration:
|
|
142
|
+
import_parser_1.parseImport(moduleResource, node);
|
|
143
|
+
break;
|
|
144
|
+
case typescript_1.SyntaxKind.ExportDeclaration:
|
|
145
|
+
case typescript_1.SyntaxKind.ExportAssignment:
|
|
146
|
+
export_parser_1.parseExport(moduleResource, node);
|
|
147
|
+
break;
|
|
148
|
+
case typescript_1.SyntaxKind.EnumDeclaration:
|
|
149
|
+
enum_parser_1.parseEnum(moduleResource, node);
|
|
150
|
+
break;
|
|
151
|
+
case typescript_1.SyntaxKind.TypeAliasDeclaration:
|
|
152
|
+
type_alias_parser_1.parseTypeAlias(moduleResource, node);
|
|
153
|
+
break;
|
|
154
|
+
case typescript_1.SyntaxKind.FunctionDeclaration:
|
|
155
|
+
function_parser_1.parseFunction(moduleResource, node);
|
|
156
|
+
break;
|
|
157
|
+
case typescript_1.SyntaxKind.VariableStatement:
|
|
158
|
+
variable_parser_1.parseVariable(moduleResource, node);
|
|
159
|
+
break;
|
|
160
|
+
case typescript_1.SyntaxKind.InterfaceDeclaration:
|
|
161
|
+
interface_parser_1.parseInterface(moduleResource, node);
|
|
162
|
+
break;
|
|
163
|
+
case typescript_1.SyntaxKind.ClassDeclaration:
|
|
164
|
+
class_parser_1.parseClass(moduleResource, node);
|
|
165
|
+
break;
|
|
166
|
+
case typescript_1.SyntaxKind.Identifier:
|
|
167
|
+
identifier_parser_1.parseIdentifier(moduleResource, node);
|
|
168
|
+
break;
|
|
169
|
+
case typescript_1.SyntaxKind.ModuleDeclaration:
|
|
170
|
+
modules.push({
|
|
171
|
+
moduleRoot: node,
|
|
172
|
+
moduleResource: module_parser_1.parseModule(moduleResource, node),
|
|
173
|
+
});
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}, (node) => {
|
|
179
|
+
switch (node.kind) {
|
|
180
|
+
case typescript_1.SyntaxKind.ClassDeclaration:
|
|
181
|
+
case typescript_1.SyntaxKind.ModuleDeclaration:
|
|
182
|
+
case typescript_1.SyntaxKind.FunctionDeclaration:
|
|
183
|
+
return true;
|
|
184
|
+
default:
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.TypescriptParser = TypescriptParser;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for clonable objects. The clone() method creates a deep clone of the object.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @template T
|
|
6
|
+
* @interface Clonable
|
|
7
|
+
*/
|
|
8
|
+
export interface Clonable<T> {
|
|
9
|
+
/**
|
|
10
|
+
* Create a deep clone of this object.
|
|
11
|
+
*
|
|
12
|
+
* @returns {T}
|
|
13
|
+
*
|
|
14
|
+
* @memberof Clonable
|
|
15
|
+
*/
|
|
16
|
+
clone(): T;
|
|
17
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Declaration } from '../declarations/Declaration';
|
|
2
|
+
import { Export } from '../exports/Export';
|
|
3
|
+
import { Import } from '../imports/Import';
|
|
4
|
+
import { SymbolSpecifier } from '../SymbolSpecifier';
|
|
5
|
+
import { TypescriptGenerationOptions } from './TypescriptGenerationOptions';
|
|
6
|
+
/**
|
|
7
|
+
* All generatable items combined. If the element is not generatable, the specific generator should throw
|
|
8
|
+
* an exception.
|
|
9
|
+
*/
|
|
10
|
+
export declare type Generatable = Declaration | Import | Export | SymbolSpecifier;
|
|
11
|
+
/**
|
|
12
|
+
* Type for generators.
|
|
13
|
+
*/
|
|
14
|
+
export declare type Generators = {
|
|
15
|
+
[name: string]: (generatable: Generatable, options: TypescriptGenerationOptions) => string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Hash with all possible (yet implemented) generators.
|
|
19
|
+
*/
|
|
20
|
+
export declare const GENERATORS: Generators;
|
|
21
|
+
/**
|
|
22
|
+
* Generator for typescript code elements. Takes a generatable object and tries to generate typescript code.
|
|
23
|
+
*
|
|
24
|
+
* @export
|
|
25
|
+
* @class TypescriptCodeGenerator
|
|
26
|
+
*/
|
|
27
|
+
export declare class TypescriptCodeGenerator {
|
|
28
|
+
private options;
|
|
29
|
+
constructor(options: TypescriptGenerationOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Generator function. Calls the specific element generator. If no generator is found, an exception is thrown.
|
|
32
|
+
*
|
|
33
|
+
* @param {Generatable} declaration
|
|
34
|
+
* @returns {string}
|
|
35
|
+
* @throws {NotGeneratableYetError}
|
|
36
|
+
* @memberof TypescriptCodeGenerator
|
|
37
|
+
*/
|
|
38
|
+
generate(declaration: Generatable): string;
|
|
39
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypescriptCodeGenerator = exports.GENERATORS = void 0;
|
|
4
|
+
const AccessorDeclaration_1 = require("../declarations/AccessorDeclaration");
|
|
5
|
+
const MethodDeclaration_1 = require("../declarations/MethodDeclaration");
|
|
6
|
+
const ParameterDeclaration_1 = require("../declarations/ParameterDeclaration");
|
|
7
|
+
const PropertyDeclaration_1 = require("../declarations/PropertyDeclaration");
|
|
8
|
+
const VariableDeclaration_1 = require("../declarations/VariableDeclaration");
|
|
9
|
+
const NotGeneratableYetError_1 = require("../errors/NotGeneratableYetError");
|
|
10
|
+
const ExternalModuleImport_1 = require("../imports/ExternalModuleImport");
|
|
11
|
+
const NamedImport_1 = require("../imports/NamedImport");
|
|
12
|
+
const NamespaceImport_1 = require("../imports/NamespaceImport");
|
|
13
|
+
const StringImport_1 = require("../imports/StringImport");
|
|
14
|
+
const SymbolSpecifier_1 = require("../SymbolSpecifier");
|
|
15
|
+
const accessorDeclaration_1 = require("./typescript-generators/accessorDeclaration");
|
|
16
|
+
const externalModuleImport_1 = require("./typescript-generators/externalModuleImport");
|
|
17
|
+
const methodDeclaration_1 = require("./typescript-generators/methodDeclaration");
|
|
18
|
+
const namedImport_1 = require("./typescript-generators/namedImport");
|
|
19
|
+
const namespaceImport_1 = require("./typescript-generators/namespaceImport");
|
|
20
|
+
const parameterDeclaration_1 = require("./typescript-generators/parameterDeclaration");
|
|
21
|
+
const propertyDeclaration_1 = require("./typescript-generators/propertyDeclaration");
|
|
22
|
+
const stringImport_1 = require("./typescript-generators/stringImport");
|
|
23
|
+
const symbolSpecifier_1 = require("./typescript-generators/symbolSpecifier");
|
|
24
|
+
const variableDeclaration_1 = require("./typescript-generators/variableDeclaration");
|
|
25
|
+
/**
|
|
26
|
+
* Hash with all possible (yet implemented) generators.
|
|
27
|
+
*/
|
|
28
|
+
exports.GENERATORS = {
|
|
29
|
+
[SymbolSpecifier_1.SymbolSpecifier.name]: symbolSpecifier_1.generateSymbolSpecifier,
|
|
30
|
+
[MethodDeclaration_1.MethodDeclaration.name]: methodDeclaration_1.generateMethodDeclaration,
|
|
31
|
+
[ParameterDeclaration_1.ParameterDeclaration.name]: parameterDeclaration_1.generateParameterDeclaration,
|
|
32
|
+
[PropertyDeclaration_1.PropertyDeclaration.name]: propertyDeclaration_1.generatePropertyDeclaration,
|
|
33
|
+
[VariableDeclaration_1.VariableDeclaration.name]: variableDeclaration_1.generateVariableDelcaration,
|
|
34
|
+
[ExternalModuleImport_1.ExternalModuleImport.name]: externalModuleImport_1.generateExternalModuleImport,
|
|
35
|
+
[NamedImport_1.NamedImport.name]: namedImport_1.generateNamedImport,
|
|
36
|
+
[NamespaceImport_1.NamespaceImport.name]: namespaceImport_1.generateNamespaceImport,
|
|
37
|
+
[StringImport_1.StringImport.name]: stringImport_1.generateStringImport,
|
|
38
|
+
[AccessorDeclaration_1.SetterDeclaration.name]: accessorDeclaration_1.generateAccessorDeclaration,
|
|
39
|
+
[AccessorDeclaration_1.GetterDeclaration.name]: accessorDeclaration_1.generateAccessorDeclaration,
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Generator for typescript code elements. Takes a generatable object and tries to generate typescript code.
|
|
43
|
+
*
|
|
44
|
+
* @export
|
|
45
|
+
* @class TypescriptCodeGenerator
|
|
46
|
+
*/
|
|
47
|
+
class TypescriptCodeGenerator {
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.options = options;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Generator function. Calls the specific element generator. If no generator is found, an exception is thrown.
|
|
53
|
+
*
|
|
54
|
+
* @param {Generatable} declaration
|
|
55
|
+
* @returns {string}
|
|
56
|
+
* @throws {NotGeneratableYetError}
|
|
57
|
+
* @memberof TypescriptCodeGenerator
|
|
58
|
+
*/
|
|
59
|
+
generate(declaration) {
|
|
60
|
+
if (exports.GENERATORS[declaration.constructor.name]) {
|
|
61
|
+
return exports.GENERATORS[declaration.constructor.name](declaration, this.options);
|
|
62
|
+
}
|
|
63
|
+
throw new NotGeneratableYetError_1.NotGeneratableYetError(declaration);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.TypescriptCodeGenerator = TypescriptCodeGenerator;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare enum MultiLineImportRule {
|
|
2
|
+
strictlyOneImportPerLine = "strictlyOneImportPerLine",
|
|
3
|
+
oneImportPerLineOnlyAfterThreshold = "oneImportPerLineOnlyAfterThreshold",
|
|
4
|
+
multipleImportsPerLine = "multipleImportsPerLine"
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Typescript generation options type. Contains all information needed to stringify some objects to typescript.
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @interface TypescriptGenerationOptions
|
|
11
|
+
*/
|
|
12
|
+
export interface TypescriptGenerationOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Which quote type should be used (' or ").
|
|
15
|
+
*
|
|
16
|
+
* @type {string}
|
|
17
|
+
* @memberof TypescriptGenerationOptions
|
|
18
|
+
*/
|
|
19
|
+
stringQuoteStyle: string;
|
|
20
|
+
/**
|
|
21
|
+
* Defines end of line character (semicolon or nothing).
|
|
22
|
+
*
|
|
23
|
+
* @type {('' | ';')}
|
|
24
|
+
* @memberof TypescriptGenerationOptions
|
|
25
|
+
*/
|
|
26
|
+
eol: '' | ';';
|
|
27
|
+
/**
|
|
28
|
+
* Defines if the symbols should have spacing in the braces ({ Foo } or {Foo}).
|
|
29
|
+
*
|
|
30
|
+
* @type {boolean}
|
|
31
|
+
* @memberof TypescriptGenerationOptions
|
|
32
|
+
*/
|
|
33
|
+
spaceBraces: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The wrapping methodology to be used for imports.
|
|
36
|
+
*
|
|
37
|
+
* @type {MultiLineImportRule}
|
|
38
|
+
* @memberof TypescriptGenerationOptions
|
|
39
|
+
*/
|
|
40
|
+
wrapMethod: MultiLineImportRule;
|
|
41
|
+
/**
|
|
42
|
+
* The threshold where an import is written as multiline.
|
|
43
|
+
*
|
|
44
|
+
* @type {number}
|
|
45
|
+
* @memberof TypescriptGenerationOptions
|
|
46
|
+
*/
|
|
47
|
+
multiLineWrapThreshold: number;
|
|
48
|
+
/**
|
|
49
|
+
* Defines if the last line of a multiline import should have a comma.
|
|
50
|
+
*
|
|
51
|
+
* @type {boolean}
|
|
52
|
+
* @memberof TypescriptGenerationOptions
|
|
53
|
+
*/
|
|
54
|
+
multiLineTrailingComma: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* How many spaces of indentiation.
|
|
57
|
+
*
|
|
58
|
+
* @type {number}
|
|
59
|
+
* @memberof TypescriptGenerationOptions
|
|
60
|
+
*/
|
|
61
|
+
tabSize: number;
|
|
62
|
+
/**
|
|
63
|
+
* Insert spaces instead of tabs (default: true)
|
|
64
|
+
*
|
|
65
|
+
* @type {boolean}
|
|
66
|
+
* @memberof TypescriptGenerationOptions
|
|
67
|
+
*/
|
|
68
|
+
insertSpaces: boolean;
|
|
69
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultiLineImportRule = void 0;
|
|
4
|
+
var MultiLineImportRule;
|
|
5
|
+
(function (MultiLineImportRule) {
|
|
6
|
+
MultiLineImportRule["strictlyOneImportPerLine"] = "strictlyOneImportPerLine";
|
|
7
|
+
MultiLineImportRule["oneImportPerLineOnlyAfterThreshold"] = "oneImportPerLineOnlyAfterThreshold";
|
|
8
|
+
MultiLineImportRule["multipleImportsPerLine"] = "multipleImportsPerLine";
|
|
9
|
+
})(MultiLineImportRule = exports.MultiLineImportRule || (exports.MultiLineImportRule = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AccessorDeclaration } from '../../declarations/AccessorDeclaration';
|
|
2
|
+
import { TypescriptGenerationOptions } from '../TypescriptGenerationOptions';
|
|
3
|
+
/**
|
|
4
|
+
* Generates typescript code for a class property accessor.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @param {AccessorDeclaration} accessor
|
|
8
|
+
* @param {TypescriptGenerationOptions} { tabSize }
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateAccessorDeclaration(accessor: AccessorDeclaration, { tabSize }: TypescriptGenerationOptions): string;
|
package/dist/modules/typescript-parser/code-generators/typescript-generators/accessorDeclaration.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateAccessorDeclaration = void 0;
|
|
4
|
+
const AccessorDeclaration_1 = require("../../declarations/AccessorDeclaration");
|
|
5
|
+
const DeclarationVisibility_1 = require("../../declarations/DeclarationVisibility");
|
|
6
|
+
/**
|
|
7
|
+
* Generates typescript code for a class property accessor.
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @param {AccessorDeclaration} accessor
|
|
11
|
+
* @param {TypescriptGenerationOptions} { tabSize }
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
function generateAccessorDeclaration(accessor, { tabSize }) {
|
|
15
|
+
const tabs = Array(tabSize + 1).join(' ');
|
|
16
|
+
let definitionLine;
|
|
17
|
+
if (accessor instanceof AccessorDeclaration_1.SetterDeclaration) {
|
|
18
|
+
definitionLine = `${tabs}${accessor.visibility !== undefined ? DeclarationVisibility_1.getVisibilityText(accessor.visibility) + ' ' : ''}` +
|
|
19
|
+
`${accessor.isAbstract ? 'abstract ' : ''}` +
|
|
20
|
+
`set ${accessor.name}(value${accessor.type ? `: ${accessor.type}` : ''})`;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
definitionLine = `${tabs}${accessor.visibility !== undefined ? DeclarationVisibility_1.getVisibilityText(accessor.visibility) + ' ' : ''}` +
|
|
24
|
+
`${accessor.isAbstract ? 'abstract ' : ''}` +
|
|
25
|
+
`get ${accessor.name}()${accessor.type ? `: ${accessor.type}` : ''}`;
|
|
26
|
+
}
|
|
27
|
+
if (accessor.isAbstract) {
|
|
28
|
+
return `${definitionLine};`;
|
|
29
|
+
}
|
|
30
|
+
return `${definitionLine} {
|
|
31
|
+
${tabs}${tabs}throw new Error('Not implemented yet.');
|
|
32
|
+
${tabs}}\n`;
|
|
33
|
+
}
|
|
34
|
+
exports.generateAccessorDeclaration = generateAccessorDeclaration;
|