@tslite/parser 1.9.0 → 1.12.0
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/LICENSE +55 -0
- package/NOTICE +14 -0
- package/dist/_namespaces/ts.d.ts +18 -0
- package/dist/_namespaces/ts.js +21 -0
- package/dist/_namespaces/ts.performance.d.ts +1 -0
- package/dist/_namespaces/ts.performance.js +2 -0
- package/dist/core.d.ts +450 -0
- package/dist/core.js +1394 -0
- package/dist/corePublic.d.ts +62 -0
- package/dist/corePublic.js +31 -0
- package/dist/debug.d.ts +74 -0
- package/dist/debug.js +326 -0
- package/dist/diagnosticInformationMap.generated.d.ts +1435 -0
- package/dist/diagnosticInformationMap.generated.js +1441 -0
- package/dist/factory.d.ts +78 -0
- package/dist/factory.js +622 -0
- package/dist/factoryPublic.d.ts +314 -0
- package/dist/factoryPublic.js +1796 -0
- package/dist/index.d.ts +1 -249
- package/dist/index.js +4 -6
- package/dist/parser.d.ts +59 -0
- package/dist/parser.js +5075 -0
- package/dist/path.d.ts +312 -0
- package/dist/path.js +475 -0
- package/dist/perfLogger.d.ts +4 -0
- package/dist/perfLogger.js +38 -0
- package/dist/performance.d.ts +20 -0
- package/dist/performance.js +49 -0
- package/dist/performanceTimestamp.d.ts +2 -0
- package/dist/performanceTimestamp.js +2 -0
- package/dist/scanner.d.ts +80 -0
- package/dist/scanner.js +1984 -0
- package/dist/shims/mapShim.d.ts +23 -0
- package/dist/shims/mapShim.js +156 -0
- package/dist/types.d.ts +2626 -0
- package/dist/types.js +1074 -0
- package/dist/utilities.d.ts +473 -0
- package/dist/utilities.js +2632 -0
- package/dist/utilitiesPublic.d.ts +274 -0
- package/dist/utilitiesPublic.js +1049 -0
- package/dist/visitor.d.ts +15 -0
- package/dist/visitor.js +64 -0
- package/dist/visitorPublic.d.ts +82 -0
- package/dist/visitorPublic.js +352 -0
- package/package.json +14 -42
- package/dist/index.cjs +0 -6
- package/dist/index.d.cts +0 -249
package/dist/scanner.js
ADDED
|
@@ -0,0 +1,1984 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/compiler/scanner.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Debug, Diagnostics, append, arraysEqual, binarySearch, compareValues, createMapFromTemplate, identity, parsePseudoBigInt, positionIsSynthesized, } from "./_namespaces/ts.js";
|
|
3
|
+
export function tokenIsIdentifierOrKeyword(token) {
|
|
4
|
+
return token >= 75 /* SyntaxKind.Identifier */;
|
|
5
|
+
}
|
|
6
|
+
export function tokenIsIdentifierOrKeywordOrGreaterThan(token) {
|
|
7
|
+
return token === 31 /* SyntaxKind.GreaterThanToken */ || tokenIsIdentifierOrKeyword(token);
|
|
8
|
+
}
|
|
9
|
+
const textToKeywordObj = {
|
|
10
|
+
any: 125 /* SyntaxKind.AnyKeyword */,
|
|
11
|
+
as: 123 /* SyntaxKind.AsKeyword */,
|
|
12
|
+
asserts: 124 /* SyntaxKind.AssertsKeyword */,
|
|
13
|
+
bigint: 151 /* SyntaxKind.BigIntKeyword */,
|
|
14
|
+
boolean: 128 /* SyntaxKind.BooleanKeyword */,
|
|
15
|
+
break: 77 /* SyntaxKind.BreakKeyword */,
|
|
16
|
+
case: 78 /* SyntaxKind.CaseKeyword */,
|
|
17
|
+
catch: 79 /* SyntaxKind.CatchKeyword */,
|
|
18
|
+
continue: 82 /* SyntaxKind.ContinueKeyword */,
|
|
19
|
+
const: 81 /* SyntaxKind.ConstKeyword */,
|
|
20
|
+
declare: 130 /* SyntaxKind.DeclareKeyword */,
|
|
21
|
+
default: 84 /* SyntaxKind.DefaultKeyword */,
|
|
22
|
+
delete: 85 /* SyntaxKind.DeleteKeyword */,
|
|
23
|
+
do: 86 /* SyntaxKind.DoKeyword */,
|
|
24
|
+
else: 87 /* SyntaxKind.ElseKeyword */,
|
|
25
|
+
export: 89 /* SyntaxKind.ExportKeyword */,
|
|
26
|
+
extends: 90 /* SyntaxKind.ExtendsKeyword */,
|
|
27
|
+
false: 91 /* SyntaxKind.FalseKeyword */,
|
|
28
|
+
finally: 92 /* SyntaxKind.FinallyKeyword */,
|
|
29
|
+
for: 93 /* SyntaxKind.ForKeyword */,
|
|
30
|
+
from: 149 /* SyntaxKind.FromKeyword */,
|
|
31
|
+
if: 95 /* SyntaxKind.IfKeyword */,
|
|
32
|
+
import: 96 /* SyntaxKind.ImportKeyword */,
|
|
33
|
+
in: 97 /* SyntaxKind.InKeyword */,
|
|
34
|
+
infer: 132 /* SyntaxKind.InferKeyword */,
|
|
35
|
+
is: 133 /* SyntaxKind.IsKeyword */,
|
|
36
|
+
keyof: 134 /* SyntaxKind.KeyOfKeyword */,
|
|
37
|
+
let: 115 /* SyntaxKind.LetKeyword */,
|
|
38
|
+
namespace: 136 /* SyntaxKind.NamespaceKeyword */,
|
|
39
|
+
never: 137 /* SyntaxKind.NeverKeyword */,
|
|
40
|
+
null: 100 /* SyntaxKind.NullKeyword */,
|
|
41
|
+
number: 140 /* SyntaxKind.NumberKeyword */,
|
|
42
|
+
object: 141 /* SyntaxKind.ObjectKeyword */,
|
|
43
|
+
readonly: 138 /* SyntaxKind.ReadonlyKeyword */,
|
|
44
|
+
global: 150 /* SyntaxKind.GlobalKeyword */,
|
|
45
|
+
return: 101 /* SyntaxKind.ReturnKeyword */,
|
|
46
|
+
string: 143 /* SyntaxKind.StringKeyword */,
|
|
47
|
+
switch: 103 /* SyntaxKind.SwitchKeyword */,
|
|
48
|
+
symbol: 144 /* SyntaxKind.SymbolKeyword */,
|
|
49
|
+
throw: 105 /* SyntaxKind.ThrowKeyword */,
|
|
50
|
+
true: 106 /* SyntaxKind.TrueKeyword */,
|
|
51
|
+
try: 107 /* SyntaxKind.TryKeyword */,
|
|
52
|
+
type: 145 /* SyntaxKind.TypeKeyword */,
|
|
53
|
+
typeof: 108 /* SyntaxKind.TypeOfKeyword */,
|
|
54
|
+
undefined: 146 /* SyntaxKind.UndefinedKeyword */,
|
|
55
|
+
unknown: 148 /* SyntaxKind.UnknownKeyword */,
|
|
56
|
+
void: 110 /* SyntaxKind.VoidKeyword */,
|
|
57
|
+
while: 111 /* SyntaxKind.WhileKeyword */,
|
|
58
|
+
async: 126 /* SyntaxKind.AsyncKeyword */,
|
|
59
|
+
await: 127 /* SyntaxKind.AwaitKeyword */,
|
|
60
|
+
of: 152 /* SyntaxKind.OfKeyword */,
|
|
61
|
+
};
|
|
62
|
+
const textToKeyword = createMapFromTemplate(textToKeywordObj);
|
|
63
|
+
const textToToken = createMapFromTemplate({
|
|
64
|
+
...textToKeywordObj,
|
|
65
|
+
"{": 18 /* SyntaxKind.OpenBraceToken */,
|
|
66
|
+
"}": 19 /* SyntaxKind.CloseBraceToken */,
|
|
67
|
+
"(": 20 /* SyntaxKind.OpenParenToken */,
|
|
68
|
+
")": 21 /* SyntaxKind.CloseParenToken */,
|
|
69
|
+
"[": 22 /* SyntaxKind.OpenBracketToken */,
|
|
70
|
+
"]": 23 /* SyntaxKind.CloseBracketToken */,
|
|
71
|
+
".": 24 /* SyntaxKind.DotToken */,
|
|
72
|
+
"...": 25 /* SyntaxKind.DotDotDotToken */,
|
|
73
|
+
";": 26 /* SyntaxKind.SemicolonToken */,
|
|
74
|
+
",": 27 /* SyntaxKind.CommaToken */,
|
|
75
|
+
"<": 29 /* SyntaxKind.LessThanToken */,
|
|
76
|
+
">": 31 /* SyntaxKind.GreaterThanToken */,
|
|
77
|
+
"<=": 32 /* SyntaxKind.LessThanEqualsToken */,
|
|
78
|
+
">=": 33 /* SyntaxKind.GreaterThanEqualsToken */,
|
|
79
|
+
"==": 34 /* SyntaxKind.EqualsEqualsToken */,
|
|
80
|
+
"!=": 35 /* SyntaxKind.ExclamationEqualsToken */,
|
|
81
|
+
"===": 36 /* SyntaxKind.EqualsEqualsEqualsToken */,
|
|
82
|
+
"!==": 37 /* SyntaxKind.ExclamationEqualsEqualsToken */,
|
|
83
|
+
"=>": 38 /* SyntaxKind.EqualsGreaterThanToken */,
|
|
84
|
+
"+": 39 /* SyntaxKind.PlusToken */,
|
|
85
|
+
"-": 40 /* SyntaxKind.MinusToken */,
|
|
86
|
+
"**": 42 /* SyntaxKind.AsteriskAsteriskToken */,
|
|
87
|
+
"*": 41 /* SyntaxKind.AsteriskToken */,
|
|
88
|
+
"/": 43 /* SyntaxKind.SlashToken */,
|
|
89
|
+
"%": 44 /* SyntaxKind.PercentToken */,
|
|
90
|
+
"++": 45 /* SyntaxKind.PlusPlusToken */,
|
|
91
|
+
"--": 46 /* SyntaxKind.MinusMinusToken */,
|
|
92
|
+
"<<": 47 /* SyntaxKind.LessThanLessThanToken */,
|
|
93
|
+
"</": 30 /* SyntaxKind.LessThanSlashToken */,
|
|
94
|
+
">>": 48 /* SyntaxKind.GreaterThanGreaterThanToken */,
|
|
95
|
+
">>>": 49 /* SyntaxKind.GreaterThanGreaterThanGreaterThanToken */,
|
|
96
|
+
"&": 50 /* SyntaxKind.AmpersandToken */,
|
|
97
|
+
"|": 51 /* SyntaxKind.BarToken */,
|
|
98
|
+
"^": 52 /* SyntaxKind.CaretToken */,
|
|
99
|
+
"!": 53 /* SyntaxKind.ExclamationToken */,
|
|
100
|
+
"~": 54 /* SyntaxKind.TildeToken */,
|
|
101
|
+
"&&": 55 /* SyntaxKind.AmpersandAmpersandToken */,
|
|
102
|
+
"||": 56 /* SyntaxKind.BarBarToken */,
|
|
103
|
+
"?": 57 /* SyntaxKind.QuestionToken */,
|
|
104
|
+
"??": 60 /* SyntaxKind.QuestionQuestionToken */,
|
|
105
|
+
"?.": 28 /* SyntaxKind.QuestionDotToken */,
|
|
106
|
+
":": 58 /* SyntaxKind.ColonToken */,
|
|
107
|
+
"=": 62 /* SyntaxKind.EqualsToken */,
|
|
108
|
+
"+=": 63 /* SyntaxKind.PlusEqualsToken */,
|
|
109
|
+
"-=": 64 /* SyntaxKind.MinusEqualsToken */,
|
|
110
|
+
"*=": 65 /* SyntaxKind.AsteriskEqualsToken */,
|
|
111
|
+
"**=": 66 /* SyntaxKind.AsteriskAsteriskEqualsToken */,
|
|
112
|
+
"/=": 67 /* SyntaxKind.SlashEqualsToken */,
|
|
113
|
+
"%=": 68 /* SyntaxKind.PercentEqualsToken */,
|
|
114
|
+
"<<=": 69 /* SyntaxKind.LessThanLessThanEqualsToken */,
|
|
115
|
+
">>=": 70 /* SyntaxKind.GreaterThanGreaterThanEqualsToken */,
|
|
116
|
+
">>>=": 71 /* SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken */,
|
|
117
|
+
"&=": 72 /* SyntaxKind.AmpersandEqualsToken */,
|
|
118
|
+
"|=": 73 /* SyntaxKind.BarEqualsToken */,
|
|
119
|
+
"^=": 74 /* SyntaxKind.CaretEqualsToken */,
|
|
120
|
+
"@": 59 /* SyntaxKind.AtToken */,
|
|
121
|
+
"`": 61 /* SyntaxKind.BacktickToken */
|
|
122
|
+
});
|
|
123
|
+
/*
|
|
124
|
+
As per ECMAScript Language Specification 3th Edition, Section 7.6: Identifiers
|
|
125
|
+
IdentifierStart ::
|
|
126
|
+
Can contain Unicode 3.0.0 categories:
|
|
127
|
+
Uppercase letter (Lu),
|
|
128
|
+
Lowercase letter (Ll),
|
|
129
|
+
Titlecase letter (Lt),
|
|
130
|
+
Modifier letter (Lm),
|
|
131
|
+
Other letter (Lo), or
|
|
132
|
+
Letter number (Nl).
|
|
133
|
+
IdentifierPart :: =
|
|
134
|
+
Can contain IdentifierStart + Unicode 3.0.0 categories:
|
|
135
|
+
Non-spacing mark (Mn),
|
|
136
|
+
Combining spacing mark (Mc),
|
|
137
|
+
Decimal number (Nd), or
|
|
138
|
+
Connector punctuation (Pc).
|
|
139
|
+
|
|
140
|
+
Codepoint ranges for ES3 Identifiers are extracted from the Unicode 3.0.0 specification at:
|
|
141
|
+
http://www.unicode.org/Public/3.0-Update/UnicodeData-3.0.0.txt
|
|
142
|
+
*/
|
|
143
|
+
const unicodeES3IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1610, 1649, 1747, 1749, 1749, 1765, 1766, 1786, 1788, 1808, 1808, 1810, 1836, 1920, 1957, 2309, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2784, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3294, 3294, 3296, 3297, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3424, 3425, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3805, 3840, 3840, 3904, 3911, 3913, 3946, 3976, 3979, 4096, 4129, 4131, 4135, 4137, 4138, 4176, 4181, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6067, 6176, 6263, 6272, 6312, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8319, 8319, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12346, 12353, 12436, 12445, 12446, 12449, 12538, 12540, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65138, 65140, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
|
|
144
|
+
const unicodeES3IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592, 685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 768, 846, 864, 866, 890, 890, 902, 902, 904, 906, 908, 908, 910, 929, 931, 974, 976, 983, 986, 1011, 1024, 1153, 1155, 1158, 1164, 1220, 1223, 1224, 1227, 1228, 1232, 1269, 1272, 1273, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1441, 1443, 1465, 1467, 1469, 1471, 1471, 1473, 1474, 1476, 1476, 1488, 1514, 1520, 1522, 1569, 1594, 1600, 1621, 1632, 1641, 1648, 1747, 1749, 1756, 1759, 1768, 1770, 1773, 1776, 1788, 1808, 1836, 1840, 1866, 1920, 1968, 2305, 2307, 2309, 2361, 2364, 2381, 2384, 2388, 2392, 2403, 2406, 2415, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2492, 2494, 2500, 2503, 2504, 2507, 2509, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2562, 2562, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2649, 2652, 2654, 2654, 2662, 2676, 2689, 2691, 2693, 2699, 2701, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2784, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2870, 2873, 2876, 2883, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2913, 2918, 2927, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 2997, 2999, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3031, 3031, 3047, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3134, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3168, 3169, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3262, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3297, 3302, 3311, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3368, 3370, 3385, 3390, 3395, 3398, 3400, 3402, 3405, 3415, 3415, 3424, 3425, 3430, 3439, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3805, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3946, 3953, 3972, 3974, 3979, 3984, 3991, 3993, 4028, 4038, 4038, 4096, 4129, 4131, 4135, 4137, 4138, 4140, 4146, 4150, 4153, 4160, 4169, 4176, 4185, 4256, 4293, 4304, 4342, 4352, 4441, 4447, 4514, 4520, 4601, 4608, 4614, 4616, 4678, 4680, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4742, 4744, 4744, 4746, 4749, 4752, 4782, 4784, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4814, 4816, 4822, 4824, 4846, 4848, 4878, 4880, 4880, 4882, 4885, 4888, 4894, 4896, 4934, 4936, 4954, 4969, 4977, 5024, 5108, 5121, 5740, 5743, 5750, 5761, 5786, 5792, 5866, 6016, 6099, 6112, 6121, 6160, 6169, 6176, 6263, 6272, 6313, 7680, 7835, 7840, 7929, 7936, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8319, 8319, 8400, 8412, 8417, 8417, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8497, 8499, 8505, 8544, 8579, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12346, 12353, 12436, 12441, 12442, 12445, 12446, 12449, 12542, 12549, 12588, 12593, 12686, 12704, 12727, 13312, 19893, 19968, 40869, 40960, 42124, 44032, 55203, 63744, 64045, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65056, 65059, 65075, 65076, 65101, 65103, 65136, 65138, 65140, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65381, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
|
|
145
|
+
/*
|
|
146
|
+
As per ECMAScript Language Specification 5th Edition, Section 7.6: ISyntaxToken Names and Identifiers
|
|
147
|
+
IdentifierStart ::
|
|
148
|
+
Can contain Unicode 6.2 categories:
|
|
149
|
+
Uppercase letter (Lu),
|
|
150
|
+
Lowercase letter (Ll),
|
|
151
|
+
Titlecase letter (Lt),
|
|
152
|
+
Modifier letter (Lm),
|
|
153
|
+
Other letter (Lo), or
|
|
154
|
+
Letter number (Nl).
|
|
155
|
+
IdentifierPart ::
|
|
156
|
+
Can contain IdentifierStart + Unicode 6.2 categories:
|
|
157
|
+
Non-spacing mark (Mn),
|
|
158
|
+
Combining spacing mark (Mc),
|
|
159
|
+
Decimal number (Nd),
|
|
160
|
+
Connector punctuation (Pc),
|
|
161
|
+
<ZWNJ>, or
|
|
162
|
+
<ZWJ>.
|
|
163
|
+
|
|
164
|
+
Codepoint ranges for ES5 Identifiers are extracted from the Unicode 6.2 specification at:
|
|
165
|
+
http://www.unicode.org/Public/6.2.0/ucd/UnicodeData.txt
|
|
166
|
+
*/
|
|
167
|
+
const unicodeES5IdentifierStart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1488, 1514, 1520, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2208, 2208, 2210, 2220, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2423, 2425, 2431, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3133, 3160, 3161, 3168, 3169, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3424, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6263, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6428, 6480, 6509, 6512, 6516, 6528, 6571, 6593, 6599, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7401, 7404, 7406, 7409, 7413, 7414, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11823, 11823, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42647, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43648, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
|
|
168
|
+
const unicodeES5IdentifierPart = [170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1319, 1329, 1366, 1369, 1369, 1377, 1415, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1520, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2048, 2093, 2112, 2139, 2208, 2208, 2210, 2220, 2276, 2302, 2304, 2403, 2406, 2415, 2417, 2423, 2425, 2431, 2433, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3073, 3075, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3123, 3125, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3161, 3168, 3171, 3174, 3183, 3202, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3330, 3331, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3396, 3398, 3400, 3402, 3406, 3415, 3415, 3424, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3719, 3720, 3722, 3722, 3725, 3725, 3732, 3735, 3737, 3743, 3745, 3747, 3749, 3749, 3751, 3751, 3754, 3755, 3757, 3769, 3771, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4992, 5007, 5024, 5108, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5872, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6263, 6272, 6314, 6320, 6389, 6400, 6428, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6617, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7376, 7378, 7380, 7414, 7424, 7654, 7676, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8204, 8205, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8473, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8493, 8495, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 11823, 11823, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12442, 12445, 12447, 12449, 12538, 12540, 12543, 12549, 12589, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40908, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42647, 42655, 42737, 42775, 42783, 42786, 42888, 42891, 42894, 42896, 42899, 42912, 42922, 43000, 43047, 43072, 43123, 43136, 43204, 43216, 43225, 43232, 43255, 43259, 43259, 43264, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43643, 43648, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43968, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65062, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500,];
|
|
169
|
+
/**
|
|
170
|
+
* Generated by scripts/regenerate-unicode-identifier-parts.js on node v12.4.0 with unicode 12.1
|
|
171
|
+
* based on http://www.unicode.org/reports/tr31/ and https://www.ecma-international.org/ecma-262/6.0/#sec-names-and-keywords
|
|
172
|
+
* unicodeESNextIdentifierStart corresponds to the ID_Start and Other_ID_Start property, and
|
|
173
|
+
* unicodeESNextIdentifierPart corresponds to ID_Continue, Other_ID_Continue, plus ID_Start and Other_ID_Start
|
|
174
|
+
*/
|
|
175
|
+
const unicodeESNextIdentifierStart = [65, 90, 97, 122, 170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 880, 884, 886, 887, 890, 893, 895, 895, 902, 902, 904, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1162, 1327, 1329, 1366, 1369, 1369, 1376, 1416, 1488, 1514, 1519, 1522, 1568, 1610, 1646, 1647, 1649, 1747, 1749, 1749, 1765, 1766, 1774, 1775, 1786, 1788, 1791, 1791, 1808, 1808, 1810, 1839, 1869, 1957, 1969, 1969, 1994, 2026, 2036, 2037, 2042, 2042, 2048, 2069, 2074, 2074, 2084, 2084, 2088, 2088, 2112, 2136, 2144, 2154, 2208, 2228, 2230, 2237, 2308, 2361, 2365, 2365, 2384, 2384, 2392, 2401, 2417, 2432, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2493, 2493, 2510, 2510, 2524, 2525, 2527, 2529, 2544, 2545, 2556, 2556, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2649, 2652, 2654, 2654, 2674, 2676, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2749, 2749, 2768, 2768, 2784, 2785, 2809, 2809, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2877, 2877, 2908, 2909, 2911, 2913, 2929, 2929, 2947, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3024, 3024, 3077, 3084, 3086, 3088, 3090, 3112, 3114, 3129, 3133, 3133, 3160, 3162, 3168, 3169, 3200, 3200, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3261, 3261, 3294, 3294, 3296, 3297, 3313, 3314, 3333, 3340, 3342, 3344, 3346, 3386, 3389, 3389, 3406, 3406, 3412, 3414, 3423, 3425, 3450, 3455, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3585, 3632, 3634, 3635, 3648, 3654, 3713, 3714, 3716, 3716, 3718, 3722, 3724, 3747, 3749, 3749, 3751, 3760, 3762, 3763, 3773, 3773, 3776, 3780, 3782, 3782, 3804, 3807, 3840, 3840, 3904, 3911, 3913, 3948, 3976, 3980, 4096, 4138, 4159, 4159, 4176, 4181, 4186, 4189, 4193, 4193, 4197, 4198, 4206, 4208, 4213, 4225, 4238, 4238, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4992, 5007, 5024, 5109, 5112, 5117, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5880, 5888, 5900, 5902, 5905, 5920, 5937, 5952, 5969, 5984, 5996, 5998, 6000, 6016, 6067, 6103, 6103, 6108, 6108, 6176, 6264, 6272, 6312, 6314, 6314, 6320, 6389, 6400, 6430, 6480, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6656, 6678, 6688, 6740, 6823, 6823, 6917, 6963, 6981, 6987, 7043, 7072, 7086, 7087, 7098, 7141, 7168, 7203, 7245, 7247, 7258, 7293, 7296, 7304, 7312, 7354, 7357, 7359, 7401, 7404, 7406, 7411, 7413, 7414, 7418, 7418, 7424, 7615, 7680, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8305, 8305, 8319, 8319, 8336, 8348, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8472, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11502, 11506, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11648, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 12293, 12295, 12321, 12329, 12337, 12341, 12344, 12348, 12353, 12438, 12443, 12447, 12449, 12538, 12540, 12543, 12549, 12591, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40943, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42527, 42538, 42539, 42560, 42606, 42623, 42653, 42656, 42735, 42775, 42783, 42786, 42888, 42891, 42943, 42946, 42950, 42999, 43009, 43011, 43013, 43015, 43018, 43020, 43042, 43072, 43123, 43138, 43187, 43250, 43255, 43259, 43259, 43261, 43262, 43274, 43301, 43312, 43334, 43360, 43388, 43396, 43442, 43471, 43471, 43488, 43492, 43494, 43503, 43514, 43518, 43520, 43560, 43584, 43586, 43588, 43595, 43616, 43638, 43642, 43642, 43646, 43695, 43697, 43697, 43701, 43702, 43705, 43709, 43712, 43712, 43714, 43714, 43739, 43741, 43744, 43754, 43762, 43764, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43824, 43866, 43868, 43879, 43888, 44002, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64285, 64287, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65136, 65140, 65142, 65276, 65313, 65338, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65536, 65547, 65549, 65574, 65576, 65594, 65596, 65597, 65599, 65613, 65616, 65629, 65664, 65786, 65856, 65908, 66176, 66204, 66208, 66256, 66304, 66335, 66349, 66378, 66384, 66421, 66432, 66461, 66464, 66499, 66504, 66511, 66513, 66517, 66560, 66717, 66736, 66771, 66776, 66811, 66816, 66855, 66864, 66915, 67072, 67382, 67392, 67413, 67424, 67431, 67584, 67589, 67592, 67592, 67594, 67637, 67639, 67640, 67644, 67644, 67647, 67669, 67680, 67702, 67712, 67742, 67808, 67826, 67828, 67829, 67840, 67861, 67872, 67897, 67968, 68023, 68030, 68031, 68096, 68096, 68112, 68115, 68117, 68119, 68121, 68149, 68192, 68220, 68224, 68252, 68288, 68295, 68297, 68324, 68352, 68405, 68416, 68437, 68448, 68466, 68480, 68497, 68608, 68680, 68736, 68786, 68800, 68850, 68864, 68899, 69376, 69404, 69415, 69415, 69424, 69445, 69600, 69622, 69635, 69687, 69763, 69807, 69840, 69864, 69891, 69926, 69956, 69956, 69968, 70002, 70006, 70006, 70019, 70066, 70081, 70084, 70106, 70106, 70108, 70108, 70144, 70161, 70163, 70187, 70272, 70278, 70280, 70280, 70282, 70285, 70287, 70301, 70303, 70312, 70320, 70366, 70405, 70412, 70415, 70416, 70419, 70440, 70442, 70448, 70450, 70451, 70453, 70457, 70461, 70461, 70480, 70480, 70493, 70497, 70656, 70708, 70727, 70730, 70751, 70751, 70784, 70831, 70852, 70853, 70855, 70855, 71040, 71086, 71128, 71131, 71168, 71215, 71236, 71236, 71296, 71338, 71352, 71352, 71424, 71450, 71680, 71723, 71840, 71903, 71935, 71935, 72096, 72103, 72106, 72144, 72161, 72161, 72163, 72163, 72192, 72192, 72203, 72242, 72250, 72250, 72272, 72272, 72284, 72329, 72349, 72349, 72384, 72440, 72704, 72712, 72714, 72750, 72768, 72768, 72818, 72847, 72960, 72966, 72968, 72969, 72971, 73008, 73030, 73030, 73056, 73061, 73063, 73064, 73066, 73097, 73112, 73112, 73440, 73458, 73728, 74649, 74752, 74862, 74880, 75075, 77824, 78894, 82944, 83526, 92160, 92728, 92736, 92766, 92880, 92909, 92928, 92975, 92992, 92995, 93027, 93047, 93053, 93071, 93760, 93823, 93952, 94026, 94032, 94032, 94099, 94111, 94176, 94177, 94179, 94179, 94208, 100343, 100352, 101106, 110592, 110878, 110928, 110930, 110948, 110951, 110960, 111355, 113664, 113770, 113776, 113788, 113792, 113800, 113808, 113817, 119808, 119892, 119894, 119964, 119966, 119967, 119970, 119970, 119973, 119974, 119977, 119980, 119982, 119993, 119995, 119995, 119997, 120003, 120005, 120069, 120071, 120074, 120077, 120084, 120086, 120092, 120094, 120121, 120123, 120126, 120128, 120132, 120134, 120134, 120138, 120144, 120146, 120485, 120488, 120512, 120514, 120538, 120540, 120570, 120572, 120596, 120598, 120628, 120630, 120654, 120656, 120686, 120688, 120712, 120714, 120744, 120746, 120770, 120772, 120779, 123136, 123180, 123191, 123197, 123214, 123214, 123584, 123627, 124928, 125124, 125184, 125251, 125259, 125259, 126464, 126467, 126469, 126495, 126497, 126498, 126500, 126500, 126503, 126503, 126505, 126514, 126516, 126519, 126521, 126521, 126523, 126523, 126530, 126530, 126535, 126535, 126537, 126537, 126539, 126539, 126541, 126543, 126545, 126546, 126548, 126548, 126551, 126551, 126553, 126553, 126555, 126555, 126557, 126557, 126559, 126559, 126561, 126562, 126564, 126564, 126567, 126570, 126572, 126578, 126580, 126583, 126585, 126588, 126590, 126590, 126592, 126601, 126603, 126619, 126625, 126627, 126629, 126633, 126635, 126651, 131072, 173782, 173824, 177972, 177984, 178205, 178208, 183969, 183984, 191456, 194560, 195101];
|
|
176
|
+
const unicodeESNextIdentifierPart = [48, 57, 65, 90, 95, 95, 97, 122, 170, 170, 181, 181, 183, 183, 186, 186, 192, 214, 216, 246, 248, 705, 710, 721, 736, 740, 748, 748, 750, 750, 768, 884, 886, 887, 890, 893, 895, 895, 902, 906, 908, 908, 910, 929, 931, 1013, 1015, 1153, 1155, 1159, 1162, 1327, 1329, 1366, 1369, 1369, 1376, 1416, 1425, 1469, 1471, 1471, 1473, 1474, 1476, 1477, 1479, 1479, 1488, 1514, 1519, 1522, 1552, 1562, 1568, 1641, 1646, 1747, 1749, 1756, 1759, 1768, 1770, 1788, 1791, 1791, 1808, 1866, 1869, 1969, 1984, 2037, 2042, 2042, 2045, 2045, 2048, 2093, 2112, 2139, 2144, 2154, 2208, 2228, 2230, 2237, 2259, 2273, 2275, 2403, 2406, 2415, 2417, 2435, 2437, 2444, 2447, 2448, 2451, 2472, 2474, 2480, 2482, 2482, 2486, 2489, 2492, 2500, 2503, 2504, 2507, 2510, 2519, 2519, 2524, 2525, 2527, 2531, 2534, 2545, 2556, 2556, 2558, 2558, 2561, 2563, 2565, 2570, 2575, 2576, 2579, 2600, 2602, 2608, 2610, 2611, 2613, 2614, 2616, 2617, 2620, 2620, 2622, 2626, 2631, 2632, 2635, 2637, 2641, 2641, 2649, 2652, 2654, 2654, 2662, 2677, 2689, 2691, 2693, 2701, 2703, 2705, 2707, 2728, 2730, 2736, 2738, 2739, 2741, 2745, 2748, 2757, 2759, 2761, 2763, 2765, 2768, 2768, 2784, 2787, 2790, 2799, 2809, 2815, 2817, 2819, 2821, 2828, 2831, 2832, 2835, 2856, 2858, 2864, 2866, 2867, 2869, 2873, 2876, 2884, 2887, 2888, 2891, 2893, 2902, 2903, 2908, 2909, 2911, 2915, 2918, 2927, 2929, 2929, 2946, 2947, 2949, 2954, 2958, 2960, 2962, 2965, 2969, 2970, 2972, 2972, 2974, 2975, 2979, 2980, 2984, 2986, 2990, 3001, 3006, 3010, 3014, 3016, 3018, 3021, 3024, 3024, 3031, 3031, 3046, 3055, 3072, 3084, 3086, 3088, 3090, 3112, 3114, 3129, 3133, 3140, 3142, 3144, 3146, 3149, 3157, 3158, 3160, 3162, 3168, 3171, 3174, 3183, 3200, 3203, 3205, 3212, 3214, 3216, 3218, 3240, 3242, 3251, 3253, 3257, 3260, 3268, 3270, 3272, 3274, 3277, 3285, 3286, 3294, 3294, 3296, 3299, 3302, 3311, 3313, 3314, 3328, 3331, 3333, 3340, 3342, 3344, 3346, 3396, 3398, 3400, 3402, 3406, 3412, 3415, 3423, 3427, 3430, 3439, 3450, 3455, 3458, 3459, 3461, 3478, 3482, 3505, 3507, 3515, 3517, 3517, 3520, 3526, 3530, 3530, 3535, 3540, 3542, 3542, 3544, 3551, 3558, 3567, 3570, 3571, 3585, 3642, 3648, 3662, 3664, 3673, 3713, 3714, 3716, 3716, 3718, 3722, 3724, 3747, 3749, 3749, 3751, 3773, 3776, 3780, 3782, 3782, 3784, 3789, 3792, 3801, 3804, 3807, 3840, 3840, 3864, 3865, 3872, 3881, 3893, 3893, 3895, 3895, 3897, 3897, 3902, 3911, 3913, 3948, 3953, 3972, 3974, 3991, 3993, 4028, 4038, 4038, 4096, 4169, 4176, 4253, 4256, 4293, 4295, 4295, 4301, 4301, 4304, 4346, 4348, 4680, 4682, 4685, 4688, 4694, 4696, 4696, 4698, 4701, 4704, 4744, 4746, 4749, 4752, 4784, 4786, 4789, 4792, 4798, 4800, 4800, 4802, 4805, 4808, 4822, 4824, 4880, 4882, 4885, 4888, 4954, 4957, 4959, 4969, 4977, 4992, 5007, 5024, 5109, 5112, 5117, 5121, 5740, 5743, 5759, 5761, 5786, 5792, 5866, 5870, 5880, 5888, 5900, 5902, 5908, 5920, 5940, 5952, 5971, 5984, 5996, 5998, 6000, 6002, 6003, 6016, 6099, 6103, 6103, 6108, 6109, 6112, 6121, 6155, 6157, 6160, 6169, 6176, 6264, 6272, 6314, 6320, 6389, 6400, 6430, 6432, 6443, 6448, 6459, 6470, 6509, 6512, 6516, 6528, 6571, 6576, 6601, 6608, 6618, 6656, 6683, 6688, 6750, 6752, 6780, 6783, 6793, 6800, 6809, 6823, 6823, 6832, 6845, 6912, 6987, 6992, 7001, 7019, 7027, 7040, 7155, 7168, 7223, 7232, 7241, 7245, 7293, 7296, 7304, 7312, 7354, 7357, 7359, 7376, 7378, 7380, 7418, 7424, 7673, 7675, 7957, 7960, 7965, 7968, 8005, 8008, 8013, 8016, 8023, 8025, 8025, 8027, 8027, 8029, 8029, 8031, 8061, 8064, 8116, 8118, 8124, 8126, 8126, 8130, 8132, 8134, 8140, 8144, 8147, 8150, 8155, 8160, 8172, 8178, 8180, 8182, 8188, 8255, 8256, 8276, 8276, 8305, 8305, 8319, 8319, 8336, 8348, 8400, 8412, 8417, 8417, 8421, 8432, 8450, 8450, 8455, 8455, 8458, 8467, 8469, 8469, 8472, 8477, 8484, 8484, 8486, 8486, 8488, 8488, 8490, 8505, 8508, 8511, 8517, 8521, 8526, 8526, 8544, 8584, 11264, 11310, 11312, 11358, 11360, 11492, 11499, 11507, 11520, 11557, 11559, 11559, 11565, 11565, 11568, 11623, 11631, 11631, 11647, 11670, 11680, 11686, 11688, 11694, 11696, 11702, 11704, 11710, 11712, 11718, 11720, 11726, 11728, 11734, 11736, 11742, 11744, 11775, 12293, 12295, 12321, 12335, 12337, 12341, 12344, 12348, 12353, 12438, 12441, 12447, 12449, 12538, 12540, 12543, 12549, 12591, 12593, 12686, 12704, 12730, 12784, 12799, 13312, 19893, 19968, 40943, 40960, 42124, 42192, 42237, 42240, 42508, 42512, 42539, 42560, 42607, 42612, 42621, 42623, 42737, 42775, 42783, 42786, 42888, 42891, 42943, 42946, 42950, 42999, 43047, 43072, 43123, 43136, 43205, 43216, 43225, 43232, 43255, 43259, 43259, 43261, 43309, 43312, 43347, 43360, 43388, 43392, 43456, 43471, 43481, 43488, 43518, 43520, 43574, 43584, 43597, 43600, 43609, 43616, 43638, 43642, 43714, 43739, 43741, 43744, 43759, 43762, 43766, 43777, 43782, 43785, 43790, 43793, 43798, 43808, 43814, 43816, 43822, 43824, 43866, 43868, 43879, 43888, 44010, 44012, 44013, 44016, 44025, 44032, 55203, 55216, 55238, 55243, 55291, 63744, 64109, 64112, 64217, 64256, 64262, 64275, 64279, 64285, 64296, 64298, 64310, 64312, 64316, 64318, 64318, 64320, 64321, 64323, 64324, 64326, 64433, 64467, 64829, 64848, 64911, 64914, 64967, 65008, 65019, 65024, 65039, 65056, 65071, 65075, 65076, 65101, 65103, 65136, 65140, 65142, 65276, 65296, 65305, 65313, 65338, 65343, 65343, 65345, 65370, 65382, 65470, 65474, 65479, 65482, 65487, 65490, 65495, 65498, 65500, 65536, 65547, 65549, 65574, 65576, 65594, 65596, 65597, 65599, 65613, 65616, 65629, 65664, 65786, 65856, 65908, 66045, 66045, 66176, 66204, 66208, 66256, 66272, 66272, 66304, 66335, 66349, 66378, 66384, 66426, 66432, 66461, 66464, 66499, 66504, 66511, 66513, 66517, 66560, 66717, 66720, 66729, 66736, 66771, 66776, 66811, 66816, 66855, 66864, 66915, 67072, 67382, 67392, 67413, 67424, 67431, 67584, 67589, 67592, 67592, 67594, 67637, 67639, 67640, 67644, 67644, 67647, 67669, 67680, 67702, 67712, 67742, 67808, 67826, 67828, 67829, 67840, 67861, 67872, 67897, 67968, 68023, 68030, 68031, 68096, 68099, 68101, 68102, 68108, 68115, 68117, 68119, 68121, 68149, 68152, 68154, 68159, 68159, 68192, 68220, 68224, 68252, 68288, 68295, 68297, 68326, 68352, 68405, 68416, 68437, 68448, 68466, 68480, 68497, 68608, 68680, 68736, 68786, 68800, 68850, 68864, 68903, 68912, 68921, 69376, 69404, 69415, 69415, 69424, 69456, 69600, 69622, 69632, 69702, 69734, 69743, 69759, 69818, 69840, 69864, 69872, 69881, 69888, 69940, 69942, 69951, 69956, 69958, 69968, 70003, 70006, 70006, 70016, 70084, 70089, 70092, 70096, 70106, 70108, 70108, 70144, 70161, 70163, 70199, 70206, 70206, 70272, 70278, 70280, 70280, 70282, 70285, 70287, 70301, 70303, 70312, 70320, 70378, 70384, 70393, 70400, 70403, 70405, 70412, 70415, 70416, 70419, 70440, 70442, 70448, 70450, 70451, 70453, 70457, 70459, 70468, 70471, 70472, 70475, 70477, 70480, 70480, 70487, 70487, 70493, 70499, 70502, 70508, 70512, 70516, 70656, 70730, 70736, 70745, 70750, 70751, 70784, 70853, 70855, 70855, 70864, 70873, 71040, 71093, 71096, 71104, 71128, 71133, 71168, 71232, 71236, 71236, 71248, 71257, 71296, 71352, 71360, 71369, 71424, 71450, 71453, 71467, 71472, 71481, 71680, 71738, 71840, 71913, 71935, 71935, 72096, 72103, 72106, 72151, 72154, 72161, 72163, 72164, 72192, 72254, 72263, 72263, 72272, 72345, 72349, 72349, 72384, 72440, 72704, 72712, 72714, 72758, 72760, 72768, 72784, 72793, 72818, 72847, 72850, 72871, 72873, 72886, 72960, 72966, 72968, 72969, 72971, 73014, 73018, 73018, 73020, 73021, 73023, 73031, 73040, 73049, 73056, 73061, 73063, 73064, 73066, 73102, 73104, 73105, 73107, 73112, 73120, 73129, 73440, 73462, 73728, 74649, 74752, 74862, 74880, 75075, 77824, 78894, 82944, 83526, 92160, 92728, 92736, 92766, 92768, 92777, 92880, 92909, 92912, 92916, 92928, 92982, 92992, 92995, 93008, 93017, 93027, 93047, 93053, 93071, 93760, 93823, 93952, 94026, 94031, 94087, 94095, 94111, 94176, 94177, 94179, 94179, 94208, 100343, 100352, 101106, 110592, 110878, 110928, 110930, 110948, 110951, 110960, 111355, 113664, 113770, 113776, 113788, 113792, 113800, 113808, 113817, 113821, 113822, 119141, 119145, 119149, 119154, 119163, 119170, 119173, 119179, 119210, 119213, 119362, 119364, 119808, 119892, 119894, 119964, 119966, 119967, 119970, 119970, 119973, 119974, 119977, 119980, 119982, 119993, 119995, 119995, 119997, 120003, 120005, 120069, 120071, 120074, 120077, 120084, 120086, 120092, 120094, 120121, 120123, 120126, 120128, 120132, 120134, 120134, 120138, 120144, 120146, 120485, 120488, 120512, 120514, 120538, 120540, 120570, 120572, 120596, 120598, 120628, 120630, 120654, 120656, 120686, 120688, 120712, 120714, 120744, 120746, 120770, 120772, 120779, 120782, 120831, 121344, 121398, 121403, 121452, 121461, 121461, 121476, 121476, 121499, 121503, 121505, 121519, 122880, 122886, 122888, 122904, 122907, 122913, 122915, 122916, 122918, 122922, 123136, 123180, 123184, 123197, 123200, 123209, 123214, 123214, 123584, 123641, 124928, 125124, 125136, 125142, 125184, 125259, 125264, 125273, 126464, 126467, 126469, 126495, 126497, 126498, 126500, 126500, 126503, 126503, 126505, 126514, 126516, 126519, 126521, 126521, 126523, 126523, 126530, 126530, 126535, 126535, 126537, 126537, 126539, 126539, 126541, 126543, 126545, 126546, 126548, 126548, 126551, 126551, 126553, 126553, 126555, 126555, 126557, 126557, 126559, 126559, 126561, 126562, 126564, 126564, 126567, 126570, 126572, 126578, 126580, 126583, 126585, 126588, 126590, 126590, 126592, 126601, 126603, 126619, 126625, 126627, 126629, 126633, 126635, 126651, 131072, 173782, 173824, 177972, 177984, 178205, 178208, 183969, 183984, 191456, 194560, 195101, 917760, 917999];
|
|
177
|
+
/**
|
|
178
|
+
* Test for whether a single line comment's text contains a directive.
|
|
179
|
+
*/
|
|
180
|
+
const commentDirectiveRegExSingleLine = /^\s*\/\/\/?\s*@(ts-expect-error|ts-ignore)/;
|
|
181
|
+
/**
|
|
182
|
+
* Test for whether a multi-line comment's last line contains a directive.
|
|
183
|
+
*/
|
|
184
|
+
const commentDirectiveRegExMultiLine = /^\s*(?:\/|\*)*\s*@(ts-expect-error|ts-ignore)/;
|
|
185
|
+
function lookupInUnicodeMap(code, map) {
|
|
186
|
+
// Bail out quickly if it couldn't possibly be in the map.
|
|
187
|
+
if (code < map[0]) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
// Perform binary search in one of the Unicode range maps
|
|
191
|
+
let lo = 0;
|
|
192
|
+
let hi = map.length;
|
|
193
|
+
let mid;
|
|
194
|
+
while (lo + 1 < hi) {
|
|
195
|
+
mid = lo + (hi - lo) / 2;
|
|
196
|
+
// mid has to be even to catch a range's beginning
|
|
197
|
+
mid -= mid % 2;
|
|
198
|
+
if (map[mid] <= code && code <= map[mid + 1]) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
if (code < map[mid]) {
|
|
202
|
+
hi = mid;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
lo = mid + 2;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
export function isUnicodeIdentifierStart(code, languageVersion) {
|
|
211
|
+
return languageVersion >= 2 /* ScriptTarget.ES2015 */ ?
|
|
212
|
+
lookupInUnicodeMap(code, unicodeESNextIdentifierStart) :
|
|
213
|
+
languageVersion === 1 /* ScriptTarget.ES5 */ ? lookupInUnicodeMap(code, unicodeES5IdentifierStart) :
|
|
214
|
+
lookupInUnicodeMap(code, unicodeES3IdentifierStart);
|
|
215
|
+
}
|
|
216
|
+
function isUnicodeIdentifierPart(code, languageVersion) {
|
|
217
|
+
return languageVersion >= 2 /* ScriptTarget.ES2015 */ ?
|
|
218
|
+
lookupInUnicodeMap(code, unicodeESNextIdentifierPart) :
|
|
219
|
+
languageVersion === 1 /* ScriptTarget.ES5 */ ? lookupInUnicodeMap(code, unicodeES5IdentifierPart) :
|
|
220
|
+
lookupInUnicodeMap(code, unicodeES3IdentifierPart);
|
|
221
|
+
}
|
|
222
|
+
function makeReverseMap(source) {
|
|
223
|
+
const result = [];
|
|
224
|
+
source.forEach((value, name) => {
|
|
225
|
+
result[value] = name;
|
|
226
|
+
});
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
const tokenStrings = makeReverseMap(textToToken);
|
|
230
|
+
export function tokenToString(t) {
|
|
231
|
+
return tokenStrings[t];
|
|
232
|
+
}
|
|
233
|
+
export function stringToToken(s) {
|
|
234
|
+
return textToToken.get(s);
|
|
235
|
+
}
|
|
236
|
+
export function computeLineStarts(text) {
|
|
237
|
+
const result = new Array();
|
|
238
|
+
let pos = 0;
|
|
239
|
+
let lineStart = 0;
|
|
240
|
+
while (pos < text.length) {
|
|
241
|
+
const ch = text.charCodeAt(pos);
|
|
242
|
+
pos++;
|
|
243
|
+
switch (ch) {
|
|
244
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
245
|
+
if (text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) {
|
|
246
|
+
pos++;
|
|
247
|
+
}
|
|
248
|
+
// falls through
|
|
249
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
250
|
+
result.push(lineStart);
|
|
251
|
+
lineStart = pos;
|
|
252
|
+
break;
|
|
253
|
+
default:
|
|
254
|
+
if (ch > 127 /* CharacterCodes.maxAsciiCharacter */ && isLineBreak(ch)) {
|
|
255
|
+
result.push(lineStart);
|
|
256
|
+
lineStart = pos;
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
result.push(lineStart);
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
export function getPositionOfLineAndCharacter(sourceFile, line, character, allowEdits) {
|
|
265
|
+
return sourceFile.getPositionOfLineAndCharacter ?
|
|
266
|
+
sourceFile.getPositionOfLineAndCharacter(line, character, allowEdits) :
|
|
267
|
+
computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character, sourceFile.text, allowEdits);
|
|
268
|
+
}
|
|
269
|
+
export function computePositionOfLineAndCharacter(lineStarts, line, character, debugText, allowEdits) {
|
|
270
|
+
if (line < 0 || line >= lineStarts.length) {
|
|
271
|
+
if (allowEdits) {
|
|
272
|
+
// Clamp line to nearest allowable value
|
|
273
|
+
line = line < 0 ? 0 : line >= lineStarts.length ? lineStarts.length - 1 : line;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
Debug.fail(`Bad line number. Line: ${line}, lineStarts.length: ${lineStarts.length} , line map is correct? ${debugText !== undefined ? arraysEqual(lineStarts, computeLineStarts(debugText)) : "unknown"}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const res = lineStarts[line] + character;
|
|
280
|
+
if (allowEdits) {
|
|
281
|
+
// Clamp to nearest allowable values to allow the underlying to be edited without crashing (accuracy is lost, instead)
|
|
282
|
+
return res > lineStarts[line + 1] ? lineStarts[line + 1] : typeof debugText === "string" && res > debugText.length ? debugText.length : res;
|
|
283
|
+
}
|
|
284
|
+
if (line < lineStarts.length - 1) {
|
|
285
|
+
Debug.assert(res < lineStarts[line + 1]);
|
|
286
|
+
}
|
|
287
|
+
else if (debugText !== undefined) {
|
|
288
|
+
Debug.assert(res <= debugText.length); // Allow single character overflow for trailing newline
|
|
289
|
+
}
|
|
290
|
+
return res;
|
|
291
|
+
}
|
|
292
|
+
export function getLineStarts(sourceFile) {
|
|
293
|
+
return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text));
|
|
294
|
+
}
|
|
295
|
+
export function computeLineAndCharacterOfPosition(lineStarts, position) {
|
|
296
|
+
const lineNumber = computeLineOfPosition(lineStarts, position);
|
|
297
|
+
return {
|
|
298
|
+
line: lineNumber,
|
|
299
|
+
character: position - lineStarts[lineNumber]
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* We assume the first line starts at position 0 and 'position' is non-negative.
|
|
304
|
+
*/
|
|
305
|
+
export function computeLineOfPosition(lineStarts, position, lowerBound) {
|
|
306
|
+
let lineNumber = binarySearch(lineStarts, position, identity, compareValues, lowerBound);
|
|
307
|
+
if (lineNumber < 0) {
|
|
308
|
+
// If the actual position was not found,
|
|
309
|
+
// the binary search returns the 2's-complement of the next line start
|
|
310
|
+
// e.g. if the line starts at [5, 10, 23, 80] and the position requested was 20
|
|
311
|
+
// then the search will return -2.
|
|
312
|
+
//
|
|
313
|
+
// We want the index of the previous line start, so we subtract 1.
|
|
314
|
+
// Review 2's-complement if this is confusing.
|
|
315
|
+
lineNumber = ~lineNumber - 1;
|
|
316
|
+
Debug.assert(lineNumber !== -1, "position cannot precede the beginning of the file");
|
|
317
|
+
}
|
|
318
|
+
return lineNumber;
|
|
319
|
+
}
|
|
320
|
+
export function getLinesBetweenPositions(sourceFile, pos1, pos2) {
|
|
321
|
+
if (pos1 === pos2)
|
|
322
|
+
return 0;
|
|
323
|
+
const lineStarts = getLineStarts(sourceFile);
|
|
324
|
+
const lower = Math.min(pos1, pos2);
|
|
325
|
+
const isNegative = lower === pos2;
|
|
326
|
+
const upper = isNegative ? pos1 : pos2;
|
|
327
|
+
const lowerLine = computeLineOfPosition(lineStarts, lower);
|
|
328
|
+
const upperLine = computeLineOfPosition(lineStarts, upper, lowerLine);
|
|
329
|
+
return isNegative ? lowerLine - upperLine : upperLine - lowerLine;
|
|
330
|
+
}
|
|
331
|
+
export function getLineAndCharacterOfPosition(sourceFile, position) {
|
|
332
|
+
return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
|
|
333
|
+
}
|
|
334
|
+
export function isWhiteSpaceLike(ch) {
|
|
335
|
+
return isWhiteSpaceSingleLine(ch) || isLineBreak(ch);
|
|
336
|
+
}
|
|
337
|
+
/** Does not include line breaks. For that, see isWhiteSpaceLike. */
|
|
338
|
+
export function isWhiteSpaceSingleLine(ch) {
|
|
339
|
+
// Note: nextLine is in the Zs space, and should be considered to be a whitespace.
|
|
340
|
+
// It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript.
|
|
341
|
+
return ch === 32 /* CharacterCodes.space */ ||
|
|
342
|
+
ch === 9 /* CharacterCodes.tab */ ||
|
|
343
|
+
ch === 11 /* CharacterCodes.verticalTab */ ||
|
|
344
|
+
ch === 12 /* CharacterCodes.formFeed */ ||
|
|
345
|
+
ch === 160 /* CharacterCodes.nonBreakingSpace */ ||
|
|
346
|
+
ch === 133 /* CharacterCodes.nextLine */ ||
|
|
347
|
+
ch === 5760 /* CharacterCodes.ogham */ ||
|
|
348
|
+
ch >= 8192 /* CharacterCodes.enQuad */ && ch <= 8203 /* CharacterCodes.zeroWidthSpace */ ||
|
|
349
|
+
ch === 8239 /* CharacterCodes.narrowNoBreakSpace */ ||
|
|
350
|
+
ch === 8287 /* CharacterCodes.mathematicalSpace */ ||
|
|
351
|
+
ch === 12288 /* CharacterCodes.ideographicSpace */ ||
|
|
352
|
+
ch === 65279 /* CharacterCodes.byteOrderMark */;
|
|
353
|
+
}
|
|
354
|
+
export function isLineBreak(ch) {
|
|
355
|
+
// ES5 7.3:
|
|
356
|
+
// The ECMAScript line terminator characters are listed in Table 3.
|
|
357
|
+
// Table 3: Line Terminator Characters
|
|
358
|
+
// Code Unit Value Name Formal Name
|
|
359
|
+
// \u000A Line Feed <LF>
|
|
360
|
+
// \u000D Carriage Return <CR>
|
|
361
|
+
// \u2028 Line separator <LS>
|
|
362
|
+
// \u2029 Paragraph separator <PS>
|
|
363
|
+
// Only the characters in Table 3 are treated as line terminators. Other new line or line
|
|
364
|
+
// breaking characters are treated as white space but not as line terminators.
|
|
365
|
+
return ch === 10 /* CharacterCodes.lineFeed */ ||
|
|
366
|
+
ch === 13 /* CharacterCodes.carriageReturn */ ||
|
|
367
|
+
ch === 8232 /* CharacterCodes.lineSeparator */ ||
|
|
368
|
+
ch === 8233 /* CharacterCodes.paragraphSeparator */;
|
|
369
|
+
}
|
|
370
|
+
function isDigit(ch) {
|
|
371
|
+
return ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */;
|
|
372
|
+
}
|
|
373
|
+
export function isOctalDigit(ch) {
|
|
374
|
+
return ch >= 48 /* CharacterCodes._0 */ && ch <= 55 /* CharacterCodes._7 */;
|
|
375
|
+
}
|
|
376
|
+
export function couldStartTrivia(text, pos) {
|
|
377
|
+
// Keep in sync with skipTrivia
|
|
378
|
+
const ch = text.charCodeAt(pos);
|
|
379
|
+
switch (ch) {
|
|
380
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
381
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
382
|
+
case 9 /* CharacterCodes.tab */:
|
|
383
|
+
case 11 /* CharacterCodes.verticalTab */:
|
|
384
|
+
case 12 /* CharacterCodes.formFeed */:
|
|
385
|
+
case 32 /* CharacterCodes.space */:
|
|
386
|
+
case 47 /* CharacterCodes.slash */:
|
|
387
|
+
// starts of normal trivia
|
|
388
|
+
// falls through
|
|
389
|
+
case 60 /* CharacterCodes.lessThan */:
|
|
390
|
+
case 124 /* CharacterCodes.bar */:
|
|
391
|
+
case 61 /* CharacterCodes.equals */:
|
|
392
|
+
case 62 /* CharacterCodes.greaterThan */:
|
|
393
|
+
// Starts of conflict marker trivia
|
|
394
|
+
return true;
|
|
395
|
+
case 35 /* CharacterCodes.hash */:
|
|
396
|
+
// Only if its the beginning can we have #! trivia
|
|
397
|
+
return pos === 0;
|
|
398
|
+
default:
|
|
399
|
+
return ch > 127 /* CharacterCodes.maxAsciiCharacter */;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
export function skipTrivia(text, pos, stopAfterLineBreak, stopAtComments = false) {
|
|
403
|
+
if (positionIsSynthesized(pos)) {
|
|
404
|
+
return pos;
|
|
405
|
+
}
|
|
406
|
+
// Keep in sync with couldStartTrivia
|
|
407
|
+
while (true) {
|
|
408
|
+
const ch = text.charCodeAt(pos);
|
|
409
|
+
switch (ch) {
|
|
410
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
411
|
+
if (text.charCodeAt(pos + 1) === 10 /* CharacterCodes.lineFeed */) {
|
|
412
|
+
pos++;
|
|
413
|
+
}
|
|
414
|
+
// falls through
|
|
415
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
416
|
+
pos++;
|
|
417
|
+
if (stopAfterLineBreak) {
|
|
418
|
+
return pos;
|
|
419
|
+
}
|
|
420
|
+
continue;
|
|
421
|
+
case 9 /* CharacterCodes.tab */:
|
|
422
|
+
case 11 /* CharacterCodes.verticalTab */:
|
|
423
|
+
case 12 /* CharacterCodes.formFeed */:
|
|
424
|
+
case 32 /* CharacterCodes.space */:
|
|
425
|
+
pos++;
|
|
426
|
+
continue;
|
|
427
|
+
case 47 /* CharacterCodes.slash */:
|
|
428
|
+
if (stopAtComments) {
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
if (text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
|
|
432
|
+
pos += 2;
|
|
433
|
+
while (pos < text.length) {
|
|
434
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
pos++;
|
|
438
|
+
}
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (text.charCodeAt(pos + 1) === 42 /* CharacterCodes.asterisk */) {
|
|
442
|
+
pos += 2;
|
|
443
|
+
while (pos < text.length) {
|
|
444
|
+
if (text.charCodeAt(pos) === 42 /* CharacterCodes.asterisk */ && text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
|
|
445
|
+
pos += 2;
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
pos++;
|
|
449
|
+
}
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
break;
|
|
453
|
+
case 60 /* CharacterCodes.lessThan */:
|
|
454
|
+
case 124 /* CharacterCodes.bar */:
|
|
455
|
+
case 61 /* CharacterCodes.equals */:
|
|
456
|
+
case 62 /* CharacterCodes.greaterThan */:
|
|
457
|
+
if (isConflictMarkerTrivia(text, pos)) {
|
|
458
|
+
pos = scanConflictMarkerTrivia(text, pos);
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
break;
|
|
462
|
+
case 35 /* CharacterCodes.hash */:
|
|
463
|
+
if (pos === 0 && isShebangTrivia(text, pos)) {
|
|
464
|
+
pos = scanShebangTrivia(text, pos);
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
468
|
+
default:
|
|
469
|
+
if (ch > 127 /* CharacterCodes.maxAsciiCharacter */ && (isWhiteSpaceLike(ch))) {
|
|
470
|
+
pos++;
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
return pos;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
// All conflict markers consist of the same character repeated seven times. If it is
|
|
479
|
+
// a <<<<<<< or >>>>>>> marker then it is also followed by a space.
|
|
480
|
+
const mergeConflictMarkerLength = "<<<<<<<".length;
|
|
481
|
+
function isConflictMarkerTrivia(text, pos) {
|
|
482
|
+
Debug.assert(pos >= 0);
|
|
483
|
+
// Conflict markers must be at the start of a line.
|
|
484
|
+
if (pos === 0 || isLineBreak(text.charCodeAt(pos - 1))) {
|
|
485
|
+
const ch = text.charCodeAt(pos);
|
|
486
|
+
if ((pos + mergeConflictMarkerLength) < text.length) {
|
|
487
|
+
for (let i = 0; i < mergeConflictMarkerLength; i++) {
|
|
488
|
+
if (text.charCodeAt(pos + i) !== ch) {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return ch === 61 /* CharacterCodes.equals */ ||
|
|
493
|
+
text.charCodeAt(pos + mergeConflictMarkerLength) === 32 /* CharacterCodes.space */;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
function scanConflictMarkerTrivia(text, pos, error) {
|
|
499
|
+
if (error) {
|
|
500
|
+
error(Diagnostics.Merge_conflict_marker_encountered, pos, mergeConflictMarkerLength);
|
|
501
|
+
}
|
|
502
|
+
const ch = text.charCodeAt(pos);
|
|
503
|
+
const len = text.length;
|
|
504
|
+
if (ch === 60 /* CharacterCodes.lessThan */ || ch === 62 /* CharacterCodes.greaterThan */) {
|
|
505
|
+
while (pos < len && !isLineBreak(text.charCodeAt(pos))) {
|
|
506
|
+
pos++;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
Debug.assert(ch === 124 /* CharacterCodes.bar */ || ch === 61 /* CharacterCodes.equals */);
|
|
511
|
+
// Consume everything from the start of a ||||||| or ======= marker to the start
|
|
512
|
+
// of the next ======= or >>>>>>> marker.
|
|
513
|
+
while (pos < len) {
|
|
514
|
+
const currentChar = text.charCodeAt(pos);
|
|
515
|
+
if ((currentChar === 61 /* CharacterCodes.equals */ || currentChar === 62 /* CharacterCodes.greaterThan */) && currentChar !== ch && isConflictMarkerTrivia(text, pos)) {
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
pos++;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return pos;
|
|
522
|
+
}
|
|
523
|
+
const shebangTriviaRegex = /^#!.*/;
|
|
524
|
+
export function isShebangTrivia(text, pos) {
|
|
525
|
+
// Shebangs check must only be done at the start of the file
|
|
526
|
+
Debug.assert(pos === 0);
|
|
527
|
+
return shebangTriviaRegex.test(text);
|
|
528
|
+
}
|
|
529
|
+
export function scanShebangTrivia(text, pos) {
|
|
530
|
+
const shebang = shebangTriviaRegex.exec(text)[0];
|
|
531
|
+
pos = pos + shebang.length;
|
|
532
|
+
return pos;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Invokes a callback for each comment range following the provided position.
|
|
536
|
+
*
|
|
537
|
+
* Single-line comment ranges include the leading double-slash characters but not the ending
|
|
538
|
+
* line break. Multi-line comment ranges include the leading slash-asterisk and trailing
|
|
539
|
+
* asterisk-slash characters.
|
|
540
|
+
*
|
|
541
|
+
* @param reduce If true, accumulates the result of calling the callback in a fashion similar
|
|
542
|
+
* to reduceLeft. If false, iteration stops when the callback returns a truthy value.
|
|
543
|
+
* @param text The source text to scan.
|
|
544
|
+
* @param pos The position at which to start scanning.
|
|
545
|
+
* @param trailing If false, whitespace is skipped until the first line break and comments
|
|
546
|
+
* between that location and the next token are returned. If true, comments occurring
|
|
547
|
+
* between the given position and the next line break are returned.
|
|
548
|
+
* @param cb The callback to execute as each comment range is encountered.
|
|
549
|
+
* @param state A state value to pass to each iteration of the callback.
|
|
550
|
+
* @param initial An initial value to pass when accumulating results (when "reduce" is true).
|
|
551
|
+
* @returns If "reduce" is true, the accumulated value. If "reduce" is false, the first truthy
|
|
552
|
+
* return value of the callback.
|
|
553
|
+
*/
|
|
554
|
+
function iterateCommentRanges(reduce, text, pos, trailing, cb, state, initial) {
|
|
555
|
+
let pendingPos;
|
|
556
|
+
let pendingEnd;
|
|
557
|
+
let pendingKind;
|
|
558
|
+
let pendingHasTrailingNewLine;
|
|
559
|
+
let hasPendingCommentRange = false;
|
|
560
|
+
let collecting = trailing;
|
|
561
|
+
let accumulator = initial;
|
|
562
|
+
if (pos === 0) {
|
|
563
|
+
collecting = true;
|
|
564
|
+
const shebang = getShebang(text);
|
|
565
|
+
if (shebang) {
|
|
566
|
+
pos = shebang.length;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
scan: while (pos >= 0 && pos < text.length) {
|
|
570
|
+
const ch = text.charCodeAt(pos);
|
|
571
|
+
switch (ch) {
|
|
572
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
573
|
+
if (text.charCodeAt(pos + 1) === 10 /* CharacterCodes.lineFeed */) {
|
|
574
|
+
pos++;
|
|
575
|
+
}
|
|
576
|
+
// falls through
|
|
577
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
578
|
+
pos++;
|
|
579
|
+
if (trailing) {
|
|
580
|
+
break scan;
|
|
581
|
+
}
|
|
582
|
+
collecting = true;
|
|
583
|
+
if (hasPendingCommentRange) {
|
|
584
|
+
pendingHasTrailingNewLine = true;
|
|
585
|
+
}
|
|
586
|
+
continue;
|
|
587
|
+
case 9 /* CharacterCodes.tab */:
|
|
588
|
+
case 11 /* CharacterCodes.verticalTab */:
|
|
589
|
+
case 12 /* CharacterCodes.formFeed */:
|
|
590
|
+
case 32 /* CharacterCodes.space */:
|
|
591
|
+
pos++;
|
|
592
|
+
continue;
|
|
593
|
+
case 47 /* CharacterCodes.slash */:
|
|
594
|
+
const nextChar = text.charCodeAt(pos + 1);
|
|
595
|
+
let hasTrailingNewLine = false;
|
|
596
|
+
if (nextChar === 47 /* CharacterCodes.slash */ || nextChar === 42 /* CharacterCodes.asterisk */) {
|
|
597
|
+
const kind = nextChar === 47 /* CharacterCodes.slash */ ? 2 /* SyntaxKind.SingleLineCommentTrivia */ : 3 /* SyntaxKind.MultiLineCommentTrivia */;
|
|
598
|
+
const startPos = pos;
|
|
599
|
+
pos += 2;
|
|
600
|
+
if (nextChar === 47 /* CharacterCodes.slash */) {
|
|
601
|
+
while (pos < text.length) {
|
|
602
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
603
|
+
hasTrailingNewLine = true;
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
pos++;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
while (pos < text.length) {
|
|
611
|
+
if (text.charCodeAt(pos) === 42 /* CharacterCodes.asterisk */ && text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
|
|
612
|
+
pos += 2;
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
pos++;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (collecting) {
|
|
619
|
+
if (hasPendingCommentRange) {
|
|
620
|
+
accumulator = cb(pendingPos, pendingEnd, pendingKind, pendingHasTrailingNewLine, state, accumulator);
|
|
621
|
+
if (!reduce && accumulator) {
|
|
622
|
+
// If we are not reducing and we have a truthy result, return it.
|
|
623
|
+
return accumulator;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
pendingPos = startPos;
|
|
627
|
+
pendingEnd = pos;
|
|
628
|
+
pendingKind = kind;
|
|
629
|
+
pendingHasTrailingNewLine = hasTrailingNewLine;
|
|
630
|
+
hasPendingCommentRange = true;
|
|
631
|
+
}
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
break scan;
|
|
635
|
+
default:
|
|
636
|
+
if (ch > 127 /* CharacterCodes.maxAsciiCharacter */ && (isWhiteSpaceLike(ch))) {
|
|
637
|
+
if (hasPendingCommentRange && isLineBreak(ch)) {
|
|
638
|
+
pendingHasTrailingNewLine = true;
|
|
639
|
+
}
|
|
640
|
+
pos++;
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
break scan;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
if (hasPendingCommentRange) {
|
|
647
|
+
accumulator = cb(pendingPos, pendingEnd, pendingKind, pendingHasTrailingNewLine, state, accumulator);
|
|
648
|
+
}
|
|
649
|
+
return accumulator;
|
|
650
|
+
}
|
|
651
|
+
export function forEachLeadingCommentRange(text, pos, cb, state) {
|
|
652
|
+
return iterateCommentRanges(/*reduce*/ false, text, pos, /*trailing*/ false, cb, state);
|
|
653
|
+
}
|
|
654
|
+
export function forEachTrailingCommentRange(text, pos, cb, state) {
|
|
655
|
+
return iterateCommentRanges(/*reduce*/ false, text, pos, /*trailing*/ true, cb, state);
|
|
656
|
+
}
|
|
657
|
+
export function reduceEachLeadingCommentRange(text, pos, cb, state, initial) {
|
|
658
|
+
return iterateCommentRanges(/*reduce*/ true, text, pos, /*trailing*/ false, cb, state, initial);
|
|
659
|
+
}
|
|
660
|
+
export function reduceEachTrailingCommentRange(text, pos, cb, state, initial) {
|
|
661
|
+
return iterateCommentRanges(/*reduce*/ true, text, pos, /*trailing*/ true, cb, state, initial);
|
|
662
|
+
}
|
|
663
|
+
function appendCommentRange(pos, end, kind, hasTrailingNewLine, _state, comments) {
|
|
664
|
+
if (!comments) {
|
|
665
|
+
comments = [];
|
|
666
|
+
}
|
|
667
|
+
comments.push({ kind, pos, end, hasTrailingNewLine });
|
|
668
|
+
return comments;
|
|
669
|
+
}
|
|
670
|
+
export function getLeadingCommentRanges(text, pos) {
|
|
671
|
+
return reduceEachLeadingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined);
|
|
672
|
+
}
|
|
673
|
+
export function getTrailingCommentRanges(text, pos) {
|
|
674
|
+
return reduceEachTrailingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined);
|
|
675
|
+
}
|
|
676
|
+
/** Optionally, get the shebang */
|
|
677
|
+
export function getShebang(text) {
|
|
678
|
+
const match = shebangTriviaRegex.exec(text);
|
|
679
|
+
if (match) {
|
|
680
|
+
return match[0];
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
export function isIdentifierStart(ch, languageVersion) {
|
|
684
|
+
return ch >= 65 /* CharacterCodes.A */ && ch <= 90 /* CharacterCodes.Z */ || ch >= 97 /* CharacterCodes.a */ && ch <= 122 /* CharacterCodes.z */ ||
|
|
685
|
+
ch === 36 /* CharacterCodes.$ */ || ch === 95 /* CharacterCodes._ */ ||
|
|
686
|
+
ch > 127 /* CharacterCodes.maxAsciiCharacter */ && isUnicodeIdentifierStart(ch, languageVersion);
|
|
687
|
+
}
|
|
688
|
+
export function isIdentifierPart(ch, languageVersion, identifierVariant) {
|
|
689
|
+
return ch >= 65 /* CharacterCodes.A */ && ch <= 90 /* CharacterCodes.Z */ || ch >= 97 /* CharacterCodes.a */ && ch <= 122 /* CharacterCodes.z */ ||
|
|
690
|
+
ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */ || ch === 36 /* CharacterCodes.$ */ || ch === 95 /* CharacterCodes._ */ ||
|
|
691
|
+
// "-" and ":" are valid in JSX Identifiers
|
|
692
|
+
(identifierVariant === 1 /* LanguageVariant.JSX */ ? (ch === 45 /* CharacterCodes.minus */ || ch === 58 /* CharacterCodes.colon */) : false) ||
|
|
693
|
+
ch > 127 /* CharacterCodes.maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion);
|
|
694
|
+
}
|
|
695
|
+
export function isIdentifierText(name, languageVersion, identifierVariant) {
|
|
696
|
+
let ch = codePointAt(name, 0);
|
|
697
|
+
if (!isIdentifierStart(ch, languageVersion)) {
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
for (let i = charSize(ch); i < name.length; i += charSize(ch)) {
|
|
701
|
+
if (!isIdentifierPart(ch = codePointAt(name, i), languageVersion, identifierVariant)) {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return true;
|
|
706
|
+
}
|
|
707
|
+
// Creates a scanner over a (possibly unspecified) range of a piece of text.
|
|
708
|
+
export function createScanner(languageVersion, skipTrivia, languageVariant = 0 /* LanguageVariant.Standard */, textInitial, onError, start, length) {
|
|
709
|
+
let text = textInitial;
|
|
710
|
+
// Current position (end position of text of current token)
|
|
711
|
+
let pos;
|
|
712
|
+
// end of text
|
|
713
|
+
let end;
|
|
714
|
+
// Start position of whitespace before current token
|
|
715
|
+
let startPos;
|
|
716
|
+
// Start position of text of current token
|
|
717
|
+
let tokenPos;
|
|
718
|
+
let token;
|
|
719
|
+
let tokenValue;
|
|
720
|
+
let tokenFlags;
|
|
721
|
+
let commentDirectives;
|
|
722
|
+
setText(text, start, length);
|
|
723
|
+
const scanner = {
|
|
724
|
+
getStartPos: () => startPos,
|
|
725
|
+
getTextPos: () => pos,
|
|
726
|
+
getToken: () => token,
|
|
727
|
+
getTokenPos: () => tokenPos,
|
|
728
|
+
getTokenText: () => text.substring(tokenPos, pos),
|
|
729
|
+
getTokenValue: () => tokenValue,
|
|
730
|
+
hasUnicodeEscape: () => (tokenFlags & 1024 /* TokenFlags.UnicodeEscape */) !== 0,
|
|
731
|
+
hasExtendedUnicodeEscape: () => (tokenFlags & 8 /* TokenFlags.ExtendedUnicodeEscape */) !== 0,
|
|
732
|
+
hasPrecedingLineBreak: () => (tokenFlags & 1 /* TokenFlags.PrecedingLineBreak */) !== 0,
|
|
733
|
+
isIdentifier: () => token === 75 /* SyntaxKind.Identifier */ || token > 112 /* SyntaxKind.LastReservedWord */,
|
|
734
|
+
isReservedWord: () => token >= 77 /* SyntaxKind.FirstReservedWord */ && token <= 112 /* SyntaxKind.LastReservedWord */,
|
|
735
|
+
isUnterminated: () => (tokenFlags & 4 /* TokenFlags.Unterminated */) !== 0,
|
|
736
|
+
getCommentDirectives: () => commentDirectives,
|
|
737
|
+
getTokenFlags: () => tokenFlags,
|
|
738
|
+
reScanGreaterToken,
|
|
739
|
+
reScanTemplateToken,
|
|
740
|
+
scanJsxIdentifier,
|
|
741
|
+
scanJsxAttributeValue,
|
|
742
|
+
reScanJsxAttributeValue,
|
|
743
|
+
reScanJsxToken,
|
|
744
|
+
reScanLessThanToken,
|
|
745
|
+
reScanQuestionToken,
|
|
746
|
+
scanJsxToken,
|
|
747
|
+
scan,
|
|
748
|
+
getText,
|
|
749
|
+
clearCommentDirectives,
|
|
750
|
+
setText,
|
|
751
|
+
setScriptTarget,
|
|
752
|
+
setLanguageVariant,
|
|
753
|
+
setOnError,
|
|
754
|
+
setTextPos,
|
|
755
|
+
tryScan,
|
|
756
|
+
lookAhead,
|
|
757
|
+
scanRange,
|
|
758
|
+
};
|
|
759
|
+
if (Debug.isDebugging) {
|
|
760
|
+
Object.defineProperty(scanner, "__debugShowCurrentPositionInText", {
|
|
761
|
+
get: () => {
|
|
762
|
+
const text = scanner.getText();
|
|
763
|
+
return text.slice(0, scanner.getStartPos()) + "║" + text.slice(scanner.getStartPos());
|
|
764
|
+
},
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
return scanner;
|
|
768
|
+
function error(message, errPos = pos, length) {
|
|
769
|
+
if (onError) {
|
|
770
|
+
const oldPos = pos;
|
|
771
|
+
pos = errPos;
|
|
772
|
+
onError(message, length || 0);
|
|
773
|
+
pos = oldPos;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
function scanNumberFragment() {
|
|
777
|
+
let start = pos;
|
|
778
|
+
let allowSeparator = false;
|
|
779
|
+
let isPreviousTokenSeparator = false;
|
|
780
|
+
let result = "";
|
|
781
|
+
while (true) {
|
|
782
|
+
const ch = text.charCodeAt(pos);
|
|
783
|
+
if (ch === 95 /* CharacterCodes._ */) {
|
|
784
|
+
tokenFlags |= 512 /* TokenFlags.ContainsSeparator */;
|
|
785
|
+
if (allowSeparator) {
|
|
786
|
+
allowSeparator = false;
|
|
787
|
+
isPreviousTokenSeparator = true;
|
|
788
|
+
result += text.substring(start, pos);
|
|
789
|
+
}
|
|
790
|
+
else if (isPreviousTokenSeparator) {
|
|
791
|
+
error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
|
|
795
|
+
}
|
|
796
|
+
pos++;
|
|
797
|
+
start = pos;
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
if (isDigit(ch)) {
|
|
801
|
+
allowSeparator = true;
|
|
802
|
+
isPreviousTokenSeparator = false;
|
|
803
|
+
pos++;
|
|
804
|
+
continue;
|
|
805
|
+
}
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
if (text.charCodeAt(pos - 1) === 95 /* CharacterCodes._ */) {
|
|
809
|
+
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos - 1, 1);
|
|
810
|
+
}
|
|
811
|
+
return result + text.substring(start, pos);
|
|
812
|
+
}
|
|
813
|
+
function scanNumber() {
|
|
814
|
+
const start = pos;
|
|
815
|
+
const mainFragment = scanNumberFragment();
|
|
816
|
+
let decimalFragment;
|
|
817
|
+
let scientificFragment;
|
|
818
|
+
if (text.charCodeAt(pos) === 46 /* CharacterCodes.dot */) {
|
|
819
|
+
pos++;
|
|
820
|
+
decimalFragment = scanNumberFragment();
|
|
821
|
+
}
|
|
822
|
+
let end = pos;
|
|
823
|
+
if (text.charCodeAt(pos) === 69 /* CharacterCodes.E */ || text.charCodeAt(pos) === 101 /* CharacterCodes.e */) {
|
|
824
|
+
pos++;
|
|
825
|
+
tokenFlags |= 16 /* TokenFlags.Scientific */;
|
|
826
|
+
if (text.charCodeAt(pos) === 43 /* CharacterCodes.plus */ || text.charCodeAt(pos) === 45 /* CharacterCodes.minus */)
|
|
827
|
+
pos++;
|
|
828
|
+
const preNumericPart = pos;
|
|
829
|
+
const finalFragment = scanNumberFragment();
|
|
830
|
+
if (!finalFragment) {
|
|
831
|
+
error(Diagnostics.Digit_expected);
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
scientificFragment = text.substring(end, preNumericPart) + finalFragment;
|
|
835
|
+
end = pos;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
let result;
|
|
839
|
+
if (tokenFlags & 512 /* TokenFlags.ContainsSeparator */) {
|
|
840
|
+
result = mainFragment;
|
|
841
|
+
if (decimalFragment) {
|
|
842
|
+
result += "." + decimalFragment;
|
|
843
|
+
}
|
|
844
|
+
if (scientificFragment) {
|
|
845
|
+
result += scientificFragment;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
else {
|
|
849
|
+
result = text.substring(start, end); // No need to use all the fragments; no _ removal needed
|
|
850
|
+
}
|
|
851
|
+
if (decimalFragment !== undefined || tokenFlags & 16 /* TokenFlags.Scientific */) {
|
|
852
|
+
checkForIdentifierStartAfterNumericLiteral(start, decimalFragment === undefined && !!(tokenFlags & 16 /* TokenFlags.Scientific */));
|
|
853
|
+
return {
|
|
854
|
+
type: 8 /* SyntaxKind.NumericLiteral */,
|
|
855
|
+
value: "" + +result // if value is not an integer, it can be safely coerced to a number
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
tokenValue = result;
|
|
860
|
+
const type = checkBigIntSuffix(); // if value is an integer, check whether it is a bigint
|
|
861
|
+
checkForIdentifierStartAfterNumericLiteral(start);
|
|
862
|
+
return { type, value: tokenValue };
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
function checkForIdentifierStartAfterNumericLiteral(numericStart, isScientific) {
|
|
866
|
+
if (!isIdentifierStart(codePointAt(text, pos), languageVersion)) {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
const identifierStart = pos;
|
|
870
|
+
const { length } = scanIdentifierParts();
|
|
871
|
+
if (length === 1 && text[identifierStart] === "n") {
|
|
872
|
+
if (isScientific) {
|
|
873
|
+
error(Diagnostics.A_bigint_literal_cannot_use_exponential_notation, numericStart, identifierStart - numericStart + 1);
|
|
874
|
+
}
|
|
875
|
+
else {
|
|
876
|
+
error(Diagnostics.A_bigint_literal_must_be_an_integer, numericStart, identifierStart - numericStart + 1);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
error(Diagnostics.An_identifier_or_keyword_cannot_immediately_follow_a_numeric_literal, identifierStart, length);
|
|
881
|
+
pos = identifierStart;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
function scanOctalDigits() {
|
|
885
|
+
const start = pos;
|
|
886
|
+
while (isOctalDigit(text.charCodeAt(pos))) {
|
|
887
|
+
pos++;
|
|
888
|
+
}
|
|
889
|
+
return +(text.substring(start, pos));
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Scans the given number of hexadecimal digits in the text,
|
|
893
|
+
* returning -1 if the given number is unavailable.
|
|
894
|
+
*/
|
|
895
|
+
function scanExactNumberOfHexDigits(count, canHaveSeparators) {
|
|
896
|
+
const valueString = scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ false, canHaveSeparators);
|
|
897
|
+
return valueString ? parseInt(valueString, 16) : -1;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Scans as many hexadecimal digits as are available in the text,
|
|
901
|
+
* returning "" if the given number of digits was unavailable.
|
|
902
|
+
*/
|
|
903
|
+
function scanMinimumNumberOfHexDigits(count, canHaveSeparators) {
|
|
904
|
+
return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ true, canHaveSeparators);
|
|
905
|
+
}
|
|
906
|
+
function scanHexDigits(minCount, scanAsManyAsPossible, canHaveSeparators) {
|
|
907
|
+
let valueChars = [];
|
|
908
|
+
let allowSeparator = false;
|
|
909
|
+
let isPreviousTokenSeparator = false;
|
|
910
|
+
while (valueChars.length < minCount || scanAsManyAsPossible) {
|
|
911
|
+
let ch = text.charCodeAt(pos);
|
|
912
|
+
if (canHaveSeparators && ch === 95 /* CharacterCodes._ */) {
|
|
913
|
+
tokenFlags |= 512 /* TokenFlags.ContainsSeparator */;
|
|
914
|
+
if (allowSeparator) {
|
|
915
|
+
allowSeparator = false;
|
|
916
|
+
isPreviousTokenSeparator = true;
|
|
917
|
+
}
|
|
918
|
+
else if (isPreviousTokenSeparator) {
|
|
919
|
+
error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
|
|
920
|
+
}
|
|
921
|
+
else {
|
|
922
|
+
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
|
|
923
|
+
}
|
|
924
|
+
pos++;
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
allowSeparator = canHaveSeparators;
|
|
928
|
+
if (ch >= 65 /* CharacterCodes.A */ && ch <= 70 /* CharacterCodes.F */) {
|
|
929
|
+
ch += 97 /* CharacterCodes.a */ - 65 /* CharacterCodes.A */; // standardize hex literals to lowercase
|
|
930
|
+
}
|
|
931
|
+
else if (!((ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */) ||
|
|
932
|
+
(ch >= 97 /* CharacterCodes.a */ && ch <= 102 /* CharacterCodes.f */))) {
|
|
933
|
+
break;
|
|
934
|
+
}
|
|
935
|
+
valueChars.push(ch);
|
|
936
|
+
pos++;
|
|
937
|
+
isPreviousTokenSeparator = false;
|
|
938
|
+
}
|
|
939
|
+
if (valueChars.length < minCount) {
|
|
940
|
+
valueChars = [];
|
|
941
|
+
}
|
|
942
|
+
if (text.charCodeAt(pos - 1) === 95 /* CharacterCodes._ */) {
|
|
943
|
+
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos - 1, 1);
|
|
944
|
+
}
|
|
945
|
+
return String.fromCharCode(...valueChars);
|
|
946
|
+
}
|
|
947
|
+
function scanString(jsxAttributeString = false) {
|
|
948
|
+
const quote = text.charCodeAt(pos);
|
|
949
|
+
pos++;
|
|
950
|
+
let result = "";
|
|
951
|
+
let start = pos;
|
|
952
|
+
while (true) {
|
|
953
|
+
if (pos >= end) {
|
|
954
|
+
result += text.substring(start, pos);
|
|
955
|
+
tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
956
|
+
error(Diagnostics.Unterminated_string_literal);
|
|
957
|
+
break;
|
|
958
|
+
}
|
|
959
|
+
const ch = text.charCodeAt(pos);
|
|
960
|
+
if (ch === quote) {
|
|
961
|
+
result += text.substring(start, pos);
|
|
962
|
+
pos++;
|
|
963
|
+
break;
|
|
964
|
+
}
|
|
965
|
+
if (ch === 92 /* CharacterCodes.backslash */ && !jsxAttributeString) {
|
|
966
|
+
result += text.substring(start, pos);
|
|
967
|
+
result += scanEscapeSequence();
|
|
968
|
+
start = pos;
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
971
|
+
if (isLineBreak(ch) && !jsxAttributeString) {
|
|
972
|
+
result += text.substring(start, pos);
|
|
973
|
+
tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
974
|
+
error(Diagnostics.Unterminated_string_literal);
|
|
975
|
+
break;
|
|
976
|
+
}
|
|
977
|
+
pos++;
|
|
978
|
+
}
|
|
979
|
+
return result;
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Sets the current 'tokenValue' and returns a NoSubstitutionTemplateLiteral or
|
|
983
|
+
* a literal component of a TemplateExpression.
|
|
984
|
+
*/
|
|
985
|
+
function scanTemplateAndSetTokenValue() {
|
|
986
|
+
const startedWithBacktick = text.charCodeAt(pos) === 96 /* CharacterCodes.backtick */;
|
|
987
|
+
pos++;
|
|
988
|
+
let start = pos;
|
|
989
|
+
let contents = "";
|
|
990
|
+
let resultingToken;
|
|
991
|
+
while (true) {
|
|
992
|
+
if (pos >= end) {
|
|
993
|
+
contents += text.substring(start, pos);
|
|
994
|
+
tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
995
|
+
error(Diagnostics.Unterminated_template_literal);
|
|
996
|
+
resultingToken = startedWithBacktick ? 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */ : 17 /* SyntaxKind.TemplateTail */;
|
|
997
|
+
break;
|
|
998
|
+
}
|
|
999
|
+
const currChar = text.charCodeAt(pos);
|
|
1000
|
+
// '`'
|
|
1001
|
+
if (currChar === 96 /* CharacterCodes.backtick */) {
|
|
1002
|
+
contents += text.substring(start, pos);
|
|
1003
|
+
pos++;
|
|
1004
|
+
resultingToken = startedWithBacktick ? 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */ : 17 /* SyntaxKind.TemplateTail */;
|
|
1005
|
+
break;
|
|
1006
|
+
}
|
|
1007
|
+
// '${'
|
|
1008
|
+
if (currChar === 36 /* CharacterCodes.$ */ && pos + 1 < end && text.charCodeAt(pos + 1) === 123 /* CharacterCodes.openBrace */) {
|
|
1009
|
+
contents += text.substring(start, pos);
|
|
1010
|
+
pos += 2;
|
|
1011
|
+
resultingToken = startedWithBacktick ? 15 /* SyntaxKind.TemplateHead */ : 16 /* SyntaxKind.TemplateMiddle */;
|
|
1012
|
+
break;
|
|
1013
|
+
}
|
|
1014
|
+
// Escape character
|
|
1015
|
+
if (currChar === 92 /* CharacterCodes.backslash */) {
|
|
1016
|
+
contents += text.substring(start, pos);
|
|
1017
|
+
contents += scanEscapeSequence();
|
|
1018
|
+
start = pos;
|
|
1019
|
+
continue;
|
|
1020
|
+
}
|
|
1021
|
+
// Speculated ECMAScript 6 Spec 11.8.6.1:
|
|
1022
|
+
// <CR><LF> and <CR> LineTerminatorSequences are normalized to <LF> for Template Values
|
|
1023
|
+
if (currChar === 13 /* CharacterCodes.carriageReturn */) {
|
|
1024
|
+
contents += text.substring(start, pos);
|
|
1025
|
+
pos++;
|
|
1026
|
+
if (pos < end && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) {
|
|
1027
|
+
pos++;
|
|
1028
|
+
}
|
|
1029
|
+
contents += "\n";
|
|
1030
|
+
start = pos;
|
|
1031
|
+
continue;
|
|
1032
|
+
}
|
|
1033
|
+
pos++;
|
|
1034
|
+
}
|
|
1035
|
+
Debug.assert(resultingToken !== undefined);
|
|
1036
|
+
tokenValue = contents;
|
|
1037
|
+
return resultingToken;
|
|
1038
|
+
}
|
|
1039
|
+
function scanEscapeSequence() {
|
|
1040
|
+
pos++;
|
|
1041
|
+
if (pos >= end) {
|
|
1042
|
+
error(Diagnostics.Unexpected_end_of_text);
|
|
1043
|
+
return "";
|
|
1044
|
+
}
|
|
1045
|
+
const ch = text.charCodeAt(pos);
|
|
1046
|
+
pos++;
|
|
1047
|
+
switch (ch) {
|
|
1048
|
+
case 48 /* CharacterCodes._0 */:
|
|
1049
|
+
return "\0";
|
|
1050
|
+
case 98 /* CharacterCodes.b */:
|
|
1051
|
+
return "\b";
|
|
1052
|
+
case 116 /* CharacterCodes.t */:
|
|
1053
|
+
return "\t";
|
|
1054
|
+
case 110 /* CharacterCodes.n */:
|
|
1055
|
+
return "\n";
|
|
1056
|
+
case 118 /* CharacterCodes.v */:
|
|
1057
|
+
return "\v";
|
|
1058
|
+
case 102 /* CharacterCodes.f */:
|
|
1059
|
+
return "\f";
|
|
1060
|
+
case 114 /* CharacterCodes.r */:
|
|
1061
|
+
return "\r";
|
|
1062
|
+
case 39 /* CharacterCodes.singleQuote */:
|
|
1063
|
+
return "\'";
|
|
1064
|
+
case 34 /* CharacterCodes.doubleQuote */:
|
|
1065
|
+
return "\"";
|
|
1066
|
+
case 117 /* CharacterCodes.u */:
|
|
1067
|
+
// '\u{DDDDDDDD}'
|
|
1068
|
+
if (pos < end && text.charCodeAt(pos) === 123 /* CharacterCodes.openBrace */) {
|
|
1069
|
+
pos++;
|
|
1070
|
+
tokenFlags |= 8 /* TokenFlags.ExtendedUnicodeEscape */;
|
|
1071
|
+
return scanExtendedUnicodeEscape();
|
|
1072
|
+
}
|
|
1073
|
+
tokenFlags |= 1024 /* TokenFlags.UnicodeEscape */;
|
|
1074
|
+
// '\uDDDD'
|
|
1075
|
+
return scanHexadecimalEscape(/*numDigits*/ 4);
|
|
1076
|
+
case 120 /* CharacterCodes.x */:
|
|
1077
|
+
// '\xDD'
|
|
1078
|
+
return scanHexadecimalEscape(/*numDigits*/ 2);
|
|
1079
|
+
// when encountering a LineContinuation (i.e. a backslash and a line terminator sequence),
|
|
1080
|
+
// the line terminator is interpreted to be "the empty code unit sequence".
|
|
1081
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
1082
|
+
if (pos < end && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) {
|
|
1083
|
+
pos++;
|
|
1084
|
+
}
|
|
1085
|
+
// falls through
|
|
1086
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
1087
|
+
case 8232 /* CharacterCodes.lineSeparator */:
|
|
1088
|
+
case 8233 /* CharacterCodes.paragraphSeparator */:
|
|
1089
|
+
return "";
|
|
1090
|
+
default:
|
|
1091
|
+
return String.fromCharCode(ch);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
function scanHexadecimalEscape(numDigits) {
|
|
1095
|
+
const escapedValue = scanExactNumberOfHexDigits(numDigits, /*canHaveSeparators*/ false);
|
|
1096
|
+
if (escapedValue >= 0) {
|
|
1097
|
+
return String.fromCharCode(escapedValue);
|
|
1098
|
+
}
|
|
1099
|
+
else {
|
|
1100
|
+
error(Diagnostics.Hexadecimal_digit_expected);
|
|
1101
|
+
return "";
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
function scanExtendedUnicodeEscape() {
|
|
1105
|
+
const escapedValueString = scanMinimumNumberOfHexDigits(1, /*canHaveSeparators*/ false);
|
|
1106
|
+
const escapedValue = escapedValueString ? parseInt(escapedValueString, 16) : -1;
|
|
1107
|
+
let isInvalidExtendedEscape = false;
|
|
1108
|
+
// Validate the value of the digit
|
|
1109
|
+
if (escapedValue < 0) {
|
|
1110
|
+
error(Diagnostics.Hexadecimal_digit_expected);
|
|
1111
|
+
isInvalidExtendedEscape = true;
|
|
1112
|
+
}
|
|
1113
|
+
else if (escapedValue > 0x10FFFF) {
|
|
1114
|
+
error(Diagnostics.An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive);
|
|
1115
|
+
isInvalidExtendedEscape = true;
|
|
1116
|
+
}
|
|
1117
|
+
if (pos >= end) {
|
|
1118
|
+
error(Diagnostics.Unexpected_end_of_text);
|
|
1119
|
+
isInvalidExtendedEscape = true;
|
|
1120
|
+
}
|
|
1121
|
+
else if (text.charCodeAt(pos) === 125 /* CharacterCodes.closeBrace */) {
|
|
1122
|
+
// Only swallow the following character up if it's a '}'.
|
|
1123
|
+
pos++;
|
|
1124
|
+
}
|
|
1125
|
+
else {
|
|
1126
|
+
error(Diagnostics.Unterminated_Unicode_escape_sequence);
|
|
1127
|
+
isInvalidExtendedEscape = true;
|
|
1128
|
+
}
|
|
1129
|
+
if (isInvalidExtendedEscape) {
|
|
1130
|
+
return "";
|
|
1131
|
+
}
|
|
1132
|
+
return utf16EncodeAsString(escapedValue);
|
|
1133
|
+
}
|
|
1134
|
+
// Current character is known to be a backslash. Check for Unicode escape of the form '\uXXXX'
|
|
1135
|
+
// and return code point value if valid Unicode escape is found. Otherwise return -1.
|
|
1136
|
+
function peekUnicodeEscape() {
|
|
1137
|
+
if (pos + 5 < end && text.charCodeAt(pos + 1) === 117 /* CharacterCodes.u */) {
|
|
1138
|
+
const start = pos;
|
|
1139
|
+
pos += 2;
|
|
1140
|
+
const value = scanExactNumberOfHexDigits(4, /*canHaveSeparators*/ false);
|
|
1141
|
+
pos = start;
|
|
1142
|
+
return value;
|
|
1143
|
+
}
|
|
1144
|
+
return -1;
|
|
1145
|
+
}
|
|
1146
|
+
function peekExtendedUnicodeEscape() {
|
|
1147
|
+
if (languageVersion >= 2 /* ScriptTarget.ES2015 */ && codePointAt(text, pos + 1) === 117 /* CharacterCodes.u */ && codePointAt(text, pos + 2) === 123 /* CharacterCodes.openBrace */) {
|
|
1148
|
+
const start = pos;
|
|
1149
|
+
pos += 3;
|
|
1150
|
+
const escapedValueString = scanMinimumNumberOfHexDigits(1, /*canHaveSeparators*/ false);
|
|
1151
|
+
const escapedValue = escapedValueString ? parseInt(escapedValueString, 16) : -1;
|
|
1152
|
+
pos = start;
|
|
1153
|
+
return escapedValue;
|
|
1154
|
+
}
|
|
1155
|
+
return -1;
|
|
1156
|
+
}
|
|
1157
|
+
function scanIdentifierParts() {
|
|
1158
|
+
let result = "";
|
|
1159
|
+
let start = pos;
|
|
1160
|
+
while (pos < end) {
|
|
1161
|
+
let ch = codePointAt(text, pos);
|
|
1162
|
+
if (isIdentifierPart(ch, languageVersion)) {
|
|
1163
|
+
pos += charSize(ch);
|
|
1164
|
+
}
|
|
1165
|
+
else if (ch === 92 /* CharacterCodes.backslash */) {
|
|
1166
|
+
ch = peekExtendedUnicodeEscape();
|
|
1167
|
+
if (ch >= 0 && isIdentifierPart(ch, languageVersion)) {
|
|
1168
|
+
pos += 3;
|
|
1169
|
+
tokenFlags |= 8 /* TokenFlags.ExtendedUnicodeEscape */;
|
|
1170
|
+
result += scanExtendedUnicodeEscape();
|
|
1171
|
+
start = pos;
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
ch = peekUnicodeEscape();
|
|
1175
|
+
if (!(ch >= 0 && isIdentifierPart(ch, languageVersion))) {
|
|
1176
|
+
break;
|
|
1177
|
+
}
|
|
1178
|
+
tokenFlags |= 1024 /* TokenFlags.UnicodeEscape */;
|
|
1179
|
+
result += text.substring(start, pos);
|
|
1180
|
+
result += utf16EncodeAsString(ch);
|
|
1181
|
+
// Valid Unicode escape is always six characters
|
|
1182
|
+
pos += 6;
|
|
1183
|
+
start = pos;
|
|
1184
|
+
}
|
|
1185
|
+
else {
|
|
1186
|
+
break;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
result += text.substring(start, pos);
|
|
1190
|
+
return result;
|
|
1191
|
+
}
|
|
1192
|
+
function getIdentifierToken() {
|
|
1193
|
+
// Reserved words are between 2 and 11 characters long and start with a lowercase letter
|
|
1194
|
+
const len = tokenValue.length;
|
|
1195
|
+
if (len >= 2 && len <= 11) {
|
|
1196
|
+
const ch = tokenValue.charCodeAt(0);
|
|
1197
|
+
if (ch >= 97 /* CharacterCodes.a */ && ch <= 122 /* CharacterCodes.z */) {
|
|
1198
|
+
const keyword = textToKeyword.get(tokenValue);
|
|
1199
|
+
if (keyword !== undefined) {
|
|
1200
|
+
return token = keyword;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
return token = 75 /* SyntaxKind.Identifier */;
|
|
1205
|
+
}
|
|
1206
|
+
function scanBinaryOrOctalDigits(base) {
|
|
1207
|
+
let value = "";
|
|
1208
|
+
// For counting number of digits; Valid binaryIntegerLiteral must have at least one binary digit following B or b.
|
|
1209
|
+
// Similarly valid octalIntegerLiteral must have at least one octal digit following o or O.
|
|
1210
|
+
let separatorAllowed = false;
|
|
1211
|
+
let isPreviousTokenSeparator = false;
|
|
1212
|
+
while (true) {
|
|
1213
|
+
const ch = text.charCodeAt(pos);
|
|
1214
|
+
// Numeric separators are allowed anywhere within a numeric literal, except not at the beginning, or following another separator
|
|
1215
|
+
if (ch === 95 /* CharacterCodes._ */) {
|
|
1216
|
+
tokenFlags |= 512 /* TokenFlags.ContainsSeparator */;
|
|
1217
|
+
if (separatorAllowed) {
|
|
1218
|
+
separatorAllowed = false;
|
|
1219
|
+
isPreviousTokenSeparator = true;
|
|
1220
|
+
}
|
|
1221
|
+
else if (isPreviousTokenSeparator) {
|
|
1222
|
+
error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
|
|
1223
|
+
}
|
|
1224
|
+
else {
|
|
1225
|
+
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
|
|
1226
|
+
}
|
|
1227
|
+
pos++;
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
1230
|
+
separatorAllowed = true;
|
|
1231
|
+
if (!isDigit(ch) || ch - 48 /* CharacterCodes._0 */ >= base) {
|
|
1232
|
+
break;
|
|
1233
|
+
}
|
|
1234
|
+
value += text[pos];
|
|
1235
|
+
pos++;
|
|
1236
|
+
isPreviousTokenSeparator = false;
|
|
1237
|
+
}
|
|
1238
|
+
if (text.charCodeAt(pos - 1) === 95 /* CharacterCodes._ */) {
|
|
1239
|
+
// Literal ends with underscore - not allowed
|
|
1240
|
+
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos - 1, 1);
|
|
1241
|
+
}
|
|
1242
|
+
return value;
|
|
1243
|
+
}
|
|
1244
|
+
function checkBigIntSuffix() {
|
|
1245
|
+
if (text.charCodeAt(pos) === 110 /* CharacterCodes.n */) {
|
|
1246
|
+
tokenValue += "n";
|
|
1247
|
+
// Use base 10 instead of base 2 or base 8 for shorter literals
|
|
1248
|
+
if (tokenFlags & 384 /* TokenFlags.BinaryOrOctalSpecifier */) {
|
|
1249
|
+
tokenValue = parsePseudoBigInt(tokenValue) + "n";
|
|
1250
|
+
}
|
|
1251
|
+
pos++;
|
|
1252
|
+
return 9 /* SyntaxKind.BigIntLiteral */;
|
|
1253
|
+
}
|
|
1254
|
+
else { // not a bigint, so can convert to number in simplified form
|
|
1255
|
+
// Number() may not support 0b or 0o, so use parseInt() instead
|
|
1256
|
+
const numericValue = tokenFlags & 128 /* TokenFlags.BinarySpecifier */
|
|
1257
|
+
? parseInt(tokenValue.slice(2), 2) // skip "0b"
|
|
1258
|
+
: tokenFlags & 256 /* TokenFlags.OctalSpecifier */
|
|
1259
|
+
? parseInt(tokenValue.slice(2), 8) // skip "0o"
|
|
1260
|
+
: +tokenValue;
|
|
1261
|
+
tokenValue = "" + numericValue;
|
|
1262
|
+
return 8 /* SyntaxKind.NumericLiteral */;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
function scan() {
|
|
1266
|
+
startPos = pos;
|
|
1267
|
+
tokenFlags = 0 /* TokenFlags.None */;
|
|
1268
|
+
while (true) {
|
|
1269
|
+
tokenPos = pos;
|
|
1270
|
+
if (pos >= end) {
|
|
1271
|
+
return token = 1 /* SyntaxKind.EndOfFileToken */;
|
|
1272
|
+
}
|
|
1273
|
+
let ch = codePointAt(text, pos);
|
|
1274
|
+
// Special handling for shebang
|
|
1275
|
+
if (ch === 35 /* CharacterCodes.hash */ && pos === 0 && isShebangTrivia(text, pos)) {
|
|
1276
|
+
pos = scanShebangTrivia(text, pos);
|
|
1277
|
+
if (skipTrivia) {
|
|
1278
|
+
continue;
|
|
1279
|
+
}
|
|
1280
|
+
else {
|
|
1281
|
+
return token = 6 /* SyntaxKind.ShebangTrivia */;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
switch (ch) {
|
|
1285
|
+
case 10 /* CharacterCodes.lineFeed */:
|
|
1286
|
+
case 13 /* CharacterCodes.carriageReturn */:
|
|
1287
|
+
tokenFlags |= 1 /* TokenFlags.PrecedingLineBreak */;
|
|
1288
|
+
if (skipTrivia) {
|
|
1289
|
+
pos++;
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
else {
|
|
1293
|
+
if (ch === 13 /* CharacterCodes.carriageReturn */ && pos + 1 < end && text.charCodeAt(pos + 1) === 10 /* CharacterCodes.lineFeed */) {
|
|
1294
|
+
// consume both CR and LF
|
|
1295
|
+
pos += 2;
|
|
1296
|
+
}
|
|
1297
|
+
else {
|
|
1298
|
+
pos++;
|
|
1299
|
+
}
|
|
1300
|
+
return token = 4 /* SyntaxKind.NewLineTrivia */;
|
|
1301
|
+
}
|
|
1302
|
+
case 9 /* CharacterCodes.tab */:
|
|
1303
|
+
case 11 /* CharacterCodes.verticalTab */:
|
|
1304
|
+
case 12 /* CharacterCodes.formFeed */:
|
|
1305
|
+
case 32 /* CharacterCodes.space */:
|
|
1306
|
+
case 160 /* CharacterCodes.nonBreakingSpace */:
|
|
1307
|
+
case 5760 /* CharacterCodes.ogham */:
|
|
1308
|
+
case 8192 /* CharacterCodes.enQuad */:
|
|
1309
|
+
case 8193 /* CharacterCodes.emQuad */:
|
|
1310
|
+
case 8194 /* CharacterCodes.enSpace */:
|
|
1311
|
+
case 8195 /* CharacterCodes.emSpace */:
|
|
1312
|
+
case 8196 /* CharacterCodes.threePerEmSpace */:
|
|
1313
|
+
case 8197 /* CharacterCodes.fourPerEmSpace */:
|
|
1314
|
+
case 8198 /* CharacterCodes.sixPerEmSpace */:
|
|
1315
|
+
case 8199 /* CharacterCodes.figureSpace */:
|
|
1316
|
+
case 8200 /* CharacterCodes.punctuationSpace */:
|
|
1317
|
+
case 8201 /* CharacterCodes.thinSpace */:
|
|
1318
|
+
case 8202 /* CharacterCodes.hairSpace */:
|
|
1319
|
+
case 8203 /* CharacterCodes.zeroWidthSpace */:
|
|
1320
|
+
case 8239 /* CharacterCodes.narrowNoBreakSpace */:
|
|
1321
|
+
case 8287 /* CharacterCodes.mathematicalSpace */:
|
|
1322
|
+
case 12288 /* CharacterCodes.ideographicSpace */:
|
|
1323
|
+
case 65279 /* CharacterCodes.byteOrderMark */:
|
|
1324
|
+
if (skipTrivia) {
|
|
1325
|
+
pos++;
|
|
1326
|
+
continue;
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
while (pos < end && isWhiteSpaceSingleLine(text.charCodeAt(pos))) {
|
|
1330
|
+
pos++;
|
|
1331
|
+
}
|
|
1332
|
+
return token = 5 /* SyntaxKind.WhitespaceTrivia */;
|
|
1333
|
+
}
|
|
1334
|
+
case 33 /* CharacterCodes.exclamation */:
|
|
1335
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1336
|
+
if (text.charCodeAt(pos + 2) === 61 /* CharacterCodes.equals */) {
|
|
1337
|
+
return pos += 3, token = 37 /* SyntaxKind.ExclamationEqualsEqualsToken */;
|
|
1338
|
+
}
|
|
1339
|
+
return pos += 2, token = 35 /* SyntaxKind.ExclamationEqualsToken */;
|
|
1340
|
+
}
|
|
1341
|
+
pos++;
|
|
1342
|
+
return token = 53 /* SyntaxKind.ExclamationToken */;
|
|
1343
|
+
case 34 /* CharacterCodes.doubleQuote */:
|
|
1344
|
+
case 39 /* CharacterCodes.singleQuote */:
|
|
1345
|
+
tokenValue = scanString();
|
|
1346
|
+
return token = 10 /* SyntaxKind.StringLiteral */;
|
|
1347
|
+
case 96 /* CharacterCodes.backtick */:
|
|
1348
|
+
return token = scanTemplateAndSetTokenValue();
|
|
1349
|
+
case 37 /* CharacterCodes.percent */:
|
|
1350
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1351
|
+
return pos += 2, token = 68 /* SyntaxKind.PercentEqualsToken */;
|
|
1352
|
+
}
|
|
1353
|
+
pos++;
|
|
1354
|
+
return token = 44 /* SyntaxKind.PercentToken */;
|
|
1355
|
+
case 38 /* CharacterCodes.ampersand */:
|
|
1356
|
+
if (text.charCodeAt(pos + 1) === 38 /* CharacterCodes.ampersand */) {
|
|
1357
|
+
return pos += 2, token = 55 /* SyntaxKind.AmpersandAmpersandToken */;
|
|
1358
|
+
}
|
|
1359
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1360
|
+
return pos += 2, token = 72 /* SyntaxKind.AmpersandEqualsToken */;
|
|
1361
|
+
}
|
|
1362
|
+
pos++;
|
|
1363
|
+
return token = 50 /* SyntaxKind.AmpersandToken */;
|
|
1364
|
+
case 40 /* CharacterCodes.openParen */:
|
|
1365
|
+
pos++;
|
|
1366
|
+
return token = 20 /* SyntaxKind.OpenParenToken */;
|
|
1367
|
+
case 41 /* CharacterCodes.closeParen */:
|
|
1368
|
+
pos++;
|
|
1369
|
+
return token = 21 /* SyntaxKind.CloseParenToken */;
|
|
1370
|
+
case 42 /* CharacterCodes.asterisk */:
|
|
1371
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1372
|
+
return pos += 2, token = 65 /* SyntaxKind.AsteriskEqualsToken */;
|
|
1373
|
+
}
|
|
1374
|
+
if (text.charCodeAt(pos + 1) === 42 /* CharacterCodes.asterisk */) {
|
|
1375
|
+
if (text.charCodeAt(pos + 2) === 61 /* CharacterCodes.equals */) {
|
|
1376
|
+
return pos += 3, token = 66 /* SyntaxKind.AsteriskAsteriskEqualsToken */;
|
|
1377
|
+
}
|
|
1378
|
+
return pos += 2, token = 42 /* SyntaxKind.AsteriskAsteriskToken */;
|
|
1379
|
+
}
|
|
1380
|
+
pos++;
|
|
1381
|
+
return token = 41 /* SyntaxKind.AsteriskToken */;
|
|
1382
|
+
case 43 /* CharacterCodes.plus */:
|
|
1383
|
+
if (text.charCodeAt(pos + 1) === 43 /* CharacterCodes.plus */) {
|
|
1384
|
+
return pos += 2, token = 45 /* SyntaxKind.PlusPlusToken */;
|
|
1385
|
+
}
|
|
1386
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1387
|
+
return pos += 2, token = 63 /* SyntaxKind.PlusEqualsToken */;
|
|
1388
|
+
}
|
|
1389
|
+
pos++;
|
|
1390
|
+
return token = 39 /* SyntaxKind.PlusToken */;
|
|
1391
|
+
case 44 /* CharacterCodes.comma */:
|
|
1392
|
+
pos++;
|
|
1393
|
+
return token = 27 /* SyntaxKind.CommaToken */;
|
|
1394
|
+
case 45 /* CharacterCodes.minus */:
|
|
1395
|
+
if (text.charCodeAt(pos + 1) === 45 /* CharacterCodes.minus */) {
|
|
1396
|
+
return pos += 2, token = 46 /* SyntaxKind.MinusMinusToken */;
|
|
1397
|
+
}
|
|
1398
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1399
|
+
return pos += 2, token = 64 /* SyntaxKind.MinusEqualsToken */;
|
|
1400
|
+
}
|
|
1401
|
+
pos++;
|
|
1402
|
+
return token = 40 /* SyntaxKind.MinusToken */;
|
|
1403
|
+
case 46 /* CharacterCodes.dot */:
|
|
1404
|
+
if (isDigit(text.charCodeAt(pos + 1))) {
|
|
1405
|
+
tokenValue = scanNumber().value;
|
|
1406
|
+
return token = 8 /* SyntaxKind.NumericLiteral */;
|
|
1407
|
+
}
|
|
1408
|
+
if (text.charCodeAt(pos + 1) === 46 /* CharacterCodes.dot */ && text.charCodeAt(pos + 2) === 46 /* CharacterCodes.dot */) {
|
|
1409
|
+
return pos += 3, token = 25 /* SyntaxKind.DotDotDotToken */;
|
|
1410
|
+
}
|
|
1411
|
+
pos++;
|
|
1412
|
+
return token = 24 /* SyntaxKind.DotToken */;
|
|
1413
|
+
case 47 /* CharacterCodes.slash */:
|
|
1414
|
+
// Single-line comment
|
|
1415
|
+
if (text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
|
|
1416
|
+
pos += 2;
|
|
1417
|
+
while (pos < end) {
|
|
1418
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
1419
|
+
break;
|
|
1420
|
+
}
|
|
1421
|
+
pos++;
|
|
1422
|
+
}
|
|
1423
|
+
commentDirectives = appendIfCommentDirective(commentDirectives, text.slice(tokenPos, pos), commentDirectiveRegExSingleLine, tokenPos);
|
|
1424
|
+
if (skipTrivia) {
|
|
1425
|
+
continue;
|
|
1426
|
+
}
|
|
1427
|
+
else {
|
|
1428
|
+
return token = 2 /* SyntaxKind.SingleLineCommentTrivia */;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
// Multi-line comment
|
|
1432
|
+
if (text.charCodeAt(pos + 1) === 42 /* CharacterCodes.asterisk */) {
|
|
1433
|
+
pos += 2;
|
|
1434
|
+
let commentClosed = false;
|
|
1435
|
+
let lastLineStart = tokenPos;
|
|
1436
|
+
while (pos < end) {
|
|
1437
|
+
const ch = text.charCodeAt(pos);
|
|
1438
|
+
if (ch === 42 /* CharacterCodes.asterisk */ && text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
|
|
1439
|
+
pos += 2;
|
|
1440
|
+
commentClosed = true;
|
|
1441
|
+
break;
|
|
1442
|
+
}
|
|
1443
|
+
pos++;
|
|
1444
|
+
if (isLineBreak(ch)) {
|
|
1445
|
+
lastLineStart = pos;
|
|
1446
|
+
tokenFlags |= 1 /* TokenFlags.PrecedingLineBreak */;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
commentDirectives = appendIfCommentDirective(commentDirectives, text.slice(lastLineStart, pos), commentDirectiveRegExMultiLine, lastLineStart);
|
|
1450
|
+
if (!commentClosed) {
|
|
1451
|
+
error(Diagnostics.Asterisk_Slash_expected);
|
|
1452
|
+
}
|
|
1453
|
+
if (skipTrivia) {
|
|
1454
|
+
continue;
|
|
1455
|
+
}
|
|
1456
|
+
else {
|
|
1457
|
+
if (!commentClosed) {
|
|
1458
|
+
tokenFlags |= 4 /* TokenFlags.Unterminated */;
|
|
1459
|
+
}
|
|
1460
|
+
return token = 3 /* SyntaxKind.MultiLineCommentTrivia */;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1464
|
+
return pos += 2, token = 67 /* SyntaxKind.SlashEqualsToken */;
|
|
1465
|
+
}
|
|
1466
|
+
pos++;
|
|
1467
|
+
return token = 43 /* SyntaxKind.SlashToken */;
|
|
1468
|
+
case 48 /* CharacterCodes._0 */:
|
|
1469
|
+
if (pos + 2 < end && (text.charCodeAt(pos + 1) === 88 /* CharacterCodes.X */ || text.charCodeAt(pos + 1) === 120 /* CharacterCodes.x */)) {
|
|
1470
|
+
pos += 2;
|
|
1471
|
+
tokenValue = scanMinimumNumberOfHexDigits(1, /*canHaveSeparators*/ true);
|
|
1472
|
+
if (!tokenValue) {
|
|
1473
|
+
error(Diagnostics.Hexadecimal_digit_expected);
|
|
1474
|
+
tokenValue = "0";
|
|
1475
|
+
}
|
|
1476
|
+
tokenValue = "0x" + tokenValue;
|
|
1477
|
+
tokenFlags |= 64 /* TokenFlags.HexSpecifier */;
|
|
1478
|
+
return token = checkBigIntSuffix();
|
|
1479
|
+
}
|
|
1480
|
+
else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 66 /* CharacterCodes.B */ || text.charCodeAt(pos + 1) === 98 /* CharacterCodes.b */)) {
|
|
1481
|
+
pos += 2;
|
|
1482
|
+
tokenValue = scanBinaryOrOctalDigits(/* base */ 2);
|
|
1483
|
+
if (!tokenValue) {
|
|
1484
|
+
error(Diagnostics.Binary_digit_expected);
|
|
1485
|
+
tokenValue = "0";
|
|
1486
|
+
}
|
|
1487
|
+
tokenValue = "0b" + tokenValue;
|
|
1488
|
+
tokenFlags |= 128 /* TokenFlags.BinarySpecifier */;
|
|
1489
|
+
return token = checkBigIntSuffix();
|
|
1490
|
+
}
|
|
1491
|
+
else if (pos + 2 < end && (text.charCodeAt(pos + 1) === 79 /* CharacterCodes.O */ || text.charCodeAt(pos + 1) === 111 /* CharacterCodes.o */)) {
|
|
1492
|
+
pos += 2;
|
|
1493
|
+
tokenValue = scanBinaryOrOctalDigits(/* base */ 8);
|
|
1494
|
+
if (!tokenValue) {
|
|
1495
|
+
error(Diagnostics.Octal_digit_expected);
|
|
1496
|
+
tokenValue = "0";
|
|
1497
|
+
}
|
|
1498
|
+
tokenValue = "0o" + tokenValue;
|
|
1499
|
+
tokenFlags |= 256 /* TokenFlags.OctalSpecifier */;
|
|
1500
|
+
return token = checkBigIntSuffix();
|
|
1501
|
+
}
|
|
1502
|
+
// Try to parse as an octal
|
|
1503
|
+
if (pos + 1 < end && isOctalDigit(text.charCodeAt(pos + 1))) {
|
|
1504
|
+
tokenValue = "" + scanOctalDigits();
|
|
1505
|
+
tokenFlags |= 32 /* TokenFlags.Octal */;
|
|
1506
|
+
return token = 8 /* SyntaxKind.NumericLiteral */;
|
|
1507
|
+
}
|
|
1508
|
+
// This fall-through is a deviation from the EcmaScript grammar. The grammar says that a leading zero
|
|
1509
|
+
// can only be followed by an octal digit, a dot, or the end of the number literal. However, we are being
|
|
1510
|
+
// permissive and allowing decimal digits of the form 08* and 09* (which many browsers also do).
|
|
1511
|
+
// falls through
|
|
1512
|
+
case 49 /* CharacterCodes._1 */:
|
|
1513
|
+
case 50 /* CharacterCodes._2 */:
|
|
1514
|
+
case 51 /* CharacterCodes._3 */:
|
|
1515
|
+
case 52 /* CharacterCodes._4 */:
|
|
1516
|
+
case 53 /* CharacterCodes._5 */:
|
|
1517
|
+
case 54 /* CharacterCodes._6 */:
|
|
1518
|
+
case 55 /* CharacterCodes._7 */:
|
|
1519
|
+
case 56 /* CharacterCodes._8 */:
|
|
1520
|
+
case 57 /* CharacterCodes._9 */:
|
|
1521
|
+
({ type: token, value: tokenValue } = scanNumber());
|
|
1522
|
+
return token;
|
|
1523
|
+
case 58 /* CharacterCodes.colon */:
|
|
1524
|
+
pos++;
|
|
1525
|
+
return token = 58 /* SyntaxKind.ColonToken */;
|
|
1526
|
+
case 59 /* CharacterCodes.semicolon */:
|
|
1527
|
+
pos++;
|
|
1528
|
+
return token = 26 /* SyntaxKind.SemicolonToken */;
|
|
1529
|
+
case 60 /* CharacterCodes.lessThan */:
|
|
1530
|
+
if (isConflictMarkerTrivia(text, pos)) {
|
|
1531
|
+
pos = scanConflictMarkerTrivia(text, pos, error);
|
|
1532
|
+
if (skipTrivia) {
|
|
1533
|
+
continue;
|
|
1534
|
+
}
|
|
1535
|
+
else {
|
|
1536
|
+
return token = 7 /* SyntaxKind.ConflictMarkerTrivia */;
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
if (text.charCodeAt(pos + 1) === 60 /* CharacterCodes.lessThan */) {
|
|
1540
|
+
if (text.charCodeAt(pos + 2) === 61 /* CharacterCodes.equals */) {
|
|
1541
|
+
return pos += 3, token = 69 /* SyntaxKind.LessThanLessThanEqualsToken */;
|
|
1542
|
+
}
|
|
1543
|
+
return pos += 2, token = 47 /* SyntaxKind.LessThanLessThanToken */;
|
|
1544
|
+
}
|
|
1545
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1546
|
+
return pos += 2, token = 32 /* SyntaxKind.LessThanEqualsToken */;
|
|
1547
|
+
}
|
|
1548
|
+
if (languageVariant === 1 /* LanguageVariant.JSX */ &&
|
|
1549
|
+
text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */ &&
|
|
1550
|
+
text.charCodeAt(pos + 2) !== 42 /* CharacterCodes.asterisk */) {
|
|
1551
|
+
return pos += 2, token = 30 /* SyntaxKind.LessThanSlashToken */;
|
|
1552
|
+
}
|
|
1553
|
+
pos++;
|
|
1554
|
+
return token = 29 /* SyntaxKind.LessThanToken */;
|
|
1555
|
+
case 61 /* CharacterCodes.equals */:
|
|
1556
|
+
if (isConflictMarkerTrivia(text, pos)) {
|
|
1557
|
+
pos = scanConflictMarkerTrivia(text, pos, error);
|
|
1558
|
+
if (skipTrivia) {
|
|
1559
|
+
continue;
|
|
1560
|
+
}
|
|
1561
|
+
else {
|
|
1562
|
+
return token = 7 /* SyntaxKind.ConflictMarkerTrivia */;
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1566
|
+
if (text.charCodeAt(pos + 2) === 61 /* CharacterCodes.equals */) {
|
|
1567
|
+
return pos += 3, token = 36 /* SyntaxKind.EqualsEqualsEqualsToken */;
|
|
1568
|
+
}
|
|
1569
|
+
return pos += 2, token = 34 /* SyntaxKind.EqualsEqualsToken */;
|
|
1570
|
+
}
|
|
1571
|
+
if (text.charCodeAt(pos + 1) === 62 /* CharacterCodes.greaterThan */) {
|
|
1572
|
+
return pos += 2, token = 38 /* SyntaxKind.EqualsGreaterThanToken */;
|
|
1573
|
+
}
|
|
1574
|
+
pos++;
|
|
1575
|
+
return token = 62 /* SyntaxKind.EqualsToken */;
|
|
1576
|
+
case 62 /* CharacterCodes.greaterThan */:
|
|
1577
|
+
if (isConflictMarkerTrivia(text, pos)) {
|
|
1578
|
+
pos = scanConflictMarkerTrivia(text, pos, error);
|
|
1579
|
+
if (skipTrivia) {
|
|
1580
|
+
continue;
|
|
1581
|
+
}
|
|
1582
|
+
else {
|
|
1583
|
+
return token = 7 /* SyntaxKind.ConflictMarkerTrivia */;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
pos++;
|
|
1587
|
+
return token = 31 /* SyntaxKind.GreaterThanToken */;
|
|
1588
|
+
case 63 /* CharacterCodes.question */:
|
|
1589
|
+
pos++;
|
|
1590
|
+
if (text.charCodeAt(pos) === 46 /* CharacterCodes.dot */ && !isDigit(text.charCodeAt(pos + 1))) {
|
|
1591
|
+
pos++;
|
|
1592
|
+
return token = 28 /* SyntaxKind.QuestionDotToken */;
|
|
1593
|
+
}
|
|
1594
|
+
if (text.charCodeAt(pos) === 63 /* CharacterCodes.question */) {
|
|
1595
|
+
pos++;
|
|
1596
|
+
return token = 60 /* SyntaxKind.QuestionQuestionToken */;
|
|
1597
|
+
}
|
|
1598
|
+
return token = 57 /* SyntaxKind.QuestionToken */;
|
|
1599
|
+
case 91 /* CharacterCodes.openBracket */:
|
|
1600
|
+
pos++;
|
|
1601
|
+
return token = 22 /* SyntaxKind.OpenBracketToken */;
|
|
1602
|
+
case 93 /* CharacterCodes.closeBracket */:
|
|
1603
|
+
pos++;
|
|
1604
|
+
return token = 23 /* SyntaxKind.CloseBracketToken */;
|
|
1605
|
+
case 94 /* CharacterCodes.caret */:
|
|
1606
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1607
|
+
return pos += 2, token = 74 /* SyntaxKind.CaretEqualsToken */;
|
|
1608
|
+
}
|
|
1609
|
+
pos++;
|
|
1610
|
+
return token = 52 /* SyntaxKind.CaretToken */;
|
|
1611
|
+
case 123 /* CharacterCodes.openBrace */:
|
|
1612
|
+
pos++;
|
|
1613
|
+
return token = 18 /* SyntaxKind.OpenBraceToken */;
|
|
1614
|
+
case 124 /* CharacterCodes.bar */:
|
|
1615
|
+
if (isConflictMarkerTrivia(text, pos)) {
|
|
1616
|
+
pos = scanConflictMarkerTrivia(text, pos, error);
|
|
1617
|
+
if (skipTrivia) {
|
|
1618
|
+
continue;
|
|
1619
|
+
}
|
|
1620
|
+
else {
|
|
1621
|
+
return token = 7 /* SyntaxKind.ConflictMarkerTrivia */;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
if (text.charCodeAt(pos + 1) === 124 /* CharacterCodes.bar */) {
|
|
1625
|
+
return pos += 2, token = 56 /* SyntaxKind.BarBarToken */;
|
|
1626
|
+
}
|
|
1627
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1628
|
+
return pos += 2, token = 73 /* SyntaxKind.BarEqualsToken */;
|
|
1629
|
+
}
|
|
1630
|
+
pos++;
|
|
1631
|
+
return token = 51 /* SyntaxKind.BarToken */;
|
|
1632
|
+
case 125 /* CharacterCodes.closeBrace */:
|
|
1633
|
+
pos++;
|
|
1634
|
+
return token = 19 /* SyntaxKind.CloseBraceToken */;
|
|
1635
|
+
case 126 /* CharacterCodes.tilde */:
|
|
1636
|
+
pos++;
|
|
1637
|
+
return token = 54 /* SyntaxKind.TildeToken */;
|
|
1638
|
+
case 64 /* CharacterCodes.at */:
|
|
1639
|
+
pos++;
|
|
1640
|
+
return token = 59 /* SyntaxKind.AtToken */;
|
|
1641
|
+
case 92 /* CharacterCodes.backslash */:
|
|
1642
|
+
const extendedCookedChar = peekExtendedUnicodeEscape();
|
|
1643
|
+
if (extendedCookedChar >= 0 && isIdentifierStart(extendedCookedChar, languageVersion)) {
|
|
1644
|
+
pos += 3;
|
|
1645
|
+
tokenFlags |= 8 /* TokenFlags.ExtendedUnicodeEscape */;
|
|
1646
|
+
tokenValue = scanExtendedUnicodeEscape() + scanIdentifierParts();
|
|
1647
|
+
return token = getIdentifierToken();
|
|
1648
|
+
}
|
|
1649
|
+
const cookedChar = peekUnicodeEscape();
|
|
1650
|
+
if (cookedChar >= 0 && isIdentifierStart(cookedChar, languageVersion)) {
|
|
1651
|
+
pos += 6;
|
|
1652
|
+
tokenFlags |= 1024 /* TokenFlags.UnicodeEscape */;
|
|
1653
|
+
tokenValue = String.fromCharCode(cookedChar) + scanIdentifierParts();
|
|
1654
|
+
return token = getIdentifierToken();
|
|
1655
|
+
}
|
|
1656
|
+
error(Diagnostics.Invalid_character);
|
|
1657
|
+
pos++;
|
|
1658
|
+
return token = 0 /* SyntaxKind.Unknown */;
|
|
1659
|
+
case 35 /* CharacterCodes.hash */:
|
|
1660
|
+
if (pos !== 0 && text[pos + 1] === "!") {
|
|
1661
|
+
error(Diagnostics.can_only_be_used_at_the_start_of_a_file);
|
|
1662
|
+
pos++;
|
|
1663
|
+
return token = 0 /* SyntaxKind.Unknown */;
|
|
1664
|
+
}
|
|
1665
|
+
// Sem o `#private` da classe, o `#` não começa nada.
|
|
1666
|
+
error(Diagnostics.Invalid_character);
|
|
1667
|
+
pos++;
|
|
1668
|
+
return token = 0 /* SyntaxKind.Unknown */;
|
|
1669
|
+
default:
|
|
1670
|
+
if (isIdentifierStart(ch, languageVersion)) {
|
|
1671
|
+
pos += charSize(ch);
|
|
1672
|
+
while (pos < end && isIdentifierPart(ch = codePointAt(text, pos), languageVersion))
|
|
1673
|
+
pos += charSize(ch);
|
|
1674
|
+
tokenValue = text.substring(tokenPos, pos);
|
|
1675
|
+
if (ch === 92 /* CharacterCodes.backslash */) {
|
|
1676
|
+
tokenValue += scanIdentifierParts();
|
|
1677
|
+
}
|
|
1678
|
+
return token = getIdentifierToken();
|
|
1679
|
+
}
|
|
1680
|
+
else if (isWhiteSpaceSingleLine(ch)) {
|
|
1681
|
+
pos += charSize(ch);
|
|
1682
|
+
continue;
|
|
1683
|
+
}
|
|
1684
|
+
else if (isLineBreak(ch)) {
|
|
1685
|
+
tokenFlags |= 1 /* TokenFlags.PrecedingLineBreak */;
|
|
1686
|
+
pos += charSize(ch);
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
error(Diagnostics.Invalid_character);
|
|
1690
|
+
pos += charSize(ch);
|
|
1691
|
+
return token = 0 /* SyntaxKind.Unknown */;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
function reScanGreaterToken() {
|
|
1696
|
+
if (token === 31 /* SyntaxKind.GreaterThanToken */) {
|
|
1697
|
+
if (text.charCodeAt(pos) === 62 /* CharacterCodes.greaterThan */) {
|
|
1698
|
+
if (text.charCodeAt(pos + 1) === 62 /* CharacterCodes.greaterThan */) {
|
|
1699
|
+
if (text.charCodeAt(pos + 2) === 61 /* CharacterCodes.equals */) {
|
|
1700
|
+
return pos += 3, token = 71 /* SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken */;
|
|
1701
|
+
}
|
|
1702
|
+
return pos += 2, token = 49 /* SyntaxKind.GreaterThanGreaterThanGreaterThanToken */;
|
|
1703
|
+
}
|
|
1704
|
+
if (text.charCodeAt(pos + 1) === 61 /* CharacterCodes.equals */) {
|
|
1705
|
+
return pos += 2, token = 70 /* SyntaxKind.GreaterThanGreaterThanEqualsToken */;
|
|
1706
|
+
}
|
|
1707
|
+
pos++;
|
|
1708
|
+
return token = 48 /* SyntaxKind.GreaterThanGreaterThanToken */;
|
|
1709
|
+
}
|
|
1710
|
+
if (text.charCodeAt(pos) === 61 /* CharacterCodes.equals */) {
|
|
1711
|
+
pos++;
|
|
1712
|
+
return token = 33 /* SyntaxKind.GreaterThanEqualsToken */;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
return token;
|
|
1716
|
+
}
|
|
1717
|
+
function appendIfCommentDirective(commentDirectives, text, commentDirectiveRegEx, lineStart) {
|
|
1718
|
+
const type = getDirectiveFromComment(text, commentDirectiveRegEx);
|
|
1719
|
+
if (type === undefined) {
|
|
1720
|
+
return commentDirectives;
|
|
1721
|
+
}
|
|
1722
|
+
return append(commentDirectives, {
|
|
1723
|
+
range: { pos: lineStart, end: pos },
|
|
1724
|
+
type,
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
function getDirectiveFromComment(text, commentDirectiveRegEx) {
|
|
1728
|
+
const match = commentDirectiveRegEx.exec(text);
|
|
1729
|
+
if (!match) {
|
|
1730
|
+
return undefined;
|
|
1731
|
+
}
|
|
1732
|
+
switch (match[1]) {
|
|
1733
|
+
case "ts-expect-error":
|
|
1734
|
+
return 0 /* CommentDirectiveType.ExpectError */;
|
|
1735
|
+
case "ts-ignore":
|
|
1736
|
+
return 1 /* CommentDirectiveType.Ignore */;
|
|
1737
|
+
}
|
|
1738
|
+
return undefined;
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Unconditionally back up and scan a template expression portion.
|
|
1742
|
+
*/
|
|
1743
|
+
function reScanTemplateToken() {
|
|
1744
|
+
Debug.assert(token === 19 /* SyntaxKind.CloseBraceToken */, "'reScanTemplateToken' should only be called on a '}'");
|
|
1745
|
+
pos = tokenPos;
|
|
1746
|
+
return token = scanTemplateAndSetTokenValue();
|
|
1747
|
+
}
|
|
1748
|
+
function reScanJsxToken() {
|
|
1749
|
+
pos = tokenPos = startPos;
|
|
1750
|
+
return token = scanJsxToken();
|
|
1751
|
+
}
|
|
1752
|
+
function reScanLessThanToken() {
|
|
1753
|
+
if (token === 47 /* SyntaxKind.LessThanLessThanToken */) {
|
|
1754
|
+
pos = tokenPos + 1;
|
|
1755
|
+
return token = 29 /* SyntaxKind.LessThanToken */;
|
|
1756
|
+
}
|
|
1757
|
+
return token;
|
|
1758
|
+
}
|
|
1759
|
+
function reScanQuestionToken() {
|
|
1760
|
+
Debug.assert(token === 60 /* SyntaxKind.QuestionQuestionToken */, "'reScanQuestionToken' should only be called on a '??'");
|
|
1761
|
+
pos = tokenPos + 1;
|
|
1762
|
+
return token = 57 /* SyntaxKind.QuestionToken */;
|
|
1763
|
+
}
|
|
1764
|
+
function scanJsxToken() {
|
|
1765
|
+
startPos = tokenPos = pos;
|
|
1766
|
+
if (pos >= end) {
|
|
1767
|
+
return token = 1 /* SyntaxKind.EndOfFileToken */;
|
|
1768
|
+
}
|
|
1769
|
+
let char = text.charCodeAt(pos);
|
|
1770
|
+
if (char === 60 /* CharacterCodes.lessThan */) {
|
|
1771
|
+
if (text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
|
|
1772
|
+
pos += 2;
|
|
1773
|
+
return token = 30 /* SyntaxKind.LessThanSlashToken */;
|
|
1774
|
+
}
|
|
1775
|
+
pos++;
|
|
1776
|
+
return token = 29 /* SyntaxKind.LessThanToken */;
|
|
1777
|
+
}
|
|
1778
|
+
if (char === 123 /* CharacterCodes.openBrace */) {
|
|
1779
|
+
pos++;
|
|
1780
|
+
return token = 18 /* SyntaxKind.OpenBraceToken */;
|
|
1781
|
+
}
|
|
1782
|
+
// First non-whitespace character on this line.
|
|
1783
|
+
let firstNonWhitespace = 0;
|
|
1784
|
+
let lastNonWhitespace = -1;
|
|
1785
|
+
// These initial values are special because the first line is:
|
|
1786
|
+
// firstNonWhitespace = 0 to indicate that we want leading whitespace,
|
|
1787
|
+
while (pos < end) {
|
|
1788
|
+
// We want to keep track of the last non-whitespace (but including
|
|
1789
|
+
// newlines character for hitting the end of the JSX Text region)
|
|
1790
|
+
if (!isWhiteSpaceSingleLine(char)) {
|
|
1791
|
+
lastNonWhitespace = pos;
|
|
1792
|
+
}
|
|
1793
|
+
char = text.charCodeAt(pos);
|
|
1794
|
+
if (char === 123 /* CharacterCodes.openBrace */) {
|
|
1795
|
+
break;
|
|
1796
|
+
}
|
|
1797
|
+
if (char === 60 /* CharacterCodes.lessThan */) {
|
|
1798
|
+
if (isConflictMarkerTrivia(text, pos)) {
|
|
1799
|
+
pos = scanConflictMarkerTrivia(text, pos, error);
|
|
1800
|
+
return token = 7 /* SyntaxKind.ConflictMarkerTrivia */;
|
|
1801
|
+
}
|
|
1802
|
+
break;
|
|
1803
|
+
}
|
|
1804
|
+
if (char === 62 /* CharacterCodes.greaterThan */) {
|
|
1805
|
+
error(Diagnostics.Unexpected_token_Did_you_mean_or_gt, pos, 1);
|
|
1806
|
+
}
|
|
1807
|
+
if (char === 125 /* CharacterCodes.closeBrace */) {
|
|
1808
|
+
error(Diagnostics.Unexpected_token_Did_you_mean_or_rbrace, pos, 1);
|
|
1809
|
+
}
|
|
1810
|
+
if (lastNonWhitespace > 0)
|
|
1811
|
+
lastNonWhitespace++;
|
|
1812
|
+
// FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces.
|
|
1813
|
+
// i.e (- : whitespace)
|
|
1814
|
+
// <div>----
|
|
1815
|
+
// </div> becomes <div></div>
|
|
1816
|
+
//
|
|
1817
|
+
// <div>----</div> becomes <div>----</div>
|
|
1818
|
+
if (isLineBreak(char) && firstNonWhitespace === 0) {
|
|
1819
|
+
firstNonWhitespace = -1;
|
|
1820
|
+
}
|
|
1821
|
+
else if (!isWhiteSpaceLike(char)) {
|
|
1822
|
+
firstNonWhitespace = pos;
|
|
1823
|
+
}
|
|
1824
|
+
pos++;
|
|
1825
|
+
}
|
|
1826
|
+
const endPosition = lastNonWhitespace === -1 ? pos : lastNonWhitespace;
|
|
1827
|
+
tokenValue = text.substring(startPos, endPosition);
|
|
1828
|
+
return firstNonWhitespace === -1 ? 12 /* SyntaxKind.JsxTextAllWhiteSpaces */ : 11 /* SyntaxKind.JsxText */;
|
|
1829
|
+
}
|
|
1830
|
+
// Scans a JSX identifier; these differ from normal identifiers in that
|
|
1831
|
+
// they allow dashes
|
|
1832
|
+
function scanJsxIdentifier() {
|
|
1833
|
+
if (tokenIsIdentifierOrKeyword(token)) {
|
|
1834
|
+
// An identifier or keyword has already been parsed - check for a `-` and then append it and everything after it to the token
|
|
1835
|
+
// Do note that this means that `scanJsxIdentifier` effectively _mutates_ the visible token without advancing to a new token
|
|
1836
|
+
// Any caller should be expecting this behavior and should only read the pos or token value after calling it.
|
|
1837
|
+
while (pos < end) {
|
|
1838
|
+
const ch = text.charCodeAt(pos);
|
|
1839
|
+
if (ch === 45 /* CharacterCodes.minus */) {
|
|
1840
|
+
tokenValue += "-";
|
|
1841
|
+
pos++;
|
|
1842
|
+
continue;
|
|
1843
|
+
}
|
|
1844
|
+
const oldPos = pos;
|
|
1845
|
+
tokenValue += scanIdentifierParts(); // reuse `scanIdentifierParts` so unicode escapes are handled
|
|
1846
|
+
if (pos === oldPos) {
|
|
1847
|
+
break;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
return token;
|
|
1852
|
+
}
|
|
1853
|
+
function scanJsxAttributeValue() {
|
|
1854
|
+
startPos = pos;
|
|
1855
|
+
switch (text.charCodeAt(pos)) {
|
|
1856
|
+
case 34 /* CharacterCodes.doubleQuote */:
|
|
1857
|
+
case 39 /* CharacterCodes.singleQuote */:
|
|
1858
|
+
tokenValue = scanString(/*jsxAttributeString*/ true);
|
|
1859
|
+
return token = 10 /* SyntaxKind.StringLiteral */;
|
|
1860
|
+
default:
|
|
1861
|
+
// If this scans anything other than `{`, it's a parse error.
|
|
1862
|
+
return scan();
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
function reScanJsxAttributeValue() {
|
|
1866
|
+
pos = tokenPos = startPos;
|
|
1867
|
+
return scanJsxAttributeValue();
|
|
1868
|
+
}
|
|
1869
|
+
function speculationHelper(callback, isLookahead) {
|
|
1870
|
+
const savePos = pos;
|
|
1871
|
+
const saveStartPos = startPos;
|
|
1872
|
+
const saveTokenPos = tokenPos;
|
|
1873
|
+
const saveToken = token;
|
|
1874
|
+
const saveTokenValue = tokenValue;
|
|
1875
|
+
const saveTokenFlags = tokenFlags;
|
|
1876
|
+
const result = callback();
|
|
1877
|
+
// If our callback returned something 'falsy' or we're just looking ahead,
|
|
1878
|
+
// then unconditionally restore us to where we were.
|
|
1879
|
+
if (!result || isLookahead) {
|
|
1880
|
+
pos = savePos;
|
|
1881
|
+
startPos = saveStartPos;
|
|
1882
|
+
tokenPos = saveTokenPos;
|
|
1883
|
+
token = saveToken;
|
|
1884
|
+
tokenValue = saveTokenValue;
|
|
1885
|
+
tokenFlags = saveTokenFlags;
|
|
1886
|
+
}
|
|
1887
|
+
return result;
|
|
1888
|
+
}
|
|
1889
|
+
function scanRange(start, length, callback) {
|
|
1890
|
+
const saveEnd = end;
|
|
1891
|
+
const savePos = pos;
|
|
1892
|
+
const saveStartPos = startPos;
|
|
1893
|
+
const saveTokenPos = tokenPos;
|
|
1894
|
+
const saveToken = token;
|
|
1895
|
+
const saveTokenValue = tokenValue;
|
|
1896
|
+
const saveTokenFlags = tokenFlags;
|
|
1897
|
+
const saveErrorExpectations = commentDirectives;
|
|
1898
|
+
setText(text, start, length);
|
|
1899
|
+
const result = callback();
|
|
1900
|
+
end = saveEnd;
|
|
1901
|
+
pos = savePos;
|
|
1902
|
+
startPos = saveStartPos;
|
|
1903
|
+
tokenPos = saveTokenPos;
|
|
1904
|
+
token = saveToken;
|
|
1905
|
+
tokenValue = saveTokenValue;
|
|
1906
|
+
tokenFlags = saveTokenFlags;
|
|
1907
|
+
commentDirectives = saveErrorExpectations;
|
|
1908
|
+
return result;
|
|
1909
|
+
}
|
|
1910
|
+
function lookAhead(callback) {
|
|
1911
|
+
return speculationHelper(callback, /*isLookahead*/ true);
|
|
1912
|
+
}
|
|
1913
|
+
function tryScan(callback) {
|
|
1914
|
+
return speculationHelper(callback, /*isLookahead*/ false);
|
|
1915
|
+
}
|
|
1916
|
+
function getText() {
|
|
1917
|
+
return text;
|
|
1918
|
+
}
|
|
1919
|
+
function clearCommentDirectives() {
|
|
1920
|
+
commentDirectives = undefined;
|
|
1921
|
+
}
|
|
1922
|
+
function setText(newText, start, length) {
|
|
1923
|
+
text = newText || "";
|
|
1924
|
+
end = length === undefined ? text.length : start + length;
|
|
1925
|
+
setTextPos(start || 0);
|
|
1926
|
+
}
|
|
1927
|
+
function setOnError(errorCallback) {
|
|
1928
|
+
onError = errorCallback;
|
|
1929
|
+
}
|
|
1930
|
+
function setScriptTarget(scriptTarget) {
|
|
1931
|
+
languageVersion = scriptTarget;
|
|
1932
|
+
}
|
|
1933
|
+
function setLanguageVariant(variant) {
|
|
1934
|
+
languageVariant = variant;
|
|
1935
|
+
}
|
|
1936
|
+
function setTextPos(textPos) {
|
|
1937
|
+
Debug.assert(textPos >= 0);
|
|
1938
|
+
pos = textPos;
|
|
1939
|
+
startPos = textPos;
|
|
1940
|
+
tokenPos = textPos;
|
|
1941
|
+
token = 0 /* SyntaxKind.Unknown */;
|
|
1942
|
+
tokenValue = undefined;
|
|
1943
|
+
tokenFlags = 0 /* TokenFlags.None */;
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
const codePointAt = String.prototype.codePointAt ? (s, i) => s.codePointAt(i) : function codePointAt(str, i) {
|
|
1947
|
+
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt
|
|
1948
|
+
const size = str.length;
|
|
1949
|
+
// Account for out-of-bounds indices:
|
|
1950
|
+
if (i < 0 || i >= size) {
|
|
1951
|
+
return undefined; // String.codePointAt returns `undefined` for OOB indexes
|
|
1952
|
+
}
|
|
1953
|
+
// Get the first code unit
|
|
1954
|
+
const first = str.charCodeAt(i);
|
|
1955
|
+
// check if it’s the start of a surrogate pair
|
|
1956
|
+
if (first >= 0xD800 && first <= 0xDBFF && size > i + 1) { // high surrogate and there is a next code unit
|
|
1957
|
+
const second = str.charCodeAt(i + 1);
|
|
1958
|
+
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
|
|
1959
|
+
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
|
1960
|
+
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
return first;
|
|
1964
|
+
};
|
|
1965
|
+
function charSize(ch) {
|
|
1966
|
+
if (ch >= 0x10000) {
|
|
1967
|
+
return 2;
|
|
1968
|
+
}
|
|
1969
|
+
return 1;
|
|
1970
|
+
}
|
|
1971
|
+
// Derived from the 10.1.1 UTF16Encoding of the ES6 Spec.
|
|
1972
|
+
function utf16EncodeAsStringFallback(codePoint) {
|
|
1973
|
+
Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF);
|
|
1974
|
+
if (codePoint <= 65535) {
|
|
1975
|
+
return String.fromCharCode(codePoint);
|
|
1976
|
+
}
|
|
1977
|
+
const codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800;
|
|
1978
|
+
const codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00;
|
|
1979
|
+
return String.fromCharCode(codeUnit1, codeUnit2);
|
|
1980
|
+
}
|
|
1981
|
+
const utf16EncodeAsStringWorker = String.fromCodePoint ? codePoint => String.fromCodePoint(codePoint) : utf16EncodeAsStringFallback;
|
|
1982
|
+
export function utf16EncodeAsString(codePoint) {
|
|
1983
|
+
return utf16EncodeAsStringWorker(codePoint);
|
|
1984
|
+
}
|