Skip to content

Commit 8619be5

Browse files
committed
format
1 parent 8c4f63c commit 8619be5

File tree

5 files changed

+52
-47
lines changed

5 files changed

+52
-47
lines changed

bench/perf/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const saxPath = new URL('../../test/data/sax/', import.meta.url);
1515

1616
//HACK: https://github.com/bestiejs/benchmark.js/issues/51
1717
/* global workingCopy, WorkingCopyParserStream, upstreamParser, hugePage, microTests, runMicro, runPages, files */
18-
global.workingCopy = parse5;
19-
global.WorkingCopyParserStream = parse5Stream;
20-
global.upstreamParser = parse5Upstream;
18+
globalThis.workingCopy = parse5;
19+
globalThis.WorkingCopyParserStream = parse5Stream;
20+
globalThis.upstreamParser = parse5Upstream;
2121

2222
// Huge page data
23-
global.hugePage = readFileSync(hugePagePath).toString();
23+
globalThis.hugePage = readFileSync(hugePagePath).toString();
2424

2525
// Micro data
26-
global.microTests = loadTreeConstructionTestData(treeConstructionPath, treeAdapters.default)
26+
globalThis.microTests = loadTreeConstructionTestData(treeConstructionPath, treeAdapters.default)
2727
.filter(
2828
(test) =>
2929
//NOTE: this test caused a stack overflow in parse5 v1.x
@@ -34,7 +34,7 @@ global.microTests = loadTreeConstructionTestData(treeConstructionPath, treeAdapt
3434
fragmentContext: test.fragmentContext,
3535
}));
3636

37-
global.runMicro = function (parser) {
37+
globalThis.runMicro = function (parser) {
3838
for (const test of microTests) {
3939
if (test.fragmentContext) {
4040
parser.parseFragment(test.fragmentContext, test.html);
@@ -47,14 +47,14 @@ global.runMicro = function (parser) {
4747
// Pages data
4848
const pages = loadSAXParserTestData().map((test) => test.src);
4949

50-
global.runPages = function (parser) {
50+
globalThis.runPages = function (parser) {
5151
for (const page of pages) {
5252
parser.parse(page);
5353
}
5454
};
5555

5656
// Stream data
57-
global.files = readdirSync(saxPath).map((dirName) => new URL(`${dirName}/src.html`, saxPath).pathname);
57+
globalThis.files = readdirSync(saxPath).map((dirName) => new URL(`${dirName}/src.html`, saxPath).pathname);
5858

5959
// Utils
6060
function getHz(suite, testName) {

package-lock.json

Lines changed: 35 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/parse5/lib/parser/formatting-element-list.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class FormattingElementList<T extends TreeAdapterTypeMap> {
122122
removeEntry(entry: Entry<T>): void {
123123
const entryIndex = this.entries.indexOf(entry);
124124

125-
if (entryIndex >= 0) {
125+
if (entryIndex !== -1) {
126126
this.entries.splice(entryIndex, 1);
127127
}
128128
}
@@ -135,10 +135,10 @@ export class FormattingElementList<T extends TreeAdapterTypeMap> {
135135
clearToLastMarker(): void {
136136
const markerIdx = this.entries.indexOf(MARKER);
137137

138-
if (markerIdx >= 0) {
139-
this.entries.splice(0, markerIdx + 1);
140-
} else {
138+
if (markerIdx === -1) {
141139
this.entries.length = 0;
140+
} else {
141+
this.entries.splice(0, markerIdx + 1);
142142
}
143143
}
144144

packages/parse5/lib/parser/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ export class Parser<T extends TreeAdapterTypeMap> implements TokenHandler, Stack
643643
(entry) => entry.type === EntryType.Marker || this.openElements.contains(entry.element),
644644
);
645645

646-
const unopenIdx = endIndex < 0 ? listLength - 1 : endIndex - 1;
646+
const unopenIdx = endIndex === -1 ? listLength - 1 : endIndex - 1;
647647

648648
for (let i = unopenIdx; i >= 0; i--) {
649649
const entry = this.activeFormattingElements.entries[i] as ElementEntry<T>;
@@ -1419,7 +1419,7 @@ function aaObtainFurthestBlock<T extends TreeAdapterTypeMap>(
14191419
}
14201420

14211421
if (!furthestBlock) {
1422-
p.openElements.shortenToLength(idx < 0 ? 0 : idx);
1422+
p.openElements.shortenToLength(Math.max(idx, 0));
14231423
p.activeFormattingElements.removeEntry(formattingElementEntry);
14241424
}
14251425

packages/parse5/lib/parser/open-element-stack.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class OpenElementStack<T extends TreeAdapterTypeMap> {
136136
targetIdx = this.tagIDs.lastIndexOf(tagName, targetIdx - 1);
137137
} while (targetIdx > 0 && this.treeAdapter.getNamespaceURI(this.items[targetIdx]) !== NS.HTML);
138138

139-
this.shortenToLength(targetIdx < 0 ? 0 : targetIdx);
139+
this.shortenToLength(Math.max(targetIdx, 0));
140140
}
141141

142142
shortenToLength(idx: number): void {
@@ -156,12 +156,12 @@ export class OpenElementStack<T extends TreeAdapterTypeMap> {
156156

157157
popUntilElementPopped(element: T['element']): void {
158158
const idx = this._indexOf(element);
159-
this.shortenToLength(idx < 0 ? 0 : idx);
159+
this.shortenToLength(Math.max(idx, 0));
160160
}
161161

162162
private popUntilPopped(tagNames: Set<$>, targetNS: NS): void {
163163
const idx = this._indexOfTagNames(tagNames, targetNS);
164-
this.shortenToLength(idx < 0 ? 0 : idx);
164+
this.shortenToLength(Math.max(idx, 0));
165165
}
166166

167167
popUntilNumberedHeaderPopped(): void {

0 commit comments

Comments
 (0)