@descent-vtt/spec-guard 0.3.0 → 0.5.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.
- package/CHANGELOG.md +125 -0
- package/README.md +292 -49
- package/dist/cli.d.ts +9 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +46 -7
- package/dist/cli.js.map +1 -1
- package/dist/comments.d.ts +23 -4
- package/dist/comments.d.ts.map +1 -1
- package/dist/comments.js +40 -14
- package/dist/comments.js.map +1 -1
- package/dist/engine.d.ts +52 -49
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +185 -259
- package/dist/engine.js.map +1 -1
- package/dist/glob.d.ts +19 -6
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +14 -28
- package/dist/glob.js.map +1 -1
- package/dist/imports.d.ts +28 -4
- package/dist/imports.d.ts.map +1 -1
- package/dist/imports.js +36 -4
- package/dist/imports.js.map +1 -1
- package/dist/index.d.ts +15 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +28 -23
- package/dist/parser.js.map +1 -1
- package/dist/polyglot.d.ts +129 -0
- package/dist/polyglot.d.ts.map +1 -0
- package/dist/polyglot.js +544 -0
- package/dist/polyglot.js.map +1 -0
- package/dist/reporter.d.ts +41 -0
- package/dist/reporter.d.ts.map +1 -1
- package/dist/reporter.js +187 -4
- package/dist/reporter.js.map +1 -1
- package/dist/runner.d.ts +47 -3
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +371 -105
- package/dist/runner.js.map +1 -1
- package/dist/scope.d.ts +108 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +115 -0
- package/dist/scope.js.map +1 -0
- package/dist/text.d.ts +26 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +69 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +87 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGxG,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,aAAa,EACb,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAWrB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,OAAO,EACP,SAAS,GACV,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,aAAa,EACb,aAAa,EACb,2BAA2B,EAC3B,kBAAkB,EAClB,eAAe,EACf,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,QAAQ,EACR,qBAAqB,EACrB,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,eAAe,EACf,aAAa,EACb,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EACf,MAAM,EACN,aAAa,EACb,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGzE,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAA4C,WAAW,EAAkB,MAAM,YAAY,CAAC;AAyExG,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAwD/C;AAMD,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUrE;AAED,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,WAAW,CAkDlF"}
|
package/dist/parser.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* error rather than silently skipped - a typo must never turn into a
|
|
15
15
|
* silently-passing invariant.
|
|
16
16
|
*/
|
|
17
|
+
import { lineStarts, locate } from './text.js';
|
|
17
18
|
const KINDS = new Set([
|
|
18
19
|
'assert-absence',
|
|
19
20
|
'assert-count',
|
|
@@ -34,6 +35,9 @@ const ALLOWED_ATTRIBUTES = {
|
|
|
34
35
|
'regex',
|
|
35
36
|
'word',
|
|
36
37
|
'ignore-case',
|
|
38
|
+
'allow-empty',
|
|
39
|
+
'baseline',
|
|
40
|
+
'ratchet',
|
|
37
41
|
'reason',
|
|
38
42
|
]),
|
|
39
43
|
'assert-count': new Set([
|
|
@@ -48,11 +52,33 @@ const ALLOWED_ATTRIBUTES = {
|
|
|
48
52
|
'regex',
|
|
49
53
|
'word',
|
|
50
54
|
'ignore-case',
|
|
55
|
+
'allow-empty',
|
|
51
56
|
'reason',
|
|
52
57
|
]),
|
|
53
58
|
'assert-present': new Set(['file', 'reason']),
|
|
54
|
-
'assert-import-absence': new Set([
|
|
55
|
-
|
|
59
|
+
'assert-import-absence': new Set([
|
|
60
|
+
'target',
|
|
61
|
+
'module',
|
|
62
|
+
'exclude',
|
|
63
|
+
'types',
|
|
64
|
+
'expected',
|
|
65
|
+
'max',
|
|
66
|
+
'allow-empty',
|
|
67
|
+
'baseline',
|
|
68
|
+
'ratchet',
|
|
69
|
+
'reason',
|
|
70
|
+
]),
|
|
71
|
+
'assert-import-count': new Set([
|
|
72
|
+
'target',
|
|
73
|
+
'module',
|
|
74
|
+
'exclude',
|
|
75
|
+
'types',
|
|
76
|
+
'expected',
|
|
77
|
+
'min',
|
|
78
|
+
'max',
|
|
79
|
+
'allow-empty',
|
|
80
|
+
'reason',
|
|
81
|
+
]),
|
|
56
82
|
};
|
|
57
83
|
const DIRECTIVE_RE = /<!--\s*@([a-zA-Z][\w-]*)([\s\S]*?)-->/g;
|
|
58
84
|
const ATTRIBUTE_RE = /([a-zA-Z][\w-]*)(?:\s*=\s*(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)'|([^\s"'=<>`]+)))?/g;
|
|
@@ -116,27 +142,6 @@ export function maskCode(source) {
|
|
|
116
142
|
}
|
|
117
143
|
return chars.join('');
|
|
118
144
|
}
|
|
119
|
-
/** Pre-computed line starts, for O(log n) offset -> line/column resolution. */
|
|
120
|
-
function lineStarts(source) {
|
|
121
|
-
const starts = [0];
|
|
122
|
-
for (let i = 0; i < source.length; i++) {
|
|
123
|
-
if (source[i] === '\n')
|
|
124
|
-
starts.push(i + 1);
|
|
125
|
-
}
|
|
126
|
-
return starts;
|
|
127
|
-
}
|
|
128
|
-
function locate(starts, index) {
|
|
129
|
-
let low = 0;
|
|
130
|
-
let high = starts.length - 1;
|
|
131
|
-
while (low < high) {
|
|
132
|
-
const mid = (low + high + 1) >> 1;
|
|
133
|
-
if (starts[mid] <= index)
|
|
134
|
-
low = mid;
|
|
135
|
-
else
|
|
136
|
-
high = mid - 1;
|
|
137
|
-
}
|
|
138
|
-
return { line: low + 1, column: index - starts[low] + 1 };
|
|
139
|
-
}
|
|
140
145
|
function unescape(value) {
|
|
141
146
|
return value.replace(/\\(.)/g, '$1');
|
|
142
147
|
}
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAG/C,MAAM,KAAK,GAAG,IAAI,GAAG,CAAS;IAC5B,gBAAgB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GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,kBAAkB,CAAC,IAAqB,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7E,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,IAAI,CAAC;gBACV,QAAQ;gBACR,GAAG;gBACH,OAAO,EAAE,oBAAoB,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,OAAO;qBAClE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC;qBAC1B,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,cAAc,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;aAClE,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAqB,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-reference extraction for Python, Go, Rust and C#.
|
|
3
|
+
*
|
|
4
|
+
* The JavaScript analyser in `imports.ts` is a full tokenizer because it has to
|
|
5
|
+
* be: a module reference can appear anywhere in an expression, `/` is division
|
|
6
|
+
* or a regular expression depending on context, and template literals nest
|
|
7
|
+
* arbitrarily. None of that is true here. In these four languages an import is
|
|
8
|
+
* a statement, its shape is fixed, and the only thing that can disguise one is
|
|
9
|
+
* a comment or a string literal.
|
|
10
|
+
*
|
|
11
|
+
* spec-guard already has something that finds comments and string literals in
|
|
12
|
+
* nine language families, and it is the most adversarially tested code in the
|
|
13
|
+
* project. So this module does not add four more tokenizers. It masks the
|
|
14
|
+
* source with the existing lexer and then reads statements off what is left:
|
|
15
|
+
*
|
|
16
|
+
* source -> lexRanges (comments.ts) -> masked code -> per-language statement reader
|
|
17
|
+
*
|
|
18
|
+
* That is the whole architecture, and it is the reason four languages cost
|
|
19
|
+
* about as much as one.
|
|
20
|
+
*
|
|
21
|
+
* The alternative was Tree-sitter, and the reason it lost is size: its runtime
|
|
22
|
+
* plus grammars for these four languages measures 94 MB unpacked against this
|
|
23
|
+
* package's 0.33 MB. What that buys is real - a parser knows about
|
|
24
|
+
* conditional compilation and macro expansion, and this does not - so the
|
|
25
|
+
* places where it would be more accurate are listed in ADR-0008 rather than
|
|
26
|
+
* waved away. None of them is an import that this misreads; they are imports
|
|
27
|
+
* this cannot see, and every one of them is reported.
|
|
28
|
+
*
|
|
29
|
+
* Which is the invariant from ADR-0005, carried over unchanged: **a reference
|
|
30
|
+
* this module cannot resolve becomes a note, never silence**. A dependency
|
|
31
|
+
* rule that quietly ignores what it did not understand is a rule that passes
|
|
32
|
+
* for the wrong reason.
|
|
33
|
+
*/
|
|
34
|
+
import type { FileImports } from './imports.js';
|
|
35
|
+
/** Languages this module reads. JavaScript and TypeScript live in `imports.ts`. */
|
|
36
|
+
export type ModuleLanguage = 'python' | 'go' | 'rust' | 'csharp';
|
|
37
|
+
/** Extension to language. The single place a new language is switched on. */
|
|
38
|
+
export declare const POLYGLOT_EXTENSIONS: ReadonlyMap<string, ModuleLanguage>;
|
|
39
|
+
/** The language for a path, or null when this module does not read it. */
|
|
40
|
+
export declare function languageFor(filePath: string): ModuleLanguage | null;
|
|
41
|
+
/**
|
|
42
|
+
* Largest number of module paths one statement may expand to.
|
|
43
|
+
*
|
|
44
|
+
* Rust's brace groups nest, and nesting multiplies: `use a::{b::{c,d}, e::{f,g}}`
|
|
45
|
+
* is four paths from twelve characters, and the growth is exponential in depth.
|
|
46
|
+
* A file that nests twenty levels deep is not a file anyone wrote, but it is a
|
|
47
|
+
* file somebody could commit, and the failure mode without a cap is an
|
|
48
|
+
* out-of-memory kill in CI rather than an error message. Hitting the cap is
|
|
49
|
+
* reported as a note, so the statement is never silently half-read.
|
|
50
|
+
*/
|
|
51
|
+
export declare const MAX_EXPANSION = 64;
|
|
52
|
+
/**
|
|
53
|
+
* Which comment profile each language is read with.
|
|
54
|
+
*
|
|
55
|
+
* Keyed by language rather than by extension on purpose: the caller has already
|
|
56
|
+
* decided what this file is, and looking the answer up a second way is how the
|
|
57
|
+
* two answers get to disagree. A test asserts these agree with the
|
|
58
|
+
* extension-based lookup for every extension this module claims.
|
|
59
|
+
*/
|
|
60
|
+
export declare const SYNTAX_NAMES: Record<ModuleLanguage, string>;
|
|
61
|
+
/** Strips the delimiters off a literal as the lexer captured it. */
|
|
62
|
+
export declare function literalValue(raw: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Whitespace-skipping cursor over masked code.
|
|
65
|
+
*
|
|
66
|
+
* Exported so its edges can be pinned directly. Reaching "what does peek() do
|
|
67
|
+
* at the end of the file" through a C# source string is possible but says
|
|
68
|
+
* nothing about C#.
|
|
69
|
+
*/
|
|
70
|
+
export declare class Reader {
|
|
71
|
+
readonly text: string;
|
|
72
|
+
index: number;
|
|
73
|
+
constructor(text: string);
|
|
74
|
+
skipSpace(): void;
|
|
75
|
+
peek(): string;
|
|
76
|
+
eat(token: string): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Eats a word only when it really is the whole word.
|
|
79
|
+
*
|
|
80
|
+
* `eat('static')` also matches the first six characters of a namespace called
|
|
81
|
+
* `staticfiles`, and would then read the dependency as `files`.
|
|
82
|
+
*/
|
|
83
|
+
keyword(word: string): boolean;
|
|
84
|
+
identifier(): string;
|
|
85
|
+
/** Reads `a.b.c`, treating `::` as a separator too (C# alias qualifiers). */
|
|
86
|
+
dotted(): string;
|
|
87
|
+
/** Skips a balanced `<...>`, so a generic alias target does not end the read. */
|
|
88
|
+
skipGenerics(): void;
|
|
89
|
+
}
|
|
90
|
+
/** Offset of the matching close, given the depth-tracking characters. */
|
|
91
|
+
export declare function matchingClose(text: string, open: number, opener: string, closer: string): number;
|
|
92
|
+
/**
|
|
93
|
+
* Groups physical lines into the logical lines Python actually executes.
|
|
94
|
+
*
|
|
95
|
+
* A statement continues while a bracket is open or the line ends in a
|
|
96
|
+
* backslash, and `from x import (\n a,\n b,\n)` is the shape that matters
|
|
97
|
+
* here. Lines are joined with a space so two tokens cannot fuse into one.
|
|
98
|
+
*/
|
|
99
|
+
export declare function logicalLines(code: string): Array<{
|
|
100
|
+
text: string;
|
|
101
|
+
offset: number;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Expands one `use` path into the module paths it actually names.
|
|
105
|
+
*
|
|
106
|
+
* `a::{b, c::{d, e}}` is three dependencies written as one statement, and a
|
|
107
|
+
* rule about `a::c` has to see them. Returns null when the expansion would
|
|
108
|
+
* exceed MAX_EXPANSION, which the caller reports rather than truncating.
|
|
109
|
+
*/
|
|
110
|
+
export declare function expandUsePath(input: string): string[] | null;
|
|
111
|
+
/**
|
|
112
|
+
* Rewrites a specifier into the `/`-separated form module patterns match.
|
|
113
|
+
*
|
|
114
|
+
* Every language names modules with its own separator - `a.b.c`, `a::b::c`,
|
|
115
|
+
* `a/b/c` - and a rule author should not have to know which one a given file
|
|
116
|
+
* uses. One notation, and the raw specifier stays matchable too, so a pattern
|
|
117
|
+
* written either way finds the dependency.
|
|
118
|
+
*
|
|
119
|
+
* Python's relative imports resolve against the importing file, the same path
|
|
120
|
+
* arithmetic (and the same refusal to touch the filesystem) as ADR-0005.
|
|
121
|
+
* Rust's `self::` and `super::` deliberately do not: resolving them needs the
|
|
122
|
+
* module tree, the module tree needs to know where inline `mod` blocks are, and
|
|
123
|
+
* that needs a parser. They are matched literally instead, and ADR-0008 says so
|
|
124
|
+
* out loud rather than leaving a rule to quietly miss them.
|
|
125
|
+
*/
|
|
126
|
+
export declare function normalizeModule(specifier: string, importingFile: string, language: ModuleLanguage): string;
|
|
127
|
+
/** Extracts every module reference from a Python, Go, Rust or C# source file. */
|
|
128
|
+
export declare function analyzePolyglot(source: string, file: string, language: ModuleLanguage): FileImports;
|
|
129
|
+
//# sourceMappingURL=polyglot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyglot.d.ts","sourceRoot":"","sources":["../src/polyglot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAMH,OAAO,KAAK,EAAgB,WAAW,EAAkC,MAAM,cAAc,CAAC;AAE9F,mFAAmF;AACnF,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,IAAI,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEjE,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAOlE,CAAC;AAEH,0EAA0E;AAC1E,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAEnE;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,KAAK,CAAC;AAehC;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAKvD,CAAC;AAsCF,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAUhD;AAMD;;;;;;GAMG;AACH,qBAAa,MAAM;IAGL,QAAQ,CAAC,IAAI,EAAE,MAAM;IAFjC,KAAK,SAAK;IAEV,YAAqB,IAAI,EAAE,MAAM,EAAI;IAErC,SAAS,IAAI,IAAI,CAShB;IAED,IAAI,IAAI,MAAM,CAEb;IAED,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAI1B;IAED;;;;;OAKG;IACH,OAAO,CAAC,IAA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