Skip to content

Commit

Permalink
Breaking: remove attachComment (#405)
Browse files Browse the repository at this point in the history
* Turn off comment attachment for lib tests

* Remove attachComment

* Update readme
  • Loading branch information
kaicataldo authored Dec 5, 2018
1 parent 35623ee commit 1bcd563
Show file tree
Hide file tree
Showing 54 changed files with 23 additions and 8,660 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ Espree started out as a fork of [Esprima](http://esprima.org) v1.2.2, the last s
Install:

```
npm i espree --save
npm i espree
```

And in your Node.js code:

```javascript
var espree = require("espree");
const espree = require("espree");

var ast = espree.parse(code);
const ast = espree.parse(code);
```

There is a second argument to `parse()` that allows you to specify various options:

```javascript
var espree = require("espree");
const espree = require("espree");

// Optional second options argument with the following default settings
var ast = espree.parse(code, {
const ast = espree.parse(code, {

// attach range information to each node
range: false,
Expand All @@ -40,9 +40,6 @@ var ast = espree.parse(code, {
// create a top-level comments array containing all comments
comment: false,

// attach comments to the closest relevant node as leadingComments and trailingComments
attachComment: false,

// create a top-level tokens array containing all tokens
tokens: false,

Expand Down
176 changes: 0 additions & 176 deletions lib/comment-attachment.js

This file was deleted.

17 changes: 2 additions & 15 deletions lib/espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
/* eslint-disable no-param-reassign*/
const acorn = require("acorn");
const jsx = require("acorn-jsx");
const commentAttachment = require("./comment-attachment");
const TokenTranslator = require("./token-translator");

const DEFAULT_ECMA_VERSION = 5;
Expand Down Expand Up @@ -98,7 +97,7 @@ module.exports = () => Parser => class Espree extends Parser {
super({
ecmaVersion: isModule ? Math.max(6, ecmaVersion) : ecmaVersion,
sourceType: isModule ? "module" : "script",
ranges: options.range === true || options.attachComment === true,
ranges: options.range === true,
locations: options.loc === true,

// Truthy value is true for backward compatibility.
Expand All @@ -122,22 +121,14 @@ module.exports = () => Parser => class Espree extends Parser {
const comment = convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc);

this[STATE].comments.push(comment);

if (options.attachComment === true) {
commentAttachment.addComment(comment);
}
}
}
}, code);

// TODO: remove global state.
commentAttachment.reset();

// Initialize internal state.
this[STATE] = {
tokens: tokenTranslator ? [] : null,
comments: options.comment === true || options.attachComment === true ? [] : null,
attachComment: options.attachComment === true,
comments: options.comment === true ? [] : null,
impliedStrict: ecmaFeatures.impliedStrict === true && this.options.ecmaVersion >= 5,
ecmaVersion: this.options.ecmaVersion,
jsxAttrValueToken: false,
Expand Down Expand Up @@ -309,10 +300,6 @@ module.exports = () => Parser => class Espree extends Parser {
}
}

if (this[STATE].attachComment) {
commentAttachment.processComment(result);
}

if (result.type.indexOf("Function") > -1 && !result.generator) {
result.generator = false;
}
Expand Down
Loading

0 comments on commit 1bcd563

Please sign in to comment.