parent
d05df30a94
commit
f490565b09
|
@ -7,12 +7,13 @@ export function moduleRef(moduleId): string {
|
|||
}
|
||||
|
||||
export class SourceModule {
|
||||
constructor(public moduleId: string, public source: string) {}
|
||||
constructor(public moduleId: string, public sourceWithModuleRefs: string) {}
|
||||
|
||||
getSourceWithImports(): SourceWithImports {
|
||||
var moduleAliases = {};
|
||||
var imports: string[][] = [];
|
||||
var newSource = StringWrapper.replaceAllMapped(this.source, MODULE_REGEXP, (match) => {
|
||||
var newSource =
|
||||
StringWrapper.replaceAllMapped(this.sourceWithModuleRefs, MODULE_REGEXP, (match) => {
|
||||
var moduleId = match[1];
|
||||
var alias = moduleAliases[moduleId];
|
||||
if (isBlank(alias)) {
|
||||
|
|
|
@ -36,7 +36,7 @@ export class TemplateCompiler {
|
|||
private _commandCompiler: CommandCompiler,
|
||||
private _cdCompiler: ChangeDetectionCompiler) {}
|
||||
|
||||
normalizeDirective(directive: DirectiveMetadata): Promise<INormalizedDirectiveMetadata> {
|
||||
normalizeDirectiveMetadata(directive: DirectiveMetadata): Promise<INormalizedDirectiveMetadata> {
|
||||
var normalizedTemplatePromise;
|
||||
if (directive.isComponent) {
|
||||
normalizedTemplatePromise =
|
||||
|
@ -54,11 +54,11 @@ export class TemplateCompiler {
|
|||
}));
|
||||
}
|
||||
|
||||
serializeTemplateMetadata(metadata: INormalizedDirectiveMetadata): string {
|
||||
serializeDirectiveMetadata(metadata: INormalizedDirectiveMetadata): string {
|
||||
return Json.stringify((<NormalizedDirectiveMetadata>metadata).toJson());
|
||||
}
|
||||
|
||||
deserializeTemplateMetadata(data: string): INormalizedDirectiveMetadata {
|
||||
deserializeDirectiveMetadata(data: string): INormalizedDirectiveMetadata {
|
||||
return NormalizedDirectiveMetadata.fromJson(Json.parse(data));
|
||||
}
|
||||
|
||||
|
@ -87,9 +87,9 @@ export class TemplateCompiler {
|
|||
new CompiledTemplate(compMeta.type.id, () => [changeDetectorFactories, commands, styles]);
|
||||
this._compiledTemplateCache.set(compMeta.type.id, compiledTemplate);
|
||||
compilingComponentIds.add(compMeta.type.id);
|
||||
done =
|
||||
PromiseWrapper.all([this._styleCompiler.compileComponentRuntime(compMeta)].concat(
|
||||
viewDirectives.map(dirMeta => this.normalizeDirective(dirMeta))))
|
||||
done = PromiseWrapper.all([this._styleCompiler.compileComponentRuntime(compMeta)].concat(
|
||||
viewDirectives.map(
|
||||
dirMeta => this.normalizeDirectiveMetadata(dirMeta))))
|
||||
.then((stylesAndNormalizedViewDirMetas: any[]) => {
|
||||
var childPromises = [];
|
||||
var normalizedViewDirMetas = stylesAndNormalizedViewDirMetas.slice(1);
|
||||
|
|
|
@ -94,7 +94,6 @@ export class DirectiveResolver {
|
|||
events: mergedEvents,
|
||||
host: mergedHost,
|
||||
dynamicLoadable: dm.dynamicLoadable,
|
||||
compiledHostTemplate: dm.compiledHostTemplate,
|
||||
bindings: dm.bindings,
|
||||
exportAs: dm.exportAs,
|
||||
moduleId: dm.moduleId,
|
||||
|
|
|
@ -808,13 +808,6 @@ export class ComponentMetadata extends DirectiveMetadata {
|
|||
*/
|
||||
dynamicLoadable: boolean;
|
||||
|
||||
|
||||
/**
|
||||
* Used by build tools to store the compiled template.
|
||||
* Not intended to be used by a user.
|
||||
*/
|
||||
compiledHostTemplate: /* CompiledTemplate */ any;
|
||||
|
||||
/**
|
||||
* Defines the used change detection strategy.
|
||||
*
|
||||
|
@ -868,15 +861,14 @@ export class ComponentMetadata extends DirectiveMetadata {
|
|||
*/
|
||||
viewBindings: any[];
|
||||
|
||||
constructor({selector, properties, events, host, dynamicLoadable, compiledHostTemplate, exportAs,
|
||||
moduleId, bindings, viewBindings, changeDetection = ChangeDetectionStrategy.Default,
|
||||
constructor({selector, properties, events, host, dynamicLoadable, exportAs, moduleId, bindings,
|
||||
viewBindings, changeDetection = ChangeDetectionStrategy.Default,
|
||||
compileChildren = true}: {
|
||||
selector?: string,
|
||||
properties?: string[],
|
||||
events?: string[],
|
||||
host?: StringMap<string, string>,
|
||||
dynamicLoadable?: boolean,
|
||||
compiledHostTemplate?: any,
|
||||
bindings?: any[],
|
||||
exportAs?: string,
|
||||
moduleId?: string,
|
||||
|
@ -898,7 +890,6 @@ export class ComponentMetadata extends DirectiveMetadata {
|
|||
this.changeDetection = changeDetection;
|
||||
this.viewBindings = viewBindings;
|
||||
this.dynamicLoadable = dynamicLoadable;
|
||||
this.compiledHostTemplate = compiledHostTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ export class MockDirectiveResolver extends DirectiveResolver {
|
|||
events: dm.events,
|
||||
host: dm.host,
|
||||
dynamicLoadable: dm.dynamicLoadable,
|
||||
compiledHostTemplate: dm.compiledHostTemplate,
|
||||
bindings: bindings,
|
||||
exportAs: dm.exportAs,
|
||||
moduleId: dm.moduleId,
|
||||
|
|
|
@ -210,7 +210,7 @@ function testableExpression(source: SourceExpression): SourceModule {
|
|||
}
|
||||
|
||||
function testableModule(sourceModule: SourceModule): SourceModule {
|
||||
var testableSource = `${sourceModule.source}
|
||||
var testableSource = `${sourceModule.sourceWithModuleRefs}
|
||||
${codeGenExportVariable('run')}${codeGenValueFn(['_'], 'STYLES')};`;
|
||||
return new SourceModule(sourceModule.moduleId, testableSource);
|
||||
}
|
||||
|
|
|
@ -143,8 +143,8 @@ export function main() {
|
|||
Promise<NormalizedComponentWithViewDirectives> {
|
||||
var compAndViewDirMetas = [runtimeMetadataResolver.getMetadata(component)].concat(
|
||||
runtimeMetadataResolver.getViewDirectivesMetadata(component));
|
||||
return PromiseWrapper.all(compAndViewDirMetas.map(meta =>
|
||||
compiler.normalizeDirective(meta)))
|
||||
return PromiseWrapper.all(compAndViewDirMetas.map(
|
||||
meta => compiler.normalizeDirectiveMetadata(meta)))
|
||||
.then((normalizedCompAndViewDirMetas: NormalizedDirectiveMetadata[]) =>
|
||||
new NormalizedComponentWithViewDirectives(
|
||||
normalizedCompAndViewDirMetas[0],
|
||||
|
@ -169,16 +169,16 @@ export function main() {
|
|||
|
||||
});
|
||||
|
||||
describe('serializeTemplateMetadata and deserializeTemplateMetadata', () => {
|
||||
describe('serializeDirectiveMetadata and deserializeDirectiveMetadata', () => {
|
||||
it('should serialize and deserialize', inject([AsyncTestCompleter], (async) => {
|
||||
compiler.normalizeDirective(
|
||||
compiler.normalizeDirectiveMetadata(
|
||||
runtimeMetadataResolver.getMetadata(CompWithBindingsAndStyles))
|
||||
.then((meta: NormalizedDirectiveMetadata) => {
|
||||
var json = compiler.serializeTemplateMetadata(meta);
|
||||
var json = compiler.serializeDirectiveMetadata(meta);
|
||||
expect(isString(json)).toBe(true);
|
||||
// Note: serializing will clear our the runtime type!
|
||||
var clonedMeta =
|
||||
<NormalizedDirectiveMetadata>compiler.deserializeTemplateMetadata(json);
|
||||
<NormalizedDirectiveMetadata>compiler.deserializeDirectiveMetadata(json);
|
||||
expect(meta.changeDetection).toEqual(clonedMeta.changeDetection);
|
||||
expect(meta.template).toEqual(clonedMeta.template);
|
||||
expect(meta.selector).toEqual(clonedMeta.selector);
|
||||
|
@ -188,11 +188,12 @@ export function main() {
|
|||
}));
|
||||
});
|
||||
|
||||
describe('normalizeDirective', () => {
|
||||
describe('normalizeDirectiveMetadata', () => {
|
||||
it('should normalize the template',
|
||||
inject([AsyncTestCompleter, XHR], (async, xhr: MockXHR) => {
|
||||
xhr.expect('angular2/test/compiler/compUrl.html', 'loadedTemplate');
|
||||
compiler.normalizeDirective(runtimeMetadataResolver.getMetadata(CompWithTemplateUrl))
|
||||
compiler.normalizeDirectiveMetadata(
|
||||
runtimeMetadataResolver.getMetadata(CompWithTemplateUrl))
|
||||
.then((meta: NormalizedDirectiveMetadata) => {
|
||||
expect(meta.template.template).toEqual('loadedTemplate');
|
||||
async.done();
|
||||
|
@ -202,7 +203,8 @@ export function main() {
|
|||
|
||||
it('should copy all the other fields', inject([AsyncTestCompleter], (async) => {
|
||||
var meta = runtimeMetadataResolver.getMetadata(CompWithBindingsAndStyles);
|
||||
compiler.normalizeDirective(meta).then((normMeta: NormalizedDirectiveMetadata) => {
|
||||
compiler.normalizeDirectiveMetadata(meta)
|
||||
.then((normMeta: NormalizedDirectiveMetadata) => {
|
||||
expect(normMeta.selector).toEqual(meta.selector);
|
||||
expect(normMeta.dynamicLoadable).toEqual(meta.dynamicLoadable);
|
||||
expect(normMeta.isComponent).toEqual(meta.isComponent);
|
||||
|
@ -262,13 +264,13 @@ function testableTemplateModule(sourceModule: SourceModule, comp: INormalizedDir
|
|||
SourceModule {
|
||||
var normComp = <NormalizedDirectiveMetadata>comp;
|
||||
var resultExpression = `${THIS_MODULE_REF}humanizeTemplate(Host${normComp.type.name}Template)`;
|
||||
var testableSource = `${sourceModule.source}
|
||||
var testableSource = `${sourceModule.sourceWithModuleRefs}
|
||||
${codeGenExportVariable('run')}${codeGenValueFn(['_'], resultExpression)};`;
|
||||
return new SourceModule(sourceModule.moduleId, testableSource);
|
||||
}
|
||||
|
||||
function testableStylesModule(sourceModule: SourceModule): SourceModule {
|
||||
var testableSource = `${sourceModule.source}
|
||||
var testableSource = `${sourceModule.sourceWithModuleRefs}
|
||||
${codeGenExportVariable('run')}${codeGenValueFn(['_'], 'STYLES')};`;
|
||||
return new SourceModule(sourceModule.moduleId, testableSource);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue