Skip to content

Commit b97ec79

Browse files
committed
renamed StringWithSourcemap to MappedCode
1 parent 78c8ab9 commit b97ec79

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

src/compiler/compile/Component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import add_to_set from './utils/add_to_set';
2929
import check_graph_for_cycles from './utils/check_graph_for_cycles';
3030
import { print, x, b } from 'code-red';
3131
import { is_reserved_keyword } from './utils/reserved_keywords';
32-
import { apply_preprocessor_sourcemap } from '../utils/string_with_sourcemap';
32+
import { apply_preprocessor_sourcemap } from '../utils/mapped_code';
3333
import Element from './nodes/Element';
3434
import { DecodedSourceMap, RawSourceMap } from '@ampproject/remapping/dist/types/types';
3535

src/compiler/compile/render_dom/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { extract_names, Scope } from '../utils/scope';
77
import { invalidate } from './invalidate';
88
import Block from './Block';
99
import { ClassDeclaration, FunctionExpression, Node, Statement, ObjectExpression, Expression } from 'estree';
10-
import { apply_preprocessor_sourcemap } from '../../utils/string_with_sourcemap';
10+
import { apply_preprocessor_sourcemap } from '../../utils/mapped_code';
1111
import { RawSourceMap, DecodedSourceMap } from '@ampproject/remapping/dist/types/types';
1212

