Skip to content

Commit 24646e7

Browse files
dariajungrkirov
authored andcommitted
feat(typings): add typing specs
add test in gulpfile which will compile a basic TS file with generated angular2.d.ts to ensure generated d.ts is valid syntactic TS Adds support for enums in .d.ts generation pipeline. Removes renaming reexports in http module.
1 parent 6149ce2 commit 24646e7

File tree

13 files changed

+102
-19
lines changed

13 files changed

+102
-19
lines changed

docs/dgeni-package/processors/createTypeDefinitionFile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function createTypeDefinitionFile() {
1010
id: 'type-definition',
1111
aliases: ['type-definition'],
1212
path: 'type-definition',
13-
outputPath: 'angular2.d.ts',
13+
outputPath: 'typings/angular2/angular2.d.ts',
1414
modules: []
1515
};
1616
_.forEach(docs, function(doc) {

docs/dgeni-package/processors/readTypeScriptModules.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
9191
}
9292
}
9393

94+
if (exportDoc.docType == 'enum') {
95+
exportDoc.members = [];
96+
for (var etype in resolvedExport.exports) {
97+
exportDoc.members.push(etype);
98+
}
99+
}
100+
94101
// Add this export doc to its module doc
95102
moduleDoc.exports.push(exportDoc);
96103
docs.push(exportDoc);
@@ -165,6 +172,7 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
165172
fileInfo: getFileInfo(exportSymbol, basePath),
166173
location: getLocation(exportSymbol)
167174
};
175+
168176
if(exportSymbol.flags & ts.SymbolFlags.Function) {
169177
exportDoc.parameters = getParameters(typeChecker, exportSymbol);
170178
}
@@ -290,4 +298,4 @@ function anyMatches(regexes, item) {
290298
if ( item.match(regexes[i]) ) return true;
291299
}
292300
return false;
293-
}
301+
}

