How to use the terser/package.version function in terser

To help you get started, we’ve selected a few terser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gdh1995 / vimium-c / tests / unit / terser.js View on Github external
#!/usr/bin/env node
"use strict";
var opts = {
  "mangle": {
    "properties": true,
    "toplevel": true
  },
  nameCache: { vars: {}, props: {} }
};

var terser = require('terser');
var hasOptionUndeclared = require('terser/package').version >= '4.1.1';
if (hasOptionUndeclared) {
  opts.mangle.properties = {
    "undeclared": true
  };
}
terser.minify('var Bar = {};', opts);
var result = terser.minify('var Foo = { foo: function() { return Bar.bar() } };', opts);
var expected = `var r={o:function(){return a.${hasOptionUndeclared ? "t" : "v"}()}};`;
console.log("[task] test uglifying external properties",
    "\n[Current ]", result.code, "\n[Expected]", expected);
if (result.code === expected) {
  console.log(">>> same");
} else {
  // https://github.com/terser-js/terser/issues/397
  console.log(">>> different, so", hasOptionUndeclared ? "please check test code" : "recommend a terser <= v3.14.0");
}
github gdh1995 / vimium-c / scripts / dependencies.js View on Github external
p.regex = ToRegExp(p.regex);
    }
    if (m && typeof m.keep_fnames === "string") {
      m.keep_fnames = ToRegExp(m.keep_fnames);
    }
    else if (m && !m.keep_fnames) {
      m.keep_fnames = c.keep_fnames;
    }
    var comments = o.comments;
    if (comments && typeof comments === "string") {
      o.comments = ToRegExp(comments);
    }
    let ver = "", terser = null;
    try {
      // @ts-ignore
      ver = require("terser/package").version;
    } catch (e) {
      console.log("Can not read the version of terser.");
    }
    try {
      // @ts-ignore
      terser = require("terser");
    } catch (e) {
      console.log("Can not read the module of terser.");
    }
    if (ver) {
      var hasOptionUndeclared = ver >= '4.1.2', has_wrap_func_args = ver >= '4.3';
      if (m) {
        if (hasOptionUndeclared) {
          if (p.undeclared == null) {
            p.undeclared = true;
          }

terser

JavaScript parser, mangler/compressor and beautifier toolkit for ES6+

BSD-2-Clause
Latest version published 19 days ago

Package Health Score

92 / 100
Full package analysis