Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function transformer(file, api) {
const extension = path.extname(file.path);
if (!['.js', '.ts'].includes(extension.toLowerCase())) {
// do nothing on non-js/ts files
return;
}
const j = api.jscodeshift;
const options = Object.assign({}, DEFAULT_OPTIONS, getOptions());
let { source } = file;
const root = j(source);
const replaced = replaceEmberObjectExpressions(j, root, file.path, options);
if (replaced) {
source = root.toSource({
quote: options.quotes || options.quote,
});
}
return source;
};
module.exports = function transformer(file, api) {
const j = getParser(api);
const options = getOptions();
const root = j(file.source);
const createInit = (props, exp1, exp2) => {
// First create the super call for init
let superCall = j.expressionStatement(
j.callExpression(j.memberExpression(j.thisExpression(), j.identifier("_super"), false), [
j.identifier("...arguments")
])
);
let initProp = j.objectMethod("method", j.identifier("init"), [], j.blockStatement([superCall, exp1, exp2]));
props.push(initProp);
};
module.exports = function transformer(file, api) {
const j = getParser(api);
const options = getOptions();
const root = j(file.source);
root
.find(j.CallExpression, {
callee: {
type: "MemberExpression",
object: { type: "FunctionExpression" },
property: { name: "on" }
}
})
//.forEach(p => console.log(p))
.replaceWith(path => {
let onImport = j.importDeclaration(
[j.importSpecifier(j.identifier("on"))],
j.literal("@ember/object/evented")
);
module.exports = function transformer(file, api) {
const j = getParser(api);
const options = getOptions();
const root = j(file.source);
root
.find(j.CallExpression, {
callee: {
type: "MemberExpression",
object: { type: "FunctionExpression" },
property: { name: "computed" }
}
})
//.forEach(p => console.log(p))
.replaceWith(path => {
let computedImport = j.importDeclaration(
[j.importSpecifier(j.identifier("computed"))],
j.literal("@ember/object")
);
module.exports = function transformer(file, api) {
const j = getParser(api);
const options = getOptions();
const root = j(file.source);
root
.find(j.CallExpression, {
callee: {
type: "MemberExpression",
object: { callee: { name: "computed" } },
property: { name: "property" }
}
})
//.forEach(p => console.log(p))
.replaceWith(path => {
let args = [...path.value.arguments].concat(path.value.callee.object.arguments);
return j.callExpression(j.identifier("computed"), args);
});
function getOptions() {
let options = {};
let cliOptions = getCLIOptions();
if (cliOptions.config) {
let filePath = path.join(process.cwd(), cliOptions.config);
let config = JSON.parse(fs.readFileSync(filePath));
if (config.helpers) {
options.helpers = config.helpers;
}
if (config.skipAttributesThatMatchRegex) {
options.skipAttributesThatMatchRegex = config.skipAttributesThatMatchRegex;
}
if (config.skipFilesThatMatchRegex) {
options.skipFilesThatMatchRegex = new RegExp(config.skipFilesThatMatchRegex);
}
module.exports = function transformer(file, api) {
const j = getParser(api);
const options = getOptions();
const root = j(file.source);
root
.find(j.CallExpression, {
callee: {
object: {
callee: {
object: {
type: "ThisExpression"
},
property: {
name: "$"
}
}
}
}
return function(file, api) {
let src = file.source;
let options = getOptions();
let error;
fs.readdirSync(transformPath).forEach(fileName => {
let fix = require(path.join(transformPath, fileName));
if (typeof src === 'undefined') {
return;
}
try {
src = fix(Object.assign({}, file, { source: src }), api, options);
} catch (e) {
error = new Error(
`Transformation ${fileName} errored on file ${file.path}. Reason ${e}. Please report this in https://github.com/ember-codemods/ember-angle-brackets-codemod/issues\n\nStack trace:\n${e.stack}\n\nSource:\n${src}`
);
}
});