xhs-mp-compiler-cli 1.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/bin/xhs-mp-cli-build.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-build.js +42 -0
- package/dist/bin/xhs-mp-cli-dev.d.ts +2 -0
- package/dist/bin/xhs-mp-cli-dev.js +84 -0
- package/dist/bin/xhs-mp-cli.d.ts +2 -0
- package/dist/bin/xhs-mp-cli.js +16 -0
- package/dist/build/index.d.ts +3 -0
- package/dist/build/index.js +22 -0
- package/dist/dev-server/index.d.ts +3 -0
- package/dist/dev-server/index.js +62 -0
- package/dist/dev-server/lib/ensurePort.d.ts +2 -0
- package/dist/dev-server/lib/ensurePort.js +32 -0
- package/dist/dev-server/lib/openBrowser.d.ts +2 -0
- package/dist/dev-server/lib/openBrowser.js +23 -0
- package/dist/dev-server/lib/openChrome.applescript +78 -0
- package/dist/globalData/SjsModule.d.ts +32 -0
- package/dist/globalData/SjsModule.js +34 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +118 -0
- package/dist/types/index.d.ts +110 -0
- package/dist/types/index.js +13 -0
- package/dist/utils/asyncWebpack.d.ts +3 -0
- package/dist/utils/asyncWebpack.js +38 -0
- package/dist/utils/combineExtJson.d.ts +3 -0
- package/dist/utils/combineExtJson.js +74 -0
- package/dist/utils/common.d.ts +7 -0
- package/dist/utils/common.js +35 -0
- package/dist/utils/depenedHelper.d.ts +31 -0
- package/dist/utils/depenedHelper.js +89 -0
- package/dist/utils/getCssSuffixName.d.ts +1 -0
- package/dist/utils/getCssSuffixName.js +9 -0
- package/dist/utils/getMlSuffixName.d.ts +1 -0
- package/dist/utils/getMlSuffixName.js +6 -0
- package/dist/utils/getPrefixName.d.ts +1 -0
- package/dist/utils/getPrefixName.js +6 -0
- package/dist/utils/projectConfig.d.ts +1 -0
- package/dist/utils/projectConfig.js +20 -0
- package/dist/utils/transformAppJson.d.ts +16 -0
- package/dist/utils/transformAppJson.js +199 -0
- package/dist/utils/validateAppJson.d.ts +4 -0
- package/dist/utils/validateAppJson.js +111 -0
- package/dist/webpack-config/index.d.ts +4 -0
- package/dist/webpack-config/index.js +41 -0
- package/dist/webpack-config/lib/const.d.ts +13 -0
- package/dist/webpack-config/lib/const.js +15 -0
- package/dist/webpack-config/lib/css.d.ts +2 -0
- package/dist/webpack-config/lib/css.js +41 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.d.ts +13 -0
- package/dist/webpack-config/lib/postcssRpx2Vw.js +40 -0
- package/dist/webpack-config/lib/tagTransformMap.d.ts +35 -0
- package/dist/webpack-config/lib/tagTransformMap.js +38 -0
- package/dist/webpack-config/lib/utils.d.ts +5 -0
- package/dist/webpack-config/lib/utils.js +37 -0
- package/dist/webpack-config/loaders/component-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-loader.js +31 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/component-entry-requirements-loader.js +24 -0
- package/dist/webpack-config/loaders/mini-style-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/mini-style-loader.js +69 -0
- package/dist/webpack-config/loaders/ml-loader/index.d.ts +3 -0
- package/dist/webpack-config/loaders/ml-loader/index.js +66 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/generator.js +107 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.d.ts +6 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/index.js +64 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.d.ts +11 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectScript.js +41 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/injectTemplate.js +18 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/parser.js +21 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.d.ts +7 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformer.js +185 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBindAttribute.js +73 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.d.ts +13 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleBlockTag.js +42 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleCatchAttribute.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleClassAttribute.js +17 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleDataAttribute.js +23 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.d.ts +13 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleHiddenAttribute.js +25 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.d.ts +4 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleImportTag.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleIncludeTag.js +30 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleLoopAttribute.js +89 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleMLAttribute.js +33 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleModelAttribute.js +61 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleOtherAttribute.js +35 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.d.ts +11 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSjsEvent.js +72 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSlotAttribute.js +74 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleSpaceAttribute.js +12 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.d.ts +2 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/handleStyleAttribute.js +16 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.d.ts +10 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/transformerUtils/utils.js +80 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.d.ts +7 -0
- package/dist/webpack-config/loaders/ml-loader/ml2vue/utils.js +41 -0
- package/dist/webpack-config/loaders/render-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/render-entry-loader.js +50 -0
- package/dist/webpack-config/loaders/service-entry-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/service-entry-loader.js +51 -0
- package/dist/webpack-config/loaders/sjs-loader/frame.d.ts +1 -0
- package/dist/webpack-config/loaders/sjs-loader/frame.js +51 -0
- package/dist/webpack-config/loaders/sjs-loader/index.d.ts +1 -0
- package/dist/webpack-config/loaders/sjs-loader/index.js +93 -0
- package/dist/webpack-config/loaders/utils.d.ts +13 -0
- package/dist/webpack-config/loaders/utils.js +41 -0
- package/dist/webpack-config/loaders/wxss-loader.d.ts +1 -0
- package/dist/webpack-config/loaders/wxss-loader.js +76 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.d.ts +19 -0
- package/dist/webpack-config/plugins/VueLoaderPlugin.js +205 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.d.ts +8 -0
- package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.js +40 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.d.ts +36 -0
- package/dist/webpack-config/plugins/XhsMpJsonPlugin.js +71 -0
- package/dist/webpack-config/presets/babel.d.ts +8 -0
- package/dist/webpack-config/presets/babel.js +57 -0
- package/dist/webpack-config/presets/common.d.ts +4 -0
- package/dist/webpack-config/presets/common.js +40 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.d.ts +23 -0
- package/dist/webpack-config/presets/mp/MpEntryPlugin.js +87 -0
- package/dist/webpack-config/presets/mp/index.d.ts +4 -0
- package/dist/webpack-config/presets/mp/index.js +48 -0
- package/dist/webpack-config/presets/prod.d.ts +4 -0
- package/dist/webpack-config/presets/prod.js +85 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.d.ts +18 -0
- package/dist/webpack-config/presets/render/ComponentEntryPlugin.js +77 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +9 -0
- package/dist/webpack-config/presets/render/RenderChunkPlugin.js +65 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.d.ts +14 -0
- package/dist/webpack-config/presets/render/RenderEntryPlugin.js +42 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.d.ts +31 -0
- package/dist/webpack-config/presets/render/SjsEntryPlugin.js +124 -0
- package/dist/webpack-config/presets/render/index.d.ts +4 -0
- package/dist/webpack-config/presets/render/index.js +99 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/ServiceEntryPlugin.js +36 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.d.ts +6 -0
- package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +46 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.d.ts +8 -0
- package/dist/webpack-config/presets/service/XhsResolveLimitPlugin.js +65 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.d.ts +5 -0
- package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.js +27 -0
- package/dist/webpack-config/presets/service/index.d.ts +4 -0
- package/dist/webpack-config/presets/service/index.js +38 -0
- package/package.json +124 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const getMlSuffixName_1 = __importDefault(require("../../utils/getMlSuffixName"));
|
|
8
|
+
const common_1 = require("../../utils/common");
|
|
9
|
+
function entryLoader() {
|
|
10
|
+
const { miniprogramDir, jsonDependencies } = this._compiler.xhsData;
|
|
11
|
+
const { compPath } = this.getOptions();
|
|
12
|
+
const { pkg, root } = this.getOptions();
|
|
13
|
+
for (const file of jsonDependencies) {
|
|
14
|
+
this.addDependency(file);
|
|
15
|
+
}
|
|
16
|
+
let name = 'XHS_COMPONENTS';
|
|
17
|
+
if (pkg === 'sub') {
|
|
18
|
+
name = `XHS_COMPONENTS_${root}`;
|
|
19
|
+
}
|
|
20
|
+
return `
|
|
21
|
+
;(globalThis['${name}'] || (globalThis['${name}'] = { default: {} })).default['${compPath}'] = () => require('${(0, common_1.unixJoin)(miniprogramDir, `${compPath}.${(0, getMlSuffixName_1.default)()}`)}')
|
|
22
|
+
`;
|
|
23
|
+
}
|
|
24
|
+
module.exports = entryLoader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
16
|
+
const cssnano_1 = __importDefault(require("cssnano"));
|
|
17
|
+
const common_1 = require("../../utils/common");
|
|
18
|
+
const CSS_MINIMIZER_OPTIONS = {
|
|
19
|
+
preset: ['default', { normalizeUrl: false, calc: false }],
|
|
20
|
+
};
|
|
21
|
+
const minify = (source, name) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const postcssOptions = {
|
|
24
|
+
to: name,
|
|
25
|
+
from: name,
|
|
26
|
+
};
|
|
27
|
+
try {
|
|
28
|
+
const result = yield cssnano_1.default.process(source, postcssOptions, CSS_MINIMIZER_OPTIONS);
|
|
29
|
+
return {
|
|
30
|
+
code: result.css,
|
|
31
|
+
warnings: (_b = (_a = result.warnings()) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, i => i.toString())
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
return {
|
|
36
|
+
code: source,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
function miniStyleLoader(source) {
|
|
41
|
+
var _a;
|
|
42
|
+
const callback = this.async();
|
|
43
|
+
const { resourcePath } = this;
|
|
44
|
+
const { miniprogramDir, enableVDom, enableV1, enableV2, independent } = this.getOptions();
|
|
45
|
+
const shortPath = (0, common_1.getShortPath)(miniprogramDir, resourcePath).replace(/\.wxss$/, ".css");
|
|
46
|
+
source = (_a = source === null || source === void 0 ? void 0 : source.trim) === null || _a === void 0 ? void 0 : _a.call(source);
|
|
47
|
+
function result(code) {
|
|
48
|
+
if (!code) {
|
|
49
|
+
return `export default void 0;`;
|
|
50
|
+
}
|
|
51
|
+
// 判断浏览器环境,注入css添加逻辑
|
|
52
|
+
return new webpack_sources_1.RawSource(`globalThis.localStorage && globalThis.__XHS_APPEND_CSS(${JSON.stringify(code)});
|
|
53
|
+
export default ${JSON.stringify(shortPath)};
|
|
54
|
+
`).source();
|
|
55
|
+
}
|
|
56
|
+
// 压缩css
|
|
57
|
+
minify(source, shortPath)
|
|
58
|
+
.then(({ code, warnings }) => {
|
|
59
|
+
// vdom架构下emit出一份css文件
|
|
60
|
+
if ((independent || enableVDom) && code) {
|
|
61
|
+
enableV1 && this.emitFile(`v1/${shortPath}`, code);
|
|
62
|
+
enableV2 && this.emitFile(`v2/${shortPath}`, code);
|
|
63
|
+
}
|
|
64
|
+
callback(null, result(code));
|
|
65
|
+
}).catch(error => {
|
|
66
|
+
callback(error);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
module.exports = miniStyleLoader;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
16
|
+
const ml2vue_1 = __importDefault(require("./ml2vue"));
|
|
17
|
+
const getCssSuffixName_1 = __importDefault(require("../../../utils/getCssSuffixName"));
|
|
18
|
+
const getMlSuffixName_1 = __importDefault(require("../../../utils/getMlSuffixName"));
|
|
19
|
+
const common_1 = require("../../../utils/common");
|
|
20
|
+
const isCustomComponents = (filePath) => {
|
|
21
|
+
try {
|
|
22
|
+
const json = JSON.parse(fs_extra_1.default.readFileSync(`${filePath}.json`, 'utf-8'));
|
|
23
|
+
return json.component;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function mlLoader(source) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
32
|
+
const callback = this.async();
|
|
33
|
+
try {
|
|
34
|
+
const { resourcePath, _compiler, resourceQuery } = this;
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
const xhsData = (_compiler === null || _compiler === void 0 ? void 0 : _compiler.xhsData) || {};
|
|
37
|
+
const shortPath = (0, common_1.getShortPath)(xhsData.miniprogramDir, resourcePath);
|
|
38
|
+
const styleIsolation = (_d = (_c = (_b = (_a = xhsData.appJSON) === null || _a === void 0 ? void 0 : _a.componentsMap) === null || _b === void 0 ? void 0 : _b[shortPath]) === null || _c === void 0 ? void 0 : _c.styleIsolation) !== null && _d !== void 0 ? _d : null;
|
|
39
|
+
const componentIndex = styleIsolation === 'shared' ? 0 : (_h = (_g = (_f = (_e = xhsData.appJSON) === null || _e === void 0 ? void 0 : _e.componentsMap) === null || _f === void 0 ? void 0 : _f[shortPath]) === null || _g === void 0 ? void 0 : _g.index) !== null && _h !== void 0 ? _h : null;
|
|
40
|
+
const reg = new RegExp(`.${(0, getMlSuffixName_1.default)()}$`);
|
|
41
|
+
const filePath = (0, common_1.toUnixPath)(resourcePath.replace(reg, ''));
|
|
42
|
+
// 收集 imports / includes
|
|
43
|
+
const importMap = {};
|
|
44
|
+
const includeMap = {};
|
|
45
|
+
// 收集 sjs module name
|
|
46
|
+
const sjsScopeNames = [];
|
|
47
|
+
const res = yield (0, ml2vue_1.default)(this, xhsData.miniprogramDir, source, shortPath, filePath, importMap, includeMap, isCustomComponents(filePath), componentIndex, resourceQuery, sjsScopeNames);
|
|
48
|
+
if (fs_extra_1.default.existsSync(`${filePath}.${(0, getCssSuffixName_1.default)()}`)) {
|
|
49
|
+
this.addDependency(`${filePath}.${(0, getCssSuffixName_1.default)()}`);
|
|
50
|
+
}
|
|
51
|
+
// fse.writeFileSync(`${__dirname}/.testTemp.vue`, res)
|
|
52
|
+
// if (/catchTapTest/g.test(res)) {
|
|
53
|
+
// fse.writeFileSync(`${__dirname}/.testTemp.vue`, res)
|
|
54
|
+
// }
|
|
55
|
+
// if (res.includes('include')) {
|
|
56
|
+
// fse.writeFileSync(`${__dirname}/.testTemp.vue`, res)
|
|
57
|
+
// debugger
|
|
58
|
+
// }
|
|
59
|
+
callback(null, res);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
callback(error);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.default = mlLoader;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
let result = '';
|
|
5
|
+
const emptyTags = {
|
|
6
|
+
area: 1,
|
|
7
|
+
base: 1,
|
|
8
|
+
basefont: 1,
|
|
9
|
+
br: 1,
|
|
10
|
+
col: 1,
|
|
11
|
+
frame: 1,
|
|
12
|
+
hr: 1,
|
|
13
|
+
img: 1,
|
|
14
|
+
input: 1,
|
|
15
|
+
isindex: 1,
|
|
16
|
+
link: 1,
|
|
17
|
+
meta: 1,
|
|
18
|
+
param: 1,
|
|
19
|
+
embed: 1,
|
|
20
|
+
'?xml': 1,
|
|
21
|
+
};
|
|
22
|
+
const ampRe = /&/g;
|
|
23
|
+
// var looseAmpRe = /&([^a-z#]|#(?:[^0-9x]|x(?:[^0-9a-f]|$)|$)|$)/gi
|
|
24
|
+
const ltRe = /</g;
|
|
25
|
+
const gtRe = />/g;
|
|
26
|
+
const quotRe = /"/g;
|
|
27
|
+
const eqRe = /=/g;
|
|
28
|
+
const config = {
|
|
29
|
+
disableAttribEscape: true,
|
|
30
|
+
};
|
|
31
|
+
function escapeAttrib(s) {
|
|
32
|
+
if (config.disableAttribEscape === true) {
|
|
33
|
+
return s.toString();
|
|
34
|
+
}
|
|
35
|
+
// null or undefined
|
|
36
|
+
if (s == null) {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
if (s.toString && typeof s.toString === 'function') {
|
|
40
|
+
// Escaping '=' defangs many UTF-7 and SGML short-tag attacks.
|
|
41
|
+
return s
|
|
42
|
+
.toString()
|
|
43
|
+
.replace(ampRe, '&')
|
|
44
|
+
.replace(ltRe, '<')
|
|
45
|
+
.replace(gtRe, '>')
|
|
46
|
+
.replace(quotRe, '"')
|
|
47
|
+
.replace(eqRe, '=');
|
|
48
|
+
}
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
const HTMLGenerator = (item, parent, eachFn) => {
|
|
52
|
+
// apply recursively to arrays
|
|
53
|
+
if (Array.isArray(item)) {
|
|
54
|
+
// parent, not item: the parent of an array item is not the array,
|
|
55
|
+
// but rather the element that contained the array
|
|
56
|
+
return item.map(subitem => HTMLGenerator(subitem, parent, eachFn)).join('');
|
|
57
|
+
}
|
|
58
|
+
let orig = item;
|
|
59
|
+
if (eachFn) {
|
|
60
|
+
item = eachFn(item, parent);
|
|
61
|
+
}
|
|
62
|
+
if (typeof item !== 'undefined' && typeof item.type !== 'undefined') {
|
|
63
|
+
switch (item.type) {
|
|
64
|
+
case 'text':
|
|
65
|
+
return item.data;
|
|
66
|
+
case 'directive':
|
|
67
|
+
return `<${item.data}>`;
|
|
68
|
+
case 'comment':
|
|
69
|
+
return `<!--${item.data}-->`;
|
|
70
|
+
case 'style':
|
|
71
|
+
case 'script':
|
|
72
|
+
case 'tag':
|
|
73
|
+
result = `<${item.name}`;
|
|
74
|
+
if (item.attribs && Object.keys(item.attribs).length > 0) {
|
|
75
|
+
const attrString = Object.keys(item.attribs)
|
|
76
|
+
.map(key => {
|
|
77
|
+
if (key === 'v-else' || key.startsWith('v-slot:')) {
|
|
78
|
+
return key;
|
|
79
|
+
}
|
|
80
|
+
return `${key}="${escapeAttrib(item.attribs[key])}"`;
|
|
81
|
+
})
|
|
82
|
+
.join(' ');
|
|
83
|
+
result += ` ${attrString}`;
|
|
84
|
+
}
|
|
85
|
+
if (item.children) {
|
|
86
|
+
// parent becomes the current element
|
|
87
|
+
// check if the current item (before any eachFns are run) - is a renderable
|
|
88
|
+
if (!orig.render) {
|
|
89
|
+
orig = parent;
|
|
90
|
+
}
|
|
91
|
+
result += `>${HTMLGenerator(item.children, orig, eachFn)}${emptyTags[item.name] ? '' : `</${item.name}>`}`;
|
|
92
|
+
}
|
|
93
|
+
else if (emptyTags[item.name]) {
|
|
94
|
+
result += '>';
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
result += `></${item.name}>`;
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
case 'cdata':
|
|
101
|
+
return `<!CDATA[${item.data}]]>`;
|
|
102
|
+
default:
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return item;
|
|
106
|
+
};
|
|
107
|
+
exports.default = HTMLGenerator;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const ml2vue: (context: any, miniprogramDir: string, sourceCode: string, shortPath: string, filePath: string, importMap: {
|
|
2
|
+
[key: string]: string[];
|
|
3
|
+
} | undefined, includeMap: {
|
|
4
|
+
[key: string]: string[];
|
|
5
|
+
} | undefined, isCustomComponents: boolean, componentIndex: number | null, resourceQuery: any, sjsScopeNames: string[]) => Promise<any>;
|
|
6
|
+
export default ml2vue;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
16
|
+
const parser_1 = __importDefault(require("./parser"));
|
|
17
|
+
const transformer_1 = __importDefault(require("./transformer"));
|
|
18
|
+
const generator_1 = __importDefault(require("./generator"));
|
|
19
|
+
const injectTemplate_1 = __importDefault(require("./injectTemplate"));
|
|
20
|
+
const injectScript_1 = __importDefault(require("./injectScript"));
|
|
21
|
+
const getCssSuffixName_1 = __importDefault(require("../../../../utils/getCssSuffixName"));
|
|
22
|
+
const SjsModule_1 = __importDefault(require("../../../../globalData/SjsModule"));
|
|
23
|
+
const utils_1 = require("./utils");
|
|
24
|
+
const ml2vue = (context_1, miniprogramDir_1, sourceCode_1, shortPath_1, filePath_1, ...args_1) => __awaiter(void 0, [context_1, miniprogramDir_1, sourceCode_1, shortPath_1, filePath_1, ...args_1], void 0, function* (context, miniprogramDir, sourceCode, shortPath, filePath, importMap = {}, includeMap = {}, isCustomComponents, componentIndex, resourceQuery, sjsScopeNames) {
|
|
25
|
+
let ast = yield (0, parser_1.default)(sourceCode);
|
|
26
|
+
let importBy = '';
|
|
27
|
+
const isInclude = resourceQuery.includes('include=true');
|
|
28
|
+
ast = (0, utils_1.sortNodes)(ast);
|
|
29
|
+
if (resourceQuery.includes('importBy="')) {
|
|
30
|
+
// 被 import 的文件,只有 template name 下的内容、import 标签生效
|
|
31
|
+
const filterImportNodes = node => node.type === 'tag' && ((0, utils_1.isTemplateDefineNode)(node) || (0, utils_1.isImportNode)(node));
|
|
32
|
+
ast = ast.filter(filterImportNodes);
|
|
33
|
+
importBy = resourceQuery.match(/importBy="(.+?)"/)[1];
|
|
34
|
+
}
|
|
35
|
+
if (isInclude) {
|
|
36
|
+
const includeTagFilter = node => !(0, utils_1.isTemplateDefineNode)(node) || node.name !== 'wxs';
|
|
37
|
+
ast = ast.filter(includeTagFilter);
|
|
38
|
+
}
|
|
39
|
+
const distAst = yield (0, transformer_1.default)(context, ast, filePath, importMap, includeMap, componentIndex, importBy, sjsScopeNames);
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
let distCode = (0, generator_1.default)(distAst);
|
|
42
|
+
// 使用 <template> <xhs-page> 等标签包裹
|
|
43
|
+
const isPage = !(isCustomComponents || importBy || isInclude);
|
|
44
|
+
distCode = (0, injectTemplate_1.default)(distCode, shortPath, isPage);
|
|
45
|
+
const cssPath = `${filePath}.${(0, getCssSuffixName_1.default)()}`;
|
|
46
|
+
const cssExists = !importBy && !isInclude && fs_extra_1.default.existsSync(cssPath);
|
|
47
|
+
// 当前文件存在 import 或者 include 时,或者使用了 sjs 时,修改 script 部分
|
|
48
|
+
if (importMap[filePath] ||
|
|
49
|
+
includeMap[filePath] ||
|
|
50
|
+
Object.keys(SjsModule_1.default.moduleMap).includes(filePath) ||
|
|
51
|
+
cssExists) {
|
|
52
|
+
distCode = (0, injectScript_1.default)({
|
|
53
|
+
cssPath: cssExists ? cssPath : '',
|
|
54
|
+
miniprogramDir,
|
|
55
|
+
source: distCode,
|
|
56
|
+
filePath,
|
|
57
|
+
imports: importMap[filePath],
|
|
58
|
+
includes: includeMap[filePath],
|
|
59
|
+
sjsModules: SjsModule_1.default.moduleMap,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return distCode;
|
|
63
|
+
});
|
|
64
|
+
exports.default = ml2vue;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ModuleMap } from '../../../../globalData/SjsModule';
|
|
2
|
+
declare const injectScript: ({ cssPath, miniprogramDir, source, filePath, imports, includes, sjsModules, }: {
|
|
3
|
+
cssPath: string;
|
|
4
|
+
miniprogramDir: string;
|
|
5
|
+
source: string;
|
|
6
|
+
filePath: string;
|
|
7
|
+
imports: string[];
|
|
8
|
+
includes: string[];
|
|
9
|
+
sjsModules: ModuleMap;
|
|
10
|
+
}) => string;
|
|
11
|
+
export default injectScript;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const common_1 = require("../../../../utils/common");
|
|
9
|
+
const injectScript = ({ cssPath, miniprogramDir, source, filePath, imports = [], includes = [], sjsModules, }) => {
|
|
10
|
+
const importStatements = {};
|
|
11
|
+
const sjsRelations = {};
|
|
12
|
+
for (const targetPath of imports) {
|
|
13
|
+
const compName = (0, utils_1.formatPathToVar)(targetPath);
|
|
14
|
+
importStatements[compName] = `import ${compName} from '${(0, common_1.toUnixPath)(targetPath)}?importBy="${(0, utils_1.formatPathToVar)(filePath)}"'`;
|
|
15
|
+
}
|
|
16
|
+
for (const targetPath of includes) {
|
|
17
|
+
const compName = (0, utils_1.formatPathToVar)(targetPath);
|
|
18
|
+
importStatements[compName] = `import ${compName} from '${(0, common_1.toUnixPath)(targetPath)}?include=true'`;
|
|
19
|
+
}
|
|
20
|
+
for (const [moduleName, target] of Object.entries((sjsModules === null || sjsModules === void 0 ? void 0 : sjsModules[filePath]) || [])) {
|
|
21
|
+
sjsRelations[moduleName] = (0, common_1.unixResolve)(path_1.default.dirname(filePath), target).replace(`${miniprogramDir}/`, '');
|
|
22
|
+
}
|
|
23
|
+
const useImport = Object.keys(importStatements).length > 0;
|
|
24
|
+
const useSjs = Object.keys(sjsRelations).length > 0;
|
|
25
|
+
return `${source}
|
|
26
|
+
<script>
|
|
27
|
+
${cssPath ? `import cssPath from "${cssPath}?from=xhsml"` : ''}
|
|
28
|
+
${useImport ? Object.values(importStatements).join(';\n') : ''}
|
|
29
|
+
export default {
|
|
30
|
+
${cssPath ? `cssPath,` : ''}
|
|
31
|
+
${useSjs ? `sjsRelations: ${JSON.stringify(sjsRelations)},` : ''}
|
|
32
|
+
${useImport
|
|
33
|
+
? `
|
|
34
|
+
methods: {
|
|
35
|
+
getComp: () => ({${Object.keys(importStatements).join(',')}})
|
|
36
|
+
}`
|
|
37
|
+
: ''}
|
|
38
|
+
}
|
|
39
|
+
</script>`;
|
|
40
|
+
};
|
|
41
|
+
exports.default = injectScript;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const injectTemplate = (source, shortPath, isPage) => {
|
|
4
|
+
// 当是 page 时,需要使用 xhs-page 包裹以支持 :host 选择器
|
|
5
|
+
if (isPage) {
|
|
6
|
+
return `
|
|
7
|
+
<template>
|
|
8
|
+
<xhs-page is="${shortPath}">
|
|
9
|
+
${source}
|
|
10
|
+
</xhs-page>
|
|
11
|
+
</template>`;
|
|
12
|
+
}
|
|
13
|
+
return `
|
|
14
|
+
<template>
|
|
15
|
+
${source}
|
|
16
|
+
</template>`;
|
|
17
|
+
};
|
|
18
|
+
exports.default = injectTemplate;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const htmlparser2_1 = require("htmlparser2");
|
|
4
|
+
const parse = (sourceCode) => new Promise((resolve, reject) => {
|
|
5
|
+
const handler = new htmlparser2_1.DomHandler((err, dom) => {
|
|
6
|
+
if (err) {
|
|
7
|
+
reject(err);
|
|
8
|
+
}
|
|
9
|
+
resolve(dom);
|
|
10
|
+
});
|
|
11
|
+
const parser = new htmlparser2_1.Parser(handler, {
|
|
12
|
+
xmlMode: false,
|
|
13
|
+
lowerCaseAttributeNames: false,
|
|
14
|
+
lowerCaseTags: false,
|
|
15
|
+
recognizeSelfClosing: true,
|
|
16
|
+
decodeEntities: false,
|
|
17
|
+
});
|
|
18
|
+
parser.write(sourceCode);
|
|
19
|
+
parser.end();
|
|
20
|
+
});
|
|
21
|
+
exports.default = parse;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const attributeTransformer: (node: any, filePath: string, importBy: string) => void;
|
|
2
|
+
declare const templateTransformer: (context: any, ast: any, filePath: string, importMap: {
|
|
3
|
+
[key: string]: string[];
|
|
4
|
+
} | undefined, includeMap: {
|
|
5
|
+
[key: string]: string[];
|
|
6
|
+
} | undefined, componentIndex: number | null, importBy: string, sjsScopeNames: string[]) => Promise<any>;
|
|
7
|
+
export default templateTransformer;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.attributeTransformer = void 0;
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const xhs_mp_compiler_utils_1 = require("xhs-mp-compiler-utils");
|
|
18
|
+
const tagTransformMap_1 = __importDefault(require("../../../lib/tagTransformMap"));
|
|
19
|
+
const getPrefixName_1 = __importDefault(require("../../../../utils/getPrefixName"));
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
const handleStyleAttribute_1 = __importDefault(require("./transformerUtils/handleStyleAttribute"));
|
|
22
|
+
const handleClassAttribute_1 = __importDefault(require("./transformerUtils/handleClassAttribute"));
|
|
23
|
+
const handleCatchAttribute_1 = __importDefault(require("./transformerUtils/handleCatchAttribute"));
|
|
24
|
+
const handleMLAttribute_1 = __importDefault(require("./transformerUtils/handleMLAttribute"));
|
|
25
|
+
const handleLoopAttribute_1 = __importDefault(require("./transformerUtils/handleLoopAttribute"));
|
|
26
|
+
const handleImportTag_1 = __importDefault(require("./transformerUtils/handleImportTag"));
|
|
27
|
+
const handleBindAttribute_1 = __importDefault(require("./transformerUtils/handleBindAttribute"));
|
|
28
|
+
const handleIncludeTag_1 = __importDefault(require("./transformerUtils/handleIncludeTag"));
|
|
29
|
+
const handleDataAttribute_1 = __importDefault(require("./transformerUtils/handleDataAttribute"));
|
|
30
|
+
const handleModelAttribute_1 = __importDefault(require("./transformerUtils/handleModelAttribute"));
|
|
31
|
+
const handleOtherAttribute_1 = __importDefault(require("./transformerUtils/handleOtherAttribute"));
|
|
32
|
+
const handleSlotAttribute_1 = __importDefault(require("./transformerUtils/handleSlotAttribute"));
|
|
33
|
+
const handleHiddenAttribute_1 = __importDefault(require("./transformerUtils/handleHiddenAttribute"));
|
|
34
|
+
const handleSpaceAttribute_1 = __importDefault(require("./transformerUtils/handleSpaceAttribute"));
|
|
35
|
+
const handleBlockTag_1 = __importDefault(require("./transformerUtils/handleBlockTag"));
|
|
36
|
+
const utils_2 = require("./transformerUtils/utils");
|
|
37
|
+
const SjsModule_1 = __importDefault(require("../../../../globalData/SjsModule"));
|
|
38
|
+
const common_1 = require("../../../../utils/common");
|
|
39
|
+
const attributeTransformer = (node, filePath, importBy) => {
|
|
40
|
+
// **:for 场景下多个 attr 存在联动关系,因此单独处理
|
|
41
|
+
const attrKeys = Object.keys(node.attribs || {});
|
|
42
|
+
if (attrKeys.join().includes(`${(0, getPrefixName_1.default)()}:for`)) {
|
|
43
|
+
(0, handleLoopAttribute_1.default)(node);
|
|
44
|
+
}
|
|
45
|
+
if (attrKeys.includes('slot')) {
|
|
46
|
+
(0, handleSlotAttribute_1.default)(node);
|
|
47
|
+
}
|
|
48
|
+
const reg = new RegExp(`^${(0, getPrefixName_1.default)()}:`);
|
|
49
|
+
Object.keys(node.attribs || {}).forEach(attribute => {
|
|
50
|
+
const value = node.attribs[attribute];
|
|
51
|
+
if (node.name === 'XhsVueTemplate' && attribute === 'data') {
|
|
52
|
+
node.attribs[':data'] = (0, utils_2.injectContext2Exp)(value, node, 6);
|
|
53
|
+
delete node.attribs.data;
|
|
54
|
+
}
|
|
55
|
+
else if (attribute === 'class' ||
|
|
56
|
+
attribute === 'hover-class' ||
|
|
57
|
+
attribute === 'placeholder-class') {
|
|
58
|
+
(0, handleClassAttribute_1.default)(attribute, value, node);
|
|
59
|
+
}
|
|
60
|
+
else if (attribute === 'style') {
|
|
61
|
+
(0, handleStyleAttribute_1.default)(value, node);
|
|
62
|
+
}
|
|
63
|
+
else if (attribute.match(/^capture-bind/) || attribute.match(/^bind/)) {
|
|
64
|
+
(0, handleBindAttribute_1.default)(value, attribute, node, filePath, importBy);
|
|
65
|
+
}
|
|
66
|
+
else if (attribute.match(/^catch/)) {
|
|
67
|
+
(0, handleCatchAttribute_1.default)(value, attribute, node, filePath, importBy);
|
|
68
|
+
}
|
|
69
|
+
else if (attribute.match(reg)) {
|
|
70
|
+
(0, handleMLAttribute_1.default)(value, attribute, node);
|
|
71
|
+
}
|
|
72
|
+
else if (attribute === 'space') {
|
|
73
|
+
(0, handleSpaceAttribute_1.default)(value, node);
|
|
74
|
+
}
|
|
75
|
+
else if (attribute === 'mfConfig') {
|
|
76
|
+
delete node.attribs[attribute];
|
|
77
|
+
}
|
|
78
|
+
else if (attribute.match(/^data-/)) {
|
|
79
|
+
(0, handleDataAttribute_1.default)(value, attribute, node);
|
|
80
|
+
}
|
|
81
|
+
else if (attribute === 'hidden') {
|
|
82
|
+
(0, handleHiddenAttribute_1.default)(value, attribute, node);
|
|
83
|
+
}
|
|
84
|
+
else if (attribute.match(/^model:/)) {
|
|
85
|
+
(0, handleModelAttribute_1.default)(value, attribute, node);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
(0, handleOtherAttribute_1.default)(value, attribute, node);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
exports.attributeTransformer = attributeTransformer;
|
|
93
|
+
const templateTransformer = (context_1, ast_1, filePath_1, ...args_1) => __awaiter(void 0, [context_1, ast_1, filePath_1, ...args_1], void 0, function* (context, ast, filePath, importMap = {}, includeMap = {}, componentIndex, importBy, sjsScopeNames) {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
for (const node of ast) {
|
|
96
|
+
if (node.children) {
|
|
97
|
+
node.children = (0, utils_1.sortNodes)(node.children);
|
|
98
|
+
}
|
|
99
|
+
if (node.type === 'tag') {
|
|
100
|
+
// 未来可以考虑放在 vue-laoder plugin 中处理
|
|
101
|
+
if (['wxs', 'sjs'].includes(node.name)) {
|
|
102
|
+
SjsModule_1.default.add(filePath, node.attribs.module, node.attribs.src || node.attribs.from);
|
|
103
|
+
const sjsPath = (0, common_1.unixResolve)(path_1.default.dirname(filePath), node.attribs.src || node.attribs.from);
|
|
104
|
+
context.addDependency(sjsPath);
|
|
105
|
+
SjsModule_1.default.addPath(sjsPath);
|
|
106
|
+
sjsScopeNames.push(node.attribs.module);
|
|
107
|
+
node.type = 'text';
|
|
108
|
+
node.data = '';
|
|
109
|
+
node.children = [];
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (node.name === 'import') {
|
|
113
|
+
(0, utils_1.notifyImport)('import');
|
|
114
|
+
yield (0, handleImportTag_1.default)(node, filePath, importMap);
|
|
115
|
+
}
|
|
116
|
+
if (node.name === 'include') {
|
|
117
|
+
(0, utils_1.notifyImport)('include');
|
|
118
|
+
yield (0, handleIncludeTag_1.default)(node, filePath, includeMap);
|
|
119
|
+
}
|
|
120
|
+
if (node.name === 'template' && (node.attribs.name || node.attribs.is)) {
|
|
121
|
+
(0, utils_1.notifyImport)('template');
|
|
122
|
+
node.name = 'XhsVueTemplate';
|
|
123
|
+
const filePathVar = (0, utils_1.formatPathToVar)(filePath);
|
|
124
|
+
if (node.attribs.name) {
|
|
125
|
+
if (node.attribs[`${(0, getPrefixName_1.default)()}:if`]) {
|
|
126
|
+
node.type = 'text';
|
|
127
|
+
node.children = '';
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
// importBy => 1234
|
|
131
|
+
node.attribs[':xhsTplDefineScope'] = importBy
|
|
132
|
+
? `['${importBy}', '${filePathVar}']`
|
|
133
|
+
: `['${filePathVar}']`;
|
|
134
|
+
node.attribs['#default'] = 'data';
|
|
135
|
+
(0, utils_2.addContextToNode)({
|
|
136
|
+
nodes: node,
|
|
137
|
+
underTemplate: true,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (node.attribs.is) {
|
|
141
|
+
// filePathVar => hash 1234
|
|
142
|
+
const templateDataString = (_a = node.attribs) === null || _a === void 0 ? void 0 : _a.data;
|
|
143
|
+
if (templateDataString && typeof templateDataString === 'string') {
|
|
144
|
+
let index = sjsScopeNames.length;
|
|
145
|
+
while (index--) {
|
|
146
|
+
/**
|
|
147
|
+
* - {{ name: 'data' }} => ['name’, 'data']
|
|
148
|
+
*/
|
|
149
|
+
const reg = new RegExp(`(\\w+)(?:\\s+)?\\:(?:\\s+)?(${sjsScopeNames[index]})`);
|
|
150
|
+
const match = templateDataString.match(reg);
|
|
151
|
+
// 匹配出 template data 上的 sjs 变量别名加入 scopes 数组
|
|
152
|
+
if (match === null || match === void 0 ? void 0 : match[1]) {
|
|
153
|
+
sjsScopeNames.push(match[1]);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
SjsModule_1.default.addTemplateHash(filePathVar, sjsScopeNames);
|
|
158
|
+
node.attribs.xhsTplConsumeScope = filePathVar;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (node.name === 'block') {
|
|
162
|
+
(0, handleBlockTag_1.default)(node);
|
|
163
|
+
}
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
node.name = tagTransformMap_1.default[node.name] || node.name;
|
|
166
|
+
(0, exports.attributeTransformer)(node, filePath, importBy);
|
|
167
|
+
// 暂时忽略 自定义元素,挂载后对运行时无影响
|
|
168
|
+
if ((0, utils_1.isCustomComponent)(node.name)) {
|
|
169
|
+
const { OwnerId, ComponentIndex } = xhs_mp_compiler_utils_1.CompileAddedAttrs;
|
|
170
|
+
node.attribs[`:${OwnerId}`] = `${OwnerId}`;
|
|
171
|
+
componentIndex !== null && (node.attribs[`:${ComponentIndex}`] = componentIndex);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (node.type === 'text' && ((_b = (0, utils_2.matchMustache)(node.data)) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
175
|
+
if (!node.data.includes(`${xhs_mp_compiler_utils_1.COMPILE_CALL_RUNTIME}(`)) {
|
|
176
|
+
node.data = (0, utils_2.injectContext2Exp)(node.data, node, 4);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (node.children) {
|
|
180
|
+
yield templateTransformer(context, node.children, filePath, importMap, includeMap, componentIndex, importBy, sjsScopeNames);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return ast;
|
|
184
|
+
});
|
|
185
|
+
exports.default = templateTransformer;
|