* Gets list of experiments registered in MainImpl.js.
(mainImplFile, experimentNames)
| 112 | * Gets list of experiments registered in MainImpl.js. |
| 113 | */ |
| 114 | function getMainImplExperimentList(mainImplFile, experimentNames) { |
| 115 | const mainAST = espree.parse(mainImplFile, parseOptions); |
| 116 | |
| 117 | // Find MainImpl Class node |
| 118 | let mainImplClassNode; |
| 119 | for (const node of mainAST.body) { |
| 120 | if (isClassNameDeclaration(node, 'MainImpl')) { |
| 121 | mainImplClassNode = node; |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | if (!mainImplClassNode) { |
| 126 | return null; |
| 127 | } |
| 128 | |
| 129 | // Find function in MainImpl Class |
| 130 | const initializeExperimentNode = findFunctionInClass( |
| 131 | mainImplClassNode, |
| 132 | 'initializeExperiments', |
| 133 | ); |
| 134 | if (!initializeExperimentNode) { |
| 135 | return null; |
| 136 | } |
| 137 | |
| 138 | // Get list of experiments |
| 139 | const experiments = []; |
| 140 | for (const statement of initializeExperimentNode.value.body.body) { |
| 141 | let expression = null; |
| 142 | if (statement.expression && statement.expression.type === 'CallExpression') { |
| 143 | expression = statement.expression; |
| 144 | } else if (statement.type === 'VariableDeclaration') { |
| 145 | expression = statement.declarations[0].init; |
| 146 | } |
| 147 | |
| 148 | let experimentNameArg = ''; |
| 149 | if (isExperimentRegistrationCall(expression)) { |
| 150 | // Experiment name is first argument of registration call |
| 151 | experimentNameArg = expression.arguments[0]; |
| 152 | } else if (isHostExperimentRegistrationCall(expression)) { |
| 153 | // Experiment name is the value of the `name` property of the first |
| 154 | // argument of registration call |
| 155 | experimentNameArg = expression.arguments[0].properties.find(property => property.key.name === 'name').value; |
| 156 | } |
| 157 | // Translate the Root.ExperimentNames.ExperimentName to a string |
| 158 | if (experimentNameArg) { |
| 159 | const experimentName = isExperimentNameReference(experimentNameArg); |
| 160 | if (experimentName) { |
| 161 | const translatedName = experimentNames.get(experimentName); |
| 162 | if (!translatedName) { |
| 163 | console.log( |
| 164 | 'Failed to resolve Root.ExperimentNames.${experimentName} to a string', |
| 165 | ); |
| 166 | process.exit(1); |
| 167 | } |
| 168 | experiments.push(translatedName); |
| 169 | } else { |
| 170 | console.log( |
| 171 | 'Unexpected argument to Root.Runtime.experiments.register: ', |
no test coverage detected