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

createValueExpression::sourceNode.expressions is undefined #124

Closed
YujiroTakahashi opened this issue Aug 6, 2019 · 0 comments
Closed

createValueExpression::sourceNode.expressions is undefined #124

YujiroTakahashi opened this issue Aug 6, 2019 · 0 comments
Assignees

Comments

@YujiroTakahashi
Copy link

YujiroTakahashi commented Aug 6, 2019

"@riotjs/compiler": "4.3.8"

If you add a value attribute in the createValueExpression function, an error will occur if expressions is undefined.

The problem is when the type is checkbox.

my-tag.riot

<my-tag>
  <input type="text" name="txt" is="binding" data="{data}" value="1">
  <script>
    import binding  from './binding.riot';
    export default {
      components: {
        'binding': binding
      },
      onMounted(props, state) {
        this.data =  { txt: 'test' };
      }
    }
  </script>
</my-tag>

binding.riot

<binding>
  <slot/>
  <script>
    import debounce from 'debounce';
    export default {
      onMounted(props, state) {
        input = debounce((e)=> {
          this.props.data[this.props.name] = e.target.value;
        }, 100);
        this.root.onkeyup = input;
        this.root.onchange = input;
      }
    }
  </script>
</binding>

Error message

[!] (plugin at position 5) TypeError: Cannot read property '0' of undefined
opt/app/front-end/tags/index.riot
TypeError: Cannot read property '0' of undefined
    at createValueExpression (/node_modules/@riotjs/compiler/dist/index.js:1559:46)
    at createExpression (/node_modules/@riotjs/compiler/dist/index.js:1571:12)
    at attributes.map.attribute (/node_modules/@riotjs/compiler/dist/index.js:1735:49)
    at Array.map (<anonymous>)
    at builders.arrayExpression.attributes (/node_modules/@riotjs/compiler/dist/index.js:1735:32)
    at args (/node_modules/cumpa/cumpa.js:24:46)
    at args (/node_modules/cumpa/cumpa.js:24:46)
    at createBindingAttributes (/node_modules/@riotjs/compiler/dist/index.js:1738:6)
    at createTagBinding (/node_modules/@riotjs/compiler/dist/index.js:1776:7)
    at createTagWithBindings (/node_modules/@riotjs/compile

@riotjs/compiler/dist/index.js

function createValueExpression(sourceNode, sourceFile, sourceCode) {
  return builders.objectExpression([
    simplePropertyNode(BINDING_TYPE_KEY,
      builders.memberExpression(
        builders.identifier(EXPRESSION_TYPES),
        builders.identifier(VALUE_EXPRESSION_TYPE),
        false
      ),
    ),
    simplePropertyNode(
      BINDING_EVALUATE_KEY,
      toScopedFunction(sourceNode.expressions[0], sourceFile, sourceCode)
    )
  ])
}

toScopedFunction(sourceNode.expressions[0], sourceFile, sourceCode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants