Skip to content

Commit

Permalink
fix(core): as_xxx methods must START with as_ to be considered
Browse files Browse the repository at this point in the history
  • Loading branch information
georgejecook committed Apr 4, 2022
1 parent c6a5dfe commit 14999dc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,38 @@ end sub
]))
print m.items.show(mc_getNode(items, "0.item"))
end function`);
expect(a).to.equal(b);
});
it('ignores asXXX calls in that do not start with as_XXX', async () => {
plugin.afterProgramCreate(program);
program.setFile('source/comp.bs', `
function notInClass()
formatJson(fw_asAA(json.user))
print(fw_asString(json.user.name, "default name"))
if asBoolean(json.user.favorites[0].isActive)
print fw_asInteger(json.age[0].time[thing].other["this"])
end if
print m.items.getValue(fw_asArray(items, ["none"]))
print m.items.show(fw_asNode(items[0].item))
end function
`);
program.validate();
await builder.transpile();
//ignore diagnostics - need to import core

let a = getContents('source/comp.brs');
let b = trimLeading(`function notInClass()
formatJson(fw_asAA(json.user))
print (fw_asString(json.user.name, "default name"))
if mc_getBoolean(json, "user.favorites.0.isActive") then
print fw_asInteger(json.age[0].time[thing].other["this"])
end if
print m.items.getValue(fw_asArray(items, [
"none"
]))
print m.items.show(fw_asNode(items[0].item))
end function`);
expect(a).to.equal(b);
});

it('fails validations if a method invocation is present in an as call', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export class MaestroPlugin implements CompilerPlugin {

// event.file.functionCalls
for (let callExpression of functionScope.func.callExpressions) {
let regex = /as(Any|Array|AA|Boolean|Float|Integer|Node|Point|String)/i;
let regex = /^as(Any|Array|AA|Boolean|Float|Integer|Node|Point|String)/i;
if (isVariableExpression(callExpression.callee) && isExpression(callExpression.args[0])) {
let name = callExpression.callee.name.text;
if (regex.test(name)) {
Expand Down

0 comments on commit 14999dc

Please sign in to comment.