diff --git a/package-lock.json b/package-lock.json index 9986f1b45..95bf935b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "eslint": "^9.39.2", "globals": "^17.3.0", "prettier": "^3.8.1", - "typescript": "^5.9.3", + "typescript": "^6.0.0", "vitepress": "^1.6.4", "vitest": "^4.1.4" }, @@ -2439,26 +2439,47 @@ "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/ignore": { - "version": "7.0.5", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz", - "integrity": "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==", + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/type-utils": { + "version": "8.54.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.54.0.tgz", + "integrity": "sha512-hiLguxJWHjjwL6xMBwD903ciAwd7DmK30Y9Axs/etOkftC3ZNN9K44IuRD/EB08amu+Zw6W37x9RecLkOo3pMA==", "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.54.0", + "@typescript-eslint/typescript-estree": "8.54.0", + "@typescript-eslint/utils": "8.54.0", + "debug": "^4.4.3", + "ts-api-utils": "^2.4.0" + }, "engines": { - "node": ">= 4" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/parser": { + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/typescript-estree": { "version": "8.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.54.0.tgz", - "integrity": "sha512-BtE0k6cjwjLZoZixN0t5AKP0kSzlGu7FctRXYuPAm//aaiZhmfq1JwdYpYr1brzEspYyFeF+8XF5j2VK6oalrA==", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.54.0.tgz", + "integrity": "sha512-BUwcskRaPvTk6fzVWgDPdUndLjB87KYDrN5EYGetnktoeAvPtO4ONHlAZDnj5VFnUANg0Sjm7j4usBlnoVMHwA==", "dev": true, + "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "8.54.0", + "@typescript-eslint/project-service": "8.54.0", + "@typescript-eslint/tsconfig-utils": "8.54.0", "@typescript-eslint/types": "8.54.0", - "@typescript-eslint/typescript-estree": "8.54.0", "@typescript-eslint/visitor-keys": "8.54.0", - "debug": "^4.4.3" + "debug": "^4.4.3", + "minimatch": "^9.0.5", + "semver": "^7.7.3", + "tinyglobby": "^0.2.15", + "ts-api-utils": "^2.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2468,15 +2489,15 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/project-service": { + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/typescript-estree/node_modules/@typescript-eslint/project-service": { "version": "8.54.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.54.0.tgz", "integrity": "sha512-YPf+rvJ1s7MyiWM4uTRhE4DvBXrEV+d8oC3P9Y2eT7S+HBS0clybdMIPnhiATi9vZOYDc7OQ1L/i6ga6NFYK/g==", "dev": true, + "license": "MIT", "dependencies": { "@typescript-eslint/tsconfig-utils": "^8.54.0", "@typescript-eslint/types": "^8.54.0", @@ -2493,28 +2514,35 @@ "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/scope-manager": { + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/typescript-estree/node_modules/@typescript-eslint/tsconfig-utils": { "version": "8.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.54.0.tgz", - "integrity": "sha512-27rYVQku26j/PbHYcVfRPonmOlVI6gihHtXFbTdB5sb6qA0wdAQAbyXFVarQ5t4HRojIz64IV90YtsjQSSGlQg==", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.54.0.tgz", + "integrity": "sha512-dRgOyT2hPk/JwxNMZDsIXDgyl9axdJI3ogZ2XWhBPsnZUv+hPesa5iuhdYt2gzwA9t8RE5ytOJ6xB0moV0Ujvw==", "dev": true, - "dependencies": { - "@typescript-eslint/types": "8.54.0", - "@typescript-eslint/visitor-keys": "8.54.0" - }, + "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/tsconfig-utils": { + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils": { "version": "8.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.54.0.tgz", - "integrity": "sha512-dRgOyT2hPk/JwxNMZDsIXDgyl9axdJI3ogZ2XWhBPsnZUv+hPesa5iuhdYt2gzwA9t8RE5ytOJ6xB0moV0Ujvw==", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.54.0.tgz", + "integrity": "sha512-9Cnda8GS57AQakvRyG0PTejJNlA2xhvyNtEVIMlDWOOeEyBkYWhGPnfrIAnqxLMTSTo6q8g12XVjjev5l1NvMA==", "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.9.1", + "@typescript-eslint/scope-manager": "8.54.0", + "@typescript-eslint/types": "8.54.0", + "@typescript-eslint/typescript-estree": "8.54.0" + }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, @@ -2523,19 +2551,25 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/type-utils": { + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/typescript-estree": { "version": "8.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.54.0.tgz", - "integrity": "sha512-hiLguxJWHjjwL6xMBwD903ciAwd7DmK30Y9Axs/etOkftC3ZNN9K44IuRD/EB08amu+Zw6W37x9RecLkOo3pMA==", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.54.0.tgz", + "integrity": "sha512-BUwcskRaPvTk6fzVWgDPdUndLjB87KYDrN5EYGetnktoeAvPtO4ONHlAZDnj5VFnUANg0Sjm7j4usBlnoVMHwA==", "dev": true, + "license": "MIT", "dependencies": { + "@typescript-eslint/project-service": "8.54.0", + "@typescript-eslint/tsconfig-utils": "8.54.0", "@typescript-eslint/types": "8.54.0", - "@typescript-eslint/typescript-estree": "8.54.0", - "@typescript-eslint/utils": "8.54.0", + "@typescript-eslint/visitor-keys": "8.54.0", "debug": "^4.4.3", + "minimatch": "^9.0.5", + "semver": "^7.7.3", + "tinyglobby": "^0.2.15", "ts-api-utils": "^2.4.0" }, "engines": { @@ -2546,28 +2580,113 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/types": { + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/typescript-estree/node_modules/@typescript-eslint/project-service": { "version": "8.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.54.0.tgz", - "integrity": "sha512-PDUI9R1BVjqu7AUDsRBbKMtwmjWcn4J3le+5LpcFgWULN3LvHC5rkc9gCVxbrsrGmO1jfPybN5s6h4Jy+OnkAA==", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.54.0.tgz", + "integrity": "sha512-YPf+rvJ1s7MyiWM4uTRhE4DvBXrEV+d8oC3P9Y2eT7S+HBS0clybdMIPnhiATi9vZOYDc7OQ1L/i6ga6NFYK/g==", "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/tsconfig-utils": "^8.54.0", + "@typescript-eslint/types": "^8.54.0", + "debug": "^4.4.3" + }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/typescript-estree": { + "node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/typescript-estree/node_modules/@typescript-eslint/tsconfig-utils": { + "version": "8.54.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.54.0.tgz", + "integrity": "sha512-dRgOyT2hPk/JwxNMZDsIXDgyl9axdJI3ogZ2XWhBPsnZUv+hPesa5iuhdYt2gzwA9t8RE5ytOJ6xB0moV0Ujvw==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/brace-expansion": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.0.tgz", + "integrity": "sha512-TN1kCZAgdgweJhWWpgKYrQaMNHcDULHkWwQIspdtjV4Y5aurRdZpjAqn6yX3FPqTA9ngHCc4hJxMAMgGfve85w==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/ignore": { + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz", + "integrity": "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==", + "dev": true, + "engines": { + "node": ">= 4" + } + }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/minimatch": { + "version": "9.0.9", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.9.tgz", + "integrity": "sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.2" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "8.54.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.54.0.tgz", + "integrity": "sha512-BtE0k6cjwjLZoZixN0t5AKP0kSzlGu7FctRXYuPAm//aaiZhmfq1JwdYpYr1brzEspYyFeF+8XF5j2VK6oalrA==", + "dev": true, + "dependencies": { + "@typescript-eslint/scope-manager": "8.54.0", + "@typescript-eslint/types": "8.54.0", + "@typescript-eslint/typescript-estree": "8.54.0", + "@typescript-eslint/visitor-keys": "8.54.0", + "debug": "^4.4.3" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": { "version": "8.54.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.54.0.tgz", "integrity": "sha512-BUwcskRaPvTk6fzVWgDPdUndLjB87KYDrN5EYGetnktoeAvPtO4ONHlAZDnj5VFnUANg0Sjm7j4usBlnoVMHwA==", "dev": true, + "license": "MIT", "dependencies": { "@typescript-eslint/project-service": "8.54.0", "@typescript-eslint/tsconfig-utils": "8.54.0", @@ -2590,22 +2709,63 @@ "typescript": ">=4.8.4 <6.0.0" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree/node_modules/@typescript-eslint/project-service": { + "version": "8.54.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.54.0.tgz", + "integrity": "sha512-YPf+rvJ1s7MyiWM4uTRhE4DvBXrEV+d8oC3P9Y2eT7S+HBS0clybdMIPnhiATi9vZOYDc7OQ1L/i6ga6NFYK/g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/tsconfig-utils": "^8.54.0", + "@typescript-eslint/types": "^8.54.0", + "debug": "^4.4.3" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree/node_modules/@typescript-eslint/tsconfig-utils": { + "version": "8.54.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.54.0.tgz", + "integrity": "sha512-dRgOyT2hPk/JwxNMZDsIXDgyl9axdJI3ogZ2XWhBPsnZUv+hPesa5iuhdYt2gzwA9t8RE5ytOJ6xB0moV0Ujvw==", "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.0.0" + } + }, + "node_modules/@typescript-eslint/parser/node_modules/brace-expansion": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.0.tgz", + "integrity": "sha512-TN1kCZAgdgweJhWWpgKYrQaMNHcDULHkWwQIspdtjV4Y5aurRdZpjAqn6yX3FPqTA9ngHCc4hJxMAMgGfve85w==", + "dev": true, + "license": "MIT", "dependencies": { "balanced-match": "^1.0.0" } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "node_modules/@typescript-eslint/parser/node_modules/minimatch": { + "version": "9.0.9", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.9.tgz", + "integrity": "sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg==", "dev": true, + "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^2.0.2" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -2614,16 +2774,14 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/@typescript-eslint/utils": { + "node_modules/@typescript-eslint/scope-manager": { "version": "8.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.54.0.tgz", - "integrity": "sha512-9Cnda8GS57AQakvRyG0PTejJNlA2xhvyNtEVIMlDWOOeEyBkYWhGPnfrIAnqxLMTSTo6q8g12XVjjev5l1NvMA==", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.54.0.tgz", + "integrity": "sha512-27rYVQku26j/PbHYcVfRPonmOlVI6gihHtXFbTdB5sb6qA0wdAQAbyXFVarQ5t4HRojIz64IV90YtsjQSSGlQg==", "dev": true, "dependencies": { - "@eslint-community/eslint-utils": "^4.9.1", - "@typescript-eslint/scope-manager": "8.54.0", "@typescript-eslint/types": "8.54.0", - "@typescript-eslint/typescript-estree": "8.54.0" + "@typescript-eslint/visitor-keys": "8.54.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2631,10 +2789,19 @@ "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/types": { + "version": "8.54.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.54.0.tgz", + "integrity": "sha512-PDUI9R1BVjqu7AUDsRBbKMtwmjWcn4J3le+5LpcFgWULN3LvHC5rkc9gCVxbrsrGmO1jfPybN5s6h4Jy+OnkAA==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, - "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0", - "typescript": ">=4.8.4 <6.0.0" + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" } }, "node_modules/@typescript-eslint/visitor-keys": { @@ -5491,10 +5658,11 @@ "peer": true }, "node_modules/semver": { - "version": "7.7.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", - "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", "dev": true, + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -5903,10 +6071,11 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.2.tgz", + "integrity": "sha512-bGdAIrZ0wiGDo5l8c++HWtbaNCWTS4UTv7RaTH/ThVIgjkveJt83m74bBHMJkuCbslY8ixgLBVZJIOiQlQTjfQ==", "dev": true, + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 9bc8ffb2b..e7e5015f1 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "eslint": "^9.39.2", "globals": "^17.3.0", "prettier": "^3.8.1", - "typescript": "^5.9.3", + "typescript": "^6.0.0", "vitepress": "^1.6.4", "vitest": "^4.1.4" }, diff --git a/packages/owl/src/common/utils.ts b/packages/owl/src/common/utils.ts index 95ea39019..b3c3ec725 100644 --- a/packages/owl/src/common/utils.ts +++ b/packages/owl/src/common/utils.ts @@ -12,7 +12,7 @@ export function parseXML(xml: string): XMLDocument { const doc = parser.parseFromString(xml, "text/xml"); if (doc.getElementsByTagName("parsererror").length) { let msg = "Invalid XML in template."; - const parsererrorText = doc.getElementsByTagName("parsererror")[0].textContent; + const parsererrorText = doc.getElementsByTagName("parsererror")[0]!.textContent; if (parsererrorText) { msg += "\nThe parser has produced the following error message:\n" + parsererrorText; const re = /\d+/g; diff --git a/packages/owl/src/compiler/code_generator.ts b/packages/owl/src/compiler/code_generator.ts index c6339e214..a4f3dc9e1 100644 --- a/packages/owl/src/compiler/code_generator.ts +++ b/packages/owl/src/compiler/code_generator.ts @@ -535,7 +535,7 @@ export class CodeGenerator { const bareArrowMatch = !arrowMatch && compiled.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=>/); if (arrowMatch) { - const inner = arrowMatch[1].slice(1, -1).trim(); + const inner = arrowMatch[1]!.slice(1, -1).trim(); const rest = compiled.slice(arrowMatch[0].length); hoistedExpr = inner ? `(ctx,${inner})=>${rest}` : `(ctx)=>${rest}`; } else if (bareArrowMatch) { @@ -573,14 +573,14 @@ export class CodeGenerator { for (let key in ast.attrs) { let expr, attrName; if (key.startsWith("t-attf")) { - expr = interpolate(ast.attrs[key]); + expr = interpolate(ast.attrs[key]!); const idx = block!.insertData(expr, "attr"); attrName = key.slice(7); attrs["block-attribute-" + idx] = attrName; } else if (key.startsWith("t-att")) { attrName = key === "t-att" ? null : key.slice(6); - expr = compileExpr(ast.attrs[key]); + expr = compileExpr(ast.attrs[key]!); if (attrName && isProp(ast.tag, attrName)) { if (attrName === "readonly") { // the property has a different name than the attribute @@ -605,11 +605,11 @@ export class CodeGenerator { } } else if (this.translatableAttributes.includes(key)) { const attrTranslationCtx = ast.attrsTranslationCtx?.[key] || ctx.translationCtx; - attrs[key] = this.translateFn(ast.attrs[key], attrTranslationCtx); + attrs[key] = this.translateFn(ast.attrs[key]!, attrTranslationCtx); } else { - expr = `"${ast.attrs[key]}"`; + expr = `"${ast.attrs[key]!}"`; attrName = key; - attrs[key] = ast.attrs[key]; + attrs[key] = ast.attrs[key]!; } if (attrName === "value" && ctx.tModelSelectedExpr) { @@ -679,7 +679,7 @@ export class CodeGenerator { // event handlers for (let ev in ast.on) { - const name = this.generateHandlerCode(ev, ast.on[ev]); + const name = this.generateHandlerCode(ev, ast.on[ev]!); const idx = block!.insertData(name, "hdlr"); attrs[`block-handler-${idx}`] = ev; } @@ -708,7 +708,7 @@ export class CodeGenerator { block!.currentDom = dom; const children = ast.content; for (let i = 0; i < children.length; i++) { - const child = ast.content[i]; + const child = ast.content[i]!; const subCtx = createContext(ctx, { block, index: block!.childNumber, @@ -729,11 +729,11 @@ export class CodeGenerator { if (block!.children.length && block!.hasDynamicChildren) { const code = this.target.code; const children = block!.children.slice(); - let current = children.shift(); + let current = children.shift()!; for (let i = codeIdx; i < code.length; i++) { - if (code[i].trimStart().startsWith(`const ${current!.varName} `)) { - code[i] = code[i].replace(`const ${current!.varName}`, current!.varName); - current = children.shift(); + if (code[i]!.trimStart().startsWith(`const ${current.varName} `)) { + code[i] = code[i]!.replace(`const ${current.varName}`, current.varName); + current = children.shift()!; if (!current) break; } } @@ -817,11 +817,11 @@ export class CodeGenerator { if (block!.children.length) { const code = this.target.code; const children = block!.children.slice(); - let current = children.shift(); + let current = children.shift()!; for (let i = codeIdx; i < code.length; i++) { - if (code[i].trimStart().startsWith(`const ${current!.varName} `)) { - code[i] = code[i].replace(`const ${current!.varName}`, current!.varName); - current = children.shift(); + if (code[i]!.trimStart().startsWith(`const ${current.varName} `)) { + code[i] = code[i]!.replace(`const ${current.varName}`, current.varName); + current = children.shift()!; if (!current) break; } } @@ -914,7 +914,7 @@ export class CodeGenerator { // Check if there are non-DOM directives (like t-set) after the DOM child. // If so, defer the return so those directives are compiled before it. const shouldDefer = - !this.target.hasRoot && ast.content[ast.content.length - 1].hasNoRepresentation; + !this.target.hasRoot && ast.content[ast.content.length - 1]!.hasNoRepresentation; if (shouldDefer) { this.target.deferReturn = true; } @@ -932,7 +932,7 @@ export class CodeGenerator { } let index = 0; for (let i = 0, l = ast.content.length; i < l; i++) { - const child = ast.content[i]; + const child = ast.content[i]!; const forceNewBlock = !child.hasNoRepresentation; const subCtx = createContext(ctx, { block, @@ -948,11 +948,11 @@ export class CodeGenerator { if (block!.hasDynamicChildren && block!.children.length) { const code = this.target.code; const children = block!.children.slice(); - let current = children.shift(); + let current = children.shift()!; for (let i = codeIdx; i < code.length; i++) { - if (code[i].trimStart().startsWith(`const ${current!.varName} `)) { - code[i] = code[i].replace(`const ${current!.varName}`, current!.varName); - current = children.shift(); + if (code[i]!.trimStart().startsWith(`const ${current.varName} `)) { + code[i] = code[i]!.replace(`const ${current.varName}`, current.varName); + current = children.shift()!; if (!current) break; } } @@ -1110,7 +1110,7 @@ export class CodeGenerator { } if (name.includes(".")) { let [_name, suffix] = name.split("."); - name = _name; + name = _name!; switch (suffix) { case "bind": value = `(${value}).bind(this)`; @@ -1155,14 +1155,15 @@ export class CodeGenerator { for (let p in ast.props || {}) { let [name, suffix] = p.split("."); + name = name!; if (suffix) { // .alike, .bind, .translate — delegate to formatProp, no propList entry - props.push(this.formatProp(p, ast.props![p], ast.propsTranslationCtx, ctx.translationCtx)); + props.push(this.formatProp(p, ast.props![p]!, ast.propsTranslationCtx, ctx.translationCtx)); continue; } - const { expr: compiledValue, freeVariables } = processExpr(ast.props![p]); + const { expr: compiledValue, freeVariables } = processExpr(ast.props![p]!); const propName = /^[a-z_]+$/i.test(name) ? name : `'${name}'`; props.push(`${propName}: ${compiledValue || undefined}`); @@ -1183,21 +1184,21 @@ export class CodeGenerator { if (ast.slots) { let slotStr: string[] = []; for (let slotName in ast.slots) { - const slotAst = ast.slots[slotName]; + const slotAst = ast.slots[slotName]!; const params = []; if (slotAst.content) { const name = this.compileInNewTarget("slot", slotAst.content, ctx, slotAst.on); params.push(`__render: ${name}.bind(this), __ctx: ctx`); } - const scope = ast.slots[slotName].scope; + const scope = slotAst.scope; if (scope) { params.push(`__scope: "${scope}"`); } - if (ast.slots[slotName].attrs) { + if (slotAst.attrs) { params.push( ...this.formatPropObject( - ast.slots[slotName].attrs!, - ast.slots[slotName].attrsTranslationCtx, + slotAst.attrs!, + slotAst.attrsTranslationCtx, ctx.translationCtx ) ); @@ -1285,7 +1286,7 @@ export class CodeGenerator { let handlerId = generateId("hdlr"); let idx = handlers.push(handlerId) - 1; spec[ev] = idx; - const handler = this.generateHandlerCode(ev, on[ev]); + const handler = this.generateHandlerCode(ev, on[ev]!); this.define(handlerId, handler); } this.staticDefs.push({ id: name, expr: `createCatcher(${JSON.stringify(spec)})` }); @@ -1309,7 +1310,7 @@ export class CodeGenerator { this.slotNames.add(ast.name); } const attrs = { ...ast.attrs }; - const dynProps = attrs["t-props"]; + const dynProps = attrs["t-props"] ?? null; delete attrs["t-props"]; let key = this.target.loopLevel ? `key${this.target.loopLevel}` : "key"; if (isMultiple) { diff --git a/packages/owl/src/compiler/inline_expressions.ts b/packages/owl/src/compiler/inline_expressions.ts index b4b2a1aa6..a57372a9d 100644 --- a/packages/owl/src/compiler/inline_expressions.ts +++ b/packages/owl/src/compiler/inline_expressions.ts @@ -129,8 +129,8 @@ let tokenizeNumber: Tokenizer = function (expr) { let s = expr[0]; if (s && s.match(/[0-9]/)) { let i = 1; - while (expr[i] && expr[i].match(/[0-9]|\./)) { - s += expr[i]; + while (expr[i] && expr[i]!.match(/[0-9]|\./)) { + s += expr[i]! i++; } return { type: "VALUE", value: s }; @@ -143,12 +143,12 @@ let tokenizeSymbol: Tokenizer = function (expr) { let s = expr[0]; if (s && s.match(/[a-zA-Z_\$]/)) { let i = 1; - while (expr[i] && expr[i].match(/[\w\$]/)) { - s += expr[i]; + while (expr[i] && expr[i]!.match(/[\w\$]/)) { + s += expr[i]! i++; } if (s in WORD_REPLACEMENT) { - return { type: "OPERATOR", value: WORD_REPLACEMENT[s], size: s.length }; + return { type: "OPERATOR", value: WORD_REPLACEMENT[s]!, size: s.length }; } return { type: "SYMBOL", value: s }; } else { @@ -159,7 +159,7 @@ let tokenizeSymbol: Tokenizer = function (expr) { const tokenizeStatic: Tokenizer = function (expr) { const char = expr[0]; if (char && char in STATIC_TOKEN_MAP) { - return { type: STATIC_TOKEN_MAP[char], value: char }; + return { type: STATIC_TOKEN_MAP[char]!, value: char }; } return false; }; @@ -277,7 +277,7 @@ export function processExpr(expr: string): ProcessedExpr { let topLevelArrowIndex = -1; while (i < tokens.length) { - let token = tokens[i]; + let token = tokens[i]!; let prevToken = tokens[i - 1]; let nextToken = tokens[i + 1]; let groupType = stack[stack.length - 1]; @@ -301,10 +301,10 @@ export function processExpr(expr: string): ProcessedExpr { if ( groupType === "LEFT_BRACE" && isLeftSeparator(prevToken) && - isRightSeparator(nextToken) + nextToken && isRightSeparator(nextToken) ) { tokens.splice(i + 1, 0, { type: "COLON", value: ":" }, { ...token }); - nextToken = tokens[i + 1]; + nextToken = tokens[i + 1]!; } if (prevToken.type === "OPERATOR" && prevToken.value === ".") { @@ -325,10 +325,10 @@ export function processExpr(expr: string): ProcessedExpr { } if (token.type === "RIGHT_PAREN") { let j = i - 1; - while (j > 0 && tokens[j].type !== "LEFT_PAREN") { - if (tokens[j].type === "SYMBOL" && tokens[j].originalValue) { - tokens[j].value = tokens[j].originalValue!; - localVars.add(tokens[j].value); + while (j > 0 && tokens[j]!.type !== "LEFT_PAREN") { + if (tokens[j]!.type === "SYMBOL" && tokens[j]!.originalValue) { + tokens[j]!.value = tokens[j]!.originalValue!; + localVars.add(tokens[j]!.value); } j--; } @@ -363,7 +363,7 @@ export function processExpr(expr: string): ProcessedExpr { freeVariables = []; const seen = new Set(); for (let i = topLevelArrowIndex + 1; i < tokens.length; i++) { - const t = tokens[i]; + const t = tokens[i]!; if (t.varName && !t.isLocal && t.varName !== "this" && !seen.has(t.varName)) { seen.add(t.varName); freeVariables.push(t.varName); diff --git a/packages/owl/src/compiler/parser.ts b/packages/owl/src/compiler/parser.ts index 2e68876ab..506594395 100644 --- a/packages/owl/src/compiler/parser.ts +++ b/packages/owl/src/compiler/parser.ts @@ -291,7 +291,7 @@ function parseTCustom(node: Element, ctx: ParsingContext): AST | null { throw new OwlError("Missing custom directive name with t-custom directive"); } if (attr.startsWith("t-custom-")) { - const directiveName = attr.split(".")[0].slice(9); + const directiveName = attr.split(".")[0]!.slice(9); const customDirective = ctx.customDirectives[directiveName]; if (!customDirective) { throw new OwlError(`Custom directive "${directiveName}" is not defined`); @@ -704,7 +704,7 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null { ); } - if (!(firstLetter === firstLetter.toUpperCase() || isDynamic)) { + if (!(firstLetter === firstLetter!.toUpperCase() || isDynamic)) { return null; } if (isDynamic) { @@ -760,7 +760,7 @@ function parseComponent(node: Element, ctx: ParsingContext): AST | null { let el = slotNode.parentElement!; let isInSubComponent = false; while (el && el !== clone) { - if (el!.hasAttribute("t-component") || el!.tagName[0] === el!.tagName[0].toUpperCase()) { + if (el!.hasAttribute("t-component") || el!.tagName[0] === el!.tagName[0]!.toUpperCase()) { isInSubComponent = true; break; } @@ -960,7 +960,7 @@ function parseChildNodes(node: Element, ctx: ParsingContext): AST | null { case 0: return null; case 1: - return children[0]; + return children[0]!; default: return makeASTMulti(children); } @@ -977,10 +977,10 @@ function parseChildNodes(node: Element, ctx: ParsingContext): AST | null { function normalizeTIf(el: Element) { let tbranch = el.querySelectorAll("[t-elif], [t-else]"); for (let i = 0, ilen = tbranch.length; i < ilen; i++) { - let node = tbranch[i]; + let node = tbranch[i]!; let prevElem = node.previousElementSibling!; let pattr = (name: string) => prevElem.getAttribute(name); - let nattr = (name: string) => +!!node.getAttribute(name); + let nattr = (name: string) => +!!node!.getAttribute(name); if (prevElem && (pattr("t-if") || pattr("t-elif"))) { if (pattr("t-foreach")) { throw new OwlError( @@ -1021,7 +1021,7 @@ function normalizeTIf(el: Element) { */ function normalizeTOut(el: Element) { const elements = [...el.querySelectorAll(`[t-out]`)].filter( - (el) => el.tagName[0] === el.tagName[0].toUpperCase() || el.hasAttribute("t-component") + (el) => el.tagName[0] === el.tagName[0]!.toUpperCase() || el.hasAttribute("t-component") ); for (const el of elements) { if (el.childNodes.length) { diff --git a/packages/owl/src/compiler/standalone/index.ts b/packages/owl/src/compiler/standalone/index.ts index 793ad4ebd..1236d9494 100644 --- a/packages/owl/src/compiler/standalone/index.ts +++ b/packages/owl/src/compiler/standalone/index.ts @@ -62,7 +62,7 @@ export async function compileTemplates(paths: string[]) { const fileContent = xmlStrings[i]; process.stdout.write(`.`); const parser = new DOMParser(); - const doc = parser.parseFromString(fileContent, "text/xml"); + const doc = parser.parseFromString(fileContent!, "text/xml"); for (const template of doc.querySelectorAll("[t-name]")) { const name = template.getAttribute("t-name"); if (template.hasAttribute("owl")) { diff --git a/packages/owl/src/runtime/blockdom/attributes.ts b/packages/owl/src/runtime/blockdom/attributes.ts index 09789deb9..8be73134a 100644 --- a/packages/owl/src/runtime/blockdom/attributes.ts +++ b/packages/owl/src/runtime/blockdom/attributes.ts @@ -121,7 +121,7 @@ function toClassObj(expr: string | number | { [c: string]: any }) { } let words = split.call(str, wordRegexp); for (let i = 0, l = words.length; i < l; i++) { - result[words[i]] = true; + result[words[i]!] = true; } return result; case "object": @@ -159,7 +159,7 @@ const CSS_PROP_CACHE: { [key: string]: string } = {}; function toKebabCase(prop: string): string { if (prop in CSS_PROP_CACHE) { - return CSS_PROP_CACHE[prop]; + return CSS_PROP_CACHE[prop]!; } const result = prop.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase()); CSS_PROP_CACHE[prop] = result; diff --git a/packages/owl/src/runtime/blockdom/block_compiler.ts b/packages/owl/src/runtime/blockdom/block_compiler.ts index add4ccc07..c75055b38 100644 --- a/packages/owl/src/runtime/blockdom/block_compiler.ts +++ b/packages/owl/src/runtime/blockdom/block_compiler.ts @@ -62,7 +62,7 @@ const cache: { [key: string]: BlockType } = {}; */ export function createBlock(str: string): BlockType { if (str in cache) { - return cache[str]; + return cache[str]!; } // step 0: prepare html base element @@ -175,8 +175,8 @@ function buildTree( } const attrs = (node as Element).attributes; for (let i = 0; i < attrs.length; i++) { - const attrName = attrs[i].name; - const attrValue = attrs[i].value; + const attrName = attrs[i]!.name; + const attrValue = attrs[i]!.value; if (attrName.startsWith("block-handler-")) { const idx = parseInt(attrName.slice(14), 10); info.push({ @@ -211,7 +211,7 @@ function buildTree( idx: parseInt(attrValue, 10), }); } else { - el.setAttribute(attrs[i].name, attrValue); + el.setAttribute(attrs[i]!.name, attrValue); } } } @@ -227,7 +227,7 @@ function buildTree( }; if (node.firstChild) { - const childNode = node.childNodes[0]; + const childNode = node.childNodes[0]!; if ( node.childNodes.length === 1 && childNode.nodeType === Node.ELEMENT_NODE && @@ -566,15 +566,15 @@ function createBlockClass(template: HTMLElement, ctx: BlockCtx): BlockClass { this.refs = refs; refs[0] = el; for (let i = 0; i < colN; i++) { - const packed = colPacked[i]; - refs[packed & 0x7fff] = GETTERS[(packed >> 30) & 1].call(refs[(packed >> 15) & 0x7fff])!; + const packed = colPacked[i]!; + refs[packed & 0x7fff] = GETTERS[(packed >> 30) & 1]!.call(refs[(packed >> 15) & 0x7fff]!)!; } // applying data to all update points if (locN) { const data = this.data!; for (let i = 0; i < locN; i++) { - locSetters[i].call(refs[locRefIdxs[i]], data[i]); + locSetters[i]!.call(refs[locRefIdxs[i]!], data[i]); } } @@ -584,9 +584,9 @@ function createBlockClass(template: HTMLElement, ctx: BlockCtx): BlockClass { for (let i = 0; i < childN; i++) { const child = children![i]; if (child) { - const info = childInfos[i]; + const info = childInfos[i]!; const afterRefIdx = (info >> 16) & 0x7fff; - const afterNode = afterRefIdx ? refs[afterRefIdx] : null; + const afterNode = afterRefIdx ? refs[afterRefIdx]! : null; child.isOnlyChild = !!(info & (1 << 15)); child.mount(refs[info & 0x7fff] as any, afterNode); } @@ -602,7 +602,7 @@ function createBlockClass(template: HTMLElement, ctx: BlockCtx): BlockClass { const refs = this.refs!; for (let cbRef of cbRefs) { const fn = data[cbRef]; - fn(refs[locRefIdxs[cbRef]], null); + fn(refs[locRefIdxs[cbRef]!], null); } } }; @@ -620,7 +620,7 @@ function createBlockClass(template: HTMLElement, ctx: BlockCtx): BlockClass { const val1 = data1[i]; const val2 = data2[i]; if (val1 !== val2) { - locUpdaters[i].call(refs[locRefIdxs[i]], val2, val1); + locUpdaters[i]!.call(refs[locRefIdxs[i]!], val2, val1); } } this.data = data2; @@ -644,9 +644,9 @@ function createBlockClass(template: HTMLElement, ctx: BlockCtx): BlockClass { children1![i] = undefined; } } else if (child2) { - const info = childInfos[i]; + const info = childInfos[i]!; const afterRefIdx = (info >> 16) & 0x7fff; - const afterNode = afterRefIdx ? refs[afterRefIdx] : null; + const afterNode = afterRefIdx ? refs[afterRefIdx]! : null; child2.mount(refs[info & 0x7fff] as any, afterNode); children1![i] = child2; } @@ -660,7 +660,7 @@ function createBlockClass(template: HTMLElement, ctx: BlockCtx): BlockClass { const refs = this.refs!; for (let cbRef of cbRefs) { const fn = data[cbRef]; - fn(null, refs[locRefIdxs[cbRef]]); + fn(null, refs[locRefIdxs[cbRef]!]); } } diff --git a/packages/owl/src/runtime/blockdom/event_catcher.ts b/packages/owl/src/runtime/blockdom/event_catcher.ts index b51577d74..89ba132d5 100644 --- a/packages/owl/src/runtime/blockdom/event_catcher.ts +++ b/packages/owl/src/runtime/blockdom/event_catcher.ts @@ -28,10 +28,10 @@ export function createCatcher(eventsSpec: EventsSpec): Catcher { parent.insertBefore(this.afterNode, afterNode); this.wrapHandlerData(); for (let name in eventsSpec) { - const index = eventsSpec[name]; + const index = eventsSpec[name]!; const handler = createEventHandler(name); this.handlerFns[index] = handler; - handler.setup.call(parent, this.handlerData[index]); + handler.setup.call(parent, this.handlerData[index]!); } } diff --git a/packages/owl/src/runtime/blockdom/events.ts b/packages/owl/src/runtime/blockdom/events.ts index 0edb641b0..d419dbb80 100644 --- a/packages/owl/src/runtime/blockdom/events.ts +++ b/packages/owl/src/runtime/blockdom/events.ts @@ -10,13 +10,13 @@ interface EventHandlerCreator { } export function createEventHandler(rawEvent: string): EventHandlerCreator { - const eventName = rawEvent.split(".")[0]; + const eventName = rawEvent.split(".")[0]!; const capture = rawEvent.includes(".capture"); const passive = rawEvent.includes(".passive"); if (rawEvent.includes(".synthetic")) { return createSyntheticHandler(eventName, capture, passive); } else { - return createElementHandler(eventName, capture, passive); + return createElementHandler(eventName!, capture, passive); } } diff --git a/packages/owl/src/runtime/blockdom/html.ts b/packages/owl/src/runtime/blockdom/html.ts index 429b2986d..ec4d74cdd 100644 --- a/packages/owl/src/runtime/blockdom/html.ts +++ b/packages/owl/src/runtime/blockdom/html.ts @@ -40,7 +40,7 @@ class VHtml { } moveBeforeVNode(other: VHtml | null, afterNode: Node | null) { - const target = other ? other.content[0] : afterNode; + const target = other ? other.content[0]! : afterNode; this.moveBeforeDOMNode(target); } @@ -52,7 +52,7 @@ class VHtml { if (this.html !== html2) { const parent = this.parentEl; // insert new html in front of current - const afterNode = this.content[0]; + const afterNode = this.content[0]!; const template = document.createElement("template"); template.innerHTML = html2; const content = [...(template.content.childNodes as any)]; diff --git a/packages/owl/src/runtime/blockdom/list.ts b/packages/owl/src/runtime/blockdom/list.ts index f26fa867c..a07b4b327 100644 --- a/packages/owl/src/runtime/blockdom/list.ts +++ b/packages/owl/src/runtime/blockdom/list.ts @@ -1,6 +1,6 @@ import type { VNode } from "./index"; -const getDescriptor = (o: any, p: any) => Object.getOwnPropertyDescriptor(o, p)!; +const getDescriptor = (o: object, p: string) => Object.getOwnPropertyDescriptor(o, p)!; let nodeInsertBefore: typeof Node.prototype.insertBefore; let nodeAppendChild: typeof Node.prototype.appendChild; let nodeRemoveChild: typeof Node.prototype.removeChild; @@ -34,7 +34,7 @@ class VList { nodeInsertBefore.call(parent, _anchor, afterNode); const l = children.length; if (l) { - const mount = children[0].mount; + const mount = children[0]!.mount; for (let i = 0; i < l; i++) { mount.call(children[i], parent, _anchor); } @@ -47,7 +47,7 @@ class VList { this.parentEl = parent; const children = this.children; for (let i = 0, l = children.length; i < l; i++) { - children[i].moveBeforeDOMNode(node, parent); + children[i]!.moveBeforeDOMNode(node, parent); } parent!.insertBefore(this.anchor!, node); } @@ -59,7 +59,7 @@ class VList { } const children = this.children; for (let i = 0, l = children.length; i < l; i++) { - children[i].moveBeforeVNode(null, afterNode); + children[i]!.moveBeforeVNode(null, afterNode); } this.parentEl!.insertBefore(this.anchor!, afterNode); } @@ -74,7 +74,7 @@ class VList { return; } this.children = ch2; - const proto = ch2[0] || ch1[0]; + const proto = (ch2[0] || ch1[0])!; const { mount: cMount, patch: cPatch, @@ -110,7 +110,7 @@ class VList { let endVn1 = ch1[endIdx1]; let endVn2 = ch2[endIdx2]; - let mapping: any = undefined; + let mapping: Record | undefined = undefined; while (startIdx1 <= endIdx1 && startIdx2 <= endIdx2) { // ------------------------------------------------------------------- @@ -124,21 +124,21 @@ class VList { continue; } // ------------------------------------------------------------------- - let startKey1 = startVn1.key; - let startKey2 = startVn2.key; + let startKey1 = startVn1!.key; + let startKey2 = startVn2!.key; if (startKey1 === startKey2) { cPatch.call(startVn1, startVn2, withBeforeRemove); - ch2[startIdx2] = startVn1; + ch2[startIdx2] = startVn1!; startVn1 = ch1[++startIdx1]; startVn2 = ch2[++startIdx2]; continue; } // ------------------------------------------------------------------- - let endKey1 = endVn1.key; - let endKey2 = endVn2.key; + let endKey1 = endVn1!.key; + let endKey2 = endVn2!.key; if (endKey1 === endKey2) { cPatch.call(endVn1, endVn2, withBeforeRemove); - ch2[endIdx2] = endVn1; + ch2[endIdx2] = endVn1!; endVn1 = ch1[--endIdx1]; endVn2 = ch2[--endIdx2]; continue; @@ -147,7 +147,7 @@ class VList { if (startKey1 === endKey2) { // bnode moved right cPatch.call(startVn1, endVn2, withBeforeRemove); - ch2[endIdx2] = startVn1; + ch2[endIdx2] = startVn1!; const nextChild = ch2[endIdx2 + 1]; cMoveBefore.call(startVn1, nextChild, _anchor); startVn1 = ch1[++startIdx1]; @@ -158,7 +158,7 @@ class VList { if (endKey1 === startKey2) { // bnode moved left cPatch.call(endVn1, startVn2, withBeforeRemove); - ch2[startIdx2] = endVn1; + ch2[startIdx2] = endVn1!; const nextChild = ch1[startIdx1]; cMoveBefore.call(endVn1, nextChild, _anchor); endVn1 = ch1[--endIdx1]; @@ -171,7 +171,7 @@ class VList { if (idxInOld === undefined) { cMount.call(startVn2, parent, cFirstNode.call(startVn1) || null); } else { - const elmToMove = ch1[idxInOld]; + const elmToMove = ch1[idxInOld]!; cMoveBefore.call(elmToMove, startVn1, null); cPatch.call(elmToMove, startVn2, withBeforeRemove); ch2[startIdx2] = elmToMove; @@ -205,7 +205,7 @@ class VList { const children = this.children; const l = children.length; if (l) { - const beforeRemove = children[0].beforeRemove; + const beforeRemove = children[0]!.beforeRemove; for (let i = 0; i < l; i++) { beforeRemove.call(children[i]); } @@ -220,7 +220,7 @@ class VList { const children = this.children; const l = children.length; if (l) { - const remove = children[0].remove; + const remove = children[0]!.remove; for (let i = 0; i < l; i++) { remove.call(children[i]); } @@ -243,10 +243,10 @@ export function list(children: VNode[]): VNode { return new VList(children); } -function createMapping(ch1: any[], startIdx1: number, endIdx2: number): { [key: string]: any } { - let mapping: any = {}; +function createMapping(ch1: (VNode | null)[], startIdx1: number, endIdx2: number): Record { + let mapping: Record = {}; for (let i = startIdx1; i <= endIdx2; i++) { - mapping[ch1[i].key] = i; + mapping[ch1[i]!.key] = i; } return mapping; } diff --git a/packages/owl/src/runtime/blockdom/multi.ts b/packages/owl/src/runtime/blockdom/multi.ts index 2c53eb80f..6bc688993 100644 --- a/packages/owl/src/runtime/blockdom/multi.ts +++ b/packages/owl/src/runtime/blockdom/multi.ts @@ -52,7 +52,7 @@ export class VMulti { if (child) { child.moveBeforeDOMNode(node, parent); } else { - const anchor = anchors![i]; + const anchor = anchors![i]!; nodeInsertBefore.call(parent, anchor, node); } } @@ -61,7 +61,7 @@ export class VMulti { moveBeforeVNode(other: VMulti | null, afterNode: Node | null) { if (other) { const next = other!.children[0]; - afterNode = (next ? next.firstNode() : other!.anchors![0]) || null; + afterNode = (next ? next.firstNode() : other!.anchors![0]!) || null; } const children = this.children; const parent = this.parentEl; @@ -71,7 +71,7 @@ export class VMulti { if (child) { child.moveBeforeVNode(null, afterNode); } else { - const anchor = anchors![i]; + const anchor = anchors![i]!; nodeInsertBefore.call(parent, anchor, afterNode); } } @@ -104,7 +104,7 @@ export class VMulti { } } else if (vn2) { children1[i] = vn2; - const anchor = anchors[i]; + const anchor = anchors[i]!; vn2.mount(parentEl, anchor); nodeRemoveChild.call(parentEl, anchor); } @@ -133,7 +133,7 @@ export class VMulti { if (child) { child.remove(); } else { - nodeRemoveChild.call(parentEl, anchors![i]); + nodeRemoveChild.call(parentEl, anchors![i]!); } } } diff --git a/packages/owl/src/runtime/component_node.ts b/packages/owl/src/runtime/component_node.ts index 2d792beb2..09da446e9 100644 --- a/packages/owl/src/runtime/component_node.ts +++ b/packages/owl/src/runtime/component_node.ts @@ -164,7 +164,7 @@ export class ComponentNode implements VNode { this.status = STATUS.CANCELLED; const children = this.children; for (let childKey in children) { - children[childKey]._cancel(); + children[childKey]!._cancel(); } } @@ -184,7 +184,7 @@ export class ComponentNode implements VNode { } } for (let childKey in this.children) { - this.children[childKey]._destroy(); + this.children[childKey]!._destroy(); } if (this.willDestroy.length) { try { @@ -247,7 +247,7 @@ export class ComponentNode implements VNode { // If the error was handled by some child component, we need to find it to // apply its change for (let k in this.children) { - const child = this.children[k]; + const child = this.children[k]!; child.updateDom(); } } else { diff --git a/packages/owl/src/runtime/lifecycle_hooks.ts b/packages/owl/src/runtime/lifecycle_hooks.ts index 558facb82..f60ddba9b 100644 --- a/packages/owl/src/runtime/lifecycle_hooks.ts +++ b/packages/owl/src/runtime/lifecycle_hooks.ts @@ -23,37 +23,37 @@ function decorate(node: ComponentNode, f: Function, hookName: string) { return f.bind(node.component); } -export function onWillStart(fn: () => Promise | void | any) { +export function onWillStart(fn: () => void | Promise) { const { node } = getContext("component"); node.willStart.push(decorate(node, fn, "onWillStart")); } -export function onWillUpdateProps(fn: (nextProps: any) => Promise | void | any) { +export function onWillUpdateProps(fn: (nextProps: Record) => void | Promise) { const { node } = getContext("component"); node.willUpdateProps.push(decorate(node, fn, "onWillUpdateProps")); } -export function onMounted(fn: () => void | any) { +export function onMounted(fn: () => void) { const { node } = getContext("component"); node.mounted.push(decorate(node, fn, "onMounted")); } -export function onWillPatch(fn: () => any | void) { +export function onWillPatch(fn: () => void) { const { node } = getContext("component"); node.willPatch.unshift(decorate(node, fn, "onWillPatch")); } -export function onPatched(fn: () => void | any) { +export function onPatched(fn: () => void) { const { node } = getContext("component"); node.patched.push(decorate(node, fn, "onPatched")); } -export function onWillUnmount(fn: () => void | any) { +export function onWillUnmount(fn: () => void) { const { node } = getContext("component"); node.willUnmount.unshift(decorate(node, fn, "onWillUnmount")); } -export function onWillDestroy(fn: () => void | any) { +export function onWillDestroy(fn: () => void) { const context = getContext(); if (context.type === "component") { context.node.willDestroy.unshift(decorate(context.node, fn, "onWillDestroy")); @@ -62,7 +62,7 @@ export function onWillDestroy(fn: () => void | any) { } } -type OnErrorCallback = (error: any) => void | any; +type OnErrorCallback = (error: unknown) => void; export function onError(callback: OnErrorCallback) { const { node } = getContext("component"); let handlers = nodeErrorHandlers.get(node); diff --git a/packages/owl/src/runtime/reactivity/computations.ts b/packages/owl/src/runtime/reactivity/computations.ts index 6071009dd..3e9b254a0 100644 --- a/packages/owl/src/runtime/reactivity/computations.ts +++ b/packages/owl/src/runtime/reactivity/computations.ts @@ -73,7 +73,7 @@ export function onWriteAtom(atom: Atom) { const batchProcessEffects = batched(processEffects); function processEffects() { for (let i = 0; i < observers.length; i++) { - updateComputation(observers[i]); + updateComputation(observers[i]!); } observers.length = 0; } diff --git a/packages/owl/src/runtime/registry.ts b/packages/owl/src/runtime/registry.ts index 7cc00e541..a7b4c2f4f 100644 --- a/packages/owl/src/runtime/registry.ts +++ b/packages/owl/src/runtime/registry.ts @@ -48,7 +48,7 @@ export class Registry { if (!hasKey && arguments.length < 2) { throw new Error(`KeyNotFoundError: Cannot find key "${key}" (registry '${this._name}')`); } - return hasKey ? this._map()[key][1] : defaultValue!; + return hasKey ? this._map()[key]![1] : defaultValue!; } delete(key: string) { diff --git a/packages/owl/src/runtime/rendering/error_handling.ts b/packages/owl/src/runtime/rendering/error_handling.ts index 9fd31df47..7d2e03d26 100644 --- a/packages/owl/src/runtime/rendering/error_handling.ts +++ b/packages/owl/src/runtime/rendering/error_handling.ts @@ -52,7 +52,7 @@ export function handleError(params: ErrorParams) { // execute in the opposite order for (let i = errorHandlers.length - 1; i >= 0; i--) { try { - errorHandlers[i](error, finalize); + errorHandlers[i]!(error, finalize); return; // handled } catch (e) { error = e; diff --git a/packages/owl/src/runtime/rendering/fibers.ts b/packages/owl/src/runtime/rendering/fibers.ts index 9d817d23f..90e99f343 100644 --- a/packages/owl/src/runtime/rendering/fibers.ts +++ b/packages/owl/src/runtime/rendering/fibers.ts @@ -103,7 +103,7 @@ export class Fiber { this.root = root; parent.children.push(this); } else { - this.root = this as any; + this.root = this as unknown as RootFiber; } } diff --git a/packages/owl/src/runtime/template_set.ts b/packages/owl/src/runtime/template_set.ts index 3ba17a277..e7da08f2a 100644 --- a/packages/owl/src/runtime/template_set.ts +++ b/packages/owl/src/runtime/template_set.ts @@ -40,7 +40,7 @@ export class TemplateSet { this.addTemplates(config.templates); } else { for (const name in config.templates) { - this.addTemplate(name, config.templates[name]); + this.addTemplate(name, config.templates[name]!); } } } @@ -56,7 +56,7 @@ export class TemplateSet { if (!this.dev) { return; } - const rawTemplate = this.rawTemplates[name]; + const rawTemplate = this.rawTemplates[name]!; const currentAsString = typeof rawTemplate === "string" ? rawTemplate @@ -102,12 +102,12 @@ export class TemplateSet { // recursive call to the template name const templates = this.templates; this.templates[cacheKey] = function (context, parent) { - return templates[cacheKey].call(this, context, parent); + return templates[cacheKey]!.call(this, context, parent); }; const template = templateFn(this, bdom, this.runtimeUtils); this.templates[cacheKey] = template; } - return this.templates[cacheKey]; + return this.templates[cacheKey]!; } private _compileTemplate(name: string, template: string | Element): ReturnType { diff --git a/packages/owl/src/runtime/utils.ts b/packages/owl/src/runtime/utils.ts index 4e576dd6d..a1e203aff 100644 --- a/packages/owl/src/runtime/utils.ts +++ b/packages/owl/src/runtime/utils.ts @@ -87,7 +87,7 @@ export class EventBus extends EventTarget { } } -export function whenReady(fn?: any): Promise { +export function whenReady(fn?: () => void): Promise { return new Promise(function (resolve) { if (document.readyState !== "loading") { resolve(true); @@ -104,7 +104,7 @@ export function whenReady(fn?: any): Promise { */ export class Markup extends String {} -export function htmlEscape(str: any): Markup { +export function htmlEscape(str: unknown): Markup { if (str instanceof Markup) { return str; } @@ -114,6 +114,7 @@ export function htmlEscape(str: any): Markup { if (typeof str === "number") { return markup(String(str)); } + let result = String(str); [ ["&", "&"], ["<", "<"], @@ -122,9 +123,9 @@ export function htmlEscape(str: any): Markup { ['"', """], ["`", "`"], ].forEach((pairs) => { - str = String(str).replace(new RegExp(pairs[0], "g"), pairs[1]); + result = result.replace(new RegExp(pairs[0]!, "g"), pairs[1]!); }); - return markup(str); + return markup(result); } /* diff --git a/packages/owl/tests/blockdom/block_event_handling.test.ts b/packages/owl/tests/blockdom/block_event_handling.test.ts index 01bad322c..e83236acc 100644 --- a/packages/owl/tests/blockdom/block_event_handling.test.ts +++ b/packages/owl/tests/blockdom/block_event_handling.test.ts @@ -206,7 +206,7 @@ test("synthetic and native handlers can cohabitate (3)", async () => { mount(tree, fixture); expect(fixture.innerHTML).toBe("
"); - const children = fixture.children[0].children; + const children = fixture.children[0]!.children; (children[0] as HTMLElement).click(); expect(steps).toEqual(["1", "0"]); @@ -230,7 +230,7 @@ test("synthetic and native handlers can cohabitate (4)", async () => { mount(tree, fixture); expect(fixture.innerHTML).toBe("
"); - const children = fixture.children[0].children; + const children = fixture.children[0]!.children; (children[0] as HTMLElement).click(); expect(steps).toEqual(["1", "0"]); diff --git a/packages/owl/tests/compiler/event_handling.test.ts b/packages/owl/tests/compiler/event_handling.test.ts index 3a7a8db85..594c1cc84 100644 --- a/packages/owl/tests/compiler/event_handling.test.ts +++ b/packages/owl/tests/compiler/event_handling.test.ts @@ -331,7 +331,7 @@ describe("t-on", () => { }; const node = mountToFixture(template, owner); const div = node.querySelector(".myClass"); - const button = (node).getElementsByTagName("button")[0]; + const button = (node).getElementsByTagName("button")[0]!; button.click(); expect(steps).toEqual(["btnClicked", "divClicked"]); }); @@ -362,9 +362,9 @@ describe("t-on", () => { const node = mountToFixture(template, owner); const buttons = (node).getElementsByTagName("button"); - buttons[0].click(); - buttons[1].click(); - buttons[2].click(); + buttons[0]!.click(); + buttons[1]!.click(); + buttons[2]!.click(); }); test("t-on with self modifier", async () => { @@ -386,10 +386,10 @@ describe("t-on", () => { const buttons = (node).getElementsByTagName("button"); const spans = (node).getElementsByTagName("span"); - spans[0].click(); - spans[1].click(); - buttons[0].click(); - buttons[1].click(); + spans[0]!.click(); + spans[1]!.click(); + buttons[0]!.click(); + buttons[1]!.click(); expect(steps).toEqual(["onClick", "onClick", "onClickSelf"]); }); @@ -408,8 +408,8 @@ describe("t-on", () => { steps.push(e.defaultPrevented); }); - const button = (node).getElementsByTagName("button")[0]; - const span = (node).getElementsByTagName("span")[0]; + const button = (node).getElementsByTagName("button")[0]!; + const span = (node).getElementsByTagName("span")[0]!; span.click(); button.click(); @@ -430,8 +430,8 @@ describe("t-on", () => { steps.push(e.defaultPrevented); }); - const button = (node).getElementsByTagName("button")[0]; - const span = (node).getElementsByTagName("span")[0]; + const button = (node).getElementsByTagName("button")[0]!; + const span = (node).getElementsByTagName("span")[0]!; span.click(); button.click(); @@ -465,9 +465,9 @@ describe("t-on", () => { `` ); - const links = node.querySelectorAll("a")!; - links[0].click(); - links[1].click(); + const links = node.querySelectorAll("a"); + links[0]!.click(); + links[1]!.click(); expect(steps).toEqual([1, 2]); }); @@ -483,7 +483,7 @@ describe("t-on", () => { expect(e.defaultPrevented).toBe(true); }); - const button = (node).getElementsByTagName("button")[0]; + const button = (node).getElementsByTagName("button")[0]!; button.click(); }); @@ -531,7 +531,7 @@ describe("t-on", () => { }; const node = mountToFixture(template, owner); - const button = (node).getElementsByTagName("button")[0]; + const button = (node).getElementsByTagName("button")[0]!; button.click(); expect(steps).toEqual(["captured", "normal"]); }); @@ -588,7 +588,7 @@ describe("t-on", () => { }, }; const node = mountToFixture(template, owner); - const button = (node).getElementsByTagName("button")[0]; + const button = (node).getElementsByTagName("button")[0]!; button.click(); expect(steps).toEqual(["btnClicked", "divClicked"]); }); diff --git a/packages/owl/tests/components/basics.test.ts b/packages/owl/tests/components/basics.test.ts index cc7b268bb..d721cce62 100644 --- a/packages/owl/tests/components/basics.test.ts +++ b/packages/owl/tests/components/basics.test.ts @@ -431,7 +431,7 @@ describe("basics", () => { await mount(Counter, fixture); expect(fixture.innerHTML).toBe("
0
"); - const button = fixture.getElementsByTagName("button")[0]; + const button = fixture.getElementsByTagName("button")[0]!; button.click(); await nextTick(); expect(fixture.innerHTML).toBe("
1
"); @@ -451,7 +451,7 @@ describe("basics", () => { static components = { Counter }; } const parent = await mount(Parent, fixture); - const button = fixture.getElementsByTagName("button")[0]; + const button = fixture.getElementsByTagName("button")[0]!; button.click(); await nextTick(); expect(fixture.innerHTML).toBe("
1
"); @@ -752,12 +752,12 @@ describe("basics", () => { state = proxy({ flag: false }); } const parent = await mount(Parent, fixture); - const child = Object.values(parent.__owl__.children)[0].component as any; + const child = Object.values(parent.__owl__.children)[0]!.component as any; expect(fixture.innerHTML).toBe(`

noo

child
`); parent.state.flag = true; await nextTick(); - expect(Object.values(parent.__owl__.children)[0].component).toBe(child); + expect(Object.values(parent.__owl__.children)[0]!.component).toBe(child); expect(status(child)).toBe("mounted"); expect(fixture.innerHTML).toBe( `

hey

childtest
` diff --git a/packages/owl/tests/components/concurrency.test.ts b/packages/owl/tests/components/concurrency.test.ts index 050dd1b8c..441c6f52c 100644 --- a/packages/owl/tests/components/concurrency.test.ts +++ b/packages/owl/tests/components/concurrency.test.ts @@ -522,9 +522,9 @@ test("update a sub-component twice in the same frame", async () => { ] `); - defs[0].resolve(); + defs[0]!.resolve(); await Promise.resolve(); - defs[1].resolve(); + defs[1]!.resolve(); await nextTick(); expect(fixture.innerHTML).toBe("
3
"); expect(steps.splice(0)).toMatchInlineSnapshot(` @@ -917,7 +917,7 @@ test("concurrent renderings scenario 2", async () => { ] `); - defs[1].resolve(); // resolve rendering initiated in B + defs[1]!.resolve(); // resolve rendering initiated in B await nextTick(); expect(fixture.innerHTML).toBe("
2

2c

"); expect(steps.splice(0)).toMatchInlineSnapshot(` @@ -931,7 +931,7 @@ test("concurrent renderings scenario 2", async () => { ] `); - defs[0].resolve(); // resolve rendering initiated in A + defs[0]!.resolve(); // resolve rendering initiated in A await nextTick(); expect(fixture.innerHTML).toBe("
2

2c

"); expect(steps.splice(0)).toMatchInlineSnapshot(`[]`); @@ -1008,12 +1008,12 @@ test("concurrent renderings scenario 2bis", async () => { ] `); - defs[0].resolve(); // resolve rendering initiated in A + defs[0]!.resolve(); // resolve rendering initiated in A await nextTick(); expect(fixture.innerHTML).toBe("

1b

"); // TODO: is this what we want?? 2b could be ok too expect(steps.splice(0)).toMatchInlineSnapshot(`[]`); - defs[1].resolve(); // resolve rendering initiated in B + defs[1]!.resolve(); // resolve rendering initiated in B await nextTick(); expect(fixture.innerHTML).toBe("

2c

"); expect(steps.splice(0)).toMatchInlineSnapshot(` @@ -1124,7 +1124,7 @@ test("concurrent renderings scenario 3", async () => { ] `); - defsD[0].resolve(); // resolve rendering initiated in C (should be ignored) + defsD[0]!.resolve(); // resolve rendering initiated in C (should be ignored) await nextTick(); expect(fixture.innerHTML).toBe("

2d

"); expect(steps.splice(0)).toMatchInlineSnapshot(` @@ -1237,13 +1237,13 @@ test("concurrent renderings scenario 4", async () => { ] `); - defsD[1].resolve(); // completely resolve rendering initiated in A + defsD[1]!.resolve(); // completely resolve rendering initiated in A await nextTick(); expect(fixture.innerHTML).toBe("

1c

"); expect(ComponentD.prototype.someValue).toHaveBeenCalledTimes(1); expect(steps.splice(0)).toMatchInlineSnapshot(`[]`); - defsD[0].resolve(); // resolve rendering initiated in C (should be ignored) + defsD[0]!.resolve(); // resolve rendering initiated in C (should be ignored) await nextTick(); expect(fixture.innerHTML).toBe("

2d

"); expect(ComponentD.prototype.someValue).toHaveBeenCalledTimes(2); @@ -1319,13 +1319,13 @@ test("concurrent renderings scenario 5", async () => { ] `); - defsB[0].resolve(); // resolve first re-rendering (should be ignored) + defsB[0]!.resolve(); // resolve first re-rendering (should be ignored) await nextTick(); expect(fixture.innerHTML).toBe("

1

"); expect(ComponentB.prototype.someValue).toHaveBeenCalledTimes(1); expect(steps.splice(0)).toMatchInlineSnapshot(`[]`); - defsB[1].resolve(); // resolve second re-rendering + defsB[1]!.resolve(); // resolve second re-rendering await nextTick(); expect(fixture.innerHTML).toBe("

3

"); expect(ComponentB.prototype.someValue).toHaveBeenCalledTimes(2); @@ -1398,7 +1398,7 @@ test("concurrent renderings scenario 6", async () => { ] `); - defsB[1].resolve(); // resolve second re-rendering + defsB[1]!.resolve(); // resolve second re-rendering await nextTick(); expect(fixture.innerHTML).toBe("

3

"); expect(ComponentB.prototype.someValue).toHaveBeenCalledTimes(2); @@ -1411,7 +1411,7 @@ test("concurrent renderings scenario 6", async () => { ] `); - defsB[0].resolve(); // resolve first re-rendering (should be ignored) + defsB[0]!.resolve(); // resolve first re-rendering (should be ignored) await nextTick(); expect(fixture.innerHTML).toBe("

3

"); expect(ComponentB.prototype.someValue).toHaveBeenCalledTimes(2); diff --git a/packages/owl/tests/components/error_handling.test.ts b/packages/owl/tests/components/error_handling.test.ts index 82d6cd0d2..64aa4fa35 100644 --- a/packages/owl/tests/components/error_handling.test.ts +++ b/packages/owl/tests/components/error_handling.test.ts @@ -360,7 +360,7 @@ describe("errors and promises", () => { onWillPatch(() => { throw new Error("boom"); }); - onError((e) => (error = e)); + onError((e) => (error = e as Error)); } } @@ -382,7 +382,7 @@ describe("errors and promises", () => { onPatched(() => { throw new Error("boom"); }); - onError((e) => (error = e)); + onError((e) => (error = e as Error)); } } @@ -423,7 +423,7 @@ describe("errors and promises", () => { static template = xml`
`; flag = false; setup() { - onError((cause) => (error = cause)); + onError((cause) => (error = cause as Error)); } } diff --git a/packages/owl/tests/components/event_handling.test.ts b/packages/owl/tests/components/event_handling.test.ts index 7999fdf28..803fa6888 100644 --- a/packages/owl/tests/components/event_handling.test.ts +++ b/packages/owl/tests/components/event_handling.test.ts @@ -68,7 +68,7 @@ describe("event handling", () => { await mount(Counter, fixture); await nextTick(); expect(fixture.innerHTML).toBe(`
`); - const input = fixture.getElementsByTagName("input")[0]; + const input = fixture.getElementsByTagName("input")[0]!; input.value = "test"; input.dispatchEvent(new Event("input")); await nextTick(); diff --git a/packages/owl/tests/components/hooks.test.ts b/packages/owl/tests/components/hooks.test.ts index c3664088b..ccdc2adb0 100644 --- a/packages/owl/tests/components/hooks.test.ts +++ b/packages/owl/tests/components/hooks.test.ts @@ -326,7 +326,7 @@ describe("hooks", () => { await mount(MyComponent, fixture); expect(fixture.innerHTML).toBe("0"); - const span = fixture.getElementsByTagName("span")[0]; + const span = fixture.getElementsByTagName("span")[0]!; span.click(); await nextTick(); expect(fixture.innerHTML).toBe("1"); diff --git a/packages/owl/tests/components/props.test.ts b/packages/owl/tests/components/props.test.ts index ff20aead2..455fa9b35 100644 --- a/packages/owl/tests/components/props.test.ts +++ b/packages/owl/tests/components/props.test.ts @@ -560,8 +560,8 @@ test("arrow function props re-render when captured variable changes", async () = useLogLifecycle(this); } toggle(id: number) { - const index = this.state.elems.findIndex((el) => el.id === id)!; - const todo = this.state.elems[index]; + const index = this.state.elems.findIndex((el) => el.id === id); + const todo = this.state.elems[index]!; this.state.elems[index] = { ...todo, isChecked: !todo.isChecked }; } } diff --git a/packages/owl/tests/components/props_validation.test.ts b/packages/owl/tests/components/props_validation.test.ts index 4465ba99d..89da08f96 100644 --- a/packages/owl/tests/components/props_validation.test.ts +++ b/packages/owl/tests/components/props_validation.test.ts @@ -679,7 +679,7 @@ describe("props validation", () => { static components = { SubComp }; state: any = { p: 1 }; setup() { - onError((e) => (error = e)); + onError((e) => (error = e as Error)); } } const parent = await mount(Parent, fixture, { dev: true }); diff --git a/packages/owl/tests/components/slots.test.ts b/packages/owl/tests/components/slots.test.ts index 279c07892..b53c82a62 100644 --- a/packages/owl/tests/components/slots.test.ts +++ b/packages/owl/tests/components/slots.test.ts @@ -619,7 +619,7 @@ describe("slots", () => { ); // test updateprops here - app.state.users[1].name = "Mathieu"; + app.state.users[1]!.name = "Mathieu"; await nextTick(); expect(fixture.innerHTML).toBe( '' @@ -659,7 +659,7 @@ describe("slots", () => { ); // test updateprops here - app.state.users[1].name = "Mathieu"; + app.state.users[1]!.name = "Mathieu"; await nextTick(); expect(fixture.innerHTML).toBe( '' @@ -858,7 +858,7 @@ describe("slots", () => { expect(parentChildren.length).toBe(1); expect(parentChildren[0]).toBeInstanceOf(Child); - const childrenChildren = children(parentChildren[0]); + const childrenChildren = children(parentChildren[0]!); expect(childrenChildren.length).toBe(1); expect(childrenChildren[0]).toBeInstanceOf(GrandChild); }); @@ -896,7 +896,7 @@ describe("slots", () => { expect(parentChildren.length).toBe(1); expect(parentChildren[0]).toBeInstanceOf(Child); - const childrenChildren = children(parentChildren[0]); + const childrenChildren = children(parentChildren[0]!); expect(childrenChildren.length).toBe(1); expect(childrenChildren[0]).toBeInstanceOf(GrandChild); }); @@ -1039,10 +1039,10 @@ describe("slots", () => { expect(parent).toBeInstanceOf(UsingTcallInSlotted); expect(children(parent).length).toBe(1); - const slotted = children(parent)[0]; + const slotted = children(parent)[0]!; expect(slotted).toBeInstanceOf(Slotted); expect(children(slotted).length).toBe(1); - const child = children(slotted)[0]; + const child = children(slotted)[0]!; expect(child).toBeInstanceOf(Child); expect(fixture.innerHTML).toBe( diff --git a/packages/owl/tests/components/t_component.test.ts b/packages/owl/tests/components/t_component.test.ts index 1569408f9..6923d6230 100644 --- a/packages/owl/tests/components/t_component.test.ts +++ b/packages/owl/tests/components/t_component.test.ts @@ -188,7 +188,7 @@ describe("t-component", () => { } await mount(ParentWidget, fixture); expect(fixture.innerHTML).toBe("
0
"); - const button = fixture.getElementsByTagName("button")[0]; + const button = fixture.getElementsByTagName("button")[0]!; await button.click(); await nextTick(); expect(fixture.innerHTML).toBe("
1
"); diff --git a/packages/owl/tests/components/t_model.test.ts b/packages/owl/tests/components/t_model.test.ts index 50ec25098..1b09209c7 100644 --- a/packages/owl/tests/components/t_model.test.ts +++ b/packages/owl/tests/components/t_model.test.ts @@ -167,7 +167,7 @@ describe("t-model directive", () => { '
Choice: One
' ); - const secondInput = fixture.querySelectorAll("input")[1]; + const secondInput = fixture.querySelectorAll("input")[1]!; secondInput.click(); await nextTick(); expect(comp.choice()).toBe("Two"); @@ -190,7 +190,7 @@ describe("t-model directive", () => { '
' ); - const secondInput = fixture.querySelectorAll("input")[1]; + const secondInput = fixture.querySelectorAll("input")[1]!; expect(secondInput.checked).toBe(true); }); @@ -410,9 +410,9 @@ describe("t-model directive", () => { const input = fixture.querySelectorAll("input")[1]!; input.click(); - expect(comp.things[1].f()).toBe(true); - expect(comp.things[0].f()).toBe(false); - expect(comp.things[2].f()).toBe(false); + expect(comp.things[1]!.f()).toBe(true); + expect(comp.things[0]!.f()).toBe(false); + expect(comp.things[2]!.f()).toBe(false); }); test("in a t-foreach, part 2", async () => { @@ -565,7 +565,7 @@ describe("t-model directive", () => { expect(comp.choice()).toBe(""); expect(comp.lastClicked()).toBe(""); - const lastInput = fixture.querySelectorAll("input")[2]; + const lastInput = fixture.querySelectorAll("input")[2]!; lastInput.click(); await nextTick(); expect(comp.choice()).toBe("Three"); @@ -682,7 +682,7 @@ describe("t-model directive", () => { expect(comp.value()).toBe(2); // emulate a click on the option=3 element - fixture.querySelectorAll("option")[2].selected = true; + fixture.querySelectorAll("option")[2]!.selected = true; fixture.querySelector("select")!.dispatchEvent(new Event("change")); await nextTick(); @@ -840,7 +840,7 @@ describe("t-model.proxy directive", () => { '
Choice:
' ); - const firstInput = fixture.querySelectorAll("input")[0]; + const firstInput = fixture.querySelectorAll("input")[0]!; firstInput.click(); await nextTick(); expect(comp.state.choice).toBe("One"); diff --git a/packages/owl/tests/components/t_on.test.ts b/packages/owl/tests/components/t_on.test.ts index 9cea9a14e..6cabee17e 100644 --- a/packages/owl/tests/components/t_on.test.ts +++ b/packages/owl/tests/components/t_on.test.ts @@ -85,8 +85,8 @@ describe("t-on", () => { ); expect(comp.otherState.vals).toStrictEqual([]); const buttons = fixture.querySelectorAll("button"); - buttons[0].click(); - buttons[1].click(); + buttons[0]!.click(); + buttons[1]!.click(); expect(comp.otherState.vals).toStrictEqual(["a", "b"]); }); @@ -111,8 +111,8 @@ describe("t-on", () => { ); expect(comp.otherState.vals).toStrictEqual([]); const buttons = fixture.querySelectorAll("button"); - buttons[0].click(); - buttons[1].click(); + buttons[0]!.click(); + buttons[1]!.click(); expect(comp.otherState.vals).toStrictEqual(["a_nova_0_1", "b_nova_0_1"]); }); @@ -138,8 +138,8 @@ describe("t-on", () => { ); expect(comp.otherState.vals).toStrictEqual([]); const buttons = fixture.querySelectorAll("button"); - buttons[0].click(); - buttons[1].click(); + buttons[0]!.click(); + buttons[1]!.click(); expect(comp.otherState.vals).toStrictEqual(["a", "b"]); }); @@ -163,8 +163,8 @@ describe("t-on", () => { ); expect(comp.otherState.vals).toStrictEqual([]); const buttons = fixture.querySelectorAll("button"); - buttons[0].click(); - buttons[1].click(); + buttons[0]!.click(); + buttons[1]!.click(); expect(comp.otherState.vals).toStrictEqual(["2_2", "2_2"]); }); @@ -370,15 +370,15 @@ describe("t-on", () => { await mount(Parent, fixture); expect(fixture.innerHTML).toBe("
John
Raoul
Gérald
"); expect([]).toBeLogged(); - fixture.querySelectorAll("div")[0].click(); + fixture.querySelectorAll("div")[0]!.click(); await nextTick(); expect(["John"]).toBeLogged(); - fixture.querySelectorAll("div")[1].click(); + fixture.querySelectorAll("div")[1]!.click(); await nextTick(); expect(["Raoul"]).toBeLogged(); - fixture.querySelectorAll("div")[2].click(); + fixture.querySelectorAll("div")[2]!.click(); await nextTick(); expect(["Gérald"]).toBeLogged(); }); @@ -404,7 +404,7 @@ describe("t-on", () => { expect(fixture.innerHTML).toBe("
aaron
"); expect([]).toBeLogged(); - fixture.querySelectorAll("div")[0].click(); + fixture.querySelectorAll("div")[0]!.click(); await nextTick(); expect(["aaron"]).toBeLogged(); @@ -412,7 +412,7 @@ describe("t-on", () => { await nextTick(); expect(fixture.innerHTML).toBe("
lucas
"); - fixture.querySelectorAll("div")[0].click(); + fixture.querySelectorAll("div")[0]!.click(); await nextTick(); expect(["lucas"]).toBeLogged(); }); diff --git a/packages/owl/tests/helpers.ts b/packages/owl/tests/helpers.ts index 95e020164..73d8d4fb4 100644 --- a/packages/owl/tests/helpers.ts +++ b/packages/owl/tests/helpers.ts @@ -211,7 +211,7 @@ export function useLogLifecycle( export function children(w: Component): Component[] { const childrenMap = w.__owl__.children; - return Object.keys(childrenMap).map((id) => childrenMap[id].component); + return Object.keys(childrenMap).map((id) => childrenMap[id]!.component); } export function isDirectChildOf(child: Component, parent: Component): boolean { diff --git a/packages/owl/tests/reactivity/signals.test.ts b/packages/owl/tests/reactivity/signals.test.ts index 023a6ddd3..032dc2fd8 100644 --- a/packages/owl/tests/reactivity/signals.test.ts +++ b/packages/owl/tests/reactivity/signals.test.ts @@ -85,11 +85,11 @@ describe("signal.Array", () => { const reactiveArray = signal.Array<{ value: number }>([obj]); expect(reactiveArray()[0]).toBe(obj); - const e = spyEffect(() => reactiveArray()[0].value); + const e = spyEffect(() => reactiveArray()[0]!.value); e(); expectSpy(e.spy, 1); - reactiveArray()[0].value = 1; + reactiveArray()[0]!.value = 1; expectSpy(e.spy, 1, { result: 0 }); expect(reactiveArray()[0]).toBe(obj); diff --git a/tsconfig.base.json b/tsconfig.base.json index d7e63939d..2b1fd695d 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -6,7 +6,7 @@ "compilerOptions": { // Main options "target": "ES2022", - "module": "es6", + "module": "es2022", "lib": ["ES2022", "DOM", "DOM.Iterable"], // Strict typechecking options "strict": true, @@ -16,8 +16,9 @@ "noUnusedParameters": false, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, // Module resolution options - "moduleResolution": "node", + "moduleResolution": "bundler", "types": [ "node" ],