From 839fe035fdee6b6e11caeabb3913194a9dda3301 Mon Sep 17 00:00:00 2001 From: Emiliano Santucci Date: Wed, 12 Oct 2016 23:43:35 +0200 Subject: [PATCH 1/9] Ignore new TypeScript 2.0 options Ignore new TypeScript 2.0 options until official typedoc can't manage it --- src/lib/utils/options/sources/typescript.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/utils/options/sources/typescript.ts b/src/lib/utils/options/sources/typescript.ts index 0b6aad05d..fba6c5e3d 100644 --- a/src/lib/utils/options/sources/typescript.ts +++ b/src/lib/utils/options/sources/typescript.ts @@ -17,6 +17,8 @@ export class TypeScriptSource extends OptionsComponent 'out', 'version', 'help', 'watch', 'declaration', 'mapRoot', 'sourceMap', 'inlineSources', 'removeComments' + // Ignore new TypeScript 2.0 options until official typedoc can't manage it + , 'paths', 'lib' ]; From f59651a8942ba36d70db8ce2a6be8110e0137161 Mon Sep 17 00:00:00 2001 From: Emiliano Santucci Date: Wed, 12 Oct 2016 23:52:53 +0200 Subject: [PATCH 2/9] generate libs --- .gitignore | 1 - lib/application.d.ts | 30 ++ lib/application.js | 176 ++++++++++ lib/application.js.map | 1 + lib/cli.d.ts | 17 + lib/cli.js | 109 ++++++ lib/cli.js.map | 1 + lib/converter/components.d.ts | 26 ++ lib/converter/components.js | 34 ++ lib/converter/components.js.map | 1 + lib/converter/context.d.ts | 36 ++ lib/converter/context.js | 173 ++++++++++ lib/converter/context.js.map | 1 + lib/converter/convert-expression.d.ts | 3 + lib/converter/convert-expression.js | 28 ++ lib/converter/convert-expression.js.map | 1 + lib/converter/converter.d.ts | 47 +++ lib/converter/converter.js | 232 +++++++++++++ lib/converter/converter.js.map | 1 + lib/converter/factories/comment.d.ts | 5 + lib/converter/factories/comment.js | 132 ++++++++ lib/converter/factories/comment.js.map | 1 + lib/converter/factories/declaration.d.ts | 4 + lib/converter/factories/declaration.js | 128 +++++++ lib/converter/factories/declaration.js.map | 1 + lib/converter/factories/index.d.ts | 6 + lib/converter/factories/index.js | 14 + lib/converter/factories/index.js.map | 1 + lib/converter/factories/parameter.d.ts | 4 + lib/converter/factories/parameter.js | 33 ++ lib/converter/factories/parameter.js.map | 1 + lib/converter/factories/reference.d.ts | 4 + lib/converter/factories/reference.js | 13 + lib/converter/factories/reference.js.map | 1 + lib/converter/factories/signature.d.ts | 4 + lib/converter/factories/signature.js | 43 +++ lib/converter/factories/signature.js.map | 1 + lib/converter/factories/type-parameter.d.ts | 4 + lib/converter/factories/type-parameter.js | 20 ++ lib/converter/factories/type-parameter.js.map | 1 + lib/converter/index.d.ts | 6 + lib/converter/index.js | 12 + lib/converter/index.js.map | 1 + lib/converter/nodes/accessor.d.ts | 8 + lib/converter/nodes/accessor.js | 44 +++ lib/converter/nodes/accessor.js.map | 1 + lib/converter/nodes/alias.d.ts | 8 + lib/converter/nodes/alias.js | 39 +++ lib/converter/nodes/alias.js.map | 1 + lib/converter/nodes/block.d.ts | 15 + lib/converter/nodes/block.js | 100 ++++++ lib/converter/nodes/block.js.map | 1 + lib/converter/nodes/class.d.ts | 8 + lib/converter/nodes/class.js | 77 +++++ lib/converter/nodes/class.js.map | 1 + lib/converter/nodes/constructor.d.ts | 9 + lib/converter/nodes/constructor.js | 77 +++++ lib/converter/nodes/constructor.js.map | 1 + lib/converter/nodes/enum.d.ts | 9 + lib/converter/nodes/enum.js | 52 +++ lib/converter/nodes/enum.js.map | 1 + lib/converter/nodes/export.d.ts | 8 + lib/converter/nodes/export.js | 62 ++++ lib/converter/nodes/export.js.map | 1 + lib/converter/nodes/function.d.ts | 8 + lib/converter/nodes/function.js | 52 +++ lib/converter/nodes/function.js.map | 1 + lib/converter/nodes/index.d.ts | 16 + lib/converter/nodes/index.js | 34 ++ lib/converter/nodes/index.js.map | 1 + lib/converter/nodes/interface.d.ts | 8 + lib/converter/nodes/interface.js | 65 ++++ lib/converter/nodes/interface.js.map | 1 + lib/converter/nodes/literal-object.d.ts | 8 + lib/converter/nodes/literal-object.js | 38 +++ lib/converter/nodes/literal-object.js.map | 1 + lib/converter/nodes/literal-type.d.ts | 8 + lib/converter/nodes/literal-type.js | 38 +++ lib/converter/nodes/literal-type.js.map | 1 + lib/converter/nodes/module.d.ts | 8 + lib/converter/nodes/module.js | 47 +++ lib/converter/nodes/module.js.map | 1 + lib/converter/nodes/signature-call.d.ts | 8 + lib/converter/nodes/signature-call.js | 45 +++ lib/converter/nodes/signature-call.js.map | 1 + lib/converter/nodes/signature-index.d.ts | 8 + lib/converter/nodes/signature-index.js | 38 +++ lib/converter/nodes/signature-index.js.map | 1 + lib/converter/nodes/variable-statement.d.ts | 9 + lib/converter/nodes/variable-statement.js | 52 +++ lib/converter/nodes/variable-statement.js.map | 1 + lib/converter/nodes/variable.d.ts | 9 + lib/converter/nodes/variable.js | 98 ++++++ lib/converter/nodes/variable.js.map | 1 + lib/converter/plugins/CommentPlugin.d.ts | 18 + lib/converter/plugins/CommentPlugin.js | 257 ++++++++++++++ lib/converter/plugins/CommentPlugin.js.map | 1 + lib/converter/plugins/DecoratorPlugin.d.ts | 9 + lib/converter/plugins/DecoratorPlugin.js | 108 ++++++ lib/converter/plugins/DecoratorPlugin.js.map | 1 + lib/converter/plugins/DeepCommentPlugin.d.ts | 5 + lib/converter/plugins/DeepCommentPlugin.js | 74 +++++ .../plugins/DeepCommentPlugin.js.map | 1 + .../plugins/DynamicModulePlugin.d.ts | 9 + lib/converter/plugins/DynamicModulePlugin.js | 62 ++++ .../plugins/DynamicModulePlugin.js.map | 1 + lib/converter/plugins/GitHubPlugin.d.ts | 8 + lib/converter/plugins/GitHubPlugin.js | 144 ++++++++ lib/converter/plugins/GitHubPlugin.js.map | 1 + lib/converter/plugins/GroupPlugin.d.ts | 16 + lib/converter/plugins/GroupPlugin.js | 180 ++++++++++ lib/converter/plugins/GroupPlugin.js.map | 1 + lib/converter/plugins/ImplementsPlugin.d.ts | 7 + lib/converter/plugins/ImplementsPlugin.js | 96 ++++++ lib/converter/plugins/ImplementsPlugin.js.map | 1 + lib/converter/plugins/PackagePlugin.d.ts | 12 + lib/converter/plugins/PackagePlugin.js | 96 ++++++ lib/converter/plugins/PackagePlugin.js.map | 1 + lib/converter/plugins/SourcePlugin.d.ts | 13 + lib/converter/plugins/SourcePlugin.js | 128 +++++++ lib/converter/plugins/SourcePlugin.js.map | 1 + lib/converter/plugins/TypePlugin.d.ts | 9 + lib/converter/plugins/TypePlugin.js | 151 +++++++++ lib/converter/plugins/TypePlugin.js.map | 1 + lib/converter/plugins/index.d.ts | 10 + lib/converter/plugins/index.js | 22 ++ lib/converter/plugins/index.js.map | 1 + lib/converter/types/alias.d.ts | 9 + lib/converter/types/alias.js | 51 +++ lib/converter/types/alias.js.map | 1 + lib/converter/types/array.d.ts | 8 + lib/converter/types/array.js | 40 +++ lib/converter/types/array.js.map | 1 + lib/converter/types/binding-array.d.ts | 8 + lib/converter/types/binding-array.js | 38 +++ lib/converter/types/binding-array.js.map | 1 + lib/converter/types/binding-object.d.ts | 8 + lib/converter/types/binding-object.js | 46 +++ lib/converter/types/binding-object.js.map | 1 + lib/converter/types/enum.d.ts | 8 + lib/converter/types/enum.js | 33 ++ lib/converter/types/enum.js.map | 1 + lib/converter/types/index.d.ts | 12 + lib/converter/types/index.js | 26 ++ lib/converter/types/index.js.map | 1 + lib/converter/types/intrinsic.d.ts | 8 + lib/converter/types/intrinsic.js | 33 ++ lib/converter/types/intrinsic.js.map | 1 + lib/converter/types/reference.d.ts | 12 + lib/converter/types/reference.js | 92 +++++ lib/converter/types/reference.js.map | 1 + lib/converter/types/string-literal.d.ts | 10 + lib/converter/types/string-literal.js | 39 +++ lib/converter/types/string-literal.js.map | 1 + lib/converter/types/tuple.d.ts | 10 + lib/converter/types/tuple.js | 55 +++ lib/converter/types/tuple.js.map | 1 + lib/converter/types/type-parameter.d.ts | 9 + lib/converter/types/type-parameter.js | 42 +++ lib/converter/types/type-parameter.js.map | 1 + lib/converter/types/union.d.ts | 10 + lib/converter/types/union.js | 55 +++ lib/converter/types/union.js.map | 1 + lib/converter/types/unknown.d.ts | 9 + lib/converter/types/unknown.js | 34 ++ lib/converter/types/unknown.js.map | 1 + lib/converter/utils/base-path.d.ts | 7 + lib/converter/utils/base-path.js | 53 +++ lib/converter/utils/base-path.js.map | 1 + lib/converter/utils/compiler-host.d.ts | 15 + lib/converter/utils/compiler-host.js | 58 ++++ lib/converter/utils/compiler-host.js.map | 1 + lib/models/ReflectionGroup.d.ts | 16 + lib/models/ReflectionGroup.js | 34 ++ lib/models/ReflectionGroup.js.map | 1 + lib/models/comments/comment.d.ts | 13 + lib/models/comments/comment.js | 55 +++ lib/models/comments/comment.js.map | 1 + lib/models/comments/index.d.ts | 2 + lib/models/comments/index.js | 6 + lib/models/comments/index.js.map | 1 + lib/models/comments/tag.d.ts | 7 + lib/models/comments/tag.js | 21 ++ lib/models/comments/tag.js.map | 1 + lib/models/index.d.ts | 4 + lib/models/index.js | 9 + lib/models/index.js.map | 1 + lib/models/reflections/abstract.d.ts | 125 +++++++ lib/models/reflections/abstract.js | 287 ++++++++++++++++ lib/models/reflections/abstract.js.map | 1 + lib/models/reflections/container.d.ts | 10 + lib/models/reflections/container.js | 55 +++ lib/models/reflections/container.js.map | 1 + lib/models/reflections/declaration.d.ts | 32 ++ lib/models/reflections/declaration.js | 99 ++++++ lib/models/reflections/declaration.js.map | 1 + lib/models/reflections/index.d.ts | 7 + lib/models/reflections/index.js | 19 ++ lib/models/reflections/index.js.map | 1 + lib/models/reflections/parameter.d.ts | 11 + lib/models/reflections/parameter.js | 36 ++ lib/models/reflections/parameter.js.map | 1 + lib/models/reflections/project.d.ts | 21 ++ lib/models/reflections/project.js | 54 +++ lib/models/reflections/project.js.map | 1 + lib/models/reflections/signature.d.ts | 18 + lib/models/reflections/signature.js | 62 ++++ lib/models/reflections/signature.js.map | 1 + lib/models/reflections/type-parameter.d.ts | 9 + lib/models/reflections/type-parameter.js | 24 ++ lib/models/reflections/type-parameter.js.map | 1 + lib/models/sources/directory.d.ts | 17 + lib/models/sources/directory.js | 38 +++ lib/models/sources/directory.js.map | 1 + lib/models/sources/file.d.ts | 20 ++ lib/models/sources/file.js | 13 + lib/models/sources/file.js.map | 1 + lib/models/sources/index.d.ts | 2 + lib/models/sources/index.js | 6 + lib/models/sources/index.js.map | 1 + lib/models/types/abstract.d.ts | 9 + lib/models/types/abstract.js | 46 +++ lib/models/types/abstract.js.map | 1 + lib/models/types/index.d.ts | 9 + lib/models/types/index.js | 20 ++ lib/models/types/index.js.map | 1 + lib/models/types/intrinsic.d.ts | 9 + lib/models/types/intrinsic.js | 36 ++ lib/models/types/intrinsic.js.map | 1 + lib/models/types/reference.d.ts | 15 + lib/models/types/reference.js | 52 +++ lib/models/types/reference.js.map | 1 + lib/models/types/reflection.d.ts | 10 + lib/models/types/reflection.js | 41 +++ lib/models/types/reflection.js.map | 1 + lib/models/types/string-literal.d.ts | 9 + lib/models/types/string-literal.js | 36 ++ lib/models/types/string-literal.js.map | 1 + lib/models/types/tuple.d.ts | 9 + lib/models/types/tuple.js | 44 +++ lib/models/types/tuple.js.map | 1 + lib/models/types/type-parameter.d.ts | 9 + lib/models/types/type-parameter.js | 52 +++ lib/models/types/type-parameter.js.map | 1 + lib/models/types/union.d.ts | 9 + lib/models/types/union.js | 44 +++ lib/models/types/union.js.map | 1 + lib/models/types/unknown.d.ts | 9 + lib/models/types/unknown.js | 36 ++ lib/models/types/unknown.js.map | 1 + lib/output/components.d.ts | 16 + lib/output/components.js | 47 +++ lib/output/components.js.map | 1 + lib/output/events.d.ts | 32 ++ lib/output/events.js | 48 +++ lib/output/events.js.map | 1 + lib/output/helpers/compact.d.ts | 1 + lib/output/helpers/compact.js | 10 + lib/output/helpers/compact.js.map | 1 + lib/output/helpers/if-cond.d.ts | 1 + lib/output/helpers/if-cond.js | 25 ++ lib/output/helpers/if-cond.js.map | 1 + lib/output/helpers/if-signature.d.ts | 1 + lib/output/helpers/if-signature.js | 12 + lib/output/helpers/if-signature.js.map | 1 + lib/output/helpers/wbr.d.ts | 1 + lib/output/helpers/wbr.js | 9 + lib/output/helpers/wbr.js.map | 1 + lib/output/models/NavigationItem.d.ts | 16 + lib/output/models/NavigationItem.js | 34 ++ lib/output/models/NavigationItem.js.map | 1 + lib/output/models/UrlMapping.d.ts | 6 + lib/output/models/UrlMapping.js | 11 + lib/output/models/UrlMapping.js.map | 1 + lib/output/plugins/AssetsPlugin.d.ts | 6 + lib/output/plugins/AssetsPlugin.js | 51 +++ lib/output/plugins/AssetsPlugin.js.map | 1 + lib/output/plugins/JavascriptIndexPlugin.d.ts | 5 + lib/output/plugins/JavascriptIndexPlugin.js | 70 ++++ .../plugins/JavascriptIndexPlugin.js.map | 1 + lib/output/plugins/LayoutPlugin.d.ts | 5 + lib/output/plugins/LayoutPlugin.js | 33 ++ lib/output/plugins/LayoutPlugin.js.map | 1 + lib/output/plugins/MarkedLinksPlugin.d.ts | 16 + lib/output/plugins/MarkedLinksPlugin.js | 101 ++++++ lib/output/plugins/MarkedLinksPlugin.js.map | 1 + lib/output/plugins/MarkedPlugin.d.ts | 15 + lib/output/plugins/MarkedPlugin.js | 137 ++++++++ lib/output/plugins/MarkedPlugin.js.map | 1 + lib/output/plugins/NavigationPlugin.d.ts | 8 + lib/output/plugins/NavigationPlugin.js | 72 ++++ lib/output/plugins/NavigationPlugin.js.map | 1 + lib/output/plugins/PrettyPrintPlugin.d.ts | 8 + lib/output/plugins/PrettyPrintPlugin.js | 138 ++++++++ lib/output/plugins/PrettyPrintPlugin.js.map | 1 + lib/output/plugins/TocPlugin.d.ts | 8 + lib/output/plugins/TocPlugin.js | 72 ++++ lib/output/plugins/TocPlugin.js.map | 1 + lib/output/plugins/index.d.ts | 8 + lib/output/plugins/index.js | 18 + lib/output/plugins/index.js.map | 1 + lib/output/renderer.d.ts | 22 ++ lib/output/renderer.js | 178 ++++++++++ lib/output/renderer.js.map | 1 + lib/output/theme.d.ts | 14 + lib/output/theme.js | 38 +++ lib/output/theme.js.map | 1 + lib/output/themes/DefaultTheme.d.ts | 28 ++ lib/output/themes/DefaultTheme.js | 313 ++++++++++++++++++ lib/output/themes/DefaultTheme.js.map | 1 + lib/output/themes/MinimalTheme.d.ts | 12 + lib/output/themes/MinimalTheme.js | 58 ++++ lib/output/themes/MinimalTheme.js.map | 1 + lib/output/utils/resources.d.ts | 18 + lib/output/utils/resources.js | 74 +++++ lib/output/utils/resources.js.map | 1 + lib/output/utils/resources/helpers.d.ts | 13 + lib/output/utils/resources/helpers.js | 75 +++++ lib/output/utils/resources/helpers.js.map | 1 + lib/output/utils/resources/stack.d.ts | 43 +++ lib/output/utils/resources/stack.js | 173 ++++++++++ lib/output/utils/resources/stack.js.map | 1 + lib/output/utils/resources/templates.d.ts | 14 + lib/output/utils/resources/templates.js | 72 ++++ lib/output/utils/resources/templates.js.map | 1 + lib/utils/component.d.ts | 47 +++ lib/utils/component.js | 181 ++++++++++ lib/utils/component.js.map | 1 + lib/utils/events.d.ts | 31 ++ lib/utils/events.js | 268 +++++++++++++++ lib/utils/events.js.map | 1 + lib/utils/fs.d.ts | 5 + lib/utils/fs.js | 67 ++++ lib/utils/fs.js.map | 1 + lib/utils/index.d.ts | 5 + lib/utils/index.js | 22 ++ lib/utils/index.js.map | 1 + lib/utils/loggers.d.ts | 30 ++ lib/utils/loggers.js | 146 ++++++++ lib/utils/loggers.js.map | 1 + lib/utils/options/declaration.d.ts | 45 +++ lib/utils/options/declaration.js | 66 ++++ lib/utils/options/declaration.js.map | 1 + lib/utils/options/help.d.ts | 7 + lib/utils/options/help.js | 58 ++++ lib/utils/options/help.js.map | 1 + lib/utils/options/index.d.ts | 3 + lib/utils/options/index.js | 7 + lib/utils/options/index.js.map | 1 + lib/utils/options/options.d.ts | 42 +++ lib/utils/options/options.js | 199 +++++++++++ lib/utils/options/options.js.map | 1 + lib/utils/options/readers/arguments.d.ts | 7 + lib/utils/options/readers/arguments.js | 105 ++++++ lib/utils/options/readers/arguments.js.map | 1 + lib/utils/options/readers/index.d.ts | 3 + lib/utils/options/readers/index.js | 8 + lib/utils/options/readers/index.js.map | 1 + lib/utils/options/readers/tsconfig.d.ts | 8 + lib/utils/options/readers/tsconfig.js | 85 +++++ lib/utils/options/readers/tsconfig.js.map | 1 + lib/utils/options/readers/typedoc.d.ts | 8 + lib/utils/options/readers/typedoc.js | 81 +++++ lib/utils/options/readers/typedoc.js.map | 1 + lib/utils/options/sources/component.d.ts | 9 + lib/utils/options/sources/component.js | 80 +++++ lib/utils/options/sources/component.js.map | 1 + lib/utils/options/sources/index.d.ts | 2 + lib/utils/options/sources/index.js | 6 + lib/utils/options/sources/index.js.map | 1 + lib/utils/options/sources/typescript.d.ts | 9 + lib/utils/options/sources/typescript.js | 83 +++++ lib/utils/options/sources/typescript.js.map | 1 + lib/utils/plugins.d.ts | 7 + lib/utils/plugins.js | 121 +++++++ lib/utils/plugins.js.map | 1 + 376 files changed, 10526 insertions(+), 1 deletion(-) create mode 100644 lib/application.d.ts create mode 100644 lib/application.js create mode 100644 lib/application.js.map create mode 100644 lib/cli.d.ts create mode 100644 lib/cli.js create mode 100644 lib/cli.js.map create mode 100644 lib/converter/components.d.ts create mode 100644 lib/converter/components.js create mode 100644 lib/converter/components.js.map create mode 100644 lib/converter/context.d.ts create mode 100644 lib/converter/context.js create mode 100644 lib/converter/context.js.map create mode 100644 lib/converter/convert-expression.d.ts create mode 100644 lib/converter/convert-expression.js create mode 100644 lib/converter/convert-expression.js.map create mode 100644 lib/converter/converter.d.ts create mode 100644 lib/converter/converter.js create mode 100644 lib/converter/converter.js.map create mode 100644 lib/converter/factories/comment.d.ts create mode 100644 lib/converter/factories/comment.js create mode 100644 lib/converter/factories/comment.js.map create mode 100644 lib/converter/factories/declaration.d.ts create mode 100644 lib/converter/factories/declaration.js create mode 100644 lib/converter/factories/declaration.js.map create mode 100644 lib/converter/factories/index.d.ts create mode 100644 lib/converter/factories/index.js create mode 100644 lib/converter/factories/index.js.map create mode 100644 lib/converter/factories/parameter.d.ts create mode 100644 lib/converter/factories/parameter.js create mode 100644 lib/converter/factories/parameter.js.map create mode 100644 lib/converter/factories/reference.d.ts create mode 100644 lib/converter/factories/reference.js create mode 100644 lib/converter/factories/reference.js.map create mode 100644 lib/converter/factories/signature.d.ts create mode 100644 lib/converter/factories/signature.js create mode 100644 lib/converter/factories/signature.js.map create mode 100644 lib/converter/factories/type-parameter.d.ts create mode 100644 lib/converter/factories/type-parameter.js create mode 100644 lib/converter/factories/type-parameter.js.map create mode 100644 lib/converter/index.d.ts create mode 100644 lib/converter/index.js create mode 100644 lib/converter/index.js.map create mode 100644 lib/converter/nodes/accessor.d.ts create mode 100644 lib/converter/nodes/accessor.js create mode 100644 lib/converter/nodes/accessor.js.map create mode 100644 lib/converter/nodes/alias.d.ts create mode 100644 lib/converter/nodes/alias.js create mode 100644 lib/converter/nodes/alias.js.map create mode 100644 lib/converter/nodes/block.d.ts create mode 100644 lib/converter/nodes/block.js create mode 100644 lib/converter/nodes/block.js.map create mode 100644 lib/converter/nodes/class.d.ts create mode 100644 lib/converter/nodes/class.js create mode 100644 lib/converter/nodes/class.js.map create mode 100644 lib/converter/nodes/constructor.d.ts create mode 100644 lib/converter/nodes/constructor.js create mode 100644 lib/converter/nodes/constructor.js.map create mode 100644 lib/converter/nodes/enum.d.ts create mode 100644 lib/converter/nodes/enum.js create mode 100644 lib/converter/nodes/enum.js.map create mode 100644 lib/converter/nodes/export.d.ts create mode 100644 lib/converter/nodes/export.js create mode 100644 lib/converter/nodes/export.js.map create mode 100644 lib/converter/nodes/function.d.ts create mode 100644 lib/converter/nodes/function.js create mode 100644 lib/converter/nodes/function.js.map create mode 100644 lib/converter/nodes/index.d.ts create mode 100644 lib/converter/nodes/index.js create mode 100644 lib/converter/nodes/index.js.map create mode 100644 lib/converter/nodes/interface.d.ts create mode 100644 lib/converter/nodes/interface.js create mode 100644 lib/converter/nodes/interface.js.map create mode 100644 lib/converter/nodes/literal-object.d.ts create mode 100644 lib/converter/nodes/literal-object.js create mode 100644 lib/converter/nodes/literal-object.js.map create mode 100644 lib/converter/nodes/literal-type.d.ts create mode 100644 lib/converter/nodes/literal-type.js create mode 100644 lib/converter/nodes/literal-type.js.map create mode 100644 lib/converter/nodes/module.d.ts create mode 100644 lib/converter/nodes/module.js create mode 100644 lib/converter/nodes/module.js.map create mode 100644 lib/converter/nodes/signature-call.d.ts create mode 100644 lib/converter/nodes/signature-call.js create mode 100644 lib/converter/nodes/signature-call.js.map create mode 100644 lib/converter/nodes/signature-index.d.ts create mode 100644 lib/converter/nodes/signature-index.js create mode 100644 lib/converter/nodes/signature-index.js.map create mode 100644 lib/converter/nodes/variable-statement.d.ts create mode 100644 lib/converter/nodes/variable-statement.js create mode 100644 lib/converter/nodes/variable-statement.js.map create mode 100644 lib/converter/nodes/variable.d.ts create mode 100644 lib/converter/nodes/variable.js create mode 100644 lib/converter/nodes/variable.js.map create mode 100644 lib/converter/plugins/CommentPlugin.d.ts create mode 100644 lib/converter/plugins/CommentPlugin.js create mode 100644 lib/converter/plugins/CommentPlugin.js.map create mode 100644 lib/converter/plugins/DecoratorPlugin.d.ts create mode 100644 lib/converter/plugins/DecoratorPlugin.js create mode 100644 lib/converter/plugins/DecoratorPlugin.js.map create mode 100644 lib/converter/plugins/DeepCommentPlugin.d.ts create mode 100644 lib/converter/plugins/DeepCommentPlugin.js create mode 100644 lib/converter/plugins/DeepCommentPlugin.js.map create mode 100644 lib/converter/plugins/DynamicModulePlugin.d.ts create mode 100644 lib/converter/plugins/DynamicModulePlugin.js create mode 100644 lib/converter/plugins/DynamicModulePlugin.js.map create mode 100644 lib/converter/plugins/GitHubPlugin.d.ts create mode 100644 lib/converter/plugins/GitHubPlugin.js create mode 100644 lib/converter/plugins/GitHubPlugin.js.map create mode 100644 lib/converter/plugins/GroupPlugin.d.ts create mode 100644 lib/converter/plugins/GroupPlugin.js create mode 100644 lib/converter/plugins/GroupPlugin.js.map create mode 100644 lib/converter/plugins/ImplementsPlugin.d.ts create mode 100644 lib/converter/plugins/ImplementsPlugin.js create mode 100644 lib/converter/plugins/ImplementsPlugin.js.map create mode 100644 lib/converter/plugins/PackagePlugin.d.ts create mode 100644 lib/converter/plugins/PackagePlugin.js create mode 100644 lib/converter/plugins/PackagePlugin.js.map create mode 100644 lib/converter/plugins/SourcePlugin.d.ts create mode 100644 lib/converter/plugins/SourcePlugin.js create mode 100644 lib/converter/plugins/SourcePlugin.js.map create mode 100644 lib/converter/plugins/TypePlugin.d.ts create mode 100644 lib/converter/plugins/TypePlugin.js create mode 100644 lib/converter/plugins/TypePlugin.js.map create mode 100644 lib/converter/plugins/index.d.ts create mode 100644 lib/converter/plugins/index.js create mode 100644 lib/converter/plugins/index.js.map create mode 100644 lib/converter/types/alias.d.ts create mode 100644 lib/converter/types/alias.js create mode 100644 lib/converter/types/alias.js.map create mode 100644 lib/converter/types/array.d.ts create mode 100644 lib/converter/types/array.js create mode 100644 lib/converter/types/array.js.map create mode 100644 lib/converter/types/binding-array.d.ts create mode 100644 lib/converter/types/binding-array.js create mode 100644 lib/converter/types/binding-array.js.map create mode 100644 lib/converter/types/binding-object.d.ts create mode 100644 lib/converter/types/binding-object.js create mode 100644 lib/converter/types/binding-object.js.map create mode 100644 lib/converter/types/enum.d.ts create mode 100644 lib/converter/types/enum.js create mode 100644 lib/converter/types/enum.js.map create mode 100644 lib/converter/types/index.d.ts create mode 100644 lib/converter/types/index.js create mode 100644 lib/converter/types/index.js.map create mode 100644 lib/converter/types/intrinsic.d.ts create mode 100644 lib/converter/types/intrinsic.js create mode 100644 lib/converter/types/intrinsic.js.map create mode 100644 lib/converter/types/reference.d.ts create mode 100644 lib/converter/types/reference.js create mode 100644 lib/converter/types/reference.js.map create mode 100644 lib/converter/types/string-literal.d.ts create mode 100644 lib/converter/types/string-literal.js create mode 100644 lib/converter/types/string-literal.js.map create mode 100644 lib/converter/types/tuple.d.ts create mode 100644 lib/converter/types/tuple.js create mode 100644 lib/converter/types/tuple.js.map create mode 100644 lib/converter/types/type-parameter.d.ts create mode 100644 lib/converter/types/type-parameter.js create mode 100644 lib/converter/types/type-parameter.js.map create mode 100644 lib/converter/types/union.d.ts create mode 100644 lib/converter/types/union.js create mode 100644 lib/converter/types/union.js.map create mode 100644 lib/converter/types/unknown.d.ts create mode 100644 lib/converter/types/unknown.js create mode 100644 lib/converter/types/unknown.js.map create mode 100644 lib/converter/utils/base-path.d.ts create mode 100644 lib/converter/utils/base-path.js create mode 100644 lib/converter/utils/base-path.js.map create mode 100644 lib/converter/utils/compiler-host.d.ts create mode 100644 lib/converter/utils/compiler-host.js create mode 100644 lib/converter/utils/compiler-host.js.map create mode 100644 lib/models/ReflectionGroup.d.ts create mode 100644 lib/models/ReflectionGroup.js create mode 100644 lib/models/ReflectionGroup.js.map create mode 100644 lib/models/comments/comment.d.ts create mode 100644 lib/models/comments/comment.js create mode 100644 lib/models/comments/comment.js.map create mode 100644 lib/models/comments/index.d.ts create mode 100644 lib/models/comments/index.js create mode 100644 lib/models/comments/index.js.map create mode 100644 lib/models/comments/tag.d.ts create mode 100644 lib/models/comments/tag.js create mode 100644 lib/models/comments/tag.js.map create mode 100644 lib/models/index.d.ts create mode 100644 lib/models/index.js create mode 100644 lib/models/index.js.map create mode 100644 lib/models/reflections/abstract.d.ts create mode 100644 lib/models/reflections/abstract.js create mode 100644 lib/models/reflections/abstract.js.map create mode 100644 lib/models/reflections/container.d.ts create mode 100644 lib/models/reflections/container.js create mode 100644 lib/models/reflections/container.js.map create mode 100644 lib/models/reflections/declaration.d.ts create mode 100644 lib/models/reflections/declaration.js create mode 100644 lib/models/reflections/declaration.js.map create mode 100644 lib/models/reflections/index.d.ts create mode 100644 lib/models/reflections/index.js create mode 100644 lib/models/reflections/index.js.map create mode 100644 lib/models/reflections/parameter.d.ts create mode 100644 lib/models/reflections/parameter.js create mode 100644 lib/models/reflections/parameter.js.map create mode 100644 lib/models/reflections/project.d.ts create mode 100644 lib/models/reflections/project.js create mode 100644 lib/models/reflections/project.js.map create mode 100644 lib/models/reflections/signature.d.ts create mode 100644 lib/models/reflections/signature.js create mode 100644 lib/models/reflections/signature.js.map create mode 100644 lib/models/reflections/type-parameter.d.ts create mode 100644 lib/models/reflections/type-parameter.js create mode 100644 lib/models/reflections/type-parameter.js.map create mode 100644 lib/models/sources/directory.d.ts create mode 100644 lib/models/sources/directory.js create mode 100644 lib/models/sources/directory.js.map create mode 100644 lib/models/sources/file.d.ts create mode 100644 lib/models/sources/file.js create mode 100644 lib/models/sources/file.js.map create mode 100644 lib/models/sources/index.d.ts create mode 100644 lib/models/sources/index.js create mode 100644 lib/models/sources/index.js.map create mode 100644 lib/models/types/abstract.d.ts create mode 100644 lib/models/types/abstract.js create mode 100644 lib/models/types/abstract.js.map create mode 100644 lib/models/types/index.d.ts create mode 100644 lib/models/types/index.js create mode 100644 lib/models/types/index.js.map create mode 100644 lib/models/types/intrinsic.d.ts create mode 100644 lib/models/types/intrinsic.js create mode 100644 lib/models/types/intrinsic.js.map create mode 100644 lib/models/types/reference.d.ts create mode 100644 lib/models/types/reference.js create mode 100644 lib/models/types/reference.js.map create mode 100644 lib/models/types/reflection.d.ts create mode 100644 lib/models/types/reflection.js create mode 100644 lib/models/types/reflection.js.map create mode 100644 lib/models/types/string-literal.d.ts create mode 100644 lib/models/types/string-literal.js create mode 100644 lib/models/types/string-literal.js.map create mode 100644 lib/models/types/tuple.d.ts create mode 100644 lib/models/types/tuple.js create mode 100644 lib/models/types/tuple.js.map create mode 100644 lib/models/types/type-parameter.d.ts create mode 100644 lib/models/types/type-parameter.js create mode 100644 lib/models/types/type-parameter.js.map create mode 100644 lib/models/types/union.d.ts create mode 100644 lib/models/types/union.js create mode 100644 lib/models/types/union.js.map create mode 100644 lib/models/types/unknown.d.ts create mode 100644 lib/models/types/unknown.js create mode 100644 lib/models/types/unknown.js.map create mode 100644 lib/output/components.d.ts create mode 100644 lib/output/components.js create mode 100644 lib/output/components.js.map create mode 100644 lib/output/events.d.ts create mode 100644 lib/output/events.js create mode 100644 lib/output/events.js.map create mode 100644 lib/output/helpers/compact.d.ts create mode 100644 lib/output/helpers/compact.js create mode 100644 lib/output/helpers/compact.js.map create mode 100644 lib/output/helpers/if-cond.d.ts create mode 100644 lib/output/helpers/if-cond.js create mode 100644 lib/output/helpers/if-cond.js.map create mode 100644 lib/output/helpers/if-signature.d.ts create mode 100644 lib/output/helpers/if-signature.js create mode 100644 lib/output/helpers/if-signature.js.map create mode 100644 lib/output/helpers/wbr.d.ts create mode 100644 lib/output/helpers/wbr.js create mode 100644 lib/output/helpers/wbr.js.map create mode 100644 lib/output/models/NavigationItem.d.ts create mode 100644 lib/output/models/NavigationItem.js create mode 100644 lib/output/models/NavigationItem.js.map create mode 100644 lib/output/models/UrlMapping.d.ts create mode 100644 lib/output/models/UrlMapping.js create mode 100644 lib/output/models/UrlMapping.js.map create mode 100644 lib/output/plugins/AssetsPlugin.d.ts create mode 100644 lib/output/plugins/AssetsPlugin.js create mode 100644 lib/output/plugins/AssetsPlugin.js.map create mode 100644 lib/output/plugins/JavascriptIndexPlugin.d.ts create mode 100644 lib/output/plugins/JavascriptIndexPlugin.js create mode 100644 lib/output/plugins/JavascriptIndexPlugin.js.map create mode 100644 lib/output/plugins/LayoutPlugin.d.ts create mode 100644 lib/output/plugins/LayoutPlugin.js create mode 100644 lib/output/plugins/LayoutPlugin.js.map create mode 100644 lib/output/plugins/MarkedLinksPlugin.d.ts create mode 100644 lib/output/plugins/MarkedLinksPlugin.js create mode 100644 lib/output/plugins/MarkedLinksPlugin.js.map create mode 100644 lib/output/plugins/MarkedPlugin.d.ts create mode 100644 lib/output/plugins/MarkedPlugin.js create mode 100644 lib/output/plugins/MarkedPlugin.js.map create mode 100644 lib/output/plugins/NavigationPlugin.d.ts create mode 100644 lib/output/plugins/NavigationPlugin.js create mode 100644 lib/output/plugins/NavigationPlugin.js.map create mode 100644 lib/output/plugins/PrettyPrintPlugin.d.ts create mode 100644 lib/output/plugins/PrettyPrintPlugin.js create mode 100644 lib/output/plugins/PrettyPrintPlugin.js.map create mode 100644 lib/output/plugins/TocPlugin.d.ts create mode 100644 lib/output/plugins/TocPlugin.js create mode 100644 lib/output/plugins/TocPlugin.js.map create mode 100644 lib/output/plugins/index.d.ts create mode 100644 lib/output/plugins/index.js create mode 100644 lib/output/plugins/index.js.map create mode 100644 lib/output/renderer.d.ts create mode 100644 lib/output/renderer.js create mode 100644 lib/output/renderer.js.map create mode 100644 lib/output/theme.d.ts create mode 100644 lib/output/theme.js create mode 100644 lib/output/theme.js.map create mode 100644 lib/output/themes/DefaultTheme.d.ts create mode 100644 lib/output/themes/DefaultTheme.js create mode 100644 lib/output/themes/DefaultTheme.js.map create mode 100644 lib/output/themes/MinimalTheme.d.ts create mode 100644 lib/output/themes/MinimalTheme.js create mode 100644 lib/output/themes/MinimalTheme.js.map create mode 100644 lib/output/utils/resources.d.ts create mode 100644 lib/output/utils/resources.js create mode 100644 lib/output/utils/resources.js.map create mode 100644 lib/output/utils/resources/helpers.d.ts create mode 100644 lib/output/utils/resources/helpers.js create mode 100644 lib/output/utils/resources/helpers.js.map create mode 100644 lib/output/utils/resources/stack.d.ts create mode 100644 lib/output/utils/resources/stack.js create mode 100644 lib/output/utils/resources/stack.js.map create mode 100644 lib/output/utils/resources/templates.d.ts create mode 100644 lib/output/utils/resources/templates.js create mode 100644 lib/output/utils/resources/templates.js.map create mode 100644 lib/utils/component.d.ts create mode 100644 lib/utils/component.js create mode 100644 lib/utils/component.js.map create mode 100644 lib/utils/events.d.ts create mode 100644 lib/utils/events.js create mode 100644 lib/utils/events.js.map create mode 100644 lib/utils/fs.d.ts create mode 100644 lib/utils/fs.js create mode 100644 lib/utils/fs.js.map create mode 100644 lib/utils/index.d.ts create mode 100644 lib/utils/index.js create mode 100644 lib/utils/index.js.map create mode 100644 lib/utils/loggers.d.ts create mode 100644 lib/utils/loggers.js create mode 100644 lib/utils/loggers.js.map create mode 100644 lib/utils/options/declaration.d.ts create mode 100644 lib/utils/options/declaration.js create mode 100644 lib/utils/options/declaration.js.map create mode 100644 lib/utils/options/help.d.ts create mode 100644 lib/utils/options/help.js create mode 100644 lib/utils/options/help.js.map create mode 100644 lib/utils/options/index.d.ts create mode 100644 lib/utils/options/index.js create mode 100644 lib/utils/options/index.js.map create mode 100644 lib/utils/options/options.d.ts create mode 100644 lib/utils/options/options.js create mode 100644 lib/utils/options/options.js.map create mode 100644 lib/utils/options/readers/arguments.d.ts create mode 100644 lib/utils/options/readers/arguments.js create mode 100644 lib/utils/options/readers/arguments.js.map create mode 100644 lib/utils/options/readers/index.d.ts create mode 100644 lib/utils/options/readers/index.js create mode 100644 lib/utils/options/readers/index.js.map create mode 100644 lib/utils/options/readers/tsconfig.d.ts create mode 100644 lib/utils/options/readers/tsconfig.js create mode 100644 lib/utils/options/readers/tsconfig.js.map create mode 100644 lib/utils/options/readers/typedoc.d.ts create mode 100644 lib/utils/options/readers/typedoc.js create mode 100644 lib/utils/options/readers/typedoc.js.map create mode 100644 lib/utils/options/sources/component.d.ts create mode 100644 lib/utils/options/sources/component.js create mode 100644 lib/utils/options/sources/component.js.map create mode 100644 lib/utils/options/sources/index.d.ts create mode 100644 lib/utils/options/sources/index.js create mode 100644 lib/utils/options/sources/index.js.map create mode 100644 lib/utils/options/sources/typescript.d.ts create mode 100644 lib/utils/options/sources/typescript.js create mode 100644 lib/utils/options/sources/typescript.js.map create mode 100644 lib/utils/plugins.d.ts create mode 100644 lib/utils/plugins.js create mode 100644 lib/utils/plugins.js.map diff --git a/.gitignore b/.gitignore index 56e54517c..66b9e29a8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,3 @@ /node_modules/ /typescript/ /coverage/ -/lib/ \ No newline at end of file diff --git a/lib/application.d.ts b/lib/application.d.ts new file mode 100644 index 000000000..dd014dee2 --- /dev/null +++ b/lib/application.d.ts @@ -0,0 +1,30 @@ +import { Converter } from "./converter/index"; +import { Renderer } from "./output/renderer"; +import { ProjectReflection } from "./models/index"; +import { Logger, PluginHost } from "./utils/index"; +import { AbstractComponent, ChildableComponent } from "./utils/component"; +import { Options, IOptionsReadResult } from "./utils/options/index"; +export declare class Application extends ChildableComponent> { + options: Options; + converter: Converter; + renderer: Renderer; + logger: Logger; + plugins: PluginHost; + loggerType: string | Function; + ignoreCompilerErrors: boolean; + exclude: string; + static VERSION: string; + constructor(options?: Object); + protected bootstrap(options?: Object): IOptionsReadResult; + readonly application: Application; + readonly isCLI: boolean; + getTypeScriptPath(): string; + getTypeScriptVersion(): string; + convert(src: string[]): ProjectReflection; + generateDocs(src: string[], out: string): boolean; + generateDocs(project: ProjectReflection, out: string): boolean; + generateJson(src: string[], out: string): boolean; + generateJson(project: ProjectReflection, out: string): boolean; + expandInputFiles(inputFiles?: string[]): string[]; + toString(): string; +} diff --git a/lib/application.js b/lib/application.js new file mode 100644 index 000000000..3065a43a1 --- /dev/null +++ b/lib/application.js @@ -0,0 +1,176 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var Path = require("path"); +var FS = require("fs"); +var typescript = require("typescript"); +var minimatch_1 = require("minimatch"); +var index_1 = require("./converter/index"); +var renderer_1 = require("./output/renderer"); +var index_2 = require("./models/index"); +var index_3 = require("./utils/index"); +var component_1 = require("./utils/component"); +var index_4 = require("./utils/options/index"); +var declaration_1 = require("./utils/options/declaration"); +var Application = (function (_super) { + __extends(Application, _super); + function Application(options) { + _super.call(this, null); + this.logger = new index_3.ConsoleLogger(); + this.converter = this.addComponent('converter', index_1.Converter); + this.renderer = this.addComponent('renderer', renderer_1.Renderer); + this.plugins = this.addComponent('plugins', index_3.PluginHost); + this.options = this.addComponent('options', index_4.Options); + this.bootstrap(options); + } + Application.prototype.bootstrap = function (options) { + this.options.read(options, index_4.OptionsReadMode.Prefetch); + var logger = this.loggerType; + if (typeof logger == 'function') { + this.logger = new index_3.CallbackLogger(logger); + } + else if (logger == 'none') { + this.logger = new index_3.Logger(); + } + this.plugins.load(); + return this.options.read(options, index_4.OptionsReadMode.Fetch); + }; + Object.defineProperty(Application.prototype, "application", { + get: function () { + return this; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Application.prototype, "isCLI", { + get: function () { + return false; + }, + enumerable: true, + configurable: true + }); + Application.prototype.getTypeScriptPath = function () { + return Path.dirname(require.resolve('typescript')); + }; + Application.prototype.getTypeScriptVersion = function () { + var tsPath = this.getTypeScriptPath(); + var json = JSON.parse(FS.readFileSync(Path.join(tsPath, '..', 'package.json'), 'utf8')); + return json.version; + }; + Application.prototype.convert = function (src) { + this.logger.writeln('Using TypeScript %s from %s', this.getTypeScriptVersion(), this.getTypeScriptPath()); + var result = this.converter.convert(src); + if (result.errors && result.errors.length) { + this.logger.diagnostics(result.errors); + if (this.ignoreCompilerErrors) { + this.logger.resetErrors(); + return result.project; + } + else { + return null; + } + } + else { + return result.project; + } + }; + Application.prototype.generateDocs = function (input, out) { + var project = input instanceof index_2.ProjectReflection ? input : this.convert(input); + if (!project) + return false; + out = Path.resolve(out); + this.renderer.render(project, out); + if (this.logger.hasErrors()) { + this.logger.error('Documentation could not be generated due to the errors above.'); + } + else { + this.logger.success('Documentation generated at %s', out); + } + return true; + }; + Application.prototype.generateJson = function (input, out) { + var project = input instanceof index_2.ProjectReflection ? input : this.convert(input); + if (!project) + return false; + out = Path.resolve(out); + index_3.writeFile(out, JSON.stringify(project.toObject(), null, '\t'), false); + this.logger.success('JSON written to %s', out); + return true; + }; + Application.prototype.expandInputFiles = function (inputFiles) { + var exclude, files = []; + if (this.exclude) { + exclude = new minimatch_1.Minimatch(this.exclude); + } + function add(dirname) { + FS.readdirSync(dirname).forEach(function (file) { + var realpath = Path.join(dirname, file); + if (FS.statSync(realpath).isDirectory()) { + add(realpath); + } + else if (/\.tsx?$/.test(realpath)) { + if (exclude && exclude.match(realpath.replace(/\\/g, '/'))) { + return; + } + files.push(realpath); + } + }); + } + inputFiles.forEach(function (file) { + file = Path.resolve(file); + if (FS.statSync(file).isDirectory()) { + add(file); + } + else { + files.push(file); + } + }); + return files; + }; + Application.prototype.toString = function () { + return [ + '', + 'TypeDoc ' + Application.VERSION, + 'Using TypeScript ' + this.getTypeScriptVersion() + ' from ' + this.getTypeScriptPath(), + '' + ].join(typescript.sys.newLine); + }; + Application.VERSION = '0.5.0'; + __decorate([ + component_1.Option({ + name: 'logger', + help: 'Specify the logger that should be used, \'none\' or \'console\'', + defaultValue: 'console', + type: declaration_1.ParameterType.Mixed, + }) + ], Application.prototype, "loggerType", void 0); + __decorate([ + component_1.Option({ + name: 'ignoreCompilerErrors', + help: 'Should TypeDoc generate documentation pages even after the compiler has returned errors?', + type: declaration_1.ParameterType.Boolean + }) + ], Application.prototype, "ignoreCompilerErrors", void 0); + __decorate([ + component_1.Option({ + name: 'exclude', + help: 'Define a pattern for excluded files when specifying paths.', + type: declaration_1.ParameterType.String + }) + ], Application.prototype, "exclude", void 0); + Application = __decorate([ + component_1.Component({ name: "application", internal: true }) + ], Application); + return Application; +}(component_1.ChildableComponent)); +exports.Application = Application; +//# sourceMappingURL=application.js.map \ No newline at end of file diff --git a/lib/application.js.map b/lib/application.js.map new file mode 100644 index 000000000..78fbf2a0d --- /dev/null +++ b/lib/application.js.map @@ -0,0 +1 @@ +{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/lib/application.ts"],"names":[],"mappings":";;;;;;;;;;;;AAQA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAC7B,IAAY,EAAE,WAAM,IAAI,CAAC,CAAA;AAEzB,IAAY,UAAU,WAAM,YAA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BAAW,cA+PvB,CAAA","sourcesContent":["/**\n * The TypeDoc main module and namespace.\n *\n * The [[Application]] class holds the core logic of the cli application. All code related\n * to resolving reflections is stored in [[TypeDoc.Factories]], the actual data models can be found\n * in [[TypeDoc.Models]] and the final rendering is defined in [[TypeDoc.Output]].\n */\n\nimport * as Path from \"path\";\nimport * as FS from \"fs\";\nimport * as Util from \"util\";\nimport * as typescript from \"typescript\";\nimport {Minimatch, IMinimatch} from \"minimatch\";\n\nimport {Converter} from \"./converter/index\";\nimport {Renderer} from \"./output/renderer\";\nimport {ProjectReflection} from \"./models/index\";\nimport {Logger, ConsoleLogger, CallbackLogger, PluginHost, writeFile} from \"./utils/index\";\n\nimport {AbstractComponent, ChildableComponent, Component, Option} from \"./utils/component\";\nimport {Options, OptionsReadMode, IOptionsReadResult} from \"./utils/options/index\"\nimport {ParameterType} from \"./utils/options/declaration\";\n\n\n/**\n * The default TypeDoc main application class.\n *\n * This class holds the two main components of TypeDoc, the [[Dispatcher]] and\n * the [[Renderer]]. When running TypeDoc, first the [[Dispatcher]] is invoked which\n * generates a [[ProjectReflection]] from the passed in source files. The\n * [[ProjectReflection]] is a hierarchical model representation of the TypeScript\n * project. Afterwards the model is passed to the [[Renderer]] which uses an instance\n * of [[BaseTheme]] to generate the final documentation.\n *\n * Both the [[Dispatcher]] and the [[Renderer]] are subclasses of the [[EventDispatcher]]\n * and emit a series of events while processing the project. Subscribe to these Events\n * to control the application flow or alter the output.\n */\n@Component({name:\"application\", internal:true})\nexport class Application extends ChildableComponent>\n{\n options:Options;\n\n /**\n * The converter used to create the declaration reflections.\n */\n converter:Converter;\n\n /**\n * The renderer used to generate the documentation output.\n */\n renderer:Renderer;\n\n /**\n * The logger that should be used to output messages.\n */\n logger:Logger;\n\n plugins:PluginHost;\n\n @Option({\n name: 'logger',\n help: 'Specify the logger that should be used, \\'none\\' or \\'console\\'',\n defaultValue: 'console',\n type: ParameterType.Mixed,\n })\n loggerType:string|Function;\n\n @Option({\n name: 'ignoreCompilerErrors',\n help: 'Should TypeDoc generate documentation pages even after the compiler has returned errors?',\n type: ParameterType.Boolean\n })\n ignoreCompilerErrors:boolean;\n\n @Option({\n name: 'exclude',\n help: 'Define a pattern for excluded files when specifying paths.',\n type: ParameterType.String\n })\n exclude:string;\n\n /**\n * The version number of TypeDoc.\n */\n static VERSION:string = '{{ VERSION }}';\n\n\n\n /**\n * Create a new TypeDoc application instance.\n *\n * @param options An object containing the options that should be used.\n */\n constructor(options?:Object) {\n super(null);\n\n this.logger = new ConsoleLogger();\n this.converter = this.addComponent('converter', Converter);\n this.renderer = this.addComponent('renderer', Renderer);\n this.plugins = this.addComponent('plugins', PluginHost);\n this.options = this.addComponent('options', Options);\n\n this.bootstrap(options);\n }\n\n\n /**\n * Initialize TypeDoc with the given options object.\n *\n * @param options The desired options to set.\n */\n protected bootstrap(options?:Object):IOptionsReadResult {\n this.options.read(options, OptionsReadMode.Prefetch);\n\n var logger = this.loggerType;\n if (typeof logger == 'function') {\n this.logger = new CallbackLogger(logger);\n } else if (logger == 'none') {\n this.logger = new Logger();\n }\n\n this.plugins.load();\n return this.options.read(options, OptionsReadMode.Fetch);\n }\n\n\n /**\n * Return the application / root component instance.\n */\n get application():Application {\n return this\n }\n\n\n get isCLI():boolean {\n return false;\n }\n\n\n /**\n * Return the path to the TypeScript compiler.\n */\n public getTypeScriptPath():string {\n return Path.dirname(require.resolve('typescript'));\n }\n\n\n public getTypeScriptVersion():string {\n var tsPath = this.getTypeScriptPath();\n var json = JSON.parse(FS.readFileSync(Path.join(tsPath, '..', 'package.json'), 'utf8'));\n return json.version;\n }\n\n\n /**\n * Run the converter for the given set of files and return the generated reflections.\n *\n * @param src A list of source that should be compiled and converted.\n * @returns An instance of ProjectReflection on success, NULL otherwise.\n */\n public convert(src:string[]):ProjectReflection {\n this.logger.writeln('Using TypeScript %s from %s', this.getTypeScriptVersion(), this.getTypeScriptPath());\n\n var result = this.converter.convert(src);\n if (result.errors && result.errors.length) {\n this.logger.diagnostics(result.errors);\n if (this.ignoreCompilerErrors) {\n this.logger.resetErrors();\n return result.project;\n } else {\n return null;\n }\n } else {\n return result.project;\n }\n }\n\n\n /**\n * @param src A list of source files whose documentation should be generated.\n */\n public generateDocs(src:string[], out:string):boolean;\n\n /**\n * @param project The project the documentation should be generated for.\n */\n public generateDocs(project:ProjectReflection, out:string):boolean;\n\n /**\n * Run the documentation generator for the given set of files.\n *\n * @param out The path the documentation should be written to.\n * @returns TRUE if the documentation could be generated successfully, otherwise FALSE.\n */\n public generateDocs(input:any, out:string):boolean {\n var project = input instanceof ProjectReflection ? input : this.convert(input);\n if (!project) return false;\n\n out = Path.resolve(out);\n this.renderer.render(project, out);\n if (this.logger.hasErrors()) {\n this.logger.error('Documentation could not be generated due to the errors above.');\n } else {\n this.logger.success('Documentation generated at %s', out);\n }\n\n return true;\n }\n\n\n /**\n * @param src A list of source that should be compiled and converted.\n */\n public generateJson(src:string[], out:string):boolean;\n\n /**\n * @param project The project that should be converted.\n */\n public generateJson(project:ProjectReflection, out:string):boolean;\n\n /**\n * Run the converter for the given set of files and write the reflections to a json file.\n *\n * @param out The path and file name of the target file.\n * @returns TRUE if the json file could be written successfully, otherwise FALSE.\n */\n public generateJson(input:any, out:string):boolean {\n var project = input instanceof ProjectReflection ? input : this.convert(input);\n if (!project) return false;\n\n out = Path.resolve(out);\n writeFile(out, JSON.stringify(project.toObject(), null, '\\t'), false);\n this.logger.success('JSON written to %s', out);\n\n return true;\n }\n\n\n /**\n * Expand a list of input files.\n *\n * Searches for directories in the input files list and replaces them with a\n * listing of all TypeScript files within them. One may use the ```--exclude``` option\n * to filter out files with a pattern.\n *\n * @param inputFiles The list of files that should be expanded.\n * @returns The list of input files with expanded directories.\n */\n public expandInputFiles(inputFiles?:string[]):string[] {\n var exclude:IMinimatch, files:string[] = [];\n if (this.exclude) {\n exclude = new Minimatch(this.exclude);\n }\n\n function add(dirname:string) {\n FS.readdirSync(dirname).forEach((file) => {\n var realpath = Path.join(dirname, file);\n if (FS.statSync(realpath).isDirectory()) {\n add(realpath);\n } else if (/\\.tsx?$/.test(realpath)) {\n if (exclude && exclude.match(realpath.replace(/\\\\/g, '/'))) {\n return;\n }\n\n files.push(realpath);\n }\n });\n }\n\n inputFiles.forEach((file) => {\n file = Path.resolve(file);\n if (FS.statSync(file).isDirectory()) {\n add(file);\n } else {\n files.push(file);\n }\n });\n\n return files;\n }\n\n\n /**\n * Print the version number.\n */\n public toString() {\n return [\n '',\n 'TypeDoc ' + Application.VERSION,\n 'Using TypeScript ' + this.getTypeScriptVersion() + ' from ' + this.getTypeScriptPath(),\n ''\n ].join(typescript.sys.newLine);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/cli.d.ts b/lib/cli.d.ts new file mode 100644 index 000000000..f1aca5145 --- /dev/null +++ b/lib/cli.d.ts @@ -0,0 +1,17 @@ +import { Application } from "./application"; +import { IOptionsReadResult } from "./utils/options/options"; +export declare const enum ExitCode { + OptionError = 1, + NoInputFiles = 2, + NoOutput = 3, + CompileError = 4, + OutputError = 5, +} +export declare class CliApplication extends Application { + out: string; + json: string; + version: boolean; + help: boolean; + protected bootstrap(options?: Object): IOptionsReadResult; + readonly isCLI: boolean; +} diff --git a/lib/cli.js b/lib/cli.js new file mode 100644 index 000000000..7b48e6d95 --- /dev/null +++ b/lib/cli.js @@ -0,0 +1,109 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var typescript = require("typescript"); +var application_1 = require("./application"); +var component_1 = require("./utils/component"); +var declaration_1 = require("./utils/options/declaration"); +var help_1 = require("./utils/options/help"); +(function (ExitCode) { + ExitCode[ExitCode["OptionError"] = 1] = "OptionError"; + ExitCode[ExitCode["NoInputFiles"] = 2] = "NoInputFiles"; + ExitCode[ExitCode["NoOutput"] = 3] = "NoOutput"; + ExitCode[ExitCode["CompileError"] = 4] = "CompileError"; + ExitCode[ExitCode["OutputError"] = 5] = "OutputError"; +})(exports.ExitCode || (exports.ExitCode = {})); +var ExitCode = exports.ExitCode; +var CliApplication = (function (_super) { + __extends(CliApplication, _super); + function CliApplication() { + _super.apply(this, arguments); + } + CliApplication.prototype.bootstrap = function (options) { + var result = _super.prototype.bootstrap.call(this, options); + if (result.hasErrors) { + process.exit(1); + return; + } + if (this.version) { + typescript.sys.write(this.toString()); + } + else if (this.help) { + typescript.sys.write(help_1.getOptionsHelp(this.options)); + } + else if (result.inputFiles.length === 0) { + typescript.sys.write(help_1.getOptionsHelp(this.options)); + process.exit(2); + } + else if (!this.out && !this.json) { + this.logger.error("You must either specify the 'out' or 'json' option."); + process.exit(3); + } + else { + var src = this.expandInputFiles(result.inputFiles); + var project = this.convert(src); + if (project) { + if (this.out) + this.generateDocs(project, this.out); + if (this.json) + this.generateJson(project, this.json); + if (this.logger.hasErrors()) { + process.exit(5); + } + } + else { + process.exit(4); + } + } + return result; + }; + Object.defineProperty(CliApplication.prototype, "isCLI", { + get: function () { + return true; + }, + enumerable: true, + configurable: true + }); + __decorate([ + component_1.Option({ + name: 'out', + help: 'Specifies the location the documentation should be written to.', + hint: declaration_1.ParameterHint.Directory + }) + ], CliApplication.prototype, "out", void 0); + __decorate([ + component_1.Option({ + name: 'json', + help: 'Specifies the location and file name a json file describing the project is written to.', + hint: declaration_1.ParameterHint.File + }) + ], CliApplication.prototype, "json", void 0); + __decorate([ + component_1.Option({ + name: 'version', + short: 'v', + help: 'Print the TypeDoc\'s version.', + type: declaration_1.ParameterType.Boolean + }) + ], CliApplication.prototype, "version", void 0); + __decorate([ + component_1.Option({ + name: 'help', + short: 'h', + help: 'Print this message.', + type: declaration_1.ParameterType.Boolean + }) + ], CliApplication.prototype, "help", void 0); + return CliApplication; +}(application_1.Application)); +exports.CliApplication = CliApplication; +//# sourceMappingURL=cli.js.map \ No newline at end of file diff --git a/lib/cli.js.map b/lib/cli.js.map new file mode 100644 index 000000000..6ec5edd6b --- /dev/null +++ b/lib/cli.js.map @@ -0,0 +1 @@ +{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/lib/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,UAAU,WAAM,YAAY,CAAC,CAAA;AAEzC,4BAA0B,eAAe,CAAC,CAAA;AAC1C,0BAAqB,mBAAmB,CAAC,CAAA;AAEzC,4BAA2C,6BAA6B,CAAC,CAAA;AACzE,qBAA6B,sBAAsB,CAAC,CAAA;AAGpD,WAAkB,QAAQ;IAEtB,qDAAgB,CAAA;IAChB,uDAAgB,CAAA;IAChB,+CAAgB,CAAA;IAChB,uDAAgB,CAAA;IAChB,qDAAgB,CAAA;AACpB,CAAC,EAPiB,gBAAQ,KAAR,gBAAQ,QAOzB;AAPD,IAAkB,QAAQ,GAAR,gBAOjB,CAAA;AAGD;IAAoC,kCAAW;IAA/C;QAAoC,8BAAW;IA2E/C,CAAC;IAtCa,kCAAS,GAAnB,UAAoB,OAAe;QAC/B,IAAI,MAAM,GAAG,gBAAK,CAAC,SAAS,YAAC,OAAO,CAAC,CAAC;QACtC,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,CAAoB,CAAC,CAAC;YACnC,MAAM,CAAC;QACX,CAAC;QAED,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YACf,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI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,CAAC,CAAC;oBAC1B,OAAO,CAAC,IAAI,CAAC,CAAoB,CAAC,CAAC;gBACvC,CAAC;YACL,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,CAAqB,CAAC,CAAC;YACxC,CAAC;QACL,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAGD,sBAAI,iCAAK;aAAT;YACI,MAAM,CAAC,IAAI,CAAC;QAChB,CAAC;;;OAAA;IAxED;QAAC,kBAAM,CAAC;YACJ,IAAI,EAAG,KAAK;YACZ,IAAI,EAAG,gEAAgE;YACvE,IAAI,EAAG,2BAAa,CAAC,SAAS;SACjC,CAAC;+CAAA;IAGF;QAAC,kBAAM,CAAC;YACJ,IAAI,EAAG,MAAM;YACb,IAAI,EAAG,wFAAwF;YAC/F,IAAI,EAAG,2BAAa,CAAC,IAAI;SAC5B,CAAC;gDAAA;IAGF;QAAC,kBAAM,CAAC;YACJ,IAAI,EAAG,SAAS;YAChB,KAAK,EAAE,GAAG;YACV,IAAI,EAAG,+BAA+B;YACtC,IAAI,EAAG,2BAAa,CAAC,OAAO;SAC/B,CAAC;mDAAA;IAGF;QAAC,kBAAM,CAAC;YACJ,IAAI,EAAG,MAAM;YACb,KAAK,EAAE,GAAG;YACV,IAAI,EAAG,qBAAqB;YAC5B,IAAI,EAAG,2BAAa,CAAC,OAAO;SAC/B,CAAC;gDAAA;IA8CN,qBAAC;AAAD,CAAC,AA3ED,CAAoC,yBAAW,GA2E9C;AA3EY,sBAAc,iBA2E1B,CAAA","sourcesContent":["import * as typescript from \"typescript\";\n\nimport {Application} from \"./application\";\nimport {Option} from \"./utils/component\";\nimport {OptionsReadMode, IOptionsReadResult} from \"./utils/options/options\";\nimport {ParameterHint, ParameterType} from \"./utils/options/declaration\";\nimport {getOptionsHelp} from \"./utils/options/help\";\n\n\nexport const enum ExitCode\n{\n OptionError = 1,\n NoInputFiles = 2,\n NoOutput = 3,\n CompileError = 4,\n OutputError = 5\n}\n\n\nexport class CliApplication extends Application\n{\n @Option({\n name: 'out',\n help: 'Specifies the location the documentation should be written to.',\n hint: ParameterHint.Directory\n })\n out:string;\n\n @Option({\n name: 'json',\n help: 'Specifies the location and file name a json file describing the project is written to.',\n hint: ParameterHint.File\n })\n json:string;\n\n @Option({\n name: 'version',\n short: 'v',\n help: 'Print the TypeDoc\\'s version.',\n type: ParameterType.Boolean\n })\n version:boolean;\n\n @Option({\n name: 'help',\n short: 'h',\n help: 'Print this message.',\n type: ParameterType.Boolean\n })\n help:boolean;\n\n\n\n /**\n * Run TypeDoc from the command line.\n */\n protected bootstrap(options?:Object):IOptionsReadResult {\n var result = super.bootstrap(options);\n if (result.hasErrors) {\n process.exit(ExitCode.OptionError);\n return;\n }\n\n if (this.version) {\n typescript.sys.write(this.toString());\n } else if (this.help) {\n typescript.sys.write(getOptionsHelp(this.options));\n } else if (result.inputFiles.length === 0) {\n typescript.sys.write(getOptionsHelp(this.options));\n process.exit(ExitCode.NoInputFiles);\n } else if (!this.out && !this.json) {\n this.logger.error(\"You must either specify the 'out' or 'json' option.\");\n process.exit(ExitCode.NoOutput);\n } else {\n var src = this.expandInputFiles(result.inputFiles);\n var project = this.convert(src);\n if (project) {\n if (this.out) this.generateDocs(project, this.out);\n if (this.json) this.generateJson(project, this.json);\n if (this.logger.hasErrors()) {\n process.exit(ExitCode.OutputError);\n }\n } else {\n process.exit(ExitCode.CompileError);\n }\n }\n\n return result;\n }\n\n\n get isCLI():boolean {\n return true;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/components.d.ts b/lib/converter/components.d.ts new file mode 100644 index 000000000..0dd18a1f1 --- /dev/null +++ b/lib/converter/components.d.ts @@ -0,0 +1,26 @@ +import * as ts from "typescript"; +import { Component, AbstractComponent } from "../utils/component"; +import { Reflection } from "../models/reflections/abstract"; +import { Type } from "../models/types/abstract"; +import { Context } from "./context"; +import { Converter } from "./converter"; +export { Component }; +export declare abstract class ConverterComponent extends AbstractComponent { +} +export declare abstract class ConverterNodeComponent extends ConverterComponent { + supports: ts.SyntaxKind[]; + abstract convert(context: Context, node: T): Reflection; +} +export declare abstract class ConverterTypeComponent extends ConverterComponent { + priority: number; +} +export interface ITypeConverter extends ConverterTypeComponent, ITypeTypeConverter, ITypeNodeConverter { +} +export interface ITypeTypeConverter extends ConverterTypeComponent { + supportsType(context: Context, type: T): boolean; + convertType(context: Context, type: T): Type; +} +export interface ITypeNodeConverter extends ConverterTypeComponent { + supportsNode(context: Context, node: N, type: T): boolean; + convertNode(context: Context, node: N, type: T): Type; +} diff --git a/lib/converter/components.js b/lib/converter/components.js new file mode 100644 index 000000000..c8e52f1d6 --- /dev/null +++ b/lib/converter/components.js @@ -0,0 +1,34 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var component_1 = require("../utils/component"); +exports.Component = component_1.Component; +var ConverterComponent = (function (_super) { + __extends(ConverterComponent, _super); + function ConverterComponent() { + _super.apply(this, arguments); + } + return ConverterComponent; +}(component_1.AbstractComponent)); +exports.ConverterComponent = ConverterComponent; +var ConverterNodeComponent = (function (_super) { + __extends(ConverterNodeComponent, _super); + function ConverterNodeComponent() { + _super.apply(this, arguments); + } + return ConverterNodeComponent; +}(ConverterComponent)); +exports.ConverterNodeComponent = ConverterNodeComponent; +var ConverterTypeComponent = (function (_super) { + __extends(ConverterTypeComponent, _super); + function ConverterTypeComponent() { + _super.apply(this, arguments); + this.priority = 0; + } + return ConverterTypeComponent; +}(ConverterComponent)); +exports.ConverterTypeComponent = ConverterTypeComponent; +//# sourceMappingURL=components.js.map \ No newline at end of file diff --git a/lib/converter/components.js.map b/lib/converter/components.js.map new file mode 100644 index 000000000..79fb8fe83 --- /dev/null +++ b/lib/converter/components.js.map @@ -0,0 +1 @@ +{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/lib/converter/components.ts"],"names":[],"mappings":";;;;;;AAGA,0BAA2C,oBAAoB,CAAC,CAAA;AAOxD,iBAAS;AAGjB;IAAiD,sCAA4B;IAA7E;QAAiD,8BAA4B;IAAG,CAAC;IAAD,yBAAC;AAAD,CAAC,AAAjF,CAAiD,6BAAiB,GAAe;AAA3D,0BAAkB,qBAAyC,CAAA;AAGjF;IAAwE,0CAAkB;IAA1F;QAAwE,8BAAkB;IAS1F,CAAC;IAAD,6BAAC;AAAD,CAAC,AATD,CAAwE,kBAAkB,GASzF;AATqB,8BAAsB,yBAS3C,CAAA;AAGD;IAAqD,0CAAkB;IAAvE;QAAqD,8BAAkB;QAMnE,aAAQ,GAAU,CAAC,CAAC;IACxB,CAAC;IAAD,6BAAC;AAAD,CAAC,AAPD,CAAqD,kBAAkB,GAOtE;AAPqB,8BAAsB,yBAO3C,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Application} from \"../application\";\nimport {Component, AbstractComponent} from \"../utils/component\";\nimport {Reflection} from \"../models/reflections/abstract\";\nimport {Type} from \"../models/types/abstract\";\nimport {Context} from \"./context\";\nimport {Converter} from \"./converter\";\n\n\nexport {Component};\n\n\nexport abstract class ConverterComponent extends AbstractComponent { }\n\n\nexport abstract class ConverterNodeComponent extends ConverterComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[];\n\n\n abstract convert(context:Context, node:T):Reflection;\n}\n\n\nexport abstract class ConverterTypeComponent extends ConverterComponent\n{\n /**\n * The priority this converter should be executed with.\n * A higher priority means the converter will be applied earlier.\n */\n priority:number = 0;\n}\n\n\nexport interface ITypeConverter\n extends ConverterTypeComponent, ITypeTypeConverter, ITypeNodeConverter {}\n\n\nexport interface ITypeTypeConverter extends ConverterTypeComponent\n{\n /**\n * Test whether this converter can handle the given TypeScript type.\n */\n supportsType(context:Context, type:T):boolean;\n\n /**\n * Convert the given type to its type reflection.\n */\n convertType(context:Context, type:T):Type;\n}\n\n\nexport interface ITypeNodeConverter extends ConverterTypeComponent\n{\n /**\n * Test whether this converter can handle the given TypeScript node.\n */\n supportsNode(context:Context, node:N, type:T):boolean;\n\n /**\n * Convert the given type node to its type reflection.\n */\n convertNode(context:Context, node:N, type:T):Type;\n}\n"]} \ No newline at end of file diff --git a/lib/converter/context.d.ts b/lib/converter/context.d.ts new file mode 100644 index 000000000..0090ff431 --- /dev/null +++ b/lib/converter/context.d.ts @@ -0,0 +1,36 @@ +import * as ts from "typescript"; +import { Logger } from "../utils/loggers"; +import { Reflection, ProjectReflection, Type } from "../models/index"; +import { Converter } from "./converter"; +export declare class Context { + converter: Converter; + fileNames: string[]; + checker: ts.TypeChecker; + program: ts.Program; + project: ProjectReflection; + scope: Reflection; + isExternal: boolean; + isDeclaration: boolean; + typeParameters: ts.MapLike; + typeArguments: Type[]; + isInherit: boolean; + inheritParent: ts.Node; + inheritedChildren: number[]; + inherited: string[]; + visitStack: ts.Node[]; + private symbolID; + private externalPattern; + constructor(converter: Converter, fileNames: string[], checker: ts.TypeChecker, program: ts.Program); + getCompilerOptions(): ts.CompilerOptions; + getTypeAtLocation(node: ts.Node): ts.Type; + getLogger(): Logger; + getSymbolID(symbol: ts.Symbol): number; + registerReflection(reflection: Reflection, node: ts.Node, symbol?: ts.Symbol): void; + trigger(name: string, reflection: Reflection, node?: ts.Node): void; + withSourceFile(node: ts.SourceFile, callback: Function): void; + withScope(scope: Reflection, callback: Function): void; + withScope(scope: Reflection, parameters: ts.NodeArray, callback: Function): void; + withScope(scope: Reflection, parameters: ts.NodeArray, preserve: boolean, callback: Function): void; + inherit(baseNode: ts.Node, typeArguments?: ts.NodeArray): Reflection; + private extractTypeParameters(parameters, preserve?); +} diff --git a/lib/converter/context.js b/lib/converter/context.js new file mode 100644 index 000000000..c82fd1f9d --- /dev/null +++ b/lib/converter/context.js @@ -0,0 +1,173 @@ +"use strict"; +var ts = require("typescript"); +var minimatch_1 = require("minimatch"); +var index_1 = require("../models/index"); +var type_parameter_1 = require("./factories/type-parameter"); +var converter_1 = require("./converter"); +var Context = (function () { + function Context(converter, fileNames, checker, program) { + this.symbolID = -1024; + this.converter = converter; + this.fileNames = fileNames; + this.checker = checker; + this.program = program; + this.visitStack = []; + var project = new index_1.ProjectReflection(converter.name); + this.project = project; + this.scope = project; + if (converter.externalPattern) { + this.externalPattern = new minimatch_1.Minimatch(converter.externalPattern); + } + } + Context.prototype.getCompilerOptions = function () { + return this.converter.application.options.getCompilerOptions(); + }; + Context.prototype.getTypeAtLocation = function (node) { + try { + return this.checker.getTypeAtLocation(node); + } + catch (error) { + try { + if (node.symbol) { + return this.checker.getDeclaredTypeOfSymbol(node.symbol); + } + } + catch (error) { } + } + return null; + }; + Context.prototype.getLogger = function () { + return this.converter.application.logger; + }; + Context.prototype.getSymbolID = function (symbol) { + if (!symbol) + return null; + if (!symbol.id) + symbol.id = this.symbolID--; + return symbol.id; + }; + Context.prototype.registerReflection = function (reflection, node, symbol) { + this.project.reflections[reflection.id] = reflection; + var id = this.getSymbolID(symbol ? symbol : (node ? node.symbol : null)); + if (!this.isInherit && id && !this.project.symbolMapping[id]) { + this.project.symbolMapping[id] = reflection.id; + } + }; + Context.prototype.trigger = function (name, reflection, node) { + this.converter.trigger(name, this, reflection, node); + }; + Context.prototype.withSourceFile = function (node, callback) { + var options = this.converter.application.options; + var externalPattern = this.externalPattern; + var isExternal = this.fileNames.indexOf(node.fileName) == -1; + if (externalPattern) { + isExternal = isExternal || externalPattern.match(node.fileName); + } + if (isExternal && this.converter.excludeExternals) { + return; + } + var isDeclaration = ts.isDeclarationFile(node); + if (isDeclaration) { + var lib = this.converter.getDefaultLib(); + var isLib = node.fileName.substr(-lib.length) == lib; + if (!this.converter.includeDeclarations || isLib) { + return; + } + } + this.isExternal = isExternal; + this.isDeclaration = isDeclaration; + this.trigger(converter_1.Converter.EVENT_FILE_BEGIN, this.project, node); + callback(); + this.isExternal = false; + this.isDeclaration = false; + }; + Context.prototype.withScope = function (scope) { + var args = []; + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; + } + if (!scope || !args.length) + return; + var callback = args.pop(); + var parameters = args.shift(); + var oldScope = this.scope; + var oldTypeArguments = this.typeArguments; + var oldTypeParameters = this.typeParameters; + this.scope = scope; + this.typeParameters = parameters ? this.extractTypeParameters(parameters, args.length > 0) : this.typeParameters; + this.typeArguments = null; + callback(); + this.scope = oldScope; + this.typeParameters = oldTypeParameters; + this.typeArguments = oldTypeArguments; + }; + Context.prototype.inherit = function (baseNode, typeArguments) { + var _this = this; + var wasInherit = this.isInherit; + var oldInherited = this.inherited; + var oldInheritParent = this.inheritParent; + var oldTypeArguments = this.typeArguments; + this.isInherit = true; + this.inheritParent = baseNode; + this.inherited = []; + var target = this.scope; + if (!(target instanceof index_1.ContainerReflection)) { + throw new Error('Expected container reflection'); + } + if (baseNode.symbol) { + var id = this.getSymbolID(baseNode.symbol); + if (this.inheritedChildren && this.inheritedChildren.indexOf(id) != -1) { + return target; + } + else { + this.inheritedChildren = this.inheritedChildren || []; + this.inheritedChildren.push(id); + } + } + if (target.children) { + this.inherited = target.children.map(function (c) { return c.name; }); + } + else { + this.inherited = []; + } + if (typeArguments) { + this.typeArguments = typeArguments.map(function (t) { return _this.converter.convertType(_this, t); }); + } + else { + this.typeArguments = null; + } + this.converter.convertNode(this, baseNode); + this.isInherit = wasInherit; + this.inherited = oldInherited; + this.inheritParent = oldInheritParent; + this.typeArguments = oldTypeArguments; + if (!this.isInherit) { + delete this.inheritedChildren; + } + return target; + }; + Context.prototype.extractTypeParameters = function (parameters, preserve) { + var _this = this; + var typeParameters = {}; + if (preserve) { + for (var key in this.typeParameters) { + if (!this.typeParameters.hasOwnProperty(key)) + continue; + typeParameters[key] = this.typeParameters[key]; + } + } + parameters.forEach(function (declaration, index) { + var name = declaration.symbol.name; + if (_this.typeArguments && _this.typeArguments[index]) { + typeParameters[name] = _this.typeArguments[index]; + } + else { + typeParameters[name] = type_parameter_1.createTypeParameter(_this, declaration); + } + }); + return typeParameters; + }; + return Context; +}()); +exports.Context = Context; +//# sourceMappingURL=context.js.map \ No newline at end of file diff --git a/lib/converter/context.js.map b/lib/converter/context.js.map new file mode 100644 index 000000000..2e166f657 --- /dev/null +++ b/lib/converter/context.js.map @@ -0,0 +1 @@ +{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/lib/converter/context.ts"],"names":[],"mappings":";AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AACjC,0BAAoC,WAAW,CAAC,CAAA;AAGhD,sBAAuE,iBAAiB,CAAC,CAAA;AACzF,+BAAkC,4BAA4B,CAAC,CAAA;AAC/D,0BAAwB,aAAa,CAAC,CAAA;AAMtC;IAgGI,iBAAY,SAAmB,EAAE,SAAkB,EAAE,OAAsB,EAAE,OAAkB;QAhBvF,aAAQ,GAAU,CAAC,IAAI,CAAC;QAiB5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QAErB,IAAI,OAAO,GAAG,IAAI,yBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;QAErB,EAAE,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC;YAC5B,IAAI,CAAC,eAAe,GAAG,IAAI,qBAAS,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;QACpE,CAAC;IACL,CAAC;IAMD,oCAAkB,GAAlB;QACI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC;IACnE,CAAC;IASD,mCAAiB,GAAjB,UAAkB,IAAY;QAC1B,IAAI,CAAC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AAC;QAED,UAAU,CAAC,OAAO,CAAC,UAAC,WAAuC,EAAE,KAAY;YACrE,IAAI,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;YACnC,EAAE,CAAC,CAAC,KAAI,CAAC,aAAa,IAAI,KAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAClD,cAAc,CAAC,IAAI,CAAC,GAAG,KAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACrD,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,cAAc,CAAC,IAAI,CAAC,GAAG,oCAAmB,CAAC,KAAI,EAAE,WAAW,CAAC,CAAC;YAClE,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,cAAc,CAAC;IAC1B,CAAC;IACL,cAAC;AAAD,CAAC,AAnXD,IAmXC;AAnXY,eAAO,UAmXnB,CAAA","sourcesContent":["import * as ts from \"typescript\";\nimport {Minimatch, IMinimatch} from \"minimatch\";\n\nimport {Logger} from \"../utils/loggers\";\nimport {Reflection, ProjectReflection, ContainerReflection, Type} from \"../models/index\";\nimport {createTypeParameter} from \"./factories/type-parameter\";\nimport {Converter} from \"./converter\";\n\n\n/**\n * The context describes the current state the converter is in.\n */\nexport class Context\n{\n /**\n * The converter instance that has created the context.\n */\n converter:Converter;\n\n /**\n * A list of all files that have been passed to the TypeScript compiler.\n */\n fileNames:string[];\n\n /**\n * The TypeChecker instance returned by the TypeScript compiler.\n */\n checker:ts.TypeChecker;\n\n /**\n * The program that is currently processed.\n */\n program:ts.Program;\n\n /**\n * The project that is currently processed.\n */\n project:ProjectReflection;\n\n /**\n * The scope or parent reflection that is currently processed.\n */\n scope:Reflection;\n\n /**\n * Is the current source file marked as being external?\n */\n isExternal:boolean;\n\n /**\n * Is the current source file a declaration file?\n */\n isDeclaration:boolean;\n\n /**\n * The currently set type parameters.\n */\n typeParameters:ts.MapLike;\n\n /**\n * The currently set type arguments.\n */\n typeArguments:Type[];\n\n /**\n * Is the converter in inheritance mode?\n */\n isInherit:boolean;\n\n /**\n * The node that has started the inheritance mode.\n */\n inheritParent:ts.Node;\n\n /**\n * List symbol ids of inherited children already visited while inheriting.\n */\n inheritedChildren:number[];\n\n /**\n * The names of the children of the scope before inheritance has been started.\n */\n inherited:string[];\n\n /**\n * A list of parent nodes that have been passed to the visit function.\n */\n visitStack:ts.Node[];\n\n /**\n * Next free symbol id used by [[getSymbolID]].\n */\n private symbolID:number = -1024;\n\n /**\n * The pattern that should be used to flag external source files.\n */\n private externalPattern:IMinimatch;\n\n\n\n /**\n * Create a new Context instance.\n *\n * @param converter The converter instance that has created the context.\n * @param fileNames A list of all files that have been passed to the TypeScript compiler.\n * @param checker The TypeChecker instance returned by the TypeScript compiler.\n */\n constructor(converter:Converter, fileNames:string[], checker:ts.TypeChecker, program:ts.Program) {\n this.converter = converter;\n this.fileNames = fileNames;\n this.checker = checker;\n this.program = program;\n this.visitStack = [];\n\n var project = new ProjectReflection(converter.name);\n this.project = project;\n this.scope = project;\n\n if (converter.externalPattern) {\n this.externalPattern = new Minimatch(converter.externalPattern);\n }\n }\n\n\n /**\n * Return the compiler options.\n */\n getCompilerOptions():ts.CompilerOptions {\n return this.converter.application.options.getCompilerOptions();\n }\n\n\n /**\n * Return the type declaration of the given node.\n *\n * @param node The TypeScript node whose type should be resolved.\n * @returns The type declaration of the given node.\n */\n getTypeAtLocation(node:ts.Node):ts.Type {\n try {\n return this.checker.getTypeAtLocation(node);\n } catch (error) {\n try {\n if (node.symbol) {\n return this.checker.getDeclaredTypeOfSymbol(node.symbol);\n }\n } catch (error) {}\n }\n\n return null;\n }\n\n\n /**\n * Return the current logger instance.\n *\n * @returns The current logger instance.\n */\n getLogger():Logger {\n return this.converter.application.logger;\n }\n\n\n /**\n * Return the symbol id of the given symbol.\n *\n * The compiler sometimes does not assign an id to symbols, this method makes sure that we have one.\n * It will assign negative ids if they are not set.\n *\n * @param symbol The symbol whose id should be returned.\n * @returns The id of the given symbol.\n */\n getSymbolID(symbol:ts.Symbol):number {\n if (!symbol) return null;\n if (!symbol.id) symbol.id = this.symbolID--;\n return symbol.id;\n }\n\n\n /**\n * Register a newly generated reflection.\n *\n * Ensures that the reflection is both listed in [[Project.reflections]] and\n * [[Project.symbolMapping]] if applicable.\n *\n * @param reflection The reflection that should be registered.\n * @param node The node the given reflection was resolved from.\n * @param symbol The symbol the given reflection was resolved from.\n */\n registerReflection(reflection:Reflection, node:ts.Node, symbol?:ts.Symbol) {\n this.project.reflections[reflection.id] = reflection;\n\n var id = this.getSymbolID(symbol ? symbol : (node ? node.symbol : null));\n if (!this.isInherit && id && !this.project.symbolMapping[id]) {\n this.project.symbolMapping[id] = reflection.id;\n }\n }\n\n\n /**\n * Trigger a node reflection event.\n *\n * All events are dispatched on the current converter instance.\n *\n * @param name The name of the event that should be triggered.\n * @param reflection The triggering reflection.\n * @param node The triggering TypeScript node if available.\n */\n trigger(name:string, reflection:Reflection, node?:ts.Node) {\n this.converter.trigger(name, this, reflection, node);\n }\n\n\n /**\n * Run the given callback with the context configured for the given source file.\n *\n * @param node The TypeScript node containing the source file declaration.\n * @param callback The callback that should be executed.\n */\n withSourceFile(node:ts.SourceFile, callback:Function) {\n var options = this.converter.application.options;\n var externalPattern = this.externalPattern;\n var isExternal = this.fileNames.indexOf(node.fileName) == -1;\n if (externalPattern) {\n isExternal = isExternal || externalPattern.match(node.fileName);\n }\n\n if (isExternal && this.converter.excludeExternals) {\n return;\n }\n\n var isDeclaration = ts.isDeclarationFile(node);\n if (isDeclaration) {\n var lib = this.converter.getDefaultLib();\n var isLib = node.fileName.substr(-lib.length) == lib;\n if (!this.converter.includeDeclarations || isLib) {\n return;\n }\n }\n\n this.isExternal = isExternal;\n this.isDeclaration = isDeclaration;\n\n this.trigger(Converter.EVENT_FILE_BEGIN, this.project, node);\n callback();\n\n this.isExternal = false;\n this.isDeclaration = false;\n }\n\n\n /**\n * @param callback The callback function that should be executed with the changed context.\n */\n public withScope(scope:Reflection, callback:Function):void;\n\n /**\n * @param parameters An array of type parameters that should be set on the context while the callback is invoked.\n * @param callback The callback function that should be executed with the changed context.\n */\n public withScope(scope:Reflection, parameters:ts.NodeArray, callback:Function):void;\n\n /**\n * @param parameters An array of type parameters that should be set on the context while the callback is invoked.\n * @param preserve Should the currently set type parameters of the context be preserved?\n * @param callback The callback function that should be executed with the changed context.\n */\n public withScope(scope:Reflection, parameters:ts.NodeArray, preserve:boolean, callback:Function):void;\n\n /**\n * Run the given callback with the scope of the context set to the given reflection.\n *\n * @param scope The reflection that should be set as the scope of the context while the callback is invoked.\n */\n public withScope(scope:Reflection, ...args:any[]):void {\n if (!scope || !args.length) return;\n var callback = args.pop();\n var parameters = args.shift();\n\n var oldScope = this.scope;\n var oldTypeArguments = this.typeArguments;\n var oldTypeParameters = this.typeParameters;\n\n this.scope = scope;\n this.typeParameters = parameters ? this.extractTypeParameters(parameters, args.length > 0) : this.typeParameters;\n this.typeArguments = null;\n\n callback();\n\n this.scope = oldScope;\n this.typeParameters = oldTypeParameters;\n this.typeArguments = oldTypeArguments;\n }\n\n\n /**\n * Inherit the children of the given TypeScript node to the current scope.\n *\n * @param baseNode The node whose children should be inherited.\n * @param typeArguments The type arguments that apply while inheriting the given node.\n * @return The resulting reflection / the current scope.\n */\n inherit(baseNode:ts.Node, typeArguments?:ts.NodeArray):Reflection {\n var wasInherit = this.isInherit;\n var oldInherited = this.inherited;\n var oldInheritParent = this.inheritParent;\n var oldTypeArguments = this.typeArguments;\n\n this.isInherit = true;\n this.inheritParent = baseNode;\n this.inherited = [];\n\n var target = this.scope;\n if (!(target instanceof ContainerReflection)) {\n throw new Error('Expected container reflection');\n }\n\n if (baseNode.symbol) {\n var id = this.getSymbolID(baseNode.symbol);\n if (this.inheritedChildren && this.inheritedChildren.indexOf(id) != -1) {\n return target;\n } else {\n this.inheritedChildren = this.inheritedChildren || [];\n this.inheritedChildren.push(id);\n }\n }\n\n if (target.children) {\n this.inherited = target.children.map((c) => c.name);\n } else {\n this.inherited = [];\n }\n\n if (typeArguments) {\n this.typeArguments = typeArguments.map((t) => this.converter.convertType(this, t));\n } else {\n this.typeArguments = null;\n }\n\n this.converter.convertNode(this, baseNode);\n\n this.isInherit = wasInherit;\n this.inherited = oldInherited;\n this.inheritParent = oldInheritParent;\n this.typeArguments = oldTypeArguments;\n\n if (!this.isInherit) {\n delete this.inheritedChildren;\n }\n\n return target;\n }\n\n\n /**\n * Convert the given list of type parameter declarations into a type mapping.\n *\n * @param parameters The list of type parameter declarations that should be converted.\n * @param preserve Should the currently set type parameters of the context be preserved?\n * @returns The resulting type mapping.\n */\n private extractTypeParameters(parameters:ts.NodeArray, preserve?:boolean):ts.MapLike {\n var typeParameters:ts.MapLike = {};\n\n if (preserve) {\n for (var key in this.typeParameters) {\n if (!this.typeParameters.hasOwnProperty(key)) continue;\n typeParameters[key] = this.typeParameters[key];\n }\n }\n\n parameters.forEach((declaration:ts.TypeParameterDeclaration, index:number) => {\n var name = declaration.symbol.name;\n if (this.typeArguments && this.typeArguments[index]) {\n typeParameters[name] = this.typeArguments[index];\n } else {\n typeParameters[name] = createTypeParameter(this, declaration);\n }\n });\n\n return typeParameters;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/convert-expression.d.ts b/lib/converter/convert-expression.d.ts new file mode 100644 index 000000000..ba3ddd59e --- /dev/null +++ b/lib/converter/convert-expression.d.ts @@ -0,0 +1,3 @@ +import * as ts from "typescript"; +export declare function convertDefaultValue(node: ts.VariableDeclaration | ts.ParameterDeclaration | ts.EnumMember): string; +export declare function convertExpression(expression: ts.Expression): string; diff --git a/lib/converter/convert-expression.js b/lib/converter/convert-expression.js new file mode 100644 index 000000000..c70a5be71 --- /dev/null +++ b/lib/converter/convert-expression.js @@ -0,0 +1,28 @@ +"use strict"; +var ts = require("typescript"); +function convertDefaultValue(node) { + if (node.initializer) { + return convertExpression(node.initializer); + } + else { + return null; + } +} +exports.convertDefaultValue = convertDefaultValue; +function convertExpression(expression) { + switch (expression.kind) { + case 9: + return '"' + expression.text + '"'; + case 8: + return expression.text; + case 99: + return 'true'; + case 84: + return 'false'; + default: + var source = ts.getSourceFileOfNode(expression); + return source.text.substring(expression.pos, expression.end); + } +} +exports.convertExpression = convertExpression; +//# sourceMappingURL=convert-expression.js.map \ No newline at end of file diff --git a/lib/converter/convert-expression.js.map b/lib/converter/convert-expression.js.map new file mode 100644 index 000000000..38ffcac0d --- /dev/null +++ b/lib/converter/convert-expression.js.map @@ -0,0 +1 @@ +{"version":3,"file":"convert-expression.js","sourceRoot":"","sources":["../../src/lib/converter/convert-expression.ts"],"names":[],"mappings":";AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAUjC,6BAAoC,IAAiE;IACjG,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QACnB,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAAC,IAAI,CAAC,CAAC;QACJ,MAAM,CAAC,IAAI,CAAC;IAChB,CAAC;AACL,CAAC;AANe,2BAAmB,sBAMlC,CAAA;AAGD,2BAAkC,UAAwB;IAEtD,MAAM,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QACtB,KAAK,CAA2B;YAC5B,MAAM,CAAC,GAAG,GAA0B,UAAW,CAAC,IAAI,GAAG,GAAG,CAAC;QAC/D,KAAK,CAA4B;YAC7B,MAAM,CAAwB,UAAW,CAAC,IAAI,CAAC;QACnD,KAAK,EAAyB;YAC1B,MAAM,CAAC,MAAM,CAAC;QAClB,KAAK,EAA0B;YAC3B,MAAM,CAAC,OAAO,CAAC;QACnB;YACI,IAAI,MAAM,GAAG,EAAE,CAAC,mBAAmB,CAAU,UAAU,CAAC,CAAC;YACzD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IACrE,CAAC;AACL,CAAC;AAfe,yBAAiB,oBAehC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\n\n/**\n * Return the default value of the given node.\n *\n * @param node The TypeScript node whose default value should be extracted.\n * @returns The default value as a string.\n */\n\nexport function convertDefaultValue(node:ts.VariableDeclaration|ts.ParameterDeclaration|ts.EnumMember):string {\n if (node.initializer) {\n return convertExpression(node.initializer);\n } else {\n return null;\n }\n}\n\n\nexport function convertExpression(expression:ts.Expression):string\n{\n switch (expression.kind) {\n case ts.SyntaxKind.StringLiteral:\n return '\"' + (expression).text + '\"';\n case ts.SyntaxKind.NumericLiteral:\n return (expression).text;\n case ts.SyntaxKind.TrueKeyword:\n return 'true';\n case ts.SyntaxKind.FalseKeyword:\n return 'false';\n default:\n var source = ts.getSourceFileOfNode(expression);\n return source.text.substring(expression.pos, expression.end);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/converter.d.ts b/lib/converter/converter.d.ts new file mode 100644 index 000000000..4b209de06 --- /dev/null +++ b/lib/converter/converter.d.ts @@ -0,0 +1,47 @@ +import * as ts from "typescript"; +import { Application } from "../application"; +import { Reflection, Type, ProjectReflection } from "../models/index"; +import { Context } from "./context"; +import { ConverterComponent } from "./components"; +import { ChildableComponent, IComponentClass } from "../utils/component"; +export interface IConverterResult { + errors: ts.Diagnostic[]; + project: ProjectReflection; +} +export declare class Converter extends ChildableComponent { + name: string; + externalPattern: string; + includeDeclarations: boolean; + excludeExternals: boolean; + excludeNotExported: boolean; + excludePrivate: boolean; + private compilerHost; + private nodeConverters; + private typeNodeConverters; + private typeTypeConverters; + static EVENT_BEGIN: string; + static EVENT_END: string; + static EVENT_FILE_BEGIN: string; + static EVENT_CREATE_DECLARATION: string; + static EVENT_CREATE_SIGNATURE: string; + static EVENT_CREATE_PARAMETER: string; + static EVENT_CREATE_TYPE_PARAMETER: string; + static EVENT_FUNCTION_IMPLEMENTATION: string; + static EVENT_RESOLVE_BEGIN: string; + static EVENT_RESOLVE: string; + static EVENT_RESOLVE_END: string; + initialize(): void; + addComponent(name: string, componentClass: IComponentClass): ConverterComponent; + private addNodeConverter(converter); + private addTypeConverter(converter); + removeComponent(name: string): ConverterComponent; + private removeNodeConverter(converter); + private removeTypeConverter(converter); + removeAllComponents(): void; + convert(fileNames: string[]): IConverterResult; + convertNode(context: Context, node: ts.Node): Reflection; + convertType(context: Context, node?: ts.Node, type?: ts.Type): Type; + private compile(context); + private resolve(context); + getDefaultLib(): string; +} diff --git a/lib/converter/converter.js b/lib/converter/converter.js new file mode 100644 index 000000000..73131f5cc --- /dev/null +++ b/lib/converter/converter.js @@ -0,0 +1,232 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var declaration_1 = require("../utils/options/declaration"); +var context_1 = require("./context"); +var components_1 = require("./components"); +var compiler_host_1 = require("./utils/compiler-host"); +var component_1 = require("../utils/component"); +var Converter = (function (_super) { + __extends(Converter, _super); + function Converter() { + _super.apply(this, arguments); + } + Converter.prototype.initialize = function () { + this.compilerHost = new compiler_host_1.CompilerHost(this); + this.nodeConverters = {}; + this.typeTypeConverters = []; + this.typeNodeConverters = []; + }; + Converter.prototype.addComponent = function (name, componentClass) { + var component = _super.prototype.addComponent.call(this, name, componentClass); + if (component instanceof components_1.ConverterNodeComponent) { + this.addNodeConverter(component); + } + else if (component instanceof components_1.ConverterTypeComponent) { + this.addTypeConverter(component); + } + return component; + }; + Converter.prototype.addNodeConverter = function (converter) { + for (var _i = 0, _a = converter.supports; _i < _a.length; _i++) { + var supports = _a[_i]; + this.nodeConverters[supports] = converter; + } + }; + Converter.prototype.addTypeConverter = function (converter) { + if ("supportsNode" in converter && "convertNode" in converter) { + this.typeNodeConverters.push(converter); + this.typeNodeConverters.sort(function (a, b) { return (b.priority || 0) - (a.priority || 0); }); + } + if ("supportsType" in converter && "convertType" in converter) { + this.typeTypeConverters.push(converter); + this.typeTypeConverters.sort(function (a, b) { return (b.priority || 0) - (a.priority || 0); }); + } + }; + Converter.prototype.removeComponent = function (name) { + var component = _super.prototype.removeComponent.call(this, name); + if (component instanceof components_1.ConverterNodeComponent) { + this.removeNodeConverter(component); + } + else if (component instanceof components_1.ConverterTypeComponent) { + this.removeTypeConverter(component); + } + return component; + }; + Converter.prototype.removeNodeConverter = function (converter) { + var converters = this.nodeConverters; + var keys = _.keys(this.nodeConverters); + for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { + var key = keys_1[_i]; + if (converters[key] === converter) { + delete converters[key]; + } + } + }; + Converter.prototype.removeTypeConverter = function (converter) { + var index = this.typeNodeConverters.indexOf(converter); + if (index != -1) { + this.typeTypeConverters.splice(index, 1); + } + index = this.typeNodeConverters.indexOf(converter); + if (index != -1) { + this.typeNodeConverters.splice(index, 1); + } + }; + Converter.prototype.removeAllComponents = function () { + _super.prototype.removeAllComponents.call(this); + this.nodeConverters = {}; + this.typeTypeConverters = []; + this.typeNodeConverters = []; + }; + Converter.prototype.convert = function (fileNames) { + for (var i = 0, c = fileNames.length; i < c; i++) { + fileNames[i] = ts.normalizePath(ts.normalizeSlashes(fileNames[i])); + } + var program = ts.createProgram(fileNames, this.application.options.getCompilerOptions(), this.compilerHost); + var checker = program.getTypeChecker(); + var context = new context_1.Context(this, fileNames, checker, program); + this.trigger(Converter.EVENT_BEGIN, context); + var errors = this.compile(context); + var project = this.resolve(context); + this.trigger(Converter.EVENT_END, context); + return { + errors: errors, + project: project + }; + }; + Converter.prototype.convertNode = function (context, node) { + if (context.visitStack.indexOf(node) != -1) { + return null; + } + var oldVisitStack = context.visitStack; + context.visitStack = oldVisitStack.slice(); + context.visitStack.push(node); + var result; + if (node.kind in this.nodeConverters) { + result = this.nodeConverters[node.kind].convert(context, node); + } + context.visitStack = oldVisitStack; + return result; + }; + Converter.prototype.convertType = function (context, node, type) { + if (node) { + type = type || context.getTypeAtLocation(node); + for (var _i = 0, _a = this.typeNodeConverters; _i < _a.length; _i++) { + var converter = _a[_i]; + if (converter.supportsNode(context, node, type)) { + return converter.convertNode(context, node, type); + } + } + } + if (type) { + for (var _b = 0, _c = this.typeTypeConverters; _b < _c.length; _b++) { + var converter = _c[_b]; + if (converter.supportsType(context, type)) { + return converter.convertType(context, type); + } + } + } + }; + Converter.prototype.compile = function (context) { + var _this = this; + var program = context.program; + program.getSourceFiles().forEach(function (sourceFile) { + _this.convertNode(context, sourceFile); + }); + var diagnostics = program.getOptionsDiagnostics(); + if (diagnostics.length) + return diagnostics; + diagnostics = program.getSyntacticDiagnostics(); + if (diagnostics.length) + return diagnostics; + diagnostics = program.getGlobalDiagnostics(); + if (diagnostics.length) + return diagnostics; + diagnostics = program.getSemanticDiagnostics(); + if (diagnostics.length) + return diagnostics; + return []; + }; + Converter.prototype.resolve = function (context) { + this.trigger(Converter.EVENT_RESOLVE_BEGIN, context); + var project = context.project; + for (var id in project.reflections) { + if (!project.reflections.hasOwnProperty(id)) + continue; + this.trigger(Converter.EVENT_RESOLVE, context, project.reflections[id]); + } + this.trigger(Converter.EVENT_RESOLVE_END, context); + return project; + }; + Converter.prototype.getDefaultLib = function () { + return ts.getDefaultLibFileName(this.application.options.getCompilerOptions()); + }; + Converter.EVENT_BEGIN = 'begin'; + Converter.EVENT_END = 'end'; + Converter.EVENT_FILE_BEGIN = 'fileBegin'; + Converter.EVENT_CREATE_DECLARATION = 'createDeclaration'; + Converter.EVENT_CREATE_SIGNATURE = 'createSignature'; + Converter.EVENT_CREATE_PARAMETER = 'createParameter'; + Converter.EVENT_CREATE_TYPE_PARAMETER = 'createTypeParameter'; + Converter.EVENT_FUNCTION_IMPLEMENTATION = 'functionImplementation'; + Converter.EVENT_RESOLVE_BEGIN = 'resolveBegin'; + Converter.EVENT_RESOLVE = 'resolveReflection'; + Converter.EVENT_RESOLVE_END = 'resolveEnd'; + __decorate([ + component_1.Option({ + name: "name", + help: "Set the name of the project that will be used in the header of the template." + }) + ], Converter.prototype, "name", void 0); + __decorate([ + component_1.Option({ + name: "externalPattern", + help: 'Define a pattern for files that should be considered being external.' + }) + ], Converter.prototype, "externalPattern", void 0); + __decorate([ + component_1.Option({ + name: "includeDeclarations", + help: 'Turn on parsing of .d.ts declaration files.', + type: declaration_1.ParameterType.Boolean + }) + ], Converter.prototype, "includeDeclarations", void 0); + __decorate([ + component_1.Option({ + name: "excludeExternals", + help: 'Prevent externally resolved TypeScript files from being documented.', + type: declaration_1.ParameterType.Boolean + }) + ], Converter.prototype, "excludeExternals", void 0); + __decorate([ + component_1.Option({ + name: "excludeNotExported", + help: 'Prevent symbols that are not exported from being documented.', + type: declaration_1.ParameterType.Boolean + }) + ], Converter.prototype, "excludeNotExported", void 0); + __decorate([ + component_1.Option({ + name: "excludePrivate", + help: 'Ignores private variables and methods', + type: declaration_1.ParameterType.Boolean + }) + ], Converter.prototype, "excludePrivate", void 0); + Converter = __decorate([ + component_1.Component({ name: "converter", internal: true, childClass: components_1.ConverterComponent }) + ], Converter); + return Converter; +}(component_1.ChildableComponent)); +exports.Converter = Converter; +//# sourceMappingURL=converter.js.map \ No newline at end of file diff --git a/lib/converter/converter.js.map b/lib/converter/converter.js.map new file mode 100644 index 000000000..b7d4bfb35 --- /dev/null +++ b/lib/converter/converter.js.map @@ -0,0 +1 @@ +{"version":3,"file":"converter.js","sourceRoot":"","sources":["../../src/lib/converter/converter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;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BAAa,CAAC,OAAO;SAC9B,CAAC;qDAAA;IA3CN;QAAC,qBAAS,CAAC,EAAC,IAAI,EAAC,WAAW,EAAE,QAAQ,EAAC,IAAI,EAAE,UAAU,EAAC,+BAAkB,EAAC,CAAC;iBAAA;IAgY5E,gBAAC;AAAD,CAAC,AA/XD,CAA+B,8BAAkB,GA+XhD;AA/XY,iBAAS,YA+XrB,CAAA","sourcesContent":["import * as ts from \"typescript\";\nimport * as Path from \"path\";\n\nimport {Application} from \"../application\";\nimport {ParameterType} from \"../utils/options/declaration\";\nimport {Reflection, Type, ProjectReflection} from \"../models/index\";\nimport {Context} from \"./context\";\nimport {ConverterComponent, ConverterNodeComponent, ConverterTypeComponent, ITypeTypeConverter, ITypeNodeConverter} from \"./components\";\nimport {CompilerHost} from \"./utils/compiler-host\";\nimport {Component, Option, ChildableComponent, IComponentClass} from \"../utils/component\"\n\n\n/**\n * Result structure of the [[Converter.convert]] method.\n */\nexport interface IConverterResult\n{\n /**\n * An array containing all errors generated by the TypeScript compiler.\n */\n errors:ts.Diagnostic[];\n\n /**\n * The resulting project reflection.\n */\n project:ProjectReflection;\n}\n\n\n/**\n * Event callback definition for generic converter events.\n *\n * @see [[Converter.EVENT_BEGIN]]\n * @see [[Converter.EVENT_END]]\n * @see [[Converter.EVENT_RESOLVE_BEGIN]]\n * @see [[Converter.EVENT_RESOLVE_END]]\n */\ninterface IConverterCallback\n{\n /**\n * @param context The context object describing the current state the converter is in.\n */\n (context:Context):void;\n}\n\n\n/**\n * Event callback definition for events triggered by factories.\n *\n * @see [[Converter.EVENT_FILE_BEGIN]]\n * @see [[Converter.EVENT_CREATE_DECLARATION]]\n * @see [[Converter.EVENT_CREATE_SIGNATURE]]\n * @see [[Converter.EVENT_CREATE_PARAMETER]]\n * @see [[Converter.EVENT_CREATE_TYPE_PARAMETER]]\n * @see [[Converter.EVENT_FUNCTION_IMPLEMENTATION]]\n */\ninterface IConverterNodeCallback\n{\n /**\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently processed.\n * @param node The node that is currently processed if available.\n */\n (context:Context, reflection:Reflection, node?:ts.Node):void;\n}\n\n\n/**\n * Event callback definition for events during the resolving phase.\n *\n * @see [[Converter.EVENT_RESOLVE]]\n */\ninterface IConverterResolveCallback\n{\n /**\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently resolved.\n */\n (context:Context, reflection:Reflection):void;\n}\n\n\n/**\n * Compiles source files using TypeScript and converts compiler symbols to reflections.\n */\n@Component({name:\"converter\", internal:true, childClass:ConverterComponent})\nexport class Converter extends ChildableComponent\n{\n /**\n * The human readable name of the project. Used within the templates to set the title of the document.\n */\n @Option({\n name: \"name\",\n help: \"Set the name of the project that will be used in the header of the template.\"\n })\n name:string;\n\n @Option({\n name: \"externalPattern\",\n help: 'Define a pattern for files that should be considered being external.'\n })\n externalPattern:string;\n\n @Option({\n name: \"includeDeclarations\",\n help: 'Turn on parsing of .d.ts declaration files.',\n type: ParameterType.Boolean\n })\n includeDeclarations:boolean;\n\n @Option({\n name: \"excludeExternals\",\n help: 'Prevent externally resolved TypeScript files from being documented.',\n type: ParameterType.Boolean\n })\n excludeExternals:boolean;\n\n @Option({\n name: \"excludeNotExported\",\n help: 'Prevent symbols that are not exported from being documented.',\n type: ParameterType.Boolean\n })\n excludeNotExported:boolean;\n\n @Option({\n name: \"excludePrivate\",\n help: 'Ignores private variables and methods',\n type: ParameterType.Boolean\n })\n excludePrivate:boolean;\n\n private compilerHost:CompilerHost;\n\n private nodeConverters:{[syntaxKind:number]:ConverterNodeComponent};\n\n private typeNodeConverters:ITypeNodeConverter[];\n\n private typeTypeConverters:ITypeTypeConverter[];\n\n\n /**\n * General events\n */\n\n /**\n * Triggered when the converter begins converting a project.\n * The listener should implement [[IConverterCallback]].\n * @event\n */\n static EVENT_BEGIN:string = 'begin';\n\n /**\n * Triggered when the converter has finished converting a project.\n * The listener should implement [[IConverterCallback]].\n * @event\n */\n static EVENT_END:string = 'end';\n\n\n /**\n * Factory events\n */\n\n /**\n * Triggered when the converter begins converting a source file.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_FILE_BEGIN:string = 'fileBegin';\n\n /**\n * Triggered when the converter has created a declaration reflection.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_CREATE_DECLARATION:string = 'createDeclaration';\n\n /**\n * Triggered when the converter has created a signature reflection.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_CREATE_SIGNATURE:string = 'createSignature';\n\n /**\n * Triggered when the converter has created a parameter reflection.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_CREATE_PARAMETER:string = 'createParameter';\n\n /**\n * Triggered when the converter has created a type parameter reflection.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_CREATE_TYPE_PARAMETER:string = 'createTypeParameter';\n\n /**\n * Triggered when the converter has found a function implementation.\n * The listener should implement [[IConverterNodeCallback]].\n * @event\n */\n static EVENT_FUNCTION_IMPLEMENTATION:string = 'functionImplementation';\n\n\n /**\n * Resolve events\n */\n\n /**\n * Triggered when the converter begins resolving a project.\n * The listener should implement [[IConverterCallback]].\n * @event\n */\n static EVENT_RESOLVE_BEGIN:string = 'resolveBegin';\n\n /**\n * Triggered when the converter resolves a reflection.\n * The listener should implement [[IConverterResolveCallback]].\n * @event\n */\n static EVENT_RESOLVE:string = 'resolveReflection';\n\n /**\n * Triggered when the converter has finished resolving a project.\n * The listener should implement [[IConverterCallback]].\n * @event\n */\n static EVENT_RESOLVE_END:string = 'resolveEnd';\n\n\n\n /**\n * Create a new Converter instance.\n *\n * @param application The application instance this converter relies on. The application\n * must expose the settings that should be used and serves as a global logging endpoint.\n */\n initialize() {\n this.compilerHost = new CompilerHost(this);\n this.nodeConverters = {};\n this.typeTypeConverters = [];\n this.typeNodeConverters = [];\n }\n\n\n addComponent(name:string, componentClass:IComponentClass):ConverterComponent {\n var component = super.addComponent(name, componentClass);\n if (component instanceof ConverterNodeComponent) {\n this.addNodeConverter(component);\n } else if (component instanceof ConverterTypeComponent) {\n this.addTypeConverter(|ITypeNodeConverter>component);\n }\n\n return component;\n }\n\n\n private addNodeConverter(converter:ConverterNodeComponent) {\n for (var supports of converter.supports) {\n this.nodeConverters[supports] = converter;\n }\n }\n\n\n private addTypeConverter(converter:ITypeTypeConverter|ITypeNodeConverter) {\n if (\"supportsNode\" in converter && \"convertNode\" in converter) {\n this.typeNodeConverters.push(>converter);\n this.typeNodeConverters.sort((a, b) => (b.priority || 0) - (a.priority || 0));\n }\n\n if (\"supportsType\" in converter && \"convertType\" in converter) {\n this.typeTypeConverters.push(>converter);\n this.typeTypeConverters.sort((a, b) => (b.priority || 0) - (a.priority || 0));\n }\n }\n\n\n removeComponent(name:string):ConverterComponent {\n var component = super.removeComponent(name);\n if (component instanceof ConverterNodeComponent) {\n this.removeNodeConverter(component);\n } else if (component instanceof ConverterTypeComponent) {\n this.removeTypeConverter(component);\n }\n\n return component;\n }\n\n\n private removeNodeConverter(converter:ConverterNodeComponent) {\n var converters = this.nodeConverters;\n var keys = _.keys(this.nodeConverters);\n for (var key of keys) {\n if (converters[key] === converter) {\n delete converters[key];\n }\n }\n }\n\n\n private removeTypeConverter(converter:ConverterTypeComponent) {\n var index = this.typeNodeConverters.indexOf(converter);\n if (index != -1) {\n this.typeTypeConverters.splice(index, 1);\n }\n\n index = this.typeNodeConverters.indexOf(converter);\n if (index != -1) {\n this.typeNodeConverters.splice(index, 1);\n }\n }\n\n\n removeAllComponents() {\n super.removeAllComponents();\n\n this.nodeConverters = {};\n this.typeTypeConverters = [];\n this.typeNodeConverters = [];\n }\n\n\n\n /**\n * Compile the given source files and create a project reflection for them.\n *\n * @param fileNames Array of the file names that should be compiled.\n */\n convert(fileNames:string[]):IConverterResult {\n for (var i = 0, c = fileNames.length; i < c; i++) {\n fileNames[i] = ts.normalizePath(ts.normalizeSlashes(fileNames[i]));\n }\n\n var program = ts.createProgram(fileNames, this.application.options.getCompilerOptions(), this.compilerHost);\n var checker = program.getTypeChecker();\n var context = new Context(this, fileNames, checker, program);\n\n this.trigger(Converter.EVENT_BEGIN, context);\n\n var errors = this.compile(context);\n var project = this.resolve(context);\n\n this.trigger(Converter.EVENT_END, context);\n\n return {\n errors: errors,\n project: project\n }\n }\n\n\n /**\n * Analyze the given node and create a suitable reflection.\n *\n * This function checks the kind of the node and delegates to the matching function implementation.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The compiler node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convertNode(context:Context, node:ts.Node):Reflection {\n if (context.visitStack.indexOf(node) != -1) {\n return null;\n }\n\n var oldVisitStack = context.visitStack;\n context.visitStack = oldVisitStack.slice();\n context.visitStack.push(node);\n\n var result:Reflection;\n if (node.kind in this.nodeConverters) {\n result = this.nodeConverters[node.kind].convert(context, node);\n }\n\n context.visitStack = oldVisitStack;\n return result;\n }\n\n\n /**\n * Convert the given TypeScript type into its TypeDoc type reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The node whose type should be reflected.\n * @param type The type of the node if already known.\n * @returns The TypeDoc type reflection representing the given node and type.\n */\n convertType(context:Context, node?:ts.Node, type?:ts.Type):Type {\n // Run all node based type conversions\n if (node) {\n type = type || context.getTypeAtLocation(node);\n\n for (let converter of this.typeNodeConverters) {\n if (converter.supportsNode(context, node, type)) {\n return converter.convertNode(context, node, type);\n }\n }\n }\n\n // Run all type based type conversions\n if (type) {\n for (let converter of this.typeTypeConverters) {\n if (converter.supportsType(context, type)) {\n return converter.convertType(context, type);\n }\n }\n }\n }\n\n\n /**\n * Compile the files within the given context and convert the compiler symbols to reflections.\n *\n * @param context The context object describing the current state the converter is in.\n * @returns An array containing all errors generated by the TypeScript compiler.\n */\n private compile(context:Context):ts.Diagnostic[] {\n var program = context.program;\n\n program.getSourceFiles().forEach((sourceFile) => {\n this.convertNode(context, sourceFile);\n });\n \n let diagnostics = program.getOptionsDiagnostics();\n if (diagnostics.length) return diagnostics;\n \n diagnostics = program.getSyntacticDiagnostics();\n if (diagnostics.length) return diagnostics;\n \n diagnostics = program.getGlobalDiagnostics();\n if (diagnostics.length) return diagnostics;\n\n diagnostics = program.getSemanticDiagnostics();\n if (diagnostics.length) return diagnostics;\n \n return [];\n }\n\n\n /**\n * Resolve the project within the given context.\n *\n * @param context The context object describing the current state the converter is in.\n * @returns The final project reflection.\n */\n private resolve(context:Context):ProjectReflection {\n this.trigger(Converter.EVENT_RESOLVE_BEGIN, context);\n var project = context.project;\n\n for (var id in project.reflections) {\n if (!project.reflections.hasOwnProperty(id)) continue;\n this.trigger(Converter.EVENT_RESOLVE, context, project.reflections[id]);\n }\n\n this.trigger(Converter.EVENT_RESOLVE_END, context);\n return project;\n }\n\n\n /**\n * Return the basename of the default library that should be used.\n *\n * @returns The basename of the default library.\n */\n getDefaultLib():string {\n return ts.getDefaultLibFileName(this.application.options.getCompilerOptions());\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/factories/comment.d.ts b/lib/converter/factories/comment.d.ts new file mode 100644 index 000000000..6690366ff --- /dev/null +++ b/lib/converter/factories/comment.d.ts @@ -0,0 +1,5 @@ +import * as ts from "typescript"; +import { Comment } from "../../models/comments/index"; +export declare function createComment(node: ts.Node): Comment; +export declare function getRawComment(node: ts.Node): string; +export declare function parseComment(text: string, comment?: Comment): Comment; diff --git a/lib/converter/factories/comment.js b/lib/converter/factories/comment.js new file mode 100644 index 000000000..14fb40f4f --- /dev/null +++ b/lib/converter/factories/comment.js @@ -0,0 +1,132 @@ +"use strict"; +var ts = require("typescript"); +var index_1 = require("../../models/comments/index"); +function createComment(node) { + var comment = getRawComment(node); + if (comment == null) { + return null; + } + return parseComment(comment); +} +exports.createComment = createComment; +function isTopmostModuleDeclaration(node) { + if (node.nextContainer && node.nextContainer.kind == 225) { + var next = node.nextContainer; + if (node.name.end + 1 == next.name.pos) { + return false; + } + } + return true; +} +function getRootModuleDeclaration(node) { + while (node.parent && node.parent.kind == 225) { + var parent_1 = node.parent; + if (node.name.pos == parent_1.name.end + 1) { + node = parent_1; + } + else { + break; + } + } + return node; +} +function getRawComment(node) { + if (node.parent && node.parent.kind === 219) { + node = node.parent.parent; + } + else if (node.kind === 225) { + if (!isTopmostModuleDeclaration(node)) { + return null; + } + else { + node = getRootModuleDeclaration(node); + } + } + var sourceFile = ts.getSourceFileOfNode(node); + var comments = ts.getJsDocComments(node, sourceFile); + if (comments && comments.length) { + var comment; + if (node.kind == 256) { + if (comments.length == 1) + return null; + comment = comments[0]; + } + else { + comment = comments[comments.length - 1]; + } + return sourceFile.text.substring(comment.pos, comment.end); + } + else { + return null; + } +} +exports.getRawComment = getRawComment; +function parseComment(text, comment) { + if (comment === void 0) { comment = new index_1.Comment(); } + var currentTag; + var shortText = 0; + function consumeTypeData(line) { + line = line.replace(/^\{[^\}]*\}+/, ''); + line = line.replace(/^\[[^\[][^\]]*\]+/, ''); + return line.trim(); + } + function readBareLine(line) { + if (currentTag) { + currentTag.text += '\n' + line; + } + else if (line == '' && shortText == 0) { + } + else if (line == '' && shortText == 1) { + shortText = 2; + } + else { + if (shortText == 2) { + comment.text += (comment.text == '' ? '' : '\n') + line; + } + else { + comment.shortText += (comment.shortText == '' ? '' : '\n') + line; + shortText = 1; + } + } + } + function readTagLine(line, tag) { + var tagName = tag[1].toLowerCase(); + line = line.substr(tagName.length + 1).trim(); + if (tagName == 'return') + tagName = 'returns'; + if (tagName == 'param' || tagName == 'typeparam') { + line = consumeTypeData(line); + var param = /[^\s]+/.exec(line); + if (param) { + var paramName = param[0]; + line = line.substr(paramName.length + 1).trim(); + } + line = consumeTypeData(line); + line = line.replace(/^\-\s+/, ''); + } + else if (tagName == 'returns') { + line = consumeTypeData(line); + } + currentTag = new index_1.CommentTag(tagName, paramName, line); + if (!comment.tags) + comment.tags = []; + comment.tags.push(currentTag); + } + function readLine(line) { + line = line.replace(/^\s*\*? ?/, ''); + line = line.replace(/\s*$/, ''); + var tag = /^@(\w+)/.exec(line); + if (tag) { + readTagLine(line, tag); + } + else { + readBareLine(line); + } + } + text = text.replace(/^\s*\/\*+/, ''); + text = text.replace(/\*+\/\s*$/, ''); + text.split(/\r\n?|\n/).forEach(readLine); + return comment; +} +exports.parseComment = parseComment; +//# sourceMappingURL=comment.js.map \ No newline at end of file diff --git a/lib/converter/factories/comment.js.map b/lib/converter/factories/comment.js.map new file mode 100644 index 000000000..7d366699c --- /dev/null +++ b/lib/converter/factories/comment.js.map @@ -0,0 +1 @@ +{"version":3,"file":"comment.js","sourceRoot":"","sources":["../../../src/lib/converter/factories/comment.ts"],"names":[],"mappings":";AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAkC,6BAA6B,CAAC,CAAA;AAUhE,uBAA8B,IAAY;IACtC,IAAI,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAClC,EAAE,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC;QAClB,MAAM,CAAC,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAPe,qBAAa,gBAO5B,CAAA;AAgBD,oCAAoC,IAAyB;IACzD,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,GAA+B,CAAC,CAAC,CAAC;QACnF,IAAI,IAAI,GAAyB,IAAI,CAAC,aAAa,CAAC;QACpD,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACrC,MAAM,CAAC,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IAED,MAAM,CAAC,IAAI,CAAC;AAChB,CAAC;AAYD,kCAAkC,IAAyB;IAEvD,OAAO,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,GAA+B,EAAE,CAAC;QACxE,IAAI,QAAM,GAAy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;YAC9B,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,UAAU,GAAG,IAAI,kBAAU,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QACtD,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;YAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,kBAAkB,IAAW;QACzB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACrC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAEhC,IAAI,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACN,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC3B,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,YAAY,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;IAID,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACrC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEzC,MAAM,CAAC,OAAO,CAAC;AACnB,CAAC;AArEe,oBAAY,eAqE3B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Comment, CommentTag} from \"../../models/comments/index\";\n\n\n/**\n * Return the parsed comment of the given TypeScript node.\n *\n * @param node The node whose comment should be returned.\n * @return The parsed comment as a [[Comment]] instance or NULL if\n * no comment is present.\n */\nexport function createComment(node:ts.Node):Comment {\n var comment = getRawComment(node);\n if (comment == null) {\n return null;\n }\n\n return parseComment(comment);\n}\n\n\n/**\n * Check whether the given module declaration is the topmost.\n *\n * This funtion returns TRUE if there is no trailing module defined, in\n * the following example this would be the case only for module C.\n *\n * ```\n * module A.B.C { }\n * ```\n *\n * @param node The module definition that should be tested.\n * @return TRUE if the given node is the topmost module declaration, FALSE otherwise.\n */\nfunction isTopmostModuleDeclaration(node:ts.ModuleDeclaration):boolean {\n if (node.nextContainer && node.nextContainer.kind == ts.SyntaxKind.ModuleDeclaration) {\n let next = node.nextContainer;\n if (node.name.end + 1 == next.name.pos) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Return the root module declaration of the given module declaration.\n *\n * In the following example this function would always return module\n * A no matter which of the modules was passed in.\n *\n * ```\n * module A.B.C { }\n * ```\n */\nfunction getRootModuleDeclaration(node:ts.ModuleDeclaration):ts.Node\n{\n while (node.parent && node.parent.kind == ts.SyntaxKind.ModuleDeclaration) {\n let parent = node.parent;\n if (node.name.pos == parent.name.end + 1) {\n node = parent;\n } else {\n break;\n }\n }\n\n return node;\n}\n\n\n/**\n * Return the raw comment string for the given node.\n *\n * @param node The node whose comment should be resolved.\n * @returns The raw comment string or NULL if no comment could be found.\n */\nexport function getRawComment(node:ts.Node):string {\n if (node.parent && node.parent.kind === ts.SyntaxKind.VariableDeclarationList) {\n node = node.parent.parent;\n } else if (node.kind === ts.SyntaxKind.ModuleDeclaration) {\n if (!isTopmostModuleDeclaration(node)) {\n return null;\n } else {\n node = getRootModuleDeclaration(node);\n }\n }\n\n var sourceFile = ts.getSourceFileOfNode(node);\n var comments = ts.getJsDocComments(node, sourceFile);\n if (comments && comments.length) {\n var comment:ts.CommentRange;\n if (node.kind == ts.SyntaxKind.SourceFile) {\n if (comments.length == 1) return null;\n comment = comments[0];\n } else {\n comment = comments[comments.length - 1];\n }\n\n return sourceFile.text.substring(comment.pos, comment.end);\n } else {\n return null;\n }\n}\n\n\n/**\n * Parse the given doc comment string.\n *\n * @param text The doc comment string that should be parsed.\n * @param comment The [[Models.Comment]] instance the parsed results should be stored into.\n * @returns A populated [[Models.Comment]] instance.\n */\nexport function parseComment(text:string, comment:Comment = new Comment()):Comment {\n var currentTag:CommentTag;\n var shortText:number = 0;\n\n function consumeTypeData(line:string):string {\n line = line.replace(/^\\{[^\\}]*\\}+/, '');\n line = line.replace(/^\\[[^\\[][^\\]]*\\]+/, '');\n return line.trim();\n }\n\n function readBareLine(line:string) {\n if (currentTag) {\n currentTag.text += '\\n' + line;\n } else if (line == '' && shortText == 0) {\n // Ignore\n } else if (line == '' && shortText == 1) {\n shortText = 2;\n } else {\n if (shortText == 2) {\n comment.text += (comment.text == '' ? '' : '\\n') + line;\n } else {\n comment.shortText += (comment.shortText == '' ? '' : '\\n') + line;\n shortText = 1;\n }\n }\n }\n\n function readTagLine(line:string, tag:RegExpExecArray) {\n var tagName = tag[1].toLowerCase();\n line = line.substr(tagName.length + 1).trim();\n\n if (tagName == 'return') tagName = 'returns';\n if (tagName == 'param' || tagName == 'typeparam') {\n line = consumeTypeData(line);\n var param = /[^\\s]+/.exec(line);\n if (param) {\n var paramName = param[0];\n line = line.substr(paramName.length + 1).trim();\n }\n line = consumeTypeData(line);\n line = line.replace(/^\\-\\s+/, '');\n } else if (tagName == 'returns') {\n line = consumeTypeData(line);\n }\n\n currentTag = new CommentTag(tagName, paramName, line);\n if (!comment.tags) comment.tags = [];\n comment.tags.push(currentTag);\n }\n\n function readLine(line:string) {\n line = line.replace(/^\\s*\\*? ?/, '');\n line = line.replace(/\\s*$/, '');\n\n var tag = /^@(\\w+)/.exec(line);\n if (tag) {\n readTagLine(line, tag);\n } else {\n readBareLine(line);\n }\n }\n\n // text = text.replace(/^\\s*\\/\\*+\\s*(\\r\\n?|\\n)/, '');\n // text = text.replace(/(\\r\\n?|\\n)\\s*\\*+\\/\\s*$/, '');\n text = text.replace(/^\\s*\\/\\*+/, '');\n text = text.replace(/\\*+\\/\\s*$/, '');\n text.split(/\\r\\n?|\\n/).forEach(readLine);\n\n return comment;\n}\n"]} \ No newline at end of file diff --git a/lib/converter/factories/declaration.d.ts b/lib/converter/factories/declaration.d.ts new file mode 100644 index 000000000..6f551dc80 --- /dev/null +++ b/lib/converter/factories/declaration.d.ts @@ -0,0 +1,4 @@ +import * as ts from "typescript"; +import { ReflectionKind, DeclarationReflection } from "../../models/index"; +import { Context } from "../context"; +export declare function createDeclaration(context: Context, node: ts.Node, kind: ReflectionKind, name?: string): DeclarationReflection; diff --git a/lib/converter/factories/declaration.js b/lib/converter/factories/declaration.js new file mode 100644 index 000000000..9cfa73d25 --- /dev/null +++ b/lib/converter/factories/declaration.js @@ -0,0 +1,128 @@ +"use strict"; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var converter_1 = require("../converter"); +var reference_1 = require("./reference"); +var nonStaticKinds = [ + index_1.ReflectionKind.Class, + index_1.ReflectionKind.Interface, + index_1.ReflectionKind.Module +]; +function createDeclaration(context, node, kind, name) { + var container = context.scope; + if (!(container instanceof index_1.ContainerReflection)) { + throw new Error('Expected container reflection.'); + } + if (!name) { + if (node.localSymbol) { + name = node.localSymbol.name; + } + else if (node.symbol) { + name = node.symbol.name; + } + else { + return null; + } + } + var isExported; + if (container.kindOf([index_1.ReflectionKind.Module, index_1.ReflectionKind.ExternalModule])) { + isExported = false; + } + else { + isExported = container.flags.isExported; + } + if (kind == index_1.ReflectionKind.ExternalModule) { + isExported = true; + } + else if (node.parent && node.parent.kind == 219) { + isExported = isExported || !!(node.parent.parent.flags & 1); + } + else { + isExported = isExported || !!(node.flags & 1); + } + if (!isExported && context.converter.excludeNotExported) { + return null; + } + var isPrivate = !!(node.flags & 8); + if (context.isInherit && isPrivate) { + return null; + } + var isConstructorProperty = false; + var isStatic = false; + if (nonStaticKinds.indexOf(kind) == -1) { + isStatic = !!(node.flags & 32); + if (container.kind == index_1.ReflectionKind.Class) { + if (node.parent && node.parent.kind == 148) { + isConstructorProperty = true; + } + else if (!node.parent || node.parent.kind != 221) { + isStatic = true; + } + } + } + var child; + var children = container.children = container.children || []; + children.forEach(function (n) { + if (n.name == name && n.flags.isStatic == isStatic) + child = n; + }); + if (!child) { + child = new index_1.DeclarationReflection(container, name, kind); + child.setFlag(index_1.ReflectionFlag.Static, isStatic); + child.setFlag(index_1.ReflectionFlag.Private, isPrivate); + child.setFlag(index_1.ReflectionFlag.ConstructorProperty, isConstructorProperty); + child.setFlag(index_1.ReflectionFlag.Exported, isExported); + child = setupDeclaration(context, child, node); + if (child) { + children.push(child); + context.registerReflection(child, node); + } + } + else { + child = mergeDeclarations(context, child, node, kind); + } + if (child) { + context.trigger(converter_1.Converter.EVENT_CREATE_DECLARATION, child, node); + } + return child; +} +exports.createDeclaration = createDeclaration; +function setupDeclaration(context, reflection, node) { + reflection.setFlag(index_1.ReflectionFlag.External, context.isExternal); + reflection.setFlag(index_1.ReflectionFlag.Protected, !!(node.flags & 16)); + reflection.setFlag(index_1.ReflectionFlag.Public, !!(node.flags & 4)); + reflection.setFlag(index_1.ReflectionFlag.Optional, !!(node['questionToken'])); + if (context.isInherit && + (node.parent == context.inheritParent || reflection.flags.isConstructorProperty)) { + if (!reflection.inheritedFrom) { + reflection.inheritedFrom = reference_1.createReferenceType(context, node.symbol, true); + reflection.getAllSignatures().forEach(function (signature) { + signature.inheritedFrom = reference_1.createReferenceType(context, node.symbol, true); + }); + } + } + return reflection; +} +function mergeDeclarations(context, reflection, node, kind) { + if (reflection.kind != kind) { + var weights = [index_1.ReflectionKind.Module, index_1.ReflectionKind.Enum, index_1.ReflectionKind.Class]; + var kindWeight = weights.indexOf(kind); + var childKindWeight = weights.indexOf(reflection.kind); + if (kindWeight > childKindWeight) { + reflection.kind = kind; + } + } + if (context.isInherit && + context.inherited.indexOf(reflection.name) != -1 && + (node.parent == context.inheritParent || reflection.flags.isConstructorProperty)) { + if (!reflection.overwrites) { + reflection.overwrites = reference_1.createReferenceType(context, node.symbol, true); + reflection.getAllSignatures().forEach(function (signature) { + signature.overwrites = reference_1.createReferenceType(context, node.symbol, true); + }); + } + return null; + } + return reflection; +} +//# sourceMappingURL=declaration.js.map \ No newline at end of file diff --git a/lib/converter/factories/declaration.js.map b/lib/converter/factories/declaration.js.map new file mode 100644 index 000000000..eccc8e2c4 --- /dev/null +++ b/lib/converter/factories/declaration.js.map @@ -0,0 +1 @@ +{"version":3,"file":"declaration.js","sourceRoot":"","sources":["../../../src/lib/converter/factories/declaration.ts"],"names":[],"mappings":";AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAyF,oBAAoB,CAAC,CAAA;AAE9G,0BAAwB,cAAc,CAAC,CAAA;AACvC,0BAAkC,aAAa,CAAC,CAAA;AAMhD,IAAI,cAAc,GAAG;IACjB,sBAAc,CAAC,KAAK;IACpB,sBAAc,CAAC,SAAS;IACxB,sBAAc,CAAC,MAAM;CACxB,CAAC;AAaF,2BAAkC,OAAe,EAAE,IAAY,EAAE,IAAmB,EAAE,IAAY;IAC9F,IAAI,SAAS,GAAwB,OAAO,CAAC,KAAK,CAAC;IACnD,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,2BAAmB,CAAC,CAAC,CAAC,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACtD,CAAC;IAGD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACR,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;YACnB,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QACjC,CAAC;QAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YACrB,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,MAAM,CAAC,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAGD,IAAI,UAAkB,CAAC;IACvB,EAAE,CAAC,CAAC,SAAS,CAAC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AAC;QACC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;YACzB,UAAU,CAAC,UAAU,GAAG,+BAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACxE,UAAU,CAAC,gBAAgB,EAAE,CAAC,OAAO,CAAC,UAAC,SAAS;gBAC5C,SAAS,CAAC,UAAU,GAAG,+BAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC3E,CAAC,CAAC,CAAC;QACP,CAAC;QACD,MAAM,CAAC,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,UAAU,CAAC;AACtB,CAAC","sourcesContent":["import * as ts from \"typescript\";\n\nimport {ReflectionKind, ReflectionFlag, ContainerReflection, DeclarationReflection} from \"../../models/index\";\nimport {Context} from \"../context\";\nimport {Converter} from \"../converter\";\nimport {createReferenceType} from \"./reference\";\n\n\n/**\n * List of reflection kinds that never should be static.\n */\nvar nonStaticKinds = [\n ReflectionKind.Class,\n ReflectionKind.Interface,\n ReflectionKind.Module\n];\n\n\n/**\n * Create a declaration reflection from the given TypeScript node.\n *\n * @param context The context object describing the current state the converter is in. The\n * scope of the context will be the parent of the generated reflection.\n * @param node The TypeScript node that should be converted to a reflection.\n * @param kind The desired kind of the reflection.\n * @param name The desired name of the reflection.\n * @returns The resulting reflection.\n */\nexport function createDeclaration(context:Context, node:ts.Node, kind:ReflectionKind, name?:string):DeclarationReflection {\n var container = context.scope;\n if (!(container instanceof ContainerReflection)) {\n throw new Error('Expected container reflection.');\n }\n\n // Ensure we have a name for the reflection\n if (!name) {\n if (node.localSymbol) {\n name = node.localSymbol.name;\n } else if (node.symbol) {\n name = node.symbol.name;\n } else {\n return null;\n }\n }\n\n // Test whether the node is exported\n var isExported:boolean;\n if (container.kindOf([ReflectionKind.Module, ReflectionKind.ExternalModule])) {\n isExported = false; // Don't inherit exported state in modules and namespaces\n } else {\n isExported = container.flags.isExported;\n }\n\n if (kind == ReflectionKind.ExternalModule) {\n isExported = true; // Always mark external modules as exported\n } else if (node.parent && node.parent.kind == ts.SyntaxKind.VariableDeclarationList) {\n isExported = isExported || !!(node.parent.parent.flags & ts.NodeFlags.Export)\n } else {\n isExported = isExported || !!(node.flags & ts.NodeFlags.Export);\n }\n\n if (!isExported && context.converter.excludeNotExported) {\n return null;\n }\n\n // Test whether the node is private, when inheriting ignore private members\n var isPrivate = !!(node.flags & ts.NodeFlags.Private);\n if (context.isInherit && isPrivate) {\n return null;\n }\n\n // Test whether the node is static, when merging a module to a class make the node static\n var isConstructorProperty:boolean = false;\n var isStatic = false;\n if (nonStaticKinds.indexOf(kind) == -1) {\n isStatic = !!(node.flags & ts.NodeFlags.Static);\n if (container.kind == ReflectionKind.Class) {\n if (node.parent && node.parent.kind == ts.SyntaxKind.Constructor) {\n isConstructorProperty = true;\n } else if (!node.parent || node.parent.kind != ts.SyntaxKind.ClassDeclaration) {\n isStatic = true;\n }\n }\n }\n\n // Check if we already have a child with the same name and static flag\n var child:DeclarationReflection;\n var children = container.children = container.children || [];\n children.forEach((n:DeclarationReflection) => {\n if (n.name == name && n.flags.isStatic == isStatic) child = n;\n });\n\n if (!child) {\n // Child does not exist, create a new reflection\n child = new DeclarationReflection(container, name, kind);\n child.setFlag(ReflectionFlag.Static, isStatic);\n child.setFlag(ReflectionFlag.Private, isPrivate);\n child.setFlag(ReflectionFlag.ConstructorProperty, isConstructorProperty);\n child.setFlag(ReflectionFlag.Exported, isExported);\n child = setupDeclaration(context, child, node);\n\n if (child) {\n children.push(child);\n context.registerReflection(child, node);\n }\n } else {\n // Merge the existent reflection with the given node\n child = mergeDeclarations(context, child, node, kind);\n }\n\n // If we have a reflection, trigger the corresponding event\n if (child) {\n context.trigger(Converter.EVENT_CREATE_DECLARATION, child, node);\n }\n\n return child;\n}\n\n\n/**\n * Setup a newly created declaration reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The newly created blank reflection.\n * @param node The TypeScript node whose properties should be applies to the given reflection.\n * @returns The reflection populated with the values of the given node.\n */\nfunction setupDeclaration(context:Context, reflection:DeclarationReflection, node:ts.Node) {\n reflection.setFlag(ReflectionFlag.External, context.isExternal);\n reflection.setFlag(ReflectionFlag.Protected, !!(node.flags & ts.NodeFlags.Protected));\n reflection.setFlag(ReflectionFlag.Public, !!(node.flags & ts.NodeFlags.Public));\n reflection.setFlag(ReflectionFlag.Optional, !!(node['questionToken']));\n\n if (\n context.isInherit &&\n (node.parent == context.inheritParent || reflection.flags.isConstructorProperty)\n ) {\n if (!reflection.inheritedFrom) {\n reflection.inheritedFrom = createReferenceType(context, node.symbol, true);\n reflection.getAllSignatures().forEach((signature) => {\n signature.inheritedFrom = createReferenceType(context, node.symbol, true);\n });\n }\n }\n\n return reflection;\n}\n\n\n/**\n * Merge the properties of the given TypeScript node with the pre existent reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The pre existent reflection.\n * @param node The TypeScript node whose properties should be merged with the given reflection.\n * @param kind The desired kind of the reflection.\n * @returns The reflection merged with the values of the given node or NULL if the merge is invalid.\n */\nfunction mergeDeclarations(context:Context, reflection:DeclarationReflection, node:ts.Node, kind:ReflectionKind) {\n if (reflection.kind != kind) {\n var weights = [ReflectionKind.Module, ReflectionKind.Enum, ReflectionKind.Class];\n var kindWeight = weights.indexOf(kind);\n var childKindWeight = weights.indexOf(reflection.kind);\n if (kindWeight > childKindWeight) {\n reflection.kind = kind;\n }\n }\n\n if (\n context.isInherit &&\n context.inherited.indexOf(reflection.name) != -1 &&\n (node.parent == context.inheritParent || reflection.flags.isConstructorProperty)\n ) {\n if (!reflection.overwrites) {\n reflection.overwrites = createReferenceType(context, node.symbol, true);\n reflection.getAllSignatures().forEach((signature) => {\n signature.overwrites = createReferenceType(context, node.symbol, true);\n });\n }\n return null;\n }\n\n return reflection;\n}\n"]} \ No newline at end of file diff --git a/lib/converter/factories/index.d.ts b/lib/converter/factories/index.d.ts new file mode 100644 index 000000000..8f5d9fe2c --- /dev/null +++ b/lib/converter/factories/index.d.ts @@ -0,0 +1,6 @@ +export { createComment } from './comment'; +export { createDeclaration } from './declaration'; +export { createParameter } from './parameter'; +export { createReferenceType } from './reference'; +export { createSignature } from './signature'; +export { createTypeParameter } from './type-parameter'; diff --git a/lib/converter/factories/index.js b/lib/converter/factories/index.js new file mode 100644 index 000000000..805d81883 --- /dev/null +++ b/lib/converter/factories/index.js @@ -0,0 +1,14 @@ +"use strict"; +var comment_1 = require('./comment'); +exports.createComment = comment_1.createComment; +var declaration_1 = require('./declaration'); +exports.createDeclaration = declaration_1.createDeclaration; +var parameter_1 = require('./parameter'); +exports.createParameter = parameter_1.createParameter; +var reference_1 = require('./reference'); +exports.createReferenceType = reference_1.createReferenceType; +var signature_1 = require('./signature'); +exports.createSignature = signature_1.createSignature; +var type_parameter_1 = require('./type-parameter'); +exports.createTypeParameter = type_parameter_1.createTypeParameter; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/converter/factories/index.js.map b/lib/converter/factories/index.js.map new file mode 100644 index 000000000..dce32ccc1 --- /dev/null +++ b/lib/converter/factories/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/converter/factories/index.ts"],"names":[],"mappings":";AAAA,wBAA4B,WAAW,CAAC;AAAhC,gDAAgC;AACxC,4BAAgC,eAAe,CAAC;AAAxC,4DAAwC;AAChD,0BAA8B,aAAa,CAAC;AAApC,sDAAoC;AAC5C,0BAAkC,aAAa,CAAC;AAAxC,8DAAwC;AAChD,0BAA8B,aAAa,CAAC;AAApC,sDAAoC;AAC5C,+BAAkC,kBAAkB,CAAC;AAA7C,mEAA6C","sourcesContent":["export {createComment} from './comment';\nexport {createDeclaration} from './declaration';\nexport {createParameter} from './parameter';\nexport {createReferenceType} from './reference';\nexport {createSignature} from './signature';\nexport {createTypeParameter} from './type-parameter';\n"]} \ No newline at end of file diff --git a/lib/converter/factories/parameter.d.ts b/lib/converter/factories/parameter.d.ts new file mode 100644 index 000000000..de68aebf5 --- /dev/null +++ b/lib/converter/factories/parameter.d.ts @@ -0,0 +1,4 @@ +import * as ts from "typescript"; +import { ParameterReflection } from "../../models/reflections/index"; +import { Context } from "../context"; +export declare function createParameter(context: Context, node: ts.ParameterDeclaration): ParameterReflection; diff --git a/lib/converter/factories/parameter.js b/lib/converter/factories/parameter.js new file mode 100644 index 000000000..469952f30 --- /dev/null +++ b/lib/converter/factories/parameter.js @@ -0,0 +1,33 @@ +"use strict"; +var ts = require("typescript"); +var index_1 = require("../../models/reflections/index"); +var converter_1 = require("../converter"); +var convert_expression_1 = require("../convert-expression"); +function createParameter(context, node) { + var signature = context.scope; + if (!(signature instanceof index_1.SignatureReflection)) { + throw new Error('Expected signature reflection.'); + } + var parameter = new index_1.ParameterReflection(signature, node.symbol.name, index_1.ReflectionKind.Parameter); + context.registerReflection(parameter, node); + context.withScope(parameter, function () { + if (ts.isBindingPattern(node.name)) { + parameter.type = context.converter.convertType(context, node.name); + parameter.name = '__namedParameters'; + } + else { + parameter.type = context.converter.convertType(context, node.type, context.getTypeAtLocation(node)); + } + parameter.defaultValue = convert_expression_1.convertDefaultValue(node); + parameter.setFlag(index_1.ReflectionFlag.Optional, !!node.questionToken); + parameter.setFlag(index_1.ReflectionFlag.Rest, !!node.dotDotDotToken); + parameter.setFlag(index_1.ReflectionFlag.DefaultValue, !!parameter.defaultValue); + if (!signature.parameters) + signature.parameters = []; + signature.parameters.push(parameter); + }); + context.trigger(converter_1.Converter.EVENT_CREATE_PARAMETER, parameter, node); + return parameter; +} +exports.createParameter = createParameter; +//# sourceMappingURL=parameter.js.map \ No newline at end of file diff --git a/lib/converter/factories/parameter.js.map b/lib/converter/factories/parameter.js.map new file mode 100644 index 000000000..5ffe58f5b --- /dev/null +++ b/lib/converter/factories/parameter.js.map @@ -0,0 +1 @@ +{"version":3,"file":"parameter.js","sourceRoot":"","sources":["../../../src/lib/converter/factories/parameter.ts"],"names":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CAAC,OAAO,CAAC,sBAAc,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC9D,SAAS,CAAC,OAAO,CAAC,sBAAc,CAAC,YAAY,EAAE,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QAEzE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC;YAAC,SAAS,CAAC,UAAU,GAAG,EAAE,CAAC;QACrD,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,OAAO,CAAC,qBAAS,CAAC,sBAAsB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACnE,MAAM,CAAC,SAAS,CAAC;AACrB,CAAC;AA3Be,uBAAe,kBA2B9B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {ReflectionFlag, ReflectionKind, ParameterReflection, SignatureReflection} from \"../../models/reflections/index\";\nimport {Context} from \"../context\";\nimport {Converter} from \"../converter\";\nimport {convertDefaultValue} from \"../convert-expression\";\n\n\n/**\n * Create a parameter reflection for the given node.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The parameter node that should be reflected.\n * @returns The newly created parameter reflection.\n */\nexport function createParameter(context:Context, node:ts.ParameterDeclaration):ParameterReflection {\n var signature = context.scope;\n if (!(signature instanceof SignatureReflection)) {\n throw new Error('Expected signature reflection.');\n }\n\n var parameter = new ParameterReflection(signature, node.symbol.name, ReflectionKind.Parameter);\n context.registerReflection(parameter, node);\n context.withScope(parameter, () => {\n if (ts.isBindingPattern(node.name)) {\n parameter.type = context.converter.convertType(context, node.name);\n parameter.name = '__namedParameters'\n } else {\n parameter.type = context.converter.convertType(context, node.type, context.getTypeAtLocation(node));\n }\n\n parameter.defaultValue = convertDefaultValue(node);\n parameter.setFlag(ReflectionFlag.Optional, !!node.questionToken);\n parameter.setFlag(ReflectionFlag.Rest, !!node.dotDotDotToken);\n parameter.setFlag(ReflectionFlag.DefaultValue, !!parameter.defaultValue);\n\n if (!signature.parameters) signature.parameters = [];\n signature.parameters.push(parameter);\n });\n\n context.trigger(Converter.EVENT_CREATE_PARAMETER, parameter, node);\n return parameter;\n}\n"]} \ No newline at end of file diff --git a/lib/converter/factories/reference.d.ts b/lib/converter/factories/reference.d.ts new file mode 100644 index 000000000..b0e16f1d5 --- /dev/null +++ b/lib/converter/factories/reference.d.ts @@ -0,0 +1,4 @@ +import * as ts from "typescript"; +import { ReferenceType } from "../../models/types/index"; +import { Context } from "../context"; +export declare function createReferenceType(context: Context, symbol: ts.Symbol, includeParent?: boolean): ReferenceType; diff --git a/lib/converter/factories/reference.js b/lib/converter/factories/reference.js new file mode 100644 index 000000000..8906b75be --- /dev/null +++ b/lib/converter/factories/reference.js @@ -0,0 +1,13 @@ +"use strict"; +var index_1 = require("../../models/types/index"); +function createReferenceType(context, symbol, includeParent) { + var checker = context.checker; + var id = context.getSymbolID(symbol); + var name = checker.symbolToString(symbol); + if (includeParent && symbol.parent) { + name = checker.symbolToString(symbol.parent) + '.' + name; + } + return new index_1.ReferenceType(name, id); +} +exports.createReferenceType = createReferenceType; +//# sourceMappingURL=reference.js.map \ No newline at end of file diff --git a/lib/converter/factories/reference.js.map b/lib/converter/factories/reference.js.map new file mode 100644 index 000000000..24c3345d9 --- /dev/null +++ b/lib/converter/factories/reference.js.map @@ -0,0 +1 @@ +{"version":3,"file":"reference.js","sourceRoot":"","sources":["../../../src/lib/converter/factories/reference.ts"],"names":[],"mappings":";AAEA,sBAA4B,0BAA0B,CAAC,CAAA;AAYvD,6BAAoC,OAAe,EAAE,MAAgB,EAAE,aAAsB;IACzF,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAC9B,IAAI,EAAE,GAAQ,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1C,IAAI,IAAI,GAAM,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAE7C,EAAE,CAAC,CAAC,aAAa,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACjC,IAAI,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;IAC9D,CAAC;IAED,MAAM,CAAC,IAAI,qBAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACvC,CAAC;AAVe,2BAAmB,sBAUlC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {ReferenceType} from \"../../models/types/index\";\nimport {Context} from \"../context\";\n\n\n/**\n * Create a new reference type pointing to the given symbol.\n *\n * @param context The context object describing the current state the converter is in.\n * @param symbol The symbol the reference type should point to.\n * @param includeParent Should the name of the parent be provided within the fallback name?\n * @returns A new reference type instance pointing to the given symbol.\n */\nexport function createReferenceType(context:Context, symbol:ts.Symbol, includeParent?:boolean):ReferenceType {\n var checker = context.checker;\n var id = context.getSymbolID(symbol);\n var name = checker.symbolToString(symbol);\n\n if (includeParent && symbol.parent) {\n name = checker.symbolToString(symbol.parent) + '.' + name;\n }\n\n return new ReferenceType(name, id);\n}\n"]} \ No newline at end of file diff --git a/lib/converter/factories/signature.d.ts b/lib/converter/factories/signature.d.ts new file mode 100644 index 000000000..dd341a1ff --- /dev/null +++ b/lib/converter/factories/signature.d.ts @@ -0,0 +1,4 @@ +import * as ts from "typescript"; +import { ReflectionKind, SignatureReflection } from "../../models/index"; +import { Context } from "../context"; +export declare function createSignature(context: Context, node: ts.SignatureDeclaration, name: string, kind: ReflectionKind): SignatureReflection; diff --git a/lib/converter/factories/signature.js b/lib/converter/factories/signature.js new file mode 100644 index 000000000..6fc679e33 --- /dev/null +++ b/lib/converter/factories/signature.js @@ -0,0 +1,43 @@ +"use strict"; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var converter_1 = require("../converter"); +var parameter_1 = require("./parameter"); +var reference_1 = require("./reference"); +function createSignature(context, node, name, kind) { + var container = context.scope; + if (!(container instanceof index_1.ContainerReflection)) { + throw new Error('Expected container reflection.'); + } + var signature = new index_1.SignatureReflection(container, name, kind); + context.registerReflection(signature, node); + context.withScope(signature, node.typeParameters, true, function () { + node.parameters.forEach(function (parameter) { + parameter_1.createParameter(context, parameter); + }); + signature.type = extractSignatureType(context, node); + if (container.inheritedFrom) { + signature.inheritedFrom = reference_1.createReferenceType(context, node.symbol, true); + } + }); + context.trigger(converter_1.Converter.EVENT_CREATE_SIGNATURE, signature, node); + return signature; +} +exports.createSignature = createSignature; +function extractSignatureType(context, node) { + var checker = context.checker; + if (node.kind & 151 || node.kind & 174) { + try { + var signature = checker.getSignatureFromDeclaration(node); + return context.converter.convertType(context, node.type, checker.getReturnTypeOfSignature(signature)); + } + catch (error) { } + } + if (node.type) { + return context.converter.convertType(context, node.type); + } + else { + return context.converter.convertType(context, node); + } +} +//# sourceMappingURL=signature.js.map \ No newline at end of file diff --git a/lib/converter/factories/signature.js.map b/lib/converter/factories/signature.js.map new file mode 100644 index 000000000..e3f28f75b --- /dev/null +++ b/lib/converter/factories/signature.js.map @@ -0,0 +1 @@ +{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../../src/lib/converter/factories/signature.ts"],"names":[],"mappings":";AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAoG,oBAAoB,CAAC,CAAA;AAEzH,0BAAwB,cAAc,CAAC,CAAA;AACvC,0BAA8B,aAAa,CAAC,CAAA;AAC5C,0BAAkC,aAAa,CAAC,CAAA;AAYhD,yBAAgC,OAAe,EAAE,IAA4B,EAAE,IAAW,EAAE,IAAmB;IAC3G,IAAI,SAAS,GAA0B,OAAO,CAAC,KAAK,CAAC;IACrD,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,2BAAmB,CAAC,CAAC,CAAC,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,SAAS,GAAG,IAAI,2BAAmB,CAAC,SAAS,EAAE,IAA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AC;IAED,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACZ,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;IAAC,IAAI,CAAC,CAAC;QACJ,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;AACL,CAAC","sourcesContent":["import * as ts from \"typescript\";\n\nimport {ReflectionKind, SignatureReflection, ContainerReflection, DeclarationReflection, Type} from \"../../models/index\";\nimport {Context} from \"../context\";\nimport {Converter} from \"../converter\";\nimport {createParameter} from \"./parameter\";\nimport {createReferenceType} from \"./reference\";\n\n\n/**\n * Create a new signature reflection from the given node.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The TypeScript node containing the signature declaration that should be reflected.\n * @param name The name of the function or method this signature belongs to.\n * @param kind The desired kind of the reflection.\n * @returns The newly created signature reflection describing the given node.\n */\nexport function createSignature(context:Context, node:ts.SignatureDeclaration, name:string, kind:ReflectionKind):SignatureReflection {\n var container = context.scope;\n if (!(container instanceof ContainerReflection)) {\n throw new Error('Expected container reflection.');\n }\n\n var signature = new SignatureReflection(container, name, kind);\n context.registerReflection(signature, node);\n context.withScope(signature, node.typeParameters, true, () => {\n node.parameters.forEach((parameter:ts.ParameterDeclaration) => {\n createParameter(context, parameter);\n });\n\n signature.type = extractSignatureType(context, node);\n\n if (container.inheritedFrom) {\n signature.inheritedFrom = createReferenceType(context, node.symbol, true);\n }\n });\n\n context.trigger(Converter.EVENT_CREATE_SIGNATURE, signature, node);\n return signature;\n}\n\n\n\n\n/**\n * Extract the return type of the given signature declaration.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The signature declaration whose return type should be determined.\n * @returns The return type reflection of the given signature.\n */\nfunction extractSignatureType(context:Context, node:ts.SignatureDeclaration):Type {\n var checker = context.checker;\n if (node.kind & ts.SyntaxKind.CallSignature || node.kind & ts.SyntaxKind.CallExpression) {\n try {\n var signature = checker.getSignatureFromDeclaration(node);\n return context.converter.convertType(context, node.type, checker.getReturnTypeOfSignature(signature));\n } catch (error) {}\n }\n\n if (node.type) {\n return context.converter.convertType(context, node.type);\n } else {\n return context.converter.convertType(context, node);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/factories/type-parameter.d.ts b/lib/converter/factories/type-parameter.d.ts new file mode 100644 index 000000000..3c34cc9d4 --- /dev/null +++ b/lib/converter/factories/type-parameter.d.ts @@ -0,0 +1,4 @@ +import * as ts from "typescript"; +import { TypeParameterType } from "../../models/index"; +import { Context } from "../context"; +export declare function createTypeParameter(context: Context, node: ts.TypeParameterDeclaration): TypeParameterType; diff --git a/lib/converter/factories/type-parameter.js b/lib/converter/factories/type-parameter.js new file mode 100644 index 000000000..844ac7d8f --- /dev/null +++ b/lib/converter/factories/type-parameter.js @@ -0,0 +1,20 @@ +"use strict"; +var index_1 = require("../../models/index"); +var converter_1 = require("../converter"); +function createTypeParameter(context, node) { + var typeParameter = new index_1.TypeParameterType(); + typeParameter.name = node.symbol.name; + if (node.constraint) { + typeParameter.constraint = context.converter.convertType(context, node.constraint); + } + var reflection = context.scope; + var typeParameterReflection = new index_1.TypeParameterReflection(reflection, typeParameter); + if (!reflection.typeParameters) + reflection.typeParameters = []; + reflection.typeParameters.push(typeParameterReflection); + context.registerReflection(typeParameterReflection, node); + context.trigger(converter_1.Converter.EVENT_CREATE_TYPE_PARAMETER, typeParameterReflection, node); + return typeParameter; +} +exports.createTypeParameter = createTypeParameter; +//# sourceMappingURL=type-parameter.js.map \ No newline at end of file diff --git a/lib/converter/factories/type-parameter.js.map b/lib/converter/factories/type-parameter.js.map new file mode 100644 index 000000000..3100e9ee5 --- /dev/null +++ b/lib/converter/factories/type-parameter.js.map @@ -0,0 +1 @@ +{"version":3,"file":"type-parameter.js","sourceRoot":"","sources":["../../../src/lib/converter/factories/type-parameter.ts"],"names":[],"mappings":";AAEA,sBAAkF,oBAAoB,CAAC,CAAA;AAEvG,0BAAwB,cAAc,CAAC,CAAA;AAUvC,6BAAoC,OAAe,EAAE,IAAgC;IACjF,IAAI,aAAa,GAAG,IAAI,yBAAiB,EAAE,CAAC;IAC5C,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IACtC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QAClB,aAAa,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACvF,CAAC;IAED,IAAI,UAAU,GAA4B,OAAO,CAAC,KAAK,CAAC;IACxD,IAAI,uBAAuB,GAAG,IAAI,+BAAuB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAErF,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC;QAAC,UAAU,CAAC,cAAc,GAAG,EAAE,CAAC;IAC/D,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAExD,OAAO,CAAC,kBAAkB,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;IAC1D,OAAO,CAAC,OAAO,CAAC,qBAAS,CAAC,2BAA2B,EAAE,uBAAuB,EAAE,IAAI,CAAC,CAAC;IAEtF,MAAM,CAAC,aAAa,CAAC;AACzB,CAAC;AAjBe,2BAAmB,sBAiBlC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {ITypeParameterContainer, TypeParameterReflection, TypeParameterType} from \"../../models/index\";\nimport {Context} from \"../context\";\nimport {Converter} from \"../converter\";\n\n\n/**\n * Create a type parameter reflection for the given node.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The type parameter node that should be reflected.\n * @returns The newly created type parameter reflection.\n */\nexport function createTypeParameter(context:Context, node:ts.TypeParameterDeclaration):TypeParameterType {\n var typeParameter = new TypeParameterType();\n typeParameter.name = node.symbol.name;\n if (node.constraint) {\n typeParameter.constraint = context.converter.convertType(context, node.constraint);\n }\n\n var reflection = context.scope;\n var typeParameterReflection = new TypeParameterReflection(reflection, typeParameter);\n\n if (!reflection.typeParameters) reflection.typeParameters = [];\n reflection.typeParameters.push(typeParameterReflection);\n\n context.registerReflection(typeParameterReflection, node);\n context.trigger(Converter.EVENT_CREATE_TYPE_PARAMETER, typeParameterReflection, node);\n\n return typeParameter;\n}\n"]} \ No newline at end of file diff --git a/lib/converter/index.d.ts b/lib/converter/index.d.ts new file mode 100644 index 000000000..8aec3e8a8 --- /dev/null +++ b/lib/converter/index.d.ts @@ -0,0 +1,6 @@ +export { Context } from "./context"; +export { Converter } from "./converter"; +export { convertDefaultValue, convertExpression } from './convert-expression'; +import './nodes/index'; +import './types/index'; +import './plugins/index'; diff --git a/lib/converter/index.js b/lib/converter/index.js new file mode 100644 index 000000000..cc62d2dd1 --- /dev/null +++ b/lib/converter/index.js @@ -0,0 +1,12 @@ +"use strict"; +var context_1 = require("./context"); +exports.Context = context_1.Context; +var converter_1 = require("./converter"); +exports.Converter = converter_1.Converter; +var convert_expression_1 = require('./convert-expression'); +exports.convertDefaultValue = convert_expression_1.convertDefaultValue; +exports.convertExpression = convert_expression_1.convertExpression; +require('./nodes/index'); +require('./types/index'); +require('./plugins/index'); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/converter/index.js.map b/lib/converter/index.js.map new file mode 100644 index 000000000..7930e2d67 --- /dev/null +++ b/lib/converter/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/converter/index.ts"],"names":[],"mappings":";AAAA,wBAAsB,WAAW,CAAC;AAA1B,oCAA0B;AAClC,0BAAwB,aAAa,CAAC;AAA9B,0CAA8B;AAEtC,mCAAqD,sBAAsB,CAAC;AAApE,uEAAmB;AAAE,mEAA+C;AAE5E,QAAO,eAAe,CAAC,CAAA;AACvB,QAAO,eAAe,CAAC,CAAA;AACvB,QAAO,iBAAiB,CAAC,CAAA","sourcesContent":["export {Context} from \"./context\";\nexport {Converter} from \"./converter\";\n\nexport {convertDefaultValue, convertExpression} from './convert-expression';\n\nimport './nodes/index';\nimport './types/index';\nimport './plugins/index';\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/accessor.d.ts b/lib/converter/nodes/accessor.d.ts new file mode 100644 index 000000000..1b413f220 --- /dev/null +++ b/lib/converter/nodes/accessor.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class AccessorConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.SignatureDeclaration): Reflection; +} diff --git a/lib/converter/nodes/accessor.js b/lib/converter/nodes/accessor.js new file mode 100644 index 000000000..be98b7cb6 --- /dev/null +++ b/lib/converter/nodes/accessor.js @@ -0,0 +1,44 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var components_1 = require("../components"); +var AccessorConverter = (function (_super) { + __extends(AccessorConverter, _super); + function AccessorConverter() { + _super.apply(this, arguments); + this.supports = [ + 149, + 150 + ]; + } + AccessorConverter.prototype.convert = function (context, node) { + var accessor = index_2.createDeclaration(context, node, index_1.ReflectionKind.Accessor); + context.withScope(accessor, function () { + if (node.kind == 149) { + accessor.getSignature = index_2.createSignature(context, node, '__get', index_1.ReflectionKind.GetSignature); + } + else { + accessor.setSignature = index_2.createSignature(context, node, '__set', index_1.ReflectionKind.SetSignature); + } + }); + return accessor; + }; + AccessorConverter = __decorate([ + components_1.Component({ name: 'node:accessor' }) + ], AccessorConverter); + return AccessorConverter; +}(components_1.ConverterNodeComponent)); +exports.AccessorConverter = AccessorConverter; +//# sourceMappingURL=accessor.js.map \ No newline at end of file diff --git a/lib/converter/nodes/accessor.js.map b/lib/converter/nodes/accessor.js.map new file mode 100644 index 000000000..a27c1a88a --- /dev/null +++ b/lib/converter/nodes/accessor.js.map @@ -0,0 +1 @@ +{"version":3,"file":"accessor.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/accessor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAyC,oBAAoB,CAAC,CAAA;AAC9D,sBAAiD,oBAAoB,CAAC,CAAA;AAEtE,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAAuC,qCAA+C;IAAtF;QAAuC,8BAA+C;QAKlF,aAAQ,GAAmB;YACvB,GAAyB;YACzB,GAAyB;SAC5B,CAAC;IAuBN,CAAC;IAbG,mCAAO,GAAP,UAAQ,OAAe,EAAE,IAA4B;QACjD,IAAI,QAAQ,GAAG,yBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,sBAAc,CAAC,QAAQ,CAAC,CAAC;QAEzE,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE;YACxB,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,GAAyB,CAAC,CAAC,CAAC;gBACzC,QAAQ,CAAC,YAAY,GAAG,uBAAe,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,sBAAc,CAAC,YAAY,CAAC,CAAC;YACjG,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,QAAQ,CAAC,YAAY,GAAG,uBAAe,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,sBAAc,CAAC,YAAY,CAAC,CAAC;YACjG,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC;IACpB,CAAC;IA/BL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,eAAe,EAAC,CAAC;yBAAA;IAgClC,wBAAC;AAAD,CAAC,AA/BD,CAAuC,mCAAsB,GA+B5D;AA/BY,yBAAiB,oBA+B7B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind} from \"../../models/index\";\nimport {createDeclaration, createSignature} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:accessor'})\nexport class AccessorConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.GetAccessor,\n ts.SyntaxKind.SetAccessor\n ];\n\n\n /**\n * Analyze the given getter declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The signature declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.SignatureDeclaration):Reflection {\n var accessor = createDeclaration(context, node, ReflectionKind.Accessor);\n\n context.withScope(accessor, () => {\n if (node.kind == ts.SyntaxKind.GetAccessor) {\n accessor.getSignature = createSignature(context, node, '__get', ReflectionKind.GetSignature);\n } else {\n accessor.setSignature = createSignature(context, node, '__set', ReflectionKind.SetSignature);\n }\n });\n\n return accessor;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/alias.d.ts b/lib/converter/nodes/alias.d.ts new file mode 100644 index 000000000..15ff73abf --- /dev/null +++ b/lib/converter/nodes/alias.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class AliasConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.TypeAliasDeclaration): Reflection; +} diff --git a/lib/converter/nodes/alias.js b/lib/converter/nodes/alias.js new file mode 100644 index 000000000..2ee4553bf --- /dev/null +++ b/lib/converter/nodes/alias.js @@ -0,0 +1,39 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var components_1 = require("../components"); +var AliasConverter = (function (_super) { + __extends(AliasConverter, _super); + function AliasConverter() { + _super.apply(this, arguments); + this.supports = [ + 223 + ]; + } + AliasConverter.prototype.convert = function (context, node) { + var _this = this; + var alias = index_2.createDeclaration(context, node, index_1.ReflectionKind.TypeAlias); + context.withScope(alias, function () { + alias.type = _this.owner.convertType(context, node.type, context.getTypeAtLocation(node.type)); + }); + return alias; + }; + AliasConverter = __decorate([ + components_1.Component({ name: 'node:alias' }) + ], AliasConverter); + return AliasConverter; +}(components_1.ConverterNodeComponent)); +exports.AliasConverter = AliasConverter; +//# sourceMappingURL=alias.js.map \ No newline at end of file diff --git a/lib/converter/nodes/alias.js.map b/lib/converter/nodes/alias.js.map new file mode 100644 index 000000000..6d14b2c13 --- /dev/null +++ b/lib/converter/nodes/alias.js.map @@ -0,0 +1 @@ +{"version":3,"file":"alias.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/alias.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAyC,oBAAoB,CAAC,CAAA;AAC9D,sBAAgC,oBAAoB,CAAC,CAAA;AAErD,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAAoC,kCAA+C;IAAnF;QAAoC,8BAA+C;QAK/E,aAAQ,GAAmB;YACvB,GAAkC;SACrC,CAAC;IAmBN,CAAC;IATG,gCAAO,GAAP,UAAQ,OAAe,EAAE,IAA4B;QAArD,iBAQC;QAPG,IAAI,KAAK,GAAG,yBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,sBAAc,CAAC,SAAS,CAAC,CAAC;QAEvE,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE;YACrB,KAAK,CAAC,IAAI,GAAG,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAClG,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IA1BL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,YAAY,EAAC,CAAC;sBAAA;IA2B/B,qBAAC;AAAD,CAAC,AA1BD,CAAoC,mCAAsB,GA0BzD;AA1BY,sBAAc,iBA0B1B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind} from \"../../models/index\";\nimport {createDeclaration} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:alias'})\nexport class AliasConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.TypeAliasDeclaration\n ];\n\n\n /**\n * Analyze the given type alias declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The type alias declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.TypeAliasDeclaration):Reflection {\n var alias = createDeclaration(context, node, ReflectionKind.TypeAlias);\n\n context.withScope(alias, () => {\n alias.type = this.owner.convertType(context, node.type, context.getTypeAtLocation(node.type));\n });\n\n return alias;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/block.d.ts b/lib/converter/nodes/block.d.ts new file mode 100644 index 000000000..fa99fe3ae --- /dev/null +++ b/lib/converter/nodes/block.d.ts @@ -0,0 +1,15 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare enum SourceFileMode { + File = 0, + Modules = 1, +} +export declare class BlockConverter extends ConverterNodeComponent { + mode: number; + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.SourceFile | ts.Block | ts.ModuleBlock): Reflection; + private convertSourceFile(context, node); + private convertStatements(context, node); +} diff --git a/lib/converter/nodes/block.js b/lib/converter/nodes/block.js new file mode 100644 index 000000000..d633dc607 --- /dev/null +++ b/lib/converter/nodes/block.js @@ -0,0 +1,100 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var components_1 = require("../components"); +var component_1 = require("../../utils/component"); +var declaration_1 = require("../../utils/options/declaration"); +var prefered = [ + 221, + 222, + 224 +]; +(function (SourceFileMode) { + SourceFileMode[SourceFileMode["File"] = 0] = "File"; + SourceFileMode[SourceFileMode["Modules"] = 1] = "Modules"; +})(exports.SourceFileMode || (exports.SourceFileMode = {})); +var SourceFileMode = exports.SourceFileMode; +var BlockConverter = (function (_super) { + __extends(BlockConverter, _super); + function BlockConverter() { + _super.apply(this, arguments); + this.supports = [ + 199, + 226, + 256 + ]; + } + BlockConverter.prototype.convert = function (context, node) { + if (node.kind == 256) { + this.convertSourceFile(context, node); + } + else { + this.convertStatements(context, node); + } + return context.scope; + }; + BlockConverter.prototype.convertSourceFile = function (context, node) { + var _this = this; + var result = context.scope; + context.withSourceFile(node, function () { + if (_this.mode == SourceFileMode.Modules) { + result = index_2.createDeclaration(context, node, index_1.ReflectionKind.ExternalModule, node.fileName); + context.withScope(result, function () { + _this.convertStatements(context, node); + result.setFlag(index_1.ReflectionFlag.Exported); + }); + } + else { + _this.convertStatements(context, node); + } + }); + return result; + }; + BlockConverter.prototype.convertStatements = function (context, node) { + var _this = this; + if (node.statements) { + var statements = []; + node.statements.forEach(function (statement) { + if (prefered.indexOf(statement.kind) != -1) { + _this.owner.convertNode(context, statement); + } + else { + statements.push(statement); + } + }); + statements.forEach(function (statement) { + _this.owner.convertNode(context, statement); + }); + } + }; + __decorate([ + component_1.Option({ + name: "mode", + help: "Specifies the output mode the project is used to be compiled with: 'file' or 'modules'", + type: declaration_1.ParameterType.Map, + map: { + 'file': SourceFileMode.File, + 'modules': SourceFileMode.Modules + }, + defaultValue: SourceFileMode.Modules + }) + ], BlockConverter.prototype, "mode", void 0); + BlockConverter = __decorate([ + components_1.Component({ name: 'node:block' }) + ], BlockConverter); + return BlockConverter; +}(components_1.ConverterNodeComponent)); +exports.BlockConverter = BlockConverter; +//# sourceMappingURL=block.js.map \ No newline at end of file diff --git a/lib/converter/nodes/block.js.map b/lib/converter/nodes/block.js.map new file mode 100644 index 000000000..e110d486e --- /dev/null +++ b/lib/converter/nodes/block.js.map @@ -0,0 +1 @@ +{"version":3,"file":"block.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/block.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAyD,oBAAoB,CAAC,CAAA;AAC9E,sBAAgC,oBAAoB,CAAC,CAAA;AAErD,2BAAgD,eAAe,CAAC,CAAA;AAChE,0BAAqB,uBAAuB,CAAC,CAAA;AAC7C,4BAA4B,iCAAiC,CAAC,CAAA;AAG9D,IAAI,QAAQ,GAAmB;IAC3B,GAA8B;IAC9B,GAAkC;IAClC,GAA6B;CAChC,CAAC;AAGF,WAAY,cAAc;IACtB,mDAAI,CAAA;IAAE,yDAAO,CAAA;AACjB,CAAC,EAFW,sBAAc,KAAd,sBAAc,QAEzB;AAFD,IAAY,cAAc,GAAd,sBAEX,CAAA;AAID;IAAoC,kCAA6D;IAAjG;QAAoC,8BAA6D;QAiB7F,aAAQ,GAAmB;YACvB,GAAmB;YACnB,GAAyB;YACzB,GAAwB;SAC3B,CAAC;IAgEN,CAAC;IAtDG,gCAAO,GAAP,UAAQ,OAAe,EAAE,IAA0C;QAC/D,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,GAAwB,CAAC,CAAC,CAAC;YACxC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAiB,IAAI,CAAC,CAAC;QACzD,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC1C,CAAC;QAED,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;IACzB,CAAC;IAUO,0CAAiB,GAAzB,UAA0B,OAAe,EAAE,IAAkB;QAA7D,iBAgBC;QAfG,IAAI,MAAM,GAAG,OAAO,CAA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AAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAlFD;QAAC,kBAAM,CAAC;YACJ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,wFAAwF;YAC9F,IAAI,EAAE,2BAAa,CAAC,GAAG;YACvB,GAAG,EAAE;gBACD,MAAM,EAAE,cAAc,CAAC,IAAI;gBAC3B,SAAS,EAAE,cAAc,CAAC,OAAO;aACpC;YACD,YAAY,EAAE,cAAc,CAAC,OAAO;SACvC,CAAC;gDAAA;IAZN;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,YAAY,EAAC,CAAC;sBAAA;IAsF/B,qBAAC;AAAD,CAAC,AArFD,CAAoC,mCAAsB,GAqFzD;AArFY,sBAAc,iBAqF1B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind, ReflectionFlag} from \"../../models/index\";\nimport {createDeclaration} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\nimport {Option} from \"../../utils/component\";\nimport {ParameterType} from \"../../utils/options/declaration\";\n\n\nvar prefered:ts.SyntaxKind[] = [\n ts.SyntaxKind.ClassDeclaration,\n ts.SyntaxKind.InterfaceDeclaration,\n ts.SyntaxKind.EnumDeclaration\n];\n\n\nexport enum SourceFileMode {\n File, Modules\n}\n\n\n@Component({name:'node:block'})\nexport class BlockConverter extends ConverterNodeComponent\n{\n @Option({\n name: \"mode\",\n help: \"Specifies the output mode the project is used to be compiled with: 'file' or 'modules'\",\n type: ParameterType.Map,\n map: {\n 'file': SourceFileMode.File,\n 'modules': SourceFileMode.Modules\n },\n defaultValue: SourceFileMode.Modules\n })\n mode:number;\n\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.Block,\n ts.SyntaxKind.ModuleBlock,\n ts.SyntaxKind.SourceFile\n ];\n\n\n /**\n * Analyze the given class declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The class declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.SourceFile|ts.Block|ts.ModuleBlock):Reflection {\n if (node.kind == ts.SyntaxKind.SourceFile) {\n this.convertSourceFile(context, node);\n } else {\n this.convertStatements(context, node);\n }\n\n return context.scope;\n }\n\n\n /**\n * Analyze the given source file node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The source file node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n private convertSourceFile(context:Context, node:ts.SourceFile):Reflection {\n var result = context.scope;\n\n context.withSourceFile(node, () => {\n if (this.mode == SourceFileMode.Modules) {\n result = createDeclaration(context, node, ReflectionKind.ExternalModule, node.fileName);\n context.withScope(result, () => {\n this.convertStatements(context, node);\n result.setFlag(ReflectionFlag.Exported);\n });\n } else {\n this.convertStatements(context, node);\n }\n });\n\n return result;\n }\n\n\n private convertStatements(context:Context, node:ts.SourceFile|ts.Block|ts.ModuleBlock) {\n if (node.statements) {\n var statements:ts.Statement[] = [];\n\n node.statements.forEach((statement) => {\n if (prefered.indexOf(statement.kind) != -1) {\n this.owner.convertNode(context, statement);\n } else {\n statements.push(statement);\n }\n });\n\n statements.forEach((statement) => {\n this.owner.convertNode(context, statement);\n });\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/class.d.ts b/lib/converter/nodes/class.d.ts new file mode 100644 index 000000000..ecd55f847 --- /dev/null +++ b/lib/converter/nodes/class.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class ClassConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.ClassDeclaration): Reflection; +} diff --git a/lib/converter/nodes/class.js b/lib/converter/nodes/class.js new file mode 100644 index 000000000..c26ec15bd --- /dev/null +++ b/lib/converter/nodes/class.js @@ -0,0 +1,77 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var components_1 = require("../components"); +var ClassConverter = (function (_super) { + __extends(ClassConverter, _super); + function ClassConverter() { + _super.apply(this, arguments); + this.supports = [ + 192, + 221 + ]; + } + ClassConverter.prototype.convert = function (context, node) { + var _this = this; + var reflection; + if (context.isInherit && context.inheritParent == node) { + reflection = context.scope; + } + else { + reflection = index_2.createDeclaration(context, node, index_1.ReflectionKind.Class); + } + context.withScope(reflection, node.typeParameters, function () { + if (node.members) { + node.members.forEach(function (member) { + var privateMember = (member.flags & 8) > 0; + var exclude = context.converter.excludePrivate ? privateMember : false; + if (!exclude) { + _this.owner.convertNode(context, member); + } + }); + } + var baseType = ts.getClassExtendsHeritageClauseElement(node); + if (baseType) { + var type = context.getTypeAtLocation(baseType); + if (!context.isInherit) { + if (!reflection.extendedTypes) + reflection.extendedTypes = []; + reflection.extendedTypes.push(_this.owner.convertType(context, baseType, type)); + } + if (type && type.symbol) { + type.symbol.declarations.forEach(function (declaration) { + context.inherit(declaration, baseType.typeArguments); + }); + } + } + var implementedTypes = ts.getClassImplementsHeritageClauseElements(node); + if (implementedTypes) { + implementedTypes.forEach(function (implementedType) { + if (!reflection.implementedTypes) { + reflection.implementedTypes = []; + } + reflection.implementedTypes.push(_this.owner.convertType(context, implementedType)); + }); + } + }); + return reflection; + }; + ClassConverter = __decorate([ + components_1.Component({ name: 'node:class' }) + ], ClassConverter); + return ClassConverter; +}(components_1.ConverterNodeComponent)); +exports.ClassConverter = ClassConverter; +//# sourceMappingURL=class.js.map \ No newline at end of file diff --git a/lib/converter/nodes/class.js.map b/lib/converter/nodes/class.js.map new file mode 100644 index 000000000..787912ff2 --- /dev/null +++ b/lib/converter/nodes/class.js.map @@ -0,0 +1 @@ +{"version":3,"file":"class.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/class.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAgE,oBAAoB,CAAC,CAAA;AACrF,sBAAgC,oBAAoB,CAAC,CAAA;AAErD,2BAAgD,eAAe,CAAC,CAAA;AAGhE;IAAoC,kCAA2C;IAA/E;QAAoC,8BAA2C;QAK3E,aAAQ,GAAmB;YACvB,GAA6B;YAC7B,GAA8B;SACjC,CAAC;IA2DN,CAAC;IAjDG,gCAAO,GAAP,UAAQ,OAAe,EAAE,IAAwB;QAAjD,iBAgDC;QA/CG,IAAI,UAAgC,CAAC;QACrC,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC;YACrD,UAAU,GAA0B,OAAO,CAAC,KAAK,CAAC;QACtD,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,UAAU,GAAG,yBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,sBAAc,CAAC,KAAK,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,EAAE;YAC/C,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;gBACf,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;oBACxB,IA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AAgB,CAAC,OAAO,CAAC,UAAC,eAAe;oBACrC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC;wBAC/B,UAAU,CAAC,gBAAgB,GAAG,EAAE,CAAC;oBACrC,CAAC;oBAED,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;gBACvF,CAAC,CAAC,CAAC;YACP,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC;IACtB,CAAC;IAnEL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,YAAY,EAAC,CAAC;sBAAA;IAoE/B,qBAAC;AAAD,CAAC,AAnED,CAAoC,mCAAsB,GAmEzD;AAnEY,sBAAc,iBAmE1B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind, DeclarationReflection} from \"../../models/index\";\nimport {createDeclaration} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n@Component({name:'node:class'})\nexport class ClassConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.ClassExpression,\n ts.SyntaxKind.ClassDeclaration\n ];\n\n\n /**\n * Analyze the given class declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The class declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.ClassDeclaration):Reflection {\n var reflection:DeclarationReflection;\n if (context.isInherit && context.inheritParent == node) {\n reflection = context.scope;\n } else {\n reflection = createDeclaration(context, node, ReflectionKind.Class);\n }\n\n context.withScope(reflection, node.typeParameters, () => {\n if (node.members) {\n node.members.forEach((member) => {\n const privateMember = (member.flags & ts.NodeFlags.Private) > 0;\n const exclude = context.converter.excludePrivate ? privateMember : false;\n \n if (!exclude) {\n this.owner.convertNode(context, member);\n }\n });\n }\n\n var baseType = ts.getClassExtendsHeritageClauseElement(node);\n if (baseType) {\n var type = context.getTypeAtLocation(baseType);\n if (!context.isInherit) {\n if (!reflection.extendedTypes) reflection.extendedTypes = [];\n reflection.extendedTypes.push(this.owner.convertType(context, baseType, type));\n }\n\n if (type && type.symbol) {\n type.symbol.declarations.forEach((declaration) => {\n context.inherit(declaration, baseType.typeArguments);\n });\n }\n }\n\n var implementedTypes = ts.getClassImplementsHeritageClauseElements(node);\n if (implementedTypes) {\n implementedTypes.forEach((implementedType) => {\n if (!reflection.implementedTypes) {\n reflection.implementedTypes = [];\n }\n\n reflection.implementedTypes.push(this.owner.convertType(context, implementedType));\n });\n }\n });\n\n return reflection;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/constructor.d.ts b/lib/converter/nodes/constructor.d.ts new file mode 100644 index 000000000..6cf893fbf --- /dev/null +++ b/lib/converter/nodes/constructor.d.ts @@ -0,0 +1,9 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class ConstructorConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.ConstructorDeclaration): Reflection; + private addParameterProperty(context, parameter, comment); +} diff --git a/lib/converter/nodes/constructor.js b/lib/converter/nodes/constructor.js new file mode 100644 index 000000000..e9b7fdf05 --- /dev/null +++ b/lib/converter/nodes/constructor.js @@ -0,0 +1,77 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var converter_1 = require("../converter"); +var components_1 = require("../components"); +var ConstructorConverter = (function (_super) { + __extends(ConstructorConverter, _super); + function ConstructorConverter() { + _super.apply(this, arguments); + this.supports = [ + 148, + 152 + ]; + } + ConstructorConverter.prototype.convert = function (context, node) { + var parent = context.scope; + var hasBody = !!node.body; + var method = index_2.createDeclaration(context, node, index_1.ReflectionKind.Constructor, 'constructor'); + if (node.parameters && node.parameters.length) { + var comment = method ? method.comment : index_2.createComment(node); + for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) { + var parameter = _a[_i]; + this.addParameterProperty(context, parameter, comment); + } + } + context.withScope(method, function () { + if (!hasBody || !method.signatures) { + var name = 'new ' + parent.name; + var signature = index_2.createSignature(context, node, name, index_1.ReflectionKind.ConstructorSignature); + signature.type = new index_1.ReferenceType(parent.name, index_1.ReferenceType.SYMBOL_ID_RESOLVED, parent); + method.signatures = method.signatures || []; + method.signatures.push(signature); + } + else { + context.trigger(converter_1.Converter.EVENT_FUNCTION_IMPLEMENTATION, method, node); + } + }); + return method; + }; + ConstructorConverter.prototype.addParameterProperty = function (context, parameter, comment) { + var visibility = parameter.flags & (4 | 16 | 8); + if (!visibility) + return; + var privateParameter = parameter.flags & 8; + if (privateParameter && context.converter.excludePrivate) + return; + var property = index_2.createDeclaration(context, parameter, index_1.ReflectionKind.Property); + if (!property) + return; + property.setFlag(index_1.ReflectionFlag.Static, false); + property.type = this.owner.convertType(context, parameter.type, context.getTypeAtLocation(parameter)); + if (comment) { + var tag = comment.getTag('param', property.name); + if (tag && tag.text) { + property.comment = new index_1.Comment(tag.text); + } + } + }; + ConstructorConverter = __decorate([ + components_1.Component({ name: 'node:constructor' }) + ], ConstructorConverter); + return ConstructorConverter; +}(components_1.ConverterNodeComponent)); +exports.ConstructorConverter = ConstructorConverter; +//# sourceMappingURL=constructor.js.map \ No newline at end of file diff --git a/lib/converter/nodes/constructor.js.map b/lib/converter/nodes/constructor.js.map new file mode 100644 index 000000000..65bb556b0 --- /dev/null +++ b/lib/converter/nodes/constructor.js.map @@ -0,0 +1 @@ +{"version":3,"file":"constructor.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/constructor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAwG,oBAAoB,CAAC,CAAA;AAC7H,sBAAgE,oBAAoB,CAAC,CAAA;AAErF,0BAAwB,cAAc,CAAC,CAAA;AACvC,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAA0C,wCAAiD;IAA3F;QAA0C,8BAAiD;QAKvF,aAAQ,GAAmB;YACvB,GAAyB;YACzB,GAAgC;SACnC,CAAC;IAiEN,CAAC;IAvDG,sCAAO,GAAP,UAAQ,OAAe,EAAE,IAA8B;QACnD,IAAI,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1B,IAAI,MAAM,GAAG,yBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,sBAAc,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QAEzF,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;YAC5C,IAAI,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,OAAO,GAAG,qBAAa,CAAC,IAAI,CAAC,CAAC;YAC5D,GAAG,CAAC,CAAkB,UAAe,EAAf,KAAA,IAAI,CAAC,UAAU,EAAf,cAAe,EAAf,IAAe,CAAC;gBAAjC,IAAI,SAAS,SAAA;gBACd,IAAI,CAAC,oBAAoB,CAA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OAAO,EAAE,SAAS,EAAE,sBAAc,CAAC,QAAQ,CAAC,CAAC;QAC9E,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;YAAC,MAAM,CAAC;QAEtB,QAAQ,CAAC,OAAO,CAAC,sBAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC/C,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC;QAEtG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;YACV,IAAI,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;YACjD,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;gBAClB,QAAQ,CAAC,OAAO,GAAG,IAAI,eAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC7C,CAAC;QACL,CAAC;IACL,CAAC;IAzEL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,kBAAkB,EAAC,CAAC;4BAAA;IA0ErC,2BAAC;AAAD,CAAC,AAzED,CAA0C,mCAAsB,GAyE/D;AAzEY,4BAAoB,uBAyEhC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind, ReflectionFlag, DeclarationReflection, ReferenceType, Comment} from \"../../models/index\";\nimport {createDeclaration, createSignature, createComment} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Converter} from \"../converter\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:constructor'})\nexport class ConstructorConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.Constructor,\n ts.SyntaxKind.ConstructSignature\n ];\n\n\n /**\n * Analyze the given constructor declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The constructor declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.ConstructorDeclaration):Reflection {\n var parent = context.scope;\n var hasBody = !!node.body;\n var method = createDeclaration(context, node, ReflectionKind.Constructor, 'constructor');\n\n if (node.parameters && node.parameters.length) {\n var comment = method ? method.comment : createComment(node);\n for (var parameter of node.parameters) {\n this.addParameterProperty(context, parameter, comment);\n }\n }\n\n context.withScope(method, () => {\n if (!hasBody || !method.signatures) {\n var name = 'new ' + parent.name;\n var signature = createSignature(context, node, name, ReflectionKind.ConstructorSignature);\n signature.type = new ReferenceType(parent.name, ReferenceType.SYMBOL_ID_RESOLVED, parent);\n method.signatures = method.signatures || [];\n method.signatures.push(signature);\n } else {\n context.trigger(Converter.EVENT_FUNCTION_IMPLEMENTATION, method, node);\n }\n });\n\n return method;\n }\n\n\n /**\n * Analyze parameters in given constructor declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The constructor declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n private addParameterProperty(context:Context, parameter:ts.ParameterDeclaration, comment:Comment) {\n var visibility = parameter.flags & (ts.NodeFlags.Public | ts.NodeFlags.Protected | ts.NodeFlags.Private);\n if (!visibility) return;\n\n const privateParameter = parameter.flags & ts.NodeFlags.Private;\n if (privateParameter && context.converter.excludePrivate) return;\n\n var property = createDeclaration(context, parameter, ReflectionKind.Property);\n if (!property) return;\n\n property.setFlag(ReflectionFlag.Static, false);\n property.type = this.owner.convertType(context, parameter.type, context.getTypeAtLocation(parameter));\n\n if (comment) {\n var tag = comment.getTag('param', property.name);\n if (tag && tag.text) {\n property.comment = new Comment(tag.text);\n }\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/enum.d.ts b/lib/converter/nodes/enum.d.ts new file mode 100644 index 000000000..c8bdde5bd --- /dev/null +++ b/lib/converter/nodes/enum.d.ts @@ -0,0 +1,9 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class EnumConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.EnumDeclaration): Reflection; + private convertMember(context, node); +} diff --git a/lib/converter/nodes/enum.js b/lib/converter/nodes/enum.js new file mode 100644 index 000000000..bea457236 --- /dev/null +++ b/lib/converter/nodes/enum.js @@ -0,0 +1,52 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var components_1 = require("../components"); +var index_3 = require("../index"); +var EnumConverter = (function (_super) { + __extends(EnumConverter, _super); + function EnumConverter() { + _super.apply(this, arguments); + this.supports = [ + 224 + ]; + } + EnumConverter.prototype.convert = function (context, node) { + var _this = this; + var enumeration = index_2.createDeclaration(context, node, index_1.ReflectionKind.Enum); + context.withScope(enumeration, function () { + if (node.members) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + _this.convertMember(context, member); + } + } + }); + return enumeration; + }; + EnumConverter.prototype.convertMember = function (context, node) { + var member = index_2.createDeclaration(context, node, index_1.ReflectionKind.EnumMember); + if (member) { + member.defaultValue = index_3.convertDefaultValue(node); + } + return member; + }; + EnumConverter = __decorate([ + components_1.Component({ name: 'node:enum' }) + ], EnumConverter); + return EnumConverter; +}(components_1.ConverterNodeComponent)); +exports.EnumConverter = EnumConverter; +//# sourceMappingURL=enum.js.map \ No newline at end of file diff --git a/lib/converter/nodes/enum.js.map b/lib/converter/nodes/enum.js.map new file mode 100644 index 000000000..376139d3c --- /dev/null +++ b/lib/converter/nodes/enum.js.map @@ -0,0 +1 @@ +{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/enum.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAyC,oBAAoB,CAAC,CAAA;AAC9D,sBAAgC,oBAAoB,CAAC,CAAA;AAErD,2BAAgD,eAAe,CAAC,CAAA;AAChE,sBAAkC,UAAU,CAAC,CAAA;AAI7C;IAAmC,iCAA0C;IAA7E;QAAmC,8BAA0C;QAKzE,aAAQ,GAAmB;YACvB,GAA6B;SAChC,CAAC;IAwCN,CAAC;IA9BG,+BAAO,GAAP,UAAQ,OAAe,EAAE,IAAuB;QAAhD,iBAYC;QAXG,IAAI,WAAW,GAAG,yBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,sBAAc,CAAC,IAAI,CAAC,CAAC;QAExE,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE;YAC3B,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;gBACf,GAAG,CAAC,CAAe,UAAY,EAAZ,KAAA,IAAI,CAAC,OAAO,EAAZ,cAAY,EAAZ,IAAY,CAAC;oBAA3B,IAAI,MAAM,SAAA;oBACX,KAAI,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;iBACvC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,WAAW,CAAC;IACvB,CAAC;IAUO,qCAAa,GAArB,UAAsB,OAAe,EAAE,IAAkB;QACrD,IAAI,MAAM,GAAG,yBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,sBAAc,CAAC,UAAU,CAAC,CAAC;QACzE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACT,MAAM,CAAC,YAAY,GAAG,2BAAmB,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IA/CL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,WAAW,EAAC,CAAC;qBAAA;IAgD9B,oBAAC;AAAD,CAAC,AA/CD,CAAmC,mCAAsB,GA+CxD;AA/CY,qBAAa,gBA+CzB,CAAA","sourcesContent":["\nimport * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind} from \"../../models/index\";\nimport {createDeclaration} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\nimport {convertDefaultValue} from \"../index\";\n\n\n@Component({name:'node:enum'})\nexport class EnumConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.EnumDeclaration\n ];\n\n\n /**\n * Analyze the given enumeration declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The enumeration declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.EnumDeclaration):Reflection {\n var enumeration = createDeclaration(context, node, ReflectionKind.Enum);\n\n context.withScope(enumeration, () => {\n if (node.members) {\n for (var member of node.members) {\n this.convertMember(context, member);\n }\n }\n });\n\n return enumeration;\n }\n\n\n /**\n * Analyze the given enumeration member node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The enumeration member node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n private convertMember(context:Context, node:ts.EnumMember):Reflection {\n var member = createDeclaration(context, node, ReflectionKind.EnumMember);\n if (member) {\n member.defaultValue = convertDefaultValue(node);\n }\n\n return member;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/export.d.ts b/lib/converter/nodes/export.d.ts new file mode 100644 index 000000000..69376e9fc --- /dev/null +++ b/lib/converter/nodes/export.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class ExportConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.ExportAssignment): Reflection; +} diff --git a/lib/converter/nodes/export.js b/lib/converter/nodes/export.js new file mode 100644 index 000000000..d1aeb9fb1 --- /dev/null +++ b/lib/converter/nodes/export.js @@ -0,0 +1,62 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var components_1 = require("../components"); +var ExportConverter = (function (_super) { + __extends(ExportConverter, _super); + function ExportConverter() { + _super.apply(this, arguments); + this.supports = [ + 235 + ]; + } + ExportConverter.prototype.convert = function (context, node) { + var symbol = undefined; + if (node.symbol && (node.symbol.flags & 8388608) === 8388608) { + symbol = context.checker.getAliasedSymbol(node.symbol); + } + else { + var type = context.getTypeAtLocation(node.expression); + symbol = type ? type.symbol : undefined; + } + if (symbol) { + var project = context.project; + symbol.declarations.forEach(function (declaration) { + if (!declaration.symbol) + return; + var id = project.symbolMapping[context.getSymbolID(declaration.symbol)]; + if (!id) + return; + var reflection = project.reflections[id]; + if (node.isExportEquals && reflection instanceof index_1.DeclarationReflection) { + reflection.setFlag(index_1.ReflectionFlag.ExportAssignment, true); + } + markAsExported(reflection); + }); + } + function markAsExported(reflection) { + if (reflection instanceof index_1.DeclarationReflection) { + reflection.setFlag(index_1.ReflectionFlag.Exported, true); + } + reflection.traverse(markAsExported); + } + return context.scope; + }; + ExportConverter = __decorate([ + components_1.Component({ name: 'node:export' }) + ], ExportConverter); + return ExportConverter; +}(components_1.ConverterNodeComponent)); +exports.ExportConverter = ExportConverter; +//# sourceMappingURL=export.js.map \ No newline at end of file diff --git a/lib/converter/nodes/export.js.map b/lib/converter/nodes/export.js.map new file mode 100644 index 000000000..e4753c532 --- /dev/null +++ b/lib/converter/nodes/export.js.map @@ -0,0 +1 @@ +{"version":3,"file":"export.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/export.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAgF,oBAAoB,CAAC,CAAA;AAErG,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAAqC,mCAA2C;IAAhF;QAAqC,8BAA2C;QAK5E,aAAQ,GAAmB;YACvB,GAA8B;SACjC,CAAC;IAqCN,CAAC;IAnCG,iCAAO,GAAP,UAAQ,OAAe,EAAE,IAAwB;QAC7C,IAAI,MAAM,GAAc,SAAS,CAAC;QAGlC,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,OAAoB,CAAC,KAAK,OAAoB,CAAC,CAAC,CAAC;YACrF,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3D,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,IAAI,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACt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AA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind, ReflectionFlag, DeclarationReflection} from \"../../models/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:export'})\nexport class ExportConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.ExportAssignment\n ];\n\n convert(context:Context, node:ts.ExportAssignment):Reflection {\n let symbol: ts.Symbol = undefined;\n\n // default export\n if (node.symbol && (node.symbol.flags & ts.SymbolFlags.Alias) === ts.SymbolFlags.Alias) {\n symbol = context.checker.getAliasedSymbol(node.symbol);\n } else {\n let type = context.getTypeAtLocation(node.expression);\n symbol = type ? type.symbol : undefined;\n }\n if (symbol) {\n var project = context.project;\n symbol.declarations.forEach((declaration) => {\n if (!declaration.symbol) return;\n var id = project.symbolMapping[context.getSymbolID(declaration.symbol)];\n if (!id) return;\n\n var reflection = project.reflections[id];\n if (node.isExportEquals && reflection instanceof DeclarationReflection) {\n (reflection).setFlag(ReflectionFlag.ExportAssignment, true);\n }\n markAsExported(reflection);\n });\n }\n\n function markAsExported(reflection:Reflection) {\n if (reflection instanceof DeclarationReflection) {\n (reflection).setFlag(ReflectionFlag.Exported, true);\n }\n\n reflection.traverse(markAsExported);\n }\n\n return context.scope;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/function.d.ts b/lib/converter/nodes/function.d.ts new file mode 100644 index 000000000..e61e75890 --- /dev/null +++ b/lib/converter/nodes/function.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class FunctionConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.FunctionDeclaration | ts.MethodDeclaration): Reflection; +} diff --git a/lib/converter/nodes/function.js b/lib/converter/nodes/function.js new file mode 100644 index 000000000..415dd8271 --- /dev/null +++ b/lib/converter/nodes/function.js @@ -0,0 +1,52 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var converter_1 = require("../converter"); +var components_1 = require("../components"); +var FunctionConverter = (function (_super) { + __extends(FunctionConverter, _super); + function FunctionConverter() { + _super.apply(this, arguments); + this.supports = [ + 146, + 147, + 220 + ]; + } + FunctionConverter.prototype.convert = function (context, node) { + var scope = context.scope; + var kind = scope.kind & index_1.ReflectionKind.ClassOrInterface ? index_1.ReflectionKind.Method : index_1.ReflectionKind.Function; + var hasBody = !!node.body; + var method = index_2.createDeclaration(context, node, kind); + context.withScope(method, function () { + if (!hasBody || !method.signatures) { + var signature = index_2.createSignature(context, node, method.name, index_1.ReflectionKind.CallSignature); + if (!method.signatures) + method.signatures = []; + method.signatures.push(signature); + } + else { + context.trigger(converter_1.Converter.EVENT_FUNCTION_IMPLEMENTATION, method, node); + } + }); + return method; + }; + FunctionConverter = __decorate([ + components_1.Component({ name: 'node:function' }) + ], FunctionConverter); + return FunctionConverter; +}(components_1.ConverterNodeComponent)); +exports.FunctionConverter = FunctionConverter; +//# sourceMappingURL=function.js.map \ No newline at end of file diff --git a/lib/converter/nodes/function.js.map b/lib/converter/nodes/function.js.map new file mode 100644 index 000000000..84c6ac100 --- /dev/null +++ b/lib/converter/nodes/function.js.map @@ -0,0 +1 @@ +{"version":3,"file":"function.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/function.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAyC,oBAAoB,CAAC,CAAA;AAC9D,sBAAiD,oBAAoB,CAAC,CAAA;AAEtE,0BAAwB,cAAc,CAAC,CAAA;AACvC,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAAuC,qCAAmE;IAA1G;QAAuC,8BAAmE;QAKtG,aAAQ,GAAmB;YACvB,GAA6B;YAC7B,GAA+B;YAC/B,GAAiC;SACpC,CAAC;IA4BN,CAAC;IAlBG,mCAAO,GAAP,UAAQ,OAAe,EAAE,IAAgD;QACrE,IAAI,KAAK,GAAK,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,IAAI,GAAM,KAAK,CAAC,IAAI,GAAG,sBAAc,CAAC,gBAAgB,GAAG,sBAAc,CAAC,MAAM,GAAG,sBAAc,CAAC,QAAQ,CAAC;QAC7G,IAAI,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC1B,IAAI,MAAM,GAAI,yBAAiB,CAAC,OAAO,EAAW,IAAI,EAAE,IAAI,CAAC,CAAC;QAE9D,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE;YACtB,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;gBACjC,IAAI,SAAS,GAAG,uBAAe,CAAC,OAAO,EAA2B,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,sBAAc,CAAC,aAAa,CAAC,CAAC;gBACnH,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;oBAAC,MAAM,CAAC,UAAU,GAAG,EAAE,CAAC;gBAC/C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACtC,CAAC;YAAC,IAAI,CAAC,CAAC;gBACJ,OAAO,CAAC,OAAO,CAAC,qBAAS,CAAC,6BAA6B,EAAE,MAAM,EAAW,IAAI,CAAC,CAAC;YACpF,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IArCL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,eAAe,EAAC,CAAC;yBAAA;IAsClC,wBAAC;AAAD,CAAC,AArCD,CAAuC,mCAAsB,GAqC5D;AArCY,yBAAiB,oBAqC7B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind} from \"../../models/index\";\nimport {createDeclaration, createSignature} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Converter} from \"../converter\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:function'})\nexport class FunctionConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.MethodSignature,\n ts.SyntaxKind.MethodDeclaration,\n ts.SyntaxKind.FunctionDeclaration\n ];\n\n\n /**\n * Analyze the given function declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The function declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.FunctionDeclaration|ts.MethodDeclaration):Reflection {\n var scope = context.scope;\n var kind = scope.kind & ReflectionKind.ClassOrInterface ? ReflectionKind.Method : ReflectionKind.Function;\n var hasBody = !!node.body;\n var method = createDeclaration(context, node, kind);\n\n context.withScope(method, () => {\n if (!hasBody || !method.signatures) {\n var signature = createSignature(context, node, method.name, ReflectionKind.CallSignature);\n if (!method.signatures) method.signatures = [];\n method.signatures.push(signature);\n } else {\n context.trigger(Converter.EVENT_FUNCTION_IMPLEMENTATION, method, node);\n }\n });\n\n return method;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/index.d.ts b/lib/converter/nodes/index.d.ts new file mode 100644 index 000000000..c66f14382 --- /dev/null +++ b/lib/converter/nodes/index.d.ts @@ -0,0 +1,16 @@ +export { AccessorConverter } from "./accessor"; +export { AliasConverter } from "./alias"; +export { BlockConverter } from "./block"; +export { ClassConverter } from "./class"; +export { ConstructorConverter } from "./constructor"; +export { EnumConverter } from "./enum"; +export { ExportConverter } from "./export"; +export { FunctionConverter } from "./function"; +export { InterfaceConverter } from "./interface"; +export { TypeLiteralConverter } from "./literal-type"; +export { ObjectLiteralConverter } from "./literal-object"; +export { ModuleConverter } from "./module"; +export { SignatureConverter } from "./signature-call"; +export { IndexSignatureConverter } from "./signature-index"; +export { VariableStatementConverter } from "./variable-statement"; +export { VariableConverter } from "./variable"; diff --git a/lib/converter/nodes/index.js b/lib/converter/nodes/index.js new file mode 100644 index 000000000..3259ba09c --- /dev/null +++ b/lib/converter/nodes/index.js @@ -0,0 +1,34 @@ +"use strict"; +var accessor_1 = require("./accessor"); +exports.AccessorConverter = accessor_1.AccessorConverter; +var alias_1 = require("./alias"); +exports.AliasConverter = alias_1.AliasConverter; +var block_1 = require("./block"); +exports.BlockConverter = block_1.BlockConverter; +var class_1 = require("./class"); +exports.ClassConverter = class_1.ClassConverter; +var constructor_1 = require("./constructor"); +exports.ConstructorConverter = constructor_1.ConstructorConverter; +var enum_1 = require("./enum"); +exports.EnumConverter = enum_1.EnumConverter; +var export_1 = require("./export"); +exports.ExportConverter = export_1.ExportConverter; +var function_1 = require("./function"); +exports.FunctionConverter = function_1.FunctionConverter; +var interface_1 = require("./interface"); +exports.InterfaceConverter = interface_1.InterfaceConverter; +var literal_type_1 = require("./literal-type"); +exports.TypeLiteralConverter = literal_type_1.TypeLiteralConverter; +var literal_object_1 = require("./literal-object"); +exports.ObjectLiteralConverter = literal_object_1.ObjectLiteralConverter; +var module_1 = require("./module"); +exports.ModuleConverter = module_1.ModuleConverter; +var signature_call_1 = require("./signature-call"); +exports.SignatureConverter = signature_call_1.SignatureConverter; +var signature_index_1 = require("./signature-index"); +exports.IndexSignatureConverter = signature_index_1.IndexSignatureConverter; +var variable_statement_1 = require("./variable-statement"); +exports.VariableStatementConverter = variable_statement_1.VariableStatementConverter; +var variable_1 = require("./variable"); +exports.VariableConverter = variable_1.VariableConverter; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/converter/nodes/index.js.map b/lib/converter/nodes/index.js.map new file mode 100644 index 000000000..fdee239c7 --- /dev/null +++ b/lib/converter/nodes/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/index.ts"],"names":[],"mappings":";AAAA,yBAAgC,YAAY,CAAC;AAArC,yDAAqC;AAC7C,sBAA6B,SAAS,CAAC;AAA/B,gDAA+B;AACvC,sBAA6B,SAAS,CAAC;AAA/B,gDAA+B;AACvC,sBAA6B,SAAS,CAAC;AAA/B,gDAA+B;AACvC,4BAAmC,eAAe,CAAC;AAA3C,kEAA2C;AACnD,qBAA4B,QAAQ,CAAC;AAA7B,6CAA6B;AACrC,uBAA8B,UAAU,CAAC;AAAjC,mDAAiC;AACzC,yBAAgC,YAAY,CAAC;AAArC,yDAAqC;AAC7C,0BAAiC,aAAa,CAAC;AAAvC,4DAAuC;AAC/C,6BAAmC,gBAAgB,CAAC;AAA5C,mEAA4C;AACpD,+BAAqC,kBAAkB,CAAC;AAAhD,yEAAgD;AACxD,uBAA8B,UAAU,CAAC;AAAjC,mDAAiC;AACzC,+BAAiC,kBAAkB,CAAC;AAA5C,iEAA4C;AACpD,gCAAsC,mBAAmB,CAAC;AAAlD,4EAAkD;AAC1D,mCAAyC,sBAAsB,CAAC;AAAxD,qFAAwD;AAChE,yBAAgC,YAAY,CAAC;AAArC,yDAAqC","sourcesContent":["export {AccessorConverter} from \"./accessor\";\nexport {AliasConverter} from \"./alias\";\nexport {BlockConverter} from \"./block\";\nexport {ClassConverter} from \"./class\";\nexport {ConstructorConverter} from \"./constructor\";\nexport {EnumConverter} from \"./enum\";\nexport {ExportConverter} from \"./export\";\nexport {FunctionConverter} from \"./function\";\nexport {InterfaceConverter} from \"./interface\";\nexport {TypeLiteralConverter} from \"./literal-type\";\nexport {ObjectLiteralConverter} from \"./literal-object\";\nexport {ModuleConverter} from \"./module\";\nexport {SignatureConverter} from \"./signature-call\";\nexport {IndexSignatureConverter} from \"./signature-index\";\nexport {VariableStatementConverter} from \"./variable-statement\";\nexport {VariableConverter} from \"./variable\";\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/interface.d.ts b/lib/converter/nodes/interface.d.ts new file mode 100644 index 000000000..083a4d4a9 --- /dev/null +++ b/lib/converter/nodes/interface.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class InterfaceConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.InterfaceDeclaration): Reflection; +} diff --git a/lib/converter/nodes/interface.js b/lib/converter/nodes/interface.js new file mode 100644 index 000000000..c1f0ff16c --- /dev/null +++ b/lib/converter/nodes/interface.js @@ -0,0 +1,65 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var components_1 = require("../components"); +var InterfaceConverter = (function (_super) { + __extends(InterfaceConverter, _super); + function InterfaceConverter() { + _super.apply(this, arguments); + this.supports = [ + 222 + ]; + } + InterfaceConverter.prototype.convert = function (context, node) { + var _this = this; + var reflection; + if (context.isInherit && context.inheritParent == node) { + reflection = context.scope; + } + else { + reflection = index_2.createDeclaration(context, node, index_1.ReflectionKind.Interface); + } + context.withScope(reflection, node.typeParameters, function () { + if (node.members) { + node.members.forEach(function (member, isInherit) { + _this.owner.convertNode(context, member); + }); + } + var baseTypes = ts.getInterfaceBaseTypeNodes(node); + if (baseTypes) { + baseTypes.forEach(function (baseType) { + var type = context.getTypeAtLocation(baseType); + if (!context.isInherit) { + if (!reflection.extendedTypes) + reflection.extendedTypes = []; + reflection.extendedTypes.push(_this.owner.convertType(context, baseType, type)); + } + if (type && type.symbol) { + type.symbol.declarations.forEach(function (declaration) { + context.inherit(declaration, baseType.typeArguments); + }); + } + }); + } + }); + return reflection; + }; + InterfaceConverter = __decorate([ + components_1.Component({ name: 'node:interface' }) + ], InterfaceConverter); + return InterfaceConverter; +}(components_1.ConverterNodeComponent)); +exports.InterfaceConverter = InterfaceConverter; +//# sourceMappingURL=interface.js.map \ No newline at end of file diff --git a/lib/converter/nodes/interface.js.map b/lib/converter/nodes/interface.js.map new file mode 100644 index 000000000..21ac0f132 --- /dev/null +++ b/lib/converter/nodes/interface.js.map @@ -0,0 +1 @@ +{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/interface.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAgE,oBAAoB,CAAC,CAAA;AACrF,sBAAgC,oBAAoB,CAAC,CAAA;AAErD,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAAwC,sCAA+C;IAAvF;QAAwC,8BAA+C;QAKnF,aAAQ,GAAmB;YACvB,GAAkC;SACrC,CAAC;IA6CN,CAAC;IAnCG,oCAAO,GAAP,UAAQ,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AM,CAAC,CAAC,CAAC;wBACtB,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,UAAC,WAAW;4BACzC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;wBACzD,CAAC,CAAC,CAAC;oBACP,CAAC;gBACL,CAAC,CAAC,CAAC;YACP,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC;IACtB,CAAC;IApDL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,gBAAgB,EAAC,CAAC;0BAAA;IAqDnC,yBAAC;AAAD,CAAC,AApDD,CAAwC,mCAAsB,GAoD7D;AApDY,0BAAkB,qBAoD9B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind, DeclarationReflection} from \"../../models/index\";\nimport {createDeclaration} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:interface'})\nexport class InterfaceConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.InterfaceDeclaration\n ];\n\n\n /**\n * Analyze the given interface declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The interface declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.InterfaceDeclaration):Reflection {\n var reflection:DeclarationReflection;\n if (context.isInherit && context.inheritParent == node) {\n reflection = context.scope;\n } else {\n reflection = createDeclaration(context, node, ReflectionKind.Interface);\n }\n\n context.withScope(reflection, node.typeParameters, () => {\n if (node.members) {\n node.members.forEach((member, isInherit) => {\n this.owner.convertNode(context, member);\n });\n }\n\n var baseTypes = ts.getInterfaceBaseTypeNodes(node);\n if (baseTypes) {\n baseTypes.forEach((baseType) => {\n var type = context.getTypeAtLocation(baseType);\n if (!context.isInherit) {\n if (!reflection.extendedTypes) reflection.extendedTypes = [];\n reflection.extendedTypes.push(this.owner.convertType(context, baseType, type));\n }\n\n if (type && type.symbol) {\n type.symbol.declarations.forEach((declaration) => {\n context.inherit(declaration, baseType.typeArguments);\n });\n }\n });\n }\n });\n\n return reflection;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/literal-object.d.ts b/lib/converter/nodes/literal-object.d.ts new file mode 100644 index 000000000..7cee5c737 --- /dev/null +++ b/lib/converter/nodes/literal-object.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class ObjectLiteralConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.ObjectLiteralExpression): Reflection; +} diff --git a/lib/converter/nodes/literal-object.js b/lib/converter/nodes/literal-object.js new file mode 100644 index 000000000..0f4eb4276 --- /dev/null +++ b/lib/converter/nodes/literal-object.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var components_1 = require("../components"); +var ObjectLiteralConverter = (function (_super) { + __extends(ObjectLiteralConverter, _super); + function ObjectLiteralConverter() { + _super.apply(this, arguments); + this.supports = [ + 171 + ]; + } + ObjectLiteralConverter.prototype.convert = function (context, node) { + var _this = this; + if (node.properties) { + node.properties.forEach(function (node) { + _this.owner.convertNode(context, node); + }); + } + return context.scope; + }; + ObjectLiteralConverter = __decorate([ + components_1.Component({ name: 'node:literal-object' }) + ], ObjectLiteralConverter); + return ObjectLiteralConverter; +}(components_1.ConverterNodeComponent)); +exports.ObjectLiteralConverter = ObjectLiteralConverter; +//# sourceMappingURL=literal-object.js.map \ No newline at end of file diff --git a/lib/converter/nodes/literal-object.js.map b/lib/converter/nodes/literal-object.js.map new file mode 100644 index 000000000..025a80f60 --- /dev/null +++ b/lib/converter/nodes/literal-object.js.map @@ -0,0 +1 @@ +{"version":3,"file":"literal-object.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/literal-object.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAIjC,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAA4C,0CAAkD;IAA9F;QAA4C,8BAAkD;QAK1F,aAAQ,GAAmB;YACvB,GAAqC;SACxC,CAAC;IAmBN,CAAC;IATG,wCAAO,GAAP,UAAQ,OAAe,EAAE,IAA+B;QAAxD,iBAQC;QAPG,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YAClB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAC,IAAI;gBACzB,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACP,CAAC;QAED,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;IACzB,CAAC;IA1BL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,qBAAqB,EAAC,CAAC;8BAAA;IA2BxC,6BAAC;AAAD,CAAC,AA1BD,CAA4C,mCAAsB,GA0BjE;AA1BY,8BAAsB,yBA0BlC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind} from \"../../models/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:literal-object'})\nexport class ObjectLiteralConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.ObjectLiteralExpression\n ];\n\n\n /**\n * Analyze the given object literal node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The object literal node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.ObjectLiteralExpression):Reflection {\n if (node.properties) {\n node.properties.forEach((node) => {\n this.owner.convertNode(context, node);\n });\n }\n\n return context.scope;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/literal-type.d.ts b/lib/converter/nodes/literal-type.d.ts new file mode 100644 index 000000000..e8d6737e2 --- /dev/null +++ b/lib/converter/nodes/literal-type.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class TypeLiteralConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.TypeLiteralNode): Reflection; +} diff --git a/lib/converter/nodes/literal-type.js b/lib/converter/nodes/literal-type.js new file mode 100644 index 000000000..69ebc6331 --- /dev/null +++ b/lib/converter/nodes/literal-type.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var components_1 = require("../components"); +var TypeLiteralConverter = (function (_super) { + __extends(TypeLiteralConverter, _super); + function TypeLiteralConverter() { + _super.apply(this, arguments); + this.supports = [ + 159 + ]; + } + TypeLiteralConverter.prototype.convert = function (context, node) { + var _this = this; + if (node.members) { + node.members.forEach(function (node) { + _this.owner.convertNode(context, node); + }); + } + return context.scope; + }; + TypeLiteralConverter = __decorate([ + components_1.Component({ name: 'node:literal-type' }) + ], TypeLiteralConverter); + return TypeLiteralConverter; +}(components_1.ConverterNodeComponent)); +exports.TypeLiteralConverter = TypeLiteralConverter; +//# sourceMappingURL=literal-type.js.map \ No newline at end of file diff --git a/lib/converter/nodes/literal-type.js.map b/lib/converter/nodes/literal-type.js.map new file mode 100644 index 000000000..3ea28c8b7 --- /dev/null +++ b/lib/converter/nodes/literal-type.js.map @@ -0,0 +1 @@ +{"version":3,"file":"literal-type.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/literal-type.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAIjC,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAA0C,wCAA0C;IAApF;QAA0C,8BAA0C;QAKhF,aAAQ,GAAmB;YACvB,GAAyB;SAC5B,CAAC;IAmBN,CAAC;IATG,sCAAO,GAAP,UAAQ,OAAe,EAAE,IAAuB;QAAhD,iBAQC;QAPG,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YACf,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAC,IAAI;gBACtB,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACP,CAAC;QAED,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;IACzB,CAAC;IA1BL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,mBAAmB,EAAC,CAAC;4BAAA;IA2BtC,2BAAC;AAAD,CAAC,AA1BD,CAA0C,mCAAsB,GA0B/D;AA1BY,4BAAoB,uBA0BhC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind} from \"../../models/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:literal-type'})\nexport class TypeLiteralConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.TypeLiteral\n ];\n\n\n /**\n * Analyze the given type literal node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The type literal node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.TypeLiteralNode):Reflection {\n if (node.members) {\n node.members.forEach((node) => {\n this.owner.convertNode(context, node);\n });\n }\n\n return context.scope;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/module.d.ts b/lib/converter/nodes/module.d.ts new file mode 100644 index 000000000..d2353eeee --- /dev/null +++ b/lib/converter/nodes/module.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class ModuleConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.ModuleDeclaration): Reflection; +} diff --git a/lib/converter/nodes/module.js b/lib/converter/nodes/module.js new file mode 100644 index 000000000..96bebf5cd --- /dev/null +++ b/lib/converter/nodes/module.js @@ -0,0 +1,47 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var components_1 = require("../components"); +var ModuleConverter = (function (_super) { + __extends(ModuleConverter, _super); + function ModuleConverter() { + _super.apply(this, arguments); + this.supports = [ + 225 + ]; + } + ModuleConverter.prototype.convert = function (context, node) { + var _this = this; + var parent = context.scope; + var reflection = index_2.createDeclaration(context, node, index_1.ReflectionKind.Module); + context.withScope(reflection, function () { + var opt = context.getCompilerOptions(); + if (parent instanceof index_1.ProjectReflection && !context.isDeclaration && + (!module || module.valueOf() === ts.ModuleKind.None.valueOf())) { + reflection.setFlag(index_1.ReflectionFlag.Exported); + } + if (node.body) { + _this.owner.convertNode(context, node.body); + } + }); + return reflection; + }; + ModuleConverter = __decorate([ + components_1.Component({ name: 'node:module' }) + ], ModuleConverter); + return ModuleConverter; +}(components_1.ConverterNodeComponent)); +exports.ModuleConverter = ModuleConverter; +//# sourceMappingURL=module.js.map \ No newline at end of file diff --git a/lib/converter/nodes/module.js.map b/lib/converter/nodes/module.js.map new file mode 100644 index 000000000..d85612204 --- /dev/null +++ b/lib/converter/nodes/module.js.map @@ -0,0 +1 @@ +{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/module.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAA4E,oBAAoB,CAAC,CAAA;AACjG,sBAAgC,oBAAoB,CAAC,CAAA;AAErD,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAAqC,mCAA4C;IAAjF;QAAqC,8BAA4C;QAK7E,aAAQ,GAAmB;YACvB,GAA+B;SAClC,CAAC;IA4BN,CAAC;IAlBG,iCAAO,GAAP,UAAQ,OAAe,EAAE,IAAyB;QAAlD,iBAiBC;QAhBG,IAAI,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,UAAU,GAAG,yBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,sBAAc,CAAC,MAAM,CAAC,CAAC;QAEzE,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE;YAC1B,IAAI,GAAG,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;YACvC,EAAE,CAAC,CAAC,MAAM,YAAY,yBAAiB,IAAI,CAAC,OAAO,CAAC,aAAa;gBAC7D,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;gBACjE,UAAU,CAAC,OAAO,CAAC,sBAAc,CAAC,QAAQ,CAAC,CAAC;YAChD,CAAC;YAED,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBACZ,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC;IACtB,CAAC;IAnCL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,aAAa,EAAC,CAAC;uBAAA;IAoChC,sBAAC;AAAD,CAAC,AAnCD,CAAqC,mCAAsB,GAmC1D;AAnCY,uBAAe,kBAmC3B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind, ReflectionFlag, ProjectReflection} from \"../../models/index\";\nimport {createDeclaration} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:module'})\nexport class ModuleConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.ModuleDeclaration\n ];\n\n\n /**\n * Analyze the given module node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The module node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.ModuleDeclaration):Reflection {\n var parent = context.scope;\n var reflection = createDeclaration(context, node, ReflectionKind.Module);\n\n context.withScope(reflection, () => {\n var opt = context.getCompilerOptions();\n if (parent instanceof ProjectReflection && !context.isDeclaration &&\n (!module || module.valueOf() === ts.ModuleKind.None.valueOf())) {\n reflection.setFlag(ReflectionFlag.Exported);\n }\n\n if (node.body) {\n this.owner.convertNode(context, node.body);\n }\n });\n\n return reflection;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/signature-call.d.ts b/lib/converter/nodes/signature-call.d.ts new file mode 100644 index 000000000..29ca5d47b --- /dev/null +++ b/lib/converter/nodes/signature-call.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class SignatureConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.FunctionExpression | ts.SignatureDeclaration | ts.FunctionExpression): Reflection; +} diff --git a/lib/converter/nodes/signature-call.js b/lib/converter/nodes/signature-call.js new file mode 100644 index 000000000..ab9105d4a --- /dev/null +++ b/lib/converter/nodes/signature-call.js @@ -0,0 +1,45 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var components_1 = require("../components"); +var index_2 = require("../factories/index"); +var SignatureConverter = (function (_super) { + __extends(SignatureConverter, _super); + function SignatureConverter() { + _super.apply(this, arguments); + this.supports = [ + 151, + 156, + 179, + 180 + ]; + } + SignatureConverter.prototype.convert = function (context, node) { + var scope = context.scope; + if (scope instanceof index_1.DeclarationReflection) { + var name = scope.kindOf(index_1.ReflectionKind.FunctionOrMethod) ? scope.name : '__call'; + var signature = index_2.createSignature(context, node, name, index_1.ReflectionKind.CallSignature); + if (!scope.signatures) + scope.signatures = []; + scope.signatures.push(signature); + } + return scope; + }; + SignatureConverter = __decorate([ + components_1.Component({ name: 'node:signature-call' }) + ], SignatureConverter); + return SignatureConverter; +}(components_1.ConverterNodeComponent)); +exports.SignatureConverter = SignatureConverter; +//# sourceMappingURL=signature-call.js.map \ No newline at end of file diff --git a/lib/converter/nodes/signature-call.js.map b/lib/converter/nodes/signature-call.js.map new file mode 100644 index 000000000..9d6896793 --- /dev/null +++ b/lib/converter/nodes/signature-call.js.map @@ -0,0 +1 @@ +{"version":3,"file":"signature-call.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/signature-call.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAgE,oBAAoB,CAAC,CAAA;AAErF,2BAAgD,eAAe,CAAC,CAAA;AAChE,sBAA8B,oBAAoB,CAAC,CAAA;AAInD;IAAwC,sCAA2F;IAAnI;QAAwC,8BAA2F;QAK/H,aAAQ,GAAmB;YACvB,GAA2B;YAC3B,GAA0B;YAC1B,GAAgC;YAChC,GAA2B;SAC9B,CAAC;IAqBN,CAAC;IAXG,oCAAO,GAAP,UAAQ,OAAe,EAAE,IAAwE;QAC7F,IAAI,KAAK,GAA0B,OAAO,CAAC,KAAK,CAAC;QACjD,EAAE,CAAC,CAAC,KAAK,YAAY,6BAAqB,CAAC,CAAC,CAAC;YACzC,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,sBAAc,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG,QAAQ,CAAC;YACjF,IAAI,SAAS,GAAG,uBAAe,CAAC,OAAO,EAA2B,IAAI,EAAE,IAAI,EAAE,sBAAc,CAAC,aAAa,CAAC,CAAC;YAC5G,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC;gBAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CAAC;YAC7C,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IA/BL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,qBAAqB,EAAC,CAAC;0BAAA;IAgCxC,yBAAC;AAAD,CAAC,AA/BD,CAAwC,mCAAsB,GA+B7D;AA/BY,0BAAkB,qBA+B9B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind, DeclarationReflection} from \"../../models/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\nimport {createSignature} from \"../factories/index\";\n\n\n@Component({name:'node:signature-call'})\nexport class SignatureConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.CallSignature,\n ts.SyntaxKind.FunctionType,\n ts.SyntaxKind.FunctionExpression,\n ts.SyntaxKind.ArrowFunction\n ];\n\n\n /**\n * Analyze the given call signature declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The signature declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.FunctionExpression|ts.SignatureDeclaration|ts.FunctionExpression):Reflection {\n var scope = context.scope;\n if (scope instanceof DeclarationReflection) {\n var name = scope.kindOf(ReflectionKind.FunctionOrMethod) ? scope.name : '__call';\n var signature = createSignature(context, node, name, ReflectionKind.CallSignature);\n if (!scope.signatures) scope.signatures = [];\n scope.signatures.push(signature);\n }\n\n return scope;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/signature-index.d.ts b/lib/converter/nodes/signature-index.d.ts new file mode 100644 index 000000000..fd8dc3451 --- /dev/null +++ b/lib/converter/nodes/signature-index.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class IndexSignatureConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.SignatureDeclaration): Reflection; +} diff --git a/lib/converter/nodes/signature-index.js b/lib/converter/nodes/signature-index.js new file mode 100644 index 000000000..3bcaa6fad --- /dev/null +++ b/lib/converter/nodes/signature-index.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var components_1 = require("../components"); +var IndexSignatureConverter = (function (_super) { + __extends(IndexSignatureConverter, _super); + function IndexSignatureConverter() { + _super.apply(this, arguments); + this.supports = [ + 153 + ]; + } + IndexSignatureConverter.prototype.convert = function (context, node) { + var scope = context.scope; + if (scope instanceof index_1.DeclarationReflection) { + scope.indexSignature = index_2.createSignature(context, node, '__index', index_1.ReflectionKind.IndexSignature); + } + return scope; + }; + IndexSignatureConverter = __decorate([ + components_1.Component({ name: 'node:signature-index' }) + ], IndexSignatureConverter); + return IndexSignatureConverter; +}(components_1.ConverterNodeComponent)); +exports.IndexSignatureConverter = IndexSignatureConverter; +//# sourceMappingURL=signature-index.js.map \ No newline at end of file diff --git a/lib/converter/nodes/signature-index.js.map b/lib/converter/nodes/signature-index.js.map new file mode 100644 index 000000000..d41069242 --- /dev/null +++ b/lib/converter/nodes/signature-index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"signature-index.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/signature-index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAgE,oBAAoB,CAAC,CAAA;AACrF,sBAA8B,oBAAoB,CAAC,CAAA;AAEnD,2BAAgD,eAAe,CAAC,CAAA;AAIhE;IAA6C,2CAA+C;IAA5F;QAA6C,8BAA+C;QAKxF,aAAQ,GAAmB;YACvB,GAA4B;SAC/B,CAAC;IAkBN,CAAC;IARG,yCAAO,GAAP,UAAQ,OAAe,EAAE,IAA4B;QACjD,IAAI,KAAK,GAA0B,OAAO,CAAC,KAAK,CAAC;QACjD,EAAE,CAAC,CAAC,KAAK,YAAY,6BAAqB,CAAC,CAAC,CAAC;YACzC,KAAK,CAAC,cAAc,GAAG,uBAAe,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,sBAAc,CAAC,cAAc,CAAC,CAAC;QACpG,CAAC;QAED,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IAzBL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,sBAAsB,EAAC,CAAC;+BAAA;IA0BzC,8BAAC;AAAD,CAAC,AAzBD,CAA6C,mCAAsB,GAyBlE;AAzBY,+BAAuB,0BAyBnC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind, DeclarationReflection} from \"../../models/index\";\nimport {createSignature} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:signature-index'})\nexport class IndexSignatureConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.IndexSignature\n ];\n\n\n /**\n * Analyze the given index signature declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The signature declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.SignatureDeclaration):Reflection {\n var scope = context.scope;\n if (scope instanceof DeclarationReflection) {\n scope.indexSignature = createSignature(context, node, '__index', ReflectionKind.IndexSignature);\n }\n\n return scope;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/variable-statement.d.ts b/lib/converter/nodes/variable-statement.d.ts new file mode 100644 index 000000000..2168d604a --- /dev/null +++ b/lib/converter/nodes/variable-statement.d.ts @@ -0,0 +1,9 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class VariableStatementConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + convert(context: Context, node: ts.VariableStatement): Reflection; + convertBindingPattern(context: Context, node: ts.BindingPattern): void; +} diff --git a/lib/converter/nodes/variable-statement.js b/lib/converter/nodes/variable-statement.js new file mode 100644 index 000000000..fe6f7adde --- /dev/null +++ b/lib/converter/nodes/variable-statement.js @@ -0,0 +1,52 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var components_1 = require("../components"); +var VariableStatementConverter = (function (_super) { + __extends(VariableStatementConverter, _super); + function VariableStatementConverter() { + _super.apply(this, arguments); + this.supports = [ + 200 + ]; + } + VariableStatementConverter.prototype.convert = function (context, node) { + var _this = this; + if (node.declarationList && node.declarationList.declarations) { + node.declarationList.declarations.forEach(function (variableDeclaration) { + if (ts.isBindingPattern(variableDeclaration.name)) { + _this.convertBindingPattern(context, variableDeclaration.name); + } + else { + _this.owner.convertNode(context, variableDeclaration); + } + }); + } + return context.scope; + }; + VariableStatementConverter.prototype.convertBindingPattern = function (context, node) { + var _this = this; + node.elements.forEach(function (element) { + _this.owner.convertNode(context, element); + if (ts.isBindingPattern(element.name)) { + _this.convertBindingPattern(context, element.name); + } + }); + }; + VariableStatementConverter = __decorate([ + components_1.Component({ name: 'node:variable-statement' }) + ], VariableStatementConverter); + return VariableStatementConverter; +}(components_1.ConverterNodeComponent)); +exports.VariableStatementConverter = VariableStatementConverter; +//# sourceMappingURL=variable-statement.js.map \ No newline at end of file diff --git a/lib/converter/nodes/variable-statement.js.map b/lib/converter/nodes/variable-statement.js.map new file mode 100644 index 000000000..1792b19d8 --- /dev/null +++ b/lib/converter/nodes/variable-statement.js.map @@ -0,0 +1 @@ +{"version":3,"file":"variable-statement.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/variable-statement.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY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I,EAAC,yBAAyB,EAAC,CAAC;kCAAA;IAgD5C,iCAAC;AAAD,CAAC,AA/CD,CAAgD,mCAAsB,GA+CrE;AA/CY,kCAA0B,6BA+CtC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind} from \"../../models/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\n\n\n@Component({name:'node:variable-statement'})\nexport class VariableStatementConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.VariableStatement\n ];\n\n\n /**\n * Analyze the given variable statement node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The variable statement node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.VariableStatement):Reflection {\n if (node.declarationList && node.declarationList.declarations) {\n node.declarationList.declarations.forEach((variableDeclaration) => {\n if (ts.isBindingPattern(variableDeclaration.name)) {\n this.convertBindingPattern(context, variableDeclaration.name);\n } else {\n this.owner.convertNode(context, variableDeclaration);\n }\n });\n }\n\n return context.scope;\n }\n\n\n /**\n * Traverse the elements of the given binding pattern and create the corresponding variable reflections.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The binding pattern node that should be analyzed.\n */\n convertBindingPattern(context:Context, node:ts.BindingPattern) {\n node.elements.forEach((element:ts.BindingElement) => {\n this.owner.convertNode(context, element);\n\n if (ts.isBindingPattern(element.name)) {\n this.convertBindingPattern(context, element.name);\n }\n });\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/nodes/variable.d.ts b/lib/converter/nodes/variable.d.ts new file mode 100644 index 000000000..761dd524d --- /dev/null +++ b/lib/converter/nodes/variable.d.ts @@ -0,0 +1,9 @@ +import * as ts from "typescript"; +import { Reflection } from "../../models/index"; +import { Context } from "../context"; +import { ConverterNodeComponent } from "../components"; +export declare class VariableConverter extends ConverterNodeComponent { + supports: ts.SyntaxKind[]; + isSimpleObjectLiteral(objectLiteral: ts.ObjectLiteralExpression): boolean; + convert(context: Context, node: ts.VariableDeclaration): Reflection; +} diff --git a/lib/converter/nodes/variable.js b/lib/converter/nodes/variable.js new file mode 100644 index 000000000..5476f76da --- /dev/null +++ b/lib/converter/nodes/variable.js @@ -0,0 +1,98 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var index_2 = require("../factories/index"); +var components_1 = require("../components"); +var index_3 = require("../index"); +var VariableConverter = (function (_super) { + __extends(VariableConverter, _super); + function VariableConverter() { + _super.apply(this, arguments); + this.supports = [ + 144, + 145, + 253, + 254, + 218, + 169 + ]; + } + VariableConverter.prototype.isSimpleObjectLiteral = function (objectLiteral) { + if (!objectLiteral.properties) + return true; + return objectLiteral.properties.length == 0; + }; + VariableConverter.prototype.convert = function (context, node) { + var _this = this; + var comment = index_2.createComment(node); + if (comment && comment.hasTag("resolve")) { + var resolveType = context.getTypeAtLocation(node); + if (resolveType && resolveType.symbol) { + var resolved = this.owner.convertNode(context, resolveType.symbol.declarations[0]); + if (resolved) { + resolved.name = node.symbol.name; + } + return resolved; + } + } + var name, isBindingPattern; + if (ts.isBindingPattern(node.name)) { + if (node['propertyName']) { + name = ts.declarationNameToString(node['propertyName']); + isBindingPattern = true; + } + else { + return null; + } + } + var scope = context.scope; + var kind = scope.kind & index_1.ReflectionKind.ClassOrInterface ? index_1.ReflectionKind.Property : index_1.ReflectionKind.Variable; + var variable = index_2.createDeclaration(context, node, kind, name); + context.withScope(variable, function () { + if (node.initializer) { + switch (node.initializer.kind) { + case 180: + case 179: + variable.kind = scope.kind & index_1.ReflectionKind.ClassOrInterface ? index_1.ReflectionKind.Method : index_1.ReflectionKind.Function; + _this.owner.convertNode(context, node.initializer); + break; + case 171: + if (!_this.isSimpleObjectLiteral(node.initializer)) { + variable.kind = index_1.ReflectionKind.ObjectLiteral; + variable.type = new index_1.IntrinsicType('object'); + _this.owner.convertNode(context, node.initializer); + } + break; + default: + variable.defaultValue = index_3.convertDefaultValue(node); + } + } + if (variable.kind == kind || variable.kind == index_1.ReflectionKind.Event) { + if (isBindingPattern) { + variable.type = _this.owner.convertType(context, node.name); + } + else { + variable.type = _this.owner.convertType(context, node.type, context.getTypeAtLocation(node)); + } + } + }); + return variable; + }; + VariableConverter = __decorate([ + components_1.Component({ name: 'node:variable' }) + ], VariableConverter); + return VariableConverter; +}(components_1.ConverterNodeComponent)); +exports.VariableConverter = VariableConverter; +//# sourceMappingURL=variable.js.map \ No newline at end of file diff --git a/lib/converter/nodes/variable.js.map b/lib/converter/nodes/variable.js.map new file mode 100644 index 000000000..9d1af0ba5 --- /dev/null +++ b/lib/converter/nodes/variable.js.map @@ -0,0 +1 @@ +{"version":3,"file":"variable.js","sourceRoot":"","sources":["../../../src/lib/converter/nodes/variable.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAwD,oBAAoB,CAAC,CAAA;AAC7E,sBAA+C,oBAAoB,CAAC,CAAA;AAEpE,2BAAgD,eAAe,CAAC,CAAA;AAChE,sBAAkC,UAAU,CAAC,CAAA;AAI7C;IAAuC,qCAA8C;IAArF;QAAuC,8BAA8C;QAKjF,aAAQ,GAAmB;YACvB,GAA+B;YAC/B,GAAiC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BACV;wBACI,QAAQ,CAAC,YAAY,GAAG,2BAAmB,CAAC,IAAI,CAAC,CAAC;gBAC1D,CAAC;YACL,CAAC;YAED,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,sBAAc,CAAC,KAAK,CAAC,CAAC,CAAC;gBACjE,EAAE,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;oBACnB,QAAQ,CAAC,IAAI,GAAG,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC/D,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACJ,QAAQ,CAAC,IAAI,GAAG,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;gBAChG,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC;IACpB,CAAC;IArFL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,eAAe,EAAC,CAAC;yBAAA;IAsFlC,wBAAC;AAAD,CAAC,AArFD,CAAuC,mCAAsB,GAqF5D;AArFY,yBAAiB,oBAqF7B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Reflection, ReflectionKind, IntrinsicType} from \"../../models/index\";\nimport {createDeclaration, createComment} from \"../factories/index\";\nimport {Context} from \"../context\";\nimport {Component, ConverterNodeComponent} from \"../components\";\nimport {convertDefaultValue} from \"../index\";\n\n\n@Component({name:'node:variable'})\nexport class VariableConverter extends ConverterNodeComponent\n{\n /**\n * List of supported TypeScript syntax kinds.\n */\n supports:ts.SyntaxKind[] = [\n ts.SyntaxKind.PropertySignature,\n ts.SyntaxKind.PropertyDeclaration,\n ts.SyntaxKind.PropertyAssignment,\n ts.SyntaxKind.ShorthandPropertyAssignment,\n ts.SyntaxKind.VariableDeclaration,\n ts.SyntaxKind.BindingElement\n ];\n\n\n isSimpleObjectLiteral(objectLiteral:ts.ObjectLiteralExpression):boolean {\n if (!objectLiteral.properties) return true;\n return objectLiteral.properties.length == 0;\n }\n\n\n /**\n * Analyze the given variable declaration node and create a suitable reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The variable declaration node that should be analyzed.\n * @return The resulting reflection or NULL.\n */\n convert(context:Context, node:ts.VariableDeclaration):Reflection {\n var comment = createComment(node);\n if (comment && comment.hasTag(\"resolve\")) {\n var resolveType = context.getTypeAtLocation(node);\n if (resolveType && resolveType.symbol) {\n var resolved = this.owner.convertNode(context, resolveType.symbol.declarations[0]);\n if (resolved) {\n resolved.name = node.symbol.name;\n }\n return resolved;\n }\n }\n\n var name:string, isBindingPattern:boolean;\n if (ts.isBindingPattern(node.name)) {\n if (node['propertyName']) {\n name = ts.declarationNameToString(node['propertyName']);\n isBindingPattern = true;\n } else {\n return null;\n }\n }\n\n var scope = context.scope;\n var kind = scope.kind & ReflectionKind.ClassOrInterface ? ReflectionKind.Property : ReflectionKind.Variable;\n var variable = createDeclaration(context, node, kind, name);\n context.withScope(variable, () => {\n if (node.initializer) {\n switch (node.initializer.kind) {\n case ts.SyntaxKind.ArrowFunction:\n case ts.SyntaxKind.FunctionExpression:\n variable.kind = scope.kind & ReflectionKind.ClassOrInterface ? ReflectionKind.Method : ReflectionKind.Function;\n this.owner.convertNode(context, node.initializer);\n break;\n case ts.SyntaxKind.ObjectLiteralExpression:\n if (!this.isSimpleObjectLiteral(node.initializer)) {\n variable.kind = ReflectionKind.ObjectLiteral;\n variable.type = new IntrinsicType('object');\n this.owner.convertNode(context, node.initializer);\n }\n break;\n default:\n variable.defaultValue = convertDefaultValue(node);\n }\n }\n\n if (variable.kind == kind || variable.kind == ReflectionKind.Event) {\n if (isBindingPattern) {\n variable.type = this.owner.convertType(context, node.name);\n } else {\n variable.type = this.owner.convertType(context, node.type, context.getTypeAtLocation(node));\n }\n }\n });\n\n return variable;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/CommentPlugin.d.ts b/lib/converter/plugins/CommentPlugin.d.ts new file mode 100644 index 000000000..55a516c60 --- /dev/null +++ b/lib/converter/plugins/CommentPlugin.d.ts @@ -0,0 +1,18 @@ +import { Comment } from "../../models/comments/index"; +import { Reflection, ProjectReflection } from "../../models/reflections/index"; +import { ConverterComponent } from "../components"; +export declare class CommentPlugin extends ConverterComponent { + private comments; + private hidden; + initialize(): void; + private storeModuleComment(comment, reflection); + private applyModifiers(reflection, comment); + private onBegin(context); + private onCreateTypeParameter(context, reflection, node?); + private onDeclaration(context, reflection, node?); + private onFunctionImplementation(context, reflection, node?); + private onBeginResolve(context); + private onResolve(context, reflection); + static removeTags(comment: Comment, tagName: string): void; + static removeReflection(project: ProjectReflection, reflection: Reflection): void; +} diff --git a/lib/converter/plugins/CommentPlugin.js b/lib/converter/plugins/CommentPlugin.js new file mode 100644 index 000000000..82af88b0a --- /dev/null +++ b/lib/converter/plugins/CommentPlugin.js @@ -0,0 +1,257 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var index_1 = require("../../models/comments/index"); +var index_2 = require("../../models/types/index"); +var index_3 = require("../../models/reflections/index"); +var components_1 = require("../components"); +var comment_1 = require("../factories/comment"); +var converter_1 = require("../converter"); +var CommentPlugin = (function (_super) { + __extends(CommentPlugin, _super); + function CommentPlugin() { + _super.apply(this, arguments); + } + CommentPlugin.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[converter_1.Converter.EVENT_BEGIN] = this.onBegin, + _a[converter_1.Converter.EVENT_CREATE_DECLARATION] = this.onDeclaration, + _a[converter_1.Converter.EVENT_CREATE_SIGNATURE] = this.onDeclaration, + _a[converter_1.Converter.EVENT_CREATE_TYPE_PARAMETER] = this.onCreateTypeParameter, + _a[converter_1.Converter.EVENT_FUNCTION_IMPLEMENTATION] = this.onFunctionImplementation, + _a[converter_1.Converter.EVENT_RESOLVE_BEGIN] = this.onBeginResolve, + _a[converter_1.Converter.EVENT_RESOLVE] = this.onResolve, + _a + )); + var _a; + }; + CommentPlugin.prototype.storeModuleComment = function (comment, reflection) { + var isPreferred = (comment.toLowerCase().indexOf('@preferred') != -1); + if (this.comments[reflection.id]) { + var info = this.comments[reflection.id]; + if (!isPreferred && (info.isPreferred || info.fullText.length > comment.length)) { + return; + } + info.fullText = comment; + info.isPreferred = isPreferred; + } + else { + this.comments[reflection.id] = { + reflection: reflection, + fullText: comment, + isPreferred: isPreferred + }; + } + }; + CommentPlugin.prototype.applyModifiers = function (reflection, comment) { + if (comment.hasTag('private')) { + reflection.setFlag(index_3.ReflectionFlag.Private); + CommentPlugin.removeTags(comment, 'private'); + } + if (comment.hasTag('protected')) { + reflection.setFlag(index_3.ReflectionFlag.Protected); + CommentPlugin.removeTags(comment, 'protected'); + } + if (comment.hasTag('public')) { + reflection.setFlag(index_3.ReflectionFlag.Public); + CommentPlugin.removeTags(comment, 'public'); + } + if (comment.hasTag('event')) { + reflection.kind = index_3.ReflectionKind.Event; + CommentPlugin.removeTags(comment, 'event'); + } + if (comment.hasTag('hidden')) { + if (!this.hidden) + this.hidden = []; + this.hidden.push(reflection); + } + }; + CommentPlugin.prototype.onBegin = function (context) { + this.comments = {}; + }; + CommentPlugin.prototype.onCreateTypeParameter = function (context, reflection, node) { + var comment = reflection.parent.comment; + if (comment) { + var tag = comment.getTag('typeparam', reflection.name); + if (!tag) + tag = comment.getTag('param', '<' + reflection.name + '>'); + if (!tag) + tag = comment.getTag('param', reflection.name); + if (tag) { + reflection.comment = new index_1.Comment(tag.text); + comment.tags.splice(comment.tags.indexOf(tag), 1); + } + } + }; + CommentPlugin.prototype.onDeclaration = function (context, reflection, node) { + if (!node) + return; + var rawComment = comment_1.getRawComment(node); + if (!rawComment) + return; + if (reflection.kindOf(index_3.ReflectionKind.FunctionOrMethod) || (reflection.kindOf(index_3.ReflectionKind.Event) && reflection['signatures'])) { + var comment = comment_1.parseComment(rawComment, reflection.comment); + this.applyModifiers(reflection, comment); + } + else if (reflection.kindOf(index_3.ReflectionKind.Module)) { + this.storeModuleComment(rawComment, reflection); + } + else { + var comment = comment_1.parseComment(rawComment, reflection.comment); + this.applyModifiers(reflection, comment); + reflection.comment = comment; + } + }; + CommentPlugin.prototype.onFunctionImplementation = function (context, reflection, node) { + if (!node) + return; + var comment = comment_1.getRawComment(node); + if (comment) { + reflection.comment = comment_1.parseComment(comment, reflection.comment); + } + }; + CommentPlugin.prototype.onBeginResolve = function (context) { + for (var id in this.comments) { + if (!this.comments.hasOwnProperty(id)) + continue; + var info = this.comments[id]; + var comment = comment_1.parseComment(info.fullText); + CommentPlugin.removeTags(comment, 'preferred'); + this.applyModifiers(info.reflection, comment); + info.reflection.comment = comment; + } + if (this.hidden) { + var project = context.project; + this.hidden.forEach(function (reflection) { + CommentPlugin.removeReflection(project, reflection); + }); + } + }; + CommentPlugin.prototype.onResolve = function (context, reflection) { + if (!(reflection instanceof index_3.DeclarationReflection)) + return; + var signatures = reflection.getAllSignatures(); + if (signatures.length) { + var comment = reflection.comment; + if (comment && comment.hasTag('returns')) { + comment.returns = comment.getTag('returns').text; + CommentPlugin.removeTags(comment, 'returns'); + } + signatures.forEach(function (signature) { + var childComment = signature.comment; + if (childComment && childComment.hasTag('returns')) { + childComment.returns = childComment.getTag('returns').text; + CommentPlugin.removeTags(childComment, 'returns'); + } + if (comment) { + if (!childComment) { + childComment = signature.comment = new index_1.Comment(); + } + childComment.shortText = childComment.shortText || comment.shortText; + childComment.text = childComment.text || comment.text; + childComment.returns = childComment.returns || comment.returns; + } + if (signature.parameters) { + signature.parameters.forEach(function (parameter) { + var tag; + if (childComment) + tag = childComment.getTag('param', parameter.name); + if (comment && !tag) + tag = comment.getTag('param', parameter.name); + if (tag) { + parameter.comment = new index_1.Comment(tag.text); + } + }); + } + CommentPlugin.removeTags(childComment, 'param'); + }); + CommentPlugin.removeTags(comment, 'param'); + } + }; + CommentPlugin.removeTags = function (comment, tagName) { + if (!comment || !comment.tags) + return; + var i = 0, c = comment.tags.length; + while (i < c) { + if (comment.tags[i].tagName == tagName) { + comment.tags.splice(i, 1); + c--; + } + else { + i++; + } + } + }; + CommentPlugin.removeReflection = function (project, reflection) { + reflection.traverse(function (child) { return CommentPlugin.removeReflection(project, child); }); + var parent = reflection.parent; + parent.traverse(function (child, property) { + if (child == reflection) { + switch (property) { + case index_3.TraverseProperty.Children: + if (parent.children) { + var index = parent.children.indexOf(reflection); + if (index != -1) + parent.children.splice(index, 1); + } + break; + case index_3.TraverseProperty.GetSignature: + delete parent.getSignature; + break; + case index_3.TraverseProperty.IndexSignature: + delete parent.indexSignature; + break; + case index_3.TraverseProperty.Parameters: + if (reflection.parent.parameters) { + var index = reflection.parent.parameters.indexOf(reflection); + if (index != -1) + reflection.parent.parameters.splice(index, 1); + } + break; + case index_3.TraverseProperty.SetSignature: + delete parent.setSignature; + break; + case index_3.TraverseProperty.Signatures: + if (parent.signatures) { + var index = parent.signatures.indexOf(reflection); + if (index != -1) + parent.signatures.splice(index, 1); + } + break; + case index_3.TraverseProperty.TypeLiteral: + parent.type = new index_2.IntrinsicType('Object'); + break; + case index_3.TraverseProperty.TypeParameter: + if (parent.typeParameters) { + var index = parent.typeParameters.indexOf(reflection); + if (index != -1) + parent.typeParameters.splice(index, 1); + } + break; + } + } + }); + var id = reflection.id; + delete project.reflections[id]; + for (var key in project.symbolMapping) { + if (project.symbolMapping.hasOwnProperty(key) && project.symbolMapping[key] == id) { + delete project.symbolMapping[key]; + } + } + }; + CommentPlugin = __decorate([ + components_1.Component({ name: 'comment' }) + ], CommentPlugin); + return CommentPlugin; +}(components_1.ConverterComponent)); +exports.CommentPlugin = CommentPlugin; +//# sourceMappingURL=CommentPlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/CommentPlugin.js.map b/lib/converter/plugins/CommentPlugin.js.map new file mode 100644 index 000000000..2dae8a059 --- /dev/null +++ b/lib/converter/plugins/CommentPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"CommentPlugin.js","sourceRoot":"","sources":["../../../src/lib/converter/plugins/CommentPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,sBAAkC,6BAA6B,CAAC,CAAA;AAChE,sBAA4B,0BAA0B,CAAC,CAAA;AACvD,sBAEmD,gCAAgC,CAAC,CAAA;AACpF,2BAA4C,eAAe,CAAC,CAAA;AAC5D,wBAA0C,sBAAsB,CAAC,CAAA;AACjE,0BAAwB,cAAc,CAAC,CAAA;AA+BvC;IAAmC,iCAAkB;IAArD;QAAmC,8BAAkB;IAsUrD,CAAC;IAtTG,kCAAU,GAAV;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE;YACtB,GAAC,qBAAS,CAAC,WAAW,CAAC,GAAoB,IAAI,CAAC,OAAO;YACvD,GAAC,qBAAS,CAAC,wBAAwB,CAAC,GAAO,IAAI,CAAC,aAAa;YAC7D,GAAC,qBAAS,CAAC,sBAAsB,CAAC,GAAS,IAAI,CAAC,aAAa;YAC7D,GAAC,qBAAS,CAAC,2BAA2B,CAAC,GAAI,IAAI,CAAC,qBAAqB;YACrE,GAAC,qBAAS,CAAC,6BAA6B,CAAC,GAAE,IAAI,CAAC,wBAAwB;YACxE,GAAC,qBAAS,CAAC,mBAAmB,CAAC,GAAY,IAAI,CAAC,cAAc;Y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AC,cAAc,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;wBAC5D,CAAC;wBACD,KAAK,CAAC;gBACd,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;QACvB,OAAO,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAE/B,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;YACpC,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBAChF,OAAO,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;YACtC,CAAC;QACL,CAAC;IACL,CAAC;IAtUL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,SAAS,EAAC,CAAC;qBAAA;IAuU5B,oBAAC;AAAD,CAAC,AAtUD,CAAmC,+BAAkB,GAsUpD;AAtUY,qBAAa,gBAsUzB,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Comment, CommentTag} from \"../../models/comments/index\";\nimport {IntrinsicType} from \"../../models/types/index\";\nimport {Reflection, ReflectionFlag, ReflectionKind, TraverseProperty,\n TypeParameterReflection, DeclarationReflection, ProjectReflection,\n SignatureReflection, ParameterReflection} from \"../../models/reflections/index\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {parseComment, getRawComment} from \"../factories/comment\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\n\n\n/**\n * Structure used by [[ContainerCommentHandler]] to store discovered module comments.\n */\ninterface IModuleComment\n{\n /**\n * The module reflection this comment is targeting.\n */\n reflection:Reflection;\n\n /**\n * The full text of the best matched comment.\n */\n fullText:string;\n\n /**\n * Has the full text been marked as being preferred?\n */\n isPreferred:boolean;\n}\n\n\n/**\n * A handler that parses javadoc comments and attaches [[Models.Comment]] instances to\n * the generated reflections.\n */\n@Component({name:'comment'})\nexport class CommentPlugin extends ConverterComponent\n{\n /**\n * List of discovered module comments.\n */\n private comments:{[id:number]:IModuleComment};\n\n /**\n * List of hidden reflections.\n */\n private hidden:Reflection[];\n\n\n /**\n * Create a new CommentPlugin instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [Converter.EVENT_BEGIN]: this.onBegin,\n [Converter.EVENT_CREATE_DECLARATION]: this.onDeclaration,\n [Converter.EVENT_CREATE_SIGNATURE]: this.onDeclaration,\n [Converter.EVENT_CREATE_TYPE_PARAMETER]: this.onCreateTypeParameter,\n [Converter.EVENT_FUNCTION_IMPLEMENTATION]: this.onFunctionImplementation,\n [Converter.EVENT_RESOLVE_BEGIN]: this.onBeginResolve,\n [Converter.EVENT_RESOLVE]: this.onResolve\n });\n }\n\n\n private storeModuleComment(comment:string, reflection:Reflection) {\n var isPreferred = (comment.toLowerCase().indexOf('@preferred') != -1);\n\n if (this.comments[reflection.id]) {\n var info = this.comments[reflection.id];\n if (!isPreferred && (info.isPreferred || info.fullText.length > comment.length)) {\n return;\n }\n\n info.fullText = comment;\n info.isPreferred = isPreferred;\n } else {\n this.comments[reflection.id] = {\n reflection: reflection,\n fullText: comment,\n isPreferred: isPreferred\n };\n }\n }\n\n\n /**\n * Apply all comment tag modifiers to the given reflection.\n *\n * @param reflection The reflection the modifiers should be applied to.\n * @param comment The comment that should be searched for modifiers.\n */\n private applyModifiers(reflection:Reflection, comment:Comment) {\n if (comment.hasTag('private')) {\n reflection.setFlag(ReflectionFlag.Private);\n CommentPlugin.removeTags(comment, 'private');\n }\n\n if (comment.hasTag('protected')) {\n reflection.setFlag(ReflectionFlag.Protected);\n CommentPlugin.removeTags(comment, 'protected');\n }\n\n if (comment.hasTag('public')) {\n reflection.setFlag(ReflectionFlag.Public);\n CommentPlugin.removeTags(comment, 'public');\n }\n\n if (comment.hasTag('event')) {\n reflection.kind = ReflectionKind.Event;\n // reflection.setFlag(ReflectionFlag.Event);\n CommentPlugin.removeTags(comment, 'event');\n }\n\n if (comment.hasTag('hidden')) {\n if (!this.hidden) this.hidden = [];\n this.hidden.push(reflection);\n }\n }\n\n\n /**\n * Triggered when the converter begins converting a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onBegin(context:Context) {\n this.comments = {};\n }\n\n\n /**\n * Triggered when the converter has created a type parameter reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently processed.\n * @param node The node that is currently processed if available.\n */\n private onCreateTypeParameter(context:Context, reflection:TypeParameterReflection, node?:ts.Node) {\n var comment = reflection.parent.comment;\n if (comment) {\n var tag = comment.getTag('typeparam', reflection.name);\n if (!tag) tag = comment.getTag('param', '<' + reflection.name + '>');\n if (!tag) tag = comment.getTag('param', reflection.name);\n\n if (tag) {\n reflection.comment = new Comment(tag.text);\n comment.tags.splice(comment.tags.indexOf(tag), 1);\n }\n }\n }\n\n\n /**\n * Triggered when the converter has created a declaration or signature reflection.\n *\n * Invokes the comment parser.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently processed.\n * @param node The node that is currently processed if available.\n */\n private onDeclaration(context:Context, reflection:Reflection, node?:ts.Node) {\n if (!node) return;\n var rawComment = getRawComment(node);\n if (!rawComment) return;\n\n if (reflection.kindOf(ReflectionKind.FunctionOrMethod) || (reflection.kindOf(ReflectionKind.Event) && reflection['signatures'])) {\n var comment = parseComment(rawComment, reflection.comment);\n this.applyModifiers(reflection, comment);\n } else if (reflection.kindOf(ReflectionKind.Module)) {\n this.storeModuleComment(rawComment, reflection);\n } else {\n var comment = parseComment(rawComment, reflection.comment);\n this.applyModifiers(reflection, comment);\n reflection.comment = comment;\n }\n }\n\n\n /**\n * Triggered when the converter has found a function implementation.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently processed.\n * @param node The node that is currently processed if available.\n */\n private onFunctionImplementation(context:Context, reflection:Reflection, node?:ts.Node) {\n if (!node) return;\n\n var comment = getRawComment(node);\n if (comment) {\n reflection.comment = parseComment(comment, reflection.comment);\n }\n }\n\n\n /**\n * Triggered when the converter begins resolving a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onBeginResolve(context:Context) {\n for (var id in this.comments) {\n if (!this.comments.hasOwnProperty(id)) continue;\n\n var info = this.comments[id];\n var comment = parseComment(info.fullText);\n CommentPlugin.removeTags(comment, 'preferred');\n\n this.applyModifiers(info.reflection, comment);\n info.reflection.comment = comment;\n }\n\n if (this.hidden) {\n var project = context.project;\n this.hidden.forEach((reflection) => {\n CommentPlugin.removeReflection(project, reflection);\n });\n }\n }\n\n\n /**\n * Triggered when the converter resolves a reflection.\n *\n * Cleans up comment tags related to signatures like @param or @return\n * and moves their data to the corresponding parameter reflections.\n *\n * This hook also copies over the comment of function implementations to their\n * signatures.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently resolved.\n */\n private onResolve(context:Context, reflection:DeclarationReflection) {\n if (!(reflection instanceof DeclarationReflection)) return;\n\n var signatures = reflection.getAllSignatures();\n if (signatures.length) {\n var comment = reflection.comment;\n if (comment && comment.hasTag('returns')) {\n comment.returns = comment.getTag('returns').text;\n CommentPlugin.removeTags(comment, 'returns');\n }\n\n signatures.forEach((signature) => {\n var childComment = signature.comment;\n if (childComment && childComment.hasTag('returns')) {\n childComment.returns = childComment.getTag('returns').text;\n CommentPlugin.removeTags(childComment, 'returns');\n }\n\n if (comment) {\n if (!childComment) {\n childComment = signature.comment = new Comment();\n }\n\n childComment.shortText = childComment.shortText || comment.shortText;\n childComment.text = childComment.text || comment.text;\n childComment.returns = childComment.returns || comment.returns;\n }\n\n if (signature.parameters) {\n signature.parameters.forEach((parameter) => {\n var tag:CommentTag;\n if (childComment) tag = childComment.getTag('param', parameter.name);\n if (comment && !tag) tag = comment.getTag('param', parameter.name);\n if (tag) {\n parameter.comment = new Comment(tag.text);\n }\n });\n }\n\n CommentPlugin.removeTags(childComment, 'param');\n });\n\n CommentPlugin.removeTags(comment, 'param');\n }\n }\n\n\n /**\n * Remove all tags with the given name from the given comment instance.\n *\n * @param comment The comment that should be modified.\n * @param tagName The name of the that that should be removed.\n */\n static removeTags(comment:Comment, tagName:string) {\n if (!comment || !comment.tags) return;\n\n var i = 0, c = comment.tags.length;\n while (i < c) {\n if (comment.tags[i].tagName == tagName) {\n comment.tags.splice(i, 1);\n c--;\n } else {\n i++;\n }\n }\n }\n\n\n /**\n * Remove the given reflection from the project.\n */\n static removeReflection(project:ProjectReflection, reflection:Reflection) {\n reflection.traverse((child) => CommentPlugin.removeReflection(project, child));\n\n var parent = reflection.parent;\n parent.traverse((child:Reflection, property:TraverseProperty) => {\n if (child == reflection) {\n switch (property) {\n case TraverseProperty.Children:\n if (parent.children) {\n var index = parent.children.indexOf(reflection);\n if (index != -1) parent.children.splice(index, 1);\n }\n break;\n case TraverseProperty.GetSignature:\n delete parent.getSignature;\n break;\n case TraverseProperty.IndexSignature:\n delete parent.indexSignature;\n break;\n case TraverseProperty.Parameters:\n if ((reflection.parent).parameters) {\n var index = (reflection.parent).parameters.indexOf(reflection);\n if (index != -1) (reflection.parent).parameters.splice(index, 1);\n }\n break;\n case TraverseProperty.SetSignature:\n delete parent.setSignature;\n break;\n case TraverseProperty.Signatures:\n if (parent.signatures) {\n var index = parent.signatures.indexOf(reflection);\n if (index != -1) parent.signatures.splice(index, 1);\n }\n break;\n case TraverseProperty.TypeLiteral:\n parent.type = new IntrinsicType('Object');\n break;\n case TraverseProperty.TypeParameter:\n if (parent.typeParameters) {\n var index = parent.typeParameters.indexOf(reflection);\n if (index != -1) parent.typeParameters.splice(index, 1);\n }\n break;\n }\n }\n });\n\n var id = reflection.id;\n delete project.reflections[id];\n\n for (var key in project.symbolMapping) {\n if (project.symbolMapping.hasOwnProperty(key) && project.symbolMapping[key] == id) {\n delete project.symbolMapping[key];\n }\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/DecoratorPlugin.d.ts b/lib/converter/plugins/DecoratorPlugin.d.ts new file mode 100644 index 000000000..b7a1ab300 --- /dev/null +++ b/lib/converter/plugins/DecoratorPlugin.d.ts @@ -0,0 +1,9 @@ +import { ConverterComponent } from "../components"; +export declare class DecoratorPlugin extends ConverterComponent { + private usages; + initialize(): void; + private extractArguments(args, signature); + private onBegin(context); + private onDeclaration(context, reflection, node?); + private onBeginResolve(context); +} diff --git a/lib/converter/plugins/DecoratorPlugin.js b/lib/converter/plugins/DecoratorPlugin.js new file mode 100644 index 000000000..b0d61a9de --- /dev/null +++ b/lib/converter/plugins/DecoratorPlugin.js @@ -0,0 +1,108 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/types/index"); +var components_1 = require("../components"); +var converter_1 = require("../converter"); +var DecoratorPlugin = (function (_super) { + __extends(DecoratorPlugin, _super); + function DecoratorPlugin() { + _super.apply(this, arguments); + } + DecoratorPlugin.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[converter_1.Converter.EVENT_BEGIN] = this.onBegin, + _a[converter_1.Converter.EVENT_CREATE_DECLARATION] = this.onDeclaration, + _a[converter_1.Converter.EVENT_RESOLVE] = this.onBeginResolve, + _a + )); + var _a; + }; + DecoratorPlugin.prototype.extractArguments = function (args, signature) { + var result = {}; + args.forEach(function (arg, index) { + if (index < signature.parameters.length) { + var parameter = signature.parameters[index]; + result[parameter.name] = ts.getTextOfNode(arg); + } + else { + if (!result['...']) + result['...'] = []; + result['...'].push(ts.getTextOfNode(arg)); + } + }); + return result; + }; + DecoratorPlugin.prototype.onBegin = function (context) { + this.usages = {}; + }; + DecoratorPlugin.prototype.onDeclaration = function (context, reflection, node) { + var _this = this; + if (!node || !node.decorators) + return; + node.decorators.forEach(function (decorator) { + var callExpression; + var identifier; + switch (decorator.expression.kind) { + case 69: + identifier = decorator.expression; + break; + case 174: + callExpression = decorator.expression; + identifier = callExpression.expression; + break; + default: + return; + } + var info = { + name: ts.getTextOfNode(identifier) + }; + var type = context.checker.getTypeAtLocation(identifier); + if (type && type.symbol) { + var symbolID = context.getSymbolID(type.symbol); + info.type = new index_1.ReferenceType(info.name, symbolID); + if (callExpression && callExpression.arguments) { + var signature = context.checker.getResolvedSignature(callExpression); + if (signature) { + info.arguments = _this.extractArguments(callExpression.arguments, signature); + } + } + if (!_this.usages[symbolID]) + _this.usages[symbolID] = []; + _this.usages[symbolID].push(new index_1.ReferenceType(reflection.name, index_1.ReferenceType.SYMBOL_ID_RESOLVED, reflection)); + } + if (!reflection.decorators) + reflection.decorators = []; + reflection.decorators.push(info); + }); + }; + DecoratorPlugin.prototype.onBeginResolve = function (context) { + for (var symbolID in this.usages) { + if (!this.usages.hasOwnProperty(symbolID)) + continue; + var id = context.project.symbolMapping[symbolID]; + if (!id) + continue; + var reflection = context.project.reflections[id]; + if (reflection) { + reflection.decorates = this.usages[symbolID]; + } + } + }; + DecoratorPlugin = __decorate([ + components_1.Component({ name: 'decorator' }) + ], DecoratorPlugin); + return DecoratorPlugin; +}(components_1.ConverterComponent)); +exports.DecoratorPlugin = DecoratorPlugin; +//# sourceMappingURL=DecoratorPlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/DecoratorPlugin.js.map b/lib/converter/plugins/DecoratorPlugin.js.map new file mode 100644 index 000000000..a2c7094d9 --- /dev/null +++ b/lib/converter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C,EAAE,CAAC,CAAC;YACjD,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;gBACb,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACjD,CAAC;QACL,CAAC;IACL,CAAC;IAxHL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,WAAW,EAAC,CAAC;uBAAA;IAyH9B,sBAAC;AAAD,CAAC,AAxHD,CAAqC,+BAAkB,GAwHtD;AAxHY,uBAAe,kBAwH3B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {ReferenceType} from \"../../models/types/index\";\nimport {Reflection, IDecorator} from \"../../models/reflections/index\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\n\n\n/**\n * A plugin that detects decorators.\n */\n@Component({name:'decorator'})\nexport class DecoratorPlugin extends ConverterComponent\n{\n private usages:{[symbolID:number]:ReferenceType[]};\n\n\n /**\n * Create a new ImplementsPlugin instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [Converter.EVENT_BEGIN]: this.onBegin,\n [Converter.EVENT_CREATE_DECLARATION]: this.onDeclaration,\n [Converter.EVENT_RESOLVE]: this.onBeginResolve,\n });\n }\n\n\n /**\n * Create an object describing the arguments a decorator is set with.\n *\n * @param args The arguments resolved from the decorator's call expression.\n * @param signature The signature definition of the decorator being used.\n * @returns An object describing the decorator parameters,\n */\n private extractArguments(args:ts.NodeArray, signature:ts.Signature):any {\n var result = {};\n args.forEach((arg:ts.Expression, index:number) => {\n if (index < signature.parameters.length) {\n var parameter = signature.parameters[index];\n result[parameter.name] = ts.getTextOfNode(arg);\n } else {\n if (!result['...']) result['...'] = [];\n result['...'].push(ts.getTextOfNode(arg));\n }\n });\n\n return result;\n }\n\n\n /**\n * Triggered when the converter begins converting a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onBegin(context:Context) {\n this.usages = {};\n }\n\n\n /**\n * Triggered when the converter has created a declaration or signature reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently processed.\n * @param node The node that is currently processed if available.\n */\n private onDeclaration(context:Context, reflection:Reflection, node?:ts.Node) {\n if (!node || !node.decorators) return;\n node.decorators.forEach((decorator:ts.Decorator) => {\n var callExpression:ts.CallExpression;\n var identifier:ts.Expression;\n\n switch (decorator.expression.kind) {\n case ts.SyntaxKind.Identifier:\n identifier = decorator.expression;\n break;\n case ts.SyntaxKind.CallExpression:\n callExpression = decorator.expression;\n identifier = callExpression.expression;\n break;\n default:\n return;\n }\n\n var info:IDecorator = {\n name: ts.getTextOfNode(identifier)\n };\n\n var type = context.checker.getTypeAtLocation(identifier);\n if (type && type.symbol) {\n var symbolID = context.getSymbolID(type.symbol);\n info.type = new ReferenceType(info.name, symbolID);\n\n if (callExpression && callExpression.arguments) {\n var signature = context.checker.getResolvedSignature(callExpression);\n if (signature) {\n info.arguments = this.extractArguments(callExpression.arguments, signature);\n }\n }\n\n if (!this.usages[symbolID]) this.usages[symbolID] = [];\n this.usages[symbolID].push(new ReferenceType(reflection.name, ReferenceType.SYMBOL_ID_RESOLVED, reflection));\n }\n\n if (!reflection.decorators) reflection.decorators = [];\n reflection.decorators.push(info);\n });\n }\n\n\n /**\n * Triggered when the converter resolves a reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently resolved.\n */\n private onBeginResolve(context:Context) {\n for (var symbolID in this.usages) {\n if (!this.usages.hasOwnProperty(symbolID)) continue;\n\n var id = context.project.symbolMapping[symbolID];\n if (!id) continue;\n\n var reflection = context.project.reflections[id];\n if (reflection) {\n reflection.decorates = this.usages[symbolID];\n }\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/DeepCommentPlugin.d.ts b/lib/converter/plugins/DeepCommentPlugin.d.ts new file mode 100644 index 000000000..ff989eca3 --- /dev/null +++ b/lib/converter/plugins/DeepCommentPlugin.d.ts @@ -0,0 +1,5 @@ +import { ConverterComponent } from "../components"; +export declare class DeepCommentPlugin extends ConverterComponent { + initialize(): void; + private onBeginResolve(context); +} diff --git a/lib/converter/plugins/DeepCommentPlugin.js b/lib/converter/plugins/DeepCommentPlugin.js new file mode 100644 index 000000000..6882ae314 --- /dev/null +++ b/lib/converter/plugins/DeepCommentPlugin.js @@ -0,0 +1,74 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var index_1 = require("../../models/reflections/index"); +var index_2 = require("../../models/comments/index"); +var components_1 = require("../components"); +var converter_1 = require("../converter"); +var DeepCommentPlugin = (function (_super) { + __extends(DeepCommentPlugin, _super); + function DeepCommentPlugin() { + _super.apply(this, arguments); + } + DeepCommentPlugin.prototype.initialize = function () { + this.listenTo(this.owner, converter_1.Converter.EVENT_RESOLVE_BEGIN, this.onBeginResolve, 512); + }; + DeepCommentPlugin.prototype.onBeginResolve = function (context) { + var project = context.project; + var name; + for (var key in project.reflections) { + var reflection = project.reflections[key]; + if (!reflection.comment) { + findDeepComment(reflection); + } + } + function push(parent) { + var part = parent.originalName; + if (!part || part.substr(0, 2) == '__' || parent instanceof index_1.SignatureReflection) { + part = ''; + } + if (part && part != '') { + name = (name == '' ? part : part + '.' + name); + } + } + function findDeepComment(reflection) { + name = ''; + push(reflection); + var target = reflection.parent; + while (target && !(target instanceof index_1.ProjectReflection)) { + push(target); + if (target.comment) { + var tag; + if (reflection instanceof index_1.TypeParameterReflection) { + tag = target.comment.getTag('typeparam', reflection.name); + if (!tag) + tag = target.comment.getTag('param', '<' + reflection.name + '>'); + } + if (!tag) + tag = target.comment.getTag('param', name); + if (tag) { + target.comment.tags.splice(target.comment.tags.indexOf(tag), 1); + reflection.comment = new index_2.Comment('', tag.text); + break; + } + } + target = target.parent; + } + } + }; + DeepCommentPlugin = __decorate([ + components_1.Component({ name: 'deep-comment' }) + ], DeepCommentPlugin); + return DeepCommentPlugin; +}(components_1.ConverterComponent)); +exports.DeepCommentPlugin = DeepCommentPlugin; +//# sourceMappingURL=DeepCommentPlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/DeepCommentPlugin.js.map b/lib/converter/plugins/DeepCommentPlugin.js.map new file mode 100644 index 000000000..f4cf38bcc --- /dev/null +++ b/lib/converter/plugins/DeepCommentPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"DeepCommentPlugin.js","sourceRoot":"","sources":["../../../src/lib/converter/plugins/DeepCommentPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sBAA0F,gCAAgC,CAAC,CAAA;AAC3H,sBAAkC,6BAA6B,CAAC,CAAA;AAChE,2BAA4C,eAAe,CAAC,CAAA;AAC5D,0BAAwB,cAAc,CAAC,CAAA;AAQvC;IAAuC,qCAAkB;IAAzD;QAAuC,8BAAkB;IAiEzD,CAAC;IA5DG,sCAAU,GAAV;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,qBAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IACvF,CAAC;IAQO,0CAAc,GAAtB,UAAuB,OAAe;QAClC,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC9B,IAAI,IAAW,CAAC;QAChB,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;YAClC,IAA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AAC,OAAO,EAAE,GAAG,GAAG,UAAU,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;oBAChF,CAAC;oBAED,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;wBAAC,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;oBAErD,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;wBACN,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;wBAChE,UAAU,CAAC,OAAO,GAAG,IAAI,eAAO,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;wBAC/C,KAAK,CAAC;oBACV,CAAC;gBACL,CAAC;gBAED,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YAC3B,CAAC;QACL,CAAC;IACL,CAAC;IAjEL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,cAAc,EAAC,CAAC;yBAAA;IAkEjC,wBAAC;AAAD,CAAC,AAjED,CAAuC,+BAAkB,GAiExD;AAjEY,yBAAiB,oBAiE7B,CAAA","sourcesContent":["import {Reflection, SignatureReflection, ProjectReflection, TypeParameterReflection} from \"../../models/reflections/index\";\nimport {Comment, CommentTag} from \"../../models/comments/index\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\n\n\n/**\n * A handler that moves comments with dot syntax to their target.\n */\n@Component({name:'deep-comment'})\nexport class DeepCommentPlugin extends ConverterComponent\n{\n /**\n * Create a new CommentHandler instance.\n */\n initialize() {\n this.listenTo(this.owner, Converter.EVENT_RESOLVE_BEGIN, this.onBeginResolve, 512);\n }\n\n\n /**\n * Triggered when the converter begins resolving a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onBeginResolve(context:Context) {\n var project = context.project;\n var name:string;\n for (var key in project.reflections) {\n var reflection = project.reflections[key];\n if (!reflection.comment) {\n findDeepComment(reflection);\n }\n }\n\n\n function push(parent:Reflection) {\n var part = parent.originalName;\n if (!part || part.substr(0, 2) == '__' || parent instanceof SignatureReflection) {\n part = '';\n }\n\n if (part && part != '') {\n name = (name == '' ? part : part + '.' + name);\n }\n }\n\n\n function findDeepComment(reflection:Reflection) {\n name = '';\n push(reflection);\n var target = reflection.parent;\n\n while (target && !(target instanceof ProjectReflection)) {\n push(target);\n if (target.comment) {\n var tag:CommentTag;\n if (reflection instanceof TypeParameterReflection) {\n tag = target.comment.getTag('typeparam', reflection.name);\n if (!tag) tag = target.comment.getTag('param', '<' + reflection.name + '>');\n }\n\n if (!tag) tag = target.comment.getTag('param', name);\n\n if (tag) {\n target.comment.tags.splice(target.comment.tags.indexOf(tag), 1);\n reflection.comment = new Comment('', tag.text);\n break;\n }\n }\n\n target = target.parent;\n }\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/DynamicModulePlugin.d.ts b/lib/converter/plugins/DynamicModulePlugin.d.ts new file mode 100644 index 000000000..04e6b69d4 --- /dev/null +++ b/lib/converter/plugins/DynamicModulePlugin.d.ts @@ -0,0 +1,9 @@ +import { ConverterComponent } from "../components"; +export declare class DynamicModulePlugin extends ConverterComponent { + private basePath; + private reflections; + initialize(): void; + private onBegin(context); + private onDeclaration(context, reflection, node?); + private onBeginResolve(context); +} diff --git a/lib/converter/plugins/DynamicModulePlugin.js b/lib/converter/plugins/DynamicModulePlugin.js new file mode 100644 index 000000000..db55c4ab2 --- /dev/null +++ b/lib/converter/plugins/DynamicModulePlugin.js @@ -0,0 +1,62 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var Path = require("path"); +var abstract_1 = require("../../models/reflections/abstract"); +var components_1 = require("../components"); +var base_path_1 = require("../utils/base-path"); +var converter_1 = require("../converter"); +var DynamicModulePlugin = (function (_super) { + __extends(DynamicModulePlugin, _super); + function DynamicModulePlugin() { + _super.apply(this, arguments); + this.basePath = new base_path_1.BasePath(); + } + DynamicModulePlugin.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[converter_1.Converter.EVENT_BEGIN] = this.onBegin, + _a[converter_1.Converter.EVENT_CREATE_DECLARATION] = this.onDeclaration, + _a[converter_1.Converter.EVENT_RESOLVE_BEGIN] = this.onBeginResolve, + _a + )); + var _a; + }; + DynamicModulePlugin.prototype.onBegin = function (context) { + this.basePath.reset(); + this.reflections = []; + }; + DynamicModulePlugin.prototype.onDeclaration = function (context, reflection, node) { + if (reflection.kindOf(abstract_1.ReflectionKind.ExternalModule)) { + var name = reflection.name; + if (name.indexOf('/') == -1) { + return; + } + name = name.replace(/"/g, ''); + this.reflections.push(reflection); + this.basePath.add(name); + } + }; + DynamicModulePlugin.prototype.onBeginResolve = function (context) { + var _this = this; + this.reflections.forEach(function (reflection) { + var name = reflection.name.replace(/"/g, ''); + name = name.substr(0, name.length - Path.extname(name).length); + reflection.name = '"' + _this.basePath.trim(name) + '"'; + }); + }; + DynamicModulePlugin = __decorate([ + components_1.Component({ name: 'dynamic-module' }) + ], DynamicModulePlugin); + return DynamicModulePlugin; +}(components_1.ConverterComponent)); +exports.DynamicModulePlugin = DynamicModulePlugin; +//# sourceMappingURL=DynamicModulePlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/DynamicModulePlugin.js.map b/lib/converter/plugins/DynamicModulePlugin.js.map new file mode 100644 index 000000000..82fa22d01 --- /dev/null +++ b/lib/converter/plugins/DynamicModulePlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"DynamicModulePlugin.js","sourceRoot":"","sources":["../../../src/lib/converter/plugins/DynamicModulePlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAE7B,yBAAyC,mCAAmC,CAAC,CAAA;AAC7E,2BAA4C,eAAe,CAAC,CAAA;AAC5D,0BAAuB,oBAAoB,CAAC,CAAA;AAC5C,0BAAwB,cAAc,CAAC,CAAA;AASvC;IAAyC,uCAAkB;IAA3D;QAAyC,8BAAkB;QAK/C,aAAQ,GAAG,IAAI,oBAAQ,EAAE,CAAC;IAgEtC,CAAC;IArDG,wCAAU,GAAV;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE;YACtB,GAAC,qBAAS,CAAC,WAAW,CAAC,GAAe,IAAI,CAAC,OAAO;YAClD,GAAC,qBAAS,CAAC,wBAAwB,CAAC,GAAE,IAAI,CAAC,aAAa;YACxD,GAAC,qBAAS,CAAC,mBAAmB,CAAC,GAAO,IAAI,CAAC,cAAc;;SAC5D,CAAC,CAAC;;IACP,CAAC;IAQO,qCAAO,GAAf,UAAgB,OAAe;QAC3B,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IAC1B,CAAC;IAUO,2CAAa,GAArB,UAAsB,OAAe,EAAE,UAAqB,EAAE,IAAa;QACvE,EAAE,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,yBAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;YACnD,IAAI,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;YAC3B,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC1B,MAAM,CAAC;YACX,CAAC;YAED,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC9B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;IACL,CAAC;IAQO,4CAAc,GAAtB,UAAuB,OAAe;QAAtC,iBAMC;QALG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,UAAC,UAAU;YAChC,IAAI,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC7C,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;YAC/D,UAAU,CAAC,IAAI,GAAG,GAAG,GAAG,KAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QAC3D,CAAC,CAAC,CAAC;IACP,CAAC;IArEL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,gBAAgB,EAAC,CAAC;2BAAA;IAsEnC,0BAAC;AAAD,CAAC,AArED,CAAyC,+BAAkB,GAqE1D;AArEY,2BAAmB,sBAqE/B,CAAA","sourcesContent":["import * as ts from \"typescript\";\nimport * as Path from \"path\";\n\nimport {Reflection, ReflectionKind} from \"../../models/reflections/abstract\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {BasePath} from \"../utils/base-path\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\n\n\n/**\n * A handler that truncates the names of dynamic modules to not include the\n * project's base path.\n */\n@Component({name:'dynamic-module'})\nexport class DynamicModulePlugin extends ConverterComponent\n{\n /**\n * Helper class for determining the base path.\n */\n private basePath = new BasePath();\n\n /**\n * List of reflections whose name must be trimmed.\n */\n private reflections:Reflection[];\n\n\n /**\n * Create a new DynamicModuleHandler instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [Converter.EVENT_BEGIN]: this.onBegin,\n [Converter.EVENT_CREATE_DECLARATION]: this.onDeclaration,\n [Converter.EVENT_RESOLVE_BEGIN]: this.onBeginResolve\n });\n }\n\n\n /**\n * Triggered when the converter begins converting a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onBegin(context:Context) {\n this.basePath.reset();\n this.reflections = [];\n }\n\n\n /**\n * Triggered when the converter has created a declaration reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently processed.\n * @param node The node that is currently processed if available.\n */\n private onDeclaration(context:Context, reflection:Reflection, node?:ts.Node) {\n if (reflection.kindOf(ReflectionKind.ExternalModule)) {\n var name = reflection.name;\n if (name.indexOf('/') == -1) {\n return;\n }\n\n name = name.replace(/\"/g, '');\n this.reflections.push(reflection);\n this.basePath.add(name);\n }\n }\n\n\n /**\n * Triggered when the converter begins resolving a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onBeginResolve(context:Context) {\n this.reflections.forEach((reflection) => {\n var name = reflection.name.replace(/\"/g, '');\n name = name.substr(0, name.length - Path.extname(name).length);\n reflection.name = '\"' + this.basePath.trim(name) + '\"';\n });\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/GitHubPlugin.d.ts b/lib/converter/plugins/GitHubPlugin.d.ts new file mode 100644 index 000000000..c5ddbbb23 --- /dev/null +++ b/lib/converter/plugins/GitHubPlugin.d.ts @@ -0,0 +1,8 @@ +import { ConverterComponent } from "../components"; +export declare class GitHubPlugin extends ConverterComponent { + private repositories; + private ignoredPaths; + initialize(): void; + private getRepository(fileName); + private onEndResolve(context); +} diff --git a/lib/converter/plugins/GitHubPlugin.js b/lib/converter/plugins/GitHubPlugin.js new file mode 100644 index 000000000..7e72ed1de --- /dev/null +++ b/lib/converter/plugins/GitHubPlugin.js @@ -0,0 +1,144 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ShellJS = require("shelljs"); +var Path = require("path"); +var components_1 = require("../components"); +var base_path_1 = require("../utils/base-path"); +var converter_1 = require("../converter"); +var Repository = (function () { + function Repository(path) { + var _this = this; + this.branch = 'master'; + this.files = []; + this.path = path; + ShellJS.pushd(path); + var out = ShellJS.exec('git ls-remote --get-url', { silent: true }); + if (out.code == 0) { + var url; + var remotes = out.stdout.split('\n'); + for (var i = 0, c = remotes.length; i < c; i++) { + url = /github\.com[:\/]([^\/]+)\/(.*)/.exec(remotes[i]); + if (url) { + this.gitHubUser = url[1]; + this.gitHubProject = url[2]; + if (this.gitHubProject.substr(-4) == '.git') { + this.gitHubProject = this.gitHubProject.substr(0, this.gitHubProject.length - 4); + } + break; + } + } + } + out = ShellJS.exec('git ls-files', { silent: true }); + if (out.code == 0) { + out.stdout.split('\n').forEach(function (file) { + if (file != '') { + _this.files.push(base_path_1.BasePath.normalize(path + '/' + file)); + } + }); + } + out = ShellJS.exec('git rev-parse --short HEAD', { silent: true }); + if (out.code == 0) { + this.branch = out.stdout.replace('\n', ''); + } + ShellJS.popd(); + } + Repository.prototype.contains = function (fileName) { + return this.files.indexOf(fileName) != -1; + }; + Repository.prototype.getGitHubURL = function (fileName) { + if (!this.gitHubUser || !this.gitHubProject || !this.contains(fileName)) { + return null; + } + return [ + 'https://github.com', + this.gitHubUser, + this.gitHubProject, + 'blob', + this.branch, + fileName.substr(this.path.length + 1) + ].join('/'); + }; + Repository.tryCreateRepository = function (path) { + ShellJS.pushd(path); + var out = ShellJS.exec('git rev-parse --show-toplevel', { silent: true }); + ShellJS.popd(); + if (out.code != 0) + return null; + return new Repository(base_path_1.BasePath.normalize(out.stdout.replace("\n", ''))); + }; + return Repository; +}()); +var GitHubPlugin = (function (_super) { + __extends(GitHubPlugin, _super); + function GitHubPlugin() { + _super.apply(this, arguments); + this.repositories = {}; + this.ignoredPaths = []; + } + GitHubPlugin.prototype.initialize = function () { + ShellJS.config.silent = true; + if (ShellJS.which('git')) { + this.listenTo(this.owner, converter_1.Converter.EVENT_RESOLVE_END, this.onEndResolve); + } + }; + GitHubPlugin.prototype.getRepository = function (fileName) { + var dirName = Path.dirname(fileName); + for (var i = 0, c = this.ignoredPaths.length; i < c; i++) { + if (this.ignoredPaths[i] == dirName) { + return null; + } + } + for (var path in this.repositories) { + if (!this.repositories.hasOwnProperty(path)) + continue; + if (fileName.substr(0, path.length) == path) { + return this.repositories[path]; + } + } + var repository = Repository.tryCreateRepository(dirName); + if (repository) { + this.repositories[repository.path] = repository; + return repository; + } + var segments = dirName.split('/'); + for (var i = segments.length; i > 0; i--) { + this.ignoredPaths.push(segments.slice(0, i).join('/')); + } + return null; + }; + GitHubPlugin.prototype.onEndResolve = function (context) { + var _this = this; + var project = context.project; + project.files.forEach(function (sourceFile) { + var repository = _this.getRepository(sourceFile.fullFileName); + if (repository) { + sourceFile.url = repository.getGitHubURL(sourceFile.fullFileName); + } + }); + for (var key in project.reflections) { + var reflection = project.reflections[key]; + if (reflection.sources) + reflection.sources.forEach(function (source) { + if (source.file && source.file.url) { + source.url = source.file.url + '#L' + source.line; + } + }); + } + }; + GitHubPlugin = __decorate([ + components_1.Component({ name: 'git-hub' }) + ], GitHubPlugin); + return GitHubPlugin; +}(components_1.ConverterComponent)); +exports.GitHubPlugin = GitHubPlugin; +//# sourceMappingURL=GitHubPlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/GitHubPlugin.js.map b/lib/converter/plugins/GitHubPlugin.js.map new file mode 100644 index 000000000..5dcc6eec6 --- /dev/null +++ b/lib/converter/plugins/GitHubPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"GitHubPlugin.js","sourceRoot":"","sources":["../../../src/lib/converter/plugins/GitHubPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,OAAO,WAAM,SAAS,CAAC,CAAA;AACnC,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAG7B,2BAA4C,eAAe,CAAC,CAAA;AAC5D,0BAAuB,oBAAoB,CAAC,CAAA;AAC5C,0BAAwB,cAAc,CAAC,CAAA;AAOvC;IAiCI,oBAAY,IAAW;QAjC3B,iBA0HC;QAhHG,WAAM,GAAU,QAAQ,CAAC;QAKzB,UAAK,GAAY,EAAE,CAAC;QAmBhB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEpB,IAAI,GAAG,GAAkC,OAAO,CAAC,IAAI,CAAC,yBAAyB,EAAE,EAAC,MAAM,EAAC,IAAI,EAAC,CAAC,CAAC;QAChG,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;YAChB,IAAI,GAAmB,CAAC;YACxB,IAAI,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACrC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC7C,GAAG,GAAG,gCAAgC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC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,CAAC;wBACjC,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;oBACtD,CAAC;gBACL,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAzFL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,SAAS,EAAC,CAAC;oBAAA;IA0F5B,mBAAC;AAAD,CAAC,AAzFD,CAAkC,+BAAkB,GAyFnD;AAzFY,oBAAY,eAyFxB,CAAA","sourcesContent":["import * as ShellJS from \"shelljs\";\nimport * as Path from \"path\";\n\nimport {ISourceReference} from \"../../models/sources/file\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {BasePath} from \"../utils/base-path\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\n\n\n/**\n * Stores data of a repository.\n */\nclass Repository\n{\n /**\n * The root path of this repository.\n */\n path:string;\n\n /**\n * The name of the branch this repository is on right now.\n */\n branch:string = 'master';\n\n /**\n * A list of all files tracked by the repository.\n */\n files:string[] = [];\n\n /**\n * The user/organisation name of this repository on GitHub.\n */\n gitHubUser:string;\n\n /**\n * The project name of this repository on GitHub.\n */\n gitHubProject:string;\n\n\n /**\n * Create a new Repository instance.\n *\n * @param path The root path of the repository.\n */\n constructor(path:string) {\n this.path = path;\n ShellJS.pushd(path);\n\n var out = ShellJS.exec('git ls-remote --get-url', {silent:true});\n if (out.code == 0) {\n var url:RegExpExecArray;\n var remotes = out.stdout.split('\\n');\n for (var i = 0, c = remotes.length; i < c; i++) {\n url = /github\\.com[:\\/]([^\\/]+)\\/(.*)/.exec(remotes[i]);\n if (url) {\n this.gitHubUser = url[1];\n this.gitHubProject = url[2];\n if (this.gitHubProject.substr(-4) == '.git') {\n this.gitHubProject = this.gitHubProject.substr(0, this.gitHubProject.length - 4);\n }\n break;\n }\n }\n }\n\n out = ShellJS.exec('git ls-files', {silent:true});\n if (out.code == 0) {\n out.stdout.split('\\n').forEach((file) => {\n if (file != '') {\n this.files.push(BasePath.normalize(path + '/' + file));\n }\n });\n }\n\n out = ShellJS.exec('git rev-parse --short HEAD', {silent:true});\n if (out.code == 0) {\n this.branch = out.stdout.replace('\\n', '');\n }\n\n ShellJS.popd();\n }\n\n\n /**\n * Check whether the given file is tracked by this repository.\n *\n * @param fileName The name of the file to test for.\n * @returns TRUE when the file is part of the repository, otherwise FALSE.\n */\n contains(fileName:string):boolean {\n return this.files.indexOf(fileName) != -1;\n }\n\n\n /**\n * Get the URL of the given file on GitHub.\n *\n * @param fileName The file whose GitHub URL should be determined.\n * @returns An url pointing to the web preview of the given file or NULL.\n */\n getGitHubURL(fileName:string):string {\n if (!this.gitHubUser || !this.gitHubProject || !this.contains(fileName)) {\n return null;\n }\n\n return [\n 'https://github.com',\n this.gitHubUser,\n this.gitHubProject,\n 'blob',\n this.branch,\n fileName.substr(this.path.length + 1)\n ].join('/');\n }\n\n\n /**\n * Try to create a new repository instance.\n *\n * Checks whether the given path is the root of a valid repository and if so\n * creates a new instance of [[Repository]].\n *\n * @param path The potential repository root.\n * @returns A new instance of [[Repository]] or NULL.\n */\n static tryCreateRepository(path:string):Repository {\n ShellJS.pushd(path);\n var out = ShellJS.exec('git rev-parse --show-toplevel', {silent:true});\n ShellJS.popd();\n\n if (out.code != 0) return null;\n return new Repository(BasePath.normalize(out.stdout.replace(\"\\n\", '')));\n }\n}\n\n\n/**\n * A handler that watches for repositories with GitHub origin and links\n * their source files to the related GitHub pages.\n */\n@Component({name:'git-hub'})\nexport class GitHubPlugin extends ConverterComponent\n{\n /**\n * List of known repositories.\n */\n private repositories:{[path:string]:Repository} = {};\n\n /**\n * List of paths known to be not under git control.\n */\n private ignoredPaths:string[] = [];\n\n\n /**\n * Create a new GitHubHandler instance.\n *\n * @param converter The converter this plugin should be attached to.\n */\n initialize() {\n ShellJS.config.silent = true;\n if (ShellJS.which('git')) {\n this.listenTo(this.owner, Converter.EVENT_RESOLVE_END, this.onEndResolve);\n }\n }\n\n\n /**\n * Check whether the given file is placed inside a repository.\n *\n * @param fileName The name of the file a repository should be looked for.\n * @returns The found repository info or NULL.\n */\n private getRepository(fileName:string):Repository {\n // Check for known non-repositories\n var dirName = Path.dirname(fileName);\n for (var i = 0, c = this.ignoredPaths.length; i < c; i++) {\n if (this.ignoredPaths[i] == dirName) {\n return null;\n }\n }\n\n // Check for known repositories\n for (var path in this.repositories) {\n if (!this.repositories.hasOwnProperty(path)) continue;\n if (fileName.substr(0, path.length) == path) {\n return this.repositories[path];\n }\n }\n\n // Try to create a new repository\n var repository = Repository.tryCreateRepository(dirName);\n if (repository) {\n this.repositories[repository.path] = repository;\n return repository;\n }\n\n // No repository found, add path to ignored paths\n var segments = dirName.split('/');\n for (var i:number = segments.length; i > 0; i--) {\n this.ignoredPaths.push(segments.slice(0, i).join('/'));\n }\n\n return null;\n }\n\n\n /**\n * Triggered when the converter has finished resolving a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onEndResolve(context:Context) {\n var project = context.project;\n project.files.forEach((sourceFile) => {\n var repository = this.getRepository(sourceFile.fullFileName);\n if (repository) {\n sourceFile.url = repository.getGitHubURL(sourceFile.fullFileName);\n }\n });\n\n for (var key in project.reflections) {\n var reflection = project.reflections[key];\n if (reflection.sources) reflection.sources.forEach((source:ISourceReference) => {\n if (source.file && source.file.url) {\n source.url = source.file.url + '#L' + source.line;\n }\n });\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/GroupPlugin.d.ts b/lib/converter/plugins/GroupPlugin.d.ts new file mode 100644 index 000000000..d24220ea0 --- /dev/null +++ b/lib/converter/plugins/GroupPlugin.d.ts @@ -0,0 +1,16 @@ +import { Reflection, ReflectionKind } from "../../models/reflections/index"; +import { ReflectionGroup } from "../../models/ReflectionGroup"; +import { ConverterComponent } from "../components"; +export declare class GroupPlugin extends ConverterComponent { + static WEIGHTS: ReflectionKind[]; + static SINGULARS: {}; + static PLURALS: {}; + initialize(): void; + private onResolve(context, reflection); + private onEndResolve(context); + static getReflectionGroups(reflections: Reflection[]): ReflectionGroup[]; + private static getKindString(kind); + static getKindSingular(kind: ReflectionKind): string; + static getKindPlural(kind: ReflectionKind): string; + static sortCallback(a: Reflection, b: Reflection): number; +} diff --git a/lib/converter/plugins/GroupPlugin.js b/lib/converter/plugins/GroupPlugin.js new file mode 100644 index 000000000..7c637c30f --- /dev/null +++ b/lib/converter/plugins/GroupPlugin.js @@ -0,0 +1,180 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var index_1 = require("../../models/reflections/index"); +var ReflectionGroup_1 = require("../../models/ReflectionGroup"); +var components_1 = require("../components"); +var converter_1 = require("../converter"); +var GroupPlugin = (function (_super) { + __extends(GroupPlugin, _super); + function GroupPlugin() { + _super.apply(this, arguments); + } + GroupPlugin.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[converter_1.Converter.EVENT_RESOLVE] = this.onResolve, + _a[converter_1.Converter.EVENT_RESOLVE_END] = this.onEndResolve, + _a + )); + var _a; + }; + GroupPlugin.prototype.onResolve = function (context, reflection) { + var reflection = reflection; + reflection.kindString = GroupPlugin.getKindSingular(reflection.kind); + if (reflection instanceof index_1.ContainerReflection) { + var container = reflection; + if (container.children && container.children.length > 0) { + container.children.sort(GroupPlugin.sortCallback); + container.groups = GroupPlugin.getReflectionGroups(container.children); + } + } + }; + GroupPlugin.prototype.onEndResolve = function (context) { + function walkDirectory(directory) { + directory.groups = GroupPlugin.getReflectionGroups(directory.getAllReflections()); + for (var key in directory.directories) { + if (!directory.directories.hasOwnProperty(key)) + continue; + walkDirectory(directory.directories[key]); + } + } + var project = context.project; + if (project.children && project.children.length > 0) { + project.children.sort(GroupPlugin.sortCallback); + project.groups = GroupPlugin.getReflectionGroups(project.children); + } + walkDirectory(project.directory); + project.files.forEach(function (file) { + file.groups = GroupPlugin.getReflectionGroups(file.reflections); + }); + }; + GroupPlugin.getReflectionGroups = function (reflections) { + var groups = []; + reflections.forEach(function (child) { + for (var i = 0; i < groups.length; i++) { + var group = groups[i]; + if (group.kind != child.kind) { + continue; + } + group.children.push(child); + return; + } + var group = new ReflectionGroup_1.ReflectionGroup(GroupPlugin.getKindPlural(child.kind), child.kind); + group.children.push(child); + groups.push(group); + }); + groups.forEach(function (group) { + var someExported = false, allInherited = true, allPrivate = true, allProtected = true, allExternal = true; + group.children.forEach(function (child) { + someExported = child.flags.isExported || someExported; + allPrivate = child.flags.isPrivate && allPrivate; + allProtected = (child.flags.isPrivate || child.flags.isProtected) && allProtected; + allExternal = child.flags.isExternal && allExternal; + if (child instanceof index_1.DeclarationReflection) { + allInherited = child.inheritedFrom && allInherited; + } + else { + allInherited = false; + } + }); + group.someChildrenAreExported = someExported; + group.allChildrenAreInherited = allInherited; + group.allChildrenArePrivate = allPrivate; + group.allChildrenAreProtectedOrPrivate = allProtected; + group.allChildrenAreExternal = allExternal; + }); + return groups; + }; + GroupPlugin.getKindString = function (kind) { + var str = index_1.ReflectionKind[kind]; + str = str.replace(/(.)([A-Z])/g, function (m, a, b) { return a + ' ' + b.toLowerCase(); }); + return str; + }; + GroupPlugin.getKindSingular = function (kind) { + if (GroupPlugin.SINGULARS[kind]) { + return GroupPlugin.SINGULARS[kind]; + } + else { + return GroupPlugin.getKindString(kind); + } + }; + GroupPlugin.getKindPlural = function (kind) { + if (GroupPlugin.PLURALS[kind]) { + return GroupPlugin.PLURALS[kind]; + } + else { + return this.getKindString(kind) + 's'; + } + }; + GroupPlugin.sortCallback = function (a, b) { + var aWeight = GroupPlugin.WEIGHTS.indexOf(a.kind); + var bWeight = GroupPlugin.WEIGHTS.indexOf(b.kind); + if (aWeight == bWeight) { + if (a.flags.isStatic && !b.flags.isStatic) + return 1; + if (!a.flags.isStatic && b.flags.isStatic) + return -1; + if (a.name == b.name) + return 0; + return a.name > b.name ? 1 : -1; + } + else + return aWeight - bWeight; + }; + GroupPlugin.WEIGHTS = [ + index_1.ReflectionKind.Global, + index_1.ReflectionKind.ExternalModule, + index_1.ReflectionKind.Module, + index_1.ReflectionKind.Enum, + index_1.ReflectionKind.EnumMember, + index_1.ReflectionKind.Class, + index_1.ReflectionKind.Interface, + index_1.ReflectionKind.TypeAlias, + index_1.ReflectionKind.Constructor, + index_1.ReflectionKind.Event, + index_1.ReflectionKind.Property, + index_1.ReflectionKind.Variable, + index_1.ReflectionKind.Function, + index_1.ReflectionKind.Accessor, + index_1.ReflectionKind.Method, + index_1.ReflectionKind.ObjectLiteral, + index_1.ReflectionKind.Parameter, + index_1.ReflectionKind.TypeParameter, + index_1.ReflectionKind.TypeLiteral, + index_1.ReflectionKind.CallSignature, + index_1.ReflectionKind.ConstructorSignature, + index_1.ReflectionKind.IndexSignature, + index_1.ReflectionKind.GetSignature, + index_1.ReflectionKind.SetSignature, + ]; + GroupPlugin.SINGULARS = (function () { + var singulars = {}; + singulars[index_1.ReflectionKind.Enum] = 'Enumeration'; + singulars[index_1.ReflectionKind.EnumMember] = 'Enumeration member'; + return singulars; + })(); + GroupPlugin.PLURALS = (function () { + var plurals = {}; + plurals[index_1.ReflectionKind.Class] = 'Classes'; + plurals[index_1.ReflectionKind.Property] = 'Properties'; + plurals[index_1.ReflectionKind.Enum] = 'Enumerations'; + plurals[index_1.ReflectionKind.EnumMember] = 'Enumeration members'; + plurals[index_1.ReflectionKind.TypeAlias] = 'Type aliases'; + return plurals; + })(); + GroupPlugin = __decorate([ + components_1.Component({ name: 'group' }) + ], GroupPlugin); + return GroupPlugin; +}(components_1.ConverterComponent)); +exports.GroupPlugin = GroupPlugin; +//# sourceMappingURL=GroupPlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/GroupPlugin.js.map b/lib/converter/plugins/GroupPlugin.js.map new file mode 100644 index 000000000..29dca191d --- /dev/null +++ b/lib/converter/plugins/GroupPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"GroupPlugin.js","sourceRoot":"","sources":["../../../src/lib/converter/plugins/GroupPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sBAAqF,gCAAgC,CAAC,CAAA;AACtH,gCAA8B,8BAA8B,CAAC,CAAA;AAE7D,2BAA4C,eAAe,CAAC,CAAA;AAC5D,0BAAwB,cAAc,CAAC,CAAA;AAUvC;IAAiC,+BAAkB;IAAnD;QAAiC,8BAAkB;IAsOnD,CAAC;IAxKG,gCAAU,GAAV;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE;YACtB,GAAC,qBAAS,CAAC,aAAa,CAAC,GAAM,IAAI,CAAC,SAAS;YAC7C,GAAC,qBAAS,CAAC,iBAAiB,CAAC,GAAE,IAAI,CAAC,YAAY;;SACnD,CAAC,CAAC;;IACP,CAAC;IASO,+BAAS,GAAjB,UAAkB,OAAe,EAAE,UAAqB;QACpD,IAAI,UAAU,GAAG,UAAU,CAAC;QAC5B,UAAU,CAAC,UAAU,GAAG,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAErE,EAAE,CAAC,CAAC,UAAU,YAAY,2BAAmB,CAAC,CAAC,CAAC;YAC5C,IAAI,SAAS,GAAwB,UAAU,CAAC;YAChD,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;gBACtD,SAAS,CAAC,QAAQ,CAAC,IAAI,C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AAiC,+BAAkB,GAsOlD;AAtOY,mBAAW,cAsOvB,CAAA","sourcesContent":["import {Reflection, ReflectionKind, ContainerReflection, DeclarationReflection} from \"../../models/reflections/index\";\nimport {ReflectionGroup} from \"../../models/ReflectionGroup\";\nimport {SourceDirectory} from \"../../models/sources/directory\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\n\n\n/**\n * A handler that sorts and groups the found reflections in the resolving phase.\n *\n * The handler sets the ´groups´ property of all reflections.\n */\n@Component({name:'group'})\nexport class GroupPlugin extends ConverterComponent\n{\n /**\n * Define the sort order of reflections.\n */\n static WEIGHTS = [\n ReflectionKind.Global,\n ReflectionKind.ExternalModule,\n ReflectionKind.Module,\n ReflectionKind.Enum,\n ReflectionKind.EnumMember,\n ReflectionKind.Class,\n ReflectionKind.Interface,\n ReflectionKind.TypeAlias,\n\n ReflectionKind.Constructor,\n ReflectionKind.Event,\n ReflectionKind.Property,\n ReflectionKind.Variable,\n ReflectionKind.Function,\n ReflectionKind.Accessor,\n ReflectionKind.Method,\n ReflectionKind.ObjectLiteral,\n\n ReflectionKind.Parameter,\n ReflectionKind.TypeParameter,\n ReflectionKind.TypeLiteral,\n ReflectionKind.CallSignature,\n ReflectionKind.ConstructorSignature,\n ReflectionKind.IndexSignature,\n ReflectionKind.GetSignature,\n ReflectionKind.SetSignature,\n ];\n\n /**\n * Define the singular name of individual reflection kinds.\n */\n static SINGULARS = (function() {\n var singulars = {};\n singulars[ReflectionKind.Enum] = 'Enumeration';\n singulars[ReflectionKind.EnumMember] = 'Enumeration member';\n return singulars;\n })();\n\n /**\n * Define the plural name of individual reflection kinds.\n */\n static PLURALS = (function() {\n var plurals = {};\n plurals[ReflectionKind.Class] = 'Classes';\n plurals[ReflectionKind.Property] = 'Properties';\n plurals[ReflectionKind.Enum] = 'Enumerations';\n plurals[ReflectionKind.EnumMember] = 'Enumeration members';\n plurals[ReflectionKind.TypeAlias] = 'Type aliases';\n return plurals;\n })();\n\n\n\n /**\n * Create a new GroupPlugin instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [Converter.EVENT_RESOLVE]: this.onResolve,\n [Converter.EVENT_RESOLVE_END]: this.onEndResolve\n });\n }\n\n\n /**\n * Triggered when the converter resolves a reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently resolved.\n */\n private onResolve(context:Context, reflection:Reflection) {\n var reflection = reflection;\n reflection.kindString = GroupPlugin.getKindSingular(reflection.kind);\n\n if (reflection instanceof ContainerReflection) {\n var container = reflection;\n if (container.children && container.children.length > 0) {\n container.children.sort(GroupPlugin.sortCallback);\n container.groups = GroupPlugin.getReflectionGroups(container.children);\n }\n }\n }\n\n\n /**\n * Triggered when the converter has finished resolving a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onEndResolve(context:Context) {\n function walkDirectory(directory:SourceDirectory) {\n directory.groups = GroupPlugin.getReflectionGroups(directory.getAllReflections());\n\n for (var key in directory.directories) {\n if (!directory.directories.hasOwnProperty(key)) continue;\n walkDirectory(directory.directories[key]);\n }\n }\n\n var project = context.project;\n if (project.children && project.children.length > 0) {\n project.children.sort(GroupPlugin.sortCallback);\n project.groups = GroupPlugin.getReflectionGroups(project.children);\n }\n\n walkDirectory(project.directory);\n project.files.forEach((file) => {\n file.groups = GroupPlugin.getReflectionGroups(file.reflections);\n });\n }\n\n\n /**\n * Create a grouped representation of the given list of reflections.\n *\n * Reflections are grouped by kind and sorted by weight and name.\n *\n * @param reflections The reflections that should be grouped.\n * @returns An array containing all children of the given reflection grouped by their kind.\n */\n static getReflectionGroups(reflections:Reflection[]):ReflectionGroup[] {\n var groups:ReflectionGroup[] = [];\n reflections.forEach((child) => {\n for (var i = 0; i < groups.length; i++) {\n var group = groups[i];\n if (group.kind != child.kind) {\n continue;\n }\n\n group.children.push(child);\n return;\n }\n\n var group = new ReflectionGroup(GroupPlugin.getKindPlural(child.kind), child.kind);\n group.children.push(child);\n groups.push(group);\n });\n\n groups.forEach((group) => {\n var someExported = false, allInherited = true, allPrivate = true, allProtected = true, allExternal = true;\n group.children.forEach((child) => {\n someExported = child.flags.isExported || someExported;\n allPrivate = child.flags.isPrivate && allPrivate;\n allProtected = (child.flags.isPrivate || child.flags.isProtected) && allProtected;\n allExternal = child.flags.isExternal && allExternal;\n\n if (child instanceof DeclarationReflection) {\n allInherited = child.inheritedFrom && allInherited;\n } else {\n allInherited = false;\n }\n });\n\n group.someChildrenAreExported = someExported;\n group.allChildrenAreInherited = allInherited;\n group.allChildrenArePrivate = allPrivate;\n group.allChildrenAreProtectedOrPrivate = allProtected;\n group.allChildrenAreExternal = allExternal;\n });\n\n return groups;\n }\n\n\n /**\n * Transform the internal typescript kind identifier into a human readable version.\n *\n * @param kind The original typescript kind identifier.\n * @returns A human readable version of the given typescript kind identifier.\n */\n private static getKindString(kind:ReflectionKind):string {\n var str = ReflectionKind[kind];\n str = str.replace(/(.)([A-Z])/g, (m, a, b) => a + ' ' + b.toLowerCase());\n return str;\n }\n\n\n /**\n * Return the singular name of a internal typescript kind identifier.\n *\n * @param kind The original internal typescript kind identifier.\n * @returns The singular name of the given internal typescript kind identifier\n */\n static getKindSingular(kind:ReflectionKind):string {\n if (GroupPlugin.SINGULARS[kind]) {\n return GroupPlugin.SINGULARS[kind];\n } else {\n return GroupPlugin.getKindString(kind);\n }\n }\n\n\n /**\n * Return the plural name of a internal typescript kind identifier.\n *\n * @param kind The original internal typescript kind identifier.\n * @returns The plural name of the given internal typescript kind identifier\n */\n static getKindPlural(kind:ReflectionKind):string {\n if (GroupPlugin.PLURALS[kind]) {\n return GroupPlugin.PLURALS[kind];\n } else {\n return this.getKindString(kind) + 's';\n }\n }\n\n\n /**\n * Callback used to sort reflections by weight defined by ´GroupPlugin.WEIGHTS´ and name.\n *\n * @param a The left reflection to sort.\n * @param b The right reflection to sort.\n * @returns The sorting weight.\n */\n static sortCallback(a:Reflection, b:Reflection):number {\n var aWeight = GroupPlugin.WEIGHTS.indexOf(a.kind);\n var bWeight = GroupPlugin.WEIGHTS.indexOf(b.kind);\n if (aWeight == bWeight) {\n if (a.flags.isStatic && !b.flags.isStatic) return 1;\n if (!a.flags.isStatic && b.flags.isStatic) return -1;\n if (a.name == b.name) return 0;\n return a.name > b.name ? 1 : -1;\n } else return aWeight - bWeight;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/ImplementsPlugin.d.ts b/lib/converter/plugins/ImplementsPlugin.d.ts new file mode 100644 index 000000000..f2739cf23 --- /dev/null +++ b/lib/converter/plugins/ImplementsPlugin.d.ts @@ -0,0 +1,7 @@ +import { ConverterComponent } from "../components"; +export declare class ImplementsPlugin extends ConverterComponent { + initialize(): void; + private analyzeClass(context, classReflection, interfaceReflection); + private copyComment(target, source); + private onResolve(context, reflection); +} diff --git a/lib/converter/plugins/ImplementsPlugin.js b/lib/converter/plugins/ImplementsPlugin.js new file mode 100644 index 000000000..453d2830c --- /dev/null +++ b/lib/converter/plugins/ImplementsPlugin.js @@ -0,0 +1,96 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var index_1 = require("../../models/reflections/index"); +var index_2 = require("../../models/types/index"); +var components_1 = require("../components"); +var converter_1 = require("../converter"); +var ImplementsPlugin = (function (_super) { + __extends(ImplementsPlugin, _super); + function ImplementsPlugin() { + _super.apply(this, arguments); + } + ImplementsPlugin.prototype.initialize = function () { + this.listenTo(this.owner, converter_1.Converter.EVENT_RESOLVE, this.onResolve, -10); + }; + ImplementsPlugin.prototype.analyzeClass = function (context, classReflection, interfaceReflection) { + var _this = this; + if (!interfaceReflection.children) { + return; + } + interfaceReflection.children.forEach(function (interfaceMember) { + if (!(interfaceMember instanceof index_1.DeclarationReflection)) { + return; + } + var classMember; + for (var index = 0, count = classReflection.children.length; index < count; index++) { + var child = classReflection.children[index]; + if (child.name != interfaceMember.name) + continue; + if (child.flags.isStatic != interfaceMember.flags.isStatic) + continue; + classMember = child; + break; + } + if (!classMember) { + return; + } + var interfaceMemberName = interfaceReflection.name + '.' + interfaceMember.name; + classMember.implementationOf = new index_2.ReferenceType(interfaceMemberName, index_2.ReferenceType.SYMBOL_ID_RESOLVED, interfaceMember); + _this.copyComment(classMember, interfaceMember); + if (interfaceMember.kindOf(index_1.ReflectionKind.FunctionOrMethod) && interfaceMember.signatures && classMember.signatures) { + interfaceMember.signatures.forEach(function (interfaceSignature) { + var interfaceParameters = interfaceSignature.getParameterTypes(); + classMember.signatures.forEach(function (classSignature) { + if (index_2.Type.isTypeListEqual(interfaceParameters, classSignature.getParameterTypes())) { + classSignature.implementationOf = new index_2.ReferenceType(interfaceMemberName, index_2.ReferenceType.SYMBOL_ID_RESOLVED, interfaceSignature); + _this.copyComment(classSignature, interfaceSignature); + } + }); + }); + } + }); + }; + ImplementsPlugin.prototype.copyComment = function (target, source) { + if (target.comment && source.comment && target.comment.hasTag('inheritdoc')) { + target.comment.copyFrom(source.comment); + if (target instanceof index_1.SignatureReflection && target.parameters && + source instanceof index_1.SignatureReflection && source.parameters) { + for (var index = 0, count = target.parameters.length; index < count; index++) { + if (target.parameters[index].comment) { + target.parameters[index].comment.copyFrom(source.parameters[index].comment); + } + } + } + } + }; + ImplementsPlugin.prototype.onResolve = function (context, reflection) { + var _this = this; + if (reflection.kindOf(index_1.ReflectionKind.Class) && reflection.implementedTypes) { + reflection.implementedTypes.forEach(function (type) { + if (!(type instanceof index_2.ReferenceType)) { + return; + } + var source = type.reflection; + if (source && source.kindOf(index_1.ReflectionKind.Interface)) { + _this.analyzeClass(context, reflection, source); + } + }); + } + }; + ImplementsPlugin = __decorate([ + components_1.Component({ name: 'implements' }) + ], ImplementsPlugin); + return ImplementsPlugin; +}(components_1.ConverterComponent)); +exports.ImplementsPlugin = ImplementsPlugin; +//# sourceMappingURL=ImplementsPlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/ImplementsPlugin.js.map b/lib/converter/plugins/ImplementsPlugin.js.map new file mode 100644 index 000000000..ce9bda531 --- /dev/null +++ b/lib/converter/plugins/ImplementsPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ImplementsPlugin.js","sourceRoot":"","sources":["../../../src/lib/converter/plugins/ImplementsPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sBAAqF,gCAAgC,CAAC,CAAA;AACtH,sBAAkC,0BAA0B,CAAC,CAAA;AAC7D,2BAA4C,eAAe,CAAC,CAAA;AAC5D,0BAAwB,cAAc,CAAC,CAAA;AASvC;IAAsC,oCAAkB;IAAxD;QAAsC,8BAAkB;IAsGxD,CAAC;IAjGG,qCAAU,GAAV;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,qBAAS,CAAC,aAAa,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;IAUO,uCAAY,GAApB,UAAqB,OAAe,EAAE,eAAqC,EAAE,mBAAyC;QAAtH,iBAwCC;QAvCG,EAAE,CAAC,CAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC;YAChC,MAAM,CAAC;QACX,CAAC;QAED,mBAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAC,eAAqC;YACvE,EAAE,CAAC,CAAC,CAAC,CAAC,eAAe,YAAY,6BAAqB,CAAC,CAAC,CAAC,CAAC;gBACtD,MAAM,CAAC;Y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EAAE,UAAgC;QAAnE,iBAaC;QAZG,EAAE,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,sBAAc,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC;YACzE,UAAU,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAC,IAAS;gBAC1C,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,qBAAa,CAAC,CAAC,CAAC,CAAC;oBACnC,MAAM,CAAC;gBACX,CAAC;gBAED,IAAI,MAAM,GAA0C,IAAK,CAAC,UAAU,CAAC;gBACrE,EAAE,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,sBAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;oBACpD,KAAI,CAAC,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;gBACnD,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAtGL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,YAAY,EAAC,CAAC;wBAAA;IAuG/B,uBAAC;AAAD,CAAC,AAtGD,CAAsC,+BAAkB,GAsGvD;AAtGY,wBAAgB,mBAsG5B,CAAA","sourcesContent":["import {Reflection, ReflectionKind, DeclarationReflection, SignatureReflection} from \"../../models/reflections/index\";\nimport {Type, ReferenceType} from \"../../models/types/index\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\n\n\n/**\n * A plugin that detects interface implementations of functions and\n * properties on classes and links them.\n */\n@Component({name:'implements'})\nexport class ImplementsPlugin extends ConverterComponent\n{\n /**\n * Create a new ImplementsPlugin instance.\n */\n initialize() {\n this.listenTo(this.owner, Converter.EVENT_RESOLVE, this.onResolve, -10);\n }\n\n\n /**\n * Mark all members of the given class to be the implementation of the matching interface member.\n *\n * @param context The context object describing the current state the converter is in.\n * @param classReflection The reflection of the classReflection class.\n * @param interfaceReflection The reflection of the interfaceReflection interface.\n */\n private analyzeClass(context:Context, classReflection:DeclarationReflection, interfaceReflection:DeclarationReflection) {\n if (!interfaceReflection.children) {\n return;\n }\n\n interfaceReflection.children.forEach((interfaceMember:DeclarationReflection) => {\n if (!(interfaceMember instanceof DeclarationReflection)) {\n return;\n }\n\n var classMember:DeclarationReflection;\n for (var index = 0, count = classReflection.children.length; index < count; index++) {\n var child = classReflection.children[index];\n if (child.name != interfaceMember.name) continue;\n if (child.flags.isStatic != interfaceMember.flags.isStatic) continue;\n\n classMember = child;\n break;\n }\n\n if (!classMember) {\n return;\n }\n\n var interfaceMemberName = interfaceReflection.name + '.' + interfaceMember.name;\n classMember.implementationOf = new ReferenceType(interfaceMemberName, ReferenceType.SYMBOL_ID_RESOLVED, interfaceMember);\n this.copyComment(classMember, interfaceMember);\n\n if (interfaceMember.kindOf(ReflectionKind.FunctionOrMethod) && interfaceMember.signatures && classMember.signatures) {\n interfaceMember.signatures.forEach((interfaceSignature:SignatureReflection) => {\n var interfaceParameters = interfaceSignature.getParameterTypes();\n classMember.signatures.forEach((classSignature:SignatureReflection) => {\n if (Type.isTypeListEqual(interfaceParameters, classSignature.getParameterTypes())) {\n classSignature.implementationOf = new ReferenceType(interfaceMemberName, ReferenceType.SYMBOL_ID_RESOLVED, interfaceSignature);\n this.copyComment(classSignature, interfaceSignature);\n }\n });\n });\n }\n });\n }\n\n\n /**\n * Copy the comment of the source reflection to the target reflection.\n *\n * @param target\n * @param source\n */\n private copyComment(target:Reflection, source:Reflection) {\n if (target.comment && source.comment && target.comment.hasTag('inheritdoc')) {\n target.comment.copyFrom(source.comment);\n\n if (target instanceof SignatureReflection && target.parameters &&\n source instanceof SignatureReflection && source.parameters) {\n for (var index = 0, count = target.parameters.length; index < count; index++) {\n if (target.parameters[index].comment) {\n target.parameters[index].comment.copyFrom(source.parameters[index].comment);\n }\n }\n }\n }\n }\n\n\n /**\n * Triggered when the converter resolves a reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently resolved.\n */\n private onResolve(context:Context, reflection:DeclarationReflection) {\n if (reflection.kindOf(ReflectionKind.Class) && reflection.implementedTypes) {\n reflection.implementedTypes.forEach((type:Type) => {\n if (!(type instanceof ReferenceType)) {\n return;\n }\n\n var source = (type).reflection;\n if (source && source.kindOf(ReflectionKind.Interface)) {\n this.analyzeClass(context, reflection, source);\n }\n });\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/PackagePlugin.d.ts b/lib/converter/plugins/PackagePlugin.d.ts new file mode 100644 index 000000000..517c79139 --- /dev/null +++ b/lib/converter/plugins/PackagePlugin.d.ts @@ -0,0 +1,12 @@ +import { ConverterComponent } from "../components"; +export declare class PackagePlugin extends ConverterComponent { + readme: string; + private readmeFile; + private packageFile; + private visited; + private noReadmeFile; + initialize(): void; + private onBegin(context); + private onBeginDocument(context, reflection, node?); + private onBeginResolve(context); +} diff --git a/lib/converter/plugins/PackagePlugin.js b/lib/converter/plugins/PackagePlugin.js new file mode 100644 index 000000000..b7c9f80ed --- /dev/null +++ b/lib/converter/plugins/PackagePlugin.js @@ -0,0 +1,96 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var Path = require("path"); +var FS = require("fs"); +var components_1 = require("../components"); +var converter_1 = require("../converter"); +var component_1 = require("../../utils/component"); +var PackagePlugin = (function (_super) { + __extends(PackagePlugin, _super); + function PackagePlugin() { + _super.apply(this, arguments); + } + PackagePlugin.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[converter_1.Converter.EVENT_BEGIN] = this.onBegin, + _a[converter_1.Converter.EVENT_FILE_BEGIN] = this.onBeginDocument, + _a[converter_1.Converter.EVENT_RESOLVE_BEGIN] = this.onBeginResolve, + _a + )); + var _a; + }; + PackagePlugin.prototype.onBegin = function (context) { + this.readmeFile = null; + this.packageFile = null; + this.visited = []; + var readme = this.readme; + this.noReadmeFile = (readme == 'none'); + if (!this.noReadmeFile && readme) { + readme = Path.resolve(readme); + if (FS.existsSync(readme)) { + this.readmeFile = readme; + } + } + }; + PackagePlugin.prototype.onBeginDocument = function (context, reflection, node) { + var _this = this; + if (!node) + return; + if (this.readmeFile && this.packageFile) { + return; + } + var fileName = node.fileName; + var dirName, parentDir = Path.resolve(Path.dirname(fileName)); + do { + dirName = parentDir; + if (this.visited.indexOf(dirName) != -1) { + break; + } + FS.readdirSync(dirName).forEach(function (file) { + var lfile = file.toLowerCase(); + if (!_this.noReadmeFile && !_this.readmeFile && lfile == 'readme.md') { + _this.readmeFile = Path.join(dirName, file); + } + if (!_this.packageFile && lfile == 'package.json') { + _this.packageFile = Path.join(dirName, file); + } + }); + this.visited.push(dirName); + parentDir = Path.resolve(Path.join(dirName, '..')); + } while (dirName != parentDir); + }; + PackagePlugin.prototype.onBeginResolve = function (context) { + var project = context.project; + if (this.readmeFile) { + project.readme = FS.readFileSync(this.readmeFile, 'utf-8'); + } + if (this.packageFile) { + project.packageInfo = JSON.parse(FS.readFileSync(this.packageFile, 'utf-8')); + if (!project.name) { + project.name = project.packageInfo.name; + } + } + }; + __decorate([ + component_1.Option({ + name: 'readme', + help: 'Path to the readme file that should be displayed on the index page. Pass `none` to disable the index page and start the documentation on the globals page.' + }) + ], PackagePlugin.prototype, "readme", void 0); + PackagePlugin = __decorate([ + components_1.Component({ name: 'package' }) + ], PackagePlugin); + return PackagePlugin; +}(components_1.ConverterComponent)); +exports.PackagePlugin = PackagePlugin; +//# sourceMappingURL=PackagePlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/PackagePlugin.js.map b/lib/converter/plugins/PackagePlugin.js.map new file mode 100644 index 000000000..12279bffb --- /dev/null +++ b/lib/converter/plugins/PackagePlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"PackagePlugin.js","sourceRoot":"","sources":["../../../src/lib/converter/plugins/PackagePlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAC7B,IAAY,EAAE,WAAM,IAAI,CAAC,CAAA;AAIzB,2BAA4C,eAAe,CAAC,CAAA;AAC5D,0BAAwB,cAAc,CAAC,CAAA;AAEvC,0BAAqB,uBAAuB,CAAC,CAAA;AAY7C;IAAmC,iCAAkB;IAArD;QAAmC,8BAAkB;IAsHrD,CAAC;IAtFG,kCAAU,GAAV;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE;YACtB,GAAC,qBAAS,CAAC,WAAW,CAAC,GAAU,IAAI,CAAC,OAAO;YAC7C,GAAC,qBAAS,CAAC,gBAAgB,CAAC,GAAK,IAAI,CAAC,eAAe;YACrD,GAAC,qBAAS,CAAC,mBAAmB,CAAC,GAAE,IAAI,CAAC,cAAc;;SACvD,CAAC,CAAC;;IACP,CAAC;IAQO,+BAAO,GAAf,UAAgB,OAAe;QAC3B,IAAI,CAAC,UAAU,GAAI,IAAI,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,OAAO,GAAO,EAAE,CAAC;QAEtB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,CAAC;QACvC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC;YAC/B,M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\"path\";\nimport * as FS from \"fs\";\nimport * as ts from \"typescript\";\n\nimport {Reflection} from \"../../models/reflections/abstract\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\nimport {Option} from \"../../utils/component\";\n\n\n/**\n * A handler that tries to find the package.json and readme.md files of the\n * current project.\n *\n * The handler traverses the file tree upwards for each file processed by the processor\n * and records the nearest package info files it can find. Within the resolve files, the\n * contents of the found files will be read and appended to the ProjectReflection.\n */\n@Component({name:'package'})\nexport class PackagePlugin extends ConverterComponent\n{\n @Option({\n name: 'readme',\n help: 'Path to the readme file that should be displayed on the index page. Pass `none` to disable the index page and start the documentation on the globals page.'\n })\n readme:string;\n\n /**\n * The file name of the found readme.md file.\n */\n private readmeFile:string;\n\n /**\n * The file name of the found package.json file.\n */\n private packageFile:string;\n\n /**\n * List of directories the handler already inspected.\n */\n private visited:string[];\n\n /**\n * Should the readme file be ignored?\n */\n private noReadmeFile:boolean;\n\n\n /**\n * Create a new PackageHandler instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [Converter.EVENT_BEGIN]: this.onBegin,\n [Converter.EVENT_FILE_BEGIN]: this.onBeginDocument,\n [Converter.EVENT_RESOLVE_BEGIN]: this.onBeginResolve\n });\n }\n\n\n /**\n * Triggered when the converter begins converting a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onBegin(context:Context) {\n this.readmeFile = null;\n this.packageFile = null;\n this.visited = [];\n\n var readme = this.readme;\n this.noReadmeFile = (readme == 'none');\n if (!this.noReadmeFile && readme) {\n readme = Path.resolve(readme);\n if (FS.existsSync(readme)) {\n this.readmeFile = readme;\n }\n }\n }\n\n\n /**\n * Triggered when the converter begins converting a source file.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently processed.\n * @param node The node that is currently processed if available.\n */\n private onBeginDocument(context:Context, reflection:Reflection, node?:ts.SourceFile) {\n if (!node) return;\n if (this.readmeFile && this.packageFile) {\n return;\n }\n\n var fileName = node.fileName;\n var dirName:string, parentDir = Path.resolve(Path.dirname(fileName));\n do {\n dirName = parentDir;\n if (this.visited.indexOf(dirName) != -1) {\n break;\n }\n\n FS.readdirSync(dirName).forEach((file) => {\n var lfile = file.toLowerCase();\n if (!this.noReadmeFile && !this.readmeFile && lfile == 'readme.md') {\n this.readmeFile = Path.join(dirName, file);\n }\n\n if (!this.packageFile && lfile == 'package.json') {\n this.packageFile = Path.join(dirName, file);\n }\n });\n\n this.visited.push(dirName);\n parentDir = Path.resolve(Path.join(dirName, '..'));\n } while (dirName != parentDir);\n }\n\n\n /**\n * Triggered when the converter begins resolving a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onBeginResolve(context:Context) {\n var project = context.project;\n if (this.readmeFile) {\n project.readme = FS.readFileSync(this.readmeFile, 'utf-8');\n }\n\n if (this.packageFile) {\n project.packageInfo = JSON.parse(FS.readFileSync(this.packageFile, 'utf-8'));\n if (!project.name) {\n project.name = project.packageInfo.name;\n }\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/SourcePlugin.d.ts b/lib/converter/plugins/SourcePlugin.d.ts new file mode 100644 index 000000000..2f00e8420 --- /dev/null +++ b/lib/converter/plugins/SourcePlugin.d.ts @@ -0,0 +1,13 @@ +import { ConverterComponent } from "../components"; +export declare class SourcePlugin extends ConverterComponent { + private basePath; + private fileMappings; + initialize(): void; + private getSourceFile(fileName, project); + private onBegin(); + private onBeginDocument(context, reflection, node?); + private onDeclaration(context, reflection, node?); + private onBeginResolve(context); + private onResolve(context, reflection); + private onEndResolve(context); +} diff --git a/lib/converter/plugins/SourcePlugin.js b/lib/converter/plugins/SourcePlugin.js new file mode 100644 index 000000000..ded275d4e --- /dev/null +++ b/lib/converter/plugins/SourcePlugin.js @@ -0,0 +1,128 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var Path = require("path"); +var ts = require("typescript"); +var index_1 = require("../../models/reflections/index"); +var index_2 = require("../../models/sources/index"); +var components_1 = require("../components"); +var base_path_1 = require("../utils/base-path"); +var converter_1 = require("../converter"); +var SourcePlugin = (function (_super) { + __extends(SourcePlugin, _super); + function SourcePlugin() { + _super.apply(this, arguments); + this.basePath = new base_path_1.BasePath(); + this.fileMappings = {}; + } + SourcePlugin.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[converter_1.Converter.EVENT_BEGIN] = this.onBegin, + _a[converter_1.Converter.EVENT_FILE_BEGIN] = this.onBeginDocument, + _a[converter_1.Converter.EVENT_CREATE_DECLARATION] = this.onDeclaration, + _a[converter_1.Converter.EVENT_CREATE_SIGNATURE] = this.onDeclaration, + _a[converter_1.Converter.EVENT_RESOLVE_BEGIN] = this.onBeginResolve, + _a[converter_1.Converter.EVENT_RESOLVE] = this.onResolve, + _a[converter_1.Converter.EVENT_RESOLVE_END] = this.onEndResolve, + _a + )); + var _a; + }; + SourcePlugin.prototype.getSourceFile = function (fileName, project) { + if (!this.fileMappings[fileName]) { + var file = new index_2.SourceFile(fileName); + this.fileMappings[fileName] = file; + project.files.push(file); + } + return this.fileMappings[fileName]; + }; + SourcePlugin.prototype.onBegin = function () { + this.basePath.reset(); + this.fileMappings = {}; + }; + SourcePlugin.prototype.onBeginDocument = function (context, reflection, node) { + if (!node) + return; + var fileName = node.fileName; + this.basePath.add(fileName); + this.getSourceFile(fileName, context.project); + }; + SourcePlugin.prototype.onDeclaration = function (context, reflection, node) { + if (!node) + return; + var sourceFile = ts.getSourceFileOfNode(node); + var fileName = sourceFile.fileName; + var file = this.getSourceFile(fileName, context.project); + var position; + if (node['name'] && node['name'].end) { + position = ts.getLineAndCharacterOfPosition(sourceFile, node['name'].end); + } + else { + position = ts.getLineAndCharacterOfPosition(sourceFile, node.pos); + } + if (!reflection.sources) + reflection.sources = []; + if (reflection instanceof index_1.DeclarationReflection) { + file.reflections.push(reflection); + } + reflection.sources.push({ + file: file, + fileName: fileName, + line: position.line + 1, + character: position.character + }); + }; + SourcePlugin.prototype.onBeginResolve = function (context) { + var _this = this; + context.project.files.forEach(function (file) { + var fileName = file.fileName = _this.basePath.trim(file.fileName); + _this.fileMappings[fileName] = file; + }); + }; + SourcePlugin.prototype.onResolve = function (context, reflection) { + var _this = this; + if (!reflection.sources) + return; + reflection.sources.forEach(function (source) { + source.fileName = _this.basePath.trim(source.fileName); + }); + }; + SourcePlugin.prototype.onEndResolve = function (context) { + var project = context.project; + var home = project.directory; + project.files.forEach(function (file) { + var reflections = []; + file.reflections.forEach(function (reflection) { + reflections.push(reflection); + }); + var directory = home; + var path = Path.dirname(file.fileName); + if (path != '.') { + path.split('/').forEach(function (path) { + if (!directory.directories[path]) { + directory.directories[path] = new index_2.SourceDirectory(path, directory); + } + directory = directory.directories[path]; + }); + } + directory.files.push(file); + file.parent = directory; + file.reflections = reflections; + }); + }; + SourcePlugin = __decorate([ + components_1.Component({ name: 'source' }) + ], SourcePlugin); + return SourcePlugin; +}(components_1.ConverterComponent)); +exports.SourcePlugin = SourcePlugin; +//# sourceMappingURL=SourcePlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/SourcePlugin.js.map b/lib/converter/plugins/SourcePlugin.js.map new file mode 100644 index 000000000..f88c94baa --- /dev/null +++ b/lib/converter/plugins/SourcePlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"SourcePlugin.js","sourceRoot":"","sources":["../../../src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nimport {Reflection, ProjectReflection, DeclarationReflection} from \"../../models/reflections/index\";\nimport {SourceDirectory, SourceFile} from \"../../models/sources/index\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {BasePath} from \"../utils/base-path\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\n\n\n/**\n * A handler that attaches source file information to reflections.\n */\n@Component({name:'source'})\nexport class SourcePlugin extends ConverterComponent\n{\n /**\n * Helper for resolving the base path of all source files.\n */\n private basePath = new BasePath();\n\n /**\n * A map of all generated [[SourceFile]] instances.\n */\n private fileMappings:{[name:string]:SourceFile} = {};\n\n\n /**\n * Create a new SourceHandler instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [Converter.EVENT_BEGIN]: this.onBegin,\n [Converter.EVENT_FILE_BEGIN]: this.onBeginDocument,\n [Converter.EVENT_CREATE_DECLARATION]: this.onDeclaration,\n [Converter.EVENT_CREATE_SIGNATURE]: this.onDeclaration,\n [Converter.EVENT_RESOLVE_BEGIN]: this.onBeginResolve,\n [Converter.EVENT_RESOLVE]: this.onResolve,\n [Converter.EVENT_RESOLVE_END]: this.onEndResolve\n });\n }\n\n\n private getSourceFile(fileName:string, project:ProjectReflection):SourceFile {\n if (!this.fileMappings[fileName]) {\n var file = new SourceFile(fileName);\n this.fileMappings[fileName] = file;\n project.files.push(file);\n }\n\n return this.fileMappings[fileName];\n }\n\n\n /**\n * Triggered once per project before the dispatcher invokes the compiler.\n *\n * @param event An event object containing the related project and compiler instance.\n */\n private onBegin() {\n this.basePath.reset();\n this.fileMappings = {};\n }\n\n\n /**\n * Triggered when the converter begins converting a source file.\n *\n * Create a new [[SourceFile]] instance for all TypeScript files.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently processed.\n * @param node The node that is currently processed if available.\n */\n private onBeginDocument(context:Context, reflection:Reflection, node?:ts.SourceFile) {\n if (!node) return;\n var fileName = node.fileName;\n this.basePath.add(fileName);\n this.getSourceFile(fileName, context.project);\n }\n\n\n /**\n * Triggered when the converter has created a declaration reflection.\n *\n * Attach the current source file to the [[DeclarationReflection.sources]] array.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently processed.\n * @param node The node that is currently processed if available.\n */\n private onDeclaration(context:Context, reflection:Reflection, node?:ts.Node) {\n if (!node) return;\n var sourceFile = ts.getSourceFileOfNode(node);\n var fileName = sourceFile.fileName;\n var file:SourceFile = this.getSourceFile(fileName, context.project);\n\n var position:ts.LineAndCharacter;\n if (node['name'] && node['name'].end) {\n position = ts.getLineAndCharacterOfPosition(sourceFile, node['name'].end);\n } else {\n position = ts.getLineAndCharacterOfPosition(sourceFile, node.pos);\n }\n\n if (!reflection.sources) reflection.sources = [];\n if (reflection instanceof DeclarationReflection) {\n file.reflections.push(reflection);\n }\n\n reflection.sources.push({\n file: file,\n fileName: fileName,\n line: position.line + 1,\n character: position.character\n });\n }\n\n\n /**\n * Triggered when the converter begins resolving a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onBeginResolve(context:Context) {\n context.project.files.forEach((file) => {\n var fileName = file.fileName = this.basePath.trim(file.fileName);\n this.fileMappings[fileName] = file;\n });\n }\n\n\n /**\n * Triggered when the converter resolves a reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently resolved.\n */\n private onResolve(context:Context, reflection:Reflection) {\n if (!reflection.sources) return;\n reflection.sources.forEach((source) => {\n source.fileName = this.basePath.trim(source.fileName);\n });\n }\n\n\n /**\n * Triggered when the converter has finished resolving a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onEndResolve(context:Context) {\n var project = context.project;\n var home = project.directory;\n project.files.forEach((file) => {\n var reflections:Reflection[] = [];\n file.reflections.forEach((reflection) => {\n reflections.push(reflection);\n });\n\n var directory = home;\n var path = Path.dirname(file.fileName);\n if (path != '.') {\n path.split('/').forEach((path) => {\n if (!directory.directories[path]) {\n directory.directories[path] = new SourceDirectory(path, directory);\n }\n directory = directory.directories[path];\n });\n }\n\n directory.files.push(file);\n // reflections.sort(GroupHandler.sortCallback);\n file.parent = directory;\n file.reflections = reflections;\n });\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/TypePlugin.d.ts b/lib/converter/plugins/TypePlugin.d.ts new file mode 100644 index 000000000..731caf90a --- /dev/null +++ b/lib/converter/plugins/TypePlugin.d.ts @@ -0,0 +1,9 @@ +import { DeclarationReflection } from "../../models/reflections/index"; +import { ConverterComponent } from "../components"; +export declare class TypePlugin extends ConverterComponent { + reflections: DeclarationReflection[]; + initialize(): void; + private onResolve(context, reflection); + private postpone(reflection); + private onResolveEnd(context); +} diff --git a/lib/converter/plugins/TypePlugin.js b/lib/converter/plugins/TypePlugin.js new file mode 100644 index 000000000..d2cb029e7 --- /dev/null +++ b/lib/converter/plugins/TypePlugin.js @@ -0,0 +1,151 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var index_1 = require("../../models/reflections/index"); +var index_2 = require("../../models/types/index"); +var components_1 = require("../components"); +var converter_1 = require("../converter"); +var TypePlugin = (function (_super) { + __extends(TypePlugin, _super); + function TypePlugin() { + _super.apply(this, arguments); + this.reflections = []; + } + TypePlugin.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[converter_1.Converter.EVENT_RESOLVE] = this.onResolve, + _a[converter_1.Converter.EVENT_RESOLVE_END] = this.onResolveEnd, + _a + )); + var _a; + }; + TypePlugin.prototype.onResolve = function (context, reflection) { + var _this = this; + var project = context.project; + resolveType(reflection, reflection.type); + resolveType(reflection, reflection.inheritedFrom); + resolveType(reflection, reflection.overwrites); + resolveTypes(reflection, reflection.extendedTypes); + resolveTypes(reflection, reflection.extendedBy); + resolveTypes(reflection, reflection.implementedTypes); + if (reflection.decorators) + reflection.decorators.forEach(function (decorator) { + if (decorator.type) { + resolveType(reflection, decorator.type); + } + }); + if (reflection.kindOf(index_1.ReflectionKind.ClassOrInterface)) { + this.postpone(reflection); + walk(reflection.implementedTypes, function (target) { + _this.postpone(target); + if (!target.implementedBy) + target.implementedBy = []; + target.implementedBy.push(new index_2.ReferenceType(reflection.name, index_2.ReferenceType.SYMBOL_ID_RESOLVED, reflection)); + }); + walk(reflection.extendedTypes, function (target) { + _this.postpone(target); + if (!target.extendedBy) + target.extendedBy = []; + target.extendedBy.push(new index_2.ReferenceType(reflection.name, index_2.ReferenceType.SYMBOL_ID_RESOLVED, reflection)); + }); + } + function walk(types, callback) { + if (!types) + return; + types.forEach(function (type) { + if (!(type instanceof index_2.ReferenceType)) + return; + if (!type.reflection || !(type.reflection instanceof index_1.DeclarationReflection)) + return; + callback(type.reflection); + }); + } + function resolveTypes(reflection, types) { + if (!types) + return; + for (var i = 0, c = types.length; i < c; i++) { + resolveType(reflection, types[i]); + } + } + function resolveType(reflection, type) { + if (type instanceof index_2.ReferenceType) { + var referenceType = type; + if (referenceType.symbolID == index_2.ReferenceType.SYMBOL_ID_RESOLVE_BY_NAME) { + referenceType.reflection = reflection.findReflectionByName(referenceType.name); + } + else if (!referenceType.reflection && referenceType.symbolID != index_2.ReferenceType.SYMBOL_ID_RESOLVED) { + referenceType.reflection = project.reflections[project.symbolMapping[referenceType.symbolID]]; + } + if (referenceType.typeArguments) { + referenceType.typeArguments.forEach(function (typeArgument) { + resolveType(reflection, typeArgument); + }); + } + } + else if (type instanceof index_2.TupleType) { + var tupleType = type; + for (var index = 0, count = tupleType.elements.length; index < count; index++) { + resolveType(reflection, tupleType.elements[index]); + } + } + else if (type instanceof index_2.UnionType) { + var unionType = type; + for (var index = 0, count = unionType.types.length; index < count; index++) { + resolveType(reflection, unionType.types[index]); + } + } + } + }; + TypePlugin.prototype.postpone = function (reflection) { + if (this.reflections.indexOf(reflection) == -1) { + this.reflections.push(reflection); + } + }; + TypePlugin.prototype.onResolveEnd = function (context) { + this.reflections.forEach(function (reflection) { + if (reflection.implementedBy) { + reflection.implementedBy.sort(function (a, b) { + if (a['name'] == b['name']) + return 0; + return a['name'] > b['name'] ? 1 : -1; + }); + } + var root; + var hierarchy; + function push(types) { + var level = { types: types }; + if (hierarchy) { + hierarchy.next = level; + hierarchy = level; + } + else { + root = hierarchy = level; + } + } + if (reflection.extendedTypes) { + push(reflection.extendedTypes); + } + push([new index_2.ReferenceType(reflection.name, index_2.ReferenceType.SYMBOL_ID_RESOLVED, reflection)]); + hierarchy.isTarget = true; + if (reflection.extendedBy) { + push(reflection.extendedBy); + } + reflection.typeHierarchy = root; + }); + }; + TypePlugin = __decorate([ + components_1.Component({ name: 'type' }) + ], TypePlugin); + return TypePlugin; +}(components_1.ConverterComponent)); +exports.TypePlugin = TypePlugin; +//# sourceMappingURL=TypePlugin.js.map \ No newline at end of file diff --git a/lib/converter/plugins/TypePlugin.js.map b/lib/converter/plugins/TypePlugin.js.map new file mode 100644 index 000000000..30daa240f --- /dev/null +++ b/lib/converter/plugins/TypePlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"TypePlugin.js","sourceRoot":"","sources":["../../../src/lib/converter/plugins/TypePlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sBAAmG,gCAAgC,CAAC,CAAA;AACpI,sBAAwD,0BAA0B,CAAC,CAAA;AACnF,2BAA4C,eAAe,CAAC,CAAA;AAC5D,0BAAwB,cAAc,CAAC,CAAA;AAQvC;IAAgC,8BAAkB;IAAlD;QAAgC,8BAAkB;QAE9C,gBAAW,GAA2B,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YACP,CAAC;YAED,IAAI,IAA0B,CAAC;YAC/B,IAAI,SAA+B,CAAC;YACpC,cAAc,KAAY;gBACtB,IAAI,KAAK,GAAyB,EAAC,KAAK,EAAC,KAAK,EAAC,CAAC;gBAChD,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;oBACZ,SAAS,CAAC,IAAI,GAAG,KAAK,CAAC;oBACvB,SAAS,GAAG,KAAK,CAAC;gBACtB,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACJ,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC;gBAC7B,CAAC;YACL,CAAC;YAGD,EAAE,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC;gBAC3B,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;YACnC,CAAC;YAED,IAAI,CAAC,CAAC,IAAI,qBAAa,CAAC,UAAU,CAAC,IAAI,EAAE,qBAAa,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;YACzF,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC;YAE1B,EAAE,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;gBACxB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAChC,CAAC;YAED,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC;QACpC,CAAC,CAAC,CAAC;IACP,CAAC;IAnJL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,MAAM,EAAC,CAAC;kBAAA;IAoJzB,iBAAC;AAAD,CAAC,AAnJD,CAAgC,+BAAkB,GAmJjD;AAnJY,kBAAU,aAmJtB,CAAA","sourcesContent":["import {Reflection, ReflectionKind, IDecorator, DeclarationReflection, IDeclarationHierarchy} from \"../../models/reflections/index\";\nimport {Type, ReferenceType, TupleType, UnionType} from \"../../models/types/index\";\nimport {Component, ConverterComponent} from \"../components\";\nimport {Converter} from \"../converter\";\nimport {Context} from \"../context\";\n\n\n/**\n * A handler that converts all instances of [[LateResolvingType]] to their renderable equivalents.\n */\n@Component({name:'type'})\nexport class TypePlugin extends ConverterComponent\n{\n reflections:DeclarationReflection[] = [];\n\n\n /**\n * Create a new TypeHandler instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [Converter.EVENT_RESOLVE]: this.onResolve,\n [Converter.EVENT_RESOLVE_END]: this.onResolveEnd\n });\n }\n\n\n /**\n * Triggered when the converter resolves a reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param reflection The reflection that is currently resolved.\n */\n private onResolve(context:Context, reflection:DeclarationReflection) {\n var project = context.project;\n\n resolveType(reflection, reflection.type);\n resolveType(reflection, reflection.inheritedFrom);\n resolveType(reflection, reflection.overwrites);\n resolveTypes(reflection, reflection.extendedTypes);\n resolveTypes(reflection, reflection.extendedBy);\n resolveTypes(reflection, reflection.implementedTypes);\n\n if (reflection.decorators) reflection.decorators.forEach((decorator:IDecorator) => {\n if (decorator.type) {\n resolveType(reflection, decorator.type);\n }\n });\n\n if (reflection.kindOf(ReflectionKind.ClassOrInterface)) {\n this.postpone(reflection);\n\n walk(reflection.implementedTypes, (target) => {\n this.postpone(target);\n if (!target.implementedBy) target.implementedBy = [];\n target.implementedBy.push(new ReferenceType(reflection.name, ReferenceType.SYMBOL_ID_RESOLVED, reflection));\n });\n\n walk(reflection.extendedTypes, (target) => {\n this.postpone(target);\n if (!target.extendedBy) target.extendedBy = [];\n target.extendedBy.push(new ReferenceType(reflection.name, ReferenceType.SYMBOL_ID_RESOLVED, reflection));\n });\n }\n\n function walk(types:Type[], callback:{(declaration:DeclarationReflection):void}) {\n if (!types) return;\n types.forEach((type:ReferenceType) => {\n if (!(type instanceof ReferenceType)) return;\n if (!type.reflection || !(type.reflection instanceof DeclarationReflection)) return;\n callback(type.reflection);\n });\n }\n\n function resolveTypes(reflection:Reflection, types:Type[]) {\n if (!types) return;\n for (var i = 0, c = types.length; i < c; i++) {\n resolveType(reflection, types[i]);\n }\n }\n\n function resolveType(reflection:Reflection, type:Type) {\n if (type instanceof ReferenceType) {\n var referenceType:ReferenceType = type;\n if (referenceType.symbolID == ReferenceType.SYMBOL_ID_RESOLVE_BY_NAME) {\n referenceType.reflection = reflection.findReflectionByName(referenceType.name);\n } else if (!referenceType.reflection && referenceType.symbolID != ReferenceType.SYMBOL_ID_RESOLVED) {\n referenceType.reflection = project.reflections[project.symbolMapping[referenceType.symbolID]];\n }\n\n if (referenceType.typeArguments) {\n referenceType.typeArguments.forEach((typeArgument:Type) => {\n resolveType(reflection, typeArgument);\n });\n }\n } else if (type instanceof TupleType) {\n var tupleType:TupleType = type;\n for (var index = 0, count = tupleType.elements.length; index < count; index++) {\n resolveType(reflection, tupleType.elements[index]);\n }\n } else if (type instanceof UnionType) {\n var unionType:UnionType = type;\n for (var index = 0, count = unionType.types.length; index < count; index++) {\n resolveType(reflection, unionType.types[index]);\n }\n }\n }\n }\n\n\n private postpone(reflection:DeclarationReflection) {\n if (this.reflections.indexOf(reflection) == -1) {\n this.reflections.push(reflection);\n }\n }\n\n\n /**\n * Triggered when the converter has finished resolving a project.\n *\n * @param context The context object describing the current state the converter is in.\n */\n private onResolveEnd(context:Context) {\n this.reflections.forEach((reflection) => {\n if (reflection.implementedBy) {\n reflection.implementedBy.sort((a:Type, b:Type):number => {\n if (a['name'] == b['name']) return 0;\n return a['name'] > b['name'] ? 1 : -1;\n });\n }\n\n var root:IDeclarationHierarchy;\n var hierarchy:IDeclarationHierarchy;\n function push(types:Type[]) {\n var level:IDeclarationHierarchy = {types:types};\n if (hierarchy) {\n hierarchy.next = level;\n hierarchy = level;\n } else {\n root = hierarchy = level;\n }\n }\n\n\n if (reflection.extendedTypes) {\n push(reflection.extendedTypes);\n }\n\n push([new ReferenceType(reflection.name, ReferenceType.SYMBOL_ID_RESOLVED, reflection)]);\n hierarchy.isTarget = true;\n\n if (reflection.extendedBy) {\n push(reflection.extendedBy);\n }\n\n reflection.typeHierarchy = root;\n });\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/plugins/index.d.ts b/lib/converter/plugins/index.d.ts new file mode 100644 index 000000000..224d51998 --- /dev/null +++ b/lib/converter/plugins/index.d.ts @@ -0,0 +1,10 @@ +export { CommentPlugin } from "./CommentPlugin"; +export { DecoratorPlugin } from "./DecoratorPlugin"; +export { DeepCommentPlugin } from "./DeepCommentPlugin"; +export { DynamicModulePlugin } from "./DynamicModulePlugin"; +export { GitHubPlugin } from "./GitHubPlugin"; +export { GroupPlugin } from "./GroupPlugin"; +export { ImplementsPlugin } from "./ImplementsPlugin"; +export { PackagePlugin } from "./PackagePlugin"; +export { SourcePlugin } from "./SourcePlugin"; +export { TypePlugin } from "./TypePlugin"; diff --git a/lib/converter/plugins/index.js b/lib/converter/plugins/index.js new file mode 100644 index 000000000..1cc0f04e4 --- /dev/null +++ b/lib/converter/plugins/index.js @@ -0,0 +1,22 @@ +"use strict"; +var CommentPlugin_1 = require("./CommentPlugin"); +exports.CommentPlugin = CommentPlugin_1.CommentPlugin; +var DecoratorPlugin_1 = require("./DecoratorPlugin"); +exports.DecoratorPlugin = DecoratorPlugin_1.DecoratorPlugin; +var DeepCommentPlugin_1 = require("./DeepCommentPlugin"); +exports.DeepCommentPlugin = DeepCommentPlugin_1.DeepCommentPlugin; +var DynamicModulePlugin_1 = require("./DynamicModulePlugin"); +exports.DynamicModulePlugin = DynamicModulePlugin_1.DynamicModulePlugin; +var GitHubPlugin_1 = require("./GitHubPlugin"); +exports.GitHubPlugin = GitHubPlugin_1.GitHubPlugin; +var GroupPlugin_1 = require("./GroupPlugin"); +exports.GroupPlugin = GroupPlugin_1.GroupPlugin; +var ImplementsPlugin_1 = require("./ImplementsPlugin"); +exports.ImplementsPlugin = ImplementsPlugin_1.ImplementsPlugin; +var PackagePlugin_1 = require("./PackagePlugin"); +exports.PackagePlugin = PackagePlugin_1.PackagePlugin; +var SourcePlugin_1 = require("./SourcePlugin"); +exports.SourcePlugin = SourcePlugin_1.SourcePlugin; +var TypePlugin_1 = require("./TypePlugin"); +exports.TypePlugin = TypePlugin_1.TypePlugin; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/converter/plugins/index.js.map b/lib/converter/plugins/index.js.map new file mode 100644 index 000000000..b19cfc89f --- /dev/null +++ b/lib/converter/plugins/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/converter/plugins/index.ts"],"names":[],"mappings":";AAAA,8BAA4B,iBAAiB,CAAC;AAAtC,sDAAsC;AAC9C,gCAA8B,mBAAmB,CAAC;AAA1C,4DAA0C;AAClD,kCAAgC,qBAAqB,CAAC;AAA9C,kEAA8C;AACtD,oCAAkC,uBAAuB,CAAC;AAAlD,wEAAkD;AAC1D,6BAA2B,gBAAgB,CAAC;AAApC,mDAAoC;AAC5C,4BAA0B,eAAe,CAAC;AAAlC,gDAAkC;AAC1C,iCAA+B,oBAAoB,CAAC;AAA5C,+DAA4C;AACpD,8BAA4B,iBAAiB,CAAC;AAAtC,sDAAsC;AAC9C,6BAA2B,gBAAgB,CAAC;AAApC,mDAAoC;AAC5C,2BAAyB,cAAc,CAAC;AAAhC,6CAAgC","sourcesContent":["export {CommentPlugin} from \"./CommentPlugin\";\nexport {DecoratorPlugin} from \"./DecoratorPlugin\";\nexport {DeepCommentPlugin} from \"./DeepCommentPlugin\";\nexport {DynamicModulePlugin} from \"./DynamicModulePlugin\";\nexport {GitHubPlugin} from \"./GitHubPlugin\";\nexport {GroupPlugin} from \"./GroupPlugin\";\nexport {ImplementsPlugin} from \"./ImplementsPlugin\";\nexport {PackagePlugin} from \"./PackagePlugin\";\nexport {SourcePlugin} from \"./SourcePlugin\";\nexport {TypePlugin} from \"./TypePlugin\";\n"]} \ No newline at end of file diff --git a/lib/converter/types/alias.d.ts b/lib/converter/types/alias.d.ts new file mode 100644 index 000000000..3aa861815 --- /dev/null +++ b/lib/converter/types/alias.d.ts @@ -0,0 +1,9 @@ +import * as ts from "typescript"; +import { ReferenceType } from "../../models/index"; +import { ConverterTypeComponent, ITypeNodeConverter } from "../components"; +import { Context } from "../context"; +export declare class AliasConverter extends ConverterTypeComponent implements ITypeNodeConverter { + priority: number; + supportsNode(context: Context, node: ts.TypeReferenceNode, type: ts.Type): boolean; + convertNode(context: Context, node: ts.TypeReferenceNode): ReferenceType; +} diff --git a/lib/converter/types/alias.js b/lib/converter/types/alias.js new file mode 100644 index 000000000..ab8f7ac9d --- /dev/null +++ b/lib/converter/types/alias.js @@ -0,0 +1,51 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var components_1 = require("../components"); +var AliasConverter = (function (_super) { + __extends(AliasConverter, _super); + function AliasConverter() { + _super.apply(this, arguments); + this.priority = 100; + } + AliasConverter.prototype.supportsNode = function (context, node, type) { + if (!type || !node || !node.typeName) + return false; + if (!type.symbol) + return true; + var checker = context.checker; + var symbolName = checker.getFullyQualifiedName(type.symbol).split('.'); + if (!symbolName.length) + return false; + if (symbolName[0].substr(0, 1) == '"') + symbolName.shift(); + var nodeName = ts.getTextOfNode(node.typeName).split('.'); + if (!nodeName.length) + return false; + var common = Math.min(symbolName.length, nodeName.length); + symbolName = symbolName.slice(-common); + nodeName = nodeName.slice(-common); + return nodeName.join('.') != symbolName.join('.'); + }; + AliasConverter.prototype.convertNode = function (context, node) { + var name = ts.getTextOfNode(node.typeName); + return new index_1.ReferenceType(name, index_1.ReferenceType.SYMBOL_ID_RESOLVE_BY_NAME); + }; + AliasConverter = __decorate([ + components_1.Component({ name: 'type:alias' }) + ], AliasConverter); + return AliasConverter; +}(components_1.ConverterTypeComponent)); +exports.AliasConverter = AliasConverter; +//# sourceMappingURL=alias.js.map \ No newline at end of file diff --git a/lib/converter/types/alias.js.map b/lib/converter/types/alias.js.map new file mode 100644 index 000000000..d772ffd59 --- /dev/null +++ b/lib/converter/types/alias.js.map @@ -0,0 +1 @@ +{"version":3,"file":"alias.js","sourceRoot":"","sources":["../../../src/lib/converter/types/alias.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAA4B,oBAAoB,CAAC,CAAA;AACjD,2BAAoE,eAAe,CAAC,CAAA;AAKpF;IAAoC,kCAAsB;IAA1D;QAAoC,8BAAsB;QAMtD,aAAQ,GAAU,GAAG,CAAC;IAwD1B,CAAC;IAxCG,qCAAY,GAAZ,UAAa,OAAe,EAAE,IAAyB,EAAE,IAAY;QACjE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAAC,MAAM,CAAC,KAAK,CAAC;QACnD,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;YAAC,MAAM,CAAC,IAAI,CAAC;QAE9B,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC9B,IAAI,UAAU,GAAG,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;YAAC,MAAM,CAAC,KAAK,CAAC;QACrC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC;YAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QAE1D,IAAI,QAAQ,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1D,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAC,MAAM,CAAC,KAAK,CAAC;QAEnC,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC1D,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;QACvC,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;QAEnC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtD,CAAC;IAmBD,oCAAW,GAAX,UAAY,OAAe,EAAE,IAAyB;QAClD,IAAI,IAAI,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3C,MAAM,CAAC,IAAI,qBAAa,CAAC,IAAI,EAAE,qBAAa,CAAC,yBAAyB,CAAC,CAAC;IAC5E,CAAC;IA9DL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,YAAY,EAAC,CAAC;sBAAA;IA+D/B,qBAAC;AAAD,CAAC,AA9DD,CAAoC,mCAAsB,GA8DzD;AA9DY,sBAAc,iBA8D1B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {ReferenceType} from \"../../models/index\";\nimport {Component, ConverterTypeComponent, ITypeNodeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:alias'})\nexport class AliasConverter extends ConverterTypeComponent implements ITypeNodeConverter\n{\n /**\n * The priority this converter should be executed with.\n * A higher priority means the converter will be applied earlier.\n */\n priority:number = 100;\n\n\n\n /**\n * Test whether the given node and type definitions represent a type alias.\n *\n * The compiler resolves type aliases pretty early and there is no field telling us\n * whether the given node was a type alias or not. So we have to compare the type name of the\n * node with the type name of the type symbol.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The node that should be tested.\n * @param type The type of the node that should be tested.\n * @returns TRUE when the given node and type look like a type alias, otherwise FALSE.\n */\n supportsNode(context:Context, node:ts.TypeReferenceNode, type:ts.Type):boolean {\n if (!type || !node || !node.typeName) return false;\n if (!type.symbol) return true;\n\n var checker = context.checker;\n var symbolName = checker.getFullyQualifiedName(type.symbol).split('.');\n if (!symbolName.length) return false;\n if (symbolName[0].substr(0, 1) == '\"') symbolName.shift();\n\n var nodeName = ts.getTextOfNode(node.typeName).split('.');\n if (!nodeName.length) return false;\n\n var common = Math.min(symbolName.length, nodeName.length);\n symbolName = symbolName.slice(-common);\n nodeName = nodeName.slice(-common);\n\n return nodeName.join('.') != symbolName.join('.');\n }\n\n\n /**\n * Create a reflection for the given type alias node.\n *\n * This is a node based converter with no type equivalent.\n *\n * Use [[isTypeAlias]] beforehand to test whether a given type/node combination is\n * pointing to a type alias.\n *\n * ```\n * type MyNumber = number;\n * var someValue:MyNumber;\n * ```\n *\n * @param node The node whose type should be reflected.\n * @returns A type reference pointing to the type alias definition.\n */\n convertNode(context:Context, node:ts.TypeReferenceNode):ReferenceType {\n var name = ts.getTextOfNode(node.typeName);\n return new ReferenceType(name, ReferenceType.SYMBOL_ID_RESOLVE_BY_NAME);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/array.d.ts b/lib/converter/types/array.d.ts new file mode 100644 index 000000000..3365b13b8 --- /dev/null +++ b/lib/converter/types/array.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Type } from "../../models/index"; +import { ConverterTypeComponent, ITypeNodeConverter } from "../components"; +import { Context } from "../context"; +export declare class ArrayConverter extends ConverterTypeComponent implements ITypeNodeConverter { + supportsNode(context: Context, node: ts.ArrayTypeNode): boolean; + convertNode(context: Context, node: ts.ArrayTypeNode): Type; +} diff --git a/lib/converter/types/array.js b/lib/converter/types/array.js new file mode 100644 index 000000000..13a03f7e5 --- /dev/null +++ b/lib/converter/types/array.js @@ -0,0 +1,40 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var components_1 = require("../components"); +var ArrayConverter = (function (_super) { + __extends(ArrayConverter, _super); + function ArrayConverter() { + _super.apply(this, arguments); + } + ArrayConverter.prototype.supportsNode = function (context, node) { + return node.kind === 160; + }; + ArrayConverter.prototype.convertNode = function (context, node) { + var result = this.owner.convertType(context, node.elementType); + if (result) { + result.isArray = true; + } + else { + result = new index_1.IntrinsicType('Array'); + } + return result; + }; + ArrayConverter = __decorate([ + components_1.Component({ name: 'type:array' }) + ], ArrayConverter); + return ArrayConverter; +}(components_1.ConverterTypeComponent)); +exports.ArrayConverter = ArrayConverter; +//# sourceMappingURL=array.js.map \ No newline at end of file diff --git a/lib/converter/types/array.js.map b/lib/converter/types/array.js.map new file mode 100644 index 000000000..d8a5e374b --- /dev/null +++ b/lib/converter/types/array.js.map @@ -0,0 +1 @@ +{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/lib/converter/types/array.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAkC,oBAAoB,CAAC,CAAA;AACvD,2BAAoE,eAAe,CAAC,CAAA;AAKpF;IAAoC,kCAAsB;IAA1D;QAAoC,8BAAsB;IAkC1D,CAAC;IA7BG,qCAAY,GAAZ,UAAa,OAAe,EAAE,IAAqB;QAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,GAAuB,CAAC;IACjD,CAAC;IAgBD,oCAAW,GAAX,UAAY,OAAe,EAAE,IAAqB;QAC9C,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAE/D,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACT,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QAC1B,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,MAAM,GAAG,IAAI,qBAAa,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAlCL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,YAAY,EAAC,CAAC;sBAAA;IAmC/B,qBAAC;AAAD,CAAC,AAlCD,CAAoC,mCAAsB,GAkCzD;AAlCY,sBAAc,iBAkC1B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, IntrinsicType} from \"../../models/index\";\nimport {Component, ConverterTypeComponent, ITypeNodeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:array'})\nexport class ArrayConverter extends ConverterTypeComponent implements ITypeNodeConverter\n{\n /**\n * Test whether this converter can handle the given TypeScript node.\n */\n supportsNode(context:Context, node:ts.ArrayTypeNode):boolean {\n return node.kind === ts.SyntaxKind.ArrayType;\n }\n\n\n /**\n * Convert the given array type node to its type reflection.\n *\n * This is a node based converter with no type equivalent.\n *\n * ```\n * var someValue:number[];\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The array type node that should be converted.\n * @returns The type reflection representing the given array type node.\n */\n convertNode(context:Context, node:ts.ArrayTypeNode):Type {\n var result = this.owner.convertType(context, node.elementType);\n\n if (result) {\n result.isArray = true;\n } else {\n result = new IntrinsicType('Array');\n }\n\n return result;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/binding-array.d.ts b/lib/converter/types/binding-array.d.ts new file mode 100644 index 000000000..966d0d5c2 --- /dev/null +++ b/lib/converter/types/binding-array.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Type } from "../../models/index"; +import { ConverterTypeComponent, ITypeNodeConverter } from "../components"; +import { Context } from "../context"; +export declare class BindingArrayConverter extends ConverterTypeComponent implements ITypeNodeConverter { + supportsNode(context: Context, node: ts.BindingPattern): boolean; + convertNode(context: Context, node: ts.BindingPattern): Type; +} diff --git a/lib/converter/types/binding-array.js b/lib/converter/types/binding-array.js new file mode 100644 index 000000000..4d1d6596d --- /dev/null +++ b/lib/converter/types/binding-array.js @@ -0,0 +1,38 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var components_1 = require("../components"); +var BindingArrayConverter = (function (_super) { + __extends(BindingArrayConverter, _super); + function BindingArrayConverter() { + _super.apply(this, arguments); + } + BindingArrayConverter.prototype.supportsNode = function (context, node) { + return node.kind === 168; + }; + BindingArrayConverter.prototype.convertNode = function (context, node) { + var _this = this; + var types = []; + node.elements.forEach(function (element) { + types.push(_this.owner.convertType(context, element)); + }); + return new index_1.TupleType(types); + }; + BindingArrayConverter = __decorate([ + components_1.Component({ name: 'type:binding-array' }) + ], BindingArrayConverter); + return BindingArrayConverter; +}(components_1.ConverterTypeComponent)); +exports.BindingArrayConverter = BindingArrayConverter; +//# sourceMappingURL=binding-array.js.map \ No newline at end of file diff --git a/lib/converter/types/binding-array.js.map b/lib/converter/types/binding-array.js.map new file mode 100644 index 000000000..c0501d91a --- /dev/null +++ b/lib/converter/types/binding-array.js.map @@ -0,0 +1 @@ +{"version":3,"file":"binding-array.js","sourceRoot":"","sources":["../../../src/lib/converter/types/binding-array.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAA8B,oBAAoB,CAAC,CAAA;AACnD,2BAAoE,eAAe,CAAC,CAAA;AAKpF;IAA2C,yCAAsB;IAAjE;QAA2C,8BAAsB;IA0BjE,CAAC;IArBG,4CAAY,GAAZ,UAAa,OAAe,EAAE,IAAsB;QAChD,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,GAAiC,CAAC;IAC3D,CAAC;IAUD,2CAAW,GAAX,UAAY,OAAe,EAAE,IAAsB;QAAnD,iBAQC;QAPG,IAAI,KAAK,GAAU,EAAE,CAAC;QAEtB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAC,OAAO;YAC1B,KAAK,CAAC,IAAI,CAAC,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,iBAAS,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IA1BL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,oBAAoB,EAAC,CAAC;6BAAA;IA2BvC,4BAAC;AAAD,CAAC,AA1BD,CAA2C,mCAAsB,GA0BhE;AA1BY,6BAAqB,wBA0BjC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, TupleType} from \"../../models/index\";\nimport {Component, ConverterTypeComponent, ITypeNodeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:binding-array'})\nexport class BindingArrayConverter extends ConverterTypeComponent implements ITypeNodeConverter\n{\n /**\n * Test whether this converter can handle the given TypeScript node.\n */\n supportsNode(context:Context, node:ts.BindingPattern):boolean {\n return node.kind === ts.SyntaxKind.ArrayBindingPattern;\n }\n\n\n /**\n * Convert the given binding pattern to its type reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The binding pattern that should be converted.\n * @returns The type reflection representing the given binding pattern.\n */\n convertNode(context:Context, node:ts.BindingPattern):Type {\n var types:Type[] = [];\n\n node.elements.forEach((element) => {\n types.push(this.owner.convertType(context, element));\n });\n\n return new TupleType(types);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/binding-object.d.ts b/lib/converter/types/binding-object.d.ts new file mode 100644 index 000000000..d0e8ffbbd --- /dev/null +++ b/lib/converter/types/binding-object.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Type } from "../../models/index"; +import { ConverterTypeComponent, ITypeNodeConverter } from "../components"; +import { Context } from "../context"; +export declare class BindingObjectConverter extends ConverterTypeComponent implements ITypeNodeConverter { + supportsNode(context: Context, node: ts.BindingPattern): boolean; + convertNode(context: Context, node: ts.BindingPattern): Type; +} diff --git a/lib/converter/types/binding-object.js b/lib/converter/types/binding-object.js new file mode 100644 index 000000000..cd5b90072 --- /dev/null +++ b/lib/converter/types/binding-object.js @@ -0,0 +1,46 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var components_1 = require("../components"); +var converter_1 = require("../converter"); +var BindingObjectConverter = (function (_super) { + __extends(BindingObjectConverter, _super); + function BindingObjectConverter() { + _super.apply(this, arguments); + } + BindingObjectConverter.prototype.supportsNode = function (context, node) { + return node.kind == 167; + }; + BindingObjectConverter.prototype.convertNode = function (context, node) { + var _this = this; + var declaration = new index_1.DeclarationReflection(); + declaration.kind = index_1.ReflectionKind.TypeLiteral; + declaration.name = '__type'; + declaration.parent = context.scope; + context.registerReflection(declaration, null); + context.trigger(converter_1.Converter.EVENT_CREATE_DECLARATION, declaration, node); + context.withScope(declaration, function () { + node.elements.forEach(function (element) { + _this.owner.convertNode(context, element); + }); + }); + return new index_1.ReflectionType(declaration); + }; + BindingObjectConverter = __decorate([ + components_1.Component({ name: 'type:binding-object' }) + ], BindingObjectConverter); + return BindingObjectConverter; +}(components_1.ConverterTypeComponent)); +exports.BindingObjectConverter = BindingObjectConverter; +//# sourceMappingURL=binding-object.js.map \ No newline at end of file diff --git a/lib/converter/types/binding-object.js.map b/lib/converter/types/binding-object.js.map new file mode 100644 index 000000000..f385728e2 --- /dev/null +++ b/lib/converter/types/binding-object.js.map @@ -0,0 +1 @@ +{"version":3,"file":"binding-object.js","sourceRoot":"","sources":["../../../src/lib/converter/types/binding-object.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAA0E,oBAAoB,CAAC,CAAA;AAC/F,2BAAoE,eAAe,CAAC,CAAA;AAEpF,0BAAwB,cAAc,CAAC,CAAA;AAIvC;IAA4C,0CAAsB;IAAlE;QAA4C,8BAAsB;IAiClE,CAAC;IA5BG,6CAAY,GAAZ,UAAa,OAAe,EAAE,IAAsB;QAChD,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,GAAkC,CAAC;IAC3D,CAAC;IAUD,4CAAW,GAAX,UAAY,OAAe,EAAE,IAAsB;QAAnD,iBAeC;QAdG,IAAI,WAAW,GAAG,IAAI,6BAAqB,EAAE,CAAC;QAC9C,WAAW,CAAC,IAAI,GAAG,sBAAc,CAAC,WAAW,CAAC;QAC9C,WAAW,CAAC,IAAI,GAAG,QAAQ,CAAC;QAC5B,WAAW,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAEnC,OAAO,CAAC,kBAAkB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAC9C,OAAO,CAAC,OAAO,CAAC,qBAAS,CAAC,wBAAwB,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;QACvE,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE;YAC3B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAC,OAAO;gBAC1B,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,sBAAc,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;IAjCL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,qBAAqB,EAAC,CAAC;8BAAA;IAkCxC,6BAAC;AAAD,CAAC,AAjCD,CAA4C,mCAAsB,GAiCjE;AAjCY,8BAAsB,yBAiClC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, ReflectionKind, DeclarationReflection, ReflectionType} from \"../../models/index\";\nimport {Component, ConverterTypeComponent, ITypeNodeConverter} from \"../components\";\nimport {Context} from \"../context\";\nimport {Converter} from \"../converter\";\n\n\n@Component({name:'type:binding-object'})\nexport class BindingObjectConverter extends ConverterTypeComponent implements ITypeNodeConverter\n{\n /**\n * Test whether this converter can handle the given TypeScript node.\n */\n supportsNode(context:Context, node:ts.BindingPattern):boolean {\n return node.kind == ts.SyntaxKind.ObjectBindingPattern;\n }\n\n\n /**\n * Convert the given binding pattern to its type reflection.\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The binding pattern that should be converted.\n * @returns The type reflection representing the given binding pattern.\n */\n convertNode(context:Context, node:ts.BindingPattern):Type {\n var declaration = new DeclarationReflection();\n declaration.kind = ReflectionKind.TypeLiteral;\n declaration.name = '__type';\n declaration.parent = context.scope;\n\n context.registerReflection(declaration, null);\n context.trigger(Converter.EVENT_CREATE_DECLARATION, declaration, node);\n context.withScope(declaration, () => {\n node.elements.forEach((element) => {\n this.owner.convertNode(context, element);\n });\n });\n\n return new ReflectionType(declaration);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/enum.d.ts b/lib/converter/types/enum.d.ts new file mode 100644 index 000000000..3ff11b5f3 --- /dev/null +++ b/lib/converter/types/enum.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { Type } from "../../models/index"; +import { ConverterTypeComponent, ITypeTypeConverter } from "../components"; +import { Context } from "../context"; +export declare class EnumConverter extends ConverterTypeComponent implements ITypeTypeConverter { + supportsType(context: Context, type: ts.Type): boolean; + convertType(context: Context, type: ts.Type): Type; +} diff --git a/lib/converter/types/enum.js b/lib/converter/types/enum.js new file mode 100644 index 000000000..d8cbf4f24 --- /dev/null +++ b/lib/converter/types/enum.js @@ -0,0 +1,33 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../factories/index"); +var components_1 = require("../components"); +var EnumConverter = (function (_super) { + __extends(EnumConverter, _super); + function EnumConverter() { + _super.apply(this, arguments); + } + EnumConverter.prototype.supportsType = function (context, type) { + return !!(type.flags & 16); + }; + EnumConverter.prototype.convertType = function (context, type) { + return index_1.createReferenceType(context, type.symbol); + }; + EnumConverter = __decorate([ + components_1.Component({ name: 'type:enum' }) + ], EnumConverter); + return EnumConverter; +}(components_1.ConverterTypeComponent)); +exports.EnumConverter = EnumConverter; +//# sourceMappingURL=enum.js.map \ No newline at end of file diff --git a/lib/converter/types/enum.js.map b/lib/converter/types/enum.js.map new file mode 100644 index 000000000..a6b0a8ba8 --- /dev/null +++ b/lib/converter/types/enum.js.map @@ -0,0 +1 @@ +{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../src/lib/converter/types/enum.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAGjC,sBAAkC,oBAAoB,CAAC,CAAA;AACvD,2BAAoE,eAAe,CAAC,CAAA;AAKpF;IAAmC,iCAAsB;IAAzD;QAAmC,8BAAsB;IA2BzD,CAAC;IAtBG,oCAAY,GAAZ,UAAa,OAAe,EAAE,IAAY;QACtC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,EAAiB,CAAC,CAAC;IAC9C,CAAC;IAiBD,mCAAW,GAAX,UAAY,OAAe,EAAE,IAAY;QACrC,MAAM,CAAC,2BAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;IA3BL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,WAAW,EAAC,CAAC;qBAAA;IA4B9B,oBAAC;AAAD,CAAC,AA3BD,CAAmC,mCAAsB,GA2BxD;AA3BY,qBAAa,gBA2BzB,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type} from \"../../models/index\";\nimport {createReferenceType} from \"../factories/index\";\nimport {Component, ConverterTypeComponent, ITypeTypeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:enum'})\nexport class EnumConverter extends ConverterTypeComponent implements ITypeTypeConverter\n{\n /**\n * Test whether this converter can handle the given TypeScript type.\n */\n supportsType(context:Context, type:ts.Type):boolean {\n return !!(type.flags & ts.TypeFlags.Enum);\n }\n\n\n /**\n * Convert the given enumeration type to its type reflection.\n *\n * This is a type based converter with no node based equivalent.\n *\n * ```\n * enum MyEnum { One, Two, Three }\n * var someValue:MyEnum;\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param type The enumeration type that should be converted.\n * @returns The type reflection representing the given enumeration type.\n */\n convertType(context:Context, type:ts.Type):Type {\n return createReferenceType(context, type.symbol);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/index.d.ts b/lib/converter/types/index.d.ts new file mode 100644 index 000000000..a7778ed8c --- /dev/null +++ b/lib/converter/types/index.d.ts @@ -0,0 +1,12 @@ +export { AliasConverter } from "./alias"; +export { ArrayConverter } from "./array"; +export { BindingArrayConverter } from "./binding-array"; +export { BindingObjectConverter } from "./binding-object"; +export { EnumConverter } from "./enum"; +export { IntrinsicConverter } from "./intrinsic"; +export { StringLiteralConverter } from "./string-literal"; +export { ReferenceConverter } from "./reference"; +export { TupleConverter } from "./tuple"; +export { TypeParameterConverter } from "./type-parameter"; +export { UnionConverter } from "./union"; +export { UnknownConverter } from "./unknown"; diff --git a/lib/converter/types/index.js b/lib/converter/types/index.js new file mode 100644 index 000000000..a9acf750c --- /dev/null +++ b/lib/converter/types/index.js @@ -0,0 +1,26 @@ +"use strict"; +var alias_1 = require("./alias"); +exports.AliasConverter = alias_1.AliasConverter; +var array_1 = require("./array"); +exports.ArrayConverter = array_1.ArrayConverter; +var binding_array_1 = require("./binding-array"); +exports.BindingArrayConverter = binding_array_1.BindingArrayConverter; +var binding_object_1 = require("./binding-object"); +exports.BindingObjectConverter = binding_object_1.BindingObjectConverter; +var enum_1 = require("./enum"); +exports.EnumConverter = enum_1.EnumConverter; +var intrinsic_1 = require("./intrinsic"); +exports.IntrinsicConverter = intrinsic_1.IntrinsicConverter; +var string_literal_1 = require("./string-literal"); +exports.StringLiteralConverter = string_literal_1.StringLiteralConverter; +var reference_1 = require("./reference"); +exports.ReferenceConverter = reference_1.ReferenceConverter; +var tuple_1 = require("./tuple"); +exports.TupleConverter = tuple_1.TupleConverter; +var type_parameter_1 = require("./type-parameter"); +exports.TypeParameterConverter = type_parameter_1.TypeParameterConverter; +var union_1 = require("./union"); +exports.UnionConverter = union_1.UnionConverter; +var unknown_1 = require("./unknown"); +exports.UnknownConverter = unknown_1.UnknownConverter; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/converter/types/index.js.map b/lib/converter/types/index.js.map new file mode 100644 index 000000000..bfb8eaa3c --- /dev/null +++ b/lib/converter/types/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/converter/types/index.ts"],"names":[],"mappings":";AAAA,sBAA6B,SAAS,CAAC;AAA/B,gDAA+B;AACvC,sBAA6B,SAAS,CAAC;AAA/B,gDAA+B;AACvC,8BAAoC,iBAAiB,CAAC;AAA9C,sEAA8C;AACtD,+BAAqC,kBAAkB,CAAC;AAAhD,yEAAgD;AACxD,qBAA4B,QAAQ,CAAC;AAA7B,6CAA6B;AACrC,0BAAiC,aACjC,CAAC;AADO,4DAAsC;AAC9C,+BAAqC,kBAAkB,CAAC;AAAhD,yEAAgD;AACxD,0BAAiC,aAAa,CAAC;AAAvC,4DAAuC;AAC/C,sBAA6B,SAAS,CAAC;AAA/B,gDAA+B;AACvC,+BAAqC,kBAAkB,CAAC;AAAhD,yEAAgD;AACxD,sBAA6B,SAAS,CAAC;AAA/B,gDAA+B;AACvC,wBAA+B,WAAW,CAAC;AAAnC,sDAAmC","sourcesContent":["export {AliasConverter} from \"./alias\";\nexport {ArrayConverter} from \"./array\";\nexport {BindingArrayConverter} from \"./binding-array\";\nexport {BindingObjectConverter} from \"./binding-object\";\nexport {EnumConverter} from \"./enum\";\nexport {IntrinsicConverter} from \"./intrinsic\"\nexport {StringLiteralConverter} from \"./string-literal\";\nexport {ReferenceConverter} from \"./reference\";\nexport {TupleConverter} from \"./tuple\";\nexport {TypeParameterConverter} from \"./type-parameter\";\nexport {UnionConverter} from \"./union\";\nexport {UnknownConverter} from \"./unknown\";\n"]} \ No newline at end of file diff --git a/lib/converter/types/intrinsic.d.ts b/lib/converter/types/intrinsic.d.ts new file mode 100644 index 000000000..6028da93f --- /dev/null +++ b/lib/converter/types/intrinsic.d.ts @@ -0,0 +1,8 @@ +import * as ts from "typescript"; +import { IntrinsicType } from "../../models/index"; +import { ConverterTypeComponent, ITypeTypeConverter } from "../components"; +import { Context } from "../context"; +export declare class IntrinsicConverter extends ConverterTypeComponent implements ITypeTypeConverter { + supportsType(context: Context, type: ts.IntrinsicType): boolean; + convertType(context: Context, type: ts.IntrinsicType): IntrinsicType; +} diff --git a/lib/converter/types/intrinsic.js b/lib/converter/types/intrinsic.js new file mode 100644 index 000000000..9852e94d0 --- /dev/null +++ b/lib/converter/types/intrinsic.js @@ -0,0 +1,33 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/index"); +var components_1 = require("../components"); +var IntrinsicConverter = (function (_super) { + __extends(IntrinsicConverter, _super); + function IntrinsicConverter() { + _super.apply(this, arguments); + } + IntrinsicConverter.prototype.supportsType = function (context, type) { + return !!(type.flags & 16015); + }; + IntrinsicConverter.prototype.convertType = function (context, type) { + return new index_1.IntrinsicType(type.intrinsicName); + }; + IntrinsicConverter = __decorate([ + components_1.Component({ name: 'type:intrinsic' }) + ], IntrinsicConverter); + return IntrinsicConverter; +}(components_1.ConverterTypeComponent)); +exports.IntrinsicConverter = IntrinsicConverter; +//# sourceMappingURL=intrinsic.js.map \ No newline at end of file diff --git a/lib/converter/types/intrinsic.js.map b/lib/converter/types/intrinsic.js.map new file mode 100644 index 000000000..0decae985 --- /dev/null +++ b/lib/converter/types/intrinsic.js.map @@ -0,0 +1 @@ +{"version":3,"file":"intrinsic.js","sourceRoot":"","sources":["../../../src/lib/converter/types/intrinsic.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAkC,oBAAoB,CAAC,CAAA;AACvD,2BAAoE,eAAe,CAAC,CAAA;AAKpF;IAAwC,sCAAsB;IAA9D;QAAwC,8BAAsB;IAyB9D,CAAC;IApBG,yCAAY,GAAZ,UAAa,OAAe,EAAE,IAAqB;QAC/C,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,KAAsB,CAAC,CAAC;IACnD,CAAC;IAeD,wCAAW,GAAX,UAAY,OAAe,EAAE,IAAqB;QAC9C,MAAM,CAAC,IAAI,qBAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACjD,CAAC;IAzBL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,gBAAgB,EAAC,CAAC;0BAAA;IA0BnC,yBAAC;AAAD,CAAC,AAzBD,CAAwC,mCAAsB,GAyB7D;AAzBY,0BAAkB,qBAyB9B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, IntrinsicType} from \"../../models/index\";\nimport {Component, ConverterTypeComponent, ITypeTypeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:intrinsic'})\nexport class IntrinsicConverter extends ConverterTypeComponent implements ITypeTypeConverter\n{\n /**\n * Test whether this converter can handle the given TypeScript type.\n */\n supportsType(context:Context, type:ts.IntrinsicType):boolean {\n return !!(type.flags & ts.TypeFlags.Intrinsic);\n }\n\n\n /**\n * Convert the given intrinsic type to its type reflection.\n *\n * This is a type based converter with no node based equivalent.\n *\n * ```\n * var someValue:string;\n * ```\n *\n * @param type The intrinsic type that should be converted.\n * @returns The type reflection representing the given intrinsic type.\n */\n convertType(context:Context, type:ts.IntrinsicType):IntrinsicType {\n return new IntrinsicType(type.intrinsicName);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/reference.d.ts b/lib/converter/types/reference.d.ts new file mode 100644 index 000000000..ce8e696cb --- /dev/null +++ b/lib/converter/types/reference.d.ts @@ -0,0 +1,12 @@ +import * as ts from "typescript"; +import { Type } from "../../models/types/index"; +import { ConverterTypeComponent, ITypeNodeConverter } from "../components"; +import { Context } from "../context"; +export declare class ReferenceConverter extends ConverterTypeComponent implements ITypeNodeConverter { + priority: number; + supportsNode(context: Context, node: ts.TypeReferenceNode, type: ts.TypeReference): boolean; + supportsType(context: Context, type: ts.TypeReference): boolean; + convertNode(context: Context, node: ts.TypeReferenceNode, type: ts.TypeReference): Type; + convertType(context: Context, type: ts.TypeReference): Type; + private convertLiteral(context, symbol, node?); +} diff --git a/lib/converter/types/reference.js b/lib/converter/types/reference.js new file mode 100644 index 000000000..7482bcc92 --- /dev/null +++ b/lib/converter/types/reference.js @@ -0,0 +1,92 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/types/index"); +var index_2 = require("../../models/reflections/index"); +var index_3 = require("../factories/index"); +var components_1 = require("../components"); +var converter_1 = require("../converter"); +var ReferenceConverter = (function (_super) { + __extends(ReferenceConverter, _super); + function ReferenceConverter() { + _super.apply(this, arguments); + this.priority = -50; + } + ReferenceConverter.prototype.supportsNode = function (context, node, type) { + return !!(type.flags & 2588672); + }; + ReferenceConverter.prototype.supportsType = function (context, type) { + return !!(type.flags & 2588672); + }; + ReferenceConverter.prototype.convertNode = function (context, node, type) { + var _this = this; + if (!type.symbol) { + return new index_1.IntrinsicType('Object'); + } + else if (type.symbol.flags & 2048 || type.symbol.flags & 4096) { + return this.convertLiteral(context, type.symbol, node); + } + var result = index_3.createReferenceType(context, type.symbol); + if (node.typeArguments) { + result.typeArguments = node.typeArguments.map(function (n) { return _this.owner.convertType(context, n); }); + } + return result; + }; + ReferenceConverter.prototype.convertType = function (context, type) { + var _this = this; + if (!type.symbol) { + return new index_1.IntrinsicType('Object'); + } + else if (type.symbol.flags & 2048 || type.symbol.flags & 4096) { + return this.convertLiteral(context, type.symbol); + } + var result = index_3.createReferenceType(context, type.symbol); + if (type.typeArguments) { + result.typeArguments = type.typeArguments.map(function (t) { return _this.owner.convertType(context, null, t); }); + } + return result; + }; + ReferenceConverter.prototype.convertLiteral = function (context, symbol, node) { + var _this = this; + for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { + var declaration_1 = _a[_i]; + if (context.visitStack.indexOf(declaration_1) !== -1) { + if (declaration_1.kind == 159 || + declaration_1.kind == 171) { + return index_3.createReferenceType(context, declaration_1.parent.symbol); + } + else { + return index_3.createReferenceType(context, declaration_1.symbol); + } + } + } + var declaration = new index_2.DeclarationReflection(); + declaration.kind = index_2.ReflectionKind.TypeLiteral; + declaration.name = '__type'; + declaration.parent = context.scope; + context.registerReflection(declaration, null, symbol); + context.trigger(converter_1.Converter.EVENT_CREATE_DECLARATION, declaration, node); + context.withScope(declaration, function () { + symbol.declarations.forEach(function (node) { + _this.owner.convertNode(context, node); + }); + }); + return new index_1.ReflectionType(declaration); + }; + ReferenceConverter = __decorate([ + components_1.Component({ name: 'type:reference' }) + ], ReferenceConverter); + return ReferenceConverter; +}(components_1.ConverterTypeComponent)); +exports.ReferenceConverter = ReferenceConverter; +//# sourceMappingURL=reference.js.map \ No newline at end of file diff --git a/lib/converter/types/reference.js.map b/lib/converter/types/reference.js.map new file mode 100644 index 000000000..bf5f8335b --- /dev/null +++ b/lib/converter/types/reference.js.map @@ -0,0 +1 @@ +{"version":3,"file":"reference.js","sourceRoot":"","sources":["../../../src/lib/converter/types/reference.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAkD,0BAA0B,CAAC,CAAA;AAC7E,sBAAoD,gCAAgC,CAAC,CAAA;AACrF,sBAAkC,oBAAoB,CAAC,CAAA;AACvD,2BAAoE,eAAe,CAAC,CAAA;AAEpF,0BAAwB,cAAc,CAAC,CAAA;AAIvC;IAAwC,sCAAsB;IAA9D;QAAwC,8BAAsB;QAM1D,aAAQ,GAAU,CAAC,EAAE,CAAC;IAkI1B,CAAC;IA3HG,yCAAY,GAAZ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AC,CAAC;oBACJ,MAAM,CAAC,2BAAmB,CAAC,OAAO,EAAE,aAAW,CAAC,MAAM,CAAC,CAAC;gBAC5D,CAAC;YACL,CAAC;SACJ;QAED,IAAI,WAAW,GAAG,IAAI,6BAAqB,EAAE,CAAC;QAC9C,WAAW,CAAC,IAAI,GAAG,sBAAc,CAAC,WAAW,CAAC;QAC9C,WAAW,CAAC,IAAI,GAAG,QAAQ,CAAC;QAC5B,WAAW,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAEnC,OAAO,CAAC,kBAAkB,CAAC,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACtD,OAAO,CAAC,OAAO,CAAC,qBAAS,CAAC,wBAAwB,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;QACvE,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE;YAC3B,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,UAAC,IAAI;gBAC7B,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,sBAAc,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;IAxIL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,gBAAgB,EAAC,CAAC;0BAAA;IAyInC,yBAAC;AAAD,CAAC,AAxID,CAAwC,mCAAsB,GAwI7D;AAxIY,0BAAkB,qBAwI9B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, IntrinsicType, ReflectionType} from \"../../models/types/index\";\nimport {ReflectionKind, DeclarationReflection} from \"../../models/reflections/index\";\nimport {createReferenceType} from \"../factories/index\";\nimport {Component, ConverterTypeComponent, ITypeNodeConverter} from \"../components\";\nimport {Context} from \"../context\";\nimport {Converter} from \"../converter\";\n\n\n@Component({name:'type:reference'})\nexport class ReferenceConverter extends ConverterTypeComponent implements ITypeNodeConverter\n{\n /**\n * The priority this converter should be executed with.\n * A higher priority means the converter will be applied earlier.\n */\n priority:number = -50;\n\n\n\n /**\n * Test whether this converter can handle the given TypeScript node.\n */\n supportsNode(context:Context, node:ts.TypeReferenceNode, type:ts.TypeReference):boolean {\n return !!(type.flags & ts.TypeFlags.ObjectType);\n }\n\n\n /**\n * Test whether this converter can handle the given TypeScript type.\n */\n supportsType(context:Context, type:ts.TypeReference):boolean {\n return !!(type.flags & ts.TypeFlags.ObjectType);\n }\n\n\n /**\n * Convert the type reference node to its type reflection.\n *\n * This is a node based converter, see [[convertTypeReferenceType]] for the type equivalent.\n *\n * ```\n * class SomeClass { }\n * var someValue:SomeClass;\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The type reference node that should be converted.\n * @param type The type of the type reference node.\n * @returns The type reflection representing the given reference node.\n */\n convertNode(context:Context, node:ts.TypeReferenceNode, type:ts.TypeReference):Type {\n if (!type.symbol) {\n return new IntrinsicType('Object');\n } else if (type.symbol.flags & ts.SymbolFlags.TypeLiteral || type.symbol.flags & ts.SymbolFlags.ObjectLiteral) {\n return this.convertLiteral(context, type.symbol, node);\n }\n\n var result = createReferenceType(context, type.symbol);\n if (node.typeArguments) {\n result.typeArguments = node.typeArguments.map((n) => this.owner.convertType(context, n));\n }\n\n return result;\n }\n\n\n /**\n * Convert the given type reference to its type reflection.\n *\n * This is a type based converter, see [[convertTypeReference]] for the node equivalent.\n *\n * ```\n * class SomeClass { }\n * var someValue:SomeClass;\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param type The type reference that should be converted.\n * @returns The type reflection representing the given type reference.\n */\n convertType(context:Context, type:ts.TypeReference):Type {\n if (!type.symbol) {\n return new IntrinsicType('Object');\n } else if (type.symbol.flags & ts.SymbolFlags.TypeLiteral || type.symbol.flags & ts.SymbolFlags.ObjectLiteral) {\n return this.convertLiteral(context, type.symbol);\n }\n\n var result = createReferenceType(context, type.symbol);\n if (type.typeArguments) {\n result.typeArguments = type.typeArguments.map((t) => this.owner.convertType(context, null, t));\n }\n\n return result;\n }\n\n\n /**\n * Create a type literal reflection.\n *\n * This is a utility function used by [[convertTypeReferenceNode]] and\n * [[convertTypeReferenceType]] when encountering an object or type literal.\n *\n * A type literal is explicitly set:\n * ```\n * var someValue:{a:string; b:number;};\n * ```\n *\n * An object literal types are usually reflected by the TypeScript compiler:\n * ```\n * function someFunction() { return {a:'Test', b:1024}; }\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param symbol The symbol describing the type literal.\n * @param node If known the node which produced the type literal. Type literals that are\n * implicitly generated by TypeScript won't have a corresponding node.\n * @returns A type reflection representing the given type literal.\n */\n private convertLiteral(context:Context, symbol:ts.Symbol, node?:ts.Node):Type {\n for (let declaration of symbol.declarations) {\n if (context.visitStack.indexOf(declaration) !== -1) {\n if (declaration.kind == ts.SyntaxKind.TypeLiteral ||\n declaration.kind == ts.SyntaxKind.ObjectLiteralExpression) {\n return createReferenceType(context, declaration.parent.symbol);\n } else {\n return createReferenceType(context, declaration.symbol);\n }\n }\n }\n\n var declaration = new DeclarationReflection();\n declaration.kind = ReflectionKind.TypeLiteral;\n declaration.name = '__type';\n declaration.parent = context.scope;\n\n context.registerReflection(declaration, null, symbol);\n context.trigger(Converter.EVENT_CREATE_DECLARATION, declaration, node);\n context.withScope(declaration, () => {\n symbol.declarations.forEach((node) => {\n this.owner.convertNode(context, node);\n });\n });\n\n return new ReflectionType(declaration);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/string-literal.d.ts b/lib/converter/types/string-literal.d.ts new file mode 100644 index 000000000..e123d8749 --- /dev/null +++ b/lib/converter/types/string-literal.d.ts @@ -0,0 +1,10 @@ +import * as ts from "typescript"; +import { Type } from "../../models/types/index"; +import { ConverterTypeComponent, ITypeConverter } from "../components"; +import { Context } from "../context"; +export declare class StringLiteralConverter extends ConverterTypeComponent implements ITypeConverter { + supportsNode(context: Context, node: ts.StringLiteral): boolean; + supportsType(context: Context, type: ts.LiteralType): boolean; + convertNode(context: Context, node: ts.StringLiteral): Type; + convertType(context: Context, type: ts.LiteralType): Type; +} diff --git a/lib/converter/types/string-literal.js b/lib/converter/types/string-literal.js new file mode 100644 index 000000000..38eeddd75 --- /dev/null +++ b/lib/converter/types/string-literal.js @@ -0,0 +1,39 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/types/index"); +var components_1 = require("../components"); +var StringLiteralConverter = (function (_super) { + __extends(StringLiteralConverter, _super); + function StringLiteralConverter() { + _super.apply(this, arguments); + } + StringLiteralConverter.prototype.supportsNode = function (context, node) { + return node.kind === 9; + }; + StringLiteralConverter.prototype.supportsType = function (context, type) { + return !!(type.flags & 32); + }; + StringLiteralConverter.prototype.convertNode = function (context, node) { + return new index_1.StringLiteralType(node.text); + }; + StringLiteralConverter.prototype.convertType = function (context, type) { + return new index_1.StringLiteralType(type.text); + }; + StringLiteralConverter = __decorate([ + components_1.Component({ name: 'type:string-literal' }) + ], StringLiteralConverter); + return StringLiteralConverter; +}(components_1.ConverterTypeComponent)); +exports.StringLiteralConverter = StringLiteralConverter; +//# sourceMappingURL=string-literal.js.map \ No newline at end of file diff --git a/lib/converter/types/string-literal.js.map b/lib/converter/types/string-literal.js.map new file mode 100644 index 000000000..f7d427d4b --- /dev/null +++ b/lib/converter/types/string-literal.js.map @@ -0,0 +1 @@ +{"version":3,"file":"string-literal.js","sourceRoot":"","sources":["../../../src/lib/converter/types/string-literal.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAsC,0BAA0B,CAAC,CAAA;AACjE,2BAAgE,eAAe,CAAC,CAAA;AAKhF;IAA4C,0CAAsB;IAAlE;QAA4C,8BAAsB;IAkDlE,CAAC;IA7CG,6CAAY,GAAZ,UAAa,OAAe,EAAE,IAAqB;QAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAA2B,CAAC;IACrD,CAAC;IAMD,6CAAY,GAAZ,UAAa,OAAe,EAAE,IAAmB;QAC7C,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,EAA0B,CAAC,CAAC;IACvD,CAAC;IAeD,4CAAW,GAAX,UAAY,OAAe,EAAE,IAAqB;QAC9C,MAAM,CAAC,IAAI,yBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAeD,4CAAW,GAAX,UAAY,OAAe,EAAE,IAAmB;QAC5C,MAAM,CAAC,IAAI,yBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAlDL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,qBAAqB,EAAC,CAAC;8BAAA;IAmDxC,6BAAC;AAAD,CAAC,AAlDD,CAA4C,mCAAsB,GAkDjE;AAlDY,8BAAsB,yBAkDlC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, StringLiteralType} from \"../../models/types/index\";\nimport {Component, ConverterTypeComponent, ITypeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:string-literal'})\nexport class StringLiteralConverter extends ConverterTypeComponent implements ITypeConverter\n{\n /**\n * Test whether this converter can handle the given TypeScript node.\n */\n supportsNode(context:Context, node:ts.StringLiteral):boolean {\n return node.kind === ts.SyntaxKind.StringLiteral;\n }\n\n\n /**\n * Test whether this converter can handle the given TypeScript type.\n */\n supportsType(context:Context, type:ts.LiteralType):boolean {\n return !!(type.flags & ts.TypeFlags.StringLiteral);\n }\n\n\n /**\n * Convert the given string literal expression node to its type reflection.\n *\n * This is a node based converter, see [[convertStringLiteralType]] for the type equivalent.\n *\n * ```\n * createElement(tagName:\"a\"):HTMLAnchorElement;\n * ```\n *\n * @param node The string literal node that should be converted.\n * @returns The type reflection representing the given string literal node.\n */\n convertNode(context:Context, node:ts.StringLiteral):Type {\n return new StringLiteralType(node.text);\n }\n\n\n /**\n * Convert the given string literal type to its type reflection.\n *\n * This is a type based converter, see [[convertStringLiteralExpression]] for the node equivalent.\n *\n * ```\n * createElement(tagName:\"a\"):HTMLAnchorElement;\n * ```\n *\n * @param type The intrinsic type that should be converted.\n * @returns The type reflection representing the given string literal type.\n */\n convertType(context:Context, type:ts.LiteralType):Type {\n return new StringLiteralType(type.text);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/tuple.d.ts b/lib/converter/types/tuple.d.ts new file mode 100644 index 000000000..4ef1b5207 --- /dev/null +++ b/lib/converter/types/tuple.d.ts @@ -0,0 +1,10 @@ +import * as ts from "typescript"; +import { TupleType } from "../../models/types/index"; +import { ConverterTypeComponent, ITypeConverter } from "../components"; +import { Context } from "../context"; +export declare class TupleConverter extends ConverterTypeComponent implements ITypeConverter { + supportsNode(context: Context, node: ts.TupleTypeNode): boolean; + supportsType(context: Context, type: ts.TypeReference): boolean; + convertNode(context: Context, node: ts.TupleTypeNode): TupleType; + convertType(context: Context, type: ts.TypeReference): TupleType; +} diff --git a/lib/converter/types/tuple.js b/lib/converter/types/tuple.js new file mode 100644 index 000000000..45559897c --- /dev/null +++ b/lib/converter/types/tuple.js @@ -0,0 +1,55 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/types/index"); +var components_1 = require("../components"); +var TupleConverter = (function (_super) { + __extends(TupleConverter, _super); + function TupleConverter() { + _super.apply(this, arguments); + } + TupleConverter.prototype.supportsNode = function (context, node) { + return node.kind === 161; + }; + TupleConverter.prototype.supportsType = function (context, type) { + return !!(type.flags & 262144); + }; + TupleConverter.prototype.convertNode = function (context, node) { + var _this = this; + var elements; + if (node.elementTypes) { + elements = node.elementTypes.map(function (n) { return _this.owner.convertType(context, n); }); + } + else { + elements = []; + } + return new index_1.TupleType(elements); + }; + TupleConverter.prototype.convertType = function (context, type) { + var _this = this; + var elements; + if (type.typeArguments) { + elements = type.typeArguments.map(function (t) { return _this.owner.convertType(context, null, t); }); + } + else { + elements = []; + } + return new index_1.TupleType(elements); + }; + TupleConverter = __decorate([ + components_1.Component({ name: 'type:tuple' }) + ], TupleConverter); + return TupleConverter; +}(components_1.ConverterTypeComponent)); +exports.TupleConverter = TupleConverter; +//# sourceMappingURL=tuple.js.map \ No newline at end of file diff --git a/lib/converter/types/tuple.js.map b/lib/converter/types/tuple.js.map new file mode 100644 index 000000000..7c418cd23 --- /dev/null +++ b/lib/converter/types/tuple.js.map @@ -0,0 +1 @@ +{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../../src/lib/converter/types/tuple.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAA8B,0BAA0B,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AAI,iBAAS,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAlEL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,YAAY,EAAC,CAAC;sBAAA;IAmE/B,qBAAC;AAAD,CAAC,AAlED,CAAoC,mCAAsB,GAkEzD;AAlEY,sBAAc,iBAkE1B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, TupleType} from \"../../models/types/index\";\nimport {Component, ConverterTypeComponent, ITypeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:tuple'})\nexport class TupleConverter extends ConverterTypeComponent implements ITypeConverter\n{\n /**\n * Test whether this converter can handle the given TypeScript node.\n */\n supportsNode(context:Context, node:ts.TupleTypeNode):boolean {\n return node.kind === ts.SyntaxKind.TupleType;\n }\n\n\n /**\n * Test whether this converter can handle the given TypeScript type.\n */\n supportsType(context:Context, type:ts.TypeReference):boolean {\n return !!(type.flags & ts.TypeFlags.Tuple);\n }\n\n\n /**\n * Convert the given tuple type node to its type reflection.\n *\n * This is a node based converter, see [[convertTupleType]] for the type equivalent.\n *\n * ```\n * var someValue:[string,number];\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The tuple type node that should be converted.\n * @returns The type reflection representing the given tuple type node.\n */\n convertNode(context:Context, node:ts.TupleTypeNode):TupleType {\n var elements:Type[];\n if (node.elementTypes) {\n elements = node.elementTypes.map((n) => this.owner.convertType(context, n));\n } else {\n elements = [];\n }\n\n return new TupleType(elements);\n }\n\n\n /**\n * Convert the given tuple type to its type reflection.\n *\n * This is a type based converter, see [[convertTupleTypeNode]] for the node equivalent.\n *\n * ```\n * var someValue:[string,number];\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param type The tuple type that should be converted.\n * @returns The type reflection representing the given tuple type.\n */\n convertType(context:Context, type:ts.TypeReference):TupleType {\n var elements:Type[];\n if (type.typeArguments) {\n elements = type.typeArguments.map((t) => this.owner.convertType(context, null, t));\n } else {\n elements = [];\n }\n\n return new TupleType(elements);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/type-parameter.d.ts b/lib/converter/types/type-parameter.d.ts new file mode 100644 index 000000000..8937be9e5 --- /dev/null +++ b/lib/converter/types/type-parameter.d.ts @@ -0,0 +1,9 @@ +import * as ts from "typescript"; +import { Type } from "../../models/types/index"; +import { ConverterTypeComponent, ITypeNodeConverter } from "../components"; +import { Context } from "../context"; +export declare class TypeParameterConverter extends ConverterTypeComponent implements ITypeNodeConverter { + priority: number; + supportsNode(context: Context, node: ts.TypeReferenceNode, type: ts.Type): boolean; + convertNode(context: Context, node: ts.TypeReferenceNode): Type; +} diff --git a/lib/converter/types/type-parameter.js b/lib/converter/types/type-parameter.js new file mode 100644 index 000000000..9d16379ef --- /dev/null +++ b/lib/converter/types/type-parameter.js @@ -0,0 +1,42 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/types/index"); +var components_1 = require("../components"); +var TypeParameterConverter = (function (_super) { + __extends(TypeParameterConverter, _super); + function TypeParameterConverter() { + _super.apply(this, arguments); + this.priority = -50; + } + TypeParameterConverter.prototype.supportsNode = function (context, node, type) { + return !!(type.flags & 16384); + }; + TypeParameterConverter.prototype.convertNode = function (context, node) { + if (node.typeName) { + var name = ts.getTextOfNode(node.typeName); + if (context.typeParameters && context.typeParameters[name]) { + return context.typeParameters[name].clone(); + } + var result = new index_1.TypeParameterType(); + result.name = name; + return result; + } + }; + TypeParameterConverter = __decorate([ + components_1.Component({ name: 'type:type-parameter' }) + ], TypeParameterConverter); + return TypeParameterConverter; +}(components_1.ConverterTypeComponent)); +exports.TypeParameterConverter = TypeParameterConverter; +//# sourceMappingURL=type-parameter.js.map \ No newline at end of file diff --git a/lib/converter/types/type-parameter.js.map b/lib/converter/types/type-parameter.js.map new file mode 100644 index 000000000..b8b5e8d7f --- /dev/null +++ b/lib/converter/types/type-parameter.js.map @@ -0,0 +1 @@ +{"version":3,"file":"type-parameter.js","sourceRoot":"","sources":["../../../src/lib/converter/types/type-parameter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAAsC,0BAA0B,CAAC,CAAA;AACjE,2BAAoE,eAAe,CAAC,CAAA;AAKpF;IAA4C,0CAAsB;IAAlE;QAA4C,8BAAsB;QAM9D,aAAQ,GAAU,CAAC,EAAE,CAAC;IAuC1B,CAAC;IAhCG,6CAAY,GAAZ,UAAa,OAAe,EAAE,IAAyB,EAAE,IAAY;QACjE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,KAA0B,CAAC,CAAC;IACvD,CAAC;IAkBD,4CAAW,GAAX,UAAY,OAAe,EAAE,IAAyB;QAClD,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAChB,IAAI,IAAI,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3C,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBACzD,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;YAChD,CAAC;YAED,IAAI,MAAM,GAAG,IAAI,yBAAiB,EAAE,CAAC;YACrC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,MAAM,CAAC,MAAM,CAAC;QAClB,CAAC;IACL,CAAC;IA7CL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,qBAAqB,EAAC,CAAC;8BAAA;IA8CxC,6BAAC;AAAD,CAAC,AA7CD,CAA4C,mCAAsB,GA6CjE;AA7CY,8BAAsB,yBA6ClC,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, TypeParameterType} from \"../../models/types/index\";\nimport {Component, ConverterTypeComponent, ITypeNodeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:type-parameter'})\nexport class TypeParameterConverter extends ConverterTypeComponent implements ITypeNodeConverter\n{\n /**\n * The priority this converter should be executed with.\n * A higher priority means the converter will be applied earlier.\n */\n priority:number = -50;\n\n\n\n /**\n * Test whether this converter can handle the given TypeScript node.\n */\n supportsNode(context:Context, node:ts.TypeReferenceNode, type:ts.Type):boolean {\n return !!(type.flags & ts.TypeFlags.TypeParameter);\n }\n\n\n /**\n * Interpret the given type reference node as a type parameter and convert it to its type reflection.\n *\n * This is a node based converter with no type equivalent.\n *\n * ```\n * class SomeClass {\n * public someValue:T;\n * }\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The type reference node representing a type parameter.\n * @returns The type reflection representing the given type parameter.\n */\n convertNode(context:Context, node:ts.TypeReferenceNode):Type {\n if (node.typeName) {\n var name = ts.getTextOfNode(node.typeName);\n if (context.typeParameters && context.typeParameters[name]) {\n return context.typeParameters[name].clone();\n }\n\n var result = new TypeParameterType();\n result.name = name;\n return result;\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/union.d.ts b/lib/converter/types/union.d.ts new file mode 100644 index 000000000..6c747fccc --- /dev/null +++ b/lib/converter/types/union.d.ts @@ -0,0 +1,10 @@ +import * as ts from "typescript"; +import { UnionType } from "../../models/types/index"; +import { ConverterTypeComponent, ITypeConverter } from "../components"; +import { Context } from "../context"; +export declare class UnionConverter extends ConverterTypeComponent implements ITypeConverter { + supportsNode(context: Context, node: ts.UnionTypeNode): boolean; + supportsType(context: Context, type: ts.UnionType): boolean; + convertNode(context: Context, node: ts.UnionTypeNode): UnionType; + convertType(context: Context, type: ts.UnionType): UnionType; +} diff --git a/lib/converter/types/union.js b/lib/converter/types/union.js new file mode 100644 index 000000000..88d2cb8f4 --- /dev/null +++ b/lib/converter/types/union.js @@ -0,0 +1,55 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var ts = require("typescript"); +var index_1 = require("../../models/types/index"); +var components_1 = require("../components"); +var UnionConverter = (function (_super) { + __extends(UnionConverter, _super); + function UnionConverter() { + _super.apply(this, arguments); + } + UnionConverter.prototype.supportsNode = function (context, node) { + return node.kind === 162; + }; + UnionConverter.prototype.supportsType = function (context, type) { + return !!(type.flags & 524288); + }; + UnionConverter.prototype.convertNode = function (context, node) { + var _this = this; + var types = []; + if (node.types) { + types = node.types.map(function (n) { return _this.owner.convertType(context, n); }); + } + else { + types = []; + } + return new index_1.UnionType(types); + }; + UnionConverter.prototype.convertType = function (context, type) { + var _this = this; + var types; + if (type && type.types) { + types = type.types.map(function (t) { return _this.owner.convertType(context, null, t); }); + } + else { + types = []; + } + return new index_1.UnionType(types); + }; + UnionConverter = __decorate([ + components_1.Component({ name: 'type:union' }) + ], UnionConverter); + return UnionConverter; +}(components_1.ConverterTypeComponent)); +exports.UnionConverter = UnionConverter; +//# sourceMappingURL=union.js.map \ No newline at end of file diff --git a/lib/converter/types/union.js.map b/lib/converter/types/union.js.map new file mode 100644 index 000000000..572696f00 --- /dev/null +++ b/lib/converter/types/union.js.map @@ -0,0 +1 @@ +{"version":3,"file":"union.js","sourceRoot":"","sources":["../../../src/lib/converter/types/union.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AAEjC,sBAA8B,0BAA0B,CAAC,CAAA;AACzD,2BAAgE,eAAe,CAAC,CAAA;AAKhF;IAAoC,kCAAsB;IAA1D;QAAoC,8BAAsB;IAkE1D,CAAC;IA7DG,qCAAY,GAAZ,UAAa,OAAe,EAAE,IAAqB;QAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,GAAuB,CAAC;IACjD,CAAC;IAMD,qCAAY,GAAZ,UAAa,OAAe,EAAE,IAAiB;QAC3C,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,MAAkB,CAAC,CAAC;IAC/C,CAAC;IAgBD,oCAAW,GAAX,UAAY,OAAe,EAAE,IAAqB;QAAlD,iBASC;QARG,IAAI,KAAK,GAAU,EAAE,CAAC;QACtB,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YACb,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,EAAlC,CAAkC,CAAC,CAAC;QACtE,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,KAAK,GAAG,EAAE,CAAC;QACf,CAAC;QAED,MAAM,CAAC,IAAI,iBAAS,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAgBD,oCAAW,GAAX,UAAY,OAAe,EAAE,IAAiB;QAA9C,iBASC;QARG,IAAI,KAAY,CAAC;QACjB,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YACrB,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,KAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAxC,CAAwC,CAAC,CAAC;QAC5E,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,KAAK,GAAG,EAAE,CAAC;QACf,CAAC;QAED,MAAM,CAAC,IAAI,iBAAS,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAlEL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,YAAY,EAAC,CAAC;sBAAA;IAmE/B,qBAAC;AAAD,CAAC,AAlED,CAAoC,mCAAsB,GAkEzD;AAlEY,sBAAc,iBAkE1B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, UnionType} from \"../../models/types/index\";\nimport {Component, ConverterTypeComponent, ITypeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:union'})\nexport class UnionConverter extends ConverterTypeComponent implements ITypeConverter\n{\n /**\n * Test whether this converter can handle the given TypeScript node.\n */\n supportsNode(context:Context, node:ts.UnionTypeNode):boolean {\n return node.kind === ts.SyntaxKind.UnionType;\n }\n\n\n /**\n * Test whether this converter can handle the given TypeScript type.\n */\n supportsType(context:Context, type:ts.UnionType):boolean {\n return !!(type.flags & ts.TypeFlags.Union);\n }\n\n\n /**\n * Convert the given union type node to its type reflection.\n *\n * This is a node based converter, see [[convertUnionType]] for the type equivalent.\n *\n * ```\n * var someValue:string|number;\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param node The union type node that should be converted.\n * @returns The type reflection representing the given union type node.\n */\n convertNode(context:Context, node:ts.UnionTypeNode):UnionType {\n var types:Type[] = [];\n if (node.types) {\n types = node.types.map((n) => this.owner.convertType(context, n));\n } else {\n types = [];\n }\n\n return new UnionType(types);\n }\n\n\n /**\n * Convert the given union type to its type reflection.\n *\n * This is a type based converter, see [[convertUnionTypeNode]] for the node equivalent.\n *\n * ```\n * var someValue:string|number;\n * ```\n *\n * @param context The context object describing the current state the converter is in.\n * @param type The union type that should be converted.\n * @returns The type reflection representing the given union type.\n */\n convertType(context:Context, type:ts.UnionType):UnionType {\n var types:Type[];\n if (type && type.types) {\n types = type.types.map((t) => this.owner.convertType(context, null, t));\n } else {\n types = [];\n }\n\n return new UnionType(types);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/types/unknown.d.ts b/lib/converter/types/unknown.d.ts new file mode 100644 index 000000000..aa1a600da --- /dev/null +++ b/lib/converter/types/unknown.d.ts @@ -0,0 +1,9 @@ +import * as ts from "typescript"; +import { Type } from "../../models/types/index"; +import { ConverterTypeComponent, ITypeTypeConverter } from "../components"; +import { Context } from "../context"; +export declare class UnknownConverter extends ConverterTypeComponent implements ITypeTypeConverter { + priority: number; + supportsType(context: Context, type: ts.Type): boolean; + convertType(context: Context, type: ts.Type): Type; +} diff --git a/lib/converter/types/unknown.js b/lib/converter/types/unknown.js new file mode 100644 index 000000000..6d0df53a5 --- /dev/null +++ b/lib/converter/types/unknown.js @@ -0,0 +1,34 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var index_1 = require("../../models/types/index"); +var components_1 = require("../components"); +var UnknownConverter = (function (_super) { + __extends(UnknownConverter, _super); + function UnknownConverter() { + _super.apply(this, arguments); + this.priority = -100; + } + UnknownConverter.prototype.supportsType = function (context, type) { + return true; + }; + UnknownConverter.prototype.convertType = function (context, type) { + var name = context.checker.typeToString(type); + return new index_1.UnknownType(name); + }; + UnknownConverter = __decorate([ + components_1.Component({ name: 'type:unknown' }) + ], UnknownConverter); + return UnknownConverter; +}(components_1.ConverterTypeComponent)); +exports.UnknownConverter = UnknownConverter; +//# sourceMappingURL=unknown.js.map \ No newline at end of file diff --git a/lib/converter/types/unknown.js.map b/lib/converter/types/unknown.js.map new file mode 100644 index 000000000..77d84cbc4 --- /dev/null +++ b/lib/converter/types/unknown.js.map @@ -0,0 +1 @@ +{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/lib/converter/types/unknown.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,sBAAgC,0BAA0B,CAAC,CAAA;AAC3D,2BAAoE,eAAe,CAAC,CAAA;AAKpF;IAAsC,oCAAsB;IAA5D;QAAsC,8BAAsB;QAMxD,aAAQ,GAAU,CAAC,GAAG,CAAC;IA6B3B,CAAC;IAtBG,uCAAY,GAAZ,UAAa,OAAe,EAAE,IAAY;QACtC,MAAM,CAAC,IAAI,CAAC;IAChB,CAAC;IAgBD,sCAAW,GAAX,UAAY,OAAe,EAAE,IAAY;QACrC,IAAI,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAC9C,MAAM,CAAC,IAAI,mBAAW,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAnCL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,cAAc,EAAC,CAAC;wBAAA;IAoCjC,uBAAC;AAAD,CAAC,AAnCD,CAAsC,mCAAsB,GAmC3D;AAnCY,wBAAgB,mBAmC5B,CAAA","sourcesContent":["import * as ts from \"typescript\";\n\nimport {Type, UnknownType} from \"../../models/types/index\";\nimport {Component, ConverterTypeComponent, ITypeTypeConverter} from \"../components\";\nimport {Context} from \"../context\";\n\n\n@Component({name:'type:unknown'})\nexport class UnknownConverter extends ConverterTypeComponent implements ITypeTypeConverter\n{\n /**\n * The priority this converter should be executed with.\n * A higher priority means the converter will be applied earlier.\n */\n priority:number = -100;\n\n\n\n /**\n * Test whether this converter can handle the given TypeScript type.\n */\n supportsType(context:Context, type:ts.Type):boolean {\n return true;\n }\n\n\n /**\n * Convert the given type to its type reflection.\n *\n * This is a type based converter with no node based equivalent.\n *\n * If no other converter is able to reflect a type, this converter will produce a\n * reflection by utilising ts.typeToString() to generate a string representation of the\n * given type.\n *\n * @param context The context object describing the current state the converter is in.\n * @param type The type that should be converted.\n * @returns The type reflection representing the given type.\n */\n convertType(context:Context, type:ts.Type):Type {\n var name = context.checker.typeToString(type);\n return new UnknownType(name);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/utils/base-path.d.ts b/lib/converter/utils/base-path.d.ts new file mode 100644 index 000000000..6628bc1cb --- /dev/null +++ b/lib/converter/utils/base-path.d.ts @@ -0,0 +1,7 @@ +export declare class BasePath { + private basePaths; + add(fileName: string): void; + trim(fileName: string): string; + reset(): void; + static normalize(path: string): string; +} diff --git a/lib/converter/utils/base-path.js b/lib/converter/utils/base-path.js new file mode 100644 index 000000000..4d8466d2b --- /dev/null +++ b/lib/converter/utils/base-path.js @@ -0,0 +1,53 @@ +"use strict"; +var Path = require("path"); +var BasePath = (function () { + function BasePath() { + this.basePaths = []; + } + BasePath.prototype.add = function (fileName) { + var fileDir = Path.dirname(BasePath.normalize(fileName)); + var filePath = fileDir.split('/'); + basePaths: for (var n = 0, c = this.basePaths.length; n < c; n++) { + var basePath = this.basePaths[n].split('/'); + var mMax = Math.min(basePath.length, filePath.length); + for (var m = 0; m < mMax; m++) { + if (basePath[m] == filePath[m]) { + continue; + } + if (m < 1) { + continue basePaths; + } + else { + if (m < basePath.length) { + this.basePaths[n] = basePath.slice(0, m).join('/'); + } + return; + } + } + this.basePaths[n] = basePath.splice(0, mMax).join('/'); + return; + } + this.basePaths.push(fileDir); + }; + BasePath.prototype.trim = function (fileName) { + fileName = BasePath.normalize(fileName); + for (var n = 0, c = this.basePaths.length; n < c; n++) { + var basePath = this.basePaths[n]; + if (fileName.substr(0, basePath.length) == basePath) { + return fileName.substr(basePath.length + 1); + } + } + return fileName; + }; + BasePath.prototype.reset = function () { + this.basePaths = []; + }; + BasePath.normalize = function (path) { + path = path.replace(/\\/g, '/'); + path = path.replace(/^["']+|["']+$/g, ''); + return path.replace(/^([^\:]+)\:\//, function (m, m1) { return m1.toUpperCase() + ':/'; }); + }; + return BasePath; +}()); +exports.BasePath = BasePath; +//# sourceMappingURL=base-path.js.map \ No newline at end of file diff --git a/lib/converter/utils/base-path.js.map b/lib/converter/utils/base-path.js.map new file mode 100644 index 000000000..de3ba9c05 --- /dev/null +++ b/lib/converter/utils/base-path.js.map @@ -0,0 +1 @@ +{"version":3,"file":"base-path.js","sourceRoot":"","sources":["../../../src/lib/converter/utils/base-path.ts"],"names":[],"mappings":";AAAA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAS7B;IAAA;QAKY,cAAS,GAAY,EAAE,CAAC;IAqFpC,CAAC;IA7EG,sBAAG,GAAH,UAAI,QAAe;QACf,IAAI,OAAO,GAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1D,IAAI,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAElC,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/D,IAAI,QAAQ,GAAG,IAAI,CAAC,SAAS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GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACpD,IAAI,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACjC,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;gBAClD,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAChD,CAAC;QACL,CAAC;QAED,MAAM,CAAC,QAAQ,CAAC;IACpB,CAAC;IAMD,wBAAK,GAAL;QACI,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACxB,CAAC;IASM,kBAAS,GAAhB,UAAiB,IAAW;QAExB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAGhC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;QAG1C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,UAAC,CAAC,EAAE,EAAE,IAAK,OAAA,EAAE,CAAC,WAAW,EAAE,GAAG,IAAI,EAAvB,CAAuB,CAAC,CAAC;IAC7E,CAAC;IACL,eAAC;AAAD,CAAC,AA1FD,IA0FC;AA1FY,gBAAQ,WA0FpB,CAAA","sourcesContent":["import * as Path from \"path\";\n\n\n/**\n * Helper class that determines the common base path of a set of files.\n *\n * In the first step all files must be passed to [[add]]. Afterwards [[trim]]\n * can be used to retrieve the shortest path relative to the determined base path.\n */\nexport class BasePath\n{\n /**\n * List of known base paths.\n */\n private basePaths:string[] = [];\n\n\n /**\n * Add the given file path to this set of base paths.\n *\n * @param fileName The absolute filename that should be added to the base path.\n */\n add(fileName:string) {\n var fileDir = Path.dirname(BasePath.normalize(fileName));\n var filePath = fileDir.split('/');\n\n basePaths: for (var n = 0, c = this.basePaths.length; n < c; n++) {\n var basePath = this.basePaths[n].split('/');\n var mMax = Math.min(basePath.length, filePath.length);\n for (var m = 0; m < mMax; m++) {\n if (basePath[m] == filePath[m]) {\n continue;\n }\n\n if (m < 1) {\n // No match at all, try next known base path\n continue basePaths;\n } else {\n // Partial match, trim the known base path\n if (m < basePath.length) {\n this.basePaths[n] = basePath.slice(0, m).join('/');\n }\n return;\n }\n }\n\n // Complete match, exit\n this.basePaths[n] = basePath.splice(0, mMax).join('/');\n return;\n }\n\n // Unknown base path, add it\n this.basePaths.push(fileDir);\n }\n\n\n /**\n * Trim the given filename by the determined base paths.\n *\n * @param fileName The absolute filename that should be trimmed.\n * @returns The trimmed version of the filename.\n */\n trim(fileName:string):string {\n fileName = BasePath.normalize(fileName);\n for (var n = 0, c = this.basePaths.length; n < c; n++) {\n var basePath = this.basePaths[n];\n if (fileName.substr(0, basePath.length) == basePath) {\n return fileName.substr(basePath.length + 1);\n }\n }\n\n return fileName;\n }\n\n\n /**\n * Reset this instance, ignore all paths already passed to [[add]].\n */\n reset() {\n this.basePaths = [];\n }\n\n\n /**\n * Normalize the given path.\n *\n * @param path The path that should be normalized.\n * @returns Normalized version of the given path.\n */\n static normalize(path:string):string {\n // Ensure forward slashes\n path = path.replace(/\\\\/g, '/');\n\n // Remove all surrounding quotes\n path = path.replace(/^[\"']+|[\"']+$/g, '');\n\n // Make Windows drive letters lower case\n return path.replace(/^([^\\:]+)\\:\\//, (m, m1) => m1.toUpperCase() + ':/');\n }\n}\n"]} \ No newline at end of file diff --git a/lib/converter/utils/compiler-host.d.ts b/lib/converter/utils/compiler-host.d.ts new file mode 100644 index 000000000..44f658091 --- /dev/null +++ b/lib/converter/utils/compiler-host.d.ts @@ -0,0 +1,15 @@ +import * as ts from "typescript"; +import { ConverterComponent } from "../components"; +export declare class CompilerHost extends ConverterComponent implements ts.CompilerHost { + private currentDirectory; + getSourceFile(filename: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void): ts.SourceFile; + getDefaultLibFileName(options: ts.CompilerOptions): string; + getDirectories(path: string): string[]; + getCurrentDirectory(): string; + useCaseSensitiveFileNames(): boolean; + fileExists(fileName: string): boolean; + readFile(fileName: string): string; + getCanonicalFileName(fileName: string): string; + getNewLine(): string; + writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; +} diff --git a/lib/converter/utils/compiler-host.js b/lib/converter/utils/compiler-host.js new file mode 100644 index 000000000..18ab06617 --- /dev/null +++ b/lib/converter/utils/compiler-host.js @@ -0,0 +1,58 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var ts = require("typescript"); +var Path = require("path"); +var components_1 = require("../components"); +var ERROR_UNSUPPORTED_FILE_ENCODING = -2147024809; +var CompilerHost = (function (_super) { + __extends(CompilerHost, _super); + function CompilerHost() { + _super.apply(this, arguments); + } + CompilerHost.prototype.getSourceFile = function (filename, languageVersion, onError) { + try { + var text = ts.sys.readFile(filename, this.application.options.getCompilerOptions().charset); + } + catch (e) { + if (onError) { + onError(e.number === ERROR_UNSUPPORTED_FILE_ENCODING ? 'Unsupported file encoding' : e.message); + } + text = ""; + } + return text !== undefined ? ts.createSourceFile(filename, text, languageVersion) : undefined; + }; + CompilerHost.prototype.getDefaultLibFileName = function (options) { + var lib = this.owner.getDefaultLib(); + var path = ts.getDirectoryPath(ts.normalizePath(require.resolve('typescript'))); + return Path.join(path, lib); + }; + CompilerHost.prototype.getDirectories = function (path) { + return ts.sys.getDirectories(path); + }; + CompilerHost.prototype.getCurrentDirectory = function () { + return this.currentDirectory || (this.currentDirectory = ts.sys.getCurrentDirectory()); + }; + CompilerHost.prototype.useCaseSensitiveFileNames = function () { + return ts.sys.useCaseSensitiveFileNames; + }; + CompilerHost.prototype.fileExists = function (fileName) { + return ts.sys.fileExists(fileName); + }; + CompilerHost.prototype.readFile = function (fileName) { + return ts.sys.readFile(fileName); + }; + CompilerHost.prototype.getCanonicalFileName = function (fileName) { + return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); + }; + CompilerHost.prototype.getNewLine = function () { + return ts.sys.newLine; + }; + CompilerHost.prototype.writeFile = function (fileName, data, writeByteOrderMark, onError) { }; + return CompilerHost; +}(components_1.ConverterComponent)); +exports.CompilerHost = CompilerHost; +//# sourceMappingURL=compiler-host.js.map \ No newline at end of file diff --git a/lib/converter/utils/compiler-host.js.map b/lib/converter/utils/compiler-host.js.map new file mode 100644 index 000000000..0216672fc --- /dev/null +++ b/lib/converter/utils/compiler-host.js.map @@ -0,0 +1 @@ +{"version":3,"file":"compiler-host.js","sourceRoot":"","sources":["../../../src/lib/converter/utils/compiler-host.ts"],"names":[],"mappings":";;;;;;AAAA,IAAY,EAAE,WAAM,YAAY,CAAC,CAAA;AACjC,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAE7B,2BAAiC,eAAe,CAAC,CAAA;AAMjD,IAAM,+BAA+B,GAAG,CAAC,UAAU,CAAC;AAMpD;IAAkC,gCAAkB;IAApD;QAAkC,8BAAkB;IA4IpD,CAAC;IAxHG,oCAAa,GAAb,UAAc,QAAe,EAAE,eAA+B,EAAE,OAAmC;QAC/F,IAAI,CAAC;YACD,IAAI,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,OAAO,CAAC,CAAC;QAChG,CAAE;QAAA,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACT,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;gBACV,OAAO,CAAC,CAAC,CAAC,MAAM,KAAK,+BAA+B,GAAG,2BAA2B,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;YACpG,CAAC;YACD,IAAI,GAAG,EAAE,CAAC;QACd,CAAC;QAED,MAAM,CAAC,IAAI,KA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,OAAO,CAAC;IAC1B,CAAC;IAeD,gCAAS,GAAT,UAAU,QAAe,EAAE,IAAW,EAAE,kBAA0B,EAAE,OAAkC,IAAI,CAAC;IAC/G,mBAAC;AAAD,CAAC,AA5ID,CAAkC,+BAAkB,GA4InD;AA5IY,oBAAY,eA4IxB,CAAA","sourcesContent":["import * as ts from \"typescript\";\nimport * as Path from \"path\";\n\nimport {ConverterComponent} from \"../components\";\n\n\n/**\n * Return code of ts.sys.readFile when the file encoding is unsupported.\n */\nconst ERROR_UNSUPPORTED_FILE_ENCODING = -2147024809;\n\n\n/**\n * CompilerHost implementation\n */\nexport class CompilerHost extends ConverterComponent implements ts.CompilerHost\n{\n\n /**\n * The full path of the current directory. Result cache of [[getCurrentDirectory]].\n */\n private currentDirectory:string;\n\n\n\n /**\n * Return an instance of ts.SourceFile representing the given file.\n *\n * Implementation of ts.CompilerHost.getSourceFile()\n *\n * @param filename The path and name of the file that should be loaded.\n * @param languageVersion The script target the file should be interpreted with.\n * @param onError A callback that will be invoked if an error occurs.\n * @returns An instance of ts.SourceFile representing the given file.\n */\n getSourceFile(filename:string, languageVersion:ts.ScriptTarget, onError?: (message: string) => void):ts.SourceFile {\n try {\n var text = ts.sys.readFile(filename, this.application.options.getCompilerOptions().charset);\n } catch (e) {\n if (onError) {\n onError(e.number === ERROR_UNSUPPORTED_FILE_ENCODING ? 'Unsupported file encoding' : e.message);\n }\n text = \"\";\n }\n\n return text !== undefined ? ts.createSourceFile(filename, text, languageVersion) : undefined;\n }\n\n\n /**\n * Return the full path of the default library that should be used.\n *\n * Implementation of ts.CompilerHost.getDefaultLibFilename()\n *\n * @returns The full path of the default library.\n */\n getDefaultLibFileName(options:ts.CompilerOptions):string {\n var lib = this.owner.getDefaultLib();\n var path = ts.getDirectoryPath(ts.normalizePath(require.resolve('typescript')));\n return Path.join(path, lib);\n }\n\n getDirectories(path: string): string[] {\n return ts.sys.getDirectories(path);\n }\n\n\n /**\n * Return the full path of the current directory.\n *\n * Implementation of ts.CompilerHost.getCurrentDirectory()\n *\n * @returns The full path of the current directory.\n */\n getCurrentDirectory():string {\n return this.currentDirectory || (this.currentDirectory = ts.sys.getCurrentDirectory());\n }\n\n\n /**\n * Return whether file names are case sensitive on the current platform or not.\n *\n * Implementation of ts.CompilerHost.useCaseSensitiveFileNames()\n *\n * @returns TRUE if file names are case sensitive on the current platform, FALSE otherwise.\n */\n useCaseSensitiveFileNames():boolean {\n return ts.sys.useCaseSensitiveFileNames;\n }\n\n\n /**\n * Check whether the given file exists.\n *\n * Implementation of ts.CompilerHost.fileExists(fileName)\n *\n * @param fileName\n * @returns {boolean}\n */\n fileExists(fileName:string):boolean {\n return ts.sys.fileExists(fileName);\n }\n\n\n /**\n * Return the contents of the given file.\n *\n * Implementation of ts.CompilerHost.readFile(fileName)\n *\n * @param fileName\n * @returns {string}\n */\n readFile(fileName:string):string {\n return ts.sys.readFile(fileName);\n }\n\n\n /**\n * Return the canonical file name of the given file.\n *\n * Implementation of ts.CompilerHost.getCanonicalFileName()\n *\n * @param fileName The file name whose canonical variant should be resolved.\n * @returns The canonical file name of the given file.\n */\n getCanonicalFileName(fileName:string):string {\n return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();\n }\n\n\n /**\n * Return the new line char sequence of the current platform.\n *\n * Implementation of ts.CompilerHost.getNewLine()\n *\n * @returns The new line char sequence of the current platform.\n */\n getNewLine():string {\n return ts.sys.newLine;\n }\n\n\n /**\n * Write a compiled javascript file to disc.\n *\n * As TypeDoc will not emit compiled javascript files this is a null operation.\n *\n * Implementation of ts.CompilerHost.writeFile()\n *\n * @param fileName The name of the file that should be written.\n * @param data The contents of the file.\n * @param writeByteOrderMark Whether the UTF-8 BOM should be written or not.\n * @param onError A callback that will be invoked if an error occurs.\n */\n writeFile(fileName:string, data:string, writeByteOrderMark:boolean, onError?:(message: string) => void) { }\n}\n"]} \ No newline at end of file diff --git a/lib/models/ReflectionGroup.d.ts b/lib/models/ReflectionGroup.d.ts new file mode 100644 index 000000000..ec3b547a0 --- /dev/null +++ b/lib/models/ReflectionGroup.d.ts @@ -0,0 +1,16 @@ +import { Reflection, ReflectionKind } from "./reflections/abstract"; +export declare class ReflectionGroup { + title: string; + kind: ReflectionKind; + children: Reflection[]; + cssClasses: string; + allChildrenHaveOwnDocument: Function; + allChildrenAreInherited: boolean; + allChildrenArePrivate: boolean; + allChildrenAreProtectedOrPrivate: boolean; + allChildrenAreExternal: boolean; + someChildrenAreExported: boolean; + constructor(title: string, kind: ReflectionKind); + private getAllChildrenHaveOwnDocument(); + toObject(): any; +} diff --git a/lib/models/ReflectionGroup.js b/lib/models/ReflectionGroup.js new file mode 100644 index 000000000..bdc9d18c1 --- /dev/null +++ b/lib/models/ReflectionGroup.js @@ -0,0 +1,34 @@ +"use strict"; +var ReflectionGroup = (function () { + function ReflectionGroup(title, kind) { + var _this = this; + this.children = []; + this.title = title; + this.kind = kind; + this.allChildrenHaveOwnDocument = (function () { return _this.getAllChildrenHaveOwnDocument(); }); + } + ReflectionGroup.prototype.getAllChildrenHaveOwnDocument = function () { + var onlyOwnDocuments = true; + this.children.forEach(function (child) { + onlyOwnDocuments = onlyOwnDocuments && child.hasOwnDocument; + }); + return onlyOwnDocuments; + }; + ReflectionGroup.prototype.toObject = function () { + var result = { + title: this.title, + kind: this.kind + }; + if (this.children) { + var children = []; + this.children.forEach(function (child) { + children.push(child.id); + }); + result['children'] = children; + } + return result; + }; + return ReflectionGroup; +}()); +exports.ReflectionGroup = ReflectionGroup; +//# sourceMappingURL=ReflectionGroup.js.map \ No newline at end of file diff --git a/lib/models/ReflectionGroup.js.map b/lib/models/ReflectionGroup.js.map new file mode 100644 index 000000000..da8d196d2 --- /dev/null +++ b/lib/models/ReflectionGroup.js.map @@ -0,0 +1 @@ +{"version":3,"file":"ReflectionGroup.js","sourceRoot":"","sources":["../../src/lib/models/ReflectionGroup.ts"],"names":[],"mappings":";AAWA;IA+DI,yBAAY,KAAY,EAAE,IAAmB;QA/DjD,iBAwGC;QAzFG,aAAQ,GAAgB,EAAE,CAAC;QAiDvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,IAAI,CAAC,0BAA0B,GAAG,CAAC,cAAM,OAAA,KAAI,CAAC,6BAA6B,EAAE,EAApC,CAAoC,CAAC,CAAC;IACnF,CAAC;IAMO,uDAA6B,GAArC;QACI,IAAI,gBAAgB,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAC,KAAK;YACxB,gBAAgB,GAAG,gBAAgB,IAAI,KAAK,CAAC,cAAc,CAAC;QAChE,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,gBAAgB,CAAC;IAC5B,CAAC;IAMD,kCAAQ,GAAR;QACI,IAAI,MAAM,GAAG;YACT,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAG,IAAI,CAAC,IAAI;SACnB,CAAC;QAEF,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAChB,IAAI,QAAQ,GAAS,EAAE,CAAC;YACxB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAC,KAAK;gBACxB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YAC3B,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC;QAClC,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IACL,sBAAC;AAAD,CAAC,AAxGD,IAwGC;AAxGY,uBAAe,kBAwG3B,CAAA","sourcesContent":["import {Reflection, ReflectionKind} from \"./reflections/abstract\";\nimport {DeclarationReflection} from \"./reflections/declaration\";\n\n\n/**\n * A group of reflections. All reflections in a group are of the same kind.\n *\n * Reflection groups are created by the ´GroupHandler´ in the resolving phase\n * of the dispatcher. The main purpose of groups is to be able to more easily\n * render human readable children lists in templates.\n */\nexport class ReflectionGroup\n{\n /**\n * The title, a string representation of the typescript kind, of this group.\n */\n title:string;\n\n /**\n * The original typescript kind of the children of this group.\n */\n kind:ReflectionKind;\n\n /**\n * All reflections of this group.\n */\n children:Reflection[] = [];\n\n /**\n * A list of generated css classes that should be applied to representations of this\n * group in the generated markup.\n */\n cssClasses:string;\n\n /**\n * Do all children of this group have a separate document?\n *\n * A bound representation of the ´ReflectionGroup.getAllChildrenHaveOwnDocument´\n * that can be used within templates.\n */\n allChildrenHaveOwnDocument:Function;\n\n /**\n * Are all children inherited members?\n */\n allChildrenAreInherited:boolean;\n\n /**\n * Are all children private members?\n */\n allChildrenArePrivate:boolean;\n\n /**\n * Are all children private or protected members?\n */\n allChildrenAreProtectedOrPrivate:boolean;\n\n /**\n * Are all children external members?\n */\n allChildrenAreExternal:boolean;\n\n /**\n * Are any children exported declarations?\n */\n someChildrenAreExported:boolean;\n\n\n /**\n * Create a new ReflectionGroup instance.\n *\n * @param title The title of this group.\n * @param kind The original typescript kind of the children of this group.\n */\n constructor(title:string, kind:ReflectionKind) {\n this.title = title;\n this.kind = kind;\n\n this.allChildrenHaveOwnDocument = (() => this.getAllChildrenHaveOwnDocument());\n }\n\n\n /**\n * Do all children of this group have a separate document?\n */\n private getAllChildrenHaveOwnDocument():boolean {\n var onlyOwnDocuments = true;\n this.children.forEach((child) => {\n onlyOwnDocuments = onlyOwnDocuments && child.hasOwnDocument;\n });\n\n return onlyOwnDocuments;\n }\n\n\n /**\n * Return a raw object representation of this reflection group.\n */\n toObject():any {\n var result = {\n title: this.title,\n kind: this.kind\n };\n\n if (this.children) {\n var children:any[] = [];\n this.children.forEach((child) => {\n children.push(child.id)\n });\n\n result['children'] = children;\n }\n\n return result;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/comments/comment.d.ts b/lib/models/comments/comment.d.ts new file mode 100644 index 000000000..8e1b3226b --- /dev/null +++ b/lib/models/comments/comment.d.ts @@ -0,0 +1,13 @@ +import { CommentTag } from "./tag"; +export declare class Comment { + shortText: string; + text: string; + returns: string; + tags: CommentTag[]; + constructor(shortText?: string, text?: string); + hasVisibleComponent(): boolean; + hasTag(tagName: string): boolean; + getTag(tagName: string, paramName?: string): CommentTag; + copyFrom(comment: Comment): void; + toObject(): any; +} diff --git a/lib/models/comments/comment.js b/lib/models/comments/comment.js new file mode 100644 index 000000000..b9db35dfd --- /dev/null +++ b/lib/models/comments/comment.js @@ -0,0 +1,55 @@ +"use strict"; +var tag_1 = require("./tag"); +var Comment = (function () { + function Comment(shortText, text) { + this.shortText = shortText || ''; + this.text = text || ''; + } + Comment.prototype.hasVisibleComponent = function () { + return (!!this.shortText || !!this.text || !!this.tags); + }; + Comment.prototype.hasTag = function (tagName) { + if (!this.tags) + return false; + for (var i = 0, c = this.tags.length; i < c; i++) { + if (this.tags[i].tagName == tagName) { + return true; + } + } + return false; + }; + Comment.prototype.getTag = function (tagName, paramName) { + if (!this.tags) + return null; + for (var i = 0, c = this.tags.length; i < c; i++) { + var tag = this.tags[i]; + if (tag.tagName == tagName && (paramName == void 0 || tag.paramName == paramName)) { + return this.tags[i]; + } + } + return null; + }; + Comment.prototype.copyFrom = function (comment) { + this.shortText = comment.shortText; + this.text = comment.text; + this.returns = comment.returns; + this.tags = comment.tags ? comment.tags.map(function (tag) { return new tag_1.CommentTag(tag.tagName, tag.paramName, tag.text); }) : null; + }; + Comment.prototype.toObject = function () { + var result = {}; + if (this.shortText) + result.shortText = this.shortText; + if (this.text) + result.text = this.text; + if (this.returns) + result.returns = this.returns; + if (this.tags && this.tags.length) { + result.tags = []; + this.tags.forEach(function (tag) { return result.tags.push(tag.toObject()); }); + } + return result; + }; + return Comment; +}()); +exports.Comment = Comment; +//# sourceMappingURL=comment.js.map \ No newline at end of file diff --git a/lib/models/comments/comment.js.map b/lib/models/comments/comment.js.map new file mode 100644 index 000000000..5fd78d792 --- /dev/null +++ b/lib/models/comments/comment.js.map @@ -0,0 +1 @@ +{"version":3,"file":"comment.js","sourceRoot":"","sources":["../../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AAI,CAAC,OAAO,CAAC,UAAC,GAAG,IAAK,OAAA,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,EAAhC,CAAgC,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IACL,cAAC;AAAD,CAAC,AA/GD,IA+GC;AA/GY,eAAO,UA+GnB,CAAA","sourcesContent":["import {CommentTag} from \"./tag\";\n\n\n/**\n * A model that represents a javadoc comment.\n *\n * Instances of this model are created by the [[CommentHandler]]. You can retrieve comments\n * through the [[BaseReflection.comment]] property.\n */\nexport class Comment\n{\n /**\n * The abstract of the comment. TypeDoc interprets the first paragraph of a comment\n * as the abstract.\n */\n shortText:string;\n\n /**\n * The full body text of the comment. Excludes the [[shortText]].\n */\n text:string;\n\n /**\n * The text of the ```@returns``` tag if present.\n */\n returns:string;\n\n /**\n * All associated javadoc tags.\n */\n tags:CommentTag[];\n\n\n\n /**\n * Creates a new Comment instance.\n */\n constructor(shortText?:string, text?:string) {\n this.shortText = shortText || '';\n this.text = text || '';\n }\n\n\n /**\n * Has this comment a visible component?\n *\n * @returns TRUE when this comment has a visible component.\n */\n hasVisibleComponent():boolean {\n return (!!this.shortText || !!this.text || !!this.tags);\n }\n\n\n /**\n * Test whether this comment contains a tag with the given name.\n *\n * @param tagName The name of the tag to look for.\n * @returns TRUE when this comment contains a tag with the given name, otherwise FALSE.\n */\n hasTag(tagName:string):boolean {\n if (!this.tags) return false;\n for (var i = 0, c = this.tags.length; i < c; i++) {\n if (this.tags[i].tagName == tagName) {\n return true;\n }\n }\n return false;\n }\n\n\n /**\n * Return the first tag with the given name.\n *\n * You can optionally pass a parameter name that should be searched to.\n *\n * @param tagName The name of the tag to look for.\n * @param paramName An optional parameter name to look for.\n * @returns The found tag or NULL.\n */\n getTag(tagName:string, paramName?:string):CommentTag {\n if (!this.tags) return null;\n for (var i = 0, c = this.tags.length; i < c; i++) {\n var tag = this.tags[i];\n if (tag.tagName == tagName && (paramName == void 0 || tag.paramName == paramName)) {\n return this.tags[i];\n }\n }\n return null;\n }\n\n\n /**\n * Copy the data of the given comment into this comment.\n *\n * @param comment\n */\n copyFrom(comment:Comment) {\n this.shortText = comment.shortText;\n this.text = comment.text;\n this.returns = comment.returns;\n this.tags = comment.tags ? comment.tags.map((tag) => new CommentTag(tag.tagName, tag.paramName, tag.text)) : null;\n }\n\n\n /**\n * Return a raw object representation of this comment.\n */\n toObject():any {\n var result:any = {};\n if (this.shortText) result.shortText = this.shortText;\n if (this.text) result.text = this.text;\n if (this.returns) result.returns = this.returns;\n\n if (this.tags && this.tags.length) {\n result.tags = [];\n this.tags.forEach((tag) => result.tags.push(tag.toObject()));\n }\n\n return result;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/comments/index.d.ts b/lib/models/comments/index.d.ts new file mode 100644 index 000000000..eb0c512ee --- /dev/null +++ b/lib/models/comments/index.d.ts @@ -0,0 +1,2 @@ +export { Comment } from "./comment"; +export { CommentTag } from "./tag"; diff --git a/lib/models/comments/index.js b/lib/models/comments/index.js new file mode 100644 index 000000000..6d2e3b13b --- /dev/null +++ b/lib/models/comments/index.js @@ -0,0 +1,6 @@ +"use strict"; +var comment_1 = require("./comment"); +exports.Comment = comment_1.Comment; +var tag_1 = require("./tag"); +exports.CommentTag = tag_1.CommentTag; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/models/comments/index.js.map b/lib/models/comments/index.js.map new file mode 100644 index 000000000..0914a33ca --- /dev/null +++ b/lib/models/comments/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/models/comments/index.ts"],"names":[],"mappings":";AAAA,wBAAsB,WAAW,CAAC;AAA1B,oCAA0B;AAClC,oBAAyB,OAAO,CAAC;AAAzB,sCAAyB","sourcesContent":["export {Comment} from \"./comment\";\nexport {CommentTag} from \"./tag\";\n"]} \ No newline at end of file diff --git a/lib/models/comments/tag.d.ts b/lib/models/comments/tag.d.ts new file mode 100644 index 000000000..0bfe05a2b --- /dev/null +++ b/lib/models/comments/tag.d.ts @@ -0,0 +1,7 @@ +export declare class CommentTag { + tagName: string; + paramName: string; + text: string; + constructor(tagName: string, paramName?: string, text?: string); + toObject(): any; +} diff --git a/lib/models/comments/tag.js b/lib/models/comments/tag.js new file mode 100644 index 000000000..e4790b2ec --- /dev/null +++ b/lib/models/comments/tag.js @@ -0,0 +1,21 @@ +"use strict"; +var CommentTag = (function () { + function CommentTag(tagName, paramName, text) { + this.tagName = tagName; + this.paramName = paramName || ''; + this.text = text || ''; + } + CommentTag.prototype.toObject = function () { + var result = { + tag: this.tagName, + text: this.text + }; + if (this.paramName) { + result.param = this.paramName; + } + return result; + }; + return CommentTag; +}()); +exports.CommentTag = CommentTag; +//# sourceMappingURL=tag.js.map \ No newline at end of file diff --git a/lib/models/comments/tag.js.map b/lib/models/comments/tag.js.map new file mode 100644 index 000000000..e31181f48 --- /dev/null +++ b/lib/models/comments/tag.js.map @@ -0,0 +1 @@ +{"version":3,"file":"tag.js","sourceRoot":"","sources":["../../../src/lib/models/comments/tag.ts"],"names":[],"mappings":";AAKA;IAqBI,oBAAY,OAAc,EAAE,SAAiB,EAAE,IAAY;QACvD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,EAAE,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAC3B,CAAC;IAMD,6BAAQ,GAAR;QACI,IAAI,MAAM,GAAO;YACb,GAAG,EAAG,IAAI,CAAC,OAAO;YAClB,IAAI,EAAE,IAAI,CAAC,IAAI;SAClB,CAAC;QAEF,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;YACjB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC;QAClC,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IACL,iBAAC;AAAD,CAAC,AA3CD,IA2CC;AA3CY,kBAAU,aA2CtB,CAAA","sourcesContent":["/**\n * A model that represents a single javadoc comment tag.\n *\n * Tags are stored in the [[Comment.tags]] property.\n */\nexport class CommentTag\n{\n /**\n * The name of this tag.\n */\n tagName:string;\n\n /**\n * The name of the related parameter when this is a ```@param``` tag.\n */\n paramName:string;\n\n /**\n * The actual body text of this tag.\n */\n text:string;\n\n\n /**\n * Create a new CommentTag instance.\n */\n constructor(tagName:string, paramName?:string, text?:string) {\n this.tagName = tagName;\n this.paramName = paramName || '';\n this.text = text || '';\n }\n\n\n /**\n * Return a raw object representation of this tag.\n */\n toObject():any {\n var result:any = {\n tag: this.tagName,\n text: this.text\n };\n\n if (this.paramName) {\n result.param = this.paramName;\n }\n\n return result;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/index.d.ts b/lib/models/index.d.ts new file mode 100644 index 000000000..b61aecd10 --- /dev/null +++ b/lib/models/index.d.ts @@ -0,0 +1,4 @@ +export * from "./reflections/index"; +export * from "./types/index"; +export * from "./comments/index"; +export * from "./sources/index"; diff --git a/lib/models/index.js b/lib/models/index.js new file mode 100644 index 000000000..a5a41938f --- /dev/null +++ b/lib/models/index.js @@ -0,0 +1,9 @@ +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +__export(require("./reflections/index")); +__export(require("./types/index")); +__export(require("./comments/index")); +__export(require("./sources/index")); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/models/index.js.map b/lib/models/index.js.map new file mode 100644 index 000000000..6abfed84f --- /dev/null +++ b/lib/models/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/models/index.ts"],"names":[],"mappings":";;;;AAAA,iBAAc,qBAAqB,CAAC,EAAA;AACpC,iBAAc,eAAe,CAAC,EAAA;AAC9B,iBAAc,kBAAkB,CAAC,EAAA;AACjC,iBAAc,iBAAiB,CAAC,EAAA","sourcesContent":["export * from \"./reflections/index\";\nexport * from \"./types/index\";\nexport * from \"./comments/index\";\nexport * from \"./sources/index\";\n"]} \ No newline at end of file diff --git a/lib/models/reflections/abstract.d.ts b/lib/models/reflections/abstract.d.ts new file mode 100644 index 000000000..adb20276c --- /dev/null +++ b/lib/models/reflections/abstract.d.ts @@ -0,0 +1,125 @@ +import { ISourceReference } from "../sources/file"; +import { Type } from "../types/index"; +import { Comment } from "../comments/comment"; +import { TypeParameterReflection } from "./type-parameter"; +export declare function resetReflectionID(): void; +export declare enum ReflectionKind { + Global = 0, + ExternalModule = 1, + Module = 2, + Enum = 4, + EnumMember = 16, + Variable = 32, + Function = 64, + Class = 128, + Interface = 256, + Constructor = 512, + Property = 1024, + Method = 2048, + CallSignature = 4096, + IndexSignature = 8192, + ConstructorSignature = 16384, + Parameter = 32768, + TypeLiteral = 65536, + TypeParameter = 131072, + Accessor = 262144, + GetSignature = 524288, + SetSignature = 1048576, + ObjectLiteral = 2097152, + TypeAlias = 4194304, + Event = 8388608, + ClassOrInterface = 384, + VariableOrProperty = 1056, + FunctionOrMethod = 2112, + SomeSignature = 1601536, + SomeModule = 3, +} +export declare enum ReflectionFlag { + Private = 1, + Protected = 2, + Public = 4, + Static = 8, + Exported = 16, + ExportAssignment = 32, + External = 64, + Optional = 128, + DefaultValue = 256, + Rest = 512, + ConstructorProperty = 1024, +} +export interface IReflectionFlags extends Array { + flags?: ReflectionFlag; + isPrivate?: boolean; + isProtected?: boolean; + isPublic?: boolean; + isStatic?: boolean; + isExported?: boolean; + isExternal?: boolean; + isOptional?: boolean; + isRest?: boolean; + hasExportAssignment?: boolean; + isConstructorProperty?: boolean; +} +export interface IDefaultValueContainer extends Reflection { + defaultValue: string; +} +export interface ITypeContainer extends Reflection { + type: Type; +} +export interface ITypeParameterContainer extends Reflection { + typeParameters: TypeParameterReflection[]; +} +export declare enum TraverseProperty { + Children = 0, + Parameters = 1, + TypeLiteral = 2, + TypeParameter = 3, + Signatures = 4, + IndexSignature = 5, + GetSignature = 6, + SetSignature = 7, +} +export interface ITraverseCallback { + (reflection: Reflection, property: TraverseProperty): void; +} +export interface IDecorator { + name: string; + type?: Type; + arguments?: any; +} +export declare abstract class Reflection { + id: number; + name: string; + originalName: string; + kind: ReflectionKind; + kindString: string; + flags: IReflectionFlags; + parent: Reflection; + comment: Comment; + sources: ISourceReference[]; + decorators: IDecorator[]; + decorates: Type[]; + url: string; + anchor: string; + hasOwnDocument: boolean; + cssClasses: string; + private _alias; + private _aliases; + constructor(parent?: Reflection, name?: string, kind?: ReflectionKind); + kindOf(kind: ReflectionKind): boolean; + kindOf(kind: ReflectionKind[]): boolean; + getFullName(separator?: string): string; + setFlag(flag: ReflectionFlag, value?: boolean): void; + getAlias(): string; + hasComment(): boolean; + hasGetterOrSetter(): boolean; + getChildByName(name: string): Reflection; + getChildByName(names: string[]): Reflection; + isProject(): boolean; + findReflectionByName(name: string): Reflection; + findReflectionByName(names: string[]): Reflection; + traverse(callback: ITraverseCallback): void; + toObject(): any; + toString(): string; + toStringHierarchy(indent?: string): string; +} diff --git a/lib/models/reflections/abstract.js b/lib/models/reflections/abstract.js new file mode 100644 index 000000000..a903483c0 --- /dev/null +++ b/lib/models/reflections/abstract.js @@ -0,0 +1,287 @@ +"use strict"; +var REFLECTION_ID = 0; +function resetReflectionID() { + REFLECTION_ID = 0; +} +exports.resetReflectionID = resetReflectionID; +(function (ReflectionKind) { + ReflectionKind[ReflectionKind["Global"] = 0] = "Global"; + ReflectionKind[ReflectionKind["ExternalModule"] = 1] = "ExternalModule"; + ReflectionKind[ReflectionKind["Module"] = 2] = "Module"; + ReflectionKind[ReflectionKind["Enum"] = 4] = "Enum"; + ReflectionKind[ReflectionKind["EnumMember"] = 16] = "EnumMember"; + ReflectionKind[ReflectionKind["Variable"] = 32] = "Variable"; + ReflectionKind[ReflectionKind["Function"] = 64] = "Function"; + ReflectionKind[ReflectionKind["Class"] = 128] = "Class"; + ReflectionKind[ReflectionKind["Interface"] = 256] = "Interface"; + ReflectionKind[ReflectionKind["Constructor"] = 512] = "Constructor"; + ReflectionKind[ReflectionKind["Property"] = 1024] = "Property"; + ReflectionKind[ReflectionKind["Method"] = 2048] = "Method"; + ReflectionKind[ReflectionKind["CallSignature"] = 4096] = "CallSignature"; + ReflectionKind[ReflectionKind["IndexSignature"] = 8192] = "IndexSignature"; + ReflectionKind[ReflectionKind["ConstructorSignature"] = 16384] = "ConstructorSignature"; + ReflectionKind[ReflectionKind["Parameter"] = 32768] = "Parameter"; + ReflectionKind[ReflectionKind["TypeLiteral"] = 65536] = "TypeLiteral"; + ReflectionKind[ReflectionKind["TypeParameter"] = 131072] = "TypeParameter"; + ReflectionKind[ReflectionKind["Accessor"] = 262144] = "Accessor"; + ReflectionKind[ReflectionKind["GetSignature"] = 524288] = "GetSignature"; + ReflectionKind[ReflectionKind["SetSignature"] = 1048576] = "SetSignature"; + ReflectionKind[ReflectionKind["ObjectLiteral"] = 2097152] = "ObjectLiteral"; + ReflectionKind[ReflectionKind["TypeAlias"] = 4194304] = "TypeAlias"; + ReflectionKind[ReflectionKind["Event"] = 8388608] = "Event"; + ReflectionKind[ReflectionKind["ClassOrInterface"] = 384] = "ClassOrInterface"; + ReflectionKind[ReflectionKind["VariableOrProperty"] = 1056] = "VariableOrProperty"; + ReflectionKind[ReflectionKind["FunctionOrMethod"] = 2112] = "FunctionOrMethod"; + ReflectionKind[ReflectionKind["SomeSignature"] = 1601536] = "SomeSignature"; + ReflectionKind[ReflectionKind["SomeModule"] = 3] = "SomeModule"; +})(exports.ReflectionKind || (exports.ReflectionKind = {})); +var ReflectionKind = exports.ReflectionKind; +(function (ReflectionFlag) { + ReflectionFlag[ReflectionFlag["Private"] = 1] = "Private"; + ReflectionFlag[ReflectionFlag["Protected"] = 2] = "Protected"; + ReflectionFlag[ReflectionFlag["Public"] = 4] = "Public"; + ReflectionFlag[ReflectionFlag["Static"] = 8] = "Static"; + ReflectionFlag[ReflectionFlag["Exported"] = 16] = "Exported"; + ReflectionFlag[ReflectionFlag["ExportAssignment"] = 32] = "ExportAssignment"; + ReflectionFlag[ReflectionFlag["External"] = 64] = "External"; + ReflectionFlag[ReflectionFlag["Optional"] = 128] = "Optional"; + ReflectionFlag[ReflectionFlag["DefaultValue"] = 256] = "DefaultValue"; + ReflectionFlag[ReflectionFlag["Rest"] = 512] = "Rest"; + ReflectionFlag[ReflectionFlag["ConstructorProperty"] = 1024] = "ConstructorProperty"; +})(exports.ReflectionFlag || (exports.ReflectionFlag = {})); +var ReflectionFlag = exports.ReflectionFlag; +var relevantFlags = [ + ReflectionFlag.Private, + ReflectionFlag.Protected, + ReflectionFlag.Static, + ReflectionFlag.ExportAssignment, + ReflectionFlag.Optional, + ReflectionFlag.DefaultValue, + ReflectionFlag.Rest +]; +(function (TraverseProperty) { + TraverseProperty[TraverseProperty["Children"] = 0] = "Children"; + TraverseProperty[TraverseProperty["Parameters"] = 1] = "Parameters"; + TraverseProperty[TraverseProperty["TypeLiteral"] = 2] = "TypeLiteral"; + TraverseProperty[TraverseProperty["TypeParameter"] = 3] = "TypeParameter"; + TraverseProperty[TraverseProperty["Signatures"] = 4] = "Signatures"; + TraverseProperty[TraverseProperty["IndexSignature"] = 5] = "IndexSignature"; + TraverseProperty[TraverseProperty["GetSignature"] = 6] = "GetSignature"; + TraverseProperty[TraverseProperty["SetSignature"] = 7] = "SetSignature"; +})(exports.TraverseProperty || (exports.TraverseProperty = {})); +var TraverseProperty = exports.TraverseProperty; +var Reflection = (function () { + function Reflection(parent, name, kind) { + this.name = ''; + this.flags = []; + this.id = REFLECTION_ID++; + this.parent = parent; + this.name = name; + this.originalName = name; + this.kind = kind; + } + Reflection.prototype.kindOf = function (kind) { + if (Array.isArray(kind)) { + for (var i = 0, c = kind.length; i < c; i++) { + if ((this.kind & kind[i]) !== 0) { + return true; + } + } + return false; + } + else { + return (this.kind & kind) !== 0; + } + }; + Reflection.prototype.getFullName = function (separator) { + if (separator === void 0) { separator = '.'; } + if (this.parent && !this.parent.isProject()) { + return this.parent.getFullName(separator) + separator + this.name; + } + else { + return this.name; + } + }; + Reflection.prototype.setFlag = function (flag, value) { + if (value === void 0) { value = true; } + var name, index; + if (relevantFlags.indexOf(flag) != -1) { + name = ReflectionFlag[flag]; + name = name.replace(/(.)([A-Z])/g, function (m, a, b) { return a + ' ' + b.toLowerCase(); }); + index = this.flags.indexOf(name); + } + if (value) { + this.flags.flags |= flag; + if (name && index == -1) { + this.flags.push(name); + } + } + else { + this.flags.flags &= ~flag; + if (name && index != -1) { + this.flags.splice(index, 1); + } + } + switch (flag) { + case ReflectionFlag.Private: + this.flags.isPrivate = value; + if (value) { + this.setFlag(ReflectionFlag.Protected, false); + this.setFlag(ReflectionFlag.Public, false); + } + break; + case ReflectionFlag.Protected: + this.flags.isProtected = value; + if (value) { + this.setFlag(ReflectionFlag.Private, false); + this.setFlag(ReflectionFlag.Public, false); + } + break; + case ReflectionFlag.Public: + this.flags.isPublic = value; + if (value) { + this.setFlag(ReflectionFlag.Private, false); + this.setFlag(ReflectionFlag.Protected, false); + } + break; + case ReflectionFlag.Static: + this.flags.isStatic = value; + break; + case ReflectionFlag.Exported: + this.flags.isExported = value; + break; + case ReflectionFlag.External: + this.flags.isExternal = value; + break; + case ReflectionFlag.Optional: + this.flags.isOptional = value; + break; + case ReflectionFlag.Rest: + this.flags.isRest = value; + break; + case ReflectionFlag.ExportAssignment: + this.flags.hasExportAssignment = value; + break; + case ReflectionFlag.ConstructorProperty: + this.flags.isConstructorProperty = value; + break; + } + }; + Reflection.prototype.getAlias = function () { + if (!this._alias) { + var alias = this.name.replace(/[^a-z0-9]/gi, '_').toLowerCase(); + if (alias == '') { + alias = 'reflection-' + this.id; + } + var target = this; + while (target.parent && !target.parent.isProject() && !target.hasOwnDocument) { + target = target.parent; + } + if (!target._aliases) + target._aliases = []; + var suffix = '', index = 0; + while (target._aliases.indexOf(alias + suffix) != -1) { + suffix = '-' + (++index).toString(); + } + alias += suffix; + target._aliases.push(alias); + this._alias = alias; + } + return this._alias; + }; + Reflection.prototype.hasComment = function () { + return (this.comment && this.comment.hasVisibleComponent()); + }; + Reflection.prototype.hasGetterOrSetter = function () { + return false; + }; + Reflection.prototype.getChildByName = function (arg) { + var names = Array.isArray(arg) ? arg : arg.split('.'); + var name = names[0]; + var result = null; + this.traverse(function (child) { + if (child.name == name) { + if (names.length <= 1) { + result = child; + } + else if (child) { + result = child.getChildByName(names.slice(1)); + } + } + }); + return result; + }; + Reflection.prototype.isProject = function () { + return false; + }; + Reflection.prototype.findReflectionByName = function (arg) { + var names = Array.isArray(arg) ? arg : arg.split('.'); + var reflection = this.getChildByName(names); + if (reflection) { + return reflection; + } + else { + return this.parent.findReflectionByName(names); + } + }; + Reflection.prototype.traverse = function (callback) { }; + Reflection.prototype.toObject = function () { + var result = { + id: this.id, + name: this.name, + kind: this.kind, + kindString: this.kindString, + flags: {} + }; + if (this.originalName != this.name) { + result.originalName = this.originalName; + } + if (this.comment) { + result.comment = this.comment.toObject(); + } + for (var key in this.flags) { + if (parseInt(key) == key || key == 'flags') + continue; + if (this.flags[key]) + result.flags[key] = true; + } + if (this.decorates) { + result.decorates = this.decorates.map(function (type) { return type.toObject(); }); + } + if (this.decorators) { + result.decorators = this.decorators.map(function (decorator) { + var result = { name: decorator.name }; + if (decorator.type) + result.type = decorator.type.toObject(); + if (decorator.arguments) + result.arguments = decorator.arguments; + return result; + }); + } + this.traverse(function (child, property) { + if (property == TraverseProperty.TypeLiteral) + return; + var name = TraverseProperty[property]; + name = name.substr(0, 1).toLowerCase() + name.substr(1); + if (!result[name]) + result[name] = []; + result[name].push(child.toObject()); + }); + return result; + }; + Reflection.prototype.toString = function () { + return ReflectionKind[this.kind] + ' ' + this.name; + }; + Reflection.prototype.toStringHierarchy = function (indent) { + if (indent === void 0) { indent = ''; } + var lines = [indent + this.toString()]; + indent += ' '; + this.traverse(function (child, property) { + lines.push(child.toStringHierarchy(indent)); + }); + return lines.join('\n'); + }; + return Reflection; +}()); +exports.Reflection = Reflection; +//# sourceMappingURL=abstract.js.map \ No newline at end of file diff --git a/lib/models/reflections/abstract.js.map b/lib/models/reflections/abstract.js.map new file mode 100644 index 000000000..a88ca18d1 --- /dev/null +++ b/lib/models/reflections/abstract.js.map @@ -0,0 +1 @@ +{"version":3,"file":"abstract.js","sourceRoot":"","sources":["../../../src/lib/models/reflections/abstract.ts"],"names":[],"mappings":";AAsBA,IAAI,aAAa,GAAU,CAAC,CAAC;AAO7B;IACI,aAAa,GAAG,CAAC,CAAC;AACtB,CAAC;AAFe,yBAAiB,oBAEhC,CAAA;AAKD,WAAY,cAAc;IAEtB,uDAAU,CAAA;IACV,uEAAkB,CAAA;IAClB,uDAAU,CAAA;IACV,mDAAQ,CAAA;IACR,gEAAe,CAAA;IACf,4DAAa,CAAA;IACb,4DAAa,CAAA;IACb,uDAAW,CAAA;IACX,+DAAe,CAAA;IACf,mEAAiB,CAAA;IACjB,8DAAe,CAAA;IACf,0DAAa,CAAA;IACb,wEAAoB,CAAA;IACpB,0EAAqB,CAAA;IACrB,uFAA4B,CAAA;IAC5B,iEAAiB,CAAA;IACjB,qEAAmB,CAAA;IACnB,0EAAsB,CAAA;IACtB,gEAAiB,CAAA;IACjB,wEAAqB,CAAA;IACrB,yEAAsB,CAAA;IACtB,2EAAuB,CAAA;IACvB,mEAAmB,CAAA;IACnB,2DAAe,CAAA;IAEf,6EAAoC,CAAA;IACpC,kFAAwC,CAAA;IACxC,8EAAoC,CAAA;IACpC,2EAAmG,CAAA;IACnG,+DAAoC,CAAA;AACxC,CAAC,EAhCW,sBAAc,KAAd,sBAAc,QAgCzB;AAhCD,IAAY,cAAc,GAAd,sBAgCX,CAAA;AAGD,WAAY,cAAc;IAEtB,yDAAW,CAAA;IACX,6DAAa,CAAA;IACb,uDAAU,CAAA;IACV,uDAAU,CAAA;IACV,4DAAa,CAAA;IACb,4EAAqB,CAAA;IACrB,4DAAa,CAAA;IACb,6DAAc,CAAA;IACd,qEAAkB,CAAA;IAClB,qDAAU,CAAA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AAC;QAEH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IACL,iBAAC;AAAD,CAAC,AA5ZD,IA4ZC;AA5ZqB,kBAAU,aA4Z/B,CAAA","sourcesContent":["import {SourceFile, ISourceReference} from \"../sources/file\";\nimport {Type} from \"../types/index\";\nimport {Comment} from \"../comments/comment\";\nimport {TypeParameterReflection} from \"./type-parameter\";\nimport {ProjectReflection} from \"./project\";\n\n\n/**\n * Holds all data models used by TypeDoc.\n *\n * The [[BaseReflection]] is base class of all reflection models. The subclass [[ProjectReflection]]\n * serves as the root container for the current project while [[DeclarationReflection]] instances\n * form the structure of the project. Most of the other classes in this namespace are referenced by this\n * two base classes.\n *\n * The models [[NavigationItem]] and [[UrlMapping]] are special as they are only used by the [[Renderer]]\n * while creating the final output.\n */\n\n/**\n * Current reflection id.\n */\nvar REFLECTION_ID:number = 0;\n\n/**\n * Reset the reflection id.\n *\n * Used by the test cases to ensure the reflection ids won't change between runs.\n */\nexport function resetReflectionID() {\n REFLECTION_ID = 0;\n}\n\n/**\n * Defines the available reflection kinds.\n */\nexport enum ReflectionKind\n{\n Global = 0,\n ExternalModule = 1,\n Module = 2,\n Enum = 4,\n EnumMember = 16,\n Variable = 32,\n Function = 64,\n Class = 128,\n Interface = 256,\n Constructor = 512,\n Property = 1024,\n Method = 2048,\n CallSignature = 4096,\n IndexSignature = 8192,\n ConstructorSignature = 16384,\n Parameter = 32768,\n TypeLiteral = 65536,\n TypeParameter = 131072,\n Accessor = 262144,\n GetSignature = 524288,\n SetSignature = 1048576,\n ObjectLiteral = 2097152,\n TypeAlias = 4194304,\n Event = 8388608,\n\n ClassOrInterface = Class | Interface,\n VariableOrProperty = Variable | Property,\n FunctionOrMethod = Function | Method,\n SomeSignature = CallSignature | IndexSignature | ConstructorSignature | GetSignature | SetSignature,\n SomeModule = Module | ExternalModule\n}\n\n\nexport enum ReflectionFlag\n{\n Private = 1,\n Protected = 2,\n Public = 4,\n Static = 8,\n Exported = 16,\n ExportAssignment = 32,\n External = 64,\n Optional = 128,\n DefaultValue = 256,\n Rest = 512,\n ConstructorProperty = 1024\n}\n\n\nvar relevantFlags:ReflectionFlag[] = [\n ReflectionFlag.Private,\n ReflectionFlag.Protected,\n ReflectionFlag.Static,\n ReflectionFlag.ExportAssignment,\n ReflectionFlag.Optional,\n ReflectionFlag.DefaultValue,\n ReflectionFlag.Rest\n];\n\n\nexport interface IReflectionFlags extends Array\n{\n flags?:ReflectionFlag;\n\n /**\n * Is this a private member?\n */\n isPrivate?:boolean;\n\n /**\n * Is this a protected member?\n */\n isProtected?:boolean;\n\n /**\n * Is this a public member?\n */\n isPublic?:boolean;\n\n /**\n * Is this a static member?\n */\n isStatic?:boolean;\n\n /**\n * Is this member exported?\n */\n isExported?:boolean;\n\n /**\n * Is this a declaration from an external document?\n */\n isExternal?:boolean;\n\n /**\n * Whether this reflection is an optional component or not.\n *\n * Applies to function parameters and object members.\n */\n isOptional?:boolean;\n\n\n /**\n * Whether it's a rest parameter, like `foo(...params);`.\n */\n isRest?: boolean;\n\n /**\n *\n */\n hasExportAssignment?:boolean;\n\n isConstructorProperty?:boolean;\n}\n\n\nexport interface IDefaultValueContainer extends Reflection\n{\n defaultValue:string;\n}\n\n\nexport interface ITypeContainer extends Reflection\n{\n type:Type;\n}\n\n\nexport interface ITypeParameterContainer extends Reflection\n{\n typeParameters:TypeParameterReflection[];\n}\n\n\nexport enum TraverseProperty {\n Children,\n Parameters,\n TypeLiteral,\n TypeParameter,\n Signatures,\n IndexSignature,\n GetSignature,\n SetSignature\n}\n\n\nexport interface ITraverseCallback\n{\n (reflection:Reflection, property:TraverseProperty):void;\n}\n\n\n/**\n * Defines the usage of a decorator.\n */\nexport interface IDecorator\n{\n /**\n * The name of the decorator being applied.\n */\n name:string;\n\n /**\n * The type declaring the decorator.\n * Usually a ReferenceType instance pointing to the decorator function.\n */\n type?:Type;\n\n /**\n * A named map of arguments the decorator is applied with.\n */\n arguments?:any;\n}\n\n\n/**\n * Base class for all reflection classes.\n *\n * While generating a documentation, TypeDoc generates an instance of [[ProjectReflection]]\n * as the root for all reflections within the project. All other reflections are represented\n * by the [[DeclarationReflection]] class.\n *\n * This base class exposes the basic properties one may use to traverse the reflection tree.\n * You can use the [[children]] and [[parent]] properties to walk the tree. The [[groups]] property\n * contains a list of all children grouped and sorted for being rendered.\n */\nexport abstract class Reflection\n{\n /**\n * Unique id of this reflection.\n */\n id:number;\n\n /**\n * The symbol name of this reflection.\n */\n name:string = '';\n\n /**\n * The original name of the TypeScript declaration.\n */\n originalName:string;\n\n /**\n * The kind of this reflection.\n */\n kind:ReflectionKind;\n\n /**\n * The human readable string representation of the kind of this reflection.\n */\n kindString:string;\n\n flags:IReflectionFlags = [];\n\n /**\n * The reflection this reflection is a child of.\n */\n parent:Reflection;\n\n /**\n * The parsed documentation comment attached to this reflection.\n */\n comment:Comment;\n\n /**\n * A list of all source files that contributed to this reflection.\n */\n sources:ISourceReference[];\n\n /**\n * A list of all decorators attached to this reflection.\n */\n decorators:IDecorator[];\n\n /**\n * A list of all types that are decorated by this reflection.\n */\n decorates:Type[];\n\n /**\n * The url of this reflection in the generated documentation.\n */\n url:string;\n\n /**\n * The name of the anchor of this child.\n */\n anchor:string;\n\n /**\n * Is the url pointing to an individual document?\n *\n * When FALSE, the url points to an anchor tag on a page of a different reflection.\n */\n hasOwnDocument:boolean;\n\n /**\n * A list of generated css classes that should be applied to representations of this\n * reflection in the generated markup.\n */\n cssClasses:string;\n\n /**\n * Url safe alias for this reflection.\n *\n * @see [[BaseReflection.getAlias]]\n */\n private _alias:string;\n\n private _aliases:string[];\n\n\n\n /**\n * Create a new BaseReflection instance.\n */\n constructor(parent?:Reflection, name?:string, kind?:ReflectionKind) {\n this.id = REFLECTION_ID++;\n this.parent = parent;\n this.name = name;\n this.originalName = name;\n this.kind = kind;\n }\n\n\n /**\n * @param kind The kind to test for.\n */\n kindOf(kind:ReflectionKind):boolean;\n\n /**\n * @param kind An array of kinds to test for.\n */\n kindOf(kind:ReflectionKind[]):boolean;\n\n /**\n * Test whether this reflection is of the given kind.\n */\n kindOf(kind:any):boolean {\n if (Array.isArray(kind)) {\n for (var i = 0, c = kind.length; i < c; i++) {\n if ((this.kind & kind[i]) !== 0) {\n return true;\n }\n }\n return false;\n } else {\n return (this.kind & kind) !== 0;\n }\n }\n\n\n /**\n * Return the full name of this reflection.\n *\n * The full name contains the name of this reflection and the names of all parent reflections.\n *\n * @param separator Separator used to join the names of the reflections.\n * @returns The full name of this reflection.\n */\n getFullName(separator:string = '.'):string {\n if (this.parent && !this.parent.isProject()) {\n return this.parent.getFullName(separator) + separator + this.name;\n } else {\n return this.name;\n }\n }\n\n\n /**\n * Set a flag on this reflection.\n */\n setFlag(flag:ReflectionFlag, value:boolean = true) {\n var name:string, index:number;\n if (relevantFlags.indexOf(flag) != -1) {\n name = ReflectionFlag[flag];\n name = name.replace(/(.)([A-Z])/g, (m, a, b) => a + ' ' + b.toLowerCase());\n index = this.flags.indexOf(name);\n }\n\n if (value) {\n this.flags.flags |= flag;\n if (name && index == -1) {\n this.flags.push(name);\n }\n } else {\n this.flags.flags &= ~flag;\n if (name && index != -1) {\n this.flags.splice(index, 1);\n }\n }\n\n switch (flag) {\n case ReflectionFlag.Private:\n this.flags.isPrivate = value;\n if (value) {\n this.setFlag(ReflectionFlag.Protected, false);\n this.setFlag(ReflectionFlag.Public, false);\n }\n break;\n case ReflectionFlag.Protected:\n this.flags.isProtected = value;\n if (value) {\n this.setFlag(ReflectionFlag.Private, false);\n this.setFlag(ReflectionFlag.Public, false);\n }\n break;\n case ReflectionFlag.Public:\n this.flags.isPublic = value;\n if (value) {\n this.setFlag(ReflectionFlag.Private, false);\n this.setFlag(ReflectionFlag.Protected, false);\n }\n break;\n case ReflectionFlag.Static:\n this.flags.isStatic = value;\n break;\n case ReflectionFlag.Exported:\n this.flags.isExported = value;\n break;\n case ReflectionFlag.External:\n this.flags.isExternal = value;\n break;\n case ReflectionFlag.Optional:\n this.flags.isOptional = value;\n break;\n case ReflectionFlag.Rest:\n this.flags.isRest = value;\n break;\n case ReflectionFlag.ExportAssignment:\n this.flags.hasExportAssignment = value;\n break;\n case ReflectionFlag.ConstructorProperty:\n this.flags.isConstructorProperty = value;\n break;\n }\n }\n\n\n /**\n * Return an url safe alias for this reflection.\n */\n getAlias():string {\n if (!this._alias) {\n var alias = this.name.replace(/[^a-z0-9]/gi, '_').toLowerCase();\n if (alias == '') {\n alias = 'reflection-' + this.id;\n }\n\n var target = this;\n while (target.parent && !target.parent.isProject() && !target.hasOwnDocument) {\n target = target.parent;\n }\n\n if (!target._aliases) target._aliases = [];\n var suffix = '', index = 0;\n while (target._aliases.indexOf(alias + suffix) != -1) {\n suffix = '-' + (++index).toString();\n }\n\n alias += suffix;\n target._aliases.push(alias);\n this._alias = alias;\n }\n\n return this._alias;\n }\n\n\n /**\n * Has this reflection a visible comment?\n *\n * @returns TRUE when this reflection has a visible comment.\n */\n hasComment():boolean {\n return (this.comment && this.comment.hasVisibleComponent());\n }\n\n\n hasGetterOrSetter():boolean {\n return false;\n }\n\n\n /**\n * @param name The name of the child to look for. Might contain a hierarchy.\n */\n getChildByName(name:string):Reflection;\n\n /**\n * @param names The name hierarchy of the child to look for.\n */\n getChildByName(names:string[]):Reflection;\n\n /**\n * Return a child by its name.\n *\n * @returns The found child or NULL.\n */\n getChildByName(arg:any):Reflection {\n var names:string[] = Array.isArray(arg) ? arg : arg.split('.');\n var name = names[0];\n var result:Reflection = null;\n\n this.traverse((child) => {\n if (child.name == name) {\n if (names.length <= 1) {\n result = child;\n } else if (child) {\n result = child.getChildByName(names.slice(1));\n }\n }\n });\n\n return result;\n }\n\n\n /**\n * Return whether this reflection is the root / project reflection.\n */\n isProject():boolean { //:this is ProjectReflection\n return false;\n }\n\n\n /**\n * @param name The name to look for. Might contain a hierarchy.\n */\n findReflectionByName(name:string):Reflection;\n\n /**\n * @param names The name hierarchy to look for.\n */\n findReflectionByName(names:string[]):Reflection;\n\n /**\n * Try to find a reflection by its name.\n *\n * @return The found reflection or null.\n */\n findReflectionByName(arg:any):Reflection {\n var names:string[] = Array.isArray(arg) ? arg : arg.split('.');\n\n var reflection = this.getChildByName(names);\n if (reflection) {\n return reflection;\n } else {\n return this.parent.findReflectionByName(names);\n }\n }\n\n\n /**\n * Traverse all potential child reflections of this reflection.\n *\n * The given callback will be invoked for all children, signatures and type parameters\n * attached to this reflection.\n *\n * @param callback The callback function that should be applied for each child reflection.\n */\n traverse(callback:ITraverseCallback) { }\n\n\n /**\n * Return a raw object representation of this reflection.\n */\n toObject():any {\n var result:any = {\n id: this.id,\n name: this.name,\n kind: this.kind,\n kindString: this.kindString,\n flags: {}\n };\n\n if (this.originalName != this.name) {\n result.originalName = this.originalName;\n }\n\n if (this.comment) {\n result.comment = this.comment.toObject();\n }\n\n for (var key in this.flags) {\n if (parseInt(key) == key || key == 'flags') continue;\n if (this.flags[key]) result.flags[key] = true;\n }\n\n if (this.decorates) {\n result.decorates = this.decorates.map((type) => type.toObject());\n }\n\n if (this.decorators) {\n result.decorators = this.decorators.map((decorator) => {\n var result:any = { name:decorator.name };\n if (decorator.type) result.type = decorator.type.toObject();\n if (decorator.arguments) result.arguments = decorator.arguments;\n return result;\n });\n }\n\n this.traverse((child, property) => {\n if (property == TraverseProperty.TypeLiteral) return;\n var name = TraverseProperty[property];\n name = name.substr(0, 1).toLowerCase() + name.substr(1);\n if (!result[name]) result[name] = [];\n result[name].push(child.toObject());\n });\n\n return result;\n }\n\n\n /**\n * Return a string representation of this reflection.\n */\n toString():string {\n return ReflectionKind[this.kind] + ' ' + this.name;\n }\n\n\n /**\n * Return a string representation of this reflection and all of its children.\n *\n * @param indent Used internally to indent child reflections.\n */\n toStringHierarchy(indent:string = '') {\n var lines = [indent + this.toString()];\n\n indent += ' ';\n this.traverse((child, property) => {\n lines.push(child.toStringHierarchy(indent));\n });\n\n return lines.join('\\n');\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/reflections/container.d.ts b/lib/models/reflections/container.d.ts new file mode 100644 index 000000000..3907c7be6 --- /dev/null +++ b/lib/models/reflections/container.d.ts @@ -0,0 +1,10 @@ +import { Reflection, ReflectionKind, ITraverseCallback } from "./abstract"; +import { ReflectionGroup } from "../ReflectionGroup"; +import { DeclarationReflection } from "./declaration"; +export declare class ContainerReflection extends Reflection { + children: DeclarationReflection[]; + groups: ReflectionGroup[]; + getChildrenByKind(kind: ReflectionKind): DeclarationReflection[]; + traverse(callback: ITraverseCallback): void; + toObject(): any; +} diff --git a/lib/models/reflections/container.js b/lib/models/reflections/container.js new file mode 100644 index 000000000..af2e6071b --- /dev/null +++ b/lib/models/reflections/container.js @@ -0,0 +1,55 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var ContainerReflection = (function (_super) { + __extends(ContainerReflection, _super); + function ContainerReflection() { + _super.apply(this, arguments); + } + ContainerReflection.prototype.getChildrenByKind = function (kind) { + var values = []; + for (var key in this.children) { + var child = this.children[key]; + if (child.kindOf(kind)) { + values.push(child); + } + } + return values; + }; + ContainerReflection.prototype.traverse = function (callback) { + if (this.children) { + this.children.forEach(function (child) { + callback(child, abstract_1.TraverseProperty.Children); + }); + } + }; + ContainerReflection.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + if (this.groups) { + var groups = []; + this.groups.forEach(function (group) { + groups.push(group.toObject()); + }); + result['groups'] = groups; + } + if (this.sources) { + var sources = []; + this.sources.forEach(function (source) { + sources.push({ + fileName: source.fileName, + line: source.line, + character: source.character + }); + }); + result['sources'] = sources; + } + return result; + }; + return ContainerReflection; +}(abstract_1.Reflection)); +exports.ContainerReflection = ContainerReflection; +//# sourceMappingURL=container.js.map \ No newline at end of file diff --git a/lib/models/reflections/container.js.map b/lib/models/reflections/container.js.map new file mode 100644 index 000000000..fad545819 --- /dev/null +++ b/lib/models/reflections/container.js.map @@ -0,0 +1 @@ +{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../src/lib/models/reflections/container.ts"],"names":[],"mappings":";;;;;;AAAA,yBAA8E,YAAY,CAAC,CAAA;AAK3F;IAAyC,uCAAU;IAAnD;QAAyC,8BAAU;IA+EnD,CAAC;IA3DG,+CAAiB,GAAjB,UAAkB,IAAmB;QACjC,IAAI,MAAM,GAA2B,EAAE,CAAC;QACxC,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC5B,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAC/B,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBACrB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;QACL,CAAC;QACD,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAWD,sCAAQ,GAAR,UAAS,QAA0B;QAC/B,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAChB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAC,KAA2B;gBAC9C,QAAQ,CAAC,KAAK,EAAE,2BAAgB,CAAC,QAAQ,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAMD,sCAAQ,GAAR;QACI,IAAI,MAAM,GAAG,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAE9B,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YACd,IAAI,MAAM,GAAS,EAAE,CAAC;YACtB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK;gBACtB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;YACjC,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;QAC9B,CAAC;QAED,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YACjB,IAAI,OAAO,GAAS,EAAE,CAAC;YACvB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;gBACxB,OAAO,CAAC,IAAI,CAAC;oBACX,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,SAAS,EAAE,MAAM,CAAC,SAAS;iBAC5B,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YAEH,MAAM,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;QAC9B,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IACL,0BAAC;AAAD,CAAC,AA/ED,CAAyC,qBAAU,GA+ElD;AA/EY,2BAAmB,sBA+E/B,CAAA","sourcesContent":["import {Reflection, ReflectionKind, ITraverseCallback, TraverseProperty} from \"./abstract\";\nimport {ReflectionGroup} from \"../ReflectionGroup\";\nimport {DeclarationReflection} from \"./declaration\";\n\n\nexport class ContainerReflection extends Reflection\n{\n /**\n * The children of this reflection.\n */\n children:DeclarationReflection[];\n\n /**\n * All children grouped by their kind.\n */\n groups:ReflectionGroup[];\n\n\n\n /**\n * Return a list of all children of a certain kind.\n *\n * @param kind The desired kind of children.\n * @returns An array containing all children with the desired kind.\n */\n getChildrenByKind(kind:ReflectionKind):DeclarationReflection[] {\n var values:DeclarationReflection[] = [];\n for (var key in this.children) {\n var child = this.children[key];\n if (child.kindOf(kind)) {\n values.push(child);\n }\n }\n return values;\n }\n\n\n /**\n * Traverse all potential child reflections of this reflection.\n *\n * The given callback will be invoked for all children, signatures and type parameters\n * attached to this reflection.\n *\n * @param callback The callback function that should be applied for each child reflection.\n */\n traverse(callback:ITraverseCallback) {\n if (this.children) {\n this.children.forEach((child:DeclarationReflection) => {\n callback(child, TraverseProperty.Children);\n });\n }\n }\n\n\n /**\n * Return a raw object representation of this reflection.\n */\n toObject():any {\n var result = super.toObject();\n\n if (this.groups) {\n var groups:any[] = [];\n this.groups.forEach((group) => {\n groups.push(group.toObject())\n });\n\n result['groups'] = groups;\n }\n\n if (this.sources) {\n var sources:any[] = [];\n this.sources.forEach((source) => {\n sources.push({\n fileName: source.fileName,\n line: source.line,\n character: source.character\n });\n });\n\n result['sources'] = sources;\n }\n\n return result;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/reflections/declaration.d.ts b/lib/models/reflections/declaration.d.ts new file mode 100644 index 000000000..97bcc23e7 --- /dev/null +++ b/lib/models/reflections/declaration.d.ts @@ -0,0 +1,32 @@ +import { IDefaultValueContainer, ITypeContainer, ITypeParameterContainer, ITraverseCallback } from "./abstract"; +import { Type } from "../types/index"; +import { ContainerReflection } from "./container"; +import { SignatureReflection } from "./signature"; +import { TypeParameterReflection } from "./type-parameter"; +export interface IDeclarationHierarchy { + types: Type[]; + next?: IDeclarationHierarchy; + isTarget?: boolean; +} +export declare class DeclarationReflection extends ContainerReflection implements IDefaultValueContainer, ITypeContainer, ITypeParameterContainer { + type: Type; + typeParameters: TypeParameterReflection[]; + signatures: SignatureReflection[]; + indexSignature: SignatureReflection; + getSignature: SignatureReflection; + setSignature: SignatureReflection; + defaultValue: string; + overwrites: Type; + inheritedFrom: Type; + implementationOf: Type; + extendedTypes: Type[]; + extendedBy: Type[]; + implementedTypes: Type[]; + implementedBy: Type[]; + typeHierarchy: IDeclarationHierarchy; + hasGetterOrSetter(): boolean; + getAllSignatures(): SignatureReflection[]; + traverse(callback: ITraverseCallback): void; + toObject(): any; + toString(): string; +} diff --git a/lib/models/reflections/declaration.js b/lib/models/reflections/declaration.js new file mode 100644 index 000000000..27f3c1df9 --- /dev/null +++ b/lib/models/reflections/declaration.js @@ -0,0 +1,99 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var index_1 = require("../types/index"); +var container_1 = require("./container"); +var DeclarationReflection = (function (_super) { + __extends(DeclarationReflection, _super); + function DeclarationReflection() { + _super.apply(this, arguments); + } + DeclarationReflection.prototype.hasGetterOrSetter = function () { + return !!this.getSignature || !!this.setSignature; + }; + DeclarationReflection.prototype.getAllSignatures = function () { + var result = []; + if (this.signatures) + result = result.concat(this.signatures); + if (this.indexSignature) + result.push(this.indexSignature); + if (this.getSignature) + result.push(this.getSignature); + if (this.setSignature) + result.push(this.setSignature); + return result; + }; + DeclarationReflection.prototype.traverse = function (callback) { + if (this.typeParameters) { + this.typeParameters.forEach(function (parameter) { return callback(parameter, abstract_1.TraverseProperty.TypeParameter); }); + } + if (this.type instanceof index_1.ReflectionType) { + callback(this.type.declaration, abstract_1.TraverseProperty.TypeLiteral); + } + if (this.signatures) { + this.signatures.forEach(function (signature) { return callback(signature, abstract_1.TraverseProperty.Signatures); }); + } + if (this.indexSignature) { + callback(this.indexSignature, abstract_1.TraverseProperty.IndexSignature); + } + if (this.getSignature) { + callback(this.getSignature, abstract_1.TraverseProperty.GetSignature); + } + if (this.setSignature) { + callback(this.setSignature, abstract_1.TraverseProperty.SetSignature); + } + _super.prototype.traverse.call(this, callback); + }; + DeclarationReflection.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + if (this.type) { + result.type = this.type.toObject(); + } + if (this.defaultValue) { + result.defaultValue = this.defaultValue; + } + if (this.overwrites) { + result.overwrites = this.overwrites.toObject(); + } + if (this.inheritedFrom) { + result.inheritedFrom = this.inheritedFrom.toObject(); + } + if (this.extendedTypes) { + result.extendedTypes = this.extendedTypes.map(function (t) { return t.toObject(); }); + } + if (this.extendedBy) { + result.extendedBy = this.extendedBy.map(function (t) { return t.toObject(); }); + } + if (this.implementedTypes) { + result.implementedTypes = this.implementedTypes.map(function (t) { return t.toObject(); }); + } + if (this.implementedBy) { + result.implementedBy = this.implementedBy.map(function (t) { return t.toObject(); }); + } + if (this.implementationOf) { + result.implementationOf = this.implementationOf.toObject(); + } + return result; + }; + DeclarationReflection.prototype.toString = function () { + var result = _super.prototype.toString.call(this); + if (this.typeParameters) { + var parameters = []; + this.typeParameters.forEach(function (parameter) { + parameters.push(parameter.name); + }); + result += '<' + parameters.join(', ') + '>'; + } + if (this.type) { + result += ':' + this.type.toString(); + } + return result; + }; + return DeclarationReflection; +}(container_1.ContainerReflection)); +exports.DeclarationReflection = DeclarationReflection; +//# sourceMappingURL=declaration.js.map \ No newline at end of file diff --git a/lib/models/reflections/declaration.js.map b/lib/models/reflections/declaration.js.map new file mode 100644 index 000000000..ae7bc3d38 --- /dev/null +++ b/lib/models/reflections/declaration.js.map @@ -0,0 +1 @@ +{"version":3,"file":"declaration.js","sourceRoot":"","sources":["../../../src/lib/models/reflections/declaration.ts"],"names":[],"mappings":";;;;;;AACA,yBAAmH,YAAY,CAAC,CAAA;AAChI,sBAAmC,gBAAgB,CAAC,CAAA;AACpD,0BAAkC,aAAa,CAAC,CAAA;AAmChD;IAA2C,yCAAmB;IAA9D;QAA2C,8BAAmB;IAkN9D,CAAC;IAxHG,iDAAiB,GAAjB;QACI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;IACtD,CAAC;IAGD,gDAAgB,GAAhB;QACI,IAAI,MAAM,GAAyB,EAAE,CAAC;QAEtC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;YAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7D,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;YAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC1D,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;YAAC,MAAM,CAAC,IAAI,CAA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A","sourcesContent":["import {SourceFile} from \"../sources/file\";\nimport {IDefaultValueContainer, ITypeContainer, ITypeParameterContainer, ITraverseCallback, TraverseProperty} from \"./abstract\";\nimport {Type, ReflectionType} from \"../types/index\";\nimport {ContainerReflection} from \"./container\";\nimport {SignatureReflection} from \"./signature\";\nimport {TypeParameterReflection} from \"./type-parameter\";\n\n\n/**\n * Stores hierarchical type data.\n *\n * @see [[DeclarationReflection.typeHierarchy]]\n */\nexport interface IDeclarationHierarchy\n{\n /**\n * The types represented by this node in the hierarchy.\n */\n types:Type[];\n\n /**\n * The next hierarchy level.\n */\n next?:IDeclarationHierarchy;\n\n /**\n * Is this the entry containing the target type?\n */\n isTarget?:boolean;\n}\n\n\n/**\n * A reflection that represents a single declaration emitted by the TypeScript compiler.\n *\n * All parts of a project are represented by DeclarationReflection instances. The actual\n * kind of a reflection is stored in its ´kind´ member.\n */\nexport class DeclarationReflection extends ContainerReflection implements IDefaultValueContainer, ITypeContainer, ITypeParameterContainer\n{\n /**\n * The type of the reflection.\n *\n * If the reflection represents a variable or a property, this is the value type.
\n * If the reflection represents a signature, this is the return type.\n */\n type:Type;\n\n typeParameters:TypeParameterReflection[];\n\n /**\n * A list of call signatures attached to this declaration.\n *\n * TypeDoc creates one declaration per function that may contain ore or more\n * signature reflections.\n */\n signatures:SignatureReflection[];\n\n /**\n * The index signature of this declaration.\n */\n indexSignature:SignatureReflection;\n\n /**\n * The get signature of this declaration.\n */\n getSignature:SignatureReflection;\n\n /**\n * The set signature of this declaration.\n */\n setSignature:SignatureReflection;\n\n /**\n * The default value of this reflection.\n *\n * Applies to function parameters.\n */\n defaultValue:string;\n\n /**\n * A type that points to the reflection that has been overwritten by this reflection.\n *\n * Applies to interface and class members.\n */\n overwrites:Type;\n\n /**\n * A type that points to the reflection this reflection has been inherited from.\n *\n * Applies to interface and class members.\n */\n inheritedFrom:Type;\n\n /**\n * A type that points to the reflection this reflection is the implementation of.\n *\n * Applies to class members.\n */\n implementationOf:Type;\n\n /**\n * A list of all types this reflection extends (e.g. the parent classes).\n */\n extendedTypes:Type[];\n\n /**\n * A list of all types that extend this reflection (e.g. the subclasses).\n */\n extendedBy:Type[];\n\n /**\n * A list of all types this reflection implements.\n */\n implementedTypes:Type[];\n\n /**\n * A list of all types that implement this reflection.\n */\n implementedBy:Type[];\n\n /**\n * Contains a simplified representation of the type hierarchy suitable for being\n * rendered in templates.\n */\n typeHierarchy:IDeclarationHierarchy;\n\n\n hasGetterOrSetter():boolean {\n return !!this.getSignature || !!this.setSignature;\n }\n\n\n getAllSignatures():SignatureReflection[] {\n var result:SignatureReflection[] = [];\n\n if (this.signatures) result = result.concat(this.signatures);\n if (this.indexSignature) result.push(this.indexSignature);\n if (this.getSignature) result.push(this.getSignature);\n if (this.setSignature) result.push(this.setSignature);\n\n return result;\n }\n\n\n /**\n * Traverse all potential child reflections of this reflection.\n *\n * The given callback will be invoked for all children, signatures and type parameters\n * attached to this reflection.\n *\n * @param callback The callback function that should be applied for each child reflection.\n */\n traverse(callback:ITraverseCallback) {\n if (this.typeParameters) {\n this.typeParameters.forEach((parameter) => callback(parameter, TraverseProperty.TypeParameter));\n }\n\n if (this.type instanceof ReflectionType) {\n callback((this.type).declaration, TraverseProperty.TypeLiteral);\n }\n\n if (this.signatures) {\n this.signatures.forEach((signature) => callback(signature, TraverseProperty.Signatures));\n }\n\n if (this.indexSignature) {\n callback(this.indexSignature, TraverseProperty.IndexSignature);\n }\n\n if (this.getSignature) {\n callback(this.getSignature, TraverseProperty.GetSignature);\n }\n\n if (this.setSignature) {\n callback(this.setSignature, TraverseProperty.SetSignature);\n }\n\n super.traverse(callback);\n }\n\n\n /**\n * Return a raw object representation of this reflection.\n */\n toObject():any {\n var result = super.toObject();\n\n if (this.type) {\n result.type = this.type.toObject();\n }\n\n if (this.defaultValue) {\n result.defaultValue = this.defaultValue;\n }\n\n if (this.overwrites) {\n result.overwrites = this.overwrites.toObject();\n }\n\n if (this.inheritedFrom) {\n result.inheritedFrom = this.inheritedFrom.toObject();\n }\n\n if (this.extendedTypes) {\n result.extendedTypes = this.extendedTypes.map((t) => t.toObject());\n }\n\n if (this.extendedBy) {\n result.extendedBy = this.extendedBy.map((t) => t.toObject());\n }\n\n if (this.implementedTypes) {\n result.implementedTypes = this.implementedTypes.map((t) => t.toObject());\n }\n\n if (this.implementedBy) {\n result.implementedBy = this.implementedBy.map((t) => t.toObject());\n }\n\n if (this.implementationOf) {\n result.implementationOf = this.implementationOf.toObject();\n }\n\n return result;\n }\n\n\n /**\n * Return a string representation of this reflection.\n */\n toString():string {\n var result = super.toString();\n\n if (this.typeParameters) {\n var parameters:string[] = [];\n this.typeParameters.forEach((parameter) => {\n parameters.push(parameter.name)\n });\n result += '<' + parameters.join(', ') + '>';\n }\n\n if (this.type) {\n result += ':' + this.type.toString();\n }\n\n return result;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/reflections/index.d.ts b/lib/models/reflections/index.d.ts new file mode 100644 index 000000000..fcc49abca --- /dev/null +++ b/lib/models/reflections/index.d.ts @@ -0,0 +1,7 @@ +export { Reflection, ReflectionKind, ReflectionFlag, ITypeParameterContainer, IDecorator, TraverseProperty } from "./abstract"; +export { ContainerReflection } from "./container"; +export { DeclarationReflection, IDeclarationHierarchy } from "./declaration"; +export { ParameterReflection } from "./parameter"; +export { ProjectReflection } from "./project"; +export { SignatureReflection } from "./signature"; +export { TypeParameterReflection } from "./type-parameter"; diff --git a/lib/models/reflections/index.js b/lib/models/reflections/index.js new file mode 100644 index 000000000..0336ec674 --- /dev/null +++ b/lib/models/reflections/index.js @@ -0,0 +1,19 @@ +"use strict"; +var abstract_1 = require("./abstract"); +exports.Reflection = abstract_1.Reflection; +exports.ReflectionKind = abstract_1.ReflectionKind; +exports.ReflectionFlag = abstract_1.ReflectionFlag; +exports.TraverseProperty = abstract_1.TraverseProperty; +var container_1 = require("./container"); +exports.ContainerReflection = container_1.ContainerReflection; +var declaration_1 = require("./declaration"); +exports.DeclarationReflection = declaration_1.DeclarationReflection; +var parameter_1 = require("./parameter"); +exports.ParameterReflection = parameter_1.ParameterReflection; +var project_1 = require("./project"); +exports.ProjectReflection = project_1.ProjectReflection; +var signature_1 = require("./signature"); +exports.SignatureReflection = signature_1.SignatureReflection; +var type_parameter_1 = require("./type-parameter"); +exports.TypeParameterReflection = type_parameter_1.TypeParameterReflection; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/models/reflections/index.js.map b/lib/models/reflections/index.js.map new file mode 100644 index 000000000..bf2f714ac --- /dev/null +++ b/lib/models/reflections/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/models/reflections/index.ts"],"names":[],"mappings":";AAAA,yBAAgH,YAAY,CAAC;AAArH,2CAAU;AAAE,mDAAc;AAAE,mDAAc;AAAuC,uDAAoC;AAC7H,0BAAkC,aAAa,CAAC;AAAxC,8DAAwC;AAChD,4BAA2D,eAAe,CAAC;AAAnE,oEAAmE;AAC3E,0BAAkC,aAAa,CAAC;AAAxC,8DAAwC;AAChD,wBAAgC,WAAW,CAAC;AAApC,wDAAoC;AAC5C,0BAAkC,aAAa,CAAC;AAAxC,8DAAwC;AAChD,+BAAsC,kBAAkB,CAAC;AAAjD,2EAAiD","sourcesContent":["export {Reflection, ReflectionKind, ReflectionFlag, ITypeParameterContainer, IDecorator, TraverseProperty} from \"./abstract\";\nexport {ContainerReflection} from \"./container\";\nexport {DeclarationReflection, IDeclarationHierarchy} from \"./declaration\";\nexport {ParameterReflection} from \"./parameter\";\nexport {ProjectReflection} from \"./project\";\nexport {SignatureReflection} from \"./signature\";\nexport {TypeParameterReflection} from \"./type-parameter\";\n"]} \ No newline at end of file diff --git a/lib/models/reflections/parameter.d.ts b/lib/models/reflections/parameter.d.ts new file mode 100644 index 000000000..b317985a4 --- /dev/null +++ b/lib/models/reflections/parameter.d.ts @@ -0,0 +1,11 @@ +import { Type } from "../types/index"; +import { Reflection, IDefaultValueContainer, ITypeContainer, ITraverseCallback } from "./abstract"; +import { SignatureReflection } from "./signature"; +export declare class ParameterReflection extends Reflection implements IDefaultValueContainer, ITypeContainer { + parent: SignatureReflection; + defaultValue: string; + type: Type; + traverse(callback: ITraverseCallback): void; + toObject(): any; + toString(): string; +} diff --git a/lib/models/reflections/parameter.js b/lib/models/reflections/parameter.js new file mode 100644 index 000000000..342715743 --- /dev/null +++ b/lib/models/reflections/parameter.js @@ -0,0 +1,36 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var index_1 = require("../types/index"); +var abstract_1 = require("./abstract"); +var ParameterReflection = (function (_super) { + __extends(ParameterReflection, _super); + function ParameterReflection() { + _super.apply(this, arguments); + } + ParameterReflection.prototype.traverse = function (callback) { + if (this.type instanceof index_1.ReflectionType) { + callback(this.type.declaration, abstract_1.TraverseProperty.TypeLiteral); + } + _super.prototype.traverse.call(this, callback); + }; + ParameterReflection.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + if (this.type) { + result.type = this.type.toObject(); + } + if (this.defaultValue) { + result.defaultValue = this.defaultValue; + } + return result; + }; + ParameterReflection.prototype.toString = function () { + return _super.prototype.toString.call(this) + (this.type ? ':' + this.type.toString() : ''); + }; + return ParameterReflection; +}(abstract_1.Reflection)); +exports.ParameterReflection = ParameterReflection; +//# sourceMappingURL=parameter.js.map \ No newline at end of file diff --git a/lib/models/reflections/parameter.js.map b/lib/models/reflections/parameter.js.map new file mode 100644 index 000000000..6cc8e14ea --- /dev/null +++ b/lib/models/reflections/parameter.js.map @@ -0,0 +1 @@ +{"version":3,"file":"parameter.js","sourceRoot":"","sources":["../../../src/lib/models/reflections/parameter.ts"],"names":[],"mappings":";;;;;;AACA,sBAAmC,gBAAgB,CAAC,CAAA;AACpD,yBAAsG,YAAY,CAAC,CAAA;AAInH;IAAyC,uCAAU;IAAnD;QAAyC,8BAAU;IAkDnD,CAAC;IAjCG,sCAAQ,GAAR,UAAS,QAA0B;QAC/B,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,YAAY,sBAAc,CAAC,CAAC,CAAC;YACtC,QAAQ,CAAkB,IAAI,CAAC,IAAK,CAAC,WAAW,EAAE,2BAAgB,CAAC,WAAW,CAAC,CAAC;QACpF,CAAC;QAED,gBAAK,CAAC,QAAQ,YAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAMD,sCAAQ,GAAR;QACI,IAAI,MAAM,GAAG,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAE9B,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YACZ,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvC,CAAC;QAED,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;YACpB,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QAC5C,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,sCAAQ,GAAR;QACI,MAAM,CAAC,gBAAK,CAAC,QAAQ,WAAE,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAI,EAAE,CAAC,CAAC;IAC7E,CAAC;IACL,0BAAC;AAAD,CAAC,AAlDD,CAAyC,qBAAU,GAkDlD;AAlDY,2BAAmB,sBAkD/B,CAAA","sourcesContent":["import {SourceFile} from \"../sources/file\";\nimport {Type, ReflectionType} from \"../types/index\";\nimport {Reflection, IDefaultValueContainer, ITypeContainer, ITraverseCallback, TraverseProperty} from \"./abstract\";\nimport {SignatureReflection} from \"./signature\";\n\n\nexport class ParameterReflection extends Reflection implements IDefaultValueContainer, ITypeContainer\n{\n parent:SignatureReflection;\n\n defaultValue:string;\n\n type:Type;\n\n\n /**\n * Traverse all potential child reflections of this reflection.\n *\n * The given callback will be invoked for all children, signatures and type parameters\n * attached to this reflection.\n *\n * @param callback The callback function that should be applied for each child reflection.\n */\n traverse(callback:ITraverseCallback) {\n if (this.type instanceof ReflectionType) {\n callback((this.type).declaration, TraverseProperty.TypeLiteral);\n }\n\n super.traverse(callback);\n }\n\n\n /**\n * Return a raw object representation of this reflection.\n */\n toObject():any {\n var result = super.toObject();\n\n if (this.type) {\n result.type = this.type.toObject();\n }\n\n if (this.defaultValue) {\n result.defaultValue = this.defaultValue;\n }\n\n return result;\n }\n\n\n /**\n * Return a string representation of this reflection.\n */\n toString() {\n return super.toString() + (this.type ? ':' + this.type.toString() : '');\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/reflections/project.d.ts b/lib/models/reflections/project.d.ts new file mode 100644 index 000000000..c338d1fad --- /dev/null +++ b/lib/models/reflections/project.d.ts @@ -0,0 +1,21 @@ +import { SourceFile, SourceDirectory } from "../sources/index"; +import { Reflection, ReflectionKind } from "./abstract"; +import { ContainerReflection } from "./container"; +export declare class ProjectReflection extends ContainerReflection { + reflections: { + [id: number]: Reflection; + }; + symbolMapping: { + [symbolId: number]: number; + }; + directory: SourceDirectory; + files: SourceFile[]; + name: string; + readme: string; + packageInfo: any; + constructor(name: string); + isProject(): boolean; + getReflectionsByKind(kind: ReflectionKind): Reflection[]; + findReflectionByName(name: string): Reflection; + findReflectionByName(names: string[]): Reflection; +} diff --git a/lib/models/reflections/project.js b/lib/models/reflections/project.js new file mode 100644 index 000000000..4f41672aa --- /dev/null +++ b/lib/models/reflections/project.js @@ -0,0 +1,54 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var index_1 = require("../sources/index"); +var abstract_1 = require("./abstract"); +var container_1 = require("./container"); +var ProjectReflection = (function (_super) { + __extends(ProjectReflection, _super); + function ProjectReflection(name) { + _super.call(this, null, name, abstract_1.ReflectionKind.Global); + this.reflections = {}; + this.symbolMapping = {}; + this.directory = new index_1.SourceDirectory(); + this.files = []; + } + ProjectReflection.prototype.isProject = function () { + return true; + }; + ProjectReflection.prototype.getReflectionsByKind = function (kind) { + var values = []; + for (var id in this.reflections) { + var reflection = this.reflections[id]; + if (reflection.kindOf(kind)) { + values.push(reflection); + } + } + return values; + }; + ProjectReflection.prototype.findReflectionByName = function (arg) { + var names = Array.isArray(arg) ? arg : arg.split('.'); + var name = names.pop(); + search: for (var key in this.reflections) { + var reflection = this.reflections[key]; + if (reflection.name != name) + continue; + var depth = names.length - 1; + var target = reflection; + while (target && depth >= 0) { + target = target.parent; + if (target.name != names[depth]) + continue search; + depth -= 1; + } + return reflection; + } + return null; + }; + return ProjectReflection; +}(container_1.ContainerReflection)); +exports.ProjectReflection = ProjectReflection; +//# sourceMappingURL=project.js.map \ No newline at end of file diff --git a/lib/models/reflections/project.js.map b/lib/models/reflections/project.js.map new file mode 100644 index 000000000..d93d8fd58 --- /dev/null +++ b/lib/models/reflections/project.js.map @@ -0,0 +1 @@ +{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../src/lib/models/reflections/project.ts"],"names":[],"mappings":";;;;;;AAAA,sBAA0C,kBAAkB,CAAC,CAAA;AAC7D,yBAAyC,YAAY,CAAC,CAAA;AAEtD,0BAAkC,aAAa,CAAC,CAAA;AAShD;IAAuC,qCAAmB;IA0CtD,2BAAY,IAAW;QACnB,kBAAM,IAAI,EAAE,IAAI,EAAE,yBAAc,CAAC,MAAM,CAAC,CAAC;QAtC7C,gBAAW,GAA4B,EAAE,CAAC;QAE1C,kBAAa,GAA8B,EAAE,CAAC;QAK9C,cAAS,GAAmB,IAAI,uBAAe,EAAE,CAAC;QAKlD,UAAK,GAAgB,EAAE,CAAC;IA2BxB,CAAC;IAMD,qCAAS,GAAT;QACI,MAAM,CAAC,IAAI,CAAC;IAChB,CAAC;IASD,gDAAoB,GAApB,UAAqB,IAA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,CAAC,IAAI,CAAC;IAChB,CAAC;IACL,wBAAC;AAAD,CAAC,AA9GD,CAAuC,+BAAmB,GA8GzD;AA9GY,yBAAiB,oBA8G7B,CAAA","sourcesContent":["import {SourceFile, SourceDirectory} from \"../sources/index\";\nimport {Reflection, ReflectionKind} from \"./abstract\";\nimport {DeclarationReflection} from \"./declaration\";\nimport {ContainerReflection} from \"./container\";\n\n\n/**\n * A reflection that represents the root of the project.\n *\n * The project reflection acts as a global index, one may receive all reflections\n * and source files of the processed project through this reflection.\n */\nexport class ProjectReflection extends ContainerReflection\n{\n /**\n * A list of all reflections within the project.\n */\n reflections:{[id:number]:Reflection} = {};\n\n symbolMapping:{[symbolId:number]:number} = {};\n\n /**\n * The root directory of the project.\n */\n directory:SourceDirectory = new SourceDirectory();\n\n /**\n * A list of all source files within the project.\n */\n files:SourceFile[] = [];\n\n /**\n * The name of the project.\n *\n * The name can be passed as a commandline argument or it is read from the package info.\n */\n name:string;\n\n /**\n * The contents of the readme.md file of the project when found.\n */\n readme:string;\n\n /**\n * The parsed data of the package.json file of the project when found.\n */\n packageInfo:any;\n\n\n /**\n * Create a new ProjectReflection instance.\n *\n * @param name The name of the project.\n */\n constructor(name:string) {\n super(null, name, ReflectionKind.Global);\n }\n\n\n /**\n * Return whether this reflection is the root / project reflection.\n */\n isProject():boolean {\n return true;\n }\n\n\n /**\n * Return a list of all reflections in this project of a certain kind.\n *\n * @param kind The desired kind of reflection.\n * @returns An array containing all reflections with the desired kind.\n */\n getReflectionsByKind(kind:ReflectionKind):Reflection[] {\n var values:Reflection[] = [];\n for (var id in this.reflections) {\n var reflection = this.reflections[id];\n if (reflection.kindOf(kind)) {\n values.push(reflection);\n }\n }\n\n return values;\n }\n\n\n /**\n * @param name The name to look for. Might contain a hierarchy.\n */\n findReflectionByName(name:string):Reflection;\n\n /**\n * @param names The name hierarchy to look for.\n */\n findReflectionByName(names:string[]):Reflection;\n\n /**\n * Try to find a reflection by its name.\n *\n * @return The found reflection or null.\n */\n findReflectionByName(arg:any):Reflection {\n var names:string[] = Array.isArray(arg) ? arg : arg.split('.');\n var name = names.pop();\n\n search: for (var key in this.reflections) {\n var reflection = this.reflections[key];\n if (reflection.name != name) continue;\n\n var depth = names.length - 1;\n var target = reflection;\n while (target && depth >= 0) {\n target = target.parent;\n if (target.name != names[depth]) continue search;\n depth -= 1;\n }\n\n return reflection;\n }\n\n return null;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/reflections/signature.d.ts b/lib/models/reflections/signature.d.ts new file mode 100644 index 000000000..f9a049acd --- /dev/null +++ b/lib/models/reflections/signature.d.ts @@ -0,0 +1,18 @@ +import { Type } from "../types/index"; +import { Reflection, ITypeContainer, ITypeParameterContainer, ITraverseCallback } from "./abstract"; +import { ContainerReflection } from "./container"; +import { ParameterReflection } from "./parameter"; +import { TypeParameterReflection } from "./type-parameter"; +export declare class SignatureReflection extends Reflection implements ITypeContainer, ITypeParameterContainer { + parent: ContainerReflection; + parameters: ParameterReflection[]; + typeParameters: TypeParameterReflection[]; + type: Type; + overwrites: Type; + inheritedFrom: Type; + implementationOf: Type; + getParameterTypes(): Type[]; + traverse(callback: ITraverseCallback): void; + toObject(): any; + toString(): string; +} diff --git a/lib/models/reflections/signature.js b/lib/models/reflections/signature.js new file mode 100644 index 000000000..7c42160ce --- /dev/null +++ b/lib/models/reflections/signature.js @@ -0,0 +1,62 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var index_1 = require("../types/index"); +var abstract_1 = require("./abstract"); +var SignatureReflection = (function (_super) { + __extends(SignatureReflection, _super); + function SignatureReflection() { + _super.apply(this, arguments); + } + SignatureReflection.prototype.getParameterTypes = function () { + if (!this.parameters) + return []; + return this.parameters.map(function (parameter) { return parameter.type; }); + }; + SignatureReflection.prototype.traverse = function (callback) { + if (this.type instanceof index_1.ReflectionType) { + callback(this.type.declaration, abstract_1.TraverseProperty.TypeLiteral); + } + if (this.typeParameters) { + this.typeParameters.forEach(function (parameter) { return callback(parameter, abstract_1.TraverseProperty.TypeParameter); }); + } + if (this.parameters) { + this.parameters.forEach(function (parameter) { return callback(parameter, abstract_1.TraverseProperty.Parameters); }); + } + _super.prototype.traverse.call(this, callback); + }; + SignatureReflection.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + if (this.type) { + result.type = this.type.toObject(); + } + if (this.overwrites) { + result.overwrites = this.overwrites.toObject(); + } + if (this.inheritedFrom) { + result.inheritedFrom = this.inheritedFrom.toObject(); + } + if (this.implementationOf) { + result.implementationOf = this.implementationOf.toObject(); + } + return result; + }; + SignatureReflection.prototype.toString = function () { + var result = _super.prototype.toString.call(this); + if (this.typeParameters) { + var parameters = []; + this.typeParameters.forEach(function (parameter) { return parameters.push(parameter.name); }); + result += '<' + parameters.join(', ') + '>'; + } + if (this.type) { + result += ':' + this.type.toString(); + } + return result; + }; + return SignatureReflection; +}(abstract_1.Reflection)); +exports.SignatureReflection = SignatureReflection; +//# sourceMappingURL=signature.js.map \ No newline at end of file diff --git a/lib/models/reflections/signature.js.map b/lib/models/reflections/signature.js.map new file mode 100644 index 000000000..24398cf05 --- /dev/null +++ b/lib/models/reflections/signature.js.map @@ -0,0 +1 @@ +{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../../src/lib/models/reflections/signature.ts"],"names":[],"mappings":";;;;;;AAAA,sBAAmC,gBAAgB,CAAC,CAAA;AACpD,yBAAuG,YAAY,CAAC,CAAA;AAMpH;IAAyC,uCAAU;IAAnD;QAAyC,8BAAU;IA+GnD,CAAC;IA3EG,+CAAiB,GAAjB;QACI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;YAAC,MAAM,CAAC,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAC,SAA6B,IAAK,OAAA,SAAS,CAA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AQ,EAAE,CAAC;QACzD,CAAC;QAED,EAAE,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;YACxB,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAC/D,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,sCAAQ,GAAR;QACI,IAAI,MAAM,GAAG,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAE9B,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC;YACtB,IAAI,UAAU,GAAY,EAAE,CAAC;YAC7B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,UAAC,SAAS,IAAK,OAAA,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAA/B,CAA+B,CAAC,CAAC;YAC5E,MAAM,IAAI,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QAChD,CAAC;QAED,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YACZ,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzC,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IACL,0BAAC;AAAD,CAAC,AA/GD,CAAyC,qBAAU,GA+GlD;AA/GY,2BAAmB,sBA+G/B,CAAA","sourcesContent":["import {Type, ReflectionType} from \"../types/index\";\nimport {Reflection, ITypeContainer, ITypeParameterContainer, TraverseProperty, ITraverseCallback} from \"./abstract\";\nimport {ContainerReflection} from \"./container\";\nimport {ParameterReflection} from \"./parameter\";\nimport {TypeParameterReflection} from \"./type-parameter\";\n\n\nexport class SignatureReflection extends Reflection implements ITypeContainer, ITypeParameterContainer\n{\n parent:ContainerReflection;\n\n parameters:ParameterReflection[];\n\n typeParameters:TypeParameterReflection[];\n\n type:Type;\n\n /**\n * A type that points to the reflection that has been overwritten by this reflection.\n *\n * Applies to interface and class members.\n */\n overwrites:Type;\n\n /**\n * A type that points to the reflection this reflection has been inherited from.\n *\n * Applies to interface and class members.\n */\n inheritedFrom:Type;\n\n /**\n * A type that points to the reflection this reflection is the implementation of.\n *\n * Applies to class members.\n */\n implementationOf:Type;\n\n\n\n /**\n * Return an array of the parameter types.\n */\n getParameterTypes():Type[] {\n if (!this.parameters) return [];\n return this.parameters.map((parameter:ParameterReflection) => parameter.type);\n }\n\n\n /**\n * Traverse all potential child reflections of this reflection.\n *\n * The given callback will be invoked for all children, signatures and type parameters\n * attached to this reflection.\n *\n * @param callback The callback function that should be applied for each child reflection.\n */\n traverse(callback:ITraverseCallback) {\n if (this.type instanceof ReflectionType) {\n callback((this.type).declaration, TraverseProperty.TypeLiteral);\n }\n\n if (this.typeParameters) {\n this.typeParameters.forEach((parameter) => callback(parameter, TraverseProperty.TypeParameter));\n }\n\n if (this.parameters) {\n this.parameters.forEach((parameter) => callback(parameter, TraverseProperty.Parameters));\n }\n\n super.traverse(callback);\n }\n\n\n /**\n * Return a raw object representation of this reflection.\n */\n toObject():any {\n var result = super.toObject();\n\n if (this.type) {\n result.type = this.type.toObject();\n }\n\n if (this.overwrites) {\n result.overwrites = this.overwrites.toObject();\n }\n\n if (this.inheritedFrom) {\n result.inheritedFrom = this.inheritedFrom.toObject();\n }\n\n if (this.implementationOf) {\n result.implementationOf = this.implementationOf.toObject();\n }\n\n return result;\n }\n\n\n /**\n * Return a string representation of this reflection.\n */\n toString():string {\n var result = super.toString();\n\n if (this.typeParameters) {\n var parameters:string[] = [];\n this.typeParameters.forEach((parameter) => parameters.push(parameter.name));\n result += '<' + parameters.join(', ') + '>';\n }\n\n if (this.type) {\n result += ':' + this.type.toString();\n }\n\n return result;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/reflections/type-parameter.d.ts b/lib/models/reflections/type-parameter.d.ts new file mode 100644 index 000000000..f24ee6f3c --- /dev/null +++ b/lib/models/reflections/type-parameter.d.ts @@ -0,0 +1,9 @@ +import { Type, TypeParameterType } from "../types/index"; +import { Reflection, ITypeContainer } from "./abstract"; +import { DeclarationReflection } from "./declaration"; +export declare class TypeParameterReflection extends Reflection implements ITypeContainer { + parent: DeclarationReflection; + type: Type; + constructor(parent?: Reflection, type?: TypeParameterType); + toObject(): any; +} diff --git a/lib/models/reflections/type-parameter.js b/lib/models/reflections/type-parameter.js new file mode 100644 index 000000000..63f020d61 --- /dev/null +++ b/lib/models/reflections/type-parameter.js @@ -0,0 +1,24 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var TypeParameterReflection = (function (_super) { + __extends(TypeParameterReflection, _super); + function TypeParameterReflection(parent, type) { + _super.call(this, parent, type.name, abstract_1.ReflectionKind.TypeParameter); + this.type = type.constraint; + } + TypeParameterReflection.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + if (this.type) { + result.type = this.type.toObject(); + } + return result; + }; + return TypeParameterReflection; +}(abstract_1.Reflection)); +exports.TypeParameterReflection = TypeParameterReflection; +//# sourceMappingURL=type-parameter.js.map \ No newline at end of file diff --git a/lib/models/reflections/type-parameter.js.map b/lib/models/reflections/type-parameter.js.map new file mode 100644 index 000000000..7355ab9aa --- /dev/null +++ b/lib/models/reflections/type-parameter.js.map @@ -0,0 +1 @@ +{"version":3,"file":"type-parameter.js","sourceRoot":"","sources":["../../../src/lib/models/reflections/type-parameter.ts"],"names":[],"mappings":";;;;;;AACA,yBAAyD,YAAY,CAAC,CAAA;AAItE;IAA6C,2CAAU;IAUnD,iCAAY,MAAkB,EAAE,IAAuB;QACnD,kBAAM,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,yBAAc,CAAC,aAAa,CAAC,CAAC;QACvD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;IAChC,CAAC;IAMD,0CAAQ,GAAR;QACI,IAAI,MAAM,GAAG,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAE9B,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YACZ,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvC,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IACL,8BAAC;AAAD,CAAC,AA5BD,CAA6C,qBAAU,GA4BtD;AA5BY,+BAAuB,0BA4BnC,CAAA","sourcesContent":["import {Type, TypeParameterType} from \"../types/index\";\nimport {Reflection, ReflectionKind, ITypeContainer} from \"./abstract\";\nimport {DeclarationReflection} from \"./declaration\";\n\n\nexport class TypeParameterReflection extends Reflection implements ITypeContainer\n{\n parent:DeclarationReflection;\n\n type:Type;\n\n\n /**\n * Create a new TypeParameterReflection instance.\n */\n constructor(parent?:Reflection, type?:TypeParameterType) {\n super(parent, type.name, ReflectionKind.TypeParameter);\n this.type = type.constraint;\n }\n\n\n /**\n * Return a raw object representation of this reflection.\n */\n toObject():any {\n var result = super.toObject();\n\n if (this.type) {\n result.type = this.type.toObject();\n }\n\n return result;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/sources/directory.d.ts b/lib/models/sources/directory.d.ts new file mode 100644 index 000000000..cc3ee386f --- /dev/null +++ b/lib/models/sources/directory.d.ts @@ -0,0 +1,17 @@ +import { Reflection } from "../reflections/abstract"; +import { ReflectionGroup } from "../ReflectionGroup"; +import { SourceFile } from "./file"; +export declare class SourceDirectory { + parent: SourceDirectory; + directories: { + [name: string]: SourceDirectory; + }; + groups: ReflectionGroup[]; + files: SourceFile[]; + name: string; + dirName: string; + url: string; + constructor(name?: string, parent?: SourceDirectory); + toString(indent?: string): string; + getAllReflections(): Reflection[]; +} diff --git a/lib/models/sources/directory.js b/lib/models/sources/directory.js new file mode 100644 index 000000000..28dcd16ad --- /dev/null +++ b/lib/models/sources/directory.js @@ -0,0 +1,38 @@ +"use strict"; +var SourceDirectory = (function () { + function SourceDirectory(name, parent) { + this.parent = null; + this.directories = {}; + this.files = []; + this.name = null; + this.dirName = null; + if (name && parent) { + this.name = name; + this.dirName = (parent.dirName ? parent.dirName + '/' : '') + name; + this.parent = parent; + } + } + SourceDirectory.prototype.toString = function (indent) { + if (indent === void 0) { indent = ''; } + var res = indent + this.name; + for (var key in this.directories) { + if (!this.directories.hasOwnProperty(key)) + continue; + res += '\n' + this.directories[key].toString(indent + ' '); + } + this.files.forEach(function (file) { + res += '\n' + indent + ' ' + file.fileName; + }); + return res; + }; + SourceDirectory.prototype.getAllReflections = function () { + var reflections = []; + this.files.forEach(function (file) { + reflections.push.apply(reflections, file.reflections); + }); + return reflections; + }; + return SourceDirectory; +}()); +exports.SourceDirectory = SourceDirectory; +//# sourceMappingURL=directory.js.map \ No newline at end of file diff --git a/lib/models/sources/directory.js.map b/lib/models/sources/directory.js.map new file mode 100644 index 000000000..3d8afda1b --- /dev/null +++ b/lib/models/sources/directory.js.map @@ -0,0 +1 @@ +{"version":3,"file":"directory.js","sourceRoot":"","sources":["../../../src/lib/models/sources/directory.ts"],"names":[],"mappings":";AAYA;IAyCI,yBAAY,IAAY,EAAE,MAAuB;QApCjD,WAAM,GAAmB,IAAI,CAAC;QAK9B,gBAAW,GAAmC,EAAE,CAAC;QAOjD,UAAK,GAAgB,EAAE,CAAC;QAKxB,SAAI,GAAU,IAAI,CAAC;QAKnB,YAAO,GAAU,IAAI,CAAC;QAelB,EAAE,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC;YACjB,IAAI,CAAC,IAAI,GAAM,IAAI,CAAC;YACpB,IAAI,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,GAAG,GAAG,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC;YACnE,IAAI,CAAC,MAAM,GAAI,MAAM,CAAC;QAC1B,CAAC;IACL,CAAC;IASD,kCAAQ,GAAR,UAAS,MAAkB;QAAlB,sBAAkB,GAAlB,WAAkB;QACvB,IAAI,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;QAE7B,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;YAC/B,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;gBAAC,QAAQ,CAAC;YACpD,GAAG,IAAI,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAC,IAAI;YACpB,GAAG,IAAI,IAAI,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;QAChD,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,GAAG,CAAC;IACf,CAAC;IASD,2CAAiB,GAAjB;QACI,IAAI,WAAW,GAAgB,EAAE,CAAC;QAClC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAC,IAAI;YACpB,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QAGH,MAAM,CAAC,WAAW,CAAC;IACvB,CAAC;IACL,sBAAC;AAAD,CAAC,AAvFD,IAuFC;AAvFY,uBAAe,kBAuF3B,CAAA","sourcesContent":["import {Reflection} from \"../reflections/abstract\";\nimport {ReflectionGroup} from \"../ReflectionGroup\";\nimport {SourceFile} from \"./file\";\n\n\n/**\n * Exposes information about a directory containing source files.\n *\n * One my access the root directory of a project through the [[ProjectReflection.directory]]\n * property. Traverse through directories by utilizing the [[SourceDirectory.parent]] or\n * [[SourceDirectory.directories]] properties.\n */\nexport class SourceDirectory\n{\n /**\n * The parent directory or NULL if this is a root directory.\n */\n parent:SourceDirectory = null;\n\n /**\n * A list of all subdirectories.\n */\n directories:{[name:string]:SourceDirectory} = {};\n\n groups:ReflectionGroup[];\n\n /**\n * A list of all files in this directory.\n */\n files:SourceFile[] = [];\n\n /**\n * The name of this directory.\n */\n name:string = null;\n\n /**\n * The relative path from the root directory to this directory.\n */\n dirName:string = null;\n\n /**\n * The url of the page displaying the directory contents.\n */\n url:string;\n\n\n /**\n * Create a new SourceDirectory instance.\n *\n * @param name The new of directory.\n * @param parent The parent directory instance.\n */\n constructor(name?:string, parent?:SourceDirectory) {\n if (name && parent) {\n this.name = name;\n this.dirName = (parent.dirName ? parent.dirName + '/' : '') + name;\n this.parent = parent;\n }\n }\n\n\n /**\n * Return a string describing this directory and its contents.\n *\n * @param indent Used internally for indention.\n * @returns A string representing this directory and all of its children.\n */\n toString(indent:string = '') {\n var res = indent + this.name;\n\n for (var key in this.directories) {\n if (!this.directories.hasOwnProperty(key)) continue;\n res += '\\n' + this.directories[key].toString(indent + ' ');\n }\n\n this.files.forEach((file) => {\n res += '\\n' + indent + ' ' + file.fileName;\n });\n\n return res;\n }\n\n\n /**\n * Return a list of all reflections exposed by the files within this directory.\n *\n * @returns An aggregated list of all [[DeclarationReflection]] defined in the\n * files of this directory.\n */\n getAllReflections():Reflection[] {\n var reflections:Reflection[] = [];\n this.files.forEach((file) => {\n reflections.push.apply(reflections, file.reflections);\n });\n\n // reflections.sort(Factories.GroupHandler.sortCallback);\n return reflections;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/sources/file.d.ts b/lib/models/sources/file.d.ts new file mode 100644 index 000000000..d8f8ef9d2 --- /dev/null +++ b/lib/models/sources/file.d.ts @@ -0,0 +1,20 @@ +import { Reflection } from "../reflections/abstract"; +import { ReflectionGroup } from "../ReflectionGroup"; +import { SourceDirectory } from "./directory"; +export interface ISourceReference { + file?: SourceFile; + fileName: string; + line: number; + character: number; + url?: string; +} +export declare class SourceFile { + fullFileName: string; + fileName: string; + name: string; + url: string; + parent: SourceDirectory; + reflections: Reflection[]; + groups: ReflectionGroup[]; + constructor(fullFileName: string); +} diff --git a/lib/models/sources/file.js b/lib/models/sources/file.js new file mode 100644 index 000000000..dc3dee58a --- /dev/null +++ b/lib/models/sources/file.js @@ -0,0 +1,13 @@ +"use strict"; +var Path = require("path"); +var SourceFile = (function () { + function SourceFile(fullFileName) { + this.reflections = []; + this.fileName = fullFileName; + this.fullFileName = fullFileName; + this.name = Path.basename(fullFileName); + } + return SourceFile; +}()); +exports.SourceFile = SourceFile; +//# sourceMappingURL=file.js.map \ No newline at end of file diff --git a/lib/models/sources/file.js.map b/lib/models/sources/file.js.map new file mode 100644 index 000000000..411726ed6 --- /dev/null +++ b/lib/models/sources/file.js.map @@ -0,0 +1 @@ +{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/lib/models/sources/file.ts"],"names":[],"mappings":";AAAA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAgD7B;IA4CI,oBAAY,YAAmB;QAb/B,gBAAW,GAAgB,EAAE,CAAC;QAc1B,IAAI,CAAC,QAAQ,GAAO,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,IAAI,GAAW,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpD,CAAC;IACL,iBAAC;AAAD,CAAC,AAjDD,IAiDC;AAjDY,kBAAU,aAiDtB,CAAA","sourcesContent":["import * as Path from \"path\";\n\nimport {Reflection} from \"../reflections/abstract\";\nimport {ReflectionGroup} from \"../ReflectionGroup\";\nimport {SourceDirectory} from \"./directory\";\n\n\n/**\n * Represents references of reflections to their defining source files.\n *\n * @see [[DeclarationReflection.sources]]\n */\nexport interface ISourceReference\n{\n /**\n * A reference to the corresponding file instance.\n */\n file?:SourceFile;\n\n /**\n * The filename of the source file.\n */\n fileName:string;\n\n /**\n * The number of the line that emitted the declaration.\n */\n line:number;\n\n character:number;\n\n /**\n * URL for displaying the source file.\n */\n url?:string;\n}\n\n\n/**\n * Exposes information about a source file.\n *\n * One my access a list of all source files through the [[ProjectReflection.files]] property or as\n * a tree structure through the [[ProjectReflection.directory]] property.\n *\n * Furthermore each reflection carries references to the related SourceFile with their\n * [[DeclarationReflection.sources]] property. It is an array of of [[IDeclarationSource]] instances\n * containing the reference in their [[IDeclarationSource.file]] field.\n */\nexport class SourceFile\n{\n /**\n * The original full system file name.\n */\n fullFileName:string;\n\n /**\n * A trimmed version of the file name. Contains only the path relative to the\n * determined base path.\n */\n fileName:string;\n\n /**\n * The base name of the file.\n */\n name:string;\n\n /**\n * A url pointing to a page displaying the contents of this file.\n */\n url:string;\n\n /**\n * The representation of the parent directory of this source file.\n */\n parent:SourceDirectory;\n\n /**\n * A list of all reflections that are declared in this file.\n */\n reflections:Reflection[] = [];\n\n /**\n * A grouped list of the reflections declared in this file.\n */\n groups:ReflectionGroup[];\n\n\n /**\n * Create a new SourceFile instance.\n *\n * @param fullFileName The full file name.\n */\n constructor(fullFileName:string) {\n this.fileName = fullFileName;\n this.fullFileName = fullFileName;\n this.name = Path.basename(fullFileName);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/sources/index.d.ts b/lib/models/sources/index.d.ts new file mode 100644 index 000000000..6b85a96b2 --- /dev/null +++ b/lib/models/sources/index.d.ts @@ -0,0 +1,2 @@ +export { SourceDirectory } from "./directory"; +export { SourceFile } from "./file"; diff --git a/lib/models/sources/index.js b/lib/models/sources/index.js new file mode 100644 index 000000000..ef4fd7f42 --- /dev/null +++ b/lib/models/sources/index.js @@ -0,0 +1,6 @@ +"use strict"; +var directory_1 = require("./directory"); +exports.SourceDirectory = directory_1.SourceDirectory; +var file_1 = require("./file"); +exports.SourceFile = file_1.SourceFile; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/models/sources/index.js.map b/lib/models/sources/index.js.map new file mode 100644 index 000000000..7c3bc3aa9 --- /dev/null +++ b/lib/models/sources/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/models/sources/index.ts"],"names":[],"mappings":";AAAA,0BAA8B,aAAa,CAAC;AAApC,sDAAoC;AAC5C,qBAAyB,QAAQ,CAAC;AAA1B,uCAA0B","sourcesContent":["export {SourceDirectory} from \"./directory\";\nexport {SourceFile} from \"./file\";\n"]} \ No newline at end of file diff --git a/lib/models/types/abstract.d.ts b/lib/models/types/abstract.d.ts new file mode 100644 index 000000000..8f59903d6 --- /dev/null +++ b/lib/models/types/abstract.d.ts @@ -0,0 +1,9 @@ +export declare abstract class Type { + isArray: boolean; + abstract clone(): Type; + equals(type: Type): boolean; + toObject(): any; + toString(): string; + static isTypeListSimiliar(a: Type[], b: Type[]): boolean; + static isTypeListEqual(a: Type[], b: Type[]): boolean; +} diff --git a/lib/models/types/abstract.js b/lib/models/types/abstract.js new file mode 100644 index 000000000..1f1431c00 --- /dev/null +++ b/lib/models/types/abstract.js @@ -0,0 +1,46 @@ +"use strict"; +var Type = (function () { + function Type() { + this.isArray = false; + } + Type.prototype.equals = function (type) { + return false; + }; + Type.prototype.toObject = function () { + var result = {}; + result.type = 'void'; + if (this.isArray) { + result.isArray = this.isArray; + } + return result; + }; + Type.prototype.toString = function () { + return 'void'; + }; + Type.isTypeListSimiliar = function (a, b) { + if (a.length != b.length) + return false; + outerLoop: for (var an = 0, count = a.length; an < count; an++) { + var at = a[an]; + for (var bn = 0; bn < count; bn++) { + if (b[bn].equals(at)) + continue outerLoop; + } + return false; + } + return true; + }; + Type.isTypeListEqual = function (a, b) { + if (a.length != b.length) + return false; + for (var index = 0, count = a.length; index < count; index++) { + if (!a[index].equals(b[index])) { + return false; + } + } + return true; + }; + return Type; +}()); +exports.Type = Type; +//# sourceMappingURL=abstract.js.map \ No newline at end of file diff --git a/lib/models/types/abstract.js.map b/lib/models/types/abstract.js.map new file mode 100644 index 000000000..b0077e966 --- /dev/null +++ b/lib/models/types/abstract.js.map @@ -0,0 +1 @@ +{"version":3,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AAQ;QACrC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC;YAAC,MAAM,CAAC,KAAK,CAAC;QACvC,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC;YAC3D,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,MAAM,CAAC,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QAED,MAAM,CAAC,IAAI,CAAC;IAChB,CAAC;IACL,WAAC;AAAD,CAAC,AAxFD,IAwFC;AAxFqB,YAAI,OAwFzB,CAAA","sourcesContent":["/**\n * Base class of all type definitions.\n *\n * Instances of this class are also used to represent the type `void`.\n */\nexport abstract class Type\n{\n /**\n * Is this an array type?\n */\n isArray:boolean = false;\n\n\n\n /**\n * Clone this type.\n *\n * @return A clone of this type.\n */\n abstract clone():Type;\n\n\n /**\n * Test whether this type equals the given type.\n *\n * @param type The type that should be checked for equality.\n * @returns TRUE if the given type equals this type, FALSE otherwise.\n */\n equals(type:Type):boolean {\n return false;\n }\n\n\n /**\n * Return a raw object representation of this type.\n */\n toObject():any {\n var result:any = {};\n result.type = 'void';\n\n if (this.isArray) {\n result.isArray = this.isArray;\n }\n\n return result;\n }\n\n\n /**\n * Return a string representation of this type.\n */\n toString():string {\n return 'void';\n }\n\n\n /**\n * Test whether the two given list of types contain equal types.\n *\n * @param a\n * @param b\n */\n static isTypeListSimiliar(a:Type[], b:Type[]):boolean {\n if (a.length != b.length) return false;\n outerLoop: for (var an = 0, count = a.length; an < count; an++) {\n var at = a[an];\n for (var bn = 0; bn < count; bn++) {\n if (b[bn].equals(at)) continue outerLoop;\n }\n\n return false;\n }\n\n return true;\n }\n\n\n /**\n * Test whether the two given list of types are equal.\n *\n * @param a\n * @param b\n */\n static isTypeListEqual(a:Type[], b:Type[]):boolean {\n if (a.length != b.length) return false;\n for (var index = 0, count = a.length; index < count; index++) {\n if (!a[index].equals(b[index])) {\n return false;\n }\n }\n\n return true;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/types/index.d.ts b/lib/models/types/index.d.ts new file mode 100644 index 000000000..1b35a66c7 --- /dev/null +++ b/lib/models/types/index.d.ts @@ -0,0 +1,9 @@ +export { Type } from "./abstract"; +export { IntrinsicType } from "./intrinsic"; +export { ReferenceType } from "./reference"; +export { ReflectionType } from "./reflection"; +export { StringLiteralType } from "./string-literal"; +export { TupleType } from "./tuple"; +export { TypeParameterType } from "./type-parameter"; +export { UnionType } from "./union"; +export { UnknownType } from "./unknown"; diff --git a/lib/models/types/index.js b/lib/models/types/index.js new file mode 100644 index 000000000..ee75176ac --- /dev/null +++ b/lib/models/types/index.js @@ -0,0 +1,20 @@ +"use strict"; +var abstract_1 = require("./abstract"); +exports.Type = abstract_1.Type; +var intrinsic_1 = require("./intrinsic"); +exports.IntrinsicType = intrinsic_1.IntrinsicType; +var reference_1 = require("./reference"); +exports.ReferenceType = reference_1.ReferenceType; +var reflection_1 = require("./reflection"); +exports.ReflectionType = reflection_1.ReflectionType; +var string_literal_1 = require("./string-literal"); +exports.StringLiteralType = string_literal_1.StringLiteralType; +var tuple_1 = require("./tuple"); +exports.TupleType = tuple_1.TupleType; +var type_parameter_1 = require("./type-parameter"); +exports.TypeParameterType = type_parameter_1.TypeParameterType; +var union_1 = require("./union"); +exports.UnionType = union_1.UnionType; +var unknown_1 = require("./unknown"); +exports.UnknownType = unknown_1.UnknownType; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/models/types/index.js.map b/lib/models/types/index.js.map new file mode 100644 index 000000000..356c7e6b5 --- /dev/null +++ b/lib/models/types/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/models/types/index.ts"],"names":[],"mappings":";AAAA,yBAAmB,YAAY,CAAC;AAAxB,+BAAwB;AAChC,0BAA4B,aAAa,CAAC;AAAlC,kDAAkC;AAC1C,0BAA4B,aAAa,CAAC;AAAlC,kDAAkC;AAC1C,2BAA6B,cAAc,CAAC;AAApC,qDAAoC;AAC5C,+BAAgC,kBAAkB,CAAC;AAA3C,+DAA2C;AACnD,sBAAwB,SAAS,CAAC;AAA1B,sCAA0B;AAClC,+BAAgC,kBAAkB,CAAC;AAA3C,+DAA2C;AACnD,sBAAwB,SAAS,CAAC;AAA1B,sCAA0B;AAClC,wBAA0B,WAAW,CAAC;AAA9B,4CAA8B","sourcesContent":["export {Type} from \"./abstract\";\nexport {IntrinsicType} from \"./intrinsic\";\nexport {ReferenceType} from \"./reference\";\nexport {ReflectionType} from \"./reflection\";\nexport {StringLiteralType} from \"./string-literal\";\nexport {TupleType} from \"./tuple\";\nexport {TypeParameterType} from \"./type-parameter\";\nexport {UnionType} from \"./union\";\nexport {UnknownType} from \"./unknown\";\n"]} \ No newline at end of file diff --git a/lib/models/types/intrinsic.d.ts b/lib/models/types/intrinsic.d.ts new file mode 100644 index 000000000..b1b13f0ab --- /dev/null +++ b/lib/models/types/intrinsic.d.ts @@ -0,0 +1,9 @@ +import { Type } from "./abstract"; +export declare class IntrinsicType extends Type { + name: string; + constructor(name: string); + clone(): Type; + equals(type: IntrinsicType): boolean; + toObject(): any; + toString(): string; +} diff --git a/lib/models/types/intrinsic.js b/lib/models/types/intrinsic.js new file mode 100644 index 000000000..d20a612fa --- /dev/null +++ b/lib/models/types/intrinsic.js @@ -0,0 +1,36 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var IntrinsicType = (function (_super) { + __extends(IntrinsicType, _super); + function IntrinsicType(name) { + _super.call(this); + this.name = name; + } + IntrinsicType.prototype.clone = function () { + var clone = new IntrinsicType(this.name); + clone.isArray = this.isArray; + return clone; + }; + IntrinsicType.prototype.equals = function (type) { + return type instanceof IntrinsicType && + type.isArray == this.isArray && + type.name == this.name; + }; + IntrinsicType.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + result.type = 'instrinct'; + result.name = this.name; + return result; + }; + IntrinsicType.prototype.toString = function () { + return this.name + (this.isArray ? '[]' : ''); + }; + return IntrinsicType; +}(abstract_1.Type)); +exports.IntrinsicType = IntrinsicType; +//# sourceMappingURL=intrinsic.js.map \ No newline at end of file diff --git a/lib/models/types/intrinsic.js.map b/lib/models/types/intrinsic.js.map new file mode 100644 index 000000000..802bb1440 --- /dev/null +++ b/lib/models/types/intrinsic.js.map @@ -0,0 +1 @@ +{"version":3,"file":"intrinsic.js","sourceRoot":"","sources":["../../../src/lib/models/types/intrinsic.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAmB,YAAY,CAAC,CAAA;AAUhC;IAAmC,iCAAI;IAcnC,uBAAY,IAAW;QACnB,iBAAO,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAQD,6BAAK,GAAL;QACI,IAAI,KAAK,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IASD,8BAAM,GAAN,UAAO,IAAkB;QACrB,MAAM,CAAC,IAAI,YAAY,aAAa;YAChC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;YAC5B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC;IAC/B,CAAC;IAMD,gCAAQ,GAAR;QACI,IAAI,MAAM,GAAO,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,WAAW,CAAC;QAC1B,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,gCAAQ,GAAR;QACI,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC;IAClD,CAAC;IACL,oBAAC;AAAD,CAAC,AA9DD,CAAmC,eAAI,GA8DtC;AA9DY,qBAAa,gBA8DzB,CAAA","sourcesContent":["import {Type} from \"./abstract\";\n\n\n/**\n * Represents an intrinsic type like `string` or `boolean`.\n *\n * ~~~\n * var value:number;\n * ~~~\n */\nexport class IntrinsicType extends Type\n{\n /**\n * The name of the intrinsic type like `string` or `boolean`.\n */\n name:string;\n\n\n\n /**\n * Create a new instance of IntrinsicType.\n *\n * @param name The name of the intrinsic type like `string` or `boolean`.\n */\n constructor(name:string) {\n super();\n this.name = name;\n }\n\n\n /**\n * Clone this type.\n *\n * @return A clone of this type.\n */\n clone():Type {\n var clone = new IntrinsicType(this.name);\n clone.isArray = this.isArray;\n return clone;\n }\n\n\n /**\n * Test whether this type equals the given type.\n *\n * @param type The type that should be checked for equality.\n * @returns TRUE if the given type equals this type, FALSE otherwise.\n */\n equals(type:IntrinsicType):boolean {\n return type instanceof IntrinsicType &&\n type.isArray == this.isArray &&\n type.name == this.name;\n }\n\n\n /**\n * Return a raw object representation of this type.\n */\n toObject():any {\n var result:any = super.toObject();\n result.type = 'instrinct';\n result.name = this.name;\n return result;\n }\n\n\n /**\n * Return a string representation of this type.\n */\n toString() {\n return this.name + (this.isArray ? '[]' : '');\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/types/reference.d.ts b/lib/models/types/reference.d.ts new file mode 100644 index 000000000..539c2e182 --- /dev/null +++ b/lib/models/types/reference.d.ts @@ -0,0 +1,15 @@ +import { Reflection } from "../reflections/abstract"; +import { Type } from "./abstract"; +export declare class ReferenceType extends Type { + name: string; + typeArguments: Type[]; + symbolID: number; + reflection: Reflection; + static SYMBOL_ID_RESOLVED: number; + static SYMBOL_ID_RESOLVE_BY_NAME: number; + constructor(name: string, symbolID: number, reflection?: Reflection); + clone(): Type; + equals(type: ReferenceType): boolean; + toObject(): any; + toString(): string; +} diff --git a/lib/models/types/reference.js b/lib/models/types/reference.js new file mode 100644 index 000000000..374684194 --- /dev/null +++ b/lib/models/types/reference.js @@ -0,0 +1,52 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var ReferenceType = (function (_super) { + __extends(ReferenceType, _super); + function ReferenceType(name, symbolID, reflection) { + _super.call(this); + this.name = name; + this.symbolID = symbolID; + this.reflection = reflection; + } + ReferenceType.prototype.clone = function () { + var clone = new ReferenceType(this.name, this.symbolID, this.reflection); + clone.isArray = this.isArray; + clone.typeArguments = this.typeArguments; + return clone; + }; + ReferenceType.prototype.equals = function (type) { + return type instanceof ReferenceType && + type.isArray == this.isArray && + (type.symbolID == this.symbolID || type.reflection == this.reflection); + }; + ReferenceType.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + result.type = 'reference'; + result.name = this.name; + if (this.reflection) { + result.id = this.reflection.id; + } + if (this.typeArguments) { + result.typeArguments = this.typeArguments.map(function (t) { return t.toObject(); }); + } + return result; + }; + ReferenceType.prototype.toString = function () { + if (this.reflection) { + return this.reflection.name + (this.isArray ? '[]' : ''); + } + else { + return this.name + (this.isArray ? '[]' : ''); + } + }; + ReferenceType.SYMBOL_ID_RESOLVED = -1; + ReferenceType.SYMBOL_ID_RESOLVE_BY_NAME = -2; + return ReferenceType; +}(abstract_1.Type)); +exports.ReferenceType = ReferenceType; +//# sourceMappingURL=reference.js.map \ No newline at end of file diff --git a/lib/models/types/reference.js.map b/lib/models/types/reference.js.map new file mode 100644 index 000000000..e318fab60 --- /dev/null +++ b/lib/models/types/reference.js.map @@ -0,0 +1 @@ +{"version":3,"file":"reference.js","sourceRoot":"","sources":["../../../src/lib/models/types/reference.ts"],"names":[],"mappings":";;;;;;AACA,yBAAmB,YAAY,CAAC,CAAA;AAUhC;IAAmC,iCAAI;IAgDnC,uBAAY,IAAW,EAAE,QAAe,EAAE,UAAsB;QAC5D,iBAAO,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAQD,6BAAK,GAAL;QACI,IAAI,KAAK,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACzE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IASD,8BAAM,GAAN,UAAO,IAAkB;QACrB,MAAM,CAAC,IAAI,YAAY,aAAa;YAChC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;YAC5B,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;IAC/E,CAAC;IAMD,gCAAQ,GAAR;QACI,IAAI,MAAM,GAAO,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,WAAW,CAAC;QAC1B,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YAClB,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,CAAC;QAED,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;YACrB,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,QAAQ,EAAE,EAAZ,CAAY,CAAC,CAAC;QACvE,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,gCAAQ,GAAR;QACI,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC;QAC7D,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC;QAClD,CAAC;IACL,CAAC;IA9EM,gCAAkB,GAAU,CAAC,CAAC,CAAC;IAK/B,uCAAyB,GAAU,CAAC,CAAC,CAAC;IA0EjD,oBAAC;AAAD,CAAC,AAhHD,CAAmC,eAAI,GAgHtC;AAhHY,qBAAa,gBAgHzB,CAAA","sourcesContent":["import {Reflection} from \"../reflections/abstract\";\nimport {Type} from \"./abstract\";\n\n\n/**\n * Represents a type that refers to another reflection like a class, interface or enum.\n *\n * ~~~\n * var value:MyClass;\n * ~~~\n */\nexport class ReferenceType extends Type\n{\n /**\n * The name of the referenced type.\n *\n * If the symbol cannot be found cause it's not part of the documentation this\n * can be used to represent the type.\n */\n name:string;\n\n /**\n * The type arguments of this reference.\n */\n typeArguments:Type[];\n\n /**\n * The symbol id of the referenced type as returned from the TypeScript compiler.\n *\n * After the all reflections have been generated this is can be used to lookup the\n * relevant reflection with [[ProjectReflection.symbolMapping]].\n */\n symbolID:number;\n\n /**\n * The resolved reflection.\n *\n * The [[TypePlugin]] will try to set this property in the resolving phase.\n */\n reflection:Reflection;\n\n /**\n * Special symbol ID noting that the reference of a ReferenceType was known when creating the type.\n */\n static SYMBOL_ID_RESOLVED:number = -1;\n\n /**\n * Special symbol ID noting that the reference should be resolved by the type name.\n */\n static SYMBOL_ID_RESOLVE_BY_NAME:number = -2;\n\n\n /**\n * Create a new instance of ReferenceType.\n *\n * @param name The name of the referenced type.\n * @param symbolID The symbol id of the referenced type as returned from the TypeScript compiler.\n * @param reflection The resolved reflection if already known.\n */\n constructor(name:string, symbolID:number, reflection?:Reflection) {\n super();\n this.name = name;\n this.symbolID = symbolID;\n this.reflection = reflection;\n }\n\n\n /**\n * Clone this type.\n *\n * @return A clone of this type.\n */\n clone():Type {\n var clone = new ReferenceType(this.name, this.symbolID, this.reflection);\n clone.isArray = this.isArray;\n clone.typeArguments = this.typeArguments;\n return clone;\n }\n\n\n /**\n * Test whether this type equals the given type.\n *\n * @param type The type that should be checked for equality.\n * @returns TRUE if the given type equals this type, FALSE otherwise.\n */\n equals(type:ReferenceType):boolean {\n return type instanceof ReferenceType &&\n type.isArray == this.isArray &&\n (type.symbolID == this.symbolID || type.reflection == this.reflection);\n }\n\n\n /**\n * Return a raw object representation of this type.\n */\n toObject():any {\n var result:any = super.toObject();\n result.type = 'reference';\n result.name = this.name;\n\n if (this.reflection) {\n result.id = this.reflection.id;\n }\n\n if (this.typeArguments) {\n result.typeArguments = this.typeArguments.map((t) => t.toObject());\n }\n\n return result;\n }\n\n\n /**\n * Return a string representation of this type.\n */\n toString() {\n if (this.reflection) {\n return this.reflection.name + (this.isArray ? '[]' : '');\n } else {\n return this.name + (this.isArray ? '[]' : '');\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/types/reflection.d.ts b/lib/models/types/reflection.d.ts new file mode 100644 index 000000000..0bfd3a3f3 --- /dev/null +++ b/lib/models/types/reflection.d.ts @@ -0,0 +1,10 @@ +import { DeclarationReflection } from "../reflections/declaration"; +import { Type } from "./abstract"; +export declare class ReflectionType extends Type { + declaration: DeclarationReflection; + constructor(declaration: DeclarationReflection); + clone(): Type; + equals(type: ReflectionType): boolean; + toObject(): any; + toString(): string; +} diff --git a/lib/models/types/reflection.js b/lib/models/types/reflection.js new file mode 100644 index 000000000..542e55e4f --- /dev/null +++ b/lib/models/types/reflection.js @@ -0,0 +1,41 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var ReflectionType = (function (_super) { + __extends(ReflectionType, _super); + function ReflectionType(declaration) { + _super.call(this); + this.declaration = declaration; + } + ReflectionType.prototype.clone = function () { + var clone = new ReflectionType(this.declaration); + clone.isArray = this.isArray; + return clone; + }; + ReflectionType.prototype.equals = function (type) { + return type == this; + }; + ReflectionType.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + result.type = 'reflection'; + if (this.declaration) { + result.declaration = this.declaration.toObject(); + } + return result; + }; + ReflectionType.prototype.toString = function () { + if (!this.declaration.children && this.declaration.signatures) { + return 'function'; + } + else { + return 'object'; + } + }; + return ReflectionType; +}(abstract_1.Type)); +exports.ReflectionType = ReflectionType; +//# sourceMappingURL=reflection.js.map \ No newline at end of file diff --git a/lib/models/types/reflection.js.map b/lib/models/types/reflection.js.map new file mode 100644 index 000000000..93f6a20a9 --- /dev/null +++ b/lib/models/types/reflection.js.map @@ -0,0 +1 @@ +{"version":3,"file":"reflection.js","sourceRoot":"","sources":["../../../src/lib/models/types/reflection.ts"],"names":[],"mappings":";;;;;;AACA,yBAAmB,YAAY,CAAC,CAAA;AAUhC;IAAoC,kCAAI;IAcpC,wBAAY,WAAiC;QACzC,iBAAO,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;IAQD,8BAAK,GAAL;QACI,IAAI,KAAK,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACjD,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IASD,+BAAM,GAAN,UAAO,IAAmB;QACtB,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC;IACxB,CAAC;IAMD,iCAAQ,GAAR;QACI,IAAI,MAAM,GAAO,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,YAAY,CAAC;QAE3B,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;YACnB,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;QACrD,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,iCAAQ,GAAR;QACI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;YAC5D,MAAM,CAAC,UAAU,CAAC;QACtB,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,MAAM,CAAC,QAAQ,CAAC;QACpB,CAAC;IACL,CAAC;IACL,qBAAC;AAAD,CAAC,AApED,CAAoC,eAAI,GAoEvC;AApEY,sBAAc,iBAoE1B,CAAA","sourcesContent":["import {DeclarationReflection} from \"../reflections/declaration\";\nimport {Type} from \"./abstract\";\n\n\n/**\n * Represents a type which has it's own reflection like literal types.\n *\n * ~~~\n * var value:{subValueA;subValueB;subValueC;};\n * ~~~\n */\nexport class ReflectionType extends Type\n{\n /**\n * The reflection of the type.\n */\n declaration:DeclarationReflection;\n\n\n\n /**\n * Create a new instance of ReflectionType.\n *\n * @param declaration The reflection of the type.\n */\n constructor(declaration:DeclarationReflection) {\n super();\n this.declaration = declaration;\n }\n\n\n /**\n * Clone this type.\n *\n * @return A clone of this type.\n */\n clone():Type {\n var clone = new ReflectionType(this.declaration);\n clone.isArray = this.isArray;\n return clone;\n }\n\n\n /**\n * Test whether this type equals the given type.\n *\n * @param type The type that should be checked for equality.\n * @returns TRUE if the given type equals this type, FALSE otherwise.\n */\n equals(type:ReflectionType):boolean {\n return type == this;\n }\n\n\n /**\n * Return a raw object representation of this type.\n */\n toObject():any {\n var result:any = super.toObject();\n result.type = 'reflection';\n\n if (this.declaration) {\n result.declaration = this.declaration.toObject();\n }\n\n return result;\n }\n\n\n /**\n * Return a string representation of this type.\n */\n toString() {\n if (!this.declaration.children && this.declaration.signatures) {\n return 'function';\n } else {\n return 'object';\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/types/string-literal.d.ts b/lib/models/types/string-literal.d.ts new file mode 100644 index 000000000..1797bb155 --- /dev/null +++ b/lib/models/types/string-literal.d.ts @@ -0,0 +1,9 @@ +import { Type } from "./abstract"; +export declare class StringLiteralType extends Type { + value: string; + constructor(value: string); + clone(): Type; + equals(type: StringLiteralType): boolean; + toObject(): any; + toString(): string; +} diff --git a/lib/models/types/string-literal.js b/lib/models/types/string-literal.js new file mode 100644 index 000000000..590203745 --- /dev/null +++ b/lib/models/types/string-literal.js @@ -0,0 +1,36 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var StringLiteralType = (function (_super) { + __extends(StringLiteralType, _super); + function StringLiteralType(value) { + _super.call(this); + this.value = value; + } + StringLiteralType.prototype.clone = function () { + var clone = new StringLiteralType(this.value); + clone.isArray = this.isArray; + return clone; + }; + StringLiteralType.prototype.equals = function (type) { + return type instanceof StringLiteralType && + type.isArray == this.isArray && + type.value == this.value; + }; + StringLiteralType.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + result.type = 'stringLiteral'; + result.value = this.value; + return result; + }; + StringLiteralType.prototype.toString = function () { + return '"' + this.value + '"'; + }; + return StringLiteralType; +}(abstract_1.Type)); +exports.StringLiteralType = StringLiteralType; +//# sourceMappingURL=string-literal.js.map \ No newline at end of file diff --git a/lib/models/types/string-literal.js.map b/lib/models/types/string-literal.js.map new file mode 100644 index 000000000..bafcb86c7 --- /dev/null +++ b/lib/models/types/string-literal.js.map @@ -0,0 +1 @@ +{"version":3,"file":"string-literal.js","sourceRoot":"","sources":["../../../src/lib/models/types/string-literal.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAmB,YAAY,CAAC,CAAA;AAUhC;IAAuC,qCAAI;IAavC,2BAAY,KAAY;QACpB,iBAAO,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAQD,iCAAK,GAAL;QACI,IAAI,KAAK,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IASD,kCAAM,GAAN,UAAO,IAAsB;QACzB,MAAM,CAAC,IAAI,YAAY,iBAAiB;YACpC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;YAC5B,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;IACjC,CAAC;IAMD,oCAAQ,GAAR;QACI,IAAI,MAAM,GAAO,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,eAAe,CAAC;QAC9B,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAC1B,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,oCAAQ,GAAR;QACI,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;IAClC,CAAC;IACL,wBAAC;AAAD,CAAC,AA7DD,CAAuC,eAAI,GA6D1C;AA7DY,yBAAiB,oBA6D7B,CAAA","sourcesContent":["import {Type} from \"./abstract\";\n\n\n/**\n * Represents a string literal type.\n *\n * ~~~\n * var value:\"DIV\";\n * ~~~\n */\nexport class StringLiteralType extends Type\n{\n /**\n * The string literal value.\n */\n value:string;\n\n\n /**\n * Create a new instance of StringLiteralType.\n *\n * @param value The string literal value.\n */\n constructor(value:string) {\n super();\n this.value = value;\n }\n\n\n /**\n * Clone this type.\n *\n * @return A clone of this type.\n */\n clone():Type {\n var clone = new StringLiteralType(this.value);\n clone.isArray = this.isArray;\n return clone;\n }\n\n\n /**\n * Test whether this type equals the given type.\n *\n * @param type The type that should be checked for equality.\n * @returns TRUE if the given type equals this type, FALSE otherwise.\n */\n equals(type:StringLiteralType):boolean {\n return type instanceof StringLiteralType &&\n type.isArray == this.isArray &&\n type.value == this.value;\n }\n\n\n /**\n * Return a raw object representation of this type.\n */\n toObject():any {\n var result:any = super.toObject();\n result.type = 'stringLiteral';\n result.value = this.value;\n return result;\n }\n\n\n /**\n * Return a string representation of this type.\n */\n toString():string {\n return '\"' + this.value + '\"';\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/types/tuple.d.ts b/lib/models/types/tuple.d.ts new file mode 100644 index 000000000..42178c358 --- /dev/null +++ b/lib/models/types/tuple.d.ts @@ -0,0 +1,9 @@ +import { Type } from "./abstract"; +export declare class TupleType extends Type { + elements: Type[]; + constructor(elements: Type[]); + clone(): Type; + equals(type: TupleType): boolean; + toObject(): any; + toString(): string; +} diff --git a/lib/models/types/tuple.js b/lib/models/types/tuple.js new file mode 100644 index 000000000..c8a48f1f2 --- /dev/null +++ b/lib/models/types/tuple.js @@ -0,0 +1,44 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var TupleType = (function (_super) { + __extends(TupleType, _super); + function TupleType(elements) { + _super.call(this); + this.elements = elements; + } + TupleType.prototype.clone = function () { + var clone = new TupleType(this.elements); + clone.isArray = this.isArray; + return clone; + }; + TupleType.prototype.equals = function (type) { + if (!(type instanceof TupleType)) + return false; + if (type.isArray != this.isArray) + return false; + return abstract_1.Type.isTypeListEqual(type.elements, this.elements); + }; + TupleType.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + result.type = 'tuple'; + if (this.elements && this.elements.length) { + result.elements = this.elements.map(function (e) { return e.toObject(); }); + } + return result; + }; + TupleType.prototype.toString = function () { + var names = []; + this.elements.forEach(function (element) { + names.push(element.toString()); + }); + return '[' + names.join(', ') + ']'; + }; + return TupleType; +}(abstract_1.Type)); +exports.TupleType = TupleType; +//# sourceMappingURL=tuple.js.map \ No newline at end of file diff --git a/lib/models/types/tuple.js.map b/lib/models/types/tuple.js.map new file mode 100644 index 000000000..e3daba2d5 --- /dev/null +++ b/lib/models/types/tuple.js.map @@ -0,0 +1 @@ +{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../../src/lib/models/types/tuple.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAmB,YAAY,CAAC,CAAA;AAUhC;IAA+B,6BAAI;IAa/B,mBAAY,QAAe;QACvB,iBAAO,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IAQD,yBAAK,GAAL;QACI,IAAI,KAAK,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IASD,0BAAM,GAAN,UAAO,IAAc;QACjB,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,SAAS,CAAC,CAAC;YAAC,MAAM,CAAC,KAAK,CAAC;QAC/C,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC;YAAC,MAAM,CAAC,KAAK,CAAC;QAC/C,MAAM,CAAC,eAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAMD,4BAAQ,GAAR;QACI,IAAI,MAAM,GAAO,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;QAEtB,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;YACxC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,QAAQ,EAAE,EAAZ,CAAY,CAAC,CAAC;QAC7D,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,4BAAQ,GAAR;QACI,IAAI,KAAK,GAAY,EAAE,CAAC;QACxB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAC,OAAO;YAC1B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QAClC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;IACxC,CAAC;IACL,gBAAC;AAAD,CAAC,AAtED,CAA+B,eAAI,GAsElC;AAtEY,iBAAS,YAsErB,CAAA","sourcesContent":["import {Type} from \"./abstract\";\n\n\n/**\n * Represents a tuple type.\n *\n * ~~~\n * var value:[string,boolean];\n * ~~~\n */\nexport class TupleType extends Type\n{\n /**\n * The ordered type elements of the tuple type.\n */\n elements:Type[];\n\n\n /**\n * Create a new TupleType instance.\n *\n * @param elements The ordered type elements of the tuple type.\n */\n constructor(elements:Type[]) {\n super();\n this.elements = elements;\n }\n\n\n /**\n * Clone this type.\n *\n * @return A clone of this type.\n */\n clone():Type {\n var clone = new TupleType(this.elements);\n clone.isArray = this.isArray;\n return clone;\n }\n\n\n /**\n * Test whether this type equals the given type.\n *\n * @param type The type that should be checked for equality.\n * @returns TRUE if the given type equals this type, FALSE otherwise.\n */\n equals(type:TupleType):boolean {\n if (!(type instanceof TupleType)) return false;\n if (type.isArray != this.isArray) return false;\n return Type.isTypeListEqual(type.elements, this.elements);\n }\n\n\n /**\n * Return a raw object representation of this type.\n */\n toObject():any {\n var result:any = super.toObject();\n result.type = 'tuple';\n\n if (this.elements && this.elements.length) {\n result.elements = this.elements.map((e) => e.toObject());\n }\n\n return result;\n }\n\n\n /**\n * Return a string representation of this type.\n */\n toString() {\n var names:string[] = [];\n this.elements.forEach((element) => {\n names.push(element.toString())\n });\n\n return '[' + names.join(', ') + ']';\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/types/type-parameter.d.ts b/lib/models/types/type-parameter.d.ts new file mode 100644 index 000000000..52d1c2570 --- /dev/null +++ b/lib/models/types/type-parameter.d.ts @@ -0,0 +1,9 @@ +import { Type } from "./abstract"; +export declare class TypeParameterType extends Type { + name: string; + constraint: Type; + clone(): Type; + equals(type: TypeParameterType): boolean; + toObject(): any; + toString(): string; +} diff --git a/lib/models/types/type-parameter.js b/lib/models/types/type-parameter.js new file mode 100644 index 000000000..751f4e54a --- /dev/null +++ b/lib/models/types/type-parameter.js @@ -0,0 +1,52 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var TypeParameterType = (function (_super) { + __extends(TypeParameterType, _super); + function TypeParameterType() { + _super.apply(this, arguments); + } + TypeParameterType.prototype.clone = function () { + var clone = new TypeParameterType(); + clone.isArray = this.isArray; + clone.name = this.name; + clone.constraint = this.constraint; + return clone; + }; + TypeParameterType.prototype.equals = function (type) { + if (!(type instanceof TypeParameterType)) { + return false; + } + var constraintEquals; + if (this.constraint && type.constraint) { + constraintEquals = type.constraint.equals(this.constraint); + } + else if (!this.constraint && !type.constraint) { + constraintEquals = true; + } + else { + return false; + } + return constraintEquals && + type.isArray == this.isArray; + }; + TypeParameterType.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + result.type = 'typeParameter'; + result.name = this.name; + if (this.constraint) { + result.constraint = this.constraint.toObject(); + } + return result; + }; + TypeParameterType.prototype.toString = function () { + return this.name; + }; + return TypeParameterType; +}(abstract_1.Type)); +exports.TypeParameterType = TypeParameterType; +//# sourceMappingURL=type-parameter.js.map \ No newline at end of file diff --git a/lib/models/types/type-parameter.js.map b/lib/models/types/type-parameter.js.map new file mode 100644 index 000000000..6a197f9bc --- /dev/null +++ b/lib/models/types/type-parameter.js.map @@ -0,0 +1 @@ +{"version":3,"file":"type-parameter.js","sourceRoot":"","sources":["../../../src/lib/models/types/type-parameter.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAmB,YAAY,CAAC,CAAA;AAUhC;IAAuC,qCAAI;IAA3C;QAAuC,8BAAI;IAwE3C,CAAC;IAxDG,iCAAK,GAAL;QACI,IAAI,KAAK,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACpC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IASD,kCAAM,GAAN,UAAO,IAAsB;QACzB,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,iBAAiB,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,CAAC,KAAK,CAAC;QACjB,CAAC;QAED,IAAI,gBAAwB,CAAC;QAC7B,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YACrC,gBAAgB,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC/D,CAAC;QAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YAC9C,gBAAgB,GAAG,IAAI,CAAC;QAC5B,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,MAAM,CAAC,KAAK,CAAC;QACjB,CAAC;QAED,MAAM,CAAC,gBAAgB;YACnB,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC;IACrC,CAAC;IAMD,oCAAQ,GAAR;QACI,IAAI,MAAM,GAAO,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,eAAe,CAAC;QAC9B,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;YAClB,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QACnD,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,oCAAQ,GAAR;QACI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IACL,wBAAC;AAAD,CAAC,AAxED,CAAuC,eAAI,GAwE1C;AAxEY,yBAAiB,oBAwE7B,CAAA","sourcesContent":["import {Type} from \"./abstract\";\n\n\n/**\n * Represents a type parameter type.\n *\n * ~~~\n * var value:T;\n * ~~~\n */\nexport class TypeParameterType extends Type\n{\n /**\n *\n */\n name:string;\n\n constraint:Type;\n\n\n\n /**\n * Clone this type.\n *\n * @return A clone of this type.\n */\n clone():Type {\n var clone = new TypeParameterType();\n clone.isArray = this.isArray;\n clone.name = this.name;\n clone.constraint = this.constraint;\n return clone;\n }\n\n\n /**\n * Test whether this type equals the given type.\n *\n * @param type The type that should be checked for equality.\n * @returns TRUE if the given type equals this type, FALSE otherwise.\n */\n equals(type:TypeParameterType):boolean {\n if (!(type instanceof TypeParameterType)) {\n return false;\n }\n\n var constraintEquals:boolean;\n if (this.constraint && type.constraint) {\n constraintEquals = type.constraint.equals(this.constraint);\n } else if (!this.constraint && !type.constraint) {\n constraintEquals = true;\n } else {\n return false;\n }\n\n return constraintEquals &&\n type.isArray == this.isArray;\n }\n\n\n /**\n * Return a raw object representation of this type.\n */\n toObject():any {\n var result:any = super.toObject();\n result.type = 'typeParameter';\n result.name = this.name;\n\n if (this.constraint) {\n result.constraint = this.constraint.toObject();\n }\n\n return result;\n }\n\n\n /**\n * Return a string representation of this type.\n */\n toString() {\n return this.name;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/types/union.d.ts b/lib/models/types/union.d.ts new file mode 100644 index 000000000..6c11b8067 --- /dev/null +++ b/lib/models/types/union.d.ts @@ -0,0 +1,9 @@ +import { Type } from "./abstract"; +export declare class UnionType extends Type { + types: Type[]; + constructor(types: Type[]); + clone(): Type; + equals(type: UnionType): boolean; + toObject(): any; + toString(): string; +} diff --git a/lib/models/types/union.js b/lib/models/types/union.js new file mode 100644 index 000000000..1054abbd9 --- /dev/null +++ b/lib/models/types/union.js @@ -0,0 +1,44 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var UnionType = (function (_super) { + __extends(UnionType, _super); + function UnionType(types) { + _super.call(this); + this.types = types; + } + UnionType.prototype.clone = function () { + var clone = new UnionType(this.types); + clone.isArray = this.isArray; + return clone; + }; + UnionType.prototype.equals = function (type) { + if (!(type instanceof UnionType)) + return false; + if (type.isArray != this.isArray) + return false; + return abstract_1.Type.isTypeListSimiliar(type.types, this.types); + }; + UnionType.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + result.type = 'union'; + if (this.types && this.types.length) { + result.types = this.types.map(function (e) { return e.toObject(); }); + } + return result; + }; + UnionType.prototype.toString = function () { + var names = []; + this.types.forEach(function (element) { + names.push(element.toString()); + }); + return names.join(' | '); + }; + return UnionType; +}(abstract_1.Type)); +exports.UnionType = UnionType; +//# sourceMappingURL=union.js.map \ No newline at end of file diff --git a/lib/models/types/union.js.map b/lib/models/types/union.js.map new file mode 100644 index 000000000..90825ca34 --- /dev/null +++ b/lib/models/types/union.js.map @@ -0,0 +1 @@ +{"version":3,"file":"union.js","sourceRoot":"","sources":["../../../src/lib/models/types/union.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAmB,YAAY,CAAC,CAAA;AAUhC;IAA+B,6BAAI;IAa/B,mBAAY,KAAY;QACpB,iBAAO,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAQD,yBAAK,GAAL;QACI,IAAI,KAAK,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IASD,0BAAM,GAAN,UAAO,IAAc;QACjB,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,SAAS,CAAC,CAAC;YAAC,MAAM,CAAC,KAAK,CAAC;QAC/C,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC;YAAC,MAAM,CAAC,KAAK,CAAC;QAC/C,MAAM,CAAC,eAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3D,CAAC;IAMD,4BAAQ,GAAR;QACI,IAAI,MAAM,GAAO,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC;QAEtB,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;YAClC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,QAAQ,EAAE,EAAZ,CAAY,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,4BAAQ,GAAR;QACI,IAAI,KAAK,GAAY,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAC,OAAO;YACvB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QAClC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IACL,gBAAC;AAAD,CAAC,AAtED,CAA+B,eAAI,GAsElC;AAtEY,iBAAS,YAsErB,CAAA","sourcesContent":["import {Type} from \"./abstract\";\n\n\n/**\n * Represents an union type.\n *\n * ~~~\n * var value:string | string[];\n * ~~~\n */\nexport class UnionType extends Type\n{\n /**\n * The types this union consists of.\n */\n types:Type[];\n\n\n /**\n * Create a new TupleType instance.\n *\n * @param types The types this union consists of.\n */\n constructor(types:Type[]) {\n super();\n this.types = types;\n }\n\n\n /**\n * Clone this type.\n *\n * @return A clone of this type.\n */\n clone():Type {\n var clone = new UnionType(this.types);\n clone.isArray = this.isArray;\n return clone;\n }\n\n\n /**\n * Test whether this type equals the given type.\n *\n * @param type The type that should be checked for equality.\n * @returns TRUE if the given type equals this type, FALSE otherwise.\n */\n equals(type:UnionType):boolean {\n if (!(type instanceof UnionType)) return false;\n if (type.isArray != this.isArray) return false;\n return Type.isTypeListSimiliar(type.types, this.types);\n }\n\n\n /**\n * Return a raw object representation of this type.\n */\n toObject():any {\n var result:any = super.toObject();\n result.type = 'union';\n\n if (this.types && this.types.length) {\n result.types = this.types.map((e) => e.toObject());\n }\n\n return result;\n }\n\n\n /**\n * Return a string representation of this type.\n */\n toString() {\n var names:string[] = [];\n this.types.forEach((element) => {\n names.push(element.toString())\n });\n\n return names.join(' | ');\n }\n}\n"]} \ No newline at end of file diff --git a/lib/models/types/unknown.d.ts b/lib/models/types/unknown.d.ts new file mode 100644 index 000000000..885508b3a --- /dev/null +++ b/lib/models/types/unknown.d.ts @@ -0,0 +1,9 @@ +import { Type } from "./abstract"; +export declare class UnknownType extends Type { + name: string; + constructor(name: string); + clone(): Type; + equals(type: UnknownType): boolean; + toObject(): any; + toString(): string; +} diff --git a/lib/models/types/unknown.js b/lib/models/types/unknown.js new file mode 100644 index 000000000..e3ab16c4d --- /dev/null +++ b/lib/models/types/unknown.js @@ -0,0 +1,36 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var abstract_1 = require("./abstract"); +var UnknownType = (function (_super) { + __extends(UnknownType, _super); + function UnknownType(name) { + _super.call(this); + this.name = name; + } + UnknownType.prototype.clone = function () { + var clone = new UnknownType(this.name); + clone.isArray = this.isArray; + return clone; + }; + UnknownType.prototype.equals = function (type) { + return type instanceof UnknownType && + type.isArray == this.isArray && + type.name == this.name; + }; + UnknownType.prototype.toObject = function () { + var result = _super.prototype.toObject.call(this); + result.type = 'unknown'; + result.name = this.name; + return result; + }; + UnknownType.prototype.toString = function () { + return this.name; + }; + return UnknownType; +}(abstract_1.Type)); +exports.UnknownType = UnknownType; +//# sourceMappingURL=unknown.js.map \ No newline at end of file diff --git a/lib/models/types/unknown.js.map b/lib/models/types/unknown.js.map new file mode 100644 index 000000000..545ae625f --- /dev/null +++ b/lib/models/types/unknown.js.map @@ -0,0 +1 @@ +{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/lib/models/types/unknown.ts"],"names":[],"mappings":";;;;;;AAAA,yBAAmB,YAAY,CAAC,CAAA;AAMhC;IAAiC,+BAAI;IAajC,qBAAY,IAAW;QACnB,iBAAO,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAQD,2BAAK,GAAL;QACI,IAAI,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IASD,4BAAM,GAAN,UAAO,IAAgB;QACnB,MAAM,CAAC,IAAI,YAAY,WAAW;YAC9B,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO;YAC5B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC;IAC/B,CAAC;IAMD,8BAAQ,GAAR;QACI,IAAI,MAAM,GAAO,gBAAK,CAAC,QAAQ,WAAE,CAAC;QAClC,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC;QACxB,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IAMD,8BAAQ,GAAR;QACI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IACL,kBAAC;AAAD,CAAC,AA7DD,CAAiC,eAAI,GA6DpC;AA7DY,mBAAW,cA6DvB,CAAA","sourcesContent":["import {Type} from \"./abstract\";\n\n\n/**\n * Represents all unknown types.\n */\nexport class UnknownType extends Type\n{\n /**\n * A string representation of the type as returned from TypeScript compiler.\n */\n name:string;\n\n\n /**\n * Create a new instance of UnknownType.\n *\n * @param name A string representation of the type as returned from TypeScript compiler.\n */\n constructor(name:string) {\n super();\n this.name = name;\n }\n\n\n /**\n * Clone this type.\n *\n * @return A clone of this type.\n */\n clone():Type {\n var clone = new UnknownType(this.name);\n clone.isArray = this.isArray;\n return clone;\n }\n\n\n /**\n * Test whether this type equals the given type.\n *\n * @param type The type that should be checked for equality.\n * @returns TRUE if the given type equals this type, FALSE otherwise.\n */\n equals(type:UnknownType):boolean {\n return type instanceof UnknownType &&\n type.isArray == this.isArray &&\n type.name == this.name;\n }\n\n\n /**\n * Return a raw object representation of this type.\n */\n toObject():any {\n var result:any = super.toObject();\n result.type = 'unknown';\n result.name = this.name;\n return result;\n }\n\n\n /**\n * Return a string representation of this type.\n */\n toString() {\n return this.name;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/components.d.ts b/lib/output/components.d.ts new file mode 100644 index 000000000..b7cf93557 --- /dev/null +++ b/lib/output/components.d.ts @@ -0,0 +1,16 @@ +import { Component, AbstractComponent } from "../utils/component"; +import { ProjectReflection, DeclarationReflection } from "../models/reflections/index"; +import { Renderer } from "./renderer"; +import { RendererEvent, PageEvent } from "./events"; +export { Component }; +export declare abstract class RendererComponent extends AbstractComponent { +} +export declare abstract class ContextAwareRendererComponent extends RendererComponent { + protected project: ProjectReflection; + protected reflection: DeclarationReflection; + private location; + protected initialize(): void; + getRelativeUrl(absolute: string): string; + protected onBeginRenderer(event: RendererEvent): void; + protected onBeginPage(page: PageEvent): void; +} diff --git a/lib/output/components.js b/lib/output/components.js new file mode 100644 index 000000000..480ea4afc --- /dev/null +++ b/lib/output/components.js @@ -0,0 +1,47 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Path = require("path"); +var component_1 = require("../utils/component"); +exports.Component = component_1.Component; +var index_1 = require("../models/reflections/index"); +var events_1 = require("./events"); +var RendererComponent = (function (_super) { + __extends(RendererComponent, _super); + function RendererComponent() { + _super.apply(this, arguments); + } + return RendererComponent; +}(component_1.AbstractComponent)); +exports.RendererComponent = RendererComponent; +var ContextAwareRendererComponent = (function (_super) { + __extends(ContextAwareRendererComponent, _super); + function ContextAwareRendererComponent() { + _super.apply(this, arguments); + } + ContextAwareRendererComponent.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[events_1.RendererEvent.BEGIN] = this.onBeginRenderer, + _a[events_1.PageEvent.BEGIN] = this.onBeginPage, + _a + )); + var _a; + }; + ContextAwareRendererComponent.prototype.getRelativeUrl = function (absolute) { + var relative = Path.relative(Path.dirname(this.location), Path.dirname(absolute)); + return Path.join(relative, Path.basename(absolute)).replace(/\\/g, '/'); + }; + ContextAwareRendererComponent.prototype.onBeginRenderer = function (event) { + this.project = event.project; + }; + ContextAwareRendererComponent.prototype.onBeginPage = function (page) { + this.location = page.url; + this.reflection = page.model instanceof index_1.DeclarationReflection ? page.model : null; + }; + return ContextAwareRendererComponent; +}(RendererComponent)); +exports.ContextAwareRendererComponent = ContextAwareRendererComponent; +//# sourceMappingURL=components.js.map \ No newline at end of file diff --git a/lib/output/components.js.map b/lib/output/components.js.map new file mode 100644 index 000000000..9b3946858 --- /dev/null +++ b/lib/output/components.js.map @@ -0,0 +1 @@ +{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/lib/output/components.ts"],"names":[],"mappings":";;;;;;AAAA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAG7B,0BAA+D,oBAAoB,CAAC,CAAA;AAM5E,iBAAS;AALjB,sBAAuD,6BAA6B,CAAC,CAAA;AAErF,uBAAuC,UAAU,CAAC,CAAA;AAMlD;IAAgD,qCAA2B;IAA3E;QAAgD,8BAA2B;IAAG,CAAC;IAAD,wBAAC;AAAD,CAAC,AAA/E,CAAgD,6BAAiB,GAAc;AAAzD,yBAAiB,oBAAwC,CAAA;AAM/E;IAA4D,iDAAiB;IAA7E;QAA4D,8BAAiB;IA+D7E,CAAC;IAvCa,kDAAU,GAApB;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE;YACtB,GAAC,sBAAa,CAAC,KAAK,CAAC,GAAE,IAAI,CAAC,eAAe;YAC3C,GAAC,kBAAS,CAAC,KAAK,CAAC,GAAM,IAAI,CAAC,WAAW;;SAC1C,CAAC,CAAC;;IACP,CAAC;IASM,sDAAc,GAArB,UAAsB,QAAe;QACjC,IAAI,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAClF,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5E,CAAC;IAQS,uDAAe,GAAzB,UAA0B,KAAmB;QACzC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IACjC,CAAC;IAQS,mDAAW,GAArB,UAAsB,IAAc;QAChC,IAAI,CAAC,QAAQ,GAAK,IAAI,CAAC,GAAG,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,YAAY,6BAAqB,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtF,CAAC;IACL,oCAAC;AAAD,CAAC,AA/DD,CAA4D,iBAAiB,GA+D5E;AA/DqB,qCAA6B,gCA+DlD,CAAA","sourcesContent":["import * as Path from \"path\";\nimport * as ts from \"typescript\";\n\nimport {Component, AbstractComponent, ChildableComponent} from \"../utils/component\";\nimport {ProjectReflection, DeclarationReflection} from \"../models/reflections/index\";\nimport {Renderer} from \"./renderer\";\nimport {RendererEvent, PageEvent} from \"./events\";\n\n\nexport {Component};\n\n\nexport abstract class RendererComponent extends AbstractComponent { }\n\n\n/**\n * A plugin for the renderer that reads the current render context.\n */\nexport abstract class ContextAwareRendererComponent extends RendererComponent\n{\n /**\n * The project that is currently processed.\n */\n protected project:ProjectReflection;\n\n /**\n * The reflection that is currently processed.\n */\n protected reflection:DeclarationReflection;\n\n /**\n * The url of the document that is being currently generated.\n */\n private location:string;\n\n\n\n /**\n * Create a new ContextAwareRendererPlugin instance.\n *\n * @param renderer The renderer this plugin should be attached to.\n */\n protected initialize() {\n this.listenTo(this.owner, {\n [RendererEvent.BEGIN]: this.onBeginRenderer,\n [PageEvent.BEGIN]: this.onBeginPage\n });\n }\n\n\n /**\n * Transform the given absolute path into a relative path.\n *\n * @param absolute The absolute path to transform.\n * @returns A path relative to the document currently processed.\n */\n public getRelativeUrl(absolute:string):string {\n var relative = Path.relative(Path.dirname(this.location), Path.dirname(absolute));\n return Path.join(relative, Path.basename(absolute)).replace(/\\\\/g, '/');\n }\n\n\n /**\n * Triggered before the renderer starts rendering a project.\n *\n * @param event An event object describing the current render operation.\n */\n protected onBeginRenderer(event:RendererEvent) {\n this.project = event.project;\n }\n\n\n /**\n * Triggered before a document will be rendered.\n *\n * @param page An event object describing the current render operation.\n */\n protected onBeginPage(page:PageEvent) {\n this.location = page.url;\n this.reflection = page.model instanceof DeclarationReflection ? page.model : null;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/events.d.ts b/lib/output/events.d.ts new file mode 100644 index 000000000..6e2f64789 --- /dev/null +++ b/lib/output/events.d.ts @@ -0,0 +1,32 @@ +import { Event } from "../utils/events"; +import { ProjectReflection } from "../models/reflections/project"; +import { UrlMapping } from "./models/UrlMapping"; +import { NavigationItem } from "./models/NavigationItem"; +export declare class RendererEvent extends Event { + project: ProjectReflection; + settings: any; + outputDirectory: string; + urls: UrlMapping[]; + static BEGIN: string; + static END: string; + createPageEvent(mapping: UrlMapping): PageEvent; +} +export declare class PageEvent extends Event { + project: ProjectReflection; + settings: any; + filename: string; + url: string; + model: any; + template: HandlebarsTemplateDelegate; + templateName: string; + navigation: NavigationItem; + toc: NavigationItem; + contents: string; + static BEGIN: string; + static END: string; +} +export declare class MarkdownEvent extends Event { + originalText: string; + parsedText: string; + static PARSE: string; +} diff --git a/lib/output/events.js b/lib/output/events.js new file mode 100644 index 000000000..dafaf4013 --- /dev/null +++ b/lib/output/events.js @@ -0,0 +1,48 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var Path = require("path"); +var events_1 = require("../utils/events"); +var RendererEvent = (function (_super) { + __extends(RendererEvent, _super); + function RendererEvent() { + _super.apply(this, arguments); + } + RendererEvent.prototype.createPageEvent = function (mapping) { + var event = new PageEvent(PageEvent.BEGIN); + event.project = this.project; + event.settings = this.settings; + event.url = mapping.url; + event.model = mapping.model; + event.templateName = mapping.template; + event.filename = Path.join(this.outputDirectory, mapping.url); + return event; + }; + RendererEvent.BEGIN = 'beginRender'; + RendererEvent.END = 'endRender'; + return RendererEvent; +}(events_1.Event)); +exports.RendererEvent = RendererEvent; +var PageEvent = (function (_super) { + __extends(PageEvent, _super); + function PageEvent() { + _super.apply(this, arguments); + } + PageEvent.BEGIN = 'beginPage'; + PageEvent.END = 'endPage'; + return PageEvent; +}(events_1.Event)); +exports.PageEvent = PageEvent; +var MarkdownEvent = (function (_super) { + __extends(MarkdownEvent, _super); + function MarkdownEvent() { + _super.apply(this, arguments); + } + MarkdownEvent.PARSE = 'parseMarkdown'; + return MarkdownEvent; +}(events_1.Event)); +exports.MarkdownEvent = MarkdownEvent; +//# sourceMappingURL=events.js.map \ No newline at end of file diff --git a/lib/output/events.js.map b/lib/output/events.js.map new file mode 100644 index 000000000..3c2ceb154 --- /dev/null +++ b/lib/output/events.js.map @@ -0,0 +1 @@ +{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/lib/output/events.ts"],"names":[],"mappings":";;;;;;AAAA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAE7B,uBAAoB,iBAAiB,CAAC,CAAA;AAatC;IAAmC,iCAAK;IAAxC;QAAmC,8BAAK;IAuDxC,CAAC;IAVU,uCAAe,GAAtB,UAAuB,OAAkB;QACrC,IAAI,KAAK,GAAG,IAAI,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC3C,KAAK,CAAC,OAAO,GAAQ,IAAI,CAAC,OAAO,CAAC;QAClC,KAAK,CAAC,QAAQ,GAAO,IAAI,CAAC,QAAQ,CAAC;QACnC,KAAK,CAAC,GAAG,GAAY,OAAO,CAAC,GAAG,CAAC;QACjC,KAAK,CAAC,KAAK,GAAU,OAAO,CAAC,KAAK,CAAC;QACnC,KAAK,CAAC,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC;QACtC,KAAK,CAAC,QAAQ,GAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAClE,MAAM,CAAC,KAAK,CAAC;IACjB,CAAC;IA1BM,mBAAK,GAAU,aAAa,CAAC;IAM7B,iBAAG,GAAU,WAAW,CAAC;IAqBpC,oBAAC;AAAD,CAAC,AAvDD,CAAmC,cAAK,GAuDvC;AAvDY,qBAAa,gBAuDzB,CAAA;AAYD;IAA+B,6BAAK;IAApC;QAA+B,8BAAK;IAiEpC,CAAC;IAPU,eAAK,GAAU,WAAW,CAAC;IAM3B,aAAG,GAAU,SAAS,CAAC;IAClC,gBAAC;AAAD,CAAC,AAjED,CAA+B,cAAK,GAiEnC;AAjEY,iBAAS,YAiErB,CAAA;AASD;IAAmC,iCAAK;IAAxC;QAAmC,8BAAK;IAiBxC,CAAC;IADU,mBAAK,GAAU,eAAe,CAAC;IAC1C,oBAAC;AAAD,CAAC,AAjBD,CAAmC,cAAK,GAiBvC;AAjBY,qBAAa,gBAiBzB,CAAA","sourcesContent":["import * as Path from \"path\";\n\nimport {Event} from \"../utils/events\";\nimport {ProjectReflection} from \"../models/reflections/project\";\nimport {UrlMapping} from \"./models/UrlMapping\";\nimport {NavigationItem} from \"./models/NavigationItem\";\n\n\n/**\n * An event emitted by the [[Renderer]] class at the very beginning and\n * ending of the entire rendering process.\n *\n * @see [[Renderer.EVENT_BEGIN]]\n * @see [[Renderer.EVENT_END]]\n */\nexport class RendererEvent extends Event\n{\n /**\n * The project the renderer is currently processing.\n */\n project:ProjectReflection;\n\n /**\n * The settings that have been passed to TypeDoc.\n */\n settings:any;\n\n /**\n * The path of the directory the documentation should be written to.\n */\n outputDirectory:string;\n\n /**\n * A list of all pages that should be generated.\n *\n * This list can be altered during the [[Renderer.EVENT_BEGIN]] event.\n */\n urls:UrlMapping[];\n\n /**\n * Triggered before the renderer starts rendering a project.\n * @event\n */\n static BEGIN:string = 'beginRender';\n\n /**\n * Triggered after the renderer has written all documents.\n * @event\n */\n static END:string = 'endRender';\n\n\n\n /**\n * Create an [[PageEvent]] event based on this event and the given url mapping.\n *\n * @internal\n * @param mapping The mapping that defines the generated [[PageEvent]] state.\n * @returns A newly created [[PageEvent]] instance.\n */\n public createPageEvent(mapping:UrlMapping):PageEvent {\n var event = new PageEvent(PageEvent.BEGIN);\n event.project = this.project;\n event.settings = this.settings;\n event.url = mapping.url;\n event.model = mapping.model;\n event.templateName = mapping.template;\n event.filename = Path.join(this.outputDirectory, mapping.url);\n return event;\n }\n}\n\n\n/**\n * An event emitted by the [[Renderer]] class before and after the\n * markup of a page is rendered.\n *\n * This object will be passed as the rendering context to handlebars templates.\n *\n * @see [[Renderer.EVENT_BEGIN_PAGE]]\n * @see [[Renderer.EVENT_END_PAGE]]\n */\nexport class PageEvent extends Event\n{\n /**\n * The project the renderer is currently processing.\n */\n project:ProjectReflection;\n\n /**\n * The settings that have been passed to TypeDoc.\n */\n settings:any;\n\n /**\n * The filename the page will be written to.\n */\n filename:string;\n\n /**\n * The url this page will be located at.\n */\n url:string;\n\n /**\n * The model that should be rendered on this page.\n */\n model:any;\n\n /**\n * The template that should be used to render this page.\n */\n template:HandlebarsTemplateDelegate;\n\n /**\n * The name of the template that should be used to render this page.\n */\n templateName:string;\n\n /**\n * The primary navigation structure of this page.\n */\n navigation:NavigationItem;\n\n /**\n * The table of contents structure of this page.\n */\n toc:NavigationItem;\n\n /**\n * The final html content of this page.\n *\n * Should be rendered by layout templates and can be modifies by plugins.\n */\n contents:string;\n\n /**\n * Triggered before a document will be rendered.\n * @event\n */\n static BEGIN:string = 'beginPage';\n\n /**\n * Triggered after a document has been rendered, just before it is written to disc.\n * @event\n */\n static END:string = 'endPage';\n}\n\n\n/**\n * An event emitted by the [[MarkedPlugin]] on the [[Renderer]] after a chunk of\n * markdown has been processed. Allows other plugins to manipulate the result.\n *\n * @see [[MarkedPlugin.EVENT_PARSE_MARKDOWN]]\n */\nexport class MarkdownEvent extends Event\n{\n /**\n * The unparsed original text.\n */\n originalText:string;\n\n /**\n * The parsed output.\n */\n parsedText:string;\n\n /**\n * Triggered on the renderer when this plugin parses a markdown string.\n * @event\n */\n static PARSE:string = 'parseMarkdown';\n}\n"]} \ No newline at end of file diff --git a/lib/output/helpers/compact.d.ts b/lib/output/helpers/compact.d.ts new file mode 100644 index 000000000..851195f6d --- /dev/null +++ b/lib/output/helpers/compact.d.ts @@ -0,0 +1 @@ +export declare function compact(options: any): string; diff --git a/lib/output/helpers/compact.js b/lib/output/helpers/compact.js new file mode 100644 index 000000000..0e1488839 --- /dev/null +++ b/lib/output/helpers/compact.js @@ -0,0 +1,10 @@ +"use strict"; +function compact(options) { + var lines = options.fn(this).split('\n'); + for (var i = 0, c = lines.length; i < c; i++) { + lines[i] = lines[i].trim().replace(/ /, ' '); + } + return lines.join(''); +} +exports.compact = compact; +//# sourceMappingURL=compact.js.map \ No newline at end of file diff --git a/lib/output/helpers/compact.js.map b/lib/output/helpers/compact.js.map new file mode 100644 index 000000000..0182cdd4d --- /dev/null +++ b/lib/output/helpers/compact.js.map @@ -0,0 +1 @@ +{"version":3,"file":"compact.js","sourceRoot":"","sources":["../../../src/lib/output/helpers/compact.ts"],"names":[],"mappings":";AAMA,iBAAwB,OAAW;IAC/B,IAAI,KAAK,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAEzC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC;AARe,eAAO,UAQtB,CAAA","sourcesContent":["/**\n * Compress the given string by removing all newlines.\n *\n * @param text The string that should be compressed.\n * @returns The string with all newlines stripped.\n */\nexport function compact(options:any):string {\n var lines = options.fn(this).split('\\n');\n\n for (var i = 0, c = lines.length; i < c; i++) {\n lines[i] = lines[i].trim().replace(/ /, ' ');\n }\n\n return lines.join('');\n}\n"]} \ No newline at end of file diff --git a/lib/output/helpers/if-cond.d.ts b/lib/output/helpers/if-cond.d.ts new file mode 100644 index 000000000..152f2dc90 --- /dev/null +++ b/lib/output/helpers/if-cond.d.ts @@ -0,0 +1 @@ +export declare function ifCond(v1: any, operator: any, v2: any, options: any): any; diff --git a/lib/output/helpers/if-cond.js b/lib/output/helpers/if-cond.js new file mode 100644 index 000000000..103716b8e --- /dev/null +++ b/lib/output/helpers/if-cond.js @@ -0,0 +1,25 @@ +"use strict"; +function ifCond(v1, operator, v2, options) { + switch (operator) { + case '==': + return (v1 == v2) ? options.fn(this) : options.inverse(this); + case '===': + return (v1 === v2) ? options.fn(this) : options.inverse(this); + case '<': + return (v1 < v2) ? options.fn(this) : options.inverse(this); + case '<=': + return (v1 <= v2) ? options.fn(this) : options.inverse(this); + case '>': + return (v1 > v2) ? options.fn(this) : options.inverse(this); + case '>=': + return (v1 >= v2) ? options.fn(this) : options.inverse(this); + case '&&': + return (v1 && v2) ? options.fn(this) : options.inverse(this); + case '||': + return (v1 || v2) ? options.fn(this) : options.inverse(this); + default: + return options.inverse(this); + } +} +exports.ifCond = ifCond; +//# sourceMappingURL=if-cond.js.map \ No newline at end of file diff --git a/lib/output/helpers/if-cond.js.map b/lib/output/helpers/if-cond.js.map new file mode 100644 index 000000000..4f5f61d44 --- /dev/null +++ b/lib/output/helpers/if-cond.js.map @@ -0,0 +1 @@ +{"version":3,"file":"if-cond.js","sourceRoot":"","sources":["../../../src/lib/output/helpers/if-cond.ts"],"names":[],"mappings":";AAUA,gBAAuB,EAAM,EAAE,QAAY,EAAE,EAAM,EAAE,OAAW;IAC5D,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACf,KAAK,IAAI;YACL,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjE,KAAK,KAAK;YACN,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClE,KAAK,GAAG;YACJ,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChE,KAAK,IAAI;YACL,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjE,KAAK,GAAG;YACJ,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChE,KAAK,IAAI;YACL,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjE,KAAK,IAAI;YACL,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjE,KAAK,IAAI;YACL,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjE;YACI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;AACL,CAAC;AArBe,cAAM,SAqBrB,CAAA","sourcesContent":["/**\n * Handlebars if helper with condition.\n *\n * @param v1 The first value to be compared.\n * @param operator The operand to perform on the two given values.\n * @param v2 The second value to be compared\n * @param options The current handlebars object.\n * @param this The current handlebars this.\n * @returns {*}\n */\nexport function ifCond(v1:any, operator:any, v2:any, options:any) {\n switch (operator) {\n case '==':\n return (v1 == v2) ? options.fn(this) : options.inverse(this);\n case '===':\n return (v1 === v2) ? options.fn(this) : options.inverse(this);\n case '<':\n return (v1 < v2) ? options.fn(this) : options.inverse(this);\n case '<=':\n return (v1 <= v2) ? options.fn(this) : options.inverse(this);\n case '>':\n return (v1 > v2) ? options.fn(this) : options.inverse(this);\n case '>=':\n return (v1 >= v2) ? options.fn(this) : options.inverse(this);\n case '&&':\n return (v1 && v2) ? options.fn(this) : options.inverse(this);\n case '||':\n return (v1 || v2) ? options.fn(this) : options.inverse(this);\n default:\n return options.inverse(this);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/helpers/if-signature.d.ts b/lib/output/helpers/if-signature.d.ts new file mode 100644 index 000000000..afe1a5e80 --- /dev/null +++ b/lib/output/helpers/if-signature.d.ts @@ -0,0 +1 @@ +export declare function ifSignature(obj: any, arg: any): any; diff --git a/lib/output/helpers/if-signature.js b/lib/output/helpers/if-signature.js new file mode 100644 index 000000000..f98935f69 --- /dev/null +++ b/lib/output/helpers/if-signature.js @@ -0,0 +1,12 @@ +"use strict"; +var signature_1 = require("../../models/reflections/signature"); +function ifSignature(obj, arg) { + if (obj instanceof signature_1.SignatureReflection) { + return arg.fn(this); + } + else { + return arg.inverse(this); + } +} +exports.ifSignature = ifSignature; +//# sourceMappingURL=if-signature.js.map \ No newline at end of file diff --git a/lib/output/helpers/if-signature.js.map b/lib/output/helpers/if-signature.js.map new file mode 100644 index 000000000..0f221e840 --- /dev/null +++ b/lib/output/helpers/if-signature.js.map @@ -0,0 +1 @@ +{"version":3,"file":"if-signature.js","sourceRoot":"","sources":["../../../src/lib/output/helpers/if-signature.ts"],"names":[],"mappings":";AAAA,0BAAkC,oCAAoC,CAAC,CAAA;AAGvE,qBAA4B,GAAO,EAAE,GAAO;IACxC,EAAE,CAAC,CAAC,GAAG,YAAY,+BAAmB,CAAC,CAAC,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAAC,IAAI,CAAC,CAAC;QACJ,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACL,CAAC;AANe,mBAAW,cAM1B,CAAA","sourcesContent":["import {SignatureReflection} from \"../../models/reflections/signature\";\n\n\nexport function ifSignature(obj:any, arg:any) {\n if (obj instanceof SignatureReflection) {\n return arg.fn(this);\n } else {\n return arg.inverse(this);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/helpers/wbr.d.ts b/lib/output/helpers/wbr.d.ts new file mode 100644 index 000000000..717dbaed1 --- /dev/null +++ b/lib/output/helpers/wbr.d.ts @@ -0,0 +1 @@ +export declare function wbr(options: any): string; diff --git a/lib/output/helpers/wbr.js b/lib/output/helpers/wbr.js new file mode 100644 index 000000000..58906e00b --- /dev/null +++ b/lib/output/helpers/wbr.js @@ -0,0 +1,9 @@ +"use strict"; +function wbr(options) { + var str = typeof options == 'string' ? options : options.fn(this); + str = str.replace(/([^_\-][_\-])([^_\-])/g, function (m, a, b) { return a + '' + b; }); + str = str.replace(/([^A-Z])([A-Z][^A-Z])/g, function (m, a, b) { return a + '' + b; }); + return str; +} +exports.wbr = wbr; +//# sourceMappingURL=wbr.js.map \ No newline at end of file diff --git a/lib/output/helpers/wbr.js.map b/lib/output/helpers/wbr.js.map new file mode 100644 index 000000000..67397c69d --- /dev/null +++ b/lib/output/helpers/wbr.js.map @@ -0,0 +1 @@ +{"version":3,"file":"wbr.js","sourceRoot":"","sources":["../../../src/lib/output/helpers/wbr.ts"],"names":[],"mappings":";AAQA,aAAoB,OAAW;IAC3B,IAAI,GAAG,GAAG,OAAO,OAAO,IAAI,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAElE,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,wBAAwB,EAAE,UAAC,CAAQ,EAAE,CAAQ,EAAE,CAAQ,IAAK,OAAA,CAAC,GAAG,OAAO,GAAG,CAAC,EAAf,CAAe,CAAC,CAAC;IAC/F,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,wBAAwB,EAAE,UAAC,CAAQ,EAAE,CAAQ,EAAE,CAAQ,IAAK,OAAA,CAAC,GAAG,OAAO,GAAG,CAAC,EAAf,CAAe,CAAC,CAAC;IAE/F,MAAM,CAAC,GAAG,CAAC;AACf,CAAC;AAPe,WAAG,MAOlB,CAAA","sourcesContent":["/**\n * Insert word break tags ```` into the given string.\n *\n * Breaks the given string at ``_``, ``-`` and captial letters.\n *\n * @param str The string that should be split.\n * @return The original string containing ```` tags where possible.\n */\nexport function wbr(options:any):string {\n var str = typeof options == 'string' ? options : options.fn(this);\n\n str = str.replace(/([^_\\-][_\\-])([^_\\-])/g, (m:string, a:string, b:string) => a + '' + b);\n str = str.replace(/([^A-Z])([A-Z][^A-Z])/g, (m:string, a:string, b:string) => a + '' + b);\n\n return str;\n}\n"]} \ No newline at end of file diff --git a/lib/output/models/NavigationItem.d.ts b/lib/output/models/NavigationItem.d.ts new file mode 100644 index 000000000..e6cf52e49 --- /dev/null +++ b/lib/output/models/NavigationItem.d.ts @@ -0,0 +1,16 @@ +import { Reflection } from "../../models/reflections/abstract"; +export declare class NavigationItem { + title: string; + url: string; + dedicatedUrls: string[]; + parent: NavigationItem; + children: NavigationItem[]; + cssClasses: string; + isLabel: boolean; + isVisible: boolean; + isCurrent: boolean; + isGlobals: boolean; + isInPath: boolean; + constructor(title?: string, url?: string, parent?: NavigationItem, cssClasses?: string); + static create(reflection: Reflection, parent?: NavigationItem, useShortNames?: boolean): NavigationItem; +} diff --git a/lib/output/models/NavigationItem.js b/lib/output/models/NavigationItem.js new file mode 100644 index 000000000..38c89c7d6 --- /dev/null +++ b/lib/output/models/NavigationItem.js @@ -0,0 +1,34 @@ +"use strict"; +var NavigationItem = (function () { + function NavigationItem(title, url, parent, cssClasses) { + this.title = title || ''; + this.url = url || ''; + this.parent = parent || null; + this.cssClasses = cssClasses || ''; + if (!url) { + this.isLabel = true; + } + if (this.parent) { + if (!this.parent.children) + this.parent.children = []; + this.parent.children.push(this); + } + } + NavigationItem.create = function (reflection, parent, useShortNames) { + var name; + if (useShortNames || (parent && parent.parent)) { + name = reflection.name; + } + else { + name = reflection.getFullName(); + } + name = name.trim(); + if (name == '') { + name = '' + reflection.kindString + ''; + } + return new NavigationItem(name, reflection.url, parent, reflection.cssClasses); + }; + return NavigationItem; +}()); +exports.NavigationItem = NavigationItem; +//# sourceMappingURL=NavigationItem.js.map \ No newline at end of file diff --git a/lib/output/models/NavigationItem.js.map b/lib/output/models/NavigationItem.js.map new file mode 100644 index 000000000..b84c383ce --- /dev/null +++ b/lib/output/models/NavigationItem.js.map @@ -0,0 +1 @@ +{"version":3,"file":"NavigationItem.js","sourceRoot":"","sources":["../../../src/lib/output/models/NavigationItem.ts"],"names":[],"mappings":";AAUA;IAmEI,wBAAY,KAAa,EAAE,GAAW,EAAE,MAAs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AC,CAAC;IACnF,CAAC;IACL,qBAAC;AAAD,CAAC,AA1GD,IA0GC;AA1GY,sBAAc,iBA0G1B,CAAA","sourcesContent":["import {Reflection} from \"../../models/reflections/abstract\";\n\n\n/**\n * A hierarchical model holding the data of single node within the navigation.\n *\n * This structure is used by the [[NavigationPlugin]] and [[TocPlugin]] to expose the current\n * navigation state to the template engine. Themes should generate the primary navigation structure\n * through the [[BaseTheme.getNavigation]] method.\n */\nexport class NavigationItem\n{\n /**\n * The visible title of the navigation node.\n */\n title:string;\n\n /**\n * The url this navigation node points to.\n */\n url:string;\n\n /**\n * A list of urls that should be seen as sub-pages of this node.\n */\n dedicatedUrls:string[];\n\n /**\n * The parent navigation node.\n */\n parent:NavigationItem;\n\n /**\n * An array containing all child navigation nodes.\n */\n children:NavigationItem[];\n\n /**\n * A string containing the css classes of this node.\n */\n cssClasses:string;\n\n /**\n * Is this item a simple label without a link?\n */\n isLabel:boolean;\n\n /**\n * Is this item visible?\n */\n isVisible:boolean;\n\n /**\n * Does this navigation node represent the current page?\n */\n isCurrent:boolean;\n\n /**\n * Is this the navigation node for the globals page?\n */\n isGlobals:boolean;\n\n /**\n * Is this navigation node one of the parents of the current page?\n */\n isInPath:boolean;\n\n\n\n /**\n * Create a new NavigationItem instance.\n *\n * @param title The visible title of the navigation node.\n * @param url The url this navigation node points to.\n * @param parent The parent navigation node.\n * @param cssClasses A string containing the css classes of this node.\n */\n constructor(title?:string, url?:string, parent?:NavigationItem, cssClasses?:string) {\n this.title = title || '';\n this.url = url || '';\n this.parent = parent || null;\n this.cssClasses = cssClasses || '';\n\n if (!url) {\n this.isLabel = true;\n }\n\n if (this.parent) {\n if (!this.parent.children) this.parent.children = [];\n this.parent.children.push(this);\n }\n }\n\n\n /**\n * Create a navigation node for the given reflection.\n *\n * @param reflection The reflection whose navigation node should be created.\n * @param parent The parent navigation node.\n * @param useShortNames Force this function to always use short names.\n */\n static create(reflection:Reflection, parent?:NavigationItem, useShortNames?:boolean) {\n var name:string;\n if (useShortNames || (parent && parent.parent)) {\n name = reflection.name;\n } else {\n name = reflection.getFullName();\n }\n\n name = name.trim();\n if (name == '') {\n name = '' + reflection.kindString + '';\n }\n\n return new NavigationItem(name, reflection.url, parent, reflection.cssClasses);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/models/UrlMapping.d.ts b/lib/output/models/UrlMapping.d.ts new file mode 100644 index 000000000..b94356f7e --- /dev/null +++ b/lib/output/models/UrlMapping.d.ts @@ -0,0 +1,6 @@ +export declare class UrlMapping { + url: string; + model: any; + template: string; + constructor(url: string, model: any, template: string); +} diff --git a/lib/output/models/UrlMapping.js b/lib/output/models/UrlMapping.js new file mode 100644 index 000000000..321e70647 --- /dev/null +++ b/lib/output/models/UrlMapping.js @@ -0,0 +1,11 @@ +"use strict"; +var UrlMapping = (function () { + function UrlMapping(url, model, template) { + this.url = url; + this.model = model; + this.template = template; + } + return UrlMapping; +}()); +exports.UrlMapping = UrlMapping; +//# sourceMappingURL=UrlMapping.js.map \ No newline at end of file diff --git a/lib/output/models/UrlMapping.js.map b/lib/output/models/UrlMapping.js.map new file mode 100644 index 000000000..88e5ac7ab --- /dev/null +++ b/lib/output/models/UrlMapping.js.map @@ -0,0 +1 @@ +{"version":3,"file":"UrlMapping.js","sourceRoot":"","sources":["../../../src/lib/output/models/UrlMapping.ts"],"names":[],"mappings":";AAGA;IASI,oBAAY,GAAU,EAAE,KAAS,EAAE,QAAe;QAC9C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;IACL,iBAAC;AAAD,CAAC,AAdD,IAcC;AAdY,kBAAU,aActB,CAAA","sourcesContent":["/**\n *\n */\nexport class UrlMapping\n{\n url:string;\n\n model:any;\n\n template:string;\n\n\n constructor(url:string, model:any, template:string) {\n this.url = url;\n this.model = model;\n this.template = template;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/plugins/AssetsPlugin.d.ts b/lib/output/plugins/AssetsPlugin.d.ts new file mode 100644 index 000000000..57703b9c6 --- /dev/null +++ b/lib/output/plugins/AssetsPlugin.d.ts @@ -0,0 +1,6 @@ +import { RendererComponent } from "../components"; +export declare class AssetsPlugin extends RendererComponent { + copyDefaultAssets: boolean; + initialize(): void; + private onRendererBegin(event); +} diff --git a/lib/output/plugins/AssetsPlugin.js b/lib/output/plugins/AssetsPlugin.js new file mode 100644 index 000000000..3b27f477f --- /dev/null +++ b/lib/output/plugins/AssetsPlugin.js @@ -0,0 +1,51 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var Path = require("path"); +var FS = require("fs-extra"); +var components_1 = require("../components"); +var events_1 = require("../events"); +var renderer_1 = require("../renderer"); +var AssetsPlugin = (function (_super) { + __extends(AssetsPlugin, _super); + function AssetsPlugin() { + _super.apply(this, arguments); + this.copyDefaultAssets = true; + } + AssetsPlugin.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[events_1.RendererEvent.BEGIN] = this.onRendererBegin, + _a + )); + var _a; + }; + AssetsPlugin.prototype.onRendererBegin = function (event) { + var fromDefault = Path.join(renderer_1.Renderer.getDefaultTheme(), 'assets'); + var to = Path.join(event.outputDirectory, 'assets'); + if (this.copyDefaultAssets) { + FS.copySync(fromDefault, to); + } + else { + fromDefault = null; + } + var from = Path.join(this.owner.theme.basePath, 'assets'); + if (from != fromDefault && FS.existsSync(from)) { + FS.copySync(from, to); + } + }; + AssetsPlugin = __decorate([ + components_1.Component({ name: "assets" }) + ], AssetsPlugin); + return AssetsPlugin; +}(components_1.RendererComponent)); +exports.AssetsPlugin = AssetsPlugin; +//# sourceMappingURL=AssetsPlugin.js.map \ No newline at end of file diff --git a/lib/output/plugins/AssetsPlugin.js.map b/lib/output/plugins/AssetsPlugin.js.map new file mode 100644 index 000000000..0aa246d09 --- /dev/null +++ b/lib/output/plugins/AssetsPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"AssetsPlugin.js","sourceRoot":"","sources":["../../../src/lib/output/plugins/AssetsPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAC7B,IAAY,EAAE,WAAM,UAAU,CAAC,CAAA;AAE/B,2BAA2C,eAAe,CAAC,CAAA;AAC3D,uBAA4B,WAAW,CAAC,CAAA;AACxC,yBAAuB,aAAa,CAAC,CAAA;AAQrC;IAAkC,gCAAiB;IAAnD;QAAkC,8BAAiB;QAK/C,sBAAiB,GAAW,IAAI,CAAC;IAiCrC,CAAC;IA3BG,iCAAU,GAAV;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE;YACtB,GAAC,sBAAa,CAAC,KAAK,CAAC,GAAE,IAAI,CAAC,eAAe;;SAC9C,CAAC,CAAC;;IACP,CAAC;IAQO,sCAAe,GAAvB,UAAwB,KAAmB;QACvC,IAAI,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,mBAAQ,CAAC,eAAe,EAAE,EAAE,QAAQ,CAAC,CAAC;QAClE,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;QAEpD,EAAE,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;YACzB,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACjC,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,WAAW,GAAG,IAAI,CAAC;QACvB,CAAC;QAED,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC1D,EAAE,CAAC,CAAC,IAAI,IAAI,WAAW,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC7C,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;IAtCL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,CAAC;oBAAA;IAuC3B,mBAAC;AAAD,CAAC,AAtCD,CAAkC,8BAAiB,GAsClD;AAtCY,oBAAY,eAsCxB,CAAA","sourcesContent":["import * as Path from \"path\";\nimport * as FS from \"fs-extra\";\n\nimport {Component, RendererComponent} from \"../components\";\nimport {RendererEvent} from \"../events\";\nimport {Renderer} from \"../renderer\";\n\n\n/**\n * A plugin that copies the subdirectory ´assets´ from the current themes\n * source folder to the output directory.\n */\n@Component({name:\"assets\"})\nexport class AssetsPlugin extends RendererComponent\n{\n /**\n * Should the default assets always be copied to the output directory?\n */\n copyDefaultAssets:boolean = true;\n\n\n /**\n * Create a new AssetsPlugin instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [RendererEvent.BEGIN]: this.onRendererBegin\n });\n }\n\n\n /**\n * Triggered before the renderer starts rendering a project.\n *\n * @param event An event object describing the current render operation.\n */\n private onRendererBegin(event:RendererEvent) {\n var fromDefault = Path.join(Renderer.getDefaultTheme(), 'assets');\n var to = Path.join(event.outputDirectory, 'assets');\n\n if (this.copyDefaultAssets) {\n FS.copySync(fromDefault, to);\n } else {\n fromDefault = null;\n }\n\n var from = Path.join(this.owner.theme.basePath, 'assets');\n if (from != fromDefault && FS.existsSync(from)) {\n FS.copySync(from, to);\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/plugins/JavascriptIndexPlugin.d.ts b/lib/output/plugins/JavascriptIndexPlugin.d.ts new file mode 100644 index 000000000..8088ebd44 --- /dev/null +++ b/lib/output/plugins/JavascriptIndexPlugin.d.ts @@ -0,0 +1,5 @@ +import { RendererComponent } from "../components"; +export declare class JavascriptIndexPlugin extends RendererComponent { + initialize(): void; + private onRendererBegin(event); +} diff --git a/lib/output/plugins/JavascriptIndexPlugin.js b/lib/output/plugins/JavascriptIndexPlugin.js new file mode 100644 index 000000000..5ffc9459e --- /dev/null +++ b/lib/output/plugins/JavascriptIndexPlugin.js @@ -0,0 +1,70 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var Path = require("path"); +var index_1 = require("../../models/reflections/index"); +var GroupPlugin_1 = require("../../converter/plugins/GroupPlugin"); +var components_1 = require("../components"); +var fs_1 = require("../../utils/fs"); +var events_1 = require("../events"); +var JavascriptIndexPlugin = (function (_super) { + __extends(JavascriptIndexPlugin, _super); + function JavascriptIndexPlugin() { + _super.apply(this, arguments); + } + JavascriptIndexPlugin.prototype.initialize = function () { + this.listenTo(this.owner, events_1.RendererEvent.BEGIN, this.onRendererBegin); + }; + JavascriptIndexPlugin.prototype.onRendererBegin = function (event) { + var rows = []; + var kinds = {}; + for (var key in event.project.reflections) { + var reflection = event.project.reflections[key]; + if (!(reflection instanceof index_1.DeclarationReflection)) + continue; + if (!reflection.url || + !reflection.name || + reflection.flags.isExternal || + reflection.name == '') + continue; + var parent = reflection.parent; + if (parent instanceof index_1.ProjectReflection) { + parent = null; + } + var row = { + id: rows.length, + kind: reflection.kind, + name: reflection.name, + url: reflection.url, + classes: reflection.cssClasses + }; + if (parent) { + row.parent = parent.getFullName(); + } + if (!kinds[reflection.kind]) { + kinds[reflection.kind] = GroupPlugin_1.GroupPlugin.getKindSingular(reflection.kind); + } + rows.push(row); + } + var fileName = Path.join(event.outputDirectory, 'assets', 'js', 'search.js'); + var data = 'var typedoc = typedoc || {};' + + 'typedoc.search = typedoc.search || {};' + + 'typedoc.search.data = ' + JSON.stringify({ kinds: kinds, rows: rows }) + ';'; + fs_1.writeFile(fileName, data, true); + }; + JavascriptIndexPlugin = __decorate([ + components_1.Component({ name: "javascript-index" }) + ], JavascriptIndexPlugin); + return JavascriptIndexPlugin; +}(components_1.RendererComponent)); +exports.JavascriptIndexPlugin = JavascriptIndexPlugin; +//# sourceMappingURL=JavascriptIndexPlugin.js.map \ No newline at end of file diff --git a/lib/output/plugins/JavascriptIndexPlugin.js.map b/lib/output/plugins/JavascriptIndexPlugin.js.map new file mode 100644 index 000000000..e23921815 --- /dev/null +++ b/lib/output/plugins/JavascriptIndexPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"JavascriptIndexPlugin.js","sourceRoot":"","sources":["../../../src/lib/output/plugins/JavascriptIndexPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAE7B,sBAAuD,gCAAgC,CAAC,CAAA;AACxF,4BAA0B,qCAAqC,CAAC,CAAA;AAChE,2BAA2C,eAAe,CAAC,CAAA;AAC3D,mBAAwB,gBAAgB,CAAC,CAAA;AACzC,uBAA4B,W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AAW,EAAE,CAAC;YACtC,CAAC;YAED,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAC1B,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,yBAAW,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAC1E,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QAED,IAAI,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAC7E,IAAI,IAAI,GACJ,8BAA8B;YAC9B,wCAAwC;YACxC,wBAAwB,GAAG,IAAI,CAAC,SAAS,CAAC,EAAC,KAAK,EAAC,KAAK,EAAE,IAAI,EAAC,IAAI,EAAC,CAAC,GAAG,GAAG,CAAC;QAE9E,cAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IA7DL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,kBAAkB,EAAC,CAAC;6BAAA;IA8DrC,4BAAC;AAAD,CAAC,AA7DD,CAA2C,8BAAiB,GA6D3D;AA7DY,6BAAqB,wBA6DjC,CAAA","sourcesContent":["import * as Path from \"path\";\n\nimport {DeclarationReflection, ProjectReflection} from \"../../models/reflections/index\";\nimport {GroupPlugin} from \"../../converter/plugins/GroupPlugin\";\nimport {Component, RendererComponent} from \"../components\";\nimport {writeFile} from \"../../utils/fs\";\nimport {RendererEvent} from \"../events\";\n\n\n/**\n * A plugin that exports an index of the project to a javascript file.\n *\n * The resulting javascript file can be used to build a simple search function.\n */\n@Component({name:\"javascript-index\"})\nexport class JavascriptIndexPlugin extends RendererComponent\n{\n /**\n * Create a new JavascriptIndexPlugin instance.\n */\n initialize() {\n this.listenTo(this.owner, RendererEvent.BEGIN, this.onRendererBegin);\n }\n\n\n /**\n * Triggered after a document has been rendered, just before it is written to disc.\n *\n * @param event An event object describing the current render operation.\n */\n private onRendererBegin(event:RendererEvent) {\n var rows:any[] = [];\n var kinds = {};\n\n for (var key in event.project.reflections) {\n var reflection:DeclarationReflection = event.project.reflections[key];\n if (!(reflection instanceof DeclarationReflection)) continue;\n\n if (!reflection.url ||\n !reflection.name ||\n reflection.flags.isExternal ||\n reflection.name == '')\n continue;\n\n var parent = reflection.parent;\n if (parent instanceof ProjectReflection) {\n parent = null;\n }\n\n var row:any = {\n id: rows.length,\n kind: reflection.kind,\n name: reflection.name,\n url: reflection.url,\n classes: reflection.cssClasses\n };\n\n if (parent) {\n row.parent = parent.getFullName();\n }\n\n if (!kinds[reflection.kind]) {\n kinds[reflection.kind] = GroupPlugin.getKindSingular(reflection.kind);\n }\n\n rows.push(row);\n }\n\n var fileName = Path.join(event.outputDirectory, 'assets', 'js', 'search.js');\n var data =\n 'var typedoc = typedoc || {};' +\n 'typedoc.search = typedoc.search || {};' +\n 'typedoc.search.data = ' + JSON.stringify({kinds:kinds, rows:rows}) + ';';\n\n writeFile(fileName, data, true);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/plugins/LayoutPlugin.d.ts b/lib/output/plugins/LayoutPlugin.d.ts new file mode 100644 index 000000000..c2c3070e5 --- /dev/null +++ b/lib/output/plugins/LayoutPlugin.d.ts @@ -0,0 +1,5 @@ +import { RendererComponent } from "../components"; +export declare class LayoutPlugin extends RendererComponent { + initialize(): void; + private onRendererEndPage(page); +} diff --git a/lib/output/plugins/LayoutPlugin.js b/lib/output/plugins/LayoutPlugin.js new file mode 100644 index 000000000..85c3d5c44 --- /dev/null +++ b/lib/output/plugins/LayoutPlugin.js @@ -0,0 +1,33 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var components_1 = require("../components"); +var events_1 = require("../events"); +var LayoutPlugin = (function (_super) { + __extends(LayoutPlugin, _super); + function LayoutPlugin() { + _super.apply(this, arguments); + } + LayoutPlugin.prototype.initialize = function () { + this.listenTo(this.owner, events_1.PageEvent.END, this.onRendererEndPage); + }; + LayoutPlugin.prototype.onRendererEndPage = function (page) { + var layout = this.owner.theme.resources.layouts.getResource('default').getTemplate(); + page.contents = layout(page); + }; + LayoutPlugin = __decorate([ + components_1.Component({ name: "layout" }) + ], LayoutPlugin); + return LayoutPlugin; +}(components_1.RendererComponent)); +exports.LayoutPlugin = LayoutPlugin; +//# sourceMappingURL=LayoutPlugin.js.map \ No newline at end of file diff --git a/lib/output/plugins/LayoutPlugin.js.map b/lib/output/plugins/LayoutPlugin.js.map new file mode 100644 index 000000000..292d538db --- /dev/null +++ b/lib/output/plugins/LayoutPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"LayoutPlugin.js","sourceRoot":"","sources":["../../../src/lib/output/plugins/LayoutPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2BAA2C,eAAe,CAAC,CAAA;AAC3D,uBAAwB,WAAW,CAAC,CAAA;AAUpC;IAAkC,gCAAiB;IAAnD;QAAkC,8BAAiB;IAmBnD,CAAC;IAdG,iCAAU,GAAV;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,kBAAS,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACrE,CAAC;IAQO,wCAAiB,GAAzB,UAA0B,IAAc;QACpC,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QACrF,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAnBL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,CAAC;oBAAA;IAoB3B,mBAAC;AAAD,CAAC,AAnBD,CAAkC,8BAAiB,GAmBlD;AAnBY,oBAAY,eAmBxB,CAAA","sourcesContent":["import {Component, RendererComponent} from \"../components\";\nimport {PageEvent} from \"../events\";\n\n\n/**\n * A plugin that wraps the generated output with a layout template.\n *\n * Currently only a default layout is supported. The layout must be stored\n * as ´layouts/default.hbs´ in the theme directory.\n */\n@Component({name:\"layout\"})\nexport class LayoutPlugin extends RendererComponent\n{\n /**\n * Create a new LayoutPlugin instance.\n */\n initialize() {\n this.listenTo(this.owner, PageEvent.END, this.onRendererEndPage);\n }\n\n\n /**\n * Triggered after a document has been rendered, just before it is written to disc.\n *\n * @param page An event object describing the current render operation.\n */\n private onRendererEndPage(page:PageEvent) {\n var layout = this.owner.theme.resources.layouts.getResource('default').getTemplate();\n page.contents = layout(page);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/plugins/MarkedLinksPlugin.d.ts b/lib/output/plugins/MarkedLinksPlugin.d.ts new file mode 100644 index 000000000..ca6b1647d --- /dev/null +++ b/lib/output/plugins/MarkedLinksPlugin.d.ts @@ -0,0 +1,16 @@ +import { ContextAwareRendererComponent } from "../components"; +import { MarkdownEvent } from "../events"; +export declare class MarkedLinksPlugin extends ContextAwareRendererComponent { + private brackets; + private inlineTag; + private urlPrefix; + initialize(): void; + private replaceBrackets(text); + private replaceInlineTags(text); + private buildLink(original, target, caption, monospace?); + onParseMarkdown(event: MarkdownEvent): void; + static splitLinkText(text: string): { + caption: string; + target: string; + }; +} diff --git a/lib/output/plugins/MarkedLinksPlugin.js b/lib/output/plugins/MarkedLinksPlugin.js new file mode 100644 index 000000000..336bfd16a --- /dev/null +++ b/lib/output/plugins/MarkedLinksPlugin.js @@ -0,0 +1,101 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var Util = require("util"); +var components_1 = require("../components"); +var events_1 = require("../events"); +var MarkedLinksPlugin = (function (_super) { + __extends(MarkedLinksPlugin, _super); + function MarkedLinksPlugin() { + _super.apply(this, arguments); + this.brackets = /\[\[([^\]]+)\]\]/g; + this.inlineTag = /(?:\[(.+?)\])?\{@(link|linkcode|linkplain)\s+((?:.|\n)+?)\}/gi; + this.urlPrefix = /^(http|ftp)s?:\/\//; + } + MarkedLinksPlugin.prototype.initialize = function () { + _super.prototype.initialize.call(this); + this.listenTo(this.owner, events_1.MarkdownEvent.PARSE, this.onParseMarkdown, 100); + }; + MarkedLinksPlugin.prototype.replaceBrackets = function (text) { + var _this = this; + return text.replace(this.brackets, function (match, content) { + var split = MarkedLinksPlugin.splitLinkText(content); + return _this.buildLink(match, split.target, split.caption); + }); + }; + MarkedLinksPlugin.prototype.replaceInlineTags = function (text) { + var _this = this; + return text.replace(this.inlineTag, function (match, leading, tagName, content) { + var split = MarkedLinksPlugin.splitLinkText(content); + var target = split.target; + var caption = leading || split.caption; + var monospace; + if (tagName == 'linkcode') + monospace = true; + if (tagName == 'linkplain') + monospace = false; + return _this.buildLink(match, target, caption, monospace); + }); + }; + MarkedLinksPlugin.prototype.buildLink = function (original, target, caption, monospace) { + var attributes = ''; + if (this.urlPrefix.test(target)) { + attributes = ' class="external"'; + } + else { + var reflection; + if (this.reflection) { + reflection = this.reflection.findReflectionByName(target); + } + else if (this.project) { + reflection = this.project.findReflectionByName(target); + } + if (reflection && reflection.url) { + target = this.getRelativeUrl(reflection.url); + } + else { + return original; + } + } + if (monospace) { + caption = '' + caption + ''; + } + return Util.format('%s', target, attributes, caption); + }; + MarkedLinksPlugin.prototype.onParseMarkdown = function (event) { + event.parsedText = this.replaceInlineTags(this.replaceBrackets(event.parsedText)); + }; + MarkedLinksPlugin.splitLinkText = function (text) { + var splitIndex = text.indexOf('|'); + if (splitIndex === -1) { + splitIndex = text.search(/\s/); + } + if (splitIndex !== -1) { + return { + caption: text.substr(splitIndex + 1).replace(/\n+/, ' '), + target: text.substr(0, splitIndex) + }; + } + else { + return { + caption: text, + target: text + }; + } + }; + MarkedLinksPlugin = __decorate([ + components_1.Component({ name: "marked-links" }) + ], MarkedLinksPlugin); + return MarkedLinksPlugin; +}(components_1.ContextAwareRendererComponent)); +exports.MarkedLinksPlugin = MarkedLinksPlugin; +//# sourceMappingURL=MarkedLinksPlugin.js.map \ No newline at end of file diff --git a/lib/output/plugins/MarkedLinksPlugin.js.map b/lib/output/plugins/MarkedLinksPlugin.js.map new file mode 100644 index 000000000..9eb125ed9 --- /dev/null +++ b/lib/output/plugins/MarkedLinksPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"MarkedLinksPlugin.js","sourceRoot":"","sources":["../../../src/lib/output/plugins/MarkedLinksPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAG7B,2BAAuD,eAAe,CAAC,CAAA;AACvE,uBAA4B,WAAW,CAAC,CAAA;AAOxC;IAAuC,qCAA6B;IAApE;QA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AG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;IACtF,CAAC;IASM,+BAAa,GAApB,UAAqB,IAAW;QAC5B,IAAI,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACnC,EAAE,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACpB,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;QAED,EAAE,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACpB,MAAM,CAAC;gBACH,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;gBACxD,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC;aACrC,CAAC;QACN,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,MAAM,CAAC;gBACH,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,IAAI;aACf,CAAC;QACN,CAAC;IACL,CAAC;IA1IL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,cAAc,EAAC,CAAC;yBAAA;IA2IjC,wBAAC;AAAD,CAAC,AA1ID,CAAuC,0CAA6B,GA0InE;AA1IY,yBAAiB,oBA0I7B,CAAA","sourcesContent":["import * as Util from \"util\";\n\nimport {Reflection} from \"../../models/reflections/abstract\";\nimport {Component, ContextAwareRendererComponent} from \"../components\";\nimport {MarkdownEvent} from \"../events\";\n\n\n/**\n * A plugin that builds links in markdown texts.\n */\n@Component({name:\"marked-links\"})\nexport class MarkedLinksPlugin extends ContextAwareRendererComponent\n{\n /**\n * Regular expression for detecting bracket links.\n */\n private brackets:RegExp = /\\[\\[([^\\]]+)\\]\\]/g;\n\n /**\n * Regular expression for detecting inline tags like {@link ...}.\n */\n private inlineTag:RegExp = /(?:\\[(.+?)\\])?\\{@(link|linkcode|linkplain)\\s+((?:.|\\n)+?)\\}/gi;\n\n /**\n * Regular expression to test if a string looks like an external url.\n */\n private urlPrefix:RegExp = /^(http|ftp)s?:\\/\\//;\n\n\n\n /**\n * Create a new MarkedLinksPlugin instance.\n */\n initialize() {\n super.initialize();\n this.listenTo(this.owner, MarkdownEvent.PARSE, this.onParseMarkdown, 100);\n }\n\n\n /**\n * Find all references to symbols within the given text and transform them into a link.\n *\n * This function is aware of the current context and will try to find the symbol within the\n * current reflection. It will walk up the reflection chain till the symbol is found or the\n * root reflection is reached. As a last resort the function will search the entire project\n * for the given symbol.\n *\n * @param text The text that should be parsed.\n * @returns The text with symbol references replaced by links.\n */\n private replaceBrackets(text:string):string {\n return text.replace(this.brackets, (match:string, content:string):string => {\n var split = MarkedLinksPlugin.splitLinkText(content);\n return this.buildLink(match, split.target, split.caption);\n });\n }\n\n\n /**\n * Find symbol {@link ...} strings in text and turn into html links\n *\n * @param text The string in which to replace the inline tags.\n * @return The updated string.\n */\n private replaceInlineTags(text:string):string {\n return text.replace(this.inlineTag, (match:string, leading:string, tagName:string, content:string):string => {\n var split = MarkedLinksPlugin.splitLinkText(content);\n var target = split.target;\n var caption = leading || split.caption;\n\n var monospace:boolean;\n if (tagName == 'linkcode') monospace = true;\n if (tagName == 'linkplain') monospace = false;\n\n return this.buildLink(match, target, caption, monospace);\n });\n }\n\n\n /**\n * Format a link with the given text and target.\n *\n * @param original The original link string, will be returned if the target cannot be resolved..\n * @param target The link target.\n * @param caption The caption of the link.\n * @param monospace Whether to use monospace formatting or not.\n * @returns A html link tag.\n */\n private buildLink(original:string, target:string, caption:string, monospace?:boolean):string {\n var attributes = '';\n if (this.urlPrefix.test(target)) {\n attributes = ' class=\"external\"';\n } else {\n var reflection:Reflection;\n if (this.reflection) {\n reflection = this.reflection.findReflectionByName(target);\n } else if (this.project) {\n reflection = this.project.findReflectionByName(target);\n }\n\n if (reflection && reflection.url) {\n target = this.getRelativeUrl(reflection.url);\n } else {\n return original;\n }\n }\n\n if (monospace) {\n caption = '' + caption + '';\n }\n\n return Util.format('%s', target, attributes, caption);\n }\n\n\n /**\n * Triggered when [[MarkedPlugin]] parses a markdown string.\n *\n * @param event\n */\n onParseMarkdown(event:MarkdownEvent) {\n event.parsedText = this.replaceInlineTags(this.replaceBrackets(event.parsedText));\n }\n\n\n /**\n * Split the given link into text and target at first pipe or space.\n *\n * @param text The source string that should be checked for a split character.\n * @returns An object containing the link text and target.\n */\n static splitLinkText(text:string):{caption:string;target:string;} {\n var splitIndex = text.indexOf('|');\n if (splitIndex === -1) {\n splitIndex = text.search(/\\s/);\n }\n\n if (splitIndex !== -1) {\n return {\n caption: text.substr(splitIndex + 1).replace(/\\n+/, ' '),\n target: text.substr(0, splitIndex)\n };\n } else {\n return {\n caption: text,\n target: text\n };\n }\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/plugins/MarkedPlugin.d.ts b/lib/output/plugins/MarkedPlugin.d.ts new file mode 100644 index 000000000..7db9e0f54 --- /dev/null +++ b/lib/output/plugins/MarkedPlugin.d.ts @@ -0,0 +1,15 @@ +import { ContextAwareRendererComponent } from "../components"; +import { RendererEvent, MarkdownEvent } from "../events"; +export declare class MarkedPlugin extends ContextAwareRendererComponent { + includeSource: string; + mediaSource: string; + private includes; + private mediaDirectory; + private includePattern; + private mediaPattern; + initialize(): void; + getHighlighted(text: string, lang?: string): string; + parseMarkdown(text: string, context: any): string; + protected onBeginRenderer(event: RendererEvent): void; + onParseMarkdown(event: MarkdownEvent): void; +} diff --git a/lib/output/plugins/MarkedPlugin.js b/lib/output/plugins/MarkedPlugin.js new file mode 100644 index 000000000..f21bfde8e --- /dev/null +++ b/lib/output/plugins/MarkedPlugin.js @@ -0,0 +1,137 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var FS = require("fs-extra"); +var Path = require("path"); +var Marked = require("marked"); +var HighlightJS = require("highlight.js"); +var Handlebars = require("handlebars"); +var components_1 = require("../components"); +var events_1 = require("../events"); +var component_1 = require("../../utils/component"); +var declaration_1 = require("../../utils/options/declaration"); +var MarkedPlugin = (function (_super) { + __extends(MarkedPlugin, _super); + function MarkedPlugin() { + _super.apply(this, arguments); + this.includePattern = /\[\[include:([^\]]+?)\]\]/g; + this.mediaPattern = /media:\/\/([^ "\)\]\}]+)/g; + } + MarkedPlugin.prototype.initialize = function () { + var _this = this; + _super.prototype.initialize.call(this); + this.listenTo(this.owner, events_1.MarkdownEvent.PARSE, this.onParseMarkdown); + var that = this; + Handlebars.registerHelper('markdown', function (arg) { return that.parseMarkdown(arg.fn(this), this); }); + Handlebars.registerHelper('relativeURL', function (url) { return url ? _this.getRelativeUrl(url) : url; }); + Marked.setOptions({ + highlight: function (text, lang) { return _this.getHighlighted(text, lang); } + }); + }; + MarkedPlugin.prototype.getHighlighted = function (text, lang) { + try { + if (lang) { + return HighlightJS.highlight(lang, text).value; + } + else { + return HighlightJS.highlightAuto(text).value; + } + } + catch (error) { + this.application.logger.warn(error.message); + return text; + } + }; + MarkedPlugin.prototype.parseMarkdown = function (text, context) { + var _this = this; + if (this.includes) { + text = text.replace(this.includePattern, function (match, path) { + path = Path.join(_this.includes, path.trim()); + if (FS.existsSync(path) && FS.statSync(path).isFile()) { + var contents = FS.readFileSync(path, 'utf-8'); + if (path.substr(-4).toLocaleLowerCase() == '.hbs') { + var template = Handlebars.compile(contents); + return template(context); + } + else { + return contents; + } + } + else { + return ''; + } + }); + } + if (this.mediaDirectory) { + text = text.replace(this.mediaPattern, function (match, path) { + if (FS.existsSync(Path.join(_this.mediaDirectory, path))) { + return _this.getRelativeUrl('media') + '/' + path; + } + else { + return match; + } + }); + } + var event = new events_1.MarkdownEvent(events_1.MarkdownEvent.PARSE); + event.originalText = text; + event.parsedText = text; + this.owner.trigger(event); + return event.parsedText; + }; + MarkedPlugin.prototype.onBeginRenderer = function (event) { + _super.prototype.onBeginRenderer.call(this, event); + delete this.includes; + if (this.includeSource) { + var includes = Path.resolve(this.includeSource); + if (FS.existsSync(includes) && FS.statSync(includes).isDirectory()) { + this.includes = includes; + } + else { + this.application.logger.warn('Could not find provided includes directory: ' + includes); + } + } + if (this.mediaSource) { + var media = Path.resolve(this.mediaSource); + if (FS.existsSync(media) && FS.statSync(media).isDirectory()) { + this.mediaDirectory = Path.join(event.outputDirectory, 'media'); + FS.copySync(media, this.mediaDirectory); + } + else { + this.mediaDirectory = null; + this.application.logger.warn('Could not find provided media directory: ' + media); + } + } + }; + MarkedPlugin.prototype.onParseMarkdown = function (event) { + event.parsedText = Marked(event.parsedText); + }; + __decorate([ + component_1.Option({ + name: 'includes', + help: 'Specifies the location to look for included documents (use [[include:FILENAME]] in comments).', + hint: declaration_1.ParameterHint.Directory + }) + ], MarkedPlugin.prototype, "includeSource", void 0); + __decorate([ + component_1.Option({ + name: 'media', + help: 'Specifies the location with media files that should be copied to the output directory.', + hint: declaration_1.ParameterHint.Directory + }) + ], MarkedPlugin.prototype, "mediaSource", void 0); + MarkedPlugin = __decorate([ + components_1.Component({ name: "marked" }) + ], MarkedPlugin); + return MarkedPlugin; +}(components_1.ContextAwareRendererComponent)); +exports.MarkedPlugin = MarkedPlugin; +//# sourceMappingURL=MarkedPlugin.js.map \ No newline at end of file diff --git a/lib/output/plugins/MarkedPlugin.js.map b/lib/output/plugins/MarkedPlugin.js.map new file mode 100644 index 000000000..0807bfde5 --- /dev/null +++ b/lib/output/plugins/MarkedPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"MarkedPlugin.js","sourceRoot":"","sources":["../../../src/lib/output/plugins/MarkedPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAY,EAAE,WAAM,UAAU,CAAC,CAAA;AAC/B,IAAY,IAAI,WAAM,MAAM,CAAC,CAAA;AAC7B,IAAY,MAAM,WAAM,QAAQ,CAAC,CAAA;AACjC,IAAY,WAAW,WAAM,cAAc,CAAC,CAAA;AAC5C,IAAY,UAAU,WAAM,YAAY,CAAC,CAAA;AAEzC,2BAAuD,eAAe,CAAC,CAAA;AACvE,uBAA2C,WAAW,CAAC,CAAA;AACvD,0BAAqB,uBAAuB,CAAC,CAAA;AAC7C,4BAA4B,iCAAiC,CAAC,CAAA;AAkC9D;IAAkC,gCAA6B;IAA/D;QAAkC,8BAA6B;QA6BnD,mBAAc,GAAU,4BAA4B,CAAC;QAKrD,iBAAY,GAAU,2BAA2B,CAAC;IA6H9D,CAAC;IAtHG,iCAAU,GAAV;QAAA,iBAWC;QAVG,gBAAK,CAAC,UAAU,WAAE,CAAC;QACnB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,sBAAa,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAErE,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,UAAU,CAAC,cAAc,CAAC,UAAU,EAAE,UAAS,GAAO,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5G,UAAU,CAAC,cAAc,CAAC,aAAa,EAAE,UAAC,GAAU,IAAK,OAAA,GAAG,GAAG,KAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,GAAG,EAApC,CAAoC,CAAC,CAAC;QAE/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,GAAf,UAAgB,KAAmB;QAC/B,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAChD,CAAC;IA5JD;QAAC,kBAAM,CAAC;YACJ,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,+FAA+F;YACrG,IAAI,EAAE,2BAAa,CAAC,SAAS;SAChC,CAAC;uDAAA;IAGF;QAAC,kBAAM,CAAC;YACJ,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,wFAAwF;YAC9F,IAAI,EAAE,2BAAa,CAAC,SAAS;SAChC,CAAC;qDAAA;IAdN;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,CAAC;oBAAA;IAgK3B,mBAAC;AAAD,CAAC,AA/JD,CAAkC,0CAA6B,GA+J9D;AA/JY,oBAAY,eA+JxB,CAAA","sourcesContent":["import * as FS from \"fs-extra\";\nimport * as Path from \"path\";\nimport * as Marked from \"marked\";\nimport * as HighlightJS from \"highlight.js\";\nimport * as Handlebars from \"handlebars\";\n\nimport {Component, ContextAwareRendererComponent} from \"../components\";\nimport {RendererEvent, MarkdownEvent} from \"../events\";\nimport {Option} from \"../../utils/component\";\nimport {ParameterHint} from \"../../utils/options/declaration\";\n\n\n/**\n * A plugin that exposes the markdown, compact and relativeURL helper to handlebars.\n *\n * Templates should parse all comments with the markdown handler so authors can\n * easily format their documentation. TypeDoc uses the Marked (https://github.com/chjj/marked)\n * markdown parser and HighlightJS (https://github.com/isagalaev/highlight.js) to highlight\n * code blocks within markdown sections. Additionally this plugin allows to link to other symbols\n * using double angle brackets.\n *\n * You can use the markdown helper anywhere in the templates to convert content to html:\n *\n * ```handlebars\n * {{#markdown}}{{{comment.text}}}{{/markdown}}\n * ```\n *\n * The compact helper removes all newlines of its content:\n *\n * ```handlebars\n * {{#compact}}\n * Compact\n * this\n * {{/compact}}\n * ```\n *\n * The relativeURL helper simply transforms an absolute url into a relative url:\n *\n * ```handlebars\n * {{#relativeURL url}}\n * ```\n */\n@Component({name:\"marked\"})\nexport class MarkedPlugin extends ContextAwareRendererComponent\n{\n @Option({\n name: 'includes',\n help: 'Specifies the location to look for included documents (use [[include:FILENAME]] in comments).',\n hint: ParameterHint.Directory\n })\n includeSource:string;\n\n @Option({\n name: 'media',\n help: 'Specifies the location with media files that should be copied to the output directory.',\n hint: ParameterHint.Directory\n })\n mediaSource:string;\n\n /**\n * The path referenced files are located in.\n */\n private includes:string;\n\n /**\n * Path to the output media directory.\n */\n private mediaDirectory:string;\n\n /**\n * The pattern used to find references in markdown.\n */\n private includePattern:RegExp = /\\[\\[include:([^\\]]+?)\\]\\]/g;\n\n /**\n * The pattern used to find media links.\n */\n private mediaPattern:RegExp = /media:\\/\\/([^ \"\\)\\]\\}]+)/g;\n\n\n\n /**\n * Create a new MarkedPlugin instance.\n */\n initialize() {\n super.initialize();\n this.listenTo(this.owner, MarkdownEvent.PARSE, this.onParseMarkdown);\n\n var that = this;\n Handlebars.registerHelper('markdown', function(arg:any) { return that.parseMarkdown(arg.fn(this), this); });\n Handlebars.registerHelper('relativeURL', (url:string) => url ? this.getRelativeUrl(url) : url);\n\n Marked.setOptions({\n highlight: (text:any, lang:any) => this.getHighlighted(text, lang)\n });\n }\n\n\n /**\n * Highlight the synatx of the given text using HighlightJS.\n *\n * @param text The text taht should be highlightes.\n * @param lang The language that should be used to highlight the string.\n * @return A html string with syntax highlighting.\n */\n public getHighlighted(text:string, lang?:string):string {\n try {\n if (lang) {\n return HighlightJS.highlight(lang, text).value;\n } else {\n return HighlightJS.highlightAuto(text).value;\n }\n } catch (error) {\n this.application.logger.warn(error.message);\n return text;\n }\n }\n\n\n /**\n * Parse the given markdown string and return the resulting html.\n *\n * @param text The markdown string that should be parsed.\n * @param context The current handlebars context.\n * @returns The resulting html string.\n */\n public parseMarkdown(text:string, context:any) {\n if (this.includes) {\n text = text.replace(this.includePattern, (match:string, path:string) => {\n path = Path.join(this.includes, path.trim());\n if (FS.existsSync(path) && FS.statSync(path).isFile()) {\n var contents = FS.readFileSync(path, 'utf-8');\n if (path.substr(-4).toLocaleLowerCase() == '.hbs') {\n var template = Handlebars.compile(contents);\n return template(context);\n } else {\n return contents;\n }\n } else {\n return '';\n }\n });\n }\n\n if (this.mediaDirectory) {\n text = text.replace(this.mediaPattern, (match:string, path:string) => {\n if (FS.existsSync(Path.join(this.mediaDirectory, path))) {\n return this.getRelativeUrl('media') + '/' + path;\n } else {\n return match;\n }\n });\n }\n\n var event = new MarkdownEvent(MarkdownEvent.PARSE);\n event.originalText = text;\n event.parsedText = text;\n\n this.owner.trigger(event);\n return event.parsedText;\n }\n\n\n /**\n * Triggered before the renderer starts rendering a project.\n *\n * @param event An event object describing the current render operation.\n */\n protected onBeginRenderer(event:RendererEvent) {\n super.onBeginRenderer(event);\n\n delete this.includes;\n if (this.includeSource) {\n var includes = Path.resolve(this.includeSource);\n if (FS.existsSync(includes) && FS.statSync(includes).isDirectory()) {\n this.includes = includes;\n } else {\n this.application.logger.warn('Could not find provided includes directory: ' + includes);\n }\n }\n\n if (this.mediaSource) {\n var media = Path.resolve(this.mediaSource);\n if (FS.existsSync(media) && FS.statSync(media).isDirectory()) {\n this.mediaDirectory = Path.join(event.outputDirectory, 'media');\n FS.copySync(media, this.mediaDirectory);\n } else {\n this.mediaDirectory = null;\n this.application.logger.warn('Could not find provided media directory: ' + media);\n }\n }\n }\n\n\n /**\n * Triggered when [[MarkedPlugin]] parses a markdown string.\n *\n * @param event\n */\n onParseMarkdown(event:MarkdownEvent) {\n event.parsedText = Marked(event.parsedText);\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/plugins/NavigationPlugin.d.ts b/lib/output/plugins/NavigationPlugin.d.ts new file mode 100644 index 000000000..24b64a0b8 --- /dev/null +++ b/lib/output/plugins/NavigationPlugin.d.ts @@ -0,0 +1,8 @@ +import { RendererComponent } from "../components"; +import { NavigationItem } from "../models/NavigationItem"; +export declare class NavigationPlugin extends RendererComponent { + navigation: NavigationItem; + initialize(): void; + private onBeginRenderer(event); + private onBeginPage(page); +} diff --git a/lib/output/plugins/NavigationPlugin.js b/lib/output/plugins/NavigationPlugin.js new file mode 100644 index 000000000..86fcd92d6 --- /dev/null +++ b/lib/output/plugins/NavigationPlugin.js @@ -0,0 +1,72 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var components_1 = require("../components"); +var events_1 = require("../events"); +var NavigationPlugin = (function (_super) { + __extends(NavigationPlugin, _super); + function NavigationPlugin() { + _super.apply(this, arguments); + } + NavigationPlugin.prototype.initialize = function () { + this.listenTo(this.owner, (_a = {}, + _a[events_1.RendererEvent.BEGIN] = this.onBeginRenderer, + _a[events_1.PageEvent.BEGIN] = this.onBeginPage, + _a + )); + var _a; + }; + NavigationPlugin.prototype.onBeginRenderer = function (event) { + this.navigation = this.owner.theme.getNavigation(event.project); + }; + NavigationPlugin.prototype.onBeginPage = function (page) { + var currentItems = []; + (function updateItem(item) { + item.isCurrent = false; + item.isInPath = false; + item.isVisible = item.isGlobals; + if (item.url == page.url || (item.dedicatedUrls && item.dedicatedUrls.indexOf(page.url) != -1)) { + currentItems.push(item); + } + if (item.children) { + item.children.forEach(function (child) { return updateItem(child); }); + } + })(this.navigation); + currentItems.forEach(function (item) { + item.isCurrent = true; + var depth = item.isGlobals ? -1 : 0; + var count = 1; + while (item) { + item.isInPath = true; + item.isVisible = true; + count += 1; + depth += 1; + if (item.children) { + count += item.children.length; + if (depth < 2 || count < 30) { + item.children.forEach(function (child) { + child.isVisible = true; + }); + } + } + item = item.parent; + } + }); + page.navigation = this.navigation; + }; + NavigationPlugin = __decorate([ + components_1.Component({ name: "navigation" }) + ], NavigationPlugin); + return NavigationPlugin; +}(components_1.RendererComponent)); +exports.NavigationPlugin = NavigationPlugin; +//# sourceMappingURL=NavigationPlugin.js.map \ No newline at end of file diff --git a/lib/output/plugins/NavigationPlugin.js.map b/lib/output/plugins/NavigationPlugin.js.map new file mode 100644 index 000000000..cc4362840 --- /dev/null +++ b/lib/output/plugins/NavigationPlugin.js.map @@ -0,0 +1 @@ +{"version":3,"file":"NavigationPlugin.js","sourceRoot":"","sources":["../../../src/lib/output/plugins/NavigationPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2BAA2C,eAAe,CAAC,CAAA;AAE3D,uBAAuC,WAAW,CAAC,CAAA;AAYnD;IAAsC,oCAAiB;IAAvD;QAAsC,8BAAiB;IA4EvD,CAAC;IAjEG,qCAAU,GAAV;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE;YACtB,GAAC,sBAAa,CAAC,KAAK,CAAC,GAAE,IAAI,CAAC,eAAe;YAC3C,GAAC,kBAAS,CAAC,KAAK,CAAC,GAAM,IAAI,CAAC,WAAW;;SAC1C,CAAC,CAAC;;IACP,CAAC;IAQO,0CAAe,GAAvB,UAAwB,KAAmB;QACvC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACpE,CAAC;IAQO,sCAAW,GAAnB,UAAoB,IAAc;QAC9B,IAAI,YAAY,GAAoB,EAAE,CAAC;QACvC,CAAC,oBAAoB,IAAmB;YACpC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACvB,IAAI,CAAC,QAAQ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ACxB,KAAK,CAAC,SAAS,GAAG,IAAI,CAAA;wBAC1B,CAAC,CAAC,CAAC;oBACP,CAAC;gBACL,CAAC;gBAED,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;YACvB,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IACtC,CAAC;IA5EL;QAAC,sBAAS,CAAC,EAAC,IAAI,EAAC,YAAY,EAAC,CAAC;wBAAA;IA6E/B,uBAAC;AAAD,CAAC,AA5ED,CAAsC,8BAAiB,GA4EtD;AA5EY,wBAAgB,mBA4E5B,CAAA","sourcesContent":["import {Component, RendererComponent} from \"../components\";\nimport {NavigationItem} from \"../models/NavigationItem\";\nimport {RendererEvent, PageEvent} from \"../events\";\n\n\n/**\n * A plugin that exposes the navigation structure of the documentation\n * to the rendered templates.\n *\n * The navigation structure is generated using the current themes\n * [[BaseTheme.getNavigation]] function. This plugins takes care that the navigation\n * is updated and passed to the render context.\n */\n@Component({name:\"navigation\"})\nexport class NavigationPlugin extends RendererComponent\n{\n /**\n * The navigation structure generated by the current theme.\n */\n navigation:NavigationItem;\n\n\n /**\n * Create a new NavigationPlugin instance.\n */\n initialize() {\n this.listenTo(this.owner, {\n [RendererEvent.BEGIN]: this.onBeginRenderer,\n [PageEvent.BEGIN]: this.onBeginPage\n });\n }\n\n\n /**\n * Triggered before the renderer starts rendering a project.\n *\n * @param event An event object describing the current render operation.\n */\n private onBeginRenderer(event:RendererEvent) {\n this.navigation = this.owner.theme.getNavigation(event.project);\n }\n\n\n /**\n * Triggered before a document will be rendered.\n *\n * @param page An event object describing the current render operation.\n */\n private onBeginPage(page:PageEvent) {\n var currentItems:NavigationItem[] = [];\n (function updateItem(item:NavigationItem) {\n item.isCurrent = false;\n item.isInPath = false;\n item.isVisible = item.isGlobals;\n\n if (item.url == page.url || (item.dedicatedUrls && item.dedicatedUrls.indexOf(page.url) != -1)) {\n currentItems.push(item);\n }\n\n if (item.children) {\n item.children.forEach((child) => updateItem(child));\n }\n })(this.navigation);\n\n currentItems.forEach((item:NavigationItem) => {\n item.isCurrent = true;\n\n var depth = item.isGlobals ? -1 : 0;\n var count = 1;\n while (item) {\n item.isInPath = true;\n item.isVisible = true;\n\n count += 1;\n depth += 1;\n if (item.children){\n count += item.children.length;\n if (depth < 2 || count < 30) {\n item.children.forEach((child) => {\n child.isVisible = true\n });\n }\n }\n\n item = item.parent;\n }\n });\n\n page.navigation = this.navigation;\n }\n}\n"]} \ No newline at end of file diff --git a/lib/output/plugins/PrettyPrintPlugin.d.ts b/lib/output/plugins/PrettyPrintPlugin.d.ts new file mode 100644 index 000000000..28bd2178d --- /dev/null +++ b/lib/output/plugins/PrettyPrintPlugin.d.ts @@ -0,0 +1,8 @@ +import { RendererComponent } from "../components"; +import { PageEvent } from "../events"; +export declare class PrettyPrintPlugin extends RendererComponent { + static IGNORED_TAGS: any; + static PRE_TAGS: any; + initialize(): void; + onRendererEndPage(event: PageEvent): void; +} diff --git a/lib/output/plugins/PrettyPrintPlugin.js b/lib/output/plugins/PrettyPrintPlugin.js new file mode 100644 index 000000000..cff2ad697 --- /dev/null +++ b/lib/output/plugins/PrettyPrintPlugin.js @@ -0,0 +1,138 @@ +"use strict"; +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var components_1 = require("../components"); +var events_1 = require("../events"); +var PrettyPrintState; +(function (PrettyPrintState) { + PrettyPrintState[PrettyPrintState["Default"] = 0] = "Default"; + PrettyPrintState[PrettyPrintState["Comment"] = 1] = "Comment"; + PrettyPrintState[PrettyPrintState["Pre"] = 2] = "Pre"; +})(PrettyPrintState || (PrettyPrintState = {})); +var PrettyPrintPlugin = (function (_super) { + __extends(PrettyPrintPlugin, _super); + function PrettyPrintPlugin() { + _super.apply(this, arguments); + } + PrettyPrintPlugin.prototype.initialize = function () { + this.listenTo(this.owner, events_1.PageEvent.END, this.onRendererEndPage, -1024); + }; + PrettyPrintPlugin.prototype.onRendererEndPage = function (event) { + var match; + var line; + var lineState; + var lineDepth; + var tagName; + var preName; + var tagExp = /<\s*(\w+)[^>]*>|<\/\s*(\w+)[^>]*>|/g; + var emptyLineExp = /^[\s]*$/; + var minLineDepth = 1; + var state = PrettyPrintState.Default; + var stack = []; + var lines = event.contents.split(/\r\n?|\n/); + var index = 0; + var count = lines.length; + while (index < count) { + line = lines[index]; + if (emptyLineExp.test(line)) { + if (state == PrettyPrintState.Default) { + lines.splice(index, 1); + count -= 1; + continue; + } + } + else { + lineState = state; + lineDepth = stack.length; + while (match = tagExp.exec(line)) { + if (state == PrettyPrintState.Comment) { + if (match[0] == '-->') { + state = PrettyPrintState.Default; + } + } + else if (state == PrettyPrintState.Pre) { + if (match[2] && match[2].toLowerCase() == preName) { + state = PrettyPrintState.Default; + } + } + else { + if (match[0] == '/g;\n var emptyLineExp = /^[\\s]*$/;\n var minLineDepth = 1;\n var state = PrettyPrintState.Default;\n var stack:string[] = [];\n\n var lines = event.contents.split(/\\r\\n?|\\n/);\n var index = 0;\n var count = lines.length;\n\n while (index < count) {\n line = lines[index];\n if (emptyLineExp.test(line)) {\n if (state == PrettyPrintState.Default) {\n lines.splice(index, 1);\n count -= 1;\n continue;\n }\n } else {\n lineState = state;\n lineDepth = stack.length;\n\n while (match = tagExp.exec(line)) {\n if (state == PrettyPrintState.Comment) {\n if (match[0] == '-->') {\n state = PrettyPrintState.Default;\n }\n } else if (state == PrettyPrintState.Pre) {\n if (match[2] && match[2].toLowerCase() == preName) {\n state = PrettyPrintState.Default;\n }\n } else {\n if (match[0] == '/g; - var emptyLineExp = /^[\s]*$/; - var minLineDepth = 1; - var state = PrettyPrintState.Default; - var stack = []; - var lines = event.contents.split(/\r\n?|\n/); - var index = 0; - var count = lines.length; - while (index < count) { - line = lines[index]; - if (emptyLineExp.test(line)) { - if (state == PrettyPrintState.Default) { - lines.splice(index, 1); - count -= 1; - continue; - } - } - else { - lineState = state; - lineDepth = stack.length; - while (match = tagExp.exec(line)) { - if (state == PrettyPrintState.Comment) { - if (match[0] == '-->') { - state = PrettyPrintState.Default; - } - } - else if (state == PrettyPrintState.Pre) { - if (match[2] && match[2].toLowerCase() == preName) { - state = PrettyPrintState.Default; - } - } - else { - if (match[0] == '/g;\n var emptyLineExp = /^[\\s]*$/;\n var minLineDepth = 1;\n var state = PrettyPrintState.Default;\n var stack:string[] = [];\n\n var lines = event.contents.split(/\\r\\n?|\\n/);\n var index = 0;\n var count = lines.length;\n\n while (index < count) {\n line = lines[index];\n if (emptyLineExp.test(line)) {\n if (state == PrettyPrintState.Default) {\n lines.splice(index, 1);\n count -= 1;\n continue;\n }\n } else {\n lineState = state;\n lineDepth = stack.length;\n\n while (match = tagExp.exec(line)) {\n if (state == PrettyPrintState.Comment) {\n if (match[0] == '-->') {\n state = PrettyPrintState.Default;\n }\n } else if (state == PrettyPrintState.Pre) {\n if (match[2] && match[2].toLowerCase() == preName) {\n state = PrettyPrintState.Default;\n }\n } else {\n if (match[0] == '