Skip to content

Commit 658bba9

Browse files
committed
Add --inlineSources option
1 parent c940b16 commit 658bba9

22 files changed

+366
-23
lines changed

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ module ts {
3434
name: "inlineSourceMap",
3535
type: "boolean",
3636
},
37+
{
38+
name: "inlineSources",
39+
type: "boolean",
40+
},
3741
{
3842
name: "listFiles",
3943
type: "boolean",

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ module ts {
455455
Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." },
456456
Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." },
457457
Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." },
458-
Option_out_cannot_be_specified_with_option_inlineSourceMap: { code: 5051, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'inlineSourceMap'." },
458+
Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." },
459459
Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
460460
Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
461461
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." },

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@
18081808
"category": "Error",
18091809
"code": 5050
18101810
},
1811-
"Option 'out' cannot be specified with option 'inlineSourceMap'.": {
1811+
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
18121812
"category": "Error",
18131813
"code": 5051
18141814
},

src/compiler/emitter.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ var __param = this.__param || function(index, decorator) { return function (targ
493493

494494
// The one that can be used from program to get the actual source file
495495
sourceMapData.inputSourceFileNames.push(node.fileName);
496+
497+
if (compilerOptions.inlineSources) {
498+
if (!sourceMapData.sourceMapSourcesContent) {
499+
sourceMapData.sourceMapSourcesContent = [];
500+
}
501+
sourceMapData.sourceMapSourcesContent.push(node.text);
502+
}
496503
}
497504

498505
function recordScopeNameOfNode(node: Node, scopeName?: string) {
@@ -599,15 +606,14 @@ var __param = this.__param || function(index, decorator) { return function (targ
599606
function writeJavaScriptAndSourceMapFile(emitOutput: string, writeByteOrderMark: boolean) {
600607
encodeLastRecordedSourceMapSpan();
601608

602-
let fileContents = compilerOptions.inlineSourceMap ? [currentSourceFile.text] : undefined;
603609
let sourceMapText = serializeSourceMapContents(
604610
3,
605611
sourceMapData.sourceMapFile,
606612
sourceMapData.sourceMapSourceRoot,
607613
sourceMapData.sourceMapSources,
608614
sourceMapData.sourceMapNames,
609615
sourceMapData.sourceMapMappings,
610-
fileContents);
616+
sourceMapData.sourceMapSourcesContent);
611617

612618
sourceMapDataList.push(sourceMapData);
613619

@@ -638,6 +644,7 @@ var __param = this.__param || function(index, decorator) { return function (targ
638644
inputSourceFileNames: [],
639645
sourceMapNames: [],
640646
sourceMapMappings: "",
647+
sourceMapSourcesContent: undefined,
641648
sourceMapDecodedMappings: []
642649
};
643650

src/compiler/program.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,12 @@ module ts {
484484
if (options.sourceRoot) {
485485
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap));
486486
}
487-
if (options.out) {
488-
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_inlineSourceMap));
487+
}
488+
489+
490+
if (options.inlineSources) {
491+
if (!options.sourceMap && !options.inlineSourceMap) {
492+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided));
489493
}
490494
}
491495

src/compiler/types.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,14 +1092,15 @@ module ts {
10921092
}
10931093

10941094
export interface SourceMapData {
1095-
sourceMapFilePath: string; // Where the sourcemap file is written
1096-
jsSourceMappingURL: string; // source map URL written in the .js file
1097-
sourceMapFile: string; // Source map's file field - .js file name
1098-
sourceMapSourceRoot: string; // Source map's sourceRoot field - location where the sources will be present if not ""
1099-
sourceMapSources: string[]; // Source map's sources field - list of sources that can be indexed in this source map
1100-
inputSourceFileNames: string[]; // Input source file (which one can use on program to get the file), 1:1 mapping with the sourceMapSources list
1101-
sourceMapNames?: string[]; // Source map's names field - list of names that can be indexed in this source map
1102-
sourceMapMappings: string; // Source map's mapping field - encoded source map spans
1095+
sourceMapFilePath: string; // Where the sourcemap file is written
1096+
jsSourceMappingURL: string; // source map URL written in the .js file
1097+
sourceMapFile: string; // Source map's file field - .js file name
1098+
sourceMapSourceRoot: string; // Source map's sourceRoot field - location where the sources will be present if not ""
1099+
sourceMapSources: string[]; // Source map's sources field - list of sources that can be indexed in this source map
1100+
sourceMapSourcesContent?: string[]; // Source map's sourcesContent field - list of the sources' text to be embedded in the source map
1101+
inputSourceFileNames: string[]; // Input source file (which one can use on program to get the file), 1:1 mapping with the sourceMapSources list
1102+
sourceMapNames?: string[]; // Source map's names field - list of names that can be indexed in this source map
1103+
sourceMapMappings: string; // Source map's mapping field - encoded source map spans
11031104
sourceMapDecodedMappings: SourceMapSpan[]; // Raw source map spans that were encoded into the sourceMapMappings
11041105
}
11051106

@@ -1640,6 +1641,7 @@ module ts {
16401641
emitBOM?: boolean;
16411642
help?: boolean;
16421643
inlineSourceMap?: boolean;
1644+
inlineSources?: boolean;
16431645
listFiles?: boolean;
16441646
locale?: string;
16451647
mapRoot?: string;

src/harness/harness.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,10 @@ module Harness {
10761076
case 'inlinesourcemap':
10771077
options.inlineSourceMap = setting.value === 'true';
10781078
break;
1079+
1080+
case 'inlinesources':
1081+
options.inlineSources = setting.value === 'true';
1082+
break;
10791083

10801084
default:
10811085
throw new Error('Unsupported compiler setting ' + setting.flag);
@@ -1473,7 +1477,8 @@ module Harness {
14731477
"noimplicitany", "noresolve", "newline", "newlines", "emitbom",
14741478
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
14751479
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
1476-
"separatecompilation", "inlinesourcemap", "maproot", "sourceroot"];
1480+
"separatecompilation", "inlinesourcemap", "maproot", "sourceroot",
1481+
"inlinesources"];
14771482

14781483
function extractCompilerSettings(content: string): CompilerSetting[] {
14791484

src/harness/sourceMapRecorder.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ module Harness.SourceMapRecoder {
237237
sourceMapRecoder.WriteLine("mapUrl: " + sourceMapData.jsSourceMappingURL);
238238
sourceMapRecoder.WriteLine("sourceRoot: " + sourceMapData.sourceMapSourceRoot);
239239
sourceMapRecoder.WriteLine("sources: " + sourceMapData.sourceMapSources);
240+
if (sourceMapData.sourceMapSourcesContent) {
241+
sourceMapRecoder.WriteLine("sourcesContent: " + JSON.stringify(sourceMapData.sourceMapSourcesContent));
242+
}
240243
sourceMapRecoder.WriteLine("===================================================================");
241244
}
242245

tests/baselines/reference/inlineSourceMap.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/inlineSourceMap.sourcemap.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sourceFile:inlineSourceMap.ts
3939
6 > ^
4040
7 > ^
4141
8 > ^
42-
9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
42+
9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
4343
1->
4444
>
4545
2 >console
@@ -58,4 +58,4 @@ sourceFile:inlineSourceMap.ts
5858
7 >Emitted(2, 15) Source(3, 15) + SourceIndex(0)
5959
8 >Emitted(2, 16) Source(3, 16) + SourceIndex(0)
6060
---
61-
>>>//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lU291cmNlTWFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5saW5lU291cmNlTWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbnZhciB4ID0gMDtcbmNvbnNvbGUubG9nKHgpOyJdfQ==
61+
>>>//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lU291cmNlTWFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5saW5lU291cmNlTWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMifQ==

0 commit comments

Comments
 (0)