add eslint with an acorn-babel compatibility layer, yay! coming soon to a production release near you

This commit is contained in:
Sebastian McKenzie 2015-02-27 13:17:22 +11:00
parent a9db70b60d
commit 83c23d266f
32 changed files with 226 additions and 141 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
src/babel/transformation/templates

20
.eslintrc Normal file
View File

@ -0,0 +1,20 @@
{
"parser": "/Users/sebastian/Projects/6to5/6to5/eslint.js",
"ecmaFeatures": {
"blockBindings": true
},
"rules": {
"strict": 0,
"no-underscore-dangle": 0,
"no-unused-vars": 0,
"curly": 0,
"no-multi-spaces": 0,
"key-spacing": 0,
"no-return-assign": 0,
"consistent-return": 0,
"no-shadow": 0
},
"env": {
"node": true
}
}

59
eslint.js Normal file
View File

@ -0,0 +1,59 @@
var traverse = require("./lib/babel/traversal");
var Module = require("module");
var acorn = require("acorn-babel");
var hasPatched = false;
function monkeypatch() {
if (hasPatched) return;
hasPatched = true;
var mod = new Module(require.resolve("eslint"));
// monkeypatch estraverse
//var estraverse = mod.require("estraverse");
// monkeypatch escope
var escope = mod.require("escope");
console.log(escope);
}
var tokTypes = acorn.tokTypes;
function toEsprimaToken(token) {
var type = token.type;
if (type === tokTypes.name) {
token.type = "Identifier";
} else if (type === tokTypes.semi || type === tokTypes.comma || type === tokTypes.parenL || type === tokTypes.parenR || type === tokTypes.braceL || type === tokTypes.braceR) {
token.type = "Punctuator";
token.value = type.type;
}
}
exports.parse = function (code) {
monkeypatch();
var opts = {};
opts.ecmaVersion = 7;
opts.locations = true;
opts.playground = true;
opts.ranges = true;
var comments = opts.onComment = [];
var tokens = opts.onToken = [];
var ast = acorn.parse(code, opts);
// convert tokens
ast.tokens = tokens.map(function (token) {
return toEsprimaToken(token) || token;
});
// add comments
ast.comments = comments;
// transform esprima and acorn divergent nodes
return ast;
};

View File

@ -4,6 +4,7 @@ import fs from "fs";
export { default as _util, canCompile } from "../util"; export { default as _util, canCompile } from "../util";
export { default as transform } from "../transformation"; export { default as transform } from "../transformation";
export { default as parse } from "../esprima-compatibility";
export { version } from "../../../package"; export { version } from "../../../package";
@ -11,9 +12,9 @@ export { default as buildExternalHelpers } from "../build-external-helpers";
export { default as types } from "../types"; export { default as types } from "../types";
export function register(opts) { export function register(opts) {
var register = require("./register/node"); var callback = require("./register/node");
if (opts != null) register(opts); if (opts != null) callback(opts);
return register; return callback;
} }
export function polyfill() { export function polyfill() {

View File

@ -51,4 +51,4 @@ exports.Function = function (node, parent, detected) {
if (node.async) { if (node.async) {
detected("es7.asyncFunctions"); detected("es7.asyncFunctions");
} }
} };

View File

@ -5,7 +5,7 @@ export function ComprehensionBlock(node, print) {
this.push(" of "); this.push(" of ");
print(node.right); print(node.right);
this.push(")"); this.push(")");
}; }
export function ComprehensionExpression(node, print) { export function ComprehensionExpression(node, print) {
this.push(node.generator ? "(" : "["); this.push(node.generator ? "(" : "[");
@ -24,4 +24,4 @@ export function ComprehensionExpression(node, print) {
print(node.body); print(node.body);
this.push(node.generator ? ")" : "]"); this.push(node.generator ? ")" : "]");
}; }

View File

@ -71,4 +71,4 @@ export function JSXClosingElement(node, print) {
this.push(">"); this.push(">");
} }
export function JSXEmptyExpression() {}; export function JSXEmptyExpression() {}

View File

