-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
22 changed files
with
1,006 additions
and
175 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
benchmark/babel-parser/many-nested-block-elements/bench.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
25 changes: 25 additions & 0 deletions
25
benchmark/babel-parser/many-nested-jsx-elements-with-attributes/bench.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
22 changes: 22 additions & 0 deletions
22
benchmark/babel-parser/many-nested-template-elements/bench.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.