Skip to content
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"license": "MIT",
"scripts": {
"prepublish": "patch-package && yarn run build",
"prepublish": "yarn run build",
"lint": "run-p \"lint:*\"",
"lint:eslint": "eslint .",
"lint:prettier": "prettier . --check",
Expand All @@ -35,7 +35,7 @@
"release": "yarn build && standard-version"
},
"dependencies": {
"yaml": "^1.10.2"
"yaml": "^2.8.1"
},
"devDependencies": {
"@eslint/js": "9.39.1",
Expand Down
79 changes: 0 additions & 79 deletions patches/yaml+1.10.2.patch

This file was deleted.

193 changes: 98 additions & 95 deletions src/__snapshots__/yaml-test-suite.test.ts.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function attachComment(

const { trailingAttachableNode } = nodeTable[commentLine - 1];
if (trailingAttachableNode) {
// istanbul ignore next
// istanbul ignore if -- @preserve
if (trailingAttachableNode.trailingComment) {
throw new Error(
`Unexpected multiple trailing comment at ${getPointText(
Expand Down
5 changes: 0 additions & 5 deletions src/constants.ts

This file was deleted.

118 changes: 118 additions & 0 deletions src/cst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import type * as YAML from "yaml";

// Subdivide YAML.CST.SourceToken
export type SpaceSourceToken = YAML.CST.SourceToken & {
type: "space" | "newline";
};
export type CommentSourceToken = YAML.CST.SourceToken & { type: "comment" };
export type DocStartSourceToken = YAML.CST.SourceToken & { type: "doc-start" };
export type TagSourceToken = YAML.CST.SourceToken & { type: "tag" };
export type AnchorSourceToken = YAML.CST.SourceToken & { type: "anchor" };
export type SeqItemIndSourceToken = YAML.CST.SourceToken & {
type: "seq-item-ind";
};
export type ExplicitKeyIndSourceToken = YAML.CST.SourceToken & {
type: "explicit-key-ind";
};
export type MapValueIndSourceToken = YAML.CST.SourceToken & {
type: "map-value-ind";
};
export type FlowMapEndSourceToken = YAML.CST.SourceToken & {
type: "flow-map-end";
};
export type FlowSeqEndSourceToken = YAML.CST.SourceToken & {
type: "flow-seq-end";
};
export type CommaSourceToken = YAML.CST.SourceToken & { type: "comma" };
export type BlockScalarHeaderSourceToken = YAML.CST.SourceToken & {
type: "block-scalar-header";
};
export type OtherSourceToken = YAML.CST.SourceToken & {
type: Exclude<
YAML.CST.SourceToken["type"],
(
| SpaceSourceToken
| CommentSourceToken
| DocStartSourceToken
| TagSourceToken
| AnchorSourceToken
| SeqItemIndSourceToken
| ExplicitKeyIndSourceToken
| MapValueIndSourceToken
| FlowMapEndSourceToken
| FlowSeqEndSourceToken
| CommaSourceToken
| BlockScalarHeaderSourceToken
)["type"]
>;
};
export type SourceToken =
| CommentSourceToken
| DocStartSourceToken
| TagSourceToken
| AnchorSourceToken
| SeqItemIndSourceToken
| ExplicitKeyIndSourceToken
| MapValueIndSourceToken
| FlowMapEndSourceToken
| FlowSeqEndSourceToken
| CommaSourceToken
| BlockScalarHeaderSourceToken
| OtherSourceToken;

// Subdivide YAML.CST.FlowScalar
export type DoubleQuotedFlowScalar = YAML.CST.FlowScalar & {
type: "double-quoted-scalar";
};
export type SingleQuotedFlowScalar = YAML.CST.FlowScalar & {
type: "single-quoted-scalar";
};
export type OtherFlowScalar = YAML.CST.FlowScalar & {
type: Exclude<
YAML.CST.FlowScalar["type"],
(DoubleQuotedFlowScalar | SingleQuotedFlowScalar)["type"]
>;
};
export type FlowScalar =
| DoubleQuotedFlowScalar
| SingleQuotedFlowScalar
| OtherFlowScalar;

/**
* Generator to iterate over tokens, skipping space and newline tokens.
*/
export function* tokens<T extends YAML.CST.Token>(
...tokensArgs: (Iterable<T> | undefined)[]
): Iterable<Exclude<T, YAML.CST.SourceToken> | SourceToken> {
for (const tokens of tokensArgs) {
if (!tokens) continue;
for (const token of tokens) {
if (isSpace(token)) continue;
yield token as Exclude<T, YAML.CST.SourceToken> | SourceToken;
}
}
}

/**
* Type guard to check if a token is a space or newline token.
*/
function isSpace<T extends YAML.CST.Token["type"]>(token: {
type: T;
}): token is { type: T & ("space" | "newline") } {
return token.type === "space" || token.type === "newline";
}

export type ContentPropertyToken =
| CommentSourceToken
| TagSourceToken
| AnchorSourceToken;
/**
* Type guard to check if a token is a content property token (comment, tag, or anchor).
*/
export function maybeContentPropertyToken(
token: YAML.CST.SourceToken,
): token is ContentPropertyToken {
return (
token.type === "comment" || token.type === "tag" || token.type === "anchor"
);
}
9 changes: 0 additions & 9 deletions src/factories/point.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/factories/position.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Point, type Position } from "../types.js";
import type { Point, Position } from "../types.js";

export function createPosition(start: Point, end: Point): Position {
return { start, end };
Expand Down
5 changes: 2 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { wrap } from "jest-snapshot-serializer-raw";
import { type YAMLSemanticError, type YAMLSyntaxError } from "yaml/util";
import { parse } from "./parse.js";
import {
type Anchor,
Expand All @@ -8,6 +7,7 @@ import {
type Position,
type Root,
type Tag,
type YAMLSyntaxError,
type YamlUnistNode,
} from "./types.js";

Expand Down Expand Up @@ -334,14 +334,13 @@ export function testSyntaxError(text: string, message?: string) {
}
test(message || error.message, () => {
expect(
// @ts-expect-error -- FIXME
error.message + "\n" + codeFrameColumns(error.source, error.position),
).toMatchSnapshot();
});
}
}

function isYAMLError(e: any): e is YAMLSyntaxError | YAMLSemanticError {
function isYAMLError(e: any): e is YAMLSyntaxError {
return (
e instanceof Error &&
(e.name === "YAMLSyntaxError" || e.name === "YAMLSemanticError")
Expand Down
6 changes: 2 additions & 4 deletions src/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ for (const { type, text } of [
{ type: "flowMapping", text: `{"a":1,"a":2}` },
]) {
test(`(${type}): duplicate keys in ${text}`, () => {
expect(() => parse(text)).toThrowError(
`Map keys must be unique; "a" is repeated`,
);
expect(() => parse(text)).toThrowError(`Map keys must be unique`);
expect(() => parse(text, { allowDuplicateKeysInMap: false })).toThrowError(
`Map keys must be unique; "a" is repeated`,
`Map keys must be unique`,
);
const ast = parse(text, { allowDuplicateKeysInMap: true });
expect(ast).toBeDefined();
Expand Down
Loading
Loading