Skip to content

Commit 1926335

Browse files
committed
fix(Typings): Output public constructors in .d.ts files
Closes angular#3926. Closes angular#3963
1 parent 12dd44f commit 1926335

File tree

24 files changed

+136
-41
lines changed

24 files changed

+136
-41
lines changed

docs/typescript-definition-package/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
5252
id: 'angular2/angular2',
5353
references: ['../es6-promise/es6-promise.d.ts', '../rx/rx.d.ts'],
5454
modules: {
55-
'angular2/angular2': {namespace: 'ng', id: 'angular2/angular2'}
56-
/* TODO(jeffbcross): re-implement with @jteplitz as part of #3926,
55+
'angular2/angular2': {namespace: 'ng', id: 'angular2/angular2'},
5756
'angular2/web_worker/worker': {namespace: 'ngWorker', id: 'angular2/web_worker/worker'},
5857
'angular2/web_worker/ui': {namespace: 'ngUi', id: 'angular2/web_worker/ui'}
59-
*/
6058
}
6159
},
6260
{

docs/typescript-definition-package/processors/code_gen.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function DtsSerializer(remap) {
55
}
66

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

910
constructor: DtsSerializer,
1011

@@ -18,15 +19,21 @@ DtsSerializer.prototype = {
1819
}
1920
if (ast.parameters) {
2021
buffer.push('(');
21-
buffer.push(ast.parameters.join(', '));
22+
var parameters = ast.parameters;
23+
for (var i = 0; i < parameters.length; i++) {
24+
parameters[i] = parameters[i].replace(this._initializerRegex, '');
25+
}
26+
buffer.push(parameters.join(', '));
2227
buffer.push(')');
2328
}
24-
if (ast.returnType) {
25-
buffer.push(': ', ast.returnType);
26-
} else if (ast.parameters) {
27-
buffer.push(': void');
28-
} else {
29-
buffer.push(': any');
29+
if (!isConstructor(ast)) {
30+
if (ast.returnType) {
31+
buffer.push(': ', ast.returnType);
32+
} else if (ast.parameters) {
33+
buffer.push(': void');
34+
} else {
35+
buffer.push(': any');
36+
}
3037
}
3138
buffer.push(';\n');
3239
},
@@ -58,6 +65,7 @@ DtsSerializer.prototype = {
5865
buffer.indent();
5966
if (ast.newMember) this.member(buffer, ast.newMember);
6067
if (ast.callMember) this.member(buffer, ast.callMember);
68+
if (ast.constructorDoc) this.member(buffer, ast.constructorDoc);
6169

6270
ast.statics.forEach(function(staticMember) {
6371
this.member(buffer, staticMember);
@@ -144,7 +152,6 @@ DtsSerializer.prototype = {
144152
}
145153
};
146154

147-
148155
function Buffer() {
149156
this._globalBuffer = [];
150157
this._indentedBuffer = [];
@@ -191,7 +198,11 @@ Buffer.prototype = {
191198
}
192199
};
193200

201+
function isConstructor(ast) {
202+
return ast.parameters && ast.name === "constructor";
203+
}
194204

195205
module.exports = {
196206
DtsSerializer: DtsSerializer
197207
};
208+

docs/typescript-package/processors/readTypeScriptModules.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
150150
function createExportDoc(name, exportSymbol, moduleDoc, basePath, typeChecker) {
151151
var typeParamString = '';
152152
var heritageString = '';
153+
var typeDefinition = '';
153154

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

162+
if (decl.symbol.flags & ts.SymbolFlags.TypeAlias) {
163+
typeDefinition = getText(sourceFile, decl.type);
164+
}
165+
161166
if (decl.heritageClauses) {
162167
decl.heritageClauses.forEach(function(heritage) {
163168

@@ -215,6 +220,9 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
215220
if(exportSymbol.flags & ts.SymbolFlags.Value) {
216221
exportDoc.returnType = getReturnType(typeChecker, exportSymbol);
217222
}
223+
if (exportSymbol.flags & ts.SymbolFlags.TypeAlias) {
224+
exportDoc.typeDefinition = typeDefinition;
225+
}
218226
return exportDoc;
219227
}
220228

modules/angular2/angular2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './core';
22
export * from './profile';
33
export * from './lifecycle_hooks';
4-
export * from './bootstrap';
4+
export * from './bootstrap';

modules/angular2/core.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ export * from './src/core/directives';
1818
export * from './src/core/forms';
1919
export * from './src/core/debug';
2020
export * from './src/core/change_detection';
21+
export {Reflector, ReflectionInfo} from './src/core/reflection/reflection';
22+
export {
23+
PlatformReflectionCapabilities
24+
} from './src/core/reflection/platform_reflection_capabilities';
25+
export {SetterFn, GetterFn, MethodFn} from './src/core/reflection/types';

modules/angular2/http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export {BaseRequestOptions, RequestOptions} from './src/http/base_request_option
3030
export {BaseResponseOptions, ResponseOptions} from './src/http/base_response_options';
3131
export {XHRBackend, XHRConnection} from './src/http/backends/xhr_backend';
3232
export {JSONPBackend, JSONPConnection} from './src/http/backends/jsonp_backend';
33+
export {BrowserJsonp} from './src/http/backends/browser_jsonp';
3334
export {Http, Jsonp} from './src/http/http';
3435

3536
export {Headers} from './src/http/headers';

modules/angular2/router.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,47 @@
77

88
export {Router, RootRouter} from './src/router/router';
99
export {RouterOutlet} from './src/router/router_outlet';
10+
export {
11+
DynamicComponentLoader,
12+
ComponentRef,
13+
ElementRef,
14+
Compiler,
15+
AppViewManager,
16+
ViewRef,
17+
HostViewRef,
18+
ProtoViewRef,
19+
ViewContainerRef,
20+
TemplateRef
21+
} from './core';
22+
export {
23+
Renderer,
24+
RenderElementRef,
25+
RenderViewRef,
26+
RenderProtoViewRef,
27+
RenderEventDispatcher,
28+
RenderFragmentRef,
29+
RenderViewWithFragments
30+
} from './render';
31+
export {
32+
Binding,
33+
Injector,
34+
ResolvedBinding,
35+
Key,
36+
Dependency,
37+
ProtoInjector,
38+
DependencyProvider,
39+
BindingWithVisibility,
40+
Visibility,
41+
ResolvedFactory
42+
} from './src/core/di';
1043
export {RouterLink} from './src/router/router_link';
1144
export {RouteParams} from './src/router/instruction';
1245
export {RouteRegistry} from './src/router/route_registry';
1346
export {LocationStrategy} from './src/router/location_strategy';
1447
export {HashLocationStrategy} from './src/router/hash_location_strategy';
1548
export {PathLocationStrategy} from './src/router/path_location_strategy';
49+
export {PathRecognizer, PathMatch} from './src/router/path_recognizer';
50+
export {RouteHandler} from './src/router/route_handler';
1651
export {Location, APP_BASE_HREF} from './src/router/location';
1752
export {Pipeline} from './src/router/pipeline';
1853
export * from './src/router/route_config_decorator';
@@ -73,6 +108,8 @@ export const ROUTER_BINDINGS: any[] = CONST_EXPR([
73108
}))
74109
]);
75110

111+
export interface InjectableReference {}
112+
76113
function routerFactory(registry, pipeline, location, appRoot) {
77114
return new RootRouter(registry, pipeline, location, appRoot);
78115
}

modules/angular2/src/core/change_detection.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export {
2222
IterableDifferFactory,
2323
KeyValueDiffers,
2424
KeyValueDiffer,
25-
KeyValueDifferFactory
26-
27-
} from './change_detection/change_detection';
25+
KeyValueDifferFactory,
26+
Lexer,
27+
Parser,
28+
ChangeDispatcher,
29+
BindingTarget,
30+
DirectiveIndex,
31+
DebugContext,
32+
ProtoChangeDetector
33+
} from 'angular2/src/core/change_detection/change_detection';
34+
export * from 'angular2/src/core/change_detection/parser/ast';

modules/angular2/src/core/change_detection/change_detection.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ import {
2121
assertionsEnabled
2222
} from 'angular2/src/core/facade/lang';
2323

24-
export {
25-
ASTWithSource,
26-
AST,
27-
AstTransformer,
28-
PropertyRead,
29-
LiteralArray,
30-
ImplicitReceiver
31-
} from './parser/ast';
24+
export * from './parser/ast';
3225

3326
export {Lexer} from './parser/lexer';
3427
export {Parser} from './parser/parser';

modules/angular2/src/core/compiler.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ export {ElementRef} from './compiler/element_ref';
1919
export {TemplateRef} from './compiler/template_ref';
2020
export {ViewRef, HostViewRef, ProtoViewRef} from './compiler/view_ref';
2121
export {ViewContainerRef} from './compiler/view_container_ref';
22+
export {AppView, AppProtoView, AppProtoViewMergeMapping, AppViewContainer} from './compiler/view';
2223
export {ComponentRef} from './compiler/dynamic_component_loader';
24+
export {
25+
ElementInjector,
26+
PreBuiltObjects,
27+
TreeNode,
28+
ProtoElementInjector,
29+
DirectiveBinding,
30+
EventEmitterAccessor
31+
} from './compiler/element_injector';
32+
export {ElementBinder} from './compiler/element_binder';

0 commit comments

Comments
 (0)