Skip to content

Commit 574c83b

Browse files
committed
refactor(compiler-sfc): move prop key escape logic to utils
1 parent 690ef29 commit 574c83b

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

packages/compiler-sfc/src/script/defineProps.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
isLiteralNode,
1717
isCallOf,
1818
unwrapTSNode,
19-
toRuntimeTypeString
19+
toRuntimeTypeString,
20+
getEscapedKey
2021
} from './utils'
2122
import { genModelProps } from './defineModel'
2223
import { getObjectOrArrayExpressionKeys } from './analyzeScriptBindings'
@@ -364,14 +365,3 @@ function inferValueType(node: Node): string | undefined {
364365
return 'Function'
365366
}
366367
}
367-
368-
/**
369-
* key may contain symbols
370-
* e.g. onUpdate:modelValue -> "onUpdate:modelValue"
371-
*/
372-
export const escapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g
373-
function getEscapedKey(key: string) {
374-
return escapeSymbolsRE.test(key)
375-
? JSON.stringify(key)
376-
: key
377-
}

packages/compiler-sfc/src/script/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,13 @@ export function normalizePath(p: string) {
108108
}
109109

110110
export const joinPaths = (path.posix || path).join
111+
112+
/**
113+
* key may contain symbols
114+
* e.g. onUpdate:modelValue -> "onUpdate:modelValue"
115+
*/
116+
export const escapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g
117+
118+
export function getEscapedKey(key: string) {
119+
return escapeSymbolsRE.test(key) ? JSON.stringify(key) : key
120+
}

packages/compiler-sfc/src/style/cssVars.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
BindingMetadata
99
} from '@vue/compiler-dom'
1010
import { SFCDescriptor } from '../parse'
11-
import { escapeSymbolsRE } from '../script/defineProps'
11+
import { escapeSymbolsRE } from '../script/utils'
1212
import { PluginCreator } from 'postcss'
1313
import hash from 'hash-sum'
1414

@@ -32,10 +32,7 @@ function genVarName(id: string, raw: string, isProd: boolean): string {
3232
return hash(id + raw)
3333
} else {
3434
// escape ASCII Punctuation & Symbols
35-
return `${id}-${raw.replace(
36-
escapeSymbolsRE,
37-
s => `\\${s}`
38-
)}`
35+
return `${id}-${raw.replace(escapeSymbolsRE, s => `\\${s}`)}`
3936
}
4037
}
4138

0 commit comments

Comments
 (0)