From 5e070231aaad214468c0f98db984fd09a69d5d21 Mon Sep 17 00:00:00 2001 From: baiwusanyu-c <740132583@qq.com> Date: Fri, 30 Dec 2022 14:22:26 +0800 Subject: [PATCH 1/7] fix(runtime-core): Select elements can preserve data types when stringified --- .../stringifyStatic.spec.ts.snap | 20 +++++++ .../transforms/stringifyStatic.spec.ts | 13 ++++ .../src/transforms/stringifyStatic.ts | 6 ++ .../__tests__/directives/vModel.spec.ts | 60 ++++++++++++++++++- packages/runtime-dom/src/directives/vModel.ts | 13 +++- 5 files changed, 110 insertions(+), 2 deletions(-) diff --git a/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap b/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap index 176004794c9..c9a629cf795 100644 --- a/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap +++ b/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap @@ -1,5 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`stringify static html Select elements can preserve data types when stringified 1`] = ` +"const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode } = Vue + +const _hoisted_1 = /*#__PURE__*/_createStaticVNode("", 5) + +return function render(_ctx, _cache) { + return _hoisted_1 +}" +`; + exports[`stringify static html should bail on bindings that are hoisted but not stringifiable 1`] = ` "const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue @@ -33,6 +43,16 @@ return function render(_ctx, _cache) { }" `; +exports[`stringify static html stringify #6568 1`] = ` +"const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode } = Vue + +const _hoisted_1 = /*#__PURE__*/_createStaticVNode("", 5) + +return function render(_ctx, _cache) { + return _hoisted_1 +}" +`; + exports[`stringify static html stringify v-html 1`] = ` "const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode } = Vue diff --git a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts index bedec9fc00a..cf375671a90 100644 --- a/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts +++ b/packages/compiler-dom/__tests__/transforms/stringifyStatic.spec.ts @@ -477,4 +477,17 @@ describe('stringify static html', () => { expect(code).toMatch(`<span>show-it </span>`) expect(code).toMatchSnapshot() }) + + // #6568 + test('Select elements can preserve data types when stringified', () => { + const { code } = compileWithStringify(` + + + + + + `) + + expect(code).toMatchSnapshot() + }) }) diff --git a/packages/compiler-dom/src/transforms/stringifyStatic.ts b/packages/compiler-dom/src/transforms/stringifyStatic.ts index d3f58bdb9da..11fbf183dbc 100644 --- a/packages/compiler-dom/src/transforms/stringifyStatic.ts +++ b/packages/compiler-dom/src/transforms/stringifyStatic.ts @@ -318,6 +318,12 @@ function stringifyElement( res += ` ${(p.arg as SimpleExpressionNode).content}="${escapeHtml( evaluated )}"` + if (typeof evaluated !== 'object' && node.tag === 'option') { + res += ` v-stringify-type='${typeof evaluated}'` + } + } + if (evaluated === null && node.tag === 'option') { + res += ` v-stringify-type='${'null'}'` } } else if (p.name === 'html') { // #5439 v-html with constant value diff --git a/packages/runtime-dom/__tests__/directives/vModel.spec.ts b/packages/runtime-dom/__tests__/directives/vModel.spec.ts index f5a0c6fadcc..edfd07d08e4 100644 --- a/packages/runtime-dom/__tests__/directives/vModel.spec.ts +++ b/packages/runtime-dom/__tests__/directives/vModel.spec.ts @@ -6,7 +6,8 @@ import { vModelDynamic, withDirectives, VNode, - ref + ref, + createStaticVNode } from '@vue/runtime-dom' const triggerEvent = (type: string, el: Element) => { @@ -1172,4 +1173,61 @@ describe('vModel', () => { await nextTick() expect(data.value).toEqual('使用拼音输入') }) + + it(`After the select tag is stringified, + v-model can get the correct type`, async () => { + const hoist = createStaticVNode( + "", + 5 + ) + const component = defineComponent({ + data() { + return { value: '' } + }, + render() { + return [ + withVModel( + h( + 'select', + { + value: null, + 'onUpdate:modelValue': setValue.bind(this) + }, + [hoist] + ), + this.value + ) + ] + } + }) + render(h(component), root) + + await nextTick() + const input = root.querySelector('select') + const optionList = root.querySelectorAll('option') + const data = root._vnode.component.data + + optionList[0].selected = true + triggerEvent('change', input) + await nextTick() + expect(data.value).toBe('string') + + optionList[0].selected = false + optionList[1].selected = true + triggerEvent('change', input) + await nextTick() + expect(data.value).toBe(false) + + optionList[1].selected = false + optionList[2].selected = true + triggerEvent('change', input) + await nextTick() + expect(data.value).toBe(1) + + optionList[2].selected = false + optionList[4].selected = true + triggerEvent('change', input) + await nextTick() + expect(data.value).toBe(null) + }) }) diff --git a/packages/runtime-dom/src/directives/vModel.ts b/packages/runtime-dom/src/directives/vModel.ts index 2cf5f4cfc16..4a34a74d598 100644 --- a/packages/runtime-dom/src/directives/vModel.ts +++ b/packages/runtime-dom/src/directives/vModel.ts @@ -243,7 +243,18 @@ function setSelected(el: HTMLSelectElement, value: any) { // retrieve raw value set via :value bindings function getValue(el: HTMLOptionElement | HTMLInputElement) { - return '_value' in el ? (el as any)._value : el.value + let value = '_value' in el ? (el as any)._value : el.value + let stringifyType = el.getAttribute('v-stringify-type') + if (stringifyType === 'number') { + return Number(value) + } + if (stringifyType === 'boolean') { + return value !== 'false' + } + if (stringifyType === 'null') { + return null + } + return value } // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings From 8bc8aea588cfe86d7af5f746f57365392f6b04db Mon Sep 17 00:00:00 2001 From: baiwusanyu-c <740132583@qq.com> Date: Fri, 30 Dec 2022 15:49:30 +0800 Subject: [PATCH 2/7] fix(runtime-core): update stringifyStatic snap --- .../__snapshots__/stringifyStatic.spec.ts.snap | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap b/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap index c9a629cf795..c33bd7e64b3 100644 --- a/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap +++ b/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap @@ -43,16 +43,6 @@ return function render(_ctx, _cache) { }" `; -exports[`stringify static html stringify #6568 1`] = ` -"const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode } = Vue - -const _hoisted_1 = /*#__PURE__*/_createStaticVNode("", 5) - -return function render(_ctx, _cache) { - return _hoisted_1 -}" -`; - exports[`stringify static html stringify v-html 1`] = ` "const { createElementVNode: _createElementVNode, createStaticVNode: _createStaticVNode } = Vue From f9db15cbea4c21492ff1b49a4a75433f5abe7e79 Mon Sep 17 00:00:00 2001 From: baiwusanyu <740132583@qq.com> Date: Sat, 4 Feb 2023 18:14:49 +0800 Subject: [PATCH 3/7] Merge remote-tracking branch 'origin/main' into bwsy/fix/stringify # Conflicts: # packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap --- .eslintrc.js => .eslintrc.cjs | 12 +- .github/contributing.md | 81 +- .gitignore | 2 + CHANGELOG.md | 45 + api-extractor.json | 66 - jest.config.js | 67 - netlify.toml | 2 +- package.json | 62 +- .../__snapshots__/codegen.spec.ts.snap | 68 +- .../__snapshots__/compile.spec.ts.snap | 52 +- .../__snapshots__/parse.spec.ts.snap | 296 +- .../__snapshots__/scopeId.spec.ts.snap | 44 +- .../compiler-core/__tests__/codegen.spec.ts | 34 +- .../compiler-core/__tests__/parse.spec.ts | 9 +- .../compiler-core/__tests__/transform.spec.ts | 11 +- .../__snapshots__/hoistStatic.spec.ts.snap | 194 +- .../transformExpressions.spec.ts.snap | 10 +- .../__snapshots__/transformText.spec.ts.snap | 50 +- .../__snapshots__/vFor.spec.ts.snap | 72 +- .../transforms/__snapshots__/vIf.spec.ts.snap | 74 +- .../__snapshots__/vMemo.spec.ts.snap | 56 +- .../__snapshots__/vModel.spec.ts.snap | 76 +- .../__snapshots__/vOnce.spec.ts.snap | 32 +- .../__snapshots__/vSlot.spec.ts.snap | 116 +- .../transforms/transformElement.spec.ts | 3 +- .../transforms/transformExpressions.spec.ts | 3 +- .../transforms/transformSlotOutlet.spec.ts | 3 +- .../__tests__/transforms/vBind.spec.ts | 3 +- .../__tests__/transforms/vFor.spec.ts | 13 +- .../__tests__/transforms/vIf.spec.ts | 7 +- .../__tests__/transforms/vModel.spec.ts | 13 +- .../__tests__/transforms/vOn.spec.ts | 5 +- .../__tests__/transforms/vSlot.spec.ts | 9 +- packages/compiler-core/api-extractor.json | 7 - packages/compiler-core/package.json | 6 +- packages/compiler-core/src/index.ts | 34 +- .../src/transforms/transformSlotOutlet.ts | 2 +- .../__snapshots__/index.spec.ts.snap | 16 +- .../__tests__/decoderHtmlBrowser.spec.ts | 3 + .../__tests__/transforms/Transition.spec.ts | 3 +- .../__snapshots__/Transition.spec.ts.snap | 18 +- .../stringifyStatic.spec.ts.snap | 34 +- .../__snapshots__/vModel.spec.ts.snap | 112 +- .../__snapshots__/vShow.spec.ts.snap | 6 +- .../__tests__/transforms/vHtml.spec.ts | 5 +- .../__tests__/transforms/vModel.spec.ts | 9 +- .../__tests__/transforms/vShow.spec.ts | 3 +- .../__tests__/transforms/vText.spec.ts | 5 +- packages/compiler-dom/api-extractor.json | 7 - packages/compiler-dom/package.json | 6 +- packages/compiler-dom/src/errors.ts | 13 +- packages/compiler-dom/src/parserOptions.ts | 3 +- .../__snapshots__/compileScript.spec.ts.snap | 616 +- .../compileScriptPropsTransform.spec.ts.snap | 84 +- .../compileScriptRefTransform.spec.ts.snap | 30 +- .../compileTemplate.spec.ts.snap | 26 +- .../__snapshots__/cssVars.spec.ts.snap | 68 +- .../templateTransformAssetUrl.spec.ts.snap | 90 +- .../templateTransformSrcset.spec.ts.snap | 216 +- .../__tests__/compileScript.spec.ts | 31 + .../__tests__/compileStyle.spec.ts | 4 - .../compiler-sfc/__tests__/cssVars.spec.ts | 2 +- packages/compiler-sfc/api-extractor.json | 7 - packages/compiler-sfc/package.json | 16 +- packages/compiler-sfc/src/compileScript.ts | 53 +- packages/compiler-sfc/src/index.ts | 15 +- packages/compiler-sfc/src/rewriteDefault.ts | 10 +- .../__tests__/ssrComponent.spec.ts | 174 +- .../compiler-ssr/__tests__/ssrElement.spec.ts | 180 +- .../__tests__/ssrFallthroughAttrs.spec.ts | 14 +- .../__tests__/ssrInjectCssVars.spec.ts | 22 +- .../compiler-ssr/__tests__/ssrPortal.spec.ts | 30 +- .../compiler-ssr/__tests__/ssrScopeId.spec.ts | 32 +- .../__tests__/ssrSlotOutlet.spec.ts | 66 +- .../__tests__/ssrSuspense.spec.ts | 12 +- .../compiler-ssr/__tests__/ssrText.spec.ts | 8 +- .../__tests__/ssrTransitionGroup.spec.ts | 16 +- .../compiler-ssr/__tests__/ssrVFor.spec.ts | 46 +- .../compiler-ssr/__tests__/ssrVIf.spec.ts | 114 +- .../compiler-ssr/__tests__/ssrVModel.spec.ts | 174 +- .../compiler-ssr/__tests__/ssrVShow.spec.ts | 74 +- packages/compiler-ssr/api-extractor.json | 7 - packages/compiler-ssr/package.json | 6 +- packages/compiler-ssr/src/errors.ts | 13 +- packages/dts-test/README.md | 7 + .../dts-test}/appUse.test-d.ts | 2 +- .../dts-test}/compiler.test-d.ts | 4 +- .../dts-test}/component.test-d.ts | 14 +- .../componentTypeExtensions.test-d.tsx | 27 +- .../dts-test}/defineComponent.test-d.tsx | 139 +- .../dts-test}/defineCustomElement.test-d.ts | 13 +- .../dts-test}/functionalComponent.test-d.tsx | 32 +- {test-dts => packages/dts-test}/h.test-d.ts | 54 +- .../dts-test}/inject.test-d.ts | 3 +- packages/dts-test/package.json | 7 + .../dts-test}/reactivity.test-d.ts | 17 +- .../dts-test}/reactivityMacros.test-d.ts | 4 +- {test-dts => packages/dts-test}/ref.test-d.ts | 4 +- .../dts-test}/setupHelpers.test-d.ts | 17 +- .../dts-test/tsconfig.test.json | 0 .../dts-test}/tsx.test-d.tsx | 23 +- .../dts-test/utils.d.ts | 3 - .../dts-test}/watch.test-d.ts | 3 +- .../reactivityTransform.spec.ts.snap | 4 +- .../reactivity-transform/api-extractor.json | 7 - packages/reactivity-transform/package.json | 14 +- .../src/reactivityTransform.ts | 2 +- .../__tests__/collections/Map.spec.ts | 9 +- .../__tests__/collections/Set.spec.ts | 7 +- .../__tests__/collections/WeakMap.spec.ts | 5 +- .../__tests__/collections/WeakSet.spec.ts | 3 +- .../reactivity/__tests__/computed.spec.ts | 15 +- .../__tests__/deferredComputed.spec.ts | 31 +- packages/reactivity/__tests__/effect.spec.ts | 57 +- .../reactivity/__tests__/effectScope.spec.ts | 11 +- .../__tests__/reactiveArray.spec.ts | 7 +- packages/reactivity/__tests__/ref.spec.ts | 5 +- .../__tests__/shallowReactive.spec.ts | 5 +- packages/reactivity/api-extractor.json | 7 - packages/reactivity/package.json | 4 +- packages/reactivity/src/collectionHandlers.ts | 8 +- packages/reactivity/src/effect.ts | 16 +- packages/reactivity/src/index.ts | 53 +- packages/reactivity/src/ref.ts | 16 +- .../__tests__/apiAsyncComponent.spec.ts | 39 +- .../__tests__/apiCreateApp.spec.ts | 13 +- .../__tests__/apiLifecycle.spec.ts | 25 +- .../runtime-core/__tests__/apiOptions.spec.ts | 32 +- .../__tests__/apiSetupContext.spec.ts | 3 +- .../__tests__/apiSetupHelpers.spec.ts | 7 +- .../runtime-core/__tests__/apiWatch.spec.ts | 75 +- .../__tests__/componentEmits.spec.ts | 47 +- .../__tests__/componentProps.spec.ts | 10 +- .../__tests__/componentPublicInstance.spec.ts | 11 +- .../__tests__/componentSlots.spec.ts | 3 +- .../components/BaseTransition.spec.ts | 27 +- .../__tests__/components/KeepAlive.spec.ts | 71 +- .../__tests__/components/Suspense.spec.ts | 18 +- .../__tests__/components/Teleport.spec.ts | 8 +- .../runtime-core/__tests__/directives.spec.ts | 35 +- .../__tests__/errorHandling.spec.ts | 39 +- .../__tests__/helpers/withMemo.spec.ts | 4 + packages/runtime-core/__tests__/hmr.spec.ts | 21 +- .../runtime-core/__tests__/hydration.spec.ts | 36 +- .../rendererAttrsFallthrough.spec.ts | 34 +- .../__tests__/rendererComponent.spec.ts | 11 +- .../__tests__/rendererOptimizedMode.spec.ts | 13 +- .../__tests__/rendererTemplateRef.spec.ts | 15 +- .../runtime-core/__tests__/scheduler.spec.ts | 7 +- packages/runtime-core/__tests__/vnode.spec.ts | 3 +- .../runtime-core/__tests__/vnodeHooks.spec.ts | 25 +- packages/runtime-core/api-extractor.json | 7 - packages/runtime-core/package.json | 6 +- packages/runtime-core/src/apiCreateApp.ts | 4 +- packages/runtime-core/src/apiLifecycle.ts | 2 +- packages/runtime-core/src/apiSetupHelpers.ts | 22 +- packages/runtime-core/src/apiWatch.ts | 7 +- packages/runtime-core/src/component.ts | 20 +- packages/runtime-core/src/componentOptions.ts | 6 +- packages/runtime-core/src/componentProps.ts | 2 +- .../src/components/BaseTransition.ts | 42 +- .../runtime-core/src/components/KeepAlive.ts | 9 +- packages/runtime-core/src/enums.ts | 16 + packages/runtime-core/src/errorHandling.ts | 5 +- packages/runtime-core/src/index.ts | 60 +- packages/runtime-core/src/renderer.ts | 6 +- packages/runtime-core/types/refBail.d.ts | 14 - .../runtime-dom/__tests__/createApp.spec.ts | 3 +- .../__tests__/customElement.spec.ts | 26 +- .../__tests__/customizedBuiltIn.spec.ts | 5 +- .../__tests__/directives/vModel.spec.ts | 9 +- .../__tests__/directives/vOn.spec.ts | 17 +- .../runtime-dom/__tests__/patchEvents.spec.ts | 45 +- .../runtime-dom/__tests__/patchProps.spec.ts | 11 +- .../runtime-dom/__tests__/patchStyle.spec.ts | 3 +- packages/runtime-dom/api-extractor.json | 7 - packages/runtime-dom/package.json | 6 +- .../runtime-dom/src/components/Transition.ts | 21 +- packages/runtime-dom/src/index.ts | 7 +- packages/runtime-dom/src/modules/events.ts | 2 +- packages/runtime-dom/types/refBail.d.ts | 8 - packages/runtime-test/api-extractor.json | 7 - packages/runtime-test/package.json | 6 +- .../server-renderer/__tests__/render.spec.ts | 13 +- .../__tests__/ssrAttrFallthrough.spec.ts | 4 - .../__tests__/ssrCompilerOptions.spec.ts | 4 - .../__tests__/ssrComputed.spec.ts | 3 +- .../__tests__/ssrDirectives.spec.ts | 4 - .../__tests__/ssrDynamicComponent.spec.ts | 4 - .../__tests__/ssrInterpolate.spec.ts | 4 - .../__tests__/ssrRenderAttrs.spec.ts | 4 - .../__tests__/ssrRenderList.spec.ts | 4 - .../__tests__/ssrScopeId.spec.ts | 4 - .../server-renderer/__tests__/ssrSlot.spec.ts | 4 - .../__tests__/ssrSuspense.spec.ts | 13 +- .../__tests__/ssrTeleport.spec.ts | 4 - .../__tests__/ssrVModelHelpers.spec.ts | 4 - .../__tests__/webStream.spec.ts | 5 +- packages/server-renderer/api-extractor.json | 7 - packages/server-renderer/package.json | 8 +- .../server-renderer/src/helpers/ssrCompile.ts | 11 +- packages/server-renderer/src/index.ts | 29 +- packages/server-renderer/src/internal.ts | 25 + packages/sfc-playground/package.json | 8 +- .../__snapshots__/codeframe.spec.ts.snap | 48 +- packages/shared/__tests__/looseEqual.spec.ts | 3 + .../shared/__tests__/toDisplayString.spec.ts | 59 +- packages/shared/api-extractor.json | 7 - packages/shared/package.json | 2 +- packages/shared/src/domTagConfig.ts | 2 +- packages/size-check/package.json | 5 +- packages/size-check/src/index.ts | 2 +- packages/size-check/vite.config.js | 4 + packages/template-explorer/package.json | 2 +- .../vue-compat/__tests__/compiler.spec.ts | 3 +- .../__tests__/componentFunctional.spec.ts | 2 +- packages/vue-compat/__tests__/global.spec.ts | 11 +- .../vue-compat/__tests__/globalConfig.spec.ts | 5 +- .../vue-compat/__tests__/instance.spec.ts | 15 +- packages/vue-compat/__tests__/misc.spec.ts | 15 +- packages/vue-compat/__tests__/options.spec.ts | 9 +- packages/vue-compat/package.json | 4 +- .../vue/__tests__/customElementCasing.spec.ts | 5 +- .../__tests__/{ => e2e}/Transition.spec.ts | 97 +- .../{ => e2e}/TransitionGroup.spec.ts | 19 +- .../e2e}/commits.mock.ts | 0 .../e2e}/commits.spec.ts | 4 +- packages/vue/__tests__/{ => e2e}/e2eUtils.ts | 8 +- .../__tests__ => __tests__/e2e}/grid.spec.ts | 4 +- .../e2e}/markdown.spec.ts | 8 +- .../__tests__ => __tests__/e2e}/svg.spec.ts | 4 +- .../e2e}/todomvc.spec.ts | 4 +- .../vue/__tests__/{ => e2e}/transition.html | 2 +- .../__tests__ => __tests__/e2e}/tree.spec.ts | 4 +- packages/vue/__tests__/index.spec.ts | 17 +- packages/vue/api-extractor.json | 7 - packages/vue/package.json | 24 +- packages/vue/src/dev.ts | 1 + pnpm-lock.yaml | 4942 +++++++---------- rollup.config.js | 380 ++ rollup.config.mjs | 331 -- rollup.dts.config.js | 174 + scripts/aliases.js | 41 + scripts/bootstrap.js | 99 - scripts/build.js | 87 +- scripts/const-enum.js | 221 + scripts/dev.js | 113 +- scripts/filter-e2e.js | 17 - scripts/filter-unit.js | 9 - scripts/pre-dev-sfc.js | 6 +- scripts/preinstall.js | 1 + scripts/release.js | 98 +- scripts/{setupJestEnv.ts => setupVitest.ts} | 6 +- scripts/utils.js | 14 +- scripts/{verifyCommit.mjs => verifyCommit.js} | 5 +- test-dts/README.md | 13 - test-dts/tsconfig.json | 8 - tsconfig.build.json | 15 + tsconfig.json | 8 +- vitest.config.ts | 46 + vitest.e2e.config.ts | 10 + vitest.unit.config.ts | 10 + 262 files changed, 6203 insertions(+), 6863 deletions(-) rename .eslintrc.js => .eslintrc.cjs (83%) delete mode 100644 api-extractor.json delete mode 100644 jest.config.js delete mode 100644 packages/compiler-core/api-extractor.json delete mode 100644 packages/compiler-dom/api-extractor.json delete mode 100644 packages/compiler-sfc/api-extractor.json delete mode 100644 packages/compiler-ssr/api-extractor.json create mode 100644 packages/dts-test/README.md rename {test-dts => packages/dts-test}/appUse.test-d.ts (97%) rename {test-dts => packages/dts-test}/compiler.test-d.ts (89%) rename {test-dts => packages/dts-test}/component.test-d.ts (98%) rename {test-dts => packages/dts-test}/componentTypeExtensions.test-d.tsx (67%) rename {test-dts => packages/dts-test}/defineComponent.test-d.tsx (91%) rename {test-dts => packages/dts-test}/defineCustomElement.test-d.ts (79%) rename {test-dts => packages/dts-test}/functionalComponent.test-d.tsx (72%) rename {test-dts => packages/dts-test}/h.test-d.ts (82%) rename {test-dts => packages/dts-test}/inject.test-d.ts (82%) create mode 100644 packages/dts-test/package.json rename {test-dts => packages/dts-test}/reactivity.test-d.ts (87%) rename {test-dts => packages/dts-test}/reactivityMacros.test-d.ts (93%) rename {test-dts => packages/dts-test}/ref.test-d.ts (99%) rename {test-dts => packages/dts-test}/setupHelpers.test-d.ts (89%) rename test-dts/tsconfig.build.json => packages/dts-test/tsconfig.test.json (100%) rename {test-dts => packages/dts-test}/tsx.test-d.tsx (80%) rename test-dts/index.d.ts => packages/dts-test/utils.d.ts (86%) rename {test-dts => packages/dts-test}/watch.test-d.ts (95%) delete mode 100644 packages/reactivity-transform/api-extractor.json delete mode 100644 packages/reactivity/api-extractor.json delete mode 100644 packages/runtime-core/api-extractor.json create mode 100644 packages/runtime-core/src/enums.ts delete mode 100644 packages/runtime-core/types/refBail.d.ts delete mode 100644 packages/runtime-dom/api-extractor.json delete mode 100644 packages/runtime-dom/types/refBail.d.ts delete mode 100644 packages/runtime-test/api-extractor.json delete mode 100644 packages/server-renderer/api-extractor.json create mode 100644 packages/server-renderer/src/internal.ts delete mode 100644 packages/shared/api-extractor.json rename packages/vue/__tests__/{ => e2e}/Transition.spec.ts (97%) rename packages/vue/__tests__/{ => e2e}/TransitionGroup.spec.ts (98%) rename packages/vue/{examples/__tests__ => __tests__/e2e}/commits.mock.ts (100%) rename packages/vue/{examples/__tests__ => __tests__/e2e}/commits.spec.ts (94%) rename packages/vue/__tests__/{ => e2e}/e2eUtils.ts (95%) rename packages/vue/{examples/__tests__ => __tests__/e2e}/grid.spec.ts (97%) rename packages/vue/{examples/__tests__ => __tests__/e2e}/markdown.spec.ts (89%) rename packages/vue/{examples/__tests__ => __tests__/e2e}/svg.spec.ts (97%) rename packages/vue/{examples/__tests__ => __tests__/e2e}/todomvc.spec.ts (98%) rename packages/vue/__tests__/{ => e2e}/transition.html (95%) rename packages/vue/{examples/__tests__ => __tests__/e2e}/tree.spec.ts (97%) delete mode 100644 packages/vue/api-extractor.json create mode 100644 rollup.config.js delete mode 100644 rollup.config.mjs create mode 100644 rollup.dts.config.js create mode 100644 scripts/aliases.js delete mode 100644 scripts/bootstrap.js create mode 100644 scripts/const-enum.js delete mode 100644 scripts/filter-e2e.js delete mode 100644 scripts/filter-unit.js rename scripts/{setupJestEnv.ts => setupVitest.ts} (96%) rename scripts/{verifyCommit.mjs => verifyCommit.js} (83%) delete mode 100644 test-dts/README.md delete mode 100644 test-dts/tsconfig.json create mode 100644 tsconfig.build.json create mode 100644 vitest.config.ts create mode 100644 vitest.e2e.config.ts create mode 100644 vitest.unit.config.ts diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 83% rename from .eslintrc.js rename to .eslintrc.cjs index c0282ebd817..5d096dd3ab2 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -17,20 +17,22 @@ module.exports = { ], // most of the codebase are expected to be env agnostic 'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals], - // since we target ES2015 for baseline support, we need to forbid object - // rest spread usage in destructure as it compiles into a verbose helper. - // TS now compiles assignment spread into Object.assign() calls so that - // is allowed. + 'no-restricted-syntax': [ 'error', + // since we target ES2015 for baseline support, we need to forbid object + // rest spread usage in destructure as it compiles into a verbose helper. 'ObjectPattern > RestElement', + // tsc compiles assignment spread into Object.assign() calls, but esbuild + // still generates verbose helpers, so spread assignment is also prohiboted + 'ObjectExpression > SpreadElement', 'AwaitExpression' ] }, overrides: [ // tests, no restrictions (runs in Node / jest with jsdom) { - files: ['**/__tests__/**', 'test-dts/**'], + files: ['**/__tests__/**', 'packages/dts-test/**'], rules: { 'no-restricted-globals': 'off', 'no-restricted-syntax': 'off', diff --git a/.github/contributing.md b/.github/contributing.md index f7b20da2690..bb2a916c76a 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -30,7 +30,7 @@ Hi! I'm really excited that you are interested in contributing to Vue.js. Before - If you are resolving a special issue, add `(fix #xxxx[,#xxxx])` (#xxxx is the issue id) in your PR title for a better release log, e.g. `update entities encoding/decoding (fix #3899)`. - Provide a detailed description of the bug in the PR. Live demo preferred. - - Add appropriate test coverage if applicable. You can check the coverage of your code addition by running `npm test -- --coverage`. + - Add appropriate test coverage if applicable. You can check the coverage of your code addition by running `nr test-coverage`. - It's OK to have multiple small commits as you work on the PR - GitHub can automatically squash them before merging. @@ -70,9 +70,19 @@ $ pnpm i # install the dependencies of the project A high level overview of tools used: - [TypeScript](https://www.typescriptlang.org/) as the development language -- [Rollup](https://rollupjs.org) for bundling -- [Jest](https://jestjs.io/) for unit testing +- [Vite](https://vitejs.dev/) and [ESBuild](https://esbuild.github.io/) for development bundling +- [Rollup](https://rollupjs.org) for production bundling +- [Vitest](https://vitest.dev/) for unit testing - [Prettier](https://prettier.io/) for code formatting +- [ESLint](https://eslint.org/) for static error prevention (outside of types) + +## Git Hooks + +The project uses [simple-git-hooks](https://github.com/toplenboren/simple-git-hooks) to enforce the following on each commit: + +- Type check the entire project +- Automatically format changed files using Prettier +- Verify commit message format (logic in `scripts/verifyCommit.js`) ## Scripts @@ -80,6 +90,16 @@ A high level overview of tools used: The `run-s` and `run-p` commands found in some scripts are from [npm-run-all](https://github.com/mysticatea/npm-run-all) for orchestrating multiple scripts. `run-s` means "run in sequence" while `run-p` means "run in parallel". +- [`nr build`](#nr-build) +- [`nr build-dts`](#nr-build-dts) +- [`nr check`](#nr-check) +- [`nr dev`](#nr-dev) +- [`nr dev-sfc`](#nr-dev-sfc) +- [`nr dev-esm`](#nr-dev-esm) +- [`nr dev-compiler`](#nr-dev-compiler) +- [`nr test`](#nr-test) +- [`nr test-dts`](#nr-test-dts) + ### `nr build` The `build` script builds all public packages (packages without `private: true` in their `package.json`). @@ -94,6 +114,8 @@ nr build runtime-core nr build runtime --all ``` +Note that `nr build` uses `rollup-plugin-esbuild` for transpiling typescript and **does not perform type checking**. To run type check on the entire codebase, run `nr check`. Type checks are also automatically run on each commit. + #### Build Formats By default, each package will be built in multiple distribution formats as specified in the `buildOptions.formats` field in its `package.json`. These can be overwritten via the `-f` flag. The following formats are supported: @@ -127,13 +149,11 @@ nr build runtime-core -f esm-browser,cjs Use the `--sourcemap` or `-s` flag to build with source maps. Note this will make the build much slower. -#### Build with Type Declarations +### `nr build-dts` -The `--types` or `-t` flag will generate type declarations during the build and in addition: +This command builds the type declarations for all packages. It first generates the raw `.d.ts` files in the `temp` directory, then uses [rollup-plugin-dts](https://github.com/Swatinem/rollup-plugin-dts) to roll the types into a single `.d.ts` file for each package. -- Roll the declarations into a single `.d.ts` file for each package; -- Generate an API report in `/temp/.api.md`. This report contains potential warnings emitted by [api-extractor](https://api-extractor.com/). -- Generate an API model json in `/temp/.api.json`. This file can be used to generate a Markdown version of the exported APIs. +### `nr check` ### `nr dev` @@ -142,7 +162,7 @@ The `dev` script bundles a target package (default: `vue`) in a specified format ```bash $ nr dev -> watching: packages/vue/dist/vue.global.js +> built: packages/vue/dist/vue.global.js ``` - **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. @@ -169,23 +189,30 @@ The `dev-compiler` script builds, watches and serves the [Template Explorer](htt ### `nr test` -The `test` script simply calls the `jest` binary, so all [Jest CLI Options](https://jestjs.io/docs/en/cli) can be used. Some examples: +The `test` script simply calls the `vitest` binary, so all [Vitest CLI Options](https://vitest.dev/guide/cli.html#options) can be used. Some examples: ```bash -# run all tests +# run all tests in watch mode $ nr test +# run once and exit (equivalent to `vitest run`) +$ nr test run + # run all tests under the runtime-core package $ nr test runtime-core -# run tests in a specific file -$ nr test fileName +# run tests in files matching the pattern +$ nr test -# run a specific test in a specific file -$ nr test fileName -t 'test name' +# run a specific test in specific files +$ nr test -t 'test name' ``` -The default `test` script includes the `--runInBand` jest flag to improve test stability, especially for the CSS transition related tests. When you are testing specific test specs, you can also run `npx jest` with flags directly to speed up tests (jest runs them in parallel by default). +Tests that test against source code are grouped under `nr test-unit`, while tests that test against built files that run in real browsers are grouped under `nr test-e2e`. + +### `nr test-dts` + +Runs `nr build-dts` first, then verify the type tests in `packages/dts-test` are working correctly against the actual built type declarations. ## Project Structure @@ -209,14 +236,20 @@ This repository employs a [monorepo](https://en.wikipedia.org/wiki/Monorepo) set - `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. - - A [live version](https://vue-next-template-explorer.netlify.com) of the template explorer is also available, which can be used for providing reproductions for compiler bugs. You can also pick the deployment for a specific commit from the [deploy logs](https://app.netlify.com/sites/vue-next-template-explorer/deploys). - - `shared`: Internal utilities shared across multiple packages (especially environment-agnostic utils used by both runtime and compiler packages). - `vue`: The public facing "full build" which includes both the runtime AND the compiler. +- Private utility packages: + + - `dts-test`: Contains type-only tests against generated dts files. + + - `sfc-playground`: The playground continuously deployed at https://sfc.vuejs.org. To run the playground locally, use [`nr dev-sfc`](#nr-dev-sfc). + + - `template-explorer`: A development tool for debugging compiler output, continuously deployed at https://template-explorer.vuejs.org/. To run it locally, run [`nr dev-compiler`](#nr-dev-compiler). + + - `size-check`: Used for checking built bundle sizes on CI. + ### Importing Packages The packages can import each other directly using their package names. Note that when importing a package, the name listed in its `package.json` should be used. Most of the time the `@vue/` prefix is needed: @@ -228,7 +261,7 @@ import { h } from '@vue/runtime-core' This is made possible via several configurations: - For TypeScript, `compilerOptions.paths` in `tsconfig.json` -- For Jest, `moduleNameMapper` in `jest.config.js` +- Vitest and Rollup share the sae set of aliases from `scripts/aliases.js` - For plain Node.js, they are linked using [PNPM Workspaces](https://pnpm.io/workspaces). ### Package Dependencies @@ -268,7 +301,7 @@ There are some rules to follow when importing across package boundaries: ## Contributing Tests -Unit tests are collocated with the code being tested in each package, inside directories named `__tests__`. Consult the [Jest docs](https://jestjs.io/docs/en/using-matchers) and existing test cases for how to write new test specs. Here are some additional guidelines: +Unit tests are collocated with the code being tested in each package, inside directories named `__tests__`. Consult the [Vitest docs](https://vitest.dev/api/) and existing test cases for how to write new test specs. Here are some additional guidelines: - Use the minimal API needed for a test case. For example, if a test can be written without involving the reactivity system or a component, it should be written so. This limits the test's exposure to changes in unrelated parts and makes it more stable. @@ -276,11 +309,11 @@ Unit tests are collocated with the code being tested in each package, inside dir - Only use platform-specific runtimes if the test is asserting platform-specific behavior. -Test coverage is continuously deployed at https://vue-next-coverage.netlify.app/. PRs that improve test coverage are welcome, but in general the test coverage should be used as a guidance for finding API use cases that are not covered by tests. We don't recommend adding tests that only improve coverage but not actually test a meaning use case. +Test coverage is continuously deployed at https://coverage.vuejs.org. PRs that improve test coverage are welcome, but in general the test coverage should be used as a guidance for finding API use cases that are not covered by tests. We don't recommend adding tests that only improve coverage but not actually test a meaning use case. ### Testing Type Definition Correctness -Type tests are located in the `test-dts` directory. To run the dts tests, run `nr test-dts`. Note that the type test requires all relevant `*.d.ts` files to be built first (and the script does it for you). Once the `d.ts` files are built and up-to-date, the tests can be re-run by simply running `nr test-dts`. +Type tests are located in the `packages/dts-test` directory. To run the dts tests, run `nr test-dts`. Note that the type test requires all relevant `*.d.ts` files to be built first (and the script does it for you). Once the `d.ts` files are built and up-to-date, the tests can be re-run by running `nr test-dts-only`. ## Financial Contribution diff --git a/.gitignore b/.gitignore index 75c8139bd9b..810f8852690 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ TODOs.md *.log .idea .eslintcache +dts-build/packages +*.tsbuildinfo diff --git a/CHANGELOG.md b/CHANGELOG.md index 11a2a9dde78..f9171ded9e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,48 @@ +## [3.2.47](https://github.com/vuejs/core/compare/v3.2.46...v3.2.47) (2023-02-02) + + +### Bug Fixes + +* **build:** enforce __esModule interop for cjs builds ([4b70366](https://github.com/vuejs/core/commit/4b7036653e5dfd7be95e6efe8c79621b52dcccb7)) + + + +## [3.2.46](https://github.com/vuejs/core/compare/v3.2.45...v3.2.46) (2023-02-02) + + +### Bug Fixes + +* **build:** ensure cjs re-exports can be properly detected when imported from esm ([fb6ff3e](https://github.com/vuejs/core/commit/fb6ff3e99689022d963ea7257b03f73ff514c0c4)) +* **build:** ensure type exports is first ([957722c](https://github.com/vuejs/core/commit/957722c4185ea87aabc711f6f8997e528dd3ba1b)) +* **build:** fix cjs re-exports check for compat build ([ce064a1](https://github.com/vuejs/core/commit/ce064a172b3b5bcb096b4984fe0c1a54177ac9c0)) +* **compat:** fix custom transition classes in compat mode ([#7435](https://github.com/vuejs/core/issues/7435)) ([efe2efd](https://github.com/vuejs/core/commit/efe2efd210f500311e5b603345cb0d353886bd7a)), closes [#6253](https://github.com/vuejs/core/issues/6253) +* **compiler-core:** typeof should be allowed in browser expression validation ([#7037](https://github.com/vuejs/core/issues/7037)) ([3783866](https://github.com/vuejs/core/commit/378386694be6dd43da71f1fa08ee9c5705c13f86)) +* **compiler-sfc:** allow declaring variables after defineProps ([#7461](https://github.com/vuejs/core/issues/7461)) ([686c829](https://github.com/vuejs/core/commit/686c829fec9137cdfe6e51af34f2af01a575f7c6)) +* **compiler-sfc:** always generate runtime prop type for Function ([#7112](https://github.com/vuejs/core/issues/7112)) ([584eae6](https://github.com/vuejs/core/commit/584eae60d1abe80d15b317ec80b7556712df8e5a)), closes [#7111](https://github.com/vuejs/core/issues/7111) +* **compiler-sfc:** support resolving type declaration from normal script ([#5831](https://github.com/vuejs/core/issues/5831)) ([30399d4](https://github.com/vuejs/core/commit/30399d46b15f890056e7a5d076cd588b3806cc15)), closes [#5830](https://github.com/vuejs/core/issues/5830) +* **compiler:** add `hgroup` to supported `HTML_TAGS` ([#6321](https://github.com/vuejs/core/issues/6321)) ([7443174](https://github.com/vuejs/core/commit/7443174e2aa9244bc08c63b4d6c78acc6ff89767)), closes [#6313](https://github.com/vuejs/core/issues/6313) +* **custom-elements:** use strict number casting ([7d0c63f](https://github.com/vuejs/core/commit/7d0c63ff4361e59e820441a24bf4fb2a93335a1e)), closes [#4946](https://github.com/vuejs/core/issues/4946) [#2598](https://github.com/vuejs/core/issues/2598) [#2604](https://github.com/vuejs/core/issues/2604) +* **customElement:** customElement can emit event ([#7296](https://github.com/vuejs/core/issues/7296)) ([c6e5bda](https://github.com/vuejs/core/commit/c6e5bda27d13554675d68dbe33b07f3474467aa6)) +* **reactivity-transform:** fix $$ escape edge cases ([e06d3b6](https://github.com/vuejs/core/commit/e06d3b614ea518e9cdf83fca9200fc816eb4e5a1)), closes [#6312](https://github.com/vuejs/core/issues/6312) [#6944](https://github.com/vuejs/core/issues/6944) +* **reactivity-transform:** prohibit const assignment at compile time ([#6993](https://github.com/vuejs/core/issues/6993)) ([3427052](https://github.com/vuejs/core/commit/3427052229db3448252d938292a40e960a0f4b9c)), closes [#6992](https://github.com/vuejs/core/issues/6992) +* **reactivity:** `triggerRef` working with `toRef` from reactive ([#7507](https://github.com/vuejs/core/issues/7507)) ([e64c9ae](https://github.com/vuejs/core/commit/e64c9ae957aa2606b55e8652bbde30a6ada59fb0)) +* **reactivity:** ensure watch(Effect) can run independent of unmounted instance if created in a detatched effectScope (fix [#7319](https://github.com/vuejs/core/issues/7319)) ([#7330](https://github.com/vuejs/core/issues/7330)) ([cd7c887](https://github.com/vuejs/core/commit/cd7c887b755810aedf83f3d458cb956d5b147f6f)) +* **reactivity:** track hasOwnProperty ([588bd44](https://github.com/vuejs/core/commit/588bd44f036b79d7dee5d23661aa7244f70e6beb)), closes [#2619](https://github.com/vuejs/core/issues/2619) [#2621](https://github.com/vuejs/core/issues/2621) +* **runtime-core:** ensure prop type validation warning shows custom class names ([#7198](https://github.com/vuejs/core/issues/7198)) ([620327d](https://github.com/vuejs/core/commit/620327d527593c6263a21500baddbae1ebc30db8)) +* **runtime-core:** fix keep-alive cache prune logic on vnodes with same type but different keys ([#7510](https://github.com/vuejs/core/issues/7510)) ([1fde49c](https://github.com/vuejs/core/commit/1fde49c0f57cc50fedf91366a274c9759d1d9a39)), closes [#7355](https://github.com/vuejs/core/issues/7355) +* **runtime-core:** set scope id before props ([#6948](https://github.com/vuejs/core/issues/6948)) ([da2ced1](https://github.com/vuejs/core/commit/da2ced15339b6fdb7a1459fa359bb79346a82bc2)), closes [#6923](https://github.com/vuejs/core/issues/6923) +* **runtime-dom:** style update error when component use shorthand properties ([#7425](https://github.com/vuejs/core/issues/7425)) ([b7cfa6f](https://github.com/vuejs/core/commit/b7cfa6f53952daced312862fbb3a88c86e42a77e)) +* **shared:** `feDistanceLight` changed to `feDistantLight` ([#7540](https://github.com/vuejs/core/issues/7540)) ([bef85e7](https://github.com/vuejs/core/commit/bef85e7975084b05af00b60ecd171c83f251c6d5)) +* **shared:** toNumber should only coerce strings ([b55846f](https://github.com/vuejs/core/commit/b55846f05c4a3b163be2ed70ce64014feec29fac)) +* **types/effectScope:** re-expose `active` as readonly property ([#6187](https://github.com/vuejs/core/issues/6187)) ([59ffe5e](https://github.com/vuejs/core/commit/59ffe5ee1f1618be119875313970c72050b37b03)), closes [#6186](https://github.com/vuejs/core/issues/6186) +* **types:** accept sync `serverPrefetch()` ([#7000](https://github.com/vuejs/core/issues/7000)) ([5f1883e](https://github.com/vuejs/core/commit/5f1883ec53547d0847e1270f5a8fb0c46396fb07)) +* **types:** add or update referrerpolicy ([#7199](https://github.com/vuejs/core/issues/7199)) ([1fa3d95](https://github.com/vuejs/core/commit/1fa3d9573051f549e6d381a5e88ec8d5d855e4c9)) +* **types:** allow assigning wider SetupContext type ([#2818](https://github.com/vuejs/core/issues/2818)) ([eb2a832](https://github.com/vuejs/core/commit/eb2a83283caa9de0a45881d860a3cbd9d0bdd279)), closes [#2362](https://github.com/vuejs/core/issues/2362) +* **types:** optional boolean props should have boolean type in return type of defineProps ([#7619](https://github.com/vuejs/core/issues/7619)) ([a0a010d](https://github.com/vuejs/core/commit/a0a010ddc9ba8ef3e883454c73997bf6fb40b385)), closes [#7116](https://github.com/vuejs/core/issues/7116) [#5847](https://github.com/vuejs/core/issues/5847) [#7487](https://github.com/vuejs/core/issues/7487) +* **v-model:** ensure v-model listener casing is consistent with manual v-on listener ([#7067](https://github.com/vuejs/core/issues/7067)) ([87c72ae](https://github.com/vuejs/core/commit/87c72ae49a315a5464dd0c6b00f07163d1cb39e9)), closes [#7066](https://github.com/vuejs/core/issues/7066) + + + ## [3.2.45](https://github.com/vuejs/core/compare/v3.2.44...v3.2.45) (2022-11-11) diff --git a/api-extractor.json b/api-extractor.json deleted file mode 100644 index bf3e80961a9..00000000000 --- a/api-extractor.json +++ /dev/null @@ -1,66 +0,0 @@ -// this the shared base config for all packages. -{ - "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - - "apiReport": { - "enabled": true, - "reportFolder": "/temp/" - }, - - "docModel": { - "enabled": true - }, - - "dtsRollup": { - "enabled": true - }, - - "tsdocMetadata": { - "enabled": false - }, - - "messages": { - "compilerMessageReporting": { - "default": { - "logLevel": "warning" - } - }, - - "extractorMessageReporting": { - "default": { - "logLevel": "warning", - "addToApiReportFile": true - }, - - "ae-missing-release-tag": { - "logLevel": "none" - } - }, - - "tsdocMessageReporting": { - "default": { - "logLevel": "warning" - }, - - "tsdoc-undefined-tag": { - "logLevel": "none" - }, - - "tsdoc-escape-greater-than": { - "logLevel": "none" - }, - - "tsdoc-malformed-inline-tag": { - "logLevel": "none" - }, - - "tsdoc-escape-right-brace": { - "logLevel": "none" - }, - - "tsdoc-unnecessary-backslash": { - "logLevel": "none" - } - } - } -} diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 5a75ee75584..00000000000 --- a/jest.config.js +++ /dev/null @@ -1,67 +0,0 @@ -module.exports = { - testEnvironment: 'jsdom', - preset: 'ts-jest', - setupFilesAfterEnv: ['./scripts/setupJestEnv.ts'], - transform: { - '^.+\\.tsx?$': [ - 'ts-jest', - { - tsconfig: { - target: 'esnext', - sourceMap: true - } - } - ] - }, - globals: { - __DEV__: true, - __TEST__: true, - __VERSION__: require('./package.json').version, - __BROWSER__: false, - __GLOBAL__: false, - __ESM_BUNDLER__: true, - __ESM_BROWSER__: false, - __NODE_JS__: true, - __SSR__: true, - __FEATURE_OPTIONS_API__: true, - __FEATURE_SUSPENSE__: true, - __FEATURE_PROD_DEVTOOLS__: false, - __COMPAT__: true - }, - coverageDirectory: 'coverage', - coverageReporters: ['html', 'lcov', 'text'], - collectCoverageFrom: [ - 'packages/*/src/**/*.ts', - '!packages/runtime-test/src/utils/**', - '!packages/template-explorer/**', - '!packages/sfc-playground/**', - '!packages/size-check/**', - '!packages/runtime-core/src/profiling.ts', - '!packages/runtime-core/src/customFormatter.ts', - // DOM transitions are tested via e2e so no coverage is collected - '!packages/runtime-dom/src/components/Transition*', - // only called in browsers - '!packages/vue/src/devCheck.ts', - // only used as a build entry - '!packages/vue/src/runtime.ts', - // mostly just entries - '!packages/vue-compat/**' - ], - watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'], - moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], - moduleNameMapper: { - '@vue/consolidate': '@vue/consolidate', - '@vue/compat': '/packages/vue-compat/src', - '^@vue/(.*?)$': '/packages/$1/src', - 'vue/compiler-sfc': '/packages/compiler-sfc/src', - 'vue/server-renderer': '/packages/server-renderer/src', - vue: '/packages/vue/src' - }, - rootDir: __dirname, - testMatch: ['/packages/**/__tests__/**/*spec.[jt]s?(x)'], - testPathIgnorePatterns: process.env.SKIP_E2E - ? // ignore example tests on netlify builds since they don't contribute - // to coverage and can cause netlify builds to fail - ['/node_modules/', '/examples/__tests__'] - : ['/node_modules/'] -} diff --git a/netlify.toml b/netlify.toml index 539f470641d..277cc55a7ce 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,3 +1,3 @@ [build.environment] - NODE_VERSION = "16" + NODE_VERSION = "18" NPM_FLAGS = "--version" # prevent Netlify npm install diff --git a/package.json b/package.json index 53bd782547d..af043f73b5c 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,25 @@ { "private": true, - "version": "3.2.45", - "packageManager": "pnpm@7.1.0", + "version": "3.2.47", + "packageManager": "pnpm@7.26.0", + "type": "module", "scripts": { "dev": "node scripts/dev.js", "build": "node scripts/build.js", + "build-dts": "tsc -p tsconfig.build.json && rollup -c rollup.dts.config.js", "size": "run-s size-global size-baseline", "size-global": "node scripts/build.js vue runtime-dom -f global -p", - "size-baseline": "node scripts/build.js runtime-dom runtime-core reactivity shared -f esm-bundler && cd packages/size-check && vite build && node brotli", + "size-baseline": "node scripts/build.js vue -f esm-bundler-runtime && node scripts/build.js runtime-dom runtime-core reactivity shared -f esm-bundler && cd packages/size-check && vite build && node brotli", + "check": "tsc --incremental --noEmit", "lint": "eslint --cache --ext .ts packages/*/{src,__tests__}/**.ts", "format": "prettier --write --cache --parser typescript \"**/*.[tj]s?(x)\"", "format-check": "prettier --check --cache --parser typescript \"**/*.[tj]s?(x)\"", - "test": "run-s \"test-unit {@}\" \"test-e2e {@}\"", - "test-unit": "jest --filter ./scripts/filter-unit.js", - "test-e2e": "node scripts/build.js vue -f global -d && jest --filter ./scripts/filter-e2e.js --runInBand", - "test-dts": "node scripts/build.js shared reactivity runtime-core runtime-dom -dt -f esm-bundler && npm run test-dts-only", - "test-dts-only": "tsc -p ./test-dts/tsconfig.json && tsc -p ./test-dts/tsconfig.build.json", - "test-coverage": "node scripts/build.js vue -f global -d && jest --runInBand --coverage --bail", + "test": "vitest", + "test-unit": "vitest -c vitest.unit.config.ts", + "test-e2e": "node scripts/build.js vue -f global -d && vitest -c vitest.e2e.config.ts", + "test-dts": "run-s build-dts test-dts-only", + "test-dts-only": "tsc -p ./packages/dts-test/tsconfig.test.json", + "test-coverage": "vitest -c vitest.unit.config.ts --coverage", "release": "node scripts/release.js", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "dev-esm": "node scripts/dev.js -if esm-bundler-runtime", @@ -35,10 +38,9 @@ "preinstall": "node ./scripts/preinstall.js", "postinstall": "simple-git-hooks" }, - "types": "test-dts/index.d.ts", "simple-git-hooks": { - "pre-commit": "pnpm lint-staged", - "commit-msg": "node scripts/verifyCommit.mjs" + "pre-commit": "pnpm lint-staged && pnpm check", + "commit-msg": "node scripts/verifyCommit.js" }, "lint-staged": { "*.{js,json}": [ @@ -53,56 +55,54 @@ "node": ">=16.11.0" }, "devDependencies": { - "@babel/types": "^7.12.0", + "@babel/parser": "^7.20.15", + "@babel/types": "^7.20.7", "@esbuild-plugins/node-modules-polyfill": "^0.1.4", - "@microsoft/api-extractor": "~7.20.0", + "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-commonjs": "^23.0.2", "@rollup/plugin-json": "^5.0.1", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.1", "@rollup/plugin-terser": "^0.1.0", "@types/hash-sum": "^1.0.0", - "@types/jest": "^29.2.2", "@types/node": "^16.4.7", "@typescript-eslint/parser": "^5.23.0", + "@vitest/coverage-istanbul": "^0.28.2", "@vue/consolidate": "0.17.3", - "@vue/reactivity": "workspace:*", - "@vue/runtime-core": "workspace:*", - "@vue/runtime-dom": "workspace:*", "brotli": "^1.3.2", "chalk": "^4.1.0", "conventional-changelog-cli": "^2.0.31", "csstype": "^3.0.3", "enquirer": "^2.3.2", - "esbuild": "^0.15.13", - "eslint": "^7.7.0", - "eslint-plugin-jest": "26.1.5", + "esbuild": "^0.17.4", + "eslint": "^8.33.0", + "eslint-plugin-jest": "^27.2.1", + "estree-walker": "^2.0.2", "execa": "^4.0.2", - "fs-extra": "^9.0.1", - "jest": "^29.3.1", - "jest-environment-jsdom": "^29.3.1", + "jsdom": "^21.1.0", "lint-staged": "^10.2.10", "lodash": "^4.17.15", + "magic-string": "^0.27.0", "marked": "^4.0.10", "minimist": "^1.2.0", "npm-run-all": "^4.1.5", "prettier": "^2.7.1", "pug": "^3.0.1", - "puppeteer": "^19.2.2", - "rollup": "~3.2.3", + "puppeteer": "^19.6.3", + "rollup": "~3.10.0", + "rollup-plugin-dts": "^5.1.1", + "rollup-plugin-esbuild": "^5.0.0", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-polyfill-node": "^0.11.0", - "rollup-plugin-typescript2": "^0.34.1", "semver": "^7.3.2", "serve": "^12.0.0", "simple-git-hooks": "^2.8.1", "terser": "^5.15.1", "todomvc-app-css": "^2.3.0", - "ts-jest": "^29.0.3", "tslib": "^2.4.0", - "typescript": "^4.8.0", - "vite": "^3.0.0", - "vue": "workspace:*" + "typescript": "^4.9.0", + "vite": "^4.0.4", + "vitest": "^0.28.2" } } diff --git a/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap index 036b7c8f953..a2871d8669b 100644 --- a/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1 -exports[`compiler: codegen ArrayExpression 1`] = ` +exports[`compiler: codegen > ArrayExpression 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { @@ -12,14 +12,14 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen CacheExpression 1`] = ` +exports[`compiler: codegen > CacheExpression 1`] = ` " export function render(_ctx, _cache) { return _cache[1] || (_cache[1] = foo) }" `; -exports[`compiler: codegen CacheExpression w/ isVNode: true 1`] = ` +exports[`compiler: codegen > CacheExpression w/ isVNode: true 1`] = ` " export function render(_ctx, _cache) { return _cache[1] || ( @@ -31,7 +31,7 @@ export function render(_ctx, _cache) { }" `; -exports[`compiler: codegen ConditionalExpression 1`] = ` +exports[`compiler: codegen > ConditionalExpression 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { @@ -44,31 +44,31 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen Element (callExpression + objectExpression + TemplateChildNode[]) 1`] = ` +exports[`compiler: codegen > Element (callExpression + objectExpression + TemplateChildNode[]) 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { - return _createElementVNode("div", { - id: "foo", + return _createElementVNode(\\"div\\", { + id: \\"foo\\", [prop]: bar, [foo + bar]: bar }, [ - _createElementVNode("p", { "some-key": "foo" }) + _createElementVNode(\\"p\\", { \\"some-key\\": \\"foo\\" }) ], 16) } }" `; -exports[`compiler: codegen assets + temps 1`] = ` +exports[`compiler: codegen > assets + temps 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { - const _component_Foo = _resolveComponent("Foo") - const _component_bar_baz = _resolveComponent("bar-baz") - const _component_barbaz = _resolveComponent("barbaz") - const _component_Qux = _resolveComponent("Qux", true) - const _directive_my_dir_0 = _resolveDirective("my_dir_0") - const _directive_my_dir_1 = _resolveDirective("my_dir_1") + const _component_Foo = _resolveComponent(\\"Foo\\") + const _component_bar_baz = _resolveComponent(\\"bar-baz\\") + const _component_barbaz = _resolveComponent(\\"barbaz\\") + const _component_Qux = _resolveComponent(\\"Qux\\", true) + const _directive_my_dir_0 = _resolveDirective(\\"my_dir_0\\") + const _directive_my_dir_1 = _resolveDirective(\\"my_dir_1\\") let _temp0, _temp1, _temp2 return null @@ -76,16 +76,16 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen comment 1`] = ` +exports[`compiler: codegen > comment 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { - return _createCommentVNode("foo") + return _createCommentVNode(\\"foo\\") } }" `; -exports[`compiler: codegen compound expression 1`] = ` +exports[`compiler: codegen > compound expression 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { @@ -94,7 +94,7 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen forNode 1`] = ` +exports[`compiler: codegen > forNode 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { @@ -103,7 +103,7 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen forNode with constant expression 1`] = ` +exports[`compiler: codegen > forNode with constant expression 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { @@ -112,7 +112,7 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen function mode preamble 1`] = ` +exports[`compiler: codegen > function mode preamble 1`] = ` "const _Vue = Vue return function render(_ctx, _cache) { @@ -124,7 +124,7 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen function mode preamble w/ prefixIdentifiers: true 1`] = ` +exports[`compiler: codegen > function mode preamble w/ prefixIdentifiers: true 1`] = ` "const { createVNode: _createVNode, resolveDirective: _resolveDirective } = Vue return function render(_ctx, _cache) { @@ -132,10 +132,10 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen hoists 1`] = ` +exports[`compiler: codegen > hoists 1`] = ` " const _hoisted_1 = hello -const _hoisted_2 = { id: "foo" } +const _hoisted_2 = { id: \\"foo\\" } return function render(_ctx, _cache) { with (_ctx) { @@ -144,7 +144,7 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen ifNode 1`] = ` +exports[`compiler: codegen > ifNode 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { @@ -155,7 +155,7 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen interpolation 1`] = ` +exports[`compiler: codegen > interpolation 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { @@ -164,16 +164,16 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen module mode preamble 1`] = ` -"import { createVNode as _createVNode, resolveDirective as _resolveDirective } from "vue" +exports[`compiler: codegen > module mode preamble 1`] = ` +"import { createVNode as _createVNode, resolveDirective as _resolveDirective } from \\"vue\\" export function render(_ctx, _cache) { return null }" `; -exports[`compiler: codegen module mode preamble w/ optimizeImports: true 1`] = ` -"import { createVNode, resolveDirective } from "vue" +exports[`compiler: codegen > module mode preamble w/ optimizeImports: true 1`] = ` +"import { createVNode, resolveDirective } from \\"vue\\" // Binding optimization for webpack code-split const _createVNode = createVNode, _resolveDirective = resolveDirective @@ -183,16 +183,16 @@ export function render(_ctx, _cache) { }" `; -exports[`compiler: codegen static text 1`] = ` +exports[`compiler: codegen > static text 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { - return "hello" + return \\"hello\\" } }" `; -exports[`compiler: codegen temps 1`] = ` +exports[`compiler: codegen > temps 1`] = ` " return function render(_ctx, _cache) { with (_ctx) { diff --git a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap index 02c995fe97f..1054453c53c 100644 --- a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap @@ -1,25 +1,25 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1 -exports[`compiler: integration tests function mode 1`] = ` +exports[`compiler: integration tests > function mode 1`] = ` "const _Vue = Vue return function render(_ctx, _cache) { with (_ctx) { const { toDisplayString: _toDisplayString, openBlock: _openBlock, createElementBlock: _createElementBlock, createCommentVNode: _createCommentVNode, createTextVNode: _createTextVNode, Fragment: _Fragment, renderList: _renderList, createElementVNode: _createElementVNode, normalizeClass: _normalizeClass } = _Vue - return (_openBlock(), _createElementBlock("div", { - id: "foo", + return (_openBlock(), _createElementBlock(\\"div\\", { + id: \\"foo\\", class: _normalizeClass(bar.baz) }, [ - _createTextVNode(_toDisplayString(world.burn()) + " ", 1 /* TEXT */), + _createTextVNode(_toDisplayString(world.burn()) + \\" \\", 1 /* TEXT */), ok - ? (_openBlock(), _createElementBlock("div", { key: 0 }, "yes")) + ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, \\"yes\\")) : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [ - _createTextVNode("no") + _createTextVNode(\\"no\\") ], 64 /* STABLE_FRAGMENT */)), (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(list, (value, index) => { - return (_openBlock(), _createElementBlock("div", null, [ - _createElementVNode("span", null, _toDisplayString(value + index), 1 /* TEXT */) + return (_openBlock(), _createElementBlock(\\"div\\", null, [ + _createElementVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */) ])) }), 256 /* UNKEYED_FRAGMENT */)) ], 2 /* CLASS */)) @@ -27,46 +27,46 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: integration tests function mode w/ prefixIdentifiers: true 1`] = ` +exports[`compiler: integration tests > function mode w/ prefixIdentifiers: true 1`] = ` "const { toDisplayString: _toDisplayString, openBlock: _openBlock, createElementBlock: _createElementBlock, createCommentVNode: _createCommentVNode, createTextVNode: _createTextVNode, Fragment: _Fragment, renderList: _renderList, createElementVNode: _createElementVNode, normalizeClass: _normalizeClass } = Vue return function render(_ctx, _cache) { - return (_openBlock(), _createElementBlock("div", { - id: "foo", + return (_openBlock(), _createElementBlock(\\"div\\", { + id: \\"foo\\", class: _normalizeClass(_ctx.bar.baz) }, [ - _createTextVNode(_toDisplayString(_ctx.world.burn()) + " ", 1 /* TEXT */), + _createTextVNode(_toDisplayString(_ctx.world.burn()) + \\" \\", 1 /* TEXT */), (_ctx.ok) - ? (_openBlock(), _createElementBlock("div", { key: 0 }, "yes")) + ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, \\"yes\\")) : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [ - _createTextVNode("no") + _createTextVNode(\\"no\\") ], 64 /* STABLE_FRAGMENT */)), (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => { - return (_openBlock(), _createElementBlock("div", null, [ - _createElementVNode("span", null, _toDisplayString(value + index), 1 /* TEXT */) + return (_openBlock(), _createElementBlock(\\"div\\", null, [ + _createElementVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */) ])) }), 256 /* UNKEYED_FRAGMENT */)) ], 2 /* CLASS */)) }" `; -exports[`compiler: integration tests module mode 1`] = ` -"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, createTextVNode as _createTextVNode, Fragment as _Fragment, renderList as _renderList, createElementVNode as _createElementVNode, normalizeClass as _normalizeClass } from "vue" +exports[`compiler: integration tests > module mode 1`] = ` +"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, createTextVNode as _createTextVNode, Fragment as _Fragment, renderList as _renderList, createElementVNode as _createElementVNode, normalizeClass as _normalizeClass } from \\"vue\\" export function render(_ctx, _cache) { - return (_openBlock(), _createElementBlock("div", { - id: "foo", + return (_openBlock(), _createElementBlock(\\"div\\", { + id: \\"foo\\", class: _normalizeClass(_ctx.bar.baz) }, [ - _createTextVNode(_toDisplayString(_ctx.world.burn()) + " ", 1 /* TEXT */), + _createTextVNode(_toDisplayString(_ctx.world.burn()) + \\" \\", 1 /* TEXT */), (_ctx.ok) - ? (_openBlock(), _createElementBlock("div", { key: 0 }, "yes")) + ? (_openBlock(), _createElementBlock(\\"div\\", { key: 0 }, \\"yes\\")) : (_openBlock(), _createElementBlock(_Fragment, { key: 1 }, [ - _createTextVNode("no") + _createTextVNode(\\"no\\") ], 64 /* STABLE_FRAGMENT */)), (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => { - return (_openBlock(), _createElementBlock("div", null, [ - _createElementVNode("span", null, _toDisplayString(value + index), 1 /* TEXT */) + return (_openBlock(), _createElementBlock(\\"div\\", null, [ + _createElementVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */) ])) }), 256 /* UNKEYED_FRAGMENT */)) ], 2 /* CLASS */)) diff --git a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap index 8a12c8c399f..81a6a8f1973 100644 --- a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1 -exports[`compiler: parse Errors ABRUPT_CLOSING_OF_EMPTY_COMMENT 1`] = ` +exports[`compiler: parse > Errors > ABRUPT_CLOSING_OF_EMPTY_COMMENT > 1`] = ` { "cached": 0, "children": [ @@ -70,7 +70,7 @@ exports[`compiler: parse Errors ABRUPT_CLOSING_OF_EMPTY_COMMENT 1`] = ` +exports[`compiler: parse > Errors > UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME > 1`] = ` { "cached": 0, "children": [ @@ -5719,7 +5719,7 @@ exports[`compiler: parse Errors UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME
1`] = ` +exports[`compiler: parse > Errors > UNEXPECTED_SOLIDUS_IN_TAG > 1`] = ` { "cached": 0, "children": [ @@ -5832,7 +5832,7 @@ exports[`compiler: parse Errors UNEXPECTED_SOLIDUS_IN_TAG