This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
module.exports = CommonJSModuleFormatter;
|
||||
|
||||
var types = require("ast-types");
|
||||
var def = types.Type.def;
|
||||
|
||||
def("ImportBatchSpecifier")
|
||||
.bases("Specifier")
|
||||
.build("id")
|
||||
.field("id", def("Identifier"));
|
||||
|
||||
types.finalize();
|
||||
|
||||
var util = require("../util");
|
||||
var b = require("recast").types.builders;
|
||||
|
||||
@@ -30,7 +40,7 @@ CommonJSModuleFormatter.prototype.importSpecifier = function (specifier, node, n
|
||||
var templateName = "require-assign";
|
||||
|
||||
// import * as bar from "foo";
|
||||
if (specifier.type !== "ImportNamespaceSpecifier") templateName += "-key";
|
||||
if (specifier.type !== "ImportBatchSpecifier") templateName += "-key";
|
||||
|
||||
nodes.push(util.template(templateName, {
|
||||
VARIABLE_NAME: variableName.name,
|
||||
|
||||
@@ -68,12 +68,6 @@ var multiple = function (node, file) {
|
||||
};
|
||||
|
||||
exports.ComprehensionExpression = function (node, parent, file) {
|
||||
_.each(node.blocks, function (block) {
|
||||
if (!block.of) {
|
||||
throw util.errorWithNode(block, "for-in array comprehension is not supported");
|
||||
}
|
||||
});
|
||||
|
||||
if (node.blocks.length === 1) {
|
||||
return single(node);
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var traverse = require("./traverse");
|
||||
var astTypes = require("recast").types;
|
||||
var recast = require("recast");
|
||||
var acorn = require("acorn");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
@@ -237,6 +238,27 @@ exports.repeat = function (width, cha) {
|
||||
exports.parse = function (opts, code, callback) {
|
||||
try {
|
||||
var recastOpts = {};
|
||||
|
||||
recastOpts.esprima = {
|
||||
parse: function (src) {
|
||||
var comments = [];
|
||||
var tokens = [];
|
||||
|
||||
var ast = acorn.parse(src, {
|
||||
ecmaVersion: 6,
|
||||
locations: true,
|
||||
onComment: comments,
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
});
|
||||
|
||||
ast.tokens = tokens;
|
||||
ast.comments = comments;
|
||||
|
||||
return ast;
|
||||
}
|
||||
};
|
||||
|
||||
if (opts.sourceMap) {
|
||||
recastOpts.sourceFileName = opts.sourceFileName;
|
||||
recastOpts.sourceRoot = opts.sourceRoot;
|
||||
@@ -254,11 +276,9 @@ exports.parse = function (opts, code, callback) {
|
||||
err._6to5 = true;
|
||||
err.message = opts.filename + ": " + err.message;
|
||||
|
||||
if (err.lineNumber) {
|
||||
var frame = exports.codeFrame(code, err.lineNumber, err.column);
|
||||
var err2 = new SyntaxError(err.message + frame);
|
||||
err2._6to5 = true;
|
||||
throw err2;
|
||||
if (err.loc) {
|
||||
var frame = exports.codeFrame(code, err.loc.line, err.loc.column);
|
||||
err.message = err.message + frame;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,8 @@
|
||||
"regenerator": "0.6.7",
|
||||
"chokidar": "^0.9.0",
|
||||
"source-map-support": "^0.2.7",
|
||||
"esutils": "^1.1.4"
|
||||
"esutils": "^1.1.4",
|
||||
"acorn": "^0.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"es6-transpiler": "0.7.17",
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
var arr = [for (i in [1, 2, 3]) i * i];
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "for-in array comprehension is not supported"
|
||||
}
|
||||
5
test/fixtures/syntax/arrow-functions/default-parameters/actual.js
vendored
Normal file
5
test/fixtures/syntax/arrow-functions/default-parameters/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var some = (count = "30") => {
|
||||
console.log("count", count);
|
||||
};
|
||||
|
||||
some();
|
||||
8
test/fixtures/syntax/arrow-functions/default-parameters/expected.js
vendored
Normal file
8
test/fixtures/syntax/arrow-functions/default-parameters/expected.js
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var some = function (count) {
|
||||
if (count === undefined) count = "30";
|
||||
console.log("count", count);
|
||||
};
|
||||
|
||||
some();
|
||||
2
test/fixtures/syntax/arrow-functions/destructuring-parameters/actual.js
vendored
Normal file
2
test/fixtures/syntax/arrow-functions/destructuring-parameters/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var a = ({ target }) => console.log(target);
|
||||
a({ target: "I am a target" });
|
||||
6
test/fixtures/syntax/arrow-functions/destructuring-parameters/expected.js
vendored
Normal file
6
test/fixtures/syntax/arrow-functions/destructuring-parameters/expected.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
var a = function (_ref) {
|
||||
var target = _ref.target;
|
||||
return console.log(target);
|
||||
};
|
||||
a({ target: "I am a target" });
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"throws": "Line 2: Unexpected token ILLEGAL"
|
||||
"throws": "Unexpected character '@'"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user