fix: find variable in parent scope (strict_variables)

This commit is contained in:
harttle
2016-11-08 21:01:25 +08:00
parent fd9fed154c
commit 295eee8134
5 changed files with 50 additions and 21 deletions
+12 -3
View File
@@ -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);
}
},
+4
View File
@@ -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;