Skip to content

Commit

Permalink
Merge pull request #358 from znewsham/znewsham-patch-1
Browse files Browse the repository at this point in the history
Make Template.contentBlock consistent
  • Loading branch information
StorytellerCZ committed Apr 6, 2022
2 parents 23a578a + 2a841d3 commit 4a52314
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion HISTORY.md
@@ -1,7 +1,8 @@
## v2.6.0, 2021-June-XX
## v2.6.0, 2022-April-XX

* [#330](https://github.com/meteor/blaze/pull/330) Removed deprecated APIs
* [#341](https://github.com/meteor/blaze/pull/341) Add support for arbitrary iterables in #each templates
* [#358](https://github.com/meteor/blaze/pull/358) Make Template.contentBlock consistent with/out data provided

## v2.5.0, 2021-June-5

Expand Down
24 changes: 20 additions & 4 deletions packages/blaze/lookup.js
Expand Up @@ -84,6 +84,25 @@ var wrapHelper = function (f, templateFunc) {
};
};

function _lexicalKeepGoing(currentView) {
if (!currentView.parentView) {
return undefined;
}
if (!currentView.__startsNewLexicalScope) {
return currentView.parentView;
}
if (currentView.parentView.__childDoesntStartNewLexicalScope) {
return currentView.parentView;
}

// in the case of {{> Template.contentBlock data}} the contentBlock loses the lexical scope of it's parent, wheras {{> Template.contentBlock}} it does not
// this is because a #with sits between the include InOuterTemplateScope
if (currentView.parentView.name === "with" && currentView.parentView.parentView && currentView.parentView.parentView.__childDoesntStartNewLexicalScope) {
return currentView.parentView;
}
return undefined;
}

Blaze._lexicalBindingLookup = function (view, name) {
var currentView = view;
var blockHelpersStack = [];
Expand All @@ -99,10 +118,7 @@ Blaze._lexicalBindingLookup = function (view, name) {
return bindingReactiveVar.get();
};
}
} while (! (currentView.__startsNewLexicalScope &&
! (currentView.parentView &&
currentView.parentView.__childDoesntStartNewLexicalScope))
&& (currentView = currentView.parentView));
} while (currentView = _lexicalKeepGoing(currentView));

return null;
};
Expand Down

0 comments on commit 4a52314

Please sign in to comment.