Skip to content
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(yaml): inline writeFoldedLines() #5812

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions yaml/_loader_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,13 @@

return false;
}
writeFoldedLines(count: number) {
if (count === 1) {
this.result += " ";
} else if (count > 1) {
this.result += "\n".repeat(count - 1);
}

Check warning on line 581 in yaml/_loader_state.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_loader_state.ts#L580-L581

Added lines #L580 - L581 were not covered by tests
}

readDocument() {
const documentStart = this.position;
Expand Down Expand Up @@ -700,14 +707,6 @@
}
}

function writeFoldedLines(state: LoaderState, count: number) {
if (count === 1) {
state.result += " ";
} else if (count > 1) {
state.result += "\n".repeat(count - 1);
}
}

function readPlainScalar(
state: LoaderState,
nodeIndent: number,
Expand Down Expand Up @@ -795,7 +794,7 @@

if (hasPendingContent) {
state.captureSegment(captureStart, captureEnd, false);
writeFoldedLines(state, state.line - line);
state.writeFoldedLines(state.line - line);

Check warning on line 797 in yaml/_loader_state.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_loader_state.ts#L797

Added line #L797 was not covered by tests
captureStart = captureEnd = state.position;
hasPendingContent = false;
}
Expand Down Expand Up @@ -851,7 +850,7 @@
}
} else if (isEOL(ch)) {
state.captureSegment(captureStart, captureEnd, true);
writeFoldedLines(state, state.skipSeparationSpace(false, nodeIndent));
state.writeFoldedLines(state.skipSeparationSpace(false, nodeIndent));
captureStart = captureEnd = state.position;
} else if (
state.position === state.lineStart &&
Expand Down Expand Up @@ -926,7 +925,7 @@
captureStart = captureEnd = state.position;
} else if (isEOL(ch)) {
state.captureSegment(captureStart, captureEnd, true);
writeFoldedLines(state, state.skipSeparationSpace(false, nodeIndent));
state.writeFoldedLines(state.skipSeparationSpace(false, nodeIndent));
captureStart = captureEnd = state.position;
} else if (
state.position === state.lineStart &&
Expand Down