From 92f11d6740929f5b591740e30ae5fba50940ec82 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 10 Jan 2022 15:05:07 +0800 Subject: [PATCH 0001/2528] fix(types): fix shallowReadonly type --- packages/reactivity/src/reactive.ts | 4 +--- test-dts/reactivity.test-d.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index b56cb3627b5..4716230e40f 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -166,9 +166,7 @@ export function readonly( * returned properties. * This is used for creating the props proxy object for stateful components. */ -export function shallowReadonly( - target: T -): Readonly<{ [K in keyof T]: UnwrapNestedRefs }> { +export function shallowReadonly(target: T): Readonly { return createReactiveObject( target, true, diff --git a/test-dts/reactivity.test-d.ts b/test-dts/reactivity.test-d.ts index 3c35ea58a01..4c22765e742 100644 --- a/test-dts/reactivity.test-d.ts +++ b/test-dts/reactivity.test-d.ts @@ -1,3 +1,4 @@ +import { shallowReadonly } from '@vue/reactivity' import { ref, readonly, describe, expectError, expectType, Ref } from './index' describe('should support DeepReadonly', () => { @@ -13,3 +14,11 @@ describe('readonly ref', () => { const r = readonly(ref({ count: 1 })) expectType(r) }) + +describe('shallowReadonly ref unwrap', () => { + const r = shallowReadonly({ count: { n: ref(1) } }) + // @ts-expect-error + r.count = 2 + expectType(r.count.n) + r.count.n.value = 123 +}) From 3007d5b4cafed1da445bc498f771bd2c79eda6fc Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 12 Jan 2022 22:07:19 +0800 Subject: [PATCH 0002/2528] fix(types): KeepAlive match pattern should allow mixed array --- packages/runtime-core/src/components/KeepAlive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime-core/src/components/KeepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts index c6180019f86..08e28616e9c 100644 --- a/packages/runtime-core/src/components/KeepAlive.ts +++ b/packages/runtime-core/src/components/KeepAlive.ts @@ -43,7 +43,7 @@ import { ComponentRenderContext } from '../componentPublicInstance' import { devtoolsComponentAdded } from '../devtools' import { isAsyncWrapper } from '../apiAsyncComponent' -type MatchPattern = string | RegExp | string[] | RegExp[] +type MatchPattern = string | RegExp | (string | RegExp)[] export interface KeepAliveProps { include?: MatchPattern From ce49fdf999967e838fe6b61373c00cb61ff87f33 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 12 Jan 2022 22:07:47 +0800 Subject: [PATCH 0003/2528] refactor: more readable type names for watch cleanup function --- packages/runtime-core/src/apiWatch.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 092491d3b0d..b26c3ee2388 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -40,14 +40,14 @@ import { DeprecationTypes } from './compat/compatConfig' import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig' import { ObjectWatchOptionItem } from './componentOptions' -export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void +export type WatchEffect = (onCleanup: OnCleanup) => void export type WatchSource = Ref | ComputedRef | (() => T) export type WatchCallback = ( value: V, oldValue: OV, - onInvalidate: InvalidateCbRegistrator + onCleanup: OnCleanup ) => any type MapSources = { @@ -62,7 +62,7 @@ type MapSources = { : never } -type InvalidateCbRegistrator = (cb: () => void) => void +type OnCleanup = (cleanupFn: () => void) => void export interface WatchOptionsBase extends DebuggerOptions { flush?: 'pre' | 'post' | 'sync' @@ -242,7 +242,7 @@ function doWatch( source, instance, ErrorCodes.WATCH_CALLBACK, - [onInvalidate] + [onCleanup] ) } } @@ -272,7 +272,7 @@ function doWatch( } let cleanup: () => void - let onInvalidate: InvalidateCbRegistrator = (fn: () => void) => { + let onCleanup: OnCleanup = (fn: () => void) => { cleanup = effect.onStop = () => { callWithErrorHandling(fn, instance, ErrorCodes.WATCH_CLEANUP) } @@ -282,14 +282,14 @@ function doWatch( // unless it's eager if (__SSR__ && isInSSRComponentSetup) { // we will also not call the invalidate callback (+ runner is not set up) - onInvalidate = NOOP + onCleanup = NOOP if (!cb) { getter() } else if (immediate) { callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [ getter(), isMultiSource ? [] : undefined, - onInvalidate + onCleanup ]) } return NOOP @@ -323,7 +323,7 @@ function doWatch( newValue, // pass undefined as the old value when it's changed for the first time oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue, - onInvalidate + onCleanup ]) oldValue = newValue } From ff2d6d1cb7c63645fa3c1721fdff3d60e8792750 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 12 Jan 2022 22:08:05 +0800 Subject: [PATCH 0004/2528] chore: comment usage of short property name --- packages/server-renderer/src/render.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server-renderer/src/render.ts b/packages/server-renderer/src/render.ts index 2b78dda03d9..3b629be435c 100644 --- a/packages/server-renderer/src/render.ts +++ b/packages/server-renderer/src/render.ts @@ -86,7 +86,7 @@ export function renderComponentVNode( const instance = createComponentInstance(vnode, parentComponent, null) const res = setupComponent(instance, true /* isSSR */) const hasAsyncSetup = isPromise(res) - const prefetches = instance.sp + const prefetches = instance.sp /* LifecycleHooks.SERVER_PREFETCH */ if (hasAsyncSetup || prefetches) { let p: Promise = hasAsyncSetup ? (res as Promise) From 77283f4c942ffb16ef8bb501732af80a1e3ac3c2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 14 Jan 2022 14:13:03 +0800 Subject: [PATCH 0005/2528] test(types): test ComponentCustomProps --- test-dts/defineComponent.test-d.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 6c8da0591c0..49634ef57c0 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -15,6 +15,12 @@ import { h } from './index' +declare module 'vue' { + interface ComponentCustomProps { + hello?: string + } +} + describe('with object props', () => { interface ExpectedProps { a?: number | undefined @@ -294,6 +300,7 @@ describe('with object props', () => { fff={(a, b) => ({ a: a > +b })} hhh={false} jjj={() => ''} + hello="hello" /> ) From 92fcb9db0599ae633ae5ff829353612113749996 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 14 Jan 2022 16:21:50 +0800 Subject: [PATCH 0006/2528] workflow: use esbuild for dev scripts --- .github/contributing.md | 9 +- package.json | 8 +- packages/template-explorer/src/index.ts | 4 +- pnpm-lock.yaml | 203 +++++++++++++++++++++++- scripts/dev.js | 137 +++++++++++----- 5 files changed, 314 insertions(+), 47 deletions(-) diff --git a/.github/contributing.md b/.github/contributing.md index 5c50f8a9670..2b0995a1ef1 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -123,16 +123,19 @@ The `dev` script bundles a target package (default: `vue`) in a specified format ```bash $ nr dev -> rollup v1.19.4 -> bundles packages/vue/src/index.ts → packages/vue/dist/vue.global.js... +> watching: packages/vue/dist/vue.global.js ``` -- The `dev` script also supports fuzzy match for the target package, but will only match the first package matched. +- **Important:** output of the `dev` script is for development and debugging only. While it has the same runtime behavior, the generated code should never be published to npm. + +- The `dev` script does not support fuzzy match - you must specify the full package name, e.g. `nr dev runtime-core`. - The `dev` script supports specifying build format via the `-f` flag just like the `build` script. - The `dev` script also supports the `-s` flag for generating source maps, but it will make rebuilds slower. +- The `dev` script supports the `-i` flag for inlining all deps. This is useful when debugging `esm-bundler` builds which externalizes deps by default. + ### `nr dev-compiler` The `dev-compiler` script builds, watches and serves the [Template Explorer](https://github.com/vuejs/vue-next/tree/master/packages/template-explorer) at `http://localhost:5000`. This is extremely useful when working on the compiler. diff --git a/package.json b/package.json index 5bfd59dc1a8..30762ca3f52 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "release": "node scripts/release.js", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "dev-compiler": "run-p \"dev template-explorer\" serve", - "dev-sfc": "run-p \"dev compiler-sfc -- -f esm-browser\" \"dev runtime-core -- -f esm-bundler\" \"dev runtime-dom -- -f esm-bundler\" serve-sfc-playground", + "dev-sfc": "run-p \"dev compiler-sfc -- -f esm-browser\" \"dev vue -- -if esm-bundler-runtime \" serve-sfc-playground", "serve-sfc-playground": "vite packages/sfc-playground --host", "serve": "serve", "open": "open http://localhost:5000/packages/template-explorer/local.html", @@ -48,6 +48,7 @@ }, "devDependencies": { "@babel/types": "^7.12.0", + "@esbuild-plugins/node-modules-polyfill": "^0.1.4", "@microsoft/api-extractor": "^7.15.1", "@rollup/plugin-commonjs": "^18.0.0", "@rollup/plugin-json": "^4.0.0", @@ -66,6 +67,7 @@ "conventional-changelog-cli": "^2.0.31", "csstype": "^3.0.3", "enquirer": "^2.3.2", + "esbuild": "^0.14.11", "eslint": "^7.7.0", "execa": "^4.0.2", "fs-extra": "^9.0.1", @@ -86,11 +88,11 @@ "semver": "^7.3.2", "serve": "^12.0.0", "todomvc-app-css": "^2.3.0", - "tslib": "^2.3.1", "ts-jest": "^27.0.5", + "tslib": "^2.3.1", "typescript": "^4.2.2", - "vue": "workspace:*", "vite": "^2.7.1", + "vue": "workspace:*", "yorkie": "^2.0.0" } } diff --git a/packages/template-explorer/src/index.ts b/packages/template-explorer/src/index.ts index 7b7e2ae273a..d676c717373 100644 --- a/packages/template-explorer/src/index.ts +++ b/packages/template-explorer/src/index.ts @@ -62,7 +62,7 @@ window.init = () => { if (persistedState) { // functions are not persistable, so delete it in case we sometimes need // to debug with custom nodeTransforms - delete persistedState.options.nodeTransforms + delete persistedState.options?.nodeTransforms ssrMode.value = persistedState.ssr Object.assign(compilerOptions, persistedState.options) } @@ -142,7 +142,7 @@ window.init = () => { } const editor = monaco.editor.create(document.getElementById('source')!, { - value: persistedState?.src || `
Hello World!
`, + value: persistedState?.src || `
Hello World
`, language: 'html', ...sharedEditorOptions, wordWrap: 'bounded' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5a068cfbc6d..4237878a534 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,7 @@ importers: .: specifiers: '@babel/types': ^7.12.0 + '@esbuild-plugins/node-modules-polyfill': ^0.1.4 '@microsoft/api-extractor': ^7.15.1 '@rollup/plugin-commonjs': ^18.0.0 '@rollup/plugin-json': ^4.0.0 @@ -23,6 +24,7 @@ importers: conventional-changelog-cli: ^2.0.31 csstype: ^3.0.3 enquirer: ^2.3.2 + esbuild: ^0.14.11 eslint: ^7.7.0 execa: ^4.0.2 fs-extra: ^9.0.1 @@ -51,6 +53,7 @@ importers: yorkie: ^2.0.0 devDependencies: '@babel/types': 7.16.0 + '@esbuild-plugins/node-modules-polyfill': 0.1.4_esbuild@0.14.11 '@microsoft/api-extractor': 7.19.2 '@rollup/plugin-commonjs': 18.1.0_rollup@2.38.5 '@rollup/plugin-json': 4.1.0_rollup@2.38.5 @@ -69,6 +72,7 @@ importers: conventional-changelog-cli: 2.1.1 csstype: 3.0.10 enquirer: 2.3.6 + esbuild: 0.14.11 eslint: 7.32.0 execa: 4.1.0 fs-extra: 9.1.0 @@ -89,7 +93,7 @@ importers: semver: 7.3.5 serve: 12.0.1 todomvc-app-css: 2.4.1 - ts-jest: 27.1.1_dc33159234d58f1c7ac35b6119da0e94 + ts-jest: 27.1.1_305b6a4a69ca4f1a88855b62d81fc1b0 tslib: 2.3.1 typescript: 4.5.3 vite: 2.7.1 @@ -629,6 +633,16 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true + /@esbuild-plugins/node-modules-polyfill/0.1.4_esbuild@0.14.11: + resolution: {integrity: sha512-uZbcXi0zbmKC/050p3gJnne5Qdzw8vkXIv+c2BW0Lsc1ji1SkrxbKPUy5Efr0blbTu1SL8w4eyfpnSdPg3G0Qg==} + peerDependencies: + esbuild: '*' + dependencies: + esbuild: 0.14.11 + escape-string-regexp: 4.0.0 + rollup-plugin-node-polyfills: 0.2.1 + dev: true + /@eslint/eslintrc/0.4.3: resolution: {integrity: sha512-J6KFFz5QCYUJq3pf0mjEcCJVERbzv71PUIDczuh9JkwGEzced6CO5ADLHB1rbf/+oPBtoPfMYNOpGDzCANlbXw==} engines: {node: ^10.12.0 || >=12.0.0} @@ -2584,6 +2598,14 @@ packages: dev: true optional: true + /esbuild-android-arm64/0.14.11: + resolution: {integrity: sha512-6iHjgvMnC/SzDH8TefL+/3lgCjYWwAd1LixYfmz/TBPbDQlxcuSkX0yiQgcJB9k+ibZ54yjVXziIwGdlc+6WNw==} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + /esbuild-darwin-64/0.13.15: resolution: {integrity: sha512-ihOQRGs2yyp7t5bArCwnvn2Atr6X4axqPpEdCFPVp7iUj4cVSdisgvEKdNR7yH3JDjW6aQDw40iQFoTqejqxvQ==} cpu: [x64] @@ -2592,6 +2614,14 @@ packages: dev: true optional: true + /esbuild-darwin-64/0.14.11: + resolution: {integrity: sha512-olq84ikh6TiBcrs3FnM4eR5VPPlcJcdW8BnUz/lNoEWYifYQ+Po5DuYV1oz1CTFMw4k6bQIZl8T3yxL+ZT2uvQ==} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /esbuild-darwin-arm64/0.13.15: resolution: {integrity: sha512-i1FZssTVxUqNlJ6cBTj5YQj4imWy3m49RZRnHhLpefFIh0To05ow9DTrXROTE1urGTQCloFUXTX8QfGJy1P8dQ==} cpu: [arm64] @@ -2600,6 +2630,14 @@ packages: dev: true optional: true + /esbuild-darwin-arm64/0.14.11: + resolution: {integrity: sha512-Jj0ieWLREPBYr/TZJrb2GFH8PVzDqiQWavo1pOFFShrcmHWDBDrlDxPzEZ67NF/Un3t6sNNmeI1TUS/fe1xARg==} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /esbuild-freebsd-64/0.13.15: resolution: {integrity: sha512-G3dLBXUI6lC6Z09/x+WtXBXbOYQZ0E8TDBqvn7aMaOCzryJs8LyVXKY4CPnHFXZAbSwkCbqiPuSQ1+HhrNk7EA==} cpu: [x64] @@ -2608,6 +2646,14 @@ packages: dev: true optional: true + /esbuild-freebsd-64/0.14.11: + resolution: {integrity: sha512-C5sT3/XIztxxz/zwDjPRHyzj/NJFOnakAanXuyfLDwhwupKPd76/PPHHyJx6Po6NI6PomgVp/zi6GRB8PfrOTA==} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /esbuild-freebsd-arm64/0.13.15: resolution: {integrity: sha512-KJx0fzEDf1uhNOZQStV4ujg30WlnwqUASaGSFPhznLM/bbheu9HhqZ6mJJZM32lkyfGJikw0jg7v3S0oAvtvQQ==} cpu: [arm64] @@ -2616,6 +2662,14 @@ packages: dev: true optional: true + /esbuild-freebsd-arm64/0.14.11: + resolution: {integrity: sha512-y3Llu4wbs0bk4cwjsdAtVOesXb6JkdfZDLKMt+v1U3tOEPBdSu6w8796VTksJgPfqvpX22JmPLClls0h5p+L9w==} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-32/0.13.15: resolution: {integrity: sha512-ZvTBPk0YWCLMCXiFmD5EUtB30zIPvC5Itxz0mdTu/xZBbbHJftQgLWY49wEPSn2T/TxahYCRDWun5smRa0Tu+g==} cpu: [ia32] @@ -2624,6 +2678,14 @@ packages: dev: true optional: true + /esbuild-linux-32/0.14.11: + resolution: {integrity: sha512-Cg3nVsxArjyLke9EuwictFF3Sva+UlDTwHIuIyx8qpxRYAOUTmxr2LzYrhHyTcGOleLGXUXYsnUVwKqnKAgkcg==} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-64/0.13.15: resolution: {integrity: sha512-eCKzkNSLywNeQTRBxJRQ0jxRCl2YWdMB3+PkWFo2BBQYC5mISLIVIjThNtn6HUNqua1pnvgP5xX0nHbZbPj5oA==} cpu: [x64] @@ -2632,6 +2694,14 @@ packages: dev: true optional: true + /esbuild-linux-64/0.14.11: + resolution: {integrity: sha512-oeR6dIrrojr8DKVrxtH3xl4eencmjsgI6kPkDCRIIFwv4p+K7ySviM85K66BN01oLjzthpUMvBVfWSJkBLeRbg==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-arm/0.13.15: resolution: {integrity: sha512-wUHttDi/ol0tD8ZgUMDH8Ef7IbDX+/UsWJOXaAyTdkT7Yy9ZBqPg8bgB/Dn3CZ9SBpNieozrPRHm0BGww7W/jA==} cpu: [arm] @@ -2640,6 +2710,14 @@ packages: dev: true optional: true + /esbuild-linux-arm/0.14.11: + resolution: {integrity: sha512-vcwskfD9g0tojux/ZaTJptJQU3a7YgTYsptK1y6LQ/rJmw7U5QJvboNawqM98Ca3ToYEucfCRGbl66OTNtp6KQ==} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-arm64/0.13.15: resolution: {integrity: sha512-bYpuUlN6qYU9slzr/ltyLTR9YTBS7qUDymO8SV7kjeNext61OdmqFAzuVZom+OLW1HPHseBfJ/JfdSlx8oTUoA==} cpu: [arm64] @@ -2648,6 +2726,14 @@ packages: dev: true optional: true + /esbuild-linux-arm64/0.14.11: + resolution: {integrity: sha512-+e6ZCgTFQYZlmg2OqLkg1jHLYtkNDksxWDBWNtI4XG4WxuOCUErLqfEt9qWjvzK3XBcCzHImrajkUjO+rRkbMg==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-mips64le/0.13.15: resolution: {integrity: sha512-KlVjIG828uFPyJkO/8gKwy9RbXhCEUeFsCGOJBepUlpa7G8/SeZgncUEz/tOOUJTcWMTmFMtdd3GElGyAtbSWg==} cpu: [mips64el] @@ -2656,6 +2742,14 @@ packages: dev: true optional: true + /esbuild-linux-mips64le/0.14.11: + resolution: {integrity: sha512-Rrs99L+p54vepmXIb87xTG6ukrQv+CzrM8eoeR+r/OFL2Rg8RlyEtCeshXJ2+Q66MXZOgPJaokXJZb9snq28bw==} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-ppc64le/0.13.15: resolution: {integrity: sha512-h6gYF+OsaqEuBjeesTBtUPw0bmiDu7eAeuc2OEH9S6mV9/jPhPdhOWzdeshb0BskRZxPhxPOjqZ+/OqLcxQwEQ==} cpu: [ppc64] @@ -2664,6 +2758,22 @@ packages: dev: true optional: true + /esbuild-linux-ppc64le/0.14.11: + resolution: {integrity: sha512-JyzziGAI0D30Vyzt0HDihp4s1IUtJ3ssV2zx9O/c+U/dhUHVP2TmlYjzCfCr2Q6mwXTeloDcLS4qkyvJtYptdQ==} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-s390x/0.14.11: + resolution: {integrity: sha512-DoThrkzunZ1nfRGoDN6REwmo8ZZWHd2ztniPVIR5RMw/Il9wiWEYBahb8jnMzQaSOxBsGp0PbyJeVLTUatnlcw==} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-netbsd-64/0.13.15: resolution: {integrity: sha512-3+yE9emwoevLMyvu+iR3rsa+Xwhie7ZEHMGDQ6dkqP/ndFzRHkobHUKTe+NCApSqG5ce2z4rFu+NX/UHnxlh3w==} cpu: [x64] @@ -2672,6 +2782,14 @@ packages: dev: true optional: true + /esbuild-netbsd-64/0.14.11: + resolution: {integrity: sha512-12luoRQz+6eihKYh1zjrw0CBa2aw3twIiHV/FAfjh2NEBDgJQOY4WCEUEN+Rgon7xmLh4XUxCQjnwrvf8zhACw==} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + /esbuild-openbsd-64/0.13.15: resolution: {integrity: sha512-wTfvtwYJYAFL1fSs8yHIdf5GEE4NkbtbXtjLWjM3Cw8mmQKqsg8kTiqJ9NJQe5NX/5Qlo7Xd9r1yKMMkHllp5g==} cpu: [x64] @@ -2680,6 +2798,14 @@ packages: dev: true optional: true + /esbuild-openbsd-64/0.14.11: + resolution: {integrity: sha512-l18TZDjmvwW6cDeR4fmizNoxndyDHamGOOAenwI4SOJbzlJmwfr0jUgjbaXCUuYVOA964siw+Ix+A+bhALWg8Q==} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + /esbuild-sunos-64/0.13.15: resolution: {integrity: sha512-lbivT9Bx3t1iWWrSnGyBP9ODriEvWDRiweAs69vI+miJoeKwHWOComSRukttbuzjZ8r1q0mQJ8Z7yUsDJ3hKdw==} cpu: [x64] @@ -2688,6 +2814,14 @@ packages: dev: true optional: true + /esbuild-sunos-64/0.14.11: + resolution: {integrity: sha512-bmYzDtwASBB8c+0/HVOAiE9diR7+8zLm/i3kEojUH2z0aIs6x/S4KiTuT5/0VKJ4zk69kXel1cNWlHBMkmavQg==} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-32/0.13.15: resolution: {integrity: sha512-fDMEf2g3SsJ599MBr50cY5ve5lP1wyVwTe6aLJsM01KtxyKkB4UT+fc5MXQFn3RLrAIAZOG+tHC+yXObpSn7Nw==} cpu: [ia32] @@ -2696,6 +2830,14 @@ packages: dev: true optional: true + /esbuild-windows-32/0.14.11: + resolution: {integrity: sha512-J1Ys5hMid8QgdY00OBvIolXgCQn1ARhYtxPnG6ESWNTty3ashtc4+As5nTrsErnv8ZGUcWZe4WzTP/DmEVX1UQ==} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-64/0.13.15: resolution: {integrity: sha512-9aMsPRGDWCd3bGjUIKG/ZOJPKsiztlxl/Q3C1XDswO6eNX/Jtwu4M+jb6YDH9hRSUflQWX0XKAfWzgy5Wk54JQ==} cpu: [x64] @@ -2704,6 +2846,14 @@ packages: dev: true optional: true + /esbuild-windows-64/0.14.11: + resolution: {integrity: sha512-h9FmMskMuGeN/9G9+LlHPAoiQk9jlKDUn9yA0MpiGzwLa82E7r1b1u+h2a+InprbSnSLxDq/7p5YGtYVO85Mlg==} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-arm64/0.13.15: resolution: {integrity: sha512-zzvyCVVpbwQQATaf3IG8mu1IwGEiDxKkYUdA4FpoCHi1KtPa13jeScYDjlW0Qh+ebWzpKfR2ZwvqAQkSWNcKjA==} cpu: [arm64] @@ -2712,6 +2862,14 @@ packages: dev: true optional: true + /esbuild-windows-arm64/0.14.11: + resolution: {integrity: sha512-dZp7Krv13KpwKklt9/1vBFBMqxEQIO6ri7Azf8C+ob4zOegpJmha2XY9VVWP/OyQ0OWk6cEeIzMJwInRZrzBUQ==} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild/0.13.15: resolution: {integrity: sha512-raCxt02HBKv8RJxE8vkTSCXGIyKHdEdGfUmiYb8wnabnaEmHzyW7DCHb5tEN0xU8ryqg5xw54mcwnYkC4x3AIw==} hasBin: true @@ -2736,6 +2894,31 @@ packages: esbuild-windows-arm64: 0.13.15 dev: true + /esbuild/0.14.11: + resolution: {integrity: sha512-xZvPtVj6yecnDeFb3KjjCM6i7B5TCAQZT77kkW/CpXTMnd6VLnRPKrUB1XHI1pSq6a4Zcy3BGueQ8VljqjDGCg==} + hasBin: true + requiresBuild: true + optionalDependencies: + esbuild-android-arm64: 0.14.11 + esbuild-darwin-64: 0.14.11 + esbuild-darwin-arm64: 0.14.11 + esbuild-freebsd-64: 0.14.11 + esbuild-freebsd-arm64: 0.14.11 + esbuild-linux-32: 0.14.11 + esbuild-linux-64: 0.14.11 + esbuild-linux-arm: 0.14.11 + esbuild-linux-arm64: 0.14.11 + esbuild-linux-mips64le: 0.14.11 + esbuild-linux-ppc64le: 0.14.11 + esbuild-linux-s390x: 0.14.11 + esbuild-netbsd-64: 0.14.11 + esbuild-openbsd-64: 0.14.11 + esbuild-sunos-64: 0.14.11 + esbuild-windows-32: 0.14.11 + esbuild-windows-64: 0.14.11 + esbuild-windows-arm64: 0.14.11 + dev: true + /escalade/3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} engines: {node: '>=6'} @@ -5859,6 +6042,15 @@ packages: inherits: 2.0.4 dev: true + /rollup-plugin-inject/3.0.2: + resolution: {integrity: sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w==} + deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject. + dependencies: + estree-walker: 0.6.1 + magic-string: 0.25.7 + rollup-pluginutils: 2.8.2 + dev: true + /rollup-plugin-node-builtins/2.1.2: resolution: {integrity: sha1-JKH+1KQyV7a2Q3HYq8bOGrFFl+k=} dependencies: @@ -5879,6 +6071,12 @@ packages: rollup-pluginutils: 2.8.2 dev: true + /rollup-plugin-node-polyfills/0.2.1: + resolution: {integrity: sha512-4kCrKPTJ6sK4/gLL/U5QzVT8cxJcofO0OU74tnB19F40cmuAKSzH5/siithxlofFEjwvw1YAhPmbvGNA6jEroA==} + dependencies: + rollup-plugin-inject: 3.0.2 + dev: true + /rollup-plugin-polyfill-node/0.6.2_rollup@2.38.5: resolution: {integrity: sha512-gMCVuR0zsKq0jdBn8pSXN1Ejsc458k2QsFFvQdbHoM0Pot5hEnck+pBP/FDwFS6uAi77pD3rDTytsaUStsOMlA==} dependencies: @@ -6528,7 +6726,7 @@ packages: engines: {node: '>=8'} dev: true - /ts-jest/27.1.1_dc33159234d58f1c7ac35b6119da0e94: + /ts-jest/27.1.1_305b6a4a69ca4f1a88855b62d81fc1b0: resolution: {integrity: sha512-Ds0VkB+cB+8g2JUmP/GKWndeZcCKrbe6jzolGrVWdqVUFByY/2KDHqxJ7yBSon7hDB1TA4PXxjfZ+JjzJisvgA==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} hasBin: true @@ -6551,6 +6749,7 @@ packages: dependencies: '@types/jest': 27.0.3 bs-logger: 0.2.6 + esbuild: 0.14.11 fast-json-stable-stringify: 2.1.0 jest: 27.4.4 jest-util: 27.4.2 diff --git a/scripts/dev.js b/scripts/dev.js index 49418dbf4c1..621cbe63f05 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -1,44 +1,107 @@ -/* -Run Rollup in watch mode for development. +// Using esbuild for faster dev builds. +// We are still using Rollup for production builds because it generates +// smaller files w/ better tree-shaking. -To specific the package to watch, simply pass its name and the desired build -formats to watch (defaults to "global"): +// @ts-check +const { build } = require('esbuild') +const nodePolyfills = require('@esbuild-plugins/node-modules-polyfill') +const { resolve, relative } = require('path') +const args = require('minimist')(process.argv.slice(2)) -``` -# name supports fuzzy match. will watch all packages with name containing "dom" -nr dev dom +const target = args._[0] || 'vue' +const format = args.f || 'global' +const inlineDeps = args.i || args.inline +const pkg = require(resolve(__dirname, `../packages/${target}/package.json`)) -# specify the format to output -nr dev core --formats cjs +// resolve output +const outputFormat = format.startsWith('global') + ? 'iife' + : format === 'cjs' + ? 'cjs' + : 'esm' -# Can also drop all __DEV__ blocks with: -__DEV__=false nr dev -``` -*/ +const postfix = format.endsWith('-runtime') + ? `runtime.${format.replace(/-runtime$/, '')}` + : format -const execa = require('execa') -const { fuzzyMatchTarget } = require('./utils') -const args = require('minimist')(process.argv.slice(2)) -const target = args._.length ? fuzzyMatchTarget(args._)[0] : 'vue' -const formats = args.formats || args.f -const sourceMap = args.sourcemap || args.s -const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7) - -execa( - 'rollup', - [ - '-wc', - '--environment', - [ - `COMMIT:${commit}`, - `TARGET:${target}`, - `FORMATS:${formats || 'global'}`, - sourceMap ? `SOURCE_MAP:true` : `` +const outfile = resolve( + __dirname, + `../packages/${target}/dist/${target}.${postfix}.js` +) +const relativeOutfile = relative(process.cwd(), outfile) + +// resolve extenrals +// TODO this logic is largely duplicated from rollup.config.js +let external = [] +if (!inlineDeps) { + // cjs & esm-bundler: external all deps + if (format === 'cjs' || format.includes('esm-bundler')) { + external = [ + ...external, + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}), + // for @vue/compiler-sfc / server-renderer + 'path', + 'url', + 'stream' ] - .filter(Boolean) - .join(',') - ], - { - stdio: 'inherit' } -) + + if (target === 'compiler-sfc') { + const consolidateDeps = require.resolve('@vue/consolidate/package.json', { + paths: [resolve(__dirname, `../packages/${target}/`)] + }) + external = [ + ...external, + ...Object.keys(require(consolidateDeps).devDependencies), + 'fs', + 'vm', + 'crypto', + 'react-dom/server', + 'teacup/lib/express', + 'arc-templates/dist/es5', + 'then-pug', + 'then-jade' + ] + } +} + +build({ + entryPoints: [resolve(__dirname, `../packages/${target}/src/index.ts`)], + outfile, + bundle: true, + external, + sourcemap: true, + format: outputFormat, + globalName: pkg.buildOptions?.name, + platform: format === 'cjs' ? 'node' : 'browser', + plugins: + format === 'cjs' || pkg.buildOptions?.enableNonBrowserBranches + ? [nodePolyfills.default()] + : undefined, + define: { + __COMMIT__: `"dev"`, + __VERSION__: `"${pkg.version}"`, + __DEV__: `true`, + __TEST__: `false`, + __BROWSER__: String( + format !== 'cjs' && !pkg.buildOptions?.enableNonBrowserBranches + ), + __GLOBAL__: String(format === 'global'), + __ESM_BUNDLER__: String(format.includes('esm-bundler')), + __ESM_BROWSER__: String(format.includes('esm-browser')), + __NODE_JS__: String(format === 'cjs'), + __SSR__: String(format === 'cjs' || format.includes('esm-bundler')), + __COMPAT__: `false`, + __FEATURE_SUSPENSE__: `true`, + __FEATURE_OPTIONS_API__: `true`, + __FEATURE_PROD_DEVTOOLS__: `false` + }, + watch: { + onRebuild(error) { + if (!error) console.log(`rebuilt: ${relativeOutfile}`) + } + } +}).then(() => { + console.log(`watching: ${relativeOutfile}`) +}) From 4dd0f34e813147c130de09a5245f03381006da87 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 14 Jan 2022 16:22:55 +0800 Subject: [PATCH 0007/2528] workflow: bump vite --- package.json | 2 +- pnpm-lock.yaml | 198 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 197 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 30762ca3f52..f17aea784a1 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "ts-jest": "^27.0.5", "tslib": "^2.3.1", "typescript": "^4.2.2", - "vite": "^2.7.1", + "vite": "^2.8.0-beta.2", "vue": "workspace:*", "yorkie": "^2.0.0" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4237878a534..bfec884a46c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -48,7 +48,7 @@ importers: ts-jest: ^27.0.5 tslib: ^2.3.1 typescript: ^4.2.2 - vite: ^2.7.1 + vite: ^2.8.0-beta.2 vue: workspace:* yorkie: ^2.0.0 devDependencies: @@ -96,7 +96,7 @@ importers: ts-jest: 27.1.1_305b6a4a69ca4f1a88855b62d81fc1b0 tslib: 2.3.1 typescript: 4.5.3 - vite: 2.7.1 + vite: 2.8.0-beta.2 vue: link:packages/vue yorkie: 2.0.0 @@ -2606,6 +2606,14 @@ packages: dev: true optional: true + /esbuild-android-arm64/0.14.3: + resolution: {integrity: sha512-v/vdnGJiSGWOAXzg422T9qb4S+P3tOaYtc5n3FDR27Bh3/xQDS7PdYz/yY7HhOlVp0eGwWNbPHEi8FcEhXjsuw==} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + /esbuild-darwin-64/0.13.15: resolution: {integrity: sha512-ihOQRGs2yyp7t5bArCwnvn2Atr6X4axqPpEdCFPVp7iUj4cVSdisgvEKdNR7yH3JDjW6aQDw40iQFoTqejqxvQ==} cpu: [x64] @@ -2622,6 +2630,14 @@ packages: dev: true optional: true + /esbuild-darwin-64/0.14.3: + resolution: {integrity: sha512-swY5OtEg6cfWdgc/XEjkBP7wXSyXXeZHEsWMdh1bDiN1D6GmRphk9SgKFKTj+P3ZHhOGIcC1+UdIwHk5bUcOig==} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /esbuild-darwin-arm64/0.13.15: resolution: {integrity: sha512-i1FZssTVxUqNlJ6cBTj5YQj4imWy3m49RZRnHhLpefFIh0To05ow9DTrXROTE1urGTQCloFUXTX8QfGJy1P8dQ==} cpu: [arm64] @@ -2638,6 +2654,14 @@ packages: dev: true optional: true + /esbuild-darwin-arm64/0.14.3: + resolution: {integrity: sha512-6i9dXPk8oT87wF6VHmwzSad76eMRU2Rt+GXrwF3Y4DCJgnPssJbabNQ9gurkuEX8M0YnEyJF0d1cR7rpTzcEiA==} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /esbuild-freebsd-64/0.13.15: resolution: {integrity: sha512-G3dLBXUI6lC6Z09/x+WtXBXbOYQZ0E8TDBqvn7aMaOCzryJs8LyVXKY4CPnHFXZAbSwkCbqiPuSQ1+HhrNk7EA==} cpu: [x64] @@ -2654,6 +2678,14 @@ packages: dev: true optional: true + /esbuild-freebsd-64/0.14.3: + resolution: {integrity: sha512-WDY5ENsmyceeE+95U3eI+FM8yARY5akWkf21M/x/+v2P5OVsYqCYELglSeAI5Y7bhteCVV3g4i2fRqtkmprdSA==} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /esbuild-freebsd-arm64/0.13.15: resolution: {integrity: sha512-KJx0fzEDf1uhNOZQStV4ujg30WlnwqUASaGSFPhznLM/bbheu9HhqZ6mJJZM32lkyfGJikw0jg7v3S0oAvtvQQ==} cpu: [arm64] @@ -2670,6 +2702,14 @@ packages: dev: true optional: true + /esbuild-freebsd-arm64/0.14.3: + resolution: {integrity: sha512-4BEEGcP0wBzg04pCCWXlgaPuksQHHfwHvYgCIsi+7IsuB17ykt6MHhTkHR5b5pjI/jNtRhPfMsDODUyftQJgvw==} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-32/0.13.15: resolution: {integrity: sha512-ZvTBPk0YWCLMCXiFmD5EUtB30zIPvC5Itxz0mdTu/xZBbbHJftQgLWY49wEPSn2T/TxahYCRDWun5smRa0Tu+g==} cpu: [ia32] @@ -2686,6 +2726,14 @@ packages: dev: true optional: true + /esbuild-linux-32/0.14.3: + resolution: {integrity: sha512-8yhsnjLG/GwCA1RAIndjmCHWViRB2Ol0XeOh2fCXS9qF8tlVrJB7qAiHZpm2vXx+yjOA/bFLTxzU+5pMKqkn5A==} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-64/0.13.15: resolution: {integrity: sha512-eCKzkNSLywNeQTRBxJRQ0jxRCl2YWdMB3+PkWFo2BBQYC5mISLIVIjThNtn6HUNqua1pnvgP5xX0nHbZbPj5oA==} cpu: [x64] @@ -2702,6 +2750,14 @@ packages: dev: true optional: true + /esbuild-linux-64/0.14.3: + resolution: {integrity: sha512-eNq4aixfbwXHIJq4bQDe+XaSNV1grxqpZYs/zHbp0HGHf6SBNlTI02uyTbYGpIzlXmCEPS9tpPCi7BTU45kcJQ==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-arm/0.13.15: resolution: {integrity: sha512-wUHttDi/ol0tD8ZgUMDH8Ef7IbDX+/UsWJOXaAyTdkT7Yy9ZBqPg8bgB/Dn3CZ9SBpNieozrPRHm0BGww7W/jA==} cpu: [arm] @@ -2718,6 +2774,14 @@ packages: dev: true optional: true + /esbuild-linux-arm/0.14.3: + resolution: {integrity: sha512-YcMvJHAQnWrWKb+eLxN9e/iWUC/3w01UF/RXuMknqOW3prX8UQ63QknWz9/RI8BY/sdrdgPEbSmsTU2jy2cayQ==} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-arm64/0.13.15: resolution: {integrity: sha512-bYpuUlN6qYU9slzr/ltyLTR9YTBS7qUDymO8SV7kjeNext61OdmqFAzuVZom+OLW1HPHseBfJ/JfdSlx8oTUoA==} cpu: [arm64] @@ -2734,6 +2798,14 @@ packages: dev: true optional: true + /esbuild-linux-arm64/0.14.3: + resolution: {integrity: sha512-wPLyRoqoV/tEMQ7M24DpAmCMyKqBmtgZY35w2tXM8X5O5b2Ohi7fkPSmd6ZgLIxZIApWt88toA8RT0S7qoxcOA==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-mips64le/0.13.15: resolution: {integrity: sha512-KlVjIG828uFPyJkO/8gKwy9RbXhCEUeFsCGOJBepUlpa7G8/SeZgncUEz/tOOUJTcWMTmFMtdd3GElGyAtbSWg==} cpu: [mips64el] @@ -2750,6 +2822,14 @@ packages: dev: true optional: true + /esbuild-linux-mips64le/0.14.3: + resolution: {integrity: sha512-DdmfM5rcuoqjQL3px5MbquAjZWnySB5LdTrg52SSapp0gXMnGcsM6GY2WVta02CMKn5qi7WPVG4WbqTWE++tJw==} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-ppc64le/0.13.15: resolution: {integrity: sha512-h6gYF+OsaqEuBjeesTBtUPw0bmiDu7eAeuc2OEH9S6mV9/jPhPdhOWzdeshb0BskRZxPhxPOjqZ+/OqLcxQwEQ==} cpu: [ppc64] @@ -2766,6 +2846,14 @@ packages: dev: true optional: true + /esbuild-linux-ppc64le/0.14.3: + resolution: {integrity: sha512-ujdqryj0m135Ms9yaNDVFAcLeRtyftM/v2v7Osji5zElf2TivSMdFxdrYnYICuHfkm8c8gHg1ncwqitL0r+nnA==} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-s390x/0.14.11: resolution: {integrity: sha512-DoThrkzunZ1nfRGoDN6REwmo8ZZWHd2ztniPVIR5RMw/Il9wiWEYBahb8jnMzQaSOxBsGp0PbyJeVLTUatnlcw==} cpu: [s390x] @@ -2790,6 +2878,14 @@ packages: dev: true optional: true + /esbuild-netbsd-64/0.14.3: + resolution: {integrity: sha512-Z/UB9OUdwo1KDJCSGnVueDuKowRZRkduLvRMegHtDBHC3lS5LfZ3RdM1i+4MMN9iafyk8Q9FNcqIXI178ZujvA==} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + /esbuild-openbsd-64/0.13.15: resolution: {integrity: sha512-wTfvtwYJYAFL1fSs8yHIdf5GEE4NkbtbXtjLWjM3Cw8mmQKqsg8kTiqJ9NJQe5NX/5Qlo7Xd9r1yKMMkHllp5g==} cpu: [x64] @@ -2806,6 +2902,14 @@ packages: dev: true optional: true + /esbuild-openbsd-64/0.14.3: + resolution: {integrity: sha512-9I1uoMDeogq3zQuTe3qygmXYjImnvc6rBn51LLbLniQDlfvqHPBMnAZ/5KshwtXXIIMkCwByytDZdiuzRRlTvQ==} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + /esbuild-sunos-64/0.13.15: resolution: {integrity: sha512-lbivT9Bx3t1iWWrSnGyBP9ODriEvWDRiweAs69vI+miJoeKwHWOComSRukttbuzjZ8r1q0mQJ8Z7yUsDJ3hKdw==} cpu: [x64] @@ -2822,6 +2926,14 @@ packages: dev: true optional: true + /esbuild-sunos-64/0.14.3: + resolution: {integrity: sha512-pldqx/Adxl4V4ymiyKxOOyJmHn6nUIo3wqk2xBx07iDgmL2XTcDDQd7N4U4QGu9LnYN4ZF+8IdOYa3oRRpbjtg==} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-32/0.13.15: resolution: {integrity: sha512-fDMEf2g3SsJ599MBr50cY5ve5lP1wyVwTe6aLJsM01KtxyKkB4UT+fc5MXQFn3RLrAIAZOG+tHC+yXObpSn7Nw==} cpu: [ia32] @@ -2838,6 +2950,14 @@ packages: dev: true optional: true + /esbuild-windows-32/0.14.3: + resolution: {integrity: sha512-AqzvA/KbkC2m3kTXGpljLin3EttRbtoPTfBn6w6n2m9MWkTEbhQbE1ONoOBxhO5tExmyJdL/6B87TJJD5jEFBQ==} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-64/0.13.15: resolution: {integrity: sha512-9aMsPRGDWCd3bGjUIKG/ZOJPKsiztlxl/Q3C1XDswO6eNX/Jtwu4M+jb6YDH9hRSUflQWX0XKAfWzgy5Wk54JQ==} cpu: [x64] @@ -2854,6 +2974,14 @@ packages: dev: true optional: true + /esbuild-windows-64/0.14.3: + resolution: {integrity: sha512-HGg3C6113zLGB5hN41PROTnBuoh/arG2lQdOird6xFl9giff1cAfMQOUJUfODKD57dDqHjQ1YGW8gOkg0/IrWw==} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-arm64/0.13.15: resolution: {integrity: sha512-zzvyCVVpbwQQATaf3IG8mu1IwGEiDxKkYUdA4FpoCHi1KtPa13jeScYDjlW0Qh+ebWzpKfR2ZwvqAQkSWNcKjA==} cpu: [arm64] @@ -2870,6 +2998,14 @@ packages: dev: true optional: true + /esbuild-windows-arm64/0.14.3: + resolution: {integrity: sha512-qB2izYu4VpigGnOrAN2Yv7ICYLZWY/AojZtwFfteViDnHgW4jXPYkHQIXTISJbRz25H2cYiv+MfRQYK31RNjlw==} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild/0.13.15: resolution: {integrity: sha512-raCxt02HBKv8RJxE8vkTSCXGIyKHdEdGfUmiYb8wnabnaEmHzyW7DCHb5tEN0xU8ryqg5xw54mcwnYkC4x3AIw==} hasBin: true @@ -2919,6 +3055,30 @@ packages: esbuild-windows-arm64: 0.14.11 dev: true + /esbuild/0.14.3: + resolution: {integrity: sha512-zyEC5hkguW2oieXRXp8VJzQdcO/1FxCS5GjzqOHItRlojXnx/cTavsrkxdWvBH9li2lUq0bN+LeeVEmyCwiR/Q==} + hasBin: true + requiresBuild: true + optionalDependencies: + esbuild-android-arm64: 0.14.3 + esbuild-darwin-64: 0.14.3 + esbuild-darwin-arm64: 0.14.3 + esbuild-freebsd-64: 0.14.3 + esbuild-freebsd-arm64: 0.14.3 + esbuild-linux-32: 0.14.3 + esbuild-linux-64: 0.14.3 + esbuild-linux-arm: 0.14.3 + esbuild-linux-arm64: 0.14.3 + esbuild-linux-mips64le: 0.14.3 + esbuild-linux-ppc64le: 0.14.3 + esbuild-netbsd-64: 0.14.3 + esbuild-openbsd-64: 0.14.3 + esbuild-sunos-64: 0.14.3 + esbuild-windows-32: 0.14.3 + esbuild-windows-64: 0.14.3 + esbuild-windows-arm64: 0.14.3 + dev: true + /escalade/3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} engines: {node: '>=6'} @@ -5587,6 +5747,15 @@ packages: picocolors: 1.0.0 source-map-js: 1.0.1 + /postcss/8.4.5: + resolution: {integrity: sha512-jBDboWM8qpaqwkMwItqTQTiFikhs/67OYVvblFFTM7MrZjt6yMKd6r2kgXizEbTTljacm4NldIlZnhbjr84QYg==} + engines: {node: ^10 || ^12 || >=14} + dependencies: + nanoid: 3.1.30 + picocolors: 1.0.0 + source-map-js: 1.0.1 + dev: true + /prelude-ls/1.1.2: resolution: {integrity: sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=} engines: {node: '>= 0.8.0'} @@ -6961,6 +7130,31 @@ packages: fsevents: 2.3.2 dev: true + /vite/2.8.0-beta.2: + resolution: {integrity: sha512-FjaZAFL+Ln3M9C2eSskp54n0Esyx2Hh2STj0mAAPcnYK16yyNmZRe77ZFh3RQuwPcE1tMo7pQzimzcgfrfkJ+Q==} + engines: {node: '>=12.2.0'} + hasBin: true + peerDependencies: + less: '*' + sass: '*' + stylus: '*' + peerDependenciesMeta: + less: + optional: true + sass: + optional: true + stylus: + optional: true + dependencies: + esbuild: 0.14.3 + json5: 2.2.0 + postcss: 8.4.5 + resolve: 1.20.0 + rollup: 2.61.1 + optionalDependencies: + fsevents: 2.3.2 + dev: true + /vlq/0.2.3: resolution: {integrity: sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==} dev: true From 55cc4af25e6f4924b267620bd965e496f260d41a Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 16 Jan 2022 15:20:56 +0800 Subject: [PATCH 0008/2528] fix(ssr): remove missing ssr directive transform error --- packages/compiler-ssr/src/errors.ts | 4 +--- .../src/transforms/ssrTransformElement.ts | 12 ++---------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/compiler-ssr/src/errors.ts b/packages/compiler-ssr/src/errors.ts index 5030a56db52..755379fb675 100644 --- a/packages/compiler-ssr/src/errors.ts +++ b/packages/compiler-ssr/src/errors.ts @@ -17,14 +17,12 @@ export function createSSRCompilerError( } export const enum SSRErrorCodes { - X_SSR_CUSTOM_DIRECTIVE_NO_TRANSFORM = DOMErrorCodes.__EXTEND_POINT__, - X_SSR_UNSAFE_ATTR_NAME, + X_SSR_UNSAFE_ATTR_NAME = DOMErrorCodes.__EXTEND_POINT__, X_SSR_NO_TELEPORT_TARGET, X_SSR_INVALID_AST_NODE } export const SSRErrorMessages: { [code: number]: string } = { - [SSRErrorCodes.X_SSR_CUSTOM_DIRECTIVE_NO_TRANSFORM]: `Custom directive is missing corresponding SSR transform and will be ignored.`, [SSRErrorCodes.X_SSR_UNSAFE_ATTR_NAME]: `Unsafe attribute name for SSR.`, [SSRErrorCodes.X_SSR_NO_TELEPORT_TARGET]: `Missing the 'to' prop on teleport element.`, [SSRErrorCodes.X_SSR_INVALID_AST_NODE]: `Invalid AST node during SSR transform.` diff --git a/packages/compiler-ssr/src/transforms/ssrTransformElement.ts b/packages/compiler-ssr/src/transforms/ssrTransformElement.ts index 659537b2c82..13d8c04f4ce 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformElement.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformElement.ts @@ -179,18 +179,10 @@ export const ssrTransformElement: NodeTransform = (node, context) => { if (!hasDynamicVBind) { node.children = [createInterpolation(prop.exp, prop.loc)] } - } else { + } else if (!hasDynamicVBind) { // Directive transforms. const directiveTransform = context.directiveTransforms[prop.name] - if (!directiveTransform) { - // no corresponding ssr directive transform found. - context.onError( - createSSRCompilerError( - SSRErrorCodes.X_SSR_CUSTOM_DIRECTIVE_NO_TRANSFORM, - prop.loc - ) - ) - } else if (!hasDynamicVBind) { + if (directiveTransform) { const { props, ssrTagParts } = directiveTransform( prop, node, From 2e3e183b4f19c9e25865e35438653cbc9bf01afc Mon Sep 17 00:00:00 2001 From: edison Date: Sun, 16 Jan 2022 15:37:14 +0800 Subject: [PATCH 0009/2528] fix(KeepAlive): remove cached VNode properly (#5260) fix #5258 --- packages/runtime-core/src/components/KeepAlive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/runtime-core/src/components/KeepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts index 08e28616e9c..7a9419f3b63 100644 --- a/packages/runtime-core/src/components/KeepAlive.ts +++ b/packages/runtime-core/src/components/KeepAlive.ts @@ -174,7 +174,7 @@ const KeepAliveImpl: ComponentOptions = { function unmount(vnode: VNode) { // reset the shapeFlag so it can be properly unmounted resetShapeFlag(vnode) - _unmount(vnode, instance, parentSuspense) + _unmount(vnode, instance, parentSuspense, true) } function pruneCache(filter?: (name: string) => boolean) { From 6cfd72e7609a7d006678eefb4a9961f1d71b3f11 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 16 Jan 2022 15:43:19 +0800 Subject: [PATCH 0010/2528] refactor: move type utils to shared --- packages/runtime-core/src/componentEmits.ts | 4 ++-- packages/runtime-core/src/componentOptions.ts | 5 +++-- packages/runtime-core/src/componentProps.ts | 4 ++-- packages/runtime-core/src/componentPublicInstance.ts | 4 ++-- packages/shared/src/index.ts | 1 + .../{runtime-core/src/helpers => shared/src}/typeUtils.ts | 0 6 files changed, 10 insertions(+), 8 deletions(-) rename packages/{runtime-core/src/helpers => shared/src}/typeUtils.ts (100%) diff --git a/packages/runtime-core/src/componentEmits.ts b/packages/runtime-core/src/componentEmits.ts index 390c6350b8c..4d028913d15 100644 --- a/packages/runtime-core/src/componentEmits.ts +++ b/packages/runtime-core/src/componentEmits.ts @@ -8,7 +8,8 @@ import { isArray, isFunction, isOn, - toNumber + toNumber, + UnionToIntersection } from '@vue/shared' import { ComponentInternalInstance, @@ -18,7 +19,6 @@ import { } from './component' import { callWithAsyncErrorHandling, ErrorCodes } from './errorHandling' import { warn } from './warning' -import { UnionToIntersection } from './helpers/typeUtils' import { devtoolsComponentEmit } from './devtools' import { AppContext } from './apiCreateApp' import { emit as compatInstanceEmit } from './compat/instanceEventEmitter' diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 41e02c5da0a..139ef6d3967 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -15,7 +15,9 @@ import { isObject, isArray, NOOP, - isPromise + isPromise, + LooseRequired, + UnionToIntersection } from '@vue/shared' import { computed, isRef, Ref } from '@vue/reactivity' import { @@ -60,7 +62,6 @@ import { import { warn } from './warning' import { VNodeChild } from './vnode' import { callWithAsyncErrorHandling } from './errorHandling' -import { LooseRequired, UnionToIntersection } from './helpers/typeUtils' import { deepMergeData } from './compat/data' import { DeprecationTypes } from './compat/compatConfig' import { diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index dbd5453904d..946564b5e4a 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -21,7 +21,8 @@ import { EMPTY_ARR, def, extend, - isOn + isOn, + IfAny } from '@vue/shared' import { warn } from './warning' import { @@ -39,7 +40,6 @@ import { createPropsDefaultThis } from './compat/props' import { isCompatEnabled, softAssertCompatEnabled } from './compat/compatConfig' import { DeprecationTypes } from './compat/compatConfig' import { shouldSkipAttr } from './compat/attrsFallthrough' -import { IfAny } from './helpers/typeUtils' export type ComponentPropsOptions

= | ComponentObjectPropsOptions

diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index 8298aff42b1..1d7cfbdec69 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -13,7 +13,8 @@ import { NOOP, extend, isString, - isFunction + isFunction, + UnionToIntersection } from '@vue/shared' import { toRaw, @@ -40,7 +41,6 @@ import { Slots } from './componentSlots' import { markAttrsAccessed } from './componentRenderUtils' import { currentRenderingInstance } from './componentRenderContext' import { warn } from './warning' -import { UnionToIntersection } from './helpers/typeUtils' import { installCompatInstanceProperties } from './compat/instance' /** diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index c41a1a5fad5..fd4f5c9ddce 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -12,6 +12,7 @@ export * from './domAttrConfig' export * from './escapeHtml' export * from './looseEqual' export * from './toDisplayString' +export * from './typeUtils' export const EMPTY_OBJ: { readonly [key: string]: any } = __DEV__ ? Object.freeze({}) diff --git a/packages/runtime-core/src/helpers/typeUtils.ts b/packages/shared/src/typeUtils.ts similarity index 100% rename from packages/runtime-core/src/helpers/typeUtils.ts rename to packages/shared/src/typeUtils.ts From 5ac703055fa83cb1e8a173bbd6a4d6c33707a3c3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 16 Jan 2022 15:46:49 +0800 Subject: [PATCH 0011/2528] fix(types): handle ToRef fix #5188 --- packages/reactivity/src/ref.ts | 4 ++-- test-dts/ref.test-d.ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 55059485d6c..c972676ac42 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -1,6 +1,6 @@ import { isTracking, trackEffects, triggerEffects } from './effect' import { TrackOpTypes, TriggerOpTypes } from './operations' -import { isArray, hasChanged } from '@vue/shared' +import { isArray, hasChanged, IfAny } from '@vue/shared' import { isProxy, toRaw, isReactive, toReactive } from './reactive' import type { ShallowReactiveMarker } from './reactive' import { CollectionTypes } from './collectionHandlers' @@ -222,7 +222,7 @@ class ObjectRefImpl { } } -export type ToRef = [T] extends [Ref] ? T : Ref +export type ToRef = IfAny, [T] extends [Ref] ? T : Ref> export function toRef( object: T, diff --git a/test-dts/ref.test-d.ts b/test-dts/ref.test-d.ts index f91d6415f70..e585470d5e4 100644 --- a/test-dts/ref.test-d.ts +++ b/test-dts/ref.test-d.ts @@ -222,6 +222,11 @@ expectType>(p2.obj.k) expectType>(toRefResult.value.b) expectType>(toRefsResult.a.value.b) + + // #5188 + const props = { foo: 1 } as { foo: any } + const { foo } = toRefs(props) + expectType>(foo) } // toRef default value From 78df8c78c4539d2408278d1a11612b6bbc47d22f Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 16 Jan 2022 15:54:58 +0800 Subject: [PATCH 0012/2528] fix(types/tsx): allow ref_for type on tsx elements --- packages/runtime-dom/types/jsx.d.ts | 2 ++ test-dts/defineComponent.test-d.tsx | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/runtime-dom/types/jsx.d.ts b/packages/runtime-dom/types/jsx.d.ts index e86b67fa351..ab34e299de6 100644 --- a/packages/runtime-dom/types/jsx.d.ts +++ b/packages/runtime-dom/types/jsx.d.ts @@ -1312,6 +1312,8 @@ type ReservedProps = { | string | RuntimeCore.Ref | ((ref: Element | RuntimeCore.ComponentPublicInstance | null) => void) + ref_for?: boolean + ref_key?: string } type ElementAttrs = T & ReservedProps diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 49634ef57c0..c47371ef496 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -288,6 +288,7 @@ describe('with object props', () => { key={'foo'} // should allow ref ref={'foo'} + ref_for={true} /> ) From bc170e68ab452eca98be9dc40217db66a25eae55 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 16 Jan 2022 16:49:58 +0800 Subject: [PATCH 0013/2528] build: downgrade vite --- package.json | 2 +- pnpm-lock.yaml | 171 ++----------------------------------------------- 2 files changed, 6 insertions(+), 167 deletions(-) diff --git a/package.json b/package.json index f17aea784a1..5fb460ccc3e 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "ts-jest": "^27.0.5", "tslib": "^2.3.1", "typescript": "^4.2.2", - "vite": "^2.8.0-beta.2", + "vite": "^2.7.12", "vue": "workspace:*", "yorkie": "^2.0.0" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bfec884a46c..714ed713382 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -48,7 +48,7 @@ importers: ts-jest: ^27.0.5 tslib: ^2.3.1 typescript: ^4.2.2 - vite: ^2.8.0-beta.2 + vite: ^2.7.12 vue: workspace:* yorkie: ^2.0.0 devDependencies: @@ -96,7 +96,7 @@ importers: ts-jest: 27.1.1_305b6a4a69ca4f1a88855b62d81fc1b0 tslib: 2.3.1 typescript: 4.5.3 - vite: 2.8.0-beta.2 + vite: 2.7.12 vue: link:packages/vue yorkie: 2.0.0 @@ -2606,14 +2606,6 @@ packages: dev: true optional: true - /esbuild-android-arm64/0.14.3: - resolution: {integrity: sha512-v/vdnGJiSGWOAXzg422T9qb4S+P3tOaYtc5n3FDR27Bh3/xQDS7PdYz/yY7HhOlVp0eGwWNbPHEi8FcEhXjsuw==} - cpu: [arm64] - os: [android] - requiresBuild: true - dev: true - optional: true - /esbuild-darwin-64/0.13.15: resolution: {integrity: sha512-ihOQRGs2yyp7t5bArCwnvn2Atr6X4axqPpEdCFPVp7iUj4cVSdisgvEKdNR7yH3JDjW6aQDw40iQFoTqejqxvQ==} cpu: [x64] @@ -2630,14 +2622,6 @@ packages: dev: true optional: true - /esbuild-darwin-64/0.14.3: - resolution: {integrity: sha512-swY5OtEg6cfWdgc/XEjkBP7wXSyXXeZHEsWMdh1bDiN1D6GmRphk9SgKFKTj+P3ZHhOGIcC1+UdIwHk5bUcOig==} - cpu: [x64] - os: [darwin] - requiresBuild: true - dev: true - optional: true - /esbuild-darwin-arm64/0.13.15: resolution: {integrity: sha512-i1FZssTVxUqNlJ6cBTj5YQj4imWy3m49RZRnHhLpefFIh0To05ow9DTrXROTE1urGTQCloFUXTX8QfGJy1P8dQ==} cpu: [arm64] @@ -2654,14 +2638,6 @@ packages: dev: true optional: true - /esbuild-darwin-arm64/0.14.3: - resolution: {integrity: sha512-6i9dXPk8oT87wF6VHmwzSad76eMRU2Rt+GXrwF3Y4DCJgnPssJbabNQ9gurkuEX8M0YnEyJF0d1cR7rpTzcEiA==} - cpu: [arm64] - os: [darwin] - requiresBuild: true - dev: true - optional: true - /esbuild-freebsd-64/0.13.15: resolution: {integrity: sha512-G3dLBXUI6lC6Z09/x+WtXBXbOYQZ0E8TDBqvn7aMaOCzryJs8LyVXKY4CPnHFXZAbSwkCbqiPuSQ1+HhrNk7EA==} cpu: [x64] @@ -2678,14 +2654,6 @@ packages: dev: true optional: true - /esbuild-freebsd-64/0.14.3: - resolution: {integrity: sha512-WDY5ENsmyceeE+95U3eI+FM8yARY5akWkf21M/x/+v2P5OVsYqCYELglSeAI5Y7bhteCVV3g4i2fRqtkmprdSA==} - cpu: [x64] - os: [freebsd] - requiresBuild: true - dev: true - optional: true - /esbuild-freebsd-arm64/0.13.15: resolution: {integrity: sha512-KJx0fzEDf1uhNOZQStV4ujg30WlnwqUASaGSFPhznLM/bbheu9HhqZ6mJJZM32lkyfGJikw0jg7v3S0oAvtvQQ==} cpu: [arm64] @@ -2702,14 +2670,6 @@ packages: dev: true optional: true - /esbuild-freebsd-arm64/0.14.3: - resolution: {integrity: sha512-4BEEGcP0wBzg04pCCWXlgaPuksQHHfwHvYgCIsi+7IsuB17ykt6MHhTkHR5b5pjI/jNtRhPfMsDODUyftQJgvw==} - cpu: [arm64] - os: [freebsd] - requiresBuild: true - dev: true - optional: true - /esbuild-linux-32/0.13.15: resolution: {integrity: sha512-ZvTBPk0YWCLMCXiFmD5EUtB30zIPvC5Itxz0mdTu/xZBbbHJftQgLWY49wEPSn2T/TxahYCRDWun5smRa0Tu+g==} cpu: [ia32] @@ -2726,14 +2686,6 @@ packages: dev: true optional: true - /esbuild-linux-32/0.14.3: - resolution: {integrity: sha512-8yhsnjLG/GwCA1RAIndjmCHWViRB2Ol0XeOh2fCXS9qF8tlVrJB7qAiHZpm2vXx+yjOA/bFLTxzU+5pMKqkn5A==} - cpu: [ia32] - os: [linux] - requiresBuild: true - dev: true - optional: true - /esbuild-linux-64/0.13.15: resolution: {integrity: sha512-eCKzkNSLywNeQTRBxJRQ0jxRCl2YWdMB3+PkWFo2BBQYC5mISLIVIjThNtn6HUNqua1pnvgP5xX0nHbZbPj5oA==} cpu: [x64] @@ -2750,14 +2702,6 @@ packages: dev: true optional: true - /esbuild-linux-64/0.14.3: - resolution: {integrity: sha512-eNq4aixfbwXHIJq4bQDe+XaSNV1grxqpZYs/zHbp0HGHf6SBNlTI02uyTbYGpIzlXmCEPS9tpPCi7BTU45kcJQ==} - cpu: [x64] - os: [linux] - requiresBuild: true - dev: true - optional: true - /esbuild-linux-arm/0.13.15: resolution: {integrity: sha512-wUHttDi/ol0tD8ZgUMDH8Ef7IbDX+/UsWJOXaAyTdkT7Yy9ZBqPg8bgB/Dn3CZ9SBpNieozrPRHm0BGww7W/jA==} cpu: [arm] @@ -2774,14 +2718,6 @@ packages: dev: true optional: true - /esbuild-linux-arm/0.14.3: - resolution: {integrity: sha512-YcMvJHAQnWrWKb+eLxN9e/iWUC/3w01UF/RXuMknqOW3prX8UQ63QknWz9/RI8BY/sdrdgPEbSmsTU2jy2cayQ==} - cpu: [arm] - os: [linux] - requiresBuild: true - dev: true - optional: true - /esbuild-linux-arm64/0.13.15: resolution: {integrity: sha512-bYpuUlN6qYU9slzr/ltyLTR9YTBS7qUDymO8SV7kjeNext61OdmqFAzuVZom+OLW1HPHseBfJ/JfdSlx8oTUoA==} cpu: [arm64] @@ -2798,14 +2734,6 @@ packages: dev: true optional: true - /esbuild-linux-arm64/0.14.3: - resolution: {integrity: sha512-wPLyRoqoV/tEMQ7M24DpAmCMyKqBmtgZY35w2tXM8X5O5b2Ohi7fkPSmd6ZgLIxZIApWt88toA8RT0S7qoxcOA==} - cpu: [arm64] - os: [linux] - requiresBuild: true - dev: true - optional: true - /esbuild-linux-mips64le/0.13.15: resolution: {integrity: sha512-KlVjIG828uFPyJkO/8gKwy9RbXhCEUeFsCGOJBepUlpa7G8/SeZgncUEz/tOOUJTcWMTmFMtdd3GElGyAtbSWg==} cpu: [mips64el] @@ -2822,14 +2750,6 @@ packages: dev: true optional: true - /esbuild-linux-mips64le/0.14.3: - resolution: {integrity: sha512-DdmfM5rcuoqjQL3px5MbquAjZWnySB5LdTrg52SSapp0gXMnGcsM6GY2WVta02CMKn5qi7WPVG4WbqTWE++tJw==} - cpu: [mips64el] - os: [linux] - requiresBuild: true - dev: true - optional: true - /esbuild-linux-ppc64le/0.13.15: resolution: {integrity: sha512-h6gYF+OsaqEuBjeesTBtUPw0bmiDu7eAeuc2OEH9S6mV9/jPhPdhOWzdeshb0BskRZxPhxPOjqZ+/OqLcxQwEQ==} cpu: [ppc64] @@ -2846,14 +2766,6 @@ packages: dev: true optional: true - /esbuild-linux-ppc64le/0.14.3: - resolution: {integrity: sha512-ujdqryj0m135Ms9yaNDVFAcLeRtyftM/v2v7Osji5zElf2TivSMdFxdrYnYICuHfkm8c8gHg1ncwqitL0r+nnA==} - cpu: [ppc64] - os: [linux] - requiresBuild: true - dev: true - optional: true - /esbuild-linux-s390x/0.14.11: resolution: {integrity: sha512-DoThrkzunZ1nfRGoDN6REwmo8ZZWHd2ztniPVIR5RMw/Il9wiWEYBahb8jnMzQaSOxBsGp0PbyJeVLTUatnlcw==} cpu: [s390x] @@ -2878,14 +2790,6 @@ packages: dev: true optional: true - /esbuild-netbsd-64/0.14.3: - resolution: {integrity: sha512-Z/UB9OUdwo1KDJCSGnVueDuKowRZRkduLvRMegHtDBHC3lS5LfZ3RdM1i+4MMN9iafyk8Q9FNcqIXI178ZujvA==} - cpu: [x64] - os: [netbsd] - requiresBuild: true - dev: true - optional: true - /esbuild-openbsd-64/0.13.15: resolution: {integrity: sha512-wTfvtwYJYAFL1fSs8yHIdf5GEE4NkbtbXtjLWjM3Cw8mmQKqsg8kTiqJ9NJQe5NX/5Qlo7Xd9r1yKMMkHllp5g==} cpu: [x64] @@ -2902,14 +2806,6 @@ packages: dev: true optional: true - /esbuild-openbsd-64/0.14.3: - resolution: {integrity: sha512-9I1uoMDeogq3zQuTe3qygmXYjImnvc6rBn51LLbLniQDlfvqHPBMnAZ/5KshwtXXIIMkCwByytDZdiuzRRlTvQ==} - cpu: [x64] - os: [openbsd] - requiresBuild: true - dev: true - optional: true - /esbuild-sunos-64/0.13.15: resolution: {integrity: sha512-lbivT9Bx3t1iWWrSnGyBP9ODriEvWDRiweAs69vI+miJoeKwHWOComSRukttbuzjZ8r1q0mQJ8Z7yUsDJ3hKdw==} cpu: [x64] @@ -2926,14 +2822,6 @@ packages: dev: true optional: true - /esbuild-sunos-64/0.14.3: - resolution: {integrity: sha512-pldqx/Adxl4V4ymiyKxOOyJmHn6nUIo3wqk2xBx07iDgmL2XTcDDQd7N4U4QGu9LnYN4ZF+8IdOYa3oRRpbjtg==} - cpu: [x64] - os: [sunos] - requiresBuild: true - dev: true - optional: true - /esbuild-windows-32/0.13.15: resolution: {integrity: sha512-fDMEf2g3SsJ599MBr50cY5ve5lP1wyVwTe6aLJsM01KtxyKkB4UT+fc5MXQFn3RLrAIAZOG+tHC+yXObpSn7Nw==} cpu: [ia32] @@ -2950,14 +2838,6 @@ packages: dev: true optional: true - /esbuild-windows-32/0.14.3: - resolution: {integrity: sha512-AqzvA/KbkC2m3kTXGpljLin3EttRbtoPTfBn6w6n2m9MWkTEbhQbE1ONoOBxhO5tExmyJdL/6B87TJJD5jEFBQ==} - cpu: [ia32] - os: [win32] - requiresBuild: true - dev: true - optional: true - /esbuild-windows-64/0.13.15: resolution: {integrity: sha512-9aMsPRGDWCd3bGjUIKG/ZOJPKsiztlxl/Q3C1XDswO6eNX/Jtwu4M+jb6YDH9hRSUflQWX0XKAfWzgy5Wk54JQ==} cpu: [x64] @@ -2974,14 +2854,6 @@ packages: dev: true optional: true - /esbuild-windows-64/0.14.3: - resolution: {integrity: sha512-HGg3C6113zLGB5hN41PROTnBuoh/arG2lQdOird6xFl9giff1cAfMQOUJUfODKD57dDqHjQ1YGW8gOkg0/IrWw==} - cpu: [x64] - os: [win32] - requiresBuild: true - dev: true - optional: true - /esbuild-windows-arm64/0.13.15: resolution: {integrity: sha512-zzvyCVVpbwQQATaf3IG8mu1IwGEiDxKkYUdA4FpoCHi1KtPa13jeScYDjlW0Qh+ebWzpKfR2ZwvqAQkSWNcKjA==} cpu: [arm64] @@ -2998,14 +2870,6 @@ packages: dev: true optional: true - /esbuild-windows-arm64/0.14.3: - resolution: {integrity: sha512-qB2izYu4VpigGnOrAN2Yv7ICYLZWY/AojZtwFfteViDnHgW4jXPYkHQIXTISJbRz25H2cYiv+MfRQYK31RNjlw==} - cpu: [arm64] - os: [win32] - requiresBuild: true - dev: true - optional: true - /esbuild/0.13.15: resolution: {integrity: sha512-raCxt02HBKv8RJxE8vkTSCXGIyKHdEdGfUmiYb8wnabnaEmHzyW7DCHb5tEN0xU8ryqg5xw54mcwnYkC4x3AIw==} hasBin: true @@ -3055,30 +2919,6 @@ packages: esbuild-windows-arm64: 0.14.11 dev: true - /esbuild/0.14.3: - resolution: {integrity: sha512-zyEC5hkguW2oieXRXp8VJzQdcO/1FxCS5GjzqOHItRlojXnx/cTavsrkxdWvBH9li2lUq0bN+LeeVEmyCwiR/Q==} - hasBin: true - requiresBuild: true - optionalDependencies: - esbuild-android-arm64: 0.14.3 - esbuild-darwin-64: 0.14.3 - esbuild-darwin-arm64: 0.14.3 - esbuild-freebsd-64: 0.14.3 - esbuild-freebsd-arm64: 0.14.3 - esbuild-linux-32: 0.14.3 - esbuild-linux-64: 0.14.3 - esbuild-linux-arm: 0.14.3 - esbuild-linux-arm64: 0.14.3 - esbuild-linux-mips64le: 0.14.3 - esbuild-linux-ppc64le: 0.14.3 - esbuild-netbsd-64: 0.14.3 - esbuild-openbsd-64: 0.14.3 - esbuild-sunos-64: 0.14.3 - esbuild-windows-32: 0.14.3 - esbuild-windows-64: 0.14.3 - esbuild-windows-arm64: 0.14.3 - dev: true - /escalade/3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} engines: {node: '>=6'} @@ -7130,8 +6970,8 @@ packages: fsevents: 2.3.2 dev: true - /vite/2.8.0-beta.2: - resolution: {integrity: sha512-FjaZAFL+Ln3M9C2eSskp54n0Esyx2Hh2STj0mAAPcnYK16yyNmZRe77ZFh3RQuwPcE1tMo7pQzimzcgfrfkJ+Q==} + /vite/2.7.12: + resolution: {integrity: sha512-KvPYToRQWhRfBeVkyhkZ5hASuHQkqZUUdUcE3xyYtq5oYEPIJ0h9LWiWTO6v990glmSac2cEPeYeXzpX5Z6qKQ==} engines: {node: '>=12.2.0'} hasBin: true peerDependencies: @@ -7146,8 +6986,7 @@ packages: stylus: optional: true dependencies: - esbuild: 0.14.3 - json5: 2.2.0 + esbuild: 0.13.15 postcss: 8.4.5 resolve: 1.20.0 rollup: 2.61.1 From 4d07ed809c5de65addbfedb91ac334bf1b029218 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 16 Jan 2022 17:13:52 +0800 Subject: [PATCH 0014/2528] test: remove module augmentation test which does not work in the setup --- test-dts/defineComponent.test-d.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index c47371ef496..031b4a13eb8 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -15,12 +15,6 @@ import { h } from './index' -declare module 'vue' { - interface ComponentCustomProps { - hello?: string - } -} - describe('with object props', () => { interface ExpectedProps { a?: number | undefined @@ -301,7 +295,6 @@ describe('with object props', () => { fff={(a, b) => ({ a: a > +b })} hhh={false} jjj={() => ''} - hello="hello" /> ) From f4f0966b33863ac0fca6a20cf9e8ddfbb311ae87 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 16 Jan 2022 18:22:18 +0800 Subject: [PATCH 0015/2528] fix(ssr): make computed inactive during ssr, fix memory leak fix #5208 --- packages/reactivity/src/computed.ts | 11 +++++++---- packages/runtime-core/src/apiComputed.ts | 7 +++++++ packages/runtime-core/src/index.ts | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 packages/runtime-core/src/apiComputed.ts diff --git a/packages/reactivity/src/computed.ts b/packages/reactivity/src/computed.ts index c7f7b051554..c077d84b209 100644 --- a/packages/reactivity/src/computed.ts +++ b/packages/reactivity/src/computed.ts @@ -36,7 +36,8 @@ class ComputedRefImpl { constructor( getter: ComputedGetter, private readonly _setter: ComputedSetter, - isReadonly: boolean + isReadonly: boolean, + isSSR: boolean ) { this.effect = new ReactiveEffect(getter, () => { if (!this._dirty) { @@ -44,6 +45,7 @@ class ComputedRefImpl { triggerRefValue(this) } }) + this.effect.active = !isSSR this[ReactiveFlags.IS_READONLY] = isReadonly } @@ -73,7 +75,8 @@ export function computed( ): WritableComputedRef export function computed( getterOrOptions: ComputedGetter | WritableComputedOptions, - debugOptions?: DebuggerOptions + debugOptions?: DebuggerOptions, + isSSR = false ) { let getter: ComputedGetter let setter: ComputedSetter @@ -91,9 +94,9 @@ export function computed( setter = getterOrOptions.set } - const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter) + const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR) - if (__DEV__ && debugOptions) { + if (__DEV__ && debugOptions && !isSSR) { cRef.effect.onTrack = debugOptions.onTrack cRef.effect.onTrigger = debugOptions.onTrigger } diff --git a/packages/runtime-core/src/apiComputed.ts b/packages/runtime-core/src/apiComputed.ts new file mode 100644 index 00000000000..3804531bd44 --- /dev/null +++ b/packages/runtime-core/src/apiComputed.ts @@ -0,0 +1,7 @@ +import { computed as _computed } from '@vue/reactivity' +import { isInSSRComponentSetup } from './component' + +export const computed = ((getterOrOptions: any, debugOptions?: any) => { + // @ts-ignore + return _computed(getterOrOptions, debugOptions, isInSSRComponentSetup) +}) as typeof _computed diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 0d5e320e83f..65fc62b3e2f 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -3,7 +3,6 @@ export const version = __VERSION__ export { // core - computed, reactive, ref, readonly, @@ -34,6 +33,7 @@ export { getCurrentScope, onScopeDispose } from '@vue/reactivity' +export { computed } from './apiComputed' export { watch, watchEffect, From ed9eb62e5992bd575d999c4197330d8bad622cfb Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 16 Jan 2022 20:39:55 +0800 Subject: [PATCH 0016/2528] perf: improve memory usage for static vnodes Use the already mounted nodes as cache instead of separate caching via template. This reduces memory usage by 30%+ in VitePress. --- packages/runtime-core/src/renderer.ts | 8 +++++-- .../runtime-dom/__tests__/nodeOps.spec.ts | 23 +++++++++++++++++++ packages/runtime-dom/src/nodeOps.ts | 22 ++++++++++-------- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index 04bebdb1f0e..0a215a14b76 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -124,7 +124,9 @@ export interface RendererOptions< content: string, parent: HostElement, anchor: HostNode | null, - isSVG: boolean + isSVG: boolean, + start?: HostNode | null, + end?: HostNode | null ): [HostNode, HostNode] } @@ -511,7 +513,9 @@ function baseCreateRenderer( n2.children as string, container, anchor, - isSVG + isSVG, + n2.el, + n2.anchor ) } diff --git a/packages/runtime-dom/__tests__/nodeOps.spec.ts b/packages/runtime-dom/__tests__/nodeOps.spec.ts index 1944bf0e4f4..dcab9a0a6b9 100644 --- a/packages/runtime-dom/__tests__/nodeOps.spec.ts +++ b/packages/runtime-dom/__tests__/nodeOps.spec.ts @@ -82,5 +82,28 @@ describe('runtime-dom: node-ops', () => { expect((first as Element).namespaceURI).toMatch('svg') expect((last as Element).namespaceURI).toMatch('svg') }) + + test('cached insertion', () => { + const content = `

one
two
three` + const existing = `
existing
` + const parent = document.createElement('div') + parent.innerHTML = existing + const anchor = parent.firstChild + + const cached = document.createElement('div') + cached.innerHTML = content + + const nodes = nodeOps.insertStaticContent!( + content, + parent, + anchor, + false, + cached.firstChild, + cached.lastChild + ) + expect(parent.innerHTML).toBe(content + existing) + expect(nodes[0]).toBe(parent.firstChild) + expect(nodes[1]).toBe(parent.childNodes[parent.childNodes.length - 2]) + }) }) }) diff --git a/packages/runtime-dom/src/nodeOps.ts b/packages/runtime-dom/src/nodeOps.ts index de13d8f19d0..c3a4f4ba642 100644 --- a/packages/runtime-dom/src/nodeOps.ts +++ b/packages/runtime-dom/src/nodeOps.ts @@ -4,7 +4,7 @@ export const svgNS = 'http://www.w3.org/2000/svg' const doc = (typeof document !== 'undefined' ? document : null) as Document -const staticTemplateCache = new Map() +const templateContainer = doc && doc.createElement('template') export const nodeOps: Omit, 'patchProp'> = { insert: (child, parent, anchor) => { @@ -73,14 +73,19 @@ export const nodeOps: Omit, 'patchProp'> = { // Reason: innerHTML. // Static content here can only come from compiled templates. // As long as the user only uses trusted templates, this is safe. - insertStaticContent(content, parent, anchor, isSVG) { + insertStaticContent(content, parent, anchor, isSVG, start, end) { // before | first ... last | anchor const before = anchor ? anchor.previousSibling : parent.lastChild - let template = staticTemplateCache.get(content) - if (!template) { - const t = doc.createElement('template') - t.innerHTML = isSVG ? `${content}` : content - template = t.content + if (start && end) { + // cached + while (true) { + parent.insertBefore(start!.cloneNode(true), anchor) + if (start === end || !(start = start!.nextSibling)) break + } + } else { + // fresh insert + templateContainer.innerHTML = isSVG ? `${content}` : content + const template = templateContainer.content if (isSVG) { // remove outer svg wrapper const wrapper = template.firstChild! @@ -89,9 +94,8 @@ export const nodeOps: Omit, 'patchProp'> = { } template.removeChild(wrapper) } - staticTemplateCache.set(content, template) + parent.insertBefore(template, anchor) } - parent.insertBefore(template.cloneNode(true), anchor) return [ // first before ? before.nextSibling! : parent.firstChild!, From 3adfc0fe9435b70f149cef3f346780ae7a3f0651 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 16 Jan 2022 22:08:18 +0800 Subject: [PATCH 0017/2528] release: v3.2.27 --- CHANGELOG.md | 27 +++++++++++ package.json | 2 +- packages/compiler-core/package.json | 4 +- packages/compiler-dom/package.json | 6 +-- packages/compiler-sfc/package.json | 12 ++--- packages/compiler-ssr/package.json | 6 +-- packages/reactivity-transform/package.json | 6 +-- packages/reactivity/package.json | 4 +- packages/runtime-core/package.json | 6 +-- packages/runtime-dom/package.json | 6 +-- packages/runtime-test/package.json | 6 +-- packages/server-renderer/package.json | 8 ++-- packages/sfc-playground/package.json | 4 +- packages/shared/package.json | 2 +- packages/size-check/package.json | 2 +- packages/template-explorer/package.json | 2 +- packages/vue-compat/package.json | 4 +- packages/vue/package.json | 12 ++--- pnpm-lock.yaml | 54 +++++++++++----------- 19 files changed, 100 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d6e4dc0bb1..ab6b49460c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,30 @@ +## [3.2.27](https://github.com/vuejs/vue-next/compare/v3.2.26...v3.2.27) (2022-01-16) + + +### Bug Fixes + +* **KeepAlive:** remove cached VNode properly ([#5260](https://github.com/vuejs/vue-next/issues/5260)) ([2e3e183](https://github.com/vuejs/vue-next/commit/2e3e183b4f19c9e25865e35438653cbc9bf01afc)), closes [#5258](https://github.com/vuejs/vue-next/issues/5258) +* **reactivity-transform:** should not rewrite for...in / for...of scope variables ([7007ffb](https://github.com/vuejs/vue-next/commit/7007ffb2c796d6d56b9c8e278c54dc1cefd7b58f)) +* **sfc-playground:** hide title to avoid overlap ([#5099](https://github.com/vuejs/vue-next/issues/5099)) ([44b9527](https://github.com/vuejs/vue-next/commit/44b95276f5c086e1d88fa3c686a5f39eb5bb7821)) +* **ssr:** make computed inactive during ssr, fix memory leak ([f4f0966](https://github.com/vuejs/vue-next/commit/f4f0966b33863ac0fca6a20cf9e8ddfbb311ae87)), closes [#5208](https://github.com/vuejs/vue-next/issues/5208) +* **ssr:** remove missing ssr directive transform error ([55cc4af](https://github.com/vuejs/vue-next/commit/55cc4af25e6f4924b267620bd965e496f260d41a)) +* **types/tsx:** allow ref_for type on tsx elements ([78df8c7](https://github.com/vuejs/vue-next/commit/78df8c78c4539d2408278d1a11612b6bbc47d22f)) +* **types:** fix shallowReadonly type ([92f11d6](https://github.com/vuejs/vue-next/commit/92f11d6740929f5b591740e30ae5fba50940ec82)) +* **types:** handle ToRef ([5ac7030](https://github.com/vuejs/vue-next/commit/5ac703055fa83cb1e8a173bbd6a4d6c33707a3c3)), closes [#5188](https://github.com/vuejs/vue-next/issues/5188) +* **types:** KeepAlive match pattern should allow mixed array ([3007d5b](https://github.com/vuejs/vue-next/commit/3007d5b4cafed1da445bc498f771bd2c79eda6fc)) + + +### Features + +* **types:** simplify `ExtractPropTypes` to avoid props JSDocs being removed ([#5166](https://github.com/vuejs/vue-next/issues/5166)) ([a570b38](https://github.com/vuejs/vue-next/commit/a570b38741a7dc259772c5ccce7ea8a1638eb0bd)) + + +### Performance Improvements + +* improve memory usage for static vnodes ([ed9eb62](https://github.com/vuejs/vue-next/commit/ed9eb62e5992bd575d999c4197330d8bad622cfb)) + + + ## [3.2.26](https://github.com/vuejs/vue-next/compare/v3.2.25...v3.2.26) (2021-12-12) diff --git a/package.json b/package.json index 5fb460ccc3e..6fabb1c3bcc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "3.2.26", + "version": "3.2.27", "scripts": { "dev": "node scripts/dev.js", "build": "node scripts/build.js", diff --git a/packages/compiler-core/package.json b/packages/compiler-core/package.json index edadd90b1b5..097681e4ce7 100644 --- a/packages/compiler-core/package.json +++ b/packages/compiler-core/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-core", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/compiler-core", "main": "index.js", "module": "dist/compiler-core.esm-bundler.js", @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-core#readme", "dependencies": { - "@vue/shared": "3.2.26", + "@vue/shared": "3.2.27", "@babel/parser": "^7.16.4", "estree-walker": "^2.0.2", "source-map": "^0.6.1" diff --git a/packages/compiler-dom/package.json b/packages/compiler-dom/package.json index b2529f9bbbc..2451f6400af 100644 --- a/packages/compiler-dom/package.json +++ b/packages/compiler-dom/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-dom", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/compiler-dom", "main": "index.js", "module": "dist/compiler-dom.esm-bundler.js", @@ -37,7 +37,7 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-dom#readme", "dependencies": { - "@vue/shared": "3.2.26", - "@vue/compiler-core": "3.2.26" + "@vue/shared": "3.2.27", + "@vue/compiler-core": "3.2.27" } } diff --git a/packages/compiler-sfc/package.json b/packages/compiler-sfc/package.json index beb3ef9a2b0..f0f434d486f 100644 --- a/packages/compiler-sfc/package.json +++ b/packages/compiler-sfc/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-sfc", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/compiler-sfc", "main": "dist/compiler-sfc.cjs.js", "module": "dist/compiler-sfc.esm-browser.js", @@ -33,11 +33,11 @@ "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-sfc#readme", "dependencies": { "@babel/parser": "^7.16.4", - "@vue/compiler-core": "3.2.26", - "@vue/compiler-dom": "3.2.26", - "@vue/compiler-ssr": "3.2.26", - "@vue/reactivity-transform": "3.2.26", - "@vue/shared": "3.2.26", + "@vue/compiler-core": "3.2.27", + "@vue/compiler-dom": "3.2.27", + "@vue/compiler-ssr": "3.2.27", + "@vue/reactivity-transform": "3.2.27", + "@vue/shared": "3.2.27", "estree-walker": "^2.0.2", "magic-string": "^0.25.7", "source-map": "^0.6.1", diff --git a/packages/compiler-ssr/package.json b/packages/compiler-ssr/package.json index 5d580a56431..d0e24cfeb21 100644 --- a/packages/compiler-ssr/package.json +++ b/packages/compiler-ssr/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-ssr", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/compiler-ssr", "main": "dist/compiler-ssr.cjs.js", "types": "dist/compiler-ssr.d.ts", @@ -28,7 +28,7 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/compiler-ssr#readme", "dependencies": { - "@vue/shared": "3.2.26", - "@vue/compiler-dom": "3.2.26" + "@vue/shared": "3.2.27", + "@vue/compiler-dom": "3.2.27" } } diff --git a/packages/reactivity-transform/package.json b/packages/reactivity-transform/package.json index 73e23947f76..1ab3860ab0b 100644 --- a/packages/reactivity-transform/package.json +++ b/packages/reactivity-transform/package.json @@ -1,6 +1,6 @@ { "name": "@vue/reactivity-transform", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/reactivity-transform", "main": "dist/reactivity-transform.cjs.js", "files": [ @@ -29,8 +29,8 @@ "homepage": "https://github.com/vuejs/vue-next/tree/dev/packages/reactivity-transform#readme", "dependencies": { "@babel/parser": "^7.16.4", - "@vue/compiler-core": "3.2.26", - "@vue/shared": "3.2.26", + "@vue/compiler-core": "3.2.27", + "@vue/shared": "3.2.27", "estree-walker": "^2.0.2", "magic-string": "^0.25.7" }, diff --git a/packages/reactivity/package.json b/packages/reactivity/package.json index f799cd314a1..6ff3b7938f0 100644 --- a/packages/reactivity/package.json +++ b/packages/reactivity/package.json @@ -1,6 +1,6 @@ { "name": "@vue/reactivity", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/reactivity", "main": "index.js", "module": "dist/reactivity.esm-bundler.js", @@ -36,6 +36,6 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/reactivity#readme", "dependencies": { - "@vue/shared": "3.2.26" + "@vue/shared": "3.2.27" } } diff --git a/packages/runtime-core/package.json b/packages/runtime-core/package.json index ff5613b37bc..317c7da9b26 100644 --- a/packages/runtime-core/package.json +++ b/packages/runtime-core/package.json @@ -1,6 +1,6 @@ { "name": "@vue/runtime-core", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/runtime-core", "main": "index.js", "module": "dist/runtime-core.esm-bundler.js", @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/runtime-core#readme", "dependencies": { - "@vue/shared": "3.2.26", - "@vue/reactivity": "3.2.26" + "@vue/shared": "3.2.27", + "@vue/reactivity": "3.2.27" } } diff --git a/packages/runtime-dom/package.json b/packages/runtime-dom/package.json index 4203594c1cf..396d4fcd182 100644 --- a/packages/runtime-dom/package.json +++ b/packages/runtime-dom/package.json @@ -1,6 +1,6 @@ { "name": "@vue/runtime-dom", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/runtime-dom", "main": "index.js", "module": "dist/runtime-dom.esm-bundler.js", @@ -35,8 +35,8 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/runtime-dom#readme", "dependencies": { - "@vue/shared": "3.2.26", - "@vue/runtime-core": "3.2.26", + "@vue/shared": "3.2.27", + "@vue/runtime-core": "3.2.27", "csstype": "^2.6.8" } } diff --git a/packages/runtime-test/package.json b/packages/runtime-test/package.json index 10cf10eac9f..23dd5933a1b 100644 --- a/packages/runtime-test/package.json +++ b/packages/runtime-test/package.json @@ -1,6 +1,6 @@ { "name": "@vue/runtime-test", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/runtime-test", "private": true, "main": "index.js", @@ -25,7 +25,7 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/runtime-test#readme", "dependencies": { - "@vue/shared": "3.2.26", - "@vue/runtime-core": "3.2.26" + "@vue/shared": "3.2.27", + "@vue/runtime-core": "3.2.27" } } diff --git a/packages/server-renderer/package.json b/packages/server-renderer/package.json index 0c9eec993c4..90754109125 100644 --- a/packages/server-renderer/package.json +++ b/packages/server-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@vue/server-renderer", - "version": "3.2.26", + "version": "3.2.27", "description": "@vue/server-renderer", "main": "index.js", "module": "dist/server-renderer.esm-bundler.js", @@ -31,10 +31,10 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/server-renderer#readme", "peerDependencies": { - "vue": "3.2.26" + "vue": "3.2.27" }, "dependencies": { - "@vue/shared": "3.2.26", - "@vue/compiler-ssr": "3.2.26" + "@vue/shared": "3.2.27", + "@vue/compiler-ssr": "3.2.27" } } diff --git a/packages/sfc-playground/package.json b/packages/sfc-playground/package.json index fb2178283f0..30d76c9af81 100644 --- a/packages/sfc-playground/package.json +++ b/packages/sfc-playground/package.json @@ -1,6 +1,6 @@ { "name": "@vue/sfc-playground", - "version": "3.2.26", + "version": "3.2.27", "private": true, "scripts": { "dev": "vite", @@ -12,7 +12,7 @@ "vite": "^2.7.1" }, "dependencies": { - "vue": "3.2.26", + "vue": "3.2.27", "@vue/repl": "^0.4.8", "file-saver": "^2.0.5", "jszip": "^3.6.0" diff --git a/packages/shared/package.json b/packages/shared/package.json index a41f9c5fd57..08bd54d15f3 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@vue/shared", - "version": "3.2.26", + "version": "3.2.27", "description": "internal utils shared across @vue packages", "main": "index.js", "module": "dist/shared.esm-bundler.js", diff --git a/packages/size-check/package.json b/packages/size-check/package.json index 3789b7c9096..1bbb29bbee2 100644 --- a/packages/size-check/package.json +++ b/packages/size-check/package.json @@ -1,6 +1,6 @@ { "name": "@vue/size-check", - "version": "3.2.26", + "version": "3.2.27", "private": true, "scripts": { "build": "vite build" diff --git a/packages/template-explorer/package.json b/packages/template-explorer/package.json index 338d6987874..05c02976c74 100644 --- a/packages/template-explorer/package.json +++ b/packages/template-explorer/package.json @@ -1,6 +1,6 @@ { "name": "@vue/template-explorer", - "version": "3.2.26", + "version": "3.2.27", "private": true, "buildOptions": { "formats": [ diff --git a/packages/vue-compat/package.json b/packages/vue-compat/package.json index 7795b639f23..753c56502a3 100644 --- a/packages/vue-compat/package.json +++ b/packages/vue-compat/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compat", - "version": "3.2.26", + "version": "3.2.27", "description": "Vue 3 compatibility build for Vue 2", "main": "index.js", "module": "dist/vue.runtime.esm-bundler.js", @@ -38,6 +38,6 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/vue-compat#readme", "peerDependencies": { - "vue": "3.2.26" + "vue": "3.2.27" } } diff --git a/packages/vue/package.json b/packages/vue/package.json index e31b4aaa476..d62b1bb768e 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -1,6 +1,6 @@ { "name": "vue", - "version": "3.2.26", + "version": "3.2.27", "description": "The progressive JavaScript framework for building modern web UI.", "main": "index.js", "module": "dist/vue.runtime.esm-bundler.js", @@ -66,10 +66,10 @@ }, "homepage": "https://github.com/vuejs/vue-next/tree/master/packages/vue#readme", "dependencies": { - "@vue/shared": "3.2.26", - "@vue/compiler-dom": "3.2.26", - "@vue/runtime-dom": "3.2.26", - "@vue/compiler-sfc": "3.2.26", - "@vue/server-renderer": "3.2.26" + "@vue/shared": "3.2.27", + "@vue/compiler-dom": "3.2.27", + "@vue/runtime-dom": "3.2.27", + "@vue/compiler-sfc": "3.2.27", + "@vue/server-renderer": "3.2.27" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 714ed713382..79f5d796420 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -104,7 +104,7 @@ importers: specifiers: '@babel/parser': ^7.16.4 '@babel/types': ^7.16.0 - '@vue/shared': 3.2.26 + '@vue/shared': 3.2.27 estree-walker: ^2.0.2 source-map: ^0.6.1 dependencies: @@ -117,8 +117,8 @@ importers: packages/compiler-dom: specifiers: - '@vue/compiler-core': 3.2.26 - '@vue/shared': 3.2.26 + '@vue/compiler-core': 3.2.27 + '@vue/shared': 3.2.27 dependencies: '@vue/compiler-core': link:../compiler-core '@vue/shared': link:../shared @@ -129,12 +129,12 @@ importers: '@babel/types': ^7.16.0 '@types/estree': ^0.0.48 '@types/lru-cache': ^5.1.0 - '@vue/compiler-core': 3.2.26 - '@vue/compiler-dom': 3.2.26 - '@vue/compiler-ssr': 3.2.26 + '@vue/compiler-core': 3.2.27 + '@vue/compiler-dom': 3.2.27 + '@vue/compiler-ssr': 3.2.27 '@vue/consolidate': ^0.17.3 - '@vue/reactivity-transform': 3.2.26 - '@vue/shared': 3.2.26 + '@vue/reactivity-transform': 3.2.27 + '@vue/shared': 3.2.27 estree-walker: ^2.0.2 hash-sum: ^2.0.0 lru-cache: ^5.1.1 @@ -172,15 +172,15 @@ importers: packages/compiler-ssr: specifiers: - '@vue/compiler-dom': 3.2.26 - '@vue/shared': 3.2.26 + '@vue/compiler-dom': 3.2.27 + '@vue/shared': 3.2.27 dependencies: '@vue/compiler-dom': link:../compiler-dom '@vue/shared': link:../shared packages/reactivity: specifiers: - '@vue/shared': 3.2.26 + '@vue/shared': 3.2.27 dependencies: '@vue/shared': link:../shared @@ -189,8 +189,8 @@ importers: '@babel/core': ^7.16.0 '@babel/parser': ^7.16.4 '@babel/types': ^7.16.0 - '@vue/compiler-core': 3.2.26 - '@vue/shared': 3.2.26 + '@vue/compiler-core': 3.2.27 + '@vue/shared': 3.2.27 estree-walker: ^2.0.2 magic-string: ^0.25.7 dependencies: @@ -205,16 +205,16 @@ importers: packages/runtime-core: specifiers: - '@vue/reactivity': 3.2.26 - '@vue/shared': 3.2.26 + '@vue/reactivity': 3.2.27 + '@vue/shared': 3.2.27 dependencies: '@vue/reactivity': link:../reactivity '@vue/shared': link:../shared packages/runtime-dom: specifiers: - '@vue/runtime-core': 3.2.26 - '@vue/shared': 3.2.26 + '@vue/runtime-core': 3.2.27 + '@vue/shared': 3.2.27 csstype: ^2.6.8 dependencies: '@vue/runtime-core': link:../runtime-core @@ -223,16 +223,16 @@ importers: packages/runtime-test: specifiers: - '@vue/runtime-core': 3.2.26 - '@vue/shared': 3.2.26 + '@vue/runtime-core': 3.2.27 + '@vue/shared': 3.2.27 dependencies: '@vue/runtime-core': link:../runtime-core '@vue/shared': link:../shared packages/server-renderer: specifiers: - '@vue/compiler-ssr': 3.2.26 - '@vue/shared': 3.2.26 + '@vue/compiler-ssr': 3.2.27 + '@vue/shared': 3.2.27 dependencies: '@vue/compiler-ssr': link:../compiler-ssr '@vue/shared': link:../shared @@ -244,7 +244,7 @@ importers: file-saver: ^2.0.5 jszip: ^3.6.0 vite: ^2.7.1 - vue: 3.2.26 + vue: 3.2.27 dependencies: '@vue/repl': 0.4.8 file-saver: 2.0.5 @@ -270,11 +270,11 @@ importers: packages/vue: specifiers: - '@vue/compiler-dom': 3.2.26 - '@vue/compiler-sfc': 3.2.26 - '@vue/runtime-dom': 3.2.26 - '@vue/server-renderer': 3.2.26 - '@vue/shared': 3.2.26 + '@vue/compiler-dom': 3.2.27 + '@vue/compiler-sfc': 3.2.27 + '@vue/runtime-dom': 3.2.27 + '@vue/server-renderer': 3.2.27 + '@vue/shared': 3.2.27 dependencies: '@vue/compiler-dom': link:../compiler-dom '@vue/compiler-sfc': link:../compiler-sfc From 8cbfe092cf9c517e79365151d6a7994c36fbe7c8 Mon Sep 17 00:00:00 2001 From: JayFate <48240828+JayFate@users.noreply.github.com> Date: Tue, 18 Jan 2022 07:34:47 +0800 Subject: [PATCH 0018/2528] docs(contributing): missing structure info for compiler-sfc (#3559) [ci skip] --- .github/contributing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/contributing.md b/.github/contributing.md index 2b0995a1ef1..773b942a51a 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -178,6 +178,8 @@ This repository employs a [monorepo](https://en.wikipedia.org/wiki/Monorepo) set - `compiler-dom`: Compiler with additional plugins specifically targeting the browser. +- `compiler-sfc`: Lower level utilities for compiling Vue Single File Components. + - `compiler-ssr`: Compiler that produces render functions optimized for server-side rendering. - `template-explorer`: A development tool for debugging compiler output. You can run `nr dev template-explorer` and open its `index.html` to get a repl of template compilation based on current source code. From 0c06c748a511f2e7c38f8a6fb13b99561312d15e Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 18 Jan 2022 07:57:00 +0800 Subject: [PATCH 0019/2528] chore: bump marked --- package.json | 2 +- packages/vue/examples/classic/markdown.html | 2 +- packages/vue/examples/composition/markdown.html | 2 +- pnpm-lock.yaml | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 6fabb1c3bcc..de73907e213 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "jest": "^27.1.0", "lint-staged": "^10.2.10", "lodash": "^4.17.15", - "marked": "^0.7.0", + "marked": "^4.0.10", "minimist": "^1.2.0", "npm-run-all": "^4.1.5", "prettier": "^2.3.1", diff --git a/packages/vue/examples/classic/markdown.html b/packages/vue/examples/classic/markdown.html index 61e64f6e3cb..f70a75d692e 100644 --- a/packages/vue/examples/classic/markdown.html +++ b/packages/vue/examples/classic/markdown.html @@ -14,7 +14,7 @@ }), computed: { compiledMarkdown() { - return marked(this.input, { sanitize: true }) + return marked.marked(this.input, { sanitize: true }) } }, methods: { diff --git a/packages/vue/examples/composition/markdown.html b/packages/vue/examples/composition/markdown.html index 8734cf6aed2..151a8a8c141 100644 --- a/packages/vue/examples/composition/markdown.html +++ b/packages/vue/examples/composition/markdown.html @@ -13,7 +13,7 @@ Vue.createApp({ setup() { const input = ref('# hello') - const output = computed(() => marked(input.value, { sanitize: true })) + const output = computed(() => marked.marked(input.value, { sanitize: true })) const update = _.debounce(e => { input.value = e.target.value }, 50) return { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79f5d796420..424319db61a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,7 +31,7 @@ importers: jest: ^27.1.0 lint-staged: ^10.2.10 lodash: ^4.17.15 - marked: ^0.7.0 + marked: ^4.0.10 minimist: ^1.2.0 npm-run-all: ^4.1.5 prettier: ^2.3.1 @@ -79,7 +79,7 @@ importers: jest: 27.4.4 lint-staged: 10.5.4 lodash: 4.17.21 - marked: 0.7.0 + marked: 4.0.10 minimist: 1.2.5 npm-run-all: 4.1.5 prettier: 2.5.1 @@ -4978,9 +4978,9 @@ packages: engines: {node: '>=8'} dev: true - /marked/0.7.0: - resolution: {integrity: sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg==} - engines: {node: '>=0.10.0'} + /marked/4.0.10: + resolution: {integrity: sha512-+QvuFj0nGgO970fySghXGmuw+Fd0gD2x3+MqCWLIPf5oxdv1Ka6b2q+z9RP01P/IaKPMEramy+7cNy/Lw8c3hw==} + engines: {node: '>= 12'} hasBin: true dev: true From 9fda9411ec92dc703288b229106116dd0f16e5e7 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 18 Jan 2022 09:17:22 +0800 Subject: [PATCH 0020/2528] feat(reactivity): add isShallow api --- packages/reactivity/__tests__/ref.spec.ts | 5 +++++ .../reactivity/__tests__/shallowReactive.spec.ts | 13 ++++++++++++- packages/reactivity/src/baseHandlers.ts | 2 ++ packages/reactivity/src/index.ts | 1 + packages/reactivity/src/reactive.ts | 8 +++++++- packages/reactivity/src/ref.ts | 14 +++++--------- packages/runtime-core/src/apiWatch.ts | 3 ++- packages/runtime-core/src/customFormatter.ts | 7 ++++--- packages/runtime-core/src/index.ts | 1 + 9 files changed, 39 insertions(+), 15 deletions(-) diff --git a/packages/reactivity/__tests__/ref.spec.ts b/packages/reactivity/__tests__/ref.spec.ts index 0db801a5a42..2451c43ab45 100644 --- a/packages/reactivity/__tests__/ref.spec.ts +++ b/packages/reactivity/__tests__/ref.spec.ts @@ -10,6 +10,7 @@ import { } from '../src/index' import { computed } from '@vue/runtime-dom' import { shallowRef, unref, customRef, triggerRef } from '../src/ref' +import { isShallow } from '../src/reactive' describe('reactivity/ref', () => { it('should hold a value', () => { @@ -227,6 +228,10 @@ describe('reactivity/ref', () => { expect(dummy).toBe(2) }) + test('shallowRef isShallow', () => { + expect(isShallow(shallowRef({ a: 1 }))).toBe(true) + }) + test('isRef', () => { expect(isRef(ref(1))).toBe(true) expect(isRef(computed(() => 1))).toBe(true) diff --git a/packages/reactivity/__tests__/shallowReactive.spec.ts b/packages/reactivity/__tests__/shallowReactive.spec.ts index cfd870dc002..f7c7e07b055 100644 --- a/packages/reactivity/__tests__/shallowReactive.spec.ts +++ b/packages/reactivity/__tests__/shallowReactive.spec.ts @@ -1,4 +1,10 @@ -import { isReactive, reactive, shallowReactive } from '../src/reactive' +import { + isReactive, + isShallow, + reactive, + shallowReactive, + shallowReadonly +} from '../src/reactive' import { effect } from '../src/effect' @@ -24,6 +30,11 @@ describe('shallowReactive', () => { expect(isReactive(reactiveProxy.foo)).toBe(true) }) + test('isShallow', () => { + expect(isShallow(shallowReactive({}))).toBe(true) + expect(isShallow(shallowReadonly({}))).toBe(true) + }) + describe('collections', () => { test('should be reactive', () => { const shallowSet = shallowReactive(new Set()) diff --git a/packages/reactivity/src/baseHandlers.ts b/packages/reactivity/src/baseHandlers.ts index 0fa1c4bc2ea..3d2ba661973 100644 --- a/packages/reactivity/src/baseHandlers.ts +++ b/packages/reactivity/src/baseHandlers.ts @@ -84,6 +84,8 @@ function createGetter(isReadonly = false, shallow = false) { return !isReadonly } else if (key === ReactiveFlags.IS_READONLY) { return isReadonly + } else if (key === ReactiveFlags.IS_SHALLOW) { + return shallow } else if ( key === ReactiveFlags.RAW && receiver === diff --git a/packages/reactivity/src/index.ts b/packages/reactivity/src/index.ts index 676f8598fb3..a7a03b8c573 100644 --- a/packages/reactivity/src/index.ts +++ b/packages/reactivity/src/index.ts @@ -22,6 +22,7 @@ export { readonly, isReactive, isReadonly, + isShallow, isProxy, shallowReactive, shallowReadonly, diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index 4716230e40f..7d7e591fc4a 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -17,6 +17,7 @@ export const enum ReactiveFlags { SKIP = '__v_skip', IS_REACTIVE = '__v_isReactive', IS_READONLY = '__v_isReadonly', + IS_SHALLOW = '__v_isShallow', RAW = '__v_raw' } @@ -24,6 +25,7 @@ export interface Target { [ReactiveFlags.SKIP]?: boolean [ReactiveFlags.IS_REACTIVE]?: boolean [ReactiveFlags.IS_READONLY]?: boolean + [ReactiveFlags.IS_SHALLOW]?: boolean [ReactiveFlags.RAW]?: any } @@ -87,7 +89,7 @@ export type UnwrapNestedRefs = T extends Ref ? T : UnwrapRefSimple export function reactive(target: T): UnwrapNestedRefs export function reactive(target: object) { // if trying to observe a readonly proxy, return the readonly version. - if (target && (target as Target)[ReactiveFlags.IS_READONLY]) { + if (isReadonly(target)) { return target } return createReactiveObject( @@ -226,6 +228,10 @@ export function isReadonly(value: unknown): boolean { return !!(value && (value as Target)[ReactiveFlags.IS_READONLY]) } +export function isShallow(value: unknown): boolean { + return !!(value && (value as Target)[ReactiveFlags.IS_SHALLOW]) +} + export function isProxy(value: unknown): boolean { return isReactive(value) || isReadonly(value) } diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index c972676ac42..20aa6c0a989 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -16,10 +16,6 @@ export interface Ref { * autocomplete, so we use a private Symbol instead. */ [RefSymbol]: true - /** - * @internal - */ - _shallow?: boolean } type RefBase = { @@ -102,9 +98,9 @@ class RefImpl { public dep?: Dep = undefined public readonly __v_isRef = true - constructor(value: T, public readonly _shallow: boolean) { - this._rawValue = _shallow ? value : toRaw(value) - this._value = _shallow ? value : toReactive(value) + constructor(value: T, public readonly __v_isShallow: boolean) { + this._rawValue = __v_isShallow ? value : toRaw(value) + this._value = __v_isShallow ? value : toReactive(value) } get value() { @@ -113,10 +109,10 @@ class RefImpl { } set value(newVal) { - newVal = this._shallow ? newVal : toRaw(newVal) + newVal = this.__v_isShallow ? newVal : toRaw(newVal) if (hasChanged(newVal, this._rawValue)) { this._rawValue = newVal - this._value = this._shallow ? newVal : toReactive(newVal) + this._value = this.__v_isShallow ? newVal : toReactive(newVal) triggerRefValue(this, newVal) } } diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index b26c3ee2388..fd09c7434e3 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -1,5 +1,6 @@ import { isRef, + isShallow, Ref, ComputedRef, ReactiveEffect, @@ -205,7 +206,7 @@ function doWatch( if (isRef(source)) { getter = () => source.value - forceTrigger = !!source._shallow + forceTrigger = isShallow(source) } else if (isReactive(source)) { getter = () => source deep = true diff --git a/packages/runtime-core/src/customFormatter.ts b/packages/runtime-core/src/customFormatter.ts index e628f75bad4..768240feb62 100644 --- a/packages/runtime-core/src/customFormatter.ts +++ b/packages/runtime-core/src/customFormatter.ts @@ -1,5 +1,6 @@ import { isReactive, isReadonly, isRef, Ref, toRaw } from '@vue/reactivity' import { EMPTY_OBJ, extend, isArray, isFunction, isObject } from '@vue/shared' +import { isShallow } from '../../reactivity/src/reactive' import { ComponentInternalInstance, ComponentOptions } from './component' import { ComponentPublicInstance } from './componentPublicInstance' @@ -38,7 +39,7 @@ export function initCustomFormatter() { return [ 'div', {}, - ['span', vueStyle, 'Reactive'], + ['span', vueStyle, isShallow(obj) ? 'ShallowReactive' : 'Reactive'], '<', formatValue(obj), `>${isReadonly(obj) ? ` (readonly)` : ``}` @@ -47,7 +48,7 @@ export function initCustomFormatter() { return [ 'div', {}, - ['span', vueStyle, 'Readonly'], + ['span', vueStyle, isShallow(obj) ? 'ShallowReadonly' : 'Readonly'], '<', formatValue(obj), '>' @@ -181,7 +182,7 @@ export function initCustomFormatter() { } function genRefFlag(v: Ref) { - if (v._shallow) { + if (isShallow(v)) { return `ShallowRef` } if ((v as any).effect) { diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 65fc62b3e2f..ad4817d91b9 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -15,6 +15,7 @@ export { isProxy, isReactive, isReadonly, + isShallow, // advanced customRef, triggerRef, From 9c304bfe7942a20264235865b4bb5f6e53fdee0d Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 18 Jan 2022 09:22:03 +0800 Subject: [PATCH 0021/2528] fix(reactivity): differentiate shallow/deep proxies of same target when nested in reactive fix #5271 --- .../__tests__/shallowReactive.spec.ts | 20 +++++++++++++++++++ packages/reactivity/src/baseHandlers.ts | 9 ++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/reactivity/__tests__/shallowReactive.spec.ts b/packages/reactivity/__tests__/shallowReactive.spec.ts index f7c7e07b055..200aa462496 100644 --- a/packages/reactivity/__tests__/shallowReactive.spec.ts +++ b/packages/reactivity/__tests__/shallowReactive.spec.ts @@ -35,6 +35,26 @@ describe('shallowReactive', () => { expect(isShallow(shallowReadonly({}))).toBe(true) }) + // #5271 + test('should respect shallow reactive nested inside reactive on reset', () => { + const r = reactive({ foo: shallowReactive({ bar: {} }) }) + expect(isShallow(r.foo)).toBe(true) + expect(isReactive(r.foo.bar)).toBe(false) + + r.foo = shallowReactive({ bar: {} }) + expect(isShallow(r.foo)).toBe(true) + expect(isReactive(r.foo.bar)).toBe(false) + }) + + test('should respect shallow/deep versions of same target on access', () => { + const original = {} + const shallow = shallowReactive(original) + const deep = reactive(original) + const r = reactive({ shallow, deep }) + expect(r.shallow).toBe(shallow) + expect(r.deep).toBe(deep) + }) + describe('collections', () => { test('should be reactive', () => { const shallowSet = shallowReactive(new Set()) diff --git a/packages/reactivity/src/baseHandlers.ts b/packages/reactivity/src/baseHandlers.ts index 3d2ba661973..97acf063f67 100644 --- a/packages/reactivity/src/baseHandlers.ts +++ b/packages/reactivity/src/baseHandlers.ts @@ -8,7 +8,8 @@ import { reactiveMap, shallowReactiveMap, shallowReadonlyMap, - isReadonly + isReadonly, + isShallow } from './reactive' import { TrackOpTypes, TriggerOpTypes } from './operations' import { @@ -150,8 +151,10 @@ function createSetter(shallow = false) { ): boolean { let oldValue = (target as any)[key] if (!shallow && !isReadonly(value)) { - value = toRaw(value) - oldValue = toRaw(oldValue) + if (!isShallow(value)) { + value = toRaw(value) + oldValue = toRaw(oldValue) + } if (!isArray(target) && isRef(oldValue) && !isRef(value)) { oldValue.value = value return true From ae4b0783d78670b6e942ae2a4e3ec6efbbffa158 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 18 Jan 2022 16:43:59 +0800 Subject: [PATCH 0022/2528] chore: update repo references --- .github/ISSUE_TEMPLATE/config.yml | 2 +- .github/contributing.md | 6 +- .github/workflows/ci.yml | 2 +- .github/workflows/release-tag.yml | 2 +- CHANGELOG.md | 2862 ++++++++--------- README.md | 107 +- .../compiler-core/__tests__/parse.spec.ts | 2 +- packages/compiler-core/package.json | 6 +- packages/compiler-core/src/parse.ts | 2 +- packages/compiler-dom/package.json | 6 +- .../__tests__/compileScript.spec.ts | 2 +- packages/compiler-sfc/package.json | 6 +- packages/compiler-ssr/package.json | 6 +- packages/reactivity-transform/package.json | 6 +- .../reactivity/__tests__/readonly.spec.ts | 2 +- packages/reactivity/package.json | 6 +- .../runtime-core/__tests__/apiWatch.spec.ts | 2 +- packages/runtime-core/package.json | 6 +- .../runtime-core/src/compat/compatConfig.ts | 2 +- .../runtime-core/src/compat/globalConfig.ts | 2 +- packages/runtime-core/src/errorHandling.ts | 2 +- .../runtime-dom/__tests__/patchProps.spec.ts | 2 +- packages/runtime-dom/package.json | 6 +- packages/runtime-test/package.json | 6 +- .../server-renderer/__tests__/render.spec.ts | 2 +- packages/server-renderer/package.json | 6 +- packages/sfc-playground/src/Header.vue | 4 +- packages/shared/package.json | 6 +- packages/template-explorer/src/options.ts | 2 +- packages/vue-compat/README.md | 4 +- packages/vue-compat/package.json | 6 +- .../vue/examples/__tests__/commits.mock.ts | 84 +- packages/vue/examples/classic/commits.html | 2 +- .../vue/examples/composition/commits.html | 2 +- packages/vue/package.json | 6 +- 35 files changed, 1543 insertions(+), 1634 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index ac8a00ef158..d331b5312a9 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,7 +1,7 @@ blank_issues_enabled: false contact_links: - name: Create new issue - url: https://new-issue.vuejs.org/?repo=vuejs/vue-next + url: https://new-issue.vuejs.org/?repo=vuejs/core about: Please use the following link to create a new issue. - name: Patreon url: https://www.patreon.com/evanyou diff --git a/.github/contributing.md b/.github/contributing.md index 773b942a51a..b85198c3d1b 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -2,7 +2,7 @@ Hi! I'm really excited that you are interested in contributing to Vue.js. Before submitting your contribution, please make sure to take a moment and read through the following guidelines: -- [Code of Conduct](https://github.com/vuejs/vue/blob/dev/.github/CODE_OF_CONDUCT.md) +- [Code of Conduct](https://vuejs.org/about/coc.html) - [Issue Reporting Guidelines](#issue-reporting-guidelines) - [Pull Request Guidelines](#pull-request-guidelines) - [Development Setup](#development-setup) @@ -90,7 +90,7 @@ Additional formats that only apply to the main `vue` package: - **`esm-bundler-runtime`** - **`esm-browser-runtime`** -More details about each of these formats can be found in the [`vue` package README](https://github.com/vuejs/vue-next/blob/master/packages/vue/README.md#which-dist-file-to-use) and the [Rollup config file](https://github.com/vuejs/vue-next/blob/master/rollup.config.js). +More details about each of these formats can be found in the [`vue` package README](https://github.com/vuejs/core/blob/main/packages/vue/README.md#which-dist-file-to-use) and the [Rollup config file](https://github.com/vuejs/core/blob/main/rollup.config.js). For example, to build `runtime-core` with the global build only: @@ -138,7 +138,7 @@ $ nr dev ### `nr dev-compiler` -The `dev-compiler` script builds, watches and serves the [Template Explorer](https://github.com/vuejs/vue-next/tree/master/packages/template-explorer) at `http://localhost:5000`. This is extremely useful when working on the compiler. +The `dev-compiler` script builds, watches and serves the [Template Explorer](https://github.com/vuejs/core/tree/main/packages/template-explorer) at `http://localhost:5000`. This is extremely useful when working on the compiler. ### `nr test` diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 085c8dbbd6c..0e02bfc6627 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ on: - '**' pull_request: branches: - - master + - main jobs: test: runs-on: ubuntu-latest diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml index 8781b44c872..d9ea7a07f72 100644 --- a/.github/workflows/release-tag.yml +++ b/.github/workflows/release-tag.yml @@ -20,4 +20,4 @@ jobs: with: tag_name: ${{ github.ref }} body: | - Please refer to [CHANGELOG.md](https://github.com/vuejs/vue-next/blob/master/CHANGELOG.md) for details. + Please refer to [CHANGELOG.md](https://github.com/vuejs/core/blob/main/CHANGELOG.md) for details. diff --git a/CHANGELOG.md b/CHANGELOG.md index ab6b49460c6..f84611f4dae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,407 +1,407 @@ -## [3.2.27](https://github.com/vuejs/vue-next/compare/v3.2.26...v3.2.27) (2022-01-16) +## [3.2.27](https://github.com/vuejs/core/compare/v3.2.26...v3.2.27) (2022-01-16) ### Bug Fixes -* **KeepAlive:** remove cached VNode properly ([#5260](https://github.com/vuejs/vue-next/issues/5260)) ([2e3e183](https://github.com/vuejs/vue-next/commit/2e3e183b4f19c9e25865e35438653cbc9bf01afc)), closes [#5258](https://github.com/vuejs/vue-next/issues/5258) -* **reactivity-transform:** should not rewrite for...in / for...of scope variables ([7007ffb](https://github.com/vuejs/vue-next/commit/7007ffb2c796d6d56b9c8e278c54dc1cefd7b58f)) -* **sfc-playground:** hide title to avoid overlap ([#5099](https://github.com/vuejs/vue-next/issues/5099)) ([44b9527](https://github.com/vuejs/vue-next/commit/44b95276f5c086e1d88fa3c686a5f39eb5bb7821)) -* **ssr:** make computed inactive during ssr, fix memory leak ([f4f0966](https://github.com/vuejs/vue-next/commit/f4f0966b33863ac0fca6a20cf9e8ddfbb311ae87)), closes [#5208](https://github.com/vuejs/vue-next/issues/5208) -* **ssr:** remove missing ssr directive transform error ([55cc4af](https://github.com/vuejs/vue-next/commit/55cc4af25e6f4924b267620bd965e496f260d41a)) -* **types/tsx:** allow ref_for type on tsx elements ([78df8c7](https://github.com/vuejs/vue-next/commit/78df8c78c4539d2408278d1a11612b6bbc47d22f)) -* **types:** fix shallowReadonly type ([92f11d6](https://github.com/vuejs/vue-next/commit/92f11d6740929f5b591740e30ae5fba50940ec82)) -* **types:** handle ToRef ([5ac7030](https://github.com/vuejs/vue-next/commit/5ac703055fa83cb1e8a173bbd6a4d6c33707a3c3)), closes [#5188](https://github.com/vuejs/vue-next/issues/5188) -* **types:** KeepAlive match pattern should allow mixed array ([3007d5b](https://github.com/vuejs/vue-next/commit/3007d5b4cafed1da445bc498f771bd2c79eda6fc)) +* **KeepAlive:** remove cached VNode properly ([#5260](https://github.com/vuejs/core/issues/5260)) ([2e3e183](https://github.com/vuejs/core/commit/2e3e183b4f19c9e25865e35438653cbc9bf01afc)), closes [#5258](https://github.com/vuejs/core/issues/5258) +* **reactivity-transform:** should not rewrite for...in / for...of scope variables ([7007ffb](https://github.com/vuejs/core/commit/7007ffb2c796d6d56b9c8e278c54dc1cefd7b58f)) +* **sfc-playground:** hide title to avoid overlap ([#5099](https://github.com/vuejs/core/issues/5099)) ([44b9527](https://github.com/vuejs/core/commit/44b95276f5c086e1d88fa3c686a5f39eb5bb7821)) +* **ssr:** make computed inactive during ssr, fix memory leak ([f4f0966](https://github.com/vuejs/core/commit/f4f0966b33863ac0fca6a20cf9e8ddfbb311ae87)), closes [#5208](https://github.com/vuejs/core/issues/5208) +* **ssr:** remove missing ssr directive transform error ([55cc4af](https://github.com/vuejs/core/commit/55cc4af25e6f4924b267620bd965e496f260d41a)) +* **types/tsx:** allow ref_for type on tsx elements ([78df8c7](https://github.com/vuejs/core/commit/78df8c78c4539d2408278d1a11612b6bbc47d22f)) +* **types:** fix shallowReadonly type ([92f11d6](https://github.com/vuejs/core/commit/92f11d6740929f5b591740e30ae5fba50940ec82)) +* **types:** handle ToRef ([5ac7030](https://github.com/vuejs/core/commit/5ac703055fa83cb1e8a173bbd6a4d6c33707a3c3)), closes [#5188](https://github.com/vuejs/core/issues/5188) +* **types:** KeepAlive match pattern should allow mixed array ([3007d5b](https://github.com/vuejs/core/commit/3007d5b4cafed1da445bc498f771bd2c79eda6fc)) ### Features -* **types:** simplify `ExtractPropTypes` to avoid props JSDocs being removed ([#5166](https://github.com/vuejs/vue-next/issues/5166)) ([a570b38](https://github.com/vuejs/vue-next/commit/a570b38741a7dc259772c5ccce7ea8a1638eb0bd)) +* **types:** simplify `ExtractPropTypes` to avoid props JSDocs being removed ([#5166](https://github.com/vuejs/core/issues/5166)) ([a570b38](https://github.com/vuejs/core/commit/a570b38741a7dc259772c5ccce7ea8a1638eb0bd)) ### Performance Improvements -* improve memory usage for static vnodes ([ed9eb62](https://github.com/vuejs/vue-next/commit/ed9eb62e5992bd575d999c4197330d8bad622cfb)) +* improve memory usage for static vnodes ([ed9eb62](https://github.com/vuejs/core/commit/ed9eb62e5992bd575d999c4197330d8bad622cfb)) -## [3.2.26](https://github.com/vuejs/vue-next/compare/v3.2.25...v3.2.26) (2021-12-12) +## [3.2.26](https://github.com/vuejs/core/compare/v3.2.25...v3.2.26) (2021-12-12) -## [3.2.25](https://github.com/vuejs/vue-next/compare/v3.2.24...v3.2.25) (2021-12-12) +## [3.2.25](https://github.com/vuejs/core/compare/v3.2.24...v3.2.25) (2021-12-12) ### Bug Fixes -* **compiler-sfc:** generate valid TS in script and script setup co-usage with TS ([7e4f0a8](https://github.com/vuejs/vue-next/commit/7e4f0a869498e7dce601e7c150f402045ea2e79b)), closes [#5094](https://github.com/vuejs/vue-next/issues/5094) -* **compiler:** force block for custom dirs and inline beforeUpdate hooks ([1c9a481](https://github.com/vuejs/vue-next/commit/1c9a4810fcdd2b6c1c6c3be077aebbecbfcbcf1e)) -* **runtime-core:** disallow recurse in vnode/directive beforeUpdate hooks ([a1167c5](https://github.com/vuejs/vue-next/commit/a1167c57e5514be57505f4bce8d163aa1f92cf14)) +* **compiler-sfc:** generate valid TS in script and script setup co-usage with TS ([7e4f0a8](https://github.com/vuejs/core/commit/7e4f0a869498e7dce601e7c150f402045ea2e79b)), closes [#5094](https://github.com/vuejs/core/issues/5094) +* **compiler:** force block for custom dirs and inline beforeUpdate hooks ([1c9a481](https://github.com/vuejs/core/commit/1c9a4810fcdd2b6c1c6c3be077aebbecbfcbcf1e)) +* **runtime-core:** disallow recurse in vnode/directive beforeUpdate hooks ([a1167c5](https://github.com/vuejs/core/commit/a1167c57e5514be57505f4bce8d163aa1f92cf14)) ### Features -* **compiler-core:** support aliasing vue: prefixed events to inline vnode hooks ([4b0ca87](https://github.com/vuejs/vue-next/commit/4b0ca8709a7e2652f4b02665f378d47ba4dbe969)) -* **experimental:** allow const for ref sugar declarations ([9823bd9](https://github.com/vuejs/vue-next/commit/9823bd95d11f22f0ae53f5e0b705a21b6e6e8859)) -* **reactivity-transform/types:** restructure macro types + export types for all shorthand methods ([db729ce](https://github.com/vuejs/vue-next/commit/db729ce99eb13cd18dad600055239c63edd9cfb8)) -* **reactivity-transform:** $$() escape for destructured prop bindings ([198ca14](https://github.com/vuejs/vue-next/commit/198ca14f192f9eb80028153f3d36600e636de3f0)) -* **reactivity-transform:** rename @vue/ref-transform to @vue/reactivity-transform ([d70fd8d](https://github.com/vuejs/vue-next/commit/d70fd8d36b23c987f2ebe3280da785f4d2e7d2ef)) -* **reactivity-transform:** support $-shorthands for all ref-creating APIs ([179fc05](https://github.com/vuejs/vue-next/commit/179fc05a8406eac525c8450153b42fcb5af7d6bb)) -* **reactivity-transform:** support optionally importing macros ([fbd0fe9](https://github.com/vuejs/vue-next/commit/fbd0fe97595f759e12e445c713b732775589fabf)) -* **reactivity-transform:** use toRef() for $() destructure codegen ([93ba6b9](https://github.com/vuejs/vue-next/commit/93ba6b974e4a2ff4ba004fef47ef69cfe980c654)) -* **reactivity:** support default value in toRef() ([2db9c90](https://github.com/vuejs/vue-next/commit/2db9c909c2cf3845f57b2c930c05cd6c17abe3b0)) -* **sfc-playground:** add github link ([#5067](https://github.com/vuejs/vue-next/issues/5067)) ([9ac0dde](https://github.com/vuejs/vue-next/commit/9ac0ddea4beec1a1c4471463d3476ccd019bd84e)) -* **sfc-playground:** prevent ctrl+s default behavior ([#5066](https://github.com/vuejs/vue-next/issues/5066)) ([b027507](https://github.com/vuejs/vue-next/commit/b0275070e4824c5efa868528f610eaced83d8fbc)) -* support ref in v-for, remove compat deprecation warnings ([41c18ef](https://github.com/vuejs/vue-next/commit/41c18effea9dd32ab899b5de3bb0513abdb52ee4)) +* **compiler-core:** support aliasing vue: prefixed events to inline vnode hooks ([4b0ca87](https://github.com/vuejs/core/commit/4b0ca8709a7e2652f4b02665f378d47ba4dbe969)) +* **experimental:** allow const for ref sugar declarations ([9823bd9](https://github.com/vuejs/core/commit/9823bd95d11f22f0ae53f5e0b705a21b6e6e8859)) +* **reactivity-transform/types:** restructure macro types + export types for all shorthand methods ([db729ce](https://github.com/vuejs/core/commit/db729ce99eb13cd18dad600055239c63edd9cfb8)) +* **reactivity-transform:** $$() escape for destructured prop bindings ([198ca14](https://github.com/vuejs/core/commit/198ca14f192f9eb80028153f3d36600e636de3f0)) +* **reactivity-transform:** rename @vue/ref-transform to @vue/reactivity-transform ([d70fd8d](https://github.com/vuejs/core/commit/d70fd8d36b23c987f2ebe3280da785f4d2e7d2ef)) +* **reactivity-transform:** support $-shorthands for all ref-creating APIs ([179fc05](https://github.com/vuejs/core/commit/179fc05a8406eac525c8450153b42fcb5af7d6bb)) +* **reactivity-transform:** support optionally importing macros ([fbd0fe9](https://github.com/vuejs/core/commit/fbd0fe97595f759e12e445c713b732775589fabf)) +* **reactivity-transform:** use toRef() for $() destructure codegen ([93ba6b9](https://github.com/vuejs/core/commit/93ba6b974e4a2ff4ba004fef47ef69cfe980c654)) +* **reactivity:** support default value in toRef() ([2db9c90](https://github.com/vuejs/core/commit/2db9c909c2cf3845f57b2c930c05cd6c17abe3b0)) +* **sfc-playground:** add github link ([#5067](https://github.com/vuejs/core/issues/5067)) ([9ac0dde](https://github.com/vuejs/core/commit/9ac0ddea4beec1a1c4471463d3476ccd019bd84e)) +* **sfc-playground:** prevent ctrl+s default behavior ([#5066](https://github.com/vuejs/core/issues/5066)) ([b027507](https://github.com/vuejs/core/commit/b0275070e4824c5efa868528f610eaced83d8fbc)) +* support ref in v-for, remove compat deprecation warnings ([41c18ef](https://github.com/vuejs/core/commit/41c18effea9dd32ab899b5de3bb0513abdb52ee4)) -## [3.2.24](https://github.com/vuejs/vue-next/compare/v3.2.23...v3.2.24) (2021-12-06) +## [3.2.24](https://github.com/vuejs/core/compare/v3.2.23...v3.2.24) (2021-12-06) ### Bug Fixes -* **compat:** maintain compatConfig option in legacy functional comp ([#4974](https://github.com/vuejs/vue-next/issues/4974)) ([ee97cf5](https://github.com/vuejs/vue-next/commit/ee97cf5a4db9e4f135d8eb25aff725eb37363675)) -* **compiler-dom:** avoid bailing stringification on setup const bindings ([29beda7](https://github.com/vuejs/vue-next/commit/29beda7c6f69f79e65f0111cb2d2b8d57d8257bb)) -* **compiler-sfc:** make asset url imports stringifiable ([87c73e9](https://github.com/vuejs/vue-next/commit/87c73e99d6aed0771f8c955ca9d5188ec22c90e7)) -* **package:** ensure ref-macros export is recognized by vue-tsc ([#5003](https://github.com/vuejs/vue-next/issues/5003)) ([f855269](https://github.com/vuejs/vue-next/commit/f8552697fbbdbd444d8322c6b6adeb48cc0b5617)) -* **runtime-core:** handle initial undefined attrs ([#5017](https://github.com/vuejs/vue-next/issues/5017)) ([6d887aa](https://github.com/vuejs/vue-next/commit/6d887aaf591cfa05d5fea978bbd87e3e502bfa86)), closes [#5016](https://github.com/vuejs/vue-next/issues/5016) -* **types/reactivity:** export ShallowRef type ([#5026](https://github.com/vuejs/vue-next/issues/5026)) ([523b4b7](https://github.com/vuejs/vue-next/commit/523b4b78f5d2e11f1822e09c324a854c790a7863)), closes [#5205](https://github.com/vuejs/vue-next/issues/5205) +* **compat:** maintain compatConfig option in legacy functional comp ([#4974](https://github.com/vuejs/core/issues/4974)) ([ee97cf5](https://github.com/vuejs/core/commit/ee97cf5a4db9e4f135d8eb25aff725eb37363675)) +* **compiler-dom:** avoid bailing stringification on setup const bindings ([29beda7](https://github.com/vuejs/core/commit/29beda7c6f69f79e65f0111cb2d2b8d57d8257bb)) +* **compiler-sfc:** make asset url imports stringifiable ([87c73e9](https://github.com/vuejs/core/commit/87c73e99d6aed0771f8c955ca9d5188ec22c90e7)) +* **package:** ensure ref-macros export is recognized by vue-tsc ([#5003](https://github.com/vuejs/core/issues/5003)) ([f855269](https://github.com/vuejs/core/commit/f8552697fbbdbd444d8322c6b6adeb48cc0b5617)) +* **runtime-core:** handle initial undefined attrs ([#5017](https://github.com/vuejs/core/issues/5017)) ([6d887aa](https://github.com/vuejs/core/commit/6d887aaf591cfa05d5fea978bbd87e3e502bfa86)), closes [#5016](https://github.com/vuejs/core/issues/5016) +* **types/reactivity:** export ShallowRef type ([#5026](https://github.com/vuejs/core/issues/5026)) ([523b4b7](https://github.com/vuejs/core/commit/523b4b78f5d2e11f1822e09c324a854c790a7863)), closes [#5205](https://github.com/vuejs/core/issues/5205) ### Features -* **types/script-setup:** add generic type to defineExpose ([#5035](https://github.com/vuejs/vue-next/issues/5035)) ([34985fe](https://github.com/vuejs/vue-next/commit/34985fee6b23018b6eb6322239db6165c1b0e273)) +* **types/script-setup:** add generic type to defineExpose ([#5035](https://github.com/vuejs/core/issues/5035)) ([34985fe](https://github.com/vuejs/core/commit/34985fee6b23018b6eb6322239db6165c1b0e273)) -## [3.2.23](https://github.com/vuejs/vue-next/compare/v3.2.22...v3.2.23) (2021-11-26) +## [3.2.23](https://github.com/vuejs/core/compare/v3.2.22...v3.2.23) (2021-11-26) ### Bug Fixes -* **reactivity:** retain readonly proxies when setting as reactive property ([d145128](https://github.com/vuejs/vue-next/commit/d145128ab400f4563eb3727626d0942ea5f4980a)), closes [#4986](https://github.com/vuejs/vue-next/issues/4986) -* **runtime-core:** fix component public instance has check for accessed non-existent properties ([aac0466](https://github.com/vuejs/vue-next/commit/aac0466cb8819fd132fbcc9c4d3e1014c14e2ad8)), closes [#4962](https://github.com/vuejs/vue-next/issues/4962) -* **runtime-core:** handle error in async KeepAlive hooks ([#4978](https://github.com/vuejs/vue-next/issues/4978)) ([820a143](https://github.com/vuejs/vue-next/commit/820a14345798edc0ab673bae8ce3181e479d9cca)) -* **runtime-dom:** fix option element value patching edge case ([#4959](https://github.com/vuejs/vue-next/issues/4959)) ([89b2f92](https://github.com/vuejs/vue-next/commit/89b2f924fc82d7f71dcb8ffbacb386fd5cf9ade2)), closes [#4956](https://github.com/vuejs/vue-next/issues/4956) -* **runtime-dom:** patchDOMProps should not set _value if element is custom element ([#4839](https://github.com/vuejs/vue-next/issues/4839)) ([1701bf3](https://github.com/vuejs/vue-next/commit/1701bf3968f001dd3a2bc9f41e3e7e0f1b13e922)) -* **types:** export ref-macros.d.ts ([1245709](https://github.com/vuejs/vue-next/commit/124570973df4ddfdd38e43bf1e92b9710321e5d9)) -* **types:** fix propType type inference ([#4985](https://github.com/vuejs/vue-next/issues/4985)) ([3c449cd](https://github.com/vuejs/vue-next/commit/3c449cd408840d35987fb32b39737fbf093809d6)), closes [#4983](https://github.com/vuejs/vue-next/issues/4983) -* **types:** scrip-setup+ts: ensure proper handling of `null` as default prop value. ([#4979](https://github.com/vuejs/vue-next/issues/4979)) ([f2d2d7b](https://github.com/vuejs/vue-next/commit/f2d2d7b2d236f256531ae9ad2048bd939c92d834)), closes [#4868](https://github.com/vuejs/vue-next/issues/4868) +* **reactivity:** retain readonly proxies when setting as reactive property ([d145128](https://github.com/vuejs/core/commit/d145128ab400f4563eb3727626d0942ea5f4980a)), closes [#4986](https://github.com/vuejs/core/issues/4986) +* **runtime-core:** fix component public instance has check for accessed non-existent properties ([aac0466](https://github.com/vuejs/core/commit/aac0466cb8819fd132fbcc9c4d3e1014c14e2ad8)), closes [#4962](https://github.com/vuejs/core/issues/4962) +* **runtime-core:** handle error in async KeepAlive hooks ([#4978](https://github.com/vuejs/core/issues/4978)) ([820a143](https://github.com/vuejs/core/commit/820a14345798edc0ab673bae8ce3181e479d9cca)) +* **runtime-dom:** fix option element value patching edge case ([#4959](https://github.com/vuejs/core/issues/4959)) ([89b2f92](https://github.com/vuejs/core/commit/89b2f924fc82d7f71dcb8ffbacb386fd5cf9ade2)), closes [#4956](https://github.com/vuejs/core/issues/4956) +* **runtime-dom:** patchDOMProps should not set _value if element is custom element ([#4839](https://github.com/vuejs/core/issues/4839)) ([1701bf3](https://github.com/vuejs/core/commit/1701bf3968f001dd3a2bc9f41e3e7e0f1b13e922)) +* **types:** export ref-macros.d.ts ([1245709](https://github.com/vuejs/core/commit/124570973df4ddfdd38e43bf1e92b9710321e5d9)) +* **types:** fix propType type inference ([#4985](https://github.com/vuejs/core/issues/4985)) ([3c449cd](https://github.com/vuejs/core/commit/3c449cd408840d35987fb32b39737fbf093809d6)), closes [#4983](https://github.com/vuejs/core/issues/4983) +* **types:** scrip-setup+ts: ensure proper handling of `null` as default prop value. ([#4979](https://github.com/vuejs/core/issues/4979)) ([f2d2d7b](https://github.com/vuejs/core/commit/f2d2d7b2d236f256531ae9ad2048bd939c92d834)), closes [#4868](https://github.com/vuejs/core/issues/4868) ### Features -* **compiler-sfc:** export resolveTemplateUsageCheckString for HMR plugin use ([#4908](https://github.com/vuejs/vue-next/issues/4908)) ([c61baac](https://github.com/vuejs/vue-next/commit/c61baac75a03b938bc728a8de961ba93736a0ff6)) -* **compiler-sfc:** expose properties for more accurate HMR ([68c45e7](https://github.com/vuejs/vue-next/commit/68c45e73da902e715df9614800a7ab43d6579198)), closes [#4358](https://github.com/vuejs/vue-next/issues/4358) [#4908](https://github.com/vuejs/vue-next/issues/4908) +* **compiler-sfc:** export resolveTemplateUsageCheckString for HMR plugin use ([#4908](https://github.com/vuejs/core/issues/4908)) ([c61baac](https://github.com/vuejs/core/commit/c61baac75a03b938bc728a8de961ba93736a0ff6)) +* **compiler-sfc:** expose properties for more accurate HMR ([68c45e7](https://github.com/vuejs/core/commit/68c45e73da902e715df9614800a7ab43d6579198)), closes [#4358](https://github.com/vuejs/core/issues/4358) [#4908](https://github.com/vuejs/core/issues/4908) -## [3.2.22](https://github.com/vuejs/vue-next/compare/v3.2.21...v3.2.22) (2021-11-15) +## [3.2.22](https://github.com/vuejs/core/compare/v3.2.21...v3.2.22) (2021-11-15) ### Bug Fixes -* **compiler-sfc:** add type for props include Function in prod mode ([#4938](https://github.com/vuejs/vue-next/issues/4938)) ([9c42a1e](https://github.com/vuejs/vue-next/commit/9c42a1e2a3385f3b33faed5cdcc430bf8c1fc4b2)) -* **compiler-sfc:** add type for props's properties in prod mode ([#4790](https://github.com/vuejs/vue-next/issues/4790)) ([090df08](https://github.com/vuejs/vue-next/commit/090df0837eb0aedd8a02fd0107b7668ca5c136a1)), closes [#4783](https://github.com/vuejs/vue-next/issues/4783) -* **compiler-sfc:** externalRE support automatic http/https prefix url pattern ([#4922](https://github.com/vuejs/vue-next/issues/4922)) ([574070f](https://github.com/vuejs/vue-next/commit/574070f43f804fd855f4ee319936ec770a56cef0)), closes [#4920](https://github.com/vuejs/vue-next/issues/4920) -* **compiler-sfc:** fix expose codegen edge case ([#4919](https://github.com/vuejs/vue-next/issues/4919)) ([31fd590](https://github.com/vuejs/vue-next/commit/31fd590fd47e2dc89b84687ffe26a5c6f05fea34)), closes [#4917](https://github.com/vuejs/vue-next/issues/4917) -* **devtool:** improve devtools late injection browser env detection ([#4890](https://github.com/vuejs/vue-next/issues/4890)) ([fa2237f](https://github.com/vuejs/vue-next/commit/fa2237f1d824eac511c4246135318594c48dc121)) -* **runtime-core:** improve dedupe listeners when attr fallthrough ([#4912](https://github.com/vuejs/vue-next/issues/4912)) ([b4eb7e3](https://github.com/vuejs/vue-next/commit/b4eb7e3866d7dc722d93a48f4faae1696d4e7023)), closes [#4859](https://github.com/vuejs/vue-next/issues/4859) -* **types/sfc:** fix withDefaults type inference when using union types ([#4925](https://github.com/vuejs/vue-next/issues/4925)) ([04e5835](https://github.com/vuejs/vue-next/commit/04e58351965caf489ac68e4961ef70448d954912)) +* **compiler-sfc:** add type for props include Function in prod mode ([#4938](https://github.com/vuejs/core/issues/4938)) ([9c42a1e](https://github.com/vuejs/core/commit/9c42a1e2a3385f3b33faed5cdcc430bf8c1fc4b2)) +* **compiler-sfc:** add type for props's properties in prod mode ([#4790](https://github.com/vuejs/core/issues/4790)) ([090df08](https://github.com/vuejs/core/commit/090df0837eb0aedd8a02fd0107b7668ca5c136a1)), closes [#4783](https://github.com/vuejs/core/issues/4783) +* **compiler-sfc:** externalRE support automatic http/https prefix url pattern ([#4922](https://github.com/vuejs/core/issues/4922)) ([574070f](https://github.com/vuejs/core/commit/574070f43f804fd855f4ee319936ec770a56cef0)), closes [#4920](https://github.com/vuejs/core/issues/4920) +* **compiler-sfc:** fix expose codegen edge case ([#4919](https://github.com/vuejs/core/issues/4919)) ([31fd590](https://github.com/vuejs/core/commit/31fd590fd47e2dc89b84687ffe26a5c6f05fea34)), closes [#4917](https://github.com/vuejs/core/issues/4917) +* **devtool:** improve devtools late injection browser env detection ([#4890](https://github.com/vuejs/core/issues/4890)) ([fa2237f](https://github.com/vuejs/core/commit/fa2237f1d824eac511c4246135318594c48dc121)) +* **runtime-core:** improve dedupe listeners when attr fallthrough ([#4912](https://github.com/vuejs/core/issues/4912)) ([b4eb7e3](https://github.com/vuejs/core/commit/b4eb7e3866d7dc722d93a48f4faae1696d4e7023)), closes [#4859](https://github.com/vuejs/core/issues/4859) +* **types/sfc:** fix withDefaults type inference when using union types ([#4925](https://github.com/vuejs/core/issues/4925)) ([04e5835](https://github.com/vuejs/core/commit/04e58351965caf489ac68e4961ef70448d954912)) -## [3.2.21](https://github.com/vuejs/vue-next/compare/v3.2.20...v3.2.21) (2021-11-02) +## [3.2.21](https://github.com/vuejs/core/compare/v3.2.20...v3.2.21) (2021-11-02) ### Bug Fixes -* **custom-element:** fix custom element props access on initial render ([4b7f76e](https://github.com/vuejs/vue-next/commit/4b7f76e36a7fc650986a20eca258f7a5d912424f)), closes [#4792](https://github.com/vuejs/vue-next/issues/4792) -* **custom-element:** fix initial attr type casting for programmtically created elements ([3ca8317](https://github.com/vuejs/vue-next/commit/3ca83179d1a798f65e4e70215c511e2f1b64adb6)), closes [#4772](https://github.com/vuejs/vue-next/issues/4772) -* **devtools:** avoid open handle in non-browser env ([6916d72](https://github.com/vuejs/vue-next/commit/6916d725a06a57e92ff9d046ccf132c305cd0a51)), closes [#4815](https://github.com/vuejs/vue-next/issues/4815) -* **devtools:** fix memory leak when devtools is not installed ([#4833](https://github.com/vuejs/vue-next/issues/4833)) ([6b32f0d](https://github.com/vuejs/vue-next/commit/6b32f0d976c0aac8bb2c1b78fedd03e76fb391eb)), closes [#4829](https://github.com/vuejs/vue-next/issues/4829) -* **runtime-core:** add `v-memo` to built-in directives check ([#4787](https://github.com/vuejs/vue-next/issues/4787)) ([5eb7263](https://github.com/vuejs/vue-next/commit/5eb72630a53a8dd82c2b8a9705c21a8075161a3d)) -* **runtime-dom:** fix behavior regression for v-show + style display binding ([3f38d59](https://github.com/vuejs/vue-next/commit/3f38d599f5aacdd3eeaa9475251a24f74e7ae3b4)), closes [#4768](https://github.com/vuejs/vue-next/issues/4768) -* **types:** fix ref unwrapping type inference for nested shallowReactive & shallowRef ([20a3615](https://github.com/vuejs/vue-next/commit/20a361541cc5faffa82cbf3f2d49639a97b3b678)), closes [#4771](https://github.com/vuejs/vue-next/issues/4771) +* **custom-element:** fix custom element props access on initial render ([4b7f76e](https://github.com/vuejs/core/commit/4b7f76e36a7fc650986a20eca258f7a5d912424f)), closes [#4792](https://github.com/vuejs/core/issues/4792) +* **custom-element:** fix initial attr type casting for programmtically created elements ([3ca8317](https://github.com/vuejs/core/commit/3ca83179d1a798f65e4e70215c511e2f1b64adb6)), closes [#4772](https://github.com/vuejs/core/issues/4772) +* **devtools:** avoid open handle in non-browser env ([6916d72](https://github.com/vuejs/core/commit/6916d725a06a57e92ff9d046ccf132c305cd0a51)), closes [#4815](https://github.com/vuejs/core/issues/4815) +* **devtools:** fix memory leak when devtools is not installed ([#4833](https://github.com/vuejs/core/issues/4833)) ([6b32f0d](https://github.com/vuejs/core/commit/6b32f0d976c0aac8bb2c1b78fedd03e76fb391eb)), closes [#4829](https://github.com/vuejs/core/issues/4829) +* **runtime-core:** add `v-memo` to built-in directives check ([#4787](https://github.com/vuejs/core/issues/4787)) ([5eb7263](https://github.com/vuejs/core/commit/5eb72630a53a8dd82c2b8a9705c21a8075161a3d)) +* **runtime-dom:** fix behavior regression for v-show + style display binding ([3f38d59](https://github.com/vuejs/core/commit/3f38d599f5aacdd3eeaa9475251a24f74e7ae3b4)), closes [#4768](https://github.com/vuejs/core/issues/4768) +* **types:** fix ref unwrapping type inference for nested shallowReactive & shallowRef ([20a3615](https://github.com/vuejs/core/commit/20a361541cc5faffa82cbf3f2d49639a97b3b678)), closes [#4771](https://github.com/vuejs/core/issues/4771) -## [3.2.20](https://github.com/vuejs/vue-next/compare/v3.2.19...v3.2.20) (2021-10-08) +## [3.2.20](https://github.com/vuejs/core/compare/v3.2.19...v3.2.20) (2021-10-08) ### Bug Fixes -* **compiler-sfc:** fix props codegen w/ leading import ([d4c04e9](https://github.com/vuejs/vue-next/commit/d4c04e979934b81a30467aa4b1e717175b9b2d80)), closes [#4764](https://github.com/vuejs/vue-next/issues/4764) -* **compiler-sfc:** support runtime Enum in normal script ([#4698](https://github.com/vuejs/vue-next/issues/4698)) ([f66d456](https://github.com/vuejs/vue-next/commit/f66d456b7a39db9dae7e70c28bb431ff293d8fef)) -* **devtools:** clear devtools buffer after timeout ([f4639e0](https://github.com/vuejs/vue-next/commit/f4639e0a36abe16828b202d7297e1486653b1217)), closes [#4738](https://github.com/vuejs/vue-next/issues/4738) -* **hmr:** fix hmr for components with no active instance yet ([9e3d773](https://github.com/vuejs/vue-next/commit/9e3d7731c7839638f49157123c6b372fec9e4d46)), closes [#4757](https://github.com/vuejs/vue-next/issues/4757) -* **types:** ensure that DeepReadonly handles Ref type properly ([#4714](https://github.com/vuejs/vue-next/issues/4714)) ([ed0071a](https://github.com/vuejs/vue-next/commit/ed0071ac1a6d18439f3212711c6901fbb7193288)) -* **types:** make `toRef` return correct type(fix [#4732](https://github.com/vuejs/vue-next/issues/4732)) ([#4734](https://github.com/vuejs/vue-next/issues/4734)) ([925bc34](https://github.com/vuejs/vue-next/commit/925bc346fe85091467fcd2e40d6c1ff07f3b51c4)) +* **compiler-sfc:** fix props codegen w/ leading import ([d4c04e9](https://github.com/vuejs/core/commit/d4c04e979934b81a30467aa4b1e717175b9b2d80)), closes [#4764](https://github.com/vuejs/core/issues/4764) +* **compiler-sfc:** support runtime Enum in normal script ([#4698](https://github.com/vuejs/core/issues/4698)) ([f66d456](https://github.com/vuejs/core/commit/f66d456b7a39db9dae7e70c28bb431ff293d8fef)) +* **devtools:** clear devtools buffer after timeout ([f4639e0](https://github.com/vuejs/core/commit/f4639e0a36abe16828b202d7297e1486653b1217)), closes [#4738](https://github.com/vuejs/core/issues/4738) +* **hmr:** fix hmr for components with no active instance yet ([9e3d773](https://github.com/vuejs/core/commit/9e3d7731c7839638f49157123c6b372fec9e4d46)), closes [#4757](https://github.com/vuejs/core/issues/4757) +* **types:** ensure that DeepReadonly handles Ref type properly ([#4714](https://github.com/vuejs/core/issues/4714)) ([ed0071a](https://github.com/vuejs/core/commit/ed0071ac1a6d18439f3212711c6901fbb7193288)) +* **types:** make `toRef` return correct type(fix [#4732](https://github.com/vuejs/core/issues/4732)) ([#4734](https://github.com/vuejs/core/issues/4734)) ([925bc34](https://github.com/vuejs/core/commit/925bc346fe85091467fcd2e40d6c1ff07f3b51c4)) ### Features -* **compiler-sfc:** `` -- In-browser playground on [Codepen](https://codepen.io/yyx990803/pen/OJNoaZL) -- Scaffold via [Vite](https://github.com/vitejs/vite): +- Try in the browser on [StackBlitz](https://vite.new/vue) +- Scaffold via [create-vue](https://github.com/vuejs/create-vue): ```bash - # npm 6.x - npm init vite@latest my-vue-app --template vue - # npm 7+, extra double-dash is needed: - npm init vite@latest my-vue-app -- --template vue + # npm + npm init vue@latest # yarn - yarn create vite my-vue-app --template vue - ``` - -- Scaffold via [vue-cli](https://cli.vuejs.org/): - - ```bash - npm install -g @vue/cli # OR yarn global add @vue/cli - vue create hello-vue3 - # select vue 3 preset + yarn create vue ``` ## Changes from Vue 2 -Please consult the [Migration Guide](https://v3.vuejs.org/guide/migration/introduction.html). +Please consult the [Migration Guide](http://v3-migration.vuejs.org/). Also note: Vue 3 does not support IE11 ([RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0038-vue3-ie11-support.md) | [Discussion](https://github.com/vuejs/rfcs/discussions/296)). - -## Supporting Libraries - -All of our official libraries and tools now support Vue 3, but most of them are still in beta status and distributed under the `next` dist tag on NPM. **We are planning to stabilize and switch all projects to use the `latest` dist tag in early 2021.** - -### Vue CLI - -As of v4.5.0, `vue-cli` now provides built-in option to choose Vue 3 preset when creating a new project. You can upgrade `vue-cli` and run `vue create` to create a Vue 3 project today. - -### Vue Router - -Vue Router 4.0 provides Vue 3 support and has a number of breaking changes of its own. Check out its [Migration Guide](https://next.router.vuejs.org/guide/migration/) for full details. - -- [![beta](https://img.shields.io/npm/v/vue-router/next.svg)](https://www.npmjs.com/package/vue-router/v/next) -- [GitHub](https://github.com/vuejs/vue-router-next) -- [RFCs](https://github.com/vuejs/rfcs/pulls?q=is%3Apr+is%3Amerged+label%3Arouter) - -### Vuex - -Vuex 4.0 provides Vue 3 support with largely the same API as 3.x. The only breaking change is [how the plugin is installed](https://github.com/vuejs/vuex/tree/4.0#breaking-changes). - -- [![beta](https://img.shields.io/npm/v/vuex/next.svg)](https://www.npmjs.com/package/vuex/v/next) -- [GitHub](https://github.com/vuejs/vuex/tree/4.0) - -### Devtools Extension - -We are working on a new version of the Devtools with a new UI and refactored internals to support multiple Vue versions. The new version is currently in beta and only supports Vue 3 (for now). Vuex and Router integration is also work in progress. - -- For Chrome: [Install from Chrome web store](https://chrome.google.com/webstore/detail/vuejs-devtools/ljjemllljcmogpfapbkkighbhhppjdbg?hl=en) - - - Note: the beta channel may conflict with the stable version of devtools so you may need to temporarily disable the stable version for the beta channel to work properly. - -- For Firefox: [Download the signed extension](https://github.com/vuejs/vue-devtools/releases/tag/v6.0.0-beta.2) (`.xpi` file under Assets) - -### IDE Support - -It is recommended to use [VSCode](https://code.visualstudio.com/). There are currently two viable extensions for Single-File Components (SFCs) support: - -- [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur) (recommended if you are used to Vetur features) -- [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) (recommended if using TypeScript with SFCs, or ` + + `) + expect(content).toMatch(`console.log(data.value)`) + assertCode(content) + }) + describe('errors', () => { test('defineProps/Emit() referencing ref declarations', () => { expect(() => diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 79ac5207ed7..05623326ca0 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -48,10 +48,7 @@ import { compileTemplate, SFCTemplateCompileOptions } from './compileTemplate' import { warnOnce } from './warn' import { rewriteDefault } from './rewriteDefault' import { createCache } from './cache' -import { - shouldTransform as shouldTransformRef, - transformAST as transformRefAST -} from '@vue/reactivity-transform' +import { shouldTransform, transformAST } from '@vue/reactivity-transform' // Special compiler macros const DEFINE_PROPS = 'defineProps' @@ -143,7 +140,7 @@ export function compileScript( let { script, scriptSetup, source, filename } = sfc // feature flags // TODO remove support for deprecated options when out of experimental - const enableRefTransform = + const enableReactivityTransform = !!options.reactivityTransform || !!options.refSugar || !!options.refTransform @@ -170,6 +167,8 @@ export function compileScript( scriptLang === 'tsx' || scriptSetupLang === 'ts' || scriptSetupLang === 'tsx' + + // resolve parser plugins const plugins: ParserPlugin[] = [] if (!isTS || scriptLang === 'tsx' || scriptSetupLang === 'tsx') { plugins.push('jsx') @@ -193,11 +192,11 @@ export function compileScript( sourceType: 'module' }).program const bindings = analyzeScriptBindings(scriptAst.body) - if (enableRefTransform && shouldTransformRef(content)) { + if (enableReactivityTransform && shouldTransform(content)) { const s = new MagicString(source) const startOffset = script.loc.start.offset const endOffset = script.loc.end.offset - const { importedHelpers } = transformRefAST(scriptAst, s, startOffset) + const { importedHelpers } = transformAST(scriptAst, s, startOffset) if (importedHelpers.length) { s.prepend( `import { ${importedHelpers @@ -862,14 +861,14 @@ export function compileScript( } } - // apply ref transform - if (enableRefTransform && shouldTransformRef(script.content)) { - const { rootRefs: rootVars, importedHelpers } = transformRefAST( + // apply reactivity transform + if (enableReactivityTransform && shouldTransform(script.content)) { + const { rootRefs, importedHelpers } = transformAST( scriptAst, s, scriptStartOffset! ) - refBindings = rootVars + refBindings = rootRefs for (const h of importedHelpers) { helperImports.add(h) } @@ -1109,12 +1108,14 @@ export function compileScript( } } - // 3. Apply ref sugar transform + // 3. Apply reactivity transform if ( - (enableRefTransform && shouldTransformRef(scriptSetup.content)) || + (enableReactivityTransform && + // normal \n` + + `` + ) + expect(content).toMatch(`_useCssVars(_ctx => ({ + "${mockId}-_a___b____2____px__": ((_unref(a) + _unref(b)) / 2 + 'px' ), + "${mockId}-__a___b______2___a_": (((_unref(a) + _unref(b))) / (2 * _unref(a))) })`) assertCode(content) }) diff --git a/packages/compiler-sfc/src/cssVars.ts b/packages/compiler-sfc/src/cssVars.ts index 3032e2fbf5d..da3e164aeaf 100644 --- a/packages/compiler-sfc/src/cssVars.ts +++ b/packages/compiler-sfc/src/cssVars.ts @@ -13,7 +13,7 @@ import hash from 'hash-sum' export const CSS_VARS_HELPER = `useCssVars` export const cssVarRE = - /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g + /\bv-bind\s*\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^;]*))\s*\)/g export function genCssVarsFromList( vars: string[], From 3d80b15ca4317203bcb2ecaa3d58bbfc303d67c4 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 21 Jan 2022 16:12:25 +0800 Subject: [PATCH 0041/2528] build: fix build script --- rollup.config.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index 5f7b1d51251..6e909274bc7 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -151,8 +151,11 @@ function createConfig(format, output, plugins = []) { // requires a ton of template engines which should be ignored. let cjsIgnores = [] if (pkg.name === '@vue/compiler-sfc') { + const consolidatePath = require.resolve('@vue/consolidate/package.json', { + paths: [packageDir] + }) cjsIgnores = [ - ...Object.keys(require('@vue/consolidate/package.json').devDependencies), + ...Object.keys(require(consolidatePath).devDependencies), 'vm', 'crypto', 'react-dom/server', From 283df0ad6866d212d0ce4c249259d6d31d7302c1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 21 Jan 2022 16:15:13 +0800 Subject: [PATCH 0042/2528] release: v3.2.28 --- CHANGELOG.md | 29 ++++++++++++ package.json | 2 +- packages/compiler-core/package.json | 4 +- packages/compiler-dom/package.json | 6 +-- packages/compiler-sfc/package.json | 12 ++--- packages/compiler-ssr/package.json | 6 +-- packages/reactivity-transform/package.json | 6 +-- packages/reactivity/package.json | 4 +- packages/runtime-core/package.json | 6 +-- packages/runtime-dom/package.json | 6 +-- packages/runtime-test/package.json | 6 +-- packages/server-renderer/package.json | 8 ++-- packages/sfc-playground/package.json | 4 +- packages/shared/package.json | 2 +- packages/size-check/package.json | 2 +- packages/template-explorer/package.json | 2 +- packages/vue-compat/package.json | 4 +- packages/vue/package.json | 12 ++--- pnpm-lock.yaml | 54 +++++++++++----------- 19 files changed, 102 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f84611f4dae..d78263a6704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,32 @@ +## 3.2.28 (2022-01-21) + +* build: fix build script ([3d80b15](https://github.com/vuejs/vue-next/commit/3d80b15)) +* fix(compat): convertLegacyVModelProps should merge model option in mixins (#5251) ([72130ac](https://github.com/vuejs/vue-next/commit/72130ac)), closes [#5251](https://github.com/vuejs/vue-next/issues/5251) +* fix(compat): ensure fallthrough *Native events are not dropped during props update (#5228) ([97f6bd9](https://github.com/vuejs/vue-next/commit/97f6bd9)), closes [#5228](https://github.com/vuejs/vue-next/issues/5228) +* fix(compat): simulate Vue 2.6.14 version in compat build (#5293) ([d0b9708](https://github.com/vuejs/vue-next/commit/d0b9708)), closes [#5293](https://github.com/vuejs/vue-next/issues/5293) +* fix(compiler-core): handle v-memo in template v-for (#5291) ([9f55e6f](https://github.com/vuejs/vue-next/commit/9f55e6f)), closes [#5291](https://github.com/vuejs/vue-next/issues/5291) [#5288](https://github.com/vuejs/vue-next/issues/5288) +* fix(compiler-sfc): support complex expression in CSS v-bind() (#5114) ([95d49bf](https://github.com/vuejs/vue-next/commit/95d49bf)), closes [#5114](https://github.com/vuejs/vue-next/issues/5114) [#5109](https://github.com/vuejs/vue-next/issues/5109) +* fix(compiler-sfc/reactivity-transform): fix edge case where normal script has ref macros but script ([4768f26](https://github.com/vuejs/vue-next/commit/4768f26)) +* fix(reactivity-transform): apply transform for labelled variable declarations ([a05b000](https://github.com/vuejs/vue-next/commit/a05b000)), closes [/github.com/vuejs/core/issues/5298#issuecomment-1017970061](https://github.com//github.com/vuejs/core/issues/5298/issues/issuecomment-1017970061) +* fix(reactivity-transform): apply transform on exported variable declarations ([a81a992](https://github.com/vuejs/vue-next/commit/a81a992)), closes [#5298](https://github.com/vuejs/vue-next/issues/5298) +* fix(reactivity): differentiate shallow/deep proxies of same target when nested in reactive ([9c304bf](https://github.com/vuejs/vue-next/commit/9c304bf)), closes [#5271](https://github.com/vuejs/vue-next/issues/5271) +* fix(reactivity): mutating a readonly ref nested in a reactive object should fail. (#5048) ([171f5e9](https://github.com/vuejs/vue-next/commit/171f5e9)), closes [#5048](https://github.com/vuejs/vue-next/issues/5048) [#5042](https://github.com/vuejs/vue-next/issues/5042) +* fix(runtime-core): ensure mergeProps skips undefined event handlers (#5299) ([c35ec47](https://github.com/vuejs/vue-next/commit/c35ec47)), closes [#5299](https://github.com/vuejs/vue-next/issues/5299) [#5296](https://github.com/vuejs/vue-next/issues/5296) +* fix(ssr): only cache computed getters during render phase ([2f91872](https://github.com/vuejs/vue-next/commit/2f91872)), closes [#5300](https://github.com/vuejs/vue-next/issues/5300) +* fix(types): calling readonly() with ref() should return Readonly> (#5212) ([c64907d](https://github.com/vuejs/vue-next/commit/c64907d)), closes [#5212](https://github.com/vuejs/vue-next/issues/5212) +* refactor: includes instead of indexOf (#5117) ([63210fe](https://github.com/vuejs/vue-next/commit/63210fe)), closes [#5117](https://github.com/vuejs/vue-next/issues/5117) +* chore: bump marked ([0c06c74](https://github.com/vuejs/vue-next/commit/0c06c74)) +* chore: comment dom tag config usage [ci skip] ([b2bac9f](https://github.com/vuejs/vue-next/commit/b2bac9f)) +* chore: fix typo (#5261) [ci skip] ([e603fd2](https://github.com/vuejs/vue-next/commit/e603fd2)), closes [#5261](https://github.com/vuejs/vue-next/issues/5261) +* chore: fix typo (#5282) [ci skip] ([e802275](https://github.com/vuejs/vue-next/commit/e802275)), closes [#5282](https://github.com/vuejs/vue-next/issues/5282) +* chore: type improvements (#5264) ([92e04a6](https://github.com/vuejs/vue-next/commit/92e04a6)), closes [#5264](https://github.com/vuejs/vue-next/issues/5264) +* chore: update repo references ([ae4b078](https://github.com/vuejs/vue-next/commit/ae4b078)) +* perf(reactivity): optimize effect run condition ([25bc654](https://github.com/vuejs/vue-next/commit/25bc654)) +* feat(reactivity): add isShallow api ([9fda941](https://github.com/vuejs/vue-next/commit/9fda941)) +* docs(contributing): missing structure info for compiler-sfc (#3559) [ci skip] ([8cbfe09](https://github.com/vuejs/vue-next/commit/8cbfe09)), closes [#3559](https://github.com/vuejs/vue-next/issues/3559) + + + ## [3.2.27](https://github.com/vuejs/core/compare/v3.2.26...v3.2.27) (2022-01-16) diff --git a/package.json b/package.json index de73907e213..2106eb692f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "3.2.27", + "version": "3.2.28", "scripts": { "dev": "node scripts/dev.js", "build": "node scripts/build.js", diff --git a/packages/compiler-core/package.json b/packages/compiler-core/package.json index ed124f076e8..cf0df67e30d 100644 --- a/packages/compiler-core/package.json +++ b/packages/compiler-core/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-core", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/compiler-core", "main": "index.js", "module": "dist/compiler-core.esm-bundler.js", @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme", "dependencies": { - "@vue/shared": "3.2.27", + "@vue/shared": "3.2.28", "@babel/parser": "^7.16.4", "estree-walker": "^2.0.2", "source-map": "^0.6.1" diff --git a/packages/compiler-dom/package.json b/packages/compiler-dom/package.json index 5116d873710..038ab316246 100644 --- a/packages/compiler-dom/package.json +++ b/packages/compiler-dom/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-dom", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/compiler-dom", "main": "index.js", "module": "dist/compiler-dom.esm-bundler.js", @@ -37,7 +37,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-dom#readme", "dependencies": { - "@vue/shared": "3.2.27", - "@vue/compiler-core": "3.2.27" + "@vue/shared": "3.2.28", + "@vue/compiler-core": "3.2.28" } } diff --git a/packages/compiler-sfc/package.json b/packages/compiler-sfc/package.json index 33e97b6d2fa..61430357069 100644 --- a/packages/compiler-sfc/package.json +++ b/packages/compiler-sfc/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-sfc", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/compiler-sfc", "main": "dist/compiler-sfc.cjs.js", "module": "dist/compiler-sfc.esm-browser.js", @@ -33,11 +33,11 @@ "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme", "dependencies": { "@babel/parser": "^7.16.4", - "@vue/compiler-core": "3.2.27", - "@vue/compiler-dom": "3.2.27", - "@vue/compiler-ssr": "3.2.27", - "@vue/reactivity-transform": "3.2.27", - "@vue/shared": "3.2.27", + "@vue/compiler-core": "3.2.28", + "@vue/compiler-dom": "3.2.28", + "@vue/compiler-ssr": "3.2.28", + "@vue/reactivity-transform": "3.2.28", + "@vue/shared": "3.2.28", "estree-walker": "^2.0.2", "magic-string": "^0.25.7", "source-map": "^0.6.1", diff --git a/packages/compiler-ssr/package.json b/packages/compiler-ssr/package.json index 17037b4defb..1a0aba6f3a5 100644 --- a/packages/compiler-ssr/package.json +++ b/packages/compiler-ssr/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-ssr", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/compiler-ssr", "main": "dist/compiler-ssr.cjs.js", "types": "dist/compiler-ssr.d.ts", @@ -28,7 +28,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-ssr#readme", "dependencies": { - "@vue/shared": "3.2.27", - "@vue/compiler-dom": "3.2.27" + "@vue/shared": "3.2.28", + "@vue/compiler-dom": "3.2.28" } } diff --git a/packages/reactivity-transform/package.json b/packages/reactivity-transform/package.json index f9e1fef3ebf..6aff167723c 100644 --- a/packages/reactivity-transform/package.json +++ b/packages/reactivity-transform/package.json @@ -1,6 +1,6 @@ { "name": "@vue/reactivity-transform", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/reactivity-transform", "main": "dist/reactivity-transform.cjs.js", "files": [ @@ -29,8 +29,8 @@ "homepage": "https://github.com/vuejs/core/tree/dev/packages/reactivity-transform#readme", "dependencies": { "@babel/parser": "^7.16.4", - "@vue/compiler-core": "3.2.27", - "@vue/shared": "3.2.27", + "@vue/compiler-core": "3.2.28", + "@vue/shared": "3.2.28", "estree-walker": "^2.0.2", "magic-string": "^0.25.7" }, diff --git a/packages/reactivity/package.json b/packages/reactivity/package.json index 39f5cf91c33..f68505f5a45 100644 --- a/packages/reactivity/package.json +++ b/packages/reactivity/package.json @@ -1,6 +1,6 @@ { "name": "@vue/reactivity", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/reactivity", "main": "index.js", "module": "dist/reactivity.esm-bundler.js", @@ -36,6 +36,6 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/reactivity#readme", "dependencies": { - "@vue/shared": "3.2.27" + "@vue/shared": "3.2.28" } } diff --git a/packages/runtime-core/package.json b/packages/runtime-core/package.json index e1e624b7f3a..ced766e5a5d 100644 --- a/packages/runtime-core/package.json +++ b/packages/runtime-core/package.json @@ -1,6 +1,6 @@ { "name": "@vue/runtime-core", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/runtime-core", "main": "index.js", "module": "dist/runtime-core.esm-bundler.js", @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-core#readme", "dependencies": { - "@vue/shared": "3.2.27", - "@vue/reactivity": "3.2.27" + "@vue/shared": "3.2.28", + "@vue/reactivity": "3.2.28" } } diff --git a/packages/runtime-dom/package.json b/packages/runtime-dom/package.json index f40a83f301f..c7c96b36935 100644 --- a/packages/runtime-dom/package.json +++ b/packages/runtime-dom/package.json @@ -1,6 +1,6 @@ { "name": "@vue/runtime-dom", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/runtime-dom", "main": "index.js", "module": "dist/runtime-dom.esm-bundler.js", @@ -35,8 +35,8 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-dom#readme", "dependencies": { - "@vue/shared": "3.2.27", - "@vue/runtime-core": "3.2.27", + "@vue/shared": "3.2.28", + "@vue/runtime-core": "3.2.28", "csstype": "^2.6.8" } } diff --git a/packages/runtime-test/package.json b/packages/runtime-test/package.json index 1d7befa3633..a68b870bc11 100644 --- a/packages/runtime-test/package.json +++ b/packages/runtime-test/package.json @@ -1,6 +1,6 @@ { "name": "@vue/runtime-test", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/runtime-test", "private": true, "main": "index.js", @@ -25,7 +25,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-test#readme", "dependencies": { - "@vue/shared": "3.2.27", - "@vue/runtime-core": "3.2.27" + "@vue/shared": "3.2.28", + "@vue/runtime-core": "3.2.28" } } diff --git a/packages/server-renderer/package.json b/packages/server-renderer/package.json index 5c02752f5ab..9582130a6c6 100644 --- a/packages/server-renderer/package.json +++ b/packages/server-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@vue/server-renderer", - "version": "3.2.27", + "version": "3.2.28", "description": "@vue/server-renderer", "main": "index.js", "module": "dist/server-renderer.esm-bundler.js", @@ -31,10 +31,10 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/server-renderer#readme", "peerDependencies": { - "vue": "3.2.27" + "vue": "3.2.28" }, "dependencies": { - "@vue/shared": "3.2.27", - "@vue/compiler-ssr": "3.2.27" + "@vue/shared": "3.2.28", + "@vue/compiler-ssr": "3.2.28" } } diff --git a/packages/sfc-playground/package.json b/packages/sfc-playground/package.json index 30d76c9af81..748e9978b4f 100644 --- a/packages/sfc-playground/package.json +++ b/packages/sfc-playground/package.json @@ -1,6 +1,6 @@ { "name": "@vue/sfc-playground", - "version": "3.2.27", + "version": "3.2.28", "private": true, "scripts": { "dev": "vite", @@ -12,7 +12,7 @@ "vite": "^2.7.1" }, "dependencies": { - "vue": "3.2.27", + "vue": "3.2.28", "@vue/repl": "^0.4.8", "file-saver": "^2.0.5", "jszip": "^3.6.0" diff --git a/packages/shared/package.json b/packages/shared/package.json index 1040838d074..be7ffecf04c 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@vue/shared", - "version": "3.2.27", + "version": "3.2.28", "description": "internal utils shared across @vue packages", "main": "index.js", "module": "dist/shared.esm-bundler.js", diff --git a/packages/size-check/package.json b/packages/size-check/package.json index 1bbb29bbee2..c4cfa842904 100644 --- a/packages/size-check/package.json +++ b/packages/size-check/package.json @@ -1,6 +1,6 @@ { "name": "@vue/size-check", - "version": "3.2.27", + "version": "3.2.28", "private": true, "scripts": { "build": "vite build" diff --git a/packages/template-explorer/package.json b/packages/template-explorer/package.json index 05c02976c74..cec4aa35aa7 100644 --- a/packages/template-explorer/package.json +++ b/packages/template-explorer/package.json @@ -1,6 +1,6 @@ { "name": "@vue/template-explorer", - "version": "3.2.27", + "version": "3.2.28", "private": true, "buildOptions": { "formats": [ diff --git a/packages/vue-compat/package.json b/packages/vue-compat/package.json index 83eef5a6b00..f0f9ed76efb 100644 --- a/packages/vue-compat/package.json +++ b/packages/vue-compat/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compat", - "version": "3.2.27", + "version": "3.2.28", "description": "Vue 3 compatibility build for Vue 2", "main": "index.js", "module": "dist/vue.runtime.esm-bundler.js", @@ -38,6 +38,6 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/vue-compat#readme", "peerDependencies": { - "vue": "3.2.27" + "vue": "3.2.28" } } diff --git a/packages/vue/package.json b/packages/vue/package.json index 355e86823c6..11b05bae9b7 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -1,6 +1,6 @@ { "name": "vue", - "version": "3.2.27", + "version": "3.2.28", "description": "The progressive JavaScript framework for building modern web UI.", "main": "index.js", "module": "dist/vue.runtime.esm-bundler.js", @@ -66,10 +66,10 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/vue#readme", "dependencies": { - "@vue/shared": "3.2.27", - "@vue/compiler-dom": "3.2.27", - "@vue/runtime-dom": "3.2.27", - "@vue/compiler-sfc": "3.2.27", - "@vue/server-renderer": "3.2.27" + "@vue/shared": "3.2.28", + "@vue/compiler-dom": "3.2.28", + "@vue/runtime-dom": "3.2.28", + "@vue/compiler-sfc": "3.2.28", + "@vue/server-renderer": "3.2.28" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 424319db61a..ec3e65f6284 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -104,7 +104,7 @@ importers: specifiers: '@babel/parser': ^7.16.4 '@babel/types': ^7.16.0 - '@vue/shared': 3.2.27 + '@vue/shared': 3.2.28 estree-walker: ^2.0.2 source-map: ^0.6.1 dependencies: @@ -117,8 +117,8 @@ importers: packages/compiler-dom: specifiers: - '@vue/compiler-core': 3.2.27 - '@vue/shared': 3.2.27 + '@vue/compiler-core': 3.2.28 + '@vue/shared': 3.2.28 dependencies: '@vue/compiler-core': link:../compiler-core '@vue/shared': link:../shared @@ -129,12 +129,12 @@ importers: '@babel/types': ^7.16.0 '@types/estree': ^0.0.48 '@types/lru-cache': ^5.1.0 - '@vue/compiler-core': 3.2.27 - '@vue/compiler-dom': 3.2.27 - '@vue/compiler-ssr': 3.2.27 + '@vue/compiler-core': 3.2.28 + '@vue/compiler-dom': 3.2.28 + '@vue/compiler-ssr': 3.2.28 '@vue/consolidate': ^0.17.3 - '@vue/reactivity-transform': 3.2.27 - '@vue/shared': 3.2.27 + '@vue/reactivity-transform': 3.2.28 + '@vue/shared': 3.2.28 estree-walker: ^2.0.2 hash-sum: ^2.0.0 lru-cache: ^5.1.1 @@ -172,15 +172,15 @@ importers: packages/compiler-ssr: specifiers: - '@vue/compiler-dom': 3.2.27 - '@vue/shared': 3.2.27 + '@vue/compiler-dom': 3.2.28 + '@vue/shared': 3.2.28 dependencies: '@vue/compiler-dom': link:../compiler-dom '@vue/shared': link:../shared packages/reactivity: specifiers: - '@vue/shared': 3.2.27 + '@vue/shared': 3.2.28 dependencies: '@vue/shared': link:../shared @@ -189,8 +189,8 @@ importers: '@babel/core': ^7.16.0 '@babel/parser': ^7.16.4 '@babel/types': ^7.16.0 - '@vue/compiler-core': 3.2.27 - '@vue/shared': 3.2.27 + '@vue/compiler-core': 3.2.28 + '@vue/shared': 3.2.28 estree-walker: ^2.0.2 magic-string: ^0.25.7 dependencies: @@ -205,16 +205,16 @@ importers: packages/runtime-core: specifiers: - '@vue/reactivity': 3.2.27 - '@vue/shared': 3.2.27 + '@vue/reactivity': 3.2.28 + '@vue/shared': 3.2.28 dependencies: '@vue/reactivity': link:../reactivity '@vue/shared': link:../shared packages/runtime-dom: specifiers: - '@vue/runtime-core': 3.2.27 - '@vue/shared': 3.2.27 + '@vue/runtime-core': 3.2.28 + '@vue/shared': 3.2.28 csstype: ^2.6.8 dependencies: '@vue/runtime-core': link:../runtime-core @@ -223,16 +223,16 @@ importers: packages/runtime-test: specifiers: - '@vue/runtime-core': 3.2.27 - '@vue/shared': 3.2.27 + '@vue/runtime-core': 3.2.28 + '@vue/shared': 3.2.28 dependencies: '@vue/runtime-core': link:../runtime-core '@vue/shared': link:../shared packages/server-renderer: specifiers: - '@vue/compiler-ssr': 3.2.27 - '@vue/shared': 3.2.27 + '@vue/compiler-ssr': 3.2.28 + '@vue/shared': 3.2.28 dependencies: '@vue/compiler-ssr': link:../compiler-ssr '@vue/shared': link:../shared @@ -244,7 +244,7 @@ importers: file-saver: ^2.0.5 jszip: ^3.6.0 vite: ^2.7.1 - vue: 3.2.27 + vue: 3.2.28 dependencies: '@vue/repl': 0.4.8 file-saver: 2.0.5 @@ -270,11 +270,11 @@ importers: packages/vue: specifiers: - '@vue/compiler-dom': 3.2.27 - '@vue/compiler-sfc': 3.2.27 - '@vue/runtime-dom': 3.2.27 - '@vue/server-renderer': 3.2.27 - '@vue/shared': 3.2.27 + '@vue/compiler-dom': 3.2.28 + '@vue/compiler-sfc': 3.2.28 + '@vue/runtime-dom': 3.2.28 + '@vue/server-renderer': 3.2.28 + '@vue/shared': 3.2.28 dependencies: '@vue/compiler-dom': link:../compiler-dom '@vue/compiler-sfc': link:../compiler-sfc From 16fa18da6dbbc52c89f9ea729816e1e70ab0d388 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 23 Jan 2022 20:58:43 +0800 Subject: [PATCH 0043/2528] fix(compiler-sfc): fix css v-bind inside other css functions fix #5302, close #5306 --- .../__snapshots__/cssVars.spec.ts.snap | 6 ++++-- .../compiler-sfc/__tests__/cssVars.spec.ts | 8 ++++++- packages/compiler-sfc/src/cssVars.ts | 21 ++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap index b44f584b206..c290eb6feec 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap @@ -74,14 +74,16 @@ export default { expose(); _useCssVars(_ctx => ({ - \\"xxxxxxxx-_a___b____2____px__\\": ((_unref(a) + _unref(b)) / 2 + 'px' ), + \\"xxxxxxxx-foo\\": (_unref(foo)), + \\"xxxxxxxx-_a___b____2____px_\\": ((_unref(a) + _unref(b)) / 2 + 'px'), \\"xxxxxxxx-__a___b______2___a_\\": (((_unref(a) + _unref(b))) / (2 * _unref(a))) })) let a = 100 let b = 200 + let foo = 300 -return { a, b } +return { a, b, foo } } }" diff --git a/packages/compiler-sfc/__tests__/cssVars.spec.ts b/packages/compiler-sfc/__tests__/cssVars.spec.ts index 965c9a5202b..f92852e859f 100644 --- a/packages/compiler-sfc/__tests__/cssVars.spec.ts +++ b/packages/compiler-sfc/__tests__/cssVars.spec.ts @@ -204,8 +204,13 @@ describe('CSS vars injection', () => { `\n` + `` ) expect(content).toMatch(`_useCssVars(_ctx => ({ - "${mockId}-_a___b____2____px__": ((_unref(a) + _unref(b)) / 2 + 'px' ), + "${mockId}-foo": (_unref(foo)), + "${mockId}-_a___b____2____px_": ((_unref(a) + _unref(b)) / 2 + 'px'), "${mockId}-__a___b______2___a_": (((_unref(a) + _unref(b))) / (2 * _unref(a))) })`) assertCode(content) diff --git a/packages/compiler-sfc/src/cssVars.ts b/packages/compiler-sfc/src/cssVars.ts index da3e164aeaf..c7572e58d97 100644 --- a/packages/compiler-sfc/src/cssVars.ts +++ b/packages/compiler-sfc/src/cssVars.ts @@ -12,8 +12,8 @@ import { PluginCreator } from 'postcss' import hash from 'hash-sum' export const CSS_VARS_HELPER = `useCssVars` -export const cssVarRE = - /\bv-bind\s*\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^;]*))\s*\)/g +// match v-bind() with max 2-levels of nested parens. +const cssVarRE = /v-bind\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g export function genCssVarsFromList( vars: string[], @@ -33,6 +33,17 @@ function genVarName(id: string, raw: string, isProd: boolean): string { } } +function noramlizeExpression(exp: string) { + exp = exp.trim() + if ( + (exp[0] === `'` && exp[exp.length - 1] === `'`) || + (exp[0] === `"` && exp[exp.length - 1] === `"`) + ) { + return exp.slice(1, -1) + } + return exp +} + export function parseCssVars(sfc: SFCDescriptor): string[] { const vars: string[] = [] sfc.styles.forEach(style => { @@ -40,7 +51,7 @@ export function parseCssVars(sfc: SFCDescriptor): string[] { // ignore v-bind() in comments /* ... */ const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '') while ((match = cssVarRE.exec(content))) { - const variable = match[1] || match[2] || match[3] + const variable = noramlizeExpression(match[1]) if (!vars.includes(variable)) { vars.push(variable) } @@ -62,8 +73,8 @@ export const cssVarsPlugin: PluginCreator = opts => { Declaration(decl) { // rewrite CSS variables if (cssVarRE.test(decl.value)) { - decl.value = decl.value.replace(cssVarRE, (_, $1, $2, $3) => { - return `var(--${genVarName(id, $1 || $2 || $3, isProd)})` + decl.value = decl.value.replace(cssVarRE, (_, $1) => { + return `var(--${genVarName(id, noramlizeExpression($1), isProd)})` }) } } From 059c63eab7e1e62a400a6608989f4a8545c097c6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 23 Jan 2022 21:03:37 +0800 Subject: [PATCH 0044/2528] test: add missing edge case for css v-bind --- .../compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap | 1 + packages/compiler-sfc/__tests__/cssVars.spec.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap index c290eb6feec..49b0d712a7a 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap @@ -75,6 +75,7 @@ export default { _useCssVars(_ctx => ({ \\"xxxxxxxx-foo\\": (_unref(foo)), + \\"xxxxxxxx-foo____px_\\": (_unref(foo) + 'px'), \\"xxxxxxxx-_a___b____2____px_\\": ((_unref(a) + _unref(b)) / 2 + 'px'), \\"xxxxxxxx-__a___b______2___a_\\": (((_unref(a) + _unref(b))) / (2 * _unref(a))) })) diff --git a/packages/compiler-sfc/__tests__/cssVars.spec.ts b/packages/compiler-sfc/__tests__/cssVars.spec.ts index f92852e859f..d9912f44b51 100644 --- a/packages/compiler-sfc/__tests__/cssVars.spec.ts +++ b/packages/compiler-sfc/__tests__/cssVars.spec.ts @@ -210,6 +210,7 @@ describe('CSS vars injection', () => { p{ width: calc(v-bind(foo) - 3px); height: calc(v-bind('foo') - 3px); + top: calc(v-bind(foo + 'px') - 3px); } div { color: v-bind((a + b) / 2 + 'px' ); @@ -224,6 +225,7 @@ describe('CSS vars injection', () => { ) expect(content).toMatch(`_useCssVars(_ctx => ({ "${mockId}-foo": (_unref(foo)), + "${mockId}-foo____px_": (_unref(foo) + 'px'), "${mockId}-_a___b____2____px_": ((_unref(a) + _unref(b)) / 2 + 'px'), "${mockId}-__a___b______2___a_": (((_unref(a) + _unref(b))) / (2 * _unref(a))) })`) From 4be1037f31e169d667059c44364fc3e43803accb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20L=C3=BCnborg?= Date: Sun, 23 Jan 2022 14:08:27 +0100 Subject: [PATCH 0045/2528] fix(reactivity): ensure readonly refs can be replaced with new refs in reactive objects (#5310) fix #5307 --- packages/reactivity/__tests__/readonly.spec.ts | 13 ++++++++++++- packages/reactivity/src/baseHandlers.ts | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/reactivity/__tests__/readonly.spec.ts b/packages/reactivity/__tests__/readonly.spec.ts index 4462061b3a9..73030c5b997 100644 --- a/packages/reactivity/__tests__/readonly.spec.ts +++ b/packages/reactivity/__tests__/readonly.spec.ts @@ -476,7 +476,7 @@ describe('reactivity/readonly', () => { expect(isReadonly(rr.foo)).toBe(true) }) - test('attemptingt to write to a readonly ref nested in a reactive object should fail', () => { + test('attemptingt to write plain value to a readonly ref nested in a reactive object should fail', () => { const r = ref(false) const ror = readonly(r) const obj = reactive({ ror }) @@ -486,4 +486,15 @@ describe('reactivity/readonly', () => { expect(obj.ror).toBe(false) }) + test('replacing a readonly ref nested in a reactive object with a new ref', () => { + const r = ref(false) + const ror = readonly(r) + const obj = reactive({ ror }) + try { + obj.ror = ref(true) as unknown as boolean + } catch (e) {} + + expect(obj.ror).toBe(true) + expect(toRaw(obj).ror).not.toBe(ror) // ref successfully replaced + }) }) diff --git a/packages/reactivity/src/baseHandlers.ts b/packages/reactivity/src/baseHandlers.ts index eed9dc8509f..8ad8e57171f 100644 --- a/packages/reactivity/src/baseHandlers.ts +++ b/packages/reactivity/src/baseHandlers.ts @@ -150,7 +150,7 @@ function createSetter(shallow = false) { receiver: object ): boolean { let oldValue = (target as any)[key] - if (isReadonly(oldValue) && isRef(oldValue)) { + if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) { return false } if (!shallow && !isReadonly(value)) { From 9aa5dfd4bb8efac0041e33ef5fdbebab59cc6516 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 23 Jan 2022 21:37:54 +0800 Subject: [PATCH 0046/2528] fix(runtime-dom): fix static content re-insertion fix #5308 The regression was introduced in ed9eb62. In the cached code path, we attempt re-insertion by cloning cached nodes. However if the static fragment was removed as component root, it loses the nodes between start and end because each node was removed individually. Therefore the cached path can only be taken if the fragment has a single node, or it was removed as part of a parent tree so the sibling information is still available. --- packages/runtime-dom/src/nodeOps.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/runtime-dom/src/nodeOps.ts b/packages/runtime-dom/src/nodeOps.ts index c3a4f4ba642..16762580e98 100644 --- a/packages/runtime-dom/src/nodeOps.ts +++ b/packages/runtime-dom/src/nodeOps.ts @@ -76,7 +76,10 @@ export const nodeOps: Omit, 'patchProp'> = { insertStaticContent(content, parent, anchor, isSVG, start, end) { // before | first ... last | anchor const before = anchor ? anchor.previousSibling : parent.lastChild - if (start && end) { + // #5308 can only take cached path if: + // - has a single root node + // - nextSibling info is still available + if (start && (start === end || start.nextSibling)) { // cached while (true) { parent.insertBefore(start!.cloneNode(true), anchor) From 6b6889852f247a91df4793ad37e8e2e1d27c79b3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 23 Jan 2022 22:02:23 +0800 Subject: [PATCH 0047/2528] release: v3.2.29 --- CHANGELOG.md | 11 +++++ package.json | 2 +- packages/compiler-core/package.json | 4 +- packages/compiler-dom/package.json | 6 +-- packages/compiler-sfc/package.json | 12 ++--- packages/compiler-ssr/package.json | 6 +-- packages/reactivity-transform/package.json | 6 +-- packages/reactivity/package.json | 4 +- packages/runtime-core/package.json | 6 +-- packages/runtime-dom/package.json | 6 +-- packages/runtime-test/package.json | 6 +-- packages/server-renderer/package.json | 8 ++-- packages/sfc-playground/package.json | 4 +- packages/shared/package.json | 2 +- packages/size-check/package.json | 2 +- packages/template-explorer/package.json | 2 +- packages/vue-compat/package.json | 4 +- packages/vue/package.json | 12 ++--- pnpm-lock.yaml | 54 +++++++++++----------- 19 files changed, 84 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d78263a6704..7f3574609e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## [3.2.29](https://github.com/vuejs/vue-next/compare/v3.2.28...v3.2.29) (2022-01-23) + + +### Bug Fixes + +* **compiler-sfc:** fix css v-bind inside other css functions ([16fa18d](https://github.com/vuejs/vue-next/commit/16fa18da6dbbc52c89f9ea729816e1e70ab0d388)), closes [#5302](https://github.com/vuejs/vue-next/issues/5302) [#5306](https://github.com/vuejs/vue-next/issues/5306) +* **reactivity:** ensure readonly refs can be replaced with new refs in reactive objects ([#5310](https://github.com/vuejs/vue-next/issues/5310)) ([4be1037](https://github.com/vuejs/vue-next/commit/4be1037f31e169d667059c44364fc3e43803accb)), closes [#5307](https://github.com/vuejs/vue-next/issues/5307) +* **runtime-dom:** fix static content re-insertion ([9aa5dfd](https://github.com/vuejs/vue-next/commit/9aa5dfd4bb8efac0041e33ef5fdbebab59cc6516)), closes [#5308](https://github.com/vuejs/vue-next/issues/5308) + + + ## 3.2.28 (2022-01-21) * build: fix build script ([3d80b15](https://github.com/vuejs/vue-next/commit/3d80b15)) diff --git a/package.json b/package.json index 2106eb692f9..62eba0617b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "3.2.28", + "version": "3.2.29", "scripts": { "dev": "node scripts/dev.js", "build": "node scripts/build.js", diff --git a/packages/compiler-core/package.json b/packages/compiler-core/package.json index cf0df67e30d..3b203e94fb1 100644 --- a/packages/compiler-core/package.json +++ b/packages/compiler-core/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-core", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/compiler-core", "main": "index.js", "module": "dist/compiler-core.esm-bundler.js", @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme", "dependencies": { - "@vue/shared": "3.2.28", + "@vue/shared": "3.2.29", "@babel/parser": "^7.16.4", "estree-walker": "^2.0.2", "source-map": "^0.6.1" diff --git a/packages/compiler-dom/package.json b/packages/compiler-dom/package.json index 038ab316246..ce128a58928 100644 --- a/packages/compiler-dom/package.json +++ b/packages/compiler-dom/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-dom", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/compiler-dom", "main": "index.js", "module": "dist/compiler-dom.esm-bundler.js", @@ -37,7 +37,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-dom#readme", "dependencies": { - "@vue/shared": "3.2.28", - "@vue/compiler-core": "3.2.28" + "@vue/shared": "3.2.29", + "@vue/compiler-core": "3.2.29" } } diff --git a/packages/compiler-sfc/package.json b/packages/compiler-sfc/package.json index 61430357069..401da6bc062 100644 --- a/packages/compiler-sfc/package.json +++ b/packages/compiler-sfc/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-sfc", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/compiler-sfc", "main": "dist/compiler-sfc.cjs.js", "module": "dist/compiler-sfc.esm-browser.js", @@ -33,11 +33,11 @@ "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme", "dependencies": { "@babel/parser": "^7.16.4", - "@vue/compiler-core": "3.2.28", - "@vue/compiler-dom": "3.2.28", - "@vue/compiler-ssr": "3.2.28", - "@vue/reactivity-transform": "3.2.28", - "@vue/shared": "3.2.28", + "@vue/compiler-core": "3.2.29", + "@vue/compiler-dom": "3.2.29", + "@vue/compiler-ssr": "3.2.29", + "@vue/reactivity-transform": "3.2.29", + "@vue/shared": "3.2.29", "estree-walker": "^2.0.2", "magic-string": "^0.25.7", "source-map": "^0.6.1", diff --git a/packages/compiler-ssr/package.json b/packages/compiler-ssr/package.json index 1a0aba6f3a5..5ed12185869 100644 --- a/packages/compiler-ssr/package.json +++ b/packages/compiler-ssr/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compiler-ssr", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/compiler-ssr", "main": "dist/compiler-ssr.cjs.js", "types": "dist/compiler-ssr.d.ts", @@ -28,7 +28,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-ssr#readme", "dependencies": { - "@vue/shared": "3.2.28", - "@vue/compiler-dom": "3.2.28" + "@vue/shared": "3.2.29", + "@vue/compiler-dom": "3.2.29" } } diff --git a/packages/reactivity-transform/package.json b/packages/reactivity-transform/package.json index 6aff167723c..c570b4ac63c 100644 --- a/packages/reactivity-transform/package.json +++ b/packages/reactivity-transform/package.json @@ -1,6 +1,6 @@ { "name": "@vue/reactivity-transform", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/reactivity-transform", "main": "dist/reactivity-transform.cjs.js", "files": [ @@ -29,8 +29,8 @@ "homepage": "https://github.com/vuejs/core/tree/dev/packages/reactivity-transform#readme", "dependencies": { "@babel/parser": "^7.16.4", - "@vue/compiler-core": "3.2.28", - "@vue/shared": "3.2.28", + "@vue/compiler-core": "3.2.29", + "@vue/shared": "3.2.29", "estree-walker": "^2.0.2", "magic-string": "^0.25.7" }, diff --git a/packages/reactivity/package.json b/packages/reactivity/package.json index f68505f5a45..43244ff68f1 100644 --- a/packages/reactivity/package.json +++ b/packages/reactivity/package.json @@ -1,6 +1,6 @@ { "name": "@vue/reactivity", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/reactivity", "main": "index.js", "module": "dist/reactivity.esm-bundler.js", @@ -36,6 +36,6 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/reactivity#readme", "dependencies": { - "@vue/shared": "3.2.28" + "@vue/shared": "3.2.29" } } diff --git a/packages/runtime-core/package.json b/packages/runtime-core/package.json index ced766e5a5d..7eba577ac24 100644 --- a/packages/runtime-core/package.json +++ b/packages/runtime-core/package.json @@ -1,6 +1,6 @@ { "name": "@vue/runtime-core", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/runtime-core", "main": "index.js", "module": "dist/runtime-core.esm-bundler.js", @@ -32,7 +32,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-core#readme", "dependencies": { - "@vue/shared": "3.2.28", - "@vue/reactivity": "3.2.28" + "@vue/shared": "3.2.29", + "@vue/reactivity": "3.2.29" } } diff --git a/packages/runtime-dom/package.json b/packages/runtime-dom/package.json index c7c96b36935..1a88958d1f7 100644 --- a/packages/runtime-dom/package.json +++ b/packages/runtime-dom/package.json @@ -1,6 +1,6 @@ { "name": "@vue/runtime-dom", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/runtime-dom", "main": "index.js", "module": "dist/runtime-dom.esm-bundler.js", @@ -35,8 +35,8 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-dom#readme", "dependencies": { - "@vue/shared": "3.2.28", - "@vue/runtime-core": "3.2.28", + "@vue/shared": "3.2.29", + "@vue/runtime-core": "3.2.29", "csstype": "^2.6.8" } } diff --git a/packages/runtime-test/package.json b/packages/runtime-test/package.json index a68b870bc11..a70756a43f2 100644 --- a/packages/runtime-test/package.json +++ b/packages/runtime-test/package.json @@ -1,6 +1,6 @@ { "name": "@vue/runtime-test", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/runtime-test", "private": true, "main": "index.js", @@ -25,7 +25,7 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/runtime-test#readme", "dependencies": { - "@vue/shared": "3.2.28", - "@vue/runtime-core": "3.2.28" + "@vue/shared": "3.2.29", + "@vue/runtime-core": "3.2.29" } } diff --git a/packages/server-renderer/package.json b/packages/server-renderer/package.json index 9582130a6c6..4e0e66c0742 100644 --- a/packages/server-renderer/package.json +++ b/packages/server-renderer/package.json @@ -1,6 +1,6 @@ { "name": "@vue/server-renderer", - "version": "3.2.28", + "version": "3.2.29", "description": "@vue/server-renderer", "main": "index.js", "module": "dist/server-renderer.esm-bundler.js", @@ -31,10 +31,10 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/server-renderer#readme", "peerDependencies": { - "vue": "3.2.28" + "vue": "3.2.29" }, "dependencies": { - "@vue/shared": "3.2.28", - "@vue/compiler-ssr": "3.2.28" + "@vue/shared": "3.2.29", + "@vue/compiler-ssr": "3.2.29" } } diff --git a/packages/sfc-playground/package.json b/packages/sfc-playground/package.json index 748e9978b4f..81c4d41e9fd 100644 --- a/packages/sfc-playground/package.json +++ b/packages/sfc-playground/package.json @@ -1,6 +1,6 @@ { "name": "@vue/sfc-playground", - "version": "3.2.28", + "version": "3.2.29", "private": true, "scripts": { "dev": "vite", @@ -12,7 +12,7 @@ "vite": "^2.7.1" }, "dependencies": { - "vue": "3.2.28", + "vue": "3.2.29", "@vue/repl": "^0.4.8", "file-saver": "^2.0.5", "jszip": "^3.6.0" diff --git a/packages/shared/package.json b/packages/shared/package.json index be7ffecf04c..f41808ce6f9 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@vue/shared", - "version": "3.2.28", + "version": "3.2.29", "description": "internal utils shared across @vue packages", "main": "index.js", "module": "dist/shared.esm-bundler.js", diff --git a/packages/size-check/package.json b/packages/size-check/package.json index c4cfa842904..f881e90b200 100644 --- a/packages/size-check/package.json +++ b/packages/size-check/package.json @@ -1,6 +1,6 @@ { "name": "@vue/size-check", - "version": "3.2.28", + "version": "3.2.29", "private": true, "scripts": { "build": "vite build" diff --git a/packages/template-explorer/package.json b/packages/template-explorer/package.json index cec4aa35aa7..b4b0a7514c5 100644 --- a/packages/template-explorer/package.json +++ b/packages/template-explorer/package.json @@ -1,6 +1,6 @@ { "name": "@vue/template-explorer", - "version": "3.2.28", + "version": "3.2.29", "private": true, "buildOptions": { "formats": [ diff --git a/packages/vue-compat/package.json b/packages/vue-compat/package.json index f0f9ed76efb..7d9847d3b2d 100644 --- a/packages/vue-compat/package.json +++ b/packages/vue-compat/package.json @@ -1,6 +1,6 @@ { "name": "@vue/compat", - "version": "3.2.28", + "version": "3.2.29", "description": "Vue 3 compatibility build for Vue 2", "main": "index.js", "module": "dist/vue.runtime.esm-bundler.js", @@ -38,6 +38,6 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/vue-compat#readme", "peerDependencies": { - "vue": "3.2.28" + "vue": "3.2.29" } } diff --git a/packages/vue/package.json b/packages/vue/package.json index 11b05bae9b7..4a2059584d0 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -1,6 +1,6 @@ { "name": "vue", - "version": "3.2.28", + "version": "3.2.29", "description": "The progressive JavaScript framework for building modern web UI.", "main": "index.js", "module": "dist/vue.runtime.esm-bundler.js", @@ -66,10 +66,10 @@ }, "homepage": "https://github.com/vuejs/core/tree/main/packages/vue#readme", "dependencies": { - "@vue/shared": "3.2.28", - "@vue/compiler-dom": "3.2.28", - "@vue/runtime-dom": "3.2.28", - "@vue/compiler-sfc": "3.2.28", - "@vue/server-renderer": "3.2.28" + "@vue/shared": "3.2.29", + "@vue/compiler-dom": "3.2.29", + "@vue/runtime-dom": "3.2.29", + "@vue/compiler-sfc": "3.2.29", + "@vue/server-renderer": "3.2.29" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ec3e65f6284..03fb4a4022a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -104,7 +104,7 @@ importers: specifiers: '@babel/parser': ^7.16.4 '@babel/types': ^7.16.0 - '@vue/shared': 3.2.28 + '@vue/shared': 3.2.29 estree-walker: ^2.0.2 source-map: ^0.6.1 dependencies: @@ -117,8 +117,8 @@ importers: packages/compiler-dom: specifiers: - '@vue/compiler-core': 3.2.28 - '@vue/shared': 3.2.28 + '@vue/compiler-core': 3.2.29 + '@vue/shared': 3.2.29 dependencies: '@vue/compiler-core': link:../compiler-core '@vue/shared': link:../shared @@ -129,12 +129,12 @@ importers: '@babel/types': ^7.16.0 '@types/estree': ^0.0.48 '@types/lru-cache': ^5.1.0 - '@vue/compiler-core': 3.2.28 - '@vue/compiler-dom': 3.2.28 - '@vue/compiler-ssr': 3.2.28 + '@vue/compiler-core': 3.2.29 + '@vue/compiler-dom': 3.2.29 + '@vue/compiler-ssr': 3.2.29 '@vue/consolidate': ^0.17.3 - '@vue/reactivity-transform': 3.2.28 - '@vue/shared': 3.2.28 + '@vue/reactivity-transform': 3.2.29 + '@vue/shared': 3.2.29 estree-walker: ^2.0.2 hash-sum: ^2.0.0 lru-cache: ^5.1.1 @@ -172,15 +172,15 @@ importers: packages/compiler-ssr: specifiers: - '@vue/compiler-dom': 3.2.28 - '@vue/shared': 3.2.28 + '@vue/compiler-dom': 3.2.29 + '@vue/shared': 3.2.29 dependencies: '@vue/compiler-dom': link:../compiler-dom '@vue/shared': link:../shared packages/reactivity: specifiers: - '@vue/shared': 3.2.28 + '@vue/shared': 3.2.29 dependencies: '@vue/shared': link:../shared @@ -189,8 +189,8 @@ importers: '@babel/core': ^7.16.0 '@babel/parser': ^7.16.4 '@babel/types': ^7.16.0 - '@vue/compiler-core': 3.2.28 - '@vue/shared': 3.2.28 + '@vue/compiler-core': 3.2.29 + '@vue/shared': 3.2.29 estree-walker: ^2.0.2 magic-string: ^0.25.7 dependencies: @@ -205,16 +205,16 @@ importers: packages/runtime-core: specifiers: - '@vue/reactivity': 3.2.28 - '@vue/shared': 3.2.28 + '@vue/reactivity': 3.2.29 + '@vue/shared': 3.2.29 dependencies: '@vue/reactivity': link:../reactivity '@vue/shared': link:../shared packages/runtime-dom: specifiers: - '@vue/runtime-core': 3.2.28 - '@vue/shared': 3.2.28 + '@vue/runtime-core': 3.2.29 + '@vue/shared': 3.2.29 csstype: ^2.6.8 dependencies: '@vue/runtime-core': link:../runtime-core @@ -223,16 +223,16 @@ importers: packages/runtime-test: specifiers: - '@vue/runtime-core': 3.2.28 - '@vue/shared': 3.2.28 + '@vue/runtime-core': 3.2.29 + '@vue/shared': 3.2.29 dependencies: '@vue/runtime-core': link:../runtime-core '@vue/shared': link:../shared packages/server-renderer: specifiers: - '@vue/compiler-ssr': 3.2.28 - '@vue/shared': 3.2.28 + '@vue/compiler-ssr': 3.2.29 + '@vue/shared': 3.2.29 dependencies: '@vue/compiler-ssr': link:../compiler-ssr '@vue/shared': link:../shared @@ -244,7 +244,7 @@ importers: file-saver: ^2.0.5 jszip: ^3.6.0 vite: ^2.7.1 - vue: 3.2.28 + vue: 3.2.29 dependencies: '@vue/repl': 0.4.8 file-saver: 2.0.5 @@ -270,11 +270,11 @@ importers: packages/vue: specifiers: - '@vue/compiler-dom': 3.2.28 - '@vue/compiler-sfc': 3.2.28 - '@vue/runtime-dom': 3.2.28 - '@vue/server-renderer': 3.2.28 - '@vue/shared': 3.2.28 + '@vue/compiler-dom': 3.2.29 + '@vue/compiler-sfc': 3.2.29 + '@vue/runtime-dom': 3.2.29 + '@vue/server-renderer': 3.2.29 + '@vue/shared': 3.2.29 dependencies: '@vue/compiler-dom': link:../compiler-dom '@vue/compiler-sfc': link:../compiler-sfc From 2993a246181df12e367b7abdfce0954244e8f7ec Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 28 Jan 2022 18:35:09 +0800 Subject: [PATCH 0048/2528] perf(reactivity): optimize effect/effectScope active state tracking --- packages/reactivity/src/effect.ts | 54 ++++++++++++++------------ packages/reactivity/src/effectScope.ts | 21 +++++----- packages/reactivity/src/ref.ts | 2 +- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index 3c21ab7150f..892eef102ad 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -45,7 +45,6 @@ export type DebuggerEventExtraInfo = { oldTarget?: Map | Set } -const effectStack: ReactiveEffect[] = [] let activeEffect: ReactiveEffect | undefined export const ITERATE_KEY = Symbol(__DEV__ ? 'iterate' : '') @@ -54,6 +53,7 @@ export const MAP_KEY_ITERATE_KEY = Symbol(__DEV__ ? 'Map key iterate' : '') export class ReactiveEffect { active = true deps: Dep[] = [] + parent: ReactiveEffect | undefined = undefined /** * Can be attached after creation @@ -74,7 +74,7 @@ export class ReactiveEffect { constructor( public fn: () => T, public scheduler: EffectScheduler | null = null, - scope?: EffectScope | null + scope?: EffectScope ) { recordEffectScope(this, scope) } @@ -83,31 +83,37 @@ export class ReactiveEffect { if (!this.active) { return this.fn() } - if (!effectStack.length || !effectStack.includes(this)) { - try { - effectStack.push((activeEffect = this)) - enableTracking() + let parent: ReactiveEffect | undefined = activeEffect + let lastShouldTrack = shouldTrack + while (parent) { + if (parent === this) { + return + } + parent = parent.parent + } + try { + this.parent = activeEffect + activeEffect = this + shouldTrack = true - trackOpBit = 1 << ++effectTrackDepth + trackOpBit = 1 << ++effectTrackDepth - if (effectTrackDepth <= maxMarkerBits) { - initDepMarkers(this) - } else { - cleanupEffect(this) - } - return this.fn() - } finally { - if (effectTrackDepth <= maxMarkerBits) { - finalizeDepMarkers(this) - } + if (effectTrackDepth <= maxMarkerBits) { + initDepMarkers(this) + } else { + cleanupEffect(this) + } + return this.fn() + } finally { + if (effectTrackDepth <= maxMarkerBits) { + finalizeDepMarkers(this) + } - trackOpBit = 1 << --effectTrackDepth + trackOpBit = 1 << --effectTrackDepth - resetTracking() - effectStack.pop() - const n = effectStack.length - activeEffect = n > 0 ? effectStack[n - 1] : undefined - } + activeEffect = this.parent + shouldTrack = lastShouldTrack + this.parent = undefined } } @@ -214,7 +220,7 @@ export function track(target: object, type: TrackOpTypes, key: unknown) { } export function isTracking() { - return shouldTrack && activeEffect !== undefined + return shouldTrack && !!activeEffect } export function trackEffects( diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index 864443f85b8..7c3dbc989d1 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -2,7 +2,6 @@ import { ReactiveEffect } from './effect' import { warn } from './warning' let activeEffectScope: EffectScope | undefined -const effectScopeStack: EffectScope[] = [] export class EffectScope { active = true @@ -42,24 +41,29 @@ export class EffectScope { on() { if (this.active) { - effectScopeStack.push(this) activeEffectScope = this } } off() { if (this.active) { - effectScopeStack.pop() - activeEffectScope = effectScopeStack[effectScopeStack.length - 1] + activeEffectScope = this.parent } } stop(fromParent?: boolean) { if (this.active) { - this.effects.forEach(e => e.stop()) - this.cleanups.forEach(cleanup => cleanup()) + let i, l + for (i = 0, l = this.effects.length; i < l; i++) { + this.effects[i].stop() + } + for (i = 0, l = this.cleanups.length; i < l; i++) { + this.cleanups[i]() + } if (this.scopes) { - this.scopes.forEach(e => e.stop(true)) + for (i = 0, l = this.scopes.length; i < l; i++) { + this.scopes[i].stop(true) + } } // nested scope, dereference from parent to avoid memory leaks if (this.parent && !fromParent) { @@ -81,9 +85,8 @@ export function effectScope(detached?: boolean) { export function recordEffectScope( effect: ReactiveEffect, - scope?: EffectScope | null + scope: EffectScope | undefined = activeEffectScope ) { - scope = scope || activeEffectScope if (scope && scope.active) { scope.effects.push(effect) } diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 20aa6c0a989..d9ff17ac098 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -59,7 +59,7 @@ export function triggerRefValue(ref: RefBase, newVal?: any) { export function isRef(r: Ref | unknown): r is Ref export function isRef(r: any): r is Ref { - return Boolean(r && r.__v_isRef === true) + return !!(r && r.__v_isRef === true) } export function ref( From 81a6708739164e015affcc57bb22e820bfeee7d3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 28 Jan 2022 21:02:09 +0800 Subject: [PATCH 0049/2528] chore: simplify effectScope --- packages/reactivity/src/effectScope.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/reactivity/src/effectScope.ts b/packages/reactivity/src/effectScope.ts index 7c3dbc989d1..fcacab6e381 100644 --- a/packages/reactivity/src/effectScope.ts +++ b/packages/reactivity/src/effectScope.ts @@ -29,10 +29,10 @@ export class EffectScope { run(fn: () => T): T | undefined { if (this.active) { try { - this.on() + activeEffectScope = this return fn() } finally { - this.off() + activeEffectScope = this.parent } } else if (__DEV__) { warn(`cannot run an inactive effect scope.`) @@ -40,15 +40,11 @@ export class EffectScope { } on() { - if (this.active) { - activeEffectScope = this - } + activeEffectScope = this } off() { - if (this.active) { - activeEffectScope = this.parent - } + activeEffectScope = this.parent } stop(fromParent?: boolean) { From bb43704b644949cf5592de27a902c9b115440008 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 30 Jan 2022 18:50:28 +0800 Subject: [PATCH 0050/2528] chore: check string first in toDisplayString --- packages/shared/src/toDisplayString.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/toDisplayString.ts b/packages/shared/src/toDisplayString.ts index 62a042bea47..efe3b7cc0e8 100644 --- a/packages/shared/src/toDisplayString.ts +++ b/packages/shared/src/toDisplayString.ts @@ -5,7 +5,8 @@ import { isFunction, isPlainObject, isSet, - objectToString + objectToString, + isString } from './index' /** @@ -13,7 +14,9 @@ import { * @private */ export const toDisplayString = (val: unknown): string => { - return val == null + return isString(val) + ? val + : val == null ? '' : isArray(val) || (isObject(val) && From a51f935b72c7467e234221b6e1559b18f1cb8ceb Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 30 Jan 2022 18:52:23 +0800 Subject: [PATCH 0051/2528] refactor: remove isTracking() method --- packages/reactivity/src/effect.ts | 37 +++++++++++++------------------ packages/reactivity/src/ref.ts | 16 +++++++------ 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index 892eef102ad..61894ebc2ec 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -45,7 +45,7 @@ export type DebuggerEventExtraInfo = { oldTarget?: Map | Set } -let activeEffect: ReactiveEffect | undefined +export let activeEffect: ReactiveEffect | undefined export const ITERATE_KEY = Symbol(__DEV__ ? 'iterate' : '') export const MAP_KEY_ITERATE_KEY = Symbol(__DEV__ ? 'Map key iterate' : '') @@ -181,7 +181,7 @@ export function stop(runner: ReactiveEffectRunner) { runner.effect.stop() } -let shouldTrack = true +export let shouldTrack = true const trackStack: boolean[] = [] export function pauseTracking() { @@ -200,27 +200,22 @@ export function resetTracking() { } export function track(target: object, type: TrackOpTypes, key: unknown) { - if (!isTracking()) { - return - } - let depsMap = targetMap.get(target) - if (!depsMap) { - targetMap.set(target, (depsMap = new Map())) - } - let dep = depsMap.get(key) - if (!dep) { - depsMap.set(key, (dep = createDep())) - } - - const eventInfo = __DEV__ - ? { effect: activeEffect, target, type, key } - : undefined + if (shouldTrack && activeEffect) { + let depsMap = targetMap.get(target) + if (!depsMap) { + targetMap.set(target, (depsMap = new Map())) + } + let dep = depsMap.get(key) + if (!dep) { + depsMap.set(key, (dep = createDep())) + } - trackEffects(dep, eventInfo) -} + const eventInfo = __DEV__ + ? { effect: activeEffect, target, type, key } + : undefined -export function isTracking() { - return shouldTrack && !!activeEffect + trackEffects(dep, eventInfo) + } } export function trackEffects( diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index d9ff17ac098..22dd432b945 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -1,4 +1,9 @@ -import { isTracking, trackEffects, triggerEffects } from './effect' +import { + activeEffect, + shouldTrack, + trackEffects, + triggerEffects +} from './effect' import { TrackOpTypes, TriggerOpTypes } from './operations' import { isArray, hasChanged, IfAny } from '@vue/shared' import { isProxy, toRaw, isReactive, toReactive } from './reactive' @@ -24,19 +29,16 @@ type RefBase = { } export function trackRefValue(ref: RefBase) { - if (isTracking()) { + if (shouldTrack && activeEffect) { ref = toRaw(ref) - if (!ref.dep) { - ref.dep = createDep() - } if (__DEV__) { - trackEffects(ref.dep, { + trackEffects(ref.dep || (ref.dep = createDep()), { target: ref, type: TrackOpTypes.GET, key: 'value' }) } else { - trackEffects(ref.dep) + trackEffects(ref.dep || (ref.dep = createDep())) } } } From 60cf175d88236db2c2a4a02900c92e26ceea0073 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 4 Feb 2022 08:58:28 +0800 Subject: [PATCH 0052/2528] feat(ssr): support custom directive getSSRProps in optimized compilation close #5304 --- .../transforms/transformElement.spec.ts | 10 ++- packages/compiler-core/src/index.ts | 4 +- .../src/transforms/transformElement.ts | 7 +- .../__snapshots__/vModel.spec.ts.snap | 10 +-- .../__tests__/ssrComponent.spec.ts | 16 ++++ .../compiler-ssr/__tests__/ssrElement.spec.ts | 51 +++++++++++++ packages/compiler-ssr/src/runtimeHelpers.ts | 4 +- .../src/transforms/ssrTransformComponent.ts | 23 +++--- .../src/transforms/ssrTransformElement.ts | 74 +++++++++++++++---- packages/runtime-core/src/directives.ts | 6 +- .../__tests__/ssrDirectives.spec.ts | 37 +++++++++- .../src/helpers/ssrGetDirectiveProps.ts | 26 +++++++ packages/server-renderer/src/index.ts | 1 + packages/shared/src/index.ts | 4 + 14 files changed, 228 insertions(+), 45 deletions(-) create mode 100644 packages/server-renderer/src/helpers/ssrGetDirectiveProps.ts diff --git a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts index 138fa1005c4..e7a95622d1a 100644 --- a/packages/compiler-core/__tests__/transforms/transformElement.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformElement.spec.ts @@ -5,7 +5,8 @@ import { ErrorCodes, BindingTypes, NodeTransform, - transformExpression + transformExpression, + baseCompile } from '../../src' import { RESOLVE_COMPONENT, @@ -66,6 +67,7 @@ function parseWithBind(template: string, options?: CompilerOptions) { return parseWithElementTransform(template, { ...options, directiveTransforms: { + ...options?.directiveTransforms, bind: transformBind } }) @@ -932,7 +934,11 @@ describe('compiler: element transform', () => { }) test('NEED_PATCH (vnode hooks)', () => { - const { node } = parseWithBind(`
`) + const root = baseCompile(`
`, { + prefixIdentifiers: true, + cacheHandlers: true + }).ast + const node = (root as any).children[0].codegenNode expect(node.patchFlag).toBe(genFlagText(PatchFlags.NEED_PATCH)) }) diff --git a/packages/compiler-core/src/index.ts b/packages/compiler-core/src/index.ts index 1233e0ada59..a68d2395815 100644 --- a/packages/compiler-core/src/index.ts +++ b/packages/compiler-core/src/index.ts @@ -54,7 +54,9 @@ export { export { transformElement, resolveComponentType, - buildProps + buildProps, + buildDirectiveArgs, + PropsExpression } from './transforms/transformElement' export { processSlotOutlet } from './transforms/transformSlotOutlet' export { generateCodeFrame } from '@vue/shared' diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index 47cb3b0f48f..7143963d1f5 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -29,7 +29,8 @@ import { isObject, isReservedProp, capitalize, - camelize + camelize, + isBuiltInDirective } from '@vue/shared' import { createCompilerError, ErrorCodes } from '../errors' import { @@ -665,7 +666,7 @@ export function buildProps( directiveImportMap.set(prop, needRuntime) } } - } else { + } else if (!isBuiltInDirective(name)) { // no built-in transform, this is a user custom directive. runtimeDirectives.push(prop) // custom dirs may use beforeUpdate so they need to force blocks @@ -853,7 +854,7 @@ function mergeAsArray(existing: Property, incoming: Property) { } } -function buildDirectiveArgs( +export function buildDirectiveArgs( dir: DirectiveNode, context: TransformContext ): ArrayExpression { diff --git a/packages/compiler-dom/__tests__/transforms/__snapshots__/vModel.spec.ts.snap b/packages/compiler-dom/__tests__/transforms/__snapshots__/vModel.spec.ts.snap index 1a4ce5e66c7..cdaadc1d630 100644 --- a/packages/compiler-dom/__tests__/transforms/__snapshots__/vModel.spec.ts.snap +++ b/packages/compiler-dom/__tests__/transforms/__snapshots__/vModel.spec.ts.snap @@ -37,14 +37,11 @@ exports[`compiler: transform v-model input w/ dynamic v-bind 2`] = ` return function render(_ctx, _cache) { with (_ctx) { - const { vModelDynamic: _vModelDynamic, resolveDirective: _resolveDirective, withDirectives: _withDirectives, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue - - const _directive_bind = _resolveDirective(\\"bind\\") + const { vModelDynamic: _vModelDynamic, withDirectives: _withDirectives, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue return _withDirectives((_openBlock(), _createElementBlock(\\"input\\", { \\"onUpdate:modelValue\\": $event => ((model) = $event) }, null, 8 /* PROPS */, [\\"onUpdate:modelValue\\"])), [ - [_directive_bind, val, key], [_vModelDynamic, model] ]) } @@ -152,14 +149,11 @@ exports[`compiler: transform v-model simple expression for input (dynamic type) return function render(_ctx, _cache) { with (_ctx) { - const { vModelDynamic: _vModelDynamic, resolveDirective: _resolveDirective, withDirectives: _withDirectives, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue - - const _directive_bind = _resolveDirective(\\"bind\\") + const { vModelDynamic: _vModelDynamic, withDirectives: _withDirectives, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue return _withDirectives((_openBlock(), _createElementBlock(\\"input\\", { \\"onUpdate:modelValue\\": $event => ((model) = $event) }, null, 8 /* PROPS */, [\\"onUpdate:modelValue\\"])), [ - [_directive_bind, foo, \\"type\\"], [_vModelDynamic, model] ]) } diff --git a/packages/compiler-ssr/__tests__/ssrComponent.spec.ts b/packages/compiler-ssr/__tests__/ssrComponent.spec.ts index d7ceb0bcb3c..49eb9ff9941 100644 --- a/packages/compiler-ssr/__tests__/ssrComponent.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrComponent.spec.ts @@ -377,4 +377,20 @@ describe('ssr: components', () => { }) }) }) + + describe('custom directive', () => { + test('basic', () => { + expect(compile(``).code).toMatchInlineSnapshot(` + "const { resolveComponent: _resolveComponent, resolveDirective: _resolveDirective, mergeProps: _mergeProps } = require(\\"vue\\") + const { ssrGetDirectiveProps: _ssrGetDirectiveProps, ssrRenderComponent: _ssrRenderComponent } = require(\\"vue/server-renderer\\") + + return function ssrRender(_ctx, _push, _parent, _attrs) { + const _component_foo = _resolveComponent(\\"foo\\") + const _directive_xxx = _resolveDirective(\\"xxx\\") + + _push(_ssrRenderComponent(_component_foo, _mergeProps(_attrs, _ssrGetDirectiveProps(_ctx, _directive_xxx, _ctx.z, \\"x\\", { y: true })), null, _parent)) + }" + `) + }) + }) }) diff --git a/packages/compiler-ssr/__tests__/ssrElement.spec.ts b/packages/compiler-ssr/__tests__/ssrElement.spec.ts index fee43975512..bf95065237d 100644 --- a/packages/compiler-ssr/__tests__/ssrElement.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrElement.spec.ts @@ -288,5 +288,56 @@ describe('ssr: element', () => { }>
\`" `) }) + + test('custom dir', () => { + expect(getCompiledString(`
`)).toMatchInlineSnapshot(` + "\`
\`" + `) + }) + + test('custom dir with normal attrs', () => { + expect(getCompiledString(`
`)) + .toMatchInlineSnapshot(` + "\`
\`" + `) + }) + + test('custom dir with v-bind', () => { + expect(getCompiledString(`
`)) + .toMatchInlineSnapshot(` + "\`
\`" + `) + }) + + test('custom dir with object v-bind', () => { + expect(getCompiledString(`
`)) + .toMatchInlineSnapshot(` + "\`
\`" + `) + }) + + test('custom dir with object v-bind + normal bindings', () => { + expect( + getCompiledString(`
`) + ).toMatchInlineSnapshot(` + "\`
\`" + `) + }) }) }) diff --git a/packages/compiler-ssr/src/runtimeHelpers.ts b/packages/compiler-ssr/src/runtimeHelpers.ts index 9be6c610a93..f0a6a2f290c 100644 --- a/packages/compiler-ssr/src/runtimeHelpers.ts +++ b/packages/compiler-ssr/src/runtimeHelpers.ts @@ -17,6 +17,7 @@ export const SSR_RENDER_DYNAMIC_MODEL = Symbol(`ssrRenderDynamicModel`) export const SSR_GET_DYNAMIC_MODEL_PROPS = Symbol(`ssrGetDynamicModelProps`) export const SSR_RENDER_TELEPORT = Symbol(`ssrRenderTeleport`) export const SSR_RENDER_SUSPENSE = Symbol(`ssrRenderSuspense`) +export const SSR_GET_DIRECTIVE_PROPS = Symbol(`ssrGetDirectiveProps`) export const ssrHelpers = { [SSR_INTERPOLATE]: `ssrInterpolate`, @@ -35,7 +36,8 @@ export const ssrHelpers = { [SSR_RENDER_DYNAMIC_MODEL]: `ssrRenderDynamicModel`, [SSR_GET_DYNAMIC_MODEL_PROPS]: `ssrGetDynamicModelProps`, [SSR_RENDER_TELEPORT]: `ssrRenderTeleport`, - [SSR_RENDER_SUSPENSE]: `ssrRenderSuspense` + [SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`, + [SSR_GET_DIRECTIVE_PROPS]: `ssrGetDirectiveProps` } // Note: these are helpers imported from @vue/server-renderer diff --git a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts index e4cd2698d1b..b02d3afddb5 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts @@ -33,7 +33,8 @@ import { TELEPORT, TRANSITION_GROUP, CREATE_VNODE, - CallExpression + CallExpression, + JSChildNode } from '@vue/compiler-dom' import { SSR_RENDER_COMPONENT, SSR_RENDER_VNODE } from '../runtimeHelpers' import { @@ -48,6 +49,7 @@ import { } from './ssrTransformSuspense' import { ssrProcessTransitionGroup } from './ssrTransformTransitionGroup' import { isSymbol, isObject, isArray } from '@vue/shared' +import { buildSSRProps } from './ssrTransformElement' // We need to construct the slot functions in the 1st pass to ensure proper // scope tracking, but the children of each slot cannot be processed until @@ -110,12 +112,15 @@ export const ssrTransformComponent: NodeTransform = (node, context) => { }) } - const props = - node.props.length > 0 - ? // note we are not passing ssr: true here because for components, v-on - // handlers should still be passed - buildProps(node, context).props || `null` - : `null` + let propsExp: string | JSChildNode = `null` + if (node.props.length) { + // note we are not passing ssr: true here because for components, v-on + // handlers should still be passed + const { props, directives } = buildProps(node, context) + if (props || directives.length) { + propsExp = buildSSRProps(props, directives, context) + } + } const wipEntries: WIPSlotEntry[] = [] wipMap.set(node, wipEntries) @@ -151,7 +156,7 @@ export const ssrTransformComponent: NodeTransform = (node, context) => { `_push`, createCallExpression(context.helper(CREATE_VNODE), [ component, - props, + propsExp, slots ]), `_parent` @@ -160,7 +165,7 @@ export const ssrTransformComponent: NodeTransform = (node, context) => { } else { node.ssrCodegenNode = createCallExpression( context.helper(SSR_RENDER_COMPONENT), - [component, props, slots, `_parent`] + [component, propsExp, slots, `_parent`] ) } } diff --git a/packages/compiler-ssr/src/transforms/ssrTransformElement.ts b/packages/compiler-ssr/src/transforms/ssrTransformElement.ts index 13d8c04f4ce..08b7f4ad00b 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformElement.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformElement.ts @@ -26,11 +26,15 @@ import { createSequenceExpression, InterpolationNode, isStaticExp, - AttributeNode + AttributeNode, + buildDirectiveArgs, + TransformContext, + PropsExpression } from '@vue/compiler-dom' import { escapeHtml, isBooleanAttr, + isBuiltInDirective, isSSRSafeAttrName, NO, propsToAttrMap @@ -44,7 +48,8 @@ import { SSR_RENDER_ATTRS, SSR_INTERPOLATE, SSR_GET_DYNAMIC_MODEL_PROPS, - SSR_INCLUDE_BOOLEAN_ATTR + SSR_INCLUDE_BOOLEAN_ATTR, + SSR_GET_DIRECTIVE_PROPS } from '../runtimeHelpers' import { SSRTransformContext, processChildren } from '../ssrCodegenTransform' @@ -71,16 +76,26 @@ export const ssrTransformElement: NodeTransform = (node, context) => { const needTagForRuntime = node.tag === 'textarea' || node.tag.indexOf('-') > 0 - // v-bind="obj" or v-bind:[key] can potentially overwrite other static - // attrs and can affect final rendering result, so when they are present - // we need to bail out to full `renderAttrs` + // v-bind="obj", v-bind:[key] and custom directives can potentially + // overwrite other static attrs and can affect final rendering result, + // so when they are present we need to bail out to full `renderAttrs` const hasDynamicVBind = hasDynamicKeyVBind(node) - if (hasDynamicVBind) { - const { props } = buildProps(node, context, node.props, true /* ssr */) - if (props) { + const hasCustomDir = node.props.some( + p => p.type === NodeTypes.DIRECTIVE && !isBuiltInDirective(p.name) + ) + const needMergeProps = hasDynamicVBind || hasCustomDir + if (needMergeProps) { + const { props, directives } = buildProps( + node, + context, + node.props, + true /* ssr */ + ) + if (props || directives.length) { + const mergedProps = buildSSRProps(props, directives, context) const propsExp = createCallExpression( context.helper(SSR_RENDER_ATTRS), - [props] + [mergedProps] ) if (node.tag === 'textarea') { @@ -99,7 +114,7 @@ export const ssrTransformElement: NodeTransform = (node, context) => { propsExp.arguments = [ createAssignmentExpression( createSimpleExpression(tempId, false), - props + mergedProps ) ] rawChildrenMap.set( @@ -128,7 +143,7 @@ export const ssrTransformElement: NodeTransform = (node, context) => { const tempExp = createSimpleExpression(tempId, false) propsExp.arguments = [ createSequenceExpression([ - createAssignmentExpression(tempExp, props), + createAssignmentExpression(tempExp, mergedProps), createCallExpression(context.helper(MERGE_PROPS), [ tempExp, createCallExpression( @@ -176,10 +191,10 @@ export const ssrTransformElement: NodeTransform = (node, context) => { createCompilerError(ErrorCodes.X_V_SLOT_MISPLACED, prop.loc) ) } else if (isTextareaWithValue(node, prop) && prop.exp) { - if (!hasDynamicVBind) { + if (!needMergeProps) { node.children = [createInterpolation(prop.exp, prop.loc)] } - } else if (!hasDynamicVBind) { + } else if (!needMergeProps) { // Directive transforms. const directiveTransform = context.directiveTransforms[prop.name] if (directiveTransform) { @@ -277,7 +292,7 @@ export const ssrTransformElement: NodeTransform = (node, context) => { // special case: value on 1`] = ` -Object { +{ "cached": 0, - "children": Array [ - Object { - "children": Array [ - Object { + "children": [ + { + "children": [ + { "content": "
", - "loc": Object { - "end": Object { + "loc": { + "end": { "column": 17, "line": 1, "offset": 16, }, "source": "", - "start": Object { + "start": { "column": 11, "line": 1, "offset": 10, @@ -6190,40 +6190,40 @@ Object { ], "codegenNode": undefined, "isSelfClosing": false, - "loc": Object { - "end": Object { + "loc": { + "end": { "column": 28, "line": 1, "offset": 27, }, "source": "", - "start": Object { + "start": { "column": 1, "line": 1, "offset": 0, }, }, "ns": 0, - "props": Array [], + "props": [], "tag": "textarea", "tagType": 0, "type": 1, }, ], "codegenNode": undefined, - "components": Array [], - "directives": Array [], + "components": [], + "directives": [], "helpers": Set {}, - "hoists": Array [], - "imports": Array [], - "loc": Object { - "end": Object { + "hoists": [], + "imports": [], + "loc": { + "end": { "column": 28, "line": 1, "offset": 27, }, "source": "", - "start": Object { + "start": { "column": 1, "line": 1, "offset": 0, @@ -6235,41 +6235,41 @@ Object { `; exports[`compiler: parse Errors X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END
1`] = ` -Object { +{ "cached": 0, - "children": Array [ - Object { - "children": Array [], + "children": [ + { + "children": [], "codegenNode": undefined, "isSelfClosing": true, - "loc": Object { - "end": Object { + "loc": { + "end": { "column": 25, "line": 1, "offset": 24, }, "source": "
", - "start": Object { + "start": { "column": 1, "line": 1, "offset": 0, }, }, "ns": 0, - "props": Array [ - Object { - "arg": Object { + "props": [ + { + "arg": { "constType": 0, "content": "sef", "isStatic": false, - "loc": Object { - "end": Object { + "loc": { + "end": { "column": 16, "line": 1, "offset": 15, }, "source": "[sef", - "start": Object { + "start": { "column": 12, "line": 1, "offset": 11, @@ -6278,32 +6278,32 @@ Object { "type": 4, }, "exp": undefined, - "loc": Object { - "end": Object { + "loc": { + "end": { "column": 16, "line": 1, "offset": 15, }, "source": "v-foo:[sef", - "start": Object { + "start": { "column": 6, "line": 1, "offset": 5, }, }, - "modifiers": Array [], + "modifiers": [], "name": "foo", "type": 7, }, - Object { - "loc": Object { - "end": Object { + { + "loc": { + "end": { "column": 22, "line": 1, "offset": 21, }, "source": "fsef]", - "start": Object { + "start": { "column": 17, "line": 1, "offset": 16, @@ -6320,19 +6320,19 @@ Object { }, ], "codegenNode": undefined, - "components": Array [], - "directives": Array [], + "components": [], + "directives": [], "helpers": Set {}, - "hoists": Array [], - "imports": Array [], - "loc": Object { - "end": Object { + "hoists": [], + "imports": [], + "loc": { + "end": { "column": 25, "line": 1, "offset": 24, }, "source": "
", - "start": Object { + "start": { "column": 1, "line": 1, "offset": 0, @@ -6344,30 +6344,30 @@ Object { `; exports[`compiler: parse Errors X_MISSING_END_TAG