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

Access properties of the window object using "^" #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
6 changes: 3 additions & 3 deletions lib/jinja.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var jinja;
//non-primitive literals (array and object literals)
var NON_PRIMITIVES = /\[[@#~](,[@#~])*\]|\[\]|\{([@i]:[@#~])(,[@i]:[@#~])*\}|\{\}/g;
//bare identifiers such as variables and in object literals: {foo: 'value'}
var IDENTIFIERS = /[$_a-z][$\w]*/ig;
var IDENTIFIERS = /\^?[$_a-z][$\w]*/ig;
var VARIABLES = /i(\.i|\[[@#i]\])*/g;
var ACCESSOR = /(\.i|\[[@#i]\])/g;
var OPERATORS = /(===?|!==?|>=?|<=?|&&|\|\||[+\-\*\/%])/g;
Expand Down Expand Up @@ -434,7 +434,7 @@ var jinja;
var get = function() {
var val, n = arguments[0], c = stack.length;
while (c--) {
val = stack[c][n];
val = (n[0] == '^' ? window[n.slice(1)] : stack[c][n]);
Copy link
Owner

@sstur sstur Jan 7, 2020

Choose a reason for hiding this comment

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

I don't think it's safe to assume that window exists. An example where window does not exist is when running in Node. I think we will need a better way to do window[n.slice(1)] part, perhaps a helper function getGlobal(n.slice(1)).

if (typeof val != 'undefined') break;
}
for (var i = 1, len = arguments.length; i < len; i++) {
Expand Down Expand Up @@ -574,4 +574,4 @@ var jinja;
}
}

});
});