@runeditrun/rer 0.2.83 → 0.2.84

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 (157) hide show
  1. package/cli/authoring.mjs +1 -0
  2. package/cli/contract.mjs +1 -1
  3. package/cli/demo-host.mjs +5 -1
  4. package/cli/demo.mjs +6 -1
  5. package/cli/export.mjs +1 -1
  6. package/cli/parse.mjs +1 -1
  7. package/edition-authoring/base-copies.mjs +72 -25
  8. package/edition-authoring/copy-checkout.mjs +7 -120
  9. package/edition-authoring/edition-migrations.mjs +41 -0
  10. package/edition-authoring/files.mjs +67 -0
  11. package/edition-authoring/lock.mjs +2 -2
  12. package/edition-authoring/module-closure.mjs +232 -0
  13. package/edition-authoring/module-edges.mjs +100 -0
  14. package/edition-authoring/module-resolution.mjs +66 -0
  15. package/edition-authoring/module-syntax.mjs +57 -0
  16. package/edition-authoring/package-target.mjs +92 -0
  17. package/edition-authoring/runtime-dependencies.mjs +74 -97
  18. package/edition-authoring/vendor/babel-parser/LICENSE +22 -0
  19. package/edition-authoring/vendor/babel-parser/README.md +21 -0
  20. package/edition-authoring/vendor/babel-parser/babel-helper-string-parser/index.mjs +292 -0
  21. package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/identifier.mjs +66 -0
  22. package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/index.mjs +13 -0
  23. package/edition-authoring/vendor/babel-parser/babel-helper-validator-identifier/keyword.mjs +31 -0
  24. package/edition-authoring/vendor/babel-parser/babel-parser/index.mjs +99 -0
  25. package/edition-authoring/vendor/babel-parser/babel-parser/options.mjs +81 -0
  26. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/bind-operator-errors.mjs +8 -0
  27. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/module-errors.mjs +15 -0
  28. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/parse-expression-errors.mjs +10 -0
  29. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/pipeline-operator-errors.mjs +29 -0
  30. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/standard-errors.mjs +224 -0
  31. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/strict-mode-errors.mjs +17 -0
  32. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error/to-node-description.mjs +31 -0
  33. package/edition-authoring/vendor/babel-parser/babel-parser/parse-error.mjs +114 -0
  34. package/edition-authoring/vendor/babel-parser/babel-parser/parser/base.mjs +34 -0
  35. package/edition-authoring/vendor/babel-parser/babel-parser/parser/comments.mjs +199 -0
  36. package/edition-authoring/vendor/babel-parser/babel-parser/parser/expression.mjs +1794 -0
  37. package/edition-authoring/vendor/babel-parser/babel-parser/parser/index.mjs +76 -0
  38. package/edition-authoring/vendor/babel-parser/babel-parser/parser/lval.mjs +439 -0
  39. package/edition-authoring/vendor/babel-parser/babel-parser/parser/node.mjs +111 -0
  40. package/edition-authoring/vendor/babel-parser/babel-parser/parser/statement.mjs +1962 -0
  41. package/edition-authoring/vendor/babel-parser/babel-parser/parser/util.mjs +244 -0
  42. package/edition-authoring/vendor/babel-parser/babel-parser/plugin-utils.mjs +116 -0
  43. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/estree.mjs +417 -0
  44. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/index.mjs +2412 -0
  45. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/flow/scope.mjs +37 -0
  46. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/index.mjs +420 -0
  47. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/jsx/xhtml.mjs +261 -0
  48. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/placeholders.mjs +205 -0
  49. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/index.mjs +2889 -0
  50. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/typescript/scope.mjs +115 -0
  51. package/edition-authoring/vendor/babel-parser/babel-parser/plugins/v8intrinsic.mjs +26 -0
  52. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/context.mjs +22 -0
  53. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/index.mjs +1037 -0
  54. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/state.mjs +178 -0
  55. package/edition-authoring/vendor/babel-parser/babel-parser/tokenizer/types.mjs +583 -0
  56. package/edition-authoring/vendor/babel-parser/babel-parser/types.mjs +1 -0
  57. package/edition-authoring/vendor/babel-parser/babel-parser/util/class-scope.mjs +82 -0
  58. package/edition-authoring/vendor/babel-parser/babel-parser/util/expression-scope.mjs +121 -0
  59. package/edition-authoring/vendor/babel-parser/babel-parser/util/identifier.mjs +23 -0
  60. package/edition-authoring/vendor/babel-parser/babel-parser/util/location.mjs +34 -0
  61. package/edition-authoring/vendor/babel-parser/babel-parser/util/production-parameter.mjs +40 -0
  62. package/edition-authoring/vendor/babel-parser/babel-parser/util/scope.mjs +173 -0
  63. package/edition-authoring/vendor/babel-parser/babel-parser/util/scopeflags.mjs +66 -0
  64. package/edition-authoring/vendor/babel-parser/babel-parser/util/whitespace.mjs +61 -0
  65. package/edition-authoring/vendor/yaml/LICENSE +13 -0
  66. package/edition-authoring/vendor/yaml/README.md +11 -0
  67. package/edition-authoring/vendor/yaml/compose/compose-collection.mjs +88 -0
  68. package/edition-authoring/vendor/yaml/compose/compose-doc.mjs +43 -0
  69. package/edition-authoring/vendor/yaml/compose/compose-node.mjs +110 -0
  70. package/edition-authoring/vendor/yaml/compose/compose-scalar.mjs +86 -0
  71. package/edition-authoring/vendor/yaml/compose/composer.mjs +218 -0
  72. package/edition-authoring/vendor/yaml/compose/resolve-block-map.mjs +115 -0
  73. package/edition-authoring/vendor/yaml/compose/resolve-block-scalar.mjs +198 -0
  74. package/edition-authoring/vendor/yaml/compose/resolve-block-seq.mjs +49 -0
  75. package/edition-authoring/vendor/yaml/compose/resolve-end.mjs +37 -0
  76. package/edition-authoring/vendor/yaml/compose/resolve-flow-collection.mjs +207 -0
  77. package/edition-authoring/vendor/yaml/compose/resolve-flow-scalar.mjs +228 -0
  78. package/edition-authoring/vendor/yaml/compose/resolve-props.mjs +148 -0
  79. package/edition-authoring/vendor/yaml/compose/util-contains-newline.mjs +34 -0
  80. package/edition-authoring/vendor/yaml/compose/util-empty-scalar-position.mjs +27 -0
  81. package/edition-authoring/vendor/yaml/compose/util-flow-indent-check.mjs +15 -0
  82. package/edition-authoring/vendor/yaml/compose/util-map-includes.mjs +13 -0
  83. package/edition-authoring/vendor/yaml/doc/Document.mjs +333 -0
  84. package/edition-authoring/vendor/yaml/doc/anchors.mjs +74 -0
  85. package/edition-authoring/vendor/yaml/doc/applyReviver.mjs +54 -0
  86. package/edition-authoring/vendor/yaml/doc/createNode.mjs +88 -0
  87. package/edition-authoring/vendor/yaml/doc/directives.mjs +176 -0
  88. package/edition-authoring/vendor/yaml/errors.mjs +57 -0
  89. package/edition-authoring/vendor/yaml/index.mjs +17 -0
  90. package/edition-authoring/vendor/yaml/log.mjs +11 -0
  91. package/edition-authoring/vendor/yaml/nodes/Alias.mjs +119 -0
  92. package/edition-authoring/vendor/yaml/nodes/Collection.mjs +147 -0
  93. package/edition-authoring/vendor/yaml/nodes/Node.mjs +38 -0
  94. package/edition-authoring/vendor/yaml/nodes/Pair.mjs +36 -0
  95. package/edition-authoring/vendor/yaml/nodes/Scalar.mjs +24 -0
  96. package/edition-authoring/vendor/yaml/nodes/YAMLMap.mjs +144 -0
  97. package/edition-authoring/vendor/yaml/nodes/YAMLSeq.mjs +113 -0
  98. package/edition-authoring/vendor/yaml/nodes/addPairToJSMap.mjs +62 -0
  99. package/edition-authoring/vendor/yaml/nodes/identity.mjs +36 -0
  100. package/edition-authoring/vendor/yaml/nodes/toJS.mjs +35 -0
  101. package/edition-authoring/vendor/yaml/parse/cst-scalar.mjs +214 -0
  102. package/edition-authoring/vendor/yaml/parse/cst-stringify.mjs +61 -0
  103. package/edition-authoring/vendor/yaml/parse/cst-visit.mjs +97 -0
  104. package/edition-authoring/vendor/yaml/parse/cst.mjs +98 -0
  105. package/edition-authoring/vendor/yaml/parse/lexer.mjs +722 -0
  106. package/edition-authoring/vendor/yaml/parse/line-counter.mjs +39 -0
  107. package/edition-authoring/vendor/yaml/parse/parser.mjs +975 -0
  108. package/edition-authoring/vendor/yaml/public-api.mjs +102 -0
  109. package/edition-authoring/vendor/yaml/schema/Schema.mjs +37 -0
  110. package/edition-authoring/vendor/yaml/schema/common/map.mjs +17 -0
  111. package/edition-authoring/vendor/yaml/schema/common/null.mjs +15 -0
  112. package/edition-authoring/vendor/yaml/schema/common/seq.mjs +17 -0
  113. package/edition-authoring/vendor/yaml/schema/common/string.mjs +14 -0
  114. package/edition-authoring/vendor/yaml/schema/core/bool.mjs +19 -0
  115. package/edition-authoring/vendor/yaml/schema/core/float.mjs +43 -0
  116. package/edition-authoring/vendor/yaml/schema/core/int.mjs +38 -0
  117. package/edition-authoring/vendor/yaml/schema/core/schema.mjs +23 -0
  118. package/edition-authoring/vendor/yaml/schema/json/schema.mjs +62 -0
  119. package/edition-authoring/vendor/yaml/schema/tags.mjs +96 -0
  120. package/edition-authoring/vendor/yaml/schema/yaml-1.1/binary.mjs +59 -0
  121. package/edition-authoring/vendor/yaml/schema/yaml-1.1/bool.mjs +26 -0
  122. package/edition-authoring/vendor/yaml/schema/yaml-1.1/float.mjs +46 -0
  123. package/edition-authoring/vendor/yaml/schema/yaml-1.1/int.mjs +71 -0
  124. package/edition-authoring/vendor/yaml/schema/yaml-1.1/merge.mjs +67 -0
  125. package/edition-authoring/vendor/yaml/schema/yaml-1.1/omap.mjs +74 -0
  126. package/edition-authoring/vendor/yaml/schema/yaml-1.1/pairs.mjs +78 -0
  127. package/edition-authoring/vendor/yaml/schema/yaml-1.1/schema.mjs +39 -0
  128. package/edition-authoring/vendor/yaml/schema/yaml-1.1/set.mjs +93 -0
  129. package/edition-authoring/vendor/yaml/schema/yaml-1.1/timestamp.mjs +101 -0
  130. package/edition-authoring/vendor/yaml/stringify/foldFlowLines.mjs +146 -0
  131. package/edition-authoring/vendor/yaml/stringify/stringify.mjs +130 -0
  132. package/edition-authoring/vendor/yaml/stringify/stringifyCollection.mjs +155 -0
  133. package/edition-authoring/vendor/yaml/stringify/stringifyComment.mjs +20 -0
  134. package/edition-authoring/vendor/yaml/stringify/stringifyDocument.mjs +85 -0
  135. package/edition-authoring/vendor/yaml/stringify/stringifyNumber.mjs +25 -0
  136. package/edition-authoring/vendor/yaml/stringify/stringifyPair.mjs +150 -0
  137. package/edition-authoring/vendor/yaml/stringify/stringifyString.mjs +338 -0
  138. package/edition-authoring/vendor/yaml/util.mjs +11 -0
  139. package/edition-authoring/vendor/yaml/visit.mjs +233 -0
  140. package/edition-authoring/workflow-copies.mjs +125 -0
  141. package/edition-authoring/workflow-scripts.mjs +112 -0
  142. package/foundation/runtime/contract-docs.mjs +753 -0
  143. package/global/CHANGELOG.md +22 -3
  144. package/modules/demo/declaration.mjs +1 -4
  145. package/modules/demo/vite.mjs +1 -1
  146. package/modules/deploy-kit/README.md +1 -1
  147. package/modules/deploy-kit/templates.mjs +3 -3
  148. package/onboarding/operator-installer.mjs +2 -2
  149. package/package.json +1 -1
  150. package/scripts/publish-check/README.md +6 -0
  151. package/scripts/publish-check/history_scan.py +5 -3
  152. package/scripts/publish-check/hygiene_config.py +2 -1
  153. package/scripts/publish-check/report.py +9 -3
  154. package/scripts/publish-check/third-party-notices.json +13 -0
  155. package/scripts/publish-check/third_party_notices.py +38 -0
  156. package/scripts/publish-check/tree_scan.py +6 -0
  157. package/scripts/publish-check.mjs +1 -1
