@diffci.com/diffci 0.3.28 → 0.3.30

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 (96) hide show
  1. package/dist-client/src/client/cli.js +53 -5
  2. package/dist-client/src/client/command-batches.d.ts +17 -0
  3. package/dist-client/src/client/command-batches.js +73 -9
  4. package/dist-client/src/client/failure-baseline.js +0 -0
  5. package/dist-client/src/client/outcome-log.d.ts +40 -0
  6. package/dist-client/src/client/outcome-log.js +38 -1
  7. package/dist-client/src/client/selected-coverage.d.ts +3 -0
  8. package/dist-client/src/client/selected-coverage.js +35 -5
  9. package/dist-client/src/client/test-ranking.d.ts +39 -0
  10. package/dist-client/src/client/test-ranking.js +127 -0
  11. package/dist-client/src/client/test-results.d.ts +27 -0
  12. package/dist-client/src/client/test-results.js +54 -0
  13. package/dist-client/src/client/test-shards.d.ts +36 -0
  14. package/dist-client/src/client/test-shards.js +68 -0
  15. package/dist-client/src/client/verify-savings.d.ts +6 -0
  16. package/dist-client/src/client/verify-savings.js +4 -0
  17. package/dist-client/src/client/verify.d.ts +32 -1
  18. package/dist-client/src/client/verify.js +141 -13
  19. package/node_modules/@babel/helper-string-parser/lib/index.js +5 -5
  20. package/node_modules/@babel/helper-string-parser/lib/index.js.map +1 -1
  21. package/node_modules/@babel/helper-string-parser/package.json +1 -1
  22. package/node_modules/@babel/parser/lib/index.js +6306 -6143
  23. package/node_modules/@babel/parser/lib/index.js.map +1 -1
  24. package/node_modules/@babel/parser/package.json +3 -3
  25. package/node_modules/@babel/types/lib/definitions/typescript.js +2 -1
  26. package/node_modules/@babel/types/lib/definitions/typescript.js.map +1 -1
  27. package/node_modules/@babel/types/package.json +3 -3
  28. package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
  29. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +2 -1
  30. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
  31. package/node_modules/@diffci.com/core/dist/repo/file-references.js +39 -2
  32. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
  33. package/node_modules/@diffci.com/core/dist/repo/graph.js +22 -4
  34. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  35. package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +1 -1
  36. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +13 -0
  37. package/node_modules/@diffci.com/core/dist/repo/impact.js +104 -9
  38. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  39. package/node_modules/@diffci.com/core/dist/repo/repo-config.d.ts +11 -0
  40. package/node_modules/@diffci.com/core/dist/repo/repo-config.js +11 -1
  41. package/node_modules/@diffci.com/core/dist/repo/repo-config.js.map +1 -1
  42. package/node_modules/@diffci.com/core/dist/repo/route-visits.d.ts +34 -0
  43. package/node_modules/@diffci.com/core/dist/repo/route-visits.js +93 -0
  44. package/node_modules/@diffci.com/core/dist/repo/route-visits.js.map +1 -0
  45. package/node_modules/@diffci.com/core/package.json +3 -3
  46. package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +2 -1
  47. package/node_modules/@diffci.com/core/src/repo/file-references.ts +32 -2
  48. package/node_modules/@diffci.com/core/src/repo/graph.ts +20 -3
  49. package/node_modules/@diffci.com/core/src/repo/impact-types.ts +2 -0
  50. package/node_modules/@diffci.com/core/src/repo/impact.ts +95 -9
  51. package/node_modules/@diffci.com/core/src/repo/repo-config.ts +23 -1
  52. package/node_modules/@diffci.com/core/src/repo/route-visits.ts +88 -0
  53. package/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js +4 -3
  54. package/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +4 -3
  55. package/node_modules/@vue/compiler-core/dist/compiler-core.esm-bundler.js +4 -3
  56. package/node_modules/@vue/compiler-core/package.json +4 -4
  57. package/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js +9 -6
  58. package/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +41 -4
  59. package/node_modules/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +10 -7
  60. package/node_modules/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +12 -11
  61. package/node_modules/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +5 -3
  62. package/node_modules/@vue/compiler-dom/dist/compiler-dom.global.js +10 -7
  63. package/node_modules/@vue/compiler-dom/dist/compiler-dom.global.prod.js +12 -11
  64. package/node_modules/@vue/compiler-dom/package.json +3 -3
  65. package/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +155 -20
  66. package/node_modules/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +431 -98
  67. package/node_modules/@vue/compiler-sfc/package.json +10 -10
  68. package/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1 -1
  69. package/node_modules/@vue/compiler-ssr/package.json +3 -3
  70. package/node_modules/@vue/shared/dist/shared.cjs.js +51 -32
  71. package/node_modules/@vue/shared/dist/shared.cjs.prod.js +51 -32
  72. package/node_modules/@vue/shared/dist/shared.d.ts +2 -1
  73. package/node_modules/@vue/shared/dist/shared.esm-bundler.js +51 -32
  74. package/node_modules/@vue/shared/package.json +1 -1
  75. package/node_modules/nanoid/async/index.d.cts +56 -0
  76. package/node_modules/nanoid/index.cjs +12 -7
  77. package/node_modules/nanoid/index.js +1 -1
  78. package/node_modules/nanoid/package.json +3 -3
  79. package/node_modules/postcss/lib/input.js +1 -1
  80. package/node_modules/postcss/lib/lazy-result.js +1 -1
  81. package/node_modules/postcss/lib/list.js +19 -1
  82. package/node_modules/postcss/lib/map-generator.js +9 -3
  83. package/node_modules/postcss/lib/no-work-result.js +1 -1
  84. package/node_modules/postcss/lib/node.js +2 -2
  85. package/node_modules/postcss/lib/parser.js +6 -1
  86. package/node_modules/postcss/lib/processor.js +1 -1
  87. package/node_modules/postcss/lib/stringifier.js +16 -28
  88. package/node_modules/postcss/lib/stringify.js +84 -2
  89. package/node_modules/postcss/lib/warning.js +1 -0
  90. package/node_modules/postcss/package.json +3 -3
  91. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +19 -18
  92. package/node_modules/yaml/browser/dist/nodes/Alias.js +25 -23
  93. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +19 -18
  94. package/node_modules/yaml/dist/nodes/Alias.js +25 -23
  95. package/node_modules/yaml/package.json +1 -1
  96. package/package.json +2 -2
