Skip to content

Commit 4d455e0

Browse files
committed
Revert "refactor: update code to be ES2022 compliant (#49332)" (#49554)
This reverts commit 349ff01. PR Close #49554
1 parent 7ebbd6d commit 4d455e0

20 files changed

Lines changed: 130 additions & 211 deletions

File tree

packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ export class ComponentDecoratorHandler implements
6060
private injectableRegistry: InjectableClassRegistry,
6161
private semanticDepGraphUpdater: SemanticDepGraphUpdater|null,
6262
private annotateForClosureCompiler: boolean, private perf: PerfRecorder,
63-
private hostDirectivesResolver: HostDirectivesResolver) {
64-
this.extractTemplateOptions = {
65-
enableI18nLegacyMessageIdFormat: this.enableI18nLegacyMessageIdFormat,
66-
i18nNormalizeLineEndingsInICUs: this.i18nNormalizeLineEndingsInICUs,
67-
usePoisonedData: this.usePoisonedData,
68-
};
69-
}
63+
private hostDirectivesResolver: HostDirectivesResolver) {}
7064

7165
private literalCache = new Map<Decorator, ts.ObjectLiteralExpression>();
7266
private elementSchemaRegistry = new DomElementSchemaRegistry();
@@ -79,9 +73,10 @@ export class ComponentDecoratorHandler implements
7973
private preanalyzeTemplateCache = new Map<DeclarationNode, ParsedTemplateWithSource>();
8074
private preanalyzeStylesCache = new Map<DeclarationNode, string[]|null>();
8175

