From 5c5109f5910647270c75ed5120de08b1ec919a03 Mon Sep 17 00:00:00 2001 From: Rafael Weinstein Date: Tue, 14 Jan 2014 14:32:41 -0800 Subject: [PATCH] Fix template.ref R=arv, jmesserly BUG= Review URL: https://codereview.appspot.com/52350043 --- src/TemplateBinding.js | 3 ++- tests/tests.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/TemplateBinding.js b/src/TemplateBinding.js index 5e6bd38..8db0e8a 100644 --- a/src/TemplateBinding.js +++ b/src/TemplateBinding.js @@ -496,7 +496,8 @@ ref = treeScope.getElementById(refId); if (!ref) { var instanceRoot = getInstanceRoot(this); - ref = instanceRoot.querySelector('#' + refId); + if (instanceRoot) + ref = instanceRoot.querySelector('#' + refId); } } diff --git a/tests/tests.js b/tests/tests.js index c45a8a0..6354a76 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -3006,6 +3006,17 @@ suite('Binding Delegate API', function() { done(); }); }); + + test('issue-152', function() { + var div = createTestHtml( + ''); + + var template = div.firstChild; + + // if a ref cannot be located, a template will continue to use itself + // as the source of template instances. + assert.strictEqual(template, template.ref); + }); }); suite('Compat', function() {