Add globalThis (#29332)

* Restore original code from bind-toplevel-this

With one or two additional comments

* Working in JS, but the symbol is not right.

Still need to

1. Make it work in Typescript.
2. Add test (and make them work) for the other uses of GlobalThis:
window, globalThis, etc.

* Check in TS also; update some tests

Lots of tests still fail, but all but 1 change so far has been correct.

* Update baselines

A couple of tests still fail and need to be fixed.

* Handle type references to globalThis

The type reference must be `typeof globalThis`. Just `globalThis` will
be treated as a value reference in type position -- an error.

* Restore former behaviour of implicitThis errors

I left the noImplicitThis rule for captured use of global this in an
arrow function, even though technically it isn't `any` any more --
it's typeof globalThis.  However, you should still use some other method
to access globals inside an arrow, because captured-global-this is super
confusing there.

* Test values with type globalThis

I ran into a problem with intersecting `Window & typeof globalThis`:

1. This adds a new index signature to Window, which is probably not
desired. In fact, with noImplicitAny, it's not desired on globalThis
either I think.
2. Adding this type requires editing TSJS-lib-generator, not this repo.

So I added the test cases and will probably update them later, when
those two problems are fixed.

* Add esnext declaration for globalThis

* Switch to symbol-based approach

I decided I didn't like the import-type-based approach.

Update baselines to reflect the difference.

* Do not suggest globals for completions at toplevel

* Add tests of element and property access

* Look up globalThis using normal resolution

globalThis is no longer constructed lazily. Its synthetic Identifier
node is also now more realistic.

* Update fourslash tests

* Add missed fourslash test update

* Remove esnext.globalthis.d.ts too

* Add chained globalThis self-lookup test

* Attempt at making globalThis readonly

In progress, had to interrupt for other work.

* Add/update tests

* Addres PR comments:

1. Add parameter to tryGetThisTypeAt to exclude globalThis.
2. Use combined Module flag instead combining them in-place.
3. SymbolDisplay doesn't print 'module globalThis' for this expressions
anymore.
This commit is contained in:
Nathan Shively-Sanders authored and GitHub committed 2019-02-27 14:14:34 -08:00
1 parent 13c08ab32b
commit be2db9db12
167 files changed
+1372 -400

No files matched your search

+7 -2
View File
@@ -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:
+42 -17
View File
@@ -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) {
@@ -16990,25 +16997,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))) {
@@ -17055,6 +17064,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) {
@@ -19352,6 +19371,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);
}
+1 -1
View File
@@ -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
},
+1 -1
View File
@@ -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;
/**
+13 -5
View File
@@ -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<ts.CompletionEntry>, expected: ReadonlyArray<FourSlashInterface.ExpectedCompletionEntry>) {
private verifyCompletionsAreExactly(actual: ReadonlyArray<ts.CompletionEntry>, expected: ReadonlyArray<FourSlashInterface.ExpectedCompletionEntry>, marker?: ArrayOrSingle<string | Marker>) {
// 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<ExpectedCompletionEntry>): ReadonlyArray<ExpectedCompletionEntry> {
return [
{ name: "globalThis", kind: "module" },
...globalTypeDecls,
...plus,
...typeKeywords,
@@ -4786,6 +4787,7 @@ namespace FourSlashInterface {
export const globalsInsideFunction = (plus: ReadonlyArray<ExpectedCompletionEntry>): ReadonlyArray<ExpectedCompletionEntry> => [
{ 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<ExpectedCompletionEntryObject> = [
{ name: "globalThis", kind: "module" },
...globalsVars,
{ name: "undefined", kind: "var" },
...globalKeywords
];
export function globalsPlus(plus: ReadonlyArray<ExpectedCompletionEntry>): ReadonlyArray<ExpectedCompletionEntry> {
return [...globalsVars, ...plus, { name: "undefined", kind: "var" }, ...globalKeywords];
return [
{ name: "globalThis", kind: "module" },
...globalsVars,
...plus,
{ name: "undefined", kind: "var" },
...globalKeywords];
}
}
+1 -1
View File
@@ -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 };
+1 -1
View File
@@ -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<ModuleDeclaration>(symbol, SyntaxKind.ModuleDeclaration);
const isNamespace = declaration && declaration.name && declaration.name.kind === SyntaxKind.Identifier;
@@ -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(
@@ -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;
@@ -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;
@@ -21,7 +21,11 @@ declare var a;
(<any>null);
// names and dotted names
(<any>this);
>this : Symbol(globalThis)
(<any>this.x);
>this : Symbol(globalThis)
(<any>(<any>a).x);
>a : Symbol(a, Decl(castExpressionParentheses.ts, 0, 11))
@@ -77,13 +77,13 @@ declare var a;
(<any>this);
>(<any>this) : any
><any>this : any
>this : any
>this : typeof globalThis
(<any>this.x);
>(<any>this.x) : any
><any>this.x : any
>this.x : any
>this : any
>this : typeof globalThis
>x : any
(<any>(<any>a).x);
@@ -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))
@@ -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
@@ -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))
@@ -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
@@ -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))
@@ -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
@@ -4,4 +4,5 @@ class _this {
}
var f = () => this;
>f : Symbol(f, Decl(collisionThisExpressionAndClassInGlobal.ts, 2, 3))
>this : Symbol(globalThis)
@@ -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
@@ -10,4 +10,5 @@ enum _this { // Error
}
var f = () => this;
>f : Symbol(f, Decl(collisionThisExpressionAndEnumInGlobal.ts, 4, 3))
>this : Symbol(globalThis)
@@ -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
@@ -6,4 +6,5 @@ function _this() { //Error
}
var f = () => this;
>f : Symbol(f, Decl(collisionThisExpressionAndFunctionInGlobal.ts, 3, 3))
>this : Symbol(globalThis)
@@ -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
@@ -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)));
@@ -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)));
@@ -8,4 +8,5 @@ module _this { //Error
}
var f = () => this;
>f : Symbol(f, Decl(collisionThisExpressionAndModuleInGlobal.ts, 4, 3))
>this : Symbol(globalThis)
@@ -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
@@ -4,4 +4,5 @@ var _this = 1;
var f = () => this;
>f : Symbol(f, Decl(collisionThisExpressionAndVarInGlobal.ts, 1, 3))
>this : Symbol(globalThis)
@@ -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
@@ -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);
@@ -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
};
@@ -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.
@@ -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;
@@ -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;
@@ -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.
@@ -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;
@@ -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;
@@ -4,4 +4,5 @@ var obj = {
[this.bar]: 0
>[this.bar] : Symbol([this.bar], Decl(computedPropertyNames20_ES5.ts, 0, 11))
>this : Symbol(globalThis)
}
@@ -6,7 +6,7 @@ var obj = {
[this.bar]: 0
>[this.bar] : number
>this.bar : any
>this : any
>this : typeof globalThis
>bar : any
>0 : 0
}
@@ -4,4 +4,5 @@ var obj = {
[this.bar]: 0
>[this.bar] : Symbol([this.bar], Decl(computedPropertyNames20_ES6.ts, 0, 11))
>this : Symbol(globalThis)
}
@@ -6,7 +6,7 @@ var obj = {
[this.bar]: 0
>[this.bar] : number
>this.bar : any
>this : any
>this : typeof globalThis
>bar : any
>0 : 0
}
@@ -579,6 +579,7 @@ module TypeScriptAllInOne {
}
public method2() {
return 2 * this.method1(2);
>this : Symbol(globalThis)
}
}
@@ -869,7 +869,7 @@ module TypeScriptAllInOne {
>2 : 2
>this.method1(2) : any
>this.method1 : any
>this : any
>this : typeof globalThis
>method1 : any
>2 : 2
}
@@ -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;
});
@@ -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;
});
@@ -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
@@ -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;
});
@@ -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;
});
@@ -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
@@ -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))
});
@@ -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]
@@ -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))
@@ -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[]
@@ -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
@@ -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))
@@ -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
@@ -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.
@@ -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
@@ -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))
@@ -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
@@ -0,0 +1,5 @@
//// [globalThisTypeIndexAccess.ts]
declare const w_e: (typeof globalThis)["globalThis"]
//// [globalThisTypeIndexAccess.js]
@@ -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)
@@ -0,0 +1,5 @@
=== tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts ===
declare const w_e: (typeof globalThis)["globalThis"]
>w_e : typeof globalThis
>globalThis : typeof globalThis
@@ -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']
@@ -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'];
@@ -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)
@@ -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"
@@ -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.
@@ -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'];
@@ -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)
@@ -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"
@@ -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'.
@@ -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;
@@ -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, --, --))
@@ -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
@@ -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))
@@ -13,7 +13,7 @@ try { } catch (error) {
}
for (var key in this) { }
>key : string
>this : any
>this : typeof globalThis
class C {
>C : C
@@ -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 {
@@ -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
@@ -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))
</ListView>
@@ -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
@@ -39,6 +39,8 @@ declare var hasOwnProperty:any;
<div>
{this.props.children}
>this : Symbol(globalThis)
</div>;
<div>
@@ -57,6 +59,8 @@ declare var hasOwnProperty:any;
>Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 2, 11))
{this.props.children}
>this : Symbol(globalThis)
</Composite>;
>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))
<font-face />;
@@ -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
@@ -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<Role>) => data.data));
@@ -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
@@ -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; };
~~~~
@@ -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))
@@ -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
@@ -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)
@@ -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
>{} : {}
@@ -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.
>this : Symbol(globalThis)
>this : Symbol(globalThis)
>this : Symbol(globalThis)
@@ -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
@@ -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'.
}
@@ -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.
>this : Symbol(globalThis)
}
@@ -1,5 +1,5 @@
=== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts ===
for (this in b) {
>this : any
>this : typeof globalThis
>b : any
}
@@ -2,5 +2,6 @@
{
declare var x = this;
>x : Symbol(x, Decl(parserModifierOnStatementInBlock2.ts, 1, 14))
>this : Symbol(globalThis)
}
@@ -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
}
@@ -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.
delete this;
>this : Symbol(globalThis)
delete 1;
delete null;
delete "a";
@@ -4,7 +4,7 @@
delete this;
>delete this : boolean
>this : any
>this : typeof globalThis
delete 1;
>delete 1 : boolean
Loaded 100 of 167 files, more files were not shown because too many files have changed in this diff. Show more