add optional undeclared variable check transformer

This commit is contained in:
Sebastian McKenzie 2015-01-20 00:17:22 +11:00
parent da16bf1e42
commit f322252c36
6 changed files with 22 additions and 0 deletions

View File

@ -98,6 +98,7 @@ _.each({
typeofSymbol: require("./transformers/optional-typeof-symbol"),
coreAliasing: require("./transformers/optional-core-aliasing"),
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
undeclaredVariableCheck: require("./transformers/optional-undeclared-variable-check"),
// spec
specPropertyLiterals: require("./transformers/spec-property-literals"),

View File

@ -0,0 +1,9 @@
var t = require("../../types");
exports.optional = true;
exports.Identifier = function (node, parent, scope, context, file) {
if (!scope.has(node.name, true)) {
throw file.errorWithNode(node, "Reference to undeclared variable");
}
};

View File

@ -0,0 +1,5 @@
function foo() {
}
foo();

View File

@ -0,0 +1,3 @@
{
"optional": ["undeclaredVariableCheck"]
}

View File

@ -0,0 +1 @@
foo();

View File

@ -0,0 +1,3 @@
{
"throws": "Reference to undeclared variable"
}