@ansi-tools/parser 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/escaped.js +23 -11
  2. package/package.json +1 -1
package/dist/escaped.js CHANGED
@@ -18,7 +18,6 @@ for (const [sequence, len] of INTRODUCERS) {
18
18
  INTRODUCER_LOOKUP.get(secondChar)?.push([sequence, len]);
19
19
  INTRODUCER_FIRST_CHAR_CACHE.set(sequence, true);
20
20
  }
21
- const INTRODUCER_PEEK_AHEAD = new Set(INTRODUCERS.map((entry) => entry[0][1]));
22
21
  function emit(token) {
23
22
  return token;
24
23
  }
@@ -39,8 +38,21 @@ function* tokenizer(input) {
39
38
  i = l;
40
39
  break;
41
40
  }
42
- const nextChar = input[backslashIndex + 1];
43
- if (nextChar && INTRODUCER_PEEK_AHEAD.has(nextChar)) {
41
+ let isIntroducer = false;
42
+ const candidates = INTRODUCER_LOOKUP.get(input[backslashIndex + 1]);
43
+ if (candidates) for (const [seq, len] of candidates) {
44
+ if (backslashIndex + len > l) continue;
45
+ let matched = true;
46
+ for (let k = 0; k < len && matched; k += 2) {
47
+ matched = input[backslashIndex + k] === seq[k];
48
+ if (matched && k + 1 < len) matched = input[backslashIndex + k + 1] === seq[k + 1];
49
+ }
50
+ if (matched) {
51
+ isIntroducer = true;
52
+ break;
53
+ }
54
+ }
55
+ if (isIntroducer) {
44
56
  i = backslashIndex;
45
57
  break;
46
58
  } else i = backslashIndex + 1;
@@ -53,16 +65,16 @@ function* tokenizer(input) {
53
65
  if (i < l) {
54
66
  const candidates = INTRODUCER_LOOKUP.get(input[i + 1]);
55
67
  if (candidates) {
56
- let matched = false;
68
+ let isMatch = false;
57
69
  for (const [seq, len] of candidates) {
58
70
  if (i + len > l) continue;
59
- let seqMatched = true;
60
- for (let k = 0; k < len && seqMatched; k += 2) {
61
- seqMatched = input[i + k] === seq[k];
62
- if (seqMatched && k + 1 < len) seqMatched = input[i + k + 1] === seq[k + 1];
71
+ let isSeqMatch = true;
72
+ for (let k = 0; k < len && isSeqMatch; k += 2) {
73
+ isSeqMatch = input[i + k] === seq[k];
74
+ if (isSeqMatch && k + 1 < len) isSeqMatch = input[i + k + 1] === seq[k + 1];
63
75
  }
64
- if (seqMatched) {
65
- matched = true;
76
+ if (isSeqMatch) {
77
+ isMatch = true;
66
78
  if (seq === CSI_ESCAPED) {
67
79
  yield emit({
68
80
  type: TOKEN_TYPES.INTRODUCER,
@@ -127,7 +139,7 @@ function* tokenizer(input) {
127
139
  break;
128
140
  }
129
141
  }
130
- if (!matched) i++;
142
+ if (!isMatch) i++;
131
143
  } else i++;
132
144
  }
133
145
  } else if (state === "SEQUENCE") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ansi-tools/parser",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Tokenize and parse strings containing ANSI escape sequences and control codes",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",