els-component-extraction-addon
Advanced tools
Comparing version 0.1.9 to 0.1.10
@@ -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()] = [ |
{ | ||
"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; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
129300
628
0
9
+ Addedember-meta-explorer@^0.1.1
+ Added@babel/cli@7.26.4(transitive)
+ Added@babel/helper-annotate-as-pure@7.25.9(transitive)
+ Added@babel/helper-create-class-features-plugin@7.25.9(transitive)
+ Added@babel/helper-create-regexp-features-plugin@7.26.3(transitive)
+ Added@babel/helper-define-polyfill-provider@0.6.3(transitive)
+ Added@babel/helper-member-expression-to-functions@7.25.9(transitive)
+ Added@babel/helper-optimise-call-expression@7.25.9(transitive)
+ Added@babel/helper-plugin-utils@7.25.9(transitive)
+ Added@babel/helper-remap-async-to-generator@7.25.9(transitive)
+ Added@babel/helper-replace-supers@7.25.9(transitive)
+ Added@babel/helper-skip-transparent-expression-wrappers@7.25.9(transitive)
+ Added@babel/helper-wrap-function@7.25.9(transitive)
+ Added@babel/plugin-bugfix-firefox-class-in-computed-class-key@7.25.9(transitive)
+ Added@babel/plugin-bugfix-safari-class-field-initializer-scope@7.25.9(transitive)
+ Added@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@7.25.9(transitive)
+ Added@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.25.9(transitive)
+ Added@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly@7.25.9(transitive)
+ Added@babel/plugin-proposal-class-properties@7.18.6(transitive)
+ Added@babel/plugin-proposal-decorators@7.25.9(transitive)
+ Added@babel/plugin-proposal-nullish-coalescing-operator@7.18.6(transitive)
+ Added@babel/plugin-proposal-object-rest-spread@7.20.7(transitive)
+ Added@babel/plugin-proposal-optional-chaining@7.21.0(transitive)
+ Added@babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.2(transitive)
+ Added@babel/plugin-syntax-decorators@7.25.9(transitive)
+ Added@babel/plugin-syntax-import-assertions@7.26.0(transitive)
+ Added@babel/plugin-syntax-import-attributes@7.26.0(transitive)
+ Added@babel/plugin-syntax-jsx@7.25.9(transitive)
+ Added@babel/plugin-syntax-nullish-coalescing-operator@7.8.3(transitive)
+ Added@babel/plugin-syntax-object-rest-spread@7.8.3(transitive)
+ Added@babel/plugin-syntax-optional-chaining@7.8.3(transitive)
+ Added@babel/plugin-syntax-typescript@7.25.9(transitive)
+ Added@babel/plugin-syntax-unicode-sets-regex@7.18.6(transitive)
+ Added@babel/plugin-transform-arrow-functions@7.25.9(transitive)
+ Added@babel/plugin-transform-async-generator-functions@7.25.9(transitive)
+ Added@babel/plugin-transform-async-to-generator@7.25.9(transitive)
+ Added@babel/plugin-transform-block-scoped-functions@7.25.9(transitive)
+ Added@babel/plugin-transform-block-scoping@7.25.9(transitive)
+ Added@babel/plugin-transform-class-properties@7.25.9(transitive)
+ Added@babel/plugin-transform-class-static-block@7.26.0(transitive)
+ Added@babel/plugin-transform-classes@7.25.9(transitive)
+ Added@babel/plugin-transform-computed-properties@7.25.9(transitive)
+ Added@babel/plugin-transform-destructuring@7.25.9(transitive)
+ Added@babel/plugin-transform-dotall-regex@7.25.9(transitive)
+ Added@babel/plugin-transform-duplicate-keys@7.25.9(transitive)
+ Added@babel/plugin-transform-duplicate-named-capturing-groups-regex@7.25.9(transitive)
+ Added@babel/plugin-transform-dynamic-import@7.25.9(transitive)
+ Added@babel/plugin-transform-exponentiation-operator@7.26.3(transitive)
+ Added@babel/plugin-transform-export-namespace-from@7.25.9(transitive)
+ Added@babel/plugin-transform-for-of@7.25.9(transitive)
+ Added@babel/plugin-transform-function-name@7.25.9(transitive)
+ Added@babel/plugin-transform-json-strings@7.25.9(transitive)
+ Added@babel/plugin-transform-literals@7.25.9(transitive)
+ Added@babel/plugin-transform-logical-assignment-operators@7.25.9(transitive)
+ Added@babel/plugin-transform-member-expression-literals@7.25.9(transitive)
+ Added@babel/plugin-transform-modules-amd@7.25.9(transitive)
+ Added@babel/plugin-transform-modules-commonjs@7.26.3(transitive)
+ Added@babel/plugin-transform-modules-systemjs@7.25.9(transitive)
+ Added@babel/plugin-transform-modules-umd@7.25.9(transitive)
+ Added@babel/plugin-transform-named-capturing-groups-regex@7.25.9(transitive)
+ Added@babel/plugin-transform-new-target@7.25.9(transitive)
+ Added@babel/plugin-transform-nullish-coalescing-operator@7.25.9(transitive)
+ Added@babel/plugin-transform-numeric-separator@7.25.9(transitive)
+ Added@babel/plugin-transform-object-rest-spread@7.25.9(transitive)
+ Added@babel/plugin-transform-object-super@7.25.9(transitive)
+ Added@babel/plugin-transform-optional-catch-binding@7.25.9(transitive)
+ Added@babel/plugin-transform-optional-chaining@7.25.9(transitive)
+ Added@babel/plugin-transform-parameters@7.25.9(transitive)
+ Added@babel/plugin-transform-private-methods@7.25.9(transitive)
+ Added@babel/plugin-transform-private-property-in-object@7.25.9(transitive)
+ Added@babel/plugin-transform-property-literals@7.25.9(transitive)
+ Added@babel/plugin-transform-regenerator@7.25.9(transitive)
+ Added@babel/plugin-transform-regexp-modifiers@7.26.0(transitive)
+ Added@babel/plugin-transform-reserved-words@7.25.9(transitive)
+ Added@babel/plugin-transform-shorthand-properties@7.25.9(transitive)
+ Added@babel/plugin-transform-spread@7.25.9(transitive)
+ Added@babel/plugin-transform-sticky-regex@7.25.9(transitive)
+ Added@babel/plugin-transform-template-literals@7.25.9(transitive)
+ Added@babel/plugin-transform-typeof-symbol@7.25.9(transitive)
+ Added@babel/plugin-transform-typescript@7.26.3(transitive)
+ Added@babel/plugin-transform-unicode-escapes@7.25.9(transitive)
+ Added@babel/plugin-transform-unicode-property-regex@7.25.9(transitive)
+ Added@babel/plugin-transform-unicode-regex@7.25.9(transitive)
+ Added@babel/plugin-transform-unicode-sets-regex@7.25.9(transitive)
+ Added@babel/preset-env@7.26.0(transitive)
+ Added@babel/preset-modules@0.1.6-no-external-plugins(transitive)
+ Added@babel/preset-typescript@7.26.0(transitive)
+ Added@babel/runtime@7.26.0(transitive)
+ Added@glimmer/interfaces@0.47.9(transitive)
+ Added@glimmer/syntax@0.47.4(transitive)
+ Added@glimmer/util@0.47.9(transitive)
+ Added@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3(transitive)
+ Added@types/minimatch@3.0.5(transitive)
+ Addedanymatch@3.1.3(transitive)
+ Addedbabel-plugin-polyfill-corejs2@0.4.12(transitive)
+ Addedbabel-plugin-polyfill-corejs3@0.10.6(transitive)
+ Addedbabel-plugin-polyfill-regenerator@0.6.3(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-js-compat@3.39.0(transitive)
+ Addedember-meta-explorer@0.1.1(transitive)
+ Addedensure-posix-path@1.1.1(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfs-readdir-recursive@1.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhandlebars@4.7.8(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedlodash.debounce@4.0.8(transitive)
+ Addedmake-dir@2.1.0(transitive)
+ Addedmatcher-collection@2.0.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedneo-async@2.6.2(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpify@4.0.1(transitive)
+ Addedreaddirp@3.6.0(transitive)
+ Addedregenerate@1.4.2(transitive)
+ Addedregenerate-unicode-properties@10.2.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedregenerator-transform@0.15.2(transitive)
+ Addedregexpu-core@6.2.0(transitive)
+ Addedregjsgen@0.8.0(transitive)
+ Addedregjsparser@0.12.0(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedslash@2.0.0(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addeduglify-js@3.19.3(transitive)
+ Addedunicode-canonical-property-names-ecmascript@2.0.1(transitive)
+ Addedunicode-match-property-ecmascript@2.0.0(transitive)
+ Addedunicode-match-property-value-ecmascript@2.2.0(transitive)
+ Addedunicode-property-aliases-ecmascript@2.1.0(transitive)
+ Addedwalk-sync@2.2.0(transitive)
+ Addedwordwrap@1.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)