diff --git a/src/utils/__snapshots__/find-requires.snap b/src/utils/__snapshots__/find-requires.snap index a84de09b..41102f6a 100644 --- a/src/utils/__snapshots__/find-requires.snap +++ b/src/utils/__snapshots__/find-requires.snap @@ -74,6 +74,17 @@ exports[`unit:utils/findRequires > should return RequireStatement object array 1 "start": 147, "syntax": "require", }, + { + "code": "require(\\"./arr\\")", + "end": 214, + "imports": [], + "kind": "require", + "specifier": "./arr", + "specifier_kind": "relative", + "specifier_syntax": "static", + "start": 198, + "syntax": "require", + }, { "code": "const { default: myDefault, @@ -86,7 +97,7 @@ exports[`unit:utils/findRequires > should return RequireStatement object array 1 squareThree, squareTwo } = require('./lib')", - "end": 327, + "end": 358, "imports": [ "default: myDefault", "addFive", @@ -102,7 +113,7 @@ exports[`unit:utils/findRequires > should return RequireStatement object array 1 "specifier": "./lib", "specifier_kind": "relative", "specifier_syntax": "static", - "start": 185, + "start": 216, "syntax": "require", }, ] diff --git a/src/utils/__tests__/find-requires.spec.ts b/src/utils/__tests__/find-requires.spec.ts index 05e48d7a..3242746a 100644 --- a/src/utils/__tests__/find-requires.spec.ts +++ b/src/utils/__tests__/find-requires.spec.ts @@ -15,6 +15,7 @@ describe('unit:utils/findRequires', () => { const mod = require('lib'); require(id) require('#src/utils/resolve-aliases') + const arr = [require("./arr")] const { default: myDefault, addFive, @@ -32,7 +33,7 @@ describe('unit:utils/findRequires', () => { const results = testSubject(code) // Expect - expect(results).to.be.an('array').of.length(7) + expect(results).to.be.an('array').of.length(8) expect(results).toMatchSnapshot() }) diff --git a/src/utils/find-requires.ts b/src/utils/find-requires.ts index 90b88116..efe35c3d 100644 --- a/src/utils/find-requires.ts +++ b/src/utils/find-requires.ts @@ -33,7 +33,7 @@ const findRequires = (code: string = ''): RequireStatement[] => { * @const {RegExp} REQUIRE_REGEX */ const REQUIRE_REGEX: RegExp = - /(?<=^|[\s;])\b(?:(?:const\s*|let\s*|var\s*)?(?(?:[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*)|(?:[\w\t\n\r "$'*,./:{}-]+?))?\s*=?\s*(?require)\((?["']?[\S\t\n\r]+?["']?)\)(?=;?\n?))(?(?:[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*)|(?:[\w\t\n\r "$'*,./:{}-]+?))?\s*=?\s*(?require)\((?["']?[\S\t\n\r]+?["']?)\)(?=;?\n?))(? { const { 0: code = '', index: start = 0, groups = {} } = match