Previously, we had tested that expressions parsed in a Render3 AST had correctly-defined absolute spans (spans relative to the entire template, not the local expression). Sometimes we use Template ASTs rather than Render3 ASTs, and it's desirable to test for correct expression spans in the template parser as well. Adding these tests resolved one bug, similar to the one fixed in fd4fed14d8935866fe16d30648d115f3ebb5fd43, where expressions in the value of a template attribute were not given an absolute span corresponding to the start of the attribute name rather than the start of the attribute value. The diff on this commit is large, partially because it involves some structural changes of the template parser testing layout. In particular, the following is done: 1. Move `createMeta*`-like functions from `template_parser_spec.ts` to be exported from a new test utility file. 2. Create an `ExpressionSourceHumanizer`, similar to the one created in b04488d692ca11c83444da56f51d53c3ac868243, to allow convenient testing of expressions' locations. 3. Create `template_parser_absolute_span_spec.ts`, testing the spans of expressions parsed by the template parser. This is very similar to the `r3_ast_absolute_span_spec`. PR Close #33253
63 lines
2.6 KiB
TypeScript
63 lines
2.6 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
import {CompileDirectiveMetadata, CompileEntryComponentMetadata, CompileProviderMetadata, CompileQueryMetadata, CompileStylesheetMetadata, CompileTemplateMetadata, CompileTypeMetadata, ProxyClass, StaticSymbol, preserveWhitespacesDefault} from '@angular/compiler';
|
|
import {ChangeDetectionStrategy, RendererType2, ViewEncapsulation} from '@angular/core';
|
|
import {noUndefined} from '../../../src/util';
|
|
|
|
export function createTypeMeta({reference, diDeps}: {reference: any, diDeps?: any[]}):
|
|
CompileTypeMetadata {
|
|
return {reference: reference, diDeps: diDeps || [], lifecycleHooks: []};
|
|
}
|
|
|
|
export function compileDirectiveMetadataCreate(
|
|
{isHost, type, isComponent, selector, exportAs, inputs, outputs, host, providers, viewProviders,
|
|
queries, guards, viewQueries, entryComponents, template, componentViewType,
|
|
rendererType}: Partial<Parameters<typeof CompileDirectiveMetadata.create>[0]>) {
|
|
return CompileDirectiveMetadata.create({
|
|
isHost: !!isHost,
|
|
type: noUndefined(type) !,
|
|
isComponent: !!isComponent,
|
|
selector: noUndefined(selector),
|
|
exportAs: noUndefined(exportAs),
|
|
changeDetection: null,
|
|
inputs: inputs || [],
|
|
outputs: outputs || [],
|
|
host: host || {},
|
|
providers: providers || [],
|
|
viewProviders: viewProviders || [],
|
|
queries: queries || [],
|
|
guards: guards || {},
|
|
viewQueries: viewQueries || [],
|
|
entryComponents: entryComponents || [],
|
|
template: noUndefined(template) !,
|
|
componentViewType: noUndefined(componentViewType),
|
|
rendererType: noUndefined(rendererType),
|
|
componentFactory: null,
|
|
});
|
|
}
|
|
|
|
export function compileTemplateMetadata(
|
|
{encapsulation, template, templateUrl, styles, styleUrls, externalStylesheets, animations,
|
|
ngContentSelectors, interpolation, isInline,
|
|
preserveWhitespaces}: Partial<CompileTemplateMetadata>): CompileTemplateMetadata {
|
|
return new CompileTemplateMetadata({
|
|
encapsulation: noUndefined(encapsulation),
|
|
template: noUndefined(template),
|
|
templateUrl: noUndefined(templateUrl),
|
|
htmlAst: null,
|
|
styles: styles || [],
|
|
styleUrls: styleUrls || [],
|
|
externalStylesheets: externalStylesheets || [],
|
|
animations: animations || [],
|
|
ngContentSelectors: ngContentSelectors || [],
|
|
interpolation: noUndefined(interpolation),
|
|
isInline: !!isInline,
|
|
preserveWhitespaces: preserveWhitespacesDefault(noUndefined(preserveWhitespaces)),
|
|
});
|
|
}
|