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

vue-jscodeshift-adapter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-jscodeshift-adapter - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

tests/transforms/preserves-script-spacing/transform.js

4

CHANGELOG.md
# Change Log
## [2.2.0] - 2020-10-02
- Preserve indent of `<script>` and `<style>` tags. Thanks to @SevInf
## [2.1.0] - 2020-05-15

@@ -4,0 +8,0 @@

5

package.json
{
"name": "vue-jscodeshift-adapter",
"version": "2.1.0",
"version": "2.2.0",
"description": "Run jscodeshift on Vue single file components",

@@ -33,5 +33,2 @@ "main": "src/index.js",

"dependencies": {
"cheerio": "^1.0.0-rc.2",
"detect-indent": "^6.0.0",
"indent-string": "^4.0.0",
"vue-sfc-descriptor-to-string": "^1.0.0",

@@ -38,0 +35,0 @@ "vue-template-compiler": "^2.5.13"

@@ -12,3 +12,3 @@ const descriptorToString = require('vue-sfc-descriptor-to-string');

const sfcDescriptor = parseSfc(fileInfo.source);
const { sfcDescriptor, indents } = parseSfc(fileInfo.source);
const scriptBlock = sfcDescriptor.script;

@@ -24,5 +24,3 @@

return descriptorToString(sfcDescriptor, {
indents: {
template: 0
}
indents
});

@@ -29,0 +27,0 @@ } else {

const compiler = require('vue-template-compiler');
const cheerio = require('cheerio');
const detectIndent = require('detect-indent');
const indentString = require('indent-string');
module.exports = function parse(source) {
const sfcDescriptor = compiler.parseComponent(source);
const indents = {}
if (sfcDescriptor.template) {
sfcDescriptor.template.content = fixTemplateIndent(sfcDescriptor, source);
indents.template = detectIndent(sfcDescriptor.template, source);
}
return sfcDescriptor;
if (sfcDescriptor.script) {
indents.script = detectIndent(sfcDescriptor.script, source);
}
if (sfcDescriptor.styles.length > 0) {
indents.style = detectIndent(sfcDescriptor.styles[0], source);
}
return { sfcDescriptor, indents };
};
// assumes sfc has a <template>
// returns content for <template> with correct indent
function fixTemplateIndent(sfcDescriptor, source) {
const $ = cheerio.load(source);
function detectIndent(sfcBlock, source) {
const nonEmptyPaddingsPerLine = source.substring(sfcBlock.start, sfcBlock.end)
.split('\n')
.filter(line => line !== '')
.map(getLinePadding);
// contents of template including outer <template> pair
const fullTemplate = $.html($('template'));
const templateIndent = detectIndent(fullTemplate);
if (nonEmptyPaddingsPerLine.length === 0) {
return 0;
}
return Math.min(...nonEmptyPaddingsPerLine)
}
const templateBlock = sfcDescriptor.template;
return indentString(templateBlock.content, templateIndent.amount, templateIndent.indent);
function getLinePadding(line) {
const spacesMatch = line.match(/^ +/);
if (!spacesMatch) {
return 0;
}
return spacesMatch[0].length;
}
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