@ -3,7 +3,7 @@ import each from "lodash/collection/each";
import map from "lodash/collection/map"; import map from "lodash/collection/map";
import t from "../../types"; import t from "../../types";
var crawl = function (node, state) { function crawl(node, state) {
state ||= {}; state ||= {};
if (t.isMemberExpression(node)) { if (t.isMemberExpression(node)) {
@ -22,9 +22,9 @@ var crawl = function (node, state) {
} }
return state; return state;
}; }
var isHelper = function (node) { function isHelper(node) {
if (t.isMemberExpression(node)) { if (t.isMemberExpression(node)) {
return isHelper(node.object) || isHelper(node.property); return isHelper(node.object) || isHelper(node.property);
} else if (t.isIdentifier(node)) { } else if (t.isIdentifier(node)) {
@ -36,12 +36,12 @@ var isHelper = function (node) {
} else { } else {
return false; return false;
} }
}; }
var isType = function (node) { function isType(node) {
return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) || return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) ||
t.isIdentifier(node) || t.isMemberExpression(node); t.isIdentifier(node) || t.isMemberExpression(node);
}; }
exports.nodes = { exports.nodes = {
AssignmentExpression(node) { AssignmentExpression(node) {

View File

@ -12,7 +12,7 @@ import each from "lodash/collection/each";
*/ */
export default class Transformer { export default class Transformer {
constructor(key, transformer, opts) { constructor(transformerKey, transformer, opts) {
transformer = assign({}, transformer); transformer = assign({}, transformer);
var take = function (key) { var take = function (key) {
@ -33,7 +33,7 @@ export default class Transformer {
this.handlers = this.normalize(transformer); this.handlers = this.normalize(transformer);
this.opts ||= {}; this.opts ||= {};
this.key = key; this.key = transformerKey;
} }
normalize(transformer) { normalize(transformer) {

View File

@ -1,8 +1,8 @@
import t from "../../../types"; import t from "../../../types";
exports.check = require("../internal/modules").check; export { check } from "../internal/modules";
exports.ImportDeclaration = function (node, parent, scope, file) { export function ImportDeclaration(node, parent, scope, file) {
// flow type // flow type
if (node.isType) return; if (node.isType) return;
@ -22,9 +22,9 @@ exports.ImportDeclaration = function (node, parent, scope, file) {
} }
return nodes; return nodes;
}; }
exports.ExportDeclaration = function (node, parent, scope, file) { export function ExportDeclaration(node, parent, scope, file) {
// flow type // flow type
if (t.isTypeAlias(node.declaration)) return; if (t.isTypeAlias(node.declaration)) return;
@ -53,4 +53,4 @@ exports.ExportDeclaration = function (node, parent, scope, file) {
} }
return nodes; return nodes;
}; }

View File

@ -1,11 +1,11 @@
import ReplaceSupers from "../../helpers/replace-supers"; import ReplaceSupers from "../../helpers/replace-supers";
import t from "../../../types"; import t from "../../../types";
exports.check = function (node) { export function check(node) {
return t.isIdentifier(node, { name: "super" }); return t.isIdentifier(node, { name: "super" });
}; }
exports.Property = function (node, parent, scope, file) { export function Property(node, parent, scope, file) {
if (!node.method) return; if (!node.method) return;
var value = node.value; var value = node.value;
@ -29,4 +29,4 @@ exports.Property = function (node, parent, scope, file) {
]) ])
); );
} }
}; }

View File

@ -1,9 +1,9 @@
import * as util from "../../../util"; import * as util from "../../../util";
import t from "../../../types"; import t from "../../../types";
exports.check = function (node) { export function check(node) {
return t.isFunction(node) && hasDefaults(node); return t.isFunction(node) && hasDefaults(node);
}; }
var hasDefaults = function (node) { var hasDefaults = function (node) {
for (var i = 0; i < node.params.length; i++) { for (var i = 0; i < node.params.length; i++) {

View File

@ -1,48 +1,6 @@
import t from "../../../types"; import t from "../../../types";
exports.check = function (node) { function loose(node, body, objId) {
return t.isProperty(node) && node.computed;
};
exports.ObjectExpression = function (node, parent, scope, file) {
var hasComputed = false;
for (var i = 0; i < node.properties.length; i++) {
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
if (hasComputed) break;
}
if (!hasComputed) return;
var initProps = [];
var objId = scope.generateUidBasedOnNode(parent);
//
var body = [];
var container = t.functionExpression(null, [], t.blockStatement(body));
container._aliasFunction = true;
//
var callback = spec;
if (file.isLoose("es6.properties.computed")) callback = loose;
var result = callback(node, body, objId, initProps, file);
if (result) return result;
//
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(objId, t.objectExpression(initProps))
]));
body.push(t.returnStatement(objId));
return t.callExpression(container, []);
};
var loose = function (node, body, objId) {
for (var i = 0; i < node.properties.length; i++) { for (var i = 0; i < node.properties.length; i++) {
var prop = node.properties[i]; var prop = node.properties[i];
@ -54,9 +12,9 @@ var loose = function (node, body, objId) {
) )
)); ));
} }
}; }
var spec = function (node, body, objId, initProps, file) { function spec(node, body, objId, initProps, file) {
var props = node.properties; var props = node.properties;
var prop, key; var prop, key;
@ -124,4 +82,46 @@ var spec = function (node, body, objId, initProps, file) {
return first; return first;
} }
} }
}; }
export function check(node) {
return t.isProperty(node) && node.computed;
}
export function ObjectExpression(node, parent, scope, file) {
var hasComputed = false;
for (var i = 0; i < node.properties.length; i++) {
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
if (hasComputed) break;
}
if (!hasComputed) return;
var initProps = [];
var objId = scope.generateUidBasedOnNode(parent);
//
var body = [];
var container = t.functionExpression(null, [], t.blockStatement(body));
container._aliasFunction = true;
//
var callback = spec;
if (file.isLoose("es6.properties.computed")) callback = loose;
var result = callback(node, body, objId, initProps, file);
if (result) return result;
//
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(objId, t.objectExpression(initProps))
]));
body.push(t.returnStatement(objId));
return t.callExpression(container, []);
}