@@ -0,0 +1,1962 @@
1
+ // Generated from Babel v7.29.8 (MIT); see README.md.
2
+ import { tokenIsIdentifier, tokenIsKeywordOrIdentifier, tokenIsLoop, tokenIsTemplate, tt, getExportedToken } from "../tokenizer/types.mjs";
3
+ import ExpressionParser from "./expression.mjs";
4
+ import { Errors } from "../parse-error.mjs";
5
+ import { isIdentifierChar, isIdentifierStart } from "../util/identifier.mjs";
6
+ import { ScopeFlag, ClassElementType, BindingFlag } from "../util/scopeflags.mjs";
7
+ import { ExpressionErrors } from "./util.mjs";
8
+ import { ParamKind, functionFlags } from "../util/production-parameter.mjs";
9
+ import { newExpressionScope, newParameterDeclarationScope } from "../util/expression-scope.mjs";
10
+ import { OptionFlags } from "../options.mjs";
11
+ import { Token } from "../tokenizer/index.mjs";
12
+ import { createPositionWithColumnOffset } from "../util/location.mjs";
13
+ import { ParseBindingListFlags } from "./lval.mjs";
14
+ import { LoopLabelKind } from "../tokenizer/state.mjs";
15
+ const loopLabel = {
16
+ kind: LoopLabelKind.Loop
17
+ }, switchLabel = {
18
+ kind: LoopLabelKind.Switch
19
+ };
20
+ var ParseFunctionFlag = {
21
+ Expression: 0,
22
+ Declaration: 1,
23
+ HangingDeclaration: 2,
24
+ NullableId: 4,
25
+ Async: 8
26
+ };
27
+ var ParseStatementFlag = {
28
+ StatementOnly: 0,
29
+ AllowImportExport: 1,
30
+ AllowDeclaration: 2,
31
+ AllowFunctionDeclaration: 4,
32
+ AllowLabeledFunction: 8
33
+ };
34
+ const loneSurrogate = /[\uD800-\uDFFF]/u;
35
+ const keywordRelationalOperator = /in(?:stanceof)?/y;
36
+ function babel7CompatTokens(tokens, input, startIndex) {
37
+ for (let i = 0; i < tokens.length; i++) {
38
+ const token = tokens[i];
39
+ const {
40
+ type
41
+ } = token;
42
+ if (typeof type === "number") {
43
+ {
44
+ if (type === tt.privateName) {
45
+ const {
46
+ loc,
47
+ start,
48
+ value,
49
+ end
50
+ } = token;
51
+ const hashEndPos = start + 1;
52
+ const hashEndLoc = createPositionWithColumnOffset(loc.start, 1);
53
+ tokens.splice(i, 1, new Token({
54
+ type: getExportedToken(tt.hash),
55
+ value: "#",
56
+ start,
57
+ end: hashEndPos,
58
+ startLoc: loc.start,
59
+ endLoc: hashEndLoc
60
+ }), new Token({
61
+ type: getExportedToken(tt.name),
62
+ value,
63
+ start: hashEndPos,
64
+ end,
65
+ startLoc: hashEndLoc,
66
+ endLoc: loc.end
67
+ }));
68
+ i++;
69
+ continue;
70
+ }
71
+ if (tokenIsTemplate(type)) {
72
+ const {
73
+ loc,
74
+ start,
75
+ value,
76
+ end
77
+ } = token;
78
+ const backquoteEnd = start + 1;
79
+ const backquoteEndLoc = createPositionWithColumnOffset(loc.start, 1);
80
+ let startToken;
81
+ if (input.charCodeAt(start - startIndex) === 96) {
82
+ startToken = new Token({
83
+ type: getExportedToken(tt.backQuote),
84
+ value: "`",
85
+ start,
86
+ end: backquoteEnd,
87
+ startLoc: loc.start,
88
+ endLoc: backquoteEndLoc
89
+ });
90
+ } else {
91
+ startToken = new Token({
92
+ type: getExportedToken(tt.braceR),
93
+ value: "}",
94
+ start,
95
+ end: backquoteEnd,
96
+ startLoc: loc.start,
97
+ endLoc: backquoteEndLoc
98
+ });
99
+ }
100
+ let templateValue, templateElementEnd, templateElementEndLoc, endToken;
101
+ if (type === tt.templateTail) {
102
+ templateElementEnd = end - 1;
103
+ templateElementEndLoc = createPositionWithColumnOffset(loc.end, -1);
104
+ templateValue = value === null ? null : value.slice(1, -1);
105
+ endToken = new Token({
106
+ type: getExportedToken(tt.backQuote),
107
+ value: "`",
108
+ start: templateElementEnd,
109
+ end,
110
+ startLoc: templateElementEndLoc,
111
+ endLoc: loc.end
112
+ });
113
+ } else {
114
+ templateElementEnd = end - 2;
115
+ templateElementEndLoc = createPositionWithColumnOffset(loc.end, -2);
116
+ templateValue = value === null ? null : value.slice(1, -2);
117
+ endToken = new Token({
118
+ type: getExportedToken(tt.dollarBraceL),
119
+ value: "${",
120
+ start: templateElementEnd,
121
+ end,
122
+ startLoc: templateElementEndLoc,
123
+ endLoc: loc.end
124
+ });
125
+ }
126
+ tokens.splice(i, 1, startToken, new Token({
127
+ type: getExportedToken(tt.template),
128
+ value: templateValue,
129
+ start: backquoteEnd,
130
+ end: templateElementEnd,
131
+ startLoc: backquoteEndLoc,
132
+ endLoc: templateElementEndLoc
133
+ }), endToken);
134
+ i += 2;
135
+ continue;
136
+ }
137
+ }
138
+ token.type = getExportedToken(type);
139
+ }
140
+ }
141
+ return tokens;
142
+ }
143
+ class StatementParser extends ExpressionParser {
144
+ parseTopLevel(file, program) {
145
+ file.program = this.parseProgram(program, tt.eof, this.options.sourceType === "module" ? "module" : "script");
146
+ file.comments = this.comments;
147
+ if (this.optionFlags & OptionFlags.Tokens) {
148
+ file.tokens = babel7CompatTokens(this.tokens, this.input, this.startIndex);
149
+ }
150
+ return this.finishNode(file, "File");
151
+ }
152
+ parseProgram(program, end, sourceType) {
153
+ program.sourceType = sourceType;
154
+ program.interpreter = this.parseInterpreterDirective();
155
+ this.parseBlockBody(program, true, true, end);
156
+ if (this.inModule) {
157
+ if (!(this.optionFlags & OptionFlags.AllowUndeclaredExports) && this.scope.undefinedExports.size > 0) {
158
+ for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
159
+ this.raise(Errors.ModuleExportUndefined, at, {
160
+ localName
161
+ });
162
+ }
163
+ }
164
+ this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
165
+ }
166
+ let finishedProgram;
167
+ if (end === tt.eof) {
168
+ finishedProgram = this.finishNode(program, "Program");
169
+ } else {
170
+ finishedProgram = this.finishNodeAt(program, "Program", createPositionWithColumnOffset(this.state.startLoc, -1));
171
+ }
172
+ return finishedProgram;
173
+ }
174
+ stmtToDirective(stmt) {
175
+ const directive = this.castNodeTo(stmt, "Directive");
176
+ const directiveLiteral = this.castNodeTo(stmt.expression, "DirectiveLiteral");
177
+ const expressionValue = directiveLiteral.value;
178
+ const raw = this.input.slice(this.offsetToSourcePos(directiveLiteral.start), this.offsetToSourcePos(directiveLiteral.end));
179
+ const val = directiveLiteral.value = raw.slice(1, -1);
180
+ this.addExtra(directiveLiteral, "raw", raw);
181
+ this.addExtra(directiveLiteral, "rawValue", val);
182
+ this.addExtra(directiveLiteral, "expressionValue", expressionValue);
183
+ directive.value = directiveLiteral;
184
+ delete stmt.expression;
185
+ return directive;
186
+ }
187
+ parseInterpreterDirective() {
188
+ if (!this.match(tt.interpreterDirective)) {
189
+ return null;
190
+ }
191
+ const node = this.startNode();
192
+ node.value = this.state.value;
193
+ this.next();
194
+ return this.finishNode(node, "InterpreterDirective");
195
+ }
196
+ isLet() {
197
+ if (!this.isContextual(tt._let)) {
198
+ return false;
199
+ }
200
+ return this.hasFollowingBindingAtom();
201
+ }
202
+ isUsing() {
203
+ if (!this.isContextual(tt._using)) {
204
+ return false;
205
+ }
206
+ return this.nextTokenIsIdentifierOnSameLine();
207
+ }
208
+ isForUsing() {
209
+ if (!this.isContextual(tt._using)) {
210
+ return false;
211
+ }
212
+ const next = this.nextTokenInLineStart();
213
+ const nextCh = this.codePointAtPos(next);
214
+ if (this.isUnparsedContextual(next, "of")) {
215
+ const nextCharAfterOf = this.lookaheadCharCodeSince(next + 2);
216
+ if (nextCharAfterOf !== 61 && nextCharAfterOf !== 58 && nextCharAfterOf !== 59) {
217
+ return false;
218
+ }
219
+ }
220
+ if (this.chStartsBindingIdentifier(nextCh, next) || this.isUnparsedContextual(next, "void")) {
221
+ return true;
222
+ }
223
+ return false;
224
+ }
225
+ nextTokenIsIdentifierOnSameLine() {
226
+ const next = this.nextTokenInLineStart();
227
+ const nextCh = this.codePointAtPos(next);
228
+ return this.chStartsBindingIdentifier(nextCh, next);
229
+ }
230
+ isAwaitUsing() {
231
+ if (!this.isContextual(tt._await)) {
232
+ return false;
233
+ }
234
+ let next = this.nextTokenInLineStart();
235
+ if (this.isUnparsedContextual(next, "using")) {
236
+ next = this.nextTokenInLineStartSince(next + 5);
237
+ const nextCh = this.codePointAtPos(next);
238
+ if (this.chStartsBindingIdentifier(nextCh, next)) {
239
+ return true;
240
+ }
241
+ }
242
+ return false;
243
+ }
244
+ chStartsBindingIdentifier(ch, pos) {
245
+ if (isIdentifierStart(ch)) {
246
+ keywordRelationalOperator.lastIndex = pos;
247
+ if (keywordRelationalOperator.test(this.input)) {
248
+ const endCh = this.codePointAtPos(keywordRelationalOperator.lastIndex);
249
+ if (!isIdentifierChar(endCh) && endCh !== 92) {
250
+ return false;
251
+ }
252
+ }
253
+ return true;
254
+ } else if (ch === 92) {
255
+ return true;
256
+ } else {
257
+ return false;
258
+ }
259
+ }
260
+ chStartsBindingPattern(ch) {
261
+ return ch === 91 || ch === 123;
262
+ }
263
+ hasFollowingBindingAtom() {
264
+ const next = this.nextTokenStart();
265
+ const nextCh = this.codePointAtPos(next);
266
+ return this.chStartsBindingPattern(nextCh) || this.chStartsBindingIdentifier(nextCh, next);
267
+ }
268
+ hasInLineFollowingBindingIdentifierOrBrace() {
269
+ const next = this.nextTokenInLineStart();
270
+ const nextCh = this.codePointAtPos(next);
271
+ return nextCh === 123 || this.chStartsBindingIdentifier(nextCh, next);
272
+ }
273
+ allowsUsing() {
274
+ return (this.scope.inModule || !this.scope.inTopLevel) && !this.scope.inBareCaseStatement;
275
+ }
276
+ parseModuleItem() {
277
+ return this.parseStatementLike(ParseStatementFlag.AllowImportExport | ParseStatementFlag.AllowDeclaration | ParseStatementFlag.AllowFunctionDeclaration | ParseStatementFlag.AllowLabeledFunction);
278
+ }
279
+ parseStatementListItem() {
280
+ return this.parseStatementLike(ParseStatementFlag.AllowDeclaration | ParseStatementFlag.AllowFunctionDeclaration | (!this.options.annexB || this.state.strict ? 0 : ParseStatementFlag.AllowLabeledFunction));
281
+ }
282
+ parseStatementOrSloppyAnnexBFunctionDeclaration(allowLabeledFunction = false) {
283
+ let flags = ParseStatementFlag.StatementOnly;
284
+ if (this.options.annexB && !this.state.strict) {
285
+ flags |= ParseStatementFlag.AllowFunctionDeclaration;
286
+ if (allowLabeledFunction) {
287
+ flags |= ParseStatementFlag.AllowLabeledFunction;
288
+ }
289
+ }
290
+ return this.parseStatementLike(flags);
291
+ }
292
+ parseStatement() {
293
+ return this.parseStatementLike(ParseStatementFlag.StatementOnly);
294
+ }
295
+ parseStatementLike(flags) {
296
+ let decorators = null;
297
+ if (this.match(tt.at)) {
298
+ decorators = this.parseDecorators(true);
299
+ }
300
+ return this.parseStatementContent(flags, decorators);
301
+ }
302
+ parseStatementContent(flags, decorators) {
303
+ const startType = this.state.type;
304
+ const node = this.startNode();
305
+ const allowDeclaration = !!(flags & ParseStatementFlag.AllowDeclaration);
306
+ const allowFunctionDeclaration = !!(flags & ParseStatementFlag.AllowFunctionDeclaration);
307
+ const topLevel = flags & ParseStatementFlag.AllowImportExport;
308
+ switch (startType) {
309
+ case tt._break:
310
+ return this.parseBreakContinueStatement(node, true);
311
+ case tt._continue:
312
+ return this.parseBreakContinueStatement(node, false);
313
+ case tt._debugger:
314
+ return this.parseDebuggerStatement(node);
315
+ case tt._do:
316
+ return this.parseDoWhileStatement(node);
317
+ case tt._for:
318
+ return this.parseForStatement(node);
319
+ case tt._function:
320
+ if (this.lookaheadCharCode() === 46) break;
321
+ if (!allowFunctionDeclaration) {
322
+ this.raise(this.state.strict ? Errors.StrictFunction : this.options.annexB ? Errors.SloppyFunctionAnnexB : Errors.SloppyFunction, this.state.startLoc);
323
+ }
324
+ return this.parseFunctionStatement(node, false, !allowDeclaration && allowFunctionDeclaration);
325
+ case tt._class:
326
+ if (!allowDeclaration) this.unexpected();
327
+ return this.parseClass(this.maybeTakeDecorators(decorators, node), true);
328
+ case tt._if:
329
+ return this.parseIfStatement(node);
330
+ case tt._return:
331
+ return this.parseReturnStatement(node);
332
+ case tt._switch:
333
+ return this.parseSwitchStatement(node);
334
+ case tt._throw:
335
+ return this.parseThrowStatement(node);
336
+ case tt._try:
337
+ return this.parseTryStatement(node);
338
+ case tt._await:
339
+ if (this.isAwaitUsing()) {
340
+ if (!this.allowsUsing()) {
341
+ this.raise(Errors.UnexpectedUsingDeclaration, node);
342
+ } else if (!allowDeclaration) {
343
+ this.raise(Errors.UnexpectedLexicalDeclaration, node);
344
+ } else if (!this.recordAwaitIfAllowed()) {
345
+ this.raise(Errors.AwaitUsingNotInAsyncContext, node);
346
+ }
347
+ this.next();
348
+ return this.parseVarStatement(node, "await using");
349
+ }
350
+ break;
351
+ case tt._using:
352
+ if (this.state.containsEsc || !this.hasInLineFollowingBindingIdentifierOrBrace()) {
353
+ break;
354
+ }
355
+ if (!this.allowsUsing()) {
356
+ this.raise(Errors.UnexpectedUsingDeclaration, this.state.startLoc);
357
+ } else if (!allowDeclaration) {
358
+ this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
359
+ }
360
+ return this.parseVarStatement(node, "using");
361
+ case tt._let: {
362
+ if (this.state.containsEsc) {
363
+ break;
364
+ }
365
+ const next = this.nextTokenStart();
366
+ const nextCh = this.codePointAtPos(next);
367
+ if (nextCh !== 91) {
368
+ if (!allowDeclaration && this.hasFollowingLineBreak()) break;
369
+ if (!this.chStartsBindingIdentifier(nextCh, next) && nextCh !== 123) {
370
+ break;
371
+ }
372
+ }
373
+ }
374
+ // falls through (upstream parser grammar)
375
+ case tt._const: {
376
+ if (!allowDeclaration) {
377
+ this.raise(Errors.UnexpectedLexicalDeclaration, this.state.startLoc);
378
+ }
379
+ }
380
+ // falls through (upstream parser grammar)
381
+ case tt._var: {
382
+ const kind = this.state.value;
383
+ return this.parseVarStatement(node, kind);
384
+ }
385
+ case tt._while:
386
+ return this.parseWhileStatement(node);
387
+ case tt._with:
388
+ return this.parseWithStatement(node);
389
+ case tt.braceL:
390
+ return this.parseBlock();
391
+ case tt.semi:
392
+ return this.parseEmptyStatement(node);
393
+ case tt._import: {
394
+ const nextTokenCharCode = this.lookaheadCharCode();
395
+ if (nextTokenCharCode === 40 || nextTokenCharCode === 46) {
396
+ break;
397
+ }
398
+ }
399
+ // falls through (upstream parser grammar)
400
+ case tt._export: {
401
+ if (!(this.optionFlags & OptionFlags.AllowImportExportEverywhere) && !topLevel) {
402
+ this.raise(Errors.UnexpectedImportExport, this.state.startLoc);
403
+ }
404
+ this.next();
405
+ let result;
406
+ if (startType === tt._import) {
407
+ result = this.parseImport(node);
408
+ } else {
409
+ result = this.parseExport(node, decorators);
410
+ }
411
+ this.assertModuleNodeAllowed(result);
412
+ return result;
413
+ }
414
+ default: {
415
+ if (this.isAsyncFunction()) {
416
+ if (!allowDeclaration) {
417
+ this.raise(Errors.AsyncFunctionInSingleStatementContext, this.state.startLoc);
418
+ }
419
+ this.next();
420
+ return this.parseFunctionStatement(node, true, !allowDeclaration && allowFunctionDeclaration);
421
+ }
422
+ }
423
+ }
424
+ const maybeName = this.state.value;
425
+ const expr = this.parseExpression();
426
+ if (tokenIsIdentifier(startType) && expr.type === "Identifier" && this.eat(tt.colon)) {
427
+ return this.parseLabeledStatement(node, maybeName, expr, flags);
428
+ } else {
429
+ return this.parseExpressionStatement(node, expr, decorators);
430
+ }
431
+ }
432
+ assertModuleNodeAllowed(node) {
433
+ if (!(this.optionFlags & OptionFlags.AllowImportExportEverywhere) && !this.inModule) {
434
+ this.raise(Errors.ImportOutsideModule, node);
435
+ }
436
+ }
437
+ decoratorsEnabledBeforeExport() {
438
+ if (this.hasPlugin("decorators-legacy")) return true;
439
+ return this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") !== false;
440
+ }
441
+ maybeTakeDecorators(maybeDecorators, classNode, exportNode) {
442
+ if (maybeDecorators) {
443
+ if (classNode.decorators?.length) {
444
+ if (typeof this.getPluginOption("decorators", "decoratorsBeforeExport") !== "boolean") {
445
+ this.raise(Errors.DecoratorsBeforeAfterExport, classNode.decorators[0]);
446
+ }
447
+ classNode.decorators.unshift(...maybeDecorators);
448
+ } else {
449
+ classNode.decorators = maybeDecorators;
450
+ }
451
+ this.resetStartLocationFromNode(classNode, maybeDecorators[0]);
452
+ if (exportNode) this.resetStartLocationFromNode(exportNode, classNode);
453
+ }
454
+ return classNode;
455
+ }
456
+ canHaveLeadingDecorator() {
457
+ return this.match(tt._class);
458
+ }
459
+ parseDecorators(allowExport) {
460
+ const decorators = [];
461
+ do {
462
+ decorators.push(this.parseDecorator());
463
+ } while (this.match(tt.at));
464
+ if (this.match(tt._export)) {
465
+ if (!allowExport) {
466
+ this.unexpected();
467
+ }
468
+ if (!this.decoratorsEnabledBeforeExport()) {
469
+ this.raise(Errors.DecoratorExportClass, this.state.startLoc);
470
+ }
471
+ } else if (!this.canHaveLeadingDecorator()) {
472
+ throw this.raise(Errors.UnexpectedLeadingDecorator, this.state.startLoc);
473
+ }
474
+ return decorators;
475
+ }
476
+ parseDecorator() {
477
+ this.expectOnePlugin(["decorators", "decorators-legacy"]);
478
+ const node = this.startNode();
479
+ this.next();
480
+ if (this.hasPlugin("decorators")) {
481
+ const startLoc = this.state.startLoc;
482
+ let expr;
483
+ if (this.match(tt.parenL)) {
484
+ const startLoc2 = this.state.startLoc;
485
+ this.next();
486
+ expr = this.parseExpression();
487
+ this.expect(tt.parenR);
488
+ expr = this.wrapParenthesis(startLoc2, expr);
489
+ const paramsStartLoc = this.state.startLoc;
490
+ node.expression = this.parseMaybeDecoratorArguments(expr, startLoc2);
491
+ if (this.getPluginOption("decorators", "allowCallParenthesized") === false && node.expression !== expr) {
492
+ this.raise(Errors.DecoratorArgumentsOutsideParentheses, paramsStartLoc);
493
+ }
494
+ } else {
495
+ expr = this.parseIdentifier(false);
496
+ while (this.eat(tt.dot)) {
497
+ const node2 = this.startNodeAt(startLoc);
498
+ node2.object = expr;
499
+ if (this.match(tt.privateName)) {
500
+ this.classScope.usePrivateName(this.state.value, this.state.startLoc);
501
+ node2.property = this.parsePrivateName();
502
+ } else {
503
+ node2.property = this.parseIdentifier(true);
504
+ }
505
+ node2.computed = false;
506
+ expr = this.finishNode(node2, "MemberExpression");
507
+ }
508
+ node.expression = this.parseMaybeDecoratorArguments(expr, startLoc);
509
+ }
510
+ } else {
511
+ node.expression = this.parseExprSubscripts();
512
+ }
513
+ return this.finishNode(node, "Decorator");
514
+ }
515
+ parseMaybeDecoratorArguments(expr, startLoc) {
516
+ if (this.eat(tt.parenL)) {
517
+ const node = this.startNodeAt(startLoc);
518
+ node.callee = expr;
519
+ node.arguments = this.parseCallExpressionArguments();
520
+ this.toReferencedList(node.arguments);
521
+ return this.finishNode(node, "CallExpression");
522
+ }
523
+ return expr;
524
+ }
525
+ parseBreakContinueStatement(node, isBreak) {
526
+ this.next();
527
+ if (this.isLineTerminator()) {
528
+ node.label = null;
529
+ } else {
530
+ node.label = this.parseIdentifier();
531
+ this.semicolon();
532
+ }
533
+ this.verifyBreakContinue(node, isBreak);
534
+ return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
535
+ }
536
+ verifyBreakContinue(node, isBreak) {
537
+ let i;
538
+ for (i = 0; i < this.state.labels.length; ++i) {
539
+ const lab = this.state.labels[i];
540
+ if (node.label == null || lab.name === node.label.name) {
541
+ if (lab.kind != null && (isBreak || lab.kind === LoopLabelKind.Loop)) {
542
+ break;
543
+ }
544
+ if (node.label && isBreak) break;
545
+ }
546
+ }
547
+ if (i === this.state.labels.length) {
548
+ const type = isBreak ? "BreakStatement" : "ContinueStatement";
549
+ this.raise(Errors.IllegalBreakContinue, node, {
550
+ type
551
+ });
552
+ }
553
+ }
554
+ parseDebuggerStatement(node) {
555
+ this.next();
556
+ this.semicolon();
557
+ return this.finishNode(node, "DebuggerStatement");
558
+ }
559
+ parseHeaderExpression() {
560
+ this.expect(tt.parenL);
561
+ const val = this.parseExpression();
562
+ this.expect(tt.parenR);
563
+ return val;
564
+ }
565
+ parseDoWhileStatement(node) {
566
+ this.next();
567
+ this.state.labels.push(loopLabel);
568
+ node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
569
+ this.state.labels.pop();
570
+ this.expect(tt._while);
571
+ node.test = this.parseHeaderExpression();
572
+ this.eat(tt.semi);
573
+ return this.finishNode(node, "DoWhileStatement");
574
+ }
575
+ parseForStatement(node) {
576
+ this.next();
577
+ this.state.labels.push(loopLabel);
578
+ let awaitAt = null;
579
+ if (this.isContextual(tt._await) && this.recordAwaitIfAllowed()) {
580
+ awaitAt = this.state.startLoc;
581
+ this.next();
582
+ }
583
+ this.scope.enter(ScopeFlag.OTHER);
584
+ this.expect(tt.parenL);
585
+ if (this.match(tt.semi)) {
586
+ if (awaitAt !== null) {
587
+ this.unexpected(awaitAt);
588
+ }
589
+ return this.parseFor(node, null);
590
+ }
591
+ const startsWithLet = this.isContextual(tt._let);
592
+ {
593
+ const startsWithAwaitUsing = this.isAwaitUsing();
594
+ const starsWithUsingDeclaration = startsWithAwaitUsing || this.isForUsing();
595
+ const isLetOrUsing = startsWithLet && this.hasFollowingBindingAtom() || starsWithUsingDeclaration;
596
+ if (this.match(tt._var) || this.match(tt._const) || isLetOrUsing) {
597
+ const initNode = this.startNode();
598
+ let kind;
599
+ if (startsWithAwaitUsing) {
600
+ kind = "await using";
601
+ if (!this.recordAwaitIfAllowed()) {
602
+ this.raise(Errors.AwaitUsingNotInAsyncContext, this.state.startLoc);
603
+ }
604
+ this.next();
605
+ } else {
606
+ kind = this.state.value;
607
+ }
608
+ this.next();
609
+ this.parseVar(initNode, true, kind);
610
+ const init2 = this.finishNode(initNode, "VariableDeclaration");
611
+ const isForIn = this.match(tt._in);
612
+ if (isForIn && starsWithUsingDeclaration) {
613
+ this.raise(Errors.ForInUsing, init2);
614
+ }
615
+ if ((isForIn || this.isContextual(tt._of)) && init2.declarations.length === 1) {
616
+ return this.parseForIn(node, init2, awaitAt);
617
+ }
618
+ if (awaitAt !== null) {
619
+ this.unexpected(awaitAt);
620
+ }
621
+ return this.parseFor(node, init2);
622
+ }
623
+ }
624
+ const startsWithAsync = this.isContextual(tt._async);
625
+ const refExpressionErrors = new ExpressionErrors();
626
+ const init = this.parseExpression(true, refExpressionErrors);
627
+ const isForOf = this.isContextual(tt._of);
628
+ if (isForOf) {
629
+ if (startsWithLet) {
630
+ this.raise(Errors.ForOfLet, init);
631
+ }
632
+ if (awaitAt === null && startsWithAsync && init.type === "Identifier") {
633
+ this.raise(Errors.ForOfAsync, init);
634
+ }
635
+ }
636
+ if (isForOf || this.match(tt._in)) {
637
+ this.checkDestructuringPrivate(refExpressionErrors);
638
+ this.toAssignable(init, true);
639
+ const type = isForOf ? "ForOfStatement" : "ForInStatement";
640
+ this.checkLVal(init, {
641
+ type
642
+ });
643
+ return this.parseForIn(node, init, awaitAt);
644
+ } else {
645
+ this.checkExpressionErrors(refExpressionErrors, true);
646
+ }
647
+ if (awaitAt !== null) {
648
+ this.unexpected(awaitAt);
649
+ }
650
+ return this.parseFor(node, init);
651
+ }
652
+ parseFunctionStatement(node, isAsync, isHangingDeclaration) {
653
+ this.next();
654
+ return this.parseFunction(node, ParseFunctionFlag.Declaration | (isHangingDeclaration ? ParseFunctionFlag.HangingDeclaration : 0) | (isAsync ? ParseFunctionFlag.Async : 0));
655
+ }
656
+ parseIfStatement(node) {
657
+ this.next();
658
+ node.test = this.parseHeaderExpression();
659
+ node.consequent = this.parseStatementOrSloppyAnnexBFunctionDeclaration();
660
+ node.alternate = this.eat(tt._else) ? this.parseStatementOrSloppyAnnexBFunctionDeclaration() : null;
661
+ return this.finishNode(node, "IfStatement");
662
+ }
663
+ parseReturnStatement(node) {
664
+ if (!this.prodParam.hasReturn) {
665
+ this.raise(Errors.IllegalReturn, this.state.startLoc);
666
+ }
667
+ this.next();
668
+ if (this.isLineTerminator()) {
669
+ node.argument = null;
670
+ } else {
671
+ node.argument = this.parseExpression();
672
+ this.semicolon();
673
+ }
674
+ return this.finishNode(node, "ReturnStatement");
675
+ }
676
+ parseSwitchStatement(node) {
677
+ this.next();
678
+ node.discriminant = this.parseHeaderExpression();
679
+ const cases = node.cases = [];
680
+ this.expect(tt.braceL);
681
+ this.state.labels.push(switchLabel);
682
+ this.scope.enter(ScopeFlag.SWITCH);
683
+ let cur;
684
+ for (let sawDefault; !this.match(tt.braceR); ) {
685
+ if (this.match(tt._case) || this.match(tt._default)) {
686
+ const isCase = this.match(tt._case);
687
+ if (cur) this.finishNode(cur, "SwitchCase");
688
+ cases.push(cur = this.startNode());
689
+ cur.consequent = [];
690
+ this.next();
691
+ if (isCase) {
692
+ cur.test = this.parseExpression();
693
+ } else {
694
+ if (sawDefault) {
695
+ this.raise(Errors.MultipleDefaultsInSwitch, this.state.lastTokStartLoc);
696
+ }
697
+ sawDefault = true;
698
+ cur.test = null;
699
+ }
700
+ this.expect(tt.colon);
701
+ } else {
702
+ if (cur) {
703
+ cur.consequent.push(this.parseStatementListItem());
704
+ } else {
705
+ this.unexpected();
706
+ }
707
+ }
708
+ }
709
+ this.scope.exit();
710
+ if (cur) this.finishNode(cur, "SwitchCase");
711
+ this.next();
712
+ this.state.labels.pop();
713
+ return this.finishNode(node, "SwitchStatement");
714
+ }
715
+ parseThrowStatement(node) {
716
+ this.next();
717
+ if (this.hasPrecedingLineBreak()) {
718
+ this.raise(Errors.NewlineAfterThrow, this.state.lastTokEndLoc);
719
+ }
720
+ node.argument = this.parseExpression();
721
+ this.semicolon();
722
+ return this.finishNode(node, "ThrowStatement");
723
+ }
724
+ parseCatchClauseParam() {
725
+ const param = this.parseBindingAtom();
726
+ this.scope.enter(this.options.annexB && param.type === "Identifier" ? ScopeFlag.SIMPLE_CATCH : ScopeFlag.OTHER);
727
+ this.checkLVal(param, {
728
+ type: "CatchClause"
729
+ }, BindingFlag.TYPE_CATCH_PARAM);
730
+ return param;
731
+ }
732
+ parseTryStatement(node) {
733
+ this.next();
734
+ node.block = this.parseBlock();
735
+ node.handler = null;
736
+ if (this.match(tt._catch)) {
737
+ const clause = this.startNode();
738
+ this.next();
739
+ if (this.match(tt.parenL)) {
740
+ this.expect(tt.parenL);
741
+ clause.param = this.parseCatchClauseParam();
742
+ this.expect(tt.parenR);
743
+ } else {
744
+ clause.param = null;
745
+ this.scope.enter(ScopeFlag.OTHER);
746
+ }
747
+ clause.body = this.withSmartMixTopicForbiddingContext(() => this.parseBlock(false, false));
748
+ this.scope.exit();
749
+ node.handler = this.finishNode(clause, "CatchClause");
750
+ }
751
+ node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null;
752
+ if (!node.handler && !node.finalizer) {
753
+ this.raise(Errors.NoCatchOrFinally, node);
754
+ }
755
+ return this.finishNode(node, "TryStatement");
756
+ }
757
+ parseVarStatement(node, kind, allowMissingInitializer = false) {
758
+ this.next();
759
+ this.parseVar(node, false, kind, allowMissingInitializer);
760
+ this.semicolon();
761
+ return this.finishNode(node, "VariableDeclaration");
762
+ }
763
+ parseWhileStatement(node) {
764
+ this.next();
765
+ node.test = this.parseHeaderExpression();
766
+ this.state.labels.push(loopLabel);
767
+ node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
768
+ this.state.labels.pop();
769
+ return this.finishNode(node, "WhileStatement");
770
+ }
771
+ parseWithStatement(node) {
772
+ if (this.state.strict) {
773
+ this.raise(Errors.StrictWith, this.state.startLoc);
774
+ }
775
+ this.next();
776
+ node.object = this.parseHeaderExpression();
777
+ node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
778
+ return this.finishNode(node, "WithStatement");
779
+ }
780
+ parseEmptyStatement(node) {
781
+ this.next();
782
+ return this.finishNode(node, "EmptyStatement");
783
+ }
784
+ parseLabeledStatement(node, maybeName, expr, flags) {
785
+ for (const label of this.state.labels) {
786
+ if (label.name === maybeName) {
787
+ this.raise(Errors.LabelRedeclaration, expr, {
788
+ labelName: maybeName
789
+ });
790
+ }
791
+ }
792
+ const kind = tokenIsLoop(this.state.type) ? LoopLabelKind.Loop : this.match(tt._switch) ? LoopLabelKind.Switch : null;
793
+ for (let i = this.state.labels.length - 1; i >= 0; i--) {
794
+ const label = this.state.labels[i];
795
+ if (label.statementStart === node.start) {
796
+ label.statementStart = this.sourceToOffsetPos(this.state.start);
797
+ label.kind = kind;
798
+ } else {
799
+ break;
800
+ }
801
+ }
802
+ this.state.labels.push({
803
+ name: maybeName,
804
+ kind,
805
+ statementStart: this.sourceToOffsetPos(this.state.start)
806
+ });
807
+ node.body = flags & ParseStatementFlag.AllowLabeledFunction ? this.parseStatementOrSloppyAnnexBFunctionDeclaration(true) : this.parseStatement();
808
+ this.state.labels.pop();
809
+ node.label = expr;
810
+ return this.finishNode(node, "LabeledStatement");
811
+ }
812
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
813
+ parseExpressionStatement(node, expr, decorators) {
814
+ node.expression = expr;
815
+ this.semicolon();
816
+ return this.finishNode(node, "ExpressionStatement");
817
+ }
818
+ parseBlock(allowDirectives = false, createNewLexicalScope = true, afterBlockParse) {
819
+ const node = this.startNode();
820
+ if (allowDirectives) {
821
+ this.state.strictErrors.clear();
822
+ }
823
+ this.expect(tt.braceL);
824
+ if (createNewLexicalScope) {
825
+ this.scope.enter(ScopeFlag.OTHER);
826
+ }
827
+ this.parseBlockBody(node, allowDirectives, false, tt.braceR, afterBlockParse);
828
+ if (createNewLexicalScope) {
829
+ this.scope.exit();
830
+ }
831
+ return this.finishNode(node, "BlockStatement");
832
+ }
833
+ isValidDirective(stmt) {
834
+ return stmt.type === "ExpressionStatement" && stmt.expression.type === "StringLiteral" && !stmt.expression.extra.parenthesized;
835
+ }
836
+ parseBlockBody(node, allowDirectives, topLevel, end, afterBlockParse) {
837
+ const body = node.body = [];
838
+ const directives = node.directives = [];
839
+ this.parseBlockOrModuleBlockBody(body, allowDirectives ? directives : void 0, topLevel, end, afterBlockParse);
840
+ }
841
+ parseBlockOrModuleBlockBody(body, directives, topLevel, end, afterBlockParse) {
842
+ const oldStrict = this.state.strict;
843
+ let hasStrictModeDirective = false;
844
+ let parsedNonDirective = false;
845
+ while (!this.match(end)) {
846
+ const stmt = topLevel ? this.parseModuleItem() : this.parseStatementListItem();
847
+ if (directives && !parsedNonDirective) {
848
+ if (this.isValidDirective(stmt)) {
849
+ const directive = this.stmtToDirective(stmt);
850
+ directives.push(directive);
851
+ if (!hasStrictModeDirective && directive.value.value === "use strict") {
852
+ hasStrictModeDirective = true;
853
+ this.setStrict(true);
854
+ }
855
+ continue;
856
+ }
857
+ parsedNonDirective = true;
858
+ this.state.strictErrors.clear();
859
+ }
860
+ body.push(stmt);
861
+ }
862
+ afterBlockParse?.call(this, hasStrictModeDirective);
863
+ if (!oldStrict) {
864
+ this.setStrict(false);
865
+ }
866
+ this.next();
867
+ }
868
+ parseFor(node, init) {
869
+ node.init = init;
870
+ this.semicolon(false);
871
+ node.test = this.match(tt.semi) ? null : this.parseExpression();
872
+ this.semicolon(false);
873
+ node.update = this.match(tt.parenR) ? null : this.parseExpression();
874
+ this.expect(tt.parenR);
875
+ node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
876
+ this.scope.exit();
877
+ this.state.labels.pop();
878
+ return this.finishNode(node, "ForStatement");
879
+ }
880
+ parseForIn(node, init, awaitAt) {
881
+ const isForIn = this.match(tt._in);
882
+ this.next();
883
+ if (isForIn) {
884
+ if (awaitAt !== null) this.unexpected(awaitAt);
885
+ } else {
886
+ node.await = awaitAt !== null;
887
+ }
888
+ if (init.type === "VariableDeclaration" && init.declarations[0].init != null && (!isForIn || !this.options.annexB || this.state.strict || init.kind !== "var" || init.declarations[0].id.type !== "Identifier")) {
889
+ this.raise(Errors.ForInOfLoopInitializer, init, {
890
+ type: isForIn ? "ForInStatement" : "ForOfStatement"
891
+ });
892
+ }
893
+ if (init.type === "AssignmentPattern") {
894
+ this.raise(Errors.InvalidLhs, init, {
895
+ ancestor: {
896
+ type: "ForStatement"
897
+ }
898
+ });
899
+ }
900
+ node.left = init;
901
+ node.right = isForIn ? this.parseExpression() : this.parseMaybeAssignAllowIn();
902
+ this.expect(tt.parenR);
903
+ node.body = this.withSmartMixTopicForbiddingContext(() => this.parseStatement());
904
+ this.scope.exit();
905
+ this.state.labels.pop();
906
+ return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement");
907
+ }
908
+ parseVar(node, isFor, kind, allowMissingInitializer = false) {
909
+ const declarations = node.declarations = [];
910
+ node.kind = kind;
911
+ for (; ; ) {
912
+ const decl = this.startNode();
913
+ this.parseVarId(decl, kind);
914
+ decl.init = !this.eat(tt.eq) ? null : isFor ? this.parseMaybeAssignDisallowIn() : this.parseMaybeAssignAllowIn();
915
+ if (decl.init === null && !allowMissingInitializer) {
916
+ if (decl.id.type !== "Identifier" && !(isFor && (this.match(tt._in) || this.isContextual(tt._of)))) {
917
+ this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
918
+ kind: "destructuring"
919
+ });
920
+ } else if ((kind === "const" || kind === "using" || kind === "await using") && !(this.match(tt._in) || this.isContextual(tt._of))) {
921
+ this.raise(Errors.DeclarationMissingInitializer, this.state.lastTokEndLoc, {
922
+ kind
923
+ });
924
+ }
925
+ }
926
+ declarations.push(this.finishNode(decl, "VariableDeclarator"));
927
+ if (!this.eat(tt.comma)) break;
928
+ }
929
+ return node;
930
+ }
931
+ parseVarId(decl, kind) {
932
+ const id = this.parseBindingAtom();
933
+ if (kind === "using" || kind === "await using") {
934
+ if (id.type === "ArrayPattern" || id.type === "ObjectPattern") {
935
+ this.raise(Errors.UsingDeclarationHasBindingPattern, id.loc.start);
936
+ }
937
+ } else {
938
+ if (id.type === "VoidPattern") {
939
+ this.raise(Errors.UnexpectedVoidPattern, id.loc.start);
940
+ }
941
+ }
942
+ this.checkLVal(id, {
943
+ type: "VariableDeclarator"
944
+ }, kind === "var" ? BindingFlag.TYPE_VAR : BindingFlag.TYPE_LEXICAL);
945
+ decl.id = id;
946
+ }
947
+ parseAsyncFunctionExpression(node) {
948
+ return this.parseFunction(node, ParseFunctionFlag.Async);
949
+ }
950
+ parseFunction(node, flags = ParseFunctionFlag.Expression) {
951
+ const hangingDeclaration = flags & ParseFunctionFlag.HangingDeclaration;
952
+ const isDeclaration = !!(flags & ParseFunctionFlag.Declaration);
953
+ const requireId = isDeclaration && !(flags & ParseFunctionFlag.NullableId);
954
+ const isAsync = !!(flags & ParseFunctionFlag.Async);
955
+ this.initFunction(node, isAsync);
956
+ if (this.match(tt.star)) {
957
+ if (hangingDeclaration) {
958
+ this.raise(Errors.GeneratorInSingleStatementContext, this.state.startLoc);
959
+ }
960
+ this.next();
961
+ node.generator = true;
962
+ }
963
+ if (isDeclaration) {
964
+ node.id = this.parseFunctionId(requireId);
965
+ }
966
+ const oldMaybeInArrowParameters = this.state.maybeInArrowParameters;
967
+ this.state.maybeInArrowParameters = false;
968
+ this.scope.enter(ScopeFlag.FUNCTION);
969
+ this.prodParam.enter(functionFlags(isAsync, node.generator));
970
+ if (!isDeclaration) {
971
+ node.id = this.parseFunctionId();
972
+ }
973
+ this.parseFunctionParams(node, false);
974
+ this.withSmartMixTopicForbiddingContext(() => {
975
+ this.parseFunctionBodyAndFinish(node, isDeclaration ? "FunctionDeclaration" : "FunctionExpression");
976
+ });
977
+ this.prodParam.exit();
978
+ this.scope.exit();
979
+ if (isDeclaration && !hangingDeclaration) {
980
+ this.registerFunctionStatementId(node);
981
+ }
982
+ this.state.maybeInArrowParameters = oldMaybeInArrowParameters;
983
+ return node;
984
+ }
985
+ parseFunctionId(requireId) {
986
+ return requireId || tokenIsIdentifier(this.state.type) ? this.parseIdentifier() : null;
987
+ }
988
+ parseFunctionParams(node, isConstructor) {
989
+ this.expect(tt.parenL);
990
+ this.expressionScope.enter(newParameterDeclarationScope());
991
+ node.params = this.parseBindingList(tt.parenR, 41, ParseBindingListFlags.IS_FUNCTION_PARAMS | (isConstructor ? ParseBindingListFlags.IS_CONSTRUCTOR_PARAMS : 0));
992
+ this.expressionScope.exit();
993
+ }
994
+ registerFunctionStatementId(node) {
995
+ if (!node.id) return;
996
+ this.scope.declareName(node.id.name, !this.options.annexB || this.state.strict || node.generator || node.async ? this.scope.treatFunctionsAsVar ? BindingFlag.TYPE_VAR : BindingFlag.TYPE_LEXICAL : BindingFlag.TYPE_FUNCTION, node.id.loc.start);
997
+ }
998
+ parseClass(node, isStatement, optionalId) {
999
+ this.next();
1000
+ const oldStrict = this.state.strict;
1001
+ this.state.strict = true;
1002
+ this.parseClassId(node, isStatement, optionalId);
1003
+ this.parseClassSuper(node);
1004
+ node.body = this.parseClassBody(!!node.superClass, oldStrict);
1005
+ return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression");
1006
+ }
1007
+ isClassProperty() {
1008
+ return this.match(tt.eq) || this.match(tt.semi) || this.match(tt.braceR);
1009
+ }
1010
+ isClassMethod() {
1011
+ return this.match(tt.parenL);
1012
+ }
1013
+ nameIsConstructor(key) {
1014
+ return key.type === "Identifier" && key.name === "constructor" || key.type === "StringLiteral" && key.value === "constructor";
1015
+ }
1016
+ isNonstaticConstructor(method) {
1017
+ return !method.computed && !method.static && this.nameIsConstructor(method.key);
1018
+ }
1019
+ parseClassBody(hadSuperClass, oldStrict) {
1020
+ this.classScope.enter();
1021
+ const state = {
1022
+ hadConstructor: false,
1023
+ hadSuperClass
1024
+ };
1025
+ let decorators = [];
1026
+ const classBody = this.startNode();
1027
+ classBody.body = [];
1028
+ this.expect(tt.braceL);
1029
+ this.withSmartMixTopicForbiddingContext(() => {
1030
+ while (!this.match(tt.braceR)) {
1031
+ if (this.eat(tt.semi)) {
1032
+ if (decorators.length > 0) {
1033
+ throw this.raise(Errors.DecoratorSemicolon, this.state.lastTokEndLoc);
1034
+ }
1035
+ continue;
1036
+ }
1037
+ if (this.match(tt.at)) {
1038
+ decorators.push(this.parseDecorator());
1039
+ continue;
1040
+ }
1041
+ const member = this.startNode();
1042
+ if (decorators.length) {
1043
+ member.decorators = decorators;
1044
+ this.resetStartLocationFromNode(member, decorators[0]);
1045
+ decorators = [];
1046
+ }
1047
+ this.parseClassMember(classBody, member, state);
1048
+ if (member.kind === "constructor" && member.decorators && member.decorators.length > 0) {
1049
+ this.raise(Errors.DecoratorConstructor, member);
1050
+ }
1051
+ }
1052
+ });
1053
+ this.state.strict = oldStrict;
1054
+ this.next();
1055
+ if (decorators.length) {
1056
+ throw this.raise(Errors.TrailingDecorator, this.state.startLoc);
1057
+ }
1058
+ this.classScope.exit();
1059
+ return this.finishNode(classBody, "ClassBody");
1060
+ }
1061
+ parseClassMemberFromModifier(classBody, member) {
1062
+ const key = this.parseIdentifier(true);
1063
+ if (this.isClassMethod()) {
1064
+ const method = member;
1065
+ method.kind = "method";
1066
+ method.computed = false;
1067
+ method.key = key;
1068
+ method.static = false;
1069
+ this.pushClassMethod(classBody, method, false, false, false, false);
1070
+ return true;
1071
+ } else if (this.isClassProperty()) {
1072
+ const prop = member;
1073
+ prop.computed = false;
1074
+ prop.key = key;
1075
+ prop.static = false;
1076
+ classBody.body.push(this.parseClassProperty(prop));
1077
+ return true;
1078
+ }
1079
+ this.resetPreviousNodeTrailingComments(key);
1080
+ return false;
1081
+ }
1082
+ parseClassMember(classBody, member, state) {
1083
+ const isStatic = this.isContextual(tt._static);
1084
+ if (isStatic) {
1085
+ if (this.parseClassMemberFromModifier(classBody, member)) {
1086
+ return;
1087
+ }
1088
+ if (this.eat(tt.braceL)) {
1089
+ this.parseClassStaticBlock(classBody, member);
1090
+ return;
1091
+ }
1092
+ }
1093
+ this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
1094
+ }
1095
+ parseClassMemberWithIsStatic(classBody, member, state, isStatic) {
1096
+ const publicMethod = member;
1097
+ const privateMethod = member;
1098
+ const publicProp = member;
1099
+ const privateProp = member;
1100
+ const accessorProp = member;
1101
+ const method = publicMethod;
1102
+ const publicMember = publicMethod;
1103
+ member.static = isStatic;
1104
+ this.parsePropertyNamePrefixOperator(member);
1105
+ if (this.eat(tt.star)) {
1106
+ method.kind = "method";
1107
+ const isPrivateName = this.match(tt.privateName);
1108
+ this.parseClassElementName(method);
1109
+ this.parsePostMemberNameModifiers(method);
1110
+ if (isPrivateName) {
1111
+ this.pushClassPrivateMethod(classBody, privateMethod, true, false);
1112
+ return;
1113
+ }
1114
+ if (this.isNonstaticConstructor(publicMethod)) {
1115
+ this.raise(Errors.ConstructorIsGenerator, publicMethod.key);
1116
+ }
1117
+ this.pushClassMethod(classBody, publicMethod, true, false, false, false);
1118
+ return;
1119
+ }
1120
+ const isContextual = !this.state.containsEsc && tokenIsIdentifier(this.state.type);
1121
+ const key = this.parseClassElementName(member);
1122
+ const maybeContextualKw = isContextual ? key.name : null;
1123
+ const isPrivate = this.isPrivateName(key);
1124
+ const maybeQuestionTokenStartLoc = this.state.startLoc;
1125
+ this.parsePostMemberNameModifiers(publicMember);
1126
+ if (this.isClassMethod()) {
1127
+ method.kind = "method";
1128
+ if (isPrivate) {
1129
+ this.pushClassPrivateMethod(classBody, privateMethod, false, false);
1130
+ return;
1131
+ }
1132
+ const isConstructor = this.isNonstaticConstructor(publicMethod);
1133
+ let allowsDirectSuper = false;
1134
+ if (isConstructor) {
1135
+ publicMethod.kind = "constructor";
1136
+ if (state.hadConstructor && !this.hasPlugin("typescript")) {
1137
+ this.raise(Errors.DuplicateConstructor, key);
1138
+ }
1139
+ if (isConstructor && this.hasPlugin("typescript") && member.override) {
1140
+ this.raise(Errors.OverrideOnConstructor, key);
1141
+ }
1142
+ state.hadConstructor = true;
1143
+ allowsDirectSuper = state.hadSuperClass;
1144
+ }
1145
+ this.pushClassMethod(classBody, publicMethod, false, false, isConstructor, allowsDirectSuper);
1146
+ } else if (this.isClassProperty()) {
1147
+ if (isPrivate) {
1148
+ this.pushClassPrivateProperty(classBody, privateProp);
1149
+ } else {
1150
+ this.pushClassProperty(classBody, publicProp);
1151
+ }
1152
+ } else if (maybeContextualKw === "async" && !this.isLineTerminator()) {
1153
+ this.resetPreviousNodeTrailingComments(key);
1154
+ const isGenerator = this.eat(tt.star);
1155
+ if (publicMember.optional) {
1156
+ this.unexpected(maybeQuestionTokenStartLoc);
1157
+ }
1158
+ method.kind = "method";
1159
+ const isPrivate2 = this.match(tt.privateName);
1160
+ this.parseClassElementName(method);
1161
+ this.parsePostMemberNameModifiers(publicMember);
1162
+ if (isPrivate2) {
1163
+ this.pushClassPrivateMethod(classBody, privateMethod, isGenerator, true);
1164
+ } else {
1165
+ if (this.isNonstaticConstructor(publicMethod)) {
1166
+ this.raise(Errors.ConstructorIsAsync, publicMethod.key);
1167
+ }
1168
+ this.pushClassMethod(classBody, publicMethod, isGenerator, true, false, false);
1169
+ }
1170
+ } else if ((maybeContextualKw === "get" || maybeContextualKw === "set") && !(this.match(tt.star) && this.isLineTerminator())) {
1171
+ this.resetPreviousNodeTrailingComments(key);
1172
+ method.kind = maybeContextualKw;
1173
+ const isPrivate2 = this.match(tt.privateName);
1174
+ this.parseClassElementName(publicMethod);
1175
+ if (isPrivate2) {
1176
+ this.pushClassPrivateMethod(classBody, privateMethod, false, false);
1177
+ } else {
1178
+ if (this.isNonstaticConstructor(publicMethod)) {
1179
+ this.raise(Errors.ConstructorIsAccessor, publicMethod.key);
1180
+ }
1181
+ this.pushClassMethod(classBody, publicMethod, false, false, false, false);
1182
+ }
1183
+ this.checkGetterSetterParams(publicMethod);
1184
+ } else if (maybeContextualKw === "accessor" && !this.isLineTerminator()) {
1185
+ this.expectPlugin("decoratorAutoAccessors");
1186
+ this.resetPreviousNodeTrailingComments(key);
1187
+ const isPrivate2 = this.match(tt.privateName);
1188
+ this.parseClassElementName(publicProp);
1189
+ this.pushClassAccessorProperty(classBody, accessorProp, isPrivate2);
1190
+ } else if (this.isLineTerminator()) {
1191
+ if (isPrivate) {
1192
+ this.pushClassPrivateProperty(classBody, privateProp);
1193
+ } else {
1194
+ this.pushClassProperty(classBody, publicProp);
1195
+ }
1196
+ } else {
1197
+ this.unexpected();
1198
+ }
1199
+ }
1200
+ parseClassElementName(member) {
1201
+ const {
1202
+ type,
1203
+ value
1204
+ } = this.state;
1205
+ if ((type === tt.name || type === tt.string) && member.static && value === "prototype") {
1206
+ this.raise(Errors.StaticPrototype, this.state.startLoc);
1207
+ }
1208
+ if (type === tt.privateName) {
1209
+ if (value === "constructor") {
1210
+ this.raise(Errors.ConstructorClassPrivateField, this.state.startLoc);
1211
+ }
1212
+ const key = this.parsePrivateName();
1213
+ member.key = key;
1214
+ return key;
1215
+ }
1216
+ this.parsePropertyName(member);
1217
+ return member.key;
1218
+ }
1219
+ parseClassStaticBlock(classBody, member) {
1220
+ this.scope.enter(ScopeFlag.CLASS | ScopeFlag.STATIC_BLOCK | ScopeFlag.SUPER);
1221
+ const oldLabels = this.state.labels;
1222
+ this.state.labels = [];
1223
+ this.prodParam.enter(ParamKind.PARAM);
1224
+ const body = member.body = [];
1225
+ this.parseBlockOrModuleBlockBody(body, void 0, false, tt.braceR);
1226
+ this.prodParam.exit();
1227
+ this.scope.exit();
1228
+ this.state.labels = oldLabels;
1229
+ classBody.body.push(this.finishNode(member, "StaticBlock"));
1230
+ if (member.decorators?.length) {
1231
+ this.raise(Errors.DecoratorStaticBlock, member);
1232
+ }
1233
+ }
1234
+ pushClassProperty(classBody, prop) {
1235
+ if (!prop.computed && this.nameIsConstructor(prop.key)) {
1236
+ this.raise(Errors.ConstructorClassField, prop.key);
1237
+ }
1238
+ classBody.body.push(this.parseClassProperty(prop));
1239
+ }
1240
+ pushClassPrivateProperty(classBody, prop) {
1241
+ const node = this.parseClassPrivateProperty(prop);
1242
+ classBody.body.push(node);
1243
+ this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), ClassElementType.OTHER, node.key.loc.start);
1244
+ }
1245
+ pushClassAccessorProperty(classBody, prop, isPrivate) {
1246
+ if (!isPrivate && !prop.computed && this.nameIsConstructor(prop.key)) {
1247
+ this.raise(Errors.ConstructorClassField, prop.key);
1248
+ }
1249
+ const node = this.parseClassAccessorProperty(prop);
1250
+ classBody.body.push(node);
1251
+ if (isPrivate) {
1252
+ this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), ClassElementType.OTHER, node.key.loc.start);
1253
+ }
1254
+ }
1255
+ pushClassMethod(classBody, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
1256
+ classBody.body.push(this.parseMethod(method, isGenerator, isAsync, isConstructor, allowsDirectSuper, "ClassMethod", true));
1257
+ }
1258
+ pushClassPrivateMethod(classBody, method, isGenerator, isAsync) {
1259
+ const node = this.parseMethod(method, isGenerator, isAsync, false, false, "ClassPrivateMethod", true);
1260
+ classBody.body.push(node);
1261
+ const kind = node.kind === "get" ? node.static ? ClassElementType.STATIC_GETTER : ClassElementType.INSTANCE_GETTER : node.kind === "set" ? node.static ? ClassElementType.STATIC_SETTER : ClassElementType.INSTANCE_SETTER : ClassElementType.OTHER;
1262
+ this.declareClassPrivateMethodInScope(node, kind);
1263
+ }
1264
+ declareClassPrivateMethodInScope(node, kind) {
1265
+ this.classScope.declarePrivateName(this.getPrivateNameSV(node.key), kind, node.key.loc.start);
1266
+ }
1267
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
1268
+ parsePostMemberNameModifiers(methodOrProp) {
1269
+ }
1270
+ parseClassPrivateProperty(node) {
1271
+ this.parseInitializer(node);
1272
+ this.semicolon();
1273
+ return this.finishNode(node, "ClassPrivateProperty");
1274
+ }
1275
+ parseClassProperty(node) {
1276
+ this.parseInitializer(node);
1277
+ this.semicolon();
1278
+ return this.finishNode(node, "ClassProperty");
1279
+ }
1280
+ parseClassAccessorProperty(node) {
1281
+ this.parseInitializer(node);
1282
+ this.semicolon();
1283
+ return this.finishNode(node, "ClassAccessorProperty");
1284
+ }
1285
+ parseInitializer(node) {
1286
+ this.scope.enter(ScopeFlag.CLASS | ScopeFlag.SUPER);
1287
+ this.expressionScope.enter(newExpressionScope());
1288
+ this.prodParam.enter(ParamKind.PARAM);
1289
+ node.value = this.eat(tt.eq) ? this.parseMaybeAssignAllowIn() : null;
1290
+ this.expressionScope.exit();
1291
+ this.prodParam.exit();
1292
+ this.scope.exit();
1293
+ }
1294
+ parseClassId(node, isStatement, optionalId, bindingType = BindingFlag.TYPE_CLASS) {
1295
+ if (tokenIsIdentifier(this.state.type)) {
1296
+ node.id = this.parseIdentifier();
1297
+ if (isStatement) {
1298
+ this.declareNameFromIdentifier(node.id, bindingType);
1299
+ }
1300
+ } else {
1301
+ if (optionalId || !isStatement) {
1302
+ node.id = null;
1303
+ } else {
1304
+ throw this.raise(Errors.MissingClassName, this.state.startLoc);
1305
+ }
1306
+ }
1307
+ }
1308
+ parseClassSuper(node) {
1309
+ node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts() : null;
1310
+ }
1311
+ parseExport(node, decorators) {
1312
+ const maybeDefaultIdentifier = this.parseMaybeImportPhase(node, true);
1313
+ const hasDefault = this.maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier);
1314
+ const parseAfterDefault = !hasDefault || this.eat(tt.comma);
1315
+ const hasStar = parseAfterDefault && this.eatExportStar(node);
1316
+ const hasNamespace = hasStar && this.maybeParseExportNamespaceSpecifier(node);
1317
+ const parseAfterNamespace = parseAfterDefault && (!hasNamespace || this.eat(tt.comma));
1318
+ const isFromRequired = hasDefault || hasStar;
1319
+ if (hasStar && !hasNamespace) {
1320
+ if (hasDefault) this.unexpected();
1321
+ if (decorators) {
1322
+ throw this.raise(Errors.UnsupportedDecoratorExport, node);
1323
+ }
1324
+ this.parseExportFrom(node, true);
1325
+ this.sawUnambiguousESM = true;
1326
+ return this.finishNode(node, "ExportAllDeclaration");
1327
+ }
1328
+ const hasSpecifiers = this.maybeParseExportNamedSpecifiers(node);
1329
+ if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
1330
+ this.unexpected(null, tt.braceL);
1331
+ }
1332
+ if (hasNamespace && parseAfterNamespace) {
1333
+ this.unexpected(null, tt._from);
1334
+ }
1335
+ let hasDeclaration;
1336
+ if (isFromRequired || hasSpecifiers) {
1337
+ hasDeclaration = false;
1338
+ if (decorators) {
1339
+ throw this.raise(Errors.UnsupportedDecoratorExport, node);
1340
+ }
1341
+ this.parseExportFrom(node, isFromRequired);
1342
+ } else {
1343
+ hasDeclaration = this.maybeParseExportDeclaration(node);
1344
+ }
1345
+ if (isFromRequired || hasSpecifiers || hasDeclaration) {
1346
+ const node2 = node;
1347
+ this.checkExport(node2, true, false, !!node2.source);
1348
+ if (node2.declaration?.type === "ClassDeclaration") {
1349
+ this.maybeTakeDecorators(decorators, node2.declaration, node2);
1350
+ } else if (decorators) {
1351
+ throw this.raise(Errors.UnsupportedDecoratorExport, node);
1352
+ }
1353
+ this.sawUnambiguousESM = true;
1354
+ return this.finishNode(node2, "ExportNamedDeclaration");
1355
+ }
1356
+ if (this.eat(tt._default)) {
1357
+ const node2 = node;
1358
+ const decl = this.parseExportDefaultExpression();
1359
+ node2.declaration = decl;
1360
+ if (decl.type === "ClassDeclaration") {
1361
+ this.maybeTakeDecorators(decorators, decl, node2);
1362
+ } else if (decorators) {
1363
+ throw this.raise(Errors.UnsupportedDecoratorExport, node);
1364
+ }
1365
+ this.checkExport(node2, true, true);
1366
+ this.sawUnambiguousESM = true;
1367
+ return this.finishNode(node2, "ExportDefaultDeclaration");
1368
+ }
1369
+ throw this.unexpected(null, tt.braceL);
1370
+ }
1371
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
1372
+ eatExportStar(node) {
1373
+ return this.eat(tt.star);
1374
+ }
1375
+ maybeParseExportDefaultSpecifier(node, maybeDefaultIdentifier) {
1376
+ if (maybeDefaultIdentifier || this.isExportDefaultSpecifier()) {
1377
+ this.expectPlugin("exportDefaultFrom", maybeDefaultIdentifier?.loc.start);
1378
+ const id = maybeDefaultIdentifier || this.parseIdentifier(true);
1379
+ const specifier = this.startNodeAtNode(id);
1380
+ specifier.exported = id;
1381
+ node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
1382
+ return true;
1383
+ }
1384
+ return false;
1385
+ }
1386
+ maybeParseExportNamespaceSpecifier(node) {
1387
+ if (this.isContextual(tt._as)) {
1388
+ node.specifiers ??= [];
1389
+ const specifier = this.startNodeAt(this.state.lastTokStartLoc);
1390
+ this.next();
1391
+ specifier.exported = this.parseModuleExportName();
1392
+ node.specifiers.push(this.finishNode(specifier, "ExportNamespaceSpecifier"));
1393
+ return true;
1394
+ }
1395
+ return false;
1396
+ }
1397
+ maybeParseExportNamedSpecifiers(node) {
1398
+ if (this.match(tt.braceL)) {
1399
+ const node2 = node;
1400
+ if (!node2.specifiers) node2.specifiers = [];
1401
+ const isTypeExport = node2.exportKind === "type";
1402
+ node2.specifiers.push(...this.parseExportSpecifiers(isTypeExport));
1403
+ node2.source = null;
1404
+ if (this.hasPlugin("importAssertions")) {
1405
+ node2.assertions = [];
1406
+ } else {
1407
+ node2.attributes = [];
1408
+ }
1409
+ node2.declaration = null;
1410
+ return true;
1411
+ }
1412
+ return false;
1413
+ }
1414
+ maybeParseExportDeclaration(node) {
1415
+ if (this.shouldParseExportDeclaration()) {
1416
+ node.specifiers = [];
1417
+ node.source = null;
1418
+ if (this.hasPlugin("importAssertions")) {
1419
+ node.assertions = [];
1420
+ } else {
1421
+ node.attributes = [];
1422
+ }
1423
+ node.declaration = this.parseExportDeclaration(node);
1424
+ return true;
1425
+ }
1426
+ return false;
1427
+ }
1428
+ isAsyncFunction() {
1429
+ if (!this.isContextual(tt._async)) return false;
1430
+ const next = this.nextTokenInLineStart();
1431
+ return this.isUnparsedContextual(next, "function");
1432
+ }
1433
+ parseExportDefaultExpression() {
1434
+ const expr = this.startNode();
1435
+ if (this.match(tt._function)) {
1436
+ this.next();
1437
+ return this.parseFunction(expr, ParseFunctionFlag.Declaration | ParseFunctionFlag.NullableId);
1438
+ } else if (this.isAsyncFunction()) {
1439
+ this.next();
1440
+ this.next();
1441
+ return this.parseFunction(expr, ParseFunctionFlag.Declaration | ParseFunctionFlag.NullableId | ParseFunctionFlag.Async);
1442
+ }
1443
+ if (this.match(tt._class)) {
1444
+ return this.parseClass(expr, true, true);
1445
+ }
1446
+ if (this.match(tt.at)) {
1447
+ if (this.hasPlugin("decorators") && this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
1448
+ this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
1449
+ }
1450
+ return this.parseClass(this.maybeTakeDecorators(this.parseDecorators(false), this.startNode()), true, true);
1451
+ }
1452
+ if (this.match(tt._const) || this.match(tt._var) || this.isLet() || this.isUsing() || this.isAwaitUsing()) {
1453
+ throw this.raise(Errors.UnsupportedDefaultExport, this.state.startLoc);
1454
+ }
1455
+ const res = this.parseMaybeAssignAllowIn();
1456
+ this.semicolon();
1457
+ return res;
1458
+ }
1459
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
1460
+ parseExportDeclaration(node) {
1461
+ if (this.match(tt._class)) {
1462
+ const node2 = this.parseClass(this.startNode(), true, false);
1463
+ return node2;
1464
+ }
1465
+ return this.parseStatementListItem();
1466
+ }
1467
+ isExportDefaultSpecifier() {
1468
+ const {
1469
+ type
1470
+ } = this.state;
1471
+ if (tokenIsIdentifier(type)) {
1472
+ if (type === tt._async && !this.state.containsEsc || type === tt._let) {
1473
+ return false;
1474
+ }
1475
+ if ((type === tt._type || type === tt._interface) && !this.state.containsEsc) {
1476
+ const next2 = this.nextTokenStart();
1477
+ const nextChar = this.input.charCodeAt(next2);
1478
+ if (nextChar === 123 || this.chStartsBindingIdentifier(nextChar, next2) && !this.input.startsWith("from", next2)) {
1479
+ this.expectOnePlugin(["flow", "typescript"]);
1480
+ return false;
1481
+ }
1482
+ }
1483
+ } else if (!this.match(tt._default)) {
1484
+ return false;
1485
+ }
1486
+ const next = this.nextTokenStart();
1487
+ const hasFrom = this.isUnparsedContextual(next, "from");
1488
+ if (this.input.charCodeAt(next) === 44 || tokenIsIdentifier(this.state.type) && hasFrom) {
1489
+ return true;
1490
+ }
1491
+ if (this.match(tt._default) && hasFrom) {
1492
+ const nextAfterFrom = this.input.charCodeAt(this.nextTokenStartSince(next + 4));
1493
+ return nextAfterFrom === 34 || nextAfterFrom === 39;
1494
+ }
1495
+ return false;
1496
+ }
1497
+ parseExportFrom(node, expect) {
1498
+ if (this.eatContextual(tt._from)) {
1499
+ node.source = this.parseImportSource();
1500
+ this.checkExport(node);
1501
+ this.maybeParseImportAttributes(node);
1502
+ this.checkJSONModuleImport(node);
1503
+ } else if (expect) {
1504
+ this.unexpected();
1505
+ }
1506
+ this.semicolon();
1507
+ }
1508
+ shouldParseExportDeclaration() {
1509
+ const {
1510
+ type
1511
+ } = this.state;
1512
+ if (type === tt.at) {
1513
+ this.expectOnePlugin(["decorators", "decorators-legacy"]);
1514
+ if (this.hasPlugin("decorators")) {
1515
+ if (this.getPluginOption("decorators", "decoratorsBeforeExport") === true) {
1516
+ this.raise(Errors.DecoratorBeforeExport, this.state.startLoc);
1517
+ }
1518
+ return true;
1519
+ }
1520
+ }
1521
+ if (this.isUsing()) {
1522
+ this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
1523
+ return true;
1524
+ }
1525
+ if (this.isAwaitUsing()) {
1526
+ this.raise(Errors.UsingDeclarationExport, this.state.startLoc);
1527
+ return true;
1528
+ }
1529
+ return type === tt._var || type === tt._const || type === tt._function || type === tt._class || this.isLet() || this.isAsyncFunction();
1530
+ }
1531
+ checkExport(node, checkNames, isDefault, isFrom) {
1532
+ if (checkNames) {
1533
+ if (isDefault) {
1534
+ this.checkDuplicateExports(node, "default");
1535
+ if (this.hasPlugin("exportDefaultFrom")) {
1536
+ const declaration = node.declaration;
1537
+ if (declaration.type === "Identifier" && declaration.name === "from" && declaration.end - declaration.start === 4 && !declaration.extra?.parenthesized) {
1538
+ this.raise(Errors.ExportDefaultFromAsIdentifier, declaration);
1539
+ }
1540
+ }
1541
+ } else if (node.specifiers?.length) {
1542
+ for (const specifier of node.specifiers) {
1543
+ const {
1544
+ exported
1545
+ } = specifier;
1546
+ const exportName = exported.type === "Identifier" ? exported.name : exported.value;
1547
+ this.checkDuplicateExports(specifier, exportName);
1548
+ if (!isFrom && specifier.local) {
1549
+ const {
1550
+ local
1551
+ } = specifier;
1552
+ if (local.type !== "Identifier") {
1553
+ this.raise(Errors.ExportBindingIsString, specifier, {
1554
+ localName: local.value,
1555
+ exportName
1556
+ });
1557
+ } else {
1558
+ this.checkReservedWord(local.name, local.loc.start, true, false);
1559
+ this.scope.checkLocalExport(local);
1560
+ }
1561
+ }
1562
+ }
1563
+ } else if (node.declaration) {
1564
+ const decl = node.declaration;
1565
+ if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
1566
+ const {
1567
+ id
1568
+ } = decl;
1569
+ if (!id) throw new Error("Assertion failure");
1570
+ this.checkDuplicateExports(node, id.name);
1571
+ } else if (decl.type === "VariableDeclaration") {
1572
+ for (const declaration of decl.declarations) {
1573
+ this.checkDeclaration(declaration.id);
1574
+ }
1575
+ }
1576
+ }
1577
+ }
1578
+ }
1579
+ checkDeclaration(node) {
1580
+ if (node.type === "Identifier") {
1581
+ this.checkDuplicateExports(node, node.name);
1582
+ } else if (node.type === "ObjectPattern") {
1583
+ for (const prop of node.properties) {
1584
+ this.checkDeclaration(prop);
1585
+ }
1586
+ } else if (node.type === "ArrayPattern") {
1587
+ for (const elem of node.elements) {
1588
+ if (elem) {
1589
+ this.checkDeclaration(elem);
1590
+ }
1591
+ }
1592
+ } else if (node.type === "ObjectProperty") {
1593
+ this.checkDeclaration(node.value);
1594
+ } else if (node.type === "RestElement") {
1595
+ this.checkDeclaration(node.argument);
1596
+ } else if (node.type === "AssignmentPattern") {
1597
+ this.checkDeclaration(node.left);
1598
+ }
1599
+ }
1600
+ checkDuplicateExports(node, exportName) {
1601
+ if (this.exportedIdentifiers.has(exportName)) {
1602
+ if (exportName === "default") {
1603
+ this.raise(Errors.DuplicateDefaultExport, node);
1604
+ } else {
1605
+ this.raise(Errors.DuplicateExport, node, {
1606
+ exportName
1607
+ });
1608
+ }
1609
+ }
1610
+ this.exportedIdentifiers.add(exportName);
1611
+ }
1612
+ parseExportSpecifiers(isInTypeExport) {
1613
+ const nodes = [];
1614
+ let first = true;
1615
+ this.expect(tt.braceL);
1616
+ while (!this.eat(tt.braceR)) {
1617
+ if (first) {
1618
+ first = false;
1619
+ } else {
1620
+ this.expect(tt.comma);
1621
+ if (this.eat(tt.braceR)) break;
1622
+ }
1623
+ const isMaybeTypeOnly = this.isContextual(tt._type);
1624
+ const isString = this.match(tt.string);
1625
+ const node = this.startNode();
1626
+ node.local = this.parseModuleExportName();
1627
+ nodes.push(this.parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly));
1628
+ }
1629
+ return nodes;
1630
+ }
1631
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
1632
+ parseExportSpecifier(node, isString, isInTypeExport, isMaybeTypeOnly) {
1633
+ if (this.eatContextual(tt._as)) {
1634
+ node.exported = this.parseModuleExportName();
1635
+ } else if (isString) {
1636
+ node.exported = this.cloneStringLiteral(node.local);
1637
+ } else if (!node.exported) {
1638
+ node.exported = this.cloneIdentifier(node.local);
1639
+ }
1640
+ return this.finishNode(node, "ExportSpecifier");
1641
+ }
1642
+ parseModuleExportName() {
1643
+ if (this.match(tt.string)) {
1644
+ const result = this.parseStringLiteral(this.state.value);
1645
+ const surrogate = loneSurrogate.exec(result.value);
1646
+ if (surrogate) {
1647
+ this.raise(Errors.ModuleExportNameHasLoneSurrogate, result, {
1648
+ surrogateCharCode: surrogate[0].charCodeAt(0)
1649
+ });
1650
+ }
1651
+ return result;
1652
+ }
1653
+ return this.parseIdentifier(true);
1654
+ }
1655
+ isJSONModuleImport(node) {
1656
+ if (node.assertions != null) {
1657
+ return node.assertions.some(({
1658
+ key,
1659
+ value
1660
+ }) => {
1661
+ return value.value === "json" && (key.type === "Identifier" ? key.name === "type" : key.value === "type");
1662
+ });
1663
+ }
1664
+ return false;
1665
+ }
1666
+ checkImportReflection(node) {
1667
+ const {
1668
+ specifiers
1669
+ } = node;
1670
+ const singleBindingType = specifiers.length === 1 ? specifiers[0].type : null;
1671
+ if (node.phase === "source") {
1672
+ if (singleBindingType !== "ImportDefaultSpecifier") {
1673
+ this.raise(Errors.SourcePhaseImportRequiresDefault, specifiers[0].loc.start);
1674
+ }
1675
+ } else if (node.phase === "defer") {
1676
+ if (singleBindingType !== "ImportNamespaceSpecifier") {
1677
+ this.raise(Errors.DeferImportRequiresNamespace, specifiers[0].loc.start);
1678
+ }
1679
+ } else if (node.module) {
1680
+ if (singleBindingType !== "ImportDefaultSpecifier") {
1681
+ this.raise(Errors.ImportReflectionNotBinding, specifiers[0].loc.start);
1682
+ }
1683
+ if (node.assertions?.length > 0) {
1684
+ this.raise(Errors.ImportReflectionHasAssertion, specifiers[0].loc.start);
1685
+ }
1686
+ }
1687
+ }
1688
+ checkJSONModuleImport(node) {
1689
+ if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") {
1690
+ const {
1691
+ specifiers
1692
+ } = node;
1693
+ if (specifiers != null) {
1694
+ const nonDefaultNamedSpecifier = specifiers.find((specifier) => {
1695
+ let imported;
1696
+ if (specifier.type === "ExportSpecifier") {
1697
+ imported = specifier.local;
1698
+ } else if (specifier.type === "ImportSpecifier") {
1699
+ imported = specifier.imported;
1700
+ }
1701
+ if (imported !== void 0) {
1702
+ return imported.type === "Identifier" ? imported.name !== "default" : imported.value !== "default";
1703
+ }
1704
+ });
1705
+ if (nonDefaultNamedSpecifier !== void 0) {
1706
+ this.raise(Errors.ImportJSONBindingNotDefault, nonDefaultNamedSpecifier.loc.start);
1707
+ }
1708
+ }
1709
+ }
1710
+ }
1711
+ isPotentialImportPhase(isExport) {
1712
+ if (isExport) return false;
1713
+ return this.isContextual(tt._source) || this.isContextual(tt._defer) || this.isContextual(tt._module);
1714
+ }
1715
+ applyImportPhase(node, isExport, phase, loc) {
1716
+ if (isExport) {
1717
+ return;
1718
+ }
1719
+ if (phase === "module") {
1720
+ this.expectPlugin("importReflection", loc);
1721
+ node.module = true;
1722
+ } else if (this.hasPlugin("importReflection")) {
1723
+ node.module = false;
1724
+ }
1725
+ if (phase === "source") {
1726
+ this.expectPlugin("sourcePhaseImports", loc);
1727
+ node.phase = "source";
1728
+ } else if (phase === "defer") {
1729
+ this.expectPlugin("deferredImportEvaluation", loc);
1730
+ node.phase = "defer";
1731
+ } else if (this.hasPlugin("sourcePhaseImports")) {
1732
+ node.phase = null;
1733
+ }
1734
+ }
1735
+ parseMaybeImportPhase(node, isExport) {
1736
+ if (!this.isPotentialImportPhase(isExport)) {
1737
+ this.applyImportPhase(node, isExport, null);
1738
+ return null;
1739
+ }
1740
+ const phaseIdentifier = this.startNode();
1741
+ const phaseIdentifierName = this.parseIdentifierName(true);
1742
+ const {
1743
+ type
1744
+ } = this.state;
1745
+ const isImportPhase = tokenIsKeywordOrIdentifier(type) ? type !== tt._from || this.lookaheadCharCode() === 102 : type !== tt.comma;
1746
+ if (isImportPhase) {
1747
+ this.applyImportPhase(node, isExport, phaseIdentifierName, phaseIdentifier.loc.start);
1748
+ return null;
1749
+ } else {
1750
+ this.applyImportPhase(node, isExport, null);
1751
+ return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
1752
+ }
1753
+ }
1754
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Retain the upstream parser interface and bindings.
1755
+ isPrecedingIdImportPhase(phase) {
1756
+ const {
1757
+ type
1758
+ } = this.state;
1759
+ return tokenIsIdentifier(type) ? type !== tt._from || this.lookaheadCharCode() === 102 : type !== tt.comma;
1760
+ }
1761
+ parseImport(node) {
1762
+ if (this.match(tt.string)) {
1763
+ return this.parseImportSourceAndAttributes(node);
1764
+ }
1765
+ return this.parseImportSpecifiersAndAfter(node, this.parseMaybeImportPhase(node, false));
1766
+ }
1767
+ parseImportSpecifiersAndAfter(node, maybeDefaultIdentifier) {
1768
+ node.specifiers = [];
1769
+ const hasDefault = this.maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier);
1770
+ const parseNext = !hasDefault || this.eat(tt.comma);
1771
+ const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
1772
+ if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
1773
+ this.expectContextual(tt._from);
1774
+ return this.parseImportSourceAndAttributes(node);
1775
+ }
1776
+ parseImportSourceAndAttributes(node) {
1777
+ node.specifiers ??= [];
1778
+ node.source = this.parseImportSource();
1779
+ this.maybeParseImportAttributes(node);
1780
+ this.checkImportReflection(node);
1781
+ this.checkJSONModuleImport(node);
1782
+ this.semicolon();
1783
+ this.sawUnambiguousESM = true;
1784
+ return this.finishNode(node, "ImportDeclaration");
1785
+ }
1786
+ parseImportSource() {
1787
+ if (!this.match(tt.string)) this.unexpected();
1788
+ return this.parseExprAtom();
1789
+ }
1790
+ parseImportSpecifierLocal(node, specifier, type) {
1791
+ specifier.local = this.parseIdentifier();
1792
+ node.specifiers.push(this.finishImportSpecifier(specifier, type));
1793
+ }
1794
+ finishImportSpecifier(specifier, type, bindingType = BindingFlag.TYPE_LEXICAL) {
1795
+ this.checkLVal(specifier.local, {
1796
+ type
1797
+ }, bindingType);
1798
+ return this.finishNode(specifier, type);
1799
+ }
1800
+ parseImportAttributes() {
1801
+ this.expect(tt.braceL);
1802
+ const attrs = [];
1803
+ const attrNames = /* @__PURE__ */ new Set();
1804
+ do {
1805
+ if (this.match(tt.braceR)) {
1806
+ break;
1807
+ }
1808
+ const node = this.startNode();
1809
+ const keyName = this.state.value;
1810
+ if (attrNames.has(keyName)) {
1811
+ this.raise(Errors.ModuleAttributesWithDuplicateKeys, this.state.startLoc, {
1812
+ key: keyName
1813
+ });
1814
+ }
1815
+ attrNames.add(keyName);
1816
+ if (this.match(tt.string)) {
1817
+ node.key = this.parseStringLiteral(keyName);
1818
+ } else {
1819
+ node.key = this.parseIdentifier(true);
1820
+ }
1821
+ this.expect(tt.colon);
1822
+ if (!this.match(tt.string)) {
1823
+ throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
1824
+ }
1825
+ node.value = this.parseStringLiteral(this.state.value);
1826
+ attrs.push(this.finishNode(node, "ImportAttribute"));
1827
+ } while (this.eat(tt.comma));
1828
+ this.expect(tt.braceR);
1829
+ return attrs;
1830
+ }
1831
+ parseModuleAttributes() {
1832
+ const attrs = [];
1833
+ const attributes = /* @__PURE__ */ new Set();
1834
+ do {
1835
+ const node = this.startNode();
1836
+ node.key = this.parseIdentifier(true);
1837
+ if (node.key.name !== "type") {
1838
+ this.raise(Errors.ModuleAttributeDifferentFromType, node.key);
1839
+ }
1840
+ if (attributes.has(node.key.name)) {
1841
+ this.raise(Errors.ModuleAttributesWithDuplicateKeys, node.key, {
1842
+ key: node.key.name
1843
+ });
1844
+ }
1845
+ attributes.add(node.key.name);
1846
+ this.expect(tt.colon);
1847
+ if (!this.match(tt.string)) {
1848
+ throw this.raise(Errors.ModuleAttributeInvalidValue, this.state.startLoc);
1849
+ }
1850
+ node.value = this.parseStringLiteral(this.state.value);
1851
+ attrs.push(this.finishNode(node, "ImportAttribute"));
1852
+ } while (this.eat(tt.comma));
1853
+ return attrs;
1854
+ }
1855
+ maybeParseImportAttributes(node) {
1856
+ let attributes;
1857
+ {
1858
+ var useWith = false;
1859
+ }
1860
+ if (this.match(tt._with)) {
1861
+ if (this.hasPrecedingLineBreak() && this.lookaheadCharCode() === 40) {
1862
+ return;
1863
+ }
1864
+ this.next();
1865
+ if (this.hasPlugin("moduleAttributes")) {
1866
+ attributes = this.parseModuleAttributes();
1867
+ this.addExtra(node, "deprecatedWithLegacySyntax", true);
1868
+ } else {
1869
+ attributes = this.parseImportAttributes();
1870
+ }
1871
+ {
1872
+ useWith = true;
1873
+ }
1874
+ } else if (this.isContextual(tt._assert) && !this.hasPrecedingLineBreak()) {
1875
+ if (!this.hasPlugin("deprecatedImportAssert") && !this.hasPlugin("importAssertions")) {
1876
+ this.raise(Errors.ImportAttributesUseAssert, this.state.startLoc);
1877
+ }
1878
+ if (!this.hasPlugin("importAssertions")) {
1879
+ this.addExtra(node, "deprecatedAssertSyntax", true);
1880
+ }
1881
+ this.next();
1882
+ attributes = this.parseImportAttributes();
1883
+ } else {
1884
+ attributes = [];
1885
+ }
1886
+ if (!useWith && this.hasPlugin("importAssertions")) {
1887
+ node.assertions = attributes;
1888
+ } else {
1889
+ node.attributes = attributes;
1890
+ }
1891
+ }
1892
+ maybeParseDefaultImportSpecifier(node, maybeDefaultIdentifier) {
1893
+ if (maybeDefaultIdentifier) {
1894
+ const specifier = this.startNodeAtNode(maybeDefaultIdentifier);
1895
+ specifier.local = maybeDefaultIdentifier;
1896
+ node.specifiers.push(this.finishImportSpecifier(specifier, "ImportDefaultSpecifier"));
1897
+ return true;
1898
+ } else if (tokenIsKeywordOrIdentifier(this.state.type)) {
1899
+ this.parseImportSpecifierLocal(node, this.startNode(), "ImportDefaultSpecifier");
1900
+ return true;
1901
+ }
1902
+ return false;
1903
+ }
1904
+ maybeParseStarImportSpecifier(node) {
1905
+ if (this.match(tt.star)) {
1906
+ const specifier = this.startNode();
1907
+ this.next();
1908
+ this.expectContextual(tt._as);
1909
+ this.parseImportSpecifierLocal(node, specifier, "ImportNamespaceSpecifier");
1910
+ return true;
1911
+ }
1912
+ return false;
1913
+ }
1914
+ parseNamedImportSpecifiers(node) {
1915
+ let first = true;
1916
+ this.expect(tt.braceL);
1917
+ while (!this.eat(tt.braceR)) {
1918
+ if (first) {
1919
+ first = false;
1920
+ } else {
1921
+ if (this.eat(tt.colon)) {
1922
+ throw this.raise(Errors.DestructureNamedImport, this.state.startLoc);
1923
+ }
1924
+ this.expect(tt.comma);
1925
+ if (this.eat(tt.braceR)) break;
1926
+ }
1927
+ const specifier = this.startNode();
1928
+ const importedIsString = this.match(tt.string);
1929
+ const isMaybeTypeOnly = this.isContextual(tt._type);
1930
+ specifier.imported = this.parseModuleExportName();
1931
+ const importSpecifier = this.parseImportSpecifier(specifier, importedIsString, node.importKind === "type" || node.importKind === "typeof", isMaybeTypeOnly, void 0);
1932
+ node.specifiers.push(importSpecifier);
1933
+ }
1934
+ }
1935
+ parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
1936
+ if (this.eatContextual(tt._as)) {
1937
+ specifier.local = this.parseIdentifier();
1938
+ } else {
1939
+ const {
1940
+ imported
1941
+ } = specifier;
1942
+ if (importedIsString) {
1943
+ throw this.raise(Errors.ImportBindingIsString, specifier, {
1944
+ importName: imported.value
1945
+ });
1946
+ }
1947
+ this.checkReservedWord(imported.name, specifier.loc.start, true, true);
1948
+ if (!specifier.local) {
1949
+ specifier.local = this.cloneIdentifier(imported);
1950
+ }
1951
+ }
1952
+ return this.finishImportSpecifier(specifier, "ImportSpecifier", bindingType);
1953
+ }
1954
+ isThisParam(param) {
1955
+ return param.type === "Identifier" && param.name === "this";
1956
+ }
1957
+ }
1958
+ export {
1959
+ ParseFunctionFlag,
1960
+ ParseStatementFlag,
1961
+ StatementParser as default
1962
+ };