How to use the parseExpression function from babylon

Find comprehensive JavaScript babylon.parseExpression code examples handpicked from public code repositorys.

16
17
18
19
20
21
22
23
24
25

  if (t.isIdentifier(nodePath.node.id)) {
    const replaceCode =
      state.replacers[`${kind} ${nodePath.node.id.name} =`]
    if (replaceCode) {
      const newAst = parseExpression(replaceCode)
      nodePath.get('init').replaceWith(newAst)
    }
  }
},
fork icon1
star icon20
watch icon0

20
21
22
23
24
25
26
27
28
29
30
31
const path = require('path');


const debug = createDebug('babel-plugin-graphql-tag');


// eslint-disable-next-line no-restricted-syntax
const uniqueFn = parseExpression(`
  (definitions) => {
    const names = {};
    return definitions.filter(definition => {
      if (definition.kind !== 'FragmentDefinition') {
fork icon1
star icon0
watch icon0

323
324
325
326
327
328
329
330
331
332
}
lastSrc = src;
lastConstants = constants;
var ast;
try {
    ast = babylon_1.parseExpression(src, options);
}
catch (ex) {
    return (lastWasConstant = false);
}
fork icon0
star icon0
watch icon0

+ 3 other calls in file

8
9
10
11
12
13
14
15
16
17
18


let ast = babylon.parse(sourceCode, {
  sourceType: 'module',
  plugins: ['jsx']
});
let a = babylon.parseExpression(sourceCode, {
  sourceType: 'module',
  plugins: ['jsx']
})
console.log(ast)
fork icon0
star icon0
watch icon0

+ 2 other calls in file

11
12
13
14
15
16
17
18
19
20
		}"${i === path.node.properties.length - 1 ? "" : ","}`;
	},
	""
);

const newNode = babylon.parseExpression(
	`JSON.parse({${stringifiedObject}})`
);

// This is an infinite loop that needs to be fixed
fork icon0
star icon0
watch icon0

24
25
26
27
28
29
30
31
32
33
34
35


const ASSET_REGISTRY_PATH = 'react-native/Libraries/Image/AssetRegistry';


function generateAssetCodeFileAst(assetDescriptor: AssetDescriptor): Object {
  const properDescriptor = filterObject(assetDescriptor, assetPropertyBlacklist);
  const descriptorAst = babylon.parseExpression(JSON.stringify(properDescriptor));
  const t = babel.types;
  const moduleExports = t.memberExpression(t.identifier('module'), t.identifier('exports'));
  const requireCall =
    t.callExpression(t.identifier('require'), [t.stringLiteral(ASSET_REGISTRY_PATH)]);
fork icon0
star icon0
watch icon0