Skip to content

Commit

Permalink
feat: support typescript@5
Browse files Browse the repository at this point in the history
  • Loading branch information
plantain-00 committed Mar 16, 2023
1 parent d992817 commit c8acac7
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 77 deletions.
3 changes: 0 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@
+ [ ] Contains Only One Commit(`git reset` then `git commit`)
+ [ ] Build Success(`npm run build`)
+ [ ] Lint Success(`npm run lint` to check, `npm run fix` to fix)
+ [ ] File Integrity(`git add -A` or add rules at `.gitignore` file)
+ [ ] Add Test(if relevant, `npm run test` to check)
+ [ ] Add Demo(if relevant)
1 change: 0 additions & 1 deletion clean-scripts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default {
],
lint: {
ts: `eslint --ext .js,.ts ${tsFiles}`,
export: `no-unused-export ${tsFiles} --need-module tslib --need-module ts-plugin-type-coverage --ignore-module vscode --strict`,
markdown: `markdownlint README.md`
},
test: [],
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
"eslint-config-prettier": "8.6.0",
"eslint-plugin-plantain": "2.0.0",
"markdownlint-cli": "0.33.0",
"no-unused-export": "1.15.0",
"rimraf": "4.1.2",
"ts-node": "10.9.1",
"tsconfig-plantain": "0.0.2",
"typescript": "4.9.5",
"typescript": "5.0.2",
"vscode": "1.1.37"
},
"scripts": {
Expand All @@ -36,6 +35,6 @@
],
"private": true,
"typeCoverage": {
"atLeast": 96.92
"atLeast": 99.5
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async function executeCommandLine() {
});

const percent = Math.floor(10000 * correctCount / totalCount) / 100
const atLeastFailed = atLeast && percent < atLeast
const atLeastFailed = typeof atLeast === 'number' && percent < atLeast
const isFailed = is && percent !== is

