@lvce-editor/shared-process 0.18.8 → 0.18.9

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.
Files changed (187) hide show
  1. package/package.json +4 -4
  2. package/src/parts/ExportStatic/ExportStatic.js +5 -5
  3. package/src/parts/Platform/Platform.js +3 -3
  4. package/extensions/builtin.language-basics-bat/README.md +0 -14
  5. package/extensions/builtin.language-basics-bat/extension.json +0 -12
  6. package/extensions/builtin.language-basics-bat/src/tokenizeBat.js +0 -33
  7. package/extensions/builtin.language-basics-c/README.md +0 -14
  8. package/extensions/builtin.language-basics-c/extension.json +0 -12
  9. package/extensions/builtin.language-basics-c/src/tokenizeC.js +0 -211
  10. package/extensions/builtin.language-basics-coffeescript/README.md +0 -14
  11. package/extensions/builtin.language-basics-coffeescript/extension.json +0 -12
  12. package/extensions/builtin.language-basics-coffeescript/src/tokenizeCoffeeScript.js +0 -257
  13. package/extensions/builtin.language-basics-cpp/README.md +0 -14
  14. package/extensions/builtin.language-basics-cpp/extension.json +0 -32
  15. package/extensions/builtin.language-basics-cpp/languageConfiguration.json +0 -5
  16. package/extensions/builtin.language-basics-cpp/src/tokenizeCpp.js +0 -317
  17. package/extensions/builtin.language-basics-cson/README.md +0 -16
  18. package/extensions/builtin.language-basics-cson/extension.json +0 -13
  19. package/extensions/builtin.language-basics-cson/languageConfiguration.json +0 -21
  20. package/extensions/builtin.language-basics-cson/src/tokenizeCson.js +0 -207
  21. package/extensions/builtin.language-basics-css/README.md +0 -16
  22. package/extensions/builtin.language-basics-css/extension.json +0 -13
  23. package/extensions/builtin.language-basics-css/languageConfiguration.json +0 -21
  24. package/extensions/builtin.language-basics-css/src/tokenizeCss.js +0 -659
  25. package/extensions/builtin.language-basics-dart/README.md +0 -14
  26. package/extensions/builtin.language-basics-dart/extension.json +0 -12
  27. package/extensions/builtin.language-basics-dart/src/tokenizeDart.js +0 -133
  28. package/extensions/builtin.language-basics-desktop/README.md +0 -14
  29. package/extensions/builtin.language-basics-desktop/extension.json +0 -12
  30. package/extensions/builtin.language-basics-desktop/src/tokenizeDesktop.js +0 -166
  31. package/extensions/builtin.language-basics-docker/README.md +0 -14
  32. package/extensions/builtin.language-basics-docker/extension.json +0 -24
  33. package/extensions/builtin.language-basics-docker/src/tokenizeDockerfile.js +0 -131
  34. package/extensions/builtin.language-basics-dotenv/README.md +0 -14
  35. package/extensions/builtin.language-basics-dotenv/extension.json +0 -26
  36. package/extensions/builtin.language-basics-dotenv/src/tokenizeDotenv.js +0 -301
  37. package/extensions/builtin.language-basics-editorconfig/README.md +0 -14
  38. package/extensions/builtin.language-basics-editorconfig/extension.json +0 -12
  39. package/extensions/builtin.language-basics-editorconfig/src/tokenizeEditorConfig.js +0 -173
  40. package/extensions/builtin.language-basics-elixir/README.md +0 -14
  41. package/extensions/builtin.language-basics-elixir/extension.json +0 -12
  42. package/extensions/builtin.language-basics-elixir/src/tokenizeElixir.js +0 -150
  43. package/extensions/builtin.language-basics-elm/README.md +0 -14
  44. package/extensions/builtin.language-basics-elm/extension.json +0 -12
  45. package/extensions/builtin.language-basics-elm/src/tokenizeElm.js +0 -298
  46. package/extensions/builtin.language-basics-gitattributes/README.md +0 -14
  47. package/extensions/builtin.language-basics-gitattributes/extension.json +0 -12
  48. package/extensions/builtin.language-basics-gitattributes/src/tokenizeGitAttributes.js +0 -159
  49. package/extensions/builtin.language-basics-gn/README.md +0 -14
  50. package/extensions/builtin.language-basics-gn/extension.json +0 -12
  51. package/extensions/builtin.language-basics-gn/src/tokenizeGn.js +0 -178
  52. package/extensions/builtin.language-basics-go/README.md +0 -14
  53. package/extensions/builtin.language-basics-go/extension.json +0 -13
  54. package/extensions/builtin.language-basics-go/src/tokenizeGo.js +0 -295
  55. package/extensions/builtin.language-basics-graphql/README.md +0 -14
  56. package/extensions/builtin.language-basics-graphql/extension.json +0 -12
  57. package/extensions/builtin.language-basics-graphql/src/tokenizeGraphql.js +0 -432
  58. package/extensions/builtin.language-basics-html/README.md +0 -14
  59. package/extensions/builtin.language-basics-html/extension.json +0 -13
  60. package/extensions/builtin.language-basics-html/languageConfiguration.json +0 -66
  61. package/extensions/builtin.language-basics-html/src/tokenizeHtml.js +0 -551
  62. package/extensions/builtin.language-basics-java/README.md +0 -14
  63. package/extensions/builtin.language-basics-java/extension.json +0 -13
  64. package/extensions/builtin.language-basics-java/languageConfiguration.json +0 -31
  65. package/extensions/builtin.language-basics-java/src/tokenizeJava.js +0 -253
  66. package/extensions/builtin.language-basics-javascript/README.md +0 -14
  67. package/extensions/builtin.language-basics-javascript/extension.json +0 -14
  68. package/extensions/builtin.language-basics-javascript/languageConfiguration.json +0 -40
  69. package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +0 -614
  70. package/extensions/builtin.language-basics-json/README.md +0 -14
  71. package/extensions/builtin.language-basics-json/extension.json +0 -60
  72. package/extensions/builtin.language-basics-json/src/tokenizeJson.js +0 -356
  73. package/extensions/builtin.language-basics-jsx/README.md +0 -14
  74. package/extensions/builtin.language-basics-jsx/extension.json +0 -13
  75. package/extensions/builtin.language-basics-jsx/src/tokenizeJsx.js +0 -661
  76. package/extensions/builtin.language-basics-julia/README.md +0 -18
  77. package/extensions/builtin.language-basics-julia/extension.json +0 -12
  78. package/extensions/builtin.language-basics-julia/src/tokenizeJulia.js +0 -181
  79. package/extensions/builtin.language-basics-kotlin/README.md +0 -14
  80. package/extensions/builtin.language-basics-kotlin/extension.json +0 -12
  81. package/extensions/builtin.language-basics-kotlin/src/tokenizeKotlin.js +0 -274
  82. package/extensions/builtin.language-basics-less/LICENSE +0 -21
  83. package/extensions/builtin.language-basics-less/README.md +0 -14
  84. package/extensions/builtin.language-basics-less/extension.json +0 -12
  85. package/extensions/builtin.language-basics-less/languageConfiguration.json +0 -17
  86. package/extensions/builtin.language-basics-less/src/tokenizeLess.js +0 -609
  87. package/extensions/builtin.language-basics-markdown/README.md +0 -14
  88. package/extensions/builtin.language-basics-markdown/extension.json +0 -12
  89. package/extensions/builtin.language-basics-markdown/src/tokenizeMarkdown.js +0 -441
  90. package/extensions/builtin.language-basics-mdx/README.md +0 -14
  91. package/extensions/builtin.language-basics-mdx/extension.json +0 -12
  92. package/extensions/builtin.language-basics-mdx/src/tokenizeMdx.js +0 -395
  93. package/extensions/builtin.language-basics-nvmrc/README.md +0 -14
  94. package/extensions/builtin.language-basics-nvmrc/extension.json +0 -12
  95. package/extensions/builtin.language-basics-nvmrc/src/tokenizeNvmrc.js +0 -30
  96. package/extensions/builtin.language-basics-perl/README.md +0 -14
  97. package/extensions/builtin.language-basics-perl/extension.json +0 -13
  98. package/extensions/builtin.language-basics-perl/src/tokenizePerl.js +0 -200
  99. package/extensions/builtin.language-basics-plaintext/README.md +0 -14
  100. package/extensions/builtin.language-basics-plaintext/extension.json +0 -12
  101. package/extensions/builtin.language-basics-plaintext/src/tokenizePlaintext.js +0 -28
  102. package/extensions/builtin.language-basics-powershell/README.md +0 -14
  103. package/extensions/builtin.language-basics-powershell/extension.json +0 -12
  104. package/extensions/builtin.language-basics-powershell/src/tokenizePowershell.js +0 -141
  105. package/extensions/builtin.language-basics-python/README.md +0 -14
  106. package/extensions/builtin.language-basics-python/extension.json +0 -15
  107. package/extensions/builtin.language-basics-python/languageConfiguration.json +0 -5
  108. package/extensions/builtin.language-basics-python/src/tokenizePython.js +0 -304
  109. package/extensions/builtin.language-basics-r/README.md +0 -14
  110. package/extensions/builtin.language-basics-r/extension.json +0 -12
  111. package/extensions/builtin.language-basics-r/src/tokenizeR.js +0 -71
  112. package/extensions/builtin.language-basics-ruby/README.md +0 -14
  113. package/extensions/builtin.language-basics-ruby/extension.json +0 -48
  114. package/extensions/builtin.language-basics-ruby/src/tokenizeRuby.js +0 -248
  115. package/extensions/builtin.language-basics-rust/LICENSE +0 -21
  116. package/extensions/builtin.language-basics-rust/README.md +0 -14
  117. package/extensions/builtin.language-basics-rust/extension.json +0 -12
  118. package/extensions/builtin.language-basics-rust/languageConfiguration.json +0 -17
  119. package/extensions/builtin.language-basics-rust/src/tokenizeRust.js +0 -158
  120. package/extensions/builtin.language-basics-scss/README.md +0 -14
  121. package/extensions/builtin.language-basics-scss/extension.json +0 -12
  122. package/extensions/builtin.language-basics-scss/src/tokenizeScss.js +0 -28
  123. package/extensions/builtin.language-basics-shellscript/README.md +0 -14
  124. package/extensions/builtin.language-basics-shellscript/extension.json +0 -56
  125. package/extensions/builtin.language-basics-shellscript/src/tokenizeShellScript.js +0 -569
  126. package/extensions/builtin.language-basics-svelte/README.md +0 -14
  127. package/extensions/builtin.language-basics-svelte/extension.json +0 -13
  128. package/extensions/builtin.language-basics-svelte/src/tokenizeSvelte.js +0 -428
  129. package/extensions/builtin.language-basics-toml/README.md +0 -14
  130. package/extensions/builtin.language-basics-toml/extension.json +0 -14
  131. package/extensions/builtin.language-basics-toml/src/tokenizeToml.js +0 -299
  132. package/extensions/builtin.language-basics-typescript/README.md +0 -14
  133. package/extensions/builtin.language-basics-typescript/extension.json +0 -17
  134. package/extensions/builtin.language-basics-typescript/src/tokenizeTypeScript.js +0 -1602
  135. package/extensions/builtin.language-basics-vue/README.md +0 -14
  136. package/extensions/builtin.language-basics-vue/extension.json +0 -13
  137. package/extensions/builtin.language-basics-vue/src/tokenizeVue.js +0 -327
  138. package/extensions/builtin.language-basics-wgsl/README.md +0 -16
  139. package/extensions/builtin.language-basics-wgsl/extension.json +0 -13
  140. package/extensions/builtin.language-basics-wgsl/languageConfiguration.json +0 -21
  141. package/extensions/builtin.language-basics-wgsl/src/tokenizeWgsl.js +0 -226
  142. package/extensions/builtin.language-basics-xml/README.md +0 -14
  143. package/extensions/builtin.language-basics-xml/extension.json +0 -85
  144. package/extensions/builtin.language-basics-xml/src/tokenizeXml.js +0 -328
  145. package/extensions/builtin.language-basics-yaml/README.md +0 -14
  146. package/extensions/builtin.language-basics-yaml/extension.json +0 -13
  147. package/extensions/builtin.language-basics-yaml/src/tokenizeYaml.js +0 -405
  148. package/extensions/builtin.theme-atom-one-dark/README.md +0 -11
  149. package/extensions/builtin.theme-atom-one-dark/color-theme.json +0 -216
  150. package/extensions/builtin.theme-atom-one-dark/extension.json +0 -12
  151. package/extensions/builtin.theme-atom-one-dark/images/demo.png +0 -0
  152. package/extensions/builtin.theme-ayu/README.md +0 -11
  153. package/extensions/builtin.theme-ayu/color-theme.json +0 -217
  154. package/extensions/builtin.theme-ayu/extension.json +0 -12
  155. package/extensions/builtin.theme-cobalt2/README.md +0 -20
  156. package/extensions/builtin.theme-cobalt2/color-theme.json +0 -202
  157. package/extensions/builtin.theme-cobalt2/extension.json +0 -13
  158. package/extensions/builtin.theme-cobalt2/images/demo.png +0 -0
  159. package/extensions/builtin.theme-cobalt2/images/logo.png +0 -0
  160. package/extensions/builtin.theme-gruvbox/README.md +0 -20
  161. package/extensions/builtin.theme-gruvbox/color-theme.json +0 -217
  162. package/extensions/builtin.theme-gruvbox/extension.json +0 -12
  163. package/extensions/builtin.theme-high-contrast/README.md +0 -9
  164. package/extensions/builtin.theme-high-contrast/color-theme.json +0 -86
  165. package/extensions/builtin.theme-high-contrast/extension.json +0 -11
  166. package/extensions/builtin.theme-material/README.md +0 -9
  167. package/extensions/builtin.theme-material/color-theme.json +0 -183
  168. package/extensions/builtin.theme-material/extension.json +0 -12
  169. package/extensions/builtin.theme-monokai/README.md +0 -10
  170. package/extensions/builtin.theme-monokai/color-theme.json +0 -151
  171. package/extensions/builtin.theme-monokai/extension.json +0 -11
  172. package/extensions/builtin.theme-noctis-uva/README.md +0 -11
  173. package/extensions/builtin.theme-noctis-uva/color-theme.json +0 -204
  174. package/extensions/builtin.theme-noctis-uva/extension.json +0 -12
  175. package/extensions/builtin.theme-noctis-uva/images/demo.png +0 -0
  176. package/extensions/builtin.theme-palenight/README.md +0 -11
  177. package/extensions/builtin.theme-palenight/color-theme.json +0 -209
  178. package/extensions/builtin.theme-palenight/extension.json +0 -12
  179. package/extensions/builtin.theme-palenight/images/demo.png +0 -0
  180. package/extensions/builtin.theme-slime/README.md +0 -5
  181. package/extensions/builtin.theme-slime/color-theme.json +0 -290
  182. package/extensions/builtin.theme-slime/extension.json +0 -13
  183. package/extensions/builtin.theme-slime/icon.png +0 -0
  184. package/extensions/builtin.vscode-icons/README.md +0 -20
  185. package/extensions/builtin.vscode-icons/extension.json +0 -13
  186. package/extensions/builtin.vscode-icons/icon-theme.json +0 -3815
  187. package/extensions/builtin.vscode-icons/icon.png +0 -0
