Skip to content

Passing redundant attributes to a component fails the compilation with a cryptic error #253

@jakub-g

Description

@jakub-g

Let's consider the following plunk:

http://plnkr.co/edit/pPQWTgkzTLyBdBIX8vfQ?p=preview

MyItemCtrl.js

var klass = require("hsp/klass");

var MyItemCtrl= klass({
    attributes: {
        "foo" : { type : "string"},
        "bar" : { type : "string" }
    }
});

module.exports = MyItemCtrl;

hello.hsp

var MyItemCtrl = require("./MyItemCtrl");

{template Hello}
  <#myItem foo="FOO" bar="BAR" />
{/template}

{template myItem using ctrl:MyItemCtrl}
  foo = {ctrl.foo} <br>
  bar = {ctrl.bar} <br>
{/template}

module.exports = Hello;

So far so good, I define attributes in the controller (foo and bar) and pass them from Hello template to <#myItem> and everything works properly.

Now, let's change line 4 in hello.hsp from:

<#myItem foo="FOO" bar="BAR" /> 

to

<#myItem foo="FOO" bar="BAR" xxx="xxx" />

i.e. let's pass some redundant attrib that is not defined in attributes of the controller.

What we get is a compilation failure plus a cryptic error message:

TypeError: this.ctlAttributes[nm] is undefined
if (this.ctlAttributes[nm].type !== "template") {

I think the code should still compile fine, only raising a warning, with a better description of the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions