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.
This commit is contained in:
parent
6149ce28a7
commit
24646e7eb8
|
@ -10,7 +10,7 @@ module.exports = function createTypeDefinitionFile() {
|
||||||
id: 'type-definition',
|
id: 'type-definition',
|
||||||
aliases: ['type-definition'],
|
aliases: ['type-definition'],
|
||||||
path: 'type-definition',
|
path: 'type-definition',
|
||||||
outputPath: 'angular2.d.ts',
|
outputPath: 'typings/angular2/angular2.d.ts',
|
||||||
modules: []
|
modules: []
|
||||||
};
|
};
|
||||||
_.forEach(docs, function(doc) {
|
_.forEach(docs, function(doc) {
|
||||||
|
|
|
@ -91,6 +91,13 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exportDoc.docType == 'enum') {
|
||||||
|
exportDoc.members = [];
|
||||||
|
for (var etype in resolvedExport.exports) {
|
||||||
|
exportDoc.members.push(etype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add this export doc to its module doc
|
// Add this export doc to its module doc
|
||||||
moduleDoc.exports.push(exportDoc);
|
moduleDoc.exports.push(exportDoc);
|
||||||
docs.push(exportDoc);
|
docs.push(exportDoc);
|
||||||
|
@ -165,6 +172,7 @@ module.exports = function readTypeScriptModules(tsParser, readFilesProcessor, mo
|
||||||
fileInfo: getFileInfo(exportSymbol, basePath),
|
fileInfo: getFileInfo(exportSymbol, basePath),
|
||||||
location: getLocation(exportSymbol)
|
location: getLocation(exportSymbol)
|
||||||
};
|
};
|
||||||
|
|
||||||
if(exportSymbol.flags & ts.SymbolFlags.Function) {
|
if(exportSymbol.flags & ts.SymbolFlags.Function) {
|
||||||
exportDoc.parameters = getParameters(typeChecker, exportSymbol);
|
exportDoc.parameters = getParameters(typeChecker, exportSymbol);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,14 @@ declare module "{$ module.id $}" {
|
||||||
;
|
;
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{%- elif export.docType == 'enum' %} {
|
||||||
|
{%- for member in export.members %}
|
||||||
|
{$ member $}{% if not loop.last %},
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endfor %}
|
||||||
|
}
|
||||||
|
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{% if export.parameters %}({% for param in export.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif %}
|
{% if export.parameters %}({% for param in export.parameters %}{$ param $}{% if not loop.last %}, {% endif %}{% endfor %}){%- endif %}
|
||||||
{%- if export.returnType %} : {$ export.returnType $} {% endif -%}
|
{%- if export.returnType %} : {$ export.returnType $} {% endif -%}
|
||||||
|
|
29
gulpfile.js
29
gulpfile.js
|
@ -389,7 +389,7 @@ function runKarma(configFile, done) {
|
||||||
|
|
||||||
gulp.task('test.js', function(done) {
|
gulp.task('test.js', function(done) {
|
||||||
runSequence('test.unit.tools/ci', 'test.transpiler.unittest', 'docs/test', 'test.unit.js/ci',
|
runSequence('test.unit.tools/ci', 'test.transpiler.unittest', 'docs/test', 'test.unit.js/ci',
|
||||||
'test.unit.cjs/ci', sequenceComplete(done));
|
'test.unit.cjs/ci', 'test.typings', sequenceComplete(done));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test.dart', function(done) {
|
gulp.task('test.dart', function(done) {
|
||||||
|
@ -559,7 +559,6 @@ gulp.task('test.transpiler.unittest', function(done) {
|
||||||
runJasmineTests(['tools/transpiler/unittest/**/*.js'], done);
|
runJasmineTests(['tools/transpiler/unittest/**/*.js'], done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// Pre/Post-test checks
|
// Pre/Post-test checks
|
||||||
|
|
||||||
|
@ -567,12 +566,36 @@ gulp.task('pre-test-checks', function(done) {
|
||||||
runSequence('build/checkCircularDependencies', sequenceComplete(done));
|
runSequence('build/checkCircularDependencies', sequenceComplete(done));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
gulp.task('post-test-checks', function(done) {
|
gulp.task('post-test-checks', function(done) {
|
||||||
runSequence('enforce-format', sequenceComplete(done));
|
runSequence('enforce-format', sequenceComplete(done));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
gulp.task('!pre.test.typings', [], function(done) {
|
||||||
|
return gulp
|
||||||
|
.src([
|
||||||
|
'modules/angular2/typings/**/*'], {
|
||||||
|
base: 'modules/angular2/typings/**'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.pipe(gulp.dest('dist/docs/typings/*'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// -----------------
|
||||||
|
// TODO: Use a version of TypeScript that matches what is used by DefinitelyTyped.
|
||||||
|
gulp.task('test.typings', ['!pre.test.typings'], function(done) {
|
||||||
|
var stream = gulp.src(['typings_spec/*.ts', 'dist/docs/typings/angular2/angular2.d.ts'])
|
||||||
|
.pipe(tsc({target: 'ES5', module: 'commonjs',
|
||||||
|
// Don't use the version of typescript that gulp-typescript depends on, we need 1.5
|
||||||
|
// see https://github.com/ivogabe/gulp-typescript#typescript-version
|
||||||
|
typescript: require('typescript')}))
|
||||||
|
.on('error', function(error) {
|
||||||
|
// nodejs doesn't propagate errors from the src stream into the final stream so we are
|
||||||
|
// forwarding the error into the final stream
|
||||||
|
stream.emit('error', error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// orchestrated targets
|
// orchestrated targets
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,16 @@ export * from './angular2';
|
||||||
// 1) if the symbol is intended to be part of the public API, then re-export somewhere else
|
// 1) if the symbol is intended to be part of the public API, then re-export somewhere else
|
||||||
// 2) if the symbol should be omitted from the public API, then the class exposing it should
|
// 2) if the symbol should be omitted from the public API, then the class exposing it should
|
||||||
// not be exported, or should avoid exposing the symbol.
|
// not be exported, or should avoid exposing the symbol.
|
||||||
export {AbstractChangeDetector} from './src/change_detection/abstract_change_detector';
|
export {ProtoRecord, RecordType} from './src/change_detection/proto_record';
|
||||||
export {ProtoRecord} from './src/change_detection/proto_record';
|
|
||||||
export * from './src/core/compiler/element_injector';
|
export * from './src/core/compiler/element_injector';
|
||||||
|
export {DependencyAnnotation} from './src/di/annotations_impl';
|
||||||
// FIXME: this is a workaround for https://github.com/angular/angular/issues/2356
|
// FIXME: this is a workaround for https://github.com/angular/angular/issues/2356
|
||||||
// We export the Directive *annotation* instead of the *decorator*.
|
// We export the Directive *annotation* instead of the *decorator*.
|
||||||
// But it breaks the build.
|
// But it breaks the build.
|
||||||
export {Directive, LifecycleEvent} from './src/core/annotations_impl/annotations';
|
export {Directive, LifecycleEvent} from './src/core/annotations_impl/annotations';
|
||||||
export {Form} from './src/forms/directives/form_interface';
|
export {Form} from './src/forms/directives/form_interface';
|
||||||
|
export {TypeDecorator, ClassDefinition} from './src/util/decorators';
|
||||||
|
export {Query} from './src/core/annotations_impl/di';
|
||||||
export {ControlContainer} from './src/forms/directives/control_container';
|
export {ControlContainer} from './src/forms/directives/control_container';
|
||||||
export {Injectable} from './src/di/annotations_impl';
|
export {Injectable} from './src/di/annotations_impl';
|
||||||
export {BaseQueryList} from './src/core/compiler/base_query_list';
|
export {BaseQueryList} from './src/core/compiler/base_query_list';
|
||||||
|
|
|
@ -17,7 +17,16 @@ export {
|
||||||
JitChangeDetection,
|
JitChangeDetection,
|
||||||
PreGeneratedChangeDetection,
|
PreGeneratedChangeDetection,
|
||||||
preGeneratedProtoDetectors,
|
preGeneratedProtoDetectors,
|
||||||
defaultPipeRegistry
|
defaultPipeRegistry,
|
||||||
|
DirectiveIndex,
|
||||||
|
BindingRecord,
|
||||||
|
ProtoChangeDetector,
|
||||||
|
ChangeDispatcher,
|
||||||
|
ChangeDetector,
|
||||||
|
Locals,
|
||||||
|
ChangeDetectorDefinition,
|
||||||
|
BasePipe,
|
||||||
|
DirectiveRecord
|
||||||
} from './change_detection';
|
} from './change_detection';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -40,7 +49,10 @@ export {
|
||||||
InstantiationError,
|
InstantiationError,
|
||||||
InvalidBindingError,
|
InvalidBindingError,
|
||||||
NoAnnotationError,
|
NoAnnotationError,
|
||||||
OpaqueToken
|
OpaqueToken,
|
||||||
|
ResolvedBinding,
|
||||||
|
BindingBuilder,
|
||||||
|
Dependency
|
||||||
} from './di';
|
} from './di';
|
||||||
|
|
||||||
export * from './core';
|
export * from './core';
|
||||||
|
|
|
@ -45,7 +45,7 @@ export {DynamicChangeDetector} from './src/change_detection/dynamic_change_detec
|
||||||
export {ChangeDetectorRef} from './src/change_detection/change_detector_ref';
|
export {ChangeDetectorRef} from './src/change_detection/change_detector_ref';
|
||||||
export {PipeRegistry} from './src/change_detection/pipes/pipe_registry';
|
export {PipeRegistry} from './src/change_detection/pipes/pipe_registry';
|
||||||
export {uninitialized} from './src/change_detection/change_detection_util';
|
export {uninitialized} from './src/change_detection/change_detection_util';
|
||||||
export {WrappedValue, Pipe, PipeFactory} from './src/change_detection/pipes/pipe';
|
export {WrappedValue, Pipe, PipeFactory, BasePipe} from './src/change_detection/pipes/pipe';
|
||||||
export {NullPipe, NullPipeFactory} from './src/change_detection/pipes/null_pipe';
|
export {NullPipe, NullPipeFactory} from './src/change_detection/pipes/null_pipe';
|
||||||
export {
|
export {
|
||||||
defaultPipes,
|
defaultPipes,
|
||||||
|
|
|
@ -16,9 +16,19 @@ export {Request} from 'angular2/src/http/static_request';
|
||||||
export {Response} from 'angular2/src/http/static_response';
|
export {Response} from 'angular2/src/http/static_response';
|
||||||
|
|
||||||
export {Http, XHRBackend, XHRConnection, BaseRequestOptions, RequestOptions, HttpFactory};
|
export {Http, XHRBackend, XHRConnection, BaseRequestOptions, RequestOptions, HttpFactory};
|
||||||
export {IHttp} from 'angular2/src/http/interfaces';
|
export {
|
||||||
|
IHttp,
|
||||||
|
IRequestOptions,
|
||||||
|
IRequest,
|
||||||
|
IResponse,
|
||||||
|
Connection,
|
||||||
|
ConnectionBackend
|
||||||
|
} from 'angular2/src/http/interfaces';
|
||||||
export {Headers} from 'angular2/src/http/headers';
|
export {Headers} from 'angular2/src/http/headers';
|
||||||
|
|
||||||
|
export * from 'angular2/src/http/enums';
|
||||||
|
export {URLSearchParams} from 'angular2/src/http/url_search_params';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a basic set of injectables to use the {@link Http} service in any application.
|
* Provides a basic set of injectables to use the {@link Http} service in any application.
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,7 +20,7 @@ export interface IRequestOptions {
|
||||||
cache?: RequestCacheOpts;
|
cache?: RequestCacheOpts;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Request {
|
export interface IRequest {
|
||||||
method: RequestMethods;
|
method: RequestMethods;
|
||||||
mode: RequestModesOpts;
|
mode: RequestModesOpts;
|
||||||
credentials: RequestCredentialsOpts;
|
credentials: RequestCredentialsOpts;
|
||||||
|
@ -34,7 +34,7 @@ export interface ResponseOptions {
|
||||||
url?: string;
|
url?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Response {
|
export interface IResponse {
|
||||||
headers: Headers;
|
headers: Headers;
|
||||||
ok: boolean;
|
ok: boolean;
|
||||||
status: number;
|
status: number;
|
||||||
|
@ -49,12 +49,14 @@ export interface Response {
|
||||||
json(): Object;
|
json(): Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConnectionBackend { createConnection(observer: any, config: Request): Connection; }
|
export interface ConnectionBackend {
|
||||||
|
createConnection(observer: any, config: IRequest): Connection;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Connection {
|
export interface Connection {
|
||||||
readyState: ReadyStates;
|
readyState: ReadyStates;
|
||||||
request: Request;
|
request: IRequest;
|
||||||
response: Rx.Subject<Response>;
|
response: Rx.Subject<IResponse>;
|
||||||
dispose(): void;
|
dispose(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,4 +83,4 @@ export interface Connection {
|
||||||
*/
|
*/
|
||||||
// Prefixed as IHttp because used in conjunction with Http class, but interface is callable
|
// Prefixed as IHttp because used in conjunction with Http class, but interface is callable
|
||||||
// constructor(@Inject(Http) http:IHttp)
|
// constructor(@Inject(Http) http:IHttp)
|
||||||
export interface IHttp { (url: string, options?: IRequestOptions): Rx.Observable<Response> }
|
export interface IHttp { (url: string, options?: IRequestOptions): Rx.Observable<IResponse> }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {RequestMethods, RequestModesOpts, RequestCredentialsOpts} from './enums';
|
import {RequestMethods, RequestModesOpts, RequestCredentialsOpts} from './enums';
|
||||||
import {URLSearchParams} from './url_search_params';
|
import {URLSearchParams} from './url_search_params';
|
||||||
import {IRequestOptions, Request as IRequest} from './interfaces';
|
import {IRequestOptions, IRequest} from './interfaces';
|
||||||
import {Headers} from './headers';
|
import {Headers} from './headers';
|
||||||
import {BaseException, RegExpWrapper} from 'angular2/src/facade/lang';
|
import {BaseException, RegExpWrapper} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Response as IResponse, ResponseOptions} from './interfaces';
|
import {IResponse, ResponseOptions} from './interfaces';
|
||||||
import {ResponseTypes} from './enums';
|
import {ResponseTypes} from './enums';
|
||||||
import {baseResponseOptions} from './base_response_options';
|
import {baseResponseOptions} from './base_response_options';
|
||||||
import {BaseException, isJsObject, isString, global} from 'angular2/src/facade/lang';
|
import {BaseException, isJsObject, isString, global} from 'angular2/src/facade/lang';
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
///<reference path="../dist/docs/angular2.d.ts"/>
|
||||||
|
|
||||||
|
import {Component, bootstrap, View} from 'angular2/angular2'
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'my-app'
|
||||||
|
})
|
||||||
|
@View({
|
||||||
|
template: '<h1>Hello {{ name }}</h1>'
|
||||||
|
})
|
||||||
|
// Component controller
|
||||||
|
class MyAppComponent {
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
constructor() { this.name = 'Alice'; }
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap(MyAppComponent);
|
Loading…
Reference in New Issue