Improve template tokenizing (#13919)
* add benchmarks * refactor: tokenize template as middle + tail * perf: avoid push tc.brace * refactor: overwrite skipSpace in jsx plugin * transform tl.templateMiddle/Tail * refactor: simplify JSX context tracking * fix flow error * refactor: move JSX context to context.js * fix: ensure comment stack is correctly handled * rename createPositionFromPosition * rename token type and methods * add tokenIsTemplate * refactor: merge babel 7 logic in babel7CompatTokens * fix flow error
This commit is contained in:
22
benchmark/babel-parser/many-nested-block-elements/bench.mjs
Normal file
22
benchmark/babel-parser/many-nested-block-elements/bench.mjs
Normal file
@@ -0,0 +1,22 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "{".repeat(length) + "0" + "}".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested template elements`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -0,0 +1,25 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "<t a={x}>{y}".repeat(length) + "</t>".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(
|
||||
`${name} ${length} nested jsx elements with one attribute and text`,
|
||||
() => {
|
||||
implementation.parse(input, options);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline, { plugins: ["jsx"] });
|
||||
benchCases("current", current, { plugins: ["jsx"] });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -0,0 +1,22 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "` ${".repeat(length) + "0" + "}`".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested template elements`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
23
benchmark/babel-parser/many-template-elements/bench.mjs
Normal file
23
benchmark/babel-parser/many-template-elements/bench.mjs
Normal file
@@ -0,0 +1,23 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/parser";
|
||||
import current from "@babel/parser";
|
||||
import { report } from "../../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "`" + " ${0}".repeat(length) + "`";
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} template elements`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
current.parse(createInput(1));
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
Reference in New Issue
Block a user