diff --git a/src/runtime/component_node.ts b/src/runtime/component_node.ts index d020e475..0238eade 100644 --- a/src/runtime/component_node.ts +++ b/src/runtime/component_node.ts @@ -32,7 +32,7 @@ export function useComponent(): Component { * Apply default props (only top level). */ function applyDefaultProps
(props: P, defaultProps: Partial
): P { - const result = Object.create(props); + const result = Object.assign({} as any, props); for (let propName in defaultProps) { if (props[propName] === undefined) { result[propName] = defaultProps[propName]; diff --git a/tests/components/__snapshots__/basics.test.ts.snap b/tests/components/__snapshots__/basics.test.ts.snap index 6a23741d..cd49f832 100644 --- a/tests/components/__snapshots__/basics.test.ts.snap +++ b/tests/components/__snapshots__/basics.test.ts.snap @@ -551,6 +551,32 @@ exports[`basics props is set on root component 1`] = ` }" `; +exports[`basics props value are own property of props object 1`] = ` +"function anonymous(app, bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + + let block1 = createBlock(\`simple vnode\`); + + return function template(ctx, node, key = \\"\\") { + return block1(); + } +}" +`; + +exports[`basics props value are own property of props object, even with default values 1`] = ` +"function anonymous(app, bdom, helpers +) { + let { text, createBlock, list, multi, html, toggler, component, comment } = bdom; + + let block1 = createBlock(\`simple vnode\`); + + return function template(ctx, node, key = \\"\\") { + return block1(); + } +}" +`; + exports[`basics reconciliation alg is not confused in some specific situation 1`] = ` "function anonymous(app, bdom, helpers ) { diff --git a/tests/components/basics.test.ts b/tests/components/basics.test.ts index 6815b377..bfb605e9 100644 --- a/tests/components/basics.test.ts +++ b/tests/components/basics.test.ts @@ -129,6 +129,36 @@ describe("basics", () => { await app.mount(fixture); }); + test("props value are own property of props object", async () => { + expect.assertions(2); + const p = { a: 1 }; + class Test extends Component { + static template = xml`simple vnode`; + setup() { + expect(Object.prototype.hasOwnProperty.call(this.props, "a")).toBe(true); + } + } + + const app = new App(Test, { props: p }); + await app.mount(fixture); + }); + + test("props value are own property of props object, even with default values", async () => { + expect.assertions(3); + const p = { a: 1 }; + class Test extends Component { + static template = xml`simple vnode`; + static defaultProps = { b: 1 }; + setup() { + expect(Object.prototype.hasOwnProperty.call(this.props, "a")).toBe(true); + expect(Object.prototype.hasOwnProperty.call(this.props, "b")).toBe(true); + } + } + + const app = new App(Test, { props: p }); + await app.mount(fixture); + }); + test("some simple sanity checks (el/status)", async () => { expect.assertions(3); class Test extends Component {