{"size": 587, "ext": "js", "max_stars_repo_path": "demo.js", "max_stars_repo_name": "derhuerst/make-code-sync", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "demo.js", "max_issues_repo_name": "derhuerst/make-code-sync", "max_issues_repo_issues_event_min_datetime": "2020-04-16T21:59:37.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-16T21:59:37.000Z", "max_forks_repo_path": "demo.js", "max_forks_repo_name": "derhuerst/make-code-sync", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 22.5769230769, "max_line_length": 74, "alphanum_fraction": 0.6729131175}
'use strict'

const parse = require('acorn').parse
const generate = require('escodegen').generate
const vm = require('vm')
const assert = require('assert')

const syncify = require('.')
const {now, defer} = require('./hooks')

const code = `
	let x = 2
	setTimeout(() => {
		x += 1
	}, 100)
	x = 0
`

const parsed = parse(code, {ecmaVersion: 6})
const sync = syncify(parsed)
const transformed = generate(sync.ast)
	+ '\nx' // to get the value of `x`s
const ctx = {setTimeout, [sync.nameOfNow]: now, [sync.nameOfDefer]: defer}

assert.strictEqual(vm.runInNewContext(transformed, ctx), 1)
