Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const convertImports = (srcPath) => {
let changed = false;
// console.log("scanning imports of", srcPath);
let code = fs.readFileSync(srcPath).toString();
const tree = esprima.parseModule(code);
const importer = srcPath.replace(basePath, "");
const importerDir = path.dirname(importer);
// console.log("-> ", importer);
tree.body.forEach(node => {
if (node.type === "ImportDeclaration") {
let importee = node.source.value;
if (importee.startsWith(".")) {
return;
}
let importeeDir = path.dirname(importee);
let importeeFile = path.basename(importee);
let relativePath = path.relative(importerDir, importeeDir);
if (relativePath.length === 0) {
relativePath = "."
}
if (!relativePath.startsWith(".")) {
const convertImports = (srcPath) => {
let changed = false;
// console.log("scanning imports of", srcPath);
let code = fs.readFileSync(srcPath).toString();
if (code.includes("import.meta.url")) {
console.log(`skipping convertion for ${srcPath} due to import.meta.url usage`);
return;
}
const tree = esprima.parseModule(code);
const importer = srcPath.replace(basePath, "");
const importerDir = path.dirname(importer);
tree.body.forEach(node => {
if (node.type === "ImportDeclaration" && node.source.value.endsWith(".less")) {
let importee = node.source.value;
node.source.value = importee.replace(".less", "-css.js");
changed = true;
// console.log(importee, "from", importer);
}
});
if (changed) {
fs.writeFileSync(srcPath, escodegen.generate(tree));
}
}
const code2ast = (code, options = opts) => esprima.parseModule(code, options.esprima)
parseEsprima(content) {
let data = esprima_parse(content, { loc: true, tolerant: true, jsx: true });
data.astParser = this.esprimaAst;
data.Scope = new Scope(data);
return data;
}
parse (str) {
return esprima.parseModule(str)
}
}
function getImportAst (temp) {
return esprima.parseModule(temp).body
}
var parseAst = function parseAst(text) {
return esprima.parseModule(text, {
range: true,
tokens: true,
comment: true
});
};
function parse(src) {
return esprima.parseModule(src, {
loc: true,
range: true,
jsx: true
});
}
var astify = function (code, opts) {
var parse_opts = { loc: true };
var method = _.get(opts, "estype", "module");
return method == "script" ?
esprima.parseScript(code, parse_opts) :
esprima.parseModule(code, parse_opts);
};
var ast_to_code = function (node) {