mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
fix: find variable in parent scope (strict_variables)
This commit is contained in:
+12
-3
@@ -1,7 +1,6 @@
|
||||
const _ = require('./util/underscore.js');
|
||||
const lexical = require('./lexical.js');
|
||||
const assert = require('./util/assert.js');
|
||||
const referenceError = /undefined variable|Cannot read property .* of undefined/;
|
||||
|
||||
var Scope = {
|
||||
getAll: function() {
|
||||
@@ -16,13 +15,23 @@ var Scope = {
|
||||
try {
|
||||
return this.getPropertyByPath(this.scopes[i], str);
|
||||
} catch (e) {
|
||||
if (!referenceError.test(e.message) || this.opts.strict_variables) {
|
||||
if (/undefined variable/.test(e.message)) {
|
||||
continue;
|
||||
}
|
||||
if (/Cannot read property/.test(e.message)) {
|
||||
if (this.opts.strict_variables) {
|
||||
e.message += ': ' + str;
|
||||
throw e;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
e.message += ': ' + str;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.opts.strict_variables){
|
||||
if (this.opts.strict_variables) {
|
||||
throw new TypeError('undefined variable: ' + str);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -14,7 +14,11 @@ TokenizationError.prototype.constructor = TokenizationError;
|
||||
function ParseError(message, input, line, e) {
|
||||
if(Error.captureStackTrace){
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
} else{
|
||||
this.stack = "";
|
||||
}
|
||||
this.stack += (this.stack ? "\nFrom " : "From ") + e.stack;
|
||||
|
||||
this.name = this.constructor.name;
|
||||
this.originalError = e;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user