Skip to content

Commit e3064d5

Browse files
IgorMinarmhevery
authored andcommitted
feat: typescript 2.9 support (angular#24652)
PR Close angular#24652
1 parent 0c3738a commit e3064d5

File tree

38 files changed

+293
-204
lines changed

38 files changed

+293
-204
lines changed

Diff for: WORKSPACE

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ http_archive(
2020

2121
http_archive(
2222
name = "build_bazel_rules_typescript",
23-
url = "https://github.com/bazelbuild/rules_typescript/archive/7c49a0943e7ccca73bee0b8fc5f01ca2c3dcfe8b.zip",
24-
strip_prefix = "rules_typescript-7c49a0943e7ccca73bee0b8fc5f01ca2c3dcfe8b",
25-
sha256 = "9707cdafc0e59f06cf5336b1c68d8f3d04fae9f3471c0eb205a669b8b5fafc81",
23+
url = "https://github.com/rkirov/rules_typescript/archive/v0.16.0.zip",
24+
strip_prefix = "rules_typescript-0.16.0",
25+
sha256 = "f5aedd3a792e5af19cd0c0f0318cb692e2989e816e896e794152d07808fccacd",
2626
)
2727

2828
http_archive(

Diff for: integration/typings_test_ts29/include-all.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import * as compiler from '@angular/compiler';
10+
import * as compilerTesting from '@angular/compiler/testing';
11+
import * as core from '@angular/core';
12+
import * as coreTesting from '@angular/core/testing';
13+
import * as elements from '@angular/elements';
14+
import * as forms from '@angular/forms';
15+
import * as http from '@angular/http';
16+
import * as httpTesting from '@angular/http/testing';
17+
import * as platformBrowser from '@angular/platform-browser';
18+
import * as platformBrowserTesting from '@angular/platform-browser/testing';
19+
import * as platformBrowserDynamic from '@angular/platform-browser-dynamic';
20+
import * as platformServer from '@angular/platform-server';
21+
import * as platformServerTesting from '@angular/platform-server/testing';
22+
import * as platformWebworker from '@angular/platform-webworker';
23+
import * as platformWebworkerDynamic from '@angular/platform-webworker-dynamic';
24+
import * as router from '@angular/router';
25+
import * as routerTesting from '@angular/router/testing';
26+
import * as serviceWorker from '@angular/service-worker';
27+
import * as upgrade from '@angular/upgrade';
28+
29+
export default {
30+
compiler,
31+
compilerTesting,
32+
core,
33+
coreTesting,
34+
elements,
35+
forms,
36+
http,
37+
httpTesting,
38+
platformBrowser,
39+
platformBrowserTesting,
40+
platformBrowserDynamic,
41+
platformServer,
42+
platformServerTesting,
43+
platformWebworker,
44+
platformWebworkerDynamic,
45+
router,
46+
routerTesting,
47+
serviceWorker,
48+
upgrade,
49+
};

Diff for: integration/typings_test_ts29/package.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "angular-integration",
3+
"description": "Assert that users with TypeScript 2.8 can type-check an Angular application",
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"dependencies": {
7+
"@angular/animations": "file:../../dist/packages-dist/animations",
8+
"@angular/common": "file:../../dist/packages-dist/common",
9+
"@angular/compiler": "file:../../dist/packages-dist/compiler",
10+
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
11+
"@angular/core": "file:../../dist/packages-dist/core",
12+
"@angular/elements": "file:../../dist/packages-dist/elements",
13+
"@angular/forms": "file:../../dist/packages-dist/forms",
14+
"@angular/http": "file:../../dist/packages-dist/http",
15+
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
16+
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
17+
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
18+
"@angular/platform-webworker": "file:../../dist/packages-dist/platform-webworker",
19+
"@angular/platform-webworker-dynamic": "file:../../dist/packages-dist/platform-webworker-dynamic",
20+
"@angular/router": "file:../../dist/packages-dist/router",
21+
"@angular/service-worker": "file:../../dist/packages-dist/service-worker",
22+
"@angular/upgrade": "file:../../dist/packages-dist/upgrade",
23+
"@types/jasmine": "2.5.41",
24+
"rxjs": "file:../../node_modules/rxjs",
25+
"typescript": "2.8.x",
26+
"zone.js": "file:../../node_modules/zone.js"
27+
},
28+
"scripts": {
29+
"test": "tsc"
30+
}
31+
}

Diff for: integration/typings_test_ts29/tsconfig.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"emitDecoratorMetadata": true,
4+
"experimentalDecorators": true,
5+
"module": "commonjs",
6+
"moduleResolution": "node",
7+
"outDir": "../../dist/typings_test_ts28/",
8+
"rootDir": ".",
9+
"target": "es5",
10+
"lib": [
11+
"es5",
12+
"dom",
13+
"es2015.collection",
14+
"es2015.iterable",
15+
"es2015.promise"
16+
],
17+
"types": [],
18+
"strictNullChecks": true
19+
},
20+
"files": [
21+
"include-all.ts",
22+
"node_modules/@types/jasmine/index.d.ts"
23+
]
24+
}

