Skip to content

Commit 1e51228

Browse files
ota-meshifisker
andauthored
Update dependency yaml to v2 (#301)
Co-authored-by: fisker <lionkay@gmail.com>
1 parent fbcd4e4 commit 1e51228

54 files changed

Lines changed: 1547 additions & 1090 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"license": "MIT",
2323
"scripts": {
24-
"prepublish": "patch-package && yarn run build",
24+
"prepublish": "yarn run build",
2525
"lint": "run-p \"lint:*\"",
2626
"lint:eslint": "eslint .",
2727
"lint:prettier": "prettier . --check",
@@ -35,7 +35,7 @@
3535
"release": "yarn build && standard-version"
3636
},
3737
"dependencies": {
38-
"yaml": "^1.10.2"
38+
"yaml": "^2.8.1"
3939
},
4040
"devDependencies": {
4141
"@eslint/js": "9.39.1",

patches/yaml+1.10.2.patch

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/__snapshots__/yaml-test-suite.test.ts.snap

Lines changed: 98 additions & 95 deletions
Large diffs are not rendered by default.

src/attach.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function attachComment(
123123

124124
const { trailingAttachableNode } = nodeTable[commentLine - 1];
125125
if (trailingAttachableNode) {
126-
// istanbul ignore next
126+
// istanbul ignore if -- @preserve
127127
if (trailingAttachableNode.trailingComment) {
128128
throw new Error(
129129
`Unexpected multiple trailing comment at ${getPointText(

src/constants.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/cst.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import type * as YAML from "yaml";
2+
3+
// Subdivide YAML.CST.SourceToken
4+
export type SpaceSourceToken = YAML.CST.SourceToken & {
5+
type: "space" | "newline";
6+
};
7+
export type CommentSourceToken = YAML.CST.SourceToken & { type: "comment" };
8+
export type DocStartSourceToken = YAML.CST.SourceToken & { type: "doc-start" };
9+
export type TagSourceToken = YAML.CST.SourceToken & { type: "tag" };
10+
export type AnchorSourceToken = YAML.CST.SourceToken & { type: "anchor" };
11+
export type SeqItemIndSourceToken = YAML.CST.SourceToken & {
12+
type: "seq-item-ind";
13+
};
14+
export type ExplicitKeyIndSourceToken = YAML.CST.SourceToken & {
15+
type: "explicit-key-ind";
16+
};
17+
export type MapValueIndSourceToken = YAML.CST.SourceToken & {
18+
type: "map-value-ind";
19+
};
20+
export type FlowMapEndSourceToken = YAML.CST.SourceToken & {
21+
type: "flow-map-end";
22+
};
23+
export type FlowSeqEndSourceToken = YAML.CST.SourceToken & {
24+
type: "flow-seq-end";
25+
};
26+
export type CommaSourceToken = YAML.CST.SourceToken & { type: "comma" };
27+
export type BlockScalarHeaderSourceToken = YAML.CST.SourceToken & {
28+
type: "block-scalar-header";
29+
};
30+
export type OtherSourceToken = YAML.CST.SourceToken & {
31+
type: Exclude<
32+
YAML.CST.SourceToken["type"],
33+
(
34+
| SpaceSourceToken
35+
| CommentSourceToken
36+
| DocStartSourceToken
37+
| TagSourceToken
38+
| AnchorSourceToken
39+
| SeqItemIndSourceToken
40+
| ExplicitKeyIndSourceToken
41+
| MapValueIndSourceToken
42+
| FlowMapEndSourceToken
43+
| FlowSeqEndSourceToken
44+
| CommaSourceToken
45+
| BlockScalarHeaderSourceToken
46+
)["type"]
47+
>;
48+
};
49+
export type SourceToken =
50+
| CommentSourceToken
51+
| DocStartSourceToken
52+
| TagSourceToken
53+
| AnchorSourceToken
54+
| SeqItemIndSourceToken
55+
| ExplicitKeyIndSourceToken
56+
| MapValueIndSourceToken
57+
| FlowMapEndSourceToken
58+
| FlowSeqEndSourceToken
59+
| CommaSourceToken
60+
| BlockScalarHeaderSourceToken
61+
| OtherSourceToken;
62+
63+
// Subdivide YAML.CST.FlowScalar
64+
export type DoubleQuotedFlowScalar = YAML.CST.FlowScalar & {
65+
type: "double-quoted-scalar";
66+
};
67+
export type SingleQuotedFlowScalar = YAML.CST.FlowScalar & {
68+
type: "single-quoted-scalar";
69+
};
70+
export type OtherFlowScalar = YAML.CST.FlowScalar & {
71+
type: Exclude<
72+
YAML.CST.FlowScalar["type"],
73+
(DoubleQuotedFlowScalar | SingleQuotedFlowScalar)["type"]
74+
>;
75+
};
76+
export type FlowScalar =
77+
| DoubleQuotedFlowScalar
78+
| SingleQuotedFlowScalar
79+
| OtherFlowScalar;
80+
81+
/**
82+
* Generator to iterate over tokens, skipping space and newline tokens.
83+
*/
84+
export function* tokens<T extends YAML.CST.Token>(
85+
...tokensArgs: (Iterable<T> | undefined)[]
86+
): Iterable<Exclude<T, YAML.CST.SourceToken> | SourceToken> {
87+
for (const tokens of tokensArgs) {
88+
if (!tokens) continue;
89+
for (const token of tokens) {
90+
if (isSpace(token)) continue;
91+
yield token as Exclude<T, YAML.CST.SourceToken> | SourceToken;
92+
}
93+
}
94+
}
95+
96+
/**
97+
* Type guard to check if a token is a space or newline token.
98+
*/
99+
function isSpace<T extends YAML.CST.Token["type"]>(token: {
100+
type: T;
101+
}): token is { type: T & ("space" | "newline") } {
102+
return token.type === "space" || token.type === "newline";
103+
}
104+
105+
export type ContentPropertyToken =
106+
| CommentSourceToken
107+
| TagSourceToken
108+
| AnchorSourceToken;
109+
/**
110+
* Type guard to check if a token is a content property token (comment, tag, or anchor).
111+
*/
112+
export function maybeContentPropertyToken(
113+
token: YAML.CST.SourceToken,
114+
): token is ContentPropertyToken {
115+
return (
116+
token.type === "comment" || token.type === "tag" || token.type === "anchor"
117+
);
118+
}

src/factories/point.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/factories/position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Point, type Position } from "../types.js";
1+
import type { Point, Position } from "../types.js";
22

33
export function createPosition(start: Point, end: Point): Position {
44
return { start, end };

src/helpers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { wrap } from "jest-snapshot-serializer-raw";
2-
import { type YAMLSemanticError, type YAMLSyntaxError } from "yaml/util";
32
import { parse } from "./parse.js";
43
import {
54
type Anchor,
@@ -8,6 +7,7 @@ import {
87
type Position,
98
type Root,
109
type Tag,
10+
type YAMLSyntaxError,
1111
type YamlUnistNode,
1212
} from "./types.js";
1313

@@ -334,14 +334,13 @@ export function testSyntaxError(text: string, message?: string) {
334334
}
335335
test(message || error.message, () => {
336336
expect(
337-
// @ts-expect-error -- FIXME
338337
error.message + "\n" + codeFrameColumns(error.source, error.position),
339338
).toMatchSnapshot();
340339
});
341340
}
342341
}
343342

344-
function isYAMLError(e: any): e is YAMLSyntaxError | YAMLSemanticError {
343+
function isYAMLError(e: any): e is YAMLSyntaxError {
345344
return (
346345
e instanceof Error &&
347346
(e.name === "YAMLSyntaxError" || e.name === "YAMLSemanticError")

src/options.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ for (const { type, text } of [
1919
{ type: "flowMapping", text: `{"a":1,"a":2}` },
2020
]) {
2121
test(`(${type}): duplicate keys in ${text}`, () => {
22-
expect(() => parse(text)).toThrowError(
23-
`Map keys must be unique; "a" is repeated`,
24-
);
22+
expect(() => parse(text)).toThrowError(`Map keys must be unique`);
2523
expect(() => parse(text, { allowDuplicateKeysInMap: false })).toThrowError(
26-
`Map keys must be unique; "a" is repeated`,
24+
`Map keys must be unique`,
2725
);
2826
const ast = parse(text, { allowDuplicateKeysInMap: true });
2927
expect(ast).toBeDefined();

0 commit comments

Comments
 (0)