Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).then(() => {
const builders = recast.types.builders;
const code = readFileSync('./ember-cli-build.js');
const ast = recast.parse(code);
recast.visit(ast, {
visitNewExpression: function (path) {
var node = path.node;
if (node.callee.name === 'EmberApp'
|| node.callee.name === 'EmberAddon') {
// console.log(node, node.arguments)
const configNode = node.arguments.find(element => element.type === 'ObjectExpression');
let fingerprint = configNode.properties.find(property => property.key.value === 'fingerprint');
if(!fingerprint) {
fingerprint = builders.property(
'init',
builders.identifier('fingerprint'),
function rewriteSource(source: string, refactoringNamespace: string, refactoringFileName: string) {
const exportedMembers: {prop: IdentifierKind, comments: CommentKind[]}[] = [];
const ast = parse(source);
ast.program.body = ast.program.body.map((expression: any) => {
// UI.ARIAUtils.Foo = 5;
if (expression.type === 'ExpressionStatement') {
// UI.ARIAUtils.Foo = 5
if (expression.expression.type === 'AssignmentExpression') {
const assignment = expression.expression;
// UI.ARIAUtils.Foo
if (assignment.left.type === 'MemberExpression') {
// UI.ARIAUtils.Foo -> UI.ARIAUtils
// UI.ARIAUtils.Nested.Foo -> UI.ARIAUtils
const topLevelAssignment = getTopLevelMemberExpression(assignment.left);
// If there is a nested export, such as `UI.ARIAUtils.Nested.Field`
if (topLevelAssignment !== assignment.left.object) {
read = function read(name) {
return recast.parse(fixture(name), {
esprima: esprima
})
}
export function generate({ assets, scenario, scenarioName }: Input) {
const ast = recast.parse(template, {
parser: require('recast/parsers/typescript'),
}) as n.File;
processComments(
ast,
{
SPECTRAL_BIN,
SCENARIO_NAME: scenarioName,
SCENARIO_FILE_PATH: join(SCENARIOS_ROOT, scenarioName),
SCENARIOS_ROOT,
TEST_NAME: scenario.test,
},
scenario,
);
populateAssets(ast.program.body, assets);
function toAST(code) {
return recast.parse(code).program.body;
}
},
},
{
package: "liquid-fire",
components: {
"{{liquid-bind}}": {
yieldsArguments: ["value"],
},
},
},
],
});
})()
`;
const embroiderAST = recast.parse(embroiderSnippet).program.body[0];
export function rewriteEmberCLIBuild(source: string) {
let ast = recast.parse(source);
recast.visit(ast, {
visitCallExpression(path) {
if (
path.node.callee.type === "MemberExpression" &&
path.node.callee.object.type === "Identifier" &&
path.node.callee.object.name === "app" &&
path.node.callee.property.type === "Identifier" &&
path.node.callee.property.name === 'toTree'
) {
path.replace(embroiderAST);
}
return false;
},
getDeprecatedInfo(type) {
const deprecatedPropType = 'deprecated(PropTypes.'
const indexStart = type.raw.indexOf(deprecatedPropType)
if (indexStart !== -1)
return {
propTypes: type.raw.substring(
indexStart + deprecatedPropType.length,
type.raw.indexOf(',')
),
explanation: recast.parse(type.raw).program.body[0].expression
.arguments[1].value
}
return false
}
function getDeprecatedInfo(type) {
const deprecatedPropType = 'deprecated(PropTypes.'
const indexStart = type.raw.indexOf(deprecatedPropType)
if (indexStart !== -1) {
return {
propTypes: type.raw.substring(
indexStart + deprecatedPropType.length,
type.raw.indexOf(','),
),
explanation: recast.parse(type.raw).program.body[0].expression
.arguments[1].value,
}
}
return false
}
function astFromUserCode(userCode: string): any {
return recast.parse(recast.prettyPrint(recast.parse(userCode)).code);
}