Skip to content

Commit 02d3568

Browse files
committed
Share SourceFile with other grammar checker that needs it
1 parent 10925c1 commit 02d3568

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ module ts {
448448
let declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) ? d : undefined);
449449

450450
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
451-
451+
452452
// first check if usage is lexically located after the declaration
453453
let isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation);
454454
if (!isUsedBeforeDeclaration) {
@@ -465,7 +465,7 @@ module ts {
465465

466466
if (variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement ||
467467
variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement) {
468-
// variable statement/for statement case,
468+
// variable statement/for statement case,
469469
// use site should not be inside variable declaration (initializer of declaration or binding element)
470470
isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container);
471471
}
@@ -9080,7 +9080,7 @@ module ts {
90809080
*/
90819081
function checkElementTypeOfArrayOrString(arrayOrStringType: Type, expressionForError: Expression): Type {
90829082
Debug.assert(languageVersion < ScriptTarget.ES6);
9083-
9083+
90849084
// After we remove all types that are StringLike, we will know if there was a string constituent
90859085
// based on whether the remaining type is the same as the initial type.
90869086
let arrayType = removeTypesFromUnionType(arrayOrStringType, TypeFlags.StringLike, /*isTypeOfKind*/ true, /*allowEmptyUnionResult*/ true);
@@ -11324,16 +11324,15 @@ module ts {
1132411324
}
1132511325
}
1132611326

11327-
function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray<TypeParameterDeclaration>): boolean {
11327+
function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray<TypeParameterDeclaration>, file: SourceFile): boolean {
1132811328
if (checkGrammarForDisallowedTrailingComma(typeParameters)) {
1132911329
return true;
1133011330
}
1133111331

1133211332
if (typeParameters && typeParameters.length === 0) {
1133311333
let start = typeParameters.pos - "<".length;
11334-
let sourceFile = getSourceFileOfNode(node);
11335-
let end = skipTrivia(sourceFile.text, typeParameters.end) + ">".length;
11336-
return grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty);
11334+
let end = skipTrivia(file.text, typeParameters.end) + ">".length;
11335+
return grammarErrorAtPos(file, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty);
1133711336
}
1133811337
}
1133911338

@@ -11377,15 +11376,16 @@ module ts {
1137711376

1137811377
function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean {
1137911378
// Prevent cascading error by short-circuit
11380-
return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters) || checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node);
11379+
let file = getSourceFileOfNode(node);
11380+
return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) ||
11381+
checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
1138111382
}
1138211383

11383-
function checkGrammarArrowFunction(node: FunctionLikeDeclaration): boolean {
11384+
function checkGrammarArrowFunction(node: FunctionLikeDeclaration, file: SourceFile): boolean {
1138411385
if (node.kind === SyntaxKind.ArrowFunction) {
11385-
var arrowFunction = <ArrowFunction>node;
11386-
var sourceFile = getSourceFileOfNode(node);
11387-
var startLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.pos).line;
11388-
var endLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.end).line;
11386+
let arrowFunction = <ArrowFunction>node;
11387+
let startLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line;
11388+
let endLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line;
1138911389
if (startLine !== endLine) {
1139011390
return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow);
1139111391
}

src/compiler/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,11 +3134,11 @@ module ts {
31343134
}
31353135
}
31363136

3137-
function parsePossibleParenthesizedArrowFunctionExpressionHead() {
3137+
function parsePossibleParenthesizedArrowFunctionExpressionHead(): ArrowFunction {
31383138
return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity:*/ false);
31393139
}
31403140

3141-
function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): FunctionExpression {
3141+
function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): ArrowFunction {
31423142
let node = <ArrowFunction>createNode(SyntaxKind.ArrowFunction);
31433143
// Arrow functions are never generators.
31443144
//

0 commit comments

Comments
 (0)