16a23e08bSopenharmony_ci/* 26a23e08bSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 36a23e08bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 46a23e08bSopenharmony_ci * you may not use this file except in compliance with the License. 56a23e08bSopenharmony_ci * You may obtain a copy of the License at 66a23e08bSopenharmony_ci * 76a23e08bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 86a23e08bSopenharmony_ci * 96a23e08bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 106a23e08bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 116a23e08bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 126a23e08bSopenharmony_ci * See the License for the specific language governing permissions and 136a23e08bSopenharmony_ci * limitations under the License. 146a23e08bSopenharmony_ci */ 156a23e08bSopenharmony_ci 166a23e08bSopenharmony_ciimport loaderUtils from 'loader-utils'; 176a23e08bSopenharmony_ci 186a23e08bSopenharmony_ciconst codegen = require("./codegen/index.js"); 196a23e08bSopenharmony_ci 206a23e08bSopenharmony_cimodule.exports = function (source, map) { 216a23e08bSopenharmony_ci this.cacheable && this.cacheable(); 226a23e08bSopenharmony_ci const callback = this.async(); 236a23e08bSopenharmony_ci 246a23e08bSopenharmony_ci const parsed = codegen.genHmlAndCss(source); 256a23e08bSopenharmony_ci const loaderQuery = loaderUtils.getOptions(this) || {}; 266a23e08bSopenharmony_ci if (parsed.errorType && parsed.errorType !== '') { 276a23e08bSopenharmony_ci callback(parsed.errorType + ' : ' + parsed.errorMessage, ''); 286a23e08bSopenharmony_ci } else { 296a23e08bSopenharmony_ci switch (loaderQuery.type) { 306a23e08bSopenharmony_ci case 'template': 316a23e08bSopenharmony_ci callback(null, parsed.hmlCss.hml, map); 326a23e08bSopenharmony_ci break; 336a23e08bSopenharmony_ci case 'style': 346a23e08bSopenharmony_ci callback(null, parsed.hmlCss.css, map); 356a23e08bSopenharmony_ci break; 366a23e08bSopenharmony_ci case 'json': 376a23e08bSopenharmony_ci callback(null, parsed.hmlCss.json, map); 386a23e08bSopenharmony_ci break; 396a23e08bSopenharmony_ci } 406a23e08bSopenharmony_ci } 416a23e08bSopenharmony_ci}; 42