From c8eec20ed90d511e9fe0c4c21391e2b90dcd9b73 Mon Sep 17 00:00:00 2001 From: Ika Date: Tue, 8 Oct 2019 04:30:49 +0800 Subject: [PATCH] feat(yaml): update to v1.2 (#38898) --- types/yaml/index.d.ts | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/types/yaml/index.d.ts b/types/yaml/index.d.ts index c9942d5566..4258cfc9c7 100644 --- a/types/yaml/index.d.ts +++ b/types/yaml/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for yaml 1.0 +// Type definitions for yaml 1.2 // Project: https://github.com/eemeli/yaml, https://eemeli.org/yaml // Definitions by: Ika // Colin Bradley @@ -50,7 +50,8 @@ export function parseAllDocuments( */ export function createNode( value: any, - wrapScalars?: true + wrapScalars?: true, + tag?: string ): ast.MapBase | ast.SeqBase | ast.Scalar; /** @@ -62,7 +63,8 @@ export function createNode( */ export function createNode( value: any, - wrapScalars: false + wrapScalars: false, + tag?: string ): ast.MapBase | ast.SeqBase | string | number | boolean | null; export function parseCST(str: string): ParsedCST; @@ -87,6 +89,10 @@ export interface ParseOptions { * Store the original node type when parsing documents. By default `true`. */ keepNodeTypes?: boolean; + /** + * When outputting JS, use Map rather than Object to represent mappings. By default `false`. + */ + mapAsMap?: boolean; /** * Enable support for `<<` merge keys. */ @@ -110,6 +116,10 @@ export interface Tag { * A JavaScript class that should be matched to this tag, e.g. `Date` for `!!timestamp`. */ class?: new () => any; + /** + * An optional factory function, used e.g. by collections when wrapping JS objects as AST nodes. + */ + createNode?: (value: any) => ast.MapBase | ast.SeqBase | ast.Scalar; /** * If `true`, the tag should not be explicitly included when stringifying. */ @@ -118,6 +128,10 @@ export interface Tag { * If a tag has multiple forms that should be parsed and/or stringified differently, use `format` to identify them. */ format?: string; + /** + * The `Node` child class that implements this tag. Required for collections and tags that have overlapping JS representations. + */ + nodeClass?: new () => any; /** * Used by some tags to configure their stringification, where applicable. */ @@ -284,6 +298,10 @@ export namespace cst { readonly tag: null; } + interface BlankLine extends Node { + type: "BLANK_LINE"; + } + interface MapItem extends Node { type: "MAP_KEY" | "MAP_VALUE"; node: ContentNode | null; @@ -300,7 +318,7 @@ export namespace cst { interface Map extends Node { type: "MAP"; /** implicit keys are not wrapped */ - items: Array; + items: Array; } interface SeqItem extends Node { @@ -310,7 +328,7 @@ export namespace cst { interface Seq extends Node { type: "SEQ"; - items: Array; + items: Array; } interface FlowChar { @@ -321,7 +339,7 @@ export namespace cst { interface FlowCollection extends Node { type: "FLOW_MAP" | "FLOW_SEQ"; - items: Array; + items: Array; } interface FlowMap extends FlowCollection { @@ -344,8 +362,8 @@ export namespace cst { interface Document extends Node { type: "DOCUMENT"; - directives: Array; - contents: Array; + directives: Array; + contents: Array; readonly anchor: null; readonly comment: null; readonly tag: null; @@ -392,6 +410,10 @@ export namespace ast { * into this node (undefined if not parsed) */ range: null | [number, number]; + /** + * a blank line before this node and its commentBefore + */ + spaceBefore?: boolean; /** * Array of prefixes; each will have a string `handle` that * starts and ends with `!` and a string `prefix` that the handle will be replaced by. @@ -487,6 +509,10 @@ export namespace ast { * into this node (undefined for pairs or if not parsed) */ range: null | [number, number]; + /** + * a blank line before this node and its commentBefore + */ + spaceBefore?: boolean; /** * a fully qualified tag, if required */