pxt-core 9.3.4 → 9.3.6

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/pxt.js CHANGED
@@ -114404,6 +114404,17 @@ var pxt;
114404
114404
  const patches = pxt.appTarget.compile ? pxt.appTarget.compile.patches : undefined;
114405
114405
  if (!patches)
114406
114406
  return undefined;
114407
+ return parsePatches(version, patches, kind);
114408
+ }
114409
+ patching.computePatches = computePatches;
114410
+ function computePyPatches(version, kind) {
114411
+ const patches = pxt.appTarget.compile ? pxt.appTarget.compile.pyPatches : undefined;
114412
+ if (!patches)
114413
+ return undefined;
114414
+ return parsePatches(version, patches, kind);
114415
+ }
114416
+ patching.computePyPatches = computePyPatches;
114417
+ function parsePatches(version, patches, kind) {
114407
114418
  const v = pxt.semver.tryParse(version || "0.0.0") || pxt.semver.tryParse("0.0.0");
114408
114419
  let r = [];
114409
114420
  Object.keys(patches)
@@ -114413,7 +114424,6 @@ var pxt;
114413
114424
  r = r.filter(p => p.type == kind);
114414
114425
  return r.length ? r : undefined;
114415
114426
  }
114416
- patching.computePatches = computePatches;
114417
114427
  function upgradePackageReference(pkgTargetVersion, pkg, val) {
114418
114428
  if (val != "*")
114419
114429
  return pkg;
@@ -114433,6 +114443,15 @@ var pxt;
114433
114443
  patching.upgradePackageReference = upgradePackageReference;
114434
114444
  function patchJavaScript(pkgTargetVersion, fileContents) {
114435
114445
  const upgrades = pxt.patching.computePatches(pkgTargetVersion);
114446
+ return patchTextCode(pkgTargetVersion, fileContents, upgrades);
114447
+ }
114448
+ patching.patchJavaScript = patchJavaScript;
114449
+ function patchPython(pkgTargetVersion, fileContents) {
114450
+ const upgrades = pxt.patching.computePyPatches(pkgTargetVersion);
114451
+ return patchTextCode(pkgTargetVersion, fileContents, upgrades);
114452
+ }
114453
+ patching.patchPython = patchPython;
114454
+ function patchTextCode(pkgTargetVersion, fileContents, upgrades) {
114436
114455
  let updatedContents = fileContents;
114437
114456
  if (upgrades) {
114438
114457
  upgrades.filter(u => u.type === "api").forEach(rule => {
@@ -114452,7 +114471,6 @@ var pxt;
114452
114471
  }
114453
114472
  return updatedContents;
114454
114473
  }
114455
- patching.patchJavaScript = patchJavaScript;
114456
114474
  })(patching = pxt.patching || (pxt.patching = {}));
114457
114475
  })(pxt || (pxt = {}));
114458
114476
  var pxt;
@@ -122389,6 +122407,16 @@ var pxt;
122389
122407
  });
122390
122408
  }
122391
122409
  Cloud.downloadScriptMetaAsync = downloadScriptMetaAsync;
122410
+ async function downloadBuiltSimJsInfoAsync(id) {
122411
+ const targetVersion = pxt.appTarget.versions && pxt.appTarget.versions.target || "";
122412
+ const url = pxt.U.stringifyQueryString(id + "/js", { v: "v" + targetVersion }) + (id.startsWith("S") ? `&time=${Date.now()}` : "");
122413
+ const resp = await privateRequestAsync({
122414
+ url,
122415
+ forceLiveEndpoint: true,
122416
+ });
122417
+ return resp.json;
122418
+ }
122419
+ Cloud.downloadBuiltSimJsInfoAsync = downloadBuiltSimJsInfoAsync;
122392
122420
  async function markdownAsync(docid, locale, propagateExceptions) {
122393
122421
  // 1h check on markdown content if not on development server
122394
122422
  const MARKDOWN_EXPIRATION = pxt.BrowserUtils.isLocalHostDev() ? 0 : 1 * 60 * 60 * 1000;
@@ -123226,6 +123254,9 @@ var pxt;
123226
123254
  return mainPkg.getCompileOptionsAsync(target);
123227
123255
  }).then(opts => {
123228
123256
  patchTS(mainPkg.targetVersion(), opts);
123257
+ if (mainPkg.getPreferredEditor() === pxt.PYTHON_PROJECT_NAME) {
123258
+ patchPY(mainPkg.targetVersion(), opts);
123259
+ }
123229
123260
  prepPythonOptions(opts);
123230
123261
  return opts;
123231
123262
  });
