angular/packages/compiler-cli/test
wszgrcy 8d2b6affcd fix(compiler-cli): correctly interpret token arrays in @Injectable deps (#43226)
When specifying the `deps` array in the `@Injectable` decorator to
inject dependencies into the injectable's factory function, it should
be possible to use an array literal to configure how the dependency
should be resolved by the DI system.

For example, the following example is allowed:

```ts
@Injectable({
  providedIn: 'root',
  useFactory: a => new AppService(a),
  deps: [[new Optional(), 'a']],
})
export class AppService {
  constructor(a) {}
}
```

Here, the `'a'` string token should be injected as optional. However,
the AOT compiler incorrectly used the array literal itself as injection
token, resulting in a failure at runtime. Only if the token were to be
provided using `[new Optional(), new Inject('a')]` would it work
correctly.

This commit fixes the issue by using the last non-decorator in the
array literal as the token value, instead of the array literal itself.

Note that this is a loose interpretation of array literals: if a token
is omitted from the array literal then the array literal itself is used
as token, but any decorator such as `new Optional()` would still have
been applied. When there's multiple tokens in the list then only the
last one will be used as actual token, any prior tokens are silently
ignored. This behavior mirrors the JIT interpretation so is kept as is
for now, but may benefit from some stricter checking and better error
reporting in the future.

Fixes #42987

PR Close #43226
2021-09-28 14:15:48 -07:00
..
compliance fix(compiler-cli): correctly interpret token arrays in @Injectable deps (#43226) 2021-09-28 14:15:48 -07:00
diagnostics feat(compiler-cli): add support for TypeScript 4.0 (#38076) 2020-08-24 13:06:59 -07:00
metadata refactor(compiler-cli): ensure compatibility with noImplicitOverride (#42512) 2021-07-12 13:11:14 -07:00
ngtsc fix(compiler-cli): correctly interpret token arrays in @Injectable deps (#43226) 2021-09-28 14:15:48 -07:00
transformers feat(core): support TypeScript 4.4 (#43281) 2021-09-23 14:49:19 -07:00
BUILD.bazel fix(compiler-cli): readConfiguration existing options should override options in tsconfig (#40694) 2021-02-11 13:29:51 -08:00
extract_i18n_spec.ts refactor(compiler): element.sourceSpan should span the outerHTML (#38581) 2020-09-02 14:47:31 -07:00
mocks.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
ngc_spec.ts fix(compiler-cli): Emit type annotations for synthesized decorator fields (#43021) 2021-08-25 15:05:28 -07:00
perform_compile_spec.ts fix(compiler-cli): fix extending angularCompilerOptions from non relative extension less TypeScript configuration files (#41349) 2021-04-07 09:37:44 -07:00
perform_watch_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
test_support.ts test(compiler-cli): move testing utils to separate package (#39594) 2020-11-17 11:59:56 -08:00
typescript_support_spec.ts build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00