codemix / babel-plugin-typecheck

Static and runtime type checking for JavaScript in the form of a Babel plugin.
MIT License
886 stars 44 forks source link

Error in error generation in typecheck plugin (maybe) #103

Closed haf closed 8 years ago

haf commented 8 years ago
19:40:30 webpack.1    | ERROR in ./app/saveDetails.js
19:40:30 webpack.1    | Module build failed: TypeError: /app/saveDetails.js: Cannot read property 'type' of undefined
19:40:30 webpack.1    |     at humanReadableType (/node_modules/babel-plugin-typecheck/lib/index.js:2860:23)
19:40:30 webpack.1    |     at Array.map (native)
19:40:30 webpack.1    |     at humanReadableType (/node_modules/babel-plugin-typecheck/lib/index.js:2867:40)
19:40:30 webpack.1    |     at varTypeErrorMessage (/node_modules/babel-plugin-typecheck/lib/index.js:3145:102)
19:40:30 webpack.1    |     at Object.AssignmentExpression (/node_modules/babel-plugin-typecheck/lib/index.js:428:20)
19:40:30 webpack.1    |     at NodePath._call (/node_modules/babel-traverse/lib/path/context.js:74:18)
19:40:30 webpack.1    |     at NodePath.call (/node_modules/babel-traverse/lib/path/context.js:46:17)
19:40:30 webpack.1    |     at NodePath.visit (/node_modules/babel-traverse/lib/path/context.js:104:12)
19:40:30 webpack.1    |     at TraversalContext.visitQueue (/node_modules/babel-traverse/lib/context.js:153:16)
19:40:30 webpack.1    |     at TraversalContext.visitSingle (/node_modules/babel-traverse/lib/context.js:113:19)
19:40:30 webpack.1    |     at TraversalContext.visit (/node_modules/babel-traverse/lib/context.js:197:19)
19:40:30 webpack.1    |     at Function.traverse.node (/node_modules/babel-traverse/lib/index.js:139:17)

Using latest everything at time of writing.

phpnode commented 8 years ago

@haf please could you provide the code which is triggering this? thanks.

haf commented 8 years ago

I'm afraid not, it's not open source and that file is the largest file in the application. I can instrument the code further and make changes to config if you suggest anything, however.

It's using a few different ways of writing code, like:

import {
  a,
  b,
  c
} from './abc';
import 'css.css';
const o = {
  fn:
    x => x + 1,
  fn2(a, b) {
    return [a, b];
  },
  fn3() {
    this.props.abc.byNum(value, nextAbc => {
      StateWriter.clean(this.state)
        .bind(this.x(value))
        .bind(this.y(value, nextAbc))
        .bind(state => {
          if (this.isMounted()) { this.setState(state); }
          return [true, state];
        })
        .bind(this.z)
        .mreturn(id);
    });
  }
}
export default injectIntl(o);
phpnode commented 8 years ago

@haf the code you provided doesn't replicate the bug. I understand that your project is not open source but to get this fixed I need some code which replicates the issue. Since this is a compilation error, the fastest way for you to narrow this down is to comment out large sections of saveDetails.js and keep running the build until the issue goes away. At that point you should have a minimum subset of the code which replicates the problem and you should be able to sanitize that so that it doesn't expose any of the original code. Thanks for your help with this.

JounQin commented 7 years ago

I also have this issue……

My code:

export default {
  watch: {
    values(val) {
      this.mutatingValues = val
    },
    mutatingValues(val) {
      if (this.valueIndex === -1) {
        this.currentValue = (val || [])[0]
      }
      if (this.rotateEffect) {
        this.$nextTick(() => {
          this.doOnValuesChange()
        })
      }
    },
    currentValue(val) {
      this.doOnValueChange()
      if (this.rotateEffect) {
        this.planUpdateRotate()
      }
      this.$emit('input', val)
      this.dispatch('picker', 'slotValueChange', this)
    }
  }
}

And when I change my code to:

export default {
  watch: {
    values(val) {
      this.mutatingValues = val
    },
    mutatingValues(val: Array) {
      if (this.valueIndex === -1) {
        this.currentValue = (val || [])[0]
      }
      if (this.rotateEffect) {
        this.$nextTick(() => {
          this.doOnValuesChange()
        })
      }
    },
    currentValue(val: any) {
      this.doOnValueChange()
      if (this.rotateEffect) {
        this.planUpdateRotate()
      }
      this.$emit('input', val)
      this.dispatch('picker', 'slotValueChange', this)
    }
  }
}

There will be no error any more……

I don't know whether you can reproduce it……

I print annotation in function humanReadableType in babel-plugin-typecheck, it seems that annotation.params is [undefined].

@phpnode

JounQin commented 7 years ago

@phpnode I can reproduce it here.

https://github.com/JounQin/test/tree/master/babel-plugin-typecheck

Hope for your help.