fix(Typings): Output public constructors in .d.ts files

Closes #3926.

Closes #3963
This commit is contained in:
Jason Teplitz 2015-09-09 11:24:59 -07:00
parent 12dd44f7f6
commit 1926335b85
24 changed files with 136 additions and 41 deletions

View File

@ -52,11 +52,9 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
id: 'angular2/angular2', id: 'angular2/angular2',
references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'], references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'],
modules: { modules: {
'angular2/angular2': {namespace: 'ng', id: 'angular2/angular2'} 'angular2/angular2': {namespace: 'ng', id: 'angular2/angular2'},
/* TODO(jeffbcross): re-implement with @jteplitz as part of #3926,
'angular2/web_worker/worker': {namespace: 'ngWorker', id: 'angular2/web_worker/worker'}, 'angular2/web_worker/worker': {namespace: 'ngWorker', id: 'angular2/web_worker/worker'},
'angular2/web_worker/ui': {namespace: 'ngUi', id: 'angular2/web_worker/ui'} 'angular2/web_worker/ui': {namespace: 'ngUi', id: 'angular2/web_worker/ui'}
*/
} }
}, },
{ {

View File

@ -5,6 +5,7 @@ function DtsSerializer(remap) {
} }
DtsSerializer.prototype = { DtsSerializer.prototype = {
_initializerRegex: /\s*=[^>][^,}]*/g,
constructor: DtsSerializer, constructor: DtsSerializer,
@ -18,15 +19,21 @@ DtsSerializer.prototype = {
} }
if (ast.parameters) { if (ast.parameters) {
buffer.push('('); 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(')'); buffer.push(')');
} }
if (ast.returnType) { if (!isConstructor(ast)) {
buffer.push(': ', ast.returnType); if (ast.returnType) {
} else if (ast.parameters) { buffer.push(': ', ast.returnType);
buffer.push(': void'); } else if (ast.parameters) {
} else { buffer.push(': void');
buffer.push(': any'); } else {
buffer.push(': any');
}
} }
buffer.push(';\n'); buffer.push(';\n');
}, },
@ -58,6 +65,7 @@ DtsSerializer.prototype = {
buffer.indent(); buffer.indent();
if (ast.newMember) this.member(buffer, ast.newMember); if (ast.newMember) this.member(buffer, ast.newMember);
if (ast.callMember) this.member(buffer, ast.callMember); if (ast.callMember) this.member(buffer, ast.callMember);
if (ast.constructorDoc) this.member(buffer, ast.constructorDoc);
ast.statics.forEach(function(staticMember) { ast.statics.forEach(function(staticMember) {
this.member(buffer, staticMember); this.member(buffer, staticMember);
@ -144,7 +152,6 @@ DtsSerializer.prototype = {
} }
}; };
function Buffer() { function Buffer() {
this._globalBuffer = []; this._globalBuffer = [];
this._indentedBuffer = []; this._indentedBuffer = [];
@ -191,7 +198,11 @@ Buffer.prototype = {
} }
}; };
function isConstructor(ast) {
return ast.parameters && ast.name === "constructor";
}
module.exports = { module.exports = {
DtsSerializer: DtsSerializer DtsSerializer: DtsSerializer
}; };

View File

@ -150,6 +150,7 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
function createExportDoc(name, exportSymbol, moduleDoc, basePath, typeChecker) { function createExportDoc(name, exportSymbol, moduleDoc, basePath, typeChecker) {
var typeParamString = ''; var typeParamString = '';
var heritageString = ''; var heritageString = '';
var typeDefinition = '';
exportSymbol.declarations.forEach(function(decl) { exportSymbol.declarations.forEach(function(decl) {
var sourceFile = ts.getSourceFileOfNode(decl); var sourceFile = ts.getSourceFileOfNode(decl);
@ -158,6 +159,10 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
typeParamString = '<' + getText(sourceFile, decl.typeParameters) + '>'; typeParamString = '<' + getText(sourceFile, decl.typeParameters) + '>';
} }
if (decl.symbol.flags & ts.SymbolFlags.TypeAlias) {
typeDefinition = getText(sourceFile, decl.type);
}
if (decl.heritageClauses) { if (decl.heritageClauses) {
decl.heritageClauses.forEach(function(heritage) { decl.heritageClauses.forEach(function(heritage) {
@ -215,6 +220,9 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
if(exportSymbol.flags & ts.SymbolFlags.Value) { if(exportSymbol.flags & ts.SymbolFlags.Value) {
exportDoc.returnType = getReturnType(typeChecker, exportSymbol); exportDoc.returnType = getReturnType(typeChecker, exportSymbol);
} }
if (exportSymbol.flags & ts.SymbolFlags.TypeAlias) {
exportDoc.typeDefinition = typeDefinition;
}
return exportDoc; return exportDoc;
} }

View File

@ -1,4 +1,4 @@
export * from './core'; export * from './core';
export * from './profile'; export * from './profile';
export * from './lifecycle_hooks'; export * from './lifecycle_hooks';
export * from './bootstrap'; export * from './bootstrap';

View File

@ -18,3 +18,8 @@ export * from './src/core/directives';
export * from './src/core/forms'; export * from './src/core/forms';
export * from './src/core/debug'; export * from './src/core/debug';
export * from './src/core/change_detection'; 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';

View File

@ -30,6 +30,7 @@ export {BaseRequestOptions, RequestOptions} from './src/http/base_request_option
export {BaseResponseOptions, ResponseOptions} from './src/http/base_response_options'; export {BaseResponseOptions, ResponseOptions} from './src/http/base_response_options';
export {XHRBackend, XHRConnection} from './src/http/backends/xhr_backend'; export {XHRBackend, XHRConnection} from './src/http/backends/xhr_backend';
export {JSONPBackend, JSONPConnection} from './src/http/backends/jsonp_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 {Http, Jsonp} from './src/http/http';
export {Headers} from './src/http/headers'; export {Headers} from './src/http/headers';

View File

@ -7,12 +7,47 @@
export {Router, RootRouter} from './src/router/router'; export {Router, RootRouter} from './src/router/router';
export {RouterOutlet} from './src/router/router_outlet'; 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 {RouterLink} from './src/router/router_link';
export {RouteParams} from './src/router/instruction'; export {RouteParams} from './src/router/instruction';
export {RouteRegistry} from './src/router/route_registry'; export {RouteRegistry} from './src/router/route_registry';
export {LocationStrategy} from './src/router/location_strategy'; export {LocationStrategy} from './src/router/location_strategy';
export {HashLocationStrategy} from './src/router/hash_location_strategy'; export {HashLocationStrategy} from './src/router/hash_location_strategy';
export {PathLocationStrategy} from './src/router/path_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 {Location, APP_BASE_HREF} from './src/router/location';
export {Pipeline} from './src/router/pipeline'; export {Pipeline} from './src/router/pipeline';
export * from './src/router/route_config_decorator'; export * from './src/router/route_config_decorator';
@ -73,6 +108,8 @@ export const ROUTER_BINDINGS: any[] = CONST_EXPR([
})) }))
]); ]);
export interface InjectableReference {}
function routerFactory(registry, pipeline, location, appRoot) { function routerFactory(registry, pipeline, location, appRoot) {
return new RootRouter(registry, pipeline, location, appRoot); return new RootRouter(registry, pipeline, location, appRoot);
} }

View File

@ -22,6 +22,13 @@ export {
IterableDifferFactory, IterableDifferFactory,
KeyValueDiffers, KeyValueDiffers,
KeyValueDiffer, KeyValueDiffer,
KeyValueDifferFactory KeyValueDifferFactory,
Lexer,
} from './change_detection/change_detection'; Parser,
ChangeDispatcher,
BindingTarget,
DirectiveIndex,
DebugContext,
ProtoChangeDetector
} from 'angular2/src/core/change_detection/change_detection';
export * from 'angular2/src/core/change_detection/parser/ast';

