Skip to content

Commit

Permalink
fix(compiler-cli): do not fold errors past calls in the collector (an…
Browse files Browse the repository at this point in the history
…gular#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: angular#21273

PR Close angular#21708
  • Loading branch information
chuckjaz authored and leo6104 committed Mar 25, 2018
1 parent f4ed8f4 commit 12a119b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/compiler-cli/src/metadata/collector.ts
Expand Up @@ -289,7 +289,7 @@ export class MetadataCollector {
ts.TypeAliasDeclaration | ts.EnumDeclaration) => exportedIdentifierName(node.name);


// Predeclare classes and functions
// Pre-declare classes and functions
ts.forEachChild(sourceFile, node => {
switch (node.kind) {
case ts.SyntaxKind.ClassDeclaration:
Expand Down Expand Up @@ -454,7 +454,7 @@ export class MetadataCollector {
};
} else {
nextDefaultValue =
recordEntry(errorSym('Unsuppported enum member name', member.name), node);
recordEntry(errorSym('Unsupported enum member name', member.name), node);
}
}
if (writtenMembers) {
Expand Down
3 changes: 0 additions & 3 deletions packages/compiler-cli/src/metadata/evaluator.ts
Expand Up @@ -356,9 +356,6 @@ export class Evaluator {
}
}
const args = arrayOrEmpty(callExpression.arguments).map(arg => this.evaluateNode(arg));
if (!this.options.verboseInvalidExpression && args.some(isMetadataError)) {
return args.find(isMetadataError);
}
if (this.isFoldable(callExpression)) {
if (isMethodCallOf(callExpression, 'concat')) {
const arrayValue = <MetadataValue[]>this.evaluateNode(
Expand Down
18 changes: 14 additions & 4 deletions packages/compiler-cli/test/metadata/collector_spec.ts
Expand Up @@ -1054,10 +1054,20 @@ describe('Collector', () => {
expect(metadata.metadata.MyComponent).toEqual({
__symbolic: 'class',
decorators: [{
__symbolic: 'error',
message: 'Expression form not supported',
line: 5,
character: 55
__symbolic: 'call',
expression: {
__symbolic: 'reference',
module: '@angular/core',
name: 'Component',
line: 4,
character: 9
},
arguments: [{
__symbolic: 'error',
message: 'Expression form not supported',
line: 5,
character: 55
}]
}]
});
});
Expand Down
34 changes: 34 additions & 0 deletions packages/compiler-cli/test/ngc_spec.ts
Expand Up @@ -1698,6 +1698,40 @@ describe('ngc transformer command-line', () => {
expect(messages[0]).toContain(`is imported recursively by the module 'MyFaultyImport`);
});

// Regression test for #21273
it('should not report errors for unknown property annotations', () => {
write('src/tsconfig.json', `{
"extends": "../tsconfig-base.json",
"files": ["test-module.ts"]
}`);

write('src/test-decorator.ts', `
export function Convert(p: any): any {
// Make sur this doesn't look like a macro function
var r = p;
return r;
}
`);
write('src/test-module.ts', `
import {Component, Input, NgModule} from '@angular/core';
import {Convert} from './test-decorator';
@Component({template: '{{name}}'})
export class TestComponent {
@Input() @Convert(convert) name: string;
}
function convert(n: any) { return n; }
@NgModule({declarations: [TestComponent]})
export class TestModule {}
`);
const messages: string[] = [];
expect(
main(['-p', path.join(basePath, 'src/tsconfig.json')], message => messages.push(message)))
.toBe(0, `Compile failed:\n ${messages.join('\n ')}`);
});

it('should allow using 2 classes with the same name in declarations with noEmitOnError=true',
() => {
write('src/tsconfig.json', `{
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler/test/aot/static_reflector_spec.ts
Expand Up @@ -364,7 +364,8 @@ describe('StaticReflector', () => {
const classData: any = moduleMetadata['InvalidMetadata'];
expect(classData).toBeDefined();
simplify(
reflector.getStaticSymbol('/tmp/src/invalid-metadata.ts', ''), classData.decorators[0]);
reflector.getStaticSymbol('/tmp/src/invalid-metadata.ts', ''),
classData.decorators[0].arguments);
} catch (e) {
expect(e.position).toBeDefined();
threw = true;
Expand Down

0 comments on commit 12a119b

Please sign in to comment.