Skip to content

Commit

Permalink
Merge pull request #39219 from typescript-bot/pick/39216/release-4.0
Browse files Browse the repository at this point in the history
🤖 Pick PR #39216 (Leverage syntax cursor as part of r...) into release-4.0
  • Loading branch information
DanielRosenwasser committed Jun 24, 2020
2 parents edb72ea + fd2ddfe commit 99700c7
Show file tree
Hide file tree
Showing 101 changed files with 2,178 additions and 2,318 deletions.
435 changes: 213 additions & 222 deletions lib/tsc.js

Large diffs are not rendered by default.

456 changes: 230 additions & 226 deletions lib/tsserver.js

Large diffs are not rendered by default.

456 changes: 230 additions & 226 deletions lib/tsserverlibrary.js

Large diffs are not rendered by default.

456 changes: 230 additions & 226 deletions lib/typescript.js

Large diffs are not rendered by default.

456 changes: 230 additions & 226 deletions lib/typescriptServices.js

Large diffs are not rendered by default.

456 changes: 230 additions & 226 deletions lib/typingsInstaller.js

Large diffs are not rendered by default.

39 changes: 29 additions & 10 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2109,20 +2109,39 @@ namespace ts {
}

// 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) &&
// check for reserved words used as identifiers in strict mode code, as well as `yield` or `await` in
// [Yield] or [Await] contexts, respectively.
function checkContextualIdentifier(node: Identifier) {
// Report error only if there are no parse errors in file
if (!file.parseDiagnostics.length &&
!(node.flags & NodeFlags.Ambient) &&
!(node.flags & NodeFlags.JSDoc)) {
!(node.flags & NodeFlags.JSDoc) &&
!isIdentifierName(node)) {

// Report error only if there are no parse errors in file
if (!file.parseDiagnostics.length) {
// strict mode identifiers
if (inStrictMode &&
node.originalKeywordKind! >= SyntaxKind.FirstFutureReservedWord &&
node.originalKeywordKind! <= SyntaxKind.LastFutureReservedWord) {
file.bindDiagnostics.push(createDiagnosticForNode(node,
getStrictModeIdentifierMessage(node), declarationNameToString(node)));
}
else if (node.originalKeywordKind === SyntaxKind.AwaitKeyword) {
if (isExternalModule(file) && isInTopLevelContext(node)) {
file.bindDiagnostics.push(createDiagnosticForNode(node,
Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module,
declarationNameToString(node)));
}
else if (node.flags & NodeFlags.AwaitContext) {
file.bindDiagnostics.push(createDiagnosticForNode(node,
Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here,
declarationNameToString(node)));
}
}
else if (node.originalKeywordKind === SyntaxKind.YieldKeyword && node.flags & NodeFlags.YieldContext) {
file.bindDiagnostics.push(createDiagnosticForNode(node,
Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here,
declarationNameToString(node)));
}
}
}

Expand Down Expand Up @@ -2423,7 +2442,7 @@ namespace ts {
if (currentFlow && (isExpression(node) || parent.kind === SyntaxKind.ShorthandPropertyAssignment)) {
node.flowNode = currentFlow;
}
return checkStrictModeIdentifier(<Identifier>node);
return checkContextualIdentifier(<Identifier>node);
case SyntaxKind.SuperKeyword:
node.flowNode = currentFlow;
break;
Expand Down
27 changes: 1 addition & 26 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28557,11 +28557,6 @@ namespace ts {
return undefinedWideningType;
}

function isInTopLevelContext(node: Node) {
const container = getThisContainer(node, /*includeArrowFunctions*/ true);
return isSourceFile(container);
}

function checkAwaitExpression(node: AwaitExpression): Type {
// Grammar checking
if (produceDiagnostics) {
Expand Down Expand Up @@ -35168,7 +35163,6 @@ namespace ts {
}

function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) {
checkGrammarAwaitIdentifier(node.name);
checkCollisionWithRequireExportsInGeneratedCode(node, node.name!);
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name!);
checkAliasSymbol(node);
Expand Down Expand Up @@ -37934,31 +37928,19 @@ namespace ts {
return false;
}

function checkGrammarAwaitIdentifier(name: Identifier | undefined): boolean {
if (name && isIdentifier(name) && name.originalKeywordKind === SyntaxKind.AwaitKeyword && isInTopLevelContext(name.parent)) {
const file = getSourceFileOfNode(name);
if (!file.isDeclarationFile && isExternalModule(file)) {
return grammarErrorOnNode(name, Diagnostics.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, idText(name));
}
}
return false;
}

function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration | MethodSignature): boolean {
// Prevent cascading error by short-circuit
const file = getSourceFileOfNode(node);
return checkGrammarDecoratorsAndModifiers(node) ||
checkGrammarTypeParameterList(node.typeParameters, file) ||
(isFunctionDeclaration(node) && checkGrammarAwaitIdentifier(node.name)) ||
checkGrammarParameterList(node.parameters) ||
checkGrammarArrowFunction(node, file) ||
(isFunctionLikeDeclaration(node) && checkGrammarForUseStrictSimpleParameterList(node));
}

function checkGrammarClassLikeDeclaration(node: ClassLikeDeclaration): boolean {
const file = getSourceFileOfNode(node);
return (isClassDeclaration(node) && checkGrammarAwaitIdentifier(node.name)) ||
checkGrammarClassDeclarationHeritageClauses(node) ||
return checkGrammarClassDeclarationHeritageClauses(node) ||
checkGrammarTypeParameterList(node.typeParameters, file);
}

Expand Down Expand Up @@ -38601,10 +38583,6 @@ namespace ts {
}
}

if (isIdentifier(node.name) && checkGrammarAwaitIdentifier(node.name)) {
return true;
}

if (node.dotDotDotToken && node.initializer) {
// Error on equals token which immediately precedes the initializer
return grammarErrorAtPos(node, node.initializer.pos - 1, 1, Diagnostics.A_rest_element_cannot_have_an_initializer);
Expand Down Expand Up @@ -38668,9 +38646,6 @@ namespace ts {
}
}
}
if (isIdentifier(node.name) && checkGrammarAwaitIdentifier(node.name)) {
return true;
}

if (node.exclamationToken && (node.parent.parent.kind !== SyntaxKind.VariableStatement || !node.type || node.initializer || node.flags & NodeFlags.Ambient)) {
return grammarErrorOnNode(node.exclamationToken, Diagnostics.Definite_assignment_assertions_can_only_be_used_along_with_a_type_annotation);
Expand Down
Loading

0 comments on commit 99700c7

Please sign in to comment.