From 4cbf6945eee942bed3cb625d0f086944b8dd3393 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Nov 2024 09:45:48 +0200 Subject: [PATCH 1/8] chore: Update to typescript 5.7 --- package-lock.json | 12 ++++++------ package.json | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 28181db2..b543a838 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "@eslint/js": "^9.9.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-replace": "^5.0.2", - "@rollup/plugin-typescript": "^11.0.0", + "@rollup/plugin-typescript": "^12.1.1", "@types/jest": "^29.2.4", "@types/node": "^20.11.20", "babel-jest": "^29.0.1", @@ -30,8 +30,8 @@ "jest-ts-webcompat-resolver": "^1.0.0", "prettier": "^3.0.2", "rollup": "^4.12.0", - "tslib": "^2.1.0", - "typescript": "^5.0.3", + "tslib": "^2.8.1", + "typescript": "^5.7.2", "typescript-eslint": "^8.4.0" }, "engines": { @@ -2542,9 +2542,9 @@ } }, "node_modules/@rollup/plugin-typescript": { - "version": "11.1.6", - "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz", - "integrity": "sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA==", + "version": "12.1.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-12.1.1.tgz", + "integrity": "sha512-t7O653DpfB5MbFrqPe/VcKFFkvRuFNp9qId3xq4Eth5xlyymzxNpye2z8Hrl0RIMuXTSr5GGcFpkdlMeacUiFQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 35966a3e..c5139862 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "@eslint/js": "^9.9.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-replace": "^5.0.2", - "@rollup/plugin-typescript": "^11.0.0", + "@rollup/plugin-typescript": "^12.1.1", "@types/jest": "^29.2.4", "@types/node": "^20.11.20", "babel-jest": "^29.0.1", @@ -86,8 +86,8 @@ "jest-ts-webcompat-resolver": "^1.0.0", "prettier": "^3.0.2", "rollup": "^4.12.0", - "tslib": "^2.1.0", - "typescript": "^5.0.3", + "tslib": "^2.8.1", + "typescript": "^5.7.2", "typescript-eslint": "^8.4.0" }, "engines": { From 18e611279076efdcd9f4984766d852b4e1f7db99 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Nov 2024 10:36:20 +0200 Subject: [PATCH 2/8] chore: Enable typescript --rewriteRelativeImportExtensions --- config/rollup.node-config.mjs | 33 ++++++++++++++++++++++++++++++++- eslint.config.mjs | 11 +++++++++++ tsconfig.json | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/config/rollup.node-config.mjs b/config/rollup.node-config.mjs index ee79df1d..524b01d8 100644 --- a/config/rollup.node-config.mjs +++ b/config/rollup.node-config.mjs @@ -1,4 +1,33 @@ import typescript from '@rollup/plugin-typescript' +import * as ts from 'typescript' + +/** + * Strip out TS relative import path rewrite helper from dynamic import() calls + * + * Required due to + * https://github.com/rollup/plugins/issues/1820 + * + * @param {ts.TransformationContext} context + */ +function fixDynamicImportRewrite(context) { + /** @param {ts.SourceFile} source */ + return function fixDynamicImport(source) { + /** @param {ts.Node} node */ + function visitor(node) { + if ( + ts.isCallExpression(node) && + ts.isIdentifier(node.expression) && + String(node.expression.escapedText) === + '___rewriteRelativeImportExtension' && + node.arguments.length === 1 + ) { + return node.arguments[0] + } + return ts.visitEachChild(node, visitor, context) + } + return ts.visitNode(source, visitor) + } +} export default [ { @@ -20,6 +49,8 @@ export default [ input: 'src/cli.ts', output: { file: 'dist/cli.mjs' }, external: () => true, - plugins: [typescript()] + plugins: [ + typescript({ transformers: { after: [fixDynamicImportRewrite] } }) + ] } ] diff --git a/eslint.config.mjs b/eslint.config.mjs index fe2dab72..a07a4464 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -38,6 +38,17 @@ export default [ 'no-control-regex': 'off', 'no-fallthrough': ['error', { commentPattern: 'fallthrough' }], 'no-implicit-globals': 'error', + 'no-restricted-imports': [ + 'error', + { + patterns: [ + { + regex: '^\\..*(? Date: Fri, 29 Nov 2024 10:34:01 +0200 Subject: [PATCH 3/8] feat: Use .ts extension in all relative imports --- src/cli.ts | 16 ++++----- src/compose/compose-collection.ts | 24 ++++++------- src/compose/compose-doc.ts | 18 +++++----- src/compose/compose-node.ts | 24 ++++++------- src/compose/compose-scalar.ts | 18 +++++----- src/compose/composer.ts | 18 +++++----- src/compose/resolve-block-map.ts | 22 ++++++------ src/compose/resolve-block-scalar.ts | 10 +++--- src/compose/resolve-block-seq.ts | 14 ++++---- src/compose/resolve-end.ts | 4 +-- src/compose/resolve-flow-collection.ts | 26 +++++++------- src/compose/resolve-flow-scalar.ts | 12 +++---- src/compose/resolve-props.ts | 4 +-- src/compose/util-contains-newline.ts | 2 +- src/compose/util-empty-scalar-position.ts | 2 +- src/compose/util-flow-indent-check.ts | 6 ++-- src/compose/util-map-includes.ts | 8 ++--- src/doc/Document.ts | 34 +++++++++--------- src/doc/anchors.ts | 16 ++++----- src/doc/createNode.ts | 16 ++++----- src/doc/directives.ts | 6 ++-- src/errors.ts | 2 +- src/index.ts | 44 +++++++++++------------ src/nodes/Alias.ts | 22 ++++++------ src/nodes/Collection.ts | 8 ++--- src/nodes/Node.ts | 22 ++++++------ src/nodes/Pair.ts | 16 ++++----- src/nodes/Scalar.ts | 8 ++--- src/nodes/YAMLMap.ts | 24 ++++++------- src/nodes/YAMLSeq.ts | 22 ++++++------ src/nodes/addPairToJSMap.ts | 14 ++++---- src/nodes/identity.ts | 14 ++++---- src/nodes/toJS.ts | 6 ++-- src/options.ts | 20 +++++------ src/parse/cst-scalar.ts | 20 +++++------ src/parse/cst-stringify.ts | 2 +- src/parse/cst-visit.ts | 2 +- src/parse/cst.ts | 6 ++-- src/parse/lexer.ts | 2 +- src/parse/parser.ts | 4 +-- src/public-api.ts | 20 +++++------ src/schema/Schema.ts | 16 ++++----- src/schema/common/map.ts | 6 ++-- src/schema/common/null.ts | 4 +-- src/schema/common/seq.ts | 6 ++-- src/schema/common/string.ts | 4 +-- src/schema/core/bool.ts | 4 +-- src/schema/core/float.ts | 6 ++-- src/schema/core/int.ts | 8 ++--- src/schema/core/schema.ts | 14 ++++---- src/schema/json/schema.ts | 8 ++--- src/schema/tags.ts | 36 +++++++++---------- src/schema/types.ts | 16 ++++----- src/schema/yaml-1.1/binary.ts | 6 ++-- src/schema/yaml-1.1/bool.ts | 6 ++-- src/schema/yaml-1.1/float.ts | 6 ++-- src/schema/yaml-1.1/int.ts | 8 ++--- src/schema/yaml-1.1/merge.ts | 10 +++--- src/schema/yaml-1.1/omap.ts | 16 ++++----- src/schema/yaml-1.1/pairs.ts | 18 +++++----- src/schema/yaml-1.1/schema.ts | 26 +++++++------- src/schema/yaml-1.1/set.ts | 18 +++++----- src/schema/yaml-1.1/timestamp.ts | 6 ++-- src/stringify/stringify.ts | 20 +++++------ src/stringify/stringifyCollection.ts | 8 ++--- src/stringify/stringifyDocument.ts | 12 +++---- src/stringify/stringifyNumber.ts | 2 +- src/stringify/stringifyPair.ts | 10 +++--- src/stringify/stringifyString.ts | 8 ++--- src/test-events.ts | 12 +++---- src/util.ts | 24 ++++++------- src/visit.ts | 16 ++++----- 72 files changed, 469 insertions(+), 469 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 9d3529d2..0ad15356 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,14 +1,14 @@ import { resolve } from 'node:path' import { parseArgs } from 'node:util' -import { type Token, prettyToken } from './parse/cst.js' -import { Lexer } from './parse/lexer.js' -import { Parser } from './parse/parser.js' -import { Composer } from './compose/composer.js' -import { LineCounter } from './parse/line-counter.js' -import { type Document } from './doc/Document.js' -import { prettifyError } from './errors.js' -import { visit, type visitor } from './visit.js' +import { type Token, 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 { prettifyError } from './errors.ts' +import { visit, type visitor } from './visit.ts' export const help = `\ yaml: A command-line YAML processor and inspector diff --git a/src/compose/compose-collection.ts b/src/compose/compose-collection.ts index cf47c0e1..6911c5ab 100644 --- a/src/compose/compose-collection.ts +++ b/src/compose/compose-collection.ts @@ -1,20 +1,20 @@ -import { isNode } from '../nodes/identity.js' -import type { ParsedNode } from '../nodes/Node.js' -import { Scalar } from '../nodes/Scalar.js' -import { YAMLMap } from '../nodes/YAMLMap.js' -import { YAMLSeq } from '../nodes/YAMLSeq.js' +import { isNode } from '../nodes/identity.ts' +import type { ParsedNode } from '../nodes/Node.ts' +import { Scalar } from '../nodes/Scalar.ts' +import { YAMLMap } from '../nodes/YAMLMap.ts' +import { YAMLSeq } from '../nodes/YAMLSeq.ts' import type { BlockMap, BlockSequence, FlowCollection, SourceToken -} from '../parse/cst.js' -import { CollectionTag } from '../schema/types.js' -import type { ComposeContext, ComposeNode } from './compose-node.js' -import type { ComposeErrorHandler } from './composer.js' -import { resolveBlockMap } from './resolve-block-map.js' -import { resolveBlockSeq } from './resolve-block-seq.js' -import { resolveFlowCollection } from './resolve-flow-collection.js' +} from '../parse/cst.ts' +import { 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' +import { resolveBlockSeq } from './resolve-block-seq.ts' +import { resolveFlowCollection } from './resolve-flow-collection.ts' function resolveCollection( CN: ComposeNode, diff --git a/src/compose/compose-doc.ts b/src/compose/compose-doc.ts index 0f2461c0..336c0524 100644 --- a/src/compose/compose-doc.ts +++ b/src/compose/compose-doc.ts @@ -1,20 +1,20 @@ -import type { Directives } from '../doc/directives.js' -import { Document } from '../doc/Document.js' -import type { ParsedNode } from '../nodes/Node.js' +import type { Directives } from '../doc/directives.ts' +import { Document } from '../doc/Document.ts' +import type { ParsedNode } from '../nodes/Node.ts' import type { DocumentOptions, ParseOptions, SchemaOptions -} from '../options.js' -import type * as CST from '../parse/cst.js' +} from '../options.ts' +import type * as CST from '../parse/cst.ts' import { ComposeContext, composeEmptyNode, composeNode -} from './compose-node.js' -import type { ComposeErrorHandler } from './composer.js' -import { resolveEnd } from './resolve-end.js' -import { resolveProps } from './resolve-props.js' +} from './compose-node.ts' +import type { ComposeErrorHandler } from './composer.ts' +import { resolveEnd } from './resolve-end.ts' +import { resolveProps } from './resolve-props.ts' export function composeDoc< Contents extends ParsedNode = ParsedNode, diff --git a/src/compose/compose-node.ts b/src/compose/compose-node.ts index 41349c35..88dab4ec 100644 --- a/src/compose/compose-node.ts +++ b/src/compose/compose-node.ts @@ -1,15 +1,15 @@ -import type { Directives } from '../doc/directives.js' -import { Alias } from '../nodes/Alias.js' -import { isScalar } from '../nodes/identity.js' -import type { ParsedNode } from '../nodes/Node.js' -import type { ParseOptions } from '../options.js' -import type { FlowScalar, SourceToken, Token } from '../parse/cst.js' -import type { Schema } from '../schema/Schema.js' -import { composeCollection } from './compose-collection.js' -import { composeScalar } from './compose-scalar.js' -import type { ComposeErrorHandler } from './composer.js' -import { resolveEnd } from './resolve-end.js' -import { emptyScalarPosition } from './util-empty-scalar-position.js' +import type { Directives } from '../doc/directives.ts' +import { Alias } from '../nodes/Alias.ts' +import { isScalar } from '../nodes/identity.ts' +import type { ParsedNode } from '../nodes/Node.ts' +import type { ParseOptions } from '../options.ts' +import type { FlowScalar, SourceToken, Token } from '../parse/cst.ts' +import type { Schema } from '../schema/Schema.ts' +import { composeCollection } from './compose-collection.ts' +import { composeScalar } from './compose-scalar.ts' +import type { ComposeErrorHandler } from './composer.ts' +import { resolveEnd } from './resolve-end.ts' +import { emptyScalarPosition } from './util-empty-scalar-position.ts' export interface ComposeContext { atKey: boolean diff --git a/src/compose/compose-scalar.ts b/src/compose/compose-scalar.ts index f1878880..e994ec0f 100644 --- a/src/compose/compose-scalar.ts +++ b/src/compose/compose-scalar.ts @@ -1,12 +1,12 @@ -import { isScalar, SCALAR } from '../nodes/identity.js' -import { Scalar } from '../nodes/Scalar.js' -import type { BlockScalar, FlowScalar, SourceToken } from '../parse/cst.js' -import type { Schema } from '../schema/Schema.js' -import type { ScalarTag } from '../schema/types.js' -import type { ComposeContext } from './compose-node.js' -import type { ComposeErrorHandler } from './composer.js' -import { resolveBlockScalar } from './resolve-block-scalar.js' -import { resolveFlowScalar } from './resolve-flow-scalar.js' +import { isScalar, SCALAR } from '../nodes/identity.ts' +import { Scalar } from '../nodes/Scalar.ts' +import type { BlockScalar, FlowScalar, SourceToken } from '../parse/cst.ts' +import type { Schema } from '../schema/Schema.ts' +import type { ScalarTag } from '../schema/types.ts' +import type { ComposeContext } from './compose-node.ts' +import type { ComposeErrorHandler } from './composer.ts' +import { resolveBlockScalar } from './resolve-block-scalar.ts' +import { resolveFlowScalar } from './resolve-flow-scalar.ts' export function composeScalar( ctx: ComposeContext, diff --git a/src/compose/composer.ts b/src/compose/composer.ts index 4def6a00..ba9c3859 100644 --- a/src/compose/composer.ts +++ b/src/compose/composer.ts @@ -1,16 +1,16 @@ -import { Directives } from '../doc/directives.js' -import { Document } from '../doc/Document.js' -import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js' -import { isCollection, isPair } from '../nodes/identity.js' -import type { ParsedNode, Range } from '../nodes/Node.js' +import { Directives } from '../doc/directives.ts' +import { Document } from '../doc/Document.ts' +import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.ts' +import { isCollection, isPair } from '../nodes/identity.ts' +import type { ParsedNode, Range } from '../nodes/Node.ts' import type { DocumentOptions, ParseOptions, SchemaOptions -} from '../options.js' -import type { Token } from '../parse/cst.js' -import { composeDoc } from './compose-doc.js' -import { resolveEnd } from './resolve-end.js' +} from '../options.ts' +import type { Token } from '../parse/cst.ts' +import { composeDoc } from './compose-doc.ts' +import { resolveEnd } from './resolve-end.ts' type ErrorSource = | number diff --git a/src/compose/resolve-block-map.ts b/src/compose/resolve-block-map.ts index 7e5abb00..38101037 100644 --- a/src/compose/resolve-block-map.ts +++ b/src/compose/resolve-block-map.ts @@ -1,14 +1,14 @@ -import type { ParsedNode } from '../nodes/Node.js' -import { Pair } from '../nodes/Pair.js' -import { YAMLMap } from '../nodes/YAMLMap.js' -import type { BlockMap } from '../parse/cst.js' -import { CollectionTag } from '../schema/types.js' -import type { ComposeContext, ComposeNode } from './compose-node.js' -import type { ComposeErrorHandler } from './composer.js' -import { resolveProps } from './resolve-props.js' -import { containsNewline } from './util-contains-newline.js' -import { flowIndentCheck } from './util-flow-indent-check.js' -import { mapIncludes } from './util-map-includes.js' +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 { 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' +import { containsNewline } from './util-contains-newline.ts' +import { flowIndentCheck } from './util-flow-indent-check.ts' +import { mapIncludes } from './util-map-includes.ts' const startColMsg = 'All mapping items must start at the same column' diff --git a/src/compose/resolve-block-scalar.ts b/src/compose/resolve-block-scalar.ts index 90dfa65b..9200c03f 100644 --- a/src/compose/resolve-block-scalar.ts +++ b/src/compose/resolve-block-scalar.ts @@ -1,8 +1,8 @@ -import { Range } from '../nodes/Node.js' -import { Scalar } from '../nodes/Scalar.js' -import type { BlockScalar } from '../parse/cst.js' -import type { ComposeContext } from './compose-node.js' -import type { ComposeErrorHandler } from './composer.js' +import { 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' +import type { ComposeErrorHandler } from './composer.ts' export function resolveBlockScalar( ctx: ComposeContext, diff --git a/src/compose/resolve-block-seq.ts b/src/compose/resolve-block-seq.ts index 84aa3852..e888f0ec 100644 --- a/src/compose/resolve-block-seq.ts +++ b/src/compose/resolve-block-seq.ts @@ -1,10 +1,10 @@ -import { YAMLSeq } from '../nodes/YAMLSeq.js' -import type { BlockSequence } from '../parse/cst.js' -import { CollectionTag } from '../schema/types.js' -import type { ComposeContext, ComposeNode } from './compose-node.js' -import type { ComposeErrorHandler } from './composer.js' -import { resolveProps } from './resolve-props.js' -import { flowIndentCheck } from './util-flow-indent-check.js' +import { YAMLSeq } from '../nodes/YAMLSeq.ts' +import type { BlockSequence } from '../parse/cst.ts' +import { 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' +import { flowIndentCheck } from './util-flow-indent-check.ts' export function resolveBlockSeq( { composeNode, composeEmptyNode }: ComposeNode, diff --git a/src/compose/resolve-end.ts b/src/compose/resolve-end.ts index e7a9de99..83877045 100644 --- a/src/compose/resolve-end.ts +++ b/src/compose/resolve-end.ts @@ -1,5 +1,5 @@ -import type { SourceToken } from '../parse/cst.js' -import type { ComposeErrorHandler } from './composer.js' +import type { SourceToken } from '../parse/cst.ts' +import type { ComposeErrorHandler } from './composer.ts' export function resolveEnd( end: SourceToken[] | undefined, diff --git a/src/compose/resolve-flow-collection.ts b/src/compose/resolve-flow-collection.ts index 9bab53f2..bc0cd7aa 100644 --- a/src/compose/resolve-flow-collection.ts +++ b/src/compose/resolve-flow-collection.ts @@ -1,16 +1,16 @@ -import { isPair } from '../nodes/identity.js' -import { Pair } from '../nodes/Pair.js' -import { YAMLMap } from '../nodes/YAMLMap.js' -import { YAMLSeq } from '../nodes/YAMLSeq.js' -import type { FlowCollection, Token } from '../parse/cst.js' -import { Schema } from '../schema/Schema.js' -import { CollectionTag } from '../schema/types.js' -import type { ComposeContext, ComposeNode } from './compose-node.js' -import type { ComposeErrorHandler } from './composer.js' -import { resolveEnd } from './resolve-end.js' -import { resolveProps } from './resolve-props.js' -import { containsNewline } from './util-contains-newline.js' -import { mapIncludes } from './util-map-includes.js' +import { isPair } from '../nodes/identity.ts' +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 { Schema } from '../schema/Schema.ts' +import { 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' +import { resolveProps } from './resolve-props.ts' +import { containsNewline } from './util-contains-newline.ts' +import { mapIncludes } from './util-map-includes.ts' const blockMsg = 'Block collections are not allowed within flow collections' const isBlock = (token: Token | null | undefined) => diff --git a/src/compose/resolve-flow-scalar.ts b/src/compose/resolve-flow-scalar.ts index 0568dd9a..a352cc96 100644 --- a/src/compose/resolve-flow-scalar.ts +++ b/src/compose/resolve-flow-scalar.ts @@ -1,9 +1,9 @@ -import { ErrorCode } from '../errors.js' -import { Range } from '../nodes/Node.js' -import { Scalar } from '../nodes/Scalar.js' -import type { FlowScalar } from '../parse/cst.js' -import type { ComposeErrorHandler } from './composer.js' -import { resolveEnd } from './resolve-end.js' +import { ErrorCode } from '../errors.ts' +import { Range } from '../nodes/Node.ts' +import { Scalar } from '../nodes/Scalar.ts' +import type { FlowScalar } from '../parse/cst.ts' +import type { ComposeErrorHandler } from './composer.ts' +import { resolveEnd } from './resolve-end.ts' type FlowScalarErrorHandler = ( offset: number, diff --git a/src/compose/resolve-props.ts b/src/compose/resolve-props.ts index 20a1590e..1c16adb3 100644 --- a/src/compose/resolve-props.ts +++ b/src/compose/resolve-props.ts @@ -1,5 +1,5 @@ -import type { SourceToken, Token } from '../parse/cst.js' -import type { ComposeErrorHandler } from './composer.js' +import type { SourceToken, Token } from '../parse/cst.ts' +import type { ComposeErrorHandler } from './composer.ts' export interface ResolvePropsArg { flow?: 'flow map' | 'flow sequence' diff --git a/src/compose/util-contains-newline.ts b/src/compose/util-contains-newline.ts index a34e3066..41342077 100644 --- a/src/compose/util-contains-newline.ts +++ b/src/compose/util-contains-newline.ts @@ -1,4 +1,4 @@ -import type { Token } from '../parse/cst.js' +import type { Token } from '../parse/cst.ts' export function containsNewline(key: Token | null | undefined) { if (!key) return null diff --git a/src/compose/util-empty-scalar-position.ts b/src/compose/util-empty-scalar-position.ts index 51180717..48caf9db 100644 --- a/src/compose/util-empty-scalar-position.ts +++ b/src/compose/util-empty-scalar-position.ts @@ -1,4 +1,4 @@ -import type { Token } from '../parse/cst.js' +import type { Token } from '../parse/cst.ts' export function emptyScalarPosition( offset: number, diff --git a/src/compose/util-flow-indent-check.ts b/src/compose/util-flow-indent-check.ts index eb55719d..0d23291f 100644 --- a/src/compose/util-flow-indent-check.ts +++ b/src/compose/util-flow-indent-check.ts @@ -1,6 +1,6 @@ -import { Token } from '../parse/cst' -import { ComposeErrorHandler } from './composer' -import { containsNewline } from './util-contains-newline' +import { Token } from '../parse/cst.ts' +import { ComposeErrorHandler } from './composer.ts' +import { containsNewline } from './util-contains-newline.ts' export function flowIndentCheck( indent: number, diff --git a/src/compose/util-map-includes.ts b/src/compose/util-map-includes.ts index ce20c118..1b5f8ed7 100644 --- a/src/compose/util-map-includes.ts +++ b/src/compose/util-map-includes.ts @@ -1,7 +1,7 @@ -import { isScalar } from '../nodes/identity.js' -import type { ParsedNode } from '../nodes/Node.js' -import type { Pair } from '../nodes/Pair.js' -import type { ComposeContext } from './compose-node.js' +import { isScalar } from '../nodes/identity.ts' +import type { ParsedNode } from '../nodes/Node.ts' +import type { Pair } from '../nodes/Pair.ts' +import type { ComposeContext } from './compose-node.ts' export function mapIncludes( ctx: ComposeContext, diff --git a/src/doc/Document.ts b/src/doc/Document.ts index 0eb38cfe..3f61eac5 100644 --- a/src/doc/Document.ts +++ b/src/doc/Document.ts @@ -1,19 +1,19 @@ -import type { YAMLError, YAMLWarning } from '../errors.js' -import { Alias } from '../nodes/Alias.js' -import { collectionFromPath, isEmptyPath } from '../nodes/Collection.js' +import type { YAMLError, YAMLWarning } from '../errors.ts' +import { Alias } from '../nodes/Alias.ts' +import { collectionFromPath, isEmptyPath } from '../nodes/Collection.ts' import { DOC, isCollection, isNode, isScalar, NODE_TYPE -} from '../nodes/identity.js' -import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node.js' -import { Pair } from '../nodes/Pair.js' -import type { Scalar } from '../nodes/Scalar.js' -import { toJS, ToJSContext } from '../nodes/toJS.js' -import type { YAMLMap } from '../nodes/YAMLMap.js' -import type { YAMLSeq } from '../nodes/YAMLSeq.js' +} from '../nodes/identity.ts' +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, ToJSContext } from '../nodes/toJS.ts' +import type { YAMLMap } from '../nodes/YAMLMap.ts' +import type { YAMLSeq } from '../nodes/YAMLSeq.ts' import type { CreateNodeOptions, DocumentOptions, @@ -21,13 +21,13 @@ import type { SchemaOptions, ToJSOptions, ToStringOptions -} from '../options.js' -import { Schema } from '../schema/Schema.js' -import { stringifyDocument } from '../stringify/stringifyDocument.js' -import { anchorNames, createNodeAnchors, findNewAnchor } from './anchors.js' -import { applyReviver } from './applyReviver.js' -import { createNode, CreateNodeContext } from './createNode.js' -import { Directives } from './directives.js' +} from '../options.ts' +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, CreateNodeContext } from './createNode.ts' +import { Directives } from './directives.ts' export type Replacer = any[] | ((key: any, value: any) => unknown) diff --git a/src/doc/anchors.ts b/src/doc/anchors.ts index 7899fbe5..d2ea6537 100644 --- a/src/doc/anchors.ts +++ b/src/doc/anchors.ts @@ -1,11 +1,11 @@ -import { isCollection, isScalar } from '../nodes/identity.js' -import type { Node } from '../nodes/Node.js' -import type { Scalar } from '../nodes/Scalar.js' -import type { YAMLMap } from '../nodes/YAMLMap.js' -import type { YAMLSeq } from '../nodes/YAMLSeq.js' -import { visit } from '../visit.js' -import { CreateNodeContext } from './createNode.js' -import type { Document } from './Document.js' +import { isCollection, isScalar } from '../nodes/identity.ts' +import type { Node } from '../nodes/Node.ts' +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 { CreateNodeContext } from './createNode.ts' +import type { Document } from './Document.ts' /** * Verify that the input string is a valid anchor. diff --git a/src/doc/createNode.ts b/src/doc/createNode.ts index c80805d2..203b5981 100644 --- a/src/doc/createNode.ts +++ b/src/doc/createNode.ts @@ -1,11 +1,11 @@ -import { Alias } from '../nodes/Alias.js' -import { isDocument, isNode, isPair, MAP, SEQ } from '../nodes/identity.js' -import type { Node } from '../nodes/Node.js' -import { Scalar } from '../nodes/Scalar.js' -import type { YAMLMap } from '../nodes/YAMLMap.js' -import type { Schema } from '../schema/Schema.js' -import type { CollectionTag, ScalarTag } from '../schema/types.js' -import type { Replacer } from './Document.js' +import { Alias } from '../nodes/Alias.ts' +import { isDocument, isNode, isPair, MAP, SEQ } from '../nodes/identity.ts' +import type { Node } from '../nodes/Node.ts' +import { Scalar } from '../nodes/Scalar.ts' +import type { YAMLMap } from '../nodes/YAMLMap.ts' +import type { Schema } from '../schema/Schema.ts' +import type { CollectionTag, ScalarTag } from '../schema/types.ts' +import type { Replacer } from './Document.ts' const defaultTagPrefix = 'tag:yaml.org,2002:' diff --git a/src/doc/directives.ts b/src/doc/directives.ts index 1b152996..37f1ce0b 100644 --- a/src/doc/directives.ts +++ b/src/doc/directives.ts @@ -1,6 +1,6 @@ -import { isNode } from '../nodes/identity.js' -import { visit } from '../visit.js' -import type { Document } from './Document.js' +import { isNode } from '../nodes/identity.ts' +import { visit } from '../visit.ts' +import type { Document } from './Document.ts' const escapeChars: Record = { '!': '%21', diff --git a/src/errors.ts b/src/errors.ts index a5b62b0c..1200d1d1 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,4 +1,4 @@ -import type { LineCounter } from './parse/line-counter' +import type { LineCounter } from './parse/line-counter.ts' export type ErrorCode = | 'ALIAS_PROPS' diff --git a/src/index.ts b/src/index.ts index 1b5ea23d..134f7184 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ -export { Composer } from './compose/composer.js' +export { Composer } from './compose/composer.ts' -export { Document } from './doc/Document.js' -export { Schema } from './schema/Schema.js' +export { Document } from './doc/Document.ts' +export { Schema } from './schema/Schema.ts' -export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.js' +export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.ts' -export { Alias } from './nodes/Alias.js' +export { Alias } from './nodes/Alias.ts' export { isAlias, isCollection, @@ -15,12 +15,12 @@ export { isPair, isScalar, isSeq -} from './nodes/identity.js' -export { Node, ParsedNode, Range } from './nodes/Node.js' -export { Pair } from './nodes/Pair.js' -export { Scalar } from './nodes/Scalar.js' -export { YAMLMap } from './nodes/YAMLMap.js' -export { YAMLSeq } from './nodes/YAMLSeq.js' +} from './nodes/identity.ts' +export { Node, ParsedNode, Range } from './nodes/Node.ts' +export { Pair } from './nodes/Pair.ts' +export { Scalar } from './nodes/Scalar.ts' +export { YAMLMap } from './nodes/YAMLMap.ts' +export { YAMLSeq } from './nodes/YAMLSeq.ts' export type { CreateNodeOptions, @@ -29,12 +29,12 @@ export type { SchemaOptions, ToJSOptions, ToStringOptions -} from './options.js' +} from './options.ts' -export * as CST from './parse/cst.js' -export { Lexer } from './parse/lexer.js' -export { LineCounter } from './parse/line-counter.js' -export { Parser } from './parse/parser.js' +export * as CST from './parse/cst.ts' +export { Lexer } from './parse/lexer.ts' +export { LineCounter } from './parse/line-counter.ts' +export { Parser } from './parse/parser.ts' export { EmptyStream, @@ -42,12 +42,12 @@ export { parseAllDocuments, parseDocument, stringify -} from './public-api.js' +} from './public-api.ts' -export type { TagId, Tags } from './schema/tags' -export type { CollectionTag, ScalarTag } from './schema/types' -export type { YAMLOMap } from './schema/yaml-1.1/omap' -export type { YAMLSet } from './schema/yaml-1.1/set' +export type { TagId, Tags } from './schema/tags.ts' +export type { CollectionTag, ScalarTag } from './schema/types.ts' +export type { YAMLOMap } from './schema/yaml-1.1/omap.ts' +export type { YAMLSet } from './schema/yaml-1.1/set.ts' export { asyncVisitor, @@ -56,4 +56,4 @@ export { visitAsync, visitor, visitorFn -} from './visit.js' +} from './visit.ts' diff --git a/src/nodes/Alias.ts b/src/nodes/Alias.ts index b4bb5b3f..2e39b278 100644 --- a/src/nodes/Alias.ts +++ b/src/nodes/Alias.ts @@ -1,14 +1,14 @@ -import { anchorIsValid } from '../doc/anchors.js' -import type { Document } from '../doc/Document.js' -import type { FlowScalar } from '../parse/cst.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { visit } from '../visit.js' -import { ALIAS, isAlias, isCollection, isPair } from './identity.js' -import { Node, NodeBase, Range } from './Node.js' -import type { Scalar } from './Scalar' -import { toJS, ToJSContext } from './toJS.js' -import type { YAMLMap } from './YAMLMap.js' -import type { YAMLSeq } from './YAMLSeq.js' +import { anchorIsValid } from '../doc/anchors.ts' +import type { Document } from '../doc/Document.ts' +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 { Node, NodeBase, Range } from './Node.ts' +import type { Scalar } from './Scalar.ts' +import { toJS, ToJSContext } from './toJS.ts' +import type { YAMLMap } from './YAMLMap.ts' +import type { YAMLSeq } from './YAMLSeq.ts' export declare namespace Alias { interface Parsed extends Alias { diff --git a/src/nodes/Collection.ts b/src/nodes/Collection.ts index bb40d089..9e336b91 100644 --- a/src/nodes/Collection.ts +++ b/src/nodes/Collection.ts @@ -1,13 +1,13 @@ -import { createNode } from '../doc/createNode.js' -import type { Schema } from '../schema/Schema.js' +import { createNode } from '../doc/createNode.ts' +import type { Schema } from '../schema/Schema.ts' import { isCollection, isNode, isPair, isScalar, NODE_TYPE -} from './identity.js' -import { NodeBase } from './Node.js' +} from './identity.ts' +import { NodeBase } from './Node.ts' export function collectionFromPath( schema: Schema, diff --git a/src/nodes/Node.ts b/src/nodes/Node.ts index 49efb66a..8d861938 100644 --- a/src/nodes/Node.ts +++ b/src/nodes/Node.ts @@ -1,14 +1,14 @@ -import { applyReviver } from '../doc/applyReviver.js' -import type { Document } from '../doc/Document.js' -import type { ToJSOptions } from '../options.js' -import { Token } from '../parse/cst.js' -import type { StringifyContext } from '../stringify/stringify.js' -import type { Alias } from './Alias.js' -import { isDocument, NODE_TYPE } from './identity.js' -import type { Scalar } from './Scalar.js' -import { toJS, ToJSContext } from './toJS.js' -import type { MapLike, YAMLMap } from './YAMLMap.js' -import type { YAMLSeq } from './YAMLSeq.js' +import { applyReviver } from '../doc/applyReviver.ts' +import type { Document } from '../doc/Document.ts' +import type { ToJSOptions } from '../options.ts' +import { 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, ToJSContext } from './toJS.ts' +import type { MapLike, YAMLMap } from './YAMLMap.ts' +import type { YAMLSeq } from './YAMLSeq.ts' export type Node = | Alias diff --git a/src/nodes/Pair.ts b/src/nodes/Pair.ts index 370fc2c3..eb697732 100644 --- a/src/nodes/Pair.ts +++ b/src/nodes/Pair.ts @@ -1,11 +1,11 @@ -import { createNode, CreateNodeContext } from '../doc/createNode.js' -import type { CollectionItem } from '../parse/cst.js' -import type { Schema } from '../schema/Schema.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { stringifyPair } from '../stringify/stringifyPair.js' -import { addPairToJSMap } from './addPairToJSMap.js' -import { isNode, NODE_TYPE, PAIR } from './identity.js' -import type { ToJSContext } from './toJS.js' +import { createNode, CreateNodeContext } 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' +import { stringifyPair } from '../stringify/stringifyPair.ts' +import { addPairToJSMap } from './addPairToJSMap.ts' +import { isNode, NODE_TYPE, PAIR } from './identity.ts' +import type { ToJSContext } from './toJS.ts' export function createPair( key: unknown, diff --git a/src/nodes/Scalar.ts b/src/nodes/Scalar.ts index 59ea16a9..e354eb29 100644 --- a/src/nodes/Scalar.ts +++ b/src/nodes/Scalar.ts @@ -1,7 +1,7 @@ -import type { BlockScalar, FlowScalar } from '../parse/cst.js' -import { SCALAR } from './identity.js' -import { NodeBase, Range } from './Node.js' -import { toJS, ToJSContext } from './toJS.js' +import type { BlockScalar, FlowScalar } from '../parse/cst.ts' +import { SCALAR } from './identity.ts' +import { NodeBase, Range } from './Node.ts' +import { toJS, ToJSContext } from './toJS.ts' export const isScalarValue = (value: unknown) => !value || (typeof value !== 'function' && typeof value !== 'object') diff --git a/src/nodes/YAMLMap.ts b/src/nodes/YAMLMap.ts index 74852304..b73b8056 100644 --- a/src/nodes/YAMLMap.ts +++ b/src/nodes/YAMLMap.ts @@ -1,15 +1,15 @@ -import type { BlockMap, FlowCollection } from '../parse/cst.js' -import type { Schema } from '../schema/Schema.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { stringifyCollection } from '../stringify/stringifyCollection.js' -import { CreateNodeContext } from '../util.js' -import { addPairToJSMap } from './addPairToJSMap.js' -import { Collection } from './Collection.js' -import { isPair, isScalar, MAP } from './identity.js' -import type { ParsedNode, Range } from './Node.js' -import { createPair, Pair } from './Pair.js' -import { isScalarValue, Scalar } from './Scalar.js' -import type { ToJSContext } from './toJS.js' +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 { 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, Scalar } from './Scalar.ts' +import type { ToJSContext } from './toJS.ts' export type MapLike = | Map diff --git a/src/nodes/YAMLSeq.ts b/src/nodes/YAMLSeq.ts index ada8c488..61bc1270 100644 --- a/src/nodes/YAMLSeq.ts +++ b/src/nodes/YAMLSeq.ts @@ -1,14 +1,14 @@ -import { createNode, CreateNodeContext } from '../doc/createNode.js' -import type { BlockSequence, FlowCollection } from '../parse/cst.js' -import type { Schema } from '../schema/Schema.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { stringifyCollection } from '../stringify/stringifyCollection.js' -import { Collection } from './Collection.js' -import { isScalar, SEQ } from './identity.js' -import type { ParsedNode, Range } from './Node.js' -import type { Pair } from './Pair.js' -import { isScalarValue, Scalar } from './Scalar.js' -import { toJS, ToJSContext } from './toJS.js' +import { createNode, CreateNodeContext } 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' +import { stringifyCollection } from '../stringify/stringifyCollection.ts' +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, Scalar } from './Scalar.ts' +import { toJS, ToJSContext } from './toJS.ts' export declare namespace YAMLSeq { interface Parsed< diff --git a/src/nodes/addPairToJSMap.ts b/src/nodes/addPairToJSMap.ts index 4ee9a395..1be92829 100644 --- a/src/nodes/addPairToJSMap.ts +++ b/src/nodes/addPairToJSMap.ts @@ -1,10 +1,10 @@ -import { warn } from '../log.js' -import { addMergeToJSMap, isMergeKey } from '../schema/yaml-1.1/merge.js' -import { createStringifyContext } from '../stringify/stringify.js' -import { isNode } from './identity.js' -import type { Pair } from './Pair.js' -import { toJS, ToJSContext } from './toJS.js' -import type { MapLike } from './YAMLMap.js' +import { warn } from '../log.ts' +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, ToJSContext } from './toJS.ts' +import type { MapLike } from './YAMLMap.ts' export function addPairToJSMap( ctx: ToJSContext | undefined, diff --git a/src/nodes/identity.ts b/src/nodes/identity.ts index f7a6eb43..17fa55bb 100644 --- a/src/nodes/identity.ts +++ b/src/nodes/identity.ts @@ -1,10 +1,10 @@ -import type { Document } from '../doc/Document.js' -import type { Alias } from './Alias.js' -import type { Node } from './Node.js' -import type { Pair } from './Pair.js' -import type { Scalar } from './Scalar.js' -import type { YAMLMap } from './YAMLMap.js' -import type { YAMLSeq } from './YAMLSeq.js' +import type { Document } from '../doc/Document.ts' +import type { Alias } from './Alias.ts' +import type { Node } from './Node.ts' +import type { Pair } from './Pair.ts' +import type { Scalar } from './Scalar.ts' +import type { YAMLMap } from './YAMLMap.ts' +import type { YAMLSeq } from './YAMLSeq.ts' export const ALIAS = Symbol.for('yaml.alias') export const DOC = Symbol.for('yaml.document') diff --git a/src/nodes/toJS.ts b/src/nodes/toJS.ts index ac7d3944..5732668e 100644 --- a/src/nodes/toJS.ts +++ b/src/nodes/toJS.ts @@ -1,6 +1,6 @@ -import type { Document } from '../doc/Document.js' -import { hasAnchor } from './identity.js' -import type { Node } from './Node.js' +import type { Document } from '../doc/Document.ts' +import { hasAnchor } from './identity.ts' +import type { Node } from './Node.ts' export interface AnchorData { aliasCount: number diff --git a/src/options.ts b/src/options.ts index b586e206..2b8a0585 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,13 +1,13 @@ -import type { Reviver } from './doc/applyReviver.js' -import type { Directives } from './doc/directives.js' -import type { LogLevelId } from './log.js' -import type { ParsedNode } from './nodes/Node.js' -import type { Pair } from './nodes/Pair.js' -import type { Scalar } from './nodes/Scalar.js' -import type { LineCounter } from './parse/line-counter.js' -import type { Schema } from './schema/Schema.js' -import type { Tags } from './schema/tags.js' -import type { CollectionTag, ScalarTag } from './schema/types.js' +import type { Reviver } from './doc/applyReviver.ts' +import type { Directives } from './doc/directives.ts' +import type { LogLevelId } from './log.ts' +import type { ParsedNode } from './nodes/Node.ts' +import type { Pair } from './nodes/Pair.ts' +import type { Scalar } from './nodes/Scalar.ts' +import type { LineCounter } from './parse/line-counter.ts' +import type { Schema } from './schema/Schema.ts' +import type { Tags } from './schema/tags.ts' +import type { CollectionTag, ScalarTag } from './schema/types.ts' export type ParseOptions = { /** diff --git a/src/parse/cst-scalar.ts b/src/parse/cst-scalar.ts index c70c3755..73c653ae 100644 --- a/src/parse/cst-scalar.ts +++ b/src/parse/cst-scalar.ts @@ -1,13 +1,13 @@ -import type { ComposeContext } from '../compose/compose-node.js' -import type { ComposeErrorHandler } from '../compose/composer.js' -import { resolveBlockScalar } from '../compose/resolve-block-scalar.js' -import { resolveFlowScalar } from '../compose/resolve-flow-scalar.js' -import { ErrorCode, YAMLParseError } from '../errors.js' -import { Range } from '../nodes/Node.js' -import type { Scalar } from '../nodes/Scalar.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { stringifyString } from '../stringify/stringifyString.js' -import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst.js' +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 { ErrorCode, YAMLParseError } from '../errors.ts' +import { 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' +import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst.ts' /** * If `token` is a CST flow or block scalar, determine its string value and a few other attributes. diff --git a/src/parse/cst-stringify.ts b/src/parse/cst-stringify.ts index 511c082c..e428c2c7 100644 --- a/src/parse/cst-stringify.ts +++ b/src/parse/cst-stringify.ts @@ -1,4 +1,4 @@ -import type { CollectionItem, Token } from './cst.js' +import type { CollectionItem, Token } from './cst.ts' /** * Stringify a CST document, token, or collection item diff --git a/src/parse/cst-visit.ts b/src/parse/cst-visit.ts index f3a48ce6..01b9aa9d 100644 --- a/src/parse/cst-visit.ts +++ b/src/parse/cst-visit.ts @@ -1,4 +1,4 @@ -import type { CollectionItem, Document } from './cst.js' +import type { CollectionItem, Document } from './cst.ts' const BREAK = Symbol('break visit') const SKIP = Symbol('skip children') diff --git a/src/parse/cst.ts b/src/parse/cst.ts index 82b66dee..6965ffaa 100644 --- a/src/parse/cst.ts +++ b/src/parse/cst.ts @@ -2,9 +2,9 @@ export { createScalarToken, resolveAsScalar, setScalarValue -} from './cst-scalar.js' -export { stringify } from './cst-stringify.js' -export { visit, Visitor, VisitPath } from './cst-visit.js' +} from './cst-scalar.ts' +export { stringify } from './cst-stringify.ts' +export { visit, Visitor, VisitPath } from './cst-visit.ts' export interface SourceToken { type: diff --git a/src/parse/lexer.ts b/src/parse/lexer.ts index af06ee54..ebe7f137 100644 --- a/src/parse/lexer.ts +++ b/src/parse/lexer.ts @@ -66,7 +66,7 @@ plain-scalar(is-flow, min) [else] -> plain-scalar(min) */ -import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.js' +import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.ts' type State = | 'stream' diff --git a/src/parse/parser.ts b/src/parse/parser.ts index 6385186a..883f0eb2 100644 --- a/src/parse/parser.ts +++ b/src/parse/parser.ts @@ -11,8 +11,8 @@ import { prettyToken, tokenType, TokenType -} from './cst.js' -import { Lexer } from './lexer.js' +} from './cst.ts' +import { Lexer } from './lexer.ts' function includesToken(list: SourceToken[], type: SourceToken['type']) { for (let i = 0; i < list.length; ++i) if (list[i].type === type) return true diff --git a/src/public-api.ts b/src/public-api.ts index a5e05327..2202b21e 100644 --- a/src/public-api.ts +++ b/src/public-api.ts @@ -1,10 +1,10 @@ -import { Composer } from './compose/composer.js' -import type { Reviver } from './doc/applyReviver.js' -import { Document, Replacer } from './doc/Document.js' -import { prettifyError, YAMLParseError } from './errors.js' -import { warn } from './log.js' -import { isDocument } from './nodes/identity.js' -import type { Node, ParsedNode } from './nodes/Node.js' +import { Composer } from './compose/composer.ts' +import type { Reviver } from './doc/applyReviver.ts' +import { Document, Replacer } from './doc/Document.ts' +import { prettifyError, YAMLParseError } from './errors.ts' +import { warn } from './log.ts' +import { isDocument } from './nodes/identity.ts' +import type { Node, ParsedNode } from './nodes/Node.ts' import type { CreateNodeOptions, DocumentOptions, @@ -12,9 +12,9 @@ import type { SchemaOptions, ToJSOptions, ToStringOptions -} from './options.js' -import { LineCounter } from './parse/line-counter.js' -import { Parser } from './parse/parser.js' +} from './options.ts' +import { LineCounter } from './parse/line-counter.ts' +import { Parser } from './parse/parser.ts' export interface EmptyStream extends Array, diff --git a/src/schema/Schema.ts b/src/schema/Schema.ts index 209e23bd..de6a1acf 100644 --- a/src/schema/Schema.ts +++ b/src/schema/Schema.ts @@ -1,11 +1,11 @@ -import { MAP, SCALAR, SEQ } from '../nodes/identity.js' -import type { Pair } from '../nodes/Pair.js' -import type { SchemaOptions, ToStringOptions } from '../options.js' -import { map } from './common/map.js' -import { seq } from './common/seq.js' -import { string } from './common/string.js' -import { coreKnownTags, getTags } from './tags.js' -import type { CollectionTag, ScalarTag } from './types.js' +import { MAP, SCALAR, SEQ } from '../nodes/identity.ts' +import type { Pair } from '../nodes/Pair.ts' +import type { SchemaOptions, ToStringOptions } from '../options.ts' +import { map } from './common/map.ts' +import { seq } from './common/seq.ts' +import { string } from './common/string.ts' +import { coreKnownTags, getTags } from './tags.ts' +import type { CollectionTag, ScalarTag } from './types.ts' const sortMapEntriesByKey = (a: Pair, b: Pair) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0 diff --git a/src/schema/common/map.ts b/src/schema/common/map.ts index 8583d553..3f9a22e0 100644 --- a/src/schema/common/map.ts +++ b/src/schema/common/map.ts @@ -1,6 +1,6 @@ -import { isMap } from '../../nodes/identity.js' -import { YAMLMap } from '../../nodes/YAMLMap.js' -import type { CollectionTag } from '../types.js' +import { isMap } from '../../nodes/identity.ts' +import { YAMLMap } from '../../nodes/YAMLMap.ts' +import type { CollectionTag } from '../types.ts' export const map: CollectionTag = { collection: 'map', diff --git a/src/schema/common/null.ts b/src/schema/common/null.ts index b8ad7dfd..082d52ee 100644 --- a/src/schema/common/null.ts +++ b/src/schema/common/null.ts @@ -1,5 +1,5 @@ -import { Scalar } from '../../nodes/Scalar.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import type { ScalarTag } from '../types.ts' export const nullTag: ScalarTag & { test: RegExp } = { identify: value => value == null, diff --git a/src/schema/common/seq.ts b/src/schema/common/seq.ts index 8bdcab74..401e9c74 100644 --- a/src/schema/common/seq.ts +++ b/src/schema/common/seq.ts @@ -1,6 +1,6 @@ -import { isSeq } from '../../nodes/identity.js' -import { YAMLSeq } from '../../nodes/YAMLSeq.js' -import type { CollectionTag } from '../types.js' +import { isSeq } from '../../nodes/identity.ts' +import { YAMLSeq } from '../../nodes/YAMLSeq.ts' +import type { CollectionTag } from '../types.ts' export const seq: CollectionTag = { collection: 'seq', diff --git a/src/schema/common/string.ts b/src/schema/common/string.ts index 2d4a091e..6ae0b4ec 100644 --- a/src/schema/common/string.ts +++ b/src/schema/common/string.ts @@ -1,5 +1,5 @@ -import { stringifyString } from '../../stringify/stringifyString.js' -import type { ScalarTag } from '../types.js' +import { stringifyString } from '../../stringify/stringifyString.ts' +import type { ScalarTag } from '../types.ts' export const string: ScalarTag = { identify: value => typeof value === 'string', diff --git a/src/schema/core/bool.ts b/src/schema/core/bool.ts index 26daef6f..279dd925 100644 --- a/src/schema/core/bool.ts +++ b/src/schema/core/bool.ts @@ -1,5 +1,5 @@ -import { Scalar } from '../../nodes/Scalar.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import type { ScalarTag } from '../types.ts' export const boolTag: ScalarTag & { test: RegExp } = { identify: value => typeof value === 'boolean', diff --git a/src/schema/core/float.ts b/src/schema/core/float.ts index fad731a9..56146a48 100644 --- a/src/schema/core/float.ts +++ b/src/schema/core/float.ts @@ -1,6 +1,6 @@ -import { Scalar } from '../../nodes/Scalar.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' export const floatNaN: ScalarTag = { identify: value => typeof value === 'number', diff --git a/src/schema/core/int.ts b/src/schema/core/int.ts index 8f5f16d1..a5bcd2ce 100644 --- a/src/schema/core/int.ts +++ b/src/schema/core/int.ts @@ -1,7 +1,7 @@ -import type { Scalar } from '../../nodes/Scalar.js' -import type { ParseOptions } from '../../options.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import type { Scalar } from '../../nodes/Scalar.ts' +import type { ParseOptions } from '../../options.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' const intIdentify = (value: unknown): value is number | bigint => typeof value === 'bigint' || Number.isInteger(value) diff --git a/src/schema/core/schema.ts b/src/schema/core/schema.ts index 37d64cd9..98698ded 100644 --- a/src/schema/core/schema.ts +++ b/src/schema/core/schema.ts @@ -1,10 +1,10 @@ -import { map } from '../common/map.js' -import { nullTag } from '../common/null.js' -import { seq } from '../common/seq.js' -import { string } from '../common/string.js' -import { boolTag } from './bool.js' -import { float, floatExp, floatNaN } from './float.js' -import { int, intHex, intOct } from './int.js' +import { map } from '../common/map.ts' +import { nullTag } from '../common/null.ts' +import { seq } from '../common/seq.ts' +import { string } from '../common/string.ts' +import { boolTag } from './bool.ts' +import { float, floatExp, floatNaN } from './float.ts' +import { int, intHex, intOct } from './int.ts' export const schema = [ map, diff --git a/src/schema/json/schema.ts b/src/schema/json/schema.ts index d8424012..04a384d4 100644 --- a/src/schema/json/schema.ts +++ b/src/schema/json/schema.ts @@ -1,7 +1,7 @@ -import { Scalar } from '../../nodes/Scalar.js' -import { map } from '../common/map.js' -import { seq } from '../common/seq.js' -import { CollectionTag, ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import { map } from '../common/map.ts' +import { seq } from '../common/seq.ts' +import { CollectionTag, ScalarTag } from '../types.ts' function intIdentify(value: unknown): value is number | bigint { return typeof value === 'bigint' || Number.isInteger(value) diff --git a/src/schema/tags.ts b/src/schema/tags.ts index 483f9169..3d575e44 100644 --- a/src/schema/tags.ts +++ b/src/schema/tags.ts @@ -1,21 +1,21 @@ -import { SchemaOptions } from '../options.js' -import { map } from './common/map.js' -import { nullTag } from './common/null.js' -import { seq } from './common/seq.js' -import { string } from './common/string.js' -import { boolTag } from './core/bool.js' -import { float, floatExp, floatNaN } from './core/float.js' -import { int, intHex, intOct } from './core/int.js' -import { schema as core } from './core/schema.js' -import { schema as json } from './json/schema.js' -import { binary } from './yaml-1.1/binary.js' -import { merge } from './yaml-1.1/merge.js' -import { omap } from './yaml-1.1/omap.js' -import { pairs } from './yaml-1.1/pairs.js' -import { schema as yaml11 } from './yaml-1.1/schema.js' -import { set } from './yaml-1.1/set.js' -import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp.js' -import type { CollectionTag, ScalarTag } from './types.js' +import { SchemaOptions } from '../options.ts' +import { map } from './common/map.ts' +import { nullTag } from './common/null.ts' +import { seq } from './common/seq.ts' +import { string } from './common/string.ts' +import { boolTag } from './core/bool.ts' +import { float, floatExp, floatNaN } from './core/float.ts' +import { int, intHex, intOct } from './core/int.ts' +import { schema as core } from './core/schema.ts' +import { schema as json } from './json/schema.ts' +import { binary } from './yaml-1.1/binary.ts' +import { merge } from './yaml-1.1/merge.ts' +import { omap } from './yaml-1.1/omap.ts' +import { pairs } from './yaml-1.1/pairs.ts' +import { schema as yaml11 } from './yaml-1.1/schema.ts' +import { set } from './yaml-1.1/set.ts' +import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp.ts' +import type { CollectionTag, ScalarTag } from './types.ts' const schemas = new Map>([ ['core', core], diff --git a/src/schema/types.ts b/src/schema/types.ts index 0a400176..0583ffc3 100644 --- a/src/schema/types.ts +++ b/src/schema/types.ts @@ -1,11 +1,11 @@ -import type { CreateNodeContext } from '../doc/createNode.js' -import type { Node } from '../nodes/Node.js' -import type { Scalar } from '../nodes/Scalar.js' -import type { YAMLMap } from '../nodes/YAMLMap.js' -import type { YAMLSeq } from '../nodes/YAMLSeq.js' -import type { ParseOptions } from '../options.js' -import type { StringifyContext } from '../stringify/stringify.js' -import type { Schema } from './Schema.js' +import type { CreateNodeContext } from '../doc/createNode.ts' +import type { Node } from '../nodes/Node.ts' +import type { Scalar } from '../nodes/Scalar.ts' +import type { YAMLMap } from '../nodes/YAMLMap.ts' +import type { YAMLSeq } from '../nodes/YAMLSeq.ts' +import type { ParseOptions } from '../options.ts' +import type { StringifyContext } from '../stringify/stringify.ts' +import type { Schema } from './Schema.ts' interface TagBase { /** diff --git a/src/schema/yaml-1.1/binary.ts b/src/schema/yaml-1.1/binary.ts index 1d40ddfc..5ed97cc2 100644 --- a/src/schema/yaml-1.1/binary.ts +++ b/src/schema/yaml-1.1/binary.ts @@ -1,6 +1,6 @@ -import { Scalar } from '../../nodes/Scalar.js' -import { stringifyString } from '../../stringify/stringifyString.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import { stringifyString } from '../../stringify/stringifyString.ts' +import type { ScalarTag } from '../types.ts' export const binary: ScalarTag = { identify: value => value instanceof Uint8Array, // Buffer inherits from Uint8Array diff --git a/src/schema/yaml-1.1/bool.ts b/src/schema/yaml-1.1/bool.ts index 10d68d40..c7e2bb7f 100644 --- a/src/schema/yaml-1.1/bool.ts +++ b/src/schema/yaml-1.1/bool.ts @@ -1,6 +1,6 @@ -import { Scalar } from '../../nodes/Scalar.js' -import type { StringifyContext } from '../../stringify/stringify.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import type { StringifyContext } from '../../stringify/stringify.ts' +import type { ScalarTag } from '../types.ts' function boolStringify({ value, source }: Scalar, ctx: StringifyContext) { const boolObj = value ? trueTag : falseTag diff --git a/src/schema/yaml-1.1/float.ts b/src/schema/yaml-1.1/float.ts index 87e52b63..88ea3baf 100644 --- a/src/schema/yaml-1.1/float.ts +++ b/src/schema/yaml-1.1/float.ts @@ -1,6 +1,6 @@ -import { Scalar } from '../../nodes/Scalar.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' export const floatNaN: ScalarTag = { identify: value => typeof value === 'number', diff --git a/src/schema/yaml-1.1/int.ts b/src/schema/yaml-1.1/int.ts index 2dac5134..68b6450a 100644 --- a/src/schema/yaml-1.1/int.ts +++ b/src/schema/yaml-1.1/int.ts @@ -1,7 +1,7 @@ -import type { Scalar } from '../../nodes/Scalar.js' -import type { ParseOptions } from '../../options.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import type { Scalar } from '../../nodes/Scalar.ts' +import type { ParseOptions } from '../../options.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' const intIdentify = (value: unknown): value is number | bigint => typeof value === 'bigint' || Number.isInteger(value) diff --git a/src/schema/yaml-1.1/merge.ts b/src/schema/yaml-1.1/merge.ts index 68d4bce5..64484b10 100644 --- a/src/schema/yaml-1.1/merge.ts +++ b/src/schema/yaml-1.1/merge.ts @@ -1,8 +1,8 @@ -import { isAlias, isMap, isScalar, isSeq } from '../../nodes/identity.js' -import { Scalar } from '../../nodes/Scalar.js' -import type { ToJSContext } from '../../nodes/toJS.js' -import type { MapLike } from '../../nodes/YAMLMap.js' -import type { ScalarTag } from '../types.js' +import { isAlias, isMap, isScalar, isSeq } from '../../nodes/identity.ts' +import { Scalar } from '../../nodes/Scalar.ts' +import type { ToJSContext } from '../../nodes/toJS.ts' +import type { MapLike } from '../../nodes/YAMLMap.ts' +import type { ScalarTag } from '../types.ts' // If the value associated with a merge key is a single mapping node, each of // its key/value pairs is inserted into the current mapping, unless the key diff --git a/src/schema/yaml-1.1/omap.ts b/src/schema/yaml-1.1/omap.ts index f08b8fd0..95e1809c 100644 --- a/src/schema/yaml-1.1/omap.ts +++ b/src/schema/yaml-1.1/omap.ts @@ -1,11 +1,11 @@ -import { isPair, isScalar } from '../../nodes/identity.js' -import { toJS, ToJSContext } from '../../nodes/toJS.js' -import { YAMLMap } from '../../nodes/YAMLMap.js' -import { YAMLSeq } from '../../nodes/YAMLSeq.js' -import { CreateNodeContext } from '../../util.js' -import type { Schema } from '../Schema.js' -import { CollectionTag } from '../types.js' -import { createPairs, resolvePairs } from './pairs.js' +import { isPair, isScalar } from '../../nodes/identity.ts' +import { toJS, ToJSContext } from '../../nodes/toJS.ts' +import { YAMLMap } from '../../nodes/YAMLMap.ts' +import { YAMLSeq } from '../../nodes/YAMLSeq.ts' +import { CreateNodeContext } from '../../util.ts' +import type { Schema } from '../Schema.ts' +import { CollectionTag } from '../types.ts' +import { createPairs, resolvePairs } from './pairs.ts' export class YAMLOMap extends YAMLSeq { static tag = 'tag:yaml.org,2002:omap' diff --git a/src/schema/yaml-1.1/pairs.ts b/src/schema/yaml-1.1/pairs.ts index 248a847a..77e343f7 100644 --- a/src/schema/yaml-1.1/pairs.ts +++ b/src/schema/yaml-1.1/pairs.ts @@ -1,12 +1,12 @@ -import type { CreateNodeContext } from '../../doc/createNode.js' -import { isMap, isPair, isSeq } from '../../nodes/identity.js' -import type { ParsedNode } from '../../nodes/Node.js' -import { createPair, Pair } from '../../nodes/Pair.js' -import { Scalar } from '../../nodes/Scalar.js' -import { YAMLMap } from '../../nodes/YAMLMap.js' -import { YAMLSeq } from '../../nodes/YAMLSeq.js' -import type { Schema } from '../../schema/Schema.js' -import type { CollectionTag } from '../types.js' +import type { CreateNodeContext } from '../../doc/createNode.ts' +import { isMap, isPair, isSeq } from '../../nodes/identity.ts' +import type { ParsedNode } from '../../nodes/Node.ts' +import { createPair, Pair } from '../../nodes/Pair.ts' +import { Scalar } from '../../nodes/Scalar.ts' +import { YAMLMap } from '../../nodes/YAMLMap.ts' +import { YAMLSeq } from '../../nodes/YAMLSeq.ts' +import type { Schema } from '../../schema/Schema.ts' +import type { CollectionTag } from '../types.ts' export function resolvePairs( seq: diff --git a/src/schema/yaml-1.1/schema.ts b/src/schema/yaml-1.1/schema.ts index c7b700b9..85591b3a 100644 --- a/src/schema/yaml-1.1/schema.ts +++ b/src/schema/yaml-1.1/schema.ts @@ -1,16 +1,16 @@ -import { map } from '../common/map.js' -import { nullTag } from '../common/null.js' -import { seq } from '../common/seq.js' -import { string } from '../common/string.js' -import { binary } from './binary.js' -import { falseTag, trueTag } from './bool.js' -import { float, floatExp, floatNaN } from './float.js' -import { intBin, int, intHex, intOct } from './int.js' -import { merge } from './merge.js' -import { omap } from './omap.js' -import { pairs } from './pairs.js' -import { set } from './set.js' -import { intTime, floatTime, timestamp } from './timestamp.js' +import { map } from '../common/map.ts' +import { nullTag } from '../common/null.ts' +import { seq } from '../common/seq.ts' +import { string } from '../common/string.ts' +import { binary } from './binary.ts' +import { falseTag, trueTag } from './bool.ts' +import { float, floatExp, floatNaN } from './float.ts' +import { intBin, int, intHex, intOct } from './int.ts' +import { merge } from './merge.ts' +import { omap } from './omap.ts' +import { pairs } from './pairs.ts' +import { set } from './set.ts' +import { intTime, floatTime, timestamp } from './timestamp.ts' export const schema = [ map, diff --git a/src/schema/yaml-1.1/set.ts b/src/schema/yaml-1.1/set.ts index 33275a99..a2d29add 100644 --- a/src/schema/yaml-1.1/set.ts +++ b/src/schema/yaml-1.1/set.ts @@ -1,12 +1,12 @@ -import { isMap, isPair, isScalar } from '../../nodes/identity.js' -import { Pair } from '../../nodes/Pair.js' -import { Scalar } from '../../nodes/Scalar.js' -import { ToJSContext } from '../../nodes/toJS.js' -import { findPair, YAMLMap } from '../../nodes/YAMLMap.js' -import type { Schema } from '../../schema/Schema.js' -import type { StringifyContext } from '../../stringify/stringify.js' -import { CreateNodeContext, createPair } from '../../util.js' -import type { CollectionTag } from '../types.js' +import { isMap, isPair, isScalar } from '../../nodes/identity.ts' +import { Pair } from '../../nodes/Pair.ts' +import { Scalar } from '../../nodes/Scalar.ts' +import { 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 { CreateNodeContext, createPair } from '../../util.ts' +import type { CollectionTag } from '../types.ts' export class YAMLSet extends YAMLMap | null> { static tag = 'tag:yaml.org,2002:set' diff --git a/src/schema/yaml-1.1/timestamp.ts b/src/schema/yaml-1.1/timestamp.ts index 2cdc79bc..b59d6c73 100644 --- a/src/schema/yaml-1.1/timestamp.ts +++ b/src/schema/yaml-1.1/timestamp.ts @@ -1,6 +1,6 @@ -import type { Scalar } from '../../nodes/Scalar.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import type { Scalar } from '../../nodes/Scalar.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' /** Internal types handle bigint as number, because TS can't figure it out. */ function parseSexagesimal(str: string, asBigInt?: B) { diff --git a/src/stringify/stringify.ts b/src/stringify/stringify.ts index 0c454709..e699f4c1 100644 --- a/src/stringify/stringify.ts +++ b/src/stringify/stringify.ts @@ -1,19 +1,19 @@ -import { anchorIsValid } from '../doc/anchors.js' -import type { Document } from '../doc/Document.js' -import type { Alias } from '../nodes/Alias.js' +import { anchorIsValid } from '../doc/anchors.ts' +import type { Document } from '../doc/Document.ts' +import type { Alias } from '../nodes/Alias.ts' import { isAlias, isCollection, isNode, isPair, isScalar -} from '../nodes/identity.js' -import type { Node } from '../nodes/Node.js' -import type { Scalar } from '../nodes/Scalar.js' -import type { ToStringOptions } from '../options.js' -import type { CollectionTag, ScalarTag } from '../schema/types.js' -import { stringifyComment } from './stringifyComment.js' -import { stringifyString } from './stringifyString.js' +} from '../nodes/identity.ts' +import type { Node } from '../nodes/Node.ts' +import type { Scalar } from '../nodes/Scalar.ts' +import type { ToStringOptions } from '../options.ts' +import type { CollectionTag, ScalarTag } from '../schema/types.ts' +import { stringifyComment } from './stringifyComment.ts' +import { stringifyString } from './stringifyString.ts' export type StringifyContext = { actualString?: boolean diff --git a/src/stringify/stringifyCollection.ts b/src/stringify/stringifyCollection.ts index 5c4291c0..d625262e 100644 --- a/src/stringify/stringifyCollection.ts +++ b/src/stringify/stringifyCollection.ts @@ -1,7 +1,7 @@ -import { Collection } from '../nodes/Collection.js' -import { isNode, isPair } from '../nodes/identity.js' -import { stringify, StringifyContext } from './stringify.js' -import { indentComment, lineComment } from './stringifyComment.js' +import { Collection } from '../nodes/Collection.ts' +import { isNode, isPair } from '../nodes/identity.ts' +import { stringify, StringifyContext } from './stringify.ts' +import { indentComment, lineComment } from './stringifyComment.ts' interface StringifyCollectionOptions { blockItemPrefix: string diff --git a/src/stringify/stringifyDocument.ts b/src/stringify/stringifyDocument.ts index ce7337b4..75af5f9d 100644 --- a/src/stringify/stringifyDocument.ts +++ b/src/stringify/stringifyDocument.ts @@ -1,13 +1,13 @@ -import type { Document } from '../doc/Document.js' -import { isNode } from '../nodes/identity.js' -import type { Node } from '../nodes/Node.js' -import type { ToStringOptions } from '../options.js' +import type { Document } from '../doc/Document.ts' +import { isNode } from '../nodes/identity.ts' +import type { Node } from '../nodes/Node.ts' +import type { ToStringOptions } from '../options.ts' import { createStringifyContext, stringify, StringifyContext -} from './stringify.js' -import { indentComment, lineComment } from './stringifyComment.js' +} from './stringify.ts' +import { indentComment, lineComment } from './stringifyComment.ts' export function stringifyDocument( doc: Readonly>, diff --git a/src/stringify/stringifyNumber.ts b/src/stringify/stringifyNumber.ts index b12d8459..455bc750 100644 --- a/src/stringify/stringifyNumber.ts +++ b/src/stringify/stringifyNumber.ts @@ -1,4 +1,4 @@ -import type { Scalar } from '../nodes/Scalar.js' +import type { Scalar } from '../nodes/Scalar.ts' export function stringifyNumber({ format, diff --git a/src/stringify/stringifyPair.ts b/src/stringify/stringifyPair.ts index 4ef6710f..b2ab996a 100644 --- a/src/stringify/stringifyPair.ts +++ b/src/stringify/stringifyPair.ts @@ -1,8 +1,8 @@ -import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.js' -import type { Pair } from '../nodes/Pair.js' -import { Scalar } from '../nodes/Scalar.js' -import { stringify, StringifyContext } from './stringify.js' -import { indentComment, lineComment } from './stringifyComment.js' +import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.ts' +import type { Pair } from '../nodes/Pair.ts' +import { Scalar } from '../nodes/Scalar.ts' +import { stringify, StringifyContext } from './stringify.ts' +import { indentComment, lineComment } from './stringifyComment.ts' export function stringifyPair( { key, value }: Readonly, diff --git a/src/stringify/stringifyString.ts b/src/stringify/stringifyString.ts index b21dedd2..e5c17fb4 100644 --- a/src/stringify/stringifyString.ts +++ b/src/stringify/stringifyString.ts @@ -1,13 +1,13 @@ -import { Scalar } from '../nodes/Scalar.js' +import { Scalar } from '../nodes/Scalar.ts' import { foldFlowLines, FoldOptions, FOLD_BLOCK, FOLD_FLOW, FOLD_QUOTED -} from './foldFlowLines.js' -import type { CollectionTag, ScalarTag } from '../schema/types.js' -import type { StringifyContext } from './stringify.js' +} from './foldFlowLines.ts' +import type { CollectionTag, ScalarTag } from '../schema/types.ts' +import type { StringifyContext } from './stringify.ts' interface StringifyScalar { value: string diff --git a/src/test-events.ts b/src/test-events.ts index ca7c6c83..93604910 100644 --- a/src/test-events.ts +++ b/src/test-events.ts @@ -1,4 +1,4 @@ -import { Document } from './doc/Document.js' +import { Document } from './doc/Document.ts' import { isAlias, isCollection, @@ -7,11 +7,11 @@ import { isPair, isScalar, isSeq -} from './nodes/identity.js' -import type { Node, ParsedNode } from './nodes/Node.js' -import type { Pair } from './nodes/Pair.js' -import { parseAllDocuments } from './public-api.js' -import { visit } from './visit.js' +} from './nodes/identity.ts' +import type { Node, ParsedNode } from './nodes/Node.ts' +import type { Pair } from './nodes/Pair.ts' +import { parseAllDocuments } from './public-api.ts' +import { visit } from './visit.ts' const scalarChar: Record = { BLOCK_FOLDED: '>', diff --git a/src/util.ts b/src/util.ts index ba7b59f1..a4cbf238 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,12 +1,12 @@ -export { createNode, CreateNodeContext } from './doc/createNode.js' -export { debug, LogLevelId, warn } from './log.js' -export { createPair } from './nodes/Pair.js' -export { findPair } from './nodes/YAMLMap.js' -export { toJS, ToJSContext } from './nodes/toJS.js' -export { map as mapTag } from './schema/common/map.js' -export { seq as seqTag } from './schema/common/seq.js' -export { string as stringTag } from './schema/common/string.js' -export { foldFlowLines, FoldOptions } from './stringify/foldFlowLines' -export { StringifyContext } from './stringify/stringify.js' -export { stringifyNumber } from './stringify/stringifyNumber.js' -export { stringifyString } from './stringify/stringifyString.js' +export { createNode, CreateNodeContext } from './doc/createNode.ts' +export { debug, LogLevelId, warn } from './log.ts' +export { createPair } from './nodes/Pair.ts' +export { findPair } from './nodes/YAMLMap.ts' +export { toJS, ToJSContext } from './nodes/toJS.ts' +export { map as mapTag } from './schema/common/map.ts' +export { seq as seqTag } from './schema/common/seq.ts' +export { string as stringTag } from './schema/common/string.ts' +export { foldFlowLines, FoldOptions } from './stringify/foldFlowLines.ts' +export { StringifyContext } from './stringify/stringify.ts' +export { stringifyNumber } from './stringify/stringifyNumber.ts' +export { stringifyString } from './stringify/stringifyString.ts' diff --git a/src/visit.ts b/src/visit.ts index e5291b36..95f775ad 100644 --- a/src/visit.ts +++ b/src/visit.ts @@ -1,5 +1,5 @@ -import type { Document } from './doc/Document.js' -import type { Alias } from './nodes/Alias.js' +import type { Document } from './doc/Document.ts' +import type { Alias } from './nodes/Alias.ts' import { isAlias, isCollection, @@ -9,12 +9,12 @@ import { isPair, isScalar, isSeq -} from './nodes/identity.js' -import { Node } from './nodes/Node.js' -import type { Pair } from './nodes/Pair.js' -import type { Scalar } from './nodes/Scalar.js' -import type { YAMLMap } from './nodes/YAMLMap.js' -import type { YAMLSeq } from './nodes/YAMLSeq.js' +} from './nodes/identity.ts' +import { Node } from './nodes/Node.ts' +import type { Pair } from './nodes/Pair.ts' +import type { Scalar } from './nodes/Scalar.ts' +import type { YAMLMap } from './nodes/YAMLMap.ts' +import type { YAMLSeq } from './nodes/YAMLSeq.ts' const BREAK = Symbol('break visit') const SKIP = Symbol('skip children') From 39350a96118f64856c2325ff0674f8796e82502b Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Nov 2024 11:00:17 +0200 Subject: [PATCH 4/8] style: Always use type keyword when approprite on imports & exports --- eslint.config.mjs | 5 +++++ src/compose/compose-collection.ts | 2 +- src/compose/compose-doc.ts | 2 +- src/compose/composer.ts | 2 +- src/compose/resolve-block-map.ts | 2 +- src/compose/resolve-block-scalar.ts | 2 +- src/compose/resolve-block-seq.ts | 2 +- src/compose/resolve-flow-collection.ts | 4 ++-- src/compose/resolve-flow-scalar.ts | 4 ++-- src/compose/util-flow-indent-check.ts | 4 ++-- src/doc/Document.ts | 4 ++-- src/doc/anchors.ts | 2 +- src/index.ts | 12 ++++++------ src/nodes/Alias.ts | 4 ++-- src/nodes/Node.ts | 4 ++-- src/nodes/Pair.ts | 2 +- src/nodes/Scalar.ts | 4 ++-- src/nodes/YAMLMap.ts | 4 ++-- src/nodes/YAMLSeq.ts | 6 +++--- src/nodes/addPairToJSMap.ts | 2 +- src/parse/cst-scalar.ts | 4 ++-- src/parse/cst.ts | 3 ++- src/parse/parser.ts | 20 ++++++++++---------- src/public-api.ts | 2 +- src/schema/json/schema.ts | 2 +- src/schema/tags.ts | 4 ++-- src/schema/yaml-1.1/omap.ts | 6 +++--- src/schema/yaml-1.1/pairs.ts | 2 +- src/schema/yaml-1.1/set.ts | 6 +++--- src/stringify/stringifyCollection.ts | 4 ++-- src/stringify/stringifyDocument.ts | 2 +- src/stringify/stringifyPair.ts | 2 +- src/stringify/stringifyString.ts | 8 ++++---- src/test-events.ts | 2 +- src/util.ts | 15 ++++++++++----- src/visit.ts | 2 +- 36 files changed, 84 insertions(+), 73 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index a07a4464..8d15f809 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -52,6 +52,11 @@ export default [ 'no-template-curly-in-string': 'warn', 'no-var': 'error', 'prefer-const': ['warn', { destructuring: 'all' }], + '@typescript-eslint/consistent-type-exports': 'error', + '@typescript-eslint/consistent-type-imports': [ + 'error', + { fixStyle: 'inline-type-imports' } + ], '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-namespace': 'off', '@typescript-eslint/no-unsafe-argument': 'off', diff --git a/src/compose/compose-collection.ts b/src/compose/compose-collection.ts index 6911c5ab..08f0e1a9 100644 --- a/src/compose/compose-collection.ts +++ b/src/compose/compose-collection.ts @@ -9,7 +9,7 @@ import type { FlowCollection, SourceToken } from '../parse/cst.ts' -import { 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' diff --git a/src/compose/compose-doc.ts b/src/compose/compose-doc.ts index 336c0524..f70797b3 100644 --- a/src/compose/compose-doc.ts +++ b/src/compose/compose-doc.ts @@ -8,7 +8,7 @@ import type { } from '../options.ts' import type * as CST from '../parse/cst.ts' import { - ComposeContext, + type ComposeContext, composeEmptyNode, composeNode } from './compose-node.ts' diff --git a/src/compose/composer.ts b/src/compose/composer.ts index ba9c3859..493cceb2 100644 --- a/src/compose/composer.ts +++ b/src/compose/composer.ts @@ -1,6 +1,6 @@ import { Directives } from '../doc/directives.ts' import { Document } from '../doc/Document.ts' -import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.ts' +import { type ErrorCode, YAMLParseError, YAMLWarning } from '../errors.ts' import { isCollection, isPair } from '../nodes/identity.ts' import type { ParsedNode, Range } from '../nodes/Node.ts' import type { diff --git a/src/compose/resolve-block-map.ts b/src/compose/resolve-block-map.ts index 38101037..8ec303f9 100644 --- a/src/compose/resolve-block-map.ts +++ b/src/compose/resolve-block-map.ts @@ -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 { 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' diff --git a/src/compose/resolve-block-scalar.ts b/src/compose/resolve-block-scalar.ts index 9200c03f..06c9c7e0 100644 --- a/src/compose/resolve-block-scalar.ts +++ b/src/compose/resolve-block-scalar.ts @@ -1,4 +1,4 @@ -import { 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' diff --git a/src/compose/resolve-block-seq.ts b/src/compose/resolve-block-seq.ts index e888f0ec..03814810 100644 --- a/src/compose/resolve-block-seq.ts +++ b/src/compose/resolve-block-seq.ts @@ -1,6 +1,6 @@ import { YAMLSeq } from '../nodes/YAMLSeq.ts' import type { BlockSequence } from '../parse/cst.ts' -import { 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' diff --git a/src/compose/resolve-flow-collection.ts b/src/compose/resolve-flow-collection.ts index bc0cd7aa..0d51d73e 100644 --- a/src/compose/resolve-flow-collection.ts +++ b/src/compose/resolve-flow-collection.ts @@ -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 { Schema } from '../schema/Schema.ts' -import { 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' diff --git a/src/compose/resolve-flow-scalar.ts b/src/compose/resolve-flow-scalar.ts index a352cc96..49582442 100644 --- a/src/compose/resolve-flow-scalar.ts +++ b/src/compose/resolve-flow-scalar.ts @@ -1,5 +1,5 @@ -import { ErrorCode } from '../errors.ts' -import { 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' diff --git a/src/compose/util-flow-indent-check.ts b/src/compose/util-flow-indent-check.ts index 0d23291f..aece0698 100644 --- a/src/compose/util-flow-indent-check.ts +++ b/src/compose/util-flow-indent-check.ts @@ -1,5 +1,5 @@ -import { Token } from '../parse/cst.ts' -import { 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( diff --git a/src/doc/Document.ts b/src/doc/Document.ts index 3f61eac5..66b52895 100644 --- a/src/doc/Document.ts +++ b/src/doc/Document.ts @@ -11,7 +11,7 @@ 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, ToJSContext } from '../nodes/toJS.ts' +import { toJS, type ToJSContext } from '../nodes/toJS.ts' import type { YAMLMap } from '../nodes/YAMLMap.ts' import type { YAMLSeq } from '../nodes/YAMLSeq.ts' import type { @@ -26,7 +26,7 @@ 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, CreateNodeContext } from './createNode.ts' +import { createNode, type CreateNodeContext } from './createNode.ts' import { Directives } from './directives.ts' export type Replacer = any[] | ((key: any, value: any) => unknown) diff --git a/src/doc/anchors.ts b/src/doc/anchors.ts index d2ea6537..af996d47 100644 --- a/src/doc/anchors.ts +++ b/src/doc/anchors.ts @@ -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 { CreateNodeContext } from './createNode.ts' +import { type CreateNodeContext } from './createNode.ts' import type { Document } from './Document.ts' /** diff --git a/src/index.ts b/src/index.ts index 134f7184..7cb9b7f2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,8 @@ export { Composer } from './compose/composer.ts' export { Document } from './doc/Document.ts' export { Schema } from './schema/Schema.ts' -export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.ts' +export type { ErrorCode } from './errors.ts' +export { YAMLError, YAMLParseError, YAMLWarning } from './errors.ts' export { Alias } from './nodes/Alias.ts' export { @@ -16,7 +17,7 @@ export { isScalar, isSeq } from './nodes/identity.ts' -export { Node, ParsedNode, Range } from './nodes/Node.ts' +export type { Node, ParsedNode, Range } from './nodes/Node.ts' export { Pair } from './nodes/Pair.ts' export { Scalar } from './nodes/Scalar.ts' export { YAMLMap } from './nodes/YAMLMap.ts' @@ -36,8 +37,8 @@ export { Lexer } from './parse/lexer.ts' export { LineCounter } from './parse/line-counter.ts' export { Parser } from './parse/parser.ts' +export type { EmptyStream } from './public-api.ts' export { - EmptyStream, parse, parseAllDocuments, parseDocument, @@ -49,11 +50,10 @@ export type { CollectionTag, ScalarTag } from './schema/types.ts' export type { YAMLOMap } from './schema/yaml-1.1/omap.ts' export type { YAMLSet } from './schema/yaml-1.1/set.ts' -export { +export type { asyncVisitor, asyncVisitorFn, - visit, - visitAsync, visitor, visitorFn } from './visit.ts' +export { visit, visitAsync } from './visit.ts' diff --git a/src/nodes/Alias.ts b/src/nodes/Alias.ts index 2e39b278..969fd7b5 100644 --- a/src/nodes/Alias.ts +++ b/src/nodes/Alias.ts @@ -4,9 +4,9 @@ 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 { Node, NodeBase, Range } from './Node.ts' +import { type Node, NodeBase, type Range } from './Node.ts' import type { Scalar } from './Scalar.ts' -import { toJS, ToJSContext } from './toJS.ts' +import { toJS, type ToJSContext } from './toJS.ts' import type { YAMLMap } from './YAMLMap.ts' import type { YAMLSeq } from './YAMLSeq.ts' diff --git a/src/nodes/Node.ts b/src/nodes/Node.ts index 8d861938..1e46d490 100644 --- a/src/nodes/Node.ts +++ b/src/nodes/Node.ts @@ -1,12 +1,12 @@ import { applyReviver } from '../doc/applyReviver.ts' import type { Document } from '../doc/Document.ts' import type { ToJSOptions } from '../options.ts' -import { 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, ToJSContext } from './toJS.ts' +import { toJS, type ToJSContext } from './toJS.ts' import type { MapLike, YAMLMap } from './YAMLMap.ts' import type { YAMLSeq } from './YAMLSeq.ts' diff --git a/src/nodes/Pair.ts b/src/nodes/Pair.ts index eb697732..5eadfcf1 100644 --- a/src/nodes/Pair.ts +++ b/src/nodes/Pair.ts @@ -1,4 +1,4 @@ -import { createNode, CreateNodeContext } from '../doc/createNode.ts' +import { createNode, type CreateNodeContext } 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' diff --git a/src/nodes/Scalar.ts b/src/nodes/Scalar.ts index e354eb29..d2f862b8 100644 --- a/src/nodes/Scalar.ts +++ b/src/nodes/Scalar.ts @@ -1,7 +1,7 @@ import type { BlockScalar, FlowScalar } from '../parse/cst.ts' import { SCALAR } from './identity.ts' -import { NodeBase, Range } from './Node.ts' -import { toJS, ToJSContext } from './toJS.ts' +import { NodeBase, type Range } from './Node.ts' +import { toJS, type ToJSContext } from './toJS.ts' export const isScalarValue = (value: unknown) => !value || (typeof value !== 'function' && typeof value !== 'object') diff --git a/src/nodes/YAMLMap.ts b/src/nodes/YAMLMap.ts index b73b8056..db8ffff7 100644 --- a/src/nodes/YAMLMap.ts +++ b/src/nodes/YAMLMap.ts @@ -2,13 +2,13 @@ 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 { 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, Scalar } from './Scalar.ts' +import { isScalarValue, type Scalar } from './Scalar.ts' import type { ToJSContext } from './toJS.ts' export type MapLike = diff --git a/src/nodes/YAMLSeq.ts b/src/nodes/YAMLSeq.ts index 61bc1270..31fd20e5 100644 --- a/src/nodes/YAMLSeq.ts +++ b/src/nodes/YAMLSeq.ts @@ -1,4 +1,4 @@ -import { createNode, CreateNodeContext } from '../doc/createNode.ts' +import { createNode, type CreateNodeContext } 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' @@ -7,8 +7,8 @@ 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, Scalar } from './Scalar.ts' -import { toJS, ToJSContext } from './toJS.ts' +import { isScalarValue, type Scalar } from './Scalar.ts' +import { toJS, type ToJSContext } from './toJS.ts' export declare namespace YAMLSeq { interface Parsed< diff --git a/src/nodes/addPairToJSMap.ts b/src/nodes/addPairToJSMap.ts index 1be92829..73568ca1 100644 --- a/src/nodes/addPairToJSMap.ts +++ b/src/nodes/addPairToJSMap.ts @@ -3,7 +3,7 @@ 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, ToJSContext } from './toJS.ts' +import { toJS, type ToJSContext } from './toJS.ts' import type { MapLike } from './YAMLMap.ts' export function addPairToJSMap( diff --git a/src/parse/cst-scalar.ts b/src/parse/cst-scalar.ts index 73c653ae..1854cf7a 100644 --- a/src/parse/cst-scalar.ts +++ b/src/parse/cst-scalar.ts @@ -2,8 +2,8 @@ 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 { ErrorCode, YAMLParseError } from '../errors.ts' -import { Range } from '../nodes/Node.ts' +import { type ErrorCode, 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' diff --git a/src/parse/cst.ts b/src/parse/cst.ts index 6965ffaa..c73cdcc3 100644 --- a/src/parse/cst.ts +++ b/src/parse/cst.ts @@ -4,7 +4,8 @@ export { setScalarValue } from './cst-scalar.ts' export { stringify } from './cst-stringify.ts' -export { visit, Visitor, VisitPath } from './cst-visit.ts' +export type { Visitor, VisitPath } from './cst-visit.ts' +export { visit } from './cst-visit.ts' export interface SourceToken { type: diff --git a/src/parse/parser.ts b/src/parse/parser.ts index 883f0eb2..415020c7 100644 --- a/src/parse/parser.ts +++ b/src/parse/parser.ts @@ -1,16 +1,16 @@ import { - SourceToken, - Token, - FlowScalar, - FlowCollection, - Document, - BlockMap, - BlockScalar, - BlockSequence, - DocumentEnd, + type SourceToken, + type Token, + type FlowScalar, + type FlowCollection, + type Document, + type BlockMap, + type BlockScalar, + type BlockSequence, + type DocumentEnd, prettyToken, tokenType, - TokenType + type TokenType } from './cst.ts' import { Lexer } from './lexer.ts' diff --git a/src/public-api.ts b/src/public-api.ts index 2202b21e..33a4ddb4 100644 --- a/src/public-api.ts +++ b/src/public-api.ts @@ -1,6 +1,6 @@ import { Composer } from './compose/composer.ts' import type { Reviver } from './doc/applyReviver.ts' -import { Document, Replacer } from './doc/Document.ts' +import { Document, type Replacer } from './doc/Document.ts' import { prettifyError, YAMLParseError } from './errors.ts' import { warn } from './log.ts' import { isDocument } from './nodes/identity.ts' diff --git a/src/schema/json/schema.ts b/src/schema/json/schema.ts index 04a384d4..fb72cdc0 100644 --- a/src/schema/json/schema.ts +++ b/src/schema/json/schema.ts @@ -1,7 +1,7 @@ import { Scalar } from '../../nodes/Scalar.ts' import { map } from '../common/map.ts' import { seq } from '../common/seq.ts' -import { CollectionTag, ScalarTag } from '../types.ts' +import type { CollectionTag, ScalarTag } from '../types.ts' function intIdentify(value: unknown): value is number | bigint { return typeof value === 'bigint' || Number.isInteger(value) diff --git a/src/schema/tags.ts b/src/schema/tags.ts index 3d575e44..15e50ebf 100644 --- a/src/schema/tags.ts +++ b/src/schema/tags.ts @@ -1,4 +1,4 @@ -import { SchemaOptions } from '../options.ts' +import type { SchemaOptions } from '../options.ts' import { map } from './common/map.ts' import { nullTag } from './common/null.ts' import { seq } from './common/seq.ts' @@ -8,6 +8,7 @@ import { float, floatExp, floatNaN } from './core/float.ts' import { int, intHex, intOct } from './core/int.ts' import { schema as core } from './core/schema.ts' import { schema as json } from './json/schema.ts' +import type { CollectionTag, ScalarTag } from './types.ts' import { binary } from './yaml-1.1/binary.ts' import { merge } from './yaml-1.1/merge.ts' import { omap } from './yaml-1.1/omap.ts' @@ -15,7 +16,6 @@ import { pairs } from './yaml-1.1/pairs.ts' import { schema as yaml11 } from './yaml-1.1/schema.ts' import { set } from './yaml-1.1/set.ts' import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp.ts' -import type { CollectionTag, ScalarTag } from './types.ts' const schemas = new Map>([ ['core', core], diff --git a/src/schema/yaml-1.1/omap.ts b/src/schema/yaml-1.1/omap.ts index 95e1809c..eae9bfdd 100644 --- a/src/schema/yaml-1.1/omap.ts +++ b/src/schema/yaml-1.1/omap.ts @@ -1,10 +1,10 @@ import { isPair, isScalar } from '../../nodes/identity.ts' -import { toJS, ToJSContext } from '../../nodes/toJS.ts' +import { toJS, type ToJSContext } from '../../nodes/toJS.ts' import { YAMLMap } from '../../nodes/YAMLMap.ts' import { YAMLSeq } from '../../nodes/YAMLSeq.ts' -import { CreateNodeContext } from '../../util.ts' +import { type CreateNodeContext } from '../../util.ts' import type { Schema } from '../Schema.ts' -import { CollectionTag } from '../types.ts' +import { type CollectionTag } from '../types.ts' import { createPairs, resolvePairs } from './pairs.ts' export class YAMLOMap extends YAMLSeq { diff --git a/src/schema/yaml-1.1/pairs.ts b/src/schema/yaml-1.1/pairs.ts index 77e343f7..dcac4166 100644 --- a/src/schema/yaml-1.1/pairs.ts +++ b/src/schema/yaml-1.1/pairs.ts @@ -3,7 +3,7 @@ import { isMap, isPair, isSeq } from '../../nodes/identity.ts' import type { ParsedNode } from '../../nodes/Node.ts' import { createPair, Pair } from '../../nodes/Pair.ts' import { Scalar } from '../../nodes/Scalar.ts' -import { YAMLMap } from '../../nodes/YAMLMap.ts' +import type { YAMLMap } from '../../nodes/YAMLMap.ts' import { YAMLSeq } from '../../nodes/YAMLSeq.ts' import type { Schema } from '../../schema/Schema.ts' import type { CollectionTag } from '../types.ts' diff --git a/src/schema/yaml-1.1/set.ts b/src/schema/yaml-1.1/set.ts index a2d29add..e64c1616 100644 --- a/src/schema/yaml-1.1/set.ts +++ b/src/schema/yaml-1.1/set.ts @@ -1,11 +1,11 @@ import { isMap, isPair, isScalar } from '../../nodes/identity.ts' import { Pair } from '../../nodes/Pair.ts' -import { Scalar } from '../../nodes/Scalar.ts' -import { ToJSContext } from '../../nodes/toJS.ts' +import type { Scalar } from '../../nodes/Scalar.ts' +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 { CreateNodeContext, createPair } from '../../util.ts' +import { type CreateNodeContext, createPair } from '../../util.ts' import type { CollectionTag } from '../types.ts' export class YAMLSet extends YAMLMap | null> { diff --git a/src/stringify/stringifyCollection.ts b/src/stringify/stringifyCollection.ts index d625262e..4d3890b6 100644 --- a/src/stringify/stringifyCollection.ts +++ b/src/stringify/stringifyCollection.ts @@ -1,6 +1,6 @@ -import { Collection } from '../nodes/Collection.ts' +import type { Collection } from '../nodes/Collection.ts' import { isNode, isPair } from '../nodes/identity.ts' -import { stringify, StringifyContext } from './stringify.ts' +import { stringify, type StringifyContext } from './stringify.ts' import { indentComment, lineComment } from './stringifyComment.ts' interface StringifyCollectionOptions { diff --git a/src/stringify/stringifyDocument.ts b/src/stringify/stringifyDocument.ts index 75af5f9d..d3b91e06 100644 --- a/src/stringify/stringifyDocument.ts +++ b/src/stringify/stringifyDocument.ts @@ -5,7 +5,7 @@ import type { ToStringOptions } from '../options.ts' import { createStringifyContext, stringify, - StringifyContext + type StringifyContext } from './stringify.ts' import { indentComment, lineComment } from './stringifyComment.ts' diff --git a/src/stringify/stringifyPair.ts b/src/stringify/stringifyPair.ts index b2ab996a..7b76f4f7 100644 --- a/src/stringify/stringifyPair.ts +++ b/src/stringify/stringifyPair.ts @@ -1,7 +1,7 @@ import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.ts' import type { Pair } from '../nodes/Pair.ts' import { Scalar } from '../nodes/Scalar.ts' -import { stringify, StringifyContext } from './stringify.ts' +import { stringify, type StringifyContext } from './stringify.ts' import { indentComment, lineComment } from './stringifyComment.ts' export function stringifyPair( diff --git a/src/stringify/stringifyString.ts b/src/stringify/stringifyString.ts index e5c17fb4..2de6aa37 100644 --- a/src/stringify/stringifyString.ts +++ b/src/stringify/stringifyString.ts @@ -1,12 +1,12 @@ import { Scalar } from '../nodes/Scalar.ts' +import type { CollectionTag, ScalarTag } from '../schema/types.ts' import { - foldFlowLines, - FoldOptions, FOLD_BLOCK, FOLD_FLOW, - FOLD_QUOTED + FOLD_QUOTED, + foldFlowLines, + type FoldOptions } from './foldFlowLines.ts' -import type { CollectionTag, ScalarTag } from '../schema/types.ts' import type { StringifyContext } from './stringify.ts' interface StringifyScalar { diff --git a/src/test-events.ts b/src/test-events.ts index 93604910..c0260152 100644 --- a/src/test-events.ts +++ b/src/test-events.ts @@ -1,4 +1,4 @@ -import { Document } from './doc/Document.ts' +import type { Document } from './doc/Document.ts' import { isAlias, isCollection, diff --git a/src/util.ts b/src/util.ts index a4cbf238..46ec5a10 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,12 +1,17 @@ -export { createNode, CreateNodeContext } from './doc/createNode.ts' -export { debug, LogLevelId, warn } from './log.ts' +export { createNode } from './doc/createNode.ts' +export type { CreateNodeContext } from './doc/createNode.ts' +export { debug, warn } from './log.ts' +export type { LogLevelId } from './log.ts' export { createPair } from './nodes/Pair.ts' +export { toJS } from './nodes/toJS.ts' +export type { ToJSContext } from './nodes/toJS.ts' export { findPair } from './nodes/YAMLMap.ts' -export { toJS, ToJSContext } from './nodes/toJS.ts' export { map as mapTag } from './schema/common/map.ts' export { seq as seqTag } from './schema/common/seq.ts' export { string as stringTag } from './schema/common/string.ts' -export { foldFlowLines, FoldOptions } from './stringify/foldFlowLines.ts' -export { StringifyContext } from './stringify/stringify.ts' +export { foldFlowLines } from './stringify/foldFlowLines.ts' +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' + diff --git a/src/visit.ts b/src/visit.ts index 95f775ad..0a1490f3 100644 --- a/src/visit.ts +++ b/src/visit.ts @@ -10,7 +10,7 @@ import { isScalar, isSeq } from './nodes/identity.ts' -import { Node } from './nodes/Node.ts' +import type { Node } from './nodes/Node.ts' import type { Pair } from './nodes/Pair.ts' import type { Scalar } from './nodes/Scalar.ts' import type { YAMLMap } from './nodes/YAMLMap.ts' From 32b91d19949729be60fb84ae5328e26769ee6427 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Nov 2024 11:06:26 +0200 Subject: [PATCH 5/8] test: Fix import paths & add type keywords --- config/jest.config.js | 2 +- tests/clone.ts | 4 ++-- tests/collection-access.ts | 14 +++++++------- tests/cst.ts | 2 +- tests/directives.ts | 4 ++-- tests/doc/YAML-1.1.spec.ts | 2 +- tests/doc/anchors.ts | 2 +- tests/doc/comments.ts | 2 +- tests/doc/createNode.ts | 4 ++-- tests/doc/errors.ts | 2 +- tests/doc/foldFlowLines.ts | 4 ++-- tests/doc/parse.ts | 2 +- tests/doc/stringify.ts | 2 +- tests/doc/types.ts | 18 +++++++++--------- tests/node-to-js.ts | 4 ++-- tests/stream.ts | 2 +- tests/visit.ts | 2 +- tests/yaml-test-suite.ts | 4 ++-- 18 files changed, 38 insertions(+), 38 deletions(-) diff --git a/config/jest.config.js b/config/jest.config.js index a63616c1..57f878c9 100644 --- a/config/jest.config.js +++ b/config/jest.config.js @@ -27,7 +27,7 @@ switch (process.env.npm_lifecycle_event) { '^yaml$': '/dist/index.js', '^yaml/cli$': '/dist/cli.mjs', '^yaml/util$': '/dist/util.js', - '^../src/test-events$': '/dist/test-events.js' + '^../src/test-events.ts$': '/dist/test-events.js' } transform['[/\\\\]dist[/\\\\].*\\.mjs$'] = babel break diff --git a/tests/clone.ts b/tests/clone.ts index a10e1c4e..283f4751 100644 --- a/tests/clone.ts +++ b/tests/clone.ts @@ -1,5 +1,5 @@ -import { isAlias, isScalar, parseDocument, Scalar, visit, YAMLMap } from 'yaml' -import { source } from './_utils' +import { isAlias, isScalar, parseDocument, type Scalar, visit, type YAMLMap } from 'yaml' +import { source } from './_utils.ts' describe('doc.clone()', () => { test('has expected members', () => { diff --git a/tests/collection-access.ts b/tests/collection-access.ts index ba30e7e1..ec0ed50b 100644 --- a/tests/collection-access.ts +++ b/tests/collection-access.ts @@ -1,14 +1,14 @@ import { Document, - parseDocument, Pair, - Scalar, - YAMLMap, - YAMLOMap, - YAMLSeq, - YAMLSet, + type Scalar, + type YAMLMap, + type YAMLOMap, + type YAMLSeq, + type YAMLSet, + isMap, isSeq, - isMap + parseDocument } from 'yaml' describe('Map', () => { diff --git a/tests/cst.ts b/tests/cst.ts index 3580c959..b7b5f26f 100644 --- a/tests/cst.ts +++ b/tests/cst.ts @@ -1,5 +1,5 @@ import { CST, Parser } from 'yaml' -import { source } from './_utils' +import { source } from './_utils.ts' function cstDoc(src: string) { const tokens = Array.from(new Parser().parse(src)) diff --git a/tests/directives.ts b/tests/directives.ts index 1d6d2a1e..6399c79b 100644 --- a/tests/directives.ts +++ b/tests/directives.ts @@ -1,5 +1,5 @@ -import { parseDocument, Scalar } from 'yaml' -import { source } from './_utils' +import { parseDocument, type Scalar } from 'yaml' +import { source } from './_utils.ts' describe('%TAG', () => { test('parse local tags', () => { diff --git a/tests/doc/YAML-1.1.spec.ts b/tests/doc/YAML-1.1.spec.ts index 06016882..327b493d 100644 --- a/tests/doc/YAML-1.1.spec.ts +++ b/tests/doc/YAML-1.1.spec.ts @@ -1,4 +1,4 @@ -import { source } from '../_utils' +import { source } from '../_utils.ts' import { parseAllDocuments } from 'yaml' test('Use preceding directives if none defined', () => { diff --git a/tests/doc/anchors.ts b/tests/doc/anchors.ts index 70a44da7..e25d4b66 100644 --- a/tests/doc/anchors.ts +++ b/tests/doc/anchors.ts @@ -1,4 +1,4 @@ -import { Alias, Document, parse, parseDocument, YAMLMap, YAMLSeq } from 'yaml' +import { type Alias, Document, parse, parseDocument, type YAMLMap, type YAMLSeq } from 'yaml' test('basic', () => { const src = `- &a 1\n- *a\n` diff --git a/tests/doc/comments.ts b/tests/doc/comments.ts index aca037ca..22bfdada 100644 --- a/tests/doc/comments.ts +++ b/tests/doc/comments.ts @@ -1,4 +1,4 @@ -import { source } from '../_utils' +import { source } from '../_utils.ts' import * as YAML from 'yaml' describe('parse comments', () => { diff --git a/tests/doc/createNode.ts b/tests/doc/createNode.ts index af586a2f..7eb19bdc 100644 --- a/tests/doc/createNode.ts +++ b/tests/doc/createNode.ts @@ -1,5 +1,5 @@ -import { Alias, Document, Node, Scalar, YAMLMap, YAMLSeq } from 'yaml' -import { source } from '../_utils' +import { type Alias, Document, type Node, Scalar, YAMLMap, YAMLSeq } from 'yaml' +import { source } from '../_utils.ts' describe('createNode(value)', () => { test('boolean', () => { diff --git a/tests/doc/errors.ts b/tests/doc/errors.ts index 93800d2b..e18c6402 100644 --- a/tests/doc/errors.ts +++ b/tests/doc/errors.ts @@ -1,5 +1,5 @@ import * as YAML from 'yaml' -import { source } from '../_utils' +import { source } from '../_utils.ts' describe('tabs as indentation', () => { test('fail on map value indented with tab', () => { diff --git a/tests/doc/foldFlowLines.ts b/tests/doc/foldFlowLines.ts index 6c225dab..ad281891 100644 --- a/tests/doc/foldFlowLines.ts +++ b/tests/doc/foldFlowLines.ts @@ -1,6 +1,6 @@ import * as YAML from 'yaml' -import { foldFlowLines as fold, FoldOptions } from 'yaml/util' -import { source } from '../_utils' +import { foldFlowLines as fold, type FoldOptions } from 'yaml/util' +import { source } from '../_utils.ts' const FOLD_FLOW = 'flow' const FOLD_QUOTED = 'quoted' diff --git a/tests/doc/parse.ts b/tests/doc/parse.ts index a9fc9bed..24655efa 100644 --- a/tests/doc/parse.ts +++ b/tests/doc/parse.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs' import { resolve } from 'path' import * as YAML from 'yaml' -import { source } from '../_utils' +import { source } from '../_utils.ts' describe('scalars', () => { test('empty block scalar at end of document', () => { diff --git a/tests/doc/stringify.ts b/tests/doc/stringify.ts index b49d334c..82e18b85 100644 --- a/tests/doc/stringify.ts +++ b/tests/doc/stringify.ts @@ -1,4 +1,4 @@ -import { source } from '../_utils' +import { source } from '../_utils.ts' import * as YAML from 'yaml' import { Pair, Scalar } from 'yaml' diff --git a/tests/doc/types.ts b/tests/doc/types.ts index c2627d53..8c982e8a 100644 --- a/tests/doc/types.ts +++ b/tests/doc/types.ts @@ -1,22 +1,22 @@ import { - CollectionTag, + type CollectionTag, Document, - DocumentOptions, - Node, - parse, - ParsedNode, + type DocumentOptions, + type Node, parseDocument as origParseDocument, - ParseOptions, + parse, + type ParsedNode, + type ParseOptions, Scalar, - ScalarTag, + type ScalarTag, Schema, - SchemaOptions, + type SchemaOptions, stringify, YAMLMap, YAMLSeq } from 'yaml' import { seqTag, stringifyString, stringTag } from 'yaml/util' -import { source } from '../_utils' +import { source } from '../_utils.ts' const parseDocument = ( source: string, diff --git a/tests/node-to-js.ts b/tests/node-to-js.ts index 552ce3a4..95321b70 100644 --- a/tests/node-to-js.ts +++ b/tests/node-to-js.ts @@ -1,5 +1,5 @@ -import { parseDocument, YAMLMap, YAMLSeq } from 'yaml' -import { source } from './_utils' +import { parseDocument, type YAMLMap, type YAMLSeq } from 'yaml' +import { source } from './_utils.ts' describe('scalars', () => { test('plain', () => { diff --git a/tests/stream.ts b/tests/stream.ts index 3f9739d5..17af0083 100644 --- a/tests/stream.ts +++ b/tests/stream.ts @@ -1,4 +1,4 @@ -import { Composer, Document, Parser, parseDocument } from 'yaml' +import { Composer, type Document, Parser, parseDocument } from 'yaml' const src = ` #c0\n \n diff --git a/tests/visit.ts b/tests/visit.ts index 610ccb61..aa54b161 100644 --- a/tests/visit.ts +++ b/tests/visit.ts @@ -1,4 +1,4 @@ -import { Document, isSeq, parseDocument, Scalar, visit, visitAsync } from 'yaml' +import { Document, isSeq, parseDocument, type Scalar, visit, visitAsync } from 'yaml' const coll = { items: {} } diff --git a/tests/yaml-test-suite.ts b/tests/yaml-test-suite.ts index 194a7a98..af1fa02c 100644 --- a/tests/yaml-test-suite.ts +++ b/tests/yaml-test-suite.ts @@ -1,8 +1,8 @@ import { readdirSync, readFileSync } from 'fs' import { resolve } from 'path' -import { CST, Document, Lexer, parse, parseAllDocuments, Parser } from 'yaml' -import { testEvents } from '../src/test-events' // no public export +import { CST, type Document, Lexer, parse, parseAllDocuments, Parser } from 'yaml' +import { testEvents } from '../src/test-events.ts' // no public export type TestCase = { yaml: string From 3bec004db4206ebb0d4551f981a7f9961077470b Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Nov 2024 11:17:20 +0200 Subject: [PATCH 6/8] ci: Add deno smoke test --- .github/workflows/deno.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/deno.yml diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml new file mode 100644 index 00000000..038e853d --- /dev/null +++ b/.github/workflows/deno.yml @@ -0,0 +1,24 @@ +name: Deno + +on: + pull_request: + branches: [main] + push: + branches: [main] + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + deno-version: [v1.x, v2.x] + + steps: + - uses: actions/checkout@v4 + with: { submodules: true } + - uses: denoland/setup-deno@v2 + with: + deno-version: ${{ matrix.deno-version }} + - run: deno src/public-api.ts From c4c49f9e95db811a6fe7fd529647cb2659f150d0 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Nov 2024 11:56:19 +0200 Subject: [PATCH 7/8] fix: Use separate rather than inline type keyword for TS compatibility --- eslint.config.mjs | 2 +- src/cli.ts | 8 +++++--- src/compose/compose-collection.ts | 2 +- src/compose/composer.ts | 3 ++- src/compose/resolve-block-map.ts | 2 +- src/compose/resolve-block-scalar.ts | 2 +- src/compose/resolve-block-seq.ts | 2 +- src/compose/resolve-flow-collection.ts | 4 ++-- src/compose/resolve-flow-scalar.ts | 4 ++-- src/compose/util-flow-indent-check.ts | 4 ++-- src/doc/Document.ts | 6 ++++-- src/doc/anchors.ts | 2 +- src/nodes/Alias.ts | 6 ++++-- src/nodes/Node.ts | 5 +++-- src/nodes/Pair.ts | 3 ++- src/nodes/Scalar.ts | 6 ++++-- src/nodes/YAMLMap.ts | 5 +++-- src/nodes/YAMLSeq.ts | 9 ++++++--- src/nodes/addPairToJSMap.ts | 3 ++- src/parse/cst-scalar.ts | 5 +++-- src/parse/parser.ts | 25 ++++++++++++------------- src/public-api.ts | 3 ++- src/schema/yaml-1.1/omap.ts | 7 ++++--- src/schema/yaml-1.1/set.ts | 3 ++- src/stringify/stringifyCollection.ts | 3 ++- src/stringify/stringifyPair.ts | 3 ++- src/util.ts | 1 - tests/clone.ts | 3 ++- tests/directives.ts | 3 ++- tests/doc/anchors.ts | 3 ++- tests/doc/createNode.ts | 3 ++- tests/doc/foldFlowLines.ts | 3 ++- tests/node-to-js.ts | 3 ++- tests/stream.ts | 3 ++- tests/visit.ts | 3 ++- tests/yaml-test-suite.ts | 3 ++- 36 files changed, 92 insertions(+), 63 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 8d15f809..326b24c2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -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', diff --git a/src/cli.ts b/src/cli.ts index 0ad15356..9e80f32a 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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 diff --git a/src/compose/compose-collection.ts b/src/compose/compose-collection.ts index 08f0e1a9..82459191 100644 --- a/src/compose/compose-collection.ts +++ b/src/compose/compose-collection.ts @@ -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' diff --git a/src/compose/composer.ts b/src/compose/composer.ts index 493cceb2..598ba78b 100644 --- a/src/compose/composer.ts +++ b/src/compose/composer.ts @@ -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 { diff --git a/src/compose/resolve-block-map.ts b/src/compose/resolve-block-map.ts index 8ec303f9..d01c7a66 100644 --- a/src/compose/resolve-block-map.ts +++ b/src/compose/resolve-block-map.ts @@ -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' diff --git a/src/compose/resolve-block-scalar.ts b/src/compose/resolve-block-scalar.ts index 06c9c7e0..1fb3036b 100644 --- a/src/compose/resolve-block-scalar.ts +++ b/src/compose/resolve-block-scalar.ts @@ -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' diff --git a/src/compose/resolve-block-seq.ts b/src/compose/resolve-block-seq.ts index 03814810..c34a0f48 100644 --- a/src/compose/resolve-block-seq.ts +++ b/src/compose/resolve-block-seq.ts @@ -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' diff --git a/src/compose/resolve-flow-collection.ts b/src/compose/resolve-flow-collection.ts index 0d51d73e..651fa4e0 100644 --- a/src/compose/resolve-flow-collection.ts +++ b/src/compose/resolve-flow-collection.ts @@ -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' diff --git a/src/compose/resolve-flow-scalar.ts b/src/compose/resolve-flow-scalar.ts index 49582442..5568d63c 100644 --- a/src/compose/resolve-flow-scalar.ts +++ b/src/compose/resolve-flow-scalar.ts @@ -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' diff --git a/src/compose/util-flow-indent-check.ts b/src/compose/util-flow-indent-check.ts index aece0698..2f0e4076 100644 --- a/src/compose/util-flow-indent-check.ts +++ b/src/compose/util-flow-indent-check.ts @@ -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( diff --git a/src/doc/Document.ts b/src/doc/Document.ts index 66b52895..14456486 100644 --- a/src/doc/Document.ts +++ b/src/doc/Document.ts @@ -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 { @@ -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) diff --git a/src/doc/anchors.ts b/src/doc/anchors.ts index af996d47..8379494a 100644 --- a/src/doc/anchors.ts +++ b/src/doc/anchors.ts @@ -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' /** diff --git a/src/nodes/Alias.ts b/src/nodes/Alias.ts index 969fd7b5..8461c3df 100644 --- a/src/nodes/Alias.ts +++ b/src/nodes/Alias.ts @@ -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' diff --git a/src/nodes/Node.ts b/src/nodes/Node.ts index 1e46d490..0ecfbe8a 100644 --- a/src/nodes/Node.ts +++ b/src/nodes/Node.ts @@ -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' diff --git a/src/nodes/Pair.ts b/src/nodes/Pair.ts index 5eadfcf1..e3f369f2 100644 --- a/src/nodes/Pair.ts +++ b/src/nodes/Pair.ts @@ -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' diff --git a/src/nodes/Scalar.ts b/src/nodes/Scalar.ts index d2f862b8..b9d92cd6 100644 --- a/src/nodes/Scalar.ts +++ b/src/nodes/Scalar.ts @@ -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') diff --git a/src/nodes/YAMLMap.ts b/src/nodes/YAMLMap.ts index db8ffff7..23df326f 100644 --- a/src/nodes/YAMLMap.ts +++ b/src/nodes/YAMLMap.ts @@ -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 = diff --git a/src/nodes/YAMLSeq.ts b/src/nodes/YAMLSeq.ts index 31fd20e5..39e78dfb 100644 --- a/src/nodes/YAMLSeq.ts +++ b/src/nodes/YAMLSeq.ts @@ -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' @@ -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< diff --git a/src/nodes/addPairToJSMap.ts b/src/nodes/addPairToJSMap.ts index 73568ca1..08bb0608 100644 --- a/src/nodes/addPairToJSMap.ts +++ b/src/nodes/addPairToJSMap.ts @@ -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( diff --git a/src/parse/cst-scalar.ts b/src/parse/cst-scalar.ts index 1854cf7a..e10d3a6d 100644 --- a/src/parse/cst-scalar.ts +++ b/src/parse/cst-scalar.ts @@ -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' diff --git a/src/parse/parser.ts b/src/parse/parser.ts index 415020c7..3859d655 100644 --- a/src/parse/parser.ts +++ b/src/parse/parser.ts @@ -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']) { diff --git a/src/public-api.ts b/src/public-api.ts index 33a4ddb4..407fb496 100644 --- a/src/public-api.ts +++ b/src/public-api.ts @@ -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' diff --git a/src/schema/yaml-1.1/omap.ts b/src/schema/yaml-1.1/omap.ts index eae9bfdd..f3baa1a8 100644 --- a/src/schema/yaml-1.1/omap.ts +++ b/src/schema/yaml-1.1/omap.ts @@ -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 { diff --git a/src/schema/yaml-1.1/set.ts b/src/schema/yaml-1.1/set.ts index e64c1616..b1396fde 100644 --- a/src/schema/yaml-1.1/set.ts +++ b/src/schema/yaml-1.1/set.ts @@ -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 extends YAMLMap | null> { diff --git a/src/stringify/stringifyCollection.ts b/src/stringify/stringifyCollection.ts index 4d3890b6..a920fe34 100644 --- a/src/stringify/stringifyCollection.ts +++ b/src/stringify/stringifyCollection.ts @@ -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 { diff --git a/src/stringify/stringifyPair.ts b/src/stringify/stringifyPair.ts index 7b76f4f7..fddcb1b7 100644 --- a/src/stringify/stringifyPair.ts +++ b/src/stringify/stringifyPair.ts @@ -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( diff --git a/src/util.ts b/src/util.ts index 46ec5a10..d1b9aa83 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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' - diff --git a/tests/clone.ts b/tests/clone.ts index 283f4751..63dfb11a 100644 --- a/tests/clone.ts +++ b/tests/clone.ts @@ -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()', () => { diff --git a/tests/directives.ts b/tests/directives.ts index 6399c79b..058875ec 100644 --- a/tests/directives.ts +++ b/tests/directives.ts @@ -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', () => { diff --git a/tests/doc/anchors.ts b/tests/doc/anchors.ts index e25d4b66..39460832 100644 --- a/tests/doc/anchors.ts +++ b/tests/doc/anchors.ts @@ -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` diff --git a/tests/doc/createNode.ts b/tests/doc/createNode.ts index 7eb19bdc..5b070fd8 100644 --- a/tests/doc/createNode.ts +++ b/tests/doc/createNode.ts @@ -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)', () => { diff --git a/tests/doc/foldFlowLines.ts b/tests/doc/foldFlowLines.ts index ad281891..3068b7cf 100644 --- a/tests/doc/foldFlowLines.ts +++ b/tests/doc/foldFlowLines.ts @@ -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' diff --git a/tests/node-to-js.ts b/tests/node-to-js.ts index 95321b70..bc392b25 100644 --- a/tests/node-to-js.ts +++ b/tests/node-to-js.ts @@ -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', () => { diff --git a/tests/stream.ts b/tests/stream.ts index 17af0083..b4e44c34 100644 --- a/tests/stream.ts +++ b/tests/stream.ts @@ -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 diff --git a/tests/visit.ts b/tests/visit.ts index aa54b161..28e1c209 100644 --- a/tests/visit.ts +++ b/tests/visit.ts @@ -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: {} } diff --git a/tests/yaml-test-suite.ts b/tests/yaml-test-suite.ts index af1fa02c..04783291 100644 --- a/tests/yaml-test-suite.ts +++ b/tests/yaml-test-suite.ts @@ -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 = { From ab240c17d35bb808a6df8e3039b9ddd6a2de7ac4 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Nov 2024 13:23:39 +0200 Subject: [PATCH 8/8] fix: Drop .ts extension from import & export paths in .d.ts files --- config/rollup.node-config.mjs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/config/rollup.node-config.mjs b/config/rollup.node-config.mjs index 524b01d8..1367bdac 100644 --- a/config/rollup.node-config.mjs +++ b/config/rollup.node-config.mjs @@ -1,6 +1,26 @@ import typescript from '@rollup/plugin-typescript' import * as ts from 'typescript' +/** + * Drop .ts extension from import & export paths in .d.ts files + * to support older TS versions. + * + * @param {ts.TransformationContext} context + */ +function fixDeclarationImportPaths(context) { + /** @param {ts.SourceFile} source */ + return function fixPaths(source) { + /** @param {ts.Node} node */ + function visitor(node) { + if (ts.isStringLiteral(node) && /^\.+\/.*\.ts$/.test(node.text)) { + return ts.factory.createStringLiteral(node.text.slice(0, -3), true) + } + return ts.visitEachChild(node, visitor, context) + } + return ts.visitNode(source, visitor) + } +} + /** * Strip out TS relative import path rewrite helper from dynamic import() calls * @@ -42,7 +62,11 @@ export default [ esModule: false, preserveModules: true }, - plugins: [typescript()], + plugins: [ + typescript({ + transformers: { afterDeclarations: [fixDeclarationImportPaths] } + }) + ], treeshake: { moduleSideEffects: false, propertyReadSideEffects: false } }, { @@ -50,7 +74,10 @@ export default [ output: { file: 'dist/cli.mjs' }, external: () => true, plugins: [ - typescript({ transformers: { after: [fixDynamicImportRewrite] } }) + typescript({ + declaration: false, + transformers: { after: [fixDynamicImportRewrite] } + }) ] } ]