Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking: remove attachComment #405

Merged
merged 3 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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