projen 0.53.8 → 0.53.11

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.
Files changed (158) hide show
  1. package/.jsii +27 -9
  2. package/changelog.md +1 -1
  3. package/docs/api/API.md +2 -0
  4. package/lib/awscdk/auto-discover.js +4 -4
  5. package/lib/awscdk/awscdk-app-java.js +3 -3
  6. package/lib/awscdk/awscdk-app-py.js +11 -9
  7. package/lib/awscdk/awscdk-app-ts.js +4 -4
  8. package/lib/awscdk/awscdk-construct.js +2 -2
  9. package/lib/awscdk/awscdk-deps-java.js +1 -1
  10. package/lib/awscdk/awscdk-deps-js.js +1 -1
  11. package/lib/awscdk/awscdk-deps.js +1 -1
  12. package/lib/awscdk/cdk-config.js +1 -1
  13. package/lib/awscdk/cdk-tasks.js +1 -1
  14. package/lib/awscdk/integration-test.js +1 -1
  15. package/lib/awscdk/lambda-extension.js +1 -1
  16. package/lib/awscdk/lambda-function.js +2 -2
  17. package/lib/build/build-workflow.js +1 -1
  18. package/lib/cdk/auto-discover-base.js +2 -2
  19. package/lib/cdk/construct-lib.js +1 -1
  20. package/lib/cdk/integration-test-base.js +1 -1
  21. package/lib/cdk/jsii-docgen.js +1 -1
  22. package/lib/cdk/jsii-project.js +1 -1
  23. package/lib/cdk8s/auto-discover.js +2 -2
  24. package/lib/cdk8s/cdk8s-app-ts.js +1 -1
  25. package/lib/cdk8s/cdk8s-construct.js +1 -1
  26. package/lib/cdk8s/integration-test.js +1 -1
  27. package/lib/cdktf/cdktf-construct.js +1 -1
  28. package/lib/component.js +1 -1
  29. package/lib/dependencies.js +1 -1
  30. package/lib/dev-env.js +1 -1
  31. package/lib/docker-compose.js +2 -2
  32. package/lib/file.js +1 -1
  33. package/lib/gitattributes.js +1 -1
  34. package/lib/github/auto-approve.js +1 -1
  35. package/lib/github/auto-merge.js +1 -1
  36. package/lib/github/dependabot.js +1 -1
  37. package/lib/github/github-project.js +1 -1
  38. package/lib/github/github.js +1 -1
  39. package/lib/github/mergify.js +1 -1
  40. package/lib/github/pr-template.js +1 -1
  41. package/lib/github/pull-request-lint.js +1 -1
  42. package/lib/github/stale.js +1 -1
  43. package/lib/github/task-workflow.js +1 -1
  44. package/lib/github/workflows.js +1 -1
  45. package/lib/gitlab/configuration.js +1 -1
  46. package/lib/gitlab/gitlab-configuration.js +1 -1
  47. package/lib/gitlab/nested-configuration.js +1 -1
  48. package/lib/gitpod.js +1 -1
  49. package/lib/ignore-file.js +1 -1
  50. package/lib/ini.js +1 -1
  51. package/lib/java/java-project.js +1 -1
  52. package/lib/java/junit.js +1 -1
  53. package/lib/java/maven-compile.js +1 -1
  54. package/lib/java/maven-packaging.js +1 -1
  55. package/lib/java/maven-sample.js +1 -1
  56. package/lib/java/pom.js +1 -1
  57. package/lib/java/projenrc.js +1 -1
  58. package/lib/javascript/bundler.js +1 -1
  59. package/lib/javascript/eslint.js +1 -1
  60. package/lib/javascript/jest.js +1 -1
  61. package/lib/javascript/node-package.js +1 -1
  62. package/lib/javascript/node-project.js +1 -1
  63. package/lib/javascript/npm-config.js +1 -1
  64. package/lib/javascript/prettier.js +1 -1
  65. package/lib/javascript/projenrc.js +1 -1
  66. package/lib/javascript/typescript-config.js +1 -1
  67. package/lib/javascript/upgrade-dependencies.js +2 -2
  68. package/lib/json.js +1 -1
  69. package/lib/license.js +1 -1
  70. package/lib/logger.js +1 -1
  71. package/lib/makefile.js +1 -1
  72. package/lib/object-file.js +1 -1
  73. package/lib/project-build.js +1 -1
  74. package/lib/project.js +1 -1
  75. package/lib/projects.js +1 -1
  76. package/lib/projenrc-json.js +1 -1
  77. package/lib/python/pip.js +1 -1
  78. package/lib/python/poetry.js +2 -2
  79. package/lib/python/projenrc.js +1 -1
  80. package/lib/python/pytest-sample.js +1 -1
  81. package/lib/python/pytest.js +1 -1
  82. package/lib/python/python-project.js +1 -1
  83. package/lib/python/python-sample.js +1 -1
  84. package/lib/python/requirements-file.js +1 -1
  85. package/lib/python/setuppy.js +1 -1
  86. package/lib/python/setuptools.js +1 -1
  87. package/lib/python/venv.js +1 -1
  88. package/lib/readme.js +1 -1
  89. package/lib/release/publisher.js +1 -1
  90. package/lib/release/release-trigger.js +1 -1
  91. package/lib/release/release.js +1 -1
  92. package/lib/sample-file.js +2 -2
  93. package/lib/semver.js +1 -1
  94. package/lib/source-code.d.ts +6 -0
  95. package/lib/source-code.js +6 -4
  96. package/lib/task-runtime.js +1 -1
  97. package/lib/task.js +1 -1
  98. package/lib/tasks.js +1 -1
  99. package/lib/testing.js +1 -1
  100. package/lib/textfile.js +1 -1
  101. package/lib/toml.js +1 -1
  102. package/lib/typescript/projenrc.js +1 -1
  103. package/lib/typescript/typescript-typedoc.js +1 -1
  104. package/lib/typescript/typescript.js +3 -3
  105. package/lib/version.js +1 -1
  106. package/lib/vscode/devcontainer.js +1 -1
  107. package/lib/vscode/launch-config.js +1 -1
  108. package/lib/vscode/vscode.js +1 -1
  109. package/lib/web/next.js +3 -3
  110. package/lib/web/postcss.js +1 -1
  111. package/lib/web/react.js +4 -4
  112. package/lib/web/tailwind.js +1 -1
  113. package/lib/xmlfile.js +1 -1
  114. package/lib/yaml.js +1 -1
  115. package/node_modules/xmlbuilder2/node_modules/@types/node/README.md +1 -1
  116. package/node_modules/xmlbuilder2/node_modules/@types/node/fs.d.ts +48 -14
  117. package/node_modules/xmlbuilder2/node_modules/@types/node/package.json +2 -2
  118. package/node_modules/yaml/browser/dist/compose/compose-doc.js +1 -1
  119. package/node_modules/yaml/browser/dist/compose/compose-node.js +13 -4
  120. package/node_modules/yaml/browser/dist/compose/composer.js +5 -7
  121. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +9 -2
  122. package/node_modules/yaml/browser/dist/compose/resolve-props.js +2 -0
  123. package/node_modules/yaml/browser/dist/doc/Document.js +9 -2
  124. package/node_modules/yaml/browser/dist/doc/directives.js +7 -4
  125. package/node_modules/yaml/browser/dist/index.js +1 -2
  126. package/node_modules/yaml/browser/dist/parse/lexer.js +16 -7
  127. package/node_modules/yaml/browser/dist/parse/parser.js +64 -30
  128. package/node_modules/yaml/browser/dist/schema/common/null.js +3 -1
  129. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +26 -8
  130. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +1 -1
  131. package/node_modules/yaml/browser/dist/visit.js +150 -62
  132. package/node_modules/yaml/dist/compose/compose-doc.js +1 -1
  133. package/node_modules/yaml/dist/compose/compose-node.js +13 -4
  134. package/node_modules/yaml/dist/compose/composer.d.ts +1 -1
  135. package/node_modules/yaml/dist/compose/composer.js +7 -9
  136. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +9 -2
  137. package/node_modules/yaml/dist/compose/resolve-props.js +2 -0
  138. package/node_modules/yaml/dist/doc/Document.d.ts +1 -1
  139. package/node_modules/yaml/dist/doc/Document.js +16 -9
  140. package/node_modules/yaml/dist/doc/directives.d.ts +3 -1
  141. package/node_modules/yaml/dist/doc/directives.js +7 -4
  142. package/node_modules/yaml/dist/index.d.ts +2 -2
  143. package/node_modules/yaml/dist/index.js +1 -2
  144. package/node_modules/yaml/dist/options.d.ts +0 -8
  145. package/node_modules/yaml/dist/parse/lexer.js +16 -7
  146. package/node_modules/yaml/dist/parse/parser.js +64 -30
  147. package/node_modules/yaml/dist/schema/common/null.js +3 -1
  148. package/node_modules/yaml/dist/stringify/stringifyDocument.js +26 -8
  149. package/node_modules/yaml/dist/stringify/stringifyPair.js +1 -1
  150. package/node_modules/yaml/dist/test-events.js +8 -9
  151. package/node_modules/yaml/dist/visit.d.ts +49 -10
  152. package/node_modules/yaml/dist/visit.js +149 -60
  153. package/node_modules/yaml/package.json +3 -3
  154. package/package.json +3 -3
  155. package/releasetag.txt +1 -1
  156. package/version.txt +1 -1
  157. package/node_modules/yaml/browser/dist/options.js +0 -18
  158. package/node_modules/yaml/dist/options.js +0 -20
