pxt-core 7.5.45 → 7.5.46
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 +94 -22
- package/built/pxtpy.js +94 -22
- package/built/target.js +1 -1
- package/built/web/pxtembed.js +1 -1
- package/built/web/pxtpy.js +1 -1
- package/built/web/pxtworker.js +1 -1
- package/package.json +1 -1
package/built/pxt.js
CHANGED
|
@@ -140428,7 +140428,7 @@ var pxt;
|
|
|
140428
140428
|
let sym = lookupApi(name);
|
|
140429
140429
|
if (sym)
|
|
140430
140430
|
getOrSetSymbolType(sym);
|
|
140431
|
-
else if (name.indexOf(".")) {
|
|
140431
|
+
else if (name.indexOf(".") && !name.endsWith(".__constructor")) {
|
|
140432
140432
|
const base = name.substring(0, name.lastIndexOf("."));
|
|
140433
140433
|
const baseSymbol = lookupGlobalSymbol(base);
|
|
140434
140434
|
if ((baseSymbol === null || baseSymbol === void 0 ? void 0 : baseSymbol.kind) === 8 /* Class */ && ((_a = baseSymbol.extendsTypes) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
@@ -140517,7 +140517,10 @@ var pxt;
|
|
|
140517
140517
|
pref += ".";
|
|
140518
140518
|
}
|
|
140519
140519
|
let qualifiedName = pref + name;
|
|
140520
|
-
if (
|
|
140520
|
+
if (scope.kind === "ClassDef") {
|
|
140521
|
+
varSym = addSymbol(2 /* Property */, qualifiedName);
|
|
140522
|
+
}
|
|
140523
|
+
else if (isLocalScope(scope)
|
|
140521
140524
|
&& (modifier === py_1.VarModifier.Global
|
|
140522
140525
|
|| modifier === py_1.VarModifier.NonLocal)) {
|
|
140523
140526
|
varSym = addSymbol(4 /* Variable */, name);
|
|
@@ -140842,17 +140845,22 @@ var pxt;
|
|
|
140842
140845
|
return n.symInfo;
|
|
140843
140846
|
}
|
|
140844
140847
|
// TODO optimize ?
|
|
140845
|
-
function listClassFields(cd
|
|
140848
|
+
function listClassFields(cd) {
|
|
140846
140849
|
let qn = cd.symInfo.qName;
|
|
140847
|
-
return pxt.U.values(internalApis).filter(e => e.namespace == qn &&
|
|
140850
|
+
return pxt.U.values(internalApis).filter(e => e.namespace == qn && e.kind == 2 /* Property */);
|
|
140848
140851
|
}
|
|
140849
|
-
function getClassField(ct, n, checkOnly = false, skipBases = false) {
|
|
140852
|
+
function getClassField(ct, n, isStatic, checkOnly = false, skipBases = false) {
|
|
140850
140853
|
let qid;
|
|
140851
140854
|
if (n === "__init__") {
|
|
140852
140855
|
qid = ct.pyQName + ".__constructor";
|
|
140853
140856
|
}
|
|
140854
140857
|
else {
|
|
140855
|
-
|
|
140858
|
+
if (n.startsWith(ct.pyQName + ".")) {
|
|
140859
|
+
qid = n;
|
|
140860
|
+
}
|
|
140861
|
+
else {
|
|
140862
|
+
qid = ct.pyQName + "." + n;
|
|
140863
|
+
}
|
|
140856
140864
|
}
|
|
140857
140865
|
let f = lookupGlobalSymbol(qid);
|
|
140858
140866
|
if (f)
|
|
@@ -140863,7 +140871,7 @@ var pxt;
|
|
|
140863
140871
|
if (sym) {
|
|
140864
140872
|
if (sym == ct)
|
|
140865
140873
|
pxt.U.userError("field lookup loop on: " + sym.qName + " / " + n);
|
|
140866
|
-
let classF = getClassField(sym, n, true);
|
|
140874
|
+
let classF = getClassField(sym, n, isStatic, true);
|
|
140867
140875
|
if (classF)
|
|
140868
140876
|
return classF;
|
|
140869
140877
|
}
|
|
@@ -140871,7 +140879,7 @@ var pxt;
|
|
|
140871
140879
|
}
|
|
140872
140880
|
if (!checkOnly && ct.pyAST && ct.pyAST.kind == "ClassDef") {
|
|
140873
140881
|
let sym = addSymbol(2 /* Property */, qid);
|
|
140874
|
-
sym.isInstance =
|
|
140882
|
+
sym.isInstance = !isStatic;
|
|
140875
140883
|
return sym;
|
|
140876
140884
|
}
|
|
140877
140885
|
return null;
|
|
@@ -140888,16 +140896,14 @@ var pxt;
|
|
|
140888
140896
|
const recvType = typeOf(recv);
|
|
140889
140897
|
const constructorTypes = getTypesForFieldLookup(recvType);
|
|
140890
140898
|
for (let ct of constructorTypes) {
|
|
140891
|
-
let
|
|
140899
|
+
let isModule = !!recvType.moduleType;
|
|
140900
|
+
let f = getClassField(ct, n, isModule, checkOnly);
|
|
140892
140901
|
if (f) {
|
|
140893
|
-
let isModule = !!recvType.moduleType;
|
|
140894
140902
|
if (isModule) {
|
|
140895
140903
|
if (f.isInstance)
|
|
140896
140904
|
error(null, 9505, pxt.U.lf("the field '{0}' of '{1}' is not static", n, ct.pyQName));
|
|
140897
140905
|
}
|
|
140898
140906
|
else {
|
|
140899
|
-
if (!f.isInstance)
|
|
140900
|
-
error(null, 9504, pxt.U.lf("the field '{0}' of '{1}' is static", n, ct.pyQName));
|
|
140901
140907
|
if (isSuper(recv))
|
|
140902
140908
|
f.isProtected = true;
|
|
140903
140909
|
else if (isThis(recv)) {
|
|
@@ -141305,7 +141311,7 @@ var pxt;
|
|
|
141305
141311
|
let scopeValueVar = n.vars["value"];
|
|
141306
141312
|
let valueVar = scopeValueVar === null || scopeValueVar === void 0 ? void 0 : scopeValueVar.symbol;
|
|
141307
141313
|
if (funname == "__set__" && valueVar) {
|
|
141308
|
-
let cf = getClassField(ctx.currClass.symInfo, "__get__");
|
|
141314
|
+
let cf = getClassField(ctx.currClass.symInfo, "__get__", false);
|
|
141309
141315
|
if (cf && cf.pyAST && cf.pyAST.kind == "FunctionDef")
|
|
141310
141316
|
unify(n, valueVar.pyRetType, cf.pyRetType);
|
|
141311
141317
|
}
|
|
@@ -141401,7 +141407,7 @@ var pxt;
|
|
|
141401
141407
|
}
|
|
141402
141408
|
}
|
|
141403
141409
|
const classDefs = n.body.filter(s => n.isNamespace || s.kind === "FunctionDef");
|
|
141404
|
-
const staticStmts = n.isNamespace ? [] : n.body.filter(s => classDefs.indexOf(s) === -1);
|
|
141410
|
+
const staticStmts = n.isNamespace ? [] : n.body.filter(s => classDefs.indexOf(s) === -1 && s.kind !== "Pass");
|
|
141405
141411
|
let body = stmts(classDefs);
|
|
141406
141412
|
nodes.push(body);
|
|
141407
141413
|
// Python classes allow arbitrary statements in their bodies, sort of like namespaces.
|
|
@@ -141418,18 +141424,20 @@ var pxt;
|
|
|
141418
141424
|
body.children.unshift(initFun);
|
|
141419
141425
|
}
|
|
141420
141426
|
if (!n.isNamespace) {
|
|
141421
|
-
|
|
141422
|
-
const fieldDefs = listClassFields(n, false)
|
|
141423
|
-
.filter(f => f.kind == 2 /* Property */ || isStatic(f))
|
|
141427
|
+
const fieldDefs = listClassFields(n)
|
|
141424
141428
|
.map(f => {
|
|
141425
141429
|
if (!f.pyName || !f.pyRetType)
|
|
141426
141430
|
error(n, 9535, lf("field definition missing py name or return type", f.qName));
|
|
141427
141431
|
return f;
|
|
141428
141432
|
});
|
|
141429
|
-
const
|
|
141433
|
+
const staticFieldSymbols = fieldDefs.filter(f => !f.isInstance);
|
|
141434
|
+
const instanceFields = fieldDefs.filter(f => f.isInstance)
|
|
141430
141435
|
.map((f) => B.mkStmt(accessAnnot(f), quote(f.pyName), typeAnnot(f.pyRetType)));
|
|
141431
|
-
const staticFields =
|
|
141432
|
-
.map((f) => B.
|
|
141436
|
+
const staticFields = staticFieldSymbols
|
|
141437
|
+
.map((f) => B.mkGroup([
|
|
141438
|
+
B.mkStmt(accessAnnot(f), B.mkText("static "), quote(f.pyName), typeAnnot(f.pyRetType)),
|
|
141439
|
+
declareLocalStatic(quoteStr(n.name), quoteStr(f.pyName), t2s(f.pyRetType))
|
|
141440
|
+
]));
|
|
141433
141441
|
body.children = staticFields.concat(instanceFields).concat(body.children);
|
|
141434
141442
|
}
|
|
141435
141443
|
if (generatedInitFunction) {
|
|
@@ -141744,7 +141752,7 @@ var pxt;
|
|
|
141744
141752
|
// class fields can't be const
|
|
141745
141753
|
// hack: value in @namespace should always be const
|
|
141746
141754
|
isConstCall = !!(value && ctx.currClass.isNamespace);
|
|
141747
|
-
let fd = getClassField(ctx.currClass.symInfo, nm);
|
|
141755
|
+
let fd = getClassField(ctx.currClass.symInfo, nm, true);
|
|
141748
141756
|
if (!fd)
|
|
141749
141757
|
error(n, 9544, lf("cannot get class field"));
|
|
141750
141758
|
// TODO: use or remove this code
|
|
@@ -142146,6 +142154,9 @@ var pxt;
|
|
|
142146
142154
|
let methName = "";
|
|
142147
142155
|
if (isClass) {
|
|
142148
142156
|
fun = lookupSymbol(namedSymbol.pyQName + ".__constructor");
|
|
142157
|
+
if (!fun) {
|
|
142158
|
+
fun = addSymbolFor(3 /* Function */, createDummyConstructorSymbol(namedSymbol === null || namedSymbol === void 0 ? void 0 : namedSymbol.pyAST));
|
|
142159
|
+
}
|
|
142149
142160
|
}
|
|
142150
142161
|
else {
|
|
142151
142162
|
if (n.func.kind == "Attribute") {
|
|
@@ -142343,7 +142354,6 @@ var pxt;
|
|
|
142343
142354
|
]);
|
|
142344
142355
|
}
|
|
142345
142356
|
}
|
|
142346
|
-
// TODO (riknoll): Make sure __init__ isn't being added as a symbol by the super call in the subclass. Should be converted to .__constructor
|
|
142347
142357
|
let fn;
|
|
142348
142358
|
if (isSuperConstructor) {
|
|
142349
142359
|
fn = B.mkText("super");
|
|
@@ -143007,6 +143017,68 @@ var pxt;
|
|
|
143007
143017
|
break;
|
|
143008
143018
|
}
|
|
143009
143019
|
}
|
|
143020
|
+
function createDummyConstructorSymbol(def, sym = def.symInfo) {
|
|
143021
|
+
var _a;
|
|
143022
|
+
const existing = lookupApi(sym.pyQName + ".__constructor");
|
|
143023
|
+
if (!existing && ((_a = sym.extendsTypes) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
143024
|
+
const parentSymbol = lookupSymbol(sym.extendsTypes[0]) || lookupGlobalSymbol(sym.extendsTypes[0]);
|
|
143025
|
+
if (parentSymbol) {
|
|
143026
|
+
return createDummyConstructorSymbol(def, parentSymbol);
|
|
143027
|
+
}
|
|
143028
|
+
}
|
|
143029
|
+
const result = {
|
|
143030
|
+
kind: "FunctionDef",
|
|
143031
|
+
name: "__init__",
|
|
143032
|
+
startPos: def.startPos,
|
|
143033
|
+
endPos: def.endPos,
|
|
143034
|
+
parent: def,
|
|
143035
|
+
body: [],
|
|
143036
|
+
args: {
|
|
143037
|
+
kind: "Arguments",
|
|
143038
|
+
startPos: 0,
|
|
143039
|
+
endPos: 0,
|
|
143040
|
+
args: [{
|
|
143041
|
+
startPos: 0,
|
|
143042
|
+
endPos: 0,
|
|
143043
|
+
kind: "Arg",
|
|
143044
|
+
arg: "self"
|
|
143045
|
+
}],
|
|
143046
|
+
kw_defaults: [],
|
|
143047
|
+
kwonlyargs: [],
|
|
143048
|
+
defaults: []
|
|
143049
|
+
},
|
|
143050
|
+
decorator_list: [],
|
|
143051
|
+
vars: {},
|
|
143052
|
+
symInfo: mkSymbol(3 /* Function */, def.symInfo.qName + ".__constructor")
|
|
143053
|
+
};
|
|
143054
|
+
result.symInfo.parameters = [];
|
|
143055
|
+
result.symInfo.pyRetType = mkType({ classType: def.symInfo });
|
|
143056
|
+
if (existing) {
|
|
143057
|
+
result.args.args.push(...existing.parameters.map(p => ({
|
|
143058
|
+
startPos: 0,
|
|
143059
|
+
endPos: 0,
|
|
143060
|
+
kind: "Arg",
|
|
143061
|
+
arg: p.name,
|
|
143062
|
+
})));
|
|
143063
|
+
result.symInfo.parameters.push(...existing.parameters.map(p => {
|
|
143064
|
+
if (p.pyType)
|
|
143065
|
+
return p;
|
|
143066
|
+
const res = Object.assign(Object.assign({}, p), { pyType: mapTsType(p.type) });
|
|
143067
|
+
return res;
|
|
143068
|
+
}));
|
|
143069
|
+
}
|
|
143070
|
+
return result;
|
|
143071
|
+
}
|
|
143072
|
+
function declareLocalStatic(className, name, type) {
|
|
143073
|
+
const isSetVar = `___${name}_is_set`;
|
|
143074
|
+
const localVar = `___${name}`;
|
|
143075
|
+
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([
|
|
143076
|
+
B.mkText(`return this.${isSetVar} ? this.${localVar} : ${className}.${name}`)
|
|
143077
|
+
])), B.mkStmt(B.mkText(`set ${name}(value: ${type})`), B.mkBlock([
|
|
143078
|
+
B.mkStmt(B.mkText(`this.${isSetVar} = true`)),
|
|
143079
|
+
B.mkStmt(B.mkText(`this.${localVar} = value`)),
|
|
143080
|
+
])));
|
|
143081
|
+
}
|
|
143010
143082
|
})(py = pxt.py || (pxt.py = {}));
|
|
143011
143083
|
})(pxt || (pxt = {}));
|
|
143012
143084
|
// Lexer spec: https://docs.python.org/3/reference/lexical_analysis.html
|
package/built/pxtpy.js
CHANGED
|
@@ -247,7 +247,7 @@ var pxt;
|
|
|
247
247
|
let sym = lookupApi(name);
|
|
248
248
|
if (sym)
|
|
249
249
|
getOrSetSymbolType(sym);
|
|
250
|
-
else if (name.indexOf(".")) {
|
|
250
|
+
else if (name.indexOf(".") && !name.endsWith(".__constructor")) {
|
|
251
251
|
const base = name.substring(0, name.lastIndexOf("."));
|
|
252
252
|
const baseSymbol = lookupGlobalSymbol(base);
|
|
253
253
|
if ((baseSymbol === null || baseSymbol === void 0 ? void 0 : baseSymbol.kind) === 8 /* Class */ && ((_a = baseSymbol.extendsTypes) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
@@ -336,7 +336,10 @@ var pxt;
|
|
|
336
336
|
pref += ".";
|
|
337
337
|
}
|
|
338
338
|
let qualifiedName = pref + name;
|
|
339
|
-
if (
|
|
339
|
+
if (scope.kind === "ClassDef") {
|
|
340
|
+
varSym = addSymbol(2 /* Property */, qualifiedName);
|
|
341
|
+
}
|
|
342
|
+
else if (isLocalScope(scope)
|
|
340
343
|
&& (modifier === py_1.VarModifier.Global
|
|
341
344
|
|| modifier === py_1.VarModifier.NonLocal)) {
|
|
342
345
|
varSym = addSymbol(4 /* Variable */, name);
|
|
@@ -661,17 +664,22 @@ var pxt;
|
|
|
661
664
|
return n.symInfo;
|
|
662
665
|
}
|
|
663
666
|
// TODO optimize ?
|
|
664
|
-
function listClassFields(cd
|
|
667
|
+
function listClassFields(cd) {
|
|
665
668
|
let qn = cd.symInfo.qName;
|
|
666
|
-
return pxt.U.values(internalApis).filter(e => e.namespace == qn &&
|
|
669
|
+
return pxt.U.values(internalApis).filter(e => e.namespace == qn && e.kind == 2 /* Property */);
|
|
667
670
|
}
|
|
668
|
-
function getClassField(ct, n, checkOnly = false, skipBases = false) {
|
|
671
|
+
function getClassField(ct, n, isStatic, checkOnly = false, skipBases = false) {
|
|
669
672
|
let qid;
|
|
670
673
|
if (n === "__init__") {
|
|
671
674
|
qid = ct.pyQName + ".__constructor";
|
|
672
675
|
}
|
|
673
676
|
else {
|
|
674
|
-
|
|
677
|
+
if (n.startsWith(ct.pyQName + ".")) {
|
|
678
|
+
qid = n;
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
qid = ct.pyQName + "." + n;
|
|
682
|
+
}
|
|
675
683
|
}
|
|
676
684
|
let f = lookupGlobalSymbol(qid);
|
|
677
685
|
if (f)
|
|
@@ -682,7 +690,7 @@ var pxt;
|
|
|
682
690
|
if (sym) {
|
|
683
691
|
if (sym == ct)
|
|
684
692
|
pxt.U.userError("field lookup loop on: " + sym.qName + " / " + n);
|
|
685
|
-
let classF = getClassField(sym, n, true);
|
|
693
|
+
let classF = getClassField(sym, n, isStatic, true);
|
|
686
694
|
if (classF)
|
|
687
695
|
return classF;
|
|
688
696
|
}
|
|
@@ -690,7 +698,7 @@ var pxt;
|
|
|
690
698
|
}
|
|
691
699
|
if (!checkOnly && ct.pyAST && ct.pyAST.kind == "ClassDef") {
|
|
692
700
|
let sym = addSymbol(2 /* Property */, qid);
|
|
693
|
-
sym.isInstance =
|
|
701
|
+
sym.isInstance = !isStatic;
|
|
694
702
|
return sym;
|
|
695
703
|
}
|
|
696
704
|
return null;
|
|
@@ -707,16 +715,14 @@ var pxt;
|
|
|
707
715
|
const recvType = typeOf(recv);
|
|
708
716
|
const constructorTypes = getTypesForFieldLookup(recvType);
|
|
709
717
|
for (let ct of constructorTypes) {
|
|
710
|
-
let
|
|
718
|
+
let isModule = !!recvType.moduleType;
|
|
719
|
+
let f = getClassField(ct, n, isModule, checkOnly);
|
|
711
720
|
if (f) {
|
|
712
|
-
let isModule = !!recvType.moduleType;
|
|
713
721
|
if (isModule) {
|
|
714
722
|
if (f.isInstance)
|
|
715
723
|
error(null, 9505, pxt.U.lf("the field '{0}' of '{1}' is not static", n, ct.pyQName));
|
|
716
724
|
}
|
|
717
725
|
else {
|
|
718
|
-
if (!f.isInstance)
|
|
719
|
-
error(null, 9504, pxt.U.lf("the field '{0}' of '{1}' is static", n, ct.pyQName));
|
|
720
726
|
if (isSuper(recv))
|
|
721
727
|
f.isProtected = true;
|
|
722
728
|
else if (isThis(recv)) {
|
|
@@ -1124,7 +1130,7 @@ var pxt;
|
|
|
1124
1130
|
let scopeValueVar = n.vars["value"];
|
|
1125
1131
|
let valueVar = scopeValueVar === null || scopeValueVar === void 0 ? void 0 : scopeValueVar.symbol;
|
|
1126
1132
|
if (funname == "__set__" && valueVar) {
|
|
1127
|
-
let cf = getClassField(ctx.currClass.symInfo, "__get__");
|
|
1133
|
+
let cf = getClassField(ctx.currClass.symInfo, "__get__", false);
|
|
1128
1134
|
if (cf && cf.pyAST && cf.pyAST.kind == "FunctionDef")
|
|
1129
1135
|
unify(n, valueVar.pyRetType, cf.pyRetType);
|
|
1130
1136
|
}
|
|
@@ -1220,7 +1226,7 @@ var pxt;
|
|
|
1220
1226
|
}
|
|
1221
1227
|
}
|
|
1222
1228
|
const classDefs = n.body.filter(s => n.isNamespace || s.kind === "FunctionDef");
|
|
1223
|
-
const staticStmts = n.isNamespace ? [] : n.body.filter(s => classDefs.indexOf(s) === -1);
|
|
1229
|
+
const staticStmts = n.isNamespace ? [] : n.body.filter(s => classDefs.indexOf(s) === -1 && s.kind !== "Pass");
|
|
1224
1230
|
let body = stmts(classDefs);
|
|
1225
1231
|
nodes.push(body);
|
|
1226
1232
|
// Python classes allow arbitrary statements in their bodies, sort of like namespaces.
|
|
@@ -1237,18 +1243,20 @@ var pxt;
|
|
|
1237
1243
|
body.children.unshift(initFun);
|
|
1238
1244
|
}
|
|
1239
1245
|
if (!n.isNamespace) {
|
|
1240
|
-
|
|
1241
|
-
const fieldDefs = listClassFields(n, false)
|
|
1242
|
-
.filter(f => f.kind == 2 /* Property */ || isStatic(f))
|
|
1246
|
+
const fieldDefs = listClassFields(n)
|
|
1243
1247
|
.map(f => {
|
|
1244
1248
|
if (!f.pyName || !f.pyRetType)
|
|
1245
1249
|
error(n, 9535, lf("field definition missing py name or return type", f.qName));
|
|
1246
1250
|
return f;
|
|
1247
1251
|
});
|
|
1248
|
-
const
|
|
1252
|
+
const staticFieldSymbols = fieldDefs.filter(f => !f.isInstance);
|
|
1253
|
+
const instanceFields = fieldDefs.filter(f => f.isInstance)
|
|
1249
1254
|
.map((f) => B.mkStmt(accessAnnot(f), quote(f.pyName), typeAnnot(f.pyRetType)));
|
|
1250
|
-
const staticFields =
|
|
1251
|
-
.map((f) => B.
|
|
1255
|
+
const staticFields = staticFieldSymbols
|
|
1256
|
+
.map((f) => B.mkGroup([
|
|
1257
|
+
B.mkStmt(accessAnnot(f), B.mkText("static "), quote(f.pyName), typeAnnot(f.pyRetType)),
|
|
1258
|
+
declareLocalStatic(quoteStr(n.name), quoteStr(f.pyName), t2s(f.pyRetType))
|
|
1259
|
+
]));
|
|
1252
1260
|
body.children = staticFields.concat(instanceFields).concat(body.children);
|
|
1253
1261
|
}
|
|
1254
1262
|
if (generatedInitFunction) {
|
|
@@ -1563,7 +1571,7 @@ var pxt;
|
|
|
1563
1571
|
// class fields can't be const
|
|
1564
1572
|
// hack: value in @namespace should always be const
|
|
1565
1573
|
isConstCall = !!(value && ctx.currClass.isNamespace);
|
|
1566
|
-
let fd = getClassField(ctx.currClass.symInfo, nm);
|
|
1574
|
+
let fd = getClassField(ctx.currClass.symInfo, nm, true);
|
|
1567
1575
|
if (!fd)
|
|
1568
1576
|
error(n, 9544, lf("cannot get class field"));
|
|
1569
1577
|
// TODO: use or remove this code
|
|
@@ -1965,6 +1973,9 @@ var pxt;
|
|
|
1965
1973
|
let methName = "";
|
|
1966
1974
|
if (isClass) {
|
|
1967
1975
|
fun = lookupSymbol(namedSymbol.pyQName + ".__constructor");
|
|
1976
|
+
if (!fun) {
|
|
1977
|
+
fun = addSymbolFor(3 /* Function */, createDummyConstructorSymbol(namedSymbol === null || namedSymbol === void 0 ? void 0 : namedSymbol.pyAST));
|
|
1978
|
+
}
|
|
1968
1979
|
}
|
|
1969
1980
|
else {
|
|
1970
1981
|
if (n.func.kind == "Attribute") {
|
|
@@ -2162,7 +2173,6 @@ var pxt;
|
|
|
2162
2173
|
]);
|
|
2163
2174
|
}
|
|
2164
2175
|
}
|
|
2165
|
-
// TODO (riknoll): Make sure __init__ isn't being added as a symbol by the super call in the subclass. Should be converted to .__constructor
|
|
2166
2176
|
let fn;
|
|
2167
2177
|
if (isSuperConstructor) {
|
|
2168
2178
|
fn = B.mkText("super");
|
|
@@ -2826,6 +2836,68 @@ var pxt;
|
|
|
2826
2836
|
break;
|
|
2827
2837
|
}
|
|
2828
2838
|
}
|
|
2839
|
+
function createDummyConstructorSymbol(def, sym = def.symInfo) {
|
|
2840
|
+
var _a;
|
|
2841
|
+
const existing = lookupApi(sym.pyQName + ".__constructor");
|
|
2842
|
+
if (!existing && ((_a = sym.extendsTypes) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
2843
|
+
const parentSymbol = lookupSymbol(sym.extendsTypes[0]) || lookupGlobalSymbol(sym.extendsTypes[0]);
|
|
2844
|
+
if (parentSymbol) {
|
|
2845
|
+
return createDummyConstructorSymbol(def, parentSymbol);
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
const result = {
|
|
2849
|
+
kind: "FunctionDef",
|
|
2850
|
+
name: "__init__",
|
|
2851
|
+
startPos: def.startPos,
|
|
2852
|
+
endPos: def.endPos,
|
|
2853
|
+
parent: def,
|
|
2854
|
+
body: [],
|
|
2855
|
+
args: {
|
|
2856
|
+
kind: "Arguments",
|
|
2857
|
+
startPos: 0,
|
|
2858
|
+
endPos: 0,
|
|
2859
|
+
args: [{
|
|
2860
|
+
startPos: 0,
|
|
2861
|
+
endPos: 0,
|
|
2862
|
+
kind: "Arg",
|
|
2863
|
+
arg: "self"
|
|
2864
|
+
}],
|
|
2865
|
+
kw_defaults: [],
|
|
2866
|
+
kwonlyargs: [],
|
|
2867
|
+
defaults: []
|
|
2868
|
+
},
|
|
2869
|
+
decorator_list: [],
|
|
2870
|
+
vars: {},
|
|
2871
|
+
symInfo: mkSymbol(3 /* Function */, def.symInfo.qName + ".__constructor")
|
|
2872
|
+
};
|
|
2873
|
+
result.symInfo.parameters = [];
|
|
2874
|
+
result.symInfo.pyRetType = mkType({ classType: def.symInfo });
|
|
2875
|
+
if (existing) {
|
|
2876
|
+
result.args.args.push(...existing.parameters.map(p => ({
|
|
2877
|
+
startPos: 0,
|
|
2878
|
+
endPos: 0,
|
|
2879
|
+
kind: "Arg",
|
|
2880
|
+
arg: p.name,
|
|
2881
|
+
})));
|
|
2882
|
+
result.symInfo.parameters.push(...existing.parameters.map(p => {
|
|
2883
|
+
if (p.pyType)
|
|
2884
|
+
return p;
|
|
2885
|
+
const res = Object.assign(Object.assign({}, p), { pyType: mapTsType(p.type) });
|
|
2886
|
+
return res;
|
|
2887
|
+
}));
|
|
2888
|
+
}
|
|
2889
|
+
return result;
|
|
2890
|
+
}
|
|
2891
|
+
function declareLocalStatic(className, name, type) {
|
|
2892
|
+
const isSetVar = `___${name}_is_set`;
|
|
2893
|
+
const localVar = `___${name}`;
|
|
2894
|
+
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([
|
|
2895
|
+
B.mkText(`return this.${isSetVar} ? this.${localVar} : ${className}.${name}`)
|
|
2896
|
+
])), B.mkStmt(B.mkText(`set ${name}(value: ${type})`), B.mkBlock([
|
|
2897
|
+
B.mkStmt(B.mkText(`this.${isSetVar} = true`)),
|
|
2898
|
+
B.mkStmt(B.mkText(`this.${localVar} = value`)),
|
|
2899
|
+
])));
|
|
2900
|
+
}
|
|
2829
2901
|
})(py = pxt.py || (pxt.py = {}));
|
|
2830
2902
|
})(pxt || (pxt = {}));
|
|
2831
2903
|
// Lexer spec: https://docs.python.org/3/reference/lexical_analysis.html
|