Skip to content

Commit 648ce65

Browse files
committed
Do not include the source map url as file version
1 parent cec43d8 commit 648ce65

File tree

215 files changed

+2192
-2380
lines changed

Some content is hidden

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

215 files changed

+2192
-2380
lines changed

src/compiler/sourcemap.ts

Lines changed: 3 additions & 2 deletions
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;

src/compiler/tsbuildPublic.ts

Lines changed: 1 addition & 1 deletion
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

src/compiler/watch.ts

Lines changed: 38 additions & 2 deletions
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
};

tests/baselines/reference/tsbuild/amdModulesWithOut/modules-and-globals-mixed-in-amd.js

Lines changed: 16 additions & 16 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsbuild/amdModulesWithOut/multiple-emitHelpers-in-all-projects.js

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsbuild/amdModulesWithOut/multiple-prologues-in-all-projects.js

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsbuild/amdModulesWithOut/shebang-in-all-projects.js

Lines changed: 16 additions & 16 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsbuild/amdModulesWithOut/stripInternal.js

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsbuild/amdModulesWithOut/triple-slash-refs-in-all-projects.js

Lines changed: 16 additions & 16 deletions
Large diffs are not rendered by default.

tests/baselines/reference/tsbuild/amdModulesWithOut/when-the-module-resolution-finds-original-source-file.js

Lines changed: 8 additions & 8 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)