From ec26cd7069d82ba6acc45c26acb40be4bc11485e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0pan=C4=9Bl?= Date: Thu, 30 Mar 2017 09:20:22 +0200 Subject: [PATCH] Fix AST_Export $propdoc types (exported_names and module_name). --- lib/ast.js | 4 ++-- test/mocha/issue1702.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/mocha/issue1702.js diff --git a/lib/ast.js b/lib/ast.js index 57a202b9..54e3f2e6 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -794,8 +794,8 @@ var AST_Export = DEFNODE("Export", "exported_definition exported_value is_defaul $propdoc: { exported_definition: "[AST_Defun|AST_Definitions|AST_DefClass?] An exported definition", exported_value: "[AST_Node?] An exported value", - exported_names: "[string*] List of exported names", - module_name: "[string?] Name of the file to load exports from", + exported_names: "[AST_NameImport*?] List of exported names", + module_name: "[AST_String?] Name of the file to load exports from", is_default: "[Boolean] Whether this is the default exported value of this module" }, _walk: function (visitor) { diff --git a/test/mocha/issue1702.js b/test/mocha/issue1702.js new file mode 100644 index 00000000..4eb1b989 --- /dev/null +++ b/test/mocha/issue1702.js @@ -0,0 +1,35 @@ +var uglify = require('../../'); +var assert = require("assert"); + +describe("For statement", function() { + it("For variable should list enclosing scope in its references (issue #17022)", function() { + var ast = uglify.parse("function f() { for (var a = 0; a < 10; a++) {} }"); + ast.figure_out_scope(); + + var checkWalker = new uglify.TreeWalker(function(node, descend) { + if (node instanceof uglify.AST_VarDef) { + console.log("AST_VarDef"); + // one reference should be in the AST_Defun scope - search for it + + var walkNode = function (r) { + console.log(r.CTOR.name); + var walker = new uglify.TreeWalker(function(node, descend){ + // do not walk into any other scope, it should be listed if needed + console.log(" " + node.CTOR.name); + if (node instanceof uglify.AST_Scope && node != r.scope) return true; + if (node instanceof uglify.AST_For) { + console.log("Great - we found the for statement referencing the variable") + } + return false; + }); + r.scope.walk(walker); + r.walk(walker); + }; + + node.name.thedef.orig.forEach(walkNode); + node.name.thedef.references.forEach(walkNode); + } + }); + ast.walk(checkWalker); + }); +}); \ No newline at end of file