Skip to content

Commit

Permalink
fix(Typings): Output public constructors in .d.ts files
Browse files Browse the repository at this point in the history
Closes #3926.
  • Loading branch information
jteplitz committed Sep 2, 2015
1 parent 01cdd31 commit 518b690
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 26 deletions.
25 changes: 18 additions & 7 deletions docs/typescript-definition-package/processors/code_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {

signature: function(remap) {
return function(ast) {
var initializerRegex = /\s*=[^>][^,}]*/g;
try {
var text = [];
if (ast.isStatic) text.push('static ');
Expand All @@ -14,15 +15,21 @@ module.exports = {
}
if (ast.parameters) {
text.push('(');
text.push(ast.parameters.join(', '));
var parameters = ast.parameters;
for (var i = 0; i < parameters.length; i++) {
parameters[i] = parameters[i].replace(initializerRegex, '');
}
text.push(parameters.join(', '));
text.push(')');
}
if (ast.returnType) {
text.push(': ', ast.returnType);
} else if (ast.parameters) {
text.push(': void');
} else {
text.push(': any');
if (!isConstructor(ast)) {
if (ast.returnType) {
text.push(': ', ast.returnType);
} else if (ast.parameters) {
text.push(': void');
} else {
text.push(': any');
}
}
var string = text.join('');
for (var key in remap) {
Expand All @@ -38,3 +45,7 @@ module.exports = {
}
}
};

function isConstructor(ast) {
return ast.parameters && ast.name === "constructor";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
{$ signature(member) $};
{%- endmacro -%}


// Type definitions for Angular v{$ versionInfo.currentVersion.full | replace(r/\+/, "_") $}
// Project: http://angular.io/
// Definitions by: angular team <https://github.com/angular/>
Expand Down Expand Up @@ -41,8 +40,11 @@
{%- if export.content -%}
{$ commentBlock(export, 3) $}
{%- endif %}
{$ export.docType $} {$ export.name $}{$ export.typeParams $}{%- if export.heritage == ' extends Directive' %} extends DirectiveAnnotation{% else %}{$ export.heritage $}{% endif %}
{%- if export.docType == 'type-alias' %}type {$ export.name $} ={$ export.typeDefinition $}{% else %}{$ export.docType $} {$ export.name $}{$ export.typeParams $}{%- if export.heritage == ' extends Directive' %} extends DirectiveAnnotation{% else %}{$ export.heritage $}{% endif %}{% endif %}
{%- if export.docType == 'class' or export.docType == 'interface' %} {
{%- if export.constructorDoc %}
{$ memberInfo(doc.signature, export.constructorDoc) $}
{% endif -%}
{%- if export.newMember %}
{$ memberInfo(doc.signature, export.newMember) $}
{% endif %}
Expand Down
8 changes: 8 additions & 0 deletions docs/typescript-package/processors/readTypeScriptModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
function createExportDoc(name, exportSymbol, moduleDoc, basePath, typeChecker) {
var typeParamString = '';
var heritageString = '';
var typeDefinition = '';

exportSymbol.declarations.forEach(function(decl) {
var sourceFile = ts.getSourceFileOfNode(decl);
Expand All @@ -158,6 +159,10 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
typeParamString = '<' + getText(sourceFile, decl.typeParameters) + '>';
}

if (decl.symbol.flags & ts.SymbolFlags.TypeAlias) {
typeDefinition = getText(sourceFile, decl.type);
}

if (decl.heritageClauses) {
decl.heritageClauses.forEach(function(heritage) {

Expand Down Expand Up @@ -211,6 +216,9 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
if(exportSymbol.flags & ts.SymbolFlags.Value) {
exportDoc.returnType = getReturnType(typeChecker, exportSymbol);
}
if (exportSymbol.flags & ts.SymbolFlags.TypeAlias) {
exportDoc.typeDefinition = typeDefinition;
}
return exportDoc;
}

Expand Down
1 change: 1 addition & 0 deletions modules/angular2/angular2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './metadata';
export * from './change_detection';
export * from './core';
export * from './di';
export * from './reflection';
export * from './directives';
export * from './forms';
export * from './render';
Expand Down
1 change: 1 addition & 0 deletions modules/angular2/angular2_exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './metadata';
export * from './change_detection';
export * from './core';
export * from './di';
export * from './reflection';
export * from './directives';
export * from './forms';
export * from './render';
Expand Down
6 changes: 4 additions & 2 deletions modules/angular2/change_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export {
IterableDifferFactory,
KeyValueDiffers,
KeyValueDiffer,
KeyValueDifferFactory

KeyValueDifferFactory,
Lexer,
Parser,
} from 'angular2/src/core/change_detection/change_detection';
export * from 'angular2/src/core/change_detection/parser/ast';
2 changes: 0 additions & 2 deletions modules/angular2/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
export {APP_COMPONENT} from 'angular2/src/core/application_tokens';
export {Type} from 'angular2/src/core/facade/lang';
export {ApplicationRef} from 'angular2/src/core/application_ref';


// Compiler Related Dependencies.
export {AppRootUrl} from 'angular2/src/core/services/app_root_url';
export {UrlResolver} from 'angular2/src/core/services/url_resolver';
Expand Down
1 change: 1 addition & 0 deletions modules/angular2/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export {BaseRequestOptions, RequestOptions} from './src/http/base_request_option
export {BaseResponseOptions, ResponseOptions} from './src/http/base_response_options';
export {XHRBackend, XHRConnection} from './src/http/backends/xhr_backend';
export {JSONPBackend, JSONPConnection} from './src/http/backends/jsonp_backend';
export {BrowserJsonp} from './src/http/backends/browser_jsonp';
export {Http, Jsonp} from './src/http/http';

export {Headers} from './src/http/headers';
Expand Down
5 changes: 5 additions & 0 deletions modules/angular2/reflection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export {Reflector, ReflectionInfo} from 'angular2/src/core/reflection/reflection';
export {
PlatformReflectionCapabilities
} from 'angular2/src/core/reflection/platform_reflection_capabilities';
export {SetterFn, GetterFn, MethodFn} from 'angular2/src/core/reflection/types';
7 changes: 6 additions & 1 deletion modules/angular2/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ export {
ViewDefinition,
DOCUMENT,
APP_ID,
MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE
MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE,
EventManager,
EventManagerPlugin,
SharedStylesHost,
DomSharedStylesHost,
TemplateCloner
} from './src/core/render/render';
36 changes: 36 additions & 0 deletions modules/angular2/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,46 @@

export {Router, RootRouter} from './src/router/router';
export {RouterOutlet} from './src/router/router_outlet';
export {
DynamicComponentLoader,
ComponentRef,
ElementRef,
Compiler,
AppViewManager,
ViewRef,
HostViewRef,
ProtoViewRef,
ViewContainerRef,
TemplateRef
} from 'angular2/core';
export {
Renderer,
RenderElementRef,
RenderViewRef,
RenderProtoViewRef,
RenderEventDispatcher,
RenderFragmentRef,
RenderViewWithFragments
} from 'angular2/render';
export {
Binding,
Injector,
ResolvedBinding,
Key,
Dependency,
ProtoInjector,
DependencyProvider,
BindingWithVisibility,
Visibility
} from 'angular2/di';
export {RouterLink} from './src/router/router_link';
export {RouteParams} from './src/router/instruction';
export {RouteRegistry} from './src/router/route_registry';
export {LocationStrategy} from './src/router/location_strategy';
export {HashLocationStrategy} from './src/router/hash_location_strategy';
export {PathLocationStrategy} from './src/router/path_location_strategy';
export {PathRecognizer, PathMatch} from './src/router/path_recognizer';
export {RouteHandler} from './src/router/route_handler';
export {Location, APP_BASE_HREF} from './src/router/location';
export {Pipeline} from './src/router/pipeline';
export * from './src/router/route_config_decorator';
Expand Down Expand Up @@ -51,6 +85,8 @@ export const ROUTER_BINDINGS: any[] = CONST_EXPR([
}))
]);

export interface InjectableReference {}

function routerFactory(registry, pipeline, location, appRoot) {
return new RootRouter(registry, pipeline, location, appRoot);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ import {
assertionsEnabled
} from 'angular2/src/core/facade/lang';

export {
ASTWithSource,
AST,
AstTransformer,
PropertyRead,
LiteralArray,
ImplicitReceiver
} from './parser/ast';
export * from './parser/ast';

export {Lexer} from './parser/lexer';
export {Parser} from './parser/parser';
Expand Down
3 changes: 3 additions & 0 deletions modules/angular2/src/core/render/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ export * from './dom/compiler/compiler';
export * from './dom/dom_renderer';
export * from './dom/dom_tokens';
export * from './dom/template_cloner';
export * from './dom/events/event_manager';
export * from './dom/view/shared_styles_host';
export * from './dom/template_cloner';
export * from './api';
6 changes: 6 additions & 0 deletions modules/angular2/web_worker/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ export * from "../src/web_workers/ui/application";
export * from "../src/web_workers/shared/client_message_broker";
export * from "../src/web_workers/shared/service_message_broker";
export * from "../src/web_workers/shared/serializer";
export * from '../src/web_workers/shared/render_proto_view_ref_store';
export * from '../src/web_workers/shared/render_view_with_fragments_store';
export * from '../src/core/render/api';
export * from '../change_detection';
export * from "../di";
export * from "../reflection";
9 changes: 6 additions & 3 deletions modules/angular2/web_worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ export * from '../metadata';
export * from '../change_detection';
export * from '../core';
export * from '../di';
export * from "../reflection";
export * from '../directives';
export * from '../forms';
export * from '../render';
export * from '../profile';
export * from '../src/web_workers/worker/application';
export * from "../src/web_workers/shared/client_message_broker";
export * from "../src/web_workers/shared/service_message_broker";
export * from "../src/web_workers/shared/serializer";
export * from '../src/web_workers/shared/client_message_broker';
export * from '../src/web_workers/shared/service_message_broker';
export * from '../src/web_workers/shared/serializer';
export * from '../src/web_workers/shared/render_proto_view_ref_store';
export * from '../src/web_workers/shared/render_view_with_fragments_store';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ library angular2.transform.common.directive_metadata_reader;
import 'package:analyzer/analyzer.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:angular2/src/core/render/api.dart';
import 'package:angular2/src/core/change_detection/change_detection.dart';
import 'package:angular2/src/core/change_detection/change_detection.dart'
show ChangeDetectionStrategy;

/// Reads [RenderDirectiveMetadata] from the `node`. `node` is expected to be an
/// instance of [Annotation], [NodeList<Annotation>], ListLiteral, or
Expand Down

0 comments on commit 518b690

Please sign in to comment.