GithubHelp home page GithubHelp logo

syntax-tree / estree-util-attach-comments Goto Github PK

View Code? Open in Web Editor NEW
7.0 9.0 4.0 92 KB

utility to attach comments to estree nodes

License: MIT License

JavaScript 100.00%
estree ast javascript ecmascript

estree-util-attach-comments's People

Contributors

aminya avatar christianmurphy avatar wooorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

estree-util-attach-comments's Issues

Ignores the leading/trailing properties of the comments

There is a bug in the plugin which results in generating the wrong node.

The input code

/**
 * Draws lines on the corresponding layer.
 * @param  {number} firstRow the first row to render
 */
function drawLines(
  firstRow,
) {
  console.log("x")
}

Gives the following with Espree 4's attach comment (notice the leadingComments property in body)

Node {
  type: 'Program',
  start: 0,
  end: 170,
  range: [ 108, 168 ],
  body: [
    Node {
      type: 'FunctionDeclaration',
      start: 108,
      end: 168,
      range: [Array],
      id: [Node],
      expression: false,
      generator: false,
      async: false,
      params: [Array],
      body: [Node],
      leadingComments: [Array]
    }
  ],
  sourceType: 'module',
  comments: [
    {
      type: 'Block',
      value: '*\r\n' +
        ' * Draws lines on the corresponding layer.\r\n' +
        ' * @param  {number} firstRow the first row to render\r\n' +
        ' ',
      start: 0,
      end: 106,
      range: [Array]
    }
  ]
}

But using Espree 7 and this package we get the following. estree-util-attach-comments ignores leading property

  type: 'Program',
  start: 0,
  end: 170,
  body: [
    Node {
      type: 'FunctionDeclaration',
      start: 108,
      end: 168,
      id: [Node],
      expression: false,
      generator: false,
      async: false,
      params: [Array],
      body: [Node]
    }
  ],
  sourceType: 'module',
  comments: [
    {
      type: 'Block',
      value: '*\r\n' +
        ' * Draws lines on the corresponding layer.\r\n' +
        ' * @param  {number} firstRow the first row to render\r\n' +
        ' ',
      start: 0,
      end: 106,
      range: [Array],
      leading: true,
      trailing: false
    }
  ]
}

CJS output

The package doesn't include a CJS output. Could you add that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.