Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/sjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

var transform = require('babel-core').transform;
var transform = require('babel-core').transformFromAst;

var argv = require('yargs')
.usage('Usage: sjs [options] files ...')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"shift-js": "^0.2.1",
"shift-parser": "^4.1.0",
"shift-reducer": "^3.0.2",
"shift-spidermonkey-converter": "^1.0.0",
"shift-spidermonkey-converter": "gabejohnson/shift-spidermonkey-converter-js#babel",
"transit-js": "^0.8.846",
"yargs": "^4.3.2"
},
Expand Down
11 changes: 3 additions & 8 deletions src/load-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { unwrap } from './macro-context';

import { replaceTemplate } from './template-processor';

import { toSpiderMonkey as toBabel } from 'shift-spidermonkey-converter';

// indirect eval so in the global scope
let geval = eval;

Expand Down Expand Up @@ -77,14 +79,7 @@ function loadForCompiletime(expr, context) {
}))
}));

// TODO: should just pass an AST to babel but the estree converter still
// needs some work so until then just gen a string
// let estree = convert.toSpiderMonkey(parsed);
// let result = transform.fromAst(wrapForCompiletime(estree, sandboxKeys));

// let result = babel.transform(wrapForCompiletime(estree, sandboxKeys));
let gen = codegen(parsed, new FormattedCodeGen);
let result = context.transform(gen, {
let result = context.transform(toBabel(parsed), {
babelrc: true,
filename: context.filename
});
Expand Down
7 changes: 4 additions & 3 deletions src/sweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { Scope, freshScope } from "./scope";

import BindingMap from "./binding-map.js";

import { toSpiderMonkey as toBabel } from 'shift-spidermonkey-converter';

import Term from "./terms";
import { Modules } from './modules';

Expand Down Expand Up @@ -43,9 +45,8 @@ export function parse(source, options = {}) {

export function compile(source, options = {}) {
let ast = parse(source, options);
let gen = codegen(ast, new FormattedCodeGen());
return options.transform && (!options.noBabel) ? options.transform(gen, {
return options.transform && (!options.noBabel) ? options.transform(toBabel(ast), {
babelrc: true,
filename: options.filename
}) : { code: gen };
}) : { code: codegen(ast, new FormattedCodeGen()) };
}
4 changes: 3 additions & 1 deletion test/assertions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parse, compile } from "../src/sweet";
import expect from "expect.js";
import { zip, curry, equals, cond, identity, T, and, compose, type, mapObjIndexed, map, keys, has } from 'ramda';
import { transform } from 'babel-core';
import { transformFromAst as transform } from 'babel-core';
import Reader from "../src/shift-reader";
import { Enforester } from "../src/enforester";
import { List } from "immutable";
Expand Down Expand Up @@ -49,6 +49,7 @@ function testParseWithOpts(code, acc, expectedAst, options) {

export function testModule(code, loader, expectedAst) {
return testParseWithOpts(code, x => x, expectedAst, {
transform,
loc: false,
moduleResolver: x => x,
moduleLoader: path => loader[path]
Expand All @@ -58,6 +59,7 @@ export function testModule(code, loader, expectedAst) {
// if a property has the string <<hygiene> it is ignored
function testParse(code, acc, expectedAst) {
return testParseWithOpts(code, acc, expectedAst, {
transform,
loc: false,
moduleResolver: () => "",
moduleLoader: () => "",
Expand Down