5
5
* http://opensource.org/licenses/BSD-3-Clause
6
6
*/
7
7
8
- const fs = require ( ' node:fs/promises' ) ;
8
+ const fs = require ( " node:fs/promises" ) ;
9
9
const SourceMapConsumer =
10
10
require ( "../lib/source-map-consumer" ) . SourceMapConsumer ;
11
11
@@ -50,7 +50,7 @@ const skippedTests = [
50
50
"ignoreListWrongType2" ,
51
51
"ignoreListWrongType3" ,
52
52
"ignoreListOutOfBounds" ,
53
- ]
53
+ ] ;
54
54
55
55
// The source-map library converts null sources to the "null" URL in its
56
56
// sources list, so for equality checking we accept this as null.
@@ -66,76 +66,135 @@ function mapLine(line) {
66
66
}
67
67
68
68
async function testMappingAction ( assert , rawSourceMap , action ) {
69
- return SourceMapConsumer . with ( rawSourceMap , null , ( consumer ) => {
70
- mappedPosition = consumer . originalPositionFor ( {
69
+ return SourceMapConsumer . with ( rawSourceMap , null , consumer => {
70
+ let mappedPosition = consumer . originalPositionFor ( {
71
71
line : mapLine ( action . generatedLine ) ,
72
72
column : action . generatedColumn ,
73
73
} ) ;
74
74
75
- assert . equal ( mappedPosition . line , mapLine ( action . originalLine ) , `original line didn't match, expected ${ mapLine ( action . originalLine ) } got ${ mappedPosition . line } ` ) ;
76
- assert . equal ( mappedPosition . column , action . originalColumn , `original column didn't match, expected ${ action . originalColumn } got ${ mappedPosition . column } ` ) ;
77
- assert . equal ( nullish ( mappedPosition . source ) , action . originalSource , `original source didn't match, expected ${ action . originalSource } got ${ mappedPosition . source } ` ) ;
78
- if ( action . mappedName )
79
- assert . equal ( mappedPosition . name , action . mappedName , `mapped name didn't match, expected ${ action . mappedName } got ${ mappedPosition . name } ` ) ;
75
+ assert . equal (
76
+ mappedPosition . line ,
77
+ mapLine ( action . originalLine ) ,
78
+ `original line didn't match, expected ${ mapLine (
79
+ action . originalLine
80
+ ) } got ${ mappedPosition . line } `
81
+ ) ;
82
+ assert . equal (
83
+ mappedPosition . column ,
84
+ action . originalColumn ,
85
+ `original column didn't match, expected ${ action . originalColumn } got ${ mappedPosition . column } `
86
+ ) ;
87
+ assert . equal (
88
+ nullish ( mappedPosition . source ) ,
89
+ action . originalSource ,
90
+ `original source didn't match, expected ${ action . originalSource } got ${ mappedPosition . source } `
91
+ ) ;
92
+ if ( action . mappedName ) {
93
+ assert . equal (
94
+ mappedPosition . name ,
95
+ action . mappedName ,
96
+ `mapped name didn't match, expected ${ action . mappedName } got ${ mappedPosition . name } `
97
+ ) ;
98
+ }
80
99
81
100
// When the source is null, a reverse lookup may not make sense
82
101
// because there isn't a unique way to look it up.
83
102
if ( action . originalSource !== null ) {
84
- let mappedPosition = consumer . generatedPositionFor ( {
103
+ mappedPosition = consumer . generatedPositionFor ( {
85
104
source : action . originalSource ,
86
105
line : mapLine ( action . originalLine ) ,
87
- column : action . originalColumn
106
+ column : action . originalColumn ,
88
107
} ) ;
89
108
90
- assert . equal ( mappedPosition . line , mapLine ( action . generatedLine ) , `generated line didn't match, expected ${ mapLine ( action . generatedLine ) } got ${ mappedPosition . line } ` ) ;
91
- assert . equal ( mappedPosition . column , action . generatedColumn , `generated column didn't match, expected ${ action . generatedColumn } got ${ mappedPosition . column } ` ) ;
109
+ assert . equal (
110
+ mappedPosition . line ,
111
+ mapLine ( action . generatedLine ) ,
112
+ `generated line didn't match, expected ${ mapLine (
113
+ action . generatedLine
114
+ ) } got ${ mappedPosition . line } `
115
+ ) ;
116
+ assert . equal (
117
+ mappedPosition . column ,
118
+ action . generatedColumn ,
119
+ `generated column didn't match, expected ${ action . generatedColumn } got ${ mappedPosition . column } `
120
+ ) ;
92
121
}
93
-
94
122
} ) ;
95
123
}
96
124
97
125
async function testTransitiveMappingAction ( assert , rawSourceMap , action ) {
98
- return SourceMapConsumer . with ( rawSourceMap , null , async ( consumer ) => {
99
- assert . ok ( Array . isArray ( action . intermediateMaps ) , "transitive mapping case requires intermediate maps" ) ;
126
+ return SourceMapConsumer . with ( rawSourceMap , null , async consumer => {
127
+ assert . ok (
128
+ Array . isArray ( action . intermediateMaps ) ,
129
+ "transitive mapping case requires intermediate maps"
130
+ ) ;
100
131
101
132
let mappedPosition = consumer . originalPositionFor ( {
102
133
line : mapLine ( action . generatedLine ) ,
103
134
column : action . generatedColumn ,
104
135
} ) ;
105
136
106
137
for ( const intermediateMapPath of action . intermediateMaps ) {
107
- const intermediateMap = await readJSON ( `./source-map-tests/resources/${ intermediateMapPath } ` ) ;
108
- await SourceMapConsumer . with ( intermediateMap , null , ( consumer ) => {
109
- mappedPosition = consumer . originalPositionFor ( {
110
- line : mappedPosition . line ,
111
- column : mappedPosition . column ,
112
- } ) ;
113
- } ) ;
138
+ const intermediateMap = await readJSON (
139
+ `./source-map-tests/resources/${ intermediateMapPath } `
140
+ ) ;
141
+ await SourceMapConsumer . with (
142
+ intermediateMap ,
143
+ null ,
144
+ consumerIntermediate => {
145
+ mappedPosition = consumerIntermediate . originalPositionFor ( {
146
+ line : mappedPosition . line ,
147
+ column : mappedPosition . column ,
148
+ } ) ;
149
+ }
150
+ ) ;
114
151
}
115
152
116
- assert . equal ( mappedPosition . line , mapLine ( action . originalLine ) , `original line didn't match, expected ${ mapLine ( action . originalLine ) } got ${ mappedPosition . line } ` ) ;
117
- assert . equal ( mappedPosition . column , action . originalColumn , `original column didn't match, expected ${ action . originalColumn } got ${ mappedPosition . column } ` ) ;
118
- assert . equal ( mappedPosition . source , action . originalSource , `original source didn't match, expected ${ action . originalSource } got ${ mappedPosition . source } ` ) ;
153
+ assert . equal (
154
+ mappedPosition . line ,
155
+ mapLine ( action . originalLine ) ,
156
+ `original line didn't match, expected ${ mapLine (
157
+ action . originalLine
158
+ ) } got ${ mappedPosition . line } `
159
+ ) ;
160
+ assert . equal (
161
+ mappedPosition . column ,
162
+ action . originalColumn ,
163
+ `original column didn't match, expected ${ action . originalColumn } got ${ mappedPosition . column } `
164
+ ) ;
165
+ assert . equal (
166
+ mappedPosition . source ,
167
+ action . originalSource ,
168
+ `original source didn't match, expected ${ action . originalSource } got ${ mappedPosition . source } `
169
+ ) ;
119
170
} ) ;
120
171
}
121
172
122
173
for ( const testCase of sourceMapSpecTests . tests ) {
123
- if ( skippedTests . includes ( testCase . name ) )
174
+ if ( skippedTests . includes ( testCase . name ) ) {
124
175
continue ;
176
+ }
125
177
exports [ `test from source map spec tests, name: ${ testCase . name } ` ] =
126
178
async function ( assert ) {
127
- const json = await readJSON ( `./source-map-tests/resources/${ testCase . sourceMapFile } ` ) ;
179
+ const json = await readJSON (
180
+ `./source-map-tests/resources/${ testCase . sourceMapFile } `
181
+ ) ;
128
182
try {
129
183
const map = await new SourceMapConsumer ( json ) ;
130
184
map . eachMapping ( ( ) => { } ) ;
131
185
map . destroy ( ) ;
132
186
} catch ( exn ) {
133
- if ( testCase . sourceMapIsValid )
134
- assert . fail ( "Expected valid source map but failed to load successfully: " + exn . message ) ;
187
+ if ( testCase . sourceMapIsValid ) {
188
+ assert . fail (
189
+ "Expected valid source map but failed to load successfully: " +
190
+ exn . message
191
+ ) ;
192
+ }
135
193
return ;
136
194
}
137
- if ( ! testCase . sourceMapIsValid )
195
+ if ( ! testCase . sourceMapIsValid ) {
138
196
assert . fail ( "Expected invalid source map but loaded successfully" ) ;
197
+ }
139
198
if ( testCase . testActions ) {
140
199
for ( const testAction of testCase . testActions ) {
141
200
if ( testAction . actionType == "checkMapping" ) {
@@ -146,4 +205,4 @@ for (const testCase of sourceMapSpecTests.tests) {
146
205
}
147
206
}
148
207
} ;
149
- } ;
208
+ }
0 commit comments