Created
May 17, 2017 07:39
-
-
Save jamiebuilds/50e4f95c9f0fcb7dec843b643e16838a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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