From 018dfc2482811bf2753154d1b188f8180c4e859c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 21:00:39 -0800 Subject: [PATCH] Script check: keep reporting SAVECHANGES read through an alias as a file write A script can pass SaveOptions.SAVECHANGES to a document's close through a variable that holds SaveOptions, or through a property of an object that holds it. The check reports any SAVECHANGES member as a file write, whatever the receiver. A test now covers the alias and member cases, and a key of the script's own object literal, which is not reported. --- crates/scriptcheck/src/tests.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/scriptcheck/src/tests.rs b/crates/scriptcheck/src/tests.rs index 9510e29df2..9e0579ec71 100644 --- a/crates/scriptcheck/src/tests.rs +++ b/crates/scriptcheck/src/tests.rs @@ -621,6 +621,20 @@ fn closing_with_save_changes_writes_a_file() { assert_eq!(r.outside.iter().map(|o| (o.id, o.lines.as_slice())).collect::>(), [("filesWritten", &[4, 5, 7][..])]); } +/// `SAVECHANGES` read as a member of anything but `SaveOptions` may still be the save option: through +/// an alias of `SaveOptions` or through an object that holds it. A key of the script's own object +/// literal is not a read, so it writes nothing. +#[test] +fn save_changes_through_another_receiver_writes_a_file() { + let r = report(concat!( + "var o = SaveOptions; app.activeDocument.close(o.SAVECHANGES);\n", + "var k = {how: SaveOptions}; documents[0].close(k.how.SAVECHANGES);\n", + "var own = {SAVECHANGES: 1};\n", + )); + assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[1, 2][..])); + assert_eq!(r.outside.iter().map(|o| (o.id, o.lines.as_slice())).collect::>(), [("filesWritten", &[1, 2][..])]); +} + /// `saveAs` and `exportFile` called with their names as string literals in brackets write the file /// too; reading the method without calling it does not. #[test]