Estoy tratando de hacer un lenguaje de programación (muy estúpido), y me encuentro con este error:
ReferenceError: ' constructor' is not defined.
Aquí es donde está el código (Nodo JS):
class DLang { constructor(code) { this.lines = code.split('\n') } run() { let lines = this.lines let testingUtils_ = false let variables = {} for (let i = 0; i < lines.length; i++) { if (lines[i] === 'import \'testing/all.dlang\'') { testingUtils_ = true } if (lines[i].includes('(')) { let currFunction_ = lines[i].split('(')[0] // let text = lines[i].split('(')[1].replace(')', '').replace(/\'/g, '') let text let value = lines[i] .replace('(', '') .replace(')', '') .replace(currFunction_, '') if (value.includes('\'')) { text = value .replace(/\'/g, '') } else { text = variables[value] } // function conditions let printCondition_ = (currFunction_ === 'print' && testingUtils_ === true) if (printCondition_) { if (text == undefined) { throw ReferenceError(`\'${value}\' is not defined.`) } else { console.log(text) } } else if (!printCondition_) { throw new ReferenceError(`\'${currFunction_}\' is not defined.`) } } if (lines[i].includes('var', 0)) { let final_ = lines[i] .replace('var', '') .replace('=', '') .trim() .split('\'') variables[final_[0].trim()] = final_[1] } } } } module.exports = DLangComo referencia, aquí está el mensaje de error completo:
throw new ReferenceError(`\'${currFunction_}\' is not defined.`) ^ ReferenceError: ' constructor' is not defined. at DLang.run (/Users/name/Desktop/coding/programming_langs/dlang/dlang_source_code/src/index.js:42:17) at /Users/name/Desktop/coding/programming_langs/dlang/dlang_source_code/test.js:11:7 at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) Node.js v17.1.0¡Gracias por adelantado!