Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Template.contentBlock consistent #358

Merged
merged 3 commits into from
Apr 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/blaze/lookup.js
Original file line number Diff line number Diff line change
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally break the lines for better readability but that's optional, since we have no definite linter yet (I think)

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