Skip to content

Repository files navigation

source-map-validator

A comprehensive source map validator that checks format, mappings, coverage, and semantic accuracy against ECMA-426.

What it validates

Level 1 — Format (source map only)

  • Valid JSON, version is integer 3, required fields present
  • Field types (sources, sourcesContent, names, mappings, ignoreList)
  • sourcesContent/sources length match, ignoreList bounds
  • VLQ encoding validity (characters, continuations, segment field counts)
  • Mapping index bounds, column ordering, non-negative positions
  • Index map section validity

Level 2 — Generated file (+ generated JS/CSS)

  • sourceMappingURL comment present
  • Mappings within generated file bounds
  • Coverage analysis (% of generated code with mapping coverage)

Level 3 — Deep validation (+ original sources)

  • Mappings within original source bounds
  • Token matching (named mappings point to correct identifiers)
  • sourcesContent vs. file consistency
  • Round-trip accuracy

Level 4 — Advisory (always runs)

  • Absolute paths, backslash paths
  • Missing sourcesContent/ignoreList
  • Deprecated x_google_ignoreList
  • Extension fields

Install

npm install source-map-validator

CLI Usage

# Basic validation
npx sourcemap-validator validate app.js.map
# With generated file (enables Level 2 + coverage)
npx sourcemap-validator validate app.js.map --generated=app.js
# Deep validation with original sources
npx sourcemap-validator validate app.js.map --generated=app.js --sources-dir=./src
# Output formats: pretty (default), json, github
npx sourcemap-validator validate app.js.map --format=json
# Inspect: show decoded mappings and stats
npx sourcemap-validator inspect app.js.map
# Coverage report
npx sourcemap-validator coverage app.js.map app.js
# Feature flags
npx sourcemap-validator validate app.js.map --disable=has-sources-content
npx sourcemap-validator validate app.js.map --only=vlq-valid,mapping-index-bounds
npx sourcemap-validator validate app.js.map --preset=strict # warnings become errors
npx sourcemap-validator validate app.js.map --preset=minimal # spec violations only# Proposals (opt-in validation for TC39 proposals not yet in the spec)
npx sourcemap-validator validate app.js.map --proposals=scopes

Library API

import{validate}from'source-map-validator';constresult=validate({sourceMap: fs.readFileSync('app.js.map','utf-8'),generatedSource: fs.readFileSync('app.js','utf-8'),// optionaloriginalSources: {'src/app.ts': '...'},// optionalpreset: 'strict',// optionalrules: {'has-sources-content': false},// optionalproposals: ['scopes'],// optional — enable TC39 proposal validation});console.log(result.valid);// booleanconsole.log(result.errors);// Diagnostic[]console.log(result.warnings);// Diagnostic[]console.log(result.coverage);// CoverageReport | undefinedconsole.log(result.stats);// SourceMapStats

Validation Rules

RuleLevelSeverityDescription
valid-json1errorSource map must be valid JSON
version-field1errorversion must be integer 3
required-fields1errorversion, sources, mappings required
field-types1errorAll fields have correct types
sources-content-length1errorsourcesContent length matches sources
ignore-list-bounds1errorignoreList indices within bounds
vlq-valid1errorValid Base64 VLQ characters
segment-field-count1errorSegments have 1, 4, or 5 fields
mapping-index-bounds1errorSource/name indices within bounds
column-ordering1errorColumns ascending within each line
non-negative-positions1errorAll positions non-negative
index-map-valid1errorIndex map sections valid
mappings-in-generated-bounds2errorMappings within generated file
source-mapping-url2warningsourceMappingURL comment present
mappings-in-original-bounds3errorMappings within original sources
token-matching3warningNamed mappings match tokens
sources-content-consistency3warningsourcesContent matches files
no-absolute-paths4warningNo absolute filesystem paths
no-backslash-paths4warningNo backslash path separators
has-sources-content4warningsourcesContent present
has-ignore-list4infoignoreList for third-party code
deprecated-x-google4infoDeprecated x_google_ignoreList
sources-resolvable4warningEach source resolvable via content
extension-fields4infoNon-standard fields present

Proposal Rules (opt-in via --proposals)

These rules validate TC39 proposals that are not yet part of the ECMA-426 specification. They are disabled by default and must be explicitly enabled.

RuleLevelSeverityProposalDescription
scopes-field-type1errorscopesscopes must be a string
scopes-decode-valid1errorscopesVLQ/structural decoding succeeds
scopes-tree-balanced1errorscopesScope/range trees properly nested
scopes-names-bounds1errorscopesName indices within bounds
scopes-sources-bounds1errorscopesSource indices and tree count valid
scopes-positions-ordered1errorscopesStart positions precede end positions
scopes-range-bounds2errorscopesGenerated ranges within file bounds
scopes-original-bounds3errorscopesOriginal scopes within source bounds

Presets

  • strict — All rules, warnings treated as errors
  • ci — All rules enabled (default behavior)
  • minimal — Only ECMA-426 spec violations (Level 1 errors)

Project Structure

packages/
core/ — Validation engine (zero runtime dependencies)
cli/ — CLI tool (commander)
web/ — Web playground (planned)

License

MIT

About

Validate souremaps

Resources

Stars

5 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages