Add attachComment parser option to disable comment attachment (#13229)

This commit is contained in:
Huáng Jùnliàng
2021-08-04 11:04:22 -04:00
committed by GitHub
parent fc3b09e533
commit d5b0d9e33d
11 changed files with 274 additions and 18 deletions

View File

@@ -7,13 +7,14 @@ const suite = new Benchmark.Suite();
function benchCases(name, implementation, options) {
for (const length of [256, 512, 1024, 2048]) {
const input = ";".repeat(length);
suite.add(`${name} ${length} empty statement`, () => {
implementation.parse(";".repeat(length), options);
implementation.parse(input, options);
});
}
}
benchCases("baseline", baseline);
benchCases("baseline", baseline, { attachComment: true });
benchCases("current + attachComment: false", current, { attachComment: false });
suite.on("cycle", report).run();

View File

@@ -0,0 +1,28 @@
import Benchmark from "benchmark";
import baseline from "@babel-baseline/parser";
import current from "../../lib/index.js";
import { report } from "../util.mjs";
const suite = new Benchmark.Suite();
function createInput(length) {
return "\n// c\na".repeat(length);
}
function benchCases(name, implementation, options) {
for (const length of [256, 512, 1024, 2048]) {
const input = createInput(length);
const { parse } = implementation;
suite.add(
`${name} ${length} leading comments + ${length - 1} trailing comments`,
() => {
parse(input, options);
}
);
}
}
benchCases("baseline", baseline, { attachComment: true });
benchCases("current + attachComment: false", current, { attachComment: false });
suite.on("cycle", report).run();

View File

@@ -7,7 +7,7 @@ const suite = new Benchmark.Suite();
function createInput(length) {
return "\n// c\na".repeat(length);
}
current.parse(createInput(256), {});
function benchCases(name, implementation, options) {
for (const length of [128, 256, 512, 1024]) {
const input = createInput(length);