push comments to token stream to avoid having to re-sort - #1486
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user