push comments to token stream to avoid having to re-sort - #1486

This commit is contained in:
Sebastian McKenzie
2015-05-31 09:16:27 +01:00
parent 07a992e6d3
commit 82a0851526
2 changed files with 15 additions and 1 deletions

View File

@@ -22,7 +22,7 @@ function getLookupIndex(i, base, max) {
export default class Whitespace {
constructor(tokens, comments) {
this.tokens = sortBy(tokens.concat(comments), "start");
this.tokens = tokens;
this.used = {};
// Profiling this code shows that while generator passes over it, indexes

View File

@@ -21,6 +21,20 @@ export default function (code, opts = {}) {
ranges: true
};
parseOpts.onComment = return function (block, text, start, end, startLoc, endLoc) {
var comment = {
type: block ? "Block" : "Line",
value: text,
start: start,
end: end,
loc: new acorn.SourceLocation(this, startLoc, endLoc),
range: [start, end]
};
tokens.push(comment);
comments.push(comment);
};
if (opts.nonStandard) {
parseOpts.plugins.jsx = true;
parseOpts.plugins.flow = true;