@hap-toolkit/compiler
Advanced tools
Comparing version 0.7.7-beta.1 to 0.7.7-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 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(":"),i=e.key.match(/(:[A-Za-z]+)+/g);if(i&&i.length){const r=i.filter(e=>!(0,_validator.validatePseudoClass)(e));if(r.length)return s.push({line:t.position.start.line,column:t.position.start.column,reason:"ERROR: 不支持伪类选择器`"+r.toString()+"`"}),!1;if(1===i.length&&(0,_validator.validatePseudoClass)(i[0])){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": "0.7.7-beta.1", | ||
"version": "0.7.7-beta.2", | ||
"description": "compiler of hap-toolkit", | ||
@@ -21,3 +21,3 @@ "engines": { | ||
"dependencies": { | ||
"@hap-toolkit/shared-utils": "0.7.7-beta.1", | ||
"@hap-toolkit/shared-utils": "0.7.7-beta.2", | ||
"css": "^2.2.4", | ||
@@ -27,3 +27,3 @@ "css-what": "^2.1.3", | ||
}, | ||
"gitHead": "87453ffdc690c7cc7bb5777c347df83e9c0386c7" | ||
"gitHead": "69f3c032f1b791ce317113754045924e342f704f" | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
87039
352
4
+ Added@hap-toolkit/shared-utils@0.7.7-beta.2(transitive)
- Removed@hap-toolkit/shared-utils@0.7.7-beta.1(transitive)