From 063a333188125014f8fa49bd77ce9a390577a70c Mon Sep 17 00:00:00 2001 From: Lucas Galfaso Date: Sun, 3 May 2015 21:25:32 +0200 Subject: [PATCH] fix($compile): workaround for IE11 MutationObserver IE11 MutationObserver breaks consecutive text nodes into several text nodes. This patch merges consecutive text nodes into a single node before looking for interpolations. Closes #11781 --- src/ng/compile.js | 7 +++++++ test/ng/compileSpec.js | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ng/compile.js b/src/ng/compile.js index 0aba65aec107..82a6a92f508f 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1540,6 +1540,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { } break; case NODE_TYPE_TEXT: /* Text Node */ + if (msie === 11) { + // Workaround for #11781 + while (node.parentNode && node.nextSibling && node.nextSibling.nodeType === NODE_TYPE_TEXT) { + node.nodeValue = node.nodeValue + node.nextSibling.nodeValue; + node.parentNode.removeChild(node.nextSibling); + } + } addTextInterpolateDirective(directives, node.nodeValue); break; case NODE_TYPE_COMMENT: /* Comment */ diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index b89f1d08312c..c750a35da0a4 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -2762,6 +2762,23 @@ describe('$compile', function() { })); + it('should handle consecutive text elements as a single text element', inject(function($rootScope, $compile) { + window.addMutationObserver = function() { + if (!window.MutationObserver) { + return; + } + new window.MutationObserver(function() {}).observe(document.body, { + childList: true, + subtree: true + }); + }; + var base = jqLite('
— {{ "This doesn\'t." }}
'); + element = $compile(base)($rootScope); + $rootScope.$digest(); + expect(element.text()).toBe("— This doesn't."); + })); + + it('should support custom start/end interpolation symbols in template and directive template', function() { module(function($interpolateProvider, $compileProvider) {