Skip to content

Commit 978ffa9

Browse files
mheveryAndrewKushnir
authored andcommitted
refactor(ivy): refactor more files in DI to prepare it for bazel packages (angular#28098)
PR Close angular#28098
1 parent 6a9a48b commit 978ffa9

29 files changed

+194
-112
lines changed

packages/compiler/test/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ts_library(
4141
"//packages/compiler/test/ml_parser/util",
4242
"//packages/compiler/testing",
4343
"//packages/core",
44+
"//packages/core/src/compiler",
4445
"//packages/core/testing",
4546
"//packages/platform-browser",
4647
"//packages/platform-browser-dynamic",

packages/compiler/test/compiler_facade_interface_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import * as core from '../../core/src/render3/jit/compiler_facade_interface';
9+
import * as core from '../../core/src/compiler/compiler_facade_interface';
1010
import {R3ResolvedDependencyType} from '../public_api';
1111
import * as compiler from '../src/compiler_facade_interface';
1212

packages/core/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ ng_module(
1313
module_name = "@angular/core",
1414
deps = [
1515
"//packages:types",
16+
"//packages/core/src/compiler",
1617
"//packages/core/src/di/interface",
1718
"//packages/core/src/interface",
19+
"//packages/core/src/reflection",
1820
"//packages/core/src/util",
1921
"@ngdeps//zone.js",
2022
"@rxjs",

packages/core/src/change_detection/change_detection.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@ export {ChangeDetectionStrategy, ChangeDetectorStatus, isDefaultChangeDetectionS
1717
export {DefaultIterableDifferFactory} from './differs/default_iterable_differ';
1818
export {DefaultIterableDiffer} from './differs/default_iterable_differ';
1919
export {DefaultKeyValueDifferFactory} from './differs/default_keyvalue_differ';
20-
export {CollectionChangeRecord, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDifferFactory, IterableDiffers, NgIterable, TrackByFunction} from './differs/iterable_differs';
20+
export {
21+
CollectionChangeRecord,
22+
IterableChangeRecord,
23+
IterableChanges,
24+
IterableDiffer,
25+
IterableDifferFactory,
26+
IterableDiffers,
27+
NgIterable,
28+
TrackByFunction
29+
} from
30+
'./differs/iterable_differs';
2131
export {KeyValueChangeRecord, KeyValueChanges, KeyValueDiffer, KeyValueDifferFactory, KeyValueDiffers} from './differs/keyvalue_differs';
2232
export {PipeTransform} from './pipe_transform';
23-
export {SimpleChange, SimpleChanges} from './simple_change';
33+
export {SimpleChange, SimpleChanges} from '../interface/simple_change';
2434

2535

2636

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package(default_visibility = [
2+
"//packages/compiler/test:__pkg__",
3+
"//packages/core:__subpackages__",
4+
"//tools/public_api_guard:__pkg__",
5+
])
6+
7+
load("//tools:defaults.bzl", "ts_library")
8+
9+
ts_library(
10+
name = "compiler",
11+
srcs = glob(
12+
[
13+
"**/*.ts",
14+
],
15+
),
16+
module_name = "@angular/core/compiler",
17+
deps = [
18+
"//packages/core/src/util",
19+
],
20+
)

packages/core/src/render3/jit/compiler_facade.ts renamed to packages/core/src/compiler/compiler_facade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {global} from '../../util/global';
8+
import {global} from '../util/global';
99
import {CompilerFacade, ExportedCompilerFacade} from './compiler_facade_interface';
1010
export * from './compiler_facade_interface';
1111

packages/core/src/di/injectable.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
*/
88

99
import {Type} from '../interface/type';
10-
import {compileInjectable as render3CompileInjectable} from '../render3/jit/injectable';
1110
import {TypeDecorator, makeDecorator} from '../util/decorators';
12-
13-
import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueSansProvider,} from './interface/provider';
14-
import {InjectableType, defineInjectable, getInjectableDef, InjectableDef} from './interface/defs';
11+
import {InjectableDef, InjectableType, defineInjectable, getInjectableDef} from './interface/defs';
12+
import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueSansProvider} from './interface/provider';
13+
import {compileInjectable as render3CompileInjectable} from './jit/injectable';
1514
import {convertInjectableProviderToFactory} from './util';
1615

1716

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Type} from '../../interface/type';
10+
import {inject} from '../injector_compatibility';
11+
import {defineInjectable, defineInjector, getInjectableDef, getInjectorDef} from '../interface/defs';
12+
13+
14+
/**
15+
* A mapping of the @angular/core API surface used in generated expressions to the actual symbols.
16+
*
17+
* This should be kept up to date with the public exports of @angular/core.
18+
*/
19+
export const angularCoreDiEnv: {[name: string]: Function} = {
20+
'defineInjectable': defineInjectable,
21+
'defineInjector': defineInjector,
22+
'inject': inject,
23+
'ɵgetFactoryOf': getFactoryOf,
24+
};
25+
26+
function getFactoryOf<T>(type: Type<any>): ((type: Type<T>| null) => T)|null {
27+
const typeAny = type as any;
28+
const def = getInjectableDef<T>(typeAny) || getInjectorDef<T>(typeAny);
29+
if (!def || def.factory === undefined) {
30+
return null;
31+
}
32+
return def.factory;
33+
}

packages/core/src/render3/jit/injectable.ts renamed to packages/core/src/di/jit/injectable.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Injectable} from '../../di/injectable';
10-
import {NG_INJECTABLE_DEF} from '../../di/interface/defs';
11-
import {ClassSansProvider, ExistingSansProvider, FactorySansProvider, ValueProvider, ValueSansProvider} from '../../di/interface/provider';
9+
import {R3InjectableMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
1210
import {Type} from '../../interface/type';
1311
import {getClosureSafeProperty} from '../../util/property';
12+
import {Injectable} from '../injectable';
13+
import {NG_INJECTABLE_DEF} from '../interface/defs';
14+
import {ClassSansProvider, ExistingSansProvider, FactorySansProvider, ValueProvider, ValueSansProvider} from '../interface/provider';
1415

15-
import {R3InjectableMetadataFacade, getCompilerFacade} from './compiler_facade';
16-
import {angularCoreEnv} from './environment';
16+
import {angularCoreDiEnv} from './environment';
1717
import {convertDependencies, reflectDependencies} from './util';
1818

1919

@@ -71,7 +71,7 @@ export function compileInjectable(type: Type<any>, srcMeta?: Injectable): void {
7171
throw new Error(`Unreachable state.`);
7272
}
7373
def = getCompilerFacade().compileInjectable(
74-
angularCoreEnv, `ng://${type.name}/ngInjectableDef.js`, compilerMeta);
74+
angularCoreDiEnv, `ng://${type.name}/ngInjectableDef.js`, compilerMeta);
7575
}
7676
return def;
7777
},

