aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-06 14:49:39 +0000
committerGitHub <noreply@github.com>2021-03-06 22:49:39 +0800
commitad903e924050067a96a33f2eb5a0b9ab3e5454c1 (patch)
tree4729dfc4dd369cf9bb8d8f8eed8c9b1e276cb5f1 /lib
parent83c3838b07ed9ff32a83a39d5c1cbf40155c46f2 (diff)
downloadtracifyjs-ad903e924050067a96a33f2eb5a0b9ab3e5454c1.tar.gz
tracifyjs-ad903e924050067a96a33f2eb5a0b9ab3e5454c1.zip
fix corner cases with `export` (#4743)
fixes #4742
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js5
-rw-r--r--lib/scope.js11
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 20558ba8..be586a88 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3425,6 +3425,7 @@ merge(Compressor.prototype, {
if (parent instanceof AST_For && parent.init === node) return null;
return in_list ? List.skip : make_node(AST_EmptyStatement, node);
}
+ if (node instanceof AST_ExportDeclaration) return node;
if (node instanceof AST_Scope) return node;
if (!is_statement(node)) return node;
}));
@@ -6167,7 +6168,9 @@ merge(Compressor.prototype, {
}
var old_def;
if (!value && !(node instanceof AST_Let)) {
- if (drop_sym && var_defs[sym.id] > 1) {
+ if (parent instanceof AST_ExportDeclaration) {
+ flush();
+ } else if (drop_sym && var_defs[sym.id] > 1) {
AST_Node.info("Dropping declaration of variable {name} [{file}:{line},{col}]", template(def.name));
var_defs[sym.id]--;
sym.eliminated++;
diff --git a/lib/scope.js b/lib/scope.js
index b22f77a2..870ebf38 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -198,9 +198,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
} else if (node instanceof AST_SymbolConst) {
var def = scope.def_variable(node);
def.defun = defun;
- def.exported = exported;
+ if (exported) def.exported = true;
} else if (node instanceof AST_SymbolDefun) {
- defun.def_function(node, tw.parent()).exported = exported;
+ var def = defun.def_function(node, tw.parent());
+ if (exported) def.exported = true;
entangle(defun, scope);
} else if (node instanceof AST_SymbolFunarg) {
defun.def_variable(node);
@@ -209,9 +210,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
var def = defun.def_function(node, node.name == "arguments" ? undefined : defun);
if (options.ie8) def.defun = defun.parent_scope.resolve();
} else if (node instanceof AST_SymbolLet) {
- scope.def_variable(node).exported = exported;
+ var def = scope.def_variable(node);
+ if (exported) def.exported = true;
} else if (node instanceof AST_SymbolVar) {
- defun.def_variable(node, node instanceof AST_SymbolImport ? undefined : null).exported = exported;
+ var def = defun.def_variable(node, node instanceof AST_SymbolImport ? undefined : null);
+ if (exported) def.exported = true;
entangle(defun, scope);
}