@keithadler/frostjs 0.1.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/LICENSE +21 -0
- package/README.md +568 -0
- package/dist/baseline.d.ts +18 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +56 -0
- package/dist/baseline.js.map +1 -0
- package/dist/changed.d.ts +15 -0
- package/dist/changed.d.ts.map +1 -0
- package/dist/changed.js +93 -0
- package/dist/changed.js.map +1 -0
- package/dist/cli/args.d.ts +37 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +200 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +8 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +404 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/discover/index.d.ts +15 -0
- package/dist/discover/index.d.ts.map +1 -0
- package/dist/discover/index.js +70 -0
- package/dist/discover/index.js.map +1 -0
- package/dist/eslint.d.ts +103 -0
- package/dist/eslint.d.ts.map +1 -0
- package/dist/eslint.js +111 -0
- package/dist/eslint.js.map +1 -0
- package/dist/extract/annotations.d.ts +5 -0
- package/dist/extract/annotations.d.ts.map +1 -0
- package/dist/extract/annotations.js +5 -0
- package/dist/extract/annotations.js.map +1 -0
- package/dist/extract/ast.d.ts +45 -0
- package/dist/extract/ast.d.ts.map +1 -0
- package/dist/extract/ast.js +60 -0
- package/dist/extract/ast.js.map +1 -0
- package/dist/extract/capability.d.ts +22 -0
- package/dist/extract/capability.d.ts.map +1 -0
- package/dist/extract/capability.js +2 -0
- package/dist/extract/capability.js.map +1 -0
- package/dist/extract/html.d.ts +15 -0
- package/dist/extract/html.d.ts.map +1 -0
- package/dist/extract/html.js +69 -0
- package/dist/extract/html.js.map +1 -0
- package/dist/extract/index.d.ts +9 -0
- package/dist/extract/index.d.ts.map +1 -0
- package/dist/extract/index.js +95 -0
- package/dist/extract/index.js.map +1 -0
- package/dist/extract/recognizers/codegen.d.ts +10 -0
- package/dist/extract/recognizers/codegen.d.ts.map +1 -0
- package/dist/extract/recognizers/codegen.js +39 -0
- package/dist/extract/recognizers/codegen.js.map +1 -0
- package/dist/extract/recognizers/dom-escape.d.ts +11 -0
- package/dist/extract/recognizers/dom-escape.d.ts.map +1 -0
- package/dist/extract/recognizers/dom-escape.js +58 -0
- package/dist/extract/recognizers/dom-escape.js.map +1 -0
- package/dist/extract/recognizers/globals.d.ts +9 -0
- package/dist/extract/recognizers/globals.d.ts.map +1 -0
- package/dist/extract/recognizers/globals.js +121 -0
- package/dist/extract/recognizers/globals.js.map +1 -0
- package/dist/extract/recognizers/identity.d.ts +10 -0
- package/dist/extract/recognizers/identity.d.ts.map +1 -0
- package/dist/extract/recognizers/identity.js +79 -0
- package/dist/extract/recognizers/identity.js.map +1 -0
- package/dist/extract/recognizers/navigation.d.ts +12 -0
- package/dist/extract/recognizers/navigation.d.ts.map +1 -0
- package/dist/extract/recognizers/navigation.js +110 -0
- package/dist/extract/recognizers/navigation.js.map +1 -0
- package/dist/extract/recognizers/network.d.ts +11 -0
- package/dist/extract/recognizers/network.d.ts.map +1 -0
- package/dist/extract/recognizers/network.js +41 -0
- package/dist/extract/recognizers/network.js.map +1 -0
- package/dist/extract/recognizers/resolve.d.ts +37 -0
- package/dist/extract/recognizers/resolve.d.ts.map +1 -0
- package/dist/extract/recognizers/resolve.js +72 -0
- package/dist/extract/recognizers/resolve.js.map +1 -0
- package/dist/extract/recognizers/storage.d.ts +9 -0
- package/dist/extract/recognizers/storage.d.ts.map +1 -0
- package/dist/extract/recognizers/storage.js +37 -0
- package/dist/extract/recognizers/storage.js.map +1 -0
- package/dist/extract/recognizers/types.d.ts +38 -0
- package/dist/extract/recognizers/types.d.ts.map +1 -0
- package/dist/extract/recognizers/types.js +25 -0
- package/dist/extract/recognizers/types.js.map +1 -0
- package/dist/extract/recognizers/worker.d.ts +11 -0
- package/dist/extract/recognizers/worker.d.ts.map +1 -0
- package/dist/extract/recognizers/worker.js +41 -0
- package/dist/extract/recognizers/worker.js.map +1 -0
- package/dist/extract/scope.d.ts +23 -0
- package/dist/extract/scope.d.ts.map +1 -0
- package/dist/extract/scope.js +299 -0
- package/dist/extract/scope.js.map +1 -0
- package/dist/extract/suppress.d.ts +21 -0
- package/dist/extract/suppress.d.ts.map +1 -0
- package/dist/extract/suppress.js +42 -0
- package/dist/extract/suppress.js.map +1 -0
- package/dist/extract/target.d.ts +34 -0
- package/dist/extract/target.d.ts.map +1 -0
- package/dist/extract/target.js +81 -0
- package/dist/extract/target.js.map +1 -0
- package/dist/extract/typescript.d.ts +12 -0
- package/dist/extract/typescript.d.ts.map +1 -0
- package/dist/extract/typescript.js +56 -0
- package/dist/extract/typescript.js.map +1 -0
- package/dist/extract/walk.d.ts +14 -0
- package/dist/extract/walk.d.ts.map +1 -0
- package/dist/extract/walk.js +70 -0
- package/dist/extract/walk.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +10 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +79 -0
- package/dist/init.js.map +1 -0
- package/dist/policy/compile.d.ts +56 -0
- package/dist/policy/compile.d.ts.map +1 -0
- package/dist/policy/compile.js +78 -0
- package/dist/policy/compile.js.map +1 -0
- package/dist/policy/config.d.ts +18 -0
- package/dist/policy/config.d.ts.map +1 -0
- package/dist/policy/config.js +70 -0
- package/dist/policy/config.js.map +1 -0
- package/dist/policy/csp.d.ts +19 -0
- package/dist/policy/csp.d.ts.map +1 -0
- package/dist/policy/csp.js +47 -0
- package/dist/policy/csp.js.map +1 -0
- package/dist/policy/glob.d.ts +12 -0
- package/dist/policy/glob.d.ts.map +1 -0
- package/dist/policy/glob.js +63 -0
- package/dist/policy/glob.js.map +1 -0
- package/dist/policy/index.d.ts +47 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +34 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/parse.d.ts +51 -0
- package/dist/policy/parse.d.ts.map +1 -0
- package/dist/policy/parse.js +352 -0
- package/dist/policy/parse.js.map +1 -0
- package/dist/policy/vocabulary.d.ts +15 -0
- package/dist/policy/vocabulary.d.ts.map +1 -0
- package/dist/policy/vocabulary.js +99 -0
- package/dist/policy/vocabulary.js.map +1 -0
- package/dist/registry.d.ts +45 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +85 -0
- package/dist/registry.js.map +1 -0
- package/dist/report/github.d.ts +10 -0
- package/dist/report/github.d.ts.map +1 -0
- package/dist/report/github.js +31 -0
- package/dist/report/github.js.map +1 -0
- package/dist/report/json.d.ts +44 -0
- package/dist/report/json.d.ts.map +1 -0
- package/dist/report/json.js +40 -0
- package/dist/report/json.js.map +1 -0
- package/dist/report/sarif.d.ts +10 -0
- package/dist/report/sarif.d.ts.map +1 -0
- package/dist/report/sarif.js +64 -0
- package/dist/report/sarif.js.map +1 -0
- package/dist/report/summary.d.ts +9 -0
- package/dist/report/summary.d.ts.map +1 -0
- package/dist/report/summary.js +67 -0
- package/dist/report/summary.js.map +1 -0
- package/dist/report/text.d.ts +37 -0
- package/dist/report/text.d.ts.map +1 -0
- package/dist/report/text.js +81 -0
- package/dist/report/text.js.map +1 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +131 -0
- package/dist/sync.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Recognizer } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Client-side persistence: the storage globals (bare or via the global
|
|
4
|
+
* object), `document.cookie` read or written, and `navigator.storage`.
|
|
5
|
+
* Any reference counts, including `typeof localStorage`, because a
|
|
6
|
+
* feature check is still a reach for the capability.
|
|
7
|
+
*/
|
|
8
|
+
export declare const storage: Recognizer;
|
|
9
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/extract/recognizers/storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAWpD;;;;;GAKG;AACH,eAAO,MAAM,OAAO,EAAE,UAmBrB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { match } from "./types.js";
|
|
2
|
+
import { asGlobalIn, asNamedGlobal, memberName } from "./resolve.js";
|
|
3
|
+
/** Globals that are themselves storage handles. A Map, so prototype names never match. */
|
|
4
|
+
const STORAGE_GLOBALS = new Map([
|
|
5
|
+
["localStorage", "storage.local"],
|
|
6
|
+
["sessionStorage", "storage.session"],
|
|
7
|
+
["indexedDB", "storage.indexeddb"],
|
|
8
|
+
["caches", "storage.cache"],
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* Client-side persistence: the storage globals (bare or via the global
|
|
12
|
+
* object), `document.cookie` read or written, and `navigator.storage`.
|
|
13
|
+
* Any reference counts, including `typeof localStorage`, because a
|
|
14
|
+
* feature check is still a reach for the capability.
|
|
15
|
+
*/
|
|
16
|
+
export const storage = ({ node, binding }) => {
|
|
17
|
+
if (binding)
|
|
18
|
+
return null;
|
|
19
|
+
const n = node;
|
|
20
|
+
const g = asGlobalIn(n, new Set(STORAGE_GLOBALS.keys()));
|
|
21
|
+
if (g)
|
|
22
|
+
return match(STORAGE_GLOBALS.get(g.name), g.r, node);
|
|
23
|
+
if (n.type !== "MemberExpression")
|
|
24
|
+
return null;
|
|
25
|
+
const prop = memberName(n);
|
|
26
|
+
const obj = n["object"];
|
|
27
|
+
if (prop === "cookie") {
|
|
28
|
+
const r = asNamedGlobal(obj, "document");
|
|
29
|
+
return r ? match("storage.cookie", r, node) : null;
|
|
30
|
+
}
|
|
31
|
+
if (prop === "storage") {
|
|
32
|
+
const r = asNamedGlobal(obj, "navigator");
|
|
33
|
+
return r ? match("storage.navigator", r, node) : null;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/extract/recognizers/storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAErE,0FAA0F;AAC1F,MAAM,eAAe,GAAgC,IAAI,GAAG,CAAC;IAC3D,CAAC,cAAc,EAAE,eAAe,CAAC;IACjC,CAAC,gBAAgB,EAAE,iBAAiB,CAAC;IACrC,CAAC,WAAW,EAAE,mBAAmB,CAAC;IAClC,CAAC,QAAQ,EAAE,eAAe,CAAC;CAC5B,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAe,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;IACvD,IAAI,OAAO;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,CAAC,GAAG,IAAe,CAAC;IAE1B,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACzD,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAE7D,IAAI,CAAC,CAAC,IAAI,KAAK,kBAAkB;QAAE,OAAO,IAAI,CAAC;IAC/C,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAY,CAAC;IACnC,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QACzC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACxD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AnyNode, Node } from "../ast.js";
|
|
2
|
+
import type { Visit } from "../walk.js";
|
|
3
|
+
import type { Confidence } from "../capability.js";
|
|
4
|
+
/** A resolved reference to a global: the confidence, and the identifier node the resolution rests on. */
|
|
5
|
+
export interface Resolved {
|
|
6
|
+
confidence: Confidence;
|
|
7
|
+
via: Node | null;
|
|
8
|
+
}
|
|
9
|
+
export interface Match {
|
|
10
|
+
/** Stable code, e.g. "storage.local". */
|
|
11
|
+
capability: string;
|
|
12
|
+
/** Resolved destination for network-like uses, else null. */
|
|
13
|
+
target: string | null;
|
|
14
|
+
confidence: Confidence;
|
|
15
|
+
/** The node the match is anchored on; the reported expression grows outward from here. */
|
|
16
|
+
node: Node;
|
|
17
|
+
/** The identifier the match rests on (`localStorage`, `window`...), or null if none. A local binding of it means no match. */
|
|
18
|
+
via: Node | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A recognizer sees every node with its ancestors and whether it sits in a
|
|
22
|
+
* binding position, and returns a Match or null. It pattern-matches on
|
|
23
|
+
* shape only; whether `via` is shadowed is decided afterwards from the
|
|
24
|
+
* scope annotations.
|
|
25
|
+
*/
|
|
26
|
+
export type Recognizer = (v: Visit) => Match | null;
|
|
27
|
+
/** Build a Match from a resolved global reference. */
|
|
28
|
+
export declare function match(capability: string, r: Resolved, node: Node, target?: string | null): Match;
|
|
29
|
+
/** A Match that rests on no identifier (JSX syntax, dynamic import, a property write on any object). */
|
|
30
|
+
export declare function plain(capability: string, node: Node, target?: string | null): Match;
|
|
31
|
+
/**
|
|
32
|
+
* If `node` is the callee of its parent call (or `new`, when allowed),
|
|
33
|
+
* return the call's arguments; otherwise null.
|
|
34
|
+
*/
|
|
35
|
+
export declare function callArgs(node: Node, parent: AnyNode | undefined, allowNew?: boolean): AnyNode[] | null;
|
|
36
|
+
/** The value of a string literal node, else null. Templates and folds are deliberately not accepted here. */
|
|
37
|
+
export declare function stringValue(n: AnyNode | undefined): string | null;
|
|
38
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/extract/recognizers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,yGAAyG;AACzG,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,UAAU,CAAC;IACvB,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,KAAK;IACpB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;IACvB,0FAA0F;IAC1F,IAAI,EAAE,IAAI,CAAC;IACX,8HAA8H;IAC9H,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,KAAK,GAAG,IAAI,CAAC;AAEpD,sDAAsD;AACtD,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,MAAM,GAAG,IAAW,GAAG,KAAK,CAEtG;AAED,wGAAwG;AACxG,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,MAAM,GAAG,IAAW,GAAG,KAAK,CAEzF;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,EAAE,QAAQ,UAAQ,GAAG,OAAO,EAAE,GAAG,IAAI,CAMpG;AAED,6GAA6G;AAC7G,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAEjE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Build a Match from a resolved global reference. */
|
|
2
|
+
export function match(capability, r, node, target = null) {
|
|
3
|
+
return { capability, target, confidence: r.confidence, via: r.via, node };
|
|
4
|
+
}
|
|
5
|
+
/** A Match that rests on no identifier (JSX syntax, dynamic import, a property write on any object). */
|
|
6
|
+
export function plain(capability, node, target = null) {
|
|
7
|
+
return { capability, target, confidence: "certain", via: null, node };
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* If `node` is the callee of its parent call (or `new`, when allowed),
|
|
11
|
+
* return the call's arguments; otherwise null.
|
|
12
|
+
*/
|
|
13
|
+
export function callArgs(node, parent, allowNew = false) {
|
|
14
|
+
if (!parent || parent["callee"] !== node)
|
|
15
|
+
return null;
|
|
16
|
+
if (parent.type === "CallExpression" || (allowNew && parent.type === "NewExpression")) {
|
|
17
|
+
return parent["arguments"];
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
/** The value of a string literal node, else null. Templates and folds are deliberately not accepted here. */
|
|
22
|
+
export function stringValue(n) {
|
|
23
|
+
return n?.type === "Literal" && typeof n["value"] === "string" ? n["value"] : null;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/extract/recognizers/types.ts"],"names":[],"mappings":"AA8BA,sDAAsD;AACtD,MAAM,UAAU,KAAK,CAAC,UAAkB,EAAE,CAAW,EAAE,IAAU,EAAE,SAAwB,IAAI;IAC7F,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;AAC5E,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,KAAK,CAAC,UAAkB,EAAE,IAAU,EAAE,SAAwB,IAAI;IAChF,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACxE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAU,EAAE,MAA2B,EAAE,QAAQ,GAAG,KAAK;IAChF,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACtD,IAAI,MAAM,CAAC,IAAI,KAAK,gBAAgB,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,eAAe,CAAC,EAAE,CAAC;QACtF,OAAO,MAAM,CAAC,WAAW,CAAc,CAAC;IAC1C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,WAAW,CAAC,CAAsB;IAChD,OAAO,CAAC,EAAE,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Recognizer } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Code that runs off the main thread or intercepts requests: Worker and
|
|
4
|
+
* SharedWorker (bare or via the global object, target from the script
|
|
5
|
+
* URL), navigator.serviceWorker.register, and worklet addModule. A service
|
|
6
|
+
* worker has the largest blast radius of anything here: once registered it
|
|
7
|
+
* sees every future request from the origin. Reading serviceWorker state
|
|
8
|
+
* is not a use.
|
|
9
|
+
*/
|
|
10
|
+
export declare const worker: Recognizer;
|
|
11
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/extract/recognizers/worker.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAW9D;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,EAAE,UAoBpB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { callArgs, match } from "./types.js";
|
|
2
|
+
import { asGlobalIn, asNamedGlobal, memberName } from "./resolve.js";
|
|
3
|
+
import { resolveTargetOf } from "../target.js";
|
|
4
|
+
const WORKER_GLOBALS = new Map([
|
|
5
|
+
["Worker", "worker.dedicated"],
|
|
6
|
+
["SharedWorker", "worker.shared"],
|
|
7
|
+
]);
|
|
8
|
+
const WORKER_NAMES = new Set(WORKER_GLOBALS.keys());
|
|
9
|
+
const WORKLETS = new Set(["paintWorklet", "audioWorklet", "animationWorklet", "layoutWorklet"]);
|
|
10
|
+
/**
|
|
11
|
+
* Code that runs off the main thread or intercepts requests: Worker and
|
|
12
|
+
* SharedWorker (bare or via the global object, target from the script
|
|
13
|
+
* URL), navigator.serviceWorker.register, and worklet addModule. A service
|
|
14
|
+
* worker has the largest blast radius of anything here: once registered it
|
|
15
|
+
* sees every future request from the origin. Reading serviceWorker state
|
|
16
|
+
* is not a use.
|
|
17
|
+
*/
|
|
18
|
+
export const worker = ({ node, ancestors, binding }) => {
|
|
19
|
+
if (binding)
|
|
20
|
+
return null;
|
|
21
|
+
const n = node;
|
|
22
|
+
const args = callArgs(node, ancestors[0], true);
|
|
23
|
+
const firstArg = () => resolveTargetOf(args?.[0]);
|
|
24
|
+
const g = asGlobalIn(n, WORKER_NAMES);
|
|
25
|
+
if (g)
|
|
26
|
+
return match(WORKER_GLOBALS.get(g.name), g.r, node, args ? firstArg() : null);
|
|
27
|
+
if (n.type !== "MemberExpression" || !args)
|
|
28
|
+
return null;
|
|
29
|
+
const prop = memberName(n);
|
|
30
|
+
const obj = n["object"];
|
|
31
|
+
if (prop === "register" && obj.type === "MemberExpression" && memberName(obj) === "serviceWorker") {
|
|
32
|
+
const r = asNamedGlobal(obj["object"], "navigator");
|
|
33
|
+
if (r)
|
|
34
|
+
return match("worker.service", r, node, firstArg());
|
|
35
|
+
}
|
|
36
|
+
if (prop === "addModule" && obj.type === "MemberExpression" && WORKLETS.has(memberName(obj) ?? "")) {
|
|
37
|
+
return { capability: "worker.worklet", target: firstArg(), confidence: "certain", via: null, node };
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/extract/recognizers/worker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAmB,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,aAAa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AAM,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAY,CAAC;IACnC,IAAI,IAAI,KAAK,UAAU,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,IAAI,UAAU,CAAC,GAAG,CAAC,KAAK,eAAe,EAAE,CAAC;QAClG,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAY,EAAE,WAAW,CAAC,CAAC;QAC/D,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC,gBAAgB,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,IAAI,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QACnG,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACtG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lexical scope analysis. Answers one question for every identifier in
|
|
3
|
+
* reference position: does it resolve to a local binding, or is it free
|
|
4
|
+
* (and therefore a reference to a global)? Also folds `const k = "..."`
|
|
5
|
+
* so that `window[k]` can be recognized.
|
|
6
|
+
*
|
|
7
|
+
* Hoisting is honored: `var` and function declarations bind for their
|
|
8
|
+
* whole function, `let`/`const`/`class` for their whole block, regardless
|
|
9
|
+
* of where the reference sits. A reference inside `with` is unresolvable
|
|
10
|
+
* and is reported as ambiguous.
|
|
11
|
+
*/
|
|
12
|
+
import { type Node } from "./ast.js";
|
|
13
|
+
export interface ScopeInfo {
|
|
14
|
+
/** Reference-position identifiers that resolve to no local binding. */
|
|
15
|
+
free: ReadonlySet<Node>;
|
|
16
|
+
/** Reference-position identifiers inside a `with` block. */
|
|
17
|
+
ambiguous: ReadonlySet<Node>;
|
|
18
|
+
/** Reference-position identifiers bound by `const x = "literal"`, with the literal. */
|
|
19
|
+
constants: ReadonlyMap<Node, string>;
|
|
20
|
+
}
|
|
21
|
+
/** Resolve every reference-position identifier in the program; see the module comment. */
|
|
22
|
+
export declare function analyzeScopes(program: Node): ScopeInfo;
|
|
23
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/extract/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAwB,KAAK,IAAI,EAAE,MAAM,UAAU,CAAC;AAG3D,MAAM,WAAW,SAAS;IACxB,uEAAuE;IACvE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACxB,4DAA4D;IAC5D,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7B,uFAAuF;IACvF,SAAS,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;CACtC;AA+CD,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,OAAO,EAAE,IAAI,GAAG,SAAS,CA8OtD"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lexical scope analysis. Answers one question for every identifier in
|
|
3
|
+
* reference position: does it resolve to a local binding, or is it free
|
|
4
|
+
* (and therefore a reference to a global)? Also folds `const k = "..."`
|
|
5
|
+
* so that `window[k]` can be recognized.
|
|
6
|
+
*
|
|
7
|
+
* Hoisting is honored: `var` and function declarations bind for their
|
|
8
|
+
* whole function, `let`/`const`/`class` for their whole block, regardless
|
|
9
|
+
* of where the reference sits. A reference inside `with` is unresolvable
|
|
10
|
+
* and is reported as ambiguous.
|
|
11
|
+
*/
|
|
12
|
+
import { isNode } from "./ast.js";
|
|
13
|
+
import { isTypeOnly } from "./typescript.js";
|
|
14
|
+
class Scope {
|
|
15
|
+
parent;
|
|
16
|
+
isFunction;
|
|
17
|
+
names = new Map();
|
|
18
|
+
constructor(parent, isFunction) {
|
|
19
|
+
this.parent = parent;
|
|
20
|
+
this.isFunction = isFunction;
|
|
21
|
+
}
|
|
22
|
+
declare(name, binding) {
|
|
23
|
+
// A name declared twice in one scope is never folded: the second
|
|
24
|
+
// declaration replaces the first with no initializer.
|
|
25
|
+
if (!this.names.has(name))
|
|
26
|
+
this.names.set(name, binding);
|
|
27
|
+
else
|
|
28
|
+
this.names.set(name, { kind: binding.kind, init: null });
|
|
29
|
+
}
|
|
30
|
+
nearestFunction() {
|
|
31
|
+
let s = this;
|
|
32
|
+
while (!s.isFunction && s.parent)
|
|
33
|
+
s = s.parent;
|
|
34
|
+
return s;
|
|
35
|
+
}
|
|
36
|
+
resolve(name) {
|
|
37
|
+
let s = this;
|
|
38
|
+
while (s) {
|
|
39
|
+
const b = s.names.get(name);
|
|
40
|
+
if (b)
|
|
41
|
+
return b;
|
|
42
|
+
s = s.parent;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Resolve every reference-position identifier in the program; see the module comment. */
|
|
48
|
+
export function analyzeScopes(program) {
|
|
49
|
+
const refs = [];
|
|
50
|
+
const root = new Scope(null, true);
|
|
51
|
+
const visit = (node, scope, ambiguous) => {
|
|
52
|
+
if (isTypeOnly(node))
|
|
53
|
+
return;
|
|
54
|
+
switch (node.type) {
|
|
55
|
+
case "Identifier":
|
|
56
|
+
refs.push({ node, scope, ambiguous });
|
|
57
|
+
return;
|
|
58
|
+
case "TSEnumDeclaration": {
|
|
59
|
+
scope.declare(node["id"]["name"], { kind: "let", init: null });
|
|
60
|
+
const body = node["body"];
|
|
61
|
+
for (const m of (body["members"] ?? [])) {
|
|
62
|
+
const init = m["initializer"];
|
|
63
|
+
if (init)
|
|
64
|
+
visit(init, scope, ambiguous);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
case "TSModuleDeclaration": {
|
|
69
|
+
const id = node["id"];
|
|
70
|
+
if (id.type === "Identifier")
|
|
71
|
+
scope.declare(id["name"], { kind: "let", init: null });
|
|
72
|
+
const body = node["body"];
|
|
73
|
+
if (body)
|
|
74
|
+
visitChildren(body, new Scope(scope, true), ambiguous);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
case "JSXIdentifier":
|
|
78
|
+
case "JSXText":
|
|
79
|
+
case "JSXMemberExpression":
|
|
80
|
+
case "JSXNamespacedName":
|
|
81
|
+
return;
|
|
82
|
+
case "JSXAttribute":
|
|
83
|
+
if (isNode(node["value"]))
|
|
84
|
+
visit(node["value"], scope, ambiguous);
|
|
85
|
+
return;
|
|
86
|
+
case "FunctionDeclaration": {
|
|
87
|
+
const id = node["id"];
|
|
88
|
+
if (id)
|
|
89
|
+
scope.nearestFunction().declare(id["name"], { kind: "function", init: null });
|
|
90
|
+
visitFunction(node, new Scope(scope, true), ambiguous);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
case "FunctionExpression": {
|
|
94
|
+
const fn = new Scope(scope, true);
|
|
95
|
+
const id = node["id"];
|
|
96
|
+
if (id)
|
|
97
|
+
fn.declare(id["name"], { kind: "function", init: null });
|
|
98
|
+
visitFunction(node, fn, ambiguous);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
case "ArrowFunctionExpression":
|
|
102
|
+
visitFunction(node, new Scope(scope, true), ambiguous);
|
|
103
|
+
return;
|
|
104
|
+
case "ClassDeclaration": {
|
|
105
|
+
const id = node["id"];
|
|
106
|
+
if (id)
|
|
107
|
+
scope.declare(id["name"], { kind: "class", init: null });
|
|
108
|
+
visitClass(node, scope, ambiguous);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
case "ClassExpression": {
|
|
112
|
+
const inner = new Scope(scope, false);
|
|
113
|
+
const id = node["id"];
|
|
114
|
+
if (id)
|
|
115
|
+
inner.declare(id["name"], { kind: "class", init: null });
|
|
116
|
+
visitClass(node, inner, ambiguous);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
case "BlockStatement":
|
|
120
|
+
case "SwitchStatement":
|
|
121
|
+
visitChildren(node, new Scope(scope, false), ambiguous, ["discriminant"]);
|
|
122
|
+
return;
|
|
123
|
+
case "StaticBlock":
|
|
124
|
+
visitChildren(node, new Scope(scope, true), ambiguous);
|
|
125
|
+
return;
|
|
126
|
+
case "ForStatement":
|
|
127
|
+
case "ForInStatement":
|
|
128
|
+
case "ForOfStatement":
|
|
129
|
+
visitChildren(node, new Scope(scope, false), ambiguous);
|
|
130
|
+
return;
|
|
131
|
+
case "CatchClause": {
|
|
132
|
+
const inner = new Scope(scope, false);
|
|
133
|
+
const param = node["param"];
|
|
134
|
+
if (param)
|
|
135
|
+
declarePattern(param, inner, "catch", null, ambiguous);
|
|
136
|
+
visit(node["body"], inner, ambiguous);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
case "VariableDeclaration": {
|
|
140
|
+
const kind = node["kind"];
|
|
141
|
+
const target = kind === "var" ? scope.nearestFunction() : scope;
|
|
142
|
+
const bkind = kind === "var" ? "var" : kind === "const" ? "const" : "let";
|
|
143
|
+
for (const d of node["declarations"]) {
|
|
144
|
+
const init = d["init"];
|
|
145
|
+
declarePattern(d["id"], target, bkind, init, ambiguous);
|
|
146
|
+
if (init)
|
|
147
|
+
visit(init, scope, ambiguous);
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
case "ImportDeclaration":
|
|
152
|
+
for (const s of node["specifiers"]) {
|
|
153
|
+
if (isTypeOnly(s))
|
|
154
|
+
continue;
|
|
155
|
+
root.declare(s["local"]["name"], { kind: "import", init: null });
|
|
156
|
+
}
|
|
157
|
+
return;
|
|
158
|
+
case "ExportSpecifier":
|
|
159
|
+
visit(node["local"], scope, ambiguous);
|
|
160
|
+
return;
|
|
161
|
+
case "ExportAllDeclaration":
|
|
162
|
+
return;
|
|
163
|
+
case "WithStatement":
|
|
164
|
+
visit(node["object"], scope, ambiguous);
|
|
165
|
+
visit(node["body"], scope, true);
|
|
166
|
+
return;
|
|
167
|
+
case "MemberExpression":
|
|
168
|
+
visit(node["object"], scope, ambiguous);
|
|
169
|
+
if (node["computed"] === true)
|
|
170
|
+
visit(node["property"], scope, ambiguous);
|
|
171
|
+
return;
|
|
172
|
+
case "Property":
|
|
173
|
+
case "MethodDefinition":
|
|
174
|
+
case "PropertyDefinition":
|
|
175
|
+
case "AccessorProperty":
|
|
176
|
+
visitDecorators(node, scope, ambiguous);
|
|
177
|
+
if (node["computed"] === true)
|
|
178
|
+
visit(node["key"], scope, ambiguous);
|
|
179
|
+
if (isNode(node["value"]))
|
|
180
|
+
visit(node["value"], scope, ambiguous);
|
|
181
|
+
return;
|
|
182
|
+
case "LabeledStatement":
|
|
183
|
+
visit(node["body"], scope, ambiguous);
|
|
184
|
+
return;
|
|
185
|
+
case "BreakStatement":
|
|
186
|
+
case "ContinueStatement":
|
|
187
|
+
return;
|
|
188
|
+
case "MetaProperty":
|
|
189
|
+
return;
|
|
190
|
+
default:
|
|
191
|
+
visitChildren(node, scope, ambiguous);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
const visitChildren = (node, scope, ambiguous, first = []) => {
|
|
195
|
+
const keys = [...first, ...Object.keys(node).filter((k) => !first.includes(k))];
|
|
196
|
+
for (const key of keys) {
|
|
197
|
+
if (key === "type" || key === "start" || key === "end")
|
|
198
|
+
continue;
|
|
199
|
+
const value = node[key];
|
|
200
|
+
if (Array.isArray(value)) {
|
|
201
|
+
for (const item of value)
|
|
202
|
+
if (isNode(item))
|
|
203
|
+
visit(item, scope, ambiguous);
|
|
204
|
+
}
|
|
205
|
+
else if (isNode(value)) {
|
|
206
|
+
visit(value, scope, ambiguous);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const visitFunction = (node, fn, ambiguous) => {
|
|
211
|
+
for (const p of node["params"])
|
|
212
|
+
declarePattern(p, fn, "param", null, ambiguous);
|
|
213
|
+
const body = node["body"];
|
|
214
|
+
// The body block shares the function scope so params and body locals can clash correctly.
|
|
215
|
+
if (body.type === "BlockStatement")
|
|
216
|
+
visitChildren(body, fn, ambiguous);
|
|
217
|
+
else
|
|
218
|
+
visit(body, fn, ambiguous);
|
|
219
|
+
};
|
|
220
|
+
const visitDecorators = (node, scope, ambiguous) => {
|
|
221
|
+
for (const d of (node["decorators"] ?? []))
|
|
222
|
+
visit(d["expression"], scope, ambiguous);
|
|
223
|
+
};
|
|
224
|
+
const visitClass = (node, scope, ambiguous) => {
|
|
225
|
+
visitDecorators(node, scope, ambiguous);
|
|
226
|
+
const sup = node["superClass"];
|
|
227
|
+
if (sup)
|
|
228
|
+
visit(sup, scope, ambiguous);
|
|
229
|
+
visit(node["body"], scope, ambiguous);
|
|
230
|
+
};
|
|
231
|
+
/** Declare every identifier in a binding pattern; default values are expressions. */
|
|
232
|
+
const declarePattern = (p, scope, kind, init, ambiguous) => {
|
|
233
|
+
switch (p.type) {
|
|
234
|
+
case "Identifier":
|
|
235
|
+
visitDecorators(p, scope, ambiguous);
|
|
236
|
+
scope.declare(p["name"], { kind, init });
|
|
237
|
+
return;
|
|
238
|
+
case "ObjectPattern":
|
|
239
|
+
for (const prop of p["properties"]) {
|
|
240
|
+
if (prop.type === "RestElement")
|
|
241
|
+
declarePattern(prop["argument"], scope, kind, null, ambiguous);
|
|
242
|
+
else {
|
|
243
|
+
if (prop["computed"] === true)
|
|
244
|
+
visit(prop["key"], scope, ambiguous);
|
|
245
|
+
declarePattern(prop["value"], scope, kind, null, ambiguous);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return;
|
|
249
|
+
case "ArrayPattern":
|
|
250
|
+
for (const el of p["elements"])
|
|
251
|
+
if (el)
|
|
252
|
+
declarePattern(el, scope, kind, null, ambiguous);
|
|
253
|
+
return;
|
|
254
|
+
case "AssignmentPattern":
|
|
255
|
+
declarePattern(p["left"], scope, kind, null, ambiguous);
|
|
256
|
+
visit(p["right"], scope, ambiguous);
|
|
257
|
+
return;
|
|
258
|
+
case "RestElement":
|
|
259
|
+
declarePattern(p["argument"], scope, kind, null, ambiguous);
|
|
260
|
+
return;
|
|
261
|
+
case "TSParameterProperty":
|
|
262
|
+
visitDecorators(p, scope, ambiguous);
|
|
263
|
+
declarePattern(p["parameter"], scope, kind, null, ambiguous);
|
|
264
|
+
return;
|
|
265
|
+
default:
|
|
266
|
+
visitChildren(p, scope, ambiguous);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
visitChildren(program, root, false);
|
|
270
|
+
const free = new Set();
|
|
271
|
+
const ambiguous = new Set();
|
|
272
|
+
const constants = new Map();
|
|
273
|
+
for (const ref of refs) {
|
|
274
|
+
if (ref.ambiguous) {
|
|
275
|
+
ambiguous.add(ref.node);
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const b = ref.scope.resolve(ref.node["name"]);
|
|
279
|
+
if (b === null) {
|
|
280
|
+
free.add(ref.node);
|
|
281
|
+
}
|
|
282
|
+
else if (b.kind === "const" && b.init) {
|
|
283
|
+
const v = stringLiteral(b.init);
|
|
284
|
+
if (v !== null)
|
|
285
|
+
constants.set(ref.node, v);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return { free, ambiguous, constants };
|
|
289
|
+
}
|
|
290
|
+
/** The value of a string literal or expression-free template, else null. */
|
|
291
|
+
function stringLiteral(n) {
|
|
292
|
+
if (n.type === "Literal" && typeof n["value"] === "string")
|
|
293
|
+
return n["value"];
|
|
294
|
+
if (n.type === "TemplateLiteral" && n["expressions"].length === 0) {
|
|
295
|
+
return n["quasis"][0]?.["value"]?.cooked ?? null;
|
|
296
|
+
}
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.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AAS,aAAa,CAAC,CAAU;IAC/B,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;IAC9E,IAAI,CAAC,CAAC,IAAI,KAAK,iBAAiB,IAAK,CAAC,CAAC,aAAa,CAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjF,OAAS,CAAC,CAAC,QAAQ,CAAe,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAqC,EAAE,MAAM,IAAI,IAAI,CAAC;IACvG,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline suppression:
|
|
3
|
+
*
|
|
4
|
+
* // frostjs: ignore suppress every capability on this line
|
|
5
|
+
* // frostjs: ignore[storage.local, net] suppress the listed codes or families
|
|
6
|
+
*
|
|
7
|
+
* A comment applies to uses on its own line, or, when the comment is alone on
|
|
8
|
+
* its line, to uses starting on the next line.
|
|
9
|
+
*/
|
|
10
|
+
import type { ParsedFile } from "./ast.js";
|
|
11
|
+
export interface Suppression {
|
|
12
|
+
/** A bare `frostjs: ignore`: every capability on the line. */
|
|
13
|
+
all: boolean;
|
|
14
|
+
/** Codes or families listed in brackets. */
|
|
15
|
+
codes: string[];
|
|
16
|
+
}
|
|
17
|
+
/** Line number -> suppression in force for uses starting on that line. */
|
|
18
|
+
export declare function suppressions(parsed: ParsedFile): Map<number, Suppression>;
|
|
19
|
+
/** True when the suppression covers the capability: exactly, or by its family (`storage` covers `storage.local`). */
|
|
20
|
+
export declare function isSuppressed(s: Suppression | undefined, capability: string): boolean;
|
|
21
|
+
//# sourceMappingURL=suppress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suppress.d.ts","sourceRoot":"","sources":["../../src/extract/suppress.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG3C,MAAM,WAAW,WAAW;IAC1B,8DAA8D;IAC9D,GAAG,EAAE,OAAO,CAAC;IACb,4CAA4C;IAC5C,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAID,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAgBzE;AAcD,qHAAqH;AACrH,wBAAgB,YAAY,CAAC,CAAC,EAAE,WAAW,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAIpF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { positionAt } from "./ast.js";
|
|
2
|
+
const MARKER = /^\s*frostjs:\s*ignore(?:\[([^\]]*)\])?\s*$/;
|
|
3
|
+
/** Line number -> suppression in force for uses starting on that line. */
|
|
4
|
+
export function suppressions(parsed) {
|
|
5
|
+
const out = new Map();
|
|
6
|
+
for (const c of parsed.comments) {
|
|
7
|
+
const m = MARKER.exec(c.value);
|
|
8
|
+
if (!m)
|
|
9
|
+
continue;
|
|
10
|
+
const spec = m[1] === undefined ? { all: true, codes: [] } : { all: false, codes: splitCodes(m[1]) };
|
|
11
|
+
const { line } = positionAt(parsed.lines, c.start);
|
|
12
|
+
// Does anything other than whitespace precede the comment on its line?
|
|
13
|
+
const lineStart = parsed.lines[line - 1];
|
|
14
|
+
const alone = parsed.source.slice(lineStart, c.start).trim() === "";
|
|
15
|
+
const endLine = positionAt(parsed.lines, c.end).line;
|
|
16
|
+
const rest = parsed.source.slice(c.end, parsed.lines[endLine] ?? parsed.source.length).trim();
|
|
17
|
+
out.set(line, merge(out.get(line), spec));
|
|
18
|
+
if (alone && rest === "")
|
|
19
|
+
out.set(endLine + 1, merge(out.get(endLine + 1), spec));
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function splitCodes(s) {
|
|
24
|
+
return s
|
|
25
|
+
.split(",")
|
|
26
|
+
.map((c) => c.trim())
|
|
27
|
+
.filter(Boolean);
|
|
28
|
+
}
|
|
29
|
+
function merge(a, b) {
|
|
30
|
+
if (!a)
|
|
31
|
+
return b;
|
|
32
|
+
return { all: a.all || b.all, codes: [...a.codes, ...b.codes] };
|
|
33
|
+
}
|
|
34
|
+
/** True when the suppression covers the capability: exactly, or by its family (`storage` covers `storage.local`). */
|
|
35
|
+
export function isSuppressed(s, capability) {
|
|
36
|
+
if (!s)
|
|
37
|
+
return false;
|
|
38
|
+
if (s.all)
|
|
39
|
+
return true;
|
|
40
|
+
return s.codes.some((c) => c === capability || capability.startsWith(c + "."));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=suppress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suppress.js","sourceRoot":"","sources":["../../src/extract/suppress.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAStC,MAAM,MAAM,GAAG,4CAA4C,CAAC;AAE5D,0EAA0E;AAC1E,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC3C,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,CAAC,CAAC;YAAE,SAAS;QACjB,MAAM,IAAI,GAAgB,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAClH,MAAM,EAAE,IAAI,E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