MCPcopy Create free account
hub / github.com/breck7/scroll / _rootParticleDefToJavascriptClass

Method _rootParticleDefToJavascriptClass

external/.scrollLibs.js:20028–20058  ·  view source on GitHub ↗
(scrollsdkProductsPath, forNodeJs = true)

Source from the content-addressed store, hash-verified

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}
20060HandParsersProgram.makeParserId = str => Utils._replaceNonAlphaNumericCharactersWithCharCodes(str).replace(HandParsersProgram.parserSuffixRegex, "") + ParsersConstants.parserSuffix
20061HandParsersProgram.makeAtomTypeId = str => Utils._replaceNonAlphaNumericCharactersWithCharCodes(str).replace(HandParsersProgram.atomTypeSuffixRegex, "") + ParsersConstants.atomTypeSuffix

Callers 2

toNodeJsJavascriptMethod · 0.95
toBrowserJavascriptMethod · 0.95

Calls 3

mapMethod · 0.80
replaceMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected