Skip to content

Commit 9e7a71c

Browse files
crisbetodgp1130
authored andcommitted
build: update to TypeScript 4.8 RC
Updates to the TypeScript 4.8 RC and adds some code to account for a breaking change where the decorators and modifiers of an AST node have been combined into a single array.
1 parent 6aa1706 commit 9e7a71c

File tree

10 files changed

+9685
-4923
lines changed

10 files changed

+9685
-4923
lines changed

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@
6565
},
6666
"devDependencies": {
6767
"@ampproject/remapping": "2.2.0",
68-
"@angular/animations": "14.1.2",
68+
"@angular/animations": "14.2.0-rc.0",
6969
"@angular/build-tooling": "https://github.com/angular/dev-infra-private-build-tooling-builds.git#08f0188fccf98139207fbd5e683533950e9068e2",
70-
"@angular/cdk": "14.1.2",
71-
"@angular/common": "14.1.2",
72-
"@angular/compiler": "14.1.2",
73-
"@angular/compiler-cli": "14.1.2",
74-
"@angular/core": "14.1.2",
75-
"@angular/forms": "14.1.2",
76-
"@angular/localize": "14.1.2",
77-
"@angular/material": "14.1.2",
70+
"@angular/cdk": "14.2.0-next.2",
71+
"@angular/common": "14.2.0-rc.0",
72+
"@angular/compiler": "14.2.0-rc.0",
73+
"@angular/compiler-cli": "14.2.0-rc.0",
74+
"@angular/core": "14.2.0-rc.0",
75+
"@angular/forms": "14.2.0-rc.0",
76+
"@angular/localize": "14.2.0-rc.0",
77+
"@angular/material": "14.2.0-next.2",
7878
"@angular/ng-dev": "https://github.com/angular/dev-infra-private-ng-dev-builds.git#a9d380df54092930c4eabbab114c29ac125759f4",
79-
"@angular/platform-browser": "14.1.2",
80-
"@angular/platform-browser-dynamic": "14.1.2",
81-
"@angular/platform-server": "14.1.2",
82-
"@angular/router": "14.1.2",
83-
"@angular/service-worker": "14.1.2",
79+
"@angular/platform-browser": "14.2.0-rc.0",
80+
"@angular/platform-browser-dynamic": "14.2.0-rc.0",
81+
"@angular/platform-server": "14.2.0-rc.0",
82+
"@angular/router": "14.2.0-rc.0",
83+
"@angular/service-worker": "14.2.0-rc.0",
8484
"@babel/core": "7.18.10",
8585
"@babel/generator": "7.18.12",
8686
"@babel/helper-annotate-as-pure": "7.18.6",
@@ -214,7 +214,7 @@
214214
"tree-kill": "1.2.2",
215215
"ts-node": "^10.0.0",
216216
"tslib": "2.4.0",
217-
"typescript": "~4.7.2",
217+
"typescript": "4.8.1-rc",
218218
"verdaccio": "5.14.0",
219219
"verdaccio-auth-memory": "^10.0.0",
220220
"webpack": "5.74.0",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"ng-packagr": "^14.0.0 || ^14.0.0-next || ^14.1.0-next",
8181
"protractor": "^7.0.0",
8282
"tailwindcss": "^2.0.0 || ^3.0.0",
83-
"typescript": ">=4.6.2 <4.8"
83+
"typescript": ">=4.6.2 <4.9"
8484
},
8585
"peerDependenciesMeta": {
8686
"@angular/localize": {

packages/angular_devkit/core/src/json/schema/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
649649
}
650650

651651
let value = source(schema);
652-
if (isObservable(value)) {
652+
if (isObservable<{}>(value)) {
653653
value = await value.toPromise();
654654
}
655655

packages/ngtools/webpack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
"dependencies": {},
2424
"peerDependencies": {
2525
"@angular/compiler-cli": "^14.0.0 || ^14.0.0-next || ^14.1.0-next",
26-
"typescript": ">=4.6.2 <4.8",
26+
"typescript": ">=4.6.2 <4.9",
2727
"webpack": "^5.54.0"
2828
},
2929
"devDependencies": {
3030
"@angular-devkit/core": "0.0.0-PLACEHOLDER",
3131
"@angular/compiler": "14.1.2",
3232
"@angular/compiler-cli": "14.1.2",
33-
"typescript": "~4.7.2",
33+
"typescript": "4.8.1-rc",
3434
"webpack": "5.74.0"
3535
}
3636
}

packages/ngtools/webpack/src/transformers/elide_imports_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ describe('@ngtools/webpack transformers', () => {
773773
): ts.Transformer<ts.SourceFile> => {
774774
const visit: ts.Visitor = (node) => {
775775
if (ts.isShorthandPropertyAssignment(node)) {
776-
return ts.createPropertyAssignment(node.name, node.name);
776+
return ts.factory.createPropertyAssignment(node.name, node.name);
777777
}
778778

779779
return ts.visitEachChild(node, (child) => visit(child), context);

packages/ngtools/webpack/src/transformers/replace_resources.ts

Lines changed: 91 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { InlineAngularResourceLoaderPath } from '../loaders/inline-resource';
1111

1212
export const NG_COMPONENT_RESOURCE_QUERY = 'ngResource';
1313

14+
/** Whether the current version of TypeScript is after 4.8. */
15+
const IS_TS_48 = isAfterVersion(4, 8);
16+
1417
export function replaceResources(
1518
shouldTransform: (fileName: string) => boolean,
1619
getTypeChecker: () => ts.TypeChecker,
@@ -24,27 +27,13 @@ export function replaceResources(
2427

2528
const visitNode: ts.Visitor = (node: ts.Node) => {
2629
if (ts.isClassDeclaration(node)) {
27-
const decorators = ts.visitNodes(node.decorators, (node) =>
28-
ts.isDecorator(node)
29-
? visitDecorator(
30-
nodeFactory,
31-
node,
32-
typeChecker,
33-
resourceImportDeclarations,
34-
moduleKind,
35-
inlineStyleFileExtension,
36-
)
37-
: node,
38-
);
39-
40-
return nodeFactory.updateClassDeclaration(
30+
return visitClassDeclaration(
31+
nodeFactory,
32+
typeChecker,
4133
node,
42-
decorators,
43-
node.modifiers,
44-
node.name,
45-
node.typeParameters,
46-
node.heritageClauses,
47-
node.members,
34+
resourceImportDeclarations,
35+
moduleKind,
36+
inlineStyleFileExtension,
4837
);
4938
}
5039

@@ -76,6 +65,75 @@ export function replaceResources(
7665
};
7766
}
7867

68+
/**
69+
* Replaces the resources inside of a `ClassDeclaration`. This is a backwards-compatibility layer
70+
* to support TypeScript versions older than 4.8 where the decorators of a node were in a separate
71+
* array, rather than being part of its `modifiers` array.
72+
*
73+
* TODO: remove this function and use the `NodeFactory` directly once support for TypeScript
74+
* 4.6 and 4.7 has been dropped.
75+
*/
76+
function visitClassDeclaration(
77+
nodeFactory: ts.NodeFactory,
78+
typeChecker: ts.TypeChecker,
79+
node: ts.ClassDeclaration,
80+
resourceImportDeclarations: ts.ImportDeclaration[],
81+
moduleKind: ts.ModuleKind | undefined,
82+
inlineStyleFileExtension: string | undefined,
83+
): ts.ClassDeclaration {
84+
let decorators: ts.Decorator[] | undefined;
85+
let modifiers: ts.Modifier[] | undefined;
86+
87+
if (IS_TS_48) {
88+
node.modifiers?.forEach((modifier) => {
89+
if (ts.isDecorator(modifier)) {
90+
decorators ??= [];
91+
decorators.push(modifier);
92+
} else {
93+
modifiers = modifiers ??= [];
94+
modifiers.push(modifier);
95+
}
96+
});
97+
} else {
98+
decorators = node.decorators as unknown as ts.Decorator[];
99+
modifiers = node.modifiers as unknown as ts.Modifier[];
100+
}
101+
102+
if (!decorators || decorators.length === 0) {
103+
return node;
104+
}
105+
106+
decorators = decorators.map((current) =>
107+
visitDecorator(
108+
nodeFactory,
109+
current,
110+
typeChecker,
111+
resourceImportDeclarations,
112+
moduleKind,
113+
inlineStyleFileExtension,
114+
),
115+
);
116+
117+
return IS_TS_48
118+
? nodeFactory.updateClassDeclaration(
119+
node,
120+
[...decorators, ...(modifiers ?? [])],
121+
node.name,
122+
node.typeParameters,
123+
node.heritageClauses,
124+
node.members,
125+
)
126+
: nodeFactory.updateClassDeclaration(
127+
node,
128+
decorators,
129+
modifiers,
130+
node.name,
131+
node.typeParameters,
132+
node.heritageClauses,
133+
node.members,
134+
);
135+
}
136+
79137
function visitDecorator(
80138
nodeFactory: ts.NodeFactory,
81139
node: ts.Decorator,
@@ -327,3 +385,16 @@ function getDecoratorOrigin(
327385

328386
return null;
329387
}
388+
389+
/** Checks if the current version of TypeScript is after the specified major/minor versions. */
390+
function isAfterVersion(targetMajor: number, targetMinor: number): boolean {
391+
const [major, minor] = ts.versionMajorMinor.split('.').map((part) => parseInt(part));
392+
393+
if (major < targetMajor) {
394+
return false;
395+
} else if (major > targetMajor) {
396+
return true;
397+
} else {
398+
return minor >= targetMinor;
399+
}
400+
}

packages/schematics/angular/third_party/github.com/Microsoft/TypeScript/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
load("//tools:defaults.bzl", "ts_library")
22

3-
# files fetched on 2022-05-25 from
4-
# https://github.com/microsoft/TypeScript/releases/tag/v4.7.2
3+
# files fetched on 2022-08-18 from
4+
# https://github.com/microsoft/TypeScript/releases/tag/v4.8-rc
55

66
# Commands to download:
7-
# curl https://raw.githubusercontent.com/microsoft/TypeScript/v4.7.2/lib/typescript.d.ts -o packages/schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript.d.ts
8-
# curl https://raw.githubusercontent.com/microsoft/TypeScript/v4.7.2/lib/typescript.js -o packages/schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript.js
7+
# curl https://raw.githubusercontent.com/microsoft/TypeScript/v4.8-rc/lib/typescript.d.ts -o packages/schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript.d.ts
8+
# curl https://raw.githubusercontent.com/microsoft/TypeScript/v4.8-rc/lib/typescript.js -o packages/schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript.js
99

1010
licenses(["notice"]) # Apache 2.0
1111

0 commit comments

Comments
 (0)