mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Scripts: the script check counts exportVariables named in brackets as a file write
doc['exportVariables'](f) now reports file.write and filesWritten on its line, as the dot form does. Reading the method without calling it reports nothing.
This commit is contained in:
1 parent
89a280c7bf
commit
ee7576975e
2 files changed
+25
No files matched your search
@@ -287,6 +287,16 @@ impl<'s, 'a, 'l> Analyzer<'s, 'a, 'l> {
|
||||
/// `(` after a name: a call.
|
||||
fn call(&mut self, line: Option<usize>) {
|
||||
let [h0, h1, h2, h3] = self.h;
|
||||
// `doc['exportVariables'](f)`: a document method named by a string literal in brackets.
|
||||
if is(h0, "]")
|
||||
&& is(h2, "[")
|
||||
&& let Some(name) = h1.filter(|s| s.kind == T::Str)
|
||||
&& catalog::DOM_FILE_WRITES.contains(&unquote(name.text, 32).as_str())
|
||||
{
|
||||
self.acc.feature(FeatureId::FileWrite, line);
|
||||
self.acc.outside(OutsideId::FilesWritten, line, None);
|
||||
return;
|
||||
}
|
||||
let Some(callee) = h0.filter(|s| s.kind == T::Ident) else { return };
|
||||
let n = callee.text;
|
||||
if is(h1, ".") {
|
||||
|
||||
@@ -538,6 +538,21 @@ fn export_variables_writes_a_file() {
|
||||
assert_eq!(r.outside.iter().map(|o| (o.id, o.lines.as_slice())).collect::<Vec<_>>(), [("filesWritten", &[3][..])]);
|
||||
}
|
||||
|
||||
/// `exportVariables` called with its name as a string literal in brackets writes the file too;
|
||||
/// reading the method without calling it does not.
|
||||
#[test]
|
||||
fn export_variables_in_brackets_writes_a_file() {
|
||||
let r = report(concat!(
|
||||
"var f = new File(p);\n",
|
||||
"app.activeDocument['importVariables'](f);\n",
|
||||
"app.activeDocument[\"exportVariables\"](f);\n",
|
||||
"var d = app.activeDocument; d['exportVariables'] (f);\n",
|
||||
"var n = d['exportVariables'];\n",
|
||||
));
|
||||
assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[3, 4][..]));
|
||||
assert_eq!(r.outside.iter().map(|o| (o.id, o.lines.as_slice())).collect::<Vec<_>>(), [("filesWritten", &[3, 4][..])]);
|
||||
}
|
||||
|
||||
/// Setting a File object's length, hidden or read-only flag changes the file; reading them, comparing
|
||||
/// them and setting them on another object does not.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user