Skip to content

Commit

Permalink
fix: Use separate rather than inline type keyword for TS compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Nov 29, 2024
1 parent 3bec004 commit c4c49f9
Show file tree
Hide file tree
Showing 36 changed files with 92 additions and 63 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default [
'@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': [
'error',
{ fixStyle: 'inline-type-imports' }
{ fixStyle: 'separate-type-imports' }
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
Expand Down
8 changes: 5 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { resolve } from 'node:path'
import { parseArgs } from 'node:util'

import { type Token, prettyToken } from './parse/cst.ts'
import type { Token } from './parse/cst.ts'
import { prettyToken } from './parse/cst.ts'
import { Lexer } from './parse/lexer.ts'
import { Parser } from './parse/parser.ts'
import { Composer } from './compose/composer.ts'
import { LineCounter } from './parse/line-counter.ts'
import { type Document } from './doc/Document.ts'
import type { Document } from './doc/Document.ts'
import { prettifyError } from './errors.ts'
import { visit, type visitor } from './visit.ts'
import type { visitor } from './visit.ts'
import { visit } from './visit.ts'

export const help = `\
yaml: A command-line YAML processor and inspector
Expand Down
2 changes: 1 addition & 1 deletion src/compose/compose-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
FlowCollection,
SourceToken
} from '../parse/cst.ts'
import { type CollectionTag } from '../schema/types.ts'
import type { CollectionTag } from '../schema/types.ts'
import type { ComposeContext, ComposeNode } from './compose-node.ts'
import type { ComposeErrorHandler } from './composer.ts'
import { resolveBlockMap } from './resolve-block-map.ts'
Expand Down
3 changes: 2 additions & 1 deletion src/compose/composer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Directives } from '../doc/directives.ts'
import { Document } from '../doc/Document.ts'
import { type ErrorCode, YAMLParseError, YAMLWarning } from '../errors.ts'
import type { ErrorCode } from '../errors.ts'
import { YAMLParseError, YAMLWarning } from '../errors.ts'
import { isCollection, isPair } from '../nodes/identity.ts'
import type { ParsedNode, Range } from '../nodes/Node.ts'
import type {
Expand Down
2 changes: 1 addition & 1 deletion src/compose/resolve-block-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ParsedNode } from '../nodes/Node.ts'
import { Pair } from '../nodes/Pair.ts'
import { YAMLMap } from '../nodes/YAMLMap.ts'
import type { BlockMap } from '../parse/cst.ts'
import { type CollectionTag } from '../schema/types.ts'
import type { CollectionTag } from '../schema/types.ts'
import type { ComposeContext, ComposeNode } from './compose-node.ts'
import type { ComposeErrorHandler } from './composer.ts'
import { resolveProps } from './resolve-props.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/compose/resolve-block-scalar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Range } from '../nodes/Node.ts'
import type { Range } from '../nodes/Node.ts'
import { Scalar } from '../nodes/Scalar.ts'
import type { BlockScalar } from '../parse/cst.ts'
import type { ComposeContext } from './compose-node.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/compose/resolve-block-seq.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { YAMLSeq } from '../nodes/YAMLSeq.ts'
import type { BlockSequence } from '../parse/cst.ts'
import { type CollectionTag } from '../schema/types.ts'
import type { CollectionTag } from '../schema/types.ts'
import type { ComposeContext, ComposeNode } from './compose-node.ts'
import type { ComposeErrorHandler } from './composer.ts'
import { resolveProps } from './resolve-props.ts'
Expand Down
4 changes: 2 additions & 2 deletions src/compose/resolve-flow-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Pair } from '../nodes/Pair.ts'
import { YAMLMap } from '../nodes/YAMLMap.ts'
import { YAMLSeq } from '../nodes/YAMLSeq.ts'
import type { FlowCollection, Token } from '../parse/cst.ts'
import { type Schema } from '../schema/Schema.ts'
import { type CollectionTag } from '../schema/types.ts'
import type { Schema } from '../schema/Schema.ts'
import type { CollectionTag } from '../schema/types.ts'
import type { ComposeContext, ComposeNode } from './compose-node.ts'
import type { ComposeErrorHandler } from './composer.ts'
import { resolveEnd } from './resolve-end.ts'
Expand Down
4 changes: 2 additions & 2 deletions src/compose/resolve-flow-scalar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ErrorCode } from '../errors.ts'
import { type Range } from '../nodes/Node.ts'
import type { ErrorCode } from '../errors.ts'
import type { Range } from '../nodes/Node.ts'
import { Scalar } from '../nodes/Scalar.ts'
import type { FlowScalar } from '../parse/cst.ts'
import type { ComposeErrorHandler } from './composer.ts'
Expand Down
4 changes: 2 additions & 2 deletions src/compose/util-flow-indent-check.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Token } from '../parse/cst.ts'
import { type ComposeErrorHandler } from './composer.ts'
import type { Token } from '../parse/cst.ts'
import type { ComposeErrorHandler } from './composer.ts'
import { containsNewline } from './util-contains-newline.ts'

export function flowIndentCheck(
Expand Down
6 changes: 4 additions & 2 deletions src/doc/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node.ts'
import { Pair } from '../nodes/Pair.ts'
import type { Scalar } from '../nodes/Scalar.ts'
import { toJS, type ToJSContext } from '../nodes/toJS.ts'
import type { ToJSContext } from '../nodes/toJS.ts'
import { toJS } from '../nodes/toJS.ts'
import type { YAMLMap } from '../nodes/YAMLMap.ts'
import type { YAMLSeq } from '../nodes/YAMLSeq.ts'
import type {
Expand All @@ -26,7 +27,8 @@ import { Schema } from '../schema/Schema.ts'
import { stringifyDocument } from '../stringify/stringifyDocument.ts'
import { anchorNames, createNodeAnchors, findNewAnchor } from './anchors.ts'
import { applyReviver } from './applyReviver.ts'
import { createNode, type CreateNodeContext } from './createNode.ts'
import type { CreateNodeContext } from './createNode.ts'
import { createNode } from './createNode.ts'
import { Directives } from './directives.ts'

export type Replacer = any[] | ((key: any, value: any) => unknown)
Expand Down
2 changes: 1 addition & 1 deletion src/doc/anchors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Scalar } from '../nodes/Scalar.ts'
import type { YAMLMap } from '../nodes/YAMLMap.ts'
import type { YAMLSeq } from '../nodes/YAMLSeq.ts'
import { visit } from '../visit.ts'
import { type CreateNodeContext } from './createNode.ts'
import type { CreateNodeContext } from './createNode.ts'
import type { Document } from './Document.ts'

/**
Expand Down
6 changes: 4 additions & 2 deletions src/nodes/Alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import type { FlowScalar } from '../parse/cst.ts'
import type { StringifyContext } from '../stringify/stringify.ts'
import { visit } from '../visit.ts'
import { ALIAS, isAlias, isCollection, isPair } from './identity.ts'
import { type Node, NodeBase, type Range } from './Node.ts'
import type { Node, Range } from './Node.ts'
import { NodeBase } from './Node.ts'
import type { Scalar } from './Scalar.ts'
import { toJS, type ToJSContext } from './toJS.ts'
import type { ToJSContext } from './toJS.ts'
import { toJS } from './toJS.ts'
import type { YAMLMap } from './YAMLMap.ts'
import type { YAMLSeq } from './YAMLSeq.ts'

Expand Down
5 changes: 3 additions & 2 deletions src/nodes/Node.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { applyReviver } from '../doc/applyReviver.ts'
import type { Document } from '../doc/Document.ts'
import type { ToJSOptions } from '../options.ts'
import { type Token } from '../parse/cst.ts'
import type { Token } from '../parse/cst.ts'
import type { StringifyContext } from '../stringify/stringify.ts'
import type { Alias } from './Alias.ts'
import { isDocument, NODE_TYPE } from './identity.ts'
import type { Scalar } from './Scalar.ts'
import { toJS, type ToJSContext } from './toJS.ts'
import type { ToJSContext } from './toJS.ts'
import { toJS } from './toJS.ts'
import type { MapLike, YAMLMap } from './YAMLMap.ts'
import type { YAMLSeq } from './YAMLSeq.ts'

Expand Down
3 changes: 2 additions & 1 deletion src/nodes/Pair.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createNode, type CreateNodeContext } from '../doc/createNode.ts'
import type { CreateNodeContext } from '../doc/createNode.ts'
import { createNode } from '../doc/createNode.ts'
import type { CollectionItem } from '../parse/cst.ts'
import type { Schema } from '../schema/Schema.ts'
import type { StringifyContext } from '../stringify/stringify.ts'
Expand Down
6 changes: 4 additions & 2 deletions src/nodes/Scalar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { BlockScalar, FlowScalar } from '../parse/cst.ts'
import { SCALAR } from './identity.ts'
import { NodeBase, type Range } from './Node.ts'
import { toJS, type ToJSContext } from './toJS.ts'
import type { Range } from './Node.ts'
import { NodeBase } from './Node.ts'
import type { ToJSContext } from './toJS.ts'
import { toJS } from './toJS.ts'

export const isScalarValue = (value: unknown) =>
!value || (typeof value !== 'function' && typeof value !== 'object')
Expand Down
5 changes: 3 additions & 2 deletions src/nodes/YAMLMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import type { BlockMap, FlowCollection } from '../parse/cst.ts'
import type { Schema } from '../schema/Schema.ts'
import type { StringifyContext } from '../stringify/stringify.ts'
import { stringifyCollection } from '../stringify/stringifyCollection.ts'
import { type CreateNodeContext } from '../util.ts'
import type { CreateNodeContext } from '../util.ts'
import { addPairToJSMap } from './addPairToJSMap.ts'
import { Collection } from './Collection.ts'
import { isPair, isScalar, MAP } from './identity.ts'
import type { ParsedNode, Range } from './Node.ts'
import { createPair, Pair } from './Pair.ts'
import { isScalarValue, type Scalar } from './Scalar.ts'
import type { Scalar } from './Scalar.ts'
import { isScalarValue } from './Scalar.ts'
import type { ToJSContext } from './toJS.ts'

export type MapLike =
Expand Down
9 changes: 6 additions & 3 deletions src/nodes/YAMLSeq.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createNode, type CreateNodeContext } from '../doc/createNode.ts'
import type { CreateNodeContext } from '../doc/createNode.ts'
import { createNode } from '../doc/createNode.ts'
import type { BlockSequence, FlowCollection } from '../parse/cst.ts'
import type { Schema } from '../schema/Schema.ts'
import type { StringifyContext } from '../stringify/stringify.ts'
Expand All @@ -7,8 +8,10 @@ import { Collection } from './Collection.ts'
import { isScalar, SEQ } from './identity.ts'
import type { ParsedNode, Range } from './Node.ts'
import type { Pair } from './Pair.ts'
import { isScalarValue, type Scalar } from './Scalar.ts'
import { toJS, type ToJSContext } from './toJS.ts'
import type { Scalar } from './Scalar.ts'
import { isScalarValue } from './Scalar.ts'
import type { ToJSContext } from './toJS.ts'
import { toJS } from './toJS.ts'

export declare namespace YAMLSeq {
interface Parsed<
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/addPairToJSMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { addMergeToJSMap, isMergeKey } from '../schema/yaml-1.1/merge.ts'
import { createStringifyContext } from '../stringify/stringify.ts'
import { isNode } from './identity.ts'
import type { Pair } from './Pair.ts'
import { toJS, type ToJSContext } from './toJS.ts'
import type { ToJSContext } from './toJS.ts'
import { toJS } from './toJS.ts'
import type { MapLike } from './YAMLMap.ts'

export function addPairToJSMap(
Expand Down
5 changes: 3 additions & 2 deletions src/parse/cst-scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type { ComposeContext } from '../compose/compose-node.ts'
import type { ComposeErrorHandler } from '../compose/composer.ts'
import { resolveBlockScalar } from '../compose/resolve-block-scalar.ts'
import { resolveFlowScalar } from '../compose/resolve-flow-scalar.ts'
import { type ErrorCode, YAMLParseError } from '../errors.ts'
import { type Range } from '../nodes/Node.ts'
import type { ErrorCode } from '../errors.ts'
import { YAMLParseError } from '../errors.ts'
import type { Range } from '../nodes/Node.ts'
import type { Scalar } from '../nodes/Scalar.ts'
import type { StringifyContext } from '../stringify/stringify.ts'
import { stringifyString } from '../stringify/stringifyString.ts'
Expand Down
25 changes: 12 additions & 13 deletions src/parse/parser.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import {
type SourceToken,
type Token,
type FlowScalar,
type FlowCollection,
type Document,
type BlockMap,
type BlockScalar,
type BlockSequence,
type DocumentEnd,
prettyToken,
tokenType,
type TokenType
import type {
SourceToken,
Token,
FlowScalar,
FlowCollection,
Document,
BlockMap,
BlockScalar,
BlockSequence,
DocumentEnd,
TokenType
} from './cst.ts'
import { prettyToken, tokenType } from './cst.ts'
import { Lexer } from './lexer.ts'

function includesToken(list: SourceToken[], type: SourceToken['type']) {
Expand Down
3 changes: 2 additions & 1 deletion src/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Composer } from './compose/composer.ts'
import type { Reviver } from './doc/applyReviver.ts'
import { Document, type Replacer } from './doc/Document.ts'
import type { Replacer } from './doc/Document.ts'
import { Document } from './doc/Document.ts'
import { prettifyError, YAMLParseError } from './errors.ts'
import { warn } from './log.ts'
import { isDocument } from './nodes/identity.ts'
Expand Down
7 changes: 4 additions & 3 deletions src/schema/yaml-1.1/omap.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { isPair, isScalar } from '../../nodes/identity.ts'
import { toJS, type ToJSContext } from '../../nodes/toJS.ts'
import type { ToJSContext } from '../../nodes/toJS.ts'
import { toJS } from '../../nodes/toJS.ts'
import { YAMLMap } from '../../nodes/YAMLMap.ts'
import { YAMLSeq } from '../../nodes/YAMLSeq.ts'
import { type CreateNodeContext } from '../../util.ts'
import type { CreateNodeContext } from '../../util.ts'
import type { Schema } from '../Schema.ts'
import { type CollectionTag } from '../types.ts'
import type { CollectionTag } from '../types.ts'
import { createPairs, resolvePairs } from './pairs.ts'

export class YAMLOMap extends YAMLSeq {
Expand Down
3 changes: 2 additions & 1 deletion src/schema/yaml-1.1/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type { ToJSContext } from '../../nodes/toJS.ts'
import { findPair, YAMLMap } from '../../nodes/YAMLMap.ts'
import type { Schema } from '../../schema/Schema.ts'
import type { StringifyContext } from '../../stringify/stringify.ts'
import { type CreateNodeContext, createPair } from '../../util.ts'
import type { CreateNodeContext } from '../../util.ts'
import { createPair } from '../../util.ts'
import type { CollectionTag } from '../types.ts'

export class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null> {
Expand Down
3 changes: 2 additions & 1 deletion src/stringify/stringifyCollection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Collection } from '../nodes/Collection.ts'
import { isNode, isPair } from '../nodes/identity.ts'
import { stringify, type StringifyContext } from './stringify.ts'
import type { StringifyContext } from './stringify.ts'
import { stringify } from './stringify.ts'
import { indentComment, lineComment } from './stringifyComment.ts'

interface StringifyCollectionOptions {
Expand Down
3 changes: 2 additions & 1 deletion src/stringify/stringifyPair.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.ts'
import type { Pair } from '../nodes/Pair.ts'
import { Scalar } from '../nodes/Scalar.ts'
import { stringify, type StringifyContext } from './stringify.ts'
import type { StringifyContext } from './stringify.ts'
import { stringify } from './stringify.ts'
import { indentComment, lineComment } from './stringifyComment.ts'

export function stringifyPair(
Expand Down
1 change: 0 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ export type { FoldOptions } from './stringify/foldFlowLines.ts'
export type { StringifyContext } from './stringify/stringify.ts'
export { stringifyNumber } from './stringify/stringifyNumber.ts'
export { stringifyString } from './stringify/stringifyString.ts'

3 changes: 2 additions & 1 deletion tests/clone.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isAlias, isScalar, parseDocument, type Scalar, visit, type YAMLMap } from 'yaml'
import type { Scalar, YAMLMap } from 'yaml'
import { isAlias, isScalar, parseDocument, visit } from 'yaml'
import { source } from './_utils.ts'

describe('doc.clone()', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/directives.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseDocument, type Scalar } from 'yaml'
import type { Scalar } from 'yaml'
import { parseDocument } from 'yaml'
import { source } from './_utils.ts'

describe('%TAG', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/doc/anchors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Alias, Document, parse, parseDocument, type YAMLMap, type YAMLSeq } from 'yaml'
import type { Alias, YAMLMap, YAMLSeq } from 'yaml'
import { Document, parse, parseDocument } from 'yaml'

test('basic', () => {
const src = `- &a 1\n- *a\n`
Expand Down
3 changes: 2 additions & 1 deletion tests/doc/createNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Alias, Document, type Node, Scalar, YAMLMap, YAMLSeq } from 'yaml'
import type { Alias, Node } from 'yaml'
import { Document, Scalar, YAMLMap, YAMLSeq } from 'yaml'
import { source } from '../_utils.ts'

describe('createNode(value)', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/doc/foldFlowLines.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as YAML from 'yaml'
import { foldFlowLines as fold, type FoldOptions } from 'yaml/util'
import type { FoldOptions } from 'yaml/util'
import { foldFlowLines as fold } from 'yaml/util'
import { source } from '../_utils.ts'

const FOLD_FLOW = 'flow'
Expand Down
3 changes: 2 additions & 1 deletion tests/node-to-js.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseDocument, type YAMLMap, type YAMLSeq } from 'yaml'
import type { YAMLMap, YAMLSeq } from 'yaml'
import { parseDocument } from 'yaml'
import { source } from './_utils.ts'

describe('scalars', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/stream.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Composer, type Document, Parser, parseDocument } from 'yaml'
import type { Document } from 'yaml'
import { Composer, Parser, parseDocument } from 'yaml'

const src = `
#c0\n \n
Expand Down
3 changes: 2 additions & 1 deletion tests/visit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Document, isSeq, parseDocument, type Scalar, visit, visitAsync } from 'yaml'
import type { Scalar } from 'yaml'
import { Document, isSeq, parseDocument, visit, visitAsync } from 'yaml'

const coll = { items: {} }

Expand Down
3 changes: 2 additions & 1 deletion tests/yaml-test-suite.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { readdirSync, readFileSync } from 'fs'
import { resolve } from 'path'

import { CST, type Document, Lexer, parse, parseAllDocuments, Parser } from 'yaml'
import type { Document } from 'yaml'
import { CST, Lexer, parse, parseAllDocuments, Parser } from 'yaml'
import { testEvents } from '../src/test-events.ts' // no public export

type TestCase = {
Expand Down

0 comments on commit c4c49f9

Please sign in to comment.