postcss-html
Advanced tools
Comparing version 0.18.0 to 0.19.0
@@ -58,3 +58,3 @@ "use strict"; | ||
} | ||
onStyleAttribute(value, parser.endIndex); | ||
onStyleAttribute(value, parser._tokenizer._index); | ||
}, | ||
@@ -102,8 +102,11 @@ }); | ||
}; | ||
function onStyleAttribute (content, index) { | ||
styles.push({ | ||
content: content, | ||
startIndex: source.indexOf(content, index), | ||
isHTMLAttribute: true, | ||
}); | ||
function onStyleAttribute (content, endIndex) { | ||
const startIndex = endIndex - content.length; | ||
if (source[startIndex - 1] === source[endIndex] && /\S/.test(source[endIndex])) { | ||
styles.push({ | ||
content: content, | ||
startIndex, | ||
isHTMLAttribute: true, | ||
}); | ||
} | ||
} | ||
@@ -110,0 +113,0 @@ const level = iterateCode(source, tag => onTag[tag.tagName](tag), onStyleAttribute); |
"use strict"; | ||
const parse = require("babylon").parse; | ||
const traverse = require("@babel/traverse").default; | ||
const requireParser = require("./require-parser"); | ||
const htmlParser = requireParser("html"); | ||
function isScriptModule (attribute) { | ||
if (attribute && attribute.type) { | ||
return /^module$/i.test(attribute.type); | ||
} | ||
} | ||
function getSourceType (filename) { | ||
if (filename && /\.m[tj]sx?$/.test(filename)) { | ||
return "module"; | ||
} | ||
try { | ||
return require("@babel/core").loadOptions({ | ||
filename, | ||
}).sourceType; | ||
} catch (ex) { | ||
// | ||
} | ||
} | ||
function getOptions (opts, attribute) { | ||
const filename = opts.from && opts.from.replace(/\?.*$/, ""); | ||
return { | ||
sourceFilename: filename, | ||
sourceType: isScriptModule(attribute) ? "module" : (getSourceType(filename) || "unambiguous"), | ||
plugins: [ | ||
"jsx", | ||
"typescript", | ||
"objectRestSpread", | ||
"decorators", | ||
"classProperties", | ||
"exportExtensions", | ||
"asyncGenerators", | ||
"functionBind", | ||
"functionSent", | ||
"dynamicImport", | ||
"optionalCatchBinding", | ||
], | ||
}; | ||
} | ||
function skip (attribute) { | ||
@@ -64,24 +22,105 @@ if (!attribute) { | ||
} | ||
let ast; | ||
try { | ||
ast = parse(source, getOptions(opts, attribute)); | ||
} catch (ex) { | ||
return styles; | ||
} | ||
traverse(ast, { | ||
noScope: true, | ||
enter (path) { | ||
if (path.node.type === "TemplateElement") { | ||
const styleHtm = htmlParser(path.node.value.raw, opts); | ||
if (styleHtm) { | ||
styleHtm.forEach(style => { | ||
style.startIndex += path.node.start; | ||
styles.push(style); | ||
}); | ||
} | ||
} | ||
}, | ||
literal(source, (startIndex, endIndex, quote) => { | ||
if (quote !== "`") { | ||
return; | ||
} | ||
startIndex += quote.length; | ||
const strSource = source.slice(startIndex, endIndex - quote.length); | ||
if (!strSource.trim()) { | ||
return; | ||
} | ||
const styleHtm = htmlParser(strSource, opts); | ||
if (styleHtm) { | ||
styleHtm.forEach(style => { | ||
style.startIndex += startIndex; | ||
styles.push(style); | ||
}); | ||
} else { | ||
styles.push({ | ||
startIndex: startIndex, | ||
content: strSource, | ||
isStyled: true, | ||
}); | ||
} | ||
}); | ||
return styles; | ||
}; | ||
function literal (source, callback) { | ||
let insideString = false; | ||
let insideComment = false; | ||
let insideSingleLineComment = false; | ||
let strStartIndex; | ||
let openingQuote; | ||
for (let i = 0, l = source.length; i < l; i++) { | ||
const currentChar = source[i]; | ||
// Register the beginning of a comment | ||
if ( | ||
!insideString && !insideComment && | ||
currentChar === "/" && | ||
source[i - 1] !== "\\" // escaping | ||
) { | ||
// standard comments | ||
if (source[i + 1] === "*") { | ||
insideComment = true; | ||
continue; | ||
} | ||
// single-line comments | ||
if (source[i + 1] === "/") { | ||
insideComment = true; | ||
insideSingleLineComment = true; | ||
continue; | ||
} | ||
} | ||
if (insideComment) { | ||
// Register the end of a standard comment | ||
if ( | ||
!insideSingleLineComment && | ||
currentChar === "*" && | ||
source[i - 1] !== "\\" && // escaping | ||
source[i + 1] === "/" && | ||
source[i - 1] !== "/" // don't end if it's /*/ | ||
) { | ||
insideComment = false; | ||
continue; | ||
} | ||
// Register the end of a single-line comment | ||
if ( | ||
insideSingleLineComment && | ||
currentChar === "\n" | ||
) { | ||
insideComment = false; | ||
insideSingleLineComment = false; | ||
continue; | ||
} | ||
} | ||
// Register the beginning of a string | ||
if (!insideComment && !insideString && (currentChar === "\"" || currentChar === "'" || currentChar === "`")) { | ||
if (source[i - 1] === "\\") continue; // escaping | ||
openingQuote = currentChar; | ||
insideString = true; | ||
strStartIndex = i; | ||
continue; | ||
} | ||
if (insideString) { | ||
// Register the end of a string | ||
if (currentChar === openingQuote) { | ||
if (source[i - 1] === "\\") continue; // escaping | ||
insideString = false; | ||
callback(strStartIndex, i, openingQuote); | ||
continue; | ||
} | ||
} | ||
} | ||
} |
@@ -58,2 +58,5 @@ "use strict"; | ||
} catch (error) { | ||
if (style.isStyled) { | ||
return; | ||
} | ||
throw this.error(error); | ||
@@ -66,2 +69,3 @@ } | ||
isHTMLTag: !!style.isHTMLTag, | ||
isStyled: !!style.isStyled, | ||
lang: style.lang || "css", | ||
@@ -68,0 +72,0 @@ syntax, |
@@ -52,2 +52,5 @@ "use strict"; | ||
const root = parseStyle(style); | ||
if (!root) { | ||
return; | ||
} | ||
root.raws.beforeStart = source.slice(index, style.startIndex); | ||
@@ -54,0 +57,0 @@ index = style.startIndex + style.content.length; |
{ | ||
"name": "postcss-html", | ||
"version": "0.18.0", | ||
"version": "0.19.0", | ||
"description": "PostCSS Syntax for parsing HTML / Markdown / Vue Component", | ||
@@ -48,5 +48,2 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@babel/core": "^7.0.0-beta.42", | ||
"@babel/traverse": "^7.0.0-beta.42", | ||
"babylon": "^7.0.0-beta.42", | ||
"htmlparser2": "^3.9.2", | ||
@@ -77,3 +74,3 @@ "remark": "^9.0.0", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-import": "^2.9.0", | ||
"eslint-plugin-import": "^2.10.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
@@ -89,8 +86,6 @@ "eslint-plugin-promise": "^3.7.0", | ||
"postcss-sass": "^0.3.0", | ||
"postcss-scss": "^1.0.4", | ||
"postcss-scss": "^1.0.5", | ||
"strip-bom": "^3.0.0", | ||
"stylefmt": "^6.0.0", | ||
"stylelint": "^9.1.3", | ||
"sugarss": "^1.0.1" | ||
} | ||
} |
@@ -13,3 +13,9 @@ PostCSS HTML Syntax | ||
[PostCSS](https://github.com/postcss/postcss) Syntax for parsing HTML / [Markdown](https://daringfireball.net/projects/markdown/syntax) / [Vue component](https://vue-loader.vuejs.org/) | ||
[PostCSS](https://github.com/postcss/postcss) Syntax for parsing: | ||
- HTML (and HTML-like) | ||
- [PHP](http://php.net) | ||
- [Vue component](https://vue-loader.vuejs.org/) | ||
- [Quick App](https://doc.quickapp.cn/framework/source-file.html) | ||
- [styled components](https://www.styled-components.com) | ||
- [Markdown](https://daringfireball.net/projects/markdown/syntax) | ||
@@ -16,0 +22,0 @@ ## Getting Started |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20348
9
26
578
66
- Removed@babel/core@^7.0.0-beta.42
- Removed@babel/traverse@^7.0.0-beta.42
- Removedbabylon@^7.0.0-beta.42
- Removed@ampproject/remapping@2.3.0(transitive)
- Removed@babel/code-frame@7.26.2(transitive)
- Removed@babel/compat-data@7.26.2(transitive)
- Removed@babel/core@7.26.0(transitive)
- Removed@babel/generator@7.26.2(transitive)
- Removed@babel/helper-compilation-targets@7.25.9(transitive)
- Removed@babel/helper-module-imports@7.25.9(transitive)
- Removed@babel/helper-module-transforms@7.26.0(transitive)
- Removed@babel/helper-string-parser@7.25.9(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removed@babel/helper-validator-option@7.25.9(transitive)
- Removed@babel/helpers@7.26.0(transitive)
- Removed@babel/parser@7.26.2(transitive)
- Removed@babel/template@7.25.9(transitive)
- Removed@babel/traverse@7.25.9(transitive)
- Removed@babel/types@7.26.0(transitive)
- Removed@jridgewell/gen-mapping@0.3.5(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/set-array@1.2.1(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@jridgewell/trace-mapping@0.3.25(transitive)
- Removedbabylon@7.0.0-beta.47(transitive)
- Removedbrowserslist@4.24.2(transitive)
- Removedcaniuse-lite@1.0.30001680(transitive)
- Removedconvert-source-map@2.0.0(transitive)
- Removeddebug@4.3.7(transitive)
- Removedelectron-to-chromium@1.5.57(transitive)
- Removedescalade@3.2.0(transitive)
- Removedgensync@1.0.0-beta.2(transitive)
- Removedglobals@11.12.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjsesc@3.0.2(transitive)
- Removedjson5@2.2.3(transitive)
- Removedlru-cache@5.1.1(transitive)
- Removedms@2.1.3(transitive)
- Removednode-releases@2.0.18(transitive)
- Removedsemver@6.3.1(transitive)
- Removedupdate-browserslist-db@1.1.1(transitive)
- Removedyallist@3.1.1(transitive)