ddd-ts-kit 0.113.0 → 0.113.1

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 (80) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/help/work-notes.d.ts.map +1 -1
  3. package/dist/help/work-notes.js +5 -2
  4. package/dist/help/work-notes.js.map +1 -1
  5. package/dist/init/manifest/versions.js +25 -25
  6. package/dist/markers/merge-imports.d.ts.map +1 -1
  7. package/dist/markers/merge-imports.js +2 -22
  8. package/dist/markers/merge-imports.js.map +1 -1
  9. package/dist/markers/one-line-imports.d.ts +3 -0
  10. package/dist/markers/one-line-imports.d.ts.map +1 -0
  11. package/dist/markers/one-line-imports.js +22 -0
  12. package/dist/markers/one-line-imports.js.map +1 -0
  13. package/dist/merge/declarations/brackets-left-open.d.ts +7 -0
  14. package/dist/merge/declarations/brackets-left-open.d.ts.map +1 -0
  15. package/dist/merge/declarations/brackets-left-open.js +21 -0
  16. package/dist/merge/declarations/brackets-left-open.js.map +1 -0
  17. package/dist/merge/declarations/declaration.d.ts +15 -0
  18. package/dist/merge/declarations/declaration.d.ts.map +1 -0
  19. package/dist/merge/declarations/declaration.js +2 -0
  20. package/dist/merge/declarations/declaration.js.map +1 -0
  21. package/dist/merge/declarations/declarations-of.d.ts +11 -0
  22. package/dist/merge/declarations/declarations-of.d.ts.map +1 -0
  23. package/dist/merge/declarations/declarations-of.js +130 -0
  24. package/dist/merge/declarations/declarations-of.js.map +1 -0
  25. package/dist/merge/declarations/declared-lines.d.ts +14 -0
  26. package/dist/merge/declarations/declared-lines.d.ts.map +1 -0
  27. package/dist/merge/declarations/declared-lines.js +42 -0
  28. package/dist/merge/declarations/declared-lines.js.map +1 -0
  29. package/dist/merge/declarations/declared-side.d.ts +8 -0
  30. package/dist/merge/declarations/declared-side.d.ts.map +1 -0
  31. package/dist/merge/declarations/declared-side.js +2 -0
  32. package/dist/merge/declarations/declared-side.js.map +1 -0
  33. package/dist/merge/declarations/holds-every-line.d.ts +3 -0
  34. package/dist/merge/declarations/holds-every-line.d.ts.map +1 -0
  35. package/dist/merge/declarations/holds-every-line.js +10 -0
  36. package/dist/merge/declarations/holds-every-line.js.map +1 -0
  37. package/dist/merge/declarations/merge-declarations.d.ts +44 -0
  38. package/dist/merge/declarations/merge-declarations.d.ts.map +1 -0
  39. package/dist/merge/declarations/merge-declarations.js +101 -0
  40. package/dist/merge/declarations/merge-declarations.js.map +1 -0
  41. package/dist/merge/declarations/merged-imports.d.ts +9 -0
  42. package/dist/merge/declarations/merged-imports.d.ts.map +1 -0
  43. package/dist/merge/declarations/merged-imports.js +25 -0
  44. package/dist/merge/declarations/merged-imports.js.map +1 -0
  45. package/dist/merge/declarations/merged-lines.d.ts +16 -0
  46. package/dist/merge/declarations/merged-lines.d.ts.map +1 -0
  47. package/dist/merge/declarations/merged-lines.js +43 -0
  48. package/dist/merge/declarations/merged-lines.js.map +1 -0
  49. package/dist/merge/declarations/merged-region.d.ts +32 -0
  50. package/dist/merge/declarations/merged-region.d.ts.map +1 -0
  51. package/dist/merge/declarations/merged-region.js +84 -0
  52. package/dist/merge/declarations/merged-region.js.map +1 -0
  53. package/dist/merge/declarations/reads-as-merged.d.ts +9 -0
  54. package/dist/merge/declarations/reads-as-merged.d.ts.map +1 -0
  55. package/dist/merge/declarations/reads-as-merged.js +19 -0
  56. package/dist/merge/declarations/reads-as-merged.js.map +1 -0
  57. package/dist/merge/declarations/settle-declarations.d.ts +21 -0
  58. package/dist/merge/declarations/settle-declarations.d.ts.map +1 -0
  59. package/dist/merge/declarations/settle-declarations.js +88 -0
  60. package/dist/merge/declarations/settle-declarations.js.map +1 -0
  61. package/dist/merge/declarations/shares-half-a-pair.d.ts +11 -0
  62. package/dist/merge/declarations/shares-half-a-pair.d.ts.map +1 -0
  63. package/dist/merge/declarations/shares-half-a-pair.js +41 -0
  64. package/dist/merge/declarations/shares-half-a-pair.js.map +1 -0
  65. package/dist/merge/declarations/shown-of.d.ts +5 -0
  66. package/dist/merge/declarations/shown-of.d.ts.map +1 -0
  67. package/dist/merge/declarations/shown-of.js +5 -0
  68. package/dist/merge/declarations/shown-of.js.map +1 -0
  69. package/dist/merge/for-you-entry.js +4 -1
  70. package/dist/merge/for-you-entry.js.map +1 -1
  71. package/dist/merge/resolution.d.ts +2 -0
  72. package/dist/merge/resolution.d.ts.map +1 -1
  73. package/dist/merge/resolve-conflict.d.ts +4 -2
  74. package/dist/merge/resolve-conflict.d.ts.map +1 -1
  75. package/dist/merge/resolve-conflict.js +60 -15
  76. package/dist/merge/resolve-conflict.js.map +1 -1
  77. package/dist/version.d.ts +1 -1
  78. package/dist/version.js +1 -1
  79. package/package.json +6 -6
  80. package/templates/pipeline/package-scripts.json +1 -1
