diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 192398a72520b..fe42127a06012 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -28210,7 +28210,7 @@ namespace ts { return undefinedWideningType; } - function isTopLevelAwait(node: AwaitExpression) { + function isInTopLevelContext(node: Node) { const container = getThisContainer(node, /*includeArrowFunctions*/ true); return isSourceFile(container); } @@ -28219,7 +28219,7 @@ namespace ts { // Grammar checking if (produceDiagnostics) { if (!(node.flags & NodeFlags.AwaitContext)) { - if (isTopLevelAwait(node)) { + if (isInTopLevelContext(node)) { const sourceFile = getSourceFileOfNode(node); if (!hasParseDiagnostics(sourceFile)) { let span: TextSpan | undefined; @@ -33533,7 +33533,7 @@ namespace ts { function checkThrowStatement(node: ThrowStatement) { // Grammar checking if (!checkGrammarStatementInAmbientContext(node)) { - if (node.expression === undefined) { + if (isIdentifier(node.expression) && !node.expression.escapedText) { grammarErrorAfterFirstToken(node, Diagnostics.Line_break_not_permitted_here); } } @@ -34802,6 +34802,7 @@ namespace ts { } function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { + checkGrammarAwaitIdentifier(node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name!); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name!); checkAliasSymbol(node); @@ -37545,17 +37546,32 @@ 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) || - checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file) || + 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 checkGrammarClassDeclarationHeritageClauses(node) || checkGrammarTypeParameterList(node.typeParameters, file); + return (isClassDeclaration(node) && checkGrammarAwaitIdentifier(node.name)) || + checkGrammarClassDeclarationHeritageClauses(node) || + checkGrammarTypeParameterList(node.typeParameters, file); } function checkGrammarArrowFunction(node: Node, file: SourceFile): boolean { @@ -38195,11 +38211,15 @@ namespace ts { if (node.propertyName) { return grammarErrorOnNode(node.name, Diagnostics.A_rest_element_cannot_have_a_property_name); } + } - if (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); - } + 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); } } @@ -38260,6 +38280,9 @@ 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); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e863de12537d6..040318974b619 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -867,6 +867,11 @@ "category": "Error", "code": 1261 }, + "Identifier expected. '{0}' is a reserved word at the top-level of a module.": { + "category": "Error", + "code": 1262 + }, + "'with' statements are not allowed in an async function block.": { "category": "Error", "code": 1300 diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 4814bf679e074..5bf069a9c25c2 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -556,8 +556,29 @@ namespace ts { decorators, modifiers ); - node.name = asName(name); - node.transformFlags |= propagateChildFlags(node.name); + name = asName(name); + node.name = name; + + // The PropertyName of a member is allowed to be `await`. + // We don't need to exclude `await` for type signatures since types + // don't propagate child flags. + if (name) { + switch (node.kind) { + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertyAssignment: + if (isIdentifier(name)) { + node.transformFlags |= propagateIdentifierNameFlags(name); + break; + } + // fall through + default: + node.transformFlags |= propagateChildFlags(name); + break; + } + } return node; } @@ -631,7 +652,7 @@ namespace ts { type ); node.body = body; - node.transformFlags |= propagateChildFlags(node.body); + node.transformFlags |= propagateChildFlags(node.body) & ~TransformFlags.ContainsPossibleTopLevelAwait; if (!body) node.transformFlags |= TransformFlags.ContainsTypeScript; return node; } @@ -824,6 +845,9 @@ namespace ts { // NOTE: we do not use `setChildren` here because typeArguments in an identifier do not contribute to transformations node.typeArguments = createNodeArray(typeArguments); } + if (node.originalKeywordKind === SyntaxKind.AwaitKeyword) { + node.transformFlags |= TransformFlags.ContainsPossibleTopLevelAwait; + } return node; } @@ -1013,7 +1037,7 @@ namespace ts { node.right = asName(right); node.transformFlags |= propagateChildFlags(node.left) | - propagateChildFlags(node.right); + propagateIdentifierNameFlags(node.right); return node; } @@ -2028,9 +2052,13 @@ namespace ts { node.propertyName = asName(propertyName); node.dotDotDotToken = dotDotDotToken; node.transformFlags |= - propagateChildFlags(node.propertyName) | propagateChildFlags(node.dotDotDotToken) | TransformFlags.ContainsES2015; + if (node.propertyName) { + node.transformFlags |= isIdentifier(node.propertyName) ? + propagateIdentifierNameFlags(node.propertyName) : + propagateChildFlags(node.propertyName); + } if (dotDotDotToken) node.transformFlags |= TransformFlags.ContainsRestOrSpread; return node; } @@ -2094,7 +2122,9 @@ namespace ts { node.name = asName(name); node.transformFlags = propagateChildFlags(node.expression) | - propagateChildFlags(node.name); + (isIdentifier(node.name) ? + propagateIdentifierNameFlags(node.name) : + propagateChildFlags(node.name)); if (isSuperKeyword(expression)) { // super method calls require a lexical 'this' // super method calls require 'super' hoisting in ES2017 and ES2018 async functions and async generators @@ -2124,10 +2154,12 @@ namespace ts { node.questionDotToken = questionDotToken; node.name = asName(name); node.transformFlags |= + TransformFlags.ContainsES2020 | propagateChildFlags(node.expression) | propagateChildFlags(node.questionDotToken) | - propagateChildFlags(node.name) | - TransformFlags.ContainsES2020; + (isIdentifier(node.name) ? + propagateIdentifierNameFlags(node.name) : + propagateChildFlags(node.name)); return node; } @@ -3556,6 +3588,7 @@ namespace ts { node.transformFlags |= propagateChildrenFlags(node.members) | TransformFlags.ContainsTypeScript; + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Enum declarations cannot contain `await` return node; } @@ -3599,6 +3632,7 @@ namespace ts { propagateChildFlags(node.body) | TransformFlags.ContainsTypeScript; } + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Module declarations cannot contain `await`. return node; } @@ -3683,6 +3717,7 @@ namespace ts { node.moduleReference = moduleReference; node.transformFlags |= propagateChildFlags(node.moduleReference); if (!isExternalModuleReference(node.moduleReference)) node.transformFlags |= TransformFlags.ContainsTypeScript; + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // Import= declaration is always parsed in an Await context return node; } @@ -3719,6 +3754,7 @@ namespace ts { node.transformFlags |= propagateChildFlags(node.importClause) | propagateChildFlags(node.moduleSpecifier); + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3750,6 +3786,7 @@ namespace ts { if (isTypeOnly) { node.transformFlags |= TransformFlags.ContainsTypeScript; } + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3767,6 +3804,7 @@ namespace ts { const node = createBaseNode(SyntaxKind.NamespaceImport); node.name = name; node.transformFlags |= propagateChildFlags(node.name); + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3784,6 +3822,7 @@ namespace ts { node.transformFlags |= propagateChildFlags(node.name) | TransformFlags.ContainsESNext; + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3799,6 +3838,7 @@ namespace ts { const node = createBaseNode(SyntaxKind.NamedImports); node.elements = createNodeArray(elements); node.transformFlags |= propagateChildrenFlags(node.elements); + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3817,6 +3857,7 @@ namespace ts { node.transformFlags |= propagateChildFlags(node.propertyName) | propagateChildFlags(node.name); + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3845,6 +3886,7 @@ namespace ts { ? parenthesizerRules().parenthesizeRightSideOfBinary(SyntaxKind.EqualsToken, /*leftSide*/ undefined, expression) : parenthesizerRules().parenthesizeExpressionOfExportDefault(expression); node.transformFlags |= propagateChildFlags(node.expression); + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3881,6 +3923,7 @@ namespace ts { node.transformFlags |= propagateChildFlags(node.exportClause) | propagateChildFlags(node.moduleSpecifier); + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3907,6 +3950,7 @@ namespace ts { const node = createBaseNode(SyntaxKind.NamedExports); node.elements = createNodeArray(elements); node.transformFlags |= propagateChildrenFlags(node.elements); + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3925,6 +3969,7 @@ namespace ts { node.transformFlags |= propagateChildFlags(node.propertyName) | propagateChildFlags(node.name); + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -3955,6 +4000,7 @@ namespace ts { const node = createBaseNode(SyntaxKind.ExternalModuleReference); node.expression = expression; node.transformFlags |= propagateChildFlags(node.expression); + node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context return node; } @@ -5777,14 +5823,19 @@ namespace ts { return tokenValue; } - function propagatePropertyNameFlags(node: PropertyName, transformFlags: TransformFlags) { + function propagateIdentifierNameFlags(node: Identifier) { + // An IdentifierName is allowed to be `await` + return propagateChildFlags(node) & ~TransformFlags.ContainsPossibleTopLevelAwait; + } + + function propagatePropertyNameFlagsOfChild(node: PropertyName, transformFlags: TransformFlags) { return transformFlags | (node.transformFlags & TransformFlags.PropertyNamePropagatingFlags); } function propagateChildFlags(child: Node | undefined): TransformFlags { if (!child) return TransformFlags.None; const childFlags = child.transformFlags & ~getTransformFlagsSubtreeExclusions(child.kind); - return isNamedDeclaration(child) && isPropertyName(child.name) ? propagatePropertyNameFlags(child.name, childFlags) : childFlags; + return isNamedDeclaration(child) && isPropertyName(child.name) ? propagatePropertyNameFlagsOfChild(child.name, childFlags) : childFlags; } function propagateChildrenFlags(children: NodeArray | undefined): TransformFlags { diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 459b578936901..21ec704bcc877 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -811,6 +811,11 @@ namespace ts { || kind === SyntaxKind.ExportDeclaration; } + /* @internal */ + export function isExportModifier(node: Modifier): node is ExportKeyword { + return node.kind === SyntaxKind.ExportKeyword; + } + /* @internal */ export function isAsyncModifier(node: Modifier): node is AsyncKeyword { return node.kind === SyntaxKind.AsyncKeyword; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 85c0402f663fb..fe8c99204b3aa 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -8,6 +8,12 @@ namespace ts { JSDoc = 1 << 5, } + const enum SpeculationKind { + TryParse, + Lookahead, + Reparse + } + let NodeConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; let TokenConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; let IdentifierConstructor: new (kind: SyntaxKind, pos?: number, end?: number) => Node; @@ -704,6 +710,33 @@ namespace ts { const factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters | NodeFactoryFlags.NoOriginalNode, baseNodeFactory); + const reparseContext: TransformationContext = { + get factory() { return factory; }, + enableEmitNotification: notImplemented, + enableSubstitution: notImplemented, + endLexicalEnvironment: returnUndefined, + getCompilerOptions: notImplemented, + getEmitHost: notImplemented, + getEmitResolver: notImplemented, + getEmitHelperFactory: notImplemented, + setLexicalEnvironmentFlags: noop, + getLexicalEnvironmentFlags: () => 0, + hoistFunctionDeclaration: notImplemented, + hoistVariableDeclaration: notImplemented, + addInitializationStatement: notImplemented, + isEmitNotificationEnabled: notImplemented, + isSubstitutionEnabled: notImplemented, + onEmitNode: notImplemented, + onSubstituteNode: notImplemented, + readEmitHelpers: notImplemented, + requestEmitHelper: notImplemented, + resumeLexicalEnvironment: noop, + startLexicalEnvironment: noop, + suspendLexicalEnvironment: noop, + addDiagnostic: notImplemented, + }; + + let fileName: string; let sourceFlags: NodeFlags; let sourceText: string; @@ -988,8 +1021,6 @@ namespace ts { processCommentPragmas(sourceFile as {} as PragmaContext, sourceText); processPragmasIntoFields(sourceFile as {} as PragmaContext, reportPragmaDiagnostic); - setExternalModuleIndicator(sourceFile); - sourceFile.commentDirectives = scanner.getCommentDirectives(); sourceFile.nodeCount = nodeCount; sourceFile.identifierCount = identifierCount; @@ -1021,6 +1052,133 @@ namespace ts { return node; } + function reparseTopLevelAwait(sourceFile: SourceFile) { + return visitEachChild(sourceFile, visitor, reparseContext); + + function visitor(node: Node): VisitResult { + if (!(node.transformFlags & TransformFlags.ContainsPossibleTopLevelAwait)) { + return node; + } + // We explicitly visit each non-Expression node that has an immediate Expression child so that + // we can reparse the Expression in an Await context + switch (node.kind) { + case SyntaxKind.Decorator: return reparseDecorator(node as Decorator); + case SyntaxKind.ComputedPropertyName: return reparseComputedPropertyName(node as ComputedPropertyName); + case SyntaxKind.ExpressionWithTypeArguments: return reparseExpressionWithTypeArguments(node as ExpressionWithTypeArguments); + case SyntaxKind.ExpressionStatement: return reparseExpressionStatement(node as ExpressionStatement); + case SyntaxKind.IfStatement: return reparseIfStatement(node as IfStatement); + case SyntaxKind.SwitchStatement: return reparseSwitchStatement(node as SwitchStatement); + case SyntaxKind.WithStatement: return reparseWithStatement(node as WithStatement); + case SyntaxKind.DoStatement: return reparseDoStatement(node as DoStatement); + case SyntaxKind.WhileStatement: return reparseWhileStatement(node as WhileStatement); + case SyntaxKind.ForStatement: return reparseForStatement(node as ForStatement); + case SyntaxKind.ForInStatement: return reparseForInStatement(node as ForInStatement); + case SyntaxKind.ForOfStatement: return reparseForOfStatement(node as ForOfStatement); + case SyntaxKind.ReturnStatement: return reparseReturnStatement(node as ReturnStatement); + case SyntaxKind.ThrowStatement: return reparseThrowStatement(node as ThrowStatement); + case SyntaxKind.ExportAssignment: return reparseExportAssignment(node as ExportAssignment); + case SyntaxKind.VariableDeclaration: return reparseVariableDeclaration(node as VariableDeclaration); + case SyntaxKind.BindingElement: return reparseBindingElement(node as BindingElement); + default: return visitEachChild(node, visitor, reparseContext); + } + } + + function reparse(node: T, parse: () => T): T | Expression; + function reparse(node: T | undefined, parse: () => T): T | Expression | undefined; + function reparse(node: T | undefined, parse: () => T) { + if (node && node.transformFlags & TransformFlags.ContainsPossibleTopLevelAwait) { + if (isExpression(node)) { + return speculationHelper(() => { + scanner.setTextPos(node.pos); + const savedContextFlags = contextFlags; + contextFlags = node.flags & NodeFlags.ContextFlags; + nextToken(); + const result = doInAwaitContext(parse); + contextFlags = savedContextFlags; + return result; + }, SpeculationKind.Reparse); + } + return visitEachChild(node, visitor, reparseContext); + } + return node; + } + + function update(updated: T, original: T) { + if (updated !== original) { + setNodeFlags(updated, updated.flags | NodeFlags.AwaitContext); + } + return updated; + } + + function reparseExpressionStatement(node: ExpressionStatement) { + return update(factory.updateExpressionStatement(node, reparse(node.expression, parseExpression)), node); + } + + function reparseReturnStatement(node: ReturnStatement) { + return update(factory.updateReturnStatement(node, reparse(node.expression, parseExpression)), node); + } + + function reparseThrowStatement(node: ThrowStatement) { + return update(factory.updateThrowStatement(node, reparse(node.expression, parseExpression)), node); + } + + function reparseIfStatement(node: IfStatement) { + return update(factory.updateIfStatement(node, reparse(node.expression, parseExpression), ts.visitNode(node.thenStatement, visitor), ts.visitNode(node.elseStatement, visitor)), node); + } + + function reparseSwitchStatement(node: SwitchStatement) { + return update(factory.updateSwitchStatement(node, reparse(node.expression, parseExpression), ts.visitNode(node.caseBlock, visitor)), node); + } + + function reparseWithStatement(node: WithStatement) { + return update(factory.updateWithStatement(node, reparse(node.expression, parseExpression), ts.visitNode(node.statement, visitor)), node); + } + + function reparseDoStatement(node: DoStatement) { + return update(factory.updateDoStatement(node, ts.visitNode(node.statement, visitor), reparse(node.expression, parseExpression)), node); + } + + function reparseWhileStatement(node: WhileStatement) { + return update(factory.updateWhileStatement(node, reparse(node.expression, parseExpression), ts.visitNode(node.statement, visitor)), node); + } + + function reparseForStatement(node: ForStatement) { + return update(factory.updateForStatement(node, reparse(node.initializer, parseExpression), reparse(node.condition, parseExpression), reparse(node.incrementor, parseExpression), ts.visitNode(node, visitor)), node); + } + + function reparseForInStatement(node: ForInStatement) { + return update(factory.updateForInStatement(node, reparse(node.initializer, parseExpression), reparse(node.expression, parseExpression), ts.visitNode(node.statement, visitor)), node); + } + + function reparseForOfStatement(node: ForOfStatement) { + return update(factory.updateForOfStatement(node, node.awaitModifier, reparse(node.initializer, parseExpression), reparse(node.expression, parseExpression), ts.visitNode(node.statement, visitor)), node); + } + + function reparseExportAssignment(node: ExportAssignment) { + return update(factory.updateExportAssignment(node, ts.visitNodes(node.decorators, visitor), node.modifiers, reparse(node.expression, parseExpression)), node); + } + + function reparseExpressionWithTypeArguments(node: ExpressionWithTypeArguments) { + return update(factory.updateExpressionWithTypeArguments(node, reparse(node.expression, parseLeftHandSideExpressionOrHigher), node.typeArguments), node); + } + + function reparseDecorator(node: Decorator) { + return update(factory.updateDecorator(node, reparse(node.expression, parseLeftHandSideExpressionOrHigher)), node); + } + + function reparseComputedPropertyName(node: ComputedPropertyName) { + return update(factory.updateComputedPropertyName(node, reparse(node.expression, parseExpression)), node); + } + + function reparseVariableDeclaration(node: VariableDeclaration) { + return update(factory.updateVariableDeclaration(node, ts.visitNode(node.name, visitor), node.exclamationToken, node.type, reparse(node.initializer, parseExpression)), node); + } + + function reparseBindingElement(node: BindingElement) { + return update(factory.updateBindingElement(node, node.dotDotDotToken, ts.visitNode(node.propertyName, visitor), ts.visitNode(node.name, visitor), reparse(node.initializer, parseExpression)), node); + } + } + export function fixupParentReferences(rootNode: Node) { // normally parent references are set during binding. However, for clients that only need // a syntax tree, and no semantic features, then the binding process is an unnecessary @@ -1032,8 +1190,15 @@ namespace ts { function createSourceFile(fileName: string, languageVersion: ScriptTarget, scriptKind: ScriptKind, isDeclarationFile: boolean, statements: readonly Statement[], endOfFileToken: EndOfFileToken, flags: NodeFlags): SourceFile { // code from createNode is inlined here so createNode won't have to deal with special case of creating source files // this is quite rare comparing to other nodes and createNode should be as fast as possible - const sourceFile = factory.createSourceFile(statements, endOfFileToken, flags); + let sourceFile = factory.createSourceFile(statements, endOfFileToken, flags); setTextRangePosWidth(sourceFile, 0, sourceText.length); + setExternalModuleIndicator(sourceFile); + + // If we parsed this as an external module, it may contain top-level await + if (!isDeclarationFile && isExternalModule(sourceFile) && sourceFile.transformFlags & TransformFlags.ContainsPossibleTopLevelAwait) { + sourceFile = reparseTopLevelAwait(sourceFile); + } + sourceFile.text = sourceText; sourceFile.bindDiagnostics = []; sourceFile.bindSuggestionDiagnostics = undefined; @@ -1265,7 +1430,7 @@ namespace ts { return currentToken = scanner.scanJsxAttributeValue(); } - function speculationHelper(callback: () => T, isLookAhead: boolean): T { + function speculationHelper(callback: () => T, speculationKind: SpeculationKind): T { // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). const saveToken = currentToken; @@ -1281,7 +1446,7 @@ namespace ts { // If we're only looking ahead, then tell the scanner to only lookahead as well. // Otherwise, if we're actually speculatively parsing, then tell the scanner to do the // same. - const result = isLookAhead + const result = speculationKind !== SpeculationKind.TryParse ? scanner.lookAhead(callback) : scanner.tryScan(callback); @@ -1289,9 +1454,11 @@ namespace ts { // If our callback returned something 'falsy' or we're just looking ahead, // then unconditionally restore us to where we were. - if (!result || isLookAhead) { + if (!result || speculationKind !== SpeculationKind.TryParse) { currentToken = saveToken; - parseDiagnostics.length = saveParseDiagnosticsLength; + if (speculationKind !== SpeculationKind.Reparse) { + parseDiagnostics.length = saveParseDiagnosticsLength; + } parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; } @@ -1303,7 +1470,7 @@ namespace ts { * is returned from this function. */ function lookAhead(callback: () => T): T { - return speculationHelper(callback, /*isLookAhead*/ true); + return speculationHelper(callback, SpeculationKind.Lookahead); } /** Invokes the provided callback. If the callback returns something falsy, then it restores @@ -1312,7 +1479,7 @@ namespace ts { * of invoking the callback is returned from this function. */ function tryParse(callback: () => T): T { - return speculationHelper(callback, /*isLookAhead*/ false); + return speculationHelper(callback, SpeculationKind.TryParse); } // Ignore strict mode flag because we will report an error in type checker instead. @@ -3784,7 +3951,6 @@ namespace ts { function parseSimpleArrowFunctionExpression(pos: number, identifier: Identifier, asyncModifier?: NodeArray | undefined): ArrowFunction { Debug.assert(token() === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - const parameter = factory.createParameterDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, @@ -3800,7 +3966,6 @@ namespace ts { const equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken); const body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier); const node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body); - return addJSDocComment(finishNode(node, pos)); } @@ -4056,7 +4221,7 @@ namespace ts { const hasJSDocFunctionType = type && isJSDocFunctionType(type); if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && (hasJSDocFunctionType || token() !== SyntaxKind.OpenBraceToken)) { // Returning undefined here will cause our caller to rewind to where we started from. - return undefined; + return undefined; } // If we have an arrow, then try to parse the body. Even if not, try to parse if we @@ -5492,12 +5657,15 @@ namespace ts { // Because of automatic semicolon insertion, we need to report error if this // throw could be terminated with a semicolon. Note: we can't call 'parseExpression' // directly as that might consume an expression on the following line. - // We just return 'undefined' in that case. The actual error will be reported in the - // grammar walker. - // TODO(rbuckton): Should we use `createMissingNode` here instead? - const expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); + // Instead, we create a "missing" identifier, but don't report an error. The actual error + // will be reported in the grammar walker. + let expression = scanner.hasPrecedingLineBreak() ? undefined : allowInAnd(parseExpression); + if (expression === undefined) { + identifierCount++; + expression = finishNode(factory.createIdentifier(""), getNodePos()); + } parseSemicolon(); - return finishNode(factory.createThrowStatement(expression!), pos); + return finishNode(factory.createThrowStatement(expression), pos); } // TODO: Review for error recovery @@ -6060,16 +6228,20 @@ namespace ts { } function parseFunctionDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): FunctionDeclaration { + const savedAwaitContext = inAwaitContext(); const modifierFlags = modifiersToFlags(modifiers); parseExpected(SyntaxKind.FunctionKeyword); const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); + // We don't parse the name here in await context, instead we will report a grammar error in the checker. const name = modifierFlags & ModifierFlags.Default ? parseOptionalIdentifier() : parseIdentifier(); const isGenerator = asteriskToken ? SignatureFlags.Yield : SignatureFlags.None; const isAsync = modifierFlags & ModifierFlags.Async ? SignatureFlags.Await : SignatureFlags.None; const typeParameters = parseTypeParameters(); + if (modifierFlags & ModifierFlags.Export) setAwaitContext(/*value*/ true); const parameters = parseParameters(isGenerator | isAsync); const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false); const body = parseFunctionBlockOrSemicolon(isGenerator | isAsync, Diagnostics.or_expected); + setAwaitContext(savedAwaitContext); const node = factory.createFunctionDeclaration(decorators, modifiers, asteriskToken, name, typeParameters, parameters, type, body); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -6385,9 +6557,12 @@ namespace ts { } function parseClassDeclarationOrExpression(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined, kind: ClassLikeDeclaration["kind"]): ClassLikeDeclaration { + const savedAwaitContext = inAwaitContext(); parseExpected(SyntaxKind.ClassKeyword); + // We don't parse the name here in await context, instead we will report a grammar error in the checker. const name = parseNameOfClassDeclarationOrExpression(); const typeParameters = parseTypeParameters(); + if (some(modifiers, isExportModifier)) setAwaitContext(/*value*/ true); const heritageClauses = parseHeritageClauses(); let members; @@ -6400,7 +6575,7 @@ namespace ts { else { members = createMissingList(); } - + setAwaitContext(savedAwaitContext); const node = kind === SyntaxKind.ClassDeclaration ? factory.createClassDeclaration(decorators, modifiers, name, typeParameters, heritageClauses, members) : factory.createClassExpression(decorators, modifiers, name, typeParameters, heritageClauses, members); @@ -6603,8 +6778,10 @@ namespace ts { function parseImportDeclarationOrImportEqualsDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): ImportEqualsDeclaration | ImportDeclaration { parseExpected(SyntaxKind.ImportKeyword); + const afterImportPos = scanner.getStartPos(); + // We don't parse the identifier here in await context, instead we will report a grammar error in the checker. let identifier: Identifier | undefined; if (isIdentifier()) { identifier = parseIdentifier(); @@ -6787,6 +6964,8 @@ namespace ts { } function parseExportDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): ExportDeclaration { + const savedAwaitContext = inAwaitContext(); + setAwaitContext(/*value*/ true); let exportClause: NamedExportBindings | undefined; let moduleSpecifier: Expression | undefined; const isTypeOnly = parseOptional(SyntaxKind.TypeKeyword); @@ -6809,11 +6988,14 @@ namespace ts { } } parseSemicolon(); + setAwaitContext(savedAwaitContext); const node = factory.createExportDeclaration(decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier); return withJSDoc(finishNode(node, pos), hasJSDoc); } function parseExportAssignment(pos: number, hasJSDoc: boolean, decorators: NodeArray | undefined, modifiers: NodeArray | undefined): ExportAssignment { + const savedAwaitContext = inAwaitContext(); + setAwaitContext(/*value*/ true); let isExportEquals: boolean | undefined; if (parseOptional(SyntaxKind.EqualsToken)) { isExportEquals = true; @@ -6823,6 +7005,7 @@ namespace ts { } const expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); + setAwaitContext(savedAwaitContext); const node = factory.createExportAssignment(decorators, modifiers, isExportEquals, expression); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -7851,6 +8034,7 @@ namespace ts { const incrementalSourceFile = sourceFile; Debug.assert(!incrementalSourceFile.hasBeenIncrementallyParsed); incrementalSourceFile.hasBeenIncrementallyParsed = true; + Parser.fixupParentReferences(incrementalSourceFile); const oldText = sourceFile.text; const syntaxCursor = createSyntaxCursor(sourceFile); @@ -8089,8 +8273,8 @@ namespace ts { Debug.assert(pos <= end); if (element.parent) { - Debug.assert(pos >= element.parent.pos); - Debug.assert(end <= element.parent.end); + Debug.assertGreaterThanOrEqual(pos, element.parent.pos); + Debug.assertLessThanOrEqual(end, element.parent.end); } setTextRangePosEnd(element, pos, end); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5c4e6f0c1592b..c8333cc48b11b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2722,7 +2722,7 @@ namespace ts { export interface ThrowStatement extends Statement { readonly kind: SyntaxKind.ThrowStatement; - readonly expression?: Expression; + readonly expression: Expression; } export interface TryStatement extends Statement { @@ -6242,6 +6242,7 @@ namespace ts { ContainsHoistedDeclarationOrCompletion = 1 << 20, ContainsDynamicImport = 1 << 21, ContainsClassFields = 1 << 22, + ContainsPossibleTopLevelAwait = 1 << 23, // Please leave this as 1 << 29. // It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system. @@ -6268,13 +6269,13 @@ namespace ts { OuterExpressionExcludes = HasComputedFlags, PropertyAccessExcludes = OuterExpressionExcludes, NodeExcludes = PropertyAccessExcludes, - ArrowFunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread, - FunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread, - ConstructorExcludes = NodeExcludes | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread, + ArrowFunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread | ContainsPossibleTopLevelAwait, + FunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread | ContainsPossibleTopLevelAwait, + ConstructorExcludes = NodeExcludes | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread | ContainsPossibleTopLevelAwait, MethodOrAccessorExcludes = NodeExcludes | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread, PropertyExcludes = NodeExcludes | ContainsLexicalThis, ClassExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsComputedPropertyName, - ModuleExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsHoistedDeclarationOrCompletion, + ModuleExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsLexicalThis | ContainsBlockScopedBinding | ContainsHoistedDeclarationOrCompletion | ContainsPossibleTopLevelAwait, TypeExcludes = ~ContainsTypeScript, ObjectLiteralExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsComputedPropertyName | ContainsObjectRestOrSpread, ArrayLiteralOrCallOrNewExcludes = NodeExcludes | ContainsRestOrSpread, diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 86651c8e433d0..b975b1d0e2bde 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -838,7 +838,7 @@ namespace ts { case SyntaxKind.ThrowStatement: return factory.updateThrowStatement(node, - nodeVisitor((node).expression!, visitor, isExpression)); // expression could be `undefined` due to invalid parse. + nodeVisitor((node).expression, visitor, isExpression)); case SyntaxKind.TryStatement: return factory.updateTryStatement(node, diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 012164ed997b3..b01e0bf25a34d 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1445,7 +1445,7 @@ declare namespace ts { } export interface ThrowStatement extends Statement { readonly kind: SyntaxKind.ThrowStatement; - readonly expression?: Expression; + readonly expression: Expression; } export interface TryStatement extends Statement { readonly kind: SyntaxKind.TryStatement; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 0b62806635ec9..dc46b92528385 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1445,7 +1445,7 @@ declare namespace ts { } export interface ThrowStatement extends Statement { readonly kind: SyntaxKind.ThrowStatement; - readonly expression?: Expression; + readonly expression: Expression; } export interface TryStatement extends Statement { readonly kind: SyntaxKind.TryStatement; diff --git a/tests/baselines/reference/exportDefaultAsyncFunction2.errors.txt b/tests/baselines/reference/exportDefaultAsyncFunction2.errors.txt new file mode 100644 index 0000000000000..de5d23f150b7d --- /dev/null +++ b/tests/baselines/reference/exportDefaultAsyncFunction2.errors.txt @@ -0,0 +1,43 @@ +tests/cases/compiler/a.ts(1,17): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. +tests/cases/compiler/asyncawait.ts(2,17): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. +tests/cases/compiler/c.ts(1,17): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. +tests/cases/compiler/d.ts(1,17): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. +tests/cases/compiler/e.ts(1,17): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/compiler/asyncawait.ts (1 errors) ==== + export function async(...args: any[]): any { } + export function await(...args: any[]): any { } + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + +==== tests/cases/compiler/a.ts (1 errors) ==== + import { async, await } from 'asyncawait'; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + export default async(() => await(Promise.resolve(1))); + +==== tests/cases/compiler/b.ts (0 errors) ==== + export default async () => { return 0; }; + +==== tests/cases/compiler/c.ts (1 errors) ==== + import { async, await } from 'asyncawait'; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + export default async(); + +==== tests/cases/compiler/d.ts (1 errors) ==== + import { async, await } from 'asyncawait'; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + export default async; + +==== tests/cases/compiler/e.ts (1 errors) ==== + import { async, await } from 'asyncawait'; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + export default async + + export function foo() { } \ No newline at end of file diff --git a/tests/baselines/reference/throwWithoutNewLine2.js b/tests/baselines/reference/throwWithoutNewLine2.js index db2227671d390..868e4e3d844ca 100644 --- a/tests/baselines/reference/throwWithoutNewLine2.js +++ b/tests/baselines/reference/throwWithoutNewLine2.js @@ -3,5 +3,5 @@ throw a; //// [throwWithoutNewLine2.js] -throw; +throw ; a; diff --git a/tests/baselines/reference/throwWithoutNewLine2.types b/tests/baselines/reference/throwWithoutNewLine2.types index 6aba0521b7bfd..3995e5284609a 100644 --- a/tests/baselines/reference/throwWithoutNewLine2.types +++ b/tests/baselines/reference/throwWithoutNewLine2.types @@ -1,5 +1,6 @@ === tests/cases/compiler/throwWithoutNewLine2.ts === throw a; +> : any >a : any diff --git a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).errors.txt b/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).errors.txt deleted file mode 100644 index 058acd93f42ab..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/externalModules/topLevelAwait.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. - - -==== tests/cases/conformance/externalModules/topLevelAwait.ts (1 errors) ==== - export const x = 1; - await x; - ~~~~~ -!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. - \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).js b/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).js deleted file mode 100644 index 6a2b5fe680c2b..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).js +++ /dev/null @@ -1,8 +0,0 @@ -//// [topLevelAwait.ts] -export const x = 1; -await x; - - -//// [topLevelAwait.js] -export const x = 1; -await x; diff --git a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).symbols b/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).symbols deleted file mode 100644 index 7eccf23a23169..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).symbols +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/conformance/externalModules/topLevelAwait.ts === -export const x = 1; ->x : Symbol(x, Decl(topLevelAwait.ts, 0, 12)) - -await x; ->x : Symbol(x, Decl(topLevelAwait.ts, 0, 12)) - diff --git a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).types b/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).types deleted file mode 100644 index 5f579192ee586..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2015).types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/conformance/externalModules/topLevelAwait.ts === -export const x = 1; ->x : 1 ->1 : 1 - -await x; ->await x : 1 ->x : 1 - diff --git a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).js b/tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).js deleted file mode 100644 index 6a2b5fe680c2b..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).js +++ /dev/null @@ -1,8 +0,0 @@ -//// [topLevelAwait.ts] -export const x = 1; -await x; - - -//// [topLevelAwait.js] -export const x = 1; -await x; diff --git a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).symbols b/tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).symbols deleted file mode 100644 index 7eccf23a23169..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).symbols +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/conformance/externalModules/topLevelAwait.ts === -export const x = 1; ->x : Symbol(x, Decl(topLevelAwait.ts, 0, 12)) - -await x; ->x : Symbol(x, Decl(topLevelAwait.ts, 0, 12)) - diff --git a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).types b/tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).types deleted file mode 100644 index 5f579192ee586..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=esnext,target=es2017).types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/conformance/externalModules/topLevelAwait.ts === -export const x = 1; ->x : 1 ->1 : 1 - -await x; ->await x : 1 ->x : 1 - diff --git a/tests/baselines/reference/topLevelAwait(module=system,target=es2015).errors.txt b/tests/baselines/reference/topLevelAwait(module=system,target=es2015).errors.txt deleted file mode 100644 index 058acd93f42ab..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=system,target=es2015).errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/externalModules/topLevelAwait.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. - - -==== tests/cases/conformance/externalModules/topLevelAwait.ts (1 errors) ==== - export const x = 1; - await x; - ~~~~~ -!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. - \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwait(module=system,target=es2015).js b/tests/baselines/reference/topLevelAwait(module=system,target=es2015).js deleted file mode 100644 index c6d4e03efbd39..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=system,target=es2015).js +++ /dev/null @@ -1,18 +0,0 @@ -//// [topLevelAwait.ts] -export const x = 1; -await x; - - -//// [topLevelAwait.js] -System.register([], function (exports_1, context_1) { - "use strict"; - var x; - var __moduleName = context_1 && context_1.id; - return { - setters: [], - execute: async function () { - exports_1("x", x = 1); - await x; - } - }; -}); diff --git a/tests/baselines/reference/topLevelAwait(module=system,target=es2015).symbols b/tests/baselines/reference/topLevelAwait(module=system,target=es2015).symbols deleted file mode 100644 index 7eccf23a23169..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=system,target=es2015).symbols +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/conformance/externalModules/topLevelAwait.ts === -export const x = 1; ->x : Symbol(x, Decl(topLevelAwait.ts, 0, 12)) - -await x; ->x : Symbol(x, Decl(topLevelAwait.ts, 0, 12)) - diff --git a/tests/baselines/reference/topLevelAwait(module=system,target=es2015).types b/tests/baselines/reference/topLevelAwait(module=system,target=es2015).types deleted file mode 100644 index 5f579192ee586..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=system,target=es2015).types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/conformance/externalModules/topLevelAwait.ts === -export const x = 1; ->x : 1 ->1 : 1 - -await x; ->await x : 1 ->x : 1 - diff --git a/tests/baselines/reference/topLevelAwait(module=system,target=es2017).js b/tests/baselines/reference/topLevelAwait(module=system,target=es2017).js deleted file mode 100644 index c6d4e03efbd39..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=system,target=es2017).js +++ /dev/null @@ -1,18 +0,0 @@ -//// [topLevelAwait.ts] -export const x = 1; -await x; - - -//// [topLevelAwait.js] -System.register([], function (exports_1, context_1) { - "use strict"; - var x; - var __moduleName = context_1 && context_1.id; - return { - setters: [], - execute: async function () { - exports_1("x", x = 1); - await x; - } - }; -}); diff --git a/tests/baselines/reference/topLevelAwait(module=system,target=es2017).symbols b/tests/baselines/reference/topLevelAwait(module=system,target=es2017).symbols deleted file mode 100644 index 7eccf23a23169..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=system,target=es2017).symbols +++ /dev/null @@ -1,7 +0,0 @@ -=== tests/cases/conformance/externalModules/topLevelAwait.ts === -export const x = 1; ->x : Symbol(x, Decl(topLevelAwait.ts, 0, 12)) - -await x; ->x : Symbol(x, Decl(topLevelAwait.ts, 0, 12)) - diff --git a/tests/baselines/reference/topLevelAwait(module=system,target=es2017).types b/tests/baselines/reference/topLevelAwait(module=system,target=es2017).types deleted file mode 100644 index 5f579192ee586..0000000000000 --- a/tests/baselines/reference/topLevelAwait(module=system,target=es2017).types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/conformance/externalModules/topLevelAwait.ts === -export const x = 1; ->x : 1 ->1 : 1 - -await x; ->await x : 1 ->x : 1 - diff --git a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt new file mode 100644 index 0000000000000..b0eb67d7c7d48 --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt @@ -0,0 +1,66 @@ +tests/cases/conformance/externalModules/index.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/externalModules/index.ts(46,3): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. + + +==== tests/cases/conformance/externalModules/index.ts (2 errors) ==== + export const x = 1; + await x; + ~~~~~ +!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. + + // reparse element access as await + await [x]; + await [x, x]; + + // reparse call as await + declare function f(): number; + await (x); + await (f(), x); + await (x); + await (f(), x); + + // reparse tagged template as await + await ``; + await ``; + + // member names should be ok + class C1 { + await() {} + } + class C2 { + get await() { return 1; } + set await(value) { } + } + class C3 { + await = 1; + } + ({ + await() {} + }); + ({ + get await() { return 1 }, + set await(value) { } + }); + ({ + await: 1 + }); + + // property access name should be ok + C1.prototype.await; + + // await in decorators + declare const dec: any; + @(await dec) + ~~~~~ +!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. + class C { + } + + // await allowed in aliased import + import { await as _await } from "./other"; + +==== tests/cases/conformance/externalModules/other.ts (0 errors) ==== + const _await = 1; + + // await allowed in aliased export + export { _await as await }; \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).js b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).js new file mode 100644 index 0000000000000..55c20cc289c5d --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).js @@ -0,0 +1,108 @@ +//// [tests/cases/conformance/externalModules/topLevelAwait.1.ts] //// + +//// [index.ts] +export const x = 1; +await x; + +// reparse element access as await +await [x]; +await [x, x]; + +// reparse call as await +declare function f(): number; +await (x); +await (f(), x); +await (x); +await (f(), x); + +// reparse tagged template as await +await ``; +await ``; + +// member names should be ok +class C1 { + await() {} +} +class C2 { + get await() { return 1; } + set await(value) { } +} +class C3 { + await = 1; +} +({ + await() {} +}); +({ + get await() { return 1 }, + set await(value) { } +}); +({ + await: 1 +}); + +// property access name should be ok +C1.prototype.await; + +// await in decorators +declare const dec: any; +@(await dec) +class C { +} + +// await allowed in aliased import +import { await as _await } from "./other"; + +//// [other.ts] +const _await = 1; + +// await allowed in aliased export +export { _await as await }; + +//// [other.js] +const _await = 1; +// await allowed in aliased export +export { _await as await }; +//// [index.js] +export const x = 1; +await x; +// reparse element access as await +await [x]; +await [x, x]; +await (x); +await (f(), x); +await (x); +await (f(), x); +// reparse tagged template as await +await ``; +await ``; +// member names should be ok +class C1 { + await() { } +} +class C2 { + get await() { return 1; } + set await(value) { } +} +class C3 { + constructor() { + this.await = 1; + } +} +({ + await() { } +}); +({ + get await() { return 1; }, + set await(value) { } +}); +({ + await: 1 +}); +// property access name should be ok +C1.prototype.await; +let C = class C { +}; +C = __decorate([ + (await dec) +], C); diff --git a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).symbols b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).symbols new file mode 100644 index 0000000000000..992258ff5dfdf --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).symbols @@ -0,0 +1,113 @@ +=== tests/cases/conformance/externalModules/index.ts === +export const x = 1; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await x; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse element access as await +await [x]; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await [x, x]; +>x : Symbol(x, Decl(index.ts, 0, 12)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse call as await +declare function f(): number; +>f : Symbol(f, Decl(index.ts, 5, 13)) + +await (x); +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (f(), x); +>f : Symbol(f, Decl(index.ts, 5, 13)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (x); +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (f(), x); +>f : Symbol(f, Decl(index.ts, 5, 13)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse tagged template as await +await ``; +await ``; + +// member names should be ok +class C1 { +>C1 : Symbol(C1, Decl(index.ts, 16, 18)) + + await() {} +>await : Symbol(C1.await, Decl(index.ts, 19, 10)) +} +class C2 { +>C2 : Symbol(C2, Decl(index.ts, 21, 1)) + + get await() { return 1; } +>await : Symbol(C2.await, Decl(index.ts, 22, 10), Decl(index.ts, 23, 29)) + + set await(value) { } +>await : Symbol(C2.await, Decl(index.ts, 22, 10), Decl(index.ts, 23, 29)) +>value : Symbol(value, Decl(index.ts, 24, 14)) +} +class C3 { +>C3 : Symbol(C3, Decl(index.ts, 25, 1)) + + await = 1; +>await : Symbol(C3.await, Decl(index.ts, 26, 10)) +} +({ + await() {} +>await : Symbol(await, Decl(index.ts, 29, 2)) + +}); +({ + get await() { return 1 }, +>await : Symbol(await, Decl(index.ts, 32, 2), Decl(index.ts, 33, 29)) + + set await(value) { } +>await : Symbol(await, Decl(index.ts, 32, 2), Decl(index.ts, 33, 29)) +>value : Symbol(value, Decl(index.ts, 34, 14)) + +}); +({ + await: 1 +>await : Symbol(await, Decl(index.ts, 36, 2)) + +}); + +// property access name should be ok +C1.prototype.await; +>C1.prototype.await : Symbol(C1.await, Decl(index.ts, 19, 10)) +>C1.prototype : Symbol(C1.prototype) +>C1 : Symbol(C1, Decl(index.ts, 16, 18)) +>prototype : Symbol(C1.prototype) +>await : Symbol(C1.await, Decl(index.ts, 19, 10)) + +// await in decorators +declare const dec: any; +>dec : Symbol(dec, Decl(index.ts, 44, 13)) + +@(await dec) +>dec : Symbol(dec, Decl(index.ts, 44, 13)) + +class C { +>C : Symbol(C, Decl(index.ts, 44, 23)) +} + +// await allowed in aliased import +import { await as _await } from "./other"; +>await : Symbol(await, Decl(other.ts, 3, 8)) +>_await : Symbol(_await, Decl(index.ts, 50, 8)) + +=== tests/cases/conformance/externalModules/other.ts === +const _await = 1; +>_await : Symbol(_await, Decl(other.ts, 0, 5)) + +// await allowed in aliased export +export { _await as await }; +>_await : Symbol(_await, Decl(other.ts, 0, 5)) +>await : Symbol(await, Decl(other.ts, 3, 8)) + diff --git a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).types b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).types new file mode 100644 index 0000000000000..b2a82b1bea73a --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).types @@ -0,0 +1,155 @@ +=== tests/cases/conformance/externalModules/index.ts === +export const x = 1; +>x : 1 +>1 : 1 + +await x; +>await x : 1 +>x : 1 + +// reparse element access as await +await [x]; +>await [x] : number[] +>[x] : number[] +>x : 1 + +await [x, x]; +>await [x, x] : number[] +>[x, x] : number[] +>x : 1 +>x : 1 + +// reparse call as await +declare function f(): number; +>f : () => number + +await (x); +>await (x) : 1 +>(x) : 1 +>x : 1 + +await (f(), x); +>await (f(), x) : 1 +>(f(), x) : 1 +>f(), x : 1 +>f() : number +>f : () => number +>x : 1 + +await (x); +>await (x) : number +>(x) : number +>(x) : 1 +>x : 1 + +await (f(), x); +>await (f(), x) : number +>(f(), x) : number +>(f(), x) : 1 +>f(), x : 1 +>f() : number +>f : () => number +>x : 1 + +// reparse tagged template as await +await ``; +>await `` : "" +>`` : "" + +await ``; +>await `` : string +> `` : string +>`` : "" + +// member names should be ok +class C1 { +>C1 : C1 + + await() {} +>await : () => void +} +class C2 { +>C2 : C2 + + get await() { return 1; } +>await : number +>1 : 1 + + set await(value) { } +>await : number +>value : number +} +class C3 { +>C3 : C3 + + await = 1; +>await : number +>1 : 1 +} +({ +>({ await() {}}) : { await(): void; } +>{ await() {}} : { await(): void; } + + await() {} +>await : () => void + +}); +({ +>({ get await() { return 1 }, set await(value) { }}) : { await: number; } +>{ get await() { return 1 }, set await(value) { }} : { await: number; } + + get await() { return 1 }, +>await : number +>1 : 1 + + set await(value) { } +>await : number +>value : number + +}); +({ +>({ await: 1}) : { await: number; } +>{ await: 1} : { await: number; } + + await: 1 +>await : number +>1 : 1 + +}); + +// property access name should be ok +C1.prototype.await; +>C1.prototype.await : () => void +>C1.prototype : C1 +>C1 : typeof C1 +>prototype : C1 +>await : () => void + +// await in decorators +declare const dec: any; +>dec : any + +@(await dec) +>(await dec) : any +>await dec : any +>dec : any + +class C { +>C : C +} + +// await allowed in aliased import +import { await as _await } from "./other"; +>await : 1 +>_await : 1 + +=== tests/cases/conformance/externalModules/other.ts === +const _await = 1; +>_await : 1 +>1 : 1 + +// await allowed in aliased export +export { _await as await }; +>_await : 1 +>await : 1 + diff --git a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2017).js b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2017).js new file mode 100644 index 0000000000000..55c20cc289c5d --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2017).js @@ -0,0 +1,108 @@ +//// [tests/cases/conformance/externalModules/topLevelAwait.1.ts] //// + +//// [index.ts] +export const x = 1; +await x; + +// reparse element access as await +await [x]; +await [x, x]; + +// reparse call as await +declare function f(): number; +await (x); +await (f(), x); +await (x); +await (f(), x); + +// reparse tagged template as await +await ``; +await ``; + +// member names should be ok +class C1 { + await() {} +} +class C2 { + get await() { return 1; } + set await(value) { } +} +class C3 { + await = 1; +} +({ + await() {} +}); +({ + get await() { return 1 }, + set await(value) { } +}); +({ + await: 1 +}); + +// property access name should be ok +C1.prototype.await; + +// await in decorators +declare const dec: any; +@(await dec) +class C { +} + +// await allowed in aliased import +import { await as _await } from "./other"; + +//// [other.ts] +const _await = 1; + +// await allowed in aliased export +export { _await as await }; + +//// [other.js] +const _await = 1; +// await allowed in aliased export +export { _await as await }; +//// [index.js] +export const x = 1; +await x; +// reparse element access as await +await [x]; +await [x, x]; +await (x); +await (f(), x); +await (x); +await (f(), x); +// reparse tagged template as await +await ``; +await ``; +// member names should be ok +class C1 { + await() { } +} +class C2 { + get await() { return 1; } + set await(value) { } +} +class C3 { + constructor() { + this.await = 1; + } +} +({ + await() { } +}); +({ + get await() { return 1; }, + set await(value) { } +}); +({ + await: 1 +}); +// property access name should be ok +C1.prototype.await; +let C = class C { +}; +C = __decorate([ + (await dec) +], C); diff --git a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2017).symbols b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2017).symbols new file mode 100644 index 0000000000000..992258ff5dfdf --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2017).symbols @@ -0,0 +1,113 @@ +=== tests/cases/conformance/externalModules/index.ts === +export const x = 1; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await x; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse element access as await +await [x]; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await [x, x]; +>x : Symbol(x, Decl(index.ts, 0, 12)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse call as await +declare function f(): number; +>f : Symbol(f, Decl(index.ts, 5, 13)) + +await (x); +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (f(), x); +>f : Symbol(f, Decl(index.ts, 5, 13)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (x); +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (f(), x); +>f : Symbol(f, Decl(index.ts, 5, 13)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse tagged template as await +await ``; +await ``; + +// member names should be ok +class C1 { +>C1 : Symbol(C1, Decl(index.ts, 16, 18)) + + await() {} +>await : Symbol(C1.await, Decl(index.ts, 19, 10)) +} +class C2 { +>C2 : Symbol(C2, Decl(index.ts, 21, 1)) + + get await() { return 1; } +>await : Symbol(C2.await, Decl(index.ts, 22, 10), Decl(index.ts, 23, 29)) + + set await(value) { } +>await : Symbol(C2.await, Decl(index.ts, 22, 10), Decl(index.ts, 23, 29)) +>value : Symbol(value, Decl(index.ts, 24, 14)) +} +class C3 { +>C3 : Symbol(C3, Decl(index.ts, 25, 1)) + + await = 1; +>await : Symbol(C3.await, Decl(index.ts, 26, 10)) +} +({ + await() {} +>await : Symbol(await, Decl(index.ts, 29, 2)) + +}); +({ + get await() { return 1 }, +>await : Symbol(await, Decl(index.ts, 32, 2), Decl(index.ts, 33, 29)) + + set await(value) { } +>await : Symbol(await, Decl(index.ts, 32, 2), Decl(index.ts, 33, 29)) +>value : Symbol(value, Decl(index.ts, 34, 14)) + +}); +({ + await: 1 +>await : Symbol(await, Decl(index.ts, 36, 2)) + +}); + +// property access name should be ok +C1.prototype.await; +>C1.prototype.await : Symbol(C1.await, Decl(index.ts, 19, 10)) +>C1.prototype : Symbol(C1.prototype) +>C1 : Symbol(C1, Decl(index.ts, 16, 18)) +>prototype : Symbol(C1.prototype) +>await : Symbol(C1.await, Decl(index.ts, 19, 10)) + +// await in decorators +declare const dec: any; +>dec : Symbol(dec, Decl(index.ts, 44, 13)) + +@(await dec) +>dec : Symbol(dec, Decl(index.ts, 44, 13)) + +class C { +>C : Symbol(C, Decl(index.ts, 44, 23)) +} + +// await allowed in aliased import +import { await as _await } from "./other"; +>await : Symbol(await, Decl(other.ts, 3, 8)) +>_await : Symbol(_await, Decl(index.ts, 50, 8)) + +=== tests/cases/conformance/externalModules/other.ts === +const _await = 1; +>_await : Symbol(_await, Decl(other.ts, 0, 5)) + +// await allowed in aliased export +export { _await as await }; +>_await : Symbol(_await, Decl(other.ts, 0, 5)) +>await : Symbol(await, Decl(other.ts, 3, 8)) + diff --git a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2017).types b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2017).types new file mode 100644 index 0000000000000..b2a82b1bea73a --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2017).types @@ -0,0 +1,155 @@ +=== tests/cases/conformance/externalModules/index.ts === +export const x = 1; +>x : 1 +>1 : 1 + +await x; +>await x : 1 +>x : 1 + +// reparse element access as await +await [x]; +>await [x] : number[] +>[x] : number[] +>x : 1 + +await [x, x]; +>await [x, x] : number[] +>[x, x] : number[] +>x : 1 +>x : 1 + +// reparse call as await +declare function f(): number; +>f : () => number + +await (x); +>await (x) : 1 +>(x) : 1 +>x : 1 + +await (f(), x); +>await (f(), x) : 1 +>(f(), x) : 1 +>f(), x : 1 +>f() : number +>f : () => number +>x : 1 + +await (x); +>await (x) : number +>(x) : number +>(x) : 1 +>x : 1 + +await (f(), x); +>await (f(), x) : number +>(f(), x) : number +>(f(), x) : 1 +>f(), x : 1 +>f() : number +>f : () => number +>x : 1 + +// reparse tagged template as await +await ``; +>await `` : "" +>`` : "" + +await ``; +>await `` : string +> `` : string +>`` : "" + +// member names should be ok +class C1 { +>C1 : C1 + + await() {} +>await : () => void +} +class C2 { +>C2 : C2 + + get await() { return 1; } +>await : number +>1 : 1 + + set await(value) { } +>await : number +>value : number +} +class C3 { +>C3 : C3 + + await = 1; +>await : number +>1 : 1 +} +({ +>({ await() {}}) : { await(): void; } +>{ await() {}} : { await(): void; } + + await() {} +>await : () => void + +}); +({ +>({ get await() { return 1 }, set await(value) { }}) : { await: number; } +>{ get await() { return 1 }, set await(value) { }} : { await: number; } + + get await() { return 1 }, +>await : number +>1 : 1 + + set await(value) { } +>await : number +>value : number + +}); +({ +>({ await: 1}) : { await: number; } +>{ await: 1} : { await: number; } + + await: 1 +>await : number +>1 : 1 + +}); + +// property access name should be ok +C1.prototype.await; +>C1.prototype.await : () => void +>C1.prototype : C1 +>C1 : typeof C1 +>prototype : C1 +>await : () => void + +// await in decorators +declare const dec: any; +>dec : any + +@(await dec) +>(await dec) : any +>await dec : any +>dec : any + +class C { +>C : C +} + +// await allowed in aliased import +import { await as _await } from "./other"; +>await : 1 +>_await : 1 + +=== tests/cases/conformance/externalModules/other.ts === +const _await = 1; +>_await : 1 +>1 : 1 + +// await allowed in aliased export +export { _await as await }; +>_await : 1 +>await : 1 + diff --git a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt new file mode 100644 index 0000000000000..b0eb67d7c7d48 --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt @@ -0,0 +1,66 @@ +tests/cases/conformance/externalModules/index.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/externalModules/index.ts(46,3): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. + + +==== tests/cases/conformance/externalModules/index.ts (2 errors) ==== + export const x = 1; + await x; + ~~~~~ +!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. + + // reparse element access as await + await [x]; + await [x, x]; + + // reparse call as await + declare function f(): number; + await (x); + await (f(), x); + await (x); + await (f(), x); + + // reparse tagged template as await + await ``; + await ``; + + // member names should be ok + class C1 { + await() {} + } + class C2 { + get await() { return 1; } + set await(value) { } + } + class C3 { + await = 1; + } + ({ + await() {} + }); + ({ + get await() { return 1 }, + set await(value) { } + }); + ({ + await: 1 + }); + + // property access name should be ok + C1.prototype.await; + + // await in decorators + declare const dec: any; + @(await dec) + ~~~~~ +!!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. + class C { + } + + // await allowed in aliased import + import { await as _await } from "./other"; + +==== tests/cases/conformance/externalModules/other.ts (0 errors) ==== + const _await = 1; + + // await allowed in aliased export + export { _await as await }; \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).js b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).js new file mode 100644 index 0000000000000..172e302f2418e --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).js @@ -0,0 +1,127 @@ +//// [tests/cases/conformance/externalModules/topLevelAwait.1.ts] //// + +//// [index.ts] +export const x = 1; +await x; + +// reparse element access as await +await [x]; +await [x, x]; + +// reparse call as await +declare function f(): number; +await (x); +await (f(), x); +await (x); +await (f(), x); + +// reparse tagged template as await +await ``; +await ``; + +// member names should be ok +class C1 { + await() {} +} +class C2 { + get await() { return 1; } + set await(value) { } +} +class C3 { + await = 1; +} +({ + await() {} +}); +({ + get await() { return 1 }, + set await(value) { } +}); +({ + await: 1 +}); + +// property access name should be ok +C1.prototype.await; + +// await in decorators +declare const dec: any; +@(await dec) +class C { +} + +// await allowed in aliased import +import { await as _await } from "./other"; + +//// [other.ts] +const _await = 1; + +// await allowed in aliased export +export { _await as await }; + +//// [other.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var _await; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + _await = 1; + exports_1("await", _await); + } + }; +}); +//// [index.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var x, C1, C2, C3, C; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: async function () { + exports_1("x", x = 1); + await x; + // reparse element access as await + await [x]; + await [x, x]; + await (x); + await (f(), x); + await (x); + await (f(), x); + // reparse tagged template as await + await ``; + await ``; + // member names should be ok + C1 = class C1 { + await() { } + }; + C2 = class C2 { + get await() { return 1; } + set await(value) { } + }; + C3 = class C3 { + constructor() { + this.await = 1; + } + }; + ({ + await() { } + }); + ({ + get await() { return 1; }, + set await(value) { } + }); + ({ + await: 1 + }); + // property access name should be ok + C1.prototype.await; + C = class C { + }; + C = __decorate([ + (await dec) + ], C); + } + }; +}); diff --git a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).symbols b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).symbols new file mode 100644 index 0000000000000..992258ff5dfdf --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).symbols @@ -0,0 +1,113 @@ +=== tests/cases/conformance/externalModules/index.ts === +export const x = 1; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await x; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse element access as await +await [x]; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await [x, x]; +>x : Symbol(x, Decl(index.ts, 0, 12)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse call as await +declare function f(): number; +>f : Symbol(f, Decl(index.ts, 5, 13)) + +await (x); +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (f(), x); +>f : Symbol(f, Decl(index.ts, 5, 13)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (x); +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (f(), x); +>f : Symbol(f, Decl(index.ts, 5, 13)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse tagged template as await +await ``; +await ``; + +// member names should be ok +class C1 { +>C1 : Symbol(C1, Decl(index.ts, 16, 18)) + + await() {} +>await : Symbol(C1.await, Decl(index.ts, 19, 10)) +} +class C2 { +>C2 : Symbol(C2, Decl(index.ts, 21, 1)) + + get await() { return 1; } +>await : Symbol(C2.await, Decl(index.ts, 22, 10), Decl(index.ts, 23, 29)) + + set await(value) { } +>await : Symbol(C2.await, Decl(index.ts, 22, 10), Decl(index.ts, 23, 29)) +>value : Symbol(value, Decl(index.ts, 24, 14)) +} +class C3 { +>C3 : Symbol(C3, Decl(index.ts, 25, 1)) + + await = 1; +>await : Symbol(C3.await, Decl(index.ts, 26, 10)) +} +({ + await() {} +>await : Symbol(await, Decl(index.ts, 29, 2)) + +}); +({ + get await() { return 1 }, +>await : Symbol(await, Decl(index.ts, 32, 2), Decl(index.ts, 33, 29)) + + set await(value) { } +>await : Symbol(await, Decl(index.ts, 32, 2), Decl(index.ts, 33, 29)) +>value : Symbol(value, Decl(index.ts, 34, 14)) + +}); +({ + await: 1 +>await : Symbol(await, Decl(index.ts, 36, 2)) + +}); + +// property access name should be ok +C1.prototype.await; +>C1.prototype.await : Symbol(C1.await, Decl(index.ts, 19, 10)) +>C1.prototype : Symbol(C1.prototype) +>C1 : Symbol(C1, Decl(index.ts, 16, 18)) +>prototype : Symbol(C1.prototype) +>await : Symbol(C1.await, Decl(index.ts, 19, 10)) + +// await in decorators +declare const dec: any; +>dec : Symbol(dec, Decl(index.ts, 44, 13)) + +@(await dec) +>dec : Symbol(dec, Decl(index.ts, 44, 13)) + +class C { +>C : Symbol(C, Decl(index.ts, 44, 23)) +} + +// await allowed in aliased import +import { await as _await } from "./other"; +>await : Symbol(await, Decl(other.ts, 3, 8)) +>_await : Symbol(_await, Decl(index.ts, 50, 8)) + +=== tests/cases/conformance/externalModules/other.ts === +const _await = 1; +>_await : Symbol(_await, Decl(other.ts, 0, 5)) + +// await allowed in aliased export +export { _await as await }; +>_await : Symbol(_await, Decl(other.ts, 0, 5)) +>await : Symbol(await, Decl(other.ts, 3, 8)) + diff --git a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).types b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).types new file mode 100644 index 0000000000000..b2a82b1bea73a --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).types @@ -0,0 +1,155 @@ +=== tests/cases/conformance/externalModules/index.ts === +export const x = 1; +>x : 1 +>1 : 1 + +await x; +>await x : 1 +>x : 1 + +// reparse element access as await +await [x]; +>await [x] : number[] +>[x] : number[] +>x : 1 + +await [x, x]; +>await [x, x] : number[] +>[x, x] : number[] +>x : 1 +>x : 1 + +// reparse call as await +declare function f(): number; +>f : () => number + +await (x); +>await (x) : 1 +>(x) : 1 +>x : 1 + +await (f(), x); +>await (f(), x) : 1 +>(f(), x) : 1 +>f(), x : 1 +>f() : number +>f : () => number +>x : 1 + +await (x); +>await (x) : number +>(x) : number +>(x) : 1 +>x : 1 + +await (f(), x); +>await (f(), x) : number +>(f(), x) : number +>(f(), x) : 1 +>f(), x : 1 +>f() : number +>f : () => number +>x : 1 + +// reparse tagged template as await +await ``; +>await `` : "" +>`` : "" + +await ``; +>await `` : string +> `` : string +>`` : "" + +// member names should be ok +class C1 { +>C1 : C1 + + await() {} +>await : () => void +} +class C2 { +>C2 : C2 + + get await() { return 1; } +>await : number +>1 : 1 + + set await(value) { } +>await : number +>value : number +} +class C3 { +>C3 : C3 + + await = 1; +>await : number +>1 : 1 +} +({ +>({ await() {}}) : { await(): void; } +>{ await() {}} : { await(): void; } + + await() {} +>await : () => void + +}); +({ +>({ get await() { return 1 }, set await(value) { }}) : { await: number; } +>{ get await() { return 1 }, set await(value) { }} : { await: number; } + + get await() { return 1 }, +>await : number +>1 : 1 + + set await(value) { } +>await : number +>value : number + +}); +({ +>({ await: 1}) : { await: number; } +>{ await: 1} : { await: number; } + + await: 1 +>await : number +>1 : 1 + +}); + +// property access name should be ok +C1.prototype.await; +>C1.prototype.await : () => void +>C1.prototype : C1 +>C1 : typeof C1 +>prototype : C1 +>await : () => void + +// await in decorators +declare const dec: any; +>dec : any + +@(await dec) +>(await dec) : any +>await dec : any +>dec : any + +class C { +>C : C +} + +// await allowed in aliased import +import { await as _await } from "./other"; +>await : 1 +>_await : 1 + +=== tests/cases/conformance/externalModules/other.ts === +const _await = 1; +>_await : 1 +>1 : 1 + +// await allowed in aliased export +export { _await as await }; +>_await : 1 +>await : 1 + diff --git a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2017).js b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2017).js new file mode 100644 index 0000000000000..172e302f2418e --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2017).js @@ -0,0 +1,127 @@ +//// [tests/cases/conformance/externalModules/topLevelAwait.1.ts] //// + +//// [index.ts] +export const x = 1; +await x; + +// reparse element access as await +await [x]; +await [x, x]; + +// reparse call as await +declare function f(): number; +await (x); +await (f(), x); +await (x); +await (f(), x); + +// reparse tagged template as await +await ``; +await ``; + +// member names should be ok +class C1 { + await() {} +} +class C2 { + get await() { return 1; } + set await(value) { } +} +class C3 { + await = 1; +} +({ + await() {} +}); +({ + get await() { return 1 }, + set await(value) { } +}); +({ + await: 1 +}); + +// property access name should be ok +C1.prototype.await; + +// await in decorators +declare const dec: any; +@(await dec) +class C { +} + +// await allowed in aliased import +import { await as _await } from "./other"; + +//// [other.ts] +const _await = 1; + +// await allowed in aliased export +export { _await as await }; + +//// [other.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var _await; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + _await = 1; + exports_1("await", _await); + } + }; +}); +//// [index.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var x, C1, C2, C3, C; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: async function () { + exports_1("x", x = 1); + await x; + // reparse element access as await + await [x]; + await [x, x]; + await (x); + await (f(), x); + await (x); + await (f(), x); + // reparse tagged template as await + await ``; + await ``; + // member names should be ok + C1 = class C1 { + await() { } + }; + C2 = class C2 { + get await() { return 1; } + set await(value) { } + }; + C3 = class C3 { + constructor() { + this.await = 1; + } + }; + ({ + await() { } + }); + ({ + get await() { return 1; }, + set await(value) { } + }); + ({ + await: 1 + }); + // property access name should be ok + C1.prototype.await; + C = class C { + }; + C = __decorate([ + (await dec) + ], C); + } + }; +}); diff --git a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2017).symbols b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2017).symbols new file mode 100644 index 0000000000000..992258ff5dfdf --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2017).symbols @@ -0,0 +1,113 @@ +=== tests/cases/conformance/externalModules/index.ts === +export const x = 1; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await x; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse element access as await +await [x]; +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await [x, x]; +>x : Symbol(x, Decl(index.ts, 0, 12)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse call as await +declare function f(): number; +>f : Symbol(f, Decl(index.ts, 5, 13)) + +await (x); +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (f(), x); +>f : Symbol(f, Decl(index.ts, 5, 13)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (x); +>x : Symbol(x, Decl(index.ts, 0, 12)) + +await (f(), x); +>f : Symbol(f, Decl(index.ts, 5, 13)) +>x : Symbol(x, Decl(index.ts, 0, 12)) + +// reparse tagged template as await +await ``; +await ``; + +// member names should be ok +class C1 { +>C1 : Symbol(C1, Decl(index.ts, 16, 18)) + + await() {} +>await : Symbol(C1.await, Decl(index.ts, 19, 10)) +} +class C2 { +>C2 : Symbol(C2, Decl(index.ts, 21, 1)) + + get await() { return 1; } +>await : Symbol(C2.await, Decl(index.ts, 22, 10), Decl(index.ts, 23, 29)) + + set await(value) { } +>await : Symbol(C2.await, Decl(index.ts, 22, 10), Decl(index.ts, 23, 29)) +>value : Symbol(value, Decl(index.ts, 24, 14)) +} +class C3 { +>C3 : Symbol(C3, Decl(index.ts, 25, 1)) + + await = 1; +>await : Symbol(C3.await, Decl(index.ts, 26, 10)) +} +({ + await() {} +>await : Symbol(await, Decl(index.ts, 29, 2)) + +}); +({ + get await() { return 1 }, +>await : Symbol(await, Decl(index.ts, 32, 2), Decl(index.ts, 33, 29)) + + set await(value) { } +>await : Symbol(await, Decl(index.ts, 32, 2), Decl(index.ts, 33, 29)) +>value : Symbol(value, Decl(index.ts, 34, 14)) + +}); +({ + await: 1 +>await : Symbol(await, Decl(index.ts, 36, 2)) + +}); + +// property access name should be ok +C1.prototype.await; +>C1.prototype.await : Symbol(C1.await, Decl(index.ts, 19, 10)) +>C1.prototype : Symbol(C1.prototype) +>C1 : Symbol(C1, Decl(index.ts, 16, 18)) +>prototype : Symbol(C1.prototype) +>await : Symbol(C1.await, Decl(index.ts, 19, 10)) + +// await in decorators +declare const dec: any; +>dec : Symbol(dec, Decl(index.ts, 44, 13)) + +@(await dec) +>dec : Symbol(dec, Decl(index.ts, 44, 13)) + +class C { +>C : Symbol(C, Decl(index.ts, 44, 23)) +} + +// await allowed in aliased import +import { await as _await } from "./other"; +>await : Symbol(await, Decl(other.ts, 3, 8)) +>_await : Symbol(_await, Decl(index.ts, 50, 8)) + +=== tests/cases/conformance/externalModules/other.ts === +const _await = 1; +>_await : Symbol(_await, Decl(other.ts, 0, 5)) + +// await allowed in aliased export +export { _await as await }; +>_await : Symbol(_await, Decl(other.ts, 0, 5)) +>await : Symbol(await, Decl(other.ts, 3, 8)) + diff --git a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2017).types b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2017).types new file mode 100644 index 0000000000000..b2a82b1bea73a --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2017).types @@ -0,0 +1,155 @@ +=== tests/cases/conformance/externalModules/index.ts === +export const x = 1; +>x : 1 +>1 : 1 + +await x; +>await x : 1 +>x : 1 + +// reparse element access as await +await [x]; +>await [x] : number[] +>[x] : number[] +>x : 1 + +await [x, x]; +>await [x, x] : number[] +>[x, x] : number[] +>x : 1 +>x : 1 + +// reparse call as await +declare function f(): number; +>f : () => number + +await (x); +>await (x) : 1 +>(x) : 1 +>x : 1 + +await (f(), x); +>await (f(), x) : 1 +>(f(), x) : 1 +>f(), x : 1 +>f() : number +>f : () => number +>x : 1 + +await (x); +>await (x) : number +>(x) : number +>(x) : 1 +>x : 1 + +await (f(), x); +>await (f(), x) : number +>(f(), x) : number +>(f(), x) : 1 +>f(), x : 1 +>f() : number +>f : () => number +>x : 1 + +// reparse tagged template as await +await ``; +>await `` : "" +>`` : "" + +await ``; +>await `` : string +> `` : string +>`` : "" + +// member names should be ok +class C1 { +>C1 : C1 + + await() {} +>await : () => void +} +class C2 { +>C2 : C2 + + get await() { return 1; } +>await : number +>1 : 1 + + set await(value) { } +>await : number +>value : number +} +class C3 { +>C3 : C3 + + await = 1; +>await : number +>1 : 1 +} +({ +>({ await() {}}) : { await(): void; } +>{ await() {}} : { await(): void; } + + await() {} +>await : () => void + +}); +({ +>({ get await() { return 1 }, set await(value) { }}) : { await: number; } +>{ get await() { return 1 }, set await(value) { }} : { await: number; } + + get await() { return 1 }, +>await : number +>1 : 1 + + set await(value) { } +>await : number +>value : number + +}); +({ +>({ await: 1}) : { await: number; } +>{ await: 1} : { await: number; } + + await: 1 +>await : number +>1 : 1 + +}); + +// property access name should be ok +C1.prototype.await; +>C1.prototype.await : () => void +>C1.prototype : C1 +>C1 : typeof C1 +>prototype : C1 +>await : () => void + +// await in decorators +declare const dec: any; +>dec : any + +@(await dec) +>(await dec) : any +>await dec : any +>dec : any + +class C { +>C : C +} + +// await allowed in aliased import +import { await as _await } from "./other"; +>await : 1 +>_await : 1 + +=== tests/cases/conformance/externalModules/other.ts === +const _await = 1; +>_await : 1 +>1 : 1 + +// await allowed in aliased export +export { _await as await }; +>_await : 1 +>await : 1 + diff --git a/tests/baselines/reference/topLevelAwait.2.js b/tests/baselines/reference/topLevelAwait.2.js new file mode 100644 index 0000000000000..eba6d89291b69 --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.2.js @@ -0,0 +1,10 @@ +//// [topLevelAwait.2.ts] +declare namespace foo { const await: any; } + +// await allowed in import=namespace when not a module +import await = foo.await; + + +//// [topLevelAwait.2.js] +// await allowed in import=namespace when not a module +var await = foo.await; diff --git a/tests/baselines/reference/topLevelAwait.2.symbols b/tests/baselines/reference/topLevelAwait.2.symbols new file mode 100644 index 0000000000000..81c4bdd060746 --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.2.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/externalModules/topLevelAwait.2.ts === +declare namespace foo { const await: any; } +>foo : Symbol(foo, Decl(topLevelAwait.2.ts, 0, 0)) +>await : Symbol(await, Decl(topLevelAwait.2.ts, 0, 29)) + +// await allowed in import=namespace when not a module +import await = foo.await; +>await : Symbol(await, Decl(topLevelAwait.2.ts, 0, 43)) +>foo : Symbol(foo, Decl(topLevelAwait.2.ts, 0, 0)) +>await : Symbol(await, Decl(topLevelAwait.2.ts, 0, 29)) + diff --git a/tests/baselines/reference/topLevelAwait.2.types b/tests/baselines/reference/topLevelAwait.2.types new file mode 100644 index 0000000000000..ebab4ee5f8783 --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.2.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/externalModules/topLevelAwait.2.ts === +declare namespace foo { const await: any; } +>foo : typeof foo +>await : any + +// await allowed in import=namespace when not a module +import await = foo.await; +>await : any +>foo : typeof foo +>await : any + diff --git a/tests/baselines/reference/topLevelAwait.3.symbols b/tests/baselines/reference/topLevelAwait.3.symbols new file mode 100644 index 0000000000000..85bc9cb0b6fad --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.3.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/externalModules/index.d.ts === +// await keyword allowed as identifier in a declaration file +export {}; +declare const await: any; +>await : Symbol(await, Decl(index.d.ts, 2, 13)) + +declare class C extends await {} +>C : Symbol(C, Decl(index.d.ts, 2, 25)) +>await : Symbol(await, Decl(index.d.ts, 2, 13)) + diff --git a/tests/baselines/reference/topLevelAwait.3.types b/tests/baselines/reference/topLevelAwait.3.types new file mode 100644 index 0000000000000..ae181359dc6f6 --- /dev/null +++ b/tests/baselines/reference/topLevelAwait.3.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/externalModules/index.d.ts === +// await keyword allowed as identifier in a declaration file +export {}; +declare const await: any; +>await : any + +declare class C extends await {} +>C : C +>await : any + diff --git a/tests/baselines/reference/topLevelAwaitErrors.1.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.1.errors.txt new file mode 100644 index 0000000000000..d2e7ffcb15a17 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.1.errors.txt @@ -0,0 +1,95 @@ +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(4,8): error TS2695: Left side of comma operator is unused and has no side effects. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(4,10): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(5,14): error TS1005: '>' expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(5,16): error TS2693: 'string' only refers to a type, but is being used as a value here. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(8,14): error TS1005: '>' expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(8,16): error TS2693: 'string' only refers to a type, but is being used as a value here. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(11,17): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(15,8): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(18,2): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(21,2): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(26,6): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(30,6): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(34,12): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(40,14): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(41,14): error TS1109: Expression expected. +tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(42,20): error TS1109: Expression expected. + + +==== tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts (16 errors) ==== + export {}; + + // reparse call as invalid await should error + await (1,); + ~ +!!! error TS2695: Left side of comma operator is unused and has no side effects. + ~ +!!! error TS1109: Expression expected. + await (1); + ~ +!!! error TS1005: '>' expected. + ~~~~~~ +!!! error TS2693: 'string' only refers to a type, but is being used as a value here. + + // reparse tagged template as invalid await should error + await ``; + ~ +!!! error TS1005: '>' expected. + ~~~~~~ +!!! error TS2693: 'string' only refers to a type, but is being used as a value here. + + // reparse class extends clause should fail + class C extends await { + ~~~~~ +!!! error TS1109: Expression expected. + } + + // await in class decorators should fail + @(await) + ~ +!!! error TS1109: Expression expected. + class C1 {} + + @await(x) + ~~~~~ +!!! error TS1109: Expression expected. + class C2 {} + + @await + ~~~~~ +!!! error TS1109: Expression expected. + class C3 {} + + // await in member decorators should fail + class C4 { + @await + ~~~~~ +!!! error TS1109: Expression expected. + ["foo"]() {} + } + class C5 { + @await(1) + ~~~~~ +!!! error TS1109: Expression expected. + ["foo"]() {} + } + class C6 { + @(await) + ~ +!!! error TS1109: Expression expected. + ["foo"]() {} + } + + // await in parameter decorators should fail + class C7 { + method1(@await [x]) {} + ~~~~~ +!!! error TS1109: Expression expected. + method2(@await(1) [x]) {} + ~~~~~ +!!! error TS1109: Expression expected. + method3(@(await) [x]) {} + ~ +!!! error TS1109: Expression expected. + } + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.1.js b/tests/baselines/reference/topLevelAwaitErrors.1.js new file mode 100644 index 0000000000000..566c86afe4929 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.1.js @@ -0,0 +1,102 @@ +//// [topLevelAwaitErrors.1.ts] +export {}; + +// reparse call as invalid await should error +await (1,); +await (1); + +// reparse tagged template as invalid await should error +await ``; + +// reparse class extends clause should fail +class C extends await { +} + +// await in class decorators should fail +@(await) +class C1 {} + +@await(x) +class C2 {} + +@await +class C3 {} + +// await in member decorators should fail +class C4 { + @await + ["foo"]() {} +} +class C5 { + @await(1) + ["foo"]() {} +} +class C6 { + @(await) + ["foo"]() {} +} + +// await in parameter decorators should fail +class C7 { + method1(@await [x]) {} + method2(@await(1) [x]) {} + method3(@(await) [x]) {} +} + + +//// [topLevelAwaitErrors.1.js] +// reparse call as invalid await should error +await (1, ); +await , string > (1); +// reparse tagged template as invalid await should error +await , string > ``; +// reparse class extends clause should fail +class C extends { +} +// await in class decorators should fail +let C1 = class C1 { +}; +C1 = __decorate([ + (await ) +], C1); +let C2 = class C2 { +}; +C2 = __decorate([ +], C2); +let C3 = class C3 { +}; +C3 = __decorate([ +], C3); +// await in member decorators should fail +class C4 { + ["foo"]() { } +} +__decorate([ +], C4.prototype, "foo", null); +class C5 { + ["foo"]() { } +} +__decorate([ +], C5.prototype, "foo", null); +class C6 { + ["foo"]() { } +} +__decorate([ + (await ) +], C6.prototype, "foo", null); +// await in parameter decorators should fail +class C7 { + method1([x]) { } + method2([x]) { } + method3([x]) { } +} +__decorate([ + __param(0, ) +], C7.prototype, "method1", null); +__decorate([ + __param(0, ) +], C7.prototype, "method2", null); +__decorate([ + __param(0, (await )) +], C7.prototype, "method3", null); +export {}; diff --git a/tests/baselines/reference/topLevelAwaitErrors.1.symbols b/tests/baselines/reference/topLevelAwaitErrors.1.symbols new file mode 100644 index 0000000000000..c414127bbe691 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.1.symbols @@ -0,0 +1,71 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts === +export {}; + +// reparse call as invalid await should error +await (1,); +await (1); + +// reparse tagged template as invalid await should error +await ``; + +// reparse class extends clause should fail +class C extends await { +>C : Symbol(C, Decl(topLevelAwaitErrors.1.ts, 7, 26)) +} + +// await in class decorators should fail +@(await) +class C1 {} +>C1 : Symbol(C1, Decl(topLevelAwaitErrors.1.ts, 11, 1)) + +@await(x) +class C2 {} +>C2 : Symbol(C2, Decl(topLevelAwaitErrors.1.ts, 15, 11)) + +@await +class C3 {} +>C3 : Symbol(C3, Decl(topLevelAwaitErrors.1.ts, 18, 11)) + +// await in member decorators should fail +class C4 { +>C4 : Symbol(C4, Decl(topLevelAwaitErrors.1.ts, 21, 11)) + + @await + ["foo"]() {} +>["foo"] : Symbol(C4["foo"], Decl(topLevelAwaitErrors.1.ts, 24, 10)) +>"foo" : Symbol(C4["foo"], Decl(topLevelAwaitErrors.1.ts, 24, 10)) +} +class C5 { +>C5 : Symbol(C5, Decl(topLevelAwaitErrors.1.ts, 27, 1)) + + @await(1) + ["foo"]() {} +>["foo"] : Symbol(C5["foo"], Decl(topLevelAwaitErrors.1.ts, 28, 10)) +>"foo" : Symbol(C5["foo"], Decl(topLevelAwaitErrors.1.ts, 28, 10)) +} +class C6 { +>C6 : Symbol(C6, Decl(topLevelAwaitErrors.1.ts, 31, 1)) + + @(await) + ["foo"]() {} +>["foo"] : Symbol(C6["foo"], Decl(topLevelAwaitErrors.1.ts, 32, 10)) +>"foo" : Symbol(C6["foo"], Decl(topLevelAwaitErrors.1.ts, 32, 10)) +} + +// await in parameter decorators should fail +class C7 { +>C7 : Symbol(C7, Decl(topLevelAwaitErrors.1.ts, 35, 1)) + + method1(@await [x]) {} +>method1 : Symbol(C7.method1, Decl(topLevelAwaitErrors.1.ts, 38, 10)) +>x : Symbol(x, Decl(topLevelAwaitErrors.1.ts, 39, 20)) + + method2(@await(1) [x]) {} +>method2 : Symbol(C7.method2, Decl(topLevelAwaitErrors.1.ts, 39, 26)) +>x : Symbol(x, Decl(topLevelAwaitErrors.1.ts, 40, 23)) + + method3(@(await) [x]) {} +>method3 : Symbol(C7.method3, Decl(topLevelAwaitErrors.1.ts, 40, 29)) +>x : Symbol(x, Decl(topLevelAwaitErrors.1.ts, 41, 22)) +} + diff --git a/tests/baselines/reference/topLevelAwaitErrors.1.types b/tests/baselines/reference/topLevelAwaitErrors.1.types new file mode 100644 index 0000000000000..5f3a5e323c722 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.1.types @@ -0,0 +1,114 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts === +export {}; + +// reparse call as invalid await should error +await (1,); +>await (1,) : any +>(1,) : any +>1, : any +>1 : 1 +> : any + +await (1); +>await (1) : boolean +>await : any +>string>(1) : boolean +>string : any +>(1) : 1 +>1 : 1 + +// reparse tagged template as invalid await should error +await ``; +>await `` : boolean +>await : any +>string> `` : boolean +>string : any +>`` : "" + +// reparse class extends clause should fail +class C extends await { +>C : C +> : any +} + +// await in class decorators should fail +@(await) +>(await) : any +>await : any +> : any + +class C1 {} +>C1 : C1 + +@await(x) +> : any + +class C2 {} +>C2 : C2 + +@await +> : any + +class C3 {} +>C3 : C3 + +// await in member decorators should fail +class C4 { +>C4 : C4 + + @await +> : any + + ["foo"]() {} +>["foo"] : () => void +>"foo" : "foo" +} +class C5 { +>C5 : C5 + + @await(1) +> : any + + ["foo"]() {} +>["foo"] : () => void +>"foo" : "foo" +} +class C6 { +>C6 : C6 + + @(await) +>(await) : any +>await : any +> : any + + ["foo"]() {} +>["foo"] : () => void +>"foo" : "foo" +} + +// await in parameter decorators should fail +class C7 { +>C7 : C7 + + method1(@await [x]) {} +>method1 : ([x]: [any]) => void +> : any +>x : any + + method2(@await(1) [x]) {} +>method2 : ([x]: [any]) => void +> : any +>x : any + + method3(@(await) [x]) {} +>method3 : ([x]: [any]) => void +>(await) : any +>await : any +> : any +>x : any +} + diff --git a/tests/baselines/reference/topLevelAwaitErrors.10.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.10.errors.txt new file mode 100644 index 0000000000000..999ba4ab21efa --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.10.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/externalModules/index.ts(2,19): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/index.ts (1 errors) ==== + // await disallowed in alias of named import + import { await as await } from "./other"; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + +==== tests/cases/conformance/externalModules/other.ts (0 errors) ==== + declare const _await: any; + export { _await as await }; + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.10.js b/tests/baselines/reference/topLevelAwaitErrors.10.js new file mode 100644 index 0000000000000..4d0c107a0e7f9 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.10.js @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/externalModules/topLevelAwaitErrors.10.ts] //// + +//// [index.ts] +// await disallowed in alias of named import +import { await as await } from "./other"; + +//// [other.ts] +declare const _await: any; +export { _await as await }; + + +//// [other.js] +export { _await as await }; +//// [index.js] +export {}; diff --git a/tests/baselines/reference/topLevelAwaitErrors.10.symbols b/tests/baselines/reference/topLevelAwaitErrors.10.symbols new file mode 100644 index 0000000000000..01b637582def1 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.10.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in alias of named import +import { await as await } from "./other"; +>await : Symbol(await, Decl(other.ts, 1, 8)) +>await : Symbol(await, Decl(index.ts, 1, 8)) + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) + +export { _await as await }; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) +>await : Symbol(await, Decl(other.ts, 1, 8)) + diff --git a/tests/baselines/reference/topLevelAwaitErrors.10.types b/tests/baselines/reference/topLevelAwaitErrors.10.types new file mode 100644 index 0000000000000..75595969742a3 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.10.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in alias of named import +import { await as await } from "./other"; +>await : any +>await : any + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : any + +export { _await as await }; +>_await : any +>await : any + diff --git a/tests/baselines/reference/topLevelAwaitErrors.11.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.11.errors.txt new file mode 100644 index 0000000000000..5c689ca58b119 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.11.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/externalModules/index.ts(3,8): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/index.ts (1 errors) ==== + // await disallowed in import= + declare var require: any; + import await = require("./other"); + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + +==== tests/cases/conformance/externalModules/other.ts (0 errors) ==== + declare const _await: any; + export { _await as await }; + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.11.js b/tests/baselines/reference/topLevelAwaitErrors.11.js new file mode 100644 index 0000000000000..e21888aa30a33 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.11.js @@ -0,0 +1,32 @@ +//// [tests/cases/conformance/externalModules/topLevelAwaitErrors.11.ts] //// + +//// [index.ts] +// await disallowed in import= +declare var require: any; +import await = require("./other"); + +//// [other.ts] +declare const _await: any; +export { _await as await }; + + +//// [other.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + } + }; +}); +//// [index.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + } + }; +}); diff --git a/tests/baselines/reference/topLevelAwaitErrors.11.symbols b/tests/baselines/reference/topLevelAwaitErrors.11.symbols new file mode 100644 index 0000000000000..0cfb38ce493d7 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.11.symbols @@ -0,0 +1,16 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in import= +declare var require: any; +>require : Symbol(require, Decl(index.ts, 1, 11)) + +import await = require("./other"); +>await : Symbol(await, Decl(index.ts, 1, 25)) + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) + +export { _await as await }; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) +>await : Symbol(await, Decl(other.ts, 1, 8)) + diff --git a/tests/baselines/reference/topLevelAwaitErrors.11.types b/tests/baselines/reference/topLevelAwaitErrors.11.types new file mode 100644 index 0000000000000..f2d404cf770b6 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.11.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in import= +declare var require: any; +>require : any + +import await = require("./other"); +>await : typeof await + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : any + +export { _await as await }; +>_await : any +>await : any + diff --git a/tests/baselines/reference/topLevelAwaitErrors.12.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.12.errors.txt new file mode 100644 index 0000000000000..55b06a8c96d20 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.12.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/externalModules/topLevelAwaitErrors.12.ts(5,8): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/topLevelAwaitErrors.12.ts (1 errors) ==== + export {}; + declare namespace foo { const await: any; } + + // await disallowed in import=namespace when in a module + import await = foo.await; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.12.js b/tests/baselines/reference/topLevelAwaitErrors.12.js new file mode 100644 index 0000000000000..6d1e03272a01e --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.12.js @@ -0,0 +1,10 @@ +//// [topLevelAwaitErrors.12.ts] +export {}; +declare namespace foo { const await: any; } + +// await disallowed in import=namespace when in a module +import await = foo.await; + + +//// [topLevelAwaitErrors.12.js] +export {}; diff --git a/tests/baselines/reference/topLevelAwaitErrors.12.symbols b/tests/baselines/reference/topLevelAwaitErrors.12.symbols new file mode 100644 index 0000000000000..c95ce4822ae0c --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.12.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.12.ts === +export {}; +declare namespace foo { const await: any; } +>foo : Symbol(foo, Decl(topLevelAwaitErrors.12.ts, 0, 10)) +>await : Symbol(await, Decl(topLevelAwaitErrors.12.ts, 1, 29)) + +// await disallowed in import=namespace when in a module +import await = foo.await; +>await : Symbol(await, Decl(topLevelAwaitErrors.12.ts, 1, 43)) +>foo : Symbol(foo, Decl(topLevelAwaitErrors.12.ts, 0, 10)) +>await : Symbol(await, Decl(topLevelAwaitErrors.12.ts, 1, 29)) + diff --git a/tests/baselines/reference/topLevelAwaitErrors.12.types b/tests/baselines/reference/topLevelAwaitErrors.12.types new file mode 100644 index 0000000000000..04099d797b24c --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.12.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.12.ts === +export {}; +declare namespace foo { const await: any; } +>foo : typeof foo +>await : any + +// await disallowed in import=namespace when in a module +import await = foo.await; +>await : any +>foo : typeof foo +>await : any + diff --git a/tests/baselines/reference/topLevelAwaitErrors.2.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.2.errors.txt new file mode 100644 index 0000000000000..c33dcc141f55b --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/externalModules/topLevelAwaitErrors.2.ts(4,5): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/topLevelAwaitErrors.2.ts (1 errors) ==== + export {}; + + // reparse variable name as await should fail + var await = 1; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.2.js b/tests/baselines/reference/topLevelAwaitErrors.2.js new file mode 100644 index 0000000000000..c602a49167faf --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.2.js @@ -0,0 +1,11 @@ +//// [topLevelAwaitErrors.2.ts] +export {}; + +// reparse variable name as await should fail +var await = 1; + + +//// [topLevelAwaitErrors.2.js] +// reparse variable name as await should fail +var await = 1; +export {}; diff --git a/tests/baselines/reference/topLevelAwaitErrors.2.symbols b/tests/baselines/reference/topLevelAwaitErrors.2.symbols new file mode 100644 index 0000000000000..fe956e02d4116 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.2.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.2.ts === +export {}; + +// reparse variable name as await should fail +var await = 1; +>await : Symbol(await, Decl(topLevelAwaitErrors.2.ts, 3, 3)) + diff --git a/tests/baselines/reference/topLevelAwaitErrors.2.types b/tests/baselines/reference/topLevelAwaitErrors.2.types new file mode 100644 index 0000000000000..259a942030be5 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.2.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.2.ts === +export {}; + +// reparse variable name as await should fail +var await = 1; +>await : number +>1 : 1 + diff --git a/tests/baselines/reference/topLevelAwaitErrors.3.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.3.errors.txt new file mode 100644 index 0000000000000..e8f7a42817a53 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.3.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/externalModules/topLevelAwaitErrors.3.ts(4,6): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/topLevelAwaitErrors.3.ts (1 errors) ==== + export {}; + + // reparse binding pattern as await should fail + var {await} = {await:1}; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.3.js b/tests/baselines/reference/topLevelAwaitErrors.3.js new file mode 100644 index 0000000000000..9957fa58fc05a --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.3.js @@ -0,0 +1,11 @@ +//// [topLevelAwaitErrors.3.ts] +export {}; + +// reparse binding pattern as await should fail +var {await} = {await:1}; + + +//// [topLevelAwaitErrors.3.js] +// reparse binding pattern as await should fail +var { await } = { await: 1 }; +export {}; diff --git a/tests/baselines/reference/topLevelAwaitErrors.3.symbols b/tests/baselines/reference/topLevelAwaitErrors.3.symbols new file mode 100644 index 0000000000000..0626ef8b64d66 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.3.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.3.ts === +export {}; + +// reparse binding pattern as await should fail +var {await} = {await:1}; +>await : Symbol(await, Decl(topLevelAwaitErrors.3.ts, 3, 5)) +>await : Symbol(await, Decl(topLevelAwaitErrors.3.ts, 3, 15)) + diff --git a/tests/baselines/reference/topLevelAwaitErrors.3.types b/tests/baselines/reference/topLevelAwaitErrors.3.types new file mode 100644 index 0000000000000..4b98e1217127a --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.3.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.3.ts === +export {}; + +// reparse binding pattern as await should fail +var {await} = {await:1}; +>await : number +>{await:1} : { await: number; } +>await : number +>1 : 1 + diff --git a/tests/baselines/reference/topLevelAwaitErrors.4.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.4.errors.txt new file mode 100644 index 0000000000000..845d4385621cd --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.4.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/externalModules/topLevelAwaitErrors.4.ts(4,6): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/topLevelAwaitErrors.4.ts (1 errors) ==== + export {}; + + // reparse binding pattern as await should fail + var [await] = [1]; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.4.js b/tests/baselines/reference/topLevelAwaitErrors.4.js new file mode 100644 index 0000000000000..47bab9d5c1c1c --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.4.js @@ -0,0 +1,11 @@ +//// [topLevelAwaitErrors.4.ts] +export {}; + +// reparse binding pattern as await should fail +var [await] = [1]; + + +//// [topLevelAwaitErrors.4.js] +// reparse binding pattern as await should fail +var [await] = [1]; +export {}; diff --git a/tests/baselines/reference/topLevelAwaitErrors.4.symbols b/tests/baselines/reference/topLevelAwaitErrors.4.symbols new file mode 100644 index 0000000000000..756d0baaf04bc --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.4.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.4.ts === +export {}; + +// reparse binding pattern as await should fail +var [await] = [1]; +>await : Symbol(await, Decl(topLevelAwaitErrors.4.ts, 3, 5)) + diff --git a/tests/baselines/reference/topLevelAwaitErrors.4.types b/tests/baselines/reference/topLevelAwaitErrors.4.types new file mode 100644 index 0000000000000..9afcbbb85480d --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.4.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.4.ts === +export {}; + +// reparse binding pattern as await should fail +var [await] = [1]; +>await : number +>[1] : [number] +>1 : 1 + diff --git a/tests/baselines/reference/topLevelAwaitErrors.5.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.5.errors.txt new file mode 100644 index 0000000000000..75554ce21df80 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.5.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/externalModules/topLevelAwaitErrors.5.ts(2,14): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/topLevelAwaitErrors.5.ts (1 errors) ==== + // await in exported class name should fail + export class await { + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.5.js b/tests/baselines/reference/topLevelAwaitErrors.5.js new file mode 100644 index 0000000000000..702d0a8003131 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.5.js @@ -0,0 +1,10 @@ +//// [topLevelAwaitErrors.5.ts] +// await in exported class name should fail +export class await { +} + + +//// [topLevelAwaitErrors.5.js] +// await in exported class name should fail +export class await { +} diff --git a/tests/baselines/reference/topLevelAwaitErrors.5.symbols b/tests/baselines/reference/topLevelAwaitErrors.5.symbols new file mode 100644 index 0000000000000..8d8b4669cf812 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.5.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.5.ts === +// await in exported class name should fail +export class await { +>await : Symbol(await, Decl(topLevelAwaitErrors.5.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/topLevelAwaitErrors.5.types b/tests/baselines/reference/topLevelAwaitErrors.5.types new file mode 100644 index 0000000000000..d4a5403dadc9c --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.5.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.5.ts === +// await in exported class name should fail +export class await { +>await : await +} + diff --git a/tests/baselines/reference/topLevelAwaitErrors.6.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.6.errors.txt new file mode 100644 index 0000000000000..e7d68df46f212 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.6.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/externalModules/topLevelAwaitErrors.6.ts(2,17): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/topLevelAwaitErrors.6.ts (1 errors) ==== + // await in exported function name should fail + export function await() { + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.6.js b/tests/baselines/reference/topLevelAwaitErrors.6.js new file mode 100644 index 0000000000000..a4391c56b04ac --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.6.js @@ -0,0 +1,10 @@ +//// [topLevelAwaitErrors.6.ts] +// await in exported function name should fail +export function await() { +} + + +//// [topLevelAwaitErrors.6.js] +// await in exported function name should fail +export function await() { +} diff --git a/tests/baselines/reference/topLevelAwaitErrors.6.symbols b/tests/baselines/reference/topLevelAwaitErrors.6.symbols new file mode 100644 index 0000000000000..8acd78377851c --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.6.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.6.ts === +// await in exported function name should fail +export function await() { +>await : Symbol(await, Decl(topLevelAwaitErrors.6.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/topLevelAwaitErrors.6.types b/tests/baselines/reference/topLevelAwaitErrors.6.types new file mode 100644 index 0000000000000..52eef99cfa052 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.6.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/externalModules/topLevelAwaitErrors.6.ts === +// await in exported function name should fail +export function await() { +>await : () => void +} + diff --git a/tests/baselines/reference/topLevelAwaitErrors.7.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.7.errors.txt new file mode 100644 index 0000000000000..ae56ff6fcf343 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.7.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/externalModules/index.ts(2,13): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/index.ts (1 errors) ==== + // await disallowed in namespace import + import * as await from "./other"; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + +==== tests/cases/conformance/externalModules/other.ts (0 errors) ==== + declare const _await: any; + export { _await as await }; \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.7.js b/tests/baselines/reference/topLevelAwaitErrors.7.js new file mode 100644 index 0000000000000..80f4d0d1dc70d --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.7.js @@ -0,0 +1,14 @@ +//// [tests/cases/conformance/externalModules/topLevelAwaitErrors.7.ts] //// + +//// [index.ts] +// await disallowed in namespace import +import * as await from "./other"; + +//// [other.ts] +declare const _await: any; +export { _await as await }; + +//// [other.js] +export { _await as await }; +//// [index.js] +export {}; diff --git a/tests/baselines/reference/topLevelAwaitErrors.7.symbols b/tests/baselines/reference/topLevelAwaitErrors.7.symbols new file mode 100644 index 0000000000000..4bdcaada48bca --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.7.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in namespace import +import * as await from "./other"; +>await : Symbol(await, Decl(index.ts, 1, 6)) + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) + +export { _await as await }; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) +>await : Symbol(await, Decl(other.ts, 1, 8)) + diff --git a/tests/baselines/reference/topLevelAwaitErrors.7.types b/tests/baselines/reference/topLevelAwaitErrors.7.types new file mode 100644 index 0000000000000..88ad9d378a7b6 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.7.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in namespace import +import * as await from "./other"; +>await : typeof await + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : any + +export { _await as await }; +>_await : any +>await : any + diff --git a/tests/baselines/reference/topLevelAwaitErrors.8.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.8.errors.txt new file mode 100644 index 0000000000000..ddcc2a7bd655f --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.8.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/externalModules/index.ts(2,8): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/index.ts (1 errors) ==== + // await disallowed in default import + import await from "./other"; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + +==== tests/cases/conformance/externalModules/other.ts (0 errors) ==== + declare const _await: any; + export default _await; + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.8.js b/tests/baselines/reference/topLevelAwaitErrors.8.js new file mode 100644 index 0000000000000..836b64095a9b8 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.8.js @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/externalModules/topLevelAwaitErrors.8.ts] //// + +//// [index.ts] +// await disallowed in default import +import await from "./other"; + +//// [other.ts] +declare const _await: any; +export default _await; + + +//// [other.js] +export default _await; +//// [index.js] +export {}; diff --git a/tests/baselines/reference/topLevelAwaitErrors.8.symbols b/tests/baselines/reference/topLevelAwaitErrors.8.symbols new file mode 100644 index 0000000000000..5a20ce957d49c --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.8.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in default import +import await from "./other"; +>await : Symbol(await, Decl(index.ts, 1, 6)) + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) + +export default _await; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) + diff --git a/tests/baselines/reference/topLevelAwaitErrors.8.types b/tests/baselines/reference/topLevelAwaitErrors.8.types new file mode 100644 index 0000000000000..19df9e0946252 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.8.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in default import +import await from "./other"; +>await : any + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : any + +export default _await; +>_await : any + diff --git a/tests/baselines/reference/topLevelAwaitErrors.9.errors.txt b/tests/baselines/reference/topLevelAwaitErrors.9.errors.txt new file mode 100644 index 0000000000000..16eea20bebbaf --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.9.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/externalModules/index.ts(2,10): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + + +==== tests/cases/conformance/externalModules/index.ts (1 errors) ==== + // await disallowed in un-alised named import + import { await } from "./other"; + ~~~~~ +!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module. + +==== tests/cases/conformance/externalModules/other.ts (0 errors) ==== + declare const _await: any; + export { _await as await }; + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitErrors.9.js b/tests/baselines/reference/topLevelAwaitErrors.9.js new file mode 100644 index 0000000000000..76f86b6d5cbc7 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.9.js @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/externalModules/topLevelAwaitErrors.9.ts] //// + +//// [index.ts] +// await disallowed in un-alised named import +import { await } from "./other"; + +//// [other.ts] +declare const _await: any; +export { _await as await }; + + +//// [other.js] +export { _await as await }; +//// [index.js] +export {}; diff --git a/tests/baselines/reference/topLevelAwaitErrors.9.symbols b/tests/baselines/reference/topLevelAwaitErrors.9.symbols new file mode 100644 index 0000000000000..e1b820fd0ed0d --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.9.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in un-alised named import +import { await } from "./other"; +>await : Symbol(await, Decl(index.ts, 1, 8)) + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) + +export { _await as await }; +>_await : Symbol(_await, Decl(other.ts, 0, 13)) +>await : Symbol(await, Decl(other.ts, 1, 8)) + diff --git a/tests/baselines/reference/topLevelAwaitErrors.9.types b/tests/baselines/reference/topLevelAwaitErrors.9.types new file mode 100644 index 0000000000000..e31f8d453f001 --- /dev/null +++ b/tests/baselines/reference/topLevelAwaitErrors.9.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/externalModules/index.ts === +// await disallowed in un-alised named import +import { await } from "./other"; +>await : any + +=== tests/cases/conformance/externalModules/other.ts === +declare const _await: any; +>_await : any + +export { _await as await }; +>_await : any +>await : any + diff --git a/tests/cases/conformance/externalModules/topLevelAwait.1.ts b/tests/cases/conformance/externalModules/topLevelAwait.1.ts new file mode 100644 index 0000000000000..dbee4b33013d3 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwait.1.ts @@ -0,0 +1,62 @@ +// @target: es2015,es2017 +// @module: esnext,system +// @experimentalDecorators: true +// @noEmitHelpers: true +// @filename: index.ts +export const x = 1; +await x; + +// reparse element access as await +await [x]; +await [x, x]; + +// reparse call as await +declare function f(): number; +await (x); +await (f(), x); +await (x); +await (f(), x); + +// reparse tagged template as await +await ``; +await ``; + +// member names should be ok +class C1 { + await() {} +} +class C2 { + get await() { return 1; } + set await(value) { } +} +class C3 { + await = 1; +} +({ + await() {} +}); +({ + get await() { return 1 }, + set await(value) { } +}); +({ + await: 1 +}); + +// property access name should be ok +C1.prototype.await; + +// await in decorators +declare const dec: any; +@(await dec) +class C { +} + +// await allowed in aliased import +import { await as _await } from "./other"; + +// @filename: other.ts +const _await = 1; + +// await allowed in aliased export +export { _await as await }; \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/topLevelAwait.2.ts b/tests/cases/conformance/externalModules/topLevelAwait.2.ts new file mode 100644 index 0000000000000..25b841d3e8ce3 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwait.2.ts @@ -0,0 +1,7 @@ +// @target: esnext +// @module: esnext + +declare namespace foo { const await: any; } + +// await allowed in import=namespace when not a module +import await = foo.await; diff --git a/tests/cases/conformance/externalModules/topLevelAwait.3.ts b/tests/cases/conformance/externalModules/topLevelAwait.3.ts new file mode 100644 index 0000000000000..1e18814559989 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwait.3.ts @@ -0,0 +1,8 @@ +// @target: esnext +// @module: esnext +// @filename: index.d.ts + +// await keyword allowed as identifier in a declaration file +export {}; +declare const await: any; +declare class C extends await {} \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/topLevelAwait.ts b/tests/cases/conformance/externalModules/topLevelAwait.ts deleted file mode 100644 index 7c92e507e57cd..0000000000000 --- a/tests/cases/conformance/externalModules/topLevelAwait.ts +++ /dev/null @@ -1,4 +0,0 @@ -// @target: es2015,es2017 -// @module: esnext,system -export const x = 1; -await x; diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts new file mode 100644 index 0000000000000..72fe5c12ceb78 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts @@ -0,0 +1,48 @@ +// @target: esnext +// @module: esnext +// @experimentalDecorators: true +// @noEmitHelpers: true + +export {}; + +// reparse call as invalid await should error +await (1,); +await (1); + +// reparse tagged template as invalid await should error +await ``; + +// reparse class extends clause should fail +class C extends await { +} + +// await in class decorators should fail +@(await) +class C1 {} + +@await(x) +class C2 {} + +@await +class C3 {} + +// await in member decorators should fail +class C4 { + @await + ["foo"]() {} +} +class C5 { + @await(1) + ["foo"]() {} +} +class C6 { + @(await) + ["foo"]() {} +} + +// await in parameter decorators should fail +class C7 { + method1(@await [x]) {} + method2(@await(1) [x]) {} + method3(@(await) [x]) {} +} diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.10.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.10.ts new file mode 100644 index 0000000000000..d418925f202f4 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.10.ts @@ -0,0 +1,10 @@ +// @target: esnext +// @module: esnext + +// @filename: index.ts +// await disallowed in alias of named import +import { await as await } from "./other"; + +// @filename: other.ts +declare const _await: any; +export { _await as await }; diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.11.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.11.ts new file mode 100644 index 0000000000000..8bbf3142e1995 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.11.ts @@ -0,0 +1,11 @@ +// @target: esnext +// @module: system + +// @filename: index.ts +// await disallowed in import= +declare var require: any; +import await = require("./other"); + +// @filename: other.ts +declare const _await: any; +export { _await as await }; diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.12.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.12.ts new file mode 100644 index 0000000000000..b884960706256 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.12.ts @@ -0,0 +1,8 @@ +// @target: esnext +// @module: esnext + +export {}; +declare namespace foo { const await: any; } + +// await disallowed in import=namespace when in a module +import await = foo.await; diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.2.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.2.ts new file mode 100644 index 0000000000000..5b963d006ad44 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.2.ts @@ -0,0 +1,7 @@ +// @target: esnext +// @module: esnext + +export {}; + +// reparse variable name as await should fail +var await = 1; diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.3.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.3.ts new file mode 100644 index 0000000000000..4d88141e09b9d --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.3.ts @@ -0,0 +1,7 @@ +// @target: esnext +// @module: esnext + +export {}; + +// reparse binding pattern as await should fail +var {await} = {await:1}; diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.4.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.4.ts new file mode 100644 index 0000000000000..99306b5203794 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.4.ts @@ -0,0 +1,7 @@ +// @target: esnext +// @module: esnext + +export {}; + +// reparse binding pattern as await should fail +var [await] = [1]; diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.5.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.5.ts new file mode 100644 index 0000000000000..a6c3a8c6aa58d --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.5.ts @@ -0,0 +1,6 @@ +// @target: esnext +// @module: esnext + +// await in exported class name should fail +export class await { +} diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.6.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.6.ts new file mode 100644 index 0000000000000..9ee13de03fb84 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.6.ts @@ -0,0 +1,6 @@ +// @target: esnext +// @module: esnext + +// await in exported function name should fail +export function await() { +} diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.7.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.7.ts new file mode 100644 index 0000000000000..41c0110522af1 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.7.ts @@ -0,0 +1,10 @@ +// @target: esnext +// @module: esnext + +// @filename: index.ts +// await disallowed in namespace import +import * as await from "./other"; + +// @filename: other.ts +declare const _await: any; +export { _await as await }; \ No newline at end of file diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.8.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.8.ts new file mode 100644 index 0000000000000..defa012d3d7fb --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.8.ts @@ -0,0 +1,10 @@ +// @target: esnext +// @module: esnext + +// @filename: index.ts +// await disallowed in default import +import await from "./other"; + +// @filename: other.ts +declare const _await: any; +export default _await; diff --git a/tests/cases/conformance/externalModules/topLevelAwaitErrors.9.ts b/tests/cases/conformance/externalModules/topLevelAwaitErrors.9.ts new file mode 100644 index 0000000000000..69e6ffc796c51 --- /dev/null +++ b/tests/cases/conformance/externalModules/topLevelAwaitErrors.9.ts @@ -0,0 +1,10 @@ +// @target: esnext +// @module: esnext + +// @filename: index.ts +// await disallowed in un-alised named import +import { await } from "./other"; + +// @filename: other.ts +declare const _await: any; +export { _await as await }; diff --git a/tests/cases/fourslash/incrementalParsingTopLevelAwait.1.ts b/tests/cases/fourslash/incrementalParsingTopLevelAwait.1.ts new file mode 100644 index 0000000000000..48aa67d13b844 --- /dev/null +++ b/tests/cases/fourslash/incrementalParsingTopLevelAwait.1.ts @@ -0,0 +1,15 @@ +/// + +// @target: esnext +// @module: esnext + +// @Filename: ./foo.ts +//// await(1); +//// /*1*/ + +verify.numberOfErrorsInCurrentFile(1); +goTo.marker("1"); +edit.insert("export {};"); +verify.numberOfErrorsInCurrentFile(0); +edit.replaceLine(1, ""); +verify.numberOfErrorsInCurrentFile(1); \ No newline at end of file diff --git a/tests/cases/fourslash/incrementalParsingTopLevelAwait.2.ts b/tests/cases/fourslash/incrementalParsingTopLevelAwait.2.ts new file mode 100644 index 0000000000000..84d0cc74e00a9 --- /dev/null +++ b/tests/cases/fourslash/incrementalParsingTopLevelAwait.2.ts @@ -0,0 +1,15 @@ +/// + +// @target: esnext +// @module: esnext + +// @Filename: ./foo.ts +//// export {}; +//// /*1*/ + +verify.numberOfErrorsInCurrentFile(0); +goTo.marker("1"); +edit.insert("await(1);"); +verify.numberOfErrorsInCurrentFile(0); +edit.replaceLine(1, ""); +verify.numberOfErrorsInCurrentFile(0); \ No newline at end of file