Skip to content

Commit b6fc3cd

Browse files
committed
fix: use strip-literal to strip string lterals (#8054)
1 parent b0e9234 commit b6fc3cd

10 files changed

+49
-339
lines changed

packages/vite/LICENSE.md

+29
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,35 @@ Repository: chalk/strip-ansi
34653465
34663466
---------------------------------------
34673467

3468+
## strip-literal
3469+
License: MIT
3470+
By: Anthony Fu
3471+
Repository: git+https://github.com/antfu/strip-literal.git
3472+
3473+
> MIT License
3474+
>
3475+
> Copyright (c) 2022 Anthony Fu <https://github.com/antfu>
3476+
>
3477+
> Permission is hereby granted, free of charge, to any person obtaining a copy
3478+
> of this software and associated documentation files (the "Software"), to deal
3479+
> in the Software without restriction, including without limitation the rights
3480+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3481+
> copies of the Software, and to permit persons to whom the Software is
3482+
> furnished to do so, subject to the following conditions:
3483+
>
3484+
> The above copyright notice and this permission notice shall be included in all
3485+
> copies or substantial portions of the Software.
3486+
>
3487+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3488+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3489+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3490+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3491+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3492+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3493+
> SOFTWARE.
3494+
3495+
---------------------------------------
3496+
34683497
## to-regex-range
34693498
License: MIT
34703499
By: Jon Schlinkert, Rouven Weßling

packages/vite/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"source-map-js": "^1.0.2",
113113
"source-map-support": "^0.5.21",
114114
"strip-ansi": "^6.0.1",
115+
"strip-literal": "^0.2.0",
115116
"terser": "^5.13.1",
116117
"tsconfck": "^1.2.2",
117118
"tslib": "^2.4.0",

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

-190
This file was deleted.

packages/vite/src/node/cleanString.ts

-142
This file was deleted.

packages/vite/src/node/plugins/assetImportMetaUrl.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import MagicString from 'magic-string'
33
import path from 'path'
44
import { fileToUrl } from './asset'
55
import type { ResolvedConfig } from '../config'
6-
import { emptyString } from '../cleanString'
6+
import { stripLiteral } from 'strip-literal'
77

88
/**
99
* Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL
@@ -27,7 +27,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
2727
let s: MagicString | undefined
2828
const assetImportMetaUrlRE =
2929
/\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*,?\s*\)/g
30-
const cleanString = emptyString(code)
30+
const cleanString = stripLiteral(code)
3131

3232
let match: RegExpExecArray | null
3333
while ((match = assetImportMetaUrlRE.exec(cleanString))) {

0 commit comments

Comments
 (0)