packages/core/src/render3/jit/util.ts renamed to packages/core/src/di/jit/util.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Host, Inject, Optional, Self, SkipSelf} from '../../di/metadata';
9+
import {CompilerFacade, R3DependencyMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
1010
import {Type} from '../../interface/type';
11-
import {Attribute} from '../../metadata/di';
1211
import {ReflectionCapabilities} from '../../reflection/reflection_capabilities';
13-
14-
import {CompilerFacade, R3DependencyMetadataFacade, getCompilerFacade} from './compiler_facade';
12+
import {Attribute, Host, Inject, Optional, Self, SkipSelf} from '../metadata';
1513

1614
let _reflect: ReflectionCapabilities|null = null;
1715

packages/core/src/di/metadata.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,67 @@ export interface Host {}
206206
* @publicApi
207207
*/
208208
export const Host: HostDecorator = makeParamDecorator('Host');
209+
210+
211+
/**
212+
* Type of the Attribute decorator / constructor function.
213+
*
214+
* @publicApi
215+
*/
216+
export interface AttributeDecorator {
217+
/**
218+
* Specifies that a constant attribute value should be injected.
219+
*
220+
* The directive can inject constant string literals of host element attributes.
221+
*
222+
* @usageNotes
223+
* ### Example
224+
*
225+
* Suppose we have an `<input>` element and want to know its `type`.
226+
*
227+
* ```html
228+
* <input type="text">
229+
* ```
230+
*
231+
* A decorator can inject string literal `text` like so:
232+
*
233+
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
234+
*
235+
* ### Example as TypeScript Decorator
236+
*
237+
* {@example core/ts/metadata/metadata.ts region='attributeFactory'}
238+
*
239+
* ### Example as ES5 annotation
240+
*
241+
* ```
242+
* var MyComponent = function(title) {
243+
* ...
244+
* };
245+
*
246+
* MyComponent.annotations = [
247+
* new ng.Component({...})
248+
* ]
249+
* MyComponent.parameters = [
250+
* [new ng.Attribute('title')]
251+
* ]
252+
* ```
253+
*/
254+
(name: string): any;
255+
new (name: string): Attribute;
256+
}
257+
258+
/**
259+
* Type of the Attribute metadata.
260+
*
261+
* @publicApi
262+
*/
263+
export interface Attribute { attributeName?: string; }
264+
265+
/**
266+
* Attribute decorator and metadata.
267+
*
268+
* @Annotation
269+
* @publicApi
270+
*/
271+
export const Attribute: AttributeDecorator =
272+
makeParamDecorator('Attribute', (attributeName?: string) => ({attributeName}));

packages/core/src/di/r3_injector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {OnDestroy} from '../interface/lifecycle_hooks';
910
import {Type} from '../interface/type';
10-
import {OnDestroy} from '../metadata/lifecycle_hooks';
1111
import {stringify} from '../util/stringify';
1212

1313
import {resolveForwardRef} from './forward_ref';

packages/core/src/di/reflective_errors.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {wrappedError} from '../error_handler';
109
import {Type} from '../interface/type';
11-
import {ERROR_ORIGINAL_ERROR} from '../util/errors';
10+
import {ERROR_ORIGINAL_ERROR, wrappedError} from '../util/errors';
1211
import {stringify} from '../util/stringify';
1312

1413
import {ReflectiveInjector} from './reflective_injector';

packages/core/src/error_handler.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import {getDebugContext, getErrorLogger, getOriginalError} from './errors';
10-
import {ERROR_ORIGINAL_ERROR} from './util/errors';
1110

1211

1312

@@ -78,11 +77,3 @@ export class ErrorHandler {
7877
return e;
7978
}
8079
}
81-
82-
export function wrappedError(message: string, originalError: any): Error {
83-
const msg =
84-
`${message} caused by: ${originalError instanceof Error ? originalError.message: originalError }`;
85-
const error = Error(msg);
86-
(error as any)[ERROR_ORIGINAL_ERROR] = originalError;
87-
return error;
88-
}

