]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler-sfc): move prop key escape logic to utils
authorEvan You <yyx990803@gmail.com>
Fri, 12 May 2023 10:26:25 +0000 (11:26 +0100)
committerEvan You <yyx990803@gmail.com>
Fri, 12 May 2023 10:26:33 +0000 (11:26 +0100)
packages/compiler-sfc/src/script/defineProps.ts
packages/compiler-sfc/src/script/utils.ts
packages/compiler-sfc/src/style/cssVars.ts

index 38968527c9a4e9c6abef922b32507b85b42afb7c..be99c6122ec2ec76765c3bc35825faec9565e420 100644 (file)
@@ -16,7 +16,8 @@ import {
   isLiteralNode,
   isCallOf,
   unwrapTSNode,
-  toRuntimeTypeString
+  toRuntimeTypeString,
+  getEscapedKey
 } from './utils'
 import { genModelProps } from './defineModel'
 import { getObjectOrArrayExpressionKeys } from './analyzeScriptBindings'
@@ -364,14 +365,3 @@ function inferValueType(node: Node): string | undefined {
       return 'Function'
   }
 }
-
-/**
- * key may contain symbols
- * e.g. onUpdate:modelValue -> "onUpdate:modelValue"
- */
-export const escapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g
-function getEscapedKey(key: string) {
-  return escapeSymbolsRE.test(key)
-    ? JSON.stringify(key)
-    : key
-}
index 53362fcdca80cc6d3f0191822fadbdd2b1501f89..42c4718e3a87c1201a0fcb5bd6cf1ad6aa8298ca 100644 (file)
@@ -108,3 +108,13 @@ export function normalizePath(p: string) {
 }
 
 export const joinPaths = (path.posix || path).join
+
+/**
+ * key may contain symbols
+ * e.g. onUpdate:modelValue -> "onUpdate:modelValue"
+ */
+export const escapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g
+
+export function getEscapedKey(key: string) {
+  return escapeSymbolsRE.test(key) ? JSON.stringify(key) : key
+}
index a3e2104999a2fe62bd5653d0d12527df5359d450..c86dbf2a5b94a521c0de71e9d57c89d3ad9a9733 100644 (file)
@@ -8,7 +8,7 @@ import {
   BindingMetadata
 } from '@vue/compiler-dom'
 import { SFCDescriptor } from '../parse'
-import { escapeSymbolsRE } from '../script/defineProps'
+import { escapeSymbolsRE } from '../script/utils'
 import { PluginCreator } from 'postcss'
 import hash from 'hash-sum'
 
@@ -32,10 +32,7 @@ function genVarName(id: string, raw: string, isProd: boolean): string {
     return hash(id + raw)
   } else {
     // escape ASCII Punctuation & Symbols
-    return `${id}-${raw.replace(
-      escapeSymbolsRE,
-      s => `\\${s}`
-    )}`
+    return `${id}-${raw.replace(escapeSymbolsRE, s => `\\${s}`)}`
   }
 }