diff --git a/src/babel/generation/whitespace.js b/src/babel/generation/whitespace.js index a6b67d9633..f4cf563b47 100644 --- a/src/babel/generation/whitespace.js +++ b/src/babel/generation/whitespace.js @@ -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 diff --git a/src/babel/helpers/parse.js b/src/babel/helpers/parse.js index 74f80b2ff4..869bd21d71 100644 --- a/src/babel/helpers/parse.js +++ b/src/babel/helpers/parse.js @@ -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;