mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Scripts: a later saveAs value in brackets ends the exemption
A literal such as `{saveAs: function () {}, saveAs: (doc.saveAs)}` kept
the first key's exemption, because the value's opening bracket had
already raised the depth when the key was read. The key is now read at
the depth outside that bracket, so the later value replaces the
function and `n['saveAs'](f)` is reported as a file write.
This commit is contained in:
1 parent
c4edd76fc8
commit
ff4fc193f8
2 files changed
+7
-2
No files matched your search
@@ -1401,7 +1401,9 @@ impl<'s, 'a, 'l> Analyzer<'s, 'a, 'l> {
|
||||
_ => return,
|
||||
};
|
||||
let Some(i) = catalog::DOM_FILE_WRITES.iter().position(|m| *m == key.as_ref()) else { return };
|
||||
let Some(o) = self.objects.last_mut().filter(|o| o.depth == depth) else { return };
|
||||
// A value that starts with a bracket has opened it already: the key is at the depth outside it.
|
||||
let at = if t.is("(") || t.is("[") || t.is("{") { depth.saturating_sub(1) } else { depth };
|
||||
let Some(o) = self.objects.last_mut().filter(|o| o.depth == at) else { return };
|
||||
if t.word("function") {
|
||||
o.bits |= 1 << i;
|
||||
} else {
|
||||
|
||||
@@ -609,8 +609,11 @@ fn a_changed_or_shared_own_save_as_writes_a_file() {
|
||||
"var m = {saveAs: d.saveAs}; var n = {saveAs: function () {}, saveAs: d.saveAs};\n",
|
||||
"m.saveAs(f);\n",
|
||||
"n.saveAs(f);\n",
|
||||
"var q = {saveAs: function () {}, saveAs: (d.saveAs)}; var s = {saveAs: function () {}, saveAs: [w][0]};\n",
|
||||
"q['saveAs'](f);\n",
|
||||
"s.saveAs(f);\n",
|
||||
));
|
||||
assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[11, 12, 13, 14, 15, 16, 18, 19][..]));
|
||||
assert_eq!(feature(&r, "file.write").map(|f| f.lines.as_slice()), Some(&[11, 12, 13, 14, 15, 16, 18, 19, 21, 22][..]));
|
||||
}
|
||||
|
||||
/// Only a `var` statement directly in a function body or the global code that gives its first name
|
||||
|
||||
Reference in new issue
Block a user