Skip to content

Commit 44e6bcf

Browse files
author
Yui T
committed
2 parents 92f8d0b + af4a121 commit 44e6bcf

File tree

248 files changed

+3503
-1283
lines changed

Some content is hidden

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

248 files changed

+3503
-1283
lines changed

Diff for: src/compiler/diagnosticInformationMap.generated.ts

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ module ts {
125125
Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." },
126126
Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." },
127127
An_object_member_cannot_be_declared_optional: { code: 1162, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." },
128+
yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." },
128129
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
129130
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
130131
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

Diff for: src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@
491491
"category": "Error",
492492
"code": 1162
493493
},
494+
"'yield' expression must be contained_within a generator declaration.": {
495+
"category": "Error",
496+
"code": 1163
497+
},
494498

495499
"Duplicate identifier '{0}'.": {
496500
"category": "Error",

Diff for: src/compiler/parser.ts

+646-309
Large diffs are not rendered by default.

Diff for: src/compiler/types.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ module ts {
183183
ConditionalExpression,
184184
TemplateExpression,
185185
TemplateSpan,
186+
YieldExpression,
186187
OmittedExpression,
187188
// Element
188189
Block,
@@ -269,20 +270,30 @@ module ts {
269270
DeclarationFile = 0x00000400, // Node is a .d.ts file
270271
Let = 0x00000800, // Variable declaration
271272
Const = 0x00001000, // Variable declaration
272-
273-
// Set if this node was parsed in strict mode. Used for grammar error checks, as well as
274-
// checking if the node can be reused in incremental settings.
275-
ParsedInStrictMode = 0x00002000,
276-
OctalLiteral = 0x00004000,
273+
OctalLiteral = 0x00002000,
274+
Generator = 0x00004000,
275+
YieldStar = 0x00008000,
277276

278277
Modifier = Export | Ambient | Public | Private | Protected | Static,
279278
AccessibilityModifier = Public | Private | Protected,
280279
BlockScoped = Let | Const
281280
}
282281

282+
export const enum ParserContextFlags {
283+
// Set if this node was parsed in strict mode. Used for grammar error checks, as well as
284+
// checking if the node can be reused in incremental settings.
285+
StrictMode = 1 << 0,
286+
DisallowIn = 1 << 1,
287+
Yield = 1 << 2,
288+
GeneratorParameter = 1 << 3,
289+
}
290+
283291
export interface Node extends TextRange {
284292
kind: SyntaxKind;
285293
flags: NodeFlags;
294+
// Specific context the parser was in when this node was created. Normally undefined.
295+
// Only set when the parser was in some interesting context (like async/yield).
296+
parserContextFlags?: ParserContextFlags;
286297
id?: number; // Unique id (used to look up NodeLinks)
287298
parent?: Node; // Parent node (initialized by binding)
288299
symbol?: Symbol; // Symbol declared by node (initialized by binding)
@@ -429,6 +440,10 @@ module ts {
429440
operator: SyntaxKind;
430441
operand: Expression;
431442
}
443+
444+
export interface YieldExpression extends Expression {
445+
expression: Expression;
446+
}
432447

433448
export interface BinaryExpression extends Expression {
434449
left: Expression;
@@ -758,7 +773,7 @@ module ts {
758773
getAugmentedPropertiesOfType(type: Type): Symbol[];
759774
getRootSymbols(symbol: Symbol): Symbol[];
760775
getContextualType(node: Node): Type;
761-
getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature;
776+
getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[]): Signature;
762777
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
763778
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;
764779
isUndefinedSymbol(symbol: Symbol): boolean;

Diff for: src/services/services.ts

+25-8
Original file line numberDiff line numberDiff line change
@@ -3887,39 +3887,56 @@ module ts {
38873887
var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations);
38883888

38893889
// Get the text to search for, we need to normalize it as external module names will have quote
3890-
var symbolName = getNormalizedSymbolName(symbol.name, declarations);
3890+
var declaredName = getDeclaredName(symbol);
38913891

3892-
// Get syntactic diagnostics
3892+
// Try to get the smallest valid scope that we can limit our search to;
3893+
// otherwise we'll need to search globally (i.e. include each file).
38933894
var scope = getSymbolScope(symbol);
38943895

38953896
if (scope) {
38963897
result = [];
3897-
getReferencesInNode(scope, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result);
3898+
getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
38983899
}
38993900
else {
3901+
var internedName = getInternedName(symbol, declarations)
39003902
forEach(sourceFiles, sourceFile => {
39013903
cancellationToken.throwIfCancellationRequested();
39023904

3903-
if (lookUp(sourceFile.identifiers, symbolName)) {
3905+
if (lookUp(sourceFile.identifiers, internedName)) {
39043906
result = result || [];
3905-
getReferencesInNode(sourceFile, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result);
3907+
getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
39063908
}
39073909
});
39083910
}
39093911

39103912
return result;
39113913

3912-
function getNormalizedSymbolName(symbolName: string, declarations: Declaration[]): string {
3914+
function getDeclaredName(symbol: Symbol) {
3915+
var name = typeInfoResolver.symbolToString(symbol);
3916+
3917+
return stripQuotes(name);
3918+
}
3919+
3920+
function getInternedName(symbol: Symbol, declarations: Declaration[]): string {
39133921
// Special case for function expressions, whose names are solely local to their bodies.
39143922
var functionExpression = forEach(declarations, d => d.kind === SyntaxKind.FunctionExpression ? <FunctionExpression>d : undefined);
39153923

3924+
// When a name gets interned into a SourceFile's 'identifiers' Map,
3925+
// its name is escaped and stored in the same way its symbol name/identifier
3926+
// name should be stored. Function expressions, however, are a special case,
3927+
// because despite sometimes having a name, the binder unconditionally binds them
3928+
// to a symbol with the name "__function".
39163929
if (functionExpression && functionExpression.name) {
39173930
var name = functionExpression.name.text;
39183931
}
39193932
else {
3920-
var name = symbolName;
3933+
var name = symbol.name;
39213934
}
39223935

3936+
return stripQuotes(name);
3937+
}
3938+
3939+
function stripQuotes(name: string) {
39233940
var length = name.length;
39243941
if (length >= 2 && name.charCodeAt(0) === CharacterCodes.doubleQuote && name.charCodeAt(length - 1) === CharacterCodes.doubleQuote) {
39253942
return name.substring(1, length - 1);
@@ -5385,7 +5402,7 @@ module ts {
53855402
getFormattingEditsForDocument,
53865403
getFormattingEditsAfterKeystroke,
53875404
getEmitOutput,
5388-
getSourceFile: getCurrentSourceFile,
5405+
getSourceFile: getCurrentSourceFile,
53895406
};
53905407
}
53915408

0 commit comments

Comments
 (0)