How to use the parseExpressionAt function from acorn

Find comprehensive JavaScript acorn.parseExpressionAt code examples handpicked from public code repositorys.

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)
}
fork icon54
star icon28
watch icon3

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] !== '@') {
fork icon107
star icon0
watch icon66

+ 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 [];
fork icon48
star icon0
watch icon1

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();
fork icon1
star icon2
watch icon3

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]*/, '');
fork icon0
star icon1
watch icon1