browser-requirements 0.0.0-stage → 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.
Files changed (106) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +248 -2
  3. package/dist/analysis/analyze.d.ts +14 -0
  4. package/dist/analysis/analyze.js +67 -0
  5. package/dist/analysis/analyze.js.map +1 -0
  6. package/dist/analysis/ast.d.ts +12 -0
  7. package/dist/analysis/ast.js +21 -0
  8. package/dist/analysis/ast.js.map +1 -0
  9. package/dist/analysis/context.d.ts +17 -0
  10. package/dist/analysis/context.js +2 -0
  11. package/dist/analysis/context.js.map +1 -0
  12. package/dist/analysis/detectors/builtins.d.ts +8 -0
  13. package/dist/analysis/detectors/builtins.js +68 -0
  14. package/dist/analysis/detectors/builtins.js.map +1 -0
  15. package/dist/analysis/detectors/syntax.d.ts +6 -0
  16. package/dist/analysis/detectors/syntax.js +79 -0
  17. package/dist/analysis/detectors/syntax.js.map +1 -0
  18. package/dist/analysis/detectors/web-apis.d.ts +12 -0
  19. package/dist/analysis/detectors/web-apis.js +30 -0
  20. package/dist/analysis/detectors/web-apis.js.map +1 -0
  21. package/dist/analysis/files.d.ts +9 -0
  22. package/dist/analysis/files.js +60 -0
  23. package/dist/analysis/files.js.map +1 -0
  24. package/dist/analysis/guards.d.ts +9 -0
  25. package/dist/analysis/guards.js +41 -0
  26. package/dist/analysis/guards.js.map +1 -0
  27. package/dist/analysis/parse.d.ts +21 -0
  28. package/dist/analysis/parse.js +43 -0
  29. package/dist/analysis/parse.js.map +1 -0
  30. package/dist/analysis/scope.d.ts +11 -0
  31. package/dist/analysis/scope.js +31 -0
  32. package/dist/analysis/scope.js.map +1 -0
  33. package/dist/analysis/walk.d.ts +9 -0
  34. package/dist/analysis/walk.js +168 -0
  35. package/dist/analysis/walk.js.map +1 -0
  36. package/dist/analysis/writes.d.ts +6 -0
  37. package/dist/analysis/writes.js +16 -0
  38. package/dist/analysis/writes.js.map +1 -0
  39. package/dist/bin/cli.d.ts +2 -0
  40. package/dist/bin/cli.js +114 -0
  41. package/dist/bin/cli.js.map +1 -0
  42. package/dist/config/load.d.ts +14 -0
  43. package/dist/config/load.js +95 -0
  44. package/dist/config/load.js.map +1 -0
  45. package/dist/config/suppressions.d.ts +16 -0
  46. package/dist/config/suppressions.js +60 -0
  47. package/dist/config/suppressions.js.map +1 -0
  48. package/dist/data/browsers.d.ts +8 -0
  49. package/dist/data/browsers.js +49 -0
  50. package/dist/data/browsers.js.map +1 -0
  51. package/dist/data/features.d.ts +14 -0
  52. package/dist/data/features.js +46 -0
  53. package/dist/data/features.js.map +1 -0
  54. package/dist/data/generated/features.json +1 -0
  55. package/dist/data/globals.d.ts +5 -0
  56. package/dist/data/globals.js +22 -0
  57. package/dist/data/globals.js.map +1 -0
  58. package/dist/data/syntax-map.d.ts +10 -0
  59. package/dist/data/syntax-map.js +34 -0
  60. package/dist/data/syntax-map.js.map +1 -0
  61. package/dist/index.d.ts +8 -0
  62. package/dist/index.js +8 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/model/baseline.d.ts +7 -0
  65. package/dist/model/baseline.js +15 -0
  66. package/dist/model/baseline.js.map +1 -0
  67. package/dist/model/compare.d.ts +5 -0
  68. package/dist/model/compare.js +61 -0
  69. package/dist/model/compare.js.map +1 -0
  70. package/dist/model/minimums.d.ts +5 -0
  71. package/dist/model/minimums.js +45 -0
  72. package/dist/model/minimums.js.map +1 -0
  73. package/dist/model/targets.d.ts +12 -0
  74. package/dist/model/targets.js +89 -0
  75. package/dist/model/targets.js.map +1 -0
  76. package/dist/model/types.d.ts +165 -0
  77. package/dist/model/types.js +2 -0
  78. package/dist/model/types.js.map +1 -0
  79. package/dist/model/version.d.ts +9 -0
  80. package/dist/model/version.js +39 -0
  81. package/dist/model/version.js.map +1 -0
  82. package/dist/output/comparison.d.ts +2 -0
  83. package/dist/output/comparison.js +7 -0
  84. package/dist/output/comparison.js.map +1 -0
  85. package/dist/output/index.d.ts +3 -0
  86. package/dist/output/index.js +6 -0
  87. package/dist/output/index.js.map +1 -0
  88. package/dist/output/json.d.ts +3 -0
  89. package/dist/output/json.js +5 -0
  90. package/dist/output/json.js.map +1 -0
  91. package/dist/output/markdown.d.ts +9 -0
  92. package/dist/output/markdown.js +59 -0
  93. package/dist/output/markdown.js.map +1 -0
  94. package/dist/output/style.d.ts +5 -0
  95. package/dist/output/style.js +14 -0
  96. package/dist/output/style.js.map +1 -0
  97. package/dist/output/text.d.ts +9 -0
  98. package/dist/output/text.js +115 -0
  99. package/dist/output/text.js.map +1 -0
  100. package/dist/version.d.ts +2 -0
  101. package/dist/version.js +5 -0
  102. package/dist/version.js.map +1 -0
  103. package/package.json +78 -4
  104. package/schemas/comparison-1.json +44 -0
  105. package/schemas/config-1.json +24 -0
  106. package/schemas/report-1.json +114 -0
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Nossair Ghazouani
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,249 @@
1
- # Temporary Holding Version
1
+ # browser-requirements
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **The minimum browser requirements of your web app, like the system requirements of a video game. And why.**
4
+
5
+ ```text
6
+ $ npx browser-requirements analyze src
7
+
8
+ Minimum browser requirements (source, 2 files, BCD 8.1.12)
9
+
10
+ Browser Minimum Limited by Where
11
+ Chrome 110 Array.prototype.toSorted src/list/sort.ts:3:10
12
+ Edge 110 Array.prototype.toSorted src/list/sort.ts:3:10
13
+ Firefox 115 Array.prototype.toSorted src/list/sort.ts:3:10
14
+ Safari 16 Array.prototype.toSorted src/list/sort.ts:3:10
15
+ Safari on iOS 16 Array.prototype.toSorted src/list/sort.ts:3:10
16
+ Samsung Internet 21.0 Array.prototype.toSorted src/list/sort.ts:3:10
17
+ ...
18
+
19
+ Baseline 2023 (widely available)
20
+ Guarded: 2 · Suppressed: 0 · Skipped files: 0
21
+ ```
22
+
23
+ > **Status: 0.1, milestones 1 and 2.** JavaScript and TypeScript sources and unmapped build output.
24
+ > Source maps, dependency attribution, the manifest and coverage figures come next (see [Roadmap](#roadmap)).
25
+
26
+ ## Why this exists
27
+
28
+ Every web app has minimum browser requirements, but almost nobody knows what theirs are. One
29
+ recent method, such as `array.toSorted()`, is enough to break an app on Safari 15 while it works
30
+ fine on every developer machine.
31
+
32
+ Existing tools check your code against browsers you have already declared. If that is what you
33
+ need, use them:
34
+
35
+ | You want to… | Use |
36
+ | --- | --- |
37
+ | Lint source against the browsers you declared | [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat), [eslint-plugin-baseline-js](https://github.com/3ru/eslint-plugin-baseline-js), [eslint-plugin-es-x](https://github.com/eslint-community/eslint-plugin-es-x) |
38
+ | Check a bundle against the browsers you declared | [es-compat](https://github.com/robatwilliams/es-compat), [es-check](https://github.com/yowainwright/es-check) |
39
+ | Know which Baseline year your project meets | web-features-based CLIs such as `baseline-check` or `baseline-guard` |
40
+ | Know which ECMAScript version your code needs | [fast-brake](https://www.npmjs.com/package/fast-brake) |
41
+ | Polyfill what your targets lack | Babel `preset-env` + core-js (`useBuiltIns: "usage"`) |
42
+
43
+ What none of them gives you is the reverse view, explained and kept up to date:
44
+
45
+ - **"What is the oldest version of each browser that can run this, and why?"** Not yes/no against
46
+ targets you had to guess, and not a single coarse label, but a version per browser with the feature
47
+ that sets it and the line where it is used.
48
+ - **For what ships**, dependencies included, mapped back to source and blamed on the right package.
49
+ - **As a diff on every pull request**: *"This PR raises minimum Safari from 15.4 to 16
50
+ (`toSorted` in `src/list/sort.ts:42`)."*
51
+ - **As a fact libraries can publish**, so apps inherit their requirements: `engines.node`, but for browsers.
52
+
53
+ This tool is complementary to linters: it tells you what targets to declare, and they enforce them.
54
+ Detection is reused from existing open-source work wherever possible; the new parts are computing,
55
+ explaining, diffing, and publishing the minimums.
56
+
57
+ ## Usage
58
+
59
+ Requires Node.js 22.12 or later.
60
+
61
+ ### Find your minimum browsers
62
+
63
+ ```bash
64
+ npx browser-requirements analyze src # text table
65
+ npx browser-requirements analyze src --details # also the next limiting features and every finding
66
+ npx browser-requirements analyze dist --kind output --format json --output report.json
67
+ ```
68
+
69
+ For each browser the report gives the oldest version that **fully** supports every feature used (data
70
+ from MDN browser-compat-data), the feature that sets it, and every place it is used.
71
+
72
+ - Calls whose receiver type cannot be known locally (`list.toSorted()` on a parameter) are *probable*:
73
+ they don't move the headline minimums but are shown as "could rise to Safari 16".
74
+ - Feature checks are recognised and never raise minimums: `'groupBy' in Object`, `typeof x !== 'undefined'`,
75
+ `if (navigator.share)`, `x && x()`, `x?.()`.
76
+ - Strings, comments, local functions with Web API names and TypeScript types never count.
77
+ - Files that fail to parse are listed as skipped, never silently dropped.
78
+
79
+ Browsers: Chrome, Edge, Firefox, Safari, Safari on iOS, Samsung Internet, Opera, Chrome and Firefox for
80
+ Android. Change them with `--browsers chrome,safari` (BCD ids).
81
+
82
+ ### See what a change does
83
+
84
+ ```bash
85
+ npx browser-requirements analyze src --format json --output base.json # on the base branch
86
+ npx browser-requirements analyze src --format json --output head.json # on your branch
87
+ npx browser-requirements compare base.json head.json --format markdown
88
+ ```
89
+
90
+ ```markdown
91
+ | Browser | Before | After | Cause |
92
+ | --- | --- | --- | --- |
93
+ | Safari | 15.4 | ⬆️ **16** | `Array.prototype.toSorted` at `src/list/sort.ts:3` |
94
+ ```
95
+
96
+ When no minimum changes, the output is empty, so it is safe to post as a comment only when there is
97
+ something to say.
98
+
99
+ ### Fail when you exceed your targets
100
+
101
+ ```bash
102
+ npx browser-requirements check src --targets "safari >= 15.4"
103
+ ```
104
+
105
+ ```text
106
+ Targets: safari >= 15.4 (from --targets)
107
+ ✗ Safari 15.4: needs 16
108
+ Array.prototype.toSorted (Safari 16)
109
+ src/list/sort.ts:3:10 return copy.toSorted((a, b) => a.price - b.price);
110
+ 1 target not met
111
+ ```
112
+
113
+ Targets come from `--targets`, then `targets` in the config file, then your project's browserslist
114
+ config, then the browserslist `defaults` query (announced in the output). Exit codes: `0` met,
115
+ `1` not met, `2` usage or configuration error, `3` internal error.
116
+
117
+ ### Configuration and suppressions
118
+
119
+ `browser-requirements.config.json` in the analysed directory or the current directory:
120
+
121
+ ```json
122
+ {
123
+ "$schema": "./node_modules/browser-requirements/schemas/config-1.json",
124
+ "browsers": ["chrome", "safari", "safari_ios", "firefox"],
125
+ "targets": "> 0.5%, not dead",
126
+ "ignore": ["**/*.test.ts"],
127
+ "suppressions": [
128
+ { "feature": "api.structuredClone", "files": ["src/legacy/**"], "reason": "polyfilled with core-js" }
129
+ ]
130
+ }
131
+ ```
132
+
133
+ Or inline, for the next line:
134
+
135
+ ```js
136
+ // browser-requirements-ignore javascript.builtins.Array.toSorted -- polyfilled in src/polyfills.ts
137
+ const sorted = items.toSorted();
138
+ ```
139
+
140
+ A reason is required. Suppressed findings stay in the report with their reason and never count toward
141
+ minimums. Feature ids are MDN browser-compat-data keys, shown in `--format json` output.
142
+
143
+ ### GitHub Action
144
+
145
+ Comments on a pull request when it raises or lowers a minimum, updates the comment on new pushes, and
146
+ deletes it when the change is reverted:
147
+
148
+ ```yaml
149
+ on: pull_request
150
+ permissions:
151
+ contents: read
152
+ pull-requests: write
153
+ jobs:
154
+ browser-requirements:
155
+ runs-on: ubuntu-latest
156
+ steps:
157
+ - uses: actions/checkout@v5
158
+ with: { fetch-depth: 0 }
159
+ - uses: n0ss4/browser-requirements@v0
160
+ with:
161
+ paths: src
162
+ targets: "> 0.5%, not dead" # optional: also fail the job when targets are exceeded
163
+ ```
164
+
165
+ Inputs: `paths`, `kind`, `build-command`, `targets`, `comment`, `github-token`. Outputs: `changed`,
166
+ `report`, `comparison`. The CLI itself never touches git or tokens; other CI systems can run
167
+ `analyze` twice and post `compare --format markdown` themselves.
168
+
169
+ ### Library
170
+
171
+ ```ts
172
+ import { analyze, compare, checkTargets, formatReport } from 'browser-requirements';
173
+
174
+ const report = await analyze({ paths: ['src'] });
175
+ console.log(formatReport(report, 'text'));
176
+ ```
177
+
178
+ Reports follow [`schemas/report-1.json`](schemas/report-1.json); comparisons
179
+ [`schemas/comparison-1.json`](schemas/comparison-1.json). Output is deterministic and records the
180
+ dataset versions used.
181
+
182
+ ## Data sources
183
+
184
+ - [MDN browser-compat-data](https://github.com/mdn/browser-compat-data): per-browser, per-version
185
+ support for every JavaScript built-in and Web API.
186
+ - [web-features](https://github.com/web-platform-dx/web-features): Baseline status ("Baseline
187
+ 2023", "Widely available").
188
+ - [browserslist](https://github.com/browserslist/browserslist) + caniuse-lite: target queries and
189
+ global usage statistics.
190
+
191
+ Every report records the dataset versions it used, so results are reproducible.
192
+
193
+ ## Roadmap
194
+
195
+ | Milestone | Scope | Status |
196
+ | --- | --- | --- |
197
+ | **M1: Minimum browsers** | Per-browser minimums with reasons on JS/TS; JSON report | ✅ 0.1 |
198
+ | **M2: PR diff** | Compare revisions, PR comment when minimums change, target gate, suppressions | ✅ 0.1 |
199
+ | **M3: Ship-aware** | Source maps, dependency attribution, polyfill detection | next |
200
+ | **M4: Manifest** | Standalone manifest spec; generate in libraries, merge in apps | planned |
201
+ | **M5: Impact & exports** | Coverage %, custom usage stats, what-if; browserslist, Baseline label, badge | planned |
202
+ | Later | CSS and HTML features, bundler plugins, runtime guard | to be specified |
203
+
204
+ The full specification is in [`specs/001-browser-requirements-report`](specs/001-browser-requirements-report/spec.md);
205
+ see [docs/VISION.md](docs/VISION.md) for the manifest as a standard, framework and bundler integrations,
206
+ and a runtime "your browser is too old" guard.
207
+
208
+ ## Development
209
+
210
+ This project uses **Spec-Driven Development** with [GitHub Spec Kit](https://github.com/github/spec-kit).
211
+ Specs are the source of truth; code follows them.
212
+
213
+ ```text
214
+ .specify/memory/constitution.md Project principles (read this first)
215
+ specs/NNN-feature/spec.md What and why: user stories, requirements, success criteria
216
+ specs/NNN-feature/plan.md How: architecture and technical decisions (generated by /speckit-plan)
217
+ specs/NNN-feature/tasks.md Ordered, testable tasks (generated by /speckit-tasks)
218
+ ```
219
+
220
+ With Claude Code (or another supported agent), the workflow is:
221
+
222
+ ```text
223
+ /speckit-clarify Resolve open questions in the current spec
224
+ /speckit-plan Produce the technical plan
225
+ /speckit-tasks Break the plan into tasks
226
+ /speckit-implement Build it, task by task
227
+ ```
228
+
229
+ Setup:
230
+
231
+ ```bash
232
+ pnpm install
233
+ pnpm test
234
+ pnpm build
235
+ pnpm dev analyze src # run the CLI from source
236
+ pnpm generate:data # regenerate src/data/generated/features.json from BCD + web-features
237
+ pnpm bench # SC-004 benchmark (downloads typescript@5.9)
238
+ ```
239
+
240
+ Releases: bump `version` in `package.json`, merge, then publish a GitHub release tagged `vX.Y.Z`. The
241
+ [release workflow](.github/workflows/release.yml) runs the checks, publishes to npm with provenance
242
+ (trusted publishing, no stored token) and moves the `v0` tag used by the GitHub Action.
243
+
244
+ Requires Node.js 22.12+ and pnpm. Type checking and builds use TypeScript 7 (the native Go compiler); tests run on Vitest. To refresh Spec Kit templates, install the
245
+ [`specify` CLI](https://github.com/github/spec-kit) and run `specify init --here --integration claude`.
246
+
247
+ ## License
248
+
249
+ ISC
@@ -0,0 +1,14 @@
1
+ import { type BrowserId, type Config, type Report } from '../model/types.js';
2
+ export interface AnalyzeOptions {
3
+ /** Files or directories, relative to `root` or absolute. */
4
+ paths: string[];
5
+ /** Locations are reported relative to this directory. Default: process.cwd(). */
6
+ root?: string;
7
+ browsers?: BrowserId[];
8
+ kind?: 'source' | 'output';
9
+ ignore?: string[];
10
+ /** Configuration object or path to browser-requirements.config.json. Default: looked up (findConfig). */
11
+ config?: Config | string;
12
+ }
13
+ /** Computes the minimum browser requirements of the given code (US1). */
14
+ export declare function analyze(options: AnalyzeOptions): Promise<Report>;
@@ -0,0 +1,67 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { DEFAULT_BROWSERS } from '../data/browsers.js';
4
+ import { byId, datasets } from '../data/features.js';
5
+ import { computeBaseline } from '../model/baseline.js';
6
+ import { computeMinimums } from '../model/minimums.js';
7
+ import { findConfig, loadConfig, validateConfig } from '../config/load.js';
8
+ import { applyConfigSuppressions, applyInlineSuppressions, parseInlineSuppressions } from '../config/suppressions.js';
9
+ import { REPORT_SCHEMA_VERSION } from '../model/types.js';
10
+ import { TOOL_VERSION } from '../version.js';
11
+ import { discoverFiles } from './files.js';
12
+ import { analyzeSource } from './walk.js';
13
+ const compareFindings = (a, b) => a.location.file.localeCompare(b.location.file, 'en') ||
14
+ a.location.line - b.location.line ||
15
+ a.location.column - b.location.column ||
16
+ (a.feature < b.feature ? -1 : a.feature > b.feature ? 1 : 0);
17
+ /** Computes the minimum browser requirements of the given code (US1). */
18
+ export async function analyze(options) {
19
+ const root = path.resolve(options.root ?? process.cwd());
20
+ const paths = options.paths.length > 0 ? options.paths : ['.'];
21
+ const kind = options.kind ?? 'source';
22
+ const { config, configDir } = resolveConfig(options.config, root, paths);
23
+ const browsers = options.browsers ?? config.browsers ?? [...DEFAULT_BROWSERS];
24
+ const files = discoverFiles(paths, { root, kind, ignore: [...(config.ignore ?? []), ...(options.ignore ?? [])] });
25
+ const findings = [];
26
+ const skipped = [];
27
+ for (const file of files) {
28
+ let code;
29
+ try {
30
+ code = fs.readFileSync(path.join(root, file), 'utf8');
31
+ }
32
+ catch (error) {
33
+ skipped.push({ file, reason: `Unreadable: ${error.message}` });
34
+ continue;
35
+ }
36
+ // Each file's AST is dropped after this call (research R10).
37
+ const result = analyzeSource(file, code);
38
+ const firstError = result.errors[0];
39
+ if (firstError) {
40
+ skipped.push({ file, reason: `Syntax error at ${firstError.line}:${firstError.column}: ${firstError.message}` });
41
+ continue;
42
+ }
43
+ // Throws ConfigError for malformed inline suppressions.
44
+ applyInlineSuppressions(result.findings, parseInlineSuppressions(file, result.parsed));
45
+ findings.push(...result.findings);
46
+ }
47
+ findings.sort(compareFindings);
48
+ const suppressions = applyConfigSuppressions(findings, config.suppressions ?? [], root, configDir);
49
+ return {
50
+ schemaVersion: REPORT_SCHEMA_VERSION,
51
+ tool: { name: 'browser-requirements', version: TOOL_VERSION },
52
+ analyzed: { kind, root: '.', files: files.length },
53
+ datasets: { ...datasets },
54
+ browsers: computeMinimums(findings, browsers, byId),
55
+ baseline: computeBaseline(findings, byId),
56
+ findings,
57
+ suppressions,
58
+ skipped,
59
+ };
60
+ }
61
+ function resolveConfig(option, root, paths) {
62
+ if (option !== undefined && typeof option !== 'string')
63
+ return { config: validateConfig(option), configDir: root };
64
+ const file = typeof option === 'string' ? path.resolve(option) : findConfig(root, paths);
65
+ return file ? { config: loadConfig(file), configDir: path.dirname(file) } : { config: {}, configDir: root };
66
+ }
67
+ //# sourceMappingURL=analyze.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyze.js","sourceRoot":"","sources":["../../src/analysis/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,M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MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzF,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC9G,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** Loose ESTree / TS-ESTree node shape produced by oxc-parser with `astType: 'ts'`. */
2
+ export interface AstNode {
3
+ type: string;
4
+ start: number;
5
+ end: number;
6
+ [key: string]: any;
7
+ }
8
+ export declare const isNode: (value: unknown) => value is AstNode;
9
+ /** Removes TypeScript-only and parenthesis wrappers around an expression. */
10
+ export declare function unwrap(node: AstNode): AstNode;
11
+ /** Name of a non-computed member property, or of a computed string-literal property. */
12
+ export declare function memberName(node: AstNode): string | null;
@@ -0,0 +1,21 @@
1
+ export const isNode = (value) => typeof value === 'object' && value !== null && typeof value.type === 'string';
2
+ const WRAPPERS = new Set(['TSAsExpression', 'TSSatisfiesExpression', 'TSNonNullExpression', 'TSTypeAssertion', 'TSInstantiationExpression', 'ParenthesizedExpression']);
3
+ /** Removes TypeScript-only and parenthesis wrappers around an expression. */
4
+ export function unwrap(node) {
5
+ let current = node;
6
+ while (WRAPPERS.has(current.type) && isNode(current.expression))
7
+ current = current.expression;
8
+ return current;
9
+ }
10
+ /** Name of a non-computed member property, or of a computed string-literal property. */
11
+ export function memberName(node) {
12
+ if (node.type !== 'MemberExpression')
13
+ return null;
14
+ const { property, computed } = node;
15
+ if (!computed && property?.type === 'Identifier')
16
+ return property.name;
17
+ if (computed && property?.type === 'Literal' && typeof property.value === 'string')
18
+ return property.value;
19
+ return null;
20
+ }
21
+ //# sourceMappingURL=ast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/analysis/ast.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAoB,EAAE,CACzD,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ,CAAC;AAExG,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,gBAAgB,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,yBAAyB,CAAC,CAAC,CAAC;AAExK,6EAA6E;AAC7E,MAAM,UAAU,MAAM,CAAC,IAAa;IAClC,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;QAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;IAC9F,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,IAAI,IAAI,CAAC,IAAI,KAAK,kBAAkB;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACpC,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,IAAI,KAAK,YAAY;QAAE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvE,IAAI,QAAQ,IAAI,QAAQ,EAAE,IAAI,KAAK,SAAS,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC,KAAK,CAAC;IAC1G,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Confidence, Feature, Finding } from '../model/types.js';
2
+ import type { AstNode } from './ast.js';
3
+ export interface WalkContext {
4
+ file: string;
5
+ globals: Map<number, string>;
6
+ declarationCounts: Map<string, number>;
7
+ /** const bindings initialised with a value of a known built-in type: name → owner (null = ambiguous). */
8
+ receivers: Map<string, string | null>;
9
+ /** Names checked by enclosing feature-detection tests (research R6). */
10
+ guards: string[];
11
+ /** > 0 while inside a `typeof` operand or a compared read: detection, never usage. */
12
+ typeofDepth: number;
13
+ functionDepth: number;
14
+ findings: Finding[];
15
+ /** Records a finding; `guardKey` is the member or global name a guard must check. */
16
+ report(feature: Feature, at: AstNode, confidence: Confidence, guardKey: string | null, name?: string): void;
17
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/analysis/context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { type AstNode } from '../ast.js';
2
+ import type { WalkContext } from '../context.js';
3
+ /** Built-in type of an expression when it is known locally (research R5), else null. */
4
+ export declare function receiverOwner(expr: AstNode, ctx: WalkContext): string | null;
5
+ /** Records `const name = <expr of known built-in type>` so later calls on `name` are certain. */
6
+ export declare function recordReceiver(declarator: AstNode, declaration: AstNode | null, ctx: WalkContext): void;
7
+ /** `receiver.member(...)`: certain when the receiver type is known locally, otherwise probable. */
8
+ export declare function detectInstanceCall(member: AstNode, object: AstNode, property: string, ctx: WalkContext): void;
@@ -0,0 +1,68 @@
1
+ import { DEFAULT_BROWSERS } from '../../data/browsers.js';
2
+ import { globalApi, instanceMembers } from '../../data/features.js';
3
+ import { maxSupport, compareSupport } from '../../model/version.js';
4
+ import { unwrap } from '../ast.js';
5
+ const TYPED_ARRAYS = new Set([
6
+ 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array',
7
+ 'Uint32Array', 'Float16Array', 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array',
8
+ ]);
9
+ /** Built-in type of an expression when it is known locally (research R5), else null. */
10
+ export function receiverOwner(expr, ctx) {
11
+ const node = unwrap(expr);
12
+ switch (node.type) {
13
+ case 'ArrayExpression':
14
+ return 'Array';
15
+ case 'TemplateLiteral':
16
+ return 'String';
17
+ case 'Literal':
18
+ if (typeof node.value === 'string')
19
+ return 'String';
20
+ if (node.regex)
21
+ return 'RegExp';
22
+ return null;
23
+ case 'NewExpression': {
24
+ const callee = unwrap(node.callee);
25
+ if (callee.type === 'Identifier' && ctx.globals.has(callee.start)) {
26
+ const builtin = globalApi(callee.name);
27
+ if (builtin?.kind === 'builtin-global')
28
+ return callee.name;
29
+ }
30
+ return null;
31
+ }
32
+ case 'Identifier': {
33
+ if (ctx.declarationCounts.get(node.name) !== 1)
34
+ return null;
35
+ return ctx.receivers.get(node.name) ?? null;
36
+ }
37
+ default:
38
+ return null;
39
+ }
40
+ }
41
+ /** Records `const name = <expr of known built-in type>` so later calls on `name` are certain. */
42
+ export function recordReceiver(declarator, declaration, ctx) {
43
+ if (declarator.id?.type !== 'Identifier' || !declarator.init)
44
+ return;
45
+ const name = declarator.id.name;
46
+ const owner = declaration?.kind === 'const' ? receiverOwner(declarator.init, ctx) : null;
47
+ ctx.receivers.set(name, ctx.receivers.has(name) && ctx.receivers.get(name) !== owner ? null : owner);
48
+ }
49
+ /** Candidate with the earliest support, so "could rise to" is never overstated. */
50
+ function earliest(candidates) {
51
+ const score = (f) => maxSupport(DEFAULT_BROWSERS.map((b) => f.support[b] ?? 'unknown')) ?? 'unknown';
52
+ return [...candidates].sort((a, b) => compareSupport(score(a), score(b)) || (a.id < b.id ? -1 : 1))[0];
53
+ }
54
+ /** `receiver.member(...)`: certain when the receiver type is known locally, otherwise probable. */
55
+ export function detectInstanceCall(member, object, property, ctx) {
56
+ const candidates = instanceMembers(property);
57
+ if (candidates.length === 0)
58
+ return;
59
+ const owner = receiverOwner(object, ctx);
60
+ if (owner) {
61
+ const match = candidates.find((c) => c.owner === owner) ?? (TYPED_ARRAYS.has(owner) ? candidates.find((c) => c.owner === 'TypedArray') : undefined);
62
+ if (match)
63
+ ctx.report(match, member, 'certain', property);
64
+ return;
65
+ }
66
+ ctx.report(earliest(candidates), member, 'probable', property);
67
+ }
68
+ //# sourceMappingURL=builtins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtins.js","sourceRoot":"","sources":["../../../src/analysis/detectors/builtins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAgB,MAAM,EAAE,MAAM,WAAW,CAAC;AAGjD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY;IACzF,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB;CACjG,CAAC,CAAC;AAEH,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAAC,IAAa,EAAE,GAAgB;IAC3D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,iBAAiB;YACpB,OAAO,OAAO,CAAC;QACjB,KAAK,iBAAiB;YACpB,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;gBAAE,OAAO,QAAQ,CAAC;YACpD,IAAI,IAAI,CAAC,KAAK;gBAAE,OAAO,QAAQ,CAAC;YAChC,OAAO,IAAI,CAAC;QACd,KAAK,eAAe,EAAE,CAAC;YACrB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACnC,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM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AAG,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;AACjE,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { SYNTAX_FEATURES } from '../../data/syntax-map.js';
2
+ import type { AstNode } from '../ast.js';
3
+ type SyntaxKey = keyof typeof SYNTAX_FEATURES;
4
+ /** Syntax features used by this node (research R8). */
5
+ export declare function detectSyntax(node: AstNode, parent: AstNode | null, functionDepth: number): SyntaxKey[];
6
+ export {};
@@ -0,0 +1,79 @@
1
+ import { SYNTAX_FEATURES } from '../../data/syntax-map.js';
2
+ const FUNCTION_TYPES = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression']);
3
+ /** Syntax features used by this node (research R8). */
4
+ export function detectSyntax(node, parent, functionDepth) {
5
+ switch (node.type) {
6
+ case 'Program':
7
+ return node.hashbang ? ['hashbang'] : [];
8
+ case 'ChainExpression':
9
+ return ['optionalChaining'];
10
+ case 'LogicalExpression':
11
+ return node.operator === '??' ? ['nullishCoalescing'] : [];
12
+ case 'AssignmentExpression':
13
+ if (node.operator === '&&=')
14
+ return ['logicalAndAssignment'];
15
+ if (node.operator === '||=')
16
+ return ['logicalOrAssignment'];
17
+ if (node.operator === '??=')
18
+ return ['nullishAssignment'];
19
+ if (node.operator === '**=')
20
+ return ['exponentiation'];
21
+ return [];
22
+ case 'BinaryExpression':
23
+ if (node.operator === '**')
24
+ return ['exponentiation'];
25
+ if (node.operator === 'in' && node.left?.type === 'PrivateIdentifier')
26
+ return ['privateIn'];
27
+ return [];
28
+ case 'PropertyDefinition':
29
+ case 'AccessorProperty': {
30
+ if (node.declare)
31
+ return [];
32
+ const keys = [node.key?.type === 'PrivateIdentifier' ? 'privateClassFields' : 'publicClassFields'];
33
+ if (node.static)
34
+ keys.push('staticClassFields');
35
+ return keys;
36
+ }
37
+ case 'MethodDefinition':
38
+ return node.key?.type === 'PrivateIdentifier' ? ['privateClassMethods'] : [];
39
+ case 'StaticBlock':
40
+ return ['staticBlocks'];
41
+ case 'AwaitExpression':
42
+ return functionDepth === 0 ? ['topLevelAwait'] : [];
43
+ case 'ForOfStatement':
44
+ return node.await && functionDepth === 0 ? ['topLevelAwait'] : [];
45
+ case 'Literal': {
46
+ const keys = [];
47
+ if (typeof node.bigint === 'string')
48
+ keys.push('bigintLiteral');
49
+ if ((typeof node.value === 'number' || typeof node.bigint === 'string') && typeof node.raw === 'string' && node.raw.includes('_')) {
50
+ keys.push('numericSeparators');
51
+ }
52
+ const flags = node.regex?.flags ?? '';
53
+ if (flags.includes('d'))
54
+ keys.push('regexpHasIndices');
55
+ if (flags.includes('s'))
56
+ keys.push('regexpDotAll');
57
+ if (flags.includes('v'))
58
+ keys.push('regexpUnicodeSets');
59
+ return keys;
60
+ }
61
+ case 'ImportDeclaration':
62
+ case 'ExportNamedDeclaration':
63
+ case 'ExportAllDeclaration':
64
+ return Array.isArray(node.attributes) && node.attributes.length > 0 ? ['importAttributes'] : [];
65
+ case 'CatchClause':
66
+ return node.param === null ? ['optionalCatchBinding'] : [];
67
+ case 'SpreadElement':
68
+ return parent?.type === 'ObjectExpression' ? ['objectSpread'] : [];
69
+ case 'MetaProperty':
70
+ return node.meta?.name === 'import' && node.property?.name === 'meta' ? ['importMeta'] : [];
71
+ case 'VariableDeclaration':
72
+ return node.kind === 'using' || node.kind === 'await using' ? ['using'] : [];
73
+ default:
74
+ if (FUNCTION_TYPES.has(node.type) && node.async)
75
+ return [node.generator ? 'asyncGenerator' : 'asyncFunction'];
76
+ return [];
77
+ }
78
+ }
79
+ //# sourceMappingURL=syntax.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syntax.js","sourceRoot":"","sources":["../../../src/analysis/detectors/syntax.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAK3D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,qBAAqB,EAAE,oBAAoB,E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AAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK;gBAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;YAC9G,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { AstNode } from '../ast.js';
2
+ import type { WalkContext } from '../context.js';
3
+ /**
4
+ * A reference to a global (resolved by scope analysis): Web API functions and interfaces
5
+ * (`structuredClone`, `new Response()`) and global built-ins (`WeakRef`).
6
+ */
7
+ export declare function detectGlobalIdentifier(node: AstNode, ctx: WalkContext): void;
8
+ /**
9
+ * A member of a global object: `globalThis.fetch`, members of singletons (`navigator.share`),
10
+ * static members of built-ins (`Object.groupBy`) and Web API interfaces (`URL.canParse`).
11
+ */
12
+ export declare function detectGlobalMember(objectName: string, property: string, node: AstNode, ctx: WalkContext): void;