@@ -541,36 +541,70 @@ class Parser {
541
541
  this.onKeyLine = true;
542
542
  return;
543
543
  case 'map-value-ind':
544
- if (!it.sep)
545
- Object.assign(it, { key: null, sep: [this.sourceToken] });
546
- else if (it.value ||
547
- (atNextItem && !includesToken(it.start, 'explicit-key-ind')))
548
- map.items.push({ start: [], key: null, sep: [this.sourceToken] });
549
- else if (includesToken(it.sep, 'map-value-ind'))
550
- this.stack.push({
551
- type: 'block-map',
552
- offset: this.offset,
553
- indent: this.indent,
554
- items: [{ start: [], key: null, sep: [this.sourceToken] }]
555
- });
556
- else if (includesToken(it.start, 'explicit-key-ind') &&
557
- isFlowToken(it.key) &&
558
- !includesToken(it.sep, 'newline')) {
559
- const start = getFirstKeyStartProps(it.start);
560
- const key = it.key;
561
- const sep = it.sep;
562
- sep.push(this.sourceToken);
563
- // @ts-ignore type guard is wrong here
564
- delete it.key, delete it.sep;
565
- this.stack.push({
566
- type: 'block-map',
567
- offset: this.offset,
568
- indent: this.indent,
569
- items: [{ start, key, sep }]
570
- });
544
+ if (includesToken(it.start, 'explicit-key-ind')) {
545
+ if (!it.sep) {
546
+ if (includesToken(it.start, 'newline')) {
547
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
548
+ }
549
+ else {
550
+ const start = getFirstKeyStartProps(it.start);
551
+ this.stack.push({
552
+ type: 'block-map',
553
+ offset: this.offset,
554
+ indent: this.indent,
555
+ items: [{ start, key: null, sep: [this.sourceToken] }]
556
+ });
557
+ }
558
+ }
559
+ else if (it.value) {
560
+ map.items.push({ start: [], key: null, sep: [this.sourceToken] });
561
+ }
562
+ else if (includesToken(it.sep, 'map-value-ind')) {
563
+ this.stack.push({
564
+ type: 'block-map',
565
+ offset: this.offset,
566
+ indent: this.indent,
567
+ items: [{ start: [], key: null, sep: [this.sourceToken] }]
568
+ });
569
+ }
570
+ else if (isFlowToken(it.key) &&
571
+ !includesToken(it.sep, 'newline')) {
572
+ const start = getFirstKeyStartProps(it.start);
573
+ const key = it.key;
574
+ const sep = it.sep;
575
+ sep.push(this.sourceToken);
576
+ // @ts-expect-error type guard is wrong here
577
+ delete it.key, delete it.sep;
578
+ this.stack.push({
579
+ type: 'block-map',
580
+ offset: this.offset,
581
+ indent: this.indent,
582
+ items: [{ start, key, sep }]
583
+ });
584
+ }
585
+ else {
586
+ it.sep.push(this.sourceToken);
587
+ }
588
+ }
589
+ else {
590
+ if (!it.sep) {
591
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
592
+ }
593
+ else if (it.value || atNextItem) {
594
+ map.items.push({ start: [], key: null, sep: [this.sourceToken] });
595
+ }
596
+ else if (includesToken(it.sep, 'map-value-ind')) {
597
+ this.stack.push({
598
+ type: 'block-map',
599
+ offset: this.offset,
600
+ indent: this.indent,
601
+ items: [{ start: [], key: null, sep: [this.sourceToken] }]
602
+ });
603
+ }
604
+ else {
605
+ it.sep.push(this.sourceToken);
606
+ }
571
607
  }
572
- else
573
- it.sep.push(this.sourceToken);
574
608
  this.onKeyLine = true;
575
609
  return;
576
610
  case 'alias':
@@ -734,7 +768,7 @@ class Parser {
734
768
  else {
735
769
  const parent = this.peek(2);
736
770
  if (parent.type === 'block-map' &&
737
- (this.type === 'map-value-ind' ||
771
+ ((this.type === 'map-value-ind' && parent.indent === fc.indent) ||
738
772
  (this.type === 'newline' &&
739
773
  !parent.items[parent.items.length - 1].sep))) {
740
774
  yield* this.pop();
@@ -7,7 +7,9 @@ const nullTag = {
7
7
  tag: 'tag:yaml.org,2002:null',
8
8
  test: /^(?:~|[Nn]ull|NULL)?$/,
9
9
  resolve: () => new Scalar(null),
10
- stringify: ({ source }, ctx) => source && nullTag.test.test(source) ? source : ctx.options.nullStr
10
+ stringify: ({ source }, ctx) => typeof source === 'string' && nullTag.test.test(source)
11
+ ? source
12
+ : ctx.options.nullStr
11
13
  };
12
14
 
13
15
  export { nullTag };
@@ -3,6 +3,7 @@ import { createStringifyContext, stringify } from './stringify.js';
3
3
  import { indentComment, lineComment } from './stringifyComment.js';
4
4
 
5
5
  function stringifyDocument(doc, options) {
6
+ var _a;
6
7
  const lines = [];
7
8
  let hasDirectives = options.directives === true;
8
9
  if (options.directives !== false && doc.directives) {
@@ -11,7 +12,7 @@ function stringifyDocument(doc, options) {
11
12
  lines.push(dir);
12
13
  hasDirectives = true;
13
14
  }
14
- else if (doc.directives.marker)
15
+ else if (doc.directives.docStart)
15
16
  hasDirectives = true;
16
17
  }
17
18
  if (hasDirectives)
@@ -54,13 +55,30 @@ function stringifyDocument(doc, options) {
54
55
  else {
55
56
  lines.push(stringify(doc.contents, ctx));
56
57
  }
57
- let dc = doc.comment;
58
- if (dc && chompKeep)
59
- dc = dc.replace(/^\n+/, '');
60
- if (dc) {
61
- if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '')
62
- lines.push('');
63
- lines.push(indentComment(commentString(dc), ''));
58
+ if ((_a = doc.directives) === null || _a === void 0 ? void 0 : _a.docEnd) {
59
+ if (doc.comment) {
60
+ const cs = commentString(doc.comment);
61
+ if (cs.includes('\n')) {
62
+ lines.push('...');
63
+ lines.push(indentComment(cs, ''));
64
+ }
65
+ else {
66
+ lines.push(`... ${cs}`);
67
+ }
68
+ }
69
+ else {
70
+ lines.push('...');
71
+ }
72
+ }
73
+ else {
74
+ let dc = doc.comment;
75
+ if (dc && chompKeep)
76
+ dc = dc.replace(/^\n+/, '');
77
+ if (dc) {
78
+ if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '')
79
+ lines.push('');
80
+ lines.push(indentComment(commentString(dc), ''));
81
+ }
64
82
  }
65
83
  return lines.join('\n') + '\n';
66
84
  }
@@ -39,7 +39,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
39
39
  if (allNullValues || value == null) {
40
40
  if (keyCommentDone && onComment)
41
41
  onComment();
42
- return explicitKey ? `? ${str}` : str;
42
+ return str === '' ? '?' : explicitKey ? `? ${str}` : str;
43
43
  }
44
44
  }
45
45
  else if ((allNullValues && !simpleKeys) || (value == null && explicitKey)) {
@@ -1,4 +1,4 @@
1
- import { isDocument, isMap, isSeq, isPair, isScalar, isAlias, isNode, isCollection } from './nodes/Node.js';
1
+ import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/Node.js';
2
2
 
3
3
  const BREAK = Symbol('break visit');
4
4
  const SKIP = Symbol('skip children');
@@ -34,29 +34,14 @@ const REMOVE = Symbol('remove node');
34
34
  * specific defined one will be used for each node.
35
35
  */
36
36
  function visit(node, visitor) {
37
- if (typeof visitor === 'object' &&
38
- (visitor.Collection || visitor.Node || visitor.Value)) {
39
- visitor = Object.assign({
40
- Alias: visitor.Node,
41
- Map: visitor.Node,
42
- Scalar: visitor.Node,
43
- Seq: visitor.Node
44
- }, visitor.Value && {
45
- Map: visitor.Value,
46
- Scalar: visitor.Value,
47
- Seq: visitor.Value
48
- }, visitor.Collection && {
49
- Map: visitor.Collection,
50
- Seq: visitor.Collection
51
- }, visitor);
52
- }
37
+ const visitor_ = initVisitor(visitor);
53
38
  if (isDocument(node)) {
54
- const cd = _visit(null, node.contents, visitor, Object.freeze([node]));
39
+ const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
55
40
  if (cd === REMOVE)
56
41
  node.contents = null;
57
42
  }
58
43
  else
59
- _visit(null, node, visitor, Object.freeze([]));
44
+ visit_(null, node, visitor_, Object.freeze([]));
60
45
  }
61
46
  // Without the `as symbol` casts, TS declares these in the `visit`
62
47
  // namespace using `var`, but then complains about that because
@@ -67,55 +52,104 @@ visit.BREAK = BREAK;
67
52
  visit.SKIP = SKIP;
68
53
  /** Remove the current node */
69
54
  visit.REMOVE = REMOVE;
70
- function _visit(key, node, visitor, path) {
71
- let ctrl = undefined;
72
- if (typeof visitor === 'function')
73
- ctrl = visitor(key, node, path);
74
- else if (isMap(node)) {
75
- if (visitor.Map)
76
- ctrl = visitor.Map(key, node, path);
77
- }
78
- else if (isSeq(node)) {
79
- if (visitor.Seq)
80
- ctrl = visitor.Seq(key, node, path);
81
- }
82
- else if (isPair(node)) {
83
- if (visitor.Pair)
84
- ctrl = visitor.Pair(key, node, path);
55
+ function visit_(key, node, visitor, path) {
56
+ const ctrl = callVisitor(key, node, visitor, path);
57
+ if (isNode(ctrl) || isPair(ctrl)) {
58
+ replaceNode(key, path, ctrl);
59
+ return visit_(key, ctrl, visitor, path);
85
60
  }
86
- else if (isScalar(node)) {
87
- if (visitor.Scalar)
88
- ctrl = visitor.Scalar(key, node, path);
61
+ if (typeof ctrl !== 'symbol') {
62
+ if (isCollection(node)) {
63
+ path = Object.freeze(path.concat(node));
64
+ for (let i = 0; i < node.items.length; ++i) {
65
+ const ci = visit_(i, node.items[i], visitor, path);
66
+ if (typeof ci === 'number')
67
+ i = ci - 1;
68
+ else if (ci === BREAK)
69
+ return BREAK;
70
+ else if (ci === REMOVE) {
71
+ node.items.splice(i, 1);
72
+ i -= 1;
73
+ }
74
+ }
75
+ }
76
+ else if (isPair(node)) {
77
+ path = Object.freeze(path.concat(node));
78
+ const ck = visit_('key', node.key, visitor, path);
79
+ if (ck === BREAK)
80
+ return BREAK;
81
+ else if (ck === REMOVE)
82
+ node.key = null;
83
+ const cv = visit_('value', node.value, visitor, path);
84
+ if (cv === BREAK)
85
+ return BREAK;
86
+ else if (cv === REMOVE)
87
+ node.value = null;
88
+ }
89
89
  }
90
- else if (isAlias(node)) {
91
- if (visitor.Alias)
92
- ctrl = visitor.Alias(key, node, path);
90
+ return ctrl;
91
+ }
92
+ /**
93
+ * Apply an async visitor to an AST node or document.
94
+ *
95
+ * Walks through the tree (depth-first) starting from `node`, calling a
96
+ * `visitor` function with three arguments:
97
+ * - `key`: For sequence values and map `Pair`, the node's index in the
98
+ * collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
99
+ * `null` for the root node.
100
+ * - `node`: The current node.
101
+ * - `path`: The ancestry of the current node.
102
+ *
103
+ * The return value of the visitor may be used to control the traversal:
104
+ * - `Promise`: Must resolve to one of the following values
105
+ * - `undefined` (default): Do nothing and continue
106
+ * - `visit.SKIP`: Do not visit the children of this node, continue with next
107
+ * sibling
108
+ * - `visit.BREAK`: Terminate traversal completely
109
+ * - `visit.REMOVE`: Remove the current node, then continue with the next one
110
+ * - `Node`: Replace the current node, then continue by visiting it
111
+ * - `number`: While iterating the items of a sequence or map, set the index
112
+ * of the next step. This is useful especially if the index of the current
113
+ * node has changed.
114
+ *
115
+ * If `visitor` is a single function, it will be called with all values
116
+ * encountered in the tree, including e.g. `null` values. Alternatively,
117
+ * separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
118
+ * `Alias` and `Scalar` node. To define the same visitor function for more than
119
+ * one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
120
+ * and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
121
+ * specific defined one will be used for each node.
122
+ */
123
+ async function visitAsync(node, visitor) {
124
+ const visitor_ = initVisitor(visitor);
125
+ if (isDocument(node)) {
126
+ const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
127
+ if (cd === REMOVE)
128
+ node.contents = null;
93
129
  }
130
+ else
131
+ await visitAsync_(null, node, visitor_, Object.freeze([]));
132
+ }
133
+ // Without the `as symbol` casts, TS declares these in the `visit`
134
+ // namespace using `var`, but then complains about that because
135
+ // `unique symbol` must be `const`.
136
+ /** Terminate visit traversal completely */
137
+ visitAsync.BREAK = BREAK;
138
+ /** Do not visit the children of the current node */
139
+ visitAsync.SKIP = SKIP;
140
+ /** Remove the current node */
141
+ visitAsync.REMOVE = REMOVE;
142
+ async function visitAsync_(key, node, visitor, path) {
143
+ const ctrl = await callVisitor(key, node, visitor, path);
94
144
  if (isNode(ctrl) || isPair(ctrl)) {
95
- const parent = path[path.length - 1];
96
- if (isCollection(parent)) {
97
- parent.items[key] = ctrl;
98
- }
99
- else if (isPair(parent)) {
100
- if (key === 'key')
101
- parent.key = ctrl;
102
- else
103
- parent.value = ctrl;
104
- }
105
- else if (isDocument(parent)) {
106
- parent.contents = ctrl;
107
- }
108
- else {
109
- const pt = isAlias(parent) ? 'alias' : 'scalar';
110
- throw new Error(`Cannot replace node with ${pt} parent`);
111
- }
112
- return _visit(key, ctrl, visitor, path);
145
+ replaceNode(key, path, ctrl);
146
+ return visitAsync_(key, ctrl, visitor, path);
113
147
  }
114
148
  if (typeof ctrl !== 'symbol') {
115
149
  if (isCollection(node)) {
116
150
  path = Object.freeze(path.concat(node));
117
151
  for (let i = 0; i < node.items.length; ++i) {
118
- const ci = _visit(i, node.items[i], visitor, path);
152
+ const ci = await visitAsync_(i, node.items[i], visitor, path);
119
153
  if (typeof ci === 'number')
120
154
  i = ci - 1;
121
155
  else if (ci === BREAK)
@@ -128,12 +162,12 @@ function _visit(key, node, visitor, path) {
128
162
  }
129
163
  else if (isPair(node)) {
130
164
  path = Object.freeze(path.concat(node));
131
- const ck = _visit('key', node.key, visitor, path);
165
+ const ck = await visitAsync_('key', node.key, visitor, path);
132
166
  if (ck === BREAK)
133
167
  return BREAK;
134
168
  else if (ck === REMOVE)
135
169
  node.key = null;
136
- const cv = _visit('value', node.value, visitor, path);
170
+ const cv = await visitAsync_('value', node.value, visitor, path);
137
171
  if (cv === BREAK)
138
172
  return BREAK;
139
173
  else if (cv === REMOVE)
@@ -142,5 +176,59 @@ function _visit(key, node, visitor, path) {
142
176
  }
143
177
  return ctrl;
144
178
  }
179
+ function initVisitor(visitor) {
180
+ if (typeof visitor === 'object' &&
181
+ (visitor.Collection || visitor.Node || visitor.Value)) {
182
+ return Object.assign({
183
+ Alias: visitor.Node,
184
+ Map: visitor.Node,
185
+ Scalar: visitor.Node,
186
+ Seq: visitor.Node
187
+ }, visitor.Value && {
188
+ Map: visitor.Value,
189
+ Scalar: visitor.Value,
190
+ Seq: visitor.Value
191
+ }, visitor.Collection && {
192
+ Map: visitor.Collection,
193
+ Seq: visitor.Collection
194
+ }, visitor);
195
+ }
196
+ return visitor;
197
+ }
198
+ function callVisitor(key, node, visitor, path) {
199
+ var _a, _b, _c, _d, _e;
200
+ if (typeof visitor === 'function')
201
+ return visitor(key, node, path);
202
+ if (isMap(node))
203
+ return (_a = visitor.Map) === null || _a === void 0 ? void 0 : _a.call(visitor, key, node, path);
204
+ if (isSeq(node))
205
+ return (_b = visitor.Seq) === null || _b === void 0 ? void 0 : _b.call(visitor, key, node, path);
206
+ if (isPair(node))
207
+ return (_c = visitor.Pair) === null || _c === void 0 ? void 0 : _c.call(visitor, key, node, path);
208
+ if (isScalar(node))
209
+ return (_d = visitor.Scalar) === null || _d === void 0 ? void 0 : _d.call(visitor, key, node, path);
210
+ if (isAlias(node))
211
+ return (_e = visitor.Alias) === null || _e === void 0 ? void 0 : _e.call(visitor, key, node, path);
212
+ return undefined;
213
+ }
214
+ function replaceNode(key, path, node) {
215
+ const parent = path[path.length - 1];
216
+ if (isCollection(parent)) {
217
+ parent.items[key] = node;
218
+ }
219
+ else if (isPair(parent)) {
220
+ if (key === 'key')
221
+ parent.key = node;
222
+ else
223
+ parent.value = node;
224
+ }
225
+ else if (isDocument(parent)) {
226
+ parent.contents = node;
227
+ }
228
+ else {
229
+ const pt = isAlias(parent) ? 'alias' : 'scalar';
230
+ throw new Error(`Cannot replace node with ${pt} parent`);
231
+ }
232
+ }
145
233
 
146
- export { visit };
234
+ export { visit, visitAsync };
@@ -22,7 +22,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
22
22
  startOnNewline: true
23
23
  });
24
24
  if (props.found) {
25
- doc.directives.marker = true;
25
+ doc.directives.docStart = true;
26
26
  if (value &&
27
27
  (value.type === 'block-map' || value.type === 'block-seq') &&
28
28
  !props.hasNewline)
@@ -10,6 +10,7 @@ const CN = { composeNode, composeEmptyNode };
10
10
  function composeNode(ctx, token, props, onError) {
11
11
  const { spaceBefore, comment, anchor, tag } = props;
12
12
  let node;
13
+ let isSrcToken = true;
13
14
  switch (token.type) {
14
15
  case 'alias':
15
16
  node = composeAlias(ctx, token, onError);
@@ -31,9 +32,14 @@ function composeNode(ctx, token, props, onError) {
31
32
  if (anchor)
32
33
  node.anchor = anchor.source.substring(1);
33
34
  break;
34
- default:
35
- console.log(token);
36
- throw new Error(`Unsupporten token type: ${token.type}`);
35
+ default: {
36
+ const message = token.type === 'error'
37
+ ? token.message
38
+ : `Unsupported token (type: ${token.type})`;
39
+ onError(token, 'UNEXPECTED_TOKEN', message);
40
+ node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError);
41
+ isSrcToken = false;
42
+ }
37
43
  }
38
44
  if (anchor && node.anchor === '')
39
45
  onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
@@ -45,7 +51,8 @@ function composeNode(ctx, token, props, onError) {
45
51
  else
46
52
  node.commentBefore = comment;
47
53
  }
48
- if (ctx.options.keepSourceTokens)
54
+ // @ts-expect-error Type checking misses meaning of isSrcToken
55
+ if (ctx.options.keepSourceTokens && isSrcToken)
49
56
  node.srcToken = token;
50
57
  return node;
51
58
  }
@@ -72,6 +79,8 @@ function composeAlias({ options }, { offset, source, end }, onError) {
72
79
  const alias = new Alias.Alias(source.substring(1));
73
80
  if (alias.source === '')
74
81
  onError(offset, 'BAD_ALIAS', 'Alias cannot be an empty string');
82
+ if (alias.source.endsWith(':'))
83
+ onError(offset + source.length - 1, 'BAD_ALIAS', 'Alias ending in : is ambiguous', true);
75
84
  const valueEnd = offset + source.length;
76
85
  const re = resolveEnd.resolveEnd(end, valueEnd, options.strict, onError);
77
86
  alias.range = [offset, valueEnd, re.offset];
@@ -2,7 +2,7 @@ import { Directives } from '../doc/directives.js';
2
2
  import { Document } from '../doc/Document.js';
3
3
  import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js';
4
4
  import { Range } from '../nodes/Node.js';
5
- import { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
5
+ import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
6
6
  import type { Token } from '../parse/cst.js';
7
7
  declare type ErrorSource = number | [number, number] | Range | {
8
8
  offset: number;
@@ -4,7 +4,6 @@ var directives = require('../doc/directives.js');
4
4
  var Document = require('../doc/Document.js');
5
5
  var errors = require('../errors.js');
6
6
  var Node = require('../nodes/Node.js');
7
- var options = require('../options.js');
8
7
  var composeDoc = require('./compose-doc.js');
9
8
  var resolveEnd = require('./resolve-end.js');
10
9
 
@@ -57,7 +56,7 @@ function parsePrelude(prelude) {
57
56
  * ```
58
57
  */
59
58
  class Composer {
60
- constructor(options$1 = {}) {
59
+ constructor(options = {}) {
61
60
  this.doc = null;
62
61
  this.atDirectives = false;
63
62
  this.prelude = [];
@@ -70,10 +69,8 @@ class Composer {
70
69
  else
71
70
  this.errors.push(new errors.YAMLParseError(pos, code, message));
72
71
  };
73
- this.directives = new directives.Directives({
74
- version: options$1.version || options.defaultOptions.version
75
- });
76
- this.options = options$1;
72
+ this.directives = new directives.Directives({ version: options.version || '1.2' });
73
+ this.options = options;
77
74
  }
78
75
  decorate(doc, afterDoc) {
79
76
  const { comment, afterEmptyLine } = parsePrelude(this.prelude);
@@ -83,7 +80,7 @@ class Composer {
83
80
  if (afterDoc) {
84
81
  doc.comment = doc.comment ? `${doc.comment}\n${comment}` : comment;
85
82
  }
86
- else if (afterEmptyLine || doc.directives.marker || !dc) {
83
+ else if (afterEmptyLine || doc.directives.docStart || !dc) {
87
84
  doc.commentBefore = comment;
88
85
  }
89
86
  else if (Node.isCollection(dc) && !dc.flow && dc.items.length > 0) {
@@ -150,8 +147,8 @@ class Composer {
150
147
  break;
151
148
  case 'document': {
152
149
  const doc = composeDoc.composeDoc(this.options, this.directives, token, this.onError);
153
- if (this.atDirectives && !doc.directives.marker)
154
- this.onError(token, 'MISSING_CHAR', 'Missing directives-end indicator line');
150
+ if (this.atDirectives && !doc.directives.docStart)
151
+ this.onError(token, 'MISSING_CHAR', 'Missing directives-end/doc-start indicator line');
155
152
  this.decorate(doc, false);
156
153
  if (this.doc)
157
154
  yield this.doc;
@@ -183,6 +180,7 @@ class Composer {
183
180
  this.errors.push(new errors.YAMLParseError(getErrorPos(token), 'UNEXPECTED_TOKEN', msg));
184
181
  break;
185
182
  }
183
+ this.doc.directives.docEnd = true;
186
184
  const end = resolveEnd.resolveEnd(token.end, token.offset + token.source.length, this.doc.options.strict, this.onError);
187
185
  this.decorate(this.doc, true);
188
186
  if (end.comment) {
@@ -19,8 +19,10 @@ function resolveBlockScalar(scalar, strict, onError) {
19
19
  break;
20
20
  }
21
21
  // shortcut for empty contents
22
- if (!scalar.source || chompStart === 0) {
23
- const value = header.chomp === '+' ? '\n'.repeat(Math.max(0, lines.length - 1)) : '';
22
+ if (chompStart === 0) {
23
+ const value = header.chomp === '+' && lines.length > 0
24
+ ? '\n'.repeat(Math.max(1, lines.length - 1))
25
+ : '';
24
26
  let end = start + header.length;
25
27
  if (scalar.source)
26
28
  end += scalar.source.length;
@@ -48,6 +50,11 @@ function resolveBlockScalar(scalar, strict, onError) {
48
50
  }
49
51
  offset += indent.length + content.length + 1;
50
52
  }
53
+ // include trailing more-indented empty lines in content
54
+ for (let i = lines.length - 1; i >= chompStart; --i) {
55
+ if (lines[i][0].length > trimIndent)
56
+ chompStart = i + 1;
57
+ }
51
58
  let value = '';
52
59
  let sep = '';
53
60
  let prevMoreIndented = false;
@@ -61,6 +61,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
61
61
  case 'anchor':
62
62
  if (anchor)
63
63
  onError(token, 'MULTIPLE_ANCHORS', 'A node can have at most one anchor');
64
+ if (token.source.endsWith(':'))
65
+ onError(token.offset + token.source.length - 1, 'BAD_ALIAS', 'Anchor ending in : is ambiguous', true);
64
66
  anchor = token;
65
67
  if (start === null)
66
68
  start = token.offset;
@@ -5,7 +5,7 @@ import { Pair } from '../nodes/Pair.js';
5
5
  import type { Scalar } from '../nodes/Scalar.js';
6
6
  import type { YAMLMap } from '../nodes/YAMLMap.js';
7
7
  import type { YAMLSeq } from '../nodes/YAMLSeq.js';
8
- import { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
8
+ import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
9
9
  import { Schema } from '../schema/Schema.js';
10
10
  import { Directives } from './directives.js';
11
11
  export declare type Replacer = any[] | ((key: any, value: any) => unknown);