return node instanceof AST_AsyncFunction || node instanceof AST_Function;
}
-var AST_AsyncFunction = DEFNODE("AsyncFunction", null, {
+var AST_AsyncFunction = DEFNODE("AsyncFunction", "inlined", {
$documentation: "An asynchronous function expression",
_validate: function() {
if (this.name != null) {
return node instanceof AST_AsyncDefun || node instanceof AST_Defun;
}
-var AST_AsyncDefun = DEFNODE("AsyncDefun", null, {
+var AST_AsyncDefun = DEFNODE("AsyncDefun", "inlined", {
$documentation: "An asynchronous function definition",
_validate: function() {
if (!(this.name instanceof AST_SymbolDefun)) throw new Error("name must be AST_SymbolDefun");
return true;
});
def(AST_Lambda, function(tw, descend, compressor) {
+ this.inlined = false;
push(tw);
reset_variables(tw, compressor, this);
descend();
var assign_used = false;
var can_replace = !args || !hit;
if (!can_replace) {
- for (var j = compressor.self().argnames.lastIndexOf(candidate.name) + 1; !abort && j < args.length; j++) {
+ for (var j = scope.argnames.lastIndexOf(candidate.name) + 1; !abort && j < args.length; j++) {
args[j].transform(scanner);
}
can_replace = true;
function extract_args() {
var iife, fn = compressor.self();
- if (fn instanceof AST_Function
+ if (is_function(fn)
&& !fn.name
&& !fn.uses_arguments
&& !fn.pinned()
})) {
var fn_strict = compressor.has_directive("use strict");
if (fn_strict && !member(fn_strict, fn.body)) fn_strict = false;
+ var has_await = fn instanceof AST_AsyncFunction ? function(node) {
+ return node instanceof AST_Symbol && node.name == "await";
+ } : function(node) {
+ return node instanceof AST_Await && !tw.find_parent(AST_Scope);
+ };
+ var tw = new TreeWalker(function(node) {
+ if (!arg) return true;
+ if (has_await(node)) {
+ arg = null;
+ return true;
+ }
+ if (node instanceof AST_SymbolRef && fn.variables.has(node.name)) {
+ var s = node.definition().scope;
+ if (s !== scope) while (s = s.parent_scope) {
+ if (s === scope) return true;
+ }
+ arg = null;
+ }
+ if (node instanceof AST_This && (fn_strict || !tw.find_parent(AST_Scope))) {
+ arg = null;
+ return true;
+ }
+ });
var len = fn.argnames.length;
args = iife.args.slice(len);
var names = Object.create(null);
} else if (arg instanceof AST_Lambda && arg.pinned()) {
arg = null;
} else {
- arg.walk(new TreeWalker(function(node) {
- if (!arg) return true;
- if (node instanceof AST_SymbolRef && fn.variables.has(node.name)) {
- var s = node.definition().scope;
- if (s !== scope) while (s = s.parent_scope) {
- if (s === scope) return true;
- }
- arg = null;
- }
- if (node instanceof AST_This && (fn_strict || !this.find_parent(AST_Scope))) {
- arg = null;
- return true;
- }
- }));
+ arg.walk(tw);
}
if (arg) candidates.unshift([ make_node(AST_VarDef, sym, {
name: sym,
single_use = fixed.is_constant_expression(self.scope);
if (single_use == "f") {
var scope = self.scope;
- do if (scope instanceof AST_Defun || scope instanceof AST_Function) {
+ do if (is_defun(scope) || is_function(scope)) {
scope.inlined = true;
} while (scope = scope.parent_scope);
}
expect_stdout: "PASS"
node_version: ">=8"
}
+
+issue_4349_1: {
+ input: {
+ console.log(typeof async function() {
+ await /abc/;
+ }().then);
+ }
+ expect_exact: "console.log(typeof async function(){await/abc/}().then);"
+ expect_stdout: "function"
+ node_version: ">=8"
+}
+
+issue_4349_2: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ console.log(typeof async function() {
+ (function(a) {
+ this[a];
+ }(await 0));
+ }().then);
+ }
+ expect: {
+ console.log(typeof async function() {
+ (function(a) {
+ this[a];
+ }(await 0));
+ }().then);
+ }
+ expect_stdout: "function"
+ node_version: ">=8"
+}
+
+issue_4349_3: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ console.log(typeof function(await) {
+ return async function(a) {
+ this[a];
+ }(await);
+ }(this).then);
+ }
+ expect: {
+ console.log(typeof function(await) {
+ return async function(a) {
+ this[a];
+ }(await);
+ }(this).then);
+ }
+ expect_stdout: "function"
+ node_version: ">=8"
+}