sourcemap-codec-1.5.0/000077500000000000000000000000001464330745500146015ustar00rootroot00000000000000sourcemap-codec-1.5.0/.editorconfig000066400000000000000000000003231464330745500172540ustar00rootroot00000000000000#root = true [*] indent_style = space end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true max_line_length = 100 indent_size = 2 [*.md] trim_trailing_whitespace = false sourcemap-codec-1.5.0/.eslintrc.js000066400000000000000000000014741464330745500170460ustar00rootroot00000000000000module.exports = { root: true, parser: '@typescript-eslint/parser', plugins: ['@typescript-eslint'], extends: [ 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier', ], rules: { '@typescript-eslint/consistent-type-imports': 'error', '@typescript-eslint/no-duplicate-imports': 'error', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-unused-vars': [ 'error', { argsIgnorePattern: '^_', }, ], 'no-constant-condition': 'off', 'no-unused-labels': 'off', }, overrides: [ { files: ['test/**/*.ts'], rules: { '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-explicit-any': 'off', }, }, ], }; sourcemap-codec-1.5.0/.github/000077500000000000000000000000001464330745500161415ustar00rootroot00000000000000sourcemap-codec-1.5.0/.github/workflows/000077500000000000000000000000001464330745500201765ustar00rootroot00000000000000sourcemap-codec-1.5.0/.github/workflows/test.yml000066400000000000000000000016101464330745500216760ustar00rootroot00000000000000name: Node CI on: [push] jobs: build: runs-on: ubuntu-latest strategy: matrix: latest-node-version: [22.x] node-version: [18.x, 20.x, 22.x] steps: - uses: actions/checkout@v1 - name: Build with Node.js ${{ matrix.latest-node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.latest-node-version }} - name: Build and test with latest run: | npm install npm run build npm run test:coverage - name: Switch to Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - name: Test legacy node run: | npm run test:only - name: Benchmark run: | npm run benchmark:install npm run benchmark:only env: CI: true sourcemap-codec-1.5.0/.gitignore000066400000000000000000000000751464330745500165730ustar00rootroot00000000000000.DS_Store node_modules dist coverage package-lock.json .idea sourcemap-codec-1.5.0/.mocharc.js000066400000000000000000000001261464330745500166300ustar00rootroot00000000000000module.exports = { spec: ['test/**/*.test.ts'], 'node-option': ['import=tsx'], }; sourcemap-codec-1.5.0/CHANGELOG.md000066400000000000000000000030231464330745500164100ustar00rootroot00000000000000# sourcemap-codec changelog ## 1.4.10 * Sort mappings during decode ([f9d1b33f](https://github.com/jridgewell/sourcemap-codec/commit/f9d1b33f)) ## 1.4.9 * Performance boost ([#86](https://github.com/Rich-Harris/sourcemap-codec/pull/86)) * Add native ESM entry point ([#85](https://github.com/Rich-Harris/sourcemap-codec/pull/85)) ## 1.4.8 * Performance boost ([#80](https://github.com/Rich-Harris/sourcemap-codec/pull/80)) ## 1.4.7 * Include .map files in package ([#73](https://github.com/Rich-Harris/sourcemap-codec/issues/73)) ## 1.4.6 * Use arrays instead of typed arrays ([#79](https://github.com/Rich-Harris/sourcemap-codec/pull/79)) ## 1.4.5 * Handle overflow cases ([#78](https://github.com/Rich-Harris/sourcemap-codec/pull/78)) ## 1.4.4 * Use Uint32Array, yikes ([#77](https://github.com/Rich-Harris/sourcemap-codec/pull/77)) ## 1.4.3 * Use Uint16Array to prevent overflow ([#75](https://github.com/Rich-Harris/sourcemap-codec/pull/75)) ## 1.4.2 * GO EVEN FASTER ([#74](https://github.com/Rich-Harris/sourcemap-codec/pull/74)) ## 1.4.1 * GO FASTER ([#71](https://github.com/Rich-Harris/sourcemap-codec/pull/71)) ## 1.4.0 * Add TypeScript declarations ([#70](https://github.com/Rich-Harris/sourcemap-codec/pull/70)) ## 1.3.1 * Update build process, expose `pkg.module` ## 1.3.0 * Update build process ## 1.2.1 * Add dist files to npm package ## 1.2.0 * Add ES6 build * Update dependencies * Add test coverage ## 1.1.0 * Fix bug with lines containing single-character segments * Add tests ## 1.0.0 * First release sourcemap-codec-1.5.0/LICENSE000066400000000000000000000020601464330745500156040ustar00rootroot00000000000000The MIT License Copyright (c) 2015 Rich Harris Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. sourcemap-codec-1.5.0/README.md000066400000000000000000000235031464330745500160630ustar00rootroot00000000000000# @jridgewell/sourcemap-codec Encode/decode the `mappings` property of a [sourcemap](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit). ## Why? Sourcemaps are difficult to generate and manipulate, because the `mappings` property – the part that actually links the generated code back to the original source – is encoded using an obscure method called [Variable-length quantity](https://en.wikipedia.org/wiki/Variable-length_quantity). On top of that, each segment in the mapping contains offsets rather than absolute indices, which means that you can't look at a segment in isolation – you have to understand the whole sourcemap. This package makes the process slightly easier. ## Installation ```bash npm install @jridgewell/sourcemap-codec ``` ## Usage ```js import { encode, decode } from '@jridgewell/sourcemap-codec'; var decoded = decode( ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' ); assert.deepEqual( decoded, [ // the first line (of the generated code) has no mappings, // as shown by the starting semi-colon (which separates lines) [], // the second line contains four (comma-separated) segments [ // segments are encoded as you'd expect: // [ generatedCodeColumn, sourceIndex, sourceCodeLine, sourceCodeColumn, nameIndex ] // i.e. the first segment begins at column 2, and maps back to the second column // of the second line (both zero-based) of the 0th source, and uses the 0th // name in the `map.names` array [ 2, 0, 2, 2, 0 ], // the remaining segments are 4-length rather than 5-length, // because they don't map a name [ 4, 0, 2, 4 ], [ 6, 0, 2, 5 ], [ 7, 0, 2, 7 ] ], // the final line contains two segments [ [ 2, 1, 10, 19 ], [ 12, 1, 11, 20 ] ] ]); var encoded = encode( decoded ); assert.equal( encoded, ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' ); ``` ## Benchmarks ``` node v20.10.0 amp.js.map - 45120 segments Decode Memory Usage: local code 5815135 bytes @jridgewell/sourcemap-codec 1.4.15 5868160 bytes sourcemap-codec 5492584 bytes source-map-0.6.1 13569984 bytes source-map-0.8.0 6390584 bytes chrome dev tools 8011136 bytes Smallest memory usage is sourcemap-codec Decode speed: decode: local code x 492 ops/sec ±1.22% (90 runs sampled) decode: @jridgewell/sourcemap-codec 1.4.15 x 499 ops/sec ±1.16% (89 runs sampled) decode: sourcemap-codec x 376 ops/sec ±1.66% (89 runs sampled) decode: source-map-0.6.1 x 34.99 ops/sec ±0.94% (48 runs sampled) decode: source-map-0.8.0 x 351 ops/sec ±0.07% (95 runs sampled) chrome dev tools x 165 ops/sec ±0.91% (86 runs sampled) Fastest is decode: @jridgewell/sourcemap-codec 1.4.15 Encode Memory Usage: local code 444248 bytes @jridgewell/sourcemap-codec 1.4.15 623024 bytes sourcemap-codec 8696280 bytes source-map-0.6.1 8745176 bytes source-map-0.8.0 8736624 bytes Smallest memory usage is local code Encode speed: encode: local code x 796 ops/sec ±0.11% (97 runs sampled) encode: @jridgewell/sourcemap-codec 1.4.15 x 795 ops/sec ±0.25% (98 runs sampled) encode: sourcemap-codec x 231 ops/sec ±0.83% (86 runs sampled) encode: source-map-0.6.1 x 166 ops/sec ±0.57% (86 runs sampled) encode: source-map-0.8.0 x 203 ops/sec ±0.45% (88 runs sampled) Fastest is encode: local code,encode: @jridgewell/sourcemap-codec 1.4.15 *** babel.min.js.map - 347793 segments Decode Memory Usage: local code 35424960 bytes @jridgewell/sourcemap-codec 1.4.15 35424696 bytes sourcemap-codec 36033464 bytes source-map-0.6.1 62253704 bytes source-map-0.8.0 43843920 bytes chrome dev tools 45111400 bytes Smallest memory usage is @jridgewell/sourcemap-codec 1.4.15 Decode speed: decode: local code x 38.18 ops/sec ±5.44% (52 runs sampled) decode: @jridgewell/sourcemap-codec 1.4.15 x 38.36 ops/sec ±5.02% (52 runs sampled) decode: sourcemap-codec x 34.05 ops/sec ±4.45% (47 runs sampled) decode: source-map-0.6.1 x 4.31 ops/sec ±2.76% (15 runs sampled) decode: source-map-0.8.0 x 55.60 ops/sec ±0.13% (73 runs sampled) chrome dev tools x 16.94 ops/sec ±3.78% (46 runs sampled) Fastest is decode: source-map-0.8.0 Encode Memory Usage: local code 2606016 bytes @jridgewell/sourcemap-codec 1.4.15 2626440 bytes sourcemap-codec 21152576 bytes source-map-0.6.1 25023928 bytes source-map-0.8.0 25256448 bytes Smallest memory usage is local code Encode speed: encode: local code x 127 ops/sec ±0.18% (83 runs sampled) encode: @jridgewell/sourcemap-codec 1.4.15 x 128 ops/sec ±0.26% (83 runs sampled) encode: sourcemap-codec x 29.31 ops/sec ±2.55% (53 runs sampled) encode: source-map-0.6.1 x 18.85 ops/sec ±3.19% (36 runs sampled) encode: source-map-0.8.0 x 19.34 ops/sec ±1.97% (36 runs sampled) Fastest is encode: @jridgewell/sourcemap-codec 1.4.15 *** preact.js.map - 1992 segments Decode Memory Usage: local code 261696 bytes @jridgewell/sourcemap-codec 1.4.15 244296 bytes sourcemap-codec 302816 bytes source-map-0.6.1 939176 bytes source-map-0.8.0 336 bytes chrome dev tools 587368 bytes Smallest memory usage is source-map-0.8.0 Decode speed: decode: local code x 17,782 ops/sec ±0.32% (97 runs sampled) decode: @jridgewell/sourcemap-codec 1.4.15 x 17,863 ops/sec ±0.40% (100 runs sampled) decode: sourcemap-codec x 12,453 ops/sec ±0.27% (101 runs sampled) decode: source-map-0.6.1 x 1,288 ops/sec ±1.05% (96 runs sampled) decode: source-map-0.8.0 x 9,289 ops/sec ±0.27% (101 runs sampled) chrome dev tools x 4,769 ops/sec ±0.18% (100 runs sampled) Fastest is decode: @jridgewell/sourcemap-codec 1.4.15 Encode Memory Usage: local code 262944 bytes @jridgewell/sourcemap-codec 1.4.15 25544 bytes sourcemap-codec 323048 bytes source-map-0.6.1 507808 bytes source-map-0.8.0 507480 bytes Smallest memory usage is @jridgewell/sourcemap-codec 1.4.15 Encode speed: encode: local code x 24,207 ops/sec ±0.79% (95 runs sampled) encode: @jridgewell/sourcemap-codec 1.4.15 x 24,288 ops/sec ±0.48% (96 runs sampled) encode: sourcemap-codec x 6,761 ops/sec ±0.21% (100 runs sampled) encode: source-map-0.6.1 x 5,374 ops/sec ±0.17% (99 runs sampled) encode: source-map-0.8.0 x 5,633 ops/sec ±0.32% (99 runs sampled) Fastest is encode: @jridgewell/sourcemap-codec 1.4.15,encode: local code *** react.js.map - 5726 segments Decode Memory Usage: local code 678816 bytes @jridgewell/sourcemap-codec 1.4.15 678816 bytes sourcemap-codec 816400 bytes source-map-0.6.1 2288864 bytes source-map-0.8.0 721360 bytes chrome dev tools 1012512 bytes Smallest memory usage is local code Decode speed: decode: local code x 6,178 ops/sec ±0.19% (98 runs sampled) decode: @jridgewell/sourcemap-codec 1.4.15 x 6,261 ops/sec ±0.22% (100 runs sampled) decode: sourcemap-codec x 4,472 ops/sec ±0.90% (99 runs sampled) decode: source-map-0.6.1 x 449 ops/sec ±0.31% (95 runs sampled) decode: source-map-0.8.0 x 3,219 ops/sec ±0.13% (100 runs sampled) chrome dev tools x 1,743 ops/sec ±0.20% (99 runs sampled) Fastest is decode: @jridgewell/sourcemap-codec 1.4.15 Encode Memory Usage: local code 140960 bytes @jridgewell/sourcemap-codec 1.4.15 159808 bytes sourcemap-codec 969304 bytes source-map-0.6.1 930520 bytes source-map-0.8.0 930248 bytes Smallest memory usage is local code Encode speed: encode: local code x 8,013 ops/sec ±0.19% (100 runs sampled) encode: @jridgewell/sourcemap-codec 1.4.15 x 7,989 ops/sec ±0.20% (101 runs sampled) encode: sourcemap-codec x 2,472 ops/sec ±0.21% (99 runs sampled) encode: source-map-0.6.1 x 2,200 ops/sec ±0.17% (99 runs sampled) encode: source-map-0.8.0 x 2,220 ops/sec ±0.37% (99 runs sampled) Fastest is encode: local code *** vscode.map - 2141001 segments Decode Memory Usage: local code 198955264 bytes @jridgewell/sourcemap-codec 1.4.15 199175352 bytes sourcemap-codec 199102688 bytes source-map-0.6.1 386323432 bytes source-map-0.8.0 244116432 bytes chrome dev tools 293734280 bytes Smallest memory usage is local code Decode speed: decode: local code x 3.90 ops/sec ±22.21% (15 runs sampled) decode: @jridgewell/sourcemap-codec 1.4.15 x 3.95 ops/sec ±23.53% (15 runs sampled) decode: sourcemap-codec x 3.82 ops/sec ±17.94% (14 runs sampled) decode: source-map-0.6.1 x 0.61 ops/sec ±7.81% (6 runs sampled) decode: source-map-0.8.0 x 9.54 ops/sec ±0.28% (28 runs sampled) chrome dev tools x 2.18 ops/sec ±10.58% (10 runs sampled) Fastest is decode: source-map-0.8.0 Encode Memory Usage: local code 13509880 bytes @jridgewell/sourcemap-codec 1.4.15 13537648 bytes sourcemap-codec 32540104 bytes source-map-0.6.1 127531040 bytes source-map-0.8.0 127535312 bytes Smallest memory usage is local code Encode speed: encode: local code x 20.10 ops/sec ±0.19% (38 runs sampled) encode: @jridgewell/sourcemap-codec 1.4.15 x 20.26 ops/sec ±0.32% (38 runs sampled) encode: sourcemap-codec x 5.44 ops/sec ±1.64% (18 runs sampled) encode: source-map-0.6.1 x 2.30 ops/sec ±4.79% (10 runs sampled) encode: source-map-0.8.0 x 2.46 ops/sec ±6.53% (10 runs sampled) Fastest is encode: @jridgewell/sourcemap-codec 1.4.15 ``` # License MIT sourcemap-codec-1.5.0/package.json000066400000000000000000000043701464330745500170730ustar00rootroot00000000000000{ "name": "@jridgewell/sourcemap-codec", "version": "1.5.0", "description": "Encode/decode sourcemap mappings", "keywords": [ "sourcemap", "vlq" ], "main": "dist/sourcemap-codec.umd.js", "module": "dist/sourcemap-codec.mjs", "types": "dist/types/sourcemap-codec.d.ts", "files": [ "dist" ], "exports": { ".": [ { "types": "./dist/types/sourcemap-codec.d.ts", "browser": "./dist/sourcemap-codec.umd.js", "require": "./dist/sourcemap-codec.umd.js", "import": "./dist/sourcemap-codec.mjs" }, "./dist/sourcemap-codec.umd.js" ], "./package.json": "./package.json" }, "scripts": { "benchmark": "run-s build:rollup benchmark:*", "benchmark:install": "cd benchmark && npm install", "benchmark:only": "node --expose-gc benchmark/index.js", "build": "run-s -n build:*", "build:rollup": "rollup -c rollup.config.js", "build:ts": "tsc --project tsconfig.build.json", "lint": "run-s -n lint:*", "lint:prettier": "npm run test:lint:prettier -- --write", "lint:ts": "npm run test:lint:ts -- --fix", "prebuild": "rm -rf dist", "prepublishOnly": "npm run preversion", "preversion": "run-s test build", "test": "run-s -n test:lint test:only", "test:debug": "mocha --inspect-brk", "test:lint": "run-s -n test:lint:*", "test:lint:prettier": "prettier --check '{src,test}/**/*.ts'", "test:lint:ts": "eslint '{src,test}/**/*.ts'", "test:only": "mocha", "test:coverage": "c8 mocha", "test:watch": "mocha --watch" }, "repository": { "type": "git", "url": "git+https://github.com/jridgewell/sourcemap-codec.git" }, "author": "Rich Harris", "license": "MIT", "devDependencies": { "@rollup/plugin-typescript": "8.3.0", "@types/mocha": "10.0.6", "@types/node": "17.0.15", "@typescript-eslint/eslint-plugin": "5.10.0", "@typescript-eslint/parser": "5.10.0", "benchmark": "2.1.4", "c8": "7.11.2", "eslint": "8.7.0", "eslint-config-prettier": "8.3.0", "mocha": "9.2.0", "npm-run-all": "4.1.5", "prettier": "2.5.1", "rollup": "2.64.0", "source-map": "0.6.1", "source-map-js": "1.0.2", "sourcemap-codec": "1.4.8", "tsx": "4.7.1", "typescript": "4.5.4" } } sourcemap-codec-1.5.0/prettier.config.js000066400000000000000000000001511464330745500202360ustar00rootroot00000000000000module.exports = { endOfLine: 'lf', printWidth: 100, singleQuote: true, trailingComma: 'all', }; sourcemap-codec-1.5.0/rollup.config.js000066400000000000000000000013471464330745500177250ustar00rootroot00000000000000import typescript from '@rollup/plugin-typescript'; function configure(esm) { return { input: 'src/sourcemap-codec.ts', output: esm ? { format: 'es', dir: 'dist', entryFileNames: '[name].mjs', sourcemap: true, exports: 'named', } : { format: 'umd', name: 'sourcemapCodec', dir: 'dist', entryFileNames: '[name].umd.js', sourcemap: true, exports: 'named', }, plugins: [ typescript({ tsconfig: './tsconfig.build.json', tslib: './throw-when-needed', }), ], watch: { include: 'src/**', }, }; } export default [configure(false), configure(true)]; sourcemap-codec-1.5.0/src/000077500000000000000000000000001464330745500153705ustar00rootroot00000000000000sourcemap-codec-1.5.0/src/scopes.ts000066400000000000000000000227611464330745500172440ustar00rootroot00000000000000import { StringReader, StringWriter } from './strings'; import { comma, decodeInteger, encodeInteger, hasMoreVlq, semicolon } from './vlq'; const EMPTY: any[] = []; type Line = number; type Column = number; type Kind = number; type Name = number; type Var = number; type SourcesIndex = number; type ScopesIndex = number; type Mix = (A & O) | (B & O); export type OriginalScope = Mix< [Line, Column, Line, Column, Kind], [Line, Column, Line, Column, Kind, Name], { vars: Var[] } >; export type GeneratedRange = Mix< [Line, Column, Line, Column], [Line, Column, Line, Column, SourcesIndex, ScopesIndex], { callsite: CallSite | null; bindings: Binding[]; isScope: boolean; } >; export type CallSite = [SourcesIndex, Line, Column]; type Binding = BindingExpressionRange[]; export type BindingExpressionRange = [Name] | [Name, Line, Column]; export function decodeOriginalScopes(input: string): OriginalScope[] { const { length } = input; const reader = new StringReader(input); const scopes: OriginalScope[] = []; const stack: OriginalScope[] = []; let line = 0; for (; reader.pos < length; reader.pos++) { line = decodeInteger(reader, line); const column = decodeInteger(reader, 0); if (!hasMoreVlq(reader, length)) { const last = stack.pop()!; last[2] = line; last[3] = column; continue; } const kind = decodeInteger(reader, 0); const fields = decodeInteger(reader, 0); const hasName = fields & 0b0001; const scope: OriginalScope = ( hasName ? [line, column, 0, 0, kind, decodeInteger(reader, 0)] : [line, column, 0, 0, kind] ) as OriginalScope; let vars: Var[] = EMPTY; if (hasMoreVlq(reader, length)) { vars = []; do { const varsIndex = decodeInteger(reader, 0); vars.push(varsIndex); } while (hasMoreVlq(reader, length)); } scope.vars = vars; scopes.push(scope); stack.push(scope); } return scopes; } export function encodeOriginalScopes(scopes: OriginalScope[]): string { const writer = new StringWriter(); for (let i = 0; i < scopes.length; ) { i = _encodeOriginalScopes(scopes, i, writer, [0]); } return writer.flush(); } function _encodeOriginalScopes( scopes: OriginalScope[], index: number, writer: StringWriter, state: [ number, // GenColumn ], ): number { const scope = scopes[index]; const { 0: startLine, 1: startColumn, 2: endLine, 3: endColumn, 4: kind, vars } = scope; if (index > 0) writer.write(comma); state[0] = encodeInteger(writer, startLine, state[0]); encodeInteger(writer, startColumn, 0); encodeInteger(writer, kind, 0); const fields = scope.length === 6 ? 0b0001 : 0; encodeInteger(writer, fields, 0); if (scope.length === 6) encodeInteger(writer, scope[5], 0); for (const v of vars) { encodeInteger(writer, v, 0); } for (index++; index < scopes.length; ) { const next = scopes[index]; const { 0: l, 1: c } = next; if (l > endLine || (l === endLine && c >= endColumn)) { break; } index = _encodeOriginalScopes(scopes, index, writer, state); } writer.write(comma); state[0] = encodeInteger(writer, endLine, state[0]); encodeInteger(writer, endColumn, 0); return index; } export function decodeGeneratedRanges(input: string): GeneratedRange[] { const { length } = input; const reader = new StringReader(input); const ranges: GeneratedRange[] = []; const stack: GeneratedRange[] = []; let genLine = 0; let definitionSourcesIndex = 0; let definitionScopeIndex = 0; let callsiteSourcesIndex = 0; let callsiteLine = 0; let callsiteColumn = 0; let bindingLine = 0; let bindingColumn = 0; do { const semi = reader.indexOf(';'); let genColumn = 0; for (; reader.pos < semi; reader.pos++) { genColumn = decodeInteger(reader, genColumn); if (!hasMoreVlq(reader, semi)) { const last = stack.pop()!; last[2] = genLine; last[3] = genColumn; continue; } const fields = decodeInteger(reader, 0); const hasDefinition = fields & 0b0001; const hasCallsite = fields & 0b0010; const hasScope = fields & 0b0100; let callsite: CallSite | null = null; let bindings: Binding[] = EMPTY; let range: GeneratedRange; if (hasDefinition) { const defSourcesIndex = decodeInteger(reader, definitionSourcesIndex); definitionScopeIndex = decodeInteger( reader, definitionSourcesIndex === defSourcesIndex ? definitionScopeIndex : 0, ); definitionSourcesIndex = defSourcesIndex; range = [genLine, genColumn, 0, 0, defSourcesIndex, definitionScopeIndex] as GeneratedRange; } else { range = [genLine, genColumn, 0, 0] as GeneratedRange; } range.isScope = !!hasScope; if (hasCallsite) { const prevCsi = callsiteSourcesIndex; const prevLine = callsiteLine; callsiteSourcesIndex = decodeInteger(reader, callsiteSourcesIndex); const sameSource = prevCsi === callsiteSourcesIndex; callsiteLine = decodeInteger(reader, sameSource ? callsiteLine : 0); callsiteColumn = decodeInteger( reader, sameSource && prevLine === callsiteLine ? callsiteColumn : 0, ); callsite = [callsiteSourcesIndex, callsiteLine, callsiteColumn]; } range.callsite = callsite; if (hasMoreVlq(reader, semi)) { bindings = []; do { bindingLine = genLine; bindingColumn = genColumn; const expressionsCount = decodeInteger(reader, 0); let expressionRanges: BindingExpressionRange[]; if (expressionsCount < -1) { expressionRanges = [[decodeInteger(reader, 0)]]; for (let i = -1; i > expressionsCount; i--) { const prevBl = bindingLine; bindingLine = decodeInteger(reader, bindingLine); bindingColumn = decodeInteger(reader, bindingLine === prevBl ? bindingColumn : 0); const expression = decodeInteger(reader, 0); expressionRanges.push([expression, bindingLine, bindingColumn]); } } else { expressionRanges = [[expressionsCount]]; } bindings.push(expressionRanges); } while (hasMoreVlq(reader, semi)); } range.bindings = bindings; ranges.push(range); stack.push(range); } genLine++; reader.pos = semi + 1; } while (reader.pos < length); return ranges; } export function encodeGeneratedRanges(ranges: GeneratedRange[]): string { if (ranges.length === 0) return ''; const writer = new StringWriter(); for (let i = 0; i < ranges.length; ) { i = _encodeGeneratedRanges(ranges, i, writer, [0, 0, 0, 0, 0, 0, 0]); } return writer.flush(); } function _encodeGeneratedRanges( ranges: GeneratedRange[], index: number, writer: StringWriter, state: [ number, // GenLine number, // GenColumn number, // DefSourcesIndex number, // DefScopesIndex number, // CallSourcesIndex number, // CallLine number, // CallColumn ], ): number { const range = ranges[index]; const { 0: startLine, 1: startColumn, 2: endLine, 3: endColumn, isScope, callsite, bindings, } = range; if (state[0] < startLine) { catchupLine(writer, state[0], startLine); state[0] = startLine; state[1] = 0; } else if (index > 0) { writer.write(comma); } state[1] = encodeInteger(writer, range[1], state[1]); const fields = (range.length === 6 ? 0b0001 : 0) | (callsite ? 0b0010 : 0) | (isScope ? 0b0100 : 0); encodeInteger(writer, fields, 0); if (range.length === 6) { const { 4: sourcesIndex, 5: scopesIndex } = range; if (sourcesIndex !== state[2]) { state[3] = 0; } state[2] = encodeInteger(writer, sourcesIndex, state[2]); state[3] = encodeInteger(writer, scopesIndex, state[3]); } if (callsite) { const { 0: sourcesIndex, 1: callLine, 2: callColumn } = range.callsite!; if (sourcesIndex !== state[4]) { state[5] = 0; state[6] = 0; } else if (callLine !== state[5]) { state[6] = 0; } state[4] = encodeInteger(writer, sourcesIndex, state[4]); state[5] = encodeInteger(writer, callLine, state[5]); state[6] = encodeInteger(writer, callColumn, state[6]); } if (bindings) { for (const binding of bindings) { if (binding.length > 1) encodeInteger(writer, -binding.length, 0); const expression = binding[0][0]; encodeInteger(writer, expression, 0); let bindingStartLine = startLine; let bindingStartColumn = startColumn; for (let i = 1; i < binding.length; i++) { const expRange = binding[i]; bindingStartLine = encodeInteger(writer, expRange[1]!, bindingStartLine); bindingStartColumn = encodeInteger(writer, expRange[2]!, bindingStartColumn); encodeInteger(writer, expRange[0]!, 0); } } } for (index++; index < ranges.length; ) { const next = ranges[index]; const { 0: l, 1: c } = next; if (l > endLine || (l === endLine && c >= endColumn)) { break; } index = _encodeGeneratedRanges(ranges, index, writer, state); } if (state[0] < endLine) { catchupLine(writer, state[0], endLine); state[0] = endLine; state[1] = 0; } else { writer.write(comma); } state[1] = encodeInteger(writer, endColumn, state[1]); return index; } function catchupLine(writer: StringWriter, lastLine: number, line: number) { do { writer.write(semicolon); } while (++lastLine < line); } sourcemap-codec-1.5.0/src/sourcemap-codec.ts000066400000000000000000000062031464330745500210120ustar00rootroot00000000000000import { comma, decodeInteger, encodeInteger, hasMoreVlq, semicolon } from './vlq'; import { StringWriter, StringReader } from './strings'; export { decodeOriginalScopes, encodeOriginalScopes, decodeGeneratedRanges, encodeGeneratedRanges, } from './scopes'; export type { OriginalScope, GeneratedRange, CallSite, BindingExpressionRange } from './scopes'; export type SourceMapSegment = | [number] | [number, number, number, number] | [number, number, number, number, number]; export type SourceMapLine = SourceMapSegment[]; export type SourceMapMappings = SourceMapLine[]; export function decode(mappings: string): SourceMapMappings { const { length } = mappings; const reader = new StringReader(mappings); const decoded: SourceMapMappings = []; let genColumn = 0; let sourcesIndex = 0; let sourceLine = 0; let sourceColumn = 0; let namesIndex = 0; do { const semi = reader.indexOf(';'); const line: SourceMapLine = []; let sorted = true; let lastCol = 0; genColumn = 0; while (reader.pos < semi) { let seg: SourceMapSegment; genColumn = decodeInteger(reader, genColumn); if (genColumn < lastCol) sorted = false; lastCol = genColumn; if (hasMoreVlq(reader, semi)) { sourcesIndex = decodeInteger(reader, sourcesIndex); sourceLine = decodeInteger(reader, sourceLine); sourceColumn = decodeInteger(reader, sourceColumn); if (hasMoreVlq(reader, semi)) { namesIndex = decodeInteger(reader, namesIndex); seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]; } else { seg = [genColumn, sourcesIndex, sourceLine, sourceColumn]; } } else { seg = [genColumn]; } line.push(seg); reader.pos++; } if (!sorted) sort(line); decoded.push(line); reader.pos = semi + 1; } while (reader.pos <= length); return decoded; } function sort(line: SourceMapSegment[]) { line.sort(sortComparator); } function sortComparator(a: SourceMapSegment, b: SourceMapSegment): number { return a[0] - b[0]; } export function encode(decoded: SourceMapMappings): string; export function encode(decoded: Readonly): string; export function encode(decoded: Readonly): string { const writer = new StringWriter(); let sourcesIndex = 0; let sourceLine = 0; let sourceColumn = 0; let namesIndex = 0; for (let i = 0; i < decoded.length; i++) { const line = decoded[i]; if (i > 0) writer.write(semicolon); if (line.length === 0) continue; let genColumn = 0; for (let j = 0; j < line.length; j++) { const segment = line[j]; if (j > 0) writer.write(comma); genColumn = encodeInteger(writer, segment[0], genColumn); if (segment.length === 1) continue; sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex); sourceLine = encodeInteger(writer, segment[2], sourceLine); sourceColumn = encodeInteger(writer, segment[3], sourceColumn); if (segment.length === 4) continue; namesIndex = encodeInteger(writer, segment[4], namesIndex); } } return writer.flush(); } sourcemap-codec-1.5.0/src/strings.ts000066400000000000000000000027011464330745500174310ustar00rootroot00000000000000const bufLength = 1024 * 16; // Provide a fallback for older environments. const td = typeof TextDecoder !== 'undefined' ? /* #__PURE__ */ new TextDecoder() : typeof Buffer !== 'undefined' ? { decode(buf: Uint8Array): string { const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength); return out.toString(); }, } : { decode(buf: Uint8Array): string { let out = ''; for (let i = 0; i < buf.length; i++) { out += String.fromCharCode(buf[i]); } return out; }, }; export class StringWriter { pos = 0; private out = ''; private buffer = new Uint8Array(bufLength); write(v: number): void { const { buffer } = this; buffer[this.pos++] = v; if (this.pos === bufLength) { this.out += td.decode(buffer); this.pos = 0; } } flush(): string { const { buffer, out, pos } = this; return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out; } } export class StringReader { pos = 0; private declare buffer: string; constructor(buffer: string) { this.buffer = buffer; } next(): number { return this.buffer.charCodeAt(this.pos++); } peek(): number { return this.buffer.charCodeAt(this.pos); } indexOf(char: string): number { const { buffer, pos } = this; const idx = buffer.indexOf(char, pos); return idx === -1 ? buffer.length : idx; } } sourcemap-codec-1.5.0/src/vlq.ts000066400000000000000000000025531464330745500165470ustar00rootroot00000000000000import type { StringReader, StringWriter } from './strings'; export const comma = ','.charCodeAt(0); export const semicolon = ';'.charCodeAt(0); const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; const intToChar = new Uint8Array(64); // 64 possible chars. const charToInt = new Uint8Array(128); // z is 122 in ASCII for (let i = 0; i < chars.length; i++) { const c = chars.charCodeAt(i); intToChar[i] = c; charToInt[c] = i; } export function decodeInteger(reader: StringReader, relative: number): number { let value = 0; let shift = 0; let integer = 0; do { const c = reader.next(); integer = charToInt[c]; value |= (integer & 31) << shift; shift += 5; } while (integer & 32); const shouldNegate = value & 1; value >>>= 1; if (shouldNegate) { value = -0x80000000 | -value; } return relative + value; } export function encodeInteger(builder: StringWriter, num: number, relative: number): number { let delta = num - relative; delta = delta < 0 ? (-delta << 1) | 1 : delta << 1; do { let clamped = delta & 0b011111; delta >>>= 5; if (delta > 0) clamped |= 0b100000; builder.write(intToChar[clamped]); } while (delta > 0); return num; } export function hasMoreVlq(reader: StringReader, max: number) { if (reader.pos >= max) return false; return reader.peek() !== comma; } sourcemap-codec-1.5.0/test/000077500000000000000000000000001464330745500155605ustar00rootroot00000000000000sourcemap-codec-1.5.0/test/codec.test.ts000066400000000000000000000120341464330745500201630ustar00rootroot00000000000000/* eslint-env node, mocha */ import { encode, decode, type SourceMapMappings } from '../src/sourcemap-codec'; import { strict as assert } from 'assert'; import * as fs from 'fs'; import * as path from 'path'; describe('sourcemap-codec', () => { // TODO more tests let tests: { encoded: string; decoded: SourceMapMappings; only?: true }[] = [ { encoded: 'AAAA', decoded: [[[0, 0, 0, 0]]], }, { encoded: ';;;', decoded: [[], [], [], []], }, { encoded: 'A,AAAC;;AACDE;', decoded: [[[0], [0, 0, 0, 1]], [], [[0, 0, 1, 0, 2]], []], }, { encoded: ';;;;EAEEA,EAAE,EAAC,CAAE;ECQY,UACC', decoded: [ [], [], [], [], [ [2, 0, 2, 2, 0], [4, 0, 2, 4], [6, 0, 2, 5], [7, 0, 2, 7], ], [ [2, 1, 10, 19], [12, 1, 11, 20], ], ], }, { encoded: 'AAAA,aAEA,IAAIA,eAAiB,oCAAoCC,cACzD,SAASC,IACRC,OAAOC,MAAOJ,eAAgB,GAG/B,IAAIK,iBAAmB,sBAAsBJ,cAC7C,SAASK,IACRH,OAAOC,MAAOC,iBAAkB,GAGjCH,IACAI', decoded: [ [ [0, 0, 0, 0], [13, 0, 2, 0], [17, 0, 2, 4, 0], [32, 0, 2, 21], [68, 0, 2, 57, 1], [82, 0, 3, 0], [91, 0, 3, 9, 2], [95, 0, 4, 1, 3], [102, 0, 4, 8, 4], [108, 0, 4, 15, 0], [123, 0, 4, 31], [126, 0, 7, 0], [130, 0, 7, 4, 5], [147, 0, 7, 23], [169, 0, 7, 45, 1], [183, 0, 8, 0], [192, 0, 8, 9, 6], [196, 0, 9, 1, 3], [203, 0, 9, 8, 4], [209, 0, 9, 15, 5], [226, 0, 9, 33], [229, 0, 12, 0, 2], [233, 0, 13, 0, 6], ], ], }, { encoded: 'CAAC,SAAUA,EAAQC,GACC,iBAAZC,SAA0C,oBAAXC,OAAyBF,IAC7C,mBAAXG,QAAyBA,OAAOC,IAAMD,OAAOH,GACnDA,IAHF,CAIEK,EAAM,WAAe,aAEtB,IAAIC,EAAiB,oCAAoCC,cAKzD,IAAIC,EAAmB,sBAAsBD,cAH5CE,OAAOC,MAAOJ,EAAgB,GAK9BG,OAAOC,MAAOF,EAAkB', decoded: [ [ [1, 0, 0, 1], [10, 0, 0, 11, 0], [12, 0, 0, 19, 1], [15, 0, 1, 20], [32, 0, 1, 8, 2], [41, 0, 1, 50], [61, 0, 1, 39, 3], [68, 0, 1, 64, 1], [72, 0, 2, 19], [91, 0, 2, 8, 4], [99, 0, 2, 33, 4], [106, 0, 2, 40, 5], [110, 0, 2, 46, 4], [117, 0, 2, 53, 1], [120, 0, 3, 2, 1], [124, 0, 0, 0], [125, 0, 4, 2, 6], [127, 0, 4, 8], [138, 0, 4, 23], [151, 0, 6, 1], [155, 0, 6, 5, 7], [157, 0, 6, 22], [193, 0, 6, 58, 8], [207, 0, 11, 1], [211, 0, 11, 5, 9], [213, 0, 11, 24], [235, 0, 11, 46, 8], [249, 0, 8, 2, 10], [256, 0, 8, 9, 11], [262, 0, 8, 16, 7], [264, 0, 8, 32], [267, 0, 13, 2, 10], [274, 0, 13, 9, 11], [280, 0, 13, 16, 9], [282, 0, 13, 34], ], ], }, { // Make sure Int16 isn't being used encoded: 'gw+BAAAA,w+BAAAA,w+BAAAA,w+BAAAA', decoded: [ [ [32000, 0, 0, 0, 0], [33000, 0, 0, 0, 0], [34000, 0, 0, 0, 0], [35000, 0, 0, 0, 0], ], ], }, { // Handle largest 32bit int encoded: '+/////D', decoded: [[[2147483647]]], }, { // Handle smallest 32bit int encoded: 'AAA+/////D,AAAE,AAAB', decoded: [ [ [0, 0, 0, 2147483647], [0, 0, 0, 2147483649], [0, 0, 0, 1], ], ], }, ]; const filtered = tests.filter((test) => { return test.only; }); tests = filtered.length ? filtered : tests; describe('decode()', () => { tests.forEach((test, i) => { it('decodes sample ' + i, () => { assert.deepEqual(decode(test.encoded), test.decoded); }); }); it('sorts during decoding', () => { const mappings: SourceMapMappings = [ [[1], [2], [3]], [[1], [3], [2]], [[2], [1], [3]], [[2], [3], [1]], [[3], [1], [2]], [[3], [2], [1]], ]; mappings.sort(() => (Math.random() < 0.5 ? 1 : -1)); const decoded = decode(encode(mappings)); const expected = mappings.map(() => { return [[1], [2], [3]]; }); assert.deepEqual(decoded, expected); }); }); describe('encode()', () => { tests.forEach((test, i) => { it('encodes sample ' + i, () => { assert.deepEqual(encode(test.decoded), test.encoded); }); }); }); describe('real world', () => { const dir = path.join(__dirname, '..', 'benchmark'); const files = fs.readdirSync(dir); files.forEach((file) => { if (path.extname(file) !== '.map') return; it(file, function () { this.timeout(5000); const { mappings } = JSON.parse(fs.readFileSync(path.join(dir, file), 'utf8')); assert.deepEqual(encode(decode(mappings)), mappings); }); }); }); }); sourcemap-codec-1.5.0/test/scopes.test.ts000066400000000000000000000174721464330745500204150ustar00rootroot00000000000000/* eslint-env node, mocha */ import { decodeGeneratedRanges, decodeOriginalScopes, encodeGeneratedRanges, encodeOriginalScopes, } from '../src/scopes'; import { strict as assert } from 'assert'; import type { GeneratedRange, OriginalScope } from '../src/scopes'; describe('scopes proposal', () => { type Tuple = Pick>; function init( init: Tuple, data: Pick>, ): T { return Object.assign(init, data) as T; } describe('original scopes', () => { let tests: { encoded: string[]; decoded: OriginalScope[][]; only?: true }[] = [ { encoded: ['AACAAC,AAECAE,EC,CAECCE,GC,E2C'], decoded: [ [ init([0, 0, 8, 43, 1], { vars: [0, 1] }), init([0, 0, 2, 1, 2, 0], { vars: [2] }), init([3, 0, 6, 1, 2, 1], { vars: [2] }), ], ], }, { encoded: ['AACAAC,GgBECEG,EG,CC', 'AACACIK,EkBECIG,EC,EkBECKG,EC,GY'], decoded: [ [init([0, 0, 6, 1, 1], { vars: [0, 1] }), init([3, 16, 5, 3, 2, 2], { vars: [3] })], [ init([0, 0, 11, 12, 1], { vars: [1, 4, 5] }), init([2, 18, 4, 1, 2, 4], { vars: [3] }), init([6, 18, 8, 1, 2, 5], { vars: [3] }), ], ], }, { encoded: ['AACAAC,GmB', 'AACAEA,CqBECAG,EC,AC'], decoded: [ [init([0, 0, 3, 19, 1], { vars: [0, 1] })], [init([0, 0, 3, 1, 1], { vars: [2, 0] }), init([1, 21, 3, 1, 2, 0], { vars: [3] })], ], }, { encoded: ['AACAACEG,EgBECCI,EC,EkBECEI,EC,EkBECGIK,GkBIA,EG,CC,GY'], decoded: [ [ init([0, 0, 19, 12, 1], { vars: [0, 1, 2, 3] }), init([2, 16, 4, 1, 2, 1], { vars: [4] }), init([6, 18, 8, 1, 2, 2], { vars: [4] }), init([10, 18, 16, 1, 2, 3], { vars: [4, 5] }), init([13, 18, 15, 3, 4], { vars: [] }), ], ], }, { encoded: ['AACAAC,AkBECAE,EC,IO'], decoded: [ [init([0, 0, 6, 7, 1], { vars: [0, 1] }), init([0, 18, 2, 1, 2, 0], { vars: [2] })], ], }, { encoded: ['AACA,AAIAA,GEIAA,GG,EC,AC'], decoded: [ [ init([0, 0, 8, 1, 1], { vars: [] }), init([0, 0, 8, 1, 4], { vars: [0] }), init([3, 2, 6, 3, 4], { vars: [0] }), ], ], }, { encoded: ['AACAA,AAECACEG,CEECCIK,GG,GC,CS'], decoded: [ [ init([0, 0, 8, 9, 1], { vars: [0] }), init([0, 0, 7, 1, 2, 0], { vars: [1, 2, 3] }), init([1, 2, 4, 3, 2, 1], { vars: [4, 5] }), ], ], }, ]; const filtered = tests.filter((test) => { return test.only; }); tests = filtered.length ? filtered : tests; describe('decodeOriginalScopes()', () => { tests.forEach((test, i) => { test.encoded.forEach((encoded, j) => { it(`decodes sample ${i}, source ${j}`, () => { assert.deepEqual(decodeOriginalScopes(encoded), test.decoded[j]); }); }); }); }); describe('encodeOriginalScopes()', () => { tests.forEach((test, i) => { test.decoded.forEach((decoded, j) => { it(`encodes sample ${i}, source ${j}`, () => { assert.deepEqual(encodeOriginalScopes(decoded), test.encoded[j]); }); }); }); }); }); describe('generated ranges', () => { let tests: { encoded: string; decoded: GeneratedRange[]; only?: true }[] = [ { encoded: 'AKAADD,AGAEAOAG,AGADAHEI,2B;8B;2C', decoded: [ init([0, 0, 2, 43, 0, 0], { isScope: true, callsite: null, bindings: [[[-1]], [[-1]]] }), init([0, 0, 1, 30, 0, 2], { isScope: false, callsite: [0, 7, 0], bindings: [[[3]]] }), init([0, 0, 0, 27, 0, 1], { isScope: false, callsite: [0, 4, 2], bindings: [[[4]]] }), ], }, { encoded: 'AKCADDD,ACDAMD,AGCECUAO,AGADAHEO,AGDCAJEO,gB,A,A,A,ACADMD,AGCEAQAQ,AGADAJEQ,AGDCAJEQ,kB,A,A,A,A', decoded: [ init([0, 0, 0, 34, 1, 0], { isScope: true, callsite: null, bindings: [[[-1]], [[-1]], [[-1]]], }), init([0, 0, 0, 16, 0, 0], { isScope: false, callsite: null, bindings: [[[6]], [[-1]]] }), init([0, 0, 0, 16, 1, 2], { isScope: false, callsite: [1, 10, 0], bindings: [[[7]]] }), init([0, 0, 0, 16, 1, 1], { isScope: false, callsite: [1, 7, 2], bindings: [[[7]]] }), init([0, 0, 0, 16, 0, 1], { isScope: false, callsite: [1, 3, 2], bindings: [[[7]]] }), init([0, 16, 0, 34, 0, 0], { isScope: false, callsite: null, bindings: [[[6]], [[-1]]] }), init([0, 16, 0, 34, 1, 2], { isScope: false, callsite: [1, 11, 0], bindings: [[[8]]] }), init([0, 16, 0, 34, 1, 1], { isScope: false, callsite: [1, 7, 2], bindings: [[[8]]] }), init([0, 16, 0, 34, 0, 1], { isScope: false, callsite: [1, 3, 2], bindings: [[[8]]] }), ], }, { encoded: 'AKAADI,ACCAKD;;AGACAEAM;;qB;iB,A', decoded: [ init([0, 0, 5, 17, 0, 0], { isScope: true, callsite: null, bindings: [[[-1]], [[4]]] }), init([0, 0, 5, 17, 1, 0], { isScope: false, callsite: null, bindings: [[[5]], [[-1]]] }), init([2, 0, 4, 21, 1, 1], { isScope: false, callsite: [0, 2, 0], bindings: [[[6]]] }), ], }, { encoded: 'AKAAMDDD,aKAGOQ,yDGADAcIO,AGADAPEO,c,A,C,c', decoded: [ init([0, 0, 0, 99, 0, 0], { isScope: true, callsite: null, bindings: [[[6]], [[-1]], [[-1]], [[-1]]], }), init([0, 13, 0, 85, 0, 3], { isScope: true, callsite: null, bindings: [[[7]], [[8]]] }), init([0, 70, 0, 84, 0, 2], { isScope: false, callsite: [0, 14, 4], bindings: [[[7]]] }), init([0, 70, 0, 84, 0, 1], { isScope: false, callsite: [0, 7, 2], bindings: [[[7]]] }), ], }, { encoded: 'AKAADFGCAI,AGACAICG,mB;AGAAAEAI,mB,A', decoded: [ init([0, 0, 1, 19, 0, 0], { isScope: true, callsite: null, bindings: [[[-1]], [[3], [4, 1, 0]]], }), init([0, 0, 0, 19, 0, 1], { isScope: false, callsite: [0, 4, 1], bindings: [[[3]]] }), init([1, 0, 1, 19, 0, 1], { isScope: false, callsite: [0, 6, 0], bindings: [[[4]]] }), ], }, { encoded: 'AKAA,AKACC;;;ECACE;kB;;C,A', decoded: [ init([0, 0, 6, 1, 0, 0], { isScope: true, callsite: null, bindings: [] }), init([0, 0, 6, 1, 0, 1], { isScope: true, callsite: null, bindings: [[[1]]] }), init([3, 2, 4, 18, 0, 2], { isScope: false, callsite: null, bindings: [[[2]]] }), ], }, { encoded: 'AKAAM,AKACOQS;EKACQS;;;G;;;C;K', decoded: [ init([0, 0, 8, 5, 0, 0], { isScope: true, callsite: null, bindings: [[[6]]] }), init([0, 0, 7, 1, 0, 1], { isScope: true, callsite: null, bindings: [[[7]], [[8]], [[9]]], }), init([1, 2, 4, 3, 0, 2], { isScope: true, callsite: null, bindings: [[[8]], [[9]]] }), ], }, ]; const filtered = tests.filter((test) => { return test.only; }); tests = filtered.length ? filtered : tests; describe('decodeGeneratedRanges()', () => { tests.forEach((test, i) => { it('decodes sample ' + i, () => { assert.deepEqual(decodeGeneratedRanges(test.encoded), test.decoded); }); }); }); describe('encodeGeneratedRanges()', () => { tests.forEach((test, i) => { it('encodes sample ' + i, () => { assert.deepEqual(encodeGeneratedRanges(test.decoded), test.encoded); }); }); }); }); }); sourcemap-codec-1.5.0/tsconfig.build.json000066400000000000000000000002231464330745500204030ustar00rootroot00000000000000{ "extends": "./tsconfig.json", "compilerOptions": { "emitDeclarationOnly": true, "rootDir": "src" }, "include": [ "src" ] } sourcemap-codec-1.5.0/tsconfig.json000066400000000000000000000006651464330745500173170ustar00rootroot00000000000000{ "compilerOptions": { "moduleResolution": "node", "esModuleInterop": true, "target": "es2015", "module": "es2015", "lib": ["es2015", "dom"], "strict": true, "sourceMap": true, "inlineSources": true, "declaration": true, "allowSyntheticDefaultImports": true, "declarationDir": "dist/types", "typeRoots": ["node_modules/@types"] }, "exclude": ["dist"], "include": ["src", "test"] }