import path from "path" ; import fs from "fs" ; import { parse as esprimaParse } from "esprima" ; import { parse as reifyBabylonParse } from "reify/lib/parsers/babylon" ; import { namedTypes as n } from "../main" ; export function validateECMAScript ( file ) { var fullPath = path . join ( __dirname , ".." , file ) ; it ( "should validate " + file + " with Esprima" , function ( done ) { fs . readFile ( fullPath , "utf8" , function ( err , code ) { if ( err ) { throw err ; } n . Program . assert ( esprimaParse ( code ) , true ) ; n . Program . assert ( esprimaParse ( code , { loc : true } ) , true ) ; done ( ) ; } ) ; } ) ; it ( "should validate " + file + " with Babylon" , function ( done ) { fs . readFile ( fullPath , "utf8" , function ( err , code ) { if ( err ) { throw err ; } var ast = babylonParse ( code ) ; n . Program . assert ( ast , true ) ; done ( ) ; } ) ; } ) ; } ; export function babylonParse ( source , options ? ) { var ast = reifyBabylonParse ( source , options ) ; if ( ast . type === "File" ) ast = ast . program ; return ast ; } export { esprimaParse } ; export function isEarlyStageProposalType ( typeName ) { switch ( typeName ) { case "PipelineTopicExpression" : case "PipelineBareFunction" : case "PipelinePrimaryTopicReference" : case "Placeholder" : case "ArgumentPlaceholder" : return true ; default : return false ; } }