Passed
Push — master ( c35d6f...3a8069 )
by Rafael S.
01:26
created

terser.output.comments   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
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
export default [
23
  // umd bundle includes polyfill for String.codePointAt by @mathiasbynens
24
  // @see https://www.npmjs.com/package/string.prototype.codepointat
25
  {
26
    input: 'main.js',
27
    output: [
28
      {
29
        file: 'dist/utf8-buffer-size.umd.js',
30
        name: 'utf8BufferSize',
31
        format: 'umd',
32
        banner: license + codePointAtPolyfill
33
      }
34
    ],
35
    plugins: [
36
      terser({
37
        output: {
38
          comments: function(node, comment) {
39
            var text = comment.value;
40
            var type = comment.type;
41
            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...
42
              // multiline comment
43
              return /@preserve|!|@license|@cc_on/i.test(text);
44
            }
45
          }
46
        }
47
      })
48
    ]
49
  }
50
];
51