diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 17919a326d59c..ed70444bd9baa 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2499,8 +2499,13 @@ namespace ts { declareSymbol(symbolTable, containingClass.symbol, node, SymbolFlags.Property, SymbolFlags.None, /*isReplaceableByMethod*/ true); break; case SyntaxKind.SourceFile: - // this.foo assignment in a source file - // Do not bind. It would be nice to support this someday though. + // this.property = assignment in a source file -- declare symbol in exports for a module, in locals for a script + if ((thisContainer as SourceFile).commonJsModuleIndicator) { + declareSymbol(thisContainer.symbol.exports!, thisContainer.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None); + } + else { + declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes); + } break; default: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7e6cb97a9302e..7a4c32ea00113 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -88,8 +88,16 @@ namespace ts { const emitResolver = createResolver(); const nodeBuilder = createNodeBuilder(); + const globals = createSymbolTable(); const undefinedSymbol = createSymbol(SymbolFlags.Property, "undefined" as __String); undefinedSymbol.declarations = []; + + const globalThisSymbol = createSymbol(SymbolFlags.Module, "globalThis" as __String, CheckFlags.Readonly); + globalThisSymbol.exports = globals; + globalThisSymbol.valueDeclaration = createNode(SyntaxKind.Identifier) as Identifier; + (globalThisSymbol.valueDeclaration as Identifier).escapedText = "globalThis" as __String; + globals.set(globalThisSymbol.escapedName, globalThisSymbol); + const argumentsSymbol = createSymbol(SymbolFlags.Property, "arguments" as __String); const requireSymbol = createSymbol(SymbolFlags.Property, "require" as __String); @@ -310,9 +318,9 @@ namespace ts { getAccessibleSymbolChain, getTypePredicateOfSignature: getTypePredicateOfSignature as (signature: Signature) => TypePredicate, // TODO: GH#18217 resolveExternalModuleSymbol, - tryGetThisTypeAt: node => { + tryGetThisTypeAt: (node, includeGlobalThis) => { node = getParseTreeNode(node); - return node && tryGetThisTypeAt(node); + return node && tryGetThisTypeAt(node, includeGlobalThis); }, getTypeArgumentConstraint: nodeIn => { const node = getParseTreeNode(nodeIn, isTypeNode); @@ -459,7 +467,6 @@ namespace ts { const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); - const globals = createSymbolTable(); interface DuplicateInfoForSymbol { readonly firstFileLocations: Node[]; readonly secondFileLocations: Node[]; @@ -9703,7 +9710,7 @@ namespace ts { } function getLiteralTypeFromProperties(type: Type, include: TypeFlags) { - return getUnionType(map(getPropertiesOfType(type), t => getLiteralTypeFromProperty(t, include))); + return getUnionType(map(getPropertiesOfType(type), p => getLiteralTypeFromProperty(p, include))); } function getNonEnumNumberIndexInfo(type: Type) { @@ -16981,25 +16988,27 @@ namespace ts { captureLexicalThis(node, container); } - const type = tryGetThisTypeAt(node, container); - if (!type && noImplicitThis) { - // With noImplicitThis, functions may not reference 'this' if it has type 'any' - const diag = error( - node, - capturedByArrowFunction && container.kind === SyntaxKind.SourceFile ? - Diagnostics.The_containing_arrow_function_captures_the_global_value_of_this_which_implicitly_has_type_any : - Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation); - if (!isSourceFile(container)) { - const outsideThis = tryGetThisTypeAt(container); - if (outsideThis) { - addRelatedInfo(diag, createDiagnosticForNode(container, Diagnostics.An_outer_value_of_this_is_shadowed_by_this_container)); + const type = tryGetThisTypeAt(node, /*includeGlobalThis*/ true, container); + if (noImplicitThis) { + const globalThisType = getTypeOfSymbol(globalThisSymbol); + if (type === globalThisType && capturedByArrowFunction) { + error(node, Diagnostics.The_containing_arrow_function_captures_the_global_value_of_this); + } + else if (!type) { + // With noImplicitThis, functions may not reference 'this' if it has type 'any' + const diag = error(node, Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation); + if (!isSourceFile(container)) { + const outsideThis = tryGetThisTypeAt(container); + if (outsideThis && outsideThis !== globalThisType) { + addRelatedInfo(diag, createDiagnosticForNode(container, Diagnostics.An_outer_value_of_this_is_shadowed_by_this_container)); + } } } } return type || anyType; } - function tryGetThisTypeAt(node: Node, container = getThisContainer(node, /*includeArrowFunctions*/ false)): Type | undefined { + function tryGetThisTypeAt(node: Node, includeGlobalThis = true, container = getThisContainer(node, /*includeArrowFunctions*/ false)): Type | undefined { const isInJS = isInJSFile(node); if (isFunctionLike(container) && (!isInParameterInitializerBeforeContainingFunction(node) || getThisParameter(container))) { @@ -17046,6 +17055,16 @@ namespace ts { return getFlowTypeOfReference(node, type); } } + if (isSourceFile(container)) { + // look up in the source file's locals or exports + if (container.commonJsModuleIndicator) { + const fileSymbol = getSymbolOfNode(container); + return fileSymbol && getTypeOfSymbol(fileSymbol); + } + else if (includeGlobalThis) { + return getTypeOfSymbol(globalThisSymbol); + } + } } function getClassNameFromPrototypeMethod(container: Node) { @@ -19343,6 +19362,12 @@ namespace ts { if (isJSLiteralType(leftType)) { return anyType; } + if (leftType.symbol === globalThisSymbol) { + if (noImplicitAny) { + error(right, Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature, typeToString(leftType)); + } + return anyType; + } if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) { reportNonexistentProperty(right, leftType.flags & TypeFlags.TypeParameter && (leftType as TypeParameter).isThisType ? apparentType : leftType); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 09b0f72129255..83483a95de1ec 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4149,7 +4149,7 @@ "category": "Error", "code": 7040 }, - "The containing arrow function captures the global value of 'this' which implicitly has type 'any'.": { + "The containing arrow function captures the global value of 'this'.": { "category": "Error", "code": 7041 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index cce869df44ea1..42fd1126d4cba 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3223,7 +3223,7 @@ namespace ts { */ /* @internal */ resolveExternalModuleSymbol(symbol: Symbol): Symbol; /** @param node A location where we might consider accessing `this`. Not necessarily a ThisExpression. */ - /* @internal */ tryGetThisTypeAt(node: Node): Type | undefined; + /* @internal */ tryGetThisTypeAt(node: Node, includeGlobalThis?: boolean): Type | undefined; /* @internal */ getTypeArgumentConstraint(node: TypeNode): Type | undefined; /** diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index f3a7197e7772c..16f1a37ae83fa 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -774,7 +774,7 @@ namespace FourSlash { if ("exact" in options) { ts.Debug.assert(!("includes" in options) && !("excludes" in options)); if (options.exact === undefined) throw this.raiseError("Expected no completions"); - this.verifyCompletionsAreExactly(actualCompletions.entries, toArray(options.exact)); + this.verifyCompletionsAreExactly(actualCompletions.entries, toArray(options.exact), options.marker); } else { if (options.includes) { @@ -841,14 +841,14 @@ namespace FourSlash { } } - private verifyCompletionsAreExactly(actual: ReadonlyArray, expected: ReadonlyArray) { + private verifyCompletionsAreExactly(actual: ReadonlyArray, expected: ReadonlyArray, marker?: ArrayOrSingle) { // First pass: test that names are right. Then we'll test details. - assert.deepEqual(actual.map(a => a.name), expected.map(e => typeof e === "string" ? e : e.name)); + assert.deepEqual(actual.map(a => a.name), expected.map(e => typeof e === "string" ? e : e.name), marker ? "At marker " + JSON.stringify(marker) : undefined); ts.zipWith(actual, expected, (completion, expectedCompletion, index) => { const name = typeof expectedCompletion === "string" ? expectedCompletion : expectedCompletion.name; if (completion.name !== name) { - this.raiseError(`Expected completion at index ${index} to be ${name}, got ${completion.name}`); + this.raiseError(`${marker ? JSON.stringify(marker) : "" } Expected completion at index ${index} to be ${name}, got ${completion.name}`); } this.verifyCompletionEntry(completion, expectedCompletion); }); @@ -4545,6 +4545,7 @@ namespace FourSlashInterface { export function globalTypesPlus(plus: ReadonlyArray): ReadonlyArray { return [ + { name: "globalThis", kind: "module" }, ...globalTypeDecls, ...plus, ...typeKeywords, @@ -4786,6 +4787,7 @@ namespace FourSlashInterface { export const globalsInsideFunction = (plus: ReadonlyArray): ReadonlyArray => [ { name: "arguments", kind: "local var" }, ...plus, + { name: "globalThis", kind: "module" }, ...globalsVars, { name: "undefined", kind: "var" }, ...globalKeywordsInsideFunction, @@ -4921,13 +4923,19 @@ namespace FourSlashInterface { })(); export const globals: ReadonlyArray = [ + { name: "globalThis", kind: "module" }, ...globalsVars, { name: "undefined", kind: "var" }, ...globalKeywords ]; export function globalsPlus(plus: ReadonlyArray): ReadonlyArray { - return [...globalsVars, ...plus, { name: "undefined", kind: "var" }, ...globalKeywords]; + return [ + { name: "globalThis", kind: "module" }, + ...globalsVars, + ...plus, + { name: "undefined", kind: "var" }, + ...globalKeywords]; } } diff --git a/src/services/completions.ts b/src/services/completions.ts index f17ee862ccaf8..a070bf8f7c1f0 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1030,7 +1030,7 @@ namespace ts.Completions { // Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions` if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== SyntaxKind.SourceFile) { - const thisType = typeChecker.tryGetThisTypeAt(scopeNode); + const thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false); if (thisType) { for (const symbol of getPropertiesForCompletion(thisType, typeChecker)) { symbolToOriginInfoMap[getSymbolId(symbol)] = { kind: SymbolOriginInfoKind.ThisType }; diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index e0728f98a29ba..1c710b8cd7838 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -310,7 +310,7 @@ namespace ts.SymbolDisplay { displayParts.push(spacePart()); addFullSymbolName(symbol); } - if (symbolFlags & SymbolFlags.Module) { + if (symbolFlags & SymbolFlags.Module && !isThisExpression) { prefixNextMeaning(); const declaration = getDeclarationOfKind(symbol, SyntaxKind.ModuleDeclaration); const isNamespace = declaration && declaration.name && declaration.name.kind === SyntaxKind.Identifier; diff --git a/src/testRunner/unittests/tsserver/projects.ts b/src/testRunner/unittests/tsserver/projects.ts index 3a648c9189e40..264dbff285ec5 100644 --- a/src/testRunner/unittests/tsserver/projects.ts +++ b/src/testRunner/unittests/tsserver/projects.ts @@ -708,7 +708,8 @@ namespace ts.projectSystem { // Check identifiers defined in HTML content are available in .ts file const project = configuredProjectAt(projectService, 0); let completions = project.getLanguageService().getCompletionsAtPosition(file1.path, 1, emptyOptions); - assert(completions && completions.entries[0].name === "hello", `expected entry hello to be in completion list`); + assert(completions && completions.entries[1].name === "hello", `expected entry hello to be in completion list`); + assert(completions && completions.entries[0].name === "globalThis", `first entry should be globalThis (not strictly relevant for this test).`); // Close HTML file projectService.applyChangesInOpenFiles( diff --git a/tests/baselines/reference/assignmentLHSIsValue.symbols b/tests/baselines/reference/assignmentLHSIsValue.symbols index 17925257dfb4b..aad2ec2ed95ef 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.symbols +++ b/tests/baselines/reference/assignmentLHSIsValue.symbols @@ -27,6 +27,7 @@ function foo() { this = value; } >value : Symbol(value, Decl(assignmentLHSIsValue.ts, 1, 3)) this = value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(assignmentLHSIsValue.ts, 1, 3)) // identifiers: module, class, enum, function @@ -116,6 +117,7 @@ foo() = value; // parentheses, the containted expression is value (this) = value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(assignmentLHSIsValue.ts, 1, 3)) (M) = value; diff --git a/tests/baselines/reference/assignmentLHSIsValue.types b/tests/baselines/reference/assignmentLHSIsValue.types index b35c15bfe2365..81fd5dc537b5a 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.types +++ b/tests/baselines/reference/assignmentLHSIsValue.types @@ -33,7 +33,7 @@ function foo() { this = value; } this = value; >this = value : any ->this : any +>this : typeof globalThis >value : any // identifiers: module, class, enum, function @@ -159,8 +159,8 @@ foo() = value; // parentheses, the containted expression is value (this) = value; >(this) = value : any ->(this) : any ->this : any +>(this) : typeof globalThis +>this : typeof globalThis >value : any (M) = value; diff --git a/tests/baselines/reference/castExpressionParentheses.symbols b/tests/baselines/reference/castExpressionParentheses.symbols index df7ef6a1f2f7f..ebc326e0a854b 100644 --- a/tests/baselines/reference/castExpressionParentheses.symbols +++ b/tests/baselines/reference/castExpressionParentheses.symbols @@ -21,7 +21,11 @@ declare var a; (null); // names and dotted names (this); +>this : Symbol(globalThis) + (this.x); +>this : Symbol(globalThis) + ((a).x); >a : Symbol(a, Decl(castExpressionParentheses.ts, 0, 11)) diff --git a/tests/baselines/reference/castExpressionParentheses.types b/tests/baselines/reference/castExpressionParentheses.types index db38aad5a47e4..a2d789577a018 100644 --- a/tests/baselines/reference/castExpressionParentheses.types +++ b/tests/baselines/reference/castExpressionParentheses.types @@ -77,13 +77,13 @@ declare var a; (this); >(this) : any >this : any ->this : any +>this : typeof globalThis (this.x); >(this.x) : any >this.x : any >this.x : any ->this : any +>this : typeof globalThis >x : any ((a).x); diff --git a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.symbols index b8904c087b308..29cb9d44b4998 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.symbols @@ -7,6 +7,7 @@ module a { } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndAliasInGlobal.ts, 3, 3)) +>this : Symbol(globalThis) import _this = a; // Error >_this : Symbol(_this, Decl(collisionThisExpressionAndAliasInGlobal.ts, 3, 19)) diff --git a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.types index 2bc6c89031972..1a4b1c9182114 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.types @@ -7,9 +7,9 @@ module a { >10 : 10 } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis import _this = a; // Error >_this : typeof a diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.symbols index 71aaa26e2ea44..ba225612d7383 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.symbols @@ -4,6 +4,7 @@ declare class _this { // no error - as no code generation } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndAmbientClassInGlobal.ts, 2, 3)) +>this : Symbol(globalThis) var a = new _this(); // Error >a : Symbol(a, Decl(collisionThisExpressionAndAmbientClassInGlobal.ts, 3, 3)) diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.types index ea0c8505fa0b2..886e0c70eea2a 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.types @@ -3,9 +3,9 @@ declare class _this { // no error - as no code generation >_this : _this } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis var a = new _this(); // Error >a : _this diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.symbols index 859234b35faa3..702a8300c3687 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.symbols @@ -4,6 +4,7 @@ declare var _this: number; // no error as no code gen var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndAmbientVarInGlobal.ts, 1, 3)) +>this : Symbol(globalThis) _this = 10; // Error >_this : Symbol(_this, Decl(collisionThisExpressionAndAmbientVarInGlobal.ts, 0, 11)) diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.types index c4038602bbae8..ed58281dfd687 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.types @@ -3,9 +3,9 @@ declare var _this: number; // no error as no code gen >_this : number var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis _this = 10; // Error >_this = 10 : 10 diff --git a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.symbols index 73781af4894f7..ba749b89ad089 100644 --- a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.symbols @@ -4,4 +4,5 @@ class _this { } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndClassInGlobal.ts, 2, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.types index 5e4cd6e0ab48e..f68d4212c1f47 100644 --- a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.types @@ -3,7 +3,7 @@ class _this { >_this : _this } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.symbols index 022b6487d026d..88723692ffdd8 100644 --- a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.symbols @@ -10,4 +10,5 @@ enum _this { // Error } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndEnumInGlobal.ts, 4, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.types index 87a28ada0e2b7..5be7877f4e92f 100644 --- a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.types @@ -9,7 +9,7 @@ enum _this { // Error >_thisVal2 : _this._thisVal2 } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.symbols index a5d171dbe9475..5461d86a0fcbb 100644 --- a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.symbols @@ -6,4 +6,5 @@ function _this() { //Error } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndFunctionInGlobal.ts, 3, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.types index bb0e11172cc2b..d3e4b57f58cd1 100644 --- a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.types @@ -6,7 +6,7 @@ function _this() { //Error >10 : 10 } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.symbols b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.symbols index 2105baf09a2d4..79bfda70d2887 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.symbols @@ -15,6 +15,7 @@ var x = { return callback(this); >callback : Symbol(callback, Decl(collisionThisExpressionAndLocalVarInLambda.ts, 3, 14)) +>this : Symbol(globalThis) } } alert(x.doStuff(x => alert(x))); diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.types b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.types index cbc625b36e1ce..d1f051e339cba 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.types +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.types @@ -20,7 +20,7 @@ var x = { return callback(this); >callback(this) : any >callback : any ->this : any +>this : typeof globalThis } } alert(x.doStuff(x => alert(x))); diff --git a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.symbols index 8dcb9dca6d20c..8cd392ac2687c 100644 --- a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.symbols @@ -8,4 +8,5 @@ module _this { //Error } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndModuleInGlobal.ts, 4, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.types index b950cda2d100c..ffa6fcb1a0237 100644 --- a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.types @@ -7,7 +7,7 @@ module _this { //Error } } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.symbols index 5895e29b2c235..9554f0013f942 100644 --- a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.symbols @@ -4,4 +4,5 @@ var _this = 1; var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndVarInGlobal.ts, 1, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.types index dd12ea635023a..a82334edc49e8 100644 --- a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.types @@ -4,7 +4,7 @@ var _this = 1; >1 : 1 var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/commentsInterface.symbols b/tests/baselines/reference/commentsInterface.symbols index 6e3a9e2797826..d98dae0c8938d 100644 --- a/tests/baselines/reference/commentsInterface.symbols +++ b/tests/baselines/reference/commentsInterface.symbols @@ -187,19 +187,25 @@ i3_i = { l: this.f, >l : Symbol(l, Decl(commentsInterface.ts, 56, 56)) +>this : Symbol(globalThis) /** own x*/ x: this.f(10), >x : Symbol(x, Decl(commentsInterface.ts, 57, 14)) +>this : Symbol(globalThis) nc_x: this.l(this.x), >nc_x : Symbol(nc_x, Decl(commentsInterface.ts, 59, 18)) +>this : Symbol(globalThis) +>this : Symbol(globalThis) nc_f: this.f, >nc_f : Symbol(nc_f, Decl(commentsInterface.ts, 60, 25)) +>this : Symbol(globalThis) nc_l: this.l >nc_l : Symbol(nc_l, Decl(commentsInterface.ts, 61, 17)) +>this : Symbol(globalThis) }; i3_i.f(10); diff --git a/tests/baselines/reference/commentsInterface.types b/tests/baselines/reference/commentsInterface.types index 65f1f5f4a38f0..97169b771d382 100644 --- a/tests/baselines/reference/commentsInterface.types +++ b/tests/baselines/reference/commentsInterface.types @@ -198,7 +198,7 @@ i3_i = { l: this.f, >l : any >this.f : any ->this : any +>this : typeof globalThis >f : any /** own x*/ @@ -206,7 +206,7 @@ i3_i = { >x : any >this.f(10) : any >this.f : any ->this : any +>this : typeof globalThis >f : any >10 : 10 @@ -214,22 +214,22 @@ i3_i = { >nc_x : any >this.l(this.x) : any >this.l : any ->this : any +>this : typeof globalThis >l : any >this.x : any ->this : any +>this : typeof globalThis >x : any nc_f: this.f, >nc_f : any >this.f : any ->this : any +>this : typeof globalThis >f : any nc_l: this.l >nc_l : any >this.l : any ->this : any +>this : typeof globalThis >l : any }; diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt index 8a13314800787..2c22361bfd637 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt @@ -6,7 +6,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(16,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(21,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(22,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(25,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(25,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(26,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(30,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(31,1): error TS2539: Cannot assign to 'M' because it is not a variable. @@ -45,7 +45,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(88,11): error TS1005: ';' expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(91,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(92,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(95,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(95,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(96,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(97,2): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(98,2): error TS2539: Cannot assign to 'M' because it is not a variable. @@ -119,7 +119,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa this *= value; ~~~~ -!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. this += value; ~~~~ !!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. @@ -267,7 +267,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa // parentheses, the containted expression is value (this) *= value; ~~~~~~ -!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. (this) += value; ~~~~~~ !!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.symbols b/tests/baselines/reference/compoundAssignmentLHSIsValue.symbols index 790c05ed9a124..891127c32cc2b 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.symbols +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.symbols @@ -51,9 +51,11 @@ function foo() { } this *= value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundAssignmentLHSIsValue.ts, 1, 3)) this += value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundAssignmentLHSIsValue.ts, 1, 3)) // identifiers: module, class, enum, function @@ -216,9 +218,11 @@ foo() += value; // parentheses, the containted expression is value (this) *= value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundAssignmentLHSIsValue.ts, 1, 3)) (this) += value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundAssignmentLHSIsValue.ts, 1, 3)) (M) *= value; diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.types b/tests/baselines/reference/compoundAssignmentLHSIsValue.types index 7736256f97356..5aafaa2647c64 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.types +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.types @@ -62,12 +62,12 @@ function foo() { this *= value; >this *= value : number ->this : any +>this : typeof globalThis >value : any this += value; >this += value : any ->this : any +>this : typeof globalThis >value : any // identifiers: module, class, enum, function @@ -300,14 +300,14 @@ foo() += value; // parentheses, the containted expression is value (this) *= value; >(this) *= value : number ->(this) : any ->this : any +>(this) : typeof globalThis +>this : typeof globalThis >value : any (this) += value; >(this) += value : any ->(this) : any ->this : any +>(this) : typeof globalThis +>this : typeof globalThis >value : any (M) *= value; diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt index e3c9918aa4b46..37e9ca6be1de0 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(10,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(13,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(18,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(21,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(21,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(25,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(27,1): error TS2539: Cannot assign to 'C' because it is not a variable. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(30,1): error TS2539: Cannot assign to 'E' because it is not a variable. @@ -22,7 +22,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(65,21): error TS1128: Declaration or statement expected. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(66,11): error TS1005: ';' expected. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(69,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(72,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(72,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(73,2): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(74,2): error TS2539: Cannot assign to 'C' because it is not a variable. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(75,2): error TS2539: Cannot assign to 'E' because it is not a variable. @@ -70,7 +70,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm this **= value; ~~~~ -!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. // identifiers: module, class, enum, function module M { export var a; } @@ -161,7 +161,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm // parentheses, the containted expression is value (this) **= value; ~~~~~~ -!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. (M) **= value; ~ !!! error TS2539: Cannot assign to 'M' because it is not a variable. diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.symbols b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.symbols index 7e85139b7a89f..5596f648979e3 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.symbols +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.symbols @@ -36,6 +36,7 @@ function foo() { } this **= value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundExponentiationAssignmentLHSIsValue.ts, 1, 3)) // identifiers: module, class, enum, function @@ -135,6 +136,7 @@ foo() **= value; // parentheses, the containted expression is value (this) **= value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundExponentiationAssignmentLHSIsValue.ts, 1, 3)) (M) **= value; diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.types b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.types index 982b6b2bdee9e..58ec77add862e 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.types +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.types @@ -42,7 +42,7 @@ function foo() { this **= value; >this **= value : number ->this : any +>this : typeof globalThis >value : any // identifiers: module, class, enum, function @@ -178,8 +178,8 @@ foo() **= value; // parentheses, the containted expression is value (this) **= value; >(this) **= value : number ->(this) : any ->this : any +>(this) : typeof globalThis +>this : typeof globalThis >value : any (M) **= value; diff --git a/tests/baselines/reference/computedPropertyNames20_ES5.symbols b/tests/baselines/reference/computedPropertyNames20_ES5.symbols index 2b249fd8f9507..3ac422d6e73c0 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES5.symbols +++ b/tests/baselines/reference/computedPropertyNames20_ES5.symbols @@ -4,4 +4,5 @@ var obj = { [this.bar]: 0 >[this.bar] : Symbol([this.bar], Decl(computedPropertyNames20_ES5.ts, 0, 11)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/computedPropertyNames20_ES5.types b/tests/baselines/reference/computedPropertyNames20_ES5.types index cc0614b3d0b45..7a95872481129 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES5.types +++ b/tests/baselines/reference/computedPropertyNames20_ES5.types @@ -6,7 +6,7 @@ var obj = { [this.bar]: 0 >[this.bar] : number >this.bar : any ->this : any +>this : typeof globalThis >bar : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames20_ES6.symbols b/tests/baselines/reference/computedPropertyNames20_ES6.symbols index ffd5645ccd6f3..62c934426fdb1 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES6.symbols +++ b/tests/baselines/reference/computedPropertyNames20_ES6.symbols @@ -4,4 +4,5 @@ var obj = { [this.bar]: 0 >[this.bar] : Symbol([this.bar], Decl(computedPropertyNames20_ES6.ts, 0, 11)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/computedPropertyNames20_ES6.types b/tests/baselines/reference/computedPropertyNames20_ES6.types index 5ffc037860e99..516559e3e3eeb 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES6.types +++ b/tests/baselines/reference/computedPropertyNames20_ES6.types @@ -6,7 +6,7 @@ var obj = { [this.bar]: 0 >[this.bar] : number >this.bar : any ->this : any +>this : typeof globalThis >bar : any >0 : 0 } diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.symbols b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.symbols index c5f1afffb2f5f..f7e719e39d3e3 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.symbols +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.symbols @@ -579,6 +579,7 @@ module TypeScriptAllInOne { } public method2() { return 2 * this.method1(2); +>this : Symbol(globalThis) } } diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.types b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.types index c4428efcd4dad..affae0f3108fb 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.types +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.types @@ -869,7 +869,7 @@ module TypeScriptAllInOne { >2 : 2 >this.method1(2) : any >this.method1 : any ->this : any +>this : typeof globalThis >method1 : any >2 : 2 } diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturing.errors.txt b/tests/baselines/reference/emitArrowFunctionThisCapturing.errors.txt new file mode 100644 index 0000000000000..2030b47b3ec6e --- /dev/null +++ b/tests/baselines/reference/emitArrowFunctionThisCapturing.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturing.ts(6,10): error TS2540: Cannot assign to 'name' because it is a read-only property. + + +==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturing.ts (1 errors) ==== + var f1 = () => { + this.age = 10 + }; + + var f2 = (x: string) => { + this.name = x + ~~~~ +!!! error TS2540: Cannot assign to 'name' because it is a read-only property. + } + + function foo(func: () => boolean) { } + foo(() => { + this.age = 100; + return true; + }); + \ No newline at end of file diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturing.symbols b/tests/baselines/reference/emitArrowFunctionThisCapturing.symbols index ad62a0df5be92..e130eafd77095 100644 --- a/tests/baselines/reference/emitArrowFunctionThisCapturing.symbols +++ b/tests/baselines/reference/emitArrowFunctionThisCapturing.symbols @@ -3,6 +3,8 @@ var f1 = () => { >f1 : Symbol(f1, Decl(emitArrowFunctionThisCapturing.ts, 0, 3)) this.age = 10 +>this : Symbol(globalThis) + }; var f2 = (x: string) => { @@ -10,6 +12,9 @@ var f2 = (x: string) => { >x : Symbol(x, Decl(emitArrowFunctionThisCapturing.ts, 4, 10)) this.name = x +>this.name : Symbol(name, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>name : Symbol(name, Decl(lib.dom.d.ts, --, --)) >x : Symbol(x, Decl(emitArrowFunctionThisCapturing.ts, 4, 10)) } @@ -21,6 +26,8 @@ foo(() => { >foo : Symbol(foo, Decl(emitArrowFunctionThisCapturing.ts, 6, 1)) this.age = 100; +>this : Symbol(globalThis) + return true; }); diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturing.types b/tests/baselines/reference/emitArrowFunctionThisCapturing.types index 0ef27791d1765..8edaa3141da7f 100644 --- a/tests/baselines/reference/emitArrowFunctionThisCapturing.types +++ b/tests/baselines/reference/emitArrowFunctionThisCapturing.types @@ -6,7 +6,7 @@ var f1 = () => { this.age = 10 >this.age = 10 : 10 >this.age : any ->this : any +>this : typeof globalThis >age : any >10 : 10 @@ -20,7 +20,7 @@ var f2 = (x: string) => { this.name = x >this.name = x : string >this.name : any ->this : any +>this : typeof globalThis >name : any >x : string } @@ -37,7 +37,7 @@ foo(() => { this.age = 100; >this.age = 100 : 100 >this.age : any ->this : any +>this : typeof globalThis >age : any >100 : 100 diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.errors.txt b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.errors.txt new file mode 100644 index 0000000000000..fb644a4127e47 --- /dev/null +++ b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturingES6.ts(6,10): error TS2540: Cannot assign to 'name' because it is a read-only property. + + +==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturingES6.ts (1 errors) ==== + var f1 = () => { + this.age = 10 + }; + + var f2 = (x: string) => { + this.name = x + ~~~~ +!!! error TS2540: Cannot assign to 'name' because it is a read-only property. + } + + function foo(func: () => boolean){ } + foo(() => { + this.age = 100; + return true; + }); + \ No newline at end of file diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.symbols b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.symbols index 0e8855dd680c5..d370a207de69d 100644 --- a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.symbols @@ -3,6 +3,8 @@ var f1 = () => { >f1 : Symbol(f1, Decl(emitArrowFunctionThisCapturingES6.ts, 0, 3)) this.age = 10 +>this : Symbol(globalThis) + }; var f2 = (x: string) => { @@ -10,6 +12,9 @@ var f2 = (x: string) => { >x : Symbol(x, Decl(emitArrowFunctionThisCapturingES6.ts, 4, 10)) this.name = x +>this.name : Symbol(name, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>name : Symbol(name, Decl(lib.dom.d.ts, --, --)) >x : Symbol(x, Decl(emitArrowFunctionThisCapturingES6.ts, 4, 10)) } @@ -21,6 +26,8 @@ foo(() => { >foo : Symbol(foo, Decl(emitArrowFunctionThisCapturingES6.ts, 6, 1)) this.age = 100; +>this : Symbol(globalThis) + return true; }); diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.types b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.types index 3c20bfd195cd2..c57317ec5bfb8 100644 --- a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.types +++ b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.types @@ -6,7 +6,7 @@ var f1 = () => { this.age = 10 >this.age = 10 : 10 >this.age : any ->this : any +>this : typeof globalThis >age : any >10 : 10 @@ -20,7 +20,7 @@ var f2 = (x: string) => { this.name = x >this.name = x : string >this.name : any ->this : any +>this : typeof globalThis >name : any >x : string } @@ -37,7 +37,7 @@ foo(() => { this.age = 100; >this.age = 100 : 100 >this.age : any ->this : any +>this : typeof globalThis >age : any >100 : 100 diff --git a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.symbols b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.symbols index 6bd13ccfd470b..bfef6d5b3e3a1 100644 --- a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.symbols +++ b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.symbols @@ -8,6 +8,9 @@ wrapper((array: [any]) => { >array : Symbol(array, Decl(emitCapturingThisInTupleDestructuring1.ts, 1, 9)) [this.test, this.test1, this.test2] = array; // even though there is a compiler error, we should still emit lexical capture for "this" +>this : Symbol(globalThis) +>this : Symbol(globalThis) +>this : Symbol(globalThis) >array : Symbol(array, Decl(emitCapturingThisInTupleDestructuring1.ts, 1, 9)) }); diff --git a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.types b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.types index 7e9f03780caba..9cd06b6b5600b 100644 --- a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.types +++ b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.types @@ -13,13 +13,13 @@ wrapper((array: [any]) => { >[this.test, this.test1, this.test2] = array : [any] >[this.test, this.test1, this.test2] : [any, any, any] >this.test : any ->this : any +>this : typeof globalThis >test : any >this.test1 : any ->this : any +>this : typeof globalThis >test1 : any >this.test2 : any ->this : any +>this : typeof globalThis >test2 : any >array : [any] diff --git a/tests/baselines/reference/globalThisCapture.symbols b/tests/baselines/reference/globalThisCapture.symbols index bfb7bf147c0a4..9ece286c98f29 100644 --- a/tests/baselines/reference/globalThisCapture.symbols +++ b/tests/baselines/reference/globalThisCapture.symbols @@ -1,6 +1,9 @@ === tests/cases/compiler/globalThisCapture.ts === // Add a lambda to ensure global 'this' capture is triggered (()=>this.window); +>this.window : Symbol(window, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) var parts = []; >parts : Symbol(parts, Decl(globalThisCapture.ts, 3, 3)) diff --git a/tests/baselines/reference/globalThisCapture.types b/tests/baselines/reference/globalThisCapture.types index 063100ff78eaf..43a061382282c 100644 --- a/tests/baselines/reference/globalThisCapture.types +++ b/tests/baselines/reference/globalThisCapture.types @@ -1,11 +1,11 @@ === tests/cases/compiler/globalThisCapture.ts === // Add a lambda to ensure global 'this' capture is triggered (()=>this.window); ->(()=>this.window) : () => any ->()=>this.window : () => any ->this.window : any ->this : any ->window : any +>(()=>this.window) : () => Window +>()=>this.window : () => Window +>this.window : Window +>this : typeof globalThis +>window : Window var parts = []; >parts : any[] diff --git a/tests/baselines/reference/globalThisPropertyAssignment.errors.txt b/tests/baselines/reference/globalThisPropertyAssignment.errors.txt new file mode 100644 index 0000000000000..a02824415ae34 --- /dev/null +++ b/tests/baselines/reference/globalThisPropertyAssignment.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es2019/globalThisPropertyAssignment.js(4,8): error TS2339: Property 'z' does not exist on type 'Window'. + + +==== tests/cases/conformance/es2019/globalThisPropertyAssignment.js (1 errors) ==== + this.x = 1 + var y = 2 + // should work in JS + window.z = 3 + ~ +!!! error TS2339: Property 'z' does not exist on type 'Window'. + // should work in JS (even though it's a secondary declaration) + globalThis.alpha = 4 + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisPropertyAssignment.symbols b/tests/baselines/reference/globalThisPropertyAssignment.symbols new file mode 100644 index 0000000000000..1ae4dd5af6387 --- /dev/null +++ b/tests/baselines/reference/globalThisPropertyAssignment.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es2019/globalThisPropertyAssignment.js === +this.x = 1 +>this.x : Symbol(x, Decl(globalThisPropertyAssignment.js, 0, 0)) +>this : Symbol(globalThis) +>x : Symbol(x, Decl(globalThisPropertyAssignment.js, 0, 0)) + +var y = 2 +>y : Symbol(y, Decl(globalThisPropertyAssignment.js, 1, 3)) + +// should work in JS +window.z = 3 +>window : Symbol(window, Decl(lib.dom.d.ts, --, --), Decl(globalThisPropertyAssignment.js, 1, 9)) + +// should work in JS (even though it's a secondary declaration) +globalThis.alpha = 4 +>globalThis.alpha : Symbol(alpha, Decl(globalThisPropertyAssignment.js, 3, 12)) +>globalThis : Symbol(globalThis) +>alpha : Symbol(alpha, Decl(globalThisPropertyAssignment.js, 3, 12)) + diff --git a/tests/baselines/reference/globalThisPropertyAssignment.types b/tests/baselines/reference/globalThisPropertyAssignment.types new file mode 100644 index 0000000000000..6be55e136b0b5 --- /dev/null +++ b/tests/baselines/reference/globalThisPropertyAssignment.types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2019/globalThisPropertyAssignment.js === +this.x = 1 +>this.x = 1 : 1 +>this.x : number +>this : typeof globalThis +>x : number +>1 : 1 + +var y = 2 +>y : number +>2 : 2 + +// should work in JS +window.z = 3 +>window.z = 3 : 3 +>window.z : any +>window : Window +>z : any +>3 : 3 + +// should work in JS (even though it's a secondary declaration) +globalThis.alpha = 4 +>globalThis.alpha = 4 : 4 +>globalThis.alpha : number +>globalThis : typeof globalThis +>alpha : number +>4 : 4 + diff --git a/tests/baselines/reference/globalThisReadonlyProperties.errors.txt b/tests/baselines/reference/globalThisReadonlyProperties.errors.txt new file mode 100644 index 0000000000000..925cf90a10c77 --- /dev/null +++ b/tests/baselines/reference/globalThisReadonlyProperties.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es2019/globalThisReadonlyProperties.ts(1,12): error TS2540: Cannot assign to 'globalThis' because it is a read-only property. +tests/cases/conformance/es2019/globalThisReadonlyProperties.ts(5,12): error TS2540: Cannot assign to 'y' because it is a read-only property. + + +==== tests/cases/conformance/es2019/globalThisReadonlyProperties.ts (2 errors) ==== + globalThis.globalThis = 1 as any // should error + ~~~~~~~~~~ +!!! error TS2540: Cannot assign to 'globalThis' because it is a read-only property. + var x = 1 + const y = 2 + globalThis.x = 3 + globalThis.y = 4 // should error + ~ +!!! error TS2540: Cannot assign to 'y' because it is a read-only property. + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisReadonlyProperties.js b/tests/baselines/reference/globalThisReadonlyProperties.js new file mode 100644 index 0000000000000..3012608a125c1 --- /dev/null +++ b/tests/baselines/reference/globalThisReadonlyProperties.js @@ -0,0 +1,14 @@ +//// [globalThisReadonlyProperties.ts] +globalThis.globalThis = 1 as any // should error +var x = 1 +const y = 2 +globalThis.x = 3 +globalThis.y = 4 // should error + + +//// [globalThisReadonlyProperties.js] +globalThis.globalThis = 1; // should error +var x = 1; +var y = 2; +globalThis.x = 3; +globalThis.y = 4; // should error diff --git a/tests/baselines/reference/globalThisReadonlyProperties.symbols b/tests/baselines/reference/globalThisReadonlyProperties.symbols new file mode 100644 index 0000000000000..df59ee45ca36a --- /dev/null +++ b/tests/baselines/reference/globalThisReadonlyProperties.symbols @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es2019/globalThisReadonlyProperties.ts === +globalThis.globalThis = 1 as any // should error +>globalThis.globalThis : Symbol(globalThis) +>globalThis : Symbol(globalThis) +>globalThis : Symbol(globalThis) + +var x = 1 +>x : Symbol(x, Decl(globalThisReadonlyProperties.ts, 1, 3)) + +const y = 2 +>y : Symbol(y, Decl(globalThisReadonlyProperties.ts, 2, 5)) + +globalThis.x = 3 +>globalThis.x : Symbol(x, Decl(globalThisReadonlyProperties.ts, 1, 3)) +>globalThis : Symbol(globalThis) +>x : Symbol(x, Decl(globalThisReadonlyProperties.ts, 1, 3)) + +globalThis.y = 4 // should error +>globalThis.y : Symbol(y, Decl(globalThisReadonlyProperties.ts, 2, 5)) +>globalThis : Symbol(globalThis) +>y : Symbol(y, Decl(globalThisReadonlyProperties.ts, 2, 5)) + diff --git a/tests/baselines/reference/globalThisReadonlyProperties.types b/tests/baselines/reference/globalThisReadonlyProperties.types new file mode 100644 index 0000000000000..05b3d7c84e8f1 --- /dev/null +++ b/tests/baselines/reference/globalThisReadonlyProperties.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/es2019/globalThisReadonlyProperties.ts === +globalThis.globalThis = 1 as any // should error +>globalThis.globalThis = 1 as any : any +>globalThis.globalThis : any +>globalThis : typeof globalThis +>globalThis : any +>1 as any : any +>1 : 1 + +var x = 1 +>x : number +>1 : 1 + +const y = 2 +>y : 2 +>2 : 2 + +globalThis.x = 3 +>globalThis.x = 3 : 3 +>globalThis.x : number +>globalThis : typeof globalThis +>x : number +>3 : 3 + +globalThis.y = 4 // should error +>globalThis.y = 4 : 4 +>globalThis.y : any +>globalThis : typeof globalThis +>y : any +>4 : 4 + diff --git a/tests/baselines/reference/globalThisTypeIndexAccess.js b/tests/baselines/reference/globalThisTypeIndexAccess.js new file mode 100644 index 0000000000000..aef5c97ed9a91 --- /dev/null +++ b/tests/baselines/reference/globalThisTypeIndexAccess.js @@ -0,0 +1,5 @@ +//// [globalThisTypeIndexAccess.ts] +declare const w_e: (typeof globalThis)["globalThis"] + + +//// [globalThisTypeIndexAccess.js] diff --git a/tests/baselines/reference/globalThisTypeIndexAccess.symbols b/tests/baselines/reference/globalThisTypeIndexAccess.symbols new file mode 100644 index 0000000000000..460867fb1f133 --- /dev/null +++ b/tests/baselines/reference/globalThisTypeIndexAccess.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts === +declare const w_e: (typeof globalThis)["globalThis"] +>w_e : Symbol(w_e, Decl(globalThisTypeIndexAccess.ts, 0, 13)) +>globalThis : Symbol(globalThis) + diff --git a/tests/baselines/reference/globalThisTypeIndexAccess.types b/tests/baselines/reference/globalThisTypeIndexAccess.types new file mode 100644 index 0000000000000..c290b74407185 --- /dev/null +++ b/tests/baselines/reference/globalThisTypeIndexAccess.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts === +declare const w_e: (typeof globalThis)["globalThis"] +>w_e : typeof globalThis +>globalThis : typeof globalThis + diff --git a/tests/baselines/reference/globalThisUnknown.errors.txt b/tests/baselines/reference/globalThisUnknown.errors.txt new file mode 100644 index 0000000000000..fc9a8485b6479 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknown.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es2019/globalThisUnknown.ts(4,5): error TS2339: Property 'hi' does not exist on type 'Window & typeof globalThis'. + + +==== tests/cases/conformance/es2019/globalThisUnknown.ts (1 errors) ==== + declare let win: Window & typeof globalThis; + + // this access should be an error + win.hi + ~~ +!!! error TS2339: Property 'hi' does not exist on type 'Window & typeof globalThis'. + // these two should be fine, with type any + this.hi + globalThis.hi + + // element access is always ok without noImplicitAny + win['hi'] + this['hi'] + globalThis['hi'] + + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisUnknown.js b/tests/baselines/reference/globalThisUnknown.js new file mode 100644 index 0000000000000..9763100c1291b --- /dev/null +++ b/tests/baselines/reference/globalThisUnknown.js @@ -0,0 +1,26 @@ +//// [globalThisUnknown.ts] +declare let win: Window & typeof globalThis; + +// this access should be an error +win.hi +// these two should be fine, with type any +this.hi +globalThis.hi + +// element access is always ok without noImplicitAny +win['hi'] +this['hi'] +globalThis['hi'] + + + +//// [globalThisUnknown.js] +// this access should be an error +win.hi; +// these two should be fine, with type any +this.hi; +globalThis.hi; +// element access is always ok without noImplicitAny +win['hi']; +this['hi']; +globalThis['hi']; diff --git a/tests/baselines/reference/globalThisUnknown.symbols b/tests/baselines/reference/globalThisUnknown.symbols new file mode 100644 index 0000000000000..4f8437bf244fd --- /dev/null +++ b/tests/baselines/reference/globalThisUnknown.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2019/globalThisUnknown.ts === +declare let win: Window & typeof globalThis; +>win : Symbol(win, Decl(globalThisUnknown.ts, 0, 11)) +>Window : Symbol(Window, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>globalThis : Symbol(globalThis) + +// this access should be an error +win.hi +>win : Symbol(win, Decl(globalThisUnknown.ts, 0, 11)) + +// these two should be fine, with type any +this.hi +>this : Symbol(globalThis) + +globalThis.hi +>globalThis : Symbol(globalThis) + +// element access is always ok without noImplicitAny +win['hi'] +>win : Symbol(win, Decl(globalThisUnknown.ts, 0, 11)) + +this['hi'] +>this : Symbol(globalThis) + +globalThis['hi'] +>globalThis : Symbol(globalThis) + + diff --git a/tests/baselines/reference/globalThisUnknown.types b/tests/baselines/reference/globalThisUnknown.types new file mode 100644 index 0000000000000..42ac606ec549b --- /dev/null +++ b/tests/baselines/reference/globalThisUnknown.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2019/globalThisUnknown.ts === +declare let win: Window & typeof globalThis; +>win : Window & typeof globalThis +>globalThis : typeof globalThis + +// this access should be an error +win.hi +>win.hi : any +>win : Window & typeof globalThis +>hi : any + +// these two should be fine, with type any +this.hi +>this.hi : any +>this : typeof globalThis +>hi : any + +globalThis.hi +>globalThis.hi : any +>globalThis : typeof globalThis +>hi : any + +// element access is always ok without noImplicitAny +win['hi'] +>win['hi'] : any +>win : Window & typeof globalThis +>'hi' : "hi" + +this['hi'] +>this['hi'] : any +>this : typeof globalThis +>'hi' : "hi" + +globalThis['hi'] +>globalThis['hi'] : any +>globalThis : typeof globalThis +>'hi' : "hi" + + diff --git a/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt b/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt new file mode 100644 index 0000000000000..fc5e91de594be --- /dev/null +++ b/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt @@ -0,0 +1,32 @@ +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(4,5): error TS2339: Property 'hi' does not exist on type 'Window & typeof globalThis'. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(5,6): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(6,12): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(8,1): error TS7017: Element implicitly has an 'any' type because type 'Window & typeof globalThis' has no index signature. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(9,1): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(10,1): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + + +==== tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts (6 errors) ==== + declare let win: Window & typeof globalThis; + + // all accesses should be errors + win.hi + ~~ +!!! error TS2339: Property 'hi' does not exist on type 'Window & typeof globalThis'. + this.hi + ~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + globalThis.hi + ~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + + win['hi'] + ~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'Window & typeof globalThis' has no index signature. + this['hi'] + ~~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + globalThis['hi'] + ~~~~~~~~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisUnknownNoImplicitAny.js b/tests/baselines/reference/globalThisUnknownNoImplicitAny.js new file mode 100644 index 0000000000000..cc1952e0afc19 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknownNoImplicitAny.js @@ -0,0 +1,21 @@ +//// [globalThisUnknownNoImplicitAny.ts] +declare let win: Window & typeof globalThis; + +// all accesses should be errors +win.hi +this.hi +globalThis.hi + +win['hi'] +this['hi'] +globalThis['hi'] + + +//// [globalThisUnknownNoImplicitAny.js] +// all accesses should be errors +win.hi; +this.hi; +globalThis.hi; +win['hi']; +this['hi']; +globalThis['hi']; diff --git a/tests/baselines/reference/globalThisUnknownNoImplicitAny.symbols b/tests/baselines/reference/globalThisUnknownNoImplicitAny.symbols new file mode 100644 index 0000000000000..6aee6d6051c61 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknownNoImplicitAny.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts === +declare let win: Window & typeof globalThis; +>win : Symbol(win, Decl(globalThisUnknownNoImplicitAny.ts, 0, 11)) +>Window : Symbol(Window, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>globalThis : Symbol(globalThis) + +// all accesses should be errors +win.hi +>win : Symbol(win, Decl(globalThisUnknownNoImplicitAny.ts, 0, 11)) + +this.hi +>this : Symbol(globalThis) + +globalThis.hi +>globalThis : Symbol(globalThis) + +win['hi'] +>win : Symbol(win, Decl(globalThisUnknownNoImplicitAny.ts, 0, 11)) + +this['hi'] +>this : Symbol(globalThis) + +globalThis['hi'] +>globalThis : Symbol(globalThis) + diff --git a/tests/baselines/reference/globalThisUnknownNoImplicitAny.types b/tests/baselines/reference/globalThisUnknownNoImplicitAny.types new file mode 100644 index 0000000000000..19611a785b462 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknownNoImplicitAny.types @@ -0,0 +1,36 @@ +=== tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts === +declare let win: Window & typeof globalThis; +>win : Window & typeof globalThis +>globalThis : typeof globalThis + +// all accesses should be errors +win.hi +>win.hi : any +>win : Window & typeof globalThis +>hi : any + +this.hi +>this.hi : any +>this : typeof globalThis +>hi : any + +globalThis.hi +>globalThis.hi : any +>globalThis : typeof globalThis +>hi : any + +win['hi'] +>win['hi'] : any +>win : Window & typeof globalThis +>'hi' : "hi" + +this['hi'] +>this['hi'] : any +>this : typeof globalThis +>'hi' : "hi" + +globalThis['hi'] +>globalThis['hi'] : any +>globalThis : typeof globalThis +>'hi' : "hi" + diff --git a/tests/baselines/reference/globalThisVarDeclaration.errors.txt b/tests/baselines/reference/globalThisVarDeclaration.errors.txt new file mode 100644 index 0000000000000..daf2349c6b0a3 --- /dev/null +++ b/tests/baselines/reference/globalThisVarDeclaration.errors.txt @@ -0,0 +1,69 @@ +tests/cases/conformance/es2019/actual.ts(8,6): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(9,6): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(10,8): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(11,8): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(12,5): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(13,5): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(8,6): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(9,6): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(10,8): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(11,8): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(12,5): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(13,5): error TS2339: Property 'b' does not exist on type 'Window'. + + +==== tests/cases/conformance/es2019/b.js (6 errors) ==== + var a = 10; + this.a; + this.b; + globalThis.a; + globalThis.b; + + // DOM access is not supported until the index signature is handled more strictly + self.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + self.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + window.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + window.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + top.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + top.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + +==== tests/cases/conformance/es2019/actual.ts (6 errors) ==== + var b = 10; + this.a; + this.b; + globalThis.a; + globalThis.b; + + // same here -- no DOM access to globalThis yet + self.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + self.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + window.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + window.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + top.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + top.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisVarDeclaration.js b/tests/baselines/reference/globalThisVarDeclaration.js new file mode 100644 index 0000000000000..2ae75af703ebc --- /dev/null +++ b/tests/baselines/reference/globalThisVarDeclaration.js @@ -0,0 +1,59 @@ +//// [tests/cases/conformance/es2019/globalThisVarDeclaration.ts] //// + +//// [b.js] +var a = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; + +// DOM access is not supported until the index signature is handled more strictly +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; + +//// [actual.ts] +var b = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; + +// same here -- no DOM access to globalThis yet +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; + + + +//// [output.js] +var a = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; +// DOM access is not supported until the index signature is handled more strictly +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; +var b = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; +// same here -- no DOM access to globalThis yet +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; diff --git a/tests/baselines/reference/globalThisVarDeclaration.symbols b/tests/baselines/reference/globalThisVarDeclaration.symbols new file mode 100644 index 0000000000000..b2d7feb37fd75 --- /dev/null +++ b/tests/baselines/reference/globalThisVarDeclaration.symbols @@ -0,0 +1,87 @@ +=== tests/cases/conformance/es2019/b.js === +var a = 10; +>a : Symbol(a, Decl(b.js, 0, 3)) + +this.a; +>this.a : Symbol(a, Decl(b.js, 0, 3)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(b.js, 0, 3)) + +this.b; +>this.b : Symbol(b, Decl(actual.ts, 0, 3)) +>this : Symbol(globalThis) +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +globalThis.a; +>globalThis.a : Symbol(a, Decl(b.js, 0, 3)) +>globalThis : Symbol(globalThis) +>a : Symbol(a, Decl(b.js, 0, 3)) + +globalThis.b; +>globalThis.b : Symbol(b, Decl(actual.ts, 0, 3)) +>globalThis : Symbol(globalThis) +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +// DOM access is not supported until the index signature is handled more strictly +self.a; +>self : Symbol(self, Decl(lib.dom.d.ts, --, --)) + +self.b; +>self : Symbol(self, Decl(lib.dom.d.ts, --, --)) + +window.a; +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) + +window.b; +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) + +top.a; +>top : Symbol(top, Decl(lib.dom.d.ts, --, --)) + +top.b; +>top : Symbol(top, Decl(lib.dom.d.ts, --, --)) + +=== tests/cases/conformance/es2019/actual.ts === +var b = 10; +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +this.a; +>this.a : Symbol(a, Decl(b.js, 0, 3)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(b.js, 0, 3)) + +this.b; +>this.b : Symbol(b, Decl(actual.ts, 0, 3)) +>this : Symbol(globalThis) +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +globalThis.a; +>globalThis.a : Symbol(a, Decl(b.js, 0, 3)) +>globalThis : Symbol(globalThis) +>a : Symbol(a, Decl(b.js, 0, 3)) + +globalThis.b; +>globalThis.b : Symbol(b, Decl(actual.ts, 0, 3)) +>globalThis : Symbol(globalThis) +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +// same here -- no DOM access to globalThis yet +self.a; +>self : Symbol(self, Decl(lib.dom.d.ts, --, --)) + +self.b; +>self : Symbol(self, Decl(lib.dom.d.ts, --, --)) + +window.a; +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) + +window.b; +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) + +top.a; +>top : Symbol(top, Decl(lib.dom.d.ts, --, --)) + +top.b; +>top : Symbol(top, Decl(lib.dom.d.ts, --, --)) + + diff --git a/tests/baselines/reference/globalThisVarDeclaration.types b/tests/baselines/reference/globalThisVarDeclaration.types new file mode 100644 index 0000000000000..9c520f667dcf2 --- /dev/null +++ b/tests/baselines/reference/globalThisVarDeclaration.types @@ -0,0 +1,113 @@ +=== tests/cases/conformance/es2019/b.js === +var a = 10; +>a : number +>10 : 10 + +this.a; +>this.a : number +>this : typeof globalThis +>a : number + +this.b; +>this.b : number +>this : typeof globalThis +>b : number + +globalThis.a; +>globalThis.a : number +>globalThis : typeof globalThis +>a : number + +globalThis.b; +>globalThis.b : number +>globalThis : typeof globalThis +>b : number + +// DOM access is not supported until the index signature is handled more strictly +self.a; +>self.a : any +>self : Window +>a : any + +self.b; +>self.b : any +>self : Window +>b : any + +window.a; +>window.a : any +>window : Window +>a : any + +window.b; +>window.b : any +>window : Window +>b : any + +top.a; +>top.a : any +>top : Window +>a : any + +top.b; +>top.b : any +>top : Window +>b : any + +=== tests/cases/conformance/es2019/actual.ts === +var b = 10; +>b : number +>10 : 10 + +this.a; +>this.a : number +>this : typeof globalThis +>a : number + +this.b; +>this.b : number +>this : typeof globalThis +>b : number + +globalThis.a; +>globalThis.a : number +>globalThis : typeof globalThis +>a : number + +globalThis.b; +>globalThis.b : number +>globalThis : typeof globalThis +>b : number + +// same here -- no DOM access to globalThis yet +self.a; +>self.a : any +>self : Window +>a : any + +self.b; +>self.b : any +>self : Window +>b : any + +window.a; +>window.a : any +>window : Window +>a : any + +window.b; +>window.b : any +>window : Window +>b : any + +top.a; +>top.a : any +>top : Window +>a : any + +top.b; +>top.b : any +>top : Window +>b : any + + diff --git a/tests/baselines/reference/implicitAnyInCatch.symbols b/tests/baselines/reference/implicitAnyInCatch.symbols index 7ce3ac40f369d..4f09ecdcbe5c8 100644 --- a/tests/baselines/reference/implicitAnyInCatch.symbols +++ b/tests/baselines/reference/implicitAnyInCatch.symbols @@ -8,6 +8,7 @@ try { } catch (error) { } for (var key in this) { } >key : Symbol(key, Decl(implicitAnyInCatch.ts, 4, 8)) +>this : Symbol(globalThis) class C { >C : Symbol(C, Decl(implicitAnyInCatch.ts, 4, 25)) diff --git a/tests/baselines/reference/implicitAnyInCatch.types b/tests/baselines/reference/implicitAnyInCatch.types index 6f70165407f99..5619ec536224f 100644 --- a/tests/baselines/reference/implicitAnyInCatch.types +++ b/tests/baselines/reference/implicitAnyInCatch.types @@ -13,7 +13,7 @@ try { } catch (error) { } for (var key in this) { } >key : string ->this : any +>this : typeof globalThis class C { >C : C diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols index 25af733e40f35..c53ac6b194883 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols +++ b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols @@ -127,6 +127,7 @@ export const MySFC = (props: {x: number, y: number, children?: predom.JSX.Elemen >props.y : Symbol(y, Decl(component.tsx, 3, 40)) >props : Symbol(props, Decl(component.tsx, 3, 22)) >y : Symbol(y, Decl(component.tsx, 3, 40)) +>this : Symbol(globalThis) >p : Symbol(predom.JSX.IntrinsicElements, Decl(renderer2.d.ts, 1, 19)) export class MyClass implements predom.JSX.Element { diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types index a1c0e79909d89..ab33876cbdadb 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types +++ b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types @@ -99,7 +99,7 @@ export const MySFC = (props: {x: number, y: number, children?: predom.JSX.Elemen >y : number >this.props.children : any >this.props : any ->this : any +>this : typeof globalThis >props : any >children : any >p : any diff --git a/tests/baselines/reference/jsxAttributeWithoutExpressionReact.symbols b/tests/baselines/reference/jsxAttributeWithoutExpressionReact.symbols index fc489ff899d04..a12ac0b1c929e 100644 --- a/tests/baselines/reference/jsxAttributeWithoutExpressionReact.symbols +++ b/tests/baselines/reference/jsxAttributeWithoutExpressionReact.symbols @@ -12,6 +12,7 @@ declare var React: any; } dataSource={this.state.ds} renderRow={}> >dataSource : Symbol(dataSource, Decl(jsxAttributeWithoutExpressionReact.tsx, 4, 5)) +>this : Symbol(globalThis) >renderRow : Symbol(renderRow, Decl(jsxAttributeWithoutExpressionReact.tsx, 4, 32)) diff --git a/tests/baselines/reference/jsxAttributeWithoutExpressionReact.types b/tests/baselines/reference/jsxAttributeWithoutExpressionReact.types index e5c192b4876eb..dac0e2c3df4e2 100644 --- a/tests/baselines/reference/jsxAttributeWithoutExpressionReact.types +++ b/tests/baselines/reference/jsxAttributeWithoutExpressionReact.types @@ -21,7 +21,7 @@ declare var React: any; >dataSource : any >this.state.ds : any >this.state : any ->this : any +>this : typeof globalThis >state : any >ds : any >renderRow : any diff --git a/tests/baselines/reference/jsxReactTestSuite.symbols b/tests/baselines/reference/jsxReactTestSuite.symbols index dfcc4c70bd801..8d656a8ecb120 100644 --- a/tests/baselines/reference/jsxReactTestSuite.symbols +++ b/tests/baselines/reference/jsxReactTestSuite.symbols @@ -39,6 +39,8 @@ declare var hasOwnProperty:any;
{this.props.children} +>this : Symbol(globalThis) +
;
@@ -57,6 +59,8 @@ declare var hasOwnProperty:any; >Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 2, 11)) {this.props.children} +>this : Symbol(globalThis) + ; >Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 2, 11)) @@ -154,6 +158,7 @@ var x = >Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 1, 11)) {...this.props} sound="moo" />; +>this : Symbol(globalThis) >sound : Symbol(sound, Decl(jsxReactTestSuite.tsx, 93, 19)) ; diff --git a/tests/baselines/reference/jsxReactTestSuite.types b/tests/baselines/reference/jsxReactTestSuite.types index 3637a21c2682a..dae8b8ae91221 100644 --- a/tests/baselines/reference/jsxReactTestSuite.types +++ b/tests/baselines/reference/jsxReactTestSuite.types @@ -47,7 +47,7 @@ declare var hasOwnProperty:any; {this.props.children} >this.props.children : any >this.props : any ->this : any +>this : typeof globalThis >props : any >children : any @@ -89,7 +89,7 @@ declare var hasOwnProperty:any; {this.props.children} >this.props.children : any >this.props : any ->this : any +>this : typeof globalThis >props : any >children : any @@ -262,7 +262,7 @@ var x = {...this.props} sound="moo" />; >this.props : any ->this : any +>this : typeof globalThis >props : any >sound : string diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.symbols b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.symbols index 306e629e82df7..e906195f9b187 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.symbols +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.symbols @@ -1,9 +1,12 @@ === tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts === return this.edit(role) +>this : Symbol(globalThis) + .then((role: Role) => >role : Symbol(role, Decl(multiLinePropertyAccessAndArrowFunctionIndent1.ts, 1, 11)) this.roleService.add(role) +>this : Symbol(globalThis) >role : Symbol(role, Decl(multiLinePropertyAccessAndArrowFunctionIndent1.ts, 1, 11)) .then((data: ng.IHttpPromiseCallbackArg) => data.data)); diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types index 5347dbb876dfb..9f35e8fff5799 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types @@ -4,7 +4,7 @@ return this.edit(role) >this.edit(role) .then : any >this.edit(role) : any >this.edit : any ->this : any +>this : typeof globalThis >edit : any >role : any @@ -19,7 +19,7 @@ return this.edit(role) >this.roleService.add(role) : any >this.roleService.add : any >this.roleService : any ->this : any +>this : typeof globalThis >roleService : any >add : any >role : any diff --git a/tests/baselines/reference/noImplicitThisFunctions.errors.txt b/tests/baselines/reference/noImplicitThisFunctions.errors.txt index aac8faa566ca7..8fb99eb27242d 100644 --- a/tests/baselines/reference/noImplicitThisFunctions.errors.txt +++ b/tests/baselines/reference/noImplicitThisFunctions.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/noImplicitThisFunctions.ts(13,12): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. -tests/cases/compiler/noImplicitThisFunctions.ts(17,38): error TS7041: The containing arrow function captures the global value of 'this' which implicitly has type 'any'. -tests/cases/compiler/noImplicitThisFunctions.ts(18,22): error TS7041: The containing arrow function captures the global value of 'this' which implicitly has type 'any'. +tests/cases/compiler/noImplicitThisFunctions.ts(17,38): error TS7041: The containing arrow function captures the global value of 'this'. +tests/cases/compiler/noImplicitThisFunctions.ts(18,22): error TS7041: The containing arrow function captures the global value of 'this'. tests/cases/compiler/noImplicitThisFunctions.ts(20,36): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. tests/cases/compiler/noImplicitThisFunctions.ts(21,50): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. @@ -26,10 +26,10 @@ tests/cases/compiler/noImplicitThisFunctions.ts(21,50): error TS2683: 'this' imp // error: `this` is `window`, but is still of type `any` let f4: (b: number) => number = b => this.c + b; ~~~~ -!!! error TS7041: The containing arrow function captures the global value of 'this' which implicitly has type 'any'. +!!! error TS7041: The containing arrow function captures the global value of 'this'. let f5 = () => () => this; ~~~~ -!!! error TS7041: The containing arrow function captures the global value of 'this' which implicitly has type 'any'. +!!! error TS7041: The containing arrow function captures the global value of 'this'. let f6 = function() { return () => this; }; ~~~~ diff --git a/tests/baselines/reference/noImplicitThisFunctions.symbols b/tests/baselines/reference/noImplicitThisFunctions.symbols index d8d937893f32b..a86b117f910fc 100644 --- a/tests/baselines/reference/noImplicitThisFunctions.symbols +++ b/tests/baselines/reference/noImplicitThisFunctions.symbols @@ -31,10 +31,12 @@ let f4: (b: number) => number = b => this.c + b; >f4 : Symbol(f4, Decl(noImplicitThisFunctions.ts, 16, 3)) >b : Symbol(b, Decl(noImplicitThisFunctions.ts, 16, 9)) >b : Symbol(b, Decl(noImplicitThisFunctions.ts, 16, 31)) +>this : Symbol(globalThis) >b : Symbol(b, Decl(noImplicitThisFunctions.ts, 16, 31)) let f5 = () => () => this; >f5 : Symbol(f5, Decl(noImplicitThisFunctions.ts, 17, 3)) +>this : Symbol(globalThis) let f6 = function() { return () => this; }; >f6 : Symbol(f6, Decl(noImplicitThisFunctions.ts, 19, 3)) diff --git a/tests/baselines/reference/noImplicitThisFunctions.types b/tests/baselines/reference/noImplicitThisFunctions.types index f5b93fa9efbc1..639e84f650b27 100644 --- a/tests/baselines/reference/noImplicitThisFunctions.types +++ b/tests/baselines/reference/noImplicitThisFunctions.types @@ -42,15 +42,15 @@ let f4: (b: number) => number = b => this.c + b; >b : number >this.c + b : any >this.c : any ->this : any +>this : typeof globalThis >c : any >b : number let f5 = () => () => this; ->f5 : () => () => any ->() => () => this : () => () => any ->() => this : () => any ->this : any +>f5 : () => () => typeof globalThis +>() => () => this : () => () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis let f6 = function() { return () => this; }; >f6 : () => () => any diff --git a/tests/baselines/reference/parserCommaInTypeMemberList2.symbols b/tests/baselines/reference/parserCommaInTypeMemberList2.symbols index ffaac46fd2749..9bc7a392292ca 100644 --- a/tests/baselines/reference/parserCommaInTypeMemberList2.symbols +++ b/tests/baselines/reference/parserCommaInTypeMemberList2.symbols @@ -5,4 +5,5 @@ var s = $.extend< { workItem: any }, { workItem: any, width: string }>({ workIte >workItem : Symbol(workItem, Decl(parserCommaInTypeMemberList2.ts, 0, 38)) >width : Symbol(width, Decl(parserCommaInTypeMemberList2.ts, 0, 53)) >workItem : Symbol(workItem, Decl(parserCommaInTypeMemberList2.ts, 0, 72)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/parserCommaInTypeMemberList2.types b/tests/baselines/reference/parserCommaInTypeMemberList2.types index cfa270d983871..0b172848ccd4e 100644 --- a/tests/baselines/reference/parserCommaInTypeMemberList2.types +++ b/tests/baselines/reference/parserCommaInTypeMemberList2.types @@ -11,7 +11,7 @@ var s = $.extend< { workItem: any }, { workItem: any, width: string }>({ workIte >{ workItem: this._workItem } : { workItem: any; } >workItem : any >this._workItem : any ->this : any +>this : typeof globalThis >_workItem : any >{} : {} diff --git a/tests/baselines/reference/parserConditionalExpression1.symbols b/tests/baselines/reference/parserConditionalExpression1.symbols index e271c68b4a0b3..91453101af13a 100644 --- a/tests/baselines/reference/parserConditionalExpression1.symbols +++ b/tests/baselines/reference/parserConditionalExpression1.symbols @@ -1,3 +1,6 @@ === tests/cases/conformance/parser/ecmascript5/Expressions/parserConditionalExpression1.ts === (a=this.R[c])?a.JW||(a.e5(this,c),a.JW=_.l):this.A -No type information for this code. \ No newline at end of file +>this : Symbol(globalThis) +>this : Symbol(globalThis) +>this : Symbol(globalThis) + diff --git a/tests/baselines/reference/parserConditionalExpression1.types b/tests/baselines/reference/parserConditionalExpression1.types index 930d744d48ab8..d0fb5556033f9 100644 --- a/tests/baselines/reference/parserConditionalExpression1.types +++ b/tests/baselines/reference/parserConditionalExpression1.types @@ -6,7 +6,7 @@ >a : any >this.R[c] : any >this.R : any ->this : any +>this : typeof globalThis >R : any >c : any >a.JW||(a.e5(this,c),a.JW=_.l) : any @@ -19,7 +19,7 @@ >a.e5 : any >a : any >e5 : any ->this : any +>this : typeof globalThis >c : any >a.JW=_.l : any >a.JW : any @@ -29,6 +29,6 @@ >_ : any >l : any >this.A : any ->this : any +>this : typeof globalThis >A : any diff --git a/tests/baselines/reference/parserForStatement8.errors.txt b/tests/baselines/reference/parserForStatement8.errors.txt index 21ea55e3b09f1..ac04ed5e5480a 100644 --- a/tests/baselines/reference/parserForStatement8.errors.txt +++ b/tests/baselines/reference/parserForStatement8.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,6): error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,14): error TS2304: Cannot find name 'b'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts (2 errors) ==== for (this in b) { ~~~~ -!!! error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. ~ !!! error TS2304: Cannot find name 'b'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForStatement8.symbols b/tests/baselines/reference/parserForStatement8.symbols index 4e34f8b90c91c..2133f54f57ca8 100644 --- a/tests/baselines/reference/parserForStatement8.symbols +++ b/tests/baselines/reference/parserForStatement8.symbols @@ -1,4 +1,4 @@ === tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts === for (this in b) { -No type information for this code.} -No type information for this code. \ No newline at end of file +>this : Symbol(globalThis) +} diff --git a/tests/baselines/reference/parserForStatement8.types b/tests/baselines/reference/parserForStatement8.types index 0a52052875902..72572e68cfc4c 100644 --- a/tests/baselines/reference/parserForStatement8.types +++ b/tests/baselines/reference/parserForStatement8.types @@ -1,5 +1,5 @@ === tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts === for (this in b) { ->this : any +>this : typeof globalThis >b : any } diff --git a/tests/baselines/reference/parserModifierOnStatementInBlock2.symbols b/tests/baselines/reference/parserModifierOnStatementInBlock2.symbols index c118eff4a863b..daf115443ae17 100644 --- a/tests/baselines/reference/parserModifierOnStatementInBlock2.symbols +++ b/tests/baselines/reference/parserModifierOnStatementInBlock2.symbols @@ -2,5 +2,6 @@ { declare var x = this; >x : Symbol(x, Decl(parserModifierOnStatementInBlock2.ts, 1, 14)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/parserModifierOnStatementInBlock2.types b/tests/baselines/reference/parserModifierOnStatementInBlock2.types index a74d3a0c544d0..3bb3aee1cf9cc 100644 --- a/tests/baselines/reference/parserModifierOnStatementInBlock2.types +++ b/tests/baselines/reference/parserModifierOnStatementInBlock2.types @@ -1,7 +1,7 @@ === tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnStatementInBlock2.ts === { declare var x = this; ->x : any ->this : any +>x : typeof globalThis +>this : typeof globalThis } diff --git a/tests/baselines/reference/parserStrictMode16.symbols b/tests/baselines/reference/parserStrictMode16.symbols index 655201fbea2bf..bef54a8af998b 100644 --- a/tests/baselines/reference/parserStrictMode16.symbols +++ b/tests/baselines/reference/parserStrictMode16.symbols @@ -1,7 +1,8 @@ === tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode16.ts === "use strict"; -No type information for this code.delete this; -No type information for this code.delete 1; -No type information for this code.delete null; -No type information for this code.delete "a"; -No type information for this code. \ No newline at end of file +delete this; +>this : Symbol(globalThis) + +delete 1; +delete null; +delete "a"; diff --git a/tests/baselines/reference/parserStrictMode16.types b/tests/baselines/reference/parserStrictMode16.types index fbe701f374b13..94c8a6a6bd75f 100644 --- a/tests/baselines/reference/parserStrictMode16.types +++ b/tests/baselines/reference/parserStrictMode16.types @@ -4,7 +4,7 @@ delete this; >delete this : boolean ->this : any +>this : typeof globalThis delete 1; >delete 1 : boolean diff --git a/tests/baselines/reference/parserUnaryExpression1.errors.txt b/tests/baselines/reference/parserUnaryExpression1.errors.txt index 278960d53f31b..4001996551248 100644 --- a/tests/baselines/reference/parserUnaryExpression1.errors.txt +++ b/tests/baselines/reference/parserUnaryExpression1.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts(1,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts(1,3): error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type. ==== tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts (1 errors) ==== ++this; ~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. \ No newline at end of file +!!! error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/parserUnaryExpression1.symbols b/tests/baselines/reference/parserUnaryExpression1.symbols index 2311212b63d6f..053c922f947ec 100644 --- a/tests/baselines/reference/parserUnaryExpression1.symbols +++ b/tests/baselines/reference/parserUnaryExpression1.symbols @@ -1,3 +1,4 @@ === tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts === ++this; -No type information for this code. \ No newline at end of file +>this : Symbol(globalThis) + diff --git a/tests/baselines/reference/parserUnaryExpression1.types b/tests/baselines/reference/parserUnaryExpression1.types index 5803ac1f1f835..534dad664747d 100644 --- a/tests/baselines/reference/parserUnaryExpression1.types +++ b/tests/baselines/reference/parserUnaryExpression1.types @@ -1,5 +1,5 @@ === tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts === ++this; >++this : number ->this : any +>this : typeof globalThis diff --git a/tests/baselines/reference/propertyWrappedInTry.symbols b/tests/baselines/reference/propertyWrappedInTry.symbols index cce74c0981b94..4d570fee1bbcf 100644 --- a/tests/baselines/reference/propertyWrappedInTry.symbols +++ b/tests/baselines/reference/propertyWrappedInTry.symbols @@ -14,6 +14,7 @@ class Foo { public baz() { return this.bar; // doesn't get rewritten to Foo.bar. +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/propertyWrappedInTry.types b/tests/baselines/reference/propertyWrappedInTry.types index 29be27edee9d4..8138f41091f41 100644 --- a/tests/baselines/reference/propertyWrappedInTry.types +++ b/tests/baselines/reference/propertyWrappedInTry.types @@ -21,7 +21,7 @@ class Foo { return this.bar; // doesn't get rewritten to Foo.bar. >this.bar : any ->this : any +>this : typeof globalThis >bar : any } diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 3581d6d6f29bc..7a357e1327ea5 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -3,11 +3,12 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,15): tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'typeof globalThis' is not a constructor function type. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (7 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -56,6 +57,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): !!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. class ErrClass3 extends this { + ~~~~ +!!! error TS2507: Type 'typeof globalThis' is not a constructor function type. } diff --git a/tests/baselines/reference/thisInInvalidContexts.symbols b/tests/baselines/reference/thisInInvalidContexts.symbols index 417b9cc5ea81a..7fecdf73f4397 100644 --- a/tests/baselines/reference/thisInInvalidContexts.symbols +++ b/tests/baselines/reference/thisInInvalidContexts.symbols @@ -69,6 +69,7 @@ genericFunc(undefined); // Should be an error class ErrClass3 extends this { >ErrClass3 : Symbol(ErrClass3, Decl(thisInInvalidContexts.ts, 35, 29)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/thisInInvalidContexts.types b/tests/baselines/reference/thisInInvalidContexts.types index 672a8fe58c4ee..6f35006b6c12a 100644 --- a/tests/baselines/reference/thisInInvalidContexts.types +++ b/tests/baselines/reference/thisInInvalidContexts.types @@ -72,7 +72,7 @@ genericFunc(undefined); // Should be an error class ErrClass3 extends this { >ErrClass3 : ErrClass3 ->this : any +>this : typeof globalThis } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index f89b28978922a..4cfd109b00e12 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -3,11 +3,12 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'typeof globalThis' is not a constructor function type. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(44,9): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (7 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (8 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -56,6 +57,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod !!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. class ErrClass3 extends this { + ~~~~ +!!! error TS2507: Type 'typeof globalThis' is not a constructor function type. } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols b/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols index 9cf261fa672b3..ad52fbdabeb70 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols @@ -69,6 +69,7 @@ genericFunc(undefined); // Should be an error class ErrClass3 extends this { >ErrClass3 : Symbol(ErrClass3, Decl(thisInInvalidContextsExternalModule.ts, 35, 29)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.types b/tests/baselines/reference/thisInInvalidContextsExternalModule.types index cdc1317307771..e6ad34c9a2077 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.types +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.types @@ -72,7 +72,7 @@ genericFunc(undefined); // Should be an error class ErrClass3 extends this { >ErrClass3 : ErrClass3 ->this : any +>this : typeof globalThis } diff --git a/tests/baselines/reference/thisTypeInFunctions.symbols b/tests/baselines/reference/thisTypeInFunctions.symbols index ad16785f28830..c1dcdb9829dc3 100644 --- a/tests/baselines/reference/thisTypeInFunctions.symbols +++ b/tests/baselines/reference/thisTypeInFunctions.symbols @@ -126,6 +126,7 @@ let impl: I = { explicitVoid2: () => this.a, // ok, this: any because it refers to some outer object (window?) >explicitVoid2 : Symbol(explicitVoid2, Decl(thisTypeInFunctions.ts, 38, 10)) +>this : Symbol(globalThis) explicitVoid1() { return 12; }, >explicitVoid1 : Symbol(explicitVoid1, Decl(thisTypeInFunctions.ts, 39, 32)) @@ -365,6 +366,7 @@ let unboundToSpecified: (this: { y: number }, x: number) => number = x => x + th >x : Symbol(x, Decl(thisTypeInFunctions.ts, 92, 45)) >x : Symbol(x, Decl(thisTypeInFunctions.ts, 92, 68)) >x : Symbol(x, Decl(thisTypeInFunctions.ts, 92, 68)) +>this : Symbol(globalThis) let specifiedToSpecified: (this: {y: number}, x: number) => number = explicitStructural; >specifiedToSpecified : Symbol(specifiedToSpecified, Decl(thisTypeInFunctions.ts, 93, 3)) @@ -495,6 +497,9 @@ c.explicitC = m => m + this.n; >explicitC : Symbol(C.explicitC, Decl(thisTypeInFunctions.ts, 8, 5)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 117, 13)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 117, 13)) +>this.n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) +>this : Symbol(globalThis) +>n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) c.explicitThis = m => m + this.n; >c.explicitThis : Symbol(C.explicitThis, Decl(thisTypeInFunctions.ts, 5, 14)) @@ -502,6 +507,9 @@ c.explicitThis = m => m + this.n; >explicitThis : Symbol(C.explicitThis, Decl(thisTypeInFunctions.ts, 5, 14)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 118, 16)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 118, 16)) +>this.n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) +>this : Symbol(globalThis) +>n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) c.explicitProperty = m => m + this.n; >c.explicitProperty : Symbol(C.explicitProperty, Decl(thisTypeInFunctions.ts, 11, 5)) @@ -509,6 +517,9 @@ c.explicitProperty = m => m + this.n; >explicitProperty : Symbol(C.explicitProperty, Decl(thisTypeInFunctions.ts, 11, 5)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 119, 20)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 119, 20)) +>this.n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) +>this : Symbol(globalThis) +>n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) //NOTE: this=C here, I guess? c.explicitThis = explicitCFunction; diff --git a/tests/baselines/reference/thisTypeInFunctions.types b/tests/baselines/reference/thisTypeInFunctions.types index caf4e9a5971cd..7408a764f1a91 100644 --- a/tests/baselines/reference/thisTypeInFunctions.types +++ b/tests/baselines/reference/thisTypeInFunctions.types @@ -137,7 +137,7 @@ let impl: I = { >explicitVoid2 : () => any >() => this.a : () => any >this.a : any ->this : any +>this : typeof globalThis >a : any explicitVoid1() { return 12; }, @@ -431,7 +431,7 @@ let unboundToSpecified: (this: { y: number }, x: number) => number = x => x + th >x + this.y : any >x : number >this.y : any ->this : any +>this : typeof globalThis >y : any let specifiedToSpecified: (this: {y: number}, x: number) => number = explicitStructural; @@ -580,43 +580,43 @@ c.explicitProperty = m => m; // this inside lambdas refer to outer scope // the outer-scoped lambda at top-level is still just `any` c.explicitC = m => m + this.n; ->c.explicitC = m => m + this.n : (this: C, m: number) => any +>c.explicitC = m => m + this.n : (this: C, m: number) => number >c.explicitC : (this: C, m: number) => number >c : C >explicitC : (this: C, m: number) => number ->m => m + this.n : (this: C, m: number) => any +>m => m + this.n : (this: C, m: number) => number >m : number ->m + this.n : any +>m + this.n : number >m : number ->this.n : any ->this : any ->n : any +>this.n : number +>this : typeof globalThis +>n : number c.explicitThis = m => m + this.n; ->c.explicitThis = m => m + this.n : (this: C, m: number) => any +>c.explicitThis = m => m + this.n : (this: C, m: number) => number >c.explicitThis : (this: C, m: number) => number >c : C >explicitThis : (this: C, m: number) => number ->m => m + this.n : (this: C, m: number) => any +>m => m + this.n : (this: C, m: number) => number >m : number ->m + this.n : any +>m + this.n : number >m : number ->this.n : any ->this : any ->n : any +>this.n : number +>this : typeof globalThis +>n : number c.explicitProperty = m => m + this.n; ->c.explicitProperty = m => m + this.n : (this: { n: number; }, m: number) => any +>c.explicitProperty = m => m + this.n : (this: { n: number; }, m: number) => number >c.explicitProperty : (this: { n: number; }, m: number) => number >c : C >explicitProperty : (this: { n: number; }, m: number) => number ->m => m + this.n : (this: { n: number; }, m: number) => any +>m => m + this.n : (this: { n: number; }, m: number) => number >m : number ->m + this.n : any +>m + this.n : number >m : number ->this.n : any ->this : any ->n : any +>this.n : number +>this : typeof globalThis +>n : number //NOTE: this=C here, I guess? c.explicitThis = explicitCFunction; diff --git a/tests/baselines/reference/thisTypeInFunctionsNegative.symbols b/tests/baselines/reference/thisTypeInFunctionsNegative.symbols index 024ae663a9d70..14566bbf946c9 100644 --- a/tests/baselines/reference/thisTypeInFunctionsNegative.symbols +++ b/tests/baselines/reference/thisTypeInFunctionsNegative.symbols @@ -134,6 +134,7 @@ let impl: I = { }, explicitVoid2: () => this.a, // ok, `this:any` because it refers to an outer object >explicitVoid2 : Symbol(explicitVoid2, Decl(thisTypeInFunctionsNegative.ts, 39, 6)) +>this : Symbol(globalThis) explicitStructural: () => 12, >explicitStructural : Symbol(explicitStructural, Decl(thisTypeInFunctionsNegative.ts, 40, 32)) @@ -655,6 +656,7 @@ function initializer(this: C = new C()): number { return this.n; } >C : Symbol(C, Decl(thisTypeInFunctionsNegative.ts, 0, 0)) > : Symbol((Missing), Decl(thisTypeInFunctionsNegative.ts, 171, 30)) >C : Symbol(C, Decl(thisTypeInFunctionsNegative.ts, 171, 34)) +>this : Symbol(globalThis) // can't name parameters 'this' in a lambda. c.explicitProperty = (this, m) => m + this.n; @@ -664,6 +666,7 @@ c.explicitProperty = (this, m) => m + this.n; >this : Symbol(this, Decl(thisTypeInFunctionsNegative.ts, 174, 22)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 174, 27)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 174, 27)) +>this : Symbol(globalThis) const f2 = (this: {n: number}, m: number) => m + this.n; >f2 : Symbol(f2, Decl(thisTypeInFunctionsNegative.ts, 175, 5)) @@ -672,6 +675,7 @@ const f2 = (this: {n: number}, m: number) => m + this.n; >n : Symbol(n, Decl(thisTypeInFunctionsNegative.ts, 175, 22)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 175, 33)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 175, 33)) +>this : Symbol(globalThis) const f3 = async (this: {n: number}, m: number) => m + this.n; >f3 : Symbol(f3, Decl(thisTypeInFunctionsNegative.ts, 176, 5)) @@ -679,6 +683,7 @@ const f3 = async (this: {n: number}, m: number) => m + this.n; >n : Symbol(n, Decl(thisTypeInFunctionsNegative.ts, 176, 25)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 176, 36)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 176, 36)) +>this : Symbol(globalThis) const f4 = async (this: {n: number}, m: number) => m + this.n; >f4 : Symbol(f4, Decl(thisTypeInFunctionsNegative.ts, 177, 5)) @@ -687,4 +692,5 @@ const f4 = async (this: {n: number}, m: number) => m + this.n; >n : Symbol(n, Decl(thisTypeInFunctionsNegative.ts, 177, 28)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 177, 39)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 177, 39)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/thisTypeInFunctionsNegative.types b/tests/baselines/reference/thisTypeInFunctionsNegative.types index 90a5f06ad40a2..3a86203772f45 100644 --- a/tests/baselines/reference/thisTypeInFunctionsNegative.types +++ b/tests/baselines/reference/thisTypeInFunctionsNegative.types @@ -143,7 +143,7 @@ let impl: I = { >explicitVoid2 : () => any >() => this.a : () => any >this.a : any ->this : any +>this : typeof globalThis >a : any explicitStructural: () => 12, @@ -751,7 +751,7 @@ function initializer(this: C = new C()): number { return this.n; } > : any >number : any >this.n : any ->this : any +>this : typeof globalThis >n : any // can't name parameters 'this' in a lambda. @@ -766,7 +766,7 @@ c.explicitProperty = (this, m) => m + this.n; >m + this.n : any >m : number >this.n : any ->this : any +>this : typeof globalThis >n : any const f2 = (this: {n: number}, m: number) => m + this.n; @@ -778,7 +778,7 @@ const f2 = (this: {n: number}, m: number) => m + this.n; >m + this.n : any >m : number >this.n : any ->this : any +>this : typeof globalThis >n : any const f3 = async (this: {n: number}, m: number) => m + this.n; @@ -790,7 +790,7 @@ const f3 = async (this: {n: number}, m: number) => m + this.n; >m + this.n : any >m : number >this.n : any ->this : any +>this : typeof globalThis >n : any const f4 = async (this: {n: number}, m: number) => m + this.n; @@ -802,6 +802,6 @@ const f4 = async (this: {n: number}, m: number) => m + this.n; >m + this.n : any >m : number >this.n : any ->this : any +>this : typeof globalThis >n : any diff --git a/tests/baselines/reference/topLevelLambda2.symbols b/tests/baselines/reference/topLevelLambda2.symbols index 712d0a1611afc..412a7c8a547bf 100644 --- a/tests/baselines/reference/topLevelLambda2.symbols +++ b/tests/baselines/reference/topLevelLambda2.symbols @@ -5,4 +5,7 @@ function foo(x:any) {} foo(()=>this.window); >foo : Symbol(foo, Decl(topLevelLambda2.ts, 0, 0)) +>this.window : Symbol(window, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) diff --git a/tests/baselines/reference/topLevelLambda2.types b/tests/baselines/reference/topLevelLambda2.types index 7dcb909cdf952..ddca05514d0ee 100644 --- a/tests/baselines/reference/topLevelLambda2.types +++ b/tests/baselines/reference/topLevelLambda2.types @@ -6,8 +6,8 @@ function foo(x:any) {} foo(()=>this.window); >foo(()=>this.window) : void >foo : (x: any) => void ->()=>this.window : () => any ->this.window : any ->this : any ->window : any +>()=>this.window : () => Window +>this.window : Window +>this : typeof globalThis +>window : Window diff --git a/tests/baselines/reference/topLevelLambda3.symbols b/tests/baselines/reference/topLevelLambda3.symbols index 6ec9476ff743a..7dd41958b7f06 100644 --- a/tests/baselines/reference/topLevelLambda3.symbols +++ b/tests/baselines/reference/topLevelLambda3.symbols @@ -1,4 +1,7 @@ === tests/cases/compiler/topLevelLambda3.ts === var f = () => {this.window;} >f : Symbol(f, Decl(topLevelLambda3.ts, 0, 3)) +>this.window : Symbol(window, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) diff --git a/tests/baselines/reference/topLevelLambda3.types b/tests/baselines/reference/topLevelLambda3.types index e96d40880fca1..b2bb8f30bad4a 100644 --- a/tests/baselines/reference/topLevelLambda3.types +++ b/tests/baselines/reference/topLevelLambda3.types @@ -2,7 +2,7 @@ var f = () => {this.window;} >f : () => void >() => {this.window;} : () => void ->this.window : any ->this : any ->window : any +>this.window : Window +>this : typeof globalThis +>window : Window diff --git a/tests/baselines/reference/topLevelLambda4.symbols b/tests/baselines/reference/topLevelLambda4.symbols index a4f403a762ffd..202d1bf90d551 100644 --- a/tests/baselines/reference/topLevelLambda4.symbols +++ b/tests/baselines/reference/topLevelLambda4.symbols @@ -1,4 +1,7 @@ === tests/cases/compiler/topLevelLambda4.ts === export var x = () => this.window; >x : Symbol(x, Decl(topLevelLambda4.ts, 0, 10)) +>this.window : Symbol(window, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) diff --git a/tests/baselines/reference/topLevelLambda4.types b/tests/baselines/reference/topLevelLambda4.types index f6c8752c267fb..081f5c47c5ae1 100644 --- a/tests/baselines/reference/topLevelLambda4.types +++ b/tests/baselines/reference/topLevelLambda4.types @@ -1,8 +1,8 @@ === tests/cases/compiler/topLevelLambda4.ts === export var x = () => this.window; ->x : () => any ->() => this.window : () => any ->this.window : any ->this : any ->window : any +>x : () => Window +>() => this.window : () => Window +>this.window : Window +>this : typeof globalThis +>window : Window diff --git a/tests/baselines/reference/topLevelThisAssignment.symbols b/tests/baselines/reference/topLevelThisAssignment.symbols index e9b94983bf287..4ac7e79984861 100644 --- a/tests/baselines/reference/topLevelThisAssignment.symbols +++ b/tests/baselines/reference/topLevelThisAssignment.symbols @@ -1,10 +1,23 @@ === tests/cases/conformance/salsa/a.js === this.a = 10; -No type information for this code.this.a; -No type information for this code.a; -No type information for this code. -No type information for this code.=== tests/cases/conformance/salsa/b.js === +>this.a : Symbol(a, Decl(a.js, 0, 0)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(a.js, 0, 0)) + this.a; -No type information for this code.a; -No type information for this code. -No type information for this code. \ No newline at end of file +>this.a : Symbol(a, Decl(a.js, 0, 0)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(a.js, 0, 0)) + +a; +>a : Symbol(a, Decl(a.js, 0, 0)) + +=== tests/cases/conformance/salsa/b.js === +this.a; +>this.a : Symbol(a, Decl(a.js, 0, 0)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(a.js, 0, 0)) + +a; +>a : Symbol(a, Decl(a.js, 0, 0)) + diff --git a/tests/baselines/reference/topLevelThisAssignment.types b/tests/baselines/reference/topLevelThisAssignment.types index 92bb458b41f46..11c7b5a82e143 100644 --- a/tests/baselines/reference/topLevelThisAssignment.types +++ b/tests/baselines/reference/topLevelThisAssignment.types @@ -1,25 +1,25 @@ === tests/cases/conformance/salsa/a.js === this.a = 10; >this.a = 10 : 10 ->this.a : any ->this : any ->a : any +>this.a : number +>this : typeof globalThis +>a : number >10 : 10 this.a; ->this.a : any ->this : any ->a : any +>this.a : number +>this : typeof globalThis +>a : number a; ->a : error +>a : number === tests/cases/conformance/salsa/b.js === this.a; ->this.a : any ->this : any ->a : any +>this.a : number +>this : typeof globalThis +>a : number a; ->a : error +>a : number diff --git a/tests/baselines/reference/tsxAttributeResolution15.errors.txt b/tests/baselines/reference/tsxAttributeResolution15.errors.txt index f4c9c14deb5a9..ca86178b57863 100644 --- a/tests/baselines/reference/tsxAttributeResolution15.errors.txt +++ b/tests/baselines/reference/tsxAttributeResolution15.errors.txt @@ -1,8 +1,9 @@ tests/cases/conformance/jsx/file.tsx(11,10): error TS2322: Type '{ prop1: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & { children?: ReactNode; }'. Property 'prop1' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & { children?: ReactNode; }'. +tests/cases/conformance/jsx/file.tsx(14,44): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. -==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== +==== tests/cases/conformance/jsx/file.tsx (2 errors) ==== import React = require('react'); class BigGreeter extends React.Component<{ }, {}> { @@ -20,4 +21,6 @@ tests/cases/conformance/jsx/file.tsx(11,10): error TS2322: Type '{ prop1: string // OK let b = { this.textInput = input; }} /> + ~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. let c = \ No newline at end of file diff --git a/tests/baselines/reference/tsxAttributeResolution15.symbols b/tests/baselines/reference/tsxAttributeResolution15.symbols index 5c91d12a103f7..c366c93cef1cc 100644 --- a/tests/baselines/reference/tsxAttributeResolution15.symbols +++ b/tests/baselines/reference/tsxAttributeResolution15.symbols @@ -31,6 +31,7 @@ let b = { this.textInput = input; }} /> >BigGreeter : Symbol(BigGreeter, Decl(file.tsx, 0, 32)) >ref : Symbol(ref, Decl(file.tsx, 13, 19)) >input : Symbol(input, Decl(file.tsx, 13, 26)) +>this : Symbol(globalThis) >input : Symbol(input, Decl(file.tsx, 13, 26)) let c = diff --git a/tests/baselines/reference/tsxAttributeResolution15.types b/tests/baselines/reference/tsxAttributeResolution15.types index b95dcffcaf7bb..469f146cc45ce 100644 --- a/tests/baselines/reference/tsxAttributeResolution15.types +++ b/tests/baselines/reference/tsxAttributeResolution15.types @@ -37,7 +37,7 @@ let b = { this.textInput = input; }} /> >input : BigGreeter >this.textInput = input : BigGreeter >this.textInput : any ->this : any +>this : typeof globalThis >textInput : any >input : BigGreeter diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution4.symbols b/tests/baselines/reference/tsxSpreadAttributesResolution4.symbols index e599665b156fd..cb357c8a20da9 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution4.symbols +++ b/tests/baselines/reference/tsxSpreadAttributesResolution4.symbols @@ -79,6 +79,7 @@ let e3 = { this.textInput = input; } }} /> >EmptyProp : Symbol(EmptyProp, Decl(file.tsx, 19, 30)) >ref : Symbol(ref, Decl(file.tsx, 31, 25)) >input : Symbol(input, Decl(file.tsx, 31, 32)) +>this : Symbol(globalThis) >input : Symbol(input, Decl(file.tsx, 31, 32)) let e4 = diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution4.types b/tests/baselines/reference/tsxSpreadAttributesResolution4.types index 194993348dc5f..82173c0df83b6 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution4.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution4.types @@ -89,7 +89,7 @@ let e3 = { this.textInput = input; } }} /> >input : EmptyProp >this.textInput = input : EmptyProp >this.textInput : any ->this : any +>this : typeof globalThis >textInput : any >input : EmptyProp diff --git a/tests/baselines/reference/typeFromPropertyAssignment23.symbols b/tests/baselines/reference/typeFromPropertyAssignment23.symbols index 2ba8651ea535e..f28bf54ac7a02 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment23.symbols +++ b/tests/baselines/reference/typeFromPropertyAssignment23.symbols @@ -38,6 +38,8 @@ D.prototype.foo = () => { >foo : Symbol(D.foo, Decl(a.js, 14, 21)) this.n = 'not checked, so no error' +>this : Symbol(globalThis) +>n : Symbol(n, Decl(a.js, 15, 26)) } // post-class prototype assignments are trying to show that these properties are abstract diff --git a/tests/baselines/reference/typeFromPropertyAssignment23.types b/tests/baselines/reference/typeFromPropertyAssignment23.types index 4e540e3962fda..03bf1d91776c2 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment23.types +++ b/tests/baselines/reference/typeFromPropertyAssignment23.types @@ -46,7 +46,7 @@ D.prototype.foo = () => { this.n = 'not checked, so no error' >this.n = 'not checked, so no error' : "not checked, so no error" >this.n : any ->this : any +>this : typeof globalThis >n : any >'not checked, so no error' : "not checked, so no error" } diff --git a/tests/baselines/reference/typeFromPropertyAssignment9.symbols b/tests/baselines/reference/typeFromPropertyAssignment9.symbols index 27188c71b32db..2ebec8f5204ee 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment9.symbols +++ b/tests/baselines/reference/typeFromPropertyAssignment9.symbols @@ -118,6 +118,11 @@ min.nest = this.min.nest || function () { }; >min.nest : Symbol(min.nest, Decl(a.js, 29, 27), Decl(a.js, 31, 4)) >min : Symbol(min, Decl(a.js, 29, 3), Decl(a.js, 29, 27), Decl(a.js, 30, 44)) >nest : Symbol(min.nest, Decl(a.js, 29, 27), Decl(a.js, 31, 4)) +>this.min.nest : Symbol(min.nest, Decl(a.js, 29, 27), Decl(a.js, 31, 4)) +>this.min : Symbol(min, Decl(a.js, 29, 3), Decl(a.js, 29, 27), Decl(a.js, 30, 44)) +>this : Symbol(globalThis) +>min : Symbol(min, Decl(a.js, 29, 3), Decl(a.js, 29, 27), Decl(a.js, 30, 44)) +>nest : Symbol(min.nest, Decl(a.js, 29, 27), Decl(a.js, 31, 4)) min.nest.other = self.min.nest.other || class { }; >min.nest.other : Symbol(min.nest.other, Decl(a.js, 30, 44)) diff --git a/tests/baselines/reference/typeFromPropertyAssignment9.types b/tests/baselines/reference/typeFromPropertyAssignment9.types index b212f12bb17bd..c4f813f0a8985 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment9.types +++ b/tests/baselines/reference/typeFromPropertyAssignment9.types @@ -157,11 +157,11 @@ min.nest = this.min.nest || function () { }; >min : typeof min >nest : { (): void; other: typeof other; } >this.min.nest || function () { } : { (): void; other: typeof other; } ->this.min.nest : any ->this.min : any ->this : any ->min : any ->nest : any +>this.min.nest : { (): void; other: typeof other; } +>this.min : typeof min +>this : typeof globalThis +>min : typeof min +>nest : { (): void; other: typeof other; } >function () { } : { (): void; other: typeof other; } min.nest.other = self.min.nest.other || class { }; diff --git a/tests/baselines/reference/typeOfThis.errors.txt b/tests/baselines/reference/typeOfThis.errors.txt index 83d450570fce9..b47207670cc62 100644 --- a/tests/baselines/reference/typeOfThis.errors.txt +++ b/tests/baselines/reference/typeOfThis.errors.txt @@ -1,24 +1,16 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(14,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyTestClass'. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(18,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(22,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(24,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(27,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(29,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyTestClass'. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(37,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(53,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(61,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(83,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyGenericTestClass'. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(87,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyGenericTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(91,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(93,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyGenericTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(96,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(98,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyGenericTestClass'. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyGenericTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(122,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -==== tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts (18 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts (10 errors) ==== class MyTestClass { private canary: number; static staticCanary: number; @@ -45,8 +37,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 //type of 'this' in member accessor(get and set) body is the class instance type get prop() { - ~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. var p = this; var p: MyTestClass; ~ @@ -54,8 +44,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 return this; } set prop(v) { - ~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. var p = this; var p: MyTestClass; ~ @@ -86,8 +74,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 } static get staticProp() { - ~~~~~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. //type of 'this' in static accessor body is constructor function type var p = this; var p: typeof MyTestClass; @@ -96,8 +82,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 return this; } static set staticProp(v: typeof MyTestClass) { - ~~~~~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. //type of 'this' in static accessor body is constructor function type var p = this; var p: typeof MyTestClass; @@ -132,8 +116,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 //type of 'this' in member accessor(get and set) body is the class instance type get prop() { - ~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. var p = this; var p: MyGenericTestClass; ~ @@ -141,8 +123,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 return this; } set prop(v) { - ~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. var p = this; var p: MyGenericTestClass; ~ @@ -173,8 +153,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 } static get staticProp() { - ~~~~~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. //type of 'this' in static accessor body is constructor function type var p = this; var p: typeof MyGenericTestClass; @@ -183,8 +161,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 return this; } static set staticProp(v: typeof MyGenericTestClass) { - ~~~~~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. //type of 'this' in static accessor body is constructor function type var p = this; var p: typeof MyGenericTestClass; @@ -215,19 +191,19 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 this.spaaaaace = 4; } - //type of 'this' in a fat arrow expression param list is Any + //type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { - var s: any; + var s: typeof globalThis; s.spaaaaaaace = 4; - //type of 'this' in a fat arrow expression body is Any - var t: any; + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; var t = this; this.spaaaaace = 4; } - //type of 'this' in global module is Any - var t: any; + //type of 'this' in global module is GlobalThis + var t: typeof globalThis; var t = this; this.spaaaaace = 4; diff --git a/tests/baselines/reference/typeOfThis.js b/tests/baselines/reference/typeOfThis.js index 42593bd3d2ae3..0ea8fc2f93541 100644 --- a/tests/baselines/reference/typeOfThis.js +++ b/tests/baselines/reference/typeOfThis.js @@ -159,32 +159,30 @@ var q1 = function (s = this) { this.spaaaaace = 4; } -//type of 'this' in a fat arrow expression param list is Any +//type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { - var s: any; + var s: typeof globalThis; s.spaaaaaaace = 4; - //type of 'this' in a fat arrow expression body is Any - var t: any; + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; var t = this; this.spaaaaace = 4; } -//type of 'this' in global module is Any -var t: any; +//type of 'this' in global module is GlobalThis +var t: typeof globalThis; var t = this; this.spaaaaace = 4; //// [typeOfThis.js] -var _this = this; -var MyTestClass = /** @class */ (function () { - function MyTestClass() { - var _this = this; - this.someFunc = function () { +class MyTestClass { + constructor() { + this.someFunc = () => { //type of 'this' in member variable initializer is the class instance type - var t = _this; + var t = this; var t; }; //type of 'this' in constructor body is the class instance type @@ -193,32 +191,26 @@ var MyTestClass = /** @class */ (function () { this.canary = 3; } //type of 'this' in member function param list is the class instance type - MyTestClass.prototype.memberFunc = function (t) { - if (t === void 0) { t = this; } + memberFunc(t = this) { var t; //type of 'this' in member function body is the class instance type var p = this; var p; - }; - Object.defineProperty(MyTestClass.prototype, "prop", { - //type of 'this' in member accessor(get and set) body is the class instance type - get: function () { - var p = this; - var p; - return this; - }, - set: function (v) { - var p = this; - var p; - p = v; - v = p; - }, - enumerable: true, - configurable: true - }); + } + //type of 'this' in member accessor(get and set) body is the class instance type + get prop() { + var p = this; + var p; + return this; + } + set prop(v) { + var p = this; + var p; + p = v; + v = p; + } //type of 'this' in static function param list is constructor function type - MyTestClass.staticFn = function (t) { - if (t === void 0) { t = this; } + static staticFn(t = this) { var t; var t = MyTestClass; t.staticCanary; @@ -227,34 +219,28 @@ var MyTestClass = /** @class */ (function () { var p; var p = MyTestClass; p.staticCanary; - }; - Object.defineProperty(MyTestClass, "staticProp", { - get: function () { - //type of 'this' in static accessor body is constructor function type - var p = this; - var p; - var p = MyTestClass; - p.staticCanary; - return this; - }, - set: function (v) { - //type of 'this' in static accessor body is constructor function type - var p = this; - var p; - var p = MyTestClass; - p.staticCanary; - }, - enumerable: true, - configurable: true - }); - return MyTestClass; -}()); -var MyGenericTestClass = /** @class */ (function () { - function MyGenericTestClass() { - var _this = this; - this.someFunc = function () { + } + static get staticProp() { + //type of 'this' in static accessor body is constructor function type + var p = this; + var p; + var p = MyTestClass; + p.staticCanary; + return this; + } + static set staticProp(v) { + //type of 'this' in static accessor body is constructor function type + var p = this; + var p; + var p = MyTestClass; + p.staticCanary; + } +} +class MyGenericTestClass { + constructor() { + this.someFunc = () => { //type of 'this' in member variable initializer is the class instance type - var t = _this; + var t = this; var t; }; //type of 'this' in constructor body is the class instance type @@ -263,32 +249,26 @@ var MyGenericTestClass = /** @class */ (function () { this.canary = 3; } //type of 'this' in member function param list is the class instance type - MyGenericTestClass.prototype.memberFunc = function (t) { - if (t === void 0) { t = this; } + memberFunc(t = this) { var t; //type of 'this' in member function body is the class instance type var p = this; var p; - }; - Object.defineProperty(MyGenericTestClass.prototype, "prop", { - //type of 'this' in member accessor(get and set) body is the class instance type - get: function () { - var p = this; - var p; - return this; - }, - set: function (v) { - var p = this; - var p; - p = v; - v = p; - }, - enumerable: true, - configurable: true - }); + } + //type of 'this' in member accessor(get and set) body is the class instance type + get prop() { + var p = this; + var p; + return this; + } + set prop(v) { + var p = this; + var p; + p = v; + v = p; + } //type of 'this' in static function param list is constructor function type - MyGenericTestClass.staticFn = function (t) { - if (t === void 0) { t = this; } + static staticFn(t = this) { var t; var t = MyGenericTestClass; t.staticCanary; @@ -297,31 +277,25 @@ var MyGenericTestClass = /** @class */ (function () { var p; var p = MyGenericTestClass; p.staticCanary; - }; - Object.defineProperty(MyGenericTestClass, "staticProp", { - get: function () { - //type of 'this' in static accessor body is constructor function type - var p = this; - var p; - var p = MyGenericTestClass; - p.staticCanary; - return this; - }, - set: function (v) { - //type of 'this' in static accessor body is constructor function type - var p = this; - var p; - var p = MyGenericTestClass; - p.staticCanary; - }, - enumerable: true, - configurable: true - }); - return MyGenericTestClass; -}()); + } + static get staticProp() { + //type of 'this' in static accessor body is constructor function type + var p = this; + var p; + var p = MyGenericTestClass; + p.staticCanary; + return this; + } + static set staticProp(v) { + //type of 'this' in static accessor body is constructor function type + var p = this; + var p; + var p = MyGenericTestClass; + p.staticCanary; + } +} //type of 'this' in a function declaration param list is Any -function fn(s) { - if (s === void 0) { s = this; } +function fn(s = this) { var s; s.spaaaaaaace = 4; //type of 'this' in a function declaration body is Any @@ -330,8 +304,7 @@ function fn(s) { this.spaaaaace = 4; } //type of 'this' in a function expression param list list is Any -var q1 = function (s) { - if (s === void 0) { s = this; } +var q1 = function (s = this) { var s; s.spaaaaaaace = 4; //type of 'this' in a function expression body is Any @@ -339,17 +312,16 @@ var q1 = function (s) { var t = this; this.spaaaaace = 4; }; -//type of 'this' in a fat arrow expression param list is Any -var q2 = function (s) { - if (s === void 0) { s = _this; } +//type of 'this' in a fat arrow expression param list is typeof globalThis +var q2 = (s = this) => { var s; s.spaaaaaaace = 4; - //type of 'this' in a fat arrow expression body is Any + //type of 'this' in a fat arrow expression body is typeof globalThis var t; - var t = _this; - _this.spaaaaace = 4; + var t = this; + this.spaaaaace = 4; }; -//type of 'this' in global module is Any +//type of 'this' in global module is GlobalThis var t; var t = this; this.spaaaaace = 4; diff --git a/tests/baselines/reference/typeOfThis.symbols b/tests/baselines/reference/typeOfThis.symbols index c89796f81577f..11c2ae273c4a1 100644 --- a/tests/baselines/reference/typeOfThis.symbols +++ b/tests/baselines/reference/typeOfThis.symbols @@ -419,34 +419,42 @@ var q1 = function (s = this) { this.spaaaaace = 4; } -//type of 'this' in a fat arrow expression param list is Any +//type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { >q2 : Symbol(q2, Decl(typeOfThis.ts, 161, 3)) >s : Symbol(s, Decl(typeOfThis.ts, 161, 10), Decl(typeOfThis.ts, 162, 7)) +>this : Symbol(globalThis) - var s: any; + var s: typeof globalThis; >s : Symbol(s, Decl(typeOfThis.ts, 161, 10), Decl(typeOfThis.ts, 162, 7)) +>globalThis : Symbol(globalThis) s.spaaaaaaace = 4; >s : Symbol(s, Decl(typeOfThis.ts, 161, 10), Decl(typeOfThis.ts, 162, 7)) - //type of 'this' in a fat arrow expression body is Any - var t: any; + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; >t : Symbol(t, Decl(typeOfThis.ts, 166, 7), Decl(typeOfThis.ts, 167, 7)) +>globalThis : Symbol(globalThis) var t = this; >t : Symbol(t, Decl(typeOfThis.ts, 166, 7), Decl(typeOfThis.ts, 167, 7)) +>this : Symbol(globalThis) this.spaaaaace = 4; +>this : Symbol(globalThis) } -//type of 'this' in global module is Any -var t: any; +//type of 'this' in global module is GlobalThis +var t: typeof globalThis; >t : Symbol(t, Decl(typeOfThis.ts, 172, 3), Decl(typeOfThis.ts, 173, 3)) +>globalThis : Symbol(globalThis) var t = this; >t : Symbol(t, Decl(typeOfThis.ts, 172, 3), Decl(typeOfThis.ts, 173, 3)) +>this : Symbol(globalThis) this.spaaaaace = 4; +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/typeOfThis.types b/tests/baselines/reference/typeOfThis.types index 0d27690a49aa8..9f10153eb97bf 100644 --- a/tests/baselines/reference/typeOfThis.types +++ b/tests/baselines/reference/typeOfThis.types @@ -430,51 +430,54 @@ var q1 = function (s = this) { >4 : 4 } -//type of 'this' in a fat arrow expression param list is Any +//type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { ->q2 : (s?: any) => void ->(s = this) => { var s: any; s.spaaaaaaace = 4; //type of 'this' in a fat arrow expression body is Any var t: any; var t = this; this.spaaaaace = 4;} : (s?: any) => void ->s : any ->this : any +>q2 : (s?: typeof globalThis) => void +>(s = this) => { var s: typeof globalThis; s.spaaaaaaace = 4; //type of 'this' in a fat arrow expression body is typeof globalThis var t: typeof globalThis; var t = this; this.spaaaaace = 4;} : (s?: typeof globalThis) => void +>s : typeof globalThis +>this : typeof globalThis - var s: any; ->s : any + var s: typeof globalThis; +>s : typeof globalThis +>globalThis : typeof globalThis s.spaaaaaaace = 4; >s.spaaaaaaace = 4 : 4 >s.spaaaaaaace : any ->s : any +>s : typeof globalThis >spaaaaaaace : any >4 : 4 - //type of 'this' in a fat arrow expression body is Any - var t: any; ->t : any + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; +>t : typeof globalThis +>globalThis : typeof globalThis var t = this; ->t : any ->this : any +>t : typeof globalThis +>this : typeof globalThis this.spaaaaace = 4; >this.spaaaaace = 4 : 4 >this.spaaaaace : any ->this : any +>this : typeof globalThis >spaaaaace : any >4 : 4 } -//type of 'this' in global module is Any -var t: any; ->t : any +//type of 'this' in global module is GlobalThis +var t: typeof globalThis; +>t : typeof globalThis +>globalThis : typeof globalThis var t = this; ->t : any ->this : any +>t : typeof globalThis +>this : typeof globalThis this.spaaaaace = 4; >this.spaaaaace = 4 : 4 >this.spaaaaace : any ->this : any +>this : typeof globalThis >spaaaaace : any >4 : 4 diff --git a/tests/baselines/reference/unknownSymbols1.symbols b/tests/baselines/reference/unknownSymbols1.symbols index d9726011f1ac6..c6f67db4a1ddd 100644 --- a/tests/baselines/reference/unknownSymbols1.symbols +++ b/tests/baselines/reference/unknownSymbols1.symbols @@ -54,6 +54,7 @@ class C4 extends C3 { var x2 = this.asdf; // no error, this is any >x2 : Symbol(x2, Decl(unknownSymbols1.ts, 25, 3)) +>this : Symbol(globalThis) class C5 { >C5 : Symbol(C5, Decl(unknownSymbols1.ts, 25, 19)) diff --git a/tests/baselines/reference/unknownSymbols1.types b/tests/baselines/reference/unknownSymbols1.types index f453273348519..9fced36d703a9 100644 --- a/tests/baselines/reference/unknownSymbols1.types +++ b/tests/baselines/reference/unknownSymbols1.types @@ -57,7 +57,7 @@ class C4 extends C3 { var x2 = this.asdf; // no error, this is any >x2 : any >this.asdf : any ->this : any +>this : typeof globalThis >asdf : any class C5 { diff --git a/tests/baselines/reference/wrappedIncovations1.symbols b/tests/baselines/reference/wrappedIncovations1.symbols index 49ccc1fa896ab..0949334104019 100644 --- a/tests/baselines/reference/wrappedIncovations1.symbols +++ b/tests/baselines/reference/wrappedIncovations1.symbols @@ -1,6 +1,7 @@ === tests/cases/compiler/wrappedIncovations1.ts === var v = this >v : Symbol(v, Decl(wrappedIncovations1.ts, 0, 3)) +>this : Symbol(globalThis) .foo() .bar() diff --git a/tests/baselines/reference/wrappedIncovations1.types b/tests/baselines/reference/wrappedIncovations1.types index 32f7bb0e1b846..92adf203aa920 100644 --- a/tests/baselines/reference/wrappedIncovations1.types +++ b/tests/baselines/reference/wrappedIncovations1.types @@ -7,7 +7,7 @@ var v = this >this .foo() .bar : any >this .foo() : any >this .foo : any ->this : any +>this : typeof globalThis .foo() >foo : any diff --git a/tests/baselines/reference/wrappedIncovations2.symbols b/tests/baselines/reference/wrappedIncovations2.symbols index 2836bf7c19cbe..6e5dcf7aae22e 100644 --- a/tests/baselines/reference/wrappedIncovations2.symbols +++ b/tests/baselines/reference/wrappedIncovations2.symbols @@ -1,6 +1,7 @@ === tests/cases/compiler/wrappedIncovations2.ts === var v = this. >v : Symbol(v, Decl(wrappedIncovations2.ts, 0, 3)) +>this : Symbol(globalThis) foo(). bar(). diff --git a/tests/baselines/reference/wrappedIncovations2.types b/tests/baselines/reference/wrappedIncovations2.types index 96337796bcd62..71317c3f9c26d 100644 --- a/tests/baselines/reference/wrappedIncovations2.types +++ b/tests/baselines/reference/wrappedIncovations2.types @@ -7,7 +7,7 @@ var v = this. >this. foo(). bar : any >this. foo() : any >this. foo : any ->this : any +>this : typeof globalThis foo(). >foo : any diff --git a/tests/cases/conformance/es2019/globalThisPropertyAssignment.ts b/tests/cases/conformance/es2019/globalThisPropertyAssignment.ts new file mode 100644 index 0000000000000..fb9638e30fb18 --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisPropertyAssignment.ts @@ -0,0 +1,10 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @Filename: globalThisPropertyAssignment.js +this.x = 1 +var y = 2 +// should work in JS +window.z = 3 +// should work in JS (even though it's a secondary declaration) +globalThis.alpha = 4 diff --git a/tests/cases/conformance/es2019/globalThisReadonlyProperties.ts b/tests/cases/conformance/es2019/globalThisReadonlyProperties.ts new file mode 100644 index 0000000000000..f641fe8d0da51 --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisReadonlyProperties.ts @@ -0,0 +1,5 @@ +globalThis.globalThis = 1 as any // should error +var x = 1 +const y = 2 +globalThis.x = 3 +globalThis.y = 4 // should error diff --git a/tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts b/tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts new file mode 100644 index 0000000000000..88f68f8f88405 --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts @@ -0,0 +1,2 @@ + +declare const w_e: (typeof globalThis)["globalThis"] diff --git a/tests/cases/conformance/es2019/globalThisUnknown.ts b/tests/cases/conformance/es2019/globalThisUnknown.ts new file mode 100644 index 0000000000000..b1ae4224e1e29 --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisUnknown.ts @@ -0,0 +1,13 @@ +declare let win: Window & typeof globalThis; + +// this access should be an error +win.hi +// these two should be fine, with type any +this.hi +globalThis.hi + +// element access is always ok without noImplicitAny +win['hi'] +this['hi'] +globalThis['hi'] + diff --git a/tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts b/tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts new file mode 100644 index 0000000000000..53fb9a98edba0 --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts @@ -0,0 +1,11 @@ +// @noImplicitAny: true +declare let win: Window & typeof globalThis; + +// all accesses should be errors +win.hi +this.hi +globalThis.hi + +win['hi'] +this['hi'] +globalThis['hi'] diff --git a/tests/cases/conformance/es2019/globalThisVarDeclaration.ts b/tests/cases/conformance/es2019/globalThisVarDeclaration.ts new file mode 100644 index 0000000000000..5b75d1095a687 --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisVarDeclaration.ts @@ -0,0 +1,35 @@ +// @out: output.js +// @target: esnext +// @lib: esnext, dom +// @Filename: b.js +// @allowJs: true +// @checkJs: true +var a = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; + +// DOM access is not supported until the index signature is handled more strictly +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; + +// @Filename: actual.ts +var b = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; + +// same here -- no DOM access to globalThis yet +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; + diff --git a/tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts b/tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts index 4e9da72af6dfd..3a793f1f39131 100644 --- a/tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts +++ b/tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts @@ -1,3 +1,4 @@ +// @target: esnext class MyTestClass { private canary: number; static staticCanary: number; @@ -158,19 +159,19 @@ var q1 = function (s = this) { this.spaaaaace = 4; } -//type of 'this' in a fat arrow expression param list is Any +//type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { - var s: any; + var s: typeof globalThis; s.spaaaaaaace = 4; - //type of 'this' in a fat arrow expression body is Any - var t: any; + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; var t = this; this.spaaaaace = 4; } -//type of 'this' in global module is Any -var t: any; +//type of 'this' in global module is GlobalThis +var t: typeof globalThis; var t = this; this.spaaaaace = 4; diff --git a/tests/cases/conformance/salsa/topLevelThisAssignment.ts b/tests/cases/conformance/salsa/topLevelThisAssignment.ts index 162bed0c30fc7..aed2f86710803 100644 --- a/tests/cases/conformance/salsa/topLevelThisAssignment.ts +++ b/tests/cases/conformance/salsa/topLevelThisAssignment.ts @@ -1,5 +1,6 @@ // @out: output.js // @allowJs: true +// @checkJs: true // @Filename: a.js this.a = 10; this.a; diff --git a/tests/cases/fourslash/completionEntryForClassMembers.ts b/tests/cases/fourslash/completionEntryForClassMembers.ts index 9da74be0bb1bd..6dcfd059c46f1 100644 --- a/tests/cases/fourslash/completionEntryForClassMembers.ts +++ b/tests/cases/fourslash/completionEntryForClassMembers.ts @@ -130,6 +130,7 @@ verify.completions( marker: "InsideMethod", exact: [ "arguments", + "globalThis", "B", "C", "D", "D1", "D2", "D3", "D4", "D5", "D6", "E", "F", "F2", "G", "G2", "H", "I", "J", "K", "L", "L2", "M", "N", "O", "undefined", ...completion.insideMethodKeywords, diff --git a/tests/cases/fourslash/completionListIsGlobalCompletion.ts b/tests/cases/fourslash/completionListIsGlobalCompletion.ts index f8ee943053781..2a37849c2b8ea 100644 --- a/tests/cases/fourslash/completionListIsGlobalCompletion.ts +++ b/tests/cases/fourslash/completionListIsGlobalCompletion.ts @@ -47,6 +47,6 @@ verify.completions( { marker: "10", exact: completion.classElementKeywords, isGlobalCompletion: false, isNewIdentifierLocation: true }, { marker: "13", exact: globals, isGlobalCompletion: false }, { marker: "15", exact: globals, isGlobalCompletion: true, isNewIdentifierLocation: true }, - { marker: "16", exact: [...x, ...completion.globalsVars, "undefined"], isGlobalCompletion: false }, + { marker: "16", exact: [...x, "globalThis", ...completion.globalsVars, "undefined"], isGlobalCompletion: false }, { marker: "17", exact: completion.globalKeywordsPlusUndefined, isGlobalCompletion: false }, ); diff --git a/tests/cases/fourslash/completionListKeywords.ts b/tests/cases/fourslash/completionListKeywords.ts index 660099d3188a0..ed489487b3c60 100644 --- a/tests/cases/fourslash/completionListKeywords.ts +++ b/tests/cases/fourslash/completionListKeywords.ts @@ -4,4 +4,4 @@ /////**/ -verify.completions({ marker: "", exact: ["undefined", ...completion.statementKeywordsWithTypes] }); +verify.completions({ marker: "", exact: ["globalThis", "undefined", ...completion.statementKeywordsWithTypes] }); diff --git a/tests/cases/fourslash/completionListWithMeanings.ts b/tests/cases/fourslash/completionListWithMeanings.ts index 8c3498ebda5a7..41df1ed381657 100644 --- a/tests/cases/fourslash/completionListWithMeanings.ts +++ b/tests/cases/fourslash/completionListWithMeanings.ts @@ -16,6 +16,7 @@ ////var zz = { x: 4, y: 3 }; const values: ReadonlyArray = [ + "globalThis", { name: "m2", text: "namespace m2" }, // With no type side, allowed only in value { name: "m3", text: "namespace m3" }, { name: "xx", text: "var xx: number" }, @@ -28,6 +29,7 @@ const values: ReadonlyArray = [ ]; const types: ReadonlyArray = [ + "globalThis", { name: "m", text: "namespace m" }, { name: "m3", text: "namespace m3" }, { name: "point", text: "interface point" }, diff --git a/tests/cases/fourslash/completionListWithModulesFromModule.ts b/tests/cases/fourslash/completionListWithModulesFromModule.ts index d08e26a8d504e..dbcbdd797835a 100644 --- a/tests/cases/fourslash/completionListWithModulesFromModule.ts +++ b/tests/cases/fourslash/completionListWithModulesFromModule.ts @@ -263,6 +263,7 @@ verify.completions( { name: "shwvar", text: "var shwvar: string" }, { name: "shwcls", text: "class shwcls" }, "tmp", + "globalThis", ...commonValues, "undefined", ...completion.statementKeywordsWithTypes, @@ -272,6 +273,7 @@ verify.completions( exact: [ { name: "shwcls", text: "class shwcls" }, { name: "shwint", text: "interface shwint" }, + "globalThis", ...commonTypes, ...completion.typeKeywords, ] @@ -282,6 +284,7 @@ verify.completions( "Mod1", "iMod1", "tmp", + "globalThis", { name: "shwfn", text: "function shwfn(): void" }, ...commonValues, { name: "shwcls", text: "class shwcls" }, @@ -295,6 +298,7 @@ verify.completions( exact: [ "Mod1", "iMod1", + "globalThis", ...commonTypes, { name: "shwcls", text: "class shwcls" }, { name: "shwint", text: "interface shwint" }, diff --git a/tests/cases/fourslash/completionsImport_default_anonymous.ts b/tests/cases/fourslash/completionsImport_default_anonymous.ts index 8aa9dfb5af63b..720bb3f1c6bec 100644 --- a/tests/cases/fourslash/completionsImport_default_anonymous.ts +++ b/tests/cases/fourslash/completionsImport_default_anonymous.ts @@ -14,7 +14,7 @@ goTo.marker("0"); const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true }; verify.completions( - { marker: "0", exact: ["undefined", ...completion.statementKeywordsWithTypes], preferences }, + { marker: "0", exact: ["globalThis", "undefined", ...completion.statementKeywordsWithTypes], preferences }, { marker: "1", includes: { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) default: 0", kind: "property", hasAction: true }, diff --git a/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts index c5e87877cfb90..8fc73457117b5 100644 --- a/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts +++ b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts @@ -14,7 +14,7 @@ goTo.marker("0"); const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true }; const exportEntry: FourSlashInterface.ExpectedCompletionEntryObject = { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) export=: 0", kind: "property", hasAction: true }; verify.completions( - { marker: "0", exact: ["undefined", exportEntry, ...completion.statementKeywordsWithTypes], preferences }, + { marker: "0", exact: ["globalThis", "undefined", exportEntry, ...completion.statementKeywordsWithTypes], preferences }, { marker: "1", includes: exportEntry, preferences } ); verify.applyCodeActionFromCompletion("0", { @@ -25,4 +25,4 @@ verify.applyCodeActionFromCompletion("0", { exp fooB`, -}); \ No newline at end of file +}); diff --git a/tests/cases/fourslash/completionsImport_keywords.ts b/tests/cases/fourslash/completionsImport_keywords.ts index 6d4edd83b36ae..64bab64c7a8f5 100644 --- a/tests/cases/fourslash/completionsImport_keywords.ts +++ b/tests/cases/fourslash/completionsImport_keywords.ts @@ -34,7 +34,7 @@ verify.completions( { marker: "unique", exact: [ - ...completion.globalsVars, "undefined", + "globalThis", ...completion.globalsVars, "undefined", { name: "unique", source: "/a", sourceDisplay: "./a", text: "(alias) const unique: 0\nexport unique", hasAction: true }, ...completion.globalKeywords.filter(e => e.name !== "unique"), ], diff --git a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts index ae552f437fee9..5893f6f0fdc8c 100644 --- a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts +++ b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts @@ -20,6 +20,7 @@ goTo.marker(""); verify.completions({ marker: "", exact: [ + "globalThis", { name: "foo", text: "var foo: number", kind: "var", kindModifiers: "declare" }, "undefined", { diff --git a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts index 10a0c124e4d48..5f21db1e3763e 100644 --- a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts +++ b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts @@ -14,6 +14,7 @@ verify.completions({ marker: "", exact: [ { name: "Test2", text: "(alias) function Test2(): void\nimport Test2", kind: "alias" }, + "globalThis", "undefined", { name: "Test1", source: "/a", sourceDisplay: "./a", text: "function Test1(): void", kind: "function", kindModifiers: "export", hasAction: true }, ...completion.statementKeywordsWithTypes, diff --git a/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts b/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts index f5efa9cd912ab..71242bc240a96 100644 --- a/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts +++ b/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts @@ -19,6 +19,7 @@ verify.completions({ marker: "", exact: [ + "globalThis", "undefined", { name: "foo", source: "/foo/lib/foo", sourceDisplay: "./foo", text: "const foo: 0", kind: "const", kindModifiers: "export", hasAction: true }, ...completion.statementKeywordsWithTypes, diff --git a/tests/cases/fourslash/completionsImport_reExportDefault.ts b/tests/cases/fourslash/completionsImport_reExportDefault.ts index 8e38faa0b052c..7f6639c3f13d8 100644 --- a/tests/cases/fourslash/completionsImport_reExportDefault.ts +++ b/tests/cases/fourslash/completionsImport_reExportDefault.ts @@ -15,6 +15,7 @@ verify.completions({ marker: "", exact: [ + "globalThis", ...completion.globalsVars, "undefined", { diff --git a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts index afe88fa6da893..711386816c081 100644 --- a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts +++ b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts @@ -11,6 +11,6 @@ verify.completions({ marker: "", - exact: [{ name: "foo", text: "const foo: 1" }, "undefined", ...completion.statementKeywordsWithTypes], + exact: ["globalThis", { name: "foo", text: "const foo: 1" }, "undefined", ...completion.statementKeywordsWithTypes], preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsTypeKeywords.ts b/tests/cases/fourslash/completionsTypeKeywords.ts index 10a6d4537594f..4c26e13932ec1 100644 --- a/tests/cases/fourslash/completionsTypeKeywords.ts +++ b/tests/cases/fourslash/completionsTypeKeywords.ts @@ -6,5 +6,5 @@ verify.completions({ marker: "", - exact: ["T", ...completion.typeKeywords], + exact: ["globalThis", "T", ...completion.typeKeywords], }); diff --git a/tests/cases/fourslash/findAllRefsThisKeyword.ts b/tests/cases/fourslash/findAllRefsThisKeyword.ts index 34995467a2783..b0045e91bc195 100644 --- a/tests/cases/fourslash/findAllRefsThisKeyword.ts +++ b/tests/cases/fourslash/findAllRefsThisKeyword.ts @@ -24,8 +24,8 @@ ////const x = { [|{| "isWriteAccess": true, "isDefinition": true |}this|]: 0 } ////x.[|this|]; -const [global, f0, f1, g0, g1, x, y, constructor, method, propDef, propUse] = test.ranges(); -verify.singleReferenceGroup("this", [global]); +const [glob, f0, f1, g0, g1, x, y, constructor, method, propDef, propUse] = test.ranges(); +verify.singleReferenceGroup("this: typeof globalThis", [glob]); verify.singleReferenceGroup("(parameter) this: any", [f0, f1]); verify.singleReferenceGroup("(parameter) this: any", [g0, g1]); verify.singleReferenceGroup("this: typeof C", [x, y]); diff --git a/tests/cases/fourslash/findAllRefsThisKeywordMultipleFiles.ts b/tests/cases/fourslash/findAllRefsThisKeywordMultipleFiles.ts index d94f2993d1df8..807bc9bf19405 100644 --- a/tests/cases/fourslash/findAllRefsThisKeywordMultipleFiles.ts +++ b/tests/cases/fourslash/findAllRefsThisKeywordMultipleFiles.ts @@ -12,4 +12,4 @@ //// // different 'this' //// function f(this) { return this; } -verify.singleReferenceGroup("this"); +verify.singleReferenceGroup("this: typeof globalThis"); diff --git a/tests/cases/fourslash/tsxCompletionOnOpeningTagWithoutJSX1.ts b/tests/cases/fourslash/tsxCompletionOnOpeningTagWithoutJSX1.ts index 7a577cfbcce36..9198f5a857add 100644 --- a/tests/cases/fourslash/tsxCompletionOnOpeningTagWithoutJSX1.ts +++ b/tests/cases/fourslash/tsxCompletionOnOpeningTagWithoutJSX1.ts @@ -3,4 +3,4 @@ //@Filename: file.tsx //// var x =