Skip to content

Commit

Permalink
Add check for onChange function (#941)
Browse files Browse the repository at this point in the history
* Add check for onChange function

* Check for defined onChange first

---------

Co-authored-by: Bronley Plumb <bronley@gmail.com>
  • Loading branch information
MilapNaik and TwitchBronBron authored Dec 18, 2023
1 parent f88c677 commit 02f0de9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/XmlScope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('XmlScope', () => {
<function id="func3" />
<function name="" />
<function name />
<field id="field1" type="string" onChange="func4" />
</interface>
<script uri="child.brs"/>
</component>
Expand All @@ -127,6 +128,9 @@ describe('XmlScope', () => {
range: Range.create(7, 9, 7, 17)
}, { // syntax error expecting '=' but found '/>'
code: DiagnosticMessages.xmlGenericParseError('').code
}, { // onChange function
...DiagnosticMessages.xmlFunctionNotFound('func4'),
range: Range.create(8, 51, 8, 56)
}]);
});

Expand Down
11 changes: 10 additions & 1 deletion src/XmlScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class XmlScope extends Scope {
}
//validate fields
for (const field of api.fields) {
const { id, type } = field;
const { id, type, onChange } = field;
if (!id) {
this.diagnosticMissingAttribute(field, 'id');
}
Expand All @@ -86,6 +86,15 @@ export class XmlScope extends Scope {
file: this.xmlFile
});
}
if (onChange) {
if (!callableContainerMap.has(onChange.toLowerCase())) {
this.diagnostics.push({
...DiagnosticMessages.xmlFunctionNotFound(onChange),
range: field.getAttribute('onchange').value.range,
file: this.xmlFile
});
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/SGTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class SGTag {
}

getAttributeValue(name: string): string | undefined {
return this.getAttribute(name)?.value?.text;
return this.getAttribute(name.toLowerCase())?.value?.text;
}

setAttribute(name: string, value: string) {
Expand Down

0 comments on commit 02f0de9

Please sign in to comment.