terser 3.13.0 → 3.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of terser might be problematic. Click here for more details.

package/lib/compress.js CHANGED
@@ -2064,11 +2064,18 @@ merge(Compressor.prototype, {
2064
2064
  };
2065
2065
  if (!all(def.value.properties, diff)) break;
2066
2066
  var p = def.value.properties.filter(function (p) { return p.key === prop; })[0];
2067
- p.value = new AST_Sequence({
2068
- start: p.start,
2069
- expressions: [p.value, node.right],
2070
- end: p.end
2071
- });
2067
+ if (!p) {
2068
+ def.value.properties.push(make_node(AST_ObjectKeyVal, node, {
2069
+ key: prop,
2070
+ value: node.right
2071
+ }));
2072
+ } else {
2073
+ p.value = new AST_Sequence({
2074
+ start: p.start,
2075
+ expressions: [p.value.clone(), node.right.clone()],
2076
+ end: p.end
2077
+ });
2078
+ }
2072
2079
  exprs.shift();
2073
2080
  trimmed = true;
2074
2081
  } while (exprs.length);
@@ -2757,6 +2764,16 @@ merge(Compressor.prototype, {
2757
2764
  var exp = this.expression;
2758
2765
  var val;
2759
2766
  if (is_undeclared_ref(exp)) {
2767
+
2768
+ var aa;
2769
+ var first_arg = exp.name === "hasOwnProperty"
2770
+ && key === "call"
2771
+ && (aa = compressor.parent() && compressor.parent().args)
2772
+ && (aa && aa[0]
2773
+ && aa[0].evaluate(compressor));
2774
+ if (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared) {
2775
+ return this.clone();
2776
+ }
2760
2777
  if (!(static_values[exp.name] || return_false)(key)) return this;
2761
2778
  val = global_objs[exp.name];
2762
2779
  } else {
@@ -2786,6 +2803,13 @@ merge(Compressor.prototype, {
2786
2803
  var val;
2787
2804
  var e = exp.expression;
2788
2805
  if (is_undeclared_ref(e)) {
2806
+ var first_arg =
2807
+ e.name === "hasOwnProperty" &&
2808
+ key === "call" &&
2809
+ (this.args[0] && this.args[0].evaluate(compressor));
2810
+ if ((first_arg == null || first_arg.thedef && first_arg.thedef.undeclared)) {
2811
+ return this.clone();
2812
+ }
2789
2813
  if (!(static_fns[e.name] || return_false)(key)) return this;
2790
2814
  val = global_objs[e.name];
2791
2815
  } else {
@@ -2901,6 +2925,13 @@ merge(Compressor.prototype, {
2901
2925
  AST_Call.DEFMETHOD("is_expr_pure", function(compressor) {
2902
2926
  if (compressor.option("unsafe")) {
2903
2927
  var expr = this.expression;
2928
+ var first_arg = (this.args && this.args[0] && this.args[0].evaluate(compressor));
2929
+ if (
2930
+ expr.expression && expr.expression.name === "hasOwnProperty" &&
2931
+ (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared)
2932
+ ) {
2933
+ return false;
2934
+ }
2904
2935
  if (is_undeclared_ref(expr) && global_pure_fns(expr.name)) return true;
2905
2936
  if (expr instanceof AST_Dot
2906
2937
  && is_undeclared_ref(expr.expression)
@@ -6648,6 +6679,7 @@ merge(Compressor.prototype, {
6648
6679
  if (!(self.key instanceof AST_Constant)) return self;
6649
6680
  // whitelist acceptable props as not all AST_Constants are true constants
6650
6681
  if (self.key instanceof AST_String || self.key instanceof AST_Number) {
6682
+ if (self.key.value === "__proto__") return self;
6651
6683
  if (self.key.value == "constructor"
6652
6684
  && compressor.parent() instanceof AST_Class) return self;
6653
6685
  if (self instanceof AST_ObjectKeyVal) {
package/lib/output.js CHANGED
@@ -1228,13 +1228,6 @@ function OutputStream(options) {
1228
1228
  /* -----[ if ]----- */
1229
1229
  function make_then(self, output) {
1230
1230
  var b = self.body;
1231
- if (b.print_to_string() === "") {
1232
- output.newline();
1233
- var indent = new Array(output.next_indent()).join(" ");
1234
- output.print(indent + ";");
1235
- output.newline();
1236
- return;
1237
- }
1238
1231
  if (output.option("braces")
1239
1232
  || output.option("ie8") && b instanceof AST_Do)
1240
1233
  return make_block(b, output);
@@ -1268,7 +1261,7 @@ function OutputStream(options) {
1268
1261
  output.space();
1269
1262
  if (self.alternative) {
1270
1263
  make_then(self, output);
1271
- if (self.body.print_to_string() !== "") output.space();
1264
+ output.space();
1272
1265
  output.print("else");
1273
1266
  output.space();
1274
1267
  if (self.alternative instanceof AST_If)
package/lib/propmangle.js CHANGED
@@ -43,8 +43,6 @@
43
43
 
44
44
  "use strict";
45
45
 
46
- var domprops = require("../tools/domprops.json");
47
-
48
46
  function find_builtins(reserved) {
49
47
  reserved.push.apply(reserved, domprops);
50
48
 
@@ -168,7 +166,11 @@ function mangle_properties(ast, options) {
168
166
  // setter or getter, since KeyVal is handled above
169
167
  add(node.key.name);
170
168
  } else if (node instanceof AST_Dot) {
171
- add(node.property);
169
+ var root = node;
170
+ while (root.expression) {
171
+ root = root.expression;
172
+ }
173
+ if (!(root.thedef && root.thedef.undeclared)) add(node.property);
172
174
  } else if (node instanceof AST_Sub) {
173
175
  addStrings(node.property, add);
174
176
  } else if (node instanceof AST_Call
package/lib/utils.js CHANGED
@@ -315,6 +315,7 @@ Dictionary.fromObject = function(obj) {
315
315
  dict._size = merge(dict._values, obj);
316
316
  return dict;
317
317
  };
318
+ exports.Dictionary = Dictionary;
318
319
 
319
320
  function HOP(obj, prop) {
320
321
  return Object.prototype.hasOwnProperty.call(obj, prop);
package/package.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "homepage": "https://github.com/fabiosantoscode/terser",
5
5
  "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
6
6
  "license": "BSD-2-Clause",
7
- "version": "3.13.0",
7
+ "version": "3.14.1",
8
8
  "engines": {
9
- "node": ">=0.8.0"
9
+ "node": ">=4.0.0"
10
10
  },
11
11
  "maintainers": [
12
12
  "Fábio Santos <fabiosantosart@gmail.com>",
@@ -52,7 +52,7 @@
52
52
  "coveralls": "coveralls < coverage/lcov.info",
53
53
  "lint": "eslint lib",
54
54
  "lint-fix": "eslint --fix lib",
55
- "prepare": "cd dist && TERSER_NO_BUNDLE=1 ../bin/uglifyjs ../lib/utils.js ../lib/ast.js ../lib/parse.js ../lib/transform.js ../lib/scope.js ../lib/output.js ../lib/compress.js ../lib/sourcemap.js ../lib/mozilla-ast.js ../lib/propmangle.js ../lib/minify.js ../tools/exports.js -mc -d \"MOZ_SourceMap=require('source-map')\" --source-map \"includeSources=true,url='bundle.js.map'\" -e \"exports:(typeof module != 'undefined' ? module.exports : Terser = {})\" -b beautify=false,ascii_only --comments /license/ -o ../dist/bundle.js"
55
+ "prepare": "cd dist && TERSER_NO_BUNDLE=1 ../bin/uglifyjs ../tools/domprops.js ../lib/utils.js ../lib/ast.js ../lib/parse.js ../lib/transform.js ../lib/scope.js ../lib/output.js ../lib/compress.js ../lib/sourcemap.js ../lib/mozilla-ast.js ../lib/propmangle.js ../lib/minify.js ../tools/exports.js -mc -d \"MOZ_SourceMap=require('source-map')\" --source-map \"includeSources=true,url='bundle.js.map'\" -e \"exports:(typeof module != 'undefined' ? module.exports : Terser = {})\" -b beautify=false,ascii_only --comments /license/ -o ../dist/bundle.js"
56
56
  },
57
57
  "keywords": [
58
58
  "uglify",
@@ -1,4 +1,4 @@
1
- [
1
+ var domprops = [
2
2
  "$&",
3
3
  "$'",
4
4
  "$*",
package/tools/node.js CHANGED
@@ -2,6 +2,7 @@ var fs = require("fs");
2
2
 
3
3
  var UglifyJS = exports;
4
4
  var FILES = UglifyJS.FILES = [
5
+ "./domprops.js",
5
6
  "../lib/utils.js",
6
7
  "../lib/ast.js",
7
8
  "../lib/parse.js",
package/tools/props.html CHANGED
@@ -45,7 +45,7 @@
45
45
  <!-- ta.value = Object.keys(props).sort(cmp).map(function(name){ -->
46
46
  <!-- return JSON.stringify(name); -->
47
47
  <!-- }).join(",\n"); -->
48
- ta.value = JSON.stringify({
48
+ ta.value = 'var domprops = ' + JSON.stringify({
49
49
  vars: [],
50
50
  props: Object.keys(props).sort(cmp)
51
51
  }, null, 2);