diff --git a/CHANGELOG.md b/CHANGELOG.md index ec08f2169..53b685c39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,34 @@ +## [3.3.10](https://github.com/vuejs/core/compare/v3.3.9...v3.3.10) (2023-12-04) + + +### Bug Fixes + +* **app:** prevent template from being cached between apps with different options ([#9724](https://github.com/vuejs/core/issues/9724)) ([ec71585](https://github.com/vuejs/core/commit/ec715854ca12520b2afc9e9b3981cbae05ae5206)), closes [#9618](https://github.com/vuejs/core/issues/9618) +* **compiler-sfc:** avoid passing forEach index to genMap ([f12db7f](https://github.com/vuejs/core/commit/f12db7fb564a534cef2e5805cc9f54afe5d72fbf)) +* **compiler-sfc:** deindent pug/jade templates ([6345197](https://github.com/vuejs/core/commit/634519720a21fb5a6871454e1cadad7053a568b8)), closes [#3231](https://github.com/vuejs/core/issues/3231) [#3842](https://github.com/vuejs/core/issues/3842) [#7723](https://github.com/vuejs/core/issues/7723) +* **compiler-sfc:** fix :where and :is selector in scoped mode with multiple selectors ([#9735](https://github.com/vuejs/core/issues/9735)) ([c3e2c55](https://github.com/vuejs/core/commit/c3e2c556b532656b50b8ab5cd2d9eabc26622d63)), closes [#9707](https://github.com/vuejs/core/issues/9707) +* **compiler-sfc:** generate more treeshaking friendly code ([#9507](https://github.com/vuejs/core/issues/9507)) ([8d74ca0](https://github.com/vuejs/core/commit/8d74ca0e6fa2738ca6854b7e879ff59419f948c7)), closes [#9500](https://github.com/vuejs/core/issues/9500) +* **compiler-sfc:** support inferring generic types ([#8511](https://github.com/vuejs/core/issues/8511)) ([eb5e307](https://github.com/vuejs/core/commit/eb5e307c0be62002e62c4c800d0dfacb39b0d4ca)), closes [#8482](https://github.com/vuejs/core/issues/8482) +* **compiler-sfc:** support resolving components from props ([#8785](https://github.com/vuejs/core/issues/8785)) ([7cbcee3](https://github.com/vuejs/core/commit/7cbcee3d831241a8bd3588ae92d3f27e3641e25f)) +* **compiler-sfc:** throw error when failing to load TS during type resolution ([#8883](https://github.com/vuejs/core/issues/8883)) ([4936d2e](https://github.com/vuejs/core/commit/4936d2e11a8d0ca3704bfe408548cb26bb3fd5e9)) +* **cssVars:** cssVar names should be double-escaped when generating code for ssr ([#8824](https://github.com/vuejs/core/issues/8824)) ([5199a12](https://github.com/vuejs/core/commit/5199a12f8855cd06f24bf355708b5a2134f63176)), closes [#7823](https://github.com/vuejs/core/issues/7823) +* **deps:** update compiler to ^7.23.4 ([#9681](https://github.com/vuejs/core/issues/9681)) ([31f6ebc](https://github.com/vuejs/core/commit/31f6ebc4df84490ed29fb75e7bf4259200eb51f0)) +* **runtime-core:** Suspense get anchor properly in Transition ([#9309](https://github.com/vuejs/core/issues/9309)) ([65f3fe2](https://github.com/vuejs/core/commit/65f3fe273127a8b68e1222fbb306d28d85f01757)), closes [#8105](https://github.com/vuejs/core/issues/8105) +* **runtime-dom:** set width/height with units as attribute ([#8781](https://github.com/vuejs/core/issues/8781)) ([bfc1838](https://github.com/vuejs/core/commit/bfc1838f31199de3f189198a3c234fa7bae91386)) +* **ssr:** avoid computed being accidentally cached before server render ([#9688](https://github.com/vuejs/core/issues/9688)) ([30d5d93](https://github.com/vuejs/core/commit/30d5d93a92b2154406ec04f8aca6b217fa01177c)), closes [#5300](https://github.com/vuejs/core/issues/5300) +* **types:** expose emits as props in functional components ([#9234](https://github.com/vuejs/core/issues/9234)) ([887e54c](https://github.com/vuejs/core/commit/887e54c347ea9eac4c721b5e2288f054873d1d30)) +* **types:** fix reactive collection types ([#8960](https://github.com/vuejs/core/issues/8960)) ([ad27473](https://github.com/vuejs/core/commit/ad274737015c36906d76f3189203093fa3a2e4e7)), closes [#8904](https://github.com/vuejs/core/issues/8904) +* **types:** improve return type withKeys and withModifiers ([#9734](https://github.com/vuejs/core/issues/9734)) ([43c3cfd](https://github.com/vuejs/core/commit/43c3cfdec5ae5d70fa2a21e857abc2d73f1a0d07)) + + +### Performance Improvements + +* optimize on* prop check ([38aaa8c](https://github.com/vuejs/core/commit/38aaa8c88648c54fe2616ad9c0961288092fcb44)) +* **runtime-dom:** cache modifier wrapper functions ([da4a4fb](https://github.com/vuejs/core/commit/da4a4fb5e8eee3c6d31f24ebd79a9d0feca56cb2)), closes [#8882](https://github.com/vuejs/core/issues/8882) +* **v-on:** constant handlers with modifiers should not be treated as dynamic ([4d94ebf](https://github.com/vuejs/core/commit/4d94ebfe75174b340d2b794e699cad1add3600a9)) + + + # [3.4.0-alpha.3](https://github.com/vuejs/core/compare/v3.4.0-alpha.2...v3.4.0-alpha.3) (2023-11-28) @@ -97,7 +128,7 @@ * **compiler-sfc:** fix dynamic directive arguments usage check for slots ([#9495](https://github.com/vuejs/core/issues/9495)) ([b39fa1f](https://github.com/vuejs/core/commit/b39fa1f8157647859331ce439c42ae016a49b415)), closes [#9493](https://github.com/vuejs/core/issues/9493) * **deps:** update dependency @vue/repl to ^2.6.2 ([#9536](https://github.com/vuejs/core/issues/9536)) ([5cef325](https://github.com/vuejs/core/commit/5cef325f41e3b38657c72fa1a38dedeee1c7a60a)) * **deps:** update dependency @vue/repl to ^2.6.3 ([#9540](https://github.com/vuejs/core/issues/9540)) ([176d590](https://github.com/vuejs/core/commit/176d59058c9aecffe9da4d4311e98496684f06d4)) -* **hydration:** fix tagName access eeror on comment/text node hydration mismatch ([dd8a0cf](https://github.com/vuejs/core/commit/dd8a0cf5dcde13d2cbd899262a0e07f16e14e489)), closes [#9531](https://github.com/vuejs/core/issues/9531) +* **hydration:** fix tagName access error on comment/text node hydration mismatch ([dd8a0cf](https://github.com/vuejs/core/commit/dd8a0cf5dcde13d2cbd899262a0e07f16e14e489)), closes [#9531](https://github.com/vuejs/core/issues/9531) * **types:** avoid exposing lru-cache types in generated dts ([462aeb3](https://github.com/vuejs/core/commit/462aeb3b600765e219ded2ee9a0ed1e74df61de0)), closes [#9521](https://github.com/vuejs/core/issues/9521) * **warn:** avoid warning on empty children with Suspense ([#3962](https://github.com/vuejs/core/issues/3962)) ([405f345](https://github.com/vuejs/core/commit/405f34587a63a5f1e3d147b9848219ea98acc22d)) diff --git a/package.json b/package.json index d4e6e7270..27327e224 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,8 @@ "node": ">=18.12.0" }, "devDependencies": { - "@babel/parser": "^7.23.4", - "@babel/types": "^7.23.4", + "@babel/parser": "^7.23.5", + "@babel/types": "^7.23.5", "@rollup/plugin-alias": "^5.0.1", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-json": "^6.0.1", @@ -67,7 +67,7 @@ "@rollup/plugin-terser": "^0.4.4", "@types/hash-sum": "^1.0.2", "@types/minimist": "^1.2.5", - "@types/node": "^20.10.0", + "@types/node": "^20.10.3", "@types/semver": "^7.5.5", "@typescript-eslint/parser": "^6.13.0", "@vitest/coverage-istanbul": "^0.34.6", @@ -93,7 +93,7 @@ "prettier": "^3.1.0", "pretty-bytes": "^6.1.1", "pug": "^3.0.2", - "puppeteer": "~21.5.1", + "puppeteer": "~21.5.2", "rimraf": "^5.0.5", "rollup": "^4.1.4", "rollup-plugin-dts": "^6.1.0", @@ -105,7 +105,7 @@ "terser": "^5.22.0", "todomvc-app-css": "^2.4.3", "tslib": "^2.6.2", - "tsx": "^4.5.0", + "tsx": "^4.6.2", "typescript": "^5.2.2", "vite": "^5.0.0", "vitest": "^0.34.6" diff --git a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts index f08b9f22e..e8cca8224 100644 --- a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts @@ -152,6 +152,28 @@ describe('compiler: element transform', () => { expect(node.tag).toBe(`Foo.Example`) }) + test('resolve namespaced component from props bindings (inline)', () => { + const { root, node } = parseWithElementTransform(``, { + inline: true, + bindingMetadata: { + Foo: BindingTypes.PROPS + } + }) + expect(root.helpers).not.toContain(RESOLVE_COMPONENT) + expect(node.tag).toBe(`_unref(__props["Foo"]).Example`) + }) + + test('resolve namespaced component from props bindings (non-inline)', () => { + const { root, node } = parseWithElementTransform(``, { + inline: false, + bindingMetadata: { + Foo: BindingTypes.PROPS + } + }) + expect(root.helpers).not.toContain(RESOLVE_COMPONENT) + expect(node.tag).toBe('_unref($props["Foo"]).Example') + }) + test('do not resolve component from non-script-setup bindings', () => { const bindingMetadata = { Example: BindingTypes.SETUP_MAYBE_REF @@ -1138,6 +1160,20 @@ describe('compiler: element transform', () => { genFlagText([PatchFlags.PROPS, PatchFlags.NEED_HYDRATION]) ) }) + + test('should not have PROPS patchflag for constant v-on handlers', () => { + const { node } = parseWithElementTransform(`
`, { + prefixIdentifiers: true, + bindingMetadata: { + foo: BindingTypes.SETUP_CONST + }, + directiveTransforms: { + on: transformOn + } + }) + // should only have hydration flag + expect(node.patchFlag).toBe(genFlagText(PatchFlags.NEED_HYDRATION)) + }) }) describe('dynamic component', () => { diff --git a/packages/compiler-core/package.json b/packages/compiler-core/package.json index 0991102a7..511dd4a23 100644 --- a/packages/compiler-core/package.json +++ b/packages/compiler-core/package.json @@ -32,13 +32,13 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme", "dependencies": { - "@babel/parser": "^7.23.4", + "@babel/parser": "^7.23.5", "@vue/shared": "workspace:*", "entities": "^4.5.0", "estree-walker": "^2.0.2", "source-map-js": "^1.0.2" }, "devDependencies": { - "@babel/types": "^7.23.4" + "@babel/types": "^7.23.5" } } diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index 921f61234..6f35f4f8e 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -19,7 +19,8 @@ import { TemplateTextChildNode, DirectiveArguments, createVNodeCall, - ConstantTypes + ConstantTypes, + JSChildNode } from '../ast' import { PatchFlags, @@ -370,6 +371,13 @@ function resolveSetupReference(name: string, context: TransformContext) { `${context.helperString(UNREF)}(${fromMaybeRef})` : `$setup[${JSON.stringify(fromMaybeRef)}]` } + + const fromProps = checkType(BindingTypes.PROPS) + if (fromProps) { + return `${context.helperString(UNREF)}(${ + context.inline ? '__props' : '$props' + }[${JSON.stringify(fromProps)}])` + } } export type PropsExpression = ObjectExpression | CallExpression | ExpressionNode @@ -437,6 +445,12 @@ export function buildProps( hasVnodeHook = true } + if (isEventHandler && value.type === NodeTypes.JS_CALL_EXPRESSION) { + // handler wrapped with internal helper e.g. withModifiers(fn) + // extract the actual expression + value = value.arguments[0] as JSChildNode + } + if ( value.type === NodeTypes.JS_CACHE_EXPRESSION || ((value.type === NodeTypes.SIMPLE_EXPRESSION || diff --git a/packages/compiler-dom/__tests__/transforms/vOn.spec.ts b/packages/compiler-dom/__tests__/transforms/vOn.spec.ts index 79ffcdef0..42b4cd798 100644 --- a/packages/compiler-dom/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-dom/__tests__/transforms/vOn.spec.ts @@ -7,7 +7,8 @@ import { NodeTypes, ObjectExpression, transform, - VNodeCall + VNodeCall, + BindingTypes } from '@vue/compiler-core' import { transformOn } from '../../src/transforms/vOn' import { V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS } from '../../src/runtimeHelpers' @@ -25,12 +26,11 @@ function parseWithVOn(template: string, options: CompilerOptions = {}) { }, ...options }) + const node = (ast.children[0] as ElementNode).codegenNode as VNodeCall return { root: ast, - props: ( - ((ast.children[0] as ElementNode).codegenNode as VNodeCall) - .props as ObjectExpression - ).properties + node, + props: (node.props as ObjectExpression).properties } } @@ -288,4 +288,18 @@ describe('compiler-dom: transform v-on', () => { } }) }) + + test('should not have PROPS patchFlag for constant v-on handlers with modifiers', () => { + const { node } = parseWithVOn(`
`, { + prefixIdentifiers: true, + bindingMetadata: { + foo: BindingTypes.SETUP_CONST + }, + directiveTransforms: { + on: transformOn + } + }) + // should only have hydration flag + expect(node.patchFlag).toBe(genFlagText(PatchFlags.NEED_HYDRATION)) + }) }) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index e26dfef53..220c68607 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -1065,10 +1065,12 @@ export default { setup(__props) { const count = ref(0) + const style = { color: 'red' } return (_ctx, _push, _parent, _attrs) => { const _cssVars = { style: { - \\"--xxxxxxxx-count\\": (count.value) + \\"--xxxxxxxx-count\\": (count.value), + \\"--xxxxxxxx-style\\\\\\\\.color\\": (style.color) }} _push(\`', () => {