Skip to content

Commit 043b567

Browse files
committed
Improve error message
1 parent 6422036 commit 043b567

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

dist/evil-eval.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class Environment<T> {
2929

3030
const evaluate = this.evaluateMap[node.type];
3131
if (!evaluate) {
32-
throw new Error();
32+
throw new Error(`evil-eval: Node type "${node.type}" is not implemented`);
3333
}
3434

3535
return evaluate(env);

src/evaluate/es2015.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function ObjectExpression(env: Environment<ESTree.ObjectExpression>) {
1515
} else if (property.key.type === 'Identifier') {
1616
key = property.key.name;
1717
} else {
18-
throw new Error();
18+
throw new Error(`evil-eval: [ObjectExpression] Unsupported property key type "${property.key.type}"`);
1919
}
2020
} else {
2121
if (property.key.type === 'Identifier') {
@@ -34,109 +34,109 @@ export function ObjectExpression(env: Environment<ESTree.ObjectExpression>) {
3434
} else if (property.kind === 'set') {
3535
Object.defineProperty(obj, key, { set: value });
3636
} else {
37-
throw new Error();
37+
throw new Error(`evil-eval: [ObjectExpression] Unsupported property kind "${property.kind}"`);
3838
}
3939
}
4040

4141
return obj;
4242
}
4343

4444
export function ForOfStatement(env: Environment<ESTree.ForOfStatement>) {
45-
throw new Error(`"${env.node.type}" not implemented`);
45+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
4646
}
4747

4848
export function Super(env: Environment<ESTree.Super>) {
49-
throw new Error(`"${env.node.type}" not implemented`);
49+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
5050
}
5151

5252
export function SpreadElement(env: Environment<ESTree.SpreadElement>) {
53-
throw new Error(`"${env.node.type}" not implemented`);
53+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
5454
}
5555

5656
export function ArrowFunctionExpression(env: Environment<ESTree.ArrowFunctionExpression>) {
57-
throw new Error(`"${env.node.type}" not implemented`);
57+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
5858
}
5959

6060
export function YieldExpression(env: Environment<ESTree.YieldExpression>) {
61-
throw new Error(`"${env.node.type}" not implemented`);
61+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
6262
}
6363

6464
export function TemplateLiteral(env: Environment<ESTree.TemplateLiteral>) {
65-
throw new Error(`"${env.node.type}" not implemented`);
65+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
6666
}
6767

6868
export function TaggedTemplateExpression(env: Environment<ESTree.TaggedTemplateExpression>) {
69-
throw new Error(`"${env.node.type}" not implemented`);
69+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
7070
}
7171

7272
export function TemplateElement(env: Environment<ESTree.TemplateElement>) {
73-
throw new Error(`"${env.node.type}" not implemented`);
73+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
7474
}
7575

7676
export function ObjectPattern(env: Environment<ESTree.ObjectPattern>) {
77-
throw new Error(`"${env.node.type}" not implemented`);
77+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
7878
}
7979

8080
export function ArrayPattern(env: Environment<ESTree.ArrayPattern>) {
81-
throw new Error(`"${env.node.type}" not implemented`);
81+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
8282
}
8383

8484
export function RestElement(env: Environment<ESTree.RestElement>) {
85-
throw new Error(`"${env.node.type}" not implemented`);
85+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
8686
}
8787

8888
export function AssignmentPattern(env: Environment<ESTree.AssignmentPattern>) {
89-
throw new Error(`"${env.node.type}" not implemented`);
89+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
9090
}
9191

9292
export function ClassBody(env: Environment<ESTree.ClassBody>) {
93-
throw new Error(`"${env.node.type}" not implemented`);
93+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
9494
}
9595

9696
export function MethodDefinition(env: Environment<ESTree.MethodDefinition>) {
97-
throw new Error(`"${env.node.type}" not implemented`);
97+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
9898
}
9999

100100
export function ClassDeclaration(env: Environment<ESTree.ClassDeclaration>) {
101-
throw new Error(`"${env.node.type}" not implemented`);
101+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
102102
}
103103

104104
export function ClassExpression(env: Environment<ESTree.ClassExpression>) {
105-
throw new Error(`"${env.node.type}" not implemented`);
105+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
106106
}
107107

108108
export function MetaProperty(env: Environment<ESTree.MetaProperty>) {
109-
throw new Error(`"${env.node.type}" not implemented`);
109+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
110110
}
111111

112112
export function ImportDeclaration(env: Environment<ESTree.ImportDeclaration>) {
113-
throw new Error(`"${env.node.type}" not implemented`);
113+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
114114
}
115115

116116
export function ImportSpecifier(env: Environment<ESTree.ImportSpecifier>) {
117-
throw new Error(`"${env.node.type}" not implemented`);
117+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
118118
}
119119

