Skip to content

Commit

Permalink
refactor: update babel-helper-module-imports and use its built-in imp…
Browse files Browse the repository at this point in the history
…orts-merging feature

The snapshots are also updated. These are just order-related changes,
the functionality remains the same.
  • Loading branch information
haoqunjiang committed Mar 27, 2024
1 parent fb00715 commit 9770f43
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/babel-plugin-jsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dist"
],
"dependencies": {
"@babel/helper-module-imports": "~7.22.15",
"@babel/helper-module-imports": "^7.24.3",
"@babel/helper-plugin-utils": "^7.22.5",
"@babel/plugin-syntax-jsx": "^7.23.3",
"@babel/template": "^7.23.9",
Expand Down
64 changes: 30 additions & 34 deletions packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`_Fragment already imported > _Fragment already imported 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode, Fragment as _Fragment2 } from "vue";
import { Fragment as _Fragment } from 'vue';
"import { Fragment as _Fragment, Fragment as _Fragment2, createTextVNode as _createTextVNode, createVNode as _createVNode } from 'vue';
const Root1 = () => _createVNode(_Fragment2, null, [_createTextVNode("root1")]);
const Root2 = () => _createVNode(_Fragment, null, [_createTextVNode("root2")]);"
`;

exports[`MereProps Order > MereProps Order 1`] = `
"import { createVNode as _createVNode, mergeProps as _mergeProps, createTextVNode as _createTextVNode } from "vue";
"import { createTextVNode as _createTextVNode, mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
_createVNode("button", _mergeProps({
"loading": true
}, x, {
Expand All @@ -30,17 +29,17 @@ createVNode('div', null, ['Without JSX should work']);"
`;

exports[`Without props > Without props 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
"import { createTextVNode as _createTextVNode, createVNode as _createVNode } from "vue";
_createVNode("a", null, [_createTextVNode("a")]);"
`;

exports[`custom directive > custom directive 1`] = `
"import { withDirectives as _withDirectives, createVNode as _createVNode, resolveDirective as _resolveDirective, resolveComponent as _resolveComponent } from "vue";
"import { resolveComponent as _resolveComponent, resolveDirective as _resolveDirective, createVNode as _createVNode, withDirectives as _withDirectives } from "vue";
_withDirectives(_createVNode(_resolveComponent("A"), null, null, 512), [[_resolveDirective("cus"), x]]);"
`;

exports[`custom directive > custom directive 2`] = `
"import { withDirectives as _withDirectives, createVNode as _createVNode, resolveDirective as _resolveDirective, resolveComponent as _resolveComponent, Fragment as _Fragment } from "vue";
"import { Fragment as _Fragment, resolveComponent as _resolveComponent, resolveDirective as _resolveDirective, createVNode as _createVNode, withDirectives as _withDirectives } from "vue";
_createVNode(_Fragment, null, [_withDirectives(_createVNode(_resolveComponent("A"), null, null, 512), [[_resolveDirective("xxx"), x]]), _withDirectives(_createVNode(_resolveComponent("A"), null, null, 512), [[_resolveDirective("xxx"), x]]), _withDirectives(_createVNode(_resolveComponent("A"), null, null, 512), [[_resolveDirective("xxx"), x, 'y']]), _withDirectives(_createVNode(_resolveComponent("A"), null, null, 512), [[_resolveDirective("xxx"), x, 'y', {
a: true,
b: true
Expand All @@ -57,31 +56,31 @@ _createVNode(_Fragment, null, [_withDirectives(_createVNode(_resolveComponent("A
`;

exports[`disable object slot syntax with defaultSlot > defaultSlot 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent } from "vue";
"import { resolveComponent as _resolveComponent, createVNode as _createVNode } from "vue";
_createVNode(_resolveComponent("Badge"), null, {
default: () => [slots.default()],
_: 1
});"
`;

exports[`dynamic type in input > dynamic type in input 1`] = `
"import { withDirectives as _withDirectives, createVNode as _createVNode, vModelDynamic as _vModelDynamic } from "vue";
"import { vModelDynamic as _vModelDynamic, createVNode as _createVNode, withDirectives as _withDirectives } from "vue";
_withDirectives(_createVNode("input", {
"type": type,
"onUpdate:modelValue": $event => test = $event
}, null, 8, ["type", "onUpdate:modelValue"]), [[_vModelDynamic, test]]);"
`;

exports[`input[type="checkbox"] > input[type="checkbox"] 1`] = `
"import { withDirectives as _withDirectives, createVNode as _createVNode, vModelCheckbox as _vModelCheckbox } from "vue";
"import { vModelCheckbox as _vModelCheckbox, createVNode as _createVNode, withDirectives as _withDirectives } from "vue";
_withDirectives(_createVNode("input", {
"type": "checkbox",
"onUpdate:modelValue": $event => test = $event
}, null, 8, ["onUpdate:modelValue"]), [[_vModelCheckbox, test]]);"
`;

exports[`input[type="radio"] > input[type="radio"] 1`] = `
"import { withDirectives as _withDirectives, createVNode as _createVNode, vModelRadio as _vModelRadio, Fragment as _Fragment } from "vue";
"import { Fragment as _Fragment, vModelRadio as _vModelRadio, createVNode as _createVNode, withDirectives as _withDirectives } from "vue";
_createVNode(_Fragment, null, [_withDirectives(_createVNode("input", {
"type": "radio",
"value": "1",
Expand All @@ -96,7 +95,7 @@ _createVNode(_Fragment, null, [_withDirectives(_createVNode("input", {
`;

exports[`input[type="text"] .lazy modifier > input[type="text"] .lazy modifier 1`] = `
"import { withDirectives as _withDirectives, createVNode as _createVNode, vModelText as _vModelText } from "vue";
"import { vModelText as _vModelText, createVNode as _createVNode, withDirectives as _withDirectives } from "vue";
_withDirectives(_createVNode("input", {
"onUpdate:modelValue": $event => test = $event
}, null, 8, ["onUpdate:modelValue"]), [[_vModelText, test, void 0, {
Expand All @@ -105,31 +104,30 @@ _withDirectives(_createVNode("input", {
`;

exports[`input[type="text"] > input[type="text"] 1`] = `
"import { withDirectives as _withDirectives, createVNode as _createVNode, vModelText as _vModelText } from "vue";
"import { vModelText as _vModelText, createVNode as _createVNode, withDirectives as _withDirectives } from "vue";
_withDirectives(_createVNode("input", {
"onUpdate:modelValue": $event => test = $event
}, null, 8, ["onUpdate:modelValue"]), [[_vModelText, test]]);"
`;

exports[`isCustomElement > isCustomElement 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
"import { createTextVNode as _createTextVNode, createVNode as _createVNode } from "vue";
_createVNode("foo", null, [_createVNode("span", null, [_createTextVNode("foo")])]);"
`;

exports[`named import specifier \`Keep Alive\` > named import specifier \`Keep Alive\` 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
import { KeepAlive } from 'vue';
"import { KeepAlive, createTextVNode as _createTextVNode, createVNode as _createVNode } from 'vue';
_createVNode(KeepAlive, null, [_createTextVNode("123")]);"
`;

exports[`namespace specifier \`Keep Alive\` > namespace specifier \`Keep Alive\` 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
"import { createTextVNode as _createTextVNode, createVNode as _createVNode } from "vue";
import * as Vue from 'vue';
_createVNode(Vue.KeepAlive, null, [_createTextVNode("123")]);"
`;

exports[`override props multiple > multiple 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent } from "vue";
"import { resolveComponent as _resolveComponent, createVNode as _createVNode } from "vue";
_createVNode(_resolveComponent("A"), {
"loading": true,
...a,
Expand All @@ -148,23 +146,23 @@ _createVNode("div", a, null);"
`;

exports[`passing object slots via JSX children multiple expressions > multiple expressions 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent } from "vue";
"import { resolveComponent as _resolveComponent, createVNode as _createVNode } from "vue";
_createVNode(_resolveComponent("A"), null, {
default: () => [foo, bar],
_: 1
});"
`;

exports[`passing object slots via JSX children single expression, function expression > single expression, function expression 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent } from "vue";
"import { resolveComponent as _resolveComponent, createVNode as _createVNode } from "vue";
_createVNode(_resolveComponent("A"), null, {
default: () => "foo"
});"
`;

exports[`passing object slots via JSX children single expression, non-literal value: runtime check > single expression, non-literal value: runtime check 1`] = `
"let _slot;
import { createVNode as _createVNode, isVNode as _isVNode, resolveComponent as _resolveComponent } from "vue";
"import { resolveComponent as _resolveComponent, isVNode as _isVNode, createVNode as _createVNode } from "vue";
let _slot;
function _isSlot(s) {
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !_isVNode(s);
}
Expand All @@ -176,8 +174,7 @@ _createVNode(_resolveComponent("A"), null, _isSlot(_slot = foo()) ? _slot : {
`;

exports[`reassign variable as component > reassign variable as component 1`] = `
"import { isVNode as _isVNode, createVNode as _createVNode } from "vue";
import { defineComponent } from 'vue';
"import { defineComponent, createVNode as _createVNode, isVNode as _isVNode } from 'vue';
function _isSlot(s) {
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !_isVNode(s);
}
Expand All @@ -201,7 +198,7 @@ a = _createVNode(A, null, _isSlot(a) ? a : {
`;

exports[`select > select 1`] = `
"import { withDirectives as _withDirectives, vModelSelect as _vModelSelect, createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
"import { createTextVNode as _createTextVNode, createVNode as _createVNode, vModelSelect as _vModelSelect, withDirectives as _withDirectives } from "vue";
_withDirectives(_createVNode("select", {
"onUpdate:modelValue": $event => test = $event
}, [_createVNode("option", {
Expand All @@ -219,25 +216,24 @@ custom("div", null, [_createTextVNode("pragma")]);"
`;

exports[`should keep \`import * as Vue from "vue"\` > should keep \`import * as Vue from "vue"\` 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
"import { createTextVNode as _createTextVNode, createVNode as _createVNode } from "vue";
import * as Vue from 'vue';
_createVNode("div", null, [_createTextVNode("Vue")]);"
`;

exports[`single no need for a mergeProps call > single no need for a mergeProps call 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
"import { createTextVNode as _createTextVNode, createVNode as _createVNode } from "vue";
_createVNode("div", x, [_createTextVNode("single")], 16);"
`;

exports[`specifiers should be merged into a single importDeclaration > specifiers should be merged into a single importDeclaration 1`] = `
"import { createVNode as _createVNode } from "vue";
import { createVNode, Fragment as _Fragment } from 'vue';
"import { createVNode, Fragment as _Fragment, createVNode as _createVNode } from 'vue';
import { vShow } from 'vue';
_createVNode(_Fragment, null, null);"
`;

exports[`textarea > textarea 1`] = `
"import { withDirectives as _withDirectives, createVNode as _createVNode, vModelText as _vModelText } from "vue";
"import { vModelText as _vModelText, createVNode as _createVNode, withDirectives as _withDirectives } from "vue";
_withDirectives(_createVNode("textarea", {
"onUpdate:modelValue": $event => test = $event
}, null, 8, ["onUpdate:modelValue"]), [[_vModelText, test]]);"
Expand All @@ -252,20 +248,20 @@ custom("div", {
`;

exports[`use "model" as the prop name > use "model" as the prop name 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent } from "vue";
"import { resolveComponent as _resolveComponent, createVNode as _createVNode } from "vue";
_createVNode(_resolveComponent("C"), {
"model": foo,
"onUpdate:model": $event => foo = $event
}, null, 8, ["model", "onUpdate:model"]);"
`;

exports[`using v-slots without children should not be spread > using v-slots without children should not be spread 1`] = `
"import { createVNode as _createVNode, resolveDirective as _resolveDirective, resolveComponent as _resolveComponent } from "vue";
"import { resolveComponent as _resolveComponent, resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
_createVNode(_resolveComponent("A"), null, slots);"
`;

exports[`v-model target value support variable > v-model target value support variable 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, Fragment as _Fragment } from "vue";
"import { Fragment as _Fragment, resolveComponent as _resolveComponent, createVNode as _createVNode } from "vue";
const foo = 'foo';
const a = () => 'a';
const b = {
Expand Down Expand Up @@ -308,7 +304,7 @@ _createVNode(_Fragment, null, [_createVNode(_resolveComponent("A"), {
`;

exports[`v-show > v-show 1`] = `
"import { withDirectives as _withDirectives, createVNode as _createVNode, vShow as _vShow, createTextVNode as _createTextVNode } from "vue";
"import { createTextVNode as _createTextVNode, vShow as _vShow, createVNode as _createVNode, withDirectives as _withDirectives } from "vue";
_withDirectives(_createVNode("div", null, [_createTextVNode("vShow")], 512), [[_vShow, x]]);"
`;

Expand All @@ -320,7 +316,7 @@ _createVNode("h1", {
`;

exports[`vModels > vModels 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent } from "vue";
"import { resolveComponent as _resolveComponent, createVNode as _createVNode } from "vue";
_createVNode(_resolveComponent("C"), {
"modelValue": foo,
"modelModifiers": {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-resolve-type/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"dependencies": {
"@babel/code-frame": "^7.23.5",
"@babel/helper-module-imports": "~7.22.15",
"@babel/helper-module-imports": "^7.24.3",
"@babel/helper-plugin-utils": "^7.22.5",
"@babel/parser": "^7.23.9",
"@vue/compiler-sfc": "^3.4.15"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ defineComponent((props: Props & Props2) => {
`;
exports[`resolve type > runtime props > with dynamic default value 1`] = `
"import { _mergeDefaults } from "vue";
import { defineComponent, h } from 'vue';
"import { defineComponent, h, _mergeDefaults } from 'vue';
const defaults = {};
defineComponent((props: {
msg?: string;
Expand Down
31 changes: 23 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9770f43

Please sign in to comment.