<commit_before>(function () {

'use strict';

var extend = require('extend');
var escope = require('escope');
var b = require('ast-types').builders;
var jsonpath = require('JSONPath').eval;

module.exports = function (compiler) {

	var run = false;
	var counter = 0;

	// var [a, b] = foo();
	compiler.on('VariableDeclaration', {
		'$.declarations[*].id.type': 'ArrayPattern'
	}, function (node) {
		var replacement = extend({}, node, { declarations: [] });
		node.declarations.forEach(function (declaration) {
			if (declaration.id.type !== 'ArrayPattern') {
				return replacement.declarations.push(declaration);
			} else {
				var temp = '$fsadtmp' + counter++;
				replacement.declarations.push(b.variableDeclarator(
					b.identifier(temp),
					declaration.init
				));
				declaration.id.elements.forEach(function (id, index) {
					replacement.declarations.push(b.variableDeclarator(
						id,
						b.memberExpression(
							b.identifier(temp),
							b.literal(index),
							true
						)
					));
				});
			}
		});
		return replacement;
	});

};

}).call(this);




/*
[a, b] = [b, a];
{ type: 'ExpressionStatement',
	expression:
		{ type: 'AssignmentExpression',
			operator: '=',
			left:
			 { type: 'ArrayPattern',
				 elements:
					[ { type: 'Identifier', name: 'a' },
						{ type: 'Identifier', name: 'b' } ] },
			right:
			 { type: 'ArrayExpression',
				 elements:
					[ { type: 'Identifier', name: 'b' },
						{ type: 'Identifier', name: 'a' } ] } } } ] }
*/
<commit_msg>Fix bug with ignored values in array destructuring<commit_after>(function () {

'use strict';

var extend = require('extend');
var escope = require('escope');
var b = require('ast-types').builders;
var jsonpath = require('JSONPath').eval;

module.exports = function (compiler) {

	var run = false;
	var counter = 0;

	// var [a, b] = foo();
	compiler.on('VariableDeclaration', {
		'$.declarations[*].id.type': 'ArrayPattern'
	}, function (node) {
		var replacement = extend({}, node, { declarations: [] });
		node.declarations.forEach(function (declaration) {
			if (declaration.id.type !== 'ArrayPattern') {
				replacement.declarations.push(declaration);
			} else {
				var temp = '$fsadtmp' + counter++;
				replacement.declarations.push(b.variableDeclarator(
					b.identifier(temp),
					declaration.init
				));
				declaration.id.elements.forEach(function (id, index) {
					if (id === null) return false;
					replacement.declarations.push(b.variableDeclarator(
						id,
						b.memberExpression(
							b.identifier(temp),
							b.literal(index),
							true
						)
					));
				});
			}
		});
		return replacement;
	});

};

}).call(this);




/*
[a, b] = [b, a];
{ type: 'ExpressionStatement',
	expression:
		{ type: 'AssignmentExpression',
			operator: '=',
			left:
			 { type: 'ArrayPattern',
				 elements:
					[ { type: 'Identifier', name: 'a' },
						{ type: 'Identifier', name: 'b' } ] },
			right:
			 { type: 'ArrayExpression',
				 elements:
					[ { type: 'Identifier', name: 'b' },
						{ type: 'Identifier', name: 'a' } ] } } } ] }
*/

{'fraction_non_alphanumeric': 0.18003913894324852, 'fraction_numerical': 0.0006523157208088715, 'mean_word_length': 3.111260053619303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1855530', 'n_tokens_mistral': 1246, 'n_tokens_neox': 995, 'n_words': 209}