add optional undeclared variable check transformer
This commit is contained in:
parent
da16bf1e42
commit
f322252c36
@ -98,6 +98,7 @@ _.each({
|
|||||||
typeofSymbol: require("./transformers/optional-typeof-symbol"),
|
typeofSymbol: require("./transformers/optional-typeof-symbol"),
|
||||||
coreAliasing: require("./transformers/optional-core-aliasing"),
|
coreAliasing: require("./transformers/optional-core-aliasing"),
|
||||||
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
||||||
|
undeclaredVariableCheck: require("./transformers/optional-undeclared-variable-check"),
|
||||||
|
|
||||||
// spec
|
// spec
|
||||||
specPropertyLiterals: require("./transformers/spec-property-literals"),
|
specPropertyLiterals: require("./transformers/spec-property-literals"),
|
||||||
|
|||||||
@ -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");
|
||||||
|
}
|
||||||
|
};
|
||||||
5
test/fixtures/transformation/optional-undeclared-variable-check/declared/exec.js
vendored
Normal file
5
test/fixtures/transformation/optional-undeclared-variable-check/declared/exec.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foo();
|
||||||
3
test/fixtures/transformation/optional-undeclared-variable-check/options.json
vendored
Normal file
3
test/fixtures/transformation/optional-undeclared-variable-check/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"optional": ["undeclaredVariableCheck"]
|
||||||
|
}
|
||||||
1
test/fixtures/transformation/optional-undeclared-variable-check/undeclared/exec.js
vendored
Normal file
1
test/fixtures/transformation/optional-undeclared-variable-check/undeclared/exec.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
foo();
|
||||||
3
test/fixtures/transformation/optional-undeclared-variable-check/undeclared/options.json
vendored
Normal file
3
test/fixtures/transformation/optional-undeclared-variable-check/undeclared/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Reference to undeclared variable"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user