From 7edd390a900c342e69d3cc994e001438146264b3 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 25 Feb 2022 15:07:26 +0800 Subject: [PATCH] wip(app): nvue styler --- .../nvue/__snapshots__/compiler.spec.ts.snap | 49 ++++++++++++------- .../__tests__/nvue/compiler.spec.ts | 41 ++++++++-------- .../uni-app-vite/src/nvue/plugin/index.ts | 12 +++-- .../nvue/plugin/transforms/transformAttrs.ts | 39 +++++++++++++++ .../uni-app-vue/dist/nvue.runtime.esm.dev.js | 31 ++++++------ .../uni-app-vue/dist/nvue.runtime.esm.prod.js | 31 ++++++------ packages/uni-app-vue/lib/nvue.runtime.esm.js | 34 ++++++------- .../__tests__/combinators.spec.ts | 25 ++++++++-- .../__tests__/normalize.spec.ts | 8 +-- .../__tests__/objectifier.spec.ts | 40 +++++++-------- .../uni-nvue-styler/src/normalize/length.ts | 2 +- packages/uni-nvue-styler/src/objectifier.ts | 10 +++- 12 files changed, 198 insertions(+), 124 deletions(-) create mode 100644 packages/uni-app-vite/src/nvue/plugin/transforms/transformAttrs.ts diff --git a/packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap b/packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap index 18f6e903ed..5acd016687 100644 --- a/packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap +++ b/packages/uni-app-vite/__tests__/nvue/__snapshots__/compiler.spec.ts.snap @@ -13,6 +13,20 @@ export function render(_ctx, _cache) { }" `; +exports[`app-nvue: compiler 1`] = ` +"import { openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\" + +const _hoisted_1 = { + \\"data-id\\": \\"id\\", + scrollX: \\"true\\", + showScrollbar: true +} + +export function render(_ctx, _cache) { + return (_openBlock(), _createElementBlock(\\"scroll-view\\", _hoisted_1)) +}" +`; + exports[`app-nvue: compiler 1`] = ` "import { resolveComponent as _resolveComponent, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\" @@ -62,45 +76,44 @@ export function render(_ctx, _cache) { exports[`app-nvue: compiler hello 1`] = ` "import { createElementVNode as _createElementVNode, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\" -const _hoisted_1 = [\\"appendAsTree\\"] +const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"hello\\", -1 /* HOISTED */) +const _hoisted_2 = [ + _hoisted_1 +] export function render(_ctx, _cache) { - return (_openBlock(), _createElementBlock(\\"view\\", null, [ - _createElementVNode(\\"u-text\\", { appendAsTree: true }, \\"hello\\", 8 /* PROPS */, _hoisted_1) - ])) + return (_openBlock(), _createElementBlock(\\"view\\", null, _hoisted_2)) }" `; exports[`app-nvue: compiler hello 1`] = ` "import { createElementVNode as _createElementVNode, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\" -const _hoisted_1 = [\\"appendAsTree\\"] +const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"hello\\", -1 /* HOISTED */) +const _hoisted_2 = [ + _hoisted_1 +] export function render(_ctx, _cache) { - return (_openBlock(), _createElementBlock(\\"view\\", null, [ - _createElementVNode(\\"u-text\\", { appendAsTree: true }, \\"hello\\", 8 /* PROPS */, _hoisted_1) - ])) + return (_openBlock(), _createElementBlock(\\"view\\", null, _hoisted_2)) }" `; exports[`app-nvue: compiler hello{{a}}aaa{{a}}{{b}} 1`] = ` "import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\" -const _hoisted_1 = [\\"appendAsTree\\"] -const _hoisted_2 = [\\"appendAsTree\\"] -const _hoisted_3 = [\\"appendAsTree\\"] -const _hoisted_4 = [\\"appendAsTree\\"] -const _hoisted_5 = [\\"appendAsTree\\"] +const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"hello\\", -1 /* HOISTED */) +const _hoisted_2 = /*#__PURE__*/_createElementVNode(\\"u-text\\", null, \\"aaa\\", -1 /* HOISTED */) export function render(_ctx, _cache) { return (_openBlock(), _createElementBlock(\\"view\\", null, [ - _createElementVNode(\\"u-text\\", { appendAsTree: true }, \\"hello\\", 8 /* PROPS */, _hoisted_1), - _createElementVNode(\\"u-text\\", { appendAsTree: true }, _toDisplayString(_ctx.a), 9 /* TEXT, PROPS */, _hoisted_2), + _hoisted_1, + _createElementVNode(\\"u-text\\", null, _toDisplayString(_ctx.a), 1 /* TEXT */), _createElementVNode(\\"view\\", null, [ - _createElementVNode(\\"u-text\\", { appendAsTree: true }, \\"aaa\\", 8 /* PROPS */, _hoisted_3), - _createElementVNode(\\"u-text\\", { appendAsTree: true }, _toDisplayString(_ctx.a), 9 /* TEXT, PROPS */, _hoisted_4) + _hoisted_2, + _createElementVNode(\\"u-text\\", null, _toDisplayString(_ctx.a), 1 /* TEXT */) ]), - _createElementVNode(\\"u-text\\", { appendAsTree: true }, _toDisplayString(_ctx.b), 9 /* TEXT, PROPS */, _hoisted_5) + _createElementVNode(\\"u-text\\", null, _toDisplayString(_ctx.b), 1 /* TEXT */) ])) }" `; diff --git a/packages/uni-app-vite/__tests__/nvue/compiler.spec.ts b/packages/uni-app-vite/__tests__/nvue/compiler.spec.ts index 52c740f5a8..75c4cb1b1c 100644 --- a/packages/uni-app-vite/__tests__/nvue/compiler.spec.ts +++ b/packages/uni-app-vite/__tests__/nvue/compiler.spec.ts @@ -1,10 +1,8 @@ import { NVUE_U_BUILT_IN_TAGS } from '@dcloudio/uni-shared' import { - DirectiveNode, ElementNode, ElementTypes, findDir, - findProp, SimpleExpressionNode, } from '@vue/compiler-core' import { compileTemplate } from '@vue/compiler-sfc' @@ -41,6 +39,7 @@ const codes = [ ``, `