Skip to content

Commit

Permalink
Allow mod as an aa prop, aa member identifier kinds forced to Ident…
Browse files Browse the repository at this point in the history
…ifier (#684)

* Allow `mod` as an aa prop.
Force all AA member identifier-like tokens to `Identifier` kind

* lint fixes
  • Loading branch information
TwitchBronBron authored Sep 2, 2022
1 parent b701de2 commit f7d789a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lexer/TokenKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export const AllowedProperties = [
TokenKind.If,
TokenKind.Invalid,
TokenKind.Let,
TokenKind.Mod,
TokenKind.Next,
TokenKind.Not,
TokenKind.ObjFun,
Expand Down
43 changes: 42 additions & 1 deletion src/parser/Parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, assert } from 'chai';
import { Lexer } from '../lexer/Lexer';
import { ReservedWords, TokenKind } from '../lexer/TokenKind';
import type { Expression } from './Expression';
import type { AAMemberExpression, Expression } from './Expression';
import { TernaryExpression, NewExpression, IndexedGetExpression, DottedGetExpression, XmlAttributeGetExpression, CallfuncExpression, AnnotationExpression, CallExpression, FunctionExpression } from './Expression';
import { Parser, ParseMode } from './Parser';
import type { AssignmentStatement, ClassStatement, Statement } from './Statement';
Expand All @@ -14,6 +14,7 @@ import { BrsTranspileState } from './BrsTranspileState';
import { SourceNode } from 'source-map';
import { BrsFile } from '../files/BrsFile';
import { Program } from '../Program';
import { createVisitor, WalkMode } from '../astUtils/visitors';

describe('parser', () => {
it('emits empty object when empty token list is provided', () => {
Expand Down Expand Up @@ -843,7 +844,47 @@ describe('parser', () => {
`);
expect(diagnostics[0]?.message).not.to.exist;
});

it('allows `mod` as an AA literal property', () => {
const parser = parse(`
sub main()
person = {
mod: true
}
person.mod = false
print person.mod
end sub
`);
expectZeroDiagnostics(parser);
});

it('converts aa literal property TokenKind to Identifier', () => {
const parser = parse(`
sub main()
person = {
mod: true
and: true
}
end sub
`);
expectZeroDiagnostics(parser);
const elements = [] as AAMemberExpression[];
parser.ast.walk(createVisitor({
AAMemberExpression: (node) => {
elements.push(node as any);
}
}), {
walkMode: WalkMode.visitAllRecursive
});

expect(
elements.map(x => x.keyToken.kind)
).to.eql(
[TokenKind.Identifier, TokenKind.Identifier]
);
});
});

it('"end" is not allowed as a local identifier', () => {
let { diagnostics } = parse(`
sub main()
Expand Down
2 changes: 1 addition & 1 deletion src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,7 @@ export class Parser {
range: null as Range
};
if (this.checkAny(TokenKind.Identifier, ...AllowedProperties)) {
result.keyToken = this.advance();
result.keyToken = this.identifier(...AllowedProperties);
} else if (this.check(TokenKind.StringLiteral)) {
result.keyToken = this.advance();
} else {
Expand Down

0 comments on commit f7d789a

Please sign in to comment.