Skip to content

Commit

Permalink
refactor: Use text.matchAll instead of sequenceFromRegExpMatch (#5994)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Jul 28, 2024
1 parent 6aa194a commit ba86668
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/cspell-dictionary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"@cspell/cspell-pipe": "workspace:*",
"@cspell/cspell-types": "workspace:*",
"cspell-trie-lib": "workspace:*",
"fast-equals": "^5.0.1",
"gensequence": "^7.0.0"
"fast-equals": "^5.0.1"
},
"devDependencies": {
"gensequence": "^7.0.0",
"lorem-ipsum": "^2.0.8"
}
}
5 changes: 3 additions & 2 deletions packages/cspell-lib/src/lib/util/text.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { opConcatMap, opMap, pipe } from '@cspell/cspell-pipe/sync';
import type { TextDocumentOffset, TextOffset } from '@cspell/cspell-types';
import { sequenceFromRegExpMatch } from 'gensequence';

import { binarySearch } from './search.js';
import {
Expand Down Expand Up @@ -47,7 +46,9 @@ export function splitCamelCaseWord(word: string): string[] {
* This function lets you iterate over regular expression matches.
*/
export function match(reg: RegExp, text: string): Iterable<RegExpExecArray> {
return sequenceFromRegExpMatch(reg, text);
if (!text) return [];
reg = reg.global ? reg : new RegExp(reg.source, reg.flags + 'g');
return text.matchAll(reg);
}

export function matchStringToTextOffset(reg: RegExp, text: string): Iterable<TextOffset> {
Expand Down
1 change: 0 additions & 1 deletion packages/cspell-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"commander": "^12.1.0",
"cosmiconfig": "9.0.0",
"cspell-trie-lib": "workspace:*",
"gensequence": "^7.0.0",
"glob": "^10.4.5",
"hunspell-reader": "workspace:*",
"yaml": "^2.5.0"
Expand Down
5 changes: 1 addition & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba86668

Please sign in to comment.