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

prettier-plugin-svelte

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-svelte - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

25

package.json
{
"name": "prettier-plugin-svelte",
"version": "0.1.1",
"version": "0.2.0",
"description": "Svelte plugin for prettier",

@@ -9,3 +9,3 @@ "main": "plugin.js",

"test": "ava",
"prepublish": "npm test && npm run build"
"prepublishOnly": "npm test && npm run build"
},

@@ -27,16 +27,17 @@ "repository": {

"dependencies": {
"prettier": "^1.14.2",
"svelte": "^2.12.0"
"prettier": "^1.16.1",
"svelte": "2.16.0",
"tslib": "^1.9.3"
},
"devDependencies": {
"@types/node": "^10.7.1",
"@types/prettier": "^1.13.2",
"ava": "^1.0.0-beta.7",
"rollup": "^0.64.1",
"rollup-plugin-commonjs": "^9.1.5",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-typescript": "^0.8.1",
"@types/node": "^10.12.18",
"@types/prettier": "^1.15.2",
"ava": "1.2.0",
"rollup": "1.1.2",
"rollup-plugin-commonjs": "9.2.0",
"rollup-plugin-node-resolve": "4.0.0",
"rollup-plugin-typescript": "1.0.0",
"ts-node": "^7.0.1",
"typescript": "^3.0.1"
"typescript": "3.2.4"
}
}

@@ -5,4 +5,4 @@ 'use strict';

var svelte = require('svelte');
var prettier = require('prettier');
var svelte = require('svelte');

@@ -62,3 +62,3 @@ function isASTNode(n) {

case 'Element':
case 'Component':
case 'InlineComponent':
case 'Slot':

@@ -72,3 +72,3 @@ case 'Window':

indent(group(concat([
node.type === 'Component' && node.expression
node.type === 'InlineComponent' && node.expression
? concat([

@@ -87,16 +87,2 @@ line,

]));
case 'Script':
case 'Style':
return group(concat([
'<',
node.type.toLowerCase(),
indent(group(concat(path.map(childPath => childPath.call(print), 'attributes')))),
'>',
indent(path.call(print, 'content')),
hardline,
'</',
node.type.toLowerCase(),
'>',
hardline,
]));
case 'Identifier':

@@ -258,2 +244,3 @@ return node.name;

}
console.log(JSON.stringify(node, null, 4));
throw new Error('unknown node type: ' + node.type);

@@ -333,3 +320,3 @@ }

const { builders: { concat: concat$1, hardline: hardline$1 }, utils: { removeLines }, } = prettier.doc;
const { builders: { concat: concat$1, hardline: hardline$1, group: group$1, indent: indent$1 }, utils: { removeLines }, } = prettier.doc;
function embed(path, print, textToDoc, options) {

@@ -344,7 +331,6 @@ const node = path.getNode();

switch (node.type) {
case 'Program':
const script = getText(node, options);
return concat$1([hardline$1, nukeLastLine(textToDoc(script, { parser: 'babylon' }))]);
case 'StyleProgram':
return concat$1([hardline$1, nukeLastLine(textToDoc(node.styles, { parser: 'css' }))]);
case 'Script':
return embedTag(path, print, textToDoc, node, 'babel');
case 'Style':
return embedTag(path, print, textToDoc, node, 'css');
}

@@ -395,3 +381,34 @@ return null;

}
function embedTag(path, print, textToDoc, node, parser) {
const contentAttribute = node.attributes.find(n => n.name === '✂prettier:content✂');
let content = '';
if (contentAttribute &&
Array.isArray(contentAttribute.value) &&
contentAttribute.value.length > 0) {
const encodedContent = contentAttribute.value[0].data;
content = Buffer.from(encodedContent, 'base64').toString('ascii');
}
node.attributes = node.attributes.filter(n => n !== contentAttribute);
return group$1(concat$1([
'<',
node.type.toLowerCase(),
indent$1(group$1(concat$1(path.map(childPath => childPath.call(print), 'attributes')))),
'>',
indent$1(concat$1([hardline$1, nukeLastLine(textToDoc(content, { parser }))])),
hardline$1,
'</',
node.type.toLowerCase(),
'>',
hardline$1,
]));
}
function snipTagContent(tagName, source, placeholder = '') {
const regex = new RegExp(`<${tagName}([^]*?)>([^]*?)<\/${tagName}>`, 'gi');
return source.replace(regex, (_, attributes, content) => {
const encodedContext = Buffer.from(content).toString('base64');
return `<${tagName}${attributes} ✂prettier:content✂="${encodedContext}">${placeholder}</${tagName}>`;
});
}
function locStart(node) {

@@ -412,3 +429,7 @@ return node.start;

svelte: {
parse: (text) => svelte.parse(text),
parse: (text) => {
text = snipTagContent('style', text);
text = snipTagContent('script', text, '{}');
return svelte.parse(text);
},
locStart,

@@ -415,0 +436,0 @@ locEnd,

Sorry, the diff of this file is not supported yet

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