@@ -0,0 +1,44 @@
1
+ import type { Declaration } from './declaration.js';
2
+ import type { DeclaredSide } from './declared-side.js';
3
+ import type { LineMerge } from './merged-lines.js';
4
+ /** The three sides of a region, each read as declarations. */
5
+ export interface DeclaredSides {
6
+ readonly ours: DeclaredSide;
7
+ readonly base: DeclaredSide;
8
+ readonly theirs: DeclaredSide;
9
+ }
10
+ /** A declaration of the merged region: the one kept, or the versions the two sides do not agree on. */
11
+ export type MergedDeclaration = {
12
+ readonly kind: 'kept';
13
+ readonly declaration: Declaration;
14
+ } | {
15
+ readonly kind: 'conflict';
16
+ readonly ours: Declaration | undefined;
17
+ readonly base: Declaration | undefined;
18
+ readonly theirs: Declaration | undefined;
19
+ };
20
+ /**
21
+ * Why a region is not merged by declaration: a side changed or removed a statement of the base
22
+ * that declares no name, the two sides differ on entries of a list, which no line ends, each
23
+ * added a nameless statement that may be the other's written again, or both changed the order of
24
+ * the declarations they share, each its own way.
25
+ */
26
+ export type Refusal = 'unnamed' | 'entries' | 'twice' | 'order';
27
+ /** The declarations of a merged region, and the side whose order and blank lines it follows. */
28
+ export interface MergedRegion {
29
+ readonly merged: readonly MergedDeclaration[];
30
+ readonly lead: DeclaredSide;
31
+ }
32
+ /**
33
+ * The declarations of a region merged three ways, each whole: what one side added, changed or
34
+ * removed is taken when the other left that declaration as the base holds it, a declaration both
35
+ * wrote alike is kept once, one both changed takes the merge of its lines when they merge without
36
+ * a conflict, and one the two sides wrote differently, or one removed and the other changed, is a
37
+ * conflict. The declarations both sides hold stand in the order of the side that changed it, ours
38
+ * when none did; what a side alone brings stands after the declaration it follows on that side.
39
+ * Refused when nothing says which statement of the other side a statement is, or which order holds.
40
+ */
41
+ export declare function mergeDeclarations(sides: DeclaredSides, lineMerge: LineMerge): MergedRegion | {
42
+ refused: Refusal;
43
+ };
44
+ //# sourceMappingURL=merge-declarations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-declarations.d.ts","sourceRoot":"","sources":["../../../src/merge/declarations/merge-declarations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC/B;AAED,uGAAuG;AACvG,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;CAAE,GAC5D;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;CAC1C,CAAC;AAEN;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhE,gGAAgG;AAChG,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC9C,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,GAAG,YAAY,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CA6BjH"}
@@ -0,0 +1,101 @@
1
+ import { holdsEveryLine } from './holds-every-line.js';
2
+ /**
3
+ * The declarations of a region merged three ways, each whole: what one side added, changed or
4
+ * removed is taken when the other left that declaration as the base holds it, a declaration both
5
+ * wrote alike is kept once, one both changed takes the merge of its lines when they merge without
6
+ * a conflict, and one the two sides wrote differently, or one removed and the other changed, is a
7
+ * conflict. The declarations both sides hold stand in the order of the side that changed it, ours
8
+ * when none did; what a side alone brings stands after the declaration it follows on that side.
9
+ * Refused when nothing says which statement of the other side a statement is, or which order holds.
10
+ */
11
+ export function mergeDeclarations(sides, lineMerge) {
12
+ const refused = refusalOf(sides);
13
+ const lead = refused === undefined ? leadOf(sides) : undefined;
14
+ if (refused !== undefined || lead === undefined) {
15
+ return { refused: refused ?? 'order' };
16
+ }
17
+ const inBase = byKey(sides.base);
18
+ const inOurs = byKey(sides.ours);
19
+ const inTheirs = byKey(sides.theirs);
20
+ const follower = lead === sides.ours ? sides.theirs : sides.ours;
21
+ const inLead = byKey(lead);
22
+ const versionsOf = (key) => ({
23
+ ours: inOurs.get(key),
24
+ base: inBase.get(key),
25
+ theirs: inTheirs.get(key),
26
+ });
27
+ const merged = lead.declarations.flatMap(({ key }) => placed(key, settled(versionsOf(key), lineMerge)));
28
+ follower.declarations.forEach(({ key }, at) => {
29
+ const brought = inLead.has(key) ? [] : placed(key, settled(versionsOf(key), lineMerge));
30
+ merged.splice(placeAfter(merged, follower.declarations.slice(0, at)), 0, ...brought);
31
+ });
32
+ return { merged: merged.map(({ item }) => item), lead };
33
+ }
34
+ /** What makes the statements of a region impossible to pair between the sides, if anything does. */
35
+ function refusalOf({ ours, base, theirs }) {
36
+ const inOurs = byKey(ours);
37
+ const inTheirs = byKey(theirs);
38
+ const onBoth = ({ key }) => inOurs.has(key) && inTheirs.has(key);
39
+ const nameless = (declarations) => declarations.filter(({ name }) => name === undefined);
40
+ if (nameless([...ours.declarations, ...theirs.declarations]).some((entry) => !entry.ended && !onBoth(entry))) {
41
+ return 'entries';
42
+ }
43
+ if (!nameless(base.declarations).every(onBoth)) {
44
+ return 'unnamed';
45
+ }
46
+ const alone = (side, other) => nameless(side.declarations).filter(({ key }) => !other.has(key));
47
+ return alone(ours, inTheirs).some((mine) => alone(theirs, inOurs).some((other) => mayBeOne(mine, other)))
48
+ ? 'twice'
49
+ : undefined;
50
+ }
51
+ /** Whether two statements open alike and one holds every line of the other: one statement written twice, or two, nothing says which. */
52
+ function mayBeOne(one, other) {
53
+ return (one.lines[0] === other.lines[0] &&
54
+ (holdsEveryLine(one.lines, other.lines) || holdsEveryLine(other.lines, one.lines)));
55
+ }
56
+ /**
57
+ * The side whose order the merged region follows: ours, unless the trunk alone changed the order
58
+ * of the declarations both sides hold. Undefined when the two sides order them differently and
59
+ * the base does not say that one of them left that order alone.
60
+ */
61
+ function leadOf({ ours, base, theirs }) {
62
+ const shared = new Set(ours.declarations.map(({ key }) => key).filter((key) => byKey(theirs).has(key)));
63
+ const orderOf = (side, among = shared) => side.declarations.flatMap(({ key }) => (among.has(key) ? [key] : [])).join('\0');
64
+ if (orderOf(ours) === orderOf(theirs)) {
65
+ return ours;
66
+ }
67
+ const kept = new Set(base.declarations.map(({ key }) => key).filter((key) => shared.has(key)));
68
+ const moved = [ours, theirs].filter((side) => orderOf(side, kept) !== orderOf(base, kept));
69
+ return moved.length === 1 ? moved[0] : undefined;
70
+ }
71
+ function placed(key, items) {
72
+ return items.map((item) => ({ key, item }));
73
+ }
74
+ /** Where what a side alone brings goes: after the nearest declaration above it on that side that the merged region holds, else first. */
75
+ function placeAfter(merged, above) {
76
+ const anchor = above.findLast(({ key }) => merged.some((held) => held.key === key));
77
+ return anchor === undefined ? 0 : merged.findLastIndex((held) => held.key === anchor.key) + 1;
78
+ }
79
+ function byKey(side) {
80
+ return new Map(side.declarations.map((declaration) => [declaration.key, declaration]));
81
+ }
82
+ function settled(versions, lineMerge) {
83
+ const { ours, base, theirs } = versions;
84
+ if (same(ours, theirs) || same(theirs, base)) {
85
+ return kept(ours);
86
+ }
87
+ if (same(ours, base)) {
88
+ return kept(theirs);
89
+ }
90
+ const lines = ours === undefined || base === undefined || theirs === undefined
91
+ ? undefined
92
+ : lineMerge({ ours: ours.lines, base: base.lines, theirs: theirs.lines });
93
+ return lines === undefined || ours === undefined ? [{ kind: 'conflict', ...versions }] : kept({ ...ours, lines });
94
+ }
95
+ function kept(declaration) {
96
+ return declaration === undefined ? [] : [{ kind: 'kept', declaration }];
97
+ }
98
+ function same(one, other) {
99
+ return one?.lines.join('\n') === other?.lines.join('\n');
100
+ }
101
+ //# sourceMappingURL=merge-declarations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-declarations.js","sourceRoot":"","sources":["../../../src/merge/declarations/merge-declarations.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAkCpD;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAoB,EAAE,SAAoB;IAC1E,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE/D,IAAI,OAAO,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QAChD,OAAO,EA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,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACpH,CAAC;AAED,SAAS,IAAI,CAAC,WAAoC;IAChD,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,IAAI,CAAC,GAA4B,EAAE,KAA8B;IACxE,OAAO,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { DeclaredSides } from './merge-declarations.js';
2
+ /**
3
+ * The imports region merged statement by statement when each statement of the three sides reads
4
+ * as one import: each on one line, then merged as the registry merges whole statements, the names
5
+ * imported from one module in one statement. Undefined when a statement holds a comment or is no
6
+ * import: the region is then merged as any other declarations.
7
+ */
8
+ export declare function mergedImports({ ours, base, theirs }: DeclaredSides): string[] | undefined;
9
+ //# sourceMappingURL=merged-imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merged-imports.d.ts","sourceRoot":"","sources":["../../../src/merge/declarations/merged-imports.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAK1D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,aAAa,GAAG,MAAM,EAAE,GAAG,SAAS,CASzF"}
@@ -0,0 +1,25 @@
1
+ import { oneLineImports } from '../../markers/one-line-imports.js';
2
+ import { registryUnion } from '../registry-union.js';
3
+ /** A whole import statement on one line, without a comment. */
4
+ const ONE_IMPORT = /^import\s[^/']*(?:'[^']*')?;$/;
5
+ /**
6
+ * The imports region merged statement by statement when each statement of the three sides reads
7
+ * as one import: each on one line, then merged as the registry merges whole statements, the names
8
+ * imported from one module in one statement. Undefined when a statement holds a comment or is no
9
+ * import: the region is then merged as any other declarations.
10
+ */
11
+ export function mergedImports({ ours, base, theirs }) {
12
+ const sides = [ours, base, theirs].map(statementsOf);
13
+ const [mine, origin, other] = sides;
14
+ if (mine === undefined || origin === undefined || other === undefined) {
15
+ return undefined;
16
+ }
17
+ return registryUnion({ kind: 'conflict', ours: mine, base: origin, theirs: other, raw: [], line: 1 }, 'imports');
18
+ }
19
+ function statementsOf(side) {
20
+ const statements = side.declarations.map(({ lines }) => oneLineImports(lines));
21
+ return statements.every((lines) => lines.length === 1 && ONE_IMPORT.test(lines[0] ?? ''))
22
+ ? statements.flat()
23
+ : undefined;
24
+ }
25
+ //# sourceMappingURL=merged-imports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merged-imports.js","sourceRoot":"","sources":["../../../src/merge/declarations/merged-imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIlD,+DAA+D;AAC/D,MAAM,UAAU,GAAG,+BAA+B,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAiB;IACjE,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACrD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC;IAEpC,IAAI,IAAI,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtE,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,aAAa,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;AACnH,CAAC;AAED,SAAS,YAAY,CAAC,IAAkB;IACtC,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IAE/E,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACvF,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE;QACnB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** The three versions of one declaration, as lines. */
2
+ export interface Versions {
3
+ readonly ours: readonly string[];
4
+ readonly base: readonly string[];
5
+ readonly theirs: readonly string[];
6
+ }
7
+ /** What merges the lines of the three versions of a declaration; undefined when they do not merge without a conflict. */
8
+ export type LineMerge = (versions: Versions) => readonly string[] | undefined;
9
+ /**
10
+ * The lines of a declaration both sides changed, merged as git merges a file: each version is
11
+ * written as an object of the repository, no ref names it, and the merge is computed as
12
+ * merge-trunk computes the one of the tree. Undefined when the versions conflict, or when git cannot write or merge
13
+ * them: the declaration is then left to a person.
14
+ */
15
+ export declare function mergedLines(top: string, { ours, base, theirs }: Versions): string[] | undefined;
16
+ //# sourceMappingURL=merged-lines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merged-lines.d.ts","sourceRoot":"","sources":["../../../src/merge/declarations/merged-lines.ts"],"names":[],"mappings":"AAGA,uDAAuD;AACvD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,yHAAyH;AACzH,MAAM,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;AAK9E;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,GAAG,MAAM,EAAE,GAAG,SAAS,CAQ/F"}
@@ -0,0 +1,43 @@
1
+ import { gitProcess } from '../git-process.js';
2
+ import { objectBytes } from '../object-bytes.js';
3
+ const FILE = 'declaration';
4
+ const AUTHOR = ['-c', 'user.name=ddd-ts-kit', '-c', 'user.email=ddd-ts-kit@localhost', '-c', 'commit.gpgsign=false'];
5
+ /**
6
+ * The lines of a declaration both sides changed, merged as git merges a file: each version is
7
+ * written as an object of the repository, no ref names it, and the merge is computed as
8
+ * merge-trunk computes the one of the tree. Undefined when the versions conflict, or when git cannot write or merge
9
+ * them: the declaration is then left to a person.
10
+ */
11
+ export function mergedLines(top, { ours, base, theirs }) {
12
+ const origin = commitOf(top, base);
13
+ const mine = origin === undefined ? undefined : commitOf(top, ours, origin);
14
+ const other = origin === undefined ? undefined : commitOf(top, theirs, origin);
15
+ return origin === undefined || mine === undefined || other === undefined
16
+ ? undefined
17
+ : mergedFile(top, { base: origin, ours: mine, theirs: other });
18
+ }
19
+ /**
20
+ * The file three commits merge into, as lines, by the `git merge-tree` that computes the merge of
21
+ * the tree; undefined on a conflict, or when git does not merge them (a git without `--merge-base`).
22
+ */
23
+ function mergedFile(top, { base, ours, theirs }) {
24
+ const tree = written(top, ['merge-tree', '--write-tree', '--no-messages', `--merge-base=${base}`, ours, theirs]);
25
+ const name = `${tree ?? ''}:${FILE}`;
26
+ const text = tree === undefined ? undefined : objectBytes(top, [name]).get(name)?.toString('utf8');
27
+ return text?.replace(/\n$/, '').split('\n');
28
+ }
29
+ /** A commit that holds the lines as one file, on `parent` when it has one; undefined when git does not write it. */
30
+ function commitOf(top, lines, parent) {
31
+ const blob = written(top, ['hash-object', '-w', '--stdin'], `${lines.join('\n')}\n`);
32
+ const tree = blob === undefined ? undefined : written(top, ['mktree'], `100644 blob ${blob}\t${FILE}\n`);
33
+ return tree === undefined
34
+ ? undefined
35
+ : written(top, [...AUTHOR, 'commit-tree', tree, ...(parent === undefined ? [] : ['-p', parent]), '-m', FILE]);
36
+ }
37
+ /** The object git wrote, by its id. */
38
+ function written(top, args, input) {
39
+ const answer = gitProcess(top, args, input);
40
+ const id = answer.status === 0 ? answer.stdout.trim() : '';
41
+ return /^[0-9a-f]{40,64}$/.test(id) ? id : undefined;
42
+ }
43
+ //# sourceMappingURL=merged-lines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merged-lines.js","sourceRoot":"","sources":["../../../src/merge/declarations/merged-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAY9C,MAAM,IAAI,GAAG,aAAa,CAAC;AAC3B,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE,iCAAiC,EAAE,IAAI,EAAE,sBAAsB,CAAC,CAAC;AAErH;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAY;IACvE,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5E,MAAM,KAAK,GAA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I,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,eAAe,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC;IAEzG,OAAO,IAAI,KAAK,SAAS;QACvB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAClH,CAAC;AAED,uCAAuC;AACvC,SAAS,OAAO,CAAC,GAAW,EAAE,IAAuB,EAAE,KAAc;IACnE,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5C,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE3D,OAAO,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { ConflictedPath } from '../conflicted-path.js';
2
+ import { type ConflictLabels } from './declared-lines.js';
3
+ /** What a region of declarations leaves to a person. */
4
+ export interface HeldRegion {
5
+ /** How to settle it. */
6
+ readonly advice: string;
7
+ /** How many conflicts of the file lie in it. */
8
+ readonly blocks: number;
9
+ }
10
+ /** The lines a region of declarations is written again with, and what it leaves to a person. */
11
+ export type RegionOutcome = {
12
+ readonly lines: readonly string[];
13
+ } | {
14
+ readonly lines: readonly string[] | undefined;
15
+ readonly held: HeldRegion;
16
+ };
17
+ /** What the merge of a region is given: the repository, the marker lines of its conflicts, how many it holds. */
18
+ interface Given {
19
+ readonly top: string;
20
+ readonly labels: ConflictLabels;
21
+ readonly blocks: number;
22
+ }
23
+ /**
24
+ * A region of a conflicted file merged from its three sides, declaration by declaration. Its
25
+ * lines hold a conflict for each declaration the two sides do not agree on. Nothing is written,
26
+ * and the conflicts git wrote stay for a person, when the region is not read with certainty: a
27
+ * side, the base among them, does not hold it once or cannot be read, the declarations of the
28
+ * sides cannot be paired or ordered, or the merged lines do not read back as the declarations merged.
29
+ */
30
+ export declare function mergedRegion(name: string, path: ConflictedPath, { top, labels, blocks }: Given): RegionOutcome;
31
+ export {};
32
+ //# sourceMappingURL=merged-region.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merged-region.d.ts","sourceRoot":"","sources":["../../../src/merge/declarations/merged-region.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,kBAAkB,CAAC;AAOtE,wDAAwD;AACxD,MAAM,WAAW,UAAU;IACzB,wBAAwB;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,gGAAgG;AAChG,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GACrC;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAEjF,iHAAiH;AACjH,UAAU,KAAK;IACb,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,GAAG,aAAa,CA6B9G"}
@@ -0,0 +1,84 @@
1
+ import { regionsOf } from '../../markers/index.js';
2
+ import { declarationsOf } from './declarations-of.js';
3
+ import { declaredLines } from './declared-lines.js';
4
+ import { mergeDeclarations } from './merge-declarations.js';
5
+ import { mergedLines } from './merged-lines.js';
6
+ import { readsAsMerged } from './reads-as-merged.js';
7
+ import { shownOf } from './shown-of.js';
8
+ import { mergedImports } from './merged-imports.js';
9
+ /**
10
+ * A region of a conflicted file merged from its three sides, declaration by declaration. Its
11
+ * lines hold a conflict for each declaration the two sides do not agree on. Nothing is written,
12
+ * and the conflicts git wrote stay for a person, when the region is not read with certainty: a
13
+ * side, the base among them, does not hold it once or cannot be read, the declarations of the
14
+ * sides cannot be paired or ordered, or the merged lines do not read back as the declarations merged.
15
+ */
16
+ export function mergedRegion(name, path, { top, labels, blocks }) {
17
+ const ours = sideOf(path.ours, name);
18
+ const theirs = sideOf(path.theirs, name);
19
+ const base = sideOf(path.base, name);
20
+ if (ours === undefined || theirs === undefined || base === undefined) {
21
+ return unread(name, blocks);
22
+ }
23
+ const imports = name === 'imports' ? mergedImports({ ours, base, theirs }) : undefined;
24
+ if (imports !== undefined) {
25
+ return { lines: imports };
26
+ }
27
+ const outcome = mergeDeclarations({ ours, base, theirs }, (versions) => mergedLines(top, versions));
28
+ const why = whyNot(outcome);
29
+ if ('refused' in outcome || why !== undefined) {
30
+ return unread(name, blocks, why);
31
+ }
32
+ const lines = declaredLines(outcome.merged, outcome.lead, labels);
33
+ const conflicts = outcome.merged.flatMap((item) => (item.kind === 'conflict' ? [item] : []));
34
+ return conflicts.length === 0
35
+ ? { lines }
36
+ : { lines, held: { advice: adviceOf(name, conflicts), blocks: conflicts.length } };
37
+ }
38
+ /** Why a region is not written as merged: its declarations were not merged, they do not read back, or they give the file two default exports. */
39
+ function whyNot(outcome) {
40
+ if ('refused' in outcome) {
41
+ return outcome.refused;
42
+ }
43
+ if (!readsAsMerged(outcome.merged, outcome.lead)) {
44
+ return 'unread';
45
+ }
46
+ return outcome.merged.filter(exportsADefault).length > 1 ? 'defaults' : undefined;
47
+ }
48
+ /** A default export in either spelling: `export default ...` or `export { name as default }`. */
49
+ const DEFAULT_EXPORT = /^\s*export\s+(?:default\b|(?:type\s+)?\{[^}]*\bas\s+default\b)/;
50
+ /** Whether a declaration of the merged region, in the version of a side when it is left to a person, gives the file its default export. */
51
+ function exportsADefault(item) {
52
+ return shownOf(item)?.lines.some((line) => DEFAULT_EXPORT.test(line)) === true;
53
+ }
54
+ const WHOLE = ', and its hunks show lines, not whole declarations: keep each declaration of both sides whole, once, its brackets closed';
55
+ /** What stops the merge of a region by declaration, and what to do of its hunks, said to the person they are left to. */
56
+ const WHY = {
57
+ unread: `holds declarations of several lines the kit could not read with certainty${WHOLE}.`,
58
+ unnamed: `holds a statement that declares no name and that one side changed or removed, which the kit does not merge${WHOLE}.`,
59
+ entries: `holds lines that end no statement (entries of a list, or statements written without \`;\`) on which the two sides differ, which the kit does not merge one by one${WHOLE}.`,
60
+ twice: 'holds two statements with no declared name that open alike, one holding every line of the other, which the kit cannot tell from one statement written twice, and its hunks show lines, not whole statements: write it once if it is one statement, each whole if they are two.',
61
+ order: `holds declarations the two sides set in two different orders${WHOLE}, in the order that holds for both.`,
62
+ defaults: 'holds a default export of each side, and a file has one: write the one the file keeps, whole, and export what the other side declared under a name.',
63
+ };
64
+ function unread(name, blocks, why = 'unread') {
65
+ return { lines: undefined, held: { advice: `the region \`${name}\` ${WHY[why]}`, blocks } };
66
+ }
67
+ /** What to do of the declarations left: each named when both sides hold it, the region when a side removed one. */
68
+ function adviceOf(name, conflicts) {
69
+ const names = conflicts.map(({ ours, theirs }) => ours === undefined || theirs === undefined ? undefined : ours.name);
70
+ const what = names.includes(undefined)
71
+ ? `in the region \`${name}\`: for each hunk`
72
+ : `on ${names.map((declared) => `\`${declared}\``).join(', ')} in the region \`${name}\`: for each`;
73
+ return `the two sides do not agree ${what}, write the one declaration that keeps the intent of both, whole, or remove it.`;
74
+ }
75
+ /** The declarations a side holds in its one region of that name; undefined when it holds none, several, or one that is not read. */
76
+ function sideOf(text, name) {
77
+ const lines = (text ?? '').split('\n');
78
+ const regions = regionsOf(lines).filter((region) => region.name === name);
79
+ const [region] = regions;
80
+ return region === undefined || regions.length > 1
81
+ ? undefined
82
+ : declarationsOf(lines.slice(region.open + 1, region.close));
83
+ }
84
+ //# sourceMappingURL=merged-region.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merged-region.js","sourceRoot":"","sources":["../../../src/merge/declarations/merged-region.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAuB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAA0B,iBAAiB,EAAgB,MAAM,sBAAsB,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAsBjD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,IAAoB,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAS;IAC7F,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EA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AAC,KAAK,CAAC,CAAC,CAAC;AACjE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { DeclaredSide } from './declared-side.js';
2
+ import type { MergedDeclaration } from './merge-declarations.js';
3
+ /**
4
+ * Whether the lines a merged region is written with read back as the declarations merged, each
5
+ * whole, in their order, every bracket paired: the last check before anything is written. A
6
+ * declaration left to a person is read as the version of one side.
7
+ */
8
+ export declare function readsAsMerged(merged: readonly MergedDeclaration[], ours: DeclaredSide): boolean;
9
+ //# sourceMappingURL=reads-as-merged.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads-as-merged.d.ts","sourceRoot":"","sources":["../../../src/merge/declarations/reads-as-merged.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAK9D;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAW/F"}
@@ -0,0 +1,19 @@
1
+ import { declarationsOf } from './declarations-of.js';
2
+ import { declaredLines } from './declared-lines.js';
3
+ import { shownOf } from './shown-of.js';
4
+ const NO_LABELS = { ours: '', base: '', theirs: '' };
5
+ /**
6
+ * Whether the lines a merged region is written with read back as the declarations merged, each
7
+ * whole, in their order, every bracket paired: the last check before anything is written. A
8
+ * declaration left to a person is read as the version of one side.
9
+ */
10
+ export function readsAsMerged(merged, ours) {
11
+ const shown = merged.flatMap((item) => {
12
+ const declaration = shownOf(item);
13
+ return declaration === undefined ? [] : [{ kind: 'kept', declaration }];
14
+ });
15
+ const read = declarationsOf(declaredLines(shown, ours, NO_LABELS));
16
+ const texts = shown.map(({ declaration }) => declaration.lines.join('\n'));
17
+ return read?.declarations.map(({ lines }) => lines.join('\n')).join('\n\0') === texts.join('\n\0');
18
+ }
19
+ //# sourceMappingURL=reads-as-merged.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads-as-merged.js","sourceRoot":"","sources":["../../../src/merge/declarations/reads-as-merged.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAErD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAoC,EAAE,IAAkB;IACpF,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACpC,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAElC,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,WAAW,EAAE,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,cAAc,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE3E,OAAO,IAAI,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACrG,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { ConflictedPath } from '../conflicted-path.js';
2
+ import { type HeldRegion } from './merged-region.js';
3
+ /** What the merge of the declarations of a file gives. */
4
+ export interface SettledDeclarations {
5
+ /** The text of the merge, each region of declarations that could be merged written again. */
6
+ readonly content: string;
7
+ /** The regions the union of lines would break, by name, that it must not settle: what is left of each to a person. */
8
+ readonly held: ReadonlyMap<string, HeldRegion>;
9
+ /** Whether a region was merged declaration by declaration. */
10
+ readonly merged: boolean;
11
+ }
12
+ /**
13
+ * Merges, in the text a merge wrote for a file, each generated region in which the lines of both
14
+ * sides, kept, would leave a declaration open: git sets two tables, two models or two functions
15
+ * added at one place side by side and keeps the lines they share once, so that the union of the
16
+ * lines no longer pairs their brackets. Such a region is merged from the three sides of the
17
+ * file, declaration by declaration. Any other region is left to the union of lines, untouched:
18
+ * `top` is the repository the lines of a declaration both sides changed are merged in.
19
+ */
20
+ export declare function settleDeclarations(path: ConflictedPath, top: string): SettledDeclarations;
21
+ //# sourceMappingURL=settle-declarations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settle-declarations.d.ts","sourceRoot":"","sources":["../../../src/merge/declarations/settle-declarations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIzD,OAAO,EAAE,KAAK,UAAU,EAAgB,MAAM,iBAAiB,CAAC;AAGhE,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IAClC,6FAA6F;IAC7F,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,sHAAsH;IACtH,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC/C,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GAAG,mBAAmB,CA4BzF"}
@@ -0,0 +1,88 @@
1
+ import { scan } from '../../check/scan/scan.js';
2
+ import { REGION_MARKER, regionsOf } from '../../markers/index.js';
3
+ import { conflictBlocks } from '../conflict-blocks.js';
4
+ import { registryUnion } from '../registry-union.js';
5
+ import { bracketsLeftOpen } from './brackets-left-open.js';
6
+ import { mergedRegion } from './merged-region.js';
7
+ import { sharesHalfAPair } from './shares-half-a-pair.js';
8
+ /**
9
+ * Merges, in the text a merge wrote for a file, each generated region in which the lines of both
10
+ * sides, kept, would leave a declaration open: git sets two tables, two models or two functions
11
+ * added at one place side by side and keeps the lines they share once, so that the union of the
12
+ * lines no longer pairs their brackets. Such a region is merged from the three sides of the
13
+ * file, declaration by declaration. Any other region is left to the union of lines, untouched:
14
+ * `top` is the repository the lines of a declaration both sides changed are merged in.
15
+ */
16
+ export function settleDeclarations(path, top) {
17
+ const text = path.merged ?? '';
18
+ const owners = ownersOf(text);
19
+ const lines = text.split('\n');
20
+ const held = new Map();
21
+ let merged = false;
22
+ const frame = regionsOf(lines.map((line, at) => (owners[at] === undefined ? line : '')));
23
+ const written = [];
24
+ let from = 0;
25
+ for (const region of frame.filter((candidate) => leavesADeclarationOpen(candidate, lines, owners))) {
26
+ const blocks = blocksIn(region, owners);
27
+ const outcome = mergedRegion(region.name, path, { top, labels: labelsOf(blocks[0]), blocks: blocks.length });
28
+ if ('held' in outcome) {
29
+ held.set(region.name, outcome.held);
30
+ // A conflict in a region written inside this one is a conflict of this one: no union settles it either.
31
+ innerNames(lines.slice(region.open + 1, region.close)).forEach((inner) => held.set(inner, NOTHING_MORE));
32
+ }
33
+ if (outcome.lines !== undefined) {
34
+ written.push(...lines.slice(from, region.open + 1), ...outcome.lines);
35
+ from = region.close;
36
+ merged = true;
37
+ }
38
+ }
39
+ return { content: [...written, ...lines.slice(from)].join('\n'), held, merged };
40
+ }
41
+ /** A region written inside one that is left: its conflicts are counted with those of the outer one. */
42
+ const NOTHING_MORE = { advice: '', blocks: 0 };
43
+ /** The names of the regions whose markers these lines hold. */
44
+ function innerNames(lines) {
45
+ return lines.flatMap((line) => REGION_MARKER.exec(line)?.[2] ?? []);
46
+ }
47
+ /** For each line of the text of a merge, the conflict it is a line of. */
48
+ function ownersOf(text) {
49
+ return conflictBlocks(text).flatMap((segment) => segment.kind === 'conflict'
50
+ ? Array(segment.raw.length).fill(segment)
51
+ : Array(segment.lines.length).fill(undefined));
52
+ }
53
+ /** The conflicts that lie in a region, each once. */
54
+ function blocksIn(region, owners) {
55
+ return [...new Set(owners.slice(region.open + 1, region.close))].flatMap((owner) => owner === undefined ? [] : [owner]);
56
+ }
57
+ /**
58
+ * Whether the lines of both sides, kept as the registry keeps them, would leave a declaration of
59
+ * the region open: the region the union of lines writes does not pair its brackets, or it pairs
60
+ * them by chance, two different statements added in one conflict opening or closing on one line
61
+ * the union keeps once. A region with no conflict, or with one that holds a marker, which no
62
+ * union settles, is not concerned.
63
+ */
64
+ function leavesADeclarationOpen(region, lines, owners) {
65
+ const blocks = blocksIn(region, owners);
66
+ const sides = blocks.flatMap((block) => [...block.ours, ...block.base, ...block.theirs]);
67
+ if (blocks.length === 0 || sides.some((line) => REGION_MARKER.test(line))) {
68
+ return false;
69
+ }
70
+ const union = lines.slice(region.open + 1, region.close).flatMap((line, at) => {
71
+ const owner = owners[region.open + 1 + at];
72
+ if (owner === undefined) {
73
+ return [line];
74
+ }
75
+ return owner === owners[region.open + at] ? [] : registryUnion(owner, region.name);
76
+ });
77
+ return blocks.some(sharesHalfAPair) || bracketsLeftOpen(scan(union.join('\n')).code)?.length !== 0;
78
+ }
79
+ /** The marker lines of the first conflict of a region: the declarations left to a person are written with the same. */
80
+ function labelsOf(block) {
81
+ const base = block?.raw[block.ours.length + 1] ?? '';
82
+ return {
83
+ ours: block?.raw[0] ?? '<<<<<<< ours',
84
+ base: base.startsWith('|||||||') ? base : '||||||| base',
85
+ theirs: block?.raw.at(-1) ?? '>>>>>>> theirs',
86
+ };
87
+ }
88
+ //# sourceMappingURL=settle-declarations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settle-declar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,CAAC,CAAC,CAAC,cAAc;QACxD,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,gBAAgB;KAC9C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { ConflictBlock } from '../conflict-blocks.js';
2
+ /**
3
+ * Whether the union of the lines of a conflict would pair the brackets of two different
4
+ * statements by chance. The lines each side adds are read in units that pair their own brackets:
5
+ * one line, or a run from a line that opens a bracket to the line that closes it. Two different
6
+ * units that open on the same line, or close on the same line, lose that line once in the union,
7
+ * which keeps each line once; a unit both sides added alike is one unit, kept once as the union
8
+ * keeps it, and never counts.
9
+ */
10
+ export declare function sharesHalfAPair(block: ConflictBlock): boolean;
11
+ //# sourceMappingURL=shares-half-a-pair.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shares-half-a-pair.d.ts","sourceRoot":"","sources":["../../../src/merge/declarations/shares-half-a-pair.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAQ7D"}