🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

postcss-values-parser

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-values-parser - npm Package Compare versions

Comparing version

to
3.0.2

lib/nodes/Container.js

18

lib/index.js

@@ -14,6 +14,4 @@ /*

const Parser = require('./ValuesParser');
const Stringifier = require('./ValuesStringifier');
const { stringify } = require('./ValuesStringifier');
// TODO: walk methods for custom nodes
module.exports = {

@@ -26,9 +24,15 @@ parse(css, options) {

const { root } = parser;
const ogToString = root.toString;
function toString(stringifier) {
return ogToString.bind(root)(stringifier || module.exports.stringify);
}
root.toString = toString.bind(root);
return parser.root;
},
stringify(node, builder) {
const stringifier = new Stringifier(builder);
stringifier.stringify(node);
},
stringify,

@@ -35,0 +39,0 @@ nodeToString(node) {

@@ -15,6 +15,7 @@ /*

const { stringify } = require('../ValuesStringifier');
class AtWord extends AtRule {
constructor(options) {
super(options);
this.type = 'atword';
toString(stringifier = stringify) {
return super.toString(stringifier);
}

@@ -21,0 +22,0 @@ }

@@ -11,59 +11,69 @@ /*

*/
const Comment = require('postcss/lib/comment');
const PostCssComment = require('postcss/lib/comment');
const { stringify } = require('../ValuesStringifier');
const inlineRegex = /(\/\/)/;
Comment.testInline = (token) => inlineRegex.test(token[1]);
class Comment extends PostCssComment {
static testInline(token) {
return inlineRegex.test(token[1]);
}
Comment.tokenizeNext = (tokens, parser) => {
const [first] = tokens;
const newlineIndex = tokens.findIndex((t) => /\n/.test(t[1]));
let bits = tokens;
let rest = [];
static tokenizeNext(tokens, parser) {
const [first] = tokens;
const newlineIndex = tokens.findIndex((t) => /\n/.test(t[1]));
let bits = tokens;
let rest = [];
if (newlineIndex >= 0) {
bits = tokens.slice(0, newlineIndex);
rest = tokens.slice(newlineIndex);
if (newlineIndex >= 0) {
bits = tokens.slice(0, newlineIndex);
rest = tokens.slice(newlineIndex);
}
bits = bits.map((t) => t[1]);
// see tilde comment in tokenizeInline
const text = bits.concat('~~').join('');
const last = bits[bits.length - 1];
const newToken = ['comment', text, first[2], first[3], last[2], last[3]];
parser.back([newToken, ...rest]);
}
bits = bits.map((t) => t[1]);
static tokenizeInline(tokens, parser) {
const [first, ...rest] = tokens;
const bits = first[1].split(/(\/\/.+)/).filter((t) => !!t);
const newTokens = [];
const [, , startLine, , endLine] = first;
let [, , , startChar, , endChar] = first;
// see tilde comment in tokenizeInline
const text = bits.concat('~~').join('');
const last = bits[bits.length - 1];
const newToken = ['comment', text, first[2], first[3], last[2], last[3]];
for (let bit of bits) {
const comment = bit.slice(0, 2) === '//';
const type = comment ? 'comment' : 'word';
parser.back([newToken, ...rest]);
};
if (comment) {
// the Parser base comment() method trims the last two characters when creating the node
// these tildes are added to counter that. it's hacky, but it works, and we don't have to
// re-implement the method
bit += '~~';
}
Comment.tokenizeInline = (tokens, parser) => {
const [first, ...rest] = tokens;
const bits = first[1].split(/(\/\/.+)/).filter((t) => !!t);
const newTokens = [];
const [, , startLine, , endLine] = first;
let [, , , startChar, , endChar] = first;
if (bit !== bits[0]) {
startChar = endChar + 1;
}
for (let bit of bits) {
const comment = bit.slice(0, 2) === '//';
const type = comment ? 'comment' : 'word';
endChar = startChar + bit.length - 1;
if (comment) {
// the Parser base comment() method trims the last two characters when creating the node
// these tildes are added to counter that. it's hacky, but it works, and we don't have to
// re-implement the method
bit += '~~';
newTokens.push([type, bit, startLine, startChar, endLine, endChar]);
}
if (bit !== bits[0]) {
startChar = endChar + 1;
}
parser.back(newTokens.concat(rest));
}
endChar = startChar + bit.length - 1;
newTokens.push([type, bit, startLine, startChar, endLine, endChar]);
toString(stringifier = stringify) {
return super.toString(stringifier);
}
}
parser.back(newTokens.concat(rest));
};
module.exports = Comment;

@@ -11,6 +11,6 @@ /*

*/
const Container = require('postcss/lib/container');
const { registerWalker } = require('../walker');
const Container = require('./Container');
const colorFunctions = ['hsl', 'hsla', 'rgb', 'rgba'];

@@ -88,3 +88,4 @@

const { parse } = require('../'); // eslint-disable-line global-require
const { nodes: children } = parse(params, opts);
const root = parse(params, opts);
const { nodes: children } = root;

@@ -95,2 +96,6 @@ // TODO: correct line and character position (should we just pad the input? probably easiest)

}
if (root.raws.after) {
node.last.raws.after = root.raws.after;
}
}

@@ -97,0 +102,0 @@

@@ -11,6 +11,6 @@ /*

*/
const Container = require('postcss/lib/container');
const { registerWalker } = require('../walker');
const Container = require('./Container');
class Interpolation extends Container {

@@ -17,0 +17,0 @@ constructor(options = {}) {

@@ -12,6 +12,7 @@ /*

const isNumber = require('is-number');
const Node = require('postcss/lib/node');
const { registerWalker } = require('../walker');
const Node = require('./Node');
const unitRegex = /%|ch|cm|em|ex|in|mm|pc|pt|px|rem|vh|vmax|vmin|vw$/i;

@@ -18,0 +19,0 @@

@@ -11,6 +11,6 @@ /*

*/
const Node = require('postcss/lib/node');
const { registerWalker } = require('../walker');
const Node = require('./Node');
const operators = ['+', '-', '/', '*', '%'];

@@ -17,0 +17,0 @@ const operRegex = new RegExp(`([/|*}])`);

@@ -11,7 +11,7 @@ /*

*/
const Node = require('postcss/lib/node');
const { getTokens } = require('../tokenize');
const { registerWalker } = require('../walker');
const Node = require('./Node');
/**

@@ -18,0 +18,0 @@ * @desc Punctuation nodes can contain:

@@ -11,6 +11,6 @@ /*

*/
const Node = require('postcss/lib/node');
const { registerWalker } = require('../walker');
const Node = require('./Node');
class Quoted extends Node {

@@ -17,0 +17,0 @@ constructor(options) {

@@ -11,6 +11,6 @@ /*

*/
const Node = require('postcss/lib/node');
const { registerWalker } = require('../walker');
const Node = require('./Node');
class UnicodeRange extends Node {

@@ -17,0 +17,0 @@ constructor(options) {

@@ -13,6 +13,7 @@ /*

const isUrl = require('is-url-superb');
const Node = require('postcss/lib/node');
const { registerWalker } = require('../walker');
const Node = require('./Node');
const escapeRegex = /^\\(.+)/;

@@ -19,0 +20,0 @@ const hexRegex = /^#(.+)/;

@@ -55,2 +55,3 @@ /*

node.inline = inline;
Object.setPrototypeOf(node, Comment.prototype);
}

@@ -57,0 +58,0 @@

const Stringifier = require('postcss/lib/stringifier');
module.exports = class LessStringifier extends Stringifier {
basic(node) {
const after = this.raw(node, 'after');
module.exports = class ValuesStringifier extends Stringifier {
static stringify(node, builder) {
const stringifier = new ValuesStringifier(builder);
stringifier.stringify(node);
}
this.builder(node.value, node, 'start');
this.builder(after || '', node, 'end');
basic(node, value) {
const print = value || node.value;
const after = node.raws.after ? this.raw(node, 'after') || '' : '';
// NOTE: before is handled by postcss in stringifier.body
this.builder(print, node, 'start');
this.builder(after, node, 'end');
}

@@ -26,21 +33,26 @@

func(node) {
const after = this.raw(node, 'after');
const after = this.raw(node, 'after') || '';
this.builder(node.name + node.params, node, 'start');
this.builder(after || '', node, 'end');
this.builder(`${node.name}(`, node, 'start');
for (const child of node.nodes) {
// since we're duplicating this.body here, we have to handle `before`
// but we don't want the postcss default \n value, so check it's non-empty first
const before = child.raws.before ? this.raw(child, 'before') : '';
if (before) {
this.builder(before);
}
this.stringify(child);
}
this.builder(`)${after}`, node, 'end');
}
interpolation(node) {
const after = this.raw(node, 'after');
this.builder(node.prefix + node.params, node, 'start');
this.builder(after || '', node, 'end');
this.basic(node, node.prefix + node.params);
}
numeric(node) {
const start = node.value + node.unit;
const after = this.raw(node, 'after');
this.builder(start, node, 'start');
this.builder(after || '', node, 'end');
const print = node.value + node.unit;
this.basic(node, print);
}

@@ -47,0 +59,0 @@

{
"name": "postcss-values-parser",
"version": "3.0.1",
"version": "3.0.2",
"description": "A CSS property value parser for use with PostCSS",

@@ -5,0 +5,0 @@ "license": "MPL-2.0",