Issues (2)

rollup.config.js (1 issue)

1
/*
2
 * Copyright (c) 2018 Rafael da Silva Rocha.
3
 */
4
5
/**
6
 * @fileoverview rollup configuration file.
7
 * @see https://github.com/rochars/utf8-buffer-size
8
 */
9
10
import { terser } from "rollup-plugin-terser";
11
import fs from 'fs';
12
13
// Load polyfill only in UMD dist
14
const codePointAtPolyfill = fs.readFileSync(
15
  './node_modules/string.prototype.codepointat/codepointat.js', 'utf8');
16
17
// Legal
18
const license = '/*!\n'+
19
  ' * Copyright (c) 2018 Rafael da Silva Rocha.\n'+
20
  ' */\n';
21
22
// Exports as default and as .default so it do not break in TypeScript
23
let UMDHeader = "(function (global, factory) {" +
24
  "typeof exports === 'object' && typeof module !== 'undefined' ? " +
25
  "(module.exports = factory(), module.exports.default = module.exports)  :" +
26
  "typeof define === 'function' && define.amd ? define(factory) :" +
27
  "(global.utf8BufferSize = factory());" +
28
  "}(this, (function () { 'use strict';";
29
let UMDFooter = "return utf8BufferSize;})));";
30
31
export default [
32
  // umd bundle includes polyfill for String.codePointAt by @mathiasbynens
33
  // @see https://www.npmjs.com/package/string.prototype.codepointat
34
  {
35
    input: 'main.js',
36
    output: [
37
      {
38
        file: 'dist/utf8-buffer-size.umd.js',
39
        name: 'utf8BufferSize',
40
        format: 'iife',
41
        banner: license + codePointAtPolyfill + UMDHeader,
42
        footer: UMDFooter
43
      }
44
    ],
45
    plugins: [
46
      terser({
47
        output: {
48
          comments: function(node, comment) {
49
            var text = comment.value;
50
            var type = comment.type;
51
            if (type == "comment2") {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if type == "comment2" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
52
              // multiline comment
53
              return /@preserve|!|@license|@cc_on/i.test(text);
54
            }
55
          }
56
        }
57
      })
58
    ]
59
  }
60
];
61