@lvce-editor/shared-process 0.12.0 → 0.13.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.
Files changed (102) hide show
  1. package/config/defaultKeyBindings.json +5 -0
  2. package/config/defaultSettings.json +4 -0
  3. package/extensions/builtin.language-basics-graphql/extension.json +1 -1
  4. package/extensions/builtin.language-basics-graphql/src/tokenizeGraphql.js +408 -4
  5. package/extensions/builtin.language-basics-html/src/tokenizeHtml.js +91 -3
  6. package/extensions/builtin.language-basics-javascript/src/tokenizeJavaScript.js +7 -0
  7. package/extensions/builtin.language-basics-json/extension.json +3 -1
  8. package/extensions/builtin.language-basics-jsx/README.md +14 -0
  9. package/extensions/builtin.language-basics-jsx/extension.json +13 -0
  10. package/extensions/builtin.language-basics-jsx/src/tokenizeJsx.js +648 -0
  11. package/extensions/builtin.language-basics-julia/src/tokenizeJulia.js +52 -1
  12. package/extensions/builtin.language-basics-markdown/src/tokenizeMarkdown.js +82 -2
  13. package/extensions/builtin.language-basics-mdx/README.md +14 -0
  14. package/extensions/builtin.language-basics-mdx/extension.json +12 -0
  15. package/extensions/builtin.language-basics-mdx/src/tokenizeMdx.js +395 -0
  16. package/extensions/builtin.language-basics-shellscript/src/tokenizeShellScript.js +22 -1
  17. package/extensions/builtin.language-basics-toml/src/tokenizeToml.js +29 -1
  18. package/extensions/builtin.language-basics-typescript/extension.json +1 -1
  19. package/extensions/builtin.language-basics-typescript/src/tokenizeTypeScript.js +128 -12
  20. package/extensions/builtin.language-basics-xml/extension.json +3 -2
  21. package/extensions/builtin.language-basics-xml/src/tokenizeXml.js +26 -3
  22. package/extensions/builtin.language-basics-yaml/src/tokenizeYaml.js +7 -1
  23. package/extensions/builtin.theme-atom-one-dark/color-theme.json +4 -0
  24. package/extensions/builtin.theme-cobalt2/color-theme.json +4 -0
  25. package/extensions/builtin.theme-gruvbox/color-theme.json +4 -0
  26. package/extensions/builtin.vscode-icons/icon-theme.json +40 -2
  27. package/extensions/builtin.vscode-icons/icons/file_type_bazel_ignore.svg +1 -0
  28. package/extensions/builtin.vscode-icons/icons/file_type_bazel_version.svg +1 -0
  29. package/extensions/builtin.vscode-icons/icons/file_type_eleventy.svg +1 -0
  30. package/extensions/builtin.vscode-icons/icons/file_type_eleventy2.svg +1 -0
  31. package/extensions/builtin.vscode-icons/icons/file_type_light_eleventy.svg +1 -0
  32. package/extensions/builtin.vscode-icons/icons/file_type_light_eleventy2.svg +1 -0
  33. package/extensions/builtin.vscode-icons/icons/file_type_light_rome.svg +1 -0
  34. package/extensions/builtin.vscode-icons/icons/file_type_light_tree.svg +1 -0
  35. package/extensions/builtin.vscode-icons/icons/file_type_mondoo.svg +1 -0
  36. package/extensions/builtin.vscode-icons/icons/file_type_nuxt.svg +1 -1
  37. package/extensions/builtin.vscode-icons/icons/file_type_rome.svg +1 -0
  38. package/extensions/builtin.vscode-icons/icons/file_type_sapphire_framework_cli.svg +1 -0
  39. package/extensions/builtin.vscode-icons/icons/file_type_shellcheck.svg +91 -0
  40. package/extensions/builtin.vscode-icons/icons/file_type_shuttle.svg +1 -0
  41. package/extensions/builtin.vscode-icons/icons/file_type_tree.svg +1 -0
  42. package/extensions/builtin.vscode-icons/icons/folder_type_nuxt.svg +1 -1
  43. package/extensions/builtin.vscode-icons/icons/folder_type_nuxt_opened.svg +1 -1
  44. package/package.json +7 -6
  45. package/src/parts/CleanStack/CleanStack.js +5 -0
  46. package/src/parts/Cli/Cli.js +5 -4
  47. package/src/parts/CliCommandType/CliCommandType.js +10 -0
  48. package/src/parts/CliInstall/CliInstall.js +3 -2
  49. package/src/parts/CliLink/CliLink.js +3 -2
  50. package/src/parts/CliList/CliList.js +3 -1
  51. package/src/parts/ClipBoard/ClipBoard.js +3 -2
  52. package/src/parts/ClipBoard/ClipBoardGnome.js +15 -31
  53. package/src/parts/CommandNotFoundError/CommandNotFoundError.js +9 -0
  54. package/src/parts/DesktopType/DesktopType.js +3 -0
  55. package/src/parts/Download/Download.js +1 -1
  56. package/src/parts/DownloadAndExtract/DownloadAndExtract.js +2 -2
  57. package/src/parts/Error/FileSystemError.js +1 -1
  58. package/src/parts/ErrorCodes/ErrorCodes.js +2 -0
  59. package/src/parts/ErrorHandling/ErrorHandling.js +4 -3
  60. package/src/parts/ExecCommand/ExecCommand.js +25 -0
  61. package/src/parts/ExecPromise/ExecPromise.js +4 -0
  62. package/src/parts/ExitCode/ExitCode.js +5 -0
  63. package/src/parts/ExportStatic/ExportStatic.js +2 -2
  64. package/src/parts/ExtensionHost/ExtensionHost.ipc.js +0 -1
  65. package/src/parts/ExtensionHost/ExtensionHost.js +1 -1
  66. package/src/parts/ExtensionHostIpc/ExtensionHostIpcWithChildProcess.js +3 -8
  67. package/src/parts/ExtensionHostIpc/ExtensionHostIpcWithWorker.js +3 -7
  68. package/src/parts/ExtensionInstallFromFile/ExtensionInstallFromFile.js +2 -5
  69. package/src/parts/ExtensionInstallFromGitHub/ExtensionInstallFromGitHub.js +1 -1
  70. package/src/parts/ExtensionInstallFromUrl/ExtensionInstallFromUrl.js +3 -3
  71. package/src/parts/ExtensionLink/ExtensionLink.js +19 -0
  72. package/src/parts/ExtensionManagement/ExtensionManagement.ipc.js +1 -1
  73. package/src/parts/ExtensionManagement/ExtensionManagementColorTheme.js +3 -2
  74. package/src/parts/ExtensionManagement/ExtensionManagementLanguages.js +7 -14
  75. package/src/parts/ExtensionManifest/ExtensionManifest.js +14 -4
  76. package/src/parts/ExtractZip/ExtractZip.js +1 -1
  77. package/src/parts/GetResponse/GetResponse.js +2 -1
  78. package/src/parts/GitLsFiles/GitLsFiles.ipc.js +2 -0
  79. package/src/parts/GitLsFiles/GitLsFiles.js +21 -5
  80. package/src/parts/Hash/Hash.js +7 -0
  81. package/src/parts/IpcChild/IpcChild.js +6 -0
  82. package/src/parts/IpcChildModule/IpcChildModule.js +12 -0
  83. package/src/parts/IpcChildType/IpcChildType.js +13 -0
  84. package/src/parts/IpcChildWithNodeForkedProcess/IpcChildWithNodeForkedProcess.js +19 -0
  85. package/src/parts/IpcChildWithNodeWorker/IpcChildWithNodeWorker.js +27 -0
  86. package/src/parts/MergeStacks/MergeStacks.js +19 -0
  87. package/src/parts/ModuleMap/ModuleMap.js +4 -1
  88. package/src/parts/NormalizeErrorLine/NormalizeErrorLine.js +9 -0
  89. package/src/parts/OutputChannel/OutputChannel.ipc.js +1 -1
  90. package/src/parts/ParentIpc/ParentIpc.js +6 -10
  91. package/src/parts/ParseInt/ParseInt.js +3 -0
  92. package/src/parts/Platform/Platform.js +16 -21
  93. package/src/parts/Preferences/Preferences.js +2 -1
  94. package/src/parts/PrettyError/PrettyError.js +12 -23
  95. package/src/parts/PrintPrettyError/PrintPrettyError.js +3 -0
  96. package/src/parts/Process/Process.js +2 -2
  97. package/src/parts/ProtocolType/ProtocolType.js +3 -0
  98. package/src/parts/RecentlyOpened/RecentlyOpened.js +1 -1
  99. package/src/parts/Stats/Stats.js +8 -11
  100. package/src/parts/SymLink/SymLink.js +2 -14
  101. package/src/parts/TextDocument/TextDocument.js +3 -1
  102. package/src/parts/VError/VError.js +5 -22
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "builtin.language-basics-jsx",
3
+ "name": "Language Basics Jsx",
4
+ "description": "Provides syntax highlighting and bracket matching in Jsx files.",
5
+ "languages": [
6
+ {
7
+ "id": "jsx",
8
+ "extensions": [".jsx"],
9
+ "tokenize": "src/tokenizeJsx.js",
10
+ "configuration": "./languageConfiguration.json"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,648 @@
1
+ /**
2
+ * @enum number
3
+ */
4
+ const State = {
5
+ None: 0,
6
+ TopLevelContent: 1,
7
+ AfterOpeningAngleBracket: 2,
8
+ InsideOpeningTag: 3,
9
+ InsideOpeningTagAndHasSeenWhitespace: 4,
10
+ AfterClosingTagAngleBrackets: 5,
11
+ AfterClosingTagName: 6,
12
+ AfterAttributeName: 7,
13
+ AfterAttributeEqualSign: 8,
14
+ InsideAttributeDoubleQuote: 9,
15
+ InsideBlockComment: 10,
16
+ InsideString: 11,
17
+ AfterKeyword: 12,
18
+ Keyword: 13,
19
+ InsideLineComment: 14,
20
+ InsideSingleQuoteString: 15,
21
+ InsideDoubleQuoteString: 16,
22
+ InsideBacktickString: 17,
23
+ AfterPropertyDot: 18,
24
+ InsideTag: 19,
25
+ }
26
+
27
+ /**
28
+ * @enum number
29
+ */
30
+ export const TokenType = {
31
+ None: 99999999,
32
+ Numeric: 30,
33
+ String: 50,
34
+ Whitespace: 777,
35
+ Comment: 60,
36
+ Text: 117,
37
+ PunctuationTag: 228,
38
+ TagName: 118,
39
+ AttributeName: 119,
40
+ Punctuation: 10,
41
+ Error: 141,
42
+ PunctuationString: 11,
43
+ NewLine: 771,
44
+ Keyword: 951,
45
+ VariableName: 952,
46
+ LanguageConstant: 13,
47
+ Regex: 14,
48
+ KeywordImport: 215,
49
+ KeywordControl: 881,
50
+ KeywordModifier: 882,
51
+ KeywordReturn: 883,
52
+ KeywordNew: 884,
53
+ FunctionName: 885,
54
+ KeywordThis: 886,
55
+ KeywordOperator: 887,
56
+ KeywordFunction: 889,
57
+ }
58
+
59
+ export const TokenMap = {
60
+ [TokenType.None]: 'None',
61
+ [TokenType.Numeric]: 'Numeric',
62
+ [TokenType.String]: 'String',
63
+ [TokenType.Whitespace]: 'Whitespace',
64
+ [TokenType.Comment]: 'Comment',
65
+ [TokenType.Text]: 'Text',
66
+ [TokenType.PunctuationTag]: 'PunctuationTag',
67
+ [TokenType.TagName]: 'TagName',
68
+ [TokenType.AttributeName]: 'AttributeName',
69
+ [TokenType.Punctuation]: 'Punctuation',
70
+ [TokenType.Error]: 'Error',
71
+ [TokenType.PunctuationString]: 'PunctuationString',
72
+ [TokenType.NewLine]: 'NewLine',
73
+ [TokenType.Keyword]: 'Keyword',
74
+ [TokenType.VariableName]: 'VariableName',
75
+ [TokenType.LanguageConstant]: 'LanguageConstant',
76
+ [TokenType.Regex]: 'Regex',
77
+ [TokenType.KeywordImport]: 'KeywordImport',
78
+ [TokenType.KeywordControl]: 'KeywordControl',
79
+ [TokenType.KeywordModifier]: 'KeywordModifier',
80
+ [TokenType.KeywordReturn]: 'KeywordReturn',
81
+ [TokenType.KeywordNew]: 'KeywordNew',
82
+ [TokenType.FunctionName]: 'Function',
83
+ [TokenType.KeywordThis]: 'KeywordThis',
84
+ [TokenType.KeywordOperator]: 'KeywordOperator',
85
+ [TokenType.KeywordFunction]: 'KeywordFunction',
86
+ }
87
+
88
+ const RE_KEYWORD =
89
+ /^(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|from|function|if|implements|import|in|Infinity|instanceof|interface|let|new|null|of|package|private|protected|public|return|super|switch|static|this|throw|try|true|typeof|undefined|var|void|while|with|yield)\b/
90
+ const RE_CURLY_OPEN = /^\{/
91
+ const RE_CURLY_CLOSE = /^\}/
92
+ const RE_SQUARE_OPEN = /^\[/
93
+ const RE_SQUARE_CLOSE = /^\]/
94
+ const RE_COMMA = /^,/
95
+ const RE_COLON = /^:/
96
+ const RE_NUMERIC =
97
+ /^((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)\b/
98
+ const RE_NUMERIC_OCTAL = /0(?:o|O)?[0-7][0-7_]*(n)?\b/
99
+ const RE_LINE_COMMENT_START = /^\/\//
100
+ const RE_LINE_COMMENT_CONTENT = /^[^\n]+/
101
+ const RE_NEWLINE_WHITESPACE = /^\n\s*/
102
+ const RE_BLOCK_COMMENT_START = /^\/\*/
103
+ const RE_BLOCK_COMMENT_CONTENT = /^.+?(?=\*\/)/
104
+ const RE_BLOCK_COMMENT_END = /^\*\//
105
+ const RE_UNKNOWN_VALUE = /^[^\}\{\s,"]+/
106
+ const RE_IMPORT = /^[a-zA-Z\.]+/
107
+ const RE_SEMICOLON = /^;/
108
+ const RE_VARIABLE_NAME = /^[a-zA-Z_$][a-zA-Z\d\_]*/
109
+ const RE_LINE_COMMENT = /^\/\/[^\n]*/
110
+ const RE_ROUND_OPEN = /^\(/
111
+ const RE_ROUND_CLOSE = /^\)/
112
+ const RE_DOT = /^\./
113
+ const RE_EQUAL_SIGN = /^=/
114
+ const RE_SINGLE_QUOTE = /^'/
115
+ const RE_PUNCTUATION = /^[\(\)=\+\-><\.:;\{\}\[\]!,&\|\^\?\*%~]/
116
+ const RE_SLASH = /^\//
117
+ const RE_ANYTHING_UNTIL_END = /^.+/s
118
+ const RE_WHITESPACE = /^\s+/
119
+ const RE_QUOTE_SINGLE = /^'/
120
+ const RE_QUOTE_DOUBLE = /^"/
121
+ const RE_QUOTE_BACKTICK = /^`/
122
+ const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^'\\]+/
123
+ const RE_STRING_DOUBLE_QUOTE_CONTENT = /^[^"\\]+/
124
+ const RE_STRING_BACKTICK_QUOTE_CONTENT = /^[^`\\\$]+/
125
+ const RE_STRING_ESCAPE = /^\\./
126
+ const RE_SHEBANG = /^#!.*/
127
+ const RE_FUNCTION_CALL_NAME = /^[\w]+(?=\s*(\(|\=\s*function|\=\s*\())/
128
+ const RE_DECORATOR = /^@\w+/
129
+ const RE_BACKSLASH = /^\\/
130
+ const RE_DOLLAR_CURLY_OPEN = /^\$\{/
131
+ const RE_DOLLAR = /^\$/
132
+ const RE_ANYTHING = /^.+/u
133
+ const RE_ANGLE_BRACKET_OPEN_TAG = /^<(?![\s!<=])/
134
+ const RE_ANGLE_BRACKET_CLOSE_TAG = /^<\/(?![\s!])/
135
+ const RE_TAGNAME = /^[!\w\:\.]+/
136
+ const RE_ANGLE_BRACKET_CLOSE = /^>/
137
+ const RE_ANGLE_BRACKET_ONLY = /^</
138
+ const RE_ANGLE_BRACKET_OPEN = /^</
139
+ const RE_ANY_TEXT = /^[^\n]+/
140
+ const RE_PUNCTUATION_SELF_CLOSING = /^\/>/
141
+ const RE_TAG_TEXT = /^[^\s>]+/
142
+ const RE_ATTRIBUTE_NAME = /^[a-zA-Z\d\-\:\_]+/
143
+ const RE_DOUBLE_QUOTE = /^"/
144
+ const RE_ATTRIBUTE_VALUE_UNQUOTED = /^[^<>\s]+/
145
+
146
+ // copied from https://github.com/PrismJS/prism/blob/master/components/prism-jsx.js#L57
147
+ const RE_REGEX =
148
+ /^((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*\]|\\.|[^/\\\[\r\n])+\/[dgimyus]{0,7}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/
149
+
150
+ const RE_VARIABLE_NAME_SPECIAL = /\p{L}/u
151
+ const RE_VARIABLE_NAME_SPECIAL_2 = /./u
152
+ const RE_SELF_CLOSING = /^\/>/
153
+ const RE_TEXT = /^[^<>\n\{\}\)]+/
154
+ const RE_EMPTY_FRAGMENT = /^<\s*\>/
155
+ const RE_VAR_CONST_LET_EXPORT =
156
+ /^\s*(?=(?:if|class|export|var|const|let)(?:\s+|$))/
157
+
158
+ export const initialLineState = {
159
+ state: State.TopLevelContent,
160
+ /**
161
+ * @type {any[]}
162
+ */
163
+ stack: [],
164
+ tag: '',
165
+ }
166
+
167
+ export const hasArrayReturn = true
168
+
169
+ /**
170
+ *
171
+ * @param {string} line
172
+ * @param {*} lineState
173
+ * @returns
174
+ */
175
+ export const tokenizeLine = (line, lineState) => {
176
+ let next = null
177
+ let index = 0
178
+ let tokens = []
179
+ let token = TokenType.None
180
+ let state = lineState.state
181
+ let stack = [...lineState.stack]
182
+ let tag = lineState.tag
183
+
184
+ while (index < line.length) {
185
+ const part = line.slice(index)
186
+ switch (state) {
187
+ case State.TopLevelContent:
188
+ if ((next = part.match(RE_WHITESPACE))) {
189
+ token = TokenType.Whitespace
190
+ state = State.TopLevelContent
191
+ } else if ((next = part.match(RE_KEYWORD))) {
192
+ switch (next[0]) {
193
+ case 'true':
194
+ case 'false':
195
+ case 'null':
196
+ case 'undefined':
197
+ token = TokenType.LanguageConstant
198
+ break
199
+ case 'import':
200
+ case 'export':
201
+ case 'from':
202
+ token = TokenType.KeywordImport
203
+ break
204
+ case 'as':
205
+ case 'switch':
206
+ case 'default':
207
+ case 'case':
208
+ case 'else':
209
+ case 'if':
210
+ case 'break':
211
+ case 'throw':
212
+ case 'for':
213
+ case 'try':
214
+ case 'catch':
215
+ case 'finally':
216
+ case 'continue':
217
+ case 'while':
218
+ token = TokenType.KeywordControl
219
+ break
220
+ case 'async':
221
+ case 'await':
222
+ token = TokenType.KeywordModifier
223
+ break
224
+ case 'return':
225
+ token = TokenType.KeywordReturn
226
+ break
227
+ case 'new':
228
+ token = TokenType.KeywordNew
229
+ break
230
+ case 'this':
231
+ token = TokenType.KeywordThis
232
+ break
233
+ case 'delete':
234
+ case 'typeof':
235
+ case 'in':
236
+ token = TokenType.KeywordOperator
237
+ break
238
+ case 'function':
239
+ token = TokenType.KeywordFunction
240
+ break
241
+ case 'Infinity':
242
+ token = TokenType.Numeric
243
+ state = State.TopLevelContent
244
+ break
245
+ case 'of':
246
+ token = TokenType.KeywordOperator
247
+ break
248
+ default:
249
+ token = TokenType.Keyword
250
+ break
251
+ }
252
+ state = State.TopLevelContent
253
+ } else if ((next = part.match(RE_FUNCTION_CALL_NAME))) {
254
+ token = TokenType.FunctionName
255
+ state = State.TopLevelContent
256
+ } else if ((next = part.match(RE_VARIABLE_NAME))) {
257
+ token = TokenType.VariableName
258
+ state = State.TopLevelContent
259
+ } else if ((next = part.match(RE_NUMERIC))) {
260
+ token = TokenType.Numeric
261
+ state = State.TopLevelContent
262
+ } else if ((next = part.match(RE_ANGLE_BRACKET_OPEN_TAG))) {
263
+ token = TokenType.PunctuationTag
264
+ state = State.AfterOpeningAngleBracket
265
+ } else if ((next = part.match(RE_CURLY_CLOSE))) {
266
+ token = TokenType.Punctuation
267
+ state = stack.pop() || State.TopLevelContent
268
+ } else if ((next = part.match(RE_CURLY_OPEN))) {
269
+ token = TokenType.Punctuation
270
+ stack.push(State.TopLevelContent)
271
+ state = State.TopLevelContent
272
+ } else if ((next = part.match(RE_PUNCTUATION))) {
273
+ token = TokenType.Punctuation
274
+ if (next[0] === '.') {
275
+ state = State.AfterPropertyDot
276
+ } else if (next[0] === '}') {
277
+ state = stack.pop() || State.TopLevelContent
278
+ } else {
279
+ state = State.TopLevelContent
280
+ }
281
+ } else if ((next = part.match(RE_SLASH))) {
282
+ if ((next = part.match(RE_BLOCK_COMMENT_START))) {
283
+ token = TokenType.Comment
284
+ state = State.InsideBlockComment
285
+ } else if ((next = part.match(RE_LINE_COMMENT_START))) {
286
+ token = TokenType.Comment
287
+ state = State.InsideLineComment
288
+ } else if ((next = part.match(RE_REGEX))) {
289
+ token = TokenType.Regex
290
+ state = State.TopLevelContent
291
+ } else {
292
+ next = part.match(RE_SLASH)
293
+ token = TokenType.Punctuation
294
+ state = State.TopLevelContent
295
+ }
296
+ } else if ((next = part.match(RE_QUOTE_SINGLE))) {
297
+ token = TokenType.Punctuation
298
+ state = State.InsideSingleQuoteString
299
+ } else if ((next = part.match(RE_QUOTE_DOUBLE))) {
300
+ token = TokenType.Punctuation
301
+ stack.push(state)
302
+ state = State.InsideDoubleQuoteString
303
+ } else if ((next = part.match(RE_QUOTE_BACKTICK))) {
304
+ token = TokenType.Punctuation
305
+ state = State.InsideBacktickString
306
+ } else if ((next = part.match(RE_NUMERIC_OCTAL))) {
307
+ token = TokenType.Numeric
308
+ state = State.TopLevelContent
309
+ } else if ((next = part.match(RE_SHEBANG))) {
310
+ token = TokenType.Comment
311
+ state = State.TopLevelContent
312
+ } else if ((next = part.match(RE_DECORATOR))) {
313
+ token = TokenType.VariableName
314
+ state = State.TopLevelContent
315
+ } else if ((next = part.match(RE_VARIABLE_NAME_SPECIAL))) {
316
+ token = TokenType.VariableName
317
+ state = State.TopLevelContent
318
+ } else if ((next = part.match(RE_ANYTHING))) {
319
+ token = TokenType.Text
320
+ state = State.TopLevelContent
321
+ } else {
322
+ throw new Error('no')
323
+ }
324
+ break
325
+ case State.Keyword:
326
+ const keyword = next[0]
327
+ switch (keyword) {
328
+ case 'true':
329
+ case 'false':
330
+ break
331
+ default:
332
+ token = TokenType.Keyword
333
+ state = State.TopLevelContent
334
+ break
335
+ }
336
+ break
337
+ case State.InsideLineComment:
338
+ if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
339
+ token = TokenType.Comment
340
+ state = State.TopLevelContent
341
+ } else {
342
+ throw new Error('no')
343
+ }
344
+ break
345
+ case State.InsideBlockComment:
346
+ if ((next = part.match(RE_BLOCK_COMMENT_END))) {
347
+ token = TokenType.Comment
348
+ state = State.TopLevelContent
349
+ } else if ((next = part.match(RE_BLOCK_COMMENT_CONTENT))) {
350
+ token = TokenType.Comment
351
+ state = State.InsideBlockComment
352
+ } else if ((next = part.match(RE_ANYTHING_UNTIL_END))) {
353
+ token = TokenType.Comment
354
+ state = State.InsideBlockComment
355
+ } else {
356
+ throw new Error('no')
357
+ }
358
+ break
359
+ case State.InsideSingleQuoteString:
360
+ if ((next = part.match(RE_QUOTE_SINGLE))) {
361
+ token = TokenType.Punctuation
362
+ state = State.TopLevelContent
363
+ } else if ((next = part.match(RE_STRING_SINGLE_QUOTE_CONTENT))) {
364
+ token = TokenType.String
365
+ state = State.InsideSingleQuoteString
366
+ } else if ((next = part.match(RE_STRING_ESCAPE))) {
367
+ token = TokenType.String
368
+ state = State.InsideSingleQuoteString
369
+ } else if ((next = part.match(RE_BACKSLASH))) {
370
+ token = TokenType.String
371
+ state = State.InsideSingleQuoteString
372
+ } else {
373
+ part
374
+ throw new Error('no')
375
+ }
376
+ break
377
+ case State.InsideDoubleQuoteString:
378
+ if ((next = part.match(RE_QUOTE_DOUBLE))) {
379
+ token = TokenType.Punctuation
380
+ state = stack.pop() || State.TopLevelContent
381
+ } else if ((next = part.match(RE_STRING_DOUBLE_QUOTE_CONTENT))) {
382
+ token = TokenType.String
383
+ state = State.InsideDoubleQuoteString
384
+ } else if ((next = part.match(RE_STRING_ESCAPE))) {
385
+ token = TokenType.String
386
+ state = State.InsideDoubleQuoteString
387
+ } else if ((next = part.match(RE_BACKSLASH))) {
388
+ token = TokenType.String
389
+ state = State.InsideDoubleQuoteString
390
+ } else {
391
+ throw new Error('no')
392
+ }
393
+ break
394
+ case State.InsideBacktickString:
395
+ if ((next = part.match(RE_QUOTE_BACKTICK))) {
396
+ token = TokenType.Punctuation
397
+ state = State.TopLevelContent
398
+ } else if ((next = part.match(RE_STRING_BACKTICK_QUOTE_CONTENT))) {
399
+ token = TokenType.String
400
+ state = State.InsideBacktickString
401
+ } else if ((next = part.match(RE_DOLLAR_CURLY_OPEN))) {
402
+ token = TokenType.Punctuation
403
+ state = State.TopLevelContent
404
+ stack.push(State.InsideBacktickString)
405
+ } else if ((next = part.match(RE_STRING_ESCAPE))) {
406
+ token = TokenType.String
407
+ state = State.InsideBacktickString
408
+ } else if ((next = part.match(RE_BACKSLASH))) {
409
+ token = TokenType.String
410
+ state = State.InsideDoubleQuoteString
411
+ } else if ((next = part.match(RE_DOLLAR))) {
412
+ token = TokenType.String
413
+ state = State.InsideBacktickString
414
+ } else {
415
+ throw new Error('no')
416
+ }
417
+ break
418
+ case State.AfterPropertyDot:
419
+ if ((next = part.match(RE_WHITESPACE))) {
420
+ token = TokenType.Whitespace
421
+ state = State.AfterPropertyDot
422
+ } else if ((next = part.match(RE_FUNCTION_CALL_NAME))) {
423
+ token = TokenType.FunctionName
424
+ state = State.TopLevelContent
425
+ } else if ((next = part.match(RE_VARIABLE_NAME))) {
426
+ token = TokenType.VariableName
427
+ state = State.TopLevelContent
428
+ } else if ((next = part.match(RE_LINE_COMMENT))) {
429
+ token = TokenType.Comment
430
+ state = State.InsideLineComment
431
+ } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
432
+ token = TokenType.Comment
433
+ state = State.InsideBlockComment
434
+ } else if ((next = part.match(RE_PUNCTUATION))) {
435
+ token = TokenType.Punctuation
436
+ state = State.TopLevelContent
437
+ } else if ((next = part.match(RE_VARIABLE_NAME_SPECIAL_2))) {
438
+ token = TokenType.VariableName
439
+ state = State.TopLevelContent
440
+ } else {
441
+ throw new Error('no')
442
+ }
443
+ break
444
+ case State.AfterOpeningAngleBracket:
445
+ if ((next = part.match(RE_TAGNAME))) {
446
+ token = TokenType.TagName
447
+ state = State.InsideOpeningTag
448
+ tag = next[0]
449
+ } else if ((next = part.match(RE_SLASH))) {
450
+ token = TokenType.PunctuationTag
451
+ state = State.AfterClosingTagAngleBrackets
452
+ } else if ((next = part.match(RE_ANGLE_BRACKET_CLOSE))) {
453
+ token = TokenType.PunctuationTag
454
+ state = State.TopLevelContent
455
+ } else if ((next = part.match(RE_ANGLE_BRACKET_OPEN))) {
456
+ token = TokenType.PunctuationTag
457
+ state = State.AfterOpeningAngleBracket
458
+ } else if ((next = part.match(RE_ANY_TEXT))) {
459
+ token = TokenType.Text
460
+ state = State.TopLevelContent
461
+ } else {
462
+ part //?
463
+ throw new Error('no')
464
+ }
465
+ break
466
+ case State.InsideOpeningTag:
467
+ if ((next = part.match(RE_ANGLE_BRACKET_CLOSE))) {
468
+ token = TokenType.PunctuationTag
469
+ state = State.InsideTag
470
+ } else if ((next = part.match(RE_WHITESPACE))) {
471
+ token = TokenType.Whitespace
472
+ state = State.InsideOpeningTagAndHasSeenWhitespace
473
+ } else if ((next = part.match(RE_PUNCTUATION_SELF_CLOSING))) {
474
+ token = TokenType.PunctuationTag
475
+ state = State.TopLevelContent
476
+ } else if ((next = part.match(RE_TAG_TEXT))) {
477
+ token = TokenType.Text
478
+ state = State.InsideOpeningTag
479
+ } else {
480
+ part //?
481
+ throw new Error('no')
482
+ }
483
+ break
484
+ case State.InsideOpeningTagAndHasSeenWhitespace:
485
+ if ((next = part.match(RE_ATTRIBUTE_NAME))) {
486
+ token = TokenType.AttributeName
487
+ state = State.AfterAttributeName
488
+ } else if ((next = part.match(RE_SELF_CLOSING))) {
489
+ token = TokenType.PunctuationTag
490
+ state = State.TopLevelContent
491
+ } else if ((next = part.match(RE_ANGLE_BRACKET_CLOSE))) {
492
+ token = TokenType.PunctuationTag
493
+ state = State.InsideTag
494
+ } else if ((next = part.match(RE_CURLY_OPEN))) {
495
+ token = TokenType.Punctuation
496
+ state = State.TopLevelContent
497
+ stack.push(State.InsideOpeningTag)
498
+ } else if ((next = part.match(RE_TAG_TEXT))) {
499
+ token = TokenType.Text
500
+ state = State.TopLevelContent
501
+ } else {
502
+ part //?
503
+ throw new Error('no')
504
+ }
505
+ break
506
+ case State.AfterClosingTagAngleBrackets:
507
+ if ((next = part.match(RE_TAGNAME))) {
508
+ token = TokenType.TagName
509
+ state = State.AfterClosingTagName
510
+ } else if ((next = part.match(RE_WHITESPACE))) {
511
+ token = TokenType.Whitespace
512
+ state = State.TopLevelContent
513
+ } else if ((next = part.match(RE_ANGLE_BRACKET_CLOSE))) {
514
+ token = TokenType.PunctuationTag
515
+ state = State.InsideTag
516
+ } else if ((next = part.match(RE_ANY_TEXT))) {
517
+ token = TokenType.Text
518
+ state = State.TopLevelContent
519
+ } else {
520
+ part //?
521
+ throw new Error('no')
522
+ }
523
+ break
524
+ case State.AfterClosingTagName:
525
+ if ((next = part.match(RE_ANGLE_BRACKET_CLOSE))) {
526
+ token = TokenType.PunctuationTag
527
+ state = State.InsideTag
528
+ } else if ((next = part.match(RE_TEXT))) {
529
+ token = TokenType.Text
530
+ state = State.TopLevelContent
531
+ } else {
532
+ throw new Error('no')
533
+ }
534
+ break
535
+ case State.InsideTag:
536
+ if ((next = part.match(RE_TEXT))) {
537
+ token = TokenType.Text
538
+ state = State.InsideTag
539
+ if (index === 0) {
540
+ const match = part.match(RE_VAR_CONST_LET_EXPORT)
541
+ if (match) {
542
+ next = match
543
+ token = TokenType.Whitespace
544
+ state = State.TopLevelContent
545
+ }
546
+ }
547
+ } else if ((next = part.match(RE_ANGLE_BRACKET_OPEN_TAG))) {
548
+ token = TokenType.PunctuationTag
549
+ state = State.AfterOpeningAngleBracket
550
+ } else if ((next = part.match(RE_ANGLE_BRACKET_CLOSE_TAG))) {
551
+ token = TokenType.PunctuationTag
552
+ state = State.AfterClosingTagAngleBrackets
553
+ } else if ((next = part.match(RE_CURLY_OPEN))) {
554
+ token = TokenType.Punctuation
555
+ state = State.TopLevelContent
556
+ stack.push(State.InsideTag)
557
+ } else if ((next = part.match(RE_CURLY_CLOSE))) {
558
+ token = TokenType.Punctuation
559
+ state = stack.pop() || State.TopLevelContent
560
+ } else if ((next = part.match(RE_ROUND_CLOSE))) {
561
+ if (stack.length === 0) {
562
+ token = TokenType.Punctuation
563
+ state = State.TopLevelContent
564
+ } else {
565
+ token = TokenType.Text
566
+ state = State.InsideTag
567
+ }
568
+ } else if ((next = part.match(RE_EMPTY_FRAGMENT))) {
569
+ token = TokenType.PunctuationTag
570
+ state = State.InsideTag
571
+ } else {
572
+ part
573
+ throw new Error('no')
574
+ }
575
+ break
576
+ case State.AfterAttributeName:
577
+ if ((next = part.match(RE_ANGLE_BRACKET_CLOSE))) {
578
+ token = TokenType.PunctuationTag
579
+ state = State.InsideTag
580
+ } else if ((next = part.match(RE_EQUAL_SIGN))) {
581
+ token = TokenType.Punctuation
582
+ state = State.AfterAttributeEqualSign
583
+ } else if ((next = part.match(RE_DOUBLE_QUOTE))) {
584
+ token = TokenType.PunctuationString
585
+ state = State.InsideDoubleQuoteString
586
+ } else if ((next = part.match(RE_SINGLE_QUOTE))) {
587
+ token = TokenType.PunctuationString
588
+ state = State.InsideSingleQuoteString
589
+ } else if ((next = part.match(RE_TAG_TEXT))) {
590
+ token = TokenType.Text
591
+ state = State.InsideOpeningTag
592
+ } else if ((next = part.match(RE_WHITESPACE))) {
593
+ token = TokenType.Whitespace
594
+ state = State.InsideOpeningTagAndHasSeenWhitespace
595
+ } else {
596
+ // TODO check quotation mark
597
+ part //?
598
+ throw new Error('no')
599
+ }
600
+ break
601
+ case State.AfterAttributeEqualSign:
602
+ if ((next = part.match(RE_DOUBLE_QUOTE))) {
603
+ token = TokenType.PunctuationString
604
+ state = State.InsideDoubleQuoteString
605
+ stack.push(State.InsideOpeningTag)
606
+ } else if ((next = part.match(RE_SINGLE_QUOTE))) {
607
+ token = TokenType.PunctuationString
608
+ state = State.InsideSingleQuoteString
609
+ stack.push(State.InsideOpeningTag)
610
+ } else if ((next = part.match(RE_CURLY_OPEN))) {
611
+ token = TokenType.Punctuation
612
+ state = State.TopLevelContent
613
+ stack.push(State.InsideOpeningTag)
614
+ } else if ((next = part.match(RE_ANGLE_BRACKET_CLOSE))) {
615
+ token = TokenType.PunctuationTag
616
+ state = State.TopLevelContent
617
+ } else if ((next = part.match(RE_ATTRIBUTE_VALUE_UNQUOTED))) {
618
+ token = TokenType.String
619
+ state = State.InsideOpeningTag
620
+ } else {
621
+ part
622
+ throw new Error('no')
623
+ }
624
+ break
625
+ default:
626
+ state
627
+ throw new Error('no')
628
+ }
629
+ const tokenLength = next[0].length
630
+ index += tokenLength
631
+ tokens.push(token, tokenLength)
632
+ }
633
+ if (state === State.InsideLineComment) {
634
+ state = State.TopLevelContent
635
+ }
636
+ if (state === State.InsideSingleQuoteString && !line.endsWith('\\')) {
637
+ state = State.TopLevelContent
638
+ }
639
+ if (state === State.InsideTag && (line.endsWith(',') || line.endsWith(';'))) {
640
+ state = stack.pop() || State.TopLevelContent
641
+ }
642
+ return {
643
+ state,
644
+ tokens,
645
+ stack,
646
+ tag,
647
+ }
648
+ }