Update yaml-unist-parser to v2.1 (#18295)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-11-21 23:09:13 +08:00
1 parent f5a85ab0b6
commit b79cfcf345
7 files changed
+78 -63

No files matched your search

+1 -1
View File
@@ -120,7 +120,7 @@
"vnopts": "2.0.3",
"wcwidth.js": "2.0.0",
"yaml": "1.10.2",
"yaml-unist-parser": "2.0.5"
"yaml-unist-parser": "2.1.1"
},
"devDependencies": {
"@babel/generator": "8.0.0-beta.3",
+24
View File
@@ -0,0 +1,24 @@
import { isPragma } from "./pragma.js";
function clean(original, cloned /* , parent */) {
switch (original.type) {
case "comment":
// insert pragma
if (isPragma(original.value)) {
return null;
}
break;
case "quoteDouble":
case "quoteSingle":
cloned.type = "quote";
break;
case "document":
// We may insert explicit start/end mark
delete cloned.directivesEndMarker;
delete cloned.documentEndMarker;
break;
}
}
clean.ignoredProperties = new Set(["position"]);
export default clean;
+34 -53
View File
@@ -12,10 +12,11 @@ import {
} from "../document/index.js";
import isPreviousLineEmpty from "../utils/is-previous-line-empty.js";
import UnexpectedNodeError from "../utils/unexpected-node-error.js";
import clean from "./clean.js";
import embed from "./embed.js";
import getVisitorKeys from "./get-visitor-keys.js";
import { locStart } from "./loc.js";
import { insertPragma, isPragma } from "./pragma.js";
import { insertPragma } from "./pragma.js";
import printBlock from "./print/block.js";
import {
printFlowMapping,
@@ -154,7 +155,7 @@ function printNode(path, options, print) {
parts.push(hardline);
}
parts.push(print());
if (shouldPrintDocumentEndMarker(document, nextDocument)) {
if (shouldPrintDocumentEndMarker(path)) {
parts.push(hardline, "...");
if (hasTrailingComment(document)) {
parts.push(" ", print("trailingComment"));
@@ -175,7 +176,7 @@ function printNode(path, options, print) {
}
case "document": {
const parts = [];
if (shouldPrintDocumentHeadEndMarker(path, options) === "head") {
if (shouldPrintDocumentHeadEndMarker(path)) {
if (node.head.children.length > 0 || node.head.endComments.length > 0) {
parts.push(print("head"));
}
@@ -341,39 +342,46 @@ function shouldPrintDocumentBody(document) {
return document.body.children.length > 0 || hasEndComments(document.body);
}
function shouldPrintDocumentEndMarker(document, nextDocument) {
function shouldPrintDocumentEndMarker(path) {
const document = path.node;
/**
*... # trailingComment
*/
if (hasTrailingComment(document)) {
return true;
}
if (path.isLast) {
return false;
}
const nextDocument = path.next;
return (
/**
*... # trailingComment
* ...
* %DIRECTIVE
* ---
*/
hasTrailingComment(document) ||
(nextDocument &&
/**
* ...
* %DIRECTIVE
* ---
*/
(nextDocument.head.children.length > 0 ||
/**
* ...
* # endComment
* ---
*/
hasEndComments(nextDocument.head)))
nextDocument.head.children.length > 0 ||
/**
* ...
* # endComment
* ---
*/
hasEndComments(nextDocument.head)
);
}
function shouldPrintDocumentHeadEndMarker(path, options) {
function shouldPrintDocumentHeadEndMarker(path) {
const document = path.node;
if (
return (
/**
* ---
* preserve the first document head end marker
*/
(path.isFirst &&
/---(?:\s|$)/u.test(
options.originalText.slice(locStart(document), locStart(document) + 4),
)) ||
(path.isFirst && document.directivesEndMarker) ||
/**
* %DIRECTIVE
* ---
@@ -388,16 +396,7 @@ function shouldPrintDocumentHeadEndMarker(path, options) {
* --- # trailing comment
*/
hasTrailingComment(document.head)
) {
return "head";
}
const nextDocument = path.next;
if (shouldPrintDocumentEndMarker(document, nextDocument)) {
return false;
}
return nextDocument ? "root" : false;
);
}
function printFlowScalarContent(nodeType, content, options) {
@@ -408,24 +407,6 @@ function printFlowScalarContent(nodeType, content, options) {
);
}
function clean(original, cloned /* , parent */) {
if (isNode(original)) {
switch (original.type) {
case "comment":
// insert pragma
if (isPragma(original.value)) {
return null;
}
break;
case "quoteDouble":
case "quoteSingle":
cloned.type = "quote";
break;
}
}
}
clean.ignoredProperties = new Set(["position"]);
const printer = {
preprocess,
embed,
+1 -3
View File
@@ -5,9 +5,7 @@ import isNonEmptyArray from "../utils/is-non-empty-array.js";
* @param {string[]=} types
*/
function isNode(value, types) {
return (
typeof value?.type === "string" && (!types || types.includes(value.type))
);
return typeof value?.type === "string" && types.includes(value.type);
}
function mapNode(node, callback, parent) {
@@ -482,3 +482,15 @@ foobar: !sexy
================================================================================
`;
exports[`snippet: #0 format 1`] = `
====================================options=====================================
parsers: ["yaml"]
printWidth: 80
| printWidth
=====================================input======================================
=====================================output=====================================
================================================================================
`;
+1 -1
View File
@@ -1 +1 @@
runFormatTest(import.meta, ["yaml"]);
runFormatTest({ importMeta: import.meta, snippets: [""] }, ["yaml"]);
+5 -5
View File
@@ -7389,7 +7389,7 @@ __metadata:
vnopts: "npm:2.0.3"
wcwidth.js: "npm:2.0.0"
yaml: "npm:1.10.2"
yaml-unist-parser: "npm:2.0.5"
yaml-unist-parser: "npm:2.1.1"
bin:
prettier: ./bin/prettier.cjs
languageName: unknown
@@ -8989,12 +8989,12 @@ __metadata:
languageName: node
linkType: hard
"yaml-unist-parser@npm:2.0.5":
version: 2.0.5
resolution: "yaml-unist-parser@npm:2.0.5"
"yaml-unist-parser@npm:2.1.1":
version: 2.1.1
resolution: "yaml-unist-parser@npm:2.1.1"
dependencies:
yaml: "npm:^1.10.2"
checksum: 10/e8b820e7ecc8157ba105b73c1c6d54dda49cfb7ef0dc234c38d1c5d0e57dc83ca04abe70f99171b42709c39cf157f6bbbaeffc5f5631615576390b97a73c9729
checksum: 10/683513f5f7e69c2d42408d5316a5a50031c42cb3dbfd98809c8746c29350f7a6116c55532df4212146642d33b5abedfba0be5775304ce477c5d56dfc1204ee60
languageName: node
linkType: hard