packages/core/src/metadata/lifecycle_hooks.ts renamed to packages/core/src/interface/lifecycle_hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {SimpleChanges} from '../change_detection/simple_change';
8+
import {SimpleChanges} from './simple_change';
99

1010

1111
/**

packages/core/src/metadata.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
* to be used by the decorator versions of these annotations.
1212
*/
1313

14-
import {Attribute, ContentChild, ContentChildren, Query, ViewChild, ViewChildren} from './metadata/di';
14+
import {Attribute} from './di';
15+
import {ContentChild, ContentChildren, Query, ViewChild, ViewChildren} from './metadata/di';
1516
import {Component, Directive, HostBinding, HostListener, Input, Output, Pipe} from './metadata/directives';
1617
import {DoBootstrap, ModuleWithProviders, NgModule, SchemaMetadata} from './metadata/ng_module';
1718
import {ViewEncapsulation} from './metadata/view';
1819

19-
export {ANALYZE_FOR_ENTRY_COMPONENTS, Attribute, ContentChild, ContentChildDecorator, ContentChildren, ContentChildrenDecorator, Query, ViewChild, ViewChildDecorator, ViewChildren, ViewChildrenDecorator} from './metadata/di';
20+
export {Attribute} from './di';
21+
export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './interface/lifecycle_hooks';
22+
export {ANALYZE_FOR_ENTRY_COMPONENTS, ContentChild, ContentChildDecorator, ContentChildren, ContentChildrenDecorator, Query, ViewChild, ViewChildDecorator, ViewChildren, ViewChildrenDecorator} from './metadata/di';
2023
export {Component, ComponentDecorator, Directive, DirectiveDecorator, HostBinding, HostListener, Input, Output, Pipe} from './metadata/directives';
21-
export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './metadata/lifecycle_hooks';
2224
export {CUSTOM_ELEMENTS_SCHEMA, DoBootstrap, ModuleWithProviders, NO_ERRORS_SCHEMA, NgModule, SchemaMetadata} from './metadata/ng_module';
2325
export {ViewEncapsulation} from './metadata/view';

packages/core/src/metadata/di.ts

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {InjectionToken} from '../di/injection_token';
1010
import {Type} from '../interface/type';
11-
import {makeParamDecorator, makePropDecorator} from '../util/decorators';
11+
import {makePropDecorator} from '../util/decorators';
1212

1313
/**
1414
* This token can be used to create a virtual provider that will populate the
@@ -47,71 +47,6 @@ import {makeParamDecorator, makePropDecorator} from '../util/decorators';
4747
*/
4848
export const ANALYZE_FOR_ENTRY_COMPONENTS = new InjectionToken<any>('AnalyzeForEntryComponents');
4949

50-
/**
51-
* Type of the Attribute decorator / constructor function.
52-
*
53-
* @publicApi
54-
*/
55-
export interface AttributeDecorator {
56-
/**
57-
* Specifies that a constant attribute value should be injected.
58-
*
59-
* The directive can inject constant string literals of host element attributes.
60-
*
61-
* @usageNotes
62-
* ### Example
63-
*
64-
* Suppose we have an `<input>` element and want to know its `type`.
65-
*
66-
* ```html
67-
* <input type="text">
68-
* ```
69-
*
70-
* A decorator can inject string literal `text` like so:
71-
*
72-
* {@example core/ts/metadata/metadata.ts region='attributeMetadata'}
73-
*
74-
* ### Example as TypeScript Decorator
75-
*
76-
* {@example core/ts/metadata/metadata.ts region='attributeFactory'}
77-
*
78-
* ### Example as ES5 annotation
79-
*
80-
* ```
81-
* var MyComponent = function(title) {
82-
* ...
83-
* };
84-
*
85-
* MyComponent.annotations = [
86-
* new ng.Component({...})
87-
* ]
88-
* MyComponent.parameters = [
89-
* [new ng.Attribute('title')]
90-
* ]
91-
* ```
92-
*
93-
* @publicApi
94-
*/
95-
(name: string): any;
96-
new (name: string): Attribute;
97-
}
98-
99-
100-
/**
101-
* Type of the Attribute metadata.
102-
*
103-
* @publicApi
104-
*/
105-
export interface Attribute { attributeName?: string; }
106-
107-
/**
108-
* Attribute decorator and metadata.
109-
*
110-
* @Annotation
111-
* @publicApi
112-
*/
113-
export const Attribute: AttributeDecorator =
114-
makeParamDecorator('Attribute', (attributeName?: string) => ({attributeName}));
11550

11651
/**
11752
* Type of the Query metadata.

0 commit comments

Comments
 (0)