better fix for mangle
This commit is contained in:
parent
9edb72fe01
commit
269df9267c
29
lib/scope.js
29
lib/scope.js
|
|
@ -111,7 +111,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||
var labels = new Dictionary();
|
||||
var defun = null;
|
||||
var in_destructuring = null;
|
||||
var in_export = false;
|
||||
var for_scopes = [];
|
||||
var tw = new TreeWalker(function(node, descend){
|
||||
if (node.is_block_scope()) {
|
||||
|
|
@ -151,12 +150,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||
labels = save_labels;
|
||||
return true; // don't descend again in TreeWalker
|
||||
}
|
||||
if (node instanceof AST_Export) {
|
||||
in_export = true;
|
||||
descend();
|
||||
in_export = false;
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_LabeledStatement) {
|
||||
var l = node.label;
|
||||
if (labels.has(l.name)) {
|
||||
|
|
@ -184,7 +177,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||
}
|
||||
if (node instanceof AST_SymbolLambda) {
|
||||
defun.def_function(node);
|
||||
in_export = false;
|
||||
}
|
||||
else if (node instanceof AST_SymbolDefun) {
|
||||
// Careful here, the scope where this should be defined is
|
||||
|
|
@ -196,29 +188,24 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||
while (parent_lambda.is_block_scope()) {
|
||||
parent_lambda = parent_lambda.parent_scope;
|
||||
}
|
||||
mark_export((node.scope = parent_lambda).def_function(node));
|
||||
mark_export((node.scope = parent_lambda).def_function(node), 1);
|
||||
}
|
||||
else if (node instanceof AST_SymbolClass) {
|
||||
mark_export(defun.def_variable(node));
|
||||
mark_export(defun.def_variable(node), 1);
|
||||
}
|
||||
else if (node instanceof AST_SymbolImport) {
|
||||
scope.def_variable(node);
|
||||
in_export = false;
|
||||
}
|
||||
else if (node instanceof AST_SymbolDefClass) {
|
||||
// This deals with the name of the class being available
|
||||
// inside the class.
|
||||
mark_export((node.scope = defun.parent_scope).def_function(node));
|
||||
mark_export((node.scope = defun.parent_scope).def_function(node), 1);
|
||||
}
|
||||
else if (node instanceof AST_SymbolVar
|
||||
|| node instanceof AST_SymbolLet
|
||||
|| node instanceof AST_SymbolConst) {
|
||||
var def = ((node instanceof AST_SymbolBlockDeclaration) ? scope : defun).def_variable(node);
|
||||
if (node instanceof AST_SymbolFunarg) {
|
||||
in_export = false;
|
||||
} else {
|
||||
mark_export(def);
|
||||
}
|
||||
if (!(node instanceof AST_SymbolFunarg)) mark_export(def, 2);
|
||||
def.destructuring = in_destructuring;
|
||||
if (defun !== scope) {
|
||||
node.mark_enclosed(options);
|
||||
|
|
@ -231,7 +218,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||
}
|
||||
else if (node instanceof AST_SymbolCatch) {
|
||||
scope.def_variable(node).defun = defun;
|
||||
in_export = false;
|
||||
}
|
||||
else if (node instanceof AST_LabelRef) {
|
||||
var sym = labels.get(node.name);
|
||||
|
|
@ -243,11 +229,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
|||
node.thedef = sym;
|
||||
}
|
||||
|
||||
function mark_export(def) {
|
||||
if (in_export) {
|
||||
def.export = true;
|
||||
in_export = false;
|
||||
}
|
||||
function mark_export(def, level) {
|
||||
def.export = tw.parent(level) instanceof AST_Export;
|
||||
}
|
||||
});
|
||||
self.walk(tw);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,9 @@ export_default_func_3: {
|
|||
}
|
||||
|
||||
export_mangle_1: {
|
||||
mangle = {}
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
export function foo(one, two) {
|
||||
return one - two;
|
||||
|
|
@ -73,7 +75,9 @@ export_mangle_1: {
|
|||
}
|
||||
|
||||
export_mangle_2: {
|
||||
mangle = {}
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
export default function foo(one, two) {
|
||||
return one - two;
|
||||
|
|
@ -86,7 +90,9 @@ export_mangle_3: {
|
|||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
mangle = {}
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
export class C {
|
||||
go(one, two) {
|
||||
|
|
@ -102,7 +108,9 @@ export_mangle_4: {
|
|||
options = {
|
||||
collapse_vars: true,
|
||||
}
|
||||
mangle = {}
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
export default class C {
|
||||
go(one, two) {
|
||||
|
|
@ -115,7 +123,9 @@ export_mangle_4: {
|
|||
}
|
||||
|
||||
export_mangle_5: {
|
||||
mangle = {}
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
export default {
|
||||
prop: function(one, two) {
|
||||
|
|
@ -127,11 +137,14 @@ export_mangle_5: {
|
|||
}
|
||||
|
||||
export_mangle_6: {
|
||||
mangle = {}
|
||||
input: {
|
||||
export let foo = 1;
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
expect_exact: "export let foo=1;"
|
||||
input: {
|
||||
var baz = 2;
|
||||
export let foo = 1, bar = baz;
|
||||
}
|
||||
expect_exact: "var a=2;export let foo=1,bar=a;"
|
||||
}
|
||||
|
||||
export_toplevel_1: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user