Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function visitArrowFunction(traverse, node, path, state) {
var notInExpression = (path[0].type === Syntax.ExpressionStatement);
// Wrap a function into a grouping operator, if it's not
// in the expression position.
if (notInExpression) {
utils.append('(', state);
}
utils.append('function', state);
renderParams(traverse, node, path, state);
// Skip arrow.
utils.catchupWhiteSpace(node.body.range[0], state);
var renderBody = node.body.type == Syntax.BlockStatement
? renderStatementBody
: renderExpressionBody;
path.unshift(node);
renderBody(traverse, node, path, state);
path.shift();
// Bind the function only if `this` value is used
// inside it or inside any sub-expression.
var containsBindingSyntax =
utils.containsChildMatching(node.body, function(node) {
return node.type === Syntax.ThisExpression
|| (node.type === Syntax.Identifier
&& node.name === "super");
});
utils.append(variable + '=' + iter + '[' + k + '++];', state);
// Iterators case.
utils.append(
'}else{' + k + '=' + iter + '.next();' +
'if(' + k + '.done) break;',
state
);
utils.append(variable + '=' + k + '.value;}', state);
traverse(node.body, path, state);
utils.catchup(node.body.range[1], state);
if (node.body.type !== Syntax.BlockStatement) {
utils.append('}', state);
}
return false;
}
function visitArrowFunction(traverse, node, path, state) {
var notInExpression = (path[0].type === Syntax.ExpressionStatement);
// Wrap a function into a grouping operator, if it's not
// in the expression position.
if (notInExpression) {
utils.append('(', state);
}
utils.append('function', state);
renderParams(traverse, node, path, state);
// Skip arrow.
utils.catchupWhiteSpace(node.body.range[0], state);
var renderBody = node.body.type == Syntax.BlockStatement
? renderStatementBody
: renderExpressionBody;
path.unshift(node);
renderBody(traverse, node, path, state);
path.shift();
// Bind the function only if `this` value is used
// inside it or inside any sub-expression.
var containsBindingSyntax =
utils.containsChildMatching(node.body, function(node) {
return node.type === Syntax.ThisExpression
|| (node.type === Syntax.Identifier
&& node.name === "super");
});
utils.append(iter + '=', state);
process(traverse, node.right, path, state);
// Setup iterator with optimization for arrays.
utils.append(
',' + isArray + '=Array.isArray(' + iter + '),' +
k + '=0,' +
iter + '=' + isArray + '?' + iter + ':' +
iter + '[/*global Symbol*/typeof Symbol=="function"' +
'?Symbol.iterator:"@@iterator"]();;',
state
);
// Jump to the body creating block if needed.
if (node.body.type === Syntax.BlockStatement) {
utils.catchup(node.body.range[0] + 1, state);
} else {
utils.catchup(node.body.range[0], state);
utils.append('{', state);
}
// Arrays case.
utils.append(
'if(' + isArray + '){' +
'if(' + k + '>=' + iter + '.length) break;',
state
);
utils.append(variable + '=' + iter + '[' + k + '++];', state);
// Iterators case.
visitFunctionBodyWithRestParam.test = function(node, path, state) {
return node.type === Syntax.BlockStatement
&& _nodeIsFunctionWithRestParam(path[0]);
};
visitFunctionBodyWithRestParam.test = function(node, path, state) {
return node.type === Syntax.BlockStatement
&& _nodeIsFunctionWithRestParam(path[0]);
};
visitFunctionBodyForStructuredParameter.test = function(node, path, state) {
return node.type === Syntax.BlockStatement && isFunctionNode(path[0]);
};
visitFunctionBodyWithRestParam.test = function(node, path, state) {
return node.type === Syntax.BlockStatement
&& _nodeIsFunctionWithRestParam(path[0]);
};
visitFunctionBodyWithRestParam.test = function(node, path, state) {
return node.type === Syntax.BlockStatement
&& _nodeIsFunctionWithRestParam(path[0]);
};
visitFunctionBodyForStructuredParameter.test = function(node, path, state) {
return node.type === Syntax.BlockStatement && isFunctionNode(path[0]);
};