more updates to estree and new acorn
This commit is contained in:
parent
df7524d909
commit
6a1b33b443
7
Makefile
7
Makefile
@ -8,7 +8,7 @@ BABEL_CMD = node_modules/babel/bin/babel
|
|||||||
|
|
||||||
export NODE_ENV = test
|
export NODE_ENV = test
|
||||||
|
|
||||||
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser publish build bootstrap publish-core publish-runtime build-core watch-core build-core-test
|
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser test-parser publish build bootstrap publish-core publish-runtime build-core watch-core build-core-test
|
||||||
|
|
||||||
build-core:
|
build-core:
|
||||||
node $(BABEL_CMD) src/babel --out-dir lib/babel --copy-files
|
node $(BABEL_CMD) src/babel --out-dir lib/babel --copy-files
|
||||||
@ -42,7 +42,7 @@ clean:
|
|||||||
test-clean:
|
test-clean:
|
||||||
rm -rf test/tmp
|
rm -rf test/tmp
|
||||||
|
|
||||||
test:
|
test: test-parser
|
||||||
node $(MOCHA_CMD)
|
node $(MOCHA_CMD)
|
||||||
make test-clean
|
make test-clean
|
||||||
|
|
||||||
@ -55,6 +55,9 @@ test-cov:
|
|||||||
make build-core-test
|
make build-core-test
|
||||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||||
|
|
||||||
|
test-parser:
|
||||||
|
node vendor/acorn/test/run.js
|
||||||
|
|
||||||
test-travis: bootstrap build test
|
test-travis: bootstrap build test
|
||||||
|
|
||||||
test-browser:
|
test-browser:
|
||||||
|
|||||||
@ -17,7 +17,6 @@ program.option("-p, --print [code]", "Evaluate script and print result");
|
|||||||
program.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
|
program.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
|
||||||
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]");
|
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]");
|
||||||
program.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
|
program.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
|
||||||
program.option("-g, --playground", "Enable playground support");
|
|
||||||
program.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
program.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||||
program.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
program.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
||||||
program.option("-o, --optional [optional]", "List of optional transformers to enable", util.list);
|
program.option("-o, --optional [optional]", "List of optional transformers to enable", util.list);
|
||||||
@ -32,7 +31,6 @@ program.parse(process.argv);
|
|||||||
babel.register({
|
babel.register({
|
||||||
experimental: program.experimental,
|
experimental: program.experimental,
|
||||||
extensions: program.extensions,
|
extensions: program.extensions,
|
||||||
playground: program.playground,
|
|
||||||
blacklist: program.blacklist,
|
blacklist: program.blacklist,
|
||||||
whitelist: program.whitelist,
|
whitelist: program.whitelist,
|
||||||
optional: program.optional,
|
optional: program.optional,
|
||||||
@ -47,8 +45,7 @@ var _eval = function (code, filename) {
|
|||||||
blacklist: ["useStrict"].concat(program.blacklist || []),
|
blacklist: ["useStrict"].concat(program.blacklist || []),
|
||||||
whitelist: program.whitelist,
|
whitelist: program.whitelist,
|
||||||
optional: program.optional,
|
optional: program.optional,
|
||||||
experimental: program.experimental,
|
experimental: program.experimental
|
||||||
playground: program.playground
|
|
||||||
}).code;
|
}).code;
|
||||||
|
|
||||||
return vm.runInThisContext(code, {
|
return vm.runInThisContext(code, {
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import fs from "fs";
|
|||||||
export { util };
|
export { util };
|
||||||
export { canCompile } from "../util";
|
export { canCompile } from "../util";
|
||||||
|
|
||||||
export { default as acorn } from "../../acorn";
|
export { default as acorn } from "../../../vendor/acorn";
|
||||||
export { default as Transformer } from "../transformation/transformer";
|
export { default as Transformer } from "../transformation/transformer";
|
||||||
export { default as transform } from "../transformation";
|
export { default as transform } from "../transformation";
|
||||||
export { default as traverse } from "../traversal";
|
export { default as traverse } from "../traversal";
|
||||||
|
|||||||
@ -57,6 +57,10 @@ export function ThisExpression() {
|
|||||||
this.push("this");
|
this.push("this");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function SuperExpression() {
|
||||||
|
this.push("super");
|
||||||
|
}
|
||||||
|
|
||||||
export function CallExpression(node, print) {
|
export function CallExpression(node, print) {
|
||||||
print(node.callee);
|
print(node.callee);
|
||||||
|
|
||||||
|
|||||||
@ -21,11 +21,13 @@ export function _method(node, print) {
|
|||||||
var kind = node.kind;
|
var kind = node.kind;
|
||||||
var key = node.key;
|
var key = node.key;
|
||||||
|
|
||||||
if (!kind || kind === "init") {
|
if (kind === "method" || kind === "init") {
|
||||||
if (value.generator) {
|
if (value.generator) {
|
||||||
this.push("*");
|
this.push("*");
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (kind === "get" || kind === "set") {
|
||||||
this.push(kind + " ");
|
this.push(kind + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,13 +2,17 @@ import each from "lodash/collection/each";
|
|||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
export function ImportSpecifier(node, print) {
|
export function ImportSpecifier(node, print) {
|
||||||
if (t.isSpecifierDefault(node)) {
|
print(node.local);
|
||||||
print(t.getSpecifierName(node));
|
if (node.imported && node.local !== node.imported) {
|
||||||
} else {
|
this.push(" as ");
|
||||||
return ExportSpecifier.apply(this, arguments);
|
print(node.imported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ImportDefaultSpecifier(node, print) {
|
||||||
|
print(node.local);
|
||||||
|
}
|
||||||
|
|
||||||
export function ExportSpecifier(node, print) {
|
export function ExportSpecifier(node, print) {
|
||||||
print(node.local);
|
print(node.local);
|
||||||
if (node.exported && node.local !== node.exported) {
|
if (node.exported && node.local !== node.exported) {
|
||||||
@ -17,8 +21,8 @@ export function ExportSpecifier(node, print) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExportAllDeclaration(node, source) {
|
export function ExportAllDeclaration(node, print) {
|
||||||
this.push("export * from");
|
this.push("export * from ");
|
||||||
print(node.source);
|
print(node.source);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
@ -40,17 +44,13 @@ function ExportDeclaration(node, print) {
|
|||||||
print(node.declaration);
|
print(node.declaration);
|
||||||
if (t.isStatement(node.declaration)) return;
|
if (t.isStatement(node.declaration)) return;
|
||||||
} else {
|
} else {
|
||||||
if (specifiers.length === 1 && t.isExportBatchSpecifier(specifiers[0])) {
|
this.push("{");
|
||||||
print(specifiers[0]);
|
if (specifiers.length) {
|
||||||
} else {
|
this.space();
|
||||||
this.push("{");
|
print.join(specifiers, { separator: ", " });
|
||||||
if (specifiers.length) {
|
this.space();
|
||||||
this.space();
|
|
||||||
print.join(specifiers, { separator: ", " });
|
|
||||||
this.space();
|
|
||||||
}
|
|
||||||
this.push("}");
|
|
||||||
}
|
}
|
||||||
|
this.push("}");
|
||||||
|
|
||||||
if (node.source) {
|
if (node.source) {
|
||||||
this.push(" from ");
|
this.push(" from ");
|
||||||
@ -81,7 +81,7 @@ export function ImportDeclaration(node, print) {
|
|||||||
|
|
||||||
var isDefault = t.isSpecifierDefault(spec);
|
var isDefault = t.isSpecifierDefault(spec);
|
||||||
|
|
||||||
if (!isDefault && spec.type !== "ImportBatchSpecifier" && !foundImportSpecifier) {
|
if (!isDefault && spec.type !== "ImportNamespaceSpecifier" && !foundImportSpecifier) {
|
||||||
foundImportSpecifier = true;
|
foundImportSpecifier = true;
|
||||||
this.push("{ ");
|
this.push("{ ");
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ export function ImportDeclaration(node, print) {
|
|||||||
this.semicolon();
|
this.semicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ImportBatchSpecifier(node, print) {
|
export function ImportNamespaceSpecifier(node, print) {
|
||||||
this.push("* as ");
|
this.push("* as ");
|
||||||
print(node.name);
|
print(node.name);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -212,7 +212,7 @@ export function PrivateDeclaration(node, print) {
|
|||||||
|
|
||||||
export function VariableDeclarator(node, print) {
|
export function VariableDeclarator(node, print) {
|
||||||
print(node.id);
|
print(node.id);
|
||||||
print(node.id.typeAnnotation);
|
//print(node.id.typeAnnotation);
|
||||||
if (node.init) {
|
if (node.init) {
|
||||||
this.space();
|
this.space();
|
||||||
this.push("=");
|
this.push("=");
|
||||||
|
|||||||
@ -81,7 +81,7 @@ export default class Whitespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endToken && endToken.type.type === "eof") {
|
if (endToken && endToken.type.label === "eof") {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
var lines = this.getNewlinesBetween(startToken, endToken);
|
var lines = this.getNewlinesBetween(startToken, endToken);
|
||||||
|
|||||||
@ -1,25 +1,30 @@
|
|||||||
import normalizeAst from "./normalize-ast";
|
import normalizeAst from "./normalize-ast";
|
||||||
import estraverse from "estraverse";
|
import estraverse from "estraverse";
|
||||||
import codeFrame from "./code-frame";
|
import codeFrame from "./code-frame";
|
||||||
import acorn from "../../acorn";
|
import acorn from "../../../vendor/acorn";
|
||||||
|
|
||||||
export default function (opts, code, callback) {
|
export default function (opts, code, callback) {
|
||||||
try {
|
try {
|
||||||
var comments = [];
|
var comments = [];
|
||||||
var tokens = [];
|
var tokens = [];
|
||||||
|
|
||||||
var ast = acorn.parse(code, {
|
var parseOpts = {
|
||||||
allowImportExportEverywhere: opts.looseModules,
|
allowImportExportEverywhere: opts.looseModules,
|
||||||
allowReturnOutsideFunction: opts.looseModules,
|
allowReturnOutsideFunction: opts.looseModules,
|
||||||
transformers: opts.transformers || {},
|
|
||||||
ecmaVersion: 6,
|
ecmaVersion: 6,
|
||||||
strictMode: opts.strictMode,
|
strictMode: opts.strictMode,
|
||||||
onComment: comments,
|
onComment: comments,
|
||||||
locations: true,
|
locations: true,
|
||||||
plugins: opts.plugins || [],
|
features: opts.features || {},
|
||||||
|
plugins: opts.plugins || {},
|
||||||
onToken: tokens,
|
onToken: tokens,
|
||||||
ranges: true
|
ranges: true
|
||||||
});
|
};
|
||||||
|
|
||||||
|
parseOpts.plugins.flow = true;
|
||||||
|
parseOpts.plugins.jsx = true;
|
||||||
|
|
||||||
|
var ast = acorn.parse(code, parseOpts);
|
||||||
|
|
||||||
estraverse.attachComments(ast, comments, tokens);
|
estraverse.attachComments(ast, comments, tokens);
|
||||||
|
|
||||||
|
|||||||
@ -28,4 +28,26 @@ def("RestElement")
|
|||||||
.build("argument")
|
.build("argument")
|
||||||
.field("argument", def("expression"));
|
.field("argument", def("expression"));
|
||||||
|
|
||||||
|
def("ExportDefaultDeclaration")
|
||||||
|
.bases("Declaration")
|
||||||
|
.build("declaration")
|
||||||
|
.field("declaration", or(
|
||||||
|
def("Declaration"),
|
||||||
|
def("Expression"),
|
||||||
|
null
|
||||||
|
));
|
||||||
|
|
||||||
|
def("ExportNamedDeclaration")
|
||||||
|
.bases("Declaration")
|
||||||
|
.build("declaration")
|
||||||
|
.field("declaration", or(
|
||||||
|
def("Declaration"),
|
||||||
|
def("Expression"),
|
||||||
|
null
|
||||||
|
))
|
||||||
|
.field("specifiers", [or(
|
||||||
|
def("ExportSpecifier")
|
||||||
|
)])
|
||||||
|
.field("source", or(def("ModuleSpecifier"), null));
|
||||||
|
|
||||||
types.finalize();
|
types.finalize();
|
||||||
|
|||||||
@ -21,9 +21,6 @@ import path from "path";
|
|||||||
import each from "lodash/collection/each";
|
import each from "lodash/collection/each";
|
||||||
import * as t from "../../types";
|
import * as t from "../../types";
|
||||||
|
|
||||||
import "../../parser/jsx";
|
|
||||||
import "../../parser/flow";
|
|
||||||
|
|
||||||
var checkTransformerVisitor = {
|
var checkTransformerVisitor = {
|
||||||
enter(node, parent, scope, state) {
|
enter(node, parent, scope, state) {
|
||||||
checkNode(state.stack, node, scope);
|
checkNode(state.stack, node, scope);
|
||||||
@ -184,7 +181,7 @@ export default class File {
|
|||||||
each(transform.transformers, function (transformer, key) {
|
each(transform.transformers, function (transformer, key) {
|
||||||
var pass = transformers[key] = transformer.buildPass(file);
|
var pass = transformers[key] = transformer.buildPass(file);
|
||||||
|
|
||||||
if (pass.canTransform) {
|
if (pass.canTransform()) {
|
||||||
stack.push(pass);
|
stack.push(pass);
|
||||||
|
|
||||||
if (transformer.metadata.secondPass) {
|
if (transformer.metadata.secondPass) {
|
||||||
@ -270,14 +267,14 @@ export default class File {
|
|||||||
if (!id) {
|
if (!id) {
|
||||||
id = this.dynamicImportIds[name] = this.scope.generateUidIdentifier(name);
|
id = this.dynamicImportIds[name] = this.scope.generateUidIdentifier(name);
|
||||||
|
|
||||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
var specifiers = [t.importDefaultSpecifier(id)];
|
||||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||||
declar._blockHoist = 3;
|
declar._blockHoist = 3;
|
||||||
|
|
||||||
this.dynamicImported.push(declar);
|
this.dynamicImported.push(declar);
|
||||||
if (noDefault) this.dynamicImportedNoDefault.push(declar);
|
if (noDefault) this.dynamicImportedNoDefault.push(declar);
|
||||||
|
|
||||||
if (this.transformers["es6.modules"].canTransform) {
|
if (this.transformers["es6.modules"].canTransform()) {
|
||||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||||
} else {
|
} else {
|
||||||
this.dynamicImports.push(declar);
|
this.dynamicImports.push(declar);
|
||||||
@ -390,24 +387,14 @@ export default class File {
|
|||||||
plugins: {}
|
plugins: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
var transformers = parseOpts.transformers = {};
|
var features = parseOpts.features = {};
|
||||||
for (var key in this.transformers) {
|
for (var key in this.transformers) {
|
||||||
var transformer = this.transformers[key];
|
var transformer = this.transformers[key];
|
||||||
|
features[key] = transformer.canTransform();
|
||||||
transformers[key] = transformer.canTransform;
|
|
||||||
|
|
||||||
if (transformer.parser) {
|
|
||||||
parseOpts.plugins[key] = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseOpts.looseModules = this.isLoose("es6.modules");
|
parseOpts.looseModules = this.isLoose("es6.modules");
|
||||||
parseOpts.strictMode = transformers.strict;
|
parseOpts.strictMode = features.strict;
|
||||||
|
|
||||||
if (!opts.standardOnly) {
|
|
||||||
parseOpts.plugins.jsx = true;
|
|
||||||
parseOpts.plugins.flow = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -441,7 +428,7 @@ export default class File {
|
|||||||
this.lastStatements = t.getLastStatements(ast.program);
|
this.lastStatements = t.getLastStatements(ast.program);
|
||||||
|
|
||||||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||||
if (modFormatter.init && this.transformers["es6.modules"].canTransform) {
|
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
||||||
modFormatter.init();
|
modFormatter.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -252,8 +252,8 @@ export default function (exports, opts) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.ExportDeclaration = function (node, parent, scope, file) {
|
exports.ExportDefaultDeclaration = function (node, parent, scope, file) {
|
||||||
if (node.default && react.isCreateClass(node.declaration)) {
|
if (react.isCreateClass(node.declaration)) {
|
||||||
addDisplayName(file.opts.basename, node.declaration);
|
addDisplayName(file.opts.basename, node.declaration);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -5,16 +5,12 @@ import * as t from "../../types";
|
|||||||
|
|
||||||
|
|
||||||
function isIllegalBareSuper(node, parent) {
|
function isIllegalBareSuper(node, parent) {
|
||||||
if (!isSuper(node, parent)) return false;
|
if (!t.isSuperExpression(node)) return false;
|
||||||
if (t.isMemberExpression(parent, { computed: false })) return false;
|
if (t.isMemberExpression(parent, { computed: false })) return false;
|
||||||
if (t.isCallExpression(parent, { callee: node })) return false;
|
if (t.isCallExpression(parent, { callee: node })) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSuper(node, parent) {
|
|
||||||
return t.isIdentifier(node, { name: "super" }) && t.isReferenced(node, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
var visitor = {
|
var visitor = {
|
||||||
enter(node, parent, scope, state) {
|
enter(node, parent, scope, state) {
|
||||||
var topLevel = state.topLevel;
|
var topLevel = state.topLevel;
|
||||||
@ -193,13 +189,13 @@ export default class ReplaceSupers {
|
|||||||
|
|
||||||
looseHandle(path: TraversalPath, getThisReference: Function) {
|
looseHandle(path: TraversalPath, getThisReference: Function) {
|
||||||
var node = path.node;
|
var node = path.node;
|
||||||
if (path.isIdentifier({ name: "super" })) {
|
if (path.isSuperExpression()) {
|
||||||
this.hasSuper = true;
|
this.hasSuper = true;
|
||||||
return this.getLooseSuperProperty(node, path.parent);
|
return this.getLooseSuperProperty(node, path.parent);
|
||||||
} else if (path.isCallExpression()) {
|
} else if (path.isCallExpression()) {
|
||||||
var callee = node.callee;
|
var callee = node.callee;
|
||||||
if (!t.isMemberExpression(callee)) return;
|
if (!t.isMemberExpression(callee)) return;
|
||||||
if (callee.object.name !== "super") return;
|
if (!t.isSuperExpression(callee.object)) return;
|
||||||
|
|
||||||
// super.test(); -> objectRef.prototype.MethodName.call(this);
|
// super.test(); -> objectRef.prototype.MethodName.call(this);
|
||||||
this.hasSuper = true;
|
this.hasSuper = true;
|
||||||
@ -228,7 +224,7 @@ export default class ReplaceSupers {
|
|||||||
|
|
||||||
if (t.isCallExpression(node)) {
|
if (t.isCallExpression(node)) {
|
||||||
var callee = node.callee;
|
var callee = node.callee;
|
||||||
if (isSuper(callee, node)) {
|
if (t.isSuperExpression(callee)) {
|
||||||
// super(); -> _get(Object.getPrototypeOf(objectRef), "MethodName", this).call(this);
|
// super(); -> _get(Object.getPrototypeOf(objectRef), "MethodName", this).call(this);
|
||||||
property = methodNode.key;
|
property = methodNode.key;
|
||||||
computed = methodNode.computed;
|
computed = methodNode.computed;
|
||||||
@ -241,17 +237,17 @@ export default class ReplaceSupers {
|
|||||||
var methodName = methodNode.key.name || "METHOD_NAME";
|
var methodName = methodNode.key.name || "METHOD_NAME";
|
||||||
throw this.file.errorWithNode(node, messages.get("classesIllegalSuperCall", methodName));
|
throw this.file.errorWithNode(node, messages.get("classesIllegalSuperCall", methodName));
|
||||||
}
|
}
|
||||||
} else if (t.isMemberExpression(callee) && isSuper(callee.object, callee)) {
|
} else if (t.isMemberExpression(callee) && t.isSuperExpression(callee.object)) {
|
||||||
// super.test(); -> _get(Object.getPrototypeOf(objectRef.prototype), "test", this).call(this);
|
// super.test(); -> _get(Object.getPrototypeOf(objectRef.prototype), "test", this).call(this);
|
||||||
property = callee.property;
|
property = callee.property;
|
||||||
computed = callee.computed;
|
computed = callee.computed;
|
||||||
args = node.arguments;
|
args = node.arguments;
|
||||||
}
|
}
|
||||||
} else if (t.isMemberExpression(node) && isSuper(node.object, node)) {
|
} else if (t.isMemberExpression(node) && t.isSuperExpression(node.object)) {
|
||||||
// super.name; -> _get(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
// super.name; -> _get(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
||||||
property = node.property;
|
property = node.property;
|
||||||
computed = node.computed;
|
computed = node.computed;
|
||||||
} else if (t.isAssignmentExpression(node) && isSuper(node.left.object, node.left) && methodNode.kind === "set") {
|
} else if (t.isAssignmentExpression(node) && t.isSuperExpression(node.left.object) && methodNode.kind === "set") {
|
||||||
// super.name = "val"; -> _set(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
// super.name = "val"; -> _set(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
||||||
this.hasSuper = true;
|
this.hasSuper = true;
|
||||||
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
|
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import * as messages from "../../messages";
|
import * as messages from "../../messages";
|
||||||
|
import traverse from "../../traversal";
|
||||||
import extend from "lodash/object/extend";
|
import extend from "lodash/object/extend";
|
||||||
import object from "../../helpers/object";
|
import object from "../../helpers/object";
|
||||||
import * as util from "../../util";
|
import * as util from "../../util";
|
||||||
@ -51,17 +52,17 @@ var importsVisitor = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var exportsVisitor = {
|
var exportsVisitor = traverse.explode({
|
||||||
ExportDeclaration: {
|
ExportDeclaration: {
|
||||||
enter(node, parent, scope, formatter) {
|
enter(node, parent, scope, formatter) {
|
||||||
var declar = this.get("declaration");
|
|
||||||
formatter.hasLocalImports = true;
|
formatter.hasLocalImports = true;
|
||||||
|
|
||||||
|
var declar = this.get("declaration");
|
||||||
if (declar.isStatement()) {
|
if (declar.isStatement()) {
|
||||||
extend(formatter.localExports, declar.getBindingIdentifiers());
|
extend(formatter.localExports, declar.getBindingIdentifiers());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node.default) {
|
if (!t.isExportDefaultDeclaration(node)) {
|
||||||
formatter.hasNonDefaultExports = true;
|
formatter.hasNonDefaultExports = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ var exportsVisitor = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
export default class DefaultFormatter {
|
export default class DefaultFormatter {
|
||||||
constructor(file) {
|
constructor(file) {
|
||||||
@ -94,14 +95,16 @@ export default class DefaultFormatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
doDefaultExportInterop(node) {
|
doDefaultExportInterop(node) {
|
||||||
return node.default && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
return t.isExportDefaultDeclaration(node) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
||||||
}
|
}
|
||||||
|
|
||||||
bumpImportOccurences(node) {
|
bumpImportOccurences(node) {
|
||||||
var source = node.source.value;
|
var source = node.source.value;
|
||||||
var occurs = this.localImportOccurences;
|
var occurs = this.localImportOccurences;
|
||||||
occurs[source] ||= 0;
|
occurs[source] ||= 0;
|
||||||
occurs[source] += node.specifiers.length;
|
if (node.specifiers) {
|
||||||
|
occurs[source] += node.specifiers.length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLocalExports() {
|
getLocalExports() {
|
||||||
@ -211,31 +214,29 @@ 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) {
|
exportSpecifier(specifier, node, nodes) {
|
||||||
if (node.source) {
|
if (node.source) {
|
||||||
var ref = this.getExternalReference(node, nodes);
|
var ref = this.getExternalReference(node, nodes);
|
||||||
|
|
||||||
if (t.isExportBatchSpecifier(specifier)) {
|
if (t.isSpecifierDefault(specifier) && !this.noInteropRequireExport) {
|
||||||
// export * from "foo";
|
// importing a default so we need to normalize it
|
||||||
nodes.push(this.buildExportsWildcard(ref, node));
|
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||||
} else {
|
} else {
|
||||||
if (t.isSpecifierDefault(specifier) && !this.noInteropRequireExport) {
|
ref = t.memberExpression(ref, specifier.local);
|
||||||
// importing a default so we need to normalize it
|
|
||||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
|
||||||
} else {
|
|
||||||
ref = t.memberExpression(ref, t.getSpecifierId(specifier));
|
|
||||||
}
|
|
||||||
|
|
||||||
// export { foo } from "test";
|
|
||||||
nodes.push(this.buildExportsAssignment(
|
|
||||||
node.local,
|
|
||||||
ref,
|
|
||||||
node
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// export { foo } from "test";
|
||||||
|
nodes.push(this.buildExportsAssignment(specifier.exported, ref, node));
|
||||||
} else {
|
} else {
|
||||||
// export { foo };
|
// export { foo };
|
||||||
nodes.push(this.buildExportsAssignment(specifier.local, specifier.exported, node));
|
nodes.push(this.buildExportsAssignment(specifier.exported, specifier.local, node));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +260,7 @@ export default class DefaultFormatter {
|
|||||||
|
|
||||||
var id = declar.id;
|
var id = declar.id;
|
||||||
|
|
||||||
if (node.default) {
|
if (t.isExportDefaultDeclaration(node)) {
|
||||||
id = t.identifier("default");
|
id = t.identifier("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -74,18 +74,20 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
||||||
// Prevent unnecessary renaming of dynamic imports.
|
// Prevent unnecessary renaming of dynamic imports.
|
||||||
this.ids[node.source.value] = ref;
|
this.ids[node.source.value] = ref;
|
||||||
} else if (t.isImportBatchSpecifier(specifier)) {
|
} else if (t.isImportNamespaceSpecifier(specifier)) {
|
||||||
// import * as bar from "foo";
|
// import * as bar from "foo";
|
||||||
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||||
// import foo from "foo";
|
// import foo from "foo";
|
||||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||||
} else {
|
} else {
|
||||||
// import {foo} from "foo";
|
// import { foo } from "foo";
|
||||||
ref = t.memberExpression(ref, t.getSpecifierId(specifier), false);
|
var imported = specifier.imported;
|
||||||
|
if (t.isSpecifierDefault(specifier)) imported = t.identifier("default");
|
||||||
|
ref = t.memberExpression(ref, imported);
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.push(t.variableDeclaration("var", [
|
nodes.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(node.local, ref)
|
t.variableDeclarator(specifier.local, ref)
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
importSpecifier(specifier, node, nodes) {
|
importSpecifier(specifier, node, nodes) {
|
||||||
var variableName = node.local;
|
var variableName = specifier.local;
|
||||||
|
|
||||||
var ref = this.getExternalReference(node, nodes);
|
var ref = this.getExternalReference(node, nodes);
|
||||||
|
|
||||||
@ -33,8 +33,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
}
|
}
|
||||||
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(variableName, ref)]));
|
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(variableName, ref)]));
|
||||||
} else {
|
} else {
|
||||||
if (specifier.type === "ImportBatchSpecifier") {
|
if (t.isImportNamespaceSpecifier(specifier)) {
|
||||||
|
|
||||||
if (!this.noInteropRequireImport) {
|
if (!this.noInteropRequireImport) {
|
||||||
ref = t.callExpression(this.file.addHelper("interop-require-wildcard"), [ref]);
|
ref = t.callExpression(this.file.addHelper("interop-require-wildcard"), [ref]);
|
||||||
}
|
}
|
||||||
@ -48,7 +47,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
|||||||
nodes.push(t.variableDeclaration("var", [
|
nodes.push(t.variableDeclaration("var", [
|
||||||
t.variableDeclarator(
|
t.variableDeclarator(
|
||||||
variableName,
|
variableName,
|
||||||
t.memberExpression(ref, t.getSpecifierId(specifier))
|
t.memberExpression(ref, specifier.imported)
|
||||||
)
|
)
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ export default class IgnoreFormatter {
|
|||||||
if (declar) nodes.push(t.inherits(declar, node));
|
if (declar) nodes.push(t.inherits(declar, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exportAllDeclaration() {}
|
||||||
importDeclaration() {}
|
importDeclaration() {}
|
||||||
importSpecifier() {}
|
importSpecifier() {}
|
||||||
exportSpecifier() {}
|
exportSpecifier() {}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"blacklist": ["useStrict", "es6.blockScoping", "regenerator"],
|
"blacklist": ["useStrict", "es6.blockScoping", "regenerator"],
|
||||||
"loose": ["es6.modules"]
|
"loose": ["es6.modules"],
|
||||||
|
"breakConfig": true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,12 +12,10 @@ export default class TransformerPass {
|
|||||||
this.shouldRun = !transformer.check;
|
this.shouldRun = !transformer.check;
|
||||||
this.handlers = transformer.handlers;
|
this.handlers = transformer.handlers;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
this.ran = false;
|
||||||
this.canTransform = this._canTransform();
|
|
||||||
this.ran = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_canTransform(): boolean {
|
canTransform(): boolean {
|
||||||
var transformer = this.transformer;
|
var transformer = this.transformer;
|
||||||
|
|
||||||
var opts = this.file.opts;
|
var opts = this.file.opts;
|
||||||
@ -34,9 +32,6 @@ export default class TransformerPass {
|
|||||||
var whitelist = opts.whitelist;
|
var whitelist = opts.whitelist;
|
||||||
if (whitelist.length) return includes(whitelist, key);
|
if (whitelist.length) return includes(whitelist, key);
|
||||||
|
|
||||||
// react
|
|
||||||
if (transformer.metadata.react && opts.react) return true;
|
|
||||||
|
|
||||||
// experimental
|
// experimental
|
||||||
if (transformer.metadata.experimental && opts.experimental) return true;
|
if (transformer.metadata.experimental && opts.experimental) return true;
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import isFunction from "lodash/lang/isFunction";
|
|||||||
import traverse from "../traversal";
|
import traverse from "../traversal";
|
||||||
import isObject from "lodash/lang/isObject";
|
import isObject from "lodash/lang/isObject";
|
||||||
import assign from "lodash/object/assign";
|
import assign from "lodash/object/assign";
|
||||||
import acorn from "../../../../acorn";
|
import acorn from "../../../vendor/acorn";
|
||||||
import File from "./file";
|
import File from "./file";
|
||||||
import each from "lodash/collection/each";
|
import each from "lodash/collection/each";
|
||||||
|
|
||||||
@ -33,10 +33,6 @@ export default class Transformer {
|
|||||||
this.handlers = this.normalize(transformer);
|
this.handlers = this.normalize(transformer);
|
||||||
this.opts ||= {};
|
this.opts ||= {};
|
||||||
this.key = transformerKey;
|
this.key = transformerKey;
|
||||||
|
|
||||||
if (this.parser) {
|
|
||||||
acorn.plugins[key] = this.parser(acorn.Parser.prototype, acorn.tokTypes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
normalize(transformer: Object): Object {
|
normalize(transformer: Object): Object {
|
||||||
|
|||||||
@ -44,7 +44,7 @@ export function check(node) {
|
|||||||
export function VariableDeclaration(node, parent, scope, file) {
|
export function VariableDeclaration(node, parent, scope, file) {
|
||||||
if (!isLet(node, parent)) return;
|
if (!isLet(node, parent)) return;
|
||||||
|
|
||||||
if (isLetInitable(node) && file.transformers["es6.blockScopingTDZ"].canTransform) {
|
if (isLetInitable(node) && file.transformers["es6.blockScopingTDZ"].canTransform()) {
|
||||||
var nodes = [node];
|
var nodes = [node];
|
||||||
|
|
||||||
for (var i = 0; i < node.declarations.length; i++) {
|
for (var i = 0; i < node.declarations.length; i++) {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ var verifyConstructorVisitor = traverse.explode({
|
|||||||
|
|
||||||
CallExpression: {
|
CallExpression: {
|
||||||
enter(node, parent, scope, state) {
|
enter(node, parent, scope, state) {
|
||||||
if (this.get("callee").isIdentifier({ name: "super" })) {
|
if (this.get("callee").isSuperExpression()) {
|
||||||
state.hasBareSuper = true;
|
state.hasBareSuper = true;
|
||||||
|
|
||||||
if (!state.hasSuper) {
|
if (!state.hasSuper) {
|
||||||
@ -275,7 +275,7 @@ class ClassTransformer {
|
|||||||
|
|
||||||
var kind = node.kind;
|
var kind = node.kind;
|
||||||
|
|
||||||
if (kind === "") {
|
if (kind === "method") {
|
||||||
nameMethod.property(node, this.file, this.scope);
|
nameMethod.property(node, this.file, this.scope);
|
||||||
|
|
||||||
if (this.isLoose) {
|
if (this.isLoose) {
|
||||||
|
|||||||
@ -25,7 +25,15 @@ export function ImportDeclaration(node, parent, scope, file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ExportAllDeclaration(node, parent, scope, file) {
|
export function ExportAllDeclaration(node, parent, scope, file) {
|
||||||
return file.moduleFormatter.exportAllDeclaration(node, parent);
|
var nodes = [];
|
||||||
|
file.moduleFormatter.exportAllDeclaration(node, nodes, parent);
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ExportDefaultDeclaration(node, parent, scope, file) {
|
||||||
|
var nodes = [];
|
||||||
|
file.moduleFormatter.exportDeclaration(node, nodes, parent);
|
||||||
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExportNamedDeclaration(node, parent, scope, file) {
|
export function ExportNamedDeclaration(node, parent, scope, file) {
|
||||||
@ -33,7 +41,6 @@ export function ExportNamedDeclaration(node, parent, scope, file) {
|
|||||||
if (this.get("declaration").isTypeAlias()) return;
|
if (this.get("declaration").isTypeAlias()) return;
|
||||||
|
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
var i;
|
|
||||||
|
|
||||||
if (node.declaration) {
|
if (node.declaration) {
|
||||||
// make sure variable exports have an initializer
|
// make sure variable exports have an initializer
|
||||||
@ -45,13 +52,13 @@ export function ExportNamedDeclaration(node, parent, scope, file) {
|
|||||||
|
|
||||||
file.moduleFormatter.exportDeclaration(node, nodes, parent);
|
file.moduleFormatter.exportDeclaration(node, nodes, parent);
|
||||||
} else if (node.specifiers) {
|
} else if (node.specifiers) {
|
||||||
for (i = 0; i < node.specifiers.length; i++) {
|
for (let i = 0; i < node.specifiers.length; i++) {
|
||||||
file.moduleFormatter.exportSpecifier(node.specifiers[i], node, nodes, parent);
|
file.moduleFormatter.exportSpecifier(node.specifiers[i], node, nodes, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node._blockHoist) {
|
if (node._blockHoist) {
|
||||||
for (i = 0; i < nodes.length; i++) {
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
nodes[i]._blockHoist = node._blockHoist;
|
nodes[i]._blockHoist = node._blockHoist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import ReplaceSupers from "../../helpers/replace-supers";
|
import ReplaceSupers from "../../helpers/replace-supers";
|
||||||
import * as t from "../../../types";
|
import * as t from "../../../types";
|
||||||
|
|
||||||
export function check(node) {
|
export var check = t.isSuperExpression;
|
||||||
return t.isIdentifier(node, { name: "super" });
|
|
||||||
}
|
|
||||||
|
|
||||||
function Property(node, scope, getObjectRef, file) {
|
function Property(node, scope, getObjectRef, file) {
|
||||||
if (!node.method) return;
|
if (!node.method) return;
|
||||||
|
|||||||
@ -62,7 +62,7 @@ exports.Function = function (node, parent, scope, file) {
|
|||||||
param.traverse(iifeVisitor, state);
|
param.traverse(iifeVisitor, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file.transformers["es6.blockScopingTDZ"].canTransform && param.isIdentifier()) {
|
if (file.transformers["es6.blockScopingTDZ"].canTransform() && param.isIdentifier()) {
|
||||||
pushDefNode(param.node, t.identifier("undefined"), i);
|
pushDefNode(param.node, t.identifier("undefined"), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
export var metadata = {
|
||||||
|
experimental: true,
|
||||||
|
optional: true
|
||||||
|
};
|
||||||
|
|
||||||
|
export function check() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
|
"es7.asyncFunctions": require("./es7/async-functions"),
|
||||||
|
|
||||||
strict: require("./other/strict"),
|
strict: require("./other/strict"),
|
||||||
|
|
||||||
_validation: require("./internal/validation"),
|
_validation: require("./internal/validation"),
|
||||||
|
|||||||
@ -5,7 +5,7 @@ export function Program(program, parent, scope, file) {
|
|||||||
program.body = file.dynamicImports.concat(program.body);
|
program.body = file.dynamicImports.concat(program.body);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!file.transformers["es6.modules"].canTransform) return;
|
if (!file.transformers["es6.modules"].canTransform()) return;
|
||||||
|
|
||||||
if (file.moduleFormatter.transform) {
|
if (file.moduleFormatter.transform) {
|
||||||
file.moduleFormatter.transform(program);
|
file.moduleFormatter.transform(program);
|
||||||
|
|||||||
@ -29,8 +29,8 @@ export function ExportDefaultDeclaration(node, parent, scope) {
|
|||||||
|
|
||||||
if (t.isClassDeclaration(declar)) {
|
if (t.isClassDeclaration(declar)) {
|
||||||
// export default class Foo {};
|
// export default class Foo {};
|
||||||
this.node = [getDeclar(), node];
|
|
||||||
node.declaration = declar.id;
|
node.declaration = declar.id;
|
||||||
|
return [getDeclar(), node];
|
||||||
} else if (t.isClassExpression(declar)) {
|
} else if (t.isClassExpression(declar)) {
|
||||||
// export default class {};
|
// export default class {};
|
||||||
var temp = scope.generateUidIdentifier("default");
|
var temp = scope.generateUidIdentifier("default");
|
||||||
@ -59,12 +59,12 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
|||||||
|
|
||||||
if (t.isClassDeclaration(declar)) {
|
if (t.isClassDeclaration(declar)) {
|
||||||
// export class Foo {}
|
// export class Foo {}
|
||||||
node.specifiers = [t.importSpecifier(declar.id, declar.id)];
|
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
|
||||||
node.declaration = null;
|
node.declaration = null;
|
||||||
return [getDeclar(), node];
|
return [getDeclar(), node];
|
||||||
} else if (t.isFunctionDeclaration(declar)) {
|
} else if (t.isFunctionDeclaration(declar)) {
|
||||||
// export function Foo() {}
|
// export function Foo() {}
|
||||||
node.specifiers = [t.importSpecifier(declar.id, declar.id)];
|
node.specifiers = [t.exportSpecifier(declar.id, declar.id)];
|
||||||
node.declaration = null;
|
node.declaration = null;
|
||||||
node._blockHoist = 2;
|
node._blockHoist = 2;
|
||||||
return [getDeclar(), node];
|
return [getDeclar(), node];
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as t from "../../../types";
|
import * as t from "../../../types";
|
||||||
|
|
||||||
export function Program(program, parent, scope, file) {
|
export function Program(program, parent, scope, file) {
|
||||||
if (file.transformers.strict.canTransform) {
|
if (file.transformers.strict.canTransform()) {
|
||||||
var directive = file.get("existingStrictDirective");
|
var directive = file.get("existingStrictDirective");
|
||||||
|
|
||||||
if (!directive) {
|
if (!directive) {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import remapAsyncToGenerator from "../../helpers/remap-async-to-generator";
|
|||||||
import * as t from "../../../types";
|
import * as t from "../../../types";
|
||||||
|
|
||||||
export function manipulateOptions(opts) {
|
export function manipulateOptions(opts) {
|
||||||
opts.experimental = true;
|
opts.optional.push("es7.asyncFunctions");
|
||||||
opts.blacklist.push("regenerator");
|
opts.blacklist.push("regenerator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -199,7 +199,7 @@ export default class Scope {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
generateTempBasedOnNode(node: Object): ?Object {
|
generateTempBasedOnNode(node: Object): ?Object {
|
||||||
if (t.isThisExpression(node)) {
|
if (t.isThisExpression(node) || t.isSuperExpression(node)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -67,6 +67,7 @@
|
|||||||
"SequenceExpression": ["Expression"],
|
"SequenceExpression": ["Expression"],
|
||||||
"TaggedTemplateExpression": ["Expression"],
|
"TaggedTemplateExpression": ["Expression"],
|
||||||
"ThisExpression": ["Expression"],
|
"ThisExpression": ["Expression"],
|
||||||
|
"SuperExpression": ["Expression"],
|
||||||
"UpdateExpression": ["Expression"],
|
"UpdateExpression": ["Expression"],
|
||||||
"VirtualPropertyExpression": ["Expression"],
|
"VirtualPropertyExpression": ["Expression"],
|
||||||
"JSXEmptyExpression": ["Expression"],
|
"JSXEmptyExpression": ["Expression"],
|
||||||
|
|||||||
@ -80,8 +80,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"ImportSpecifier": {
|
"ImportSpecifier": {
|
||||||
"id": null,
|
"local": null,
|
||||||
"name": null
|
"imported": null
|
||||||
},
|
},
|
||||||
|
|
||||||
"LabeledStatement": {
|
"LabeledStatement": {
|
||||||
|
|||||||
@ -38,6 +38,7 @@ getBindingIdentifiers.keys = {
|
|||||||
AssignmentExpression: ["left"],
|
AssignmentExpression: ["left"],
|
||||||
ImportSpecifier: ["local"],
|
ImportSpecifier: ["local"],
|
||||||
ImportNamespaceSpecifier: ["local"],
|
ImportNamespaceSpecifier: ["local"],
|
||||||
|
ImportDefaultSpecifier: ["local"],
|
||||||
VariableDeclarator: ["id"],
|
VariableDeclarator: ["id"],
|
||||||
FunctionDeclaration: ["id"],
|
FunctionDeclaration: ["id"],
|
||||||
FunctionExpression: ["id"],
|
FunctionExpression: ["id"],
|
||||||
|
|||||||
@ -7,102 +7,90 @@ import * as t from "./index";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function isReferenced(node: Object, parent: Object): boolean {
|
export function isReferenced(node: Object, parent: Object): boolean {
|
||||||
// yes: PARENT[NODE]
|
switch (parent.type) {
|
||||||
// yes: NODE.child
|
// yes: PARENT[NODE]
|
||||||
// no: parent.CHILD
|
// yes: NODE.child
|
||||||
if (t.isMemberExpression(parent)) {
|
// no: parent.CHILD
|
||||||
if (parent.property === node && parent.computed) {
|
case "MemberExpression":
|
||||||
return true;
|
if (parent.property === node && parent.computed) {
|
||||||
} else if (parent.object === node) {
|
return true;
|
||||||
return true;
|
} else if (parent.object === node) {
|
||||||
} else {
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// yes: { [NODE]: "" }
|
||||||
|
// no: { NODE: "" }
|
||||||
|
case "Property":
|
||||||
|
if (parent.key === node) {
|
||||||
|
return parent.computed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no: var NODE = init;
|
||||||
|
// yes: var id = NODE;
|
||||||
|
case "VariableDeclarator":
|
||||||
|
return parent.id !== node;
|
||||||
|
|
||||||
|
// no: function NODE() {}
|
||||||
|
// no: function foo(NODE) {}
|
||||||
|
case "ArrowFunctionExpression":
|
||||||
|
case "FunctionDeclaration":
|
||||||
|
case "FunctionExpression":
|
||||||
|
for (var i = 0; i < parent.params.length; i++) {
|
||||||
|
var param = parent.params[i];
|
||||||
|
if (param === node) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent.id !== node;
|
||||||
|
|
||||||
|
// no: export { foo as NODE };
|
||||||
|
case "ExportSpecifier":
|
||||||
|
return parent.exported !== node;
|
||||||
|
|
||||||
|
// no: import { NODE as foo } from "foo";
|
||||||
|
case "ImportSpecifier":
|
||||||
|
return parent.imported !== node;
|
||||||
|
|
||||||
|
// no: class NODE {}
|
||||||
|
case "ClassDeclaration":
|
||||||
|
case "ClassExpression":
|
||||||
|
return parent.id !== node;
|
||||||
|
|
||||||
|
// yes: class { [NODE](){} }
|
||||||
|
case "MethodDefinition":
|
||||||
|
return parent.key === node && parent.computed;
|
||||||
|
|
||||||
|
// no: NODE: for (;;) {}
|
||||||
|
case "LabeledStatement":
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// yes: { [NODE]: "" }
|
// no: try {} catch (NODE) {}
|
||||||
// no: { NODE: "" }
|
case "CatchClause":
|
||||||
if (t.isProperty(parent) && parent.key === node) {
|
return parent.param !== node;
|
||||||
return parent.computed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: var NODE = init;
|
// no: function foo(...NODE) {}
|
||||||
// yes: var id = NODE;
|
case "RestElement":
|
||||||
if (t.isVariableDeclarator(parent)) {
|
return false;
|
||||||
return parent.id !== node;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: function NODE() {}
|
// no: [NODE = foo] = [];
|
||||||
// no: function foo(NODE) {}
|
// yes: [foo = NODE] = [];
|
||||||
if (t.isFunction(parent)) {
|
case "AssignmentPattern":
|
||||||
for (var i = 0; i < parent.params.length; i++) {
|
return parent.right === node;
|
||||||
var param = parent.params[i];
|
|
||||||
if (param === node) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent.id !== node;
|
// no: [NODE] = [];
|
||||||
}
|
// no: ({ NODE }) = [];
|
||||||
|
case "ObjectPattern":
|
||||||
|
case "ArrayPattern":
|
||||||
|
return false;
|
||||||
|
|
||||||
// no: export { foo as NODE };
|
// no: import NODE from "bar";
|
||||||
if (t.isExportSpecifier(parent, { name: node })) {
|
case "ImportSpecifier":
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// no: import { NODE as foo } from "foo";
|
// no: import * as NODE from "foo";
|
||||||
if (t.isImportSpecifier(parent, { id: node })) {
|
case "ImportNamespaceSpecifier":
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// no: class NODE {}
|
|
||||||
if (t.isClass(parent)) {
|
|
||||||
return parent.id !== node;
|
|
||||||
}
|
|
||||||
|
|
||||||
// yes: class { [NODE](){} }
|
|
||||||
if (t.isMethodDefinition(parent)) {
|
|
||||||
return parent.key === node && parent.computed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: NODE: for (;;) {}
|
|
||||||
if (t.isLabeledStatement(parent)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: try {} catch (NODE) {}
|
|
||||||
if (t.isCatchClause(parent)) {
|
|
||||||
return parent.param !== node;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: function foo(...NODE) {}
|
|
||||||
if (t.isRestElement(parent)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: [NODE = foo] = [];
|
|
||||||
// yes: [foo = NODE] = [];
|
|
||||||
if (t.isAssignmentPattern(parent)) {
|
|
||||||
return parent.right === node;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: [NODE] = [];
|
|
||||||
// no: ({ NODE }) = [];
|
|
||||||
if (t.isPattern(parent)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: import NODE from "bar";
|
|
||||||
if (t.isImportSpecifier(parent)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: import * as NODE from "foo";
|
|
||||||
if (t.isImportBatchSpecifier(parent)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no: class Foo { private NODE; }
|
|
||||||
if (t.isPrivateDeclaration(parent)) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -154,7 +142,7 @@ export function isVar(node: Object): boolean {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function isSpecifierDefault(specifier: Object): boolean {
|
export function isSpecifierDefault(specifier: Object): boolean {
|
||||||
return specifier.default || t.isIdentifier(specifier.id) && specifier.id.name === "default";
|
return t.isImportDefaultSpecifier(specifier) || t.isIdentifier(specifier.imported || specifier.exported, { name: "default" });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -22,7 +22,6 @@
|
|||||||
"DebuggerStatement": [],
|
"DebuggerStatement": [],
|
||||||
"DoWhileStatement": ["body", "test"],
|
"DoWhileStatement": ["body", "test"],
|
||||||
"EmptyStatement": [],
|
"EmptyStatement": [],
|
||||||
"ExportBatchSpecifier": [],
|
|
||||||
"ExportAllDeclaration": ["source"],
|
"ExportAllDeclaration": ["source"],
|
||||||
"ExportDefaultDeclaration": ["declaration"],
|
"ExportDefaultDeclaration": ["declaration"],
|
||||||
"ExportNamedDeclaration": ["declaration", "specifiers", "source"],
|
"ExportNamedDeclaration": ["declaration", "specifiers", "source"],
|
||||||
@ -36,6 +35,7 @@
|
|||||||
"FunctionExpression": ["id", "params", "defaults", "rest", "body", "returnType", "typeParameters"],
|
"FunctionExpression": ["id", "params", "defaults", "rest", "body", "returnType", "typeParameters"],
|
||||||
"Identifier": ["typeAnnotation"],
|
"Identifier": ["typeAnnotation"],
|
||||||
"IfStatement": ["test", "consequent", "alternate"],
|
"IfStatement": ["test", "consequent", "alternate"],
|
||||||
|
"ImportDefaultSpecifier": ["local"],
|
||||||
"ImportNamespaceSpecifier": ["local"],
|
"ImportNamespaceSpecifier": ["local"],
|
||||||
"ImportDeclaration": ["specifiers", "source"],
|
"ImportDeclaration": ["specifiers", "source"],
|
||||||
"ImportSpecifier": ["imported", "local"],
|
"ImportSpecifier": ["imported", "local"],
|
||||||
@ -55,6 +55,7 @@
|
|||||||
"SequenceExpression": ["expressions"],
|
"SequenceExpression": ["expressions"],
|
||||||
"SpreadElement": ["argument"],
|
"SpreadElement": ["argument"],
|
||||||
"SpreadProperty": ["argument"],
|
"SpreadProperty": ["argument"],
|
||||||
|
"SuperExpression": [],
|
||||||
"SwitchCase": ["test", "consequent"],
|
"SwitchCase": ["test", "consequent"],
|
||||||
"SwitchStatement": ["discriminant", "cases"],
|
"SwitchStatement": ["discriminant", "cases"],
|
||||||
"TaggedTemplateExpression": ["tag", "quasi"],
|
"TaggedTemplateExpression": ["tag", "quasi"],
|
||||||
|
|||||||
@ -73,7 +73,6 @@ var run = function (task, done) {
|
|||||||
|
|
||||||
if (execCode) {
|
if (execCode) {
|
||||||
result = transform(execCode, getOpts(exec));
|
result = transform(execCode, getOpts(exec));
|
||||||
checkAst(result, exec);
|
|
||||||
execCode = result.code;
|
execCode = result.code;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -94,13 +93,14 @@ var run = function (task, done) {
|
|||||||
err.message += codeFrame(execCode);
|
err.message += codeFrame(execCode);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkAst(result, exec);
|
||||||
}
|
}
|
||||||
|
|
||||||
var actualCode = actual.code;
|
var actualCode = actual.code;
|
||||||
var expectCode = expect.code;
|
var expectCode = expect.code;
|
||||||
if (!execCode || actualCode) {
|
if (!execCode || actualCode) {
|
||||||
result = transform(actualCode, getOpts(actual));
|
result = transform(actualCode, getOpts(actual));
|
||||||
checkAst(result, actual);
|
|
||||||
actualCode = result.code.trim();
|
actualCode = result.code.trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -109,6 +109,8 @@ var run = function (task, done) {
|
|||||||
//require("fs").writeFileSync(expect.loc, actualCode);
|
//require("fs").writeFileSync(expect.loc, actualCode);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkAst(result, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task.sourceMap) {
|
if (task.sourceMap) {
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
class Obj {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.doesNotThrow(function() {
|
|
||||||
new Obj();
|
|
||||||
});
|
|
||||||
@ -18,4 +18,4 @@ define(["exports", "foo"], function (exports, _foo) {
|
|||||||
exports["default"] = _foo.foo;
|
exports["default"] = _foo.foo;
|
||||||
exports["default"] = _foo.foo;
|
exports["default"] = _foo.foo;
|
||||||
exports.bar = _foo.bar;
|
exports.bar = _foo.bar;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"experimental": true,
|
"whitelist": ["flow", "es7.asyncFunctions"],
|
||||||
"whitelist": ["flow"],
|
|
||||||
"noCheckAst": true
|
"noCheckAst": true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
export { foo as foo };
|
export { foo };
|
||||||
|
|
||||||
export { bar as bar };
|
export { bar };
|
||||||
|
|
||||||
function foo() {}
|
function foo() {}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user