Socket
Socket
Sign inDemoInstall

postcss-html

Package Overview
Dependencies
Maintainers
4
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 1.0.2 to 1.1.0

14

lib/html/extract-styles.js

@@ -9,6 +9,7 @@ "use strict";

const openTag = {};
let disable, style;
let disable, ignore, style;
const parser = new htmlparser.Parser({
oncomment: (data) => {
ignore = false;
const match = /(?:^|\s+)postcss-(\w+)(?:\s+|$)/i.exec(data);

@@ -23,2 +24,4 @@ if (!match) {

disable = true;
} else if (directive === "ignore") {
ignore = true;
}

@@ -29,2 +32,8 @@ },

const currIgnore = ignore;
ignore = false;
if (currIgnore) {
// ignore
return;
}
// Test if current tag is a valid <style> tag.

@@ -47,2 +56,3 @@ if (!/^style$/i.test(name)) {

openTag[name] = false;
ignore = false;
if (disable || !style || name !== style.tagName) {

@@ -67,3 +77,3 @@ return;

onattribute(name, content) {
if (disable || name !== "style") {
if (disable || ignore || name !== "style") {
return;

@@ -70,0 +80,0 @@ }

115

lib/html/parse-styles.js

@@ -8,23 +8,50 @@ "use strict";

class LocalFixer {
constructor(lines, style) {
let line = 0;
let column = style.startIndex;
lines.some((lineEndIndex, lineNumber) => {
if (lineEndIndex >= style.startIndex) {
line = lineNumber;
if (lines[line - 1] != null) {
column = style.startIndex - lines[line - 1] - 1;
}
return true;
class Locations {
constructor(source) {
let match;
const lines = [];
reNewLine.lastIndex = 0;
while ((match = reNewLine.exec(source))) {
lines.push(match.index);
}
lines.push(source.length);
this.lines = lines;
this.source = source;
}
getOffsetFromLoc(loc) {
const lineIndex = loc.line - 2;
return (lineIndex >= 0 ? this.lines[lineIndex] : -1) + loc.column;
}
getLocFromOffset(offset) {
const lines = this.lines;
for (let index = 0; index < lines.length; index++) {
const lineEndIndex = lines[index];
if (lineEndIndex >= offset) {
const before = this.lines[index - 1];
return {
line: index + 1,
column: offset - (before != null ? before : -1),
};
}
return false;
});
}
const before = this.lines[this.lines.length - 2];
return {
line: lines.length,
column: offset - (before != null ? before : -1),
};
}
}
this.line = line;
this.column = column;
class LocalFixer {
constructor(locations, style) {
const { line, column } = locations.getLocFromOffset(style.startIndex);
this.line = line - 1;
this.column = column - 1;
this.style = style;
}
object(object) {
fixLocation(object) {
if (object) {

@@ -42,4 +69,4 @@ if (object.line === 1) {

node(node) {
this.object(node.source.start);
this.object(node.source.end);
this.fixLocation(node.source.start);
this.fixLocation(node.source.end);
}

@@ -56,4 +83,4 @@

if (error && error.name === "CssSyntaxError") {
this.object(error);
this.object(error.input);
this.fixLocation(error);
this.fixLocation(error.input);
error.message = error.message.replace(

@@ -99,11 +126,5 @@ /:\d+:\d+:/,

function docFixer(source, opts) {
let match;
const lines = [];
reNewLine.lastIndex = 0;
while ((match = reNewLine.exec(source))) {
lines.push(match.index);
}
lines.push(source.length);
const locations = new Locations(source);
return function parseStyle(style) {
return new LocalFixer(lines, style).parse(opts);
return new LocalFixer(locations, style).parse(opts);
};

@@ -126,10 +147,15 @@ }

// Note: Stylelint is still using this property.
Object.defineProperty(root.raws, "beforeStart", {
get() {
return root.raws.codeBefore;
},
set(value) {
root.raws.codeBefore = value;
},
});
try {
Object.defineProperty(root.raws, "beforeStart", {
configurable: true,
get() {
return root.raws.codeBefore;
},
set(value) {
root.raws.codeBefore = value;
},
});
} catch {
// ignore
}

@@ -164,8 +190,13 @@ index =

const originalToString = root.toString;
Object.defineProperty(root, "toString", {
enumerable: false,
value(stringifier) {
return originalToString.call(this, stringifier || syntax);
},
});
try {
Object.defineProperty(root, "toString", {
configurable: true,
enumerable: false,
value(stringifier) {
return originalToString.call(this, stringifier || syntax);
},
});
} catch {
// ignore
}
}
{
"name": "postcss-html",
"version": "1.0.2",
"version": "1.1.0",
"publishConfig": {

@@ -55,3 +55,4 @@ "access": "public"

"eslint-fix": "eslint . --fix",
"preversion": "npm run test"
"preversion": "npm run test",
"update-snap": "mocha \"test/**/*.js\" --no-timeouts --update"
},

@@ -58,0 +59,0 @@ "dependencies": {

@@ -105,5 +105,17 @@ # PostCSS HTML Syntax

<body>
<!-- postcss-ignore -->
<a style="color: red;" description="style is not parsed."></a>
<a style="color: red;" description="style is parsed."></a>
```
```html
<html>
<body>
<!-- postcss-disable -->
<a style="color: red;"></a>
<a style="color: red;" description="style is not parsed."></a>
<a style="color: red;" description="style is not parsed."></a>
<!-- postcss-enable -->
<a style="color: red;" description="style is parsed."></a>
```

@@ -110,0 +122,0 @@

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