terser 3.9.2 → 3.10.2

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/ast.js CHANGED
@@ -627,7 +627,7 @@ var AST_Catch = DEFNODE("Catch", "argname", {
627
627
  },
628
628
  _walk: function(visitor) {
629
629
  return visitor._visit(this, function() {
630
- this.argname._walk(visitor);
630
+ if (this.argname) this.argname._walk(visitor);
631
631
  walk_body(this, visitor);
632
632
  });
633
633
  }
package/lib/compress.js CHANGED
@@ -52,6 +52,7 @@ function Compressor(options, false_by_default) {
52
52
  arguments : false,
53
53
  arrows : !false_by_default,
54
54
  booleans : !false_by_default,
55
+ booleans_as_integers : false,
55
56
  collapse_vars : !false_by_default,
56
57
  comparisons : !false_by_default,
57
58
  computed_props: !false_by_default,
@@ -892,7 +893,7 @@ merge(Compressor.prototype, {
892
893
  var scope, i = 0;
893
894
  while (scope = compressor.parent(i++)) {
894
895
  if (scope instanceof AST_Scope) break;
895
- if (scope instanceof AST_Catch) {
896
+ if (scope instanceof AST_Catch && scope.argname) {
896
897
  scope = scope.argname.definition().scope;
897
898
  break;
898
899
  }
@@ -4633,10 +4634,6 @@ merge(Compressor.prototype, {
4633
4634
  }
4634
4635
  }
4635
4636
  break;
4636
- case "Symbol":
4637
- // Symbol's argument is only used for debugging.
4638
- self.args = [];
4639
- return self;
4640
4637
  } else if (exp instanceof AST_Dot) switch(exp.property) {
4641
4638
  case "toString":
4642
4639
  if (self.args.length == 0 && !exp.expression.may_throw_on_access(compressor)) {
@@ -4836,7 +4833,12 @@ merge(Compressor.prototype, {
4836
4833
  if (can_inline && stat instanceof AST_Return && is_regular_func) {
4837
4834
  var value = stat.value;
4838
4835
  if (!value || value.is_constant_expression()) {
4839
- var args = self.args.concat(value || make_node(AST_Undefined, self));
4836
+ if (value) {
4837
+ value = value.clone(true);
4838
+ } else {
4839
+ value = make_node(AST_Undefined, self);
4840
+ }
4841
+ var args = self.args.concat(value);
4840
4842
  return make_sequence(self, args).optimize(compressor);
4841
4843
  }
4842
4844
  }
@@ -4987,7 +4989,9 @@ merge(Compressor.prototype, {
4987
4989
  }
4988
4990
  }
4989
4991
  if (scope instanceof AST_Catch) {
4990
- block_scoped[scope.argname.name] = true;
4992
+ if (scope.argname) {
4993
+ block_scoped[scope.argname.name] = true;
4994
+ }
4991
4995
  } else if (scope instanceof AST_IterationStatement) {
4992
4996
  in_loop = [];
4993
4997
  } else if (scope instanceof AST_SymbolRef) {
@@ -6212,8 +6216,16 @@ merge(Compressor.prototype, {
6212
6216
  if (compressor.in_boolean_context()) return make_node(AST_Number, self, {
6213
6217
  value: +self.value
6214
6218
  });
6219
+ var p = compressor.parent();
6220
+ if (compressor.option("booleans_as_integers")) {
6221
+ if (p instanceof AST_Binary && (p.operator == "===" || p.operator == "!==")) {
6222
+ p.operator = p.operator.replace(/=$/, "");
6223
+ }
6224
+ return make_node(AST_Number, self, {
6225
+ value: +self.value
6226
+ });
6227
+ }
6215
6228
  if (compressor.option("booleans")) {
6216
- var p = compressor.parent();
6217
6229
  if (p instanceof AST_Binary && (p.operator == "=="
6218
6230
  || p.operator == "!=")) {
6219
6231
  compressor.warn("Non-strict equality against boolean: {operator} {value} [{file}:{line},{col}]", {
package/lib/output.js CHANGED
@@ -1320,10 +1320,12 @@ function OutputStream(options) {
1320
1320
  });
1321
1321
  DEFPRINT(AST_Catch, function(self, output) {
1322
1322
  output.print("catch");
1323
- output.space();
1324
- output.with_parens(function() {
1325
- self.argname.print(output);
1326
- });
1323
+ if (self.argname) {
1324
+ output.space();
1325
+ output.with_parens(function() {
1326
+ self.argname.print(output);
1327
+ });
1328
+ }
1327
1329
  output.space();
1328
1330
  print_braced(self, output);
1329
1331
  });
package/lib/parse.js CHANGED
@@ -420,7 +420,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
420
420
  }
421
421
  }
422
422
 
423
- function read_escaped_char(in_string) {
423
+ function read_escaped_char(in_string, template_string) {
424
424
  var ch = next(true, in_string);
425
425
  switch (ch.charCodeAt(0)) {
426
426
  case 110 : return "\n";
@@ -445,7 +445,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
445
445
  next(true);
446
446
  return from_char_code(result);
447
447
  }
448
- return String.fromCharCode(hex_bytes(4));
448
+ return String.fromCharCode(hex_bytes(4, template_string));
449
449
  case 10 : return ""; // newline
450
450
  case 13 : // \r
451
451
  if (peek() == "\n") { // DOS newline
@@ -474,9 +474,12 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
474
474
  return String.fromCharCode(parseInt(ch, 8));
475
475
  }
476
476
 
477
- function hex_bytes(n) {
477
+ function hex_bytes(n, abrupt_ending) {
478
478
  var num = 0;
479
479
  for (; n > 0; --n) {
480
+ if (abrupt_ending && isNaN(parseInt(peek(), 16))) {
481
+ return num || "";
482
+ }
480
483
  var digit = parseInt(next(true), 16);
481
484
  if (isNaN(digit))
482
485
  parse_error("Invalid hex-character pattern in string");
@@ -522,7 +525,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
522
525
  raw += ch;
523
526
  if (ch == "\\") {
524
527
  var tmp = S.pos;
525
- ch = read_escaped_char(true);
528
+ ch = read_escaped_char(true, true);
526
529
  raw += S.text.substr(tmp, S.pos - tmp);
527
530
  }
528
531
 
@@ -1847,9 +1850,13 @@ function parse($TEXT, options) {
1847
1850
  if (is("keyword", "catch")) {
1848
1851
  var start = S.token;
1849
1852
  next();
1850
- expect("(");
1851
- var name = parameter(undefined, AST_SymbolCatch);
1852
- expect(")");
1853
+ if (is("punc", "{")) {
1854
+ var name = null;
1855
+ } else {
1856
+ expect("(");
1857
+ var name = parameter(undefined, AST_SymbolCatch);
1858
+ expect(")");
1859
+ }
1853
1860
  bcatch = new AST_Catch({
1854
1861
  start : start,
1855
1862
  argname : name,
package/lib/scope.js CHANGED
@@ -68,11 +68,11 @@ SymbolDef.prototype = {
68
68
  || this.export
69
69
  || this.undeclared
70
70
  || !options.eval && this.scope.pinned()
71
- || options.keep_fnames
71
+ || (options.keep_fnames instanceof RegExp && options.keep_fnames.test(this.orig[0].name) || options.keep_fnames === true)
72
72
  && (this.orig[0] instanceof AST_SymbolLambda
73
73
  || this.orig[0] instanceof AST_SymbolDefun)
74
74
  || this.orig[0] instanceof AST_SymbolMethod
75
- || options.keep_classnames
75
+ || (options.keep_classnames instanceof RegExp && options.keep_classnames.test(this.orig[0].name) || options.keep_classnames === true)
76
76
  && (this.orig[0] instanceof AST_SymbolClass
77
77
  || this.orig[0] instanceof AST_SymbolDefClass);
78
78
  },
package/lib/transform.js CHANGED
@@ -152,7 +152,7 @@ TreeTransformer.prototype = new TreeWalker;
152
152
  });
153
153
 
154
154
  _(AST_Catch, function(self, tw) {
155
- self.argname = self.argname.transform(tw);
155
+ if (self.argname) self.argname = self.argname.transform(tw);
156
156
  self.body = do_list(self.body, tw);
157
157
  });
158
158
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
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.9.2",
7
+ "version": "3.10.2",
8
8
  "engines": {
9
9
  "node": ">=0.8.0"
10
10
  },
@@ -14,8 +14,7 @@
14
14
  "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
15
15
  ],
16
16
  "repository": "https://github.com/fabiosantoscode/terser.git",
17
- "main": "tools/node.js",
18
- "browser": "dist/browser.bundle.js",
17
+ "main": "dist/bundle.js",
19
18
  "bin": {
20
19
  "terser": "bin/uglifyjs"
21
20
  },
@@ -33,17 +32,22 @@
33
32
  },
34
33
  "devDependencies": {
35
34
  "acorn": "~5.7.1",
35
+ "coveralls": "^3.0.2",
36
36
  "escodegen": "^1.9.1",
37
37
  "eslint": "^4.19.1",
38
- "mocha": "~3.5.1",
38
+ "istanbul": "^0.4.5",
39
+ "mocha": "^3.0.0",
40
+ "mochallel": "^1.6.8",
39
41
  "pre-commit": "^1.2.2",
40
42
  "semver": "~5.5.0"
41
43
  },
42
44
  "scripts": {
43
- "test": "node test/run-tests.js",
45
+ "test": "rm -f dist/* && npm run prepublish && node test/run-tests.js",
46
+ "coverage": "istanbul cover test/run-tests.js",
47
+ "coveralls": "coveralls < coverage/lcov.info",
44
48
  "lint": "eslint lib",
45
49
  "lint-fix": "eslint --fix lib",
46
- "prepublish": "node 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 -c defaults=false -d \"MOZ_SourceMap=require('source-map')\" --source-map \"includeSources=true,url='browser.bundle.js.map'\" -e \"exports:(typeof module != 'undefined' ? module.exports : Terser = {})\" -b ascii_only --comments /license/ -o dist/browser.bundle.js"
50
+ "prepublish": "cd dist && node ../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 -c defaults=false -d \"MOZ_SourceMap=require('source-map')\" --source-map \"includeSources=true,url='bundle.js.map'\" -e \"exports:(typeof module != 'undefined' ? module.exports : Terser = {})\" -b ascii_only --comments /license/ -o ../dist/bundle.js"
47
51
  },
48
52
  "keywords": [
49
53
  "uglify",
package/tools/exports.js CHANGED
@@ -2,5 +2,6 @@ exports["Dictionary"] = Dictionary;
2
2
  exports["minify"] = minify;
3
3
  exports["parse"] = parse;
4
4
  exports["push_uniq"] = push_uniq;
5
+ exports["OutputStream"] = OutputStream;
5
6
  exports["TreeTransformer"] = TreeTransformer;
6
7
  exports["TreeWalker"] = TreeWalker;
package/tools/node.js CHANGED
@@ -1,4 +1,5 @@
1
1
  var fs = require("fs");
2
+ var istanbul = require("istanbul");
2
3
 
3
4
  var UglifyJS = exports;
4
5
  var FILES = UglifyJS.FILES = [
@@ -18,52 +19,20 @@ var FILES = UglifyJS.FILES = [
18
19
  return require.resolve(file);
19
20
  });
20
21
 
22
+ var instrumenter = new istanbul.Instrumenter();
23
+
21
24
  new Function("MOZ_SourceMap", "exports", function() {
22
25
  var code = FILES.map(function(file) {
23
- return fs.readFileSync(file, "utf8");
26
+ var contents = fs.readFileSync(file, "utf8");
27
+ if (global.__IS_TESTING__) return instrumenter.instrumentSync(contents, file);
28
+ return contents;
24
29
  });
25
- code.push("exports.describe_ast = " + describe_ast.toString());
26
30
  return code.join("\n\n");
27
31
  }())(
28
32
  require("source-map"),
29
33
  UglifyJS
30
34
  );
31
35
 
32
- function describe_ast() {
33
- var out = OutputStream({ beautify: true });
34
- function doitem(ctor) {
35
- out.print("AST_" + ctor.TYPE);
36
- var props = ctor.SELF_PROPS.filter(function(prop){
37
- return !/^\$/.test(prop);
38
- });
39
- if (props.length > 0) {
40
- out.space();
41
- out.with_parens(function(){
42
- props.forEach(function(prop, i){
43
- if (i) out.space();
44
- out.print(prop);
45
- });
46
- });
47
- }
48
- if (ctor.documentation) {
49
- out.space();
50
- out.print_string(ctor.documentation);
51
- }
52
- if (ctor.SUBCLASSES.length > 0) {
53
- out.space();
54
- out.with_block(function(){
55
- ctor.SUBCLASSES.forEach(function(ctor, i){
56
- out.indent();
57
- doitem(ctor);
58
- out.newline();
59
- });
60
- });
61
- }
62
- };
63
- doitem(AST_Node);
64
- return out + "\n";
65
- }
66
-
67
36
  function infer_options(options) {
68
37
  var result = UglifyJS.minify("", options);
69
38
  return result.error && result.error.defs;