How to use the sourcemap-codec.encode function in sourcemap-codec

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 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 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
	};
}
github Rich-Harris / code-red / src / print / index.ts View on Github external
chunk.loc.end.line - 1,
				chunk.loc.end.column,
			]);
		}
	}

	mappings.push(current_line);

	return {
		code,
		map: {
			version: 3,
			names: [],
			sources: [opts.sourceMapSource || null],
			sourcesContent: [opts.sourceMapContent || null],
			mappings: encode(mappings)
		}
	};
}

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