refactor(yaml): remove State class (#5275)

initial commit
This commit is contained in:
Tim Reichen 2024-07-03 09:37:13 +02:00 committed by GitHub
parent b775a956d1
commit 769cc02d71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 23 deletions

View File

@ -28,8 +28,7 @@ import {
VERTICAL_LINE,
} from "./_chars.ts";
import { YamlError } from "./_error.ts";
import type { Schema } from "./_schema.ts";
import { State } from "./_state.ts";
import { DEFAULT_SCHEMA, type Schema } from "./_schema.ts";
import type { RepresentFn, StyleVariant, Type } from "./_type.ts";
import * as common from "./_utils.ts";
@ -146,7 +145,8 @@ export interface DumperStateOptions {
condenseFlow?: boolean;
}
export class DumperState extends State {
export class DumperState {
schema: Schema;
indent: number;
noArrayIndent: boolean;
skipInvalid: boolean;
@ -166,7 +166,7 @@ export class DumperState extends State {
dump: Any;
constructor({
schema,
schema = DEFAULT_SCHEMA,
indent = 2,
noArrayIndent = false,
skipInvalid = false,
@ -178,7 +178,7 @@ export class DumperState extends State {
noCompatMode = false,
condenseFlow = false,
}: DumperStateOptions) {
super(schema);
this.schema = schema;
this.indent = Math.max(1, indent);
this.noArrayIndent = noArrayIndent;
this.skipInvalid = skipInvalid;

View File

@ -34,8 +34,7 @@ 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 { DEFAULT_SCHEMA, type Schema, type TypeMap } from "./_schema.ts";
import type { Type } from "./_type.ts";
import * as common from "./_utils.ts";
@ -72,7 +71,8 @@ interface LoaderStateOptions {
// deno-lint-ignore no-explicit-any
type ResultType = any[] | Record<string, any> | string;
class LoaderState extends State {
class LoaderState {
schema: Schema;
input: string;
length: number;
lineIndent = 0;
@ -96,12 +96,12 @@ class LoaderState extends State {
constructor(
input: string,
{
schema,
schema = DEFAULT_SCHEMA,
onWarning,
json = false,
}: LoaderStateOptions,
) {
super(schema);
this.schema = schema;
this.input = input;
this.onWarning = onWarning;
this.json = json;

View File

@ -1,13 +0,0 @@
// Ported from js-yaml v3.13.1:
// https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { DEFAULT_SCHEMA, type Schema } from "./_schema.ts";
export abstract class State {
schema: Schema;
constructor(schema: Schema = DEFAULT_SCHEMA) {
this.schema = schema;
}
}