@omnia/tooling-vue
Version:
Used to bundle and serve manifests web component that build on Vue framework.
113 lines (112 loc) • 5.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const babel_plugin_transform_vue_jsx_1 = tslib_1.__importDefault(require("@vue/babel-plugin-transform-vue-jsx"));
const babel_sugar_functional_vue_1 = tslib_1.__importDefault(require("@vue/babel-sugar-functional-vue"));
const babel_sugar_inject_h_1 = tslib_1.__importDefault(require("@vue/babel-sugar-inject-h"));
const babel_sugar_composition_api_inject_h_1 = tslib_1.__importDefault(require("@vue/babel-sugar-composition-api-inject-h"));
const babel_sugar_composition_api_render_instance_1 = tslib_1.__importDefault(require("@vue/babel-sugar-composition-api-render-instance"));
const babel_sugar_v_model_1 = tslib_1.__importDefault(require("@vue/babel-sugar-v-model"));
const babel_sugar_v_on_1 = tslib_1.__importDefault(require("@vue/babel-sugar-v-on"));
const autoImportVue = (t, path) => {
const importSource = "vue";
const imports = path.node.body.filter(t.isImportDeclaration);
const imported = imports.find(node => node.source.value === importSource);
const autoImport = () => path.unshiftContainer("body", t.importDeclaration([t.importDefaultSpecifier(t.identifier("Vue"))], t.stringLiteral(importSource)));
if (!imported) {
autoImport();
return;
}
const defaultSpecifier = imported.specifiers.find(t.isImportDefaultSpecifier);
if (!defaultSpecifier) {
autoImport();
//imported.specifiers.push(t.importDefaultSpecifier(t.identifier("Vue")));
}
else if (defaultSpecifier.local.name !== "Vue") {
autoImport();
}
};
const customSugarVModel = ({ types: t }) => {
// console.log('customSugarVModel')
return {
visitor: {
Program(p) {
p.traverse({
"ObjectMethod|ObjectProperty"(path) {
if (path.node.key.name !== "setup")
return;
path.traverse({
JSXAttribute(path) {
const n = path.get("name");
const isInputOrModel = n.node.name === "on-input" || n.node.name === "on-change" || n.node.name === "model";
// if (n.node.name === "model") {
// console.log(n.node.name, n.node, n)
// }
if (!isInputOrModel)
return;
path.traverse({
MemberExpression(path) {
const obj = path.get("object");
const prop = path.get("property");
if (t.isThisExpression(obj) && t.isIdentifier(prop) && prop.node.name === "$set") {
autoImportVue(t, p);
obj.replaceWith(t.identifier("Vue"));
prop.replaceWith(t.identifier("set"));
}
}
});
}
});
}
});
}
}
};
};
exports.default = (_, { functional = true, injectH = true, vModel = true, vOn = true, compositionAPI = false } = {}) => {
return {
plugins: [
functional && babel_sugar_functional_vue_1.default,
injectH && (compositionAPI ? [babel_sugar_composition_api_inject_h_1.default, { importSource: "vue" }] : babel_sugar_inject_h_1.default),
compositionAPI && [babel_sugar_composition_api_render_instance_1.default, { importSource: "vue" }],
//vModel && customSugarVModel,
vModel && babel_sugar_v_model_1.default,
vModel && customSugarVModel,
vOn && babel_sugar_v_on_1.default,
babel_plugin_transform_vue_jsx_1.default,
].filter(Boolean),
};
// return {
// plugins: [
// functional && babelSugarFunctionalVue,
// injectH && (compositionAPI ? babelSugarCompositionApiInjectH : babelSugarInjectH),
// vModel && babelSugarVModel,
// vOn && babelSugarVOn,
// compositionAPI && babelSugarCompositionApiRenderInstance,
// babelPluginTransformVueJsx,
// ].filter(Boolean),
// }
};
// function _interopDefault(a) {
// return a && "object" == typeof a && "default" in a ? a["default"] : a;
// }
// var babelPluginTransformVueJsx = _interopDefault(require("@vue/babel-plugin-transform-vue-jsx")),
// babelSugarFunctionalVue = _interopDefault(require("@vue/babel-sugar-functional-vue")),
// babelSugarInjectH = _interopDefault(require("@vue/babel-sugar-inject-h")),
// babelSugarCompositionApiInjectH = _interopDefault(require("@vue/babel-sugar-composition-api-inject-h")),
// babelSugarCompositionApiRenderInstance = _interopDefault(require("@vue/babel-sugar-composition-api-render-instance")),
// babelSugarVModel = _interopDefault(require("@vue/babel-sugar-v-model")),
// babelSugarVOn = _interopDefault(require("@vue/babel-sugar-v-on")),
// index = (a, { functional: b = !0, injectH: c = !0, vModel: d = !0, vOn: e = !0, compositionAPI: f = !1 } = {}) => ({
// plugins: [
// b && babelSugarFunctionalVue,
// c && (f ? babelSugarCompositionApiInjectH : babelSugarInjectH),
// d && babelSugarVModel,
// e && babelSugarVOn,
// f && babelSugarCompositionApiRenderInstance,
// babelPluginTransformVueJsx
// ].filter(
// Boolean
// ),
// });
// module.exports = index;