@@ -404,8 +404,33 @@ public void testEsModule() {
404
404
});
405
405
}
406
406
407
+ private static final String BASE64_PREFIX = "data:application/json;base64," ;
408
+ private static final String ENCODED_SOURCE_MAP =
409
+ "eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9vLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiZm9vLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBO0lBR0UsV0FBWSxLQUFhO1FBQ3ZCLElBQUksQ0FBQyxDQUFDLEdBQUcsS0FBSyxDQUFDO0lBQ2pCLENBQUM7SUFDSCxRQUFDO0FBQUQsQ0FBQyxBQU5ELElBTUM7QUFFRCxPQUFPLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMifQ==" ;
410
+
407
411
@ Test
408
- public void testSourceMaps () {
412
+ public void testInlineSourceMaps () {
413
+ String sourceMapTestCode =
414
+ lines (
415
+ "var X = (function () {" ,
416
+ " function X(input) {" ,
417
+ " this.y = input;" ,
418
+ " }" ,
419
+ " return X;" ,
420
+ "}());" );
421
+ String sourceMappingURLComment = "//# sourceMappingURL=" + BASE64_PREFIX + ENCODED_SOURCE_MAP ;
422
+ ;
423
+ String code = sourceMapTestCode + "\n " + sourceMappingURLComment ;
424
+
425
+ Result result = testAndReturnResult (srcs (code ), expected (code ));
426
+ assertThat (result .compiler .getBase64SourceMapContents ("testcode" ))
427
+ .isEqualTo (ENCODED_SOURCE_MAP );
428
+ }
429
+
430
+ @ Test
431
+ public void testSourceMapsInSeparateMapFiles () {
432
+ // Sourcemap URLs should be a base64 encoded data url, not the name of a .js.map file.
433
+ // If we see a .js.map file, we will not serialize it.
409
434
String sourceMapTestCode =
410
435
lines (
411
436
"var X = (function () {" ,
@@ -419,7 +444,7 @@ public void testSourceMaps() {
419
444
String code = sourceMapTestCode + "\n " + sourceMappingURLComment ;
420
445
421
446
Result result = testAndReturnResult (srcs (code ), expected (code ));
422
- assertThat (result .compiler .getInputSourceMappingURL ("testcode" )).isEqualTo (sourceMappingURL );
447
+ assertThat (result .compiler .getBase64SourceMapContents ("testcode" )).isEqualTo (null );
423
448
}
424
449
425
450
@ Test
@@ -433,13 +458,13 @@ public void testSourceMapsWithoutResolvingSourceMapAnnotations() {
433
458
" }" ,
434
459
" return X;" ,
435
460
"}());" );
436
- String sourceMappingURL = "foo.js.map" ;
437
- String sourceMappingURLComment = "//# sourceMappingURL=" + sourceMappingURL ;
461
+ String sourceMappingURLComment = "//# sourceMappingURL=" + BASE64_PREFIX + ENCODED_SOURCE_MAP ;
462
+ ;
438
463
String code = sourceMapTestCode + "\n " + sourceMappingURLComment ;
439
464
440
465
Result result = testAndReturnResult (srcs (code ), expected (code ));
441
- // Input source map not registered because `resolveSourceMapAnnotations = false`
442
- assertThat (result .compiler .getInputSourceMappingURL ("testcode" )).isNull ();
466
+ // Source map not registered because `resolveSourceMapAnnotations = false`
467
+ assertThat (result .compiler .getBase64SourceMapContents ("testcode" )).isNull ();
443
468
}
444
469
445
470
@ Test
@@ -453,23 +478,22 @@ public void testSourceMapsWithoutParsingInlineSourceMaps() {
453
478
" }" ,
454
479
" return X;" ,
455
480
"}());" );
456
- String sourceMappingURL = "foo.js.map" ;
457
- String sourceMappingURLComment = "//# sourceMappingURL=" + sourceMappingURL ;
481
+ String sourceMappingURLComment = "//# sourceMappingURL=" + BASE64_PREFIX + ENCODED_SOURCE_MAP ;
482
+ ;
458
483
String code = sourceMapTestCode + "\n " + sourceMappingURLComment ;
459
484
460
485
Result result = testAndReturnResult (srcs (code ), expected (code ));
461
- // Input source map is registered when `parseInlineSourceMaps = false`, but we won't try to
486
+ // Source map is registered when `parseInlineSourceMaps = false`, but we won't try to
462
487
// parse it as a Base64 encoded source map.
463
- assertThat (result .compiler .getInputSourceMappingURL ("testcode" )).isEqualTo (sourceMappingURL );
488
+ assertThat (result .compiler .getBase64SourceMapContents ("testcode" )).isEqualTo (null );
464
489
}
465
490
466
491
@ Test
467
492
public void testConfiguredDirectorySourceMaps () {
468
493
// We do not allow the TypeScript compiler to set "compilerOptions.sourceRoot" (option to
469
494
// configure a directory to store
470
- // sourcemaps). Sourcemaps (.js.map) files are placed next to the .js files.
471
- // This means sourcemap URLs should be the name of the sourcemap file, not a path to the
472
- // sourcemap file. If we see a path, we will serialize only the name of the sourcemap file.
495
+ // sourcemaps). Sourcemap URLs should be a base64 encoded data url, not a path to the
496
+ // sourcemap file. If we see a path, we will not serialize anything.
473
497
String sourceMapTestCode =
474
498
lines (
475
499
"var X = (function () {" ,
@@ -483,7 +507,7 @@ public void testConfiguredDirectorySourceMaps() {
483
507
String code = sourceMapTestCode + "\n " + sourceMappingURLComment ;
484
508
485
509
Result result = testAndReturnResult (srcs (code ), expected (code ));
486
- assertThat (result .compiler .getInputSourceMappingURL ("testcode" )).isEqualTo ("foo.js.map" );
510
+ assertThat (result .compiler .getBase64SourceMapContents ("testcode" )).isEqualTo (null );
487
511
}
488
512
489
513
@ Test
0 commit comments