Fixing error with functions below constructor

This commit is contained in:
metacryst
2024-03-27 15:41:07 -05:00
parent ec2ae3229a
commit 0252b92554
2 changed files with 34 additions and 1 deletions

View File

@@ -118,4 +118,35 @@ testParseClassFieldsWithInnerFunctionVariable() {
} }
} }
ParseConstructorWithFunctionsBelow() {
class Space extends Shadow {
$$form = Forms.observe(window.location.pathname, this)
render = () => {
ForEach(this.form.children, (form) => {
switch(form.type) {
case "file":
File(form)
break
case "space":
ChildSpace(form)
break
case "link":
Link()
break
}
})
}
constructor() {
super()
}
connectedCallback() {
}
}
window.Registry.parseConstructor(Space)
}
}) })

View File

@@ -511,6 +511,7 @@ window.Registry = class Registry {
let braceDepth = 0; let braceDepth = 0;
let constructorFound = false let constructorFound = false
let superCallFound = false; let superCallFound = false;
let constructorEndFound = false;
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
let line = lines[i]; let line = lines[i];
@@ -530,9 +531,10 @@ window.Registry = class Registry {
modifiedLines.push(` window.Registry.construct(this, window.Registry.currentStateVariables, ...window.Registry.currentParams);`); modifiedLines.push(` window.Registry.construct(this, window.Registry.currentStateVariables, ...window.Registry.currentParams);`);
} }
if (constructorFound && braceDepth === 1 && superCallFound) { if (constructorFound && braceDepth === 1 && superCallFound && !constructorEndFound) {
modifiedLines.splice(modifiedLines.length - 1, 0, ' Object.preventExtensions(this);'); modifiedLines.splice(modifiedLines.length - 1, 0, ' Object.preventExtensions(this);');
modifiedLines.splice(modifiedLines.length - 1, 0, ' window.Registry.testInitialized(this);'); modifiedLines.splice(modifiedLines.length - 1, 0, ' window.Registry.testInitialized(this);');
constructorEndFound = true
} }
} }