Skip to content

Commit 52970c0

Browse files
chuckjazmhevery
authored andcommitted
fix(compiler-cli): do not fold errors past calls in the collector (#21708)
Folding errors passed calls prevented the static reflector from begin able to ignore errors in annotations it doesn't know as the call to the unknown annotation was elided from the metadata. Fixes: #21273 PR Close #21708
1 parent eecdf34 commit 52970c0

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

packages/compiler-cli/src/metadata/collector.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export class MetadataCollector {
289289
ts.TypeAliasDeclaration | ts.EnumDeclaration) => exportedIdentifierName(node.name);
290290

291291

292-
// Predeclare classes and functions
292+
// Pre-declare classes and functions
293293
ts.forEachChild(sourceFile, node => {
294294
switch (node.kind) {
295295
case ts.SyntaxKind.ClassDeclaration:
@@ -454,7 +454,7 @@ export class MetadataCollector {
454454
};
455455
} else {
456456
nextDefaultValue =
457-
recordEntry(errorSym('Unsuppported enum member name', member.name), node);
457+
recordEntry(errorSym('Unsupported enum member name', member.name), node);
458458
}
459459
}
460460
if (writtenMembers) {

packages/compiler-cli/src/metadata/evaluator.ts

-3
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,6 @@ export class Evaluator {
356356
}
357357
}
358358
const args = arrayOrEmpty(callExpression.arguments).map(arg => this.evaluateNode(arg));
359-
if (!this.options.verboseInvalidExpression && args.some(isMetadataError)) {
360-
return args.find(isMetadataError);
361-
}
362359
if (this.isFoldable(callExpression)) {
363360
if (isMethodCallOf(callExpression, 'concat')) {
364361
const arrayValue = <MetadataValue[]>this.evaluateNode(

packages/compiler-cli/test/metadata/collector_spec.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -1054,10 +1054,20 @@ describe('Collector', () => {
10541054
expect(metadata.metadata.MyComponent).toEqual({
10551055
__symbolic: 'class',
10561056
decorators: [{
1057-
__symbolic: 'error',
1058-
message: 'Expression form not supported',
1059-
line: 5,
1060-
character: 55
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+
}]
10611071
}]
10621072
});
10631073
});

packages/compiler-cli/test/ngc_spec.ts

+34
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,40 @@ describe('ngc transformer command-line', () => {
16981698
expect(messages[0]).toContain(`is imported recursively by the module 'MyFaultyImport`);
16991699
});
17001700

1701+
// Regression test for #21273
1702+
it('should not report errors for unknown property annotations', () => {
1703+
write('src/tsconfig.json', `{
1704+
"extends": "../tsconfig-base.json",
1705+
"files": ["test-module.ts"]
1706+
}`);
1707+
1708+
write('src/test-decorator.ts', `
1709+
export function Convert(p: any): any {
1710+
// Make sur this doesn't look like a macro function
1711+
var r = p;
1712+
return r;
1713+
}
1714+
`);
1715+
write('src/test-module.ts', `
1716+
import {Component, Input, NgModule} from '@angular/core';
1717+
import {Convert} from './test-decorator';
1718+
1719+
@Component({template: '{{name}}'})
1720+
export class TestComponent {
1721+
@Input() @Convert(convert) name: string;
1722+
}
1723+
1724+
function convert(n: any) { return n; }
1725+
1726+
@NgModule({declarations: [TestComponent]})
1727+
export class TestModule {}
1728+
`);
1729+
const messages: string[] = [];
1730+
expect(
1731+
main(['-p', path.join(basePath, 'src/tsconfig.json')], message => messages.push(message)))
1732+
.toBe(0, `Compile failed:\n ${messages.join('\n ')}`);
1733+
});
1734+
17011735
it('should allow using 2 classes with the same name in declarations with noEmitOnError=true',
17021736
() => {
17031737
write('src/tsconfig.json', `{

packages/compiler/test/aot/static_reflector_spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ describe('StaticReflector', () => {
364364
const classData: any = moduleMetadata['InvalidMetadata'];
365365
expect(classData).toBeDefined();
366366
simplify(
367-
reflector.getStaticSymbol('/tmp/src/invalid-metadata.ts', ''), classData.decorators[0]);
367+
reflector.getStaticSymbol('/tmp/src/invalid-metadata.ts', ''),
368+
classData.decorators[0].arguments);
368369
} catch (e) {
369370
expect(e.position).toBeDefined();
370371
threw = true;

0 commit comments

Comments
 (0)