Skip to content

Commit

Permalink
chore: Merge branch 'main' into minor
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 24, 2023
2 parents 7aa3f25 + a8d0b1b commit 5ec9377
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 245 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
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"version": "3.4.0-beta.4",
"packageManager": "[email protected].0",
"packageManager": "[email protected].1",
"type": "module",
"scripts": {
"dev": "node scripts/dev.js",
Expand Down Expand Up @@ -59,8 +59,8 @@
"node": ">=18.12.0"
},
"devDependencies": {
"@babel/parser": "^7.23.5",
"@babel/types": "^7.23.5",
"@babel/parser": "^7.23.6",
"@babel/types": "^7.23.6",
"@codspeed/vitest-plugin": "^2.3.1",
"@rollup/plugin-alias": "^5.0.1",
"@rollup/plugin-commonjs": "^25.0.7",
Expand All @@ -70,16 +70,16 @@
"@rollup/plugin-terser": "^0.4.4",
"@types/hash-sum": "^1.0.2",
"@types/minimist": "^1.2.5",
"@types/node": "^20.10.4",
"@types/node": "^20.10.5",
"@types/semver": "^7.5.5",
"@typescript-eslint/parser": "^6.13.2",
"@vitest/coverage-istanbul": "^1.0.4",
"@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-define-config": "^1.24.1",
"eslint-plugin-jest": "^27.6.0",
"estree-walker": "^2.0.2",
Expand All @@ -89,14 +89,14 @@
"lodash": "^4.17.21",
"magic-string": "^0.30.5",
"markdown-table": "^3.0.3",
"marked": "^11.0.1",
"marked": "^11.1.0",
"minimist": "^1.2.8",
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"prettier": "^3.1.1",
"pretty-bytes": "^6.1.1",
"pug": "^3.0.2",
"puppeteer": "~21.6.0",
"puppeteer": "~21.6.1",
"rimraf": "^5.0.5",
"rollup": "^4.1.4",
"rollup-plugin-dts": "^6.1.0",
Expand All @@ -108,9 +108,9 @@
"terser": "^5.22.0",
"todomvc-app-css": "^2.4.3",
"tslib": "^2.6.2",
"tsx": "^4.6.2",
"tsx": "^4.7.0",
"typescript": "^5.2.2",
"vite": "^5.0.5",
"vitest": "^1.0.4"
"vitest": "^1.1.0"
}
}
4 changes: 2 additions & 2 deletions packages/compiler-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
},
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme",
"dependencies": {
"@babel/parser": "^7.23.5",
"@babel/parser": "^7.23.6",
"@vue/shared": "workspace:*",
"entities": "^4.5.0",
"estree-walker": "^2.0.2",
"source-map-js": "^1.0.2"
},
"devDependencies": {
"@babel/types": "^7.23.5"
"@babel/types": "^7.23.6"
}
}
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
4 changes: 2 additions & 2 deletions packages/compiler-sfc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
"dependencies": {
"@babel/parser": "^7.23.5",
"@babel/parser": "^7.23.6",
"@vue/compiler-core": "workspace:*",
"@vue/compiler-dom": "workspace:*",
"@vue/compiler-ssr": "workspace:*",
Expand All @@ -43,7 +43,7 @@
"source-map-js": "^1.0.2"
},
"devDependencies": {
"@babel/types": "^7.23.5",
"@babel/types": "^7.23.6",
"@vue/consolidate": "^0.17.3",
"hash-sum": "^2.0.0",
"lru-cache": "^10.1.0",
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 @@ -115,7 +115,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 @@ -146,15 +146,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 @@ -215,17 +217,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 @@ -322,6 +325,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 @@ -694,16 +698,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
2 changes: 1 addition & 1 deletion packages/vue-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"homepage": "https://github.com/vuejs/core/tree/main/packages/vue-compat#readme",
"dependencies": {
"@babel/parser": "^7.23.5",
"@babel/parser": "^7.23.6",
"estree-walker": "^2.0.2",
"source-map-js": "^1.0.2"
},
Expand Down
Loading

0 comments on commit 5ec9377

Please sign in to comment.