How to use the source-map.SourceNode.fromStringWithSourceMap function in source-map

To help you get started, we’ve selected a few source-map examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erzu / porter / packages / porter / src / package.js View on Github external
async createSourceNode({ source, code, map }) {
    if (map instanceof SourceMapGenerator) {
      map = map.toJSON()
    }

    if (map) {
      const consumer = await new SourceMapConsumer(map)
      return SourceNode.fromStringWithSourceMap(code, consumer)
    } else {
      // Source code need to be mapped line by line for debugging in devtols to work.
      const lines = code.split('\n')
      const node = new SourceNode()
      for (let i = 0; i < lines.length; i++) {
        node.add(new SourceNode(i + 1, 0, source, lines[i]))
      }
      return node.join('\n')
      // return new SourceNode(1, 0, source, code)
    }
  }
github accordproject / concerto / packages / composer-runtime / lib / scriptcompiler.js View on Github external
LOG.entry(method, context, script);

        // Convert the script into a source map.
        let sourceFileName = script.getIdentifier();
        let sourceCode = script.getContents();
        let sourceMap = this.convertScriptToSourceMap(context, script);

        // Allow someone else to post-process the converted script.
        const transformedScript = this.transformScript(sourceFileName, sourceCode, sourceMap);
        sourceFileName = transformedScript.sourceFileName;
        sourceCode = transformedScript.sourceCode;
        sourceMap = transformedScript.sourceMap;

        // Create a new source node from the script contents and source map
        const sourceMapConsumer = new SourceMapConsumer(sourceMap);
        const result = SourceNode.fromStringWithSourceMap(sourceCode, sourceMapConsumer);
        LOG.exit(method, result);
        return result;
    }
github fossasia / susper.com / node_modules / handlebars / lib / precompiler.js View on Github external
knownHelpersOnly: opts.o
    };

    if (opts.map) {
      options.srcName = template.path;
    }
    if (opts.data) {
      options.data = true;
    }

    let precompiled = Handlebars.precompile(template.source, options);

    // If we are generating a source map, we have to reconstruct the SourceNode object
    if (opts.map) {
      let consumer = new SourceMapConsumer(precompiled.map);
      precompiled = SourceNode.fromStringWithSourceMap(precompiled.code, consumer);
    }

    if (opts.simple) {
      output.add([precompiled, '\n']);
    } else {
      if (!template.name) {
        throw new Handlebars.Exception('Name missing for template');
      }

      if (opts.amd && !multiple) {
        output.add('return ');
      }
      output.add([objectName, '[\'', template.name, '\'] = template(', precompiled, ');\n']);
    }
  });
github wycats / handlebars.js / lib / precompiler.js View on Github external
knownHelpersOnly: opts.o
    };

    if (opts.map) {
      options.srcName = template.path;
    }
    if (opts.data) {
      options.data = true;
    }

    let precompiled = Handlebars.precompile(template.source, options);

    // If we are generating a source map, we have to reconstruct the SourceNode object
    if (opts.map) {
      let consumer = new SourceMapConsumer(precompiled.map);
      precompiled = SourceNode.fromStringWithSourceMap(
        precompiled.code,
        consumer
      );
    }

    if (opts.simple) {
      output.add([precompiled, '\n']);
    } else {
      if (!template.name) {
        throw new Handlebars.Exception('Name missing for template');
      }

      if (opts.amd && !multiple) {
        output.add('return ');
      }
      output.add([
github sony / cdp-js / packages / master-tasks / tasks / srcmap.js View on Github external
function getNodeFromFiles(scriptFile, mapFile) {
    if (fs.existsSync(scriptFile) && fs.existsSync(mapFile)) {
        try {
            return SourceNode.fromStringWithSourceMap(
                getScriptFromFile(scriptFile),
                new SourceMapConsumer(getMapFromMapFile(mapFile))
            );
        } catch (error) {
            console.error('getNodeFromFiles() error: ' + error);
            return new SourceNode();
        }
    } else {
        return new SourceNode();
    }
}
github yargalot / Angular-HMR / index.js View on Github external
if (this.sourceMap === false) {
    return this.callback(null, [
      prependText,
      processedSource,
      appendText
    ].join(separator));
  }

  if (!map) {
    map = makeIdentitySourceMap(source, this.resourcePath);
  }

  node = new SourceNode(null, null, null, [
    new SourceNode(null, null, this.resourcePath, prependText),
    SourceNode.fromStringWithSourceMap(processedSource, new SourceMapConsumer(map))
  ]).join(separator);

  result = node.toStringWithSourceMap();

  this.callback(null, result.code, result.map.toString());
};
github webpack / webpack-sources / lib / ConcatSource.js View on Github external
this._children.map(function(item) {
				if (typeof item.node === "function") return item.node(options);
				const sourceAndMap = item.sourceAndMap(options);
				if (sourceAndMap.map) {
					return SourceNode.fromStringWithSourceMap(
						sourceAndMap.source,
						new SourceMapConsumer(sourceAndMap.map)
					);
				} else {
					return sourceAndMap.source;
				}
			})
		);
github webpack / webpack-sources / lib / SourceMapSource.js View on Github external
node(options) {
		this._ensureValueString();
		this._ensureSourceMapObject();
		this._ensureOriginalSourceString();
		let node = SourceNode.fromStringWithSourceMap(
			this._valueAsString,
			new SourceMapConsumer(this._sourceMapAsObject)
		);
		node.setSourceContent(this._name, this._originalSourceAsString);
		if (this._hasInnerSourceMap) {
			this._ensureInnerSourceMapObject();
			node = applySourceMap(
				node,
				new SourceMapConsumer(this._innerSourceMapAsObject),
				this._name,
				this._removeOriginalSource
			);
		}
		return node;
	}
github fossasia / susper.com / node_modules / webpack-sources / lib / SourceMapSource.js View on Github external
node(options) {
		var innerSourceMap = this._innerSourceMap;
		var sourceMap = this._sourceMap;
		if(innerSourceMap) {
			sourceMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
			if(this._originalSource)
				sourceMap.setSourceContent(this._name, this._originalSource);
			innerSourceMap = new SourceMapConsumer(innerSourceMap);
			sourceMap.applySourceMap(innerSourceMap, this._name);
			sourceMap = sourceMap.toJSON();
		}
		return SourceNode.fromStringWithSourceMap(this._value, new SourceMapConsumer(sourceMap));
	}
github webpack / core / lib / SourceMapSource.js View on Github external
SourceMapSource.prototype.node = function(options) {
	var innerSourceMap = this._innerSourceMap;
	var sourceMap = this._sourceMap;
	if(innerSourceMap) {
		innerSourceMap = new SourceMapConsumer(innerSourceMap);
		sourceMap = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(sourceMap));
		sourceMap.setSourceContent(this._name, this._originalSource);
		sourceMap.applySourceMap(innerSourceMap, this._name);
		sourceMap = sourceMap.toJSON();
	}
	return SourceNode.fromStringWithSourceMap(this._value, new SourceMapConsumer(sourceMap));
};