Skip to content

Commit 1e8e18b

Browse files
committed
Chore: Code Reordering
1 parent a28a8ac commit 1e8e18b

File tree

4 files changed

+61
-61
lines changed

4 files changed

+61
-61
lines changed

src/tracer/__tests__/tracer_debug.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ function h(f, x) {
112112
// TODO: Check for -Infinity
113113
test('general', () => {
114114
const code = `
115-
1 ? 2: 2;
115+
const x = 1;
116+
const f = x => x + "";
117+
f(2);
116118
`
117119
const program = parse(code, { ecmaVersion: 10, locations: true })!
118120
const steps = getSteps(convert(program), { stepLimit: 200 })

src/tracer/generator.ts

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export function explain(redex: StepperBaseNode): string {
163163
throw new Error('`callee` should be function expression.')
164164
}
165165

166+
// Determine whether the called function is built-in or not and create explanation accordingly
166167
const func: StepperArrowFunctionExpression = node.callee as StepperArrowFunctionExpression
167168
if (func.name && isBuiltinFunction(func.name)) {
168169
return `${func.name} runs`

src/tracer/nodes/Statement/ExpressionStatement.ts

+31-33
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,37 @@ import { StepperExpression, StepperPattern } from '..'
55
import { redex } from '../..'
66

77
export class StepperExpressionStatement implements ExpressionStatement, StepperBaseNode {
8+
type: 'ExpressionStatement'
9+
expression: StepperExpression
10+
leadingComments?: Comment[] | undefined
11+
trailingComments?: Comment[] | undefined
12+
loc?: SourceLocation | null | undefined
13+
range?: [number, number] | undefined
14+
15+
constructor(
16+
expression: StepperExpression,
17+
leadingComments?: Comment[] | undefined,
18+
trailingComments?: Comment[] | undefined,
19+
loc?: SourceLocation | null | undefined,
20+
range?: [number, number] | undefined,
21+
) {
22+
this.type = 'ExpressionStatement'
23+
this.expression = expression;
24+
this.leadingComments = leadingComments;
25+
this.trailingComments = trailingComments;
26+
this.loc = loc;
27+
this.range = range;
28+
}
29+
30+
static create(node: ExpressionStatement) {
31+
return new StepperExpressionStatement(
32+
convert(node.expression) as StepperExpression,
33+
node.leadingComments,
34+
node.trailingComments,
35+
node.loc,
36+
node.range
37+
)
38+
}
839

940
isContractible(): boolean {
1041
return this.expression.isContractible()
@@ -38,39 +69,6 @@ export class StepperExpressionStatement implements ExpressionStatement, StepperB
3869
)
3970
}
4071

41-
type: 'ExpressionStatement'
42-
expression: StepperExpression
43-
leadingComments?: Comment[] | undefined
44-
trailingComments?: Comment[] | undefined
45-
loc?: SourceLocation | null | undefined
46-
range?: [number, number] | undefined
47-
48-
49-
static create(node: ExpressionStatement) {
50-
return new StepperExpressionStatement(
51-
convert(node.expression) as StepperExpression,
52-
node.leadingComments,
53-
node.trailingComments,
54-
node.loc,
55-
node.range
56-
)
57-
}
58-
59-
constructor(
60-
expression: StepperExpression,
61-
leadingComments?: Comment[] | undefined,
62-
trailingComments?: Comment[] | undefined,
63-
loc?: SourceLocation | null | undefined,
64-
range?: [number, number] | undefined,
65-
) {
66-
this.type = 'ExpressionStatement'
67-
this.expression = expression;
68-
this.leadingComments = leadingComments;
69-
this.trailingComments = trailingComments;
70-
this.loc = loc;
71-
this.range = range;
72-
}
73-
7472
substitute(id: StepperPattern, value: StepperExpression): StepperBaseNode {
7573
return new StepperExpressionStatement(
7674
this.expression.substitute(id, value),

src/tracer/nodes/Statement/ReturnStatement.ts

+26-27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@ export class StepperReturnStatement implements ReturnStatement, StepperBaseNode
1111
trailingComments?: Comment[] | undefined
1212
loc?: SourceLocation | null | undefined
1313
range?: [number, number] | undefined
14+
15+
16+
constructor(
17+
argument: StepperExpression | null,
18+
leadingComments?: Comment[] | undefined,
19+
trailingComments?: Comment[] | undefined,
20+
loc?: SourceLocation | null | undefined,
21+
range?: [number, number] | undefined,
22+
) {
23+
this.type = 'ReturnStatement'
24+
this.argument = argument;
25+
this.leadingComments = leadingComments;
26+
this.trailingComments = trailingComments;
27+
this.loc = loc;
28+
this.range = range;
29+
}
30+
31+
static create(node: ReturnStatement) {
32+
return new StepperReturnStatement(
33+
node.argument ? convert(node.argument) as StepperExpression : null,
34+
node.leadingComments,
35+
node.trailingComments,
36+
node.loc,
37+
node.range
38+
)
39+
}
1440

1541
isContractible(): boolean {
1642
return true;
@@ -41,33 +67,6 @@ export class StepperReturnStatement implements ReturnStatement, StepperBaseNode
4167
return this.contract();
4268
}
4369

44-
45-
46-
static create(node: ReturnStatement) {
47-
return new StepperReturnStatement(
48-
node.argument ? convert(node.argument) as StepperExpression : null,
49-
node.leadingComments,
50-
node.trailingComments,
51-
node.loc,
52-
node.range
53-
)
54-
}
55-
56-
constructor(
57-
argument: StepperExpression | null,
58-
leadingComments?: Comment[] | undefined,
59-
trailingComments?: Comment[] | undefined,
60-
loc?: SourceLocation | null | undefined,
61-
range?: [number, number] | undefined,
62-
) {
63-
this.type = 'ReturnStatement'
64-
this.argument = argument;
65-
this.leadingComments = leadingComments;
66-
this.trailingComments = trailingComments;
67-
this.loc = loc;
68-
this.range = range;
69-
}
70-
7170
substitute(id: StepperPattern, value: StepperExpression): StepperBaseNode {
7271
return new StepperReturnStatement(
7372
this.argument ? this.argument.substitute(id, value) as StepperExpression : null,

0 commit comments

Comments
 (0)