Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-html

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-html - npm Package Compare versions

Comparing version 0.18.0 to 0.19.0

17

lib/html-parser.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc