diff --git a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/definePropsDestructure.spec.ts.snap b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/definePropsDestructure.spec.ts.snap index c31005c40c0..35f4e066826 100644 --- a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/definePropsDestructure.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/definePropsDestructure.spec.ts.snap @@ -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) { diff --git a/packages/compiler-sfc/__tests__/compileScript/definePropsDestructure.spec.ts b/packages/compiler-sfc/__tests__/compileScript/definePropsDestructure.spec.ts index a41f3131bef..2cb0428e543 100644 --- a/packages/compiler-sfc/__tests__/compileScript/definePropsDestructure.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/definePropsDestructure.spec.ts @@ -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 }>() @@ -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 }) @@ -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) diff --git a/packages/compiler-sfc/src/script/utils.ts b/packages/compiler-sfc/src/script/utils.ts index 42c4718e3a8..9bdfa6ad24e 100644 --- a/packages/compiler-sfc/src/script/utils.ts +++ b/packages/compiler-sfc/src/script/utils.ts @@ -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 }