Skip to content

Instantly share code, notes, and snippets.

@cef62
Forked from jamiebuilds/babel.js
Created May 17, 2017 10:29
Show Gist options
  • Save cef62/2576bf05d09c8a96971662153354cf9b to your computer and use it in GitHub Desktop.
Save cef62/2576bf05d09c8a96971662153354cf9b to your computer and use it in GitHub Desktop.
import createBabelFile from 'babel-file';
import createBabylonOptions from 'babel-options';
import {buildCodeFrameError} from 'babel-errors';
let code = `
console.log('hello world');
`;
let file = createBabelFile(code, {
filename: 'hello-world.js',
parserOpts: createBabylonOptions({
stage: 2,
jsx: true,
flow: true,
}),
});
file.path.traverse({
StringLiteral(path) {
if (path.node.value !== 'hello world') {
throw buildCodeFrameError(path, 'Must be "hello-world"');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment