Class extends value undefined is not a constructor or null

954 views
Skip to first unread message

fu6...@gmail.com

unread,
Jul 11, 2023, 7:25:50 AM7/11/23
to Blockly
Hi group:

I got a error message when I upgraded the Blockly cores version to 10.0.0.

This is my code.
class myMutator extends Blockly.Mutator {}

The error message
Uncaught TypeError: Class extends value undefined is not a constructor or null

Any help will/would be appreciated.

fu6...



Beka Westberg

unread,
Jul 11, 2023, 2:05:18 PM7/11/23
to blo...@googlegroups.com
Hello!

In v10 `Blockly.Mutator` was renamed to `Blockly.icons.MutatorIcon` =) You can check the release notes for the full list of breaking changes and deprecations. And you can run the migration script to automatically perform any renamings.

Since it seems you're creating a custom icon, you may also be interested in our docs on the new custom icons API!

I hope that helps! If you have any further questions please reply =)
--Beka

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/c94e89be-4288-4c11-946b-805b4f5e7ec7n%40googlegroups.com.
Message has been deleted

fu6...@gmail.com

unread,
Jul 12, 2023, 8:42:50 AM7/12/23
to Blockly
Hi beka

Thank you for your help. After changing the class name to "Blockly.icons.MutatorIcon", the program can run without generating any error message, but it doesn't have any effect.

This is class code.
This is block code.

I tried using another approach, and although it seems to be working fine now  as shown in the video., I still encounter error messages. How can I avoid generating these errors?

blocks$$module$build$src$blocks$procedures.procedures_callnoreturn=Object.assign({},PROCEDURE_CALL_COMMON$$module$build$src$blocks$procedures,
{
init:function(){
this.appendDummyInput("TOPROW").appendField("","NAME");
this.setPreviousStatement(!0);
this.setNextStatement(!0);
this.setStyle("procedure_blocks");
this.setHelpUrl($.Msg$$module$build$src$core$msg.PROCEDURES_CALLNORETURN_HELPURL);
this.arguments_=[];
this.argumentVarModels_=[];
this.quarkConnections_={};
this.quarkIds_=null;
this.setMutator(new $.MutatorIcon$$module$build$src$core$icons$mutator_icon([],this));
this.previousEnabledState_=!0
this.arguments_=[];this.argumentVarModels_=[];
}
,defType_:"procedures_defnoreturn"
,decompose: function(a) {
const b=a.newBlock("procedures_defnoreturn");
b.initSvg();
return b
}
,compose: function(a) {
}
,saveConnections:function(a){
var xml = Blockly.Xml.workspaceToDom(Blockly.getMainWorkspace());
xml = new XMLSerializer().serializeToString(xml);
xml = new DOMParser().parseFromString(xml,"text/xml").firstChild.childNodes;

for (var i=0;i<xml.length;i++) {
if (xml[i].getAttribute("type")=="procedures_defnoreturn") {
for (var j=0;j<xml[i].childNodes.length;j++) {
if (xml[i].childNodes[j].textContent==this.getFieldValue("NAME")) {
xml = Blockly.Xml.domToPrettyText(xml[i]);
xml = Blockly.utils.xml.textToDom('<xml xmlns="https://developers.google.com/blockly/xml">'+xml.replace("x=","xx=").replace("y=","yy=")+'</xml>');
a.workspace.clear();
Blockly.Xml.domToWorkspace(xml, a.workspace);
break;
}
}
}
}
}
});

