@speclynx/apidom-parser-adapter-yaml-1-2 6.1.0 → 6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speclynx/apidom-parser-adapter-yaml-1-2",
3
- "version": "6.1.0",
3
+ "version": "6.1.2",
4
4
  "description": "Parser adapter for parsing YAML documents into base namespace.",
5
5
  "keywords": [
6
6
  "apidom",
@@ -58,10 +58,10 @@
58
58
  "author": "Vladimir Gorej",
59
59
  "license": "Apache-2.0",
60
60
  "dependencies": {
61
- "@babel/runtime-corejs3": "^8.0.5",
62
- "@speclynx/apidom-core": "6.1.0",
63
- "@speclynx/apidom-datamodel": "6.1.0",
64
- "@speclynx/apidom-error": "6.1.0",
61
+ "@babel/runtime-corejs3": "^8.0.8",
62
+ "@speclynx/apidom-core": "6.1.2",
63
+ "@speclynx/apidom-datamodel": "6.1.2",
64
+ "@speclynx/apidom-error": "6.1.2",
65
65
  "ramda": "~0.32.0",
66
66
  "ramda-adjunct": "^6.1.0",
67
67
  "web-tree-sitter": "=0.27.1",
@@ -80,5 +80,5 @@
80
80
  "README.md",
81
81
  "CHANGELOG.md"
82
82
  ],
83
- "gitHead": "575dbf59cb58a6c57248bf2c027a5cbc99442a63"
83
+ "gitHead": "e3ba735e1c56369bb263dd8246c711d405ed9606"
84
84
  }
@@ -430,9 +430,19 @@ const transformKeyValuePair = (node, ctx) => {
430
430
  }
431
431
 
432
432
  // Transform key and value (these are dynamically defined properties)
433
- const keyResult = transform(key, ctx);
433
+ let keyResult = transform(key, ctx);
434
434
  const valueResult = transform(value, ctx);
435
435
 
436
+ // an empty key is a null in YAML, but a JavaScript property name can't be null, so it's the empty
437
+ // string it's named by, marked as an empty key
438
+ if ((0, _apidomDatamodel.isNullElement)(keyResult) && (0, _apidomDatamodel.includesClasses)(keyResult, ['yaml-e-node'])) {
439
+ const emptyKey = new _apidomDatamodel.StringElement('', keyResult.meta, keyResult.attributes);
440
+ emptyKey.classes.push('yaml-e-key');
441
+ _apidomDatamodel.SourceMapElement.transfer(keyResult, emptyKey);
442
+ _apidomDatamodel.StyleElement.transfer(keyResult, emptyKey);
443
+ keyResult = emptyKey;
444
+ }
445
+
436
446
  // @ts-ignore
437
447
  element.content.key = keyResult;
438
448
  // @ts-ignore
@@ -459,12 +469,11 @@ const transformSequence = (node, ctx) => {
459
469
 
460
470
  // Scalar: Converts to Element via namespace
461
471
  const transformScalar = (node, ctx) => {
462
- const element = ctx.namespace.toElement(node.content);
463
-
464
- // Translate style information about empty nodes; an empty node (YAML 1.2 §7.2) is a null unless
465
- // a tag other than the null tag makes it something else (e.g. !!str makes it an empty string)
472
+ // an empty node (YAML 1.2 §7.2) is a null unless a tag other than the null tag makes it
473
+ // something else (e.g. !!str makes it an empty string); its classes tell it from an explicit null
466
474
  const tag = node.tag?.explicitName;
467
475
  const isEmptyNode = node.content === '' && node.style === _YamlStyle.YamlStyle.Plain && [undefined, '?', '!!null', '!<tag:yaml.org,2002:null>'].includes(tag);
476
+ const element = isEmptyNode ? new _apidomDatamodel.NullElement() : ctx.namespace.toElement(node.content);
468
477
  if (isEmptyNode) {
469
478
  element.classes.push('yaml-e-node');
470
479
  element.classes.push('yaml-e-scalar');
@@ -1,4 +1,4 @@
1
- import { ParseResultElement, AnnotationElement, CommentElement, MemberElement, ObjectElement, ArrayElement, isPrimitiveElement, Namespace, SourceMapElement } from '@speclynx/apidom-datamodel';
1
+ import { ParseResultElement, AnnotationElement, CommentElement, MemberElement, ObjectElement, ArrayElement, StringElement, NullElement, isPrimitiveElement, isNullElement, includesClasses, Namespace, SourceMapElement, StyleElement } from '@speclynx/apidom-datamodel';
2
2
  import { isComment, isDocument } from "./ast/nodes/predicates.mjs";
3
3
  import { YamlStyle, YamlStyleGroup } from "./ast/nodes/YamlStyle.mjs"; // Transform context passed through transformation
4
4
  // Node with type property and flat position properties
@@ -421,9 +421,19 @@ const transformKeyValuePair = (node, ctx) => {
421
421
  }
422
422
 
423
423
  // Transform key and value (these are dynamically defined properties)
424
- const keyResult = transform(key, ctx);
424
+ let keyResult = transform(key, ctx);
425
425
  const valueResult = transform(value, ctx);
426
426
 
427
+ // an empty key is a null in YAML, but a JavaScript property name can't be null, so it's the empty
428
+ // string it's named by, marked as an empty key
429
+ if (isNullElement(keyResult) && includesClasses(keyResult, ['yaml-e-node'])) {
430
+ const emptyKey = new StringElement('', keyResult.meta, keyResult.attributes);
431
+ emptyKey.classes.push('yaml-e-key');
432
+ SourceMapElement.transfer(keyResult, emptyKey);
433
+ StyleElement.transfer(keyResult, emptyKey);
434
+ keyResult = emptyKey;
435
+ }
436
+
427
437
  // @ts-ignore
428
438
  element.content.key = keyResult;
429
439
  // @ts-ignore
@@ -450,12 +460,11 @@ const transformSequence = (node, ctx) => {
450
460
 
451
461
  // Scalar: Converts to Element via namespace
452
462
  const transformScalar = (node, ctx) => {
453
- const element = ctx.namespace.toElement(node.content);
454
-
455
- // Translate style information about empty nodes; an empty node (YAML 1.2 §7.2) is a null unless
456
- // a tag other than the null tag makes it something else (e.g. !!str makes it an empty string)
463
+ // an empty node (YAML 1.2 §7.2) is a null unless a tag other than the null tag makes it
464
+ // something else (e.g. !!str makes it an empty string); its classes tell it from an explicit null
457
465
  const tag = node.tag?.explicitName;
458
466
  const isEmptyNode = node.content === '' && node.style === YamlStyle.Plain && [undefined, '?', '!!null', '!<tag:yaml.org,2002:null>'].includes(tag);
467
+ const element = isEmptyNode ? new NullElement() : ctx.namespace.toElement(node.content);
459
468
  if (isEmptyNode) {
460
469
  element.classes.push('yaml-e-node');
461
470
  element.classes.push('yaml-e-scalar');