Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2b9e4aa
Allow emitter to write multiple newlines in node lists
andrewbranch Feb 6, 2020
c689617
Progress
andrewbranch Feb 7, 2020
6e272f3
Progress
andrewbranch Feb 7, 2020
839fb8e
Fix recomputeIndentation
andrewbranch Feb 7, 2020
0ea8d79
Add tests, fix leading line terminator count
andrewbranch Feb 7, 2020
6ff9c2b
Do a bit less work when `preserveNewlines` is off
andrewbranch Feb 10, 2020
c91efd4
Fix accidental find/replace rename
andrewbranch Feb 11, 2020
e3ef427
Restore some monomorphism
andrewbranch Feb 19, 2020
e535e27
Fix single line writer
andrewbranch Feb 19, 2020
21b0cb8
Fix other writers
andrewbranch Feb 19, 2020
b6cf73d
Merge branch 'master' into bug/27294
andrewbranch Feb 19, 2020
0c536c5
Revert "Fix other writers"
andrewbranch Feb 19, 2020
91eaf80
Revert "Fix single line writer"
andrewbranch Feb 19, 2020
3be2c86
Revert "Restore some monomorphism"
andrewbranch Feb 19, 2020
8ed98bc
Add equal position optimization to getLinesBetweenRangeEndAndRangeStart
andrewbranch Feb 19, 2020
d9c80fd
Add one more test
andrewbranch Feb 19, 2020
af188d4
Actually save the test file
andrewbranch Feb 19, 2020
19a9728
Rename preserveNewlines to preserveSourceNewlines
andrewbranch Feb 28, 2020
131f2bb
Make ignoreSourceNewlines internal
andrewbranch Feb 28, 2020
34147a5
Optimize lines-between functions
andrewbranch Mar 2, 2020
cf96308
Merge branch 'master' into bug/27294
andrewbranch Mar 2, 2020
075c782
Add comment;
andrewbranch Mar 2, 2020
563d223
Fix trailing line terminator count bug for function parameters
andrewbranch Mar 13, 2020
8b61d66
Preserve newlines around parenthesized expressions
andrewbranch Mar 14, 2020
e7c2b28
Merge branch 'master' into bug/27294
andrewbranch Mar 14, 2020
e99d833
Back to speculative microoptimizations, yay
andrewbranch Mar 16, 2020
ac768d0
Don’t call getEffectiveLines during tsc emit at all
andrewbranch Mar 16, 2020
6daa27e
Merge branch 'master' into bug/27294
andrewbranch Mar 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don’t call getEffectiveLines during tsc emit at all
  • Loading branch information
andrewbranch committed Mar 16, 2020
commit ac768d030290290ade1a951624fb6f7d76521666
38 changes: 21 additions & 17 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4323,12 +4323,15 @@ namespace ts {
return 0;
}
else if (!nodeIsSynthesized(previousNode) && !nodeIsSynthesized(nextNode) && previousNode.parent === nextNode.parent) {
return getEffectiveLines(
includeComments => getLinesBetweenRangeEndAndRangeStart(
previousNode,
nextNode,
currentSourceFile!,
includeComments));
if (preserveSourceNewlines) {
return getEffectiveLines(
includeComments => getLinesBetweenRangeEndAndRangeStart(
previousNode,
nextNode,
currentSourceFile!,
includeComments));
}
return rangeEndIsOnSameLineAsRangeStart(previousNode, nextNode, currentSourceFile!) ? 0 : 1;
}
else if (synthesizedNodeStartsOnNewLine(previousNode, format) || synthesizedNodeStartsOnNewLine(nextNode, format)) {
Comment thread
andrewbranch marked this conversation as resolved.
return 1;
Expand Down Expand Up @@ -4371,11 +4374,9 @@ namespace ts {
}

function getEffectiveLines(getLineDifference: (includeComments: boolean) => number) {
// If 'preserveSourceNewlines' is disabled, skip the more accurate check that might require
// querying for source positions twice.
if (!preserveSourceNewlines) {
return Math.min(1, getLineDifference(/*includeComments*/ false));
}
// If 'preserveSourceNewlines' is disabled, we should never call this function
// because it could be more expensive than alternative approximations.
Debug.assert(!!preserveSourceNewlines);
// We start by measuring the line difference from a position to its adjacent comments,
// so that this is counted as a one-line difference, not two:
//
Expand Down Expand Up @@ -4424,12 +4425,15 @@ namespace ts {
}

if (!nodeIsSynthesized(parent) && !nodeIsSynthesized(node1) && !nodeIsSynthesized(node2)) {
return getEffectiveLines(
includeComments => getLinesBetweenRangeEndAndRangeStart(
node1,
node2,
currentSourceFile!,
includeComments));
if (preserveSourceNewlines) {
return getEffectiveLines(
includeComments => getLinesBetweenRangeEndAndRangeStart(
node1,
node2,
currentSourceFile!,
includeComments));
}
return rangeEndIsOnSameLineAsRangeStart(node1, node2, currentSourceFile!) ? 0 : 1;
}

return 0;
Expand Down