From dcce4e5c6625e2ebb14d12801ce934890e47081f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Fri, 14 Aug 2015 22:05:42 +0100 Subject: [PATCH] Fix evaluating the typeof an arrow function. Using evaluate on used to cause a crash. --- lib/compress.js | 6 +++++- test/compress/harmony.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 6b480390..7b07667e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -738,6 +738,9 @@ merge(Compressor.prototype, { // places too. :-( Wish JS had multiple inheritance. throw def; }); + def(AST_Arrow, function() { + throw def; + }); function ev(node, compressor) { if (!compressor) throw new Error("Compressor must be passed"); @@ -756,7 +759,8 @@ merge(Compressor.prototype, { case "typeof": // Function would be evaluated to an array and so typeof would // incorrectly return 'object'. Hence making is a special case. - if (e instanceof AST_Function) return typeof function(){}; + if (e instanceof AST_Function || + e instanceof AST_Arrow) return typeof function(){}; e = ev(e, compressor); diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 02d2b299..812ad9d9 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -36,6 +36,16 @@ regression_arrow_functions_and_hoist: { expect_exact: "a=>b;" } +typeof_arrow_functions: { + options = { + evaluate: true + } + input: { + typeof (x) => null; + } + expect_exact: "\"function\";" +} + destructuring_arguments: { input: { (function ( a ) { });