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

els-component-extraction-addon

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

els-component-extraction-addon - npm Package Compare versions

Comparing version 0.1.9 to 0.1.10

5

index.js

@@ -33,2 +33,3 @@ "use strict";

code: source,
shape: {},
args: [],

@@ -48,3 +49,3 @@ };

}
let { code, args } = result;
let { code, args, shape } = result;
let argNames = args

@@ -118,3 +119,3 @@ .slice(0)

tagName,
argNames
argNames, shape
);

@@ -121,0 +122,0 @@ edit.changes[URI.file(testFileName).toString()] = [

3

package.json
{
"name": "els-component-extraction-addon",
"version": "0.1.9",
"version": "0.1.10",
"description": "Ember Language Server Templates Code Actions extension",

@@ -26,2 +26,3 @@ "main": "index.js",

"@babel/types": "^7.9.6",
"ember-meta-explorer": "^0.1.1",
"ember-template-recast": "^4.1.4",

@@ -28,0 +29,0 @@ "vscode-languageserver": "^6.1.1",

@@ -9,2 +9,6 @@ const babel = require("@babel/core");

const lowerName = name.toLowerCase();
if (lowerName === 'context') {
return {};
}

@@ -74,3 +78,4 @@ if (

componentName,
args = []
args = [],
shape = {}
) {

@@ -82,3 +87,7 @@ function transform(babel) {

args.forEach((name) => {
scopeValues[name] = variableMockByName(name);
if (name in shape) {
scopeValues[name] = shape[name];
} else {
scopeValues[name] = variableMockByName(name);
}
});

@@ -85,0 +94,0 @@

@@ -1,8 +0,117 @@

const { transform } = require("ember-template-recast");
const { transform, traverse, parse } = require("ember-template-recast");
const { rebelObject } = require("ember-meta-explorer");
module.exports.transformSelection = function transformSelection(
template,
helpers = []
) {
function argsShapeFromTemplate(tpl) {
const tokens = [];
let blockScope = [];
let currentBlockPath = [];
let currentBlockArg = null;
let paramsMap = {};
traverse(parse(tpl), {
Block: {
enter(node) {
blockScope = [...blockScope, ...node.blockParams];
},
exit(node) {
node.blockParams.forEach(() => {
blockScope.pop();
});
},
},
BlockStatement: {
enter(node) {
if (node.path.type === "PathExpression") {
if (node.path.original === "each") {
const param = node.params[0];
if (
param.type === "PathExpression" &&
(param.data || blockScope.includes(param.parts[0]))
) {
let arrKey = `${param.original}.[]`;
currentBlockPath.push(arrKey.replace(currentBlockArg || "", ""));
paramsMap[arrKey] = node.program.blockParams[0];
currentBlockArg = node.program.blockParams[0];
}
}
}
},
exit(node) {
if (node.path.type === "PathExpression") {
if (node.path.original === "each") {
const param = node.params[0];
if (
param.type === "PathExpression" &&
(param.data || blockScope.includes(param.parts[0]))
) {
currentBlockPath.pop();
currentBlockArg = paramsMap[last(currentBlockPath)];
}
}
}
},
},
PathExpression(node) {
if (node.data) {
tokens.push(node.original);
} else {
const p = node.parts[0];
if (
!currentBlockPath.length ||
!blockScope.length ||
!currentBlockArg ||
!blockScope.includes(p)
) {
return;
}
let namePath = [];
currentBlockPath.forEach((n) => {
namePath.push(n);
});
let name = node.original.replace(currentBlockArg, "");
if (name) {
namePath.push(name);
}
if (blockScope.includes(currentBlockArg)) {
tokens.push(namePath.join(""));
}
}
},
});
const rawData = rebelObject(tokens).args || {};
createArrays(rawData);
return rawData;
}
function last(arr) {
return arr[arr.length - 1];
}
function createArrays(obj, key = null, parent = {}) {
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
return;
}
let props = Object.keys(obj);
props.forEach((name) => {
if (name === "[]") {
createArrays(obj[name], name, obj);
let value = obj[name];
if (typeof value === "string") {
parent[key] = ["foo", "bar", "baz"];
} else {
parent[key] = [
JSON.parse(JSON.stringify(value)),
JSON.parse(JSON.stringify(value)),
JSON.parse(JSON.stringify(value)),
];
}
} else {
createArrays(obj[name], name, obj);
}
});
return;
}
module.exports.argsShapeFromTemplate = argsShapeFromTemplate;
function transformSelection(template, helpers = []) {
const tokens = [];
const scope = {};

@@ -35,3 +144,2 @@ const externalTokens = new Set();

let blockScope = [];
let { code } = transform(template.trim(), () => {

@@ -134,5 +242,5 @@ return {

// tokens.push(node);
} else if (node.original.includes('-')) {
} else if (node.original.includes("-")) {
// skip component-like names
} else if (node.original.includes(".")) {
} else if (node.original.includes(".")) {
tokens.push(node);

@@ -161,6 +269,16 @@ } else if (node.original.toLowerCase() !== node.original) {

let shape = {};
try {
shape = argsShapeFromTemplate(code);
} catch (e) {
//
}
return {
code,
shape,
args: keys,
};
};
}
module.exports.transformSelection = transformSelection;
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