@turbowarp/sb3fix 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/sb3fix.js +11 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbowarp/sb3fix",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Fix corrupted Scratch projects",
5
5
  "main": "src/sb3fix.js",
6
6
  "scripts": {
package/src/sb3fix.js CHANGED
@@ -134,7 +134,7 @@ const fixJSON = (data, options = {}) => {
134
134
  /**
135
135
  * @param {unknown[]} native
136
136
  */
137
- const fixNativeInPlace = (native) => {
137
+ const fixCompressedNativeInPlace = (native) => {
138
138
  if (!Array.isArray(native)) {
139
139
  throw new Error('native is not an array');
140
140
  }
@@ -144,10 +144,13 @@ const fixJSON = (data, options = {}) => {
144
144
  throw new Error('native type is not a number');
145
145
  }
146
146
  switch (type) {
147
- case 12: // Variable: [12, variable name, variable id]
148
- case 13: // List: [13, list name, list id]
149
- if (native.length !== 3) {
150
- throw new Error('variable or list native is of wrong length');
147
+ // Variable: [12, variable name, variable id, x?, y?]
148
+ // List: [13, list name, list id, x?, y?]
149
+ // x and y only present if the native is a top-level block
150
+ case 12:
151
+ case 13: {
152
+ if (native.length !== 3 && native.length !== 5) {
153
+ throw new Error(`Variable or list native is of unexpected length: ${native.length}`);
151
154
  }
152
155
  const name = native[1];
153
156
  if (typeof name !== 'string') {
@@ -155,6 +158,7 @@ const fixJSON = (data, options = {}) => {
155
158
  native[1] = String(native[1]);
156
159
  }
157
160
  break;
161
+ }
158
162
  }
159
163
  };
160
164
 
@@ -164,7 +168,7 @@ const fixJSON = (data, options = {}) => {
164
168
  */
165
169
  const fixBlockInPlace = (id, block) => {
166
170
  if (Array.isArray(block)) {
167
- fixNativeInPlace(block);
171
+ fixCompressedNativeInPlace(block);
168
172
  } else if (isObject(block)) {
169
173
  const inputs = block.inputs;
170
174
  if (!isObject(inputs)) {
@@ -176,7 +180,7 @@ const fixJSON = (data, options = {}) => {
176
180
  }
177
181
  for (let i = 1; i < input.length; i++) {
178
182
  if (Array.isArray(input[i])) {
179
- fixNativeInPlace(input[i]);
183
+ fixCompressedNativeInPlace(input[i]);
180
184
  }
181
185
  }
182
186
  }