UNPKG

@areslabs/alita-core

Version:

alita-core

61 lines (47 loc) 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var path = _interopRequireWildcard(require("path")); var _uast = require("../util/uast"); var _index = _interopRequireDefault(require("../tran/index")); var _util = require("../util/util"); var _configure = _interopRequireDefault(require("../configure")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /** * Copyright (c) Areslabs. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ function _default({ ast, isEntry, isRF, isFuncComp }) { const filepath = this.resourcePath; const { entryFullpath, allCompSet } = _configure.default; let finalCode = null; if (filepath === entryFullpath) { // nothing finalCode = (0, _uast.geneReactCode)(ast); } else if (isRF) { finalCode = (0, _index.default)(ast, filepath, isFuncComp, isPageComp(filepath, allCompSet), this); } else { finalCode = (0, _uast.geneReactCode)(ast); } console.log(`处理完成:${filepath.replace(_configure.default.inputFullpath, '')}`.info); return finalCode; } function isPageComp(filepath, allCompSet) { const originPath = (0, _util.miscNameToJSName)(filepath).replace(_configure.default.inputFullpath + path.sep, '').replace('.js', '').replace(/\\/g, '/'); // 考虑win平台 return allCompSet.has(originPath); }