pxt-core 7.3.6 → 7.3.7

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.
package/built/cli.js CHANGED
@@ -403,6 +403,8 @@ function ciAsync() {
403
403
  pxt.log(`pull request: ${pullRequest}`);
404
404
  pxt.log(`upload api strings: ${uploadApiStrings}`);
405
405
  pxt.log(`upload docs: ${uploadDocs}`);
406
+ lintJSONInDirectory(path.resolve("."));
407
+ lintJSONInDirectory(path.resolve("docs"));
406
408
  function npmPublishAsync() {
407
409
  if (!npmPublish)
408
410
  return Promise.resolve();
@@ -459,6 +461,21 @@ function ciAsync() {
459
461
  });
460
462
  }
461
463
  }
464
+ function lintJSONInDirectory(dir) {
465
+ for (const file of fs.readdirSync(dir)) {
466
+ const fullPath = path.join(dir, file);
467
+ if (file.endsWith(".json")) {
468
+ const contents = fs.readFileSync(fullPath, "utf8");
469
+ try {
470
+ JSON.parse(contents);
471
+ }
472
+ catch (e) {
473
+ console.log("Could not parse " + fullPath);
474
+ process.exit(1);
475
+ }
476
+ }
477
+ }
478
+ }
462
479
  function bumpPxtCoreDepAsync() {
463
480
  let pkg = readJson("package.json");
464
481
  if (pkg["name"] == "pxt-core")
package/built/pxt.js CHANGED
@@ -124143,6 +124143,53 @@ ${info.id}_IfaceVT:
124143
124143
  else
124144
124144
  return `0xffffffff, 0xffffffff ; -> ${vt}`;
124145
124145
  }
124146
+ function encodeSourceMap(srcmap) {
124147
+ // magic: 0x4d435253 0x2d4e1588 0x719986aa ('SRCM' ... )
124148
+ const res = [0x53, 0x52, 0x43, 0x4d, 0x88, 0x15, 0x4e, 0x2d, 0xaa, 0x86, 0x99, 0x71, 0x00, 0x00, 0x00, 0x00];
124149
+ for (const fn of Object.keys(srcmap)) {
124150
+ for (const c of pxtc.U.stringToUint8Array(fn))
124151
+ res.push(c);
124152
+ res.push(0);
124153
+ const arr = srcmap[fn];
124154
+ let prevLn = 0;
124155
+ let prevOff = 0;
124156
+ for (let i = 0; i < arr.length; i += 3) {
124157
+ encodeNumber(arr[i] - prevLn);
124158
+ encodeNumber((arr[i + 1] - prevOff) >> 1);
124159
+ encodeNumber(arr[i + 2] >> 1);
124160
+ prevLn = arr[i];
124161
+ prevOff = arr[i + 1];
124162
+ }
124163
+ res.push(0xff); // end-marker
124164
+ }
124165
+ res.push(0);
124166
+ if (res.length & 1)
124167
+ res.push(0);
124168
+ const res2 = [];
124169
+ for (let i = 0; i < res.length; i += 2)
124170
+ res2.push(res[i] | (res[i + 1] << 8));
124171
+ return res2;
124172
+ function encodeNumber(k) {
124173
+ if (0 <= k && k < 0xf0)
124174
+ res.push(k);
124175
+ else {
124176
+ let mark = 0xf0;
124177
+ if (k < 0) {
124178
+ k = -k;
124179
+ mark |= 0x08;
124180
+ }
124181
+ const idx = res.length;
124182
+ res.push(null); // placeholder
124183
+ let len = 0;
124184
+ while (k != 0) {
124185
+ res.push(k & 0xff);
124186
+ k >>>= 8;
124187
+ len++;
124188
+ }
124189
+ res[idx] = mark | len;
124190
+ }
124191
+ }
124192
+ }
124146
124193
  /* eslint-disable no-trailing-spaces */
