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 readLineBreak() #5783

Merged
merged 1 commit into from
Aug 22, 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
41 changes: 20 additions & 21 deletions yaml/_loader_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,23 @@

return result;
}
readLineBreak() {
const ch = this.peek();

if (ch === LINE_FEED) {
this.position++;
} else if (ch === CARRIAGE_RETURN) {
this.position++;
if (this.peek() === LINE_FEED) {
this.position++;
}
} else {
return this.throwError("a line break is expected");
}

Check warning on line 465 in yaml/_loader_state.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_loader_state.ts#L464-L465

Added lines #L464 - L465 were not covered by tests

this.line += 1;
this.lineStart = this.position;
}

readDocument() {
const documentStart = this.position;
Expand Down Expand Up @@ -513,7 +530,7 @@
directiveArgs.push(this.input.slice(position, this.position));
}

if (ch !== 0) readLineBreak(this);
if (ch !== 0) this.readLineBreak();

switch (directiveName) {
case "YAML":
Expand Down Expand Up @@ -577,24 +594,6 @@
}
}

function readLineBreak(state: LoaderState) {
const ch = state.peek();

if (ch === LINE_FEED) {
state.position++;
} else if (ch === CARRIAGE_RETURN) {
state.position++;
if (state.peek() === LINE_FEED) {
state.position++;
}
} else {
return state.throwError("a line break is expected");
}

state.line += 1;
state.lineStart = state.position;
}

function skipSeparationSpace(
state: LoaderState,
allowComments: boolean,
Expand All @@ -615,7 +614,7 @@
}

if (isEOL(ch)) {
readLineBreak(state);
state.readLineBreak();

ch = state.peek();
lineBreaks++;
Expand Down Expand Up @@ -1085,7 +1084,7 @@
}

while (ch !== 0) {
readLineBreak(state);
state.readLineBreak();
state.lineIndent = 0;

ch = state.peek();
Expand Down