@mnemonik/shared 7.152.1 → 7.153.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/dist/vueSource.d.ts +2 -0
- package/dist/vueSource.d.ts.map +1 -1
- package/dist/vueSource.js +17 -3
- package/dist/vueSource.js.map +1 -1
- package/package.json +1 -1
- package/src/vueSource.ts +23 -3
package/dist/vueSource.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type VueTemplateNode = TemplateRoot | TemplateRoot['children'][number];
|
|
|
7
7
|
type ParsedVueSource = {
|
|
8
8
|
descriptor: SFCDescriptor;
|
|
9
9
|
nodeTypes: typeof import('@vue/compiler-core').NodeTypes;
|
|
10
|
+
/** Set on the sanitation path only; the template walk throws past it. */
|
|
11
|
+
templateNodeLimit?: number;
|
|
10
12
|
};
|
|
11
13
|
export declare function parseVueSource(source: string, forSanitation?: boolean): Promise<ParsedVueSource | {
|
|
12
14
|
reason: string;
|
package/dist/vueSource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vueSource.d.ts","sourceRoot":"","sources":["../src/vueSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"vueSource.d.ts","sourceRoot":"","sources":["../src/vueSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD,+EAA+E;AAC/E,eAAO,MAAM,mBAAmB,sDAAsD,CAAC;AACvF,KAAK,YAAY,GAAG,WAAW,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/E,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9E,sFAAsF;AACtF,KAAK,eAAe,GAAG;IACrB,UAAU,EAAE,aAAa,CAAC;IAC1B,SAAS,EAAE,cAAc,oBAAoB,EAAE,SAAS,CAAC;IACzD,yEAAyE;IACzE,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAUF,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,aAAa,UAAQ,GACpB,OAAO,CAAC,eAAe,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAuC/C;AAED,2FAA2F;AAC3F,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,EACvB,KAAK,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,GACtD,IAAI,CAuBN"}
|
package/dist/vueSource.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { MAX_AST_PARSE_BYTES } from './ast/astChunker.js';
|
|
2
|
+
import { MAX_SCANNED_FILE_BYTES } from './codeScanner.js';
|
|
2
3
|
/** A fallback scrub may repair syntax; it must never become graph evidence. */
|
|
3
4
|
export const VUE_FIDELITY_MARKER = '<!-- mnemonik:vue-source-fidelity-unavailable -->';
|
|
5
|
+
/**
|
|
6
|
+
* Sanitation runs on the API server's event loop (scan push, file push, documents), and
|
|
7
|
+
* its edit loop costs the file's length per edit, so it keeps the 2 MiB and 200,000-node
|
|
8
|
+
* bounds until it moves off that loop. Connected-code reads run in the parse pool and
|
|
9
|
+
* take any file up to the product's 10 MB ceiling.
|
|
10
|
+
*/
|
|
11
|
+
const SANITATION_MAX_BYTES = MAX_AST_PARSE_BYTES;
|
|
12
|
+
const SANITATION_TEMPLATE_NODE_LIMIT = 200_000;
|
|
4
13
|
export async function parseVueSource(source, forSanitation = false) {
|
|
5
14
|
// Sanitation still inspects marked bytes; graph extraction must continue to reject them.
|
|
6
15
|
if (!forSanitation && source.includes(VUE_FIDELITY_MARKER))
|
|
7
16
|
return { reason: 'vue_source_fidelity_unavailable' };
|
|
8
|
-
if (Buffer.byteLength(source, 'utf8') >
|
|
17
|
+
if (Buffer.byteLength(source, 'utf8') >
|
|
18
|
+
(forSanitation ? SANITATION_MAX_BYTES : MAX_SCANNED_FILE_BYTES))
|
|
9
19
|
return { reason: 'file_too_large' };
|
|
10
20
|
let clearCache;
|
|
11
21
|
try {
|
|
@@ -27,7 +37,9 @@ export async function parseVueSource(source, forSanitation = false) {
|
|
|
27
37
|
(descriptor.template?.lang && descriptor.template.lang !== 'html') ||
|
|
28
38
|
descriptor.customBlocks.length)
|
|
29
39
|
return { reason: 'vue_preprocessor_or_custom_block_unsupported' };
|
|
30
|
-
return
|
|
40
|
+
return forSanitation
|
|
41
|
+
? { descriptor, nodeTypes, templateNodeLimit: SANITATION_TEMPLATE_NODE_LIMIT }
|
|
42
|
+
: { descriptor, nodeTypes };
|
|
31
43
|
}
|
|
32
44
|
catch {
|
|
33
45
|
return { reason: 'vue_parse_failed' };
|
|
@@ -43,12 +55,14 @@ export function walkVueTemplate(parsed, visit) {
|
|
|
43
55
|
const pending = descriptor.template?.ast
|
|
44
56
|
? [{ node: descriptor.template.ast, scoped: false }]
|
|
45
57
|
: [];
|
|
58
|
+
// Iterative and linear in the template's nodes; only sanitation is bounded by count.
|
|
59
|
+
const limit = parsed.templateNodeLimit ?? Infinity;
|
|
46
60
|
let count = 0;
|
|
47
61
|
while (pending.length) {
|
|
48
62
|
const item = pending.pop();
|
|
49
63
|
if (!item)
|
|
50
64
|
break;
|
|
51
|
-
if (++count >
|
|
65
|
+
if (++count > limit)
|
|
52
66
|
throw new Error('vue_template_work_limit');
|
|
53
67
|
const { node } = item;
|
|
54
68
|
const scoped = item.scoped ||
|
package/dist/vueSource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vueSource.js","sourceRoot":"","sources":["../src/vueSource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,+EAA+E;AAC/E,MAAM,CAAC,MAAM,mBAAmB,G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} from './ast/astChunker.js';
|
|
3
|
+
import { MAX_SCANNED_FILE_BYTES } from './codeScanner.js';
|
|
3
4
|
|
|
4
5
|
/** A fallback scrub may repair syntax; it must never become graph evidence. */
|
|
5
6
|
export const VUE_FIDELITY_MARKER = '<!-- mnemonik:vue-source-fidelity-unavailable -->';
|
|
@@ -10,7 +11,18 @@ export type VueTemplateNode = TemplateRoot | TemplateRoot['children'][number];
|
|
|
10
11
|
type ParsedVueSource = {
|
|
11
12
|
descriptor: SFCDescriptor;
|
|
12
13
|
nodeTypes: typeof import('@vue/compiler-core').NodeTypes;
|
|
14
|
+
/** Set on the sanitation path only; the template walk throws past it. */
|
|
15
|
+
templateNodeLimit?: number;
|
|
13
16
|
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sanitation runs on the API server's event loop (scan push, file push, documents), and
|
|
20
|
+
* its edit loop costs the file's length per edit, so it keeps the 2 MiB and 200,000-node
|
|
21
|
+
* bounds until it moves off that loop. Connected-code reads run in the parse pool and
|
|
22
|
+
* take any file up to the product's 10 MB ceiling.
|
|
23
|
+
*/
|
|
24
|
+
const SANITATION_MAX_BYTES = MAX_AST_PARSE_BYTES;
|
|
25
|
+
const SANITATION_TEMPLATE_NODE_LIMIT = 200_000;
|
|
14
26
|
export async function parseVueSource(
|
|
15
27
|
source: string,
|
|
16
28
|
forSanitation = false
|
|
@@ -18,7 +30,11 @@ export async function parseVueSource(
|
|
|
18
30
|
// Sanitation still inspects marked bytes; graph extraction must continue to reject them.
|
|
19
31
|
if (!forSanitation && source.includes(VUE_FIDELITY_MARKER))
|
|
20
32
|
return { reason: 'vue_source_fidelity_unavailable' };
|
|
21
|
-
if (
|
|
33
|
+
if (
|
|
34
|
+
Buffer.byteLength(source, 'utf8') >
|
|
35
|
+
(forSanitation ? SANITATION_MAX_BYTES : MAX_SCANNED_FILE_BYTES)
|
|
36
|
+
)
|
|
37
|
+
return { reason: 'file_too_large' };
|
|
22
38
|
let clearCache: (() => void) | undefined;
|
|
23
39
|
try {
|
|
24
40
|
// Most shared consumers never scan Vue; do not load the compiler on their startup path.
|
|
@@ -40,7 +56,9 @@ export async function parseVueSource(
|
|
|
40
56
|
descriptor.customBlocks.length
|
|
41
57
|
)
|
|
42
58
|
return { reason: 'vue_preprocessor_or_custom_block_unsupported' };
|
|
43
|
-
return
|
|
59
|
+
return forSanitation
|
|
60
|
+
? { descriptor, nodeTypes, templateNodeLimit: SANITATION_TEMPLATE_NODE_LIMIT }
|
|
61
|
+
: { descriptor, nodeTypes };
|
|
44
62
|
} catch {
|
|
45
63
|
return { reason: 'vue_parse_failed' };
|
|
46
64
|
} finally {
|
|
@@ -58,11 +76,13 @@ export function walkVueTemplate(
|
|
|
58
76
|
const pending: Array<{ node: VueTemplateNode; scoped: boolean }> = descriptor.template?.ast
|
|
59
77
|
? [{ node: descriptor.template.ast, scoped: false }]
|
|
60
78
|
: [];
|
|
79
|
+
// Iterative and linear in the template's nodes; only sanitation is bounded by count.
|
|
80
|
+
const limit = parsed.templateNodeLimit ?? Infinity;
|
|
61
81
|
let count = 0;
|
|
62
82
|
while (pending.length) {
|
|
63
83
|
const item = pending.pop();
|
|
64
84
|
if (!item) break;
|
|
65
|
-
if (++count >
|
|
85
|
+
if (++count > limit) throw new Error('vue_template_work_limit');
|
|
66
86
|
const { node } = item;
|
|
67
87
|
const scoped =
|
|
68
88
|
item.scoped ||
|