From d0073ae32712e901ac8d135094913e2060104d2f Mon Sep 17 00:00:00 2001 From: so1ve Date: Tue, 17 Oct 2023 14:30:23 +0800 Subject: [PATCH 01/12] init tests --- packages/vue-test-workspace/package.json | 1 + .../non-strict-template/tsconfig.json | 4 +++ .../vue-test-workspace/vue-tsc-2.7/shared.ts | 10 ++++++ .../vue-tsc-2.7/strict-template/tsconfig.json | 7 ++++ .../vue-tsc-2.7/tsconfig.base.json | 13 ++++++++ packages/vue-tsc/tests/index.spec.ts | 33 ++++++++++--------- 6 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 packages/vue-test-workspace/vue-tsc-2.7/non-strict-template/tsconfig.json create mode 100644 packages/vue-test-workspace/vue-tsc-2.7/shared.ts create mode 100644 packages/vue-test-workspace/vue-tsc-2.7/strict-template/tsconfig.json create mode 100644 packages/vue-test-workspace/vue-tsc-2.7/tsconfig.base.json diff --git a/packages/vue-test-workspace/package.json b/packages/vue-test-workspace/package.json index 50319e2457..f0132abd6d 100644 --- a/packages/vue-test-workspace/package.json +++ b/packages/vue-test-workspace/package.json @@ -5,6 +5,7 @@ "license": "MIT", "devDependencies": { "vue": "^3.3.0", + "vue2.7": "npm:vue@^2.7.0", "vue-component-type-helpers": "1.8.19" } } diff --git a/packages/vue-test-workspace/vue-tsc-2.7/non-strict-template/tsconfig.json b/packages/vue-test-workspace/vue-tsc-2.7/non-strict-template/tsconfig.json new file mode 100644 index 0000000000..8411f7729a --- /dev/null +++ b/packages/vue-test-workspace/vue-tsc-2.7/non-strict-template/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../tsconfig.base.json", + "include": ["**/*"] +} diff --git a/packages/vue-test-workspace/vue-tsc-2.7/shared.ts b/packages/vue-test-workspace/vue-tsc-2.7/shared.ts new file mode 100644 index 0000000000..26abe5a11b --- /dev/null +++ b/packages/vue-test-workspace/vue-tsc-2.7/shared.ts @@ -0,0 +1,10 @@ +// https://stackoverflow.com/a/53808212 +type IfEquals = + (() => G extends T ? 1 : 2) extends + (() => G extends U ? 1 : 2) ? Y : N; +export declare function exactType(draft: T & IfEquals, expected: U & IfEquals): IfEquals; + +// https://stackoverflow.com/a/49928360 +type IfNotAny = 0 extends 1 & T ? never : T; +type IfNotUndefined = Exclude extends never ? never : T; +export declare function isNotAnyOrUndefined(value: IfNotAny>): void; diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/tsconfig.json b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/tsconfig.json new file mode 100644 index 0000000000..715269aba2 --- /dev/null +++ b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../tsconfig.base.json", + "vueCompilerOptions": { + "strictTemplates": true + }, + "include": ["**/*"] +} diff --git a/packages/vue-test-workspace/vue-tsc-2.7/tsconfig.base.json b/packages/vue-test-workspace/vue-tsc-2.7/tsconfig.base.json new file mode 100644 index 0000000000..43e1368f62 --- /dev/null +++ b/packages/vue-test-workspace/vue-tsc-2.7/tsconfig.base.json @@ -0,0 +1,13 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "noPropertyAccessFromIndexSignature": true, + }, + "vueCompilerOptions": { + "target": 2.7, + "lib": "vue2.7", + "jsxSlots": true, + "plugins": ["../../vue-language-plugin-pug"] + }, + "include": [] +} \ No newline at end of file diff --git a/packages/vue-tsc/tests/index.spec.ts b/packages/vue-tsc/tests/index.spec.ts index aded5088c3..2d583ca538 100644 --- a/packages/vue-tsc/tests/index.spec.ts +++ b/packages/vue-tsc/tests/index.spec.ts @@ -5,39 +5,42 @@ import { fork } from 'child_process'; const binPath = require.resolve('../bin/vue-tsc.js'); const workspace = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc'); +const workspace27 = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc-2.7'); function prettyPath(path: string, isRoot: boolean) { const segments = path.split('/'); - return !isRoot ? segments.slice(segments.length - 2, segments.length).join('/') : segments[segments.length - 1]; + return !isRoot ? segments.slice(segments.length - 3, segments.length).join('/') : segments[segments.length - 1]; } -function collectTests(dir: string, depth = 2, isRoot: boolean = true): [string, boolean][] { +function collectTests(dirs: string[], depth = 2, isRoot: boolean = true): [string, boolean][] { const tests: [string, boolean][] = []; if (depth <= 0) { return tests; } - const files = fs.readdirSync(dir); - for (const file of files) { - const filePath = path.join(dir, file); - const stat = fs.statSync(filePath); - if (stat.isDirectory()) { - const tsconfigPath = path.join(filePath, 'tsconfig.json'); - if (fs.existsSync(tsconfigPath)) { - tests.push([ - filePath.replace(/\\/g, '/'), - isRoot, - ]); + for (const dir of dirs) { + const files = fs.readdirSync(dir); + for (const file of files) { + const filePath = path.join(dir, file); + const stat = fs.statSync(filePath); + if (stat.isDirectory()) { + const tsconfigPath = path.join(filePath, 'tsconfig.json'); + if (fs.existsSync(tsconfigPath)) { + tests.push([ + filePath.replace(/\\/g, '/'), + isRoot, + ]); + } + tests.push(...collectTests([filePath], depth - 1, false)); } - tests.push(...collectTests(filePath, depth - 1, false)); } } return tests; } -const tests = collectTests(workspace); +const tests = collectTests([workspace, workspace27]); function runVueTsc(cwd: string) { return new Promise((resolve, reject) => { From 6fc3e84ad705382647d0ebfb801e981d13f46e61 Mon Sep 17 00:00:00 2001 From: so1ve Date: Tue, 17 Oct 2023 14:39:37 +0800 Subject: [PATCH 02/12] update lock --- pnpm-lock.yaml | 86 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84e9cb8206..3014175cab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,14 +10,14 @@ importers: optionalDependencies: '@lerna-lite/cli': specifier: latest - version: 2.5.1(@lerna-lite/publish@2.5.1)(@lerna-lite/version@2.5.1)(typescript@5.2.2) + version: 2.6.0(@lerna-lite/publish@2.6.0)(@lerna-lite/version@2.6.0)(typescript@5.2.2) '@lerna-lite/publish': specifier: latest - version: 2.5.1(typescript@5.2.2) + version: 2.6.0(typescript@5.2.2) devDependencies: '@types/node': specifier: latest - version: 20.8.4 + version: 20.8.6 '@volar/language-service': specifier: ~1.10.4 version: 1.10.4 @@ -26,7 +26,7 @@ importers: version: 5.2.2 vite: specifier: latest - version: 4.4.11(@types/node@20.8.4) + version: 4.4.11(@types/node@20.8.6) vitest: specifier: latest version: 0.34.6 @@ -251,6 +251,9 @@ importers: vue-component-type-helpers: specifier: 1.8.19 version: link:../vue-component-type-helpers + vue2.7: + specifier: npm:vue@^2.7.0 + version: /vue@2.7.14 packages/vue-tsc: dependencies: @@ -606,8 +609,8 @@ packages: resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} dev: true - /@lerna-lite/cli@2.5.1(@lerna-lite/publish@2.5.1)(@lerna-lite/version@2.5.1)(typescript@5.2.2): - resolution: {integrity: sha512-6Bs/w4rB/SVbiwbHfahm2W9wfUcvKcA34VBkVE8UrYOmwxOqODNdBUOUiZj76OTl5n5yByBf6MHWZN2MREPECw==} + /@lerna-lite/cli@2.6.0(@lerna-lite/publish@2.6.0)(@lerna-lite/version@2.6.0)(typescript@5.2.2): + resolution: {integrity: sha512-sxJmgGt/zQ4rYfdl5OSp5/TToLB16RVxsoVsUsg/qTl5F5C+P35evYBuXRuFNWr50+MdfHqLisbf0qEJgGAk9g==} engines: {node: '>=16.15.0', npm: '>=8.5.0'} hasBin: true requiresBuild: true @@ -632,10 +635,10 @@ packages: '@lerna-lite/watch': optional: true dependencies: - '@lerna-lite/core': 2.5.1(typescript@5.2.2) - '@lerna-lite/init': 2.5.1(typescript@5.2.2) - '@lerna-lite/publish': 2.5.1(typescript@5.2.2) - '@lerna-lite/version': 2.5.1(@lerna-lite/publish@2.5.1)(typescript@5.2.2) + '@lerna-lite/core': 2.6.0(typescript@5.2.2) + '@lerna-lite/init': 2.6.0(typescript@5.2.2) + '@lerna-lite/publish': 2.6.0(typescript@5.2.2) + '@lerna-lite/version': 2.6.0(@lerna-lite/publish@2.6.0)(typescript@5.2.2) dedent: 1.5.1 dotenv: 16.3.1 import-local: 3.1.0 @@ -649,8 +652,8 @@ packages: dev: false optional: true - /@lerna-lite/core@2.5.1(typescript@5.2.2): - resolution: {integrity: sha512-Bqx5e7/QiK1NzX8qfQyW3WP63Cw5mByCS0ZvrMUioQFJKw7BgXytOmg1OrcB2A7+hYwkZOiz25GWIUzHMvxVAA==} + /@lerna-lite/core@2.6.0(typescript@5.2.2): + resolution: {integrity: sha512-WFyDgjuHHj5dC8WYA4w1hoMyUL8pnb7eFNMVYgPYzXi1L8yoQPpvJr02wOWl464XJbhhfr8Q8tMdMHI7YUSbMQ==} engines: {node: '>=16.15.0', npm: '>=8.5.0'} requiresBuild: true dependencies: @@ -687,12 +690,12 @@ packages: dev: false optional: true - /@lerna-lite/init@2.5.1(typescript@5.2.2): - resolution: {integrity: sha512-6deyLNCt2w3xS4oAho/B24LXeUBH6h3PE+D0BmX/vxvfq1UXDTXyBs+Ch2/H+oi6CMlWIQvYP/+oH7VZ9daVyQ==} + /@lerna-lite/init@2.6.0(typescript@5.2.2): + resolution: {integrity: sha512-K8lxcQXgGrTfl3YyvKSl+uiAT287vd1awouvme7m+3j32H6DTI31u35t7mR6mBY7GhkDLX/iJzjaHpv2qBb3NQ==} engines: {node: '>=16.15.0', npm: '>=8.5.0'} requiresBuild: true dependencies: - '@lerna-lite/core': 2.5.1(typescript@5.2.2) + '@lerna-lite/core': 2.6.0(typescript@5.2.2) fs-extra: 11.1.1 p-map: 6.0.0 write-json-file: 5.0.0 @@ -703,14 +706,14 @@ packages: dev: false optional: true - /@lerna-lite/publish@2.5.1(typescript@5.2.2): - resolution: {integrity: sha512-bxvaaFUcQ1wiOLc1xWtekmsyobd7kqUoehzZ8HIStDIASMo+DZGVNyM+OZirI1F3Fz3PM/JbyRz+yo7Qp6kEVA==} + /@lerna-lite/publish@2.6.0(typescript@5.2.2): + resolution: {integrity: sha512-Xa7MT1nZ8Q6vY0vwLMZgdoX8Lz2PHZ6tEMWx54qgWiK0HYOfZjW+NNXGV9hKu6PpaRBq+N5PIKOptJSjQCjEew==} engines: {node: '>=16.15.0', npm: '>=8.5.0'} requiresBuild: true dependencies: - '@lerna-lite/cli': 2.5.1(@lerna-lite/publish@2.5.1)(@lerna-lite/version@2.5.1)(typescript@5.2.2) - '@lerna-lite/core': 2.5.1(typescript@5.2.2) - '@lerna-lite/version': 2.5.1(@lerna-lite/publish@2.5.1)(typescript@5.2.2) + '@lerna-lite/cli': 2.6.0(@lerna-lite/publish@2.6.0)(@lerna-lite/version@2.6.0)(typescript@5.2.2) + '@lerna-lite/core': 2.6.0(typescript@5.2.2) + '@lerna-lite/version': 2.6.0(@lerna-lite/publish@2.6.0)(typescript@5.2.2) '@npmcli/arborist': 7.2.0 byte-size: 8.1.1 chalk: 5.3.0 @@ -747,13 +750,13 @@ packages: dev: false optional: true - /@lerna-lite/version@2.5.1(@lerna-lite/publish@2.5.1)(typescript@5.2.2): - resolution: {integrity: sha512-d7b2ZiCwTGbxE5LPkt43kRNSCBCgAEMYKVGMhpabm6YXOs9J5Si7gmcSQ9eTYctUjwY+QBUimRr/KFT4PvBfEw==} + /@lerna-lite/version@2.6.0(@lerna-lite/publish@2.6.0)(typescript@5.2.2): + resolution: {integrity: sha512-OEdSV6SwYqspXls2Nthd6itw7XJaWGAr65rDVrgcQajQ0dAngateYtsq/zmRMaJnSYNX6u5gUV5y+6WISQaGMA==} engines: {node: '>=16.15.0', npm: '>=8.5.0'} requiresBuild: true dependencies: - '@lerna-lite/cli': 2.5.1(@lerna-lite/publish@2.5.1)(@lerna-lite/version@2.5.1)(typescript@5.2.2) - '@lerna-lite/core': 2.5.1(typescript@5.2.2) + '@lerna-lite/cli': 2.6.0(@lerna-lite/publish@2.6.0)(@lerna-lite/version@2.6.0)(typescript@5.2.2) + '@lerna-lite/core': 2.6.0(typescript@5.2.2) '@octokit/plugin-enterprise-rest': 6.0.1 '@octokit/rest': 19.0.13 chalk: 5.3.0 @@ -1280,8 +1283,8 @@ packages: dev: false optional: true - /@types/node@20.8.4: - resolution: {integrity: sha512-ZVPnqU58giiCjSxjVUESDtdPk4QR5WQhhINbc9UBrKLU68MX5BF6kbQzTrkwbolyr0X8ChBpXfavr5mZFKZQ5A==} + /@types/node@20.8.6: + resolution: {integrity: sha512-eWO4K2Ji70QzKUqRy6oyJWUeB7+g2cRagT3T/nxYibYcT4y2BDL8lqolRXjTHmkZCdJfIPaY73KbJAZmcryxTQ==} dependencies: undici-types: 5.25.3 dev: true @@ -1429,6 +1432,14 @@ packages: '@vue/compiler-core': 3.3.4 '@vue/shared': 3.3.4 + /@vue/compiler-sfc@2.7.14: + resolution: {integrity: sha512-aNmNHyLPsw+sVvlQFQ2/8sjNuLtK54TC6cuKnVzAY93ks4ZBrvwQSnkkIh7bsbNhum5hJBS00wSDipQ937f5DA==} + dependencies: + '@babel/parser': 7.23.0 + postcss: 8.4.31 + source-map: 0.6.1 + dev: true + /@vue/compiler-sfc@3.3.4: resolution: {integrity: sha512-6y/d8uw+5TkCuzBkgLS0v3lSM3hJDntFEiUORM11pQ/hKvkhSKZrXW6i69UyXlJQisJxuUEJKAWEqWbWsLeNKQ==} dependencies: @@ -5589,8 +5600,6 @@ packages: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} requiresBuild: true - dev: false - optional: true /spdx-correct@3.2.0: resolution: {integrity: sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==} @@ -6114,7 +6123,7 @@ packages: dev: false optional: true - /vite-node@0.34.6(@types/node@20.8.4): + /vite-node@0.34.6(@types/node@20.8.6): resolution: {integrity: sha512-nlBMJ9x6n7/Amaz6F3zJ97EBwR2FkzhBRxF5e+jE6LA3yi6Wtc2lyTij1OnDMIr34v5g/tVQtsVAzhT0jc5ygA==} engines: {node: '>=v14.18.0'} hasBin: true @@ -6124,7 +6133,7 @@ packages: mlly: 1.4.2 pathe: 1.1.1 picocolors: 1.0.0 - vite: 4.4.11(@types/node@20.8.4) + vite: 4.4.11(@types/node@20.8.6) transitivePeerDependencies: - '@types/node' - less @@ -6136,7 +6145,7 @@ packages: - terser dev: true - /vite@4.4.11(@types/node@20.8.4): + /vite@4.4.11(@types/node@20.8.6): resolution: {integrity: sha512-ksNZJlkcU9b0lBwAGZGGaZHCMqHsc8OpgtoYhsQ4/I2v5cnpmmmqe5pM4nv/4Hn6G/2GhTdj0DhZh2e+Er1q5A==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -6164,7 +6173,7 @@ packages: terser: optional: true dependencies: - '@types/node': 20.8.4 + '@types/node': 20.8.6 esbuild: 0.18.20 postcss: 8.4.31 rollup: 3.29.4 @@ -6205,7 +6214,7 @@ packages: dependencies: '@types/chai': 4.3.7 '@types/chai-subset': 1.3.3 - '@types/node': 20.8.4 + '@types/node': 20.8.6 '@vitest/expect': 0.34.6 '@vitest/runner': 0.34.6 '@vitest/snapshot': 0.34.6 @@ -6224,8 +6233,8 @@ packages: strip-literal: 1.3.0 tinybench: 2.5.1 tinypool: 0.7.0 - vite: 4.4.11(@types/node@20.8.4) - vite-node: 0.34.6(@types/node@20.8.4) + vite: 4.4.11(@types/node@20.8.6) + vite-node: 0.34.6(@types/node@20.8.6) why-is-node-running: 2.2.2 transitivePeerDependencies: - less @@ -6447,6 +6456,13 @@ packages: he: 1.2.0 dev: false + /vue@2.7.14: + resolution: {integrity: sha512-b2qkFyOM0kwqWFuQmgd4o+uHGU7T+2z3T+WQp8UBjADfEv2n4FEMffzBmCKNP0IGzOEEfYjvtcC62xaSKeQDrQ==} + dependencies: + '@vue/compiler-sfc': 2.7.14 + csstype: 3.1.2 + dev: true + /vue@3.3.4: resolution: {integrity: sha512-VTyEYn3yvIeY1Py0WaYGZsXnz3y5UnGi62GjVEqvEGPl6nxbOrCXbVOTQWBEJUqAyTUk2uJ5JLVnYJ6ZzGbrSw==} dependencies: From f0396f5cf0c517b9ed4ca5bf1fb94322ec51d8fd Mon Sep 17 00:00:00 2001 From: so1ve Date: Tue, 17 Oct 2023 14:39:41 +0800 Subject: [PATCH 03/12] add tests --- .../vue-tsc-2.7/strict-template/#3673/Comp.vue | 8 ++++++++ .../vue-tsc-2.7/strict-template/#3673/main.vue | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue create mode 100644 packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue new file mode 100644 index 0000000000..dd21148914 --- /dev/null +++ b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue @@ -0,0 +1,8 @@ + diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue new file mode 100644 index 0000000000..0a19ac4050 --- /dev/null +++ b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue @@ -0,0 +1,7 @@ + + + \ No newline at end of file From 68294dc8964f5f066a296e904c5bc35c023413f5 Mon Sep 17 00:00:00 2001 From: so1ve Date: Tue, 17 Oct 2023 14:45:21 +0800 Subject: [PATCH 04/12] update --- packages/vue-test-workspace/package.json | 2 +- .../strict-template/unknownProp/main.vue | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 packages/vue-test-workspace/vue-tsc-2.7/strict-template/unknownProp/main.vue diff --git a/packages/vue-test-workspace/package.json b/packages/vue-test-workspace/package.json index f0132abd6d..60cfb7c767 100644 --- a/packages/vue-test-workspace/package.json +++ b/packages/vue-test-workspace/package.json @@ -5,7 +5,7 @@ "license": "MIT", "devDependencies": { "vue": "^3.3.0", - "vue2.7": "npm:vue@^2.7.0", + "vue2.7": "npm:vue@^2.7.14", "vue-component-type-helpers": "1.8.19" } } diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/unknownProp/main.vue b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/unknownProp/main.vue new file mode 100644 index 0000000000..8e4a04fd0c --- /dev/null +++ b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/unknownProp/main.vue @@ -0,0 +1,18 @@ + + + \ No newline at end of file From 1d26a5fe12fb38e3f5712706f33e11940f885784 Mon Sep 17 00:00:00 2001 From: so1ve Date: Tue, 17 Oct 2023 16:01:09 +0800 Subject: [PATCH 05/12] update --- packages/vue-test-workspace/vue-tsc-2.7/shared.ts | 10 ---------- .../vue-tsc-2.7/strict-template/#3673/Comp.vue | 2 +- .../vue-tsc-2.7/strict-template/#3673/main.vue | 3 ++- 3 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 packages/vue-test-workspace/vue-tsc-2.7/shared.ts diff --git a/packages/vue-test-workspace/vue-tsc-2.7/shared.ts b/packages/vue-test-workspace/vue-tsc-2.7/shared.ts deleted file mode 100644 index 26abe5a11b..0000000000 --- a/packages/vue-test-workspace/vue-tsc-2.7/shared.ts +++ /dev/null @@ -1,10 +0,0 @@ -// https://stackoverflow.com/a/53808212 -type IfEquals = - (() => G extends T ? 1 : 2) extends - (() => G extends U ? 1 : 2) ? Y : N; -export declare function exactType(draft: T & IfEquals, expected: U & IfEquals): IfEquals; - -// https://stackoverflow.com/a/49928360 -type IfNotAny = 0 extends 1 & T ? never : T; -type IfNotUndefined = Exclude extends never ? never : T; -export declare function isNotAnyOrUndefined(value: IfNotAny>): void; diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue index dd21148914..a42d737857 100644 --- a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue +++ b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue @@ -3,6 +3,6 @@ defineProps<{ border?: boolean; }>(); defineEmits<{ - (event: 'click'): void; + (event: 'click', s: string): void; }>(); diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue index 0a19ac4050..b488e2b6b7 100644 --- a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue +++ b/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue @@ -1,7 +1,8 @@ \ No newline at end of file From 9ab181769fb82b7e88bcd121d47233bd980e3e95 Mon Sep 17 00:00:00 2001 From: so1ve Date: Tue, 17 Oct 2023 16:48:23 +0800 Subject: [PATCH 06/12] fix: convert emits to props --- .../src/generators/script.ts | 19 ++++++++++++++ packages/vue-test-workspace/package.json | 1 - packages/vue-tsc/tests/index.spec.ts | 10 +++++--- packages/vue2-test-workspace/LICENSE | 21 ++++++++++++++++ packages/vue2-test-workspace/package.json | 10 ++++++++ packages/vue2-test-workspace/tsconfig.json | 25 +++++++++++++++++++ .../non-strict-template/tsconfig.json | 0 .../vue2-test-workspace/vue-tsc/shared.ts | 10 ++++++++ .../vue-tsc}/strict-template/#3673/Comp.vue | 0 .../vue-tsc}/strict-template/#3673/main.vue | 0 .../vue-tsc}/strict-template/tsconfig.json | 0 .../strict-template/unknownProp/main.vue | 2 +- .../vue-tsc}/tsconfig.base.json | 5 ++-- pnpm-lock.yaml | 12 ++++++--- 14 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 packages/vue2-test-workspace/LICENSE create mode 100644 packages/vue2-test-workspace/package.json create mode 100644 packages/vue2-test-workspace/tsconfig.json rename packages/{vue-test-workspace/vue-tsc-2.7 => vue2-test-workspace/vue-tsc}/non-strict-template/tsconfig.json (100%) create mode 100644 packages/vue2-test-workspace/vue-tsc/shared.ts rename packages/{vue-test-workspace/vue-tsc-2.7 => vue2-test-workspace/vue-tsc}/strict-template/#3673/Comp.vue (100%) rename packages/{vue-test-workspace/vue-tsc-2.7 => vue2-test-workspace/vue-tsc}/strict-template/#3673/main.vue (100%) rename packages/{vue-test-workspace/vue-tsc-2.7 => vue2-test-workspace/vue-tsc}/strict-template/tsconfig.json (100%) rename packages/{vue-test-workspace/vue-tsc-2.7 => vue2-test-workspace/vue-tsc}/strict-template/unknownProp/main.vue (85%) rename packages/{vue-test-workspace/vue-tsc-2.7 => vue2-test-workspace/vue-tsc}/tsconfig.base.json (68%) diff --git a/packages/vue-language-core/src/generators/script.ts b/packages/vue-language-core/src/generators/script.ts index 8931666731..4d594b1087 100644 --- a/packages/vue-language-core/src/generators/script.ts +++ b/packages/vue-language-core/src/generators/script.ts @@ -69,7 +69,12 @@ export function generate( MergePropDefaults: false, WithTemplateSlots: false, PropsChildren: false, + EmitsToProps: false, }; + const isVue27 = vueCompilerOptions.target < 3 && vueCompilerOptions.target >= 2.7; + + if (isVue27) + usedHelperTypes.EmitsToProps = true; codes.push(`/* __placeholder__ */\n`); @@ -136,6 +141,17 @@ export function generate( if (usedHelperTypes.PropsChildren) { codes.push(`type __VLS_PropsChildren = { [K in keyof (boolean extends (JSX.ElementChildrenAttribute extends never ? true : false) ? never : JSX.ElementChildrenAttribute)]?: S; };\n`); } + if (usedHelperTypes.EmitsToProps) { + codes.push( + `type __VLS_ObjectEmitsOptions = Record any) | null>; + type __VLS_EmitsOptions = __VLS_ObjectEmitsOptions | string[]; + type __VLS_EmitsToProps = T extends string[] ? { + [K in string & \`on\${Capitalize}\`]?: (...args: any[]) => any; + } : T extends __VLS_ObjectEmitsOptions ? { + [K in string & \`on\${Capitalize}\`]?: K extends \`on\${infer C}\` ? T[Uncapitalize] extends null ? (...args: any[]) => any : (...args: T[Uncapitalize] extends (...args: infer P) => any ? P : never) => any : never; + } : {};`, + ); + } } function generateSrc() { if (!sfc.script?.src) @@ -647,6 +663,9 @@ declare function defineProp(value?: T | (() => T), required?: boolean, rest?: else { addExtraReferenceVirtualCode('scriptSetup', typeArg.start, typeArg.end); } + if (isVue27 && ranges.emits.define) { + codes.push(`& __VLS_EmitsToProps<__VLS_NormalizeEmits>`); + } codes.push(`>`); if (ranges.props.withDefaults?.arg) { diff --git a/packages/vue-test-workspace/package.json b/packages/vue-test-workspace/package.json index 60cfb7c767..50319e2457 100644 --- a/packages/vue-test-workspace/package.json +++ b/packages/vue-test-workspace/package.json @@ -5,7 +5,6 @@ "license": "MIT", "devDependencies": { "vue": "^3.3.0", - "vue2.7": "npm:vue@^2.7.14", "vue-component-type-helpers": "1.8.19" } } diff --git a/packages/vue-tsc/tests/index.spec.ts b/packages/vue-tsc/tests/index.spec.ts index 2d583ca538..c2ec94c4a8 100644 --- a/packages/vue-tsc/tests/index.spec.ts +++ b/packages/vue-tsc/tests/index.spec.ts @@ -5,11 +5,15 @@ import { fork } from 'child_process'; const binPath = require.resolve('../bin/vue-tsc.js'); const workspace = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc'); -const workspace27 = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc-2.7'); +const workspace2 = path.resolve(__dirname, '../../vue2-test-workspace/vue-tsc'); function prettyPath(path: string, isRoot: boolean) { const segments = path.split('/'); - return !isRoot ? segments.slice(segments.length - 3, segments.length).join('/') : segments[segments.length - 1]; + const slicePath = (seg: number) => segments + .slice(segments.length - seg, segments.length) + .join('/') + .replace('/vue-tsc', ''); + return !isRoot ? slicePath(4) : slicePath(3); } function collectTests(dirs: string[], depth = 2, isRoot: boolean = true): [string, boolean][] { @@ -40,7 +44,7 @@ function collectTests(dirs: string[], depth = 2, isRoot: boolean = true): [strin return tests; } -const tests = collectTests([workspace, workspace27]); +const tests = collectTests([workspace, workspace2]); function runVueTsc(cwd: string) { return new Promise((resolve, reject) => { diff --git a/packages/vue2-test-workspace/LICENSE b/packages/vue2-test-workspace/LICENSE new file mode 100644 index 0000000000..b55e47a7e8 --- /dev/null +++ b/packages/vue2-test-workspace/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021-present Johnson Chu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/vue2-test-workspace/package.json b/packages/vue2-test-workspace/package.json new file mode 100644 index 0000000000..ffb87954f9 --- /dev/null +++ b/packages/vue2-test-workspace/package.json @@ -0,0 +1,10 @@ +{ + "private": true, + "name": "@volar/vue-test-workspace", + "version": "1.8.19", + "license": "MIT", + "devDependencies": { + "vue": "^2.7.14", + "vue-component-type-helpers": "1.8.19" + } +} diff --git a/packages/vue2-test-workspace/tsconfig.json b/packages/vue2-test-workspace/tsconfig.json new file mode 100644 index 0000000000..46e1e7b737 --- /dev/null +++ b/packages/vue2-test-workspace/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "lib": [ + "esnext", + "dom" + ], + "strict": true, + "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "skipLibCheck": true, + "allowJs": true, + "jsx": "preserve", + "baseUrl": ".", + "paths": { + "__COMPLETE_ROOT__/*": [ + "./complete/*" + ], + "__FIND_DEFINITION_ROOT__/*": [ + "./find-definition/*" + ] + }, + }, + "include": [ "**/*" ], +} \ No newline at end of file diff --git a/packages/vue-test-workspace/vue-tsc-2.7/non-strict-template/tsconfig.json b/packages/vue2-test-workspace/vue-tsc/non-strict-template/tsconfig.json similarity index 100% rename from packages/vue-test-workspace/vue-tsc-2.7/non-strict-template/tsconfig.json rename to packages/vue2-test-workspace/vue-tsc/non-strict-template/tsconfig.json diff --git a/packages/vue2-test-workspace/vue-tsc/shared.ts b/packages/vue2-test-workspace/vue-tsc/shared.ts new file mode 100644 index 0000000000..26abe5a11b --- /dev/null +++ b/packages/vue2-test-workspace/vue-tsc/shared.ts @@ -0,0 +1,10 @@ +// https://stackoverflow.com/a/53808212 +type IfEquals = + (() => G extends T ? 1 : 2) extends + (() => G extends U ? 1 : 2) ? Y : N; +export declare function exactType(draft: T & IfEquals, expected: U & IfEquals): IfEquals; + +// https://stackoverflow.com/a/49928360 +type IfNotAny = 0 extends 1 & T ? never : T; +type IfNotUndefined = Exclude extends never ? never : T; +export declare function isNotAnyOrUndefined(value: IfNotAny>): void; diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue b/packages/vue2-test-workspace/vue-tsc/strict-template/#3673/Comp.vue similarity index 100% rename from packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/Comp.vue rename to packages/vue2-test-workspace/vue-tsc/strict-template/#3673/Comp.vue diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue b/packages/vue2-test-workspace/vue-tsc/strict-template/#3673/main.vue similarity index 100% rename from packages/vue-test-workspace/vue-tsc-2.7/strict-template/#3673/main.vue rename to packages/vue2-test-workspace/vue-tsc/strict-template/#3673/main.vue diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/tsconfig.json b/packages/vue2-test-workspace/vue-tsc/strict-template/tsconfig.json similarity index 100% rename from packages/vue-test-workspace/vue-tsc-2.7/strict-template/tsconfig.json rename to packages/vue2-test-workspace/vue-tsc/strict-template/tsconfig.json diff --git a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/unknownProp/main.vue b/packages/vue2-test-workspace/vue-tsc/strict-template/unknownProp/main.vue similarity index 85% rename from packages/vue-test-workspace/vue-tsc-2.7/strict-template/unknownProp/main.vue rename to packages/vue2-test-workspace/vue-tsc/strict-template/unknownProp/main.vue index 8e4a04fd0c..07d4b2e56f 100644 --- a/packages/vue-test-workspace/vue-tsc-2.7/strict-template/unknownProp/main.vue +++ b/packages/vue2-test-workspace/vue-tsc/strict-template/unknownProp/main.vue @@ -9,7 +9,7 @@ diff --git a/packages/vue-test-workspace-vue-2/vue-tsc/strict-template/#3673/main.vue b/packages/vue-test-workspace-vue-2/vue-tsc/strict-template/#3673/main.vue deleted file mode 100644 index b488e2b6b7..0000000000 --- a/packages/vue-test-workspace-vue-2/vue-tsc/strict-template/#3673/main.vue +++ /dev/null @@ -1,8 +0,0 @@ - - - \ No newline at end of file From a5aea54352cb5ee56b738e15d5cdb4abfd709080 Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Mon, 23 Oct 2023 16:32:25 +0800 Subject: [PATCH 12/12] remove license for tests --- packages/vue-test-workspace-vue-2/LICENSE | 21 --------------------- packages/vue-test-workspace/LICENSE | 21 --------------------- 2 files changed, 42 deletions(-) delete mode 100644 packages/vue-test-workspace-vue-2/LICENSE delete mode 100644 packages/vue-test-workspace/LICENSE diff --git a/packages/vue-test-workspace-vue-2/LICENSE b/packages/vue-test-workspace-vue-2/LICENSE deleted file mode 100644 index b55e47a7e8..0000000000 --- a/packages/vue-test-workspace-vue-2/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-present Johnson Chu - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/vue-test-workspace/LICENSE b/packages/vue-test-workspace/LICENSE deleted file mode 100644 index b55e47a7e8..0000000000 --- a/packages/vue-test-workspace/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021-present Johnson Chu - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE.