diff --git a/src/babel/build-external-helpers.js b/src/babel/build-external-helpers.js deleted file mode 100644 index 91c393fcc5..0000000000 --- a/src/babel/build-external-helpers.js +++ /dev/null @@ -1,86 +0,0 @@ -import generator from "./generation"; -import * as messages from "./messages"; -import * as util from "./util"; -import File from "./transformation/file"; -import each from "lodash/collection/each"; -import t from "./types"; - -function buildGlobal(namespace, builder) { - var body = []; - var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body)); - var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]); - - body.push(t.variableDeclaration("var", [ - t.variableDeclarator( - namespace, - t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([])) - ) - ])); - - builder(body); - - return tree; -} - -function buildUmd(namespace, builder) { - var body = []; - body.push(t.variableDeclaration("var", [ - t.variableDeclarator(namespace, t.identifier("global")) - ])); - - builder(body); - - var container = util.template("umd-commonjs-strict", { - FACTORY_PARAMETERS: t.identifier("global"), - BROWSER_ARGUMENTS: t.assignmentExpression("=", t.memberExpression(t.identifier("root"), namespace), t.objectExpression({})), - COMMON_ARGUMENTS: t.identifier("exports"), - AMD_ARGUMENTS: t.arrayExpression([t.literal("exports")]), - FACTORY_BODY: body, - UMD_ROOT: t.identifier("this") - }); - return t.program([container]); -} - -function buildVar(namespace, builder) { - var body = []; - body.push(t.variableDeclaration("var", [ - t.variableDeclarator(namespace, t.objectExpression({})) - ])); - builder(body); - return t.program(body); -} - -function buildHelpers(body, namespace, whitelist = []) { - each(File.helpers, function (name) { - if (whitelist.length && whitelist.indexOf(name) === -1) return; - - var key = t.identifier(t.toIdentifier(name)); - body.push(t.expressionStatement( - t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name)) - )); - }); -} - -export default function (whitelist, outputType = "global") { - var namespace = t.identifier("babelHelpers"); - - var builder = function (body) { - return buildHelpers(body, namespace, whitelist); - }; - - var tree; - - var build = { - global: buildGlobal, - umd: buildUmd, - var: buildVar - }[outputType]; - - if (build) { - tree = build(namespace, builder); - } else { - throw new Error(messages.get("unsupportedOutputType", outputType)); - } - - return generator(tree).code; -}; diff --git a/src/babel/detection/index.js b/src/babel/detection/index.js deleted file mode 100644 index 604663c9a3..0000000000 --- a/src/babel/detection/index.js +++ /dev/null @@ -1,28 +0,0 @@ -import SYNTAX_KEYS from "./syntax-keys"; -import traverse from "../traversal"; - -var visitors = traverse.explode(require("./visitors")); - -export default function (ast) { - var stats = { - syntax: {}, - builtins: {} - }; - - var detectedSyntax = function (name) { - stats.syntax[name] = true; - }; - - traverse(ast, { - enter(node, parent) { - if (SYNTAX_KEYS[node.type]) { - detectedSyntax(SYNTAX_KEYS[node.type]); - } - - var visitor = visitors[node.type]; - if (visitor) visitor(node, parent, detectedSyntax); - } - }); - - return stats; -}; diff --git a/src/babel/detection/syntax-keys.json b/src/babel/detection/syntax-keys.json deleted file mode 100644 index 07756104d4..0000000000 --- a/src/babel/detection/syntax-keys.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "ArrowFunctionExpression": "es6.arrowFunctions", - - "AwaitExpression": "es7.asyncFunctions", - - "ClassBody": "es6.classes", - "ClassDeclaration": "es6.classes", - "ClassExpression": "es6.classes", - "MethodDefinition": "es6.classes", - - "ComprehensionBlock": "es7.comprehensions", - "ComprehensionExpression": "es7.comprehensions", - - "ForOfStatement": "es6.forOf", - - "ExportBatchSpecifier": "es6.modules", - "ExportDeclaration": "es6.modules", - "ExportSpecifier": "es6.modules", - "ImportBatchSpecifier": "es6.modules", - "ImportDeclaration": "es6.modules", - "ImportSpecifier": "es6.modules", - - "ArrayPattern": "es6.destructuring", - "AssignmentPattern": "es6.destructuring", - "ObjectPattern": "es6.destructuring", - - "RestElement": "es6.parameters.rest", - - "SpreadElement": "es6.spread", - - "SpreadProperty": "es7.objectSpread", - - "TaggedTemplateExpression": "es6.templateLiterals", - "TemplateElement": "es6.templateLiterals", - "TemplateLiteral": "es6.templateLiterals", - - "VirtualPropertyExpression": "es7.abstractReferences", - "PrivateDeclaration": "es7.abstractReferences", - - "YieldExpression": "es6.generators", - - "AnyTypeAnnotation": "flow", - "ArrayTypeAnnotation": "flow", - "BooleanTypeAnnotation": "flow", - "ClassProperty": "flow", - "DeclareClass": "flow", - "DeclareFunction": "flow", - "DeclareModule": "flow", - "DeclareVariable": "flow", - "FunctionTypeAnnotation": "flow", - "FunctionTypeParam": "flow", - "GenericTypeAnnotation": "flow", - "InterfaceExtends": "flow", - "InterfaceDeclaration": "flow", - "IntersectionTypeAnnotation": "flow", - "NullableTypeAnnotation": "flow", - "NumberTypeAnnotation": "flow", - "StringLiteralTypeAnnotation": "flow", - "StringTypeAnnotation": "flow", - "TupleTypeAnnotation": "flow", - "TypeofTypeAnnotation": "flow", - "TypeAlias": "flow", - "TypeAnnotation": "flow", - "TypeParameterDeclaration": "flow", - "TypeParameterInstantiation": "flow", - "ObjectTypeAnnotation": "flow", - "ObjectTypeCallProperty": "flow", - "ObjectTypeIndexer": "flow", - "ObjectTypeProperty": "flow", - "QualifiedTypeIdentifier": "flow", - "UnionTypeAnnotation": "flow", - "VoidTypeAnnotation": "flow", - - "JSXAttribute": "jsx", - "JSXClosingElement": "jsx", - "JSXElement": "jsx", - "JSXEmptyExpression": "jsx", - "JSXExpressionContainer": "jsx", - "JSXIdentifier": "jsx", - "JSXMemberExpression": "jsx", - "JSXNamespacedName": "jsx", - "JSXOpeningElement": "jsx", - "JSXSpreadAttribute": "jsx" -} diff --git a/src/babel/detection/visitors.js b/src/babel/detection/visitors.js deleted file mode 100644 index e8e26e356b..0000000000 --- a/src/babel/detection/visitors.js +++ /dev/null @@ -1,54 +0,0 @@ -import includes from "lodash/collection/includes"; -import t from "../types"; - -export function AssignmentExpression(node, parent, detected) { - if (node.operator === "**=") { - detected("es6.exponentation"); - } -} - -export function BinaryExpression(node, parent, detected) { - if (node.operator === "**") { - detected("es6.exponentation"); - } -} - -export function VariableDeclaration(node, parent, detected) { - if (node.kind === "let" || node.kind === "const") { - detected("es6.blockScoping"); - } - - if (node.kind === "const") { - detected("es6.constants"); - } -} - -export function Property(node, parent, detected) { - if (node.shorthand || node.method) { - detected("es6.properties.shorthand"); - } - - if (node.kind === "set" || node.kind === "get") { - detected("es5.properties.mutators"); - } - - if (node.computed) { - detected("es6.properties.computed"); - } -} - -export function AssignmentPattern(node, parent, detected) { - if (t.isFunction(parent) && includes(parent.params, node)) { - detected("es6.parameters.default"); - } -} - -exports.Function = function (node, parent, detected) { - if (node.generator) { - detected("es6.generators"); - } - - if (node.async) { - detected("es7.asyncFunctions"); - } -}; diff --git a/test/detection.js b/test/detection.js deleted file mode 100644 index e7e922318a..0000000000 --- a/test/detection.js +++ /dev/null @@ -1,140 +0,0 @@ -var detect = require("../lib/babel/detection"); -var assert = require("assert"); -var parse = require("../lib/babel/helpers/parse"); - -suite("detection", function () { - var checkSyntax = function (code, name) { - var ast = parse({ - experimental: true - }, code); - - assert.ok(detect(ast).syntax[name]); - }; - - test("es5.properties.mutators", function () { - checkSyntax("var obj = { get foo() {} };", "es5.properties.mutators"); - checkSyntax("var obj = { set foo() {} };", "es5.properties.mutators"); - }); - - test("es6.exponentation", function () { - checkSyntax("x ** 2;", "es6.exponentation"); - checkSyntax("x **= 2;", "es6.exponentation"); - }); - - test("es6.blockScoping", function () { - checkSyntax("let foo;", "es6.blockScoping"); - checkSyntax("let foo = bar;", "es6.blockScoping"); - checkSyntax("const foo = bar;", "es6.blockScoping"); - }); - - test("es6.constants", function () { - checkSyntax("const foo = bar;", "es6.constants"); - }); - - test("es6.properties.shorthand", function () { - checkSyntax("var obj = { foo };", "es6.properties.shorthand"); - checkSyntax("var obj = { foo };", "es6.properties.shorthand"); - }); - - test("es6.properties.computed", function () { - checkSyntax("var obj = { [foo]: bar };", "es6.properties.computed"); - checkSyntax("var obj = { ['foo']: bar };", "es6.properties.computed"); - }); - - test("es6.parameters.default", function () { - checkSyntax("var obj = (foo = bar) => {};", "es6.parameters.default"); - checkSyntax("var obj = function (foo = bar) {};", "es6.parameters.default"); - checkSyntax("function foo(foo = bar) {}", "es6.parameters.default"); - }); - - test("es6.arrowFunctions", function () { - checkSyntax("var foo = x => x;", "es6.arrowFunctions"); - checkSyntax("var foo = x => { return x * x };", "es6.arrowFunctions"); - checkSyntax("var foo = (x) => x;", "es6.arrowFunctions"); - checkSyntax("var foo = (a, b) => { return a * b };", "es6.arrowFunctions"); - }); - - test("es6.classes", function () { - checkSyntax("class Foo {}", "es6.classes"); - checkSyntax("var Foo = class {};", "es6.classes"); - }); - - test("es6.forOf", function () { - checkSyntax("for (var val of foo);", "es6.forOf"); - checkSyntax("for (val of foo);", "es6.forOf"); - }); - - test("es6.modules", function () { - checkSyntax("import 'foo';", "es6.modules"); - checkSyntax("import foo from 'foo';", "es6.modules"); - checkSyntax("import * as foo from 'foo';", "es6.modules"); - checkSyntax("import { foo } from 'foo';", "es6.modules"); - checkSyntax("export { foo } from 'foo';", "es6.modules"); - checkSyntax("export var foo = 5;", "es6.modules"); - checkSyntax("export class Foo {}", "es6.modules"); - checkSyntax("export function foo() {}", "es6.modules"); - checkSyntax("export default class Foo {}", "es6.modules"); - checkSyntax("export default function foo() {}", "es6.modules"); - }); - - test("es6.destructuring", function () { - checkSyntax("[a, b] = [];", "es6.destructuring"); - checkSyntax("var [a, b] = [];", "es6.destructuring"); - checkSyntax("({ a, b }) = {};", "es6.destructuring"); - checkSyntax("var { a, b } = {};", "es6.destructuring"); - checkSyntax("function foo(foo = bar) {}", "es6.destructuring"); - }); - - test("es6.parameters.rest", function () { - checkSyntax("function foo(...items) {}", "es6.parameters.rest"); - checkSyntax("var foo = (...items) => {}", "es6.parameters.rest"); - }); - - test("es6.spread", function () { - checkSyntax("new Foo(...items);", "es6.spread"); - checkSyntax("foo(...items);", "es6.spread"); - checkSyntax("[...items];", "es6.spread"); - }); - - test("es6.templateLiterals", function () { - checkSyntax("`foobar`;", "es6.templateLiterals"); - checkSyntax("foobar`foobar`;", "es6.templateLiterals"); - }); - - test("es6.generators", function () { - checkSyntax("function* foo() {}", "es6.generators"); - checkSyntax("var foo = function* () {};", "es6.generators"); - }); - - test("es7.asyncFunctions", function () { - checkSyntax("async function foo() {}", "es7.asyncFunctions"); - checkSyntax("var foo = async function() {};", "es7.asyncFunctions"); - checkSyntax("var foo = async () => {};", "es7.asyncFunctions"); - }); - - test("es7.comprehensions", function () { - checkSyntax("[for (i of test) i]", "es7.comprehensions"); - checkSyntax("(for (i of test) i)", "es7.comprehensions"); - }); - - test("es7.objectSpread", function () { - checkSyntax("var foo = { ...bar };", "es7.objectSpread"); - }); - - test("es7.abstractReferences", function () { - checkSyntax("class Foo { private A; }", "es7.abstractReferences"); - checkSyntax("foo::bar();", "es7.abstractReferences"); - checkSyntax("delete foo::bar;", "es7.abstractReferences"); - checkSyntax("foo::bar;", "es7.abstractReferences"); - checkSyntax("foo::bar = baz;", "es7.abstractReferences"); - }); - - test("flow", function () { - - }); - - test("jsx", function () { - checkSyntax("
", "jsx"); - checkSyntax("", "jsx"); - }); -});