megawac / acorn-umd

Parse acorn ast for AMD, CommonJS, and ES6 definitions.
MIT License
4 stars 1 forks source link

Bug: Duplicate CJSImport when require is called with method. #5

Open reggi opened 9 years ago

reggi commented 9 years ago

When the following code is processed:

var example = require('example').method()

It results in two references for the same import.

[ { type: 'CJSImport',
    specifiers: [],
    start: 13,
    end: 38,
    reference: 
     { type: 'MemberExpression',
       start: 13,
       end: 38,
       object: [Object],
       property: [Object],
       computed: false },
    ast: 
     { type: 'Program',
       start: 0,
       end: 80,
       body: [Object],
       sourceType: 'script' },
    source: 
     { type: 'Literal',
       reference: [Object],
       value: 'example',
       raw: '\'example\'',
       start: 21,
       end: 30 } },
  { type: 'CJSImport',
    specifiers: [],
    start: 13,
    end: 31,
    reference: 
     { type: 'CallExpression',
       start: 13,
       end: 31,
       callee: [Object],
       arguments: [Object] },
    ast: 
     { type: 'Program',
       start: 0,
       end: 80,
       body: [Object],
       sourceType: 'script' },
    source: 
     { type: 'Literal',
       reference: [Object],
       value: 'example',
       raw: '\'example\'',
       start: 21,
       end: 30 } } ]

This was super hard to track down :)

megawac commented 9 years ago

Good catch