How to use the esprima.parseModule function in esprima

To help you get started, we’ve selected a few esprima examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SAP / ui5-webcomponents / packages / core / lib / esm-abs-to-rel / index.js View on Github external
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(".")) {
github SAP / ui5-webcomponents / packages / main / lib / less-to-json-imports / index.js View on Github external
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));
	}
}
github DrSensor / p5-global2instance / index.js View on Github external
const code2ast = (code, options = opts) => esprima.parseModule(code, options.esprima)
github doyensec / electronegativity / src / parser / parser.js View on Github external
parseEsprima(content) {
    let data = esprima_parse(content, { loc: true, tolerant: true, jsx: true });
    data.astParser = this.esprimaAst;
    data.Scope = new Scope(data);
    return data;
  }
github Andifeind / firescript / src / JSParser.js View on Github external
parse (str) {
    return esprima.parseModule(str)
  }
}
github Youjingyu / vue-hap-tools / convert / utils / index.js View on Github external
function getImportAst (temp) {
  return esprima.parseModule(temp).body
}
github VulcanJS / vulcanjs-cli / dist / generator-vulcanjs / lib / ast.js View on Github external
var parseAst = function parseAst(text) {
  return esprima.parseModule(text, {
    range: true,
    tokens: true,
    comment: true
  });
};
github Persper / js-callgraph / src / astutil.js View on Github external
function parse(src) {
    return esprima.parseModule(src, {
        loc: true,
        range: true,
        jsx: true
    });
}
github brentlintner / synt / lib / similar / javascript.js View on Github external
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) {