Skip to content

Commit 0efa044

Browse files
committed
Do not include sourceMapUrl text in the sourceFile version
with only incremental and --out the compilerOptions need to be serialized only js emit enabling retain d.ts emit flags even if current options dont specify it? --out tsbuildinfo manipulation needed or not Verify all the new test outputs
1 parent e263ee1 commit 0efa044

File tree

165 files changed

+1142
-1360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+1142
-1360
lines changed

Diff for: src/compiler/sourcemap.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,10 @@ namespace ts {
322322
}
323323

324324
// Sometimes tools can see the following line as a source mapping url comment, so we mangle it a bit (the [M])
325-
const sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)\r?\n?$/;
325+
export const sourceMapCommentRegExpDontCareLineStart = /\/\/[@#] source[M]appingURL=(.+)\r?\n?$/;
326+
export const sourceMapCommentRegExp = /^\/\/[@#] source[M]appingURL=(.+)\r?\n?$/;
326327

327-
const whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/;
328+
export const whitespaceOrMapCommentRegExp = /^\s*(\/\/[@#] .*)?$/;
328329

329330
export interface LineInfo {
330331
getLineCount(): number;

Diff for: src/compiler/tsbuildPublic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ namespace ts {
16701670
if (!buildInfoVersionMap) buildInfoVersionMap = getBuildInfoFileVersionMap(buildInfoProgram, buildInfoPath!, host);
16711671
version = buildInfoVersionMap.get(toPath(state, inputFile));
16721672
const text = version ? state.readFileWithCache(inputFile) : undefined;
1673-
currentVersion = text && (host.createHash || generateDjb2Hash)(text);
1673+
currentVersion = text && getSourceFileVersionAsHashFromText(host, text);
16741674
if (version && version === currentVersion) pseudoInputUpToDate = true;
16751675
}
16761676

Diff for: src/compiler/watch.ts

+38-2
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,49 @@ namespace ts {
659659
}
660660
}
661661

662+
export function getSourceFileVersionAsHashFromText(host: Pick<CompilerHost, "createHash">, text: string) {
663+
if (text.match(sourceMapCommentRegExpDontCareLineStart)) {
664+
let lineEnd = text.length;
665+
let lineStart = lineEnd;
666+
for (let pos = lineEnd - 1; pos >= 0; pos--) {
667+
const ch = text.charCodeAt(pos);
668+
switch (ch) {
669+
case CharacterCodes.lineFeed:
670+
if (pos && text.charCodeAt(pos - 1) === CharacterCodes.carriageReturn) {
671+
pos--;
672+
}
673+
// falls through
674+
case CharacterCodes.carriageReturn:
675+
break;
676+
default:
677+
if (ch < CharacterCodes.maxAsciiCharacter || !isLineBreak(ch)) {
678+
lineStart = pos;
679+
continue;
680+
}
681+
break;
682+
}
683+
// This is start of the line
684+
const line = text.substring(lineStart, lineEnd);
685+
if (line.match(sourceMapCommentRegExp)) {
686+
text = text.substring(0, lineStart);
687+
break;
688+
}
689+
// If we see a non-whitespace/map comment-like line, break, to avoid scanning up the entire file
690+
else if (!line.match(whitespaceOrMapCommentRegExp)){
691+
break;
692+
}
693+
lineEnd = lineStart;
694+
}
695+
}
696+
return (host.createHash || generateDjb2Hash)(text);
697+
}
698+
662699
export function setGetSourceFileAsHashVersioned(compilerHost: CompilerHost, host: { createHash?(data: string): string; }) {
663700
const originalGetSourceFile = compilerHost.getSourceFile;
664-
const computeHash = maybeBind(host, host.createHash) || generateDjb2Hash;
665701
compilerHost.getSourceFile = (...args) => {
666702
const result = originalGetSourceFile.call(compilerHost, ...args);
667703
if (result) {
668-
result.version = computeHash(result.text);
704+
result.version = getSourceFileVersionAsHashFromText(host, result.text);
669705
}
670706
return result;
671707
};

Diff for: tests/baselines/reference/tsbuild/outFile/non-module-projects-without-prepend.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ c.doSomething();
369369
{"version":3,"file":"third_part1.js","sourceRoot":"","sources":["third_part1.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;AAChB,CAAC,CAAC,WAAW,EAAE,CAAC"}
370370

371371
//// [/src/third/tsconfig.tsbuildinfo]
372-
{"program":{"fileNames":["../../lib/lib.d.ts","../first/first_part1.d.ts","../first/first_part2.d.ts","../first/first_part3.d.ts","../second/second_part1.d.ts","../second/second_part2.d.ts","./third_part1.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-17939996161-interface TheFirst {\r\n none: any;\r\n}\r\ndeclare const s = \"Hello, world\";\r\ninterface NoJsForHereEither {\r\n none: any;\r\n}\r\n//# sourceMappingURL=first_PART1.d.ts.map","affectsGlobalScope":true},"-2054710634-//# sourceMappingURL=first_part2.d.ts.map",{"version":"-4577888121-declare function f(): string;\r\n//# sourceMappingURL=first_part3.d.ts.map","affectsGlobalScope":true},{"version":"-3134340341-declare namespace N {\r\n}\r\ndeclare namespace N {\r\n}\r\n//# sourceMappingURL=second_part1.d.ts.map","affectsGlobalScope":true},{"version":"6579734441-declare class C {\r\n doSomething(): void;\r\n}\r\n//# sourceMappingURL=second_part2.d.ts.map","affectsGlobalScope":true},{"version":"10470273651-var c = new C();\r\nc.doSomething();\r\n","signature":"2394638288-declare var c: C;\r\n","affectsGlobalScope":true}],"options":{"composite":true,"declaration":true,"declarationMap":true,"module":0,"removeComments":true,"skipDefaultLibCheck":true,"sourceMap":true,"strict":false,"target":1},"semanticDiagnosticsPerFile":[1,2,3,4,5,6,7],"latestChangedDtsFile":"./third_part1.d.ts"},"version":"FakeTSVersion"}
372+
{"program":{"fileNames":["../../lib/lib.d.ts","../first/first_part1.d.ts","../first/first_part2.d.ts","../first/first_part3.d.ts","../second/second_part1.d.ts","../second/second_part2.d.ts","./third_part1.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-12382020913-interface TheFirst {\r\n none: any;\r\n}\r\ndeclare const s = \"Hello, world\";\r\ninterface NoJsForHereEither {\r\n none: any;\r\n}\r\n","affectsGlobalScope":true},"-2054710634-//# sourceMappingURL=first_part2.d.ts.map",{"version":"-5732730923-declare function f(): string;\r\n","affectsGlobalScope":true},{"version":"-4200194009-declare namespace N {\r\n}\r\ndeclare namespace N {\r\n}\r\n","affectsGlobalScope":true},{"version":"1950347108-declare class C {\r\n doSomething(): void;\r\n}\r\n","affectsGlobalScope":true},{"version":"10470273651-var c = new C();\r\nc.doSomething();\r\n","signature":"2394638288-declare var c: C;\r\n","affectsGlobalScope":true}],"options":{"composite":true,"declaration":true,"declarationMap":true,"module":0,"removeComments":true,"skipDefaultLibCheck":true,"sourceMap":true,"strict":false,"target":1},"semanticDiagnosticsPerFile":[1,2,3,4,5,6,7],"latestChangedDtsFile":"./third_part1.d.ts"},"version":"FakeTSVersion"}
373373

374374
//// [/src/third/tsconfig.tsbuildinfo.readable.baseline.txt]
375375
{
@@ -390,27 +390,27 @@ c.doSomething();
390390
"affectsGlobalScope": true
391391
},
392392
"../first/first_part1.d.ts": {
393-
"version": "-17939996161-interface TheFirst {\r\n none: any;\r\n}\r\ndeclare const s = \"Hello, world\";\r\ninterface NoJsForHereEither {\r\n none: any;\r\n}\r\n//# sourceMappingURL=first_PART1.d.ts.map",
394-
"signature": "-17939996161-interface TheFirst {\r\n none: any;\r\n}\r\ndeclare const s = \"Hello, world\";\r\ninterface NoJsForHereEither {\r\n none: any;\r\n}\r\n//# sourceMappingURL=first_PART1.d.ts.map",
393+
"version": "-12382020913-interface TheFirst {\r\n none: any;\r\n}\r\ndeclare const s = \"Hello, world\";\r\ninterface NoJsForHereEither {\r\n none: any;\r\n}\r\n",
394+
"signature": "-12382020913-interface TheFirst {\r\n none: any;\r\n}\r\ndeclare const s = \"Hello, world\";\r\ninterface NoJsForHereEither {\r\n none: any;\r\n}\r\n",
395395
"affectsGlobalScope": true
396396
},
397397
"../first/first_part2.d.ts": {
398398
"version": "-2054710634-//# sourceMappingURL=first_part2.d.ts.map",
399399
"signature": "-2054710634-//# sourceMappingURL=first_part2.d.ts.map"
400400
},
401401
"../first/first_part3.d.ts": {
402-
"version": "-4577888121-declare function f(): string;\r\n//# sourceMappingURL=first_part3.d.ts.map",
403-
"signature": "-4577888121-declare function f(): string;\r\n//# sourceMappingURL=first_part3.d.ts.map",
402+
"version": "-5732730923-declare function f(): string;\r\n",
403+
"signature": "-5732730923-declare function f(): string;\r\n",
404404
"affectsGlobalScope": true
405405
},
406406
"../second/second_part1.d.ts": {
407-
"version": "-3134340341-declare namespace N {\r\n}\r\ndeclare namespace N {\r\n}\r\n//# sourceMappingURL=second_part1.d.ts.map",
408-
"signature": "-3134340341-declare namespace N {\r\n}\r\ndeclare namespace N {\r\n}\r\n//# sourceMappingURL=second_part1.d.ts.map",
407+
"version": "-4200194009-declare namespace N {\r\n}\r\ndeclare namespace N {\r\n}\r\n",
408+
"signature": "-4200194009-declare namespace N {\r\n}\r\ndeclare namespace N {\r\n}\r\n",
409409
"affectsGlobalScope": true
410410
},
411411
"../second/second_part2.d.ts": {
412-
"version": "6579734441-declare class C {\r\n doSomething(): void;\r\n}\r\n//# sourceMappingURL=second_part2.d.ts.map",
413-
"signature": "6579734441-declare class C {\r\n doSomething(): void;\r\n}\r\n//# sourceMappingURL=second_part2.d.ts.map",
412+
"version": "1950347108-declare class C {\r\n doSomething(): void;\r\n}\r\n",
413+
"signature": "1950347108-declare class C {\r\n doSomething(): void;\r\n}\r\n",
414414
"affectsGlobalScope": true
415415
},
416416
"./third_part1.ts": {
@@ -442,6 +442,6 @@ c.doSomething();
442442
"latestChangedDtsFile": "./third_part1.d.ts"
443443
},
444444
"version": "FakeTSVersion",
445-
"size": 1855
445+
"size": 1689
446446
}
447447

0 commit comments

Comments
 (0)