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 readAnchorProperty() #5853

Merged
merged 1 commit into from
Aug 28, 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
53 changes: 26 additions & 27 deletions yaml/_loader_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,31 @@

return true;
}
readAnchorProperty(): boolean {
let ch = this.peek();
if (ch !== AMPERSAND) return false;

if (this.anchor !== null) {
return this.throwError(
"Cannot read anchor property: duplicate anchor property",

Check warning on line 1386 in yaml/_loader_state.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_loader_state.ts#L1385-L1386

Added lines #L1385 - L1386 were not covered by tests
);
}
ch = this.next();

const position = this.position;
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
ch = this.next();
}

if (this.position === position) {
return this.throwError(
"Cannot read anchor property: name of an anchor node must contain at least one character",

Check warning on line 1398 in yaml/_loader_state.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_loader_state.ts#L1397-L1398

Added lines #L1397 - L1398 were not covered by tests
);
}

this.anchor = this.input.slice(position, this.position);
return true;
}

readDocument() {
const documentStart = this.position;
Expand Down Expand Up @@ -1506,32 +1531,6 @@
}
}

function readAnchorProperty(state: LoaderState): boolean {
let ch = state.peek();
if (ch !== AMPERSAND) return false;

if (state.anchor !== null) {
return state.throwError(
"Cannot read anchor property: duplicate anchor property",
);
}
ch = state.next();

const position = state.position;
while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
ch = state.next();
}

if (state.position === position) {
return state.throwError(
"Cannot read anchor property: name of an anchor node must contain at least one character",
);
}

state.anchor = state.input.slice(position, state.position);
return true;
}

function readAlias(state: LoaderState): boolean {
if (state.peek() !== ASTERISK) return false;

Expand Down Expand Up @@ -1599,7 +1598,7 @@
}

if (indentStatus === 1) {
while (state.readTagProperty() || readAnchorProperty(state)) {
while (state.readTagProperty() || state.readAnchorProperty()) {
if (state.skipSeparationSpace(true, -1)) {
atNewLine = true;
allowBlockCollections = allowBlockStyles;
Expand Down