Skip to content

Commit

Permalink
docs: fix typo in dependency injection guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ashinzekene committed Dec 13, 2018
2 parents f2e2833 + 7fabe44 commit 251e51c
Show file tree
Hide file tree
Showing 27 changed files with 550 additions and 427 deletions.
6 changes: 6 additions & 0 deletions aio/content/marketing/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,12 @@
"title": "SFEIR School (French)",
"url": "https://school.sfeir.com/project/sa200/"
},
"zenika-angular": {
"desc": "Angular trainings delivered by Zenika (FRANCE)",
"rev": true,
"title": "Angular Trainings (French)",
"url": "https://training.zenika.com/fr/training/angular2/description"
},
"formationjs": {
"desc": "Angular onsite training in Paris (France). Monthly Angular workshops and custom onsite classes. We are focused on Angular, so we are always up to date.",
"rev": true,
Expand Down
7 changes: 3 additions & 4 deletions aio/src/styles/1-layouts/_top-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,13 @@ aio-top-menu {

a.nav-link {
margin: 0;
padding: 24px 16px;
padding: 8px 16px;
cursor: pointer;

border-radius: 4px;

&:focus {
background: rgba($white, 0.15);
border-radius: 4px;
outline: none;
padding: 8px 16px;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"bazel:lint": "yarn bazel:format --lint=warn",
"bazel:lint-fix": "yarn bazel:format --lint=fix",
"preinstall": "node tools/yarn/check-yarn.js",
"postinstall": "yarn update-webdriver && node ./tools/postinstall-patches.js",
"postinstall": "yarn update-webdriver && node --preserve-symlinks --preserve-symlinks-main ./tools/postinstall-patches.js",
"update-webdriver": "webdriver-manager update --gecko false $CHROMEDRIVER_VERSION_ARG",
"check-env": "gulp check-env",
"commitmsg": "node ./scripts/git/commit-msg.js",
Expand Down Expand Up @@ -76,7 +76,7 @@
"shelljs": "^0.8.1",
"source-map": "^0.6.1",
"source-map-support": "0.5.9",
"tsickle": "0.32.1",
"tsickle": "0.33.1",
"tslib": "^1.7.1",
"typescript": "~3.1.1",
"xhr2": "0.1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ ng_module(
],
),
module_name = "app_built",
tags = [
"fixme-ivy-aot",
],
deps = [
"//packages/compiler-cli/integrationtest/bazel/injectable_def/lib2",
"//packages/core",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @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
*/

export {RootAppModule} from './root';
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ ts_library(
"**/*.ts",
],
),
tags = [
"fixme-ivy-aot",
],
deps = [
"//packages/compiler-cli/integrationtest/bazel/injectable_def/app",
"//packages/core",
Expand All @@ -25,9 +22,6 @@ ts_library(
jasmine_node_test(
name = "test",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
tags = [
"fixme-ivy-aot",
],
deps = [
":test_lib",
"//packages/platform-server",
Expand Down
18 changes: 10 additions & 8 deletions packages/compiler-cli/src/ngcc/src/host/esm2015_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,11 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
this.getParamInfoFromHelperCall(classSymbol, parameterNodes);

return parameterNodes.map((node, index) => {
const {decorators, type} =
paramInfo && paramInfo[index] ? paramInfo[index] : {decorators: null, type: null};
const {decorators, typeExpression} = paramInfo && paramInfo[index] ?
paramInfo[index] :
{decorators: null, typeExpression: null};
const nameNode = node.name;
return {name: getNameText(nameNode), nameNode, type, decorators};
return {name: getNameText(nameNode), nameNode, typeExpression, typeNode: null, decorators};
});
}

Expand Down Expand Up @@ -832,12 +833,12 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
element =>
ts.isObjectLiteralExpression(element) ? reflectObjectLiteral(element) : null)
.map(paramInfo => {
const type = paramInfo && paramInfo.get('type') || null;
const typeExpression = paramInfo && paramInfo.get('type') || null;
const decoratorInfo = paramInfo && paramInfo.get('decorators') || null;
const decorators = decoratorInfo &&
this.reflectDecorators(decoratorInfo)
.filter(decorator => this.isFromCore(decorator));
return {type, decorators};
return {typeExpression, decorators};
});
}
}
Expand All @@ -857,7 +858,8 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
*/
protected getParamInfoFromHelperCall(
classSymbol: ts.Symbol, parameterNodes: ts.ParameterDeclaration[]): ParamInfo[] {
const parameters: ParamInfo[] = parameterNodes.map(() => ({type: null, decorators: null}));
const parameters: ParamInfo[] =
parameterNodes.map(() => ({typeExpression: null, decorators: null}));
const helperCalls = this.getHelperCallsForClass(classSymbol, '__decorate');
helperCalls.forEach(helperCall => {
const {classDecorators} =
Expand All @@ -871,7 +873,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
metadataArg.text === 'design:paramtypes';
const types = typesArg && ts.isArrayLiteralExpression(typesArg) && typesArg.elements;
if (isParamTypeDecorator && types) {
types.forEach((type, index) => parameters[index].type = type);
types.forEach((type, index) => parameters[index].typeExpression = type);
}
break;
case '__param':
Expand Down Expand Up @@ -1024,7 +1026,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N

export type ParamInfo = {
decorators: Decorator[] | null,
type: ts.Expression | null
typeExpression: ts.Expression | null
};

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/src/ngcc/src/host/esm5_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost {
if (expression && ts.isArrayLiteralExpression(expression)) {
const elements = expression.elements;
return elements.map(reflectArrayElement).map(paramInfo => {
const type = paramInfo && paramInfo.get('type') || null;
const typeExpression = paramInfo && paramInfo.get('type') || null;
const decoratorInfo = paramInfo && paramInfo.get('decorators') || null;
const decorators = decoratorInfo && this.reflectDecorators(decoratorInfo);
return {type, decorators};
return {typeExpression, decorators};
});
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
expect(parameters !.map(parameter => parameter.name)).toEqual([
'_viewContainer', '_template', 'injected'
]);
expect(parameters !.map(parameter => parameter.type !.getText())).toEqual([
expect(parameters !.map(parameter => parameter.typeExpression !.getText())).toEqual([
'ViewContainerRef', 'TemplateRef', 'String'
]);
});
Expand Down Expand Up @@ -296,7 +296,7 @@ describe('Fesm2015ReflectionHost [import helper style]', () => {
const classNode = getDeclaration(
program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration);
const ctrDecorators = host.getConstructorParameters(classNode) !;
const identifierOfViewContainerRef = ctrDecorators[0].type !as ts.Identifier;
const identifierOfViewContainerRef = ctrDecorators[0].typeExpression !as ts.Identifier;

const expectedDeclarationNode = getDeclaration(
program, '/some_directive.js', 'ViewContainerRef', ts.isClassDeclaration);
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/src/ngcc/test/host/esm2015_host_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ describe('Fesm2015ReflectionHost', () => {
expect(parameters.map(parameter => parameter.name)).toEqual([
'_viewContainer', '_template', 'injected'
]);
expect(parameters.map(parameter => parameter.type !.getText())).toEqual([
expect(parameters.map(parameter => parameter.typeExpression !.getText())).toEqual([
'ViewContainerRef', 'TemplateRef', 'undefined'
]);
});
Expand Down Expand Up @@ -1140,7 +1140,7 @@ describe('Fesm2015ReflectionHost', () => {
const classNode =
getDeclaration(program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isClassDeclaration);
const ctrDecorators = host.getConstructorParameters(classNode) !;
const identifierOfViewContainerRef = ctrDecorators[0].type !as ts.Identifier;
const identifierOfViewContainerRef = ctrDecorators[0].typeExpression !as ts.Identifier;

const expectedDeclarationNode = getDeclaration(
program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', ts.isVariableDeclaration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
expect(parameters !.map(parameter => parameter.name)).toEqual([
'_viewContainer', '_template', 'injected'
]);
expect(parameters !.map(parameter => parameter.type !.getText())).toEqual([
expect(parameters !.map(parameter => parameter.typeExpression !.getText())).toEqual([
'ViewContainerRef', 'TemplateRef', 'String'
]);
});
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('Esm5ReflectionHost [import helper style]', () => {
const classNode = getDeclaration(
program, '/some_directive.js', 'SomeDirective', ts.isVariableDeclaration);
const ctrDecorators = host.getConstructorParameters(classNode) !;
const identifierOfViewContainerRef = ctrDecorators[0].type !as ts.Identifier;
const identifierOfViewContainerRef = ctrDecorators[0].typeExpression !as ts.Identifier;

const expectedDeclarationNode = getDeclaration(
program, '/some_directive.js', 'ViewContainerRef', ts.isVariableDeclaration);
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/src/ngcc/test/host/esm5_host_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ describe('Esm5ReflectionHost', () => {
expect(parameters !.map(parameter => parameter.name)).toEqual([
'_viewContainer', '_template', 'injected'
]);
expect(parameters !.map(parameter => parameter.type !.getText())).toEqual([
expect(parameters !.map(parameter => parameter.typeExpression !.getText())).toEqual([
'ViewContainerRef', 'TemplateRef', 'undefined'
]);
});
Expand Down Expand Up @@ -1079,7 +1079,7 @@ describe('Esm5ReflectionHost', () => {
const classNode = getDeclaration(
program, SOME_DIRECTIVE_FILE.name, 'SomeDirective', ts.isVariableDeclaration);
const ctrDecorators = host.getConstructorParameters(classNode) !;
const identifierOfViewContainerRef = ctrDecorators[0].type !as ts.Identifier;
const identifierOfViewContainerRef = ctrDecorators[0].typeExpression !as ts.Identifier;

const expectedDeclarationNode = getDeclaration(
program, SOME_DIRECTIVE_FILE.name, 'ViewContainerRef', ts.isVariableDeclaration);
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export function generateSetClassMetadataCall(
function ctorParameterToMetadata(param: CtorParameter, isCore: boolean): ts.Expression {
// Parameters sometimes have a type that can be referenced. If so, then use it, otherwise
// its type is undefined.
const type = param.type !== null ? param.type : ts.createIdentifier('undefined');
const type =
param.typeExpression !== null ? param.typeExpression : ts.createIdentifier('undefined');
const properties: ts.ObjectLiteralElementLike[] = [
ts.createPropertyAssignment('type', type),
];
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/src/ngtsc/annotations/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function getConstructorDependencies(
}
}
ctorParams.forEach((param, idx) => {
let tokenExpr = param.type;
let tokenExpr = param.typeExpression;
let optional = false, self = false, skipSelf = false, host = false;
let resolved = R3ResolvedDependencyType.Token;
(param.decorators || []).filter(dec => isCore || isAngularCore(dec)).forEach(dec => {
Expand Down Expand Up @@ -62,7 +62,7 @@ export function getConstructorDependencies(
if (tokenExpr === null) {
throw new FatalDiagnosticError(
ErrorCode.PARAM_MISSING_TOKEN, param.nameNode,
`No suitable token for parameter ${param.name || idx} of class ${clazz.name!.text}`);
`No suitable injection token for parameter '${param.name || idx}' of class '${clazz.name!.text}'. Found: ${param.typeNode!.getText()}`);
}
const token = new WrappedNodeExpr(tokenExpr);
useType.push({token, optional, self, skipSelf, host, resolved});
Expand Down
16 changes: 13 additions & 3 deletions packages/compiler-cli/src/ngtsc/host/src/reflection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,22 @@ export interface CtorParameter {
nameNode: ts.BindingName;

/**
* TypeScript `ts.Expression` representing the type of the parameter, if the type is a simple
* expression type.
* TypeScript `ts.Expression` representing the type value of the parameter, if the type is a
* simple
* expression type that can be converted to a value.
*
* If the type is not present or cannot be represented as an expression, `type` is `null`.
*/
type: ts.Expression|null;
typeExpression: ts.Expression|null;

/**
* TypeScript `ts.TypeNode` representing the type node found in the type position.
*
* This field can be used for diagnostics reporting if `typeExpression` is `null`.
*
* Can be null, if the param has no type declared.
*/
typeNode: ts.TypeNode|null;

/**
* Any `Decorator`s which are present on the parameter, or `null` if none are present.
Expand Down
32 changes: 25 additions & 7 deletions packages/compiler-cli/src/ngtsc/metadata/src/reflector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,43 @@ export class TypeScriptReflectionHost implements ReflectionHost {
// It may or may not be possible to write an expression that refers to the value side of the
// type named for the parameter.
let typeValueExpr: ts.Expression|null = null;
let originalTypeNode = node.type || null;
let typeNode = originalTypeNode;

// Check if we are dealing with a simple nullable union type e.g. `foo: Foo|null`
// and extract the type. More complext union types e.g. `foo: Foo|Bar` are not supported.
// We also don't need to support `foo: Foo|undefined` because Angular's DI injects `null` for
// optional tokes that don't have providers.
if (typeNode && ts.isUnionTypeNode(typeNode)) {
let childTypeNodes = typeNode.types.filter(
childTypeNode => childTypeNode.kind !== ts.SyntaxKind.NullKeyword);

if (childTypeNodes.length === 1) {
typeNode = childTypeNodes[0];
} else {
typeNode = null;
}
}

// It's not possible to get a value expression if the parameter doesn't even have a type.
if (node.type !== undefined) {
if (typeNode) {
// It's only valid to convert a type reference to a value reference if the type actually has
// a
// value declaration associated with it.
const type = this.checker.getTypeFromTypeNode(node.type);
if (type.symbol !== undefined && type.symbol.valueDeclaration !== undefined) {
// a value declaration associated with it.
let type: ts.Type|null = this.checker.getTypeFromTypeNode(typeNode);

if (type && type.symbol !== undefined && type.symbol.valueDeclaration !== undefined) {
// The type points to a valid value declaration. Rewrite the TypeReference into an
// Expression
// which references the value pointed to by the TypeReference, if possible.
typeValueExpr = typeNodeToValueExpr(node.type);
typeValueExpr = typeNodeToValueExpr(typeNode);
}
}

return {
name,
nameNode: node.name,
type: typeValueExpr, decorators,
typeExpression: typeValueExpr,
typeNode: originalTypeNode, decorators,
};
});
}
Expand Down

0 comments on commit 251e51c

Please sign in to comment.