fix(core): make decorators closure safe (#16905)

This is required as e.g. `token` from `@Inject` is
accessed in string form via makeParamDecorator
but as a property in the `ReflectiveInjector`.

Closes #16889 as this is a more general fix.
This commit is contained in:
Tobias Bosch
2017-05-23 10:52:40 -07:00
committed by Chuck Jazdzewski
parent 5af143e8e4
commit a80ac0a8d3
9 changed files with 76 additions and 122 deletions

View File

@ -58,7 +58,7 @@ export interface Inject { token: any; }
* @stable
* @Annotation
*/
export const Inject: InjectDecorator = makeParamDecorator('Inject', [['token', undefined]]);
export const Inject: InjectDecorator = makeParamDecorator('Inject', (token: any) => ({token}));
/**
@ -104,7 +104,7 @@ export interface Optional {}
* @stable
* @Annotation
*/
export const Optional: OptionalDecorator = makeParamDecorator('Optional', []);
export const Optional: OptionalDecorator = makeParamDecorator('Optional');
/**
* Type of the Injectable decorator / constructor function.
@ -151,7 +151,7 @@ export interface Injectable {}
* @stable
* @Annotation
*/
export const Injectable: InjectableDecorator = <InjectableDecorator>makeDecorator('Injectable', []);
export const Injectable: InjectableDecorator = <InjectableDecorator>makeDecorator('Injectable');
/**
* Type of the Self decorator / constructor function.
@ -195,7 +195,7 @@ export interface Self {}
* @stable
* @Annotation
*/
export const Self: SelfDecorator = makeParamDecorator('Self', []);
export const Self: SelfDecorator = makeParamDecorator('Self');
/**
@ -240,7 +240,7 @@ export interface SkipSelf {}
* @stable
* @Annotation
*/
export const SkipSelf: SkipSelfDecorator = makeParamDecorator('SkipSelf', []);
export const SkipSelf: SkipSelfDecorator = makeParamDecorator('SkipSelf');
/**
* Type of the Host decorator / constructor function.
@ -285,4 +285,4 @@ export interface Host {}
* @stable
* @Annotation
*/
export const Host: HostDecorator = makeParamDecorator('Host', []);
export const Host: HostDecorator = makeParamDecorator('Host');

View File

@ -225,7 +225,7 @@ function _extractToken(
if (!Array.isArray(metadata)) {
if (metadata instanceof Inject) {
return _createDependency(metadata['token'], optional, null);
return _createDependency(metadata.token, optional, null);
} else {
return _createDependency(metadata, optional, null);
}
@ -240,7 +240,7 @@ function _extractToken(
token = paramMetadata;
} else if (paramMetadata instanceof Inject) {
token = paramMetadata['token'];
token = paramMetadata.token;
} else if (paramMetadata instanceof Optional) {
optional = true;