View File

@ -1,11 +1,11 @@
import clone from "lodash/lang/clone"; import clone from "lodash/lang/clone";
import t from "../../../types"; import t from "../../../types";
exports.check = function (node) { export function check(node) {
return t.isProperty(node) && (node.method || node.shorthand); return t.isProperty(node) && (node.method || node.shorthand);
}; }
exports.Property = function (node) { export function Property(node) {
if (node.method) { if (node.method) {
node.method = false; node.method = false;
} }
@ -14,4 +14,4 @@ exports.Property = function (node) {
node.shorthand = false; node.shorthand = false;
node.key = t.removeComments(clone(node.key)); node.key = t.removeComments(clone(node.key));
} }
}; }

View File

@ -3,20 +3,20 @@ import t from "../../../types";
exports.check = t.isSpreadElement; exports.check = t.isSpreadElement;
var getSpreadLiteral = function (spread, scope) { function getSpreadLiteral(spread, scope) {
return scope.toArray(spread.argument, true); return scope.toArray(spread.argument, true);
}; }
var hasSpread = function (nodes) { function hasSpread(nodes) {
for (var i = 0; i < nodes.length; i++) { for (var i = 0; i < nodes.length; i++) {
if (t.isSpreadElement(nodes[i])) { if (t.isSpreadElement(nodes[i])) {
return true; return true;
} }
} }
return false; return false;
}; }
var build = function (props, scope) { function build(props, scope) {
var nodes = []; var nodes = [];
var _props = []; var _props = [];
@ -40,9 +40,9 @@ var build = function (props, scope) {
push(); push();
return nodes; return nodes;
}; }
exports.ArrayExpression = function (node, parent, scope) { export function ArrayExpression(node, parent, scope) {
var elements = node.elements; var elements = node.elements;
if (!hasSpread(elements)) return; if (!hasSpread(elements)) return;
@ -55,9 +55,9 @@ exports.ArrayExpression = function (node, parent, scope) {
} }
return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes); return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes);
}; }
exports.CallExpression = function (node, parent, scope) { export function CallExpression(node, parent, scope) {
var args = node.arguments; var args = node.arguments;
if (!hasSpread(args)) return; if (!hasSpread(args)) return;
@ -95,9 +95,9 @@ exports.CallExpression = function (node, parent, scope) {
} }
node.arguments.unshift(contextLiteral); node.arguments.unshift(contextLiteral);
}; }
exports.NewExpression = function (node, parent, scope, file) { export function NewExpression(node, parent, scope, file) {
var args = node.arguments; var args = node.arguments;
if (!hasSpread(args)) return; if (!hasSpread(args)) return;
@ -128,4 +128,4 @@ exports.NewExpression = function (node, parent, scope, file) {
} else { } else {
return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]); return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]);
} }
}; }

