Skip to content

Commit

Permalink
fix: logic remove (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Talljack authored Jan 18, 2024
1 parent ad37bde commit 6e2210d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
14 changes: 14 additions & 0 deletions playground/vite/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ console.log(
)
document.getElementById('app')!.innerHTML = `__UNPLUGIN__${count}`

console.log('00000')
const a = true;

!a && console.log('1111111')

a || console.log(2222)

a ? 2 : console.log('010101')

function test0() {
const b = a && console.log(111)
console.log(b)
}

console.log('hello world')

const test = () => console.log(123)
Expand Down
1 change: 1 addition & 0 deletions playground/vite/test.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const count = 1

export { count }
2 changes: 1 addition & 1 deletion playground/vite/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineConfig } from 'vite'
import Inspect from 'vite-plugin-inspect'
import unpluginRemoveVite from 'unplugin-remove/vite'
import unpluginRemoveVite from '../../src/vite'

export default defineConfig({
plugins: [Inspect(), unpluginRemoveVite()],
Expand Down
2 changes: 1 addition & 1 deletion playground/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"devDependencies": {
"@types/webpack": "^5.28.0",
"cross-env": "^7.0.3",
"html-webpack-plugin": "^5.5.0",
"html-webpack-plugin": "^5.6.0",
"rimraf": "^3.0.2",
"serve": "^14.0.1",
"sucrase": "^3.25.0",
Expand Down
14 changes: 10 additions & 4 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/core/unpluginContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const createUnpluginContext = (options: Options = {}) => {
}
}
const reg = new RegExp(
`(?<!=>\\s*)console\\.(${options.consoleType?.join('|') || 'log'})\\s*\\([\\s\\S]*?\\)(?:\\s*;)?\\s*\\)?;?`,
`(?<![=>|&|\||\?|:]\\s*)console\\.(${options.consoleType?.join('|') || 'log'})\\s*\\([\\s\\S]*?\\)(?:\\s*;)?\\s*\\)?;?`,
'g',
)
s.replace(reg, '')
Expand Down

0 comments on commit 6e2210d

Please sign in to comment.