postcss-styl
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -86,2 +86,6 @@ "use strict" | ||
} | ||
get index() { | ||
return this._index | ||
} | ||
} | ||
@@ -223,2 +227,28 @@ | ||
/** | ||
* Gets if known assignment exression value node for given node | ||
* @param {*} node | ||
*/ | ||
function getAssignmentExpressionValue(node) { | ||
const name = getName(node) | ||
if (name === "binop") { | ||
if (node.op === "[]=" && node.val) { | ||
return node.val | ||
} | ||
} else if (name === "member") { | ||
if (node.val) { | ||
return node.val | ||
} | ||
} | ||
return null | ||
} | ||
/** | ||
* Checks if known assignment exression for given node | ||
* @param {*} node | ||
*/ | ||
function isAssignmentExpression(node) { | ||
return Boolean(getAssignmentExpressionValue(node)) | ||
} | ||
/** | ||
* Checks if known exression for given node name | ||
@@ -613,2 +643,3 @@ * @param {*} name | ||
*/ | ||
// eslint-disable-next-line complexity | ||
expression(node, parent, info) { | ||
@@ -628,40 +659,96 @@ if (node.isEmpty) { | ||
} | ||
if (node.nodes.length === 1) { | ||
const first = node.nodes[0] | ||
const name = getName(first) | ||
if (name === "call") { | ||
// fn() | ||
this.atruleImpl(node, {}, parent, info).call = true | ||
const first = node.nodes[0] | ||
if (first) { | ||
if (isAssignmentExpression(first)) { | ||
const valueNode = getAssignmentExpressionValue(first) | ||
if ( | ||
getName(valueNode) === "expression" && | ||
valueNode.nodes[0] && | ||
getName(valueNode.nodes[0]) === "atblock" | ||
) { | ||
const needAdjustInfo = node.nodes.length === 2 | ||
let atblockInfo = info | ||
if (needAdjustInfo) { | ||
// parser bug? | ||
// see tests/fixtures/hash04-block/input.styl | ||
const adjustNodes = [ | ||
...info.nodes.slice(0, info.index + 1), | ||
node.nodes[1], | ||
...info.nodes.slice(info.index + 1), | ||
] | ||
atblockInfo = new ProcessInfo( | ||
adjustNodes, | ||
info.index, | ||
info.parent | ||
) | ||
} | ||
// foo.bar = @block | ||
const atrule = this.atruleAtblockImpl( | ||
node, | ||
{ blockNode: valueNode.nodes[0].block }, | ||
parent, | ||
atblockInfo | ||
) | ||
atrule.expression = true | ||
atrule.assignment = true | ||
if (needAdjustInfo) { | ||
// parser bug? | ||
this.process( | ||
node.nodes[1], | ||
parent, | ||
new ProcessInfo( | ||
atblockInfo.nodes, | ||
info.index + 1, | ||
info.parent | ||
) | ||
) | ||
} | ||
} else { | ||
// foo.bar = baz | ||
this.declImpl( | ||
node, | ||
{ propStartNode: node }, | ||
parent, | ||
info | ||
).assignment = true | ||
} | ||
return | ||
} | ||
if (isExpressionName(name)) { | ||
this.atruleImpl( | ||
node, | ||
{ expression: true }, | ||
parent, | ||
info | ||
).expression = true | ||
return | ||
const firstName = getName(first) | ||
if (node.nodes.length === 1) { | ||
if (firstName === "call") { | ||
// fn() | ||
this.atruleImpl(node, {}, parent, info).call = true | ||
return | ||
} | ||
if (isExpressionName(firstName)) { | ||
this.atruleImpl( | ||
node, | ||
{ expression: true }, | ||
parent, | ||
info | ||
).expression = true | ||
return | ||
} | ||
if (firstName === "atblock") { | ||
this.atruleAtblockImpl( | ||
node, | ||
{ blockNode: first.block }, | ||
parent, | ||
info | ||
).expression = true | ||
return | ||
} | ||
} else if (node.nodes.length > 1) { | ||
if (firstName === "unit") { | ||
this.atruleImpl( | ||
node, | ||
{ expression: true }, | ||
parent, | ||
info | ||
).expression = true | ||
return | ||
} | ||
} | ||
if (name === "atblock") { | ||
this.atruleAtblockImpl( | ||
node, | ||
{ blockNode: first.block }, | ||
parent, | ||
info | ||
).expression = true | ||
return | ||
} | ||
} else if (node.nodes.length > 1) { | ||
const first = node.nodes[0] | ||
const name = getName(first) | ||
if (name === "unit") { | ||
this.atruleImpl( | ||
node, | ||
{ expression: true }, | ||
parent, | ||
info | ||
).expression = true | ||
return | ||
} | ||
} | ||
@@ -1094,2 +1181,3 @@ // TODO: Unknown expression type | ||
atRule.raws = atRuleRaws | ||
// Stylus property | ||
@@ -1096,0 +1184,0 @@ if (pythonic) { |
@@ -28,2 +28,14 @@ "use strict" | ||
} | ||
if (token.value === ".") { | ||
if ( | ||
tokens.length > 0 && | ||
tokens[tokens.length - 1].range[1] === token.range[0] | ||
) { | ||
// maybe member expression | ||
} else { | ||
// end | ||
endIndex = token.range[0] - 1 | ||
break | ||
} | ||
} | ||
if ( | ||
@@ -33,3 +45,2 @@ token.value === ":" || | ||
token.value === "," || | ||
token.value === "." || | ||
token.value === "!" || | ||
@@ -36,0 +47,0 @@ token.value === "}" |
{ | ||
"name": "postcss-styl", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "PostCSS parser plugin for converting Stylus syntax to PostCSS AST.", | ||
@@ -14,2 +14,4 @@ "main": "lib/index.js", | ||
"test:d1": "mocha --inspect-brk \"debug/index.js\" --reporter dot", | ||
"preversion": "npm run test", | ||
"version": "npm run lint -- --fix && git add .", | ||
"try:stylelint": "stylelint \"**/*.(vue|styl)\" --custom-syntax ./tests/integration/stylelint/custom-syntax.js" | ||
@@ -16,0 +18,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129025
3922