fix(tsc-wrapped): validate metadata in static members of a class (#14772)

Fixes #13481
This commit is contained in:
Chuck Jazdzewski 2017-03-01 14:45:00 -08:00 committed by Igor Minar
parent 6bae7378b1
commit a6996a9cdd
2 changed files with 28 additions and 2 deletions

View File

@ -581,6 +581,16 @@ function validateMetadata(
Object.getOwnPropertyNames(classData.members) Object.getOwnPropertyNames(classData.members)
.forEach(name => classData.members[name].forEach((m) => validateMember(classData, m))); .forEach(name => classData.members[name].forEach((m) => validateMember(classData, m)));
} }
if (classData.statics) {
Object.getOwnPropertyNames(classData.statics).forEach(name => {
const staticMember = classData.statics[name];
if (isFunctionMetadata(staticMember)) {
validateExpression(staticMember.value);
} else {
validateExpression(staticMember);
}
});
}
} }
function validateFunction(functionDeclaration: FunctionMetadata) { function validateFunction(functionDeclaration: FunctionMetadata) {

View File

@ -28,6 +28,7 @@ describe('Collector', () => {
'/promise.ts', '/promise.ts',
'/unsupported-1.ts', '/unsupported-1.ts',
'/unsupported-2.ts', '/unsupported-2.ts',
'/unsupported-3.ts',
'class-arity.ts', 'class-arity.ts',
'import-star.ts', 'import-star.ts',
'exported-classes.ts', 'exported-classes.ts',
@ -621,10 +622,16 @@ describe('Collector', () => {
}); });
it('should throw for references to unexpected types', () => { it('should throw for references to unexpected types', () => {
const unsupported1 = program.getSourceFile('/unsupported-2.ts'); const unsupported2 = program.getSourceFile('/unsupported-2.ts');
expect(() => collector.getMetadata(unsupported1, true)) expect(() => collector.getMetadata(unsupported2, true))
.toThrowError(/Reference to non-exported class/); .toThrowError(/Reference to non-exported class/);
}); });
it('should throw for errors in a static method', () => {
const unsupported3 = program.getSourceFile('/unsupported-3.ts');
expect(() => collector.getMetadata(unsupported3, true))
.toThrowError(/Reference to a non-exported class/);
});
}); });
describe('with invalid input', () => { describe('with invalid input', () => {
@ -911,6 +918,15 @@ const FILES: Directory = {
constructor(private f: Foo) {} constructor(private f: Foo) {}
} }
`, `,
'unsupported-3.ts': `
class Foo {}
export class SomeClass {
static someStatic() {
return Foo;
}
}
`,
'import-star.ts': ` 'import-star.ts': `
import {Injectable} from 'angular2/core'; import {Injectable} from 'angular2/core';
import * as common from 'angular2/common'; import * as common from 'angular2/common';