pxt-core 7.5.44 → 7.5.47

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
@@ -107990,6 +107990,12 @@ var pxt;
107990
107990
  GitRepoStatus[GitRepoStatus["Approved"] = 1] = "Approved";
107991
107991
  GitRepoStatus[GitRepoStatus["Banned"] = 2] = "Banned";
107992
107992
  })(GitRepoStatus = github.GitRepoStatus || (github.GitRepoStatus = {}));
107993
+ function isDefaultBranch(branch, repo) {
107994
+ if (repo && repo.defaultBranch)
107995
+ return branch === repo.defaultBranch;
107996
+ return /^(main|master)$/.test(branch);
107997
+ }
107998
+ github.isDefaultBranch = isDefaultBranch;
107993
107999
  function listUserReposAsync() {
107994
108000
  const q = `{
107995
108001
  viewer {
@@ -108007,12 +108013,12 @@ var pxt;
108007
108013
  defaultBranchRef {
108008
108014
  name
108009
108015
  }
108010
- pxtjson: object(expression: "master:pxt.json") {
108016
+ pxtjson: object(expression: "HEAD:pxt.json") {
108011
108017
  ... on Blob {
108012
108018
  text
108013
108019
  }
108014
108020
  }
108015
- readme: object(expression: "master:README.md") {
108021
+ readme: object(expression: "HEAD:README.md") {
108016
108022
  ... on Blob {
108017
108023
  text
108018
108024
  }
@@ -140367,6 +140373,7 @@ var pxt;
140367
140373
  return mkType({ primType: tp });
140368
140374
  }
140369
140375
  function getOrSetSymbolType(sym) {
140376
+ var _a;
140370
140377
  if (!sym.pySymbolType) {
140371
140378
  currErrorCtx = sym.pyQName;
140372
140379
  if (sym.parameters) {
@@ -140388,8 +140395,24 @@ var pxt;
140388
140395
  sym.pyRetType = mkType({ moduleType: sym });
140389
140396
  }
140390
140397
  else {
140391
- if (sym.retType)
140392
- sym.pyRetType = mapTsType(sym.retType);
140398
+ if (sym.retType) {
140399
+ if (((_a = sym.qName) === null || _a === void 0 ? void 0 : _a.endsWith(".__constructor")) && sym.retType === "void") {
140400
+ // This must be a TS class. Because python treats constructors as functions,
140401
+ // set the return type to be the class instead of void
140402
+ const classSym = lookupGlobalSymbol(sym.qName.substring(0, sym.qName.lastIndexOf(".")));
140403
+ if (classSym) {
140404
+ sym.pyRetType = mkType({
140405
+ classType: classSym
140406
+ });
140407
+ }
140408
+ else {
140409
+ sym.pyRetType = mapTsType(sym.retType);
140410
+ }
140411
+ }
140412
+ else {
140413
+ sym.pyRetType = mapTsType(sym.retType);
140414
+ }
140415
+ }
140393
140416
  else if (sym.pyRetType) {
140394
140417
  // nothing to do
140395
140418
  }
@@ -140422,11 +140445,19 @@ var pxt;
140422
140445
  return pxt.U.lookup(internalApis, name) || pxt.U.lookup(externalApis, name);
140423
140446
  }
140424
140447
  function lookupGlobalSymbol(name) {
140448
+ var _a;
140425
140449
  if (!name)
140426
140450
  return undefined;
140427
140451
  let sym = lookupApi(name);
140428
140452
  if (sym)
140429
140453
  getOrSetSymbolType(sym);
140454
+ else if (name.indexOf(".") && !name.endsWith(".__constructor")) {
140455
+ const base = name.substring(0, name.lastIndexOf("."));
140456
+ const baseSymbol = lookupGlobalSymbol(base);
140457
+ if ((baseSymbol === null || baseSymbol === void 0 ? void 0 : baseSymbol.kind) === 8 /* Class */ && ((_a = baseSymbol.extendsTypes) === null || _a === void 0 ? void 0 : _a.length)) {
140458
+ return lookupGlobalSymbol(baseSymbol.extendsTypes[0] + name.substring(base.length));
140459
+ }
140460
+ }
140430
140461
  return sym;
140431
140462
  }
140432
140463
  function initApis(apisInfo, tsShadowFiles) {
@@ -140509,7 +140540,10 @@ var pxt;
140509
140540
  pref += ".";
140510
140541
  }
140511
140542
  let qualifiedName = pref + name;
140512
- if (isLocalScope(scope)
140543
+ if (scope.kind === "ClassDef") {
140544
+ varSym = addSymbol(2 /* Property */, qualifiedName);
140545
+ }
140546
+ else if (isLocalScope(scope)
140513
140547
  && (modifier === py_1.VarModifier.Global
140514
140548
  || modifier === py_1.VarModifier.NonLocal)) {
140515
140549
  varSym = addSymbol(4 /* Variable */, name);
@@ -140623,7 +140657,7 @@ var pxt;
140623
140657
  };
140624
140658
  }
140625
140659
  }
140626
- // next free error 9575
140660
+ // next free error 9576
140627
140661
  function error(astNode, code, msg) {
140628
140662
  diagnostics.push(mkDiag(astNode, pxtc.DiagnosticCategory.Error, code, msg));
140629
140663
  //const pos = position(astNode ? astNode.startPos || 0 : 0, mod.source)
@@ -140838,8 +140872,19 @@ var pxt;
140838
140872
  let qn = cd.symInfo.qName;
140839
140873
  return pxt.U.values(internalApis).filter(e => e.namespace == qn && e.kind == 2 /* Property */);
140840
140874
  }
140841
- function getClassField(ct, n, checkOnly = false, skipBases = false) {
140842
- let qid = ct.pyQName + "." + n;
140875
+ function getClassField(ct, n, isStatic, checkOnly = false, skipBases = false) {
140876
+ let qid;
140877
+ if (n === "__init__") {
140878
+ qid = ct.pyQName + ".__constructor";
140879
+ }
140880
+ else {
140881
+ if (n.startsWith(ct.pyQName + ".")) {
140882
+ qid = n;
140883
+ }
140884
+ else {
140885
+ qid = ct.pyQName + "." + n;
140886
+ }
140887
+ }
140843
140888
  let f = lookupGlobalSymbol(qid);
140844
140889
  if (f)
140845
140890
  return f;
@@ -140849,7 +140894,7 @@ var pxt;
140849
140894
  if (sym) {
140850
140895
  if (sym == ct)
140851
140896
  pxt.U.userError("field lookup loop on: " + sym.qName + " / " + n);
140852
- let classF = getClassField(sym, n, true);
140897
+ let classF = getClassField(sym, n, isStatic, true);
140853
140898
  if (classF)
140854
140899
  return classF;
140855
140900
  }
@@ -140857,7 +140902,7 @@ var pxt;
140857
140902
  }
140858
140903
  if (!checkOnly && ct.pyAST && ct.pyAST.kind == "ClassDef") {
140859
140904
  let sym = addSymbol(2 /* Property */, qid);
140860
- sym.isInstance = true;
140905
+ sym.isInstance = !isStatic;
140861
140906
  return sym;
140862
140907
  }
140863
140908
  return null;
@@ -140874,16 +140919,14 @@ var pxt;
140874
140919
  const recvType = typeOf(recv);
140875
140920
  const constructorTypes = getTypesForFieldLookup(recvType);
140876
140921
  for (let ct of constructorTypes) {
140877
- let f = getClassField(ct, n, checkOnly);
140922
+ let isModule = !!recvType.moduleType;
140923
+ let f = getClassField(ct, n, isModule, checkOnly);
140878
140924
  if (f) {
140879
- let isModule = !!recvType.moduleType;
140880
140925
  if (isModule) {
140881
140926
  if (f.isInstance)
140882
140927
  error(null, 9505, pxt.U.lf("the field '{0}' of '{1}' is not static", n, ct.pyQName));
140883
140928
  }
140884
140929
  else {
140885
- if (!f.isInstance)
140886
- error(null, 9504, pxt.U.lf("the field '{0}' of '{1}' is static", n, ct.pyQName));
140887
140930
  if (isSuper(recv))
140888
140931
  f.isProtected = true;
140889
140932
  else if (isThis(recv)) {
@@ -141066,14 +141109,17 @@ var pxt;
141066
141109
  return mkType({});
141067
141110
  }
141068
141111
  function doArgs(n, isMethod) {
141112
+ var _a;
141069
141113
  const args = n.args;
141070
141114
  if (args.kwonlyargs.length)
141071
141115
  error(n, 9517, pxt.U.lf("keyword-only arguments not supported yet"));
141072
141116
  let nargs = args.args.slice();
141073
141117
  if (isMethod) {
141074
- if (nargs[0].arg != "self")
141075
- error(n, 9518, pxt.U.lf("first argument of method has to be called 'self'"));
141076
- nargs.shift();
141118
+ if (((_a = nargs[0]) === null || _a === void 0 ? void 0 : _a.arg) !== "self")
141119
+ n.symInfo.isStatic = true;
141120
+ else {
141121
+ nargs.shift();
141122
+ }
141077
141123
  }
141078
141124
  else {
141079
141125
  if (nargs.some(a => a.arg == "self"))
@@ -141235,6 +141281,7 @@ var pxt;
141235
141281
  }
141236
141282
  function emitFunctionDef(n, inline = false) {
141237
141283
  return guardedScope(n, () => {
141284
+ var _a, _b, _c, _d;
141238
141285
  const isMethod = !!ctx.currClass && !ctx.currFun;
141239
141286
  const topLev = isTopLevel();
141240
141287
  const nested = !!ctx.currFun;
@@ -141287,7 +141334,7 @@ var pxt;
141287
141334
  let scopeValueVar = n.vars["value"];
141288
141335
  let valueVar = scopeValueVar === null || scopeValueVar === void 0 ? void 0 : scopeValueVar.symbol;
141289
141336
  if (funname == "__set__" && valueVar) {
141290
- let cf = getClassField(ctx.currClass.symInfo, "__get__");
141337
+ let cf = getClassField(ctx.currClass.symInfo, "__get__", false);
141291
141338
  if (cf && cf.pyAST && cf.pyAST.kind == "FunctionDef")
141292
141339
  unify(n, valueVar.pyRetType, cf.pyRetType);
141293
141340
  }
@@ -141295,6 +141342,9 @@ var pxt;
141295
141342
  }
141296
141343
  if (!prefix) {
141297
141344
  prefix = funname[0] == "_" ? (sym.isProtected ? "protected" : "private") : "public";
141345
+ if (n.symInfo.isStatic) {
141346
+ prefix += " static";
141347
+ }
141298
141348
  }
141299
141349
  nodes.push(B.mkText(prefix + " "), quote(funname));
141300
141350
  }
@@ -141306,7 +141356,7 @@ var pxt;
141306
141356
  else
141307
141357
  nodes.push(B.mkText("export function "), quote(funname));
141308
141358
  }
141309
- let retType = n.returns ? compileType(n.returns) : sym.pyRetType;
141359
+ let retType = n.name == "__init__" ? undefined : (n.returns ? compileType(n.returns) : sym.pyRetType);
141310
141360
  nodes.push(doArgs(n, isMethod), retType && canonicalize(retType) != tpVoid ? typeAnnot(retType) : B.mkText(""));
141311
141361
  // make sure type is initialized
141312
141362
  getOrSetSymbolType(sym);
@@ -141314,6 +141364,13 @@ var pxt;
141314
141364
  if (n.name == "__init__") {
141315
141365
  if (!ctx.currClass)
141316
141366
  error(n, 9533, lf("__init__ method '{0}' is missing current class context", sym.pyQName));
141367
+ if ((_a = ctx.currClass) === null || _a === void 0 ? void 0 : _a.baseClass) {
141368
+ const firstStatement = n.body[0];
141369
+ const superConstructor = ctx.currClass.baseClass.pyQName + ".__constructor";
141370
+ if (((_d = (_c = (_b = firstStatement.value) === null || _b === void 0 ? void 0 : _b.func) === null || _c === void 0 ? void 0 : _c.symbolInfo) === null || _d === void 0 ? void 0 : _d.pyQName) !== superConstructor) {
141371
+ error(n, 9575, lf("Sub classes must call 'super().__init__' as the first statement inside an __init__ method"));
141372
+ }
141373
+ }
141317
141374
  for (let f of listClassFields(ctx.currClass)) {
141318
141375
  let p = f.pyAST;
141319
141376
  if (p && p.value) {
@@ -141357,22 +141414,61 @@ var pxt;
141357
141414
  nodes.push(B.mkCommaSep(n.bases.map(expr)));
141358
141415
  let b = getClassDef(n.bases[0]);
141359
141416
  if (b) {
141360
- n.baseClass = b;
141417
+ n.baseClass = b.symInfo;
141361
141418
  sym.extendsTypes = [b.symInfo.pyQName];
141362
141419
  }
141420
+ else {
141421
+ const nm = tryGetName(n.bases[0]);
141422
+ if (nm) {
141423
+ const localSym = lookupSymbol(nm);
141424
+ const globalSym = lookupGlobalSymbol(nm);
141425
+ n.baseClass = localSym || globalSym;
141426
+ if (n.baseClass)
141427
+ sym.extendsTypes = [n.baseClass.pyQName];
141428
+ }
141429
+ }
141363
141430
  }
141364
141431
  }
141365
- let body = stmts(n.body);
141432
+ const classDefs = n.body.filter(s => n.isNamespace || s.kind === "FunctionDef");
141433
+ const staticStmts = n.isNamespace ? [] : n.body.filter(s => classDefs.indexOf(s) === -1 && s.kind !== "Pass");
141434
+ let body = stmts(classDefs);
141366
141435
  nodes.push(body);
141367
- let fieldDefs = listClassFields(n)
141368
- .filter(f => f.kind == 2 /* Property */ && f.isInstance)
141369
- .map(f => {
141370
- if (!f.pyName || !f.pyRetType)
141371
- error(n, 9535, lf("field definition missing py name or ret type", f.qName));
141372
- return f;
141373
- })
141374
- .map((f) => B.mkStmt(accessAnnot(f), quote(f.pyName), typeAnnot(f.pyRetType)));
141375
- body.children = fieldDefs.concat(body.children);
141436
+ // Python classes allow arbitrary statements in their bodies, sort of like namespaces.
141437
+ // Take all of these statements and put them in a static method that we can call when
141438
+ // the class is defined.
141439
+ let generatedInitFunction = false;
141440
+ if (staticStmts.length) {
141441
+ generatedInitFunction = true;
141442
+ const staticBody = stmts(staticStmts);
141443
+ const initFun = B.mkStmt(B.mkGroup([
141444
+ B.mkText(`public static __init${n.name}() `),
141445
+ staticBody
141446
+ ]));
141447
+ body.children.unshift(initFun);
141448
+ }
141449
+ if (!n.isNamespace) {
141450
+ const fieldDefs = listClassFields(n)
141451
+ .map(f => {
141452
+ if (!f.pyName || !f.pyRetType)
141453
+ error(n, 9535, lf("field definition missing py name or return type", f.qName));
141454
+ return f;
141455
+ });
141456
+ const staticFieldSymbols = fieldDefs.filter(f => !f.isInstance);
141457
+ const instanceFields = fieldDefs.filter(f => f.isInstance)
141458
+ .map((f) => B.mkStmt(accessAnnot(f), quote(f.pyName), typeAnnot(f.pyRetType)));
141459
+ const staticFields = staticFieldSymbols
141460
+ .map((f) => B.mkGroup([
141461
+ B.mkStmt(accessAnnot(f), B.mkText("static "), quote(f.pyName), typeAnnot(f.pyRetType)),
141462
+ declareLocalStatic(quoteStr(n.name), quoteStr(f.pyName), t2s(f.pyRetType))
141463
+ ]));
141464
+ body.children = staticFields.concat(instanceFields).concat(body.children);
141465
+ }
141466
+ if (generatedInitFunction) {
141467
+ nodes = [
141468
+ B.mkStmt(B.mkGroup(nodes)),
141469
+ B.mkStmt(B.mkText(`${n.name}.__init${n.name}()`))
141470
+ ];
141471
+ }
141376
141472
  return B.mkStmt(B.mkGroup(nodes));
141377
141473
  }),
141378
141474
  Return: (n) => {
@@ -141679,7 +141775,7 @@ var pxt;
141679
141775
  // class fields can't be const
141680
141776
  // hack: value in @namespace should always be const
141681
141777
  isConstCall = !!(value && ctx.currClass.isNamespace);
141682
- let fd = getClassField(ctx.currClass.symInfo, nm);
141778
+ let fd = getClassField(ctx.currClass.symInfo, nm, true);
141683
141779
  if (!fd)
141684
141780
  error(n, 9544, lf("cannot get class field"));
141685
141781
  // TODO: use or remove this code
@@ -141721,7 +141817,9 @@ var pxt;
141721
141817
  error(n, 9539, lf("function '{0}' missing return type", fd.pyQName));
141722
141818
  unifyTypeOf(target, fd.pyRetType);
141723
141819
  fd.isInstance = false;
141724
- pref = ctx.currClass.isNamespace ? `export ${isConstCall ? "const" : "let"} ` : "static ";
141820
+ if (ctx.currClass.isNamespace) {
141821
+ pref = `export ${isConstCall ? "const" : "let"} `;
141822
+ }
141725
141823
  }
141726
141824
  if (value)
141727
141825
  unifyTypeOf(target, typeOf(value));
@@ -141787,6 +141885,7 @@ var pxt;
141787
141885
  }
141788
141886
  }
141789
141887
  function possibleDef(n, excludeLet = false) {
141888
+ var _a, _b;
141790
141889
  let id = n.id;
141791
141890
  let currScopeVar = lookupScopeSymbol(id);
141792
141891
  let curr = currScopeVar === null || currScopeVar === void 0 ? void 0 : currScopeVar.symbol;
@@ -141821,6 +141920,10 @@ var pxt;
141821
141920
  if (n.isdef && !excludeLet) {
141822
141921
  return B.mkGroup([B.mkText("let "), quote(id)]);
141823
141922
  }
141923
+ else if ((curr === null || curr === void 0 ? void 0 : curr.namespace) && (curr === null || curr === void 0 ? void 0 : curr.qName) && !(((_a = ctx.currClass) === null || _a === void 0 ? void 0 : _a.isNamespace) && ((_b = ctx.currClass) === null || _b === void 0 ? void 0 : _b.name) === (curr === null || curr === void 0 ? void 0 : curr.namespace))) {
141924
+ // If this is a static variable in a class, we want the full qname
141925
+ return quote(curr.qName);
141926
+ }
141824
141927
  else
141825
141928
  return quote(id);
141826
141929
  }
@@ -141834,20 +141937,27 @@ var pxt;
141834
141937
  //return id.replace(/([a-z0-9])_([a-zA-Z0-9])/g, (f: string, x: string, y: string) => x + y.toUpperCase())
141835
141938
  }
141836
141939
  function tryGetName(e) {
141940
+ var _a;
141837
141941
  if (e.kind == "Name") {
141838
141942
  let s = e.id;
141839
141943
  let scopeV = lookupVar(s);
141840
141944
  let v = scopeV === null || scopeV === void 0 ? void 0 : scopeV.symbol;
141841
- if (v && v.expandsTo)
141842
- return v.expandsTo;
141843
- else
141844
- return s;
141945
+ if (v) {
141946
+ if (v.expandsTo)
141947
+ return v.expandsTo;
141948
+ else if (ctx.currClass && !ctx.currFun && !(scopeV === null || scopeV === void 0 ? void 0 : scopeV.modifier) && v.qName)
141949
+ return v.qName;
141950
+ }
141951
+ return s;
141845
141952
  }
141846
141953
  if (e.kind == "Attribute") {
141847
141954
  let pref = tryGetName(e.value);
141848
141955
  if (pref)
141849
141956
  return pref + "." + e.attr;
141850
141957
  }
141958
+ if (isSuper(e) && ((_a = ctx.currClass) === null || _a === void 0 ? void 0 : _a.baseClass)) {
141959
+ return ctx.currClass.baseClass.qName;
141960
+ }
141851
141961
  return undefined;
141852
141962
  }
141853
141963
  function getName(e) {
@@ -142055,6 +142165,7 @@ var pxt;
142055
142165
  return r;
142056
142166
  },
142057
142167
  Call: (n) => {
142168
+ var _a, _b, _c, _d, _e;
142058
142169
  // TODO(dz): move body out; needs seperate PR that doesn't touch content
142059
142170
  n.func.inCalledPosition = true;
142060
142171
  let nm = tryGetName(n.func);
@@ -142066,6 +142177,9 @@ var pxt;
142066
142177
  let methName = "";
142067
142178
  if (isClass) {
142068
142179
  fun = lookupSymbol(namedSymbol.pyQName + ".__constructor");
142180
+ if (!fun) {
142181
+ fun = addSymbolFor(3 /* Function */, createDummyConstructorSymbol(namedSymbol === null || namedSymbol === void 0 ? void 0 : namedSymbol.pyAST));
142182
+ }
142069
142183
  }
142070
142184
  else {
142071
142185
  if (n.func.kind == "Attribute") {
@@ -142085,7 +142199,7 @@ var pxt;
142085
142199
  if (ctx.currClass && ctx.currClass.baseClass) {
142086
142200
  if (!n.tsType)
142087
142201
  error(n, 9543, lf("call expr missing ts type"));
142088
- unifyClass(n, n.tsType, ctx.currClass.baseClass.symInfo);
142202
+ unifyClass(n, n.tsType, ctx.currClass.baseClass);
142089
142203
  }
142090
142204
  return B.mkText("super");
142091
142205
  }
@@ -142145,6 +142259,17 @@ var pxt;
142145
142259
  unify(n, n.tsType, tpString);
142146
142260
  return B.mkInfix(B.mkText(`""`), "+", expr(n.args[0]));
142147
142261
  }
142262
+ const isSuperAttribute = n.func.kind === "Attribute" && isSuper(n.func.value);
142263
+ if (!fun && isSuperAttribute) {
142264
+ fun = lookupGlobalSymbol(nm);
142265
+ }
142266
+ const isSuperConstructor = ((_a = ctx.currFun) === null || _a === void 0 ? void 0 : _a.name) === "__init__" &&
142267
+ (fun === null || fun === void 0 ? void 0 : fun.name) === "__constructor" &&
142268
+ ((_c = (_b = ctx.currClass) === null || _b === void 0 ? void 0 : _b.baseClass) === null || _c === void 0 ? void 0 : _c.pyQName) === (fun === null || fun === void 0 ? void 0 : fun.namespace) &&
142269
+ isSuperAttribute;
142270
+ if (isSuperConstructor) {
142271
+ fun = lookupSymbol(((_e = (_d = ctx.currClass) === null || _d === void 0 ? void 0 : _d.baseClass) === null || _e === void 0 ? void 0 : _e.pyQName) + ".__constructor");
142272
+ }
142148
142273
  if (!fun) {
142149
142274
  error(n, 9508, pxt.U.lf("can't find called function '{0}'", nm));
142150
142275
  }
@@ -142252,7 +142377,13 @@ var pxt;
142252
142377
  ]);
142253
142378
  }
142254
142379
  }
142255
- let fn = methName ? B.mkInfix(expr(recv), ".", B.mkText(methName)) : expr(n.func);
142380
+ let fn;
142381
+ if (isSuperConstructor) {
142382
+ fn = B.mkText("super");
142383
+ }
142384
+ else {
142385
+ fn = methName ? B.mkInfix(expr(recv), ".", B.mkText(methName)) : expr(n.func);
142386
+ }
142256
142387
  let nodes = [
142257
142388
  fn,
142258
142389
  B.mkText("("),
@@ -142909,6 +143040,68 @@ var pxt;
142909
143040
  break;
142910
143041
  }
142911
143042
  }
143043
+ function createDummyConstructorSymbol(def, sym = def.symInfo) {
143044
+ var _a;
143045
+ const existing = lookupApi(sym.pyQName + ".__constructor");
143046
+ if (!existing && ((_a = sym.extendsTypes) === null || _a === void 0 ? void 0 : _a.length)) {
143047
+ const parentSymbol = lookupSymbol(sym.extendsTypes[0]) || lookupGlobalSymbol(sym.extendsTypes[0]);
143048
+ if (parentSymbol) {
143049
+ return createDummyConstructorSymbol(def, parentSymbol);
143050
+ }
143051
+ }
143052
+ const result = {
143053
+ kind: "FunctionDef",
143054
+ name: "__init__",
143055
+ startPos: def.startPos,
143056
+ endPos: def.endPos,
143057
+ parent: def,
143058
+ body: [],
143059
+ args: {
143060
+ kind: "Arguments",
143061
+ startPos: 0,
143062
+ endPos: 0,
143063
+ args: [{
143064
+ startPos: 0,
143065
+ endPos: 0,
143066
+ kind: "Arg",
143067
+ arg: "self"
143068
+ }],
143069
+ kw_defaults: [],
143070
+ kwonlyargs: [],
143071
+ defaults: []
143072
+ },
143073
+ decorator_list: [],
143074
+ vars: {},
143075
+ symInfo: mkSymbol(3 /* Function */, def.symInfo.qName + ".__constructor")
143076
+ };
143077
+ result.symInfo.parameters = [];
143078
+ result.symInfo.pyRetType = mkType({ classType: def.symInfo });
143079
+ if (existing) {
143080
+ result.args.args.push(...existing.parameters.map(p => ({
143081
+ startPos: 0,
143082
+ endPos: 0,
143083
+ kind: "Arg",
143084
+ arg: p.name,
143085
+ })));
143086
+ result.symInfo.parameters.push(...existing.parameters.map(p => {
143087
+ if (p.pyType)
143088
+ return p;
143089
+ const res = Object.assign(Object.assign({}, p), { pyType: mapTsType(p.type) });
143090
+ return res;
143091
+ }));
143092
+ }
143093
+ return result;
143094
+ }
143095
+ function declareLocalStatic(className, name, type) {
143096
+ const isSetVar = `___${name}_is_set`;
143097
+ const localVar = `___${name}`;
143098
+ return B.mkStmt(B.mkStmt(B.mkText(`private ${isSetVar}: boolean`)), B.mkStmt(B.mkText(`private ${localVar}: ${type}`)), B.mkStmt(B.mkText(`get ${name}(): ${type}`), B.mkBlock([
143099
+ B.mkText(`return this.${isSetVar} ? this.${localVar} : ${className}.${name}`)
143100
+ ])), B.mkStmt(B.mkText(`set ${name}(value: ${type})`), B.mkBlock([
143101
+ B.mkStmt(B.mkText(`this.${isSetVar} = true`)),
143102
+ B.mkStmt(B.mkText(`this.${localVar} = value`)),
143103
+ ])));
143104
+ }
142912
143105
  })(py = pxt.py || (pxt.py = {}));
142913
143106
  })(pxt || (pxt = {}));
142914
143107
  // Lexer spec: https://docs.python.org/3/reference/lexical_analysis.html
@@ -12212,6 +12212,12 @@ var pxtblockly;
12212
12212
  // This creates the little arrow for dropdown fields. Intentionally
12213
12213
  // do nothing
12214
12214
  }
12215
+ showPromptEditor_() {
12216
+ Blockly.prompt(Blockly.Msg['CHANGE_VALUE_TITLE'], this.parsedValue, (newValue) => {
12217
+ this.setValue(this.getValueFromEditorText_(newValue));
12218
+ this.forceRerender();
12219
+ });
12220
+ }
12215
12221
  }
12216
12222
  pxtblockly.FieldAutoComplete = FieldAutoComplete;
12217
12223
  })(pxtblockly || (pxtblockly = {}));
@@ -14988,6 +14994,15 @@ var pxtblockly;
14988
14994
  }
14989
14995
  })(pxtblockly || (pxtblockly = {}));
14990
14996
  /// <reference path="../../localtypings/pxtblockly.d.ts" />
14997
+ // common time options -- do not remove
14998
+ // lf("100 ms")
14999
+ // lf("200 ms")
15000
+ // lf("500 ms")
15001
+ // lf("1 second")
15002
+ // lf("2 seconds")
15003
+ // lf("5 seconds")
15004
+ // lf("1 minute")
15005
+ // lf("1 hour")
14991
15006
  var pxtblockly;
14992
15007
  (function (pxtblockly) {
14993
15008
  class FieldNumberDropdown extends Blockly.FieldNumberDropdown {
@@ -14999,7 +15014,12 @@ var pxtblockly;
14999
15014
  let newOptions;
15000
15015
  if (this.menuGenerator_) {
15001
15016
  newOptions = JSON.parse(this.menuGenerator_).map((x) => {
15002
- return (typeof x == 'object') ? x : [String(x), String(x)];
15017
+ if (typeof x == 'object') {
15018
+ return [pxt.Util.rlf(x[0]), x[1]];
15019
+ }
15020
+ else {
15021
+ return [String(x), String(x)];
15022
+ }
15003
15023
  });
15004
15024
  }
15005
15025
  return newOptions;
@@ -15473,6 +15493,7 @@ var pxtblockly;
15473
15493
  widgetDiv.style.height = "";
15474
15494
  widgetDiv.style.opacity = "";
15475
15495
  widgetDiv.style.transition = "";
15496
+ widgetDiv.style.alignItems = "";
15476
15497
  Blockly.Events.enable();
15477
15498
  Blockly.Events.setGroup(true);
15478
15499
  this.fireNumberInputUpdate(this.options.durationInputName, initialSound.duration);
@@ -15514,7 +15535,8 @@ var pxtblockly;
15514
15535
  widgetDiv.style.top = top + "px";
15515
15536
  widgetDiv.style.width = "30rem";
15516
15537
  widgetDiv.style.height = "40rem";
15517
- widgetDiv.style.display = "block";
15538
+ widgetDiv.style.display = "flex";
15539
+ widgetDiv.style.alignItems = "center";
15518
15540
  widgetDiv.style.transition = "transform 0.25s ease 0s, opacity 0.25s ease 0s";
15519
15541
  widgetDiv.style.borderRadius = "";
15520
15542
  fv.onHide(() => {
@@ -558,6 +558,7 @@ declare namespace pxtblockly {
558
558
  positionRight(x: number): number;
559
559
  positionLeft(x: number): number;
560
560
  createSVGArrow_(): void;
561
+ showPromptEditor_(): void;
561
562
  }
562
563
  }
563
564
  declare namespace pxtblockly {
@@ -8650,6 +8650,12 @@ var pxtblockly;
8650
8650
  // This creates the little arrow for dropdown fields. Intentionally
8651
8651
  // do nothing
8652
8652
  }
8653
+ showPromptEditor_() {
8654
+ Blockly.prompt(Blockly.Msg['CHANGE_VALUE_TITLE'], this.parsedValue, (newValue) => {
8655
+ this.setValue(this.getValueFromEditorText_(newValue));
8656
+ this.forceRerender();
8657
+ });
8658
+ }
8653
8659
  }
8654
8660
  pxtblockly.FieldAutoComplete = FieldAutoComplete;
8655
8661
  })(pxtblockly || (pxtblockly = {}));
@@ -11426,6 +11432,15 @@ var pxtblockly;
11426
11432
  }
11427
11433
  })(pxtblockly || (pxtblockly = {}));
11428
11434
  /// <reference path="../../localtypings/pxtblockly.d.ts" />
11435
+ // common time options -- do not remove
11436
+ // lf("100 ms")
11437
+ // lf("200 ms")
11438
+ // lf("500 ms")
11439
+ // lf("1 second")
11440
+ // lf("2 seconds")
11441
+ // lf("5 seconds")
11442
+ // lf("1 minute")
11443
+ // lf("1 hour")
11429
11444
  var pxtblockly;
11430
11445
  (function (pxtblockly) {
11431
11446
  class FieldNumberDropdown extends Blockly.FieldNumberDropdown {
@@ -11437,7 +11452,12 @@ var pxtblockly;
11437
11452
  let newOptions;
11438
11453
  if (this.menuGenerator_) {
11439
11454
  newOptions = JSON.parse(this.menuGenerator_).map((x) => {
11440
- return (typeof x == 'object') ? x : [String(x), String(x)];
11455
+ if (typeof x == 'object') {
11456
+ return [pxt.Util.rlf(x[0]), x[1]];
11457
+ }
11458
+ else {
11459
+ return [String(x), String(x)];
11460
+ }
11441
11461
  });
11442
11462
  }
11443
11463
  return newOptions;
@@ -11911,6 +11931,7 @@ var pxtblockly;
11911
11931
  widgetDiv.style.height = "";
11912
11932
  widgetDiv.style.opacity = "";
11913
11933
  widgetDiv.style.transition = "";
11934
+ widgetDiv.style.alignItems = "";
11914
11935
  Blockly.Events.enable();
11915
11936
  Blockly.Events.setGroup(true);
11916
11937
  this.fireNumberInputUpdate(this.options.durationInputName, initialSound.duration);
@@ -11952,7 +11973,8 @@ var pxtblockly;
11952
11973
  widgetDiv.style.top = top + "px";
11953
11974
  widgetDiv.style.width = "30rem";
11954
11975
  widgetDiv.style.height = "40rem";
11955
- widgetDiv.style.display = "block";
11976
+ widgetDiv.style.display = "flex";
11977
+ widgetDiv.style.alignItems = "center";
11956
11978
  widgetDiv.style.transition = "transform 0.25s ease 0s, opacity 0.25s ease 0s";
11957
11979
  widgetDiv.style.borderRadius = "";
11958
11980
  fv.onHide(() => {
package/built/pxtlib.d.ts CHANGED
@@ -1305,6 +1305,7 @@ declare namespace pxt.github {
1305
1305
  private?: boolean;
1306
1306
  fork?: boolean;
1307
1307
  }
1308
+ function isDefaultBranch(branch: string, repo?: GitRepo): boolean;
1308
1309
  function listUserReposAsync(): Promise<GitRepo[]>;
1309
1310
  function createRepoAsync(name: string, description: string, priv?: boolean): Promise<GitRepo>;
1310
1311
  function enablePagesAsync(repo: string): Promise<void>;
package/built/pxtlib.js CHANGED
@@ -10304,6 +10304,12 @@ var pxt;
10304
10304
  GitRepoStatus[GitRepoStatus["Approved"] = 1] = "Approved";
10305
10305
  GitRepoStatus[GitRepoStatus["Banned"] = 2] = "Banned";
10306
10306
  })(GitRepoStatus = github.GitRepoStatus || (github.GitRepoStatus = {}));
10307
+ function isDefaultBranch(branch, repo) {
10308
+ if (repo && repo.defaultBranch)
10309
+ return branch === repo.defaultBranch;
10310
+ return /^(main|master)$/.test(branch);
10311
+ }
10312
+ github.isDefaultBranch = isDefaultBranch;
10307
10313
  function listUserReposAsync() {
10308
10314
  const q = `{
10309
10315
  viewer {
@@ -10321,12 +10327,12 @@ var pxt;
10321
10327
  defaultBranchRef {
10322
10328
  name
10323
10329
  }
10324
- pxtjson: object(expression: "master:pxt.json") {
10330
+ pxtjson: object(expression: "HEAD:pxt.json") {
10325
10331
  ... on Blob {
10326
10332
  text
10327
10333
  }
10328
10334
  }
10329
- readme: object(expression: "master:README.md") {
10335
+ readme: object(expression: "HEAD:README.md") {
10330
10336
  ... on Blob {
10331
10337
  text
10332
10338
  }