120120
export function ImportDefaultSpecifier(env: Environment<ESTree.ImportDefaultSpecifier>) {
121-
throw new Error(`"${env.node.type}" not implemented`);
121+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
122122
}
123123

124124
export function ImportNamespaceSpecifier(env: Environment<ESTree.ImportNamespaceSpecifier>) {
125-
throw new Error(`"${env.node.type}" not implemented`);
125+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
126126
}
127127

128128
export function ExportNamedDeclaration(env: Environment<ESTree.ExportNamedDeclaration>) {
129-
throw new Error(`"${env.node.type}" not implemented`);
129+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
130130
}
131131

132132
export function ExportSpecifier(env: Environment<ESTree.ExportSpecifier>) {
133-
throw new Error(`"${env.node.type}" not implemented`);
133+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
134134
}
135135

136136
export function ExportDefaultDeclaration(env: Environment<ESTree.ExportDefaultDeclaration>) {
137-
throw new Error(`"${env.node.type}" not implemented`);
137+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
138138
}
139139

140140
export function ExportAllDeclaration(env: Environment<ESTree.ExportAllDeclaration>) {
141-
throw new Error(`"${env.node.type}" not implemented`);
141+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
142142
}

src/evaluate/es2017.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import Signal from '../signal';
55
import Environment from '../environment';
66

77
export function AwaitExpression(env: Environment<ESTree.AwaitExpression>) {
8-
throw new Error('Not implemented');
8+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
99
}

src/evaluate/es5.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function DebuggerStatement(env: Environment<ESTree.DebuggerStatement>) {
6565
}
6666

6767
export function WithStatement(env: Environment<ESTree.WithStatement>) {
68-
throw new Error(`"${env.node.type}" not implemented`);
68+
throw new Error(`evil-eval: "${env.node.type}" not implemented`);
6969
}
7070

7171
export function ReturnStatement(env: Environment<ESTree.ReturnStatement>) {
@@ -234,7 +234,7 @@ export function ForInStatement(env: Environment<ESTree.ForInStatement>) {
234234
value = scope.declare(keyName, null, left.kind);
235235
isConstDeclaration = left.kind === 'const';
236236
} else {
237-
throw new Error();
237+
throw new Error(`evil-eval: [ForInStatement] Unsupported left type "${left.type}"`);
238238
}
239239

240240
for (const key in env.evaluate(right)) {
@@ -271,7 +271,7 @@ export function VariableDeclaration(env: Environment<ESTree.VariableDeclaration>
271271
}
272272

273273
export function VariableDeclarator(env: Environment<ESTree.VariableDeclarator>) {
274-
throw new Error();
274+
throw new Error(`evil-eval: [VariableDeclarator] Should not happen`);
275275
}
276276

277277
export function ThisExpression(env: Environment<ESTree.ThisExpression>) {
@@ -293,7 +293,7 @@ export function ObjectExpression(env: Environment<ESTree.ObjectExpression>) {
293293
} else if (property.key.type === 'Identifier') {
294294
key = property.key.name;
295295
} else {
296-
throw new Error();
296+
throw new Error(`evil-eval: [ObjectExpression] Unsupported property key type "${property.key.type}"`);
297297
}
298298
obj[key] = env.evaluate(property.value);
299299
}
@@ -302,7 +302,7 @@ export function ObjectExpression(env: Environment<ESTree.ObjectExpression>) {
302302
}
303303

304304
export function Property(env: Environment<ESTree.Property>) {
305-
throw new Error();
305+
throw new Error(`evil-eval: [Property] Should not happen`);
306306
}
307307

308308
export function FunctionExpression(env: Environment<ESTree.FunctionExpression>) {
@@ -342,11 +342,11 @@ const UnaryExpressionOperatorEvaluateMap = {
342342
try {
343343
const value = env.scope.get(env.node.argument.name);
344344
return value ? typeof value.v : 'undefined';
345-
} catch (e) {
346-
if (e.message === `${env.node.argument.name} is not defined`) {
345+
} catch (err) {
346+
if (err.message === `${env.node.argument.name} is not defined`) {
347347
return 'undefined';
348348
} else {
349-
throw e;
349+
throw err;
350350
}
351351
}
352352
} else {

src/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class Scope {
4242
return this.constDeclare(name, value);
4343

4444
} else {
45-
throw new Error();
45+
throw new Error('evil-eval: Invalid Variable Declaration Kind');
4646
}
4747
}
4848

src/tool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ export function getIdentifierOrMemberExpressionValue(node: ESTree.Pattern | ESTr
2020
return createMemberValue(obj, name);
2121

2222
} else {
23-
throw new Error();
23+
throw new Error(`evil-eval: Not support to get value of node type "${node.type}"`);
2424
}
2525
}

0 commit comments

Comments
 (0)