@plannotator/sem-jiff 0.0.0-stage → 0.2.0

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 (66) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE-APACHE +191 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +110 -2
  5. package/THIRD-PARTY-NOTICES +367 -0
  6. package/dist/candidate.d.ts +14 -0
  7. package/dist/candidate.js +1 -0
  8. package/dist/classifier.d.ts +25 -0
  9. package/dist/classifier.js +32 -0
  10. package/dist/copy-wasm-bin.d.ts +2 -0
  11. package/dist/copy-wasm-bin.js +11 -0
  12. package/dist/copy-wasm.d.ts +3 -0
  13. package/dist/copy-wasm.js +43 -0
  14. package/dist/coverage.d.ts +7 -0
  15. package/dist/coverage.js +43 -0
  16. package/dist/edits.d.ts +10 -0
  17. package/dist/edits.js +230 -0
  18. package/dist/extract.d.ts +5 -0
  19. package/dist/extract.js +24 -0
  20. package/dist/grammars.d.ts +22 -0
  21. package/dist/grammars.js +37 -0
  22. package/dist/index.d.ts +76 -0
  23. package/dist/index.js +493 -0
  24. package/dist/inline.d.ts +21 -0
  25. package/dist/inline.js +723 -0
  26. package/dist/languages.d.ts +2 -0
  27. package/dist/languages.js +28 -0
  28. package/dist/linediff.d.ts +27 -0
  29. package/dist/linediff.js +163 -0
  30. package/dist/opinions.d.ts +84 -0
  31. package/dist/opinions.js +201 -0
  32. package/dist/pairing.d.ts +10 -0
  33. package/dist/pairing.js +137 -0
  34. package/dist/parse.d.ts +118 -0
  35. package/dist/parse.js +1274 -0
  36. package/dist/pierre-types.d.ts +101 -0
  37. package/dist/pierre-types.js +5 -0
  38. package/dist/runtime.d.ts +46 -0
  39. package/dist/runtime.js +51 -0
  40. package/dist/structure.d.ts +13 -0
  41. package/dist/structure.js +894 -0
  42. package/dist/summary.d.ts +19 -0
  43. package/dist/summary.js +15 -0
  44. package/dist/syntax.d.ts +67 -0
  45. package/dist/syntax.js +412 -0
  46. package/dist/textdiff.d.ts +15 -0
  47. package/dist/textdiff.js +64 -0
  48. package/dist/textmoves.d.ts +8 -0
  49. package/dist/textmoves.js +143 -0
  50. package/package.json +108 -4
  51. package/src/candidate.ts +10 -0
  52. package/src/grammars.ts +44 -0
  53. package/src/opinions.ts +271 -0
  54. package/wasm/SHA256SUMS +12 -0
  55. package/wasm/tree-sitter-c_sharp.wasm +0 -0
  56. package/wasm/tree-sitter-go.wasm +0 -0
  57. package/wasm/tree-sitter-java.wasm +0 -0
  58. package/wasm/tree-sitter-kotlin.wasm +0 -0
  59. package/wasm/tree-sitter-php.wasm +0 -0
  60. package/wasm/tree-sitter-python.wasm +0 -0
  61. package/wasm/tree-sitter-ruby.wasm +0 -0
  62. package/wasm/tree-sitter-rust.wasm +0 -0
  63. package/wasm/tree-sitter-swift.wasm +0 -0
  64. package/wasm/tree-sitter-tsx.wasm +0 -0
  65. package/wasm/tree-sitter-typescript.wasm +0 -0
  66. package/wasm/web-tree-sitter.wasm +0 -0
