Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita998abb

Browse files
committed
Add inlineSourceMap option
1 parent73e22ed commita998abb

16 files changed

+294
-24
lines changed

‎src/compiler/commandLineParser.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ module ts {
3030
type:"boolean",
3131
description:Diagnostics.Print_this_message,
3232
},
33+
{
34+
name:"inlineSourceMap",
35+
type:"boolean",
36+
},
3337
{
3438
name:"listFiles",
3539
type:"boolean",

‎src/compiler/diagnosticInformationMap.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ module ts {
445445
Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation:{code:5045,category:DiagnosticCategory.Error,key:"Option 'noEmitOnError' cannot be specified with option 'separateCompilation'."},
446446
Option_out_cannot_be_specified_with_option_separateCompilation:{code:5046,category:DiagnosticCategory.Error,key:"Option 'out' cannot be specified with option 'separateCompilation'."},
447447
Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher:{code:5047,category:DiagnosticCategory.Error,key:"Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher."},
448+
Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap:{code:5048,category:DiagnosticCategory.Error,key:"Option 'sourceMap' cannot be specified with option 'inlineSourceMap'."},
449+
Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap:{code:5049,category:DiagnosticCategory.Error,key:"Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'."},
450+
Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap:{code:5050,category:DiagnosticCategory.Error,key:"Option 'mapRoot' cannot be specified with option 'inlineSourceMap'."},
451+
Option_out_cannot_be_specified_with_option_inlineSourceMap:{code:5051,category:DiagnosticCategory.Error,key:"Option 'out' cannot be specified with option 'inlineSourceMap'."},
448452
Concatenate_and_emit_output_to_single_file:{code:6001,category:DiagnosticCategory.Message,key:"Concatenate and emit output to single file."},
449453
Generates_corresponding_d_ts_file:{code:6002,category:DiagnosticCategory.Message,key:"Generates corresponding '.d.ts' file."},
450454
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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@
661661
},
662662
"Invalid use of '{0}'. Class definitions are automatically in strict mode.": {
663663
"category":"Error",
664-
"code":1210
664+
"code":1210
665665
},
666666
"A class declaration without the 'default' modifier must have a name": {
667667
"category":"Error",
@@ -1772,6 +1772,23 @@
17721772
"category":"Error",
17731773
"code":5047
17741774
},
1775+
"Option 'sourceMap' cannot be specified with option 'inlineSourceMap'.": {
1776+
"category":"Error",
1777+
"code":5048
1778+
},
1779+
"Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'.": {
1780+
"category":"Error",
1781+
"code":5049
1782+
},
1783+
"Option 'mapRoot' cannot be specified with option 'inlineSourceMap'.": {
1784+
"category":"Error",
1785+
"code":5050
1786+
},
1787+
"Option 'out' cannot be specified with option 'inlineSourceMap'.": {
1788+
"category":"Error",
1789+
"code":5051
1790+
},
1791+
17751792
"Concatenate and emit output to single file.": {
17761793
"category":"Message",
17771794
"code":6001

‎src/compiler/emitter.ts‎

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var __param = this.__param || function(index, decorator) { return function (targ
5252

5353
letcompilerOptions=host.getCompilerOptions();
5454
letlanguageVersion=compilerOptions.target||ScriptTarget.ES3;
55-
letsourceMapDataList:SourceMapData[]=compilerOptions.sourceMap ?[] :undefined;
55+
letsourceMapDataList:SourceMapData[]=compilerOptions.sourceMap||compilerOptions.inlineSourceMap?[] :undefined;
5656
letdiagnostics:Diagnostic[]=[];
5757
letnewLine=host.getNewLine();
5858

@@ -169,7 +169,7 @@ var __param = this.__param || function(index, decorator) { return function (targ
169169
/** Sourcemap data that will get encoded */
170170
letsourceMapData:SourceMapData;
171171

172-
if(compilerOptions.sourceMap){
172+
if(compilerOptions.sourceMap||compilerOptions.inlineSourceMap){
173173
initializeEmitterWithSourceMaps();
174174
}
175175

@@ -564,19 +564,25 @@ var __param = this.__param || function(index, decorator) { return function (targ
564564
recordSourceMapSpan(comment.end);
565565
}
566566

567-
functionserializeSourceMapContents(version:number,file:string,sourceRoot:string,sources:string[],names:string[],mappings:string){
567+
functionserializeSourceMapContents(version:number,file:string,sourceRoot:string,sources:string[],names:string[],mappings:string,sourcesContent?:string[]){
568568
if(typeofJSON!=="undefined"){
569-
returnJSON.stringify({
570-
version:version,
571-
file:file,
572-
sourceRoot:sourceRoot,
573-
sources:sources,
574-
names:names,
575-
mappings:mappings
576-
});
569+
letmap:any={
570+
version,
571+
file,
572+
sourceRoot,
573+
sources,
574+
names,
575+
mappings
576+
};
577+
578+
if(sourcesContent!==undefined){
579+
map.sourcesContent=sourcesContent;
580+
}
581+
582+
returnJSON.stringify(map);
577583
}
578584

579-
return"{\"version\":"+version+",\"file\":\""+escapeString(file)+"\",\"sourceRoot\":\""+escapeString(sourceRoot)+"\",\"sources\":["+serializeStringArray(sources)+"],\"names\":["+serializeStringArray(names)+"],\"mappings\":\""+escapeString(mappings)+"\"}";
585+
return"{\"version\":"+version+",\"file\":\""+escapeString(file)+"\",\"sourceRoot\":\""+escapeString(sourceRoot)+"\",\"sources\":["+serializeStringArray(sources)+"],\"names\":["+serializeStringArray(names)+"],\"mappings\":\""+escapeString(mappings)+"\" "+(sourcesContent!==undefined ?",\"sourcesContent\":["+serializeStringArray(sourcesContent)+"]" :"")+"}";
580586

581587
functionserializeStringArray(list:string[]):string{
582588
letoutput="";
@@ -591,19 +597,34 @@ var __param = this.__param || function(index, decorator) { return function (targ
591597
}
592598

593599
functionwriteJavaScriptAndSourceMapFile(emitOutput:string,writeByteOrderMark:boolean){
594-
// Write source map file
595600
encodeLastRecordedSourceMapSpan();
596-
writeFile(host,diagnostics,sourceMapData.sourceMapFilePath,serializeSourceMapContents(
601+
602+
letfileContents=compilerOptions.inlineSourceMap ?[currentSourceFile.text] :undefined;
603+
letsourceMapText=serializeSourceMapContents(
597604
3,
598605
sourceMapData.sourceMapFile,
599606
sourceMapData.sourceMapSourceRoot,
600607
sourceMapData.sourceMapSources,
601608
sourceMapData.sourceMapNames,
602-
sourceMapData.sourceMapMappings),/*writeByteOrderMark*/false);
609+
sourceMapData.sourceMapMappings,
610+
fileContents);
611+
603612
sourceMapDataList.push(sourceMapData);
604613

614+
letsourceMapUrl:string;
615+
if(compilerOptions.inlineSourceMap){
616+
// Encode the sourceMap into the sourceMap url
617+
letbase64SourceMapText=convertToBase64(sourceMapText);
618+
sourceMapUrl=`//# sourceMappingURL=data:application/json;base64,${base64SourceMapText}`;
619+
}
620+
else{
621+
// Write source map file
622+
writeFile(host,diagnostics,sourceMapData.sourceMapFilePath,sourceMapText,/*writeByteOrderMark*/false);
623+
sourceMapUrl=`//# sourceMappingURL=${sourceMapData.jsSourceMappingURL}`;
624+
}
625+
605626
// Write sourcemap url to the js file and write the js file
606-
writeJavaScriptFile(emitOutput+"//# sourceMappingURL="+sourceMapData.jsSourceMappingURL,writeByteOrderMark);
627+
writeJavaScriptFile(emitOutput+sourceMapUrl,writeByteOrderMark);
607628
}
608629

609630
// Initialize source map data
@@ -861,7 +882,7 @@ var __param = this.__param || function(index, decorator) { return function (targ
861882
functionemitLiteral(node:LiteralExpression){
862883
lettext=getLiteralText(node);
863884

864-
if(compilerOptions.sourceMap&&(node.kind===SyntaxKind.StringLiteral||isTemplateLiteralKind(node.kind))){
885+
if((compilerOptions.sourceMap||compilerOptions.inlineSourceMap)&&(node.kind===SyntaxKind.StringLiteral||isTemplateLiteralKind(node.kind))){
865886
writer.writeLiteral(text);
866887
}
867888
// For versions below ES6, emit binary & octal literals in their canonical decimal form.

‎src/compiler/program.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,21 @@ module ts {
472472
}
473473
}
474474

475+
if(options.inlineSourceMap){
476+
if(options.sourceMap){
477+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap));
478+
}
479+
if(options.mapRoot){
480+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap));
481+
}
482+
if(options.sourceRoot){
483+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap));
484+
}
485+
if(options.out){
486+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_inlineSourceMap));
487+
}
488+
}
489+
475490
if(!options.sourceMap&&(options.mapRoot||options.sourceRoot)){
476491
// Error to specify --mapRoot or --sourceRoot without mapSourceFiles
477492
if(options.mapRoot){

‎src/compiler/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,7 @@ module ts {
15871587
diagnostics?:boolean;
15881588
emitBOM?:boolean;
15891589
help?:boolean;
1590+
inlineSourceMap?:boolean;
15901591
listFiles?:boolean;
15911592
locale?:string;
15921593
mapRoot?:string;

‎src/harness/compilerRunner.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class CompilerBaselineRunner extends RunnerBase {
159159

160160
// Source maps?
161161
it('Correct sourcemap content for '+fileName,()=>{
162-
if(options.sourceMap){
162+
if(options.sourceMap||options.inlineSourceMap){
163163
Harness.Baseline.runBaseline('Correct sourcemap content for '+fileName,justName.replace(/\.ts$/,'.sourcemap.txt'),()=>{
164164
varrecord=result.getSourceMapRecord();
165165
if(options.noEmitOnError&&result.errors.length!==0&&record===undefined){
@@ -228,11 +228,14 @@ class CompilerBaselineRunner extends RunnerBase {
228228
});
229229

230230
it('Correct Sourcemap output for '+fileName,()=>{
231-
if(options.sourceMap){
232-
if(result.sourceMaps.length!==result.files.length){
233-
thrownewError('Number of sourcemap files should be same as js files.');
234-
}
231+
if(options.sourceMap&&result.sourceMaps.length!==result.files.length){
232+
thrownewError('Number of sourcemap files should be same as js files.');
233+
}
234+
elseif(options.inlineSourceMap&&result.sourceMaps.length>0){
235+
thrownewError('No sourcemap files should be generated if inlineSourceMaps was set.');
236+
}
235237

238+
if(options.sourceMap){
236239
Harness.Baseline.runBaseline('Correct Sourcemap output for '+fileName,justName.replace(/\.ts/,'.js.map'),()=>{
237240
if(options.noEmitOnError&&result.errors.length!==0&&result.sourceMaps.length===0){
238241
// We need to return null here or the runBaseLine will actually create a empty file.

‎src/harness/harness.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,10 @@ module Harness {
10161016
options.sourceRoot=setting.value;
10171017
break;
10181018

1019+
case'maproot':
1020+
options.mapRoot=setting.value;
1021+
break;
1022+
10191023
case'sourcemap':
10201024
options.sourceMap=!!setting.value;
10211025
break;
@@ -1069,6 +1073,10 @@ module Harness {
10691073
includeBuiltFiles.push({unitName:builtFileName,content:normalizeLineEndings(IO.readFile(builtFileName),newLine)});
10701074
break;
10711075

1076+
case'inlinesourcemap':
1077+
options.inlineSourceMap=setting.value==='true';
1078+
break;
1079+
10721080
default:
10731081
thrownewError('Unsupported compiler setting '+setting.flag);
10741082
}
@@ -1465,7 +1473,7 @@ module Harness {
14651473
"noimplicitany","noresolve","newline","newlines","emitbom",
14661474
"errortruncation","usecasesensitivefilenames","preserveconstenums",
14671475
"includebuiltfile","suppressimplicitanyindexerrors","stripinternal",
1468-
"separatecompilation"];
1476+
"separatecompilation","inlinesourcemap","maproot","sourceroot"];
14691477

14701478
functionextractCompilerSettings(content:string):CompilerSetting[]{
14711479

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/inlineSourceMap.ts(3,1): error TS2304: Cannot find name 'console'.
2+
3+
4+
==== tests/cases/compiler/inlineSourceMap.ts (1 errors) ====
5+
6+
var x = 0;
7+
console.log(x);
8+
~~~~~~~
9+
!!! error TS2304: Cannot find name 'console'.

‎tests/baselines/reference/inlineSourceMap.js‎

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp