From 5e5cda56e59661fb6c00aa2d34e16cc9e9653791 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 12 Feb 2018 17:50:23 +0200 Subject: [PATCH] fix(upgrade): fix empty transclusion content with AngularJS@>=1.5.8 The function provided by `ngUpgrade` as `parentBoundTranscludeFn` when upgrading a component with transclusion, will break in AngularJS v1.5.8+ if no transclusion content is provided. The reason is that AngularJS will try to destroy the transclusion scope (which would not be needed any more). But since the transcluded content comes from Angular, not AngularJS, there is no transclusion scope to destroy. This commit fixes it by providing a dummy scope object with a no-op `$destroy()` method. See https://github.com/angular/angular/issues/13271#issuecomment-364861088. --- package.json | 6 +++--- packages/upgrade/src/common/upgrade_helper.ts | 10 ++++++++-- yarn.lock | 18 +++++++++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 0ed233810fcf32..bea98f598b323b 100644 --- a/package.json +++ b/package.json @@ -47,9 +47,9 @@ "@types/selenium-webdriver": "3.0.7", "@types/source-map": "^0.5.1", "@types/systemjs": "0.19.32", - "angular": "1.5.0", - "angular-animate": "1.5.0", - "angular-mocks": "1.5.0", + "angular": "1.6.9", + "angular-animate": "1.6.9", + "angular-mocks": "1.6.9", "base64-js": "1.2.1", "bower": "1.8.2", "browserstacktunnel-wrapper": "2.0.1", diff --git a/packages/upgrade/src/common/upgrade_helper.ts b/packages/upgrade/src/common/upgrade_helper.ts index 0b9c6a8022df05..e570ab9f4d270a 100644 --- a/packages/upgrade/src/common/upgrade_helper.ts +++ b/packages/upgrade/src/common/upgrade_helper.ts @@ -123,8 +123,14 @@ export class UpgradeHelper { const transclude = this.directive.transclude; const contentChildNodes = this.extractChildNodes(); let $template = contentChildNodes; - let attachChildrenFn: angular.ILinkFn|undefined = (scope, cloneAttach) => - cloneAttach !($template, scope); + let attachChildrenFn: angular.ILinkFn = (scope, cloneAttachFn) => { + // Since AngularJS v1.5.8, `cloneAttachFn` will try to destroy the transclusion scope if + // `$template` is empty. Since the transcluded content comes from Angular, not AngularJS, + // there will be no transclusion scope here. + // Provide a dummy `scope.$destroy()` method to prevent `cloneAttachFn` from throwing. + scope = scope || {$destroy: () => undefined}; + return cloneAttachFn!($template, scope); + }; if (transclude) { const slots = Object.create(null); diff --git a/yarn.lock b/yarn.lock index 05f87a79e092ab..c92e4f9aaf016d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -227,17 +227,17 @@ amdetective@0.0.2: dependencies: esprima "~1.2.2" -angular-animate@1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/angular-animate/-/angular-animate-1.5.0.tgz#0e31f31fa7ab2ddf5ea5787e476548644d62fb93" +angular-animate@1.6.9: + version "1.6.9" + resolved "https://registry.yarnpkg.com/angular-animate/-/angular-animate-1.6.9.tgz#a0f926c1ba3190bd8929ef966a7fa79760682622" -angular-mocks@1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/angular-mocks/-/angular-mocks-1.5.0.tgz#81b3e4b21098d7c545c6f0a0a97f897b26879dd9" +angular-mocks@1.6.9: + version "1.6.9" + resolved "https://registry.yarnpkg.com/angular-mocks/-/angular-mocks-1.6.9.tgz#4fed8c8293a5080e0919a7ff0dcf0f704864b7ba" -angular@1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/angular/-/angular-1.5.0.tgz#d96ee97ab6df6cfd0915accbee484d098adb74ec" +angular@1.6.9: + version "1.6.9" + resolved "https://registry.yarnpkg.com/angular/-/angular-1.6.9.tgz#bc812932e18909038412d594a5990f4bb66c0619" ansi-align@^1.1.0: version "1.1.0"