diff --git a/packages/apidom-ast/src/Node.ts b/packages/apidom-ast/src/Node.ts index 18023b43d8..13c7ab32b9 100644 --- a/packages/apidom-ast/src/Node.ts +++ b/packages/apidom-ast/src/Node.ts @@ -7,6 +7,12 @@ export interface NodeOptions { readonly children?: unknown[]; readonly position?: Position; readonly isMissing?: boolean; + readonly startPositionRow?: number; + readonly startPositionColumn?: number; + readonly startIndex?: number; + readonly endPositionRow?: number; + readonly endPositionColumn?: number; + readonly endIndex?: number; } /** @@ -21,13 +27,37 @@ class Node { public children: unknown[]; - public position?: Position; + public startPositionRow?: number; - constructor({ children = [], position, isMissing = false }: NodeOptions = {}) { + public startPositionColumn?: number; + + public startIndex?: number; + + public endPositionRow?: number; + + public endPositionColumn?: number; + + public endIndex?: number; + + constructor({ + children = [], + isMissing = false, + startPositionRow, + startPositionColumn, + startIndex, + endPositionRow, + endPositionColumn, + endIndex, + }: NodeOptions = {}) { this.type = (this.constructor as typeof Node).type; this.isMissing = isMissing; this.children = children; - this.position = position; + this.startPositionRow = startPositionRow; + this.startPositionColumn = startPositionColumn; + this.startIndex = startIndex; + this.endPositionRow = endPositionRow; + this.endPositionColumn = endPositionColumn; + this.endIndex = endIndex; } // creates shallow clone of node diff --git a/packages/apidom-ast/src/index.ts b/packages/apidom-ast/src/index.ts index d63a24537c..9dce0f4a46 100644 --- a/packages/apidom-ast/src/index.ts +++ b/packages/apidom-ast/src/index.ts @@ -82,7 +82,7 @@ export type { PointOptions, PositionOptions } from './Position.ts'; export { default as Error } from './Error.ts'; export type { ErrorOptions } from './Error.ts'; export { default as ParseResult } from './ParseResult.ts'; -export { isParseResult, isLiteral, isPoint, isPosition } from './predicates.ts'; +export { isParseResult, isLiteral } from './predicates.ts'; // AST traversal related exports export { BREAK, diff --git a/packages/apidom-ast/src/predicates.ts b/packages/apidom-ast/src/predicates.ts index cb194c6e6e..ae5ad42ca3 100644 --- a/packages/apidom-ast/src/predicates.ts +++ b/packages/apidom-ast/src/predicates.ts @@ -1,5 +1,4 @@ import type Literal from './Literal.ts'; -import Position, { Point } from './Position.ts'; import ParseResult from './ParseResult.ts'; /** @@ -13,16 +12,6 @@ export const isNodeType = (type: string, node: unknown): boolean => */ export const isLiteral = (node: unknown): node is Literal => isNodeType('literal', node); -/** - * @public - */ -export const isPosition = (node: unknown): node is Position => isNodeType('position', node); - -/** - * @public - */ -export const isPoint = (node: unknown): node is Point => isNodeType('point', node); - /** * @public */ diff --git a/packages/apidom-ast/src/yaml/errors/YamlTagError.ts b/packages/apidom-ast/src/yaml/errors/YamlTagError.ts index 2248b261ec..3fe1152d23 100644 --- a/packages/apidom-ast/src/yaml/errors/YamlTagError.ts +++ b/packages/apidom-ast/src/yaml/errors/YamlTagError.ts @@ -1,7 +1,6 @@ import type { ApiDOMErrorOptions } from '@swagger-api/apidom-error'; import YamlSchemaError from './YamlSchemaError.ts'; -import Position from '../../Position.ts'; import Node from '../../Node.ts'; /** @@ -11,7 +10,12 @@ export interface YamlTagErrorOptions extends ApiDOMErrorO readonly specificTagName: string; readonly explicitTagName: string; readonly tagKind: string; - readonly tagPosition?: Position; + readonly tagStartPositionRow?: number; + readonly tagStartPositionColumn?: number; + readonly tagStartPositionIndex?: number; + readonly tagEndPositionRow?: number; + readonly tagEndPositionColumn?: number; + readonly tagEndPositionIndex?: number; readonly nodeCanonicalContent?: string; readonly node?: T; } @@ -26,7 +30,17 @@ class YamlTagError extends YamlSchemaError { public readonly tagKind!: string; - public readonly tagPosition?: Position; + public readonly tagStartPositionRow?: number; + + public readonly tagStartPositionColumn?: number; + + public readonly tagStartPositionIndex?: number; + + public readonly tagEndPositionRow?: number; + + public readonly tagEndPositionColumn?: number; + + public readonly tagEndPositionIndex?: number; public readonly nodeCanonicalContent?: string; @@ -39,7 +53,12 @@ class YamlTagError extends YamlSchemaError { this.specificTagName = structuredOptions.specificTagName; this.explicitTagName = structuredOptions.explicitTagName; this.tagKind = structuredOptions.tagKind; - this.tagPosition = structuredOptions.tagPosition; + this.tagStartPositionRow = structuredOptions.tagStartPositionRow; + this.tagStartPositionColumn = structuredOptions.tagStartPositionColumn; + this.tagStartPositionIndex = structuredOptions.tagStartPositionIndex; + this.tagEndPositionRow = structuredOptions.tagEndPositionRow; + this.tagEndPositionColumn = structuredOptions.tagEndPositionColumn; + this.tagEndPositionIndex = structuredOptions.tagEndPositionIndex; this.nodeCanonicalContent = structuredOptions.nodeCanonicalContent; this.node = structuredOptions.node; } diff --git a/packages/apidom-ast/src/yaml/schemas/failsafe/index.ts b/packages/apidom-ast/src/yaml/schemas/failsafe/index.ts index d0a4524e4c..f3f74e30f2 100644 --- a/packages/apidom-ast/src/yaml/schemas/failsafe/index.ts +++ b/packages/apidom-ast/src/yaml/schemas/failsafe/index.ts @@ -1,5 +1,3 @@ -import { clone } from 'ramda'; - import YamlTagError from '../../errors/YamlTagError.ts'; import YamlDirective from '../../nodes/YamlDirective.ts'; import { YamlNodeKind } from '../../nodes/YamlTag.ts'; @@ -95,7 +93,12 @@ class FailsafeSchema { specificTagName, explicitTagName: node.tag.explicitName, tagKind: node.tag.kind, - tagPosition: clone(node.tag.position), + tagStartPositionRow: node.tag.startPositionRow, + tagStartPositionColumn: node.tag.startPositionColumn, + tagStartPositionIndex: node.tag.startIndex, + tagEndPositionRow: node.tag.endPositionRow, + tagEndPositionColumn: node.tag.endPositionColumn, + tagEndPositionIndex: node.tag.endIndex, node: node.clone(), }); } @@ -106,7 +109,12 @@ class FailsafeSchema { specificTagName, explicitTagName: node.tag.explicitName, tagKind: node.tag.kind, - tagPosition: clone(node.tag.position), + tagStartPositionRow: node.tag.startPositionRow, + tagStartPositionColumn: node.tag.startPositionColumn, + tagStartPositionIndex: node.tag.startIndex, + tagEndPositionRow: node.tag.endPositionRow, + tagEndPositionColumn: node.tag.endPositionColumn, + tagEndPositionIndex: node.tag.endIndex, nodeCanonicalContent: canonicalNode.content, node: node.clone(), }); diff --git a/packages/apidom-converter/src/strategies/openapi-3-1-to-openapi-3-0-3/toolbox.ts b/packages/apidom-converter/src/strategies/openapi-3-1-to-openapi-3-0-3/toolbox.ts index 3eae07b4e4..30ad9bbd96 100644 --- a/packages/apidom-converter/src/strategies/openapi-3-1-to-openapi-3-0-3/toolbox.ts +++ b/packages/apidom-converter/src/strategies/openapi-3-1-to-openapi-3-0-3/toolbox.ts @@ -1,4 +1,10 @@ -import { Element, Meta, Attributes, AnnotationElement } from '@swagger-api/apidom-core'; +import { + Element, + Meta, + Attributes, + AnnotationElement, + assignSourceMap, +} from '@swagger-api/apidom-core'; import { createToolbox as createToolboxOpenAPI31 } from '@swagger-api/apidom-ns-openapi-3-1'; const createToolbox = () => { @@ -6,7 +12,7 @@ const createToolbox = () => { const copySourceMap = (from: T, to: U): void => { if (openAPI31Toolbox.predicates.hasElementSourceMap(from)) { - to.meta.set('sourceMap', from.meta.get('sourceMap')); + assignSourceMap(to, from); } }; diff --git a/packages/apidom-converter/test/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-requirements-empty-roles/index.ts b/packages/apidom-converter/test/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-requirements-empty-roles/index.ts index 2018ee45e8..07340bf171 100644 --- a/packages/apidom-converter/test/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-requirements-empty-roles/index.ts +++ b/packages/apidom-converter/test/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-requirements-empty-roles/index.ts @@ -2,7 +2,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { mediaTypes as openAPI31MediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-1'; import { mediaTypes as openAPI30MediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-0'; -import { AnnotationElement, includesClasses, toJSON, toValue } from '@swagger-api/apidom-core'; +import { AnnotationElement, includesClasses, toJSON } from '@swagger-api/apidom-core'; import { assert, expect } from 'chai'; import convert from '../../../../../src/index.ts'; @@ -73,20 +73,22 @@ describe('converter', function () { const annotation: AnnotationElement = annotations.find((a: AnnotationElement) => a.code?.equals('security-requirements-empty-roles'), ); - const sourceMap = annotation.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const [startRow, startColumn, startChar] = toValue(positionStart); - const [endRow, endColumn, endChar] = toValue(positionEnd); + const { + startPositionRow, + startPositionColumn, + startIndex, + endPositionRow, + endPositionColumn, + endIndex, + } = annotation; - assert.isDefined(sourceMap); + assert.strictEqual(startPositionRow, 15); + assert.strictEqual(startPositionColumn, 29); + assert.strictEqual(startIndex, 299); - assert.strictEqual(startRow, 15); - assert.strictEqual(startColumn, 29); - assert.strictEqual(startChar, 299); - - assert.strictEqual(endRow, 18); - assert.strictEqual(endColumn, 13); - assert.strictEqual(endChar, 358); + assert.strictEqual(endPositionRow, 18); + assert.strictEqual(endPositionColumn, 13); + assert.strictEqual(endIndex, 358); }); }); }); diff --git a/packages/apidom-converter/test/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-scheme-type/index.ts b/packages/apidom-converter/test/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-scheme-type/index.ts index e9770c5606..50d3864aee 100644 --- a/packages/apidom-converter/test/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-scheme-type/index.ts +++ b/packages/apidom-converter/test/strategies/openapi-3-1-to-openapi-3-0-3/refractor-plugins/security-scheme-type/index.ts @@ -2,7 +2,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { mediaTypes as openAPI31MediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-1'; import { mediaTypes as openAPI30MediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-0'; -import { AnnotationElement, includesClasses, toJSON, toValue } from '@swagger-api/apidom-core'; +import { AnnotationElement, includesClasses, toJSON } from '@swagger-api/apidom-core'; import { assert, expect } from 'chai'; import convert from '../../../../../src/index.ts'; @@ -61,20 +61,22 @@ describe('converter', function () { const annotation: AnnotationElement = annotations.find((a: AnnotationElement) => a.code?.equals('mutualTLS'), ); - const sourceMap = annotation.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const [startRow, startColumn, startChar] = toValue(positionStart); - const [endRow, endColumn, endChar] = toValue(positionEnd); + const { + startPositionRow, + startPositionColumn, + startIndex, + endPositionRow, + endPositionColumn, + endIndex, + } = annotation; - assert.isDefined(sourceMap); + assert.strictEqual(startPositionRow, 9); + assert.strictEqual(startPositionColumn, 32); + assert.strictEqual(startIndex, 188); - assert.strictEqual(startRow, 9); - assert.strictEqual(startColumn, 32); - assert.strictEqual(startChar, 188); - - assert.strictEqual(endRow, 12); - assert.strictEqual(endColumn, 13); - assert.strictEqual(endChar, 247); + assert.strictEqual(endPositionRow, 12); + assert.strictEqual(endPositionColumn, 13); + assert.strictEqual(endIndex, 247); }); specify( diff --git a/packages/apidom-core/src/clone/index.ts b/packages/apidom-core/src/clone/index.ts index e13b32aeed..82caadb9fc 100644 --- a/packages/apidom-core/src/clone/index.ts +++ b/packages/apidom-core/src/clone/index.ts @@ -1,8 +1,9 @@ import { ArraySlice, ObjectSlice, KeyValuePair, Element } from 'minim'; -import { isElement } from '../predicates/index.ts'; +import { hasElementSourceMap, isElement } from '../predicates/index.ts'; import DeepCloneError from './errors/DeepCloneError.ts'; import ShallowCloneError from './errors/ShallowCloneError.ts'; +import { assignSourceMap } from '../util.ts'; /** * @public @@ -123,6 +124,10 @@ const cloneShallowElement = (element: T): T => { copy.element = element.element; + if (hasElementSourceMap(element)) { + assignSourceMap(copy, element); + } + if (element.meta.length > 0) { copy._meta = cloneDeep(element.meta); } diff --git a/packages/apidom-core/src/elements/SourceMap.ts b/packages/apidom-core/src/elements/SourceMap.ts deleted file mode 100644 index 8e5ecb0f0d..0000000000 --- a/packages/apidom-core/src/elements/SourceMap.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { ArrayElement, Element, Attributes, Meta } from 'minim'; - -/** - * @public - */ -export interface Position { - row: number; - column: number; - char: number; -} - -/** - * @public - */ -export interface PositionRange { - start: Position; - end: Position; -} - -/** - * @public - */ -class SourceMap extends ArrayElement { - constructor(content?: Array, meta?: Meta, attributes?: Attributes) { - super(content, meta, attributes); - this.element = 'sourceMap'; - } - - get positionStart(): Element | undefined { - return this.children.filter((item) => item.classes.contains('position')).get(0); - } - - get positionEnd(): Element | undefined { - return this.children.filter((item) => item.classes.contains('position')).get(1); - } - - set position(position: PositionRange | undefined) { - if (typeof position === 'undefined') { - return; - } - - const start = new ArrayElement([ - position.start.row, - position.start.column, - position.start.char, - ]); - const end = new ArrayElement([position.end.row, position.end.column, position.end.char]); - - start.classes.push('position'); - end.classes.push('position'); - - this.push(start).push(end); - } -} - -export default SourceMap; diff --git a/packages/apidom-core/src/index.ts b/packages/apidom-core/src/index.ts index f14c93309f..52496b4e58 100644 --- a/packages/apidom-core/src/index.ts +++ b/packages/apidom-core/src/index.ts @@ -13,7 +13,6 @@ export { default as MediaTypes } from './media-types.ts'; export { Element, MemberElement, KeyValuePair, ObjectSlice, ArraySlice, refract } from 'minim'; export type { NamespacePluginOptions, Attributes, Meta } from 'minim'; -export type { PositionRange, Position } from './elements/SourceMap.ts'; export { default as namespace, Namespace, createNamespace } from './namespace.ts'; export { @@ -28,7 +27,6 @@ export { AnnotationElement, CommentElement, ParseResultElement, - SourceMapElement, } from './refractor/registration.ts'; export type { default as createToolbox, Toolbox, basePredicates } from './refractor/toolbox.ts'; @@ -46,7 +44,6 @@ export { isRefElement, isAnnotationElement, isParseResultElement, - isSourceMapElement, isPrimitiveElement, hasElementSourceMap, includesSymbols, @@ -83,7 +80,7 @@ export type { Callback, TraverseOptions } from './traversal/traverse.ts'; export { transclude, default as Transcluder } from './transcluder/index.ts'; -export { dereference } from './util.ts'; +export { dereference, assignSourceMap } from './util.ts'; export { cloneShallow, cloneDeep } from './clone/index.ts'; export { default as CloneError } from './clone/errors/CloneError.ts'; diff --git a/packages/apidom-core/src/namespace.ts b/packages/apidom-core/src/namespace.ts index c78b4bbaa7..7927e92e41 100644 --- a/packages/apidom-core/src/namespace.ts +++ b/packages/apidom-core/src/namespace.ts @@ -4,7 +4,6 @@ import { isPlainObject } from 'ramda-adjunct'; import AnnotationElement from './elements/Annotation.ts'; import CommentElement from './elements/Comment.ts'; import ParseResultElement from './elements/ParseResult.ts'; -import SourceMapElement from './elements/SourceMap.ts'; /** * @public @@ -16,7 +15,6 @@ export class Namespace extends MinimNamespace { this.register('annotation', AnnotationElement); this.register('comment', CommentElement); this.register('parseResult', ParseResultElement); - this.register('sourceMap', SourceMapElement); } } diff --git a/packages/apidom-core/src/predicates/index.ts b/packages/apidom-core/src/predicates/index.ts index ab0303b2fb..f122411b92 100644 --- a/packages/apidom-core/src/predicates/index.ts +++ b/packages/apidom-core/src/predicates/index.ts @@ -16,7 +16,6 @@ import { included } from 'ramda-adjunct'; import AnnotationElement from '../elements/Annotation.ts'; import CommentElement from '../elements/Comment.ts'; import ParserResultElement from '../elements/ParseResult.ts'; -import SourceMapElement from '../elements/SourceMap.ts'; import createPredicate, { isElementType as isElementTypeHelper } from './helpers.ts'; import type { ElementPredicate } from './helpers.ts'; @@ -174,19 +173,6 @@ export const isParseResultElement = createPredicate( }, ); -/** - * @public - */ -export const isSourceMapElement = createPredicate( - ({ hasBasicElementProps, isElementType, primitiveEq }) => { - return (element: unknown): element is SourceMapElement => - element instanceof SourceMapElement || - (hasBasicElementProps(element) && - isElementType('sourceMap', element) && - primitiveEq('array', element)); - }, -); - /** * @public */ @@ -219,8 +205,19 @@ export const isPrimitiveElement: ElementPredicate = ( /** * @public */ -export const hasElementSourceMap = (element: T): boolean => { - return isSourceMapElement(element.meta.get('sourceMap')); +export const hasElementSourceMap = (element?: T): boolean => { + if (!isElement(element)) { + return false; + } + + return ( + Number.isInteger(element.startPositionRow) && + Number.isInteger(element.startPositionColumn) && + Number.isInteger(element.startIndex) && + Number.isInteger(element.endPositionRow) && + Number.isInteger(element.endPositionColumn) && + Number.isInteger(element.endIndex) + ); }; /** diff --git a/packages/apidom-core/src/refractor/registration.ts b/packages/apidom-core/src/refractor/registration.ts index 5dd5578ec9..5f001b7d64 100644 --- a/packages/apidom-core/src/refractor/registration.ts +++ b/packages/apidom-core/src/refractor/registration.ts @@ -12,7 +12,6 @@ import { import AnnotationElement from '../elements/Annotation.ts'; import CommentElement from '../elements/Comment.ts'; import ParseResultElement from '../elements/ParseResult.ts'; -import SourceMapElement from '../elements/SourceMap.ts'; import { createRefractor } from './index.ts'; ObjectElement.refract = createRefractor(ObjectElement); @@ -27,7 +26,6 @@ RefElement.refract = createRefractor(RefElement); AnnotationElement.refract = createRefractor(AnnotationElement); CommentElement.refract = createRefractor(CommentElement); ParseResultElement.refract = createRefractor(ParseResultElement); -SourceMapElement.refract = createRefractor(SourceMapElement); export { ObjectElement, @@ -41,5 +39,4 @@ export { AnnotationElement, CommentElement, ParseResultElement, - SourceMapElement, }; diff --git a/packages/apidom-core/src/traversal/findAtOffset.ts b/packages/apidom-core/src/traversal/findAtOffset.ts index 362b86b179..8bd5c8a118 100644 --- a/packages/apidom-core/src/traversal/findAtOffset.ts +++ b/packages/apidom-core/src/traversal/findAtOffset.ts @@ -4,7 +4,6 @@ import { Element } from 'minim'; import { hasElementSourceMap } from '../predicates/index.ts'; import { visit } from './visitor.ts'; -import toValue from '../transformers/serializers/value/index.ts'; interface VisitorOptions { readonly offset?: number; @@ -29,12 +28,10 @@ class Visitor { return undefined; // dive in } - const sourceMapElement = element.getMetaProperty('sourceMap'); - const charStart = toValue(sourceMapElement.positionStart.get(2)); - const charEnd = toValue(sourceMapElement.positionEnd.get(2)); + const { startIndex, endIndex } = element; const isWithinOffsetRange = - this.offset >= charStart && - (this.offset < charEnd || (this.includeRightBound && this.offset <= charEnd)); + this.offset >= startIndex && + (this.offset < endIndex || (this.includeRightBound && this.offset <= endIndex)); if (isWithinOffsetRange) { this.result.push(element); diff --git a/packages/apidom-core/src/traversal/visitor.ts b/packages/apidom-core/src/traversal/visitor.ts index 45e4139697..e65b652aad 100644 --- a/packages/apidom-core/src/traversal/visitor.ts +++ b/packages/apidom-core/src/traversal/visitor.ts @@ -85,7 +85,6 @@ export const keyMapDefault = { Annotation: [], Comment: [], ParseResultElement: ['content'], - SourceMap: ['content'], }; export interface PredicateVisitorOptions { diff --git a/packages/apidom-core/src/util.ts b/packages/apidom-core/src/util.ts index 356b007104..cc4da28755 100644 --- a/packages/apidom-core/src/util.ts +++ b/packages/apidom-core/src/util.ts @@ -26,3 +26,32 @@ export const dereference = ( return val; }, object); }; + +type SourceMapContainer = { + startPositionRow?: number; + startPositionColumn?: number; + startIndex?: number; + endPositionRow?: number; + endPositionColumn?: number; + endIndex?: number; + [key: string]: any; +}; + +/** + * @public + */ +/* eslint-disable no-param-reassign */ +export const assignSourceMap = ( + to: SourceMapContainer, + from?: SourceMapContainer, +): SourceMapContainer => { + to.startPositionRow = from?.startPositionRow; + to.startPositionColumn = from?.startPositionColumn; + to.startIndex = from?.startIndex; + to.endPositionRow = from?.endPositionRow; + to.endPositionColumn = from?.endPositionColumn; + to.endIndex = from?.endIndex; + + return to; +}; +/* eslint-enable no-param-reassign */ diff --git a/packages/apidom-core/test/predicates/index.ts b/packages/apidom-core/test/predicates/index.ts index 986136b46f..c3dfe281d9 100644 --- a/packages/apidom-core/test/predicates/index.ts +++ b/packages/apidom-core/test/predicates/index.ts @@ -13,7 +13,6 @@ import { RefElement, ParseResultElement, AnnotationElement, - SourceMapElement, isElement, isStringElement, isNumberElement, @@ -26,7 +25,6 @@ import { isRefElement, isParseResultElement, isAnnotationElement, - isSourceMapElement, hasElementSourceMap, includesSymbols, includesClasses, @@ -779,68 +777,16 @@ describe('predicates', function () { }); }); - context('isSourceMapElement', function () { - context('given SourceMapElement instance value', function () { - specify('should return true', function () { - const element = new SourceMapElement(); - - assert.isTrue(isSourceMapElement(element)); - }); - }); - - context('given subtype instance value', function () { - specify('should return true', function () { - class SourceMapSubElement extends SourceMapElement {} - - assert.isTrue(isSourceMapElement(new SourceMapSubElement())); - }); - }); - - context('given non SourceMapSubElement instance value', function () { - specify('should return false', function () { - assert.isFalse(isSourceMapElement(1)); - assert.isFalse(isSourceMapElement(null)); - assert.isFalse(isSourceMapElement(undefined)); - assert.isFalse(isSourceMapElement({})); - assert.isFalse(isSourceMapElement([])); - assert.isFalse(isSourceMapElement('string')); - - assert.isFalse(isSourceMapElement(new StringElement())); - assert.isFalse(isSourceMapElement(new BooleanElement())); - }); - }); - - specify('should support duck-typing', function () { - const sourceMapElementDuck = { - _storedElement: 'sourceMap', - _content: [], - primitive() { - return 'array'; - }, - get element() { - return this._storedElement; - }, - }; - - const sourceMapElementSwan = { - _storedElement: 'sourceMap', - _content: [], - primitive() { - return undefined; - }, - }; - - assert.isTrue(isSourceMapElement(sourceMapElementDuck)); - assert.isFalse(isSourceMapElement(sourceMapElementSwan)); - }); - }); - context('hasSourceMapElement', function () { context('given element has sourcemap', function () { specify('should return true', function () { const element = new ObjectElement({ prop: 'val' }); - const sourceMap = new SourceMapElement(); - element.setMetaProperty('sourceMap', sourceMap); + element.startPositionRow = 1; + element.startPositionColumn = 1; + element.startIndex = 0; + element.endPositionRow = 1; + element.endPositionColumn = 2; + element.endIndex = 1; assert.isTrue(hasElementSourceMap(element)); }); @@ -848,7 +794,12 @@ describe('predicates', function () { context('and sourcemap is not SourceMapElement', function () { specify('should return false', function () { const element = new ObjectElement({ prop: 'val' }); - element.setMetaProperty('sourceMap', null); + element.startPositionRow = null; + element.startPositionColumn = null; + element.startIndex = null; + element.endPositionRow = null; + element.endPositionColumn = null; + element.endIndex = null; assert.isFalse(hasElementSourceMap(element)); }); diff --git a/packages/apidom-core/test/refractor/elements/SourceMap/__snapshots__/index.mjs.snap b/packages/apidom-core/test/refractor/elements/SourceMap/__snapshots__/index.mjs.snap deleted file mode 100644 index c1c9719099..0000000000 --- a/packages/apidom-core/test/refractor/elements/SourceMap/__snapshots__/index.mjs.snap +++ /dev/null @@ -1,13 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`refractor elements Annotation should refract to generic ApiDOM tree 1`] = ` -(SourceMapElement - (ArrayElement - (NumberElement) - (NumberElement) - (NumberElement)) - (ArrayElement - (NumberElement) - (NumberElement) - (NumberElement))) -`; diff --git a/packages/apidom-core/test/refractor/elements/SourceMap/index.ts b/packages/apidom-core/test/refractor/elements/SourceMap/index.ts deleted file mode 100644 index 280edac715..0000000000 --- a/packages/apidom-core/test/refractor/elements/SourceMap/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { expect } from 'chai'; - -import { SourceMapElement, sexprs } from '../../../../src/index.ts'; - -describe('refractor', function () { - context('elements', function () { - context('Annotation', function () { - specify('should refract to generic ApiDOM tree', function () { - const arrayElement = SourceMapElement.refract([ - [0, 1, 2], - [0, 1, 2], - ]); - - expect(sexprs(arrayElement)).toMatchSnapshot(); - }); - }); - }); -}); diff --git a/packages/apidom-ls/src/utils/utils.ts b/packages/apidom-ls/src/utils/utils.ts index 7dbe0e2b7b..d50e11f928 100644 --- a/packages/apidom-ls/src/utils/utils.ts +++ b/packages/apidom-ls/src/utils/utils.ts @@ -28,6 +28,7 @@ import { StringElement, traverse, toValue, + hasElementSourceMap, } from '@swagger-api/apidom-core'; import { compile, URIFragmentIdentifier } from '@swagger-api/apidom-json-pointer/modern'; import { TextDocument } from 'vscode-languageserver-textdocument'; @@ -109,15 +110,14 @@ export class SourceMap { } export function getSourceMap(element: Element): SourceMap { - if (element && element.meta && element.meta.get('sourceMap')) { - const sourceMap: [][number] = toValue(element.meta.get('sourceMap')) as [][number]; - const offset = sourceMap[0][2]; - const length = sourceMap[1][2] - sourceMap[0][2]; - const line = sourceMap[0][0]; - const column = sourceMap[0][1]; - const endLine = sourceMap[1][0]; - const endColumn = sourceMap[1][1]; - const endOffset = sourceMap[1][2]; + if (element && hasElementSourceMap(element)) { + const offset = element.startIndex as number; + const length = (element.endIndex as number) - (element.startIndex as number); + const line = element.startPositionRow as number; + const column = element.startPositionColumn as number; + const endLine = element.endPositionRow as number; + const endColumn = element.endPositionColumn as number; + const endOffset = element.endIndex as number; return new SourceMap(offset, length, line, column, endLine, endColumn, endOffset); // TODO ??? } return new SourceMap(1, 2, 0, 1); // TODO ??? diff --git a/packages/apidom-ns-api-design-systems/src/refractor/visitors/Visitor.ts b/packages/apidom-ns-api-design-systems/src/refractor/visitors/Visitor.ts index a9b5296e53..919c49aac4 100644 --- a/packages/apidom-ns-api-design-systems/src/refractor/visitors/Visitor.ts +++ b/packages/apidom-ns-api-design-systems/src/refractor/visitors/Visitor.ts @@ -1,4 +1,10 @@ -import { Element, ObjectElement, hasElementSourceMap, deepmerge } from '@swagger-api/apidom-core'; +import { + Element, + ObjectElement, + hasElementSourceMap, + deepmerge, + assignSourceMap, +} from '@swagger-api/apidom-core'; /** * @public @@ -19,10 +25,9 @@ class Visitor { public copyMetaAndAttributes(from: Element, to: Element) { if (from.meta.length > 0 || to.meta.length > 0) { to.meta = deepmerge(to.meta, from.meta) as ObjectElement; - if (hasElementSourceMap(from)) { - // avoid deep merging of source maps - to.meta.set('sourceMap', from.meta.get('sourceMap')); - } + } + if (hasElementSourceMap(from)) { + assignSourceMap(to, from); } if (from.attributes.length > 0 || from.meta.length > 0) { to.attributes = deepmerge(to.attributes, from.attributes) as ObjectElement; // eslint-disable-line no-param-reassign diff --git a/packages/apidom-ns-arazzo-1/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-arazzo-1/src/refractor/plugins/replace-empty-element.ts index 05247d3a7c..9dcaffe07a 100644 --- a/packages/apidom-ns-arazzo-1/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-arazzo-1/src/refractor/plugins/replace-empty-element.ts @@ -7,6 +7,7 @@ import { includesClasses, cloneDeep, toValue, + assignSourceMap, } from '@swagger-api/apidom-core'; /** @@ -96,12 +97,14 @@ const plugin = () => () => ({ // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }); diff --git a/packages/apidom-ns-arazzo-1/src/refractor/visitors/Visitor.ts b/packages/apidom-ns-arazzo-1/src/refractor/visitors/Visitor.ts index c2c2436811..31375ad09a 100644 --- a/packages/apidom-ns-arazzo-1/src/refractor/visitors/Visitor.ts +++ b/packages/apidom-ns-arazzo-1/src/refractor/visitors/Visitor.ts @@ -1,4 +1,10 @@ -import { Element, ObjectElement, deepmerge, hasElementSourceMap } from '@swagger-api/apidom-core'; +import { + Element, + ObjectElement, + assignSourceMap, + deepmerge, + hasElementSourceMap, +} from '@swagger-api/apidom-core'; /** * @public @@ -19,10 +25,9 @@ class Visitor { public copyMetaAndAttributes(from: Element, to: Element) { if (from.meta.length > 0 || to.meta.length > 0) { to.meta = deepmerge(to.meta, from.meta) as ObjectElement; - if (hasElementSourceMap(from)) { - // avoid deep merging of source maps - to.meta.set('sourceMap', from.meta.get('sourceMap')); - } + } + if (hasElementSourceMap(from)) { + assignSourceMap(to, from); } if (from.attributes.length > 0 || from.meta.length > 0) { to.attributes = deepmerge(to.attributes, from.attributes) as ObjectElement; // eslint-disable-line no-param-reassign diff --git a/packages/apidom-ns-arazzo-1/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-arazzo-1/test/refractor/plugins/replace-empty-element/mappings.ts index 3ad77e4c02..0198fe029b 100644 --- a/packages/apidom-ns-arazzo-1/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-arazzo-1/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { @@ -34,12 +34,12 @@ describe('given Workflows definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as ArazzoSpecification1Element; const { info: infoValue } = workflowsSpecificationElement; - const sourceMap = infoValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 5, 19]; - expect(infoValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(infoValue?.startPositionRow).to.equal(1); + expect(infoValue?.startPositionColumn).to.equal(5); + expect(infoValue?.startIndex).to.equal(19); + expect(infoValue?.endPositionRow).to.equal(1); + expect(infoValue?.endPositionColumn).to.equal(5); + expect(infoValue?.endIndex).to.equal(19); }); }); diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts index b381f68e7d..aca37dbab5 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts @@ -10,6 +10,7 @@ import { includesClasses, cloneDeep, toValue, + assignSourceMap, } from '@swagger-api/apidom-core'; import mediaTypes from '../../media-types.ts'; @@ -1061,12 +1062,14 @@ const plugin = () => () => ({ // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }); diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/Visitor.ts b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/Visitor.ts index ad6c7c2450..a29006b8c5 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/Visitor.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/Visitor.ts @@ -1,4 +1,10 @@ -import { Element, ObjectElement, deepmerge, hasElementSourceMap } from '@swagger-api/apidom-core'; +import { + Element, + ObjectElement, + assignSourceMap, + deepmerge, + hasElementSourceMap, +} from '@swagger-api/apidom-core'; /** * @public @@ -19,10 +25,9 @@ class Visitor { public copyMetaAndAttributes(from: Element, to: Element) { if (from.meta.length > 0 || to.meta.length > 0) { to.meta = deepmerge(to.meta, from.meta) as ObjectElement; - if (hasElementSourceMap(from)) { - // avoid deep merging of source maps - to.meta.set('sourceMap', from.meta.get('sourceMap')); - } + } + if (hasElementSourceMap(from)) { + assignSourceMap(to, from); } if (from.attributes.length > 0 || from.meta.length > 0) { to.attributes = deepmerge(to.attributes, from.attributes) as ObjectElement; // eslint-disable-line no-param-reassign diff --git a/packages/apidom-ns-asyncapi-2/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-asyncapi-2/test/refractor/plugins/replace-empty-element/mappings.ts index 28ce734d4f..7139e41def 100644 --- a/packages/apidom-ns-asyncapi-2/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-asyncapi-2/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, AsyncApi2Element } from '../../../../src/index.ts'; @@ -175,12 +175,12 @@ describe('given AsyncAPI definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as AsyncApi2Element; const { info: infoValue } = asyncApiElement; - const sourceMap = infoValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 5, 21]; - expect(infoValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(infoValue?.startPositionRow).to.equal(1); + expect(infoValue?.startPositionColumn).to.equal(5); + expect(infoValue?.startIndex).to.equal(21); + expect(infoValue?.endPositionRow).to.equal(1); + expect(infoValue?.endPositionColumn).to.equal(5); + expect(infoValue?.endIndex).to.equal(21); }); }); diff --git a/packages/apidom-ns-json-schema-2019-09/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-json-schema-2019-09/src/refractor/plugins/replace-empty-element.ts index 5875ecb823..4d0661498d 100644 --- a/packages/apidom-ns-json-schema-2019-09/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-json-schema-2019-09/src/refractor/plugins/replace-empty-element.ts @@ -9,6 +9,7 @@ import { includesClasses, cloneDeep, toValue, + assignSourceMap, } from '@swagger-api/apidom-core'; /** * JSON Schema 2019-09 specification elements. @@ -265,12 +266,14 @@ const plugin = () => () => { // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }; diff --git a/packages/apidom-ns-json-schema-2019-09/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-json-schema-2019-09/test/refractor/plugins/replace-empty-element/mappings.ts index fb3764ce1e..66f363193d 100644 --- a/packages/apidom-ns-json-schema-2019-09/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-json-schema-2019-09/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -339,12 +339,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { properties: propertiesValue } = jsonSchemaElement; - const sourceMap = propertiesValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 11, 67]; - expect(propertiesValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(propertiesValue?.startPositionRow).to.equal(1); + expect(propertiesValue?.startPositionColumn).to.equal(11); + expect(propertiesValue?.startIndex).to.equal(67); + expect(propertiesValue?.endPositionRow).to.equal(1); + expect(propertiesValue?.endPositionColumn).to.equal(11); + expect(propertiesValue?.endIndex).to.equal(67); }); }); diff --git a/packages/apidom-ns-json-schema-2019-09/test/refractor/plugins/replace-empty-element/sequences.ts b/packages/apidom-ns-json-schema-2019-09/test/refractor/plugins/replace-empty-element/sequences.ts index f1b53d68ac..da68054b30 100644 --- a/packages/apidom-ns-json-schema-2019-09/test/refractor/plugins/replace-empty-element/sequences.ts +++ b/packages/apidom-ns-json-schema-2019-09/test/refractor/plugins/replace-empty-element/sequences.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -130,12 +130,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { oneOf: oneOfValue } = jsonSchemaElement; - const sourceMap = oneOfValue?.get(0)?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [2, 2, 65]; - expect(oneOfValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(oneOfValue?.get(0)?.startPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.startPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.startIndex).to.equal(65); + expect(oneOfValue?.get(0)?.endPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.endPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.endIndex).to.equal(65); }); }); diff --git a/packages/apidom-ns-json-schema-2020-12/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-json-schema-2020-12/src/refractor/plugins/replace-empty-element.ts index b068992cdf..4b0c817592 100644 --- a/packages/apidom-ns-json-schema-2020-12/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-json-schema-2020-12/src/refractor/plugins/replace-empty-element.ts @@ -9,6 +9,7 @@ import { includesClasses, cloneDeep, toValue, + assignSourceMap, } from '@swagger-api/apidom-core'; /** * JSON Schema 2020-12 specification elements. @@ -272,12 +273,14 @@ const plugin = () => () => { // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }; diff --git a/packages/apidom-ns-json-schema-2020-12/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-json-schema-2020-12/test/refractor/plugins/replace-empty-element/mappings.ts index 9f6402c67d..7f09abf59e 100644 --- a/packages/apidom-ns-json-schema-2020-12/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-json-schema-2020-12/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -339,12 +339,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { properties: propertiesValue } = jsonSchemaElement; - const sourceMap = propertiesValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 11, 67]; - expect(propertiesValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(propertiesValue?.startPositionRow).to.equal(1); + expect(propertiesValue?.startPositionColumn).to.equal(11); + expect(propertiesValue?.startIndex).to.equal(67); + expect(propertiesValue?.endPositionRow).to.equal(1); + expect(propertiesValue?.endPositionColumn).to.equal(11); + expect(propertiesValue?.endIndex).to.equal(67); }); }); diff --git a/packages/apidom-ns-json-schema-2020-12/test/refractor/plugins/replace-empty-element/sequences.ts b/packages/apidom-ns-json-schema-2020-12/test/refractor/plugins/replace-empty-element/sequences.ts index 8440a0854e..2999b374b2 100644 --- a/packages/apidom-ns-json-schema-2020-12/test/refractor/plugins/replace-empty-element/sequences.ts +++ b/packages/apidom-ns-json-schema-2020-12/test/refractor/plugins/replace-empty-element/sequences.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -146,12 +146,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { oneOf: oneOfValue } = jsonSchemaElement; - const sourceMap = oneOfValue?.get(0)?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [2, 2, 65]; - expect(oneOfValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(oneOfValue?.get(0)?.startPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.startPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.startIndex).to.equal(65); + expect(oneOfValue?.get(0)?.endPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.endPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.endIndex).to.equal(65); }); }); diff --git a/packages/apidom-ns-json-schema-draft-4/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-json-schema-draft-4/src/refractor/plugins/replace-empty-element.ts index 3257b29e2d..a1785a4869 100644 --- a/packages/apidom-ns-json-schema-draft-4/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-json-schema-draft-4/src/refractor/plugins/replace-empty-element.ts @@ -9,6 +9,7 @@ import { includesClasses, cloneDeep, toValue, + assignSourceMap, } from '@swagger-api/apidom-core'; /** @@ -209,12 +210,14 @@ const plugin = () => () => ({ // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }); diff --git a/packages/apidom-ns-json-schema-draft-4/src/refractor/visitors/Visitor.ts b/packages/apidom-ns-json-schema-draft-4/src/refractor/visitors/Visitor.ts index 0a4feba290..2656eedb2d 100644 --- a/packages/apidom-ns-json-schema-draft-4/src/refractor/visitors/Visitor.ts +++ b/packages/apidom-ns-json-schema-draft-4/src/refractor/visitors/Visitor.ts @@ -1,4 +1,10 @@ -import { ObjectElement, hasElementSourceMap, deepmerge, Element } from '@swagger-api/apidom-core'; +import { + ObjectElement, + hasElementSourceMap, + deepmerge, + Element, + assignSourceMap, +} from '@swagger-api/apidom-core'; /** * @public @@ -15,21 +21,19 @@ class Visitor { Object.assign(this, options); } - // eslint-disable-next-line class-methods-use-this + /* eslint-disable class-methods-use-this, no-param-reassign */ public copyMetaAndAttributes(from: Element, to: Element) { if (from.meta.length > 0 || to.meta.length > 0) { - // eslint-disable-next-line no-param-reassign to.meta = deepmerge(to.meta, from.meta) as ObjectElement; - if (hasElementSourceMap(from)) { - // avoid deep merging of source maps - to.meta.set('sourceMap', from.meta.get('sourceMap')); - } + } + if (hasElementSourceMap(from)) { + assignSourceMap(to, from); } if (from.attributes.length > 0 || from.meta.length > 0) { - // eslint-disable-next-line no-param-reassign to.attributes = deepmerge(to.attributes, from.attributes) as ObjectElement; } } + /* eslint-enable class-methods-use-this, no-param-reassign */ } export default Visitor; diff --git a/packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/mappings.ts index d72602c9fb..26ea7b7ba8 100644 --- a/packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -125,12 +125,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { properties: propertiesValue } = jsonSchemaElement; - const sourceMap = propertiesValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 11, 62]; - expect(propertiesValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(propertiesValue?.startPositionRow).to.equal(1); + expect(propertiesValue?.startPositionColumn).to.equal(11); + expect(propertiesValue?.startIndex).to.equal(62); + expect(propertiesValue?.endPositionRow).to.equal(1); + expect(propertiesValue?.endPositionColumn).to.equal(11); + expect(propertiesValue?.endIndex).to.equal(62); }); }); diff --git a/packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/sequences.ts b/packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/sequences.ts index afda0f2d39..b1adc3d2b5 100644 --- a/packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/sequences.ts +++ b/packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/sequences.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -84,12 +84,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { oneOf: oneOfValue } = jsonSchemaElement; - const sourceMap = oneOfValue?.get(0)?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [2, 2, 60]; - expect(oneOfValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(oneOfValue?.get(0)?.startPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.startPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.startIndex).to.equal(60); + expect(oneOfValue?.get(0)?.endPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.endPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.endIndex).to.equal(60); }); }); diff --git a/packages/apidom-ns-json-schema-draft-6/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-json-schema-draft-6/src/refractor/plugins/replace-empty-element.ts index f15ad85c74..51ce5e3b2c 100644 --- a/packages/apidom-ns-json-schema-draft-6/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-json-schema-draft-6/src/refractor/plugins/replace-empty-element.ts @@ -9,6 +9,7 @@ import { includesClasses, cloneDeep, toValue, + assignSourceMap, } from '@swagger-api/apidom-core'; /** * JSON Schema Draft 6 specification elements. @@ -223,12 +224,14 @@ const plugin = () => () => ({ // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }); diff --git a/packages/apidom-ns-json-schema-draft-6/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-json-schema-draft-6/test/refractor/plugins/replace-empty-element/mappings.ts index c78b31ebf1..35e710ac05 100644 --- a/packages/apidom-ns-json-schema-draft-6/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-json-schema-draft-6/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -171,12 +171,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { properties: propertiesValue } = jsonSchemaElement; - const sourceMap = propertiesValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 11, 62]; - expect(propertiesValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(propertiesValue?.startPositionRow).to.equal(1); + expect(propertiesValue?.startPositionColumn).to.equal(11); + expect(propertiesValue?.startIndex).to.equal(62); + expect(propertiesValue?.endPositionRow).to.equal(1); + expect(propertiesValue?.endPositionColumn).to.equal(11); + expect(propertiesValue?.endIndex).to.equal(62); }); }); diff --git a/packages/apidom-ns-json-schema-draft-6/test/refractor/plugins/replace-empty-element/sequences.ts b/packages/apidom-ns-json-schema-draft-6/test/refractor/plugins/replace-empty-element/sequences.ts index fc6473f2e8..b234c37d89 100644 --- a/packages/apidom-ns-json-schema-draft-6/test/refractor/plugins/replace-empty-element/sequences.ts +++ b/packages/apidom-ns-json-schema-draft-6/test/refractor/plugins/replace-empty-element/sequences.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -99,12 +99,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { oneOf: oneOfValue } = jsonSchemaElement; - const sourceMap = oneOfValue?.get(0)?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [2, 2, 60]; - expect(oneOfValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(oneOfValue?.get(0)?.startPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.startPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.startIndex).to.equal(60); + expect(oneOfValue?.get(0)?.endPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.endPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.endIndex).to.equal(60); }); }); diff --git a/packages/apidom-ns-json-schema-draft-7/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-json-schema-draft-7/src/refractor/plugins/replace-empty-element.ts index 32b699dca1..033700805f 100644 --- a/packages/apidom-ns-json-schema-draft-7/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-json-schema-draft-7/src/refractor/plugins/replace-empty-element.ts @@ -9,6 +9,7 @@ import { includesClasses, cloneDeep, toValue, + assignSourceMap, } from '@swagger-api/apidom-core'; /** * JSON Schema Draft 7 specification elements. @@ -241,12 +242,14 @@ const plugin = () => () => { // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }; diff --git a/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/mappings.ts index 34f63cf41f..d6dab46508 100644 --- a/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -264,12 +264,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { properties: propertiesValue } = jsonSchemaElement; - const sourceMap = propertiesValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 11, 62]; - expect(propertiesValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(propertiesValue?.startPositionRow).to.equal(1); + expect(propertiesValue?.startPositionColumn).to.equal(11); + expect(propertiesValue?.startIndex).to.equal(62); + expect(propertiesValue?.endPositionRow).to.equal(1); + expect(propertiesValue?.endPositionColumn).to.equal(11); + expect(propertiesValue?.endIndex).to.equal(62); }); }); diff --git a/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/sequences.ts b/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/sequences.ts index e5c1221da8..05ff59a2f4 100644 --- a/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/sequences.ts +++ b/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/sequences.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, JSONSchemaElement } from '../../../../src/index.ts'; @@ -115,12 +115,12 @@ describe('given JSON Schema definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as JSONSchemaElement; const { oneOf: oneOfValue } = jsonSchemaElement; - const sourceMap = oneOfValue?.get(0)?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [2, 2, 60]; - expect(oneOfValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(oneOfValue?.get(0)?.startPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.startPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.startIndex).to.equal(60); + expect(oneOfValue?.get(0)?.endPositionRow).to.equal(2); + expect(oneOfValue?.get(0)?.endPositionColumn).to.equal(2); + expect(oneOfValue?.get(0)?.endIndex).to.equal(60); }); }); diff --git a/packages/apidom-ns-openapi-2/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-openapi-2/src/refractor/plugins/replace-empty-element.ts index fff2684b20..7995ed8389 100644 --- a/packages/apidom-ns-openapi-2/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-openapi-2/src/refractor/plugins/replace-empty-element.ts @@ -9,6 +9,7 @@ import { includesClasses, cloneDeep, toValue, + assignSourceMap, } from '@swagger-api/apidom-core'; /** @@ -366,12 +367,14 @@ const plugin = () => () => ({ // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }); diff --git a/packages/apidom-ns-openapi-2/src/refractor/visitors/Visitor.ts b/packages/apidom-ns-openapi-2/src/refractor/visitors/Visitor.ts index a9b5296e53..919c49aac4 100644 --- a/packages/apidom-ns-openapi-2/src/refractor/visitors/Visitor.ts +++ b/packages/apidom-ns-openapi-2/src/refractor/visitors/Visitor.ts @@ -1,4 +1,10 @@ -import { Element, ObjectElement, hasElementSourceMap, deepmerge } from '@swagger-api/apidom-core'; +import { + Element, + ObjectElement, + hasElementSourceMap, + deepmerge, + assignSourceMap, +} from '@swagger-api/apidom-core'; /** * @public @@ -19,10 +25,9 @@ class Visitor { public copyMetaAndAttributes(from: Element, to: Element) { if (from.meta.length > 0 || to.meta.length > 0) { to.meta = deepmerge(to.meta, from.meta) as ObjectElement; - if (hasElementSourceMap(from)) { - // avoid deep merging of source maps - to.meta.set('sourceMap', from.meta.get('sourceMap')); - } + } + if (hasElementSourceMap(from)) { + assignSourceMap(to, from); } if (from.attributes.length > 0 || from.meta.length > 0) { to.attributes = deepmerge(to.attributes, from.attributes) as ObjectElement; // eslint-disable-line no-param-reassign diff --git a/packages/apidom-ns-openapi-2/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-openapi-2/test/refractor/plugins/replace-empty-element/mappings.ts index 3613e60afb..bad6107bab 100644 --- a/packages/apidom-ns-openapi-2/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-openapi-2/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, SwaggerElement } from '../../../../src/index.ts'; @@ -121,12 +121,12 @@ describe('given OpenAPI definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as SwaggerElement; const { info: infoValue } = swaggerElement; - const sourceMap = infoValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 5, 20]; - expect(infoValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(infoValue?.startPositionRow).to.equal(1); + expect(infoValue?.startPositionColumn).to.equal(5); + expect(infoValue?.startIndex).to.equal(20); + expect(infoValue?.endPositionRow).to.equal(1); + expect(infoValue?.endPositionColumn).to.equal(5); + expect(infoValue?.endIndex).to.equal(20); }); }); diff --git a/packages/apidom-ns-openapi-3-0/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-openapi-3-0/src/refractor/plugins/replace-empty-element.ts index 655ef37f96..c96cf4f320 100644 --- a/packages/apidom-ns-openapi-3-0/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-openapi-3-0/src/refractor/plugins/replace-empty-element.ts @@ -9,6 +9,7 @@ import { includesClasses, cloneDeep, toValue, + assignSourceMap, } from '@swagger-api/apidom-core'; /** @@ -635,12 +636,14 @@ const plugin = () => () => ({ // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }); diff --git a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/Visitor.ts b/packages/apidom-ns-openapi-3-0/src/refractor/visitors/Visitor.ts index c2c2436811..31375ad09a 100644 --- a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/Visitor.ts +++ b/packages/apidom-ns-openapi-3-0/src/refractor/visitors/Visitor.ts @@ -1,4 +1,10 @@ -import { Element, ObjectElement, deepmerge, hasElementSourceMap } from '@swagger-api/apidom-core'; +import { + Element, + ObjectElement, + assignSourceMap, + deepmerge, + hasElementSourceMap, +} from '@swagger-api/apidom-core'; /** * @public @@ -19,10 +25,9 @@ class Visitor { public copyMetaAndAttributes(from: Element, to: Element) { if (from.meta.length > 0 || to.meta.length > 0) { to.meta = deepmerge(to.meta, from.meta) as ObjectElement; - if (hasElementSourceMap(from)) { - // avoid deep merging of source maps - to.meta.set('sourceMap', from.meta.get('sourceMap')); - } + } + if (hasElementSourceMap(from)) { + assignSourceMap(to, from); } if (from.attributes.length > 0 || from.meta.length > 0) { to.attributes = deepmerge(to.attributes, from.attributes) as ObjectElement; // eslint-disable-line no-param-reassign diff --git a/packages/apidom-ns-openapi-3-0/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-openapi-3-0/test/refractor/plugins/replace-empty-element/mappings.ts index 2ab35c9c98..8a29cc60b7 100644 --- a/packages/apidom-ns-openapi-3-0/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-openapi-3-0/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, OpenApi3_0Element } from '../../../../src/index.ts'; @@ -119,12 +119,12 @@ describe('given OpenAPI definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as OpenApi3_0Element; const { info: infoValue } = openApiElement; - const sourceMap = infoValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 5, 20]; - expect(infoValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(infoValue?.startPositionRow).to.equal(1); + expect(infoValue?.startPositionColumn).to.equal(5); + expect(infoValue?.startIndex).to.equal(20); + expect(infoValue?.endPositionRow).to.equal(1); + expect(infoValue?.endPositionColumn).to.equal(5); + expect(infoValue?.endIndex).to.equal(20); }); }); diff --git a/packages/apidom-ns-openapi-3-1/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-openapi-3-1/src/refractor/plugins/replace-empty-element.ts index e04ec23992..123de7e79d 100644 --- a/packages/apidom-ns-openapi-3-1/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-openapi-3-1/src/refractor/plugins/replace-empty-element.ts @@ -2,6 +2,7 @@ import { ArrayElement, ObjectElement, StringElement, + assignSourceMap, cloneDeep, toValue, } from '@swagger-api/apidom-core'; @@ -703,12 +704,14 @@ const plugin = // no element factory found if (typeof elementFactory !== 'function') return undefined; - return elementFactory.call( + const result = elementFactory.call( { context }, undefined, cloneDeep(element.meta), cloneDeep(element.attributes), ); + + return assignSourceMap(result, element); }, }, }; diff --git a/packages/apidom-ns-openapi-3-1/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-openapi-3-1/test/refractor/plugins/replace-empty-element/mappings.ts index 38b300e200..011d6be24d 100644 --- a/packages/apidom-ns-openapi-3-1/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-openapi-3-1/test/refractor/plugins/replace-empty-element/mappings.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import dedent from 'dedent'; -import { sexprs, SourceMapElement } from '@swagger-api/apidom-core'; +import { sexprs } from '@swagger-api/apidom-core'; import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; import { refractorPluginReplaceEmptyElement, OpenApi3_1Element } from '../../../../src/index.ts'; @@ -119,12 +119,12 @@ describe('given OpenAPI definition with empty values', function () { plugins: [refractorPluginReplaceEmptyElement()], }) as OpenApi3_1Element; const { info: infoValue } = openApiElement; - const sourceMap = infoValue?.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedPosition = [1, 5, 20]; - expect(infoValue?.meta.get('sourceMap')).to.be.an.instanceof(SourceMapElement); - expect(positionStart.equals(expectedPosition)).to.be.true; - expect(positionEnd.equals(expectedPosition)).to.be.true; + expect(infoValue?.startPositionRow).to.equal(1); + expect(infoValue?.startPositionColumn).to.equal(5); + expect(infoValue?.startIndex).to.equal(20); + expect(infoValue?.endPositionRow).to.equal(1); + expect(infoValue?.endPositionColumn).to.equal(5); + expect(infoValue?.endIndex).to.equal(20); }); }); diff --git a/packages/apidom-parser-adapter-arazzo-yaml-1/test/adapter.ts b/packages/apidom-parser-adapter-arazzo-yaml-1/test/adapter.ts index d36adc3bdd..eb4ef18e81 100644 --- a/packages/apidom-parser-adapter-arazzo-yaml-1/test/adapter.ts +++ b/packages/apidom-parser-adapter-arazzo-yaml-1/test/adapter.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { assert, expect } from 'chai'; import dedent from 'dedent'; -import { isParseResultElement, SourceMapElement, sexprs } from '@swagger-api/apidom-core'; +import { isParseResultElement, sexprs } from '@swagger-api/apidom-core'; import { isArazzoSpecification1Element } from '@swagger-api/apidom-ns-arazzo-1'; import * as adapter from '../src/adapter.ts'; @@ -89,13 +89,13 @@ describe('adapter', function () { const { result } = await adapter.parse(yamlSource, { sourceMap: true }); // @ts-ignore const infoValue = result.get('info'); - const sourceMap = infoValue.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedEmptyPosition = [1, 5, 19]; - assert.instanceOf(sourceMap, SourceMapElement); - assert.isTrue(positionStart.equals(expectedEmptyPosition)); - assert.isTrue(positionEnd.equals(expectedEmptyPosition)); + expect(infoValue?.startPositionRow).to.equal(1); + expect(infoValue?.startPositionColumn).to.equal(5); + expect(infoValue?.startIndex).to.equal(19); + expect(infoValue?.endPositionRow).to.equal(1); + expect(infoValue?.endPositionColumn).to.equal(5); + expect(infoValue?.endIndex).to.equal(19); }); }); diff --git a/packages/apidom-parser-adapter-asyncapi-yaml-2/test/adapter.ts b/packages/apidom-parser-adapter-asyncapi-yaml-2/test/adapter.ts index 007a65ccc2..13901fbdca 100644 --- a/packages/apidom-parser-adapter-asyncapi-yaml-2/test/adapter.ts +++ b/packages/apidom-parser-adapter-asyncapi-yaml-2/test/adapter.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { assert, expect } from 'chai'; import dedent from 'dedent'; -import { isParseResultElement, SourceMapElement, sexprs } from '@swagger-api/apidom-core'; +import { isParseResultElement, sexprs } from '@swagger-api/apidom-core'; import { isAsyncApi2Element } from '@swagger-api/apidom-ns-asyncapi-2'; import * as adapter from '../src/adapter.ts'; @@ -85,13 +85,13 @@ describe('adapter', function () { const { result } = await adapter.parse(yamlSource, { sourceMap: true }); // @ts-ignore const infoValue = result.get('info'); - const sourceMap = infoValue.meta.get('sourceMap'); - const { positionStart, positionEnd } = sourceMap; - const expectedEmptyPosition = [1, 5, 21]; - assert.instanceOf(sourceMap, SourceMapElement); - assert.isTrue(positionStart.equals(expectedEmptyPosition)); - assert.isTrue(positionEnd.equals(expectedEmptyPosition)); + expect(infoValue?.startPositionRow).to.equal(1); + expect(infoValue?.startPositionColumn).to.equal(5); + expect(infoValue?.startIndex).to.equal(21); + expect(infoValue?.endPositionRow).to.equal(1); + expect(infoValue?.endPositionColumn).to.equal(5); + expect(infoValue?.endIndex).to.equal(21); }); }); diff --git a/packages/apidom-parser-adapter-json-schema-yaml-2020-12/test/adapter.ts b/packages/apidom-parser-adapter-json-schema-yaml-2020-12/test/adapter.ts index 1c880a4fef..d7b6b0f5df 100644 --- a/packages/apidom-parser-adapter-json-schema-yaml-2020-12/test/adapter.ts +++ b/packages/apidom-parser-adapter-json-schema-yaml-2020-12/test/adapter.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { assert, expect } from 'chai'; import dedent from 'dedent'; -import { isParseResultElement, SourceMapElement, sexprs } from '@swagger-api/apidom-core'; +import { isParseResultElement, hasElementSourceMap, sexprs } from '@swagger-api/apidom-core'; import { isJSONSchemaElement } from '@swagger-api/apidom-ns-json-schema-2020-12'; import * as adapter from '../src/adapter.ts'; @@ -78,7 +78,7 @@ describe('adapter', function () { // @ts-ignore const subMappingValue = result.get('mapping').get('sub-mapping'); - assert.instanceOf(subMappingValue.meta.get('sourceMap'), SourceMapElement); + assert.isTrue(hasElementSourceMap(subMappingValue)); }); }); diff --git a/packages/apidom-parser-adapter-json/src/syntactic-analysis/TreeCursorSyntaxNode.ts b/packages/apidom-parser-adapter-json/src/syntactic-analysis/TreeCursorSyntaxNode.ts index d1866d0814..34131df6e3 100644 --- a/packages/apidom-parser-adapter-json/src/syntactic-analysis/TreeCursorSyntaxNode.ts +++ b/packages/apidom-parser-adapter-json/src/syntactic-analysis/TreeCursorSyntaxNode.ts @@ -1,15 +1,19 @@ -import { TreeCursor as NodeTreeCursor, Point as NodePoint } from 'tree-sitter'; -import { TreeCursor as WebTreeCursor, Point as WebPoint } from 'web-tree-sitter'; +import { TreeCursor as NodeTreeCursor } from 'tree-sitter'; +import { TreeCursor as WebTreeCursor } from 'web-tree-sitter'; class TreeCursorSyntaxNode { public readonly type: string; - public readonly startPosition: NodePoint | WebPoint; + public readonly startPositionRow: number; - public readonly endPosition: NodePoint | WebPoint; + public readonly startPositionColumn: number; public readonly startIndex: number; + public readonly endPositionRow: number; + + public readonly endPositionColumn: number; + public readonly endIndex: number; public readonly text: string; @@ -26,9 +30,11 @@ class TreeCursorSyntaxNode { constructor(cursor: NodeTreeCursor | WebTreeCursor) { this.type = cursor.nodeType; - this.startPosition = cursor.startPosition; - this.endPosition = cursor.endPosition; + this.startPositionRow = cursor.startPosition.row; + this.startPositionColumn = cursor.startPosition.column; this.startIndex = cursor.startIndex; + this.endPositionRow = cursor.endPosition.row; + this.endPositionColumn = cursor.endPosition.column; this.endIndex = cursor.endIndex; this.text = cursor.nodeText; this.isNamed = cursor.nodeIsNamed; diff --git a/packages/apidom-parser-adapter-json/src/syntactic-analysis/direct/visitors/CstVisitor.ts b/packages/apidom-parser-adapter-json/src/syntactic-analysis/direct/visitors/CstVisitor.ts index 0b5f7cb9ce..e6c5c9c96a 100644 --- a/packages/apidom-parser-adapter-json/src/syntactic-analysis/direct/visitors/CstVisitor.ts +++ b/packages/apidom-parser-adapter-json/src/syntactic-analysis/direct/visitors/CstVisitor.ts @@ -4,13 +4,13 @@ import { NumberElement, ParseResultElement, Element, - SourceMapElement, MemberElement, ObjectElement, ArrayElement, StringElement, AnnotationElement, isPrimitiveElement, + assignSourceMap, } from '@swagger-api/apidom-core'; import TreeCursorSyntaxNode from '../../TreeCursorSyntaxNode.ts'; @@ -18,20 +18,6 @@ import TreeCursorSyntaxNode from '../../TreeCursorSyntaxNode.ts'; /* eslint-disable no-underscore-dangle */ class CstVisitor { - private static toPosition(node: TreeCursorSyntaxNode): Array { - const start = new ArrayElement([ - node.startPosition.row, - node.startPosition.column, - node.startIndex, - ]); - const end = new ArrayElement([node.endPosition.row, node.endPosition.column, node.endIndex]); - - start.classes.push('position'); - end.classes.push('position'); - - return [start, end]; - } - public sourceMap: boolean = false; public annotations: AnnotationElement[]; @@ -187,17 +173,7 @@ class CstVisitor { return; } - const sourceMap = new SourceMapElement(); - const position = CstVisitor.toPosition(node); - - if (position !== null) { - const [start, end] = position; - sourceMap.push(start); - sourceMap.push(end); - } - // @ts-ignore - sourceMap.astNode = node; - element.meta.set('sourceMap', sourceMap); + assignSourceMap(element, node); } } diff --git a/packages/apidom-parser-adapter-json/src/syntactic-analysis/indirect/visitors/CstVisitor.ts b/packages/apidom-parser-adapter-json/src/syntactic-analysis/indirect/visitors/CstVisitor.ts index 6efc24dac3..3d98c9a8dc 100644 --- a/packages/apidom-parser-adapter-json/src/syntactic-analysis/indirect/visitors/CstVisitor.ts +++ b/packages/apidom-parser-adapter-json/src/syntactic-analysis/indirect/visitors/CstVisitor.ts @@ -11,11 +11,11 @@ import { JsonStringContent, JsonTrue, ParseResult, - Position, - Point, Literal, Error, } from '@swagger-api/apidom-ast'; +import type { JsonValueOptions } from '@swagger-api/apidom-ast'; +import { assignSourceMap } from '@swagger-api/apidom-core'; import TreeCursorSyntaxNode from '../../TreeCursorSyntaxNode.ts'; @@ -32,30 +32,11 @@ export const keyMap = { /* eslint-disable class-methods-use-this */ class CstVisitor { - private static toPosition(node: TreeCursorSyntaxNode): Position { - const start = new Point({ - row: node.startPosition.row, - column: node.startPosition.column, - char: node.startIndex, - }); - const end = new Point({ - row: node.endPosition.row, - column: node.endPosition.column, - char: node.endIndex, - }); - - return new Position({ start, end }); - } - public readonly document = { enter: (node: TreeCursorSyntaxNode): JsonDocument => { - const position = CstVisitor.toPosition(node); - - return new JsonDocument({ - children: node.children, - position, - isMissing: node.isMissing, - }); + return new JsonDocument( + assignSourceMap({ children: node.children, isMissing: node.isMissing }, node), + ); }, leave: (document: JsonDocument): ParseResult => { return new ParseResult({ children: [document] }); @@ -65,77 +46,91 @@ class CstVisitor { public enter(node: TreeCursorSyntaxNode): Literal | undefined { // anonymous literals from CST transformed into AST literal nodes if (node instanceof TreeCursorSyntaxNode && !node.isNamed) { - const position = CstVisitor.toPosition(node); const value = node.type || node.text; const { isMissing } = node; - return new Literal({ value, position, isMissing }); + return new Literal(assignSourceMap({ value, isMissing }, node)); } return undefined; } public object(node: TreeCursorSyntaxNode): JsonObject { - const position = CstVisitor.toPosition(node); - - return new JsonObject({ children: node.children, position, isMissing: node.isMissing }); + return new JsonObject( + assignSourceMap({ children: node.children, isMissing: node.isMissing }, node), + ); } public pair(node: TreeCursorSyntaxNode): JsonProperty { - const position = CstVisitor.toPosition(node); const children = node.children.slice(1); const { keyNode } = node; - const key = new JsonKey({ - children: keyNode?.children || [], - position: keyNode != null ? CstVisitor.toPosition(keyNode) : undefined, - isMissing: keyNode != null ? keyNode.isMissing : false, - }); - - return new JsonProperty({ children: [key, ...children], position, isMissing: node.isMissing }); + const key = new JsonKey( + assignSourceMap( + { + children: keyNode?.children || [], + isMissing: keyNode != null ? keyNode.isMissing : false, + }, + keyNode, + ), + ); + + return new JsonProperty( + assignSourceMap( + { + children: [key, ...children], + isMissing: node.isMissing, + }, + node, + ), + ); } public array(node: TreeCursorSyntaxNode): JsonArray { - const position = CstVisitor.toPosition(node); - - return new JsonArray({ children: node.children, position, isMissing: node.isMissing }); + return new JsonArray( + assignSourceMap({ children: node.children, isMissing: node.isMissing }, node), + ); } public string(node: TreeCursorSyntaxNode): JsonString { - const position = CstVisitor.toPosition(node); const content = new JsonStringContent({ value: JSON.parse(node.text) }); - return new JsonString({ children: [content], position, isMissing: node.isMissing }); + return new JsonString( + assignSourceMap({ children: [content], isMissing: node.isMissing }, node), + ); } public number(node: TreeCursorSyntaxNode): JsonNumber { - const position = CstVisitor.toPosition(node); const value = node.text; - - return new JsonNumber({ value, position, isMissing: node.isMissing }); + return new JsonNumber( + assignSourceMap({ value, isMissing: node.isMissing }, node) as JsonValueOptions, + ); } // eslint-disable-next-line @typescript-eslint/naming-convention public null(node: TreeCursorSyntaxNode): JsonNull { - const position = CstVisitor.toPosition(node); const value = node.text; - return new JsonNull({ value, position, isMissing: node.isMissing }); + return new JsonNull( + assignSourceMap({ value, isMissing: node.isMissing }, node) as JsonValueOptions, + ); } // eslint-disable-next-line @typescript-eslint/naming-convention public true(node: TreeCursorSyntaxNode): JsonTrue { - const position = CstVisitor.toPosition(node); const value = node.text; - return new JsonTrue({ value, position, isMissing: node.isMissing }); + return new JsonTrue( + assignSourceMap({ value, isMissing: node.isMissing }, node) as JsonValueOptions, + ); } // eslint-disable-next-line @typescript-eslint/naming-convention public false(node: TreeCursorSyntaxNode): JsonFalse { - const position = CstVisitor.toPosition(node); const value = node.text; - return new JsonFalse({ value, position, isMissing: node.isMissing }); + return new JsonFalse( + assignSourceMap({ value, isMissing: node.isMissing }, node) as JsonValueOptions, + ); } public ERROR( @@ -144,14 +139,17 @@ class CstVisitor { parent: unknown, path: string[], ): ParseResult | Error { - const position = CstVisitor.toPosition(node); - const errorNode = new Error({ - children: node.children, - position, - isUnexpected: !node.hasError, - isMissing: node.isMissing, - value: node.text, - }); + const errorNode = new Error( + assignSourceMap( + { + children: node.children, + isUnexpected: !node.hasError, + isMissing: node.isMissing, + value: node.text, + }, + node, + ), + ); if (path.length === 0) { return new ParseResult({ children: [errorNode] }); diff --git a/packages/apidom-parser-adapter-json/src/syntactic-analysis/indirect/visitors/JsonAstVisitor.ts b/packages/apidom-parser-adapter-json/src/syntactic-analysis/indirect/visitors/JsonAstVisitor.ts index 9d3407a15e..07998ff6c9 100644 --- a/packages/apidom-parser-adapter-json/src/syntactic-analysis/indirect/visitors/JsonAstVisitor.ts +++ b/packages/apidom-parser-adapter-json/src/syntactic-analysis/indirect/visitors/JsonAstVisitor.ts @@ -20,7 +20,6 @@ import { Element, ParseResultElement, ObjectElement, - SourceMapElement, MemberElement, ArrayElement, BooleanElement, @@ -33,6 +32,7 @@ import { isElement, keyMap as keyMapApiDOM, getNodeType as getNodeTypeApiDOM, + assignSourceMap, } from '@swagger-api/apidom-core'; export const keyMap = { @@ -223,12 +223,7 @@ class JsonAstVisitor { return; } - const sourceMap = new SourceMapElement(); - // @ts-ignore - sourceMap.position = node.position; - // @ts-ignore - sourceMap.astNode = node; - element.meta.set('sourceMap', sourceMap); + assignSourceMap(element, node); } } diff --git a/packages/apidom-parser-adapter-json/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap b/packages/apidom-parser-adapter-json/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap index a253c9dedf..d6ee8fb8ed 100644 --- a/packages/apidom-parser-adapter-json/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap +++ b/packages/apidom-parser-adapter-json/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap @@ -8,131 +8,103 @@ TreeCursorSyntaxNode { TreeCursorSyntaxNode { children: Array [], endIndex: 1, - endPosition: Object { - column: 1, - row: 0, - }, + endPositionColumn: 1, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: false, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [, type: [, }, TreeCursorSyntaxNode { children: Array [], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: number, }, TreeCursorSyntaxNode { children: Array [], endIndex: 3, - endPosition: Object { - column: 3, - row: 0, - }, + endPositionColumn: 3, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: false, startIndex: 2, - startPosition: Object { - column: 2, - row: 0, - }, + startPositionColumn: 2, + startPositionRow: 0, text: ,, type: ,, }, TreeCursorSyntaxNode { children: Array [], endIndex: 5, - endPosition: Object { - column: 5, - row: 0, - }, + endPositionColumn: 5, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, startIndex: 4, - startPosition: Object { - column: 4, - row: 0, - }, + startPositionColumn: 4, + startPositionRow: 0, text: 2, type: number, }, TreeCursorSyntaxNode { children: Array [], endIndex: 6, - endPosition: Object { - column: 6, - row: 0, - }, + endPositionColumn: 6, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: false, startIndex: 5, - startPosition: Object { - column: 5, - row: 0, - }, + startPositionColumn: 5, + startPositionRow: 0, text: ], type: ], }, ], endIndex: 6, - endPosition: Object { - column: 6, - row: 0, - }, + endPositionColumn: 6, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [1, 2], type: array, }, ], endIndex: 6, - endPosition: Object { - column: 6, - row: 0, - }, + endPositionColumn: 6, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [1, 2], type: document, } diff --git a/packages/apidom-parser-adapter-openapi-yaml-2/test/adapter.ts b/packages/apidom-parser-adapter-openapi-yaml-2/test/adapter.ts index d8420f4e3c..b043b6eb67 100644 --- a/packages/apidom-parser-adapter-openapi-yaml-2/test/adapter.ts +++ b/packages/apidom-parser-adapter-openapi-yaml-2/test/adapter.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { assert, expect } from 'chai'; import dedent from 'dedent'; -import { isParseResultElement, SourceMapElement, sexprs } from '@swagger-api/apidom-core'; +import { isParseResultElement, hasElementSourceMap, sexprs } from '@swagger-api/apidom-core'; import { isSwaggerElement } from '@swagger-api/apidom-ns-openapi-2'; import * as adapter from '../src/adapter.ts'; @@ -86,7 +86,7 @@ describe('adapter', function () { // @ts-ignore const subMappingValue = result.get('mapping').get('sub-mapping'); - assert.instanceOf(subMappingValue.meta.get('sourceMap'), SourceMapElement); + assert.isTrue(hasElementSourceMap(subMappingValue)); }); }); diff --git a/packages/apidom-parser-adapter-openapi-yaml-3-0/test/adapter.ts b/packages/apidom-parser-adapter-openapi-yaml-3-0/test/adapter.ts index 46f898daaa..193b2865d5 100644 --- a/packages/apidom-parser-adapter-openapi-yaml-3-0/test/adapter.ts +++ b/packages/apidom-parser-adapter-openapi-yaml-3-0/test/adapter.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { assert, expect } from 'chai'; import dedent from 'dedent'; -import { isParseResultElement, SourceMapElement, sexprs } from '@swagger-api/apidom-core'; +import { isParseResultElement, sexprs, hasElementSourceMap } from '@swagger-api/apidom-core'; import { isOpenApi3_0Element } from '@swagger-api/apidom-ns-openapi-3-0'; import * as adapter from '../src/adapter.ts'; @@ -86,7 +86,7 @@ describe('adapter', function () { // @ts-ignore const subMappingValue = result.get('mapping').get('sub-mapping'); - assert.instanceOf(subMappingValue.meta.get('sourceMap'), SourceMapElement); + assert.isTrue(hasElementSourceMap(subMappingValue)); }); }); diff --git a/packages/apidom-parser-adapter-openapi-yaml-3-1/test/adapter.ts b/packages/apidom-parser-adapter-openapi-yaml-3-1/test/adapter.ts index 15b314c20d..dc3a2e8703 100644 --- a/packages/apidom-parser-adapter-openapi-yaml-3-1/test/adapter.ts +++ b/packages/apidom-parser-adapter-openapi-yaml-3-1/test/adapter.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { assert, expect } from 'chai'; import dedent from 'dedent'; -import { isParseResultElement, SourceMapElement, sexprs } from '@swagger-api/apidom-core'; +import { isParseResultElement, hasElementSourceMap, sexprs } from '@swagger-api/apidom-core'; import { isOpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1'; import * as adapter from '../src/adapter.ts'; @@ -86,7 +86,7 @@ describe('adapter', function () { // @ts-ignore const subMappingValue = result.get('mapping').get('sub-mapping'); - assert.instanceOf(subMappingValue.meta.get('sourceMap'), SourceMapElement); + assert.isTrue(hasElementSourceMap(subMappingValue)); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/TreeCursorSyntaxNode.ts b/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/TreeCursorSyntaxNode.ts index d12c7947f1..6cfde2ee6d 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/TreeCursorSyntaxNode.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/TreeCursorSyntaxNode.ts @@ -1,15 +1,19 @@ -import { TreeCursor as NodeTreeCursor, Point as NodePoint } from 'tree-sitter'; -import { TreeCursor as WebTreeCursor, Point as WebPoint } from 'web-tree-sitter'; +import { TreeCursor as NodeTreeCursor } from 'tree-sitter'; +import { TreeCursor as WebTreeCursor } from 'web-tree-sitter'; class TreeCursorSyntaxNode { public readonly type: string; - public readonly startPosition: NodePoint | WebPoint; + public readonly startPositionRow: number; - public readonly endPosition: NodePoint | WebPoint; + public readonly startPositionColumn: number; public readonly startIndex: number; + public readonly endPositionRow: number; + + public readonly endPositionColumn: number; + public readonly endIndex: number; public readonly text: string; @@ -28,9 +32,11 @@ class TreeCursorSyntaxNode { constructor(cursor: NodeTreeCursor | WebTreeCursor) { this.type = cursor.nodeType; - this.startPosition = cursor.startPosition; - this.endPosition = cursor.endPosition; + this.startPositionRow = cursor.startPosition.row; + this.startPositionColumn = cursor.startPosition.column; this.startIndex = cursor.startIndex; + this.endPositionRow = cursor.endPosition.row; + this.endPositionColumn = cursor.endPosition.column; this.endIndex = cursor.endIndex; this.text = cursor.nodeText; this.isNamed = cursor.nodeIsNamed; diff --git a/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/indirect/visitors/CstVisitor.ts b/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/indirect/visitors/CstVisitor.ts index 5d2a1a1c39..6205bd695c 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/indirect/visitors/CstVisitor.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/indirect/visitors/CstVisitor.ts @@ -3,8 +3,6 @@ import { isNode as isCSTNode, Literal, ParseResult, - Point, - Position, YamlNode, YamlAlias, YamlAnchor, @@ -22,6 +20,15 @@ import { YamlStyleGroup, YamlTag, } from '@swagger-api/apidom-ast'; +import type { + YamlAnchorOptions, + YamlDirectiveOptions, + YamlKeyValuePairOptions, + YamlNodeOptions, + YamlScalarOptions, + YamlTagOptions, +} from '@swagger-api/apidom-ast'; +import { assignSourceMap } from '@swagger-api/apidom-core'; import TreeCursorSyntaxNode from '../../TreeCursorSyntaxNode.ts'; @@ -54,30 +61,18 @@ class CstVisitor { node.type.endsWith(ending); } - private static toPosition(node: TreeCursorSyntaxNode): Position { - const start = new Point({ - row: node.startPosition.row, - column: node.startPosition.column, - char: node.startIndex, - }); - const end = new Point({ - row: node.endPosition.row, - column: node.endPosition.column, - char: node.endIndex, - }); - - return new Position({ start, end }); - } - private static kindNodeToYamlAnchor(node: TreeCursorSyntaxNode): YamlAnchor | undefined { const { anchor: anchorNode } = node; if (typeof anchorNode === 'undefined') return undefined; - - return new YamlAnchor({ - name: anchorNode.text, - position: CstVisitor.toPosition(anchorNode), - }); + return new YamlAnchor( + assignSourceMap( + { + name: anchorNode.text, + }, + anchorNode, + ) as YamlAnchorOptions, + ); } private static hasKeyValuePairEmptyKey(node: TreeCursorSyntaxNode): boolean { @@ -104,9 +99,8 @@ class CstVisitor { : node.type.endsWith('sequence') ? YamlNodeKind.Sequence : YamlNodeKind.Scalar; - const position = tagNode ? CstVisitor.toPosition(tagNode) : undefined; - return new YamlTag({ explicitName, kind, position }); + return new YamlTag(assignSourceMap({ explicitName, kind }, tagNode) as YamlTagOptions); } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -116,13 +110,15 @@ class CstVisitor { public readonly stream = { enter: (node: TreeCursorSyntaxNode): YamlStream => { - const position = CstVisitor.toPosition(node); - - return new YamlStream({ - children: node.children, - position, - isMissing: node.isMissing, - }); + return new YamlStream( + assignSourceMap( + { + children: node.children, + isMissing: node.isMissing, + }, + node, + ), + ); }, leave: (stream: YamlStream): ParseResult => { return new ParseResult({ children: [stream] }); @@ -131,32 +127,38 @@ class CstVisitor { public readonly yaml_directive = { enter: (node: TreeCursorSyntaxNode): YamlDirective => { - const position = CstVisitor.toPosition(node); const version = node?.firstNamedChild?.text; - return new YamlDirective({ - position, - name: '%YAML', - parameters: { - version, - }, - }); + return new YamlDirective( + assignSourceMap( + { + name: '%YAML', + parameters: { + version, + }, + }, + node, + ) as YamlDirectiveOptions, + ); }, }; public readonly tag_directive = { enter: (node: TreeCursorSyntaxNode): YamlDirective => { - const position = CstVisitor.toPosition(node); const tagHandleNode = node.children[0]; const tagPrefixNode = node.children[1]; - const tagDirective = new YamlDirective({ - position, - name: '%TAG', - parameters: { - handle: tagHandleNode?.text, - prefix: tagPrefixNode?.text, - }, - }); + const tagDirective = new YamlDirective( + assignSourceMap( + { + name: '%TAG', + parameters: { + handle: tagHandleNode?.text, + prefix: tagPrefixNode?.text, + }, + }, + node, + ) as YamlDirectiveOptions, + ); this.schema.registerTagDirective(tagDirective); @@ -166,31 +168,36 @@ class CstVisitor { public readonly reserved_directive = { enter: (node: TreeCursorSyntaxNode): YamlDirective => { - const position = CstVisitor.toPosition(node); const directiveNameNode = node.children[0]; const directiveParameter1Node = node.children[1]; const directiveParameter2Node = node.children[2]; - return new YamlDirective({ - position, - name: directiveNameNode?.text, - parameters: { - handle: directiveParameter1Node?.text, - prefix: directiveParameter2Node?.text, - }, - }); + return new YamlDirective( + assignSourceMap( + { + name: directiveNameNode?.text, + parameters: { + handle: directiveParameter1Node?.text, + prefix: directiveParameter2Node?.text, + }, + }, + node, + ) as YamlDirectiveOptions, + ); }, }; public readonly document = { enter: (node: TreeCursorSyntaxNode): YamlDocument => { - const position = CstVisitor.toPosition(node); - - return new YamlDocument({ - children: node.children, - position, - isMissing: node.isMissing, - }); + return new YamlDocument( + assignSourceMap( + { + children: node.children, + isMissing: node.isMissing, + }, + node, + ), + ); }, leave: (node: YamlDocument): void => { node.children = node.children.flat(); @@ -215,18 +222,17 @@ class CstVisitor { ) { return node.children; } - // kind node not present in flow node, creating empty node - const emptyPoint = new Point({ - row: kindCandidate.endPosition.row, - column: kindCandidate.endPosition.column, - char: kindCandidate.endIndex, - }); const emptyScalarNode = new YamlScalar({ content: '', anchor: CstVisitor.kindNodeToYamlAnchor(kindCandidate), tag: CstVisitor.kindNodeToYamlTag(kindCandidate), - position: new Position({ start: emptyPoint, end: emptyPoint }), + startPositionRow: kindCandidate.endPositionRow, + startPositionColumn: kindCandidate.endPositionColumn, + startIndex: kindCandidate.endIndex, + endPositionRow: kindCandidate.endPositionRow, + endPositionColumn: kindCandidate.endPositionColumn, + endIndex: kindCandidate.endIndex, styleGroup: YamlStyleGroup.Flow, style: YamlStyle.Plain, }); @@ -251,18 +257,21 @@ class CstVisitor { public readonly block_mapping = { enter: (node: TreeCursorSyntaxNode) => { - const position = CstVisitor.toPosition(node); const tag = CstVisitor.kindNodeToYamlTag(node); const anchor = CstVisitor.kindNodeToYamlAnchor(node); - const mappingNode = new YamlMapping({ - children: node.children, - position, - anchor, - tag, - styleGroup: YamlStyleGroup.Block, - style: YamlStyle.NextLine, - isMissing: node.isMissing, - }); + const mappingNode = new YamlMapping( + assignSourceMap( + { + children: node.children, + anchor, + tag, + styleGroup: YamlStyleGroup.Block, + style: YamlStyle.NextLine, + isMissing: node.isMissing, + }, + node, + ) as YamlNodeOptions, + ); this.registerAnchor(mappingNode); @@ -272,7 +281,6 @@ class CstVisitor { public readonly block_mapping_pair = { enter: (node: TreeCursorSyntaxNode): YamlKeyValuePair => { - const position = CstVisitor.toPosition(node); const children: Array = [...node.children]; if (CstVisitor.hasKeyValuePairEmptyKey(node)) { @@ -284,29 +292,36 @@ class CstVisitor { children.push(valueNode); } - return new YamlKeyValuePair({ - children, - position, - styleGroup: YamlStyleGroup.Block, - isMissing: node.isMissing, - }); + return new YamlKeyValuePair( + assignSourceMap( + { + children, + styleGroup: YamlStyleGroup.Block, + isMissing: node.isMissing, + }, + node, + ) as YamlKeyValuePairOptions, + ); }, }; public readonly flow_mapping = { enter: (node: TreeCursorSyntaxNode) => { - const position = CstVisitor.toPosition(node); const tag = CstVisitor.kindNodeToYamlTag(node); const anchor = CstVisitor.kindNodeToYamlAnchor(node); - const mappingNode = new YamlMapping({ - children: node.children, - position, - anchor, - tag, - styleGroup: YamlStyleGroup.Flow, - style: YamlStyle.Explicit, - isMissing: node.isMissing, - }); + const mappingNode = new YamlMapping( + assignSourceMap( + { + children: node.children, + anchor, + tag, + styleGroup: YamlStyleGroup.Flow, + style: YamlStyle.Explicit, + isMissing: node.isMissing, + }, + node, + ) as YamlNodeOptions, + ); this.registerAnchor(mappingNode); @@ -316,7 +331,6 @@ class CstVisitor { public readonly flow_pair = { enter: (node: TreeCursorSyntaxNode): YamlKeyValuePair => { - const position = CstVisitor.toPosition(node); const children: Array = [...node.children]; if (CstVisitor.hasKeyValuePairEmptyKey(node)) { @@ -328,12 +342,16 @@ class CstVisitor { children.push(valueNode); } - return new YamlKeyValuePair({ - children, - position, - styleGroup: YamlStyleGroup.Flow, - isMissing: node.isMissing, - }); + return new YamlKeyValuePair( + assignSourceMap( + { + children, + styleGroup: YamlStyleGroup.Flow, + isMissing: node.isMissing, + }, + node, + ) as YamlKeyValuePairOptions, + ); }, }; @@ -345,17 +363,20 @@ class CstVisitor { public readonly block_sequence = { enter: (node: TreeCursorSyntaxNode) => { - const position = CstVisitor.toPosition(node); const tag = CstVisitor.kindNodeToYamlTag(node); const anchor = CstVisitor.kindNodeToYamlAnchor(node); - const sequenceNode = new YamlSequence({ - children: node.children, - position, - anchor, - tag, - styleGroup: YamlStyleGroup.Block, - style: YamlStyle.NextLine, - }); + const sequenceNode = new YamlSequence( + assignSourceMap( + { + children: node.children, + anchor, + tag, + styleGroup: YamlStyleGroup.Block, + style: YamlStyle.NextLine, + }, + node, + ) as YamlNodeOptions, + ); this.registerAnchor(sequenceNode); @@ -371,18 +392,18 @@ class CstVisitor { } // create empty node - const emptyPoint = new Point({ - row: node.endPosition.row, - column: node.endPosition.column, - char: node.endIndex, - }); const emptyScalarNode = new YamlScalar({ content: '', tag: new YamlTag({ explicitName: '?', kind: YamlNodeKind.Scalar, }), - position: new Position({ start: emptyPoint, end: emptyPoint }), + startPositionRow: node.endPositionRow, + startPositionColumn: node.endPositionColumn, + startIndex: node.endIndex, + endPositionRow: node.endPositionRow, + endPositionColumn: node.endPositionColumn, + endIndex: node.endIndex, styleGroup: YamlStyleGroup.Flow, style: YamlStyle.Plain, }); @@ -393,17 +414,20 @@ class CstVisitor { public readonly flow_sequence = { enter: (node: TreeCursorSyntaxNode) => { - const position = CstVisitor.toPosition(node); const tag = CstVisitor.kindNodeToYamlTag(node); const anchor = CstVisitor.kindNodeToYamlAnchor(node); - const sequenceNode = new YamlSequence({ - children: node.children.flat(), - position, - anchor, - tag, - styleGroup: YamlStyleGroup.Flow, - style: YamlStyle.Explicit, - }); + const sequenceNode = new YamlSequence( + assignSourceMap( + { + children: node.children.flat(), + anchor, + tag, + styleGroup: YamlStyleGroup.Flow, + style: YamlStyle.Explicit, + }, + node, + ) as YamlNodeOptions, + ); this.registerAnchor(sequenceNode); @@ -419,17 +443,20 @@ class CstVisitor { public readonly plain_scalar = { enter: (node: TreeCursorSyntaxNode) => { - const position = CstVisitor.toPosition(node); const tag = CstVisitor.kindNodeToYamlTag(node); const anchor = CstVisitor.kindNodeToYamlAnchor(node); - const scalarNode = new YamlScalar({ - content: node.text, - anchor, - tag, - position, - styleGroup: YamlStyleGroup.Flow, - style: YamlStyle.Plain, - }); + const scalarNode = new YamlScalar( + assignSourceMap( + { + content: node.text, + anchor, + tag, + styleGroup: YamlStyleGroup.Flow, + style: YamlStyle.Plain, + }, + node, + ) as YamlScalarOptions, + ); this.registerAnchor(scalarNode); @@ -439,17 +466,20 @@ class CstVisitor { public readonly single_quote_scalar = { enter: (node: TreeCursorSyntaxNode) => { - const position = CstVisitor.toPosition(node); const tag = CstVisitor.kindNodeToYamlTag(node); const anchor = CstVisitor.kindNodeToYamlAnchor(node); - const scalarNode = new YamlScalar({ - content: node.text, - anchor, - tag, - position, - styleGroup: YamlStyleGroup.Flow, - style: YamlStyle.SingleQuoted, - }); + const scalarNode = new YamlScalar( + assignSourceMap( + { + content: node.text, + anchor, + tag, + styleGroup: YamlStyleGroup.Flow, + style: YamlStyle.SingleQuoted, + }, + node, + ) as YamlScalarOptions, + ); this.registerAnchor(scalarNode); @@ -459,17 +489,20 @@ class CstVisitor { public readonly double_quote_scalar = { enter: (node: TreeCursorSyntaxNode) => { - const position = CstVisitor.toPosition(node); const tag = CstVisitor.kindNodeToYamlTag(node); const anchor = CstVisitor.kindNodeToYamlAnchor(node); - const scalarNode = new YamlScalar({ - content: node.text, - anchor, - tag, - position, - styleGroup: YamlStyleGroup.Flow, - style: YamlStyle.DoubleQuoted, - }); + const scalarNode = new YamlScalar( + assignSourceMap( + { + content: node.text, + anchor, + tag, + styleGroup: YamlStyleGroup.Flow, + style: YamlStyle.DoubleQuoted, + }, + node, + ) as YamlScalarOptions, + ); this.registerAnchor(scalarNode); @@ -479,7 +512,6 @@ class CstVisitor { public readonly block_scalar = { enter: (node: TreeCursorSyntaxNode) => { - const position = CstVisitor.toPosition(node); const tag = CstVisitor.kindNodeToYamlTag(node); const anchor = CstVisitor.kindNodeToYamlAnchor(node); const style = node.text.startsWith('|') @@ -487,14 +519,18 @@ class CstVisitor { : node.text.startsWith('>') ? YamlStyle.Folded : YamlStyle.Plain; - const scalarNode = new YamlScalar({ - content: node.text, - anchor, - tag, - position, - styleGroup: YamlStyleGroup.Block, - style, - }); + const scalarNode = new YamlScalar( + assignSourceMap( + { + content: node.text, + anchor, + tag, + styleGroup: YamlStyleGroup.Block, + style, + }, + node, + ) as YamlScalarOptions, + ); this.registerAnchor(scalarNode); @@ -525,11 +561,18 @@ class CstVisitor { public enter(node: TreeCursorSyntaxNode): Literal | undefined { // missing anonymous literals from CST transformed into AST literal nodes if (node instanceof TreeCursorSyntaxNode && !node.isNamed) { - const position = CstVisitor.toPosition(node); const value = node.type || node.text; const { isMissing } = node; - return new Literal({ value, position, isMissing }); + return new Literal( + assignSourceMap( + { + value, + isMissing, + }, + node, + ), + ); } return undefined; @@ -542,14 +585,17 @@ class CstVisitor { parent: unknown, path: string[], ): Error | ParseResult { - const position = CstVisitor.toPosition(node); - const errorNode = new Error({ - children: node.children, - position, - isUnexpected: !node.hasError, - isMissing: node.isMissing, - value: node.text, - }); + const errorNode = new Error( + assignSourceMap( + { + children: node.children, + isUnexpected: !node.hasError, + isMissing: node.isMissing, + value: node.text, + }, + node, + ), + ); if (path.length === 0) { return new ParseResult({ children: [errorNode] }); @@ -565,33 +611,44 @@ class CstVisitor { } private createKeyValuePairEmptyKey(node: TreeCursorSyntaxNode): YamlScalar { - const emptyPoint = new Point({ - row: node.startPosition.row, - column: node.startPosition.column, - char: node.startIndex, - }); const { keyNode } = node; const children = keyNode?.children || []; const tagNode = children.find(CstVisitor.isKind('tag')); const anchorNode = children.find(CstVisitor.isKind('anchor')); const tag = typeof tagNode !== 'undefined' - ? new YamlTag({ - explicitName: tagNode.text, - kind: YamlNodeKind.Scalar, - position: CstVisitor.toPosition(tagNode), - }) + ? new YamlTag( + assignSourceMap( + { + explicitName: tagNode.text, + kind: YamlNodeKind.Scalar, + }, + tagNode, + ) as YamlTagOptions, + ) : new YamlTag({ explicitName: '?', kind: YamlNodeKind.Scalar, }); const anchor = typeof anchorNode !== 'undefined' - ? new YamlAnchor({ name: anchorNode.text, position: CstVisitor.toPosition(anchorNode) }) + ? new YamlAnchor( + assignSourceMap( + { + name: anchorNode.text, + }, + anchorNode, + ) as YamlAnchorOptions, + ) : undefined; const scalarNode = new YamlScalar({ content: '', - position: new Position({ start: emptyPoint, end: emptyPoint }), + startPositionRow: node.startPositionRow, + startPositionColumn: node.startPositionColumn, + startIndex: node.startIndex, + endPositionRow: node.startPositionRow, + endPositionColumn: node.startPositionColumn, + endIndex: node.startIndex, tag, anchor, styleGroup: YamlStyleGroup.Flow, @@ -604,33 +661,44 @@ class CstVisitor { } private createKeyValuePairEmptyValue(node: TreeCursorSyntaxNode): YamlScalar { - const emptyPoint = new Point({ - row: node.endPosition.row, - column: node.endPosition.column, - char: node.endIndex, - }); const { valueNode } = node; const children = valueNode?.children || []; const tagNode = children.find(CstVisitor.isKind('tag')); const anchorNode = children.find(CstVisitor.isKind('anchor')); const tag = typeof tagNode !== 'undefined' - ? new YamlTag({ - explicitName: tagNode.text, - kind: YamlNodeKind.Scalar, - position: CstVisitor.toPosition(tagNode), - }) + ? new YamlTag( + assignSourceMap( + { + explicitName: tagNode.text, + kind: YamlNodeKind.Scalar, + }, + tagNode, + ) as YamlTagOptions, + ) : new YamlTag({ explicitName: '?', kind: YamlNodeKind.Scalar, }); const anchor = typeof anchorNode !== 'undefined' - ? new YamlAnchor({ name: anchorNode.text, position: CstVisitor.toPosition(anchorNode) }) + ? new YamlAnchor( + assignSourceMap( + { + name: anchorNode.text, + }, + anchorNode, + ) as YamlAnchorOptions, + ) : undefined; const scalarNode = new YamlScalar({ content: '', - position: new Position({ start: emptyPoint, end: emptyPoint }), + startPositionRow: node.endPositionRow, + startPositionColumn: node.endPositionColumn, + startIndex: node.endIndex, + endPositionRow: node.endPositionRow, + endPositionColumn: node.endPositionColumn, + endIndex: node.endIndex, tag, anchor, styleGroup: YamlStyleGroup.Flow, diff --git a/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.ts b/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.ts index a3fdfee584..59dd2270e3 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.ts @@ -11,12 +11,12 @@ import { isNode as isCSTNode, YamlScalar, YamlStyle, + Node, } from '@swagger-api/apidom-ast'; import { ParseResultElement, AnnotationElement, CommentElement, - SourceMapElement, Element, MemberElement, ObjectElement, @@ -27,6 +27,7 @@ import { getNodeType as getNodeTypeApiDOM, Namespace, createNamespace, + assignSourceMap, } from '@swagger-api/apidom-core'; export const keyMap = { @@ -212,17 +213,12 @@ class YamlAstVisitor { return null; } - private maybeAddSourceMap(node: unknown, element: Element): void { + private maybeAddSourceMap(node: T, element: Element): void { if (!this.sourceMap) { return; } - const sourceMap = new SourceMapElement(); - // @ts-ignore - sourceMap.position = node.position; - // @ts-ignore - sourceMap.astNode = node; - element.meta.set('sourceMap', sourceMap); + assignSourceMap(element, node); } } diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-properties.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-properties.ts index 6e15171275..484f63ab76 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-properties.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-properties.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node with tag and anchor as block mapping key', function ( it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 12); - assert.strictEqual(char, 12); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 12); + assert.strictEqual(startIndex, 12); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 12); - assert.strictEqual(char, 12); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 12); + assert.strictEqual(endIndex, 12); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value-opt-key-indicator.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value-opt-key-indicator.ts index 93f72716af..a1701f4933 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value-opt-key-indicator.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value-opt-key-indicator.ts @@ -1,6 +1,6 @@ import { assert } from 'chai'; import dedent from 'dedent'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -25,37 +25,26 @@ describe('given block mapping pair specified as optional “?” mapping key ind it('should generate source maps for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 1); - assert.strictEqual(column, 0); - assert.strictEqual(char, 11); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 1); + assert.strictEqual(startPositionColumn, 0); + assert.strictEqual(startIndex, 11); }); it('should generate proper source map end position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 1); - assert.strictEqual(column, 0); - assert.strictEqual(char, 11); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 1); + assert.strictEqual(endPositionColumn, 0); + assert.strictEqual(endIndex, 11); }); it('should create empty value element', async function () { @@ -66,36 +55,25 @@ describe('given block mapping pair specified as optional “?” mapping key ind it('should generate source maps for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 1); - assert.strictEqual(column, 1); - assert.strictEqual(char, 12); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 1); + assert.strictEqual(startPositionColumn, 1); + assert.strictEqual(startIndex, 12); }); it('should generate proper source map end position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 1); - assert.strictEqual(column, 1); - assert.strictEqual(char, 12); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 1); + assert.strictEqual(endPositionColumn, 1); + assert.strictEqual(endIndex, 12); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value-properties.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value-properties.ts index c2cfe182d9..39ac51ab32 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value-properties.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value-properties.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -21,37 +21,26 @@ describe('given block mapping pair containing empty fields and explicit tag and it('should generate source maps for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 12); - assert.strictEqual(char, 12); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 12); + assert.strictEqual(startIndex, 12); }); it('should generate proper source map end position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 12); - assert.strictEqual(char, 12); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 12); + assert.strictEqual(endIndex, 12); }); it('should create empty value element', async function () { @@ -62,36 +51,25 @@ describe('given block mapping pair containing empty fields and explicit tag and it('should generate source maps for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 27); - assert.strictEqual(char, 27); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 27); + assert.strictEqual(startIndex, 27); }); it('should generate proper source map end position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 27); - assert.strictEqual(char, 27); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 27); + assert.strictEqual(endIndex, 27); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value.ts index 24923e14c1..74d5892e06 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key-value.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -21,37 +21,26 @@ describe('given block mapping pair with empty key and value', function () { it('should generate source maps for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 0); - assert.strictEqual(char, 0); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 0); + assert.strictEqual(startIndex, 0); }); it('should generate proper source map end position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 0); - assert.strictEqual(char, 0); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 0); + assert.strictEqual(endIndex, 0); }); it('should create empty value element', async function () { @@ -62,36 +51,25 @@ describe('given block mapping pair with empty key and value', function () { it('should generate source maps for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 1); - assert.strictEqual(char, 1); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 1); + assert.strictEqual(startIndex, 1); }); it('should generate proper source map end position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 1); - assert.strictEqual(char, 1); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 1); + assert.strictEqual(endIndex, 1); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key.ts index 5c4b6aaf30..174131dadd 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-key.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node as block mapping key', function () { it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 0); - assert.strictEqual(char, 0); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 0); + assert.strictEqual(startIndex, 0); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 0); - assert.strictEqual(char, 0); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 0); + assert.strictEqual(endIndex, 0); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-value-properties.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-value-properties.ts index 12a57c9689..0882942901 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-value-properties.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-value-properties.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node with tag and anchor as block mapping value', function it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 17); - assert.strictEqual(char, 17); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 17); + assert.strictEqual(startIndex, 17); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 17); - assert.strictEqual(char, 17); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 17); + assert.strictEqual(endIndex, 17); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-value.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-value.ts index fb202569b7..628955e0b1 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-value.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/block-maping/empty-value.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node as block mapping value', function () { it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 4); - assert.strictEqual(char, 4); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 4); + assert.strictEqual(startIndex, 4); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 4); - assert.strictEqual(char, 4); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 4); + assert.strictEqual(endIndex, 4); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-properties.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-properties.ts index 5375a05cde..e7e06c0a96 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-properties.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-properties.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node with tag and anchor as flow mapping key', function () it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 13); - assert.strictEqual(char, 13); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 13); + assert.strictEqual(startIndex, 13); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 13); - assert.strictEqual(char, 13); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 13); + assert.strictEqual(endIndex, 13); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value-opt-key-indicator.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value-opt-key-indicator.ts index da44b80020..e1c577c2e0 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value-opt-key-indicator.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value-opt-key-indicator.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -21,37 +21,26 @@ describe('given flow mapping pair specified as optional “?” mapping key indi it('should generate source maps for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 14); - assert.strictEqual(char, 14); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 14); + assert.strictEqual(startIndex, 14); }); it('should generate proper source map end position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 14); - assert.strictEqual(char, 14); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 14); + assert.strictEqual(endIndex, 14); }); it('should create empty value element', async function () { @@ -62,36 +51,25 @@ describe('given flow mapping pair specified as optional “?” mapping key indi it('should generate source maps for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 15); - assert.strictEqual(char, 15); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 15); + assert.strictEqual(startIndex, 15); }); it('should generate proper source map end position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 15); - assert.strictEqual(char, 15); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 15); + assert.strictEqual(endIndex, 15); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value-properties.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value-properties.ts index 602b8a4bca..98eea02e2f 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value-properties.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value-properties.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -21,37 +21,26 @@ describe('given flow mapping pair containing empty fields and explicit tag and a it('should generate source maps for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 13); - assert.strictEqual(char, 13); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 13); + assert.strictEqual(startIndex, 13); }); it('should generate proper source map end position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 13); - assert.strictEqual(char, 13); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 13); + assert.strictEqual(endIndex, 13); }); it('should create empty value element', async function () { @@ -62,36 +51,25 @@ describe('given flow mapping pair containing empty fields and explicit tag and a it('should generate source maps for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 28); - assert.strictEqual(char, 28); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 28); + assert.strictEqual(startIndex, 28); }); it('should generate proper source map end position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 28); - assert.strictEqual(char, 28); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 28); + assert.strictEqual(endIndex, 28); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value.ts index 52e7fcdedd..9aab75ade4 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key-value.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -21,37 +21,26 @@ describe('given flow mapping pair with empty key and value', function () { it('should generate source maps for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 1); - assert.strictEqual(char, 1); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 1); + assert.strictEqual(startIndex, 1); }); it('should generate proper source map end position for empty key', async function () { const emptyElement = await setupEmptyKeyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 1); - assert.strictEqual(char, 1); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 1); + assert.strictEqual(endIndex, 1); }); it('should create empty value element', async function () { @@ -62,36 +51,25 @@ describe('given flow mapping pair with empty key and value', function () { it('should generate source maps for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 2); - assert.strictEqual(char, 2); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 2); + assert.strictEqual(startIndex, 2); }); it('should generate proper source map end position for empty value', async function () { const emptyElement = await setupEmptyValueElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 2); - assert.strictEqual(char, 2); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 2); + assert.strictEqual(endIndex, 2); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key.ts index 19dbddb65c..30c775cf7c 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-key.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node as flow mapping key', function () { it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 1); - assert.strictEqual(char, 1); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 1); + assert.strictEqual(startIndex, 1); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 1); - assert.strictEqual(char, 1); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 1); + assert.strictEqual(endIndex, 1); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-value-properties.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-value-properties.ts index 7df6dcd383..d64b519773 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-value-properties.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-value-properties.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node with tag and anchor as flow mapping value', function it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 18); - assert.strictEqual(char, 18); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 18); + assert.strictEqual(startIndex, 18); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 18); - assert.strictEqual(char, 18); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 18); + assert.strictEqual(endIndex, 18); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-value.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-value.ts index b73e5ccce7..18eee74c30 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-value.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/mappings/flow-mapping/empty-value.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node as flow mapping value', function () { it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 5); - assert.strictEqual(char, 5); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 5); + assert.strictEqual(startIndex, 5); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 5); - assert.strictEqual(char, 5); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 5); + assert.strictEqual(endIndex, 5); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/scalars/flow-scalar/empty-flow-scalar-properties.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/scalars/flow-scalar/empty-flow-scalar-properties.ts index 9ef1f753c8..a58c6548d4 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/scalars/flow-scalar/empty-flow-scalar-properties.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/scalars/flow-scalar/empty-flow-scalar-properties.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -18,36 +18,25 @@ describe('given empty flow scalar node with and explicit tag and anchor', functi it('should generate source maps', async function () { const emptyElement = await setupMemberElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupMemberElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 12); - assert.strictEqual(char, 12); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 12); + assert.strictEqual(startIndex, 12); }); it('should generate proper source map end position', async function () { const emptyElement = await setupMemberElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 12); - assert.strictEqual(char, 12); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 12); + assert.strictEqual(endIndex, 12); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/sequences/block-sequence/empty-block-sequence-item.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/sequences/block-sequence/empty-block-sequence-item.ts index 50e201d20d..a29aaf1244 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/sequences/block-sequence/empty-block-sequence-item.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/sequences/block-sequence/empty-block-sequence-item.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node as block sequence item', function () { it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 1); - assert.strictEqual(char, 1); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 1); + assert.strictEqual(startIndex, 1); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 1); - assert.strictEqual(char, 1); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 1); + assert.strictEqual(endIndex, 1); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/sequences/flow-sequence/empty-flow-sequence-item-properties.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/sequences/flow-sequence/empty-flow-sequence-item-properties.ts index c373f019d7..159491f86d 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/sequences/flow-sequence/empty-flow-sequence-item-properties.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/empty-nodes/sequences/flow-sequence/empty-flow-sequence-item-properties.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import { includesClasses, toValue, SourceMapElement } from '@swagger-api/apidom-core'; +import { includesClasses, hasElementSourceMap } from '@swagger-api/apidom-core'; import * as adapter from '../../../../../src/adapter-node.ts'; @@ -19,36 +19,25 @@ describe('given empty node with tag and anchor as flow sequence item', function it('should generate source maps', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - assert.instanceOf(sourceMapElement, SourceMapElement); + assert.isTrue(hasElementSourceMap(emptyElement)); }); it('should generate proper source map start position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionStart.get(0)), - toValue(sourceMapElement.positionStart.get(1)), - toValue(sourceMapElement.positionStart.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 16); - assert.strictEqual(char, 16); + const { startPositionRow, startPositionColumn, startIndex } = emptyElement; + + assert.strictEqual(startPositionRow, 0); + assert.strictEqual(startPositionColumn, 16); + assert.strictEqual(startIndex, 16); }); it('should generate proper source map end position', async function () { const emptyElement = await setupEmptyElement(); - const sourceMapElement = emptyElement.meta.get('sourceMap'); - const [row, column, char] = [ - toValue(sourceMapElement.positionEnd.get(0)), - toValue(sourceMapElement.positionEnd.get(1)), - toValue(sourceMapElement.positionEnd.get(2)), - ]; - - assert.strictEqual(row, 0); - assert.strictEqual(column, 16); - assert.strictEqual(char, 16); + const { endPositionRow, endPositionColumn, endIndex } = emptyElement; + + assert.strictEqual(endPositionRow, 0); + assert.strictEqual(endPositionColumn, 16); + assert.strictEqual(endIndex, 16); }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/index.ts b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/index.ts index 2ae55fb5b3..85f8a8d107 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/index.ts +++ b/packages/apidom-parser-adapter-yaml-1-2/test/adapter-node/index.ts @@ -155,8 +155,12 @@ describe('adapter-node', function () { tagKind: 'Scalar', nodeCanonicalContent: undefined, }); - assert.include(error.tagPosition?.start, { type: 'point', row: 0, column: 6, char: 6 }); - assert.include(error.tagPosition?.end, { type: 'point', row: 0, column: 18, char: 18 }); + expect(error.tagStartPositionRow).to.equal(0); + expect(error.tagStartPositionColumn).to.equal(6); + expect(error.tagStartPositionIndex).to.equal(6); + expect(error.tagEndPositionRow).to.equal(0); + expect(error.tagEndPositionColumn).to.equal(18); + expect(error.tagEndPositionIndex).to.equal(18); } }); }); @@ -177,8 +181,12 @@ describe('adapter-node', function () { tagKind: 'Scalar', nodeCanonicalContent: 'value', }); - assert.include(error.tagPosition?.start, { type: 'point', row: 0, column: 6, char: 6 }); - assert.include(error.tagPosition?.end, { type: 'point', row: 0, column: 11, char: 11 }); + expect(error.tagStartPositionRow).to.equal(0); + expect(error.tagStartPositionColumn).to.equal(6); + expect(error.tagStartPositionIndex).to.equal(6); + expect(error.tagEndPositionRow).to.equal(0); + expect(error.tagEndPositionColumn).to.equal(11); + expect(error.tagEndPositionIndex).to.equal(11); } }); }); diff --git a/packages/apidom-parser-adapter-yaml-1-2/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap b/packages/apidom-parser-adapter-yaml-1-2/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap index 6f7a2f5566..5b48d023e3 100644 --- a/packages/apidom-parser-adapter-yaml-1-2/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap +++ b/packages/apidom-parser-adapter-yaml-1-2/test/syntactic-analysis/__snapshots__/TreeCursorIterator.mjs.snap @@ -12,20 +12,16 @@ TreeCursorSyntaxNode { TreeCursorSyntaxNode { children: Array [], endIndex: 1, - endPosition: Object { - column: 1, - row: 0, - }, + endPositionColumn: 1, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: false, previousSibling: undefined, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [, type: [, }, @@ -36,48 +32,38 @@ TreeCursorSyntaxNode { TreeCursorSyntaxNode { children: Array [], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: integer_scalar, }, ], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: plain_scalar, }, ], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -85,38 +71,30 @@ TreeCursorSyntaxNode { previousSibling: TreeCursorSyntaxNode { children: Array [], endIndex: 1, - endPosition: Object { - column: 1, - row: 0, - }, + endPositionColumn: 1, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: false, previousSibling: undefined, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [, type: [, }, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: flow_node, }, TreeCursorSyntaxNode { children: Array [], endIndex: 3, - endPosition: Object { - column: 3, - row: 0, - }, + endPositionColumn: 3, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -128,48 +106,38 @@ TreeCursorSyntaxNode { TreeCursorSyntaxNode { children: Array [], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: integer_scalar, }, ], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: plain_scalar, }, ], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -177,36 +145,28 @@ TreeCursorSyntaxNode { previousSibling: TreeCursorSyntaxNode { children: Array [], endIndex: 1, - endPosition: Object { - column: 1, - row: 0, - }, + endPositionColumn: 1, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: false, previousSibling: undefined, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [, type: [, }, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: flow_node, }, startIndex: 2, - startPosition: Object { - column: 2, - row: 0, - }, + startPositionColumn: 2, + startPositionRow: 0, text: ,, type: ,, }, @@ -217,48 +177,38 @@ TreeCursorSyntaxNode { TreeCursorSyntaxNode { children: Array [], endIndex: 5, - endPosition: Object { - column: 5, - row: 0, - }, + endPositionColumn: 5, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 4, - startPosition: Object { - column: 4, - row: 0, - }, + startPositionColumn: 4, + startPositionRow: 0, text: 2, type: integer_scalar, }, ], endIndex: 5, - endPosition: Object { - column: 5, - row: 0, - }, + endPositionColumn: 5, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 4, - startPosition: Object { - column: 4, - row: 0, - }, + startPositionColumn: 4, + startPositionRow: 0, text: 2, type: plain_scalar, }, ], endIndex: 5, - endPosition: Object { - column: 5, - row: 0, - }, + endPositionColumn: 5, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -266,10 +216,8 @@ TreeCursorSyntaxNode { previousSibling: TreeCursorSyntaxNode { children: Array [], endIndex: 3, - endPosition: Object { - column: 3, - row: 0, - }, + endPositionColumn: 3, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -281,48 +229,38 @@ TreeCursorSyntaxNode { TreeCursorSyntaxNode { children: Array [], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: integer_scalar, }, ], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: plain_scalar, }, ], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -330,54 +268,42 @@ TreeCursorSyntaxNode { previousSibling: TreeCursorSyntaxNode { children: Array [], endIndex: 1, - endPosition: Object { - column: 1, - row: 0, - }, + endPositionColumn: 1, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: false, previousSibling: undefined, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [, type: [, }, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: flow_node, }, startIndex: 2, - startPosition: Object { - column: 2, - row: 0, - }, + startPositionColumn: 2, + startPositionRow: 0, text: ,, type: ,, }, startIndex: 4, - startPosition: Object { - column: 4, - row: 0, - }, + startPositionColumn: 4, + startPositionRow: 0, text: 2, type: flow_node, }, TreeCursorSyntaxNode { children: Array [], endIndex: 6, - endPosition: Object { - column: 6, - row: 0, - }, + endPositionColumn: 6, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -389,48 +315,38 @@ TreeCursorSyntaxNode { TreeCursorSyntaxNode { children: Array [], endIndex: 5, - endPosition: Object { - column: 5, - row: 0, - }, + endPositionColumn: 5, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 4, - startPosition: Object { - column: 4, - row: 0, - }, + startPositionColumn: 4, + startPositionRow: 0, text: 2, type: integer_scalar, }, ], endIndex: 5, - endPosition: Object { - column: 5, - row: 0, - }, + endPositionColumn: 5, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 4, - startPosition: Object { - column: 4, - row: 0, - }, + startPositionColumn: 4, + startPositionRow: 0, text: 2, type: plain_scalar, }, ], endIndex: 5, - endPosition: Object { - column: 5, - row: 0, - }, + endPositionColumn: 5, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -438,10 +354,8 @@ TreeCursorSyntaxNode { previousSibling: TreeCursorSyntaxNode { children: Array [], endIndex: 3, - endPosition: Object { - column: 3, - row: 0, - }, + endPositionColumn: 3, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -453,48 +367,38 @@ TreeCursorSyntaxNode { TreeCursorSyntaxNode { children: Array [], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: integer_scalar, }, ], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: plain_scalar, }, ], endIndex: 2, - endPosition: Object { - column: 2, - row: 0, - }, + endPositionColumn: 2, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, @@ -502,128 +406,100 @@ TreeCursorSyntaxNode { previousSibling: TreeCursorSyntaxNode { children: Array [], endIndex: 1, - endPosition: Object { - column: 1, - row: 0, - }, + endPositionColumn: 1, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: false, previousSibling: undefined, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [, type: [, }, startIndex: 1, - startPosition: Object { - column: 1, - row: 0, - }, + startPositionColumn: 1, + startPositionRow: 0, text: 1, type: flow_node, }, startIndex: 2, - startPosition: Object { - column: 2, - row: 0, - }, + startPositionColumn: 2, + startPositionRow: 0, text: ,, type: ,, }, startIndex: 4, - startPosition: Object { - column: 4, - row: 0, - }, + startPositionColumn: 4, + startPositionRow: 0, text: 2, type: flow_node, }, startIndex: 5, - startPosition: Object { - column: 5, - row: 0, - }, + startPositionColumn: 5, + startPositionRow: 0, text: ], type: ], }, ], endIndex: 6, - endPosition: Object { - column: 6, - row: 0, - }, + endPositionColumn: 6, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [1, 2], type: flow_sequence, }, ], endIndex: 6, - endPosition: Object { - column: 6, - row: 0, - }, + endPositionColumn: 6, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [1, 2], type: flow_node, }, ], endIndex: 6, - endPosition: Object { - column: 6, - row: 0, - }, + endPositionColumn: 6, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [1, 2], type: document, }, ], endIndex: 6, - endPosition: Object { - column: 6, - row: 0, - }, + endPositionColumn: 6, + endPositionRow: 0, fieldName: undefined, hasError: false, isMissing: false, isNamed: true, previousSibling: undefined, startIndex: 0, - startPosition: Object { - column: 0, - row: 0, - }, + startPositionColumn: 0, + startPositionRow: 0, text: [1, 2], type: stream, } diff --git a/packages/apidom-reference/test/parse/index.ts b/packages/apidom-reference/test/parse/index.ts index 527f601f64..804a2953c4 100644 --- a/packages/apidom-reference/test/parse/index.ts +++ b/packages/apidom-reference/test/parse/index.ts @@ -1,6 +1,6 @@ import { Buffer } from 'node:buffer'; import path from 'node:path'; -import { assert } from 'chai'; +import { assert, expect } from 'chai'; import { isParseResultElement, toValue } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import { fileURLToPath } from 'node:url'; @@ -40,7 +40,12 @@ describe('parse', function () { const parseResult = await parse(uri, options); const { api } = parseResult; - assert.isTrue(api?.meta.hasKey('sourceMap')); + expect(api?.startPositionRow).to.be.a('number'); + expect(api?.startPositionColumn).to.be.a('number'); + expect(api?.startIndex).to.be.a('number'); + expect(api?.endPositionRow).to.be.a('number'); + expect(api?.endPositionColumn).to.be.a('number'); + expect(api?.endIndex).to.be.a('number'); }); specify('should respect parserOpts during parsing; sourceMap = off', async function () { diff --git a/packages/apidom-reference/test/parse/parsers/api-design-systems-json/index.ts b/packages/apidom-reference/test/parse/parsers/api-design-systems-json/index.ts index 7ed9ef9d65..110ac02a8b 100644 --- a/packages/apidom-reference/test/parse/parsers/api-design-systems-json/index.ts +++ b/packages/apidom-reference/test/parse/parsers/api-design-systems-json/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-api-design-systems-json'; import { fileURLToPath } from 'node:url'; @@ -176,7 +176,7 @@ describe('parsers', function () { const parser = new APIDesignSystemsJSONParser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.result?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.result)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/api-design-systems-yaml/index.ts b/packages/apidom-reference/test/parse/parsers/api-design-systems-yaml/index.ts index b9343901d4..a50f23ef0b 100644 --- a/packages/apidom-reference/test/parse/parsers/api-design-systems-yaml/index.ts +++ b/packages/apidom-reference/test/parse/parsers/api-design-systems-yaml/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-api-design-systems-yaml'; import { fileURLToPath } from 'node:url'; @@ -197,7 +197,7 @@ describe('parsers', function () { const parser = new APIDesignSystemsYAMLParser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.result?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.result)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/arazzo-json-1/index.ts b/packages/apidom-reference/test/parse/parsers/arazzo-json-1/index.ts index eeb00b2757..646a37419f 100644 --- a/packages/apidom-reference/test/parse/parsers/arazzo-json-1/index.ts +++ b/packages/apidom-reference/test/parse/parsers/arazzo-json-1/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-arazzo-json-1'; import { fileURLToPath } from 'node:url'; @@ -174,7 +174,7 @@ describe('parsers', function () { const parser = new ArazzoJSON1Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/arazzo-yaml-1/index.ts b/packages/apidom-reference/test/parse/parsers/arazzo-yaml-1/index.ts index 3bfef24319..e7e4d8d9ff 100644 --- a/packages/apidom-reference/test/parse/parsers/arazzo-yaml-1/index.ts +++ b/packages/apidom-reference/test/parse/parsers/arazzo-yaml-1/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-arazzo-yaml-1'; import { fileURLToPath } from 'node:url'; @@ -205,7 +205,7 @@ describe('parsers', function () { const parser = new ArazzoYAML1Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/asyncapi-json-2/index.ts b/packages/apidom-reference/test/parse/parsers/asyncapi-json-2/index.ts index ac3b3219f5..a64ab15045 100644 --- a/packages/apidom-reference/test/parse/parsers/asyncapi-json-2/index.ts +++ b/packages/apidom-reference/test/parse/parsers/asyncapi-json-2/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-asyncapi-json-2'; import { fileURLToPath } from 'node:url'; @@ -174,7 +174,7 @@ describe('parsers', function () { const parser = new AsyncAPIJSON2Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/asyncapi-yaml-2/index.ts b/packages/apidom-reference/test/parse/parsers/asyncapi-yaml-2/index.ts index 7cedbec15a..90dfa67c22 100644 --- a/packages/apidom-reference/test/parse/parsers/asyncapi-yaml-2/index.ts +++ b/packages/apidom-reference/test/parse/parsers/asyncapi-yaml-2/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-2'; import { fileURLToPath } from 'node:url'; @@ -197,7 +197,7 @@ describe('parsers', function () { const parser = new AsyncAPIYAML2Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/json/index.ts b/packages/apidom-reference/test/parse/parsers/json/index.ts index e03be7924f..f82c637ceb 100644 --- a/packages/apidom-reference/test/parse/parsers/json/index.ts +++ b/packages/apidom-reference/test/parse/parsers/json/index.ts @@ -4,7 +4,7 @@ import { NumberElement, ObjectElement, isParseResultElement, - isSourceMapElement, + hasElementSourceMap, } from '@swagger-api/apidom-core'; import File from '../../../../src/File.ts'; @@ -126,7 +126,7 @@ describe('parsers', function () { const result = await parser.parse(file); const objElement: ObjectElement = result.get(0); - assert.isTrue(isSourceMapElement(objElement.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(objElement)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/openapi-json-2/index.ts b/packages/apidom-reference/test/parse/parsers/openapi-json-2/index.ts index 2a2865c17f..972a46e213 100644 --- a/packages/apidom-reference/test/parse/parsers/openapi-json-2/index.ts +++ b/packages/apidom-reference/test/parse/parsers/openapi-json-2/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-2'; import { fileURLToPath } from 'node:url'; @@ -174,7 +174,7 @@ describe('parsers', function () { const parser = new OpenAPIJSON2Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/openapi-json-3-0/index.ts b/packages/apidom-reference/test/parse/parsers/openapi-json-3-0/index.ts index 150b372169..c2234d9648 100644 --- a/packages/apidom-reference/test/parse/parsers/openapi-json-3-0/index.ts +++ b/packages/apidom-reference/test/parse/parsers/openapi-json-3-0/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-0'; import { fileURLToPath } from 'node:url'; @@ -174,7 +174,7 @@ describe('parsers', function () { const parser = new OpenAPIJSON3_0Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/openapi-json-3-1/index.ts b/packages/apidom-reference/test/parse/parsers/openapi-json-3-1/index.ts index 264ea48c5b..6930464340 100644 --- a/packages/apidom-reference/test/parse/parsers/openapi-json-3-1/index.ts +++ b/packages/apidom-reference/test/parse/parsers/openapi-json-3-1/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-json-3-1'; import { fileURLToPath } from 'node:url'; @@ -174,7 +174,7 @@ describe('parsers', function () { const parser = new OpenAPIJSON3_1Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/openapi-yaml-2/index.ts b/packages/apidom-reference/test/parse/parsers/openapi-yaml-2/index.ts index f0d62ae566..2ec35864af 100644 --- a/packages/apidom-reference/test/parse/parsers/openapi-yaml-2/index.ts +++ b/packages/apidom-reference/test/parse/parsers/openapi-yaml-2/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-yaml-2'; import { fileURLToPath } from 'node:url'; @@ -205,7 +205,7 @@ describe('parsers', function () { const parser = new OpenAPIYAML2Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/openapi-yaml-3-0/index.ts b/packages/apidom-reference/test/parse/parsers/openapi-yaml-3-0/index.ts index 98e5f533e0..51e7098377 100644 --- a/packages/apidom-reference/test/parse/parsers/openapi-yaml-3-0/index.ts +++ b/packages/apidom-reference/test/parse/parsers/openapi-yaml-3-0/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-yaml-3-0'; import { fileURLToPath } from 'node:url'; @@ -205,7 +205,7 @@ describe('parsers', function () { const parser = new OpenAPIYAML3_0Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/openapi-yaml-3-1/index.ts b/packages/apidom-reference/test/parse/parsers/openapi-yaml-3-1/index.ts index 9fe53bf672..89d9ec41e5 100644 --- a/packages/apidom-reference/test/parse/parsers/openapi-yaml-3-1/index.ts +++ b/packages/apidom-reference/test/parse/parsers/openapi-yaml-3-1/index.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { assert } from 'chai'; -import { NumberElement, isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { NumberElement, isParseResultElement, hasElementSourceMap } from '@swagger-api/apidom-core'; import { mediaTypes } from '@swagger-api/apidom-parser-adapter-openapi-yaml-3-1'; import { fileURLToPath } from 'node:url'; @@ -205,7 +205,7 @@ describe('parsers', function () { const parser = new OpenAPIYAML3_1Parser({ sourceMap: true }); const parseResult = await parser.parse(file); - assert.isTrue(isSourceMapElement(parseResult.api?.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(parseResult.api)); }); }); diff --git a/packages/apidom-reference/test/parse/parsers/yaml/index.ts b/packages/apidom-reference/test/parse/parsers/yaml/index.ts index 9be125355c..cf8d7f252e 100644 --- a/packages/apidom-reference/test/parse/parsers/yaml/index.ts +++ b/packages/apidom-reference/test/parse/parsers/yaml/index.ts @@ -4,7 +4,7 @@ import { ObjectElement, NumberElement, isParseResultElement, - isSourceMapElement, + hasElementSourceMap, } from '@swagger-api/apidom-core'; import File from '../../../../src/File.ts'; @@ -132,7 +132,7 @@ describe('parsers', function () { const result = await parser.parse(file); const objElement: ObjectElement = result.get(0); - assert.isTrue(isSourceMapElement(objElement.meta.get('sourceMap'))); + assert.isTrue(hasElementSourceMap(objElement)); }); });