blocks$$module$build$src$blocks$procedures.procedures_callreturn=Object.assign({},PROCEDURE_CALL_COMMON$$module$build$src$blocks$procedures,
{
init:function(){
this.appendDummyInput("TOPROW").appendField("","NAME");
this.setOutput(!0);
this.setStyle("procedure_blocks");
this.setHelpUrl($.Msg$$module$build$src$core$msg.PROCEDURES_CALLRETURN_HELPURL);
this.arguments_=[];
this.argumentVarModels_=[];
this.quarkConnections_={};
this.quarkIds_=null;
this.setMutator(new $.MutatorIcon$$module$build$src$core$icons$mutator_icon([],this));
this.previousEnabledState_=!0
this.arguments_=[];this.argumentVarModels_=[];
}
,defType_:"procedures_defreturn"
,decompose: function(a) {
const b=a.newBlock("procedures_defreturn");
b.initSvg();
return b
}
,compose: function(a) {
}
,saveConnections:function(a){
var xml = Blockly.Xml.workspaceToDom(Blockly.getMainWorkspace());
xml = new XMLSerializer().serializeToString(xml);
xml = new DOMParser().parseFromString(xml,"text/xml").firstChild.childNodes;
for (var i=0;i<xml.length;i++) {
if (xml[i].getAttribute("type")=="procedures_defreturn") {
for (var j=0;j<xml[i].childNodes.length;j++) {
if (xml[i].childNodes[j].textContent==this.getFieldValue("NAME")) {
xml = Blockly.Xml.domToPrettyText(xml[i]);
xml = Blockly.utils.xml.textToDom('<xml xmlns="https://developers.google.com/blockly/xml">'+xml.replace("x=","xx=").replace("y=","yy=")+'</xml>');
a.workspace.clear();
Blockly.Xml.domToWorkspace(xml, a.workspace);
break;
}
}
}
}
}
});
error2.jpg


error1.jpg
bwes...@google.com 在 2023年7月12日 星期三凌晨2:05:18 [UTC+8] 的信中寫道:
mutor.mp4

Beka Westberg

unread,
Jul 12, 2023, 11:44:47 AM7/12/23
to blo...@googlegroups.com
Hello,

I don't think I have enough information to help you with those errors :/ It looks like the first one is coming from a text input field, and the second one is coming from a mutationToDom function. Could you share the code where those are defined?

I'll also say that you should be able to access things off the `Blockly` namespace! Accessing them using the fully mangled `$$module$build$src$blocks$etc` name is fragile and not guaranteed to be consistent!

Hopefully with a bit more information we can get this sorted =)

Best wishes,
--Beka

Message has been deleted

fu6...@gmail.com

unread,
Jul 13, 2023, 5:57:41 AM7/13/23
to Blockly
Hi Beka,

Thank you for your help again. I had found the bug in the code where the error occurred. The error was caused by the repeated execution of the saveConnections() function three times. I am not sure about the cause of the error. Currently, this code can run properly without generating any error messages.


blocks$$module$build$src$blocks$procedures.procedures_callnoreturn=Object.assign({},PROCEDURE_CALL_COMMON$$module$build$src$blocks$procedures,
{
init:function(){
this.appendDummyInput("TOPROW").appendField("","NAME");
this.setPreviousStatement(!0);
this.setNextStatement(!0);
this.setStyle("procedure_blocks");
this.setHelpUrl($.Msg$$module$build$src$core$msg.PROCEDURES_CALLNORETURN_HELPURL);
this.arguments_=[];
this.argumentVarModels_=[];
this.quarkConnections_={};
this.quarkIds_=null;
this.setMutator(new Blockly.icons.MutatorIcon([],this));

this.previousEnabledState_=!0;
this.arguments_=[];
this.argumentVarModels_=[];
}
,defType_:"procedures_defnoreturn"
,decompose: function(a) {
const b=a.newBlock("");

b.initSvg();
return b
}
,compose: function(a) {
}
,saveConnections:function(a){
var xml = Blockly.Xml.workspaceToDom(a.workspace);
xml = new XMLSerializer().serializeToString(xml);

if (xml.indexOf('type="undefined"')!=-1) {

xml = Blockly.Xml.workspaceToDom(Blockly.getMainWorkspace());
xml = new XMLSerializer().serializeToString(xml);
xml = new DOMParser().parseFromString(xml,"text/xml").firstChild.childNodes;

for (var i=0;i<xml.length;i++) {
if (xml[i].getAttribute("type")=="procedures_defnoreturn") {
for (var j=0;j<xml[i].childNodes.length;j++) {
if (xml[i].childNodes[j].textContent==this.getFieldValue("NAME")) {
xml = Blockly.Xml.domToPrettyText(xml[i]);
xml = Blockly.utils.xml.textToDom('<xml xmlns="https://developers.google.com/blockly/xml">'+xml.replace("x=","xx=").replace("y=","yy=")+'</xml>');
a.workspace.clear();
Blockly.Xml.domToWorkspace(xml, a.workspace);
break;
}
}
}
}
}
}
});