if (detail || (!noDetailWhenFailed && (atLeastFailed || isFailed))) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"registry": "https://registry.npmjs.org/"
},
"peerDependencies": {
"typescript": "2 || 3 || 4"
"typescript": "2 || 3 || 4 || 5"
}
}
14 changes: 7 additions & 7 deletions packages/core/src/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function typeIsAnyOrInTypeArguments(type: ts.Type, anyCanBeInTypeArguments: bool

// See https://github.com/plantain-00/type-coverage/issues/28
function isEvolvingAssignment(node: ts.Node) {
const {parent} = node;
const { parent } = node;
if (ts.isVariableDeclaration(parent)) {
// Match "let foo" and "let foo = null" but not "let foo: any".
return !parent.type;
Expand All @@ -114,7 +114,7 @@ function checkNodes(nodes: ts.NodeArray<ts.Node> | undefined, context: FileConte
}
}

const isTypeAssertionExpression = ts.isTypeAssertionExpression || ts.isTypeAssertion
const isTypeAssertionExpression = ts.isTypeAssertionExpression || (ts as { isTypeAssertion?: typeof ts.isTypeAssertionExpression }).isTypeAssertion

function checkTypeAssertion(node: ts.Node, context: FileContext, kind: FileAnyInfoKind) {
if (context.strict) {
Expand Down Expand Up @@ -164,8 +164,8 @@ export function checkNode(node: ts.Node | undefined, context: FileContext): void
console.log(`node: ${context.file}:${line + 1}:${character + 1}: ${node.getText(context.sourceFile)} ${node.kind}(kind)`)
}

checkNodes(node.decorators, context)
checkNodes(node.modifiers, context)
checkNodes((node as { decorators?: ts.NodeArray<ts.Node> }).decorators, context)
checkNodes((node as { modifiers?: ts.NodeArray<ts.Node> }).modifiers, context)

if (skippedNodeKinds.has(node.kind)) {
return
Expand Down Expand Up @@ -215,7 +215,7 @@ export function checkNode(node: ts.Node | undefined, context: FileContext): void
checkNode(node.name, context)
checkNode(node.questionToken, context)
checkNode(node.type, context)
checkNode(node.initializer, context)
checkNode((node as { initializer?: ts.Node }).initializer, context)
return
}
if (ts.isMethodSignature(node)
Expand Down Expand Up @@ -625,13 +625,13 @@ export function checkNode(node: ts.Node | undefined, context: FileContext): void
}
if (ts.isPropertyAssignment(node)) {
checkNode(node.name, context)
checkNode(node.questionToken, context)
checkNode((node as { questionToken?: ts.Node }).questionToken, context)
checkNode(node.initializer, context)
return
}
if (ts.isShorthandPropertyAssignment(node)) {
checkNode(node.name, context)
checkNode(node.questionToken, context)
checkNode((node as { questionToken?: ts.Node }).questionToken, context)
checkNode(node.equalsToken, context)
checkNode(node.objectAssignmentInitializer, context)
return
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"registry": "https://registry.npmjs.org/"
},
"peerDependencies": {
"typescript": "2 || 3 || 4"
"typescript": "2 || 3 || 4 || 5"
}
}
4 changes: 2 additions & 2 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ interface Option {
}

function init(modules: { typescript: typeof tsserverlibrary }) {
let oldProgram: ts.Program | undefined
let oldProgram: tsserverlibrary.Program | undefined
let options: Option | undefined

function create(info: ts.server.PluginCreateInfo) {
function create(info: tsserverlibrary.server.PluginCreateInfo) {
const proxy: tsserverlibrary.LanguageService = {
...info.languageService,
getSemanticDiagnostics(fileName) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ts-plugin-type-coverage": "^2.18.2"
},
"devDependencies": {
"typescript": "4.9.5"
"typescript": "5.0.2"
},
"keywords": [
"type",
Expand Down
61 changes: 4 additions & 57 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1273,11 +1273,6 @@ mute-stream@0.0.8:
resolved "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==

nanoid@^3.3.4:
version "3.3.4"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab"
integrity sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==

natural-compare-lite@^1.4.0:
version "1.4.0"
resolved "https://registry.npmjs.org/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4"
Expand All @@ -1293,20 +1288,6 @@ nested-error-stacks@^2.0.0:
resolved "https://registry.npmjs.org/nested-error-stacks/-/nested-error-stacks-2.1.1.tgz#26c8a3cee6cc05fbcf1e333cd2fc3e003326c0b5"
integrity sha512-9iN1ka/9zmX1ZvLV9ewJYEk9h7RyRRtqdK0woXcqohu8EWIerfPUjYJPg0ULy0UqP7cslmdGc8xKDJcojlKiaw==

no-unused-export@1.15.0:
version "1.15.0"
resolved "https://registry.npmjs.org/no-unused-export/-/no-unused-export-1.15.0.tgz#85e119f1fe07af05353769742923f25ea4d0f9f6"
integrity sha512-6nALEKlwmVXLQphKij0i4pIz+U1ynDaOzJ7FwXfx/KlYPTcrZrBaYWzNn5prfr+P+RaV+dfgwz8DqjqEm7NZKA==
dependencies:
glob "7"
minimist "1"
parse5 "6"
postcss "8"
postcss-less "3 || 4 || 5 || 6"
postcss-scss "2 || 3 || 4"
tslib "1 || 2"
typescript "3 || 4"

normalize-path@3:
version "3.0.0"
resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
Expand Down Expand Up @@ -1424,11 +1405,6 @@ parse-ms@^2.1.0:
resolved "https://registry.npmjs.org/parse-ms/-/parse-ms-2.1.0.tgz#348565a753d4391fa524029956b172cb7753097d"
integrity sha512-kHt7kzLoS9VBZfUsiKjv43mr91ea+U05EyKkEtqp7vNbHxmaVuEqN7XxeEVnGrMtYOAxGrDElSi96K7EgO1zCA==

parse5@6:
version "6.0.1"
resolved "https://registry.npmjs.org/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b"
integrity sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==

path-exists@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3"
Expand All @@ -1449,11 +1425,6 @@ path-type@^4.0.0:
resolved "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

picocolors@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==

picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
Expand All @@ -1466,25 +1437,6 @@ picomatch@^2.3.1:
dependencies:
safe-buffer "^5.2.1"

"postcss-less@3 || 4 || 5 || 6":
version "6.0.0"
resolved "https://registry.npmjs.org/postcss-less/-/postcss-less-6.0.0.tgz#463b34c60f53b648c237f569aeb2e09149d85af4"
integrity sha512-FPX16mQLyEjLzEuuJtxA8X3ejDLNGGEG503d2YGZR5Ask1SpDN8KmZUMpzCvyalWRywAn1n1VOA5dcqfCLo5rg==

"postcss-scss@2 || 3 || 4":
version "4.0.6"
resolved "https://registry.npmjs.org/postcss-scss/-/postcss-scss-4.0.6.tgz#5d62a574b950a6ae12f2aa89b60d63d9e4432bfd"
integrity sha512-rLDPhJY4z/i4nVFZ27j9GqLxj1pwxE80eAzUNRMXtcpipFYIeowerzBgG3yJhMtObGEXidtIgbUpQ3eLDsf5OQ==

postcss@8:
version "8.4.21"
resolved "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz#c639b719a57efc3187b13a1d765675485f4134f4"
integrity sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==
dependencies:
nanoid "^3.3.4"
picocolors "^1.0.0"
source-map-js "^1.0.2"

prelude-ls@^1.2.1:
version "1.2.1"
resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
Expand Down Expand Up @@ -1648,11 +1600,6 @@ slice-ansi@^4.0.0:
astral-regex "^2.0.0"
is-fullwidth-code-point "^3.0.0"

source-map-js@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==

source-map-support@^0.5.0:
version "0.5.21"
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
Expand Down Expand Up @@ -1808,10 +1755,10 @@ type-fest@^0.21.3:
resolved "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37"
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==

"typescript@3 || 4", typescript@4.9.5:
version "4.9.5"
resolved "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==
typescript@5.0.2:
version "5.0.2"
resolved "https://registry.npmjs.org/typescript/-/typescript-5.0.2.tgz#891e1a90c5189d8506af64b9ef929fca99ba1ee5"
integrity sha512-wVORMBGO/FAs/++blGNeAVdbNKtIh1rbBL2EyQ1+J9lClJ93KiiKe8PmFIVdXhHcyv44SL9oglmfeSsndo0jRw==

uc.micro@^1.0.1, uc.micro@^1.0.5:
version "1.0.6"
Expand Down

0 comments on commit c8acac7

Please sign in to comment.