Skip to content

refactor(yaml): declare-on-use variables #6594

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

Merged
merged 5 commits into from
Apr 23, 2025
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
83 changes: 40 additions & 43 deletions yaml/_loader_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,8 @@
this.tagMap.set(handle, prefix);
}
captureSegment(start: number, end: number, checkJson: boolean) {
let result: string;
if (start < end) {
result = this.input.slice(start, end);
const result = this.input.slice(start, end);

if (checkJson) {
for (
Expand All @@ -356,10 +355,8 @@
}
}
readBlockSequence(nodeIndent: number): boolean {
let line: number;
let following: number;
let detected = false;
let ch: number;

const tag = this.tag;
const anchor = this.anchor;
const result: unknown[] = [];
Expand All @@ -368,14 +365,14 @@
this.anchorMap.set(this.anchor, result);
}

ch = this.peek();
let ch = this.peek();

while (ch !== 0) {
if (ch !== MINUS) {
break;
}

following = this.peek(1);
const following = this.peek(1);

if (!isWhiteSpaceOrEOL(following)) {
break;
Expand All @@ -392,7 +389,7 @@
}
}

line = this.line;
const line = this.line;
this.composeNode(nodeIndent, CONTEXT_BLOCK_IN, false, true);
result.push(this.result);
this.skipSeparationSpace(true, -1);
Expand Down Expand Up @@ -700,11 +697,7 @@
return false;
}
readSingleQuotedScalar(nodeIndent: number): boolean {
let ch;
let captureStart;
let captureEnd;

ch = this.peek();
let ch = this.peek();

if (ch !== SINGLE_QUOTE) {
return false;
Expand All @@ -713,9 +706,11 @@
this.kind = "scalar";
this.result = "";
this.position++;
captureStart = captureEnd = this.position;
let captureStart = this.position;
let captureEnd = this.position;

while ((ch = this.peek()) !== 0) {
ch = this.peek();
while (ch !== 0) {
if (ch === SINGLE_QUOTE) {
this.captureSegment(captureStart, this.position, true);
ch = this.next();
Expand All @@ -742,6 +737,7 @@
this.position++;
captureEnd = this.position;
}
ch = this.peek();
}

throw this.#createError(
Expand All @@ -761,7 +757,8 @@
let captureEnd = this.position;
let captureStart = this.position;
let tmp: number;
while ((ch = this.peek()) !== 0) {
ch = this.peek();
while (ch !== 0) {
if (ch === DOUBLE_QUOTE) {
this.captureSegment(captureStart, this.position, true);
this.position++;
Expand Down Expand Up @@ -817,6 +814,7 @@
this.position++;
captureEnd = this.position;
}
ch = this.peek();
}

throw this.#createError(
Expand Down Expand Up @@ -1099,7 +1097,7 @@
const anchor = this.anchor;
const result = {};
const overridableKeys = new Set<string>();
let following: number;

let allowCompact = false;
let line: number;
let pos: number;
Expand All @@ -1108,16 +1106,15 @@
let valueNode = null;
let atExplicitKey = false;
let detected = false;
let ch: number;

if (this.anchor !== null && typeof this.anchor !== "undefined") {
this.anchorMap.set(this.anchor, result);
}

ch = this.peek();
let ch = this.peek();

while (ch !== 0) {
following = this.peek(1);
const following = this.peek(1);
line = this.line; // Save the current line.
pos = this.position;

Expand All @@ -1135,7 +1132,9 @@
keyNode,
null,
);
keyTag = keyNode = valueNode = null;
keyTag = null;
keyNode = null;
valueNode = null;
}

detected = true;
Expand Down Expand Up @@ -1182,7 +1181,9 @@
keyNode,
null,
);
keyTag = keyNode = valueNode = null;
keyTag = null;
keyNode = null;
valueNode = null;

Check warning on line 1186 in yaml/_loader_state.ts

View check run for this annotation

Codecov / codecov/patch

yaml/_loader_state.ts#L1184-L1186

Added lines #L1184 - L1186 were not covered by tests
}

detected = true;
Expand Down Expand Up @@ -1278,14 +1279,12 @@
return detected;
}
readTagProperty(): boolean {
let position: number;
let isVerbatim = false;
let isNamed = false;
let tagHandle = "";
let tagName: string;
let ch: number;

ch = this.peek();
let ch = this.peek();

if (ch !== EXCLAMATION) return false;

Expand All @@ -1308,7 +1307,7 @@
tagHandle = "!";
}

position = this.position;
let position = this.position;

if (isVerbatim) {
do {
Expand Down Expand Up @@ -1438,23 +1437,21 @@
allowToSeek: boolean,
allowCompact: boolean,
): boolean {
let allowBlockScalars: boolean;
let allowBlockCollections: boolean;
let indentStatus = 1; // 1: this>parent, 0: this=parent, -1: this<parent
let atNewLine = false;
let hasContent = false;
let type: Type<KindType>;
let flowIndent: number;
let blockIndent: number;

this.tag = null;
this.anchor = null;
this.kind = null;
this.result = null;

const allowBlockStyles = (allowBlockScalars =
allowBlockCollections =
CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext);
const allowBlockScalars = CONTEXT_BLOCK_OUT === nodeContext ||
CONTEXT_BLOCK_IN === nodeContext;

let allowBlockCollections = allowBlockScalars;
const allowBlockStyles = allowBlockScalars;

if (allowToSeek) {
if (this.skipSeparationSpace(true, -1)) {
Expand Down Expand Up @@ -1496,9 +1493,9 @@
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
const cond = CONTEXT_FLOW_IN === nodeContext ||
CONTEXT_FLOW_OUT === nodeContext;
flowIndent = cond ? parentIndent : parentIndent + 1;
const flowIndent = cond ? parentIndent : parentIndent + 1;

blockIndent = this.position - this.lineStart;
const blockIndent = this.position - this.lineStart;

if (indentStatus === 1) {
if (
Expand Down Expand Up @@ -1599,18 +1596,16 @@

readDocument() {
const documentStart = this.position;
let position: number;
let directiveName: string;
let directiveArgs: string[];

let hasDirectives = false;
let ch: number;

this.version = null;
this.checkLineBreaks = false;
this.tagMap = new Map();
this.anchorMap = new Map();

while ((ch = this.peek()) !== 0) {
let ch = this.peek();
while (ch !== 0) {
this.skipSeparationSpace(true, -1);

ch = this.peek();
Expand All @@ -1621,14 +1616,14 @@

hasDirectives = true;
ch = this.next();
position = this.position;
let position = this.position;

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

directiveName = this.input.slice(position, this.position);
directiveArgs = [];
const directiveName = this.input.slice(position, this.position);
const directiveArgs = [];

if (directiveName.length < 1) {
throw this.#createError(
Expand Down Expand Up @@ -1670,6 +1665,8 @@
);
break;
}

ch = this.peek();
}

this.skipSeparationSpace(true, -1);
Expand Down
Loading