Skip to content

Commit

Permalink
Merge pull request #38 from georgejecook/fix/asXXX-start-with-as
Browse files Browse the repository at this point in the history
Fix/as xxx start with as
  • Loading branch information
georgejecook authored Apr 4, 2022
2 parents f963827 + 14999dc commit ec6183c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## [0.18.1](https://github.com/georgejecook/maestro-roku-bsc-plugin/compare/0.17.0...0.18.1)
## [0.19.0](https://github.com/georgejecook/maestro-roku-bsc-plugin/compare/0.18.1...0.19.0)

### Merged

- updates to bsc 0.45.2 [`#35`](https://github.com/georgejecook/maestro-roku-bsc-plugin/pull/35)
- imrpoves error logging and diagnostics [`#37`](https://github.com/georgejecook/maestro-roku-bsc-plugin/pull/37)
- Feat/as type support [`#36`](https://github.com/georgejecook/maestro-roku-bsc-plugin/pull/36)

### Commits

- adds support for swizzling asXXX functions, so that we can do instance invocations, as a polyfill for optional chaining [`9a7f2b2`](https://github.com/georgejecook/maestro-roku-bsc-plugin/commit/9a7f2b2cb61785223caff24b0bc69195a634dd43)

## [0.18.1](https://github.com/georgejecook/maestro-roku-bsc-plugin/compare/0.18.0...0.18.1) - 2022-02-26

### Commits

- bump [`65fda9d`](https://github.com/georgejecook/maestro-roku-bsc-plugin/commit/65fda9d3672cd40ad7fe192eca774b226826499e)
- bump [`1989c42`](https://github.com/georgejecook/maestro-roku-bsc-plugin/commit/1989c42a9b8d10c1639450f9ca4c4ef9a4fe1b1d)

## [0.18.0](https://github.com/georgejecook/maestro-roku-bsc-plugin/compare/0.17.0...0.18.0) - 2022-02-26

### Merged

- updates to bsc 0.45.2 [`#35`](https://github.com/georgejecook/maestro-roku-bsc-plugin/pull/35)

## [0.17.0](https://github.com/georgejecook/maestro-roku-bsc-plugin/compare/0.16.0...0.17.0) - 2022-02-14

### Merged
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maestro-roku-bsc-plugin",
"version": "0.18.1",
"version": "0.19.0",
"description": "Visual studio plugin for maestro brightscript development",
"files": [
"dist/**/!(*.spec.*)*",
Expand Down
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 ec6183c

Please sign in to comment.