Skip to content

Commit

Permalink
Prevent regex literal in .brs mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Oct 5, 2021
1 parent f62ee46 commit 57cca5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,7 @@ export class Parser {
}

private regexLiteralExpression() {
this.warnIfNotBrighterScriptMode('regular expression literal');
return new RegexLiteralExpression({
regexLiteral: this.advance()
});
Expand Down
11 changes: 11 additions & 0 deletions src/parser/tests/expression/RegexLiteralExpression.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Program } from '../../../Program';
import { standardizePath as s } from '../../../util';
import { getTestTranspile } from '../../../testHelpers.spec';
import { expect } from 'chai';
import { DiagnosticMessages } from '../../../DiagnosticMessages';

describe('RegexLiteralExpression', () => {
let rootDir = s`${process.cwd()}/rootDir`;
Expand Down Expand Up @@ -63,6 +65,15 @@ describe('RegexLiteralExpression', () => {
`);
});

it('warns when in non-brighterscript mode', () => {
program.addOrReplaceFile('source/main.brs', `
sub main()
print /"/
end sub
`);
expect(program.getDiagnostics()[0].code).to.eql(DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('').code);
});

it('handles edge cases', () => {
testTranspile(`
sub main()
Expand Down

0 comments on commit 57cca5d

Please sign in to comment.