View File

@ -21,14 +21,7 @@ import {
assertionsEnabled assertionsEnabled
} from 'angular2/src/core/facade/lang'; } from 'angular2/src/core/facade/lang';
export { export * from './parser/ast';
ASTWithSource,
AST,
AstTransformer,
PropertyRead,
LiteralArray,
ImplicitReceiver
} from './parser/ast';
export {Lexer} from './parser/lexer'; export {Lexer} from './parser/lexer';
export {Parser} from './parser/parser'; export {Parser} from './parser/parser';

View File

@ -19,4 +19,14 @@ export {ElementRef} from './compiler/element_ref';
export {TemplateRef} from './compiler/template_ref'; export {TemplateRef} from './compiler/template_ref';
export {ViewRef, HostViewRef, ProtoViewRef} from './compiler/view_ref'; export {ViewRef, HostViewRef, ProtoViewRef} from './compiler/view_ref';
export {ViewContainerRef} from './compiler/view_container_ref'; export {ViewContainerRef} from './compiler/view_container_ref';
export {AppView, AppProtoView, AppProtoViewMergeMapping, AppViewContainer} from './compiler/view';
export {ComponentRef} from './compiler/dynamic_component_loader'; export {ComponentRef} from './compiler/dynamic_component_loader';
export {
ElementInjector,
PreBuiltObjects,
TreeNode,
ProtoElementInjector,
DirectiveBinding,
EventEmitterAccessor
} from './compiler/element_injector';
export {ElementBinder} from './compiler/element_binder';

