fix remaining issues in estree port

This commit is contained in:
Sebastian McKenzie
2015-03-19 02:59:44 +11:00
parent 0e68b6ca11
commit 4ac1a856ae
9 changed files with 36 additions and 33 deletions

View File

@@ -79,9 +79,7 @@ export function ImportDeclaration(node, print) {
this.push(", ");
}
var isDefault = t.isSpecifierDefault(spec);
if (!isDefault && spec.type !== "ImportNamespaceSpecifier" && !foundImportSpecifier) {
if (!t.isSpecifierDefault(spec) && !foundImportSpecifier) {
foundImportSpecifier = true;
this.push("{ ");
}

View File

@@ -215,17 +215,15 @@ export default class DefaultFormatter {
}
exportAllDeclaration(node, nodes) {
var nodes = [];
var ref = this.getExternalReference(node, nodes);
nodes.push(this.buildExportsWildcard(ref, node));
return nodes;
}
exportSpecifier(specifier, node, nodes) {
if (node.source) {
var ref = this.getExternalReference(node, nodes);
if (t.isSpecifierDefault(specifier) && !this.noInteropRequireExport) {
if (specifier.local.name === "default" && !this.noInteropRequireExport) {
// importing a default so we need to normalize it
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
} else {

View File

@@ -2,6 +2,14 @@ import * as t from "../../../types";
export { check } from "../internal/modules";
function keepBlockHoist(node, nodes) {
if (node._blockHoist) {
for (let i = 0; i < nodes.length; i++) {
nodes[i]._blockHoist = node._blockHoist;
}
}
}
export function ImportDeclaration(node, parent, scope, file) {
// flow type
if (node.isType) return;
@@ -27,12 +35,14 @@ export function ImportDeclaration(node, parent, scope, file) {
export function ExportAllDeclaration(node, parent, scope, file) {
var nodes = [];
file.moduleFormatter.exportAllDeclaration(node, nodes, parent);
keepBlockHoist(node, nodes);
return nodes;
}
export function ExportDefaultDeclaration(node, parent, scope, file) {
var nodes = [];
file.moduleFormatter.exportDeclaration(node, nodes, parent);
keepBlockHoist(node, nodes);
return nodes;
}
@@ -57,11 +67,7 @@ export function ExportNamedDeclaration(node, parent, scope, file) {
}
}
if (node._blockHoist) {
for (let i = 0; i < nodes.length; i++) {
nodes[i]._blockHoist = node._blockHoist;
}
}
keepBlockHoist(node, nodes);
return nodes;
}

View File

@@ -9,7 +9,7 @@ export var metadata = {
};
export function manipulateOptions(opts) {
if (opts.whitelist.length) opts.whitelist.push("es6.destructuring");
if (opts.whitelist) opts.whitelist.push("es6.destructuring");
}
var hasSpread = function (node) {

View File

@@ -11,6 +11,22 @@ export function ForOfStatement(node, parent, scope, file) {
export { ForOfStatement as ForInStatement };
export function MethodDefinition(node) {
if (node.kind !== "constructor") {
// get constructor() {}
var isConstructor = !node.computed && t.isIdentifier(node.key, { name: "constructor" });
// get ["constructor"]() {}
isConstructor ||= t.isLiteral(node.key, { value: "constructor" });
if (isConstructor) {
throw this.errorWithNode(messages.get("classesIllegalConstructorKind"));
}
}
Property.apply(this, arguments);
}
export function Property(node, parent, scope, file) {
if (node.kind === "set") {
if (node.value.params.length !== 1) {
@@ -24,8 +40,6 @@ export function Property(node, parent, scope, file) {
}
}
export { Property as MethodDefinition };
export function BlockStatement(node) {
for (var i = 0; i < node.body.length; i++) {
var bodyNode = node.body[i];