Diff for: modules/benchmarks/src/tree/ng2_next/tree.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
*/
88

99
import {NgIf} from '@angular/common';
10-
import {ComponentFactory, ComponentFactoryResolver, ComponentRef, ErrorHandler, Injector, NgModuleRef, RendererFactory2, RootRenderer, Sanitizer, TemplateRef, ViewContainerRef} from '@angular/core';
11-
import {ArgumentType, BindingFlags, NodeFlags, ViewDefinition, ViewFlags, anchorDef, createComponentFactory, directiveDef, elementDef, initServicesIfNeeded, textDef, viewDef} from '@angular/core/src/view/index';
12-
import {DomRendererFactory2} from '@angular/platform-browser/src/dom/dom_renderer';
13-
import {DomSanitizerImpl, SafeStyle} from '@angular/platform-browser/src/security/dom_sanitization_service';
10+
import {ComponentFactory, ComponentFactoryResolver, ComponentRef, ErrorHandler, Injector, NgModuleRef, RendererFactory2, RootRenderer, Sanitizer, TemplateRef, ViewContainerRef, ɵArgumentType as ArgumentType, ɵBindingFlags as BindingFlags, ɵNodeFlags as NodeFlags, ɵViewDefinition as ViewDefinition, ɵViewFlags as ViewFlags, ɵand as anchorDef, ɵccf as createComponentFactory, ɵdid as directiveDef, ɵeld as elementDef, ɵinitServicesIfNeeded as initServicesIfNeeded, ɵted as textDef, ɵvid as viewDef} from '@angular/core';
11+
import {SafeStyle, ɵDomRendererFactory2 as DomRendererFactory2, ɵDomSanitizerImpl as DomSanitizerImpl} from '@angular/platform-browser';
1412

1513
import {TreeNode, emptyTree} from '../util';
1614

Diff for: modules/benchmarks/src/tree/render3/tree.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {ɵC as C, ɵE as E, ɵRenderFlags as RenderFlags, ɵT as T, ɵV as V, ɵb as b, ɵcR as cR, ɵcr as cr, ɵdefineComponent as defineComponent, ɵdetectChanges as _detectChanges, ɵe as e, ɵi1 as i1, ɵp as p, ɵsn as sn, ɵt as t, ɵv as v} from '@angular/core';
10-
import {ComponentDefInternal} from '@angular/core/src/render3/interfaces/definition';
1110

1211
import {TreeNode, buildTree, emptyTree} from '../util';
1312