View File

@ -4,11 +4,11 @@ var buildBinaryExpression = function (left, right) {
return t.binaryExpression("+", left, right); return t.binaryExpression("+", left, right);
}; };
exports.check = function (node) { export function check(node) {
return t.isTemplateLiteral(node) || t.isTaggedTemplateExpression(node); return t.isTemplateLiteral(node) || t.isTaggedTemplateExpression(node);
}; }
exports.TaggedTemplateExpression = function (node, parent, scope, file) { export function TaggedTemplateExpression(node, parent, scope, file) {
var args = []; var args = [];
var quasi = node.quasi; var quasi = node.quasi;
@ -31,9 +31,9 @@ exports.TaggedTemplateExpression = function (node, parent, scope, file) {
args = args.concat(quasi.expressions); args = args.concat(quasi.expressions);
return t.callExpression(node.tag, args); return t.callExpression(node.tag, args);
}; }
exports.TemplateLiteral = function (node) { export function TemplateLiteral(node) {
var nodes = []; var nodes = [];
var i; var i;
@ -61,4 +61,4 @@ exports.TemplateLiteral = function (node) {
} else { } else {
return nodes[0]; return nodes[0];
} }
}; }

View File

@ -2,11 +2,11 @@ import rewritePattern from "regexpu/rewrite-pattern";
import pull from "lodash/array/pull"; import pull from "lodash/array/pull";
import t from "../../../types"; import t from "../../../types";
exports.check = function (node) { export function check(node) {
return t.isLiteral(node) && node.regex && node.regex.flags.indexOf("u") >= 0; return t.isLiteral(node) && node.regex && node.regex.flags.indexOf("u") >= 0;
}; }
exports.Literal = function (node) { export function Literal(node) {
var regex = node.regex; var regex = node.regex;
if (!regex) return; if (!regex) return;
@ -16,4 +16,4 @@ exports.Literal = function (node) {
regex.pattern = rewritePattern(regex.pattern, regex.flags); regex.pattern = rewritePattern(regex.pattern, regex.flags);
regex.flags = flags.join(""); regex.flags = flags.join("");
}; }

View File

@ -3,7 +3,7 @@
import * as util from "../../../util"; import * as util from "../../../util";
import t from "../../../types"; import t from "../../../types";
exports.experimental = true; export var experimental = true;
var container = function (parent, call, ret, file) { var container = function (parent, call, ret, file) {
if (t.isExpressionStatement(parent) && !file.isConsequenceExpressionStatement(parent)) { if (t.isExpressionStatement(parent) && !file.isConsequenceExpressionStatement(parent)) {
@ -21,7 +21,7 @@ var container = function (parent, call, ret, file) {
} }
}; };
exports.AssignmentExpression = function (node, parent, scope, file) { export function AssignmentExpression(node, parent, scope, file) {
var left = node.left; var left = node.left;
if (!t.isVirtualPropertyExpression(left)) return; if (!t.isVirtualPropertyExpression(left)) return;
@ -59,9 +59,9 @@ exports.AssignmentExpression = function (node, parent, scope, file) {
} }
return container(parent, call, value, file); return container(parent, call, value, file);
}; }
exports.UnaryExpression = function (node, parent, scope, file) { export function UnaryExpression(node, parent, scope, file) {
var arg = node.argument; var arg = node.argument;
if (!t.isVirtualPropertyExpression(arg)) return; if (!t.isVirtualPropertyExpression(arg)) return;
if (node.operator !== "delete") return; if (node.operator !== "delete") return;
@ -72,9 +72,9 @@ exports.UnaryExpression = function (node, parent, scope, file) {
}); });
return container(parent, call, t.literal(true), file); return container(parent, call, t.literal(true), file);
}; }
exports.CallExpression = function (node, parent, scope) { export function CallExpression(node, parent, scope) {
var callee = node.callee; var callee = node.callee;
if (!t.isVirtualPropertyExpression(callee)) return; if (!t.isVirtualPropertyExpression(callee)) return;
@ -95,17 +95,17 @@ exports.CallExpression = function (node, parent, scope) {
} else { } else {
return call; return call;
} }
}; }
exports.VirtualPropertyExpression = function (node) { export function VirtualPropertyExpression(node) {
return util.template("abstract-expression-get", { return util.template("abstract-expression-get", {
PROPERTY: node.property, PROPERTY: node.property,
OBJECT: node.object OBJECT: node.object
}); });
}; }
exports.PrivateDeclaration = function (node) { export function PrivateDeclaration(node) {
return t.variableDeclaration("const", node.declarations.map(function (id) { return t.variableDeclaration("const", node.declarations.map(function (id) {
return t.variableDeclarator(id, t.newExpression(t.identifier("WeakMap"), [])); return t.variableDeclarator(id, t.newExpression(t.identifier("WeakMap"), []));
})); }));
}; }

