pxt-core 7.3.4 → 7.3.8

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/pxtlib.js CHANGED
@@ -190,6 +190,10 @@ var pxt;
190
190
  let _client;
191
191
  function client() { return _client; }
192
192
  auth.client = client;
193
+ const PREFERENCES_DEBOUNCE_MS = 5 * 1000;
194
+ const PREFERENCES_DEBOUNCE_MAX_MS = 30 * 1000;
195
+ let debouncePreferencesChangedTimeout = 0;
196
+ let debouncePreferencesChangedStarted = 0;
193
197
  class AuthClient {
194
198
  constructor() {
195
199
  this.initialUserPreferences_ = undefined;
@@ -395,15 +399,28 @@ var pxt;
395
399
  if (!await this.loggedInAsync()) {
396
400
  return;
397
401
  }
398
- // If the user is logged in, save to cloud
399
- const result = await this.apiAsync('/api/user/preferences', ops, 'PATCH');
400
- if (result.success) {
401
- pxt.debug("Updating local user preferences w/ cloud data after result of POST");
402
- // Set user profile from returned value so we stay in-sync
403
- this.setUserPreferencesAsync(result.resp);
402
+ // If the user is logged in, save to cloud, but debounce the api call as this can be called frequently from skillmaps
403
+ clearTimeout(debouncePreferencesChangedTimeout);
404
+ const savePrefs = async () => {
405
+ debouncePreferencesChangedStarted = 0;
406
+ const result = await this.apiAsync('/api/user/preferences', ops, 'PATCH');
407
+ if (result.success) {
408
+ pxt.debug("Updating local user preferences w/ cloud data after result of POST");
409
+ // Set user profile from returned value so we stay in-sync
410
+ this.setUserPreferencesAsync(result.resp);
411
+ }
412
+ else {
413
+ pxt.reportError("identity", "update preferences failed", result);
414
+ }
415
+ };
416
+ if (!debouncePreferencesChangedStarted) {
417
+ debouncePreferencesChangedStarted = pxt.U.now();
418
+ }
419
+ if (PREFERENCES_DEBOUNCE_MAX_MS < pxt.U.now() - debouncePreferencesChangedStarted) {
420
+ await savePrefs();
404
421
  }
405
422
  else {
406
- pxt.reportError("identity", "update preferences failed", result);
423
+ debouncePreferencesChangedTimeout = setTimeout(savePrefs, PREFERENCES_DEBOUNCE_MS);
407
424
  }
408
425
  }
409
426
  /*protected*/ hasUserId() {
@@ -653,6 +670,17 @@ var pxt;
653
670
  }
654
671
  }
655
672
  auth.generateUserProfilePicDataUrl = generateUserProfilePicDataUrl;
673
+ /**
674
+ * Checks only the ID and sourceURL
675
+ */
676
+ function badgeEquals(badgeA, badgeB) {
677
+ return badgeA.id === badgeB.id && badgeA.sourceURL === badgeB.sourceURL;
678
+ }
679
+ auth.badgeEquals = badgeEquals;
680
+ function hasBadge(preferences, badge) {
681
+ return preferences.badges.some(toCheck => badgeEquals(toCheck, badge));
682
+ }
683
+ auth.hasBadge = hasBadge;
656
684
  })(auth = pxt.auth || (pxt.auth = {}));
657
685
  })(pxt || (pxt = {}));
658
686
  // Needs to be in its own file to avoid a circular dependency: util.ts -> main.ts -> util.ts
@@ -3366,6 +3394,8 @@ var pxt;
3366
3394
  }
3367
3395
  if (!comp.switches)
3368
3396
  comp.switches = {};
3397
+ if (comp.nativeType == pxtc.NATIVE_TYPE_VM)
3398
+ comp.sourceMap = true;
3369
3399
  pxt.U.jsonCopyFrom(comp.switches, savedSwitches);
3370
3400
  // JS ref counting currently not supported
3371
3401
  comp.jsRefCounting = false;
@@ -6960,7 +6990,7 @@ int main() {
6960
6990
  .then(ret => new Promise((resolve, reject) => {
6961
6991
  let retry = 0;
6962
6992
  const delay = 8000; // ms
6963
- const maxWait = 180000; // ms
6993
+ const maxWait = 300000; // ms
6964
6994
  const startTry = pxt.U.now();
6965
6995
  const tryGet = () => {
6966
6996
  retry++;
@@ -15160,6 +15190,7 @@ var ts;
15160
15190
  pxtc.BINARY_ELF = "binary.elf";
15161
15191
  pxtc.BINARY_PXT64 = "binary.pxt64";
15162
15192
  pxtc.BINARY_ESP = "binary.bin";
15193
+ pxtc.BINARY_SRCMAP = "binary.srcmap";
15163
15194
  pxtc.NATIVE_TYPE_THUMB = "thumb";
15164
15195
  pxtc.NATIVE_TYPE_VM = "vm";
15165
15196
  function BuildSourceMapHelpers(sourceMap, tsFile, pyFile) {
@@ -21024,7 +21055,6 @@ var pxt;
21024
21055
  youtube.watchUrl = watchUrl;
21025
21056
  })(youtube = pxt.youtube || (pxt.youtube = {}));
21026
21057
  })(pxt || (pxt = {}));
21027
- /* eslint-disable no-cond-assign */
21028
21058
  // TODO: add a macro facility to make 8-bit assembly easier?
21029
21059
  var ts;
21030
21060
  (function (ts) {
@@ -21282,7 +21312,7 @@ var ts;
21282
21312
  // recursive-descent parsing of multiplication
21283
21313
  if (s.indexOf("*") >= 0) {
21284
21314
  let m = null;
21285
- while (m = /^([^\*]*)\*(.*)$/.exec(s)) {
21315
+ while (null != (m = /^([^\*]*)\*(.*)$/.exec(s))) {
21286
21316
  let tmp = this.parseOneInt(m[1]);
21287
21317
  if (tmp == null)
21288
21318
  return null;
@@ -21897,6 +21927,37 @@ var ts;
21897
21927
  }
21898
21928
  });
21899
21929
  }
21930
+ getSourceMap() {
21931
+ const sourceMap = {};
21932
+ let locFile = "";
21933
+ let locLn = 0;
21934
+ let locPos = 0;
21935
+ let locEnd = 0;
21936
+ this.lines.forEach((ln, i) => {
21937
+ const m = /^; ([\w\/\.-]+)\(([\d]+),\d+\):/.exec(ln.text);
21938
+ if (m) {
21939
+ flush();
21940
+ locFile = m[1];
21941
+ locLn = parseInt(m[2]);
21942
+ }
21943
+ if (ln.type == "instruction") {
21944
+ if (!locPos)
21945
+ locPos = ln.location;
21946
+ locEnd = ln.location;
21947
+ }
21948
+ });
21949
+ flush();
21950
+ function flush() {
21951
+ if (locFile && locPos) {
21952
+ if (!sourceMap[locFile])
21953
+ sourceMap[locFile] = [];
21954
+ sourceMap[locFile].push(locLn, locPos, locEnd - locPos);
21955
+ }
21956
+ locPos = 0;
21957
+ locEnd = 0;
21958
+ }
21959
+ return sourceMap;
21960
+ }
21900
21961
  getSource(clean, numStmts = 1, flashSize = 0) {
21901
21962
  let lenPrev = 0;
21902
21963
  let size = (lbl) => {