Skip to content

Commit a6996a9

Browse files
chuckjazIgorMinar
authored andcommitted
fix(tsc-wrapped): validate metadata in static members of a class (angular#14772)
Fixes angular#13481
1 parent 6bae737 commit a6996a9

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tools/@angular/tsc-wrapped/src/collector.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,16 @@ function validateMetadata(
581581
Object.getOwnPropertyNames(classData.members)
582582
.forEach(name => classData.members[name].forEach((m) => validateMember(classData, m)));
583583
}
584+
if (classData.statics) {
585+
Object.getOwnPropertyNames(classData.statics).forEach(name => {
586+
const staticMember = classData.statics[name];
587+
if (isFunctionMetadata(staticMember)) {
588+
validateExpression(staticMember.value);
589+
} else {
590+
validateExpression(staticMember);
591+
}
592+
});
593+
}
584594
}
585595

586596
function validateFunction(functionDeclaration: FunctionMetadata) {

tools/@angular/tsc-wrapped/test/collector.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('Collector', () => {
2828
'/promise.ts',
2929
'/unsupported-1.ts',
3030
'/unsupported-2.ts',
31+
'/unsupported-3.ts',
3132
'class-arity.ts',
3233
'import-star.ts',
3334
'exported-classes.ts',
@@ -621,10 +622,16 @@ describe('Collector', () => {
621622
});
622623

623624
it('should throw for references to unexpected types', () => {
624-
const unsupported1 = program.getSourceFile('/unsupported-2.ts');
625-
expect(() => collector.getMetadata(unsupported1, true))
625+
const unsupported2 = program.getSourceFile('/unsupported-2.ts');
626+
expect(() => collector.getMetadata(unsupported2, true))
626627
.toThrowError(/Reference to non-exported class/);
627628
});
629+
630+
it('should throw for errors in a static method', () => {
631+
const unsupported3 = program.getSourceFile('/unsupported-3.ts');
632+
expect(() => collector.getMetadata(unsupported3, true))
633+
.toThrowError(/Reference to a non-exported class/);
634+
});
628635
});
629636

630637
describe('with invalid input', () => {
@@ -911,6 +918,15 @@ const FILES: Directory = {
911918
constructor(private f: Foo) {}
912919
}
913920
`,
921+
'unsupported-3.ts': `
922+
class Foo {}
923+
924+
export class SomeClass {
925+
static someStatic() {
926+
return Foo;
927+
}
928+
}
929+
`,
914930
'import-star.ts': `
915931
import {Injectable} from 'angular2/core';
916932
import * as common from 'angular2/common';

0 commit comments

Comments
 (0)