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

postcss-styl

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-styl - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

182

lib/parser/index.js

@@ -7,3 +7,2 @@ "use strict"

const parseAtRuleNameAndCondition = require("./parse-atrule-name-and-condition")
const parseFunction = require("./parse-function")
const parseProp = require("./parse-prop")

@@ -55,7 +54,6 @@ const parseValue = require("./parse-value")

class ProcessInfo {
constructor(nodes, index, parentInfo, parent) {
constructor(nodes, index, parentInfo) {
this._nodes = nodes
this._index = index
this._parent = parentInfo
this._parentNode = parent
}

@@ -67,2 +65,5 @@

/**
* @returns {StylusNode|number} next sibling node or index
*/
get nextSibling() {

@@ -72,2 +73,5 @@ return this._nodes[this._index + 1]

/**
* @returns {StylusNode|number} next node or index
*/
get next() {

@@ -84,6 +88,2 @@ return (

}
get parentNode() {
return this._parentNode
}
}

@@ -300,7 +300,3 @@

node.nodes.forEach((n, i) =>
this.process(
n,
root,
new ProcessInfo(node.nodes, i, undefined, root)
)
this.process(n, root, new ProcessInfo(node.nodes, i))
)

@@ -369,7 +365,3 @@

node.nodes.forEach((n, i) =>
this.process(
n,
parent,
new ProcessInfo(node.nodes, i, info, parent)
)
this.process(n, parent, new ProcessInfo(node.nodes, i, info))
)

@@ -618,3 +610,20 @@ }

this.function(node.val, parent, info)
} else if (valNodeName === "expression" || valNodeName === "null") {
} else if (valNodeName === "null") {
const cursor = this.sourceCode.createTokenCursor(
this.sourceCode.getIndex(node)
)
cursor.next()
const token = cursor.next()
if (token && token.value === ":") {
// empty decl
this.declImpl(node, { propStartNode: node }, parent, info)
} else {
this.atruleImpl(
node,
{ expression: true },
parent,
info
).expression = true
}
} else if (valNodeName === "expression") {
this.declImpl(

@@ -659,3 +668,3 @@ node,

} else {
this.atruleFunctionImpl(
this.atruleImpl(
node,

@@ -665,3 +674,3 @@ { blockNode: node.block },

info
)
).function = true
}

@@ -729,3 +738,20 @@ }

if(node, parent, info) {
const nodes = [node, ...node.elses]
const elses = node.elses.map(el => {
if (el.nodeName === "if") {
const idx = this.sourceCode.getIndex(el)
const cursor = this.sourceCode.createBackwardTokenCursor(idx)
let token = cursor.next()
while (token && token.value !== "else") {
token = cursor.next()
}
return {
index: token.range[0],
block: el.block,
}
}
return {
block: el,
}
})
const nodes = [node, ...elses.map(e => e.index || e.block)]

@@ -736,11 +762,11 @@ this.atruleImpl(

parent,
new ProcessInfo(nodes, 0, info, parent)
new ProcessInfo(nodes, 0, info)
)
node.elses.forEach((el, i) => {
elses.forEach((el, i) => {
this.atruleImpl(
el,
{ blockNode: el },
el.index || el.block,
{ blockNode: el.block },
parent,
new ProcessInfo(nodes, i + 1, info, parent)
new ProcessInfo(nodes, i + 1, info)
)

@@ -808,3 +834,3 @@ })

/**
* @param {StylusNode} node
* @param {StylusNode|number} nodeOrIndex
* @param {*} infomation

@@ -815,3 +841,3 @@ * @param {PostCssNode} parent

atruleImpl(
node,
nodeOrIndex,
{ blockFirstNode, blockNode, postfix, expression },

@@ -822,3 +848,3 @@ parent,

/* eslint-enable complexity */
const startIndex = this.sourceCode.getIndex(node)
const startIndex = this.sourceCode.getIndex(nodeOrIndex)
const parsedNameAndCondition = parseAtRuleNameAndCondition(

@@ -921,3 +947,6 @@ this.sourceCode,

} else if (parent.postfix) {
const blockParent = info.parent.parentNode
let blockParent = parent.parent
while (blockParent.postfix) {
blockParent = blockParent.parent
}
const parentIndex = blockParent.nodes.indexOf(parent)

@@ -982,7 +1011,3 @@ ;({

childNodes.forEach((n, i) =>
this.process(
n,
atRule,
new ProcessInfo(childNodes, i, info, atRule)
)
this.process(n, atRule, new ProcessInfo(childNodes, i, info))
)

@@ -1014,76 +1039,2 @@ this.pushInlineComments(atRule, blockAfterInlineComments)

/**
* @param {StylusNode} node
* @param {*} infomation
* @param {PostCssNode} parent
* @param {ProcessInfo} info
*/
atruleFunctionImpl(node, _opt, parent, info) {
const startIndex = this.sourceCode.getIndex(node)
const endIndex = this.getBlockEndIndex(startIndex, parent, info)
const parsedFunction = parseFunction(
this.sourceCode,
startIndex,
endIndex
)
const atRuleSource = {
start: this.sourceCode.getLoc(startIndex),
input: this.input,
end: this.sourceCode.getLoc(parsedFunction.endIndex),
}
const atRuleRaws = {
before: undefined,
between: parsedFunction.raw.between,
afterName: parsedFunction.raw.afterName,
}
const {
before: rawBefore,
stylusBefore: rawStylusBefore,
} = this.processRawBefore(parent, undefined, parent)
atRuleRaws.before = rawBefore
if (rawBefore !== rawStylusBefore) {
atRuleRaws.stylusBefore = rawStylusBefore
}
if (parsedFunction.raw.between !== parsedFunction.raw.stylusBetween) {
atRuleRaws.stylusBetween = parsedFunction.raw.stylusBetween
}
const rawParams = raw(
parsedFunction.params,
parsedFunction.raw.stylus,
parsedFunction.raw.css
)
if (rawParams.raw) {
atRuleRaws.params = rawParams
}
const rawBody = raw(
parsedFunction.body,
parsedFunction.raw.body.stylus,
parsedFunction.raw.body.css
)
if (rawBody.raw) {
atRuleRaws.body = rawBody
}
if (parsedFunction.raw.identifier !== "@") {
atRuleRaws.identifier = parsedFunction.raw.identifier
}
// Create Rule node
const atRule = postcss.atRule()
atRule.parent = parent
atRule.name = parsedFunction.name
atRule.source = atRuleSource
atRule.params = parsedFunction.params
atRule.raws = atRuleRaws
// Stylus property
atRule.function = true
atRule.body = parsedFunction.body
parent.nodes.push(atRule)
if (!parsedFunction.raw.semicolon) {
atRule.omittedSemi = true
}
}
atruleExpressionImpl(node, parent, _info) {

@@ -1353,7 +1304,3 @@ // `{...}`

blockNode.nodes.forEach((n, i) =>
this.process(
n,
rule,
new ProcessInfo(blockNode.nodes, i, info, rule)
)
this.process(n, rule, new ProcessInfo(blockNode.nodes, i, info))
)

@@ -1429,3 +1376,3 @@ this.pushInlineComments(rule, afterInlineComments)

declImpl(node, { propStartNode, atblock }, parent, info) {
declImpl(node, { propStartNode, atblock }, parent, _info) {
const propStartIndex = this.sourceCode.getIndex(propStartNode)

@@ -1475,3 +1422,6 @@ const { prop, endIndex: propEndIndex } = parseProp(

} else {
const blockParent = info.parent.parentNode
let blockParent = parent.parent
while (blockParent.postfix) {
blockParent = blockParent.parent
}
const parentIndex = blockParent.nodes.indexOf(parent)

@@ -1478,0 +1428,0 @@ ;({

@@ -32,6 +32,6 @@ "use strict"

* The source code split into lines according
* @param {string} spaces source code
* @param {string} text source code
* @returns {string[]} lines
*/
function toLines(spaces) {
function toLines(text) {
const lines = []

@@ -43,8 +43,8 @@

let start = 0
while ((match = lineEndingPattern.exec(spaces))) {
while ((match = lineEndingPattern.exec(text))) {
const end = match.index + match[0].length
lines.push(spaces.slice(start, end))
lines.push(text.slice(start, end))
start = end
}
lines.push(spaces.slice(start))
lines.push(text.slice(start))

@@ -102,9 +102,15 @@ return lines

rawValue(node, prop) {
const value = node[prop]
const raw = node.raws[prop]
if (raw && raw.value === value && raw.stylus != null) {
return raw.stylus
const value = this.rawValuePlain(node, prop)
if (
prop === "selector" &&
node.parent &&
node.parent.pythonic &&
/\r\n|\r|\n/gu.test(value)
) {
const indent = this.getIndent(node)
return toLines(value)
.map(line => line.replace(/^\s+/u, indent))
.join("")
}
return super.rawValue(node, prop)
return value
}

@@ -231,2 +237,12 @@

rawValuePlain(node, prop) {
const value = node[prop]
const raw = node.raws[prop]
if (raw && raw.value === value && raw.stylus != null) {
return raw.stylus
}
return super.rawValue(node, prop)
}
rawPlain(node, own, detect) {

@@ -261,3 +277,3 @@ if (node.postfix && own === "before") {

let parentTarget = childTarget.parent
if (parentTarget.postfix) {
while (parentTarget.postfix) {
childTarget = parentTarget

@@ -292,7 +308,6 @@ parentTarget = childTarget.parent

}
const parent2Target =
parentTarget.parent &&
(parentTarget.parent.postfix
? parentTarget.parent.parent
: parentTarget.parent)
let parent2Target = parentTarget.parent
while (parent2Target && parent2Target.postfix) {
parent2Target = parent2Target.parent
}

@@ -299,0 +314,0 @@ const parent2Indent =

{
"name": "postcss-styl",
"version": "0.0.8",
"version": "0.0.9",
"description": "PostCSS parser plugin for converting Stylus syntax to PostCSS AST.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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