Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Binary nodes not equipped with lexical information in wrapped AST #4

Open
apatil opened this Issue · 5 comments

2 participants

@apatil

Hi James,

Thanks for burrito. I've been using it to assist a heavy source-to-source transformation and have found the following small bug. When I do the following in Node.js

burrito('d=a+b',function (n){console.log(n.node);});

I see

[ { name: 'stat',
    start: 
     { type: 'name',
       value: 'c',
       line: 0,
       col: 0,
       pos: 0,
       nlb: false,
       comments_before: [] },
    end: 
     { type: 'name',
       value: 'b',
       line: 0,
       col: 4,
       pos: 4,
       nlb: false,
       comments_before: [] } },
  [ { name: 'assign', start: [Object], end: [Object] },
    true,
    [ [Object], 'c' ],
    [ 'binary', '+', [Object], [Object] ] ] ]
[ { name: 'assign',
    start: 
     { type: 'name',
       value: 'c',
       line: 0,
       col: 0,
       pos: 0,
       nlb: false,
       comments_before: [] },
    end: 
     { type: 'name',
       value: 'b',
       line: 0,
       col: 4,
       pos: 4,
       nlb: false,
       comments_before: [] } },
  true,
  [ { name: 'name', start: [Object], end: [Object] }, 'c' ],
  [ 'binary', '+', [ [Object], 'a' ], [ [Object], 'b' ] ] ]   // This is the line with the problem!
[ { name: 'name',
    start: 
     { type: 'name',
       value: 'c',
       line: 0,
       col: 0,
       pos: 0,
       nlb: false,
       comments_before: [] },
    end: 
     { type: 'name',
       value: 'c',
       line: 0,
       col: 0,
       pos: 0,
       nlb: false,
       comments_before: [] } },
  'c' ]
[ { name: 'name',
    start: 
     { type: 'name',
       value: 'a',
       line: 0,
       col: 2,
       pos: 2,
       nlb: false,
       comments_before: [] },
    end: 
     { type: 'name',
       value: 'a',
       line: 0,
       col: 2,
       pos: 2,
       nlb: false,
       comments_before: [] } },
  'a' ]
[ { name: 'name',
    start: 
     { type: 'name',
       value: 'b',
       line: 0,
       col: 4,
       pos: 4,
       nlb: false,
       comments_before: [] },
    end: 
     { type: 'name',
       value: 'b',
       line: 0,
       col: 4,
       pos: 4,
       nlb: false,
       comments_before: [] } },
  'b' ]

See the flagged line above. In that line, the binary node hasn't got the usual {type: 'binary', value: ...} information that Burrito adds to the UglifyJS AST nodes.

Anand

@apatil

The same happens for unary prefixes in some cases. Try replacing 'd=a+b' with '-a'.

@makc

same with

a.b;a.b(c);

second statement does not pass dot node (it is plain ["dot", ["name", "a"], "b"] in call node.node)

@makc

actually this is uglify thing, the ast already comes like that from parser.parse:

ocalhost:Downloads makc$ npm install uglify-js@1.3.4
npm http GET https://registry.npmjs.org/uglify-js/1.3.4
npm http 200 https://registry.npmjs.org/uglify-js/1.3.4
npm http GET https://registry.npmjs.org/uglify-js/-/uglify-js-1.3.4.tgz
npm http 200 https://registry.npmjs.org/uglify-js/-/uglify-js-1.3.4.tgz
uglify-js@1.3.4 node_modules/uglify-js
localhost:Downloads makc$ node
> var uglify = require('uglify-js');
undefined
> var ast = uglify.parser.parse('a.b;a.b(c);',false,true);
undefined
> ast[1][1][1]
[ { name: 'call',
    start: 
     { type: 'name',
       value: 'a',
       line: 0,
       col: 4,
       pos: 4,
       endpos: 5,
       nlb: false,
       comments_before: [] },
    end: 
     { type: 'punc',
       value: ')',
       line: 0,
       col: 9,
       pos: 9,
       endpos: 10,
       nlb: false,
       comments_before: [] } },
  [ 'dot',
    [ 'name', 'a' ],
    'b' ],
  [ [ [Object], 'c' ] ] ]
> 

so you would need to upgrade to something newer than 1.3.4 (#11) in order to fix this :disappointed:

@makc

with OP 'd=a+b',

> var ast = uglify.parser.parse('d=a+b',false,true);
undefined
> ast[1][0][1][2]
[ { name: 'name',
    start: 
     { type: 'name',
       value: 'd',
       line: 0,
       col: 0,
       pos: 0,
       endpos: 1,
       nlb: false,
       comments_before: [] },
    end: 
     { type: 'name',
       value: 'd',
       line: 0,
       col: 0,
       pos: 0,
       endpos: 1,
       nlb: false,
       comments_before: [] } },
  'd' ]
> ast[1][0][1][3]
[ 'binary',
  '+',
  [ { name: 'name',
      start: [Object],
      end: [Object] },
    'a' ],
  [ { name: 'name',
      start: [Object],
      end: [Object] },
    'b' ] ]
@makc

this still the same in 1.3.5 (currently latest 1.x) :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.