124147
124194
  function vmEmit(bin, opts) {
124148
124195
  let vmsource = `; VM start
@@ -124266,9 +124313,10 @@ _start_${name}:
124266
124313
  vmsource += "\n; The end.\n";
124267
124314
  bin.writeFile(pxtc.BINARY_ASM, vmsource);
124268
124315
  let res = pxtc.assemble(opts.target, bin, vmsource);
124269
- if (res.src)
124270
- bin.writeFile(pxtc.BINARY_ASM, res.src);
124271
124316
  const srcmap = res.thumbFile.getSourceMap();
124317
+ const encodedSrcMap = encodeSourceMap(srcmap);
124318
+ if (res.src)
124319
+ bin.writeFile(pxtc.BINARY_ASM, `; srcmap size: ${encodedSrcMap.length << 1} bytes\n` + res.src);
124272
124320
  {
124273
124321
  let binstring = "";
124274
124322
  for (let v of res.buf)
@@ -124294,12 +124342,16 @@ _start_${name}:
124294
124342
  }
124295
124343
  if (res.buf) {
124296
124344
  let binstring = "";
124297
- for (let v of res.buf)
124345
+ const buf = res.buf;
124346
+ while (buf.length & 0xf)
124347
+ buf.push(0);
124348
+ pxtc.U.pushRange(buf, encodedSrcMap);
124349
+ for (let v of buf)
124298
124350
  binstring += String.fromCharCode(v & 0xff, v >> 8);
124299
124351
  binstring = ts.pxtc.encodeBase64(binstring);
124300
124352
  if (embedVTs()) {
124301
124353
  bin.writeFile(pxtc.BINARY_PXT64, binstring);
124302
- const patched = pxtc.hexfile.patchHex(bin, res.buf, false, !!pxtc.target.useUF2)[0];
124354
+ const patched = pxtc.hexfile.patchHex(bin, buf, false, !!pxtc.target.useUF2)[0];
124303
124355
  bin.writeFile(pxt.outputName(pxtc.target), ts.pxtc.encodeBase64(patched));
124304
124356
  }
124305
124357
  else {
@@ -156220,6 +156272,8 @@ function ciAsync() {
156220
156272
  pxt.log(`pull request: ${pullRequest}`);
156221
156273
  pxt.log(`upload api strings: ${uploadApiStrings}`);
156222
156274
  pxt.log(`upload docs: ${uploadDocs}`);
156275
+ lintJSONInDirectory(path.resolve("."));
156276
+ lintJSONInDirectory(path.resolve("docs"));
156223
156277
  function npmPublishAsync() {
156224
156278
  if (!npmPublish)
156225
156279
  return Promise.resolve();
@@ -156276,6 +156330,21 @@ function ciAsync() {
156276
156330
  });
156277
156331
  }
156278
156332
  }
156333
+ function lintJSONInDirectory(dir) {
156334
+ for (const file of fs.readdirSync(dir)) {
156335
+ const fullPath = path.join(dir, file);
156336
+ if (file.endsWith(".json")) {
156337
+ const contents = fs.readFileSync(fullPath, "utf8");
156338
+ try {
156339
+ JSON.parse(contents);
156340
+ }
156341
+ catch (e) {
156342
+ console.log("Could not parse " + fullPath);
156343
+ process.exit(1);
156344
+ }
156345
+ }
156346
+ }
156347
+ }
156279
156348
  function bumpPxtCoreDepAsync() {
156280
156349
  let pkg = readJson("package.json");
156281
156350
  if (pkg["name"] == "pxt-core")
@@ -3350,6 +3350,53 @@ ${info.id}_IfaceVT:
3350
3350
  else
3351
3351
  return `0xffffffff, 0xffffffff ; -> ${vt}`;
3352
3352
  }
3353
+ function encodeSourceMap(srcmap) {
3354
+ // magic: 0x4d435253 0x2d4e1588 0x719986aa ('SRCM' ... )
3355
+ const res = [0x53, 0x52, 0x43, 0x4d, 0x88, 0x15, 0x4e, 0x2d, 0xaa, 0x86, 0x99, 0x71, 0x00, 0x00, 0x00, 0x00];
3356
+ for (const fn of Object.keys(srcmap)) {
3357
+ for (const c of pxtc.U.stringToUint8Array(fn))
3358
+ res.push(c);
3359
+ res.push(0);
3360
+ const arr = srcmap[fn];
3361
+ let prevLn = 0;
3362
+ let prevOff = 0;
3363
+ for (let i = 0; i < arr.length; i += 3) {
3364
+ encodeNumber(arr[i] - prevLn);
3365
+ encodeNumber((arr[i + 1] - prevOff) >> 1);
3366
+ encodeNumber(arr[i + 2] >> 1);
3367
+ prevLn = arr[i];
3368
+ prevOff = arr[i + 1];
3369
+ }
3370
+ res.push(0xff); // end-marker
3371
+ }
3372
+ res.push(0);
3373
+ if (res.length & 1)
3374
+ res.push(0);
3375
+ const res2 = [];
3376
+ for (let i = 0; i < res.length; i += 2)
3377
+ res2.push(res[i] | (res[i + 1] << 8));
3378
+ return res2;
3379
+ function encodeNumber(k) {
3380
+ if (0 <= k && k < 0xf0)
3381
+ res.push(k);
3382
+ else {
3383
+ let mark = 0xf0;
3384
+ if (k < 0) {
3385
+ k = -k;
3386
+ mark |= 0x08;
3387
+ }
3388
+ const idx = res.length;
3389
+ res.push(null); // placeholder
3390
+ let len = 0;
3391
+ while (k != 0) {
3392
+ res.push(k & 0xff);
3393
+ k >>>= 8;
3394
+ len++;
3395
+ }
3396
+ res[idx] = mark | len;
3397
+ }
3398
+ }
3399
+ }
3353
3400
  /* eslint-disable no-trailing-spaces */
3354
3401
  function vmEmit(bin, opts) {
3355
3402
  let vmsource = `; VM start
@@ -3473,9 +3520,10 @@ _start_${name}:
3473
3520
  vmsource += "\n; The end.\n";
3474
3521
  bin.writeFile(pxtc.BINARY_ASM, vmsource);
3475
3522
  let res = pxtc.assemble(opts.target, bin, vmsource);
3476
- if (res.src)
3477
- bin.writeFile(pxtc.BINARY_ASM, res.src);
3478
3523
  const srcmap = res.thumbFile.getSourceMap();
3524
+ const encodedSrcMap = encodeSourceMap(srcmap);
3525
+ if (res.src)
3526
+ bin.writeFile(pxtc.BINARY_ASM, `; srcmap size: ${encodedSrcMap.length << 1} bytes\n` + res.src);
3479
3527
  {
3480
3528
  let binstring = "";
3481
3529
  for (let v of res.buf)
@@ -3501,12 +3549,16 @@ _start_${name}:
3501
3549
  }
3502
3550
  if (res.buf) {
3503
3551
  let binstring = "";
3504
- for (let v of res.buf)
3552
+ const buf = res.buf;
3553
+ while (buf.length & 0xf)
3554
+ buf.push(0);
3555
+ pxtc.U.pushRange(buf, encodedSrcMap);
3556
+ for (let v of buf)
3505
3557
  binstring += String.fromCharCode(v & 0xff, v >> 8);
3506
3558
  binstring = ts.pxtc.encodeBase64(binstring);
3507
3559
  if (embedVTs()) {
3508
3560
  bin.writeFile(pxtc.BINARY_PXT64, binstring);
3509
- const patched = pxtc.hexfile.patchHex(bin, res.buf, false, !!pxtc.target.useUF2)[0];
3561
+ const patched = pxtc.hexfile.patchHex(bin, buf, false, !!pxtc.target.useUF2)[0];
3510
3562
  bin.writeFile(pxt.outputName(pxtc.target), ts.pxtc.encodeBase64(patched));
3511
3563
  }
3512
3564
  else {