Skip to content

Instantly share code, notes, and snippets.

@georgejecook
Created December 15, 2022 14:47
Show Gist options
  • Save georgejecook/8acbe9934df85d088f49674a8cd1c24c to your computer and use it in GitHub Desktop.
Save georgejecook/8acbe9934df85d088f49674a8cd1c24c to your computer and use it in GitHub Desktop.
notes for updating maestro plugin
Based on the provided information, you can modify the updateAsFunctionCalls function as follows to correctly transpile the asString(m.titles[m.video.id].text) call to mc_getString(m, "title." + m.video.id + ".text):
Update the regex in the updateAsFunctionCalls function to also match function calls that include array indexing, such as m.titles[m.video.id]. This can be done by adding \[\] to the regex pattern, so that it looks like this:
Copy code
let regex = /^as(Any|Array|AA|Boolean|Number|Float|Integer|Node|Point|String)(\[\])*/i;
In the getStringPathFromDottedGet function, add a check for array indexing to the while loop that builds up the path parts array. If the current expression is an indexed get expression (isIndexedGetExpression), you can add the index value to the parts array, like this:
Copy code
while (root) {
if (isCallExpression(root) || isCallfuncExpression(root)) {
throw this.getWrongAsXXXFunctionPartError(root);
}
if (isIndexedGetExpression(root)) {
let index = root.index;
if (isLiteralExpression(index)) {
parts.push(index.token.text.replace(/^"/, '').replace(/"$/, ''));
} else if (isVariableExpression(index)) {
parts.push(index.name.text);
}
} else if (root.obj) {
parts.push(`${this.getPathValuePartAsString(root)}`);
}
root = root.obj;
}
In the updateAsFunctionCalls function, modify the if block that checks for regex matches to also check if the first argument to the function call (callExpression.args[0]) is an indexed get expression. If it is, you can add the root object and the concatenated path parts from step 2 as arguments to the mc_getXXX function call, like this:
Copy code
if (regex.test(name)) {
try {
let value = callExpression.args.shift() as DottedGetExpression;
let rootValue = this.getRootValue(value);
let stringPath = this.getStringPathFromDottedGet(value);
let joinedPath = stringPath ? `"${stringPath}"` : undefined;
if (isIndexedGetExpression(value)) {
joinedPath = `"${this.getPathValuePartAsString(value.obj)}." + ${value.index.name.text}`;
}
name = `mc_get${name.match(regex)[1]}`;
callExpression.callee.name.text = name;
if (joinedPath) {
callExpression.args.unshift(createStringLiteral(joinedPath));
} else {
callExpression.args.unshift(createInvalidLiteral());
}
callExpression.args.
George Cook
continue - don't repeat anything
if (joinedPath) {
callExpression.args.unshift(createStringLiteral(joinedPath));
} else {
callExpression.args.unshift(createInvalidLiteral());
}
callExpression.args.unshift(rootValue);
Copy code
This updated `updateAsFunctionCalls` function should transpile `asString(m.titles[m.video.id].text)` to `mc_getString(m, "title." + m.video.id + ".text)` as required. Let me know if you have any questions or need further clarification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment