postcss-styl
Advanced tools
Comparing version 0.12.2 to 0.12.3
@@ -105,3 +105,3 @@ "use strict" | ||
if (!params.length) { | ||
between.push(...afterName) | ||
between.unshift(...afterName) | ||
afterName.length = 0 | ||
@@ -108,0 +108,0 @@ } |
"use strict" | ||
const { tokensToRaws, isSkipToken } = require("./token-utils") | ||
const { | ||
tokensToRaws, | ||
isSkipToken, | ||
createCommentTokenInfo, | ||
} = require("./token-utils") | ||
const { findLastIndex } = require("./util") | ||
module.exports = (sourceCode, end, opt = {}) => { | ||
const options = Object.assign({ blockCommentAsRaw: true }, opt) | ||
module.exports = (sourceCode, end, options) => { | ||
const cursor = sourceCode.createBackwardTokenCursor(end) | ||
@@ -37,19 +40,14 @@ | ||
const before = [] | ||
const buffer = [] | ||
const inlineComments = [] | ||
for (const afterToken of afterTokens) { | ||
if (afterToken.type === "inline-comment") { | ||
const raws = tokensToRaws(before) | ||
inlineComments.push({ | ||
token: afterToken, | ||
before: raws.raw, | ||
stylusBefore: raws.stylus, | ||
}) | ||
before.length = 0 | ||
inlineComments.push(createCommentTokenInfo(buffer, afterToken)) | ||
buffer.length = 0 | ||
} else { | ||
before.push(afterToken) | ||
buffer.push(afterToken) | ||
} | ||
} | ||
const raws = tokensToRaws(before) | ||
const raws = tokensToRaws(buffer) | ||
@@ -56,0 +54,0 @@ return { |
"use strict" | ||
const { tokensToRaws, isSkipToken } = require("./token-utils") | ||
const { | ||
tokensToRaws, | ||
isSkipToken, | ||
createCommentTokenInfo, | ||
} = require("./token-utils") | ||
@@ -11,3 +15,3 @@ module.exports = (sourceCode, start, end) => { | ||
const inlineComments = [] | ||
const before = [] | ||
const buffer = [] | ||
@@ -18,11 +22,6 @@ let token = cursor.next() | ||
if (token.type === "inline-comment") { | ||
const raws = tokensToRaws(before) | ||
inlineComments.push({ | ||
token, | ||
before: raws.raw, | ||
stylusBefore: raws.stylus, | ||
}) | ||
before.length = 0 | ||
inlineComments.push(createCommentTokenInfo(buffer, token)) | ||
buffer.length = 0 | ||
} else { | ||
before.push(token) | ||
buffer.push(token) | ||
endIndex = token.range[1] - 1 | ||
@@ -33,3 +32,3 @@ } | ||
const raws = tokensToRaws(before) | ||
const raws = tokensToRaws(buffer) | ||
@@ -36,0 +35,0 @@ return { |
@@ -12,9 +12,3 @@ "use strict" | ||
const token = tokens.pop() | ||
if ( | ||
token.type === "whitespace" || | ||
token.type === "escaped-whitespace" || | ||
token.type === "linebreak" || | ||
token.type === "comment" || | ||
token.type === "inline-comment" | ||
) { | ||
if (isSkipToken(token)) { | ||
between.unshift(token) | ||
@@ -21,0 +15,0 @@ } else { |
@@ -196,2 +196,3 @@ "use strict" | ||
const { semicolon, endIndex } = valueTokens | ||
return { | ||
@@ -198,0 +199,0 @@ value: raws.value.replace(/\s+$/u, ""), |
@@ -46,31 +46,9 @@ "use strict" | ||
}, | ||
tokensToRaws(tokens) { | ||
const value = [] | ||
const rawCss = [] | ||
const rawStylus = [] | ||
for (const token of tokens) { | ||
if (typeof token === "string") { | ||
rawStylus.push(token) | ||
rawCss.push(token) | ||
value.push(token) | ||
} else { | ||
rawStylus.push(token.value) | ||
if (token.type === "inline-comment") { | ||
rawCss.push(replaceInlineComment(token)) | ||
} else if (token.type === "escaped-whitespace") { | ||
const val = replaceEscaped(token) | ||
rawCss.push(val) | ||
value.push(val) | ||
} else { | ||
rawCss.push(token.value) | ||
if (token.type !== "comment") { | ||
value.push(token.value) | ||
} | ||
} | ||
} | ||
} | ||
tokensToRaws, | ||
createCommentTokenInfo(before, commentToken) { | ||
const raws = tokensToRaws(before) | ||
return { | ||
value: value.join(""), | ||
raw: rawCss.join(""), | ||
stylus: rawStylus.join(""), | ||
token: commentToken, | ||
before: raws.raw, | ||
stylusBefore: raws.stylus, | ||
} | ||
@@ -80,2 +58,3 @@ }, | ||
isSkipToken, | ||
isCommentToken, | ||
isWhitespaceToken, | ||
@@ -85,2 +64,38 @@ } | ||
/** | ||
* Tokens to raw info | ||
* @param {*} tokens | ||
*/ | ||
function tokensToRaws(tokens) { | ||
const value = [] | ||
const rawCss = [] | ||
const rawStylus = [] | ||
for (const token of tokens) { | ||
if (typeof token === "string") { | ||
rawStylus.push(token) | ||
rawCss.push(token) | ||
value.push(token) | ||
} else { | ||
rawStylus.push(token.value) | ||
if (token.type === "inline-comment") { | ||
rawCss.push(replaceInlineComment(token)) | ||
} else if (token.type === "escaped-whitespace") { | ||
const val = replaceEscaped(token) | ||
rawCss.push(val) | ||
value.push(val) | ||
} else { | ||
rawCss.push(token.value) | ||
if (token.type !== "comment") { | ||
value.push(token.value) | ||
} | ||
} | ||
} | ||
} | ||
return { | ||
value: value.join(""), | ||
raw: rawCss.join(""), | ||
stylus: rawStylus.join(""), | ||
} | ||
} | ||
/** | ||
* Checks if skip target token | ||
@@ -90,5 +105,12 @@ * @param {*} token token | ||
function isSkipToken(token) { | ||
return isWhitespaceToken(token) || isCommentToken(token) | ||
} | ||
/** | ||
* Checks if comment token | ||
* @param {*} token token | ||
*/ | ||
function isCommentToken(token) { | ||
return ( | ||
isWhitespaceToken(token) || | ||
(token && (token.type === "comment" || token.type === "inline-comment")) | ||
token && (token.type === "comment" || token.type === "inline-comment") | ||
) | ||
@@ -95,0 +117,0 @@ } |
@@ -486,49 +486,43 @@ "use strict" | ||
const semiChar = needSemi && isObjectProperty(node) ? "," : ";" | ||
if ( | ||
node.raws.identifier == null && | ||
!node.function && | ||
!node.postfix && | ||
!node.atblock && | ||
semiChar === ";" | ||
) { | ||
super.atrule(node, needSemi) | ||
} else { | ||
if (node.postfix && node.nodes) { | ||
this.block(node, "") | ||
if (node.raws && node.raws.postfixBefore != null) { | ||
this.builder(node.raws.postfixBefore) | ||
} else { | ||
this.builder(" ") // default | ||
} | ||
} | ||
let name = node.raws.identifier + node.name | ||
const params = node.params ? this.rawValue(node, "params") : "" | ||
if (typeof node.raws.afterName !== "undefined") { | ||
name += node.raws.afterName | ||
} else if (node.function || node.call || node.expression) { | ||
// name += "" | ||
} else if (params && name) { | ||
name += " " | ||
if (node.postfix && node.nodes) { | ||
this.block(node, "") | ||
if (node.raws && node.raws.postfixBefore != null) { | ||
this.builder(node.raws.postfixBefore) | ||
} else { | ||
this.builder(" ") // default | ||
} | ||
} | ||
let name = | ||
(node.raws.identifier == null ? "@" : node.raws.identifier) + | ||
node.name | ||
const params = node.params ? this.rawValue(node, "params") : "" | ||
let nameAndParams = name + params | ||
if (node.atblock) { | ||
// adjust @block | ||
if (isPythonic(node)) { | ||
nameAndParams = nameAndParams.replace(/@block$/iu, "") | ||
} else if (!/@block/iu.test(nameAndParams)) { | ||
nameAndParams += "@block" | ||
} | ||
} | ||
if (typeof node.raws.afterName !== "undefined") { | ||
name += node.raws.afterName | ||
} else if (node.function || node.call || node.expression) { | ||
// name += "" | ||
} else if (params && name) { | ||
name += " " | ||
} | ||
if (!node.postfix && node.nodes) { | ||
this.block(node, nameAndParams) | ||
} else { | ||
const end = | ||
(node.raws.stylusBetween || node.raws.between || "") + | ||
(needSemi ? semiChar : "") | ||
this.builder(nameAndParams + end, node) | ||
let nameAndParams = name + params | ||
if (node.atblock) { | ||
// adjust @block | ||
if (isPythonic(node)) { | ||
nameAndParams = nameAndParams.replace(/@block$/iu, "") | ||
} else if (!/@block/iu.test(nameAndParams)) { | ||
nameAndParams += "@block" | ||
} | ||
} | ||
if (!node.postfix && node.nodes) { | ||
this.block(node, nameAndParams) | ||
} else { | ||
const end = | ||
(node.raws.stylusBetween || node.raws.between || "") + | ||
(needSemi ? semiChar : "") | ||
this.builder(nameAndParams + end, node) | ||
} | ||
if (node.raws.ownSemicolon) { | ||
@@ -535,0 +529,0 @@ this.builder(node.raws.ownSemicolon, node, "end") |
{ | ||
"name": "postcss-styl", | ||
"version": "0.12.2", | ||
"version": "0.12.3", | ||
"description": "PostCSS parser plugin for converting Stylus syntax to PostCSS AST.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
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
4656
152822