Sha256: 6f0476e513fc058031b8bebb06f37963a6641cce18af73ac3bc6d9fd1fb2d799

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

// Set source-map.js sourceMap to terser.js MOZ_SourceMap
MOZ_SourceMap = sourceMap;

function comments(option) {
  if (Object.prototype.toString.call(option) === '[object Array]') {
    return new RegExp(option[0], option[1]);
  } else if (option == "jsdoc") {
    return function(node, comment) {
      if (comment.type == "comment2") {
        return /@preserve|@license|@cc_on/i.test(comment.value);
      } else {
        return false;
      }
    };
  } else {
    return option;
  }
}

function regexOption(options) {
  if (typeof options === 'object' && options.regex) {
    return new RegExp(options.regex[0], options.regex[1]);
  } else {
    return null;
  }
}

function terser_wrapper(options) {
  var source = options.source;
  options.output.comments = comments(options.output.comments);

  if (options.mangle) {
    if (options.mangle.properties) {
      options.mangle.properties.regex = regexOption(options.mangle.properties);
    }
  }
  delete options.source;


  var inputFilename = '0';
  if (options.sourceMap) {
    inputFilename = options.sourceMap.input;
    delete options.sourceMap.input;
  }

  var inputs = {};
  inputs[inputFilename] = source;

  try {
    return Terser.minifySync(inputs, options);
  } catch (error) {
    const { message, filename, line, col, pos } = error;
    return {error: {message: message, filename: filename, line: line, col: col, pos: pos}}
  }
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
terser-1.1.8 lib/terser_wrapper.js
terser-1.1.7 lib/terser_wrapper.js
terser-1.1.6 lib/terser_wrapper.js
terser-1.1.5 lib/terser_wrapper.js
terser-1.1.4 lib/terser_wrapper.js
terser-1.1.3 lib/terser_wrapper.js
terser-1.1.2 lib/terser_wrapper.js
terser-1.1.1 lib/terser_wrapper.js