mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
try handling as a Scratch 1 file after scratch-parser validation fails
This commit is contained in:
parent
a92f33960f
commit
5593b28984
1 changed files with 21 additions and 14 deletions
|
@ -290,25 +290,32 @@ class VirtualMachine extends EventEmitter {
|
|||
}
|
||||
|
||||
const validationPromise = new Promise((resolve, reject) => {
|
||||
try {
|
||||
const sb1 = new SB1File(input);
|
||||
const json = sb1.json;
|
||||
json.projectVersion = 2;
|
||||
return resolve([json, sb1.zip]);
|
||||
} catch (e) {
|
||||
if (e instanceof ValidationError) {
|
||||
// The input does not validate as a Scratch 1 file.
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// The second argument of false below indicates to the validator that the
|
||||
// input should be parsed/validated as an entire project (and not a single sprite)
|
||||
validate(input, false, (error, res) => {
|
||||
if (error) return reject(error);
|
||||
resolve(res);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
try {
|
||||
const sb1 = new SB1File(input);
|
||||
const json = sb1.json;
|
||||
json.projectVersion = 2;
|
||||
return [json, sb1.zip];
|
||||
} catch (sb1Error) {
|
||||
if (sb1Error instanceof ValidationError) {
|
||||
// The input does not validate as a Scratch 1 file.
|
||||
} else {
|
||||
// The project appears to be a Scratch 1 file but it
|
||||
// could not be successfully translated into a Scratch 2
|
||||
// project.
|
||||
throw sb1Error;
|
||||
}
|
||||
}
|
||||
// Through original error since the input does not appear to be
|
||||
// an SB1File.
|
||||
throw error;
|
||||
});
|
||||
|
||||
return validationPromise
|
||||
|
|
Loading…
Reference in a new issue