@@ -123259,6 +123290,22 @@ var pxt;
123259
123290
  }
123260
123291
  }
123261
123292
  pxt.patchTS = patchTS;
123293
+ function patchPY(version, opts) {
123294
+ if (!version)
123295
+ return;
123296
+ pxt.debug(`applying PY patches relative to ${version}`);
123297
+ for (let fn of Object.keys(opts.fileSystem)) {
123298
+ if (fn.indexOf("/") == -1 && pxt.U.endsWith(fn, ".py")) {
123299
+ const initial = opts.fileSystem[fn];
123300
+ const patched = pxt.patching.patchPython(version, initial);
123301
+ if (initial != patched) {
123302
+ pxt.debug(`applying PY patch to ${fn}`);
123303
+ opts.fileSystem[fn] = patched;
123304
+ }
123305
+ }
123306
+ }
123307
+ }
123308
+ pxt.patchPY = patchPY;
123262
123309
  function setupSimpleCompile(cfg) {
123263
123310
  if (typeof global != "undefined" && !global.btoa) {
123264
123311
  global.btoa = function (str) { return Buffer.from(str, "binary").toString("base64"); };
@@ -141734,7 +141781,7 @@ var ts;
141734
141781
  }
141735
141782
  const type = checker === null || checker === void 0 ? void 0 : checker.getTypeAtLocation(param);
141736
141783
  const typeSymbol = service.getPxtSymbolFromTsSymbol(type === null || type === void 0 ? void 0 : type.symbol, apis, checker);
141737
- if (((typeSymbol === null || typeSymbol === void 0 ? void 0 : typeSymbol.attributes.fixedInstances) || (typeSymbol === null || typeSymbol === void 0 ? void 0 : typeSymbol.attributes.emitAsConstant)) && python) {
141784
+ if ((typeSymbol === null || typeSymbol === void 0 ? void 0 : typeSymbol.attributes.fixedInstances) && python) {
141738
141785
  return pxt.Util.snakify(paramDefl);
141739
141786
  }
141740
141787
  if (python) {
@@ -31,6 +31,7 @@ declare namespace pxt {
31
31
  function simpleGetCompileOptionsAsync(files: pxt.Map<string>, simpleOptions: SimpleCompileOptions): Promise<pxtc.CompileOptions>;
32
32
  function simpleCompileAsync(files: pxt.Map<string>, optionsOrNative?: SimpleCompileOptions | boolean): Promise<CompileResultWithErrors>;
33
33
  function patchTS(version: string, opts: pxtc.CompileOptions): void;
34
+ function patchPY(version: string, opts: pxtc.CompileOptions): void;
34
35
  function setupSimpleCompile(cfg?: SimpleDriverCallbacks): void;
35
36
  }
36
37
  declare namespace pxt {
@@ -141,6 +141,9 @@ var pxt;
141
141
  return mainPkg.getCompileOptionsAsync(target);
142
142
  }).then(opts => {
143
143
  patchTS(mainPkg.targetVersion(), opts);
144
+ if (mainPkg.getPreferredEditor() === pxt.PYTHON_PROJECT_NAME) {
145
+ patchPY(mainPkg.targetVersion(), opts);
146
+ }
144
147
  prepPythonOptions(opts);
145
148
  return opts;
146
149
  });
@@ -174,6 +177,22 @@ var pxt;
174
177
  }
175
178
  }
176
179
  pxt.patchTS = patchTS;
180
+ function patchPY(version, opts) {
181
+ if (!version)
182
+ return;
183
+ pxt.debug(`applying PY patches relative to ${version}`);
184
+ for (let fn of Object.keys(opts.fileSystem)) {
185
+ if (fn.indexOf("/") == -1 && pxt.U.endsWith(fn, ".py")) {
186
+ const initial = opts.fileSystem[fn];
187
+ const patched = pxt.patching.patchPython(version, initial);
188
+ if (initial != patched) {
189
+ pxt.debug(`applying PY patch to ${fn}`);
190
+ opts.fileSystem[fn] = patched;
191
+ }
192
+ }
193
+ }
194
+ }
195
+ pxt.patchPY = patchPY;
177
196
  function setupSimpleCompile(cfg) {
178
197
  if (typeof global != "undefined" && !global.btoa) {
179
198
  global.btoa = function (str) { return Buffer.from(str, "binary").toString("base64"); };
@@ -18649,7 +18668,7 @@ var ts;
18649
18668
  }
18650
18669
  const type = checker === null || checker === void 0 ? void 0 : checker.getTypeAtLocation(param);
18651
18670
  const typeSymbol = service.getPxtSymbolFromTsSymbol(type === null || type === void 0 ? void 0 : type.symbol, apis, checker);
18652
- if (((typeSymbol === null || typeSymbol === void 0 ? void 0 : typeSymbol.attributes.fixedInstances) || (typeSymbol === null || typeSymbol === void 0 ? void 0 : typeSymbol.attributes.emitAsConstant)) && python) {
18671
+ if ((typeSymbol === null || typeSymbol === void 0 ? void 0 : typeSymbol.attributes.fixedInstances) && python) {
18653
18672
  return pxt.Util.snakify(paramDefl);
18654
18673
  }
18655
18674
  if (python) {
package/built/pxtlib.d.ts CHANGED
@@ -1986,8 +1986,10 @@ declare namespace pxt.packetio {
1986
1986
  }
1987
1987
  declare namespace pxt.patching {
1988
1988
  function computePatches(version: string, kind?: string): ts.pxtc.UpgradePolicy[];
1989
+ function computePyPatches(version: string, kind?: string): ts.pxtc.UpgradePolicy[];
1989
1990
  function upgradePackageReference(pkgTargetVersion: string, pkg: string, val: string): string;
1990
1991
  function patchJavaScript(pkgTargetVersion: string, fileContents: string): string;
1992
+ function patchPython(pkgTargetVersion: string, fileContents: string): string;
1991
1993
  }
1992
1994
  declare namespace pxt.react {
1993
1995
  interface FieldEditorView<U> {
@@ -3658,6 +3660,7 @@ declare namespace pxt.Cloud {
3658
3660
  function downloadTargetConfigAsync(): Promise<pxt.TargetConfig>;
3659
3661
  function downloadScriptFilesAsync(id: string): Promise<Map<string>>;
3660
3662
  function downloadScriptMetaAsync(id: string): Promise<JsonScriptMeta>;
3663
+ function downloadBuiltSimJsInfoAsync(id: string): Promise<pxtc.BuiltSimJsInfo>;
3661
3664
  function markdownAsync(docid: string, locale?: string, propagateExceptions?: boolean): Promise<string>;
3662
3665
  function privateDeleteAsync(path: string): Promise<any>;
3663
3666
  function privatePostAsync(path: string, data: any, forceLiveEndpoint?: boolean): Promise<any>;
package/built/pxtlib.js CHANGED
@@ -16718,6 +16718,17 @@ var pxt;
16718
16718
  const patches = pxt.appTarget.compile ? pxt.appTarget.compile.patches : undefined;
16719
16719
  if (!patches)
16720
16720
  return undefined;
16721
+ return parsePatches(version, patches, kind);
16722
+ }
16723
+ patching.computePatches = computePatches;
16724
+ function computePyPatches(version, kind) {
16725
+ const patches = pxt.appTarget.compile ? pxt.appTarget.compile.pyPatches : undefined;
16726
+ if (!patches)
16727
+ return undefined;
16728
+ return parsePatches(version, patches, kind);
16729
+ }
16730
+ patching.computePyPatches = computePyPatches;
16731
+ function parsePatches(version, patches, kind) {
16721
16732
  const v = pxt.semver.tryParse(version || "0.0.0") || pxt.semver.tryParse("0.0.0");
16722
16733
  let r = [];
16723
16734
  Object.keys(patches)
@@ -16727,7 +16738,6 @@ var pxt;
16727
16738
  r = r.filter(p => p.type == kind);
16728
16739
  return r.length ? r : undefined;
16729
16740
  }
16730
- patching.computePatches = computePatches;
16731
16741
  function upgradePackageReference(pkgTargetVersion, pkg, val) {
16732
16742
  if (val != "*")
16733
16743
  return pkg;
@@ -16747,6 +16757,15 @@ var pxt;
16747
16757
  patching.upgradePackageReference = upgradePackageReference;
16748
16758
  function patchJavaScript(pkgTargetVersion, fileContents) {
16749
16759
  const upgrades = pxt.patching.computePatches(pkgTargetVersion);
16760
+ return patchTextCode(pkgTargetVersion, fileContents, upgrades);
16761
+ }
16762
+ patching.patchJavaScript = patchJavaScript;
16763
+ function patchPython(pkgTargetVersion, fileContents) {
16764
+ const upgrades = pxt.patching.computePyPatches(pkgTargetVersion);
16765
+ return patchTextCode(pkgTargetVersion, fileContents, upgrades);
16766
+ }
16767
+ patching.patchPython = patchPython;
16768
+ function patchTextCode(pkgTargetVersion, fileContents, upgrades) {
16750
16769
  let updatedContents = fileContents;
16751
16770
  if (upgrades) {
16752
16771
  upgrades.filter(u => u.type === "api").forEach(rule => {
@@ -16766,7 +16785,6 @@ var pxt;
16766
16785
  }
16767
16786
  return updatedContents;
16768
16787
  }
16769
- patching.patchJavaScript = patchJavaScript;
16770
16788
  })(patching = pxt.patching || (pxt.patching = {}));
16771
16789
  })(pxt || (pxt = {}));
16772
16790
  var pxt;
@@ -24703,6 +24721,16 @@ var pxt;
24703
24721
  });
24704
24722
  }
24705
24723
  Cloud.downloadScriptMetaAsync = downloadScriptMetaAsync;
24724
+ async function downloadBuiltSimJsInfoAsync(id) {
24725
+ const targetVersion = pxt.appTarget.versions && pxt.appTarget.versions.target || "";
24726
+ const url = pxt.U.stringifyQueryString(id + "/js", { v: "v" + targetVersion }) + (id.startsWith("S") ? `&time=${Date.now()}` : "");
24727
+ const resp = await privateRequestAsync({
24728
+ url,
24729
+ forceLiveEndpoint: true,
24730
+ });
24731
+ return resp.json;
24732
+ }
24733
+ Cloud.downloadBuiltSimJsInfoAsync = downloadBuiltSimJsInfoAsync;
24706
24734
  async function markdownAsync(docid, locale, propagateExceptions) {
24707
24735
  // 1h check on markdown content if not on development server
24708
24736
  const MARKDOWN_EXPIRATION = pxt.BrowserUtils.isLocalHostDev() ? 0 : 1 * 60 * 60 * 1000;
@@ -115,6 +115,7 @@ declare namespace pxt.runner {
115
115
  function preloadSim(container: HTMLElement, simOpts: SimulateOptions): void;
116
116
  function currentDriver(): pxsim.SimulatorDriver;
117
117
  function postSimMessage(msg: pxsim.SimulatorMessage): void;
118
+ function fetchSimJsInfo(simOptions: SimulateOptions): Promise<pxtc.BuiltSimJsInfo>;
118
119
  function buildSimJsInfo(simOptions: SimulateOptions): Promise<pxtc.BuiltSimJsInfo>;
119
120
  enum LanguageMode {
120
121
  Blocks = 0,
@@ -1734,7 +1734,7 @@ var pxt;
1734
1734
  runner.generateVMFileAsync = generateVMFileAsync;
1735
1735
  async function simulateAsync(container, simOptions) {
1736
1736
  var _a, _b;
1737
- const builtSimJS = simOptions.builtJsInfo || await buildSimJsInfo(simOptions);
1737
+ const builtSimJS = simOptions.builtJsInfo || await fetchSimJsInfo(simOptions) || await buildSimJsInfo(simOptions);
1738
1738
  const { js } = builtSimJS;
1739
1739
  if (!js) {
1740
1740
  console.error("Program failed to compile");
@@ -1815,6 +1815,17 @@ var pxt;
1815
1815
  simDriver === null || simDriver === void 0 ? void 0 : simDriver.postMessage(msg);
1816
1816
  }
1817
1817
  runner.postSimMessage = postSimMessage;
1818
+ async function fetchSimJsInfo(simOptions) {
1819
+ try {
1820
+ return await pxt.Cloud.downloadBuiltSimJsInfoAsync(simOptions.id);
1821
+ }
1822
+ catch (e) {
1823
+ // This exception will happen in the majority of cases, so we don't want to log it unless for debugging.
1824
+ pxt.debug(e.toString());
1825
+ return undefined;
1826
+ }
1827
+ }
1828
+ runner.fetchSimJsInfo = fetchSimJsInfo;
1818
1829
  async function buildSimJsInfo(simOptions) {
1819
1830
  var _a;
1820
1831
  await loadPackageAsync(simOptions.id, simOptions.code, simOptions.dependencies);