angular/packages/core/src
Misko Hevery 33630dd3ed fix(ivy): workaround for tsickle bug (#23379)
The issue is with tsickle type inference and the bug should be assigned to them.

The offending code is:
```
function cacheMatchingDirectivesForNode(
    tNode: TNode, tView: TView, localRefs: string[] | null): void {
  const exportsMap = localRefs ? {'': -1} : null;     // <<<<< ===== OFFENDING LINE
  const matches = tView.currentMatches = findDirectiveMatches(tNode);
  if (matches) {
    for (let i = 0; i < matches.length; i += 2) {
      const def = matches[i] as DirectiveDef<any>;
      const valueIndex = i + 1;
      resolveDirective(def, valueIndex, matches, tView);
      saveNameToExportMap(matches[valueIndex] as number, def, exportsMap);
    }
  }
  if (exportsMap) cacheMatchingLocalNames(tNode, localRefs, exportsMap);
}

```

because it generates invalid js closure code:
```
function cacheMatchingDirectivesForNode(tNode, tView, localRefs) {
    const /** @type {(null|{: number})} */ exportsMap = localRefs ? { '': -1 } : null;      // <<<<< ===== OFFENDING LINE
    const /** @type {(null|!Array<?>)} */ matches = tView.currentMatches = findDirectiveMatches(tNode);
    if (matches) {
        for (let /** @type {number} */ i = 0; i < matches.length; i += 2) {
            const /** @type {!tsickle_forward_declare_11.DirectiveDef<?>} */ def = /** @type {!tsickle_forward_declare_11.DirectiveDef<?>} */ (matches[i]);
            const /** @type {number} */ valueIndex = i + 1;
            resolveDirective(def, valueIndex, matches, tView);
            saveNameToExportMap(/** @type {number} */ (matches[valueIndex]), def, exportsMap);
        }
    }
    if (exportsMap)
        cacheMatchingLocalNames(tNode, localRefs, exportsMap);
}
```

The workaround is to declare the type explicitly such as:

```
const exportsMap: ({[key:string]:number}|null) = localRefs ? {'': -1} : null;
```

which than generates valid closure code:

```
const /** @type {(null|!Object<string,number>)} */ exportsMap = localRefs ? { '': -1 } : null;
```

PR Close #23379
2018-04-13 21:29:39 -07:00
..
change_detection refactor(ivy): make return value of define(Component|Directive|Pipe|Injector|Injectable) private (#23371) 2018-04-13 16:20:25 -07:00
debug build: update npm dependencies (#19328) 2017-09-22 13:20:52 -07:00
di refactor(ivy): make return value of define(Component|Directive|Pipe|Injector|Injectable) private (#23371) 2018-04-13 16:20:25 -07:00
i18n docs(core): add docs for i18n tokens (#17920) 2017-12-05 21:56:43 -08:00
linker docs: remove all deprecated @stable jsdoc tags (#23210) 2018-04-10 21:49:32 -07:00
metadata refactor(ivy): make return value of define(Component|Directive|Pipe|Injector|Injectable) private (#23371) 2018-04-13 16:20:25 -07:00
profile fix(core): Update types for TypeScript nullability support (#15472) 2017-03-29 09:34:45 -07:00
reflection feat(core): support metadata reflection for native class types (#22356) 2018-02-22 13:22:03 -08:00
render docs: fix link texts 2017-11-01 15:44:59 -04:00
render3 fix(ivy): workaround for tsickle bug (#23379) 2018-04-13 21:29:39 -07:00
sanitization docs: remove all deprecated @stable jsdoc tags (#23210) 2018-04-10 21:49:32 -07:00
testability feat(core): add task tracking to Testability (#16863) 2018-03-14 08:48:48 -07:00
util refactor: ensure all 'TODO's are consistent (#23252) 2018-04-13 13:11:01 -07:00
view refactor(ivy): make return value of define(Component|Directive|Pipe|Injector|Injectable) private (#23371) 2018-04-13 16:20:25 -07:00
zone feat(core): add task tracking to Testability (#16863) 2018-03-14 08:48:48 -07:00
application_init.ts refactor(core): removed getter and changed to readonly variable (#19117) 2017-09-20 12:38:57 -07:00
application_module.ts refactor: core, http & platform-webworker to remove public private class separation (#19143) 2017-09-14 13:38:06 -04:00
application_ref.ts docs: remove all deprecated @stable jsdoc tags (#23210) 2018-04-10 21:49:32 -07:00
application_tokens.ts docs: fix link texts 2017-11-01 15:44:59 -04:00
change_detection.ts refactor(core): remove deprecated TrackByFn (#18757) 2017-08-18 13:23:46 -05:00
codegen_private_exports.ts refactor(compiler): don’t rely on global reflector (#16832) 2017-05-23 10:41:23 -06:00
console.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
core.externs.js fix: don’t use the global ng at all with closure enhanced optimizations 2017-09-27 10:09:56 -07:00
core.ts fix(core): remove core animation import symbols (#22692) 2018-03-14 12:23:51 -07:00
core_private_export.ts feat(ivy): support injection even if no injector present (#23345) 2018-04-13 14:29:52 -07:00
core_render3_private_export.ts refactor(ivy): make return value of define(Component|Directive|Pipe|Injector|Injectable) private (#23371) 2018-04-13 16:20:25 -07:00
di.ts feat(ivy): @NgModule -> ngInjectorDef compilation (#22458) 2018-03-16 12:57:11 -07:00
error_handler.ts docs: remove all deprecated @stable jsdoc tags (#23210) 2018-04-10 21:49:32 -07:00
errors.ts refactor(compiler): split compiler and core (#18683) 2017-08-16 17:58:53 -05:00
event_emitter.ts docs: remove all deprecated @stable jsdoc tags (#23210) 2018-04-10 21:49:32 -07:00
linker.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
metadata.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
platform_core_providers.ts refactor: core, http & platform-webworker to remove public private class separation (#19143) 2017-09-14 13:38:06 -04:00
render.ts refactor(core): use flags in Renderer2.setStyle instead of booleans (#15045) 2017-03-13 09:45:04 -07:00
type.ts docs: remove all deprecated @stable jsdoc tags (#23210) 2018-04-10 21:49:32 -07:00
util.ts fix(core): should check Zone existance when scheduleMicroTask (#20656) 2018-02-02 07:53:55 -08:00
version.ts docs: remove all deprecated @stable jsdoc tags (#23210) 2018-04-10 21:49:32 -07:00
zone.ts refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00