82-
private extractTemplateOptions: {
83-
enableI18nLegacyMessageIdFormat: boolean; i18nNormalizeLineEndingsInICUs: boolean;
84-
usePoisonedData: boolean;
76+
private extractTemplateOptions = {
77+
enableI18nLegacyMessageIdFormat: this.enableI18nLegacyMessageIdFormat,
78+
i18nNormalizeLineEndingsInICUs: this.i18nNormalizeLineEndingsInICUs,
79+
usePoisonedData: this.usePoisonedData,
8580
};
8681

8782
readonly precedence = HandlerPrecedence.PRIMARY;

packages/compiler-cli/src/ngtsc/core/src/compiler.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,12 +1265,8 @@ class ReferenceGraphAdapter implements ReferencesRegistry {
12651265
}
12661266

12671267
class NotifyingProgramDriverWrapper implements ProgramDriver {
1268-
getSourceFileVersion: ProgramDriver['getSourceFileVersion'];
1269-
12701268
constructor(
1271-
private delegate: ProgramDriver, private notifyNewProgram: (program: ts.Program) => void) {
1272-
this.getSourceFileVersion = this.delegate.getSourceFileVersion?.bind(this);
1273-
}
1269+
private delegate: ProgramDriver, private notifyNewProgram: (program: ts.Program) => void) {}
12741270

12751271
get supportsInlineOperations() {
12761272
return this.delegate.supportsInlineOperations;
@@ -1284,6 +1280,8 @@ class NotifyingProgramDriverWrapper implements ProgramDriver {
12841280
this.delegate.updateFiles(contents, updateMode);
12851281
this.notifyNewProgram(this.delegate.getProgram());
12861282
}
1283+
1284+
getSourceFileVersion = this.delegate.getSourceFileVersion?.bind(this);
12871285
}
12881286

12891287
function versionMapFromProgram(

packages/compiler-cli/src/ngtsc/core/src/host.ts

Lines changed: 38 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -32,81 +32,50 @@ import {ExtendedTsCompilerHost, NgCompilerAdapter, NgCompilerOptions, UnifiedMod
3232
*/
3333
export class DelegatingCompilerHost implements
3434
Omit<RequiredDelegations<ExtendedTsCompilerHost>, 'getSourceFile'|'fileExists'> {
35-
createHash;
36-
directoryExists;
37-
fileNameToModuleName;
38-
getCancellationToken;
39-
getCanonicalFileName;
40-
getCurrentDirectory;
41-
getDefaultLibFileName;
42-
getDefaultLibLocation;
43-
getDirectories;
44-
getEnvironmentVariable;
45-
getModifiedResourceFiles;
46-
getNewLine;
47-
getParsedCommandLine;
48-
getSourceFileByPath;
49-
readDirectory;
50-
readFile;
51-
readResource;
52-
transformResource;
53-
realpath;
54-
resolveModuleNames;
55-
resolveTypeReferenceDirectives;
56-
resourceNameToFileName;
57-
trace;
58-
useCaseSensitiveFileNames;
59-
writeFile;
60-
getModuleResolutionCache;
61-
hasInvalidatedResolutions;
62-
resolveModuleNameLiterals;
63-
resolveTypeReferenceDirectiveReferences;
64-
65-
constructor(protected delegate: ExtendedTsCompilerHost) {
66-
// Excluded are 'getSourceFile' and 'fileExists', which are actually implemented by
67-
// NgCompilerHost
68-
// below.
69-
this.createHash = this.delegateMethod('createHash');
70-
this.directoryExists = this.delegateMethod('directoryExists');
71-
this.fileNameToModuleName = this.delegateMethod('fileNameToModuleName');
72-
this.getCancellationToken = this.delegateMethod('getCancellationToken');
73-
this.getCanonicalFileName = this.delegateMethod('getCanonicalFileName');
74-
this.getCurrentDirectory = this.delegateMethod('getCurrentDirectory');
75-
this.getDefaultLibFileName = this.delegateMethod('getDefaultLibFileName');
76-
this.getDefaultLibLocation = this.delegateMethod('getDefaultLibLocation');
77-
this.getDirectories = this.delegateMethod('getDirectories');
78-
this.getEnvironmentVariable = this.delegateMethod('getEnvironmentVariable');
79-
this.getModifiedResourceFiles = this.delegateMethod('getModifiedResourceFiles');
80-
this.getNewLine = this.delegateMethod('getNewLine');
81-
this.getParsedCommandLine = this.delegateMethod('getParsedCommandLine');
82-
this.getSourceFileByPath = this.delegateMethod('getSourceFileByPath');
83-
this.readDirectory = this.delegateMethod('readDirectory');
84-
this.readFile = this.delegateMethod('readFile');
85-
this.readResource = this.delegateMethod('readResource');
86-
this.transformResource = this.delegateMethod('transformResource');
87-
this.realpath = this.delegateMethod('realpath');
88-
this.resolveModuleNames = this.delegateMethod('resolveModuleNames');
89-
this.resolveTypeReferenceDirectives = this.delegateMethod('resolveTypeReferenceDirectives');
90-
this.resourceNameToFileName = this.delegateMethod('resourceNameToFileName');
91-
this.trace = this.delegateMethod('trace');
92-
this.useCaseSensitiveFileNames = this.delegateMethod('useCaseSensitiveFileNames');
93-
this.writeFile = this.delegateMethod('writeFile');
94-
this.getModuleResolutionCache = this.delegateMethod('getModuleResolutionCache');
95-
this.hasInvalidatedResolutions = this.delegateMethod('hasInvalidatedResolutions');
96-
// The following methods are required in TS 5.0+, but they don't exist in earlier versions.
97-
// TODO(crisbeto): remove the `ts-ignore` when dropping support for TypeScript 4.9.
98-
// @ts-ignore
99-
this.resolveModuleNameLiterals = this.delegateMethod('resolveModuleNameLiterals');
100-
this.resolveTypeReferenceDirectiveReferences =
101-
// @ts-ignore
102-
this.delegateMethod('resolveTypeReferenceDirectiveReferences');
103-
}
35+
constructor(protected delegate: ExtendedTsCompilerHost) {}
10436

10537
private delegateMethod<M extends keyof ExtendedTsCompilerHost>(name: M):
10638
ExtendedTsCompilerHost[M] {
10739
return this.delegate[name] !== undefined ? (this.delegate[name] as any).bind(this.delegate) :
10840
undefined;
10941
}
42+
43+
// Excluded are 'getSourceFile' and 'fileExists', which are actually implemented by NgCompilerHost
44+
// below.
45+
createHash = this.delegateMethod('createHash');
46+
directoryExists = this.delegateMethod('directoryExists');
47+
fileNameToModuleName = this.delegateMethod('fileNameToModuleName');
48+
getCancellationToken = this.delegateMethod('getCancellationToken');
49+
getCanonicalFileName = this.delegateMethod('getCanonicalFileName');
50+
getCurrentDirectory = this.delegateMethod('getCurrentDirectory');
51+
getDefaultLibFileName = this.delegateMethod('getDefaultLibFileName');
52+
getDefaultLibLocation = this.delegateMethod('getDefaultLibLocation');
53+
getDirectories = this.delegateMethod('getDirectories');
54+
getEnvironmentVariable = this.delegateMethod('getEnvironmentVariable');
55+
getModifiedResourceFiles = this.delegateMethod('getModifiedResourceFiles');
56+
getNewLine = this.delegateMethod('getNewLine');
57+
getParsedCommandLine = this.delegateMethod('getParsedCommandLine');
58+
getSourceFileByPath = this.delegateMethod('getSourceFileByPath');
59+
readDirectory = this.delegateMethod('readDirectory');
60+
readFile = this.delegateMethod('readFile');
61+
readResource = this.delegateMethod('readResource');
62+
transformResource = this.delegateMethod('transformResource');
63+
realpath = this.delegateMethod('realpath');
64+
resolveModuleNames = this.delegateMethod('resolveModuleNames');
65+
resolveTypeReferenceDirectives = this.delegateMethod('resolveTypeReferenceDirectives');
66+
resourceNameToFileName = this.delegateMethod('resourceNameToFileName');
67+
trace = this.delegateMethod('trace');
68+
useCaseSensitiveFileNames = this.delegateMethod('useCaseSensitiveFileNames');
69+
writeFile = this.delegateMethod('writeFile');
70+
getModuleResolutionCache = this.delegateMethod('getModuleResolutionCache');
71+
hasInvalidatedResolutions = this.delegateMethod('hasInvalidatedResolutions');
72+
// The following methods are required in TS 5.0+, but they don't exist in earlier versions.
73+
// TODO(crisbeto): remove the `ts-ignore` when dropping support for TypeScript 4.9.
74+
// @ts-ignore
75+
resolveModuleNameLiterals = this.delegateMethod('resolveModuleNameLiterals');
76+
resolveTypeReferenceDirectiveReferences =
77+
// @ts-ignore
78+
this.delegateMethod('resolveTypeReferenceDirectiveReferences');
11079
}
11180

11281
/**

packages/compiler-cli/src/ngtsc/imports/src/emitter.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,9 @@ export class AbsoluteModuleStrategy implements ReferenceEmitStrategy {
367367
* Instead, `LogicalProjectPath`s are used.
368368
*/
369369
export class LogicalProjectStrategy implements ReferenceEmitStrategy {
370-
private relativePathStrategy: RelativePathStrategy;
370+
private relativePathStrategy = new RelativePathStrategy(this.reflector);
371371

372-
constructor(private reflector: ReflectionHost, private logicalFs: LogicalFileSystem) {
373-
this.relativePathStrategy = new RelativePathStrategy(this.reflector);
374-
}
372+
constructor(private reflector: ReflectionHost, private logicalFs: LogicalFileSystem) {}
375373

376374
emit(ref: Reference, context: ts.SourceFile, importFlags: ImportFlags): ReferenceEmitResult|null {
377375
const destSf = getSourceFile(ref.node);

packages/compiler-cli/src/ngtsc/perf/src/recorder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ActivePerfRecorder implements PerfRecorder {
2828
private bytes: number[];
2929

3030
private currentPhase = PerfPhase.Unaccounted;
31-
private currentPhaseEntered: HrTime;
31+
private currentPhaseEntered = this.zeroTime;
3232

3333
/**
3434
* Creates an `ActivePerfRecorder` with its zero point set to the current time.
@@ -38,7 +38,6 @@ export class ActivePerfRecorder implements PerfRecorder {
3838
}
3939

4040
private constructor(private zeroTime: HrTime) {
41-
this.currentPhaseEntered = this.zeroTime;
4241
this.counters = Array(PerfEvent.LAST).fill(0);
4342
this.phaseTime = Array(PerfPhase.LAST).fill(0);
4443
this.bytes = Array(PerfCheckpoint.LAST).fill(0);

packages/compiler-cli/src/ngtsc/program_driver/src/ts_create_program_driver.ts

Lines changed: 35 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,68 +23,43 @@ import {FileUpdate, MaybeSourceFileWithOriginalFile, NgOriginalFile, ProgramDriv
2323
*/
2424
export class DelegatingCompilerHost implements
2525
Omit<RequiredDelegations<ts.CompilerHost>, 'getSourceFile'|'fileExists'|'writeFile'> {
26-
createHash;
27-
directoryExists;
28-
getCancellationToken;
29-
getCanonicalFileName;
30-
getCurrentDirectory;
31-
getDefaultLibFileName;
32-
getDefaultLibLocation;
33-
getDirectories;
34-
getEnvironmentVariable;
35-
getNewLine;
36-
getParsedCommandLine;
37-
getSourceFileByPath;
38-
readDirectory;
39-
readFile;
40-
realpath;
41-
resolveModuleNames;
42-
resolveTypeReferenceDirectives;
43-
trace;
44-
useCaseSensitiveFileNames;
45-
getModuleResolutionCache;
46-
hasInvalidatedResolutions;
47-
resolveModuleNameLiterals;
48-
resolveTypeReferenceDirectiveReferences;
49-
50-
constructor(protected delegate: ts.CompilerHost) {
51-
// Excluded are 'getSourceFile', 'fileExists' and 'writeFile', which are actually implemented by
52-
// `TypeCheckProgramHost` below.
53-
54-
this.createHash = this.delegateMethod('createHash');
55-
this.directoryExists = this.delegateMethod('directoryExists');
56-
this.getCancellationToken = this.delegateMethod('getCancellationToken');
57-
this.getCanonicalFileName = this.delegateMethod('getCanonicalFileName');
58-
this.getCurrentDirectory = this.delegateMethod('getCurrentDirectory');
59-
this.getDefaultLibFileName = this.delegateMethod('getDefaultLibFileName');
60-
this.getDefaultLibLocation = this.delegateMethod('getDefaultLibLocation');
61-
this.getDirectories = this.delegateMethod('getDirectories');
62-
this.getEnvironmentVariable = this.delegateMethod('getEnvironmentVariable');
63-
this.getNewLine = this.delegateMethod('getNewLine');
64-
this.getParsedCommandLine = this.delegateMethod('getParsedCommandLine');
65-
this.getSourceFileByPath = this.delegateMethod('getSourceFileByPath');
66-
this.readDirectory = this.delegateMethod('readDirectory');
67-
this.readFile = this.delegateMethod('readFile');
68-
this.realpath = this.delegateMethod('realpath');
69-
this.resolveModuleNames = this.delegateMethod('resolveModuleNames');
70-
this.resolveTypeReferenceDirectives = this.delegateMethod('resolveTypeReferenceDirectives');
71-
this.trace = this.delegateMethod('trace');
72-
this.useCaseSensitiveFileNames = this.delegateMethod('useCaseSensitiveFileNames');
73-
this.getModuleResolutionCache = this.delegateMethod('getModuleResolutionCache');
74-
this.hasInvalidatedResolutions = this.delegateMethod('hasInvalidatedResolutions');
75-
// The following methods are required in TS 5.0+, but they don't exist in earlier versions.
76-
// TODO(crisbeto): remove the `ts-ignore` when dropping support for TypeScript 4.9.
77-
// @ts-ignore
78-
this.resolveModuleNameLiterals = this.delegateMethod('resolveModuleNameLiterals');
79-
this.resolveTypeReferenceDirectiveReferences =
80-
// @ts-ignore
81-
this.delegateMethod('resolveTypeReferenceDirectiveReferences');
82-
}
26+
constructor(protected delegate: ts.CompilerHost) {}
8327

8428
private delegateMethod<M extends keyof ts.CompilerHost>(name: M): ts.CompilerHost[M] {
8529
return this.delegate[name] !== undefined ? (this.delegate[name] as any).bind(this.delegate) :
8630
undefined;
8731
}
32+
33+
// Excluded are 'getSourceFile', 'fileExists' and 'writeFile', which are actually implemented by
34+
// `TypeCheckProgramHost` below.
35+
createHash = this.delegateMethod('createHash');
36+
directoryExists = this.delegateMethod('directoryExists');
37+
getCancellationToken = this.delegateMethod('getCancellationToken');
38+
getCanonicalFileName = this.delegateMethod('getCanonicalFileName');
39+
getCurrentDirectory = this.delegateMethod('getCurrentDirectory');
40+
getDefaultLibFileName = this.delegateMethod('getDefaultLibFileName');
41+
getDefaultLibLocation = this.delegateMethod('getDefaultLibLocation');
42+
getDirectories = this.delegateMethod('getDirectories');
43+
getEnvironmentVariable = this.delegateMethod('getEnvironmentVariable');
44+
getNewLine = this.delegateMethod('getNewLine');
45+
getParsedCommandLine = this.delegateMethod('getParsedCommandLine');
46+
getSourceFileByPath = this.delegateMethod('getSourceFileByPath');
47+
readDirectory = this.delegateMethod('readDirectory');
48+
readFile = this.delegateMethod('readFile');
49+
realpath = this.delegateMethod('realpath');
50+
resolveModuleNames = this.delegateMethod('resolveModuleNames');
51+
resolveTypeReferenceDirectives = this.delegateMethod('resolveTypeReferenceDirectives');
52+
trace = this.delegateMethod('trace');
53+
useCaseSensitiveFileNames = this.delegateMethod('useCaseSensitiveFileNames');
54+
getModuleResolutionCache = this.delegateMethod('getModuleResolutionCache');
55+
hasInvalidatedResolutions = this.delegateMethod('hasInvalidatedResolutions');
56+
// The following methods are required in TS 5.0+, but they don't exist in earlier versions.
57+
// TODO(crisbeto): remove the `ts-ignore` when dropping support for TypeScript 4.9.
58+
// @ts-ignore
59+
resolveModuleNameLiterals = this.delegateMethod('resolveModuleNameLiterals');
60+
resolveTypeReferenceDirectiveReferences =
61+
// @ts-ignore
62+
this.delegateMethod('resolveTypeReferenceDirectiveReferences');
8863
}
8964

9065
/**
@@ -106,13 +81,12 @@ class UpdatedProgramHost extends DelegatingCompilerHost {
10681
* order for those shims to be loaded, and then cleaned up afterwards. Thus the
10782
* `UpdatedProgramHost` has its own `ShimReferenceTagger` to perform this function.
10883
*/
109-
private shimTagger: ShimReferenceTagger;
84+
private shimTagger = new ShimReferenceTagger(this.shimExtensionPrefixes);
11085

11186
constructor(
11287
sfMap: Map<string, ts.SourceFile>, private originalProgram: ts.Program,
11388
delegate: ts.CompilerHost, private shimExtensionPrefixes: string[]) {
11489
super(delegate);
115-
this.shimTagger = new ShimReferenceTagger(this.shimExtensionPrefixes);
11690
this.sfMap = sfMap;
11791
}
11892

@@ -176,13 +150,11 @@ export class TsCreateProgramDriver implements ProgramDriver {
176150
*/
177151
private sfMap = new Map<string, ts.SourceFile>();
178152

179-
private program: ts.Program;
153+
private program: ts.Program = this.originalProgram;
180154

181155
constructor(
182156
private originalProgram: ts.Program, private originalHost: ts.CompilerHost,
183-
private options: ts.CompilerOptions, private shimExtensionPrefixes: string[]) {
184-
this.program = this.originalProgram;
185-
}
157+
private options: ts.CompilerOptions, private shimExtensionPrefixes: string[]) {}
186158

187159
readonly supportsInlineOperations = true;
188160

packages/compiler-cli/src/ngtsc/resource/src/loader.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ const RESOURCE_MARKER_TS = RESOURCE_MARKER + '.ts';
2424
export class AdapterResourceLoader implements ResourceLoader {
2525
private cache = new Map<string, string>();
2626
private fetching = new Map<string, Promise<void>>();
27-
private lookupResolutionHost: RequiredDelegations<ts.ModuleResolutionHost>;
27+
private lookupResolutionHost = createLookupResolutionHost(this.adapter);
2828

29-
canPreload: boolean;
30-
canPreprocess: boolean;
29+
canPreload = !!this.adapter.readResource;
30+
canPreprocess = !!this.adapter.transformResource;
3131

32-
constructor(private adapter: NgCompilerAdapter, private options: ts.CompilerOptions) {
33-
this.lookupResolutionHost = createLookupResolutionHost(this.adapter);
34-
this.canPreload = !!this.adapter.readResource;
35-
this.canPreprocess = !!this.adapter.transformResource;
36-
}
32+
constructor(private adapter: NgCompilerAdapter, private options: ts.CompilerOptions) {}
3733

3834
/**
3935
* Resolve the url of a resource relative to the file that contains the reference to it.

packages/compiler/src/i18n/i18n_ast.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ export interface MessagePlaceholder {
2222

2323
export class Message {
2424
sources: MessageSpan[];
25-
id: string;
25+
id: string = this.customId;
2626
/** The ids to use if there are no custom id and if `i18nLegacyMessageIdFormat` is not empty */
2727
legacyIds: string[] = [];
2828

29-
messageString: string;
29+
messageString = serializeMessage(this.nodes);
3030

3131
/**
3232
* @param nodes message AST
@@ -40,9 +40,6 @@ export class Message {
4040
public nodes: Node[], public placeholders: {[phName: string]: MessagePlaceholder},
4141
public placeholderToMessage: {[phName: string]: Message}, public meaning: string,
4242
public description: string, public customId: string) {
43-
this.id = this.customId;
44-
this.messageString = serializeMessage(this.nodes);
45-
4643
if (nodes.length) {
4744
this.sources = [{
4845
filePath: nodes[0].sourceSpan.start.file.url,

0 commit comments

Comments
 (0)