@@ -20,8 +20,21 @@ let list = {
20
20
  let inQuote = false
21
21
  let prevQuote = ''
22
22
  let escape = false
23
+ let inComment = false
24
+
25
+ for (let i = 0; i < string.length; i++) {
26
+ let letter = string[i]
27
+
28
+ if (inComment) {
29
+ current += letter
30
+ if (letter === '*' && string[i + 1] === '/') {
31
+ current += '/'
32
+ i += 1
33
+ inComment = false
34
+ }
35
+ continue
36
+ }
23
37
 
24
- for (let letter of string) {
25
38
  if (escape) {
26
39
  escape = false
27
40
  } else if (letter === '\\') {
@@ -33,6 +46,11 @@ let list = {
33
46
  } else if (letter === '"' || letter === "'") {
34
47
  inQuote = true
35
48
  prevQuote = letter
49
+ } else if (letter === '/' && string[i + 1] === '*') {
50
+ current += '/*'
51
+ i += 1
52
+ inComment = true
53
+ continue
36
54
  } else if (letter === '(') {
37
55
  func += 1
38
56
  } else if (letter === ')') {
@@ -75,16 +75,22 @@ class MapGenerator {
75
75
  }
76
76
  }
77
77
  } else if (this.css) {
78
+ // Single forward pass. Removing every annotation from the whole
79
+ // string separately would be O(n^2) on many annotations.
78
80
  let annotation = '/*# sourceMappingURL='
81
+ let css = ''
82
+ let cursor = 0
79
83
  let startIndex
80
- while ((startIndex = this.css.lastIndexOf(annotation)) !== -1) {
84
+ while ((startIndex = this.css.indexOf(annotation, cursor)) !== -1) {
81
85
  let endIndex = this.css.indexOf('*/', startIndex + annotation.length)
82
86
  if (endIndex === -1) break
83
- while (startIndex > 0 && this.css[startIndex - 1] === '\n') {
87
+ while (startIndex > cursor && this.css[startIndex - 1] === '\n') {
84
88
  startIndex--
85
89
  }
86
- this.css = this.css.slice(0, startIndex) + this.css.slice(endIndex + 2)
90
+ css += this.css.slice(cursor, startIndex)
91
+ cursor = endIndex + 2
87
92
  }
93
+ if (cursor > 0) this.css = css + this.css.slice(cursor)
88
94
  }
89
95
  }
90
96
 
@@ -102,7 +102,7 @@ class NoWorkResult {
102
102
  }
103
103
 
104
104
  finally(onFinally) {
105
- return this.async().then(onFinally, onFinally)
105
+ return this.async().finally(onFinally)
106
106
  }
107
107
 
108
108
  sync() {
@@ -240,7 +240,7 @@ class Node {
240
240
  } else if (opts.word) {
241
241
  let stringRepresentation = inputString.slice(
242
242
  sourceOffset(inputString, this.source.start),
243
- sourceOffset(inputString, this.source.end)
243
+ this.rangeBy().end.offset
244
244
  )
245
245
  let index = stringRepresentation.indexOf(opts.word)
246
246
  if (index !== -1) pos = this.positionInside(index)
@@ -308,7 +308,7 @@ class Node {
308
308
  if (opts.word) {
309
309
  let stringRepresentation = inputString.slice(
310
310
  sourceOffset(inputString, this.source.start),
311
- sourceOffset(inputString, this.source.end)
311
+ end.offset
312
312
  )
313
313
  let index = stringRepresentation.indexOf(opts.word)
314
314
  if (index !== -1) {
@@ -494,6 +494,9 @@ class Parser {
494
494
  let token, type
495
495
  let length = tokens.length
496
496
  let value = ''
497
+ // Last character of `value`. Reading it from `value` would flatten
498
+ // the string concatenation on every comment and make parsing O(n^2).
499
+ let last = ''
497
500
  let clean = true
498
501
  let next, prev
499
502
 
@@ -506,16 +509,18 @@ class Parser {
506
509
  prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty'
507
510
  next = tokens[i + 1] ? tokens[i + 1][0] : 'empty'
508
511
  if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
509
- if (value.slice(-1) === ',') {
512
+ if (last === ',') {
510
513
  clean = false
511
514
  } else {
512
515
  value += token[1]
516
+ last = token[1].slice(-1)
513
517
  }
514
518
  } else {
515
519
  clean = false
516
520
  }
517
521
  } else {
518
522
  value += token[1]
523
+ last = token[1].slice(-1)
519
524
  }
520
525
  }
521
526
  if (!clean) {
@@ -7,7 +7,7 @@ let Root = require('./root')
7
7
 
8
8
  class Processor {
9
9
  constructor(plugins = []) {
10
- this.version = '8.5.28'
10
+ this.version = '8.5.32'
11
11
  this.plugins = this.normalize(plugins)
12
12
  }
13
13
 
@@ -1,21 +1,9 @@
1
1
  'use strict'
2
2
 
3
- // Escapes sequences that could break out of an HTML <style> context.
4
- // Uses CSS unicode escaping (\3c = '<') which is valid CSS and parsed
5
- // correctly by all compliant CSS consumers.
6
- const STYLE_TAG = /(<)(\/?style\b)/gi
7
- const COMMENT_OPEN = /(<)(!--)/g
8
-
9
3
  // Characters that end an at-rule name, mirroring RE_AT_END in the tokenizer.
10
4
  // Params starting with anything else need a space to stay separate tokens.
11
5
  const AT_NAME_END = /[\t\n\f\r "#'()/;[\\\]{}]/
12
6
 
13
- function escapeHTMLInCSS(str) {
14
- if (typeof str !== 'string') return str
15
- if (!str.includes('<')) return str
16
- return str.replace(STYLE_TAG, '\\3c $2').replace(COMMENT_OPEN, '\\3c $2')
17
- }
18
-
19
7
  const DEFAULT_RAW = {
20
8
  after: '\n',
21
9
  beforeClose: '\n',
@@ -50,11 +38,12 @@ function atruleStart(str, node) {
50
38
  }
51
39
 
52
40
  // `*--x` is not a custom property: the parser checks the first token, and the
53
- // `*`/`_` hack prefix moves from `prop` into `before` only after that.
41
+ // `*`/`_` hack prefix moves from `prop` into `before` only after that. A free
42
+ // semicolon in front of the declaration also ends up in `before`.
54
43
  function isCustomProperty(node) {
55
44
  if (!node.prop.startsWith('--')) return false
56
45
  let before = node.raws.before
57
- return typeof before === 'undefined' || !/\S$/.test(before)
46
+ return typeof before === 'undefined' || !/[^\s;]$/.test(before)
58
47
  }
59
48
 
60
49
  function pushBody(str, stack, node) {
@@ -92,17 +81,17 @@ function pushBody(str, stack, node) {
92
81
 
93
82
  function pushBlock(str, stack, node, start) {
94
83
  let between = str.raw(node, 'between', 'beforeOpen')
95
- str.builder(escapeHTMLInCSS(start + between) + '{', node, 'start')
84
+ str.builder(start + between + '{', node, 'start')
96
85
 
97
86
  let hasNodes = node.nodes && node.nodes.length
98
87
  let close = () => {
99
88
  let after = hasNodes
100
89
  ? str.raw(node, 'after')
101
90
  : str.raw(node, 'after', 'emptyBody')
102
- if (after) str.builder(escapeHTMLInCSS(after))
91
+ if (after) str.builder(after)
103
92
  str.builder('}', node, 'end')
104
93
  if (node.type === 'rule' && node.raws.ownSemicolon) {
105
- str.builder(escapeHTMLInCSS(node.raws.ownSemicolon), node, 'end')
94
+ str.builder(node.raws.ownSemicolon, node, 'end')
106
95
  }
107
96
  }
108
97
 
@@ -125,7 +114,7 @@ class Stringifier {
125
114
  this.block(node, start)
126
115
  } else {
127
116
  let end = (node.raws.between || '') + (semicolon ? ';' : '')
128
- this.builder(escapeHTMLInCSS(start + end), node)
117
+ this.builder(start + end, node)
129
118
  }
130
119
  }
131
120
 
@@ -160,7 +149,7 @@ class Stringifier {
160
149
 
161
150
  block(node, start) {
162
151
  let between = this.raw(node, 'between', 'beforeOpen')
163
- this.builder(escapeHTMLInCSS(start + between) + '{', node, 'start')
152
+ this.builder(start + between + '{', node, 'start')
164
153
 
165
154
  let after
166
155
  if (node.nodes && node.nodes.length) {
@@ -170,7 +159,7 @@ class Stringifier {
170
159
  after = this.raw(node, 'after', 'emptyBody')
171
160
  }
172
161
 
173
- if (after) this.builder(escapeHTMLInCSS(after))
162
+ if (after) this.builder(after)
174
163
  this.builder('}', node, 'end')
175
164
  }
176
165
 
@@ -197,7 +186,7 @@ class Stringifier {
197
186
  let child = entry.node
198
187
  let before = this.raw(child, 'before')
199
188
  if (before) {
200
- this.builder(entry.document ? before : escapeHTMLInCSS(before))
189
+ this.builder(before)
201
190
  }
202
191
 
203
192
  if (expandable && child.type === 'rule') {
@@ -213,7 +202,7 @@ class Stringifier {
213
202
  comment(node) {
214
203
  let left = this.raw(node, 'left', 'commentLeft')
215
204
  let right = this.raw(node, 'right', 'commentRight')
216
- this.builder(escapeHTMLInCSS('/*' + left + node.text + right + '*/'), node)
205
+ this.builder('/*' + left + node.text + right + '*/', node)
217
206
  }
218
207
 
219
208
  decl(node, semicolon) {
@@ -227,7 +216,7 @@ class Stringifier {
227
216
  }
228
217
 
229
218
  if (semicolon) string += ';'
230
- this.builder(escapeHTMLInCSS(string), node)
219
+ this.builder(string, node)
231
220
  }
232
221
 
233
222
  document(node) {
@@ -432,21 +421,20 @@ class Stringifier {
432
421
  }
433
422
 
434
423
  root(node) {
435
- if (node.source && node.source.input.hasBOM) {
424
+ let inDocument = node.parent && node.parent.type === 'document'
425
+ if (!inDocument && node.source && node.source.input.hasBOM) {
436
426
  this.builder('\uFEFF', node, 'start')
437
427
  }
438
428
  this.body(node)
439
429
  if (node.raws.after) {
440
- let after = node.raws.after
441
- let isDocument = node.parent && node.parent.type === 'document'
442
- this.builder(isDocument ? after : escapeHTMLInCSS(after))
430
+ this.builder(node.raws.after)
443
431
  }
444
432
  }
445
433
 
446
434
  rule(node) {
447
435
  this.block(node, this.rawValue(node, 'selector'))
448
436
  if (node.raws.ownSemicolon) {
449
- this.builder(escapeHTMLInCSS(node.raws.ownSemicolon), node, 'end')
437
+ this.builder(node.raws.ownSemicolon, node, 'end')
450
438
  }
451
439
  }
452
440
 
@@ -2,9 +2,91 @@
2
2
 
3
3
  let Stringifier = require('./stringifier')
4
4
 
5
+ const STYLE_TAG = /(<)(\/?style\b)/gi
6
+ const COMMENT_OPEN = /(<)(!--)/g
7
+
8
+ function escapeHTMLInCSS(str) {
9
+ if (!str.includes('<')) return str
10
+ return str.replace(STYLE_TAG, '\\3c $2').replace(COMMENT_OPEN, '\\3c $2')
11
+ }
12
+
13
+ function cutEscaped(chunks, css, escaped) {
14
+ let parts = []
15
+ let at = 0
16
+ let into = 0
17
+ for (let i = 0; i < chunks.length; i += 3) {
18
+ let from = into
19
+ let end = at + chunks[i].length
20
+ while (at < end) {
21
+ if (css[at] === escaped[into]) {
22
+ at += 1
23
+ into += 1
24
+ } else {
25
+ // The `<` of this pair was replaced by the `\3c ` in front of it
26
+ at += 1
27
+ into += 4
28
+ }
29
+ }
30
+ parts.push(escaped.slice(from, into))
31
+ }
32
+ return parts
33
+ }
34
+
35
+ class SafeStringifier extends Stringifier {
36
+ escapeHTML(print) {
37
+ let builder = this.builder
38
+ let chunks, css
39
+ this.builder = (str, child, type) => {
40
+ if (chunks) {
41
+ css += str
42
+ chunks.push(str, child, type)
43
+ } else if (str.includes('<')) {
44
+ // Dangerous sequences start with `<`, so everything before
45
+ // the first `<` is safe to pass through. The rest is buffered
46
+ // to escape it as a whole.
47
+ css = str
48
+ chunks = [str, child, type]
49
+ } else {
50
+ builder(str, child, type)
51
+ }
52
+ }
53
+ print()
54
+ this.builder = builder
55
+ if (!chunks) return
56
+
57
+ let escaped = escapeHTMLInCSS(css)
58
+ if (escaped === css) {
59
+ // Keep the chunks to get a precise source map
60
+ for (let i = 0; i < chunks.length; i += 3) {
61
+ builder(chunks[i], chunks[i + 1], chunks[i + 2])
62
+ }
63
+ } else {
64
+ let parts = cutEscaped(chunks, css, escaped)
65
+ for (let i = 0; i < chunks.length; i += 3) {
66
+ builder(parts[i / 3], chunks[i + 1], chunks[i + 2])
67
+ }
68
+ }
69
+ }
70
+
71
+ root(node) {
72
+ if (node.parent && node.parent.type === 'document') {
73
+ // Document raws around the Root hold markup and are kept as is since CSS in Document can be marked with <style>
74
+ this.escapeHTML(() => this.body(node))
75
+ if (node.raws.after) this.builder(node.raws.after)
76
+ } else {
77
+ this.escapeHTML(() => super.root(node))
78
+ }
79
+ }
80
+ }
81
+
5
82
  function stringify(node, builder) {
6
- let str = new Stringifier(builder)
7
- str.stringify(node)
83
+ let str = new SafeStringifier(builder)
84
+ // Root escapes its own output and keeps markup in Document raws
85
+ if (node.type === 'root' || node.type === 'document') {
86
+ str.stringify(node)
87
+ } else {
88
+ str.escapeHTML(() => str.stringify(node))
89
+ }
8
90
  }
9
91
 
10
92
  module.exports = stringify
@@ -31,6 +31,7 @@ class Warning {
31
31
  return this.node.error(this.text, {
32
32
  index: this.index,
33
33
  plugin: this.plugin,
34
+ start: this.start,
34
35
  word: this.word
35
36
  }).message
36
37
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss",
3
- "version": "8.5.28",
3
+ "version": "8.5.32",
4
4
  "description": "Tool for transforming styles with JS plugins",
5
5
  "keywords": [
6
6
  "css",
@@ -78,9 +78,9 @@
78
78
  "./package.json": "./package.json"
79
79
  },
80
80
  "dependencies": {
81
- "nanoid": "^3.3.18",
81
+ "nanoid": "^3.3.20",
82
82
  "picocolors": "^1.1.1",
83
- "source-map-js": "^1.2.1"
83
+ "source-map-js": "^1.2.2"
84
84
  },
85
85
  "engines": {
86
86
  "node": "^10 || ^12 || >=14"
@@ -64,46 +64,47 @@ function plainValue(source, onError) {
64
64
  }
65
65
  if (badChar)
66
66
  onError(0, 'BAD_SCALAR_START', `Plain value cannot start with ${badChar}`);
67
- return foldLines(source);
67
+ return unfoldLines(source);
68
68
  }
69
69
  function singleQuotedValue(source, onError) {
70
70
  if (source[source.length - 1] !== "'" || source.length === 1)
71
71
  onError(source.length, 'MISSING_CHAR', "Missing closing 'quote");
72
- return foldLines(source.slice(1, -1)).replace(/''/g, "'");
72
+ return unfoldLines(source.slice(1, -1)).replace(/''/g, "'");
73
73
  }
74
- function foldLines(source) {
74
+ function unfoldLines(source) {
75
+ const line = /(.*?)\r?\n/sy;
76
+ let match = line.exec(source);
77
+ if (!match)
78
+ return source;
75
79
  /**
76
- * The negative lookbehind here and in the `re` RegExp is to
80
+ * The negative lookbehinds in these RegExps are to
77
81
  * prevent causing a polynomial search time in certain cases.
78
82
  *
79
- * The try-catch is for Safari, which doesn't support this yet:
83
+ * The try-catch is for Safari < 16.4 and other old browsers:
80
84
  * https://caniuse.com/js-regexp-lookbehind
81
85
  */
82
- let first, line;
86
+ let trimEnd, trimBoth;
83
87
  try {
84
- first = new RegExp('(.*?)(?<![ \t])[ \t]*\r?\n', 'sy');
85
- line = new RegExp('[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n', 'sy');
88
+ trimEnd = new RegExp('(?<![ \t])[ \t]+$');
89
+ trimBoth = new RegExp('^[ \t]+|(?<![ \t])[ \t]+$', 'g');
86
90
  }
87
91
  catch {
88
- first = /(.*?)[ \t]*\r?\n/sy;
89
- line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
92
+ trimEnd = /[ \t]+$/;
93
+ trimBoth = /^[ \t]+|[ \t]+$/g;
90
94
  }
91
- let match = first.exec(source);
92
- if (!match)
93
- return source;
94
- let res = match[1];
95
+ let res = match[1].replace(trimEnd, '');
95
96
  let sep = ' ';
96
- let pos = first.lastIndex;
97
- line.lastIndex = pos;
97
+ let pos = line.lastIndex;
98
98
  while ((match = line.exec(source))) {
99
- if (match[1] === '') {
99
+ const lm = match[1].replace(trimBoth, '');
100
+ if (lm === '') {
100
101
  if (sep === '\n')
101
102
  res += sep;
102
103
  else
103
104
  sep = '\n';
104
105
  }
105
106
  else {
106
- res += sep + match[1];
107
+ res += sep + lm;
107
108
  sep = ' ';
108
109
  }
109
110
  pos = line.lastIndex;
@@ -43,38 +43,40 @@ class Alias extends NodeBase {
43
43
  if (node.anchor === this.source)
44
44
  found = node;
45
45
  }
46
+ if (found && ctx) {
47
+ const { anchors, doc, maxAliasCount } = ctx;
48
+ let data = anchors.get(found);
49
+ if (!data) {
50
+ // Resolve anchors for Node.prototype.toJS()
51
+ toJS(found, null, ctx);
52
+ data = anchors.get(found);
53
+ }
54
+ /* istanbul ignore if */
55
+ if (data?.res === undefined) {
56
+ const msg = 'This should not happen: Alias anchor was not resolved?';
57
+ throw new ReferenceError(msg);
58
+ }
59
+ if (maxAliasCount >= 0) {
60
+ data.count += 1;
61
+ if (data.aliasCount === 0)
62
+ data.aliasCount = getAliasCount(doc, found, anchors);
63
+ if (data.count * data.aliasCount > maxAliasCount) {
64
+ const msg = 'Excessive alias count indicates a resource exhaustion attack';
65
+ throw new ReferenceError(msg);
66
+ }
67
+ }
68
+ }
46
69
  return found;
47
70
  }
48
71
  toJSON(_arg, ctx) {
49
72
  if (!ctx)
50
73
  return { source: this.source };
51
- const { anchors, doc, maxAliasCount } = ctx;
52
- const source = this.resolve(doc, ctx);
74
+ const source = this.resolve(ctx.doc, ctx);
53
75
  if (!source) {
54
76
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
55
77
  throw new ReferenceError(msg);
56
78
  }
57
- let data = anchors.get(source);
58
- if (!data) {
59
- // Resolve anchors for Node.prototype.toJS()
60
- toJS(source, null, ctx);
61
- data = anchors.get(source);
62
- }
63
- /* istanbul ignore if */
64
- if (data?.res === undefined) {
65
- const msg = 'This should not happen: Alias anchor was not resolved?';
66
- throw new ReferenceError(msg);
67
- }
68
- if (maxAliasCount >= 0) {
69
- data.count += 1;
70
- if (data.aliasCount === 0)
71
- data.aliasCount = getAliasCount(doc, source, anchors);
72
- if (data.count * data.aliasCount > maxAliasCount) {
73
- const msg = 'Excessive alias count indicates a resource exhaustion attack';
74
- throw new ReferenceError(msg);
75
- }
76
- }
77
- return data.res;
79
+ return ctx.anchors.get(source).res;
78
80
  }
79
81
  toString(ctx, _onComment, _onChompKeep) {
80
82
  const src = `*${this.source}`;
@@ -66,46 +66,47 @@ function plainValue(source, onError) {
66
66
  }
67
67
  if (badChar)
68
68
  onError(0, 'BAD_SCALAR_START', `Plain value cannot start with ${badChar}`);
69
- return foldLines(source);
69
+ return unfoldLines(source);
70
70
  }
71
71
  function singleQuotedValue(source, onError) {
72
72
  if (source[source.length - 1] !== "'" || source.length === 1)
73
73
  onError(source.length, 'MISSING_CHAR', "Missing closing 'quote");
74
- return foldLines(source.slice(1, -1)).replace(/''/g, "'");
74
+ return unfoldLines(source.slice(1, -1)).replace(/''/g, "'");
75
75
  }
76
- function foldLines(source) {
76
+ function unfoldLines(source) {
77
+ const line = /(.*?)\r?\n/sy;
78
+ let match = line.exec(source);
79
+ if (!match)
80
+ return source;
77
81
  /**
78
- * The negative lookbehind here and in the `re` RegExp is to
82
+ * The negative lookbehinds in these RegExps are to
79
83
  * prevent causing a polynomial search time in certain cases.
80
84
  *
81
- * The try-catch is for Safari, which doesn't support this yet:
85
+ * The try-catch is for Safari < 16.4 and other old browsers:
82
86
  * https://caniuse.com/js-regexp-lookbehind
83
87
  */
84
- let first, line;
88
+ let trimEnd, trimBoth;
85
89
  try {
86
- first = new RegExp('(.*?)(?<![ \t])[ \t]*\r?\n', 'sy');
87
- line = new RegExp('[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n', 'sy');
90
+ trimEnd = new RegExp('(?<![ \t])[ \t]+$');
91
+ trimBoth = new RegExp('^[ \t]+|(?<![ \t])[ \t]+$', 'g');
88
92
  }
89
93
  catch {
90
- first = /(.*?)[ \t]*\r?\n/sy;
91
- line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
94
+ trimEnd = /[ \t]+$/;
95
+ trimBoth = /^[ \t]+|[ \t]+$/g;
92
96
  }
93
- let match = first.exec(source);
94
- if (!match)
95
- return source;
96
- let res = match[1];
97
+ let res = match[1].replace(trimEnd, '');
97
98
  let sep = ' ';
98
- let pos = first.lastIndex;
99
- line.lastIndex = pos;
99
+ let pos = line.lastIndex;
100
100
  while ((match = line.exec(source))) {
101
- if (match[1] === '') {
101
+ const lm = match[1].replace(trimBoth, '');
102
+ if (lm === '') {
102
103
  if (sep === '\n')
103
104
  res += sep;
104
105
  else
105
106
  sep = '\n';
106
107
  }
107
108
  else {
108
- res += sep + match[1];
109
+ res += sep + lm;
109
110
  sep = ' ';
110
111
  }
111
112
  pos = line.lastIndex;
@@ -45,38 +45,40 @@ class Alias extends Node.NodeBase {
45
45
  if (node.anchor === this.source)
46
46
  found = node;
47
47
  }
48
+ if (found && ctx) {
49
+ const { anchors, doc, maxAliasCount } = ctx;
50
+ let data = anchors.get(found);
51
+ if (!data) {
52
+ // Resolve anchors for Node.prototype.toJS()
53
+ toJS.toJS(found, null, ctx);
54
+ data = anchors.get(found);
55
+ }
56
+ /* istanbul ignore if */
57
+ if (data?.res === undefined) {
58
+ const msg = 'This should not happen: Alias anchor was not resolved?';
59
+ throw new ReferenceError(msg);
60
+ }
61
+ if (maxAliasCount >= 0) {
62
+ data.count += 1;
63
+ if (data.aliasCount === 0)
64
+ data.aliasCount = getAliasCount(doc, found, anchors);
65
+ if (data.count * data.aliasCount > maxAliasCount) {
66
+ const msg = 'Excessive alias count indicates a resource exhaustion attack';
67
+ throw new ReferenceError(msg);
68
+ }
69
+ }
70
+ }
48
71
  return found;
49
72
  }
50
73
  toJSON(_arg, ctx) {
51
74
  if (!ctx)
52
75
  return { source: this.source };
53
- const { anchors, doc, maxAliasCount } = ctx;
54
- const source = this.resolve(doc, ctx);
76
+ const source = this.resolve(ctx.doc, ctx);
55
77
  if (!source) {
56
78
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
57
79
  throw new ReferenceError(msg);
58
80
  }
59
- let data = anchors.get(source);
60
- if (!data) {
61
- // Resolve anchors for Node.prototype.toJS()
62
- toJS.toJS(source, null, ctx);
63
- data = anchors.get(source);
64
- }
65
- /* istanbul ignore if */
66
- if (data?.res === undefined) {
67
- const msg = 'This should not happen: Alias anchor was not resolved?';
68
- throw new ReferenceError(msg);
69
- }
70
- if (maxAliasCount >= 0) {
71
- data.count += 1;
72
- if (data.aliasCount === 0)
73
- data.aliasCount = getAliasCount(doc, source, anchors);
74
- if (data.count * data.aliasCount > maxAliasCount) {
75
- const msg = 'Excessive alias count indicates a resource exhaustion attack';
76
- throw new ReferenceError(msg);
77
- }
78
- }
79
- return data.res;
81
+ return ctx.anchors.get(source).res;
80
82
  }
81
83
  toString(ctx, _onComment, _onChompKeep) {
82
84
  const src = `*${this.source}`;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "2.9.0",
3
+ "version": "2.9.1",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
6
  "funding": "https://github.com/sponsors/eemeli",