babel-plugin-rewire icon indicating copy to clipboard operation
babel-plugin-rewire copied to clipboard

HTML error when using default function parameters

Open queicherius opened this issue 7 years ago • 4 comments

Cannot read property 'start' of undefined
TypeError: Cannot read property 'start' of undefined
    at /Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/html/annotator.js:137:32
    at Array.forEach (native)
    at annotateBranches (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/html/annotator.js:112:30)
    at Object.annotateSourceCode (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/html/annotator.js:191:9)
    at HtmlReport.onDetail (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/html/index.js:217:39)
    at LcovReport.(anonymous function) [as onDetail] (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-reports/lib/lcov/index.js:24:24)
    at Visitor.(anonymous function) [as onDetail] (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:34:30)
    at ReportNode.Node.visit (/Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:123:17)
    at /Users/david/Projects/abc-environment/node_modules/nyc/node_modules/istanbul-lib-report/lib/tree.js:116:23
    at Array.forEach (native)

  • The CLI command runs through without error
  • The error message is present in the HTML output (see @BenoitAverty comment here)
  • This error only seems to happen when you are using the default function parameters from ES2015 and comparing something with if afterwards. When using one of the two, it's working fine.
  • The error does not happen when ran on the pre-generated code (from babel)
  • The error happens in all versions of babel-plugin-rewire, starting from 1.0.0-beta-1 up to 1.0.0
  • The error does not happen when rewire is removed from the .babelrc, so it seems to be an issue with this library
  • The full dependency list can be seen here

This is a minimal reproduction test case, which yields the HTML error.

// module
const answer = 42
export default function (something, punctuation = '!') {
  if (something === 'test') {
    console.log('Testing something.')
  }

  return answer + punctuation
}
// Test
import {expect} from 'chai'
import module from './module.js'

describe('my module', () => {
  it('should return the answer to life', async () => {
    let result = await module('hello')
    expect(result).to.equal('42!')
  })

  it('should return the answer to life', async () => {
    let result = await module('test', '?')
    expect(result).to.equal('42?')
  })
})

queicherius avatar Oct 09 '16 23:10 queicherius

I committed this pull request, but it would be better to figure out what generates the issue instead of patching it in the end result.

queicherius avatar Oct 09 '16 23:10 queicherius

@queicherius thanks for the PR. I would really like to fix the issue also from our side, but I do not understand what is meant by wrong meta data. Do you have a complete sample to reproduce the error?

speedskater avatar Oct 10 '16 16:10 speedskater

I would really like to fix the issue also from our side, but I do not understand what is meant by wrong meta data.

The generated branch array is [ 2, null ], while the generated meta array is only [ { start: { line: 8, column: 50 }, end: { line: 8, column: 53 } } ] triggering an error when going through the branch array and accessing the undefined meta element. Not sure why / how it does that, I just logged it when putting in the PR.

Do you have a complete sample to reproduce the error?

Sure, I made a repository for you here. Tried to make it as simple as possible.

queicherius avatar Oct 10 '16 18:10 queicherius

@queicherius thanks for your detailed example. I had a look at it and although the sample perfectly reproduces the error, I haven't found a solution until now. Sorry that I am not having a longer time slot to investigate the problem in the next week but I will try to find a solution ASAP.

speedskater avatar Oct 11 '16 09:10 speedskater