Merge pull request #3526 from Microsoft/removeGeneratorParameter

Remove generatorParameter and asyncParameter contexts.
This commit is contained in:
CyrusNajmabadi 2015-06-16 14:10:55 -07:00
commit 1b93265257
57 changed files with 721 additions and 733 deletions

View file

@ -88,6 +88,12 @@ namespace ts {
let container: Node;
let blockScopeContainer: Node;
let lastContainer: Node;
// If this file is an external module, then it is automatically in strict-mode according to
// ES6. If it is not an external module, then we'll determine if it is in strict mode or
// not depending on if we see "use strict" in certain places (or if we hit a class/namespace).
let inStrictMode = !!file.externalModuleIndicator;
let symbolCount = 0;
let Symbol = objectAllocator.getSymbolConstructor();
let classifiableNames: Map<string> = {};
@ -531,6 +537,51 @@ namespace ts {
typeLiteralSymbol.members = { [symbol.name]: symbol };
}
function bindObjectLiteralExpression(node: ObjectLiteralExpression) {
const enum ElementKind {
Property = 1,
Accessor = 2
}
if (inStrictMode) {
let seen: Map<ElementKind> = {};
for (let prop of node.properties) {
if (prop.name.kind !== SyntaxKind.Identifier) {
continue;
}
let identifier = <Identifier>prop.name;
// ECMA-262 11.1.5 Object Initialiser
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
// a.This production is contained in strict code and IsDataDescriptor(previous) is true and
// IsDataDescriptor(propId.descriptor) is true.
// b.IsDataDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true.
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
let currentKind = prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment || prop.kind === SyntaxKind.MethodDeclaration
? ElementKind.Property
: ElementKind.Accessor;
let existingKind = seen[identifier.text];
if (!existingKind) {
seen[identifier.text] = currentKind;
continue;
}
if (currentKind === ElementKind.Property && existingKind === ElementKind.Property) {
let span = getErrorSpanForNode(file, identifier);
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length,
Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode));
}
}
}
return bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object");
}
function bindAnonymousDeclaration(node: Declaration, symbolFlags: SymbolFlags, name: string) {
let symbol = createSymbol(symbolFlags, name);
addDeclarationToSymbol(symbol, node, symbolFlags);
@ -560,6 +611,138 @@ namespace ts {
bindBlockScopedDeclaration(node, SymbolFlags.BlockScopedVariable, SymbolFlags.BlockScopedVariableExcludes);
}
// The binder visits every node in the syntax tree so it is a convenient place to perform a single localized
// check for reserved words used as identifiers in strict mode code.
function checkStrictModeIdentifier(node: Identifier) {
if (inStrictMode &&
node.originalKeywordKind >= SyntaxKind.FirstFutureReservedWord &&
node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord &&
!isIdentifierName(node)) {
// Report error only if there are no parse errors in file
if (!file.parseDiagnostics.length) {
file.bindDiagnostics.push(createDiagnosticForNode(node,
getStrictModeIdentifierMessage(node), declarationNameToString(node)));
}
}
}
function getStrictModeIdentifierMessage(node: Node) {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression)) {
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode;
}
if (file.externalModuleIndicator) {
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode;
}
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
}
function checkStrictModeBinaryExpression(node: BinaryExpression) {
if (inStrictMode && isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operatorToken.kind)) {
// ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3)
checkStrictModeEvalOrArguments(node, <Identifier>node.left);
}
}
function checkStrictModeCatchClause(node: CatchClause) {
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
// Catch production is eval or arguments
if (inStrictMode && node.variableDeclaration) {
checkStrictModeEvalOrArguments(node, node.variableDeclaration.name);
}
}
function checkStrictModeDeleteExpression(node: DeleteExpression) {
// Grammar checking
if (inStrictMode && node.expression.kind === SyntaxKind.Identifier) {
// When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
// UnaryExpression is a direct reference to a variable, function argument, or function name
let span = getErrorSpanForNode(file, node.expression);
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode));
}
}
function isEvalOrArgumentsIdentifier(node: Node): boolean {
return node.kind === SyntaxKind.Identifier &&
((<Identifier>node).text === "eval" || (<Identifier>node).text === "arguments");
}
function checkStrictModeEvalOrArguments(contextNode: Node, name: Node) {
if (name && name.kind === SyntaxKind.Identifier) {
let identifier = <Identifier>name;
if (isEvalOrArgumentsIdentifier(identifier)) {
// We check first if the name is inside class declaration or class expression; if so give explicit message
// otherwise report generic error message.
let span = getErrorSpanForNode(file, name);
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length,
getStrictModeEvalOrArgumentsMessage(contextNode), identifier.text));
}
}
}
function getStrictModeEvalOrArgumentsMessage(node: Node) {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression)) {
return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
}
if (file.externalModuleIndicator) {
return Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode;
}
return Diagnostics.Invalid_use_of_0_in_strict_mode;
}
function checkStrictModeFunctionName(node: FunctionLikeDeclaration) {
if (inStrictMode) {
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
checkStrictModeEvalOrArguments(node, node.name);
}
}
function checkStrictModeNumericLiteral(node: LiteralExpression) {
if (inStrictMode && node.flags & NodeFlags.OctalLiteral) {
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
}
}
function checkStrictModePostfixUnaryExpression(node: PostfixUnaryExpression) {
// Grammar checking
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator.
if (inStrictMode) {
checkStrictModeEvalOrArguments(node, <Identifier>node.operand);
}
}
function checkStrictModePrefixUnaryExpression(node: PrefixUnaryExpression) {
// Grammar checking
if (inStrictMode) {
if (node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken) {
checkStrictModeEvalOrArguments(node, <Identifier>node.operand);
}
}
}
function checkStrictModeWithStatement(node: WithStatement) {
// Grammar checking for withStatement
if (inStrictMode) {
grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_strict_mode);
}
}
function grammarErrorOnFirstToken(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any) {
let span = getSpanOfTokenAtPosition(file, node.pos);
file.bindDiagnostics.push(createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
}
function getDestructuringParameterName(node: Declaration) {
return "__" + indexOf((<SignatureDeclaration>node.parent).parameters, node);
}
@ -567,6 +750,11 @@ namespace ts {
function bind(node: Node) {
node.parent = parent;
var savedInStrictMode = inStrictMode;
if (!savedInStrictMode) {
updateStrictMode(node);
}
// First we bind declaration nodes to a symbol if possible. We'll both create a symbol
// and then potentially add the symbol to an appropriate symbol table. Possible
// destination symbol tables are:
@ -584,10 +772,70 @@ namespace ts {
// the current 'container' node when it changes. This helps us know which symbol table
// a local should go into for example.
bindChildren(node);
inStrictMode = savedInStrictMode;
}
function updateStrictMode(node: Node) {
switch (node.kind) {
case SyntaxKind.SourceFile:
case SyntaxKind.ModuleBlock:
updateStrictModeStatementList((<SourceFile | ModuleBlock>node).statements);
return;
case SyntaxKind.Block:
if (isFunctionLike(node.parent)) {
updateStrictModeStatementList((<Block>node).statements);
}
return;
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
// All classes are automatically in strict mode in ES6.
inStrictMode = true;
return;
}
}
function updateStrictModeStatementList(statements: NodeArray<Statement>) {
for (let statement of statements) {
if (!isPrologueDirective(statement)) {
return;
}
if (isUseStrictPrologueDirective(<ExpressionStatement>statement)) {
inStrictMode = true;
return;
}
}
}
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
function isUseStrictPrologueDirective(node: ExpressionStatement): boolean {
let nodeText = getTextOfNodeFromSourceText(file.text, node.expression);
// Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the
// string to contain unicode escapes (as per ES5).
return nodeText === '"use strict"' || nodeText === "'use strict'";
}
function bindWorker(node: Node) {
switch (node.kind) {
case SyntaxKind.Identifier:
return checkStrictModeIdentifier(<Identifier>node);
case SyntaxKind.BinaryExpression:
return checkStrictModeBinaryExpression(<BinaryExpression>node);
case SyntaxKind.CatchClause:
return checkStrictModeCatchClause(<CatchClause>node);
case SyntaxKind.DeleteExpression:
return checkStrictModeDeleteExpression(<DeleteExpression>node);
case SyntaxKind.NumericLiteral:
return checkStrictModeNumericLiteral(<LiteralExpression>node);
case SyntaxKind.PostfixUnaryExpression:
return checkStrictModePostfixUnaryExpression(<PostfixUnaryExpression>node);
case SyntaxKind.PrefixUnaryExpression:
return checkStrictModePrefixUnaryExpression(<PrefixUnaryExpression>node);
case SyntaxKind.WithStatement:
return checkStrictModeWithStatement(<WithStatement>node);
case SyntaxKind.TypeParameter:
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes);
case SyntaxKind.Parameter:
@ -616,6 +864,7 @@ namespace ts {
return bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : SymbolFlags.None),
isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes);
case SyntaxKind.FunctionDeclaration:
checkStrictModeFunctionName(<FunctionDeclaration>node);
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
case SyntaxKind.Constructor:
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Constructor, /*symbolExcludes:*/ SymbolFlags.None);
@ -629,9 +878,10 @@ namespace ts {
case SyntaxKind.TypeLiteral:
return bindAnonymousDeclaration(<TypeLiteralNode>node, SymbolFlags.TypeLiteral, "__type");
case SyntaxKind.ObjectLiteralExpression:
return bindAnonymousDeclaration(<ObjectLiteralExpression>node, SymbolFlags.ObjectLiteral, "__object");
return bindObjectLiteralExpression(<ObjectLiteralExpression>node);
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
checkStrictModeFunctionName(<FunctionExpression>node);
return bindAnonymousDeclaration(<FunctionExpression>node, SymbolFlags.Function, "__function");
case SyntaxKind.ClassExpression:
case SyntaxKind.ClassDeclaration:
@ -737,6 +987,10 @@ namespace ts {
}
function bindVariableDeclarationOrBindingElement(node: VariableDeclaration | BindingElement) {
if (inStrictMode) {
checkStrictModeEvalOrArguments(node, node.name)
}
if (!isBindingPattern(node.name)) {
if (isBlockOrCatchScoped(node)) {
bindBlockScopedVariableDeclaration(node);
@ -760,6 +1014,12 @@ namespace ts {
}
function bindParameter(node: ParameterDeclaration) {
if (inStrictMode) {
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
checkStrictModeEvalOrArguments(node, node.name);
}
if (isBindingPattern(node.name)) {
bindAnonymousDeclaration(node, SymbolFlags.FunctionScopedVariable, getDestructuringParameterName(node));
}

View file

@ -3637,7 +3637,7 @@ namespace ts {
// The expression is processed as an identifier expression (section 4.3)
// or property access expression(section 4.10),
// the widened type(section 3.9) of which becomes the result.
links.resolvedType = getWidenedType(checkExpressionOrQualifiedName(node.exprName));
links.resolvedType = getWidenedType(checkExpression(node.exprName));
}
return links.resolvedType;
}
@ -6083,6 +6083,18 @@ namespace ts {
return undefined;
}
function isInParameterInitializerBeforeContainingFunction(node: Node) {
while (node.parent && !isFunctionLike(node.parent)) {
if (node.parent.kind === SyntaxKind.Parameter && (<ParameterDeclaration>node.parent).initializer === node) {
return true;
}
node = node.parent;
}
return false;
}
function getContextualReturnType(functionDecl: FunctionLikeDeclaration): Type {
// If the containing function has a return type annotation, is a constructor, or is a get accessor whose
// corresponding set accessor has a type annotation, return statements in the function are contextually typed
@ -6645,7 +6657,7 @@ namespace ts {
}
function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) {
let type = checkExpressionOrQualifiedName(left);
let type = checkExpression(left);
if (isTypeAny(type)) {
return type;
}
@ -6686,7 +6698,7 @@ namespace ts {
? (<PropertyAccessExpression>node).expression
: (<QualifiedName>node).left;
let type = checkExpressionOrQualifiedName(left);
let type = checkExpression(left);
if (type !== unknownType && !isTypeAny(type)) {
let prop = getPropertyOfType(getWidenedType(type), propertyName);
if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) {
@ -7819,9 +7831,9 @@ namespace ts {
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
// Grammar checking
let hasGrammarError = checkGrammarDeclarationNameInStrictMode(node) || checkGrammarFunctionLikeDeclaration(node);
let hasGrammarError = checkGrammarFunctionLikeDeclaration(node);
if (!hasGrammarError && node.kind === SyntaxKind.FunctionExpression) {
checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node);
checkGrammarForGenerator(node);
}
// The identityMapper object is used to indicate that function expressions are wildcards
@ -8008,14 +8020,7 @@ namespace ts {
}
function checkDeleteExpression(node: DeleteExpression): Type {
// Grammar checking
if (node.parserContextFlags & ParserContextFlags.StrictMode && node.expression.kind === SyntaxKind.Identifier) {
// When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
// UnaryExpression is a direct reference to a variable, function argument, or function name
grammarErrorOnNode(node.expression, Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode);
}
let operandType = checkExpression(node.expression);
checkExpression(node.expression);
return booleanType;
}
@ -8031,8 +8036,14 @@ namespace ts {
function checkAwaitExpression(node: AwaitExpression): Type {
// Grammar checking
if (!(node.parserContextFlags & ParserContextFlags.Await)) {
grammarErrorOnFirstToken(node, Diagnostics.await_expression_is_only_allowed_within_an_async_function);
if (produceDiagnostics) {
if (!(node.parserContextFlags & ParserContextFlags.Await)) {
grammarErrorOnFirstToken(node, Diagnostics.await_expression_is_only_allowed_within_an_async_function);
}
if (isInParameterInitializerBeforeContainingFunction(node)) {
error(node, Diagnostics.await_expressions_cannot_be_used_in_a_parameter_initializer);
}
}
let operandType = checkExpression(node.expression);
@ -8040,14 +8051,6 @@ namespace ts {
}
function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type {
// Grammar checking
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator
if ((node.operator === SyntaxKind.PlusPlusToken || node.operator === SyntaxKind.MinusMinusToken)) {
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.operand);
}
let operandType = checkExpression(node.operand);
switch (node.operator) {
case SyntaxKind.PlusToken:
@ -8074,12 +8077,6 @@ namespace ts {
}
function checkPostfixUnaryExpression(node: PostfixUnaryExpression): Type {
// Grammar checking
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator.
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.operand);
let operandType = checkExpression(node.operand);
let ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
if (ok) {
@ -8259,13 +8256,6 @@ namespace ts {
}
function checkBinaryExpression(node: BinaryExpression, contextualMapper?: TypeMapper) {
// Grammar checking
if (isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operatorToken.kind)) {
// ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3)
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.left);
}
let operator = node.operatorToken.kind;
if (operator === SyntaxKind.EqualsToken && (node.left.kind === SyntaxKind.ObjectLiteralExpression || node.left.kind === SyntaxKind.ArrayLiteralExpression)) {
return checkDestructuringAssignment(node.left, checkExpression(node.right, contextualMapper), contextualMapper);
@ -8465,8 +8455,14 @@ namespace ts {
function checkYieldExpression(node: YieldExpression): Type {
// Grammar checking
if (!(node.parserContextFlags & ParserContextFlags.Yield) || isYieldExpressionInClass(node)) {
grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
if (produceDiagnostics) {
if (!(node.parserContextFlags & ParserContextFlags.Yield) || isYieldExpressionInClass(node)) {
grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body);
}
if (isInParameterInitializerBeforeContainingFunction(node)) {
error(node, Diagnostics.yield_expressions_cannot_be_used_in_a_parameter_initializer);
}
}
if (node.expression) {
@ -8578,11 +8574,6 @@ namespace ts {
return type;
}
function checkExpression(node: Expression, contextualMapper?: TypeMapper): Type {
checkGrammarIdentifierInStrictMode(node);
return checkExpressionOrQualifiedName(node, contextualMapper);
}
// Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
// contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the
// expression is being inferentially typed (section 4.12.2 in spec) and provides the type mapper to use in
@ -8590,7 +8581,7 @@ namespace ts {
// object, it serves as an indicator that all contained function and arrow expressions should be considered to
// have the wildcard function type; this form of type check is used during overload resolution to exclude
// contextually typed function and arrow expressions in the initial phase.
function checkExpressionOrQualifiedName(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type {
function checkExpression(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type {
let type: Type;
if (node.kind == SyntaxKind.QualifiedName) {
type = checkQualifiedName(<QualifiedName>node);
@ -8696,8 +8687,6 @@ namespace ts {
// DECLARATION AND STATEMENT TYPE CHECKING
function checkTypeParameter(node: TypeParameterDeclaration) {
checkGrammarDeclarationNameInStrictMode(node);
// Grammar Checking
if (node.expression) {
grammarErrorOnFirstToken(node.expression, Diagnostics.Type_expected);
@ -8716,11 +8705,9 @@ namespace ts {
// It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
// Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code
// or if its FunctionBody is strict code(11.1.5).
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
// Grammar checking
checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.name);
checkGrammarDecorators(node) || checkGrammarModifiers(node);
checkVariableLikeDeclaration(node);
let func = getContainingFunction(node);
@ -9084,13 +9071,10 @@ namespace ts {
}
function checkTypeReferenceNode(node: TypeReferenceNode) {
checkGrammarTypeReferenceInStrictMode(node.typeName);
return checkTypeReferenceOrExpressionWithTypeArguments(node);
}
function checkExpressionWithTypeArguments(node: ExpressionWithTypeArguments) {
checkGrammarExpressionWithTypeArgumentsInStrictMode(<PropertyAccessExpression>node.expression);
return checkTypeReferenceOrExpressionWithTypeArguments(node);
}
@ -9714,7 +9698,7 @@ namespace ts {
// When we emit the async function, we need to ensure we emit any imports that might
// otherwise have been elided if the return type were only ever referenced in a type
// position. As such, we check the entity name as an expression.
let declaredType = checkExpressionOrQualifiedName(entityName);
let declaredType = checkExpression(entityName);
if (!isTypeAssignableTo(declaredType, globalPromiseConstructorLikeType)) {
// If the declared type of the return type is not assignable to a PromiseConstructorLike, report an error.
@ -9769,7 +9753,7 @@ namespace ts {
return;
}
if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) {
checkExpressionOrQualifiedName((<TypeReferenceNode>node).typeName);
checkExpression((<TypeReferenceNode>node).typeName);
}
}
}
@ -9855,9 +9839,7 @@ namespace ts {
function checkFunctionDeclaration(node: FunctionDeclaration): void {
if (produceDiagnostics) {
checkFunctionLikeDeclaration(node) ||
checkGrammarFunctionName(node.name) ||
checkGrammarForGenerator(node);
checkFunctionLikeDeclaration(node) || checkGrammarForGenerator(node);
checkCollisionWithCapturedSuperVariable(node, node.name);
checkCollisionWithCapturedThisVariable(node, node.name);
@ -9866,7 +9848,6 @@ namespace ts {
}
function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void {
checkGrammarDeclarationNameInStrictMode(node);
checkDecorators(node);
checkSignatureDeclaration(node);
let isAsync = isAsyncFunctionLike(node);
@ -10178,7 +10159,6 @@ namespace ts {
// Check variable, parameter, or property declaration
function checkVariableLikeDeclaration(node: VariableLikeDeclaration) {
checkGrammarDeclarationNameInStrictMode(node);
checkDecorators(node);
checkSourceElement(node.type);
// For a computed property, just check the initializer and exit
@ -10730,10 +10710,7 @@ namespace ts {
function checkWithStatement(node: WithStatement) {
// Grammar checking for withStatement
if (!checkGrammarStatementInAmbientContext(node)) {
if (node.parserContextFlags & ParserContextFlags.StrictMode) {
grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_strict_mode);
}
else if (node.parserContextFlags & ParserContextFlags.Await) {
if (node.parserContextFlags & ParserContextFlags.Await) {
grammarErrorOnFirstToken(node, Diagnostics.with_statements_are_not_allowed_in_an_async_function_block);
}
}
@ -10840,10 +10817,6 @@ namespace ts {
grammarErrorOnNode(localSymbol.valueDeclaration, Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName);
}
}
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
// Catch production is eval or arguments
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>catchClause.variableDeclaration.name);
}
}
@ -10982,7 +10955,6 @@ namespace ts {
}
function checkClassDeclaration(node: ClassDeclaration) {
checkGrammarDeclarationNameInStrictMode(node);
// Grammar checking
if (!node.name && !(node.flags & NodeFlags.Default)) {
grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name);
@ -11029,7 +11001,7 @@ namespace ts {
if (baseTypes.length || (baseTypeNode && compilerOptions.isolatedModules)) {
// Check that base type can be evaluated as expression
checkExpressionOrQualifiedName(baseTypeNode.expression);
checkExpression(baseTypeNode.expression);
}
let implementedTypeNodes = getClassImplementsHeritageClauseElements(node);
@ -11208,7 +11180,7 @@ namespace ts {
function checkInterfaceDeclaration(node: InterfaceDeclaration) {
// Grammar checking
checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node);
checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node);
checkTypeParameters(node.typeParameters);
if (produceDiagnostics) {
@ -11433,7 +11405,7 @@ namespace ts {
}
// Grammar checking
checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node);
checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node);
checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0);
checkCollisionWithCapturedThisVariable(node, node.name);
@ -11529,7 +11501,7 @@ namespace ts {
return;
}
if (!checkGrammarDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node)) {
if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) {
if (!isInAmbientContext(node) && node.name.kind === SyntaxKind.StringLiteral) {
grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names);
}
@ -11645,7 +11617,7 @@ namespace ts {
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
if (!checkGrammarImportDeclarationNameInStrictMode(node) && !checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) {
if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) {
grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
}
if (checkExternalImportOrExportDeclaration(node)) {
@ -11672,7 +11644,7 @@ namespace ts {
return;
}
checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node);
checkGrammarDecorators(node) || checkGrammarModifiers(node);
if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
checkImportBinding(node);
if (node.flags & NodeFlags.Export) {
@ -13071,153 +13043,6 @@ namespace ts {
}
// GRAMMAR CHECKING
function isReservedWordInStrictMode(node: Identifier): boolean {
// Check that originalKeywordKind is less than LastFutureReservedWord to see if an Identifier is a strict-mode reserved word
return (node.parserContextFlags & ParserContextFlags.StrictMode) &&
(SyntaxKind.FirstFutureReservedWord <= node.originalKeywordKind && node.originalKeywordKind <= SyntaxKind.LastFutureReservedWord);
}
function reportStrictModeGrammarErrorInClassDeclaration(identifier: Identifier, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
// We are checking if this name is inside class declaration or class expression (which are under class definitions inside ES6 spec.)
// if so, we would like to give more explicit invalid usage error.
if (getAncestor(identifier, SyntaxKind.ClassDeclaration) || getAncestor(identifier, SyntaxKind.ClassExpression)) {
return grammarErrorOnNode(identifier, message, arg0);
}
return false;
}
function checkGrammarImportDeclarationNameInStrictMode(node: ImportDeclaration): boolean {
// Check if the import declaration used strict-mode reserved word in its names bindings
if (node.importClause) {
let impotClause = node.importClause;
if (impotClause.namedBindings) {
let nameBindings = impotClause.namedBindings;
if (nameBindings.kind === SyntaxKind.NamespaceImport) {
let name = <Identifier>(<NamespaceImport>nameBindings).name;
if (isReservedWordInStrictMode(name)) {
let nameText = declarationNameToString(name);
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
}
}
else if (nameBindings.kind === SyntaxKind.NamedImports) {
let reportError = false;
for (let element of (<NamedImports>nameBindings).elements) {
let name = element.name;
if (isReservedWordInStrictMode(name)) {
let nameText = declarationNameToString(name);
reportError = reportError || grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
}
}
return reportError;
}
}
}
return false;
}
function checkGrammarDeclarationNameInStrictMode(node: Declaration): boolean {
let name = node.name;
if (name && name.kind === SyntaxKind.Identifier && isReservedWordInStrictMode(<Identifier>name)) {
let nameText = declarationNameToString(name);
switch (node.kind) {
case SyntaxKind.Parameter:
case SyntaxKind.VariableDeclaration:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.TypeParameter:
case SyntaxKind.BindingElement:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.EnumDeclaration:
return checkGrammarIdentifierInStrictMode(<Identifier>name);
case SyntaxKind.ClassDeclaration:
// Report an error if the class declaration uses strict-mode reserved word.
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText);
case SyntaxKind.ModuleDeclaration:
// Report an error if the module declaration uses strict-mode reserved word.
// TODO(yuisu): fix this when having external module in strict mode
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
case SyntaxKind.ImportEqualsDeclaration:
// TODO(yuisu): fix this when having external module in strict mode
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
}
}
return false;
}
function checkGrammarTypeReferenceInStrictMode(typeName: Identifier | QualifiedName) {
// Check if the type reference is using strict mode keyword
// Example:
// class C {
// foo(x: public){} // Error.
// }
if (typeName.kind === SyntaxKind.Identifier) {
checkGrammarTypeNameInStrictMode(<Identifier>typeName);
}
// Report an error for each identifier in QualifiedName
// Example:
// foo (x: B.private.bar) // error at private
// foo (x: public.private.package) // error at public, private, and package
else if (typeName.kind === SyntaxKind.QualifiedName) {
// Walk from right to left and report a possible error at each Identifier in QualifiedName
// Example:
// x1: public.private.package // error at public and private
checkGrammarTypeNameInStrictMode((<QualifiedName>typeName).right);
checkGrammarTypeReferenceInStrictMode((<QualifiedName>typeName).left);
}
}
// This function will report an error for every identifier in property access expression
// whether it violates strict mode reserved words.
// Example:
// public // error at public
// public.private.package // error at public
// B.private.B // no error
function checkGrammarExpressionWithTypeArgumentsInStrictMode(expression: Expression) {
// Example:
// class C extends public // error at public
if (expression && expression.kind === SyntaxKind.Identifier) {
return checkGrammarIdentifierInStrictMode(expression);
}
else if (expression && expression.kind === SyntaxKind.PropertyAccessExpression) {
// Walk from left to right in PropertyAccessExpression until we are at the left most expression
// in PropertyAccessExpression. According to grammar production of MemberExpression,
// the left component expression is a PrimaryExpression (i.e. Identifier) while the other
// component after dots can be IdentifierName.
checkGrammarExpressionWithTypeArgumentsInStrictMode((<PropertyAccessExpression>expression).expression);
}
}
// The function takes an identifier itself or an expression which has SyntaxKind.Identifier.
function checkGrammarIdentifierInStrictMode(node: Expression | Identifier, nameText?: string): boolean {
if (node && node.kind === SyntaxKind.Identifier && isReservedWordInStrictMode(<Identifier>node)) {
if (!nameText) {
nameText = declarationNameToString(<Identifier>node);
}
// TODO (yuisu): Fix when module is a strict mode
let errorReport = reportStrictModeGrammarErrorInClassDeclaration(<Identifier>node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText)||
grammarErrorOnNode(node, Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText);
return errorReport;
}
return false;
}
// The function takes an identifier when uses as a typeName in TypeReferenceNode
function checkGrammarTypeNameInStrictMode(node: Identifier): boolean {
if (node && node.kind === SyntaxKind.Identifier && isReservedWordInStrictMode(<Identifier>node)) {
let nameText = declarationNameToString(<Identifier>node);
// TODO (yuisu): Fix when module is a strict mode
let errorReport = reportStrictModeGrammarErrorInClassDeclaration(<Identifier>node, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode, nameText) ||
grammarErrorOnNode(node, Diagnostics.Type_expected_0_is_a_reserved_word_in_strict_mode, nameText);
return errorReport;
}
return false;
}
function checkGrammarDecorators(node: Node): boolean {
if (!node.decorators) {
@ -13694,11 +13519,6 @@ namespace ts {
}
}
function checkGrammarFunctionName(name: Node) {
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
return checkGrammarEvalOrArgumentsInStrictMode(name, <Identifier>name);
}
function checkGrammarForInvalidQuestionMark(node: Declaration, questionToken: Node, message: DiagnosticMessage): boolean {
if (questionToken) {
return grammarErrorOnNode(questionToken, message);
@ -13711,7 +13531,6 @@ namespace ts {
let GetAccessor = 2;
let SetAccesor = 4;
let GetOrSetAccessor = GetAccessor | SetAccesor;
let inStrictMode = (node.parserContextFlags & ParserContextFlags.StrictMode) !== 0;
for (let prop of node.properties) {
let name = prop.name;
@ -13758,9 +13577,7 @@ namespace ts {
else {
let existingKind = seen[(<Identifier>name).text];
if (currentKind === Property && existingKind === Property) {
if (inStrictMode) {
grammarErrorOnNode(name, Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode);
}
continue;
}
else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
@ -13983,9 +13800,6 @@ namespace ts {
return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - 1, 1, Diagnostics.A_rest_element_cannot_have_an_initializer);
}
}
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
// and its Identifier is eval or arguments
return checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.name);
}
function checkGrammarVariableDeclaration(node: VariableDeclaration) {
@ -14017,8 +13831,7 @@ namespace ts {
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
// and its Identifier is eval or arguments
return (checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name)) ||
checkGrammarEvalOrArgumentsInStrictMode(node, <Identifier>node.name);
return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name);
}
function checkGrammarNameInLetOrConstDeclarations(name: Identifier | BindingPattern): boolean {
@ -14157,29 +13970,6 @@ namespace ts {
}
}
function checkGrammarEvalOrArgumentsInStrictMode(contextNode: Node, name: Node): boolean {
if (name && name.kind === SyntaxKind.Identifier) {
let identifier = <Identifier>name;
if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) {
let nameText = declarationNameToString(identifier);
// We check first if the name is inside class declaration or class expression; if so give explicit message
// otherwise report generic error message.
// reportGrammarErrorInClassDeclaration only return true if grammar error is successfully reported and false otherwise
let reportErrorInClassDeclaration = reportStrictModeGrammarErrorInClassDeclaration(identifier, Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode, nameText);
if (!reportErrorInClassDeclaration){
return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText);
}
return reportErrorInClassDeclaration;
}
}
}
function isEvalOrArgumentsIdentifier(node: Node): boolean {
return node.kind === SyntaxKind.Identifier &&
((<Identifier>node).text === "eval" || (<Identifier>node).text === "arguments");
}
function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
if (node.typeParameters) {
return grammarErrorAtPos(getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
@ -14289,13 +14079,8 @@ namespace ts {
function checkGrammarNumericLiteral(node: Identifier): boolean {
// Grammar checking
if (node.flags & NodeFlags.OctalLiteral) {
if (node.parserContextFlags & ParserContextFlags.StrictMode) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
}
else if (languageVersion >= ScriptTarget.ES5) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
}
if (node.flags & NodeFlags.OctalLiteral && languageVersion >= ScriptTarget.ES5) {
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
}
}

View file

@ -179,8 +179,8 @@ namespace ts {
A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" },
Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" },
Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1213, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" },
Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode: { code: 1214, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode. Modules are automatically in strict mode." },
Invalid_use_of_0_Modules_are_automatically_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Modules are automatically in strict mode." },
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." },
Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." },
@ -398,6 +398,8 @@ namespace ts {
Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." },
Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." },
The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." },
yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." },
await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },

View file

@ -703,14 +703,14 @@
"category": "Error",
"code": 1213
},
"Type expected. '{0}' is a reserved word in strict mode": {
"Identifier expected. '{0}' is a reserved word in strict mode. Modules are automatically in strict mode.": {
"category": "Error",
"code": 1214
},
"Invalid use of '{0}'. Modules are automatically in strict mode.": {
"category": "Error",
"code": 1215
},
"Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode.": {
"category": "Error",
"code": 1216
},
"Export assignment is not supported when '--module' flag is 'system'.": {
"category": "Error",
"code": 1218
@ -1570,7 +1570,6 @@
"category": "Error",
"code": 2505
},
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
"category": "Error",
"code": 2520
@ -1583,6 +1582,14 @@
"category": "Error",
"code": 2522
},
"'yield' expressions cannot be used in a parameter initializer.": {
"category": "Error",
"code": 2523
},
"'await' expressions cannot be used in a parameter initializer.": {
"category": "Error",
"code": 2524
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",

View file

@ -546,7 +546,7 @@ namespace ts {
token = nextToken();
processReferenceComments(sourceFile);
sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseStatement);
sourceFile.statements = parseList(ParsingContext.SourceElements, parseStatement);
Debug.assert(token === SyntaxKind.EndOfFileToken);
sourceFile.endOfFileToken = parseTokenNode();
@ -649,10 +649,6 @@ namespace ts {
}
}
function setStrictModeContext(val: boolean) {
setContextFlag(val, ParserContextFlags.StrictMode);
}
function setDisallowInContext(val: boolean) {
setContextFlag(val, ParserContextFlags.DisallowIn);
}
@ -661,10 +657,6 @@ namespace ts {
setContextFlag(val, ParserContextFlags.Yield);
}
function setGeneratorParameterContext(val: boolean) {
setContextFlag(val, ParserContextFlags.GeneratorParameter);
}
function setDecoratorContext(val: boolean) {
setContextFlag(val, ParserContextFlags.Decorator);
}
@ -672,11 +664,7 @@ namespace ts {
function setAwaitContext(val: boolean) {
setContextFlag(val, ParserContextFlags.Await);
}
function setAsyncParameterContext(val: boolean) {
setContextFlag(val, ParserContextFlags.AsyncParameter);
}
function doOutsideOfContext<T>(context: ParserContextFlags, func: () => T): T {
// contextFlagsToClear will contain only the context flags that are
// currently set that we need to temporarily clear
@ -763,14 +751,6 @@ namespace ts {
return inContext(ParserContextFlags.Yield);
}
function inStrictModeContext() {
return inContext(ParserContextFlags.StrictMode);
}
function inGeneratorParameterContext() {
return inContext(ParserContextFlags.GeneratorParameter);
}
function inDisallowInContext() {
return inContext(ParserContextFlags.DisallowIn);
}
@ -782,15 +762,7 @@ namespace ts {
function inAwaitContext() {
return inContext(ParserContextFlags.Await);
}
function inAsyncParameterContext() {
return inContext(ParserContextFlags.AsyncParameter);
}
function inGeneratorParameterOrAsyncParameterContext() {
return inContext(ParserContextFlags.GeneratorParameter | ParserContextFlags.AsyncParameter);
}
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void {
let start = scanner.getTokenPos();
let length = scanner.getTextPos() - start;
@ -1083,24 +1055,16 @@ namespace ts {
}
function parseComputedPropertyName(): ComputedPropertyName {
// PropertyName[Yield,GeneratorParameter] :
// LiteralPropertyName
// [+GeneratorParameter] ComputedPropertyName
// [+AsyncParameter] ComputedPropertyName
// [~GeneratorParameter,~AsyncParameter] ComputedPropertyName[?Yield,?Await]
//
// ComputedPropertyName[Yield] :
// [ AssignmentExpression[In, ?Yield] ]
//
// PropertyName [Yield]:
// LiteralPropertyName
// ComputedPropertyName[?Yield]
let node = <ComputedPropertyName>createNode(SyntaxKind.ComputedPropertyName);
parseExpected(SyntaxKind.OpenBracketToken);
// We parse any expression (including a comma expression). But the grammar
// says that only an assignment expression is allowed, so the grammar checker
// will error if it sees a comma expression.
node.expression = inGeneratorParameterOrAsyncParameterContext()
? doOutsideOfYieldAndAwaitContext(allowInAndParseExpression)
: allowInAnd(parseExpression);
node.expression = allowInAnd(parseExpression);
parseExpected(SyntaxKind.CloseBracketToken);
return finishNode(node);
@ -1355,31 +1319,17 @@ namespace ts {
}
// Parses a list of elements
function parseList<T extends Node>(kind: ParsingContext, checkForStrictMode: boolean, parseElement: () => T): NodeArray<T> {
function parseList<T extends Node>(kind: ParsingContext, parseElement: () => T): NodeArray<T> {
let saveParsingContext = parsingContext;
parsingContext |= 1 << kind;
let result = <NodeArray<T>>[];
result.pos = getNodePos();
let savedStrictModeContext = inStrictModeContext();
while (!isListTerminator(kind)) {
if (isListElement(kind, /* inErrorRecovery */ false)) {
let element = parseListElement(kind, parseElement);
result.push(element);
// test elements only if we are not already in strict mode
if (checkForStrictMode && !inStrictModeContext()) {
if (isPrologueDirective(element)) {
if (isUseStrictPrologueDirective(element)) {
setStrictModeContext(true);
checkForStrictMode = false;
}
}
else {
checkForStrictMode = false;
}
}
continue;
}
@ -1388,22 +1338,11 @@ namespace ts {
}
}
setStrictModeContext(savedStrictModeContext);
result.end = getNodeEnd();
parsingContext = saveParsingContext;
return result;
}
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
function isUseStrictPrologueDirective(node: Node): boolean {
Debug.assert(isPrologueDirective(node));
let nodeText = getTextOfNodeFromSourceText(sourceText, (<ExpressionStatement>node).expression);
// Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the
// string to contain unicode escapes (as per ES5).
return nodeText === '"use strict"' || nodeText === "'use strict'";
}
function parseListElement<T extends Node>(parsingContext: ParsingContext, parseElement: () => T): T {
let node = currentNode(parsingContext);
if (node) {
@ -1991,8 +1930,8 @@ namespace ts {
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
setModifiers(node, parseModifiers());
// FormalParameter[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified) See 14.1
// BindingElement[?Yield,?GeneratorParameter,?Await,?AsyncParameter]
// FormalParameter [Yield,Await]:
// BindingElement[?Yield,?Await]
node.name = parseIdentifierOrPattern();
@ -2024,18 +1963,7 @@ namespace ts {
}
function parseBindingElementInitializer(inParameter: boolean) {
// BindingElement[Yield,GeneratorParameter,Await,AsyncParameter] :
// [+GeneratorParameter] BindingPattern[?Yield,?Await,?AsyncParameter,GeneratorParameter] Initializer[In]opt
// [+AsyncParameter] BindingPattern[?Yield,?GeneratorParameter,?Await,AsyncParameter] Initializer[In]opt
// [~GeneratorParameter,~AsyncParameter] BindingPattern[?Yield,?Await] Initializer[In,?Yield,?Await]opt
// SingleNameBinding[Yield,GeneratorParameter,Await,AsyncParameter] :
// [+GeneratorParameter] BindingIdentifier[Yield, ?Await] Initializer[In]opt
// [+AsyncParameter] BindingIdentifier[Await, ?Yield] Initializer[In]opt
// [~GeneratorParameter,~AsyncParameter] BindingIdentifier[?Yield,?Await] Initializer[In,?Yield,?Await]opt
let parseInitializer = inParameter ? parseParameterInitializer : parseNonParameterInitializer;
return inGeneratorParameterOrAsyncParameterContext()
? doOutsideOfYieldAndAwaitContext(parseInitializer)
: parseInitializer();
return inParameter ? parseParameterInitializer() : parseNonParameterInitializer();
}
function parseParameterInitializer() {
@ -2043,14 +1971,15 @@ namespace ts {
}
function fillSignature(
returnToken: SyntaxKind,
yieldAndGeneratorParameterContext: boolean,
awaitAndAsyncParameterContext: boolean,
requireCompleteParameterList: boolean,
signature: SignatureDeclaration): void {
returnToken: SyntaxKind,
yieldContext: boolean,
awaitContext: boolean,
requireCompleteParameterList: boolean,
signature: SignatureDeclaration): void {
let returnTokenRequired = returnToken === SyntaxKind.EqualsGreaterThanToken;
signature.typeParameters = parseTypeParameters();
signature.parameters = parseParameterList(yieldAndGeneratorParameterContext, awaitAndAsyncParameterContext, requireCompleteParameterList);
signature.parameters = parseParameterList(yieldContext, awaitContext, requireCompleteParameterList);
if (returnTokenRequired) {
parseExpected(returnToken);
@ -2061,44 +1990,31 @@ namespace ts {
}
}
// Note: after careful analysis of the grammar, it does not appear to be possible to
// have 'Yield' And 'GeneratorParameter' not in sync. i.e. any production calling
// this FormalParameters production either always sets both to true, or always sets
// both to false. As such we only have a single parameter to represent both.
function parseParameterList(yieldAndGeneratorParameterContext: boolean, awaitAndAsyncParameterContext: boolean, requireCompleteParameterList: boolean) {
// FormalParameters[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified)
// ...
function parseParameterList(yieldContext: boolean, awaitContext: boolean, requireCompleteParameterList: boolean) {
// FormalParameters [Yield,Await]: (modified)
// [empty]
// FormalParameterList[?Yield,Await]
//
// FormalParameter[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified)
// BindingElement[?Yield,?GeneratorParameter,?Await,?AsyncParameter]
// FormalParameter[Yield,Await]: (modified)
// BindingElement[?Yield,Await]
//
// BindingElement[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified) See 13.2.3
// SingleNameBinding[?Yield,?GeneratorParameter,?Await,?AsyncParameter]
// [+GeneratorParameter]BindingPattern[?Yield,?Await,?AsyncParameter,GeneratorParameter] Initializer[In]opt
// [+AsyncParameter]BindingPattern[?Yield,?Await,?GeneratorParameter,AsyncParameter] Initializer[In]opt
// [~GeneratorParameter,~AsyncParameter]BindingPattern[?Yield,?Await]Initializer[In,?Yield,?Await]opt
// BindingElement [Yield,Await]: (modified)
// SingleNameBinding[?Yield,?Await]
// BindingPattern[?Yield,?Await]Initializer [In, ?Yield,?Await] opt
//
// SingleNameBinding[Yield,GeneratorParameter,Await,AsyncParameter] : (Modified) See 13.2.3
// [+GeneratorParameter]BindingIdentifier[Yield]Initializer[In]opt
// [+AsyncParameter]BindingIdentifier[Await]Initializer[In]opt
// [~GeneratorParameter,~AsyncParameter]BindingIdentifier[?Yield,?Await]Initializer[In,?Yield,?Await]opt
// SingleNameBinding [Yield,Await]:
// BindingIdentifier[?Yield,?Await]Initializer [In, ?Yield,?Await] opt
if (parseExpected(SyntaxKind.OpenParenToken)) {
let savedYieldContext = inYieldContext();
let savedGeneratorParameterContext = inGeneratorParameterContext();
let savedAwaitContext = inAwaitContext();
let savedAsyncParameterContext = inAsyncParameterContext();
setYieldContext(yieldAndGeneratorParameterContext);
setGeneratorParameterContext(yieldAndGeneratorParameterContext);
setAwaitContext(awaitAndAsyncParameterContext);
setAsyncParameterContext(awaitAndAsyncParameterContext);
setYieldContext(yieldContext);
setAwaitContext(awaitContext);
let result = parseDelimitedList(ParsingContext.Parameters, parseParameter);
setYieldContext(savedYieldContext);
setGeneratorParameterContext(savedGeneratorParameterContext);
setAwaitContext(savedAwaitContext);
setAsyncParameterContext(savedAsyncParameterContext);
if (!parseExpected(SyntaxKind.CloseParenToken) && requireCompleteParameterList) {
// Caller insisted that we had to end with a ) We didn't. So just return
@ -2131,7 +2047,7 @@ namespace ts {
if (kind === SyntaxKind.ConstructSignature) {
parseExpected(SyntaxKind.NewKeyword);
}
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, node);
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
parseTypeMemberSemicolon();
return finishNode(node);
}
@ -2220,8 +2136,8 @@ namespace ts {
method.questionToken = questionToken;
// Method signatues don't exist in expression contexts. So they have neither
// [Yield] nor [GeneratorParameter]
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, method);
// [Yield] nor [Await]
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, method);
parseTypeMemberSemicolon();
return finishNode(method);
}
@ -2331,7 +2247,7 @@ namespace ts {
function parseObjectTypeMembers(): NodeArray<Declaration> {
let members: NodeArray<Declaration>;
if (parseExpected(SyntaxKind.OpenBraceToken)) {
members = parseList(ParsingContext.TypeMembers, /*checkForStrictMode*/ false, parseTypeMember);
members = parseList(ParsingContext.TypeMembers, parseTypeMember);
parseExpected(SyntaxKind.CloseBraceToken);
}
else {
@ -2360,7 +2276,7 @@ namespace ts {
if (kind === SyntaxKind.ConstructorType) {
parseExpected(SyntaxKind.NewKeyword);
}
fillSignature(SyntaxKind.EqualsGreaterThanToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, node);
fillSignature(SyntaxKind.EqualsGreaterThanToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
return finishNode(node);
}
@ -2694,12 +2610,6 @@ namespace ts {
return true;
}
if (inStrictModeContext()) {
// If we're in strict mode, then 'yield' is a keyword, could only ever start
// a yield expression.
return true;
}
// We're in a context where 'yield expr' is not allowed. However, if we can
// definitely tell that the user was trying to parse a 'yield expr' and not
// just a normal expr that start with a 'yield' identifier, then parse out
@ -2714,7 +2624,7 @@ namespace ts {
// for now we just check if the next token is an identifier. More heuristics
// can be added here later as necessary. We just need to make sure that we
// don't accidently consume something legal.
return lookAhead(nextTokenIsIdentifierOnSameLine);
return lookAhead(nextTokenIsIdentifierOrKeywordOrNumberOnSameLine);
}
return false;
@ -2912,7 +2822,7 @@ namespace ts {
// a => (b => c)
// And think that "(b =>" was actually a parenthesized arrow function with a missing
// close paren.
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ isAsync, /*requireCompleteParameterList*/ !allowAmbiguity, node);
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ !allowAmbiguity, node);
// If we couldn't get parameters, we definitely could not parse out an arrow function.
if (!node.parameters) {
@ -3566,11 +3476,12 @@ namespace ts {
return finishNode(node);
}
// GeneratorExpression :
function parseFunctionExpression(): FunctionExpression {
// function * BindingIdentifier[Yield]opt (FormalParameters[Yield, GeneratorParameter]) { GeneratorBody[Yield] }
// GeneratorExpression:
// function* BindingIdentifier [Yield][opt](FormalParameters[Yield]){ GeneratorBody }
//
// FunctionExpression:
// function BindingIdentifieropt(FormalParameters) { FunctionBody }
// function BindingIdentifier[opt](FormalParameters){ FunctionBody }
let saveDecoratorContext = inDecoratorContext();
if (saveDecoratorContext) {
setDecoratorContext(false);
@ -3589,7 +3500,7 @@ namespace ts {
isAsync ? doInAwaitContext(parseOptionalIdentifier) :
parseOptionalIdentifier();
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ isGenerator, /*awaitAndAsyncParameterContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false);
if (saveDecoratorContext) {
@ -3616,10 +3527,10 @@ namespace ts {
}
// STATEMENTS
function parseBlock(ignoreMissingOpenBrace: boolean, checkForStrictMode: boolean, diagnosticMessage?: DiagnosticMessage): Block {
function parseBlock(ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): Block {
let node = <Block>createNode(SyntaxKind.Block);
if (parseExpected(SyntaxKind.OpenBraceToken, diagnosticMessage) || ignoreMissingOpenBrace) {
node.statements = parseList(ParsingContext.BlockStatements, checkForStrictMode, parseStatement);
node.statements = parseList(ParsingContext.BlockStatements, parseStatement);
parseExpected(SyntaxKind.CloseBraceToken);
}
else {
@ -3642,7 +3553,7 @@ namespace ts {
setDecoratorContext(false);
}
let block = parseBlock(ignoreMissingOpenBrace, /*checkForStrictMode*/ true, diagnosticMessage);
let block = parseBlock(ignoreMissingOpenBrace, diagnosticMessage);
if (saveDecoratorContext) {
setDecoratorContext(true);
@ -3785,7 +3696,7 @@ namespace ts {
parseExpected(SyntaxKind.CaseKeyword);
node.expression = allowInAnd(parseExpression);
parseExpected(SyntaxKind.ColonToken);
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement);
node.statements = parseList(ParsingContext.SwitchClauseStatements, parseStatement);
return finishNode(node);
}
@ -3793,7 +3704,7 @@ namespace ts {
let node = <DefaultClause>createNode(SyntaxKind.DefaultClause);
parseExpected(SyntaxKind.DefaultKeyword);
parseExpected(SyntaxKind.ColonToken);
node.statements = parseList(ParsingContext.SwitchClauseStatements, /*checkForStrictMode*/ false, parseStatement);
node.statements = parseList(ParsingContext.SwitchClauseStatements, parseStatement);
return finishNode(node);
}
@ -3809,7 +3720,7 @@ namespace ts {
parseExpected(SyntaxKind.CloseParenToken);
let caseBlock = <CaseBlock>createNode(SyntaxKind.CaseBlock, scanner.getStartPos());
parseExpected(SyntaxKind.OpenBraceToken);
caseBlock.clauses = parseList(ParsingContext.SwitchClauses, /*checkForStrictMode*/ false, parseCaseOrDefaultClause);
caseBlock.clauses = parseList(ParsingContext.SwitchClauses, parseCaseOrDefaultClause);
parseExpected(SyntaxKind.CloseBraceToken);
node.caseBlock = finishNode(caseBlock);
return finishNode(node);
@ -3836,14 +3747,14 @@ namespace ts {
let node = <TryStatement>createNode(SyntaxKind.TryStatement);
parseExpected(SyntaxKind.TryKeyword);
node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false);
node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false);
node.catchClause = token === SyntaxKind.CatchKeyword ? parseCatchClause() : undefined;
// If we don't have a catch clause, then we must have a finally clause. Try to parse
// one out no matter what.
if (!node.catchClause || token === SyntaxKind.FinallyKeyword) {
parseExpected(SyntaxKind.FinallyKeyword);
node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false);
node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false);
}
return finishNode(node);
@ -3857,7 +3768,7 @@ namespace ts {
}
parseExpected(SyntaxKind.CloseParenToken);
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false);
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false);
return finishNode(result);
}
@ -3903,6 +3814,11 @@ namespace ts {
return token === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak();
}
function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() {
nextToken();
return (isIdentifierOrKeyword() || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak();
}
function isDeclaration(): boolean {
while (true) {
switch (token) {
@ -4033,16 +3949,15 @@ namespace ts {
}
}
function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() {
function nextTokenIsIdentifierOrStartOfDestructuring() {
nextToken();
return !scanner.hasPrecedingLineBreak() &&
(isIdentifier() || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken);
return isIdentifier() || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken;
}
function isLetDeclaration() {
// It is let declaration if in strict mode or next token is identifier\open bracket\open curly on same line.
// otherwise it needs to be treated like identifier
return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine);
// In ES6 'let' always starts a lexical declaration if followed by an identifier or {
// or [.
return lookAhead(nextTokenIsIdentifierOrStartOfDestructuring);
}
function parseStatement(): Statement {
@ -4050,7 +3965,7 @@ namespace ts {
case SyntaxKind.SemicolonToken:
return parseEmptyStatement();
case SyntaxKind.OpenBraceToken:
return parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false);
return parseBlock(/*ignoreMissingOpenBrace*/ false);
case SyntaxKind.VarKeyword:
return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined);
case SyntaxKind.LetKeyword:
@ -4303,7 +4218,7 @@ namespace ts {
node.name = node.flags & NodeFlags.Default ? parseOptionalIdentifier() : parseIdentifier();
let isGenerator = !!node.asteriskToken;
let isAsync = isAsyncFunctionLike(node);
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ isGenerator, /*awaitAndAsyncParameterContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
node.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, Diagnostics.or_expected);
return finishNode(node);
}
@ -4313,7 +4228,7 @@ namespace ts {
node.decorators = decorators;
setModifiers(node, modifiers);
parseExpected(SyntaxKind.ConstructorKeyword);
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, node);
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false, Diagnostics.or_expected);
return finishNode(node);
}
@ -4327,7 +4242,7 @@ namespace ts {
method.questionToken = questionToken;
let isGenerator = !!asteriskToken;
let isAsync = isAsyncFunctionLike(method);
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ isGenerator, /*awaitAndAsyncParameterContext*/ isAsync, /*requireCompleteParameterList*/ false, method);
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, method);
method.body = parseFunctionBlockOrSemicolon(isGenerator, isAsync, diagnosticMessage);
return finishNode(method);
}
@ -4381,7 +4296,7 @@ namespace ts {
node.decorators = decorators;
setModifiers(node, modifiers);
node.name = parsePropertyName();
fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*awaitAndAsyncParameterContext*/ false, /*requireCompleteParameterList*/ false, node);
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ false, /*awaitContext*/ false, /*requireCompleteParameterList*/ false, node);
node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, /*isAsync*/ false);
return finishNode(node);
}
@ -4591,10 +4506,6 @@ namespace ts {
}
function parseClassDeclarationOrExpression(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray, kind: SyntaxKind): ClassLikeDeclaration {
// In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code
let savedStrictModeContext = inStrictModeContext();
setStrictModeContext(true);
var node = <ClassLikeDeclaration>createNode(kind, fullStart);
node.decorators = decorators;
setModifiers(node, modifiers);
@ -4613,9 +4524,7 @@ namespace ts {
node.members = createMissingList<ClassElement>();
}
var finishedNode = finishNode(node);
setStrictModeContext(savedStrictModeContext);
return finishedNode;
return finishNode(node);
}
function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray<HeritageClause> {
@ -4623,12 +4532,16 @@ namespace ts {
// ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt }
if (isHeritageClause()) {
return parseList(ParsingContext.HeritageClauses, /*checkForStrictMode:*/ false, parseHeritageClause);
return parseList(ParsingContext.HeritageClauses, parseHeritageClause);
}
return undefined;
}
function parseHeritageClausesWorker() {
return parseList(ParsingContext.HeritageClauses, parseHeritageClause);
}
function parseHeritageClause() {
if (token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword) {
let node = <HeritageClause>createNode(SyntaxKind.HeritageClause);
@ -4656,7 +4569,7 @@ namespace ts {
}
function parseClassMembers() {
return parseList(ParsingContext.ClassMembers, /*checkForStrictMode*/ false, parseClassElement);
return parseList(ParsingContext.ClassMembers, parseClassElement);
}
function parseInterfaceDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): InterfaceDeclaration {
@ -4714,7 +4627,7 @@ namespace ts {
function parseModuleBlock(): ModuleBlock {
let node = <ModuleBlock>createNode(SyntaxKind.ModuleBlock, scanner.getStartPos());
if (parseExpected(SyntaxKind.OpenBraceToken)) {
node.statements = parseList(ParsingContext.BlockStatements, /*checkForStrictMode*/ false, parseStatement);
node.statements = parseList(ParsingContext.BlockStatements, parseStatement);
parseExpected(SyntaxKind.CloseBraceToken);
}
else {

View file

@ -366,58 +366,41 @@ namespace ts {
export const enum ParserContextFlags {
None = 0,
// Set if this node was parsed in strict mode. Used for grammar error checks, as well as
// checking if the node can be reused in incremental settings.
StrictMode = 1 << 0,
// If this node was parsed in a context where 'in-expressions' are not allowed.
DisallowIn = 1 << 1,
DisallowIn = 1 << 0,
// If this node was parsed in the 'yield' context created when parsing a generator.
Yield = 1 << 2,
// If this node was parsed in the parameters of a generator.
GeneratorParameter = 1 << 3,
Yield = 1 << 1,
// If this node was parsed as part of a decorator
Decorator = 1 << 4,
Decorator = 1 << 2,
// If this node was parsed in the 'await' context created when parsing an async function.
Await = 1 << 5,
// If this node was parsed in the parameters of an async function.
AsyncParameter = 1 << 6,
Await = 1 << 3,
// If the parser encountered an error when parsing the code that created this node. Note
// the parser only sets this directly on the node it creates right after encountering the
// error.
ThisNodeHasError = 1 << 7,
ThisNodeHasError = 1 << 4,
// This node was parsed in a JavaScript file and can be processed differently. For example
// its type can be specified usign a JSDoc comment.
JavaScriptFile = 1 << 8,
JavaScriptFile = 1 << 5,
// Context flags set directly by the parser.
ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError | Await | AsyncParameter,
// Context flags passed as part of the modified ES6 grammar.
YieldAndGeneratorParameterFlags = Yield | GeneratorParameter,
AwaitAndAsyncParameterFlags = Await | AsyncParameter,
ParserGeneratedFlags = DisallowIn | Yield | Decorator | ThisNodeHasError | Await,
// Exclude these flags when parsing a Type
TypeExcludesFlags = YieldAndGeneratorParameterFlags | AwaitAndAsyncParameterFlags,
TypeExcludesFlags = Yield | Await,
// Context flags computed by aggregating child flags upwards.
// Used during incremental parsing to determine if this node or any of its children had an
// error. Computed only once and then cached.
ThisNodeOrAnySubNodesHasError = 1 << 9,
// Used to know if we've computed whether any children of this node are or contain an 'await' or 'yield' expression.
ThisNodeOrAnySubNodesHasAwaitOrYield = 1 << 10,
ThisNodeOrAnySubNodesHasError = 1 << 6,
// Used to know if we've computed data from children and cached it in this node.
HasAggregatedChildData = 1 << 11
HasAggregatedChildData = 1 << 7
}
/* @internal */

View file

@ -1206,6 +1206,41 @@ namespace ts {
return false;
}
// Return true if the given identifier is classified as an IdentifierName
export function isIdentifierName(node: Identifier): boolean {
let parent = node.parent;
switch (parent.kind) {
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.EnumMember:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.PropertyAccessExpression:
// Name in member declaration or property name in property access
return (<Declaration | PropertyAccessExpression>parent).name === node;
case SyntaxKind.QualifiedName:
// Name on right hand side of dot in a type query
if ((<QualifiedName>parent).right === node) {
while (parent.kind === SyntaxKind.QualifiedName) {
parent = parent.parent;
}
return parent.kind === SyntaxKind.TypeQuery;
}
return false;
case SyntaxKind.BindingElement:
case SyntaxKind.ImportSpecifier:
// Property name in binding element or import specifier
return (<BindingElement | ImportSpecifier>parent).propertyName === node;
case SyntaxKind.ExportSpecifier:
// Any name in an export specifier
return true;
}
return false;
}
// An alias symbol is created by one of the following declarations:
// import <symbol> = ...
// import <symbol> from ...

View file

@ -1,8 +1,20 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,10): error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,26): error TS1005: ',' expected.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,29): error TS1138: Parameter declaration expected.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,29): error TS2304: Cannot find name 'yield'.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,34): error TS1005: ';' expected.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (1 errors) ====
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (5 errors) ====
function * foo(a = yield => yield) {
~
!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
~~~~~~~~~
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
~~
!!! error TS1005: ',' expected.
~~~~~
!!! error TS1138: Parameter declaration expected.
~~~~~
!!! error TS2304: Cannot find name 'yield'.
~
!!! error TS1005: ';' expected.
}

View file

@ -3,6 +3,6 @@ function * foo(a = yield => yield) {
}
//// [FunctionDeclaration10_es6.js]
function foo(a) {
if (a === void 0) { a = function (yield) { return yield; }; }
yield;
{
}

View file

@ -1,5 +1,5 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,18): error TS2304: Cannot find name 'yield'.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,18): error TS2523: 'yield' expressions cannot be used in a parameter initializer.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts (2 errors) ====
@ -7,5 +7,5 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,1
~
!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
~~~~~
!!! error TS2304: Cannot find name 'yield'.
!!! error TS2523: 'yield' expressions cannot be used in a parameter initializer.
}

View file

@ -1,6 +1,6 @@
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,11): error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,20): error TS2304: Cannot find name 'yield'.
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,20): error TS2523: 'yield' expressions cannot be used in a parameter initializer.
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts (3 errors) ====
@ -12,6 +12,6 @@ tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,2
~
!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher.
~~~~~
!!! error TS2304: Cannot find name 'yield'.
!!! error TS2523: 'yield' expressions cannot be used in a parameter initializer.
}
}

View file

@ -1,8 +1,11 @@
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,4): error TS1123: Variable declaration list cannot be empty.
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,1): error TS1212: Identifier expected. 'let' is a reserved word in strict mode
tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts(2,1): error TS2304: Cannot find name 'let'.
==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts (1 errors) ====
==== tests/cases/conformance/es6/variableDeclarations/VariableDeclaration11_es6.ts (2 errors) ====
"use strict";
let
!!! error TS1123: Variable declaration list cannot be empty.
~~~
!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode
~~~
!!! error TS2304: Cannot find name 'let'.

View file

@ -4,4 +4,4 @@ let
//// [VariableDeclaration11_es6.js]
"use strict";
let ;
let;

View file

@ -1,8 +1,14 @@
tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts(2,1): error TS1163: A 'yield' expression is only allowed in a generator body.
tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts(2,1): error TS1212: Identifier expected. 'yield' is a reserved word in strict mode
tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts(2,1): error TS2304: Cannot find name 'yield'.
tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts(2,7): error TS2304: Cannot find name 'foo'.
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts (1 errors) ====
==== tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts (3 errors) ====
"use strict";
yield(foo);
~~~~~
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
!!! error TS1212: Identifier expected. 'yield' is a reserved word in strict mode
~~~~~
!!! error TS2304: Cannot find name 'yield'.
~~~
!!! error TS2304: Cannot find name 'foo'.

View file

@ -4,4 +4,4 @@ yield(foo);
//// [YieldExpression18_es6.js]
"use strict";
yield (foo);
yield(foo);

View file

@ -1,9 +1,12 @@
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts(2,22): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts(2,22): error TS2524: 'await' expressions cannot be used in a parameter initializer.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts(2,27): error TS1109: Expression expected.
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts (1 errors) ====
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction6_es6.ts (2 errors) ====
var foo = async (a = await): Promise<void> => {
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~
!!! error TS1109: Expression expected.
}

View file

@ -4,6 +4,6 @@ var foo = async (a = await): Promise<void> => {
}
//// [asyncArrowFunction6_es6.js]
var foo = (a = await) => __awaiter(function* () {
var foo = (a = yield ) => __awaiter(function* () {
},
this, void 0, Promise);

View file

@ -1,12 +1,15 @@
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts(4,24): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts(4,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts(4,29): error TS1109: Expression expected.
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts (1 errors) ====
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction7_es6.ts (2 errors) ====
var bar = async (): Promise<void> => {
// 'await' here is an identifier, and not an await expression.
var foo = async (a = await): Promise<void> => {
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~
!!! error TS1109: Expression expected.
}
}

View file

@ -9,7 +9,7 @@ var bar = async (): Promise<void> => {
//// [asyncArrowFunction7_es6.js]
var bar = () => __awaiter(function* () {
// 'await' here is an identifier, and not an await expression.
var foo = (a = await) => __awaiter(function* () {
var foo = (a = yield ) => __awaiter(function* () {
},
this, void 0, Promise);
},

View file

@ -0,0 +1,23 @@
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,11): error TS2304: Cannot find name 'async'.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,18): error TS2304: Cannot find name 'a'.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,37): error TS1005: ',' expected.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,39): error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,46): error TS1005: '=' expected.
tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts(1,53): error TS1109: Expression expected.
==== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts (6 errors) ====
var foo = async (a = await => await): Promise<void> => {
~~~~~
!!! error TS2304: Cannot find name 'async'.
~
!!! error TS2304: Cannot find name 'a'.
~
!!! error TS1005: ',' expected.
~~~~~~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'void'.
~
!!! error TS1005: '=' expected.
~~
!!! error TS1109: Expression expected.
}

View file

@ -3,6 +3,6 @@ var foo = async (a = await => await): Promise<void> => {
}
//// [asyncArrowFunction9_es6.js]
var foo = (a = await => await) => __awaiter(function* () {
},
this, void 0, Promise);
var foo = async(a = await => await), Promise = ;
{
}

View file

@ -1,8 +0,0 @@
=== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts ===
var foo = async (a = await => await): Promise<void> => {
>foo : Symbol(foo, Decl(asyncArrowFunction9_es6.ts, 0, 3))
>a : Symbol(a, Decl(asyncArrowFunction9_es6.ts, 0, 17))
>await : Symbol(await, Decl(asyncArrowFunction9_es6.ts, 0, 20))
>await : Symbol(await, Decl(asyncArrowFunction9_es6.ts, 0, 20))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
}

View file

@ -1,10 +0,0 @@
=== tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts ===
var foo = async (a = await => await): Promise<void> => {
>foo : (a?: (await: any) => any) => Promise<void>
>async (a = await => await): Promise<void> => {} : (a?: (await: any) => any) => Promise<void>
>a : (await: any) => any
>await => await : (await: any) => any
>await : any
>await : any
>Promise : Promise<T>
}

View file

@ -0,0 +1,26 @@
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,20): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,30): error TS1109: Expression expected.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,33): error TS1138: Parameter declaration expected.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,33): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,38): error TS1005: ';' expected.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,39): error TS1128: Declaration or statement expected.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,53): error TS1109: Expression expected.
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts (7 errors) ====
async function foo(a = await => await): Promise<void> {
~~~~~~~~~
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
~~
!!! error TS1109: Expression expected.
~~~~~
!!! error TS1138: Parameter declaration expected.
~~~~~
!!! error TS2304: Cannot find name 'await'.
~
!!! error TS1005: ';' expected.
~
!!! error TS1128: Declaration or statement expected.
~
!!! error TS1109: Expression expected.
}

View file

@ -3,8 +3,5 @@ async function foo(a = await => await): Promise<void> {
}
//// [asyncFunctionDeclaration10_es6.js]
function foo(a = await => await) {
return __awaiter(function* () {
},
this, void 0, Promise);
}
await;
Promise < void > {};

View file

@ -1,8 +0,0 @@
=== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts ===
async function foo(a = await => await): Promise<void> {
>foo : Symbol(foo, Decl(asyncFunctionDeclaration10_es6.ts, 0, 0))
>a : Symbol(a, Decl(asyncFunctionDeclaration10_es6.ts, 0, 19))
>await : Symbol(await, Decl(asyncFunctionDeclaration10_es6.ts, 0, 22))
>await : Symbol(await, Decl(asyncFunctionDeclaration10_es6.ts, 0, 22))
>Promise : Symbol(Promise, Decl(lib.d.ts, 4768, 1), Decl(lib.d.ts, 4854, 11))
}

View file

@ -1,9 +0,0 @@
=== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts ===
async function foo(a = await => await): Promise<void> {
>foo : (a?: (await: any) => any) => Promise<void>
>a : (await: any) => any
>await => await : (await: any) => any
>await : any
>await : any
>Promise : Promise<T>
}

View file

@ -1,8 +1,11 @@
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts(1,24): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts(1,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts(1,29): error TS1109: Expression expected.
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts (1 errors) ====
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration6_es6.ts (2 errors) ====
async function foo(a = await): Promise<void> {
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~
!!! error TS1109: Expression expected.
}

View file

@ -3,7 +3,7 @@ async function foo(a = await): Promise<void> {
}
//// [asyncFunctionDeclaration6_es6.js]
function foo(a = await) {
function foo(a = yield ) {
return __awaiter(function* () {
},
this, void 0, Promise);

View file

@ -1,11 +1,14 @@
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts(3,26): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts(3,26): error TS2524: 'await' expressions cannot be used in a parameter initializer.
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts(3,31): error TS1109: Expression expected.
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts (1 errors) ====
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration7_es6.ts (2 errors) ====
async function bar(): Promise<void> {
// 'await' here is an identifier, and not a yield expression.
async function foo(a = await): Promise<void> {
~~~~~
!!! error TS2304: Cannot find name 'await'.
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
~
!!! error TS1109: Expression expected.
}
}

View file

@ -9,7 +9,7 @@ async function bar(): Promise<void> {
function bar() {
return __awaiter(function* () {
// 'await' here is an identifier, and not a yield expression.
function foo(a = await) {
function foo(a = yield ) {
return __awaiter(function* () {
},
this, void 0, Promise);

View file

@ -1,9 +1,10 @@
tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorInvalidOperations.ts(5,20): error TS1005: ',' expected.
tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorInvalidOperations.ts(5,27): error TS1109: Expression expected.
tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorInvalidOperations.ts(8,23): error TS1109: Expression expected.
tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorInvalidOperations.ts(13,16): error TS1102: 'delete' cannot be called on an identifier in strict mode.
==== tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorInvalidOperations.ts (3 errors) ====
==== tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperatorInvalidOperations.ts (4 errors) ====
// Unary operator delete
var ANY;
@ -23,5 +24,7 @@ tests/cases/conformance/expressions/unaryOperators/deleteOperator/deleteOperator
class testADelx {
constructor(public s: () => {}) {
delete s; //expect error
~
!!! error TS1102: 'delete' cannot be called on an identifier in strict mode.
}
}

View file

@ -1,8 +1,11 @@
tests/cases/compiler/downlevelLetConst11.ts(2,4): error TS1123: Variable declaration list cannot be empty.
tests/cases/compiler/downlevelLetConst11.ts(2,1): error TS1212: Identifier expected. 'let' is a reserved word in strict mode
tests/cases/compiler/downlevelLetConst11.ts(2,1): error TS2304: Cannot find name 'let'.
==== tests/cases/compiler/downlevelLetConst11.ts (1 errors) ====
==== tests/cases/compiler/downlevelLetConst11.ts (2 errors) ====
"use strict";
let
!!! error TS1123: Variable declaration list cannot be empty.
~~~
!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode
~~~
!!! error TS2304: Cannot find name 'let'.

View file

@ -4,4 +4,4 @@ let
//// [downlevelLetConst11.js]
"use strict";
var ;
let;

View file

@ -1,15 +1,18 @@
tests/cases/conformance/externalModules/exportNonInitializedVariablesAMD.ts(2,4): error TS1123: Variable declaration list cannot be empty.
tests/cases/conformance/externalModules/exportNonInitializedVariablesAMD.ts(3,1): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
tests/cases/conformance/externalModules/exportNonInitializedVariablesAMD.ts(3,1): error TS2304: Cannot find name 'let'.
tests/cases/conformance/externalModules/exportNonInitializedVariablesAMD.ts(4,6): error TS1123: Variable declaration list cannot be empty.
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesAMD.ts (3 errors) ====
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesAMD.ts (4 errors) ====
var;
!!! error TS1123: Variable declaration list cannot be empty.
let;
~~~
!!! error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~
!!! error TS2304: Cannot find name 'let'.
const;

View file

@ -1,15 +1,18 @@
tests/cases/conformance/externalModules/exportNonInitializedVariablesCommonJS.ts(2,4): error TS1123: Variable declaration list cannot be empty.
tests/cases/conformance/externalModules/exportNonInitializedVariablesCommonJS.ts(3,1): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
tests/cases/conformance/externalModules/exportNonInitializedVariablesCommonJS.ts(3,1): error TS2304: Cannot find name 'let'.
tests/cases/conformance/externalModules/exportNonInitializedVariablesCommonJS.ts(4,6): error TS1123: Variable declaration list cannot be empty.
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesCommonJS.ts (3 errors) ====
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesCommonJS.ts (4 errors) ====
var;
!!! error TS1123: Variable declaration list cannot be empty.
let;
~~~
!!! error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~
!!! error TS2304: Cannot find name 'let'.
const;

View file

@ -1,15 +1,18 @@
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(2,4): error TS1123: Variable declaration list cannot be empty.
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(3,1): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(3,1): error TS2304: Cannot find name 'let'.
tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts(4,6): error TS1123: Variable declaration list cannot be empty.
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts (3 errors) ====
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesES6.ts (4 errors) ====
var;
!!! error TS1123: Variable declaration list cannot be empty.
let;
~~~
!!! error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~
!!! error TS2304: Cannot find name 'let'.
const;

View file

@ -1,15 +1,18 @@
tests/cases/conformance/externalModules/exportNonInitializedVariablesSystem.ts(2,4): error TS1123: Variable declaration list cannot be empty.
tests/cases/conformance/externalModules/exportNonInitializedVariablesSystem.ts(3,1): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
tests/cases/conformance/externalModules/exportNonInitializedVariablesSystem.ts(3,1): error TS2304: Cannot find name 'let'.
tests/cases/conformance/externalModules/exportNonInitializedVariablesSystem.ts(4,6): error TS1123: Variable declaration list cannot be empty.
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesSystem.ts (3 errors) ====
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesSystem.ts (4 errors) ====
var;
!!! error TS1123: Variable declaration list cannot be empty.
let;
~~~
!!! error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~
!!! error TS2304: Cannot find name 'let'.
const;

View file

@ -1,15 +1,18 @@
tests/cases/conformance/externalModules/exportNonInitializedVariablesUMD.ts(2,4): error TS1123: Variable declaration list cannot be empty.
tests/cases/conformance/externalModules/exportNonInitializedVariablesUMD.ts(3,1): error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
tests/cases/conformance/externalModules/exportNonInitializedVariablesUMD.ts(3,1): error TS2304: Cannot find name 'let'.
tests/cases/conformance/externalModules/exportNonInitializedVariablesUMD.ts(4,6): error TS1123: Variable declaration list cannot be empty.
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesUMD.ts (3 errors) ====
==== tests/cases/conformance/externalModules/exportNonInitializedVariablesUMD.ts (4 errors) ====
var;
!!! error TS1123: Variable declaration list cannot be empty.
let;
~~~
!!! error TS1214: Identifier expected. 'let' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~
!!! error TS2304: Cannot find name 'let'.
const;

View file

@ -0,0 +1,23 @@
tests/cases/conformance/es6/modules/t3.ts(1,17): error TS1214: Identifier expected. 'yield' is a reserved word in strict mode. Modules are automatically in strict mode.
==== tests/cases/conformance/es6/modules/t1.ts (0 errors) ====
let set = {
set foo(x: number) {
}
}
let get = 10;
export { set, get };
==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ====
import * as set from "./t1";
==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ====
import { set as yield } from "./t1";
~~~~~
!!! error TS1214: Identifier expected. 'yield' is a reserved word in strict mode. Modules are automatically in strict mode.
==== tests/cases/conformance/es6/modules/t4.ts (0 errors) ====
import { get } from "./t1";

View file

@ -1,30 +0,0 @@
=== tests/cases/conformance/es6/modules/t1.ts ===
let set = {
>set : Symbol(set, Decl(t1.ts, 1, 3))
set foo(x: number) {
>foo : Symbol(foo, Decl(t1.ts, 1, 11))
>x : Symbol(x, Decl(t1.ts, 2, 12))
}
}
let get = 10;
>get : Symbol(get, Decl(t1.ts, 5, 3))
export { set, get };
>set : Symbol(set, Decl(t1.ts, 7, 8))
>get : Symbol(get, Decl(t1.ts, 7, 13))
=== tests/cases/conformance/es6/modules/t2.ts ===
import * as set from "./t1";
>set : Symbol(set, Decl(t2.ts, 0, 6))
=== tests/cases/conformance/es6/modules/t3.ts ===
import { set as yield } from "./t1";
>set : Symbol(yield, Decl(t3.ts, 0, 8))
>yield : Symbol(yield, Decl(t3.ts, 0, 8))
=== tests/cases/conformance/es6/modules/t4.ts ===
import { get } from "./t1";
>get : Symbol(get, Decl(t4.ts, 0, 8))

View file

@ -1,32 +0,0 @@
=== tests/cases/conformance/es6/modules/t1.ts ===
let set = {
>set : { foo: number; }
>{ set foo(x: number) { }} : { foo: number; }
set foo(x: number) {
>foo : number
>x : number
}
}
let get = 10;
>get : number
>10 : number
export { set, get };
>set : { foo: number; }
>get : number
=== tests/cases/conformance/es6/modules/t2.ts ===
import * as set from "./t1";
>set : typeof set
=== tests/cases/conformance/es6/modules/t3.ts ===
import { set as yield } from "./t1";
>set : { foo: number; }
>yield : { foo: number; }
=== tests/cases/conformance/es6/modules/t4.ts ===
import { get } from "./t1";
>get : number

View file

@ -0,0 +1,15 @@
tests/cases/compiler/letAsIdentifier.ts(3,5): error TS2300: Duplicate identifier 'a'.
tests/cases/compiler/letAsIdentifier.ts(6,1): error TS2300: Duplicate identifier 'a'.
==== tests/cases/compiler/letAsIdentifier.ts (2 errors) ====
var let = 10;
var a = 10;
~
!!! error TS2300: Duplicate identifier 'a'.
let = 30;
let
a;
~
!!! error TS2300: Duplicate identifier 'a'.

View file

@ -10,10 +10,10 @@ a;
var let = 10;
var a = 10;
let = 30;
let;
a;
var a;
//// [letAsIdentifier.d.ts]
declare var let: number;
declare var a: number;
declare let a: any;

View file

@ -1,17 +0,0 @@
=== tests/cases/compiler/letAsIdentifier.ts ===
var let = 10;
>let : Symbol(let, Decl(letAsIdentifier.ts, 1, 3))
var a = 10;
>a : Symbol(a, Decl(letAsIdentifier.ts, 2, 3))
let = 30;
>let : Symbol(let, Decl(letAsIdentifier.ts, 1, 3))
let
>let : Symbol(let, Decl(letAsIdentifier.ts, 1, 3))
a;
>a : Symbol(a, Decl(letAsIdentifier.ts, 2, 3))

View file

@ -1,21 +0,0 @@
=== tests/cases/compiler/letAsIdentifier.ts ===
var let = 10;
>let : number
>10 : number
var a = 10;
>a : number
>10 : number
let = 30;
>let = 30 : number
>let : number
>30 : number
let
>let : number
a;
>a : number

View file

@ -1,20 +1,20 @@
tests/cases/compiler/letAsIdentifierInStrictMode.ts(2,5): error TS1212: Identifier expected. 'let' is a reserved word in strict mode
tests/cases/compiler/letAsIdentifierInStrictMode.ts(3,5): error TS2300: Duplicate identifier 'a'.
tests/cases/compiler/letAsIdentifierInStrictMode.ts(4,5): error TS1134: Variable declaration expected.
tests/cases/compiler/letAsIdentifierInStrictMode.ts(4,7): error TS1134: Variable declaration expected.
tests/cases/compiler/letAsIdentifierInStrictMode.ts(4,1): error TS1212: Identifier expected. 'let' is a reserved word in strict mode
tests/cases/compiler/letAsIdentifierInStrictMode.ts(6,1): error TS2300: Duplicate identifier 'a'.
==== tests/cases/compiler/letAsIdentifierInStrictMode.ts (4 errors) ====
"use strict";
var let = 10;
~~~
!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode
var a = 10;
~
!!! error TS2300: Duplicate identifier 'a'.
let = 30;
~
!!! error TS1134: Variable declaration expected.
~~
!!! error TS1134: Variable declaration expected.
~~~
!!! error TS1212: Identifier expected. 'let' is a reserved word in strict mode
let
a;
~

View file

@ -10,6 +10,5 @@ a;
"use strict";
var let = 10;
var a = 10;
var ;
30;
let = 30;
var a;

View file

@ -1,4 +1,4 @@
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21): error TS2304: Cannot find name 'public'.
@ -7,7 +7,7 @@ tests/cases/conformance/parser/ecmascript5/RegressionTests/parser553699.ts(3,21)
constructor() { }
public banana (x: public) { }
~~~~~~
!!! error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
~~~~~~
!!! error TS2304: Cannot find name 'public'.
}

View file

@ -16,30 +16,32 @@ tests/cases/compiler/strictModeReservedWord.ts(12,41): error TS1212: Identifier
tests/cases/compiler/strictModeReservedWord.ts(13,11): error TS1212: Identifier expected. 'private' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(13,20): error TS1212: Identifier expected. 'public' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(13,28): error TS1212: Identifier expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(15,25): error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWord.ts(15,25): error TS9003: 'class' expressions are not currently supported.
tests/cases/compiler/strictModeReservedWord.ts(15,41): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWord.ts(17,9): error TS2300: Duplicate identifier 'b'.
tests/cases/compiler/strictModeReservedWord.ts(17,12): error TS1215: Type expected. 'public' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(17,12): error TS1212: Identifier expected. 'public' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(17,12): error TS2503: Cannot find namespace 'public'.
tests/cases/compiler/strictModeReservedWord.ts(19,21): error TS1215: Type expected. 'private' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(19,21): error TS1212: Identifier expected. 'private' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(19,21): error TS2503: Cannot find namespace 'private'.
tests/cases/compiler/strictModeReservedWord.ts(20,22): error TS1215: Type expected. 'private' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(20,22): error TS1212: Identifier expected. 'private' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(20,22): error TS2503: Cannot find namespace 'private'.
tests/cases/compiler/strictModeReservedWord.ts(20,30): error TS1215: Type expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(21,22): error TS1215: Type expected. 'private' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(20,30): error TS1212: Identifier expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(21,22): error TS1212: Identifier expected. 'private' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(21,22): error TS2503: Cannot find namespace 'private'.
tests/cases/compiler/strictModeReservedWord.ts(21,30): error TS1215: Type expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(21,38): error TS1215: Type expected. 'protected' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(21,30): error TS1212: Identifier expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(21,38): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(22,9): error TS2300: Duplicate identifier 'b'.
tests/cases/compiler/strictModeReservedWord.ts(22,12): error TS1215: Type expected. 'interface' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(22,12): error TS1212: Identifier expected. 'interface' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(22,12): error TS2503: Cannot find namespace 'interface'.
tests/cases/compiler/strictModeReservedWord.ts(22,22): error TS1215: Type expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(22,30): error TS1215: Type expected. 'implements' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(22,22): error TS1212: Identifier expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(22,30): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(23,5): error TS2304: Cannot find name 'ublic'.
tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS1212: Identifier expected. 'static' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS2349: Cannot invoke an expression whose type lacks a call signature.
==== tests/cases/compiler/strictModeReservedWord.ts (39 errors) ====
==== tests/cases/compiler/strictModeReservedWord.ts (41 errors) ====
let let = 10;
function foo() {
@ -92,48 +94,52 @@ tests/cases/compiler/strictModeReservedWord.ts(24,5): error TS2349: Cannot invok
var myClass = class package extends public {}
~~~~~~~
!!! error TS1213: Identifier expected. 'package' is a reserved word in strict mode. Class definitions are automatically in strict mode.
~~~~~~~
!!! error TS9003: 'class' expressions are not currently supported.
~~~~~~
!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
var b: public.bar;
~
!!! error TS2300: Duplicate identifier 'b'.
~~~~~~
!!! error TS1215: Type expected. 'public' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode
~~~~~~
!!! error TS2503: Cannot find namespace 'public'.
function foo(x: private.x) { }
~~~~~~~
!!! error TS1215: Type expected. 'private' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode
~~~~~~~
!!! error TS2503: Cannot find namespace 'private'.
function foo1(x: private.package.x) { }
~~~~~~~
!!! error TS1215: Type expected. 'private' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode
~~~~~~~
!!! error TS2503: Cannot find namespace 'private'.
~~~~~~~
!!! error TS1215: Type expected. 'package' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode
function foo2(x: private.package.protected) { }
~~~~~~~
!!! error TS1215: Type expected. 'private' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode
~~~~~~~
!!! error TS2503: Cannot find namespace 'private'.
~~~~~~~
!!! error TS1215: Type expected. 'package' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode
~~~~~~~~~
!!! error TS1215: Type expected. 'protected' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
let b: interface.package.implements.B;
~
!!! error TS2300: Duplicate identifier 'b'.
~~~~~~~~~
!!! error TS1215: Type expected. 'interface' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'interface' is a reserved word in strict mode
~~~~~~~~~
!!! error TS2503: Cannot find namespace 'interface'.
~~~~~~~
!!! error TS1215: Type expected. 'package' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode
~~~~~~~~~~
!!! error TS1215: Type expected. 'implements' is a reserved word in strict mode
!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode
ublic();
~~~~~
!!! error TS2304: Cannot find name 'ublic'.

View file

@ -4,13 +4,14 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(4,34): error TS
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(5,9): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(5,19): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(5,28): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(7,22): error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(7,22): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(11,24): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(11,32): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(13,10): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(13,19): error TS1213: Identifier expected. 'static' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(13,27): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(14,18): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(15,26): error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,9): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(21,17): error TS1213: Identifier expected. 'private' is a reserved word in strict mode. Class definitions are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(23,20): error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
@ -24,7 +25,7 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T
tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error TS2503: Cannot find namespace 'package'.
==== tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts (24 errors) ====
==== tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts (25 errors) ====
interface public { }
class Foo {
@ -45,7 +46,7 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T
}
public banana(x: public) { }
~~~~~~
!!! error TS1216: Type expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
!!! error TS1213: Identifier expected. 'public' is a reserved word in strict mode. Class definitions are automatically in strict mode.
}
class C {
@ -66,6 +67,8 @@ tests/cases/compiler/strictModeReservedWordInClassDeclaration.ts(28,17): error T
~~~
!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode.
var z = function let() { };
~~~
!!! error TS1213: Identifier expected. 'let' is a reserved word in strict mode. Class definitions are automatically in strict mode.
}
public pulbic() { } // No Error;

View file

@ -3,8 +3,8 @@ tests/cases/compiler/strictModeReservedWordInDestructuring.ts(3,10): error TS121
tests/cases/compiler/strictModeReservedWordInDestructuring.ts(4,7): error TS1212: Identifier expected. 'private' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWordInDestructuring.ts(5,15): error TS1212: Identifier expected. 'static' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWordInDestructuring.ts(5,38): error TS1212: Identifier expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWordInDestructuring.ts(6,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWordInDestructuring.ts(6,14): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWordInDestructuring.ts(6,7): error TS1212: Identifier expected. 'public' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWordInDestructuring.ts(6,15): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
==== tests/cases/compiler/strictModeReservedWordInDestructuring.ts (7 errors) ====
@ -18,13 +18,15 @@ tests/cases/compiler/strictModeReservedWordInDestructuring.ts(6,14): error TS121
var [[private]] = [["hello"]];
~~~~~~~
!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode
var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } };
var { y: { s: static }, z: { o: { p: package } }} = { y: { s: 1 }, z: { o: { p: 'h' } } };
~~~~~~
!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode
~~~~~~~
!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode
var {public, protected} = { public: 1, protected: 2 };
~~~~~~
var { public, protected } = { public: 1, protected: 2 };
~~~~~~
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode
~~~~~~~~~
!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
~~~~~~~~~
!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode
var { public: a, protected: b } = { public: 1, protected: 2 };

View file

@ -3,8 +3,10 @@
var [public] = [1];
var { x: public } = { x: 1 };
var [[private]] = [["hello"]];
var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } };
var {public, protected} = { public: 1, protected: 2 };
var { y: { s: static }, z: { o: { p: package } }} = { y: { s: 1 }, z: { o: { p: 'h' } } };
var { public, protected } = { public: 1, protected: 2 };
var { public: a, protected: b } = { public: 1, protected: 2 };
//// [strictModeReservedWordInDestructuring.js]
"use strict";
@ -13,3 +15,4 @@ var public = { x: 1 }.x;
var private = [["hello"]][0][0];
var _a = { y: { s: 1 }, z: { o: { p: 'h' } } }, static = _a.y.s, package = _a.z.o.p;
var _b = { public: 1, protected: 2 }, public = _b.public, protected = _b.protected;
var _c = { public: 1, protected: 2 }, a = _c.public, b = _c.protected;

View file

@ -1,4 +1,4 @@
tests/cases/compiler/strictModeReservedWordInImportEqualDeclaration.ts(3,8): error TS1212: Identifier expected. 'public' is a reserved word in strict mode
tests/cases/compiler/strictModeReservedWordInImportEqualDeclaration.ts(3,8): error TS1214: Identifier expected. 'public' is a reserved word in strict mode. Modules are automatically in strict mode.
tests/cases/compiler/strictModeReservedWordInImportEqualDeclaration.ts(3,25): error TS2307: Cannot find module '1'.
@ -7,6 +7,6 @@ tests/cases/compiler/strictModeReservedWordInImportEqualDeclaration.ts(3,25): er
"use strict"
import public = require("1");
~~~~~~
!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode
!!! error TS1214: Identifier expected. 'public' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~
!!! error TS2307: Cannot find module '1'.

View file

@ -1,22 +1,25 @@
tests/cases/compiler/strictModeWordInImportDeclaration.ts(2,13): error TS1212: Identifier expected. 'package' is a reserved word in strict mode
tests/cases/compiler/strictModeWordInImportDeclaration.ts(2,13): error TS1214: Identifier expected. 'package' is a reserved word in strict mode. Modules are automatically in strict mode.
tests/cases/compiler/strictModeWordInImportDeclaration.ts(2,26): error TS2307: Cannot find module './1'.
tests/cases/compiler/strictModeWordInImportDeclaration.ts(3,16): error TS1212: Identifier expected. 'private' is a reserved word in strict mode
tests/cases/compiler/strictModeWordInImportDeclaration.ts(3,16): error TS1214: Identifier expected. 'private' is a reserved word in strict mode. Modules are automatically in strict mode.
tests/cases/compiler/strictModeWordInImportDeclaration.ts(3,30): error TS2307: Cannot find module './1'.
tests/cases/compiler/strictModeWordInImportDeclaration.ts(4,8): error TS1214: Identifier expected. 'public' is a reserved word in strict mode. Modules are automatically in strict mode.
tests/cases/compiler/strictModeWordInImportDeclaration.ts(4,20): error TS2307: Cannot find module './1'.
==== tests/cases/compiler/strictModeWordInImportDeclaration.ts (5 errors) ====
==== tests/cases/compiler/strictModeWordInImportDeclaration.ts (6 errors) ====
"use strict"
import * as package from "./1"
~~~~~~~
!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode
!!! error TS1214: Identifier expected. 'package' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~~~
!!! error TS2307: Cannot find module './1'.
import {foo as private} from "./1"
~~~~~~~
!!! error TS1212: Identifier expected. 'private' is a reserved word in strict mode
!!! error TS1214: Identifier expected. 'private' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~~~
!!! error TS2307: Cannot find module './1'.
import public from "./1"
~~~~~~
!!! error TS1214: Identifier expected. 'public' is a reserved word in strict mode. Modules are automatically in strict mode.
~~~~~
!!! error TS2307: Cannot find module './1'.

View file

@ -2,5 +2,6 @@
var [public] = [1];
var { x: public } = { x: 1 };
var [[private]] = [["hello"]];
var { y: { s: static }, z: { o: { p: package} }} = { y: { s: 1 }, z: { o: { p: 'h' } } };
var {public, protected} = { public: 1, protected: 2 };
var { y: { s: static }, z: { o: { p: package } }} = { y: { s: 1 }, z: { o: { p: 'h' } } };
var { public, protected } = { public: 1, protected: 2 };
var { public: a, protected: b } = { public: 1, protected: 2 };

View file

@ -252,11 +252,6 @@ module ts {
});
it('Strict mode 1',() => {
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
//
// Note: in this test we don't actually add 'use strict'. This is so we can compare
// reuse with/without a strict mode change.
var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();";
var oldText = ScriptSnapshot.fromString(source);
@ -266,23 +261,15 @@ module ts {
});
it('Strict mode 2',() => {
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
var source = "foo1();\r\nfoo1();\r\nfoo1();\r\package();";
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withInsert(oldText, 0, "'use strict';\r\n");
// Note the decreased reuse of nodes compared to 'Strict mode 1'
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 9);
});
it('Strict mode 3',() => {
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
//
// Note: in this test we don't actually remove 'use strict'. This is so we can compare
// reuse with/without a strict mode change.
var source = "'strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();";
var index = source.indexOf('f');
@ -293,16 +280,13 @@ module ts {
});
it('Strict mode 4',() => {
// In non-strict mode 'package' means nothing and can be reused. In strict mode though
// we'll have to reparse the nodes (and generate an error for 'package();'
var source = "'use strict';\r\nfoo1();\r\nfoo1();\r\nfoo1();\r\npackage();";
var index = source.indexOf('f');
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withDelete(oldText, 0, index);
// Note the decreased reuse of nodes compared to testStrictMode3
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 9);
});
it('Strict mode 5',() => {
@ -312,7 +296,7 @@ module ts {
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, index, 6, "strict");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 27);
});
it('Strict mode 6',() => {
@ -322,7 +306,7 @@ module ts {
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, index, 6, "blahhh");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 27);
});
it('Strict mode 7',() => {
@ -492,7 +476,6 @@ module ts {
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, index, ": Foo<Bar<".length, "= ");
// Note the decreased reuse of nodes compared to testStrictMode3
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
});
@ -545,7 +528,7 @@ module ts {
var index = source.lastIndexOf(";");
var newTextAndChange = withDelete(oldText, index, 1);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 11);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 14);
});
it('Edit after empty type parameter list',() => {
@ -555,7 +538,7 @@ module ts {
var index = source.length;
var newTextAndChange = withInsert(oldText, index, "var x;");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 2);
});
it('Delete parameter after comment',() => {
@ -595,7 +578,7 @@ constructor(name) { }\
var index = source.indexOf("100");
var newTextAndChange = withInsert(oldText, index, "'1', ");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 5);
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 7);
});
it('Insert declare modifier before module',() => {
@ -718,7 +701,7 @@ module m3 { }\
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code.
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4);
});
it('Moving methods from object literal to class in strict mode', () => {
@ -736,7 +719,7 @@ module m3 { }\
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "class".length, "interface");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code.
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18);
});
it('Moving index signatures from class to interface in strict mode', () => {
@ -754,7 +737,7 @@ module m3 { }\
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "interface".length, "class");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code.
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18);
});
@ -782,7 +765,7 @@ module m3 { }\
var oldText = ScriptSnapshot.fromString(source);
var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C");
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code.
compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4);
});