feat(compiler): assert that Component.style is an array
Part of #7481 (effort to improve error messages) Closes #7559
This commit is contained in:
3
modules/angular2/src/compiler/assertions.dart
Normal file
3
modules/angular2/src/compiler/assertions.dart
Normal file
@ -0,0 +1,3 @@
|
||||
library angular2.core.util.asserions;
|
||||
|
||||
void assertArrayOfStrings(String identifier, Object value) {}
|
16
modules/angular2/src/compiler/assertions.ts
Normal file
16
modules/angular2/src/compiler/assertions.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import {isArray, isString, isBlank, assertionsEnabled} from '../facade/lang';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
|
||||
export function assertArrayOfStrings(identifier: string, value: any) {
|
||||
if (!assertionsEnabled() || isBlank(value)) {
|
||||
return;
|
||||
}
|
||||
if (!isArray(value)) {
|
||||
throw new BaseException(`Expected '${identifier}' to be an array of strings.`);
|
||||
}
|
||||
for (var i = 0; i < value.length; i += 1) {
|
||||
if (!isString(value[i])) {
|
||||
throw new BaseException(`Expected '${identifier}' to be an array of strings.`);
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import {reflector} from 'angular2/src/core/reflection/reflection';
|
||||
import {Injectable, Inject, Optional} from 'angular2/src/core/di';
|
||||
import {PLATFORM_DIRECTIVES, PLATFORM_PIPES} from 'angular2/src/core/platform_directives_and_pipes';
|
||||
import {MODULE_SUFFIX} from './util';
|
||||
import {assertArrayOfStrings} from './assertions';
|
||||
import {getUrlScheme} from 'angular2/src/compiler/url_resolver';
|
||||
|
||||
@Injectable()
|
||||
@ -41,9 +42,11 @@ export class RuntimeMetadataResolver {
|
||||
var changeDetectionStrategy = null;
|
||||
|
||||
if (dirMeta instanceof md.ComponentMetadata) {
|
||||
assertArrayOfStrings('styles', dirMeta.styles);
|
||||
var cmpMeta = <md.ComponentMetadata>dirMeta;
|
||||
moduleUrl = calcModuleUrl(directiveType, cmpMeta);
|
||||
var viewMeta = this._viewResolver.resolve(directiveType);
|
||||
assertArrayOfStrings('styles', viewMeta.styles);
|
||||
templateMeta = new cpl.CompileTemplateMetadata({
|
||||
encapsulation: viewMeta.encapsulation,
|
||||
template: viewMeta.template,
|
||||
|
Reference in New Issue
Block a user