[Pkg-javascript-commits] [uglifyjs] 154/190: collapse_vars: Do not consider RegExp literals to be constants
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:22 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 09d5707a8a368d6498f39a8b9fd07226a1159d76
Author: kzc <zaxxon2011 at gmail.com>
Date: Thu May 26 14:47:16 2016 -0400
collapse_vars: Do not consider RegExp literals to be constants
Fixes #1100
---
lib/compress.js | 2 +-
test/compress/collapse_vars.js | 56 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/lib/compress.js b/lib/compress.js
index e78ee32..461c3c4 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -338,7 +338,7 @@ merge(Compressor.prototype, {
if (ref.scope.uses_eval || ref.scope.uses_with) break;
// Constant single use vars can be replaced in any scope.
- if (var_decl.value.is_constant(compressor)) {
+ if (!(var_decl.value instanceof AST_RegExp) && var_decl.value.is_constant(compressor)) {
var ctt = new TreeTransformer(function(node) {
if (node === ref)
return replace_var(node, ctt.parent(), true);
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 934a5c7..ef7af9e 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -1153,3 +1153,59 @@ collapse_vars_short_circuited_conditions: {
}
}
+collapse_vars_regexp: {
+ options = {
+ collapse_vars: true,
+ loops: false,
+ sequences: true,
+ dead_code: true,
+ conditionals: true,
+ comparisons: true,
+ evaluate: true,
+ booleans: true,
+ unused: true,
+ hoist_funs: true,
+ keep_fargs: true,
+ if_return: true,
+ join_vars: true,
+ cascade: true,
+ side_effects: true,
+ }
+ input: {
+ function f1() {
+ var k = 9;
+ var rx = /[A-Z]+/;
+ return [rx, k];
+ }
+ function f2() {
+ var rx = /[abc123]+/;
+ return function(s) {
+ return rx.exec(s);
+ };
+ }
+ (function(){
+ var result;
+ var s = 'acdabcdeabbb';
+ var rx = /ab*/g;
+ while (result = rx.exec(s)) {
+ console.log(result[0]);
+ }
+ })();
+ }
+ expect: {
+ function f1() {
+ return [/[A-Z]+/, 9];
+ }
+ function f2() {
+ var rx = /[abc123]+/;
+ return function(s) {
+ return rx.exec(s);
+ };
+ }
+ (function(){
+ var result, rx = /ab*/g;
+ while (result = rx.exec('acdabcdeabbb'))
+ console.log(result[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