From 8ee5b89e00cf74b6b572e7f1b777a81c883dce2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Wed, 20 Dec 2023 07:09:20 +0800 Subject: [PATCH] style: apply prettier&eslint --- .github/renovate.json5 | 20 +- .vscode/launch.json | 2 +- .../compiler-core/__tests__/codegen.spec.ts | 292 ++--- .../compiler-core/__tests__/compile.spec.ts | 108 +- .../compiler-core/__tests__/parse.spec.ts | 1104 ++++++++--------- .../compiler-core/__tests__/scopeId.spec.ts | 22 +- packages/compiler-core/__tests__/testUtils.ts | 30 +- .../compiler-core/__tests__/transform.spec.ts | 100 +- .../__tests__/transforms/hoistStatic.spec.ts | 258 ++-- .../transforms/noopDirectiveTransform.spec.ts | 10 +- .../transforms/transformElement.spec.ts | 568 ++++----- .../transforms/transformExpressions.spec.ts | 218 ++-- .../transforms/transformSlotOutlet.spec.ts | 186 +-- .../transforms/transformText.spec.ts | 88 +- .../__tests__/transforms/vBind.spec.ts | 198 +-- .../__tests__/transforms/vFor.spec.ts | 330 ++--- .../__tests__/transforms/vIf.spec.ts | 249 ++-- .../__tests__/transforms/vMemo.spec.ts | 18 +- .../__tests__/transforms/vModel.spec.ts | 267 ++-- .../__tests__/transforms/vOn.spec.ts | 326 ++--- .../__tests__/transforms/vOnce.spec.ts | 46 +- .../__tests__/transforms/vSlot.spec.ts | 462 +++---- .../compiler-core/__tests__/utils.spec.ts | 10 +- packages/compiler-core/src/ast.ts | 110 +- packages/compiler-core/src/babelUtils.ts | 30 +- packages/compiler-core/src/codegen.ts | 168 +-- .../compiler-core/src/compat/compatConfig.ts | 32 +- .../src/compat/transformFilter.ts | 16 +- packages/compiler-core/src/compile.ts | 40 +- packages/compiler-core/src/errors.ts | 8 +- packages/compiler-core/src/index.ts | 14 +- packages/compiler-core/src/options.ts | 24 +- packages/compiler-core/src/parser.ts | 126 +- packages/compiler-core/src/runtimeHelpers.ts | 4 +- packages/compiler-core/src/tokenizer.ts | 40 +- packages/compiler-core/src/transform.ts | 74 +- .../src/transforms/hoistStatic.ts | 52 +- .../src/transforms/noopDirectiveTransform.ts | 2 +- .../src/transforms/transformElement.ts | 154 +-- .../src/transforms/transformExpression.ts | 56 +- .../src/transforms/transformSlotOutlet.ts | 28 +- .../src/transforms/transformText.ts | 24 +- .../compiler-core/src/transforms/vBind.ts | 12 +- packages/compiler-core/src/transforms/vFor.ts | 118 +- packages/compiler-core/src/transforms/vIf.ts | 84 +- .../compiler-core/src/transforms/vMemo.ts | 12 +- .../compiler-core/src/transforms/vModel.ts | 42 +- packages/compiler-core/src/transforms/vOn.ts | 30 +- .../compiler-core/src/transforms/vOnce.ts | 4 +- .../compiler-core/src/transforms/vSlot.ts | 109 +- packages/compiler-core/src/utils.ts | 104 +- .../compiler-core/src/validateExpression.ts | 16 +- .../__tests__/decoderHtmlBrowser.spec.ts | 8 +- packages/compiler-dom/__tests__/parse.spec.ts | 132 +- .../__tests__/transforms/Transition.spec.ts | 28 +- .../transforms/ignoreSideEffectTags.spec.ts | 6 +- .../transforms/stringifyStatic.spec.ts | 230 ++-- .../transforms/transformStyle.spec.ts | 34 +- .../__tests__/transforms/vHtml.spec.ts | 26 +- .../__tests__/transforms/vModel.spec.ts | 36 +- .../__tests__/transforms/vOn.spec.ts | 156 +-- .../__tests__/transforms/vShow.spec.ts | 12 +- .../__tests__/transforms/vText.spec.ts | 30 +- packages/compiler-dom/src/errors.ts | 16 +- packages/compiler-dom/src/index.ts | 28 +- packages/compiler-dom/src/parserOptions.ts | 8 +- packages/compiler-dom/src/runtimeHelpers.ts | 2 +- .../compiler-dom/src/transforms/Transition.ts | 20 +- .../src/transforms/ignoreSideEffectTags.ts | 6 +- .../src/transforms/stringifyStatic.ts | 58 +- .../src/transforms/transformStyle.ts | 14 +- packages/compiler-dom/src/transforms/vHtml.ts | 16 +- .../compiler-dom/src/transforms/vModel.ts | 32 +- packages/compiler-dom/src/transforms/vOn.ts | 42 +- packages/compiler-dom/src/transforms/vShow.ts | 8 +- packages/compiler-dom/src/transforms/vText.ts | 22 +- .../__tests__/compileScript.spec.ts | 190 +-- .../compileScript/defineEmits.spec.ts | 10 +- .../compileScript/defineExpose.spec.ts | 2 +- .../compileScript/defineModel.spec.ts | 40 +- .../compileScript/defineOptions.spec.ts | 46 +- .../compileScript/defineProps.spec.ts | 88 +- .../definePropsDestructure.spec.ts | 96 +- .../compileScript/defineSlots.spec.ts | 2 +- .../compileScript/hoistStatic.spec.ts | 28 +- .../compileScript/resolveType.spec.ts | 306 ++--- .../__tests__/compileStyle.spec.ts | 58 +- .../__tests__/compileTemplate.spec.ts | 100 +- .../compiler-sfc/__tests__/cssVars.spec.ts | 64 +- packages/compiler-sfc/__tests__/parse.spec.ts | 82 +- .../__tests__/rewriteDefault.spec.ts | 79 +- .../templateTransformAssetUrl.spec.ts | 56 +- .../__tests__/templateTransformSrcset.spec.ts | 32 +- .../__tests__/templateUtils.spec.ts | 4 +- packages/compiler-sfc/__tests__/utils.ts | 14 +- packages/compiler-sfc/src/cache.ts | 2 +- packages/compiler-sfc/src/compileScript.ts | 152 +-- packages/compiler-sfc/src/compileStyle.ts | 58 +- packages/compiler-sfc/src/compileTemplate.ts | 72 +- packages/compiler-sfc/src/index.ts | 16 +- packages/compiler-sfc/src/parse.ts | 78 +- packages/compiler-sfc/src/rewriteDefault.ts | 14 +- .../src/script/analyzeScriptBindings.ts | 8 +- packages/compiler-sfc/src/script/context.ts | 32 +- .../compiler-sfc/src/script/defineEmits.ts | 20 +- .../compiler-sfc/src/script/defineExpose.ts | 6 +- .../compiler-sfc/src/script/defineModel.ts | 17 +- .../compiler-sfc/src/script/defineOptions.ts | 14 +- .../compiler-sfc/src/script/defineProps.ts | 68 +- .../src/script/definePropsDestructure.ts | 38 +- .../compiler-sfc/src/script/defineSlots.ts | 8 +- .../src/script/importUsageCheck.ts | 8 +- .../compiler-sfc/src/script/normalScript.ts | 8 +- .../compiler-sfc/src/script/resolveType.ts | 224 ++-- .../compiler-sfc/src/script/topLevelAwait.ts | 14 +- packages/compiler-sfc/src/script/utils.ts | 13 +- packages/compiler-sfc/src/style/cssVars.ts | 34 +- .../compiler-sfc/src/style/pluginScoped.ts | 20 +- packages/compiler-sfc/src/style/pluginTrim.ts | 4 +- .../compiler-sfc/src/style/preprocessors.ts | 28 +- .../src/template/templateUtils.ts | 2 +- .../src/template/transformAssetUrl.ts | 42 +- .../src/template/transformSrcset.ts | 31 +- packages/compiler-sfc/src/warn.ts | 2 +- .../__tests__/ssrComponent.spec.ts | 8 +- .../compiler-ssr/__tests__/ssrElement.spec.ts | 30 +- .../__tests__/ssrInjectCssVars.spec.ts | 24 +- .../compiler-ssr/__tests__/ssrPortal.spec.ts | 2 +- .../compiler-ssr/__tests__/ssrScopeId.spec.ts | 28 +- .../__tests__/ssrSlotOutlet.spec.ts | 14 +- .../__tests__/ssrSuspense.spec.ts | 2 +- .../compiler-ssr/__tests__/ssrText.spec.ts | 14 +- .../__tests__/ssrTransitionGroup.spec.ts | 18 +- .../compiler-ssr/__tests__/ssrVFor.spec.ts | 12 +- .../compiler-ssr/__tests__/ssrVIf.spec.ts | 9 +- .../compiler-ssr/__tests__/ssrVModel.spec.ts | 32 +- .../compiler-ssr/__tests__/ssrVShow.spec.ts | 10 +- packages/compiler-ssr/__tests__/utils.ts | 2 +- packages/compiler-ssr/src/errors.ts | 14 +- packages/compiler-ssr/src/index.ts | 30 +- packages/compiler-ssr/src/runtimeHelpers.ts | 2 +- .../compiler-ssr/src/ssrCodegenTransform.ts | 64 +- .../src/transforms/ssrInjectCssVars.ts | 14 +- .../transforms/ssrInjectFallthroughAttrs.ts | 16 +- .../src/transforms/ssrTransformComponent.ts | 116 +- .../src/transforms/ssrTransformElement.ts | 145 +-- .../src/transforms/ssrTransformSlotOutlet.ts | 22 +- .../src/transforms/ssrTransformSuspense.ts | 32 +- .../src/transforms/ssrTransformTeleport.ts | 30 +- .../src/transforms/ssrTransformTransition.ts | 15 +- .../transforms/ssrTransformTransitionGroup.ts | 29 +- .../compiler-ssr/src/transforms/ssrVFor.ts | 26 +- .../compiler-ssr/src/transforms/ssrVIf.ts | 32 +- .../compiler-ssr/src/transforms/ssrVModel.ts | 78 +- .../compiler-ssr/src/transforms/ssrVShow.ts | 22 +- packages/dts-built-test/src/index.ts | 2 +- packages/dts-test/appDirective.test-d.ts | 2 +- packages/dts-test/appUse.test-d.ts | 20 +- packages/dts-test/built.test-d.ts | 2 +- packages/dts-test/compiler.test-d.ts | 12 +- packages/dts-test/component.test-d.ts | 100 +- .../dts-test/componentInstance.test-d.tsx | 36 +- .../componentTypeExtensions.test-d.tsx | 8 +- packages/dts-test/defineComponent.test-d.tsx | 336 ++--- .../dts-test/defineCustomElement.test-d.ts | 30 +- packages/dts-test/extractProps.test-d.ts | 10 +- .../dts-test/functionalComponent.test-d.tsx | 4 +- packages/dts-test/h.test-d.ts | 66 +- packages/dts-test/inject.test-d.ts | 2 +- packages/dts-test/reactivity.test-d.ts | 17 +- packages/dts-test/ref.test-d.ts | 92 +- packages/dts-test/setupHelpers.test-d.ts | 56 +- packages/dts-test/tsx.test-d.tsx | 18 +- packages/dts-test/watch.test-d.ts | 16 +- packages/global.d.ts | 2 +- .../__tests__/collections/Map.spec.ts | 4 +- .../__tests__/collections/Set.spec.ts | 4 +- .../__tests__/collections/WeakMap.spec.ts | 2 +- .../__tests__/collections/WeakSet.spec.ts | 2 +- .../collections/shallowReadonly.spec.ts | 22 +- .../reactivity/__tests__/computed.bench.ts | 4 +- .../reactivity/__tests__/computed.spec.ts | 38 +- packages/reactivity/__tests__/effect.spec.ts | 50 +- .../reactivity/__tests__/effectScope.spec.ts | 12 +- packages/reactivity/__tests__/gc.spec.ts | 4 +- .../reactivity/__tests__/reactive.spec.ts | 18 +- .../__tests__/reactiveArray.bench.ts | 2 +- .../__tests__/reactiveArray.spec.ts | 4 +- .../reactivity/__tests__/reactiveMap.bench.ts | 2 +- .../__tests__/reactiveObject.bench.ts | 2 +- .../reactivity/__tests__/readonly.spec.ts | 58 +- packages/reactivity/__tests__/ref.bench.ts | 2 +- packages/reactivity/__tests__/ref.spec.ts | 32 +- .../__tests__/shallowReactive.spec.ts | 16 +- .../__tests__/shallowReadonly.spec.ts | 26 +- packages/reactivity/src/baseHandlers.ts | 38 +- packages/reactivity/src/collectionHandlers.ts | 56 +- packages/reactivity/src/computed.ts | 18 +- packages/reactivity/src/constants.ts | 8 +- packages/reactivity/src/dep.ts | 2 +- packages/reactivity/src/effect.ts | 16 +- packages/reactivity/src/effectScope.ts | 8 +- packages/reactivity/src/index.ts | 10 +- packages/reactivity/src/reactive.ts | 26 +- packages/reactivity/src/reactiveEffect.ts | 16 +- packages/reactivity/src/ref.ts | 54 +- .../__tests__/apiAsyncComponent.spec.ts | 120 +- .../__tests__/apiCreateApp.spec.ts | 132 +- .../runtime-core/__tests__/apiExpose.spec.ts | 72 +- .../runtime-core/__tests__/apiInject.spec.ts | 94 +- .../__tests__/apiLifecycle.spec.ts | 84 +- .../runtime-core/__tests__/apiOptions.spec.ts | 506 ++++---- .../__tests__/apiSetupContext.spec.ts | 54 +- .../__tests__/apiSetupHelpers.spec.ts | 146 +-- .../runtime-core/__tests__/apiWatch.bench.ts | 2 +- .../runtime-core/__tests__/apiWatch.spec.ts | 190 +-- .../__tests__/componentEmits.spec.ts | 114 +- .../__tests__/componentProps.spec.ts | 182 +-- .../__tests__/componentPublicInstance.spec.ts | 93 +- .../__tests__/componentSlots.spec.ts | 64 +- .../components/BaseTransition.spec.ts | 138 +-- .../__tests__/components/KeepAlive.spec.ts | 154 +-- .../__tests__/components/Suspense.spec.ts | 372 +++--- .../__tests__/components/Teleport.spec.ts | 186 +-- .../runtime-core/__tests__/directives.spec.ts | 71 +- .../__tests__/errorHandling.spec.ts | 104 +- packages/runtime-core/__tests__/h.spec.ts | 24 +- .../__tests__/helpers/createSlots.spec.ts | 14 +- .../__tests__/helpers/renderList.spec.ts | 16 +- .../__tests__/helpers/renderSlot.spec.ts | 20 +- .../__tests__/helpers/resolveAssets.spec.ts | 48 +- .../__tests__/helpers/toHandlers.spec.ts | 4 +- .../__tests__/helpers/withMemo.spec.ts | 34 +- packages/runtime-core/__tests__/hmr.spec.ts | 150 +-- .../runtime-core/__tests__/hydration.spec.ts | 347 +++--- packages/runtime-core/__tests__/misc.spec.ts | 4 +- .../rendererAttrsFallthrough.spec.ts | 146 +-- .../__tests__/rendererChildren.spec.ts | 108 +- .../__tests__/rendererComponent.spec.ts | 90 +- .../__tests__/rendererElement.spec.ts | 6 +- .../__tests__/rendererFragment.spec.ts | 130 +- .../__tests__/rendererOptimizedMode.spec.ts | 286 ++--- .../__tests__/rendererTemplateRef.spec.ts | 104 +- .../runtime-core/__tests__/scheduler.spec.ts | 12 +- .../runtime-core/__tests__/scopeId.spec.ts | 78 +- packages/runtime-core/__tests__/vnode.spec.ts | 152 +-- .../runtime-core/__tests__/vnodeHooks.spec.ts | 28 +- .../runtime-core/src/apiAsyncComponent.ts | 34 +- packages/runtime-core/src/apiComputed.ts | 4 +- packages/runtime-core/src/apiCreateApp.ts | 68 +- .../runtime-core/src/apiDefineComponent.ts | 66 +- packages/runtime-core/src/apiInject.ts | 8 +- packages/runtime-core/src/apiLifecycle.ts | 26 +- packages/runtime-core/src/apiSetupHelpers.ts | 88 +- packages/runtime-core/src/apiWatch.ts | 97 +- .../src/compat/attrsFallthrough.ts | 4 +- .../runtime-core/src/compat/compatConfig.ts | 114 +- packages/runtime-core/src/compat/component.ts | 10 +- .../runtime-core/src/compat/componentAsync.ts | 6 +- .../src/compat/componentFunctional.ts | 12 +- .../src/compat/componentVModel.ts | 16 +- .../src/compat/customDirective.ts | 14 +- packages/runtime-core/src/compat/global.ts | 84 +- .../runtime-core/src/compat/globalConfig.ts | 12 +- packages/runtime-core/src/compat/instance.ts | 22 +- .../src/compat/instanceChildren.ts | 10 +- .../src/compat/instanceEventEmitter.ts | 20 +- .../src/compat/instanceListeners.ts | 4 +- packages/runtime-core/src/compat/props.ts | 13 +- packages/runtime-core/src/compat/renderFn.ts | 60 +- .../runtime-core/src/compat/renderHelpers.ts | 20 +- packages/runtime-core/src/component.ts | 167 +-- packages/runtime-core/src/componentEmits.ts | 46 +- packages/runtime-core/src/componentOptions.ts | 168 +-- packages/runtime-core/src/componentProps.ts | 82 +- .../src/componentPublicInstance.ts | 120 +- .../src/componentRenderContext.ts | 6 +- .../runtime-core/src/componentRenderUtils.ts | 68 +- packages/runtime-core/src/componentSlots.ts | 46 +- .../src/components/BaseTransition.ts | 56 +- .../runtime-core/src/components/KeepAlive.ts | 68 +- .../runtime-core/src/components/Suspense.ts | 120 +- .../runtime-core/src/components/Teleport.ts | 68 +- packages/runtime-core/src/customFormatter.ts | 34 +- packages/runtime-core/src/devtools.ts | 26 +- packages/runtime-core/src/directives.ts | 28 +- packages/runtime-core/src/enums.ts | 2 +- packages/runtime-core/src/errorHandling.ts | 22 +- packages/runtime-core/src/featureFlags.ts | 2 +- packages/runtime-core/src/h.ts | 68 +- .../runtime-core/src/helpers/createSlots.ts | 4 +- .../runtime-core/src/helpers/renderList.ts | 20 +- .../runtime-core/src/helpers/renderSlot.ts | 24 +- .../runtime-core/src/helpers/resolveAssets.ts | 22 +- .../runtime-core/src/helpers/toHandlers.ts | 4 +- .../runtime-core/src/helpers/useSsrContext.ts | 2 +- packages/runtime-core/src/helpers/withMemo.ts | 4 +- packages/runtime-core/src/hmr.ts | 24 +- packages/runtime-core/src/hydration.ts | 110 +- packages/runtime-core/src/index.ts | 60 +- packages/runtime-core/src/profiling.ts | 9 +- packages/runtime-core/src/renderer.ts | 298 ++--- .../runtime-core/src/rendererTemplateRef.ts | 18 +- packages/runtime-core/src/scheduler.ts | 14 +- packages/runtime-core/src/vnode.ts | 108 +- packages/runtime-core/src/warning.ts | 26 +- .../runtime-dom/__tests__/createApp.spec.ts | 6 +- .../__tests__/customElement.spec.ts | 130 +- .../__tests__/customizedBuiltIn.spec.ts | 6 +- .../__tests__/directives/vCloak.spec.ts | 2 +- .../__tests__/directives/vModel.spec.ts | 250 ++-- .../__tests__/directives/vOn.spec.ts | 8 +- .../__tests__/directives/vShow.spec.ts | 26 +- .../__tests__/helpers/useCssModule.spec.ts | 14 +- .../__tests__/helpers/useCssVars.spec.ts | 58 +- .../runtime-dom/__tests__/nodeOps.spec.ts | 12 +- .../runtime-dom/__tests__/patchClass.spec.ts | 5 +- .../runtime-dom/__tests__/patchEvents.spec.ts | 2 +- .../runtime-dom/__tests__/patchProps.spec.ts | 20 +- .../runtime-dom/__tests__/patchStyle.spec.ts | 20 +- packages/runtime-dom/src/apiCustomElement.ts | 72 +- .../runtime-dom/src/components/Transition.ts | 42 +- .../src/components/TransitionGroup.ts | 48 +- packages/runtime-dom/src/directives/vModel.ts | 40 +- packages/runtime-dom/src/directives/vOn.ts | 20 +- packages/runtime-dom/src/directives/vShow.ts | 4 +- .../runtime-dom/src/helpers/useCssModule.ts | 2 +- .../runtime-dom/src/helpers/useCssVars.ts | 12 +- packages/runtime-dom/src/index.ts | 52 +- packages/runtime-dom/src/jsx.ts | 4 +- packages/runtime-dom/src/modules/attrs.ts | 14 +- packages/runtime-dom/src/modules/class.ts | 2 +- packages/runtime-dom/src/modules/events.ts | 16 +- packages/runtime-dom/src/modules/props.ts | 10 +- packages/runtime-dom/src/modules/style.ts | 8 +- packages/runtime-dom/src/nodeOps.ts | 6 +- packages/runtime-dom/src/patchProp.ts | 10 +- .../__tests__/testRuntime.spec.ts | 64 +- packages/runtime-test/src/index.ts | 10 +- packages/runtime-test/src/nodeOps.ts | 30 +- packages/runtime-test/src/patchProp.ts | 6 +- packages/runtime-test/src/serialize.ts | 16 +- packages/runtime-test/src/triggerEvent.ts | 4 +- .../server-renderer/__tests__/render.spec.ts | 416 ++++--- .../__tests__/ssrAttrFallthrough.spec.ts | 30 +- .../__tests__/ssrCompilerOptions.spec.ts | 68 +- .../__tests__/ssrComputed.spec.ts | 4 +- .../__tests__/ssrDirectives.spec.ts | 322 ++--- .../__tests__/ssrDynamicComponent.spec.ts | 34 +- .../__tests__/ssrInterpolate.spec.ts | 14 +- .../__tests__/ssrRenderAttrs.spec.ts | 74 +- .../__tests__/ssrRenderList.spec.ts | 10 +- .../__tests__/ssrScopeId.spec.ts | 60 +- .../server-renderer/__tests__/ssrSlot.spec.ts | 86 +- .../__tests__/ssrSuspense.spec.ts | 46 +- .../__tests__/ssrTeleport.spec.ts | 66 +- .../__tests__/ssrVModelHelpers.spec.ts | 62 +- .../__tests__/ssrWatch.spec.ts | 6 +- .../__tests__/webStream.spec.ts | 20 +- .../server-renderer/src/helpers/ssrCompile.ts | 32 +- .../src/helpers/ssrGetDirectiveProps.ts | 8 +- .../src/helpers/ssrRenderAttrs.ts | 20 +- .../src/helpers/ssrRenderComponent.ts | 15 +- .../src/helpers/ssrRenderList.ts | 4 +- .../src/helpers/ssrRenderSlot.ts | 19 +- .../src/helpers/ssrRenderSuspense.ts | 4 +- .../src/helpers/ssrRenderTeleport.ts | 11 +- .../src/helpers/ssrVModelHelpers.ts | 6 +- packages/server-renderer/src/index.ts | 2 +- packages/server-renderer/src/internal.ts | 4 +- packages/server-renderer/src/render.ts | 70 +- .../server-renderer/src/renderToStream.ts | 46 +- .../server-renderer/src/renderToString.ts | 10 +- packages/sfc-playground/src/App.vue | 14 +- packages/sfc-playground/src/Header.vue | 4 +- packages/sfc-playground/src/VersionSelect.vue | 2 +- .../sfc-playground/src/download/download.ts | 2 +- .../src/download/template/vite.config.js | 2 +- packages/sfc-playground/src/icons/GitHub.vue | 3 +- packages/sfc-playground/src/icons/Moon.vue | 5 +- packages/sfc-playground/src/icons/Reload.vue | 14 +- packages/sfc-playground/src/icons/Sun.vue | 45 +- packages/sfc-playground/src/main.ts | 2 +- .../sfc-playground/src/vue-dev-proxy-prod.ts | 2 +- packages/sfc-playground/vite.config.ts | 26 +- packages/shared/__tests__/codeframe.spec.ts | 4 +- packages/shared/__tests__/looseEqual.spec.ts | 14 +- .../shared/__tests__/normalizeProp.spec.ts | 16 +- .../shared/__tests__/toDisplayString.spec.ts | 24 +- packages/shared/src/codeframe.ts | 6 +- packages/shared/src/domAttrConfig.ts | 8 +- packages/shared/src/general.ts | 10 +- packages/shared/src/makeMap.ts | 2 +- packages/shared/src/normalizeProp.ts | 6 +- packages/shared/src/patchFlags.ts | 4 +- packages/shared/src/shapeFlags.ts | 2 +- packages/shared/src/slotFlags.ts | 4 +- packages/shared/src/toDisplayString.ts | 12 +- packages/template-explorer/src/index.ts | 68 +- packages/template-explorer/src/options.ts | 66 +- packages/template-explorer/src/theme.ts | 118 +- packages/template-explorer/style.css | 5 +- .../vue-compat/__tests__/compiler.spec.ts | 44 +- .../__tests__/componentAsync.spec.ts | 24 +- .../__tests__/componentFunctional.spec.ts | 32 +- .../__tests__/componentVModel.spec.ts | 20 +- packages/vue-compat/__tests__/filters.spec.ts | 72 +- packages/vue-compat/__tests__/global.spec.ts | 124 +- .../vue-compat/__tests__/globalConfig.spec.ts | 12 +- .../vue-compat/__tests__/instance.spec.ts | 90 +- packages/vue-compat/__tests__/misc.spec.ts | 82 +- packages/vue-compat/__tests__/options.spec.ts | 50 +- .../vue-compat/__tests__/renderFn.spec.ts | 112 +- packages/vue-compat/__tests__/utils.ts | 4 +- packages/vue-compat/src/createCompatVue.ts | 12 +- packages/vue-compat/src/dev.ts | 2 +- packages/vue-compat/src/index.ts | 28 +- packages/vue-compat/src/runtime.ts | 2 +- .../vue/__tests__/customElementCasing.spec.ts | 6 +- packages/vue/__tests__/e2e/Transition.spec.ts | 476 +++---- .../vue/__tests__/e2e/TransitionGroup.spec.ts | 98 +- packages/vue/__tests__/e2e/commits.mock.ts | 126 +- packages/vue/__tests__/e2e/commits.spec.ts | 12 +- packages/vue/__tests__/e2e/e2eUtils.ts | 22 +- packages/vue/__tests__/e2e/grid.spec.ts | 24 +- packages/vue/__tests__/e2e/markdown.spec.ts | 12 +- packages/vue/__tests__/e2e/svg.spec.ts | 20 +- packages/vue/__tests__/e2e/todomvc.spec.ts | 12 +- packages/vue/__tests__/e2e/tree.spec.ts | 42 +- packages/vue/__tests__/index.spec.ts | 66 +- .../vue/__tests__/mathmlNamespace.spec.ts | 6 +- .../__tests__/runtimeCompilerOptions.spec.ts | 24 +- packages/vue/__tests__/svgNamespace.spec.ts | 6 +- packages/vue/index.mjs | 2 +- packages/vue/jsx-runtime/index.d.ts | 4 +- packages/vue/jsx-runtime/index.mjs | 7 +- packages/vue/jsx.d.ts | 4 +- packages/vue/macros.d.ts | 22 +- packages/vue/server-renderer/index.mjs | 2 +- packages/vue/src/dev.ts | 2 +- packages/vue/src/index.ts | 28 +- packages/vue/src/runtime.ts | 2 +- rollup.config.js | 58 +- rollup.dts.config.js | 20 +- scripts/aliases.js | 4 +- scripts/build.js | 22 +- scripts/dev.js | 22 +- scripts/inline-enums.js | 34 +- scripts/pre-dev-sfc.js | 4 +- scripts/release.js | 56 +- scripts/setupVitest.ts | 20 +- scripts/size-report.ts | 8 +- scripts/usage-size.ts | 24 +- scripts/utils.js | 4 +- scripts/verifyCommit.js | 8 +- vitest.config.ts | 16 +- vitest.e2e.config.ts | 4 +- vitest.unit.config.ts | 4 +- 458 files changed, 12418 insertions(+), 12194 deletions(-) diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 088913317c7..a43f4ae30cf 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -7,35 +7,35 @@ packageRules: [ { depTypeList: ['peerDependencies'], - enabled: false + enabled: false, }, { groupName: 'test', matchPackageNames: ['vitest', 'jsdom', 'puppeteer'], - matchPackagePrefixes: ['@vitest'] + matchPackagePrefixes: ['@vitest'], }, { groupName: 'playground', matchFileNames: [ 'packages/sfc-playground/package.json', - 'packages/template-explorer/package.json' - ] + 'packages/template-explorer/package.json', + ], }, { groupName: 'compiler', matchPackageNames: ['magic-string'], - matchPackagePrefixes: ['@babel', 'postcss'] + matchPackagePrefixes: ['@babel', 'postcss'], }, { groupName: 'build', matchPackageNames: ['vite', 'terser'], - matchPackagePrefixes: ['rollup', 'esbuild', '@rollup', '@vitejs'] + matchPackagePrefixes: ['rollup', 'esbuild', '@rollup', '@vitejs'], }, { groupName: 'lint', matchPackageNames: ['simple-git-hooks', 'lint-staged'], - matchPackagePrefixes: ['@typescript-eslint', 'eslint', 'prettier'] - } + matchPackagePrefixes: ['@typescript-eslint', 'eslint', 'prettier'], + }, ], ignoreDeps: [ 'vue', @@ -45,6 +45,6 @@ 'typescript', // ESM only - 'estree-walker' - ] + 'estree-walker', + ], } diff --git a/.vscode/launch.json b/.vscode/launch.json index b63ffc79b80..b616400b48e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -21,7 +21,7 @@ "console": "integratedTerminal", "sourceMaps": true, "windows": { - "program": "${workspaceFolder}/node_modules/jest/bin/jest", + "program": "${workspaceFolder}/node_modules/jest/bin/jest" } } ] diff --git a/packages/compiler-core/__tests__/codegen.spec.ts b/packages/compiler-core/__tests__/codegen.spec.ts index 4938e758546..9c923075634 100644 --- a/packages/compiler-core/__tests__/codegen.spec.ts +++ b/packages/compiler-core/__tests__/codegen.spec.ts @@ -1,38 +1,38 @@ import { - locStub, - generate, + ConstantTypes, + type DirectiveArguments, + type ForCodegenNode, + type IfConditionalExpression, NodeTypes, - RootNode, - createSimpleExpression, - createObjectExpression, - createObjectProperty, + type RootNode, + type VNodeCall, createArrayExpression, - createCompoundExpression, - createInterpolation, + createAssignmentExpression, + createBlockStatement, + createCacheExpression, createCallExpression, + createCompoundExpression, createConditionalExpression, - ForCodegenNode, - createCacheExpression, - createTemplateLiteral, - createBlockStatement, createIfStatement, - createAssignmentExpression, - IfConditionalExpression, + createInterpolation, + createObjectExpression, + createObjectProperty, + createSimpleExpression, + createTemplateLiteral, createVNodeCall, - VNodeCall, - DirectiveArguments, - ConstantTypes + generate, + locStub, } from '../src' import { - CREATE_VNODE, - TO_DISPLAY_STRING, - RESOLVE_DIRECTIVE, - helperNameMap, - RESOLVE_COMPONENT, CREATE_COMMENT, + CREATE_ELEMENT_VNODE, + CREATE_VNODE, FRAGMENT, RENDER_LIST, - CREATE_ELEMENT_VNODE + RESOLVE_COMPONENT, + RESOLVE_DIRECTIVE, + TO_DISPLAY_STRING, + helperNameMap, } from '../src/runtimeHelpers' import { createElementWithCodegen, genFlagText } from './testUtils' import { PatchFlags } from '@vue/shared' @@ -51,59 +51,59 @@ function createRoot(options: Partial = {}): RootNode { temps: 0, codegenNode: createSimpleExpression(`null`, false), loc: locStub, - ...options + ...options, } } describe('compiler: codegen', () => { test('module mode preamble', () => { const root = createRoot({ - helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]) + helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]), }) const { code } = generate(root, { mode: 'module' }) expect(code).toMatch( - `import { ${helperNameMap[CREATE_VNODE]} as _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} as _${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"` + `import { ${helperNameMap[CREATE_VNODE]} as _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} as _${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"`, ) expect(code).toMatchSnapshot() }) test('module mode preamble w/ optimizeImports: true', () => { const root = createRoot({ - helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]) + helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]), }) const { code } = generate(root, { mode: 'module', optimizeImports: true }) expect(code).toMatch( - `import { ${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"` + `import { ${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"`, ) expect(code).toMatch( - `const _${helperNameMap[CREATE_VNODE]} = ${helperNameMap[CREATE_VNODE]}, _${helperNameMap[RESOLVE_DIRECTIVE]} = ${helperNameMap[RESOLVE_DIRECTIVE]}` + `const _${helperNameMap[CREATE_VNODE]} = ${helperNameMap[CREATE_VNODE]}, _${helperNameMap[RESOLVE_DIRECTIVE]} = ${helperNameMap[RESOLVE_DIRECTIVE]}`, ) expect(code).toMatchSnapshot() }) test('function mode preamble', () => { const root = createRoot({ - helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]) + helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]), }) const { code } = generate(root, { mode: 'function' }) expect(code).toMatch(`const _Vue = Vue`) expect(code).toMatch( - `const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = _Vue` + `const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = _Vue`, ) expect(code).toMatchSnapshot() }) test('function mode preamble w/ prefixIdentifiers: true', () => { const root = createRoot({ - helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]) + helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]), }) const { code } = generate(root, { mode: 'function', - prefixIdentifiers: true + prefixIdentifiers: true, }) expect(code).not.toMatch(`const _Vue = Vue`) expect(code).toMatch( - `const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = Vue` + `const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = Vue`, ) expect(code).toMatchSnapshot() }) @@ -112,27 +112,27 @@ describe('compiler: codegen', () => { const root = createRoot({ components: [`Foo`, `bar-baz`, `barbaz`, `Qux__self`], directives: [`my_dir_0`, `my_dir_1`], - temps: 3 + temps: 3, }) const { code } = generate(root, { mode: 'function' }) expect(code).toMatch( - `const _component_Foo = _${helperNameMap[RESOLVE_COMPONENT]}("Foo")\n` + `const _component_Foo = _${helperNameMap[RESOLVE_COMPONENT]}("Foo")\n`, ) expect(code).toMatch( - `const _component_bar_baz = _${helperNameMap[RESOLVE_COMPONENT]}("bar-baz")\n` + `const _component_bar_baz = _${helperNameMap[RESOLVE_COMPONENT]}("bar-baz")\n`, ) expect(code).toMatch( - `const _component_barbaz = _${helperNameMap[RESOLVE_COMPONENT]}("barbaz")\n` + `const _component_barbaz = _${helperNameMap[RESOLVE_COMPONENT]}("barbaz")\n`, ) // implicit self reference from SFC filename expect(code).toMatch( - `const _component_Qux = _${helperNameMap[RESOLVE_COMPONENT]}("Qux", true)\n` + `const _component_Qux = _${helperNameMap[RESOLVE_COMPONENT]}("Qux", true)\n`, ) expect(code).toMatch( - `const _directive_my_dir_0 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_0")\n` + `const _directive_my_dir_0 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_0")\n`, ) expect(code).toMatch( - `const _directive_my_dir_1 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_1")\n` + `const _directive_my_dir_1 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_1")\n`, ) expect(code).toMatch(`let _temp0, _temp1, _temp2`) expect(code).toMatchSnapshot() @@ -146,12 +146,12 @@ describe('compiler: codegen', () => { [ createObjectProperty( createSimpleExpression(`id`, true, locStub), - createSimpleExpression(`foo`, true, locStub) - ) + createSimpleExpression(`foo`, true, locStub), + ), ], - locStub - ) - ] + locStub, + ), + ], }) const { code } = generate(root) expect(code).toMatch(`const _hoisted_1 = hello`) @@ -161,7 +161,7 @@ describe('compiler: codegen', () => { test('temps', () => { const root = createRoot({ - temps: 3 + temps: 3, }) const { code } = generate(root) expect(code).toMatch(`let _temp0, _temp1, _temp2`) @@ -174,9 +174,9 @@ describe('compiler: codegen', () => { codegenNode: { type: NodeTypes.TEXT, content: 'hello', - loc: locStub - } - }) + loc: locStub, + }, + }), ) expect(code).toMatch(`return "hello"`) expect(code).toMatchSnapshot() @@ -185,8 +185,8 @@ describe('compiler: codegen', () => { test('interpolation', () => { const { code } = generate( createRoot({ - codegenNode: createInterpolation(`hello`, locStub) - }) + codegenNode: createInterpolation(`hello`, locStub), + }), ) expect(code).toMatch(`return _${helperNameMap[TO_DISPLAY_STRING]}(hello)`) expect(code).toMatchSnapshot() @@ -198,9 +198,9 @@ describe('compiler: codegen', () => { codegenNode: { type: NodeTypes.COMMENT, content: 'foo', - loc: locStub - } - }) + loc: locStub, + }, + }), ) expect(code).toMatch(`return _${helperNameMap[CREATE_COMMENT]}("foo")`) expect(code).toMatchSnapshot() @@ -216,15 +216,15 @@ describe('compiler: codegen', () => { { type: NodeTypes.INTERPOLATION, loc: locStub, - content: createSimpleExpression(`bar`, false, locStub) + content: createSimpleExpression(`bar`, false, locStub), }, // nested compound - createCompoundExpression([` + `, `nested`]) - ]) - }) + createCompoundExpression([` + `, `nested`]), + ]), + }), ) expect(code).toMatch( - `return _ctx.foo + _${helperNameMap[TO_DISPLAY_STRING]}(bar) + nested` + `return _ctx.foo + _${helperNameMap[TO_DISPLAY_STRING]}(bar) + nested`, ) expect(code).toMatchSnapshot() }) @@ -239,10 +239,10 @@ describe('compiler: codegen', () => { codegenNode: createConditionalExpression( createSimpleExpression('foo', false), createSimpleExpression('bar', false), - createSimpleExpression('baz', false) - ) as IfConditionalExpression - } - }) + createSimpleExpression('baz', false), + ) as IfConditionalExpression, + }, + }), ) expect(code).toMatch(/return foo\s+\? bar\s+: baz/) expect(code).toMatchSnapshot() @@ -270,10 +270,10 @@ describe('compiler: codegen', () => { patchFlag: '1', dynamicProps: undefined, directives: undefined, - loc: locStub - } as ForCodegenNode - } - }) + loc: locStub, + } as ForCodegenNode, + }, + }), ) expect(code).toMatch(`openBlock(true)`) expect(code).toMatchSnapshot() @@ -289,7 +289,7 @@ describe('compiler: codegen', () => { '1 + 2', false, locStub, - ConstantTypes.CAN_STRINGIFY + ConstantTypes.CAN_STRINGIFY, ), valueAlias: undefined, keyAlias: undefined, @@ -306,10 +306,10 @@ describe('compiler: codegen', () => { patchFlag: genFlagText(PatchFlags.STABLE_FRAGMENT), dynamicProps: undefined, directives: undefined, - loc: locStub - } as ForCodegenNode - } - }) + loc: locStub, + } as ForCodegenNode, + }, + }), ) expect(code).toMatch(`openBlock()`) expect(code).toMatchSnapshot() @@ -326,11 +326,11 @@ describe('compiler: codegen', () => { [ createObjectProperty( createSimpleExpression(`id`, true, locStub), - createSimpleExpression(`foo`, true, locStub) + createSimpleExpression(`foo`, true, locStub), ), createObjectProperty( createSimpleExpression(`prop`, false, locStub), - createSimpleExpression(`bar`, false, locStub) + createSimpleExpression(`bar`, false, locStub), ), // compound expression as computed key createObjectProperty( @@ -339,13 +339,13 @@ describe('compiler: codegen', () => { loc: locStub, children: [ `foo + `, - createSimpleExpression(`bar`, false, locStub) - ] + createSimpleExpression(`bar`, false, locStub), + ], }, - createSimpleExpression(`bar`, false, locStub) - ) + createSimpleExpression(`bar`, false, locStub), + ), ], - locStub + locStub, ), // ChildNode[] [ @@ -356,17 +356,17 @@ describe('compiler: codegen', () => { createObjectProperty( // should quote the key! createSimpleExpression(`some-key`, true, locStub), - createSimpleExpression(`foo`, true, locStub) - ) + createSimpleExpression(`foo`, true, locStub), + ), ], - locStub - ) - ) + locStub, + ), + ), ], // flag - PatchFlags.FULL_PROPS + '' - ) - }) + PatchFlags.FULL_PROPS + '', + ), + }), ) expect(code).toMatch(` return _${helperNameMap[CREATE_ELEMENT_VNODE]}("div", { @@ -384,9 +384,9 @@ describe('compiler: codegen', () => { createRoot({ codegenNode: createArrayExpression([ createSimpleExpression(`foo`, false), - createCallExpression(`bar`, [`baz`]) - ]) - }) + createCallExpression(`bar`, [`baz`]), + ]), + }), ) expect(code).toMatch(`return [ foo, @@ -404,17 +404,17 @@ describe('compiler: codegen', () => { createConditionalExpression( createSimpleExpression(`orNot`, false), createCallExpression(`bar`), - createCallExpression(`baz`) - ) - ) - }) + createCallExpression(`baz`), + ), + ), + }), ) expect(code).toMatch( `return ok ? foo() : orNot ? bar() - : baz()` + : baz()`, ) expect(code).toMatchSnapshot() }) @@ -425,13 +425,13 @@ describe('compiler: codegen', () => { cached: 1, codegenNode: createCacheExpression( 1, - createSimpleExpression(`foo`, false) - ) + createSimpleExpression(`foo`, false), + ), }), { mode: 'module', - prefixIdentifiers: true - } + prefixIdentifiers: true, + }, ) expect(code).toMatch(`_cache[1] || (_cache[1] = foo)`) expect(code).toMatchSnapshot() @@ -444,13 +444,13 @@ describe('compiler: codegen', () => { codegenNode: createCacheExpression( 1, createSimpleExpression(`foo`, false), - true - ) + true, + ), }), { mode: 'module', - prefixIdentifiers: true - } + prefixIdentifiers: true, + }, ) expect(code).toMatch( ` @@ -460,7 +460,7 @@ describe('compiler: codegen', () => { _setBlockTracking(1), _cache[1] ) - `.trim() + `.trim(), ) expect(code).toMatchSnapshot() }) @@ -472,11 +472,11 @@ describe('compiler: codegen', () => { createTemplateLiteral([ `foo`, createCallExpression(`_renderAttr`, ['id', 'foo']), - `bar` - ]) - ]) + `bar`, + ]), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -493,11 +493,11 @@ describe('compiler: codegen', () => { codegenNode: createBlockStatement([ createIfStatement( createSimpleExpression('foo', false), - createBlockStatement([createCallExpression(`ok`)]) - ) - ]) + createBlockStatement([createCallExpression(`ok`)]), + ), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -516,11 +516,11 @@ describe('compiler: codegen', () => { createIfStatement( createSimpleExpression('foo', false), createBlockStatement([createCallExpression(`foo`)]), - createBlockStatement([createCallExpression('bar')]) - ) - ]) + createBlockStatement([createCallExpression('bar')]), + ), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -543,12 +543,12 @@ describe('compiler: codegen', () => { createBlockStatement([createCallExpression(`foo`)]), createIfStatement( createSimpleExpression('bar', false), - createBlockStatement([createCallExpression(`bar`)]) - ) - ) - ]) + createBlockStatement([createCallExpression(`bar`)]), + ), + ), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -572,12 +572,12 @@ describe('compiler: codegen', () => { createIfStatement( createSimpleExpression('bar', false), createBlockStatement([createCallExpression(`bar`)]), - createBlockStatement([createCallExpression('baz')]) - ) - ) - ]) + createBlockStatement([createCallExpression('baz')]), + ), + ), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -599,9 +599,9 @@ describe('compiler: codegen', () => { createRoot({ codegenNode: createAssignmentExpression( createSimpleExpression(`foo`, false), - createSimpleExpression(`bar`, false) - ) - }) + createSimpleExpression(`bar`, false), + ), + }), ) expect(code).toMatchInlineSnapshot(` " @@ -617,17 +617,17 @@ describe('compiler: codegen', () => { function genCode(node: VNodeCall) { return generate( createRoot({ - codegenNode: node - }) + codegenNode: node, + }), ).code.match(/with \(_ctx\) \{\s+([^]+)\s+\}\s+\}$/)![1] } const mockProps = createObjectExpression([ - createObjectProperty(`foo`, createSimpleExpression(`bar`, true)) + createObjectProperty(`foo`, createSimpleExpression(`bar`, true)), ]) const mockChildren = createCompoundExpression(['children']) const mockDirs = createArrayExpression([ - createArrayExpression([`foo`, createSimpleExpression(`bar`, false)]) + createArrayExpression([`foo`, createSimpleExpression(`bar`, false)]), ]) as DirectiveArguments test('tag only', () => { @@ -684,9 +684,9 @@ describe('compiler: codegen', () => { undefined, undefined, undefined, - true - ) - ) + true, + ), + ), ).toMatchInlineSnapshot(` "return (_openBlock(), _createElementBlock("div", { foo: "bar" }, children)) " @@ -705,9 +705,9 @@ describe('compiler: codegen', () => { undefined, undefined, true, - true - ) - ) + true, + ), + ), ).toMatchInlineSnapshot(` "return (_openBlock(true), _createElementBlock("div", { foo: "bar" }, children)) " @@ -724,9 +724,9 @@ describe('compiler: codegen', () => { mockChildren, undefined, undefined, - mockDirs - ) - ) + mockDirs, + ), + ), ).toMatchInlineSnapshot(` "return _withDirectives(_createElementVNode("div", { foo: "bar" }, children), [ [foo, bar] @@ -746,9 +746,9 @@ describe('compiler: codegen', () => { undefined, undefined, mockDirs, - true - ) - ) + true, + ), + ), ).toMatchInlineSnapshot(` "return _withDirectives((_openBlock(), _createElementBlock("div", { foo: "bar" }, children)), [ [foo, bar] diff --git a/packages/compiler-core/__tests__/compile.spec.ts b/packages/compiler-core/__tests__/compile.spec.ts index dc4f57ad3d2..995741091df 100644 --- a/packages/compiler-core/__tests__/compile.spec.ts +++ b/packages/compiler-core/__tests__/compile.spec.ts @@ -1,5 +1,5 @@ import { baseCompile as compile } from '../src' -import { SourceMapConsumer, RawSourceMap } from 'source-map-js' +import { type RawSourceMap, SourceMapConsumer } from 'source-map-js' describe('compiler: integration tests', () => { const source = ` @@ -20,7 +20,7 @@ describe('compiler: integration tests', () => { function getPositionInCode( code: string, token: string, - expectName: string | boolean = false + expectName: string | boolean = false, ): Pos { const generatedOffset = code.indexOf(token) let line = 1 @@ -36,7 +36,7 @@ describe('compiler: integration tests', () => { column: lastNewLinePos === -1 ? generatedOffset - : generatedOffset - lastNewLinePos - 1 + : generatedOffset - lastNewLinePos - 1, } if (expectName) { res.name = typeof expectName === 'string' ? expectName : token @@ -47,7 +47,7 @@ describe('compiler: integration tests', () => { test('function mode', () => { const { code, map } = compile(source, { sourceMap: true, - filename: `foo.vue` + filename: `foo.vue`, }) expect(code).toMatchSnapshot() @@ -57,55 +57,55 @@ describe('compiler: integration tests', () => { const consumer = new SourceMapConsumer(map as RawSourceMap) expect( - consumer.originalPositionFor(getPositionInCode(code, `id`)) + consumer.originalPositionFor(getPositionInCode(code, `id`)), ).toMatchObject(getPositionInCode(source, `id`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `"foo"`)) + consumer.originalPositionFor(getPositionInCode(code, `"foo"`)), ).toMatchObject(getPositionInCode(source, `"foo"`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `class:`)) + consumer.originalPositionFor(getPositionInCode(code, `class:`)), ).toMatchObject(getPositionInCode(source, `class=`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`)) // without prefixIdentifiers: true, identifiers inside compound expressions // are mapped to closest parent expression. expect( - consumer.originalPositionFor(getPositionInCode(code, `baz`)) + consumer.originalPositionFor(getPositionInCode(code, `baz`)), ).toMatchObject(getPositionInCode(source, `bar`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `world`)) + consumer.originalPositionFor(getPositionInCode(code, `world`)), ).toMatchObject(getPositionInCode(source, `world`)) // without prefixIdentifiers: true, identifiers inside compound expressions // are mapped to closest parent expression. expect( - consumer.originalPositionFor(getPositionInCode(code, `burn()`)) + consumer.originalPositionFor(getPositionInCode(code, `burn()`)), ).toMatchObject(getPositionInCode(source, `world`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `list`)) + consumer.originalPositionFor(getPositionInCode(code, `list`)), ).toMatchObject(getPositionInCode(source, `list`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value`)) + consumer.originalPositionFor(getPositionInCode(code, `value`)), ).toMatchObject(getPositionInCode(source, `value`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `index`)) + consumer.originalPositionFor(getPositionInCode(code, `index`)), ).toMatchObject(getPositionInCode(source, `index`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value + index`)) + consumer.originalPositionFor(getPositionInCode(code, `value + index`)), ).toMatchObject(getPositionInCode(source, `value + index`)) }) @@ -113,7 +113,7 @@ describe('compiler: integration tests', () => { const { code, map } = compile(source, { sourceMap: true, filename: `foo.vue`, - prefixIdentifiers: true + prefixIdentifiers: true, }) expect(code).toMatchSnapshot() @@ -123,64 +123,66 @@ describe('compiler: integration tests', () => { const consumer = new SourceMapConsumer(map as RawSourceMap) expect( - consumer.originalPositionFor(getPositionInCode(code, `id`)) + consumer.originalPositionFor(getPositionInCode(code, `id`)), ).toMatchObject(getPositionInCode(source, `id`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `"foo"`)) + consumer.originalPositionFor(getPositionInCode(code, `"foo"`)), ).toMatchObject(getPositionInCode(source, `"foo"`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `class:`)) + consumer.originalPositionFor(getPositionInCode(code, `class:`)), ).toMatchObject(getPositionInCode(source, `class=`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.bar`, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `_ctx.bar`, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `baz`)) + consumer.originalPositionFor(getPositionInCode(code, `baz`)), ).toMatchObject(getPositionInCode(source, `baz`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `world`, true)) + consumer.originalPositionFor(getPositionInCode(code, `world`, true)), ).toMatchObject(getPositionInCode(source, `world`, `world`)) expect( consumer.originalPositionFor( - getPositionInCode(code, `_ctx.world`, `world`) - ) + getPositionInCode(code, `_ctx.world`, `world`), + ), ).toMatchObject(getPositionInCode(source, `world`, `world`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `burn()`)) + consumer.originalPositionFor(getPositionInCode(code, `burn()`)), ).toMatchObject(getPositionInCode(source, `burn()`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.ok`, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `_ctx.ok`, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `list`)) + consumer.originalPositionFor(getPositionInCode(code, `list`)), ).toMatchObject(getPositionInCode(source, `list`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.list`, `list`)) + consumer.originalPositionFor( + getPositionInCode(code, `_ctx.list`, `list`), + ), ).toMatchObject(getPositionInCode(source, `list`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value`)) + consumer.originalPositionFor(getPositionInCode(code, `value`)), ).toMatchObject(getPositionInCode(source, `value`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `index`)) + consumer.originalPositionFor(getPositionInCode(code, `index`)), ).toMatchObject(getPositionInCode(source, `index`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value + index`)) + consumer.originalPositionFor(getPositionInCode(code, `value + index`)), ).toMatchObject(getPositionInCode(source, `value + index`)) }) @@ -188,7 +190,7 @@ describe('compiler: integration tests', () => { const { code, map } = compile(source, { mode: 'module', sourceMap: true, - filename: `foo.vue` + filename: `foo.vue`, }) expect(code).toMatchSnapshot() @@ -198,64 +200,66 @@ describe('compiler: integration tests', () => { const consumer = new SourceMapConsumer(map as RawSourceMap) expect( - consumer.originalPositionFor(getPositionInCode(code, `id`)) + consumer.originalPositionFor(getPositionInCode(code, `id`)), ).toMatchObject(getPositionInCode(source, `id`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `"foo"`)) + consumer.originalPositionFor(getPositionInCode(code, `"foo"`)), ).toMatchObject(getPositionInCode(source, `"foo"`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `class:`)) + consumer.originalPositionFor(getPositionInCode(code, `class:`)), ).toMatchObject(getPositionInCode(source, `class=`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.bar`, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `_ctx.bar`, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `baz`)) + consumer.originalPositionFor(getPositionInCode(code, `baz`)), ).toMatchObject(getPositionInCode(source, `baz`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `world`, true)) + consumer.originalPositionFor(getPositionInCode(code, `world`, true)), ).toMatchObject(getPositionInCode(source, `world`, `world`)) expect( consumer.originalPositionFor( - getPositionInCode(code, `_ctx.world`, `world`) - ) + getPositionInCode(code, `_ctx.world`, `world`), + ), ).toMatchObject(getPositionInCode(source, `world`, `world`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `burn()`)) + consumer.originalPositionFor(getPositionInCode(code, `burn()`)), ).toMatchObject(getPositionInCode(source, `burn()`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.ok`, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `_ctx.ok`, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `list`)) + consumer.originalPositionFor(getPositionInCode(code, `list`)), ).toMatchObject(getPositionInCode(source, `list`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.list`, `list`)) + consumer.originalPositionFor( + getPositionInCode(code, `_ctx.list`, `list`), + ), ).toMatchObject(getPositionInCode(source, `list`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value`)) + consumer.originalPositionFor(getPositionInCode(code, `value`)), ).toMatchObject(getPositionInCode(source, `value`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `index`)) + consumer.originalPositionFor(getPositionInCode(code, `index`)), ).toMatchObject(getPositionInCode(source, `index`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value + index`)) + consumer.originalPositionFor(getPositionInCode(code, `value + index`)), ).toMatchObject(getPositionInCode(source, `value + index`)) }) }) diff --git a/packages/compiler-core/__tests__/parse.spec.ts b/packages/compiler-core/__tests__/parse.spec.ts index 7c6b9f463d8..0ec4718145c 100644 --- a/packages/compiler-core/__tests__/parse.spec.ts +++ b/packages/compiler-core/__tests__/parse.spec.ts @@ -1,20 +1,20 @@ -import { ParserOptions } from '../src/options' +import type { ParserOptions } from '../src/options' import { ErrorCodes } from '../src/errors' import { - CommentNode, - ElementNode, + type CommentNode, + ConstantTypes, + type DirectiveNode, + type ElementNode, ElementTypes, + type InterpolationNode, Namespaces, NodeTypes, - Position, - TextNode, - InterpolationNode, - ConstantTypes, - DirectiveNode + type Position, + type TextNode, } from '../src/ast' import { baseParse } from '../src/parser' -import { Program } from '@babel/types' +import type { Program } from '@babel/types' /* eslint jest/no-disabled-tests: "off" */ @@ -30,8 +30,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 9, line: 1, column: 10 }, - source: 'some text' - } + source: 'some text', + }, }) }) @@ -46,10 +46,10 @@ describe('compiler: parse', () => { code: ErrorCodes.X_INVALID_END_TAG, loc: { start: { column: 10, line: 1, offset: 9 }, - end: { column: 10, line: 1, offset: 9 } - } - } - ] + end: { column: 10, line: 1, offset: 9 }, + }, + }, + ], ]) expect(text).toStrictEqual({ @@ -58,8 +58,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 9, line: 1, column: 10 }, - source: 'some text' - } + source: 'some text', + }, }) }) @@ -74,8 +74,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: 'some ' - } + source: 'some ', + }, }) expect(text2).toStrictEqual({ type: NodeTypes.TEXT, @@ -83,8 +83,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 20, line: 1, column: 21 }, end: { offset: 25, line: 1, column: 26 }, - source: ' text' - } + source: ' text', + }, }) }) @@ -99,8 +99,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: 'some ' - } + source: 'some ', + }, }) expect(text2).toStrictEqual({ type: NodeTypes.TEXT, @@ -108,8 +108,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 21, line: 1, column: 22 }, end: { offset: 26, line: 1, column: 27 }, - source: ' text' - } + source: ' text', + }, }) }) @@ -124,8 +124,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: 'some ' - } + source: 'some ', + }, }) expect(text2).toStrictEqual({ type: NodeTypes.TEXT, @@ -133,8 +133,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 32, line: 1, column: 33 }, end: { offset: 37, line: 1, column: 38 }, - source: ' text' - } + source: ' text', + }, }) }) @@ -144,7 +144,7 @@ describe('compiler: parse', () => { if (err.code !== ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME) { throw err } - } + }, }) const text = ast.children[0] as TextNode @@ -154,8 +154,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: 'a < b' - } + source: 'a < b', + }, }) }) @@ -165,7 +165,7 @@ describe('compiler: parse', () => { if (error.code !== ErrorCodes.X_MISSING_INTERPOLATION_END) { throw error } - } + }, }) const text = ast.children[0] as TextNode @@ -175,8 +175,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 6, line: 1, column: 7 }, - source: 'a {{ b' - } + source: 'a {{ b', + }, }) }) }) @@ -196,14 +196,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 2, line: 1, column: 3 }, end: { offset: 9, line: 1, column: 10 }, - source: 'message' - } + source: 'message', + }, }, loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 11, line: 1, column: 12 }, - source: '{{message}}' - } + source: '{{message}}', + }, }) }) @@ -221,14 +221,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 3, line: 1, column: 4 }, end: { offset: 6, line: 1, column: 7 }, - source: 'a { loc: { start: { offset: 3, line: 1, column: 4 }, end: { offset: 6, line: 1, column: 7 }, - source: 'a { loc: { start: { offset: 12, line: 1, column: 13 }, end: { offset: 15, line: 1, column: 16 }, - source: 'c>d' - } + source: 'c>d', + }, }, loc: { start: { offset: 9, line: 1, column: 10 }, end: { offset: 18, line: 1, column: 19 }, - source: '{{ c>d }}' - } + source: '{{ c>d }}', + }, }) }) @@ -294,20 +294,20 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 16, line: 1, column: 17 }, - source: '""' - } + source: '""', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 19, line: 1, column: 20 }, - source: '{{ "" }}' - } + source: '{{ "" }}', + }, }) }) test('custom delimiters', () => { const ast = baseParse('

{msg}

', { - delimiters: ['{', '}'] + delimiters: ['{', '}'], }) const element = ast.children[0] as ElementNode const interpolation = element.children[0] as InterpolationNode @@ -322,14 +322,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 4, line: 1, column: 5 }, end: { offset: 7, line: 1, column: 8 }, - source: 'msg' - } + source: 'msg', + }, }, loc: { start: { offset: 3, line: 1, column: 4 }, end: { offset: 8, line: 1, column: 9 }, - source: '{msg}' - } + source: '{msg}', + }, }) }) }) @@ -345,8 +345,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 7, line: 1, column: 8 }, - source: '' - } + source: '', + }, }) }) @@ -360,8 +360,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 10, line: 1, column: 11 }, - source: '' - } + source: '', + }, }) }) @@ -376,8 +376,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 10, line: 1, column: 11 }, - source: '' - } + source: '', + }, }) expect(comment2).toStrictEqual({ type: NodeTypes.COMMENT, @@ -385,8 +385,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 10, line: 1, column: 11 }, end: { offset: 20, line: 1, column: 21 }, - source: '' - } + source: '', + }, }) }) @@ -403,38 +403,38 @@ describe('compiler: parse', () => { const rawText = `

` const astWithComments = baseParse(`

${rawText}
`, { - comments: true + comments: true, }) expect( - (astWithComments.children[0] as ElementNode).children + (astWithComments.children[0] as ElementNode).children, ).toMatchObject([ { type: NodeTypes.ELEMENT, - tag: 'p' + tag: 'p', }, { - type: NodeTypes.COMMENT + type: NodeTypes.COMMENT, }, { type: NodeTypes.ELEMENT, - tag: 'p' - } + tag: 'p', + }, ]) const astWithoutComments = baseParse(`
${rawText}
`, { - comments: false + comments: false, }) expect( - (astWithoutComments.children[0] as ElementNode).children + (astWithoutComments.children[0] as ElementNode).children, ).toMatchObject([ { type: NodeTypes.ELEMENT, - tag: 'p' + tag: 'p', }, { type: NodeTypes.ELEMENT, - tag: 'p' - } + tag: 'p', + }, ]) }) }) @@ -458,15 +458,15 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: 'hello' - } - } + source: 'hello', + }, + }, ], loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 16, line: 1, column: 17 }, - source: '
hello
' - } + source: '
hello
', + }, }) }) @@ -485,8 +485,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 11, line: 1, column: 12 }, - source: '
' - } + source: '
', + }, }) }) @@ -506,14 +506,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 6, line: 1, column: 7 }, - source: '
' - } + source: '
', + }, }) }) test('void element', () => { const ast = baseParse('after', { - isVoidTag: tag => tag === 'img' + isVoidTag: tag => tag === 'img', }) const element = ast.children[0] as ElementNode @@ -528,14 +528,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: '' - } + source: '', + }, }) }) test('self-closing void element', () => { const ast = baseParse('after', { - isVoidTag: tag => tag === 'img' + isVoidTag: tag => tag === 'img', }) const element = ast.children[0] as ElementNode @@ -551,8 +551,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 6, line: 1, column: 7 }, - source: '' - } + source: '', + }, }) }) @@ -561,7 +561,7 @@ describe('compiler: parse', () => { const element = ast.children[0] expect(element).toMatchObject({ type: NodeTypes.ELEMENT, - tagType: ElementTypes.TEMPLATE + tagType: ElementTypes.TEMPLATE, }) }) @@ -570,31 +570,31 @@ describe('compiler: parse', () => { const element = ast.children[0] expect(element).toMatchObject({ type: NodeTypes.ELEMENT, - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) }) test('native element with `isNativeTag`', () => { const ast = baseParse('
', { - isNativeTag: tag => tag === 'div' + isNativeTag: tag => tag === 'div', }) expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) expect(ast.children[2]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -604,19 +604,19 @@ describe('compiler: parse', () => { expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'comp', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[2]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -624,26 +624,26 @@ describe('compiler: parse', () => { const ast = baseParse( `
`, { - isNativeTag: tag => tag === 'div' - } + isNativeTag: tag => tag === 'div', + }, ) expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) expect(ast.children[2]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -653,56 +653,56 @@ describe('compiler: parse', () => { expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) expect(ast.children[2]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) test('custom element', () => { const ast = baseParse('
', { isNativeTag: tag => tag === 'div', - isCustomElement: tag => tag === 'comp' + isCustomElement: tag => tag === 'comp', }) expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'comp', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) }) test('built-in component', () => { const ast = baseParse('
', { - isBuiltInComponent: tag => (tag === 'comp' ? Symbol() : void 0) + isBuiltInComponent: tag => (tag === 'comp' ? Symbol() : void 0), }) expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -712,13 +712,13 @@ describe('compiler: parse', () => { expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'slot', - tagType: ElementTypes.SLOT + tagType: ElementTypes.SLOT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -739,23 +739,23 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'id' + source: 'id', }, value: undefined, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'id' - } - } + source: 'id', + }, + }, ], children: [], loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 14, line: 1, column: 15 }, - source: '
' - } + source: '
', + }, }) }) @@ -776,7 +776,7 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'id' + source: 'id', }, value: { type: NodeTypes.TEXT, @@ -784,23 +784,23 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 10, line: 1, column: 11 }, - source: '""' - } + source: '""', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: 'id=""' - } - } + source: 'id=""', + }, + }, ], children: [], loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 17, line: 1, column: 18 }, - source: '
' - } + source: '
', + }, }) }) @@ -821,7 +821,7 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'id' + source: 'id', }, value: { type: NodeTypes.TEXT, @@ -829,23 +829,23 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 10, line: 1, column: 11 }, - source: "''" - } + source: "''", + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: "id=''" - } - } + source: "id=''", + }, + }, ], children: [], loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 17, line: 1, column: 18 }, - source: "
" - } + source: "
", + }, }) }) @@ -866,7 +866,7 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'id' + source: 'id', }, value: { type: NodeTypes.TEXT, @@ -874,23 +874,23 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 12, line: 1, column: 13 }, - source: '">\'"' - } + source: '">\'"', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 12, line: 1, column: 13 }, - source: 'id=">\'"' - } - } + source: 'id=">\'"', + }, + }, ], children: [], loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 19, line: 1, column: 20 }, - source: '
' - } + source: '
', + }, }) }) @@ -911,7 +911,7 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'id' + source: 'id', }, value: { type: NodeTypes.TEXT, @@ -919,23 +919,23 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 12, line: 1, column: 13 }, - source: "'>\"'" - } + source: "'>\"'", + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 12, line: 1, column: 13 }, - source: "id='>\"'" - } - } + source: "id='>\"'", + }, + }, ], children: [], loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 19, line: 1, column: 20 }, - source: "
" - } + source: "
", + }, }) }) @@ -956,7 +956,7 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'id' + source: 'id', }, value: { type: NodeTypes.TEXT, @@ -964,23 +964,23 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 10, line: 1, column: 11 }, - source: 'a/' - } + source: 'a/', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: 'id=a/' - } - } + source: 'id=a/', + }, + }, ], children: [], loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 17, line: 1, column: 18 }, - source: '
' - } + source: '
', + }, }) }) @@ -1001,7 +1001,7 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'id' + source: 'id', }, value: { type: NodeTypes.TEXT, @@ -1009,14 +1009,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 9, line: 1, column: 10 }, - source: 'a' - } + source: 'a', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: 'id=a' - } + source: 'id=a', + }, }, { type: NodeTypes.ATTRIBUTE, @@ -1024,7 +1024,7 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 10, line: 1, column: 11 }, end: { offset: 15, line: 1, column: 16 }, - source: 'class' + source: 'class', }, value: { type: NodeTypes.TEXT, @@ -1032,14 +1032,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 16, line: 1, column: 17 }, end: { offset: 19, line: 1, column: 20 }, - source: '"c"' - } + source: '"c"', + }, }, loc: { start: { offset: 10, line: 1, column: 11 }, end: { offset: 19, line: 1, column: 20 }, - source: 'class="c"' - } + source: 'class="c"', + }, }, { type: NodeTypes.ATTRIBUTE, @@ -1047,14 +1047,14 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 20, line: 1, column: 21 }, end: { offset: 25, line: 1, column: 26 }, - source: 'inert' + source: 'inert', }, value: undefined, loc: { start: { offset: 20, line: 1, column: 21 }, end: { offset: 25, line: 1, column: 26 }, - source: 'inert' - } + source: 'inert', + }, }, { type: NodeTypes.ATTRIBUTE, @@ -1062,7 +1062,7 @@ describe('compiler: parse', () => { nameLoc: { start: { offset: 26, line: 1, column: 27 }, end: { offset: 31, line: 1, column: 32 }, - source: 'style' + source: 'style', }, value: { type: NodeTypes.TEXT, @@ -1070,23 +1070,23 @@ describe('compiler: parse', () => { loc: { start: { offset: 32, line: 1, column: 33 }, end: { offset: 34, line: 1, column: 35 }, - source: "''" - } + source: "''", + }, }, loc: { start: { offset: 26, line: 1, column: 27 }, end: { offset: 34, line: 1, column: 35 }, - source: "style=''" - } - } + source: "style=''", + }, + }, ], children: [], loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 41, line: 1, column: 42 }, - source: '
' - } + source: '
', + }, }) }) @@ -1101,7 +1101,7 @@ describe('compiler: parse', () => { loc: { start: { column: 1, line: 1, offset: 0 }, end: { column: 10, line: 3, offset: 29 }, - source: '
' + source: '
', }, ns: Namespaces.HTML, props: [ @@ -1110,7 +1110,7 @@ describe('compiler: parse', () => { nameLoc: { start: { column: 6, line: 1, offset: 5 }, end: { column: 11, line: 1, offset: 10 }, - source: 'class' + source: 'class', }, type: NodeTypes.ATTRIBUTE, value: { @@ -1118,20 +1118,20 @@ describe('compiler: parse', () => { loc: { start: { column: 12, line: 1, offset: 11 }, end: { column: 3, line: 3, offset: 22 }, - source: '" \n\t c \t\n "' + source: '" \n\t c \t\n "', }, - type: NodeTypes.TEXT + type: NodeTypes.TEXT, }, loc: { start: { column: 6, line: 1, offset: 5 }, end: { column: 3, line: 3, offset: 22 }, - source: 'class=" \n\t c \t\n "' - } - } + source: 'class=" \n\t c \t\n "', + }, + }, ], tag: 'div', tagType: ElementTypes.ELEMENT, - type: NodeTypes.ELEMENT + type: NodeTypes.ELEMENT, }) }) @@ -1149,8 +1149,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: 'v-if' - } + source: 'v-if', + }, }) }) @@ -1172,14 +1172,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 11, line: 1, column: 12 }, end: { offset: 12, line: 1, column: 13 }, - source: 'a' - } + source: 'a', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 13, line: 1, column: 14 }, - source: 'v-if="a"' - } + source: 'v-if="a"', + }, }) }) @@ -1199,16 +1199,16 @@ describe('compiler: parse', () => { loc: { start: { column: 11, line: 1, offset: 10 }, end: { column: 16, line: 1, offset: 15 }, - source: 'click' - } + source: 'click', + }, }, modifiers: [], exp: undefined, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 15, line: 1, column: 16 }, - source: 'v-on:click' - } + source: 'v-on:click', + }, }) }) @@ -1220,8 +1220,8 @@ describe('compiler: parse', () => { expect(directive.arg).toMatchObject({ loc: { start: { offset: 12, line: 1, column: 13 }, - end: { offset: 16, line: 1, column: 17 } - } + end: { offset: 16, line: 1, column: 17 }, + }, }) }) @@ -1234,8 +1234,8 @@ describe('compiler: parse', () => { content: 'item.item', loc: { start: { offset: 6, line: 1, column: 7 }, - end: { offset: 15, line: 1, column: 16 } - } + end: { offset: 15, line: 1, column: 16 }, + }, }) }) @@ -1255,16 +1255,16 @@ describe('compiler: parse', () => { loc: { start: { column: 11, line: 1, offset: 10 }, end: { column: 18, line: 1, offset: 17 }, - source: '[event]' - } + source: '[event]', + }, }, modifiers: [], exp: undefined, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 17, line: 1, column: 18 }, - source: 'v-on:[event]' - } + source: 'v-on:[event]', + }, }) }) @@ -1282,8 +1282,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 15, line: 1, column: 16 }, - source: 'v-on.enter' - } + source: 'v-on.enter', + }, }) }) @@ -1301,8 +1301,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 21, line: 1, column: 22 }, - source: 'v-on.enter.exact' - } + source: 'v-on.enter.exact', + }, }) }) @@ -1322,16 +1322,16 @@ describe('compiler: parse', () => { loc: { start: { column: 11, line: 1, offset: 10 }, end: { column: 16, line: 1, offset: 15 }, - source: 'click' - } + source: 'click', + }, }, modifiers: ['enter', 'exact'], exp: undefined, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 27, line: 1, column: 28 }, - source: 'v-on:click.enter.exact' - } + source: 'v-on:click.enter.exact', + }, }) }) @@ -1351,16 +1351,16 @@ describe('compiler: parse', () => { loc: { start: { column: 11, line: 1, offset: 10 }, end: { column: 16, line: 1, offset: 15 }, - source: '[a.b]' - } + source: '[a.b]', + }, }, modifiers: ['camel'], exp: undefined, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 21, line: 1, column: 22 }, - source: 'v-on:[a.b].camel' - } + source: 'v-on:[a.b].camel', + }, }) }) @@ -1369,7 +1369,7 @@ describe('compiler: parse', () => { const ast = baseParse('
', { onError: err => { errorCode = err.code as number - } + }, }) const directive = (ast.children[0] as ElementNode).props[0] @@ -1381,13 +1381,13 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'v-' + source: 'v-', }, nameLoc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'v-' - } + source: 'v-', + }, }) }) @@ -1407,8 +1407,8 @@ describe('compiler: parse', () => { loc: { start: { column: 7, line: 1, offset: 6 }, end: { column: 8, line: 1, offset: 7 }, - source: 'a' - } + source: 'a', + }, }, modifiers: [], exp: { @@ -1419,14 +1419,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 9, line: 1, column: 10 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: ':a=b' - } + source: ':a=b', + }, }) }) @@ -1446,8 +1446,8 @@ describe('compiler: parse', () => { loc: { start: { column: 7, line: 1, offset: 6 }, end: { column: 8, line: 1, offset: 7 }, - source: 'a' - } + source: 'a', + }, }, modifiers: ['prop'], exp: { @@ -1458,14 +1458,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 9, line: 1, column: 10 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: '.a=b' - } + source: '.a=b', + }, }) }) @@ -1485,8 +1485,8 @@ describe('compiler: parse', () => { loc: { start: { column: 7, line: 1, offset: 6 }, end: { column: 8, line: 1, offset: 7 }, - source: 'a' - } + source: 'a', + }, }, modifiers: ['sync'], exp: { @@ -1498,14 +1498,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 13, line: 1, column: 14 }, end: { offset: 14, line: 1, column: 15 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 14, line: 1, column: 15 }, - source: ':a.sync=b' - } + source: ':a.sync=b', + }, }) }) @@ -1525,8 +1525,8 @@ describe('compiler: parse', () => { loc: { start: { column: 7, line: 1, offset: 6 }, end: { column: 8, line: 1, offset: 7 }, - source: 'a' - } + source: 'a', + }, }, modifiers: [], exp: { @@ -1538,14 +1538,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 9, line: 1, column: 10 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: '@a=b' - } + source: '@a=b', + }, }) }) @@ -1565,8 +1565,8 @@ describe('compiler: parse', () => { loc: { start: { column: 7, line: 1, offset: 6 }, end: { column: 8, line: 1, offset: 7 }, - source: 'a' - } + source: 'a', + }, }, modifiers: ['enter'], exp: { @@ -1578,14 +1578,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 14, line: 1, column: 15 }, end: { offset: 15, line: 1, column: 16 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 15, line: 1, column: 16 }, - source: '@a.enter=b' - } + source: '@a.enter=b', + }, }) }) @@ -1605,8 +1605,8 @@ describe('compiler: parse', () => { loc: { start: { column: 8, line: 1, offset: 7 }, end: { column: 9, line: 1, offset: 8 }, - source: 'a' - } + source: 'a', + }, }, modifiers: [], exp: { @@ -1618,14 +1618,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 10, line: 1, column: 11 }, end: { offset: 15, line: 1, column: 16 }, - source: '{ b }' - } + source: '{ b }', + }, }, loc: { start: { offset: 6, line: 1, column: 7 }, end: { offset: 16, line: 1, column: 17 }, - source: '#a="{ b }"' - } + source: '#a="{ b }"', + }, }) }) @@ -1647,22 +1647,22 @@ describe('compiler: parse', () => { start: { column: 14, line: 1, - offset: 13 + offset: 13, }, end: { column: 21, line: 1, - offset: 20 - } - } - } + offset: 20, + }, + }, + }, }) }) test('v-pre', () => { const ast = baseParse( `
{{ bar }}
\n` + - `
{{ bar }}
` + `
{{ bar }}
`, ) const divWithPre = ast.children[0] as ElementNode @@ -1672,22 +1672,22 @@ describe('compiler: parse', () => { name: `:id`, value: { type: NodeTypes.TEXT, - content: `foo` + content: `foo`, }, loc: { start: { line: 1, column: 12 }, - end: { line: 1, column: 21 } - } - } + end: { line: 1, column: 21 }, + }, + }, ]) expect(divWithPre.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tagType: ElementTypes.ELEMENT, - tag: `Comp` + tag: `Comp`, }) expect(divWithPre.children[1]).toMatchObject({ type: NodeTypes.TEXT, - content: `{{ bar }}` + content: `{{ bar }}`, }) // should not affect siblings after it @@ -1699,37 +1699,37 @@ describe('compiler: parse', () => { arg: { type: NodeTypes.SIMPLE_EXPRESSION, isStatic: true, - content: `id` + content: `id`, }, exp: { type: NodeTypes.SIMPLE_EXPRESSION, isStatic: false, - content: `foo` + content: `foo`, }, loc: { start: { line: 2, - column: 6 + column: 6, }, end: { line: 2, - column: 15 - } - } - } + column: 15, + }, + }, + }, ]) expect(divWithoutPre.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tagType: ElementTypes.COMPONENT, - tag: `Comp` + tag: `Comp`, }) expect(divWithoutPre.children[1]).toMatchObject({ type: NodeTypes.INTERPOLATION, content: { type: NodeTypes.SIMPLE_EXPRESSION, content: `bar`, - isStatic: false - } + isStatic: false, + }, }) }) @@ -1740,31 +1740,31 @@ describe('compiler: parse', () => { {{ number }}
- ` + `, ) expect((ast.children[0] as ElementNode).children).toMatchObject([ { type: NodeTypes.ELEMENT, - children: [{ type: NodeTypes.TEXT, content: `{{ number ` }] + children: [{ type: NodeTypes.TEXT, content: `{{ number ` }], }, { type: NodeTypes.ELEMENT, - children: [{ type: NodeTypes.TEXT, content: `}}` }] - } + children: [{ type: NodeTypes.TEXT, content: `}}` }], + }, ]) const ast2 = baseParse(`
{{ number
`) expect((ast2.children[0] as ElementNode).children).toMatchObject([ { type: NodeTypes.ELEMENT, - children: [{ type: NodeTypes.TEXT, content: `{{ number ` }] - } + children: [{ type: NodeTypes.TEXT, content: `{{ number ` }], + }, ]) }) test('self-closing v-pre', () => { const ast = baseParse( - `
\n
{{ bar }}
` + `
\n
{{ bar }}
`, ) // should not affect siblings after it const divWithoutPre = ast.children[1] as ElementNode @@ -1775,37 +1775,37 @@ describe('compiler: parse', () => { arg: { type: NodeTypes.SIMPLE_EXPRESSION, isStatic: true, - content: `id` + content: `id`, }, exp: { type: NodeTypes.SIMPLE_EXPRESSION, isStatic: false, - content: `foo` + content: `foo`, }, loc: { start: { line: 2, - column: 6 + column: 6, }, end: { line: 2, - column: 15 - } - } - } + column: 15, + }, + }, + }, ]) expect(divWithoutPre.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tagType: ElementTypes.COMPONENT, - tag: `Comp` + tag: `Comp`, }) expect(divWithoutPre.children[1]).toMatchObject({ type: NodeTypes.INTERPOLATION, content: { type: NodeTypes.SIMPLE_EXPRESSION, content: `bar`, - isStatic: false - } + isStatic: false, + }, }) }) @@ -1820,8 +1820,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: 'hello' - } + source: 'hello', + }, }) }) }) @@ -1837,7 +1837,7 @@ describe('compiler: parse', () => { test('self closing multiple tag', () => { const ast = baseParse( `
\n` + - `

` + `

`, ) expect(ast).toMatchSnapshot() @@ -1852,7 +1852,7 @@ describe('compiler: parse', () => { `

\n` + `

\n` + ` \n` + - `

` + `
`, ) expect(ast).toMatchSnapshot() @@ -1860,14 +1860,14 @@ describe('compiler: parse', () => { expect(ast.children).toHaveLength(1) const el = ast.children[0] as any expect(el).toMatchObject({ - tag: 'div' + tag: 'div', }) expect(el.children).toHaveLength(2) expect(el.children[0]).toMatchObject({ - tag: 'p' + tag: 'p', }) expect(el.children[1]).toMatchObject({ - type: NodeTypes.COMMENT + type: NodeTypes.COMMENT, }) }) @@ -1878,7 +1878,7 @@ describe('compiler: parse', () => { const spy = vi.fn() const ast = baseParse(`
\n\n
\n`, { - onError: spy + onError: spy, }) expect(spy.mock.calls).toMatchObject([ @@ -1889,10 +1889,10 @@ describe('compiler: parse', () => { start: { offset: 6, line: 2, - column: 1 - } - } - } + column: 1, + }, + }, + }, ], [ { @@ -1901,11 +1901,11 @@ describe('compiler: parse', () => { start: { offset: 20, line: 4, - column: 1 - } - } - } - ] + column: 1, + }, + }, + }, + ], ]) expect(ast).toMatchSnapshot() @@ -1917,7 +1917,7 @@ describe('compiler: parse', () => { const butSrc = ` but ` const bazSrc = `{{ baz }}` const [foo, bar, but, baz] = baseParse( - fooSrc + barSrc + butSrc + bazSrc + fooSrc + barSrc + butSrc + bazSrc, ).children let offset = 0 @@ -1960,14 +1960,14 @@ describe('compiler: parse', () => { const ast = baseParse( ` `, - { filename: 'example.vue', sourceMap: true } + { filename: 'example.vue', sourceMap: true }, ).descriptor.template as SFCTemplateBlock const result = compile({ filename: 'example.vue', source: template.content, - preprocessLang: template.lang + preprocessLang: template.lang, }) expect(result.errors.length).toBe(1) const message = result.errors[0].toString() expect(message).toMatch(`Error: example.vue:3:1`) expect(message).toMatch( - `The end of the string reached with no closing bracket ) found.` + `The end of the string reached with no closing bracket ) found.`, ) }) @@ -362,7 +362,7 @@ test('should generate the correct imports expression', () => { `, - ssr: true + ssr: true, }) expect(code).toMatch(`_ssrRenderAttr(\"src\", _imports_1)`) expect(code).toMatch(`_createVNode(\"img\", { src: _imports_1 })`) @@ -384,7 +384,7 @@ test('should not hoist srcset URLs in SSR mode', () => { `, - ssr: true + ssr: true, }) expect(code).toMatchSnapshot() }) @@ -422,7 +422,7 @@ test('prefixing edge case for reused AST', () => { id: 'xxx', filename: 'test.vue', ast: descriptor.template!.ast, - source: descriptor.template!.content + source: descriptor.template!.content, }) expect(code).not.toMatch(`_ctx.t`) }) @@ -436,7 +436,7 @@ interface Pos { function getPositionInCode( code: string, token: string, - expectName: string | boolean = false + expectName: string | boolean = false, ): Pos { const generatedOffset = code.indexOf(token) let line = 1 @@ -452,7 +452,7 @@ function getPositionInCode( column: lastNewLinePos === -1 ? generatedOffset - : generatedOffset - lastNewLinePos - 1 + : generatedOffset - lastNewLinePos - 1, } if (expectName) { res.name = typeof expectName === 'string' ? expectName : token diff --git a/packages/compiler-sfc/__tests__/cssVars.spec.ts b/packages/compiler-sfc/__tests__/cssVars.spec.ts index d57ad079d24..323c9c7a599 100644 --- a/packages/compiler-sfc/__tests__/cssVars.spec.ts +++ b/packages/compiler-sfc/__tests__/cssVars.spec.ts @@ -1,5 +1,5 @@ import { compileStyle, parse } from '../src' -import { mockId, compileSFCScript, assertCode } from './utils' +import { assertCode, compileSFCScript, mockId } from './utils' describe('CSS vars injection', () => { test('generating correct code for nested paths', () => { @@ -8,7 +8,7 @@ describe('CSS vars injection', () => { `` + }`, ) expect(content).toMatch(`_useCssVars(_ctx => ({ "${mockId}-color": (_ctx.color), @@ -32,7 +32,7 @@ describe('CSS vars injection', () => { div { font-size: v-bind(size); } - ` + `, ) expect(content).toMatch(`_useCssVars(_ctx => ({ "${mockId}-size": (_ctx.size) @@ -57,7 +57,7 @@ describe('CSS vars injection', () => { font-size: v-bind(size); border: v-bind(foo); } - ` + `, ) // should handle: // 1. local const bindings @@ -69,7 +69,7 @@ describe('CSS vars injection', () => { "${mockId}-foo": (__props.foo) })`) expect(content).toMatch( - `import { useCssVars as _useCssVars, unref as _unref } from 'vue'` + `import { useCssVars as _useCssVars, unref as _unref } from 'vue'`, ) assertCode(content) }) @@ -85,7 +85,7 @@ describe('CSS vars injection', () => { font-family: v-bind(フォント); }`, filename: 'test.css', - id: 'data-v-test' + id: 'data-v-test', }) expect(code).toMatchInlineSnapshot(` ".foo { @@ -106,7 +106,7 @@ describe('CSS vars injection', () => { color: v-bind(color); font-size: v-bind('font.size'); }`, - { isProd: true } + { isProd: true }, ) expect(content).toMatch(`_useCssVars(_ctx => ({ "4003f1a6": (_ctx.color), @@ -120,7 +120,7 @@ describe('CSS vars injection', () => { }`, filename: 'test.css', id: mockId, - isProd: true + isProd: true, }) expect(code).toMatchInlineSnapshot(` ".foo { @@ -135,8 +135,8 @@ describe('CSS vars injection', () => { assertCode( compileSFCScript( `\n` + - `` - ).content + ``, + ).content, ) }) @@ -144,8 +144,8 @@ describe('CSS vars injection', () => { assertCode( compileSFCScript( `\n` + - `` - ).content + ``, + ).content, ) }) @@ -155,8 +155,8 @@ describe('CSS vars injection', () => { `\n` + `` - ).content + \n` + ``, + ).content, ) }) @@ -164,8 +164,8 @@ describe('CSS vars injection', () => { assertCode( compileSFCScript( `\n` + - `` - ).content + ``, + ).content, ) }) @@ -178,7 +178,7 @@ describe('CSS vars injection', () => { div{ /* color: v-bind(color); */ width:20; } div{ width: v-bind(width); } /* comment */ - ` + `, ) expect(content).not.toMatch(`"${mockId}-color": (color)`) @@ -198,7 +198,7 @@ describe('CSS vars injection', () => { p { color: v-bind(color); } - ` + `, ) // color should only be injected once, even if it is twice in style expect(content).toMatch(`_useCssVars(_ctx => ({ @@ -229,7 +229,7 @@ describe('CSS vars injection', () => { p { color: v-bind(((a + b)) / (2 * a)); } - ` + `, ) expect(content).toMatch(`_useCssVars(_ctx => ({ "${mockId}-foo": (_unref(foo)), @@ -243,7 +243,7 @@ describe('CSS vars injection', () => { // #6022 test('should be able to parse incomplete expressions', () => { const { - descriptor: { cssVars } + descriptor: { cssVars }, } = parse( ` ` + `, ) expect(cssVars).toMatchObject([`count.toString(`, `xxx`]) }) @@ -266,10 +266,10 @@ describe('CSS vars injection', () => { label { background: v-bind(background); } - ` + `, ) expect(content).toMatch( - `export default {\n setup(__props, { expose: __expose }) {\n __expose();\n\n_useCssVars(_ctx => ({\n "xxxxxxxx-background": (_unref(background))\n}))` + `export default {\n setup(__props, { expose: __expose }) {\n __expose();\n\n_useCssVars(_ctx => ({\n "xxxxxxxx-background": (_unref(background))\n}))`, ) }) @@ -287,9 +287,9 @@ describe('CSS vars injection', () => { { inlineTemplate: true, templateOptions: { - ssr: true - } - } + ssr: true, + }, + }, ) expect(content).not.toMatch(`_useCssVars`) }) @@ -308,9 +308,9 @@ describe('CSS vars injection', () => { { inlineTemplate: false, templateOptions: { - ssr: true - } - } + ssr: true, + }, + }, ) expect(content).not.toMatch(`_useCssVars`) }) @@ -333,9 +333,9 @@ describe('CSS vars injection', () => { `, { templateOptions: { - ssr: true - } - } + ssr: true, + }, + }, ) expect(content).not.toMatch(`_useCssVars`) }) diff --git a/packages/compiler-sfc/__tests__/parse.spec.ts b/packages/compiler-sfc/__tests__/parse.spec.ts index 9b3e3e8a672..e650a850abd 100644 --- a/packages/compiler-sfc/__tests__/parse.spec.ts +++ b/packages/compiler-sfc/__tests__/parse.spec.ts @@ -37,7 +37,7 @@ font-weight: bold; } ` const { - descriptor: { styles } + descriptor: { styles }, } = parse(src) expect(styles[0].map).not.toBeUndefined() @@ -69,7 +69,7 @@ font-weight: bold; // Padding determines how many blank lines will there be before the style block const padding = Math.round(Math.random() * 10) const script = parse( - `${'\n'.repeat(padding)}\n` + `${'\n'.repeat(padding)}\n`, ).descriptor.script expect(script!.map).not.toBeUndefined() @@ -88,7 +88,7 @@ font-weight: bold; h1 foo div bar span baz -\n` +\n`, ).descriptor.template! expect(template.map).not.toBeUndefined() @@ -103,7 +103,7 @@ font-weight: bold; test('custom block', () => { const padding = Math.round(Math.random() * 10) const custom = parse( - `${'\n'.repeat(padding)}\n{\n "greeting": "hello"\n}\n\n` + `${'\n'.repeat(padding)}\n{\n "greeting": "hello"\n}\n\n`, ).descriptor.customBlocks[0] expect(custom!.map).not.toBeUndefined() @@ -138,42 +138,42 @@ h1 { color: red } const padTrue = parse(content.trim(), { pad: true }).descriptor expect(padTrue.script!.content).toBe( - Array(3 + 1).join('//\n') + '\nexport default {}\n' + Array(3 + 1).join('//\n') + '\nexport default {}\n', ) expect(padTrue.styles[0].content).toBe( - Array(6 + 1).join('\n') + '\nh1 { color: red }\n' + Array(6 + 1).join('\n') + '\nh1 { color: red }\n', ) expect(padTrue.customBlocks[0].content).toBe( - Array(9 + 1).join('\n') + '\n{ "greeting": "hello" }\n' + Array(9 + 1).join('\n') + '\n{ "greeting": "hello" }\n', ) const padLine = parse(content.trim(), { pad: 'line' }).descriptor expect(padLine.script!.content).toBe( - Array(3 + 1).join('//\n') + '\nexport default {}\n' + Array(3 + 1).join('//\n') + '\nexport default {}\n', ) expect(padLine.styles[0].content).toBe( - Array(6 + 1).join('\n') + '\nh1 { color: red }\n' + Array(6 + 1).join('\n') + '\nh1 { color: red }\n', ) expect(padLine.customBlocks[0].content).toBe( - Array(9 + 1).join('\n') + '\n{ "greeting": "hello" }\n' + Array(9 + 1).join('\n') + '\n{ "greeting": "hello" }\n', ) const padSpace = parse(content.trim(), { pad: 'space' }).descriptor expect(padSpace.script!.content).toBe( `\n\n\n`.replace( /./g, - ' ' - ) + '\n{ "greeting": "hello" }\n' + ' ', + ) + '\n{ "greeting": "hello" }\n', ) }) @@ -187,8 +187,8 @@ h1 { color: red } end: { line: 3, column: 1, - offset: 10 + content.length - } + offset: 10 + content.length, + }, }) }) @@ -198,7 +198,7 @@ h1 { color: red } expect(descriptor.template!.content).toBeFalsy() expect(descriptor.template!.loc).toMatchObject({ start: { line: 1, column: 12, offset: 11 }, - end: { line: 1, column: 12, offset: 11 } + end: { line: 1, column: 12, offset: 11 }, }) }) @@ -208,7 +208,7 @@ h1 { color: red } expect(descriptor.template!.content).toBeFalsy() expect(descriptor.template!.loc).toMatchObject({ start: { line: 1, column: 11, offset: 10 }, - end: { line: 1, column: 11, offset: 10 } + end: { line: 1, column: 11, offset: 10 }, }) }) @@ -219,7 +219,7 @@ h1 { color: red } expect(parse(``).descriptor.styles.length).toBe(0) expect(parse(``).descriptor.customBlocks.length).toBe(0) expect( - parse(` \n\t `).descriptor.customBlocks.length + parse(` \n\t `).descriptor.customBlocks.length, ).toBe(0) }) @@ -239,19 +239,19 @@ h1 { color: red } const { descriptor } = parse( `\n`, { - ignoreEmpty: false - } + ignoreEmpty: false, + }, ) expect(descriptor.script).toBeTruthy() expect(descriptor.script!.loc).toMatchObject({ start: { line: 1, column: 9, offset: 8 }, - end: { line: 1, column: 9, offset: 8 } + end: { line: 1, column: 9, offset: 8 }, }) expect(descriptor.scriptSetup).toBeTruthy() expect(descriptor.scriptSetup!.loc).toMatchObject({ start: { line: 2, column: 15, offset: 32 }, - end: { line: 3, column: 1, offset: 33 } + end: { line: 3, column: 1, offset: 33 }, }) }) @@ -267,7 +267,7 @@ h1 { color: red } test('treat empty lang attribute as the html', () => { const content = `
` const { descriptor, errors } = parse( - `` + ``, ) expect(descriptor.template!.content).toBe(content) expect(errors.length).toBe(0) @@ -277,7 +277,7 @@ h1 { color: red } test('template with preprocessor lang should be treated as plain text', () => { const content = `p(v-if="1 < 2") test
` const { descriptor, errors } = parse( - `` + ``, ) expect(errors.length).toBe(0) expect(descriptor.template!.content).toBe(content) @@ -301,17 +301,17 @@ h1 { color: red } expect(parse(``).descriptor.slotted).toBe(false) expect( parse(``).descriptor - .slotted + .slotted, ).toBe(false) expect( parse( - `` - ).descriptor.slotted + ``, + ).descriptor.slotted, ).toBe(true) expect( parse( - `` - ).descriptor.slotted + ``, + ).descriptor.slotted, ).toBe(true) }) @@ -332,8 +332,8 @@ h1 { color: red } options.onError!(new Error('foo') as any) return createRoot([]) }, - compile: baseCompile - } + compile: baseCompile, + }, }) expect(errors.length).toBe(2) // error thrown by the custom parse @@ -344,7 +344,7 @@ h1 { color: red } test('treat custom blocks as raw text', () => { const { errors, descriptor } = parse( - ` <-& ` + ` <-& `, ) expect(errors.length).toBe(0) expect(descriptor.customBlocks[0].content).toBe(` <-& `) @@ -358,7 +358,7 @@ h1 { color: red } test('should only allow single template element', () => { assertWarning( parse(``).errors, - `Single file component can contain only one