Skip to content

Commit

Permalink
Merge branch 'main' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
rotu authored Dec 23, 2023
2 parents 223b328 + a8d0b1b commit d521a45
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Hi! I'm really excited that you are interested in contributing to Vue.js. Before

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

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.
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.

After cloning the repo, run:

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

## Scripts

**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`.
**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`.

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".

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
"@rollup/plugin-terser": "^0.4.4",
"@types/hash-sum": "^1.0.2",
"@types/node": "^20.10.5",
"@typescript-eslint/parser": "^6.13.2",
"@typescript-eslint/parser": "^6.15.0",
"@vitest/coverage-istanbul": "^1.1.0",
"@vue/consolidate": "0.17.3",
"conventional-changelog-cli": "^4.1.0",
"enquirer": "^2.4.1",
"esbuild": "^0.19.5",
"esbuild-plugin-polyfill-node": "^0.3.0",
"eslint": "^8.55.0",
"eslint": "^8.56.0",
"eslint-plugin-jest": "^27.6.0",
"estree-walker": "^2.0.2",
"execa": "^8.0.1",
Expand Down
37 changes: 34 additions & 3 deletions packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,34 @@ describe('resolveType', () => {
manufacturer: ['Object']
})
})

// #9871
test('shared generics with different args', () => {
const files = {
'/foo.ts': `export interface Foo<T> { value: T }`
}
const { props } = resolve(
`import type { Foo } from './foo'
defineProps<Foo<string>>()`,
files,
undefined,
`/One.vue`
)
expect(props).toStrictEqual({
value: ['String']
})
const { props: props2 } = resolve(
`import type { Foo } from './foo'
defineProps<Foo<number>>()`,
files,
undefined,
`/Two.vue`,
false /* do not invalidate cache */
)
expect(props2).toStrictEqual({
value: ['Number']
})
})
})

describe('errors', () => {
Expand Down Expand Up @@ -1012,7 +1040,8 @@ function resolve(
code: string,
files: Record<string, string> = {},
options?: Partial<SFCScriptCompileOptions>,
sourceFileName: string = '/Test.vue'
sourceFileName: string = '/Test.vue',
invalidateCache = true
) {
const { descriptor } = parse(`<script setup lang="ts">\n${code}\n</script>`, {
filename: sourceFileName
Expand All @@ -1030,8 +1059,10 @@ function resolve(
...options
})

for (const file in files) {
invalidateTypeCache(file)
if (invalidateCache) {
for (const file in files) {
invalidateTypeCache(file)
}
}

// ctx.userImports is collected when calling compileScript(), but we are
Expand Down
24 changes: 15 additions & 9 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class TypeScope {
public types: Record<string, ScopeTypeNode> = Object.create(null),
public declares: Record<string, ScopeTypeNode> = Object.create(null)
) {}

isGenericScope = false
resolvedImportSources: Record<string, string> = Object.create(null)
exportedTypes: Record<string, ScopeTypeNode> = Object.create(null)
exportedDeclares: Record<string, ScopeTypeNode> = Object.create(null)
Expand Down Expand Up @@ -121,15 +121,17 @@ export function resolveTypeElements(
scope?: TypeScope,
typeParameters?: Record<string, Node>
): ResolvedElements {
if (node._resolvedElements) {
const canCache = !typeParameters
if (canCache && node._resolvedElements) {
return node._resolvedElements
}
return (node._resolvedElements = innerResolveTypeElements(
const resolved = innerResolveTypeElements(
ctx,
node,
node._ownerScope || scope || ctxToScope(ctx),
typeParameters
))
)
return canCache ? (node._resolvedElements = resolved) : resolved
}

function innerResolveTypeElements(
Expand Down Expand Up @@ -190,17 +192,18 @@ function innerResolveTypeElements(
}
const resolved = resolveTypeReference(ctx, node, scope)
if (resolved) {
const typeParams: Record<string, Node> = Object.create(null)
let typeParams: Record<string, Node> | undefined
if (
(resolved.type === 'TSTypeAliasDeclaration' ||
resolved.type === 'TSInterfaceDeclaration') &&
resolved.typeParameters &&
node.typeParameters
) {
typeParams = Object.create(null)
resolved.typeParameters.params.forEach((p, i) => {
let param = typeParameters && typeParameters[p.name]
if (!param) param = node.typeParameters!.params[i]
typeParams[p.name] = param
typeParams![p.name] = param
})
}
return resolveTypeElements(
Expand Down Expand Up @@ -297,6 +300,7 @@ function typeElementsToMap(
// capture generic parameters on node's scope
if (typeParameters) {
scope = createChildScope(scope)
scope.isGenericScope = true
Object.assign(scope.types, typeParameters)
}
;(e as MaybeWithScope)._ownerScope = scope
Expand Down Expand Up @@ -669,16 +673,18 @@ function resolveTypeReference(
name?: string,
onlyExported = false
): ScopeTypeNode | undefined {
if (node._resolvedReference) {
const canCache = !scope?.isGenericScope
if (canCache && node._resolvedReference) {
return node._resolvedReference
}
return (node._resolvedReference = innerResolveTypeReference(
const resolved = innerResolveTypeReference(
ctx,
scope || ctxToScope(ctx),
name || getReferenceName(node),
node,
onlyExported
))
)
return canCache ? (node._resolvedReference = resolved) : resolved
}

function innerResolveTypeReference(
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-dom/__tests__/customizedBuiltIn.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type SpyInstance } from 'vitest'
import { type MockInstance } from 'vitest'
import { render, h } from '@vue/runtime-dom'

describe('customized built-in elements support', () => {
let createElement: SpyInstance
let createElement: MockInstance
afterEach(() => {
createElement.mockRestore()
})
Expand Down
78 changes: 39 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d521a45

Please sign in to comment.