188c88e8eSopenharmony_ci/* 288c88e8eSopenharmony_ci * Licensed to the Apache Software Foundation (ASF) under one 388c88e8eSopenharmony_ci * or more contributor license agreements. See the NOTICE file 488c88e8eSopenharmony_ci * distributed with this work for additional information 588c88e8eSopenharmony_ci * regarding copyright ownership. The ASF licenses this file 688c88e8eSopenharmony_ci * to you under the Apache License, Version 2.0 (the 788c88e8eSopenharmony_ci * "License"); you may not use this file except in compliance 888c88e8eSopenharmony_ci * with the License. You may obtain a copy of the License at 988c88e8eSopenharmony_ci * 1088c88e8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 1188c88e8eSopenharmony_ci * 1288c88e8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, 1388c88e8eSopenharmony_ci * software distributed under the License is distributed on an 1488c88e8eSopenharmony_ci * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1588c88e8eSopenharmony_ci * KIND, either express or implied. See the License for the 1688c88e8eSopenharmony_ci * specific language governing permissions and limitations 1788c88e8eSopenharmony_ci * under the License. 1888c88e8eSopenharmony_ci */ 1988c88e8eSopenharmony_ci 2088c88e8eSopenharmony_ciimport { 2188c88e8eSopenharmony_ci logWarn 2288c88e8eSopenharmony_ci} from './util' 2388c88e8eSopenharmony_ci 2488c88e8eSopenharmony_ciimport { 2588c88e8eSopenharmony_ci parseStyle 2688c88e8eSopenharmony_ci} from './parser' 2788c88e8eSopenharmony_ciconst compileStyle = require('./lite/lite-transform-style') 2888c88e8eSopenharmony_ciconst { DEVICE_LEVEL } = require('./lite/lite-enum') 2988c88e8eSopenharmony_cimodule.exports = function (source) { 3088c88e8eSopenharmony_ci this.cacheable && this.cacheable() 3188c88e8eSopenharmony_ci 3288c88e8eSopenharmony_ci const callback = this.async() 3388c88e8eSopenharmony_ci 3488c88e8eSopenharmony_ci parseStyle(source, this.resourcePath) 3588c88e8eSopenharmony_ci .then(({ parsed, log }) => { 3688c88e8eSopenharmony_ci if (log && log.length) { 3788c88e8eSopenharmony_ci logWarn(this, log) 3888c88e8eSopenharmony_ci } 3988c88e8eSopenharmony_ci if (process.env.DEVICE_LEVEL === DEVICE_LEVEL.LITE) { 4088c88e8eSopenharmony_ci parsed = compileStyle.transformStyle(parsed) 4188c88e8eSopenharmony_ci } 4288c88e8eSopenharmony_ci callback(null, parsed) 4388c88e8eSopenharmony_ci }).catch(e => { 4488c88e8eSopenharmony_ci logWarn(this, [{ 4588c88e8eSopenharmony_ci reason: 'ERROR: Failed to parse the CSS file. ' + e 4688c88e8eSopenharmony_ci }]) 4788c88e8eSopenharmony_ci callback('') 4888c88e8eSopenharmony_ci }) 4988c88e8eSopenharmony_ci} 50