@remotex-labs/xmap 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.md +143 -0
- package/dist/components/base64.component.d.ts +26 -0
- package/dist/components/formatter.component.d.ts +66 -0
- package/dist/components/highlighter.component.d.ts +186 -0
- package/dist/components/interfaces/formatter.interface.d.ts +42 -0
- package/dist/components/interfaces/highlighter.interface.d.ts +48 -0
- package/dist/components/interfaces/parse.interface.d.ts +31 -0
- package/dist/components/parser.component.d.ts +11 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +7 -0
- package/dist/services/interfaces/source.interface.d.ts +112 -0
- package/dist/services/source.service.d.ts +147 -0
- package/package.json +64 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import will remove at compile time
|
|
3
|
+
*/
|
|
4
|
+
import type { PositionInterface, SourceMapInterface, SourceOptionsInterface, PositionSourceInterface } from './interfaces/source.interface';
|
|
5
|
+
/**
|
|
6
|
+
* Imports
|
|
7
|
+
*/
|
|
8
|
+
import { Bias } from './interfaces/source.interface';
|
|
9
|
+
/**
|
|
10
|
+
* A service for validating and processing source maps.
|
|
11
|
+
*/
|
|
12
|
+
export declare class SourceService {
|
|
13
|
+
/**
|
|
14
|
+
* A list of symbol names used by the “mappings” entry.
|
|
15
|
+
*/
|
|
16
|
+
private readonly names;
|
|
17
|
+
/**
|
|
18
|
+
* An array of source file paths.
|
|
19
|
+
*/
|
|
20
|
+
private readonly sources;
|
|
21
|
+
/**
|
|
22
|
+
* A string of base64 VLQ-encoded mappings.
|
|
23
|
+
*/
|
|
24
|
+
private readonly mappings;
|
|
25
|
+
/**
|
|
26
|
+
* An array of source files contents.
|
|
27
|
+
*/
|
|
28
|
+
private readonly sourcesContent;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new SourceService instance.
|
|
31
|
+
*
|
|
32
|
+
* @param source - The source map object to be validated.
|
|
33
|
+
* @throws Error If any required key is missing from the source map.
|
|
34
|
+
*/
|
|
35
|
+
constructor(source: SourceMapInterface);
|
|
36
|
+
/**
|
|
37
|
+
* Returns a plain object representation of the source map data.
|
|
38
|
+
*
|
|
39
|
+
* This method creates a new object containing essential source map properties:
|
|
40
|
+
* - `version`: The version of the source map (typically 3).
|
|
41
|
+
* - `names`: An array of function or variable names from the original source code.
|
|
42
|
+
* - `sources`: An array of source file names referenced in the mappings.
|
|
43
|
+
* - `mappings`: A string representation of the encoded source map mappings. (Generated by `encodeMappings`)
|
|
44
|
+
* - `sourcesContent`: An optional array containing the content of the source files. (May not be present in all source maps)
|
|
45
|
+
*
|
|
46
|
+
* @returns A plain object representing the source map data.
|
|
47
|
+
*/
|
|
48
|
+
getMapObject(): SourceMapInterface;
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves source code information for a given line and column in the generated code.
|
|
51
|
+
*
|
|
52
|
+
* @param line - The line number in the generated code.
|
|
53
|
+
* @param column - The column number in the generated code.
|
|
54
|
+
* @param options - Optional configuration for retrieving source information.
|
|
55
|
+
* linesBefore (default: 3) - Number of lines before the matching source line to include.
|
|
56
|
+
* linesAfter (default: 4) - Number of lines after the matching source line to include.
|
|
57
|
+
* includeSourceContent (default: false) - Flag to include the relevant source code snippet.
|
|
58
|
+
* @returns An object containing source location information (line, column, name, source)
|
|
59
|
+
* or including source code (code) if the includeSourceContent flag is set.
|
|
60
|
+
* Returns null if no matching mapping is found.
|
|
61
|
+
*/
|
|
62
|
+
getSourcePosition(line: number, column: number, options?: SourceOptionsInterface): PositionSourceInterface | null;
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves the position information in the original source code for a given line and column in the generated code.
|
|
65
|
+
*
|
|
66
|
+
* @param line - The line number in the generated code.
|
|
67
|
+
* @param column - The column number in the generated code.
|
|
68
|
+
* @param bias - An optional bias value specifying how to handle cases where only the line number matches. Defaults to Bias.LOWER_BOUND.
|
|
69
|
+
* Bias.LOWER_BOUND: If the line number matches but the column is less, return the closest mapping with a lower column.
|
|
70
|
+
* Bias.UPPER_BOUND: If the line number matches but the column is greater, return the closest mapping with a higher column.
|
|
71
|
+
* Bias.BOUND: If the line number matches and the column doesn't, return null (default behavior).
|
|
72
|
+
* @returns A PositionInterface object representing the position in the original source code, or null if no matching position is found.
|
|
73
|
+
*/
|
|
74
|
+
getPosition(line: number, column: number, bias?: Bias): PositionInterface | null;
|
|
75
|
+
/**
|
|
76
|
+
* Merges multiple source maps into this source map object.
|
|
77
|
+
* The order of the provided source maps must match the order in which the corresponding source files were concatenated.
|
|
78
|
+
*
|
|
79
|
+
* @param maps - An array of `SourceService` instances representing the source maps to be merged.
|
|
80
|
+
* @throws Error - If no source maps are provided for concatenation.
|
|
81
|
+
*/
|
|
82
|
+
concat(...maps: Array<SourceMapInterface>): void;
|
|
83
|
+
/**
|
|
84
|
+
* Converts the source map object to a base64 encoded string representation.
|
|
85
|
+
*
|
|
86
|
+
* This method performs the following steps:
|
|
87
|
+
* 1. Creates a plain object representation of the source map using `getMapObject`.
|
|
88
|
+
* 2. Convert the plain object to a JSON string using `JSON.stringify`.
|
|
89
|
+
* 3. Encodes the JSON string using the `encode` function (assumed to be a base64 encoding function).
|
|
90
|
+
*
|
|
91
|
+
* @returns A string representing the source map.
|
|
92
|
+
*/
|
|
93
|
+
toString(): string;
|
|
94
|
+
/**
|
|
95
|
+
* Validates the provided source map object.
|
|
96
|
+
*
|
|
97
|
+
* This private method throws an error if any of the required keys are missing from the source map.
|
|
98
|
+
*
|
|
99
|
+
* @private
|
|
100
|
+
* @param input - The source map object to be validated.
|
|
101
|
+
* @throws Error If any required key is missing from the source map.
|
|
102
|
+
*/
|
|
103
|
+
private validateSourceMap;
|
|
104
|
+
/**
|
|
105
|
+
* Decodes and processes the encoded mappings.
|
|
106
|
+
*
|
|
107
|
+
* @param encodedMappings - The source map object to be decoded.
|
|
108
|
+
* @param thresholdSegment
|
|
109
|
+
*/
|
|
110
|
+
private decodeMappings;
|
|
111
|
+
/**
|
|
112
|
+
* Processes a decoded segment and updates the mappings.
|
|
113
|
+
*
|
|
114
|
+
* @param shift - The current state of the mapping information.
|
|
115
|
+
* @param decodedSegment - The decoded VLQ segment.
|
|
116
|
+
* @param generatedLine - The current line index in the generated code.
|
|
117
|
+
*/
|
|
118
|
+
private decodedSegment;
|
|
119
|
+
/**
|
|
120
|
+
* Encodes the mappings into a VLQ string.
|
|
121
|
+
*
|
|
122
|
+
* @param mappings - An array of MappingInterface objects to encode.
|
|
123
|
+
* @returns A VLQ-encoded string representing the mappings.
|
|
124
|
+
*/
|
|
125
|
+
private encodeMappings;
|
|
126
|
+
/**
|
|
127
|
+
* Encodes a single segment of the mappings.
|
|
128
|
+
*
|
|
129
|
+
* @param map - The MappingInterface object representing a single mapping.
|
|
130
|
+
* @param segments - An array of encoded segments.
|
|
131
|
+
* @param shift - The current state of the mapping information.
|
|
132
|
+
*/
|
|
133
|
+
private encodeSegment;
|
|
134
|
+
/**
|
|
135
|
+
* Performs a binary search on the internal `mappings` array to find a mapping object based on the line and column information.
|
|
136
|
+
* This function utilizes a binary search algorithm to efficiently locate the mapping corresponding to a specific line and column in the generated code.
|
|
137
|
+
*
|
|
138
|
+
* @param targetLine - The line number in the generated code to search for.
|
|
139
|
+
* @param targetColumn - The column number in the generated code to search for.
|
|
140
|
+
* @param bias - An optional bias value specifying how to handle cases where only the line number matches (DEFAULT: Bias.BOUND).
|
|
141
|
+
* Bias.LOWER_BOUND: If the line number matches but the column is less, return the closest mapping with a lower column.
|
|
142
|
+
* Bias.UPPER_BOUND: If the line number matches but the column is greater, return the closest mapping with a higher column.
|
|
143
|
+
* Bias.BOUND: If the line number matches and the column doesn't, return null (default behavior).
|
|
144
|
+
* @returns A MappingInterface object representing the found mapping, or null if no matching mapping is found based on the bias.
|
|
145
|
+
*/
|
|
146
|
+
private findMapping;
|
|
147
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@remotex-labs/xmap",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"author": "Garefild",
|
|
7
|
+
"version": "1.0.0",
|
|
8
|
+
"license": "Mozilla Public License Version 2.0",
|
|
9
|
+
"description": "A library with a sourcemap parser and TypeScript code formatter for the CLI",
|
|
10
|
+
"homepage": "https://github.com/remotex-lab/xMap",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/remotex-lab/xMap.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/remotex-lab/xMap/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"xmap",
|
|
20
|
+
"xMap",
|
|
21
|
+
"sourcemap",
|
|
22
|
+
"parser",
|
|
23
|
+
"typescript",
|
|
24
|
+
"formatter",
|
|
25
|
+
"CLI",
|
|
26
|
+
"syntax-highlighting",
|
|
27
|
+
"code-formatting",
|
|
28
|
+
"javascript",
|
|
29
|
+
"debugging",
|
|
30
|
+
"developer-tools",
|
|
31
|
+
"typescript runner"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"LICENSE",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"dev": "xBuild -w",
|
|
43
|
+
"build": "xBuild",
|
|
44
|
+
"lint": "tsc -noEmit && eslint . -c ./eslint.config.mjs",
|
|
45
|
+
"test": "jest",
|
|
46
|
+
"test:coverage": "jest --coverage",
|
|
47
|
+
"ci:test": "jest",
|
|
48
|
+
"ci:clean": "rm -rf ./dist",
|
|
49
|
+
"ci:build": "npm run build"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@remotex-labs/xbuild": "^0.0.1-beta.4",
|
|
53
|
+
"@swc/jest": "^0.2.36",
|
|
54
|
+
"@types/jest": "^29.5.12",
|
|
55
|
+
"@types/node": "^22.5.1",
|
|
56
|
+
"eslint": "^9.9.1",
|
|
57
|
+
"eslint-plugin-jsdoc": "^50.2.2",
|
|
58
|
+
"jest": "^29.7.0",
|
|
59
|
+
"typescript-eslint": "^8.3.0"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"typescript": "^5.5.4"
|
|
63
|
+
}
|
|
64
|
+
}
|