(scrollsdkProductsPath, forNodeJs = true)
| 20026 | return this._rootParticleDefToJavascriptClass("", false).trim() |
| 20027 | } |
| 20028 | _rootParticleDefToJavascriptClass(scrollsdkProductsPath, forNodeJs = true) { |
| 20029 | const defs = this.validConcreteAndAbstractParserDefinitions |
| 20030 | // todo: throw if there is no root particle defined |
| 20031 | const parserClasses = defs.map(def => def.asJavascriptClass).join("\n\n") |
| 20032 | const rootDef = this.rootParserDefinition |
| 20033 | const rootName = rootDef.generatedClassName |
| 20034 | if (!rootName) throw new Error(`Root Particle Type Has No Name`) |
| 20035 | let exportScript = "" |
| 20036 | if (forNodeJs) |
| 20037 | exportScript = `module.exports = ${rootName}; |
| 20038 | ${rootName}` |
| 20039 | else exportScript = `window.${rootName} = ${rootName}` |
| 20040 | let nodeJsImports = `` |
| 20041 | if (forNodeJs) { |
| 20042 | const path = require("path") |
| 20043 | nodeJsImports = Object.keys(GlobalNamespaceAdditions) |
| 20044 | .map(key => { |
| 20045 | const thePath = scrollsdkProductsPath + "/" + GlobalNamespaceAdditions[key] |
| 20046 | return `const { ${key} } = require("${thePath.replace(/\\/g, "\\\\")}")` // escape windows backslashes |
| 20047 | }) |
| 20048 | .join("\n") |
| 20049 | } |
| 20050 | // todo: we can expose the previous "constants" export, if needed, via the parsers, which we preserve. |
| 20051 | return `{ |
| 20052 | ${nodeJsImports} |
| 20053 | ${parserClasses} |
| 20054 | |
| 20055 | ${exportScript} |
| 20056 | } |
| 20057 | ` |
| 20058 | } |
| 20059 | } |
| 20060 | HandParsersProgram.makeParserId = str => Utils._replaceNonAlphaNumericCharactersWithCharCodes(str).replace(HandParsersProgram.parserSuffixRegex, "") + ParsersConstants.parserSuffix |
| 20061 | HandParsersProgram.makeAtomTypeId = str => Utils._replaceNonAlphaNumericCharactersWithCharCodes(str).replace(HandParsersProgram.atomTypeSuffixRegex, "") + ParsersConstants.atomTypeSuffix |
no test coverage detected