├── .coveralls.yml ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .vscode ├── cSpell.json ├── launch.json ├── settings.json └── tasks.json ├── LICENSE ├── README.md ├── examples └── simple │ ├── exported-const-variables.ts │ ├── exported-functions.ts │ ├── index.ts │ ├── my-types.ts │ ├── package.json │ └── tsconfig.json ├── package-lock.json ├── package.json ├── src ├── abstractions │ ├── api-callable-base.ts │ └── api-item.ts ├── api-helpers.ts ├── api-registry.ts ├── api-type-helpers.ts ├── contracts.ts ├── contracts │ ├── access-modifier.ts │ ├── api-definitions.ts │ ├── api-item-location-dto.ts │ ├── api-item-reference.ts │ ├── api-metadata-dto.ts │ ├── api-types.ts │ ├── dictionary.ts │ ├── extractor-options.ts │ └── registry.ts ├── debug.ts ├── definitions │ ├── api-call.ts │ ├── api-class-constructor.ts │ ├── api-class-method.ts │ ├── api-class-property.ts │ ├── api-class.ts │ ├── api-construct.ts │ ├── api-enum-member.ts │ ├── api-enum.ts │ ├── api-export-specifier.ts │ ├── api-export.ts │ ├── api-function-expression.ts │ ├── api-function.ts │ ├── api-get-accessor.ts │ ├── api-import-specifier.ts │ ├── api-index.ts │ ├── api-interface.ts │ ├── api-mapped.ts │ ├── api-method.ts │ ├── api-namespace.ts │ ├── api-parameter.ts │ ├── api-property.ts │ ├── api-set-accessor.ts │ ├── api-source-file.ts │ ├── api-type-alias.ts │ ├── api-type-literal.ts │ ├── api-type-parameter.ts │ └── api-variable.ts ├── extractor.ts ├── index.ts ├── internal.ts ├── ts-helpers.ts └── utils │ ├── logger.ts │ ├── path-is-inside.ts │ └── tsconfig-json.ts ├── tests ├── .gitignore ├── __tests__ │ ├── extractor.test.ts │ ├── file-with-errors.ts │ ├── ts-helpers.test.ts │ └── utils │ │ ├── __snapshots__ │ │ └── tsconfig-json.test.ts.snap │ │ ├── _tsconfig.json │ │ └── tsconfig-json.test.ts ├── cases │ ├── __tests__ │ │ └── __snapshots__ │ │ │ ├── class-declaration1.test.ts.snap │ │ │ ├── class-declaration10.test.ts.snap │ │ │ ├── class-declaration11.test.ts.snap │ │ │ ├── class-declaration12.test.ts.snap │ │ │ ├── class-declaration2.test.ts.snap │ │ │ ├── class-declaration3.test.ts.snap │ │ │ ├── class-declaration4.test.ts.snap │ │ │ ├── class-declaration5.test.ts.snap │ │ │ ├── class-declaration6.test.ts.snap │ │ │ ├── class-declaration7.test.ts.snap │ │ │ ├── class-declaration8.test.ts.snap │ │ │ ├── class-declaration9.test.ts.snap │ │ │ ├── construct-signature1.test.ts.snap │ │ │ ├── construct-signature2.test.ts.snap │ │ │ ├── enum-declaration1.test.ts.snap │ │ │ ├── enum-declaration2.test.ts.snap │ │ │ ├── enum-declaration3.test.ts.snap │ │ │ ├── enum-declaration4.test.ts.snap │ │ │ ├── export-declaration1.test.ts.snap │ │ │ ├── export-declaration2.test.ts.snap │ │ │ ├── export-specifier1.test.ts.snap │ │ │ ├── export-specifier2.test.ts.snap │ │ │ ├── export-specifier3.test.ts.snap │ │ │ ├── export-specifier4.test.ts.snap │ │ │ ├── extractor-empty-file.test.ts.snap │ │ │ ├── function-declaration1.test.ts.snap │ │ │ ├── function-declaration2.test.ts.snap │ │ │ ├── function-declaration3.test.ts.snap │ │ │ ├── function-declaration4.test.ts.snap │ │ │ ├── function-declaration5.test.ts.snap │ │ │ ├── function-declaration6.test.ts.snap │ │ │ ├── function-declaration7.test.ts.snap │ │ │ ├── function-declaration8.test.ts.snap │ │ │ ├── get-accessor1.test.ts.snap │ │ │ ├── get-accessor3.test.ts.snap │ │ │ ├── import-declaration1.test.ts.snap │ │ │ ├── import-specifier1.test.ts.snap │ │ │ ├── import-specifier2.test.ts.snap │ │ │ ├── index-signature1.test.ts.snap │ │ │ ├── index-signature2.test.ts.snap │ │ │ ├── index-signature3.test.ts.snap │ │ │ ├── interface-class-merging.test.ts.snap │ │ │ ├── interface-declaration1.test.ts.snap │ │ │ ├── interface-declaration2.test.ts.snap │ │ │ ├── interface-declaration3.test.ts.snap │ │ │ ├── interface-declaration4.test.ts.snap │ │ │ ├── interface-declaration5.test.ts.snap │ │ │ ├── interface-declaration6.test.ts.snap │ │ │ ├── interface-declaration7.test.ts.snap │ │ │ ├── interface-subtyping.test.ts.snap │ │ │ ├── mapped-declaration1.test.ts.snap │ │ │ ├── mapped-declaration2.test.ts.snap │ │ │ ├── mapped-declaration3.test.ts.snap │ │ │ ├── mapped-declaration4.test.ts.snap │ │ │ ├── multiple-declaration.test.ts.snap │ │ │ ├── namespace-declaration1.test.ts.snap │ │ │ ├── namespace-declaration2.test.ts.snap │ │ │ ├── namespace-declaration3.test.ts.snap │ │ │ ├── object-literal1.test.ts.snap │ │ │ ├── parameter-declaration1.test.ts.snap │ │ │ ├── parameter-declaration2.test.ts.snap │ │ │ ├── parameter-declaration3.test.ts.snap │ │ │ ├── set-accessor1.test.ts.snap │ │ │ ├── set-accessor2.test.ts.snap │ │ │ ├── set-accessor3.test.ts.snap │ │ │ ├── symbol1.test.ts.snap │ │ │ ├── type-alias-declaration1.test.ts.snap │ │ │ ├── type-alias-declaration2.test.ts.snap │ │ │ ├── type-alias-declaration3.test.ts.snap │ │ │ ├── type-alias-declaration4.test.ts.snap │ │ │ ├── type-alias-declaration5.test.ts.snap │ │ │ ├── type-alias-declaration6.test.ts.snap │ │ │ ├── type-alias-declaration7.test.ts.snap │ │ │ ├── type-alias-declaration8.test.ts.snap │ │ │ ├── type-parameter-declaration1.test.ts.snap │ │ │ ├── type-parameter-declaration2.test.ts.snap │ │ │ ├── type-parameter-declaration3.test.ts.snap │ │ │ ├── variable-declaration1.test.ts.snap │ │ │ ├── variable-declaration2.test.ts.snap │ │ │ ├── variable-declaration3.test.ts.snap │ │ │ └── variable-declaration4.test.ts.snap │ ├── class-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration10 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration11 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration12 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration4 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration5 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration6 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration7 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration8 │ │ ├── main.ts │ │ └── test-config.json │ ├── class-declaration9 │ │ ├── main.ts │ │ └── test-config.json │ ├── construct-signature1 │ │ ├── main.ts │ │ └── test-config.json │ ├── construct-signature2 │ │ ├── main.ts │ │ └── test-config.json │ ├── enum-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── enum-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── enum-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ ├── enum-declaration4 │ │ ├── main.ts │ │ └── test-config.json │ ├── export-declaration1 │ │ ├── foo.ts │ │ ├── main.ts │ │ └── test-config.json │ ├── export-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── export-specifier1 │ │ ├── foo.ts │ │ ├── main.ts │ │ └── test-config.json │ ├── export-specifier2 │ │ ├── foo.ts │ │ ├── main.ts │ │ └── test-config.json │ ├── export-specifier3 │ │ ├── foo.ts │ │ ├── main.ts │ │ └── test-config.json │ ├── export-specifier4 │ │ ├── foo.ts │ │ ├── main.ts │ │ └── test-config.json │ ├── extractor-empty-file │ │ ├── main.ts │ │ └── test-config.json │ ├── function-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── function-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── function-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ ├── function-declaration4 │ │ ├── main.ts │ │ └── test-config.json │ ├── function-declaration5 │ │ ├── main.ts │ │ └── test-config.json │ ├── function-declaration6 │ │ ├── main.ts │ │ └── test-config.json │ ├── function-declaration7 │ │ ├── main.ts │ │ └── test-config.json │ ├── function-declaration8 │ │ ├── main.ts │ │ └── test-config.json │ ├── get-accessor1 │ │ ├── main.ts │ │ └── test-config.json │ ├── get-accessor3 │ │ ├── main.ts │ │ └── test-config.json │ ├── import-declaration1 │ │ ├── foo.ts │ │ ├── main.ts │ │ └── test-config.json │ ├── import-specifier1 │ │ ├── foo.ts │ │ ├── main.ts │ │ └── test-config.json │ ├── import-specifier2 │ │ ├── main.ts │ │ └── test-config.json │ ├── index-signature1 │ │ ├── main.ts │ │ └── test-config.json │ ├── index-signature2 │ │ ├── main.ts │ │ └── test-config.json │ ├── index-signature3 │ │ ├── main.ts │ │ └── test-config.json │ ├── interface-class-merging │ │ ├── main.ts │ │ └── test-config.json │ ├── interface-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── interface-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── interface-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ ├── interface-declaration4 │ │ ├── main.ts │ │ └── test-config.json │ ├── interface-declaration5 │ │ ├── main.ts │ │ └── test-config.json │ ├── interface-declaration6 │ │ ├── main.ts │ │ └── test-config.json │ ├── interface-declaration7 │ │ ├── main.ts │ │ └── test-config.json │ ├── interface-subtyping │ │ ├── main.ts │ │ └── test-config.json │ ├── mapped-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── mapped-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── mapped-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ ├── mapped-declaration4 │ │ ├── main.ts │ │ └── test-config.json │ ├── multiple-declaration │ │ ├── main.ts │ │ └── test-config.json │ ├── namespace-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── namespace-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── namespace-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ ├── object-literal1 │ │ ├── main.ts │ │ └── test-config.json │ ├── parameter-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── parameter-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── parameter-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ ├── set-accessor1 │ │ ├── main.ts │ │ └── test-config.json │ ├── set-accessor2 │ │ ├── main.ts │ │ └── test-config.json │ ├── set-accessor3 │ │ ├── main.ts │ │ └── test-config.json │ ├── symbol1 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-alias-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-alias-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-alias-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-alias-declaration4 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-alias-declaration5 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-alias-declaration6 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-alias-declaration7 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-alias-declaration8 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-parameter-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-parameter-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── type-parameter-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ ├── variable-declaration1 │ │ ├── main.ts │ │ └── test-config.json │ ├── variable-declaration2 │ │ ├── main.ts │ │ └── test-config.json │ ├── variable-declaration3 │ │ ├── main.ts │ │ └── test-config.json │ └── variable-declaration4 │ │ ├── main.ts │ │ └── test-config.json ├── default-template.ts ├── default.test.tpl ├── tsconfig.json └── tsconfig.test.json ├── tools └── travis-release │ ├── release.js │ ├── release.ts │ └── tsconfig.json ├── tsconfig.json └── tslint.json /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | **/__snapshots__/* linguist-generated=true 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | notifications: 3 | email: 4 | on_success: never 5 | on_failure: change 6 | branches: 7 | only: 8 | - master 9 | - dev 10 | - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ 11 | node_js: 12 | - "node" 13 | script: 14 | - npm run test-ci 15 | after_script: 16 | - npm run coveralls 17 | before_deploy: 18 | - npm run travis-release 19 | deploy: 20 | provider: npm 21 | email: $SIMPLR_NPM_EMAIL 22 | api_key: $SIMPLR_NPM_API_KEY 23 | skip_cleanup: true 24 | on: 25 | tags: true 26 | repo: SimplrJS/ts-extractor 27 | -------------------------------------------------------------------------------- /.vscode/cSpell.json: -------------------------------------------------------------------------------- 1 | // cSpell Settings 2 | { 3 | // Version of the setting file. Always 0.1 4 | "version": "0.1", 5 | // language - current active spelling language 6 | "language": "en", 7 | // words - list of words to be always considered correct 8 | "words": [ 9 | "AGPL", 10 | "loglevel", 11 | "simplrjs" 12 | ], 13 | // flagWords - list of words to be always considered incorrect 14 | // This is useful for offensive words and common spelling errors. 15 | // For example "hte" should be "the" 16 | "flagWords": [ 17 | "hte" 18 | ] 19 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible Node.js debug attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "preLaunchTask": "build", 12 | "program": "${workspaceRoot}\\src\\debug.ts", 13 | "outFiles": [ 14 | "${workspaceRoot}\\dist\\**\\*.js" 15 | ], 16 | "sourceMaps": true 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "eslint.enable": false, 3 | "typescript.tsdk": "node_modules\\typescript\\lib", 4 | "files.exclude": { 5 | "**/.git": true, 6 | "**/.svn": true, 7 | "**/.hg": true, 8 | "**/CVS": true, 9 | "**/.DS_Store": true, 10 | "tests/cases/__tests__/**/*.test.ts": true 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build", 8 | "type": "npm", 9 | "script": "build", 10 | "problemMatcher": [ 11 | "$tsc" 12 | ] 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) JSC, QuatroDev 2017-present 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ts-extractor 2 | 3 | [![NPM version](https://img.shields.io/npm/v/ts-extractor.svg)](https://www.npmjs.com/package/ts-extractor) 4 | [![Build Status](https://travis-ci.org/SimplrJS/ts-extractor.svg?branch=master)](https://travis-ci.org/SimplrJS/ts-extractor) 5 | [![Coverage Status](https://coveralls.io/repos/github/SimplrJS/ts-extractor/badge.svg?branch=master)](https://coveralls.io/github/SimplrJS/ts-extractor?branch=master) 6 | [![dependencies Status](https://david-dm.org/SimplrJS/ts-extractor/status.svg)](https://david-dm.org/SimplrJS/ts-extractor) 7 | [![devDependencies Status](https://david-dm.org/SimplrJS/ts-extractor/dev-status.svg)](https://david-dm.org/SimplrJS/ts-extractor?type=dev) 8 | [![devDependencies Status](https://img.shields.io/npm/l/ts-extractor.svg)](https://npmjs.org/package/ts-extractor) 9 | 10 | TypeScript AST extractor to a useful JSON structure. 11 | 12 | The purpose of this package is to extract AST into a flat JSON structure. 13 | 14 | After extraction, it can be used for documentation generation tool, easier code analysis without compiler, etc. 15 | 16 | ## Relation to API Extractor 17 | The library is inspired by [API Extractor](https://github.com/Microsoft/web-build-tools/tree/master/apps/api-extractor) created by [Microsoft](https://microsoft.com). 18 | 19 | `ts-extractor` does everything `api-extractor` was supposed to do and supports ALL things that latest TypeScript has, compared to a limited support in `api-extractor`. 20 | 21 | In essence, it is an evolution of what `api-extractor` does, though outputs are not interchangable directly. 22 | 23 | ## Usage example 24 | 25 | ```ts 26 | import * as path from "path"; 27 | import * as process from "process"; 28 | import { Extractor, GetCompilerOptions } from "ts-extractor"; 29 | 30 | async function Main(): Promise { 31 | // Absolute path to projectDirectory 32 | const projectDirectory = process.cwd(); 33 | const pathToTsconfig = path.join(projectDirectory, "./tsconfig.json"); 34 | 35 | const compilerOptions = await GetCompilerOptions(pathToTsconfig); 36 | 37 | const extractor = new Extractor({ 38 | CompilerOptions: compilerOptions, 39 | ProjectDirectory: projectDirectory 40 | }); 41 | 42 | const extractedOutput = extractor.Extract(["./src/index.ts", "./src/another-entry-file.ts"]); 43 | console.log(extractedOutput); 44 | } 45 | 46 | Main(); 47 | ``` 48 | -------------------------------------------------------------------------------- /examples/simple/exported-const-variables.ts: -------------------------------------------------------------------------------- 1 | export const Kintamasis = "Hello World!"; 2 | export const Kintamasis2 = "Hello World!"; 3 | export const Kintamasis3 = "Not imported!"; 4 | -------------------------------------------------------------------------------- /examples/simple/exported-functions.ts: -------------------------------------------------------------------------------- 1 | export function Foo(): string { 2 | return "foo"; 3 | } 4 | 5 | export function Bar(): string { 6 | return "bar"; 7 | } 8 | -------------------------------------------------------------------------------- /examples/simple/index.ts: -------------------------------------------------------------------------------- 1 | export const a = Symbol("Hello"); 2 | -------------------------------------------------------------------------------- /examples/simple/my-types.ts: -------------------------------------------------------------------------------- 1 | export interface MyInterface { 2 | foo: string; 3 | } -------------------------------------------------------------------------------- /examples/simple/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple", 3 | "dependencies": { 4 | "react": "^15.6.1" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/simple/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "removeComments": false, 6 | "outDir": "dist", 7 | "rootDir": ".", 8 | "sourceMap": false, 9 | "skipDefaultLibCheck": true, 10 | "declaration": true, 11 | "pretty": true, 12 | "strict": true, 13 | "forceConsistentCasingInFileNames": true, 14 | "lib": [ 15 | "es6", 16 | "dom" 17 | ] 18 | }, 19 | "exclude": [ 20 | "node_modules", 21 | "dist", 22 | "@types", 23 | "__tests__" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ts-extractor", 3 | "version": "4.0.0-rc.4", 4 | "description": "TypeScript AST extractor to useful JSON structure.", 5 | "keywords": [ 6 | "typescript", 7 | "extractor", 8 | "ast", 9 | "abstract", 10 | "syntax", 11 | "tree" 12 | ], 13 | "main": "./dist/index.js", 14 | "types": "./dist/index.d.ts", 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/SimplrJS/ts-extractor" 18 | }, 19 | "scripts": { 20 | "pretest": "npm run build -- --noEmit && npm run build-tests", 21 | "test": "npm run tslint && jest && echo All tests passed successfully.", 22 | "pretest-ci": "npm run pretest", 23 | "test-ci": "npm run tslint && npm run jest && echo All tests passed successfully.", 24 | "jest": "jest --maxWorkers=4", 25 | "tslint": "tslint --project . --config ./tslint.json && echo Successfully passed tslint test.", 26 | "coveralls": "coveralls < coverage/lcov.info", 27 | "test-watch": "start npm run build-tests -- --watchAll && jest --watchAll", 28 | "build": "tsc -p .", 29 | "build-watch": "npm run build -- -w", 30 | "build-tests": "test-generator-cli", 31 | "prepublishOnly": "npm run build && rimraf dist/debug.*", 32 | "travis-release": "node ./tools/travis-release/release.js" 33 | }, 34 | "author": "SimplrJS (https://github.com/simplrjs)", 35 | "contributors": [ 36 | "Giedrius Grabauskas (https://github.com/GiedriusGrabauskas)", 37 | "Martynas Žilinskas (https://github.com/MartynasZilinskas)", 38 | "Dovydas Navickas (https://github.com/DovydasNavickas)" 39 | ], 40 | "license": "MIT", 41 | "dependencies": { 42 | "@types/fs-extra": "^5.0.0", 43 | "fs-extra": "^5.0.0", 44 | "read-package-json": "^2.0.12", 45 | "simplr-logger": "^1.0.1", 46 | "typescript": "^2.7.1" 47 | }, 48 | "devDependencies": { 49 | "@simplrjs/test-generator-cli": "^0.1.3", 50 | "@types/globby": "^6.1.0", 51 | "@types/jest": "^22.1.1", 52 | "coveralls": "^3.0.0", 53 | "jest": "^22.1.4", 54 | "rimraf": "^2.6.2", 55 | "simplr-tslint": "0.0.1", 56 | "ts-jest": "^22.0.2", 57 | "ts-node": "^4.1.0", 58 | "tslint": "^5.9.1" 59 | }, 60 | "files": [ 61 | "dist", 62 | "**/*.md", 63 | "@types", 64 | "!/examples" 65 | ], 66 | "jest": { 67 | "collectCoverage": true, 68 | "mapCoverage": true, 69 | "transform": { 70 | ".(ts|tsx)": "/node_modules/ts-jest/preprocessor.js" 71 | }, 72 | "globals": { 73 | "ts-jest": { 74 | "skipBabel": true, 75 | "tsConfigFile": "tests/tsconfig.json" 76 | } 77 | }, 78 | "testRegex": "__tests__/.*\\.(test|spec).(ts|tsx|js)$", 79 | "moduleNameMapper": { 80 | "@src/(.*)": "/src/$1" 81 | }, 82 | "coveragePathIgnorePatterns": [ 83 | "/node_modules/", 84 | "/tests/" 85 | ], 86 | "moduleFileExtensions": [ 87 | "ts", 88 | "tsx", 89 | "js" 90 | ] 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/abstractions/api-callable-base.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiItemReference } from "../contracts/api-item-reference"; 6 | import { ApiType } from "../contracts/api-types"; 7 | import { ApiCallableBaseDefinition } from "../contracts/api-definitions"; 8 | import { ApiTypeHelpers } from "../api-type-helpers"; 9 | import { ApiItemLocationDto } from "../contracts"; 10 | 11 | /** 12 | * A callable api item base. 13 | */ 14 | export abstract class ApiCallableBase< 15 | TDeclaration extends ts.SignatureDeclaration, 16 | TExtractDto extends ApiCallableBaseDefinition 17 | > 18 | extends ApiItem { 19 | 20 | protected IsOverloadBase: boolean; 21 | protected Parameters: ApiItemReference[] = []; 22 | protected TypeParameters: ApiItemReference[] = []; 23 | protected ReturnType: ApiType | undefined; 24 | protected Location: ApiItemLocationDto; 25 | 26 | protected OnGatherData(): void { 27 | // ApiItemLocation 28 | this.Location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 29 | 30 | // Overload 31 | this.IsOverloadBase = this.TypeChecker.isImplementationOfOverload(this.Declaration as ts.FunctionLike) || false; 32 | 33 | // Parameters 34 | this.Parameters = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.parameters, this.Options); 35 | 36 | // TypeParameters 37 | if (this.Declaration.typeParameters != null) { 38 | this.TypeParameters = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.typeParameters, this.Options); 39 | } 40 | 41 | // ReturnType 42 | const signature = this.TypeChecker.getSignatureFromDeclaration(this.Declaration); 43 | if (signature != null) { 44 | const type = this.TypeChecker.getReturnTypeOfSignature(signature); 45 | 46 | this.ReturnType = ApiTypeHelpers.ResolveApiType(this.Options, this.Location, type, this.Declaration.type); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/abstractions/api-item.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiBaseDefinition, TypeScriptTypeDeclarationDebug } from "../contracts/api-definitions"; 4 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 5 | import { ExtractorOptions } from "../contracts/extractor-options"; 6 | import { ReadonlyRegistry } from "../contracts/registry"; 7 | 8 | export interface ApiItemOptions { 9 | Program: ts.Program; 10 | ExtractorOptions: ExtractorOptions; 11 | ExternalPackages: string[]; 12 | Registry: ReadonlyRegistry; 13 | AddItemToRegistry(item: ApiItem): string; 14 | } 15 | 16 | export enum ApiItemStatus { 17 | Initial = 0, 18 | Gathered = 1 << 0, 19 | Extracted = 1 << 1, 20 | GatheredAndExtracted = Gathered | Extracted 21 | } 22 | 23 | export abstract class ApiItem { 24 | constructor(private declaration: TDeclaration, private symbol: ts.Symbol, private options: ApiItemOptions) { 25 | this.TypeChecker = options.Program.getTypeChecker(); 26 | } 27 | 28 | protected TypeChecker: ts.TypeChecker; 29 | protected ItemStatus: ApiItemStatus = ApiItemStatus.Initial; 30 | protected ExtractedData: TExtractDto; 31 | 32 | public GetItemMetadata(): ApiMetadataDto { 33 | return { 34 | DocumentationComment: ts.displayPartsToString(this.Symbol.getDocumentationComment(this.TypeChecker)), 35 | JSDocTags: this.Symbol.getJsDocTags() 36 | }; 37 | } 38 | 39 | public get Options(): ApiItemOptions { 40 | return this.options; 41 | } 42 | 43 | public get Declaration(): TDeclaration { 44 | return this.declaration; 45 | } 46 | 47 | public get Symbol(): ts.Symbol { 48 | return this.symbol; 49 | } 50 | 51 | public get Status(): ApiItemStatus { 52 | return this.ItemStatus; 53 | } 54 | 55 | /** 56 | * It gives precise TypeScript information about item after extracting. 57 | */ 58 | protected GetTsDebugInfo(): TypeScriptTypeDeclarationDebug | undefined { 59 | if (this.Options.ExtractorOptions.IncludeTsDebugInfo) { 60 | return { 61 | Kind: this.Declaration.kind, 62 | KindString: ts.SyntaxKind[this.Declaration.kind] 63 | }; 64 | } 65 | 66 | return undefined; 67 | } 68 | 69 | protected abstract OnExtract(): TExtractDto; 70 | 71 | public Extract(forceExtraction: boolean = false): TExtractDto { 72 | if (this.Status === ApiItemStatus.Initial || forceExtraction) { 73 | this.ExtractedData = this.OnExtract(); 74 | this.ItemStatus = ApiItemStatus.Extracted; 75 | } 76 | return this.ExtractedData; 77 | } 78 | 79 | protected abstract OnGatherData(): void; 80 | 81 | public GatherData(forceGathering: boolean = false): void { 82 | if (this.ItemStatus & ApiItemStatus.Gathered) { 83 | return; 84 | } 85 | this.OnGatherData(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/api-registry.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "./abstractions/api-item"; 3 | import { Dictionary } from "./contracts/dictionary"; 4 | import { Registry } from "./contracts/registry"; 5 | import { ApiDefinition } from "./contracts/api-definitions"; 6 | 7 | export type ExtractedApiRegistry = Dictionary; 8 | 9 | export class ApiRegistry implements Registry { 10 | protected registry: Map = new Map(); 11 | 12 | protected ExtractedData: ExtractedApiRegistry = {}; 13 | protected IsDataExtracted: boolean = false; 14 | 15 | public Extract(forceExtract: boolean = false): ExtractedApiRegistry { 16 | if (this.IsDataExtracted && !forceExtract) { 17 | return this.ExtractedData; 18 | } 19 | 20 | for (const [key, apiItem] of this.Registry) { 21 | const extractedData = apiItem.Extract(forceExtract); 22 | 23 | this.ExtractedData[key] = extractedData as ApiDefinition; 24 | } 25 | 26 | this.IsDataExtracted = true; 27 | return this.ExtractedData; 28 | } 29 | 30 | public get Registry(): ReadonlyMap { 31 | return this.registry as ReadonlyMap; 32 | } 33 | 34 | private declarationsToIdsMap: WeakMap = new WeakMap(); 35 | private counters: Map = new Map(); 36 | 37 | protected GetNextDeclarationId(declaration: ts.Declaration | undefined): string | undefined { 38 | if (declaration == null) { 39 | return undefined; 40 | } 41 | 42 | // Get string syntax kind 43 | const syntaxKind = ts.SyntaxKind[declaration.kind]; 44 | 45 | let index: number; 46 | if (this.counters.has(syntaxKind)) { 47 | const oldIndex = this.counters.get(syntaxKind)!; 48 | index = oldIndex + 1; 49 | } else { 50 | index = 0; 51 | } 52 | 53 | this.counters.set(syntaxKind, index); 54 | return `${syntaxKind}-${index}`; 55 | } 56 | 57 | public GetDeclarationId(declaration: ts.Declaration): string | undefined { 58 | return this.declarationsToIdsMap.get(declaration); 59 | } 60 | 61 | public HasDeclaration(declaration: ts.Declaration): boolean { 62 | const declarationId = this.GetDeclarationId(declaration); 63 | return declarationId != null && this.registry.has(declarationId); 64 | } 65 | 66 | public Get(id: string): ApiItem | undefined { 67 | if (id == null) { 68 | return undefined; 69 | } 70 | return this.registry.get(id); 71 | } 72 | 73 | public AddItem(item: ApiItem): string { 74 | const declarationId = this.GetNextDeclarationId(item.Declaration); 75 | 76 | if (declarationId == null) { 77 | throw new Error(`Declaration id should always be deterministic.`); 78 | } 79 | 80 | if (!this.registry.has(declarationId)) { 81 | this.registry.set(declarationId, item); 82 | this.declarationsToIdsMap.set(item.Declaration, declarationId); 83 | this.IsDataExtracted = false; 84 | } 85 | 86 | item.GatherData(); 87 | 88 | return declarationId; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/contracts.ts: -------------------------------------------------------------------------------- 1 | export * from "./contracts/access-modifier"; 2 | export * from "./contracts/api-item-reference"; 3 | export * from "./contracts/api-metadata-dto"; 4 | export * from "./contracts/api-definitions"; 5 | export * from "./contracts/dictionary"; 6 | export * from "./contracts/extractor-options"; 7 | export * from "./contracts/registry"; 8 | export * from "./contracts/api-item-location-dto"; 9 | export * from "./contracts/api-types"; 10 | export * from "./contracts/api-definitions"; 11 | -------------------------------------------------------------------------------- /src/contracts/access-modifier.ts: -------------------------------------------------------------------------------- 1 | export enum AccessModifier { 2 | Public = "public", 3 | Private = "private", 4 | Protected = "protected" 5 | } 6 | -------------------------------------------------------------------------------- /src/contracts/api-item-location-dto.ts: -------------------------------------------------------------------------------- 1 | export interface ApiItemLocationDto { 2 | FileName: string; 3 | Line: number; 4 | Character: number; 5 | IsExternalPackage: boolean; 6 | } 7 | -------------------------------------------------------------------------------- /src/contracts/api-item-reference.ts: -------------------------------------------------------------------------------- 1 | export interface ApiItemReference { 2 | Alias: string; 3 | Ids: string[]; 4 | } 5 | -------------------------------------------------------------------------------- /src/contracts/api-metadata-dto.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | export interface ApiMetadataDto { 4 | DocumentationComment: string; 5 | JSDocTags: JSDocTagItem[]; 6 | } 7 | 8 | export type DocumentationCommentsItem = ts.SymbolDisplayPart; 9 | export type JSDocTagItem = ts.JSDocTagInfo; 10 | -------------------------------------------------------------------------------- /src/contracts/dictionary.ts: -------------------------------------------------------------------------------- 1 | export type Dictionary = { [key: string]: TItem }; 2 | -------------------------------------------------------------------------------- /src/contracts/extractor-options.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { LogLevel } from "simplr-logger"; 3 | 4 | import { ApiItem } from "../abstractions/api-item"; 5 | 6 | export interface ExtractorOptions { 7 | /** 8 | * TypeScript compiler options. 9 | */ 10 | CompilerOptions: ts.CompilerOptions; 11 | /** 12 | * Full path to TypeScript project directory. 13 | */ 14 | ProjectDirectory: string; 15 | /** 16 | * File locations that should not be included in extracted data. 17 | */ 18 | Exclude?: string[]; 19 | /** 20 | * Used to standartize paths in extracted data. 21 | */ 22 | OutputPathSeparator?: string; 23 | /** 24 | * Package names to include in extracted data. 25 | */ 26 | ExternalPackages?: string[]; 27 | /** 28 | * Include TypeScript specific information in extracted data. 29 | */ 30 | IncludeTsDebugInfo?: boolean; 31 | /** 32 | * Filters ApiItems that should not appear in extracted data. 33 | * Example: ApiItem with private access modifiers should be omitted from extracted data. 34 | * ```ts 35 | * const extractor = new Extractor({ 36 | * CompilerOptions: compilerOptions, 37 | * ProjectDirectory: projectDirectory, 38 | * FilterApiItems: apiItem => { 39 | * // Check Access Modifier. 40 | * const accessModifier = ApiHelpers.ResolveAccessModifierFromModifiers(apiItem.Declaration.modifiers); 41 | * if (accessModifier === AccessModifier.Private) { 42 | * return false; 43 | * } 44 | * 45 | * // Look for JSDocTag "@private" 46 | * const metadata = apiItem.GetItemMetadata(); 47 | * if (metadata.JSDocTags.findIndex(x => x.name === "private") !== -1) { 48 | * return false; 49 | * } 50 | * 51 | * return true; 52 | * } 53 | * }); 54 | * ``` 55 | */ 56 | FilterApiItems?: FilterApiItemsHandler; 57 | Verbosity?: LogLevel; 58 | } 59 | 60 | export type FilterApiItemsHandler = (apiitem: ApiItem) => boolean; 61 | -------------------------------------------------------------------------------- /src/contracts/registry.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | export interface ReadonlyRegistry { 4 | Extract(): void; 5 | HasDeclaration(declaration: ts.Declaration | undefined): boolean; 6 | GetDeclarationId(declaration: ts.Declaration | undefined): string | undefined; 7 | Get(id: string): TItem | undefined; 8 | Registry: ReadonlyMap; 9 | } 10 | 11 | export interface Registry extends ReadonlyRegistry { 12 | AddItem(item: TItem): string; 13 | } 14 | -------------------------------------------------------------------------------- /src/debug.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { GetCompilerOptions } from "./utils/tsconfig-json"; 3 | import * as fs from "fs-extra"; 4 | 5 | import { Extractor } from "./extractor"; 6 | import { ApiHelpers } from "./api-helpers"; 7 | import { AccessModifier } from "./contracts"; 8 | 9 | async function main(): Promise { 10 | const projectDirectory = path.resolve(__dirname, "../examples/simple/"); 11 | const tsconfigPath = path.join(projectDirectory, "tsconfig.json"); 12 | const compilerOptions = await GetCompilerOptions(tsconfigPath); 13 | 14 | const extractor = new Extractor({ 15 | CompilerOptions: compilerOptions, 16 | ProjectDirectory: projectDirectory, 17 | ExternalPackages: ["typescript"], 18 | FilterApiItems: apiItem => { 19 | const accessModifier = ApiHelpers.ResolveAccessModifierFromModifiers(apiItem.Declaration.modifiers); 20 | if (accessModifier === AccessModifier.Private) { 21 | return false; 22 | } 23 | 24 | const metadata = apiItem.GetItemMetadata(); 25 | if (metadata.JSDocTags.findIndex(x => x.name === "private") !== -1) { 26 | return false; 27 | } 28 | 29 | return true; 30 | } 31 | }); 32 | 33 | const extract1 = extractor.Extract([path.resolve("examples/simple/index.ts")]); 34 | // tslint:disable-next-line:no-console 35 | console.log(JSON.stringify(extract1, null, 4)); 36 | 37 | await fs.writeJson("./debug.json", extract1); 38 | } 39 | 40 | main(); 41 | -------------------------------------------------------------------------------- /src/definitions/api-call.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiHelpers } from "../api-helpers"; 4 | import { ApiDefinitionKind, ApiCallDto } from "../contracts/api-definitions"; 5 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 6 | import { ApiCallableBase } from "../abstractions/api-callable-base"; 7 | 8 | export class ApiCall extends ApiCallableBase { 9 | public OnExtract(): ApiCallDto { 10 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 11 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 12 | 13 | return { 14 | ApiKind: ApiDefinitionKind.Call, 15 | Name: this.Symbol.name, 16 | ParentId: parentId, 17 | Metadata: metadata, 18 | Location: this.Location, 19 | IsOverloadBase: this.IsOverloadBase, 20 | Parameters: this.Parameters, 21 | ReturnType: this.ReturnType, 22 | TypeParameters: this.TypeParameters, 23 | _ts: this.GetTsDebugInfo() 24 | }; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/definitions/api-class-constructor.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiCallableBase } from "../abstractions/api-callable-base"; 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiClassConstructorDto } from "../contracts/api-definitions"; 6 | import { AccessModifier } from "../contracts/access-modifier"; 7 | 8 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 9 | 10 | export class ApiClassConstructor extends ApiCallableBase { 11 | private accessModifier: AccessModifier; 12 | 13 | protected OnGatherData(): void { 14 | super.OnGatherData(); 15 | 16 | // Modifiers 17 | this.accessModifier = ApiHelpers.ResolveAccessModifierFromModifiers(this.Declaration.modifiers); 18 | } 19 | 20 | public OnExtract(): ApiClassConstructorDto { 21 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 22 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 23 | 24 | return { 25 | ApiKind: ApiDefinitionKind.ClassConstructor, 26 | Name: this.Symbol.name, 27 | ParentId: parentId, 28 | Metadata: metadata, 29 | Location: this.Location, 30 | IsOverloadBase: this.IsOverloadBase, 31 | Parameters: this.Parameters, 32 | AccessModifier: this.accessModifier, 33 | TypeParameters: this.TypeParameters, 34 | _ts: this.GetTsDebugInfo() 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/definitions/api-class-method.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiHelpers } from "../api-helpers"; 4 | import { ApiDefinitionKind, ApiClassMethodDto } from "../contracts/api-definitions"; 5 | import { AccessModifier } from "../contracts/access-modifier"; 6 | 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiCallableBase } from "../abstractions/api-callable-base"; 9 | 10 | export class ApiClassMethod extends ApiCallableBase { 11 | private accessModifier: AccessModifier; 12 | private isAbstract: boolean; 13 | private isStatic: boolean; 14 | private isOptional: boolean; 15 | private isAsync: boolean; 16 | 17 | public OnGatherData(): void { 18 | super.OnGatherData(); 19 | 20 | // Modifiers 21 | this.accessModifier = ApiHelpers.ResolveAccessModifierFromModifiers(this.Declaration.modifiers); 22 | this.isAbstract = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.AbstractKeyword); 23 | this.isStatic = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.StaticKeyword); 24 | this.isAsync = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.AsyncKeyword); 25 | 26 | // IsOptional 27 | this.isOptional = Boolean((this.Declaration as ts.FunctionLikeDeclarationBase).questionToken); 28 | } 29 | 30 | public OnExtract(): ApiClassMethodDto { 31 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 32 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 33 | 34 | return { 35 | ApiKind: ApiDefinitionKind.ClassMethod, 36 | Name: this.Symbol.name, 37 | ParentId: parentId, 38 | Metadata: metadata, 39 | Location: this.Location, 40 | IsOverloadBase: this.IsOverloadBase, 41 | Parameters: this.Parameters, 42 | ReturnType: this.ReturnType, 43 | AccessModifier: this.accessModifier, 44 | IsAbstract: this.isAbstract, 45 | IsStatic: this.isStatic, 46 | IsOptional: this.isOptional, 47 | IsAsync: this.isAsync, 48 | TypeParameters: this.TypeParameters, 49 | _ts: this.GetTsDebugInfo() 50 | }; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/definitions/api-class-property.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiClassPropertyDto } from "../contracts/api-definitions"; 6 | import { ApiType } from "../contracts/api-types"; 7 | import { AccessModifier } from "../contracts/access-modifier"; 8 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 9 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 10 | import { ApiTypeHelpers } from "../api-type-helpers"; 11 | 12 | export class ApiClassProperty extends ApiItem { 13 | private location: ApiItemLocationDto; 14 | private accessModifier: AccessModifier; 15 | private isAbstract: boolean; 16 | private isStatic: boolean; 17 | private isReadonly: boolean; 18 | private isOptional: boolean; 19 | private type: ApiType; 20 | 21 | protected OnGatherData(): void { 22 | // ApiItemLocation 23 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 24 | 25 | // Modifiers 26 | this.accessModifier = ApiHelpers.ResolveAccessModifierFromModifiers(this.Declaration.modifiers); 27 | this.isAbstract = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.AbstractKeyword); 28 | this.isStatic = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.StaticKeyword); 29 | this.isReadonly = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.ReadonlyKeyword); 30 | 31 | // IsOptional 32 | this.isOptional = Boolean(this.Declaration.questionToken); 33 | 34 | // Type 35 | const type = this.TypeChecker.getTypeOfSymbolAtLocation(this.Symbol, this.Declaration); 36 | this.type = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.type); 37 | } 38 | 39 | public OnExtract(): ApiClassPropertyDto { 40 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 41 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 42 | 43 | return { 44 | ApiKind: ApiDefinitionKind.ClassProperty, 45 | Name: this.Symbol.name, 46 | ParentId: parentId, 47 | Metadata: metadata, 48 | Location: this.location, 49 | AccessModifier: this.accessModifier, 50 | IsAbstract: this.isAbstract, 51 | IsReadonly: this.isReadonly, 52 | IsStatic: this.isStatic, 53 | IsOptional: this.isOptional, 54 | Type: this.type, 55 | _ts: this.GetTsDebugInfo() 56 | }; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/definitions/api-class.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiItem } from "../abstractions/api-item"; 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiClassDto } from "../contracts/api-definitions"; 6 | import { ApiItemReference } from "../contracts/api-item-reference"; 7 | import { ApiType } from "../contracts/api-types"; 8 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 9 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 10 | import { ApiTypeHelpers } from "../api-type-helpers"; 11 | 12 | export class ApiClass extends ApiItem { 13 | private location: ApiItemLocationDto; 14 | /** 15 | * Interfaces can extend multiple interfaces. 16 | */ 17 | private extends: ApiType | undefined; 18 | private implements: ApiType[] = []; 19 | private typeParameters: ApiItemReference[] = []; 20 | private members: ApiItemReference[] = []; 21 | private isAbstract: boolean = false; 22 | 23 | protected OnGatherData(): void { 24 | // ApiItemLocation 25 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 26 | 27 | // Members 28 | this.members = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.members, this.Options); 29 | 30 | // Extends 31 | if (this.Declaration.heritageClauses != null) { 32 | const extendingList = ApiTypeHelpers.GetHeritageList( 33 | this.Options, 34 | this.location, 35 | this.Declaration.heritageClauses, 36 | ts.SyntaxKind.ExtendsKeyword 37 | ); 38 | 39 | if (extendingList.length > 0) { 40 | this.extends = extendingList[0]; 41 | } 42 | } 43 | 44 | // Implements 45 | if (this.Declaration.heritageClauses != null) { 46 | this.implements = ApiTypeHelpers.GetHeritageList( 47 | this.Options, 48 | this.location, 49 | this.Declaration.heritageClauses, 50 | ts.SyntaxKind.ImplementsKeyword 51 | ); 52 | } 53 | 54 | // IsAbstract 55 | this.isAbstract = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.AbstractKeyword); 56 | 57 | // TypeParameters 58 | if (this.Declaration.typeParameters != null) { 59 | this.typeParameters = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.typeParameters, this.Options); 60 | } 61 | } 62 | 63 | public OnExtract(): ApiClassDto { 64 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 65 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 66 | 67 | return { 68 | ApiKind: ApiDefinitionKind.Class, 69 | Name: this.Symbol.name, 70 | ParentId: parentId, 71 | Metadata: metadata, 72 | Location: this.location, 73 | IsAbstract: this.isAbstract, 74 | Members: this.members, 75 | Extends: this.extends, 76 | Implements: this.implements, 77 | TypeParameters: this.typeParameters, 78 | _ts: this.GetTsDebugInfo() 79 | }; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/definitions/api-construct.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiHelpers } from "../api-helpers"; 4 | import { ApiDefinitionKind, ApiConstructDto } from "../contracts/api-definitions"; 5 | 6 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 7 | import { ApiCallableBase } from "../abstractions/api-callable-base"; 8 | 9 | export class ApiConstruct extends ApiCallableBase { 10 | protected ResolveApiKind(): ApiDefinitionKind.Construct | ApiDefinitionKind.ConstructorType { 11 | if (ts.isConstructSignatureDeclaration(this.Declaration)) { 12 | return ApiDefinitionKind.Construct; 13 | } else { 14 | return ApiDefinitionKind.ConstructorType; 15 | } 16 | } 17 | 18 | public OnExtract(): ApiConstructDto { 19 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 20 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 21 | const apiKind = this.ResolveApiKind(); 22 | 23 | return { 24 | ApiKind: apiKind, 25 | Name: this.Symbol.name, 26 | ParentId: parentId, 27 | Metadata: metadata, 28 | Location: this.Location, 29 | IsOverloadBase: this.IsOverloadBase, 30 | Parameters: this.Parameters, 31 | ReturnType: this.ReturnType, 32 | TypeParameters: this.TypeParameters, 33 | _ts: this.GetTsDebugInfo() 34 | }; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/definitions/api-enum-member.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiEnumMemberDto } from "../contracts/api-definitions"; 6 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 7 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 8 | 9 | export class ApiEnumMember extends ApiItem { 10 | private location: ApiItemLocationDto; 11 | 12 | public GetValue(): string { 13 | for (const item of this.Declaration.getChildren()) { 14 | if (ts.isNumericLiteral(item) || 15 | ts.isStringLiteral(item) || 16 | ts.isBinaryExpression(item)) { 17 | return item.getText(); 18 | } 19 | } 20 | 21 | let valueIndex: string | undefined; 22 | if (this.Declaration.parent != null) { 23 | const parentChildren = this.Declaration.parent.members; 24 | for (const index in parentChildren) { 25 | if (parentChildren.hasOwnProperty(index) && 26 | parentChildren[index] === this.Declaration) { 27 | valueIndex = index; 28 | } 29 | } 30 | } 31 | 32 | return valueIndex || ""; 33 | } 34 | 35 | protected OnGatherData(): void { 36 | // ApiItemLocation 37 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 38 | } 39 | 40 | public OnExtract(): ApiEnumMemberDto { 41 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 42 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 43 | const value: string = this.GetValue(); 44 | 45 | return { 46 | ApiKind: ApiDefinitionKind.EnumMember, 47 | Name: this.Symbol.name, 48 | ParentId: parentId, 49 | Metadata: metadata, 50 | Location: this.location, 51 | Value: value, 52 | _ts: this.GetTsDebugInfo() 53 | }; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/definitions/api-enum.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiEnumDto } from "../contracts/api-definitions"; 6 | import { ApiItemReference } from "../contracts/api-item-reference"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 9 | 10 | export class ApiEnum extends ApiItem { 11 | private location: ApiItemLocationDto; 12 | private members: ApiItemReference[] = []; 13 | private isConst: boolean; 14 | 15 | protected OnGatherData(): void { 16 | // ApiItemLocation 17 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 18 | 19 | // IsConst 20 | this.isConst = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.ConstKeyword); 21 | 22 | // Members 23 | this.members = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.members, this.Options); 24 | 25 | } 26 | 27 | public OnExtract(): ApiEnumDto { 28 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 29 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 30 | 31 | return { 32 | ApiKind: ApiDefinitionKind.Enum, 33 | Name: this.Symbol.name, 34 | ParentId: parentId, 35 | Metadata: metadata, 36 | Location: this.location, 37 | IsConst: this.isConst, 38 | Members: this.members, 39 | _ts: this.GetTsDebugInfo() 40 | }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/definitions/api-export-specifier.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { LogLevel } from "simplr-logger"; 3 | 4 | import { ApiItem } from "../abstractions/api-item"; 5 | import { ApiHelpers } from "../api-helpers"; 6 | import { ApiDefinitionKind, ApiExportSpecifierDto, ApiExportSpecifierApiItems } from "../contracts/api-definitions"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 9 | 10 | export class ApiExportSpecifier extends ApiItem { 11 | private location: ApiItemLocationDto; 12 | private apiItems: ApiExportSpecifierApiItems; 13 | 14 | protected OnGatherData(): void { 15 | // ApiItemLocation 16 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 17 | 18 | const targetSymbol = this.TypeChecker.getExportSpecifierLocalTargetSymbol(this.Declaration); 19 | const symbolReferences = ApiHelpers.GetItemIdsFromSymbol(targetSymbol, this.Options); 20 | 21 | if (symbolReferences != null) { 22 | this.apiItems = symbolReferences.Ids; 23 | } else { 24 | ApiHelpers.LogWithNodePosition(LogLevel.Warning, this.Declaration, "Exported item does not exist."); 25 | } 26 | } 27 | 28 | public OnExtract(): ApiExportSpecifierDto { 29 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 30 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 31 | 32 | return { 33 | ApiKind: ApiDefinitionKind.ExportSpecifier, 34 | Name: this.Declaration.name.getText(), 35 | ParentId: parentId, 36 | Metadata: metadata, 37 | Location: this.location, 38 | ApiItems: this.apiItems, 39 | _ts: this.GetTsDebugInfo() 40 | }; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/definitions/api-export.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import * as path from "path"; 3 | import { LogLevel } from "simplr-logger"; 4 | 5 | import { ApiItem } from "../abstractions/api-item"; 6 | import { ApiSourceFile } from "./api-source-file"; 7 | import { TsHelpers } from "../ts-helpers"; 8 | import { ApiHelpers } from "../api-helpers"; 9 | import { ApiDefinitionKind, ApiExportDto } from "../contracts/api-definitions"; 10 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 11 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 12 | 13 | export class ApiExport extends ApiItem { 14 | private location: ApiItemLocationDto; 15 | private getExportPath(): string | undefined { 16 | if (this.apiSourceFile == null) { 17 | ApiHelpers.LogWithNodePosition(LogLevel.Warning, this.Declaration, "Exported source file is not found!"); 18 | return undefined; 19 | } 20 | 21 | const projectDirectory = this.Options.ExtractorOptions.ProjectDirectory; 22 | const declarationFileName = this.apiSourceFile.Declaration.fileName; 23 | const exportRelativePath = path.relative(projectDirectory, declarationFileName); 24 | 25 | return ApiHelpers.StandardizeRelativePath(exportRelativePath, this.Options); 26 | } 27 | 28 | private sourceFileId: string | undefined; 29 | private apiSourceFile: ApiSourceFile | undefined; 30 | 31 | protected OnGatherData(): void { 32 | // ApiItemLocation 33 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 34 | 35 | // Extract members from Source file. 36 | const sourceFileDeclaration = TsHelpers.ResolveSourceFile(this.Declaration, this.Options.Program); 37 | 38 | if (sourceFileDeclaration != null && ApiHelpers.ShouldVisit(sourceFileDeclaration, this.Options)) { 39 | const sourceFileSymbol = TsHelpers.GetSymbolFromDeclaration(sourceFileDeclaration, this.TypeChecker); 40 | 41 | if (sourceFileSymbol != null) { 42 | this.apiSourceFile = new ApiSourceFile(sourceFileDeclaration, sourceFileSymbol, this.Options); 43 | this.sourceFileId = this.Options.AddItemToRegistry(this.apiSourceFile); 44 | } 45 | } 46 | } 47 | 48 | public OnExtract(): ApiExportDto { 49 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 50 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 51 | const exportPath: string | undefined = this.getExportPath(); 52 | 53 | return { 54 | ApiKind: ApiDefinitionKind.Export, 55 | Name: this.Symbol.name, 56 | ParentId: parentId, 57 | Metadata: metadata, 58 | Location: this.location, 59 | SourceFileId: this.sourceFileId, 60 | ExportPath: exportPath, 61 | _ts: this.GetTsDebugInfo() 62 | }; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/definitions/api-function-expression.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiHelpers } from "../api-helpers"; 4 | import { ApiDefinitionKind, ApiFunctionExpressionDto } from "../contracts/api-definitions"; 5 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 6 | import { ApiCallableBase } from "../abstractions/api-callable-base"; 7 | 8 | export type FunctionTypes = ts.FunctionExpression | ts.FunctionTypeNode | ts.ArrowFunction; 9 | 10 | export class ApiFunctionExpression extends ApiCallableBase { 11 | protected ResolveApiKind(): ApiDefinitionKind.FunctionExpression | ApiDefinitionKind.FunctionType | ApiDefinitionKind.ArrowFunction { 12 | if (ts.isFunctionTypeNode(this.Declaration)) { 13 | return ApiDefinitionKind.FunctionType; 14 | } else if (ts.isFunctionExpression(this.Declaration)) { 15 | return ApiDefinitionKind.FunctionExpression; 16 | } else { 17 | return ApiDefinitionKind.ArrowFunction; 18 | } 19 | } 20 | 21 | public OnExtract(): ApiFunctionExpressionDto { 22 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 23 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 24 | const apiKind = this.ResolveApiKind(); 25 | 26 | return { 27 | ApiKind: apiKind, 28 | Name: this.Symbol.name, 29 | ParentId: parentId, 30 | Metadata: metadata, 31 | Location: this.Location, 32 | IsOverloadBase: this.IsOverloadBase, 33 | TypeParameters: this.TypeParameters, 34 | Parameters: this.Parameters, 35 | ReturnType: this.ReturnType, 36 | _ts: this.GetTsDebugInfo() 37 | }; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/definitions/api-function.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiHelpers } from "../api-helpers"; 4 | import { ApiDefinitionKind, ApiFunctionDto } from "../contracts/api-definitions"; 5 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 6 | import { ApiCallableBase } from "../abstractions/api-callable-base"; 7 | 8 | export class ApiFunction extends ApiCallableBase { 9 | private isAsync: boolean; 10 | 11 | public OnGatherData(): void { 12 | super.OnGatherData(); 13 | 14 | // Modifiers 15 | this.isAsync = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.AsyncKeyword); 16 | } 17 | 18 | public OnExtract(): ApiFunctionDto { 19 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 20 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 21 | 22 | return { 23 | ApiKind: ApiDefinitionKind.Function, 24 | Name: this.Symbol.name, 25 | ParentId: parentId, 26 | Metadata: metadata, 27 | Location: this.Location, 28 | IsOverloadBase: this.IsOverloadBase, 29 | TypeParameters: this.TypeParameters, 30 | Parameters: this.Parameters, 31 | IsAsync: this.isAsync, 32 | ReturnType: this.ReturnType, 33 | _ts: this.GetTsDebugInfo() 34 | }; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/definitions/api-get-accessor.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiHelpers } from "../api-helpers"; 4 | import { ApiItem } from "../abstractions/api-item"; 5 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 6 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 7 | import { ApiDefinitionKind, ApiGetAccessorDto } from "../contracts/api-definitions"; 8 | import { ApiType } from "../contracts/api-types"; 9 | import { AccessModifier } from "../contracts/access-modifier"; 10 | import { ApiTypeHelpers } from "../api-type-helpers"; 11 | 12 | export class ApiGetAccessor extends ApiItem { 13 | private location: ApiItemLocationDto; 14 | private accessModifier: AccessModifier; 15 | private isAbstract: boolean; 16 | private isStatic: boolean; 17 | private type: ApiType; 18 | 19 | protected OnGatherData(): void { 20 | // ApiItemLocation 21 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 22 | 23 | // Modifiers 24 | this.accessModifier = ApiHelpers.ResolveAccessModifierFromModifiers(this.Declaration.modifiers); 25 | this.isAbstract = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.AbstractKeyword); 26 | this.isStatic = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.StaticKeyword); 27 | 28 | // Type 29 | const type = this.TypeChecker.getTypeOfSymbolAtLocation(this.Symbol, this.Declaration); 30 | this.type = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.type); 31 | } 32 | 33 | public OnExtract(): ApiGetAccessorDto { 34 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 35 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 36 | 37 | return { 38 | ApiKind: ApiDefinitionKind.GetAccessor, 39 | Name: this.Symbol.name, 40 | ParentId: parentId, 41 | Metadata: metadata, 42 | Location: this.location, 43 | AccessModifier: this.accessModifier, 44 | IsAbstract: this.isAbstract, 45 | IsStatic: this.isStatic, 46 | Type: this.type, 47 | _ts: this.GetTsDebugInfo() 48 | }; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/definitions/api-import-specifier.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { LogLevel } from "simplr-logger"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { TsHelpers } from "../ts-helpers"; 6 | import { ApiItem } from "../abstractions/api-item"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 9 | import { ApiDefinitionKind, ApiImportSpecifierDto, ApiImportSpecifierApiItems } from "../contracts/api-definitions"; 10 | 11 | export class ApiImportSpecifier extends ApiItem { 12 | private location: ApiItemLocationDto; 13 | private apiItems: ApiImportSpecifierApiItems; 14 | 15 | protected OnGatherData(): void { 16 | // ApiItemLocation 17 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 18 | 19 | const targetSymbol = TsHelpers.GetImportSpecifierLocalTargetSymbol(this.Declaration, this.Options.Program); 20 | const symbolReferences = ApiHelpers.GetItemIdsFromSymbol(targetSymbol, this.Options); 21 | 22 | if (symbolReferences != null) { 23 | this.apiItems = symbolReferences.Ids; 24 | } else { 25 | ApiHelpers.LogWithNodePosition(LogLevel.Warning, this.Declaration, "Imported item does not exist."); 26 | } 27 | } 28 | 29 | public OnExtract(): ApiImportSpecifierDto { 30 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 31 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 32 | 33 | return { 34 | ApiKind: ApiDefinitionKind.ImportSpecifier, 35 | Name: this.Symbol.name, 36 | ParentId: parentId, 37 | Metadata: metadata, 38 | Location: this.location, 39 | ApiItems: this.apiItems, 40 | _ts: this.GetTsDebugInfo() 41 | }; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/definitions/api-index.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { LogLevel } from "simplr-logger"; 3 | 4 | import { ApiItem } from "../abstractions/api-item"; 5 | 6 | import { ApiHelpers } from "../api-helpers"; 7 | import { ApiDefinitionKind, ApiIndexDto } from "../contracts/api-definitions"; 8 | import { ApiType } from "../contracts/api-types"; 9 | 10 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 11 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 12 | import { ApiTypeHelpers } from "../api-type-helpers"; 13 | 14 | export class ApiIndex extends ApiItem { 15 | private location: ApiItemLocationDto; 16 | private parameter: string; 17 | private type: ApiType; 18 | private isReadonly: boolean; 19 | 20 | protected OnGatherData(): void { 21 | // ApiItemLocation 22 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 23 | 24 | // Parameter 25 | const parameters = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.parameters, this.Options); 26 | 27 | if (parameters.length !== 1) { 28 | const message = `An index signature must have exactly one parameter, it has ${parameters.length}.`; 29 | ApiHelpers.LogWithNodePosition( 30 | LogLevel.Error, 31 | this.Declaration, 32 | message 33 | ); 34 | } else { 35 | this.parameter = parameters[0].Ids[0]; 36 | } 37 | 38 | /** 39 | * Type 40 | * getTypeFromTypeNode method handles undefined and returns `any` type. 41 | */ 42 | const type = this.TypeChecker.getTypeFromTypeNode(this.Declaration.type!); 43 | this.type = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.type); 44 | 45 | // Modifiers 46 | this.isReadonly = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.ReadonlyKeyword); 47 | } 48 | 49 | public OnExtract(): ApiIndexDto { 50 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 51 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 52 | 53 | return { 54 | ApiKind: ApiDefinitionKind.Index, 55 | Name: this.Symbol.name, 56 | ParentId: parentId, 57 | Metadata: metadata, 58 | Location: this.location, 59 | Parameter: this.parameter, 60 | IsReadonly: this.isReadonly, 61 | Type: this.type, 62 | _ts: this.GetTsDebugInfo() 63 | }; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/definitions/api-interface.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiItem } from "../abstractions/api-item"; 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiInterfaceDto } from "../contracts/api-definitions"; 6 | import { ApiItemReference } from "../contracts/api-item-reference"; 7 | import { ApiType } from "../contracts/api-types"; 8 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 9 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 10 | import { ApiTypeHelpers } from "../api-type-helpers"; 11 | 12 | export class ApiInterface extends ApiItem { 13 | private location: ApiItemLocationDto; 14 | /** 15 | * Interfaces can extend multiple interfaces. 16 | */ 17 | private extends: ApiType[] = []; 18 | private typeParameters: ApiItemReference[] = []; 19 | private members: ApiItemReference[] = []; 20 | 21 | protected OnGatherData(): void { 22 | // ApiItemLocation 23 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 24 | 25 | // Members 26 | this.members = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.members, this.Options); 27 | 28 | // Extends 29 | if (this.Declaration.heritageClauses != null) { 30 | this.extends = ApiTypeHelpers.GetHeritageList( 31 | this.Options, 32 | this.location, 33 | this.Declaration.heritageClauses, 34 | ts.SyntaxKind.ExtendsKeyword 35 | ); 36 | } 37 | 38 | // TypeParameters 39 | if (this.Declaration.typeParameters != null) { 40 | this.typeParameters = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.typeParameters, this.Options); 41 | } 42 | } 43 | 44 | public OnExtract(): ApiInterfaceDto { 45 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 46 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 47 | 48 | return { 49 | ApiKind: ApiDefinitionKind.Interface, 50 | Name: this.Symbol.name, 51 | ParentId: parentId, 52 | Metadata: metadata, 53 | Location: this.location, 54 | Members: this.members, 55 | Extends: this.extends, 56 | TypeParameters: this.typeParameters, 57 | _ts: this.GetTsDebugInfo() 58 | }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/definitions/api-mapped.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | 6 | import { ApiDefinitionKind, ApiMappedDto } from "../contracts/api-definitions"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 9 | import { ApiType } from "../contracts/api-types"; 10 | import { TsHelpers } from "../ts-helpers"; 11 | import { ApiTypeHelpers } from "../api-type-helpers"; 12 | 13 | export class ApiMapped extends ApiItem { 14 | private location: ApiItemLocationDto; 15 | private typeParameter: string | undefined; 16 | private type: ApiType; 17 | private isReadonly: boolean; 18 | private isOptional: boolean; 19 | 20 | protected OnGatherData(): void { 21 | // ApiItemLocation 22 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 23 | 24 | // TypeParameter 25 | const typeParameterSymbol = TsHelpers.GetSymbolFromDeclaration(this.Declaration.typeParameter, this.TypeChecker); 26 | if (typeParameterSymbol != null) { 27 | this.typeParameter = ApiHelpers.GetItemId(this.Declaration.typeParameter, typeParameterSymbol, this.Options); 28 | } 29 | 30 | /** 31 | * Type 32 | * getTypeFromTypeNode method handles undefined and returns `any` type. 33 | */ 34 | const type = this.TypeChecker.getTypeFromTypeNode(this.Declaration.type!); 35 | this.type = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.type); 36 | 37 | // Readonly 38 | this.isReadonly = Boolean(this.Declaration.readonlyToken); 39 | 40 | // Optional 41 | this.isOptional = Boolean(this.Declaration.questionToken); 42 | } 43 | 44 | public OnExtract(): ApiMappedDto { 45 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 46 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 47 | 48 | return { 49 | ApiKind: ApiDefinitionKind.Mapped, 50 | Name: this.Symbol.name, 51 | ParentId: parentId, 52 | Metadata: metadata, 53 | Location: this.location, 54 | TypeParameter: this.typeParameter, 55 | IsOptional: this.isOptional, 56 | IsReadonly: this.isReadonly, 57 | Type: this.type, 58 | _ts: this.GetTsDebugInfo() 59 | }; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/definitions/api-method.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | 3 | import { ApiHelpers } from "../api-helpers"; 4 | 5 | import { ApiDefinitionKind, ApiMethodDto } from "../contracts/api-definitions"; 6 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 7 | import { ApiCallableBase } from "../abstractions/api-callable-base"; 8 | 9 | export class ApiMethod extends ApiCallableBase { 10 | private isOptional: boolean; 11 | 12 | public OnGatherData(): void { 13 | super.OnGatherData(); 14 | 15 | // IsOptional 16 | this.isOptional = Boolean(this.Declaration.questionToken); 17 | } 18 | 19 | public OnExtract(): ApiMethodDto { 20 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 21 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 22 | 23 | return { 24 | ApiKind: ApiDefinitionKind.Method, 25 | Name: this.Symbol.name, 26 | ParentId: parentId, 27 | Metadata: metadata, 28 | Location: this.Location, 29 | IsOverloadBase: this.IsOverloadBase, 30 | Parameters: this.Parameters, 31 | ReturnType: this.ReturnType, 32 | IsOptional: this.isOptional, 33 | TypeParameters: this.TypeParameters, 34 | _ts: this.GetTsDebugInfo() 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/definitions/api-namespace.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiNamespaceDto } from "../contracts/api-definitions"; 6 | import { ApiItemReference } from "../contracts/api-item-reference"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 9 | 10 | export class ApiNamespace extends ApiItem { 11 | private location: ApiItemLocationDto; 12 | private members: ApiItemReference[] = []; 13 | 14 | protected ResolveApiKind(): ApiDefinitionKind.Namespace | ApiDefinitionKind.ImportNamespace { 15 | if (ts.isModuleDeclaration(this.Declaration)) { 16 | return ApiDefinitionKind.Namespace; 17 | } else { 18 | return ApiDefinitionKind.ImportNamespace; 19 | } 20 | } 21 | 22 | protected OnGatherData(): void { 23 | // ApiItemLocation 24 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 25 | 26 | // Members 27 | this.members = ApiHelpers.GetItemsIdsFromSymbolsMap(this.Symbol.exports, this.Options); 28 | } 29 | 30 | public OnExtract(): ApiNamespaceDto { 31 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 32 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 33 | const apiKind = this.ResolveApiKind(); 34 | 35 | return { 36 | ApiKind: apiKind, 37 | Name: this.Declaration.name.getText(), 38 | ParentId: parentId, 39 | Metadata: metadata, 40 | Location: this.location, 41 | Members: this.members, 42 | _ts: this.GetTsDebugInfo() 43 | }; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/definitions/api-parameter.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiParameterDto } from "../contracts/api-definitions"; 6 | import { ApiType } from "../contracts/api-types"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 9 | import { ApiTypeHelpers } from "../api-type-helpers"; 10 | 11 | export class ApiParameter extends ApiItem { 12 | private location: ApiItemLocationDto; 13 | private type: ApiType; 14 | private isOptional: boolean; 15 | private isSpread: boolean; 16 | private initializer: string | undefined; 17 | 18 | protected OnGatherData(): void { 19 | // ApiItemLocation 20 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 21 | 22 | // Type 23 | const type = this.TypeChecker.getTypeOfSymbolAtLocation(this.Symbol, this.Declaration); 24 | this.type = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.type); 25 | 26 | // IsOptional 27 | this.isOptional = Boolean(this.Declaration.questionToken); 28 | 29 | // IsSpread 30 | this.isSpread = Boolean(this.Declaration.dotDotDotToken); 31 | 32 | // Initializer 33 | this.initializer = this.Declaration.initializer != null ? this.Declaration.initializer.getText() : undefined; 34 | } 35 | 36 | public OnExtract(): ApiParameterDto { 37 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 38 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 39 | 40 | return { 41 | ApiKind: ApiDefinitionKind.Parameter, 42 | Name: this.Symbol.name, 43 | ParentId: parentId, 44 | Metadata: metadata, 45 | Location: this.location, 46 | IsOptional: this.isOptional, 47 | IsSpread: this.isSpread, 48 | Initializer: this.initializer, 49 | Type: this.type, 50 | _ts: this.GetTsDebugInfo() 51 | }; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/definitions/api-property.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiPropertyDto } from "../contracts/api-definitions"; 6 | import { ApiType } from "../contracts/api-types"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 9 | import { ApiTypeHelpers } from "../api-type-helpers"; 10 | 11 | export class ApiProperty extends ApiItem { 12 | private location: ApiItemLocationDto; 13 | private type: ApiType; 14 | private isOptional: boolean; 15 | private isReadonly: boolean; 16 | 17 | protected OnGatherData(): void { 18 | // ApiItemLocation 19 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 20 | 21 | // Type 22 | const typeNode: ts.TypeNode | undefined = ts.isPropertySignature(this.Declaration) ? this.Declaration.type : undefined; 23 | const type = this.TypeChecker.getTypeOfSymbolAtLocation(this.Symbol, this.Declaration); 24 | this.type = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, typeNode); 25 | 26 | // IsOptional 27 | this.isOptional = Boolean(this.Declaration.questionToken); 28 | 29 | // IsReadonly 30 | this.isReadonly = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.ReadonlyKeyword); 31 | } 32 | 33 | public OnExtract(): ApiPropertyDto { 34 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 35 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 36 | 37 | return { 38 | ApiKind: ApiDefinitionKind.Property, 39 | Name: this.Symbol.name, 40 | ParentId: parentId, 41 | Metadata: metadata, 42 | Location: this.location, 43 | IsOptional: this.isOptional, 44 | IsReadonly: this.isReadonly, 45 | Type: this.type, 46 | _ts: this.GetTsDebugInfo() 47 | }; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/definitions/api-set-accessor.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { LogLevel } from "simplr-logger"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiItem } from "../abstractions/api-item"; 6 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 7 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 8 | import { ApiDefinitionKind, ApiSetAccessorDto } from "../contracts/api-definitions"; 9 | import { ApiItemReference } from "../contracts/api-item-reference"; 10 | import { AccessModifier } from "../contracts/access-modifier"; 11 | 12 | export class ApiSetAccessor extends ApiItem { 13 | private location: ApiItemLocationDto; 14 | private accessModifier: AccessModifier; 15 | private isAbstract: boolean; 16 | private isStatic: boolean; 17 | private parameter: ApiItemReference | undefined; 18 | 19 | protected OnGatherData(): void { 20 | // ApiItemLocation 21 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 22 | 23 | // Modifiers 24 | this.accessModifier = ApiHelpers.ResolveAccessModifierFromModifiers(this.Declaration.modifiers); 25 | this.isAbstract = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.AbstractKeyword); 26 | this.isStatic = ApiHelpers.ModifierKindExistsInModifiers(this.Declaration.modifiers, ts.SyntaxKind.StaticKeyword); 27 | 28 | // Parameter 29 | const parameters = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.parameters, this.Options); 30 | 31 | if (parameters.length !== 1) { 32 | const message = `A 'set' accessor must have exactly one parameter, it has ${parameters.length}.`; 33 | ApiHelpers.LogWithNodePosition( 34 | LogLevel.Error, 35 | this.Declaration, 36 | message 37 | ); 38 | } else { 39 | this.parameter = parameters[0]; 40 | } 41 | } 42 | 43 | public OnExtract(): ApiSetAccessorDto { 44 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 45 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 46 | 47 | return { 48 | ApiKind: ApiDefinitionKind.SetAccessor, 49 | Name: this.Symbol.name, 50 | ParentId: parentId, 51 | Metadata: metadata, 52 | Location: this.location, 53 | AccessModifier: this.accessModifier, 54 | IsAbstract: this.isAbstract, 55 | IsStatic: this.isStatic, 56 | Parameter: this.parameter, 57 | _ts: this.GetTsDebugInfo() 58 | }; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/definitions/api-source-file.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import * as path from "path"; 3 | 4 | import { ApiItem } from "../abstractions/api-item"; 5 | import { ApiDefinitionKind, ApiSourceFileDto } from "../contracts/api-definitions"; 6 | import { ApiItemReference } from "../contracts/api-item-reference"; 7 | import { ApiHelpers } from "../api-helpers"; 8 | 9 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 10 | import { ApiItemLocationDto } from "../contracts"; 11 | 12 | export class ApiSourceFile extends ApiItem { 13 | private location: ApiItemLocationDto; 14 | private members: ApiItemReference[]; 15 | 16 | private getFileName(): string { 17 | return path.basename(this.Declaration.fileName); 18 | } 19 | 20 | protected OnGatherData(): void { 21 | // ApiItemLocation 22 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 23 | 24 | // Members 25 | this.members = ApiHelpers.GetItemsIdsFromSymbolsMap(this.Symbol.exports, this.Options); 26 | } 27 | 28 | public OnExtract(): ApiSourceFileDto { 29 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 30 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 31 | const name: string = this.getFileName(); 32 | 33 | return { 34 | ApiKind: ApiDefinitionKind.SourceFile, 35 | Name: name, 36 | ParentId: parentId, 37 | Metadata: metadata, 38 | Location: this.location, 39 | Members: this.members, 40 | _ts: this.GetTsDebugInfo() 41 | }; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/definitions/api-type-alias.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | 6 | import { ApiDefinitionKind, ApiTypeAliasDto } from "../contracts/api-definitions"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemReference } from "../contracts/api-item-reference"; 9 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 10 | import { ApiType } from "../contracts/api-types"; 11 | import { ApiTypeHelpers } from "../api-type-helpers"; 12 | 13 | export class ApiTypeAlias extends ApiItem { 14 | private location: ApiItemLocationDto; 15 | private typeParameters: ApiItemReference[] = []; 16 | private type: ApiType; 17 | 18 | protected OnGatherData(): void { 19 | // ApiItemLocation 20 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 21 | 22 | // TypeParameters 23 | if (this.Declaration.typeParameters != null) { 24 | this.typeParameters = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.typeParameters, this.Options); 25 | } 26 | 27 | // Type 28 | const type = this.TypeChecker.getTypeFromTypeNode(this.Declaration.type); 29 | const self = type.aliasSymbol === this.Symbol; 30 | this.type = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.type, self); 31 | } 32 | 33 | public OnExtract(): ApiTypeAliasDto { 34 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 35 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 36 | 37 | return { 38 | ApiKind: ApiDefinitionKind.TypeAlias, 39 | Name: this.Symbol.name, 40 | ParentId: parentId, 41 | Metadata: metadata, 42 | Location: this.location, 43 | Type: this.type, 44 | TypeParameters: this.typeParameters, 45 | _ts: this.GetTsDebugInfo() 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/definitions/api-type-literal.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | 6 | import { ApiDefinitionKind, ApiTypeLiteralDto } from "../contracts/api-definitions"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemReference } from "../contracts/api-item-reference"; 9 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 10 | 11 | export class ApiTypeLiteral extends ApiItem { 12 | private location: ApiItemLocationDto; 13 | private members: ApiItemReference[] = []; 14 | 15 | protected ResolveApiKind(): ApiDefinitionKind.TypeLiteral | ApiDefinitionKind.ObjectLiteral { 16 | if (ts.isTypeLiteralNode(this.Declaration)) { 17 | return ApiDefinitionKind.TypeLiteral; 18 | } else { 19 | return ApiDefinitionKind.ObjectLiteral; 20 | } 21 | } 22 | 23 | protected OnGatherData(): void { 24 | // ApiItemLocation 25 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 26 | 27 | if (ts.isTypeLiteralNode(this.Declaration)) { 28 | this.members = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.members, this.Options); 29 | } else if (ts.isObjectLiteralExpression(this.Declaration)) { 30 | this.members = ApiHelpers.GetItemsIdsFromDeclarations(this.Declaration.properties, this.Options); 31 | } 32 | } 33 | 34 | public OnExtract(): ApiTypeLiteralDto { 35 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 36 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 37 | const apiKind = this.ResolveApiKind(); 38 | 39 | return { 40 | ApiKind: apiKind, 41 | ParentId: parentId, 42 | Name: this.Symbol.name, 43 | Metadata: metadata, 44 | Location: this.location, 45 | Members: this.members, 46 | _ts: this.GetTsDebugInfo() 47 | }; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/definitions/api-type-parameter.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | 6 | import { ApiDefinitionKind, ApiTypeParameterDto } from "../contracts/api-definitions"; 7 | import { ApiType } from "../contracts/api-types"; 8 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 9 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 10 | import { ApiTypeHelpers } from "../api-type-helpers"; 11 | 12 | export class ApiTypeParameter extends ApiItem { 13 | private location: ApiItemLocationDto; 14 | private constraintType: ApiType | undefined; 15 | private defaultType: ApiType | undefined; 16 | 17 | protected OnGatherData(): void { 18 | // ApiItemLocation 19 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 20 | 21 | // Constraint type 22 | if (this.Declaration.constraint != null) { 23 | const type = this.TypeChecker.getTypeFromTypeNode(this.Declaration.constraint); 24 | this.constraintType = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.constraint); 25 | } 26 | 27 | // Default type 28 | if (this.Declaration.default != null) { 29 | const type = this.TypeChecker.getTypeFromTypeNode(this.Declaration.default); 30 | this.defaultType = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.default); 31 | } 32 | } 33 | 34 | public OnExtract(): ApiTypeParameterDto { 35 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 36 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 37 | 38 | return { 39 | ApiKind: ApiDefinitionKind.TypeParameter, 40 | Name: this.Symbol.name, 41 | ParentId: parentId, 42 | Metadata: metadata, 43 | Location: this.location, 44 | ConstraintType: this.constraintType, 45 | DefaultType: this.defaultType, 46 | _ts: this.GetTsDebugInfo() 47 | }; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/definitions/api-variable.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import { ApiItem } from "../abstractions/api-item"; 3 | 4 | import { ApiHelpers } from "../api-helpers"; 5 | import { ApiDefinitionKind, ApiVariableDto, ApiVariableDeclarationType } from "../contracts/api-definitions"; 6 | import { ApiType } from "../contracts/api-types"; 7 | import { ApiMetadataDto } from "../contracts/api-metadata-dto"; 8 | import { ApiItemLocationDto } from "../contracts/api-item-location-dto"; 9 | import { ApiTypeHelpers } from "../api-type-helpers"; 10 | 11 | export class ApiVariable extends ApiItem { 12 | private location: ApiItemLocationDto; 13 | private type: ApiType; 14 | private variableDeclarationType: ApiVariableDeclarationType; 15 | 16 | protected OnGatherData(): void { 17 | // ApiItemLocation 18 | this.location = ApiHelpers.GetApiItemLocationDtoFromNode(this.Declaration, this.Options); 19 | 20 | // Type 21 | const type = this.TypeChecker.getTypeOfSymbolAtLocation(this.Symbol, this.Declaration); 22 | this.type = ApiTypeHelpers.ResolveApiType(this.Options, this.location, type, this.Declaration.type); 23 | 24 | // VariableDeclarationType 25 | if (this.Declaration.parent != null) { 26 | switch (this.Declaration.parent.flags) { 27 | case ts.NodeFlags.Const: { 28 | this.variableDeclarationType = ApiVariableDeclarationType.Const; 29 | break; 30 | } 31 | case ts.NodeFlags.Let: { 32 | this.variableDeclarationType = ApiVariableDeclarationType.Let; 33 | break; 34 | } 35 | default: { 36 | this.variableDeclarationType = ApiVariableDeclarationType.Var; 37 | } 38 | } 39 | } 40 | } 41 | 42 | public OnExtract(): ApiVariableDto { 43 | const parentId: string | undefined = ApiHelpers.GetParentIdFromDeclaration(this.Declaration, this.Options); 44 | const metadata: ApiMetadataDto = this.GetItemMetadata(); 45 | 46 | return { 47 | ApiKind: ApiDefinitionKind.Variable, 48 | Name: this.Symbol.name, 49 | ParentId: parentId, 50 | Metadata: metadata, 51 | Location: this.location, 52 | VariableDeclarationType: this.variableDeclarationType, 53 | Type: this.type, 54 | _ts: this.GetTsDebugInfo() 55 | }; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./extractor"; 2 | export * from "./utils/tsconfig-json"; 3 | 4 | import * as Contracts from "./contracts"; 5 | export { 6 | Contracts 7 | }; 8 | -------------------------------------------------------------------------------- /src/internal.ts: -------------------------------------------------------------------------------- 1 | export * from "./api-helpers"; 2 | export * from "./api-type-helpers"; 3 | export * from "./ts-helpers"; 4 | export * from "./api-registry"; 5 | -------------------------------------------------------------------------------- /src/utils/logger.ts: -------------------------------------------------------------------------------- 1 | import { LoggerBuilder, LoggerConfigurationBuilder, LogLevel } from "simplr-logger"; 2 | 3 | const LoggerConfiguration = new LoggerConfigurationBuilder() 4 | .SetDefaultLogLevel(LogLevel.Information) 5 | .Build(); 6 | 7 | export const Logger = new LoggerBuilder(LoggerConfiguration); 8 | -------------------------------------------------------------------------------- /src/utils/path-is-inside.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | 3 | export function PathIsInside(thePath: string, potentialParent: string): boolean { 4 | // For inside-directory checking, we want to allow trailing slashes, so normalize. 5 | thePath = StripTrailingSep(thePath); 6 | potentialParent = StripTrailingSep(potentialParent); 7 | 8 | // Node treats only Windows as case-insensitive in its path module; we follow those conventions. 9 | if (process.platform === "win32") { 10 | thePath = thePath.toLowerCase(); 11 | potentialParent = potentialParent.toLowerCase(); 12 | } 13 | 14 | thePath = path.normalize(thePath); 15 | potentialParent = path.normalize(potentialParent); 16 | 17 | return thePath.lastIndexOf(potentialParent, 0) === 0 && ( 18 | thePath[potentialParent.length] === path.sep || 19 | thePath[potentialParent.length] === undefined 20 | ); 21 | } 22 | 23 | function StripTrailingSep(thePath: string): string { 24 | if (thePath[thePath.length - 1] === path.sep) { 25 | return thePath.slice(0, -1); 26 | } 27 | return thePath; 28 | } 29 | -------------------------------------------------------------------------------- /src/utils/tsconfig-json.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs-extra"; 2 | import * as path from "path"; 3 | import * as ts from "typescript"; 4 | 5 | // TODO: Fool proof. 6 | /** 7 | * Get TypeScript compiler options from tsconfig.json. 8 | */ 9 | export async function GetCompilerOptions(fileLocation: string): Promise { 10 | const json = await fs.readJSON(fileLocation); 11 | 12 | const fullPath = path.resolve(fileLocation); 13 | const dirName = path.dirname(fullPath); 14 | 15 | const compilerOptions = ts.convertCompilerOptionsFromJson(json.compilerOptions, dirName); 16 | 17 | compilerOptions.options.typeRoots = ["."]; 18 | 19 | return compilerOptions.options; 20 | } 21 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | */__tests__/* 2 | !*/__tests__/**/__snapshots__ 3 | -------------------------------------------------------------------------------- /tests/__tests__/extractor.test.ts: -------------------------------------------------------------------------------- 1 | import * as ts from "typescript"; 2 | import * as path from "path"; 3 | import { Extractor } from "@src/extractor"; 4 | 5 | const EXTRACTOR_COMPILER_OPTIONS: ts.CompilerOptions = { 6 | target: ts.ScriptTarget.Latest, 7 | module: ts.ModuleKind.CommonJS, 8 | skipLibCheck: true, 9 | skipDefaultLibCheck: true 10 | }; 11 | 12 | const EXTRACTOR_OPTIONS = { 13 | CompilerOptions: EXTRACTOR_COMPILER_OPTIONS, 14 | ProjectDirectory: path.resolve(__dirname, "../cases/"), 15 | ExternalPackages: [] 16 | }; 17 | 18 | it("EntryFile that doesn't exist with absolute path.", () => { 19 | const extractor = new Extractor(EXTRACTOR_OPTIONS); 20 | expect(() => extractor.Extract(["C:/does-not-exist.ts"])).toThrowError(); 21 | }); 22 | 23 | it("EntryFile that is outside of project folder.", () => { 24 | EXTRACTOR_OPTIONS.ProjectDirectory = __dirname; 25 | 26 | const extractor = new Extractor(EXTRACTOR_OPTIONS); 27 | expect(() => extractor.Extract(["../cases/ClassDeclaration1.ts"])).toThrowError(); 28 | }); 29 | 30 | it("EntryFile that has errors.", () => { 31 | EXTRACTOR_OPTIONS.ProjectDirectory = __dirname; 32 | 33 | const extractor = new Extractor(EXTRACTOR_OPTIONS); 34 | expect(() => extractor.Extract(["./file-with-errors.ts"])).toThrowError(); 35 | }); 36 | -------------------------------------------------------------------------------- /tests/__tests__/file-with-errors.ts: -------------------------------------------------------------------------------- 1 | // Test case file that is outside of project's folder. 2 | export const A: number = "not a number ;)"; 3 | -------------------------------------------------------------------------------- /tests/__tests__/ts-helpers.test.ts: -------------------------------------------------------------------------------- 1 | import { TsHelpers } from "@src/ts-helpers"; 2 | 3 | describe("IsTypeScriptInternalSymbolName", () => { 4 | it("Internal names", () => { 5 | const internalNames = ["__type", "__call"]; 6 | 7 | internalNames.forEach(x => 8 | expect(TsHelpers.IsInternalSymbolName(x)).toBe(true) 9 | ); 10 | }); 11 | 12 | it("Internal names", () => { 13 | const internalNames = ["Foo", "Bar"]; 14 | 15 | internalNames.forEach(x => 16 | expect(TsHelpers.IsInternalSymbolName(x)).toBe(false) 17 | ); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /tests/__tests__/utils/__snapshots__/tsconfig-json.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Successfully get compiler options 1`] = ` 4 | Object { 5 | "experimentalDecorators": false, 6 | "module": 1, 7 | "noEmit": true, 8 | "pretty": true, 9 | "removeComments": false, 10 | "skipDefaultLibCheck": true, 11 | "sourceMap": false, 12 | "target": 2, 13 | "typeRoots": Array [ 14 | ".", 15 | ], 16 | } 17 | `; 18 | -------------------------------------------------------------------------------- /tests/__tests__/utils/_tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "removeComments": false, 6 | "sourceMap": false, 7 | "skipDefaultLibCheck": true, 8 | "pretty": true, 9 | "noEmit": true, 10 | "experimentalDecorators": false 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/__tests__/utils/tsconfig-json.test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | // TODO: Fix paths. 3 | import { GetCompilerOptions } from "../../../src/utils/tsconfig-json"; 4 | 5 | it("Successfully get compiler options", async done => { 6 | try { 7 | const compilerOptions = await GetCompilerOptions(path.resolve(__dirname, "./_tsconfig.json")); 8 | expect(compilerOptions).toMatchSnapshot(); 9 | done(); 10 | } catch (err) { 11 | done.fail(err); 12 | } 13 | }); 14 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/class-declaration11.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`class-declaration11 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ClassDeclaration-0": Object { 10 | "ApiKind": "class", 11 | "Extends": undefined, 12 | "Implements": Array [], 13 | "IsAbstract": false, 14 | "Location": Object { 15 | "Character": 0, 16 | "FileName": "./main.ts", 17 | "IsExternalPackage": false, 18 | "Line": 0, 19 | }, 20 | "Members": Array [ 21 | Object { 22 | "Alias": "getFoo", 23 | "Ids": Array [ 24 | "MethodDeclaration-0", 25 | ], 26 | }, 27 | ], 28 | "Metadata": Object { 29 | "DocumentationComment": "", 30 | "JSDocTags": Array [], 31 | }, 32 | "Name": "Foo", 33 | "ParentId": "SourceFile-0", 34 | "TypeParameters": Array [], 35 | "_ts": undefined, 36 | }, 37 | "MethodDeclaration-0": Object { 38 | "AccessModifier": "public", 39 | "ApiKind": "class-method", 40 | "IsAbstract": false, 41 | "IsAsync": false, 42 | "IsOptional": false, 43 | "IsOverloadBase": false, 44 | "IsStatic": false, 45 | "Location": Object { 46 | "Character": 4, 47 | "FileName": "./main.ts", 48 | "IsExternalPackage": false, 49 | "Line": 1, 50 | }, 51 | "Metadata": Object { 52 | "DocumentationComment": "", 53 | "JSDocTags": Array [], 54 | }, 55 | "Name": "getFoo", 56 | "Parameters": Array [], 57 | "ParentId": "ClassDeclaration-0", 58 | "ReturnType": Object { 59 | "ApiTypeKind": "this", 60 | "Location": Object { 61 | "Character": 21, 62 | "FileName": "./main.ts", 63 | "IsExternalPackage": false, 64 | "Line": 1, 65 | }, 66 | "ReferenceId": "ClassDeclaration-0", 67 | "Text": "this", 68 | }, 69 | "TypeParameters": Array [], 70 | "_ts": undefined, 71 | }, 72 | "SourceFile-0": Object { 73 | "ApiKind": "source-file", 74 | "Location": Object { 75 | "Character": 0, 76 | "FileName": "./main.ts", 77 | "IsExternalPackage": false, 78 | "Line": 0, 79 | }, 80 | "Members": Array [ 81 | Object { 82 | "Alias": "Foo", 83 | "Ids": Array [ 84 | "ClassDeclaration-0", 85 | ], 86 | }, 87 | ], 88 | "Metadata": Object { 89 | "DocumentationComment": "", 90 | "JSDocTags": Array [], 91 | }, 92 | "Name": "main.ts", 93 | "ParentId": undefined, 94 | "_ts": undefined, 95 | }, 96 | }, 97 | } 98 | `; 99 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/class-declaration7.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`class-declaration7 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ClassDeclaration-0": Object { 10 | "ApiKind": "class", 11 | "Extends": undefined, 12 | "Implements": Array [], 13 | "IsAbstract": false, 14 | "Location": Object { 15 | "Character": 0, 16 | "FileName": "./main.ts", 17 | "IsExternalPackage": false, 18 | "Line": 2, 19 | }, 20 | "Members": Array [], 21 | "Metadata": Object { 22 | "DocumentationComment": "", 23 | "JSDocTags": Array [], 24 | }, 25 | "Name": "FooClass", 26 | "ParentId": "SourceFile-0", 27 | "TypeParameters": Array [ 28 | Object { 29 | "Alias": "TValue", 30 | "Ids": Array [ 31 | "TypeParameter-0", 32 | ], 33 | }, 34 | ], 35 | "_ts": undefined, 36 | }, 37 | "SourceFile-0": Object { 38 | "ApiKind": "source-file", 39 | "Location": Object { 40 | "Character": 0, 41 | "FileName": "./main.ts", 42 | "IsExternalPackage": false, 43 | "Line": 2, 44 | }, 45 | "Members": Array [ 46 | Object { 47 | "Alias": "FooClass", 48 | "Ids": Array [ 49 | "ClassDeclaration-0", 50 | ], 51 | }, 52 | ], 53 | "Metadata": Object { 54 | "DocumentationComment": "", 55 | "JSDocTags": Array [], 56 | }, 57 | "Name": "main.ts", 58 | "ParentId": undefined, 59 | "_ts": undefined, 60 | }, 61 | "TypeParameter-0": Object { 62 | "ApiKind": "type-parameter", 63 | "ConstraintType": undefined, 64 | "DefaultType": undefined, 65 | "Location": Object { 66 | "Character": 22, 67 | "FileName": "./main.ts", 68 | "IsExternalPackage": false, 69 | "Line": 2, 70 | }, 71 | "Metadata": Object { 72 | "DocumentationComment": "", 73 | "JSDocTags": Array [], 74 | }, 75 | "Name": "TValue", 76 | "ParentId": "ClassDeclaration-0", 77 | "_ts": undefined, 78 | }, 79 | }, 80 | } 81 | `; 82 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/export-declaration1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`export-declaration1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ClassDeclaration-0": Object { 10 | "ApiKind": "class", 11 | "Extends": undefined, 12 | "Implements": Array [], 13 | "IsAbstract": false, 14 | "Location": Object { 15 | "Character": 0, 16 | "FileName": "./foo.ts", 17 | "IsExternalPackage": false, 18 | "Line": 0, 19 | }, 20 | "Members": Array [], 21 | "Metadata": Object { 22 | "DocumentationComment": "", 23 | "JSDocTags": Array [], 24 | }, 25 | "Name": "Foo", 26 | "ParentId": "SourceFile-1", 27 | "TypeParameters": Array [], 28 | "_ts": undefined, 29 | }, 30 | "ExportDeclaration-0": Object { 31 | "ApiKind": "export", 32 | "ExportPath": "./foo.ts", 33 | "Location": Object { 34 | "Character": 0, 35 | "FileName": "./main.ts", 36 | "IsExternalPackage": false, 37 | "Line": 0, 38 | }, 39 | "Metadata": Object { 40 | "DocumentationComment": "", 41 | "JSDocTags": Array [], 42 | }, 43 | "Name": "__export", 44 | "ParentId": "SourceFile-0", 45 | "SourceFileId": "SourceFile-1", 46 | "_ts": undefined, 47 | }, 48 | "SourceFile-0": Object { 49 | "ApiKind": "source-file", 50 | "Location": Object { 51 | "Character": 0, 52 | "FileName": "./main.ts", 53 | "IsExternalPackage": false, 54 | "Line": 0, 55 | }, 56 | "Members": Array [ 57 | Object { 58 | "Alias": "__export", 59 | "Ids": Array [ 60 | "ExportDeclaration-0", 61 | ], 62 | }, 63 | ], 64 | "Metadata": Object { 65 | "DocumentationComment": "", 66 | "JSDocTags": Array [], 67 | }, 68 | "Name": "main.ts", 69 | "ParentId": undefined, 70 | "_ts": undefined, 71 | }, 72 | "SourceFile-1": Object { 73 | "ApiKind": "source-file", 74 | "Location": Object { 75 | "Character": 0, 76 | "FileName": "./foo.ts", 77 | "IsExternalPackage": false, 78 | "Line": 0, 79 | }, 80 | "Members": Array [ 81 | Object { 82 | "Alias": "Foo", 83 | "Ids": Array [ 84 | "ClassDeclaration-0", 85 | ], 86 | }, 87 | ], 88 | "Metadata": Object { 89 | "DocumentationComment": "", 90 | "JSDocTags": Array [], 91 | }, 92 | "Name": "foo.ts", 93 | "ParentId": undefined, 94 | "_ts": undefined, 95 | }, 96 | }, 97 | } 98 | `; 99 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/export-declaration2.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`export-declaration2 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ExportDeclaration-0": Object { 10 | "ApiKind": "export", 11 | "ExportPath": undefined, 12 | "Location": Object { 13 | "Character": 0, 14 | "FileName": "./main.ts", 15 | "IsExternalPackage": false, 16 | "Line": 1, 17 | }, 18 | "Metadata": Object { 19 | "DocumentationComment": "", 20 | "JSDocTags": Array [], 21 | }, 22 | "Name": "__export", 23 | "ParentId": "SourceFile-0", 24 | "SourceFileId": undefined, 25 | "_ts": undefined, 26 | }, 27 | "SourceFile-0": Object { 28 | "ApiKind": "source-file", 29 | "Location": Object { 30 | "Character": 0, 31 | "FileName": "./main.ts", 32 | "IsExternalPackage": false, 33 | "Line": 1, 34 | }, 35 | "Members": Array [ 36 | Object { 37 | "Alias": "__export", 38 | "Ids": Array [ 39 | "ExportDeclaration-0", 40 | ], 41 | }, 42 | ], 43 | "Metadata": Object { 44 | "DocumentationComment": "", 45 | "JSDocTags": Array [], 46 | }, 47 | "Name": "main.ts", 48 | "ParentId": undefined, 49 | "_ts": undefined, 50 | }, 51 | }, 52 | } 53 | `; 54 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/export-specifier1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`export-specifier1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ClassDeclaration-0": Object { 10 | "ApiKind": "class", 11 | "Extends": undefined, 12 | "Implements": Array [], 13 | "IsAbstract": false, 14 | "Location": Object { 15 | "Character": 0, 16 | "FileName": "./foo.ts", 17 | "IsExternalPackage": false, 18 | "Line": 0, 19 | }, 20 | "Members": Array [], 21 | "Metadata": Object { 22 | "DocumentationComment": "", 23 | "JSDocTags": Array [], 24 | }, 25 | "Name": "Foo", 26 | "ParentId": "SourceFile-1", 27 | "TypeParameters": Array [], 28 | "_ts": undefined, 29 | }, 30 | "ExportSpecifier-0": Object { 31 | "ApiItems": Array [ 32 | "ClassDeclaration-0", 33 | ], 34 | "ApiKind": "export-specifier", 35 | "Location": Object { 36 | "Character": 9, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 0, 40 | }, 41 | "Metadata": Object { 42 | "DocumentationComment": "", 43 | "JSDocTags": Array [], 44 | }, 45 | "Name": "Foo", 46 | "ParentId": undefined, 47 | "_ts": undefined, 48 | }, 49 | "SourceFile-0": Object { 50 | "ApiKind": "source-file", 51 | "Location": Object { 52 | "Character": 0, 53 | "FileName": "./main.ts", 54 | "IsExternalPackage": false, 55 | "Line": 0, 56 | }, 57 | "Members": Array [ 58 | Object { 59 | "Alias": "Foo", 60 | "Ids": Array [ 61 | "ExportSpecifier-0", 62 | ], 63 | }, 64 | ], 65 | "Metadata": Object { 66 | "DocumentationComment": "", 67 | "JSDocTags": Array [], 68 | }, 69 | "Name": "main.ts", 70 | "ParentId": undefined, 71 | "_ts": undefined, 72 | }, 73 | "SourceFile-1": Object { 74 | "ApiKind": "source-file", 75 | "Location": Object { 76 | "Character": 0, 77 | "FileName": "./foo.ts", 78 | "IsExternalPackage": false, 79 | "Line": 0, 80 | }, 81 | "Members": Array [ 82 | Object { 83 | "Alias": "Foo", 84 | "Ids": Array [ 85 | "ClassDeclaration-0", 86 | ], 87 | }, 88 | ], 89 | "Metadata": Object { 90 | "DocumentationComment": "", 91 | "JSDocTags": Array [], 92 | }, 93 | "Name": "foo.ts", 94 | "ParentId": undefined, 95 | "_ts": undefined, 96 | }, 97 | }, 98 | } 99 | `; 100 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/extractor-empty-file.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`extractor-empty-file 1`] = ` 4 | Object { 5 | "EntryFiles": Array [], 6 | "Registry": Object {}, 7 | } 8 | `; 9 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/function-declaration1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`function-declaration1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "FunctionDeclaration-0": Object { 10 | "ApiKind": "function", 11 | "IsAsync": false, 12 | "IsOverloadBase": false, 13 | "Location": Object { 14 | "Character": 0, 15 | "FileName": "./main.ts", 16 | "IsExternalPackage": false, 17 | "Line": 0, 18 | }, 19 | "Metadata": Object { 20 | "DocumentationComment": "", 21 | "JSDocTags": Array [], 22 | }, 23 | "Name": "Foo", 24 | "Parameters": Array [], 25 | "ParentId": "SourceFile-0", 26 | "ReturnType": Object { 27 | "ApiTypeKind": "basic", 28 | "Location": Object { 29 | "Character": 23, 30 | "FileName": "./main.ts", 31 | "IsExternalPackage": false, 32 | "Line": 0, 33 | }, 34 | "Text": "string", 35 | }, 36 | "TypeParameters": Array [], 37 | "_ts": undefined, 38 | }, 39 | "SourceFile-0": Object { 40 | "ApiKind": "source-file", 41 | "Location": Object { 42 | "Character": 0, 43 | "FileName": "./main.ts", 44 | "IsExternalPackage": false, 45 | "Line": 0, 46 | }, 47 | "Members": Array [ 48 | Object { 49 | "Alias": "Foo", 50 | "Ids": Array [ 51 | "FunctionDeclaration-0", 52 | ], 53 | }, 54 | ], 55 | "Metadata": Object { 56 | "DocumentationComment": "", 57 | "JSDocTags": Array [], 58 | }, 59 | "Name": "main.ts", 60 | "ParentId": undefined, 61 | "_ts": undefined, 62 | }, 63 | }, 64 | } 65 | `; 66 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/function-declaration3.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`function-declaration3 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "FunctionDeclaration-0": Object { 10 | "ApiKind": "function", 11 | "IsAsync": true, 12 | "IsOverloadBase": false, 13 | "Location": Object { 14 | "Character": 0, 15 | "FileName": "./main.ts", 16 | "IsExternalPackage": false, 17 | "Line": 0, 18 | }, 19 | "Metadata": Object { 20 | "DocumentationComment": "", 21 | "JSDocTags": Array [], 22 | }, 23 | "Name": "AsyncFoo", 24 | "Parameters": Array [], 25 | "ParentId": "SourceFile-0", 26 | "ReturnType": Object { 27 | "ApiTypeKind": "reference", 28 | "Location": Object { 29 | "Character": 34, 30 | "FileName": "./main.ts", 31 | "IsExternalPackage": false, 32 | "Line": 0, 33 | }, 34 | "ReferenceId": undefined, 35 | "SymbolName": "Promise", 36 | "Text": "Promise", 37 | "TypeParameters": Array [ 38 | Object { 39 | "ApiTypeKind": "basic", 40 | "Location": Object { 41 | "Character": 42, 42 | "FileName": "./main.ts", 43 | "IsExternalPackage": false, 44 | "Line": 0, 45 | }, 46 | "Text": "void", 47 | }, 48 | ], 49 | }, 50 | "TypeParameters": Array [], 51 | "_ts": undefined, 52 | }, 53 | "SourceFile-0": Object { 54 | "ApiKind": "source-file", 55 | "Location": Object { 56 | "Character": 0, 57 | "FileName": "./main.ts", 58 | "IsExternalPackage": false, 59 | "Line": 0, 60 | }, 61 | "Members": Array [ 62 | Object { 63 | "Alias": "AsyncFoo", 64 | "Ids": Array [ 65 | "FunctionDeclaration-0", 66 | ], 67 | }, 68 | ], 69 | "Metadata": Object { 70 | "DocumentationComment": "", 71 | "JSDocTags": Array [], 72 | }, 73 | "Name": "main.ts", 74 | "ParentId": undefined, 75 | "_ts": undefined, 76 | }, 77 | }, 78 | } 79 | `; 80 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/get-accessor1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`get-accessor1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ClassDeclaration-0": Object { 10 | "ApiKind": "class", 11 | "Extends": undefined, 12 | "Implements": Array [], 13 | "IsAbstract": false, 14 | "Location": Object { 15 | "Character": 0, 16 | "FileName": "./main.ts", 17 | "IsExternalPackage": false, 18 | "Line": 0, 19 | }, 20 | "Members": Array [ 21 | Object { 22 | "Alias": "Foo", 23 | "Ids": Array [ 24 | "GetAccessor-0", 25 | ], 26 | }, 27 | ], 28 | "Metadata": Object { 29 | "DocumentationComment": "", 30 | "JSDocTags": Array [], 31 | }, 32 | "Name": "Foo", 33 | "ParentId": "SourceFile-0", 34 | "TypeParameters": Array [], 35 | "_ts": undefined, 36 | }, 37 | "GetAccessor-0": Object { 38 | "AccessModifier": "public", 39 | "ApiKind": "get-accessor", 40 | "IsAbstract": false, 41 | "IsStatic": false, 42 | "Location": Object { 43 | "Character": 4, 44 | "FileName": "./main.ts", 45 | "IsExternalPackage": false, 46 | "Line": 1, 47 | }, 48 | "Metadata": Object { 49 | "DocumentationComment": "", 50 | "JSDocTags": Array [], 51 | }, 52 | "Name": "Foo", 53 | "ParentId": "ClassDeclaration-0", 54 | "Type": Object { 55 | "ApiTypeKind": "basic", 56 | "Location": Object { 57 | "Character": 22, 58 | "FileName": "./main.ts", 59 | "IsExternalPackage": false, 60 | "Line": 1, 61 | }, 62 | "Text": "string", 63 | }, 64 | "_ts": undefined, 65 | }, 66 | "SourceFile-0": Object { 67 | "ApiKind": "source-file", 68 | "Location": Object { 69 | "Character": 0, 70 | "FileName": "./main.ts", 71 | "IsExternalPackage": false, 72 | "Line": 0, 73 | }, 74 | "Members": Array [ 75 | Object { 76 | "Alias": "Foo", 77 | "Ids": Array [ 78 | "ClassDeclaration-0", 79 | ], 80 | }, 81 | ], 82 | "Metadata": Object { 83 | "DocumentationComment": "", 84 | "JSDocTags": Array [], 85 | }, 86 | "Name": "main.ts", 87 | "ParentId": undefined, 88 | "_ts": undefined, 89 | }, 90 | }, 91 | } 92 | `; 93 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/import-specifier1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`import-specifier1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ClassDeclaration-0": Object { 10 | "ApiKind": "class", 11 | "Extends": undefined, 12 | "Implements": Array [], 13 | "IsAbstract": false, 14 | "Location": Object { 15 | "Character": 0, 16 | "FileName": "./foo.ts", 17 | "IsExternalPackage": false, 18 | "Line": 0, 19 | }, 20 | "Members": Array [], 21 | "Metadata": Object { 22 | "DocumentationComment": "", 23 | "JSDocTags": Array [], 24 | }, 25 | "Name": "Foo", 26 | "ParentId": "SourceFile-1", 27 | "TypeParameters": Array [], 28 | "_ts": undefined, 29 | }, 30 | "ExportSpecifier-0": Object { 31 | "ApiItems": Array [ 32 | "ImportSpecifier-0", 33 | ], 34 | "ApiKind": "export-specifier", 35 | "Location": Object { 36 | "Character": 9, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 2, 40 | }, 41 | "Metadata": Object { 42 | "DocumentationComment": "", 43 | "JSDocTags": Array [], 44 | }, 45 | "Name": "Foo", 46 | "ParentId": undefined, 47 | "_ts": undefined, 48 | }, 49 | "ImportSpecifier-0": Object { 50 | "ApiItems": Array [ 51 | "ClassDeclaration-0", 52 | ], 53 | "ApiKind": "import-specifier", 54 | "Location": Object { 55 | "Character": 9, 56 | "FileName": "./main.ts", 57 | "IsExternalPackage": false, 58 | "Line": 0, 59 | }, 60 | "Metadata": Object { 61 | "DocumentationComment": "", 62 | "JSDocTags": Array [], 63 | }, 64 | "Name": "Foo", 65 | "ParentId": undefined, 66 | "_ts": undefined, 67 | }, 68 | "SourceFile-0": Object { 69 | "ApiKind": "source-file", 70 | "Location": Object { 71 | "Character": 0, 72 | "FileName": "./main.ts", 73 | "IsExternalPackage": false, 74 | "Line": 0, 75 | }, 76 | "Members": Array [ 77 | Object { 78 | "Alias": "Foo", 79 | "Ids": Array [ 80 | "ExportSpecifier-0", 81 | ], 82 | }, 83 | ], 84 | "Metadata": Object { 85 | "DocumentationComment": "", 86 | "JSDocTags": Array [], 87 | }, 88 | "Name": "main.ts", 89 | "ParentId": undefined, 90 | "_ts": undefined, 91 | }, 92 | "SourceFile-1": Object { 93 | "ApiKind": "source-file", 94 | "Location": Object { 95 | "Character": 0, 96 | "FileName": "./foo.ts", 97 | "IsExternalPackage": false, 98 | "Line": 0, 99 | }, 100 | "Members": Array [ 101 | Object { 102 | "Alias": "Foo", 103 | "Ids": Array [ 104 | "ClassDeclaration-0", 105 | ], 106 | }, 107 | ], 108 | "Metadata": Object { 109 | "DocumentationComment": "", 110 | "JSDocTags": Array [], 111 | }, 112 | "Name": "foo.ts", 113 | "ParentId": undefined, 114 | "_ts": undefined, 115 | }, 116 | }, 117 | } 118 | `; 119 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/import-specifier2.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`import-specifier2 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ExportSpecifier-0": Object { 10 | "ApiItems": Array [ 11 | "ImportSpecifier-0", 12 | ], 13 | "ApiKind": "export-specifier", 14 | "Location": Object { 15 | "Character": 9, 16 | "FileName": "./main.ts", 17 | "IsExternalPackage": false, 18 | "Line": 3, 19 | }, 20 | "Metadata": Object { 21 | "DocumentationComment": "", 22 | "JSDocTags": Array [], 23 | }, 24 | "Name": "DoesNotExist", 25 | "ParentId": undefined, 26 | "_ts": undefined, 27 | }, 28 | "ImportSpecifier-0": Object { 29 | "ApiItems": undefined, 30 | "ApiKind": "import-specifier", 31 | "Location": Object { 32 | "Character": 9, 33 | "FileName": "./main.ts", 34 | "IsExternalPackage": false, 35 | "Line": 1, 36 | }, 37 | "Metadata": Object { 38 | "DocumentationComment": "", 39 | "JSDocTags": Array [], 40 | }, 41 | "Name": "unknown", 42 | "ParentId": undefined, 43 | "_ts": undefined, 44 | }, 45 | "SourceFile-0": Object { 46 | "ApiKind": "source-file", 47 | "Location": Object { 48 | "Character": 0, 49 | "FileName": "./main.ts", 50 | "IsExternalPackage": false, 51 | "Line": 1, 52 | }, 53 | "Members": Array [ 54 | Object { 55 | "Alias": "DoesNotExist", 56 | "Ids": Array [ 57 | "ExportSpecifier-0", 58 | ], 59 | }, 60 | ], 61 | "Metadata": Object { 62 | "DocumentationComment": "", 63 | "JSDocTags": Array [], 64 | }, 65 | "Name": "main.ts", 66 | "ParentId": undefined, 67 | "_ts": undefined, 68 | }, 69 | }, 70 | } 71 | `; 72 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/index-signature1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`index-signature1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "IndexSignature-0": Object { 10 | "ApiKind": "index", 11 | "IsReadonly": false, 12 | "Location": Object { 13 | "Character": 4, 14 | "FileName": "./main.ts", 15 | "IsExternalPackage": false, 16 | "Line": 1, 17 | }, 18 | "Metadata": Object { 19 | "DocumentationComment": "", 20 | "JSDocTags": Array [], 21 | }, 22 | "Name": "__index", 23 | "Parameter": "Parameter-0", 24 | "ParentId": "InterfaceDeclaration-0", 25 | "Type": Object { 26 | "ApiTypeKind": "basic", 27 | "Location": Object { 28 | "Character": 19, 29 | "FileName": "./main.ts", 30 | "IsExternalPackage": false, 31 | "Line": 1, 32 | }, 33 | "Text": "number", 34 | }, 35 | "_ts": undefined, 36 | }, 37 | "InterfaceDeclaration-0": Object { 38 | "ApiKind": "interface", 39 | "Extends": Array [], 40 | "Location": Object { 41 | "Character": 0, 42 | "FileName": "./main.ts", 43 | "IsExternalPackage": false, 44 | "Line": 0, 45 | }, 46 | "Members": Array [ 47 | Object { 48 | "Alias": "__index", 49 | "Ids": Array [ 50 | "IndexSignature-0", 51 | ], 52 | }, 53 | ], 54 | "Metadata": Object { 55 | "DocumentationComment": "", 56 | "JSDocTags": Array [], 57 | }, 58 | "Name": "Foo", 59 | "ParentId": "SourceFile-0", 60 | "TypeParameters": Array [], 61 | "_ts": undefined, 62 | }, 63 | "Parameter-0": Object { 64 | "ApiKind": "parameter", 65 | "Initializer": undefined, 66 | "IsOptional": false, 67 | "IsSpread": false, 68 | "Location": Object { 69 | "Character": 5, 70 | "FileName": "./main.ts", 71 | "IsExternalPackage": false, 72 | "Line": 1, 73 | }, 74 | "Metadata": Object { 75 | "DocumentationComment": "", 76 | "JSDocTags": Array [], 77 | }, 78 | "Name": "key", 79 | "ParentId": "IndexSignature-0", 80 | "Type": Object { 81 | "ApiTypeKind": "basic", 82 | "Location": Object { 83 | "Character": 10, 84 | "FileName": "./main.ts", 85 | "IsExternalPackage": false, 86 | "Line": 1, 87 | }, 88 | "Text": "string", 89 | }, 90 | "_ts": undefined, 91 | }, 92 | "SourceFile-0": Object { 93 | "ApiKind": "source-file", 94 | "Location": Object { 95 | "Character": 0, 96 | "FileName": "./main.ts", 97 | "IsExternalPackage": false, 98 | "Line": 0, 99 | }, 100 | "Members": Array [ 101 | Object { 102 | "Alias": "Foo", 103 | "Ids": Array [ 104 | "InterfaceDeclaration-0", 105 | ], 106 | }, 107 | ], 108 | "Metadata": Object { 109 | "DocumentationComment": "", 110 | "JSDocTags": Array [], 111 | }, 112 | "Name": "main.ts", 113 | "ParentId": undefined, 114 | "_ts": undefined, 115 | }, 116 | }, 117 | } 118 | `; 119 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/index-signature2.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`index-signature2 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "IndexSignature-0": Object { 10 | "ApiKind": "index", 11 | "IsReadonly": true, 12 | "Location": Object { 13 | "Character": 4, 14 | "FileName": "./main.ts", 15 | "IsExternalPackage": false, 16 | "Line": 1, 17 | }, 18 | "Metadata": Object { 19 | "DocumentationComment": "", 20 | "JSDocTags": Array [], 21 | }, 22 | "Name": "__index", 23 | "Parameter": "Parameter-0", 24 | "ParentId": "InterfaceDeclaration-0", 25 | "Type": Object { 26 | "ApiTypeKind": "basic", 27 | "Location": Object { 28 | "Character": 28, 29 | "FileName": "./main.ts", 30 | "IsExternalPackage": false, 31 | "Line": 1, 32 | }, 33 | "Text": "number", 34 | }, 35 | "_ts": undefined, 36 | }, 37 | "InterfaceDeclaration-0": Object { 38 | "ApiKind": "interface", 39 | "Extends": Array [], 40 | "Location": Object { 41 | "Character": 0, 42 | "FileName": "./main.ts", 43 | "IsExternalPackage": false, 44 | "Line": 0, 45 | }, 46 | "Members": Array [ 47 | Object { 48 | "Alias": "__index", 49 | "Ids": Array [ 50 | "IndexSignature-0", 51 | ], 52 | }, 53 | ], 54 | "Metadata": Object { 55 | "DocumentationComment": "", 56 | "JSDocTags": Array [], 57 | }, 58 | "Name": "Foo", 59 | "ParentId": "SourceFile-0", 60 | "TypeParameters": Array [], 61 | "_ts": undefined, 62 | }, 63 | "Parameter-0": Object { 64 | "ApiKind": "parameter", 65 | "Initializer": undefined, 66 | "IsOptional": false, 67 | "IsSpread": false, 68 | "Location": Object { 69 | "Character": 14, 70 | "FileName": "./main.ts", 71 | "IsExternalPackage": false, 72 | "Line": 1, 73 | }, 74 | "Metadata": Object { 75 | "DocumentationComment": "", 76 | "JSDocTags": Array [], 77 | }, 78 | "Name": "key", 79 | "ParentId": "IndexSignature-0", 80 | "Type": Object { 81 | "ApiTypeKind": "basic", 82 | "Location": Object { 83 | "Character": 19, 84 | "FileName": "./main.ts", 85 | "IsExternalPackage": false, 86 | "Line": 1, 87 | }, 88 | "Text": "string", 89 | }, 90 | "_ts": undefined, 91 | }, 92 | "SourceFile-0": Object { 93 | "ApiKind": "source-file", 94 | "Location": Object { 95 | "Character": 0, 96 | "FileName": "./main.ts", 97 | "IsExternalPackage": false, 98 | "Line": 0, 99 | }, 100 | "Members": Array [ 101 | Object { 102 | "Alias": "Foo", 103 | "Ids": Array [ 104 | "InterfaceDeclaration-0", 105 | ], 106 | }, 107 | ], 108 | "Metadata": Object { 109 | "DocumentationComment": "", 110 | "JSDocTags": Array [], 111 | }, 112 | "Name": "main.ts", 113 | "ParentId": undefined, 114 | "_ts": undefined, 115 | }, 116 | }, 117 | } 118 | `; 119 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/interface-declaration1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`interface-declaration1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "InterfaceDeclaration-0": Object { 10 | "ApiKind": "interface", 11 | "Extends": Array [], 12 | "Location": Object { 13 | "Character": 0, 14 | "FileName": "./main.ts", 15 | "IsExternalPackage": false, 16 | "Line": 0, 17 | }, 18 | "Members": Array [], 19 | "Metadata": Object { 20 | "DocumentationComment": "", 21 | "JSDocTags": Array [], 22 | }, 23 | "Name": "Foo", 24 | "ParentId": "SourceFile-0", 25 | "TypeParameters": Array [], 26 | "_ts": undefined, 27 | }, 28 | "SourceFile-0": Object { 29 | "ApiKind": "source-file", 30 | "Location": Object { 31 | "Character": 0, 32 | "FileName": "./main.ts", 33 | "IsExternalPackage": false, 34 | "Line": 0, 35 | }, 36 | "Members": Array [ 37 | Object { 38 | "Alias": "Foo", 39 | "Ids": Array [ 40 | "InterfaceDeclaration-0", 41 | ], 42 | }, 43 | ], 44 | "Metadata": Object { 45 | "DocumentationComment": "", 46 | "JSDocTags": Array [], 47 | }, 48 | "Name": "main.ts", 49 | "ParentId": undefined, 50 | "_ts": undefined, 51 | }, 52 | }, 53 | } 54 | `; 55 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/interface-declaration2.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`interface-declaration2 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "InterfaceDeclaration-0": Object { 10 | "ApiKind": "interface", 11 | "Extends": Array [], 12 | "Location": Object { 13 | "Character": 0, 14 | "FileName": "./main.ts", 15 | "IsExternalPackage": false, 16 | "Line": 0, 17 | }, 18 | "Members": Array [ 19 | Object { 20 | "Alias": "Bar", 21 | "Ids": Array [ 22 | "PropertySignature-0", 23 | ], 24 | }, 25 | ], 26 | "Metadata": Object { 27 | "DocumentationComment": "", 28 | "JSDocTags": Array [], 29 | }, 30 | "Name": "Foo", 31 | "ParentId": "SourceFile-0", 32 | "TypeParameters": Array [], 33 | "_ts": undefined, 34 | }, 35 | "PropertySignature-0": Object { 36 | "ApiKind": "property", 37 | "IsOptional": false, 38 | "IsReadonly": false, 39 | "Location": Object { 40 | "Character": 2, 41 | "FileName": "./main.ts", 42 | "IsExternalPackage": false, 43 | "Line": 1, 44 | }, 45 | "Metadata": Object { 46 | "DocumentationComment": "", 47 | "JSDocTags": Array [], 48 | }, 49 | "Name": "Bar", 50 | "ParentId": "InterfaceDeclaration-0", 51 | "Type": Object { 52 | "ApiTypeKind": "basic", 53 | "Location": Object { 54 | "Character": 7, 55 | "FileName": "./main.ts", 56 | "IsExternalPackage": false, 57 | "Line": 1, 58 | }, 59 | "Text": "string", 60 | }, 61 | "_ts": undefined, 62 | }, 63 | "SourceFile-0": Object { 64 | "ApiKind": "source-file", 65 | "Location": Object { 66 | "Character": 0, 67 | "FileName": "./main.ts", 68 | "IsExternalPackage": false, 69 | "Line": 0, 70 | }, 71 | "Members": Array [ 72 | Object { 73 | "Alias": "Foo", 74 | "Ids": Array [ 75 | "InterfaceDeclaration-0", 76 | ], 77 | }, 78 | ], 79 | "Metadata": Object { 80 | "DocumentationComment": "", 81 | "JSDocTags": Array [], 82 | }, 83 | "Name": "main.ts", 84 | "ParentId": undefined, 85 | "_ts": undefined, 86 | }, 87 | }, 88 | } 89 | `; 90 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/interface-declaration7.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`interface-declaration7 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "InterfaceDeclaration-0": Object { 10 | "ApiKind": "interface", 11 | "Extends": Array [], 12 | "Location": Object { 13 | "Character": 0, 14 | "FileName": "./main.ts", 15 | "IsExternalPackage": false, 16 | "Line": 0, 17 | }, 18 | "Members": Array [ 19 | Object { 20 | "Alias": "Bar", 21 | "Ids": Array [ 22 | "PropertySignature-0", 23 | ], 24 | }, 25 | ], 26 | "Metadata": Object { 27 | "DocumentationComment": "", 28 | "JSDocTags": Array [], 29 | }, 30 | "Name": "Foo", 31 | "ParentId": "SourceFile-0", 32 | "TypeParameters": Array [], 33 | "_ts": undefined, 34 | }, 35 | "PropertySignature-0": Object { 36 | "ApiKind": "property", 37 | "IsOptional": false, 38 | "IsReadonly": true, 39 | "Location": Object { 40 | "Character": 4, 41 | "FileName": "./main.ts", 42 | "IsExternalPackage": false, 43 | "Line": 1, 44 | }, 45 | "Metadata": Object { 46 | "DocumentationComment": "", 47 | "JSDocTags": Array [], 48 | }, 49 | "Name": "Bar", 50 | "ParentId": "InterfaceDeclaration-0", 51 | "Type": Object { 52 | "ApiTypeKind": "basic", 53 | "Location": Object { 54 | "Character": 18, 55 | "FileName": "./main.ts", 56 | "IsExternalPackage": false, 57 | "Line": 1, 58 | }, 59 | "Text": "string", 60 | }, 61 | "_ts": undefined, 62 | }, 63 | "SourceFile-0": Object { 64 | "ApiKind": "source-file", 65 | "Location": Object { 66 | "Character": 0, 67 | "FileName": "./main.ts", 68 | "IsExternalPackage": false, 69 | "Line": 0, 70 | }, 71 | "Members": Array [ 72 | Object { 73 | "Alias": "Foo", 74 | "Ids": Array [ 75 | "InterfaceDeclaration-0", 76 | ], 77 | }, 78 | ], 79 | "Metadata": Object { 80 | "DocumentationComment": "", 81 | "JSDocTags": Array [], 82 | }, 83 | "Name": "main.ts", 84 | "ParentId": undefined, 85 | "_ts": undefined, 86 | }, 87 | }, 88 | } 89 | `; 90 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/namespace-declaration1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`namespace-declaration1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ModuleDeclaration-0": Object { 10 | "ApiKind": "namespace", 11 | "Location": Object { 12 | "Character": 0, 13 | "FileName": "./main.ts", 14 | "IsExternalPackage": false, 15 | "Line": 0, 16 | }, 17 | "Members": Array [], 18 | "Metadata": Object { 19 | "DocumentationComment": "", 20 | "JSDocTags": Array [], 21 | }, 22 | "Name": "Foo", 23 | "ParentId": "SourceFile-0", 24 | "_ts": undefined, 25 | }, 26 | "SourceFile-0": Object { 27 | "ApiKind": "source-file", 28 | "Location": Object { 29 | "Character": 0, 30 | "FileName": "./main.ts", 31 | "IsExternalPackage": false, 32 | "Line": 0, 33 | }, 34 | "Members": Array [ 35 | Object { 36 | "Alias": "Foo", 37 | "Ids": Array [ 38 | "ModuleDeclaration-0", 39 | ], 40 | }, 41 | ], 42 | "Metadata": Object { 43 | "DocumentationComment": "", 44 | "JSDocTags": Array [], 45 | }, 46 | "Name": "main.ts", 47 | "ParentId": undefined, 48 | "_ts": undefined, 49 | }, 50 | }, 51 | } 52 | `; 53 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/namespace-declaration2.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`namespace-declaration2 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ModuleDeclaration-0": Object { 10 | "ApiKind": "namespace", 11 | "Location": Object { 12 | "Character": 0, 13 | "FileName": "./main.ts", 14 | "IsExternalPackage": false, 15 | "Line": 0, 16 | }, 17 | "Members": Array [ 18 | Object { 19 | "Alias": "Bar", 20 | "Ids": Array [ 21 | "ModuleDeclaration-1", 22 | ], 23 | }, 24 | ], 25 | "Metadata": Object { 26 | "DocumentationComment": "", 27 | "JSDocTags": Array [], 28 | }, 29 | "Name": "Foo", 30 | "ParentId": "SourceFile-0", 31 | "_ts": undefined, 32 | }, 33 | "ModuleDeclaration-1": Object { 34 | "ApiKind": "namespace", 35 | "Location": Object { 36 | "Character": 4, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 1, 40 | }, 41 | "Members": Array [], 42 | "Metadata": Object { 43 | "DocumentationComment": "", 44 | "JSDocTags": Array [], 45 | }, 46 | "Name": "Bar", 47 | "ParentId": undefined, 48 | "_ts": undefined, 49 | }, 50 | "SourceFile-0": Object { 51 | "ApiKind": "source-file", 52 | "Location": Object { 53 | "Character": 0, 54 | "FileName": "./main.ts", 55 | "IsExternalPackage": false, 56 | "Line": 0, 57 | }, 58 | "Members": Array [ 59 | Object { 60 | "Alias": "Foo", 61 | "Ids": Array [ 62 | "ModuleDeclaration-0", 63 | ], 64 | }, 65 | ], 66 | "Metadata": Object { 67 | "DocumentationComment": "", 68 | "JSDocTags": Array [], 69 | }, 70 | "Name": "main.ts", 71 | "ParentId": undefined, 72 | "_ts": undefined, 73 | }, 74 | }, 75 | } 76 | `; 77 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/namespace-declaration3.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`namespace-declaration3 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ModuleDeclaration-0": Object { 10 | "ApiKind": "namespace", 11 | "Location": Object { 12 | "Character": 0, 13 | "FileName": "./main.ts", 14 | "IsExternalPackage": false, 15 | "Line": 0, 16 | }, 17 | "Members": Array [ 18 | Object { 19 | "Alias": "Bar", 20 | "Ids": Array [ 21 | "ModuleDeclaration-1", 22 | ], 23 | }, 24 | ], 25 | "Metadata": Object { 26 | "DocumentationComment": "", 27 | "JSDocTags": Array [], 28 | }, 29 | "Name": "Foo", 30 | "ParentId": "SourceFile-0", 31 | "_ts": undefined, 32 | }, 33 | "ModuleDeclaration-1": Object { 34 | "ApiKind": "namespace", 35 | "Location": Object { 36 | "Character": 4, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 1, 40 | }, 41 | "Members": Array [ 42 | Object { 43 | "Alias": "Hello", 44 | "Ids": Array [ 45 | "VariableDeclaration-0", 46 | ], 47 | }, 48 | ], 49 | "Metadata": Object { 50 | "DocumentationComment": "", 51 | "JSDocTags": Array [], 52 | }, 53 | "Name": "Bar", 54 | "ParentId": undefined, 55 | "_ts": undefined, 56 | }, 57 | "SourceFile-0": Object { 58 | "ApiKind": "source-file", 59 | "Location": Object { 60 | "Character": 0, 61 | "FileName": "./main.ts", 62 | "IsExternalPackage": false, 63 | "Line": 0, 64 | }, 65 | "Members": Array [ 66 | Object { 67 | "Alias": "Foo", 68 | "Ids": Array [ 69 | "ModuleDeclaration-0", 70 | ], 71 | }, 72 | ], 73 | "Metadata": Object { 74 | "DocumentationComment": "", 75 | "JSDocTags": Array [], 76 | }, 77 | "Name": "main.ts", 78 | "ParentId": undefined, 79 | "_ts": undefined, 80 | }, 81 | "VariableDeclaration-0": Object { 82 | "ApiKind": "variable", 83 | "Location": Object { 84 | "Character": 21, 85 | "FileName": "./main.ts", 86 | "IsExternalPackage": false, 87 | "Line": 2, 88 | }, 89 | "Metadata": Object { 90 | "DocumentationComment": "", 91 | "JSDocTags": Array [], 92 | }, 93 | "Name": "Hello", 94 | "ParentId": undefined, 95 | "Type": Object { 96 | "ApiTypeKind": "basic", 97 | "Location": Object { 98 | "Character": 21, 99 | "FileName": "./main.ts", 100 | "IsExternalPackage": false, 101 | "Line": 2, 102 | }, 103 | "Text": "\\"world!\\"", 104 | }, 105 | "VariableDeclarationType": "const", 106 | "_ts": undefined, 107 | }, 108 | }, 109 | } 110 | `; 111 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/parameter-declaration1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`parameter-declaration1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "FunctionDeclaration-0": Object { 10 | "ApiKind": "function", 11 | "IsAsync": false, 12 | "IsOverloadBase": false, 13 | "Location": Object { 14 | "Character": 0, 15 | "FileName": "./main.ts", 16 | "IsExternalPackage": false, 17 | "Line": 2, 18 | }, 19 | "Metadata": Object { 20 | "DocumentationComment": "", 21 | "JSDocTags": Array [], 22 | }, 23 | "Name": "FooFunction", 24 | "Parameters": Array [ 25 | Object { 26 | "Alias": "bar", 27 | "Ids": Array [ 28 | "Parameter-0", 29 | ], 30 | }, 31 | ], 32 | "ParentId": "SourceFile-0", 33 | "ReturnType": Object { 34 | "ApiTypeKind": "basic", 35 | "Location": Object { 36 | "Character": 44, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 2, 40 | }, 41 | "Text": "void", 42 | }, 43 | "TypeParameters": Array [], 44 | "_ts": undefined, 45 | }, 46 | "Parameter-0": Object { 47 | "ApiKind": "parameter", 48 | "Initializer": undefined, 49 | "IsOptional": true, 50 | "IsSpread": false, 51 | "Location": Object { 52 | "Character": 28, 53 | "FileName": "./main.ts", 54 | "IsExternalPackage": false, 55 | "Line": 2, 56 | }, 57 | "Metadata": Object { 58 | "DocumentationComment": "", 59 | "JSDocTags": Array [], 60 | }, 61 | "Name": "bar", 62 | "ParentId": "FunctionDeclaration-0", 63 | "Type": Object { 64 | "ApiTypeKind": "basic", 65 | "Location": Object { 66 | "Character": 34, 67 | "FileName": "./main.ts", 68 | "IsExternalPackage": false, 69 | "Line": 2, 70 | }, 71 | "Text": "boolean", 72 | }, 73 | "_ts": undefined, 74 | }, 75 | "SourceFile-0": Object { 76 | "ApiKind": "source-file", 77 | "Location": Object { 78 | "Character": 0, 79 | "FileName": "./main.ts", 80 | "IsExternalPackage": false, 81 | "Line": 2, 82 | }, 83 | "Members": Array [ 84 | Object { 85 | "Alias": "FooFunction", 86 | "Ids": Array [ 87 | "FunctionDeclaration-0", 88 | ], 89 | }, 90 | ], 91 | "Metadata": Object { 92 | "DocumentationComment": "", 93 | "JSDocTags": Array [], 94 | }, 95 | "Name": "main.ts", 96 | "ParentId": undefined, 97 | "_ts": undefined, 98 | }, 99 | }, 100 | } 101 | `; 102 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/parameter-declaration2.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`parameter-declaration2 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "FunctionDeclaration-0": Object { 10 | "ApiKind": "function", 11 | "IsAsync": false, 12 | "IsOverloadBase": false, 13 | "Location": Object { 14 | "Character": 0, 15 | "FileName": "./main.ts", 16 | "IsExternalPackage": false, 17 | "Line": 2, 18 | }, 19 | "Metadata": Object { 20 | "DocumentationComment": "", 21 | "JSDocTags": Array [], 22 | }, 23 | "Name": "FooFunction", 24 | "Parameters": Array [ 25 | Object { 26 | "Alias": "bar", 27 | "Ids": Array [ 28 | "Parameter-0", 29 | ], 30 | }, 31 | ], 32 | "ParentId": "SourceFile-0", 33 | "ReturnType": Object { 34 | "ApiTypeKind": "basic", 35 | "Location": Object { 36 | "Character": 47, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 2, 40 | }, 41 | "Text": "void", 42 | }, 43 | "TypeParameters": Array [], 44 | "_ts": undefined, 45 | }, 46 | "Parameter-0": Object { 47 | "ApiKind": "parameter", 48 | "Initializer": undefined, 49 | "IsOptional": false, 50 | "IsSpread": true, 51 | "Location": Object { 52 | "Character": 28, 53 | "FileName": "./main.ts", 54 | "IsExternalPackage": false, 55 | "Line": 2, 56 | }, 57 | "Metadata": Object { 58 | "DocumentationComment": "", 59 | "JSDocTags": Array [], 60 | }, 61 | "Name": "bar", 62 | "ParentId": "FunctionDeclaration-0", 63 | "Type": Object { 64 | "ApiTypeKind": "array", 65 | "Location": Object { 66 | "Character": 36, 67 | "FileName": "./main.ts", 68 | "IsExternalPackage": false, 69 | "Line": 2, 70 | }, 71 | "Text": "string[]", 72 | "Type": Object { 73 | "ApiTypeKind": "basic", 74 | "Location": Object { 75 | "Character": 36, 76 | "FileName": "./main.ts", 77 | "IsExternalPackage": false, 78 | "Line": 2, 79 | }, 80 | "Text": "string", 81 | }, 82 | }, 83 | "_ts": undefined, 84 | }, 85 | "SourceFile-0": Object { 86 | "ApiKind": "source-file", 87 | "Location": Object { 88 | "Character": 0, 89 | "FileName": "./main.ts", 90 | "IsExternalPackage": false, 91 | "Line": 2, 92 | }, 93 | "Members": Array [ 94 | Object { 95 | "Alias": "FooFunction", 96 | "Ids": Array [ 97 | "FunctionDeclaration-0", 98 | ], 99 | }, 100 | ], 101 | "Metadata": Object { 102 | "DocumentationComment": "", 103 | "JSDocTags": Array [], 104 | }, 105 | "Name": "main.ts", 106 | "ParentId": undefined, 107 | "_ts": undefined, 108 | }, 109 | }, 110 | } 111 | `; 112 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/parameter-declaration3.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`parameter-declaration3 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "FunctionDeclaration-0": Object { 10 | "ApiKind": "function", 11 | "IsAsync": false, 12 | "IsOverloadBase": false, 13 | "Location": Object { 14 | "Character": 0, 15 | "FileName": "./main.ts", 16 | "IsExternalPackage": false, 17 | "Line": 2, 18 | }, 19 | "Metadata": Object { 20 | "DocumentationComment": "", 21 | "JSDocTags": Array [], 22 | }, 23 | "Name": "FooFunction", 24 | "Parameters": Array [ 25 | Object { 26 | "Alias": "bar", 27 | "Ids": Array [ 28 | "Parameter-0", 29 | ], 30 | }, 31 | ], 32 | "ParentId": "SourceFile-0", 33 | "ReturnType": Object { 34 | "ApiTypeKind": "basic", 35 | "Location": Object { 36 | "Character": 59, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 2, 40 | }, 41 | "Text": "void", 42 | }, 43 | "TypeParameters": Array [], 44 | "_ts": undefined, 45 | }, 46 | "Parameter-0": Object { 47 | "ApiKind": "parameter", 48 | "Initializer": "\\"Hello World!\\"", 49 | "IsOptional": false, 50 | "IsSpread": false, 51 | "Location": Object { 52 | "Character": 28, 53 | "FileName": "./main.ts", 54 | "IsExternalPackage": false, 55 | "Line": 2, 56 | }, 57 | "Metadata": Object { 58 | "DocumentationComment": "", 59 | "JSDocTags": Array [], 60 | }, 61 | "Name": "bar", 62 | "ParentId": "FunctionDeclaration-0", 63 | "Type": Object { 64 | "ApiTypeKind": "basic", 65 | "Location": Object { 66 | "Character": 33, 67 | "FileName": "./main.ts", 68 | "IsExternalPackage": false, 69 | "Line": 2, 70 | }, 71 | "Text": "string", 72 | }, 73 | "_ts": undefined, 74 | }, 75 | "SourceFile-0": Object { 76 | "ApiKind": "source-file", 77 | "Location": Object { 78 | "Character": 0, 79 | "FileName": "./main.ts", 80 | "IsExternalPackage": false, 81 | "Line": 2, 82 | }, 83 | "Members": Array [ 84 | Object { 85 | "Alias": "FooFunction", 86 | "Ids": Array [ 87 | "FunctionDeclaration-0", 88 | ], 89 | }, 90 | ], 91 | "Metadata": Object { 92 | "DocumentationComment": "", 93 | "JSDocTags": Array [], 94 | }, 95 | "Name": "main.ts", 96 | "ParentId": undefined, 97 | "_ts": undefined, 98 | }, 99 | }, 100 | } 101 | `; 102 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/set-accessor1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`set-accessor1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "ClassDeclaration-0": Object { 10 | "ApiKind": "class", 11 | "Extends": undefined, 12 | "Implements": Array [], 13 | "IsAbstract": false, 14 | "Location": Object { 15 | "Character": 0, 16 | "FileName": "./main.ts", 17 | "IsExternalPackage": false, 18 | "Line": 0, 19 | }, 20 | "Members": Array [ 21 | Object { 22 | "Alias": "Foo", 23 | "Ids": Array [ 24 | "SetAccessor-0", 25 | ], 26 | }, 27 | ], 28 | "Metadata": Object { 29 | "DocumentationComment": "", 30 | "JSDocTags": Array [], 31 | }, 32 | "Name": "Foo", 33 | "ParentId": "SourceFile-0", 34 | "TypeParameters": Array [], 35 | "_ts": undefined, 36 | }, 37 | "Parameter-0": Object { 38 | "ApiKind": "parameter", 39 | "Initializer": undefined, 40 | "IsOptional": false, 41 | "IsSpread": false, 42 | "Location": Object { 43 | "Character": 19, 44 | "FileName": "./main.ts", 45 | "IsExternalPackage": false, 46 | "Line": 1, 47 | }, 48 | "Metadata": Object { 49 | "DocumentationComment": "", 50 | "JSDocTags": Array [], 51 | }, 52 | "Name": "arg", 53 | "ParentId": "SetAccessor-0", 54 | "Type": Object { 55 | "ApiTypeKind": "basic", 56 | "Location": Object { 57 | "Character": 24, 58 | "FileName": "./main.ts", 59 | "IsExternalPackage": false, 60 | "Line": 1, 61 | }, 62 | "Text": "string", 63 | }, 64 | "_ts": undefined, 65 | }, 66 | "SetAccessor-0": Object { 67 | "AccessModifier": "public", 68 | "ApiKind": "set-accessor", 69 | "IsAbstract": false, 70 | "IsStatic": false, 71 | "Location": Object { 72 | "Character": 4, 73 | "FileName": "./main.ts", 74 | "IsExternalPackage": false, 75 | "Line": 1, 76 | }, 77 | "Metadata": Object { 78 | "DocumentationComment": "", 79 | "JSDocTags": Array [], 80 | }, 81 | "Name": "Foo", 82 | "Parameter": Object { 83 | "Alias": "arg", 84 | "Ids": Array [ 85 | "Parameter-0", 86 | ], 87 | }, 88 | "ParentId": "ClassDeclaration-0", 89 | "_ts": undefined, 90 | }, 91 | "SourceFile-0": Object { 92 | "ApiKind": "source-file", 93 | "Location": Object { 94 | "Character": 0, 95 | "FileName": "./main.ts", 96 | "IsExternalPackage": false, 97 | "Line": 0, 98 | }, 99 | "Members": Array [ 100 | Object { 101 | "Alias": "Foo", 102 | "Ids": Array [ 103 | "ClassDeclaration-0", 104 | ], 105 | }, 106 | ], 107 | "Metadata": Object { 108 | "DocumentationComment": "", 109 | "JSDocTags": Array [], 110 | }, 111 | "Name": "main.ts", 112 | "ParentId": undefined, 113 | "_ts": undefined, 114 | }, 115 | }, 116 | } 117 | `; 118 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/symbol1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`symbol1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "SourceFile-0": Object { 10 | "ApiKind": "source-file", 11 | "Location": Object { 12 | "Character": 0, 13 | "FileName": "./main.ts", 14 | "IsExternalPackage": false, 15 | "Line": 0, 16 | }, 17 | "Members": Array [ 18 | Object { 19 | "Alias": "foo", 20 | "Ids": Array [ 21 | "VariableDeclaration-0", 22 | ], 23 | }, 24 | ], 25 | "Metadata": Object { 26 | "DocumentationComment": "", 27 | "JSDocTags": Array [], 28 | }, 29 | "Name": "main.ts", 30 | "ParentId": undefined, 31 | "_ts": undefined, 32 | }, 33 | "VariableDeclaration-0": Object { 34 | "ApiKind": "variable", 35 | "Location": Object { 36 | "Character": 13, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 0, 40 | }, 41 | "Metadata": Object { 42 | "DocumentationComment": "", 43 | "JSDocTags": Array [], 44 | }, 45 | "Name": "foo", 46 | "ParentId": undefined, 47 | "Type": Object { 48 | "ApiTypeKind": "type-operator", 49 | "Keyword": "unique", 50 | "Location": Object { 51 | "Character": 13, 52 | "FileName": "./main.ts", 53 | "IsExternalPackage": false, 54 | "Line": 0, 55 | }, 56 | "Text": "unique symbol", 57 | "Type": Object { 58 | "ApiTypeKind": "basic", 59 | "Location": Object { 60 | "Character": 13, 61 | "FileName": "./main.ts", 62 | "IsExternalPackage": false, 63 | "Line": 0, 64 | }, 65 | "Text": "symbol", 66 | }, 67 | }, 68 | "VariableDeclarationType": "const", 69 | "_ts": undefined, 70 | }, 71 | }, 72 | } 73 | `; 74 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/type-alias-declaration5.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`type-alias-declaration5 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "SourceFile-0": Object { 10 | "ApiKind": "source-file", 11 | "Location": Object { 12 | "Character": 0, 13 | "FileName": "./main.ts", 14 | "IsExternalPackage": false, 15 | "Line": 0, 16 | }, 17 | "Members": Array [ 18 | Object { 19 | "Alias": "FooTuple", 20 | "Ids": Array [ 21 | "TypeAliasDeclaration-0", 22 | ], 23 | }, 24 | ], 25 | "Metadata": Object { 26 | "DocumentationComment": "", 27 | "JSDocTags": Array [], 28 | }, 29 | "Name": "main.ts", 30 | "ParentId": undefined, 31 | "_ts": undefined, 32 | }, 33 | "TypeAliasDeclaration-0": Object { 34 | "ApiKind": "type-alias", 35 | "Location": Object { 36 | "Character": 0, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 0, 40 | }, 41 | "Metadata": Object { 42 | "DocumentationComment": "", 43 | "JSDocTags": Array [], 44 | }, 45 | "Name": "FooTuple", 46 | "ParentId": "SourceFile-0", 47 | "Type": Object { 48 | "ApiTypeKind": "tuple", 49 | "Location": Object { 50 | "Character": 23, 51 | "FileName": "./main.ts", 52 | "IsExternalPackage": false, 53 | "Line": 0, 54 | }, 55 | "Members": Array [ 56 | Object { 57 | "ApiTypeKind": "basic", 58 | "Location": Object { 59 | "Character": 24, 60 | "FileName": "./main.ts", 61 | "IsExternalPackage": false, 62 | "Line": 0, 63 | }, 64 | "Text": "string", 65 | }, 66 | Object { 67 | "ApiTypeKind": "basic", 68 | "Location": Object { 69 | "Character": 32, 70 | "FileName": "./main.ts", 71 | "IsExternalPackage": false, 72 | "Line": 0, 73 | }, 74 | "Text": "number", 75 | }, 76 | ], 77 | "Text": "[string, number]", 78 | }, 79 | "TypeParameters": Array [], 80 | "_ts": undefined, 81 | }, 82 | }, 83 | } 84 | `; 85 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/type-alias-declaration7.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`type-alias-declaration7 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "SourceFile-0": Object { 10 | "ApiKind": "source-file", 11 | "Location": Object { 12 | "Character": 0, 13 | "FileName": "./main.ts", 14 | "IsExternalPackage": false, 15 | "Line": 0, 16 | }, 17 | "Members": Array [ 18 | Object { 19 | "Alias": "Foo", 20 | "Ids": Array [ 21 | "TypeAliasDeclaration-0", 22 | ], 23 | }, 24 | ], 25 | "Metadata": Object { 26 | "DocumentationComment": "", 27 | "JSDocTags": Array [], 28 | }, 29 | "Name": "main.ts", 30 | "ParentId": undefined, 31 | "_ts": undefined, 32 | }, 33 | "TypeAliasDeclaration-0": Object { 34 | "ApiKind": "type-alias", 35 | "Location": Object { 36 | "Character": 0, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 0, 40 | }, 41 | "Metadata": Object { 42 | "DocumentationComment": "", 43 | "JSDocTags": Array [], 44 | }, 45 | "Name": "Foo", 46 | "ParentId": "SourceFile-0", 47 | "Type": Object { 48 | "ApiTypeKind": "array", 49 | "Location": Object { 50 | "Character": 18, 51 | "FileName": "./main.ts", 52 | "IsExternalPackage": false, 53 | "Line": 0, 54 | }, 55 | "Text": "(string | number)[]", 56 | "Type": Object { 57 | "ApiTypeKind": "parenthesized", 58 | "Location": Object { 59 | "Character": 18, 60 | "FileName": "./main.ts", 61 | "IsExternalPackage": false, 62 | "Line": 0, 63 | }, 64 | "Text": "string | number", 65 | "Type": Object { 66 | "ApiTypeKind": "union", 67 | "Location": Object { 68 | "Character": 19, 69 | "FileName": "./main.ts", 70 | "IsExternalPackage": false, 71 | "Line": 0, 72 | }, 73 | "Members": Array [ 74 | Object { 75 | "ApiTypeKind": "basic", 76 | "Location": Object { 77 | "Character": 19, 78 | "FileName": "./main.ts", 79 | "IsExternalPackage": false, 80 | "Line": 0, 81 | }, 82 | "Text": "string", 83 | }, 84 | Object { 85 | "ApiTypeKind": "basic", 86 | "Location": Object { 87 | "Character": 28, 88 | "FileName": "./main.ts", 89 | "IsExternalPackage": false, 90 | "Line": 0, 91 | }, 92 | "Text": "number", 93 | }, 94 | ], 95 | "Text": "string | number", 96 | }, 97 | }, 98 | }, 99 | "TypeParameters": Array [], 100 | "_ts": undefined, 101 | }, 102 | }, 103 | } 104 | `; 105 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/variable-declaration1.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`variable-declaration1 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "SourceFile-0": Object { 10 | "ApiKind": "source-file", 11 | "Location": Object { 12 | "Character": 0, 13 | "FileName": "./main.ts", 14 | "IsExternalPackage": false, 15 | "Line": 0, 16 | }, 17 | "Members": Array [ 18 | Object { 19 | "Alias": "FOO", 20 | "Ids": Array [ 21 | "VariableDeclaration-0", 22 | ], 23 | }, 24 | ], 25 | "Metadata": Object { 26 | "DocumentationComment": "", 27 | "JSDocTags": Array [], 28 | }, 29 | "Name": "main.ts", 30 | "ParentId": undefined, 31 | "_ts": undefined, 32 | }, 33 | "VariableDeclaration-0": Object { 34 | "ApiKind": "variable", 35 | "Location": Object { 36 | "Character": 13, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 0, 40 | }, 41 | "Metadata": Object { 42 | "DocumentationComment": "", 43 | "JSDocTags": Array [], 44 | }, 45 | "Name": "FOO", 46 | "ParentId": undefined, 47 | "Type": Object { 48 | "ApiTypeKind": "basic", 49 | "Location": Object { 50 | "Character": 18, 51 | "FileName": "./main.ts", 52 | "IsExternalPackage": false, 53 | "Line": 0, 54 | }, 55 | "Text": "undefined", 56 | }, 57 | "VariableDeclarationType": "const", 58 | "_ts": undefined, 59 | }, 60 | }, 61 | } 62 | `; 63 | -------------------------------------------------------------------------------- /tests/cases/__tests__/__snapshots__/variable-declaration3.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`variable-declaration3 1`] = ` 4 | Object { 5 | "EntryFiles": Array [ 6 | "SourceFile-0", 7 | ], 8 | "Registry": Object { 9 | "SourceFile-0": Object { 10 | "ApiKind": "source-file", 11 | "Location": Object { 12 | "Character": 0, 13 | "FileName": "./main.ts", 14 | "IsExternalPackage": false, 15 | "Line": 0, 16 | }, 17 | "Members": Array [ 18 | Object { 19 | "Alias": "z", 20 | "Ids": Array [ 21 | "VariableDeclaration-0", 22 | ], 23 | }, 24 | ], 25 | "Metadata": Object { 26 | "DocumentationComment": "", 27 | "JSDocTags": Array [], 28 | }, 29 | "Name": "main.ts", 30 | "ParentId": undefined, 31 | "_ts": undefined, 32 | }, 33 | "VariableDeclaration-0": Object { 34 | "ApiKind": "variable", 35 | "Location": Object { 36 | "Character": 13, 37 | "FileName": "./main.ts", 38 | "IsExternalPackage": false, 39 | "Line": 2, 40 | }, 41 | "Metadata": Object { 42 | "DocumentationComment": "", 43 | "JSDocTags": Array [], 44 | }, 45 | "Name": "z", 46 | "ParentId": undefined, 47 | "Type": Object { 48 | "ApiTypeKind": "type-query", 49 | "Keyword": "typeof", 50 | "Location": Object { 51 | "Character": 16, 52 | "FileName": "./main.ts", 53 | "IsExternalPackage": false, 54 | "Line": 2, 55 | }, 56 | "ReferenceId": undefined, 57 | "Text": "string", 58 | }, 59 | "VariableDeclarationType": "const", 60 | "_ts": undefined, 61 | }, 62 | }, 63 | } 64 | `; 65 | -------------------------------------------------------------------------------- /tests/cases/class-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | // Simple class. 2 | 3 | /** 4 | * Class Foo comment line. 5 | * @summary Summary of comment line. 6 | */ 7 | export class FooClass { 8 | /** 9 | * Sets foo. 10 | * @param foo foo 11 | */ 12 | protected SetFoo?(foo?: string): void; 13 | 14 | /** 15 | * GetFoo overload comment. 16 | * @param text GetFoo property comment. 17 | */ 18 | public GetFoo(text: string): string; 19 | /** 20 | * GetFoo overload comment. 21 | * @param open GetFoo property comment. 22 | */ 23 | public GetFoo(open: boolean): string; 24 | /** 25 | * GetFoo without A parameter comment line. 26 | */ 27 | public GetFoo(arg: string | boolean): string { 28 | return ""; 29 | } 30 | 31 | public async AsyncGetFoo?(): Promise; 32 | 33 | /** 34 | * Property Id comment line. 35 | * @readonly Id is Immutable. 36 | */ 37 | public readonly IdProperty: string; 38 | public static BarProperty: string; 39 | } 40 | -------------------------------------------------------------------------------- /tests/cases/class-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration10/main.ts: -------------------------------------------------------------------------------- 1 | // Simple class with overload constructor 2 | 3 | export class FooClass { 4 | /** 5 | * Creating foo with text. 6 | * @param text Text for the foo class. 7 | */ 8 | constructor(text: string) 9 | /** 10 | * Creating foo with boolean. 11 | * @param should Boolean for foo class. 12 | */ 13 | constructor(should: boolean) 14 | // tslint:disable-next-line:no-empty 15 | constructor(arg: string | boolean) { } 16 | } 17 | -------------------------------------------------------------------------------- /tests/cases/class-declaration10/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration11/main.ts: -------------------------------------------------------------------------------- 1 | export class Foo { 2 | public getFoo(): this { 3 | return this; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/cases/class-declaration11/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration12/main.ts: -------------------------------------------------------------------------------- 1 | // Simple class. 2 | 3 | /** 4 | * Class Foo comment line. 5 | * @summary Summary of comment line. 6 | * @template TProps component props 7 | * @template TState component state 8 | */ 9 | export class FooComponent { 10 | } 11 | -------------------------------------------------------------------------------- /tests/cases/class-declaration12/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | // Abstract class. 2 | 3 | export abstract class Foo { 4 | protected abstract SetFoo(foo: string): void; 5 | 6 | private property: string = ""; 7 | 8 | public GetFoo(): string { 9 | return ""; 10 | } 11 | 12 | public abstract readonly Id: string; 13 | public static Bar: string; 14 | } 15 | -------------------------------------------------------------------------------- /tests/cases/class-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | // Implemented interface in class. 2 | 3 | export interface Foo { 4 | Bar: string; 5 | } 6 | 7 | export class FooClass implements Foo { 8 | public Bar: string; 9 | } 10 | -------------------------------------------------------------------------------- /tests/cases/class-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration4/main.ts: -------------------------------------------------------------------------------- 1 | // Implemented 2 interfaces in class. 2 | 3 | export interface Foo { 4 | Bar: string; 5 | } 6 | 7 | export interface Foo2 { 8 | Bar2: string; 9 | } 10 | 11 | export class FooClass implements Foo, Foo2 { 12 | public Bar: string; 13 | public Bar2: string; 14 | } 15 | -------------------------------------------------------------------------------- /tests/cases/class-declaration4/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration5/main.ts: -------------------------------------------------------------------------------- 1 | // Extending another class with generic. 2 | 3 | export abstract class FooBase { 4 | public abstract GetValue(): TValue; 5 | } 6 | 7 | export class Foo extends FooBase { 8 | public GetValue(): number { 9 | return 0; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/cases/class-declaration5/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration6/main.ts: -------------------------------------------------------------------------------- 1 | // Extends another class with generic and implements interface. 2 | 3 | export abstract class FooBase { 4 | public abstract GetValue(): TValue; 5 | } 6 | 7 | export interface Bar { 8 | BarName: string; 9 | } 10 | 11 | export class Foo extends FooBase implements Bar { 12 | public GetValue(): number { 13 | return 0; 14 | } 15 | 16 | public BarName: string; 17 | } 18 | -------------------------------------------------------------------------------- /tests/cases/class-declaration6/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration7/main.ts: -------------------------------------------------------------------------------- 1 | // Class with TypeParameters 2 | 3 | export class FooClass {} 4 | -------------------------------------------------------------------------------- /tests/cases/class-declaration7/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration8/main.ts: -------------------------------------------------------------------------------- 1 | export class Control { 2 | private state: any; 3 | } 4 | 5 | export interface SelectableControl extends Control { 6 | select(): void; 7 | } 8 | 9 | export class Button extends Control implements SelectableControl { 10 | select() { } 11 | } 12 | -------------------------------------------------------------------------------- /tests/cases/class-declaration8/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/class-declaration9/main.ts: -------------------------------------------------------------------------------- 1 | // Class implements another class. 2 | 3 | export class Point { 4 | x: number; 5 | y: number; 6 | } 7 | 8 | export class Point3d implements Point { 9 | x: number; 10 | y: number; 11 | z: number; 12 | } 13 | 14 | let point3d: Point3d = { x: 1, y: 2, z: 3 }; 15 | -------------------------------------------------------------------------------- /tests/cases/class-declaration9/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/construct-signature1/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | new(arg: string): Foo; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/construct-signature1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/construct-signature2/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | new (): T; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/construct-signature2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/enum-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | // Simple enum without specified value. 2 | 3 | export enum LogLevel { 4 | None, 5 | Critical, 6 | Error, 7 | Warning, 8 | Information, 9 | Debug, 10 | Trace 11 | } 12 | -------------------------------------------------------------------------------- /tests/cases/enum-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/enum-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | // Enum with specified value. 2 | 3 | /** 4 | * Defines logging severity levels. 5 | */ 6 | export enum LogLevel { 7 | /** 8 | * Not used for writing log messages. Specifies that a logging category should not write any messages. 9 | */ 10 | None = 0, 11 | 12 | /** 13 | * Logs that describe an unrecoverable application or system crash, 14 | * or a catastrophic failure that requires immediate attention. 15 | */ 16 | Critical = 1 << 0, 17 | 18 | /** 19 | * Logs that highlight when the current flow of execution is stopped due to a failure. 20 | * These should indicate a failure in the current activity, not an application-wide failure. 21 | */ 22 | Error = 1 << 1, 23 | 24 | /** 25 | * Logs that highlight an abnormal or unexpected event in the application flow, 26 | * but do not otherwise cause the application execution to stop. 27 | */ 28 | Warning = 1 << 2, 29 | 30 | /** 31 | * Logs that track the general flow of the application. These logs should have long-term value. 32 | */ 33 | Information = 1 << 3, 34 | 35 | /** 36 | * Logs that are used for interactive investigation during development. 37 | * These logs should primarily contain information useful for debugging and have no long-term value. 38 | */ 39 | Debug = 1 << 4, 40 | 41 | /** 42 | * Logs that contain the most detailed messages. These messages may contain sensitive application data. 43 | * These messages are disabled by default and should never be enabled in a production environment. 44 | */ 45 | Trace = 1 << 5 46 | } 47 | -------------------------------------------------------------------------------- /tests/cases/enum-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/enum-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | // Enum with string value. 2 | 3 | /** 4 | * Defines logging severity levels. 5 | */ 6 | export enum LogLevel { 7 | /** 8 | * Not used for writing log messages. Specifies that a logging category should not write any messages. 9 | */ 10 | None = "none", 11 | 12 | /** 13 | * Logs that describe an unrecoverable application or system crash, 14 | * or a catastrophic failure that requires immediate attention. 15 | */ 16 | Critical = "critical", 17 | 18 | /** 19 | * Logs that highlight when the current flow of execution is stopped due to a failure. 20 | * These should indicate a failure in the current activity, not an application-wide failure. 21 | */ 22 | Error = "error", 23 | 24 | /** 25 | * Logs that highlight an abnormal or unexpected event in the application flow, 26 | * but do not otherwise cause the application execution to stop. 27 | */ 28 | Warning = "warning", 29 | 30 | /** 31 | * Logs that track the general flow of the application. These logs should have long-term value. 32 | */ 33 | Information = "information", 34 | 35 | /** 36 | * Logs that are used for interactive investigation during development. 37 | * These logs should primarily contain information useful for debugging and have no long-term value. 38 | */ 39 | Debug = "debug", 40 | 41 | /** 42 | * Logs that contain the most detailed messages. These messages may contain sensitive application data. 43 | * These messages are disabled by default and should never be enabled in a production environment. 44 | */ 45 | Trace = "trace" 46 | } 47 | -------------------------------------------------------------------------------- /tests/cases/enum-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/enum-declaration4/main.ts: -------------------------------------------------------------------------------- 1 | // Simple const enum without specified value. 2 | 3 | export const enum LogLevel { 4 | None, 5 | Critical, 6 | Error, 7 | Warning, 8 | Information, 9 | Debug, 10 | Trace 11 | } 12 | -------------------------------------------------------------------------------- /tests/cases/enum-declaration4/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/export-declaration1/foo.ts: -------------------------------------------------------------------------------- 1 | export class Foo { } 2 | -------------------------------------------------------------------------------- /tests/cases/export-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | export * from "./foo"; 2 | -------------------------------------------------------------------------------- /tests/cases/export-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/export-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | export * from "./NotExistent------aaa"; 3 | -------------------------------------------------------------------------------- /tests/cases/export-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/export-specifier1/foo.ts: -------------------------------------------------------------------------------- 1 | export class Foo { } 2 | -------------------------------------------------------------------------------- /tests/cases/export-specifier1/main.ts: -------------------------------------------------------------------------------- 1 | export { Foo } from "./foo"; 2 | -------------------------------------------------------------------------------- /tests/cases/export-specifier1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/export-specifier2/foo.ts: -------------------------------------------------------------------------------- 1 | export interface Boo { 2 | Name: string; 3 | } 4 | 5 | export class Foo implements Boo { 6 | public Name: string = "World"; 7 | } 8 | -------------------------------------------------------------------------------- /tests/cases/export-specifier2/main.ts: -------------------------------------------------------------------------------- 1 | export { Foo, Boo } from "./foo"; 2 | -------------------------------------------------------------------------------- /tests/cases/export-specifier2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/export-specifier3/foo.ts: -------------------------------------------------------------------------------- 1 | export class Foo { } 2 | -------------------------------------------------------------------------------- /tests/cases/export-specifier3/main.ts: -------------------------------------------------------------------------------- 1 | export { Foo as Bar } from "./foo"; 2 | export { Foo } from "./foo"; 3 | -------------------------------------------------------------------------------- /tests/cases/export-specifier3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/export-specifier4/foo.ts: -------------------------------------------------------------------------------- 1 | export class Foo { } 2 | -------------------------------------------------------------------------------- /tests/cases/export-specifier4/main.ts: -------------------------------------------------------------------------------- 1 | export { Foo } from "./foo"; 2 | // @ts-ignore 3 | export { NotValid } from "./aaaa"; 4 | -------------------------------------------------------------------------------- /tests/cases/export-specifier4/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/extractor-empty-file/main.ts: -------------------------------------------------------------------------------- 1 | // Empty file. 2 | -------------------------------------------------------------------------------- /tests/cases/extractor-empty-file/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/function-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | export function Foo(): string { 2 | return "bar"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/function-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/function-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | export function Foo(value: TValue): void { } 2 | -------------------------------------------------------------------------------- /tests/cases/function-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/function-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | export async function AsyncFoo(): Promise { 2 | // 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/function-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/function-declaration4/main.ts: -------------------------------------------------------------------------------- 1 | // Foo with missing return type. 2 | 3 | export function Foo(arg: string[]) { 4 | return arg; 5 | } 6 | -------------------------------------------------------------------------------- /tests/cases/function-declaration4/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/function-declaration5/main.ts: -------------------------------------------------------------------------------- 1 | export function IsString(arg: string | number): arg is string { 2 | return typeof arg === "string"; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/function-declaration5/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/function-declaration6/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | 3 | } 4 | 5 | export function Bar(arg: Foo) { 6 | return arg; 7 | } 8 | -------------------------------------------------------------------------------- /tests/cases/function-declaration6/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/function-declaration7/main.ts: -------------------------------------------------------------------------------- 1 | export function Foo(arg: string | boolean) { 2 | return arg; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/function-declaration7/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/function-declaration8/main.ts: -------------------------------------------------------------------------------- 1 | export function Foo(arg: [string, number]) { 2 | return arg; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/function-declaration8/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/get-accessor1/main.ts: -------------------------------------------------------------------------------- 1 | export class Foo { 2 | public get Foo(): string { 3 | return ""; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/cases/get-accessor1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/get-accessor3/main.ts: -------------------------------------------------------------------------------- 1 | export abstract class Foo { 2 | public abstract get Foo(): string; 3 | 4 | public static get StaticFoo(): string { 5 | return ""; 6 | } 7 | 8 | private get foo(): string { 9 | return ""; 10 | } 11 | 12 | protected get ProtectedFoo(): string { 13 | return ""; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/cases/get-accessor3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/import-declaration1/foo.ts: -------------------------------------------------------------------------------- 1 | export class Foo { } 2 | -------------------------------------------------------------------------------- /tests/cases/import-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | import * as Something from "./foo"; 2 | 3 | export { Something }; 4 | -------------------------------------------------------------------------------- /tests/cases/import-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/import-specifier1/foo.ts: -------------------------------------------------------------------------------- 1 | export class Foo { } 2 | -------------------------------------------------------------------------------- /tests/cases/import-specifier1/main.ts: -------------------------------------------------------------------------------- 1 | import { Foo } from "./foo"; 2 | 3 | export { Foo }; 4 | -------------------------------------------------------------------------------- /tests/cases/import-specifier1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/import-specifier2/main.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | import { DoesNotExist } from "./ClassDeclaration1"; 3 | 4 | export { DoesNotExist }; 5 | -------------------------------------------------------------------------------- /tests/cases/import-specifier2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/index-signature1/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | [key: string]: number; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/index-signature1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/index-signature2/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | readonly [key: string]: number; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/index-signature2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/index-signature3/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | // @ts-ignore 3 | [key: string, key2: string]: number; 4 | 5 | // @ts-ignore 6 | [a: number]; 7 | } 8 | -------------------------------------------------------------------------------- /tests/cases/index-signature3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/interface-class-merging/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | method(a: number): string; 3 | optionalMethod?(a: number): string; 4 | property: string; 5 | optionalProperty?: string; 6 | } 7 | 8 | export class Foo { 9 | public additionalProperty: string; 10 | 11 | public additionalMethod(a: number): string { 12 | return this.method(0); 13 | } 14 | } 15 | 16 | export class Bar extends Foo { 17 | public method(a: number): string { 18 | return this.optionalProperty; 19 | } 20 | } 21 | 22 | export let bar = new Bar(); 23 | export let foo = new Foo(); 24 | export let iFoo: Foo; 25 | -------------------------------------------------------------------------------- /tests/cases/interface-class-merging/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { } 2 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | Bar: string; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | export interface Generic { 2 | x: T; 3 | } 4 | 5 | export const y: Generic = { x: 3 }; 6 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration4/main.ts: -------------------------------------------------------------------------------- 1 | export interface a0 { 2 | (): string; 3 | (a, b, c?: string): number; 4 | 5 | new(): string; 6 | new(s: string); 7 | 8 | [n: number]: () => string; 9 | [s: string]: any; 10 | 11 | p1; 12 | p3?; 13 | p2: string; 14 | p4?: number; 15 | p5(s: number): string; 16 | 17 | f1(); 18 | f2?(); 19 | f3(a: string): number; 20 | f4?(s: number): string; 21 | } 22 | 23 | export interface a1 { 24 | [n: number]: number; 25 | } 26 | 27 | export interface a2 { 28 | [s: string]: number; 29 | } 30 | 31 | export interface a { 32 | } 33 | 34 | export interface b extends a { 35 | } 36 | 37 | export interface c extends a, b { 38 | } 39 | 40 | export interface d extends a { 41 | } 42 | 43 | export class c1 implements a { 44 | } 45 | 46 | export var instance2 = new c1(); 47 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration4/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration5/main.ts: -------------------------------------------------------------------------------- 1 | export interface GenericIdentityFn { 2 | (value: TValue): TValue; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration5/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration6/main.ts: -------------------------------------------------------------------------------- 1 | // Interface with TypeParameters and Method with TypeParameters with the same generic type name. 2 | 3 | export interface Foo { 4 | Bar(args: string): void; 5 | } 6 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration6/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration7/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | readonly Bar: string; 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/interface-declaration7/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/interface-subtyping/main.ts: -------------------------------------------------------------------------------- 1 | export interface Face { 2 | foo(): void; 3 | } 4 | 5 | export class Camera implements Face { 6 | constructor(public str: string) { } 7 | 8 | public foo(): string { return "s"; } 9 | } 10 | -------------------------------------------------------------------------------- /tests/cases/interface-subtyping/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/mapped-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | export type mapped = {[K in "a-b-c"]: number }; 2 | -------------------------------------------------------------------------------- /tests/cases/mapped-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/mapped-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | Name: string; 3 | Age: number; 4 | } 5 | 6 | export type mapped = {[K in keyof Foo]: number }; 7 | -------------------------------------------------------------------------------- /tests/cases/mapped-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/mapped-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | Name: string; 3 | Age: number; 4 | } 5 | 6 | export type mapped = { 7 | readonly [K in keyof Foo]: number 8 | }; 9 | -------------------------------------------------------------------------------- /tests/cases/mapped-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/mapped-declaration4/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | Name: string; 3 | Age: number; 4 | } 5 | 6 | export type mapped = { 7 | [K in keyof Foo]?: number 8 | }; 9 | -------------------------------------------------------------------------------- /tests/cases/mapped-declaration4/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/multiple-declaration/main.ts: -------------------------------------------------------------------------------- 1 | export namespace M { 2 | class C { } 3 | interface C { } 4 | interface D { } 5 | class D { } 6 | } 7 | 8 | export interface Foo { 9 | a: string; 10 | } 11 | 12 | export class Foo { 13 | public b: number; 14 | } 15 | 16 | export class Bar { 17 | public b: number; 18 | } 19 | 20 | export interface Bar { 21 | a: string; 22 | } 23 | -------------------------------------------------------------------------------- /tests/cases/multiple-declaration/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/namespace-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | export namespace Foo { } 2 | -------------------------------------------------------------------------------- /tests/cases/namespace-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/namespace-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | export namespace Foo { 2 | export namespace Bar { } 3 | } 4 | -------------------------------------------------------------------------------- /tests/cases/namespace-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/namespace-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | export namespace Foo { 2 | export namespace Bar { 3 | export const Hello = "world!"; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/cases/namespace-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/object-literal1/main.ts: -------------------------------------------------------------------------------- 1 | export const ObjectLiteralConst = { Property: "value" }; 2 | -------------------------------------------------------------------------------- /tests/cases/object-literal1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/parameter-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | // IsOptional 2 | 3 | export function FooFunction(bar?: boolean): void { } 4 | -------------------------------------------------------------------------------- /tests/cases/parameter-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/parameter-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | // IsSpread 2 | 3 | export function FooFunction(...bar: string[]): void { } 4 | -------------------------------------------------------------------------------- /tests/cases/parameter-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/parameter-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | // Initializer 2 | 3 | export function FooFunction(bar: string = "Hello World!"): void { } 4 | -------------------------------------------------------------------------------- /tests/cases/parameter-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/set-accessor1/main.ts: -------------------------------------------------------------------------------- 1 | export class Foo { 2 | public set Foo(arg: string) { 3 | console.info(arg); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/cases/set-accessor1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/set-accessor2/main.ts: -------------------------------------------------------------------------------- 1 | export class Foo { 2 | // @ts-ignore 3 | public set Foo(arg: string, arg2: string) { 4 | console.info(arg); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/cases/set-accessor2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/set-accessor3/main.ts: -------------------------------------------------------------------------------- 1 | export abstract class Foo { 2 | public abstract set Foo(arg: string); 3 | public static set StaticFoo(arg: string) { } 4 | private set foo(arg: string) { } 5 | protected set ProtectedFoo(arg: string) { } 6 | } 7 | -------------------------------------------------------------------------------- /tests/cases/set-accessor3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/symbol1/main.ts: -------------------------------------------------------------------------------- 1 | export const foo = Symbol("Bar"); 2 | -------------------------------------------------------------------------------- /tests/cases/symbol1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | // Simple type declarations 2 | 3 | export type MyType = { 4 | BarName: string; 5 | }; 6 | 7 | export type AnotherType = MyType; 8 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | export type OneCommonField1 = { 2 | BarName: string; 3 | FooName: string; 4 | }; 5 | 6 | export type OneCommonField2 = { 7 | BarName: string; 8 | BazName: string; 9 | }; 10 | 11 | export type OneCommonFieldTypeIntersection = OneCommonField1 | OneCommonField2; 12 | 13 | // // tslint:disable:no-consecutive-blank-lines 14 | // // Simple type declarations with type parameters 15 | 16 | // export type MyType = { 17 | // BarName: string; 18 | // FooName: TType; 19 | // }; 20 | 21 | // export type AnotherType = MyType; 22 | 23 | 24 | // export type NoCommonFields1 = { 25 | // FooName: string; 26 | // }; 27 | 28 | // export type NoCommonFields2 = { 29 | // BarName: number; 30 | // }; 31 | 32 | // export type NoCommonFieldsType = NoCommonFields1 | NoCommonFields2; 33 | 34 | 35 | // // Two types have a one common field 36 | // export type OneCommonField1 = { 37 | // BarName: string; 38 | // FooName: string; 39 | // }; 40 | 41 | // export type OneCommonField2 = { 42 | // BarName: string; 43 | // BazName: string; 44 | // }; 45 | 46 | // export type OneCommonFieldTypeIntersection = OneCommonField1 | OneCommonField2; 47 | 48 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | // tslint:disable:no-consecutive-blank-lines 2 | // Simple type declarations with type parameters 3 | 4 | export type NoCommonFields1 = { 5 | BarName: string; 6 | FooName: TType; 7 | }; 8 | 9 | export type NoCommonFields2 = { 10 | BazName: TType; 11 | }; 12 | 13 | export type AnotherType = NoCommonFields1 | NoCommonFields2; 14 | 15 | 16 | 17 | // Two types have a one common field 18 | export type OneCommonField1 = { 19 | BarName: TType; 20 | FooName: string; 21 | }; 22 | 23 | export type OneCommonField2 = { 24 | BarName: TType; 25 | BazName: string; 26 | }; 27 | 28 | export type OneCommonFieldTypeIntersection = OneCommonField1 | OneCommonField2; 29 | 30 | export type OneCommonFieldTypeIntersectionWithDifferentTypes = OneCommonField1 & OneCommonField2; 31 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration4/main.ts: -------------------------------------------------------------------------------- 1 | export type User = { 2 | Name: string; 3 | }; 4 | 5 | export type ReadonlyUser = Readonly; 6 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration4/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration5/main.ts: -------------------------------------------------------------------------------- 1 | export type FooTuple = [string, number]; 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration5/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration6/main.ts: -------------------------------------------------------------------------------- 1 | export interface Foo { 2 | Name: string; 3 | LastName: string; 4 | } 5 | 6 | export type Bar = { 7 | [TKey in keyof Foo]: Foo[TKey] 8 | }; 9 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration6/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration7/main.ts: -------------------------------------------------------------------------------- 1 | export type Foo = (string | number)[]; 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration7/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration8/main.ts: -------------------------------------------------------------------------------- 1 | export type Foo = new () => { 2 | Name: string; 3 | Age: number; 4 | }; 5 | -------------------------------------------------------------------------------- /tests/cases/type-alias-declaration8/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-parameter-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | export function Foo(a: TValue): void {} 2 | -------------------------------------------------------------------------------- /tests/cases/type-parameter-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-parameter-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | export function Foo(a: TValue): void { } 2 | -------------------------------------------------------------------------------- /tests/cases/type-parameter-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/type-parameter-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | export function Foo(a: TValue): void { } 2 | -------------------------------------------------------------------------------- /tests/cases/type-parameter-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/variable-declaration1/main.ts: -------------------------------------------------------------------------------- 1 | export const FOO: undefined = undefined; 2 | -------------------------------------------------------------------------------- /tests/cases/variable-declaration1/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/variable-declaration2/main.ts: -------------------------------------------------------------------------------- 1 | export const Foo: string = ""; 2 | 3 | export const ArrowFunctionConst = (a: string) => `return-${a}`; 4 | 5 | export var functionVar = function (): string { 6 | return "functionVar"; 7 | }; 8 | -------------------------------------------------------------------------------- /tests/cases/variable-declaration2/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/variable-declaration3/main.ts: -------------------------------------------------------------------------------- 1 | const a: string = "a"; 2 | 3 | export const z: typeof a = "z"; 4 | -------------------------------------------------------------------------------- /tests/cases/variable-declaration3/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/cases/variable-declaration4/main.ts: -------------------------------------------------------------------------------- 1 | export interface A { 2 | b: string; 3 | } 4 | 5 | export const a: A = { 6 | b: "str" 7 | }; 8 | 9 | export const z: typeof a = { 10 | b: "bstr" 11 | }; 12 | -------------------------------------------------------------------------------- /tests/cases/variable-declaration4/test-config.json: -------------------------------------------------------------------------------- 1 | {"EntryFiles": ["./main.ts"]} 2 | -------------------------------------------------------------------------------- /tests/default-template.ts: -------------------------------------------------------------------------------- 1 | import { Extractor, GetCompilerOptions } from "@src/index"; 2 | 3 | test("{{caseName}}", async done => { 4 | const projectDirectory = "{{projectDirectory}}"; 5 | const { EntryFiles, ...rest }: any = undefined; //{{{json testConfig}}}; 6 | const compilerOptions = await GetCompilerOptions("./tsconfig.json"); 7 | 8 | try { 9 | const extractor = new Extractor({ 10 | ProjectDirectory: projectDirectory, 11 | CompilerOptions: compilerOptions, 12 | ...rest 13 | }); 14 | expect(extractor.Extract(EntryFiles)).toMatchSnapshot(); 15 | done(); 16 | } catch (error) { 17 | done.fail(error); 18 | } 19 | }); 20 | -------------------------------------------------------------------------------- /tests/default.test.tpl: -------------------------------------------------------------------------------- 1 | import { Extractor, GetCompilerOptions } from "@src/index"; 2 | 3 | test("{{caseName}}", async done => { 4 | const projectDirectory = "{{projectDirectory}}"; 5 | const { EntryFiles, ...rest } = {{{json testConfig}}}; 6 | const compilerOptions = await GetCompilerOptions("./tests/tsconfig.test.json"); 7 | 8 | try { 9 | const extractor = new Extractor({ 10 | ProjectDirectory: projectDirectory, 11 | CompilerOptions: compilerOptions, 12 | ...rest 13 | }); 14 | expect(extractor.Extract(EntryFiles)).toMatchSnapshot(); 15 | done(); 16 | } catch (error) { 17 | done.fail(error); 18 | } 19 | }); 20 | -------------------------------------------------------------------------------- /tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "removeComments": false, 6 | "sourceMap": false, 7 | "skipDefaultLibCheck": true, 8 | "pretty": true, 9 | "noEmit": true, 10 | "experimentalDecorators": false, 11 | "baseUrl": "./", 12 | "typeRoots": [ 13 | "../" 14 | ], 15 | "types": [ 16 | "jest", 17 | "typescript", 18 | "node" 19 | ], 20 | "lib": [ 21 | "es6", 22 | "dom" 23 | ], 24 | "paths": { 25 | "@src/*": [ 26 | "../src/*" 27 | ] 28 | }, 29 | "rootDirs": [ 30 | "./", 31 | "../src" 32 | ] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "removeComments": false, 6 | "sourceMap": false, 7 | "skipDefaultLibCheck": true, 8 | "pretty": true, 9 | "noEmit": true, 10 | "baseUrl": "." 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tools/travis-release/release.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs-extra"; 2 | import * as path from "path"; 3 | import { LoggerBuilder, LoggerConfigurationBuilder, LogLevel } from "simplr-logger"; 4 | 5 | const LoggerConfiguration = new LoggerConfigurationBuilder() 6 | .SetDefaultLogLevel(LogLevel.Trace) 7 | .Build(); 8 | 9 | export const Logger = new LoggerBuilder(LoggerConfiguration); 10 | 11 | 12 | interface PackageJson { 13 | version: string; 14 | publishConfig?: { 15 | tag?: string; 16 | registry?: string; 17 | access?: string; 18 | }; 19 | } 20 | 21 | async function Main(): Promise { 22 | const travisTag = process.env["TRAVIS_TAG"]; 23 | Logger.Info("---- Travis-Release ----"); 24 | Logger.Info("TravisTag", travisTag); 25 | 26 | if (travisTag == null) { 27 | return undefined; 28 | } 29 | 30 | const packageJsonPath = path.join(process.cwd(), "./package.json"); 31 | const packageJsonContents = await fs.readJson(packageJsonPath) as PackageJson; 32 | 33 | const prereleaseTags = ["-alpha", "-beta", "-rc"]; 34 | 35 | let isPrerelease: boolean = false; 36 | for (const tag of prereleaseTags) { 37 | if (packageJsonContents.version.indexOf(tag)) { 38 | isPrerelease = true; 39 | break; 40 | } 41 | } 42 | 43 | if (!isPrerelease) { 44 | return undefined; 45 | } 46 | 47 | // Pre-release 48 | if (packageJsonContents.publishConfig == null) { 49 | packageJsonContents.publishConfig = {}; 50 | } 51 | 52 | // Add tag next 53 | packageJsonContents.publishConfig.tag = "next"; 54 | await fs.writeJson(packageJsonPath, packageJsonContents, { spaces: 4 }); 55 | } 56 | 57 | Main(); 58 | -------------------------------------------------------------------------------- /tools/travis-release/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "removeComments": false, 6 | "noUnusedLocals": true, 7 | "inlineSourceMap": true, 8 | "inlineSources": true, 9 | "skipDefaultLibCheck": true, 10 | "pretty": true, 11 | "strict": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "lib": [ 14 | "es6", 15 | "es2017.object" 16 | ], 17 | "types": [ 18 | "node" 19 | ], 20 | "typeRoots": [ 21 | "./node_modules/@types" 22 | ] 23 | }, 24 | "exclude": [ 25 | "node_modules", 26 | "dist", 27 | "@types", 28 | "tests", 29 | "examples" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "removeComments": false, 6 | "outDir": "dist", 7 | "rootDir": "src", 8 | "noUnusedLocals": true, 9 | "inlineSourceMap": true, 10 | "inlineSources": true, 11 | "skipDefaultLibCheck": true, 12 | "declaration": true, 13 | "pretty": true, 14 | "strict": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "strictPropertyInitialization": false, 17 | "lib": [ 18 | "es6", 19 | "es2017.object" 20 | ], 21 | "types": [ 22 | "node" 23 | ], 24 | "typeRoots": [ 25 | "./node_modules/@types" 26 | ] 27 | }, 28 | "exclude": [ 29 | "node_modules", 30 | "dist", 31 | "@types", 32 | "tests", 33 | "examples", 34 | "tools" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "simplr-tslint" 3 | } 4 | --------------------------------------------------------------------------------