Skip to content

Commit 92ae32f

Browse files
authored
Merge branch 'main' into fix-compat-document-flag-name
2 parents c16361d + a8d0b1b commit 92ae32f

File tree

7 files changed

+96
-59
lines changed

7 files changed

+96
-59
lines changed

.github/contributing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Hi! I'm really excited that you are interested in contributing to Vue.js. Before
6363

6464
You will need [Node.js](https://nodejs.org) **version 18.12+**, and [PNPM](https://pnpm.io) **version 8+**.
6565

66-
We also recommend installing [ni](https://github.com/antfu/ni) to help switching between repos using different package managers. `ni` also provides the handy `nr` command which running npm scripts easier.
66+
We also recommend installing [@antfu/ni](https://github.com/antfu/ni) to help switching between repos using different package managers. `ni` also provides the handy `nr` command which running npm scripts easier.
6767

6868
After cloning the repo, run:
6969

@@ -90,7 +90,7 @@ The project uses [simple-git-hooks](https://github.com/toplenboren/simple-git-ho
9090

9191
## Scripts
9292

93-
**The examples below will be using the `nr` command from the [ni](https://github.com/antfu/ni) package.** You can also use plain `npm run`, but you will need to pass all additional arguments after the command after an extra `--`. For example, `nr build runtime --all` is equivalent to `npm run build -- runtime --all`.
93+
**The examples below will be using the `nr` command from the [@antfu/ni](https://github.com/antfu/ni) package.** You can also use plain `npm run`, but you will need to pass all additional arguments after the command after an extra `--`. For example, `nr build runtime --all` is equivalent to `npm run build -- runtime --all`.
9494

9595
The `run-s` and `run-p` commands found in some scripts are from [npm-run-all](https://github.com/mysticatea/npm-run-all) for orchestrating multiple scripts. `run-s` means "run in sequence" while `run-p` means "run in parallel".
9696

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@
7070
"@rollup/plugin-terser": "^0.4.4",
7171
"@types/hash-sum": "^1.0.2",
7272
"@types/node": "^20.10.5",
73-
"@typescript-eslint/parser": "^6.13.2",
73+
"@typescript-eslint/parser": "^6.15.0",
7474
"@vitest/coverage-istanbul": "^1.1.0",
7575
"@vue/consolidate": "0.17.3",
7676
"conventional-changelog-cli": "^4.1.0",
7777
"enquirer": "^2.4.1",
7878
"esbuild": "^0.19.5",
7979
"esbuild-plugin-polyfill-node": "^0.3.0",
80-
"eslint": "^8.55.0",
80+
"eslint": "^8.56.0",
8181
"eslint-plugin-jest": "^27.6.0",
8282
"estree-walker": "^2.0.2",
8383
"execa": "^8.0.1",

packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,34 @@ describe('resolveType', () => {
939939
manufacturer: ['Object']
940940
})
941941
})
942+
943+
// #9871
944+
test('shared generics with different args', () => {
945+
const files = {
946+
'/foo.ts': `export interface Foo<T> { value: T }`
947+
}
948+
const { props } = resolve(
949+
`import type { Foo } from './foo'
950+
defineProps<Foo<string>>()`,
951+
files,
952+
undefined,
953+
`/One.vue`
954+
)
955+
expect(props).toStrictEqual({
956+
value: ['String']
957+
})
958+
const { props: props2 } = resolve(
959+
`import type { Foo } from './foo'
960+
defineProps<Foo<number>>()`,
961+
files,
962+
undefined,
963+
`/Two.vue`,
964+
false /* do not invalidate cache */
965+
)
966+
expect(props2).toStrictEqual({
967+
value: ['Number']
968+
})
969+
})
942970
})
943971

944972
describe('errors', () => {
@@ -1012,7 +1040,8 @@ function resolve(
10121040
code: string,
10131041
files: Record<string, string> = {},
10141042
options?: Partial<SFCScriptCompileOptions>,
1015-
sourceFileName: string = '/Test.vue'
1043+
sourceFileName: string = '/Test.vue',
1044+
invalidateCache = true
10161045
) {
10171046
const { descriptor } = parse(`<script setup lang="ts">\n${code}\n</script>`, {
10181047
filename: sourceFileName
@@ -1030,8 +1059,10 @@ function resolve(
10301059
...options
10311060
})
10321061

1033-
for (const file in files) {
1034-
invalidateTypeCache(file)
1062+
if (invalidateCache) {
1063+
for (const file in files) {
1064+
invalidateTypeCache(file)
1065+
}
10351066
}
10361067

10371068
// ctx.userImports is collected when calling compileScript(), but we are

packages/compiler-sfc/src/script/resolveType.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class TypeScope {
9090
public types: Record<string, ScopeTypeNode> = Object.create(null),
9191
public declares: Record<string, ScopeTypeNode> = Object.create(null)
9292
) {}
93-
93+
isGenericScope = false
9494
resolvedImportSources: Record<string, string> = Object.create(null)
9595
exportedTypes: Record<string, ScopeTypeNode> = Object.create(null)
9696
exportedDeclares: Record<string, ScopeTypeNode> = Object.create(null)
@@ -121,15 +121,17 @@ export function resolveTypeElements(
121121
scope?: TypeScope,
122122
typeParameters?: Record<string, Node>
123123
): ResolvedElements {
124-
if (node._resolvedElements) {
124+
const canCache = !typeParameters
125+
if (canCache && node._resolvedElements) {
125126
return node._resolvedElements
126127
}
127-
return (node._resolvedElements = innerResolveTypeElements(
128+
const resolved = innerResolveTypeElements(
128129
ctx,
129130
node,
130131
node._ownerScope || scope || ctxToScope(ctx),
131132
typeParameters
132-
))
133+
)
134+
return canCache ? (node._resolvedElements = resolved) : resolved
133135
}
134136

135137
function innerResolveTypeElements(
@@ -190,17 +192,18 @@ function innerResolveTypeElements(
190192
}
191193
const resolved = resolveTypeReference(ctx, node, scope)
192194
if (resolved) {
193-
const typeParams: Record<string, Node> = Object.create(null)
195+
let typeParams: Record<string, Node> | undefined
194196
if (
195197
(resolved.type === 'TSTypeAliasDeclaration' ||
196198
resolved.type === 'TSInterfaceDeclaration') &&
197199
resolved.typeParameters &&
198200
node.typeParameters
199201
) {
202+
typeParams = Object.create(null)
200203
resolved.typeParameters.params.forEach((p, i) => {
201204
let param = typeParameters && typeParameters[p.name]
202205
if (!param) param = node.typeParameters!.params[i]
203-
typeParams[p.name] = param
206+
typeParams![p.name] = param
204207
})
205208
}
206209
return resolveTypeElements(
@@ -297,6 +300,7 @@ function typeElementsToMap(
297300
// capture generic parameters on node's scope
298301
if (typeParameters) {
299302
scope = createChildScope(scope)
303+
scope.isGenericScope = true
300304
Object.assign(scope.types, typeParameters)
301305
}
302306
;(e as MaybeWithScope)._ownerScope = scope
@@ -669,16 +673,18 @@ function resolveTypeReference(
669673
name?: string,
670674
onlyExported = false
671675
): ScopeTypeNode | undefined {
672-
if (node._resolvedReference) {
676+
const canCache = !scope?.isGenericScope
677+
if (canCache && node._resolvedReference) {
673678
return node._resolvedReference
674679
}
675-
return (node._resolvedReference = innerResolveTypeReference(
680+
const resolved = innerResolveTypeReference(
676681
ctx,
677682
scope || ctxToScope(ctx),
678683
name || getReferenceName(node),
679684
node,
680685
onlyExported
681-
))
686+
)
687+
return canCache ? (node._resolvedReference = resolved) : resolved
682688
}
683689

684690
function innerResolveTypeReference(

packages/runtime-dom/__tests__/customizedBuiltIn.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { type SpyInstance } from 'vitest'
1+
import { type MockInstance } from 'vitest'
22
import { render, h } from '@vue/runtime-dom'
33

44
describe('customized built-in elements support', () => {
5-
let createElement: SpyInstance
5+
let createElement: MockInstance
66
afterEach(() => {
77
createElement.mockRestore()
88
})

pnpm-lock.yaml

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)