refactor(core): do not remove templateUrl when resolving (#28055)

When we resolve a component `templateUrl` we copy the contents of the
resolved template file into the `template` property.

Previously we would then remove the `templateUrl` to indicate that
the component has been resolved. But this meant that we no longer had
access to the URL of the original template file. This is essential for
diagnostics messages about the template compilation.

Now the existence of the `template` property overrides the existence of
`templateUrl`, which allows us to keep the `templateUrl` property.

PR Close #28055
This commit is contained in:
Pete Bacon Darwin 2019-02-08 22:10:19 +00:00 committed by Misko Hevery
parent 8d15dd8b70
commit 8c3f1717a8
2 changed files with 6 additions and 7 deletions

View File

@ -62,7 +62,6 @@ export function resolveComponentResources(
if (component.templateUrl) {
cachedResourceResolve(component.templateUrl).then((template) => {
component.template = template;
component.templateUrl = undefined;
});
}
const styleUrls = component.styleUrls;
@ -92,7 +91,9 @@ export function maybeQueueResolutionOfComponentResources(metadata: Component) {
}
export function componentNeedsResolution(component: Component): boolean {
return !!(component.templateUrl || component.styleUrls && component.styleUrls.length);
return !!(
(component.templateUrl && !component.template) ||
component.styleUrls && component.styleUrls.length);
}
export function clearResolutionOfComponentResourcesQueue() {
componentResourceResolutionQueue.clear();

View File

@ -64,7 +64,6 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
compileComponent(MyComponent, metadata);
await resolveComponentResources(testResolver);
expect(MyComponent.ngComponentDef).toBeDefined();
expect(metadata.templateUrl).toBe(undefined);
expect(metadata.template).toBe('content');
expect(resourceFetchCount).toBe(1);
});
@ -127,7 +126,6 @@ Did you run and wait for 'resolveComponentResources()'?`.trim());
compileComponent(MyComponent, metadata);
await resolveComponentResources(fetch);
expect(MyComponent.ngComponentDef).toBeDefined();
expect(metadata.templateUrl).toBe(undefined);
expect(metadata.template).toBe('response for test://content');
});
});