brighterscript 1.0.0-alpha.1 → 1.0.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +362 -248
- package/README.md +2 -2
- package/bsconfig.schema.json +1 -1
- package/dist/CodeActionUtil.d.ts +11 -2
- package/dist/CodeActionUtil.js +17 -3
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +4 -4
- package/dist/CommentFlagProcessor.js +5 -3
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticCollection.js +2 -2
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticFilterer.js +3 -3
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +15 -5
- package/dist/DiagnosticMessages.js +19 -9
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.d.ts +11 -10
- package/dist/LanguageServer.js +87 -58
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.d.ts +2 -0
- package/dist/Logger.js +5 -3
- package/dist/Logger.js.map +1 -1
- package/dist/Program.d.ts +76 -46
- package/dist/Program.js +254 -180
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +7 -7
- package/dist/ProgramBuilder.js +37 -43
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +33 -23
- package/dist/Scope.js +222 -147
- package/dist/Scope.js.map +1 -1
- package/dist/SemanticTokenUtils.d.ts +14 -0
- package/dist/SemanticTokenUtils.js +81 -0
- package/dist/SemanticTokenUtils.js.map +1 -0
- package/dist/SymbolTable.d.ts +9 -3
- package/dist/SymbolTable.js +40 -13
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.d.ts +7 -2
- package/dist/XmlScope.js +67 -29
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +27 -0
- package/dist/astUtils/AstEditor.js +97 -0
- package/dist/astUtils/AstEditor.js.map +1 -0
- package/dist/astUtils/AstEditor.spec.d.ts +1 -0
- package/dist/astUtils/AstEditor.spec.js +133 -0
- package/dist/astUtils/AstEditor.spec.js.map +1 -0
- package/dist/astUtils/creators.d.ts +15 -1
- package/dist/astUtils/creators.js +39 -9
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +4 -4
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/index.js +1 -1
- package/dist/astUtils/reflection.d.ts +20 -8
- package/dist/astUtils/reflection.js +42 -1
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +115 -115
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +13 -13
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.js +1 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +28 -28
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +4 -3
- package/dist/astUtils/xml.js +8 -3
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +2 -1
- package/dist/bscPlugin/BscPlugin.js +4 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +5 -6
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +30 -30
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +7 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js +63 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +45 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +1 -0
- package/dist/diagnosticUtils.d.ts +1 -0
- package/dist/diagnosticUtils.js +14 -7
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +2 -2
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +486 -71
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +48 -23
- package/dist/files/BrsFile.js +403 -233
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +367 -316
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +13 -6
- package/dist/files/XmlFile.js +27 -21
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +274 -228
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +49 -49
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/globalCallables.d.ts +3 -1
- package/dist/globalCallables.js +359 -87
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +51 -14
- package/dist/lexer/Lexer.d.ts +14 -1
- package/dist/lexer/Lexer.js +91 -21
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +187 -132
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.d.ts +2 -2
- package/dist/lexer/TokenKind.d.ts +7 -1
- package/dist/lexer/TokenKind.js +51 -3
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/lexer/index.js +2 -1
- package/dist/lexer/index.js.map +1 -1
- package/dist/parser/BrsTranspileState.d.ts +7 -0
- package/dist/parser/BrsTranspileState.js +10 -1
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +23 -5
- package/dist/parser/Expression.js +124 -75
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +159 -60
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +114 -26
- package/dist/parser/Parser.js +471 -126
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +396 -235
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +41 -4
- package/dist/parser/SGParser.js +186 -175
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +35 -22
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +206 -38
- package/dist/parser/SGTypes.js +470 -161
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/SGTypes.spec.d.ts +1 -0
- package/dist/parser/SGTypes.spec.js +351 -0
- package/dist/parser/SGTypes.spec.js.map +1 -0
- package/dist/parser/Statement.d.ts +92 -18
- package/dist/parser/Statement.js +287 -58
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +11 -11
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +1 -1
- package/dist/parser/TranspileState.js +15 -7
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/index.js +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +8 -7
- package/dist/parser/tests/Parser.spec.js +12 -8
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +50 -50
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +31 -31
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +174 -156
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +32 -32
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +21 -21
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +105 -105
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +148 -124
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +17 -17
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +30 -30
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +16 -16
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +247 -247
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +73 -73
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +36 -36
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +59 -47
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +35 -35
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +26 -26
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +170 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
- package/dist/parser/tests/expression/Relational.spec.js +42 -42
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +8 -8
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +12 -12
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +100 -100
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +35 -35
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/Declaration.spec.js +39 -39
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +21 -21
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Function.spec.js +192 -192
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +11 -11
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +46 -46
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +61 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/LibraryStatement.spec.js +10 -10
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +37 -36
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +30 -30
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +43 -43
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +69 -69
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +9 -9
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +5 -5
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +13 -13
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Chunk.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +1 -1
- package/dist/preprocessor/Preprocessor.js +1 -1
- package/dist/preprocessor/Preprocessor.js.map +1 -1
- package/dist/preprocessor/Preprocessor.spec.js +49 -49
- package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +72 -72
- package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
- package/dist/preprocessor/index.js +1 -1
- package/dist/types/ArrayType.js +5 -4
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +8 -8
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/BooleanType.js +3 -3
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +2 -2
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +19 -5
- package/dist/types/BscType.js +9 -0
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/CustomType.d.ts +8 -5
- package/dist/types/CustomType.js +17 -6
- package/dist/types/CustomType.js.map +1 -1
- package/dist/types/DoubleType.js +8 -8
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +2 -2
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.js +1 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +2 -2
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/FloatType.d.ts +1 -1
- package/dist/types/FloatType.js +8 -8
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +2 -2
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +5 -11
- package/dist/types/FunctionType.js +24 -13
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/FunctionType.spec.js +11 -5
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/IntegerType.d.ts +1 -1
- package/dist/types/IntegerType.js +8 -8
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +2 -2
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +8 -2
- package/dist/types/InterfaceType.js +42 -6
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.d.ts +1 -0
- package/dist/types/InterfaceType.spec.js +174 -0
- package/dist/types/InterfaceType.spec.js.map +1 -0
- package/dist/types/InvalidType.js +4 -4
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +2 -2
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LazyType.d.ts +9 -7
- package/dist/types/LazyType.js +22 -10
- package/dist/types/LazyType.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +1 -1
- package/dist/types/LongIntegerType.js +8 -8
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +2 -2
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/ObjectType.d.ts +7 -4
- package/dist/types/ObjectType.js +6 -3
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ObjectType.spec.js +2 -2
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/StringType.js +3 -3
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +2 -2
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/UninitializedType.js +3 -3
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.js +3 -3
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/VoidType.spec.js +2 -2
- package/dist/types/VoidType.spec.js.map +1 -1
- package/dist/types/helpers.d.ts +42 -0
- package/dist/types/helpers.js +113 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/util.d.ts +77 -17
- package/dist/util.js +247 -59
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +5 -1
- package/dist/validators/ClassValidator.js +59 -24
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +13 -13
package/dist/lexer/Lexer.spec.js
CHANGED
|
@@ -11,7 +11,7 @@ const util_1 = require("../util");
|
|
|
11
11
|
describe('lexer', () => {
|
|
12
12
|
it('recognizes namespace keywords', () => {
|
|
13
13
|
let { tokens } = Lexer_1.Lexer.scan('namespace end namespace endnamespace end namespace');
|
|
14
|
-
chai_1.expect(tokens.map(x => x.kind)).to.eql([
|
|
14
|
+
(0, chai_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
15
15
|
_1.TokenKind.Namespace,
|
|
16
16
|
_1.TokenKind.EndNamespace,
|
|
17
17
|
_1.TokenKind.EndNamespace,
|
|
@@ -21,43 +21,43 @@ describe('lexer', () => {
|
|
|
21
21
|
});
|
|
22
22
|
it('recognizes the callfunc operator', () => {
|
|
23
23
|
let { tokens } = Lexer_1.Lexer.scan('@.');
|
|
24
|
-
chai_1.expect(tokens[0].kind).to.equal(_1.TokenKind.Callfunc);
|
|
24
|
+
(0, chai_1.expect)(tokens[0].kind).to.equal(_1.TokenKind.Callfunc);
|
|
25
25
|
});
|
|
26
26
|
it('recognizes the import token', () => {
|
|
27
27
|
let { tokens } = Lexer_1.Lexer.scan('import');
|
|
28
|
-
chai_1.expect(tokens[0].kind).to.eql(_1.TokenKind.Import);
|
|
28
|
+
(0, chai_1.expect)(tokens[0].kind).to.eql(_1.TokenKind.Import);
|
|
29
29
|
});
|
|
30
30
|
it('recognizes library token', () => {
|
|
31
31
|
let { tokens } = Lexer_1.Lexer.scan('library');
|
|
32
|
-
chai_1.expect(tokens[0].kind).to.eql(_1.TokenKind.Library);
|
|
32
|
+
(0, chai_1.expect)(tokens[0].kind).to.eql(_1.TokenKind.Library);
|
|
33
33
|
});
|
|
34
34
|
it('recognizes the question mark operator', () => {
|
|
35
35
|
let { tokens } = Lexer_1.Lexer.scan('?');
|
|
36
|
-
chai_1.expect(tokens[0].kind).to.equal(_1.TokenKind.Question);
|
|
36
|
+
(0, chai_1.expect)(tokens[0].kind).to.equal(_1.TokenKind.Question);
|
|
37
37
|
});
|
|
38
38
|
it('produces an at symbol token', () => {
|
|
39
39
|
let { tokens } = Lexer_1.Lexer.scan('@');
|
|
40
|
-
chai_1.expect(tokens[0].kind).to.equal(_1.TokenKind.At);
|
|
40
|
+
(0, chai_1.expect)(tokens[0].kind).to.equal(_1.TokenKind.At);
|
|
41
41
|
});
|
|
42
42
|
it('produces a semicolon token', () => {
|
|
43
43
|
let { tokens } = Lexer_1.Lexer.scan(';');
|
|
44
|
-
chai_1.expect(tokens[0].kind).to.equal(_1.TokenKind.Semicolon);
|
|
44
|
+
(0, chai_1.expect)(tokens[0].kind).to.equal(_1.TokenKind.Semicolon);
|
|
45
45
|
});
|
|
46
46
|
it('emits error on unknown character type', () => {
|
|
47
47
|
let { diagnostics } = Lexer_1.Lexer.scan('\0');
|
|
48
|
-
chai_1.expect(diagnostics).to.be.lengthOf(1);
|
|
48
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(1);
|
|
49
49
|
});
|
|
50
50
|
it('includes an end-of-file marker', () => {
|
|
51
51
|
let { tokens } = Lexer_1.Lexer.scan('');
|
|
52
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Eof]);
|
|
52
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Eof]);
|
|
53
53
|
});
|
|
54
54
|
it('ignores tabs and spaces', () => {
|
|
55
55
|
let { tokens } = Lexer_1.Lexer.scan('\t\t \t \t');
|
|
56
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Eof]);
|
|
56
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Eof]);
|
|
57
57
|
});
|
|
58
58
|
it('retains every single newline', () => {
|
|
59
59
|
let { tokens } = Lexer_1.Lexer.scan('\n\n\'foo\n\n\nprint 2\n\n');
|
|
60
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
60
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
61
61
|
_1.TokenKind.Newline,
|
|
62
62
|
_1.TokenKind.Newline,
|
|
63
63
|
_1.TokenKind.Comment,
|
|
@@ -79,7 +79,7 @@ describe('lexer', () => {
|
|
|
79
79
|
' print 0\r\n' +
|
|
80
80
|
' end if\r\n' +
|
|
81
81
|
'end function\r\n').tokens.map(x => x.kind);
|
|
82
|
-
chai_1.expect(kinds).to.eql([
|
|
82
|
+
(0, chai_1.expect)(kinds).to.eql([
|
|
83
83
|
_1.TokenKind.Function, _1.TokenKind.Identifier, _1.TokenKind.LeftParen, _1.TokenKind.RightParen, _1.TokenKind.As, _1.TokenKind.String, _1.TokenKind.Newline,
|
|
84
84
|
_1.TokenKind.If, _1.TokenKind.True, _1.TokenKind.Then, _1.TokenKind.Newline,
|
|
85
85
|
_1.TokenKind.Print, _1.TokenKind.IntegerLiteral, _1.TokenKind.Newline,
|
|
@@ -92,11 +92,11 @@ describe('lexer', () => {
|
|
|
92
92
|
});
|
|
93
93
|
it('computes range properly both with and without whitespace', () => {
|
|
94
94
|
let withoutWhitespace = Lexer_1.Lexer.scan(`sub Main()\n bob = true\nend sub`).tokens
|
|
95
|
-
.map(x => Parser_spec_1.rangeToArray(x.range));
|
|
95
|
+
.map(x => (0, Parser_spec_1.rangeToArray)(x.range));
|
|
96
96
|
let withWhitespace = Lexer_1.Lexer.scan(`sub Main()\n bob = true\nend sub`).tokens
|
|
97
97
|
//filter out the whitespace...we only care that it was computed during the scan
|
|
98
98
|
.filter(x => x.kind !== _1.TokenKind.Whitespace)
|
|
99
|
-
.map(x => Parser_spec_1.rangeToArray(x.range));
|
|
99
|
+
.map(x => (0, Parser_spec_1.rangeToArray)(x.range));
|
|
100
100
|
/*eslint-disable */
|
|
101
101
|
let expectedLocations = [
|
|
102
102
|
[0, 0, 0, 3],
|
|
@@ -112,20 +112,20 @@ describe('lexer', () => {
|
|
|
112
112
|
[2, 7, 2, 8] //Eof
|
|
113
113
|
];
|
|
114
114
|
/*eslint-enable*/
|
|
115
|
-
chai_1.expect(withoutWhitespace, 'Without whitespace').to.eql(expectedLocations);
|
|
116
|
-
chai_1.expect(withWhitespace, 'With whitespace').to.eql(expectedLocations);
|
|
115
|
+
(0, chai_1.expect)(withoutWhitespace, 'Without whitespace').to.eql(expectedLocations);
|
|
116
|
+
(0, chai_1.expect)(withWhitespace, 'With whitespace').to.eql(expectedLocations);
|
|
117
117
|
});
|
|
118
118
|
it('retains original line endings', () => {
|
|
119
119
|
let { tokens } = Lexer_1.Lexer.scan('print "hello"\r\nprint "world"\n');
|
|
120
|
-
chai_1.expect([
|
|
120
|
+
(0, chai_1.expect)([
|
|
121
121
|
tokens[2].text.charCodeAt(0),
|
|
122
122
|
tokens[2].text.charCodeAt(1)
|
|
123
123
|
], 'should contain \\r\\n').to.eql([13, 10]);
|
|
124
|
-
chai_1.expect(tokens[5].text.charCodeAt(0), 'should contain \\r\\n').to.eql(10);
|
|
124
|
+
(0, chai_1.expect)(tokens[5].text.charCodeAt(0), 'should contain \\r\\n').to.eql(10);
|
|
125
125
|
});
|
|
126
126
|
it('correctly splits the elseif token', () => {
|
|
127
127
|
let { tokens } = Lexer_1.Lexer.scan('else if elseif else if');
|
|
128
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
128
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
129
129
|
_1.TokenKind.Else,
|
|
130
130
|
_1.TokenKind.If,
|
|
131
131
|
_1.TokenKind.Else,
|
|
@@ -137,20 +137,20 @@ describe('lexer', () => {
|
|
|
137
137
|
});
|
|
138
138
|
it('gives the `as` keyword its own TokenKind', () => {
|
|
139
139
|
let { tokens } = Lexer_1.Lexer.scan('as');
|
|
140
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.As, _1.TokenKind.Eof]);
|
|
140
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.As, _1.TokenKind.Eof]);
|
|
141
141
|
});
|
|
142
142
|
it('gives the `stop` keyword its own TokenKind', () => {
|
|
143
143
|
let { tokens } = Lexer_1.Lexer.scan('stop');
|
|
144
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Stop, _1.TokenKind.Eof]);
|
|
144
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Stop, _1.TokenKind.Eof]);
|
|
145
145
|
});
|
|
146
146
|
it('does not alias \'?\' to \'print\' - the parser will do that', () => {
|
|
147
147
|
let { tokens } = Lexer_1.Lexer.scan('?2');
|
|
148
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Question, _1.TokenKind.IntegerLiteral, _1.TokenKind.Eof]);
|
|
148
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Question, _1.TokenKind.IntegerLiteral, _1.TokenKind.Eof]);
|
|
149
149
|
});
|
|
150
150
|
describe('comments', () => {
|
|
151
151
|
it('does not include carriage return character', () => {
|
|
152
152
|
let tokens = Lexer_1.Lexer.scan(`'someComment\r\nprint "hello"`).tokens;
|
|
153
|
-
chai_1.expect(tokens[0].text).to.equal(`'someComment`);
|
|
153
|
+
(0, chai_1.expect)(tokens[0].text).to.equal(`'someComment`);
|
|
154
154
|
});
|
|
155
155
|
it('includes the comment characters in the text', () => {
|
|
156
156
|
let text = Lexer_1.Lexer.scan(`
|
|
@@ -159,7 +159,7 @@ describe('lexer', () => {
|
|
|
159
159
|
`).tokens
|
|
160
160
|
.filter(x => ![_1.TokenKind.Newline, _1.TokenKind.Eof].includes(x.kind))
|
|
161
161
|
.map(x => x.text);
|
|
162
|
-
chai_1.expect(text).to.eql([
|
|
162
|
+
(0, chai_1.expect)(text).to.eql([
|
|
163
163
|
`'comment`,
|
|
164
164
|
'REM some comment'
|
|
165
165
|
]);
|
|
@@ -172,8 +172,8 @@ describe('lexer', () => {
|
|
|
172
172
|
end sub
|
|
173
173
|
`, {
|
|
174
174
|
includeWhitespace: true
|
|
175
|
-
}).tokens.map(x => [...Parser_spec_1.rangeToArray(x.range), x.text]);
|
|
176
|
-
chai_1.expect(tokens).to.eql([
|
|
175
|
+
}).tokens.map(x => [...(0, Parser_spec_1.rangeToArray)(x.range), x.text]);
|
|
176
|
+
(0, chai_1.expect)(tokens).to.eql([
|
|
177
177
|
[0, 0, 0, 1, '\n'],
|
|
178
178
|
[1, 0, 1, 16, ' '],
|
|
179
179
|
[1, 16, 1, 19, 'sub'],
|
|
@@ -208,14 +208,14 @@ describe('lexer', () => {
|
|
|
208
208
|
'comment
|
|
209
209
|
REM some comment
|
|
210
210
|
`).tokens.filter(x => ![_1.TokenKind.Newline, _1.TokenKind.Eof].includes(x.kind));
|
|
211
|
-
chai_1.expect(tokens[0].range).to.eql(vscode_languageserver_1.Range.create(1, 16, 1, 24));
|
|
212
|
-
chai_1.expect(tokens[1].range).to.eql(vscode_languageserver_1.Range.create(2, 16, 2, 32));
|
|
211
|
+
(0, chai_1.expect)(tokens[0].range).to.eql(vscode_languageserver_1.Range.create(1, 16, 1, 24));
|
|
212
|
+
(0, chai_1.expect)(tokens[1].range).to.eql(vscode_languageserver_1.Range.create(2, 16, 2, 32));
|
|
213
213
|
});
|
|
214
214
|
it('finds correct location for newlines', () => {
|
|
215
215
|
let tokens = Lexer_1.Lexer.scan('sub\nsub\r\nsub\n\n').tokens
|
|
216
216
|
//ignore the Eof token
|
|
217
217
|
.filter(x => x.kind !== _1.TokenKind.Eof);
|
|
218
|
-
chai_1.expect(tokens.map(x => x.range)).to.eql([
|
|
218
|
+
(0, chai_1.expect)(tokens.map(x => x.range)).to.eql([
|
|
219
219
|
vscode_languageserver_1.Range.create(0, 0, 0, 3),
|
|
220
220
|
vscode_languageserver_1.Range.create(0, 3, 0, 4),
|
|
221
221
|
vscode_languageserver_1.Range.create(1, 0, 1, 3),
|
|
@@ -238,26 +238,26 @@ describe('lexer', () => {
|
|
|
238
238
|
end sub
|
|
239
239
|
`);
|
|
240
240
|
let comments = tokens.filter(x => x.kind === _1.TokenKind.Comment);
|
|
241
|
-
chai_1.expect(comments).to.be.lengthOf(1);
|
|
242
|
-
chai_1.expect(comments[0].range).to.eql(vscode_languageserver_1.Range.create(8, 27, 8, 35));
|
|
241
|
+
(0, chai_1.expect)(comments).to.be.lengthOf(1);
|
|
242
|
+
(0, chai_1.expect)(comments[0].range).to.eql(vscode_languageserver_1.Range.create(8, 27, 8, 35));
|
|
243
243
|
});
|
|
244
244
|
it('ignores everything after `\'`', () => {
|
|
245
245
|
let { tokens } = Lexer_1.Lexer.scan('= \' (');
|
|
246
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Equal, _1.TokenKind.Comment, _1.TokenKind.Eof]);
|
|
246
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Equal, _1.TokenKind.Comment, _1.TokenKind.Eof]);
|
|
247
247
|
});
|
|
248
248
|
it('ignores everything after `REM`', () => {
|
|
249
249
|
let { tokens } = Lexer_1.Lexer.scan('= REM (');
|
|
250
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Equal, _1.TokenKind.Comment, _1.TokenKind.Eof]);
|
|
250
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Equal, _1.TokenKind.Comment, _1.TokenKind.Eof]);
|
|
251
251
|
});
|
|
252
252
|
it('ignores everything after `rem`', () => {
|
|
253
253
|
let { tokens } = Lexer_1.Lexer.scan('= rem (');
|
|
254
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Equal, _1.TokenKind.Comment, _1.TokenKind.Eof]);
|
|
254
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.Equal, _1.TokenKind.Comment, _1.TokenKind.Eof]);
|
|
255
255
|
});
|
|
256
256
|
}); // comments
|
|
257
257
|
describe('non-literals', () => {
|
|
258
258
|
it('reads parens & braces', () => {
|
|
259
259
|
let { tokens } = Lexer_1.Lexer.scan('(){}');
|
|
260
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
260
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
261
261
|
_1.TokenKind.LeftParen,
|
|
262
262
|
_1.TokenKind.RightParen,
|
|
263
263
|
_1.TokenKind.LeftCurlyBrace,
|
|
@@ -267,7 +267,7 @@ describe('lexer', () => {
|
|
|
267
267
|
});
|
|
268
268
|
it('reads operators', () => {
|
|
269
269
|
let { tokens } = Lexer_1.Lexer.scan('^ - + * MOD / \\ -- ++');
|
|
270
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
270
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
271
271
|
_1.TokenKind.Caret,
|
|
272
272
|
_1.TokenKind.Minus,
|
|
273
273
|
_1.TokenKind.Plus,
|
|
@@ -282,7 +282,7 @@ describe('lexer', () => {
|
|
|
282
282
|
});
|
|
283
283
|
it('reads bitshift operators', () => {
|
|
284
284
|
let { tokens } = Lexer_1.Lexer.scan('<< >> <<');
|
|
285
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
285
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
286
286
|
_1.TokenKind.LeftShift,
|
|
287
287
|
_1.TokenKind.RightShift,
|
|
288
288
|
_1.TokenKind.LeftShift,
|
|
@@ -291,7 +291,7 @@ describe('lexer', () => {
|
|
|
291
291
|
});
|
|
292
292
|
it('reads bitshift assignment operators', () => {
|
|
293
293
|
let { tokens } = Lexer_1.Lexer.scan('<<= >>=');
|
|
294
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
294
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
295
295
|
_1.TokenKind.LeftShiftEqual,
|
|
296
296
|
_1.TokenKind.RightShiftEqual,
|
|
297
297
|
_1.TokenKind.Eof
|
|
@@ -299,7 +299,7 @@ describe('lexer', () => {
|
|
|
299
299
|
});
|
|
300
300
|
it('reads comparators', () => {
|
|
301
301
|
let { tokens } = Lexer_1.Lexer.scan('< <= > >= = <>');
|
|
302
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
302
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
303
303
|
_1.TokenKind.Less,
|
|
304
304
|
_1.TokenKind.LessEqual,
|
|
305
305
|
_1.TokenKind.Greater,
|
|
@@ -313,23 +313,23 @@ describe('lexer', () => {
|
|
|
313
313
|
describe('string literals', () => {
|
|
314
314
|
it('produces string literal tokens', () => {
|
|
315
315
|
let { tokens } = Lexer_1.Lexer.scan(`"hello world"`);
|
|
316
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.StringLiteral, _1.TokenKind.Eof]);
|
|
316
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([_1.TokenKind.StringLiteral, _1.TokenKind.Eof]);
|
|
317
317
|
});
|
|
318
318
|
it(`safely escapes " literals`, () => {
|
|
319
319
|
let { tokens } = Lexer_1.Lexer.scan(`"the cat says ""meow"""`);
|
|
320
|
-
chai_1.expect(tokens[0].kind).to.equal(_1.TokenKind.StringLiteral);
|
|
320
|
+
(0, chai_1.expect)(tokens[0].kind).to.equal(_1.TokenKind.StringLiteral);
|
|
321
321
|
});
|
|
322
322
|
it('captures text to end of line for unterminated strings with LF', () => {
|
|
323
323
|
let { tokens } = Lexer_1.Lexer.scan(`"unterminated!\n`);
|
|
324
|
-
chai_1.expect(tokens[0].kind).to.eql(_1.TokenKind.StringLiteral);
|
|
324
|
+
(0, chai_1.expect)(tokens[0].kind).to.eql(_1.TokenKind.StringLiteral);
|
|
325
325
|
});
|
|
326
326
|
it('captures text to end of line for unterminated strings with CRLF', () => {
|
|
327
327
|
let { tokens } = Lexer_1.Lexer.scan(`"unterminated!\r\n`);
|
|
328
|
-
chai_1.expect(tokens[0].text).to.equal('"unterminated!');
|
|
328
|
+
(0, chai_1.expect)(tokens[0].text).to.equal('"unterminated!');
|
|
329
329
|
});
|
|
330
330
|
it('disallows multiline strings', () => {
|
|
331
331
|
let { diagnostics } = Lexer_1.Lexer.scan(`"multi-line\n\n`);
|
|
332
|
-
chai_1.expect(diagnostics.map(err => err.message)).to.deep.equal([
|
|
332
|
+
(0, chai_1.expect)(diagnostics.map(err => err.message)).to.deep.equal([
|
|
333
333
|
'Unterminated string at end of line'
|
|
334
334
|
]);
|
|
335
335
|
});
|
|
@@ -338,7 +338,7 @@ describe('lexer', () => {
|
|
|
338
338
|
describe('template string literals', () => {
|
|
339
339
|
it('supports escaped chars', () => {
|
|
340
340
|
let { tokens } = Lexer_1.Lexer.scan('`\\n\\`\\r\\n`');
|
|
341
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
341
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
342
342
|
_1.TokenKind.BackTick,
|
|
343
343
|
_1.TokenKind.TemplateStringQuasi,
|
|
344
344
|
_1.TokenKind.EscapedCharCodeLiteral,
|
|
@@ -352,7 +352,7 @@ describe('lexer', () => {
|
|
|
352
352
|
_1.TokenKind.BackTick,
|
|
353
353
|
_1.TokenKind.Eof
|
|
354
354
|
]);
|
|
355
|
-
chai_1.expect(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
|
|
355
|
+
(0, chai_1.expect)(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
|
|
356
356
|
10,
|
|
357
357
|
96,
|
|
358
358
|
13,
|
|
@@ -361,7 +361,7 @@ describe('lexer', () => {
|
|
|
361
361
|
});
|
|
362
362
|
it('prevents expressions when escaping the dollar sign', () => {
|
|
363
363
|
let { tokens } = Lexer_1.Lexer.scan('`\\${just text}`');
|
|
364
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
364
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
365
365
|
_1.TokenKind.BackTick,
|
|
366
366
|
_1.TokenKind.TemplateStringQuasi,
|
|
367
367
|
_1.TokenKind.EscapedCharCodeLiteral,
|
|
@@ -372,7 +372,7 @@ describe('lexer', () => {
|
|
|
372
372
|
});
|
|
373
373
|
it('supports escaping unicode char codes', () => {
|
|
374
374
|
let { tokens } = Lexer_1.Lexer.scan('`\\c1\\c12\\c123`');
|
|
375
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
375
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
376
376
|
_1.TokenKind.BackTick,
|
|
377
377
|
_1.TokenKind.TemplateStringQuasi,
|
|
378
378
|
_1.TokenKind.EscapedCharCodeLiteral,
|
|
@@ -384,7 +384,7 @@ describe('lexer', () => {
|
|
|
384
384
|
_1.TokenKind.BackTick,
|
|
385
385
|
_1.TokenKind.Eof
|
|
386
386
|
]);
|
|
387
|
-
chai_1.expect(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
|
|
387
|
+
(0, chai_1.expect)(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
|
|
388
388
|
1,
|
|
389
389
|
12,
|
|
390
390
|
123
|
|
@@ -392,7 +392,7 @@ describe('lexer', () => {
|
|
|
392
392
|
});
|
|
393
393
|
it('converts doublequote to EscapedCharCodeLiteral', () => {
|
|
394
394
|
let { tokens } = Lexer_1.Lexer.scan('`"`');
|
|
395
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
395
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
396
396
|
_1.TokenKind.BackTick,
|
|
397
397
|
_1.TokenKind.TemplateStringQuasi,
|
|
398
398
|
_1.TokenKind.EscapedCharCodeLiteral,
|
|
@@ -400,11 +400,11 @@ describe('lexer', () => {
|
|
|
400
400
|
_1.TokenKind.BackTick,
|
|
401
401
|
_1.TokenKind.Eof
|
|
402
402
|
]);
|
|
403
|
-
chai_1.expect(tokens[2].charCode).to.equal(34);
|
|
403
|
+
(0, chai_1.expect)(tokens[2].charCode).to.equal(34);
|
|
404
404
|
});
|
|
405
405
|
it(`safely escapes \` literals`, () => {
|
|
406
406
|
let { tokens } = Lexer_1.Lexer.scan('`the cat says \\`meow\\` a lot`');
|
|
407
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
407
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
408
408
|
_1.TokenKind.BackTick,
|
|
409
409
|
_1.TokenKind.TemplateStringQuasi,
|
|
410
410
|
_1.TokenKind.EscapedCharCodeLiteral,
|
|
@@ -414,7 +414,7 @@ describe('lexer', () => {
|
|
|
414
414
|
_1.TokenKind.BackTick,
|
|
415
415
|
_1.TokenKind.Eof
|
|
416
416
|
]);
|
|
417
|
-
chai_1.expect(tokens.map(x => x.text)).to.eql([
|
|
417
|
+
(0, chai_1.expect)(tokens.map(x => x.text)).to.eql([
|
|
418
418
|
'`',
|
|
419
419
|
'the cat says ',
|
|
420
420
|
'\\`',
|
|
@@ -427,17 +427,17 @@ describe('lexer', () => {
|
|
|
427
427
|
});
|
|
428
428
|
it('produces template string literal tokens', () => {
|
|
429
429
|
let { tokens } = Lexer_1.Lexer.scan('`hello world`');
|
|
430
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
430
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
431
431
|
_1.TokenKind.BackTick,
|
|
432
432
|
_1.TokenKind.TemplateStringQuasi,
|
|
433
433
|
_1.TokenKind.BackTick,
|
|
434
434
|
_1.TokenKind.Eof
|
|
435
435
|
]);
|
|
436
|
-
chai_1.expect(tokens[1].text).to.deep.equal('hello world');
|
|
436
|
+
(0, chai_1.expect)(tokens[1].text).to.deep.equal('hello world');
|
|
437
437
|
});
|
|
438
438
|
it('collects quasis outside and expressions inside of template strings', () => {
|
|
439
439
|
let { tokens } = Lexer_1.Lexer.scan('`hello ${"world"}!`');
|
|
440
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
440
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
441
441
|
_1.TokenKind.BackTick,
|
|
442
442
|
_1.TokenKind.TemplateStringQuasi,
|
|
443
443
|
_1.TokenKind.TemplateStringExpressionBegin,
|
|
@@ -447,7 +447,7 @@ describe('lexer', () => {
|
|
|
447
447
|
_1.TokenKind.BackTick,
|
|
448
448
|
_1.TokenKind.Eof
|
|
449
449
|
]);
|
|
450
|
-
chai_1.expect(tokens[1].text).to.deep.equal(`hello `);
|
|
450
|
+
(0, chai_1.expect)(tokens[1].text).to.deep.equal(`hello `);
|
|
451
451
|
});
|
|
452
452
|
it('real example, which is causing issues in the formatter', () => {
|
|
453
453
|
let { tokens } = Lexer_1.Lexer.scan(`
|
|
@@ -466,7 +466,7 @@ describe('lexer', () => {
|
|
|
466
466
|
\`
|
|
467
467
|
end function
|
|
468
468
|
`);
|
|
469
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
469
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
470
470
|
_1.TokenKind.Newline,
|
|
471
471
|
_1.TokenKind.Function,
|
|
472
472
|
_1.TokenKind.Identifier,
|
|
@@ -544,7 +544,7 @@ describe('lexer', () => {
|
|
|
544
544
|
});
|
|
545
545
|
it('complicated example', () => {
|
|
546
546
|
let { tokens } = Lexer_1.Lexer.scan('`hello ${"world"}!I am a ${"template" + "string"} and I am very ${["pleased"][0]} to meet you ${m.top.getChildCount()}.The end`');
|
|
547
|
-
chai_1.expect(tokens.map(t => t.kind)).to.eql([
|
|
547
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.eql([
|
|
548
548
|
_1.TokenKind.BackTick,
|
|
549
549
|
_1.TokenKind.TemplateStringQuasi,
|
|
550
550
|
_1.TokenKind.TemplateStringExpressionBegin,
|
|
@@ -582,7 +582,7 @@ describe('lexer', () => {
|
|
|
582
582
|
});
|
|
583
583
|
it('allows multiline strings', () => {
|
|
584
584
|
let { tokens } = Lexer_1.Lexer.scan('`multi-line\n\n`');
|
|
585
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
585
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
586
586
|
_1.TokenKind.BackTick,
|
|
587
587
|
_1.TokenKind.TemplateStringQuasi,
|
|
588
588
|
_1.TokenKind.EscapedCharCodeLiteral,
|
|
@@ -592,7 +592,7 @@ describe('lexer', () => {
|
|
|
592
592
|
_1.TokenKind.BackTick,
|
|
593
593
|
_1.TokenKind.Eof
|
|
594
594
|
]);
|
|
595
|
-
chai_1.expect(tokens.map(x => x.text)).to.eql([
|
|
595
|
+
(0, chai_1.expect)(tokens.map(x => x.text)).to.eql([
|
|
596
596
|
'`',
|
|
597
597
|
'multi-line',
|
|
598
598
|
'\n',
|
|
@@ -605,7 +605,7 @@ describe('lexer', () => {
|
|
|
605
605
|
});
|
|
606
606
|
it('maintains proper line/column locations for multiline strings', () => {
|
|
607
607
|
let { tokens } = Lexer_1.Lexer.scan('123 `multi\nline\r\nstrings` true\nfalse');
|
|
608
|
-
chai_1.expect(tokens.map(x => {
|
|
608
|
+
(0, chai_1.expect)(tokens.map(x => {
|
|
609
609
|
return {
|
|
610
610
|
range: x.range,
|
|
611
611
|
kind: x.kind
|
|
@@ -628,7 +628,7 @@ describe('lexer', () => {
|
|
|
628
628
|
});
|
|
629
629
|
it('Example that tripped up the expression tests', () => {
|
|
630
630
|
let { tokens } = Lexer_1.Lexer.scan('`I am a complex example\n${a.isRunning(["a","b","c"])}\nmore ${m.finish(true)}`');
|
|
631
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
631
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
632
632
|
_1.TokenKind.BackTick,
|
|
633
633
|
_1.TokenKind.TemplateStringQuasi,
|
|
634
634
|
_1.TokenKind.EscapedCharCodeLiteral,
|
|
@@ -667,111 +667,111 @@ describe('lexer', () => {
|
|
|
667
667
|
describe('double literals', () => {
|
|
668
668
|
it('respects \'#\' suffix', () => {
|
|
669
669
|
let d = Lexer_1.Lexer.scan('123#').tokens[0];
|
|
670
|
-
chai_1.expect(d.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
671
|
-
chai_1.expect(d.text).to.eql('123#');
|
|
670
|
+
(0, chai_1.expect)(d.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
671
|
+
(0, chai_1.expect)(d.text).to.eql('123#');
|
|
672
672
|
});
|
|
673
673
|
it('forces literals >= 10 digits into doubles', () => {
|
|
674
674
|
let d = Lexer_1.Lexer.scan('0000000005').tokens[0];
|
|
675
|
-
chai_1.expect(d.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
676
|
-
chai_1.expect(d.text).to.eql('0000000005');
|
|
675
|
+
(0, chai_1.expect)(d.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
676
|
+
(0, chai_1.expect)(d.text).to.eql('0000000005');
|
|
677
677
|
});
|
|
678
678
|
it('forces literals with \'D\' in exponent into doubles', () => {
|
|
679
679
|
let d = Lexer_1.Lexer.scan('2.5d3').tokens[0];
|
|
680
|
-
chai_1.expect(d.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
681
|
-
chai_1.expect(d.text).to.eql('2.5d3');
|
|
680
|
+
(0, chai_1.expect)(d.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
681
|
+
(0, chai_1.expect)(d.text).to.eql('2.5d3');
|
|
682
682
|
});
|
|
683
683
|
it('allows digits before `.` to be elided', () => {
|
|
684
684
|
let f = Lexer_1.Lexer.scan('.123#').tokens[0];
|
|
685
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
686
|
-
chai_1.expect(f.text).to.eql('.123#');
|
|
685
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
686
|
+
(0, chai_1.expect)(f.text).to.eql('.123#');
|
|
687
687
|
});
|
|
688
688
|
it('allows digits after `.` to be elided', () => {
|
|
689
689
|
let f = Lexer_1.Lexer.scan('12.#').tokens[0];
|
|
690
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
691
|
-
chai_1.expect(f.text).to.eql('12.#');
|
|
690
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.DoubleLiteral);
|
|
691
|
+
(0, chai_1.expect)(f.text).to.eql('12.#');
|
|
692
692
|
});
|
|
693
693
|
});
|
|
694
694
|
describe('float literals', () => {
|
|
695
695
|
it('respects \'!\' suffix', () => {
|
|
696
696
|
let f = Lexer_1.Lexer.scan('0.00000008!').tokens[0];
|
|
697
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
697
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
698
698
|
// Floating precision will make this *not* equal
|
|
699
|
-
chai_1.expect(f.text).not.to.equal(8e-8);
|
|
700
|
-
chai_1.expect(f.text).to.eql('0.00000008!');
|
|
699
|
+
(0, chai_1.expect)(f.text).not.to.equal(8e-8);
|
|
700
|
+
(0, chai_1.expect)(f.text).to.eql('0.00000008!');
|
|
701
701
|
});
|
|
702
702
|
it('forces literals with a decimal into floats', () => {
|
|
703
703
|
let f = Lexer_1.Lexer.scan('1.0').tokens[0];
|
|
704
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
705
|
-
chai_1.expect(f.text).to.equal('1.0');
|
|
704
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
705
|
+
(0, chai_1.expect)(f.text).to.equal('1.0');
|
|
706
706
|
});
|
|
707
707
|
it('forces literals with \'E\' in exponent into floats', () => {
|
|
708
708
|
let f = Lexer_1.Lexer.scan('2.5e3').tokens[0];
|
|
709
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
710
|
-
chai_1.expect(f.text).to.eql('2.5e3');
|
|
709
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
710
|
+
(0, chai_1.expect)(f.text).to.eql('2.5e3');
|
|
711
711
|
});
|
|
712
712
|
it('supports larger-than-supported-precision floats to be defined with exponents', () => {
|
|
713
713
|
let f = Lexer_1.Lexer.scan('2.3659475627512424e-38').tokens[0];
|
|
714
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
715
|
-
chai_1.expect(f.text).to.eql('2.3659475627512424e-38');
|
|
714
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
715
|
+
(0, chai_1.expect)(f.text).to.eql('2.3659475627512424e-38');
|
|
716
716
|
});
|
|
717
717
|
it('allows digits before `.` to be elided', () => {
|
|
718
718
|
let f = Lexer_1.Lexer.scan('.123').tokens[0];
|
|
719
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
720
|
-
chai_1.expect(f.text).to.equal('.123');
|
|
719
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
720
|
+
(0, chai_1.expect)(f.text).to.equal('.123');
|
|
721
721
|
});
|
|
722
722
|
it('allows digits after `.` to be elided', () => {
|
|
723
723
|
let f = Lexer_1.Lexer.scan('12.').tokens[0];
|
|
724
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
725
|
-
chai_1.expect(f.text).to.equal('12.');
|
|
724
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
725
|
+
(0, chai_1.expect)(f.text).to.equal('12.');
|
|
726
726
|
});
|
|
727
727
|
});
|
|
728
728
|
describe('long integer literals', () => {
|
|
729
729
|
it('respects \'&\' suffix', () => {
|
|
730
730
|
let f = Lexer_1.Lexer.scan('1&').tokens[0];
|
|
731
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.LongIntegerLiteral);
|
|
732
|
-
chai_1.expect(f.text).to.eql('1&');
|
|
731
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.LongIntegerLiteral);
|
|
732
|
+
(0, chai_1.expect)(f.text).to.eql('1&');
|
|
733
733
|
});
|
|
734
734
|
it('supports hexadecimal literals', () => {
|
|
735
735
|
let i = Lexer_1.Lexer.scan('&hf00d&').tokens[0];
|
|
736
|
-
chai_1.expect(i.kind).to.equal(_1.TokenKind.LongIntegerLiteral);
|
|
737
|
-
chai_1.expect(i.text).to.equal('&hf00d&');
|
|
736
|
+
(0, chai_1.expect)(i.kind).to.equal(_1.TokenKind.LongIntegerLiteral);
|
|
737
|
+
(0, chai_1.expect)(i.text).to.equal('&hf00d&');
|
|
738
738
|
});
|
|
739
739
|
it('allows very long Int64 literals', () => {
|
|
740
740
|
let li = Lexer_1.Lexer.scan('9876543210&').tokens[0];
|
|
741
|
-
chai_1.expect(li.kind).to.equal(_1.TokenKind.LongIntegerLiteral);
|
|
742
|
-
chai_1.expect(li.text).to.equal('9876543210&');
|
|
741
|
+
(0, chai_1.expect)(li.kind).to.equal(_1.TokenKind.LongIntegerLiteral);
|
|
742
|
+
(0, chai_1.expect)(li.text).to.equal('9876543210&');
|
|
743
743
|
});
|
|
744
744
|
it('forces literals with \'&\' suffix into Int64s', () => {
|
|
745
745
|
let li = Lexer_1.Lexer.scan('123&').tokens[0];
|
|
746
|
-
chai_1.expect(li.kind).to.equal(_1.TokenKind.LongIntegerLiteral);
|
|
747
|
-
chai_1.expect(li.text).to.deep.equal('123&');
|
|
746
|
+
(0, chai_1.expect)(li.kind).to.equal(_1.TokenKind.LongIntegerLiteral);
|
|
747
|
+
(0, chai_1.expect)(li.text).to.deep.equal('123&');
|
|
748
748
|
});
|
|
749
749
|
});
|
|
750
750
|
describe('integer literals', () => {
|
|
751
751
|
it('respects \'%\' suffix', () => {
|
|
752
752
|
let f = Lexer_1.Lexer.scan('1%').tokens[0];
|
|
753
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.IntegerLiteral);
|
|
754
|
-
chai_1.expect(f.text).to.eql('1%');
|
|
753
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.IntegerLiteral);
|
|
754
|
+
(0, chai_1.expect)(f.text).to.eql('1%');
|
|
755
755
|
});
|
|
756
756
|
it('does not allow decimal numbers to end with %', () => {
|
|
757
757
|
let f = Lexer_1.Lexer.scan('1.2%').tokens[0];
|
|
758
|
-
chai_1.expect(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
759
|
-
chai_1.expect(f.text).to.eql('1.2');
|
|
758
|
+
(0, chai_1.expect)(f.kind).to.equal(_1.TokenKind.FloatLiteral);
|
|
759
|
+
(0, chai_1.expect)(f.text).to.eql('1.2');
|
|
760
760
|
});
|
|
761
761
|
it('supports hexadecimal literals', () => {
|
|
762
762
|
let i = Lexer_1.Lexer.scan('&hFf').tokens[0];
|
|
763
|
-
chai_1.expect(i.kind).to.equal(_1.TokenKind.IntegerLiteral);
|
|
764
|
-
chai_1.expect(i.text).to.deep.equal('&hFf');
|
|
763
|
+
(0, chai_1.expect)(i.kind).to.equal(_1.TokenKind.IntegerLiteral);
|
|
764
|
+
(0, chai_1.expect)(i.text).to.deep.equal('&hFf');
|
|
765
765
|
});
|
|
766
766
|
it('falls back to a regular integer', () => {
|
|
767
767
|
let i = Lexer_1.Lexer.scan('123').tokens[0];
|
|
768
|
-
chai_1.expect(i.kind).to.equal(_1.TokenKind.IntegerLiteral);
|
|
769
|
-
chai_1.expect(i.text).to.deep.equal('123');
|
|
768
|
+
(0, chai_1.expect)(i.kind).to.equal(_1.TokenKind.IntegerLiteral);
|
|
769
|
+
(0, chai_1.expect)(i.text).to.deep.equal('123');
|
|
770
770
|
});
|
|
771
771
|
});
|
|
772
772
|
describe('types', () => {
|
|
773
773
|
it('captures type tokens', () => {
|
|
774
|
-
chai_1.expect(Lexer_1.Lexer.scan(`
|
|
774
|
+
(0, chai_1.expect)(Lexer_1.Lexer.scan(`
|
|
775
775
|
void boolean integer longinteger float double string object interface invalid dynamic
|
|
776
776
|
`.trim()).tokens.map(x => x.kind)).to.eql([
|
|
777
777
|
_1.TokenKind.Void,
|
|
@@ -794,7 +794,7 @@ describe('lexer', () => {
|
|
|
794
794
|
// test just a sample of single-word reserved words for now.
|
|
795
795
|
// if we find any that we've missed
|
|
796
796
|
let { tokens } = Lexer_1.Lexer.scan('and then or if else endif return true false line_num');
|
|
797
|
-
chai_1.expect(tokens.map(w => w.kind)).to.deep.equal([
|
|
797
|
+
(0, chai_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
|
|
798
798
|
_1.TokenKind.And,
|
|
799
799
|
_1.TokenKind.Then,
|
|
800
800
|
_1.TokenKind.Or,
|
|
@@ -810,7 +810,7 @@ describe('lexer', () => {
|
|
|
810
810
|
});
|
|
811
811
|
it('matches multi-word keywords', () => {
|
|
812
812
|
let { tokens } = Lexer_1.Lexer.scan('end if end while End Sub end Function Exit wHILe');
|
|
813
|
-
chai_1.expect(tokens.map(w => w.kind)).to.deep.equal([
|
|
813
|
+
(0, chai_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
|
|
814
814
|
_1.TokenKind.EndIf,
|
|
815
815
|
_1.TokenKind.EndWhile,
|
|
816
816
|
_1.TokenKind.EndSub,
|
|
@@ -821,7 +821,7 @@ describe('lexer', () => {
|
|
|
821
821
|
});
|
|
822
822
|
it('accepts \'exit for\' but not \'exitfor\'', () => {
|
|
823
823
|
let { tokens } = Lexer_1.Lexer.scan('exit for exitfor');
|
|
824
|
-
chai_1.expect(tokens.map(w => w.kind)).to.deep.equal([
|
|
824
|
+
(0, chai_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
|
|
825
825
|
_1.TokenKind.ExitFor,
|
|
826
826
|
_1.TokenKind.Identifier,
|
|
827
827
|
_1.TokenKind.Eof
|
|
@@ -829,7 +829,7 @@ describe('lexer', () => {
|
|
|
829
829
|
});
|
|
830
830
|
it('matches keywords with silly capitalization', () => {
|
|
831
831
|
let { tokens } = Lexer_1.Lexer.scan('iF ELSE eNDIf FUncTioN');
|
|
832
|
-
chai_1.expect(tokens.map(w => w.kind)).to.deep.equal([
|
|
832
|
+
(0, chai_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
|
|
833
833
|
_1.TokenKind.If,
|
|
834
834
|
_1.TokenKind.Else,
|
|
835
835
|
_1.TokenKind.EndIf,
|
|
@@ -839,14 +839,14 @@ describe('lexer', () => {
|
|
|
839
839
|
});
|
|
840
840
|
it('allows alpha-numeric (plus \'_\') identifiers', () => {
|
|
841
841
|
let identifier = Lexer_1.Lexer.scan('_abc_123_').tokens[0];
|
|
842
|
-
chai_1.expect(identifier.kind).to.equal(_1.TokenKind.Identifier);
|
|
843
|
-
chai_1.expect(identifier.text).to.equal('_abc_123_');
|
|
842
|
+
(0, chai_1.expect)(identifier.kind).to.equal(_1.TokenKind.Identifier);
|
|
843
|
+
(0, chai_1.expect)(identifier.text).to.equal('_abc_123_');
|
|
844
844
|
});
|
|
845
845
|
it('allows identifiers with trailing type designators', () => {
|
|
846
846
|
let { tokens } = Lexer_1.Lexer.scan('lorem$ ipsum% dolor! sit# amet&');
|
|
847
847
|
let identifiers = tokens.filter(t => t.kind !== _1.TokenKind.Eof);
|
|
848
|
-
chai_1.expect(identifiers.every(t => t.kind === _1.TokenKind.Identifier));
|
|
849
|
-
chai_1.expect(identifiers.map(t => t.text)).to.deep.equal([
|
|
848
|
+
(0, chai_1.expect)(identifiers.every(t => t.kind === _1.TokenKind.Identifier));
|
|
849
|
+
(0, chai_1.expect)(identifiers.map(t => t.text)).to.deep.equal([
|
|
850
850
|
'lorem$',
|
|
851
851
|
'ipsum%',
|
|
852
852
|
'dolor!',
|
|
@@ -858,7 +858,7 @@ describe('lexer', () => {
|
|
|
858
858
|
describe('conditional compilation', () => {
|
|
859
859
|
it('reads constant declarations', () => {
|
|
860
860
|
let { tokens } = Lexer_1.Lexer.scan('#const foo true');
|
|
861
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
861
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
862
862
|
_1.TokenKind.HashConst,
|
|
863
863
|
_1.TokenKind.Identifier,
|
|
864
864
|
_1.TokenKind.True,
|
|
@@ -867,7 +867,7 @@ describe('lexer', () => {
|
|
|
867
867
|
});
|
|
868
868
|
it('reads constant aliases', () => {
|
|
869
869
|
let { tokens } = Lexer_1.Lexer.scan('#const bar foo');
|
|
870
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
870
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
871
871
|
_1.TokenKind.HashConst,
|
|
872
872
|
_1.TokenKind.Identifier,
|
|
873
873
|
_1.TokenKind.Identifier,
|
|
@@ -885,7 +885,7 @@ describe('lexer', () => {
|
|
|
885
885
|
`, {
|
|
886
886
|
includeWhitespace: false
|
|
887
887
|
});
|
|
888
|
-
chai_1.expect(tokens.map(t => t.kind).filter(x => x !== _1.TokenKind.Newline)).to.deep.equal([
|
|
888
|
+
(0, chai_1.expect)(tokens.map(t => t.kind).filter(x => x !== _1.TokenKind.Newline)).to.deep.equal([
|
|
889
889
|
_1.TokenKind.HashIf,
|
|
890
890
|
_1.TokenKind.HashElseIf,
|
|
891
891
|
_1.TokenKind.HashElseIf,
|
|
@@ -897,7 +897,7 @@ describe('lexer', () => {
|
|
|
897
897
|
});
|
|
898
898
|
it('treats text "constructor" as an identifier', () => {
|
|
899
899
|
let lexer = Lexer_1.Lexer.scan(`function constructor()\nend function`);
|
|
900
|
-
chai_1.expect(lexer.tokens[1].kind).to.equal(_1.TokenKind.Identifier);
|
|
900
|
+
(0, chai_1.expect)(lexer.tokens[1].kind).to.equal(_1.TokenKind.Identifier);
|
|
901
901
|
});
|
|
902
902
|
it('reads upper case conditional directives', () => {
|
|
903
903
|
let { tokens } = Lexer_1.Lexer.scan(`
|
|
@@ -910,7 +910,7 @@ describe('lexer', () => {
|
|
|
910
910
|
`, {
|
|
911
911
|
includeWhitespace: false
|
|
912
912
|
});
|
|
913
|
-
chai_1.expect(tokens.map(t => t.kind).filter(x => x !== _1.TokenKind.Newline)).to.deep.equal([
|
|
913
|
+
(0, chai_1.expect)(tokens.map(t => t.kind).filter(x => x !== _1.TokenKind.Newline)).to.deep.equal([
|
|
914
914
|
_1.TokenKind.HashIf,
|
|
915
915
|
_1.TokenKind.HashElseIf,
|
|
916
916
|
_1.TokenKind.HashElseIf,
|
|
@@ -922,7 +922,7 @@ describe('lexer', () => {
|
|
|
922
922
|
});
|
|
923
923
|
it('supports various spacings between #endif', () => {
|
|
924
924
|
let { tokens } = Lexer_1.Lexer.scan('#endif #end if #end\tif #end if #end\t\t if');
|
|
925
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
925
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
926
926
|
_1.TokenKind.HashEndIf,
|
|
927
927
|
_1.TokenKind.HashEndIf,
|
|
928
928
|
_1.TokenKind.HashEndIf,
|
|
@@ -935,20 +935,20 @@ describe('lexer', () => {
|
|
|
935
935
|
let { tokens } = Lexer_1.Lexer.scan('#error a message goes here\n', {
|
|
936
936
|
includeWhitespace: true
|
|
937
937
|
});
|
|
938
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
938
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
939
939
|
_1.TokenKind.HashError,
|
|
940
940
|
_1.TokenKind.Whitespace,
|
|
941
941
|
_1.TokenKind.HashErrorMessage,
|
|
942
942
|
_1.TokenKind.Newline,
|
|
943
943
|
_1.TokenKind.Eof
|
|
944
944
|
]);
|
|
945
|
-
chai_1.expect(tokens[2].text).to.equal('a message goes here');
|
|
945
|
+
(0, chai_1.expect)(tokens[2].text).to.equal('a message goes here');
|
|
946
946
|
});
|
|
947
947
|
});
|
|
948
948
|
describe('location tracking', () => {
|
|
949
949
|
it('tracks starting and ending locations including whitespace', () => {
|
|
950
950
|
let { tokens } = Lexer_1.Lexer.scan(`sub foo()\n print "bar"\r\nend sub`, { includeWhitespace: true });
|
|
951
|
-
chai_1.expect(tokens.map(t => t.range)).to.eql([
|
|
951
|
+
(0, chai_1.expect)(tokens.map(t => t.range)).to.eql([
|
|
952
952
|
vscode_languageserver_1.Range.create(0, 0, 0, 3),
|
|
953
953
|
vscode_languageserver_1.Range.create(0, 3, 0, 4),
|
|
954
954
|
vscode_languageserver_1.Range.create(0, 4, 0, 7),
|
|
@@ -966,7 +966,7 @@ describe('lexer', () => {
|
|
|
966
966
|
});
|
|
967
967
|
it('tracks starting and ending locations excluding whitespace', () => {
|
|
968
968
|
let { tokens } = Lexer_1.Lexer.scan(`sub foo()\n print "bar"\r\nend sub`, { includeWhitespace: false });
|
|
969
|
-
chai_1.expect(tokens.map(t => t.range)).to.eql([
|
|
969
|
+
(0, chai_1.expect)(tokens.map(t => t.range)).to.eql([
|
|
970
970
|
vscode_languageserver_1.Range.create(0, 0, 0, 3),
|
|
971
971
|
vscode_languageserver_1.Range.create(0, 4, 0, 7),
|
|
972
972
|
vscode_languageserver_1.Range.create(0, 7, 0, 8),
|
|
@@ -983,7 +983,7 @@ describe('lexer', () => {
|
|
|
983
983
|
describe('two word keywords', () => {
|
|
984
984
|
it('supports various spacing between for each', () => {
|
|
985
985
|
let { tokens } = Lexer_1.Lexer.scan('for each for each for each for\teach for\t each for \teach for \t each');
|
|
986
|
-
chai_1.expect(tokens.map(t => t.kind)).to.deep.equal([
|
|
986
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
|
|
987
987
|
_1.TokenKind.ForEach,
|
|
988
988
|
_1.TokenKind.ForEach,
|
|
989
989
|
_1.TokenKind.ForEach,
|
|
@@ -997,7 +997,7 @@ describe('lexer', () => {
|
|
|
997
997
|
});
|
|
998
998
|
it('detects rem when used as keyword', () => {
|
|
999
999
|
let { tokens } = Lexer_1.Lexer.scan('person.rem=true');
|
|
1000
|
-
chai_1.expect(tokens.map(t => t.kind)).to.eql([
|
|
1000
|
+
(0, chai_1.expect)(tokens.map(t => t.kind)).to.eql([
|
|
1001
1001
|
_1.TokenKind.Identifier,
|
|
1002
1002
|
_1.TokenKind.Dot,
|
|
1003
1003
|
_1.TokenKind.Identifier,
|
|
@@ -1006,7 +1006,7 @@ describe('lexer', () => {
|
|
|
1006
1006
|
_1.TokenKind.Eof
|
|
1007
1007
|
]);
|
|
1008
1008
|
//verify the location of `rem`
|
|
1009
|
-
chai_1.expect(tokens.map(t => [t.range.start.character, t.range.end.character])).to.eql([
|
|
1009
|
+
(0, chai_1.expect)(tokens.map(t => [t.range.start.character, t.range.end.character])).to.eql([
|
|
1010
1010
|
[0, 6],
|
|
1011
1011
|
[6, 7],
|
|
1012
1012
|
[7, 10],
|
|
@@ -1018,12 +1018,12 @@ describe('lexer', () => {
|
|
|
1018
1018
|
describe('isToken', () => {
|
|
1019
1019
|
it('works', () => {
|
|
1020
1020
|
let range = vscode_languageserver_1.Range.create(0, 0, 0, 2);
|
|
1021
|
-
chai_1.expect(Token_1.isToken({ kind: _1.TokenKind.And, text: 'and', range: range })).is.true;
|
|
1022
|
-
chai_1.expect(Token_1.isToken({ text: 'and', range: range })).is.false;
|
|
1021
|
+
(0, chai_1.expect)((0, Token_1.isToken)({ kind: _1.TokenKind.And, text: 'and', range: range })).is.true;
|
|
1022
|
+
(0, chai_1.expect)((0, Token_1.isToken)({ text: 'and', range: range })).is.false;
|
|
1023
1023
|
});
|
|
1024
1024
|
});
|
|
1025
1025
|
it('recognizes class-related keywords', () => {
|
|
1026
|
-
chai_1.expect(Lexer_1.Lexer.scan('class public protected private end class endclass new override').tokens.map(x => x.kind)).to.eql([
|
|
1026
|
+
(0, chai_1.expect)(Lexer_1.Lexer.scan('class public protected private end class endclass new override').tokens.map(x => x.kind)).to.eql([
|
|
1027
1027
|
_1.TokenKind.Class,
|
|
1028
1028
|
_1.TokenKind.Public,
|
|
1029
1029
|
_1.TokenKind.Protected,
|
|
@@ -1038,14 +1038,14 @@ describe('lexer', () => {
|
|
|
1038
1038
|
describe('whitespace', () => {
|
|
1039
1039
|
it('preserves the exact number of whitespace characterswhitespace', () => {
|
|
1040
1040
|
let { tokens } = Lexer_1.Lexer.scan(' ', { includeWhitespace: true });
|
|
1041
|
-
chai_1.expect(tokens[0]).to.include({
|
|
1041
|
+
(0, chai_1.expect)(tokens[0]).to.include({
|
|
1042
1042
|
kind: _1.TokenKind.Whitespace,
|
|
1043
1043
|
text: ' '
|
|
1044
1044
|
});
|
|
1045
1045
|
});
|
|
1046
1046
|
it('tokenizes whitespace between things', () => {
|
|
1047
1047
|
let { tokens } = Lexer_1.Lexer.scan('sub main ( ) \n end sub', { includeWhitespace: true });
|
|
1048
|
-
chai_1.expect(tokens.map(x => x.kind)).to.eql([
|
|
1048
|
+
(0, chai_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
1049
1049
|
_1.TokenKind.Sub,
|
|
1050
1050
|
_1.TokenKind.Whitespace,
|
|
1051
1051
|
_1.TokenKind.Identifier,
|
|
@@ -1063,7 +1063,7 @@ describe('lexer', () => {
|
|
|
1063
1063
|
});
|
|
1064
1064
|
it('identifies brighterscript source literals', () => {
|
|
1065
1065
|
let { tokens } = Lexer_1.Lexer.scan('LINE_NUM SOURCE_FILE_PATH SOURCE_LINE_NUM FUNCTION_NAME SOURCE_FUNCTION_NAME SOURCE_LOCATION PKG_PATH PKG_LOCATION');
|
|
1066
|
-
chai_1.expect(tokens.map(x => x.kind)).to.eql([
|
|
1066
|
+
(0, chai_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
1067
1067
|
_1.TokenKind.LineNumLiteral,
|
|
1068
1068
|
_1.TokenKind.SourceFilePathLiteral,
|
|
1069
1069
|
_1.TokenKind.SourceLineNumLiteral,
|
|
@@ -1084,11 +1084,11 @@ describe('lexer', () => {
|
|
|
1084
1084
|
end sub
|
|
1085
1085
|
`;
|
|
1086
1086
|
const { tokens } = Lexer_1.Lexer.scan(text, { includeWhitespace: false });
|
|
1087
|
-
chai_1.expect(util_1.default.tokensToString(tokens)).to.equal(text);
|
|
1087
|
+
(0, chai_1.expect)(util_1.default.tokensToString(tokens)).to.equal(text);
|
|
1088
1088
|
});
|
|
1089
1089
|
it('properly detects try/catch tokens', () => {
|
|
1090
1090
|
const { tokens } = Lexer_1.Lexer.scan(`try catch endtry end try throw`, { includeWhitespace: false });
|
|
1091
|
-
chai_1.expect(tokens.map(x => x.kind)).to.eql([
|
|
1091
|
+
(0, chai_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
1092
1092
|
_1.TokenKind.Try,
|
|
1093
1093
|
_1.TokenKind.Catch,
|
|
1094
1094
|
_1.TokenKind.EndTry,
|
|
@@ -1097,5 +1097,60 @@ describe('lexer', () => {
|
|
|
1097
1097
|
_1.TokenKind.Eof
|
|
1098
1098
|
]);
|
|
1099
1099
|
});
|
|
1100
|
+
describe('regular expression literals', () => {
|
|
1101
|
+
function testRegex(...regexps) {
|
|
1102
|
+
regexps = regexps.map(x => x.toString());
|
|
1103
|
+
const results = [];
|
|
1104
|
+
for (const regexp of regexps) {
|
|
1105
|
+
const { tokens } = Lexer_1.Lexer.scan(regexp);
|
|
1106
|
+
results.push(tokens[0].text);
|
|
1107
|
+
}
|
|
1108
|
+
(0, chai_1.expect)(results).to.eql(regexps);
|
|
1109
|
+
}
|
|
1110
|
+
it('recognizes regex literals', () => {
|
|
1111
|
+
testRegex(/simple/, /SimpleWithValidFlags/g, /UnknownFlags/gi, /with spaces/s, /with(parens)and[squarebraces]/,
|
|
1112
|
+
//lots of special characters
|
|
1113
|
+
/.*()^$@/,
|
|
1114
|
+
//captures quote char
|
|
1115
|
+
/"/);
|
|
1116
|
+
});
|
|
1117
|
+
it('does not capture multiple divisions on one line as regex', () => {
|
|
1118
|
+
const { tokens } = Lexer_1.Lexer.scan(`one = 1/2 + 1/4 + 1/4`, {
|
|
1119
|
+
includeWhitespace: false
|
|
1120
|
+
});
|
|
1121
|
+
(0, chai_1.expect)(tokens.map(x => x.kind)).to.eql([
|
|
1122
|
+
_1.TokenKind.Identifier,
|
|
1123
|
+
_1.TokenKind.Equal,
|
|
1124
|
+
_1.TokenKind.IntegerLiteral,
|
|
1125
|
+
_1.TokenKind.Forwardslash,
|
|
1126
|
+
_1.TokenKind.IntegerLiteral,
|
|
1127
|
+
_1.TokenKind.Plus,
|
|
1128
|
+
_1.TokenKind.IntegerLiteral,
|
|
1129
|
+
_1.TokenKind.Forwardslash,
|
|
1130
|
+
_1.TokenKind.IntegerLiteral,
|
|
1131
|
+
_1.TokenKind.Plus,
|
|
1132
|
+
_1.TokenKind.IntegerLiteral,
|
|
1133
|
+
_1.TokenKind.Forwardslash,
|
|
1134
|
+
_1.TokenKind.IntegerLiteral,
|
|
1135
|
+
_1.TokenKind.Eof
|
|
1136
|
+
]);
|
|
1137
|
+
});
|
|
1138
|
+
it('only captures alphanumeric flags', () => {
|
|
1139
|
+
(0, chai_1.expect)(Lexer_1.Lexer.scan('speak(/a/)').tokens.map(x => x.kind)).to.eql([
|
|
1140
|
+
_1.TokenKind.Identifier,
|
|
1141
|
+
_1.TokenKind.LeftParen,
|
|
1142
|
+
_1.TokenKind.RegexLiteral,
|
|
1143
|
+
_1.TokenKind.RightParen,
|
|
1144
|
+
_1.TokenKind.Eof
|
|
1145
|
+
]);
|
|
1146
|
+
});
|
|
1147
|
+
it('handles escape characters properly', () => {
|
|
1148
|
+
testRegex(
|
|
1149
|
+
//an escaped forward slash right next to the end-regexp forwardslash
|
|
1150
|
+
/\//, /\r/, /\n/, /\r\n/,
|
|
1151
|
+
//a literal backslash in front of an escape backslash
|
|
1152
|
+
/\\\n/);
|
|
1153
|
+
});
|
|
1154
|
+
});
|
|
1100
1155
|
});
|
|
1101
1156
|
//# sourceMappingURL=Lexer.spec.js.map
|