dart-decimate 0.0.1 → 0.0.3
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/Cargo.lock +22 -27
- package/Cargo.toml +2 -2
- package/README.md +70 -10
- package/assets/dart-decimate-banner.png +0 -0
- package/npm/bin/dart-decimate-mcp.js +2 -45
- package/npm/bin/dart-decimate.js +2 -45
- package/npm/bin/runner.js +79 -0
- package/npm/scripts/postinstall.js +159 -25
- package/npm/scripts/test-npx-local.js +1 -2
- package/npm/scripts/test-npx-mcp-local.js +5 -1
- package/npm/scripts/test-npx-prebuilt.js +126 -0
- package/npm/scripts/test-postinstall-prebuilt.js +122 -0
- package/package.json +3 -1
- package/src/cli/coverage_run.rs +12 -12
- package/src/cli/request_args.rs +4 -4
- package/src/dart_parser.rs +17 -14
- package/src/extract/members.rs +4 -4
- package/src/extract/primary_constructors.rs +5 -5
- package/src/extract/references.rs +7 -7
- package/src/extract/routes.rs +40 -38
- package/src/extract/signatures.rs +8 -8
- package/src/extract/strings.rs +3 -2
- package/src/extract.rs +8 -8
- package/src/graph.rs +25 -24
- package/src/health/runtime_coverage.rs +5 -5
- package/src/output/next_steps.rs +14 -14
- package/src/output/security_sarif.rs +4 -4
- package/src/output/suppressions.rs +12 -12
- package/src/package_map.rs +4 -3
- package/src/security/detect.rs +6 -7
- package/src/widgets/unrendered.rs +8 -9
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn, spawnSync } = require("node:child_process");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const http = require("node:http");
|
|
6
|
+
const { tmpdir } = require("node:os");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
|
|
9
|
+
if (process.platform === "win32") {
|
|
10
|
+
console.log("skipping npx prebuilt fixture on Windows");
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const root = path.resolve(__dirname, "../..");
|
|
15
|
+
const tempRoot = fs.mkdtempSync(path.join(tmpdir(), "dart-decimate-npx-prebuilt-"));
|
|
16
|
+
|
|
17
|
+
main().catch((error) => {
|
|
18
|
+
console.error(error.message);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
24
|
+
const platform = process.platform === "win32" ? "windows" : process.platform;
|
|
25
|
+
const arch = process.arch === "x64" ? "x64" : process.arch;
|
|
26
|
+
const assetName = `dart-decimate-${platform}-${arch}.tar.gz`;
|
|
27
|
+
|
|
28
|
+
const projectDir = path.join(tempRoot, "project");
|
|
29
|
+
const payloadDir = path.join(tempRoot, "payload");
|
|
30
|
+
const assetDir = path.join(tempRoot, "assets");
|
|
31
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
32
|
+
fs.mkdirSync(payloadDir, { recursive: true });
|
|
33
|
+
fs.mkdirSync(assetDir, { recursive: true });
|
|
34
|
+
|
|
35
|
+
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
36
|
+
const binaryPath = path.join(payloadDir, binary);
|
|
37
|
+
fs.writeFileSync(
|
|
38
|
+
binaryPath,
|
|
39
|
+
`#!/usr/bin/env sh\nprintf '${binary} prebuilt'\nfor arg in "$@"; do printf ' %s' "$arg"; done\nprintf '\\n'\n`,
|
|
40
|
+
);
|
|
41
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const assetPath = path.join(assetDir, assetName);
|
|
45
|
+
const archive = spawnSync("tar", ["-czf", assetPath, "-C", payloadDir, "."], {
|
|
46
|
+
encoding: "utf8",
|
|
47
|
+
});
|
|
48
|
+
if (archive.status !== 0 || archive.error) {
|
|
49
|
+
throw new Error(archive.stderr || archive.error?.message || "failed to create test archive");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const pack = spawnSync("npm", ["pack", "--json", "--pack-destination", tempRoot], {
|
|
53
|
+
cwd: root,
|
|
54
|
+
encoding: "utf8",
|
|
55
|
+
});
|
|
56
|
+
if (pack.status !== 0 || pack.error) {
|
|
57
|
+
throw new Error(pack.stderr || pack.error?.message || "failed to pack npm package");
|
|
58
|
+
}
|
|
59
|
+
const [metadata] = JSON.parse(pack.stdout);
|
|
60
|
+
const tarball = path.join(tempRoot, metadata.filename);
|
|
61
|
+
|
|
62
|
+
const server = http.createServer((request, response) => {
|
|
63
|
+
if (request.url !== `/v${packageJson.version}/${assetName}`) {
|
|
64
|
+
response.writeHead(404);
|
|
65
|
+
response.end("not found");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
response.writeHead(200, { "content-type": "application/gzip" });
|
|
69
|
+
fs.createReadStream(assetPath).pipe(response);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
73
|
+
const { port } = server.address();
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const result = await runNpx(tarball, projectDir, {
|
|
77
|
+
...process.env,
|
|
78
|
+
CARGO: path.join(tempRoot, "missing-cargo"),
|
|
79
|
+
DART_DECIMATE_RELEASE_BASE_URL: `http://127.0.0.1:${port}/v${packageJson.version}`,
|
|
80
|
+
npm_config_cache: path.join(tempRoot, "npm-cache"),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (result.stdout) {
|
|
84
|
+
process.stdout.write(result.stdout);
|
|
85
|
+
}
|
|
86
|
+
if (result.stderr) {
|
|
87
|
+
process.stderr.write(result.stderr);
|
|
88
|
+
}
|
|
89
|
+
if (result.status !== 0 || result.error) {
|
|
90
|
+
throw new Error(result.error?.message || `npx exited ${result.status}`);
|
|
91
|
+
}
|
|
92
|
+
if (!result.stdout.includes("dart-decimate prebuilt --help")) {
|
|
93
|
+
throw new Error("npx did not execute the downloaded prebuilt binary");
|
|
94
|
+
}
|
|
95
|
+
if (result.stderr.includes("Rust/Cargo")) {
|
|
96
|
+
throw new Error("npx attempted the Cargo fallback even though a prebuilt binary was available");
|
|
97
|
+
}
|
|
98
|
+
} finally {
|
|
99
|
+
await new Promise((resolve) => server.close(resolve));
|
|
100
|
+
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function runNpx(tarball, cwd, env) {
|
|
105
|
+
return new Promise((resolve) => {
|
|
106
|
+
const child = spawn("npx", ["--yes", "--package", tarball, "--", "dart-decimate", "--help"], {
|
|
107
|
+
cwd,
|
|
108
|
+
env,
|
|
109
|
+
});
|
|
110
|
+
let stdout = "";
|
|
111
|
+
let stderr = "";
|
|
112
|
+
|
|
113
|
+
child.stdout.on("data", (chunk) => {
|
|
114
|
+
stdout += chunk;
|
|
115
|
+
});
|
|
116
|
+
child.stderr.on("data", (chunk) => {
|
|
117
|
+
stderr += chunk;
|
|
118
|
+
});
|
|
119
|
+
child.on("error", (error) => {
|
|
120
|
+
resolve({ error, stdout, stderr, status: null });
|
|
121
|
+
});
|
|
122
|
+
child.on("close", (status) => {
|
|
123
|
+
resolve({ stdout, stderr, status });
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn, spawnSync } = require("node:child_process");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const http = require("node:http");
|
|
6
|
+
const { tmpdir } = require("node:os");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
|
|
9
|
+
const root = path.resolve(__dirname, "../..");
|
|
10
|
+
const tempRoot = fs.mkdtempSync(path.join(tmpdir(), "dart-decimate-postinstall-"));
|
|
11
|
+
|
|
12
|
+
main().catch((error) => {
|
|
13
|
+
console.error(error.message);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
async function main() {
|
|
18
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
19
|
+
const platform = process.platform === "win32" ? "windows" : process.platform;
|
|
20
|
+
const arch = process.arch === "x64" ? "x64" : process.arch;
|
|
21
|
+
const assetName = `dart-decimate-${platform}-${arch}.tar.gz`;
|
|
22
|
+
|
|
23
|
+
const scriptDir = path.join(tempRoot, "npm", "scripts");
|
|
24
|
+
const payloadDir = path.join(tempRoot, "payload");
|
|
25
|
+
const assetDir = path.join(tempRoot, "assets");
|
|
26
|
+
fs.mkdirSync(scriptDir, { recursive: true });
|
|
27
|
+
fs.mkdirSync(payloadDir, { recursive: true });
|
|
28
|
+
fs.mkdirSync(assetDir, { recursive: true });
|
|
29
|
+
|
|
30
|
+
fs.copyFileSync(
|
|
31
|
+
path.join(root, "npm", "scripts", "postinstall.js"),
|
|
32
|
+
path.join(scriptDir, "postinstall.js"),
|
|
33
|
+
);
|
|
34
|
+
fs.writeFileSync(
|
|
35
|
+
path.join(tempRoot, "package.json"),
|
|
36
|
+
JSON.stringify({ name: "dart-decimate", version: packageJson.version }, null, 2),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
40
|
+
const binaryPath = path.join(payloadDir, process.platform === "win32" ? `${binary}.exe` : binary);
|
|
41
|
+
fs.writeFileSync(binaryPath, "#!/usr/bin/env sh\nexit 0\n");
|
|
42
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const assetPath = path.join(assetDir, assetName);
|
|
46
|
+
const archive = spawnSync("tar", ["-czf", assetPath, "-C", payloadDir, "."], {
|
|
47
|
+
encoding: "utf8",
|
|
48
|
+
});
|
|
49
|
+
if (archive.status !== 0 || archive.error) {
|
|
50
|
+
throw new Error(archive.stderr || archive.error?.message || "failed to create test archive");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const server = http.createServer((request, response) => {
|
|
54
|
+
if (request.url !== `/v${packageJson.version}/${assetName}`) {
|
|
55
|
+
response.writeHead(404);
|
|
56
|
+
response.end("not found");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
response.writeHead(200, { "content-type": "application/gzip" });
|
|
60
|
+
fs.createReadStream(assetPath).pipe(response);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
64
|
+
const { port } = server.address();
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const result = await runPostinstall(path.join(scriptDir, "postinstall.js"), {
|
|
68
|
+
cwd: tempRoot,
|
|
69
|
+
env: {
|
|
70
|
+
...process.env,
|
|
71
|
+
CARGO: path.join(tempRoot, "missing-cargo"),
|
|
72
|
+
DART_DECIMATE_RELEASE_BASE_URL: `http://127.0.0.1:${port}/v${packageJson.version}`,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (result.stdout) {
|
|
77
|
+
process.stdout.write(result.stdout);
|
|
78
|
+
}
|
|
79
|
+
if (result.stderr) {
|
|
80
|
+
process.stderr.write(result.stderr);
|
|
81
|
+
}
|
|
82
|
+
if (result.status !== 0 || result.error) {
|
|
83
|
+
throw new Error(result.error?.message || `postinstall exited ${result.status}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
87
|
+
const installed = path.join(
|
|
88
|
+
tempRoot,
|
|
89
|
+
"npm",
|
|
90
|
+
"bin-cache",
|
|
91
|
+
process.platform === "win32" ? `${binary}.exe` : binary,
|
|
92
|
+
);
|
|
93
|
+
if (!fs.existsSync(installed)) {
|
|
94
|
+
throw new Error(`missing installed prebuilt binary ${binary}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} finally {
|
|
98
|
+
await new Promise((resolve) => server.close(resolve));
|
|
99
|
+
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function runPostinstall(script, options) {
|
|
104
|
+
return new Promise((resolve) => {
|
|
105
|
+
const child = spawn("node", [script], options);
|
|
106
|
+
let stdout = "";
|
|
107
|
+
let stderr = "";
|
|
108
|
+
|
|
109
|
+
child.stdout.on("data", (chunk) => {
|
|
110
|
+
stdout += chunk;
|
|
111
|
+
});
|
|
112
|
+
child.stderr.on("data", (chunk) => {
|
|
113
|
+
stderr += chunk;
|
|
114
|
+
});
|
|
115
|
+
child.on("error", (error) => {
|
|
116
|
+
resolve({ error, stdout, stderr, status: null });
|
|
117
|
+
});
|
|
118
|
+
child.on("close", (status) => {
|
|
119
|
+
resolve({ stdout, stderr, status });
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dart-decimate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"pack:check": "npm pack --dry-run",
|
|
34
34
|
"test:npm": "node npm/bin/dart-decimate.js --help",
|
|
35
35
|
"test:npm:mcp": "printf '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-11-25\"}}\\n' | node npm/bin/dart-decimate-mcp.js",
|
|
36
|
+
"test:postinstall:prebuilt": "node npm/scripts/test-postinstall-prebuilt.js",
|
|
37
|
+
"test:npx:prebuilt": "node npm/scripts/test-npx-prebuilt.js",
|
|
36
38
|
"test:npx:local": "node npm/scripts/test-npx-local.js",
|
|
37
39
|
"test:npx:mcp:local": "node npm/scripts/test-npx-mcp-local.js"
|
|
38
40
|
},
|
package/src/cli/coverage_run.rs
CHANGED
|
@@ -314,20 +314,20 @@ fn coverage_health_options(subcommand: &ArgMatches, mut options: HealthOptions)
|
|
|
314
314
|
options.ownership = false.into();
|
|
315
315
|
|
|
316
316
|
options.runtime_coverage_path = subcommand.get_one::<PathBuf>("runtime-coverage").cloned();
|
|
317
|
-
if subcommand.value_source("min-invocations-hot") == Some(ValueSource::CommandLine)
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
317
|
+
if subcommand.value_source("min-invocations-hot") == Some(ValueSource::CommandLine) {
|
|
318
|
+
if let Some(value) = subcommand.get_one::<usize>("min-invocations-hot") {
|
|
319
|
+
options.min_invocations_hot = (*value).max(1);
|
|
320
|
+
}
|
|
321
321
|
}
|
|
322
|
-
if subcommand.value_source("min-observation-volume") == Some(ValueSource::CommandLine)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
322
|
+
if subcommand.value_source("min-observation-volume") == Some(ValueSource::CommandLine) {
|
|
323
|
+
if let Some(value) = subcommand.get_one::<usize>("min-observation-volume") {
|
|
324
|
+
options.min_observation_volume = (*value).max(1);
|
|
325
|
+
}
|
|
326
326
|
}
|
|
327
|
-
if subcommand.value_source("low-traffic-threshold") == Some(ValueSource::CommandLine)
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
327
|
+
if subcommand.value_source("low-traffic-threshold") == Some(ValueSource::CommandLine) {
|
|
328
|
+
if let Some(value) = subcommand.get_one::<f64>("low-traffic-threshold") {
|
|
329
|
+
options.low_traffic_threshold = LowTrafficThreshold::from_ratio(*value);
|
|
330
|
+
}
|
|
331
331
|
}
|
|
332
332
|
if let Some(top) = subcommand.get_one::<usize>("top") {
|
|
333
333
|
options.top = Some(*top);
|
package/src/cli/request_args.rs
CHANGED
|
@@ -50,10 +50,10 @@ pub(super) fn policy_pack_paths(
|
|
|
50
50
|
config: &DartDecimateConfig,
|
|
51
51
|
) -> Vec<PathBuf> {
|
|
52
52
|
let mut paths = config.policy_packs.clone();
|
|
53
|
-
if matches!(command, ReportCommand::Check | ReportCommand::Audit)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
if matches!(command, ReportCommand::Check | ReportCommand::Audit) {
|
|
54
|
+
if let Some(values) = subcommand.get_many::<PathBuf>("policy-pack") {
|
|
55
|
+
paths.extend(values.cloned());
|
|
56
|
+
}
|
|
57
57
|
}
|
|
58
58
|
paths
|
|
59
59
|
}
|
package/src/dart_parser.rs
CHANGED
|
@@ -167,10 +167,11 @@ fn primary_constructor_header(
|
|
|
167
167
|
let class_name = source[name_start..name_end].to_owned();
|
|
168
168
|
let mut header_cursor = skip_whitespace(source, name_end).unwrap_or(name_end);
|
|
169
169
|
|
|
170
|
-
if source.as_bytes().get(header_cursor).copied() == Some(b'<')
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
if source.as_bytes().get(header_cursor).copied() == Some(b'<') {
|
|
171
|
+
if let Some(type_params_end) = matching_delimiter(source, header_cursor, b'<', b'>') {
|
|
172
|
+
header_cursor =
|
|
173
|
+
skip_whitespace(source, type_params_end + 1).unwrap_or(type_params_end + 1);
|
|
174
|
+
}
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
let replacement_start = primary_constructor_replacement_start(source, &mut header_cursor)?;
|
|
@@ -259,16 +260,18 @@ fn push_constructor_body_replacement(
|
|
|
259
260
|
replacements: &mut Vec<Replacement>,
|
|
260
261
|
header: &PrimaryConstructorHeader,
|
|
261
262
|
) {
|
|
262
|
-
if let Some((terminator_start, _)) = header.terminator
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
263
|
+
if let Some((terminator_start, _)) = header.terminator {
|
|
264
|
+
if let Some(body_end) = matching_delimiter(source, terminator_start, b'{', b'}') {
|
|
265
|
+
if let Some(this_start) =
|
|
266
|
+
find_primary_constructor_body(source, terminator_start + 1, body_end)
|
|
267
|
+
{
|
|
268
|
+
replacements.push(Replacement {
|
|
269
|
+
start: this_start,
|
|
270
|
+
end: this_start + "this".len(),
|
|
271
|
+
kind: ReplacementKind::ConstructorBody(header.class_name.clone()),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
272
275
|
}
|
|
273
276
|
}
|
|
274
277
|
|
package/src/extract/members.rs
CHANGED
|
@@ -195,10 +195,10 @@ fn collect_member_field_names(node: Node<'_>, source: &str, names: &mut Vec<Stri
|
|
|
195
195
|
&["static_final_declaration", "initialized_identifier"],
|
|
196
196
|
names,
|
|
197
197
|
);
|
|
198
|
-
if names.is_empty()
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
if names.is_empty() {
|
|
199
|
+
if let Some(identifier_list) = find_first_named_descendant(node, "identifier_list") {
|
|
200
|
+
collect_direct_identifier_children(identifier_list, source, names);
|
|
201
|
+
}
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -75,11 +75,11 @@ fn primary_constructor_headers(source: &str) -> Vec<PrimaryConstructorHeader> {
|
|
|
75
75
|
};
|
|
76
76
|
let declaration = source[name_start..name_end].to_owned();
|
|
77
77
|
let mut header_cursor = skip_whitespace(source, name_end).unwrap_or(name_end);
|
|
78
|
-
if source.as_bytes().get(header_cursor).copied() == Some(b'<')
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
if source.as_bytes().get(header_cursor).copied() == Some(b'<') {
|
|
79
|
+
if let Some(type_params_end) = matching_delimiter(source, header_cursor, b'<', b'>') {
|
|
80
|
+
header_cursor =
|
|
81
|
+
skip_whitespace(source, type_params_end + 1).unwrap_or(type_params_end + 1);
|
|
82
|
+
}
|
|
83
83
|
}
|
|
84
84
|
if source.as_bytes().get(header_cursor).copied() == Some(b'.') {
|
|
85
85
|
let suffix_start =
|
|
@@ -16,13 +16,13 @@ fn collect_identifier_references(
|
|
|
16
16
|
source: &str,
|
|
17
17
|
references: &mut Vec<IdentifierReference>,
|
|
18
18
|
) {
|
|
19
|
-
if is_reference_identifier(node, source)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
19
|
+
if is_reference_identifier(node, source) {
|
|
20
|
+
if let Ok(name) = node.utf8_text(source.as_bytes()) {
|
|
21
|
+
references.push(IdentifierReference {
|
|
22
|
+
name: name.to_owned(),
|
|
23
|
+
location: node.start_position().into(),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
let mut cursor = node.walk();
|
package/src/extract/routes.rs
CHANGED
|
@@ -72,35 +72,35 @@ fn collect_raw_routes_in(
|
|
|
72
72
|
parent_resolved: bool,
|
|
73
73
|
routes: &mut Vec<DartRouteDeclaration>,
|
|
74
74
|
) {
|
|
75
|
-
if is_object_constructor(node)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
75
|
+
if is_object_constructor(node) {
|
|
76
|
+
if let Some(route_kind) = raw_route_constructor_kind(node, source) {
|
|
77
|
+
let next_parent = match route_kind {
|
|
78
|
+
RawRouteKind::GoRoute => collect_go_route(
|
|
79
|
+
node,
|
|
80
|
+
source,
|
|
81
|
+
constants,
|
|
82
|
+
parent_path,
|
|
83
|
+
parent_resolved,
|
|
84
|
+
routes,
|
|
85
|
+
),
|
|
86
|
+
RawRouteKind::RouteContainer => None,
|
|
87
|
+
};
|
|
88
|
+
let next_parent_resolved = match route_kind {
|
|
89
|
+
RawRouteKind::GoRoute => next_parent.is_some(),
|
|
90
|
+
RawRouteKind::RouteContainer => parent_resolved,
|
|
91
|
+
};
|
|
92
|
+
for child_routes_arg in route_child_argument_nodes(node, source) {
|
|
93
|
+
collect_raw_routes_in(
|
|
94
|
+
child_routes_arg,
|
|
95
|
+
source,
|
|
96
|
+
constants,
|
|
97
|
+
next_parent.as_deref().or(parent_path),
|
|
98
|
+
next_parent_resolved,
|
|
99
|
+
routes,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
102
103
|
}
|
|
103
|
-
return;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
let mut cursor = node.walk();
|
|
@@ -235,17 +235,19 @@ fn collect_string_constants_in(
|
|
|
235
235
|
node.kind(),
|
|
236
236
|
"static_final_declaration" | "initialized_identifier"
|
|
237
237
|
) && is_const_string_declaration(node, source)
|
|
238
|
-
&& let Some(name) = field_text(node, "name", source)
|
|
239
|
-
&& let Some(value) = node.child_by_field_name("value").and_then(|value| {
|
|
240
|
-
value
|
|
241
|
-
.utf8_text(source.as_bytes())
|
|
242
|
-
.ok()
|
|
243
|
-
.and_then(unquote_dart_string)
|
|
244
|
-
})
|
|
245
238
|
{
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
239
|
+
if let Some(name) = field_text(node, "name", source) {
|
|
240
|
+
if let Some(value) = node.child_by_field_name("value").and_then(|value| {
|
|
241
|
+
value
|
|
242
|
+
.utf8_text(source.as_bytes())
|
|
243
|
+
.ok()
|
|
244
|
+
.and_then(unquote_dart_string)
|
|
245
|
+
}) {
|
|
246
|
+
constants.insert(name.clone(), value.clone());
|
|
247
|
+
if let Some(class_name) = containing_class_name(node, source) {
|
|
248
|
+
constants.insert(format!("{class_name}.{name}"), value);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
249
251
|
}
|
|
250
252
|
}
|
|
251
253
|
|
|
@@ -192,10 +192,10 @@ fn variable_names(node: Node<'_>, source: &str) -> Vec<String> {
|
|
|
192
192
|
&mut names,
|
|
193
193
|
);
|
|
194
194
|
|
|
195
|
-
if names.is_empty()
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
if names.is_empty() {
|
|
196
|
+
if let Some(identifier_list) = find_first_named_descendant(node, "identifier_list") {
|
|
197
|
+
collect_direct_identifier_children(identifier_list, source, &mut names);
|
|
198
|
+
}
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
names
|
|
@@ -218,10 +218,10 @@ fn collect_named_fields(
|
|
|
218
218
|
owner_kinds: &[&str],
|
|
219
219
|
names: &mut Vec<String>,
|
|
220
220
|
) {
|
|
221
|
-
if owner_kinds.contains(&node.kind())
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
if owner_kinds.contains(&node.kind()) {
|
|
222
|
+
if let Some(name) = field_text(node, "name", source) {
|
|
223
|
+
names.push(name);
|
|
224
|
+
}
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
let mut cursor = node.walk();
|
package/src/extract/strings.rs
CHANGED
|
@@ -13,9 +13,10 @@ fn quoted_dart_string_body(trimmed: &str) -> Option<(&str, bool)> {
|
|
|
13
13
|
if let Some(raw) = trimmed
|
|
14
14
|
.strip_prefix('r')
|
|
15
15
|
.or_else(|| trimmed.strip_prefix('R'))
|
|
16
|
-
&& let Some(quoted) = quoted_dart_string_body_without_prefix(raw)
|
|
17
16
|
{
|
|
18
|
-
|
|
17
|
+
if let Some(quoted) = quoted_dart_string_body_without_prefix(raw) {
|
|
18
|
+
return Some((quoted, true));
|
|
19
|
+
}
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
quoted_dart_string_body_without_prefix(trimmed).map(|quoted| (quoted, false))
|
package/src/extract.rs
CHANGED
|
@@ -536,10 +536,10 @@ fn push_variable_declarations(
|
|
|
536
536
|
&mut names,
|
|
537
537
|
);
|
|
538
538
|
|
|
539
|
-
if names.is_empty()
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
539
|
+
if names.is_empty() {
|
|
540
|
+
if let Some(identifier_list) = find_first_named_descendant(node, "identifier_list") {
|
|
541
|
+
collect_direct_identifier_children(identifier_list, source, &mut names);
|
|
542
|
+
}
|
|
543
543
|
}
|
|
544
544
|
|
|
545
545
|
declarations.extend(names.into_iter().map(|name| TopLevelDeclaration {
|
|
@@ -587,10 +587,10 @@ fn collect_named_fields(
|
|
|
587
587
|
owner_kinds: &[&str],
|
|
588
588
|
names: &mut Vec<String>,
|
|
589
589
|
) {
|
|
590
|
-
if owner_kinds.contains(&node.kind())
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
590
|
+
if owner_kinds.contains(&node.kind()) {
|
|
591
|
+
if let Some(name) = field_text(node, "name", source) {
|
|
592
|
+
names.push(name);
|
|
593
|
+
}
|
|
594
594
|
}
|
|
595
595
|
|
|
596
596
|
let mut cursor = node.walk();
|
package/src/graph.rs
CHANGED
|
@@ -388,23 +388,23 @@ fn add_file_dependencies(
|
|
|
388
388
|
return;
|
|
389
389
|
};
|
|
390
390
|
|
|
391
|
-
if let Some(library) = &file.library
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
391
|
+
if let Some(library) = &file.library {
|
|
392
|
+
if let Some(augment_uri) = &library.augment_uri {
|
|
393
|
+
add_dependency(
|
|
394
|
+
root,
|
|
395
|
+
packages,
|
|
396
|
+
known_paths,
|
|
397
|
+
nodes_by_path,
|
|
398
|
+
graph,
|
|
399
|
+
unresolved,
|
|
400
|
+
from_index,
|
|
401
|
+
&from_path,
|
|
402
|
+
augment_uri,
|
|
403
|
+
DependencyKind::Augment,
|
|
404
|
+
library.location,
|
|
405
|
+
DependencyVisibility::default(),
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
let imports = selected_imports(&file.imports, &options.conditional_environment);
|
|
@@ -572,13 +572,14 @@ fn percent_decode_uri_path(value: &str) -> String {
|
|
|
572
572
|
let mut index = 0;
|
|
573
573
|
|
|
574
574
|
while index < bytes.len() {
|
|
575
|
-
if bytes[index] == b'%'
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
575
|
+
if bytes[index] == b'%' {
|
|
576
|
+
if let (Some(high), Some(low)) = (bytes.get(index + 1), bytes.get(index + 2)) {
|
|
577
|
+
if let Some(decoded_byte) = decode_hex_pair(*high, *low) {
|
|
578
|
+
decoded.push(decoded_byte);
|
|
579
|
+
index += 3;
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
582
583
|
}
|
|
583
584
|
|
|
584
585
|
decoded.push(bytes[index]);
|