From 93b88cad8de285cff0b6731c7415643ad2c24aca Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Wed, 24 Nov 2021 07:48:44 +0100 Subject: [PATCH] [FIX] components: allow prop names that are not valid bare property name --- src/compiler/code_generator.ts | 2 +- .../__snapshots__/props.test.ts.snap | 27 +++++++++++++++++++ tests/components/props.test.ts | 17 ++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/compiler/code_generator.ts b/src/compiler/code_generator.ts index 195563ea..69c2d2f9 100644 --- a/src/compiler/code_generator.ts +++ b/src/compiler/code_generator.ts @@ -967,7 +967,7 @@ export class CodeGenerator { const props: string[] = []; let hasSlotsProp = false; for (let p in ast.props) { - const propName = p.includes("-") ? `'${p}'` : p; + const propName = /^[a-z_]+$/i.test(p) ? p : `'${p}'`; props.push(`${propName}: ${this.captureExpression(ast.props[p]) || undefined}`); if (p === "slots") { hasSlotsProp = true; diff --git a/tests/components/__snapshots__/props.test.ts.snap b/tests/components/__snapshots__/props.test.ts.snap index ea2bcbef..235debe3 100644 --- a/tests/components/__snapshots__/props.test.ts.snap +++ b/tests/components/__snapshots__/props.test.ts.snap @@ -123,6 +123,33 @@ exports[`basics prop names can contain - 2`] = ` }" `; +exports[`basics support prop names that aren't valid bare object property names 1`] = ` +"function anonymous(bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component } = bdom; + let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber, safeOutput } = helpers; + + let block1 = createBlock(\`