View File

@ -3,13 +3,13 @@ import traverse from "../../../traversal";
import * as util from "../../../util"; import * as util from "../../../util";
import t from "../../../types"; import t from "../../../types";
exports.experimental = true; export var experimental = true;
exports.ComprehensionExpression = function (node, parent, scope, file) { export function ComprehensionExpression(node, parent, scope, file) {
var callback = array; var callback = array;
if (node.generator) callback = generator; if (node.generator) callback = generator;
return callback(node, parent, scope, file); return callback(node, parent, scope, file);
}; }
var generator = function (node) { var generator = function (node) {
var body = []; var body = [];

View File

@ -1,10 +1,10 @@
// https://github.com/rwaldron/exponentiation-operator // https://github.com/rwaldron/exponentiation-operator
exports.experimental = true;
import build from "../../helpers/build-binary-assignment-operator-transformer"; import build from "../../helpers/build-binary-assignment-operator-transformer";
import t from "../../../types"; import t from "../../../types";
export var experimental = true;
var MATH_POW = t.memberExpression(t.identifier("Math"), t.identifier("pow")); var MATH_POW = t.memberExpression(t.identifier("Math"), t.identifier("pow"));
build(exports, { build(exports, {

View File

@ -2,11 +2,11 @@
import t from "../../../types"; import t from "../../../types";
exports.experimental = true; export var experimental = true;
exports.manipulateOptions = function (opts) { export function manipulateOptions(opts) {
if (opts.whitelist.length) opts.whitelist.push("es6.destructuring"); if (opts.whitelist.length) opts.whitelist.push("es6.destructuring");
}; }
var hasSpread = function (node) { var hasSpread = function (node) {
for (var i = 0; i < node.properties.length; i++) { for (var i = 0; i < node.properties.length; i++) {
@ -17,7 +17,7 @@ var hasSpread = function (node) {
return false; return false;
}; };
exports.ObjectExpression = function (node, parent, scope, file) { export function ObjectExpression(node, parent, scope, file) {
if (!hasSpread(node)) return; if (!hasSpread(node)) return;
var args = []; var args = [];
@ -46,4 +46,4 @@ exports.ObjectExpression = function (node, parent, scope, file) {
} }
return t.callExpression(file.addHelper("extends"), args); return t.callExpression(file.addHelper("extends"), args);
}; }

View File

@ -1,5 +1,5 @@
exports.SequenceExpression = function (node) { export function SequenceExpression(node) {
if (node.expressions.length === 1) { if (node.expressions.length === 1) {
return node.expressions[0]; return node.expressions[0];
} }
}; }

View File

@ -1,7 +1,7 @@
import useStrict from "../../helpers/use-strict"; import useStrict from "../../helpers/use-strict";
import t from "../../../types"; import t from "../../../types";
exports.secondPass = true; export var secondPass = true;
exports.BlockStatement = exports.BlockStatement =
exports.Program = function (node, parent, scope, file) { exports.Program = function (node, parent, scope, file) {

View File

@ -1,6 +1,6 @@
import useStrict from "../../helpers/use-strict"; import useStrict from "../../helpers/use-strict";
exports.Program = function (program, parent, scope, file) { export function Program(program, parent, scope, file) {
if (!file.transformers["es6.modules"].canRun()) return; if (!file.transformers["es6.modules"].canRun()) return;
useStrict.wrap(program, function () { useStrict.wrap(program, function () {
@ -10,4 +10,4 @@ exports.Program = function (program, parent, scope, file) {
if (file.moduleFormatter.transform) { if (file.moduleFormatter.transform) {
file.moduleFormatter.transform(program); file.moduleFormatter.transform(program);
} }
}; }

View File

@ -49,4 +49,4 @@ export function ExportDeclaration(node, parent, scope) {
return [declar, node]; return [declar, node];
} }
} }
}; }

View File

@ -18,4 +18,4 @@ export function UnaryExpression(node, parent, scope, file) {
return call; return call;
} }
} }
}; }

View File

@ -19,7 +19,6 @@ export function CallExpression(node, parent, scope, file) {
} }
} }
exports.ImportDeclaration = export function ModuleDeclaration(node, parent, scope, file) {
exports.ExportDeclaration = function (node, parent, scope, file) {
check(node.source, file); check(node.source, file);
}; }

View File

@ -120,7 +120,7 @@ export default class TraversalPath {
// type is blacklisted // type is blacklisted
if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) { if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) {
return; return false;
} }
this.call("enter"); this.call("enter");

View File

@ -14,8 +14,8 @@
"EmptyStatement": ["Statement"], "EmptyStatement": ["Statement"],
"LabeledStatement": ["Statement"], "LabeledStatement": ["Statement"],
"VariableDeclaration": ["Statement", "Declaration"], "VariableDeclaration": ["Statement", "Declaration"],
"ExportDeclaration": ["Statement", "Declaration"], "ExportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"],
"ImportDeclaration": ["Statement", "Declaration"], "ImportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"],
"PrivateDeclaration": ["Statement", "Declaration"], "PrivateDeclaration": ["Statement", "Declaration"],
"ArrowFunctionExpression": ["Scopable", "Function", "Expression"], "ArrowFunctionExpression": ["Scopable", "Function", "Expression"],

