0d21e51cbfde731af94da822479f180a2baaf207.svn-base
984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _generated = require("../validators/generated");
var _generated2 = require("../builders/generated");
var _default = toStatement;
exports.default = _default;
function toStatement(node, ignore) {
if ((0, _generated.isStatement)(node)) {
return node;
}
let mustHaveId = false;
let newType;
if ((0, _generated.isClass)(node)) {
mustHaveId = true;
newType = "ClassDeclaration";
} else if ((0, _generated.isFunction)(node)) {
mustHaveId = true;
newType = "FunctionDeclaration";
} else if ((0, _generated.isAssignmentExpression)(node)) {
return (0, _generated2.expressionStatement)(node);
}
if (mustHaveId && !node.id) {
newType = false;
}
if (!newType) {
if (ignore) {
return false;
} else {
throw new Error(`cannot turn ${node.type} to a statement`);
}
}
node.type = newType;
return node;
}