@elliots/typical 0.2.3 → 0.2.4
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 +21 -0
- package/README.md +102 -33
- package/dist/src/config.d.ts +0 -7
- package/dist/src/config.js +0 -1
- package/dist/src/config.js.map +1 -1
- package/dist/src/transformer.js +2 -2
- package/dist/src/transformer.js.map +1 -1
- package/package.json +5 -5
- package/src/config.ts +0 -8
- package/src/transformer.ts +2 -2
- package/dist/src/cli.typical.ts +0 -136
- package/dist/src/config.typical.ts +0 -287
- package/dist/src/file-filter.d.ts +0 -13
- package/dist/src/file-filter.js +0 -42
- package/dist/src/file-filter.js.map +0 -1
- package/dist/src/program-manager.d.ts +0 -27
- package/dist/src/program-manager.js +0 -121
- package/dist/src/program-manager.js.map +0 -1
- package/dist/src/regex-hoister.d.ts +0 -11
- package/dist/src/regex-hoister.js +0 -150
- package/dist/src/regex-hoister.js.map +0 -1
- package/dist/src/setup.d.ts +0 -2
- package/dist/src/setup.js +0 -20
- package/dist/src/setup.js.map +0 -1
- package/dist/src/source-map.d.ts +0 -78
- package/dist/src/source-map.js +0 -133
- package/dist/src/source-map.js.map +0 -1
- package/dist/src/source-map.typical.ts +0 -216
- package/dist/src/transformer.typical.ts +0 -2552
- package/dist/src/tsc-plugin.d.ts +0 -10
- package/dist/src/tsc-plugin.js +0 -13
- package/dist/src/tsc-plugin.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regex-hoister.js","sourceRoot":"","sources":["../../src/regex-hoister.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAyB,EAAE,UAAqB,EAAE,OAAuB;IAC9G,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAA,CAAC,oCAAoC;IACpF,IAAI,YAAY,GAAG,CAAC,CAAA;IAEpB,2EAA2E;IAC3E,6DAA6D;IAC7D,SAAS,sBA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B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IACzC,CAAC;IAED,4DAA4D;IAC5D,IAAI,WAAW,GAAG,CAAC,CAAA;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,qBAAqB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtD,IAAI,UAAU,CAAC,mBAAmB,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7D,WAAW,GAAG,CAAC,GAAG,CAAC,CAAA;QACrB,CAAC;aAAM,CAAC;YACN,MAAK;QACP,CAAC;IACH,CAAC;IAED,4CAA4C;IAC5C,MAAM,eAAe,GAAG,CAAC,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE,GAAG,mBAAmB,EAAE,GAAG,qBAAqB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;IAE7I,OAAO,OAAO,CAAC,gBAAgB,CAAC,UAAU,EAAE,eAAe,EAAE,UAAU,CAAC,iBAAiB,EAAE,UAAU,CAAC,eAAe,EAAE,UAAU,CAAC,uBAAuB,EAAE,UAAU,CAAC,eAAe,EAAE,UAAU,CAAC,sBAAsB,CAAC,CAAA;AAC3N,CAAC"}
|
package/dist/src/setup.d.ts
DELETED
package/dist/src/setup.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export function setupTsProgram(tsInstance) {
|
|
2
|
-
// Find tsconfig.json
|
|
3
|
-
const tsConfigPath = tsInstance.findConfigFile(process.cwd(), f => tsInstance.sys.fileExists(f), 'tsconfig.json');
|
|
4
|
-
if (!tsConfigPath) {
|
|
5
|
-
throw new Error('Could not find tsconfig.json');
|
|
6
|
-
}
|
|
7
|
-
if (process.env.DEBUG) {
|
|
8
|
-
console.log(`SETUP: Using tsconfig at ${tsConfigPath}`);
|
|
9
|
-
}
|
|
10
|
-
// Load and parse tsconfig.json
|
|
11
|
-
const configFile = tsInstance.readConfigFile(tsConfigPath, f => tsInstance.sys.readFile(f));
|
|
12
|
-
const parsedConfig = tsInstance.parseJsonConfigFileContent(configFile.config, tsInstance.sys, process.cwd());
|
|
13
|
-
if (process.env.DEBUG) {
|
|
14
|
-
console.log(`SETUP: Parsed tsconfig with ${parsedConfig.fileNames.length} files`);
|
|
15
|
-
}
|
|
16
|
-
// Create the TypeScript program with all project files
|
|
17
|
-
const tsProgram = tsInstance.createProgram(parsedConfig.fileNames, parsedConfig.options);
|
|
18
|
-
return tsProgram;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=setup.js.map
|
package/dist/src/setup.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,UAAqB;IAClD,qBAAqB;IACrB,MAAM,YAAY,GAAG,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,eAAe,CAAC,CAAA;IACjH,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,4BAA4B,YAAY,EAAE,CAAC,CAAA;IACzD,CAAC;IAED,+BAA+B;IAC/B,MAAM,UAAU,GAAG,UAAU,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3F,MAAM,YAAY,GAAG,UAAU,CAAC,0BAA0B,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IAE5G,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,+BAA+B,YAAY,CAAC,SAAS,CAAC,MAAM,QAAQ,CAAC,CAAA;IACnF,CAAC;IAED,uDAAuD;IACvD,MAAM,SAAS,GAAG,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;IAExF,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
package/dist/src/source-map.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string';
|
|
2
|
-
import type { DecodedSourceMap, EncodedSourceMap } from '@ampproject/remapping';
|
|
3
|
-
/**
|
|
4
|
-
* Result of a transformation that includes source map information.
|
|
5
|
-
*/
|
|
6
|
-
export interface TransformResult {
|
|
7
|
-
code: string;
|
|
8
|
-
map: EncodedSourceMap | null;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Configuration options for source map generation.
|
|
12
|
-
*/
|
|
13
|
-
export interface SourceMapOptions {
|
|
14
|
-
/** Generate source maps. Default: true */
|
|
15
|
-
enabled?: boolean;
|
|
16
|
-
/** Include source content in map. Default: true */
|
|
17
|
-
includeContent?: boolean;
|
|
18
|
-
/** Use inline source maps (data URL). Default: false */
|
|
19
|
-
inline?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Default source map options.
|
|
23
|
-
*/
|
|
24
|
-
export declare const defaultSourceMapOptions: Required<SourceMapOptions>;
|
|
25
|
-
/**
|
|
26
|
-
* Compose multiple source maps together.
|
|
27
|
-
* Given maps [A->B, B->C], produces A->C.
|
|
28
|
-
* Maps are applied in order: first map is closest to original source.
|
|
29
|
-
*/
|
|
30
|
-
export declare function composeSourceMaps(maps: (EncodedSourceMap | DecodedSourceMap | string | null | undefined)[], _originalFileName: string): EncodedSourceMap | null;
|
|
31
|
-
/**
|
|
32
|
-
* Generate an inline source map comment (data URL).
|
|
33
|
-
*/
|
|
34
|
-
export declare function inlineSourceMapComment(map: EncodedSourceMap | string): string;
|
|
35
|
-
/**
|
|
36
|
-
* Generate an external source map URL comment.
|
|
37
|
-
*/
|
|
38
|
-
export declare function externalSourceMapComment(mapFileName: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Create a MagicString instance for tracking source modifications.
|
|
41
|
-
*/
|
|
42
|
-
export declare function createMagicString(source: string, filename?: string): MagicString;
|
|
43
|
-
/**
|
|
44
|
-
* Generate a source map from a MagicString instance.
|
|
45
|
-
*/
|
|
46
|
-
export declare function generateSourceMap(ms: MagicString, options: {
|
|
47
|
-
source: string;
|
|
48
|
-
file?: string;
|
|
49
|
-
includeContent?: boolean;
|
|
50
|
-
hires?: boolean | 'boundary';
|
|
51
|
-
}): EncodedSourceMap;
|
|
52
|
-
/**
|
|
53
|
-
* Create an identity source map (maps each position to itself).
|
|
54
|
-
* Useful as a placeholder when no transformation occurred.
|
|
55
|
-
*/
|
|
56
|
-
export declare function createIdentityMap(source: string, fileName: string, includeContent?: boolean): EncodedSourceMap;
|
|
57
|
-
/**
|
|
58
|
-
* Represents a tracked modification to source code.
|
|
59
|
-
*/
|
|
60
|
-
export interface SourceModification {
|
|
61
|
-
/** Start position in original source */
|
|
62
|
-
start: number;
|
|
63
|
-
/** End position in original source */
|
|
64
|
-
end: number;
|
|
65
|
-
/** The replacement text */
|
|
66
|
-
replacement: string;
|
|
67
|
-
/** Type of modification */
|
|
68
|
-
type: 'insert-before' | 'insert-after' | 'replace' | 'prepend' | 'append';
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Apply a list of modifications to source code using MagicString.
|
|
72
|
-
* Returns the modified code and source map.
|
|
73
|
-
*/
|
|
74
|
-
export declare function applyModifications(source: string, fileName: string, modifications: SourceModification[], includeContent?: boolean): TransformResult;
|
|
75
|
-
/**
|
|
76
|
-
* Strip any existing source map comments from code.
|
|
77
|
-
*/
|
|
78
|
-
export declare function stripSourceMapComment(code: string): string;
|
package/dist/src/source-map.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string';
|
|
2
|
-
import remapping from '@ampproject/remapping';
|
|
3
|
-
/**
|
|
4
|
-
* Default source map options.
|
|
5
|
-
*/
|
|
6
|
-
export const defaultSourceMapOptions = {
|
|
7
|
-
enabled: true,
|
|
8
|
-
includeContent: true,
|
|
9
|
-
inline: false,
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Compose multiple source maps together.
|
|
13
|
-
* Given maps [A->B, B->C], produces A->C.
|
|
14
|
-
* Maps are applied in order: first map is closest to original source.
|
|
15
|
-
*/
|
|
16
|
-
export function composeSourceMaps(maps, _originalFileName) {
|
|
17
|
-
// Filter out null/undefined maps
|
|
18
|
-
const validMaps = maps.filter((m) => m !== null && m !== undefined);
|
|
19
|
-
if (validMaps.length === 0)
|
|
20
|
-
return null;
|
|
21
|
-
if (validMaps.length === 1) {
|
|
22
|
-
const map = validMaps[0];
|
|
23
|
-
if (typeof map === 'string') {
|
|
24
|
-
return JSON.parse(map);
|
|
25
|
-
}
|
|
26
|
-
return map;
|
|
27
|
-
}
|
|
28
|
-
// remapping expects maps in reverse order (final output first)
|
|
29
|
-
// and a loader function that returns the source map for a given file
|
|
30
|
-
const reversedMaps = [...validMaps].reverse();
|
|
31
|
-
try {
|
|
32
|
-
const result = remapping(reversedMaps, () => null);
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
// If remapping fails, return the last valid map
|
|
37
|
-
console.warn('Source map composition failed:', e);
|
|
38
|
-
const lastMap = validMaps[validMaps.length - 1];
|
|
39
|
-
if (typeof lastMap === 'string') {
|
|
40
|
-
return JSON.parse(lastMap);
|
|
41
|
-
}
|
|
42
|
-
return lastMap;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Generate an inline source map comment (data URL).
|
|
47
|
-
*/
|
|
48
|
-
export function inlineSourceMapComment(map) {
|
|
49
|
-
const mapString = typeof map === 'string' ? map : JSON.stringify(map);
|
|
50
|
-
const base64 = Buffer.from(mapString).toString('base64');
|
|
51
|
-
return `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64}`;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Generate an external source map URL comment.
|
|
55
|
-
*/
|
|
56
|
-
export function externalSourceMapComment(mapFileName) {
|
|
57
|
-
return `//# sourceMappingURL=${mapFileName}`;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Create a MagicString instance for tracking source modifications.
|
|
61
|
-
*/
|
|
62
|
-
export function createMagicString(source, filename) {
|
|
63
|
-
return new MagicString(source, {
|
|
64
|
-
filename,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Generate a source map from a MagicString instance.
|
|
69
|
-
*/
|
|
70
|
-
export function generateSourceMap(ms, options) {
|
|
71
|
-
return ms.generateMap({
|
|
72
|
-
source: options.source,
|
|
73
|
-
file: options.file ?? options.source,
|
|
74
|
-
includeContent: options.includeContent ?? true,
|
|
75
|
-
hires: options.hires ?? true,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Create an identity source map (maps each position to itself).
|
|
80
|
-
* Useful as a placeholder when no transformation occurred.
|
|
81
|
-
*/
|
|
82
|
-
export function createIdentityMap(source, fileName, includeContent = true) {
|
|
83
|
-
const ms = new MagicString(source);
|
|
84
|
-
return ms.generateMap({
|
|
85
|
-
source: fileName,
|
|
86
|
-
file: fileName,
|
|
87
|
-
includeContent,
|
|
88
|
-
hires: true,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Apply a list of modifications to source code using MagicString.
|
|
93
|
-
* Returns the modified code and source map.
|
|
94
|
-
*/
|
|
95
|
-
export function applyModifications(source, fileName, modifications, includeContent = true) {
|
|
96
|
-
const ms = createMagicString(source, fileName);
|
|
97
|
-
// Sort modifications by position (descending) to apply from end to start
|
|
98
|
-
// This prevents position shifts from affecting subsequent modifications
|
|
99
|
-
const sorted = [...modifications].sort((a, b) => b.start - a.start);
|
|
100
|
-
for (const mod of sorted) {
|
|
101
|
-
switch (mod.type) {
|
|
102
|
-
case 'insert-before':
|
|
103
|
-
ms.prependLeft(mod.start, mod.replacement);
|
|
104
|
-
break;
|
|
105
|
-
case 'insert-after':
|
|
106
|
-
ms.appendRight(mod.end, mod.replacement);
|
|
107
|
-
break;
|
|
108
|
-
case 'replace':
|
|
109
|
-
ms.overwrite(mod.start, mod.end, mod.replacement);
|
|
110
|
-
break;
|
|
111
|
-
case 'prepend':
|
|
112
|
-
ms.prepend(mod.replacement);
|
|
113
|
-
break;
|
|
114
|
-
case 'append':
|
|
115
|
-
ms.append(mod.replacement);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
code: ms.toString(),
|
|
121
|
-
map: generateSourceMap(ms, {
|
|
122
|
-
source: fileName,
|
|
123
|
-
includeContent,
|
|
124
|
-
}),
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Strip any existing source map comments from code.
|
|
129
|
-
*/
|
|
130
|
-
export function stripSourceMapComment(code) {
|
|
131
|
-
return code.replace(/\/\/[#@]\s*sourceMappingURL=.*/g, '');
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=source-map.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"source-map.js","sourceRoot":"","sources":["../../src/source-map.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAuB7C;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA+B;IACjE,OAAO,EAAE,IAAI;IACb,cAAc,EAAE,IAAI;IACpB,MAAM,EAAE,KAAK;CACd,CAAA;AAED;;;;GAIG;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
-
import typia from "typia";
|
|
2
|
-
//@L:1
|
|
3
|
-
import MagicString from 'magic-string';
|
|
4
|
-
//@L:2
|
|
5
|
-
import remapping from '@ampproject/remapping';
|
|
6
|
-
//@L:3
|
|
7
|
-
import type { DecodedSourceMap, EncodedSourceMap } from '@ampproject/remapping';
|
|
8
|
-
/**
|
|
9
|
-
* Result of a transformation that includes source map information.
|
|
10
|
-
*/
|
|
11
|
-
//@L:8
|
|
12
|
-
export interface TransformResult {
|
|
13
|
-
//@L:9
|
|
14
|
-
code: string;
|
|
15
|
-
//@L:10
|
|
16
|
-
map: EncodedSourceMap | null;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Configuration options for source map generation.
|
|
20
|
-
*/
|
|
21
|
-
//@L:16
|
|
22
|
-
export interface SourceMapOptions {
|
|
23
|
-
/** Generate source maps. Default: true */
|
|
24
|
-
//@L:18
|
|
25
|
-
enabled?: boolean;
|
|
26
|
-
/** Include source content in map. Default: true */
|
|
27
|
-
//@L:20
|
|
28
|
-
includeContent?: boolean;
|
|
29
|
-
/** Use inline source maps (data URL). Default: false */
|
|
30
|
-
//@L:22
|
|
31
|
-
inline?: boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Default source map options.
|
|
35
|
-
*/
|
|
36
|
-
//@L:28
|
|
37
|
-
export const defaultSourceMapOptions: Required<SourceMapOptions> = {
|
|
38
|
-
enabled: true,
|
|
39
|
-
includeContent: true,
|
|
40
|
-
inline: false,
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Compose multiple source maps together.
|
|
44
|
-
* Given maps [A->B, B->C], produces A->C.
|
|
45
|
-
* Maps are applied in order: first map is closest to original source.
|
|
46
|
-
*/
|
|
47
|
-
//@L:39
|
|
48
|
-
export function composeSourceMaps(maps: (EncodedSourceMap | DecodedSourceMap | string | null | undefined)[], originalFileName: string): EncodedSourceMap | null {
|
|
49
|
-
// Filter out null/undefined maps
|
|
50
|
-
//@L:44
|
|
51
|
-
const validMaps = maps.filter((m): m is EncodedSourceMap | DecodedSourceMap | string => m !== null && m !== undefined);
|
|
52
|
-
//@L:48
|
|
53
|
-
if (validMaps.length === 0)
|
|
54
|
-
return null;
|
|
55
|
-
//@L:49
|
|
56
|
-
if (validMaps.length === 1) {
|
|
57
|
-
//@L:50
|
|
58
|
-
const map = validMaps[0];
|
|
59
|
-
//@L:51
|
|
60
|
-
if (typeof map === 'string') {
|
|
61
|
-
//@L:52
|
|
62
|
-
return typia.json.assertParse<EncodedSourceMap>(map) as EncodedSourceMap;
|
|
63
|
-
}
|
|
64
|
-
//@L:54
|
|
65
|
-
return map as EncodedSourceMap;
|
|
66
|
-
}
|
|
67
|
-
// remapping expects maps in reverse order (final output first)
|
|
68
|
-
// and a loader function that returns the source map for a given file
|
|
69
|
-
//@L:59
|
|
70
|
-
const reversedMaps = [...validMaps].reverse();
|
|
71
|
-
//@L:61
|
|
72
|
-
try {
|
|
73
|
-
const result = remapping(reversedMaps, () => null);
|
|
74
|
-
return result as EncodedSourceMap;
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
// If remapping fails, return the last valid map
|
|
78
|
-
console.warn('Source map composition failed:', e);
|
|
79
|
-
const lastMap = validMaps[validMaps.length - 1];
|
|
80
|
-
if (typeof lastMap === 'string') {
|
|
81
|
-
return typia.json.assertParse<EncodedSourceMap>(lastMap) as EncodedSourceMap;
|
|
82
|
-
}
|
|
83
|
-
return lastMap as EncodedSourceMap;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Generate an inline source map comment (data URL).
|
|
88
|
-
*/
|
|
89
|
-
//@L:78
|
|
90
|
-
export function inlineSourceMapComment(map: EncodedSourceMap | string): string {
|
|
91
|
-
//@L:79
|
|
92
|
-
const mapString = typeof map === 'string' ? map : typia.json.stringify(map);
|
|
93
|
-
//@L:80
|
|
94
|
-
const base64 = Buffer.from(mapString).toString('base64');
|
|
95
|
-
//@L:81
|
|
96
|
-
return `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64}`;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Generate an external source map URL comment.
|
|
100
|
-
*/
|
|
101
|
-
//@L:87
|
|
102
|
-
export function externalSourceMapComment(mapFileName: string): string {
|
|
103
|
-
//@L:88
|
|
104
|
-
return `//# sourceMappingURL=${mapFileName}`;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Create a MagicString instance for tracking source modifications.
|
|
108
|
-
*/
|
|
109
|
-
//@L:94
|
|
110
|
-
export function createMagicString(source: string, filename?: string): MagicString {
|
|
111
|
-
//@L:95
|
|
112
|
-
return new MagicString(source, {
|
|
113
|
-
filename,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Generate a source map from a MagicString instance.
|
|
118
|
-
*/
|
|
119
|
-
//@L:103
|
|
120
|
-
export function generateSourceMap(ms: MagicString, options: {
|
|
121
|
-
source: string;
|
|
122
|
-
file?: string;
|
|
123
|
-
includeContent?: boolean;
|
|
124
|
-
hires?: boolean | 'boundary';
|
|
125
|
-
}): EncodedSourceMap {
|
|
126
|
-
//@L:112
|
|
127
|
-
return ms.generateMap({
|
|
128
|
-
source: options.source,
|
|
129
|
-
file: options.file ?? options.source,
|
|
130
|
-
includeContent: options.includeContent ?? true,
|
|
131
|
-
hires: options.hires ?? true,
|
|
132
|
-
}) as EncodedSourceMap;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Create an identity source map (maps each position to itself).
|
|
136
|
-
* Useful as a placeholder when no transformation occurred.
|
|
137
|
-
*/
|
|
138
|
-
//@L:124
|
|
139
|
-
export function createIdentityMap(source: string, fileName: string, includeContent: boolean = true): EncodedSourceMap {
|
|
140
|
-
//@L:129
|
|
141
|
-
const ms = new MagicString(source);
|
|
142
|
-
//@L:130
|
|
143
|
-
return ms.generateMap({
|
|
144
|
-
source: fileName,
|
|
145
|
-
file: fileName,
|
|
146
|
-
includeContent,
|
|
147
|
-
hires: true,
|
|
148
|
-
}) as EncodedSourceMap;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Represents a tracked modification to source code.
|
|
152
|
-
*/
|
|
153
|
-
//@L:141
|
|
154
|
-
export interface SourceModification {
|
|
155
|
-
/** Start position in original source */
|
|
156
|
-
//@L:143
|
|
157
|
-
start: number;
|
|
158
|
-
/** End position in original source */
|
|
159
|
-
//@L:145
|
|
160
|
-
end: number;
|
|
161
|
-
/** The replacement text */
|
|
162
|
-
//@L:147
|
|
163
|
-
replacement: string;
|
|
164
|
-
/** Type of modification */
|
|
165
|
-
//@L:149
|
|
166
|
-
type: 'insert-before' | 'insert-after' | 'replace' | 'prepend' | 'append';
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Apply a list of modifications to source code using MagicString.
|
|
170
|
-
* Returns the modified code and source map.
|
|
171
|
-
*/
|
|
172
|
-
//@L:156
|
|
173
|
-
export function applyModifications(source: string, fileName: string, modifications: SourceModification[], includeContent: boolean = true): TransformResult {
|
|
174
|
-
//@L:162
|
|
175
|
-
const ms = createMagicString(source, fileName);
|
|
176
|
-
// Sort modifications by position (descending) to apply from end to start
|
|
177
|
-
// This prevents position shifts from affecting subsequent modifications
|
|
178
|
-
//@L:166
|
|
179
|
-
const sorted = [...modifications].sort((a, b) => b.start - a.start);
|
|
180
|
-
//@L:168
|
|
181
|
-
for (const mod of sorted) {
|
|
182
|
-
switch (mod.type) {
|
|
183
|
-
case 'insert-before':
|
|
184
|
-
ms.prependLeft(mod.start, mod.replacement);
|
|
185
|
-
break;
|
|
186
|
-
case 'insert-after':
|
|
187
|
-
ms.appendRight(mod.end, mod.replacement);
|
|
188
|
-
break;
|
|
189
|
-
case 'replace':
|
|
190
|
-
ms.overwrite(mod.start, mod.end, mod.replacement);
|
|
191
|
-
break;
|
|
192
|
-
case 'prepend':
|
|
193
|
-
ms.prepend(mod.replacement);
|
|
194
|
-
break;
|
|
195
|
-
case 'append':
|
|
196
|
-
ms.append(mod.replacement);
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
//@L:188
|
|
201
|
-
return {
|
|
202
|
-
code: ms.toString(),
|
|
203
|
-
map: generateSourceMap(ms, {
|
|
204
|
-
source: fileName,
|
|
205
|
-
includeContent,
|
|
206
|
-
}),
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Strip any existing source map comments from code.
|
|
211
|
-
*/
|
|
212
|
-
//@L:200
|
|
213
|
-
export function stripSourceMapComment(code: string): string {
|
|
214
|
-
//@L:201
|
|
215
|
-
return code.replace(/\/\/[#@]\s*sourceMappingURL=.*/g, '');
|
|
216
|
-
}
|