[Pkg-javascript-commits] [uglifyjs] 51/190: optimize `return undefined` and `return void 0`
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:12 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.
commit 7491d07666822fe943bd5f5768a5761b562c634a
Author: kzc <zaxxon2011 at gmail.com>
Date: Wed Oct 28 13:25:27 2015 -0400
optimize `return undefined` and `return void 0`
---
lib/compress.js | 10 ++
test/compress/return_undefined.js | 229 ++++++++++++++++++++++++++++++++++++++
2 files changed, 239 insertions(+)
diff --git a/lib/compress.js b/lib/compress.js
index 216aade..ebe7e95 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -65,6 +65,7 @@ function Compressor(options, false_by_default) {
keep_fnames : false,
hoist_vars : false,
if_return : !false_by_default,
+ return_void_0 : !false_by_default,
join_vars : !false_by_default,
cascade : !false_by_default,
side_effects : !false_by_default,
@@ -2519,4 +2520,13 @@ merge(Compressor.prototype, {
OPT(AST_Object, literals_in_boolean_context);
OPT(AST_RegExp, literals_in_boolean_context);
+ OPT(AST_Return, function(self, compressor){
+ if (compressor.option("return_void_0")) {
+ if (self.value instanceof AST_Undefined) {
+ self.value = null;
+ }
+ }
+ return self;
+ });
+
})();
diff --git a/test/compress/return_undefined.js b/test/compress/return_undefined.js
new file mode 100644
index 0000000..be79d89
--- /dev/null
+++ b/test/compress/return_undefined.js
@@ -0,0 +1,229 @@
+return_void_0_true: {
+ options = {
+ return_void_0 : true,
+ sequences : false,
+ if_return : true,
+ evaluate : true,
+ dead_code : true,
+ conditionals : true,
+ comparisons : true,
+ booleans : true,
+ unused : true,
+ side_effects : true,
+ properties : true,
+ drop_debugger : true,
+ loops : true,
+ hoist_funs : true,
+ keep_fargs : true,
+ keep_fnames : false,
+ hoist_vars : true,
+ join_vars : true,
+ cascade : true,
+ negate_iife : true
+ };
+ input: {
+ function f0() {
+ }
+ function f1() {
+ return undefined;
+ }
+ function f2() {
+ return void 0;
+ }
+ function f3() {
+ return void 123;
+ }
+ function f4() {
+ return;
+ }
+ function f5(a, b) {
+ console.log(a, b);
+ baz(a);
+ return;
+ }
+ function f6(a, b) {
+ console.log(a, b);
+ if (a) {
+ foo(b);
+ baz(a);
+ return a + b;
+ }
+ return undefined;
+ }
+ function f7(a, b) {
+ console.log(a, b);
+ if (a) {
+ foo(b);
+ baz(a);
+ return void 0;
+ }
+ return a + b;
+ }
+ function f8(a, b) {
+ foo(a);
+ bar(b);
+ return void 0;
+ }
+ function f9(a, b) {
+ foo(a);
+ bar(b);
+ return undefined;
+ }
+ }
+ expect: {
+ function f0() {}
+ function f1() {}
+ function f2() {}
+ function f3() {}
+ function f4() {}
+ function f5(a, b) {
+ console.log(a, b);
+ baz(a);
+ }
+ function f6(a, b) {
+ console.log(a, b);
+ if (a) {
+ foo(b);
+ baz(a);
+ return a + b;
+ }
+ }
+ function f7(a, b) {
+ console.log(a, b);
+ if (!a)
+ return a + b;
+ foo(b);
+ baz(a);
+ }
+ function f8(a, b) {
+ foo(a);
+ bar(b);
+ }
+ function f9(a, b) {
+ foo(a);
+ bar(b);
+ }
+ }
+}
+
+return_void_0_false: {
+ options = {
+ return_void_0 : false,
+ sequences : false,
+ if_return : true,
+ evaluate : true,
+ dead_code : true,
+ conditionals : true,
+ comparisons : true,
+ booleans : true,
+ unused : true,
+ side_effects : true,
+ properties : true,
+ drop_debugger : true,
+ loops : true,
+ hoist_funs : true,
+ keep_fargs : true,
+ keep_fnames : false,
+ hoist_vars : true,
+ join_vars : true,
+ cascade : true,
+ negate_iife : true
+ };
+ input: {
+ function f0() {
+ }
+ function f1() {
+ return undefined;
+ }
+ function f2() {
+ return void 0;
+ }
+ function f3() {
+ return void 123;
+ }
+ function f4() {
+ return;
+ }
+ function f5(a, b) {
+ console.log(a, b);
+ baz(a);
+ return;
+ }
+ function f6(a, b) {
+ console.log(a, b);
+ if (a) {
+ foo(b);
+ baz(a);
+ return a + b;
+ }
+ return undefined;
+ }
+ function f7(a, b) {
+ console.log(a, b);
+ if (a) {
+ foo(b);
+ baz(a);
+ return void 0;
+ }
+ return a + b;
+ }
+ function f8(a, b) {
+ foo(a);
+ bar(b);
+ return void 0;
+ }
+ function f9(a, b) {
+ foo(a);
+ bar(b);
+ return undefined;
+ }
+ }
+ expect: {
+ function f0() {
+ }
+ function f1() {
+ return void 0;
+ }
+ function f2() {
+ return void 0;
+ }
+ function f3() {
+ return void 0;
+ }
+ function f4() {
+ }
+ function f5(a, b) {
+ console.log(a, b);
+ baz(a);
+ }
+ function f6(a, b) {
+ console.log(a, b);
+ if (a) {
+ foo(b);
+ baz(a);
+ return a + b;
+ }
+ return void 0;
+ }
+ function f7(a, b) {
+ console.log(a, b);
+ if (a) {
+ foo(b);
+ baz(a);
+ return void 0;
+ }
+ return a + b;
+ }
+ function f8(a, b) {
+ foo(a);
+ bar(b);
+ return void 0;
+ }
+ function f9(a, b) {
+ foo(a);
+ bar(b);
+ return void 0;
+ }
+ }
+}
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list