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 8, 2015
1 parent 3b9c086 commit fd8fcde
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 24 deletions.
27 changes: 19 additions & 8 deletions docs/typescript-definition-package/processors/code_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function DtsSerializer(remap) {
}

DtsSerializer.prototype = {
_initializerRegex: /\s*=[^>][^,}]*/g,

constructor: DtsSerializer,

Expand All @@ -18,15 +19,21 @@ DtsSerializer.prototype = {
}
if (ast.parameters) {
buffer.push('(');
buffer.push(ast.parameters.join(', '));
var parameters = ast.parameters;
for (var i = 0; i < parameters.length; i++) {
parameters[i] = parameters[i].replace(this._initializerRegex, '');
}
buffer.push(parameters.join(', '));
buffer.push(')');
}
if (ast.returnType) {
buffer.push(': ', ast.returnType);
} else if (ast.parameters) {
buffer.push(': void');
} else {
buffer.push(': any');
if (!isConstructor(ast)) {
if (ast.returnType) {
buffer.push(': ', ast.returnType);
} else if (ast.parameters) {
buffer.push(': void');
} else {
buffer.push(': any');
}
}
buffer.push(';\n');
},
Expand Down Expand Up @@ -58,6 +65,7 @@ DtsSerializer.prototype = {
buffer.indent();
if (ast.newMember) this.member(buffer, ast.newMember);
if (ast.callMember) this.member(buffer, ast.callMember);
if (ast.constructorDoc) this.member(buffer, ast.constructorDoc);

ast.statics.forEach(function(staticMember) {
this.member(buffer, staticMember);
Expand Down Expand Up @@ -144,7 +152,6 @@ DtsSerializer.prototype = {
}
};


function Buffer() {
this._globalBuffer = [];
this._indentedBuffer = [];
Expand Down Expand Up @@ -191,7 +198,11 @@ Buffer.prototype = {
}
};

function isConstructor(ast) {
return ast.parameters && ast.name === "constructor";
}

module.exports = {
DtsSerializer: DtsSerializer
};

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 @@ -215,6 +220,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
2 changes: 1 addition & 1 deletion modules/angular2/angular2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './core';
export * from './profile';
export * from './lifecycle_hooks';
export * from './bootstrap';
export * from './bootstrap';
5 changes: 5 additions & 0 deletions modules/angular2/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ export * from './src/core/directives';
export * from './src/core/forms';
export * from './src/core/debug';
export * from './src/core/change_detection';
export {Reflector, ReflectionInfo} from './src/core/reflection/reflection';
export {
PlatformReflectionCapabilities
} from './src/core/reflection/platform_reflection_capabilities';
export {SetterFn, GetterFn, MethodFn} from './src/core/reflection/types';
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
21 changes: 20 additions & 1 deletion modules/angular2/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,23 @@
*
* JavaScript users should import from angular2/core.
*/
export * from './src/core/render';
export {
RenderDirectiveMetadata,
DomRenderer,
RenderEventDispatcher,
Renderer,
RenderElementRef,
RenderViewRef,
RenderProtoViewRef,
RenderFragmentRef,
RenderViewWithFragments,
ViewDefinition,
DOCUMENT,
APP_ID,
MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE,
EventManager,
EventManagerPlugin,
SharedStylesHost,
DomSharedStylesHost,
TemplateCloner
} from './src/core/render/render';
37 changes: 37 additions & 0 deletions modules/angular2/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,47 @@

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 './core';
export {
Renderer,
RenderElementRef,
RenderViewRef,
RenderProtoViewRef,
RenderEventDispatcher,
RenderFragmentRef,
RenderViewWithFragments
} from './render';
export {
Binding,
Injector,
ResolvedBinding,
Key,
Dependency,
ProtoInjector,
DependencyProvider,
BindingWithVisibility,
Visibility,
ResolvedFactory
} from './src/core/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 +86,8 @@ export const ROUTER_BINDINGS: any[] = CONST_EXPR([
}))
]);

export interface InjectableReference {}

function routerFactory(registry, pipeline, location, appRoot) {
return new RootRouter(registry, pipeline, location, appRoot);
}
13 changes: 10 additions & 3 deletions modules/angular2/src/core/change_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export {
IterableDifferFactory,
KeyValueDiffers,
KeyValueDiffer,
KeyValueDifferFactory

} from './change_detection/change_detection';
KeyValueDifferFactory,
Lexer,
Parser,
ChangeDispatcher,
BindingTarget,
DirectiveIndex,
DebugContext,
ProtoChangeDetector
} from 'angular2/src/core/change_detection/change_detection';
export * from 'angular2/src/core/change_detection/parser/ast';
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
10 changes: 10 additions & 0 deletions modules/angular2/src/core/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ export {ElementRef} from './compiler/element_ref';
export {TemplateRef} from './compiler/template_ref';
export {ViewRef, HostViewRef, ProtoViewRef} from './compiler/view_ref';
export {ViewContainerRef} from './compiler/view_container_ref';
export {AppView, AppProtoView, AppProtoViewMergeMapping, AppViewContainer} from './compiler/view';
export {ComponentRef} from './compiler/dynamic_component_loader';
export {
ElementInjector,
PreBuiltObjects,
TreeNode,
ProtoElementInjector,
DirectiveBinding,
EventEmitterAccessor
} from './compiler/element_injector';
export {ElementBinder} from './compiler/element_binder';
2 changes: 2 additions & 0 deletions modules/angular2/src/core/pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export {LimitToPipe} from './pipes/limit_to_pipe';
export {LowerCasePipe} from './pipes/lowercase_pipe';
export {NumberPipe, DecimalPipe, PercentPipe, CurrencyPipe} from './pipes/number_pipe';
export {UpperCasePipe} from './pipes/uppercase_pipe';
export {ProtoPipes} from './pipes/pipes';
export {PipeBinding} from './pipes/pipe_binding';
9 changes: 8 additions & 1 deletion modules/angular2/src/core/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@ export {
ViewDefinition,
DOCUMENT,
APP_ID,
MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE
MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE,
EventManager,
SharedStylesHost,
DomSharedStylesHost,
TemplateCloner,
ViewType,
RenderProtoViewMergeMapping,
EventManagerPlugin
} from './render/render';
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';
2 changes: 2 additions & 0 deletions modules/angular2/test_lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
export * from './test';
export * from './src/test_lib/utils';
export * from './src/test_lib/fake_async';
export {ComponentRef, HostViewRef} from './src/core/compiler';
export {InjectableReference} from './router';
10 changes: 10 additions & 0 deletions modules/angular2/web_worker/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@ 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 '../src/core/change_detection';
export * from '../src/core/di';
export {Reflector, ReflectionInfo} from '../src/core/reflection/reflection';
export {
PlatformReflectionCapabilities
} from '../src/core/reflection/platform_reflection_capabilities';
export {SetterFn, GetterFn, MethodFn} from '../src/core/reflection/types';
8 changes: 7 additions & 1 deletion modules/angular2/web_worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ export * from '../src/core/directives';
export * from '../src/core/forms';
export * from '../src/core/debug';
export * from '../src/core/change_detection';

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/render_proto_view_ref_store';
export * from '../src/web_workers/shared/render_view_with_fragments_store';
export {Reflector, ReflectionInfo} from '../src/core/reflection/reflection';
export {
PlatformReflectionCapabilities
} from '../src/core/reflection/platform_reflection_capabilities';
export {SetterFn, GetterFn, MethodFn} from '../src/core/reflection/types';
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 [ClassDeclaration] (a class which may have a [Directive] or
Expand Down

0 comments on commit fd8fcde

Please sign in to comment.