Skip to content

Commit f96a7f0

Browse files
authored
Merge pull request #9166 from Microsoft/removeDotToken
Remove the stored dotToken from PropertyAccessExpression
2 parents 95ae809 + 30b3871 commit f96a7f0

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/compiler/emitter.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20762076
function createPropertyAccessExpression(expression: Expression, name: Identifier): PropertyAccessExpression {
20772077
const result = <PropertyAccessExpression>createSynthesizedNode(SyntaxKind.PropertyAccessExpression);
20782078
result.expression = parenthesizeForAccess(expression);
2079-
result.dotToken = createSynthesizedNode(SyntaxKind.DotToken);
20802079
result.name = name;
20812080
return result;
20822081
}
@@ -2223,11 +2222,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22232222
// Returns 'true' if the code was actually indented, false otherwise.
22242223
// If the code is not indented, an optional valueToWriteWhenNotIndenting will be
22252224
// emitted instead.
2226-
function indentIfOnDifferentLines(parent: Node, node1: Node, node2: Node, valueToWriteWhenNotIndenting?: string): boolean {
2225+
function indentIfOnDifferentLines(parent: Node, node1: TextRange, node2: TextRange, valueToWriteWhenNotIndenting?: string): boolean {
22272226
const realNodesAreOnDifferentLines = !nodeIsSynthesized(parent) && !nodeEndIsOnSameLineAsNodeStart(node1, node2);
22282227

22292228
// Always use a newline for synthesized code if the synthesizer desires it.
2230-
const synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2);
2229+
const synthesizedNodeIsOnDifferentLine = synthesizedNodeStartsOnNewLine(node2 as Node);
22312230

22322231
if (realNodesAreOnDifferentLines || synthesizedNodeIsOnDifferentLine) {
22332232
increaseIndent();
@@ -2257,7 +2256,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22572256
}
22582257

22592258
emit(node.expression);
2260-
const indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
2259+
const dotRangeStart = nodeIsSynthesized(node.expression) ? -1 : node.expression.end;
2260+
const dotRangeEnd = nodeIsSynthesized(node.expression) ? -1 : skipTrivia(currentText, node.expression.end) + 1;
2261+
const dotToken = <TextRange>{ pos: dotRangeStart, end: dotRangeEnd };
2262+
const indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, dotToken);
22612263

22622264
// 1 .toString is a valid property access, emit a space after the literal
22632265
// Also emit a space if expression is a integer const enum value - it will appear in generated code as numeric literal
@@ -2283,7 +2285,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22832285
write(".");
22842286
}
22852287

2286-
const indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name);
2288+
const indentedAfterDot = indentIfOnDifferentLines(node, dotToken, node.name);
22872289
emit(node.name);
22882290
decreaseIndentIf(indentedBeforeDot, indentedAfterDot);
22892291
}
@@ -2780,7 +2782,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
27802782
const identifier = emitTempVariableAssignment(leftHandSideExpression.expression, /*canDefineTempVariablesInPlace*/ false, /*shouldEmitCommaBeforeAssignment*/ false);
27812783
synthesizedLHS.expression = identifier;
27822784

2783-
(<PropertyAccessExpression>synthesizedLHS).dotToken = leftHandSideExpression.dotToken;
27842785
(<PropertyAccessExpression>synthesizedLHS).name = leftHandSideExpression.name;
27852786
write(", ");
27862787
}
@@ -3758,7 +3759,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
37583759
getLineOfLocalPositionFromLineMap(currentLineMap, node2.end);
37593760
}
37603761

3761-
function nodeEndIsOnSameLineAsNodeStart(node1: Node, node2: Node) {
3762+
function nodeEndIsOnSameLineAsNodeStart(node1: TextRange, node2: TextRange) {
37623763
return getLineOfLocalPositionFromLineMap(currentLineMap, node1.end) ===
37633764
getLineOfLocalPositionFromLineMap(currentLineMap, skipTrivia(currentText, node2.pos));
37643765
}

src/compiler/parser.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ namespace ts {
137137
return visitNodes(cbNodes, (<ObjectLiteralExpression>node).properties);
138138
case SyntaxKind.PropertyAccessExpression:
139139
return visitNode(cbNode, (<PropertyAccessExpression>node).expression) ||
140-
visitNode(cbNode, (<PropertyAccessExpression>node).dotToken) ||
141140
visitNode(cbNode, (<PropertyAccessExpression>node).name);
142141
case SyntaxKind.ElementAccessExpression:
143142
return visitNode(cbNode, (<ElementAccessExpression>node).expression) ||
@@ -3571,7 +3570,7 @@ namespace ts {
35713570
// If it wasn't then just try to parse out a '.' and report an error.
35723571
const node = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
35733572
node.expression = expression;
3574-
node.dotToken = parseExpectedToken(SyntaxKind.DotToken, /*reportAtCurrentPosition*/ false, Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
3573+
parseExpectedToken(SyntaxKind.DotToken, /*reportAtCurrentPosition*/ false, Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
35753574
node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
35763575
return finishNode(node);
35773576
}
@@ -3807,7 +3806,6 @@ namespace ts {
38073806
if (dotToken) {
38083807
const propertyAccess = <PropertyAccessExpression>createNode(SyntaxKind.PropertyAccessExpression, expression.pos);
38093808
propertyAccess.expression = expression;
3810-
propertyAccess.dotToken = dotToken;
38113809
propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
38123810
expression = finishNode(propertyAccess);
38133811
continue;

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,6 @@ namespace ts {
980980
// @kind(SyntaxKind.PropertyAccessExpression)
981981
export interface PropertyAccessExpression extends MemberExpression, Declaration {
982982
expression: LeftHandSideExpression;
983-
dotToken: Node;
984983
name: Identifier;
985984
}
986985

tests/cases/unittests/incrementalParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ module m3 { }\
647647
const oldText = ScriptSnapshot.fromString(source);
648648
const newTextAndChange = withInsert(oldText, 0, "");
649649

650-
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 8);
650+
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 7);
651651
});
652652

653653
it("Class to interface", () => {

0 commit comments

Comments
 (0)