* A mapping can have one of the three levels of data: * * 1. Just the generated position. * 2. The Generated position, original position, and original source. * 3. Generated and original position, original source, as well as a name * token. * * To maintain consistency
(aGenerated, aOriginal, aSource, aName)
| 261 | * in to one of these categories. |
| 262 | */ |
| 263 | _validateMapping(aGenerated, aOriginal, aSource, aName) { |
| 264 | // When aOriginal is truthy but has empty values for .line and .column, |
| 265 | // it is most likely a programmer error. In this case we throw a very |
| 266 | // specific error message to try to guide them the right way. |
| 267 | // For example: https://github.com/Polymer/polymer-bundler/pull/519 |
| 268 | if ( |
| 269 | aOriginal && |
| 270 | typeof aOriginal.line !== "number" && |
| 271 | typeof aOriginal.column !== "number" |
| 272 | ) { |
| 273 | throw new Error( |
| 274 | "original.line and original.column are not numbers -- you probably meant to omit " + |
| 275 | "the original mapping entirely and only map the generated position. If so, pass " + |
| 276 | "null for the original mapping instead of an object with empty or null values." |
| 277 | ); |
| 278 | } |
| 279 | |
| 280 | if ( |
| 281 | aGenerated && |
| 282 | "line" in aGenerated && |
| 283 | "column" in aGenerated && |
| 284 | aGenerated.line > 0 && |
| 285 | aGenerated.column >= 0 && |
| 286 | !aOriginal && |
| 287 | !aSource && |
| 288 | !aName |
| 289 | ) { |
| 290 | // Case 1. |
| 291 | } else if ( |
| 292 | aGenerated && |
| 293 | "line" in aGenerated && |
| 294 | "column" in aGenerated && |
| 295 | aOriginal && |
| 296 | "line" in aOriginal && |
| 297 | "column" in aOriginal && |
| 298 | aGenerated.line > 0 && |
| 299 | aGenerated.column >= 0 && |
| 300 | aOriginal.line > 0 && |
| 301 | aOriginal.column >= 0 && |
| 302 | aSource |
| 303 | ) { |
| 304 | // Cases 2 and 3. |
| 305 | } else { |
| 306 | throw new Error( |
| 307 | "Invalid mapping: " + |
| 308 | JSON.stringify({ |
| 309 | generated: aGenerated, |
| 310 | source: aSource, |
| 311 | original: aOriginal, |
| 312 | name: aName, |
| 313 | }) |
| 314 | ); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Serialize the accumulated mappings in to the stream of base 64 VLQs |