Sha256: 05bbd1940b8be965d5d6aaa1ce717ca22ea71c899c3410c32a2bac5d89d21475

Contents?: true

Size: 1.47 KB

Versions: 29

Compression:

Stored size: 1.47 KB

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
"use strict";

const getNumberOfLines = require("./helpers").getNumberOfLines;
const getUnfinishedLine = require("./helpers").getUnfinishedLine;

class CodeNode {
	constructor(generatedCode) {
		this.generatedCode = generatedCode;
	}

	clone() {
		return new CodeNode(this.generatedCode);
	}

	getGeneratedCode() {
		return this.generatedCode;
	}

	getMappings(mappingsContext) {
		const lines = getNumberOfLines(this.generatedCode);
		const mapping = Array(lines+1).join(";");
		if(lines > 0) {
			mappingsContext.unfinishedGeneratedLine = getUnfinishedLine(this.generatedCode);
			if(mappingsContext.unfinishedGeneratedLine > 0) {
				return mapping + "A";
			} else {
				return mapping;
			}
		} else {
			const prevUnfinished = mappingsContext.unfinishedGeneratedLine;
			mappingsContext.unfinishedGeneratedLine += getUnfinishedLine(this.generatedCode);
			if(prevUnfinished === 0 && mappingsContext.unfinishedGeneratedLine > 0) {
				return "A";
			} else {
				return "";
			}
		}
	}

	addGeneratedCode(generatedCode) {
		this.generatedCode += generatedCode;
	}

	mapGeneratedCode(fn) {
		const generatedCode = fn(this.generatedCode);
		return new CodeNode(generatedCode);
	}

	getNormalizedNodes() {
		return [this];
	}

	merge(otherNode) {
		if(otherNode instanceof CodeNode) {
			this.generatedCode += otherNode.generatedCode;
			return this;
		}
		return false;
	}
}

module.exports = CodeNode;

Version data entries

29 entries across 28 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/source-list-map/lib/CodeNode.js
disco_app-0.18.0 test/dummy/node_modules/source-list-map/lib/CodeNode.js
disco_app-0.18.2 test/dummy/node_modules/source-list-map/lib/CodeNode.js
disco_app-0.16.1 test/dummy/node_modules/source-list-map/lib/CodeNode.js
disco_app-0.15.2 test/dummy/node_modules/source-list-map/lib/CodeNode.js
disco_app-0.18.4 test/dummy/node_modules/source-list-map/lib/CodeNode.js
disco_app-0.18.1 test/dummy/node_modules/source-list-map/lib/CodeNode.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/source-list-map/lib/CodeNode.js
disco_app-0.14.0 test/dummy/node_modules/source-list-map/lib/CodeNode.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/source-list-map/lib/CodeNode.js
tang-0.2.1 spec/tang_app/node_modules/source-list-map/lib/CodeNode.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/source-list-map/lib/CodeNode.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/source-list-map/lib/CodeNode.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/source-list-map/lib/CodeNode.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/source-list-map/lib/CodeNode.js
tang-0.2.0 spec/tang_app/node_modules/source-list-map/lib/CodeNode.js
tang-0.1.0 spec/tang_app/node_modules/source-list-map/lib/CodeNode.js
tang-0.0.9 spec/tang_app/node_modules/source-list-map/lib/CodeNode.js
enju_library-0.3.8 spec/dummy/node_modules/source-list-map/lib/CodeNode.js
ilog-0.4.1 node_modules/webpack/node_modules/source-list-map/lib/CodeNode.js