blocks$$module$build$src$blocks$procedures.procedures_callreturn=Object.assign({},PROCEDURE_CALL_COMMON$$module$build$src$blocks$procedures,
{
init:function(){
this.appendDummyInput("TOPROW").appendField("","NAME");
this.setOutput(!0);
this.setStyle("procedure_blocks");
this.setHelpUrl($.Msg$$module$build$src$core$msg.PROCEDURES_CALLRETURN_HELPURL);
this.arguments_=[];
this.argumentVarModels_=[];
this.quarkConnections_={};
this.quarkIds_=null;
this.setMutator(new Blockly.icons.MutatorIcon([],this));

this.previousEnabledState_=!0;
this.arguments_=[];
this.argumentVarModels_=[];
}
,defType_:"procedures_defreturn"
,decompose: function(a) {
const b=a.newBlock("");

b.initSvg();
return b
}
,compose: function(a) {
}
,saveConnections:function(a){
var xml = Blockly.Xml.workspaceToDom(a.workspace);
xml = new XMLSerializer().serializeToString(xml);

if (xml.indexOf('type="undefined"')!=-1) {

var xml = Blockly.Xml.workspaceToDom(Blockly.getMainWorkspace());
xml = new XMLSerializer().serializeToString(xml);
xml = new DOMParser().parseFromString(xml,"text/xml").firstChild.childNodes;
for (var i=0;i<xml.length;i++) {
if (xml[i].getAttribute("type")=="procedures_defreturn") {
for (var j=0;j<xml[i].childNodes.length;j++) {
if (xml[i].childNodes[j].textContent==this.getFieldValue("NAME")) {
xml = Blockly.Xml.domToPrettyText(xml[i]);
xml = Blockly.utils.xml.textToDom('<xml xmlns="https://developers.google.com/blockly/xml">'+xml.replace("x=","xx=").replace("y=","yy=")+'</xml>');
a.workspace.clear();
Blockly.Xml.domToWorkspace(xml, a.workspace);
break;
}
}
}
}
}
}
});

mutor.png


fu6...


bwes...@google.com 在 2023年7月12日 星期三晚上11:44:47 [UTC+8] 的信中寫道:

Beka Westberg

unread,
Jul 13, 2023, 11:39:08 AM7/13/23
to blo...@googlegroups.com
Yay I'm glad you found a solution that works for you! Thank you for posting back with it =)

Best wishes,
--Beka

fu6...@gmail.com

unread,
Jul 15, 2023, 9:42:50 AM7/15/23
to Blockly
Hi group,

I have also successfully replaced the mutator icon with a custom one for the procedures blocks.


changeicon.jpg


initView(a){
if (this.sourceBlock.defType_=="procedures_defnoreturn"||this.sourceBlock.defType_=="procedures_defreturn") {

this.svgRoot||(super.initView(a)
,createSvgElement$$module$build$src$core$utils$dom(Svg$$module$build$src$core$utils$svg.IMAGE,{width:"20px",height:"20px",href:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAABmJLR0QA/wD/AP+gvaeTAAADyUlEQVRIieXVS0xcVRzH8e85l3nAUBCsaZHUqrDQAsWZdGekj8RXVzR10qUwJERXLtTEREPARle6Nl3AMEljGmnorlZjBNpoWzVAQoFKIRFqB9raymNGZu7ce/8uhiG8hOFRY+JvdW/yP+dz/+feew7836KyKQoGg7k+n++w1vopx3GKtNZ/ish4LBa73NHRMb/jcENDQ7lt281KqRNA3holfwGdjuM0RyKRsR2BQ6HQ+yLyCeDClYvaW4EqfBI8+ZCMITNRZOoGpBIAJvBhOBz+bFtwfX39GaCRHA/6wHEoq0EZ7lV1YpvIaDcyfAmsJMCZcDj8VjawsVanwAfkFaFr3kGVVqN0ukwr8OQoHAEBlDZQu8vQJZXI5ABYiUOBQCDW19d3dVMdh0KhZ0VkmByPWx99L720wO5cRcUTBnvyFEql0btxYfC+zR/zkh48cwe763OwkqbWuqK1tXV0PVgvvXEc52PArQ8cX0TLizTH9ueQsISe2xYXx1L0TFgkLOHY/hzKixamKCxFP/8agFtEmjbqeBEOBoO5SqlaXLlQVrNYUJqvuBa1uR61uRsX5sx0t9ejNteiNvsKljx7+RFweRGRk42NjWv9Bavh/Pz8GsCnSiqXfUg9t20mZp01B0/MOnSNW4v3ynCj91YC5Jmm+WJWMPA0AAtLvNVIQUl6Yq2fyRYuBlBu37Zg5d2VfgCRx7OClVIPAEjGtgWTnMtc3c8KFpFxAJmJbsvNjM/MtyEci8UuA3GZuoHY5tZU20SmhgBiwJWs4IVT5gKpBDLavSVXbn0PqXmAzvb29kRWMIBhGE1AUoYvwcydzaHTv+Pc/BbAXNiI1s2yvbq3t3fa7/cncOxXZHIAvec58BZkhcoPX4AZR0TaI5FIZFMwQH9//49+v78EK3FIJn5CKQVF+xYPimWxTWTkO5xfzmZQWylV5ff7B/r7+39dD17vPH5XRD4F3Li86R2psAQ8uyA5t3AeD2XeqQmEgTcBbyJlpaYTqdNfnz93OuuOM+nr67saCAS+VEoVY1vlMht1y70RZHIAuTcCs5PgWHHgnGEYb7S1tZ0NBAI/z5vWqYmHc+75ZOrowepqbg0p9myq46Wpq6vzAi+R3laLgYfAb8CVlV/vyyeCLXPzZpNIevJin6f5YudXLVuCN5tXTwRbZjbA/3Gpt5Oxm0PdFZVVRtJ2DguQSNlHVi77I4EX8K6KqoOupGXXZPCqF6qjo8ODvbBiA9npfHOh46PCPE+TUgqvy3igE/Hzj9JblddPnnq7trb2sX8V/c/lbwo9q8gJVNowAAAAAElFTkSuQmCC"},this.svgRoot))
} else {

this.svgRoot||(super.initView(a)
,createSvgElement$$module$build$src$core$utils$dom(Svg$$module$build$src$core$utils$svg.RECT,{"class":"blocklyIconShape",rx:"4",ry:"4",height:"16",width:"16"},this.svgRoot)
,createSvgElement$$module$build$src$core$utils$dom(Svg$$module$build$src$core$utils$svg.PATH,{"class":"blocklyIconSymbol",d:"m4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 0.41,0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 1.8,0 0.3,-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 0.9,-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,-0.41 -0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 -0.127,-1.138 -0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,0.682 -1.043,-0.457 -0.41,0.11 -0.899,1.559 0.108,0.409z"},this.svgRoot)
,createSvgElement$$module$build$src$core$utils$dom(Svg$$module$build$src$core$utils$svg.CIRCLE,{"class":"blocklyIconShape",r:"2.7",cx:"8",cy:"8"},this.svgRoot))

}
}



Best wishes.

fu6...

bwes...@google.com 在 2023年7月13日 星期四晚上11:39:08 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages