diff --git a/.vscode/settings.template.json b/.vscode/settings.template.json index 71b1986cf1a46..9162a53f6b163 100644 --- a/.vscode/settings.template.json +++ b/.vscode/settings.template.json @@ -4,10 +4,11 @@ // To use the locally built compiler, after 'npm run build': // "typescript.tsdk": "built/local" - "[typescript][javascript][yaml]": { - "editor.formatOnSave": true, - "editor.defaultFormatter": "dprint.dprint" - }, + // Enables dprint formatting on all supported files. Setting this as the + // default for all file types is safe as dprint will just ignore any file + // it doesn't support or has explicitly excluded in .dprint.jsonc. + "editor.defaultFormatter": "dprint.dprint", + "editor.formatOnSave": true, // To ignore commits listed in .git-blame-ignore-revs in GitLens: "gitlens.advanced.blame.customArguments": [ diff --git a/package-lock.json b/package-lock.json index bb6aa9c83c486..1b309fb542baa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -937,15 +937,15 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.5.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.6.tgz", - "integrity": "sha512-Gi5wRGPbbyOTX+4Y2iULQ27oUPrefaB0PxGQJnfyWN3kvEDGM3mIB5M/gQLmitZf7A9FmLeaqxD3L1CXpm3VKQ==", + "version": "20.5.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.7.tgz", + "integrity": "sha512-dP7f3LdZIysZnmvP3ANJYTSwg+wLLl8p7RqniVlV7j+oXSXAbt9h0WIBFmJy5inWZoX9wZN6eXx+YXd9Rh3RBA==", "dev": true }, "node_modules/@types/semver": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz", - "integrity": "sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==", + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.1.tgz", + "integrity": "sha512-cJRQXpObxfNKkFAZbJl2yjWtJCqELQIdShsogr1d2MilP8dKD9TE/nEKHkJgUNHdGKCQaf9HbIynuV2csLGVLg==", "dev": true }, "node_modules/@types/source-map-support": { @@ -964,16 +964,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.4.1.tgz", - "integrity": "sha512-3F5PtBzUW0dYlq77Lcqo13fv+58KDwUib3BddilE8ajPJT+faGgxmI9Sw+I8ZS22BYwoir9ZhNXcLi+S+I2bkw==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.5.0.tgz", + "integrity": "sha512-2pktILyjvMaScU6iK3925uvGU87E+N9rh372uGZgiMYwafaw9SXq86U04XPq3UH6tzRvNgBsub6x2DacHc33lw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.4.1", - "@typescript-eslint/type-utils": "6.4.1", - "@typescript-eslint/utils": "6.4.1", - "@typescript-eslint/visitor-keys": "6.4.1", + "@typescript-eslint/scope-manager": "6.5.0", + "@typescript-eslint/type-utils": "6.5.0", + "@typescript-eslint/utils": "6.5.0", + "@typescript-eslint/visitor-keys": "6.5.0", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -999,15 +999,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.4.1.tgz", - "integrity": "sha512-610G6KHymg9V7EqOaNBMtD1GgpAmGROsmfHJPXNLCU9bfIuLrkdOygltK784F6Crboyd5tBFayPB7Sf0McrQwg==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.5.0.tgz", + "integrity": "sha512-LMAVtR5GN8nY0G0BadkG0XIe4AcNMeyEy3DyhKGAh9k4pLSMBO7rF29JvDBpZGCmp5Pgz5RLHP6eCpSYZJQDuQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.4.1", - "@typescript-eslint/types": "6.4.1", - "@typescript-eslint/typescript-estree": "6.4.1", - "@typescript-eslint/visitor-keys": "6.4.1", + "@typescript-eslint/scope-manager": "6.5.0", + "@typescript-eslint/types": "6.5.0", + "@typescript-eslint/typescript-estree": "6.5.0", + "@typescript-eslint/visitor-keys": "6.5.0", "debug": "^4.3.4" }, "engines": { @@ -1027,13 +1027,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.4.1.tgz", - "integrity": "sha512-p/OavqOQfm4/Hdrr7kvacOSFjwQ2rrDVJRPxt/o0TOWdFnjJptnjnZ+sYDR7fi4OimvIuKp+2LCkc+rt9fIW+A==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.5.0.tgz", + "integrity": "sha512-A8hZ7OlxURricpycp5kdPTH3XnjG85UpJS6Fn4VzeoH4T388gQJ/PGP4ole5NfKt4WDVhmLaQ/dBLNDC4Xl/Kw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.4.1", - "@typescript-eslint/visitor-keys": "6.4.1" + "@typescript-eslint/types": "6.5.0", + "@typescript-eslint/visitor-keys": "6.5.0" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1044,13 +1044,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.4.1.tgz", - "integrity": "sha512-7ON8M8NXh73SGZ5XvIqWHjgX2f+vvaOarNliGhjrJnv1vdjG0LVIz+ToYfPirOoBi56jxAKLfsLm40+RvxVVXA==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.5.0.tgz", + "integrity": "sha512-f7OcZOkRivtujIBQ4yrJNIuwyCQO1OjocVqntl9dgSIZAdKqicj3xFDqDOzHDlGCZX990LqhLQXWRnQvsapq8A==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.4.1", - "@typescript-eslint/utils": "6.4.1", + "@typescript-eslint/typescript-estree": "6.5.0", + "@typescript-eslint/utils": "6.5.0", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -1071,9 +1071,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.4.1.tgz", - "integrity": "sha512-zAAopbNuYu++ijY1GV2ylCsQsi3B8QvfPHVqhGdDcbx/NK5lkqMnCGU53amAjccSpk+LfeONxwzUhDzArSfZJg==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.5.0.tgz", + "integrity": "sha512-eqLLOEF5/lU8jW3Bw+8auf4lZSbbljHR2saKnYqON12G/WsJrGeeDHWuQePoEf9ro22+JkbPfWQwKEC5WwLQ3w==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -1084,13 +1084,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.4.1.tgz", - "integrity": "sha512-xF6Y7SatVE/OyV93h1xGgfOkHr2iXuo8ip0gbfzaKeGGuKiAnzS+HtVhSPx8Www243bwlW8IF7X0/B62SzFftg==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.5.0.tgz", + "integrity": "sha512-q0rGwSe9e5Kk/XzliB9h2LBc9tmXX25G0833r7kffbl5437FPWb2tbpIV9wAATebC/018pGa9fwPDuvGN+LxWQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.4.1", - "@typescript-eslint/visitor-keys": "6.4.1", + "@typescript-eslint/types": "6.5.0", + "@typescript-eslint/visitor-keys": "6.5.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -1111,17 +1111,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.4.1.tgz", - "integrity": "sha512-F/6r2RieNeorU0zhqZNv89s9bDZSovv3bZQpUNOmmQK1L80/cV4KEu95YUJWi75u5PhboFoKUJBnZ4FQcoqhDw==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.5.0.tgz", + "integrity": "sha512-9nqtjkNykFzeVtt9Pj6lyR9WEdd8npPhhIPM992FWVkZuS6tmxHfGVnlUcjpUP2hv8r4w35nT33mlxd+Be1ACQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.4.1", - "@typescript-eslint/types": "6.4.1", - "@typescript-eslint/typescript-estree": "6.4.1", + "@typescript-eslint/scope-manager": "6.5.0", + "@typescript-eslint/types": "6.5.0", + "@typescript-eslint/typescript-estree": "6.5.0", "semver": "^7.5.4" }, "engines": { @@ -1136,12 +1136,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.4.1.tgz", - "integrity": "sha512-y/TyRJsbZPkJIZQXrHfdnxVnxyKegnpEvnRGNam7s3TRR2ykGefEWOhaef00/UUN3IZxizS7BTO3svd3lCOJRQ==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.5.0.tgz", + "integrity": "sha512-yCB/2wkbv3hPsh02ZS8dFQnij9VVQXJMN/gbQsaaY+zxALkZnxa/wagvLEFsAWMPv7d7lxQmNsIzGU1w/T/WyA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.4.1", + "@typescript-eslint/types": "6.5.0", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -4423,15 +4423,15 @@ "dev": true }, "@types/node": { - "version": "20.5.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.6.tgz", - "integrity": "sha512-Gi5wRGPbbyOTX+4Y2iULQ27oUPrefaB0PxGQJnfyWN3kvEDGM3mIB5M/gQLmitZf7A9FmLeaqxD3L1CXpm3VKQ==", + "version": "20.5.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.5.7.tgz", + "integrity": "sha512-dP7f3LdZIysZnmvP3ANJYTSwg+wLLl8p7RqniVlV7j+oXSXAbt9h0WIBFmJy5inWZoX9wZN6eXx+YXd9Rh3RBA==", "dev": true }, "@types/semver": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.0.tgz", - "integrity": "sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==", + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.1.tgz", + "integrity": "sha512-cJRQXpObxfNKkFAZbJl2yjWtJCqELQIdShsogr1d2MilP8dKD9TE/nEKHkJgUNHdGKCQaf9HbIynuV2csLGVLg==", "dev": true }, "@types/source-map-support": { @@ -4450,16 +4450,16 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.4.1.tgz", - "integrity": "sha512-3F5PtBzUW0dYlq77Lcqo13fv+58KDwUib3BddilE8ajPJT+faGgxmI9Sw+I8ZS22BYwoir9ZhNXcLi+S+I2bkw==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.5.0.tgz", + "integrity": "sha512-2pktILyjvMaScU6iK3925uvGU87E+N9rh372uGZgiMYwafaw9SXq86U04XPq3UH6tzRvNgBsub6x2DacHc33lw==", "dev": true, "requires": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.4.1", - "@typescript-eslint/type-utils": "6.4.1", - "@typescript-eslint/utils": "6.4.1", - "@typescript-eslint/visitor-keys": "6.4.1", + "@typescript-eslint/scope-manager": "6.5.0", + "@typescript-eslint/type-utils": "6.5.0", + "@typescript-eslint/utils": "6.5.0", + "@typescript-eslint/visitor-keys": "6.5.0", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -4469,54 +4469,54 @@ } }, "@typescript-eslint/parser": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.4.1.tgz", - "integrity": "sha512-610G6KHymg9V7EqOaNBMtD1GgpAmGROsmfHJPXNLCU9bfIuLrkdOygltK784F6Crboyd5tBFayPB7Sf0McrQwg==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.5.0.tgz", + "integrity": "sha512-LMAVtR5GN8nY0G0BadkG0XIe4AcNMeyEy3DyhKGAh9k4pLSMBO7rF29JvDBpZGCmp5Pgz5RLHP6eCpSYZJQDuQ==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "6.4.1", - "@typescript-eslint/types": "6.4.1", - "@typescript-eslint/typescript-estree": "6.4.1", - "@typescript-eslint/visitor-keys": "6.4.1", + "@typescript-eslint/scope-manager": "6.5.0", + "@typescript-eslint/types": "6.5.0", + "@typescript-eslint/typescript-estree": "6.5.0", + "@typescript-eslint/visitor-keys": "6.5.0", "debug": "^4.3.4" } }, "@typescript-eslint/scope-manager": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.4.1.tgz", - "integrity": "sha512-p/OavqOQfm4/Hdrr7kvacOSFjwQ2rrDVJRPxt/o0TOWdFnjJptnjnZ+sYDR7fi4OimvIuKp+2LCkc+rt9fIW+A==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.5.0.tgz", + "integrity": "sha512-A8hZ7OlxURricpycp5kdPTH3XnjG85UpJS6Fn4VzeoH4T388gQJ/PGP4ole5NfKt4WDVhmLaQ/dBLNDC4Xl/Kw==", "dev": true, "requires": { - "@typescript-eslint/types": "6.4.1", - "@typescript-eslint/visitor-keys": "6.4.1" + "@typescript-eslint/types": "6.5.0", + "@typescript-eslint/visitor-keys": "6.5.0" } }, "@typescript-eslint/type-utils": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.4.1.tgz", - "integrity": "sha512-7ON8M8NXh73SGZ5XvIqWHjgX2f+vvaOarNliGhjrJnv1vdjG0LVIz+ToYfPirOoBi56jxAKLfsLm40+RvxVVXA==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.5.0.tgz", + "integrity": "sha512-f7OcZOkRivtujIBQ4yrJNIuwyCQO1OjocVqntl9dgSIZAdKqicj3xFDqDOzHDlGCZX990LqhLQXWRnQvsapq8A==", "dev": true, "requires": { - "@typescript-eslint/typescript-estree": "6.4.1", - "@typescript-eslint/utils": "6.4.1", + "@typescript-eslint/typescript-estree": "6.5.0", + "@typescript-eslint/utils": "6.5.0", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" } }, "@typescript-eslint/types": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.4.1.tgz", - "integrity": "sha512-zAAopbNuYu++ijY1GV2ylCsQsi3B8QvfPHVqhGdDcbx/NK5lkqMnCGU53amAjccSpk+LfeONxwzUhDzArSfZJg==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.5.0.tgz", + "integrity": "sha512-eqLLOEF5/lU8jW3Bw+8auf4lZSbbljHR2saKnYqON12G/WsJrGeeDHWuQePoEf9ro22+JkbPfWQwKEC5WwLQ3w==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.4.1.tgz", - "integrity": "sha512-xF6Y7SatVE/OyV93h1xGgfOkHr2iXuo8ip0gbfzaKeGGuKiAnzS+HtVhSPx8Www243bwlW8IF7X0/B62SzFftg==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.5.0.tgz", + "integrity": "sha512-q0rGwSe9e5Kk/XzliB9h2LBc9tmXX25G0833r7kffbl5437FPWb2tbpIV9wAATebC/018pGa9fwPDuvGN+LxWQ==", "dev": true, "requires": { - "@typescript-eslint/types": "6.4.1", - "@typescript-eslint/visitor-keys": "6.4.1", + "@typescript-eslint/types": "6.5.0", + "@typescript-eslint/visitor-keys": "6.5.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -4525,27 +4525,27 @@ } }, "@typescript-eslint/utils": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.4.1.tgz", - "integrity": "sha512-F/6r2RieNeorU0zhqZNv89s9bDZSovv3bZQpUNOmmQK1L80/cV4KEu95YUJWi75u5PhboFoKUJBnZ4FQcoqhDw==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.5.0.tgz", + "integrity": "sha512-9nqtjkNykFzeVtt9Pj6lyR9WEdd8npPhhIPM992FWVkZuS6tmxHfGVnlUcjpUP2hv8r4w35nT33mlxd+Be1ACQ==", "dev": true, "requires": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.4.1", - "@typescript-eslint/types": "6.4.1", - "@typescript-eslint/typescript-estree": "6.4.1", + "@typescript-eslint/scope-manager": "6.5.0", + "@typescript-eslint/types": "6.5.0", + "@typescript-eslint/typescript-estree": "6.5.0", "semver": "^7.5.4" } }, "@typescript-eslint/visitor-keys": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.4.1.tgz", - "integrity": "sha512-y/TyRJsbZPkJIZQXrHfdnxVnxyKegnpEvnRGNam7s3TRR2ykGefEWOhaef00/UUN3IZxizS7BTO3svd3lCOJRQ==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.5.0.tgz", + "integrity": "sha512-yCB/2wkbv3hPsh02ZS8dFQnij9VVQXJMN/gbQsaaY+zxALkZnxa/wagvLEFsAWMPv7d7lxQmNsIzGU1w/T/WyA==", "dev": true, "requires": { - "@typescript-eslint/types": "6.4.1", + "@typescript-eslint/types": "6.5.0", "eslint-visitor-keys": "^3.4.1" } }, diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fd69b99c1522d..8e49e18d4d1a3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -452,7 +452,6 @@ import { isAssignmentOperator, isAssignmentPattern, isAssignmentTarget, - isAsyncFunction, isAutoAccessorPropertyDeclaration, isAwaitExpression, isBinaryExpression, @@ -1918,6 +1917,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { var anyType = createIntrinsicType(TypeFlags.Any, "any"); var autoType = createIntrinsicType(TypeFlags.Any, "any", ObjectFlags.NonInferrableType); var wildcardType = createIntrinsicType(TypeFlags.Any, "any"); + var blockedStringType = createIntrinsicType(TypeFlags.Any, "any"); var errorType = createIntrinsicType(TypeFlags.Any, "error"); var unresolvedType = createIntrinsicType(TypeFlags.Any, "unresolved"); var nonInferrableAnyType = createIntrinsicType(TypeFlags.Any, "any", ObjectFlags.ContainsWideningType); @@ -3874,7 +3874,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function isSameScopeDescendentOf(initial: Node, parent: Node | undefined, stopAt: Node): boolean { return !!parent && !!findAncestor(initial, n => n === parent - || (n === stopAt || isFunctionLike(n) && (!getImmediatelyInvokedFunctionExpression(n) || isAsyncFunction(n)) ? "quit" : false)); + || (n === stopAt || isFunctionLike(n) && (!getImmediatelyInvokedFunctionExpression(n) || (getFunctionFlags(n) & FunctionFlags.AsyncGenerator)) ? "quit" : false)); } function getAnyImportSyntax(node: Node): AnyImportSyntax | undefined { @@ -8534,11 +8534,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ...oldcontext, usedSymbolNames: new Set(oldcontext.usedSymbolNames), remappedSymbolNames: new Map(), + remappedSymbolReferences: new Map(oldcontext.remappedSymbolReferences?.entries()), tracker: undefined!, }; const tracker: SymbolTracker = { ...oldcontext.tracker.inner, trackSymbol: (sym, decl, meaning) => { + if (context.remappedSymbolNames?.has(getSymbolId(sym))) return false; // If the context has a remapped name for the symbol, it *should* mean it's been made visible const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*shouldComputeAliasesToMakeVisible*/ false); if (accessibleResult.accessibility === SymbolAccessibility.Accessible) { // Lookup the root symbol of the chain of refs we'll use to access it and serialize it @@ -8791,9 +8793,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // If it's a property: emit `export default _default` with a `_default` prop // If it's a class/interface/function: emit a class/interface/function with a `default` modifier // These forms can merge, eg (`export default 12; export default interface A {}`) - function serializeSymbolWorker(symbol: Symbol, isPrivate: boolean, propertyAsAlias: boolean): void { - const symbolName = unescapeLeadingUnderscores(symbol.escapedName); - const isDefault = symbol.escapedName === InternalSymbolName.Default; + function serializeSymbolWorker(symbol: Symbol, isPrivate: boolean, propertyAsAlias: boolean, escapedSymbolName = symbol.escapedName): void { + const symbolName = unescapeLeadingUnderscores(escapedSymbolName); + const isDefault = escapedSymbolName === InternalSymbolName.Default; if (isPrivate && !(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier) && isStringANonContextualKeyword(symbolName) && !isDefault) { // Oh no. We cannot use this symbol's name as it's name... It's likely some jsdoc had an invalid name like `export` or `default` :( context.encounteredError = true; @@ -8812,7 +8814,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const modifierFlags = (!isPrivate ? ModifierFlags.Export : 0) | (isDefault && !needsPostExportDefault ? ModifierFlags.Default : 0); const isConstMergedWithNS = symbol.flags & SymbolFlags.Module && symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.FunctionScopedVariable | SymbolFlags.Property) && - symbol.escapedName !== InternalSymbolName.ExportEquals; + escapedSymbolName !== InternalSymbolName.ExportEquals; const isConstMergedWithNSPrintableAsSignatureMerge = isConstMergedWithNS && isTypeRepresentableAsFunctionNamespaceMerge(getTypeOfSymbol(symbol), symbol); if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) || isConstMergedWithNSPrintableAsSignatureMerge) { serializeAsFunctionNamespaceMerge(getTypeOfSymbol(symbol), symbol, getInternalSymbolName(symbol, symbolName), modifierFlags); @@ -8824,7 +8826,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // symbol of name `export=` which needs to be handled like an alias. It's not great, but it is what it is. if ( symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.FunctionScopedVariable | SymbolFlags.Property | SymbolFlags.Accessor) - && symbol.escapedName !== InternalSymbolName.ExportEquals + && escapedSymbolName !== InternalSymbolName.ExportEquals && !(symbol.flags & SymbolFlags.Prototype) && !(symbol.flags & SymbolFlags.Class) && !(symbol.flags & SymbolFlags.Method) @@ -8840,7 +8842,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else { const type = getTypeOfSymbol(symbol); const localName = getInternalSymbolName(symbol, symbolName); - if (!(symbol.flags & SymbolFlags.Function) && isTypeRepresentableAsFunctionNamespaceMerge(type, symbol)) { + if (type.symbol && type.symbol !== symbol && type.symbol.flags & SymbolFlags.Function && some(type.symbol.declarations, isFunctionExpressionOrArrowFunction) && (type.symbol.members?.size || type.symbol.exports?.size)) { + // assignment of a anonymous expando/class-like function, the func/ns/merge branch below won't trigger, + // and the assignment form has to reference the unreachable anonymous type so will error. + // Instead, serialize the type's symbol, but with the current symbol's name, rather than the anonymous one. + if (!context.remappedSymbolReferences) { + context.remappedSymbolReferences = new Map(); + } + context.remappedSymbolReferences.set(getSymbolId(type.symbol), symbol); // save name remapping as local name for target symbol + serializeSymbolWorker(type.symbol, isPrivate, propertyAsAlias, escapedSymbolName); + context.remappedSymbolReferences.delete(getSymbolId(type.symbol)); + } + else if (!(symbol.flags & SymbolFlags.Function) && isTypeRepresentableAsFunctionNamespaceMerge(type, symbol)) { // If the type looks like a function declaration + ns could represent it, and it's type is sourced locally, rewrite it into a function declaration + ns serializeAsFunctionNamespaceMerge(type, symbol, localName, modifierFlags); } @@ -10160,6 +10173,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { * It will also use a representation of a number as written instead of a decimal form, e.g. `0o11` instead of `9`. */ function getNameOfSymbolAsWritten(symbol: Symbol, context?: NodeBuilderContext): string { + if (context?.remappedSymbolReferences?.has(getSymbolId(symbol))) { + symbol = context.remappedSymbolReferences.get(getSymbolId(symbol))!; + } if ( context && symbol.escapedName === InternalSymbolName.Default && !(context.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope) && // If it's not the first part of an entity name, it must print as `default` @@ -12855,7 +12871,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const baseTypes = getBaseTypes(source); if (baseTypes.length) { if (source.symbol && members === getMembersOfSymbol(source.symbol)) { - members = createSymbolTable(source.declaredProperties); + const symbolTable = createSymbolTable(); + // copy all symbols (except type parameters), including the ones with internal names like `InternalSymbolName.Index` + for (const symbol of members.values()) { + if (!(symbol.flags & SymbolFlags.TypeParameter)) { + symbolTable.set(symbol.escapedName, symbol); + } + } + members = symbolTable; } setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos); const thisArgument = lastOrUndefined(typeArguments); @@ -19075,10 +19098,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function instantiateSymbol(symbol: Symbol, mapper: TypeMapper): Symbol { const links = getSymbolLinks(symbol); + // If the type of the symbol is already resolved, and if that type could not possibly + // be affected by instantiation, simply return the symbol itself. if (links.type && !couldContainTypeVariables(links.type)) { - // If the type of the symbol is already resolved, and if that type could not possibly - // be affected by instantiation, simply return the symbol itself. - return symbol; + if (!(symbol.flags & SymbolFlags.SetAccessor)) { + return symbol; + } + // If we're a setter, check writeType. + if (links.writeType && !couldContainTypeVariables(links.writeType)) { + return symbol; + } } if (getCheckFlags(symbol) & CheckFlags.Instantiated) { // If symbol being instantiated is itself a instantiation, fetch the original target and combine the @@ -25704,7 +25733,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const constraint = getConstraintOfTypeParameter(inference.typeParameter); if (constraint) { const instantiatedConstraint = instantiateType(constraint, context.nonFixingMapper); - if (!inferredType || inferredType === wildcardType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) { + if (!inferredType || inferredType === blockedStringType || !context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) { // If the fallback type satisfies the constraint, we pick it. Otherwise, we pick the constraint. inference.inferredType = fallbackType && context.compareTypes(fallbackType, getTypeWithThisArgument(instantiatedConstraint, fallbackType)) ? fallbackType : instantiatedConstraint; } @@ -32100,7 +32129,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } return isErrorType(apparentType) ? errorType : apparentType; } - prop = getPropertyOfType(apparentType, right.escapedText, /*skipObjectFunctionPropertyAugment*/ false, /*includeTypeOnlyMembers*/ node.kind === SyntaxKind.QualifiedName); + prop = getPropertyOfType(apparentType, right.escapedText, /*skipObjectFunctionPropertyAugment*/ isConstEnumObjectType(apparentType), /*includeTypeOnlyMembers*/ node.kind === SyntaxKind.QualifiedName); } // In `Foo.Bar.Baz`, 'Foo' is not referenced if 'Bar' is a const enum or a module containing only const enums. // `Foo` is also not referenced in `enum FooCopy { Bar = Foo.Bar }`, because the enum member value gets inlined @@ -35577,13 +35606,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const len = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0); for (let i = 0; i < len; i++) { const declaration = signature.parameters[i].valueDeclaration as ParameterDeclaration; - if (declaration.type) { - const typeNode = getEffectiveTypeAnnotationNode(declaration); - if (typeNode) { - const source = addOptionality(getTypeFromTypeNode(typeNode), /*isProperty*/ false, isOptionalDeclaration(declaration)); - const target = getTypeAtPosition(context, i); - inferTypes(inferenceContext.inferences, source, target); - } + const typeNode = getEffectiveTypeAnnotationNode(declaration); + if (typeNode) { + const source = addOptionality(getTypeFromTypeNode(typeNode), /*isProperty*/ false, isOptionalDeclaration(declaration)); + const target = getTypeAtPosition(context, i); + inferTypes(inferenceContext.inferences, source, target); } } } @@ -38520,7 +38547,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.StringLiteral: return hasSkipDirectInferenceFlag(node) ? - wildcardType : + blockedStringType : getFreshTypeOfLiteralType(getStringLiteralType((node as StringLiteralLike).text)); case SyntaxKind.NumericLiteral: { checkGrammarNumericLiteral(node as NumericLiteral); @@ -49987,6 +50014,7 @@ interface NodeBuilderContext { typeParameterNamesByTextNextNameCount?: Map; usedSymbolNames?: Set; remappedSymbolNames?: Map; + remappedSymbolReferences?: Map; reverseMappedStack?: ReverseMappedSymbol[]; } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 61058f8e8be26..4d754ed33e076 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -110,7 +110,6 @@ import { toFileNameLowerCase, toPath, tracing, - trimString, TsConfigOnlyOption, TsConfigSourceFile, TypeAcquisition, @@ -1699,13 +1698,13 @@ function createDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType } /** @internal */ -export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string, errors: Diagnostic[]) { - return convertJsonOptionOfCustomType(opt, trimString(value || ""), errors); +export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value: string | undefined, errors: Diagnostic[]) { + return convertJsonOptionOfCustomType(opt, (value ?? "").trim(), errors); } /** @internal */ export function parseListTypeOption(opt: CommandLineOptionOfListType, value = "", errors: Diagnostic[]): string | (string | number)[] | undefined { - value = trimString(value); + value = value.trim(); if (startsWith(value, "-")) { return undefined; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index fbd2432e9b79b..21eae040ba922 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -5,7 +5,6 @@ import { Comparison, Debug, EqualityComparer, - isWhiteSpaceLike, MapLike, Queue, SortedArray, @@ -2241,11 +2240,7 @@ export function getStringComparer(ignoreCase?: boolean) { * Creates a string comparer for use with string collation in the UI. */ const createUIStringComparer = (() => { - let defaultComparer: Comparer | undefined; - let enUSComparer: Comparer | undefined; - - const stringComparerFactory = getStringComparerFactory(); - return createStringComparer; + return createIntlCollatorStringComparer; function compareWithCallback(a: string | undefined, b: string | undefined, comparer: (a: string, b: string) => number) { if (a === b) return Comparison.EqualTo; @@ -2261,70 +2256,6 @@ const createUIStringComparer = (() => { const comparer = new Intl.Collator(locale, { usage: "sort", sensitivity: "variant" }).compare; return (a, b) => compareWithCallback(a, b, comparer); } - - function createLocaleCompareStringComparer(locale: string | undefined): Comparer { - // if the locale is not the default locale (`undefined`), use the fallback comparer. - if (locale !== undefined) return createFallbackStringComparer(); - - return (a, b) => compareWithCallback(a, b, compareStrings); - - function compareStrings(a: string, b: string) { - return a.localeCompare(b); - } - } - - function createFallbackStringComparer(): Comparer { - // An ordinal comparison puts "A" after "b", but for the UI we want "A" before "b". - // We first sort case insensitively. So "Aaa" will come before "baa". - // Then we sort case sensitively, so "aaa" will come before "Aaa". - // - // For case insensitive comparisons we always map both strings to their - // upper-case form as some unicode characters do not properly round-trip to - // lowercase (such as `ẞ` (German sharp capital s)). - return (a, b) => compareWithCallback(a, b, compareDictionaryOrder); - - function compareDictionaryOrder(a: string, b: string) { - return compareStrings(a.toUpperCase(), b.toUpperCase()) || compareStrings(a, b); - } - - function compareStrings(a: string, b: string) { - return a < b ? Comparison.LessThan : a > b ? Comparison.GreaterThan : Comparison.EqualTo; - } - } - - function getStringComparerFactory() { - // If the host supports Intl, we use it for comparisons using the default locale. - if (typeof Intl === "object" && typeof Intl.Collator === "function") { - return createIntlCollatorStringComparer; - } - - // If the host does not support Intl, we fall back to localeCompare. - // localeCompare in Node v0.10 is just an ordinal comparison, so don't use it. - if ( - typeof String.prototype.localeCompare === "function" && - typeof String.prototype.toLocaleUpperCase === "function" && - "a".localeCompare("B") < 0 - ) { - return createLocaleCompareStringComparer; - } - - // Otherwise, fall back to ordinal comparison: - return createFallbackStringComparer; - } - - function createStringComparer(locale: string | undefined) { - // Hold onto common string comparers. This avoids constantly reallocating comparers during - // tests. - if (locale === undefined) { - return defaultComparer || (defaultComparer = stringComparerFactory(locale)); - } - else if (locale === "en-US") { - return enUSComparer || (enUSComparer = stringComparerFactory(locale)); - } - else { - return stringComparerFactory(locale); - } - } })(); let uiComparerCaseSensitive: Comparer | undefined; @@ -2772,32 +2703,6 @@ function cartesianProductWorker(arrays: readonly (readonly T[])[], result: (r } } -/** - * Returns string left-padded with spaces or zeros until it reaches the given length. - * - * @param s String to pad. - * @param length Final padded length. If less than or equal to 's.length', returns 's' unchanged. - * @param padString Character to use as padding (default " "). - * - * @internal - */ -export function padLeft(s: string, length: number, padString: " " | "0" = " ") { - return length <= s.length ? s : padString.repeat(length - s.length) + s; -} - -/** - * Returns string right-padded with spaces until it reaches the given length. - * - * @param s String to pad. - * @param length Final padded length. If less than or equal to 's.length', returns 's' unchanged. - * @param padString Character to use as padding (default " "). - * - * @internal - */ -export function padRight(s: string, length: number, padString: " " = " ") { - return length <= s.length ? s : s + padString.repeat(length - s.length); -} - /** @internal */ export function takeWhile(array: readonly T[], predicate: (element: T) => element is U): U[]; /** @internal */ @@ -2829,42 +2734,6 @@ export function skipWhile(array: readonly T[] | undefined, predi } } -/** - * Removes the leading and trailing white space and line terminator characters from a string. - * - * @internal - */ -export const trimString = !!String.prototype.trim ? ((s: string) => s.trim()) : (s: string) => trimStringEnd(trimStringStart(s)); - -/** - * Returns a copy with trailing whitespace removed. - * - * @internal - */ -export const trimStringEnd = !!String.prototype.trimEnd ? ((s: string) => s.trimEnd()) : trimEndImpl; - -/** - * Returns a copy with leading whitespace removed. - * - * @internal - */ -export const trimStringStart = !!String.prototype.trimStart ? ((s: string) => s.trimStart()) : (s: string) => s.replace(/^\s+/g, ""); - -/** - * https://jsbench.me/gjkoxld4au/1 - * The simple regex for this, /\s+$/g is O(n^2) in v8. - * The native .trimEnd method is by far best, but since that's technically ES2019, - * we provide a (still much faster than the simple regex) fallback. - */ -function trimEndImpl(s: string) { - let end = s.length - 1; - while (end >= 0) { - if (!isWhiteSpaceLike(s.charCodeAt(end))) break; - end--; - } - return s.slice(0, end + 1); -} - /** @internal */ export function isNodeLikeSystem(): boolean { // This is defined here rather than in sys.ts to prevent a cycle from its diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ad0f132b4e5ab..6b900302c96df 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -368,8 +368,6 @@ import { tokenToString, tracing, TransformFlags, - trimString, - trimStringEnd, TryStatement, TupleTypeNode, TypeAliasDeclaration, @@ -8228,7 +8226,7 @@ namespace Parser { // If we are parsing a dotted namespace name, we want to // propagate the 'Namespace' flag across the names if set. const namespaceFlag = flags & NodeFlags.Namespace; - const name = parseIdentifier(); + const name = flags & NodeFlags.NestedNamespace ? parseIdentifierName() : parseIdentifier(); const body = parseOptional(SyntaxKind.DotToken) ? parseModuleOrNamespaceDeclaration(getNodePos(), /*hasJSDoc*/ false, /*modifiers*/ undefined, NodeFlags.NestedNamespace | namespaceFlag) as NamespaceDeclaration : parseModuleBlock(); @@ -8766,9 +8764,6 @@ namespace Parser { } function parseJSDocCommentWorker(start = 0, length: number | undefined): JSDoc | undefined { - const saveParsingContext = parsingContext; - parsingContext |= 1 << ParsingContext.JSDocComment; - const content = sourceText; const end = length === undefined ? content.length : start + length; length = end - start; @@ -8790,6 +8785,9 @@ namespace Parser { let comments: string[] = []; const parts: JSDocComment[] = []; + const saveParsingContext = parsingContext; + parsingContext |= 1 << ParsingContext.JSDocComment; + // + 3 for leading /**, - 5 in total for /** */ const result = scanner.scanRange(start + 3, length - 5, doJSDocScan); parsingContext = saveParsingContext; @@ -8895,7 +8893,7 @@ namespace Parser { nextTokenJSDoc(); } } - const trimmedComments = trimStringEnd(comments.join("")); + const trimmedComments = comments.join("").trimEnd(); if (parts.length && trimmedComments.length) { parts.push(finishNode(factory.createJSDocText(trimmedComments), linkEnd ?? start, commentsPos)); } @@ -8912,7 +8910,7 @@ namespace Parser { function removeTrailingWhitespace(comments: string[]) { while (comments.length) { - const trimmed = trimStringEnd(comments[comments.length - 1]); + const trimmed = comments[comments.length - 1].trimEnd(); if (trimmed === "") { comments.pop(); } @@ -9174,7 +9172,7 @@ namespace Parser { } removeLeadingNewlines(comments); - const trimmedComments = trimStringEnd(comments.join("")); + const trimmedComments = comments.join("").trimEnd(); if (parts.length) { if (trimmedComments.length) { parts.push(finishNode(factory.createJSDocText(trimmedComments), linkEnd ?? commentsPos)); @@ -10618,7 +10616,7 @@ function addPragmaForMatch(pragmas: PragmaPseudoMapEntry[], range: CommentRange, function getNamedPragmaArguments(pragma: PragmaDefinition, text: string | undefined): { [index: string]: string; } | "fail" { if (!text) return {}; if (!pragma.args) return {}; - const args = trimString(text).split(/\s+/); + const args = text.trim().split(/\s+/); const argMap: { [index: string]: string; } = {}; for (let i = 0; i < pragma.args.length; i++) { const argument = pragma.args[i]; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 294a0e7200702..13a3c37bc4126 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -250,7 +250,6 @@ import { packageIdToPackageName, packageIdToString, PackageJsonInfoCache, - padLeft, ParameterDeclaration, ParseConfigFileHost, ParsedCommandLine, @@ -318,7 +317,6 @@ import { toPath as ts_toPath, trace, tracing, - trimStringEnd, TsConfigSourceFile, TypeChecker, typeDirectiveIsEqualTo, @@ -722,22 +720,22 @@ function formatCodeSpan(file: SourceFile, start: number, length: number, indent: // If the error spans over 5 lines, we'll only show the first 2 and last 2 lines, // so we'll skip ahead to the second-to-last line. if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) { - context += indent + formatColorAndReset(padLeft(ellipsis, gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine(); + context += indent + formatColorAndReset(ellipsis.padStart(gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine(); i = lastLine - 1; } const lineStart = getPositionOfLineAndCharacter(file, i, 0); const lineEnd = i < lastLineInFile ? getPositionOfLineAndCharacter(file, i + 1, 0) : file.text.length; let lineContent = file.text.slice(lineStart, lineEnd); - lineContent = trimStringEnd(lineContent); // trim from end + lineContent = lineContent.trimEnd(); // trim from end lineContent = lineContent.replace(/\t/g, " "); // convert tabs to single spaces // Output the gutter and the actual contents of the line. - context += indent + formatColorAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator; + context += indent + formatColorAndReset((i + 1 + "").padStart(gutterWidth), gutterStyleSequence) + gutterSeparator; context += lineContent + host.getNewLine(); // Output the gutter and the error span for the line using tildes. - context += indent + formatColorAndReset(padLeft("", gutterWidth), gutterStyleSequence) + gutterSeparator; + context += indent + formatColorAndReset("".padStart(gutterWidth), gutterStyleSequence) + gutterSeparator; context += squiggleColor; if (i === firstLine) { // If we're on the last line, then limit it to the last character of the last line. diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 76eba96386352..5a519dc79dcfb 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -18,7 +18,6 @@ import { LanguageVariant, LineAndCharacter, MapLike, - padLeft, parsePseudoBigInt, positionIsSynthesized, PunctuationOrKeywordSyntaxKind, @@ -26,7 +25,6 @@ import { SourceFileLike, SyntaxKind, TokenFlags, - trimStringStart, } from "./_namespaces/ts"; export type ErrorCallback = (message: DiagnosticMessage, length: number, arg0?: any) => void; @@ -1490,7 +1488,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean tokenFlags |= TokenFlags.ContainsInvalidEscape; if (shouldEmitInvalidEscapeError) { const code = parseInt(text.substring(start + 1, pos), 8); - error(Diagnostics.Octal_escape_sequences_are_not_allowed_Use_the_syntax_0, start, pos - start, "\\x" + padLeft(code.toString(16), 2, "0")); + error(Diagnostics.Octal_escape_sequences_are_not_allowed_Use_the_syntax_0, start, pos - start, "\\x" + code.toString(16).padStart(2, "0")); return String.fromCharCode(code); } return text.substring(start, pos); @@ -2392,7 +2390,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean commentDirectiveRegEx: RegExp, lineStart: number, ) { - const type = getDirectiveFromComment(trimStringStart(text), commentDirectiveRegEx); + const type = getDirectiveFromComment(text.trimStart(), commentDirectiveRegEx); if (type === undefined) { return commentDirectives; } @@ -2793,25 +2791,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean } /** @internal */ -const codePointAt: (s: string, i: number) => number = (String.prototype as any).codePointAt ? (s, i) => (s as any).codePointAt(i) : function codePointAt(str, i): number { - // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt - const size = str.length; - // Account for out-of-bounds indices: - if (i < 0 || i >= size) { - return undefined!; // String.codePointAt returns `undefined` for OOB indexes - } - // Get the first code unit - const first = str.charCodeAt(i); - // check if it's the start of a surrogate pair - if (first >= 0xD800 && first <= 0xDBFF && size > i + 1) { // high surrogate and there is a next code unit - const second = str.charCodeAt(i + 1); - if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate - // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae - return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; - } - } - return first; -}; +function codePointAt(s: string, i: number): number { + // TODO(jakebailey): this is wrong and should have ?? 0; but all users are okay with it + return s.codePointAt(i)!; +} /** @internal */ function charSize(ch: number) { diff --git a/src/compiler/semver.ts b/src/compiler/semver.ts index 1c8af4fccab61..23573253459d5 100644 --- a/src/compiler/semver.ts +++ b/src/compiler/semver.ts @@ -8,7 +8,6 @@ import { isArray, map, some, - trimString, } from "./_namespaces/ts"; // https://semver.org/#spec-item-2 @@ -275,17 +274,17 @@ const rangeRegExp = /^(~|\^|<|<=|>|>=|=)?\s*([a-z0-9-+.*]+)$/i; function parseRange(text: string) { const alternatives: Comparator[][] = []; - for (let range of trimString(text).split(logicalOrRegExp)) { + for (let range of text.trim().split(logicalOrRegExp)) { if (!range) continue; const comparators: Comparator[] = []; - range = trimString(range); + range = range.trim(); const match = hyphenRegExp.exec(range); if (match) { if (!parseHyphen(match[1], match[2], comparators)) return undefined; } else { for (const simple of range.split(whitespaceRegExp)) { - const match = rangeRegExp.exec(trimString(simple)); + const match = rangeRegExp.exec(simple.trim()); if (!match || !parseComparator(match[1], match[2], comparators)) return undefined; } } diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index fedc66d6e77c9..6a5af5699b3f4 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -24,7 +24,6 @@ import { sortAndDeduplicate, SortedReadonlyArray, SourceMapGenerator, - trimStringEnd, } from "./_namespaces/ts"; import * as performance from "./_namespaces/ts.performance"; @@ -392,7 +391,7 @@ export function tryGetSourceMappingURL(lineInfo: LineInfo) { const line = lineInfo.getLineText(index); const comment = sourceMapCommentRegExp.exec(line); if (comment) { - return trimStringEnd(comment[1]); + return comment[1].trimEnd(); } // If we see a non-whitespace/map comment-like line, break, to avoid scanning up the entire file else if (!line.match(whitespaceOrMapCommentRegExp)) { diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 048615abb1f13..aa8ab4f9fbee0 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -100,6 +100,7 @@ import { isBindingPattern, isClassDeclaration, isClassElement, + isComputedPropertyName, isDeclaration, isElementAccessExpression, isEntityName, @@ -701,6 +702,9 @@ export function transformDeclarations(context: TransformationContext) { if (elem.kind === SyntaxKind.OmittedExpression) { return elem; } + if (elem.propertyName && isComputedPropertyName(elem.propertyName) && isEntityNameExpression(elem.propertyName.expression)) { + checkEntityNameVisibility(elem.propertyName.expression, enclosingDeclaration); + } if (elem.propertyName && isIdentifier(elem.propertyName) && isIdentifier(elem.name) && !elem.symbol.isReferenced && !isIdentifierANonContextualKeyword(elem.propertyName)) { // Unnecessary property renaming is forbidden in types, so remove renaming return factory.updateBindingElement( diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bd5958feaf660..960494f8a9abe 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -521,8 +521,6 @@ import { tracing, TransformFlags, TransientSymbol, - trimString, - trimStringStart, TriviaSyntaxKind, tryCast, tryRemovePrefix, @@ -1231,7 +1229,7 @@ export function getTextOfNodeFromSourceText(sourceText: string, node: Node, incl if (isJSDocTypeExpressionOrChild(node)) { // strip space + asterisk at line start - text = text.split(/\r\n|\n|\r/).map(line => trimStringStart(line.replace(/^\s*\*/, ""))).join("\n"); + text = text.split(/\r\n|\n|\r/).map(line => line.replace(/^\s*\*/, "").trimStart()).join("\n"); } return text; @@ -6828,7 +6826,7 @@ export function writeCommentRange(text: string, lineMap: readonly number[], writ function writeTrimmedCurrentLine(text: string, commentEnd: number, writer: EmitTextWriter, newLine: string, pos: number, nextLineStart: number) { const end = Math.min(commentEnd, nextLineStart - 1); - const currentLineText = trimString(text.substring(pos, end)); + const currentLineText = text.substring(pos, end).trim(); if (currentLineText) { // trimmed forward and ending spaces text writer.writeComment(currentLineText); diff --git a/src/executeCommandLine/executeCommandLine.ts b/src/executeCommandLine/executeCommandLine.ts index 8417f15944241..e7b2a1167a19d 100644 --- a/src/executeCommandLine/executeCommandLine.ts +++ b/src/executeCommandLine/executeCommandLine.ts @@ -61,8 +61,6 @@ import { optionDeclarations, optionsForBuild, optionsForWatch, - padLeft, - padRight, parseBuildCommand, parseCommandLine, parseConfigFileWithSystem, @@ -329,12 +327,12 @@ function generateOptionOutput(sys: System, option: CommandLineOption, rightAlign while (remainRight.length > 0) { let curLeft = ""; if (isFirstLine) { - curLeft = padLeft(left, rightAlignOfLeft); - curLeft = padRight(curLeft, leftAlignOfRight); + curLeft = left.padStart(rightAlignOfLeft); + curLeft = curLeft.padEnd(leftAlignOfRight); curLeft = colorLeft ? colors.blue(curLeft) : curLeft; } else { - curLeft = padLeft("", leftAlignOfRight); + curLeft = "".padStart(leftAlignOfRight); } const curRight = remainRight.substr(0, rightCharacterNumber); @@ -524,15 +522,15 @@ function getHeader(sys: System, message: string) { const terminalWidth = sys.getWidthOfTerminal?.() ?? 0; const tsIconLength = 5; - const tsIconFirstLine = colors.blueBackground(padLeft("", tsIconLength)); - const tsIconSecondLine = colors.blueBackground(colors.brightWhite(padLeft("TS ", tsIconLength))); + const tsIconFirstLine = colors.blueBackground("".padStart(tsIconLength)); + const tsIconSecondLine = colors.blueBackground(colors.brightWhite("TS ".padStart(tsIconLength))); // If we have enough space, print TS icon. if (terminalWidth >= message.length + tsIconLength) { // right align of the icon is 120 at most. const rightAlign = terminalWidth > 120 ? 120 : terminalWidth; const leftAlign = rightAlign - tsIconLength; - header.push(padRight(message, leftAlign) + tsIconFirstLine + sys.newLine); - header.push(padLeft("", leftAlign) + tsIconSecondLine + sys.newLine); + header.push(message.padEnd(leftAlign) + tsIconFirstLine + sys.newLine); + header.push("".padStart(leftAlign) + tsIconSecondLine + sys.newLine); } else { header.push(message + sys.newLine); @@ -1261,7 +1259,7 @@ function reportAllStatistics(sys: System, statistics: Statistic[]) { } for (const s of statistics) { - sys.write(padRight(s.name + ":", nameSize + 2) + padLeft(statisticValue(s).toString(), valueSize) + sys.newLine); + sys.write(`${s.name}:`.padEnd(nameSize + 2) + statisticValue(s).toString().padStart(valueSize) + sys.newLine); } } diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 8f9a5e5738f36..1f5f83fb8ff9a 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -2120,7 +2120,7 @@ export class TestState { const output: string[] = []; for (let lineNumber = contextStart.line; lineNumber <= contextEnd.line; lineNumber++) { const spanLine = contextString.substring(contextLineMap[lineNumber], contextLineMap[lineNumber + 1]); - output.push(lineNumbers ? `${ts.padLeft(`${lineNumber + 1}: `, lineNumberPrefixLength)}${spanLine}` : spanLine); + output.push(lineNumbers ? `${`${lineNumber + 1}: `.padStart(lineNumberPrefixLength)}${spanLine}` : spanLine); if (selection) { if (lineNumber < selectionStart.line || lineNumber > selectionEnd.line) { continue; diff --git a/src/jsTyping/shared.ts b/src/jsTyping/shared.ts index 3330d12afb15f..09deb0fc2c56b 100644 --- a/src/jsTyping/shared.ts +++ b/src/jsTyping/shared.ts @@ -1,5 +1,4 @@ import { - padLeft, sys, } from "./_namespaces/ts"; @@ -64,5 +63,5 @@ export function findArgument(argumentName: string): string | undefined { export function nowString() { // E.g. "12:34:56.789" const d = new Date(); - return `${padLeft(d.getHours().toString(), 2, "0")}:${padLeft(d.getMinutes().toString(), 2, "0")}:${padLeft(d.getSeconds().toString(), 2, "0")}.${padLeft(d.getMilliseconds().toString(), 3, "0")}`; + return `${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}:${d.getSeconds().toString().padStart(2, "0")}.${d.getMilliseconds().toString().padStart(3, "0")}`; } diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 91e0573993e08..977979c69b1f8 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -52,8 +52,6 @@ import { SyntaxKind, TemplateExpression, TextSpan, - trimString, - trimStringStart, TryStatement, } from "./_namespaces/ts"; @@ -164,11 +162,11 @@ const regionDelimiterRegExp = /^#(end)?region(?:\s+(.*))?(?:\r)?$/; function isRegionDelimiter(lineText: string) { // We trim the leading whitespace and // without the regex since the // multiple potential whitespace matches can make for some gnarly backtracking behavior - lineText = trimStringStart(lineText); + lineText = lineText.trimStart(); if (!startsWith(lineText, "//")) { return null; // eslint-disable-line no-null/no-null } - lineText = trimString(lineText.slice(2)); + lineText = lineText.slice(2).trim(); return regionDelimiterRegExp.exec(lineText); } diff --git a/src/testRunner/unittests/canWatch.ts b/src/testRunner/unittests/canWatch.ts index 1c0738e7aec94..0d25ee03f5685 100644 --- a/src/testRunner/unittests/canWatch.ts +++ b/src/testRunner/unittests/canWatch.ts @@ -190,7 +190,7 @@ describe("unittests:: canWatch::", () => { let result = "|"; let divider = addDivider ? "|" : undefined; columns.forEach((header, index) => { - result += " " + ts.padRight(header, maxLengths[index]) + " |"; + result += " " + header.padEnd(maxLengths[index]) + " |"; if (addDivider) divider += " " + "-".repeat(maxLengths[index]) + " |"; }); baseline.push(result); diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.errors.txt b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.errors.txt new file mode 100644 index 0000000000000..32d0fa85f966d --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.errors.txt @@ -0,0 +1,27 @@ +ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,1): error TS2304: Cannot find name 'declare'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,9): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`. +ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,16): error TS2819: Namespace name cannot be 'debugger'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts(11,25): error TS1005: ';' expected. + + +==== ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts (4 errors) ==== + // https://github.com/microsoft/TypeScript/issues/7840 + + declare module chrome.debugger { + declare var tabId: number; + } + + export const tabId = chrome.debugger.tabId; + + declare module test.class {} + + declare module debugger {} // still an error + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~~ +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`. + ~~~~~~~~ +!!! error TS2819: Namespace name cannot be 'debugger'. + ~ +!!! error TS1005: ';' expected. + \ No newline at end of file diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.js b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.js new file mode 100644 index 0000000000000..8066fd7de6b57 --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.js @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] //// + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] +// https://github.com/microsoft/TypeScript/issues/7840 + +declare module chrome.debugger { + declare var tabId: number; +} + +export const tabId = chrome.debugger.tabId; + +declare module test.class {} + +declare module debugger {} // still an error + + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/7840 +Object.defineProperty(exports, "__esModule", { value: true }); +exports.tabId = void 0; +exports.tabId = chrome.debugger.tabId; +declare; +module; +debugger; +{ } // still an error + + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath.d.ts] +export declare const tabId: number; diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.symbols b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.symbols new file mode 100644 index 0000000000000..353e1d3c7e1e7 --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.symbols @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] //// + +=== ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts === +// https://github.com/microsoft/TypeScript/issues/7840 + +declare module chrome.debugger { +>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 0, 0)) +>debugger : Symbol(debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 2, 22)) + + declare var tabId: number; +>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 3, 15)) +} + +export const tabId = chrome.debugger.tabId; +>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 6, 12)) +>chrome.debugger.tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 3, 15)) +>chrome.debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 2, 22)) +>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 0, 0)) +>debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 2, 22)) +>tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 3, 15)) + +declare module test.class {} +>test : Symbol(test, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 6, 43)) +>class : Symbol(class, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts, 8, 20)) + +declare module debugger {} // still an error + diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.types b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.types new file mode 100644 index 0000000000000..d3d2470edc09d --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath.types @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts] //// + +=== ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts === +// https://github.com/microsoft/TypeScript/issues/7840 + +declare module chrome.debugger { +>chrome : typeof chrome +>debugger : typeof debugger + + declare var tabId: number; +>tabId : number +} + +export const tabId = chrome.debugger.tabId; +>tabId : number +>chrome.debugger.tabId : number +>chrome.debugger : typeof chrome.debugger +>chrome : typeof chrome +>debugger : typeof chrome.debugger +>tabId : number + +declare module test.class {} + +declare module debugger {} // still an error +>declare : any +>module : any + diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.errors.txt b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.errors.txt new file mode 100644 index 0000000000000..3cce670b6fc12 --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.errors.txt @@ -0,0 +1,25 @@ +ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,1): error TS2304: Cannot find name 'declare'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,9): error TS2304: Cannot find name 'namespace'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,19): error TS2819: Namespace name cannot be 'debugger'. +ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts(9,28): error TS1005: ';' expected. + + +==== ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts (4 errors) ==== + declare namespace chrome.debugger { + declare var tabId: number; + } + + export const tabId = chrome.debugger.tabId; + + declare namespace test.class {} + + declare namespace debugger {} // still an error + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~~~~~ +!!! error TS2304: Cannot find name 'namespace'. + ~~~~~~~~ +!!! error TS2819: Namespace name cannot be 'debugger'. + ~ +!!! error TS1005: ';' expected. + \ No newline at end of file diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.js b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.js new file mode 100644 index 0000000000000..1751a8d5c967e --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] //// + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] +declare namespace chrome.debugger { + declare var tabId: number; +} + +export const tabId = chrome.debugger.tabId; + +declare namespace test.class {} + +declare namespace debugger {} // still an error + + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.tabId = void 0; +exports.tabId = chrome.debugger.tabId; +declare; +namespace; +debugger; +{ } // still an error + + +//// [ambientModuleDeclarationWithReservedIdentifierInDottedPath2.d.ts] +export declare const tabId: number; diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.symbols b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.symbols new file mode 100644 index 0000000000000..2b61ab650343f --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.symbols @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] //// + +=== ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts === +declare namespace chrome.debugger { +>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 0)) +>debugger : Symbol(debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 25)) + + declare var tabId: number; +>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 1, 15)) +} + +export const tabId = chrome.debugger.tabId; +>tabId : Symbol(tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 4, 12)) +>chrome.debugger.tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 1, 15)) +>chrome.debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 25)) +>chrome : Symbol(chrome, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 0)) +>debugger : Symbol(chrome.debugger, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 0, 25)) +>tabId : Symbol(chrome.debugger.tabId, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 1, 15)) + +declare namespace test.class {} +>test : Symbol(test, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 4, 43)) +>class : Symbol(class, Decl(ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts, 6, 23)) + +declare namespace debugger {} // still an error + diff --git a/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.types b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.types new file mode 100644 index 0000000000000..57367d2f26bcd --- /dev/null +++ b/tests/baselines/reference/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.types @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts] //// + +=== ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts === +declare namespace chrome.debugger { +>chrome : typeof chrome +>debugger : typeof debugger + + declare var tabId: number; +>tabId : number +} + +export const tabId = chrome.debugger.tabId; +>tabId : number +>chrome.debugger.tabId : number +>chrome.debugger : typeof chrome.debugger +>chrome : typeof chrome +>debugger : typeof chrome.debugger +>tabId : number + +declare namespace test.class {} + +declare namespace debugger {} // still an error +>declare : any +>namespace : any + diff --git a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.errors.txt b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.errors.txt index 771b237e28a22..c9ff8364382f9 100644 --- a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.errors.txt +++ b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.errors.txt @@ -164,4 +164,19 @@ blockScopedVariablesUseBeforeDef.ts(122,22): error TS2448: Block-scoped variable const foo = 1; } + + // #30907 + function wrapI1() { + const iter = (function* foo() { + iter; + yield 1; + })(); + } + + function wrapI2() { + const iter = (async function* foo() { + iter; + yield 1; + })(); + } \ No newline at end of file diff --git a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.js b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.js index 04274491f5a9f..0c1bca18f01ef 100644 --- a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.js +++ b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.js @@ -136,6 +136,21 @@ function foo17() { const foo = 1; } + +// #30907 +function wrapI1() { + const iter = (function* foo() { + iter; + yield 1; + })(); +} + +function wrapI2() { + const iter = (async function* foo() { + iter; + yield 1; + })(); +} //// [blockScopedVariablesUseBeforeDef.js] @@ -179,6 +194,18 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name }); }; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; function foo0() { var a = x; var x; @@ -329,3 +356,35 @@ function foo17() { }); })(); var foo = 1; } +// #30907 +function wrapI1() { + var iter = (function foo() { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + iter; + return [4 /*yield*/, 1]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + })(); +} +function wrapI2() { + var iter = (function foo() { + return __asyncGenerator(this, arguments, function foo_1() { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + iter; + return [4 /*yield*/, __await(1)]; + case 1: return [4 /*yield*/, _a.sent()]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); + })(); +} diff --git a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.symbols b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.symbols index a64201efe26d1..5821664b5a71e 100644 --- a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.symbols +++ b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.symbols @@ -283,3 +283,32 @@ function foo17() { >foo : Symbol(foo, Decl(blockScopedVariablesUseBeforeDef.ts, 133, 9)) } +// #30907 +function wrapI1() { +>wrapI1 : Symbol(wrapI1, Decl(blockScopedVariablesUseBeforeDef.ts, 134, 1)) + + const iter = (function* foo() { +>iter : Symbol(iter, Decl(blockScopedVariablesUseBeforeDef.ts, 138, 9)) +>foo : Symbol(foo, Decl(blockScopedVariablesUseBeforeDef.ts, 138, 18)) + + iter; +>iter : Symbol(iter, Decl(blockScopedVariablesUseBeforeDef.ts, 138, 9)) + + yield 1; + })(); +} + +function wrapI2() { +>wrapI2 : Symbol(wrapI2, Decl(blockScopedVariablesUseBeforeDef.ts, 142, 1)) + + const iter = (async function* foo() { +>iter : Symbol(iter, Decl(blockScopedVariablesUseBeforeDef.ts, 145, 9)) +>foo : Symbol(foo, Decl(blockScopedVariablesUseBeforeDef.ts, 145, 18)) + + iter; +>iter : Symbol(iter, Decl(blockScopedVariablesUseBeforeDef.ts, 145, 9)) + + yield 1; + })(); +} + diff --git a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.types b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.types index 2bfda8a687b05..9446d9999efa5 100644 --- a/tests/baselines/reference/blockScopedVariablesUseBeforeDef.types +++ b/tests/baselines/reference/blockScopedVariablesUseBeforeDef.types @@ -320,3 +320,44 @@ function foo17() { >1 : 1 } +// #30907 +function wrapI1() { +>wrapI1 : () => void + + const iter = (function* foo() { +>iter : Generator +>(function* foo() { iter; yield 1; })() : Generator +>(function* foo() { iter; yield 1; }) : () => Generator +>function* foo() { iter; yield 1; } : () => Generator +>foo : () => Generator + + iter; +>iter : Generator + + yield 1; +>yield 1 : any +>1 : 1 + + })(); +} + +function wrapI2() { +>wrapI2 : () => void + + const iter = (async function* foo() { +>iter : AsyncGenerator +>(async function* foo() { iter; yield 1; })() : AsyncGenerator +>(async function* foo() { iter; yield 1; }) : () => AsyncGenerator +>async function* foo() { iter; yield 1; } : () => AsyncGenerator +>foo : () => AsyncGenerator + + iter; +>iter : AsyncGenerator + + yield 1; +>yield 1 : any +>1 : 1 + + })(); +} + diff --git a/tests/baselines/reference/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.symbols b/tests/baselines/reference/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.symbols new file mode 100644 index 0000000000000..dca9748d6539b --- /dev/null +++ b/tests/baselines/reference/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.symbols @@ -0,0 +1,75 @@ +//// [tests/cases/compiler/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts] //// + +=== classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts === +interface IObserver { +>IObserver : Symbol(IObserver, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 0, 0)) + + handleChange(observable: IObservable, change: TChange): void; +>handleChange : Symbol(IObserver.handleChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 0, 21)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 1, 14)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 1, 16)) +>observable : Symbol(observable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 1, 26)) +>IObservable : Symbol(IObservable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 2, 1)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 1, 14)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 1, 16)) +>change : Symbol(change, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 1, 62)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 1, 16)) +} + +interface IObservable { +>IObservable : Symbol(IObservable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 2, 1)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 4, 22)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 4, 24), Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 5, 10)) + + get(): T; +>get : Symbol(IObservable.get, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 4, 45)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 4, 22)) + + readonly TChange: TChange; +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 4, 24), Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 5, 10)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 4, 24), Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 5, 10)) +} + +export interface IReader { +>IReader : Symbol(IReader, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 7, 1)) + + readObservable(observable: IObservable): T; +>readObservable : Symbol(IReader.readObservable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 9, 26)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 10, 16)) +>observable : Symbol(observable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 10, 19)) +>IObservable : Symbol(IObservable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 2, 1)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 10, 16)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 10, 16)) +} + +export abstract class ConvenientObservable implements IObservable { +>ConvenientObservable : Symbol(ConvenientObservable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 11, 1)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 43)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 45), Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 91)) +>IObservable : Symbol(IObservable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 2, 1)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 43)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 45), Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 91)) + + get TChange(): TChange { return null!; } +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 45), Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 91)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 45), Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 91)) + + public abstract get(): T; +>get : Symbol(ConvenientObservable.get, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 14, 41)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 13, 43)) +} + +export abstract class BaseObservable extends ConvenientObservable { +>BaseObservable : Symbol(BaseObservable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 16, 1)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 18, 37)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 18, 39)) +>ConvenientObservable : Symbol(ConvenientObservable, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 11, 1)) +>T : Symbol(T, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 18, 37)) +>TChange : Symbol(TChange, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 18, 39)) + + protected readonly observers = new Set(); +>observers : Symbol(BaseObservable.observers, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 18, 98)) +>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>IObserver : Symbol(IObserver, Decl(classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts, 0, 0)) +} + diff --git a/tests/baselines/reference/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.types b/tests/baselines/reference/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.types new file mode 100644 index 0000000000000..706dc2d2a501f --- /dev/null +++ b/tests/baselines/reference/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.types @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts] //// + +=== classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts === +interface IObserver { + handleChange(observable: IObservable, change: TChange): void; +>handleChange : (observable: IObservable, change: TChange) => void +>observable : IObservable +>change : TChange +} + +interface IObservable { + get(): T; +>get : () => T + + readonly TChange: TChange; +>TChange : TChange +} + +export interface IReader { + readObservable(observable: IObservable): T; +>readObservable : (observable: IObservable) => T +>observable : IObservable +} + +export abstract class ConvenientObservable implements IObservable { +>ConvenientObservable : ConvenientObservable + + get TChange(): TChange { return null!; } +>TChange : TChange +>null! : never + + public abstract get(): T; +>get : () => T +} + +export abstract class BaseObservable extends ConvenientObservable { +>BaseObservable : BaseObservable +>ConvenientObservable : ConvenientObservable + + protected readonly observers = new Set(); +>observers : Set +>new Set() : Set +>Set : SetConstructor +} + diff --git a/tests/baselines/reference/computedPropertyNameWithImportedKey.js b/tests/baselines/reference/computedPropertyNameWithImportedKey.js new file mode 100644 index 0000000000000..7854938f7c522 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNameWithImportedKey.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/computedPropertyNameWithImportedKey.ts] //// + +//// [a.ts] +export const a = Symbol(); + +//// [b.ts] +import { a } from "./a"; +export function fn({ [a]: value }: any): string { + return value; +} + + +//// [a.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = void 0; +exports.a = Symbol(); +//// [b.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.fn = void 0; +var a_1 = require("./a"); +function fn(_a) { + var _b = a_1.a, value = _a[_b]; + return value; +} +exports.fn = fn; + + +//// [a.d.ts] +export declare const a: unique symbol; +//// [b.d.ts] +import { a } from "./a"; +export declare function fn({ [a]: value }: any): string; diff --git a/tests/baselines/reference/computedPropertyNameWithImportedKey.symbols b/tests/baselines/reference/computedPropertyNameWithImportedKey.symbols new file mode 100644 index 0000000000000..ba006a9861328 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNameWithImportedKey.symbols @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/computedPropertyNameWithImportedKey.ts] //// + +=== /a.ts === +export const a = Symbol(); +>a : Symbol(a, Decl(a.ts, 0, 12)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +=== /b.ts === +import { a } from "./a"; +>a : Symbol(a, Decl(b.ts, 0, 8)) + +export function fn({ [a]: value }: any): string { +>fn : Symbol(fn, Decl(b.ts, 0, 24)) +>a : Symbol(a, Decl(b.ts, 0, 8)) +>value : Symbol(value, Decl(b.ts, 1, 20)) + + return value; +>value : Symbol(value, Decl(b.ts, 1, 20)) +} + diff --git a/tests/baselines/reference/computedPropertyNameWithImportedKey.types b/tests/baselines/reference/computedPropertyNameWithImportedKey.types new file mode 100644 index 0000000000000..2058f5b58ce4d --- /dev/null +++ b/tests/baselines/reference/computedPropertyNameWithImportedKey.types @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/computedPropertyNameWithImportedKey.ts] //// + +=== /a.ts === +export const a = Symbol(); +>a : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +=== /b.ts === +import { a } from "./a"; +>a : unique symbol + +export function fn({ [a]: value }: any): string { +>fn : ({ [a]: value }: any) => string +>a : unique symbol +>value : any + + return value; +>value : any +} + diff --git a/tests/baselines/reference/constEnumNoObjectPrototypePropertyAccess.errors.txt b/tests/baselines/reference/constEnumNoObjectPrototypePropertyAccess.errors.txt new file mode 100644 index 0000000000000..ffc10079bb16b --- /dev/null +++ b/tests/baselines/reference/constEnumNoObjectPrototypePropertyAccess.errors.txt @@ -0,0 +1,36 @@ +constEnumNoObjectPrototypePropertyAccess.ts(5,19): error TS2339: Property 'constructor' does not exist on type 'typeof Bebra'. +constEnumNoObjectPrototypePropertyAccess.ts(6,19): error TS2339: Property 'hasOwnProperty' does not exist on type 'typeof Bebra'. +constEnumNoObjectPrototypePropertyAccess.ts(7,19): error TS2339: Property 'isPrototypeOf' does not exist on type 'typeof Bebra'. +constEnumNoObjectPrototypePropertyAccess.ts(8,19): error TS2339: Property 'propertyIsEnumerable' does not exist on type 'typeof Bebra'. +constEnumNoObjectPrototypePropertyAccess.ts(9,19): error TS2339: Property 'toLocaleString' does not exist on type 'typeof Bebra'. +constEnumNoObjectPrototypePropertyAccess.ts(10,19): error TS2339: Property 'toString' does not exist on type 'typeof Bebra'. +constEnumNoObjectPrototypePropertyAccess.ts(11,19): error TS2339: Property 'valueOf' does not exist on type 'typeof Bebra'. + + +==== constEnumNoObjectPrototypePropertyAccess.ts (7 errors) ==== + // https://github.com/microsoft/TypeScript/issues/55421 + + const enum Bebra {} + + console.log(Bebra.constructor) + ~~~~~~~~~~~ +!!! error TS2339: Property 'constructor' does not exist on type 'typeof Bebra'. + console.log(Bebra.hasOwnProperty) + ~~~~~~~~~~~~~~ +!!! error TS2339: Property 'hasOwnProperty' does not exist on type 'typeof Bebra'. + console.log(Bebra.isPrototypeOf) + ~~~~~~~~~~~~~ +!!! error TS2339: Property 'isPrototypeOf' does not exist on type 'typeof Bebra'. + console.log(Bebra.propertyIsEnumerable) + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2339: Property 'propertyIsEnumerable' does not exist on type 'typeof Bebra'. + console.log(Bebra.toLocaleString) + ~~~~~~~~~~~~~~ +!!! error TS2339: Property 'toLocaleString' does not exist on type 'typeof Bebra'. + console.log(Bebra.toString) + ~~~~~~~~ +!!! error TS2339: Property 'toString' does not exist on type 'typeof Bebra'. + console.log(Bebra.valueOf) + ~~~~~~~ +!!! error TS2339: Property 'valueOf' does not exist on type 'typeof Bebra'. + \ No newline at end of file diff --git a/tests/baselines/reference/constEnumNoObjectPrototypePropertyAccess.symbols b/tests/baselines/reference/constEnumNoObjectPrototypePropertyAccess.symbols new file mode 100644 index 0000000000000..c018043eab648 --- /dev/null +++ b/tests/baselines/reference/constEnumNoObjectPrototypePropertyAccess.symbols @@ -0,0 +1,50 @@ +//// [tests/cases/conformance/constEnums/constEnumNoObjectPrototypePropertyAccess.ts] //// + +=== constEnumNoObjectPrototypePropertyAccess.ts === +// https://github.com/microsoft/TypeScript/issues/55421 + +const enum Bebra {} +>Bebra : Symbol(Bebra, Decl(constEnumNoObjectPrototypePropertyAccess.ts, 0, 0)) + +console.log(Bebra.constructor) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bebra : Symbol(Bebra, Decl(constEnumNoObjectPrototypePropertyAccess.ts, 0, 0)) + +console.log(Bebra.hasOwnProperty) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bebra : Symbol(Bebra, Decl(constEnumNoObjectPrototypePropertyAccess.ts, 0, 0)) + +console.log(Bebra.isPrototypeOf) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bebra : Symbol(Bebra, Decl(constEnumNoObjectPrototypePropertyAccess.ts, 0, 0)) + +console.log(Bebra.propertyIsEnumerable) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bebra : Symbol(Bebra, Decl(constEnumNoObjectPrototypePropertyAccess.ts, 0, 0)) + +console.log(Bebra.toLocaleString) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bebra : Symbol(Bebra, Decl(constEnumNoObjectPrototypePropertyAccess.ts, 0, 0)) + +console.log(Bebra.toString) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bebra : Symbol(Bebra, Decl(constEnumNoObjectPrototypePropertyAccess.ts, 0, 0)) + +console.log(Bebra.valueOf) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bebra : Symbol(Bebra, Decl(constEnumNoObjectPrototypePropertyAccess.ts, 0, 0)) + diff --git a/tests/baselines/reference/constEnumNoObjectPrototypePropertyAccess.types b/tests/baselines/reference/constEnumNoObjectPrototypePropertyAccess.types new file mode 100644 index 0000000000000..565faf535ad44 --- /dev/null +++ b/tests/baselines/reference/constEnumNoObjectPrototypePropertyAccess.types @@ -0,0 +1,71 @@ +//// [tests/cases/conformance/constEnums/constEnumNoObjectPrototypePropertyAccess.ts] //// + +=== constEnumNoObjectPrototypePropertyAccess.ts === +// https://github.com/microsoft/TypeScript/issues/55421 + +const enum Bebra {} +>Bebra : Bebra + +console.log(Bebra.constructor) +>console.log(Bebra.constructor) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Bebra.constructor : any +>Bebra : typeof Bebra +>constructor : any + +console.log(Bebra.hasOwnProperty) +>console.log(Bebra.hasOwnProperty) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Bebra.hasOwnProperty : any +>Bebra : typeof Bebra +>hasOwnProperty : any + +console.log(Bebra.isPrototypeOf) +>console.log(Bebra.isPrototypeOf) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Bebra.isPrototypeOf : any +>Bebra : typeof Bebra +>isPrototypeOf : any + +console.log(Bebra.propertyIsEnumerable) +>console.log(Bebra.propertyIsEnumerable) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Bebra.propertyIsEnumerable : any +>Bebra : typeof Bebra +>propertyIsEnumerable : any + +console.log(Bebra.toLocaleString) +>console.log(Bebra.toLocaleString) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Bebra.toLocaleString : any +>Bebra : typeof Bebra +>toLocaleString : any + +console.log(Bebra.toString) +>console.log(Bebra.toString) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Bebra.toString : any +>Bebra : typeof Bebra +>toString : any + +console.log(Bebra.valueOf) +>console.log(Bebra.valueOf) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>Bebra.valueOf : any +>Bebra : typeof Bebra +>valueOf : any + diff --git a/tests/baselines/reference/contravariantOnlyInferenceFromAnnotatedFunctionJs.symbols b/tests/baselines/reference/contravariantOnlyInferenceFromAnnotatedFunctionJs.symbols new file mode 100644 index 0000000000000..447299b80a9e8 --- /dev/null +++ b/tests/baselines/reference/contravariantOnlyInferenceFromAnnotatedFunctionJs.symbols @@ -0,0 +1,41 @@ +//// [tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunctionJs.ts] //// + +=== index.js === +/** + * @typedef {{ [K in keyof B]: { fn: (a: A, b: B) => void; thing: B[K]; } }} Funcs + * @template A + * @template {Record} B + */ + +/** + * @template A + * @template {Record} B + * @param {Funcs} fns + * @returns {[A, B]} + */ +function foo(fns) { +>foo : Symbol(foo, Decl(index.js, 0, 0)) +>fns : Symbol(fns, Decl(index.js, 12, 13)) + + return /** @type {any} */ (null); +} + +const result = foo({ +>result : Symbol(result, Decl(index.js, 16, 5)) +>foo : Symbol(foo, Decl(index.js, 0, 0)) + + bar: { +>bar : Symbol(bar, Decl(index.js, 16, 20)) + + fn: +>fn : Symbol(fn, Decl(index.js, 17, 8)) + + /** @param {string} a */ + (a) => {}, +>a : Symbol(a, Decl(index.js, 20, 7)) + + thing: "asd", +>thing : Symbol(thing, Decl(index.js, 20, 16)) + + }, +}); diff --git a/tests/baselines/reference/contravariantOnlyInferenceFromAnnotatedFunctionJs.types b/tests/baselines/reference/contravariantOnlyInferenceFromAnnotatedFunctionJs.types new file mode 100644 index 0000000000000..2f4658db5771e --- /dev/null +++ b/tests/baselines/reference/contravariantOnlyInferenceFromAnnotatedFunctionJs.types @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunctionJs.ts] //// + +=== index.js === +/** + * @typedef {{ [K in keyof B]: { fn: (a: A, b: B) => void; thing: B[K]; } }} Funcs + * @template A + * @template {Record} B + */ + +/** + * @template A + * @template {Record} B + * @param {Funcs} fns + * @returns {[A, B]} + */ +function foo(fns) { +>foo : >(fns: Funcs) => [A, B] +>fns : Funcs + + return /** @type {any} */ (null); +>(null) : any +} + +const result = foo({ +>result : [string, { bar: string; }] +>foo({ bar: { fn: /** @param {string} a */ (a) => {}, thing: "asd", },}) : [string, { bar: string; }] +>foo : >(fns: Funcs) => [A, B] +>{ bar: { fn: /** @param {string} a */ (a) => {}, thing: "asd", },} : { bar: { fn: (a: string) => void; thing: string; }; } + + bar: { +>bar : { fn: (a: string) => void; thing: string; } +>{ fn: /** @param {string} a */ (a) => {}, thing: "asd", } : { fn: (a: string) => void; thing: string; } + + fn: +>fn : (a: string) => void + + /** @param {string} a */ + (a) => {}, +>(a) => {} : (a: string) => void +>a : string + + thing: "asd", +>thing : string +>"asd" : "asd" + + }, +}); diff --git a/tests/baselines/reference/divergentAccessorsTypes7.js b/tests/baselines/reference/divergentAccessorsTypes7.js new file mode 100644 index 0000000000000..ed5cdb501d17b --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes7.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/divergentAccessorsTypes7.ts] //// + +//// [divergentAccessorsTypes7.ts] +class Test { + constructor() {} + + set value(value: string | ((item: S) => string)) {} + + get value(): string { + return null!; + } + + // -- Replacing the getter such that the getter/setter types match, removes the error: + // get value(): string | ((item: S) => string) { + // return null!; + // } + + // -- Or, replacing the setter such that a concrete type is used, removes the error: + // set value(value: string | ((item: { property: string }) => string)) {} +} + +const a = new Test<{ + property: string +}>(); + +a.value = (item) => item.property + + +//// [divergentAccessorsTypes7.js] +var Test = /** @class */ (function () { + function Test() { + } + Object.defineProperty(Test.prototype, "value", { + get: function () { + return null; + }, + set: function (value) { }, + enumerable: false, + configurable: true + }); + return Test; +}()); +var a = new Test(); +a.value = function (item) { return item.property; }; diff --git a/tests/baselines/reference/divergentAccessorsTypes7.symbols b/tests/baselines/reference/divergentAccessorsTypes7.symbols new file mode 100644 index 0000000000000..ea85654577900 --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes7.symbols @@ -0,0 +1,48 @@ +//// [tests/cases/compiler/divergentAccessorsTypes7.ts] //// + +=== divergentAccessorsTypes7.ts === +class Test { +>Test : Symbol(Test, Decl(divergentAccessorsTypes7.ts, 0, 0)) +>S : Symbol(S, Decl(divergentAccessorsTypes7.ts, 0, 11)) + + constructor() {} + + set value(value: string | ((item: S) => string)) {} +>value : Symbol(Test.value, Decl(divergentAccessorsTypes7.ts, 1, 20), Decl(divergentAccessorsTypes7.ts, 3, 55)) +>value : Symbol(value, Decl(divergentAccessorsTypes7.ts, 3, 14)) +>item : Symbol(item, Decl(divergentAccessorsTypes7.ts, 3, 32)) +>S : Symbol(S, Decl(divergentAccessorsTypes7.ts, 0, 11)) + + get value(): string { +>value : Symbol(Test.value, Decl(divergentAccessorsTypes7.ts, 1, 20), Decl(divergentAccessorsTypes7.ts, 3, 55)) + + return null!; + } + + // -- Replacing the getter such that the getter/setter types match, removes the error: + // get value(): string | ((item: S) => string) { + // return null!; + // } + + // -- Or, replacing the setter such that a concrete type is used, removes the error: + // set value(value: string | ((item: { property: string }) => string)) {} +} + +const a = new Test<{ +>a : Symbol(a, Decl(divergentAccessorsTypes7.ts, 18, 5)) +>Test : Symbol(Test, Decl(divergentAccessorsTypes7.ts, 0, 0)) + + property: string +>property : Symbol(property, Decl(divergentAccessorsTypes7.ts, 18, 20)) + +}>(); + +a.value = (item) => item.property +>a.value : Symbol(Test.value, Decl(divergentAccessorsTypes7.ts, 1, 20), Decl(divergentAccessorsTypes7.ts, 3, 55)) +>a : Symbol(a, Decl(divergentAccessorsTypes7.ts, 18, 5)) +>value : Symbol(Test.value, Decl(divergentAccessorsTypes7.ts, 1, 20), Decl(divergentAccessorsTypes7.ts, 3, 55)) +>item : Symbol(item, Decl(divergentAccessorsTypes7.ts, 22, 11)) +>item.property : Symbol(property, Decl(divergentAccessorsTypes7.ts, 18, 20)) +>item : Symbol(item, Decl(divergentAccessorsTypes7.ts, 22, 11)) +>property : Symbol(property, Decl(divergentAccessorsTypes7.ts, 18, 20)) + diff --git a/tests/baselines/reference/divergentAccessorsTypes7.types b/tests/baselines/reference/divergentAccessorsTypes7.types new file mode 100644 index 0000000000000..95e494f4d3df5 --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes7.types @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/divergentAccessorsTypes7.ts] //// + +=== divergentAccessorsTypes7.ts === +class Test { +>Test : Test + + constructor() {} + + set value(value: string | ((item: S) => string)) {} +>value : string +>value : string | ((item: S) => string) +>item : S + + get value(): string { +>value : string + + return null!; +>null! : null + } + + // -- Replacing the getter such that the getter/setter types match, removes the error: + // get value(): string | ((item: S) => string) { + // return null!; + // } + + // -- Or, replacing the setter such that a concrete type is used, removes the error: + // set value(value: string | ((item: { property: string }) => string)) {} +} + +const a = new Test<{ +>a : Test<{ property: string; }> +>new Test<{ property: string}>() : Test<{ property: string; }> +>Test : typeof Test + + property: string +>property : string + +}>(); + +a.value = (item) => item.property +>a.value = (item) => item.property : (item: { property: string; }) => string +>a.value : string | ((item: { property: string; }) => string) +>a : Test<{ property: string; }> +>value : string | ((item: { property: string; }) => string) +>(item) => item.property : (item: { property: string; }) => string +>item : { property: string; } +>item.property : string +>item : { property: string; } +>property : string + diff --git a/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js index 04abac07a28a9..99070c882b9a5 100644 --- a/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js +++ b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js @@ -228,6 +228,14 @@ type Input = { timer: Timer; hook: Hook; }; +/** + * Imports + */ +type Timer = import("./timer"); +/** + * Imports + */ +type Hook = import("./hook"); /** * Imports */ @@ -239,14 +247,6 @@ type State = { timer: Timer; hook: Hook; }; -/** - * Imports - */ -type Timer = import("./timer"); -/** - * Imports - */ -type Hook = import("./hook"); //// [hook.d.ts] export = Hook; /** diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.js b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.js new file mode 100644 index 0000000000000..984ea0a483824 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.js @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts] //// + +//// [file.js] +const SomeConstructor = function () { + this.x = 1; +}; + +const SomeConstructor2 = function () { +}; +SomeConstructor2.staticMember = "str"; + +const SomeConstructor3 = function () { + this.x = 1; +}; +SomeConstructor3.staticMember = "str"; + + + + +//// [file.d.ts] +declare function SomeConstructor(): void; +declare class SomeConstructor { + x: number; +} +declare function SomeConstructor2(): void; +declare namespace SomeConstructor2 { + let staticMember: string; +} +declare function SomeConstructor3(): void; +declare namespace SomeConstructor3 { + let staticMember_1: string; + export { staticMember_1 as staticMember }; +} +declare class SomeConstructor3 { + x: number; +} diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.symbols b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.symbols new file mode 100644 index 0000000000000..a003ed2cbc09c --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.symbols @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts] //// + +=== file.js === +const SomeConstructor = function () { +>SomeConstructor : Symbol(SomeConstructor, Decl(file.js, 0, 5)) + + this.x = 1; +>this.x : Symbol(SomeConstructor.x, Decl(file.js, 0, 37)) +>this : Symbol(SomeConstructor, Decl(file.js, 0, 23)) +>x : Symbol(SomeConstructor.x, Decl(file.js, 0, 37)) + +}; + +const SomeConstructor2 = function () { +>SomeConstructor2 : Symbol(SomeConstructor2, Decl(file.js, 4, 5), Decl(file.js, 5, 2)) + +}; +SomeConstructor2.staticMember = "str"; +>SomeConstructor2.staticMember : Symbol(SomeConstructor2.staticMember, Decl(file.js, 5, 2)) +>SomeConstructor2 : Symbol(SomeConstructor2, Decl(file.js, 4, 5), Decl(file.js, 5, 2)) +>staticMember : Symbol(SomeConstructor2.staticMember, Decl(file.js, 5, 2)) + +const SomeConstructor3 = function () { +>SomeConstructor3 : Symbol(SomeConstructor3, Decl(file.js, 8, 5), Decl(file.js, 10, 2)) + + this.x = 1; +>this.x : Symbol(SomeConstructor3.x, Decl(file.js, 8, 38)) +>this : Symbol(SomeConstructor3, Decl(file.js, 8, 24)) +>x : Symbol(SomeConstructor3.x, Decl(file.js, 8, 38)) + +}; +SomeConstructor3.staticMember = "str"; +>SomeConstructor3.staticMember : Symbol(SomeConstructor3.staticMember, Decl(file.js, 10, 2)) +>SomeConstructor3 : Symbol(SomeConstructor3, Decl(file.js, 8, 5), Decl(file.js, 10, 2)) +>staticMember : Symbol(SomeConstructor3.staticMember, Decl(file.js, 10, 2)) + diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.types b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.types new file mode 100644 index 0000000000000..3e187f5c216db --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunction.types @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts] //// + +=== file.js === +const SomeConstructor = function () { +>SomeConstructor : typeof SomeConstructor +>function () { this.x = 1;} : typeof SomeConstructor + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 + +}; + +const SomeConstructor2 = function () { +>SomeConstructor2 : { (): void; staticMember: string; } +>function () {} : { (): void; staticMember: string; } + +}; +SomeConstructor2.staticMember = "str"; +>SomeConstructor2.staticMember = "str" : "str" +>SomeConstructor2.staticMember : string +>SomeConstructor2 : { (): void; staticMember: string; } +>staticMember : string +>"str" : "str" + +const SomeConstructor3 = function () { +>SomeConstructor3 : typeof SomeConstructor3 +>function () { this.x = 1;} : typeof SomeConstructor3 + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 + +}; +SomeConstructor3.staticMember = "str"; +>SomeConstructor3.staticMember = "str" : "str" +>SomeConstructor3.staticMember : string +>SomeConstructor3 : typeof SomeConstructor3 +>staticMember : string +>"str" : "str" + diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.js b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.js new file mode 100644 index 0000000000000..3d471e3615800 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts] //// + +//// [file.js] +const SomeConstructor = function Named() { + this.x = 1; +}; + +const SomeConstructor2 = function Named() { +}; +SomeConstructor2.staticMember = "str"; + +const SomeConstructor3 = function Named() { + this.x = 1; +}; +SomeConstructor3.staticMember = "str"; + +const SelfReference = function Named() { + if (!(this instanceof Named)) return new Named(); + this.x = 1; +} +SelfReference.staticMember = "str"; + + + + +//// [file.d.ts] +declare function SomeConstructor(): void; +declare class SomeConstructor { + x: number; +} +declare function SomeConstructor2(): void; +declare namespace SomeConstructor2 { + let staticMember: string; +} +declare function SomeConstructor3(): void; +declare namespace SomeConstructor3 { + let staticMember_1: string; + export { staticMember_1 as staticMember }; +} +declare class SomeConstructor3 { + x: number; +} +declare function SelfReference(): SelfReference; +declare namespace SelfReference { + let staticMember_2: string; + export { staticMember_2 as staticMember }; +} +declare class SelfReference { + x: number; +} diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.symbols b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.symbols new file mode 100644 index 0000000000000..50b29c337521a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.symbols @@ -0,0 +1,58 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts] //// + +=== file.js === +const SomeConstructor = function Named() { +>SomeConstructor : Symbol(SomeConstructor, Decl(file.js, 0, 5)) +>Named : Symbol(Named, Decl(file.js, 0, 23)) + + this.x = 1; +>this.x : Symbol(Named.x, Decl(file.js, 0, 42)) +>this : Symbol(Named, Decl(file.js, 0, 23)) +>x : Symbol(Named.x, Decl(file.js, 0, 42)) + +}; + +const SomeConstructor2 = function Named() { +>SomeConstructor2 : Symbol(SomeConstructor2, Decl(file.js, 4, 5), Decl(file.js, 5, 2)) +>Named : Symbol(Named, Decl(file.js, 4, 24)) + +}; +SomeConstructor2.staticMember = "str"; +>SomeConstructor2.staticMember : Symbol(SomeConstructor2.staticMember, Decl(file.js, 5, 2)) +>SomeConstructor2 : Symbol(SomeConstructor2, Decl(file.js, 4, 5), Decl(file.js, 5, 2)) +>staticMember : Symbol(SomeConstructor2.staticMember, Decl(file.js, 5, 2)) + +const SomeConstructor3 = function Named() { +>SomeConstructor3 : Symbol(SomeConstructor3, Decl(file.js, 8, 5), Decl(file.js, 10, 2)) +>Named : Symbol(Named, Decl(file.js, 8, 24)) + + this.x = 1; +>this.x : Symbol(Named.x, Decl(file.js, 8, 43)) +>this : Symbol(Named, Decl(file.js, 8, 24)) +>x : Symbol(Named.x, Decl(file.js, 8, 43)) + +}; +SomeConstructor3.staticMember = "str"; +>SomeConstructor3.staticMember : Symbol(SomeConstructor3.staticMember, Decl(file.js, 10, 2)) +>SomeConstructor3 : Symbol(SomeConstructor3, Decl(file.js, 8, 5), Decl(file.js, 10, 2)) +>staticMember : Symbol(SomeConstructor3.staticMember, Decl(file.js, 10, 2)) + +const SelfReference = function Named() { +>SelfReference : Symbol(SelfReference, Decl(file.js, 13, 5), Decl(file.js, 16, 1)) +>Named : Symbol(Named, Decl(file.js, 13, 21)) + + if (!(this instanceof Named)) return new Named(); +>this : Symbol(Named, Decl(file.js, 13, 21)) +>Named : Symbol(Named, Decl(file.js, 13, 21)) +>Named : Symbol(Named, Decl(file.js, 13, 21)) + + this.x = 1; +>this.x : Symbol(Named.x, Decl(file.js, 14, 53)) +>this : Symbol(Named, Decl(file.js, 13, 21)) +>x : Symbol(Named.x, Decl(file.js, 14, 53)) +} +SelfReference.staticMember = "str"; +>SelfReference.staticMember : Symbol(SelfReference.staticMember, Decl(file.js, 16, 1)) +>SelfReference : Symbol(SelfReference, Decl(file.js, 13, 5), Decl(file.js, 16, 1)) +>staticMember : Symbol(SelfReference.staticMember, Decl(file.js, 16, 1)) + diff --git a/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.types b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.types new file mode 100644 index 0000000000000..afd849a8bb55b --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsGlobalFileConstFunctionNamed.types @@ -0,0 +1,78 @@ +//// [tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts] //// + +=== file.js === +const SomeConstructor = function Named() { +>SomeConstructor : typeof Named +>function Named() { this.x = 1;} : typeof Named +>Named : typeof Named + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 + +}; + +const SomeConstructor2 = function Named() { +>SomeConstructor2 : { (): void; staticMember: string; } +>function Named() {} : { (): void; staticMember: string; } +>Named : { (): void; staticMember: string; } + +}; +SomeConstructor2.staticMember = "str"; +>SomeConstructor2.staticMember = "str" : "str" +>SomeConstructor2.staticMember : string +>SomeConstructor2 : { (): void; staticMember: string; } +>staticMember : string +>"str" : "str" + +const SomeConstructor3 = function Named() { +>SomeConstructor3 : typeof Named +>function Named() { this.x = 1;} : typeof Named +>Named : typeof Named + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 + +}; +SomeConstructor3.staticMember = "str"; +>SomeConstructor3.staticMember = "str" : "str" +>SomeConstructor3.staticMember : string +>SomeConstructor3 : typeof Named +>staticMember : string +>"str" : "str" + +const SelfReference = function Named() { +>SelfReference : typeof Named +>function Named() { if (!(this instanceof Named)) return new Named(); this.x = 1;} : typeof Named +>Named : typeof Named + + if (!(this instanceof Named)) return new Named(); +>!(this instanceof Named) : boolean +>(this instanceof Named) : boolean +>this instanceof Named : boolean +>this : this +>Named : typeof Named +>new Named() : Named +>Named : typeof Named + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : this +>x : any +>1 : 1 +} +SelfReference.staticMember = "str"; +>SelfReference.staticMember = "str" : "str" +>SelfReference.staticMember : string +>SelfReference : typeof Named +>staticMember : string +>"str" : "str" + diff --git a/tests/baselines/reference/typeSatisfaction_asConstArrays.symbols b/tests/baselines/reference/typeSatisfaction_asConstArrays.symbols new file mode 100644 index 0000000000000..10b166cf16384 --- /dev/null +++ b/tests/baselines/reference/typeSatisfaction_asConstArrays.symbols @@ -0,0 +1,13 @@ +//// [tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction_asConstArrays.ts] //// + +=== typeSatisfaction_asConstArrays.ts === +// with readonly array +const arr1 = [1, 2, 3] as const satisfies readonly unknown[] +>arr1 : Symbol(arr1, Decl(typeSatisfaction_asConstArrays.ts, 1, 5)) +>const : Symbol(const) + +// with mutable array +const arr2 = [1, 2, 3] as const satisfies unknown[] +>arr2 : Symbol(arr2, Decl(typeSatisfaction_asConstArrays.ts, 4, 5)) +>const : Symbol(const) + diff --git a/tests/baselines/reference/typeSatisfaction_asConstArrays.types b/tests/baselines/reference/typeSatisfaction_asConstArrays.types new file mode 100644 index 0000000000000..4ac3ceaee9874 --- /dev/null +++ b/tests/baselines/reference/typeSatisfaction_asConstArrays.types @@ -0,0 +1,23 @@ +//// [tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction_asConstArrays.ts] //// + +=== typeSatisfaction_asConstArrays.ts === +// with readonly array +const arr1 = [1, 2, 3] as const satisfies readonly unknown[] +>arr1 : readonly [1, 2, 3] +>[1, 2, 3] as const satisfies readonly unknown[] : readonly [1, 2, 3] +>[1, 2, 3] as const : readonly [1, 2, 3] +>[1, 2, 3] : readonly [1, 2, 3] +>1 : 1 +>2 : 2 +>3 : 3 + +// with mutable array +const arr2 = [1, 2, 3] as const satisfies unknown[] +>arr2 : [1, 2, 3] +>[1, 2, 3] as const satisfies unknown[] : [1, 2, 3] +>[1, 2, 3] as const : [1, 2, 3] +>[1, 2, 3] : [1, 2, 3] +>1 : 1 +>2 : 2 +>3 : 3 + diff --git a/tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts b/tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts index 435f1daf563fd..1fe0749eaabaa 100644 --- a/tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts +++ b/tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts @@ -135,3 +135,18 @@ function foo17() { const foo = 1; } + +// #30907 +function wrapI1() { + const iter = (function* foo() { + iter; + yield 1; + })(); +} + +function wrapI2() { + const iter = (async function* foo() { + iter; + yield 1; + })(); +} diff --git a/tests/cases/compiler/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts b/tests/cases/compiler/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts new file mode 100644 index 0000000000000..a5ab28856660f --- /dev/null +++ b/tests/cases/compiler/classExtendingAbstractClassWithMemberCalledTheSameAsItsOwnTypeParam.ts @@ -0,0 +1,25 @@ +// @strict: true +// @lib: esnext +// @noEmit: true + +interface IObserver { + handleChange(observable: IObservable, change: TChange): void; +} + +interface IObservable { + get(): T; + readonly TChange: TChange; +} + +export interface IReader { + readObservable(observable: IObservable): T; +} + +export abstract class ConvenientObservable implements IObservable { + get TChange(): TChange { return null!; } + public abstract get(): T; +} + +export abstract class BaseObservable extends ConvenientObservable { + protected readonly observers = new Set(); +} diff --git a/tests/cases/compiler/computedPropertyNameWithImportedKey.ts b/tests/cases/compiler/computedPropertyNameWithImportedKey.ts new file mode 100644 index 0000000000000..142d4cfb6d9af --- /dev/null +++ b/tests/cases/compiler/computedPropertyNameWithImportedKey.ts @@ -0,0 +1,11 @@ +// @declaration: true +// @lib: es6 + +// @filename: /a.ts +export const a = Symbol(); + +// @filename: /b.ts +import { a } from "./a"; +export function fn({ [a]: value }: any): string { + return value; +} diff --git a/tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunctionJs.ts b/tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunctionJs.ts new file mode 100644 index 0000000000000..5d556894ea3d3 --- /dev/null +++ b/tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunctionJs.ts @@ -0,0 +1,30 @@ +// @strict: true +// @checkJs: true +// @noEmit: true + +// @filename: index.js + +/** + * @typedef {{ [K in keyof B]: { fn: (a: A, b: B) => void; thing: B[K]; } }} Funcs + * @template A + * @template {Record} B + */ + +/** + * @template A + * @template {Record} B + * @param {Funcs} fns + * @returns {[A, B]} + */ +function foo(fns) { + return /** @type {any} */ (null); +} + +const result = foo({ + bar: { + fn: + /** @param {string} a */ + (a) => {}, + thing: "asd", + }, +}); \ No newline at end of file diff --git a/tests/cases/compiler/divergentAccessorsTypes7.ts b/tests/cases/compiler/divergentAccessorsTypes7.ts new file mode 100644 index 0000000000000..830820221051f --- /dev/null +++ b/tests/cases/compiler/divergentAccessorsTypes7.ts @@ -0,0 +1,23 @@ +class Test { + constructor() {} + + set value(value: string | ((item: S) => string)) {} + + get value(): string { + return null!; + } + + // -- Replacing the getter such that the getter/setter types match, removes the error: + // get value(): string | ((item: S) => string) { + // return null!; + // } + + // -- Or, replacing the setter such that a concrete type is used, removes the error: + // set value(value: string | ((item: { property: string }) => string)) {} +} + +const a = new Test<{ + property: string +}>(); + +a.value = (item) => item.property diff --git a/tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts b/tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts new file mode 100644 index 0000000000000..0ef68f6e91ad3 --- /dev/null +++ b/tests/cases/compiler/jsDeclarationsGlobalFileConstFunction.ts @@ -0,0 +1,16 @@ +// @checkJs: true +// @declaration: true +// @emitDeclarationOnly: true +// @filename: file.js +const SomeConstructor = function () { + this.x = 1; +}; + +const SomeConstructor2 = function () { +}; +SomeConstructor2.staticMember = "str"; + +const SomeConstructor3 = function () { + this.x = 1; +}; +SomeConstructor3.staticMember = "str"; diff --git a/tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts b/tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts new file mode 100644 index 0000000000000..2b40db86dbbdc --- /dev/null +++ b/tests/cases/compiler/jsDeclarationsGlobalFileConstFunctionNamed.ts @@ -0,0 +1,22 @@ +// @checkJs: true +// @declaration: true +// @emitDeclarationOnly: true +// @filename: file.js +const SomeConstructor = function Named() { + this.x = 1; +}; + +const SomeConstructor2 = function Named() { +}; +SomeConstructor2.staticMember = "str"; + +const SomeConstructor3 = function Named() { + this.x = 1; +}; +SomeConstructor3.staticMember = "str"; + +const SelfReference = function Named() { + if (!(this instanceof Named)) return new Named(); + this.x = 1; +} +SelfReference.staticMember = "str"; diff --git a/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts b/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts new file mode 100644 index 0000000000000..5871010878546 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath.ts @@ -0,0 +1,13 @@ +// @declaration: true + +// https://github.com/microsoft/TypeScript/issues/7840 + +declare module chrome.debugger { + declare var tabId: number; +} + +export const tabId = chrome.debugger.tabId; + +declare module test.class {} + +declare module debugger {} // still an error diff --git a/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts b/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts new file mode 100644 index 0000000000000..7b41511cb2cb9 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientModuleDeclarationWithReservedIdentifierInDottedPath2.ts @@ -0,0 +1,11 @@ +// @declaration: true + +declare namespace chrome.debugger { + declare var tabId: number; +} + +export const tabId = chrome.debugger.tabId; + +declare namespace test.class {} + +declare namespace debugger {} // still an error diff --git a/tests/cases/conformance/constEnums/constEnumNoObjectPrototypePropertyAccess.ts b/tests/cases/conformance/constEnums/constEnumNoObjectPrototypePropertyAccess.ts new file mode 100644 index 0000000000000..0f8e59b61afd3 --- /dev/null +++ b/tests/cases/conformance/constEnums/constEnumNoObjectPrototypePropertyAccess.ts @@ -0,0 +1,14 @@ +// @strict: true +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/55421 + +const enum Bebra {} + +console.log(Bebra.constructor) +console.log(Bebra.hasOwnProperty) +console.log(Bebra.isPrototypeOf) +console.log(Bebra.propertyIsEnumerable) +console.log(Bebra.toLocaleString) +console.log(Bebra.toString) +console.log(Bebra.valueOf) diff --git a/tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction_asConstArrays.ts b/tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction_asConstArrays.ts new file mode 100644 index 0000000000000..16c3c5e905362 --- /dev/null +++ b/tests/cases/conformance/expressions/typeSatisfaction/typeSatisfaction_asConstArrays.ts @@ -0,0 +1,8 @@ +// @strict: true +// @noEmit: true + +// with readonly array +const arr1 = [1, 2, 3] as const satisfies readonly unknown[] + +// with mutable array +const arr2 = [1, 2, 3] as const satisfies unknown[] diff --git a/tests/cases/fourslash/quickInfoOnPropDeclaredUsingIndexSignatureOnInterfaceWithBase.ts b/tests/cases/fourslash/quickInfoOnPropDeclaredUsingIndexSignatureOnInterfaceWithBase.ts new file mode 100644 index 0000000000000..e55088eb64dd2 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnPropDeclaredUsingIndexSignatureOnInterfaceWithBase.ts @@ -0,0 +1,12 @@ +/// + +// https://github.com/microsoft/TypeScript/issues/55251 + +//// interface P {} +//// interface B extends P { +//// [k: string]: number; +//// } +//// declare const b: B; +//// b.t/*1*/est = 10; + +verify.quickInfoAt("1", "(index) B[string]: number"); diff --git a/tests/cases/fourslash/stringLiteralCompletionsInArgUsingInferenceResultFromPreviousArg.ts b/tests/cases/fourslash/stringLiteralCompletionsInArgUsingInferenceResultFromPreviousArg.ts new file mode 100644 index 0000000000000..8cc49bccbba40 --- /dev/null +++ b/tests/cases/fourslash/stringLiteralCompletionsInArgUsingInferenceResultFromPreviousArg.ts @@ -0,0 +1,35 @@ +/// + +// @strict: true + +//// // https://github.com/microsoft/TypeScript/issues/55545 +//// enum myEnum { +//// valA = "valA", +//// valB = "valB", +//// } +//// +//// interface myEnumParamMapping { +//// ["valA"]: "1" | "2"; +//// ["valB"]: "3" | "4"; +//// } +//// +//// function myFunction( +//// a: K, +//// b: myEnumParamMapping[K], +//// ) {} +//// +//// myFunction("valA", "/*ts1*/"); +//// myFunction("valA", `/*ts2*/`); +//// +//// function myFunction2( +//// a: K, +//// { b }: { b: myEnumParamMapping[K] }, +//// ) {} +//// +//// myFunction2("valA", { b: "/*ts3*/" }); +//// myFunction2("valA", { b: `/*ts4*/` }); + +verify.completions({ + marker: ["ts1", "ts2", "ts3", "ts4"], + exact: ["1", "2"] +});