Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0579f6

Browse files
committed
fix: ternary operator replacement
ref: rollup/plugins@ee8b432
1 parent da265d8 commit f0579f6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { resolveOptions, type Options, type ReplaceItem } from './core/options'
1515
/**
1616
* The main unplugin instance.
1717
*/
18-
const pluign: UnpluginInstance<Options | undefined, false> = createUnplugin<
18+
const plugin: UnpluginInstance<Options | undefined, false> = createUnplugin<
1919
Options | undefined,
2020
false
2121
>((rawOptions = {}) => {
@@ -122,9 +122,12 @@ const pluign: UnpluginInstance<Options | undefined, false> = createUnplugin<
122122
.map(({ find }) => find)
123123
.sort(longest)
124124
.map(escape)
125-
const lookahead = preventAssignment ? String.raw`(?!\s*(=[^=]|:[^:]))` : ''
125+
const lookbehind = preventAssignment
126+
? String.raw`(?<!\b(?:const|let|var)\s*)`
127+
: ''
128+
const lookahead = preventAssignment ? String.raw`(?!\s*=[^=])` : ''
126129
const pattern = new RegExp(
127-
`${delimiters[0]}(${escapedKeys.join('|')})${delimiters[1]}${lookahead}`,
130+
`${lookbehind}${delimiters[0]}(${escapedKeys.join('|')})${delimiters[1]}${lookahead}`,
128131
'g',
129132
)
130133

@@ -133,7 +136,7 @@ const pluign: UnpluginInstance<Options | undefined, false> = createUnplugin<
133136
}
134137
}
135138
})
136-
export default pluign
139+
export default plugin
137140

138141
function escape(str: string) {
139142
// eslint-disable-next-line unicorn/prefer-string-replace-all

0 commit comments

Comments
 (0)