New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor private name tokenizing #13256
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cb7ab80
add benchmark
JLHwung 203d1ab
refactor: create tt.privateName token for private names
JLHwung 94d0ae6
add backward compat privateName = hash + name to Babel 7
JLHwung 6708d82
perf: get private name SV from token value
JLHwung 97a2f60
chore: tweak benchmark file
JLHwung 97e08dc
chore: update test fixtures
JLHwung 1f65f5e
convert tt.privateName to PrivateIdentifier
JLHwung 56d64f1
perf: avoid most isPrivateName call
JLHwung 0b49227
Update packages/babel-parser/src/parser/expression.js
JLHwung 7f3d99e
perf: use inlinable codePointAtPos
JLHwung 52f533d
make prettier happy
JLHwung File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
packages/babel-parser/benchmark/many-class-private-properties/1-length.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,34 @@ | ||
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(); | ||
// All codepoints in [0x4e00, 0x9ffc] are valid identifier name per Unicode 13 | ||
function createInput(length) { | ||
if (length > 0x9ffc - 0x4e00) { | ||
throw new Error( | ||
`Length greater than ${ | ||
0x9ffc - 0x4e00 | ||
} is not supported! Consider modify the \`createInput\`.` | ||
); | ||
} | ||
let source = "class C { "; | ||
for (let i = 0; i < length; i++) { | ||
source += "#" + String.fromCharCode(0x4e00 + i) + ";"; | ||
} | ||
return source + " }"; | ||
} | ||
function benchCases(name, implementation, options) { | ||
for (const length of [256, 512, 1024, 2048]) { | ||
const input = createInput(length); | ||
suite.add(`${name} ${length} length-1 private properties`, () => { | ||
implementation.parse(input, options); | ||
}); | ||
} | ||
} | ||
|
||
benchCases("baseline", baseline); | ||
benchCases("current", current); | ||
|
||
suite.on("cycle", report).run(); |
19 changes: 19 additions & 0 deletions
19
packages/babel-parser/benchmark/many-empty-statements/attachComment-false.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,19 @@ | ||
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 benchCases(name, implementation, options) { | ||
for (const length of [256, 512, 1024, 2048]) { | ||
suite.add(`${name} ${length} empty statement`, () => { | ||
implementation.parse(";".repeat(length), options); | ||
}); | ||
} | ||
} | ||
|
||
benchCases("baseline", baseline); | ||
benchCases("current + attachComment: false", current, { attachComment: false }); | ||
|
||
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,13 @@ | ||
export function report(event) { | ||
const bench = event.target; | ||
const factor = bench.hz < 100 ? 100 : 1; | ||
const timeMs = bench.stats.mean * 1000; | ||
const time = | ||
timeMs < 10 | ||
? `${Math.round(timeMs * 1000) / 1000}ms` | ||
: `${Math.round(timeMs)}ms`; | ||
const msg = `${bench.name}: ${ | ||
Math.round(bench.hz * factor) / factor | ||
} ops/sec ±${Math.round(bench.stats.rme * 100) / 100}% (${time})`; | ||
console.log(msg); | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We convert
tt.privateName
toPrivateIdentifier
, which aligns to eslint/espree#486Note that although this PR merges
tt.hash
andtt.name
tott.privateName
, this behaviour will be not observed by@babel/eslint-parsers
because of the compat layer. However if we run withBABEL_8_BREAKING=true
, the eslint parser will seett.privateName
, instead of breakingtt.privateName
, we align it to the new espree behaviour.