syntax-tree / nlcst-emoticon-modifier
Showing 1 of 1 files from the diff.

@@ -6,8 +6,6 @@
Loading
6 6
7 7
module.exports = modifier(mergeEmoticons)
8 8
9 -
var emoticonNode = 'EmoticonNode'
10 -
11 9
// Magic numbers.
12 10
//
13 11
// Emoticons are treated by a parser as multiple nodes.
@@ -28,37 +26,32 @@
Loading
28 26
29 27
// Merge emoticons into an `EmoticonNode`.
30 28
function mergeEmoticons(child, index, parent) {
31 -
  var siblings
32 29
  var value
33 30
  var siblingIndex
34 31
  var node
35 32
  var emoticon
36 -
  var subvalue
37 33
38 34
  // Check if `child`s first character could be used to start an emoticon.
39 35
  if (start.indexOf(toString(child).charAt(0)) !== -1) {
40 -
    siblings = parent.children
36 +
    value = ''
41 37
    siblingIndex = index
42 38
    node = child
43 -
    value = ''
44 39
45 40
    while (node) {
46 41
      if (value.length >= maxEmoticonLength) {
47 42
        return
48 43
      }
49 44
50 -
      subvalue = toString(node)
51 -
52 -
      value += subvalue
45 +
      value += toString(node)
53 46
54 47
      // The second test, if the last character of the current node is
55 48
      // superfluous but improves performance by 30%.
56 49
      if (
57 -
        node.type !== emoticonNode &&
58 -
        end.indexOf(subvalue.charAt(subvalue.length - 1)) !== -1 &&
50 +
        node.type !== 'EmoticonNode' &&
51 +
        end.indexOf(value.charAt(value.length - 1)) !== -1 &&
59 52
        emoticons.indexOf(value) !== -1
60 53
      ) {
61 -
        emoticon = {type: emoticonNode, value: value}
54 +
        emoticon = {type: 'EmoticonNode', value: value}
62 55
63 56
        if (child.position && node.position) {
64 57
          emoticon.position = {
@@ -67,46 +60,36 @@
Loading
67 60
          }
68 61
        }
69 62
70 -
        siblings.splice(index, siblingIndex - index + 1, emoticon)
63 +
        parent.children.splice(index, siblingIndex - index + 1, emoticon)
71 64
72 65
        // Some emoticons, like `:-`, can be followed by more characters to form
73 66
        // other emoticons.
74 67
        return index - 1
75 68
      }
76 69
77 -
      node = siblings[++siblingIndex]
70 +
      node = parent.children[++siblingIndex]
78 71
    }
79 72
  }
80 73
}
81 74
82 75
function unpack() {
83 -
  var length = raw.length
84 76
  var index = -1
85 77
  var subset
86 78
  var offset
87 -
  var count
88 -
  var subvalue
89 79
  var char
90 80
91 -
  while (++index < length) {
81 +
  while (++index < raw.length) {
92 82
    subset = raw[index].emoticons
93 -
    count = subset.length
94 83
    offset = -1
95 84
96 -
    while (++offset < count) {
97 -
      subvalue = subset[offset]
85 +
    while (++offset < subset.length) {
86 +
      emoticons.push(subset[offset])
98 87
99 -
      emoticons.push(subvalue)
88 +
      char = subset[offset].charAt(0)
89 +
      if (start.indexOf(char) === -1) start.push(char)
100 90
101 -
      char = subvalue.charAt(0)
102 -
      if (start.indexOf(char) === -1) {
103 -
        start.push(char)
104 -
      }
105 -
106 -
      char = subvalue.charAt(subvalue.length - 1)
107 -
      if (end.indexOf(char) === -1) {
108 -
        end.push(char)
109 -
      }
91 +
      char = subset[offset].charAt(subset[offset].length - 1)
92 +
      if (end.indexOf(char) === -1) end.push(char)
110 93
    }
111 94
  }
112 95
}
Files Coverage
index.js 100.00%
Project Totals (1 files) 100.00%
33.2
node=
TRAVIS_OS_NAME=linux
33.1
lts/dubnium=/dubnium
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading