1
1
import { RawSourceMap , DecodedSourceMap } from '@ampproject/remapping/dist/types/types' ;
2
2
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 ' ;
4
4
import { decode_map } from './decode_sourcemap' ;
5
5
import { replace_in_code , Source } from './replace_in_code' ;
6
6
import { Preprocessor , PreprocessorGroup , Processed } from './types' ;
@@ -67,14 +67,14 @@ class PreprocessResult {
67
67
}
68
68
69
69
/**
70
- * Convert preprocessor output for the tag content into StringWithSourceMap
70
+ * Convert preprocessor output for the tag content into MappedCode
71
71
*/
72
- function processed_content_to_sws (
72
+ function processed_content_to_code (
73
73
processed : Processed ,
74
74
location : SourceLocation ,
75
75
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
78
78
let decoded_map : DecodedSourceMap ;
79
79
if ( processed . map ) {
80
80
decoded_map = decode_map ( processed ) ;
@@ -86,30 +86,30 @@ function processed_content_to_sws(
86
86
}
87
87
}
88
88
89
- return StringWithSourcemap . from_processed ( processed . code , decoded_map ) ;
89
+ return MappedCode . from_processed ( processed . code , decoded_map ) ;
90
90
}
91
91
92
92
/**
93
- * Given the whole tag including content, return a `StringWithSourcemap `
93
+ * Given the whole tag including content, return a `MappedCode `
94
94
* representing the tag content replaced with `processed`.
95
95
*/
96
- function processed_tag_to_sws (
96
+ function processed_tag_to_code (
97
97
processed : Processed ,
98
98
tag_name : 'style' | 'script' ,
99
99
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 ) ) ;
103
103
104
104
const tag_open = `<${ tag_name } ${ attributes || '' } >` ;
105
105
const tag_close = `</${ tag_name } >` ;
106
106
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 ) ;
109
109
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 ) ;
111
111
112
- return tag_open_sws . concat ( content_sws ) . concat ( tag_close_sws ) ;
112
+ return tag_open_code . concat ( content_code ) . concat ( tag_close_code ) ;
113
113
}
114
114
115
115
function parse_tag_attributes ( str : string ) {
@@ -143,9 +143,9 @@ async function process_tag(
143
143
attributes = '' ,
144
144
content = '' ,
145
145
tag_offset : number
146
- ) : Promise < StringWithSourcemap > {
146
+ ) : Promise < MappedCode > {
147
147
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 ) ) ;
149
149
150
150
if ( ! attributes && ! content ) return no_change ( ) ;
151
151
@@ -158,7 +158,7 @@ async function process_tag(
158
158
if ( processed && processed . dependencies ) dependencies . push ( ...processed . dependencies ) ;
159
159
if ( ! processed || ! processed . map && processed . code === content ) return no_change ( ) ;
160
160
161
- return processed_tag_to_sws ( processed , tag_name , attributes ,
161
+ return processed_tag_to_code ( processed , tag_name , attributes ,
162
162
{ source : content , get_location : offset => source . get_location ( offset + tag_offset ) , filename, file_basename} ) ;
163
163
}
164
164
0 commit comments