Skip to content

Instantly share code, notes, and snippets.

@RReverser
Created March 14, 2017 10:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RReverser/e3ebe7c2fc419e64c6b5d5ddc3b95387 to your computer and use it in GitHub Desktop.
Save RReverser/e3ebe7c2fc419e64c6b5d5ddc3b95387 to your computer and use it in GitHub Desktop.
Acorn: top-level parsing experiment
// See https://jsperf.com/acorn-top-level-parsing-experiment/1 for example
acorn.plugins.top_level = function (instance) {
// Could skip other things as well, but this
// is where the most time can be saved
instance.parseBlock = function () {
var node = this.startNode();
var length = this.context.length;
do {
this.next();
} while (this.context.length >= length);
this.next(); // this.expect(tt.braceR);
node.body = [];
return this.finishNode(node, "BlockStatement");
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment