How to use sourcemap-codec - 10 common examples

To help you get started, we’ve selected a few sourcemap-codec 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 sveltejs / sapper / src / core / create_compilers / extract_css.ts View on Github external
modules.forEach(module => {
		if (!/\.css$/.test(module)) return;

		const css = css_map.get(module);

		const { code, map } = extract_sourcemap(css, module);

		parts.push(code);

		if (map) {
			const lines = codec.decode(map.mappings);

			if (combined_map.sources.length > 0 || combined_map.names.length > 0) {
				lines.forEach(line => {
					line.forEach(segment => {
						// adjust source index
						segment[1] += combined_map.sources.length;

						// adjust name index
						if (segment[4]) segment[4] += combined_map.names.length;
					});
				});
			}

			combined_map.sources.push(...map.sources);
			combined_map.sourcesContent.push(...map.sourcesContent);
			combined_map.names.push(...map.names);
github Comandeer / rollup-plugin-babel-minify / src / fixMappings.js View on Github external
function fixMappings( mappings ) {
	if ( typeof mappings !== 'string' ) {
		return '';
	}

	mappings = decode( mappings );

	mappings[ 0 ].forEach( ( line, index ) => {
		// If the line has only one segment with only one item,
		// just drop the whole line.
		if ( line && line.length === 1 ) {
			mappings[ 0 ].splice( index, 1 );
		}
	} );

	return encode( mappings );
}
github Rich-Harris / sorcery / src / Chain.js View on Github external
while ( i-- ) {
			line = this.node.mappings[i];
			resolved[i] = result = [];

			for ( j = 0; j < line.length; j += 1 ) {
				applySegment( line[j], result );
			}
		}

		let tracingTime = process.hrtime( tracingStart );
		this._stats.tracingTime = 1e9 * tracingTime[0] + tracingTime[1];

		// Encode mappings
		let encodingStart = process.hrtime();
		let mappings = encode( resolved );
		let encodingTime = process.hrtime( encodingStart );
		this._stats.encodingTime = 1e9 * encodingTime[0] + encodingTime[1];

		let includeContent = options.includeContent !== false;

		return new SourceMap({
			file: basename( this.node.file ),
			sources: allSources.map( source => slash( relative( options.base || dirname( this.node.file ), source ) ) ),
			sourcesContent: allSources.map( source => includeContent ? this.sourcesContentByPath[ source ] : null ),
			names: allNames,
			mappings
		});
	},
github VadimDez / ngx-img-fallback / node_modules / angular-cli / node_modules / rollup / src / utils / collapseSourcemaps.js View on Github external
});

		return source;
	});

	let source = new Link( map, sources );

	bundleSourcemapChain.forEach( map => {
		source = new Link( map, [ source ] );
	});

	const { names, mappings } = source.traceMappings();

	// we re-use the `map` object because it has convenient toString/toURL methods
	map.sourcesContent = modules.map( module => module.originalCode );
	map.mappings = encode( mappings );
	map.names = names;

	return map;
}
github sveltejs / sapper / src / core / create_compilers / extract_css.ts View on Github external
// adjust name index
						if (segment[4]) segment[4] += combined_map.names.length;
					});
				});
			}

			combined_map.sources.push(...map.sources);
			combined_map.sourcesContent.push(...map.sourcesContent);
			combined_map.names.push(...map.names);

			mappings.push(...lines);
		}
	});

	if (parts.length > 0) {
		combined_map.mappings = codec.encode(mappings);

		combined_map.sources = combined_map.sources.map(source => path.relative(asset_dir, source).replace(/\\/g, '/'));

		return {
			code: parts.join('\n'),
			map: combined_map
		};
	}

	return null;
}
github Comandeer / rollup-plugin-babel-minify / src / fixMappings.js View on Github external
function fixMappings( mappings ) {
	if ( typeof mappings !== 'string' ) {
		return '';
	}

	mappings = decode( mappings );

	mappings[ 0 ].forEach( ( line, index ) => {
		// If the line has only one segment with only one item,
		// just drop the whole line.
		if ( line && line.length === 1 ) {
			mappings[ 0 ].splice( index, 1 );
		}
	} );

	return encode( mappings );
}
github Rich-Harris / butternut / src / program / check.js View on Github external
export default function check ( magicString, ast ) {
	const code = magicString.toString();

	try {
		parse( code, {
			ecmaVersion: 8,
			sourceType: 'module'
		});
	} catch ( err ) {
		const map = magicString.generateMap();
		const { line, column } = err.loc;
		const snippet = code.slice( Math.max( 0, err.pos - 35 ), Math.min( code.length, err.pos + 35 ) );

		const mappings = decode( map.mappings );
		const segments = mappings[ line - 1 ];

		for ( let i = 0; i < segments.length; i += 1 ) {
			const segment = segments[i];
			if ( segment[0] >= column ) {
				const sourceCodeLine = segment[2];
				const sourceCodeColumn = segment[3];

				err.message = `Butternut generated invalid JS: code in source file near (${sourceCodeLine + 1}:${sourceCodeColumn}) became\n...${snippet}...`;

				try {
					const repro = createRepro( magicString.original, ast, sourceCodeLine, sourceCodeColumn );
					if ( repro ) err.repro = repro;
				} catch (err) {
					// do nothing
				}
github dumberjs / dumber / test / transform.spec.js View on Github external
unit => {
      t.deepEqual(unit, {
        contents: 'a;\nadd;\nb;\n',
        path: 'src/foo.js',
        moduleId: 'foo',
        sourceMap: {
          version: 3,
          file: 'src/foo.js',
          sources: [ 'src/foo.js' ],
          sourcesContent: [ 'a;b;\n' ],
          names: [],
          mappings: encode([
            [ [ 0, 0, 0, 0 ], [ 1, 0, 0, 0 ], [ 2, 0, 0, 0 ] ],
            [ [ 0, 0, 0, 0 ] ],
            [ [ 0, 0, 0, 3 ], [ 1, 0, 0, 3 ], [ 2, 0, 0, 3 ] ]
          ])
        }
      })
    },
    t.fail
github sveltejs / rollup-plugin-svelte / index.js View on Github external
if (i > 0) {
							decoded.forEach(line => {
								line.forEach(segment => {
									segment[1] = i;
								});
							});
						}

						mappings.push(...decoded);
					}
				}

				const writer = new CssWriter(result, {
					sources,
					sourcesContent,
					mappings: encode(mappings)
				}, this.warn);

				css(writer);
			}
		}
	};
github Comandeer / rollup-plugin-babel-minify / src / utils.js View on Github external
codeStart = codeStart ? codeStart.length + 1 : 1;

	let whitespaceAtStart = code.replace( `${ banner }\n`, '' ).match( /^(\s)+/g );
	whitespaceAtStart = whitespaceAtStart ? whitespaceAtStart.length : 0;

	mappings.unshift( [] );

	if ( Array.isArray( mappings[ codeStart ] ) && mappings[ codeStart ].length ) {
		const offset = mappings[ codeStart ][ 0 ][ 0 ] - whitespaceAtStart;

		mappings[ codeStart ].forEach( ( segment ) => {
			segment[ 0 ] -= offset;
		} );
	}

	map.mappings = encodeSourceMap( mappings );

	return {
		code,
		map
	};
}

sourcemap-codec

Encode/decode sourcemap mappings

MIT
Latest version published 5 years ago

Package Health Score

55 / 100
Full package analysis

Popular sourcemap-codec functions