refactor(ivy): refactor more files in DI to prepare it for bazel packages (#28098)

PR Close #28098
This commit is contained in:
Miško Hevery 2019-01-11 16:07:01 -08:00 committed by Andrew Kushnir
parent 6a9a48b0ac
commit 978ffa9d32
29 changed files with 194 additions and 112 deletions

View File

@ -41,6 +41,7 @@ ts_library(
"//packages/compiler/test/ml_parser/util",
"//packages/compiler/testing",
"//packages/core",
"//packages/core/src/compiler",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as core from '../../core/src/render3/jit/compiler_facade_interface';
import * as core from '../../core/src/compiler/compiler_facade_interface';
import {R3ResolvedDependencyType} from '../public_api';
import * as compiler from '../src/compiler_facade_interface';

View File

@ -13,8 +13,10 @@ ng_module(
module_name = "@angular/core",
deps = [
"//packages:types",
"//packages/core/src/compiler",
"//packages/core/src/di/interface",
"//packages/core/src/interface",
"//packages/core/src/reflection",
"//packages/core/src/util",
"@ngdeps//zone.js",
"@rxjs",

View File

@ -17,10 +17,20 @@ export {ChangeDetectionStrategy, ChangeDetectorStatus, isDefaultChangeDetectionS
export {DefaultIterableDifferFactory} from './differs/default_iterable_differ';
export {DefaultIterableDiffer} from './differs/default_iterable_differ';
export {DefaultKeyValueDifferFactory} from './differs/default_keyvalue_differ';
export {CollectionChangeRecord, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDifferFactory, IterableDiffers, NgIterable, TrackByFunction} from './differs/iterable_differs';
export {
CollectionChangeRecord,
IterableChangeRecord,
IterableChanges,
IterableDiffer,
IterableDifferFactory,
IterableDiffers,
NgIterable,
TrackByFunction
} from
'./differs/iterable_differs';
export {KeyValueChangeRecord, KeyValueChanges, KeyValueDiffer, KeyValueDifferFactory, KeyValueDiffers} from './differs/keyvalue_differs';
export {PipeTransform} from './pipe_transform';
export {SimpleChange, SimpleChanges} from './simple_change';
export {SimpleChange, SimpleChanges} from '../interface/simple_change';

View File

@ -0,0 +1,20 @@
package(default_visibility = [
"//packages/compiler/test:__pkg__",
"//packages/core:__subpackages__",
"//tools/public_api_guard:__pkg__",
])
load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "compiler",
srcs = glob(
[
"**/*.ts",
],
),
module_name = "@angular/core/compiler",
deps = [
"//packages/core/src/util",
],
)

View File

@ -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 {global} from '../../util/global';
import {global} from '../util/global';
import {CompilerFacade, ExportedCompilerFacade} from './compiler_facade_interface';
export * from './compiler_facade_interface';

View File

@ -7,11 +7,10 @@
*/
import {Type} from '../interface/type';
import {compileInjectable as render3CompileInjectable} from '../render3/jit/injectable';
import {TypeDecorator, makeDecorator} from '../util/decorators';
import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueSansProvider,} from './interface/provider';
import {InjectableType, defineInjectable, getInjectableDef, InjectableDef} from './interface/defs';
import {InjectableDef, InjectableType, defineInjectable, getInjectableDef} from './interface/defs';
import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueSansProvider} from './interface/provider';
import {compileInjectable as render3CompileInjectable} from './jit/injectable';
import {convertInjectableProviderToFactory} from './util';

View File

@ -0,0 +1,33 @@
/**
* @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 {Type} from '../../interface/type';
import {inject} from '../injector_compatibility';
import {defineInjectable, defineInjector, getInjectableDef, getInjectorDef} from '../interface/defs';
/**
* A mapping of the @angular/core API surface used in generated expressions to the actual symbols.
*
* This should be kept up to date with the public exports of @angular/core.
*/
export const angularCoreDiEnv: {[name: string]: Function} = {
'defineInjectable': defineInjectable,
'defineInjector': defineInjector,
'inject': inject,
'ɵgetFactoryOf': getFactoryOf,
};
function getFactoryOf<T>(type: Type<any>): ((type: Type<T>| null) => T)|null {
const typeAny = type as any;
const def = getInjectableDef<T>(typeAny) || getInjectorDef<T>(typeAny);
if (!def || def.factory === undefined) {
return null;
}
return def.factory;
}

View File

@ -6,14 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Injectable} from '../../di/injectable';
import {NG_INJECTABLE_DEF} from '../../di/interface/defs';
import {ClassSansProvider, ExistingSansProvider, FactorySansProvider, ValueProvider, ValueSansProvider} from '../../di/interface/provider';
import {R3InjectableMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
import {Type} from '../../interface/type';
import {getClosureSafeProperty} from '../../util/property';
import {Injectable} from '../injectable';
import {NG_INJECTABLE_DEF} from '../interface/defs';
import {ClassSansProvider, ExistingSansProvider, FactorySansProvider, ValueProvider, ValueSansProvider} from '../interface/provider';
import {R3InjectableMetadataFacade, getCompilerFacade} from './compiler_facade';
import {angularCoreEnv} from './environment';
import {angularCoreDiEnv} from './environment';
import {convertDependencies, reflectDependencies} from './util';
@ -71,7 +71,7 @@ export function compileInjectable(type: Type<any>, srcMeta?: Injectable): void {
throw new Error(`Unreachable state.`);
}
def = getCompilerFacade().compileInjectable(
angularCoreEnv, `ng://${type.name}/ngInjectableDef.js`, compilerMeta);
angularCoreDiEnv, `ng://${type.name}/ngInjectableDef.js`, compilerMeta);
}
return def;
},

View File

@ -6,12 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Host, Inject, Optional, Self, SkipSelf} from '../../di/metadata';
import {CompilerFacade, R3DependencyMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
import {Type} from '../../interface/type';
import {Attribute} from '../../metadata/di';
import {ReflectionCapabilities} from '../../reflection/reflection_capabilities';
import {CompilerFacade, R3DependencyMetadataFacade, getCompilerFacade} from './compiler_facade';
import {Attribute, Host, Inject, Optional, Self, SkipSelf} from '../metadata';
let _reflect: ReflectionCapabilities|null = null;

View File

@ -206,3 +206,67 @@ export interface Host {}
* @publicApi
*/
export const Host: HostDecorator = makeParamDecorator('Host');
/**
* Type of the Attribute decorator / constructor function.
*
* @publicApi
*/
export interface AttributeDecorator {
/**
* Specifies that a constant attribute value should be injected.
*
* The directive can inject constant string literals of host element attributes.
*
* @usageNotes
* ### Example
*
* Suppose we have an `<input>` element and want to know its `type`.
*
* ```html
* <input type="text">
* ```
*
* A decorator can inject string literal `text` like so:
*
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
*
* ### Example as TypeScript Decorator
*
* {@example core/ts/metadata/metadata.ts region='attributeFactory'}
*
* ### Example as ES5 annotation
*
* ```
* var MyComponent = function(title) {
* ...
* };
*
* MyComponent.annotations = [
* new ng.Component({...})
* ]
* MyComponent.parameters = [
* [new ng.Attribute('title')]
* ]
* ```
*/
(name: string): any;
new (name: string): Attribute;
}
/**
* Type of the Attribute metadata.
*
* @publicApi
*/
export interface Attribute { attributeName?: string; }
/**
* Attribute decorator and metadata.
*
* @Annotation
* @publicApi
*/
export const Attribute: AttributeDecorator =
makeParamDecorator('Attribute', (attributeName?: string) => ({attributeName}));

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {OnDestroy} from '../interface/lifecycle_hooks';
import {Type} from '../interface/type';
import {OnDestroy} from '../metadata/lifecycle_hooks';
import {stringify} from '../util/stringify';
import {resolveForwardRef} from './forward_ref';

View File

@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {wrappedError} from '../error_handler';
import {Type} from '../interface/type';
import {ERROR_ORIGINAL_ERROR} from '../util/errors';
import {ERROR_ORIGINAL_ERROR, wrappedError} from '../util/errors';
import {stringify} from '../util/stringify';
import {ReflectiveInjector} from './reflective_injector';

View File

@ -7,7 +7,6 @@
*/
import {getDebugContext, getErrorLogger, getOriginalError} from './errors';
import {ERROR_ORIGINAL_ERROR} from './util/errors';
@ -78,11 +77,3 @@ export class ErrorHandler {
return e;
}
}
export function wrappedError(message: string, originalError: any): Error {
const msg =
`${message} caused by: ${originalError instanceof Error ? originalError.message: originalError }`;
const error = Error(msg);
(error as any)[ERROR_ORIGINAL_ERROR] = originalError;
return error;
}

View File

@ -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 {SimpleChanges} from '../change_detection/simple_change';
import {SimpleChanges} from './simple_change';
/**

View File

@ -11,13 +11,15 @@
* to be used by the decorator versions of these annotations.
*/
import {Attribute, ContentChild, ContentChildren, Query, ViewChild, ViewChildren} from './metadata/di';
import {Attribute} from './di';
import {ContentChild, ContentChildren, Query, ViewChild, ViewChildren} from './metadata/di';
import {Component, Directive, HostBinding, HostListener, Input, Output, Pipe} from './metadata/directives';
import {DoBootstrap, ModuleWithProviders, NgModule, SchemaMetadata} from './metadata/ng_module';
import {ViewEncapsulation} from './metadata/view';
export {ANALYZE_FOR_ENTRY_COMPONENTS, Attribute, ContentChild, ContentChildDecorator, ContentChildren, ContentChildrenDecorator, Query, ViewChild, ViewChildDecorator, ViewChildren, ViewChildrenDecorator} from './metadata/di';
export {Attribute} from './di';
export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './interface/lifecycle_hooks';
export {ANALYZE_FOR_ENTRY_COMPONENTS, ContentChild, ContentChildDecorator, ContentChildren, ContentChildrenDecorator, Query, ViewChild, ViewChildDecorator, ViewChildren, ViewChildrenDecorator} from './metadata/di';
export {Component, ComponentDecorator, Directive, DirectiveDecorator, HostBinding, HostListener, Input, Output, Pipe} from './metadata/directives';
export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './metadata/lifecycle_hooks';
export {CUSTOM_ELEMENTS_SCHEMA, DoBootstrap, ModuleWithProviders, NO_ERRORS_SCHEMA, NgModule, SchemaMetadata} from './metadata/ng_module';
export {ViewEncapsulation} from './metadata/view';

View File

@ -8,7 +8,7 @@
import {InjectionToken} from '../di/injection_token';
import {Type} from '../interface/type';
import {makeParamDecorator, makePropDecorator} from '../util/decorators';
import {makePropDecorator} from '../util/decorators';
/**
* This token can be used to create a virtual provider that will populate the
@ -47,71 +47,6 @@ import {makeParamDecorator, makePropDecorator} from '../util/decorators';
*/
export const ANALYZE_FOR_ENTRY_COMPONENTS = new InjectionToken<any>('AnalyzeForEntryComponents');
/**
* Type of the Attribute decorator / constructor function.
*
* @publicApi
*/
export interface AttributeDecorator {
/**
* Specifies that a constant attribute value should be injected.
*
* The directive can inject constant string literals of host element attributes.
*
* @usageNotes
* ### Example
*
* Suppose we have an `<input>` element and want to know its `type`.
*
* ```html
* <input type="text">
* ```
*
* A decorator can inject string literal `text` like so:
*
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
*
* ### Example as TypeScript Decorator
*
* {@example core/ts/metadata/metadata.ts region='attributeFactory'}
*
* ### Example as ES5 annotation
*
* ```
* var MyComponent = function(title) {
* ...
* };
*
* MyComponent.annotations = [
* new ng.Component({...})
* ]
* MyComponent.parameters = [
* [new ng.Attribute('title')]
* ]
* ```
*
* @publicApi
*/
(name: string): any;
new (name: string): Attribute;
}
/**
* Type of the Attribute metadata.
*
* @publicApi
*/
export interface Attribute { attributeName?: string; }
/**
* Attribute decorator and metadata.
*
* @Annotation
* @publicApi
*/
export const Attribute: AttributeDecorator =
makeParamDecorator('Attribute', (attributeName?: string) => ({attributeName}));
/**
* Type of the Query metadata.

View File

@ -0,0 +1,20 @@
package(default_visibility = [
"//packages/core:__subpackages__",
"//tools/public_api_guard:__pkg__",
])
load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "reflection",
srcs = glob(
[
"**/*.ts",
],
),
module_name = "@angular/core/reflection",
deps = [
"//packages/core/src/interface",
"//packages/core/src/util",
],
)

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {SimpleChanges} from '../change_detection/simple_change';
import {SimpleChanges} from '../interface/simple_change';
import {assertEqual} from '../util/assert';
import {DirectiveDef} from './interfaces/definition';

View File

