How to use the parseExpressionAt function from acorn
Find comprehensive JavaScript acorn.parseExpressionAt code examples handpicked from public code repositorys.
GitHub: bramblex/jsjs-homework
7 8 9 10 11 12 13 14 15 16
throw new Error(`Unsupported Syntax ${node.type} at Location ${node.start}:${node.end}`); } function customerEval(code, env = {}) { const node = acorn.parseExpressionAt(code, 0, { ecmaVersion: 6 }) return evaluate(node, env) }
54
28
3
GitHub: just-js/just
158 159 160 161 162 163 164 165 166 167
acorn.parse(src, { ecmaVersion: 2020, sourceType: type, onToken: token => { if (token.value === 'require') { const expr = acorn.parseExpressionAt(src, token.start) if (expr.type === 'CallExpression') { if (expr.arguments[0].type === 'Literal') { let fileName = expr.arguments[0].value if (fileName[0] !== '@') {
107
0
66
+ 3 other calls in file
19 20 21 22 23 24 25 26 27 28
return extractedTokens.filter(token => isAVueGettextFunction(token)); } function getLocalizedStringsFromNode(filename, script, token) { const expression = acorn.parseExpressionAt(script, token.start); const localizedStrings = []; if (expression.type !== 'CallExpression') { return [];
48
0
1
GitHub: AnyaTyu/atom-bem-create
91 92 93 94 95 96 97 98 99 100
function retrieveBemEntityByOffset(fileContent, offset, options) { const canEnlarge = options && options.canEnlarge !== false || !options; return new Promise(function(res, err) { const ast = parse.parseExpressionAt(fileContent, offset); traverse.traverse(ast, { enter: function(node, parent) { const bemEntity = _onNode(node, parent); if(bemEntity) res(bemEntity), this.break();
1
2
3
109 110 111 112 113 114 115 116 117 118 119
} }; function parseJavaScript(self) { try { return parseExpressionAt(self._file.content, self._index, JS_OPTIONS); } catch (err) { if (err instanceof SyntaxError && Number.isInteger(err.pos)) { if (err.pos < self._file.content.length) { const message = err.message.replace(/\([\s\S]*/, '');
0
1
1
acorn.parse is the most popular function in acorn (270 examples)