View File

@ -12,3 +12,5 @@ export {LimitToPipe} from './pipes/limit_to_pipe';
export {LowerCasePipe} from './pipes/lowercase_pipe'; export {LowerCasePipe} from './pipes/lowercase_pipe';
export {NumberPipe, DecimalPipe, PercentPipe, CurrencyPipe} from './pipes/number_pipe'; export {NumberPipe, DecimalPipe, PercentPipe, CurrencyPipe} from './pipes/number_pipe';
export {UpperCasePipe} from './pipes/uppercase_pipe'; export {UpperCasePipe} from './pipes/uppercase_pipe';
export {ProtoPipes} from './pipes/pipes';
export {PipeBinding} from './pipes/pipe_binding';

View File

@ -12,5 +12,12 @@ export {
ViewDefinition, ViewDefinition,
DOCUMENT, DOCUMENT,
APP_ID, APP_ID,
MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE MAX_IN_MEMORY_ELEMENTS_PER_TEMPLATE,
EventManager,
SharedStylesHost,
DomSharedStylesHost,
TemplateCloner,
ViewType,
RenderProtoViewMergeMapping,
EventManagerPlugin
} from './render/render'; } from './render/render';

View File

@ -10,4 +10,7 @@ export * from './dom/compiler/compiler';
export * from './dom/dom_renderer'; export * from './dom/dom_renderer';
export * from './dom/dom_tokens'; export * from './dom/dom_tokens';
export * from './dom/template_cloner'; 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'; export * from './api';

View File

@ -2,7 +2,6 @@ import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular
import {DOM} from 'angular2/src/core/dom/dom_adapter'; import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {SelectorMatcher} from 'angular2/src/core/render/dom/compiler/selector'; import {SelectorMatcher} from 'angular2/src/core/render/dom/compiler/selector';
import {CssSelector} from 'angular2/src/core/render/dom/compiler/selector'; import {CssSelector} from 'angular2/src/core/render/dom/compiler/selector';
import {ListWrapper, MapWrapper} from 'angular2/src/core/facade/collection';
export function main() { export function main() {
describe('SelectorMatcher', () => { describe('SelectorMatcher', () => {

View File

@ -15,7 +15,6 @@ import {
import {DOM} from 'angular2/src/core/dom/dom_adapter'; import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline'; import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline';
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import { import {
ProtoViewBuilder, ProtoViewBuilder,
ElementBinderBuilder ElementBinderBuilder

View File

@ -3,7 +3,6 @@ import {
TextInterpolationParser TextInterpolationParser
} from 'angular2/src/core/render/dom/compiler/text_interpolation_parser'; } from 'angular2/src/core/render/dom/compiler/text_interpolation_parser';
import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline'; import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline';
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {Lexer, Parser, ASTWithSource} from 'angular2/src/core/change_detection/change_detection'; import {Lexer, Parser, ASTWithSource} from 'angular2/src/core/change_detection/change_detection';
import {IgnoreChildrenStep} from './pipeline_spec'; import {IgnoreChildrenStep} from './pipeline_spec';
import { import {

View File

@ -16,7 +16,6 @@ import {StyleUrlResolver} from 'angular2/src/core/render/dom/compiler/style_url_
import {UrlResolver} from 'angular2/src/core/services/url_resolver'; import {UrlResolver} from 'angular2/src/core/services/url_resolver';
import {PromiseWrapper, Promise} from 'angular2/src/core/facade/async'; import {PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {XHR} from 'angular2/src/core/render/xhr'; import {XHR} from 'angular2/src/core/render/xhr';
import {MockXHR} from 'angular2/src/core/render/xhr_mock'; import {MockXHR} from 'angular2/src/core/render/xhr_mock';
import {ViewDefinition} from 'angular2/src/core/render/api'; import {ViewDefinition} from 'angular2/src/core/render/api';

View File

@ -13,7 +13,6 @@ import {
SpyObject, SpyObject,
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {MapWrapper} from 'angular2/src/core/facade/collection';
import {DOM} from 'angular2/src/core/dom/dom_adapter'; import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {DomTestbed, TestRootView, elRef} from './dom_testbed'; import {DomTestbed, TestRootView, elRef} from './dom_testbed';

View File

@ -10,8 +10,6 @@ import {
SpyObject SpyObject
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {Map, StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {RouteRecognizer} from 'angular2/src/router/route_recognizer'; import {RouteRecognizer} from 'angular2/src/router/route_recognizer';
import {ComponentInstruction} from 'angular2/src/router/instruction'; import {ComponentInstruction} from 'angular2/src/router/instruction';

View File

@ -2,3 +2,9 @@
export * from './test'; export * from './test';
export * from './src/test_lib/utils'; export * from './src/test_lib/utils';
export * from './src/test_lib/fake_async'; export * from './src/test_lib/fake_async';
export {ComponentRef, HostViewRef} from './src/core/compiler';
// This interface is referenced by TestComponents, however we can't export it directly from router
// because router pulls in dart:html & dart:js and we import test_lib in standalone VM tests
// so we re-create the interface here.
export interface InjectableReference {}

View File

@ -1,4 +1,15 @@
export * from "../src/web_workers/ui/application"; export * from "../src/web_workers/ui/application";
export * from '../src/core/zone';
export * from "../src/web_workers/shared/client_message_broker"; export * from "../src/web_workers/shared/client_message_broker";
export * from "../src/web_workers/shared/service_message_broker"; export * from "../src/web_workers/shared/service_message_broker";
export * from "../src/web_workers/shared/serializer"; 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';

View File

@ -14,14 +14,22 @@ export * from '../src/core/zone';
// Do not export render in web_worker // Do not export render in web_worker
// export * from '../src/core/render'; // export * from '../src/core/render';
// Add special import for just render API // Add special import for just render API
export * from '../src/core/application_ref';
export * from '../src/core/application_tokens';
export * from '../src/core/render/api'; export * from '../src/core/render/api';
export * from '../src/core/directives'; export * from '../src/core/directives';
export * from '../src/core/forms'; export * from '../src/core/forms';
export * from '../src/core/debug'; export * from '../src/core/debug';
export * from '../src/core/change_detection'; export * from '../src/core/change_detection';
export * from '../profile'; export * from '../profile';
export * from '../src/web_workers/worker/application'; export * from '../src/web_workers/worker/application';
export * from '../src/web_workers/shared/client_message_broker'; export * from '../src/web_workers/shared/client_message_broker';
export * from '../src/web_workers/shared/service_message_broker'; export * from '../src/web_workers/shared/service_message_broker';
export * from '../src/web_workers/shared/serializer'; 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';

View File

@ -8,14 +8,8 @@ var broker = instance.app.createClientMessageBroker(ECHO_CHANNEL, false);
document.getElementById("send_echo") document.getElementById("send_echo")
.addEventListener("click", (e) => { .addEventListener("click", (e) => {
var val = (<HTMLInputElement>document.getElementById("echo_input")).value; var val = (<HTMLInputElement>document.getElementById("echo_input")).value;
// TODO(jteplitz602): Replace default constructors with real constructors var fnArg = new FnArg(val, PRIMITIVE);
// once they're in the .d.ts file (#3926) var args = new UiArguments("echo", [fnArg]);
var args = new UiArguments();
args.method = "echo";
var fnArg = new FnArg();
fnArg.value = val;
fnArg.type = PRIMITIVE;
args.args = [fnArg];
broker.runOnService(args, PRIMITIVE) broker.runOnService(args, PRIMITIVE)
.then((echo_result: string) => { .then((echo_result: string) => {

View File

@ -3,7 +3,8 @@ library angular2.transform.common.directive_metadata_reader;
import 'package:analyzer/analyzer.dart'; import 'package:analyzer/analyzer.dart';
import 'package:analyzer/src/generated/element.dart'; import 'package:analyzer/src/generated/element.dart';
import 'package:angular2/src/core/render/api.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 /// Reads [RenderDirectiveMetadata] from the `node`. `node` is expected to be an
/// instance of [ClassDeclaration] (a class which may have a [Directive] or /// instance of [ClassDeclaration] (a class which may have a [Directive] or