Skip to content
Permalink
Browse files

refactor(ivy): split apart the 'metadata' package in the ngtsc compil…

…er (#27743)

This refactoring moves code around between a few of the ngtsc subpackages,
with the goal of having a more logical package structure. Additional
interfaces are also introduced where they make sense.

The 'metadata' package formerly contained both the partial evaluator,
the TypeScriptReflectionHost as well as some other reflection functions,
and the Reference interface and various implementations. This package
was split into 3 parts.

The partial evaluator now has its own package 'partial_evaluator', and
exists behind an interface PartialEvaluator instead of a top-level
function. In the future this will be useful for reducing churn as the
partial evaluator becomes more complicated.

The TypeScriptReflectionHost and other miscellaneous functions have moved
into a new 'reflection' package. The former 'host' package which contained
the ReflectionHost interface and associated types was also merged into this
new 'reflection' package.

Finally, the Reference APIs were moved to the 'imports' package, which will
consolidate all import-related logic in ngtsc.

PR Close #27743
  • Loading branch information...
alxhub authored and kara committed Dec 18, 2018
1 parent 37b716b commit 2a6108af97e2f54a8c96890b3ecd66c566b845f6
Showing with 534 additions and 433 deletions.
  1. +2 −1 packages/compiler-cli/BUILD.bazel
  2. +3 −2 packages/compiler-cli/src/ngcc/BUILD.bazel
  3. +7 −5 packages/compiler-cli/src/ngcc/src/analysis/decoration_analyzer.ts
  4. +2 −2 packages/compiler-cli/src/ngcc/src/analysis/module_with_providers_analyzer.ts
  5. +2 −2 packages/compiler-cli/src/ngcc/src/analysis/ngcc_references_registry.ts
  6. +1 −1 packages/compiler-cli/src/ngcc/src/analysis/private_declarations_analyzer.ts
  7. +1 −1 packages/compiler-cli/src/ngcc/src/host/decorated_class.ts
  8. +1 −2 packages/compiler-cli/src/ngcc/src/host/esm2015_host.ts
  9. +1 −2 packages/compiler-cli/src/ngcc/src/host/esm5_host.ts
  10. +1 −1 packages/compiler-cli/src/ngcc/src/host/ngcc_host.ts
  11. +0 −1 packages/compiler-cli/src/ngcc/src/rendering/renderer.ts
  12. +3 −2 packages/compiler-cli/src/ngcc/test/BUILD.bazel
  13. +1 −1 packages/compiler-cli/src/ngcc/test/analysis/decoration_analyzer_spec.ts
  14. +1 −1 packages/compiler-cli/src/ngcc/test/analysis/private_declarations_analyzer_spec.ts
  15. +5 −3 packages/compiler-cli/src/ngcc/test/analysis/references_registry_spec.ts
  16. +1 −1 packages/compiler-cli/src/ngcc/test/host/esm2015_host_import_helper_spec.ts
  17. +1 −1 packages/compiler-cli/src/ngcc/test/host/esm2015_host_spec.ts
  18. +1 −1 packages/compiler-cli/src/ngcc/test/host/esm5_host_import_helper_spec.ts
  19. +1 −1 packages/compiler-cli/src/ngcc/test/host/esm5_host_spec.ts
  20. +3 −2 packages/compiler-cli/src/ngtsc/annotations/BUILD.bazel
  21. +5 −5 packages/compiler-cli/src/ngtsc/annotations/src/base_def.ts
  22. +16 −16 packages/compiler-cli/src/ngtsc/annotations/src/component.ts
  23. +38 −38 packages/compiler-cli/src/ngtsc/annotations/src/directive.ts
  24. +1 −2 packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts
  25. +1 −1 packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts
  26. +10 −11 packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts
  27. +5 −5 packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts
  28. +2 −2 packages/compiler-cli/src/ngtsc/annotations/src/references_registry.ts
  29. +3 −4 packages/compiler-cli/src/ngtsc/annotations/src/selector_scope.ts
  30. +3 −3 packages/compiler-cli/src/ngtsc/annotations/src/util.ts
  31. +3 −1 packages/compiler-cli/src/ngtsc/annotations/test/BUILD.bazel
  32. +5 −2 packages/compiler-cli/src/ngtsc/annotations/test/component_spec.ts
  33. +2 −2 packages/compiler-cli/src/ngtsc/annotations/test/metadata_spec.ts
  34. +3 −3 packages/compiler-cli/src/ngtsc/annotations/test/selector_scope_spec.ts
  35. +18 −0 packages/compiler-cli/src/ngtsc/imports/BUILD.bazel
  36. +1 −1 packages/compiler-cli/src/ngtsc/{host → imports}/index.ts
  37. +150 −0 packages/compiler-cli/src/ngtsc/imports/src/references.ts
  38. +0 −12 packages/compiler-cli/src/ngtsc/metadata/index.ts
  39. +4 −3 packages/compiler-cli/src/ngtsc/{metadata → partial_evaluator}/BUILD.bazel
  40. +10 −0 packages/compiler-cli/src/ngtsc/partial_evaluator/index.ts
  41. +21 −0 packages/compiler-cli/src/ngtsc/partial_evaluator/src/builtin.ts
  42. +31 −0 packages/compiler-cli/src/ngtsc/partial_evaluator/src/interface.ts
  43. +5 −246 packages/compiler-cli/src/ngtsc/{metadata/src/resolver.ts → partial_evaluator/src/interpreter.ts}
  44. +79 −0 packages/compiler-cli/src/ngtsc/partial_evaluator/src/result.ts
  45. +29 −0 packages/compiler-cli/src/ngtsc/partial_evaluator/test/BUILD.bazel
  46. +20 −10 ...ompiler-cli/src/ngtsc/{metadata/test/resolver_spec.ts → partial_evaluator/test/evaluator_spec.ts}
  47. +8 −7 packages/compiler-cli/src/ngtsc/program.ts
  48. +2 −2 packages/compiler-cli/src/ngtsc/{host → reflection}/BUILD.bazel
  49. +10 −0 packages/compiler-cli/src/ngtsc/reflection/index.ts
  50. 0 packages/compiler-cli/src/ngtsc/{host/src/reflection.ts → reflection/src/host.ts}
  51. +1 −1 packages/compiler-cli/src/ngtsc/{metadata/src/reflector.ts → reflection/src/typescript.ts}
  52. +1 −3 packages/compiler-cli/src/ngtsc/{metadata → reflection}/test/BUILD.bazel
  53. +2 −2 packages/compiler-cli/src/ngtsc/{metadata/test/reflector_spec.ts → reflection/test/ts_host_spec.ts}
  54. +0 −2 packages/compiler-cli/src/ngtsc/shims/BUILD.bazel
  55. +0 −1 packages/compiler-cli/src/ngtsc/shims/src/host.ts
  56. +0 −3 packages/compiler-cli/src/ngtsc/switch/BUILD.bazel
  57. +1 −2 packages/compiler-cli/src/ngtsc/transform/BUILD.bazel
  58. +1 −1 packages/compiler-cli/src/ngtsc/transform/src/api.ts
  59. +1 −2 packages/compiler-cli/src/ngtsc/transform/src/compilation.ts
  60. +1 −2 packages/compiler-cli/src/ngtsc/transform/src/transform.ts
  61. +1 −1 packages/compiler-cli/src/ngtsc/typecheck/BUILD.bazel
  62. +1 −1 packages/compiler-cli/src/ngtsc/typecheck/src/api.ts
  63. +1 −1 packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
  64. +0 −2 packages/compiler-cli/src/ngtsc/typecheck/test/BUILD.bazel
@@ -27,7 +27,8 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/annotations",
"//packages/compiler-cli/src/ngtsc/diagnostics",
"//packages/compiler-cli/src/ngtsc/entry_point",
"//packages/compiler-cli/src/ngtsc/metadata",
"//packages/compiler-cli/src/ngtsc/partial_evaluator",
"//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/shims",
"//packages/compiler-cli/src/ngtsc/switch",
"//packages/compiler-cli/src/ngtsc/transform",
@@ -13,8 +13,9 @@ ts_library(
"//packages:types",
"//packages/compiler",
"//packages/compiler-cli/src/ngtsc/annotations",
"//packages/compiler-cli/src/ngtsc/host",
"//packages/compiler-cli/src/ngtsc/metadata",
"//packages/compiler-cli/src/ngtsc/imports",
"//packages/compiler-cli/src/ngtsc/partial_evaluator",
"//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/transform",
"//packages/compiler-cli/src/ngtsc/translator",
"@ngdeps//@types/convert-source-map",
@@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ConstantPool} from '@angular/compiler';
import {PartialEvaluator} from '@angular/compiler-cli/src/ngtsc/partial_evaluator';
import * as path from 'canonical-path';
import * as fs from 'fs';
import * as ts from 'typescript';
@@ -59,16 +60,17 @@ export class FileResourceLoader implements ResourceLoader {
export class DecorationAnalyzer {
resourceLoader = new FileResourceLoader();
scopeRegistry = new SelectorScopeRegistry(this.typeChecker, this.host);
evaluator = new PartialEvaluator(this.host, this.typeChecker);
handlers: DecoratorHandler<any, any>[] = [
new BaseDefDecoratorHandler(this.typeChecker, this.host),
new BaseDefDecoratorHandler(this.host, this.evaluator),
new ComponentDecoratorHandler(
this.typeChecker, this.host, this.scopeRegistry, this.isCore, this.resourceLoader,
this.host, this.evaluator, this.scopeRegistry, this.isCore, this.resourceLoader,
this.rootDirs, /* defaultPreserveWhitespaces */ false, /* i18nUseExternalIds */ true),
new DirectiveDecoratorHandler(this.typeChecker, this.host, this.scopeRegistry, this.isCore),
new DirectiveDecoratorHandler(this.host, this.evaluator, this.scopeRegistry, this.isCore),
new InjectableDecoratorHandler(this.host, this.isCore),
new NgModuleDecoratorHandler(
this.typeChecker, this.host, this.scopeRegistry, this.referencesRegistry, this.isCore),
new PipeDecoratorHandler(this.typeChecker, this.host, this.scopeRegistry, this.isCore),
this.host, this.evaluator, this.scopeRegistry, this.referencesRegistry, this.isCore),
new PipeDecoratorHandler(this.host, this.evaluator, this.scopeRegistry, this.isCore),
];

constructor(
@@ -8,8 +8,8 @@
import * as ts from 'typescript';

import {ReferencesRegistry} from '../../../ngtsc/annotations';
import {Declaration} from '../../../ngtsc/host';
import {ResolvedReference} from '../../../ngtsc/metadata';
import {ResolvedReference} from '../../../ngtsc/imports';
import {Declaration} from '../../../ngtsc/reflection';
import {NgccReflectionHost} from '../host/ngcc_host';
import {isDefined} from '../utils';

@@ -8,8 +8,8 @@

import * as ts from 'typescript';
import {ReferencesRegistry} from '../../../ngtsc/annotations';
import {Declaration, ReflectionHost} from '../../../ngtsc/host';
import {Reference, ResolvedReference} from '../../../ngtsc/metadata';
import {Reference, ResolvedReference} from '../../../ngtsc/imports';
import {Declaration, ReflectionHost} from '../../../ngtsc/reflection';
import {hasNameIdentifier} from '../utils';

/**
@@ -8,7 +8,7 @@
import * as ts from 'typescript';

import {ReferencesRegistry} from '../../../ngtsc/annotations';
import {Declaration} from '../../../ngtsc/host';
import {Declaration} from '../../../ngtsc/reflection';
import {NgccReflectionHost} from '../host/ngcc_host';
import {hasNameIdentifier, isDefined} from '../utils';

@@ -7,7 +7,7 @@
*/

import * as ts from 'typescript';
import {Decorator} from '../../../ngtsc/host';
import {Decorator} from '../../../ngtsc/reflection';

/**
* A simple container that holds the details of a decorated class that has been
@@ -8,8 +8,7 @@

import * as ts from 'typescript';

import {ClassMember, ClassMemberKind, CtorParameter, Decorator, Import} from '../../../ngtsc/host';
import {TypeScriptReflectionHost, reflectObjectLiteral} from '../../../ngtsc/metadata';
import {ClassMember, ClassMemberKind, CtorParameter, Decorator, Import, TypeScriptReflectionHost, reflectObjectLiteral} from '../../../ngtsc/reflection';
import {BundleProgram} from '../packages/bundle_program';
import {findAll, getNameText, isDefined} from '../utils';

@@ -8,8 +8,7 @@

import * as ts from 'typescript';

import {ClassMember, ClassMemberKind, Decorator, FunctionDefinition, Parameter} from '../../../ngtsc/host';
import {reflectObjectLiteral} from '../../../ngtsc/metadata';
import {ClassMember, ClassMemberKind, Decorator, FunctionDefinition, Parameter, reflectObjectLiteral} from '../../../ngtsc/reflection';
import {getNameText} from '../utils';

import {Esm2015ReflectionHost, ParamInfo, getPropertyValueFromSymbol, isAssignmentStatement} from './esm2015_host';
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as ts from 'typescript';
import {ReflectionHost} from '../../../ngtsc/host';
import {ReflectionHost} from '../../../ngtsc/reflection';
import {DecoratedClass} from './decorated_class';

export const PRE_R3_MARKER = '__PRE_R3__';
@@ -13,7 +13,6 @@ import {basename, dirname, relative, resolve} from 'canonical-path';
import {SourceMapConsumer, SourceMapGenerator, RawSourceMap} from 'source-map';
import * as ts from 'typescript';

import {Decorator} from '../../../ngtsc/host';
import {CompileResult} from '@angular/compiler-cli/src/ngtsc/transform';
import {translateStatement, translateType, ImportManager} from '../../../ngtsc/translator';
import {NgccImportManager} from './ngcc_import_manager';
@@ -10,8 +10,9 @@ ts_library(
]),
deps = [
"//packages/compiler-cli/src/ngcc",
"//packages/compiler-cli/src/ngtsc/host",
"//packages/compiler-cli/src/ngtsc/metadata",
"//packages/compiler-cli/src/ngtsc/imports",
"//packages/compiler-cli/src/ngtsc/partial_evaluator",
"//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/testing",
"//packages/compiler-cli/src/ngtsc/transform",
"@ngdeps//@types/convert-source-map",
@@ -7,7 +7,7 @@
*/
import * as ts from 'typescript';

import {Decorator} from '../../../ngtsc/host';
import {Decorator} from '../../../ngtsc/reflection';
import {DecoratorHandler} from '../../../ngtsc/transform';
import {DecorationAnalyses, DecorationAnalyzer} from '../../src/analysis/decoration_analyzer';
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
@@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ResolvedReference} from '@angular/compiler-cli/src/ngtsc/metadata';
import * as ts from 'typescript';

import {ResolvedReference} from '../../../ngtsc/imports';
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';
import {PrivateDeclarationsAnalyzer} from '../../src/analysis/private_declarations_analyzer';
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
@@ -8,7 +8,9 @@

import * as ts from 'typescript';

import {Reference, TypeScriptReflectionHost, staticallyResolve} from '../../../ngtsc/metadata';
import {Reference} from '../../../ngtsc/imports';
import {PartialEvaluator} from '../../../ngtsc/partial_evaluator';
import {TypeScriptReflectionHost} from '../../../ngtsc/reflection';
import {getDeclaration, makeProgram} from '../../../ngtsc/testing/in_memory_typescript';
import {NgccReferencesRegistry} from '../../src/analysis/ngcc_references_registry';

@@ -37,10 +39,10 @@ describe('NgccReferencesRegistry', () => {
const testArrayExpression = testArrayDeclaration.initializer !;

const host = new TypeScriptReflectionHost(checker);
const evaluator = new PartialEvaluator(host, checker);
const registry = new NgccReferencesRegistry(host);

const references =
staticallyResolve(testArrayExpression, host, checker) as Reference<ts.Declaration>[];
const references = evaluator.evaluate(testArrayExpression) as Reference<ts.Declaration>[];
registry.add(...references);

const map = registry.getDeclarationMap();
@@ -8,7 +8,7 @@

import * as ts from 'typescript';

import {ClassMemberKind, Import} from '../../../ngtsc/host';
import {ClassMemberKind, Import} from '../../../ngtsc/reflection';
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils';

@@ -8,7 +8,7 @@

import * as ts from 'typescript';

import {ClassMemberKind, Import} from '../../../ngtsc/host';
import {ClassMemberKind, Import} from '../../../ngtsc/reflection';
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
import {getDeclaration, makeTestBundleProgram, makeTestProgram} from '../helpers/utils';

@@ -8,7 +8,7 @@

import * as ts from 'typescript';

import {ClassMemberKind, Import} from '../../../ngtsc/host';
import {ClassMemberKind, Import} from '../../../ngtsc/reflection';
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
import {convertToDirectTsLibImport, getDeclaration, makeTestProgram} from '../helpers/utils';

@@ -8,7 +8,7 @@

import * as ts from 'typescript';

import {ClassMemberKind, Import} from '../../../ngtsc/host';
import {ClassMemberKind, Import} from '../../../ngtsc/reflection';
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
import {Esm5ReflectionHost} from '../../src/host/esm5_host';
import {getDeclaration, makeTestProgram} from '../helpers/utils';
@@ -12,8 +12,9 @@ ts_library(
deps = [
"//packages/compiler",
"//packages/compiler-cli/src/ngtsc/diagnostics",
"//packages/compiler-cli/src/ngtsc/host",
"//packages/compiler-cli/src/ngtsc/metadata",
"//packages/compiler-cli/src/ngtsc/imports",
"//packages/compiler-cli/src/ngtsc/partial_evaluator",
"//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/transform",
"//packages/compiler-cli/src/ngtsc/typecheck",
"@ngdeps//@types/node",
@@ -9,8 +9,8 @@
import {R3BaseRefMetaData, compileBaseDefFromMetadata} from '@angular/compiler';
import * as ts from 'typescript';

import {ClassMember, Decorator, ReflectionHost} from '../../host';
import {staticallyResolve} from '../../metadata';
import {PartialEvaluator} from '../../partial_evaluator';
import {ClassMember, Decorator, ReflectionHost} from '../../reflection';
import {AnalysisOutput, CompileResult, DecoratorHandler} from '../../transform';
import {isAngularCore} from './util';

@@ -26,7 +26,7 @@ function containsNgTopLevelDecorator(decorators: Decorator[] | null): boolean {

export class BaseDefDecoratorHandler implements
DecoratorHandler<R3BaseRefMetaData, R3BaseRefDecoratorDetection> {
constructor(private checker: ts.TypeChecker, private reflector: ReflectionHost, ) {}
constructor(private reflector: ReflectionHost, private evaluator: PartialEvaluator) {}

detect(node: ts.ClassDeclaration, decorators: Decorator[]|null): R3BaseRefDecoratorDetection
|undefined {
@@ -69,7 +69,7 @@ export class BaseDefDecoratorHandler implements
const args = decorator.args;
let value: string|[string, string];
if (args && args.length > 0) {
const resolvedValue = staticallyResolve(args[0], this.reflector, this.checker);
const resolvedValue = this.evaluator.evaluate(args[0]);
if (typeof resolvedValue !== 'string') {
throw new TypeError('Input alias does not resolve to a string value');
}
@@ -88,7 +88,7 @@ export class BaseDefDecoratorHandler implements
const args = decorator.args;
let value: string;
if (args && args.length > 0) {
const resolvedValue = staticallyResolve(args[0], this.reflector, this.checker);
const resolvedValue = this.evaluator.evaluate(args[0]);
if (typeof resolvedValue !== 'string') {
throw new TypeError('Output alias does not resolve to a string value');
}
@@ -11,8 +11,9 @@ import * as path from 'path';
import * as ts from 'typescript';

import {ErrorCode, FatalDiagnosticError} from '../../diagnostics';
import {Decorator, ReflectionHost} from '../../host';
import {AbsoluteReference, Reference, ResolvedReference, filterToMembersWithDecorator, reflectObjectLiteral, staticallyResolve} from '../../metadata';
import {ResolvedReference} from '../../imports';
import {PartialEvaluator} from '../../partial_evaluator';
import {Decorator, ReflectionHost, filterToMembersWithDecorator, reflectObjectLiteral} from '../../reflection';
import {AnalysisOutput, CompileResult, DecoratorHandler} from '../../transform';
import {TypeCheckContext, TypeCheckableDirectiveMeta} from '../../typecheck';

@@ -37,7 +38,7 @@ export interface ComponentHandlerData {
export class ComponentDecoratorHandler implements
DecoratorHandler<ComponentHandlerData, Decorator> {
constructor(
private checker: ts.TypeChecker, private reflector: ReflectionHost,
private reflector: ReflectionHost, private evaluator: PartialEvaluator,
private scopeRegistry: SelectorScopeRegistry, private isCore: boolean,
private resourceLoader: ResourceLoader, private rootDirs: string[],
private defaultPreserveWhitespaces: boolean, private i18nUseExternalIds: boolean) {}
@@ -62,7 +63,7 @@ export class ComponentDecoratorHandler implements

if (this.resourceLoader.preload !== undefined && component.has('templateUrl')) {
const templateUrlExpr = component.get('templateUrl') !;
const templateUrl = staticallyResolve(templateUrlExpr, this.reflector, this.checker);
const templateUrl = this.evaluator.evaluate(templateUrlExpr);
if (typeof templateUrl !== 'string') {
throw new FatalDiagnosticError(
ErrorCode.VALUE_HAS_WRONG_TYPE, templateUrlExpr, 'templateUrl must be a string');
@@ -97,7 +98,7 @@ export class ComponentDecoratorHandler implements
// @Component inherits @Directive, so begin by extracting the @Directive metadata and building
// on it.
const directiveResult = extractDirectiveMetadata(
node, decorator, this.checker, this.reflector, this.isCore,
node, decorator, this.reflector, this.evaluator, this.isCore,
this.elementSchemaRegistry.getDefaultComponentElementName());
if (directiveResult === undefined) {
// `extractDirectiveMetadata` returns undefined when the @Directive has `jit: true`. In this
@@ -112,15 +113,15 @@ export class ComponentDecoratorHandler implements
let templateStr: string|null = null;
if (component.has('templateUrl')) {
const templateUrlExpr = component.get('templateUrl') !;
const templateUrl = staticallyResolve(templateUrlExpr, this.reflector, this.checker);
const templateUrl = this.evaluator.evaluate(templateUrlExpr);
if (typeof templateUrl !== 'string') {
throw new FatalDiagnosticError(
ErrorCode.VALUE_HAS_WRONG_TYPE, templateUrlExpr, 'templateUrl must be a string');
}
templateStr = this.resourceLoader.load(templateUrl, containingFile);
} else if (component.has('template')) {
const templateExpr = component.get('template') !;
const resolvedTemplate = staticallyResolve(templateExpr, this.reflector, this.checker);
const resolvedTemplate = this.evaluator.evaluate(templateExpr);
if (typeof resolvedTemplate !== 'string') {
throw new FatalDiagnosticError(
ErrorCode.VALUE_HAS_WRONG_TYPE, templateExpr, 'template must be a string');
@@ -134,7 +135,7 @@ export class ComponentDecoratorHandler implements
let preserveWhitespaces: boolean = this.defaultPreserveWhitespaces;
if (component.has('preserveWhitespaces')) {
const expr = component.get('preserveWhitespaces') !;
const value = staticallyResolve(expr, this.reflector, this.checker);
const value = this.evaluator.evaluate(expr);
if (typeof value !== 'boolean') {
throw new FatalDiagnosticError(
ErrorCode.VALUE_HAS_WRONG_TYPE, expr, 'preserveWhitespaces must be a boolean');
@@ -161,7 +162,7 @@ export class ComponentDecoratorHandler implements
let interpolation: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG;
if (component.has('interpolation')) {
const expr = component.get('interpolation') !;
const value = staticallyResolve(expr, this.reflector, this.checker);
const value = this.evaluator.evaluate(expr);
if (!Array.isArray(value) || value.length !== 2 ||
!value.every(element => typeof element === 'string')) {
throw new FatalDiagnosticError(
@@ -200,21 +201,21 @@ export class ComponentDecoratorHandler implements
const coreModule = this.isCore ? undefined : '@angular/core';
const viewChildFromFields = queriesFromFields(
filterToMembersWithDecorator(decoratedElements, 'ViewChild', coreModule), this.reflector,
this.checker);
this.evaluator);
const viewChildrenFromFields = queriesFromFields(
filterToMembersWithDecorator(decoratedElements, 'ViewChildren', coreModule), this.reflector,
this.checker);
this.evaluator);
const viewQueries = [...viewChildFromFields, ...viewChildrenFromFields];

if (component.has('queries')) {
const queriesFromDecorator = extractQueriesFromDecorator(
component.get('queries') !, this.reflector, this.checker, this.isCore);
component.get('queries') !, this.reflector, this.evaluator, this.isCore);
viewQueries.push(...queriesFromDecorator.view);
}

let styles: string[]|null = null;
if (component.has('styles')) {
styles = parseFieldArrayValue(component, 'styles', this.reflector, this.checker);
styles = parseFieldArrayValue(component, 'styles', this.evaluator);
}

let styleUrls = this._extractStyleUrls(component);
@@ -227,8 +228,7 @@ export class ComponentDecoratorHandler implements

let encapsulation: number = 0;
if (component.has('encapsulation')) {
encapsulation = parseInt(staticallyResolve(
component.get('encapsulation') !, this.reflector, this.checker) as string);
encapsulation = parseInt(this.evaluator.evaluate(component.get('encapsulation') !) as string);
}

let animations: Expression|null = null;
@@ -333,7 +333,7 @@ export class ComponentDecoratorHandler implements
}

const styleUrlsExpr = component.get('styleUrls') !;
const styleUrls = staticallyResolve(styleUrlsExpr, this.reflector, this.checker);
const styleUrls = this.evaluator.evaluate(styleUrlsExpr);
if (!Array.isArray(styleUrls) || !styleUrls.every(url => typeof url === 'string')) {
throw new FatalDiagnosticError(
ErrorCode.VALUE_HAS_WRONG_TYPE, styleUrlsExpr, 'styleUrls must be an array of strings');
Oops, something went wrong.

0 comments on commit 2a6108a

Please sign in to comment.
You can’t perform that action at this time.