View File

@ -136,6 +136,11 @@
"expressions": null "expressions": null
}, },
"TemplateLiteral": {
"quasis": null,
"expressions": null
},
"ThrowExpression": { "ThrowExpression": {
"argument": null "argument": null
}, },

View File

@ -535,7 +535,7 @@ t.toExpression = function (node) {
} else { } else {
throw new Error("cannot turn " + node.type + " to an expression"); throw new Error("cannot turn " + node.type + " to an expression");
} }
} };
/** /**
* Description * Description

View File

@ -74,23 +74,23 @@ var templateVisitor = {
}; };
export function template(name, nodes, keepExpression) { export function template(name, nodes, keepExpression) {
var template = exports.templates[name]; var ast = exports.templates[name];
if (!template) throw new ReferenceError("unknown template " + name); if (!ast) throw new ReferenceError("unknown template " + name);
if (nodes === true) { if (nodes === true) {
keepExpression = true; keepExpression = true;
nodes = null; nodes = null;
} }
template = cloneDeep(template); ast = cloneDeep(ast);
if (!isEmpty(nodes)) { if (!isEmpty(nodes)) {
traverse(template, templateVisitor, null, nodes); traverse(ast, templateVisitor, null, nodes);
} }
if (template.body.length > 1) return template.body; if (ast.body.length > 1) return ast.body;
var node = template.body[0]; var node = ast.body[0];
if (!keepExpression && t.isExpressionStatement(node)) { if (!keepExpression && t.isExpressionStatement(node)) {
return node.expression; return node.expression;
@ -107,7 +107,7 @@ export function parseTemplate(loc, code) {
function loadTemplates() { function loadTemplates() {
var templates = {}; var templates = {};
var templatesLoc = __dirname + "/transformation/templates"; var templatesLoc = path.join(__dirname, "transformation/templates");
if (!fs.existsSync(templatesLoc)) { if (!fs.existsSync(templatesLoc)) {
throw new Error("no templates directory - this is most likely the " + throw new Error("no templates directory - this is most likely the " +
"result of a broken `npm publish`. Please report to " + "result of a broken `npm publish`. Please report to " +
@ -118,7 +118,7 @@ function loadTemplates() {
if (name[0] === ".") return; if (name[0] === ".") return;
var key = path.basename(name, path.extname(name)); var key = path.basename(name, path.extname(name));
var loc = templatesLoc + "/" + name; var loc = path.join(templatesLoc, name);
var code = fs.readFileSync(loc, "utf8"); var code = fs.readFileSync(loc, "utf8");
templates[key] = parseTemplate(loc, code); templates[key] = parseTemplate(loc, code);