-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES6] Implemented parse for export Name from Module variants. (#1701)
- add `AST_Export` new variants output - add tests to `test/compress/` - update `$propdoc` of `AST_Export` ("exported_names" & "module_name") - add tests for `export ... as ...` variants
- Loading branch information
1 parent
fccefbe
commit 5dea522
Showing
6 changed files
with
182 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var assert = require("assert"); | ||
var uglify = require("../../"); | ||
|
||
describe("Export", function() { | ||
it ("Should parse export directives", function() { | ||
|
||
var inputs = [ | ||
['export * from "a.js"', ['*'], "a.js"], | ||
['export {A} from "a.js"', ['A'], "a.js"], | ||
['export {A as X} from "a.js"', ['X'], "a.js"], | ||
['export {A as Foo, B} from "a.js"', ['Foo', 'B'], "a.js"], | ||
['export {A, B} from "a.js"', ['A', 'B'], "a.js"], | ||
]; | ||
|
||
var test = function(code) { | ||
return uglify.parse(code, {fromString: true}); | ||
}; | ||
|
||
var extractNames = function(symbols) { | ||
var ret = []; | ||
for (var i = 0; i < symbols.length; i++) { | ||
ret.push(symbols[i].name.name) | ||
} | ||
return ret; | ||
}; | ||
|
||
for (var i = 0; i < inputs.length; i++) { | ||
var ast = test(inputs[i][0]); | ||
var names = inputs[i][1]; | ||
var filename = inputs[i][2]; | ||
assert(ast instanceof uglify.AST_Toplevel); | ||
assert.equal(ast.body.length, 1); | ||
var st = ast.body[0]; | ||
assert(st instanceof uglify.AST_Export); | ||
var actualNames = extractNames(st.exported_names); | ||
assert.deepEqual(actualNames, names); | ||
assert.equal(st.module_name.value, filename) | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |