Skip to content

Commit

Permalink
fix: resolve variable
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Nov 24, 2024
1 parent a13e2b5 commit 409e4ad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/plugins/esm-shim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('require regex', () => {
expect(match('require(\n"foo"\n)')).toBe(true)
expect(match(`require(\`mod\`)`)).toBe(true)
expect(match(`require.resolve('mod')`)).toBe(true)
expect(match(`\nrequire.resolve(value)`)).toBe(true)

expect(match('foo.require("foo")')).toBe(false)
expect(match(`"require('module')"`)).toBe(false)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/esm-shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const FILENAME_REGEX = /__filename/
const DIRNAME_REGEX = /__dirname/
// not char, or space before require(.resolve)?(
export const GLOBAL_REQUIRE_REGEX =
/(?:^|[^.\w'"`])\brequire(\.resolve)?\(\s*[\r\n]*(['"`])/
/(?:^|[^.\w'"`])\brequire(\.resolve)?\(\s*[\r\n]*(\w|['"`])/

const PolyfillComment = '/** rollup-private-do-not-use-esm-shim-polyfill */'
const createESMShim = ({
Expand Down

0 comments on commit 409e4ad

Please sign in to comment.