Sha256: 6a5537b365b0b9fb28178fac65e3e59287e9426817b096100bfd3520e8a458d7

Contents?: true

Size: 900 Bytes

Versions: 4

Compression:

Stored size: 900 Bytes

Contents

import Node from '../Node.js';
import { loopStatement } from '../../utils/patterns.js';

export default class ReturnStatement extends Node {
	initialise(transforms) {
		this.loop = this.findNearest(loopStatement);
		this.nearestFunction = this.findNearest(/Function/);

		if (
			this.loop &&
			(!this.nearestFunction || this.loop.depth > this.nearestFunction.depth)
		) {
			this.loop.canReturn = true;
			this.shouldWrap = true;
		}

		if (this.argument) this.argument.initialise(transforms);
	}

	transpile(code, transforms) {
		const shouldWrap =
			this.shouldWrap && this.loop && this.loop.shouldRewriteAsFunction;

		if (this.argument) {
			if (shouldWrap) code.prependRight(this.argument.start, `{ v: `);
			this.argument.transpile(code, transforms);
			if (shouldWrap) code.appendLeft(this.argument.end, ` }`);
		} else if (shouldWrap) {
			code.appendLeft(this.start + 6, ' {}');
		}
	}
}

Version data entries

4 entries across 4 versions & 1 rubygems

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