Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-sfc): handle prop key escaping properly #8911

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default /*#__PURE__*/_defineComponent({
foo: { type: Number, required: true, default: 1 },
bar: { type: Number, required: true, default: 2 },
\\"foo:bar\\": { type: String, required: true, default: 'foo-bar' },
\\"foo:baz\\": { type: String, required: true },
\\"onUpdate:modelValue\\": { type: Function, required: true }
},
setup(__props: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('sfc reactive props destructure', () => {
"foo": number // double-quoted string
'bar': number // single-quoted string
'foo:bar': string // single-quoted string containing symbols
'foo:baz': string
"onUpdate:modelValue": (val: number) => void // double-quoted string containing symbols
}>()
</script>
Expand All @@ -163,6 +164,7 @@ describe('sfc reactive props destructure', () => {
foo: BindingTypes.PROPS,
bar: BindingTypes.PROPS,
'foo:bar': BindingTypes.PROPS,
'foo:baz': BindingTypes.PROPS,
fooBar: BindingTypes.PROPS_ALIASED,
'onUpdate:modelValue': BindingTypes.PROPS
})
Expand All @@ -171,6 +173,7 @@ describe('sfc reactive props destructure', () => {
foo: { type: Number, required: true, default: 1 },
bar: { type: Number, required: true, default: 2 },
"foo:bar": { type: String, required: true, default: 'foo-bar' },
"foo:baz": { type: String, required: true },
"onUpdate:modelValue": { type: Function, required: true }
},`)
assertCode(content)
Expand Down
6 changes: 5 additions & 1 deletion packages/compiler-sfc/src/script/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,9 @@ export const joinPaths = (path.posix || path).join
export const escapeSymbolsRE = /[ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~]/g

export function getEscapedKey(key: string) {
return escapeSymbolsRE.test(key) ? JSON.stringify(key) : key
if (escapeSymbolsRE.test(key)) {
escapeSymbolsRE.lastIndex = 0
return JSON.stringify(key)
}
return key
}