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