From 23514e88f43aa22e14d1edb6f09caf4d35f292c7 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 30 Oct 2023 20:10:36 -0400 Subject: [PATCH] chore: rewrite json and contains tests to use spec files (#367) --- Cargo.toml | 1 + src/lib.rs | 1 + src/tests.rs | 5658 ----------------- tests/helpers/mod.rs | 187 + tests/helpers/test_builder.rs | 81 + tests/integration_test.rs | 79 + tests/specs/AbstractClass.txt | 34 + tests/specs/AbstractClassAbstractMethod.txt | 59 + tests/specs/ClassAsyncMethod.txt | 66 + tests/specs/ClassConstructor.txt | 64 + tests/specs/ClassDeclaration.txt | 34 + tests/specs/ClassDecorators.txt | 168 + tests/specs/ClassDetails.txt | 85 + tests/specs/ClassDetailsAllWithPrivate.txt | 106 + ...assDetailsOnlyNonPrivateWithoutPrivate.txt | 104 + tests/specs/ClassExtends.txt | 34 + tests/specs/ClassExtendsImplements.txt | 51 + tests/specs/ClassGenericExtendsImplements.txt | 93 + tests/specs/ClassGetterAndSetter.txt | 97 + tests/specs/ClassImplements.txt | 43 + tests/specs/ClassImplements2.txt | 51 + tests/specs/ClassIndexSignature.txt | 63 + tests/specs/ClassMethod.txt | 66 + tests/specs/ClassMethodOverloads.txt | 169 + tests/specs/ClassOverridePropMethod.txt | 86 + tests/specs/ClassPrivateProperty.txt | 57 + tests/specs/ClassProperty.txt | 79 + tests/specs/ClassReadonlyIndexSignature.txt | 63 + tests/specs/ClassReadonlyProperty.txt | 56 + tests/specs/ClassStaticProperty.txt | 56 + tests/specs/ConstDeclaration.txt | 33 + tests/specs/CtorOverloads.txt | 118 + tests/specs/DeclareNamespace.txt | 146 + tests/specs/DeclareNamespaceIgnore.txt | 67 + tests/specs/DecoratorsJsdoc.txt | 73 + tests/specs/DefaultExportsDeclaredEarlier.txt | 35 + tests/specs/DocPrinterUnsupportedTag.txt | 50 + tests/specs/EnumDeclaration.txt | 26 + tests/specs/EnumMember.txt | 53 + tests/specs/ExportClass.txt | 480 ++ tests/specs/ExportClassCtorProperties.txt | 85 + tests/specs/ExportClassDecorators.txt | 213 + tests/specs/ExportClassIgnore.txt | 220 + tests/specs/ExportClassObjectExtends.txt | 85 + tests/specs/ExportConstBasic.txt | 332 + tests/specs/ExportConstDestructured.txt | 119 + .../ExportDeclarationMergedNamespace.txt | 78 + tests/specs/ExportDefaultClass.txt | 92 + tests/specs/ExportDefaultExpr.txt | 33 + tests/specs/ExportDefaultFn.txt | 47 + tests/specs/ExportDefaultInterface.txt | 97 + tests/specs/ExportEnum.txt | 80 + tests/specs/ExportFn.txt | 157 + tests/specs/ExportFn2.txt | 187 + tests/specs/ExportInterface.txt | 216 + tests/specs/ExportInterface2.txt | 59 + tests/specs/ExportInterfaceAccessors.txt | 89 + tests/specs/ExportLet.txt | 171 + tests/specs/ExportNamespace.txt | 186 + tests/specs/ExportNamespaceEnumSameName.txt | 77 + tests/specs/ExportPrivate.txt | 32 + tests/specs/ExportTypeAlias.txt | 44 + tests/specs/ExportTypeAliasLiteral.txt | 123 + tests/specs/ExportsAllWithPrivate.txt | 194 + tests/specs/ExportsDeclaredEarlier.txt | 99 + tests/specs/FunctionArrayDeconstruction.txt | 60 + tests/specs/FunctionAsync.txt | 30 + tests/specs/FunctionAsyncGenerator.txt | 30 + tests/specs/FunctionDeclaration.txt | 30 + tests/specs/FunctionGenerator.txt | 30 + tests/specs/FunctionGeneric.txt | 61 + tests/specs/FunctionObjectDeconstruction.txt | 57 + tests/specs/FunctionOverloads.txt | 138 + .../GenericInstantiatedWithTupleType.txt | 82 + tests/specs/ImportEquals.txt | 38 + tests/specs/ImportTypes.txt | 60 + tests/specs/IndentedWithTabs.txt | 108 + tests/specs/InferObjectLiteral.txt | 259 + tests/specs/InferSimpleTsArrTypes.txt | 232 + tests/specs/InferSimpleTsTypes.txt | 436 ++ tests/specs/InferTsTypes.txt | 148 + tests/specs/InferTypes.txt | 77 + tests/specs/InterfaceConstruct.txt | 59 + tests/specs/InterfaceDeclaration.txt | 31 + tests/specs/InterfaceExtends.txt | 40 + tests/specs/InterfaceExtends2.txt | 48 + tests/specs/InterfaceGeneric.txt | 35 + tests/specs/InterfaceGenericExtends.txt | 53 + tests/specs/InterfaceIndexSignature.txt | 63 + tests/specs/InterfaceMethod.txt | 106 + .../specs/InterfaceNumberLiteralProperty.txt | 71 + tests/specs/InterfaceProperty.txt | 110 + .../specs/InterfaceReadonlyIndexSignature.txt | 63 + .../specs/InterfaceStringLiteralProperty.txt | 71 + tests/specs/Jsdoc.txt | 114 + tests/specs/JsdocTags.txt | 99 + tests/specs/MappedTypes.txt | 88 + tests/specs/ModuleDocs.txt | 70 + tests/specs/ModuleDocsIgnore.txt | 16 + tests/specs/NamespaceDeclaration.txt | 26 + tests/specs/NamespaceDetails.txt | 93 + tests/specs/NamespaceFnOverloads.txt | 152 + tests/specs/NoAmbientInModule.txt | 31 + ...plementedRenamedExportsDeclaredEarlier.txt | 34 + tests/specs/OptionalReturnType.txt | 43 + tests/specs/Overloads.txt | 140 + tests/specs/ReexportExistingExport.txt | 61 + tests/specs/StructuredJsdoc.txt | 186 + tests/specs/TsLitTypes.txt | 168 + tests/specs/TsTemplateWithArgs.txt | 55 + tests/specs/TsTypeAssertion.txt | 52 + tests/specs/TsTypePredicate1.txt | 76 + tests/specs/TsTypePredicate2.txt | 76 + tests/specs/TsTypePredicate3.txt | 76 + tests/specs/TsUserDefinedTypeGuards.txt | 315 + tests/specs/TypeAlias.txt | 30 + tests/specs/TypeAliasInferType.txt | 77 + tests/specs/TypeGenericAlias.txt | 37 + tests/specs/TypeImportType.txt | 58 + tests/specs/TypeLiteralDeclaration.txt | 35 + tests/specs/TypeLiteralIndexSignature.txt | 56 + tests/specs/TypeLiteralMappedType.txt | 85 + .../TypeLiteralReadonlyIndexSignature.txt | 56 + 123 files changed, 11360 insertions(+), 5658 deletions(-) create mode 100644 tests/helpers/mod.rs create mode 100644 tests/helpers/test_builder.rs create mode 100644 tests/integration_test.rs create mode 100644 tests/specs/AbstractClass.txt create mode 100644 tests/specs/AbstractClassAbstractMethod.txt create mode 100644 tests/specs/ClassAsyncMethod.txt create mode 100644 tests/specs/ClassConstructor.txt create mode 100644 tests/specs/ClassDeclaration.txt create mode 100644 tests/specs/ClassDecorators.txt create mode 100644 tests/specs/ClassDetails.txt create mode 100644 tests/specs/ClassDetailsAllWithPrivate.txt create mode 100644 tests/specs/ClassDetailsOnlyNonPrivateWithoutPrivate.txt create mode 100644 tests/specs/ClassExtends.txt create mode 100644 tests/specs/ClassExtendsImplements.txt create mode 100644 tests/specs/ClassGenericExtendsImplements.txt create mode 100644 tests/specs/ClassGetterAndSetter.txt create mode 100644 tests/specs/ClassImplements.txt create mode 100644 tests/specs/ClassImplements2.txt create mode 100644 tests/specs/ClassIndexSignature.txt create mode 100644 tests/specs/ClassMethod.txt create mode 100644 tests/specs/ClassMethodOverloads.txt create mode 100644 tests/specs/ClassOverridePropMethod.txt create mode 100644 tests/specs/ClassPrivateProperty.txt create mode 100644 tests/specs/ClassProperty.txt create mode 100644 tests/specs/ClassReadonlyIndexSignature.txt create mode 100644 tests/specs/ClassReadonlyProperty.txt create mode 100644 tests/specs/ClassStaticProperty.txt create mode 100644 tests/specs/ConstDeclaration.txt create mode 100644 tests/specs/CtorOverloads.txt create mode 100644 tests/specs/DeclareNamespace.txt create mode 100644 tests/specs/DeclareNamespaceIgnore.txt create mode 100644 tests/specs/DecoratorsJsdoc.txt create mode 100644 tests/specs/DefaultExportsDeclaredEarlier.txt create mode 100644 tests/specs/DocPrinterUnsupportedTag.txt create mode 100644 tests/specs/EnumDeclaration.txt create mode 100644 tests/specs/EnumMember.txt create mode 100644 tests/specs/ExportClass.txt create mode 100644 tests/specs/ExportClassCtorProperties.txt create mode 100644 tests/specs/ExportClassDecorators.txt create mode 100644 tests/specs/ExportClassIgnore.txt create mode 100644 tests/specs/ExportClassObjectExtends.txt create mode 100644 tests/specs/ExportConstBasic.txt create mode 100644 tests/specs/ExportConstDestructured.txt create mode 100644 tests/specs/ExportDeclarationMergedNamespace.txt create mode 100644 tests/specs/ExportDefaultClass.txt create mode 100644 tests/specs/ExportDefaultExpr.txt create mode 100644 tests/specs/ExportDefaultFn.txt create mode 100644 tests/specs/ExportDefaultInterface.txt create mode 100644 tests/specs/ExportEnum.txt create mode 100644 tests/specs/ExportFn.txt create mode 100644 tests/specs/ExportFn2.txt create mode 100644 tests/specs/ExportInterface.txt create mode 100644 tests/specs/ExportInterface2.txt create mode 100644 tests/specs/ExportInterfaceAccessors.txt create mode 100644 tests/specs/ExportLet.txt create mode 100644 tests/specs/ExportNamespace.txt create mode 100644 tests/specs/ExportNamespaceEnumSameName.txt create mode 100644 tests/specs/ExportPrivate.txt create mode 100644 tests/specs/ExportTypeAlias.txt create mode 100644 tests/specs/ExportTypeAliasLiteral.txt create mode 100644 tests/specs/ExportsAllWithPrivate.txt create mode 100644 tests/specs/ExportsDeclaredEarlier.txt create mode 100644 tests/specs/FunctionArrayDeconstruction.txt create mode 100644 tests/specs/FunctionAsync.txt create mode 100644 tests/specs/FunctionAsyncGenerator.txt create mode 100644 tests/specs/FunctionDeclaration.txt create mode 100644 tests/specs/FunctionGenerator.txt create mode 100644 tests/specs/FunctionGeneric.txt create mode 100644 tests/specs/FunctionObjectDeconstruction.txt create mode 100644 tests/specs/FunctionOverloads.txt create mode 100644 tests/specs/GenericInstantiatedWithTupleType.txt create mode 100644 tests/specs/ImportEquals.txt create mode 100644 tests/specs/ImportTypes.txt create mode 100644 tests/specs/IndentedWithTabs.txt create mode 100644 tests/specs/InferObjectLiteral.txt create mode 100644 tests/specs/InferSimpleTsArrTypes.txt create mode 100644 tests/specs/InferSimpleTsTypes.txt create mode 100644 tests/specs/InferTsTypes.txt create mode 100644 tests/specs/InferTypes.txt create mode 100644 tests/specs/InterfaceConstruct.txt create mode 100644 tests/specs/InterfaceDeclaration.txt create mode 100644 tests/specs/InterfaceExtends.txt create mode 100644 tests/specs/InterfaceExtends2.txt create mode 100644 tests/specs/InterfaceGeneric.txt create mode 100644 tests/specs/InterfaceGenericExtends.txt create mode 100644 tests/specs/InterfaceIndexSignature.txt create mode 100644 tests/specs/InterfaceMethod.txt create mode 100644 tests/specs/InterfaceNumberLiteralProperty.txt create mode 100644 tests/specs/InterfaceProperty.txt create mode 100644 tests/specs/InterfaceReadonlyIndexSignature.txt create mode 100644 tests/specs/InterfaceStringLiteralProperty.txt create mode 100644 tests/specs/Jsdoc.txt create mode 100644 tests/specs/JsdocTags.txt create mode 100644 tests/specs/MappedTypes.txt create mode 100644 tests/specs/ModuleDocs.txt create mode 100644 tests/specs/ModuleDocsIgnore.txt create mode 100644 tests/specs/NamespaceDeclaration.txt create mode 100644 tests/specs/NamespaceDetails.txt create mode 100644 tests/specs/NamespaceFnOverloads.txt create mode 100644 tests/specs/NoAmbientInModule.txt create mode 100644 tests/specs/NonImplementedRenamedExportsDeclaredEarlier.txt create mode 100644 tests/specs/OptionalReturnType.txt create mode 100644 tests/specs/Overloads.txt create mode 100644 tests/specs/ReexportExistingExport.txt create mode 100644 tests/specs/StructuredJsdoc.txt create mode 100644 tests/specs/TsLitTypes.txt create mode 100644 tests/specs/TsTemplateWithArgs.txt create mode 100644 tests/specs/TsTypeAssertion.txt create mode 100644 tests/specs/TsTypePredicate1.txt create mode 100644 tests/specs/TsTypePredicate2.txt create mode 100644 tests/specs/TsTypePredicate3.txt create mode 100644 tests/specs/TsUserDefinedTypeGuards.txt create mode 100644 tests/specs/TypeAlias.txt create mode 100644 tests/specs/TypeAliasInferType.txt create mode 100644 tests/specs/TypeGenericAlias.txt create mode 100644 tests/specs/TypeImportType.txt create mode 100644 tests/specs/TypeLiteralDeclaration.txt create mode 100644 tests/specs/TypeLiteralIndexSignature.txt create mode 100644 tests/specs/TypeLiteralMappedType.txt create mode 100644 tests/specs/TypeLiteralReadonlyIndexSignature.txt diff --git a/Cargo.toml b/Cargo.toml index 99a09d18..07311309 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ clap = "2.33.3" criterion = { version = "0.4.0", features = ["async_futures", "html_reports"] } tokio = { version = "1.25.0", features = ["full"] } pretty_assertions = "1.0.0" +indexmap = "2.0.2" [features] default = ["rust"] diff --git a/src/lib.rs b/src/lib.rs index 4a6a579d..ba0a2b80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,7 @@ use params::ParamDef; cfg_if! { if #[cfg(feature = "rust")] { mod printer; + pub use parser::DocDiagnostic; pub use parser::DocError; pub use parser::DocParser; pub use printer::DocPrinter; diff --git a/src/tests.rs b/src/tests.rs index 60178ebe..b3480f12 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -49,118 +49,6 @@ pub(crate) async fn setup + Copy>( (graph, analyzer, root) } -macro_rules! assert_contains { - ($string:expr, $($test:expr),+ $(,)?) => { - let string = &$string; // This might be a function call or something - if !($(string.contains($test))||+) { - panic!("{:?} does not contain any of {:?}", string, [$($test),+]); - } - } -} - -macro_rules! assert_not_contains { - ($string:expr, $($test:expr),+ $(,)?) => { - let string = &$string; // This might be a function call or something - if !($(!string.contains($test))||+) { - panic!("{:?} contained {:?}", string, [$($test),+]); - } - } -} - -macro_rules! doc_test { - ( $name:ident, $source:expr; $block:expr ) => { - doc_test!($name, $source, false; $block); - }; - - ( $name:ident, $source:expr, private; $block:expr ) => { - doc_test!($name, $source, true; $block); - }; - - ( $name:ident, $source:expr, $private:expr; $block:expr ) => { - doc_test!($name, $source, $private; $block, vec![]); - }; - - ( $name:ident, $source:expr, $private:expr; $block:expr, $diagnostics:expr ) => { - #[tokio::test] - async fn $name() { - use super::setup; - - let source_code = $source; - let private = $private; - - let (graph, analyzer, specifier) = setup("file:///test.ts", vec![ - ("file:///test.ts", None, source_code) - ]).await; - let parser = DocParser::new(&graph, private, analyzer.as_capturing_parser()).unwrap(); - let entries = parser - .parse(&specifier) - .unwrap(); - - #[allow(unused_variables)] - let doc = DocPrinter::new(&entries, false, private).to_string(); - - #[allow(clippy::redundant_closure_call)] - ($block)(entries, doc); - - let actual_diagnostics = parser - .diagnostics() - .into_iter() - .map(|d| format!("{}:{}:{} {:?}", d.location.filename, d.location.line, d.location.col, d.kind)) - .collect::>(); - let expected_diagnostics: Vec<&str> = $diagnostics; - assert_eq!(actual_diagnostics, expected_diagnostics, "Diagnostics match."); - } - }; -} - -macro_rules! contains_test { - ( $name:ident, $source:expr; - $( $contains:expr ),* $( ; $( $notcontains:expr ),* )? ) => { - contains_test!($name, $source, false; $($contains),* $(;$($notcontains),*)?); - }; - - ( $name:ident, $source:expr, private; - $( $contains:expr ),* $( ; $( $notcontains:expr ),* )? ) => { - contains_test!($name, $source, true; $($contains),* $(;$($notcontains),*)?); - }; - - ( $name:ident, $source:expr, $private:expr; - $( $contains:expr ),* $( ; $( $notcontains:expr ),* )? ) => { - doc_test!($name, $source, $private; |_entries, doc: String| { - $( - assert_contains!(doc, $contains); - )* - $( - $( - assert_not_contains!(doc, $notcontains); - )* - )? - }); - }; -} - -macro_rules! json_test { - ( $name:ident, $source:expr; $json:tt ) => { - json_test!($name, $source, false; $json); - }; - - ( $name:ident, $source:expr, private; $json:tt ) => { - json_test!($name, $source, true; $json); - }; - - ( $name:ident, $source:expr, $private:expr; $json:tt ) => { - json_test!($name, $source, $private; $json, vec![]); - }; - - ( $name:ident, $source:expr, $private:expr; $json:tt, $diagnostics:expr ) => { - doc_test!($name, $source, $private; |entries, _doc| { - let actual = serde_json::to_value(&entries).unwrap(); - let expected_json = json!($json); - pretty_assertions::assert_eq!(actual, expected_json); - }, $diagnostics); - }; -} - #[tokio::test] async fn content_type_handling() { let sources = vec![( @@ -1111,5552 +999,6 @@ async fn json_module() { assert_eq!(actual, expected_json); } -mod serialization { - use crate::*; - - json_test!(module_docs, - r#"/* a non-jsdoc comment */ - -/** - * A leading JSDoc comment - * @module - */ - -/** One associated with a class */ -export class A {} - "#; - [ - { - "kind": "moduleDoc", - "name": "", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0, - }, - "declarationKind": "export", - "jsDoc": { - "doc": "A leading JSDoc comment", - "tags": [{ - "kind": "module" - }], - } - }, { - "kind": "class", - "name": "A", - "location": { - "filename": "file:///test.ts", - "line": 9, - "col": 0, - }, - "declarationKind": "export", - "jsDoc": { - "doc": "One associated with a class", - }, - "classDef": { - "isAbstract": false, - "constructors": [], - "properties": [], - "indexSignatures": [], - "methods": [], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [] - } - } - ]); - - json_test!(module_docs_ignore, - r#"/* a non-jsdoc comment */ - -/** - * A leading JSDoc comment - * @module - * @ignore - */ - -/** One associated with a class */ -export class A {} - "#; - []); - - json_test!(declare_namespace, - r#" -/** Namespace JSdoc */ -declare namespace RootNs { - declare const a = "a"; - - /** Nested namespace JSDoc */ - declare namespace NestedNs { - declare enum Foo { - a = 1, - b = 2, - c = 3, - } - } -} - "#; - [{ - "kind": "namespace", - "name": "RootNs", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "declare", - "jsDoc": { - "doc": "Namespace JSdoc", - }, - "namespaceDef": { - "elements": [ - { - "kind": "variable", - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 18 - }, - "declarationKind": "declare", - "variableDef": { - "tsType": { - "repr": "a", - "kind": "literal", - "literal": { - "kind": "string", - "string": "a" - } - }, - "kind": "const" - } - }, - { - "kind": "namespace", - "name": "NestedNs", - "location": { - "filename": "file:///test.ts", - "line": 7, - "col": 4 - }, - "jsDoc": { - "doc": "Nested namespace JSDoc", - }, - "declarationKind": "declare", - "namespaceDef": { - "elements": [ - { - "kind": "enum", - "name": "Foo", - "location": { - "filename": "file:///test.ts", - "line": 8, - "col": 6 - }, - "declarationKind": "declare", - "enumDef": { - "members": [ - { - "name": "a", - "init": { - "repr": "1", - "kind": "literal", - "literal": { - "kind": "number", - "number": 1.0, - } - }, - "location": { - "filename": "file:///test.ts", - "line": 9, - "col": 8, - }, - }, - { - "name": "b", - "init": { - "repr": "2", - "kind": "literal", - "literal": { - "kind": "number", - "number": 2.0, - } - }, - "location": { - "filename": "file:///test.ts", - "line": 10, - "col": 8, - }, - }, - { - "name": "c", - "init": { - "repr": "3", - "kind": "literal", - "literal": { - "kind": "number", - "number": 3.0, - } - }, - "location": { - "filename": "file:///test.ts", - "line": 11, - "col": 8, - }, - } - ] - } - } - ] - } - } - ] - } - }]); - - json_test!(declare_namespace_ignore, - r#" -/** Namespace JSdoc */ -declare namespace RootNs { - declare const a = "a"; - - /** Nested namespace JSDoc - * @ignore - */ - declare namespace NestedNs { - declare enum Foo { - a = 1, - b = 2, - c = 3, - } - } -} - "#; - [{ - "kind": "namespace", - "name": "RootNs", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "declare", - "jsDoc": { - "doc": "Namespace JSdoc", - }, - "namespaceDef": { - "elements": [ - { - "kind": "variable", - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 18 - }, - "declarationKind": "declare", - "variableDef": { - "tsType": { - "repr": "a", - "kind": "literal", - "literal": { - "kind": "string", - "string": "a" - } - }, - "kind": "const" - } - } - ] - } - }]); - - json_test!(structured_jsdoc, - r#" -/** Class doc */ -export class A { - /** @private */ - p = false; - - /** - * Some leading documentation here. - * - * @param {string} name some comment - * @param {string} a some other comment that - * spans two lines - * @param {number} b a number - */ - constructor(name, a, b) {} - - /** - * @returns {Promise} - */ - a() {} -} - "#; - [{ - "kind": "class", - "name": "A", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0, - }, - "jsDoc": { - "doc": "Class doc", - }, - "declarationKind": "export", - "classDef": { - "isAbstract": false, - "constructors": [ - { - "jsDoc": { - "doc": "Some leading documentation here.\n", - "tags": [ - { - "kind": "param", - "name": "name", - "type": "string", - "doc": "some comment", - }, - { - "kind": "param", - "name": "a", - "type": "string", - "doc": "some other comment that\nspans two lines", - }, - { - "kind": "param", - "name": "b", - "type": "number", - "doc": "a number", - }, - ], - }, - "accessibility": null, - "hasBody": true, - "name": "constructor", - "params": [ - { - "kind": "identifier", - "name": "name", - "optional": false, - "tsType": null, - }, - { - "kind": "identifier", - "name": "a", - "optional": false, - "tsType": null, - }, - { - "kind": "identifier", - "name": "b", - "optional": false, - "tsType": null, - } - ], - "location": { - "filename": "file:///test.ts", - "line": 15, - "col": 2, - } - } - ], - "properties": [ - { - "jsDoc": { - "tags": [ - { - "kind": "private" - } - ] - }, - "tsType": { - "repr": "boolean", - "kind": "keyword", - "keyword": "boolean", - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "p", - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 2, - } - } - ], - "indexSignatures": [], - "methods": [ - { - "jsDoc": { - "tags": [ - { - "kind": "return", - "type": "Promise" - } - ] - }, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "a", - "kind": "method", - "functionDef": { - "params": [], - "returnType": null, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - }, - "location": { - "filename": "file:///test.ts", - "line": 20, - "col": 2, - } - } - ], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [], - } - }]); - - json_test!(export_class, - r#" -/** Class doc */ -export class Foobar extends Fizz implements Buzz, Aldrin { - private private1?: boolean; - protected protected1: number; - public public1: boolean; - public2: number; - override public3: string; - m = new Map(); - s = "foo"; - a = [1, "foo"]; - fn = (a: string): void => {}; - - /** Test */ - [prop: string]: number; - /** @ignore */ - [prop: number]: number; - - /** Constructor js doc */ - constructor(name: string, private private2: number, protected protected2: number) {} - - /** Async foo method */ - async foo(): Promise { - // - } - - /** Sync bar method */ - bar?(): void { - // - } - - override s() {} -} - "#; - [{ - "kind": "class", - "name": "Foobar", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Class doc", - }, - "classDef": { - "isAbstract": false, - "extends": "Fizz", - "implements": [ - { - "repr": "Buzz", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Buzz" - } - }, - { - "repr": "Aldrin", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Aldrin" - } - } - ], - "typeParams": [], - "superTypeParams": [], - "constructors": [ - { - "jsDoc": { - "doc": "Constructor js doc", - }, - "accessibility": null, - "hasBody": true, - "name": "constructor", - "params": [ - { - "name": "name", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - } - }, - { - "accessibility": "private", - "name": "private2", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - } - }, - { - "accessibility": "protected", - "name": "protected2", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - } - } - ], - "location": { - "filename": "file:///test.ts", - "line": 20, - "col": 4 - } - } - ], - "properties": [ - { - "tsType": { - "repr": "boolean", - "kind": "keyword", - "keyword": "boolean" - }, - "readonly": false, - "accessibility": "private", - "optional": true, - "isAbstract": false, - "isStatic": false, - "name": "private1", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 4 - } - }, - { - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }, - "readonly": false, - "accessibility": "protected", - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "protected1", - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 4 - } - }, - { - "tsType": { - "repr": "boolean", - "kind": "keyword", - "keyword": "boolean" - }, - "readonly": false, - "accessibility": "public", - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "public1", - "location": { - "filename": "file:///test.ts", - "line": 6, - "col": 4 - } - }, - { - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "public2", - "location": { - "filename": "file:///test.ts", - "line": 7, - "col": 4 - } - }, - { - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "isOverride": true, - "name": "public3", - "location": { - "filename": "file:///test.ts", - "line": 8, - "col": 4 - } - }, - { - "tsType": { - "repr": "Map", - "kind": "typeRef", - "typeRef": { - "typeParams": [ - { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - { - "repr": "string", - "kind": "keyword", - "keyword": "string" - } - ], - "typeName": "Map", - }, - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "m", - "location": { - "filename": "file:///test.ts", - "line": 9, - "col": 4, - } - }, - { - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "s", - "location": { - "filename": "file:///test.ts", - "line": 10, - "col": 4, - } - }, - { - "tsType": { - "repr": "", - "kind": "array", - "array": { - "repr": "", - "kind": "union", - "union": [ - { - "repr": "number", - "kind": "keyword", - "keyword": "number", - }, { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - ] - } - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 11, - "col": 4, - } - }, - { - "tsType": { - "repr": "", - "kind": "fnOrConstructor", - "fnOrConstructor": { - "constructor": false, - "tsType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "params": [ - { - "kind": "identifier", - "name": "a", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - } - ], - "typeParams": [] - } - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "fn", - "location": { - "filename": "file:///test.ts", - "line": 12, - "col": 4, - }, - } - ], - "indexSignatures": [{ - "location": { - "filename": "file:///test.ts", - "line": 15, - "col": 4, - }, - "jsDoc": { - "doc": "Test", - }, - "readonly": false, - "params": [{ - "kind": "identifier", - "name": "prop", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - }], - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number", - } - }], - "methods": [ - { - "jsDoc": { - "doc": "Async foo method", - }, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "foo", - "kind": "method", - "functionDef": { - "params": [], - "returnType": { - "repr": "Promise", - "kind": "typeRef", - "typeRef": { - "typeParams": [ - { - "repr": "void", - "kind": "keyword", - "keyword": "void" - } - ], - "typeName": "Promise" - } - }, - "typeParams": [], - "hasBody": true, - "isAsync": true, - "isGenerator": false - }, - "location": { - "filename": "file:///test.ts", - "line": 23, - "col": 4 - } - }, - { - "jsDoc": { - "doc": "Sync bar method", - }, - "accessibility": null, - "optional": true, - "isAbstract": false, - "isStatic": false, - "name": "bar", - "kind": "method", - "functionDef": { - "params": [], - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - }, - "location": { - "filename": "file:///test.ts", - "line": 28, - "col": 4 - } - }, - { - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "isOverride": true, - "name": "s", - "kind": "method", - "functionDef": { - "params": [], - "returnType": null, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - }, - "location": { - "filename": "file:///test.ts", - "line": 32, - "col": 4, - } - } - ] - } - }]); - - json_test!( - export_class_object_extends, - r#" -class Foo {} -const obj = { Foo } - -export class Bar extends obj.Foo {} - "#, - false; - [{ - "kind": "class", - "name": "Bar", - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 0 - }, - "declarationKind": "export", - "classDef": { - "isAbstract": false, - "constructors": [], - "properties": [], - "indexSignatures": [], - "methods": [], - "extends": "obj.Foo", - "implements": [], - "typeParams": [], - "superTypeParams": [] - } - }, { - "kind": "variable", - "name": "obj", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 6, - }, - "declarationKind": "private", - "variableDef": { - "tsType": { - "repr": "", - "kind": "typeLiteral", - "typeLiteral": { - "methods": [], - "properties": [{ - "name": "Foo", - "params": [], - "computed": false, - "optional": false, - "tsType": null, - "typeParams": [], - }], - "callSignatures": [], - "indexSignatures": [], - }, - }, - "kind": "const", - }, - }], vec!["file:///test.ts:3:6 PrivateTypeRef"] - ); - - json_test!(export_class_ignore, - r#" -/** Class doc */ -export class Foobar extends Fizz implements Buzz, Aldrin { - /** @ignore */ - private private1?: boolean; - protected protected1: number; - /** @ignore */ - public public1: boolean; - public2: number; - /** @ignore */ - override public3: string; - /** @ignore */ - m = new Map(); - s = "foo"; - a = [1, "foo"]; - fn = (a: string): void => {}; - - /** Constructor js doc */ - /** @ignore */ - constructor(name: string, private private2: number, protected protected2: number) {} - - /** Async foo method */ - /** @ignore */ - async foo(): Promise { - // - } - - /** Sync bar method */ - /** @ignore */ - bar?(): void { - // - } - - /** @ignore */ - override s() {} -} - "#; - [{ - "kind": "class", - "name": "Foobar", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Class doc", - }, - "classDef": { - "isAbstract": false, - "extends": "Fizz", - "constructors": [], - "implements": [ - { - "repr": "Buzz", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Buzz" - } - }, - { - "repr": "Aldrin", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Aldrin" - } - } - ], - "typeParams": [], - "superTypeParams": [], - "properties": [ - { - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }, - "readonly": false, - "accessibility": "protected", - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "protected1", - "location": { - "filename": "file:///test.ts", - "line": 6, - "col": 4 - } - }, - { - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "public2", - "location": { - "filename": "file:///test.ts", - "line": 9, - "col": 4 - } - }, - { - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "s", - "location": { - "filename": "file:///test.ts", - "line": 14, - "col": 4, - } - }, - { - "tsType": { - "repr": "", - "kind": "array", - "array": { - "repr": "", - "kind": "union", - "union": [ - { - "repr": "number", - "kind": "keyword", - "keyword": "number", - }, { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - ] - } - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 15, - "col": 4, - } - }, - { - "tsType": { - "repr": "", - "kind": "fnOrConstructor", - "fnOrConstructor": { - "constructor": false, - "tsType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "params": [ - { - "kind": "identifier", - "name": "a", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - } - ], - "typeParams": [] - } - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "fn", - "location": { - "filename": "file:///test.ts", - "line": 16, - "col": 4, - }, - } - ], - "indexSignatures": [], - "methods": [] - } - }]); - - json_test!(export_class_decorators, - r#" -@sealed -export class A { - #x = "x"; - - @format("Hello, %s") - greeting: string; - - @configurable(false) - get x() { - return this.#x; - } - - @enumerable(false) - greet() { - return "hello"; - } - - method(@readonly param: string) {} -} -"#; - [{ - "kind": "class", - "name": "A", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0, - }, - "declarationKind": "export", - "classDef": { - "isAbstract": false, - "constructors": [], - "properties": [ - { - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, - "readonly": false, - "accessibility": null, - "decorators": [ - { - "name": "format", - "args": [ - "\"Hello, %s\"", - ], - "location": { - "filename": "file:///test.ts", - "line": 6, - "col": 3, - } - } - ], - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "greeting", - "location": { - "filename": "file:///test.ts", - "line": 6, - "col": 2, - } - } - ], - "indexSignatures": [], - "methods": [ - { - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "x", - "kind": "getter", - "functionDef": { - "params": [], - "returnType": null, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - "decorators": [ - { - "name": "configurable", - "args": [ - "false" - ], - "location": { - "filename": "file:///test.ts", - "line": 9, - "col": 3, - } - } - ] - }, - "location": { - "filename": "file:///test.ts", - "line": 9, - "col": 2, - } - }, { - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "greet", - "kind": "method", - "functionDef": { - "params": [], - "returnType": null, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - "decorators": [ - { - "name": "enumerable", - "args": [ - "false" - ], - "location": { - "filename": "file:///test.ts", - "line": 14, - "col": 3, - } - } - ] - }, - "location": { - "filename": "file:///test.ts", - "line": 14, - "col": 2, - } - }, { - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "method", - "kind": "method", - "functionDef": { - "params": [ - { - "kind": "identifier", - "name": "param", - "optional": false, - "decorators": [ - { - "name": "readonly", - "location": { - "filename": "file:///test.ts", - "line": 19, - "col": 10, - } - } - ], - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - } - ], - "returnType": null, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - }, - "location": { - "filename": "file:///test.ts", - "line": 19, - "col": 2, - } - } - ], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [], - "decorators": [ - { - "name": "sealed", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 1, - } - } - ] - } - }] - ); - - json_test!(decorators_jsdoc, - r#" -/** jsdoc */ -@sealed -export class A { - a: string = "a"; -} - "#; - [ - { - "kind": "class", - "name": "A", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 0, - }, - "declarationKind": "export", - "jsDoc": { - "doc": "jsdoc" - }, - "classDef": { - "isAbstract": false, - "constructors": [], - "properties": [ - { - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, - "readonly": false, - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 2, - } - } - ], - "indexSignatures": [], - "methods": [], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [], - "decorators": [ - { - "name": "sealed", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 1, - } - } - ] - } - } - ]); - - json_test!(export_const_basic, - r#" -/** Something about fizzBuzz */ -export const fizzBuzz = "fizzBuzz"; - -export const env: { - /** get doc */ - get(key: string): string | undefined; - - /** set doc */ - set(key: string, value: string): void; -} - -export const num = 100; -export const bool = false; -export const bigint = 123n; -export const regex = /hello/; -export const date = new Date(); -export const tpl1 = `foo`; -export const tpl2 = `Value: ${num}`; -/** @ignore */ -export const tpl3 = `Value: ${num}`; - "#; - [ - { - "kind":"variable", - "name":"fizzBuzz", - "location":{ - "filename":"file:///test.ts", - "line":3, - "col":13 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Something about fizzBuzz", - }, - "variableDef":{ - "tsType": { - "repr": "fizzBuzz", - "kind": "literal", - "literal": { - "kind": "string", - "string": "fizzBuzz" - } - }, - "kind":"const" - } - }, - { - "kind":"variable", - "name":"env", - "location":{ - "filename":"file:///test.ts", - "line":5, - "col":13 - }, - "declarationKind": "export", - "variableDef":{ - "tsType":{ - "repr":"", - "kind":"typeLiteral", - "typeLiteral":{ - "methods":[{ - "name":"get", - "kind": "method", - "params":[ - { - "name":"key", - "kind":"identifier", - "optional":false, - "tsType":{ - "repr":"string", - "kind":"keyword", - "keyword":"string" - } - } - ], - "optional": false, - "returnType":{ - "repr":"", - "kind":"union", - "union":[ - { - "repr":"string", - "kind":"keyword", - "keyword":"string" - }, - { - "repr":"undefined", - "kind":"keyword", - "keyword":"undefined" - } - ] - }, - "typeParams":[] - }, { - "name":"set", - "kind": "method", - "params":[ - { - "name":"key", - "kind":"identifier", - "optional":false, - "tsType":{ - "repr":"string", - "kind":"keyword", - "keyword":"string" - } - }, - { - "name":"value", - "kind":"identifier", - "optional":false, - "tsType":{ - "repr":"string", - "kind":"keyword", - "keyword":"string" - } - } - ], - "optional": false, - "returnType":{ - "repr":"void", - "kind":"keyword", - "keyword":"void" - }, - "typeParams":[] - } - ], - "properties":[], - "callSignatures":[], - "indexSignatures": [] - } - }, - "kind":"const" - } - }, - { - "kind":"variable", - "name":"num", - "location": { - "filename":"file:///test.ts", - "line":13, - "col":13 - }, - "declarationKind": "export", - "variableDef":{ - "tsType":{ - "repr":"100", - "kind":"literal", - "literal":{ - "kind":"number", - "number":100.0 - } - }, - "kind":"const" - } - }, - { - "kind":"variable", - "name":"bool", - "location":{ - "filename":"file:///test.ts", - "line":14, - "col":13 - }, - "declarationKind": "export", - "variableDef":{ - "tsType":{ - "repr":"false", - "kind":"literal", - "literal":{ - "kind":"boolean", - "boolean":false - } - }, - "kind":"const" - } - }, - { - "kind":"variable", - "name":"bigint", - "location":{ - "filename":"file:///test.ts", - "line":15, - "col":13 - }, - "declarationKind": "export", - "variableDef":{ - "tsType":{ - "repr":"123", - "kind":"literal", - "literal":{ - "kind":"bigInt", - "string":"123" - } - }, - "kind":"const" - } - }, - { - "kind":"variable", - "name":"regex", - "location":{ - "filename":"file:///test.ts", - "line":16, - "col":13 - }, - "declarationKind": "export", - "variableDef":{ - "tsType":{ - "repr": "hello", - "kind":"typeRef", - "typeRef":{ - "typeParams":null, - "typeName":"RegExp" - } - }, - "kind":"const" - } - }, - { - "kind":"variable", - "name":"date", - "location":{ - "filename":"file:///test.ts", - "line":17, - "col":13 - }, - "declarationKind": "export", - "variableDef":{ - "tsType":{ - "repr": "Date", - "kind":"typeRef", - "typeRef":{ - "typeParams":null, - "typeName":"Date" - } - }, - "kind":"const" - } - }, - { - "kind":"variable", - "name":"tpl1", - "location":{ - "filename":"file:///test.ts", - "line":18, - "col":13 - }, - "declarationKind": "export", - "variableDef":{ - "tsType":{ - "repr": "foo", - "kind":"literal", - "literal":{ - "kind":"template", - "tsTypes": [ - { - "repr": "foo", - "kind": "literal", - "literal": { - "kind": "string", - "string": "foo" - } - } - ] - } - }, - "kind":"const" - } - }, - { - "kind":"variable", - "name":"tpl2", - "location":{ - "filename":"file:///test.ts", - "line":19, - "col":13 - }, - "declarationKind": "export", - "variableDef":{ - "tsType":{ - "repr": "string", - "kind":"keyword", - "keyword":"string" - }, - "kind":"const" - } - } - ] - ); - - json_test!(export_const_destructured, - r#"const c = { a: "a", b: 2 }; - const d: { f: string; g: number; } = { f: "f", g: 2 }; - - export const { - /** export a doc */ - a, - /** export b doc */ - b, - }: { - /** type alias doc */ - a: string; - /** other doc */ - b: number; - } = c; - - export const { f, g: h } = d; - "#; - [ - { - "kind": "variable", - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 6, - "col": 6, - }, - "declarationKind": "export", - "jsDoc": { - "doc": "export a doc", - }, - "variableDef": { - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - "kind": "const" - } - }, - { - "kind": "variable", - "name": "b", - "location": { - "filename": "file:///test.ts", - "line": 8, - "col": 6 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "export b doc", - }, - "variableDef": { - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }, - "kind": "const" - } - }, - { - "kind": "variable", - "name": "f", - "location": { - "filename": "file:///test.ts", - "line": 16, - "col": 19 - }, - "declarationKind": "export", - "variableDef": { - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - "kind": "const" - } - }, - { - "kind": "variable", - "name": "h", - "location": { - "filename": "file:///test.ts", - "line": 16, - "col": 25 - }, - "declarationKind": "export", - "variableDef": { - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }, - "kind": "const" - } - } - ] - ); - - json_test!(export_let, - r#" -export let str = "hello"; -export let num = 100; -export let bool = false; -export let dateStr = Date(); -export let regex = RegExp("foobar"); -export let sym = Symbol("baz"); -export let tpl = `foobarbaz`; - "#; - [ - { - "kind":"variable", - "name":"str", - "location":{ - "filename":"file:///test.ts", - "line":2, - "col":11 - }, - "declarationKind": "export", - "variableDef":{ - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword":"string" - }, - "kind":"let" - } - }, - { - "kind":"variable", - "name":"num", - "location":{ - "filename":"file:///test.ts", - "line":3, - "col":11 - }, - "declarationKind": "export", - "variableDef":{ - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword":"number" - }, - "kind":"let" - } - }, - { - "kind":"variable", - "name":"bool", - "location":{ - "filename":"file:///test.ts", - "line":4, - "col":11 - }, - "declarationKind": "export", - "variableDef":{ - "tsType": { - "repr": "boolean", - "kind": "keyword", - "keyword":"boolean" - }, - "kind":"let" - } - }, - { - "kind":"variable", - "name":"dateStr", - "location":{ - "filename":"file:///test.ts", - "line":5, - "col":11 - }, - "declarationKind": "export", - "variableDef":{ - "tsType": { - "repr": "Date", - "kind": "keyword", - "keyword":"string" - }, - "kind":"let" - } - }, - { - "kind":"variable", - "name":"regex", - "location":{ - "filename":"file:///test.ts", - "line":6, - "col":11 - }, - "declarationKind": "export", - "variableDef":{ - "tsType": { - "repr": "RegExp", - "kind": "typeRef", - "typeRef":{ - "typeParams":null, - "typeName":"RegExp" - } - }, - "kind":"let" - } - }, - { - "kind":"variable", - "name":"sym", - "location":{ - "filename":"file:///test.ts", - "line":7, - "col":11 - }, - "declarationKind": "export", - "variableDef":{ - "tsType": { - "repr": "Symbol", - "kind": "keyword", - "keyword":"symbol" - }, - "kind":"let" - } - }, - { - "kind":"variable", - "name":"tpl", - "location":{ - "filename":"file:///test.ts", - "line":8, - "col":11 - }, - "declarationKind": "export", - "variableDef":{ - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword":"string" - }, - "kind":"let" - } - } - ] - ); - - json_test!(export_class_ctor_properties, - r#" -export class A { - constructor(public readonly name: string, private private: number, public override public: boolean) {} -}"#; - [{ - "kind": "class", - "name": "A", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0, - }, - "declarationKind": "export", - "classDef": { - "isAbstract": false, - "constructors": [{ - "accessibility": null, - "hasBody": true, - "name": "constructor", - "params": [ - { - "accessibility": "public", - "kind": "identifier", - "name": "name", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, - "readonly": true, - }, - { - "accessibility": "private", - "kind": "identifier", - "name": "private", - "optional": false, - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number", - }, - }, - { - "accessibility": "public", - "isOverride": true, - "kind": "identifier", - "name": "public", - "optional": false, - "tsType": { - "repr": "boolean", - "kind": "keyword", - "keyword": "boolean", - } - } - ], - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 2, - }, - }], - "properties": [], - "indexSignatures": [], - "methods": [], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [], - } - }]); - - json_test!(export_default_class, - r#" -/** Class doc */ -export default class Foobar { - /** Constructor js doc */ - constructor(name: string, private private2: number, protected protected2: number) {} -} - "#; - [{ - "kind": "class", - "name": "default", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Class doc", - }, - "classDef": { - "isAbstract": false, - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [], - "constructors": [ - { - "jsDoc": { - "doc": "Constructor js doc", - }, - "accessibility": null, - "hasBody": true, - "name": "constructor", - "params": [ - { - "name": "name", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - } - }, - { - "accessibility": "private", - "name": "private2", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - } - }, - { - "accessibility": "protected", - "name": "protected2", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - } - } - ], - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 4 - } - } - ], - "properties": [], - "indexSignatures": [], - "methods": [] - } - }]); - - json_test!(export_default_fn, - r#" -export default function foo(a: number) { - return a; -} -/** @ignore */ -export default function foo(a: number) { - return a; -} - "#; - [{ - "kind": "function", - "name": "default", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [ - { - "kind": "identifier", - "name": "a", - "optional": false, - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number", - }, - } - ], - "returnType": null, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - }]); - - json_test!(export_default_interface, - r#" -/** - * Interface js doc - */ -export default interface Reader { - /** Read n bytes */ - read?(buf: Uint8Array, something: unknown): Promise -} - "#; - [{ - "kind": "interface", - "name": "default", - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 0 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Interface js doc", - }, - "interfaceDef": { - "extends": [], - "methods": [ - { - "name": "read", - "kind": "method", - "location": { - "filename": "file:///test.ts", - "line": 7, - "col": 4 - }, - "optional": true, - "jsDoc": { - "doc": "Read n bytes", - }, - "params": [ - { - "name": "buf", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "Uint8Array", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Uint8Array" - } - } - }, - { - "name": "something", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "unknown", - "kind": "keyword", - "keyword": "unknown" - } - } - ], - "typeParams": [], - "returnType": { - "repr": "Promise", - "kind": "typeRef", - "typeRef": { - "typeParams": [ - { - "repr": "number", - "kind": "keyword", - "keyword": "number" - } - ], - "typeName": "Promise" - } - } - } - ], - "properties": [], - "callSignatures": [], - "indexSignatures": [], - "typeParams": [] - } - }]); - - json_test!(export_default_expr, - r#"export default "foo";"#; - [ - { - "kind": "variable", - "name": "default", - "location": { - "filename": "file:///test.ts", - "line": 1, - "col": 0 - }, - "declarationKind": "export", - "variableDef": { - "tsType": { - "repr": "foo", - "kind": "literal", - "literal": { - "kind": "string", - "string": "foo" - } - }, - "kind": "var" - } - } - ] - ); - - json_test!(export_enum, - r#" -/** - * Some enum for good measure - */ -export enum Hello { - World = "world", - /** There is a JsDoc */ - Fizz = "fizz", - /** There is a JsDoc - * @ignore - */ - Buzz = "buzz", -} - "#; - [{ - "kind": "enum", - "name": "Hello", - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 0 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Some enum for good measure", - }, - "enumDef": { - "members": [ - { - "name": "World", - "init": { - "repr": "world", - "kind": "literal", - "literal": { - "kind": "string", - "string": "world", - } - }, - "location": { - "filename": "file:///test.ts", - "line": 6, - "col": 4, - } - }, - { - "name": "Fizz", - "init": { - "repr": "fizz", - "kind": "literal", - "literal": { - "kind": "string", - "string": "fizz", - } - }, - "jsDoc": { - "doc": "There is a JsDoc" - }, - "location": { - "filename": "file:///test.ts", - "line": 8, - "col": 4, - } - } - ] - } - }]); - - json_test!(export_fn, - r#"/** -* @module foo -*/ - -/** -* Hello there, this is a multiline JSdoc. -* -* It has many lines -* -* Or not that many? -*/ -export function foo(a: string, b?: number, cb: (...cbArgs: unknown[]) => void, ...args: unknown[]): void { - /** - * @todo document all the things. - */ - console.log("Hello world"); -} - "#; - [ - { - "kind": "moduleDoc", - "name": "", - "location": { - "filename": "file:///test.ts", - "line": 1, - "col": 0, - }, - "declarationKind": "export", - "jsDoc": { - "tags": [ - { - "kind": "module" - } - ] - }, - }, { - "functionDef": { - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - "params": [ - { - "name": "a", - "kind": "identifier", - "optional": false, - "tsType": { - "keyword": "string", - "kind": "keyword", - "repr": "string", - }, - }, - { - "name": "b", - "kind": "identifier", - "optional": true, - "tsType": { - "keyword": "number", - "kind": "keyword", - "repr": "number", - }, - }, - { - "name": "cb", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "", - "kind": "fnOrConstructor", - "fnOrConstructor": { - "constructor": false, - "tsType": { - "keyword": "void", - "kind": "keyword", - "repr": "void" - }, - "typeParams": [], - "params": [{ - "arg": { - "name": "cbArgs", - "kind": "identifier", - "optional": false, - "tsType": null - }, - "kind": "rest", - "tsType": { - "repr": "", - "kind": "array", - "array": { - "repr": "unknown", - "kind": "keyword", - "keyword": "unknown" - } - }, - }] - } - }, - }, - { - "arg": { - "name": "args", - "kind": "identifier", - "optional": false, - "tsType": null - }, - "kind": "rest", - "tsType": { - "array": { - "keyword": "unknown", - "kind": "keyword", - "repr": "unknown" - }, - "kind": "array", - "repr": "" - } - } - ], - "returnType": { - "keyword": "void", - "kind": "keyword", - "repr": "void", - }, - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Hello there, this is a multiline JSdoc.\n\nIt has many lines\n\nOr not that many?", - }, - "kind": "function", - "location": { - "col": 0, - "filename": "file:///test.ts", - "line": 12, - }, - "name": "foo", - }]); - - json_test!(export_fn2, - r#" -interface AssignOpts { - a: string; -} - -export function foo([e,,f, ...g]: number[], { c, d: asdf, i = "asdf", ...rest}, ops: AssignOpts = {}): void { - console.log("Hello world"); -} - "#, - false; - [{ - "functionDef": { - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - "params": [ - { - "elements": [ - { - "name": "e", - "kind": "identifier", - "optional": false, - "tsType": null - }, - null, - { - "name": "f", - "kind": "identifier", - "optional": false, - "tsType": null - }, - { - "arg": { - "name": "g", - "kind": "identifier", - "optional": false, - "tsType": null - }, - "kind": "rest", - "tsType": null - } - ], - "kind": "array", - "optional": false, - "tsType": { - "repr": "", - "kind": "array", - "array": { - "repr": "number", - "kind": "keyword", - "keyword": "number" - } - } - }, - { - "kind": "object", - "optional": false, - "props": [ - { - "kind": "assign", - "key": "c", - "value": null - }, - { - "kind": "keyValue", - "key": "d", - "value": { - "name": "asdf", - "kind": "identifier", - "optional": false, - "tsType": null - } - }, - { - "kind": "assign", - "key": "i", - "value": "[UNSUPPORTED]" - }, - { - "arg": { - "name": "rest", - "kind": "identifier", - "optional": false, - "tsType": null - }, - "kind": "rest" - } - ], - "tsType": null - }, - { - "kind": "assign", - "left": { - "name": "ops", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "AssignOpts", - "kind": "typeRef", - "typeRef": { - "typeName": "AssignOpts", - "typeParams": null, - } - } - }, - "right": "[UNSUPPORTED]", - "tsType": null - } - ], - "returnType": { - "keyword": "void", - "kind": "keyword", - "repr": "void", - }, - }, - "kind": "function", - "declarationKind": "export", - "location": { - "col": 0, - "filename": "file:///test.ts", - "line": 6, - }, - "name": "foo", - }, { - "kind": "interface", - "name": "AssignOpts", - "location": { - "col": 0, - "filename": "file:///test.ts", - "line": 2, - }, - "declarationKind": "private", - "interfaceDef": { - "extends": [], - "methods": [], - "properties": [{ - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 2, - }, - "params": [], - "computed": false, - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, - "typeParams": [], - }], - "callSignatures": [], - "indexSignatures": [], - "typeParams": [], - } - }], vec!["file:///test.ts:2:0 PrivateTypeRef"]); - - json_test!(export_interface, - r#" -interface Foo { -} -interface Bar { -} -/** - * Interface js doc - */ -export interface Reader extends Foo, Bar { - /** Read n bytes */ - read?(buf: Uint8Array, something: unknown): Promise - /** Test */ - [key: string]: number; -} - "#, - false; - [{ - "kind": "interface", - "name": "Reader", - "location": { - "filename": "file:///test.ts", - "line": 9, - "col": 0 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Interface js doc", - }, - "interfaceDef": { - "extends": [ - { - "repr": "Foo", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Foo" - } - }, - { - "repr": "Bar", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Bar" - } - } - ], - "methods": [ - { - "name": "read", - "kind": "method", - "location": { - "filename": "file:///test.ts", - "line": 11, - "col": 4 - }, - "optional": true, - "jsDoc": { - "doc": "Read n bytes", - }, - "params": [ - { - "name": "buf", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "Uint8Array", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Uint8Array" - } - } - }, - { - "name": "something", - "kind": "identifier", - "optional": false, - "tsType": { - "repr": "unknown", - "kind": "keyword", - "keyword": "unknown" - } - } - ], - "typeParams": [], - "returnType": { - "repr": "Promise", - "kind": "typeRef", - "typeRef": { - "typeParams": [ - { - "repr": "number", - "kind": "keyword", - "keyword": "number" - } - ], - "typeName": "Promise" - } - } - } - ], - "properties": [], - "callSignatures": [], - "indexSignatures": [{ - "location": { - "filename": "file:///test.ts", - "line": 13, - "col": 4, - }, - "jsDoc": { - "doc": "Test", - }, - "readonly": false, - "params": [{ - "kind": "identifier", - "name": "key", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - }], - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number", - } - }], - "typeParams": [], - } - }, { - "kind": "interface", - "name": "Foo", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "private", - "interfaceDef": { - "extends": [], - "methods": [], - "properties": [], - "callSignatures": [], - "indexSignatures": [], - "typeParams": [], - } - }, { - "kind": "interface", - "name": "Bar", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 0 - }, - "declarationKind": "private", - "interfaceDef": { - "extends": [], - "methods": [], - "properties": [], - "callSignatures": [], - "indexSignatures": [], - "typeParams": [], - } - }], vec![ - "file:///test.ts:2:0 PrivateTypeRef", - "file:///test.ts:4:0 PrivateTypeRef" - ]); - - json_test!(export_interface2, - r#" -export interface TypedIface { - something(): T -} - "#; - [{ - "kind": "interface", - "name": "TypedIface", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "interfaceDef": { - "extends": [], - "methods": [ - { - "name": "something", - "kind": "method", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 4 - }, - "optional": false, - "params": [], - "typeParams": [], - "returnType": { - "repr": "T", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "T" - } - } - } - ], - "properties": [], - "callSignatures": [], - "indexSignatures": [], - "typeParams": [ - { "name": "T" } - ], - } - }]); - - json_test!(export_interface_accessors, - r#" -export interface Thing { - get size(): number; - set size(value: number | string); -} - "#; - [{ - "kind": "interface", - "name": "Thing", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "interfaceDef": { - "extends": [], - "methods": [ - { - "name": "size", - "kind": "getter", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 2, - }, - "optional": false, - "params": [], - "typeParams": [], - "returnType": { - "repr": "number", - "kind": "keyword", - "keyword": "number", - }, - }, - { - "name": "size", - "kind": "setter", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 2, - }, - "optional": false, - "params": [ - { - "kind": "identifier", - "name": "value", - "optional": false, - "tsType": { - "repr": "", - "kind": "union", - "union": [ - { - "repr": "number", - "kind": "keyword", - "keyword": "number", - }, - { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - ] - } - } - ], - "typeParams": [], - "returnType": null, - }, - ], - "properties": [], - "callSignatures": [], - "indexSignatures": [], - "typeParams": [], - } - }] - ); - - json_test!(export_type_alias, - r#" -/** Array holding numbers */ -export type NumberArray = Array; - "#; - [{ - "kind": "typeAlias", - "name": "NumberArray", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Array holding numbers", - }, - "typeAliasDef": { - "typeParams": [], - "tsType": { - "repr": "Array", - "kind": "typeRef", - "typeRef": { - "typeParams": [ - { - "repr": "number", - "kind": "keyword", - "keyword": "number" - } - ], - "typeName": "Array" - } - } - } - }]); - - json_test!(export_type_alias_literal, - r#" -export type A = { - new (d: string): A; - a(): void; - b?(): void; - get c(): string; - set c(v: number); -}; -"#; - [{ - "kind": "typeAlias", - "name": "A", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0, - }, - "declarationKind": "export", - "typeAliasDef": { - "typeParams": [], - "tsType": { - "repr": "", - "kind": "typeLiteral", - "typeLiteral": { - "methods": [ - { - "name": "new", - "kind": "method", - "params": [ - { - "kind": "identifier", - "name": "d", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - } - ], - "optional": false, - "returnType": { - "repr": "A", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "A", - } - }, - "typeParams": [], - }, - { - "name": "a", - "kind": "method", - "params": [], - "optional": false, - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void", - }, - "typeParams": [], - }, - { - "name": "b", - "kind": "method", - "params": [], - "optional": true, - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void", - }, - "typeParams": [], - }, - { - "name": "c", - "kind": "getter", - "params": [], - "optional": false, - "returnType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, - "typeParams": [], - }, - { - "name": "c", - "kind": "setter", - "params": [ - { - "kind": "identifier", - "name": "v", - "optional": false, - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number", - } - } - ], - "optional": false, - "returnType": null, - "typeParams": [], - } - ], - "properties": [], - "callSignatures": [], - "indexSignatures": [] - } - } - } - }]); - - json_test!(export_namespace, - r#" -/** Namespace JSdoc */ -export namespace RootNs { - export const a = "a"; - - /** Nested namespace JSDoc */ - export namespace NestedNs { - export enum Foo { - a = 1, - b = 2, - c = 3, - } - } -} - -export namespace RootNs.OtherNs { - export class Other {} -} - "#; - [{ - "kind": "namespace", - "name": "RootNs", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Namespace JSdoc", - }, - "namespaceDef": { - "elements": [ - { - "kind": "variable", - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 17 - }, - "declarationKind": "export", - "variableDef": { - "tsType": { - "repr": "a", - "kind": "literal", - "literal": { - "kind": "string", - "string": "a" - } - }, - "kind": "const" - } - }, - { - "kind": "namespace", - "name": "NestedNs", - "location": { - "filename": "file:///test.ts", - "line": 7, - "col": 4 - }, - "declarationKind": "export", - "jsDoc": { - "doc": "Nested namespace JSDoc", - }, - "namespaceDef": { - "elements": [ - { - "kind": "enum", - "name": "Foo", - "location": { - "filename": "file:///test.ts", - "line": 8, - "col": 6 - }, - "declarationKind": "export", - "enumDef": { - "members": [ - { - "name": "a", - "init": { - "repr": "1", - "kind": "literal", - "literal": { - "kind": "number", - "number": 1.0, - } - }, - "location": { - "filename": "file:///test.ts", - "line": 9, - "col": 8, - } - }, - { - "name": "b", - "init": { - "repr": "2", - "kind": "literal", - "literal": { - "kind": "number", - "number": 2.0, - } - }, - "location": { - "filename": "file:///test.ts", - "line": 10, - "col": 8, - } - }, - { - "name": "c", - "init": { - "repr": "3", - "kind": "literal", - "literal": { - "kind": "number", - "number": 3.0, - } - }, - "location": { - "filename": "file:///test.ts", - "line": 11, - "col": 8, - } - } - ] - } - } - ] - } - }, - { - "kind": "namespace", - "name": "OtherNs", - "location": { - "filename": "file:///test.ts", - "line": 16, - "col": 7 - }, - "declarationKind": "export", - "namespaceDef": { - "elements": [ - { - "kind": "class", - "name": "Other", - "location": { - "filename": "file:///test.ts", - "line": 17, - "col": 2 - }, - "declarationKind": "export", - "classDef": { - "isAbstract": false, - "constructors": [], - "properties": [], - "indexSignatures": [], - "methods": [], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [], - } - } - ] - } - } - ] - } - }]); - - json_test!(export_namespace_enum_same_name, - r#" -export namespace RootNs { - export namespace NestedNs { - export enum Foo { - } - } - - export enum Foo { - } -} - "#; - [{ - "kind": "namespace", - "name": "RootNs", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "namespaceDef": { - "elements": [ - { - "kind": "namespace", - "name": "NestedNs", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 2 - }, - "declarationKind": "export", - "namespaceDef": { - "elements": [ - { - "kind": "enum", - "name": "Foo", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 4 - }, - "declarationKind": "export", - "enumDef": { - "members": [] - } - } - ] - } - }, - { - "kind": "enum", - "name": "Foo", - "location": { - "filename": "file:///test.ts", - "line": 8, - "col": 2 - }, - "declarationKind": "export", - "enumDef": { - "members": [] - } - } - ] - } - }]); - - json_test!(export_declaration_merged_namespace, - r#" -namespace Namespace1 { - export class Test1 {} -} -namespace Namespace1 { - export class Test2 {} -} - -export { Namespace1 }; -"#; - [{ - "kind": "namespace", - "name": "Namespace1", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0, - }, - "declarationKind": "export", - "namespaceDef": { - "elements": [{ - "kind": "class", - "name": "Test1", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 2, - }, - "declarationKind": "export", - "classDef": { - "isAbstract": false, - "constructors": [], - "properties": [], - "indexSignatures": [], - "methods": [], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [] - } - }, { - "kind": "class", - "name": "Test2", - "location": { - "filename": "file:///test.ts", - "line": 6, - "col": 2, - }, - "declarationKind": "export", - "classDef": { - "isAbstract": false, - "constructors": [], - "properties": [], - "indexSignatures": [], - "methods": [], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [] - } - }] - } - }] - ); - - json_test!(exports_declared_earlier, - r#" -const hello = "world"; -function say(words: string): void { } -function foo(): void { } -export { hello, say, foo as bar }; - "#; - [ - { - "kind": "variable", - "name": "hello", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 6 - }, - "declarationKind": "export", - "variableDef": { - "tsType": { - "repr": "world", - "kind": "literal", - "literal": { - "kind": "string", - "string": "world" - } - }, - "kind": "const" - } - }, - { - "kind": "function", - "name": "say", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [ - { - "kind": "identifier", - "name": "words", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - } - } - ], - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - }, - { - "kind": "function", - "name": "bar", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [], - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - } - ] - ); - - json_test!(non_implemented_renamed_exports_declared_earlier, - r#" - declare function foo(): void; - export { foo as bar }; - "#; - [ - { - "kind": "function", - "name": "bar", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 2 - }, - "declarationKind": "export", - "functionDef": { - "params": [], - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - } - ] - ); - - json_test!(no_ambient_in_module, - r#" -declare function foo(): number; -export function bar() {}; - "#; - [ - { - "kind": "function", - "name": "bar", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [], - "returnType": null, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - } - ] - ); - - json_test!(default_exports_declared_earlier, - r#" -function foo(): void {} -export default foo; - "#; - [ - { - "kind": "function", - "name": "default", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [], - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - } - ] - ); - - json_test!(reexport_existing_export, - r#" -export function foo(): void {} -export { foo as bar }; - "#; - [ - { - "kind": "function", - "name": "foo", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [], - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - }, - { - "kind": "function", - "name": "bar", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [], - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - } - ] - ); - - json_test!(optional_return_type, - r#" - export function foo(a: number) { - return a; - } - "#; - [{ - "kind": "function", - "name": "foo", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 2 - }, - "declarationKind": "export", - "functionDef": { - "params": [ - { - "name": "a", - "kind": "identifier", - "optional": false, - "tsType": { - "keyword": "number", - "kind": "keyword", - "repr": "number", - }, - } - ], - "typeParams": [], - "returnType": null, - "hasBody": true, - "isAsync": false, - "isGenerator": false - } - }] - ); - - json_test!(ts_lit_types, - r#" -export type boolLit = false; -export type strLit = "text"; -export type tplLit = `text`; -export type tplLitArg = `test${number}`; -export type numLit = 5; - "#; - [ - { - "kind": "typeAlias", - "name": "boolLit", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "typeAliasDef": { - "tsType": { - "repr": "false", - "kind": "literal", - "literal": { - "kind": "boolean", - "boolean": false - } - }, - "typeParams": [] - } - }, { - "kind": "typeAlias", - "name": "strLit", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "export", - "typeAliasDef": { - "tsType": { - "repr": "text", - "kind": "literal", - "literal": { - "kind": "string", - "string": "text" - } - }, - "typeParams": [] - } - }, { - "kind": "typeAlias", - "name": "tplLit", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 0 - }, - "declarationKind": "export", - "typeAliasDef": { - "tsType": { - "repr": "text", - "kind": "literal", - "literal": { - "kind": "template", - "tsTypes": [ - { - "repr": "text", - "kind": "literal", - "literal": { - "kind": "string", - "string": "text" - } - } - ] - } - }, - "typeParams": [] - } - }, { - "kind": "typeAlias", - "name": "tplLitArg", - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 0, - }, - "declarationKind": "export", - "typeAliasDef": { - "tsType": { - "repr": "test${number}", - "kind": "literal", - "literal": { - "kind": "template", - "tsTypes": [ - { - "repr": "test", - "kind": "literal", - "literal": { - "kind": "string", - "string": "test", - } - }, { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }, { - "repr": "", - "kind": "literal", - "literal": { - "kind": "string", - "string": "" - } - } - ] - } - }, - "typeParams": [], - } - }, { - "kind": "typeAlias", - "name": "numLit", - "location": { - "filename": "file:///test.ts", - "line": 6, - "col": 0 - }, - "declarationKind": "export", - "typeAliasDef": { - "tsType": { - "repr": "5", - "kind": "literal", - "literal": { - "kind": "number", - "number": 5.0 - } - }, - "typeParams": [] - } - } - ]); - - json_test!(export_private, - r#" -const foo: string = "foo"; -export { foo }; - "#, - private; - [ - { - "kind": "variable", - "name": "foo", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 6 - }, - "declarationKind": "export", - "variableDef": { - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - "kind": "const" - } - } - ] - ); - - json_test!(ts_type_predicate_1, - r#" -export function foo(bar: A | B): bar is A {} - "#; - [ - { - "kind": "function", - "name": "foo", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [ - { - "kind": "identifier", - "name": "bar", - "optional": false, - "tsType": { - "repr": "", - "kind": "union", - "union": [ - { - "repr": "A", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "A" - } - }, - { - "repr": "B", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "B" - } - } - ] - } - } - ], - "returnType": { - "repr": "bar is A", - "kind": "typePredicate", - "typePredicate": { - "asserts": false, - "param": { - "type": "identifier", - "name": "bar" - }, - "type": { - "repr": "A", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "A" - } - } - } - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - } - ] - ); - - json_test!(ts_type_predicate_2, - r#" -export function foo(bar: A | B): asserts bar is B {} - "#; - [ - { - "kind": "function", - "name": "foo", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [ - { - "kind": "identifier", - "name": "bar", - "optional": false, - "tsType": { - "repr": "", - "kind": "union", - "union": [ - { - "repr": "A", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "A" - } - }, - { - "repr": "B", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "B" - } - } - ] - } - } - ], - "returnType": { - "repr": "asserts bar is B", - "kind": "typePredicate", - "typePredicate": { - "asserts": true, - "param": { - "type": "identifier", - "name": "bar" - }, - "type": { - "repr": "B", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "B" - } - } - } - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - } - ] - ); - - json_test!(ts_type_predicate_3, - r#" -export class C { - isSomething(): this is Something {} -} - "#; - [ - { - "kind": "class", - "name": "C", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "classDef": { - "isAbstract": false, - "constructors": [], - "properties": [], - "indexSignatures": [], - "methods": [ - { - "accessibility": null, - "optional": false, - "isAbstract": false, - "isStatic": false, - "name": "isSomething", - "kind": "method", - "functionDef": { - "params": [], - "returnType": { - "repr": "this is Something", - "kind": "typePredicate", - "typePredicate": { - "asserts": false, - "param": { - "type": "this" - }, - "type": { - "repr": "Something", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Something", - }, - }, - }, - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - }, - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 2 - } - } - ], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [] - } - } - ] - ); - - json_test!(ts_type_assertion, - r#" -export function foo(bar: any): asserts bar {} - "#; - [ - { - "kind": "function", - "name": "foo", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [ - { - "kind": "identifier", - "name": "bar", - "optional": false, - "tsType": { - "repr": "any", - "kind": "keyword", - "keyword": "any" - } - } - ], - "returnType": { - "repr": "asserts bar", - "kind": "typePredicate", - "typePredicate": { - "asserts": true, - "param": { - "type": "identifier", - "name": "bar" - }, - "type": null, - } - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [] - } - } - ] - ); - - json_test!(infer_types, - r#"export type Flatten = T extends Array ? U : T;"#; - [ - { - "kind": "typeAlias", - "name": "Flatten", - "location": { - "filename": "file:///test.ts", - "line": 1, - "col": 0 - }, - "declarationKind": "export", - "typeAliasDef": { - "tsType": { - "repr": "", - "kind": "conditional", - "conditionalType": { - "checkType": { - "repr": "T", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "T" - } - }, - "extendsType": { - "repr": "Array", - "kind": "typeRef", - "typeRef": { - "typeParams": [ - { - "repr": "", - "kind": "infer", - "infer": { - "typeParam": { - "name": "U" - } - } - } - ], - "typeName": "Array" - } - }, - "trueType": { - "repr": "U", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "U" - } - }, - "falseType": { - "repr": "T", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "T", - } - } - } - }, - "typeParams": [ - { - "name": "T" - } - ] - } - } - ]); - - json_test!(infer_object_literal, - r#" - const s: symbol = Symbol.for("s"); - const t: symbol = Symbol.for("t"); - - export const a = { - a: "a", - b: new Map(), - c: { d: "d" }, - d(e: string): void {}, - f: (g: string): void => {}, - get h(): string { - return "h"; - }, - set h(value: string) { - - }, - [s]: [1, 2, 3, "a"], - [t](u: string): void {}, - };"#; - [ - { - "kind": "variable", - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 17 - }, - "declarationKind": "export", - "variableDef": { - "tsType": { - "repr": "", - "kind": "typeLiteral", - "typeLiteral": { - "methods": [ - { - "name": "d", - "kind": "method", - "params": [ - { - "kind": "identifier", - "name": "e", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - } - } - ], - "optional": false, - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "typeParams": [] - }, - { - "name": "h", - "kind": "getter", - "params": [], - "optional": false, - "returnType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - "typeParams": [] - }, - { - "name": "h", - "kind": "setter", - "params": [ - { - "kind": "identifier", - "name": "value", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - } - } - ], - "optional": false, - "returnType": null, - "typeParams": [] - }, - { - "name": "[t]", - "kind": "method", - "params": [ - { - "kind": "identifier", - "name": "u", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - } - } - ], - "computed": true, - "optional": false, - "returnType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "typeParams": [] - } - ], - "properties": [ - { - "name": "a", - "params": [], - "computed": false, - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - "typeParams": [] - }, - { - "name": "b", - "params": [], - "computed": false, - "optional": false, - "tsType": { - "repr": "Map", - "kind": "typeRef", - "typeRef": { - "typeParams": [ - { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - { - "repr": "number", - "kind": "keyword", - "keyword": "number" - } - ], - "typeName": "Map" - } - }, - "typeParams": [] - }, - { - "name": "c", - "params": [], - "computed": false, - "optional": false, - "tsType": { - "repr": "", - "kind": "typeLiteral", - "typeLiteral": { - "methods": [], - "properties": [ - { - "name": "d", - "params": [], - "computed": false, - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - "typeParams": [] - } - ], - "callSignatures": [], - "indexSignatures": [] - } - }, - "typeParams": [] - }, - { - "name": "f", - "params": [], - "computed": false, - "optional": false, - "tsType": { - "repr": "", - "kind": "fnOrConstructor", - "fnOrConstructor": { - "constructor": false, - "tsType": { - "repr": "void", - "kind": "keyword", - "keyword": "void" - }, - "params": [ - { - "kind": "identifier", - "name": "g", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - } - } - ], - "typeParams": [] - } - }, - "typeParams": [] - }, - { - "name": "[s]", - "params": [], - "computed": true, - "optional": false, - "tsType": { - "repr": "", - "kind": "array", - "array": { - "repr": "", - "kind": "union", - "union": [ - { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }, - { - "repr": "string", - "kind": "keyword", - "keyword": "string" - } - ] - } - }, - "typeParams": [] - } - ], - "callSignatures": [], - "indexSignatures": [] - } - }, - "kind": "const" - } - } - ] - ); - - json_test!(mapped_types, - r#" -export type MappedTypeWithNewProperties = { - readonly [Properties in keyof Type as NewKeyType]?: Type[Properties]; -}; -"#; - [ - { - "kind": "typeAlias", - "name": "MappedTypeWithNewProperties", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0, - }, - "declarationKind": "export", - "typeAliasDef": { - "tsType": { - "repr": "", - "kind": "mapped", - "mappedType": { - "readonly": true, - "typeParam": { - "name": "Properties", - "constraint": { - "repr": "", - "kind": "typeOperator", - "typeOperator": { - "operator": "keyof", - "tsType": { - "repr": "Type", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Type" - } - } - } - } - }, - "nameType": { - "repr": "NewKeyType", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "NewKeyType" - } - }, - "optional": true, - "tsType": { - "repr": "", - "kind": "indexedAccess", - "indexedAccess": { - "readonly": false, - "objType": { - "repr": "Type", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Type", - } - }, - "indexType": { - "repr": "Properties", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "Properties" - } - } - } - } - } - }, - "typeParams": [ - { - "name": "Type", - } - ] - } - } - ]); - - json_test!(import_types, - r#" -export function adopt(p: import("./module.ts").Pet) { - console.log(`Adopting ${p.name}...`); -} -"#; - [ - { - "kind": "function", - "name": "adopt", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0, - }, - "declarationKind": "export", - "functionDef": { - "params": [ - { - "kind": "identifier", - "name": "p", - "optional": false, - "tsType": { - "repr": "", - "kind": "importType", - "importType": { - "specifier": "./module.ts", - "qualifier": "Pet", - "typeParams": [ - { - "repr": "T", - "kind": "typeRef", - "typeRef": { - "typeParams": null, - "typeName": "T" - } - } - ] - } - } - } - ], - "returnType": null, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [ - { - "name": "T" - } - ] - } - } - ] - ); - - json_test!(indented_with_tabs, - r#" -/** - * Line 1 - * - * Line 2 - * - * Indented - */ -export namespace Tabs { - /** - * Line 1 - * - * Line 2 - * - * Indented - */ - export interface Tabs{ - /** - * Line 1 - * - * Line 2 - * - * Indented - */ - property: string; - } -} - "#; - [ - { - "kind": "namespace", - "name": "Tabs", - "location": { - "filename": "file:///test.ts", - "line": 9, - "col": 0 - }, - "jsDoc": { - "doc": "Line 1\n\nLine 2\n\n\tIndented", - }, - "declarationKind": "export", - "namespaceDef": { - "elements": [ - { - "kind": "interface", - "name": "Tabs", - "location": { - "filename": "file:///test.ts", - "line": 17, - "col": 4 - }, - "jsDoc": { - "doc": "Line 1\n\nLine 2\n\n\tIndented", - }, - "declarationKind": "export", - "interfaceDef": { - "extends": [], - "methods": [], - "properties": [ - { - "name": "property", - "location": { - "filename": "file:///test.ts", - "line": 25, - "col": 8 - }, - "jsDoc": { - "doc": "Line 1\n\nLine 2\n\n\tIndented", - }, - "params": [], - "computed": false, - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, - "typeParams": [] - } - ], - "callSignatures": [], - "indexSignatures": [], - "typeParams": [] - } - } - ] - } - } - ] - ); - - json_test!(overloads, - r#" -export function a(b: string): string; -export function a(b: number): number; -export function a(b: string | number): string | number { - // -} - "#; - [{ - "kind": "function", - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [{ - "kind": "identifier", - "name": "b", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, - }], - "returnType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - } - }, { - "kind": "function", - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [{ - "kind": "identifier", - "name": "b", - "optional": false, - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number", - }, - }], - "returnType": { - "repr": "number", - "kind": "keyword", - "keyword": "number", - }, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - } - }, { - "kind": "function", - "name": "a", - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 0 - }, - "declarationKind": "export", - "functionDef": { - "params": [{ - "kind": "identifier", - "name": "b", - "optional": false, - "tsType": { - "repr": "", - "kind": "union", - "union": [{ - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }] - } - }], - "returnType": { - "repr": "", - "kind": "union", - "union": [{ - "repr": "string", - "kind": "keyword", - "keyword": "string" - }, { - "repr": "number", - "kind": "keyword", - "keyword": "number" - }] - }, - "hasBody": true, - "isAsync": false, - "isGenerator": false, - "typeParams": [], - } - }]); - - json_test!(ctor_overloads, - r#" -export class A { - constructor (a: string); - constructor (a: number); - constructor (a: string | number) { - // - } -}"#; - [{ - "kind": "class", - "name": "A", - "location": { - "filename": "file:///test.ts", - "line": 2, - "col": 0, - }, - "declarationKind": "export", - "classDef": { - "isAbstract": false, - "constructors": [{ - "accessibility": null, - "name": "constructor", - "params": [{ - "kind": "identifier", - "name": "a", - "optional": false, - "tsType": { - "repr": "string", - "kind": "keyword", - "keyword": "string", - } - }], - "location": { - "filename": "file:///test.ts", - "line": 3, - "col": 2, - } - }, { - "accessibility": null, - "name": "constructor", - "params": [{ - "kind": "identifier", - "name": "a", - "optional": false, - "tsType": { - "repr": "number", - "kind": "keyword", - "keyword": "number", - } - }], - "location": { - "filename": "file:///test.ts", - "line": 4, - "col": 2, - } - }, { - "accessibility": null, - "hasBody": true, - "name": "constructor", - "params": [{ - "kind": "identifier", - "name": "a", - "optional": false, - "tsType": { - "repr": "", - "kind": "union", - "union": [{ - "repr": "string", - "kind": "keyword", - "keyword": "string", - }, { - "repr": "number", - "kind": "keyword", - "keyword": "number", - }] - } - }], - "location": { - "filename": "file:///test.ts", - "line": 5, - "col": 2, - } - }], - "properties": [], - "indexSignatures": [], - "methods": [], - "extends": null, - "implements": [], - "typeParams": [], - "superTypeParams": [], - } - }]); -} - -mod printer { - use crate::*; - - contains_test!(abstract_class, - "export abstract class Class {}"; - "abstract class Class" - ); - - contains_test!(abstract_class_abstract_method, - r#" -export abstract class Class { - abstract method() {} -} - "#; - "abstract method()" - ); - - contains_test!(class_async_method, - r#" -export class Class { - async amethod(v) {} -} - "#; - "async amethod(v)" - ); - - contains_test!(class_constructor, - r#" -export class Class { - constructor(public a, readonly b) {} -} - "#; - "constructor(public a, readonly b)" - ); - - contains_test!(class_details, - r#" -export class C { - /** a doc */ - a() {} - f: number; -} - "#; - "class C", - "a()", - "f: number" - ); - - contains_test!(class_details_all_with_private, - r#" -export class Class { - private pri() {} - protected pro() {} - public pub() {} -} - "#, - private; - "private pri()", - "protected pro()", - "pub()" - ); - - contains_test!(class_details_only_non_private_without_private, - r#" -export class Class { - private pri() {} - protected pro() {} - public pub() {} -} - "#; - "protected pro()", - "pub()" - ); - - contains_test!(class_declaration, - "export class Class {}"; - "class Class" - ); - - contains_test!(class_extends, - "export class Class extends Object {}"; - "class Class extends Object" - ); - - contains_test!(class_extends_implements, - "export class Class extends Object implements Iterator, Iterable {}"; - "class Class extends Object implements Iterator, Iterable" - ); - - contains_test!(class_generic_extends_implements, - "export class Class extends Map implements Iterator, Iterable {}"; - "class Class extends Map implements Iterator, Iterable" - ); - - contains_test!(class_getter_and_setter, - r#" -export class Class { - get a(): void {} - set b(_v: void) {} -} - "#; - "get a(): void", - "set b(_v: void)" - ); - - contains_test!(class_override_prop_method, - r#" -export class C extends B { - override a(): void {} - override b: string; -} - "#; - "override a(): void", - "override b: string" - ); - - contains_test!(class_index_signature, - r#" -export class C { - [key: string]: number; -} - "#; - "[key: string]: number" - ); - - contains_test!(class_implements, - "export class Class implements Iterator {}"; - "class Class implements Iterator" - ); - - contains_test!(class_implements2, - "export class Class implements Iterator, Iterable {}"; - "class Class implements Iterator, Iterable" - ); - - contains_test!(class_method, - r#" -export class Class { - method(v) {} -} - "#; - "method(v)" - ); - - contains_test!(class_property, - r#" -export class Class { - someproperty: bool; - optproperty: bigint; -} - "#; - "someproperty: bool", - "optproperty: bigint" - ); - - contains_test!(class_readonly_index_signature, - r#" -export class C { - readonly [key: string]: number; -} - "#; - "readonly [key: string]: number" - ); - - contains_test!(class_static_property, - r#" -export class Class { - static property = ""; -} - "#; - "static property" - ); - - contains_test!(class_readonly_property, - r#" -export class Class { - readonly property = ""; -} - "#; - "readonly property" - ); - - contains_test!(class_private_property, - r#" -export class Class { - private property = ""; -} - "#, - private; - "private property" - ); - - contains_test!(class_decorators, - r#" -@sealed -export class A { - #x = "x"; - - @format("Hello, %s") - greeting: string; - - @configurable(false) - get x() { - return this.#x; - } - - @enumerable(false) - greet() { - return "hello"; - } -} - "#; - "@sealed", - "@format(\"Hello, %s\")", - "@configurable(false)", - "@enumerable(false)" - ); - - contains_test!(class_method_overloads, - r#"export class A { - a(b: string): string; - a(b: number): number; - a(b: string | number): string | number {} - }"#; - "a(b: string): string", - "a(b: number): number"; - "a(b: string | number): string | number" - ); - - contains_test!(const_declaration, - "export const Const = 0;"; - "const Const" - ); - - contains_test!(enum_declaration, - "export enum Enum {}"; - "enum Enum" - ); - - contains_test!(enum_member, - r#" -export enum Enum { - First, - /** There is a JsDoc */ - Second, -} - "#; - "enum Enum", - "First", - "Second", - "There is a JsDoc" - ); - - contains_test!(exports_all_with_private, - r#" -export function a() {} -function b() {} -export class C {} -class D {} -export interface E {} -interface F {} -export namespace G {} -namespace H {} - "#, - private; - "function a()", - "class C", - "interface E", - "namespace G", - "function b()", - "class D", - "interface F", - "namespace H" - ); - - contains_test!(exports_declared_earlier, - r#" -const hello = "world"; -function say(words: string): void { } -function foo(): void { } -export { hello, say, foo as bar }; - "#; - "const hello", - "function say(words: string): void", - "function bar(): void" - ); - - contains_test!(function_async, - "export async function a() {}"; - "async function a()" - ); - - contains_test!(function_array_deconstruction, - "export function f([a, b, ...c]) {}"; - "function f([a, b, ...c])" - ); - - contains_test!(function_async_generator, - "export async function* ag() {}"; - "async function* ag()" - ); - - contains_test!(function_declaration, - "export function fun() {}"; - "function fun()" - ); - - contains_test!(function_generator, - "export function* g() {}"; - "function* g()" - ); - - contains_test!(function_generic, - "export function add(a: T, b: T) { return a + b; }"; - "function add(a: T, b: T)" - ); - - contains_test!(function_object_deconstruction, - "export function f({ a, b, ...c }) {}"; - "function f({a, b, ...c})" - ); - - /* TODO(SyrupThinker) NYI - contains_test!(function_type_predicate, - r#" - export function isFish(pet: Fish | Bird): pet is Fish { - return (pet as Fish).swim !== undefined; - } - "#; - "pet is Fish" - ); - */ - - contains_test!(function_overloads, - r#" -export function a(b: string): string; -export function a(b: number): number; -export function a(b: string | number): string | number {} -"#; - "function a(b: string): string", - "function a(b: number): number"; - "function a(b: string | number): string | number" - ); - - contains_test!(generic_instantiated_with_tuple_type, - r#" -export interface Generic {} -export function f(): Generic<[string, number]> { return {}; } - "#; - "function f(): Generic<[string, number]>" - ); - - contains_test!(type_literal_declaration, - "export type T = {}"; - "{ }" - ); - - contains_test!(type_literal_index_signature, - "export type T = { [key: string]: number; }"; - "[key: string]: number" - ); - - contains_test!(type_literal_readonly_index_signature, - "export type T = { readonly [key: string]: number; }"; - "readonly [key: string]: number" - ); - - contains_test!(type_alias_infer_type, - "export type Flatten = T extends Array ? U : T;"; - "T extends Array ? U : T" - ); - - contains_test!(type_literal_mapped_type, - "export type T = { readonly [P in keyof Type as NewType]: Type[P]; }"; - "readonly [P in keyof Type as NewType]: Type[P]" - ); - - contains_test!(type_import_type, - "export function adopt(p: import(\"./module.ts\").Pet) { }"; - "import(\"./module.ts\").Pet" - ); - - contains_test!(interface_declaration, - "export interface Interface {}"; - "interface Interface" - ); - - contains_test!(interface_extends, - "export interface Interface extends Iterator {}"; - "interface Interface extends Iterator" - ); - - contains_test!(interface_extends2, - "export interface Interface extends Iterator, Iterable {}"; - "interface Interface extends Iterator, Iterable" - ); - - contains_test!(interface_generic, - "export interface Interface {}"; - "interface Interface" - ); - - contains_test!(interface_generic_extends, - "export interface Interface extends Iterable {}"; - "interface Interface extends Iterable" - ); - - contains_test!(interface_index_signature, - r#" -export interface Interface { - [index: number]: Interface; -} - "#; - "[index: number]: Interface" - ); - - contains_test!(interface_method, - r#" -export interface I { - m(a, b); - mo?(c); - [mc](d); -} - "#; - "m(a, b)", - "mo?(c)", - "[mc](d)" - ); - - contains_test!(interface_property, - r#" -export interface I { - p: string; - po?: number; - readonly pro: string; - [pc]: string; -} - "#; - "p: string", - "po?: number", - "readonly pro: string", - "[pc]: string" - ); - - contains_test!(interface_string_literal_property, - r#" -export interface I { - "p": string; - "po"?: number; -} - "#; - "p: string", - "po?: number" - ); - - contains_test!(interface_number_literal_property, - r#" -export interface I { - 1: string; - 2?: number; -} - "#; - "1: string", - "2?: number" - ); - - contains_test!(interface_readonly_index_signature, - r#" -export interface Interface { - readonly [index: number]: Interface; -} - "#; - "readonly [index: number]: Interface" - ); - - contains_test!(interface_construct, - r#" -export interface I { - new(name: string); -} - "#; - "new(name: string)" - ); - - contains_test!(jsdoc, - r#" -/** - * A is a class - * - * Nothing more - */ -export class A {} -/** - * B is an interface - * - * Should be - */ -export interface B {} -/** - * C is a function - * - * Summarised - */ -export function C() {} - "#; - "A is a class", - "B is an interface", - "C is a function", - "Nothing more", - "Should be", - "Summarised" - ); - - contains_test!(jsdoc_tags, - r#" -/** - * a is a function - * - * @param {string} b some doc - * @param [c=1] additional doc - * @param [d] more doc - * @returns {string} returning doc - */ -export function a(b, c, d) {} - "#; - "a is a function", - "@param {string} b", - "some doc", - "@param [1] c", - "additional doc", - "@param [?] d", - "more doc", - "@return {string}", - "returning doc" - ); - - contains_test!(namespace_declaration, - "export namespace Namespace {}"; - "namespace Namespace" - ); - - contains_test!(namespace_details, - r#" -export namespace Namespace { - /** - * Doc comment 1 - * - * Details 1 - */ - export function a() {} - /** - * Doc comment 2 - * - * Details 2 - */ - export class B {} -} - "#; - "namespace Namespace", - "function a()", - "class B", - "Doc comment 1", - "Doc comment 2", - "Details 1", - "Details 2" - ); - - contains_test!(namespace_fn_overloads, - r#" -export namespace Namespace { - export function a(b: string): string; - export function a(b: number): number; - export function a(b: number | string): number | string {} -} -"#; - "function a(b: string): string", - "function a(b: number): number"; - "function a(b: number | string): number | string" - ); - - contains_test!(type_alias, - "export type A = number"; - "type A = number" - ); - - contains_test!(type_generic_alias, - "export type A = T"; - "type A = T" - ); - - contains_test!(infer_ts_types, - r#" - export let s = "hello"; - export let n = 123; - export let b = false; - export let bi = 100n; - export let re = /hello/; - export let tpl = `foobar`; - "#; - "let s: string", - "let n: number", - "let b: boolean", - "let bi: bigint", - "let re: RegExp", - "let tpl: string" - ); - - contains_test!(infer_simple_ts_types, - r#" -export const s = "hello"; -export const n = 123; -export const b = false; -export const bi = 100n; -export const re = /hello/; -export const tpl = `foobar`; -export const d = new Date(); -export const s2 = String("foo"); -export const n2 = Number(100); -export const bi2 = BigInt(123); -export const sym = Symbol("hello"); -export const m = new Map(); -export const fn1 = (a: string): void => {}; -export const fn2 = function (a:string): void {}; -export const s3 = "VGhpcyBpcyBhIHJlYWxseSBsb25nIHN0cmluZyB0byB0cnkgdG8gZmluZCBvdXQgaWYgd2UgY2FuIHNraXAgaW5mZXJyaW5nIGEgcmVhbGx5IGxhcmdlIHZhbHVlIGZvciBhIGNvbnN0IHN0cmluZyB2YXJpYWJsZSB3aXRob3V0IGEgdHlwZSBhbm5vdGF0aW9uLg=="; - "#; - "const s: \"hello\"", - "const n: 123", - "const b: false", - "const bi: 100", - "const re: RegExp", - "const tpl: `foobar`", - "const d: Date", - "const s2: string", - "const n2: number", - "const bi2: bigint", - "const sym: symbol", - "const m: Map", - "const fn1: (a: string) => void", - "const fn2: (a: string) => void", - "const s3: string" - ); - - contains_test!(infer_simple_ts_arr_types, - r#" - export const a = [1]; - export const b = [true]; - export const c = ["c"]; - export const d = [2, "d"]; - export const e = [1, 2, 3]; - export const f = ["a", 1, e]; - export const g = ["a", 1, true] as const; - "#; - "const a: number[]", - "const b: boolean[]", - "const c: string[]", - "const d: (number | string)[]", - "const e: number[]", - "const f: any[]", - "const g: (\"a\" | 1 | true)[]" - ); - - contains_test!( - ts_template_with_args, - r#" -export const tpl: `test${number}` = `test1`; - "#; - "const tpl: `test${number}`" - ); - - contains_test!( - ts_user_defined_type_guards, - r#" -export function f1(val1: A | B): val1 is A {} -export function f2(val2: any): asserts val2 is string {} -export function f3(val3: any): asserts val3 {} -export function assertIsDefined(val4: T): asserts val4 is NonNullable { - if (val === undefined || val === null) { - throw new AssertionError( - `Expected 'val' to be defined, but received ${val}` - ); - } -} -export class C { - isSomething(): this is Something { - return this instanceof Something; - } -} - "#; - "val1 is A", - "asserts val2 is string", - "asserts val3", - "asserts val4 is NonNullable", - "this is Something" - ); - - contains_test!(import_equals, - "declare module Test { - export interface Options { - } -} - -import Options = Test.Options; - -export { Options };"; - "interface Options" - ); - - contains_test!(doc_printer_unsupported_tag, - r#" -/** - * @customtagone - * @customtagtwo value - */ -export function noop() { -} - "#; - " -function noop() - - @customtagone - @customtagtwo value -" - ); -} - fn create_analyzer() -> CapturingModuleAnalyzer { let source_parser = DefaultModuleParser::new_for_analysis(); CapturingModuleAnalyzer::new(Some(Box::new(source_parser)), None) diff --git a/tests/helpers/mod.rs b/tests/helpers/mod.rs new file mode 100644 index 00000000..6e2ac98a --- /dev/null +++ b/tests/helpers/mod.rs @@ -0,0 +1,187 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +use std::path::Path; +use std::path::PathBuf; + +mod test_builder; + +use deno_graph::ModuleSpecifier; +use indexmap::IndexMap; +use serde::de::DeserializeOwned; +use serde::Deserialize; +use serde::Serialize; +pub use test_builder::*; + +pub struct Spec { + pub private: bool, + pub files: Vec, + pub output_json_file: SpecFile, + pub output_doc_file: SpecFile, + pub diagnostics: Vec, +} + +impl Spec { + pub fn emit(&self) -> String { + let mut text = String::new(); + if self.private { + text.push_str("{ \"private\": true }\n"); + } + for file in &self.files { + text.push_str(&file.emit()); + text.push('\n'); + } + text.push_str(&self.output_doc_file.emit()); + text.push('\n'); + text.push_str(&self.output_json_file.emit()); + if !self.diagnostics.is_empty() { + text.push_str("\n# diagnostics\n"); + text.push_str(&serde_json::to_string_pretty(&self.diagnostics).unwrap()); + text.push('\n'); + } + text + } +} + +#[derive(Debug, Serialize, Deserialize)] +struct SpecOptions { + pub private: bool, +} + +#[derive(Debug)] +pub struct SpecFile { + pub specifier: String, + pub text: String, + pub headers: IndexMap, +} + +impl SpecFile { + pub fn emit(&self) -> String { + let mut text = format!("# {}\n", self.specifier); + if !self.headers.is_empty() { + text.push_str(&format!( + "HEADERS: {}\n", + serde_json::to_string(&self.headers).unwrap() + )); + } + text.push_str(&self.text); + text + } + + pub fn url(&self) -> ModuleSpecifier { + let specifier = &self.specifier; + if !specifier.starts_with("http") && !specifier.starts_with("file") { + ModuleSpecifier::parse(&format!("file:///{}", specifier)).unwrap() + } else { + ModuleSpecifier::parse(specifier).unwrap() + } + } +} + +pub fn get_specs_in_dir(path: &Path) -> Vec<(PathBuf, Spec)> { + let files = collect_files_in_dir_recursive(path); + let files = if files + .iter() + .any(|file| file.path.to_string_lossy().to_lowercase().contains("_only")) + { + files + .into_iter() + .filter(|file| { + file.path.to_string_lossy().to_lowercase().contains("_only") + }) + .collect() + } else { + files + }; + files + .into_iter() + .map(|file| (file.path, parse_spec(file.text))) + .collect() +} + +fn parse_spec(text: String) -> Spec { + let mut files = Vec::new(); + let mut current_file = None; + let mut options: Option = None; + for (i, line) in text.split('\n').enumerate() { + if i == 0 && line.starts_with('{') { + options = Some(serde_json::from_str(line).unwrap()); + continue; + } + if let Some(specifier) = line.strip_prefix("# ") { + if let Some(file) = current_file.take() { + files.push(file); + } + current_file = Some(SpecFile { + specifier: specifier.to_string(), + text: String::new(), + headers: Default::default(), + }); + } else if let Some(headers) = line.strip_prefix("HEADERS: ") { + current_file.as_mut().unwrap().headers = + serde_json::from_str(headers).unwrap(); + } else { + let current_file = current_file.as_mut().unwrap(); + if !current_file.text.is_empty() { + current_file.text.push('\n'); + } + current_file.text.push_str(line); + } + } + files.push(current_file.unwrap()); + let output_json_file = files.remove( + files + .iter() + .position(|f| f.specifier == "output.json") + .unwrap(), + ); + let output_doc_file = files.remove( + files + .iter() + .position(|f| f.specifier == "output.txt") + .unwrap(), + ); + let diagnostics = take_vec_file(&mut files, "diagnostics"); + Spec { + private: options.map(|o| o.private).unwrap_or(false), + files, + output_json_file, + output_doc_file, + diagnostics, + } +} + +fn take_vec_file( + files: &mut Vec, + name: &str, +) -> Vec { + if let Some(index) = files.iter().position(|f| f.specifier == name) { + let file = files.remove(index); + serde_json::from_str(&file.text).unwrap() + } else { + Vec::new() + } +} + +struct CollectedFile { + pub path: PathBuf, + pub text: String, +} + +fn collect_files_in_dir_recursive(path: &Path) -> Vec { + let mut result = Vec::new(); + + for entry in path.read_dir().unwrap().flatten() { + let entry_path = entry.path(); + if entry_path.is_file() { + let text = std::fs::read_to_string(&entry_path).unwrap(); + result.push(CollectedFile { + path: entry_path, + text, + }); + } else { + result.extend(collect_files_in_dir_recursive(&entry_path)); + } + } + + result +} diff --git a/tests/helpers/test_builder.rs b/tests/helpers/test_builder.rs new file mode 100644 index 00000000..09d8c0ff --- /dev/null +++ b/tests/helpers/test_builder.rs @@ -0,0 +1,81 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +use deno_ast::ModuleSpecifier; +use deno_doc::DocDiagnostic; +use deno_doc::DocParser; +use deno_doc::DocPrinter; +use deno_graph::source::MemoryLoader; +use deno_graph::BuildOptions; +use deno_graph::CapturingModuleAnalyzer; +use deno_graph::DefaultModuleParser; +use deno_graph::GraphKind; + +pub struct BuildResult { + pub json_output: serde_json::Value, + pub text_output: String, + pub diagnostics: Vec, +} + +pub struct TestBuilder { + loader: MemoryLoader, + private: bool, + entry_point: String, +} + +impl TestBuilder { + pub fn new() -> Self { + Self { + private: false, + loader: Default::default(), + entry_point: "file:///mod.ts".to_string(), + } + } + + pub fn with_loader( + &mut self, + mut action: impl FnMut(&mut MemoryLoader), + ) -> &mut Self { + action(&mut self.loader); + self + } + + pub fn set_private(&mut self, value: bool) -> &mut Self { + self.private = value; + self + } + + pub async fn build(&mut self) -> BuildResult { + let analyzer = create_analyzer(); + let mut graph = deno_graph::ModuleGraph::new(GraphKind::TypesOnly); + let entry_point_url = ModuleSpecifier::parse(&self.entry_point).unwrap(); + let roots = vec![entry_point_url.clone()]; + graph + .build( + roots.clone(), + &mut self.loader, + BuildOptions { + module_analyzer: Some(&analyzer), + ..Default::default() + }, + ) + .await; + let parser = + DocParser::new(&graph, self.private, analyzer.as_capturing_parser()) + .unwrap(); + let entries = parser.parse(&entry_point_url).unwrap(); + + let doc = DocPrinter::new(&entries, false, self.private).to_string(); + let diagnostics = parser.diagnostics(); + + BuildResult { + diagnostics, + json_output: serde_json::to_value(entries).unwrap(), + text_output: doc, + } + } +} + +fn create_analyzer() -> CapturingModuleAnalyzer { + let source_parser = DefaultModuleParser::new_for_analysis(); + CapturingModuleAnalyzer::new(Some(Box::new(source_parser)), None) +} diff --git a/tests/integration_test.rs b/tests/integration_test.rs new file mode 100644 index 00000000..c9d94b95 --- /dev/null +++ b/tests/integration_test.rs @@ -0,0 +1,79 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +use std::path::PathBuf; + +use deno_graph::source::Source; +use pretty_assertions::assert_eq; + +use crate::helpers::get_specs_in_dir; +use crate::helpers::TestBuilder; + +mod helpers; + +#[tokio::test] +async fn test_doc_specs() { + // run tests with `UPDATE=1` to automatically update the spec files + for (test_file_path, spec) in + get_specs_in_dir(&PathBuf::from("./tests/specs/")) + { + eprintln!("Running {}", test_file_path.display()); + let mut builder = TestBuilder::new(); + builder + .with_loader(|loader| { + for file in &spec.files { + let source = Source::Module { + specifier: file.url().to_string(), + maybe_headers: Some(file.headers.clone().into_iter().collect()), + content: file.text.clone(), + }; + loader.add_source(file.url(), source); + } + }) + .set_private(spec.private); + + let result = builder.build().await; + let update_var = std::env::var("UPDATE"); + let mut json_output = + serde_json::to_string_pretty(&result.json_output).unwrap(); + json_output.push('\n'); + let diagnostics = result + .diagnostics + .iter() + .map(|d| { + serde_json::to_value(serde_json::json!({ + "location": d.location, + "kind": d.kind.to_string(), + })) + .unwrap() + }) + .collect::>(); + let spec = if update_var.as_ref().map(|v| v.as_str()) == Ok("1") { + let mut spec = spec; + spec.output_json_file.text = json_output.clone(); + spec.output_doc_file.text = result.text_output.clone(); + spec.diagnostics = diagnostics.clone(); + std::fs::write(&test_file_path, spec.emit()).unwrap(); + spec + } else { + spec + }; + assert_eq!( + result.text_output, + spec.output_doc_file.text, + "Should be same for doc output {}", + test_file_path.display() + ); + assert_eq!( + json_output, + spec.output_json_file.text, + "Should be same for json output {}", + test_file_path.display() + ); + assert_eq!( + diagnostics, + spec.diagnostics, + "Should be same for {}", + test_file_path.display() + ); + } +} diff --git a/tests/specs/AbstractClass.txt b/tests/specs/AbstractClass.txt new file mode 100644 index 00000000..4e6308da --- /dev/null +++ b/tests/specs/AbstractClass.txt @@ -0,0 +1,34 @@ +# mod.ts +export abstract class Class {} + +# output.txt +Defined in file:///mod.ts:1:1 + +abstract class Class + + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": true, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/AbstractClassAbstractMethod.txt b/tests/specs/AbstractClassAbstractMethod.txt new file mode 100644 index 00000000..b59f8765 --- /dev/null +++ b/tests/specs/AbstractClassAbstractMethod.txt @@ -0,0 +1,59 @@ +# mod.ts +export abstract class Class { + abstract method() {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +abstract class Class + + abstract method() + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": true, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": true, + "isStatic": false, + "name": "method", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassAsyncMethod.txt b/tests/specs/ClassAsyncMethod.txt new file mode 100644 index 00000000..0f6bd67b --- /dev/null +++ b/tests/specs/ClassAsyncMethod.txt @@ -0,0 +1,66 @@ +# mod.ts +export class Class { + async amethod(v) {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + async amethod(v) + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "amethod", + "kind": "method", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "v", + "optional": false, + "tsType": null + } + ], + "returnType": null, + "hasBody": true, + "isAsync": true, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassConstructor.txt b/tests/specs/ClassConstructor.txt new file mode 100644 index 00000000..309e5c05 --- /dev/null +++ b/tests/specs/ClassConstructor.txt @@ -0,0 +1,64 @@ +# mod.ts +export class Class { + constructor(public a, readonly b) {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + constructor(public a, readonly b) + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [ + { + "accessibility": null, + "hasBody": true, + "name": "constructor", + "params": [ + { + "accessibility": "public", + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": null + }, + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": null, + "readonly": true + } + ], + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassDeclaration.txt b/tests/specs/ClassDeclaration.txt new file mode 100644 index 00000000..10f696e5 --- /dev/null +++ b/tests/specs/ClassDeclaration.txt @@ -0,0 +1,34 @@ +# mod.ts +export class Class {} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassDecorators.txt b/tests/specs/ClassDecorators.txt new file mode 100644 index 00000000..a394583a --- /dev/null +++ b/tests/specs/ClassDecorators.txt @@ -0,0 +1,168 @@ +# mod.ts +@sealed +export class A { + #x = "x"; + + @format("Hello, %s") + greeting: string; + + @configurable(false) + get x() { + return this.#x; + } + + @enumerable(false) + greet() { + return "hello"; + } +} + +# output.txt +Defined in file:///mod.ts:2:1 + +@sealed +class A + + @format("Hello, %s") + greeting: string + @configurable(false) + get x() + @enumerable(false) + greet() + + +# output.json +[ + { + "kind": "class", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": false, + "accessibility": null, + "decorators": [ + { + "name": "format", + "args": [ + "\"Hello, %s\"" + ], + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 3 + } + } + ], + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "greeting", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "x", + "kind": "getter", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [], + "decorators": [ + { + "name": "configurable", + "args": [ + "false" + ], + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 3 + } + } + ] + }, + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 2 + } + }, + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "greet", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [], + "decorators": [ + { + "name": "enumerable", + "args": [ + "false" + ], + "location": { + "filename": "file:///mod.ts", + "line": 13, + "col": 3 + } + } + ] + }, + "location": { + "filename": "file:///mod.ts", + "line": 13, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [], + "decorators": [ + { + "name": "sealed", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 1 + } + } + ] + } + } +] diff --git a/tests/specs/ClassDetails.txt b/tests/specs/ClassDetails.txt new file mode 100644 index 00000000..c8e37b82 --- /dev/null +++ b/tests/specs/ClassDetails.txt @@ -0,0 +1,85 @@ +# mod.ts +export class C { + /** a doc */ + a() {} + f: number; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class C + + f: number + a() + a doc + + +# output.json +[ + { + "kind": "class", + "name": "C", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "f", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [ + { + "jsDoc": { + "doc": "a doc" + }, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "a", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassDetailsAllWithPrivate.txt b/tests/specs/ClassDetailsAllWithPrivate.txt new file mode 100644 index 00000000..f1961276 --- /dev/null +++ b/tests/specs/ClassDetailsAllWithPrivate.txt @@ -0,0 +1,106 @@ +{ "private": true } +# mod.ts +export class Class { + private pri() {} + protected pro() {} + public pub() {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + private pri() + protected pro() + pub() + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [ + { + "accessibility": "private", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "pri", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + }, + { + "accessibility": "protected", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "pro", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + } + }, + { + "accessibility": "public", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "pub", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassDetailsOnlyNonPrivateWithoutPrivate.txt b/tests/specs/ClassDetailsOnlyNonPrivateWithoutPrivate.txt new file mode 100644 index 00000000..1147a41f --- /dev/null +++ b/tests/specs/ClassDetailsOnlyNonPrivateWithoutPrivate.txt @@ -0,0 +1,104 @@ +# mod.ts +export class Class { + private pri() {} + protected pro() {} + public pub() {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + protected pro() + pub() + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [ + { + "accessibility": "private", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "pri", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + }, + { + "accessibility": "protected", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "pro", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + } + }, + { + "accessibility": "public", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "pub", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassExtends.txt b/tests/specs/ClassExtends.txt new file mode 100644 index 00000000..96d4e859 --- /dev/null +++ b/tests/specs/ClassExtends.txt @@ -0,0 +1,34 @@ +# mod.ts +export class Class extends Object {} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class extends Object + + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": "Object", + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassExtendsImplements.txt b/tests/specs/ClassExtendsImplements.txt new file mode 100644 index 00000000..7c9c1ca7 --- /dev/null +++ b/tests/specs/ClassExtendsImplements.txt @@ -0,0 +1,51 @@ +# mod.ts +export class Class extends Object implements Iterator, Iterable {} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class extends Object implements Iterator, Iterable + + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": "Object", + "implements": [ + { + "repr": "Iterator", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Iterator" + } + }, + { + "repr": "Iterable", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Iterable" + } + } + ], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassGenericExtendsImplements.txt b/tests/specs/ClassGenericExtendsImplements.txt new file mode 100644 index 00000000..441022c3 --- /dev/null +++ b/tests/specs/ClassGenericExtendsImplements.txt @@ -0,0 +1,93 @@ +# mod.ts +export class Class extends Map implements Iterator, Iterable {} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class extends Map implements Iterator, Iterable + + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": "Map", + "implements": [ + { + "repr": "Iterator", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "A", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "A" + } + } + ], + "typeName": "Iterator" + } + }, + { + "repr": "Iterable", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "B", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "B" + } + } + ], + "typeName": "Iterable" + } + } + ], + "typeParams": [ + { + "name": "A" + }, + { + "name": "B" + } + ], + "superTypeParams": [ + { + "repr": "A", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "A" + } + }, + { + "repr": "B", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "B" + } + } + ] + } + } +] diff --git a/tests/specs/ClassGetterAndSetter.txt b/tests/specs/ClassGetterAndSetter.txt new file mode 100644 index 00000000..b8650081 --- /dev/null +++ b/tests/specs/ClassGetterAndSetter.txt @@ -0,0 +1,97 @@ +# mod.ts +export class Class { + get a(): void {} + set b(_v: void) {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + get a(): void + set b(_v: void) + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "a", + "kind": "getter", + "functionDef": { + "params": [], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + }, + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "b", + "kind": "setter", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "_v", + "optional": false, + "tsType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + } + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassImplements.txt b/tests/specs/ClassImplements.txt new file mode 100644 index 00000000..f552fbcb --- /dev/null +++ b/tests/specs/ClassImplements.txt @@ -0,0 +1,43 @@ +# mod.ts +export class Class implements Iterator {} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class implements Iterator + + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [ + { + "repr": "Iterator", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Iterator" + } + } + ], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassImplements2.txt b/tests/specs/ClassImplements2.txt new file mode 100644 index 00000000..148c308a --- /dev/null +++ b/tests/specs/ClassImplements2.txt @@ -0,0 +1,51 @@ +# mod.ts +export class Class implements Iterator, Iterable {} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class implements Iterator, Iterable + + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [ + { + "repr": "Iterator", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Iterator" + } + }, + { + "repr": "Iterable", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Iterable" + } + } + ], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassIndexSignature.txt b/tests/specs/ClassIndexSignature.txt new file mode 100644 index 00000000..99c5f287 --- /dev/null +++ b/tests/specs/ClassIndexSignature.txt @@ -0,0 +1,63 @@ +# mod.ts +export class C { + [key: string]: number; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class C + + [key: string]: number + + +# output.json +[ + { + "kind": "class", + "name": "C", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [ + { + "readonly": false, + "params": [ + { + "kind": "identifier", + "name": "key", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassMethod.txt b/tests/specs/ClassMethod.txt new file mode 100644 index 00000000..eed66f6a --- /dev/null +++ b/tests/specs/ClassMethod.txt @@ -0,0 +1,66 @@ +# mod.ts +export class Class { + method(v) {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + method(v) + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "method", + "kind": "method", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "v", + "optional": false, + "tsType": null + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassMethodOverloads.txt b/tests/specs/ClassMethodOverloads.txt new file mode 100644 index 00000000..69f4e223 --- /dev/null +++ b/tests/specs/ClassMethodOverloads.txt @@ -0,0 +1,169 @@ +# mod.ts +export class A { + a(b: string): string; + a(b: number): number; + a(b: string | number): string | number {} + } + +# output.txt +Defined in file:///mod.ts:1:1 + +class A + + a(b: string): string + a(b: number): number + + +# output.json +[ + { + "kind": "class", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "a", + "kind": "method", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "returnType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 6 + } + }, + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "a", + "kind": "method", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "returnType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 6 + } + }, + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "a", + "kind": "method", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ] + } + } + ], + "returnType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ] + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 6 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassOverridePropMethod.txt b/tests/specs/ClassOverridePropMethod.txt new file mode 100644 index 00000000..18c69821 --- /dev/null +++ b/tests/specs/ClassOverridePropMethod.txt @@ -0,0 +1,86 @@ +# mod.ts +export class C extends B { + override a(): void {} + override b: string; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class C extends B + + override b: string + override a(): void + + +# output.json +[ + { + "kind": "class", + "name": "C", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "isOverride": true, + "name": "b", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "isOverride": true, + "name": "a", + "kind": "method", + "functionDef": { + "params": [], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "extends": "B", + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassPrivateProperty.txt b/tests/specs/ClassPrivateProperty.txt new file mode 100644 index 00000000..e74a539f --- /dev/null +++ b/tests/specs/ClassPrivateProperty.txt @@ -0,0 +1,57 @@ +{ "private": true } +# mod.ts +export class Class { + private property = ""; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + private property: string + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": false, + "accessibility": "private", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "property", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassProperty.txt b/tests/specs/ClassProperty.txt new file mode 100644 index 00000000..a11da19e --- /dev/null +++ b/tests/specs/ClassProperty.txt @@ -0,0 +1,79 @@ +# mod.ts +export class Class { + someproperty: bool; + optproperty: bigint; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + someproperty: bool + optproperty: bigint + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "bool", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "bool" + } + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "someproperty", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + }, + { + "tsType": { + "repr": "bigint", + "kind": "keyword", + "keyword": "bigint" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "optproperty", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassReadonlyIndexSignature.txt b/tests/specs/ClassReadonlyIndexSignature.txt new file mode 100644 index 00000000..da071308 --- /dev/null +++ b/tests/specs/ClassReadonlyIndexSignature.txt @@ -0,0 +1,63 @@ +# mod.ts +export class C { + readonly [key: string]: number; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class C + + readonly [key: string]: number + + +# output.json +[ + { + "kind": "class", + "name": "C", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [ + { + "readonly": true, + "params": [ + { + "kind": "identifier", + "name": "key", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassReadonlyProperty.txt b/tests/specs/ClassReadonlyProperty.txt new file mode 100644 index 00000000..3992e620 --- /dev/null +++ b/tests/specs/ClassReadonlyProperty.txt @@ -0,0 +1,56 @@ +# mod.ts +export class Class { + readonly property = ""; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + readonly property: string + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": true, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "property", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ClassStaticProperty.txt b/tests/specs/ClassStaticProperty.txt new file mode 100644 index 00000000..74041593 --- /dev/null +++ b/tests/specs/ClassStaticProperty.txt @@ -0,0 +1,56 @@ +# mod.ts +export class Class { + static property = ""; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class Class + + static property: string + + +# output.json +[ + { + "kind": "class", + "name": "Class", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": true, + "name": "property", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ConstDeclaration.txt b/tests/specs/ConstDeclaration.txt new file mode 100644 index 00000000..6954fb80 --- /dev/null +++ b/tests/specs/ConstDeclaration.txt @@ -0,0 +1,33 @@ +# mod.ts +export const Const = 0; + +# output.txt +Defined in file:///mod.ts:1:14 + +const Const: 0 + + +# output.json +[ + { + "kind": "variable", + "name": "Const", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "0", + "kind": "literal", + "literal": { + "kind": "number", + "number": 0.0 + } + }, + "kind": "const" + } + } +] diff --git a/tests/specs/CtorOverloads.txt b/tests/specs/CtorOverloads.txt new file mode 100644 index 00000000..b03b2628 --- /dev/null +++ b/tests/specs/CtorOverloads.txt @@ -0,0 +1,118 @@ +# mod.ts +export class A { + constructor (a: string); + constructor (a: number); + constructor (a: string | number) { + // + } +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class A + + constructor(a: string) + constructor(a: number) + + +# output.json +[ + { + "kind": "class", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [ + { + "accessibility": null, + "name": "constructor", + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + }, + { + "accessibility": null, + "name": "constructor", + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + } + }, + { + "accessibility": null, + "hasBody": true, + "name": "constructor", + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ] + } + } + ], + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + } + } + ], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/DeclareNamespace.txt b/tests/specs/DeclareNamespace.txt new file mode 100644 index 00000000..593ae8be --- /dev/null +++ b/tests/specs/DeclareNamespace.txt @@ -0,0 +1,146 @@ +# mod.ts +/** Namespace JSdoc */ +declare namespace RootNs { + declare const a = "a"; + + /** Nested namespace JSDoc */ + declare namespace NestedNs { + declare enum Foo { + a = 1, + b = 2, + c = 3, + } + } +} + +# output.txt +Defined in file:///mod.ts:2:1 + +namespace RootNs + Namespace JSdoc + + const a: "a" + namespace NestedNs + Nested namespace JSDoc + + +# output.json +[ + { + "kind": "namespace", + "name": "RootNs", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "declare", + "jsDoc": { + "doc": "Namespace JSdoc" + }, + "namespaceDef": { + "elements": [ + { + "kind": "variable", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 18 + }, + "declarationKind": "declare", + "variableDef": { + "tsType": { + "repr": "a", + "kind": "literal", + "literal": { + "kind": "string", + "string": "a" + } + }, + "kind": "const" + } + }, + { + "kind": "namespace", + "name": "NestedNs", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 4 + }, + "declarationKind": "declare", + "jsDoc": { + "doc": "Nested namespace JSDoc" + }, + "namespaceDef": { + "elements": [ + { + "kind": "enum", + "name": "Foo", + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 6 + }, + "declarationKind": "declare", + "enumDef": { + "members": [ + { + "name": "a", + "init": { + "repr": "1", + "kind": "literal", + "literal": { + "kind": "number", + "number": 1.0 + } + }, + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 8 + } + }, + { + "name": "b", + "init": { + "repr": "2", + "kind": "literal", + "literal": { + "kind": "number", + "number": 2.0 + } + }, + "location": { + "filename": "file:///mod.ts", + "line": 9, + "col": 8 + } + }, + { + "name": "c", + "init": { + "repr": "3", + "kind": "literal", + "literal": { + "kind": "number", + "number": 3.0 + } + }, + "location": { + "filename": "file:///mod.ts", + "line": 10, + "col": 8 + } + } + ] + } + } + ] + } + } + ] + } + } +] diff --git a/tests/specs/DeclareNamespaceIgnore.txt b/tests/specs/DeclareNamespaceIgnore.txt new file mode 100644 index 00000000..b8094b6d --- /dev/null +++ b/tests/specs/DeclareNamespaceIgnore.txt @@ -0,0 +1,67 @@ +# mod.ts +/** Namespace JSdoc */ +declare namespace RootNs { + declare const a = "a"; + + /** Nested namespace JSDoc + * @ignore + */ + declare namespace NestedNs { + declare enum Foo { + a = 1, + b = 2, + c = 3, + } + } +} + +# output.txt +Defined in file:///mod.ts:2:1 + +namespace RootNs + Namespace JSdoc + + const a: "a" + + +# output.json +[ + { + "kind": "namespace", + "name": "RootNs", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "declare", + "jsDoc": { + "doc": "Namespace JSdoc" + }, + "namespaceDef": { + "elements": [ + { + "kind": "variable", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 18 + }, + "declarationKind": "declare", + "variableDef": { + "tsType": { + "repr": "a", + "kind": "literal", + "literal": { + "kind": "string", + "string": "a" + } + }, + "kind": "const" + } + } + ] + } + } +] diff --git a/tests/specs/DecoratorsJsdoc.txt b/tests/specs/DecoratorsJsdoc.txt new file mode 100644 index 00000000..f0f88117 --- /dev/null +++ b/tests/specs/DecoratorsJsdoc.txt @@ -0,0 +1,73 @@ +# mod.ts +/** jsdoc */ +@sealed +export class A { + a: string = "a"; +} + +# output.txt +Defined in file:///mod.ts:3:1 + +@sealed +class A + jsdoc + + a: string + + +# output.json +[ + { + "kind": "class", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "jsdoc" + }, + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [], + "decorators": [ + { + "name": "sealed", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 1 + } + } + ] + } + } +] diff --git a/tests/specs/DefaultExportsDeclaredEarlier.txt b/tests/specs/DefaultExportsDeclaredEarlier.txt new file mode 100644 index 00000000..18190c12 --- /dev/null +++ b/tests/specs/DefaultExportsDeclaredEarlier.txt @@ -0,0 +1,35 @@ +# mod.ts +function foo(): void {} +export default foo; + +# output.txt +Defined in file:///mod.ts:1:1 + +function default(): void + + +# output.json +[ + { + "kind": "function", + "name": "default", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/DocPrinterUnsupportedTag.txt b/tests/specs/DocPrinterUnsupportedTag.txt new file mode 100644 index 00000000..75669748 --- /dev/null +++ b/tests/specs/DocPrinterUnsupportedTag.txt @@ -0,0 +1,50 @@ +# mod.ts +/** + * @customtagone + * @customtagtwo value + */ +export function noop() { +} + +# output.txt +Defined in file:///mod.ts:5:1 + +function noop() + + @customtagone + @customtagtwo value + + +# output.json +[ + { + "kind": "function", + "name": "noop", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "tags": [ + { + "kind": "unsupported", + "value": "@customtagone" + }, + { + "kind": "unsupported", + "value": "@customtagtwo value" + } + ] + }, + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/EnumDeclaration.txt b/tests/specs/EnumDeclaration.txt new file mode 100644 index 00000000..58d807fe --- /dev/null +++ b/tests/specs/EnumDeclaration.txt @@ -0,0 +1,26 @@ +# mod.ts +export enum Enum {} + +# output.txt +Defined in file:///mod.ts:1:1 + +enum Enum + + + +# output.json +[ + { + "kind": "enum", + "name": "Enum", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "enumDef": { + "members": [] + } + } +] diff --git a/tests/specs/EnumMember.txt b/tests/specs/EnumMember.txt new file mode 100644 index 00000000..dd7bf5a9 --- /dev/null +++ b/tests/specs/EnumMember.txt @@ -0,0 +1,53 @@ +# mod.ts +export enum Enum { + First, + /** There is a JsDoc */ + Second, +} + +# output.txt +Defined in file:///mod.ts:1:1 + +enum Enum + + First + Second + There is a JsDoc + + +# output.json +[ + { + "kind": "enum", + "name": "Enum", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "enumDef": { + "members": [ + { + "name": "First", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + }, + { + "name": "Second", + "jsDoc": { + "doc": "There is a JsDoc" + }, + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + } + } + ] + } + } +] diff --git a/tests/specs/ExportClass.txt b/tests/specs/ExportClass.txt new file mode 100644 index 00000000..d1099104 --- /dev/null +++ b/tests/specs/ExportClass.txt @@ -0,0 +1,480 @@ +# mod.ts +/** Class doc */ +export class Foobar extends Fizz implements Buzz, Aldrin { + private private1?: boolean; + protected protected1: number; + public public1: boolean; + public2: number; + override public3: string; + m = new Map(); + s = "foo"; + a = [1, "foo"]; + fn = (a: string): void => {}; + + /** Test */ + [prop: string]: number; + /** @ignore */ + [prop: number]: number; + + /** Constructor js doc */ + constructor(name: string, private private2: number, protected protected2: number) {} + + /** Async foo method */ + async foo(): Promise { + // + } + + /** Sync bar method */ + bar?(): void { + // + } + + override s() {} +} + +# output.txt +Defined in file:///mod.ts:2:1 + +class Foobar extends Fizz implements Buzz, Aldrin + Class doc + + constructor(name: string, private private2: number, protected protected2: number) + Constructor js doc + protected protected1: number + public1: boolean + public2: number + override public3: string + m: Map + s: string + a: (number | string)[] + fn: (a: string) => void + [prop: string]: number + async foo(): Promise + Async foo method + bar?(): void + Sync bar method + override s() + + +# output.json +[ + { + "kind": "class", + "name": "Foobar", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Class doc" + }, + "classDef": { + "isAbstract": false, + "constructors": [ + { + "jsDoc": { + "doc": "Constructor js doc" + }, + "accessibility": null, + "hasBody": true, + "name": "constructor", + "params": [ + { + "kind": "identifier", + "name": "name", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + }, + { + "accessibility": "private", + "kind": "identifier", + "name": "private2", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + }, + { + "accessibility": "protected", + "kind": "identifier", + "name": "protected2", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "location": { + "filename": "file:///mod.ts", + "line": 19, + "col": 4 + } + } + ], + "properties": [ + { + "tsType": { + "repr": "boolean", + "kind": "keyword", + "keyword": "boolean" + }, + "readonly": false, + "accessibility": "private", + "optional": true, + "isAbstract": false, + "isStatic": false, + "name": "private1", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 4 + } + }, + { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "readonly": false, + "accessibility": "protected", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "protected1", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 4 + } + }, + { + "tsType": { + "repr": "boolean", + "kind": "keyword", + "keyword": "boolean" + }, + "readonly": false, + "accessibility": "public", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "public1", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 4 + } + }, + { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "public2", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 4 + } + }, + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "isOverride": true, + "name": "public3", + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 4 + } + }, + { + "tsType": { + "repr": "Map", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + ], + "typeName": "Map" + } + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "m", + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 4 + } + }, + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "s", + "location": { + "filename": "file:///mod.ts", + "line": 9, + "col": 4 + } + }, + { + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + ] + } + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 10, + "col": 4 + } + }, + { + "tsType": { + "repr": "", + "kind": "fnOrConstructor", + "fnOrConstructor": { + "constructor": false, + "tsType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "typeParams": [] + } + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "fn", + "location": { + "filename": "file:///mod.ts", + "line": 11, + "col": 4 + } + } + ], + "indexSignatures": [ + { + "jsDoc": { + "doc": "Test" + }, + "readonly": false, + "params": [ + { + "kind": "identifier", + "name": "prop", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "location": { + "filename": "file:///mod.ts", + "line": 14, + "col": 4 + } + } + ], + "methods": [ + { + "jsDoc": { + "doc": "Async foo method" + }, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "foo", + "kind": "method", + "functionDef": { + "params": [], + "returnType": { + "repr": "Promise", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "void", + "kind": "keyword", + "keyword": "void" + } + ], + "typeName": "Promise" + } + }, + "hasBody": true, + "isAsync": true, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 22, + "col": 4 + } + }, + { + "jsDoc": { + "doc": "Sync bar method" + }, + "accessibility": null, + "optional": true, + "isAbstract": false, + "isStatic": false, + "name": "bar", + "kind": "method", + "functionDef": { + "params": [], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 27, + "col": 4 + } + }, + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "isOverride": true, + "name": "s", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 31, + "col": 4 + } + } + ], + "extends": "Fizz", + "implements": [ + { + "repr": "Buzz", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Buzz" + } + }, + { + "repr": "Aldrin", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Aldrin" + } + } + ], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ExportClassCtorProperties.txt b/tests/specs/ExportClassCtorProperties.txt new file mode 100644 index 00000000..313b0120 --- /dev/null +++ b/tests/specs/ExportClassCtorProperties.txt @@ -0,0 +1,85 @@ +# mod.ts +export class A { + constructor(public readonly name: string, private private: number, public override public: boolean) {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class A + + constructor(public readonly name: string, private private: number, override public public: boolean) + + +# output.json +[ + { + "kind": "class", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [ + { + "accessibility": null, + "hasBody": true, + "name": "constructor", + "params": [ + { + "accessibility": "public", + "kind": "identifier", + "name": "name", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": true + }, + { + "accessibility": "private", + "kind": "identifier", + "name": "private", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + }, + { + "accessibility": "public", + "isOverride": true, + "kind": "identifier", + "name": "public", + "optional": false, + "tsType": { + "repr": "boolean", + "kind": "keyword", + "keyword": "boolean" + } + } + ], + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ExportClassDecorators.txt b/tests/specs/ExportClassDecorators.txt new file mode 100644 index 00000000..0983603c --- /dev/null +++ b/tests/specs/ExportClassDecorators.txt @@ -0,0 +1,213 @@ +# mod.ts +@sealed +export class A { + #x = "x"; + + @format("Hello, %s") + greeting: string; + + @configurable(false) + get x() { + return this.#x; + } + + @enumerable(false) + greet() { + return "hello"; + } + + method(@readonly param: string) {} +} + +# output.txt +Defined in file:///mod.ts:2:1 + +@sealed +class A + + @format("Hello, %s") + greeting: string + @configurable(false) + get x() + @enumerable(false) + greet() + method(@readonly param: string) + + +# output.json +[ + { + "kind": "class", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": false, + "accessibility": null, + "decorators": [ + { + "name": "format", + "args": [ + "\"Hello, %s\"" + ], + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 3 + } + } + ], + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "greeting", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "x", + "kind": "getter", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [], + "decorators": [ + { + "name": "configurable", + "args": [ + "false" + ], + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 3 + } + } + ] + }, + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 2 + } + }, + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "greet", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [], + "decorators": [ + { + "name": "enumerable", + "args": [ + "false" + ], + "location": { + "filename": "file:///mod.ts", + "line": 13, + "col": 3 + } + } + ] + }, + "location": { + "filename": "file:///mod.ts", + "line": 13, + "col": 2 + } + }, + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "method", + "kind": "method", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "param", + "optional": false, + "decorators": [ + { + "name": "readonly", + "location": { + "filename": "file:///mod.ts", + "line": 18, + "col": 10 + } + } + ], + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 18, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [], + "decorators": [ + { + "name": "sealed", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 1 + } + } + ] + } + } +] diff --git a/tests/specs/ExportClassIgnore.txt b/tests/specs/ExportClassIgnore.txt new file mode 100644 index 00000000..5e8a9fd2 --- /dev/null +++ b/tests/specs/ExportClassIgnore.txt @@ -0,0 +1,220 @@ +# mod.ts +/** Class doc */ +export class Foobar extends Fizz implements Buzz, Aldrin { + /** @ignore */ + private private1?: boolean; + protected protected1: number; + /** @ignore */ + public public1: boolean; + public2: number; + /** @ignore */ + override public3: string; + /** @ignore */ + m = new Map(); + s = "foo"; + a = [1, "foo"]; + fn = (a: string): void => {}; + + /** Constructor js doc */ + /** @ignore */ + constructor(name: string, private private2: number, protected protected2: number) {} + + /** Async foo method */ + /** @ignore */ + async foo(): Promise { + // + } + + /** Sync bar method */ + /** @ignore */ + bar?(): void { + // + } + + /** @ignore */ + override s() {} +} + +# output.txt +Defined in file:///mod.ts:2:1 + +class Foobar extends Fizz implements Buzz, Aldrin + Class doc + + protected protected1: number + public2: number + s: string + a: (number | string)[] + fn: (a: string) => void + + +# output.json +[ + { + "kind": "class", + "name": "Foobar", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Class doc" + }, + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [ + { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "readonly": false, + "accessibility": "protected", + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "protected1", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 4 + } + }, + { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "public2", + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 4 + } + }, + { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "s", + "location": { + "filename": "file:///mod.ts", + "line": 13, + "col": 4 + } + }, + { + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + ] + } + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 14, + "col": 4 + } + }, + { + "tsType": { + "repr": "", + "kind": "fnOrConstructor", + "fnOrConstructor": { + "constructor": false, + "tsType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "typeParams": [] + } + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "fn", + "location": { + "filename": "file:///mod.ts", + "line": 15, + "col": 4 + } + } + ], + "indexSignatures": [], + "methods": [], + "extends": "Fizz", + "implements": [ + { + "repr": "Buzz", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Buzz" + } + }, + { + "repr": "Aldrin", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Aldrin" + } + } + ], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ExportClassObjectExtends.txt b/tests/specs/ExportClassObjectExtends.txt new file mode 100644 index 00000000..2e0953f5 --- /dev/null +++ b/tests/specs/ExportClassObjectExtends.txt @@ -0,0 +1,85 @@ +# mod.ts +class Foo {} +const obj = { Foo } + +export class Bar extends obj.Foo {} + +# output.txt +Defined in file:///mod.ts:2:7 + +private const obj: { Foo; } + +Defined in file:///mod.ts:4:1 + +class Bar extends obj.Foo + + + +# output.json +[ + { + "kind": "class", + "name": "Bar", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": "obj.Foo", + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + }, + { + "kind": "variable", + "name": "obj", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 6 + }, + "declarationKind": "private", + "variableDef": { + "tsType": { + "repr": "", + "kind": "typeLiteral", + "typeLiteral": { + "methods": [], + "properties": [ + { + "name": "Foo", + "params": [], + "computed": false, + "optional": false, + "tsType": null, + "typeParams": [] + } + ], + "callSignatures": [], + "indexSignatures": [] + } + }, + "kind": "const" + } + } +] + +# diagnostics +[ + { + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 6 + }, + "kind": "Type is not exported, but referenced by an exported type." + } +] diff --git a/tests/specs/ExportConstBasic.txt b/tests/specs/ExportConstBasic.txt new file mode 100644 index 00000000..87a3a49d --- /dev/null +++ b/tests/specs/ExportConstBasic.txt @@ -0,0 +1,332 @@ +# mod.ts +/** Something about fizzBuzz */ +export const fizzBuzz = "fizzBuzz"; + +export const env: { + /** get doc */ + get(key: string): string | undefined; + + /** set doc */ + set(key: string, value: string): void; +} + +export const num = 100; +export const bool = false; +export const bigint = 123n; +export const regex = /hello/; +export const date = new Date(); +export const tpl1 = `foo`; +export const tpl2 = `Value: ${num}`; +/** @ignore */ +export const tpl3 = `Value: ${num}`; + +# output.txt +Defined in file:///mod.ts:14:14 + +const bigint: 123 + +Defined in file:///mod.ts:13:14 + +const bool: false + +Defined in file:///mod.ts:16:14 + +const date: Date + +Defined in file:///mod.ts:4:14 + +const env: { get(key: string): string | undefined; set(key: string, value: string): void; } + +Defined in file:///mod.ts:2:14 + +const fizzBuzz: "fizzBuzz" + Something about fizzBuzz + +Defined in file:///mod.ts:12:14 + +const num: 100 + +Defined in file:///mod.ts:15:14 + +const regex: RegExp + +Defined in file:///mod.ts:17:14 + +const tpl1: `foo` + +Defined in file:///mod.ts:18:14 + +const tpl2: string + + +# output.json +[ + { + "kind": "variable", + "name": "fizzBuzz", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 13 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Something about fizzBuzz" + }, + "variableDef": { + "tsType": { + "repr": "fizzBuzz", + "kind": "literal", + "literal": { + "kind": "string", + "string": "fizzBuzz" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "env", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "typeLiteral", + "typeLiteral": { + "methods": [ + { + "name": "get", + "kind": "method", + "params": [ + { + "kind": "identifier", + "name": "key", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "optional": false, + "returnType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "undefined", + "kind": "keyword", + "keyword": "undefined" + } + ] + }, + "typeParams": [] + }, + { + "name": "set", + "kind": "method", + "params": [ + { + "kind": "identifier", + "name": "key", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + }, + { + "kind": "identifier", + "name": "value", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "optional": false, + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "typeParams": [] + } + ], + "properties": [], + "callSignatures": [], + "indexSignatures": [] + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "num", + "location": { + "filename": "file:///mod.ts", + "line": 12, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "100", + "kind": "literal", + "literal": { + "kind": "number", + "number": 100.0 + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "bool", + "location": { + "filename": "file:///mod.ts", + "line": 13, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "false", + "kind": "literal", + "literal": { + "kind": "boolean", + "boolean": false + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "bigint", + "location": { + "filename": "file:///mod.ts", + "line": 14, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "123", + "kind": "literal", + "literal": { + "kind": "bigInt", + "string": "123" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "regex", + "location": { + "filename": "file:///mod.ts", + "line": 15, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "hello", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "RegExp" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "date", + "location": { + "filename": "file:///mod.ts", + "line": 16, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "Date", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Date" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "tpl1", + "location": { + "filename": "file:///mod.ts", + "line": 17, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "foo", + "kind": "literal", + "literal": { + "kind": "template", + "tsTypes": [ + { + "repr": "foo", + "kind": "literal", + "literal": { + "kind": "string", + "string": "foo" + } + } + ] + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "tpl2", + "location": { + "filename": "file:///mod.ts", + "line": 18, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "kind": "const" + } + } +] diff --git a/tests/specs/ExportConstDestructured.txt b/tests/specs/ExportConstDestructured.txt new file mode 100644 index 00000000..fb50b6e6 --- /dev/null +++ b/tests/specs/ExportConstDestructured.txt @@ -0,0 +1,119 @@ +# mod.ts +const c = { a: "a", b: 2 }; + const d: { f: string; g: number; } = { f: "f", g: 2 }; + + export const { + /** export a doc */ + a, + /** export b doc */ + b, + }: { + /** type alias doc */ + a: string; + /** other doc */ + b: number; + } = c; + + export const { f, g: h } = d; + +# output.txt +Defined in file:///mod.ts:6:7 + +const a: string + export a doc + +Defined in file:///mod.ts:8:7 + +const b: number + export b doc + +Defined in file:///mod.ts:16:20 + +const f: string + +Defined in file:///mod.ts:16:26 + +const h: number + + +# output.json +[ + { + "kind": "variable", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 6 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "export a doc" + }, + "variableDef": { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "b", + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 6 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "export b doc" + }, + "variableDef": { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "f", + "location": { + "filename": "file:///mod.ts", + "line": 16, + "col": 19 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "h", + "location": { + "filename": "file:///mod.ts", + "line": 16, + "col": 25 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "kind": "const" + } + } +] diff --git a/tests/specs/ExportDeclarationMergedNamespace.txt b/tests/specs/ExportDeclarationMergedNamespace.txt new file mode 100644 index 00000000..3e9c6e6e --- /dev/null +++ b/tests/specs/ExportDeclarationMergedNamespace.txt @@ -0,0 +1,78 @@ +# mod.ts +namespace Namespace1 { + export class Test1 {} +} +namespace Namespace1 { + export class Test2 {} +} + +export { Namespace1 }; + +# output.txt +Defined in file:///mod.ts:1:1 + +namespace Namespace1 + + class Test1 + class Test2 + + +# output.json +[ + { + "kind": "namespace", + "name": "Namespace1", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "namespaceDef": { + "elements": [ + { + "kind": "class", + "name": "Test1", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + }, + { + "kind": "class", + "name": "Test2", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 2 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } + ] + } + } +] diff --git a/tests/specs/ExportDefaultClass.txt b/tests/specs/ExportDefaultClass.txt new file mode 100644 index 00000000..a137a317 --- /dev/null +++ b/tests/specs/ExportDefaultClass.txt @@ -0,0 +1,92 @@ +# mod.ts +/** Class doc */ +export default class Foobar { + /** Constructor js doc */ + constructor(name: string, private private2: number, protected protected2: number) {} +} + +# output.txt +Defined in file:///mod.ts:2:1 + +class default + Class doc + + constructor(name: string, private private2: number, protected protected2: number) + Constructor js doc + + +# output.json +[ + { + "kind": "class", + "name": "default", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Class doc" + }, + "classDef": { + "isAbstract": false, + "constructors": [ + { + "jsDoc": { + "doc": "Constructor js doc" + }, + "accessibility": null, + "hasBody": true, + "name": "constructor", + "params": [ + { + "kind": "identifier", + "name": "name", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + }, + { + "accessibility": "private", + "kind": "identifier", + "name": "private2", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + }, + { + "accessibility": "protected", + "kind": "identifier", + "name": "protected2", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 4 + } + } + ], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ExportDefaultExpr.txt b/tests/specs/ExportDefaultExpr.txt new file mode 100644 index 00000000..59e115be --- /dev/null +++ b/tests/specs/ExportDefaultExpr.txt @@ -0,0 +1,33 @@ +# mod.ts +export default "foo"; + +# output.txt +Defined in file:///mod.ts:1:1 + +var default: "foo" + + +# output.json +[ + { + "kind": "variable", + "name": "default", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "foo", + "kind": "literal", + "literal": { + "kind": "string", + "string": "foo" + } + }, + "kind": "var" + } + } +] diff --git a/tests/specs/ExportDefaultFn.txt b/tests/specs/ExportDefaultFn.txt new file mode 100644 index 00000000..2d9762bf --- /dev/null +++ b/tests/specs/ExportDefaultFn.txt @@ -0,0 +1,47 @@ +# mod.ts +export default function foo(a: number) { + return a; +} +/** @ignore */ +export default function foo(a: number) { + return a; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +function default(a: number) + + +# output.json +[ + { + "kind": "function", + "name": "default", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/ExportDefaultInterface.txt b/tests/specs/ExportDefaultInterface.txt new file mode 100644 index 00000000..add9cadc --- /dev/null +++ b/tests/specs/ExportDefaultInterface.txt @@ -0,0 +1,97 @@ +# mod.ts +/** + * Interface js doc + */ +export default interface Reader { + /** Read n bytes */ + read?(buf: Uint8Array, something: unknown): Promise +} + +# output.txt +Defined in file:///mod.ts:4:1 + +interface default + Interface js doc + + read?(buf: Uint8Array, something: unknown): Promise + Read n bytes + + +# output.json +[ + { + "kind": "interface", + "name": "default", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Interface js doc" + }, + "interfaceDef": { + "extends": [], + "methods": [ + { + "name": "read", + "kind": "method", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 4 + }, + "jsDoc": { + "doc": "Read n bytes" + }, + "optional": true, + "params": [ + { + "kind": "identifier", + "name": "buf", + "optional": false, + "tsType": { + "repr": "Uint8Array", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Uint8Array" + } + } + }, + { + "kind": "identifier", + "name": "something", + "optional": false, + "tsType": { + "repr": "unknown", + "kind": "keyword", + "keyword": "unknown" + } + } + ], + "returnType": { + "repr": "Promise", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ], + "typeName": "Promise" + } + }, + "typeParams": [] + } + ], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/ExportEnum.txt b/tests/specs/ExportEnum.txt new file mode 100644 index 00000000..337cc030 --- /dev/null +++ b/tests/specs/ExportEnum.txt @@ -0,0 +1,80 @@ +# mod.ts +/** + * Some enum for good measure + */ +export enum Hello { + World = "world", + /** There is a JsDoc */ + Fizz = "fizz", + /** There is a JsDoc + * @ignore + */ + Buzz = "buzz", +} + +# output.txt +Defined in file:///mod.ts:4:1 + +enum Hello + Some enum for good measure + + World + Fizz + There is a JsDoc + + +# output.json +[ + { + "kind": "enum", + "name": "Hello", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Some enum for good measure" + }, + "enumDef": { + "members": [ + { + "name": "World", + "init": { + "repr": "world", + "kind": "literal", + "literal": { + "kind": "string", + "string": "world" + } + }, + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 4 + } + }, + { + "name": "Fizz", + "init": { + "repr": "fizz", + "kind": "literal", + "literal": { + "kind": "string", + "string": "fizz" + } + }, + "jsDoc": { + "doc": "There is a JsDoc" + }, + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 4 + } + } + ] + } + } +] diff --git a/tests/specs/ExportFn.txt b/tests/specs/ExportFn.txt new file mode 100644 index 00000000..3ac2f855 --- /dev/null +++ b/tests/specs/ExportFn.txt @@ -0,0 +1,157 @@ +# mod.ts +/** +* @module foo +*/ + +/** +* Hello there, this is a multiline JSdoc. +* +* It has many lines +* +* Or not that many? +*/ +export function foo(a: string, b?: number, cb: (...cbArgs: unknown[]) => void, ...args: unknown[]): void { + /** + * @todo document all the things. + */ + console.log("Hello world"); +} + +# output.txt +Defined in file:///mod.ts:1:1 + + + @module + +Defined in file:///mod.ts:12:1 + +function foo(a: string, b?: number, cb: (...cbArgs: unknown[]) => void, ...args: unknown[]): void + Hello there, this is a multiline JSdoc. + + It has many lines + + Or not that many? + + +# output.json +[ + { + "kind": "moduleDoc", + "name": "", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "tags": [ + { + "kind": "module" + } + ] + } + }, + { + "kind": "function", + "name": "foo", + "location": { + "filename": "file:///mod.ts", + "line": 12, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Hello there, this is a multiline JSdoc.\n\nIt has many lines\n\nOr not that many?" + }, + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + }, + { + "kind": "identifier", + "name": "b", + "optional": true, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + }, + { + "kind": "identifier", + "name": "cb", + "optional": false, + "tsType": { + "repr": "", + "kind": "fnOrConstructor", + "fnOrConstructor": { + "constructor": false, + "tsType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "params": [ + { + "kind": "rest", + "arg": { + "kind": "identifier", + "name": "cbArgs", + "optional": false, + "tsType": null + }, + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "unknown", + "kind": "keyword", + "keyword": "unknown" + } + } + } + ], + "typeParams": [] + } + } + }, + { + "kind": "rest", + "arg": { + "kind": "identifier", + "name": "args", + "optional": false, + "tsType": null + }, + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "unknown", + "kind": "keyword", + "keyword": "unknown" + } + } + } + ], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/ExportFn2.txt b/tests/specs/ExportFn2.txt new file mode 100644 index 00000000..fbc66b2d --- /dev/null +++ b/tests/specs/ExportFn2.txt @@ -0,0 +1,187 @@ +# mod.ts +interface AssignOpts { + a: string; +} + +export function foo([e,,f, ...g]: number[], { c, d: asdf, i = "asdf", ...rest}, ops: AssignOpts = {}): void { + console.log("Hello world"); +} + +# output.txt +Defined in file:///mod.ts:5:1 + +function foo([e, , f, ...g]: number[], {c, d, i, ...rest}, ops: AssignOpts): void + +Defined in file:///mod.ts:1:1 + +private interface AssignOpts + + a: string + + +# output.json +[ + { + "kind": "function", + "name": "foo", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "array", + "elements": [ + { + "kind": "identifier", + "name": "e", + "optional": false, + "tsType": null + }, + null, + { + "kind": "identifier", + "name": "f", + "optional": false, + "tsType": null + }, + { + "kind": "rest", + "arg": { + "kind": "identifier", + "name": "g", + "optional": false, + "tsType": null + }, + "tsType": null + } + ], + "optional": false, + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + }, + { + "kind": "object", + "props": [ + { + "kind": "assign", + "key": "c", + "value": null + }, + { + "kind": "keyValue", + "key": "d", + "value": { + "kind": "identifier", + "name": "asdf", + "optional": false, + "tsType": null + } + }, + { + "kind": "assign", + "key": "i", + "value": "[UNSUPPORTED]" + }, + { + "kind": "rest", + "arg": { + "kind": "identifier", + "name": "rest", + "optional": false, + "tsType": null + } + } + ], + "optional": false, + "tsType": null + }, + { + "kind": "assign", + "left": { + "kind": "identifier", + "name": "ops", + "optional": false, + "tsType": { + "repr": "AssignOpts", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "AssignOpts" + } + } + }, + "right": "[UNSUPPORTED]", + "tsType": null + } + ], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "interface", + "name": "AssignOpts", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "private", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [ + { + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + } + ], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] + +# diagnostics +[ + { + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "kind": "Type is not exported, but referenced by an exported type." + } +] diff --git a/tests/specs/ExportInterface.txt b/tests/specs/ExportInterface.txt new file mode 100644 index 00000000..19849ee4 --- /dev/null +++ b/tests/specs/ExportInterface.txt @@ -0,0 +1,216 @@ +# mod.ts +interface Foo { +} +interface Bar { +} +/** + * Interface js doc + */ +export interface Reader extends Foo, Bar { + /** Read n bytes */ + read?(buf: Uint8Array, something: unknown): Promise + /** Test */ + [key: string]: number; +} + +# output.txt +Defined in file:///mod.ts:3:1 + +private interface Bar + + +Defined in file:///mod.ts:1:1 + +private interface Foo + + +Defined in file:///mod.ts:8:1 + +interface Reader extends Foo, Bar + Interface js doc + + read?(buf: Uint8Array, something: unknown): Promise + Read n bytes + [key: string]: number + + +# output.json +[ + { + "kind": "interface", + "name": "Reader", + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Interface js doc" + }, + "interfaceDef": { + "extends": [ + { + "repr": "Foo", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Foo" + } + }, + { + "repr": "Bar", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Bar" + } + } + ], + "methods": [ + { + "name": "read", + "kind": "method", + "location": { + "filename": "file:///mod.ts", + "line": 10, + "col": 4 + }, + "jsDoc": { + "doc": "Read n bytes" + }, + "optional": true, + "params": [ + { + "kind": "identifier", + "name": "buf", + "optional": false, + "tsType": { + "repr": "Uint8Array", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Uint8Array" + } + } + }, + { + "kind": "identifier", + "name": "something", + "optional": false, + "tsType": { + "repr": "unknown", + "kind": "keyword", + "keyword": "unknown" + } + } + ], + "returnType": { + "repr": "Promise", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ], + "typeName": "Promise" + } + }, + "typeParams": [] + } + ], + "properties": [], + "callSignatures": [], + "indexSignatures": [ + { + "jsDoc": { + "doc": "Test" + }, + "readonly": false, + "params": [ + { + "kind": "identifier", + "name": "key", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "location": { + "filename": "file:///mod.ts", + "line": 12, + "col": 4 + } + } + ], + "typeParams": [] + } + }, + { + "kind": "interface", + "name": "Foo", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "private", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + }, + { + "kind": "interface", + "name": "Bar", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "declarationKind": "private", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] + +# diagnostics +[ + { + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "kind": "Type is not exported, but referenced by an exported type." + }, + { + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "kind": "Type is not exported, but referenced by an exported type." + } +] diff --git a/tests/specs/ExportInterface2.txt b/tests/specs/ExportInterface2.txt new file mode 100644 index 00000000..bedbd0dd --- /dev/null +++ b/tests/specs/ExportInterface2.txt @@ -0,0 +1,59 @@ +# mod.ts +export interface TypedIface { + something(): T +} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface TypedIface + + something(): T + + +# output.json +[ + { + "kind": "interface", + "name": "TypedIface", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [ + { + "name": "something", + "kind": "method", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 4 + }, + "optional": false, + "params": [], + "returnType": { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + }, + "typeParams": [] + } + ], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [ + { + "name": "T" + } + ] + } + } +] diff --git a/tests/specs/ExportInterfaceAccessors.txt b/tests/specs/ExportInterfaceAccessors.txt new file mode 100644 index 00000000..e29ac20d --- /dev/null +++ b/tests/specs/ExportInterfaceAccessors.txt @@ -0,0 +1,89 @@ +# mod.ts +export interface Thing { + get size(): number; + set size(value: number | string); +} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface Thing + + size(): number + size(value: number | string) + + +# output.json +[ + { + "kind": "interface", + "name": "Thing", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [ + { + "name": "size", + "kind": "getter", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "optional": false, + "params": [], + "returnType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "typeParams": [] + }, + { + "name": "size", + "kind": "setter", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + }, + "optional": false, + "params": [ + { + "kind": "identifier", + "name": "value", + "optional": false, + "tsType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + ] + } + } + ], + "returnType": null, + "typeParams": [] + } + ], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/ExportLet.txt b/tests/specs/ExportLet.txt new file mode 100644 index 00000000..8f612c58 --- /dev/null +++ b/tests/specs/ExportLet.txt @@ -0,0 +1,171 @@ +# mod.ts +export let str = "hello"; +export let num = 100; +export let bool = false; +export let dateStr = Date(); +export let regex = RegExp("foobar"); +export let sym = Symbol("baz"); +export let tpl = `foobarbaz`; + +# output.txt +Defined in file:///mod.ts:3:12 + +let bool: boolean + +Defined in file:///mod.ts:4:12 + +let dateStr: string + +Defined in file:///mod.ts:2:12 + +let num: number + +Defined in file:///mod.ts:5:12 + +let regex: RegExp + +Defined in file:///mod.ts:1:12 + +let str: string + +Defined in file:///mod.ts:6:12 + +let sym: symbol + +Defined in file:///mod.ts:7:12 + +let tpl: string + + +# output.json +[ + { + "kind": "variable", + "name": "str", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 11 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "num", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 11 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "bool", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 11 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "boolean", + "kind": "keyword", + "keyword": "boolean" + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "dateStr", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 11 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "Date", + "kind": "keyword", + "keyword": "string" + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "regex", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 11 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "RegExp", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "RegExp" + } + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "sym", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 11 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "Symbol", + "kind": "keyword", + "keyword": "symbol" + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "tpl", + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 11 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "kind": "let" + } + } +] diff --git a/tests/specs/ExportNamespace.txt b/tests/specs/ExportNamespace.txt new file mode 100644 index 00000000..1b2081b7 --- /dev/null +++ b/tests/specs/ExportNamespace.txt @@ -0,0 +1,186 @@ +# mod.ts +/** Namespace JSdoc */ +export namespace RootNs { + export const a = "a"; + + /** Nested namespace JSDoc */ + export namespace NestedNs { + export enum Foo { + a = 1, + b = 2, + c = 3, + } + } +} + +export namespace RootNs.OtherNs { + export class Other {} +} + +# output.txt +Defined in file:///mod.ts:2:1 + +namespace RootNs + Namespace JSdoc + + const a: "a" + namespace NestedNs + Nested namespace JSDoc + namespace OtherNs + + +# output.json +[ + { + "kind": "namespace", + "name": "RootNs", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Namespace JSdoc" + }, + "namespaceDef": { + "elements": [ + { + "kind": "variable", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 17 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "a", + "kind": "literal", + "literal": { + "kind": "string", + "string": "a" + } + }, + "kind": "const" + } + }, + { + "kind": "namespace", + "name": "NestedNs", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 4 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Nested namespace JSDoc" + }, + "namespaceDef": { + "elements": [ + { + "kind": "enum", + "name": "Foo", + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 6 + }, + "declarationKind": "export", + "enumDef": { + "members": [ + { + "name": "a", + "init": { + "repr": "1", + "kind": "literal", + "literal": { + "kind": "number", + "number": 1.0 + } + }, + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 8 + } + }, + { + "name": "b", + "init": { + "repr": "2", + "kind": "literal", + "literal": { + "kind": "number", + "number": 2.0 + } + }, + "location": { + "filename": "file:///mod.ts", + "line": 9, + "col": 8 + } + }, + { + "name": "c", + "init": { + "repr": "3", + "kind": "literal", + "literal": { + "kind": "number", + "number": 3.0 + } + }, + "location": { + "filename": "file:///mod.ts", + "line": 10, + "col": 8 + } + } + ] + } + } + ] + } + }, + { + "kind": "namespace", + "name": "OtherNs", + "location": { + "filename": "file:///mod.ts", + "line": 15, + "col": 7 + }, + "declarationKind": "export", + "namespaceDef": { + "elements": [ + { + "kind": "class", + "name": "Other", + "location": { + "filename": "file:///mod.ts", + "line": 16, + "col": 2 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } + ] + } + } + ] + } + } +] diff --git a/tests/specs/ExportNamespaceEnumSameName.txt b/tests/specs/ExportNamespaceEnumSameName.txt new file mode 100644 index 00000000..3e2c6faa --- /dev/null +++ b/tests/specs/ExportNamespaceEnumSameName.txt @@ -0,0 +1,77 @@ +# mod.ts +export namespace RootNs { + export namespace NestedNs { + export enum Foo { + } + } + + export enum Foo { + } +} + +# output.txt +Defined in file:///mod.ts:1:1 + +namespace RootNs + + namespace NestedNs + enum Foo + + +# output.json +[ + { + "kind": "namespace", + "name": "RootNs", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "namespaceDef": { + "elements": [ + { + "kind": "namespace", + "name": "NestedNs", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "declarationKind": "export", + "namespaceDef": { + "elements": [ + { + "kind": "enum", + "name": "Foo", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 4 + }, + "declarationKind": "export", + "enumDef": { + "members": [] + } + } + ] + } + }, + { + "kind": "enum", + "name": "Foo", + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 2 + }, + "declarationKind": "export", + "enumDef": { + "members": [] + } + } + ] + } + } +] diff --git a/tests/specs/ExportPrivate.txt b/tests/specs/ExportPrivate.txt new file mode 100644 index 00000000..7bc10fa3 --- /dev/null +++ b/tests/specs/ExportPrivate.txt @@ -0,0 +1,32 @@ +{ "private": true } +# mod.ts +const foo: string = "foo"; +export { foo }; + +# output.txt +Defined in file:///mod.ts:1:7 + +const foo: string + + +# output.json +[ + { + "kind": "variable", + "name": "foo", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 6 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "kind": "const" + } + } +] diff --git a/tests/specs/ExportTypeAlias.txt b/tests/specs/ExportTypeAlias.txt new file mode 100644 index 00000000..f312600d --- /dev/null +++ b/tests/specs/ExportTypeAlias.txt @@ -0,0 +1,44 @@ +# mod.ts +/** Array holding numbers */ +export type NumberArray = Array; + +# output.txt +Defined in file:///mod.ts:2:1 + +type NumberArray = Array + Array holding numbers + + +# output.json +[ + { + "kind": "typeAlias", + "name": "NumberArray", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Array holding numbers" + }, + "typeAliasDef": { + "tsType": { + "repr": "Array", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ], + "typeName": "Array" + } + }, + "typeParams": [] + } + } +] diff --git a/tests/specs/ExportTypeAliasLiteral.txt b/tests/specs/ExportTypeAliasLiteral.txt new file mode 100644 index 00000000..7cdb8253 --- /dev/null +++ b/tests/specs/ExportTypeAliasLiteral.txt @@ -0,0 +1,123 @@ +# mod.ts +export type A = { + new (d: string): A; + a(): void; + b?(): void; + get c(): string; + set c(v: number); +}; + +# output.txt +Defined in file:///mod.ts:1:1 + +type A = { new(d: string): A; a(): void; b?(): void; c(): string; c(v: number); } + + +# output.json +[ + { + "kind": "typeAlias", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "", + "kind": "typeLiteral", + "typeLiteral": { + "methods": [ + { + "name": "new", + "kind": "method", + "params": [ + { + "kind": "identifier", + "name": "d", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "optional": false, + "returnType": { + "repr": "A", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "A" + } + }, + "typeParams": [] + }, + { + "name": "a", + "kind": "method", + "params": [], + "optional": false, + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "typeParams": [] + }, + { + "name": "b", + "kind": "method", + "params": [], + "optional": true, + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "typeParams": [] + }, + { + "name": "c", + "kind": "getter", + "params": [], + "optional": false, + "returnType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + }, + { + "name": "c", + "kind": "setter", + "params": [ + { + "kind": "identifier", + "name": "v", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "optional": false, + "returnType": null, + "typeParams": [] + } + ], + "properties": [], + "callSignatures": [], + "indexSignatures": [] + } + }, + "typeParams": [] + } + } +] diff --git a/tests/specs/ExportsAllWithPrivate.txt b/tests/specs/ExportsAllWithPrivate.txt new file mode 100644 index 00000000..d6fa4a35 --- /dev/null +++ b/tests/specs/ExportsAllWithPrivate.txt @@ -0,0 +1,194 @@ +{ "private": true } +# mod.ts +export function a() {} +function b() {} +export class C {} +class D {} +export interface E {} +interface F {} +export namespace G {} +namespace H {} + +# output.txt +Defined in file:///mod.ts:1:1 + +function a() + +Defined in file:///mod.ts:2:1 + +private function b() + +Defined in file:///mod.ts:3:1 + +class C + + +Defined in file:///mod.ts:4:1 + +private class D + + +Defined in file:///mod.ts:5:1 + +interface E + + +Defined in file:///mod.ts:6:1 + +private interface F + + +Defined in file:///mod.ts:7:1 + +namespace G + + +Defined in file:///mod.ts:8:1 + +private namespace H + + + +# output.json +[ + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "class", + "name": "C", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + }, + { + "kind": "interface", + "name": "E", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + }, + { + "kind": "namespace", + "name": "G", + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 0 + }, + "declarationKind": "export", + "namespaceDef": { + "elements": [] + } + }, + { + "kind": "function", + "name": "b", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "private", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "class", + "name": "D", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 0 + }, + "declarationKind": "private", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + }, + { + "kind": "interface", + "name": "F", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 0 + }, + "declarationKind": "private", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + }, + { + "kind": "namespace", + "name": "H", + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 0 + }, + "declarationKind": "private", + "namespaceDef": { + "elements": [] + } + } +] diff --git a/tests/specs/ExportsDeclaredEarlier.txt b/tests/specs/ExportsDeclaredEarlier.txt new file mode 100644 index 00000000..f42a940f --- /dev/null +++ b/tests/specs/ExportsDeclaredEarlier.txt @@ -0,0 +1,99 @@ +# mod.ts +const hello = "world"; +function say(words: string): void { } +function foo(): void { } +export { hello, say, foo as bar }; + +# output.txt +Defined in file:///mod.ts:3:1 + +function bar(): void + +Defined in file:///mod.ts:2:1 + +function say(words: string): void + +Defined in file:///mod.ts:1:7 + +const hello: "world" + + +# output.json +[ + { + "kind": "variable", + "name": "hello", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 6 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "world", + "kind": "literal", + "literal": { + "kind": "string", + "string": "world" + } + }, + "kind": "const" + } + }, + { + "kind": "function", + "name": "say", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "words", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "bar", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/FunctionArrayDeconstruction.txt b/tests/specs/FunctionArrayDeconstruction.txt new file mode 100644 index 00000000..9587a179 --- /dev/null +++ b/tests/specs/FunctionArrayDeconstruction.txt @@ -0,0 +1,60 @@ +# mod.ts +export function f([a, b, ...c]) {} + +# output.txt +Defined in file:///mod.ts:1:1 + +function f([a, b, ...c]) + + +# output.json +[ + { + "kind": "function", + "name": "f", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "array", + "elements": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": null + }, + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": null + }, + { + "kind": "rest", + "arg": { + "kind": "identifier", + "name": "c", + "optional": false, + "tsType": null + }, + "tsType": null + } + ], + "optional": false, + "tsType": null + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/FunctionAsync.txt b/tests/specs/FunctionAsync.txt new file mode 100644 index 00000000..08880a2a --- /dev/null +++ b/tests/specs/FunctionAsync.txt @@ -0,0 +1,30 @@ +# mod.ts +export async function a() {} + +# output.txt +Defined in file:///mod.ts:1:1 + +async function a() + + +# output.json +[ + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": true, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/FunctionAsyncGenerator.txt b/tests/specs/FunctionAsyncGenerator.txt new file mode 100644 index 00000000..9b87c09f --- /dev/null +++ b/tests/specs/FunctionAsyncGenerator.txt @@ -0,0 +1,30 @@ +# mod.ts +export async function* ag() {} + +# output.txt +Defined in file:///mod.ts:1:1 + +async function* ag() + + +# output.json +[ + { + "kind": "function", + "name": "ag", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": true, + "isGenerator": true, + "typeParams": [] + } + } +] diff --git a/tests/specs/FunctionDeclaration.txt b/tests/specs/FunctionDeclaration.txt new file mode 100644 index 00000000..f4f0af1c --- /dev/null +++ b/tests/specs/FunctionDeclaration.txt @@ -0,0 +1,30 @@ +# mod.ts +export function fun() {} + +# output.txt +Defined in file:///mod.ts:1:1 + +function fun() + + +# output.json +[ + { + "kind": "function", + "name": "fun", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/FunctionGenerator.txt b/tests/specs/FunctionGenerator.txt new file mode 100644 index 00000000..39854d55 --- /dev/null +++ b/tests/specs/FunctionGenerator.txt @@ -0,0 +1,30 @@ +# mod.ts +export function* g() {} + +# output.txt +Defined in file:///mod.ts:1:1 + +function* g() + + +# output.json +[ + { + "kind": "function", + "name": "g", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": true, + "typeParams": [] + } + } +] diff --git a/tests/specs/FunctionGeneric.txt b/tests/specs/FunctionGeneric.txt new file mode 100644 index 00000000..625aeba6 --- /dev/null +++ b/tests/specs/FunctionGeneric.txt @@ -0,0 +1,61 @@ +# mod.ts +export function add(a: T, b: T) { return a + b; } + +# output.txt +Defined in file:///mod.ts:1:1 + +function add(a: T, b: T) + + +# output.json +[ + { + "kind": "function", + "name": "add", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + } + }, + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + } + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [ + { + "name": "T" + } + ] + } + } +] diff --git a/tests/specs/FunctionObjectDeconstruction.txt b/tests/specs/FunctionObjectDeconstruction.txt new file mode 100644 index 00000000..4f5fb6b4 --- /dev/null +++ b/tests/specs/FunctionObjectDeconstruction.txt @@ -0,0 +1,57 @@ +# mod.ts +export function f({ a, b, ...c }) {} + +# output.txt +Defined in file:///mod.ts:1:1 + +function f({a, b, ...c}) + + +# output.json +[ + { + "kind": "function", + "name": "f", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "object", + "props": [ + { + "kind": "assign", + "key": "a", + "value": null + }, + { + "kind": "assign", + "key": "b", + "value": null + }, + { + "kind": "rest", + "arg": { + "kind": "identifier", + "name": "c", + "optional": false, + "tsType": null + } + } + ], + "optional": false, + "tsType": null + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/FunctionOverloads.txt b/tests/specs/FunctionOverloads.txt new file mode 100644 index 00000000..05df3afe --- /dev/null +++ b/tests/specs/FunctionOverloads.txt @@ -0,0 +1,138 @@ +# mod.ts +export function a(b: string): string; +export function a(b: number): number; +export function a(b: string | number): string | number {} + +# output.txt +Defined in file:///mod.ts:1:1 + +function a(b: string): string + +Defined in file:///mod.ts:2:1 + +function a(b: number): number + + + +# output.json +[ + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "returnType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "returnType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ] + } + } + ], + "returnType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ] + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/GenericInstantiatedWithTupleType.txt b/tests/specs/GenericInstantiatedWithTupleType.txt new file mode 100644 index 00000000..f54f7c20 --- /dev/null +++ b/tests/specs/GenericInstantiatedWithTupleType.txt @@ -0,0 +1,82 @@ +# mod.ts +export interface Generic {} +export function f(): Generic<[string, number]> { return {}; } + +# output.txt +Defined in file:///mod.ts:2:1 + +function f(): Generic<[string, number]> + +Defined in file:///mod.ts:1:1 + +interface Generic + + + +# output.json +[ + { + "kind": "interface", + "name": "Generic", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [ + { + "name": "T" + } + ] + } + }, + { + "kind": "function", + "name": "f", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": { + "repr": "Generic", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "", + "kind": "tuple", + "tuple": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ] + } + ], + "typeName": "Generic" + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/ImportEquals.txt b/tests/specs/ImportEquals.txt new file mode 100644 index 00000000..7bcfa9df --- /dev/null +++ b/tests/specs/ImportEquals.txt @@ -0,0 +1,38 @@ +# mod.ts +declare module Test { + export interface Options { + } +} + +import Options = Test.Options; + +export { Options }; + +# output.txt +Defined in file:///mod.ts:2:3 + +interface Options + + + +# output.json +[ + { + "kind": "interface", + "name": "Options", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/ImportTypes.txt b/tests/specs/ImportTypes.txt new file mode 100644 index 00000000..c3951d37 --- /dev/null +++ b/tests/specs/ImportTypes.txt @@ -0,0 +1,60 @@ +# mod.ts +export function adopt(p: import("./module.ts").Pet) { + console.log(`Adopting ${p.name}...`); +} + +# output.txt +Defined in file:///mod.ts:1:1 + +function adopt(p: import("./module.ts").Pet) + + +# output.json +[ + { + "kind": "function", + "name": "adopt", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "p", + "optional": false, + "tsType": { + "repr": "", + "kind": "importType", + "importType": { + "specifier": "./module.ts", + "qualifier": "Pet", + "typeParams": [ + { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + } + ] + } + } + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [ + { + "name": "T" + } + ] + } + } +] diff --git a/tests/specs/IndentedWithTabs.txt b/tests/specs/IndentedWithTabs.txt new file mode 100644 index 00000000..8f867c8b --- /dev/null +++ b/tests/specs/IndentedWithTabs.txt @@ -0,0 +1,108 @@ +# mod.ts +/** + * Line 1 + * + * Line 2 + * + * Indented + */ +export namespace Tabs { + /** + * Line 1 + * + * Line 2 + * + * Indented + */ + export interface Tabs{ + /** + * Line 1 + * + * Line 2 + * + * Indented + */ + property: string; + } +} + +# output.txt +Defined in file:///mod.ts:8:1 + +namespace Tabs + Line 1 + + Line 2 + + Indented + + interface Tabs + Line 1 + + Line 2 + + Indented + + +# output.json +[ + { + "kind": "namespace", + "name": "Tabs", + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Line 1\n\nLine 2\n\n\tIndented" + }, + "namespaceDef": { + "elements": [ + { + "kind": "interface", + "name": "Tabs", + "location": { + "filename": "file:///mod.ts", + "line": 16, + "col": 4 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Line 1\n\nLine 2\n\n\tIndented" + }, + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [ + { + "name": "property", + "location": { + "filename": "file:///mod.ts", + "line": 24, + "col": 8 + }, + "jsDoc": { + "doc": "Line 1\n\nLine 2\n\n\tIndented" + }, + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + } + ], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } + ] + } + } +] diff --git a/tests/specs/InferObjectLiteral.txt b/tests/specs/InferObjectLiteral.txt new file mode 100644 index 00000000..ebd9a17b --- /dev/null +++ b/tests/specs/InferObjectLiteral.txt @@ -0,0 +1,259 @@ +# mod.ts +const s: symbol = Symbol.for("s"); + const t: symbol = Symbol.for("t"); + + export const a = { + a: "a", + b: new Map(), + c: { d: "d" }, + d(e: string): void {}, + f: (g: string): void => {}, + get h(): string { + return "h"; + }, + set h(value: string) { + + }, + [s]: [1, 2, 3, "a"], + [t](u: string): void {}, + }; + +# output.txt +Defined in file:///mod.ts:4:18 + +const a: { d(e: string): void; h(): string; h(value: string); [[t]](u: string): void; a: string; b: Map; c: { d: string; }; f: (g: string) => void; [s]: (number | string)[]; } + + +# output.json +[ + { + "kind": "variable", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 17 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "typeLiteral", + "typeLiteral": { + "methods": [ + { + "name": "d", + "kind": "method", + "params": [ + { + "kind": "identifier", + "name": "e", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "optional": false, + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "typeParams": [] + }, + { + "name": "h", + "kind": "getter", + "params": [], + "optional": false, + "returnType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + }, + { + "name": "h", + "kind": "setter", + "params": [ + { + "kind": "identifier", + "name": "value", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "optional": false, + "returnType": null, + "typeParams": [] + }, + { + "name": "[t]", + "kind": "method", + "params": [ + { + "kind": "identifier", + "name": "u", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "computed": true, + "optional": false, + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "typeParams": [] + } + ], + "properties": [ + { + "name": "a", + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + }, + { + "name": "b", + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "Map", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ], + "typeName": "Map" + } + }, + "typeParams": [] + }, + { + "name": "c", + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "", + "kind": "typeLiteral", + "typeLiteral": { + "methods": [], + "properties": [ + { + "name": "d", + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + } + ], + "callSignatures": [], + "indexSignatures": [] + } + }, + "typeParams": [] + }, + { + "name": "f", + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "", + "kind": "fnOrConstructor", + "fnOrConstructor": { + "constructor": false, + "tsType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "params": [ + { + "kind": "identifier", + "name": "g", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "typeParams": [] + } + }, + "typeParams": [] + }, + { + "name": "[s]", + "params": [], + "computed": true, + "optional": false, + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + ] + } + }, + "typeParams": [] + } + ], + "callSignatures": [], + "indexSignatures": [] + } + }, + "kind": "const" + } + } +] diff --git a/tests/specs/InferSimpleTsArrTypes.txt b/tests/specs/InferSimpleTsArrTypes.txt new file mode 100644 index 00000000..98bfb800 --- /dev/null +++ b/tests/specs/InferSimpleTsArrTypes.txt @@ -0,0 +1,232 @@ +# mod.ts +export const a = [1]; + export const b = [true]; + export const c = ["c"]; + export const d = [2, "d"]; + export const e = [1, 2, 3]; + export const f = ["a", 1, e]; + export const g = ["a", 1, true] as const; + +# output.txt +Defined in file:///mod.ts:1:14 + +const a: number[] + +Defined in file:///mod.ts:2:20 + +const b: boolean[] + +Defined in file:///mod.ts:3:20 + +const c: string[] + +Defined in file:///mod.ts:4:20 + +const d: (number | string)[] + +Defined in file:///mod.ts:5:20 + +const e: number[] + +Defined in file:///mod.ts:6:20 + +const f: any[] + +Defined in file:///mod.ts:7:20 + +const g: ("a" | 1 | true)[] + + +# output.json +[ + { + "kind": "variable", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "b", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 19 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "boolean", + "kind": "keyword", + "keyword": "boolean" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "c", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 19 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "d", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 19 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + ] + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "e", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 19 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "f", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 19 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "any[]", + "kind": "array", + "array": { + "repr": "any", + "kind": "keyword", + "keyword": "any" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "g", + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 19 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "array", + "array": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "a", + "kind": "literal", + "literal": { + "kind": "string", + "string": "a" + } + }, + { + "repr": "1", + "kind": "literal", + "literal": { + "kind": "number", + "number": 1.0 + } + }, + { + "repr": "true", + "kind": "literal", + "literal": { + "kind": "boolean", + "boolean": true + } + } + ] + } + }, + "kind": "const" + } + } +] diff --git a/tests/specs/InferSimpleTsTypes.txt b/tests/specs/InferSimpleTsTypes.txt new file mode 100644 index 00000000..e600d415 --- /dev/null +++ b/tests/specs/InferSimpleTsTypes.txt @@ -0,0 +1,436 @@ +# mod.ts +export const s = "hello"; +export const n = 123; +export const b = false; +export const bi = 100n; +export const re = /hello/; +export const tpl = `foobar`; +export const d = new Date(); +export const s2 = String("foo"); +export const n2 = Number(100); +export const bi2 = BigInt(123); +export const sym = Symbol("hello"); +export const m = new Map(); +export const fn1 = (a: string): void => {}; +export const fn2 = function (a:string): void {}; +export const s3 = "VGhpcyBpcyBhIHJlYWxseSBsb25nIHN0cmluZyB0byB0cnkgdG8gZmluZCBvdXQgaWYgd2UgY2FuIHNraXAgaW5mZXJyaW5nIGEgcmVhbGx5IGxhcmdlIHZhbHVlIGZvciBhIGNvbnN0IHN0cmluZyB2YXJpYWJsZSB3aXRob3V0IGEgdHlwZSBhbm5vdGF0aW9uLg=="; + +# output.txt +Defined in file:///mod.ts:3:14 + +const b: false + +Defined in file:///mod.ts:4:14 + +const bi: 100 + +Defined in file:///mod.ts:10:14 + +const bi2: bigint + +Defined in file:///mod.ts:7:14 + +const d: Date + +Defined in file:///mod.ts:13:14 + +const fn1: (a: string) => void + +Defined in file:///mod.ts:14:14 + +const fn2: (a: string) => void + +Defined in file:///mod.ts:12:14 + +const m: Map + +Defined in file:///mod.ts:2:14 + +const n: 123 + +Defined in file:///mod.ts:9:14 + +const n2: number + +Defined in file:///mod.ts:5:14 + +const re: RegExp + +Defined in file:///mod.ts:1:14 + +const s: "hello" + +Defined in file:///mod.ts:8:14 + +const s2: string + +Defined in file:///mod.ts:15:14 + +const s3: string + +Defined in file:///mod.ts:11:14 + +const sym: symbol + +Defined in file:///mod.ts:6:14 + +const tpl: `foobar` + + +# output.json +[ + { + "kind": "variable", + "name": "s", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "hello", + "kind": "literal", + "literal": { + "kind": "string", + "string": "hello" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "n", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "123", + "kind": "literal", + "literal": { + "kind": "number", + "number": 123.0 + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "b", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "false", + "kind": "literal", + "literal": { + "kind": "boolean", + "boolean": false + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "bi", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "100", + "kind": "literal", + "literal": { + "kind": "bigInt", + "string": "100" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "re", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "hello", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "RegExp" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "tpl", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "foobar", + "kind": "literal", + "literal": { + "kind": "template", + "tsTypes": [ + { + "repr": "foobar", + "kind": "literal", + "literal": { + "kind": "string", + "string": "foobar" + } + } + ] + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "d", + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "Date", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Date" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "s2", + "location": { + "filename": "file:///mod.ts", + "line": 8, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "String", + "kind": "keyword", + "keyword": "string" + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "n2", + "location": { + "filename": "file:///mod.ts", + "line": 9, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "Number", + "kind": "keyword", + "keyword": "number" + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "bi2", + "location": { + "filename": "file:///mod.ts", + "line": 10, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "BigInt", + "kind": "keyword", + "keyword": "bigint" + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "sym", + "location": { + "filename": "file:///mod.ts", + "line": 11, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "Symbol", + "kind": "keyword", + "keyword": "symbol" + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "m", + "location": { + "filename": "file:///mod.ts", + "line": 12, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "Map", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + ], + "typeName": "Map" + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "fn1", + "location": { + "filename": "file:///mod.ts", + "line": 13, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "fnOrConstructor", + "fnOrConstructor": { + "constructor": false, + "tsType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "typeParams": [] + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "fn2", + "location": { + "filename": "file:///mod.ts", + "line": 14, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "", + "kind": "fnOrConstructor", + "fnOrConstructor": { + "constructor": false, + "tsType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "typeParams": [] + } + }, + "kind": "const" + } + }, + { + "kind": "variable", + "name": "s3", + "location": { + "filename": "file:///mod.ts", + "line": 15, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "kind": "const" + } + } +] diff --git a/tests/specs/InferTsTypes.txt b/tests/specs/InferTsTypes.txt new file mode 100644 index 00000000..b1922ca5 --- /dev/null +++ b/tests/specs/InferTsTypes.txt @@ -0,0 +1,148 @@ +# mod.ts +export let s = "hello"; + export let n = 123; + export let b = false; + export let bi = 100n; + export let re = /hello/; + export let tpl = `foobar`; + +# output.txt +Defined in file:///mod.ts:3:16 + +let b: boolean + +Defined in file:///mod.ts:4:16 + +let bi: bigint + +Defined in file:///mod.ts:2:16 + +let n: number + +Defined in file:///mod.ts:5:16 + +let re: RegExp + +Defined in file:///mod.ts:1:12 + +let s: string + +Defined in file:///mod.ts:6:16 + +let tpl: string + + +# output.json +[ + { + "kind": "variable", + "name": "s", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 11 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "n", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 15 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "b", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 15 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "boolean", + "kind": "keyword", + "keyword": "boolean" + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "bi", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 15 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "bigint", + "kind": "keyword", + "keyword": "bigint" + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "re", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 15 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "hello", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "RegExp" + } + }, + "kind": "let" + } + }, + { + "kind": "variable", + "name": "tpl", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 15 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "kind": "let" + } + } +] diff --git a/tests/specs/InferTypes.txt b/tests/specs/InferTypes.txt new file mode 100644 index 00000000..7b141d65 --- /dev/null +++ b/tests/specs/InferTypes.txt @@ -0,0 +1,77 @@ +# mod.ts +export type Flatten = T extends Array ? U : T; + +# output.txt +Defined in file:///mod.ts:1:1 + +type Flatten = T extends Array ? U : T + + +# output.json +[ + { + "kind": "typeAlias", + "name": "Flatten", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "", + "kind": "conditional", + "conditionalType": { + "checkType": { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + }, + "extendsType": { + "repr": "Array", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "", + "kind": "infer", + "infer": { + "typeParam": { + "name": "U" + } + } + } + ], + "typeName": "Array" + } + }, + "trueType": { + "repr": "U", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "U" + } + }, + "falseType": { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + } + } + }, + "typeParams": [ + { + "name": "T" + } + ] + } + } +] diff --git a/tests/specs/InterfaceConstruct.txt b/tests/specs/InterfaceConstruct.txt new file mode 100644 index 00000000..9e5ef7f5 --- /dev/null +++ b/tests/specs/InterfaceConstruct.txt @@ -0,0 +1,59 @@ +# mod.ts +export interface I { + new(name: string); +} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface I + + new(name: string) + + +# output.json +[ + { + "kind": "interface", + "name": "I", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [ + { + "name": "new", + "kind": "method", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "optional": false, + "params": [ + { + "kind": "identifier", + "name": "name", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "returnType": null, + "typeParams": [] + } + ], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/InterfaceDeclaration.txt b/tests/specs/InterfaceDeclaration.txt new file mode 100644 index 00000000..d84e092d --- /dev/null +++ b/tests/specs/InterfaceDeclaration.txt @@ -0,0 +1,31 @@ +# mod.ts +export interface Interface {} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface Interface + + + +# output.json +[ + { + "kind": "interface", + "name": "Interface", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/InterfaceExtends.txt b/tests/specs/InterfaceExtends.txt new file mode 100644 index 00000000..03d59bff --- /dev/null +++ b/tests/specs/InterfaceExtends.txt @@ -0,0 +1,40 @@ +# mod.ts +export interface Interface extends Iterator {} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface Interface extends Iterator + + + +# output.json +[ + { + "kind": "interface", + "name": "Interface", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [ + { + "repr": "Iterator", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Iterator" + } + } + ], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/InterfaceExtends2.txt b/tests/specs/InterfaceExtends2.txt new file mode 100644 index 00000000..178abb3c --- /dev/null +++ b/tests/specs/InterfaceExtends2.txt @@ -0,0 +1,48 @@ +# mod.ts +export interface Interface extends Iterator, Iterable {} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface Interface extends Iterator, Iterable + + + +# output.json +[ + { + "kind": "interface", + "name": "Interface", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [ + { + "repr": "Iterator", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Iterator" + } + }, + { + "repr": "Iterable", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Iterable" + } + } + ], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/InterfaceGeneric.txt b/tests/specs/InterfaceGeneric.txt new file mode 100644 index 00000000..150c49ea --- /dev/null +++ b/tests/specs/InterfaceGeneric.txt @@ -0,0 +1,35 @@ +# mod.ts +export interface Interface {} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface Interface + + + +# output.json +[ + { + "kind": "interface", + "name": "Interface", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [ + { + "name": "T" + } + ] + } + } +] diff --git a/tests/specs/InterfaceGenericExtends.txt b/tests/specs/InterfaceGenericExtends.txt new file mode 100644 index 00000000..43ab6785 --- /dev/null +++ b/tests/specs/InterfaceGenericExtends.txt @@ -0,0 +1,53 @@ +# mod.ts +export interface Interface extends Iterable {} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface Interface extends Iterable + + + +# output.json +[ + { + "kind": "interface", + "name": "Interface", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [ + { + "repr": "Iterable", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "V", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "V" + } + } + ], + "typeName": "Iterable" + } + } + ], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [ + { + "name": "V" + } + ] + } + } +] diff --git a/tests/specs/InterfaceIndexSignature.txt b/tests/specs/InterfaceIndexSignature.txt new file mode 100644 index 00000000..177b7bf1 --- /dev/null +++ b/tests/specs/InterfaceIndexSignature.txt @@ -0,0 +1,63 @@ +# mod.ts +export interface Interface { + [index: number]: Interface; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface Interface + + [index: number]: Interface + + +# output.json +[ + { + "kind": "interface", + "name": "Interface", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [ + { + "readonly": false, + "params": [ + { + "kind": "identifier", + "name": "index", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "tsType": { + "repr": "Interface", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Interface" + } + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "typeParams": [] + } + } +] diff --git a/tests/specs/InterfaceMethod.txt b/tests/specs/InterfaceMethod.txt new file mode 100644 index 00000000..4c2dda52 --- /dev/null +++ b/tests/specs/InterfaceMethod.txt @@ -0,0 +1,106 @@ +# mod.ts +export interface I { + m(a, b); + mo?(c); + [mc](d); +} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface I + + m(a, b) + mo?(c) + [mc](d) + + +# output.json +[ + { + "kind": "interface", + "name": "I", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [ + { + "name": "m", + "kind": "method", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "optional": false, + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": null + }, + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": null + } + ], + "returnType": null, + "typeParams": [] + }, + { + "name": "mo", + "kind": "method", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + }, + "optional": true, + "params": [ + { + "kind": "identifier", + "name": "c", + "optional": false, + "tsType": null + } + ], + "returnType": null, + "typeParams": [] + }, + { + "name": "mc", + "kind": "method", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + }, + "computed": true, + "optional": false, + "params": [ + { + "kind": "identifier", + "name": "d", + "optional": false, + "tsType": null + } + ], + "returnType": null, + "typeParams": [] + } + ], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/InterfaceNumberLiteralProperty.txt b/tests/specs/InterfaceNumberLiteralProperty.txt new file mode 100644 index 00000000..3777d9f9 --- /dev/null +++ b/tests/specs/InterfaceNumberLiteralProperty.txt @@ -0,0 +1,71 @@ +# mod.ts +export interface I { + 1: string; + 2?: number; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface I + + 1: string + 2?: number + + +# output.json +[ + { + "kind": "interface", + "name": "I", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [ + { + "name": "1", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + }, + { + "name": "2", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + }, + "params": [], + "computed": false, + "optional": true, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "typeParams": [] + } + ], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/InterfaceProperty.txt b/tests/specs/InterfaceProperty.txt new file mode 100644 index 00000000..3f3a3c86 --- /dev/null +++ b/tests/specs/InterfaceProperty.txt @@ -0,0 +1,110 @@ +# mod.ts +export interface I { + p: string; + po?: number; + readonly pro: string; + [pc]: string; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface I + + p: string + po?: number + readonly pro: string + [pc]: string + + +# output.json +[ + { + "kind": "interface", + "name": "I", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [ + { + "name": "p", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + }, + { + "name": "po", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + }, + "params": [], + "computed": false, + "optional": true, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "typeParams": [] + }, + { + "name": "pro", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + }, + "params": [], + "readonly": true, + "computed": false, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + }, + { + "name": "pc", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 2 + }, + "params": [], + "computed": true, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + } + ], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/InterfaceReadonlyIndexSignature.txt b/tests/specs/InterfaceReadonlyIndexSignature.txt new file mode 100644 index 00000000..3bf7b9f2 --- /dev/null +++ b/tests/specs/InterfaceReadonlyIndexSignature.txt @@ -0,0 +1,63 @@ +# mod.ts +export interface Interface { + readonly [index: number]: Interface; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface Interface + + readonly [index: number]: Interface + + +# output.json +[ + { + "kind": "interface", + "name": "Interface", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [ + { + "readonly": true, + "params": [ + { + "kind": "identifier", + "name": "index", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "tsType": { + "repr": "Interface", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Interface" + } + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "typeParams": [] + } + } +] diff --git a/tests/specs/InterfaceStringLiteralProperty.txt b/tests/specs/InterfaceStringLiteralProperty.txt new file mode 100644 index 00000000..da34d97a --- /dev/null +++ b/tests/specs/InterfaceStringLiteralProperty.txt @@ -0,0 +1,71 @@ +# mod.ts +export interface I { + "p": string; + "po"?: number; +} + +# output.txt +Defined in file:///mod.ts:1:1 + +interface I + + p: string + po?: number + + +# output.json +[ + { + "kind": "interface", + "name": "I", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [ + { + "name": "p", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "params": [], + "computed": false, + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "typeParams": [] + }, + { + "name": "po", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + }, + "params": [], + "computed": false, + "optional": true, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "typeParams": [] + } + ], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + } +] diff --git a/tests/specs/Jsdoc.txt b/tests/specs/Jsdoc.txt new file mode 100644 index 00000000..03667526 --- /dev/null +++ b/tests/specs/Jsdoc.txt @@ -0,0 +1,114 @@ +# mod.ts +/** + * A is a class + * + * Nothing more + */ +export class A {} +/** + * B is an interface + * + * Should be + */ +export interface B {} +/** + * C is a function + * + * Summarised + */ +export function C() {} + +# output.txt +Defined in file:///mod.ts:18:1 + +function C() + C is a function + + Summarised + +Defined in file:///mod.ts:6:1 + +class A + A is a class + + Nothing more + + +Defined in file:///mod.ts:12:1 + +interface B + B is an interface + + Should be + + + +# output.json +[ + { + "kind": "class", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 6, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "A is a class\n\nNothing more" + }, + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + }, + { + "kind": "interface", + "name": "B", + "location": { + "filename": "file:///mod.ts", + "line": 12, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "B is an interface\n\nShould be" + }, + "interfaceDef": { + "extends": [], + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [], + "typeParams": [] + } + }, + { + "kind": "function", + "name": "C", + "location": { + "filename": "file:///mod.ts", + "line": 18, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "C is a function\n\nSummarised" + }, + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/JsdocTags.txt b/tests/specs/JsdocTags.txt new file mode 100644 index 00000000..1fe123c9 --- /dev/null +++ b/tests/specs/JsdocTags.txt @@ -0,0 +1,99 @@ +# mod.ts +/** + * a is a function + * + * @param {string} b some doc + * @param [c=1] additional doc + * @param [d] more doc + * @returns {string} returning doc + */ +export function a(b, c, d) {} + +# output.txt +Defined in file:///mod.ts:9:1 + +function a(b, c, d) + a is a function + + @param {string} b + some doc + + @param [1] c + additional doc + + @param [?] d + more doc + + @return {string} + returning doc + + + +# output.json +[ + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 9, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "a is a function\n", + "tags": [ + { + "kind": "param", + "name": "b", + "type": "string", + "doc": "some doc" + }, + { + "kind": "param", + "name": "c", + "default": "1", + "doc": "additional doc" + }, + { + "kind": "param", + "name": "d", + "optional": true, + "doc": "more doc" + }, + { + "kind": "return", + "type": "string", + "doc": "returning doc" + } + ] + }, + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": null + }, + { + "kind": "identifier", + "name": "c", + "optional": false, + "tsType": null + }, + { + "kind": "identifier", + "name": "d", + "optional": false, + "tsType": null + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/MappedTypes.txt b/tests/specs/MappedTypes.txt new file mode 100644 index 00000000..adb63b9e --- /dev/null +++ b/tests/specs/MappedTypes.txt @@ -0,0 +1,88 @@ +# mod.ts +export type MappedTypeWithNewProperties = { + readonly [Properties in keyof Type as NewKeyType]?: Type[Properties]; +}; + +# output.txt +Defined in file:///mod.ts:1:1 + +type MappedTypeWithNewProperties = readonly [Properties in keyof Type as NewKeyType]?: Type[Properties] + + +# output.json +[ + { + "kind": "typeAlias", + "name": "MappedTypeWithNewProperties", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "", + "kind": "mapped", + "mappedType": { + "readonly": true, + "typeParam": { + "name": "Properties", + "constraint": { + "repr": "", + "kind": "typeOperator", + "typeOperator": { + "operator": "keyof", + "tsType": { + "repr": "Type", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Type" + } + } + } + } + }, + "nameType": { + "repr": "NewKeyType", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "NewKeyType" + } + }, + "optional": true, + "tsType": { + "repr": "", + "kind": "indexedAccess", + "indexedAccess": { + "readonly": false, + "objType": { + "repr": "Type", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Type" + } + }, + "indexType": { + "repr": "Properties", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Properties" + } + } + } + } + } + }, + "typeParams": [ + { + "name": "Type" + } + ] + } + } +] diff --git a/tests/specs/ModuleDocs.txt b/tests/specs/ModuleDocs.txt new file mode 100644 index 00000000..e9f8579c --- /dev/null +++ b/tests/specs/ModuleDocs.txt @@ -0,0 +1,70 @@ +# mod.ts +/* a non-jsdoc comment */ + +/** + * A leading JSDoc comment + * @module + */ + +/** One associated with a class */ +export class A {} + +# output.txt +Defined in file:///mod.ts:3:1 + + A leading JSDoc comment + + @module + +Defined in file:///mod.ts:9:1 + +class A + One associated with a class + + + +# output.json +[ + { + "kind": "moduleDoc", + "name": "", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "A leading JSDoc comment", + "tags": [ + { + "kind": "module" + } + ] + } + }, + { + "kind": "class", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 9, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "One associated with a class" + }, + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/ModuleDocsIgnore.txt b/tests/specs/ModuleDocsIgnore.txt new file mode 100644 index 00000000..b9bc5bb9 --- /dev/null +++ b/tests/specs/ModuleDocsIgnore.txt @@ -0,0 +1,16 @@ +# mod.ts +/* a non-jsdoc comment */ + +/** + * A leading JSDoc comment + * @module + * @ignore + */ + +/** One associated with a class */ +export class A {} + +# output.txt + +# output.json +[] diff --git a/tests/specs/NamespaceDeclaration.txt b/tests/specs/NamespaceDeclaration.txt new file mode 100644 index 00000000..34fcbaeb --- /dev/null +++ b/tests/specs/NamespaceDeclaration.txt @@ -0,0 +1,26 @@ +# mod.ts +export namespace Namespace {} + +# output.txt +Defined in file:///mod.ts:1:1 + +namespace Namespace + + + +# output.json +[ + { + "kind": "namespace", + "name": "Namespace", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "namespaceDef": { + "elements": [] + } + } +] diff --git a/tests/specs/NamespaceDetails.txt b/tests/specs/NamespaceDetails.txt new file mode 100644 index 00000000..d218fbb9 --- /dev/null +++ b/tests/specs/NamespaceDetails.txt @@ -0,0 +1,93 @@ +# mod.ts +export namespace Namespace { + /** + * Doc comment 1 + * + * Details 1 + */ + export function a() {} + /** + * Doc comment 2 + * + * Details 2 + */ + export class B {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +namespace Namespace + + function a() + Doc comment 1 + + Details 1 + class B + Doc comment 2 + + Details 2 + + +# output.json +[ + { + "kind": "namespace", + "name": "Namespace", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "namespaceDef": { + "elements": [ + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 7, + "col": 2 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Doc comment 1\n\nDetails 1" + }, + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "class", + "name": "B", + "location": { + "filename": "file:///mod.ts", + "line": 13, + "col": 2 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Doc comment 2\n\nDetails 2" + }, + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } + ] + } + } +] diff --git a/tests/specs/NamespaceFnOverloads.txt b/tests/specs/NamespaceFnOverloads.txt new file mode 100644 index 00000000..343df1bf --- /dev/null +++ b/tests/specs/NamespaceFnOverloads.txt @@ -0,0 +1,152 @@ +# mod.ts +export namespace Namespace { + export function a(b: string): string; + export function a(b: number): number; + export function a(b: number | string): number | string {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +namespace Namespace + + function a(b: string): string + function a(b: number): number + + +# output.json +[ + { + "kind": "namespace", + "name": "Namespace", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "namespaceDef": { + "elements": [ + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "returnType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 2 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "returnType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + ] + } + } + ], + "returnType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + ] + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } + ] + } + } +] diff --git a/tests/specs/NoAmbientInModule.txt b/tests/specs/NoAmbientInModule.txt new file mode 100644 index 00000000..dc928b71 --- /dev/null +++ b/tests/specs/NoAmbientInModule.txt @@ -0,0 +1,31 @@ +# mod.ts +declare function foo(): number; +export function bar() {}; + +# output.txt +Defined in file:///mod.ts:2:1 + +function bar() + + +# output.json +[ + { + "kind": "function", + "name": "bar", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/NonImplementedRenamedExportsDeclaredEarlier.txt b/tests/specs/NonImplementedRenamedExportsDeclaredEarlier.txt new file mode 100644 index 00000000..ee3ea85f --- /dev/null +++ b/tests/specs/NonImplementedRenamedExportsDeclaredEarlier.txt @@ -0,0 +1,34 @@ +# mod.ts +declare function foo(): void; + export { foo as bar }; + +# output.txt +Defined in file:///mod.ts:1:1 + +function bar(): void + + +# output.json +[ + { + "kind": "function", + "name": "bar", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/OptionalReturnType.txt b/tests/specs/OptionalReturnType.txt new file mode 100644 index 00000000..c1609307 --- /dev/null +++ b/tests/specs/OptionalReturnType.txt @@ -0,0 +1,43 @@ +# mod.ts +export function foo(a: number) { + return a; + } + +# output.txt +Defined in file:///mod.ts:1:1 + +function foo(a: number) + + +# output.json +[ + { + "kind": "function", + "name": "foo", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/Overloads.txt b/tests/specs/Overloads.txt new file mode 100644 index 00000000..42e8a0a1 --- /dev/null +++ b/tests/specs/Overloads.txt @@ -0,0 +1,140 @@ +# mod.ts +export function a(b: string): string; +export function a(b: number): number; +export function a(b: string | number): string | number { + // +} + +# output.txt +Defined in file:///mod.ts:1:1 + +function a(b: string): string + +Defined in file:///mod.ts:2:1 + +function a(b: number): number + + + +# output.json +[ + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "returnType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ], + "returnType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "a", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ] + } + } + ], + "returnType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "string", + "kind": "keyword", + "keyword": "string" + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + ] + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/ReexportExistingExport.txt b/tests/specs/ReexportExistingExport.txt new file mode 100644 index 00000000..fd55fa7b --- /dev/null +++ b/tests/specs/ReexportExistingExport.txt @@ -0,0 +1,61 @@ +# mod.ts +export function foo(): void {} +export { foo as bar }; + +# output.txt +Defined in file:///mod.ts:1:1 + +function bar(): void + +Defined in file:///mod.ts:1:1 + +function foo(): void + + +# output.json +[ + { + "kind": "function", + "name": "foo", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "bar", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [], + "returnType": { + "repr": "void", + "kind": "keyword", + "keyword": "void" + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/StructuredJsdoc.txt b/tests/specs/StructuredJsdoc.txt new file mode 100644 index 00000000..e52311a4 --- /dev/null +++ b/tests/specs/StructuredJsdoc.txt @@ -0,0 +1,186 @@ +# mod.ts +/** Class doc */ +export class A { + /** @private */ + p = false; + + /** + * Some leading documentation here. + * + * @param {string} name some comment + * @param {string} a some other comment that + * spans two lines + * @param {number} b a number + */ + constructor(name, a, b) {} + + /** + * @returns {Promise} + */ + a() {} +} + +# output.txt +Defined in file:///mod.ts:2:1 + +class A + Class doc + + constructor(name, a, b) + Some leading documentation here. + + @param {string} name + some comment + + @param {string} a + some other comment that + spans two lines + + @param {number} b + a number + + p: boolean + + @private + a() + + @return {Promise} + + +# output.json +[ + { + "kind": "class", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "jsDoc": { + "doc": "Class doc" + }, + "classDef": { + "isAbstract": false, + "constructors": [ + { + "jsDoc": { + "doc": "Some leading documentation here.\n", + "tags": [ + { + "kind": "param", + "name": "name", + "type": "string", + "doc": "some comment" + }, + { + "kind": "param", + "name": "a", + "type": "string", + "doc": "some other comment that\nspans two lines" + }, + { + "kind": "param", + "name": "b", + "type": "number", + "doc": "a number" + } + ] + }, + "accessibility": null, + "hasBody": true, + "name": "constructor", + "params": [ + { + "kind": "identifier", + "name": "name", + "optional": false, + "tsType": null + }, + { + "kind": "identifier", + "name": "a", + "optional": false, + "tsType": null + }, + { + "kind": "identifier", + "name": "b", + "optional": false, + "tsType": null + } + ], + "location": { + "filename": "file:///mod.ts", + "line": 14, + "col": 2 + } + } + ], + "properties": [ + { + "jsDoc": { + "tags": [ + { + "kind": "private" + } + ] + }, + "tsType": { + "repr": "boolean", + "kind": "keyword", + "keyword": "boolean" + }, + "readonly": false, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "p", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 2 + } + } + ], + "indexSignatures": [], + "methods": [ + { + "jsDoc": { + "tags": [ + { + "kind": "return", + "type": "Promise" + } + ] + }, + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "a", + "kind": "method", + "functionDef": { + "params": [], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 19, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/TsLitTypes.txt b/tests/specs/TsLitTypes.txt new file mode 100644 index 00000000..1a2f013d --- /dev/null +++ b/tests/specs/TsLitTypes.txt @@ -0,0 +1,168 @@ +# mod.ts +export type boolLit = false; +export type strLit = "text"; +export type tplLit = `text`; +export type tplLitArg = `test${number}`; +export type numLit = 5; + +# output.txt +Defined in file:///mod.ts:1:1 + +type boolLit = false + +Defined in file:///mod.ts:5:1 + +type numLit = 5 + +Defined in file:///mod.ts:2:1 + +type strLit = "text" + +Defined in file:///mod.ts:3:1 + +type tplLit = `text` + +Defined in file:///mod.ts:4:1 + +type tplLitArg = `test${number}` + + +# output.json +[ + { + "kind": "typeAlias", + "name": "boolLit", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "false", + "kind": "literal", + "literal": { + "kind": "boolean", + "boolean": false + } + }, + "typeParams": [] + } + }, + { + "kind": "typeAlias", + "name": "strLit", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "text", + "kind": "literal", + "literal": { + "kind": "string", + "string": "text" + } + }, + "typeParams": [] + } + }, + { + "kind": "typeAlias", + "name": "tplLit", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "text", + "kind": "literal", + "literal": { + "kind": "template", + "tsTypes": [ + { + "repr": "text", + "kind": "literal", + "literal": { + "kind": "string", + "string": "text" + } + } + ] + } + }, + "typeParams": [] + } + }, + { + "kind": "typeAlias", + "name": "tplLitArg", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "test${number}", + "kind": "literal", + "literal": { + "kind": "template", + "tsTypes": [ + { + "repr": "test", + "kind": "literal", + "literal": { + "kind": "string", + "string": "test" + } + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + { + "repr": "", + "kind": "literal", + "literal": { + "kind": "string", + "string": "" + } + } + ] + } + }, + "typeParams": [] + } + }, + { + "kind": "typeAlias", + "name": "numLit", + "location": { + "filename": "file:///mod.ts", + "line": 5, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "5", + "kind": "literal", + "literal": { + "kind": "number", + "number": 5.0 + } + }, + "typeParams": [] + } + } +] diff --git a/tests/specs/TsTemplateWithArgs.txt b/tests/specs/TsTemplateWithArgs.txt new file mode 100644 index 00000000..04f31116 --- /dev/null +++ b/tests/specs/TsTemplateWithArgs.txt @@ -0,0 +1,55 @@ +# mod.ts +export const tpl: `test${number}` = `test1`; + +# output.txt +Defined in file:///mod.ts:1:14 + +const tpl: `test${number}` + + +# output.json +[ + { + "kind": "variable", + "name": "tpl", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 13 + }, + "declarationKind": "export", + "variableDef": { + "tsType": { + "repr": "test${number}", + "kind": "literal", + "literal": { + "kind": "template", + "tsTypes": [ + { + "repr": "test", + "kind": "literal", + "literal": { + "kind": "string", + "string": "test" + } + }, + { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + { + "repr": "", + "kind": "literal", + "literal": { + "kind": "string", + "string": "" + } + } + ] + } + }, + "kind": "const" + } + } +] diff --git a/tests/specs/TsTypeAssertion.txt b/tests/specs/TsTypeAssertion.txt new file mode 100644 index 00000000..79daa962 --- /dev/null +++ b/tests/specs/TsTypeAssertion.txt @@ -0,0 +1,52 @@ +# mod.ts +export function foo(bar: any): asserts bar {} + +# output.txt +Defined in file:///mod.ts:1:1 + +function foo(bar: any): asserts bar + + +# output.json +[ + { + "kind": "function", + "name": "foo", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "bar", + "optional": false, + "tsType": { + "repr": "any", + "kind": "keyword", + "keyword": "any" + } + } + ], + "returnType": { + "repr": "asserts bar", + "kind": "typePredicate", + "typePredicate": { + "asserts": true, + "param": { + "type": "identifier", + "name": "bar" + }, + "type": null + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/TsTypePredicate1.txt b/tests/specs/TsTypePredicate1.txt new file mode 100644 index 00000000..d52bc9a2 --- /dev/null +++ b/tests/specs/TsTypePredicate1.txt @@ -0,0 +1,76 @@ +# mod.ts +export function foo(bar: A | B): bar is A {} + +# output.txt +Defined in file:///mod.ts:1:1 + +function foo(bar: A | B): bar is A + + +# output.json +[ + { + "kind": "function", + "name": "foo", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "bar", + "optional": false, + "tsType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "A", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "A" + } + }, + { + "repr": "B", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "B" + } + } + ] + } + } + ], + "returnType": { + "repr": "bar is A", + "kind": "typePredicate", + "typePredicate": { + "asserts": false, + "param": { + "type": "identifier", + "name": "bar" + }, + "type": { + "repr": "A", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "A" + } + } + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/TsTypePredicate2.txt b/tests/specs/TsTypePredicate2.txt new file mode 100644 index 00000000..da2c7ad4 --- /dev/null +++ b/tests/specs/TsTypePredicate2.txt @@ -0,0 +1,76 @@ +# mod.ts +export function foo(bar: A | B): asserts bar is B {} + +# output.txt +Defined in file:///mod.ts:1:1 + +function foo(bar: A | B): asserts bar is B + + +# output.json +[ + { + "kind": "function", + "name": "foo", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "bar", + "optional": false, + "tsType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "A", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "A" + } + }, + { + "repr": "B", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "B" + } + } + ] + } + } + ], + "returnType": { + "repr": "asserts bar is B", + "kind": "typePredicate", + "typePredicate": { + "asserts": true, + "param": { + "type": "identifier", + "name": "bar" + }, + "type": { + "repr": "B", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "B" + } + } + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + } +] diff --git a/tests/specs/TsTypePredicate3.txt b/tests/specs/TsTypePredicate3.txt new file mode 100644 index 00000000..934fefd2 --- /dev/null +++ b/tests/specs/TsTypePredicate3.txt @@ -0,0 +1,76 @@ +# mod.ts +export class C { + isSomething(): this is Something {} +} + +# output.txt +Defined in file:///mod.ts:1:1 + +class C + + isSomething(): this is Something + + +# output.json +[ + { + "kind": "class", + "name": "C", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "isSomething", + "kind": "method", + "functionDef": { + "params": [], + "returnType": { + "repr": "this is Something", + "kind": "typePredicate", + "typePredicate": { + "asserts": false, + "param": { + "type": "this" + }, + "type": { + "repr": "Something", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Something" + } + } + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/TsUserDefinedTypeGuards.txt b/tests/specs/TsUserDefinedTypeGuards.txt new file mode 100644 index 00000000..0c07b7ca --- /dev/null +++ b/tests/specs/TsUserDefinedTypeGuards.txt @@ -0,0 +1,315 @@ +# mod.ts +export function f1(val1: A | B): val1 is A {} +export function f2(val2: any): asserts val2 is string {} +export function f3(val3: any): asserts val3 {} +export function assertIsDefined(val4: T): asserts val4 is NonNullable { + if (val === undefined || val === null) { + throw new AssertionError( + `Expected 'val' to be defined, but received ${val}` + ); + } +} +export class C { + isSomething(): this is Something { + return this instanceof Something; + } +} + +# output.txt +Defined in file:///mod.ts:4:1 + +function assertIsDefined(val4: T): asserts val4 is NonNullable + +Defined in file:///mod.ts:1:1 + +function f1(val1: A | B): val1 is A + +Defined in file:///mod.ts:2:1 + +function f2(val2: any): asserts val2 is string + +Defined in file:///mod.ts:3:1 + +function f3(val3: any): asserts val3 + +Defined in file:///mod.ts:11:1 + +class C + + isSomething(): this is Something + + +# output.json +[ + { + "kind": "function", + "name": "f1", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "val1", + "optional": false, + "tsType": { + "repr": "", + "kind": "union", + "union": [ + { + "repr": "A", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "A" + } + }, + { + "repr": "B", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "B" + } + } + ] + } + } + ], + "returnType": { + "repr": "val1 is A", + "kind": "typePredicate", + "typePredicate": { + "asserts": false, + "param": { + "type": "identifier", + "name": "val1" + }, + "type": { + "repr": "A", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "A" + } + } + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "f2", + "location": { + "filename": "file:///mod.ts", + "line": 2, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "val2", + "optional": false, + "tsType": { + "repr": "any", + "kind": "keyword", + "keyword": "any" + } + } + ], + "returnType": { + "repr": "asserts val2 is string", + "kind": "typePredicate", + "typePredicate": { + "asserts": true, + "param": { + "type": "identifier", + "name": "val2" + }, + "type": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "f3", + "location": { + "filename": "file:///mod.ts", + "line": 3, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "val3", + "optional": false, + "tsType": { + "repr": "any", + "kind": "keyword", + "keyword": "any" + } + } + ], + "returnType": { + "repr": "asserts val3", + "kind": "typePredicate", + "typePredicate": { + "asserts": true, + "param": { + "type": "identifier", + "name": "val3" + }, + "type": null + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + } + }, + { + "kind": "function", + "name": "assertIsDefined", + "location": { + "filename": "file:///mod.ts", + "line": 4, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "val4", + "optional": false, + "tsType": { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + } + } + ], + "returnType": { + "repr": "asserts val4 is NonNullable", + "kind": "typePredicate", + "typePredicate": { + "asserts": true, + "param": { + "type": "identifier", + "name": "val4" + }, + "type": { + "repr": "NonNullable", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + } + ], + "typeName": "NonNullable" + } + } + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [ + { + "name": "T" + } + ] + } + }, + { + "kind": "class", + "name": "C", + "location": { + "filename": "file:///mod.ts", + "line": 11, + "col": 0 + }, + "declarationKind": "export", + "classDef": { + "isAbstract": false, + "constructors": [], + "properties": [], + "indexSignatures": [], + "methods": [ + { + "accessibility": null, + "optional": false, + "isAbstract": false, + "isStatic": false, + "name": "isSomething", + "kind": "method", + "functionDef": { + "params": [], + "returnType": { + "repr": "this is Something", + "kind": "typePredicate", + "typePredicate": { + "asserts": false, + "param": { + "type": "this" + }, + "type": { + "repr": "Something", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Something" + } + } + } + }, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [] + }, + "location": { + "filename": "file:///mod.ts", + "line": 12, + "col": 2 + } + } + ], + "extends": null, + "implements": [], + "typeParams": [], + "superTypeParams": [] + } + } +] diff --git a/tests/specs/TypeAlias.txt b/tests/specs/TypeAlias.txt new file mode 100644 index 00000000..799e4667 --- /dev/null +++ b/tests/specs/TypeAlias.txt @@ -0,0 +1,30 @@ +# mod.ts +export type A = number + +# output.txt +Defined in file:///mod.ts:1:1 + +type A = number + + +# output.json +[ + { + "kind": "typeAlias", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + }, + "typeParams": [] + } + } +] diff --git a/tests/specs/TypeAliasInferType.txt b/tests/specs/TypeAliasInferType.txt new file mode 100644 index 00000000..7b141d65 --- /dev/null +++ b/tests/specs/TypeAliasInferType.txt @@ -0,0 +1,77 @@ +# mod.ts +export type Flatten = T extends Array ? U : T; + +# output.txt +Defined in file:///mod.ts:1:1 + +type Flatten = T extends Array ? U : T + + +# output.json +[ + { + "kind": "typeAlias", + "name": "Flatten", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "", + "kind": "conditional", + "conditionalType": { + "checkType": { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + }, + "extendsType": { + "repr": "Array", + "kind": "typeRef", + "typeRef": { + "typeParams": [ + { + "repr": "", + "kind": "infer", + "infer": { + "typeParam": { + "name": "U" + } + } + } + ], + "typeName": "Array" + } + }, + "trueType": { + "repr": "U", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "U" + } + }, + "falseType": { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + } + } + }, + "typeParams": [ + { + "name": "T" + } + ] + } + } +] diff --git a/tests/specs/TypeGenericAlias.txt b/tests/specs/TypeGenericAlias.txt new file mode 100644 index 00000000..9b3d858a --- /dev/null +++ b/tests/specs/TypeGenericAlias.txt @@ -0,0 +1,37 @@ +# mod.ts +export type A = T + +# output.txt +Defined in file:///mod.ts:1:1 + +type A = T + + +# output.json +[ + { + "kind": "typeAlias", + "name": "A", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + }, + "typeParams": [ + { + "name": "T" + } + ] + } + } +] diff --git a/tests/specs/TypeImportType.txt b/tests/specs/TypeImportType.txt new file mode 100644 index 00000000..7caea3e8 --- /dev/null +++ b/tests/specs/TypeImportType.txt @@ -0,0 +1,58 @@ +# mod.ts +export function adopt(p: import("./module.ts").Pet) { } + +# output.txt +Defined in file:///mod.ts:1:1 + +function adopt(p: import("./module.ts").Pet) + + +# output.json +[ + { + "kind": "function", + "name": "adopt", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "functionDef": { + "params": [ + { + "kind": "identifier", + "name": "p", + "optional": false, + "tsType": { + "repr": "", + "kind": "importType", + "importType": { + "specifier": "./module.ts", + "qualifier": "Pet", + "typeParams": [ + { + "repr": "T", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "T" + } + } + ] + } + } + } + ], + "returnType": null, + "hasBody": true, + "isAsync": false, + "isGenerator": false, + "typeParams": [ + { + "name": "T" + } + ] + } + } +] diff --git a/tests/specs/TypeLiteralDeclaration.txt b/tests/specs/TypeLiteralDeclaration.txt new file mode 100644 index 00000000..63600798 --- /dev/null +++ b/tests/specs/TypeLiteralDeclaration.txt @@ -0,0 +1,35 @@ +# mod.ts +export type T = {} + +# output.txt +Defined in file:///mod.ts:1:1 + +type T = { } + + +# output.json +[ + { + "kind": "typeAlias", + "name": "T", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "", + "kind": "typeLiteral", + "typeLiteral": { + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [] + } + }, + "typeParams": [] + } + } +] diff --git a/tests/specs/TypeLiteralIndexSignature.txt b/tests/specs/TypeLiteralIndexSignature.txt new file mode 100644 index 00000000..609868fc --- /dev/null +++ b/tests/specs/TypeLiteralIndexSignature.txt @@ -0,0 +1,56 @@ +# mod.ts +export type T = { [key: string]: number; } + +# output.txt +Defined in file:///mod.ts:1:1 + +type T = { [key: string]: number; } + + +# output.json +[ + { + "kind": "typeAlias", + "name": "T", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "", + "kind": "typeLiteral", + "typeLiteral": { + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [ + { + "readonly": false, + "params": [ + { + "kind": "identifier", + "name": "key", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ] + } + }, + "typeParams": [] + } + } +] diff --git a/tests/specs/TypeLiteralMappedType.txt b/tests/specs/TypeLiteralMappedType.txt new file mode 100644 index 00000000..7085a5ed --- /dev/null +++ b/tests/specs/TypeLiteralMappedType.txt @@ -0,0 +1,85 @@ +# mod.ts +export type T = { readonly [P in keyof Type as NewType]: Type[P]; } + +# output.txt +Defined in file:///mod.ts:1:1 + +type T = readonly [P in keyof Type as NewType]: Type[P] + + +# output.json +[ + { + "kind": "typeAlias", + "name": "T", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "", + "kind": "mapped", + "mappedType": { + "readonly": true, + "typeParam": { + "name": "P", + "constraint": { + "repr": "", + "kind": "typeOperator", + "typeOperator": { + "operator": "keyof", + "tsType": { + "repr": "Type", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Type" + } + } + } + } + }, + "nameType": { + "repr": "NewType", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "NewType" + } + }, + "tsType": { + "repr": "", + "kind": "indexedAccess", + "indexedAccess": { + "readonly": false, + "objType": { + "repr": "Type", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "Type" + } + }, + "indexType": { + "repr": "P", + "kind": "typeRef", + "typeRef": { + "typeParams": null, + "typeName": "P" + } + } + } + } + } + }, + "typeParams": [ + { + "name": "Type" + } + ] + } + } +] diff --git a/tests/specs/TypeLiteralReadonlyIndexSignature.txt b/tests/specs/TypeLiteralReadonlyIndexSignature.txt new file mode 100644 index 00000000..e2cf5b53 --- /dev/null +++ b/tests/specs/TypeLiteralReadonlyIndexSignature.txt @@ -0,0 +1,56 @@ +# mod.ts +export type T = { readonly [key: string]: number; } + +# output.txt +Defined in file:///mod.ts:1:1 + +type T = { readonly [key: string]: number; } + + +# output.json +[ + { + "kind": "typeAlias", + "name": "T", + "location": { + "filename": "file:///mod.ts", + "line": 1, + "col": 0 + }, + "declarationKind": "export", + "typeAliasDef": { + "tsType": { + "repr": "", + "kind": "typeLiteral", + "typeLiteral": { + "methods": [], + "properties": [], + "callSignatures": [], + "indexSignatures": [ + { + "readonly": true, + "params": [ + { + "kind": "identifier", + "name": "key", + "optional": false, + "tsType": { + "repr": "string", + "kind": "keyword", + "keyword": "string" + } + } + ], + "tsType": { + "repr": "number", + "kind": "keyword", + "keyword": "number" + } + } + ] + } + }, + "typeParams": [] + } + } +]