Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace recast.transform() call with recast.traverse() #82

Merged
merged 1 commit into from
Dec 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions transforms/no-implicit-this/helpers/plugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const recast = require('ember-template-recast');

// everything is copy-pasteable to astexplorer.net.
// sorta. telemetry needs to be defined.
// telemtry can be populated with -mock-telemetry.json
Expand All @@ -6,8 +8,8 @@ const KNOWN_HELPERS = require('./known-helpers');
/**
* plugin entrypoint
*/
function transformPlugin(env, options = {}) {
let { builders: b } = env.syntax;
function transform(root, options = {}) {
let b = recast.builders;

let scopedParams = [];
let telemetry = options.telemetry || {};
Expand Down Expand Up @@ -73,7 +75,7 @@ function transformPlugin(env, options = {}) {

let inAttrNode = false;

return {
recast.traverse(root, {
Block: paramTracker,
ElementNode: paramTracker,

Expand Down Expand Up @@ -143,7 +145,7 @@ function transformPlugin(env, options = {}) {
// <div {{foo bar=BAZ}} />
handleHash(node.hash);
},
};
});
}

function populateInvokeables(telemetry) {
Expand All @@ -166,4 +168,4 @@ function populateInvokeables(telemetry) {
return [components, helpers];
}

module.exports = transformPlugin;
module.exports = transform;
6 changes: 4 additions & 2 deletions transforms/no-implicit-this/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');

const recast = require('ember-template-recast');
const { getTelemetry } = require('ember-codemods-telemetry-helpers');
const transformPlugin = require('./helpers/plugin');
const transform = require('./helpers/plugin');
const { getOptions: getCLIOptions } = require('codemod-cli');
const DEFAULT_OPTIONS = {};

Expand Down Expand Up @@ -49,5 +49,7 @@ module.exports = function transformer(file /*, api */) {
return;
}

return recast.transform(file.source, env => transformPlugin(env, options)).code;
let root = recast.parse(file.source);
transform(root, options);
return recast.print(root);
};