docs/dgeni-package/templates/type-definition.template.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@
5757
;
5858
{%- endfor %}
5959
}
60+
61+
{%- elif export.docType == 'enum' %} {
62+
{%- for member in export.members %}
63+
{$ member $}{% if not loop.last %},
64+
{%- endif -%}
65+
{%- endfor %}
66+
}
67+
6068
{%- else -%}
6169
{% if export.parameters %}({% for param in export.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif %}
6270
{%- if export.returnType %} : {$ export.returnType $} {% endif -%}

gulpfile.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ function runKarma(configFile, done) {
389389

390390
gulp.task('test.js', function(done) {
391391
runSequence('test.unit.tools/ci', 'test.transpiler.unittest', 'docs/test', 'test.unit.js/ci',
392-
'test.unit.cjs/ci', sequenceComplete(done));
392+
'test.unit.cjs/ci', 'test.typings', sequenceComplete(done));
393393
});
394394

395395
gulp.task('test.dart', function(done) {
@@ -559,20 +559,43 @@ gulp.task('test.transpiler.unittest', function(done) {
559559
runJasmineTests(['tools/transpiler/unittest/**/*.js'], done);
560560
});
561561

562-
563562
// -----------------
564563
// Pre/Post-test checks
565564

566565
gulp.task('pre-test-checks', function(done) {
567566
runSequence('build/checkCircularDependencies', sequenceComplete(done));
568567
});
569568

570-
571569
gulp.task('post-test-checks', function(done) {
572570
runSequence('enforce-format', sequenceComplete(done));
573571
});
574572

575573

574+
gulp.task('!pre.test.typings', [], function(done) {
575+
return gulp
576+
.src([
577+
'modules/angular2/typings/**/*'], {
578+
base: 'modules/angular2/typings/**'
579+
}
580+
)
581+
.pipe(gulp.dest('dist/docs/typings/*'));
582+
});
583+
584+
// -----------------
585+
// TODO: Use a version of TypeScript that matches what is used by DefinitelyTyped.
586+
gulp.task('test.typings', ['!pre.test.typings'], function(done) {
587+
var stream = gulp.src(['typings_spec/*.ts', 'dist/docs/typings/angular2/angular2.d.ts'])
588+
.pipe(tsc({target: 'ES5', module: 'commonjs',
589+
// Don't use the version of typescript that gulp-typescript depends on, we need 1.5
590+
// see https://github.com/ivogabe/gulp-typescript#typescript-version
591+
typescript: require('typescript')}))
592+
.on('error', function(error) {
593+
// nodejs doesn't propagate errors from the src stream into the final stream so we are
594+
// forwarding the error into the final stream
595+
stream.emit('error', error);
596+
});
597+
});
598+
576599
// -----------------
577600
// orchestrated targets
578601

modules/angular2/angular2.api.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ export * from './angular2';
1111
// 1) if the symbol is intended to be part of the public API, then re-export somewhere else
1212
// 2) if the symbol should be omitted from the public API, then the class exposing it should
1313
// not be exported, or should avoid exposing the symbol.
14-
export {AbstractChangeDetector} from './src/change_detection/abstract_change_detector';
15-
export {ProtoRecord} from './src/change_detection/proto_record';
14+
export {ProtoRecord, RecordType} from './src/change_detection/proto_record';
1615
export * from './src/core/compiler/element_injector';
16+
export {DependencyAnnotation} from './src/di/annotations_impl';
1717
// FIXME: this is a workaround for https://github.com/angular/angular/issues/2356
1818
// We export the Directive *annotation* instead of the *decorator*.
1919
// But it breaks the build.
2020
export {Directive, LifecycleEvent} from './src/core/annotations_impl/annotations';
2121
export {Form} from './src/forms/directives/form_interface';
22+
export {TypeDecorator, ClassDefinition} from './src/util/decorators';
23+
export {Query} from './src/core/annotations_impl/di';
2224
export {ControlContainer} from './src/forms/directives/control_container';
2325
export {Injectable} from './src/di/annotations_impl';
2426
export {BaseQueryList} from './src/core/compiler/base_query_list';

modules/angular2/angular2.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ export {
1717
JitChangeDetection,
1818
PreGeneratedChangeDetection,
1919
preGeneratedProtoDetectors,
20-
defaultPipeRegistry
20+
defaultPipeRegistry,
21+
DirectiveIndex,
22+
BindingRecord,
23+
ProtoChangeDetector,
24+
ChangeDispatcher,
25+
ChangeDetector,
26+
Locals,
27+
ChangeDetectorDefinition,
28+
BasePipe,
29+
DirectiveRecord
2130
} from './change_detection';
2231

2332
export {
@@ -40,7 +49,10 @@ export {
4049
InstantiationError,
4150
InvalidBindingError,
4251
NoAnnotationError,
43-
OpaqueToken
52+
OpaqueToken,
53+
ResolvedBinding,
54+
BindingBuilder,
55+
Dependency
4456
} from './di';
4557

4658
export * from './core';

modules/angular2/change_detection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export {DynamicChangeDetector} from './src/change_detection/dynamic_change_detec
4545
export {ChangeDetectorRef} from './src/change_detection/change_detector_ref';
4646
export {PipeRegistry} from './src/change_detection/pipes/pipe_registry';
4747
export {uninitialized} from './src/change_detection/change_detection_util';
48-
export {WrappedValue, Pipe, PipeFactory} from './src/change_detection/pipes/pipe';
48+
export {WrappedValue, Pipe, PipeFactory, BasePipe} from './src/change_detection/pipes/pipe';
4949
export {NullPipe, NullPipeFactory} from './src/change_detection/pipes/null_pipe';
5050
export {
5151
defaultPipes,

modules/angular2/http.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,19 @@ export {Request} from 'angular2/src/http/static_request';
1616
export {Response} from 'angular2/src/http/static_response';
1717

1818
export {Http, XHRBackend, XHRConnection, BaseRequestOptions, RequestOptions, HttpFactory};
19-
export {IHttp} from 'angular2/src/http/interfaces';
19+
export {
20+
IHttp,
21+
IRequestOptions,
22+
IRequest,
23+
IResponse,
24+
Connection,
25+
ConnectionBackend
26+
} from 'angular2/src/http/interfaces';
2027
export {Headers} from 'angular2/src/http/headers';
2128

29+
export * from 'angular2/src/http/enums';
30+
export {URLSearchParams} from 'angular2/src/http/url_search_params';
31+
2232
/**
2333
* Provides a basic set of injectables to use the {@link Http} service in any application.
2434
*

modules/angular2/src/http/interfaces.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface IRequestOptions {
2020
cache?: RequestCacheOpts;
2121
}
2222

23-
export interface Request {
23+
export interface IRequest {
2424
method: RequestMethods;
2525
mode: RequestModesOpts;
2626
credentials: RequestCredentialsOpts;
@@ -34,7 +34,7 @@ export interface ResponseOptions {
3434
url?: string;
3535
}
3636

37-
export interface Response {
37+
export interface IResponse {
3838
headers: Headers;
3939
ok: boolean;
4040
status: number;
@@ -49,12 +49,14 @@ export interface Response {
4949
json(): Object;
5050
}
5151

52-
export interface ConnectionBackend { createConnection(observer: any, config: Request): Connection; }
52+
export interface ConnectionBackend {
53+
createConnection(observer: any, config: IRequest): Connection;
54+
}
5355

5456
export interface Connection {
5557
readyState: ReadyStates;
56-
request: Request;
57-
response: Rx.Subject<Response>;
58+
request: IRequest;
59+
response: Rx.Subject<IResponse>;
5860
dispose(): void;
5961
}
6062

@@ -81,4 +83,4 @@ export interface Connection {
8183
*/
8284
// Prefixed as IHttp because used in conjunction with Http class, but interface is callable
8385
// constructor(@Inject(Http) http:IHttp)
84-
export interface IHttp { (url: string, options?: IRequestOptions): Rx.Observable<Response> }
86+
export interface IHttp { (url: string, options?: IRequestOptions): Rx.Observable<IResponse> }

modules/angular2/src/http/static_request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {RequestMethods, RequestModesOpts, RequestCredentialsOpts} from './enums';
22
import {URLSearchParams} from './url_search_params';
3-
import {IRequestOptions, Request as IRequest} from './interfaces';
3+
import {IRequestOptions, IRequest} from './interfaces';
44
import {Headers} from './headers';
55
import {BaseException, RegExpWrapper} from 'angular2/src/facade/lang';
66

modules/angular2/src/http/static_response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Response as IResponse, ResponseOptions} from './interfaces';
1+
import {IResponse, ResponseOptions} from './interfaces';
22
import {ResponseTypes} from './enums';
33
import {baseResponseOptions} from './base_response_options';
44
import {BaseException, isJsObject, isString, global} from 'angular2/src/facade/lang';

typing_spec/basic_spec.dart

Whitespace-only changes.

typing_spec/basic_spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
///<reference path="../dist/docs/angular2.d.ts"/>
2+
3+
import {Component, bootstrap, View} from 'angular2/angular2'
4+
5+
@Component({
6+
selector: 'my-app'
7+
})
8+
@View({
9+
template: '<h1>Hello {{ name }}</h1>'
10+
})
11+
// Component controller
12+
class MyAppComponent {
13+
name: string;
14+
15+
constructor() { this.name = 'Alice'; }
16+
}
17+
18+
bootstrap(MyAppComponent);

0 commit comments

Comments
 (0)