Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/common/src/directives/ng_for_of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ChangeDetectorRef, Directive, DoCheck, EmbeddedViewRef, Input, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDiffers, NgIterable, TemplateRef, TrackByFunction, ViewContainerRef, forwardRef, isDevMode} from '@angular/core';
import {Directive, DoCheck, EmbeddedViewRef, Input, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDiffers, NgIterable, TemplateRef, TrackByFunction, ViewContainerRef, forwardRef, isDevMode} from '@angular/core';

/**
* @publicApi
Expand Down Expand Up @@ -151,7 +151,7 @@ export class NgForOf<T> implements DoCheck {
this._differ = this._differs.find(value).create(this.ngForTrackBy);
} catch {
throw new Error(
`Cannot find a differ supporting object '${value}' of type '${getTypeNameForDebugging(value)}'. NgFor only supports binding to Iterables such as Arrays.`);
`Cannot find a differ supporting object '${value}' of type '${getTypeName(value)}'. NgFor only supports binding to Iterables such as Arrays.`);
}
}
}
Expand Down Expand Up @@ -218,6 +218,6 @@ class RecordViewTuple<T> {
constructor(public record: any, public view: EmbeddedViewRef<NgForOfContext<T>>) {}
}

export function getTypeNameForDebugging(type: any): string {
function getTypeName(type: any): string {
return type['name'] || typeof type;
}
1 change: 1 addition & 0 deletions packages/compiler/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/test/compiler_facade_interface_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 2 additions & 0 deletions packages/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions packages/core/src/change_detection/change_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand Down
20 changes: 20 additions & 0 deletions packages/core/src/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/di/injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down
33 changes: 33 additions & 0 deletions packages/core/src/di/jit/environment.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down Expand Up @@ -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;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
64 changes: 64 additions & 0 deletions packages/core/src/di/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
2 changes: 1 addition & 1 deletion packages/core/src/di/r3_injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/di/reflective_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
9 changes: 0 additions & 9 deletions packages/core/src/error_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import {getDebugContext, getErrorLogger, getOriginalError} from './errors';
import {ERROR_ORIGINAL_ERROR} from './util/errors';



Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Loading