Skip to content

Commit 1222727

Browse files
committed
refactor: remove useless capture group
1 parent 26b1b99 commit 1222727

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

packages/vite/src/node/__tests__/scan.spec.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { scriptRE, commentRE } from '../optimizer/scan'
2+
23
describe('optimizer-scan:script-test', () => {
34
const scriptContent = `import { defineComponent } from 'vue'
45
import ScriptDevelopPane from './ScriptDevelopPane.vue';
@@ -10,14 +11,14 @@ describe('optimizer-scan:script-test', () => {
1011

1112
test('component return value test', () => {
1213
scriptRE.lastIndex = 0
13-
const [, tsOpenTag, , tsContent] = scriptRE.exec(
14+
const [, tsOpenTag, tsContent] = scriptRE.exec(
1415
`<script lang="ts">${scriptContent}</script>`
1516
)
1617
expect(tsOpenTag).toEqual('<script lang="ts">')
1718
expect(tsContent).toEqual(scriptContent)
1819

1920
scriptRE.lastIndex = 0
20-
const [, openTag, , content] = scriptRE.exec(
21+
const [, openTag, content] = scriptRE.exec(
2122
`<script>${scriptContent}</script>`
2223
)
2324
expect(openTag).toEqual('<script>')
@@ -54,16 +55,12 @@ describe('optimizer-scan:script-test', () => {
5455

5556
test('ordinary script tag test', () => {
5657
scriptRE.lastIndex = 0
57-
const [, tag, , content] = scriptRE.exec(
58-
`<script >var test = null</script>`
59-
)
58+
const [, tag, content] = scriptRE.exec(`<script >var test = null</script>`)
6059
expect(tag).toEqual('<script >')
6160
expect(content).toEqual('var test = null')
6261

6362
scriptRE.lastIndex = 0
64-
const [, tag1, , content1] = scriptRE.exec(
65-
`<script>var test = null</script>`
66-
)
63+
const [, tag1, content1] = scriptRE.exec(`<script>var test = null</script>`)
6764
expect(tag1).toEqual('<script>')
6865
expect(content1).toEqual('var test = null')
6966
})

packages/vite/src/node/optimizer/scan.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function globEntries(pattern: string | string[], config: ResolvedConfig) {
127127

128128
const scriptModuleRE =
129129
/(<script\b[^>]*type\s*=\s*(?:"module"|'module')[^>]*>)(.*?)<\/script>/gims
130-
export const scriptRE = /(<script\b(\s[^>]*>|>))(.*?)<\/script>/gims
130+
export const scriptRE = /(<script\b(?:\s[^>]*>|>))(.*?)<\/script>/gims
131131
export const commentRE = /<!--(.|[\r\n])*?-->/
132132
const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im
133133
const langRE = /\blang\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im
@@ -200,8 +200,7 @@ function esbuildScanPlugin(
200200
let loader: Loader = 'js'
201201
let match
202202
while ((match = regex.exec(raw))) {
203-
const [, openTag, htmlContent, scriptContent] = match
204-
const content = isHtml ? htmlContent : scriptContent
203+
const [, openTag, content] = match
205204
const srcMatch = openTag.match(srcRE)
206205
const langMatch = openTag.match(langRE)
207206
const lang =

0 commit comments

Comments
 (0)