Merge pull request #1105 from Microsoft/trailingTrivia

Trailing trivia
This commit is contained in:
CyrusNajmabadi
2014-11-10 15:52:30 -08:00
32 changed files with 598 additions and 1273 deletions
+1 -6
View File
@@ -96,11 +96,6 @@ module TypeScript.Services.Formatting {
}
this.previousTokenParent = this.parent().clone(this.indentationNodeContextPool());
position += width(token);
// Extract any trailing comments
if (token.trailingTriviaWidth() !== 0) {
this.processTrivia(token.trailingTrivia(), position);
}
}
private processTrivia(triviaList: ISyntaxTriviaList, fullStart: number) {
@@ -110,7 +105,7 @@ module TypeScript.Services.Formatting {
var trivia = triviaList.syntaxTriviaAt(i);
// For a comment, format it like it is a token. For skipped text, eat it up as a token, but skip the formatting
if (trivia.isComment() || trivia.isSkippedToken()) {
var currentTokenSpan = new TokenSpan(trivia.kind(), position, trivia.fullWidth());
var currentTokenSpan = new TokenSpan(trivia.kind, position, trivia.fullWidth());
if (this.textSpan().containsTextSpan(currentTokenSpan)) {
if (trivia.isComment() && this.previousTokenSpan) {
// Note that formatPair calls TrimWhitespaceInLineRange in between the 2 tokens
+1 -1
View File
@@ -109,7 +109,7 @@ module TypeScript.Services.Formatting {
var block = <BlockSyntax>node.node();
// Now check if they are on the same line
return this.snapshot.getLineNumberFromPosition(end(block.openBraceToken)) ===
return this.snapshot.getLineNumberFromPosition(fullEnd(block.openBraceToken)) ===
this.snapshot.getLineNumberFromPosition(start(block.closeBraceToken));
}
}
+2 -2
View File
@@ -46,7 +46,7 @@ module TypeScript.Services.Formatting {
// Find the outer most parent that this semicolon terminates
var current: ISyntaxElement = semicolonPositionedToken;
while (current.parent !== null &&
end(current.parent) === end(semicolonPositionedToken) &&
fullEnd(current.parent) === fullEnd(semicolonPositionedToken) &&
current.parent.kind !== SyntaxKind.List) {
current = current.parent;
}
@@ -69,7 +69,7 @@ module TypeScript.Services.Formatting {
// Find the outer most parent that this closing brace terminates
var current: ISyntaxElement = closeBracePositionedToken;
while (current.parent !== null &&
end(current.parent) === end(closeBracePositionedToken) &&
fullEnd(current.parent) === fullEnd(closeBracePositionedToken) &&
current.parent.kind !== SyntaxKind.List) {
current = current.parent;
}
@@ -90,8 +90,14 @@ module TypeScript.Services.Formatting {
this.visitTokenInSpan(token);
// Only track new lines on tokens within the range. Make sure to check that the last trivia is a newline, and not just one of the trivia
var trivia = token.trailingTrivia();
this._lastTriviaWasNewLine = trivia.hasNewLine() && trivia.syntaxTriviaAt(trivia.count() - 1).kind() == SyntaxKind.NewLineTrivia;
var _nextToken = nextToken(token);
if (_nextToken && _nextToken.hasLeadingTrivia()) {
var trivia = _nextToken.leadingTrivia();
this._lastTriviaWasNewLine = trivia.hasNewLine();
}
else {
this._lastTriviaWasNewLine = false;
}
}
// Update the position
@@ -353,7 +359,7 @@ module TypeScript.Services.Formatting {
private forceRecomputeIndentationOfParent(tokenStart: number, newLineAdded: boolean /*as opposed to removed*/): void {
var parent = this._parent;
if (parent.fullStart() === tokenStart) {
if (start(parent.node()) === tokenStart) {
// Temporarily pop the parent before recomputing
this._parent = parent.parent();
var indentation = this.getNodeIndentation(parent.node(), /* newLineInsertedByFormatting */ newLineAdded);
@@ -66,14 +66,29 @@ module TypeScript.Services.Formatting {
// Process any leading trivia if any
var triviaList = token.leadingTrivia();
if (triviaList) {
var seenNewLine = position === 0;
for (var i = 0, length = triviaList.count(); i < length; i++, position += trivia.fullWidth()) {
var trivia = triviaList.syntaxTriviaAt(i);
// Skip all trivia up to the first newline we see. We consider this trivia to
// 'belong' to the previous token.
if (!seenNewLine) {
if (trivia.kind !== SyntaxKind.NewLineTrivia) {
continue;
}
else {
seenNewLine = true;
continue;
}
}
// Skip this trivia if it is not in the span
if (!this.textSpan().containsTextSpan(new TextSpan(position, trivia.fullWidth()))) {
continue;
}
switch (trivia.kind()) {
switch (trivia.kind) {
case SyntaxKind.MultiLineCommentTrivia:
// We will only indent the first line of the multiline comment if we were planning to indent the next trivia. However,
// subsequent lines will always be indented
-105
View File
@@ -1,110 +1,5 @@
module TypeScript.Indentation {
export function columnForEndOfTokenAtPosition(syntaxTree: SyntaxTree, position: number, options: FormattingOptions): number {
var token = findToken(syntaxTree.sourceUnit(), position);
return columnForStartOfTokenAtPosition(syntaxTree, position, options) + width(token);
}
export function columnForStartOfTokenAtPosition(syntaxTree: SyntaxTree, position: number, options: FormattingOptions): number {
var token = findToken(syntaxTree.sourceUnit(), position);
// Walk backward from this token until we find the first token in the line. For each token
// we see (that is not the first tokem in line), push the entirety of the text into the text
// array. Then, for the first token, add its text (without its leading trivia) to the text
// array. i.e. if we have:
//
// var foo = a => bar();
//
// And we want the column for the start of 'bar', then we'll add the underlinded portions to
// the text array:
//
// var foo = a => bar();
// _
// __
// __
// ____
// ____
var firstTokenInLine = Syntax.firstTokenInLineContainingPosition(syntaxTree, token.fullStart());
var leadingTextInReverse: string[] = [];
var current = token;
while (current !== firstTokenInLine) {
current = previousToken(current);
if (current === firstTokenInLine) {
// We're at the first token in teh line.
// We don't want the leading trivia for this token. That will be taken care of in
// columnForFirstNonWhitespaceCharacterInLine. So just push the trailing trivia
// and then the token text.
leadingTextInReverse.push(current.trailingTrivia().fullText());
leadingTextInReverse.push(current.text());
}
else {
// We're at an intermediate token on the line. Just push all its text into the array.
leadingTextInReverse.push(current.fullText());
}
}
// Now, add all trivia to the start of the line on the first token in the list.
collectLeadingTriviaTextToStartOfLine(firstTokenInLine, leadingTextInReverse);
return columnForLeadingTextInReverse(leadingTextInReverse, options);
}
export function columnForStartOfFirstTokenInLineContainingPosition(syntaxTree: SyntaxTree, position: number, options: FormattingOptions): number {
// Walk backward through the tokens until we find the first one on the line.
var firstTokenInLine = Syntax.firstTokenInLineContainingPosition(syntaxTree, position);
var leadingTextInReverse: string[] = [];
// Now, add all trivia to the start of the line on the first token in the list.
collectLeadingTriviaTextToStartOfLine(firstTokenInLine, leadingTextInReverse);
return columnForLeadingTextInReverse(leadingTextInReverse, options);
}
// Collect all the trivia that precedes this token. Stopping when we hit a newline trivia
// or a multiline comment that spans multiple lines. This is meant to be called on the first
// token in a line.
function collectLeadingTriviaTextToStartOfLine(firstTokenInLine: ISyntaxToken,
leadingTextInReverse: string[]) {
var leadingTrivia = firstTokenInLine.leadingTrivia();
for (var i = leadingTrivia.count() - 1; i >= 0; i--) {
var trivia = leadingTrivia.syntaxTriviaAt(i);
if (trivia.kind() === SyntaxKind.NewLineTrivia) {
break;
}
if (trivia.kind() === SyntaxKind.MultiLineCommentTrivia) {
var lineSegments = Syntax.splitMultiLineCommentTriviaIntoMultipleLines(trivia);
leadingTextInReverse.push(ArrayUtilities.last(lineSegments));
if (lineSegments.length > 0) {
// This multiline comment actually spanned multiple lines. So we're done.
break;
}
// It was only on a single line, so keep on going.
}
leadingTextInReverse.push(trivia.fullText());
}
}
function columnForLeadingTextInReverse(leadingTextInReverse: string[],
options: FormattingOptions): number {
var column = 0;
// walk backwards. This means we're actually walking forward from column 0 to the start of
// the token.
for (var i = leadingTextInReverse.length - 1; i >= 0; i--) {
var text = leadingTextInReverse[i];
column = columnForPositionInStringWorker(text, text.length, column, options);
}
return column;
}
// Returns the column that this input string ends at (assuming it starts at column 0).
export function columnForPositionInString(input: string, position: number, options: FormattingOptions): number {
return columnForPositionInStringWorker(input, position, 0, options);
+9 -17
View File
@@ -998,8 +998,7 @@ var definitions = [
children: [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'moduleKeyword', isToken: true, excludeFromAST: true },
{ name: 'name', type: 'INameSyntax', isOptional: true },
{ name: 'stringLiteral', isToken: true, isOptional: true, tokenKinds: ['StringLiteral'] },
{ name: 'name', type: 'INameSyntax' },
{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
{ name: 'moduleElements', isList: true, elementType: 'IModuleElementSyntax' },
{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
@@ -1015,8 +1014,7 @@ var definitions = [
{ name: 'functionKeyword', isToken: true, excludeFromAST: true },
{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
{ name: 'callSignature', type: 'CallSignatureSyntax' },
{ name: 'block', type: 'BlockSyntax', isOptional: true },
{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
]
},
{
@@ -1096,8 +1094,7 @@ var definitions = [
children: [
{ name: 'parameter', type: 'ParameterSyntax' },
{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
{ name: 'block', type: 'BlockSyntax', isOptional: true },
{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
],
isTypeScriptSpecific: true
},
@@ -1108,8 +1105,7 @@ var definitions = [
children: [
{ name: 'callSignature', type: 'CallSignatureSyntax' },
{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
{ name: 'block', type: 'BlockSyntax', isOptional: true },
{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
],
isTypeScriptSpecific: true
},
@@ -1490,8 +1486,7 @@ var definitions = [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'constructorKeyword', isToken: true },
{ name: 'callSignature', type: 'CallSignatureSyntax' },
{ name: 'block', type: 'BlockSyntax', isOptional: true },
{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
],
isTypeScriptSpecific: true
},
@@ -1503,8 +1498,7 @@ var definitions = [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'propertyName', type: 'IPropertyNameSyntax' },
{ name: 'callSignature', type: 'CallSignatureSyntax' },
{ name: 'block', type: 'BlockSyntax', isOptional: true },
{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
],
isTypeScriptSpecific: true
},
@@ -1647,8 +1641,7 @@ var definitions = [
children: [
{ name: 'forKeyword', isToken: true, excludeFromAST: true },
{ name: 'openParenToken', isToken: true, excludeFromAST: true },
{ name: 'variableDeclaration', type: 'VariableDeclarationSyntax', isOptional: true },
{ name: 'initializer', type: 'IExpressionSyntax', isOptional: true },
{ name: 'initializer', type: 'VariableDeclarationSyntax | IExpressionSyntax', isOptional: true },
{ name: 'firstSemicolonToken', isToken: true, tokenKinds: ['SemicolonToken'], excludeFromAST: true },
{ name: 'condition', type: 'IExpressionSyntax', isOptional: true },
{ name: 'secondSemicolonToken', isToken: true, tokenKinds: ['SemicolonToken'], excludeFromAST: true },
@@ -1664,10 +1657,9 @@ var definitions = [
children: [
{ name: 'forKeyword', isToken: true, excludeFromAST: true },
{ name: 'openParenToken', isToken: true, excludeFromAST: true },
{ name: 'variableDeclaration', type: 'VariableDeclarationSyntax', isOptional: true },
{ name: 'left', type: 'IExpressionSyntax', isOptional: true },
{ name: 'left', type: 'VariableDeclarationSyntax | IExpressionSyntax' },
{ name: 'inKeyword', isToken: true, excludeFromAST: true },
{ name: 'expression', type: 'IExpressionSyntax' },
{ name: 'right', type: 'IExpressionSyntax' },
{ name: 'closeParenToken', isToken: true, excludeFromAST: true },
{ name: 'statement', type: 'IStatementSyntax' }
]
File diff suppressed because one or more lines are too long
+2
View File
@@ -529,6 +529,8 @@ module TypeScript.IncrementalParser {
}
function consumeToken(currentToken: ISyntaxToken): void {
// Debug.assert(currentToken.fullWidth() > 0 || currentToken.kind === SyntaxKind.EndOfFileToken);
// This token may have come from the old source unit, or from the new text. Handle
// both accordingly.
File diff suppressed because it is too large Load Diff
+11 -18
View File
@@ -305,9 +305,6 @@ module TypeScript.PrettyPrinter {
this.ensureSpace();
this.appendElement(node.name);
this.ensureSpace();
this.appendToken(node.stringLiteral);
this.ensureSpace();
this.appendToken(node.openBraceToken);
this.ensureNewLine();
@@ -319,13 +316,13 @@ module TypeScript.PrettyPrinter {
this.appendToken(node.closeBraceToken);
}
private appendBlockOrSemicolon(block: BlockSyntax, semicolonToken: ISyntaxToken) {
if (block) {
private appendBlockOrSemicolon(body: BlockSyntax | ISyntaxToken) {
if (body.kind === SyntaxKind.Block) {
this.ensureSpace();
visitNodeOrToken(this, block);
visitNodeOrToken(this, body);
}
else {
this.appendToken(semicolonToken);
this.appendToken(<ISyntaxToken>body);
}
}
@@ -336,7 +333,7 @@ module TypeScript.PrettyPrinter {
this.ensureSpace();
this.appendToken(node.identifier);
this.appendNode(node.callSignature);
this.appendBlockOrSemicolon(node.block, node.semicolonToken);
this.appendBlockOrSemicolon(node.body);
}
public visitVariableStatement(node: VariableStatementSyntax): void {
@@ -390,8 +387,7 @@ module TypeScript.PrettyPrinter {
this.ensureSpace();
this.appendToken(node.equalsGreaterThanToken);
this.ensureSpace();
this.appendNode(node.block);
this.appendElement(node.expression);
visitNodeOrToken(this, node.body);
}
public visitParenthesizedArrowFunctionExpression(node: ParenthesizedArrowFunctionExpressionSyntax): void {
@@ -399,8 +395,7 @@ module TypeScript.PrettyPrinter {
this.ensureSpace();
this.appendToken(node.equalsGreaterThanToken);
this.ensureSpace();
this.appendNode(node.block);
this.appendElement(node.expression);
visitNodeOrToken(this, node.body);
}
public visitQualifiedName(node: QualifiedNameSyntax): void {
@@ -671,7 +666,7 @@ module TypeScript.PrettyPrinter {
public visitConstructorDeclaration(node: ConstructorDeclarationSyntax): void {
this.appendToken(node.constructorKeyword);
visitNodeOrToken(this, node.callSignature);
this.appendBlockOrSemicolon(node.block, node.semicolonToken);
this.appendBlockOrSemicolon(node.body);
}
public visitIndexMemberDeclaration(node: IndexMemberDeclarationSyntax): void {
@@ -686,7 +681,7 @@ module TypeScript.PrettyPrinter {
this.ensureSpace();
visitNodeOrToken(this, node.propertyName);
visitNodeOrToken(this, node.callSignature);
this.appendBlockOrSemicolon(node.block, node.semicolonToken);
this.appendBlockOrSemicolon(node.body);
}
public visitGetAccessor(node: GetAccessorSyntax): void {
@@ -825,8 +820,7 @@ module TypeScript.PrettyPrinter {
this.appendToken(node.forKeyword);
this.ensureSpace();
this.appendToken(node.openParenToken);
this.appendNode(node.variableDeclaration);
this.appendElement(node.initializer);
visitNodeOrToken(this, node.initializer);
this.appendToken(node.firstSemicolonToken);
if (node.condition) {
@@ -849,12 +843,11 @@ module TypeScript.PrettyPrinter {
this.appendToken(node.forKeyword);
this.ensureSpace();
this.appendToken(node.openParenToken);
this.appendNode(node.variableDeclaration);
this.appendElement(node.left);
this.ensureSpace();
this.appendToken(node.inKeyword);
this.ensureSpace();
this.appendElement(node.expression);
this.appendElement(node.right);
this.appendToken(node.closeParenToken);
this.appendBlockOrStatement(node.statement);
}
+49 -105
View File
@@ -60,8 +60,7 @@ module TypeScript.Scanner {
// This gives us 23bit for width (or 8MB of width which should be enough for any codebase).
enum ScannerConstants {
LargeTokenFullWidthShift = 6,
LargeTokenLeadingTriviaShift = 3,
LargeTokenFullWidthShift = 3,
WhitespaceTrivia = 0x01, // 00000001
NewlineTrivia = 0x02, // 00000010
@@ -72,8 +71,8 @@ module TypeScript.Scanner {
IsVariableWidthMask = 0x80, // 10000000
}
function largeTokenPackData(fullWidth: number, leadingTriviaInfo: number, trailingTriviaInfo: number) {
return (fullWidth << ScannerConstants.LargeTokenFullWidthShift) | (leadingTriviaInfo << ScannerConstants.LargeTokenLeadingTriviaShift) | trailingTriviaInfo;
function largeTokenPackData(fullWidth: number, leadingTriviaInfo: number) {
return (fullWidth << ScannerConstants.LargeTokenFullWidthShift) | leadingTriviaInfo;
}
function largeTokenUnpackFullWidth(packedFullWidthAndInfo: number): number {
@@ -81,10 +80,6 @@ module TypeScript.Scanner {
}
function largeTokenUnpackLeadingTriviaInfo(packedFullWidthAndInfo: number): number {
return (packedFullWidthAndInfo >> ScannerConstants.LargeTokenLeadingTriviaShift) & ScannerConstants.TriviaMask;
}
function largeTokenUnpackTrailingTriviaInfo(packedFullWidthAndInfo: number): number {
return packedFullWidthAndInfo & ScannerConstants.TriviaMask;
}
@@ -92,20 +87,20 @@ module TypeScript.Scanner {
return largeTokenUnpackLeadingTriviaInfo(packed) !== 0;
}
function largeTokenUnpackHasTrailingTrivia(packed: number): boolean {
return largeTokenUnpackTrailingTriviaInfo(packed) !== 0;
}
function hasComment(info: number) {
return (info & ScannerConstants.CommentTrivia) !== 0;
}
function largeTokenUnpackHasLeadingComment(packed: number): boolean {
return hasComment(largeTokenUnpackLeadingTriviaInfo(packed));
function hasNewLine(info: number) {
return (info & ScannerConstants.NewlineTrivia) !== 0;
}
function largeTokenUnpackHasTrailingComment(packed: number): boolean {
return hasComment(largeTokenUnpackTrailingTriviaInfo(packed));
function largeTokenUnpackHasLeadingNewLine(packed: number): boolean {
return hasNewLine(largeTokenUnpackLeadingTriviaInfo(packed));
}
function largeTokenUnpackHasLeadingComment(packed: number): boolean {
return hasComment(largeTokenUnpackLeadingTriviaInfo(packed));
}
var isKeywordStartCharacter: number[] = ArrayUtilities.createArray<number>(CharacterCodes.maxAsciiCharacter, 0);
@@ -156,7 +151,7 @@ module TypeScript.Scanner {
}
}
var lastTokenInfo = { leadingTriviaWidth: -1, width: -1 };
var lastTokenInfo = { leadingTriviaWidth: -1 };
var lastTokenInfoTokenID: number = -1;
var triviaScanner = createScannerInternal(ts.ScriptTarget.Latest, SimpleText.fromString(""), () => { });
@@ -180,15 +175,7 @@ module TypeScript.Scanner {
return Syntax.emptyTriviaList;
}
return triviaScanner.scanTrivia(token, text, /*isTrailing:*/ false);
}
function trailingTrivia(token: IScannerToken, text: ISimpleText): ISyntaxTriviaList {
if (!token.hasTrailingTrivia()) {
return Syntax.emptyTriviaList;
}
return triviaScanner.scanTrivia(token, text, /*isTrailing:*/ true);
return triviaScanner.scanTrivia(token, text);
}
function leadingTriviaWidth(token: IScannerToken, text: ISimpleText): number {
@@ -200,15 +187,6 @@ module TypeScript.Scanner {
return lastTokenInfo.leadingTriviaWidth;
}
function trailingTriviaWidth(token: IScannerToken, text: ISimpleText): number {
if (!token.hasTrailingTrivia()) {
return 0;
}
fillSizeInfo(token, text);
return token.fullWidth() - lastTokenInfo.leadingTriviaWidth - lastTokenInfo.width;
}
function tokenIsIncrementallyUnusable(token: IScannerToken): boolean {
// No scanner tokens make their *containing node* incrementally unusable.
// Note: several scanner tokens may themselves be unusable. i.e. if the parser asks
@@ -231,24 +209,21 @@ module TypeScript.Scanner {
}
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
public isIncrementallyUnusable(): boolean { return false; }
public isKeywordConvertedToIdentifier(): boolean { return false; }
public hasSkippedToken(): boolean { return false; }
public fullText(): string { return SyntaxFacts.getText(this.kind); }
public text(): string { return this.fullText(); }
public leadingTrivia(): ISyntaxTriviaList { return Syntax.emptyTriviaList; }
public trailingTrivia(): ISyntaxTriviaList { return Syntax.emptyTriviaList; }
public leadingTriviaWidth(): number { return 0; }
public trailingTriviaWidth(): number { return 0; }
public fullWidth(): number { return fixedWidthTokenLength(this.kind); }
public fullStart(): number { return this._fullStart; }
public hasLeadingTrivia(): boolean { return false; }
public hasTrailingTrivia(): boolean { return false; }
public hasLeadingNewLine(): boolean { return false; }
public hasLeadingSkippedToken(): boolean { return false; }
public hasLeadingComment(): boolean { return false; }
public hasTrailingComment(): boolean { return false; }
public clone(): ISyntaxToken { return new FixedWidthTokenWithNoTrivia(this._fullStart, this.kind); }
}
FixedWidthTokenWithNoTrivia.prototype.childCount = 0;
@@ -271,7 +246,6 @@ module TypeScript.Scanner {
}
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
private syntaxTreeText(text: ISimpleText) {
var result = text || syntaxTree(this).text;
@@ -281,7 +255,6 @@ module TypeScript.Scanner {
public isIncrementallyUnusable(): boolean { return tokenIsIncrementallyUnusable(this); }
public isKeywordConvertedToIdentifier(): boolean { return false; }
public hasSkippedToken(): boolean { return false; }
public fullText(text?: ISimpleText): string {
return fullText(this, this.syntaxTreeText(text));
@@ -293,22 +266,16 @@ module TypeScript.Scanner {
}
public leadingTrivia(text?: ISimpleText): ISyntaxTriviaList { return leadingTrivia(this, this.syntaxTreeText(text)); }
public trailingTrivia(text?: ISimpleText): ISyntaxTriviaList { return trailingTrivia(this, this.syntaxTreeText(text)); }
public leadingTriviaWidth(text?: ISimpleText): number {
return leadingTriviaWidth(this, this.syntaxTreeText(text));
}
public trailingTriviaWidth(text?: ISimpleText): number {
return trailingTriviaWidth(this, this.syntaxTreeText(text));
}
public leadingTriviaWidth(text?: ISimpleText): number { return leadingTriviaWidth(this, this.syntaxTreeText(text)); }
public fullWidth(): number { return largeTokenUnpackFullWidth(this._packedFullWidthAndInfo); }
public fullStart(): number { return this._fullStart; }
public hasLeadingTrivia(): boolean { return largeTokenUnpackHasLeadingTrivia(this._packedFullWidthAndInfo); }
public hasTrailingTrivia(): boolean { return largeTokenUnpackHasTrailingTrivia(this._packedFullWidthAndInfo); }
public hasLeadingNewLine(): boolean { return largeTokenUnpackHasLeadingNewLine(this._packedFullWidthAndInfo); }
public hasLeadingComment(): boolean { return largeTokenUnpackHasLeadingComment(this._packedFullWidthAndInfo); }
public hasTrailingComment(): boolean { return largeTokenUnpackHasTrailingComment(this._packedFullWidthAndInfo); }
public hasLeadingSkippedToken(): boolean { return false; }
public clone(): ISyntaxToken { return new LargeScannerToken(this._fullStart, this.kind, this._packedFullWidthAndInfo, this.cachedText); }
}
LargeScannerToken.prototype.childCount = 0;
@@ -319,12 +286,11 @@ module TypeScript.Scanner {
interface TokenInfo {
leadingTriviaWidth: number;
width: number;
}
interface IScannerInternal extends IScanner {
fillTokenInfo(token: IScannerToken, text: ISimpleText, tokenInfo: TokenInfo): void;
scanTrivia(token: IScannerToken, text: ISimpleText, isTrailing: boolean): ISyntaxTriviaList;
scanTrivia(token: IScannerToken, text: ISimpleText): ISyntaxTriviaList;
}
export interface IScanner {
@@ -367,15 +333,13 @@ module TypeScript.Scanner {
function scan(allowContextualToken: boolean): ISyntaxToken {
var fullStart = index;
var leadingTriviaInfo = scanTriviaInfo(/*isTrailing: */ false);
var leadingTriviaInfo = scanTriviaInfo();
var start = index;
var kindAndIsVariableWidth = scanSyntaxKind(allowContextualToken);
var end = index;
var trailingTriviaInfo = scanTriviaInfo(/*isTrailing: */true);
var fullWidth = index - fullStart;
var fullEnd = index;
var fullWidth = fullEnd - fullStart;
// If we have no trivia, and we are a fixed width token kind, and our size isn't too
// large, and we're a real fixed width token (and not something like "\u0076ar").
@@ -383,28 +347,21 @@ module TypeScript.Scanner {
var isFixedWidth = kind >= SyntaxKind.FirstFixedWidth && kind <= SyntaxKind.LastFixedWidth &&
((kindAndIsVariableWidth & ScannerConstants.IsVariableWidthMask) === 0);
if (isFixedWidth &&
leadingTriviaInfo === 0 && trailingTriviaInfo === 0) {
if (isFixedWidth && leadingTriviaInfo === 0) {
return new FixedWidthTokenWithNoTrivia(fullStart, kind);
}
else {
var packedFullWidthAndInfo = largeTokenPackData(fullWidth, leadingTriviaInfo, trailingTriviaInfo);
var cachedText = isFixedWidth ? undefined : text.substr(start, end - start);
var packedFullWidthAndInfo = largeTokenPackData(fullWidth, leadingTriviaInfo);
var cachedText = isFixedWidth ? undefined : text.substr(start, fullEnd - start);
return new LargeScannerToken(fullStart, kind, packedFullWidthAndInfo, cachedText);
}
}
function scanTrivia(parent: IScannerToken, text: ISimpleText, isTrailing: boolean): ISyntaxTriviaList {
function scanTrivia(parent: IScannerToken, text: ISimpleText): ISyntaxTriviaList {
var tokenFullStart = parent.fullStart();
var tokenStart = tokenFullStart + leadingTriviaWidth(parent, text)
if (isTrailing) {
reset(text, tokenStart + parent.text().length, tokenFullStart + parent.fullWidth());
}
else {
reset(text, tokenFullStart, tokenStart);
}
reset(text, tokenFullStart, tokenStart);
// Debug.assert(length > 0);
// Keep this exactly in sync with scanTriviaInfo
@@ -461,15 +418,7 @@ module TypeScript.Scanner {
case CharacterCodes.paragraphSeparator:
case CharacterCodes.lineSeparator:
trivia.push(scanLineTerminatorSequenceTrivia(ch));
// If we're consuming leading trivia, then we will continue consuming more
// trivia (including newlines) up to the first token we see. If we're
// consuming trailing trivia, then we break after the first newline we see.
if (!isTrailing) {
continue;
}
break;
continue;
default:
throw Errors.invalidOperation();
@@ -486,7 +435,7 @@ module TypeScript.Scanner {
// Returns 0 if there was no trivia, or 1 if there was trivia. Returned as an int instead
// of a boolean because we'll need a numerical value later on to store in our tokens.
function scanTriviaInfo(isTrailing: boolean): number {
function scanTriviaInfo(): number {
// Keep this exactly in sync with scanTrivia
var result = 0;
var _end = end;
@@ -516,14 +465,6 @@ module TypeScript.Scanner {
// we have trivia
result |= ScannerConstants.NewlineTrivia;
// If we're consuming leading trivia, then we will continue consuming more
// trivia (including newlines) up to the first token we see. If we're
// consuming trailing trivia, then we break after the first newline we see.
if (isTrailing) {
return result;
}
continue;
case CharacterCodes.slash:
@@ -672,26 +613,31 @@ module TypeScript.Scanner {
return createTrivia(SyntaxKind.MultiLineCommentTrivia, absoluteStartIndex);
}
function skipMultiLineCommentTrivia(): number {
function skipMultiLineCommentTrivia(): void {
// The '2' is for the "/*" we consumed.
var _index = index + 2;
var _end = end;
index += 2;
while (true) {
if (index === end) {
if (_index === _end) {
reportDiagnostic(end, 0, DiagnosticCode._0_expected, ["*/"]);
return;
break;
}
if ((index + 1) < end &&
str.charCodeAt(index) === CharacterCodes.asterisk &&
str.charCodeAt(index + 1) === CharacterCodes.slash) {
if ((_index + 1) < _end &&
str.charCodeAt(_index) === CharacterCodes.asterisk &&
str.charCodeAt(_index + 1) === CharacterCodes.slash) {
index += 2;
return;
_index += 2;
break;
}
index++;
_index++;
}
index = _index;
}
function scanLineTerminatorSequenceTrivia(ch: number): ISyntaxTrivia {
@@ -1461,14 +1407,10 @@ module TypeScript.Scanner {
var fullEnd = fullStart + token.fullWidth();
reset(text, fullStart, fullEnd);
scanTriviaInfo(/*isTrailing: */ false);
scanTriviaInfo();
var start = index;
scanSyntaxKind(isContextualToken(token));
var end = index;
tokenInfo.leadingTriviaWidth = start - fullStart;
tokenInfo.width = end - start;
}
reset(text, 0, text.length());
@@ -1622,6 +1564,8 @@ module TypeScript.Scanner {
}
function consumeToken(token: ISyntaxToken): void {
// Debug.assert(token.fullWidth() > 0 || token.kind === SyntaxKind.EndOfFileToken);
// Debug.assert(currentToken() === token);
_absolutePosition += token.fullWidth();
+4 -98
View File
@@ -9,7 +9,7 @@ module TypeScript.Syntax {
if (isToken(child)) {
var token = <ISyntaxToken>child;
// If a token is skipped, return true. Or if it is a missing token. The only empty token that is not missing is EOF
if (token.hasSkippedToken() || (width(token) === 0 && token.kind !== SyntaxKind.EndOfFileToken)) {
if (token.hasLeadingSkippedToken() || (fullWidth(token) === 0 && token.kind !== SyntaxKind.EndOfFileToken)) {
return true;
}
}
@@ -28,7 +28,7 @@ module TypeScript.Syntax {
}
export function isUnterminatedMultilineCommentTrivia(trivia: ISyntaxTrivia): boolean {
if (trivia && trivia.kind() === SyntaxKind.MultiLineCommentTrivia) {
if (trivia && trivia.kind === SyntaxKind.MultiLineCommentTrivia) {
var text = trivia.fullText();
return text.length < 4 || text.substring(text.length - 2) !== "*/";
}
@@ -42,79 +42,7 @@ module TypeScript.Syntax {
return true;
}
else if (position === end) {
return trivia.kind() === SyntaxKind.SingleLineCommentTrivia || isUnterminatedMultilineCommentTrivia(trivia);
}
}
return false;
}
export function isEntirelyInsideComment(sourceUnit: SourceUnitSyntax, position: number): boolean {
var positionedToken = findToken(sourceUnit, position);
var fullStart = positionedToken.fullStart();
var triviaList: ISyntaxTriviaList = undefined;
var lastTriviaBeforeToken: ISyntaxTrivia = undefined;
if (positionedToken.kind === SyntaxKind.EndOfFileToken) {
// Check if the trivia is leading on the EndOfFile token
if (positionedToken.hasLeadingTrivia()) {
triviaList = positionedToken.leadingTrivia();
}
// Or trailing on the previous token
else {
positionedToken = previousToken(positionedToken);
if (positionedToken) {
if (positionedToken && positionedToken.hasTrailingTrivia()) {
triviaList = positionedToken.trailingTrivia();
fullStart = end(positionedToken);
}
}
}
}
else {
if (position <= (fullStart + positionedToken.leadingTriviaWidth())) {
triviaList = positionedToken.leadingTrivia();
}
else if (position >= (fullStart + width(positionedToken))) {
triviaList = positionedToken.trailingTrivia();
fullStart = end(positionedToken);
}
}
if (triviaList) {
// Try to find the trivia matching the position
for (var i = 0, n = triviaList.count(); i < n; i++) {
var trivia = triviaList.syntaxTriviaAt(i);
if (position <= fullStart) {
// Moved passed the trivia we need
break;
}
else if (position <= fullStart + trivia.fullWidth() && trivia.isComment()) {
// Found the comment trivia we were looking for
lastTriviaBeforeToken = trivia;
break;
}
fullStart += trivia.fullWidth();
}
}
return lastTriviaBeforeToken && isEntirelyInsideCommentTrivia(lastTriviaBeforeToken, fullStart, position);
}
export function isEntirelyInStringOrRegularExpressionLiteral(sourceUnit: SourceUnitSyntax, position: number): boolean {
var positionedToken = findToken(sourceUnit, position);
if (positionedToken) {
if (positionedToken.kind === SyntaxKind.EndOfFileToken) {
// EndOfFile token, enusre it did not follow an unterminated string literal
positionedToken = previousToken(positionedToken);
return positionedToken && positionedToken.trailingTriviaWidth() === 0 && isUnterminatedStringLiteral(positionedToken);
}
else if (position > start(positionedToken)) {
// Ensure position falls enterily within the literal if it is terminated, or the line if it is not
return (position < end(positionedToken) && (positionedToken.kind === TypeScript.SyntaxKind.StringLiteral || positionedToken.kind === TypeScript.SyntaxKind.RegularExpressionLiteral)) ||
(position <= end(positionedToken) && isUnterminatedStringLiteral(positionedToken));
return trivia.kind === SyntaxKind.SingleLineCommentTrivia || isUnterminatedMultilineCommentTrivia(trivia);
}
}
@@ -203,32 +131,10 @@ module TypeScript.Syntax {
// Debug.assert(position < positionedToken.fullEnd() || positionedToken.token().tokenKind === SyntaxKind.EndOfFileToken);
// if position is after the end of the token, then this token is the token on the left.
if (width(positionedToken) > 0 && position >= end(positionedToken)) {
if (width(positionedToken) > 0 && position >= fullEnd(positionedToken)) {
return positionedToken;
}
return previousToken(positionedToken);
}
export function firstTokenInLineContainingPosition(syntaxTree: SyntaxTree, position: number): ISyntaxToken {
var current = findToken(syntaxTree.sourceUnit(), position);
while (true) {
if (isFirstTokenInLine(current, syntaxTree.lineMap())) {
break;
}
current = previousToken(current);
}
return current;
}
function isFirstTokenInLine(token: ISyntaxToken, lineMap: LineMap): boolean {
var _previousToken = previousToken(token);
if (_previousToken === undefined) {
return true;
}
return lineMap.getLineNumberFromPosition(end(_previousToken)) !== lineMap.getLineNumberFromPosition(start(token));
}
}
+2 -54
View File
@@ -70,48 +70,6 @@ module TypeScript {
throw Errors.invalidOperation();
}
export function findSkippedTokenInPositionedToken(positionedToken: ISyntaxToken, position: number): ISyntaxToken {
var positionInLeadingTriviaList = (position < start(positionedToken));
return findSkippedTokenInTriviaList(positionedToken, position, /*lookInLeadingTriviaList*/ positionInLeadingTriviaList);
}
export function findSkippedTokenInLeadingTriviaList(positionedToken: ISyntaxToken, position: number): ISyntaxToken {
return findSkippedTokenInTriviaList(positionedToken, position, /*lookInLeadingTriviaList*/ true);
}
export function findSkippedTokenInTrailingTriviaList(positionedToken: ISyntaxToken, position: number): ISyntaxToken {
return findSkippedTokenInTriviaList(positionedToken, position, /*lookInLeadingTriviaList*/ false);
}
function findSkippedTokenInTriviaList(positionedToken: ISyntaxToken, position: number, lookInLeadingTriviaList: boolean): ISyntaxToken {
var triviaList: TypeScript.ISyntaxTriviaList = undefined;
var fullStart: number;
if (lookInLeadingTriviaList) {
triviaList = positionedToken.leadingTrivia();
fullStart = positionedToken.fullStart();
}
else {
triviaList = positionedToken.trailingTrivia();
fullStart = end(positionedToken);
}
if (triviaList && triviaList.hasSkippedToken()) {
for (var i = 0, n = triviaList.count(); i < n; i++) {
var trivia = triviaList.syntaxTriviaAt(i);
var triviaWidth = trivia.fullWidth();
if (trivia.isSkippedToken() && position >= fullStart && position <= fullStart + triviaWidth) {
return trivia.skippedToken();
}
fullStart += triviaWidth;
}
}
return undefined;
}
function findTokenWorker(element: ISyntaxElement, elementPosition: number, position: number): ISyntaxToken {
if (isList(element)) {
return findTokenInList(<ISyntaxNodeOrToken[]>element, elementPosition, position);
@@ -246,11 +204,6 @@ module TypeScript {
return token ? token.leadingTriviaWidth(text) : 0;
}
export function trailingTriviaWidth(element: ISyntaxElement, text?: ISimpleText): number {
var token = lastToken(element);
return token ? token.trailingTriviaWidth(text) : 0;
}
export function firstToken(element: ISyntaxElement): ISyntaxToken {
if (element) {
var kind = element.kind;
@@ -387,16 +340,11 @@ module TypeScript {
return token ? token.fullStart() + token.leadingTriviaWidth(text) : -1;
}
export function end(element: ISyntaxElement, text?: ISimpleText): number {
var token = isToken(element) ? <ISyntaxToken>element : lastToken(element);
return token ? fullEnd(token) - token.trailingTriviaWidth(text) : -1;
}
export function width(element: ISyntaxElement, text?: ISimpleText): number {
if (isToken(element)) {
return (<ISyntaxToken>element).text().length;
}
return fullWidth(element) - leadingTriviaWidth(element, text) - trailingTriviaWidth(element, text);
return fullWidth(element) - leadingTriviaWidth(element, text);
}
export function fullEnd(element: ISyntaxElement): number {
@@ -413,7 +361,7 @@ module TypeScript {
}
var lineMap = text.lineMap();
return lineMap.getLineNumberFromPosition(end(token1, text)) !== lineMap.getLineNumberFromPosition(start(token2, text));
return lineMap.getLineNumberFromPosition(fullEnd(token1)) !== lineMap.getLineNumberFromPosition(start(token2, text));
}
export interface ISyntaxElement {
+9 -17
View File
@@ -144,8 +144,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'moduleKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'name', type: 'INameSyntax', isOptional: true },
<any>{ name: 'stringLiteral', isToken: true, isOptional: true, tokenKinds: ['StringLiteral'] },
<any>{ name: 'name', type: 'INameSyntax' },
<any>{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
<any>{ name: 'moduleElements', isList: true, elementType: 'IModuleElementSyntax' },
<any>{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
@@ -161,8 +160,7 @@ var definitions:ITypeDefinition[] = [
<any>{ name: 'functionKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'identifier', isToken: true, tokenKinds: ['IdentifierName'] },
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
<any>{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
]
},
<any>{
@@ -242,8 +240,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'parameter', type: 'ParameterSyntax' },
<any>{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
<any>{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
<any>{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
],
isTypeScriptSpecific: true
},
@@ -254,8 +251,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
<any>{ name: 'equalsGreaterThanToken', isToken: true, excludeFromAST: true },
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
<any>{ name: 'expression', type: 'IExpressionSyntax', isOptional: true }
<any>{ name: 'body', type: 'BlockSyntax | IExpressionSyntax' }
],
isTypeScriptSpecific: true
},
@@ -639,8 +635,7 @@ var definitions:ITypeDefinition[] = [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'constructorKeyword', isToken: true },
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
<any>{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
],
isTypeScriptSpecific: true
},
@@ -652,8 +647,7 @@ var definitions:ITypeDefinition[] = [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'propertyName', type: 'IPropertyNameSyntax' },
<any>{ name: 'callSignature', type: 'CallSignatureSyntax' },
<any>{ name: 'block', type: 'BlockSyntax', isOptional: true },
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
<any>{ name: 'body', type: 'BlockSyntax | ISyntaxToken', isOptional: true }
],
isTypeScriptSpecific: true
},
@@ -796,8 +790,7 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'forKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'openParenToken', isToken: true, excludeFromAST: true },
<any>{ name: 'variableDeclaration', type: 'VariableDeclarationSyntax', isOptional: true },
<any>{ name: 'initializer', type: 'IExpressionSyntax', isOptional: true },
<any>{ name: 'initializer', type: 'VariableDeclarationSyntax | IExpressionSyntax', isOptional: true },
<any>{ name: 'firstSemicolonToken', isToken: true, tokenKinds: ['SemicolonToken'], excludeFromAST: true },
<any>{ name: 'condition', type: 'IExpressionSyntax', isOptional: true },
<any>{ name: 'secondSemicolonToken', isToken: true, tokenKinds: ['SemicolonToken'], excludeFromAST: true },
@@ -813,10 +806,9 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'forKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'openParenToken', isToken: true, excludeFromAST: true },
<any>{ name: 'variableDeclaration', type: 'VariableDeclarationSyntax', isOptional: true },
<any>{ name: 'left', type: 'IExpressionSyntax', isOptional: true },
<any>{ name: 'left', type: 'VariableDeclarationSyntax | IExpressionSyntax' },
<any>{ name: 'inKeyword', isToken: true, excludeFromAST: true },
<any>{ name: 'expression', type: 'IExpressionSyntax' },
<any>{ name: 'right', type: 'IExpressionSyntax' },
<any>{ name: 'closeParenToken', isToken: true, excludeFromAST: true },
<any>{ name: 'statement', type: 'IStatementSyntax' }
]
@@ -94,21 +94,19 @@ module TypeScript {
functionKeyword: ISyntaxToken;
identifier: ISyntaxToken;
callSignature: CallSignatureSyntax;
block: BlockSyntax;
semicolonToken: ISyntaxToken;
body: BlockSyntax | ISyntaxToken;
}
export interface FunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): FunctionDeclarationSyntax }
export interface FunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): FunctionDeclarationSyntax }
export interface ModuleDeclarationSyntax extends ISyntaxNode, IModuleElementSyntax {
modifiers: ISyntaxToken[];
moduleKeyword: ISyntaxToken;
name: INameSyntax;
stringLiteral: ISyntaxToken;
openBraceToken: ISyntaxToken;
moduleElements: IModuleElementSyntax[];
closeBraceToken: ISyntaxToken;
}
export interface ModuleDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], moduleKeyword: ISyntaxToken, name: INameSyntax, stringLiteral: ISyntaxToken, openBraceToken: ISyntaxToken, moduleElements: IModuleElementSyntax[], closeBraceToken: ISyntaxToken): ModuleDeclarationSyntax }
export interface ModuleDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], moduleKeyword: ISyntaxToken, name: INameSyntax, openBraceToken: ISyntaxToken, moduleElements: IModuleElementSyntax[], closeBraceToken: ISyntaxToken): ModuleDeclarationSyntax }
export interface ClassDeclarationSyntax extends ISyntaxNode, IModuleElementSyntax {
modifiers: ISyntaxToken[];
@@ -154,10 +152,9 @@ module TypeScript {
modifiers: ISyntaxToken[];
propertyName: IPropertyNameSyntax;
callSignature: CallSignatureSyntax;
block: BlockSyntax;
semicolonToken: ISyntaxToken;
body: BlockSyntax | ISyntaxToken;
}
export interface MemberFunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): MemberFunctionDeclarationSyntax }
export interface MemberFunctionDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): MemberFunctionDeclarationSyntax }
export interface MemberVariableDeclarationSyntax extends ISyntaxNode, IMemberDeclarationSyntax {
modifiers: ISyntaxToken[];
@@ -170,10 +167,9 @@ module TypeScript {
modifiers: ISyntaxToken[];
constructorKeyword: ISyntaxToken;
callSignature: CallSignatureSyntax;
block: BlockSyntax;
semicolonToken: ISyntaxToken;
body: BlockSyntax | ISyntaxToken;
}
export interface ConstructorDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): ConstructorDeclarationSyntax }
export interface ConstructorDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken): ConstructorDeclarationSyntax }
export interface IndexMemberDeclarationSyntax extends ISyntaxNode, IClassElementSyntax {
modifiers: ISyntaxToken[];
@@ -300,8 +296,7 @@ module TypeScript {
export interface ForStatementSyntax extends ISyntaxNode, IStatementSyntax {
forKeyword: ISyntaxToken;
openParenToken: ISyntaxToken;
variableDeclaration: VariableDeclarationSyntax;
initializer: IExpressionSyntax;
initializer: VariableDeclarationSyntax | IExpressionSyntax;
firstSemicolonToken: ISyntaxToken;
condition: IExpressionSyntax;
secondSemicolonToken: ISyntaxToken;
@@ -309,19 +304,18 @@ module TypeScript {
closeParenToken: ISyntaxToken;
statement: IStatementSyntax;
}
export interface ForStatementConstructor { new (data: number, forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, initializer: IExpressionSyntax, firstSemicolonToken: ISyntaxToken, condition: IExpressionSyntax, secondSemicolonToken: ISyntaxToken, incrementor: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForStatementSyntax }
export interface ForStatementConstructor { new (data: number, forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, initializer: VariableDeclarationSyntax | IExpressionSyntax, firstSemicolonToken: ISyntaxToken, condition: IExpressionSyntax, secondSemicolonToken: ISyntaxToken, incrementor: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForStatementSyntax }
export interface ForInStatementSyntax extends ISyntaxNode, IStatementSyntax {
forKeyword: ISyntaxToken;
openParenToken: ISyntaxToken;
variableDeclaration: VariableDeclarationSyntax;
left: IExpressionSyntax;
left: VariableDeclarationSyntax | IExpressionSyntax;
inKeyword: ISyntaxToken;
expression: IExpressionSyntax;
right: IExpressionSyntax;
closeParenToken: ISyntaxToken;
statement: IStatementSyntax;
}
export interface ForInStatementConstructor { new (data: number, forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, left: IExpressionSyntax, inKeyword: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForInStatementSyntax }
export interface ForInStatementConstructor { new (data: number, forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, left: VariableDeclarationSyntax | IExpressionSyntax, inKeyword: ISyntaxToken, right: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForInStatementSyntax }
export interface EmptyStatementSyntax extends ISyntaxNode, IStatementSyntax {
semicolonToken: ISyntaxToken;
@@ -475,18 +469,16 @@ module TypeScript {
export interface ParenthesizedArrowFunctionExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
callSignature: CallSignatureSyntax;
equalsGreaterThanToken: ISyntaxToken;
block: BlockSyntax;
expression: IExpressionSyntax;
body: BlockSyntax | IExpressionSyntax;
}
export interface ParenthesizedArrowFunctionExpressionConstructor { new (data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): ParenthesizedArrowFunctionExpressionSyntax }
export interface ParenthesizedArrowFunctionExpressionConstructor { new (data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax): ParenthesizedArrowFunctionExpressionSyntax }
export interface SimpleArrowFunctionExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
parameter: ParameterSyntax;
equalsGreaterThanToken: ISyntaxToken;
block: BlockSyntax;
expression: IExpressionSyntax;
body: BlockSyntax | IExpressionSyntax;
}
export interface SimpleArrowFunctionExpressionConstructor { new (data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): SimpleArrowFunctionExpressionSyntax }
export interface SimpleArrowFunctionExpressionConstructor { new (data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax): SimpleArrowFunctionExpressionSyntax }
export interface CastExpressionSyntax extends ISyntaxNode, IUnaryExpressionSyntax {
lessThanToken: ISyntaxToken;
+10 -6
View File
@@ -19,11 +19,11 @@ module TypeScript {
module TypeScript {
export function separatorCount(list: ISeparatedSyntaxList<ISyntaxNodeOrToken>) {
return list.length >> 1;
return list === undefined ? 0 : list.length >> 1;
}
export function nonSeparatorCount(list: ISeparatedSyntaxList<ISyntaxNodeOrToken>) {
return (list.length + 1) >> 1;
return list === undefined ? 0 : (list.length + 1) >> 1;
}
export function separatorAt(list: ISeparatedSyntaxList<ISyntaxNodeOrToken>, index: number): ISyntaxToken {
@@ -48,16 +48,20 @@ module TypeScript.Syntax {
addArrayPrototypeValue("kind", SyntaxKind.List);
export function list<T extends ISyntaxNodeOrToken>(nodes: T[]): T[] {
for (var i = 0, n = nodes.length; i < n; i++) {
nodes[i].parent = nodes;
if (nodes !== undefined) {
for (var i = 0, n = nodes.length; i < n; i++) {
nodes[i].parent = nodes;
}
}
return nodes;
}
export function separatedList<T extends ISyntaxNodeOrToken>(nodesAndTokens: ISyntaxNodeOrToken[]): ISeparatedSyntaxList<T> {
for (var i = 0, n = nodesAndTokens.length; i < n; i++) {
nodesAndTokens[i].parent = nodesAndTokens;
if (nodesAndTokens !== undefined) {
for (var i = 0, n = nodesAndTokens.length; i < n; i++) {
nodesAndTokens[i].parent = nodesAndTokens;
}
}
return <ISeparatedSyntaxList<T>>nodesAndTokens;
@@ -238,62 +238,56 @@ module TypeScript {
}
}
export var FunctionDeclarationSyntax: FunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken) {
export var FunctionDeclarationSyntax: FunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
if (data) { this.__data = data; }
this.modifiers = modifiers,
this.functionKeyword = functionKeyword,
this.identifier = identifier,
this.callSignature = callSignature,
this.block = block,
this.semicolonToken = semicolonToken,
this.body = body,
modifiers.parent = this,
functionKeyword.parent = this,
identifier.parent = this,
callSignature.parent = this,
block && (block.parent = this),
semicolonToken && (semicolonToken.parent = this);
body && (body.parent = this);
};
FunctionDeclarationSyntax.prototype.kind = SyntaxKind.FunctionDeclaration;
FunctionDeclarationSyntax.prototype.childCount = 6;
FunctionDeclarationSyntax.prototype.childCount = 5;
FunctionDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.modifiers;
case 1: return this.functionKeyword;
case 2: return this.identifier;
case 3: return this.callSignature;
case 4: return this.block;
case 5: return this.semicolonToken;
case 4: return this.body;
}
}
export var ModuleDeclarationSyntax: ModuleDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], moduleKeyword: ISyntaxToken, name: INameSyntax, stringLiteral: ISyntaxToken, openBraceToken: ISyntaxToken, moduleElements: IModuleElementSyntax[], closeBraceToken: ISyntaxToken) {
export var ModuleDeclarationSyntax: ModuleDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], moduleKeyword: ISyntaxToken, name: INameSyntax, openBraceToken: ISyntaxToken, moduleElements: IModuleElementSyntax[], closeBraceToken: ISyntaxToken) {
if (data) { this.__data = data; }
this.modifiers = modifiers,
this.moduleKeyword = moduleKeyword,
this.name = name,
this.stringLiteral = stringLiteral,
this.openBraceToken = openBraceToken,
this.moduleElements = moduleElements,
this.closeBraceToken = closeBraceToken,
modifiers.parent = this,
moduleKeyword.parent = this,
name && (name.parent = this),
stringLiteral && (stringLiteral.parent = this),
name.parent = this,
openBraceToken.parent = this,
moduleElements.parent = this,
closeBraceToken.parent = this;
};
ModuleDeclarationSyntax.prototype.kind = SyntaxKind.ModuleDeclaration;
ModuleDeclarationSyntax.prototype.childCount = 7;
ModuleDeclarationSyntax.prototype.childCount = 6;
ModuleDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.modifiers;
case 1: return this.moduleKeyword;
case 2: return this.name;
case 3: return this.stringLiteral;
case 4: return this.openBraceToken;
case 5: return this.moduleElements;
case 6: return this.closeBraceToken;
case 3: return this.openBraceToken;
case 4: return this.moduleElements;
case 5: return this.closeBraceToken;
}
}
@@ -409,28 +403,25 @@ module TypeScript {
}
}
export var MemberFunctionDeclarationSyntax: MemberFunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken) {
export var MemberFunctionDeclarationSyntax: MemberFunctionDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], propertyName: IPropertyNameSyntax, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
if (data) { this.__data = data; }
this.modifiers = modifiers,
this.propertyName = propertyName,
this.callSignature = callSignature,
this.block = block,
this.semicolonToken = semicolonToken,
this.body = body,
modifiers.parent = this,
propertyName.parent = this,
callSignature.parent = this,
block && (block.parent = this),
semicolonToken && (semicolonToken.parent = this);
body && (body.parent = this);
};
MemberFunctionDeclarationSyntax.prototype.kind = SyntaxKind.MemberFunctionDeclaration;
MemberFunctionDeclarationSyntax.prototype.childCount = 5;
MemberFunctionDeclarationSyntax.prototype.childCount = 4;
MemberFunctionDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.modifiers;
case 1: return this.propertyName;
case 2: return this.callSignature;
case 3: return this.block;
case 4: return this.semicolonToken;
case 3: return this.body;
}
}
@@ -453,28 +444,25 @@ module TypeScript {
}
}
export var ConstructorDeclarationSyntax: ConstructorDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken) {
export var ConstructorDeclarationSyntax: ConstructorDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, body: BlockSyntax | ISyntaxToken) {
if (data) { this.__data = data; }
this.modifiers = modifiers,
this.constructorKeyword = constructorKeyword,
this.callSignature = callSignature,
this.block = block,
this.semicolonToken = semicolonToken,
this.body = body,
modifiers.parent = this,
constructorKeyword.parent = this,
callSignature.parent = this,
block && (block.parent = this),
semicolonToken && (semicolonToken.parent = this);
body && (body.parent = this);
};
ConstructorDeclarationSyntax.prototype.kind = SyntaxKind.ConstructorDeclaration;
ConstructorDeclarationSyntax.prototype.childCount = 5;
ConstructorDeclarationSyntax.prototype.childCount = 4;
ConstructorDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.modifiers;
case 1: return this.constructorKeyword;
case 2: return this.callSignature;
case 3: return this.block;
case 4: return this.semicolonToken;
case 3: return this.body;
}
}
@@ -812,11 +800,10 @@ module TypeScript {
}
}
export var ForStatementSyntax: ForStatementConstructor = <any>function(data: number, forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, initializer: IExpressionSyntax, firstSemicolonToken: ISyntaxToken, condition: IExpressionSyntax, secondSemicolonToken: ISyntaxToken, incrementor: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax) {
export var ForStatementSyntax: ForStatementConstructor = <any>function(data: number, forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, initializer: VariableDeclarationSyntax | IExpressionSyntax, firstSemicolonToken: ISyntaxToken, condition: IExpressionSyntax, secondSemicolonToken: ISyntaxToken, incrementor: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax) {
if (data) { this.__data = data; }
this.forKeyword = forKeyword,
this.openParenToken = openParenToken,
this.variableDeclaration = variableDeclaration,
this.initializer = initializer,
this.firstSemicolonToken = firstSemicolonToken,
this.condition = condition,
@@ -826,7 +813,6 @@ module TypeScript {
this.statement = statement,
forKeyword.parent = this,
openParenToken.parent = this,
variableDeclaration && (variableDeclaration.parent = this),
initializer && (initializer.parent = this),
firstSemicolonToken.parent = this,
condition && (condition.parent = this),
@@ -836,53 +822,49 @@ module TypeScript {
statement.parent = this;
};
ForStatementSyntax.prototype.kind = SyntaxKind.ForStatement;
ForStatementSyntax.prototype.childCount = 10;
ForStatementSyntax.prototype.childCount = 9;
ForStatementSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.forKeyword;
case 1: return this.openParenToken;
case 2: return this.variableDeclaration;
case 3: return this.initializer;
case 4: return this.firstSemicolonToken;
case 5: return this.condition;
case 6: return this.secondSemicolonToken;
case 7: return this.incrementor;
case 8: return this.closeParenToken;
case 9: return this.statement;
case 2: return this.initializer;
case 3: return this.firstSemicolonToken;
case 4: return this.condition;
case 5: return this.secondSemicolonToken;
case 6: return this.incrementor;
case 7: return this.closeParenToken;
case 8: return this.statement;
}
}
export var ForInStatementSyntax: ForInStatementConstructor = <any>function(data: number, forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, left: IExpressionSyntax, inKeyword: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax) {
export var ForInStatementSyntax: ForInStatementConstructor = <any>function(data: number, forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, left: VariableDeclarationSyntax | IExpressionSyntax, inKeyword: ISyntaxToken, right: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax) {
if (data) { this.__data = data; }
this.forKeyword = forKeyword,
this.openParenToken = openParenToken,
this.variableDeclaration = variableDeclaration,
this.left = left,
this.inKeyword = inKeyword,
this.expression = expression,
this.right = right,
this.closeParenToken = closeParenToken,
this.statement = statement,
forKeyword.parent = this,
openParenToken.parent = this,
variableDeclaration && (variableDeclaration.parent = this),
left && (left.parent = this),
left.parent = this,
inKeyword.parent = this,
expression.parent = this,
right.parent = this,
closeParenToken.parent = this,
statement.parent = this;
};
ForInStatementSyntax.prototype.kind = SyntaxKind.ForInStatement;
ForInStatementSyntax.prototype.childCount = 8;
ForInStatementSyntax.prototype.childCount = 7;
ForInStatementSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.forKeyword;
case 1: return this.openParenToken;
case 2: return this.variableDeclaration;
case 3: return this.left;
case 4: return this.inKeyword;
case 5: return this.expression;
case 6: return this.closeParenToken;
case 7: return this.statement;
case 2: return this.left;
case 3: return this.inKeyword;
case 4: return this.right;
case 5: return this.closeParenToken;
case 6: return this.statement;
}
}
@@ -1291,47 +1273,41 @@ module TypeScript {
}
}
export var ParenthesizedArrowFunctionExpressionSyntax: ParenthesizedArrowFunctionExpressionConstructor = <any>function(data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax) {
export var ParenthesizedArrowFunctionExpressionSyntax: ParenthesizedArrowFunctionExpressionConstructor = <any>function(data: number, callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax) {
if (data) { this.__data = data; }
this.callSignature = callSignature,
this.equalsGreaterThanToken = equalsGreaterThanToken,
this.block = block,
this.expression = expression,
this.body = body,
callSignature.parent = this,
equalsGreaterThanToken.parent = this,
block && (block.parent = this),
expression && (expression.parent = this);
body.parent = this;
};
ParenthesizedArrowFunctionExpressionSyntax.prototype.kind = SyntaxKind.ParenthesizedArrowFunctionExpression;
ParenthesizedArrowFunctionExpressionSyntax.prototype.childCount = 4;
ParenthesizedArrowFunctionExpressionSyntax.prototype.childCount = 3;
ParenthesizedArrowFunctionExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.callSignature;
case 1: return this.equalsGreaterThanToken;
case 2: return this.block;
case 3: return this.expression;
case 2: return this.body;
}
}
export var SimpleArrowFunctionExpressionSyntax: SimpleArrowFunctionExpressionConstructor = <any>function(data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax) {
export var SimpleArrowFunctionExpressionSyntax: SimpleArrowFunctionExpressionConstructor = <any>function(data: number, parameter: ParameterSyntax, equalsGreaterThanToken: ISyntaxToken, body: BlockSyntax | IExpressionSyntax) {
if (data) { this.__data = data; }
this.parameter = parameter,
this.equalsGreaterThanToken = equalsGreaterThanToken,
this.block = block,
this.expression = expression,
this.body = body,
parameter.parent = this,
equalsGreaterThanToken.parent = this,
block && (block.parent = this),
expression && (expression.parent = this);
body.parent = this;
};
SimpleArrowFunctionExpressionSyntax.prototype.kind = SyntaxKind.SimpleArrowFunctionExpression;
SimpleArrowFunctionExpressionSyntax.prototype.childCount = 4;
SimpleArrowFunctionExpressionSyntax.prototype.childCount = 3;
SimpleArrowFunctionExpressionSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.parameter;
case 1: return this.equalsGreaterThanToken;
case 2: return this.block;
case 3: return this.expression;
case 2: return this.body;
}
}
+17 -70
View File
@@ -16,17 +16,12 @@ module TypeScript {
fullText(text?: ISimpleText): string;
hasLeadingTrivia(): boolean;
hasTrailingTrivia(): boolean;
hasLeadingNewLine(): boolean;
hasLeadingComment(): boolean;
hasTrailingComment(): boolean;
hasSkippedToken(): boolean;
hasLeadingSkippedToken(): boolean;
leadingTrivia(text?: ISimpleText): ISyntaxTriviaList;
trailingTrivia(text?: ISimpleText): ISyntaxTriviaList;
leadingTriviaWidth(text?: ISimpleText): number;
trailingTriviaWidth(text?: ISimpleText): number;
// True if this was a keyword that the parser converted to an identifier. i.e. if you have
// x.public
@@ -284,7 +279,7 @@ module TypeScript {
module TypeScript.Syntax {
export function realizeToken(token: ISyntaxToken, text: ISimpleText): ISyntaxToken {
return new RealizedToken(token.fullStart(), token.kind, token.isKeywordConvertedToIdentifier(), token.leadingTrivia(text), token.text(), token.trailingTrivia(text));
return new RealizedToken(token.fullStart(), token.kind, token.isKeywordConvertedToIdentifier(), token.leadingTrivia(text), token.text());
}
export function convertKeywordToIdentifier(token: ISyntaxToken): ISyntaxToken {
@@ -292,11 +287,7 @@ module TypeScript.Syntax {
}
export function withLeadingTrivia(token: ISyntaxToken, leadingTrivia: ISyntaxTriviaList, text: ISimpleText): ISyntaxToken {
return new RealizedToken(token.fullStart(), token.kind, token.isKeywordConvertedToIdentifier(), leadingTrivia, token.text(), token.trailingTrivia(text));
}
export function withTrailingTrivia(token: ISyntaxToken, trailingTrivia: ISyntaxTriviaList, text: ISimpleText): ISyntaxToken {
return new RealizedToken(token.fullStart(), token.kind, token.isKeywordConvertedToIdentifier(), token.leadingTrivia(text), token.text(), trailingTrivia);
return new RealizedToken(token.fullStart(), token.kind, token.isKeywordConvertedToIdentifier(), leadingTrivia, token.text());
}
export function emptyToken(kind: SyntaxKind): ISyntaxToken {
@@ -317,7 +308,6 @@ module TypeScript.Syntax {
}
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
public clone(): ISyntaxToken {
return new EmptyToken(this.kind);
@@ -405,16 +395,12 @@ module TypeScript.Syntax {
public fullText(): string { return ""; }
public hasLeadingTrivia() { return false; }
public hasTrailingTrivia() { return false; }
public hasLeadingNewLine() { return false; }
public hasLeadingComment() { return false; }
public hasTrailingComment() { return false; }
public hasSkippedToken() { return false; }
public hasLeadingSkippedToken() { return false; }
public leadingTriviaWidth() { return 0; }
public trailingTriviaWidth() { return 0; }
public leadingTrivia(): ISyntaxTriviaList { return Syntax.emptyTriviaList; }
public trailingTrivia(): ISyntaxTriviaList { return Syntax.emptyTriviaList; }
}
EmptyToken.prototype.childCount = 0;
@@ -425,7 +411,6 @@ module TypeScript.Syntax {
private _isKeywordConvertedToIdentifier: boolean;
private _leadingTrivia: ISyntaxTriviaList;
private _text: string;
private _trailingTrivia: ISyntaxTriviaList;
public parent: ISyntaxElement;
public childCount: number;
@@ -434,22 +419,16 @@ module TypeScript.Syntax {
public kind: SyntaxKind,
isKeywordConvertedToIdentifier: boolean,
leadingTrivia: ISyntaxTriviaList,
text: string,
trailingTrivia: ISyntaxTriviaList) {
text: string) {
this._fullStart = fullStart;
this._isKeywordConvertedToIdentifier = isKeywordConvertedToIdentifier;
this._text = text;
this._leadingTrivia = leadingTrivia.clone();
this._trailingTrivia = trailingTrivia.clone();
if (!this._leadingTrivia.isShared()) {
this._leadingTrivia.parent = this;
}
if (!this._trailingTrivia.isShared()) {
this._trailingTrivia.parent = this;
}
}
public setFullStart(fullStart: number): void {
@@ -457,10 +436,9 @@ module TypeScript.Syntax {
}
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
public clone(): ISyntaxToken {
return new RealizedToken(this._fullStart, this.kind, this._isKeywordConvertedToIdentifier, this._leadingTrivia, this._text, this._trailingTrivia);
return new RealizedToken(this._fullStart, this.kind, this._isKeywordConvertedToIdentifier, this._leadingTrivia, this._text);
}
// Realized tokens are created from the parser. They are *never* incrementally reusable.
@@ -471,23 +449,18 @@ module TypeScript.Syntax {
}
public fullStart(): number { return this._fullStart; }
public fullWidth(): number { return this._leadingTrivia.fullWidth() + this._text.length + this._trailingTrivia.fullWidth(); }
public fullWidth(): number { return this._leadingTrivia.fullWidth() + this._text.length; }
public text(): string { return this._text; }
public fullText(): string { return this._leadingTrivia.fullText() + this.text() + this._trailingTrivia.fullText(); }
public fullText(): string { return this._leadingTrivia.fullText() + this.text(); }
public hasLeadingTrivia(): boolean { return this._leadingTrivia.count() > 0; }
public hasTrailingTrivia(): boolean { return this._trailingTrivia.count() > 0; }
public hasLeadingNewLine(): boolean { return this._leadingTrivia.hasNewLine(); }
public hasLeadingComment(): boolean { return this._leadingTrivia.hasComment(); }
public hasTrailingComment(): boolean { return this._trailingTrivia.hasComment(); }
public leadingTriviaWidth(): number { return this._leadingTrivia.fullWidth(); }
public trailingTriviaWidth(): number { return this._trailingTrivia.fullWidth(); }
public hasSkippedToken(): boolean { return this._leadingTrivia.hasSkippedToken() || this._trailingTrivia.hasSkippedToken(); }
public hasLeadingSkippedToken(): boolean { return this._leadingTrivia.hasSkippedToken(); }
public leadingTrivia(): ISyntaxTriviaList { return this._leadingTrivia; }
public trailingTrivia(): ISyntaxTriviaList { return this._trailingTrivia; }
public leadingTriviaWidth(): number { return this._leadingTrivia.fullWidth(); }
}
RealizedToken.prototype.childCount = 0;
@@ -506,7 +479,6 @@ module TypeScript.Syntax {
}
public childAt(index: number): ISyntaxElement { throw Errors.invalidOperation() }
public accept(visitor: ISyntaxVisitor): any { return visitor.visitToken(this) }
public fullStart(): number {
return this.underlyingToken.fullStart();
@@ -530,25 +502,10 @@ module TypeScript.Syntax {
return this.underlyingToken.fullText(this.syntaxTreeText(text));
}
public hasLeadingTrivia(): boolean {
return this.underlyingToken.hasLeadingTrivia();
}
public hasTrailingTrivia(): boolean {
return this.underlyingToken.hasTrailingTrivia();
}
public hasLeadingComment(): boolean {
return this.underlyingToken.hasLeadingComment();
}
public hasTrailingComment(): boolean {
return this.underlyingToken.hasTrailingComment();
}
public hasSkippedToken(): boolean {
return this.underlyingToken.hasSkippedToken();
}
public hasLeadingTrivia(): boolean { return this.underlyingToken.hasLeadingTrivia(); }
public hasLeadingNewLine(): boolean { return this.underlyingToken.hasLeadingNewLine(); }
public hasLeadingComment(): boolean { return this.underlyingToken.hasLeadingComment(); }
public hasLeadingSkippedToken(): boolean { return this.underlyingToken.hasLeadingSkippedToken(); }
public leadingTrivia(text?: ISimpleText): ISyntaxTriviaList {
var result = this.underlyingToken.leadingTrivia(this.syntaxTreeText(text));
@@ -556,20 +513,10 @@ module TypeScript.Syntax {
return result;
}
public trailingTrivia(text?: ISimpleText): ISyntaxTriviaList {
var result = this.underlyingToken.trailingTrivia(this.syntaxTreeText(text));
result.parent = this;
return result;
}
public leadingTriviaWidth(text?: ISimpleText): number {
return this.underlyingToken.leadingTriviaWidth(this.syntaxTreeText(text));
}
public trailingTriviaWidth(text?: ISimpleText): number {
return this.underlyingToken.trailingTriviaWidth(this.syntaxTreeText(text));
}
public isKeywordConvertedToIdentifier(): boolean {
return true;
}
+8 -8
View File
@@ -814,7 +814,7 @@ module TypeScript {
}
private checkForDisallowedImportDeclaration(node: ModuleDeclarationSyntax): boolean {
if (!node.stringLiteral) {
if (node.name.kind !== SyntaxKind.StringLiteral) {
for (var i = 0, n = node.moduleElements.length; i < n; i++) {
var child = node.moduleElements[i];
if (child.kind === SyntaxKind.ImportDeclaration) {
@@ -849,21 +849,21 @@ module TypeScript {
public visitModuleDeclaration(node: ModuleDeclarationSyntax): void {
if (this.checkForDisallowedDeclareModifier(node.modifiers) ||
this.checkForRequiredDeclareModifier(node, node.stringLiteral ? node.stringLiteral : firstToken(node.name), node.modifiers) ||
this.checkForRequiredDeclareModifier(node, firstToken(node.name), node.modifiers) ||
this.checkModuleElementModifiers(node.modifiers) ||
this.checkForDisallowedImportDeclaration(node)) {
return;
}
if (node.stringLiteral) {
if (node.name.kind === SyntaxKind.StringLiteral) {
if (!this.inAmbientDeclaration && !SyntaxUtilities.containsToken(node.modifiers, SyntaxKind.DeclareKeyword)) {
this.pushDiagnostic(node.stringLiteral, DiagnosticCode.Only_ambient_modules_can_use_quoted_names);
this.pushDiagnostic(node.name, DiagnosticCode.Only_ambient_modules_can_use_quoted_names);
return;
}
}
if (!node.stringLiteral && this.checkForDisallowedExportAssignment(node)) {
if (node.name.kind !== SyntaxKind.StringLiteral && this.checkForDisallowedExportAssignment(node)) {
return;
}
@@ -1158,7 +1158,7 @@ module TypeScript {
}
private checkForInLeftHandSideExpression(node: ForInStatementSyntax): boolean {
if (node.left && !SyntaxUtilities.isLeftHandSizeExpression(node.left)) {
if (node.left.kind !== SyntaxKind.VariableDeclaration && !SyntaxUtilities.isLeftHandSizeExpression(node.left)) {
this.pushDiagnostic(node.left, DiagnosticCode.Invalid_left_hand_side_in_for_in_statement);
return true;
}
@@ -1170,8 +1170,8 @@ module TypeScript {
// The parser accepts a Variable Declaration in a ForInStatement, but the grammar only
// allows a very restricted form. Specifically, there must be only a single Variable
// Declarator in the Declaration.
if (node.variableDeclaration && node.variableDeclaration.variableDeclarators.length > 1) {
this.pushDiagnostic(node.variableDeclaration, DiagnosticCode.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement);
if (node.left.kind === SyntaxKind.VariableDeclaration && (<VariableDeclarationSyntax>node.left).variableDeclarators.length > 1) {
this.pushDiagnostic(node.left, DiagnosticCode.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement);
return true;
}
+9 -12
View File
@@ -2,8 +2,8 @@
module TypeScript {
export interface ISyntaxTrivia {
parent?: ISyntaxTriviaList;
kind(): SyntaxKind;
parent: ISyntaxTriviaList;
kind: SyntaxKind;
isWhitespace(): boolean;
isComment(): boolean;
@@ -25,11 +25,9 @@ module TypeScript {
module TypeScript.Syntax {
class AbstractTrivia implements ISyntaxTrivia {
constructor(private _kind: SyntaxKind) {
}
public parent: ISyntaxTriviaList;
public kind(): SyntaxKind {
return this._kind;
constructor(public kind: SyntaxKind) {
}
public clone(): ISyntaxTrivia {
@@ -53,19 +51,19 @@ module TypeScript.Syntax {
}
public isWhitespace(): boolean {
return this.kind() === SyntaxKind.WhitespaceTrivia;
return this.kind === SyntaxKind.WhitespaceTrivia;
}
public isComment(): boolean {
return this.kind() === SyntaxKind.SingleLineCommentTrivia || this.kind() === SyntaxKind.MultiLineCommentTrivia;
return this.kind === SyntaxKind.SingleLineCommentTrivia || this.kind === SyntaxKind.MultiLineCommentTrivia;
}
public isNewLine(): boolean {
return this.kind() === SyntaxKind.NewLineTrivia;
return this.kind === SyntaxKind.NewLineTrivia;
}
public isSkippedToken(): boolean {
return this.kind() === SyntaxKind.SkippedTokenTrivia;
return this.kind === SyntaxKind.SkippedTokenTrivia;
}
}
@@ -103,7 +101,7 @@ module TypeScript.Syntax {
}
public clone(): ISyntaxTrivia {
return new DeferredTrivia(this.kind(), this._text, this._fullStart, this._fullWidth);
return new DeferredTrivia(this.kind, this._text, this._fullStart, this._fullWidth);
}
public fullStart(): number {
@@ -129,7 +127,6 @@ module TypeScript.Syntax {
export function skippedTokenTrivia(token: ISyntaxToken, text: ISimpleText): ISyntaxTrivia {
Debug.assert(!token.hasLeadingTrivia());
Debug.assert(!token.hasTrailingTrivia());
Debug.assert(token.fullWidth() > 0);
return new SkippedTokenTrivia(token, token.fullText(text));
}
+5 -5
View File
@@ -76,7 +76,7 @@ module TypeScript.Syntax {
export var emptyTriviaList: ISyntaxTriviaList = new EmptyTriviaList();
function isComment(trivia: ISyntaxTrivia): boolean {
return trivia.kind() === SyntaxKind.MultiLineCommentTrivia || trivia.kind() === SyntaxKind.SingleLineCommentTrivia;
return trivia.kind === SyntaxKind.MultiLineCommentTrivia || trivia.kind === SyntaxKind.SingleLineCommentTrivia;
}
class SingletonSyntaxTriviaList implements ISyntaxTriviaList {
@@ -120,11 +120,11 @@ module TypeScript.Syntax {
}
public hasNewLine(): boolean {
return this.item.kind() === SyntaxKind.NewLineTrivia;
return this.item.kind === SyntaxKind.NewLineTrivia;
}
public hasSkippedToken(): boolean {
return this.item.kind() === SyntaxKind.SkippedTokenTrivia;
return this.item.kind === SyntaxKind.SkippedTokenTrivia;
}
public toArray(): ISyntaxTrivia[] {
@@ -193,7 +193,7 @@ module TypeScript.Syntax {
public hasNewLine(): boolean {
for (var i = 0; i < this.trivia.length; i++) {
if (this.trivia[i].kind() === SyntaxKind.NewLineTrivia) {
if (this.trivia[i].kind === SyntaxKind.NewLineTrivia) {
return true;
}
}
@@ -203,7 +203,7 @@ module TypeScript.Syntax {
public hasSkippedToken(): boolean {
for (var i = 0; i < this.trivia.length; i++) {
if (this.trivia[i].kind() === SyntaxKind.SkippedTokenTrivia) {
if (this.trivia[i].kind === SyntaxKind.SkippedTokenTrivia) {
return true;
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ module TypeScript {
}
var lineMap = text.lineMap();
var tokenLine = lineMap.getLineNumberFromPosition(end(token, text));
var tokenLine = lineMap.getLineNumberFromPosition(fullEnd(token));
var nextTokenLine = lineMap.getLineNumberFromPosition(start(_nextToken, text));
return tokenLine !== nextTokenLine;
+6 -14
View File
@@ -99,15 +99,13 @@ module TypeScript {
this.visitToken(node.functionKeyword);
this.visitToken(node.identifier);
visitNodeOrToken(this, node.callSignature);
visitNodeOrToken(this, node.block);
this.visitOptionalToken(node.semicolonToken);
visitNodeOrToken(this, node.body);
}
public visitModuleDeclaration(node: ModuleDeclarationSyntax): void {
this.visitList(node.modifiers);
this.visitToken(node.moduleKeyword);
visitNodeOrToken(this, node.name);
this.visitOptionalToken(node.stringLiteral);
this.visitToken(node.openBraceToken);
this.visitList(node.moduleElements);
this.visitToken(node.closeBraceToken);
@@ -153,8 +151,7 @@ module TypeScript {
this.visitList(node.modifiers);
visitNodeOrToken(this, node.propertyName);
visitNodeOrToken(this, node.callSignature);
visitNodeOrToken(this, node.block);
this.visitOptionalToken(node.semicolonToken);
visitNodeOrToken(this, node.body);
}
public visitMemberVariableDeclaration(node: MemberVariableDeclarationSyntax): void {
@@ -167,8 +164,7 @@ module TypeScript {
this.visitList(node.modifiers);
this.visitToken(node.constructorKeyword);
visitNodeOrToken(this, node.callSignature);
visitNodeOrToken(this, node.block);
this.visitOptionalToken(node.semicolonToken);
visitNodeOrToken(this, node.body);
}
public visitIndexMemberDeclaration(node: IndexMemberDeclarationSyntax): void {
@@ -280,7 +276,6 @@ module TypeScript {
public visitForStatement(node: ForStatementSyntax): void {
this.visitToken(node.forKeyword);
this.visitToken(node.openParenToken);
visitNodeOrToken(this, node.variableDeclaration);
visitNodeOrToken(this, node.initializer);
this.visitToken(node.firstSemicolonToken);
visitNodeOrToken(this, node.condition);
@@ -293,10 +288,9 @@ module TypeScript {
public visitForInStatement(node: ForInStatementSyntax): void {
this.visitToken(node.forKeyword);
this.visitToken(node.openParenToken);
visitNodeOrToken(this, node.variableDeclaration);
visitNodeOrToken(this, node.left);
this.visitToken(node.inKeyword);
visitNodeOrToken(this, node.expression);
visitNodeOrToken(this, node.right);
this.visitToken(node.closeParenToken);
visitNodeOrToken(this, node.statement);
}
@@ -432,15 +426,13 @@ module TypeScript {
public visitParenthesizedArrowFunctionExpression(node: ParenthesizedArrowFunctionExpressionSyntax): void {
visitNodeOrToken(this, node.callSignature);
this.visitToken(node.equalsGreaterThanToken);
visitNodeOrToken(this, node.block);
visitNodeOrToken(this, node.expression);
visitNodeOrToken(this, node.body);
}
public visitSimpleArrowFunctionExpression(node: SimpleArrowFunctionExpressionSyntax): void {
visitNodeOrToken(this, node.parameter);
this.visitToken(node.equalsGreaterThanToken);
visitNodeOrToken(this, node.block);
visitNodeOrToken(this, node.expression);
visitNodeOrToken(this, node.body);
}
public visitCastExpression(node: CastExpressionSyntax): void {
+1 -7
View File
@@ -69,10 +69,8 @@ module TypeScript {
token1.fullStart() === token2.fullStart() &&
TypeScript.fullEnd(token1) === TypeScript.fullEnd(token2) &&
TypeScript.start(token1, text1) === TypeScript.start(token2, text2) &&
TypeScript.end(token1, text1) === TypeScript.end(token2, text2) &&
token1.text() === token2.text() &&
triviaListStructuralEquals(token1.leadingTrivia(text1), token2.leadingTrivia(text2)) &&
triviaListStructuralEquals(token1.trailingTrivia(text1), token2.trailingTrivia(text2));
triviaListStructuralEquals(token1.leadingTrivia(text1), token2.leadingTrivia(text2));
}
export function triviaListStructuralEquals(triviaList1: TypeScript.ISyntaxTriviaList, triviaList2: TypeScript.ISyntaxTriviaList): boolean {
@@ -150,10 +148,6 @@ module TypeScript {
return false;
}
if (TypeScript.end(element1) !== TypeScript.end(element2)) {
return false;
}
if (TypeScript.fullEnd(element1) !== TypeScript.fullEnd(element2)) {
return false;
}
@@ -3,7 +3,7 @@
////module TestModule {
/////**/
////}
debugger;
goTo.marker("");
edit.paste(" class TestClass{\r\n\
private foo;\r\n\
@@ -6,7 +6,7 @@
////{ function h() {
////return 0;
////}}
debugger;
format.document();
verify.currentFileContentIs(
"function f()\n" +
@@ -11,4 +11,4 @@ goTo.marker();
edit.insert('}');
goTo.marker('comment');
// Comment below multi-line 'if' condition formatting
verify.currentLineContentIs(' // This is a comment');
verify.currentLineContentIs(' // This is a comment');
@@ -13,7 +13,7 @@ format.document();
goTo.marker('1');
verify.currentLineContentIs('foo(): Bar { }');
goTo.marker('2');
verify.currentLineContentIs('function Foo () # { }');
verify.currentLineContentIs('function Foo() # { }');
goTo.marker('3');
verify.currentLineContentIs('4+:5');
goTo.marker('4');
@@ -8,11 +8,11 @@
////}
////function a() {
//// /* %^ */ }/*3*/
debugger;
format.document();
goTo.marker('1');
verify.currentLineContentIs('function test() /* %^ */ {');
verify.currentLineContentIs('function test() /* %^ */');
goTo.marker('2');
verify.currentLineContentIs(' if (true) /* %^ */ {');
verify.currentLineContentIs(' if (true) /* %^ */');
goTo.marker('3');
verify.currentLineContentIs('}');
@@ -12,11 +12,11 @@ goTo.marker("innermost");
edit.insert(";");
// Adding smicolon should format the innermost statement
verify.currentLineContentIs(' var x = 0;');
verify.currentLineContentIs(' var x = 0;');
// Also should format any parent statement that is terminated by the semicolon
goTo.marker("directParent");
verify.currentLineContentIs(' if (true)');
verify.currentLineContentIs(' if (true)');
// But not parents that are not terminated by it
goTo.marker("parentOutsideBlock");
+1 -1
View File
@@ -5,7 +5,7 @@
////return[1];/*2*/
////return ;/*3*/
////}
debugger;
format.document();
goTo.marker("1");
verify.currentLineContentIs(" return 1;");