<commit_before>/* Jedi public API */
import {parseFile} from './parse'
import transform from './transform'
import {compile} from './codegen'
import errorInfo from './util/error-info'
import * as fs from 'fs'

export function transpile(source, dest, lang, {adaptive, debug, writeErrorToFile = true} = {}) {
	const outputs = []
	try {
		const config = loadConfig(source)
		const tree = transform(parseFile(source), debug)
		if (adaptive || config.adaptive) {
			tree[4].unshift(['comment', [source, 0, 1], ['html']])
			outputs.push({file: dest, content: compile(tree, lang)})
			tree[4][0][2] = ['xhtml mp 1.0']
			const wapDest = dest.replace(/(?=\.[^.]+$)/, '.wap')
			outputs.push({file: wapDest, content: compile(tree, lang)})
		} else {
			outputs.push({file: dest, content: compile(tree, lang)})
		}
	} catch (e) {
		errorInfo(e, source).forEach(args => console.error(...args))
		if (writeErrorToFile) outputs.push({file: dest, content: outputCompilingError(e, source, lang)})
		else throw e
	}<commit_msg>allow output AST as json<commit_after>/* Jedi public API */
import {parseFile} from './parse'
import transform from './transform'
import {compile} from './codegen'
import errorInfo from './util/error-info'
import * as fs from 'fs'

export function transpile(source, dest, lang, {adaptive, debug, writeErrorToFile = true} = {}) {
	const outputs = []
	try {
		const config = loadConfig(source)
		const tree = transform(parseFile(source), debug)
		if (!lang) return
		if (lang === 'json') {
			fs.writeFileSync(dest, JSON.stringify(tree, null, 2))
			return
		}
		if (adaptive || config.adaptive) {
			tree[4].unshift(['comment', [source, 0, 1], ['html']])
			outputs.push({file: dest, content: compile(tree, lang)})
			tree[4][0][2] = ['xhtml mp 1.0']
			const wapDest = dest.replace(/(?=\.[^.]+$)/, '.wap')
			outputs.push({file: wapDest, content: compile(tree, lang)})
		} else {
			outputs.push({file: dest, content: compile(tree, lang)})
		}
	} catch (e) {
		errorInfo(e, source).forEach(args => console.error(...args))
		if (writeErrorToFile) outputs.push({file: dest, content: outputCompilingError(e, source, lang)})
		else throw e
	}
{'fraction_non_alphanumeric': 0.18380642159143787, 'fraction_numerical': 0.007910656119125175, 'mean_word_length': 4.388471177944862, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '563337', 'n_tokens_mistral': 785, 'n_tokens_neox': 708, 'n_words': 199}