Add scope test for arguments
authorAnthony Van de Gejuchte <anthonyvdgent@gmail.com>
Thu, 14 Jan 2016 21:32:46 +0000 (22:32 +0100)
committerAnthony Van de Gejuchte <anthonyvdgent@gmail.com>
Thu, 14 Jan 2016 21:32:46 +0000 (22:32 +0100)
test/mocha/arguments.js [new file with mode: 0644]

diff --git a/test/mocha/arguments.js b/test/mocha/arguments.js
new file mode 100644 (file)
index 0000000..294a6c1
--- /dev/null
@@ -0,0 +1,19 @@
+var UglifyJS = require('../../');
+var assert = require("assert");
+
+describe("arguments", function() {
+    it("Should known that arguments in functions are local scoped", function() {
+        var ast = UglifyJS.parse("var arguments; var f = function() {arguments.length}");
+        ast.figure_out_scope();
+
+        // Select symbol in function
+        var symbol = ast.body[1].definitions[0].value.find_variable("arguments");
+
+        assert.strictEqual(symbol.global, false);
+        assert.strictEqual(symbol.scope, ast. // From ast
+            body[1]. // Select 2nd statement (equals to `var f ...`)
+            definitions[0]. // First definition of selected statement
+            value // Select function as scope
+        );
+    });
+});
\ No newline at end of file