From 12c925a000ca36e3b0ad0a38e705dff16a72f8a0 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Thu, 11 Mar 2021 12:59:48 +0000 Subject: [PATCH] refactor(compiler): consolidate `wrapReference()` (#41080) This function is declared in multiple places. The instances inside `compiler` are slightly different to those in `compiler-cli`. So this commit consolidates them into two reusable functions. PR Close #41080 --- .../partial_linkers/partial_directive_linker_1.ts | 7 ++----- .../partial_linkers/partial_pipe_linker_1.ts | 7 ++----- .../linker/src/file_linker/partial_linkers/util.ts | 13 +++++++++++++ packages/compiler/src/jit_compiler_facade.ts | 7 +------ 4 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 packages/compiler-cli/linker/src/file_linker/partial_linkers/util.ts diff --git a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_directive_linker_1.ts b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_directive_linker_1.ts index e11c5e79c5..16b75c530d 100644 --- a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_directive_linker_1.ts +++ b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_directive_linker_1.ts @@ -5,7 +5,7 @@ * 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 {compileDirectiveFromMetadata, ConstantPool, makeBindingParser, ParseLocation, ParseSourceFile, ParseSourceSpan, R3DeclareDirectiveMetadata, R3DeclareQueryMetadata, R3DirectiveMetadata, R3HostMetadata, R3PartialDeclaration, R3QueryMetadata, R3Reference} from '@angular/compiler'; +import {compileDirectiveFromMetadata, ConstantPool, makeBindingParser, ParseLocation, ParseSourceFile, ParseSourceSpan, R3DeclareDirectiveMetadata, R3DeclareQueryMetadata, R3DirectiveMetadata, R3HostMetadata, R3PartialDeclaration, R3QueryMetadata} from '@angular/compiler'; import * as o from '@angular/compiler/src/output/output_ast'; import {AbsoluteFsPath} from '../../../../src/ngtsc/file_system'; @@ -14,6 +14,7 @@ import {AstObject, AstValue} from '../../ast/ast_value'; import {FatalLinkerError} from '../../fatal_linker_error'; import {PartialLinker} from './partial_linker'; +import {wrapReference} from './util'; /** * A `PartialLinker` that is designed to process `ɵɵngDeclareDirective()` call expressions. @@ -154,10 +155,6 @@ function toQueryMetadata(obj: AstObject(wrapped: o.WrappedNodeExpr): R3Reference { - return {value: wrapped, type: wrapped}; -} - export function createSourceSpan(range: Range, code: string, sourceUrl: string): ParseSourceSpan { const sourceFile = new ParseSourceFile(code, sourceUrl); const startLocation = diff --git a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_pipe_linker_1.ts b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_pipe_linker_1.ts index 11b4239a72..a3d4df827a 100644 --- a/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_pipe_linker_1.ts +++ b/packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_pipe_linker_1.ts @@ -5,13 +5,14 @@ * 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 {compilePipeFromMetadata, ConstantPool, R3DeclarePipeMetadata, R3PartialDeclaration, R3PipeMetadata, R3Reference} from '@angular/compiler'; +import {compilePipeFromMetadata, ConstantPool, R3DeclarePipeMetadata, R3PartialDeclaration, R3PipeMetadata} from '@angular/compiler'; import * as o from '@angular/compiler/src/output/output_ast'; import {AstObject} from '../../ast/ast_value'; import {FatalLinkerError} from '../../fatal_linker_error'; import {PartialLinker} from './partial_linker'; +import {wrapReference} from './util'; /** * A `PartialLinker` that is designed to process `ɵɵngDeclarePipe()` call expressions. @@ -52,7 +53,3 @@ export function toR3PipeMeta(metaObj: AstObject(wrapped: o.WrappedNodeExpr): R3Reference { - return {value: wrapped, type: wrapped}; -} diff --git a/packages/compiler-cli/linker/src/file_linker/partial_linkers/util.ts b/packages/compiler-cli/linker/src/file_linker/partial_linkers/util.ts new file mode 100644 index 0000000000..87e391d9bd --- /dev/null +++ b/packages/compiler-cli/linker/src/file_linker/partial_linkers/util.ts @@ -0,0 +1,13 @@ +/** + * @license + * Copyright Google LLC 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 {R3Reference} from '@angular/compiler'; +import * as o from '@angular/compiler/src/output/output_ast'; + +export function wrapReference(wrapped: o.WrappedNodeExpr): R3Reference { + return {value: wrapped, type: wrapped}; +} diff --git a/packages/compiler/src/jit_compiler_facade.ts b/packages/compiler/src/jit_compiler_facade.ts index 5affd26500..33cc08452c 100644 --- a/packages/compiler/src/jit_compiler_facade.ts +++ b/packages/compiler/src/jit_compiler_facade.ts @@ -20,7 +20,7 @@ import {compileFactoryFunction, R3DependencyMetadata, R3FactoryTarget, R3Resolve import {R3JitReflector} from './render3/r3_jit'; import {compileInjector, compileNgModule, R3InjectorMetadata, R3NgModuleMetadata} from './render3/r3_module_compiler'; import {compilePipeFromMetadata, R3PipeMetadata} from './render3/r3_pipe_compiler'; -import {getSafePropertyAccessString, R3Reference} from './render3/util'; +import {getSafePropertyAccessString, wrapReference} from './render3/util'; import {DeclarationListEmitMode, R3ComponentMetadata, R3DirectiveMetadata, R3HostMetadata, R3QueryMetadata, R3UsedDirectiveMetadata} from './render3/view/api'; import {compileComponentFromMetadata, compileDirectiveFromMetadata, ParsedHostBindings, parseHostBindings, verifyHostBindings} from './render3/view/compiler'; import {makeBindingParser, parseTemplate} from './render3/view/template'; @@ -239,11 +239,6 @@ const USE_FACTORY = Object.keys({useFactory: null})[0]; const USE_VALUE = Object.keys({useValue: null})[0]; const USE_EXISTING = Object.keys({useExisting: null})[0]; -const wrapReference = function(value: any): R3Reference { - const wrapped = new WrappedNodeExpr(value); - return {value: wrapped, type: wrapped}; -}; - function convertToR3QueryMetadata(facade: R3QueryMetadataFacade): R3QueryMetadata { return { ...facade,