6 examples of 'babel parser' in JavaScript

Every line of 'babel parser' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
86export default function parseBabel(content, filePath, deps, rootDir) {
87 const config = loadConfig('babel', regex, filePath, content, rootDir);
88
89 if (config) {
90 return checkOptions(deps, config);
91 }
92
93 if (path.basename(filePath) === 'package.json') {
94 const metadata = parse(content);
95 return checkOptions(deps, metadata.babel);
96 }
97
98 return [];
99}
225function transBabel(data) {
226 return new Promise((resolve, reject) => {
227 babel.transform(
228 data,
229 {
230 plugins: [
231 '@babel/plugin-transform-arrow-functions',
232 '@babel/plugin-transform-template-literals',
233 '@babel/plugin-transform-block-scoping',
234 '@babel/plugin-transform-destructuring',
235 '@babel/plugin-transform-parameters',
236 '@babel/plugin-transform-shorthand-properties'
237 ]
238 },
239 function(err, result) {
240 if (err) {
241 return reject(err);
242 }
243 resolve(result.code);
244 }
245 );
246 });
247}
26constructor(bundle, options) {
27 this.name = '@babel';
28 this.core = '@babel/core';
29 this.bundle = bundle;
30 this.options = options;
31 this.path = bundle.root;
32 this.babel = null;
33 this.resolve = bundle.resolve;
34}
16return function parser(strict:boolean, opt: sax.SAXOptions) {
17 if (!saxModule) {
18 saxModule = require('sax');
19 }
20 return saxModule.parser(strict, opt);
21}
25function loadAndParse(filePath) {
26 const file = fs.readFileSync(filePath);
27 return JSON.parse(file);
28}
8public static getAst(code: string): babel.types.File {
9 let ast: babel.types.File;
10
11 const options: babylon.BabylonOptions = {
12 plugins: [
13 'jsx',
14 'flow',
15 'objectRestSpread',
16 'classProperties',
17 'asyncGenerators',
18 'dynamicImport'
19 ],
20 sourceType: 'script'
21 };
22
23 try {
24 ast = babylon.parse(code, options);
25 } catch {
26 options.sourceType = 'module';
27 ast = babylon.parse(code, options);
28 }
29 return ast;
30}

Related snippets