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.1.0 to 0.2.0

73

lib/parser/index.js

@@ -259,2 +259,46 @@ "use strict"

/**
* Checks if given node is conditional assignment
* @param {*} node ternary node
* @param {*} sourceCode
*/
function isConditionalAssignment(node, _sourceCode) {
const { cond, trueExpr, falseExpr } = node
// o is defined ? o : o = {}
// ^^^^^^^^^^^^
if (
cond.nodeName !== "binop" ||
cond.op !== "is defined" ||
cond.left.nodeName !== "ident"
) {
return false
}
const { name } = cond.left
// o is defined ? o : o = {}
// ^
if (trueExpr.nodeName !== "expression" || trueExpr.nodes.length !== 1) {
return false
}
const trueIdent = trueExpr.nodes[0]
if (
trueIdent.nodeName !== "ident" ||
trueIdent.name !== name ||
trueIdent.val.nodeName !== "null"
) {
return false
}
// o is defined ? o : o = {}
// ^^^^^^
if (
falseExpr.nodeName === "ident" &&
falseExpr.name === name &&
falseExpr.val.nodeName === "expression"
) {
return true
}
return false
}
class StylusParser {

@@ -452,2 +496,17 @@ constructor(input) {

ternary(node, parent, info) {
if (isConditionalAssignment(node, this.sourceCode)) {
// conditional assignment
const valueNode =
node.falseExpr.val.nodes[node.falseExpr.val.nodes.length - 1]
const decl = this.declImpl(
node,
{ propStartNode: node, atblockLast: valueNode },
parent,
info
)
decl.assignment = true
decl.conditional = true
return
}
this.atruleImpl(

@@ -597,5 +656,9 @@ node,

) {
const atblock = node.val.nodes[0]
this.declImpl(
node,
{ propStartNode: node, atblock: node.val.nodes[0] },
{
propStartNode: node,
atblockLast: atblock.nodes[atblock.nodes.length - 1],
},
parent,

@@ -1360,3 +1423,3 @@ info

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

@@ -1378,6 +1441,4 @@ const { prop, endIndex: propEndIndex } = parseProp(

{
minEnd: atblock
? this.sourceCode.getIndex(
atblock.nodes[atblock.nodes.length - 1]
)
minEnd: atblockLast
? this.sourceCode.getIndex(atblockLast)
: undefined,

@@ -1384,0 +1445,0 @@ }

39

lib/parser/parse-value.js

@@ -125,3 +125,3 @@ "use strict"

let sep = null
const valueStart = tokens.findIndex(t => {
const valueStart = tokens.findIndex((t, i) => {
if (isSkipToken(t)) {

@@ -135,2 +135,13 @@ return false

}
if (
t.value === "?" &&
tokens[i + 1] &&
tokens[i + 1].value === "="
) {
sep = "?"
return false
}
} else if ((sep === ":" || sep === "?") && t.value === "=") {
sep += t.value
return false
}

@@ -151,16 +162,18 @@ return true

let betweenCss = between
if (between.some(t => t.value === sep)) {
if (sep === "=") {
if (sep !== ":") {
if (!sep) {
betweenCss = [":", ...between]
} else {
const seps = sep.split("")
variable = true
let replaced = false
betweenCss = between.map(t => {
if (!replaced && t.value === "=") {
replaced = true
return ":"
}
return t
})
betweenCss = between
.map(t => {
if (t.value === seps[0]) {
seps.shift()
return seps.length ? null : ":"
}
return t
})
.filter(s => Boolean(s))
}
} else {
betweenCss = [":", ...between]
}

@@ -167,0 +180,0 @@

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

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

"test:d": "mocha --inspect --debug-brk \"tests/**/*.js\" --reporter dot",
"test:d2": "mocha --inspect --debug-brk \"tests/**/postcss-nested.js\" --reporter dot"
"test:d1": "mocha --inspect --debug-brk \"debug/index.js\" --reporter dot",
"test:d2": "mocha --inspect --debug-brk \"tests/**/postcss-nested.js\" --reporter dot",
"try:stylelint": "stylelint \"**/*.(vue|styl)\" --custom-syntax ./tests/integration/stylelint/custom-syntax.js"
},

@@ -17,0 +19,0 @@ "repository": {

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