You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@jridgewell/gen-mapping

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jridgewell/gen-mapping

Generate source maps


Version published
Weekly downloads
45M
increased by0.74%
Maintainers
1
Install size
90.6 kB
Created
Weekly downloads
 

Package description

What is @jridgewell/gen-mapping?

The @jridgewell/gen-mapping package is a library for generating source maps, which are used to map the transformed source to the original source, enabling developers to debug their code more easily after it has been compiled or minified. It provides a simple API for adding mappings and generating the source map.

What are @jridgewell/gen-mapping's main functionalities?

Creating a new source map generator

This feature allows you to create a new source map generator instance, specifying the output file name for the source map.

{"const { GenMapping } = require('@jridgewell/gen-mapping');

const map = new GenMapping({
  file: 'minified.js'
});
}

Adding mappings to the source map

This feature allows you to add individual mappings to the source map, linking a location in the generated file to a location in the original source file.

{"const { addMapping } = require('@jridgewell/gen-mapping');

addMapping(map, {
  generated: { line: 1, column: 5 },
  source: 'original.js',
  original: { line: 1, column: 30 }
});
}

Generating the source map

This feature generates the final source map from the added mappings, which can then be used by browsers or other tools to map the transformed source back to the original source.

{"const { toMapping } = require('@jridgewell/gen-mapping');

const sourceMap = toMapping(map);
}

Other packages similar to @jridgewell/gen-mapping

Readme

Source

@jridgewell/gen-mapping

Generate source maps

gen-mapping allows you to generate a source map during transpilation or minification. With a source map, you're able to trace the original location in the source file, either in Chrome's DevTools or using a library like @jridgewell/trace-mapping.

You may already be familiar with the source-map package's SourceMapGenerator. This provides the same addMapping and setSourceContent API.

Installation

npm install @jridgewell/gen-mapping

Usage

import { GenMapping, addMapping, setSourceContent, encodedMap } from '@jridgewell/gen-mapping';

const map = new GenMapping({
  file: 'output.js',
  sourceRoot: 'https://example.com/',
});

setSourceContent(map, 'input.js', `function foo() {}`);

addMapping(map, {
  // Lines start at line 1, columns at column 0.
  generated: { line: 1, column: 0 },
  source: 'input.js',
  original: { line: 1, column: 0 },
});

addMapping(map, {
  generated: { line: 1, column: 9 },
  source: 'input.js',
  original: { line: 1, column: 9 },
  name: 'foo',
});

assert.deepEqual(encodedMap(map), {
  version: 3,
  file: 'output.js',
  names: ['foo'],
  sourceRoot: 'https://example.com/',
  sources: ['input.js'],
  sourcesContent: ['function foo() {}'],
  mappings: 'AAAA,SAASA',
});

Keywords

FAQs

Package last updated on 27 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc