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): merge yaml/_loader/ files #5259

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
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
59 changes: 54 additions & 5 deletions yaml/_loader/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ import {
} from "../_chars.ts";
import { YamlError } from "../_error.ts";
import { Mark } from "../_mark.ts";
import type { Schema, TypeMap } from "../_schema.ts";
import { State } from "../_state.ts";
import type { Type } from "../_type.ts";
import * as common from "../_utils.ts";
import {
LoaderState,
type LoaderStateOptions,
type ResultType,
} from "./loader_state.ts";

type Any = common.Any;
type ArrayObject<T = Any> = common.ArrayObject<T>;
Expand All @@ -63,6 +60,58 @@ const PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
const PATTERN_TAG_URI =
/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;

interface LoaderStateOptions {
/** specifies a schema to use. */
schema?: Schema;
/** compatibility with JSON.parse behaviour. */
json?: boolean;
/** function to call on warning messages. */
onWarning?(this: null, e?: YamlError): void;
}

// deno-lint-ignore no-explicit-any
type ResultType = any[] | Record<string, any> | string;

class LoaderState extends State {
input: string;
documents: Any[] = [];
length: number;
lineIndent = 0;
lineStart = 0;
position = 0;
line = 0;
onWarning?: (...args: Any[]) => void;
json: boolean;
implicitTypes: Type[];
typeMap: TypeMap;

version?: string | null;
checkLineBreaks = false;
tagMap: ArrayObject = Object.create(null);
anchorMap: ArrayObject = Object.create(null);
tag?: string | null;
anchor?: string | null;
kind?: string | null;
result: ResultType | null = "";

constructor(
input: string,
{
schema,
onWarning,
json = false,
}: LoaderStateOptions,
) {
super(schema);
this.input = input;
this.onWarning = onWarning;
this.json = json;
this.implicitTypes = this.schema.compiledImplicit;
this.typeMap = this.schema.compiledTypeMap;
this.length = input.length;
}
}

function _class(obj: unknown): string {
return Object.prototype.toString.call(obj);
}
Expand Down
62 changes: 0 additions & 62 deletions yaml/_loader/loader_state.ts

This file was deleted.