mirror of https://github.com/vuejs/core.git
refactor(compiler-sfc): move prop key escape logic to utils
This commit is contained in:
parent
690ef29635
commit
574c83b522
|
@ -16,7 +16,8 @@ import {
|
||||||
isLiteralNode,
|
isLiteralNode,
|
||||||
isCallOf,
|
isCallOf,
|
||||||
unwrapTSNode,
|
unwrapTSNode,
|
||||||
toRuntimeTypeString
|
toRuntimeTypeString,
|
||||||
|
getEscapedKey
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import { genModelProps } from './defineModel'
|
import { genModelProps } from './defineModel'
|
||||||
import { getObjectOrArrayExpressionKeys } from './analyzeScriptBindings'
|
import { getObjectOrArrayExpressionKeys } from './analyzeScriptBindings'
|
||||||
|
@ -364,14 +365,3 @@ function inferValueType(node: Node): string | undefined {
|
||||||
return 'Function'
|
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
|
|
||||||
}
|
|
||||||
|
|
|
@ -108,3 +108,13 @@ export function normalizePath(p: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const joinPaths = (path.posix || path).join
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
BindingMetadata
|
BindingMetadata
|
||||||
} from '@vue/compiler-dom'
|
} from '@vue/compiler-dom'
|
||||||
import { SFCDescriptor } from '../parse'
|
import { SFCDescriptor } from '../parse'
|
||||||
import { escapeSymbolsRE } from '../script/defineProps'
|
import { escapeSymbolsRE } from '../script/utils'
|
||||||
import { PluginCreator } from 'postcss'
|
import { PluginCreator } from 'postcss'
|
||||||
import hash from 'hash-sum'
|
import hash from 'hash-sum'
|
||||||
|
|
||||||
|
@ -32,10 +32,7 @@ function genVarName(id: string, raw: string, isProd: boolean): string {
|
||||||
return hash(id + raw)
|
return hash(id + raw)
|
||||||
} else {
|
} else {
|
||||||
// escape ASCII Punctuation & Symbols
|
// escape ASCII Punctuation & Symbols
|
||||||
return `${id}-${raw.replace(
|
return `${id}-${raw.replace(escapeSymbolsRE, s => `\\${s}`)}`
|
||||||
escapeSymbolsRE,
|
|
||||||
s => `\\${s}`
|
|
||||||
)}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue