mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-03 17:14:27 -04:00
Merge pull request #1816 from paulkaplan/do-save-tl-var-blocks
Add a test and fix for not serializing top-level variable reporters
This commit is contained in:
commit
4756726e43
3 changed files with 21 additions and 2 deletions
|
@ -326,7 +326,7 @@ const serializeBlocks = function (blocks) {
|
|||
// a shadow block, and there are no blocks that reference it, otherwise
|
||||
// they would have been compressed in the last pass)
|
||||
if (Array.isArray(serializedBlock) &&
|
||||
[VAR_PRIMITIVE, LIST_PRIMITIVE].indexOf(serializedBlock) < 0) {
|
||||
[VAR_PRIMITIVE, LIST_PRIMITIVE].indexOf(serializedBlock[0]) < 0) {
|
||||
log.warn(`Found an unexpected top level primitive with block ID: ${
|
||||
blockID}; deleting it from serialized blocks.`);
|
||||
delete obj[blockID];
|
||||
|
@ -803,7 +803,7 @@ const deserializeBlocks = function (blocks) {
|
|||
// this is one of the primitives
|
||||
// delete the old entry in object.blocks and replace it w/the
|
||||
// deserialized object
|
||||
delete block[blockId];
|
||||
delete blocks[blockId];
|
||||
deserializeInputDesc(block, null, false, blocks);
|
||||
continue;
|
||||
}
|
||||
|
|
BIN
test/fixtures/top-level-variable-reporter.sb2
vendored
Normal file
BIN
test/fixtures/top-level-variable-reporter.sb2
vendored
Normal file
Binary file not shown.
|
@ -7,6 +7,7 @@ const exampleProjectPath = path.resolve(__dirname, '../fixtures/clone-cleanup.sb
|
|||
const commentsSB2ProjectPath = path.resolve(__dirname, '../fixtures/comments.sb2');
|
||||
const commentsSB3ProjectPath = path.resolve(__dirname, '../fixtures/comments.sb3');
|
||||
const commentsSB3NoDupeIds = path.resolve(__dirname, '../fixtures/comments_no_duplicate_id_serialization.sb3');
|
||||
const variableReporterSB2ProjectPath = path.resolve(__dirname, '../fixtures/top-level-variable-reporter.sb2');
|
||||
const FakeRenderer = require('../fixtures/fake-renderer');
|
||||
|
||||
test('serialize', t => {
|
||||
|
@ -236,3 +237,21 @@ test('getExtensionIdForOpcode', t => {
|
|||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('(#1608) serializeBlocks maintains top level variable reporters', t => {
|
||||
const vm = new VirtualMachine();
|
||||
vm.loadProject(readFileToBuffer(variableReporterSB2ProjectPath))
|
||||
.then(() => {
|
||||
const blocks = vm.runtime.targets[0].blocks._blocks;
|
||||
const result = sb3.serialize(vm.runtime);
|
||||
// Project should have 1 block, a top-level variable reporter
|
||||
t.equal(Object.keys(blocks).length, 1);
|
||||
t.equal(Object.keys(result.targets[0].blocks).length, 1);
|
||||
|
||||
// Make sure deserializing these blocks works
|
||||
t.doesNotThrow(() => {
|
||||
sb3.deserialize(JSON.parse(JSON.stringify(result)), vm.runtime);
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue