Sha256: efc2cda93946c20c1cef958f7d2c69c154a90e9e9ce02839d5fa581746be0cef

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

import LoopStatement from './shared/LoopStatement.js';
import extractNames from '../extractNames.js';

export default class ForStatement extends LoopStatement {
	findScope(functionScope) {
		return functionScope || !this.createdScope
			? this.parent.findScope(functionScope)
			: this.body.scope;
	}

	transpile(code, transforms) {
		const i1 = this.getIndentation() + code.getIndentString();

		if (this.shouldRewriteAsFunction) {
			// which variables are declared in the init statement?
			const names =
				this.init.type === 'VariableDeclaration'
					? [].concat.apply(
							[],
							this.init.declarations.map(declarator =>
								extractNames(declarator.id)
							)
						)
					: [];

			const aliases = this.aliases;

			this.args = names.map(
				name => (name in this.aliases ? this.aliases[name].outer : name)
			);
			this.params = names.map(
				name => (name in this.aliases ? this.aliases[name].inner : name)
			);

			const updates = Object.keys(this.reassigned).map(
				name => `${aliases[name].outer} = ${aliases[name].inner};`
			);

			if (updates.length) {
				if (this.body.synthetic) {
					code.appendLeft(this.body.body[0].end, `; ${updates.join(` `)}`);
				} else {
					const lastStatement = this.body.body[this.body.body.length - 1];
					code.appendLeft(
						lastStatement.end,
						`\n\n${i1}${updates.join(`\n${i1}`)}`
					);
				}
			}
		}

		super.transpile(code, transforms);
	}
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jass-0.9.5 vendor/node_modules/buble/src/program/types/ForStatement.js
jass-0.9.4 vendor/node_modules/buble/src/program/types/ForStatement.js
jass-0.9.3 vendor/node_modules/buble/src/program/types/ForStatement.js
jass-0.9.1 vendor/node_modules/buble/src/program/types/ForStatement.js