Skip to content

Commit e46c081

Browse files
Revert "fix(compiler-cli): consider the case of duplicate Angular decorators in local compilation diagnostics (#54139)" (#54264)
This reverts commit 4b1d948. PR Close #54264
1 parent bd43aa3 commit e46c081

2 files changed

Lines changed: 12 additions & 35 deletions

File tree

packages/compiler-cli/src/ngtsc/transform/src/compilation.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,9 @@ export class TraitCompiler implements ProgramTypeCheckAdapter {
259259
let record: ClassRecord|null = this.recordFor(clazz);
260260
let foundTraits: PendingTrait<unknown, unknown, SemanticSymbol|null, unknown>[] = [];
261261

262-
// A set to track the undetected decorators (= either non-Angular decorators or Angular
263-
// duplicate decorators) in local compilation mode. An error will be issued if such decorators
264-
// are found.
265-
const undetectedDecorators =
262+
// A set to track the non-Angular decorators in local compilation mode. An error will be issued
263+
// if non-Angular decorators is found in local compilation mode.
264+
const nonNgDecoratorsInLocalMode =
266265
this.compilationMode === CompilationMode.LOCAL ? new Set(decorators) : null;
267266

268267
for (const handler of this.handlers) {
@@ -271,8 +270,8 @@ export class TraitCompiler implements ProgramTypeCheckAdapter {
271270
continue;
272271
}
273272

274-
if (undetectedDecorators !== null && result.decorator !== null) {
275-
undetectedDecorators.delete(result.decorator);
273+
if (nonNgDecoratorsInLocalMode !== null && result.decorator !== null) {
274+
nonNgDecoratorsInLocalMode.delete(result.decorator);
276275
}
277276

278277
const isPrimaryHandler = handler.precedence === HandlerPrecedence.PRIMARY;
@@ -342,19 +341,19 @@ export class TraitCompiler implements ProgramTypeCheckAdapter {
342341
}
343342
}
344343

345-
if (undetectedDecorators !== null && undetectedDecorators.size > 0 && record !== null &&
346-
record.metaDiagnostics === null) {
344+
if (nonNgDecoratorsInLocalMode !== null && nonNgDecoratorsInLocalMode.size > 0 &&
345+
record !== null && record.metaDiagnostics === null) {
347346
// Custom decorators found in local compilation mode! In this mode we don't support custom
348347
// decorators yet. But will eventually do (b/320536434). For now a temporary error is thrown.
349-
record.metaDiagnostics = [...undetectedDecorators].map(
348+
record.metaDiagnostics = [...nonNgDecoratorsInLocalMode].map(
350349
decorator => ({
351350
category: ts.DiagnosticCategory.Error,
352351
code: Number('-99' + ErrorCode.DECORATOR_UNEXPECTED),
353352
file: getSourceFile(clazz),
354353
start: decorator.node.getStart(),
355354
length: decorator.node.getWidth(),
356355
messageText:
357-
'In local compilation mode, Angular does not support custom decorators or duplicate Angular decorators. Ensure all class decorators are from Angular and each decorator is used at most once for each class.',
356+
'In local compilation mode, Angular does not support custom decorators. Ensure all class decorators are from Angular.',
358357
}));
359358
record.traits = foundTraits = [];
360359
}

packages/compiler-cli/test/ngtsc/local_compilation_spec.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ runInEachFileSystem(
19891989
});
19901990
});
19911991

1992-
describe('custom/duplicate decorator', () => {
1992+
describe('custom decorator', () => {
19931993
it('should produce diagnostic for each custom decorator', () => {
19941994
env.write('test.ts', `
19951995
import {Component} from '@angular/core';
@@ -2014,31 +2014,9 @@ runInEachFileSystem(
20142014
expect(errors[0].code).toBe(ngErrorCode(ErrorCode.DECORATOR_UNEXPECTED));
20152015
expect(errors[1].code).toBe(ngErrorCode(ErrorCode.DECORATOR_UNEXPECTED));
20162016
expect(text1).toContain(
2017-
'In local compilation mode, Angular does not support custom decorators or duplicate Angular decorators');
2017+
'In local compilation mode, Angular does not support custom decorators');
20182018
expect(text2).toContain(
2019-
'In local compilation mode, Angular does not support custom decorators or duplicate Angular decorators');
2020-
});
2021-
2022-
it('should produce diagnostic for duplicate Component decorator', () => {
2023-
env.write('test.ts', `
2024-
import {Component} from '@angular/core';
2025-
import {SomeServiceImpl} from './some-where';
2026-
2027-
@Component({template: 'Hello!'})
2028-
@Component({template: 'Bye!'})
2029-
export class SomeComp {
2030-
}
2031-
`);
2032-
2033-
const errors = env.driveDiagnostics();
2034-
2035-
expect(errors.length).toBe(1);
2036-
2037-
const text1 = ts.flattenDiagnosticMessageText(errors[0].messageText, '\n');
2038-
2039-
expect(errors[0].code).toBe(ngErrorCode(ErrorCode.DECORATOR_UNEXPECTED));
2040-
expect(text1).toContain(
2041-
'In local compilation mode, Angular does not support custom decorators or duplicate Angular decorators');
2019+
'In local compilation mode, Angular does not support custom decorators');
20422020
});
20432021
});
20442022
});

0 commit comments

Comments
 (0)