@ -6,12 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/
import {SimpleChanges} from '../../change_detection/simple_change';
import {InjectionToken} from '../../di/injection_token';
import {Injector} from '../../di/injector';
import {SimpleChanges} from '../../interface/simple_change';
import {Type} from '../../interface/type';
import {QueryList} from '../../linker';
import {Sanitizer} from '../../sanitization/security';
import {LContainer} from './container';
import {ComponentDef, ComponentQuery, ComponentTemplate, DirectiveDef, DirectiveDefList, HostBindingsFunction, PipeDef, PipeDefList} from './definition';
import {I18nUpdateOpCodes, TI18n} from './i18n';
@ -22,6 +23,7 @@ import {RElement, Renderer3, RendererFactory3} from './renderer';
import {StylingContext} from './styling';
// Below are constants for LView indices to help us look up LView members
// without having to remember the specific indices.
// Uglify will inline these when minifying so there shouldn't be a cost.

View File

@ -7,7 +7,10 @@
*/
import {ComponentType} from '..';
import {R3DirectiveMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
import {R3ComponentMetadataFacade, R3QueryMetadataFacade} from '../../compiler/compiler_facade_interface';
import {resolveForwardRef} from '../../di/forward_ref';
import {getReflect, reflectDependencies} from '../../di/jit/util';
import {Type} from '../../interface/type';
import {Query} from '../../metadata/di';
import {Component, Directive} from '../../metadata/directives';
@ -17,11 +20,8 @@ import {EMPTY_ARRAY, EMPTY_OBJ} from '../empty';
import {NG_COMPONENT_DEF, NG_DIRECTIVE_DEF} from '../fields';
import {renderStringify} from '../util';
import {R3DirectiveMetadataFacade, getCompilerFacade} from './compiler_facade';
import {R3ComponentMetadataFacade, R3QueryMetadataFacade} from './compiler_facade_interface';
import {angularCoreEnv} from './environment';
import {flushModuleScopingQueueAsMuchAsPossible, patchComponentDefWithScope, transitiveScopesFor} from './module';
import {getReflect, reflectDependencies} from './util';

View File

@ -6,8 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/
import {R3InjectorMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
import {resolveForwardRef} from '../../di/forward_ref';
import {NG_INJECTOR_DEF} from '../../di/interface/defs';
import {reflectDependencies} from '../../di/jit/util';
import {Type} from '../../interface/type';
import {registerNgModuleType} from '../../linker/ng_module_factory_loader';
import {Component} from '../../metadata';
@ -19,9 +21,7 @@ import {ComponentDef} from '../interfaces/definition';
import {NgModuleType} from '../ng_module_ref';
import {renderStringify} from '../util';
import {R3InjectorMetadataFacade, getCompilerFacade} from './compiler_facade';
import {angularCoreEnv} from './environment';
import {reflectDependencies} from './util';
const EMPTY_ARRAY: Type<any>[] = [];

View File

@ -6,14 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import {getCompilerFacade} from '../../compiler/compiler_facade';
import {reflectDependencies} from '../../di/jit/util';
import {Type} from '../../interface/type';
import {Pipe} from '../../metadata/directives';
import {NG_PIPE_DEF} from '../fields';
import {renderStringify} from '../util';
import {getCompilerFacade} from './compiler_facade';
import {angularCoreEnv} from './environment';
import {reflectDependencies} from './util';
export function compilePipe(type: Type<any>, meta: Pipe): void {
let ngPipeDef: any = null;

View File

@ -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 {SimpleChange, SimpleChanges} from '../change_detection/simple_change';
import {SimpleChange, SimpleChanges} from '../interface/simple_change';
type Constructor<T> = new (...args: any[]) => T;

View File

@ -21,6 +21,7 @@ ts_library(
"//packages/core",
"//packages/core/src/di/interface",
"//packages/core/src/interface",
"//packages/core/src/reflection",
"//packages/core/src/util",
"//packages/core/testing",
"//packages/platform-browser",

View File

@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ERROR_DEBUG_CONTEXT, ERROR_LOGGER, ERROR_TYPE} from '@angular/core/src/util/errors';
import {ERROR_DEBUG_CONTEXT, ERROR_LOGGER, ERROR_TYPE, wrappedError} from '@angular/core/src/util/errors';
import {ErrorHandler, wrappedError} from '../src/error_handler';
import {ErrorHandler} from '../src/error_handler';
class MockConsole {
res: any[][] = [];

View File

@ -53,6 +53,11 @@ export interface Attribute {
export declare const Attribute: AttributeDecorator;
export interface AttributeDecorator {
(name: string): any;
new (name: string): Attribute;
}
export declare enum ChangeDetectionStrategy {
OnPush = 0,
Default = 1