@@ -35,7 +34,7 @@ export class TreeComponent {
3534
data: TreeNode = emptyTree;
3635

3736
/** @nocollapse */
38-
static ngComponentDef: ComponentDefInternal<TreeComponent> = defineComponent({
37+
static ngComponentDef = defineComponent({
3938
type: TreeComponent,
4039
selectors: [['tree']],
4140
template: function(rf: RenderFlags, ctx: TreeComponent) {
@@ -95,7 +94,7 @@ export class TreeFunction {
9594
data: TreeNode = emptyTree;
9695

9796
/** @nocollapse */
98-
static ngComponentDef: ComponentDefInternal<TreeFunction> = defineComponent({
97+
static ngComponentDef = defineComponent({
9998
type: TreeFunction,
10099
selectors: [['tree']],
101100
template: function(rf: RenderFlags, ctx: TreeFunction) {

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@
110110
"source-map": "0.5.7",
111111
"source-map-support": "0.4.18",
112112
"systemjs": "0.18.10",
113-
"tsickle": "^0.29.0",
113+
"tsickle": "0.32",
114114
"tslint": "5.7.0",
115115
"tslint-eslint-rules": "4.1.1",
116116
"tsutils": "2.20.0",
117-
"typescript": "2.8.x",
117+
"typescript": "2.9.x",
118118
"uglify-es": "^3.3.9",
119119
"universal-analytics": "0.4.15",
120120
"vlq": "0.2.2",

Diff for: packages/bazel/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"peerDependencies": {
1515
"@angular/compiler-cli": "0.0.0-PLACEHOLDER",
16-
"typescript": ">=2.7.2 <2.9"
16+
"typescript": ">=2.7.2 <2.10"
1717
},
1818
"repository": {
1919
"type": "git",

Diff for: packages/bazel/src/ng_package/packager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function main(args: string[]): number {
152152
allsrcs.filter(hasFileExtension('.d.ts')).forEach((f: string) => {
153153
const content = fs.readFileSync(f, 'utf-8')
154154
// Strip the named AMD module for compatibility with non-bazel users
155-
.replace(/^\/\/\/ <amd-module name=.*\/>\n/, '');
155+
.replace(/^\/\/\/ <amd-module name=.*\/>\n/gm, '');
156156
writeFileFromInputPath(f, content);
157157
});
158158

Diff for: packages/common/locales/BUILD.bazel

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ npm_package(
2222
# We don't actually import anything in the locale code so we can
2323
# null out the require reference passed into the module.
2424
"factory\(require, exports\)": "factory(null, exports)",
25+
26+
# Workaround for `.d.ts`` containing `/// <amd-module .../>`
27+
# which are generated in TypeScript v2.9, but not before.
28+
"/// <amd-module name=.*/>": "",
2529
},
2630
deps = [":locales"],
2731
)

Diff for: packages/compiler-cli/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
"dependencies": {
1212
"reflect-metadata": "^0.1.2",
1313
"minimist": "^1.2.0",
14-
"tsickle": "^0.29.0",
14+
"tsickle": "^0.30.0",
1515
"chokidar": "^1.4.2"
1616
},
1717
"peerDependencies": {
18-
"typescript": ">=2.7.2 <2.9",
18+
"typescript": ">=2.7.2 <2.10",
1919
"@angular/compiler": "0.0.0-PLACEHOLDER"
2020
},
2121
"engines" : {

Diff for: packages/compiler-cli/src/transformers/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const MIN_TS_VERSION = '2.7.2';
109109
* ∀ supported typescript version v, v < MAX_TS_VERSION
110110
* MAX_TS_VERSION is not considered as a supported TypeScript version
111111
*/
112-
const MAX_TS_VERSION = '2.9.0';
112+
const MAX_TS_VERSION = '2.10.0';
113113

114114
class AngularCompilerProgram implements Program {
115115
private rootNames: string[];

Diff for: packages/compiler-cli/test/metadata/collector_spec.ts

+1-32
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ describe('Collector', () => {
974974
});
975975
});
976976

977-
describe('regerssion', () => {
977+
describe('regression', () => {
978978
it('should be able to collect a short-hand property value', () => {
979979
const metadata = collectSource(`
980980
const children = { f1: 1 };
@@ -1040,37 +1040,6 @@ describe('Collector', () => {
10401040
.not.toBeUndefined('typeGuard was not collected');
10411041
});
10421042

1043-
it('should be able to collect an invalid access expression', () => {
1044-
const source = createSource(`
1045-
import {Component} from '@angular/core';
1046-
1047-
const value = [];
1048-
@Component({
1049-
provider: [{provide: 'some token', useValue: value[]}]
1050-
})
1051-
export class MyComponent {}
1052-
`);
1053-
const metadata = collector.getMetadata(source) !;
1054-
expect(metadata.metadata.MyComponent).toEqual({
1055-
__symbolic: 'class',
1056-
decorators: [{
1057-
__symbolic: 'call',
1058-
expression: {
1059-
__symbolic: 'reference',
1060-
module: '@angular/core',
1061-
name: 'Component',
1062-
line: 4,
1063-
character: 9
1064-
},
1065-
arguments: [{
1066-
__symbolic: 'error',
1067-
message: 'Expression form not supported',
1068-
line: 5,
1069-
character: 55
1070-
}]
1071-
}]
1072-
});
1073-
});
10741043
});
10751044

10761045
describe('references', () => {

Diff for: packages/core/src/core_private_export.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ export {_sanitizeUrl as ɵ_sanitizeUrl} from './sanitization/url_sanitizer';
2828
export {global as ɵglobal, looseIdentical as ɵlooseIdentical, stringify as ɵstringify} from './util';
2929
export {makeDecorator as ɵmakeDecorator} from './util/decorators';
3030
export {isObservable as ɵisObservable, isPromise as ɵisPromise} from './util/lang';
31-
export {clearOverrides as ɵclearOverrides, overrideComponentView as ɵoverrideComponentView, overrideProvider as ɵoverrideProvider} from './view/index';
31+
export {clearOverrides as ɵclearOverrides, initServicesIfNeeded as ɵinitServicesIfNeeded, overrideComponentView as ɵoverrideComponentView, overrideProvider as ɵoverrideProvider} from './view/index';
3232
export {NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as ɵNOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR} from './view/provider';

Diff for: packages/core/src/render3/definition.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function defineComponent<T>(componentDefinition: {
209209
const type = componentDefinition.type;
210210
const pipeTypes = componentDefinition.pipes !;
211211
const directiveTypes = componentDefinition.directives !;
212-
const declaredInputs: {[P in keyof T]: P} = {} as any;
212+
const declaredInputs: {[key: string]: string} = {} as any;
213213
const def: ComponentDefInternal<any> = {
214214
type: type,
215215
diPublic: null,

Diff for: packages/core/src/render3/instructions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ export function baseDirectiveCreate<T>(
15251525
* @param tNode The static data for this node
15261526
*/
15271527
function setInputsFromAttrs<T>(
1528-
directiveIndex: number, instance: T, inputs: {[key: string]: string}, tNode: TNode): void {
1528+
directiveIndex: number, instance: T, inputs: {[P in keyof T]: string;}, tNode: TNode): void {
15291529
let initialInputData = tNode.initialInputs as InitialInputData | undefined;
15301530
if (initialInputData === undefined || directiveIndex >= initialInputData.length) {
15311531
initialInputData = generateInitialInputs(directiveIndex, inputs, tNode);

Diff for: packages/core/src/render3/interfaces/definition.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export interface DirectiveDef<T, Selector extends string> {
8484
type: Type<T>;
8585

8686
/** Function that makes a directive public to the DI system. */
87-
diPublic: ((def: DirectiveDef<any, string>) => void)|null;
87+
diPublic: ((def: DirectiveDef<T, string>) => void)|null;
8888

8989
/** The selectors that will be used to match nodes to this directive. */
9090
selectors: CssSelectorList;
@@ -94,7 +94,7 @@ export interface DirectiveDef<T, Selector extends string> {
9494
* are their aliases if any, or their original unminified property names
9595
* (as in `@Input('alias') propertyName: any;`).
9696
*/
97-
readonly inputs: {[P in keyof T]: P};
97+
readonly inputs: {[P in keyof T]: string};
9898

9999
/**
100100
* @deprecated This is only here because `NgOnChanges` incorrectly uses declared name instead of

Diff for: packages/core/src/util.ts

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// Import zero symbols from zone.js. This causes the zone ambient type to be
10-
// added to the type-checker, without emitting any runtime module load statement
11-
import {} from 'zone.js';
12-
139
// TODO(jteplitz602): Load WorkerGlobalScope from lib.webworker.d.ts file #3492
1410
declare var WorkerGlobalScope: any /** TODO #9100 */;
1511
// CommonJS / Node have global context exposed as "global" variable.

Diff for: packages/core/src/zone/ng_zone.ts

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// Import zero symbols from zone.js. This causes the zone ambient type to be
10-
// added to the type-checker, without emitting any runtime module load statement
11-
import {} from 'zone.js';
129
import {EventEmitter} from '../event_emitter';
1310

1411
/**

Diff for: packages/language-service/src/ts_plugin.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
6363
tryCall(fileName, () => <T>(m.call(ls, fileName, p1, p2, p3, p4)));
6464
}
6565

66+
function tryFilenameFiveCall<T, P1, P2, P3, P4, P5>(
67+
m: (fileName: string, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) =>
68+
T): (fileName: string, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => T {
69+
return (fileName, p1, p2, p3, p4, p5) =>
70+
tryCall(fileName, () => <T>(m.call(ls, fileName, p1, p2, p3, p4, p5)));
71+
}
72+
73+
6674
function typescriptOnly(ls: ts.LanguageService): ts.LanguageService {
6775
const languageService: ts.LanguageService = {
6876
cleanupSemanticCache: () => ls.cleanupSemanticCache(),
@@ -74,7 +82,7 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
7482
getEncodedSyntacticClassifications: tryFilenameOneCall(ls.getEncodedSyntacticClassifications),
7583
getEncodedSemanticClassifications: tryFilenameOneCall(ls.getEncodedSemanticClassifications),
7684
getCompletionsAtPosition: tryFilenameTwoCall(ls.getCompletionsAtPosition),
77-
getCompletionEntryDetails: tryFilenameFourCall(ls.getCompletionEntryDetails),
85+
getCompletionEntryDetails: tryFilenameFiveCall(ls.getCompletionEntryDetails),
7886
getCompletionEntrySymbol: tryFilenameThreeCall(ls.getCompletionEntrySymbol),
7987
getQuickInfoAtPosition: tryFilenameOneCall(ls.getQuickInfoAtPosition),
8088
getNameOrDottedNameSpan: tryFilenameTwoCall(ls.getNameOrDottedNameSpan),
@@ -106,22 +114,28 @@ export function create(info: any /* ts.server.PluginCreateInfo */): ts.LanguageS
106114
getDocCommentTemplateAtPosition: tryFilenameOneCall(ls.getDocCommentTemplateAtPosition),
107115
isValidBraceCompletionAtPosition: tryFilenameTwoCall(ls.isValidBraceCompletionAtPosition),
108116
getSpanOfEnclosingComment: tryFilenameTwoCall(ls.getSpanOfEnclosingComment),
109-
getCodeFixesAtPosition: tryFilenameFourCall(ls.getCodeFixesAtPosition),
117+
getCodeFixesAtPosition: tryFilenameFiveCall(ls.getCodeFixesAtPosition),
110118
applyCodeActionCommand:
111119
<any>((action: any) => tryCall(undefined, () => ls.applyCodeActionCommand(action))),
112120
getEmitOutput: tryFilenameCall(ls.getEmitOutput),
113121
getProgram: () => ls.getProgram(),
114122
dispose: () => ls.dispose(),
115-
getApplicableRefactors: tryFilenameOneCall(ls.getApplicableRefactors),
116-
getEditsForRefactor: tryFilenameFourCall(ls.getEditsForRefactor),
123+
getApplicableRefactors: tryFilenameTwoCall(ls.getApplicableRefactors),
124+
getEditsForRefactor: tryFilenameFiveCall(ls.getEditsForRefactor),
117125
getDefinitionAndBoundSpan: tryFilenameOneCall(ls.getDefinitionAndBoundSpan),
118126
getCombinedCodeFix:
119-
(scope: ts.CombinedCodeFixScope, fixId: {}, formatOptions: ts.FormatCodeSettings) =>
120-
tryCall(undefined, () => ls.getCombinedCodeFix(scope, fixId, formatOptions)),
127+
(scope: ts.CombinedCodeFixScope, fixId: {}, formatOptions: ts.FormatCodeSettings,
128+
preferences: ts.UserPreferences) =>
129+
tryCall(
130+
undefined, () => ls.getCombinedCodeFix(scope, fixId, formatOptions, preferences)),
121131
// TODO(kyliau): dummy implementation to compile with ts 2.8, create real one
122132
getSuggestionDiagnostics: (fileName: string) => [],
123133
// TODO(kyliau): dummy implementation to compile with ts 2.8, create real one
124134
organizeImports: (scope: ts.CombinedCodeFixScope, formatOptions: ts.FormatCodeSettings) => [],
135+
// TODO: dummy implementation to compile with ts 2.9, create a real one
136+
getEditsForFileRename:
137+
(oldFilePath: string, newFilePath: string, formatOptions: ts.FormatCodeSettings,
138+
preferences: ts.UserPreferences | undefined) => []
125139
} as ts.LanguageService;
126140
return languageService;
127141
}

0 commit comments

Comments
 (0)