MCPcopy
hub / github.com/remy/jsconsole / preProcess

Function preProcess

src/core/lib/run.js:116–242  ·  view source on GitHub ↗
(content)

Source from the content-addressed store, hash-verified

114}
115
116export function preProcess(content) {
117 var wrapped = '(async () => {' + content + '})()';
118 var root = parse(wrapped, { ecmaVersion: 8 });
119 var body = root.program.body[0].expression.callee.body;
120
121 var changes = [];
122 var containsAwait = false;
123 var containsReturn = false;
124
125 const visitors = {
126 ClassDeclaration(node) {
127 if (node.parent === body)
128 changes.push({
129 text: node.id.name + '=',
130 start: node.start,
131 end: node.start,
132 });
133 },
134 FunctionDeclaration(node) {
135 changes.push({
136 text: node.id.name + '=',
137 start: node.start,
138 end: node.start,
139 });
140 return node;
141 },
142 AwaitExpression(node) {
143 containsAwait = true;
144 },
145 ReturnStatement(node) {
146 containsReturn = true;
147 },
148 VariableDeclaration(node) {
149 if (node.kind !== 'var' && node.parent !== body) return;
150 var onlyOneDeclaration = node.declarations.length === 1;
151 changes.push({
152 text: onlyOneDeclaration ? 'void' : 'void (',
153 start: node.start,
154 end: node.start + node.kind.length,
155 });
156 for (var declaration of node.declarations) {
157 if (!declaration.init) {
158 changes.push({
159 text: '(',
160 start: declaration.start,
161 end: declaration.start,
162 });
163 changes.push({
164 text: '=undefined)',
165 start: declaration.end,
166 end: declaration.end,
167 });
168 continue;
169 }
170 changes.push({
171 text: '(',
172 start: declaration.start,
173 end: declaration.start,

Callers 2

run.jsFile · 0.90
runFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected