<commit_before>import { relative } from 'path';
import { Promise } from 'sander';
import { parse } from 'acorn';
import MagicString from 'magic-string';
import Statement from './Statement';
import walk from './ast/walk';
import analyse from './ast/analyse';
import { blank, has, keys } from './utils/object';
import { sequence } from './utils/promise';
import { isImportDeclaration, isExportDeclaration } from './utils/map-helpers';
import getLocation from './utils/getLocation';
import makeLegalIdentifier from './utils/makeLegalIdentifier';

const emptyArrayPromise = Promise.resolve([]);

export default class Module {
	constructor ({ path, source, bundle }) {
		this.source = source;

		this.bundle = bundle;
		this.path = path;

		this.magicString = new MagicString( source, {
			filename: path
		});

		this.suggestedNames = {};
		this.comments = [];

		// Try to extract a list of top-level statements/declarations. If
		// the parse fails, attach file info and abort
		try {
			const ast = parse( source, {
				ecmaVersion: 6,
				sourceType: 'module',
				onComment: ( block, text, start, end ) => this.comments.push({ block, text, start, end })
			});

			walk( ast, {
				enter: node => {
					this.magicString.addSourcemapLocation( node.start );
					this.magicString.addSourcemapLocation( node.end );
				}
			});

			this.statements = ast.body.map( node => {
				const magicString = this.magicString.snip( node.start, node.end ).append( '\n' );
				return new Statement( node, magicString, this );
			});
		} catch ( err ) {
			err.code = 'PARSE_ERROR';
			err.file = path;
			throw err;
		}

		this.importDeclarations = this.statements.filter( isImportDeclaration );
		this.exportDeclarations = this.statements.filter( isExportDeclaration );

		this.analyse();
	}

	analyse () {
		// imports and exports, indexed by ID
		this.imports = {};
		this.exports = {};

		this.importDeclarations.forEach( statement => {
			const node = statement.node;
			const source = node.source.value;

			node.specifiers.forEach( specifier => {
				const isDefault = specifier.type === 'ImportDefaultSpecifier';
				const isNamespace = specifier.type === 'ImportNamespaceSpecifier';

				const localName = specifier.local.name;
				const name = isDefault ? 'default' : isNamespace ? '*' : specifier.imported.name;
<commit_msg>You get a newline! YOU get a newline! Everyone gets a newline!<commit_after>import { relative } from 'path';
import { Promise } from 'sander';
import { parse } from 'acorn';
import MagicString from 'magic-string';
import Statement from './Statement';
import walk from './ast/walk';
import analyse from './ast/analyse';
import { blank, has, keys } from './utils/object';
import { sequence } from './utils/promise';
import { isImportDeclaration, isExportDeclaration } from './utils/map-helpers';
import getLocation from './utils/getLocation';
import makeLegalIdentifier from './utils/makeLegalIdentifier';

const emptyArrayPromise = Promise.resolve([]);

export default class Module {
	constructor ({ path, source, bundle }) {
		this.source = source;

		this.bundle = bundle;
		this.path = path;

		this.magicString = new MagicString( source, {
			filename: path
		});

		this.suggestedNames = {};
		this.comments = [];

		// Try to extract a list of top-level statements/declarations. If
		// the parse fails, attach file info and abort
		try {
			const ast = parse( source, {
				ecmaVersion: 6,
				sourceType: 'module',
				onComment: ( block, text, start, end ) => this.comments.push({ block, text, start, end })
			});

			walk( ast, {
				enter: node => {
					this.magicString.addSourcemapLocation( node.start );
					this.magicString.addSourcemapLocation( node.end );
				}
			});

			this.statements = ast.body.map( node => {
				const magicString = this.magicString.snip( node.start, node.end ).prepend( '\n' ).append( '\n' );
				return new Statement( node, magicString, this );
			});
		} catch ( err ) {
			err.code = 'PARSE_ERROR';
			err.file = path;
			throw err;
		}

		this.importDeclarations = this.statements.filter( isImportDeclaration );
		this.exportDeclarations = this.statements.filter( isExportDeclaration );

		this.analyse();
	}

	analyse () {
		// imports and exports, indexed by ID
		this.imports = {};
		this.exports = {};

		this.importDeclarations.forEach( statement => {
			const node = statement.node;
			const source = node.source.value;

			node.specifiers.forEach( specifier => {
				const isDefault = specifier.type === 'ImportDefaultSpecifier';
				const isNamespace = specifier.type === 'ImportNamespaceSpecifier';

				const localName = specifier.local.name;
				const name = isDefault ? 'default' : isNamespace ? '*' : specifier.imported.name;

{'fraction_non_alphanumeric': 0.136180157212662, 'fraction_numerical': 0.0004248990864669641, 'mean_word_length': 3.59765625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4687691', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1374, 'n_words': 387}