Skip to content

Commit af4a121

Browse files
Merge pull request #1261 from Microsoft/contextFlags
Use a separate field on a node to specify parser context flags.
2 parents 229eb2a + 3597f4f commit af4a121

File tree

177 files changed

+1782
-411
lines changed

Some content is hidden

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

177 files changed

+1782
-411
lines changed

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." },

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",

src/compiler/parser.ts

+365-84
Large diffs are not rendered by default.

src/compiler/types.ts

+20-7
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,22 +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-
ParsedInStrictModeContext = 0x00002000,
276-
ParsedInDisallowInContext = 0x00004000,
277-
278-
OctalLiteral = 0x00008000,
273+
OctalLiteral = 0x00002000,
274+
Generator = 0x00004000,
275+
YieldStar = 0x00008000,
279276

280277
Modifier = Export | Ambient | Public | Private | Protected | Static,
281278
AccessibilityModifier = Public | Private | Protected,
282279
BlockScoped = Let | Const
283280
}
284281

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+
285291
export interface Node extends TextRange {
286292
kind: SyntaxKind;
287293
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;
288297
id?: number; // Unique id (used to look up NodeLinks)
289298
parent?: Node; // Parent node (initialized by binding)
290299
symbol?: Symbol; // Symbol declared by node (initialized by binding)
@@ -431,6 +440,10 @@ module ts {
431440
operator: SyntaxKind;
432441
operand: Expression;
433442
}
443+
444+
export interface YieldExpression extends Expression {
445+
expression: Expression;
446+
}
434447

435448
export interface BinaryExpression extends Expression {
436449
left: Expression;

src/services/syntax/constants.ts

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
///<reference path='references.ts' />
22

33
module TypeScript {
4+
export const enum ParserContextFlags {
5+
StrictMode = 1 << 0,
6+
DisallowIn = 1 << 1,
7+
Yield = 1 << 2,
8+
GeneratorParameter = 1 << 3,
9+
10+
Mask = 0xF
11+
}
12+
413
export enum SyntaxNodeConstants {
514
None = 0,
615

7-
// Masks that we use to place information about a node into a single int. The first bit tells
8-
// us if we've computed the data for a node.
9-
//
10-
// The second bit tells us if the node is incrementally reusable if it does not
11-
// containe any skipped tokens, zero width tokens, regex tokens in it ("/", "/=" or "/.../"),
12-
// and contains no tokens that were parser generated.
13-
//
14-
// The next bit lets us know if the nodes was parsed in a strict context or node. A node can
15-
// only be used by the incremental parser if it is parsed in the same strict context as before.
16-
// last masks off the part of the int
17-
//
16+
// The first four bit of the flags are used to store parser context flags.
1817
// The width of the node is stored in the remainder of the int. This allows us up to 128MB
1918
// for a node by using all 27 bits. However, in the common case, we'll use less than 27 bits
2019
// for the width. Thus, the info will be stored in a single int in chakra.
21-
DataComputed = 0x00000001, // 0000 0000 0000 0000 0000 0000 0000 0001
22-
IncrementallyUnusableMask = 0x00000002, // 0000 0000 0000 0000 0000 0000 0000 0010
23-
ParsedInStrictModeContext = 0x00000004, // 0000 0000 0000 0000 0000 0000 0000 0100
24-
ParsedInDisallowInContext = 0x00000008, // 0000 0000 0000 0000 0000 0000 0000 1000
25-
ParsedInYieldContext = 0x00000010, // 0000 0000 0000 0000 0000 0000 0001 0000
26-
ParsedInGeneratorParameterContext = 0x00000020, // 0000 0000 0000 0000 0000 0000 0010 0000
27-
FullWidthShift = 1 << 6, // 1111 1111 1111 1111 1111 1111 1100 0000
20+
DataComputed = 1 << 4, // 0000 0000 0000 0000 0000 0000 0001 0000
21+
IncrementallyUnusableMask = 1 << 5, // 0000 0000 0000 0000 0000 0000 0010 0000
22+
FullWidthShift = 1 << 6, // 1111 1111 1111 1111 1111 1111 1100 0000
2823
}
2924
}

0 commit comments

Comments
 (0)