[rust] Autofix lints
Joe Savona committed
Aug 10, 2023 at 10:59 UTC
74a062ba9dfe0228069bfc776abc3e5bd9176440
13 files changed
+34
-1442
compiler/forget/crates/forget_build_hir/src/build.rs
+12
-15
@@ -2,9 +2,8 @@ use std::collections::HashSet;
2
3
use forget_diagnostics::Diagnostic;
4
use forget_estree::{
5
- AssignmentTarget, BinaryExpression, BlockStatement, Expression, ExpressionOrSpread,
6
- ExpressionOrSuper, ForInit, ForStatement, Function, FunctionExpression, IfStatement,
7
- IntoFunction, JsValue, Literal, Number, Pattern, Statement, VariableDeclaration,
5
+ AssignmentTarget, BlockStatement, Expression, ExpressionOrSpread, ExpressionOrSuper, ForInit,
6
+ Function, IntoFunction, JsValue, Pattern, Statement, VariableDeclaration,
7
VariableDeclarationKind,
8
};
9
use forget_hir::{
@@ -13,7 +12,7 @@ use forget_hir::{
12
Operand, PlaceOrSpread, TerminalValue,
13
};
14
16
-use crate::builder::{Binding, Builder, LoopScope};
15
+use crate::builder::{Builder, LoopScope};
16
use crate::context::get_context_identifiers;
17
use crate::error::BuildHIRError;
18
@@ -490,9 +489,7 @@ fn lower_function<T: IntoFunction>(
489
_builder: &mut Builder,
490
function: &T,
491
) -> Result<forget_hir::FunctionExpression, Diagnostic> {
493
- println!("get_context_identifiers() ...");
492
let context_identifiers = get_context_identifiers(env, function);
495
- println!("ok");
493
let mut context = Vec::new();
494
let mut seen = HashSet::new();
495
for declaration_id in context_identifiers {
@@ -526,7 +523,7 @@ fn lower_jsx_element(
523
.iter()
524
.map(|attr| lower_jsx_attribute(env, builder, attr))
525
.collect();
529
- let props = props?;
526
+ let _props = props?;
527
let children: Result<Vec<Operand>, Diagnostic> = expr
528
.children
529
.iter()
@@ -535,7 +532,7 @@ fn lower_jsx_element(
532
Ok(Operand { effect: None, ix })
533
})
534
.collect();
538
- let children = children?;
535
+ let _children = children?;
536
todo!("lower jsx element");
537
// Ok(JSXElement {
538
// tag: todo!(),
@@ -549,17 +546,17 @@ fn lower_jsx_element(
546
}
547
548
fn lower_jsx_attribute(
552
- env: &Environment,
553
- builder: &mut Builder,
554
- attr: &forget_estree::JSXAttributeOrSpread,
549
+ _env: &Environment,
550
+ _builder: &mut Builder,
551
+ _attr: &forget_estree::JSXAttributeOrSpread,
552
) -> Result<JSXAttribute, Diagnostic> {
553
todo!("lower jsx attribute")
554
}
555
556
fn lower_jsx_child(
560
- env: &Environment,
561
- builder: &mut Builder,
562
- child: &forget_estree::JSXChildItem,
557
+ _env: &Environment,
558
+ _builder: &mut Builder,
559
+ _child: &forget_estree::JSXChildItem,
560
) -> Result<InstrIx, Diagnostic> {
561
todo!("lower jsx child")
562
}
@@ -603,7 +600,7 @@ fn lower_assignment_pattern(
600
601
fn lower_identifier_for_assignment(
602
env: &Environment,
606
- builder: &mut Builder,
603
+ _builder: &mut Builder,
604
kind: InstructionKind,
605
node: &forget_estree::Identifier,
606
) -> Result<IdentifierOperand, Diagnostic> {
compiler/forget/crates/forget_build_hir/src/builder.rs
+3
-9
@@ -3,9 +3,9 @@ use std::rc::Rc;
3
4
use forget_diagnostics::Diagnostic;
5
use forget_hir::{
6
- initialize_hir, BasicBlock, BlockId, BlockKind, Blocks, Environment, GotoKind, Identifier,
7
- IdentifierData, InstrIx, Instruction, InstructionIdGenerator, InstructionValue, Terminal,
8
- TerminalValue, Type, HIR,
6
+ initialize_hir, BasicBlock, BlockId, BlockKind, Blocks, Environment, GotoKind, IdentifierData,
7
+ InstrIx, Instruction, InstructionIdGenerator, InstructionValue, Terminal, TerminalValue, Type,
8
+ HIR,
9
};
10
11
use crate::BuildHIRError;
@@ -42,12 +42,6 @@ pub(crate) struct WipBlock {
42
pub instructions: Vec<InstrIx>,
43
}
44
45
-pub(crate) enum Binding {
46
- Local(Identifier),
47
- Module(Identifier),
48
- Global,
49
-}
50
-
45
#[derive(Clone, PartialEq, Eq, Debug)]
46
enum ControlFlowScope {
47
Loop(LoopScope),
compiler/forget/crates/forget_build_hir/src/context.rs
-21
@@ -9,10 +9,6 @@ pub(crate) fn get_context_identifiers<T: IntoFunction>(
9
node: &T,
10
) -> Vec<DeclarationId> {
11
let function_scope = env.scope(node.function()).unwrap();
12
- println!(
13
- "get_context_identifiers for function scope {:?}",
14
- function_scope.id()
15
- );
12
let mut free = FreeVariables::default();
13
let mut seen = HashSet::new();
14
populate_free_variable_references(&mut free, &mut seen, function_scope);
@@ -28,28 +24,11 @@ fn populate_free_variable_references(
24
) {
25
for reference in scope.references() {
26
if !seen.insert(reference.declaration().id()) {
31
- println!(
32
- "skip {}${:?}",
33
- reference.declaration().name(),
34
- reference.declaration().id()
35
- );
27
continue;
28
}
29
let declaration_scope = reference.declaration().scope();
30
if !declaration_scope.is_descendant_of(scope) {
40
- println!(
41
- "free variable: not descendant {}${:?}",
42
- reference.declaration().name(),
43
- reference.declaration().id()
44
- );
31
free.push(reference.declaration().id())
46
- } else {
47
- println!(
48
- "local variable: descendant {}${:?} scope={:?}",
49
- reference.declaration().name(),
50
- reference.declaration().id(),
51
- reference.declaration().scope().id()
52
- );
32
}
33
}
34
for child in scope.children() {
compiler/forget/crates/forget_estree/src/generated.rs
+3
@@ -1,5 +1,8 @@
1
// @generated
2
#![cfg_attr(rustfmt, rustfmt_skip)]
3
+#![allow(dead_code)]
4
+#![allow(unused_variables)]
5
+#![allow(non_snake_case)]
6
use std::num::NonZeroU32;
7
use serde::ser::{Serializer, SerializeMap};
8
use serde::{Serialize, Deserialize};
compiler/forget/crates/forget_estree/src/old.lib.rs
deleted
-1358
@@ -1,1358 +0,0 @@
1
-use serde::{Deserialize, Serialize};
2
-use static_assertions::assert_eq_size;
3
-use std::{fmt::Display, num::NonZeroU32};
4
-
5
-#[derive(Serialize, Deserialize, Debug)]
6
-pub struct SourceLocation {
7
- pub source: Option<String>,
8
-
9
- pub start: Position,
10
-
11
- pub end: Position,
12
-}
13
-
14
-#[derive(Serialize, Deserialize, Debug, Clone)]
15
-pub struct Position {
16
- /// >= 1
17
- pub line: NonZeroU32,
18
- /// >= 0
19
- pub column: u32,
20
-}
21
-assert_eq_size!(Option<Position>, u64);
22
-
23
-#[derive(Serialize, Deserialize, Debug, Clone)]
24
-pub struct SourceRange {
25
- pub start: u32,
26
- // end is exclusive so it can always be non-zero. This allows
27
- // Option<SourceRange> to not take any additional bytes.
28
- pub end: NonZeroU32,
29
-}
30
-assert_eq_size!(Option<SourceRange>, u64);
31
-
32
-#[derive(Serialize, Deserialize, Debug)]
33
-pub struct Program {
34
- /// sourceType
35
- #[serde(rename = "sourceType")]
36
- #[serde(default)]
37
- pub source_type: SourceType,
38
-
39
- pub body: Vec<ModuleItem>,
40
-
41
- #[serde(default)]
42
- pub comments: Option<Vec<Comment>>,
43
-
44
- pub loc: Option<SourceLocation>,
45
-
46
- #[serde(default)]
47
- pub range: Option<SourceRange>,
48
-}
49
-
50
-#[derive(Serialize, Deserialize, Debug)]
51
-pub enum SourceType {
52
- /// "module"
53
- #[serde(rename = "module")]
54
- Module,
55
- /// "script"
56
- #[serde(rename = "script")]
57
- Script,
58
-}
59
-
60
-impl Default for SourceType {
61
- fn default() -> Self {
62
- Self::Module
63
- }
64
-}
65
-
66
-#[derive(Serialize, Deserialize, Debug)]
67
-pub struct Comment {
68
- pub type_: CommentType,
69
- pub value: String,
70
-}
71
-
72
-#[derive(Serialize, Deserialize, Debug)]
73
-pub enum CommentType {
74
- /// "Line"
75
- Line,
76
- /// "Block"
77
- Block,
78
-}
79
-
80
-#[derive(Serialize, Deserialize, Debug)]
81
-#[serde(untagged)]
82
-pub enum ModuleItem {
83
- Statement(Box<Statement>),
84
- ImportDeclaration(Box<ImportDeclaration>),
85
-}
86
-
87
-#[derive(Serialize, Deserialize, Debug)]
88
-#[serde(tag = "type")]
89
-pub enum ImportExportDeclaration {
90
- ImportDeclaration(Box<ImportDeclaration>),
91
- // TODO:
92
- // ExportNamedDeclaration(Box<ExportNamedDeclaration>),
93
- // ExportDefaultDeclaration(Box<ExportDefaultDeclaration>),
94
- // ExportAllDeclaration(Box<ExportAllDeclaration>),
95
-}
96
-
97
-#[derive(Serialize, Deserialize, Debug)]
98
-pub struct ImportDeclaration {
99
- pub specifiers: Vec<ImportSpecifiers>,
100
- pub source: Literal,
101
- pub loc: Option<SourceLocation>,
102
- #[serde(default)]
103
- pub range: Option<SourceRange>,
104
-}
105
-
106
-#[derive(Serialize, Deserialize, Debug)]
107
-#[serde(tag = "type")]
108
-pub enum ImportSpecifiers {
109
- ImportSpecifier(Box<ImportSpecifier>),
110
- ImportDefaultSpecifier(Box<ImportDefaultSpecifier>),
111
-}
112
-
113
-#[derive(Serialize, Deserialize, Debug)]
114
-pub struct ImportSpecifier {
115
- pub imported: Identifier,
116
-
117
- pub local: Identifier,
118
-
119
- pub loc: Option<SourceLocation>,
120
-
121
- #[serde(default)]
122
- pub range: Option<SourceRange>,
123
-}
124
-
125
-#[derive(Serialize, Deserialize, Debug)]
126
-pub struct ImportDefaultSpecifier {
127
- pub local: Identifier,
128
-
129
- pub loc: Option<SourceLocation>,
130
-
131
- #[serde(default)]
132
- pub range: Option<SourceRange>,
133
-}
134
-
135
-#[derive(Serialize, Deserialize, Debug)]
136
-#[serde(tag = "type")]
137
-pub enum Statement {
138
- BlockStatement(Box<BlockStatement>),
139
- BreakStatement(Box<BreakStatement>),
140
- ClassDeclaration(Box<ClassDeclaration>),
141
- ContinueStatement(Box<ContinueStatement>),
142
- DebuggerStatement(Box<DebuggerStatement>),
143
- DoWhileStatement(Box<DoWhileStatement>),
144
- EmptyStatement(Box<EmptyStatement>),
145
- ExpressionStatement(Box<ExpressionStatement>),
146
- ForInStatement(Box<ForInStatement>),
147
- ForOfStatement(Box<ForOfStatement>),
148
- ForStatement(Box<ForStatement>),
149
- FunctionDeclaration(Box<FunctionDeclaration>),
150
- IfStatement(Box<IfStatement>),
151
- LabeledStatement(Box<LabeledStatement>),
152
- ReturnStatement(Box<ReturnStatement>),
153
- StaticBlock(Box<StaticBlock>),
154
- SwitchStatement(Box<SwitchStatement>),
155
- ThrowStatement(Box<ThrowStatement>),
156
- TryStatement(Box<TryStatement>),
157
- VariableDeclaration(Box<VariableDeclaration>),
158
- WhileStatement(Box<WhileStatement>),
159
- WithStatement(Box<WithStatement>),
160
-}
161
-// Prevent unboxed variants from increasing the size
162
-assert_eq_size!(Statement, u128);
163
-
164
-#[derive(Serialize, Deserialize, Debug)]
165
-pub struct BlockStatement {
166
- pub body: Vec<Statement>,
167
- pub loc: Option<SourceLocation>,
168
- #[serde(default)]
169
- pub range: Option<SourceRange>,
170
-}
171
-
172
-#[derive(Serialize, Deserialize, Debug)]
173
-pub struct BreakStatement {
174
- #[serde(default)]
175
- pub label: Option<Identifier>,
176
- pub loc: Option<SourceLocation>,
177
- #[serde(default)]
178
- pub range: Option<SourceRange>,
179
-}
180
-
181
-#[derive(Serialize, Deserialize, Debug)]
182
-pub struct ClassDeclaration {
183
- pub loc: Option<SourceLocation>,
184
- #[serde(default)]
185
- pub range: Option<SourceRange>,
186
-}
187
-
188
-#[derive(Serialize, Deserialize, Debug)]
189
-pub struct ContinueStatement {
190
- #[serde(default)]
191
- pub label: Option<Identifier>,
192
- pub loc: Option<SourceLocation>,
193
- #[serde(default)]
194
- pub range: Option<SourceRange>,
195
-}
196
-
197
-#[derive(Serialize, Deserialize, Debug)]
198
-pub struct DebuggerStatement {
199
- pub loc: Option<SourceLocation>,
200
- #[serde(default)]
201
- pub range: Option<SourceRange>,
202
-}
203
-
204
-#[derive(Serialize, Deserialize, Debug)]
205
-pub struct DoWhileStatement {
206
- pub body: Statement,
207
- pub test: ExpressionLike,
208
- pub loc: Option<SourceLocation>,
209
- #[serde(default)]
210
- pub range: Option<SourceRange>,
211
-}
212
-
213
-#[derive(Serialize, Deserialize, Debug)]
214
-pub struct EmptyStatement {
215
- pub loc: Option<SourceLocation>,
216
- #[serde(default)]
217
- pub range: Option<SourceRange>,
218
-}
219
-
220
-#[derive(Serialize, Deserialize, Debug)]
221
-pub struct FunctionDeclaration {
222
- pub id: Option<Identifier>,
223
-
224
- pub params: Vec<Pattern>,
225
-
226
- #[serde(rename = "generator")]
227
- #[serde(default)]
228
- pub is_generator: bool,
229
-
230
- #[serde(rename = "async")]
231
- #[serde(default)]
232
- pub is_async: bool,
233
-
234
- // TODO: BlockStatement
235
- pub body: Option<Statement>,
236
-
237
- pub loc: Option<SourceLocation>,
238
- #[serde(default)]
239
- pub range: Option<SourceRange>,
240
-}
241
-
242
-#[derive(Serialize, Deserialize, Debug)]
243
-pub struct StaticBlock {
244
- pub body: Vec<Statement>,
245
- pub loc: Option<SourceLocation>,
246
- #[serde(default)]
247
- pub range: Option<SourceRange>,
248
-}
249
-
250
-#[derive(Serialize, Deserialize, Debug)]
251
-pub struct ExpressionStatement {
252
- pub expression: ExpressionLike,
253
-
254
- #[serde(default)]
255
- pub directive: Option<String>,
256
-
257
- pub loc: Option<SourceLocation>,
258
-
259
- #[serde(default)]
260
- pub range: Option<SourceRange>,
261
-}
262
-
263
-#[derive(Serialize, Deserialize, Debug)]
264
-pub struct ForInStatement {
265
- pub left: ForPattern,
266
- pub right: ExpressionLike,
267
- pub body: Statement,
268
- pub loc: Option<SourceLocation>,
269
- #[serde(default)]
270
- pub range: Option<SourceRange>,
271
-}
272
-
273
-#[derive(Serialize, Deserialize, Debug)]
274
-pub struct ForOfStatement {
275
- #[serde(rename = "await")]
276
- #[serde(default)]
277
- pub is_await: bool,
278
-
279
- pub left: ForPattern,
280
-
281
- pub right: ExpressionLike,
282
-
283
- pub body: Statement,
284
-
285
- pub loc: Option<SourceLocation>,
286
- #[serde(default)]
287
- pub range: Option<SourceRange>,
288
-}
289
-
290
-#[derive(Serialize, Deserialize, Debug)]
291
-#[serde(tag = "type")]
292
-pub enum ForPattern {
293
- VariableDeclaration(Box<VariableDeclaration>),
294
- Expression(Box<ExpressionLike>),
295
-}
296
-
297
-#[derive(Serialize, Deserialize, Debug)]
298
-pub struct ForStatement {
299
- pub init: Option<ForInit>,
300
- pub test: Option<ExpressionLike>,
301
- pub update: Option<ExpressionLike>,
302
- pub body: Statement,
303
- pub loc: Option<SourceLocation>,
304
- #[serde(default)]
305
- pub range: Option<SourceRange>,
306
-}
307
-
308
-#[derive(Serialize, Deserialize, Debug)]
309
-#[serde(tag = "type")]
310
-pub enum ForInit {
311
- VariableDeclaration(Box<VariableDeclaration>),
312
- Expression(Box<ExpressionLike>),
313
-}
314
-
315
-#[derive(Serialize, Deserialize, Debug)]
316
-pub struct IfStatement {
317
- pub test: ExpressionLike,
318
- pub consequent: Statement,
319
- pub alternate: Option<Statement>,
320
- pub loc: Option<SourceLocation>,
321
- #[serde(default)]
322
- pub range: Option<SourceRange>,
323
-}
324
-
325
-#[derive(Serialize, Deserialize, Debug)]
326
-pub struct LabeledStatement {
327
- pub label: Identifier,
328
- pub body: Statement,
329
- pub loc: Option<SourceLocation>,
330
- #[serde(default)]
331
- pub range: Option<SourceRange>,
332
-}
333
-
334
-#[derive(Serialize, Deserialize, Debug)]
335
-pub struct ReturnStatement {
336
- pub argument: Option<ExpressionLike>,
337
- pub loc: Option<SourceLocation>,
338
- #[serde(default)]
339
- pub range: Option<SourceRange>,
340
-}
341
-
342
-#[derive(Serialize, Deserialize, Debug)]
343
-pub struct SwitchStatement {
344
- pub discriminant: ExpressionLike,
345
- pub cases: Vec<SwitchCase>,
346
- pub loc: Option<SourceLocation>,
347
- #[serde(default)]
348
- pub range: Option<SourceRange>,
349
-}
350
-
351
-#[derive(Serialize, Deserialize, Debug)]
352
-pub struct SwitchCase {
353
- pub test: Option<ExpressionLike>,
354
- pub consequent: Vec<Statement>,
355
- pub loc: Option<SourceLocation>,
356
- #[serde(default)]
357
- pub range: Option<SourceRange>,
358
-}
359
-
360
-#[derive(Serialize, Deserialize, Debug)]
361
-pub struct ThrowStatement {
362
- pub argument: ExpressionLike,
363
- pub loc: Option<SourceLocation>,
364
- #[serde(default)]
365
- pub range: Option<SourceRange>,
366
-}
367
-
368
-#[derive(Serialize, Deserialize, Debug)]
369
-pub struct TryStatement {
370
- // TODO: block: BlockStatement
371
- pub block: Statement,
372
- pub handler: Option<CatchClause>,
373
- // TODO: finalizer: BlockStatement
374
- pub finalizer: Option<Statement>,
375
- pub loc: Option<SourceLocation>,
376
- #[serde(default)]
377
- pub range: Option<SourceRange>,
378
-}
379
-
380
-#[derive(Serialize, Deserialize, Debug)]
381
-pub struct CatchClause {
382
- pub param: Option<Pattern>,
383
- pub body: Statement,
384
- pub loc: Option<SourceLocation>,
385
- #[serde(default)]
386
- pub range: Option<SourceRange>,
387
-}
388
-
389
-#[derive(Serialize, Deserialize, Debug)]
390
-pub struct VariableDeclaration {
391
- pub declarations: Vec<VariableDeclarator>,
392
- pub kind: VariableDeclarationKind,
393
- pub loc: Option<SourceLocation>,
394
- #[serde(default)]
395
- pub range: Option<SourceRange>,
396
-}
397
-
398
-#[derive(Serialize, Deserialize, Debug)]
399
-pub struct VariableDeclarator {
400
- pub id: Pattern,
401
- pub init: Option<ExpressionLike>,
402
- pub loc: Option<SourceLocation>,
403
- #[serde(default)]
404
- pub range: Option<SourceRange>,
405
-}
406
-
407
-#[derive(Serialize, Deserialize, Debug)]
408
-pub enum VariableDeclarationKind {
409
- #[serde(rename = "const")]
410
- Const,
411
- #[serde(rename = "let")]
412
- Let,
413
- #[serde(rename = "var")]
414
- Var,
415
-}
416
-
417
-#[derive(Serialize, Deserialize, Debug)]
418
-pub struct WhileStatement {
419
- pub test: ExpressionLike,
420
- pub body: Statement,
421
- pub loc: Option<SourceLocation>,
422
- #[serde(default)]
423
- pub range: Option<SourceRange>,
424
-}
425
-
426
-#[derive(Serialize, Deserialize, Debug)]
427
-pub struct WithStatement {
428
- pub object: ExpressionLike,
429
- pub body: Statement,
430
- pub loc: Option<SourceLocation>,
431
- #[serde(default)]
432
- pub range: Option<SourceRange>,
433
-}
434
-
435
-/// Expressions and expression-like nodes
436
-/// we flatten these into a single enum to work around limits
437
-/// of serde enum format with handling arbitrary unions
438
-#[derive(Serialize, Deserialize, Debug)]
439
-#[serde(tag = "type")]
440
-pub enum ExpressionLike {
441
- ArrayExpression(Box<ArrayExpression>),
442
- ArrowFunctionExpression(Box<ArrowFunctionExpression>),
443
- AssignmentExpression(Box<AssignmentExpression>),
444
- AwaitExpression(Box<AwaitExpression>),
445
- BinaryExpression(Box<BinaryExpression>),
446
- CallExpression(Box<CallExpression>),
447
- ChainExpression(Box<ChainExpression>),
448
- ClassExpression(Box<ClassExpression>),
449
- ConditionalExpression(Box<ConditionalExpression>),
450
- FunctionExpression(Box<FunctionExpression>),
451
- Identifier(Box<Identifier>),
452
- ImportExpression(Box<ImportExpression>),
453
- Literal(Box<Literal>),
454
- LogicalExpression(Box<LogicalExpression>),
455
- MemberExpression(Box<MemberExpression>),
456
- MetaProperty(Box<MetaProperty>),
457
- NewExpression(Box<NewExpression>),
458
- ObjectExpression(Box<ObjectExpression>),
459
- SequenceExpression(Box<SequenceExpression>),
460
- TaggedTemplateExpression(Box<TaggedTemplateExpression>),
461
- TemplateLiteral(Box<TemplateLiteral>),
462
- ThisExpression(Box<ThisExpression>),
463
- UnaryExpression(Box<UnaryExpression>),
464
- UpdateExpression(Box<UpdateExpression>),
465
- YieldExpression(Box<YieldExpression>),
466
-
467
- // pseudo-expressions to work with serde
468
- Super(Box<Super>),
469
-
470
- // patterns to work with serde
471
- ArrayPattern(Box<ArrayPattern>),
472
- AssignmentPattern(Box<AssignmentPattern>),
473
- ObjectPattern(Box<ObjectPattern>),
474
- Property(Box<Property>),
475
- RestElement(Box<RestElement>),
476
- SpreadElement(Box<SpreadElement>),
477
-
478
- // jsx expression-ish types to work with serde
479
- JSXClosingElement(Box<JSXClosingElement>),
480
- JSXElement(Box<JSXElement>),
481
- JSXExpressionContainer(Box<JSXExpressionContainer>),
482
- JSXIdentifier(Box<JSXIdentifier>),
483
- JSXMemberExpression(Box<JSXMemberExpression>),
484
- JSXNamedspacedName(Box<JSXNamedspacedName>),
485
- JSXOpeningElement(Box<JSXOpeningElement>),
486
- JSXText(Box<JSXText>),
487
-}
488
-// Prevent unboxed variants from increasing the size
489
-assert_eq_size!(ExpressionLike, u128);
490
-
491
-#[derive(Serialize, Deserialize, Debug)]
492
-pub struct ArrayExpression {
493
- pub elements: Vec<ExpressionLike>,
494
- pub loc: Option<SourceLocation>,
495
- #[serde(default)]
496
- pub range: Option<SourceRange>,
497
-}
498
-
499
-#[derive(Serialize, Deserialize, Debug)]
500
-pub struct ArrowFunctionExpression {
501
- pub params: Vec<Pattern>,
502
-
503
- #[serde(rename = "generator")]
504
- #[serde(default)]
505
- pub is_generator: bool,
506
-
507
- #[serde(rename = "async")]
508
- #[serde(default)]
509
- pub is_async: bool,
510
-
511
- #[serde(rename = "expression")]
512
- #[serde(default)]
513
- pub is_expression: bool,
514
-
515
- pub body: BlockOrExpression,
516
-
517
- pub loc: Option<SourceLocation>,
518
- #[serde(default)]
519
- pub range: Option<SourceRange>,
520
-}
521
-
522
-#[derive(Serialize, Deserialize, Debug)]
523
-#[serde(tag = "type")]
524
-pub enum BlockOrExpression {
525
- BlockStatement(Box<BlockStatement>),
526
- Expression(Box<ExpressionLike>),
527
-}
528
-
529
-#[derive(Serialize, Deserialize, Debug)]
530
-pub struct AssignmentExpression {
531
- pub operator: AssignmentOperator,
532
- pub left: AssignmentTarget,
533
- pub right: ExpressionLike,
534
- pub loc: Option<SourceLocation>,
535
- #[serde(default)]
536
- pub range: Option<SourceRange>,
537
-}
538
-
539
-#[derive(Serialize, Deserialize, Debug)]
540
-pub enum AssignmentOperator {
541
- /// =
542
- #[serde(rename = "=")]
543
- Equals,
544
- /// +=
545
- #[serde(rename = "+=")]
546
- PlusEquals,
547
- // -=
548
- #[serde(rename = "-=")]
549
- MinusEquals,
550
- /// *=
551
- #[serde(rename = "*=")]
552
- AsteriskEquals,
553
- /// /=
554
- #[serde(rename = "/=")]
555
- SlashEquals,
556
- /// %=
557
- #[serde(rename = "%=")]
558
- PercentEquals,
559
- /// **=
560
- #[serde(rename = "**=")]
561
- AsteriskAsteriskEquals,
562
- /// <<=
563
- #[serde(rename = "<<=")]
564
- LtLtEquals,
565
- /// >>=
566
- #[serde(rename = ">>=")]
567
- GtGtEquals,
568
- /// >>>=
569
- #[serde(rename = ">>>=")]
570
- GtGtGtEquals,
571
- /// |=
572
- #[serde(rename = "|=")]
573
- PipeEquals,
574
- /// ^=
575
- #[serde(rename = "^=")]
576
- CaretEquals,
577
- /// &=
578
- #[serde(rename = "&&=")]
579
- AmpersandEquals,
580
- /// ||=
581
- #[serde(rename = "||=")]
582
- PipePipeEquals,
583
- /// &&=
584
- #[serde(rename = "&&=")]
585
- AmpersandAmpersandEquals,
586
- // ??=
587
- #[serde(rename = "??=")]
588
- QuestionQuestionEquals,
589
-}
590
-
591
-impl AssignmentOperator {
592
- pub fn is_simple_equals(&self) -> bool {
593
- matches!(self, AssignmentOperator::Equals)
594
- }
595
-}
596
-
597
-#[derive(Serialize, Deserialize, Debug)]
598
-#[serde(untagged)]
599
-pub enum AssignmentTarget {
600
- Pattern(Box<Pattern>),
601
- MemberExpression(Box<MemberExpression>),
602
-}
603
-
604
-#[derive(Serialize, Deserialize, Debug)]
605
-pub struct AwaitExpression {
606
- pub argument: ExpressionLike,
607
- pub loc: Option<SourceLocation>,
608
- #[serde(default)]
609
- pub range: Option<SourceRange>,
610
-}
611
-
612
-#[derive(Serialize, Deserialize, Debug)]
613
-pub struct BinaryExpression {
614
- pub operator: BinaryOperator,
615
- pub left: ExpressionLike,
616
- pub right: ExpressionLike,
617
- pub loc: Option<SourceLocation>,
618
- #[serde(default)]
619
- pub range: Option<SourceRange>,
620
-}
621
-
622
-#[derive(Serialize, Deserialize, Debug)]
623
-pub enum BinaryOperator {
624
- /// ==
625
- #[serde(rename = "==")]
626
- EqualsEquals,
627
- /// !=
628
- #[serde(rename = "!=")]
629
- NotEquals,
630
- /// ===
631
- #[serde(rename = "===")]
632
- TripleEquals,
633
- /// !==
634
- #[serde(rename = "!==")]
635
- NotTripleEquals,
636
- /// <
637
- #[serde(rename = "<")]
638
- LessThan,
639
- /// <=
640
- #[serde(rename = "<=")]
641
- LessThanEquals,
642
- /// >
643
- #[serde(rename = ">")]
644
- GreaterThan,
645
- /// >=
646
- #[serde(rename = ">=")]
647
- GreaterThanEquals,
648
- /// <<
649
- #[serde(rename = "<<")]
650
- LtLt,
651
- /// >>
652
- #[serde(rename = ">>")]
653
- GtGt,
654
- /// >>>
655
- #[serde(rename = ">>>")]
656
- GtGtGt,
657
- /// +
658
- #[serde(rename = "+")]
659
- Plus,
660
- /// -
661
- #[serde(rename = "-")]
662
- Minus,
663
- /// *
664
- #[serde(rename = "*")]
665
- Asterisk,
666
- /// /
667
- #[serde(rename = "/")]
668
- Slash,
669
- /// %
670
- #[serde(rename = "%")]
671
- Percent,
672
- /// **
673
- #[serde(rename = "**")]
674
- AsteriskAsterisk,
675
- /// |
676
- #[serde(rename = "|")]
677
- Pipe,
678
- /// ^
679
- #[serde(rename = "^")]
680
- Caret,
681
- /// &
682
- #[serde(rename = "&")]
683
- Ampersand,
684
- /// in
685
- #[serde(rename = "in")]
686
- In,
687
- /// instanceof
688
- #[serde(rename = "instanceof")]
689
- Instanceof,
690
-}
691
-
692
-impl Display for BinaryOperator {
693
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
694
- let name = match self {
695
- Self::Plus => "+",
696
- Self::LessThan => "<",
697
- _ => todo!("display for operator: {:#?}", self),
698
- };
699
- f.write_str(name)
700
- }
701
-}
702
-
703
-impl std::str::FromStr for BinaryOperator {
704
- type Err = String;
705
-
706
- fn from_str(s: &str) -> Result<Self, Self::Err> {
707
- match s {
708
- "+" => Ok(Self::Plus),
709
- "-" => Ok(Self::Minus),
710
- _ => Err(format!("Invalid BinaryOperator: `{}`", s)),
711
- }
712
- }
713
-}
714
-
715
-#[derive(Serialize, Deserialize, Debug)]
716
-pub struct CallExpression {
717
- #[serde(rename = "optional")]
718
- #[serde(default)]
719
- pub is_optional: bool,
720
-
721
- pub callee: ExpressionLike,
722
-
723
- pub arguments: Vec<ExpressionLike>,
724
-
725
- pub loc: Option<SourceLocation>,
726
- #[serde(default)]
727
- pub range: Option<SourceRange>,
728
-}
729
-
730
-#[derive(Serialize, Deserialize, Debug)]
731
-pub struct ChainExpression {
732
- pub expression: ChainElement,
733
- pub loc: Option<SourceLocation>,
734
- #[serde(default)]
735
- pub range: Option<SourceRange>,
736
-}
737
-
738
-#[derive(Serialize, Deserialize, Debug)]
739
-#[serde(tag = "type")]
740
-pub enum ChainElement {
741
- CallExpression(Box<CallExpression>),
742
- MemberExpression(Box<MemberExpression>),
743
-}
744
-
745
-#[derive(Serialize, Deserialize, Debug)]
746
-pub struct ClassExpression {
747
- // TODO
748
- pub loc: Option<SourceLocation>,
749
- #[serde(default)]
750
- pub range: Option<SourceRange>,
751
-}
752
-
753
-#[derive(Serialize, Deserialize, Debug)]
754
-pub struct ConditionalExpression {
755
- pub test: ExpressionLike,
756
- pub alternate: ExpressionLike,
757
- pub consequent: ExpressionLike,
758
- pub loc: Option<SourceLocation>,
759
- #[serde(default)]
760
- pub range: Option<SourceRange>,
761
-}
762
-
763
-#[derive(Serialize, Deserialize, Debug)]
764
-pub struct FunctionExpression {
765
- // TODO
766
- pub loc: Option<SourceLocation>,
767
- #[serde(default)]
768
- pub range: Option<SourceRange>,
769
-}
770
-
771
-#[derive(Serialize, Deserialize, Debug)]
772
-pub struct ImportExpression {
773
- // TODO
774
- pub loc: Option<SourceLocation>,
775
- #[serde(default)]
776
- pub range: Option<SourceRange>,
777
-}
778
-
779
-#[derive(Serialize, Deserialize, Debug)]
780
-pub struct Literal {
781
- pub value: LiteralValue,
782
-
783
- #[serde(default)]
784
- pub raw: Option<String>,
785
-
786
- pub loc: Option<SourceLocation>,
787
-
788
- #[serde(default)]
789
- pub range: Option<SourceRange>,
790
-}
791
-
792
-#[derive(Serialize, Deserialize, Debug)]
793
-#[serde(untagged)]
794
-pub enum LiteralValue {
795
- BigInt(String),
796
- Boolean(bool),
797
- Null,
798
- Number(Number),
799
- RegExp(RegExp),
800
- String(String),
801
-}
802
-
803
-#[derive(Serialize, Deserialize, Debug)]
804
-pub struct Number(u64);
805
-
806
-impl From<u64> for Number {
807
- fn from(value: u64) -> Self {
808
- Number(value)
809
- }
810
-}
811
-
812
-impl From<f64> for Number {
813
- fn from(value: f64) -> Self {
814
- Number(value.to_bits())
815
- }
816
-}
817
-
818
-impl From<Number> for f64 {
819
- fn from(value: Number) -> Self {
820
- f64::from_bits(value.0)
821
- }
822
-}
823
-
824
-#[derive(Serialize, Deserialize, Debug)]
825
-pub struct RegExp {
826
- pub raw: Option<String>,
827
- pub regex: Option<RegExpValue>,
828
-}
829
-
830
-#[derive(Serialize, Deserialize, Debug)]
831
-pub struct RegExpValue {
832
- pub pattern: String,
833
- pub flags: String,
834
-}
835
-
836
-#[derive(Serialize, Deserialize, Debug)]
837
-pub struct LogicalExpression {
838
- pub operator: LogicalOperator,
839
- pub left: ExpressionLike,
840
- pub right: ExpressionLike,
841
- pub loc: Option<SourceLocation>,
842
- #[serde(default)]
843
- pub range: Option<SourceRange>,
844
-}
845
-
846
-#[derive(Serialize, Deserialize, Debug)]
847
-pub enum LogicalOperator {
848
- /// ||
849
- #[serde(rename = "||")]
850
- PipePipe,
851
- /// &&
852
- #[serde(rename = "&&")]
853
- AmpersandAmpersand,
854
- /// ??
855
- #[serde(rename = "??")]
856
- QuestionQuestion,
857
-}
858
-
859
-#[derive(Serialize, Deserialize, Debug)]
860
-pub struct MetaProperty {
861
- // TODO
862
- pub loc: Option<SourceLocation>,
863
- #[serde(default)]
864
- pub range: Option<SourceRange>,
865
-}
866
-
867
-#[derive(Serialize, Deserialize, Debug)]
868
-pub struct NewExpression {
869
- pub callee: ExpressionLike,
870
- pub arguments: Vec<ExpressionLike>,
871
- pub loc: Option<SourceLocation>,
872
- #[serde(default)]
873
- pub range: Option<SourceRange>,
874
-}
875
-
876
-#[derive(Serialize, Deserialize, Debug)]
877
-pub struct ObjectExpression {
878
- pub properties: Vec<ExpressionLike>,
879
- pub loc: Option<SourceLocation>,
880
- #[serde(default)]
881
- pub range: Option<SourceRange>,
882
-}
883
-
884
-#[derive(Serialize, Deserialize, Debug)]
885
-pub struct SequenceExpression {
886
- pub expressions: Vec<ExpressionLike>,
887
- pub loc: Option<SourceLocation>,
888
- #[serde(default)]
889
- pub range: Option<SourceRange>,
890
-}
891
-
892
-#[derive(Serialize, Deserialize, Debug)]
893
-pub struct TaggedTemplateExpression {
894
- pub tag: ExpressionLike,
895
- pub quasi: TemplateLiteral,
896
- pub loc: Option<SourceLocation>,
897
- #[serde(default)]
898
- pub range: Option<SourceRange>,
899
-}
900
-
901
-#[derive(Serialize, Deserialize, Debug)]
902
-pub struct TemplateLiteral {
903
- pub quasis: Vec<TemplateElement>,
904
- pub expressions: Vec<ExpressionLike>,
905
- pub loc: Option<SourceLocation>,
906
- #[serde(default)]
907
- pub range: Option<SourceRange>,
908
-}
909
-
910
-#[derive(Serialize, Deserialize, Debug)]
911
-pub struct TemplateElement {
912
- #[serde(rename = "tail")]
913
- #[serde(default)]
914
- pub is_tail: bool,
915
-
916
- // TODO: add value: {cooked, raw} wrapper object
917
- pub cooked: Option<String>,
918
-
919
- pub raw: String,
920
-
921
- pub loc: Option<SourceLocation>,
922
- #[serde(default)]
923
- pub range: Option<SourceRange>,
924
-}
925
-
926
-#[derive(Serialize, Deserialize, Debug)]
927
-pub struct ThisExpression {
928
- // TODO
929
- pub loc: Option<SourceLocation>,
930
- #[serde(default)]
931
- pub range: Option<SourceRange>,
932
-}
933
-
934
-#[derive(Serialize, Deserialize, Debug)]
935
-pub struct UnaryExpression {
936
- pub operator: UnaryOperator,
937
-
938
- #[serde(rename = "prefix")]
939
- #[serde(default)]
940
- pub is_prefix: bool,
941
-
942
- pub argument: ExpressionLike,
943
-
944
- pub loc: Option<SourceLocation>,
945
- #[serde(default)]
946
- pub range: Option<SourceRange>,
947
-}
948
-
949
-#[derive(Serialize, Deserialize, Debug)]
950
-pub enum UnaryOperator {
951
- /// -
952
- #[serde(rename = "+")]
953
- Minus,
954
- /// +
955
- #[serde(rename = "+")]
956
- Plus,
957
- /// !
958
- #[serde(rename = "!")]
959
- Exclamation,
960
- /// ~
961
- #[serde(rename = "~")]
962
- Tilde,
963
- /// typeof
964
- #[serde(rename = "typeof")]
965
- Typeof,
966
- /// void
967
- #[serde(rename = "void")]
968
- Void,
969
- /// delete
970
- #[serde(rename = "delete")]
971
- Delete,
972
-}
973
-
974
-#[derive(Serialize, Deserialize, Debug)]
975
-pub struct UpdateExpression {
976
- pub operator: UpdateOperator,
977
-
978
- pub argument: ExpressionLike,
979
-
980
- #[serde(rename = "prefix")]
981
- #[serde(default)]
982
- pub is_prefix: bool,
983
-
984
- pub loc: Option<SourceLocation>,
985
- #[serde(default)]
986
- pub range: Option<SourceRange>,
987
-}
988
-
989
-#[derive(Serialize, Deserialize, Debug)]
990
-pub enum UpdateOperator {
991
- /// ++
992
- #[serde(rename = "++")]
993
- PlusPlus,
994
- /// --
995
- #[serde(rename = "--")]
996
- MinusMinus,
997
-}
998
-
999
-#[derive(Serialize, Deserialize, Debug)]
1000
-pub struct YieldExpression {
1001
- pub argument: Option<ExpressionLike>,
1002
-
1003
- #[serde(rename = "delegate")]
1004
- #[serde(default)]
1005
- pub is_delegate: bool,
1006
-
1007
- pub loc: Option<SourceLocation>,
1008
- #[serde(default)]
1009
- pub range: Option<SourceRange>,
1010
-}
1011
-
1012
-// Pattern etc
1013
-
1014
-#[derive(Serialize, Deserialize, Debug)]
1015
-#[serde(tag = "type")]
1016
-pub enum Pattern {
1017
- ArrayPattern(Box<ArrayPattern>),
1018
- AssignmentPattern(Box<AssignmentPattern>),
1019
- Identifier(Box<Identifier>),
1020
- MemberExpression(Box<MemberExpression>),
1021
- ObjectPattern(Box<ObjectPattern>),
1022
- RestElement(Box<RestElement>),
1023
-}
1024
-
1025
-#[derive(Serialize, Deserialize, Debug)]
1026
-pub struct ArrayPattern {
1027
- pub elements: Vec<Pattern>,
1028
-
1029
- pub loc: Option<SourceLocation>,
1030
- #[serde(default)]
1031
- pub range: Option<SourceRange>,
1032
-}
1033
-
1034
-#[derive(Serialize, Deserialize, Debug)]
1035
-pub struct AssignmentPattern {
1036
- pub left: Pattern,
1037
- pub right: ExpressionLike,
1038
- pub loc: Option<SourceLocation>,
1039
- #[serde(default)]
1040
- pub range: Option<SourceRange>,
1041
-}
1042
-
1043
-#[derive(Serialize, Deserialize, Debug)]
1044
-pub struct Identifier {
1045
- pub name: String,
1046
-
1047
- #[serde(default)]
1048
- pub binding: Option<Binding>,
1049
-
1050
- pub loc: Option<SourceLocation>,
1051
-
1052
- #[serde(default)]
1053
- pub range: Option<SourceRange>,
1054
-}
1055
-
1056
-#[derive(Serialize, Deserialize, Debug)]
1057
-#[serde(tag = "type")]
1058
-pub enum Binding {
1059
- Local(BindingId),
1060
- Module(BindingId),
1061
- Global,
1062
-}
1063
-
1064
-#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, Copy)]
1065
-#[serde(transparent)]
1066
-pub struct BindingId(NonZeroU32);
1067
-
1068
-impl BindingId {
1069
- pub fn new(id: NonZeroU32) -> Self {
1070
- Self(id)
1071
- }
1072
-}
1073
-
1074
-impl From<BindingId> for u32 {
1075
- fn from(value: BindingId) -> Self {
1076
- value.0.into()
1077
- }
1078
-}
1079
-
1080
-#[derive(Serialize, Deserialize, Debug)]
1081
-pub struct MemberExpression {
1082
- pub object: ExpressionLike,
1083
-
1084
- pub property: ExpressionLike, // ExpressionOrPrivateIdentifier
1085
-
1086
- #[serde(rename = "computed")]
1087
- #[serde(default)]
1088
- pub is_computed: bool,
1089
-
1090
- #[serde(rename = "optional")]
1091
- #[serde(default)]
1092
- pub is_optional: bool,
1093
-
1094
- pub loc: Option<SourceLocation>,
1095
- #[serde(default)]
1096
- pub range: Option<SourceRange>,
1097
-}
1098
-
1099
-#[derive(Serialize, Deserialize, Debug)]
1100
-pub struct Super {
1101
- pub loc: Option<SourceLocation>,
1102
- #[serde(default)]
1103
- pub range: Option<SourceRange>,
1104
-}
1105
-
1106
-#[derive(Serialize, Deserialize, Debug)]
1107
-pub struct PrivateIdentifier {
1108
- pub name: String,
1109
- pub loc: Option<SourceLocation>,
1110
- #[serde(default)]
1111
- pub range: Option<SourceRange>,
1112
-}
1113
-
1114
-#[derive(Serialize, Deserialize, Debug)]
1115
-pub struct ObjectPattern {
1116
- pub properties: Vec<ExpressionLike>,
1117
- pub loc: Option<SourceLocation>,
1118
- #[serde(default)]
1119
- pub range: Option<SourceRange>,
1120
-}
1121
-
1122
-#[derive(Serialize, Deserialize, Debug)]
1123
-pub struct Property {
1124
- pub key: ExpressionLike,
1125
-
1126
- pub value: PropertyValue,
1127
-
1128
- pub kind: PropertyKind,
1129
-
1130
- #[serde(rename = "method")]
1131
- #[serde(default)]
1132
- pub is_method: bool,
1133
-
1134
- #[serde(rename = "shorthand")]
1135
- #[serde(default)]
1136
- pub is_shorthand: bool,
1137
-
1138
- #[serde(rename = "computed")]
1139
- #[serde(default)]
1140
- pub is_computed: bool,
1141
-
1142
- pub loc: Option<SourceLocation>,
1143
- #[serde(default)]
1144
- pub range: Option<SourceRange>,
1145
-}
1146
-
1147
-#[derive(Serialize, Deserialize, Debug)]
1148
-#[serde(untagged)]
1149
-pub enum PropertyValue {
1150
- Expression(Box<ExpressionLike>),
1151
- Pattern(Box<Pattern>),
1152
-}
1153
-
1154
-#[derive(Serialize, Deserialize, Debug)]
1155
-pub enum PropertyKind {
1156
- #[serde(rename = "init")]
1157
- Init,
1158
- #[serde(rename = "get")]
1159
- Get,
1160
- #[serde(rename = "set")]
1161
- Set,
1162
-}
1163
-
1164
-impl Default for PropertyKind {
1165
- fn default() -> Self {
1166
- Self::Init
1167
- }
1168
-}
1169
-
1170
-#[derive(Serialize, Deserialize, Debug)]
1171
-pub struct RestElement {
1172
- pub argument: Pattern,
1173
- pub loc: Option<SourceLocation>,
1174
- #[serde(default)]
1175
- pub range: Option<SourceRange>,
1176
-}
1177
-
1178
-#[derive(Serialize, Deserialize, Debug)]
1179
-pub struct SpreadElement {
1180
- pub argument: ExpressionLike,
1181
- pub loc: Option<SourceLocation>,
1182
- #[serde(default)]
1183
- pub range: Option<SourceRange>,
1184
-}
1185
-
1186
-#[derive(Serialize, Deserialize, Debug)]
1187
-pub struct JSXElement {
1188
- #[serde(rename = "openingElement")]
1189
- pub opening_element: ExpressionLike,
1190
-
1191
- pub children: Vec<ExpressionLike>,
1192
-
1193
- #[serde(rename = "closingElement")]
1194
- pub closing_element: Option<ExpressionLike>,
1195
-
1196
- pub loc: Option<SourceLocation>,
1197
-
1198
- #[serde(default)]
1199
- pub range: Option<SourceRange>,
1200
-}
1201
-
1202
-#[derive(Serialize, Deserialize, Debug)]
1203
-pub struct JSXOpeningElement {
1204
- pub name: ExpressionLike,
1205
-
1206
- pub attributes: Vec<JSXAttribute>,
1207
-
1208
- #[serde(rename = "selfClosing")]
1209
- #[serde(default)]
1210
- pub self_closing: bool,
1211
-
1212
- pub loc: Option<SourceLocation>,
1213
-
1214
- #[serde(default)]
1215
- pub range: Option<SourceRange>,
1216
-}
1217
-
1218
-#[derive(Serialize, Deserialize, Debug)]
1219
-pub struct JSXClosingElement {
1220
- pub name: ExpressionLike,
1221
-
1222
- pub loc: Option<SourceLocation>,
1223
-
1224
- #[serde(default)]
1225
- pub range: Option<SourceRange>,
1226
-}
1227
-
1228
-#[derive(Serialize, Deserialize, Debug)]
1229
-pub struct JSXMemberExpression {
1230
- pub object: ExpressionLike,
1231
-
1232
- pub property: ExpressionLike,
1233
-
1234
- pub loc: Option<SourceLocation>,
1235
-
1236
- #[serde(default)]
1237
- pub range: Option<SourceRange>,
1238
-}
1239
-
1240
-#[derive(Serialize, Deserialize, Debug)]
1241
-pub struct JSXIdentifier {
1242
- pub name: String,
1243
-
1244
- pub loc: Option<SourceLocation>,
1245
-
1246
- #[serde(default)]
1247
- pub range: Option<SourceRange>,
1248
-}
1249
-
1250
-#[derive(Serialize, Deserialize, Debug)]
1251
-pub struct JSXNamedspacedName {
1252
- pub namespace: ExpressionLike,
1253
-
1254
- pub name: ExpressionLike,
1255
-
1256
- pub loc: Option<SourceLocation>,
1257
-
1258
- #[serde(default)]
1259
- pub range: Option<SourceRange>,
1260
-}
1261
-
1262
-#[derive(Serialize, Deserialize, Debug)]
1263
-pub struct JSXAttribute {
1264
- pub name: ExpressionLike,
1265
-
1266
- pub value: ExpressionLike,
1267
-
1268
- pub loc: Option<SourceLocation>,
1269
-
1270
- #[serde(default)]
1271
- pub range: Option<SourceRange>,
1272
-}
1273
-
1274
-#[derive(Serialize, Deserialize, Debug)]
1275
-pub struct JSXExpressionContainer {
1276
- expression: ExpressionLike,
1277
-
1278
- pub loc: Option<SourceLocation>,
1279
-
1280
- #[serde(default)]
1281
- pub range: Option<SourceRange>,
1282
-}
1283
-
1284
-#[derive(Serialize, Deserialize, Debug)]
1285
-pub struct JSXText {
1286
- value: String,
1287
- raw: String,
1288
-
1289
- pub loc: Option<SourceLocation>,
1290
-
1291
- #[serde(default)]
1292
- pub range: Option<SourceRange>,
1293
-}
1294
-
1295
-#[cfg(test)]
1296
-mod tests {
1297
- use super::*;
1298
- use insta::{assert_snapshot, glob};
1299
- use serde_json;
1300
-
1301
- #[test]
1302
- fn for_statement() {
1303
- let source = include_str!("for-statement.json");
1304
- let ast: Program = serde_json::from_str(&source).unwrap();
1305
- println!("deserialized:\n{:#?}", ast);
1306
- let serialized = serde_json::to_string_pretty(&ast).unwrap();
1307
- println!("serialized:\n{}", serialized);
1308
- }
1309
-
1310
- #[test]
1311
- fn simple() {
1312
- let source = include_str!("simple.json");
1313
- let ast: Program = serde_json::from_str(&source).unwrap();
1314
- println!("deserialized:\n{:#?}", ast);
1315
- let serialized = serde_json::to_string_pretty(&ast).unwrap();
1316
- println!("serialized:\n{}", serialized);
1317
- }
1318
-
1319
- /// TODO: enable once this deserializes
1320
- fn _kitchen_sink() {
1321
- let source = include_str!("kitchen-sink.json");
1322
- let ast: Program = match serde_json::from_str(&source) {
1323
- Ok(ast) => ast,
1324
- Err(err) => panic!("{:#?}", err),
1325
- };
1326
- println!("deserialized:\n{:#?}", ast);
1327
- let serialized = serde_json::to_string_pretty(&ast).unwrap();
1328
- println!("serialized:\n{}", serialized);
1329
- }
1330
-
1331
- #[test]
1332
- fn import() {
1333
- let source = include_str!("import.json");
1334
- let ast: Program = serde_json::from_str(&source).unwrap();
1335
- println!("deserialized:\n{:#?}", ast);
1336
- let serialized = serde_json::to_string_pretty(&ast).unwrap();
1337
- println!("serialized:\n{}", serialized);
1338
- }
1339
-
1340
- #[test]
1341
- fn test() {
1342
- let source = include_str!("test.json");
1343
- let ast: Program = serde_json::from_str(&source).unwrap();
1344
- println!("deserialized:\n{:#?}", ast);
1345
- let serialized = serde_json::to_string_pretty(&ast).unwrap();
1346
- println!("serialized:\n{}", serialized);
1347
- }
1348
-
1349
- #[test]
1350
- fn fixtures() {
1351
- glob!("fixtures/**.json", |path| {
1352
- let input = std::fs::read_to_string(path).unwrap();
1353
- let ast: Program = serde_json::from_str(&input).unwrap();
1354
- let serialized = serde_json::to_string_pretty(&ast).unwrap();
1355
- assert_snapshot!(format!("Input:\n{input}\n\nOutput:\n{serialized}"));
1356
- });
1357
- }
1358
-}
compiler/forget/crates/forget_estree/src/visit.rs
+2
-2
@@ -145,7 +145,7 @@ pub trait Visitor_DEPRECATED<'ast> {
145
self.visit_variable_declarator(declarator)
146
}
147
}
148
- Declaration::TSTypeAliasDeclaration(declaration) => {
148
+ Declaration::TSTypeAliasDeclaration(_declaration) => {
149
todo!("visit TSTypeAliasDeclaration")
150
}
151
}
@@ -268,7 +268,7 @@ pub trait Visitor_DEPRECATED<'ast> {
268
self.visit_expression(&stmt.object);
269
self.visit_statement(&stmt.body);
270
}
271
- Statement::TSTypeAliasDeclaration(stmt) => {
271
+ Statement::TSTypeAliasDeclaration(_stmt) => {
272
todo!("visit TSTypeAliasDeclaration")
273
}
274
}
compiler/forget/crates/forget_estree_codegen/src/codegen.rs
+4
-21
@@ -88,10 +88,11 @@ impl Grammar {
88
.map(|(name, operator)| operator.codegen(name))
89
.collect();
90
91
- // println!("{}", quote! {#(#node_visitors)*});
92
- // println!("{}", quote! {#(#enum_visitors)*});
93
-
91
quote! {
92
+ #![allow(dead_code)]
93
+ #![allow(unused_variables)]
94
+ #![allow(non_snake_case)]
95
+
96
use std::num::NonZeroU32;
97
use serde::ser::{Serializer, SerializeMap};
98
use serde::{Serialize,Deserialize};
@@ -406,9 +407,7 @@ impl Node {
407
if let Some(convert_with) = &field.hermes_convert_with {
408
let convert_with = format_ident!("{}", convert_with);
409
return quote! {
409
- // println!("read {}.{}", #name_str, #name);
410
let #field_name = #convert_with(cx, unsafe { hermes::parser::#helper(node) } );
411
- // println!("ok");
411
}
412
}
413
match type_kind {
@@ -416,30 +415,22 @@ impl Node {
415
match type_name_str.as_ref() {
416
"bool" => {
417
quote! {
419
- // println!("read {}.{}", #name_str, #name);
418
let #field_name = unsafe { hermes::parser::#helper(node) };
421
- // println!("ok");
419
}
420
}
421
"Number" => {
422
quote! {
426
- // println!("read {}.{}", #name_str, #name);
423
let #field_name = convert_number(unsafe { hermes::parser::#helper(node) });
428
- // println!("ok");
424
}
425
}
426
"String" => {
427
quote! {
433
- // println!("read {}.{}", #name_str, #name);
428
let #field_name = convert_string(cx, unsafe { hermes::parser::#helper(node) });
435
- // println!("ok");
429
}
430
}
431
_ => {
432
quote! {
440
- // println!("read {}.{}", #name_str, #name);
433
let #field_name = #type_name::convert(cx, unsafe { hermes::parser::#helper(node) });
442
- // println!("ok");
434
}
435
}
436
}
@@ -448,32 +439,24 @@ impl Node {
439
match type_name_str.as_ref() {
440
"String" => {
441
quote! {
451
- // println!("read {}.{}", #name_str, #name);
442
let #field_name = convert_option_string(cx, unsafe { hermes::parser::#helper(node) });
453
- // println!("ok");
443
}
444
}
445
_ => {
446
quote! {
458
- // println!("read {}.{}", #name_str, #name);
447
let #field_name = convert_option(unsafe { hermes::parser::#helper(node) }, |node| #type_name::convert(cx, node));
460
- // println!("ok");
448
}
449
}
450
}
451
}
452
TypeKind::Vec => {
453
quote! {
467
- // println!("read {}.{}", #name_str, #name);
454
let #field_name = convert_vec(unsafe { hermes::parser::#helper(node) }, |node| #type_name::convert(cx, node));
469
- // println!("ok");
455
}
456
}
457
TypeKind::VecOfOption => {
458
quote! {
474
- // println!("read {}.{}", #name_str, #name);
459
let #field_name = convert_vec_of_option(unsafe { hermes::parser::#helper(node) }, |node| #type_name::convert(cx, node));
476
- // println!("ok");
460
}
461
}
462
}
compiler/forget/crates/forget_fixtures/tests/fixtures_test.rs
-5
@@ -22,7 +22,6 @@ fn fixtures() {
22
let mut output = String::new();
23
24
let analysis = analyze(&ast);
25
- // println!("{:#?}", analysis.debug());
25
let environment = Environment::new(
26
Features {
27
validate_frozen_lambdas: true,
@@ -38,10 +37,6 @@ fn fixtures() {
37
}
38
match build(&environment, &fun.function) {
39
Ok(mut fun) => {
41
- // println!("{fun:#?}");
42
- // let mut out = String::new();
43
- // fun.print(&fun.body, &mut out).unwrap();
44
- // println!("{out}");
40
println!("ok build");
41
enter_ssa(&environment, &mut fun).unwrap();
42
println!("ok enter_ssa");
compiler/forget/crates/forget_hir/src/environment.rs
+2
-3
@@ -1,10 +1,9 @@
1
use std::cell::{Cell, RefCell};
2
use std::collections::HashMap;
3
-use std::process::id;
3
use std::rc::Rc;
4
6
-use forget_estree::{BindingId, ESTreeNode};
7
-use forget_semantic_analysis::{AstNode, DeclarationId, ScopeManager, ScopeView};
5
+use forget_estree::ESTreeNode;
6
+use forget_semantic_analysis::{DeclarationId, ScopeManager, ScopeView};
7
8
use crate::{
9
BlockId, Features, Identifier, IdentifierData, IdentifierId, Registry, Type, TypeVarId,
compiler/forget/crates/forget_semantic_analysis/src/analyzer.rs
+2
-3
@@ -1,9 +1,8 @@
1
use forget_diagnostics::Diagnostic;
2
use forget_estree::{
3
AssignmentOperator, AssignmentPropertyOrRestElement, AssignmentTarget, Expression,
4
- ExpressionOrSuper, ForInInit, ForInit, Function, FunctionBody, Identifier, IntoFunction,
5
- JSXElementName, Pattern, Program, SourceRange, SourceType, Statement, VariableDeclarationKind,
6
- Visitor,
4
+ ExpressionOrSuper, ForInInit, ForInit, FunctionBody, Identifier, IntoFunction, JSXElementName,
5
+ Pattern, Program, SourceRange, SourceType, Statement, VariableDeclarationKind, Visitor,
6
};
7
8
use crate::{AstNode, DeclarationKind, LabelKind, ReferenceKind, ScopeId, ScopeKind, ScopeManager};
compiler/forget/crates/forget_semantic_analysis/src/scope_manager.rs
+2
-2
@@ -180,11 +180,11 @@ impl ScopeManager {
180
}
181
}
182
183
- pub fn lookup_break(&self, scope: ScopeId) -> Option<&Label> {
183
+ pub fn lookup_break(&self, _scope: ScopeId) -> Option<&Label> {
184
todo!()
185
}
186
187
- pub fn lookup_continue(&self, scope: ScopeId) -> Option<&Label> {
187
+ pub fn lookup_continue(&self, _scope: ScopeId) -> Option<&Label> {
188
todo!()
189
}
190
compiler/forget/crates/forget_semantic_analysis/src/scope_view.rs
+1
@@ -142,6 +142,7 @@ impl<'m> std::fmt::Debug for ScopeView<'m> {
142
143
#[derive(Clone, Copy)]
144
pub struct LabelView<'m> {
145
+ #[allow(dead_code)]
146
pub(crate) manager: &'m ScopeManager,
147
pub(crate) label: &'m Label,
148
}
compiler/forget/crates/forget_ssa/src/enter.rs
+3
-3
@@ -184,9 +184,9 @@ impl<'e, 'f> Builder<'e, 'f> {
184
// Else we have to look at predecessor blocks: bail if no predecessors
185
let block = self.blocks.block(block_id);
186
if block.predecessors.is_empty() {
187
- println!("Unable to find previous id for {old_identifier:?}");
188
- self.unknown.insert(old_identifier.id);
189
- return old_identifier.clone();
187
+ panic!("Unable to find previous id for {old_identifier:?}");
188
+ // self.unknown.insert(old_identifier.id);
189
+ // return old_identifier.clone();
190
}
191
// If we haven't visited all predecessors, synthesize a new identifier
192
// and save it as an incomplete phi