New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

prettier-plugin-stylus

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-stylus - npm Package Compare versions

Comparing version 0.0.1-alpha.0 to 0.0.1-alpha.1

198

dist/index.js

@@ -8,35 +8,31 @@ var __create = Object.create;

var __copyProps = (to, from, except, desc) => {
if ((from && typeof from === 'object') || typeof from === 'function') {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (
(target = mod != null ? __create(__getProtoOf(mod)) : {}),
__copyProps(
isNodeMode || !mod || !mod.__esModule
? __defProp(target, 'default', { value: mod, enumerable: true })
: target,
mod
)
);
var import_parser = __toESM(require('stylus/lib/parser.js'));
var prettier = __toESM(require('prettier'));
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
var import_parser = __toESM(require("stylus/lib/parser.js"));
var import_lexer = __toESM(require("stylus/lib/lexer.js"));
var import_comment = __toESM(require("stylus/lib/nodes/comment.js"));
var assert = __toESM(require("assert/strict"));
var prettier = __toESM(require("prettier"));
const b = prettier.doc.builders;
const languages = [
{
extensions: ['.styl'],
name: 'Stylus',
parsers: ['stylus']
extensions: [".styl"],
name: "Stylus",
parsers: ["stylus"]
}
];
const AST_FORMAT = 'postcss-stylus-ast';
const AST_FORMAT = "postcss-stylus-ast";
const parsers = {
stylus: {
parse: (text) => new import_parser.default(text).parse(),
parse: (text) => {
const result = new import_parser.default(text, { cache: false }).parse();
result.text = text;
return result;
},
astFormat: AST_FORMAT,

@@ -57,65 +53,61 @@ locStart: () => {

}
const printStylus = (path, options, print) => {
const printStylus = (path, options, print2) => {
var _a, _b;
const node = path.getValue();
const children = (node2, prop) => path.map(print, prop);
const child = (node2, prop) => path.call(print, prop);
const children = (_, prop) => path.map(print2, prop);
const child = (_, prop) => path.call(print2, prop);
switch (node.nodeName) {
case 'root':
const result = [
b.join([b.hardline, b.hardline], children(node, 'nodes')),
case "root":
return [
b.join([b.hardline, b.hardline], children(node, "nodes")),
b.hardline
];
return result;
case 'group': {
case "group": {
return [
b.join(b.hardline, children(node, 'nodes')),
child(node, 'block')
b.join(b.hardline, children(node, "nodes")),
child(node, "block")
];
}
case 'selector': {
return children(node, 'segments');
case "selector": {
return children(node, "segments");
}
case 'block': {
return block(children(node, 'nodes'));
case "block": {
return block(children(node, "nodes"));
}
case 'property': {
return [children(node, 'segments'), ' ', child(node, 'expr')];
case "property": {
return [children(node, "segments"), " ", child(node, "expr")];
}
case 'expression': {
const content = b.join(' ', children(node, 'nodes'));
if (
((_a = path.getParentNode()) == null ? void 0 : _a.nodeName) ===
'selector'
) {
return ['{', content, '}'];
case "expression": {
const content = b.join(" ", children(node, "nodes"));
if (((_a = path.getParentNode()) == null ? void 0 : _a.nodeName) === "selector") {
return ["{", content, "}"];
}
return content;
}
case 'binop': {
return [child(node, 'left'), ' ', node.op, ' ', child(node, 'right')];
case "binop": {
return [child(node, "left"), " ", node.op, " ", child(node, "right")];
}
case 'each': {
case "each": {
return [
'for ',
"for ",
node.val,
...(node.key ? [', ', node.key] : []),
' in ',
child(node, 'expr'),
child(node, 'block')
...node.key ? [", ", node.key] : [],
" in ",
child(node, "expr"),
child(node, "block")
];
}
case 'call': {
return [node.name, child(node, 'args')];
case "call": {
return [node.name, child(node, "args")];
}
case 'params':
case 'arguments': {
return ['(', b.join(', ', children(node, 'nodes')), ')'];
case "params":
case "arguments": {
return ["(", b.join(", ", children(node, "nodes")), ")"];
}
case 'function': {
return [node.name, child(node, 'params'), child(node, 'block')];
case "function": {
return [node.name, child(node, "params"), child(node, "block")];
}
case 'unit':
return `${node.val}${(_b = node.type) != null ? _b : ''}`;
case 'ident':
case "unit":
return `${node.val}${(_b = node.type) != null ? _b : ""}`;
case "ident":
if (node.val.isNull) {

@@ -125,20 +117,84 @@ return node.string;

const parent = path.getParentNode();
if ((parent == null ? void 0 : parent.nodeName) === 'params') {
return [node.name, ' = ', child(node, 'val')];
if ((parent == null ? void 0 : parent.nodeName) === "params") {
return [node.name, " = ", child(node, "val")];
}
return child(node, 'val');
return child(node, "val");
}
case 'literal':
case "literal":
return node.string;
case "string":
return [`'`, node.string, `'`];
case "comment":
return node.str;
default:
console.error(node);
throw new Error(node.nodeName + ' is not supported yet');
throw new Error(node.nodeName + " is not supported yet");
}
};
const toSequence = (path) => {
assert.equal(path.stack.length, 1);
let seq2 = [];
const toRemove = {};
const recurse = (path2) => {
const node = path2.getValue();
const i = seq2.length;
seq2.push(node);
printStylus(path2, null, recurse);
if (seq2[seq2.length - 1] !== node) {
toRemove[i] = true;
}
};
recurse(path);
const comments = [];
const lexer = new import_lexer.default(path.stack[0].text);
const originalSkip = lexer.skip.bind(lexer);
lexer.skip = (len) => {
if (lexer.str.slice(0, 2) === "//") {
const comment = new import_comment.default(lexer.str.slice(0, len), false, true);
comment.lineno = lexer.lineno;
comment.column = lexer.column;
comments.push(comment);
}
originalSkip(len);
};
let token;
while ((token = lexer.advance()) && token.type !== "eos") {
if (token.val && typeof token.val === "object")
seq2.push(token.val);
}
console.log(comments);
for (const comment of comments) {
let insertIndex = seq2.findIndex((node) => node.lineno > comment.lineno || node.lineno == comment.lineno && node.column >= comment.column);
if (insertIndex === -1) {
insertIndex = seq2.length;
}
console.log(insertIndex);
seq2.splice(insertIndex, 0, comment);
}
console.log(seq2);
return seq2;
};
const seq = [];
const print = (path, options, prettierPrint) => {
if (path.stack.length === 1) {
seq.length = 0;
seq.push(...toSequence(path));
}
const node = path.getValue();
const index = seq.indexOf(node);
if (node instanceof import_comment.default) {
console.log("wfasjld", node, index, seq[index + 1]);
}
if (seq[index + 1] instanceof import_comment.default && seq[index + 1].inline) {
return [
printStylus(path, options, prettierPrint),
" ",
seq[index + 1].str
];
}
return printStylus(path, options, prettierPrint);
};
const printers = {
[AST_FORMAT]: {
print: (...args) => {
const result = printStylus(...args);
return result;
}
print
}

@@ -145,0 +201,0 @@ };

@@ -5,36 +5,13 @@ var __defProp = Object.defineProperty;

var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if ((from && typeof from === 'object') || typeof from === 'function') {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) =>
__copyProps(__defProp({}, '__esModule', { value: true }), mod);
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var utils_exports = {};
__export(utils_exports, {
formatParams: () => formatParams
});
module.exports = __toCommonJS(utils_exports);
function formatParams(params) {
function formatParam(param) {
return param
.split('=')
.map((p) => p.trim())
.join(' = ');
}
return params
.split(',')
.map((p) => formatParam(p.trim()))
.join(', ');
}
//# sourceMappingURL=utils.js.map
{
"name": "prettier-plugin-stylus",
"version": "0.0.1-alpha.0",
"version": "0.0.1-alpha.1",
"description": "Prettier plugin for Stylus",
"main": "dist/index.js",
"files": ["dist/!(*.js.map)"],
"files": [
"dist/!(*.js.map)"
],
"scripts": {
"build": "esbuild src/index.ts src/utils.ts --sourcemap --format=cjs --outdir=dist",
"example": "npm run build && prettier --plugin . tests/example.styl",
"typeCheck": "tsc --noEmit",
"prepublishOnly": "npm run typeCheck && npm run build",
"test": "npm run build && jest"

@@ -36,5 +40,5 @@ },

"jest": "^27.5.1",
"jest-watch-typeahead": "^0.2.1",
"jest-watch-typeahead": "^1.1.0",
"typescript": "^4.6.3"
}
}

@@ -7,4 +7,5 @@ # prettier-plugin-stylus

- [ ] support comment
- [x] support comment
- [ ] add plugin recommendation in prettier docs
- [ ] Vue SFC (Waiting for upstream, see https://github.com/prettier/prettier/pull/12707)
- [ ] playground
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