@@ -0,0 +1,118 @@
1
+ import { Parser, type Node, type Tree } from 'web-tree-sitter';
2
+ import type { LanguageId } from './languages.js';
3
+ export { languageForPath, type LanguageId } from './languages.js';
4
+ /** Comment node types across grammars (Rust splits line and block comments; Swift calls block comments multiline_comment). */
5
+ export declare const COMMENT_TYPES: ReadonlySet<string>;
6
+ export declare const isComment: (n: Node | null | undefined) => boolean;
7
+ export interface LanguageConfig {
8
+ id: LanguageId;
9
+ /** The grammar's package path, e.g. `tree-sitter-go/tree-sitter-go.wasm` (see `configure`). */
10
+ wasm: string;
11
+ /** Node types that declare a named function or method. */
12
+ functionTypes: ReadonlySet<string>;
13
+ /** Node types that call a function (PHP has four: plain, member, static and nullsafe calls). */
14
+ callTypes: ReadonlySet<string>;
15
+ /** Node types that hold a list of statements. */
16
+ blockTypes: ReadonlySet<string>;
17
+ /** The statement returns from the function (`last`: it is the body's final statement, for tail expressions). */
18
+ isReturn(stmt: Node, last: boolean): boolean;
19
+ /** The function's name, or null for anonymous functions. */
20
+ nameOf(fn: Node): string | null;
21
+ /** The block node holding the function's statements. */
22
+ bodyOf(fn: Node): Node | null;
23
+ /** Statements directly inside a block. */
24
+ statementsOf(block: Node): Node[];
25
+ /** The callee name of a call expression, e.g. `foo` for `a.foo(x)`. */
26
+ calleeOf(call: Node): string | null;
27
+ /** The expression a return statement returns, if any. */
28
+ returnValueOf(ret: Node): Node | null;
29
+ /** Leaf node types that are names (variables, fields, types). */
30
+ identifierTypes: ReadonlySet<string>;
31
+ /** An identifier that is never a name to rename or pair by (Swift: names inside attributes such as `@State`). */
32
+ notAName?(id: Node): boolean;
33
+ /**
34
+ * Named declarations directly inside `container` (the file, or a class body),
35
+ * with the node to treat as the whole declaration and, for classes, the body
36
+ * that holds its members.
37
+ */
38
+ declarationsIn(container: Node): Declaration[];
39
+ /**
40
+ * Node types that hold the lines just above a declaration and belong to it:
41
+ * comments, and attributes such as Rust's `#[derive(..)]`.
42
+ */
43
+ attachedTypes: ReadonlySet<string>;
44
+ /**
45
+ * Tokens the grammar reports as missing on trees that are in fact correct (Kotlin's
46
+ * `_class_member_semi` on one-line class bodies). Any other missing token or error means the
47
+ * code does not parse, and no formatting claim is made about it.
48
+ */
49
+ harmlessMissing?: ReadonlySet<string>;
50
+ /**
51
+ * An error node the grammar makes around correct code (Swift 0.7.3: a `#else` or `#endif` line between a
52
+ * declaration's attributes, or a zero-width error before a directive in a type body). Code holding only such
53
+ * errors still counts as parsed for formatting claims.
54
+ */
55
+ harmlessError?(n: Node): boolean;
56
+ /**
57
+ * What the code at a line means depends on more than its own text (the namespace in effect, a
58
+ * visibility section): a move from one context to another is an edit, never a plain move.
59
+ */
60
+ contextAt?(root: Node, line: number): string;
61
+ /**
62
+ * The position of an item on the line whose order means something (Kotlin's constructor parameters, enum
63
+ * entries): a move that changes it is an edit. Unlike contextAt, wrapping a list onto lines changes nothing here.
64
+ */
65
+ positionAt?(root: Node, line: number): string;
66
+ /**
67
+ * Compare a claim's contexts range by range, in line order with runs collapsed, instead of
68
+ * requiring one context on each side: a whole Kotlin class moved with its doc comment and
69
+ * companion object keeps its move. Languages without it keep the one-context rule.
70
+ */
71
+ contextRuns?: boolean;
72
+ /**
73
+ * Claims this language does not make yet: their lines are shown as plain edits. Ruby holds back
74
+ * moved-with-edits in v1 (3 of its 29 on the held-out set were wrong); so does Kotlin (too few
75
+ * held-out claims, 5, to measure).
76
+ */
77
+ holdBack?: ReadonlySet<string>;
78
+ /**
79
+ * The type whose members a container holds, when members of one type can sit in several containers
80
+ * (Swift: a struct and its extensions). Those containers share one member scope, so a member moved
81
+ * from one to another pairs and is moved.
82
+ */
83
+ typeOf?(container: Declaration): string | null;
84
+ /**
85
+ * Of two declarations that swapped places, call the edited one moved and keep the unchanged one in
86
+ * place, so an unchanged declaration is never named as the move while its edited neighbour moved.
87
+ * Swift only for now: turning it on for the languages scored before it would change their results.
88
+ */
89
+ moveEditedFirst?: boolean;
90
+ /**
91
+ * What sits on a declaration and changes how it behaves rather than what it does (Swift attributes:
92
+ * `@State` to `@Binding`, a wrapper added or removed). A declaration whose marks changed is edited,
93
+ * never moved.
94
+ */
95
+ marksOf?(decl: Node): string;
96
+ }
97
+ /** The node holds an error, or a missing token that is not harmless for its language. */
98
+ export declare function brokenTree(n: Node, cfg: LanguageConfig): boolean;
99
+ /**
100
+ * Imports are declarations too, named by what they import (the module path), so
101
+ * re-sorted imports pair up and show as moved rather than deleted and re-added.
102
+ * Adding a language's imports takes only the key: the text of its module path.
103
+ */
104
+ export declare const importDeclaration: (node: Node, key: string, prefix?: string) => Declaration;
105
+ export interface Declaration {
106
+ node: Node;
107
+ kind: string;
108
+ name: string;
109
+ members?: Node;
110
+ /** The last node the declaration covers when that is not `node` itself (a Ruby heredoc body after it). */
111
+ tail?: Node;
112
+ }
113
+ /** The type written before a declaration's name (`String` in `fun String.shout()`), if any. */
114
+ export declare const kotlinReceiver: (n: Node) => Node | null;
115
+ export declare const LANGUAGES: Record<LanguageId, LanguageConfig>;
116
+ export declare function getParser(id: LanguageId): Promise<Parser>;
117
+ /** Parse both versions, run `fn`, and always free the trees (they live in WASM memory). */
118
+ export declare function withTrees<T>(id: LanguageId, oldText: string, newText: string, fn: (oldTree: Tree, newTree: Tree) => T): Promise<T>;