@@ -1,1602 +0,0 @@
1
- /**
2
- * @enum number
3
- */
4
- const State = {
5
- None: 0,
6
- TopLevelContent: 1,
7
- InsideSingleQuoteString: 2,
8
- InsideDoubleQuoteString: 3,
9
- AfterKeywordVariableDeclaration: 4,
10
- BeforeValue: 5,
11
- AfterKeywordTypeDeclaration: 8,
12
- BeforeType: 9,
13
- AfterKeywordDeclare: 10,
14
- InsideBlockComment: 11,
15
- InsideLineComment: 12,
16
- AfterKeywordClass: 13,
17
- AfterKeywordClassAfterClassName: 14,
18
- InsideClass: 15,
19
- AfterType: 16,
20
- InsideTypeExpression: 17,
21
- AfterTypeExpression: 18,
22
- AfterVariableName: 19,
23
- BeforePropertyAccess: 20,
24
- AfterKeywordEnum: 21,
25
- AfterKeywordEnumAfterVariableName: 22,
26
- InsideEnum: 23,
27
- InsideEnumAfterVariableName: 24,
28
- InsideObjectDestructuring: 25,
29
- InsideObjectDestructuringAfterValue: 26,
30
- AfterKeywordInterface: 27,
31
- InsideTypeObject: 28,
32
- AfterMethodName: 29,
33
- InsideMethodParameters: 30,
34
- InsideMethodParametersAfterVariableName: 31,
35
- AfterMethodParameters: 32,
36
- AfterPropertyDot: 33,
37
- InsideBacktickString: 34,
38
- AfterInterfaceName: 35,
39
- AfterKeywordImport: 36,
40
- AfterKeywordFunction: 37,
41
- InsideGeneric: 38,
42
- AfterTypeAfterNewLine: 39,
43
- AfterKeywordInstanceOf: 40,
44
- AfterKeywordNew: 41,
45
- AfterKeywordTypeOf: 42,
46
- }
47
-
48
- /**
49
- * @enum number
50
- */
51
- export const TokenType = {
52
- None: 99999999,
53
- Keyword: 951,
54
- Whitespace: 0,
55
- NewLine: 771,
56
- VariableName: 2,
57
- Punctuation: 3,
58
- String: 4,
59
- Numeric: 5,
60
- TypePrimitive: 6,
61
- LanguageConstant: 7,
62
- KeywordImport: 8,
63
- KeywordControl: 9,
64
- KeywordModifier: 10,
65
- KeywordReturn: 11,
66
- KeywordNew: 12,
67
- Type: 13,
68
- KeywordDeclare: 14,
69
- Comment: 15,
70
- Regex: 16,
71
- Class: 17,
72
- StorageModifier: 18,
73
- KeywordVoid: 19,
74
- Function: 20,
75
- FunctionName: 21,
76
- KeywordOperator: 22,
77
- Text: 23,
78
- KeywordThis: 24,
79
- KeywordAwait: 25,
80
- }
81
-
82
- export const TokenMap = {
83
- [TokenType.None]: 'None',
84
- [TokenType.Keyword]: 'Keyword',
85
- [TokenType.Whitespace]: 'Whitespace',
86
- [TokenType.NewLine]: 'NewLine',
87
- [TokenType.VariableName]: 'VariableName',
88
- [TokenType.Punctuation]: 'Punctuation',
89
- [TokenType.String]: 'String',
90
- [TokenType.Numeric]: 'Numeric',
91
- [TokenType.TypePrimitive]: 'TypePrimitive',
92
- [TokenType.LanguageConstant]: 'LanguageConstant',
93
- [TokenType.KeywordImport]: 'KeywordImport',
94
- [TokenType.KeywordControl]: 'KeywordControl',
95
- [TokenType.KeywordModifier]: 'KeywordModifier',
96
- [TokenType.KeywordReturn]: 'KeywordReturn',
97
- [TokenType.KeywordNew]: 'KeywordNew',
98
- [TokenType.Type]: 'Type',
99
- [TokenType.KeywordDeclare]: 'KeywordDeclare',
100
- [TokenType.Comment]: 'Comment',
101
- [TokenType.Regex]: 'Regex',
102
- [TokenType.Class]: 'Class',
103
- [TokenType.StorageModifier]: 'StorageModifier',
104
- [TokenType.KeywordVoid]: 'KeywordVoid',
105
- [TokenType.Function]: 'Function',
106
- [TokenType.FunctionName]: 'Function',
107
- [TokenType.KeywordOperator]: 'KeywordOperator',
108
- [TokenType.Text]: 'Text',
109
- [TokenType.KeywordThis]: 'KeywordThis',
110
- [TokenType.KeywordAwait]: 'KeywordAwait',
111
- }
112
-
113
- export const initialLineState = {
114
- state: State.TopLevelContent,
115
- /**
116
- * @type {any[]}
117
- */
118
- stack: [],
119
- }
120
-
121
- const RE_LINE_COMMENT = /^\/\/[^\n]*/
122
- const RE_KEYWORD =
123
- /^(?:yield|with|while|void|var|undefined|typeof|type|true|try|throw|this|static|switch|super|readonly|return|public|protected|private|package|null|new|let|interface|instanceof|in|import|implements|if|function|for|finally|from|false|extends|export|enum|else|do|delete|default|debugger|declare|continue|const|constructor|class|catch|case|break|await|async|accessor|abstract)\b/
124
-
125
- const RE_WHITESPACE = /^\s+/
126
- const RE_VARIABLE_NAME = /^[\#\$a-zA-Z\_][\$a-zA-Z\_\d]*/
127
- const RE_PUNCTUATION = /^[:,;\{\}\[\]\.=\(\)>\+\-\*]/
128
- const RE_QUOTE_SINGLE = /^'/
129
- const RE_QUOTE_DOUBLE = /^"/
130
- const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^\\']+/
131
- const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^\\"]+/
132
- const RE_NUMERIC = /^(?:-)?\d+/
133
- const RE_COLON = /^\:/
134
- const RE_COLON_OPTIONAL = /^\??\:/
135
- const RE_TYPE_PRIMITIVE =
136
- /^(?:string|boolean|number|bigint|symbol|void|any|null|undefined|object|true|false|unknown)\b/
137
-
138
- const RE_EQUAL = /^=/
139
- const RE_SEMICOLON = /^;/
140
- const RE_KEYWORD_CONST = /^(?:const)/
141
- const RE_KEYWORD_LET = /^(?:let)/
142
- const RE_KEYWORD_ENUM = /^(?:enum)/
143
- const RE_KEYWORD_CLASS = /^(?:class)/
144
- const RE_LINE_COMMENT_START = /^\/\//
145
- const RE_LINE_COMMENT_CONTENT = /^[^\n]+/
146
- const RE_NEWLINE_WHITESPACE = /^\n\s*/
147
- const RE_BLOCK_COMMENT_START = /^\/\*/
148
- const RE_BLOCK_COMMENT_CONTENT = /^.+?(?=\*\/)/
149
- const RE_BLOCK_COMMENT_END = /^\*\//
150
- const RE_SLASH = /^\//
151
- // copied from https://github.com/PrismJS/prism/blob/master/components/prism-javascript.js#L57
152
- const RE_REGEX =
153
- /((?:^|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/
154
- const RE_ANYTHING_UNTIL_END = /^.+/s
155
- const RE_CURLY_OPEN = /^\{/
156
- const RE_CURLY_CLOSE = /^\}/
157
- const RE_KEYWORD_CLASS_PROPERTY_MODIFIER =
158
- /^(?:override|public|protected|private|readonly|accessor)\b/
159
-
160
- const RE_VERTICAL_LINE = /^\|/
161
- const RE_ROUND_OPEN = /^\(/
162
- const RE_ROUND_CLOSE = /^\)/
163
- const RE_QUESTION_MARK_COLON = /^\?\:/
164
- const RE_EXLAMATION_MARK_COLON = /^\!\:/
165
- const RE_ARROW = /^\=\>/
166
- const RE_AMPERSAND = /^\&/
167
- const RE_COMMA = /^\,/
168
- const RE_DOT = /^\./
169
- const RE_SQUARE_OPEN = /^\[/
170
- const RE_SQUARE_CLOSE = /^\]/
171
- const RE_QUESTION_MARK = /^\?/
172
- const RE_EXCLAMATION_MARK = /^\!/
173
- const RE_STAR = /^\*/
174
- const RE_AS = /^as/
175
- const RE_ESCAPE = /^\\.?/
176
- const RE_ANGLE_OPEN = /^</
177
- const RE_ANGLE_CLOSE = /^>/
178
- const RE_OPERATOR = /^[!\*\?\.\:\|\%\&\^@]/
179
- const RE_METHOD_NAME = /^[\w\d]+(?=\s*(\(|\:\s*function|\:\s*\())/
180
- const RE_FUNCTION_CALL_NAME = /^[\w]+(?=\s*(\(|\=\s*function|\=\s*\())/
181
-
182
- const RE_NUMERIC_2 =
183
- /^(?:(?:[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|(?:[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|(?:(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|(?:[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|(?:[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|(?:[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|(?:[0-9][0-9_]*(\.)(n)?\B)|(?:(\.)[0-9][0-9_]*(n)?\b)|(?:[0-9][0-9_]*(n)?\b(?!\.))|(?:0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b)|(?:0(?:b|B)[01][01_]*(n)?\b)|(?:0(?:o|O)?[0-7][0-7_]*(n)?\b))/ // 1.1E+3
184
- const RE_NUMERIC_HEX = /0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b/
185
- const RE_NUMERIC_BINARY = /0(?:b|B)[01][01_]*(n)?\b/
186
- const RE_NUMERIC_OCTAL = /0(?:o|O)?[0-7][0-7_]*(n)?\b/
187
- const RE_QUOTE_BACKTICK = /^`/
188
- const RE_STRING_BACKTICK_QUOTE_CONTENT = /^[^`\\]+/
189
- const RE_STRING_ESCAPE = /^\\./
190
- const RE_KEYWORD_TYPE = /^type\b/
191
- const RE_KEYWORD_IN = /^in\b/
192
- const RE_KEYWORD_OF = /^of\b/
193
- const RE_KEYWORD_CONSTRUCTOR = /^constructor\b/
194
- const RE_KEYWORD_EXTENDS = /^extends\b/
195
- const RE_KEYWORD_READONLY = /^readonly\b/
196
- const RE_SHEBANG = /^\#\!\/.*/
197
- const RE_SPREAD = /^\.\.\./
198
- const RE_BUILTIN_CLASS =
199
- /^(?:Array|Object|Promise|ArrayBuffer|URL|URLSearchParams|WebSocket|FileSystemHandle|Function|StorageEvent|MessageEvent|MessageChannel|Int32Array|Boolean|String|Error|Set|RegExp|Map|WeakMap|RangeError|Date|Headers|Response|Request|Buffer|MessagePort|FileHandle|X509Certificate|Blob|HTMLElement|MutationRecord|HTMLVideoElement)\b/
200
-
201
- const RE_KEYWORD_NEW = /^new\b/
202
- const RE_KEYWORD_IMPLEMENTS = /^implements\b/
203
- const RE_KEYWORD_TYPE_OF = /^typeof\b/
204
- const RE_ANYTHING_BUT_SEMICOLON_UNTIL_END = /^[^;]+/s
205
-
206
- export const hasArrayReturn = true
207
- /**
208
- *
209
- * @param {string} line
210
- * @param {any} lineState
211
- * @returns
212
- */
213
- export const tokenizeLine = (line, lineState) => {
214
- let next = null
215
- let index = 0
216
- let tokens = []
217
- let token = TokenType.None
218
- let state = lineState.state
219
- let stack = lineState.stack
220
- while (index < line.length) {
221
- const part = line.slice(index)
222
- switch (state) {
223
- case State.TopLevelContent:
224
- if ((next = part.match(RE_WHITESPACE))) {
225
- token = TokenType.Whitespace
226
- state = State.TopLevelContent
227
- } else if ((next = part.match(RE_KEYWORD))) {
228
- switch (next[0]) {
229
- case 'true':
230
- case 'false':
231
- case 'null':
232
- case 'undefined':
233
- token = TokenType.LanguageConstant
234
- state = State.TopLevelContent
235
- break
236
- case 'import':
237
- token = TokenType.KeywordImport
238
- state = State.AfterKeywordImport
239
- break
240
- case 'export':
241
- case 'from':
242
- token = TokenType.KeywordImport
243
- state = State.TopLevelContent
244
- break
245
- case 'as':
246
- case 'break':
247
- case 'case':
248
- case 'catch':
249
- case 'continue':
250
- case 'default':
251
- case 'do':
252
- case 'else':
253
- case 'finally':
254
- case 'for':
255
- case 'if':
256
- case 'switch':
257
- case 'throw':
258
- case 'try':
259
- case 'while':
260
- token = TokenType.KeywordControl
261
- state = State.TopLevelContent
262
- break
263
- case 'async':
264
- token = TokenType.KeywordModifier
265
- state = State.TopLevelContent
266
- break
267
- case 'await':
268
- token = TokenType.KeywordAwait
269
- state = State.TopLevelContent
270
- break
271
- case 'return':
272
- token = TokenType.KeywordReturn
273
- state = State.TopLevelContent
274
- break
275
- case 'new':
276
- token = TokenType.KeywordNew
277
- state = State.AfterKeywordNew
278
- break
279
- case 'let':
280
- case 'const':
281
- case 'var':
282
- token = TokenType.Keyword
283
- state = State.AfterKeywordVariableDeclaration
284
- break
285
- case 'type':
286
- token = TokenType.Keyword
287
- state = State.AfterKeywordTypeDeclaration
288
- break
289
- case 'declare':
290
- token = TokenType.KeywordDeclare
291
- state = State.AfterKeywordDeclare
292
- break
293
- case 'void':
294
- token = TokenType.KeywordVoid
295
- state = State.TopLevelContent
296
- break
297
- case 'interface':
298
- token = TokenType.Keyword
299
- state = State.AfterKeywordInterface
300
- break
301
- case 'private':
302
- case 'protected':
303
- case 'readonly':
304
- case 'public':
305
- case 'override':
306
- case 'abstract':
307
- case 'static':
308
- token = TokenType.KeywordModifier
309
- state = State.TopLevelContent
310
- break
311
- case 'in':
312
- case 'of':
313
- case 'typeof':
314
- token = TokenType.KeywordOperator
315
- state = State.TopLevelContent
316
- break
317
- case 'instanceof':
318
- token = TokenType.KeywordOperator
319
- state = State.AfterKeywordInstanceOf
320
- break
321
- case 'function':
322
- token = TokenType.Keyword
323
- state = State.AfterKeywordFunction
324
- break
325
- case 'this':
326
- token = TokenType.KeywordThis
327
- state = State.TopLevelContent
328
- break
329
- case 'class':
330
- token = TokenType.Keyword
331
- state = State.AfterKeywordClass
332
- break
333
- default:
334
- token = TokenType.Keyword
335
- state = State.TopLevelContent
336
- break
337
- }
338
- } else if (index === 0 && (next = part.match(RE_SHEBANG))) {
339
- token = TokenType.Comment
340
- state = State.TopLevelContent
341
- } else if ((next = part.match(RE_BUILTIN_CLASS))) {
342
- token = TokenType.Class
343
- state = State.TopLevelContent
344
- } else if ((next = part.match(RE_FUNCTION_CALL_NAME))) {
345
- token = TokenType.Function
346
- state = State.TopLevelContent
347
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
348
- token = TokenType.VariableName
349
- state = State.TopLevelContent
350
- } else if ((next = part.match(RE_SLASH))) {
351
- if ((next = part.match(RE_BLOCK_COMMENT_START))) {
352
- token = TokenType.Comment
353
- state = State.InsideBlockComment
354
- } else if ((next = part.match(RE_LINE_COMMENT_START))) {
355
- token = TokenType.Comment
356
- state = State.InsideLineComment
357
- } else if ((next = part.match(RE_REGEX))) {
358
- token = TokenType.Regex
359
- state = State.TopLevelContent
360
- } else if ((next = part.match(RE_PUNCTUATION))) {
361
- token = TokenType.Punctuation
362
- state = State.TopLevelContent
363
- } else {
364
- next = part.match(RE_SLASH)
365
- token = TokenType.Punctuation
366
- state = State.TopLevelContent
367
- }
368
- } else if ((next = part.match(RE_NUMERIC_2))) {
369
- token = TokenType.Numeric
370
- state = State.TopLevelContent
371
- } else if ((next = part.match(RE_PUNCTUATION))) {
372
- token = TokenType.Punctuation
373
- state = State.TopLevelContent
374
- if (next[0] === '.') {
375
- state = State.AfterPropertyDot
376
- }
377
- } else if ((next = part.match(RE_QUOTE_SINGLE))) {
378
- token = TokenType.Punctuation
379
- state = State.InsideSingleQuoteString
380
- } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
381
- token = TokenType.Punctuation
382
- state = State.InsideDoubleQuoteString
383
- } else if ((next = part.match(RE_QUOTE_BACKTICK))) {
384
- token = TokenType.Punctuation
385
- state = State.InsideBacktickString
386
- } else if ((next = part.match(RE_OPERATOR))) {
387
- token = TokenType.Punctuation
388
- state = State.TopLevelContent
389
- } else if ((next = part.match(RE_ANGLE_OPEN))) {
390
- token = TokenType.Punctuation
391
- state = State.TopLevelContent
392
- } else {
393
- part //?
394
- throw new Error('no')
395
- }
396
- break
397
- case State.InsideSingleQuoteString:
398
- if ((next = part.match(RE_QUOTE_SINGLE))) {
399
- token = TokenType.Punctuation
400
- state = stack.pop() || State.TopLevelContent
401
- } else if ((next = part.match(RE_STRING_SINGLE_QUOTE_CONTENT))) {
402
- token = TokenType.String
403
- state = State.InsideSingleQuoteString
404
- } else if ((next = part.match(RE_ESCAPE))) {
405
- token = TokenType.String
406
- state = State.InsideSingleQuoteString
407
- } else {
408
- throw new Error('no')
409
- }
410
- break
411
- case State.InsideDoubleQuoteString:
412
- if ((next = part.match(RE_QUOTE_DOUBLE))) {
413
- token = TokenType.Punctuation
414
- state = stack.pop() || State.TopLevelContent
415
- } else if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
416
- token = TokenType.String
417
- state = State.InsideDoubleQuoteString
418
- } else if ((next = part.match(RE_ESCAPE))) {
419
- token = TokenType.String
420
- state = State.InsideDoubleQuoteString
421
- } else {
422
- throw new Error('no')
423
- }
424
- break
425
- case State.AfterKeywordVariableDeclaration:
426
- if ((next = part.match(RE_WHITESPACE))) {
427
- token = TokenType.Whitespace
428
- state = State.AfterKeywordVariableDeclaration
429
- } else if ((next = part.match(RE_COLON))) {
430
- token = TokenType.Punctuation
431
- state = State.BeforeType
432
- } else if ((next = part.match(RE_KEYWORD_ENUM))) {
433
- token = TokenType.Keyword
434
- state = State.AfterKeywordEnum
435
- } else if ((next = part.match(RE_KEYWORD_IN))) {
436
- token = TokenType.KeywordOperator
437
- state = State.TopLevelContent
438
- } else if ((next = part.match(RE_KEYWORD_OF))) {
439
- token = TokenType.KeywordOperator
440
- state = State.TopLevelContent
441
- } else if ((next = part.match(RE_FUNCTION_CALL_NAME))) {
442
- token = TokenType.FunctionName
443
- state = State.AfterKeywordVariableDeclaration
444
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
445
- token = TokenType.VariableName
446
- state = State.AfterKeywordVariableDeclaration
447
- } else if ((next = part.match(RE_EQUAL))) {
448
- token = TokenType.Punctuation
449
- state = State.TopLevelContent
450
- } else if ((next = part.match(RE_CURLY_OPEN))) {
451
- token = TokenType.Punctuation
452
- state = State.InsideObjectDestructuring
453
- } else if ((next = part.match(RE_DOT))) {
454
- token = TokenType.Punctuation
455
- state = State.TopLevelContent
456
- } else if ((next = part.match(RE_SEMICOLON))) {
457
- token = TokenType.Punctuation
458
- state = State.TopLevelContent
459
- } else if ((next = part.match(RE_COMMA))) {
460
- token = TokenType.Punctuation
461
- state = State.AfterKeywordVariableDeclaration
462
- } else if ((next = part.match(RE_PUNCTUATION))) {
463
- token = TokenType.Punctuation
464
- state = State.AfterKeywordVariableDeclaration
465
- } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
466
- token = TokenType.Punctuation
467
- state = State.InsideDoubleQuoteString
468
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
469
- stack.push(state)
470
- token = TokenType.Comment
471
- state = State.InsideBlockComment
472
- } else if ((next = part.match(RE_EXCLAMATION_MARK))) {
473
- token = TokenType.Punctuation
474
- state = State.AfterVariableName
475
- } else {
476
- line
477
- part
478
- throw new Error('no')
479
- }
480
- break
481
- case State.AfterKeywordTypeDeclaration:
482
- if ((next = part.match(RE_WHITESPACE))) {
483
- token = TokenType.Whitespace
484
- state = State.AfterKeywordTypeDeclaration
485
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
486
- token = TokenType.Type
487
- state = State.AfterKeywordTypeDeclaration
488
- } else if ((next = part.match(RE_EQUAL))) {
489
- token = TokenType.Punctuation
490
- state = State.BeforeType
491
- } else if ((next = part.match(RE_COLON))) {
492
- token = TokenType.Punctuation
493
- state = State.AfterKeywordTypeDeclaration
494
- } else if ((next = part.match(RE_SEMICOLON))) {
495
- token = TokenType.Punctuation
496
- state = stack.pop() || State.TopLevelContent
497
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
498
- token = TokenType.Text
499
- state = stack.pop() || State.TopLevelContent
500
- } else {
501
- part
502
- throw new Error('no')
503
- }
504
- break
505
- case State.BeforeType:
506
- if ((next = part.match(RE_WHITESPACE))) {
507
- token = TokenType.Whitespace
508
- state = State.BeforeType
509
- } else if ((next = part.match(RE_TYPE_PRIMITIVE))) {
510
- token = TokenType.TypePrimitive
511
- state = stack.pop() || State.AfterType
512
- } else if ((next = part.match(RE_BUILTIN_CLASS))) {
513
- token = TokenType.Class
514
- state = stack.pop() || State.AfterType
515
- } else if ((next = part.match(RE_KEYWORD_TYPE_OF))) {
516
- stack.push(state)
517
- token = TokenType.KeywordOperator
518
- state = State.AfterKeywordTypeOf
519
- } else if ((next = part.match(RE_KEYWORD_READONLY))) {
520
- token = TokenType.KeywordModifier
521
- state = State.BeforeType
522
- } else if ((next = part.match(RE_KEYWORD_EXTENDS))) {
523
- token = TokenType.KeywordOperator
524
- state = State.BeforeType
525
- stack.push(state)
526
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
527
- token = TokenType.Type
528
- state = State.AfterType
529
- } else if ((next = part.match(RE_SEMICOLON))) {
530
- token = TokenType.Punctuation
531
- state = stack.pop() || State.TopLevelContent
532
- } else if ((next = part.match(RE_ROUND_OPEN))) {
533
- token = TokenType.Punctuation
534
- state = State.InsideTypeExpression
535
- stack.push(State.AfterTypeExpression)
536
- } else if ((next = part.match(RE_ARROW))) {
537
- token = TokenType.Punctuation
538
- state = State.BeforeType
539
- } else if ((next = part.match(RE_ROUND_CLOSE))) {
540
- token = TokenType.Punctuation
541
- state = State.TopLevelContent
542
- } else if ((next = part.match(RE_COLON))) {
543
- token = TokenType.Punctuation
544
- state = State.BeforeType
545
- } else if ((next = part.match(RE_NUMERIC))) {
546
- token = TokenType.Numeric
547
- state = State.AfterType
548
- } else if ((next = part.match(RE_CURLY_OPEN))) {
549
- token = TokenType.Punctuation
550
- state = State.InsideTypeObject
551
- } else if ((next = part.match(RE_QUOTE_SINGLE))) {
552
- stack.push(State.AfterType)
553
- token = TokenType.Punctuation
554
- state = State.InsideSingleQuoteString
555
- } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
556
- stack.push(State.AfterType)
557
- token = TokenType.Punctuation
558
- state = State.InsideDoubleQuoteString
559
- } else if ((next = part.match(RE_VERTICAL_LINE))) {
560
- token = TokenType.Punctuation
561
- state = State.BeforeType
562
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
563
- stack.push(state)
564
- token = TokenType.Comment
565
- state = State.InsideBlockComment
566
- } else if ((next = part.match(RE_LINE_COMMENT))) {
567
- token = TokenType.Comment
568
- state = State.BeforeType
569
- } else if ((next = part.match(RE_NUMERIC))) {
570
- token = TokenType.Numeric
571
- state = State.AfterType
572
- } else if ((next = part.match(RE_NUMERIC_2))) {
573
- token = TokenType.Numeric
574
- state = State.AfterType
575
- } else if ((next = part.match(RE_SQUARE_OPEN))) {
576
- token = TokenType.Punctuation
577
- state = State.BeforeType
578
- } else if ((next = part.match(RE_CURLY_CLOSE))) {
579
- token = TokenType.Punctuation
580
- state = stack.pop() || State.TopLevelContent
581
- } else if ((next = part.match(RE_QUESTION_MARK))) {
582
- token = TokenType.Punctuation
583
- state = State.BeforeType
584
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
585
- token = TokenType.Text
586
- state = State.TopLevelContent
587
- } else {
588
- part
589
- throw new Error('no')
590
- }
591
- break
592
- case State.InsideTypeExpression:
593
- if ((next = part.match(RE_ROUND_CLOSE))) {
594
- token = TokenType.Punctuation
595
- state = State.AfterTypeExpression
596
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
597
- token = TokenType.VariableName
598
- state = State.AfterVariableName
599
- } else if ((next = part.match(RE_WHITESPACE))) {
600
- token = TokenType.Whitespace
601
- state = State.InsideTypeExpression
602
- } else if ((next = part.match(RE_PUNCTUATION))) {
603
- token = TokenType.Punctuation
604
- state = State.InsideTypeExpression
605
- } else if ((next = part.match(RE_SQUARE_OPEN))) {
606
- token = TokenType.Punctuation
607
- state = State.InsideTypeExpression
608
- } else if ((next = part.match(RE_SQUARE_CLOSE))) {
609
- token = TokenType.Punctuation
610
- state = State.InsideTypeExpression
611
- } else {
612
- throw new Error('no')
613
- }
614
- break
615
- case State.AfterTypeExpression:
616
- if ((next = part.match(RE_SEMICOLON))) {
617
- token = TokenType.Punctuation
618
- state = State.TopLevelContent
619
- } else if ((next = part.match(RE_ARROW))) {
620
- token = TokenType.Punctuation
621
- state = State.BeforeType
622
- } else if ((next = part.match(RE_WHITESPACE))) {
623
- token = TokenType.Whitespace
624
- state = State.AfterTypeExpression
625
- } else if ((next = part.match(RE_COMMA))) {
626
- token = TokenType.Punctuation
627
- state = State.InsideTypeExpression
628
- } else if ((next = part.match(RE_ROUND_CLOSE))) {
629
- token = TokenType.Punctuation
630
- state = stack.pop() || State.AfterTypeExpression
631
- } else if ((next = part.match(RE_CURLY_CLOSE))) {
632
- token = TokenType.Punctuation
633
- state = stack.pop() || State.TopLevelContent
634
- } else if ((next = part.match(RE_KEYWORD))) {
635
- token = TokenType.Keyword
636
- state = State.TopLevelContent
637
- } else if ((next = part.match(RE_PUNCTUATION))) {
638
- token = TokenType.Punctuation
639
- state = State.InsideTypeExpression
640
- } else if ((next = part.match(RE_SQUARE_OPEN))) {
641
- token = TokenType.Punctuation
642
- state = State.InsideTypeExpression
643
- } else if ((next = part.match(RE_SQUARE_CLOSE))) {
644
- token = TokenType.Punctuation
645
- state = State.InsideTypeExpression
646
- } else if ((next = part.match(RE_VERTICAL_LINE))) {
647
- token = TokenType.Punctuation
648
- state = State.InsideTypeExpression
649
- } else if ((next = part.match(RE_LINE_COMMENT))) {
650
- token = TokenType.Comment
651
- state = State.AfterTypeExpression
652
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
653
- token = TokenType.Text
654
- state = State.TopLevelContent
655
- } else {
656
- part
657
- throw new Error('no')
658
- }
659
- break
660
- case State.AfterVariableName:
661
- if ((next = part.match(RE_COLON))) {
662
- token = TokenType.Punctuation
663
- state = State.BeforeType
664
- } else if ((next = part.match(RE_QUESTION_MARK_COLON))) {
665
- token = TokenType.Punctuation
666
- state = State.BeforeType
667
- } else if ((next = part.match(RE_EXLAMATION_MARK_COLON))) {
668
- token = TokenType.Punctuation
669
- state = State.BeforeType
670
- } else if ((next = part.match(RE_WHITESPACE))) {
671
- token = TokenType.Whitespace
672
- state = State.AfterVariableName
673
- } else if ((next = part.match(RE_AMPERSAND))) {
674
- token = TokenType.Punctuation
675
- state = State.TopLevelContent
676
- } else if ((next = part.match(RE_QUESTION_MARK_COLON))) {
677
- token = TokenType.Punctuation
678
- state = State.BeforeType
679
- } else if ((next = part.match(RE_CURLY_OPEN))) {
680
- token = TokenType.Punctuation
681
- state = State.TopLevelContent
682
- } else if ((next = part.match(RE_QUOTE_SINGLE))) {
683
- token = TokenType.Punctuation
684
- state = State.InsideSingleQuoteString
685
- } else if ((next = part.match(RE_PUNCTUATION))) {
686
- token = TokenType.Punctuation
687
- state = State.TopLevelContent
688
- } else {
689
- tokens
690
- part
691
- throw new Error('no')
692
- }
693
- break
694
- case State.AfterType:
695
- if ((next = part.match(RE_SEMICOLON))) {
696
- token = TokenType.Punctuation
697
- state = stack.pop() || State.TopLevelContent
698
- } else if ((next = part.match(RE_WHITESPACE))) {
699
- token = TokenType.Whitespace
700
- state = State.AfterType
701
- } else if ((next = part.match(RE_EQUAL))) {
702
- token = TokenType.Punctuation
703
- state = stack.pop() || State.TopLevelContent
704
- } else if ((next = part.match(RE_QUESTION_MARK_COLON))) {
705
- token = TokenType.Punctuation
706
- state = State.BeforeType
707
- } else if ((next = part.match(RE_COLON))) {
708
- token = TokenType.Punctuation
709
- state = State.BeforeType
710
- } else if ((next = part.match(RE_ROUND_CLOSE))) {
711
- token = TokenType.Punctuation
712
- state = stack.pop() || State.BeforeType
713
- } else if ((next = part.match(RE_COMMA))) {
714
- token = TokenType.Punctuation
715
- state = stack.pop() || State.TopLevelContent
716
- } else if ((next = part.match(RE_DOT))) {
717
- token = TokenType.Punctuation
718
- state = State.BeforePropertyAccess
719
- } else if ((next = part.match(RE_SQUARE_OPEN))) {
720
- token = TokenType.Punctuation
721
- state = State.AfterType
722
- stack.push(State.AfterType)
723
- } else if ((next = part.match(RE_SQUARE_CLOSE))) {
724
- token = TokenType.Punctuation
725
- state = State.AfterType
726
- } else if ((next = part.match(RE_VERTICAL_LINE))) {
727
- token = TokenType.Punctuation
728
- state = State.BeforeType
729
- } else if ((next = part.match(RE_ANGLE_OPEN))) {
730
- token = TokenType.Punctuation
731
- state = State.BeforeType
732
- stack.push(State.AfterType)
733
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
734
- token = TokenType.Type
735
- state = State.AfterType
736
- } else if ((next = part.match(RE_ANGLE_CLOSE))) {
737
- token = TokenType.Punctuation
738
- state = State.AfterType
739
- } else if ((next = part.match(RE_CURLY_OPEN))) {
740
- token = TokenType.Punctuation
741
- state = State.InsideTypeObject
742
- } else if ((next = part.match(RE_QUOTE_SINGLE))) {
743
- stack.push(state)
744
- token = TokenType.Punctuation
745
- state = State.InsideSingleQuoteString
746
- } else if ((next = part.match(RE_LINE_COMMENT))) {
747
- token = TokenType.Comment
748
- state = State.AfterType
749
- } else if ((next = part.match(RE_AMPERSAND))) {
750
- token = TokenType.Punctuation
751
- state = State.BeforeType
752
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
753
- stack.push(state)
754
- token = TokenType.Comment
755
- state = State.InsideBlockComment
756
- } else if ((next = part.match(RE_ANYTHING_BUT_SEMICOLON_UNTIL_END))) {
757
- token = TokenType.Text
758
- state = State.AfterType
759
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
760
- token = TokenType.Text
761
- state = State.TopLevelContent
762
- } else {
763
- // stack.push(State.AfterType)
764
- part
765
- throw new Error('no')
766
- }
767
- break
768
- case State.AfterTypeAfterNewLine:
769
- if ((next = part.match(RE_KEYWORD))) {
770
- switch (next[0]) {
771
- case 'true':
772
- case 'false':
773
- case 'null':
774
- case 'undefined':
775
- token = TokenType.LanguageConstant
776
- state = State.TopLevelContent
777
- break
778
- case 'import':
779
- token = TokenType.KeywordImport
780
- state = State.AfterKeywordImport
781
- break
782
- case 'export':
783
- case 'from':
784
- token = TokenType.KeywordImport
785
- state = State.TopLevelContent
786
- break
787
- case 'as':
788
- case 'break':
789
- case 'case':
790
- case 'catch':
791
- case 'continue':
792
- case 'default':
793
- case 'do':
794
- case 'else':
795
- case 'finally':
796
- case 'for':
797
- case 'if':
798
- case 'switch':
799
- case 'throw':
800
- case 'try':
801
- case 'while':
802
- token = TokenType.KeywordControl
803
- state = State.TopLevelContent
804
- break
805
- case 'async':
806
- token = TokenType.KeywordModifier
807
- state = State.TopLevelContent
808
- break
809
- case 'await':
810
- token = TokenType.KeywordAwait
811
- state = State.TopLevelContent
812
- break
813
- case 'return':
814
- token = TokenType.KeywordReturn
815
- state = State.TopLevelContent
816
- break
817
- case 'new':
818
- token = TokenType.KeywordNew
819
- state = State.TopLevelContent
820
- break
821
- case 'let':
822
- case 'const':
823
- case 'var':
824
- token = TokenType.Keyword
825
- state = State.AfterKeywordVariableDeclaration
826
- break
827
- case 'type':
828
- token = TokenType.Keyword
829
- state = State.AfterKeywordTypeDeclaration
830
- break
831
- case 'declare':
832
- token = TokenType.KeywordDeclare
833
- state = State.AfterKeywordDeclare
834
- break
835
- case 'void':
836
- token = TokenType.KeywordVoid
837
- state = State.TopLevelContent
838
- break
839
- case 'interface':
840
- token = TokenType.Keyword
841
- state = State.AfterKeywordInterface
842
- break
843
- case 'private':
844
- case 'protected':
845
- case 'readonly':
846
- case 'public':
847
- case 'override':
848
- case 'abstract':
849
- token = TokenType.KeywordModifier
850
- state = State.TopLevelContent
851
- break
852
- case 'in':
853
- case 'of':
854
- case 'typeof':
855
- case 'instanceof':
856
- token = TokenType.KeywordOperator
857
- state = State.TopLevelContent
858
- break
859
- case 'instanceof':
860
- token = TokenType.KeywordOperator
861
- state = State.AfterKeywordInstanceOf
862
- break
863
- case 'function':
864
- token = TokenType.Keyword
865
- state = State.AfterKeywordFunction
866
- break
867
- case 'this':
868
- token = TokenType.KeywordThis
869
- state = State.TopLevelContent
870
- break
871
- case 'class':
872
- token = TokenType.Keyword
873
- state = State.AfterKeywordClass
874
- break
875
- default:
876
- token = TokenType.Keyword
877
- state = State.TopLevelContent
878
- break
879
- }
880
- } else if ((next = part.match(RE_ROUND_OPEN))) {
881
- token = TokenType.Punctuation
882
- state = stack.pop() || State.TopLevelContent
883
- } else if ((next = part.match(RE_SEMICOLON))) {
884
- token = TokenType.Punctuation
885
- state = stack.pop() || State.TopLevelContent
886
- } else if ((next = part.match(RE_WHITESPACE))) {
887
- token = TokenType.Whitespace
888
- state = State.AfterTypeAfterNewLine
889
- } else if ((next = part.match(RE_EQUAL))) {
890
- token = TokenType.Punctuation
891
- state = State.BeforeType
892
- } else if ((next = part.match(RE_VERTICAL_LINE))) {
893
- token = TokenType.Punctuation
894
- state = State.BeforeType
895
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
896
- token = TokenType.VariableName
897
- state = State.TopLevelContent
898
- } else if ((next = part.match(RE_ROUND_CLOSE))) {
899
- token = TokenType.Punctuation
900
- state = stack.pop() || State.TopLevelContent
901
- } else if ((next = part.match(RE_CURLY_CLOSE))) {
902
- token = TokenType.Punctuation
903
- state = stack.pop() || State.TopLevelContent
904
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
905
- stack.push(state)
906
- token = TokenType.Comment
907
- state = State.InsideBlockComment
908
- } else if ((next = part.match(RE_LINE_COMMENT))) {
909
- token = TokenType.Comment
910
- state = State.AfterTypeAfterNewLine
911
- } else if ((next = part.match(RE_AMPERSAND))) {
912
- token = TokenType.Punctuation
913
- state = State.BeforeType
914
- } else if ((next = part.match(RE_OPERATOR))) {
915
- token = TokenType.Punctuation
916
- state = State.TopLevelContent
917
- } else if ((next = part.match(RE_ANYTHING_BUT_SEMICOLON_UNTIL_END))) {
918
- token = TokenType.Text
919
- state = State.AfterType
920
- } else {
921
- throw new Error('no')
922
- }
923
- break
924
- case State.AfterKeywordDeclare:
925
- if ((next = part.match(RE_WHITESPACE))) {
926
- token = TokenType.Whitespace
927
- state = State.AfterKeywordDeclare
928
- } else if ((next = part.match(RE_KEYWORD_CONST))) {
929
- token = TokenType.Keyword
930
- state = State.AfterKeywordDeclare
931
- } else if ((next = part.match(RE_KEYWORD_LET))) {
932
- token = TokenType.Keyword
933
- state = State.AfterKeywordDeclare
934
- } else if ((next = part.match(RE_KEYWORD_ENUM))) {
935
- token = TokenType.Keyword
936
- state = State.AfterKeywordEnum
937
- } else if ((next = part.match(RE_KEYWORD_CLASS))) {
938
- token = TokenType.Keyword
939
- state = State.AfterKeywordClass
940
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
941
- token = TokenType.Type
942
- state = State.AfterVariableName
943
- } else {
944
- part
945
- throw new Error('no')
946
- }
947
- break
948
-
949
- case State.AfterKeywordEnum:
950
- if ((next = part.match(RE_WHITESPACE))) {
951
- token = TokenType.Whitespace
952
- state = State.AfterKeywordEnum
953
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
954
- token = TokenType.Type
955
- state = State.AfterKeywordEnumAfterVariableName
956
- } else {
957
- throw new Error('no')
958
- }
959
- break
960
- case State.AfterKeywordEnumAfterVariableName:
961
- if ((next = part.match(RE_WHITESPACE))) {
962
- token = TokenType.Whitespace
963
- state = State.AfterKeywordEnumAfterVariableName
964
- } else if ((next = part.match(RE_CURLY_OPEN))) {
965
- token = TokenType.Punctuation
966
- state = State.InsideEnum
967
- } else {
968
- throw new Error('no')
969
- }
970
- break
971
- case State.InsideEnum:
972
- if ((next = part.match(RE_WHITESPACE))) {
973
- token = TokenType.Whitespace
974
- state = State.InsideEnum
975
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
976
- token = TokenType.VariableName
977
- state = State.InsideEnumAfterVariableName
978
- } else if ((next = part.match(RE_CURLY_CLOSE))) {
979
- token = TokenType.Punctuation
980
- state = stack.pop() || State.TopLevelContent
981
- } else {
982
- throw new Error('no')
983
- }
984
- break
985
- case State.InsideEnumAfterVariableName:
986
- if ((next = part.match(RE_WHITESPACE))) {
987
- token = TokenType.Whitespace
988
- state = State.InsideEnumAfterVariableName
989
- } else if ((next = part.match(RE_EQUAL))) {
990
- token = TokenType.Punctuation
991
- state = State.TopLevelContent
992
- } else if ((next = part.match(RE_COMMA))) {
993
- token = TokenType.Punctuation
994
- state = State.InsideEnum
995
- } else if ((next = part.match(RE_CURLY_CLOSE))) {
996
- token = TokenType.Punctuation
997
- state = stack.pop() || State.TopLevelContent
998
- } else {
999
- part
1000
- throw new Error('no')
1001
- }
1002
- break
1003
- case State.InsideLineComment:
1004
- if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1005
- token = TokenType.Comment
1006
- state = State.TopLevelContent
1007
- } else {
1008
- throw new Error('no')
1009
- }
1010
- break
1011
- case State.InsideBlockComment:
1012
- if ((next = part.match(RE_BLOCK_COMMENT_END))) {
1013
- token = TokenType.Comment
1014
- state = stack.pop() || State.TopLevelContent
1015
- } else if ((next = part.match(RE_BLOCK_COMMENT_CONTENT))) {
1016
- token = TokenType.Comment
1017
- state = State.InsideBlockComment
1018
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1019
- token = TokenType.Comment
1020
- state = State.InsideBlockComment
1021
- } else {
1022
- throw new Error('no')
1023
- }
1024
- break
1025
- case State.BeforePropertyAccess:
1026
- if ((next = part.match(RE_VARIABLE_NAME))) {
1027
- token = TokenType.VariableName
1028
- state = stack.pop() || State.TopLevelContent
1029
- } else {
1030
- throw new Error('no')
1031
- }
1032
- break
1033
- case State.AfterKeywordClass:
1034
- if ((next = part.match(RE_WHITESPACE))) {
1035
- token = TokenType.Whitespace
1036
- state = State.AfterKeywordClass
1037
- } else if ((next = part.match(RE_KEYWORD_EXTENDS))) {
1038
- token = TokenType.KeywordModifier
1039
- state = State.AfterKeywordClass
1040
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1041
- token = TokenType.Class
1042
- state = State.AfterKeywordClassAfterClassName
1043
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1044
- stack.push(state)
1045
- token = TokenType.Comment
1046
- state = State.InsideBlockComment
1047
- } else {
1048
- part
1049
- throw new Error('no')
1050
- }
1051
- break
1052
- case State.AfterKeywordClassAfterClassName:
1053
- if ((next = part.match(RE_WHITESPACE))) {
1054
- token = TokenType.Whitespace
1055
- state = State.AfterKeywordClassAfterClassName
1056
- } else if ((next = part.match(RE_CURLY_OPEN))) {
1057
- token = TokenType.Punctuation
1058
- state = State.InsideClass
1059
- } else if ((next = part.match(RE_KEYWORD_EXTENDS))) {
1060
- token = TokenType.KeywordModifier
1061
- state = State.AfterKeywordClass
1062
- } else if ((next = part.match(RE_KEYWORD_IMPLEMENTS))) {
1063
- token = TokenType.Keyword
1064
- state = State.AfterKeywordClass
1065
- } else if ((next = part.match(RE_DOT))) {
1066
- token = TokenType.Punctuation
1067
- state = State.AfterPropertyDot
1068
- } else if ((next = part.match(RE_COMMA))) {
1069
- token = TokenType.Punctuation
1070
- state = State.AfterKeywordClass
1071
- } else if ((next = part.match(RE_ROUND_OPEN))) {
1072
- token = TokenType.Punctuation
1073
- state = State.AfterKeywordClassAfterClassName
1074
- } else if ((next = part.match(RE_ROUND_CLOSE))) {
1075
- token = TokenType.Punctuation
1076
- state = State.AfterKeywordClassAfterClassName
1077
- } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
1078
- stack.push(state)
1079
- token = TokenType.Punctuation
1080
- state = State.InsideDoubleQuoteString
1081
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1082
- token = TokenType.Class
1083
- state = State.AfterKeywordClassAfterClassName
1084
- } else if ((next = part.match(RE_ANGLE_OPEN))) {
1085
- stack.push(state)
1086
- token = TokenType.Punctuation
1087
- state = State.BeforeType
1088
- } else if ((next = part.match(RE_EQUAL))) {
1089
- token = TokenType.Punctuation
1090
- state = State.TopLevelContent
1091
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1092
- stack.push(state)
1093
- token = TokenType.Comment
1094
- state = State.InsideBlockComment
1095
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1096
- token = TokenType.Text
1097
- state = State.TopLevelContent
1098
- } else {
1099
- throw new Error('no')
1100
- }
1101
- break
1102
- case State.InsideClass:
1103
- if ((next = part.match(RE_WHITESPACE))) {
1104
- token = TokenType.Whitespace
1105
- state = State.InsideClass
1106
- } else if ((next = part.match(RE_KEYWORD_CLASS_PROPERTY_MODIFIER))) {
1107
- token = TokenType.StorageModifier
1108
- state = State.InsideClass
1109
- } else if ((next = part.match(RE_KEYWORD_CONSTRUCTOR))) {
1110
- token = TokenType.Keyword
1111
- state = State.AfterVariableName
1112
- } else if ((next = part.match(RE_FUNCTION_CALL_NAME))) {
1113
- token = TokenType.FunctionName
1114
- state = State.AfterVariableName
1115
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1116
- token = TokenType.VariableName
1117
- state = State.InsideClass
1118
- } else if ((next = part.match(RE_COLON))) {
1119
- stack.push(state)
1120
- token = TokenType.Punctuation
1121
- state = State.BeforeType
1122
- } else if ((next = part.match(RE_CURLY_CLOSE))) {
1123
- token = TokenType.Punctuation
1124
- state = stack.pop() || State.TopLevelContent
1125
- } else if ((next = part.match(RE_SEMICOLON))) {
1126
- token = TokenType.Punctuation
1127
- state = State.InsideClass
1128
- } else if ((next = part.match(RE_EQUAL))) {
1129
- token = TokenType.Punctuation
1130
- state = State.TopLevelContent
1131
- } else if ((next = part.match(RE_SQUARE_OPEN))) {
1132
- token = TokenType.Punctuation
1133
- state = State.InsideClass
1134
- } else if ((next = part.match(RE_SQUARE_CLOSE))) {
1135
- token = TokenType.Punctuation
1136
- state = State.InsideClass
1137
- } else if ((next = part.match(RE_QUOTE_SINGLE))) {
1138
- stack.push(state)
1139
- token = TokenType.Punctuation
1140
- state = State.InsideSingleQuoteString
1141
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1142
- stack.push(state)
1143
- token = TokenType.Comment
1144
- state = State.InsideBlockComment
1145
- } else if ((next = part.match(RE_VERTICAL_LINE))) {
1146
- token = TokenType.Punctuation
1147
- state = State.InsideClass
1148
- } else if ((next = part.match(RE_ANGLE_OPEN))) {
1149
- token = TokenType.Punctuation
1150
- state = State.TopLevelContent
1151
- } else if ((next = part.match(RE_QUESTION_MARK_COLON))) {
1152
- stack.push(state)
1153
- token = TokenType.Punctuation
1154
- state = State.BeforeType
1155
- } else if ((next = part.match(RE_EXLAMATION_MARK_COLON))) {
1156
- stack.push(state)
1157
- token = TokenType.Punctuation
1158
- state = State.BeforeType
1159
- } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
1160
- stack.push(state)
1161
- token = TokenType.Punctuation
1162
- state = State.InsideDoubleQuoteString
1163
- } else if ((next = part.match(RE_ROUND_OPEN))) {
1164
- stack.push(State.AfterMethodParameters)
1165
- token = TokenType.Punctuation
1166
- state = State.InsideMethodParameters
1167
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1168
- token = TokenType.Text
1169
- state = State.TopLevelContent
1170
- } else {
1171
- part
1172
- throw new Error('no')
1173
- }
1174
- break
1175
- case State.InsideObjectDestructuring:
1176
- if ((next = part.match(RE_WHITESPACE))) {
1177
- token = TokenType.Whitespace
1178
- state = State.InsideObjectDestructuring
1179
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1180
- token = TokenType.VariableName
1181
- state = State.InsideObjectDestructuringAfterValue
1182
- } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
1183
- token = TokenType.Punctuation
1184
- state = State.InsideDoubleQuoteString
1185
- } else {
1186
- throw new Error('no')
1187
- }
1188
- break
1189
- case State.InsideObjectDestructuringAfterValue:
1190
- if ((next = part.match(RE_WHITESPACE))) {
1191
- token = TokenType.Whitespace
1192
- state = State.InsideObjectDestructuringAfterValue
1193
- } else if ((next = part.match(RE_CURLY_CLOSE))) {
1194
- token = TokenType.Punctuation
1195
- state = State.AfterKeywordVariableDeclaration
1196
- } else if ((next = part.match(RE_COLON))) {
1197
- token = TokenType.Punctuation
1198
- state = State.InsideObjectDestructuringAfterValue
1199
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1200
- token = TokenType.VariableName
1201
- state = State.InsideObjectDestructuringAfterValue
1202
- } else if ((next = part.match(RE_PUNCTUATION))) {
1203
- token = TokenType.Punctuation
1204
- state = State.TopLevelContent
1205
- } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
1206
- token = TokenType.Punctuation
1207
- state = State.InsideDoubleQuoteString
1208
- } else if ((next = part.match(RE_QUOTE_SINGLE))) {
1209
- token = TokenType.Punctuation
1210
- state = State.InsideSingleQuoteString
1211
- } else {
1212
- throw new Error('no')
1213
- }
1214
- break
1215
- case State.AfterKeywordInterface:
1216
- if ((next = part.match(RE_WHITESPACE))) {
1217
- token = TokenType.Whitespace
1218
- state = State.AfterKeywordInterface
1219
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1220
- token = TokenType.Type
1221
- state = State.AfterInterfaceName
1222
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1223
- stack.push(state)
1224
- token = TokenType.Comment
1225
- state = State.InsideBlockComment
1226
- } else {
1227
- throw new Error('no')
1228
- }
1229
- break
1230
- case State.InsideTypeObject:
1231
- if ((next = part.match(RE_WHITESPACE))) {
1232
- token = TokenType.Whitespace
1233
- state = State.InsideTypeObject
1234
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1235
- token = TokenType.Comment
1236
- state = State.InsideBlockComment
1237
- stack.push(State.InsideTypeObject)
1238
- } else if ((next = part.match(RE_METHOD_NAME))) {
1239
- token = TokenType.Function
1240
- state = State.AfterMethodName
1241
- } else if ((next = part.match(RE_KEYWORD_READONLY))) {
1242
- token = TokenType.KeywordModifier
1243
- state = State.InsideTypeObject
1244
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1245
- token = TokenType.VariableName
1246
- state = State.InsideTypeObject
1247
- } else if ((next = part.match(RE_CURLY_CLOSE))) {
1248
- token = TokenType.Punctuation
1249
- state = stack.pop() || State.TopLevelContent
1250
- } else if ((next = part.match(RE_COLON_OPTIONAL))) {
1251
- token = TokenType.Punctuation
1252
- state = State.BeforeType
1253
- stack.push(State.InsideTypeObject)
1254
- } else if ((next = part.match(RE_COMMA))) {
1255
- token = TokenType.Punctuation
1256
- state = State.InsideTypeObject
1257
- } else if ((next = part.match(RE_SEMICOLON))) {
1258
- token = TokenType.Punctuation
1259
- state = State.InsideTypeObject
1260
- } else if ((next = part.match(RE_VERTICAL_LINE))) {
1261
- token = TokenType.Punctuation
1262
- state = State.BeforeType
1263
- } else if ((next = part.match(RE_SQUARE_OPEN))) {
1264
- token = TokenType.Punctuation
1265
- state = State.InsideTypeObject
1266
- } else if ((next = part.match(RE_SQUARE_CLOSE))) {
1267
- token = TokenType.Punctuation
1268
- state = State.InsideTypeObject
1269
- } else if ((next = part.match(RE_PUNCTUATION))) {
1270
- token = TokenType.Punctuation
1271
- state = State.InsideTypeObject
1272
- } else if ((next = part.match(RE_QUESTION_MARK))) {
1273
- token = TokenType.Punctuation
1274
- state = State.InsideTypeObject
1275
- } else if ((next = part.match(RE_QUOTE_SINGLE))) {
1276
- token = TokenType.Punctuation
1277
- state = State.InsideSingleQuoteString
1278
- stack.push(State.InsideTypeObject)
1279
- } else if ((next = part.match(RE_LINE_COMMENT))) {
1280
- token = TokenType.Comment
1281
- state = State.InsideTypeObject
1282
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1283
- token = TokenType.Text
1284
- state = State.TopLevelContent
1285
- } else {
1286
- part
1287
- throw new Error('no')
1288
- }
1289
- break
1290
- case State.AfterMethodName:
1291
- if ((next = part.match(RE_ROUND_OPEN))) {
1292
- token = TokenType.Punctuation
1293
- state = State.InsideMethodParameters
1294
- // stack.push()
1295
- } else if ((next = part.match(RE_COLON))) {
1296
- token = TokenType.Punctuation
1297
- state = State.AfterMethodName
1298
- } else if ((next = part.match(RE_WHITESPACE))) {
1299
- token = TokenType.Whitespace
1300
- state = State.AfterMethodName
1301
- } else if ((next = part.match(RE_SPREAD))) {
1302
- token = TokenType.Punctuation
1303
- state = State.AfterMethodName
1304
- } else {
1305
- throw new Error('no')
1306
- }
1307
- break
1308
- case State.InsideMethodParameters:
1309
- if ((next = part.match(RE_VARIABLE_NAME))) {
1310
- token = TokenType.VariableName
1311
- state = State.InsideMethodParametersAfterVariableName
1312
- } else if ((next = part.match(RE_WHITESPACE))) {
1313
- token = TokenType.Whitespace
1314
- state = State.InsideMethodParameters
1315
- } else if ((next = part.match(RE_ROUND_CLOSE))) {
1316
- token = TokenType.Punctuation
1317
- state = State.AfterMethodParameters
1318
- } else if ((next = part.match(RE_CURLY_CLOSE))) {
1319
- token = TokenType.Punctuation
1320
- state = stack.pop() || State.TopLevelContent
1321
- } else if ((next = part.match(RE_COLON))) {
1322
- token = TokenType.Punctuation
1323
- state = State.BeforeType
1324
- } else if ((next = part.match(RE_COMMA))) {
1325
- token = TokenType.Punctuation
1326
- state = State.InsideMethodParameters
1327
- } else if ((next = part.match(RE_VERTICAL_LINE))) {
1328
- stack.push(state)
1329
- token = TokenType.Punctuation
1330
- state = State.BeforeType
1331
- } else if ((next = part.match(RE_SPREAD))) {
1332
- token = TokenType.Punctuation
1333
- state = State.InsideMethodParameters
1334
- } else if ((next = part.match(RE_SQUARE_OPEN))) {
1335
- token = TokenType.Punctuation
1336
- state = State.InsideMethodParameters
1337
- } else if ((next = part.match(RE_SQUARE_CLOSE))) {
1338
- token = TokenType.Punctuation
1339
- state = State.InsideMethodParameters
1340
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1341
- stack.push(state)
1342
- token = TokenType.Comment
1343
- state = State.InsideBlockComment
1344
- } else if ((next = part.match(RE_PUNCTUATION))) {
1345
- token = TokenType.Punctuation
1346
- state = State.InsideMethodParameters
1347
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1348
- token = TokenType.Text
1349
- state = stack.pop() || State.TopLevelContent
1350
- } else {
1351
- part
1352
- throw new Error('no')
1353
- }
1354
- break
1355
- case State.InsideMethodParametersAfterVariableName:
1356
- if ((next = part.match(RE_COLON))) {
1357
- token = TokenType.Punctuation
1358
- state = State.BeforeType
1359
- stack.push(State.InsideMethodParameters)
1360
- } else if ((next = part.match(RE_QUESTION_MARK_COLON))) {
1361
- token = TokenType.Punctuation
1362
- state = State.BeforeType
1363
- stack.push(State.InsideMethodParameters)
1364
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1365
- token = TokenType.Text
1366
- state = State.InsideMethodParametersAfterVariableName
1367
- } else {
1368
- throw new Error('no')
1369
- }
1370
- break
1371
- case State.AfterMethodParameters:
1372
- if ((next = part.match(RE_COLON))) {
1373
- token = TokenType.Punctuation
1374
- state = State.BeforeType
1375
- stack.push(State.InsideTypeObject)
1376
- } else if ((next = part.match(RE_WHITESPACE))) {
1377
- token = TokenType.Whitespace
1378
- state = State.AfterMethodParameters
1379
- } else if ((next = part.match(RE_ARROW))) {
1380
- token = TokenType.Punctuation
1381
- // TODO depending on whether this is a type function
1382
- // this can be either a type or a value
1383
- state = State.BeforeType
1384
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1385
- token = TokenType.Punctuation
1386
- state = State.TopLevelContent
1387
- } else {
1388
- throw new Error('no')
1389
- }
1390
- break
1391
- case State.AfterPropertyDot:
1392
- if ((next = part.match(RE_WHITESPACE))) {
1393
- token = TokenType.Whitespace
1394
- state = State.AfterPropertyDot
1395
- } else if ((next = part.match(RE_FUNCTION_CALL_NAME))) {
1396
- token = TokenType.FunctionName
1397
- state = State.TopLevelContent
1398
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1399
- token = TokenType.VariableName
1400
- state = State.TopLevelContent
1401
- } else if ((next = part.match(RE_LINE_COMMENT))) {
1402
- token = TokenType.Comment
1403
- state = State.InsideLineComment
1404
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1405
- token = TokenType.Comment
1406
- state = State.InsideBlockComment
1407
- } else if ((next = part.match(RE_PUNCTUATION))) {
1408
- token = TokenType.Punctuation
1409
- state = State.TopLevelContent
1410
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1411
- token = TokenType.Text
1412
- state = State.TopLevelContent
1413
- } else {
1414
- throw new Error('no')
1415
- }
1416
- break
1417
- case State.InsideBacktickString:
1418
- if ((next = part.match(RE_QUOTE_BACKTICK))) {
1419
- token = TokenType.Punctuation
1420
- state = State.TopLevelContent
1421
- } else if ((next = part.match(RE_STRING_BACKTICK_QUOTE_CONTENT))) {
1422
- token = TokenType.String
1423
- state = State.InsideBacktickString
1424
- } else if ((next = part.match(RE_STRING_ESCAPE))) {
1425
- token = TokenType.String
1426
- state = State.InsideBacktickString
1427
- } else {
1428
- throw new Error('no')
1429
- }
1430
- break
1431
- case State.AfterInterfaceName:
1432
- if ((next = part.match(RE_WHITESPACE))) {
1433
- token = TokenType.Whitespace
1434
- state = State.AfterInterfaceName
1435
- } else if ((next = part.match(RE_CURLY_OPEN))) {
1436
- token = TokenType.Punctuation
1437
- state = State.InsideTypeObject
1438
- } else if ((next = part.match(RE_KEYWORD_EXTENDS))) {
1439
- token = TokenType.KeywordModifier
1440
- state = State.AfterInterfaceName
1441
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1442
- token = TokenType.Type
1443
- state = State.AfterInterfaceName
1444
- } else if ((next = part.match(RE_ANGLE_OPEN))) {
1445
- stack.push(State.AfterInterfaceName)
1446
- token = TokenType.Punctuation
1447
- state = State.BeforeType
1448
- } else if ((next = part.match(RE_QUESTION_MARK_COLON))) {
1449
- token = TokenType.Punctuation
1450
- state = State.AfterInterfaceName
1451
- } else if ((next = part.match(RE_ANGLE_CLOSE))) {
1452
- token = TokenType.Punctuation
1453
- state = State.AfterInterfaceName
1454
- } else if ((next = part.match(RE_EQUAL))) {
1455
- token = TokenType.Punctuation
1456
- state = State.TopLevelContent
1457
- } else if ((next = part.match(RE_DOT))) {
1458
- token = TokenType.Punctuation
1459
- state = State.AfterPropertyDot
1460
- } else if ((next = part.match(RE_VERTICAL_LINE))) {
1461
- token = TokenType.Punctuation
1462
- state = State.BeforeType
1463
- } else if ((next = part.match(RE_COLON))) {
1464
- token = TokenType.Punctuation
1465
- state = State.BeforeType
1466
- } else if ((next = part.match(RE_COMMA))) {
1467
- token = TokenType.Punctuation
1468
- state = State.TopLevelContent
1469
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1470
- stack.push(state)
1471
- token = TokenType.Comment
1472
- state = State.InsideBlockComment
1473
- } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
1474
- token = TokenType.Text
1475
- state = stack.pop() || State.TopLevelContent
1476
- } else {
1477
- part
1478
- throw new Error('no')
1479
- }
1480
- break
1481
- case State.AfterKeywordImport:
1482
- if ((next = part.match(RE_WHITESPACE))) {
1483
- token = TokenType.Whitespace
1484
- state = State.AfterKeywordImport
1485
- } else if ((next = part.match(RE_KEYWORD_TYPE))) {
1486
- token = TokenType.Keyword
1487
- state = State.AfterKeywordImport
1488
- } else if ((next = part.match(RE_CURLY_OPEN))) {
1489
- token = TokenType.Punctuation
1490
- state = State.TopLevelContent
1491
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1492
- token = TokenType.VariableName
1493
- state = State.TopLevelContent
1494
- } else if ((next = part.match(RE_STAR))) {
1495
- token = TokenType.Punctuation
1496
- state = State.TopLevelContent
1497
- } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
1498
- token = TokenType.Punctuation
1499
- state = State.InsideDoubleQuoteString
1500
- } else if ((next = part.match(RE_QUOTE_SINGLE))) {
1501
- token = TokenType.Punctuation
1502
- state = State.InsideSingleQuoteString
1503
- } else if ((next = part.match(RE_ROUND_OPEN))) {
1504
- token = TokenType.Punctuation
1505
- state = State.TopLevelContent
1506
- } else if ((next = part.match(RE_DOT))) {
1507
- token = TokenType.Punctuation
1508
- state = State.AfterPropertyDot
1509
- } else {
1510
- throw new Error('no')
1511
- }
1512
- break
1513
- case State.AfterKeywordFunction:
1514
- if ((next = part.match(RE_WHITESPACE))) {
1515
- token = TokenType.Whitespace
1516
- state = State.AfterKeywordFunction
1517
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1518
- token = TokenType.FunctionName
1519
- state = State.TopLevelContent
1520
- } else if ((next = part.match(RE_PUNCTUATION))) {
1521
- token = TokenType.Punctuation
1522
- state = State.TopLevelContent
1523
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1524
- stack.push(state)
1525
- token = TokenType.Comment
1526
- state = State.InsideBlockComment
1527
- } else {
1528
- throw new Error('no')
1529
- }
1530
- break
1531
- case State.AfterKeywordInstanceOf:
1532
- if ((next = part.match(RE_WHITESPACE))) {
1533
- token = TokenType.Whitespace
1534
- state = State.AfterKeywordInstanceOf
1535
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1536
- token = TokenType.Class
1537
- state = State.TopLevelContent
1538
- } else if ((next = part.match(RE_ROUND_OPEN))) {
1539
- token = TokenType.Punctuation
1540
- state = State.TopLevelContent
1541
- } else {
1542
- throw new Error('no')
1543
- }
1544
- break
1545
- case State.AfterKeywordNew:
1546
- if ((next = part.match(RE_WHITESPACE))) {
1547
- token = TokenType.Whitespace
1548
- state = State.AfterKeywordNew
1549
- } else if ((next = part.match(RE_KEYWORD_NEW))) {
1550
- token = TokenType.KeywordNew
1551
- state = State.AfterKeywordNew
1552
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1553
- token = TokenType.Class
1554
- state = State.TopLevelContent
1555
- } else if ((next = part.match(RE_ROUND_OPEN))) {
1556
- token = TokenType.Punctuation
1557
- state = State.TopLevelContent
1558
- } else if ((next = part.match(RE_COLON))) {
1559
- token = TokenType.Punctuation
1560
- state = State.TopLevelContent
1561
- } else if ((next = part.match(RE_DOT))) {
1562
- token = TokenType.Punctuation
1563
- state = State.AfterPropertyDot
1564
- } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
1565
- stack.push(state)
1566
- token = TokenType.Comment
1567
- state = State.InsideBlockComment
1568
- } else {
1569
- throw new Error('no')
1570
- }
1571
- break
1572
- case State.AfterKeywordTypeOf:
1573
- if ((next = part.match(RE_WHITESPACE))) {
1574
- token = TokenType.Whitespace
1575
- state = State.AfterKeywordTypeOf
1576
- } else if ((next = part.match(RE_VARIABLE_NAME))) {
1577
- token = TokenType.VariableName
1578
- state = stack.pop() || State.TopLevelContent
1579
- } else {
1580
- throw new Error('no')
1581
- }
1582
- break
1583
- default:
1584
- state
1585
- throw new Error('no')
1586
- }
1587
- const tokenLength = next[0].length
1588
- index += tokenLength
1589
- tokens.push(token, tokenLength)
1590
- }
1591
- if (state === State.AfterType && stack[0] === State.InsideClass) {
1592
- state = State.InsideClass
1593
- stack.pop()
1594
- } else if (state === State.AfterType) {
1595
- state = State.AfterTypeAfterNewLine
1596
- }
1597
- return {
1598
- state,
1599
- stack,
1600
- tokens,
1601
- }
1602
- }