1313
export default function dom(

src/compiler/preprocess/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { RawSourceMap, DecodedSourceMap } from '@ampproject/remapping/dist/types/types';
22
import { getLocator } from 'locate-character';
3-
import { StringWithSourcemap, SourceLocation, sourcemap_add_offset, combine_sourcemaps } from '../utils/string_with_sourcemap';
3+
import { MappedCode, SourceLocation, sourcemap_add_offset, combine_sourcemaps } from '../utils/mapped_code';
44
import { decode_map } from './decode_sourcemap';
55
import { replace_in_code, Source } from './replace_in_code';
66
import { Preprocessor, PreprocessorGroup, Processed } from './types';
@@ -67,14 +67,14 @@ class PreprocessResult {
6767
}
6868

6969
/**
70-
* Convert preprocessor output for the tag content into StringWithSourceMap
70+
* Convert preprocessor output for the tag content into MappedCode
7171
*/
72-
function processed_content_to_sws(
72+
function processed_content_to_code(
7373
processed: Processed,
7474
location: SourceLocation,
7575
file_basename: string
76-
): StringWithSourcemap {
77-
// Convert the preprocessed code and its sourcemap to a StringWithSourcemap
76+
): MappedCode {
77+
// Convert the preprocessed code and its sourcemap to a MappedCode
7878
let decoded_map: DecodedSourceMap;
7979
if (processed.map) {
8080
decoded_map = decode_map(processed);
@@ -86,30 +86,30 @@ function processed_content_to_sws(
8686
}
8787
}
8888

89-
return StringWithSourcemap.from_processed(processed.code, decoded_map);
89+
return MappedCode.from_processed(processed.code, decoded_map);
9090
}
9191

9292
/**
93-
* Given the whole tag including content, return a `StringWithSourcemap`
93+
* Given the whole tag including content, return a `MappedCode`
9494
* representing the tag content replaced with `processed`.
9595
*/
96-
function processed_tag_to_sws(
96+
function processed_tag_to_code(
9797
processed: Processed,
9898
tag_name: 'style' | 'script',
9999
attributes: string,
100-
{ source, file_basename, get_location }: Source): StringWithSourcemap {
101-
const build_sws = (source: string, offset: number) =>
102-
StringWithSourcemap.from_source(file_basename, source, get_location(offset));
100+
{ source, file_basename, get_location }: Source): MappedCode {
101+
const build_mapped_code = (source: string, offset: number) =>
102+
MappedCode.from_source(file_basename, source, get_location(offset));
103103

104104
const tag_open = `<${tag_name}${attributes || ''}>`;
105105
const tag_close = `</${tag_name}>`;
106106

107-
const tag_open_sws = build_sws(tag_open, 0);
108-
const tag_close_sws = build_sws(tag_close, tag_open.length + source.length);
107+
const tag_open_code = build_mapped_code(tag_open, 0);
108+
const tag_close_code = build_mapped_code(tag_close, tag_open.length + source.length);
109109

110-
const content_sws = processed_content_to_sws(processed, get_location(tag_open.length), file_basename);
110+
const content_code = processed_content_to_code(processed, get_location(tag_open.length), file_basename);
111111

112-
return tag_open_sws.concat(content_sws).concat(tag_close_sws);
112+
return tag_open_code.concat(content_code).concat(tag_close_code);
113113
}
114114

115115
function parse_tag_attributes(str: string) {
@@ -143,9 +143,9 @@ async function process_tag(
143143
attributes = '',
144144
content = '',
145145
tag_offset: number
146-
): Promise<StringWithSourcemap> {
146+
): Promise<MappedCode> {
147147
const no_change = () =>
148-
StringWithSourcemap.from_source(file_basename, tag_with_content, get_location(tag_offset));
148+
MappedCode.from_source(file_basename, tag_with_content, get_location(tag_offset));
149149

150150
if (!attributes && !content) return no_change();
151151

@@ -158,7 +158,7 @@ async function process_tag(
158158
if (processed && processed.dependencies) dependencies.push(...processed.dependencies);
159159
if (!processed || !processed.map && processed.code === content) return no_change();
160160

161-
return processed_tag_to_sws(processed, tag_name, attributes,
161+
return processed_tag_to_code(processed, tag_name, attributes,
162162
{source: content, get_location: offset => source.get_location(offset + tag_offset), filename, file_basename});
163163
}
164164

src/compiler/preprocess/replace_in_code.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getLocator } from 'locate-character';
2-
import { StringWithSourcemap } from '../utils/string_with_sourcemap';
2+
import { MappedCode } from '../utils/mapped_code';
33

44
export interface Source {
55
source: string;
@@ -11,12 +11,12 @@ export interface Source {
1111
interface Replacement {
1212
offset: number;
1313
length: number;
14-
replacement: StringWithSourcemap;
14+
replacement: MappedCode;
1515
}
1616

1717
function calculate_replacements(
1818
re: RegExp,
19-
get_replacement: (...match: any[]) => Promise<StringWithSourcemap>,
19+
get_replacement: (...match: any[]) => Promise<MappedCode>,
2020
source: string
2121
) {
2222
const replacements: Array<Promise<Replacement>> = [];
@@ -41,28 +41,28 @@ function calculate_replacements(
4141
function perform_replacements(
4242
replacements: Replacement[],
4343
{ file_basename, source, get_location }: Source
44-
): StringWithSourcemap {
45-
const out = new StringWithSourcemap();
44+
): MappedCode {
45+
const out = new MappedCode();
4646
let last_end = 0;
4747

4848
for (const { offset, length, replacement } of replacements) {
49-
const unchanged_prefix = StringWithSourcemap.from_source(
49+
const unchanged_prefix = MappedCode.from_source(
5050
file_basename, source.slice(last_end, offset), get_location(last_end));
5151
out.concat(unchanged_prefix).concat(replacement);
5252
last_end = offset + length;
5353
}
5454

55-
const unchanged_suffix = StringWithSourcemap.from_source(
55+
const unchanged_suffix = MappedCode.from_source(
5656
file_basename, source.slice(last_end), get_location(last_end));
5757

5858
return out.concat(unchanged_suffix);
5959
}
6060

6161
export async function replace_in_code(
6262
regex: RegExp,
63-
get_replacement: (...match: any[]) => Promise<StringWithSourcemap>,
63+
get_replacement: (...match: any[]) => Promise<MappedCode>,
6464
location: Source
65-
): Promise<StringWithSourcemap> {
65+
): Promise<MappedCode> {
6666
const replacements = await calculate_replacements(regex, get_replacement, location.source);
6767

6868
return perform_replacements(replacements, location);

src/compiler/utils/string_with_sourcemap.ts renamed to src/compiler/utils/mapped_code.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function pushArray<T>(_this: T[], other: T[]) {
6767
}
6868
}
6969

70-
export class StringWithSourcemap {
70+
export class MappedCode {
7171
string: string;
7272
map: DecodedSourceMap;
7373

@@ -89,7 +89,7 @@ export class StringWithSourcemap {
8989
* concat in-place (mutable), return this (chainable)
9090
* will also mutate the `other` object
9191
*/
92-
concat(other: StringWithSourcemap): StringWithSourcemap {
92+
concat(other: MappedCode): MappedCode {
9393
// noop: if one is empty, return the other
9494
if (other.string == '') return this;
9595
if (this.string == '') {
@@ -166,7 +166,7 @@ export class StringWithSourcemap {
166166
return this;
167167
}
168168

169-
static from_processed(string: string, map?: DecodedSourceMap): StringWithSourcemap {
169+
static from_processed(string: string, map?: DecodedSourceMap): MappedCode {
170170
const line_count = string.split('\n').length;
171171

172172
if (map) {
@@ -177,23 +177,23 @@ export class StringWithSourcemap {
177177
for (let i = 0; i < missing_lines; i++) {
178178
map.mappings.push([]);
179179
}
180-
return new StringWithSourcemap(string, map);
180+
return new MappedCode(string, map);
181181
}
182182

183-
if (string == '') return new StringWithSourcemap();
183+
if (string == '') return new MappedCode();
184184
map = { version: 3, names: [], sources: [], mappings: [] };
185185

186186
// add empty SourceMapSegment[] for every line
187187
for (let i = 0; i < line_count; i++) map.mappings.push([]);
188-
return new StringWithSourcemap(string, map);
188+
return new MappedCode(string, map);
189189
}
190190

191191
static from_source(
192192
source_file: string, source: string, offset?: SourceLocation
193-
): StringWithSourcemap {
193+
): MappedCode {
194194
if (!offset) offset = { line: 0, column: 0 };
195195
const map: DecodedSourceMap = { version: 3, names: [], sources: [source_file], mappings: [] };
196-
if (source == '') return new StringWithSourcemap(source, map);
196+
if (source == '') return new MappedCode(source, map);
197197

198198
// we create a high resolution identity map here,
199199
// we know that it will eventually be merged with svelte's map,
@@ -213,7 +213,7 @@ export class StringWithSourcemap {
213213
for (let segment = 0; segment < segment_list.length; segment++) {
214214
segment_list[segment][3] += offset.column;
215215
}
216-
return new StringWithSourcemap(source, map);
216+
return new MappedCode(source, map);
217217
}
218218
}
219219

0 commit comments

Comments
 (0)