@hap-toolkit/compiler
Advanced tools
Comparing version 1.8.1-beta.1 to 1.8.1-beta.2
@@ -1,2 +0,2 @@ | ||
"use strict";var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_css=_interopRequireDefault(require("css")),_cssWhat=_interopRequireDefault(require("css-what")),_compilationConfig=require("@hap-toolkit/shared-utils/compilation-config"),_validator=require("./validator"),_compress=require("./compress"),_mediaquery=require("./mediaquery"),_utils=require("../utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const VALID_IMPORT_FLAG="__VALID_IMPORT__",IMPORT_REG=new RegExp("@import\\s+__VALID_IMPORT__((?:['\"]([^()]+?)['\"])|(?:(?:url\\(([^()]+?)\\))))((?:\\s*)|(?:\\s+[^;]+))__VALID_IMPORT__;","g"),IMPORT_URL_REG=new RegExp("__VALID_IMPORT__(?:(?:['\"]([^()]+?)['\"])|(?:(?:url\\(([^()]+?)\\))))(\\s+[^;]+)?__VALID_IMPORT__;");function shouldAddToDependency(e,s){return(0,_validator.mightReferlocalResource)(e)&&!/^(data:|http)/.test(s)&&"string"==typeof s}function signValidCssImport(e){let s=!0;const t=_css.default.parse(e);if(t&&"stylesheet"===t.type&&t.stylesheet&&t.stylesheet.rules&&t.stylesheet.rules.length){t.stylesheet.rules.forEach(e=>{const t=e.type;"import"!==t&&"comment"!==t&&(s=!1),"import"===t&&s&&(e.import=VALID_IMPORT_FLAG+e.import+VALID_IMPORT_FLAG)}),e=_css.default.stringify(t)}return e}function processImport(e,s,t,o){let i=signValidCssImport(e);const n=i.match(IMPORT_REG);return n&&n.length>0&&(s?n.forEach(e=>{const n=e.match(IMPORT_URL_REG);if(n.length>1){const r=n[3],a=_path.default.resolve(s,n[1]||n[2]),l=_fs.default.readFileSync(a);if(l){const s=_path.default.dirname(a);let n=processImport(l.toString(),s,t,o);r&&(n=(0,_mediaquery.wrapMediaCode)(n,r)),i=i.replace(e,"\n"+n+"\n"),o.push(a)}else t.push({line:1,column:1,reason:"ERROR: 找不到文件 `"+e+"` , 导入失败"})}}):t.push({line:1,column:1,reason:"ERROR: 找不到资源路径, 无法处理@import"})),i}function processSingleClass(e,s,t,o,i,n){e.declarations.forEach((function(e){if("declaration"!==e.type)return;const s=e.property,r=e.value,a=(0,_utils.hyphenedToCamelCase)(s),l=(0,_validator.validate)(a,r,{filePath:i});l.value.forEach(e=>{(0,_utils.isValidValue)(e.v)&&(t[e.n]=e.v,shouldAddToDependency(e.n,e.v)&&n.push(e.v))}),l.log&&o.push({line:e.position.start.line,column:e.position.start.column,reason:l.log.reason})}));const r=/^[.#]?[A-Za-z0-9_\-:]+$/,a=/^([.#]?[A-Za-z0-9_\-:]+(\s+|\s*>\s*))+([.#]?[A-Za-z0-9_\-:]+)+$/;e.selectors.forEach((function(i){const n={key:i,val:t};if(i.match(r)||i.match(a)){if(!processPseudoClass(n,o,e))return;if(!_compilationConfig.compileOptionsObject.optimizeDescMeta&&i.match(a))try{n.val=Object.assign({},n.val),n.val._meta={},n.val._meta.ruleDef=(0,_compress.compressDescSelector)((0,_cssWhat.default)(n.key))}catch(s){return void o.push({line:e.position.start.line,column:e.position.start.column,reason:"ERROR: 选择器 `"+n.key+"` 不支持"})}s[n.key]=(0,_utils.extend)({},s[n.key]||{},n.val)}else o.push({line:e.position.start.line,column:e.position.start.column,reason:"ERROR: 选择器 `"+i+"` 非法"})}))}function processMediaQueryCss(e,s,t,o,i,n){const r=(0,_mediaquery.validateMediaCondition)(e.media),a=r.value,l=r.reason;if(l&&l.length>0&&r.reason.forEach(s=>{t.push({line:e.position.start.line,column:e.position.start.column,reason:s})}),!a)return;const c=i?`${i} and ${a}`:a;e.rules.forEach(e=>{if("rule"===e.type){if(e.declarations&&e.declarations.length){let i=(0,_mediaquery.findMediaClassByCondition)(s,c);const r=!i;r&&(i={condition:c}),processSingleClass(e,i,{},t,o,n),r&&s.push(i)}}else"media"===e.type&&processMediaQueryCss(e,s,t,o,c,n)})}function processPseudoClass(e,s,t){const o=e.key.indexOf(":"),i=e.key.match(/(:[A-Za-z]+)+/g);if(i&&i.length){const n=i.filter(e=>!(0,_validator.validatePseudoClass)(e));if(n.length)return s.push({line:t.position.start.line,column:t.position.start.column,reason:"ERROR: 不支持伪类选择器`"+n.toString()+"`"}),!1;if(1===i.length&&o+i[0].length===e.key.length){e.key=e.key.slice(0,o);const s={};Object.keys(e.val).forEach((function(t){s[t+i[0]]=e.val[t]})),e.val=s}}return!0}module.exports={processImport:processImport,processSingleClass:processSingleClass,processMediaQueryCss:processMediaQueryCss,shouldAddToDependency:shouldAddToDependency}; | ||
"use strict";var _fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_css=_interopRequireDefault(require("css")),_cssWhat=_interopRequireDefault(require("css-what")),_compilationConfig=require("@hap-toolkit/shared-utils/compilation-config"),_validator=require("./validator"),_compress=require("./compress"),_mediaquery=require("./mediaquery"),_utils=require("../utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const VALID_IMPORT_FLAG="__VALID_IMPORT__",IMPORT_REG=new RegExp("@import\\s+__VALID_IMPORT__((?:['\"]([^()]+?)['\"])|(?:(?:url\\(([^()]+?)\\))))((?:\\s*)|(?:\\s+[^;]+))__VALID_IMPORT__;","g"),IMPORT_URL_REG=new RegExp("__VALID_IMPORT__(?:(?:['\"]([^()]+?)['\"])|(?:(?:url\\(([^()]+?)\\))))(\\s+[^;]+)?__VALID_IMPORT__;");function shouldAddToDependency(e,s){return(0,_validator.mightReferlocalResource)(e)&&!/^(data:|http)/.test(s)&&"string"==typeof s}function signValidCssImport(e){let s=!0;const t=_css.default.parse(e);if(t&&"stylesheet"===t.type&&t.stylesheet&&t.stylesheet.rules&&t.stylesheet.rules.length){t.stylesheet.rules.forEach(e=>{const t=e.type;"import"!==t&&"comment"!==t&&(s=!1),"import"===t&&s&&(e.import=VALID_IMPORT_FLAG+e.import+VALID_IMPORT_FLAG)}),e=_css.default.stringify(t)}return e}function processImport(e,s,t,o){let i=signValidCssImport(e);const r=i.match(IMPORT_REG);return r&&r.length>0&&(s?r.forEach(e=>{const r=e.match(IMPORT_URL_REG);if(r.length>1){const n=r[3],a=_path.default.resolve(s,r[1]||r[2]),l=_fs.default.readFileSync(a);if(l){const s=_path.default.dirname(a);let r=processImport(l.toString(),s,t,o);n&&(r=(0,_mediaquery.wrapMediaCode)(r,n)),i=i.replace(e,"\n"+r+"\n"),o.push(a)}else t.push({line:1,column:1,reason:"ERROR: 找不到文件 `"+e+"` , 导入失败"})}}):t.push({line:1,column:1,reason:"ERROR: 找不到资源路径, 无法处理@import"})),i}function processSingleClass(e,s,t,o,i,r){e.declarations.forEach((function(e){if("declaration"!==e.type)return;const s=e.property,n=e.value,a=(0,_utils.hyphenedToCamelCase)(s),l=(0,_validator.validate)(a,n,{filePath:i});l.value.forEach(e=>{(0,_utils.isValidValue)(e.v)&&(t[e.n]=e.v,shouldAddToDependency(e.n,e.v)&&r.push(e.v))}),l.log&&o.push({line:e.position.start.line,column:e.position.start.column,reason:l.log.reason})}));const n=/^[.#]?[A-Za-z0-9_\-:]+$/,a=/^([.#]?[A-Za-z0-9_-]+(\s+|\s*>\s*))+([.#]?[A-Za-z0-9_\-:]+)$/;e.selectors.forEach((function(i){const r={key:i,val:t};if(i.match(n)||i.match(a)){if(!processPseudoClass(r,o,e))return;if(!_compilationConfig.compileOptionsObject.optimizeDescMeta&&i.match(a))try{r.val=Object.assign({},r.val),r.val._meta={},r.val._meta.ruleDef=(0,_compress.compressDescSelector)((0,_cssWhat.default)(r.key))}catch(s){return void o.push({line:e.position.start.line,column:e.position.start.column,reason:"ERROR: 选择器 `"+r.key+"` 不支持"})}s[r.key]=(0,_utils.extend)({},s[r.key]||{},r.val)}else o.push({line:e.position.start.line,column:e.position.start.column,reason:"ERROR: 选择器 `"+i+"` 非法"})}))}function processMediaQueryCss(e,s,t,o,i,r){const n=(0,_mediaquery.validateMediaCondition)(e.media),a=n.value,l=n.reason;if(l&&l.length>0&&n.reason.forEach(s=>{t.push({line:e.position.start.line,column:e.position.start.column,reason:s})}),!a)return;const c=i?`${i} and ${a}`:a;e.rules.forEach(e=>{if("rule"===e.type){if(e.declarations&&e.declarations.length){let i=(0,_mediaquery.findMediaClassByCondition)(s,c);const n=!i;n&&(i={condition:c}),processSingleClass(e,i,{},t,o,r),n&&s.push(i)}}else"media"===e.type&&processMediaQueryCss(e,s,t,o,c,r)})}function processPseudoClass(e,s,t){const o=e.key.indexOf(":");if(o>-1){const i=e.key.slice(o);if(!(0,_validator.validatePseudoClass)(i))return s.push({line:t.position.start.line,column:t.position.start.column,reason:"ERROR: 不支持伪类选择器`"+i+"`"}),!1;e.key=e.key.slice(0,o);const r={};Object.keys(e.val).forEach((function(s){r[s+i]=e.val[s]})),e.val=r}return!0}module.exports={processImport:processImport,processSingleClass:processSingleClass,processMediaQueryCss:processMediaQueryCss,shouldAddToDependency:shouldAddToDependency}; | ||
//# sourceMappingURL=process.js.map |
{ | ||
"name": "@hap-toolkit/compiler", | ||
"version": "1.8.1-beta.1", | ||
"version": "1.8.1-beta.2", | ||
"description": "compiler of hap-toolkit", | ||
@@ -21,3 +21,3 @@ "engines": { | ||
"dependencies": { | ||
"@hap-toolkit/shared-utils": "1.8.1-beta.1", | ||
"@hap-toolkit/shared-utils": "1.8.1-beta.2", | ||
"css": "^2.2.4", | ||
@@ -27,3 +27,3 @@ "css-what": "^2.1.3", | ||
}, | ||
"gitHead": "4e9caed276240ec8d262706ed22b495c6f3eda8d" | ||
"gitHead": "21b891dd6a075897c6a8ea2de0d9d1746d9e4701" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3
87467
354
+ Added@hap-toolkit/shared-utils@1.8.1-beta.2(transitive)
- Removed@hap-toolkit/shared-utils@1.8.1-beta.1(transitive)