diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000000..f05ad7b95b --- /dev/null +++ b/.flowconfig @@ -0,0 +1,14 @@ +[ignore] + +[include] + +[libs] +lib/file.js +lib/parser.js +lib/types.js + +[options] +strip_root=true + +[version] +0.16.0 diff --git a/Makefile b/Makefile index b4a9b08c19..b8f022252d 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,10 @@ watch: clean lint: node node_modules/.bin/eslint packages/*/src + #flow check clean: test-clean rm -rf coverage - rm -rf packages/*/lib packages/babel-core/templates.json test-clean: rm -rf packages/*/test/tmp @@ -45,7 +45,7 @@ publish: make test node scripts/publish.js make clean - ./scripts/build-website.sh + #./scripts/build-website.sh bootstrap: npm install diff --git a/VERSION b/VERSION index aaeac54d59..ac78cf1a97 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.8.23 \ No newline at end of file +5.8.33 diff --git a/doc/design/compiler-assumptions.md b/doc/design/compiler-assumptions.md new file mode 100644 index 0000000000..e4cf07e49d --- /dev/null +++ b/doc/design/compiler-assumptions.md @@ -0,0 +1,9 @@ +# Compiler assumptions + +Babel and it's associated official transforms make some assumptions about your code. These +assumptions are only made as they're either **impossible** to take into consideration or +are extremely exotic. + + - `undefined`, `NaN` and `Infinity` have not been externally redefined. + - Built-in objects such as `Object`, `Array`, `String`, `Number`, `Boolean` etc have not been redefined. + - Standard methods on built-ins have not been redefined in a way that breaks the original contract. diff --git a/doc/design/compiler-guarantees.md b/doc/design/compiler-guarantees.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/package.json b/package.json index 08e36a316c..045fd66281 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,10 @@ "babel": "5.8.21", "babel-eslint": "^4.0.6", "babel-plugin-flow-comments": "^1.0.9", - "browserify": "^11.0.0", + "browserify": "^11.2.0", + "bundle-collapser": "^1.2.1", "chai": "^2.2.0", - "chalk": "^1.1.0", + "derequire": "^2.0.2", "es5-shim": "^4.1.7", "eslint": "^1.1.0", "fs-readdir-recursive": "^0.1.2", @@ -81,7 +82,8 @@ "no-process-exit": 0, "camelcase": 0, "no-console": 0, - "no-constant-condition": 0 + "no-constant-condition": 0, + "no-inner-declarations": 0 }, "env": { "node": true diff --git a/packages/README.md b/packages/README.md index 9b51ee095f..47324dbd6d 100644 --- a/packages/README.md +++ b/packages/README.md @@ -1,88 +1,3 @@ # Woah, what's going on here? -A monorepo, muhahahahahaha. See the [monorepo design doc](/doc/design/monorepo.md) for reasoning. Here's an explanation for each package listed: - -## `babylon` - -## `babel-core` - -#### `babel-cli` - -#### `babel-types` - -#### `babel-code-frame` - -#### `babel-messages` - -#### `babel-polyfill` - -#### `babel-runtime` - -#### `babel-traverse` - -#### `babel-plugin-*` - - - `babel-plugin-auxiliary-comments` - - `babel-plugin-external-helpers` - - `babel-plugin-transform-async-functions` - - `babel-plugin-transform-async-to-bluebird-coroutines` - - `babel-plugin-transform-async-to-generator` - - `babel-plugin-transform-class-properties` - - `babel-plugin-transform-comprehensions` - - `babel-plugin-transform-constant-folding` - - `babel-plugin-transform-dead-code-elimination` - - `babel-plugin-transform-decorators` - - `babel-plugin-transform-do-expressions` - - `babel-plugin-transform-es2015-arrow-functions` - - `babel-plugin-transform-es2015-block-scoped-functions` - - `babel-plugin-transform-es2015-block-scoping` - - `babel-plugin-transform-es2015-classes` - - `babel-plugin-transform-es2015-computed-properties` - - `babel-plugin-transform-es2015-constants` - - `babel-plugin-transform-es2015-destructuring` - - `babel-plugin-transform-es2015-for-of` - - `babel-plugin-transform-es2015-function-name` - - `babel-plugin-transform-es2015-literals` - - `babel-plugin-transform-es2015-modules-amd` - - `babel-plugin-transform-es2015-modules-commonjs` - - `babel-plugin-transform-es2015-modules-systemjs` - - `babel-plugin-transform-es2015-modules-umd` - - `babel-plugin-transform-es2015-object-super` - - `babel-plugin-transform-es2015-parameters` - - `babel-plugin-transform-es2015-shorthand-properties` - - `babel-plugin-transform-es2015-spread` - - `babel-plugin-transform-es2015-sticky-regex` - - `babel-plugin-transform-es2015-tail-call` - - `babel-plugin-transform-es2015-template-literals` - - `babel-plugin-transform-es2015-unicode-regex` - - `babel-plugin-transform-es3-member-expression-literals` - - `babel-plugin-transform-es3-property-literals` - - `babel-plugin-transform-es5-property-mutators` - - `babel-plugin-transform-eval` - - `babel-plugin-transform-exponentiation-operator` - - `babel-plugin-transform-export-extensions` - - `babel-plugin-transform-flow-strip-types` - - `babel-plugin-transform-function-bind` - - `babel-plugin-transform-inline-environment-variables` - - `babel-plugin-transform-jscript` - - `babel-plugin-transform-member-expression-literals` - - `babel-plugin-transform-merge-sibling-variables` - - `babel-plugin-transform-minify-booleans` - - `babel-plugin-transform-node-env-inline` - - `babel-plugin-transform-object-assign` - - `babel-plugin-transform-object-rest-spread` - - `babel-plugin-transform-object-set-prototype-of-to-assign` - - `babel-plugin-transform-property-literals` - - `babel-plugin-transform-proto-to-assign` - - `babel-plugin-transform-react-compat-jsx` - - `babel-plugin-transform-react-constant-elements` - - `babel-plugin-transform-react-display-name` - - `babel-plugin-transform-react-inline-elements` - - `babel-plugin-transform-react-jsx` - - `babel-plugin-transform-remove-console` - - `babel-plugin-transform-remove-debugger` - - `babel-plugin-transform-runtime` - - `babel-plugin-transform-simplify-comparison-operators` - - `babel-plugin-transform-trailing-function-commas` - - `babel-plugin-transform-undeclared-variables-check` - - `babel-plugin-transform-undefined-to-void` +A monorepo, muhahahahahaha. See the [monorepo design doc](/doc/design/monorepo.md) for reasoning. diff --git a/packages/babel-cli/index.js b/packages/babel-cli/index.js index 4a0e83d072..090b3f0df5 100644 --- a/packages/babel-cli/index.js +++ b/packages/babel-cli/index.js @@ -1 +1 @@ -module.exports = require("babel-core"); +throw new Error("Use the `babel-core` package not `babel`."); diff --git a/packages/babel-cli/package.json b/packages/babel-cli/package.json index d68633db4b..421376bed9 100644 --- a/packages/babel-cli/package.json +++ b/packages/babel-cli/package.json @@ -1,6 +1,6 @@ { - "name": "babel", - "version": "5.8.23", + "name": "babel-cli", + "version": "5.10.32", "description": "Turn ES6 code into readable vanilla ES5 with source maps", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,10 +8,10 @@ "repository": "babel/babel", "preferGlobal": true, "dependencies": { - "babel-core": "^5.6.21", - "babel-polyfill": "^5.0.0", + "babel-core": "^5.10.32", + "babel-polyfill": "^5.10.32", "chokidar": "^1.0.0", - "commander": "^2.6.0", + "commander": "^2.8.1", "convert-source-map": "^1.1.0", "fs-readdir-recursive": "^0.1.0", "glob": "^5.0.5", @@ -20,13 +20,13 @@ "path-exists": "^1.0.0", "path-is-absolute": "^1.0.0", "slash": "^1.0.0", - "source-map": "^0.4.0", - "v8flags": "^2.0.10" + "source-map": "^0.5.0", + "v8flags": "^2.0.10", + "babel-runtime": "^5.10.32" }, "bin": { "babel": "./bin/babel.js", "babel-node": "./bin/babel-node.js", - "babel-external-helpers": "./bin/babel-external-helpers.js", - "babel-plugin": "./bin/babel-plugin.js" + "babel-external-helpers": "./bin/babel-external-helpers.js" } -} +} \ No newline at end of file diff --git a/packages/babel-cli/src/_babel-node.js b/packages/babel-cli/src/_babel-node.js index 2f168b7f09..6fa82ac3f8 100644 --- a/packages/babel-cli/src/_babel-node.js +++ b/packages/babel-cli/src/_babel-node.js @@ -15,10 +15,11 @@ let program = new commander.Command("babel-node"); program.option("-e, --eval [script]", "Evaluate script"); 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("-o, --only [globs]", ""); +program.option("-i, --ignore [globs]", ""); program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]"); -program.option("-w, --plugins [string]", "TODO", util.list); -program.option("-b, --presets [string]", "TODO", util.list); +program.option("-w, --plugins [string]", "", util.list); +program.option("-b, --presets [string]", "", util.list); let pkg = require("../package.json"); program.version(pkg.version); @@ -28,24 +29,24 @@ program.parse(process.argv); // register({ - extensions: program.extensions, - optional: program.optional, - ignore: program.ignore, - plugins: program.plugins, - presets: program.presets, + extensions: program.extensions, + ignore: program.ignore, + only: program.only, + plugins: program.plugins, + presets: program.presets, }); // -let replPlugin = new babel.Plugin("repl", { +let replPlugin = () => ({ visitor: { - ModuleDeclaration() { - throw this.errorWithNode("Modules aren't supported in the REPL"); + ModuleDeclaration(path) { + throw path.buildCodeFrameError("Modules aren't supported in the REPL"); }, - VariableDeclaration(node) { - if (node.kind !== "var") { - throw this.errorWithNode("Only `var` variables are supported in the REPL"); + VariableDeclaration(path) { + if (path.node.kind !== "var") { + throw path.buildCodeFrameError("Only `var` variables are supported in the REPL"); } } } @@ -59,11 +60,8 @@ let _eval = function (code, filename) { code = babel.transform(code, { filename: filename, - blacklist: program.blacklist, - whitelist: program.whitelist, - optional: program.optional, - stage: program.stage, - plugins: [replPlugin] + presets: program.presets, + plugins: (program.plugins || []).concat([replPlugin]) }).code; return vm.runInThisContext(code, { diff --git a/packages/babel-cli/src/babel-node.js b/packages/babel-cli/src/babel-node.js index 603835dc91..4ff310d144 100755 --- a/packages/babel-cli/src/babel-node.js +++ b/packages/babel-cli/src/babel-node.js @@ -18,7 +18,7 @@ if (argSeparator > -1) { babelArgs = babelArgs.slice(0, argSeparator); } -getV8Flags(function (v8Flags) { +getV8Flags(function (err, v8Flags) { babelArgs.forEach(function(arg){ let flag = arg.split("=")[0]; diff --git a/packages/babel-cli/src/babel-plugin/index.js b/packages/babel-cli/src/babel-plugin/index.js deleted file mode 100755 index de8d326b02..0000000000 --- a/packages/babel-cli/src/babel-plugin/index.js +++ /dev/null @@ -1,162 +0,0 @@ -import pathExists from "path-exists"; -import readline from "readline"; -import child from "child_process"; -import path from "path"; -import fs from "fs"; - -function spawn(cmd, args, callback) { - console.log(">", cmd, args); - - let spawn = child.spawn(cmd, args, { stdio: "inherit" }); - - spawn.on("exit", function (code) { - if (code === 0) { - callback(); - } else { - console.log("Killing..."); - process.exit(1); - } - }); -} - -function spawnMultiple(cmds) { - function next() { - let cmd = cmds.shift(); - if (cmd) { - spawn(cmd.command, cmd.args, next); - } else { - process.exit(); - } - } - - next(); -} - -function template(name, data = {}) { - let source = fs.readFileSync(path.join(__dirname, "templates", name), "utf8"); - source = source.replace(/[A-Z_]+/g, function (key) { - return data[key] === undefined ? key : data[key]; - }); - return source; -} - -function write(filename, content) { - console.log(filename); - fs.writeFileSync(filename, content); -} - -function execMaybe(cmd) { - try { - return child.execSync(cmd).toString(); - } catch (err) { - return ""; - } -} - -let rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}); - -let BABEL_PLUGIN_PREFIX = "babel-plugin-"; - -let cmds = { - init: function () { - let name = path.basename(process.cwd()); - - if (name.indexOf(BABEL_PLUGIN_PREFIX) === 0) { - name = name.slice(BABEL_PLUGIN_PREFIX.length); - } - - rl.question("Description (optional): ", function (description) { - let remote = execMaybe("git config --get remote.origin.url").trim().match(/git@github.com:(.*?).git/); - if (remote) { - build(description, remote[1]); - } else { - rl.question("GitHub Repository (eg. sebmck/babel-plugin-foobar) (optional): ", function (repo) { - build(description, repo); - }); - } - }); - - function build(description, repo) { - rl.close(); - - let templateData = { - DESCRIPTION: description, - FULL_NAME: BABEL_PLUGIN_PREFIX + name, - NAME: name - }; - - write("package.json", JSON.stringify({ - name: templateData.FULL_NAME, - version: "1.0.0", - description: templateData.DESCRIPTION, - repository: repo || undefined, - license: "MIT", - main: "lib/index.js", - - devDependencies: { - babel: "^5.6.0" - }, - - scripts: { - build: "babel-plugin build", - push: "babel-plugin publish", - test: "babel-plugin test" - }, - - keywords: ["babel-plugin"] - }, null, " ") + "\n"); - - write(".npmignore", "node_modules\n*.log\nsrc\n"); - - write(".gitignore", "node_modules\n*.log\nlib\n"); - - write("README.md", template("README.md", templateData)); - - write("LICENSE", template("LICENSE", { - AUTHOR_EMAIL: execMaybe("git config --get user.email").trim(), - AUTHOR_NAME: execMaybe("git config --get user.name").trim(), - YEAR: new Date().getFullYear() - })); - - if (!pathExists.sync("src")) { - fs.mkdirSync("src"); - write("src/index.js", template("index.js", templateData)); - } - } - }, - - build: function () { - spawn("babel", ["src", "--out-dir", "lib", "--copy-files"], process.exit); - }, - - publish: function () { - let pkg = require(process.cwd() + "/package.json"); - console.log("Current version:", pkg.version); - - rl.question("New version (enter nothing for patch): ", function (newVersion) { - rl.close(); - - newVersion = newVersion || "patch"; - - spawnMultiple([ - { command: "git", args: ["pull"] }, - { command: "git", args: ["push"] }, - { command: "babel-plugin", args: ["build"] }, - { command: "npm", args: ["version", newVersion] }, - { command: "npm", args: ["publish"] }, - { command: "git", args: ["push", "--follow-tags"] } - ]); - }); - } -}; - -let cmd = cmds[process.argv[2]]; -if (cmd) { - cmd(); -} else { - console.error("Unknown command:", cmd); - process.exit(1); -} diff --git a/packages/babel-cli/src/babel-plugin/templates/LICENSE b/packages/babel-cli/src/babel-plugin/templates/LICENSE deleted file mode 100644 index 8f49de9415..0000000000 --- a/packages/babel-cli/src/babel-plugin/templates/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) YEAR AUTHOR_NAME - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/babel-cli/src/babel-plugin/templates/README.md b/packages/babel-cli/src/babel-plugin/templates/README.md deleted file mode 100644 index b8f71ad228..0000000000 --- a/packages/babel-cli/src/babel-plugin/templates/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# FULL_NAME - -DESCRIPTION - -## Installation - -```sh -$ npm install FULL_NAME -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["NAME"] -} -``` - -### Via CLI - -```sh -$ babel --plugins NAME script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["NAME"] -}); -``` diff --git a/packages/babel-cli/src/babel-plugin/templates/index.js b/packages/babel-cli/src/babel-plugin/templates/index.js deleted file mode 100644 index ca31cf0b24..0000000000 --- a/packages/babel-cli/src/babel-plugin/templates/index.js +++ /dev/null @@ -1,8 +0,0 @@ -/* eslint no-unused-vars:0 */ -export default function ({ Plugin, types: t }) { - return new Plugin("NAME", { - visitor: { - // your visitor methods go here - } - }); -} diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 7507a78f47..c2a34b7711 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -20,6 +20,7 @@ module.exports = function (commander, filenames) { }); if (!commander.copyFiles && data.ignored) return; + // we've requested explicit sourcemaps to be written to disk if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") { let mapLoc = dest + ".map"; data.code = util.addSourceMappingUrl(data.code, mapLoc); @@ -27,6 +28,7 @@ module.exports = function (commander, filenames) { } outputFileSync(dest, data.code); + util.chmod(src, dest); util.log(src + " -> " + dest); } @@ -37,7 +39,9 @@ module.exports = function (commander, filenames) { if (util.canCompile(filename, commander.extensions)) { write(src, filename); } else if (commander.copyFiles) { - outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src)); + let dest = path.join(commander.outDir, filename); + outputFileSync(dest, fs.readFileSync(src)); + util.chmod(src, dest); } } diff --git a/packages/babel-cli/src/babel/file.js b/packages/babel-cli/src/babel/file.js index e7120f5af5..b8e03b526f 100644 --- a/packages/babel-cli/src/babel/file.js +++ b/packages/babel-cli/src/babel/file.js @@ -54,6 +54,8 @@ module.exports = function (commander, filenames, opts) { } }); + // add the inline sourcemap comment if we've either explicitly asked for inline source + // maps, or we've requested them without any output file if (commander.sourceMaps === "inline" || (!commander.outFile && commander.sourceMaps)) { code += "\n" + convertSourceMap.fromObject(map).toComment(); } @@ -68,6 +70,7 @@ module.exports = function (commander, filenames, opts) { let result = buildResult(); if (commander.outFile) { + // we've requested for a sorucemap to be written to disk if (commander.sourceMaps && commander.sourceMaps !== "inline") { let mapLoc = commander.outFile + ".map"; result.code = util.addSourceMappingUrl(result.code, mapLoc); diff --git a/packages/babel-cli/src/babel/util.js b/packages/babel-cli/src/babel/util.js index e215b38b17..720705001a 100644 --- a/packages/babel-cli/src/babel/util.js +++ b/packages/babel-cli/src/babel/util.js @@ -7,29 +7,33 @@ let path = require("path"); let fs = require("fs"); let _ = require("lodash"); -exports.readdirFilter = function (filename) { +export function chmod(src, dest) { + fs.chmodSync(dest, fs.statSync(src).mode); +} + +export function readdirFilter(filename) { return readdir(filename).filter(function (filename) { return util.canCompile(filename); }); -}; +} -exports.readdir = readdir; +export { readdir }; -exports.canCompile = util.canCompile; +export let canCompile = util.canCompile; -exports.shouldIgnore = function (loc) { +export function shouldIgnore(loc) { return util.shouldIgnore(loc, index.opts.ignore, index.opts.only); -}; +} -exports.addSourceMappingUrl = function (code, loc) { +export function addSourceMappingUrl(code, loc) { return code + "\n//# sourceMappingURL=" + path.basename(loc); -}; +} -exports.log = function (msg) { +export function log(msg) { if (!commander.quiet) console.log(msg); -}; +} -exports.transform = function (filename, code, opts) { +export function transform(filename, code, opts) { opts = _.defaults(opts || {}, index.opts); opts.filename = filename; opts.ignore = null; @@ -39,12 +43,12 @@ exports.transform = function (filename, code, opts) { result.filename = filename; result.actual = code; return result; -}; +} -exports.compile = function (filename, opts) { +export function compile(filename, opts) { try { let code = fs.readFileSync(filename, "utf8"); - return exports.transform(filename, code, opts); + return transform(filename, code, opts); } catch (err) { if (commander.watch) { console.error(toErrorStack(err)); @@ -53,7 +57,7 @@ exports.compile = function (filename, opts) { throw err; } } -}; +} function toErrorStack(err) { if (err._babel && err instanceof SyntaxError) { diff --git a/packages/babel-cli/test/.babelrc b/packages/babel-cli/test/.babelrc index 3a8f8eb911..0967ef424b 100644 --- a/packages/babel-cli/test/.babelrc +++ b/packages/babel-cli/test/.babelrc @@ -1,3 +1 @@ -{ - "breakConfig": true -} +{} diff --git a/packages/babel-cli/test/fixtures/babel-external-helpers/--output-type umd/stdout.txt b/packages/babel-cli/test/fixtures/babel-external-helpers/--output-type umd/stdout.txt index 7720acd669..5ad4dd07cd 100644 --- a/packages/babel-cli/test/fixtures/babel-external-helpers/--output-type umd/stdout.txt +++ b/packages/babel-cli/test/fixtures/babel-external-helpers/--output-type umd/stdout.txt @@ -8,4 +8,4 @@ } })(this, function (global) { var babelHelpers = global; -}) +}); diff --git a/packages/babel-cli/test/fixtures/babel-external-helpers/--whitelist/options.json b/packages/babel-cli/test/fixtures/babel-external-helpers/--whitelist/options.json index 51b6c8f4ec..2d7659493d 100644 --- a/packages/babel-cli/test/fixtures/babel-external-helpers/--whitelist/options.json +++ b/packages/babel-cli/test/fixtures/babel-external-helpers/--whitelist/options.json @@ -1,3 +1,3 @@ { - "args": ["--whitelist", "slice,has-own"] + "args": ["--whitelist", "createClass"] } diff --git a/packages/babel-cli/test/fixtures/babel-external-helpers/--whitelist/stdout.txt b/packages/babel-cli/test/fixtures/babel-external-helpers/--whitelist/stdout.txt index f07c16c3fe..88c4bd2b2f 100644 --- a/packages/babel-cli/test/fixtures/babel-external-helpers/--whitelist/stdout.txt +++ b/packages/babel-cli/test/fixtures/babel-external-helpers/--whitelist/stdout.txt @@ -1,5 +1,21 @@ (function (global) { var babelHelpers = global.babelHelpers = {}; - babelHelpers.hasOwn = Object.prototype.hasOwnProperty; - babelHelpers.slice = Array.prototype.slice; + + babelHelpers.createClass = (function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + })(); })(typeof global === "undefined" ? self : global); diff --git a/packages/babel-cli/test/fixtures/babel/--blacklist/options.json b/packages/babel-cli/test/fixtures/babel/--blacklist/options.json deleted file mode 100644 index 504eb17f7e..0000000000 --- a/packages/babel-cli/test/fixtures/babel/--blacklist/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "args": ["--blacklist", "es6.arrowFunctions"] -} diff --git a/packages/babel-cli/test/fixtures/babel/--blacklist/stdin.txt b/packages/babel-cli/test/fixtures/babel/--blacklist/stdin.txt deleted file mode 100644 index 4bc9539528..0000000000 --- a/packages/babel-cli/test/fixtures/babel/--blacklist/stdin.txt +++ /dev/null @@ -1 +0,0 @@ -arr.map(x => x * MULTIPLIER); diff --git a/packages/babel-cli/test/fixtures/babel/--blacklist/stdout.txt b/packages/babel-cli/test/fixtures/babel/--blacklist/stdout.txt deleted file mode 100644 index 420f2b900e..0000000000 --- a/packages/babel-cli/test/fixtures/babel/--blacklist/stdout.txt +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; - -arr.map(x => x * MULTIPLIER); diff --git a/packages/babel-cli/test/fixtures/babel/--whitelist/options.json b/packages/babel-cli/test/fixtures/babel/--whitelist/options.json deleted file mode 100644 index a8ea889a1c..0000000000 --- a/packages/babel-cli/test/fixtures/babel/--whitelist/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "args": ["--whitelist", "es6.arrowFunctions"] -} diff --git a/packages/babel-cli/test/fixtures/babel/--whitelist/stdin.txt b/packages/babel-cli/test/fixtures/babel/--whitelist/stdin.txt deleted file mode 100644 index 030f13f9fa..0000000000 --- a/packages/babel-cli/test/fixtures/babel/--whitelist/stdin.txt +++ /dev/null @@ -1,2 +0,0 @@ -let MULTIPLER = 5; -arr.map(x => x * MULTIPLIER); diff --git a/packages/babel-cli/test/fixtures/babel/--whitelist/stdout.txt b/packages/babel-cli/test/fixtures/babel/--whitelist/stdout.txt deleted file mode 100644 index 4181a0bd94..0000000000 --- a/packages/babel-cli/test/fixtures/babel/--whitelist/stdout.txt +++ /dev/null @@ -1,4 +0,0 @@ -let MULTIPLER = 5; -arr.map(function (x) { - return x * MULTIPLIER; -}); diff --git a/packages/babel-cli/test/index.js b/packages/babel-cli/test/index.js index 3e229d87b9..938fb6db6a 100644 --- a/packages/babel-cli/test/index.js +++ b/packages/babel-cli/test/index.js @@ -15,6 +15,16 @@ var _ = require("lodash"); var fixtureLoc = __dirname + "/fixtures"; var tmpLoc = __dirname + "/tmp"; +var presetLocs = [ + __dirname + "/../../babel-preset-es2015", + __dirname + "/../../babel-preset-react" +].join(","); + +var pluginLocs = [ + __dirname + "/../../babel-plugin-transform-strict-mode", + __dirname + "/../../babel-plugin-transform-es2015-modules-commonjs", +].join(","); + var readDir = function (loc) { var files = {}; if (pathExists.sync(loc)) { @@ -43,7 +53,7 @@ var assertTest = function (stdout, stderr, opts) { chai.expect(stderr).to.equal(expectStderr, "stderr didn't match"); } } else if (stderr) { - throw new Error("stderr: " + JSON.stringify(stderr)); + throw new Error("stderr:\n" + stderr); } var expectStdout = opts.stdout.trim(); @@ -57,7 +67,7 @@ var assertTest = function (stdout, stderr, opts) { chai.expect(stdout).to.equal(expectStdout, "stdout didn't match"); } } else if (stdout) { - throw new Error("stdout: " + JSON.stringify(stdout)); + throw new Error("stdout:\n" + stdout); } _.each(opts.outFiles, function (expect, filename) { @@ -74,7 +84,18 @@ var buildTest = function (binName, testName, opts) { clear(); saveInFiles(opts.inFiles); - var args = [binLoc].concat(opts.args); + var args = [binLoc]; + + if (binName !== "babel-external-helpers") { + args.push("--presets", presetLocs, "--plugins", pluginLocs); + } + + if (binName === "babel-node") { + args.push("--only", "packages/*/test"); + } + + args = args.concat(opts.args); + var spawn = child.spawn(process.execPath, args); var stderr = ""; diff --git a/packages/babel-code-frame/package.json b/packages/babel-code-frame/package.json index 03525c8c95..4d40c1e7e3 100644 --- a/packages/babel-code-frame/package.json +++ b/packages/babel-code-frame/package.json @@ -1,6 +1,6 @@ { "name": "babel-code-frame", - "version": "5.8.22", + "version": "5.10.32", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,10 +8,11 @@ "repository": "babel/babel", "main": "lib/index.js", "dependencies": { + "babel-runtime": "^5.10.32", "chalk": "^1.1.0", "esutils": "^2.0.2", "js-tokens": "^1.0.1", "line-numbers": "^0.2.0", "repeating": "^1.1.3" } -} +} \ No newline at end of file diff --git a/packages/babel-core/package.json b/packages/babel-core/package.json index 72ed641819..c7339a9246 100644 --- a/packages/babel-core/package.json +++ b/packages/babel-core/package.json @@ -1,13 +1,14 @@ { "name": "babel-core", - "version": "5.8.23", + "version": "5.10.32", "description": "A compiler for writing next generation JavaScript", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", "license": "MIT", "repository": "babel/babel", "browser": { - "./lib/api/register/node.js": "./lib/api/register/browser.js" + "./lib/api/register/node.js": "./lib/api/register/browser.js", + "esprima-fb": false }, "keywords": [ "6to5", @@ -27,28 +28,15 @@ "test": "make test" }, "dependencies": { - "babel-polyfill": "^5.8.22", - "babel-code-frame": "^5.8.22", - "babel-types": "^5.8.22", - "babel-traverse": "^5.8.22", - "babel-generator": "^5.8.22", - "babel-messages": "^5.8.22", - "babel-plugin-constant-folding": "^1.0.1", - "babel-plugin-dead-code-elimination": "^1.0.2", - "babel-plugin-eval": "^1.0.1", - "babel-plugin-inline-environment-variables": "^1.0.1", - "babel-plugin-jscript": "^1.0.4", - "babel-plugin-member-expression-literals": "^1.0.1", - "babel-plugin-property-literals": "^1.0.1", - "babel-plugin-proto-to-assign": "^1.0.3", - "babel-plugin-react-constant-elements": "^1.0.3", - "babel-plugin-react-display-name": "^2.0.0", - "babel-plugin-remove-console": "^1.0.1", - "babel-plugin-remove-debugger": "^1.0.1", - "babel-plugin-runtime": "^1.0.7", - "babel-plugin-undeclared-variables-check": "^1.0.2", - "babel-plugin-undefined-to-void": "^1.1.6", - "babylon": "^5.8.23", + "babel-code-frame": "^5.10.32", + "babel-generator": "^5.10.32", + "babel-helpers": "^6.0.6", + "babel-messages": "^5.10.32", + "babel-template": "^5.10.32", + "babel-runtime": "^5.10.32", + "babel-traverse": "^5.10.32", + "babel-types": "^5.10.32", + "babylon": "^5.10.32", "convert-source-map": "^1.1.0", "debug": "^2.1.1", "esutils": "^2.0.0", @@ -60,11 +48,12 @@ "path-is-absolute": "^1.0.0", "private": "^0.1.6", "regenerator": "0.8.35", - "regexpu": "^1.1.2", "shebang-regex": "^1.0.0", "slash": "^1.0.0", "source-map": "^0.4.0", - "source-map-support": "^0.2.10", - "try-resolve": "^1.0.0" + "source-map-support": "^0.2.10" + }, + "devDependencies": { + "babel-polyfill": "^5.10.32" } -} +} \ No newline at end of file diff --git a/packages/babel-core/register-without-polyfill.js b/packages/babel-core/register-without-polyfill.js deleted file mode 100644 index 6b85c7bcf8..0000000000 --- a/packages/babel-core/register-without-polyfill.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("./lib/api/register/node"); diff --git a/packages/babel-core/register.js b/packages/babel-core/register.js index c97650c29a..6b85c7bcf8 100644 --- a/packages/babel-core/register.js +++ b/packages/babel-core/register.js @@ -1 +1 @@ -module.exports = require("./lib/api/register/node-polyfill"); +module.exports = require("./lib/api/register/node"); diff --git a/packages/babel-core/scripts/build-dist.sh b/packages/babel-core/scripts/build-dist.sh index cefac7997a..2f8f2089c0 100755 --- a/packages/babel-core/scripts/build-dist.sh +++ b/packages/babel-core/scripts/build-dist.sh @@ -1,23 +1,22 @@ #!/bin/sh -set -e +set -ex BROWSERIFY_CMD="../../node_modules/browserify/bin/cmd.js" UGLIFY_CMD="../../node_modules/uglify-js/bin/uglifyjs" -BROWSERIFY_IGNORE="-i esprima-fb" +BROWSERIFY_IGNORE="-i esprima-fb -i through" mkdir -p dist -node scripts/cache-templates - # Add a Unicode BOM so browsers will interpret the file as UTF-8 node -p '"\uFEFF"' > dist/browser.js -node $BROWSERIFY_CMD lib/api/browser.js -s babel $BROWSERIFY_IGNORE >>dist/browser.js +node $BROWSERIFY_CMD lib/api/browser.js \ + --standalone babel \ + --plugin bundle-collapser/plugin \ + --plugin derequire/plugin \ + $BROWSERIFY_IGNORE \ + >>dist/browser.j node -p '"\uFEFF"' > dist/browser.min.js -node $UGLIFY_CMD dist/browser.js >>dist/browser.min.js - -node $BROWSERIFY_CMD lib/api/node.js --node $BROWSERIFY_IGNORE >dist/node.js - -node ../babel-cli/lib/babel-external-helpers >dist/external-helpers.js -node $UGLIFY_CMD dist/external-helpers.js >dist/external-helpers.min.js - -rm -rf templates.json +node $UGLIFY_CMD dist/browser.js \ + --compress warnings=false \ + --mangle \ + >>dist/browser.min.js diff --git a/packages/babel-core/scripts/cache-templates.js b/packages/babel-core/scripts/cache-templates.js deleted file mode 100755 index fa9d46449b..0000000000 --- a/packages/babel-core/scripts/cache-templates.js +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env node - -var fs = require("fs"); -var util = require("../lib/util"); -fs.writeFileSync(__dirname + "/../templates.json", JSON.stringify(util.templates)); diff --git a/packages/babel-core/scripts/postpublish.js b/packages/babel-core/scripts/postpublish.js index 726ad665e3..4e817f4529 100755 --- a/packages/babel-core/scripts/postpublish.js +++ b/packages/babel-core/scripts/postpublish.js @@ -4,5 +4,3 @@ function rmRelative(loc) { rmRelative("browser.js"); rmRelative("browser.min.js"); -rmRelative("external-helpers.js"); -rmRelative("external-helpers.min.js"); diff --git a/packages/babel-core/scripts/prepublish.js b/packages/babel-core/scripts/prepublish.js index 95df529a6f..1b04267e9d 100755 --- a/packages/babel-core/scripts/prepublish.js +++ b/packages/babel-core/scripts/prepublish.js @@ -4,6 +4,3 @@ function relative(loc) { cp(relative("dist/browser.js"), relative("browser.js")); cp(relative("dist/browser.min.js"), relative("browser.min.js")); -cp(relative("dist/external-helpers.js"), relative("external-helpers.js")); -cp(relative("dist/external-helpers.min.js"), relative("external-helpers.min.js")); -require("./cache-templates"); diff --git a/packages/babel-core/src/api/node.js b/packages/babel-core/src/api/node.js index af2713fef8..dcb666ecc2 100644 --- a/packages/babel-core/src/api/node.js +++ b/packages/babel-core/src/api/node.js @@ -1,29 +1,36 @@ /* @flow */ import isFunction from "lodash/lang/isFunction"; -import transform from "../transformation"; -import * as babylon from "babylon"; -import * as util from "../util"; import fs from "fs"; -export { util, transform }; -export { pipeline, lint } from "../transformation"; -export { canCompile } from "../util"; export { default as File } from "../transformation/file"; export { default as options } from "../transformation/file/options/config"; -export { default as Plugin } from "../transformation/plugin"; -export { default as Pipeline } from "../transformation/pipeline"; export { default as buildExternalHelpers } from "../tools/build-external-helpers"; export { default as template } from "babel-template"; export { version } from "../../package"; +// + +import * as util from "../util"; +export { util }; + import * as messages from "babel-messages"; export { messages }; import * as t from "babel-types"; export { t as types }; +// + +import Pipeline from "../transformation/pipeline"; +export { Pipeline }; + +let pipeline = new Pipeline; +export let transform = pipeline.transform.bind(pipeline); +export let transformFromAst = pipeline.transformFromAst.bind(pipeline); + +// export function transformFile(filename: string, opts?: Object, callback: Function) { if (isFunction(opts)) { diff --git a/packages/babel-core/src/api/register/cache.js b/packages/babel-core/src/api/register/cache.js index b128ea4e47..d02b8694e1 100644 --- a/packages/babel-core/src/api/register/cache.js +++ b/packages/babel-core/src/api/register/cache.js @@ -1,3 +1,5 @@ +/* @flow */ + import path from "path"; import fs from "fs"; import homeOrTmp from "home-or-tmp"; diff --git a/packages/babel-core/src/api/register/node.js b/packages/babel-core/src/api/register/node.js index bd4e7a79b5..8f2878ef82 100644 --- a/packages/babel-core/src/api/register/node.js +++ b/packages/babel-core/src/api/register/node.js @@ -1,5 +1,6 @@ /* @flow */ +import deepClone from "lodash/lang/cloneDeep"; import sourceMapSupport from "source-map-support"; import * as registerCache from "./cache"; import OptionManager from "../../transformation/file/options/option-manager"; @@ -10,10 +11,6 @@ import * as util from "../../util"; import fs from "fs"; import path from "path"; -/** - * Install sourcemaps into node. - */ - sourceMapSupport.install({ handleUncaughtExceptions: false, retrieveSourceMap(source) { @@ -29,17 +26,9 @@ sourceMapSupport.install({ } }); -/** - * Load and setup cache. - */ - registerCache.load(); let cache = registerCache.get(); -/** - * Store options. - */ - let transformOpts = {}; let ignore; @@ -50,33 +39,21 @@ let maps = {}; let cwd = process.cwd(); -/** - * Get path from `filename` relative to the current working directory. - */ - function getRelativePath(filename){ return path.relative(cwd, filename); } -/** - * Get last modified time for a `filename`. - */ - function mtime(filename) { return +fs.statSync(filename).mtime; } -/** - * Compile a `filename` with optional `opts`. - */ - function compile(filename, opts = {}) { let result; opts.filename = filename; let optsManager = new OptionManager; - optsManager.mergeOptions(transformOpts); + optsManager.mergeOptions(deepClone(transformOpts)); opts = optsManager.init(opts); let cacheKey = `${JSON.stringify(opts)}:${babel.version}`; @@ -108,10 +85,6 @@ function compile(filename, opts = {}) { return result.code; } -/** - * Test if a `filename` should be ignored by Babel. - */ - function shouldIgnore(filename) { if (!ignore && !only) { return getRelativePath(filename).split(path.sep).indexOf("node_modules") >= 0; @@ -120,58 +93,13 @@ function shouldIgnore(filename) { } } -/** - * Monkey patch istanbul if it is running so that it works properly. - */ - -let istanbulMonkey = {}; - -if (process.env.running_under_istanbul) { - // we need to monkey patch fs.readFileSync so we can hook into - // what istanbul gets, it's extremely dirty but it's the only way - let _readFileSync = fs.readFileSync; - - fs.readFileSync = function (filename) { - if (istanbulMonkey[filename]) { - delete istanbulMonkey[filename]; - let code = compile(filename, { - auxiliaryCommentBefore: "istanbul ignore next" - }); - istanbulMonkey[filename] = true; - return code; - } else { - return _readFileSync.apply(this, arguments); - } - }; -} - -/** - * Replacement for the loader for istanbul. - */ - -function istanbulLoader(m, filename, old) { - istanbulMonkey[filename] = true; - old(m, filename); -} - -/** - * Default loader. - */ - -function normalLoader(m, filename) { +function loader(m, filename) { m._compile(compile(filename), filename); } -/** - * Register a loader for an extension. - */ - function registerExtension(ext) { let old = oldHandlers[ext] || oldHandlers[".js"] || require.extensions[".js"]; - let loader = normalLoader; - if (process.env.running_under_istanbul) loader = istanbulLoader; - require.extensions[ext] = function (m, filename) { if (shouldIgnore(filename)) { old(m, filename); @@ -181,10 +109,6 @@ function registerExtension(ext) { }; } -/** - * Register loader for given extensions. - */ - function hookExtensions(_exts) { each(oldHandlers, function (old, ext) { if (old === undefined) { @@ -202,16 +126,8 @@ function hookExtensions(_exts) { }); } -/** - * Register loader for default extensions. - */ - hookExtensions(util.canCompile.EXTENSIONS); -/** - * Update options at runtime. - */ - export default function (opts?: Object = {}) { if (opts.only != null) only = util.arrayify(opts.only, util.regexify); if (opts.ignore != null) ignore = util.arrayify(opts.ignore, util.regexify); diff --git a/packages/babel-core/src/helpers/resolve.js b/packages/babel-core/src/helpers/resolve.js new file mode 100644 index 0000000000..369fc718d4 --- /dev/null +++ b/packages/babel-core/src/helpers/resolve.js @@ -0,0 +1,24 @@ +/* @flow */ + +import Module from "module"; + +let relativeModules = {}; + +export default function (loc: string, relative: string = process.cwd()): ?string { + // we're in the browser, probably + if (typeof Module === "object") return null; + + let relativeMod = relativeModules[relative]; + + if (!relativeMod) { + relativeMod = new Module; + relativeMod.paths = Module._nodeModulePaths(relative); + relativeModules[relative] = relativeMod; + } + + try { + return Module._resolveFilename(loc, relativeMod); + } catch (err) { + return null; + } +} diff --git a/packages/babel-core/src/store.js b/packages/babel-core/src/store.js index 6c1ae4f953..5783fc82f7 100644 --- a/packages/babel-core/src/store.js +++ b/packages/babel-core/src/store.js @@ -16,9 +16,10 @@ export default class Store extends Map { if (this.has(key)) { return super.get(key); } else { - let dynamic = this.dynamicData[key]; - if (dynamic) { - return this.set(key, dynamic()); + if (Object.prototype.hasOwnProperty.call(this.dynamicData, key)) { + let val = this.dynamicData[key](); + this.set(key, val); + return val; } } } diff --git a/packages/babel-core/src/tools/build-external-helpers.js b/packages/babel-core/src/tools/build-external-helpers.js index 03536fbc14..bf70bb2da2 100644 --- a/packages/babel-core/src/tools/build-external-helpers.js +++ b/packages/babel-core/src/tools/build-external-helpers.js @@ -1,16 +1,30 @@ /* @flow */ +import * as helpers from "babel-helpers"; import generator from "babel-generator"; import * as messages from "babel-messages"; -import * as util from "../util"; -import File from "../transformation/file"; +import template from "babel-template"; import each from "lodash/collection/each"; import * as t from "babel-types"; +let buildUmdWrapper = template(` + (function (root, factory) { + if (typeof define === "function" && define.amd) { + define(AMD_ARGUMENTS, factory); + } else if (typeof exports === "object") { + factory(COMMON_ARGUMENTS); + } else { + factory(BROWSER_ARGUMENTS); + } + })(UMD_ROOT, function (FACTORY_PARAMETERS) { + FACTORY_BODY + }); +`); + function buildGlobal(namespace, builder) { let body = []; let container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body)); - let tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("helper-self-global")]))]); + let tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]); body.push(t.variableDeclaration("var", [ t.variableDeclarator( @@ -32,33 +46,38 @@ function buildUmd(namespace, builder) { builder(body); - let 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.stringLiteral("exports")]), - FACTORY_BODY: body, - UMD_ROOT: t.identifier("this") - }); - return t.program([container]); + return t.program([ + buildUmdWrapper({ + 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.stringLiteral("exports")]), + FACTORY_BODY: body, + UMD_ROOT: t.identifier("this") + }) + ]); } function buildVar(namespace, builder) { let body = []; body.push(t.variableDeclaration("var", [ - t.variableDeclarator(namespace, t.objectExpression({})) + t.variableDeclarator(namespace, t.objectExpression([])) ])); builder(body); return t.program(body); } function buildHelpers(body, namespace, whitelist) { - each(File.helpers, function (name) { + each(helpers.list, function (name) { if (whitelist && whitelist.indexOf(name) === -1) return; let key = t.identifier(t.toIdentifier(name)); body.push(t.expressionStatement( - t.assignmentExpression("=", t.memberExpression(namespace, key), util.template("helper-" + name)) + t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name)) )); }); } diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js index 73f3b9a214..02034369ea 100644 --- a/packages/babel-core/src/transformation/file/index.js +++ b/packages/babel-core/src/transformation/file/index.js @@ -1,26 +1,37 @@ +/* @flow */ +/* global BabelParserOptions */ +/* global BabelFileMetadata */ +/* global BabelFileResult */ + +import getHelper from "babel-helpers"; +import * as metadataVisitor from "./metadata"; import convertSourceMap from "convert-source-map"; -import moduleFormatters from "../modules"; import OptionManager from "./options/option-manager"; -import PluginManager from "./plugin-manager"; +import type Pipeline from "../pipeline"; +import type Plugin from "../plugin"; +import PluginPass from "../plugin-pass"; import shebangRegex from "shebang-regex"; -import { NodePath, Hub } from "babel-traverse"; -import isFunction from "lodash/lang/isFunction"; +import { NodePath, Hub, Scope } from "babel-traverse"; import sourceMap from "source-map"; import generate from "babel-generator"; import codeFrame from "babel-code-frame"; -import shuffle from "lodash/collection/shuffle"; import defaults from "lodash/object/defaults"; -import includes from "lodash/collection/includes"; import traverse from "babel-traverse"; -import resolve from "try-resolve"; import Logger from "./logger"; import Store from "../../store"; -import Plugin from "../plugin"; -import parse from "../../helpers/parse"; +import { parse } from "babylon"; import * as util from "../../util"; import path from "path"; import * as t from "babel-types"; +import blockHoistPlugin from "../internal-plugins/block-hoist"; +import shadowFunctionsPlugin from "../internal-plugins/shadow-functions"; + +const INTERNAL_PLUGINS = [ + [blockHoistPlugin], + [shadowFunctionsPlugin] +]; + let errorVisitor = { enter(path, state) { let loc = path.node.loc; @@ -32,80 +43,88 @@ let errorVisitor = { }; export default class File extends Store { - constructor(opts = {}, pipeline) { + constructor(opts: Object = {}, pipeline: Pipeline) { + super(); + this.pipeline = pipeline; this.log = new Logger(this, opts.filename || "unknown"); this.opts = this.initOptions(opts); - this.buildTransformers(); + this.parserOpts = { + highlightCode: this.opts.highlightCode, + nonStandard: this.opts.nonStandard, + sourceType: this.opts.sourceType, + filename: this.opts.filename, + plugins: [] + }; + + this.pluginVisitors = []; + this.pluginPasses = []; + this.pluginStack = []; + this.buildPlugins(); + + this.metadata = { + usedHelpers: [], + marked: [], + modules: { + imports: [], + exports: { + exported: [], + specifiers: [] + } + } + }; + + this.dynamicImportTypes = {}; + this.dynamicImportIds = {}; + this.dynamicImports = []; + this.declarations = {}; + this.usedHelpers = {}; + + this.path = null; + this.ast = {}; + + this.code = ""; + this.shebang = ""; + + this.hub = new Hub(this); } - transformerDependencies = {}; - dynamicImportTypes = {}; - dynamicImportIds = {}; - dynamicImports = []; - declarations = {}; - usedHelpers = {}; - dynamicData = {}; - data = {}; - ast = {}; + static helpers: Array; - metadata = { - marked: [], + pluginVisitors: Array; + pluginPasses: Array; + pluginStack: Array; + pipeline: Pipeline; + parserOpts: BabelParserOptions; + log: Logger; + opts: Object; + dynamicImportTypes: Object; + dynamicImportIds: Object; + dynamicImports: Array; + declarations: Object; + usedHelpers: Object; + path: NodePath; + ast: Object; + scope: Scope; + metadata: BabelFileMetadata; + hub: Hub; + code: string; + shebang: string; - modules: { - imports: [], - exports: { - exported: [], - specifiers: [] + getMetadata() { + let has = false; + for (let node of (this.ast.program.body: Array)) { + if (t.isModuleDeclaration(node)) { + has = true; + break; } } - }; - - hub = new Hub(this); - - static helpers = [ - "inherits", - "defaults", - "create-class", - "create-decorated-class", - "create-decorated-object", - "define-decorated-property-descriptor", - "tagged-template-literal", - "tagged-template-literal-loose", - "to-array", - "to-consumable-array", - "sliced-to-array", - "sliced-to-array-loose", - "object-without-properties", - "has-own", - "slice", - "bind", - "define-property", - "async-to-generator", - "interop-export-wildcard", - "interop-require-wildcard", - "interop-require-default", - "typeof", - "extends", - "get", - "set", - "new-arrow-check", - "class-call-check", - "object-destructuring-empty", - "temporal-undefined", - "temporal-assert-defined", - "self-global", - "default-props", - "instanceof", - - // legacy - "interop-require" - ]; - - static soloHelpers = []; - + if (has) { + this.path.traverse(metadataVisitor, this); + } + } initOptions(opts) { opts = new OptionManager(this.log, this.pipeline).init(opts); @@ -143,130 +162,67 @@ export default class File extends Store { sourceMapTarget: basenameRelative }); - // - - if (opts.externalHelpers) { - this.set("helpersNamespace", t.identifier("babelHelpers")); - } - return opts; } - isLoose(key: string) { - return includes(this.opts.loose, key); - } - - buildTransformers() { - let file = this; - - let transformers = this.transformers = {}; - - let secondaryStack = []; - let stack = []; - - // build internal transformers - for (let key in this.pipeline.transformers) { - let transformer = this.pipeline.transformers[key]; - let pass = transformers[key] = transformer.buildPass(file); - - if (pass.canTransform()) { - stack.push(pass); - - if (transformer.metadata.secondPass) { - secondaryStack.push(pass); - } - - if (transformer.manipulateOptions) { - transformer.manipulateOptions(file.opts, file); - } - } - } + buildPlugins() { + let plugins: Array<[PluginPass, Object]> = this.opts.plugins.concat(INTERNAL_PLUGINS); // init plugins! - let beforePlugins = []; - let afterPlugins = []; - let pluginManager = new PluginManager({ - file: this, - transformers: this.transformers, - before: beforePlugins, - after: afterPlugins - }); - for (let i = 0; i < file.opts.plugins.length; i++) { - pluginManager.add(file.opts.plugins[i]); - } - stack = beforePlugins.concat(stack, afterPlugins); + for (let ref of plugins) { + let [plugin, pluginOpts] = ref; // todo: fix - can't embed in loop head because of flow bug - // build transformer stack - this.uncollapsedTransformerStack = stack = stack.concat(secondaryStack); + this.pluginStack.push(plugin); + this.pluginVisitors.push(plugin.visitor); + this.pluginPasses.push(new PluginPass(this, plugin, pluginOpts)); - // build dependency graph - for (let pass of (stack: Array)) { - for (let dep of (pass.plugin.dependencies: Array)) { - this.transformerDependencies[dep] = pass.key; + if (plugin.manipulateOptions) { + plugin.manipulateOptions(this.opts, this.parserOpts, this); } } - - // collapse stack categories - this.transformerStack = this.collapseStack(stack); } - collapseStack(_stack) { - let stack = []; - let ignore = []; - - for (let pass of (_stack: Array)) { - // been merged - if (ignore.indexOf(pass) >= 0) continue; - - let group = pass.plugin.metadata.group; - - // can't merge - if (!pass.canTransform() || !group) { - stack.push(pass); - continue; - } - - let mergeStack = []; - for (let pass of (_stack: Array)) { - if (pass.plugin.metadata.group === group) { - mergeStack.push(pass); - ignore.push(pass); - } else { - //break; - } - } - shuffle; - //mergeStack = shuffle(mergeStack); - - let visitors = []; - for (let pass of (mergeStack: Array)) { - visitors.push(pass.plugin.visitor); - } - let visitor = traverse.visitors.merge(visitors); - let mergePlugin = new Plugin(group, { visitor }); - stack.push(mergePlugin.buildPass(this)); + getModuleName(): ?string { + let opts = this.opts; + if (!opts.moduleIds) { + return null; } - return stack; - } + // moduleId is n/a if a `getModuleId()` is provided + if (opts.moduleId != null && !opts.getModuleId) { + return opts.moduleId; + } - set(key: string, val): any { - return this.data[key] = val; - } + let filenameRelative = opts.filenameRelative; + let moduleName = ""; - setDynamic(key: string, fn: Function) { - this.dynamicData[key] = fn; - } + if (opts.moduleRoot != null) { + moduleName = opts.moduleRoot + "/"; + } - get(key: string): any { - let data = this.data[key]; - if (data) { - return data; + if (!opts.filenameRelative) { + return moduleName + opts.filename.replace(/^\//, ""); + } + + if (opts.sourceRoot != null) { + // remove sourceRoot from filename + let sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?"); + filenameRelative = filenameRelative.replace(sourceRootRegEx, ""); + } + + // remove extension + filenameRelative = filenameRelative.replace(/\.(\w*?)$/, ""); + + moduleName += filenameRelative; + + // normalize path separators + moduleName = moduleName.replace(/\\/g, "/"); + + if (opts.getModuleId) { + // If return is falsy, assume they want us to use our generated default name + return opts.getModuleId(moduleName) || moduleName; } else { - let dynamic = this.dynamicData[key]; - if (dynamic) { - return this.set(key, dynamic()); - } + return moduleName; } } @@ -276,81 +232,52 @@ export default class File extends Store { return source; } - addImport(source: string, name?: string, type?: string): Object { - name = name || source; - let id = this.dynamicImportIds[name]; + addImport(source: string, imported: string, name?: string = imported): Object { + let alias = `${source}:${imported}`; + let id = this.dynamicImportIds[alias]; if (!id) { source = this.resolveModuleSource(source); - id = this.dynamicImportIds[name] = this.scope.generateUidIdentifier(name); + id = this.dynamicImportIds[alias] = this.scope.generateUidIdentifier(name); + + let specifiers = []; + + if (imported === "*") { + specifiers.push(t.importNamespaceSpecifier(id)); + } else if (imported === "default") { + specifiers.push(t.importDefaultSpecifier(id)); + } else { + specifiers.push(t.importSpecifier(id, t.identifier(imported))); + } - let specifiers = [t.importDefaultSpecifier(id)]; let declar = t.importDeclaration(specifiers, t.stringLiteral(source)); declar._blockHoist = 3; - if (type) { - let modules = this.dynamicImportTypes[type] = this.dynamicImportTypes[type] || []; - modules.push(declar); - } - - if (this.transformers["es6.modules"].canTransform()) { - this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports, this.scope); - this.moduleFormatter.hasLocalImports = true; - } else { - this.dynamicImports.push(declar); - } + this.path.unshiftContainer("body", declar); } return id; } - attachAuxiliaryComment(node: Object): Object { - let beforeComment = this.opts.auxiliaryCommentBefore; - if (beforeComment) { - node.leadingComments = node.leadingComments || []; - node.leadingComments.push({ - type: "CommentLine", - value: " " + beforeComment - }); - } - - let afterComment = this.opts.auxiliaryCommentAfter; - if (afterComment) { - node.trailingComments = node.trailingComments || []; - node.trailingComments.push({ - type: "CommentLine", - value: " " + afterComment - }); - } - - return node; - } - addHelper(name: string): Object { - let isSolo = includes(File.soloHelpers, name); - - if (!isSolo && !includes(File.helpers, name)) { - throw new ReferenceError(`Unknown helper ${name}`); - } - let declar = this.declarations[name]; if (declar) return declar; - this.usedHelpers[name] = true; - - if (!isSolo) { - let generator = this.get("helperGenerator"); - let runtime = this.get("helpersNamespace"); - if (generator) { - return generator(name); - } else if (runtime) { - let id = t.identifier(t.toIdentifier(name)); - return t.memberExpression(runtime, id); - } + if (!this.usedHelpers[name]) { + this.metadata.usedHelpers.push(name); + this.usedHelpers[name] = true; } - let ref = util.template("helper-" + name); + let generator = this.get("helperGenerator"); + let runtime = this.get("helpersNamespace"); + if (generator) { + return generator(name); + } else if (runtime) { + let id = t.identifier(t.toIdentifier(name)); + return t.memberExpression(runtime, id); + } + let ref = getHelper(name); let uid = this.declarations[name] = this.scope.generateUidIdentifier(name); if (t.isFunctionExpression(ref) && !ref.id) { @@ -358,7 +285,6 @@ export default class File extends Store { ref._generated = true; ref.id = uid; ref.type = "FunctionDeclaration"; - this.attachAuxiliaryComment(ref); this.path.unshiftContainer("body", ref); } else { ref._compact = true; @@ -372,7 +298,11 @@ export default class File extends Store { return uid; } - addTemplateObject(helperName: string, strings: Array, raw: Array): Object { + addTemplateObject( + helperName: string, + strings: Array, + raw: Object, + ): Object { // Generate a unique name based on the string literals so we dedupe // identical strings used in the program. let stringIds = raw.elements.map(function(string) { @@ -396,7 +326,7 @@ export default class File extends Store { return uid; } - buildCodeFrameError(node, msg, Error = SyntaxError) { + buildCodeFrameError(node: Object, msg: string, Error: typeof Error = SyntaxError): Error { let loc = node && (node.loc || node._loc); let err = new Error(msg); @@ -404,7 +334,7 @@ export default class File extends Store { if (loc) { err.loc = loc.start; } else { - traverse(node, errorVisitor, err); + traverse(node, errorVisitor, this.scope, err); err.message += " (This is an error on an internal node. Probably an internal error"; @@ -436,49 +366,9 @@ export default class File extends Store { } } - getModuleFormatter(type: string) { - if (isFunction(type) || !moduleFormatters[type]) { - this.log.deprecate("Custom module formatters are deprecated and will be removed in the next major. Please use Babel plugins instead."); - } - - let ModuleFormatter = isFunction(type) ? type : moduleFormatters[type]; - - if (!ModuleFormatter) { - let loc = resolve.relative(type); - if (loc) ModuleFormatter = require(loc); - } - - if (!ModuleFormatter) { - throw new ReferenceError(`Unknown module formatter type ${JSON.stringify(type)}`); - } - - return new ModuleFormatter(this); - } - parse(code: string) { - let opts = this.opts; - - // - - let parseOpts = { - highlightCode: opts.highlightCode, - nonStandard: opts.nonStandard, - sourceType: opts.sourceType, - filename: opts.filename, - plugins: {} - }; - - let features = parseOpts.features = {}; - for (let key in this.transformers) { - let transformer = this.transformers[key]; - features[key] = transformer.canRun(); - } - - parseOpts.looseModules = this.isLoose("es6.modules"); - parseOpts.strictMode = features.strict; - this.log.debug("Parse start"); - let ast = parse(code, parseOpts); + let ast = parse(code, this.parserOpts); this.log.debug("Parse stop"); return ast; } @@ -493,32 +383,25 @@ export default class File extends Store { }).setContext(); this.scope = this.path.scope; this.ast = ast; + this.getMetadata(); } addAst(ast) { this.log.debug("Start set AST"); this._addAst(ast); this.log.debug("End set AST"); - - this.log.debug("Start module formatter init"); - let modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules); - if (modFormatter.init && this.transformers["es6.modules"].canTransform()) { - modFormatter.init(); - } - this.log.debug("End module formatter init"); } - transform() { + transform(): BabelFileResult { this.call("pre"); - for (let pass of (this.transformerStack: Array)) { - pass.transform(); - } + this.log.debug(`Start transform traverse`); + traverse(this.ast, traverse.visitors.merge(this.pluginVisitors, this.pluginPasses), this.scope); + this.log.debug(`End transform traverse`); this.call("post"); - return this.generate(); } - wrap(code, callback) { + wrap(code: string, callback: Function): BabelFileResult { code = code + ""; try { @@ -578,14 +461,15 @@ export default class File extends Store { return util.shouldIgnore(opts.filename, opts.ignore, opts.only); } - call(key: string) { - for (let pass of (this.uncollapsedTransformerStack: Array)) { - let fn = pass.plugin[key]; - if (fn) fn.call(pass, this); + call(key: "pre" | "post") { + for (let pass of (this.pluginPasses: Array)) { + let plugin = pass.plugin; + let fn = plugin[key]; + if (fn) fn.call(pass, this, pass); } } - parseInputSourceMap(code: string) { + parseInputSourceMap(code: string): string { let opts = this.opts; if (opts.inputSourceMap !== false) { @@ -607,13 +491,14 @@ export default class File extends Store { } } - makeResult({ code, map = null, ast, ignored }) { + makeResult({ code, map, ast, ignored }: BabelFileResult): BabelFileResult { let result = { metadata: null, + options: this.opts, ignored: !!ignored, code: null, ast: null, - map: map + map: map || null }; if (this.opts.code) { @@ -626,17 +511,16 @@ export default class File extends Store { if (this.opts.metadata) { result.metadata = this.metadata; - result.metadata.usedHelpers = Object.keys(this.usedHelpers); } return result; } - generate() { + generate(): BabelFileResult { let opts = this.opts; let ast = this.ast; - let result = { ast }; + let result: BabelFileResult = { ast }; if (!opts.code) return this.makeResult(result); this.log.debug("Generation start"); @@ -649,7 +533,7 @@ export default class File extends Store { if (this.shebang) { // add back shebang - result.code = `${this.shebang}\n${result.code}`; + result.code = `${this.shebang}${result.code}`; } if (result.map) { @@ -667,3 +551,5 @@ export default class File extends Store { return this.makeResult(result); } } + +export { File }; diff --git a/packages/babel-core/src/transformation/modules/lib/metadata.js b/packages/babel-core/src/transformation/file/metadata.js similarity index 64% rename from packages/babel-core/src/transformation/modules/lib/metadata.js rename to packages/babel-core/src/transformation/file/metadata.js index d733e80ee9..35744f971e 100644 --- a/packages/babel-core/src/transformation/modules/lib/metadata.js +++ b/packages/babel-core/src/transformation/file/metadata.js @@ -1,33 +1,29 @@ /* @flow */ -import extend from "lodash/object/extend"; import * as t from "babel-types"; export let ModuleDeclaration = { - enter(node, parent, scope, formatter) { + enter(path, file) { + let { node } = path; if (node.source) { - node.source.value = formatter.file.resolveModuleSource(node.source.value); - formatter.addScope(this); + node.source.value = file.resolveModuleSource(node.source.value); } } }; export let ImportDeclaration = { - exit(node, parent, scope, formatter) { - formatter.hasLocalImports = true; + exit(path, file) { + let { node } = path; let specifiers = []; let imported = []; - formatter.metadata.imports.push({ + file.metadata.modules.imports.push({ source: node.source.value, imported, specifiers }); - for (let specifier of (this.get("specifiers"): Array)) { - let ids = specifier.getBindingIdentifiers(); - extend(formatter.localImports, ids); - + for (let specifier of (path.get("specifiers"): Array)) { let local = specifier.node.local.name; if (specifier.isImportDefaultSpecifier()) { @@ -60,33 +56,30 @@ export let ImportDeclaration = { } }; -export function ExportDeclaration(node, parent, scope, formatter) { - formatter.hasLocalExports = true; +export function ExportDeclaration(path, file) { + let { node } = path; let source = node.source ? node.source.value : null; - let exports = formatter.metadata.exports; + let exports = file.metadata.modules.exports; // export function foo() {} // export let foo = "bar"; - let declar = this.get("declaration"); + let declar = path.get("declaration"); if (declar.isStatement()) { let bindings = declar.getBindingIdentifiers(); for (let name in bindings) { - let binding = bindings[name]; - formatter._addExport(name, binding); - exports.exported.push(name); exports.specifiers.push({ kind: "local", local: name, - exported: this.isExportDefaultDeclaration() ? "default" : name + exported: path.isExportDefaultDeclaration() ? "default" : name }); } } - if (this.isExportNamedDeclaration() && node.specifiers) { - for (let specifier of (node.specifiers: Array)) { + if (path.isExportNamedDeclaration() && node.specifiers) { + for (let specifier of (node.specifiers: Array)) { let exported = specifier.exported.name; exports.exported.push(exported); @@ -112,8 +105,6 @@ export function ExportDeclaration(node, parent, scope, formatter) { let local = specifier.local; if (!local) continue; - formatter._addExport(local.name, specifier.exported); - // export { foo } from "bar"; // export { foo as bar } from "bar"; if (source) { @@ -138,23 +129,14 @@ export function ExportDeclaration(node, parent, scope, formatter) { } // export * from "bar"; - if (this.isExportAllDeclaration()) { + if (path.isExportAllDeclaration()) { exports.specifiers.push({ kind: "external-all", source }); } - - if (!t.isExportDefaultDeclaration(node) && !declar.isTypeAlias()) { - let onlyDefault = node.specifiers && node.specifiers.length === 1 && t.isSpecifierDefault(node.specifiers[0]); - if (!onlyDefault) { - formatter.hasNonDefaultExports = true; - } - } } -export function Scope(node, parent, scope, formatter) { - if (!formatter.isLoose()) { - this.skip(); - } +export function Scope(path) { + path.skip(); } diff --git a/packages/babel-core/src/transformation/file/options/config.json b/packages/babel-core/src/transformation/file/options/config.json index d6d6ec5b68..3810e0d1ee 100644 --- a/packages/babel-core/src/transformation/file/options/config.json +++ b/packages/babel-core/src/transformation/file/options/config.json @@ -51,8 +51,8 @@ "plugins": { "type": "list", - "description": "", - "default": [] + "default": [], + "description": "" }, "ignore": { @@ -137,5 +137,35 @@ "sourceType": { "description": "", "default": "module" + }, + + "auxiliaryComment": { + "description": "", + "type": "string" + }, + + "resolveModuleSource": { + "hidden": true + }, + + "getModuleId": { + "hidden": true + }, + + "moduleRoot": { + "type": "filename", + "description": "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions" + }, + + "moduleIds": { + "type": "boolean", + "default": false, + "shorthand": "M", + "description": "insert an explicit id for modules" + }, + + "moduleId": { + "description": "specify a custom name for module ids", + "type": "string" } } diff --git a/packages/babel-core/src/transformation/file/options/index.js b/packages/babel-core/src/transformation/file/options/index.js index cbd3051618..521f8193e9 100644 --- a/packages/babel-core/src/transformation/file/options/index.js +++ b/packages/babel-core/src/transformation/file/options/index.js @@ -11,6 +11,7 @@ export function normaliseOptions(options: Object = {}): Object { if (val == null) continue; let opt = config[key]; + if (opt && opt.alias) opt = config[opt.alias]; if (!opt) continue; let parser = parsers[opt.type]; diff --git a/packages/babel-core/src/transformation/file/options/option-manager.js b/packages/babel-core/src/transformation/file/options/option-manager.js index a0612da778..cdb577ac5d 100644 --- a/packages/babel-core/src/transformation/file/options/option-manager.js +++ b/packages/babel-core/src/transformation/file/options/option-manager.js @@ -1,9 +1,9 @@ /* @flow */ +import * as context from "../../../api/node"; import type Logger from "../logger"; import Plugin from "../../plugin"; import * as messages from "babel-messages"; -import * as context from "../../../api/node"; import { normaliseOptions } from "./index"; import resolve from "../../../helpers/resolve"; import json5 from "json5"; @@ -53,7 +53,13 @@ export default class OptionManager { if (cache.container === fn) return cache.plugin; } - let obj = fn(context); + let obj; + + if (typeof fn === "function") { + obj = fn(context); + } else { + obj = fn; + } if (typeof obj === "object") { let plugin = new Plugin(obj); @@ -63,7 +69,7 @@ export default class OptionManager { }); return plugin; } else { - throw new TypeError(messages.get("pluginNotObject", loc, i, typeof obj)); + throw new TypeError(messages.get("pluginNotObject", loc, i, typeof obj) + loc + i); } } @@ -78,6 +84,21 @@ export default class OptionManager { return opts; } + static normalisePlugin(plugin, loc, i) { + if (!(plugin instanceof Plugin)) { + // allow plugin containers to be specified so they don't have to manually require + if (typeof plugin === "function" || typeof plugin === "object") { + plugin = OptionManager.memoisePluginContainer(plugin, loc, i); + } else { + throw new TypeError(messages.get("pluginNotFunction", loc, i, typeof plugin)); + } + } + + plugin.init(loc, i); + + return plugin; + } + static normalisePlugins(loc, dirname, plugins) { return plugins.map(function (val, i) { let plugin, options; @@ -99,17 +120,7 @@ export default class OptionManager { } } - if (!(plugin instanceof Plugin)) { - // allow plugin containers to be specified so they don't have to manually require - if (typeof plugin === "function") { - plugin = OptionManager.memoisePluginContainer(plugin, loc, i); - } else { - throw new TypeError(messages.get("pluginNotFunction", loc, i)); - } - } - - // validate - plugin.validate(loc, i); + plugin = OptionManager.normalisePlugin(plugin, loc, i); return [plugin, options]; }); diff --git a/packages/babel-core/src/transformation/helpers/build-comprehension.js b/packages/babel-core/src/transformation/helpers/build-comprehension.js deleted file mode 100644 index 832b002204..0000000000 --- a/packages/babel-core/src/transformation/helpers/build-comprehension.js +++ /dev/null @@ -1,25 +0,0 @@ -/* @flow */ - -import * as t from "babel-types"; - -export default function build(node: Object, buildBody: Function): ?Object { - let self = node.blocks.shift(); - if (!self) return; - - let child = build(node, buildBody); - if (!child) { - // last item - child = buildBody(); - - // add a filter as this is our final stop - if (node.filter) { - child = t.ifStatement(node.filter, t.blockStatement([child])); - } - } - - return t.forOfStatement( - t.variableDeclaration("let", [t.variableDeclarator(self.left)]), - self.right, - t.blockStatement([child]) - ); -} diff --git a/packages/babel-core/src/transformation/helpers/build-react-transformer.js b/packages/babel-core/src/transformation/helpers/build-react-transformer.js deleted file mode 100644 index 6a2c904250..0000000000 --- a/packages/babel-core/src/transformation/helpers/build-react-transformer.js +++ /dev/null @@ -1,159 +0,0 @@ -// Based upon the excellent jsx-transpiler by Inglet Stepanyan (RReverser) -// https://github.com/RReverser/jsx-transpiler - -// jsx - -import isString from "lodash/lang/isString"; -import * as messages from "babel-messages"; -import esutils from "esutils"; -import { react } from "babel-types"; -import * as t from "babel-types"; - -export default function (opts) { - let visitor = {}; - - visitor.JSXIdentifier = function (node) { - if (node.name === "this" && this.isReferenced()) { - return t.thisExpression(); - } else if (esutils.keyword.isIdentifierNameES6(node.name)) { - node.type = "Identifier"; - } else { - return t.stringLiteral(node.name); - } - }; - - visitor.JSXNamespacedName = function () { - throw this.errorWithNode(messages.get("JSXNamespacedTags")); - }; - - visitor.JSXMemberExpression = { - exit(node) { - node.computed = t.isLiteral(node.property); - node.type = "MemberExpression"; - } - }; - - visitor.JSXExpressionContainer = function (node) { - return node.expression; - }; - - visitor.JSXAttribute = { - enter(node) { - let value = node.value; - if (t.isLiteral(value) && isString(value.value)) { - value.value = value.value.replace(/\n\s+/g, " "); - } - }, - - exit(node) { - let value = node.value || t.booleanLiteral(true); - return t.inherits(t.property("init", node.name, value), node); - } - }; - - visitor.JSXOpeningElement = { - exit(node, parent, scope, file) { - parent.children = react.buildChildren(parent); - - let tagExpr = node.name; - let args = []; - - let tagName; - if (t.isIdentifier(tagExpr)) { - tagName = tagExpr.name; - } else if (t.isLiteral(tagExpr)) { - tagName = tagExpr.value; - } - - let state = { - tagExpr: tagExpr, - tagName: tagName, - args: args - }; - - if (opts.pre) { - opts.pre(state, file); - } - - let attribs = node.attributes; - if (attribs.length) { - attribs = buildJSXOpeningElementAttributes(attribs, file); - } else { - attribs = t.nullLiteral(); - } - - args.push(attribs); - - if (opts.post) { - opts.post(state, file); - } - - return state.call || t.callExpression(state.callee, args); - } - }; - - /** - * The logic for this is quite terse. It's because we need to - * support spread elements. We loop over all attributes, - * breaking on spreads, we then push a new object containg - * all prior attributes to an array for later processing. - */ - - let buildJSXOpeningElementAttributes = function (attribs, file) { - let _props = []; - let objs = []; - - let pushProps = function () { - if (!_props.length) return; - - objs.push(t.objectExpression(_props)); - _props = []; - }; - - while (attribs.length) { - let prop = attribs.shift(); - if (t.isJSXSpreadAttribute(prop)) { - pushProps(); - objs.push(prop.argument); - } else { - _props.push(prop); - } - } - - pushProps(); - - if (objs.length === 1) { - // only one object - attribs = objs[0]; - } else { - // looks like we have multiple objects - if (!t.isObjectExpression(objs[0])) { - objs.unshift(t.objectExpression([])); - } - - // spread it - attribs = t.callExpression( - file.addHelper("extends"), - objs - ); - } - - return attribs; - }; - - visitor.JSXElement = { - exit(node) { - let callExpr = node.openingElement; - - callExpr.arguments = callExpr.arguments.concat(node.children); - - if (callExpr.arguments.length >= 3) { - callExpr._prettyCall = true; - } - - return t.inherits(callExpr, node); - } - }; - - return visitor; -} diff --git a/packages/babel-core/src/transformation/helpers/call-delegate.js b/packages/babel-core/src/transformation/helpers/call-delegate.js deleted file mode 100644 index b12c9287c9..0000000000 --- a/packages/babel-core/src/transformation/helpers/call-delegate.js +++ /dev/null @@ -1,36 +0,0 @@ -/* @flow */ - -import type { Scope } from "babel-traverse"; -import * as t from "babel-types"; - -let visitor = { - enter(path, state) { - if (path.isThisExpression() || path.isReferencedIdentifier({ name: "arguments" })) { - state.found = true; - path.stop(); - } - }, - - Function(path) { - path.skip(); - } -}; - -export default function (node: Object, scope: Scope) { - let container = t.functionExpression(null, [], node.body, node.generator, node.async); - - let callee = container; - let args = []; - - let state = { found: false }; - scope.traverse(node, visitor, state); - if (state.found) { - callee = t.memberExpression(container, t.identifier("apply")); - args = [t.thisExpression(), t.identifier("arguments")]; - } - - let call = t.callExpression(callee, args); - if (node.generator) call = t.yieldExpression(call, true); - - return t.returnStatement(call); -} diff --git a/packages/babel-core/src/transformation/helpers/remap-async-to-generator.js b/packages/babel-core/src/transformation/helpers/remap-async-to-generator.js deleted file mode 100644 index 2cd9a9aca5..0000000000 --- a/packages/babel-core/src/transformation/helpers/remap-async-to-generator.js +++ /dev/null @@ -1,66 +0,0 @@ -/* @flow */ - -import type { NodePath } from "babel-traverse"; -import * as t from "babel-types"; - -let awaitVisitor = { - Function(path) { - path.skip(); - }, - - AwaitExpression({ node }) { - node.type = "YieldExpression"; - - if (node.all) { - // await* foo; -> yield Promise.all(foo); - node.all = false; - node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]); - } - } -}; - -let referenceVisitor = { - ReferencedIdentifier({ node, scope }, state) { - let name = state.id.name; - if (node.name === name && scope.bindingIdentifierEquals(name, state.id)) { - return state.ref = state.ref || scope.generateUidIdentifier(name); - } - } -}; - -export default function (path: NodePath, callId: Object) { - let node = path.node; - - node.async = false; - node.generator = true; - - path.traverse(awaitVisitor); - - let call = t.callExpression(callId, [node]); - - let id = node.id; - node.id = null; - - if (t.isFunctionDeclaration(node)) { - let declar = t.variableDeclaration("let", [ - t.variableDeclarator(id, call) - ]); - declar._blockHoist = true; - return declar; - } else { - node.type = "FunctionExpression"; - - if (id) { - let state = { id, ref: null }; - - path.traverse(referenceVisitor, state); - - if (state.ref) { - path.scope.parent.push({ id: state.ref }); - return t.assignmentExpression("=", state.ref, call); - } - } - - return call; - } -} diff --git a/packages/babel-core/src/transformation/index.js b/packages/babel-core/src/transformation/index.js deleted file mode 100644 index daf3499a03..0000000000 --- a/packages/babel-core/src/transformation/index.js +++ /dev/null @@ -1,10 +0,0 @@ -/* @flow */ - -import Pipeline from "./pipeline"; - -let pipeline = new Pipeline; -let transform = pipeline.transform.bind(pipeline); -transform.fromAst = pipeline.transformFromAst.bind(pipeline); -transform.lint = pipeline.lint.bind(pipeline); -transform.pipeline = pipeline; -export default transform; diff --git a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js index 3f13629329..c37525dc37 100644 --- a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js +++ b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js @@ -6,12 +6,12 @@ import * as t from "babel-types"; export default new Plugin({ visitor: { ThisExpression(path) { - return remap(path, "this", () => t.thisExpression()); + remap(path, "this", () => t.thisExpression()); }, ReferencedIdentifier(path) { if (path.node.name === "arguments") { - return remap(path, "arguments", () => t.identifier("arguments")); + remap(path, "arguments", () => t.identifier("arguments")); } } } @@ -56,7 +56,7 @@ function remap(path, key, create) { if (fnPath === currentFunction) return; let cached = fnPath.getData(key); - if (cached) return cached; + if (cached) return path.replaceWith(cached); let init = create(); let id = path.scope.generateUidIdentifier(key); @@ -64,5 +64,5 @@ function remap(path, key, create) { fnPath.setData(key, id); fnPath.scope.push({ id, init }); - return id; + return path.replaceWith(id); } diff --git a/packages/babel-core/src/transformation/modules/_default.js b/packages/babel-core/src/transformation/modules/_default.js deleted file mode 100644 index 30b6549702..0000000000 --- a/packages/babel-core/src/transformation/modules/_default.js +++ /dev/null @@ -1,298 +0,0 @@ -/* @flow */ - -import type { File, FileModulesMetadata } from "../file"; -import type { Scope, NodePath } from "babel-traverse"; -import * as metadataVisitor from "./lib/metadata"; -import * as messages from "babel-messages"; -import Remaps from "./lib/remaps"; -import * as util from "../../util"; -import * as t from "babel-types"; - -export default class DefaultFormatter { - constructor(file: File) { - // object containg all module sources with the scope that they're contained in - this.sourceScopes = Object.create(null); - - // ids for use in module ids - this.defaultIds = Object.create(null); - this.ids = Object.create(null); - - // contains reference aliases for live bindings - this.remaps = new Remaps(file, this); - - this.scope = file.scope; - this.file = file; - - this.hasNonDefaultExports = false; - - this.hasLocalExports = false; - this.hasLocalImports = false; - - this.localExports = Object.create(null); - this.localImports = Object.create(null); - - this.metadata = file.metadata.modules; - this.getMetadata(); - } - - sourceScopes: Object; - defaultIds: Object; - ids: Object; - remaps: Remaps; - scope: Scope; - file: File; - hasNonDefaultExports: boolean; - hasLocalExports: boolean; - hasLocalImports: boolean; - localExports: Object; - localImports: Object; - metadata: FileModulesMetadata; - - addScope(path: NodePath) { - let source = path.node.source && path.node.source.value; - if (!source) return; - - let existingScope = this.sourceScopes[source]; - if (existingScope && existingScope !== path.scope) { - throw path.buildCodeFrameError(messages.get("modulesDuplicateDeclarations")); - } - - this.sourceScopes[source] = path.scope; - } - - isModuleType(node: Object, type: string): boolean { - let modules = this.file.dynamicImportTypes[type]; - return modules && modules.indexOf(node) >= 0; - } - - transform() { - this.remapAssignments(); - } - - doDefaultExportInterop(node: Object): Object { - return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports; - } - - getMetadata() { - let has = false; - for (let node of (this.file.ast.program.body: Array)) { - if (t.isModuleDeclaration(node)) { - has = true; - break; - } - } - if (has) { - this.file.path.traverse(metadataVisitor, this); - } - } - - remapAssignments() { - if (this.hasLocalExports || this.hasLocalImports) { - this.remaps.run(); - } - } - - remapExportAssignment(node: Object, exported: Array) { - let assign = node; - - for (let prop of exported) { - assign = t.assignmentExpression( - "=", - t.memberExpression(t.identifier("exports"), prop), - assign - ); - } - - return assign; - } - - _addExport(name: string, exported: Array) { - let info = this.localExports[name] = this.localExports[name] || { - binding: this.scope.getBindingIdentifier(name), - exported: [] - }; - info.exported.push(exported); - } - - getExport(node: Object, scope: Scope) { - if (!t.isIdentifier(node)) return; - - let local = this.localExports[node.name]; - if (local && local.binding === scope.getBindingIdentifier(node.name)) { - return local.exported; - } - } - - getModuleName(): string { - let opts = this.file.opts; - - // moduleId is n/a if a `getModuleId()` is provided - if (opts.moduleId != null && !opts.getModuleId) { - return opts.moduleId; - } - - let filenameRelative = opts.filenameRelative; - let moduleName = ""; - - if (opts.moduleRoot != null) { - moduleName = opts.moduleRoot + "/"; - } - - if (!opts.filenameRelative) { - return moduleName + opts.filename.replace(/^\//, ""); - } - - if (opts.sourceRoot != null) { - // remove sourceRoot from filename - let sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?"); - filenameRelative = filenameRelative.replace(sourceRootRegEx, ""); - } - - if (!opts.keepModuleIdExtensions) { - // remove extension - filenameRelative = filenameRelative.replace(/\.(\w*?)$/, ""); - } - - moduleName += filenameRelative; - - // normalize path separators - moduleName = moduleName.replace(/\\/g, "/"); - - if (opts.getModuleId) { - // If return is falsy, assume they want us to use our generated default name - return opts.getModuleId(moduleName) || moduleName; - } else { - return moduleName; - } - } - - _pushStatement(ref: Object, nodes: Array): Object { - if (t.isClass(ref) || t.isFunction(ref)) { - if (ref.id) { - nodes.push(t.toStatement(ref)); - ref = ref.id; - } - } - - return ref; - } - - _hoistExport(declar: Object, assign: Object, priority?: number): Object { - if (t.isFunctionDeclaration(declar)) { - assign._blockHoist = priority || 2; - } - - return assign; - } - - getExternalReference(node: Object, nodes: Array): Object { - let ids = this.ids; - let id = node.source.value; - - if (ids[id]) { - return ids[id]; - } else { - return this.ids[id] = this._getExternalReference(node, nodes); - } - } - - _getExternalReference() { - throw new Error("Should be implemented"); - } - - checkExportIdentifier(node) { - if (t.isIdentifier(node, { name: "__esModule" })) { - throw this.file.buildCodeFrameError(node, messages.get("modulesIllegalExportName", node.name)); - } - } - - exportAllDeclaration(node: Object, nodes: Array) { - let ref = this.getExternalReference(node, nodes); - nodes.push(this.buildExportsWildcard(ref, node)); - } - - exportSpecifier(specifier: Object, node: Object, nodes: Array) { - if (node.source) { - let ref = this.getExternalReference(node, nodes); - - 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 { - ref = t.memberExpression(ref, specifier.local); - - nodes.push(this.buildExportsFromAssignment(specifier.exported, ref, node)); - return; - } - - // export { foo } from "test"; - nodes.push(this.buildExportsAssignment(specifier.exported, ref, node)); - } else { - // export { foo }; - nodes.push(this.buildExportsAssignment(specifier.exported, specifier.local, node)); - } - } - - buildExportsWildcard(objectIdentifier: Object) { - return t.expressionStatement(t.callExpression(this.file.addHelper("defaults"), [ - t.identifier("exports"), - t.callExpression(this.file.addHelper("interop-export-wildcard"), [ - objectIdentifier, - this.file.addHelper("defaults") - ]) - ])); - } - - buildExportsFromAssignment(id: Object, init: Object) { - this.checkExportIdentifier(id); - return util.template("exports-from-assign", { - INIT: init, - ID: t.stringLiteral(id.name) - }, true); - } - - buildExportsAssignment(id, init) { - this.checkExportIdentifier(id); - return util.template("exports-assign", { - VALUE: init, - KEY: id - }, true); - } - - exportDeclaration(node: Object, nodes: Array) { - let declar = node.declaration; - - let id = declar.id; - - if (t.isExportDefaultDeclaration(node)) { - id = t.identifier("default"); - } - - let assign; - - if (t.isVariableDeclaration(declar)) { - for (let i = 0; i < declar.declarations.length; i++) { - let decl = declar.declarations[i]; - - decl.init = this.buildExportsAssignment(decl.id, decl.init, node).expression; - - let newDeclar = t.variableDeclaration(declar.kind, [decl]); - if (i === 0) t.inherits(newDeclar, declar); - nodes.push(newDeclar); - } - } else { - let ref = declar; - - if (t.isFunctionDeclaration(declar) || t.isClassDeclaration(declar)) { - ref = declar.id; - nodes.push(declar); - } - - assign = this.buildExportsAssignment(id, ref, node); - - nodes.push(assign); - - this._hoistExport(declar, assign); - } - } -} diff --git a/packages/babel-core/src/transformation/modules/_strict.js b/packages/babel-core/src/transformation/modules/_strict.js deleted file mode 100644 index fe705bc984..0000000000 --- a/packages/babel-core/src/transformation/modules/_strict.js +++ /dev/null @@ -1,15 +0,0 @@ -/* @flow */ - -import * as util from "../../util"; - -export default function (Parent: Function): Function { - function Constructor() { - this.noInteropRequireImport = true; - this.noInteropRequireExport = true; - Parent.apply(this, arguments); - } - - util.inherits(Constructor, Parent); - - return Constructor; -} diff --git a/packages/babel-core/src/transformation/modules/amd-strict.js b/packages/babel-core/src/transformation/modules/amd-strict.js deleted file mode 100644 index 98422e148e..0000000000 --- a/packages/babel-core/src/transformation/modules/amd-strict.js +++ /dev/null @@ -1,6 +0,0 @@ -/* @flow */ - -import AMDFormatter from "./amd"; -import buildStrict from "./_strict"; - -export default buildStrict(AMDFormatter); diff --git a/packages/babel-core/src/transformation/modules/amd.js b/packages/babel-core/src/transformation/modules/amd.js deleted file mode 100644 index 646d98edc8..0000000000 --- a/packages/babel-core/src/transformation/modules/amd.js +++ /dev/null @@ -1,145 +0,0 @@ -/* @flow */ - -import DefaultFormatter from "./_default"; -import CommonFormatter from "./common"; -import includes from "lodash/collection/includes"; -import values from "lodash/object/values"; -import * as util from "../../util"; -import * as t from "babel-types"; - -export default class AMDFormatter extends DefaultFormatter { - setup() { - CommonFormatter.prototype._setup.call(this, this.hasNonDefaultExports); - } - - buildDependencyLiterals() { - let names = []; - for (let name in this.ids) { - names.push(t.stringLiteral(name)); - } - return names; - } - - /** - * Wrap the entire body in a `define` wrapper. - */ - - transform(program) { - CommonFormatter.prototype.transform.apply(this, arguments); - - let body = program.body; - - // build an array of module names - - let names = [t.stringLiteral("exports")]; - if (this.passModuleArg) names.push(t.stringLiteral("module")); - names = names.concat(this.buildDependencyLiterals()); - names = t.arrayExpression(names); - - // build up define container - - let params = values(this.ids); - if (this.passModuleArg) params.unshift(t.identifier("module")); - params.unshift(t.identifier("exports")); - - let container = t.functionExpression(null, params, t.blockStatement(body)); - - let defineArgs = [names, container]; - let moduleName = this.getModuleName(); - if (moduleName) defineArgs.unshift(t.stringLiteral(moduleName)); - - let call = t.callExpression(t.identifier("define"), defineArgs); - - program.body = [t.expressionStatement(call)]; - } - - /** - * Get the AMD module name that we'll prepend to the wrapper - * to define this module - */ - - getModuleName() { - if (this.file.opts.moduleIds) { - return DefaultFormatter.prototype.getModuleName.apply(this, arguments); - } else { - return null; - } - } - - _getExternalReference(node) { - return this.scope.generateUidIdentifier(node.source.value); - } - - importDeclaration(node) { - this.getExternalReference(node); - } - - importSpecifier(specifier, node, nodes, scope) { - let key = node.source.value; - let ref = this.getExternalReference(node); - - if (t.isImportNamespaceSpecifier(specifier) || t.isImportDefaultSpecifier(specifier)) { - this.defaultIds[key] = specifier.local; - } - - if (this.isModuleType(node, "absolute")) { - // absolute module reference - } else if (this.isModuleType(node, "absoluteDefault")) { - // prevent unnecessary renaming of dynamic imports - this.ids[node.source.value] = ref; - ref = t.memberExpression(ref, t.identifier("default")); - } else if (t.isImportNamespaceSpecifier(specifier)) { - // import * as bar from "foo"; - } else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) { - // import foo from "foo"; - let uid = scope.generateUidIdentifier(specifier.local.name); - nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref])) - ])); - ref = t.memberExpression(uid, t.identifier("default")); - } else { - // import { foo } from "foo"; - let imported = specifier.imported; - if (t.isSpecifierDefault(specifier)) imported = t.identifier("default"); - ref = t.memberExpression(ref, imported); - } - - this.remaps.add(scope, specifier.local.name, ref); - } - - exportSpecifier(specifier, node, nodes) { - if (this.doDefaultExportInterop(specifier)) { - this.passModuleArg = true; - - if (specifier.exported !== specifier.local && !node.source) { - nodes.push(util.template("exports-default-assign", { - VALUE: specifier.local - }, true)); - return; - } - } - - CommonFormatter.prototype.exportSpecifier.apply(this, arguments); - } - - exportDeclaration(node, nodes) { - if (this.doDefaultExportInterop(node)) { - this.passModuleArg = true; - - let declar = node.declaration; - let assign = util.template("exports-default-assign", { - VALUE: this._pushStatement(declar, nodes) - }, true); - - if (t.isFunctionDeclaration(declar)) { - // we can hoist this assignment to the top of the file - assign._blockHoist = 3; - } - - nodes.push(assign); - return; - } - - DefaultFormatter.prototype.exportDeclaration.apply(this, arguments); - } -} diff --git a/packages/babel-core/src/transformation/modules/common-strict.js b/packages/babel-core/src/transformation/modules/common-strict.js deleted file mode 100644 index c02ae2e75b..0000000000 --- a/packages/babel-core/src/transformation/modules/common-strict.js +++ /dev/null @@ -1,6 +0,0 @@ -/* @flow */ - -import CommonFormatter from "./common"; -import buildStrict from "./_strict"; - -export default buildStrict(CommonFormatter); diff --git a/packages/babel-core/src/transformation/modules/common.js b/packages/babel-core/src/transformation/modules/common.js deleted file mode 100644 index 1f81d20b68..0000000000 --- a/packages/babel-core/src/transformation/modules/common.js +++ /dev/null @@ -1,123 +0,0 @@ -import DefaultFormatter from "./_default"; -import * as util from "../../util"; -import * as t from "babel-types"; - -export default class CommonJSFormatter extends DefaultFormatter { - setup() { - this._setup(this.hasLocalExports); - } - - _setup(conditional) { - let file = this.file; - let scope = file.scope; - - scope.rename("module"); - scope.rename("exports"); - - if (!this.noInteropRequireImport && conditional) { - let templateName = "exports-module-declaration"; - if (this.file.isLoose("es6.modules")) templateName += "-loose"; - let declar = util.template(templateName, true); - declar._blockHoist = 3; - file.path.unshiftContainer("body", [declar]); - } - } - - transform(program) { - DefaultFormatter.prototype.transform.apply(this, arguments); - - if (this.hasDefaultOnlyExport) { - program.body.push( - t.expressionStatement(t.assignmentExpression( - "=", - t.memberExpression(t.identifier("module"), t.identifier("exports")), - t.memberExpression(t.identifier("exports"), t.identifier("default")) - )) - ); - } - } - - importSpecifier(specifier, node, nodes, scope) { - let variableName = specifier.local; - - let ref = this.getExternalReference(node, nodes); - - // import foo from "foo"; - if (t.isSpecifierDefault(specifier)) { - if (this.isModuleType(node, "absolute")) { - // absolute module reference - } else if (this.isModuleType(node, "absoluteDefault")) { - this.remaps.add(scope, variableName.name, ref); - } else if (this.noInteropRequireImport) { - this.remaps.add(scope, variableName.name, t.memberExpression(ref, t.identifier("default"))); - } else { - let uid = this.scope.generateUidIdentifierBasedOnNode(node, "import"); - - nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref])) - ])); - - this.remaps.add(scope, variableName.name, t.memberExpression(uid, t.identifier("default"))); - } - } else { - if (t.isImportNamespaceSpecifier(specifier)) { - if (!this.noInteropRequireImport) { - ref = t.callExpression(this.file.addHelper("interop-require-wildcard"), [ref]); - } - - // import * as bar from "foo"; - nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(variableName, ref) - ])); - } else { - // import { foo } from "foo"; - this.remaps.add(scope, variableName.name, - t.memberExpression(ref, t.identifier(specifier.imported.name))); - } - } - } - - importDeclaration(node, nodes) { - // import "foo"; - nodes.push(util.template("require", { - MODULE_NAME: node.source - }, true)); - } - - exportSpecifier(specifier) { - if (this.doDefaultExportInterop(specifier)) { - this.hasDefaultOnlyExport = true; - } - - DefaultFormatter.prototype.exportSpecifier.apply(this, arguments); - } - - exportDeclaration(node) { - if (this.doDefaultExportInterop(node)) { - this.hasDefaultOnlyExport = true; - } - - DefaultFormatter.prototype.exportDeclaration.apply(this, arguments); - } - - _getExternalReference(node, nodes) { - let call = t.callExpression(t.identifier("require"), [node.source]); - let uid; - - if (this.isModuleType(node, "absolute")) { - // absolute module reference - } else if (this.isModuleType(node, "absoluteDefault")) { - call = t.memberExpression(call, t.identifier("default")); - } else { - uid = this.scope.generateUidIdentifierBasedOnNode(node, "import"); - } - - uid = uid || node.specifiers[0].local; - - let declar = t.variableDeclaration("var", [ - t.variableDeclarator(uid, call) - ]); - nodes.push(declar); - return uid; - } -} diff --git a/packages/babel-core/src/transformation/modules/ignore.js b/packages/babel-core/src/transformation/modules/ignore.js deleted file mode 100644 index b9c3ff627c..0000000000 --- a/packages/babel-core/src/transformation/modules/ignore.js +++ /dev/null @@ -1,17 +0,0 @@ -/* @flow */ - -import DefaultFormatter from "./_default"; -import * as t from "babel-types"; - -export default class IgnoreFormatter extends DefaultFormatter { - exportDeclaration(node, nodes) { - let declar = t.toStatement(node.declaration, true); - if (declar) nodes.push(t.inherits(declar, node)); - } - - exportAllDeclaration() {} - importDeclaration() {} - importSpecifier() {} - exportSpecifier() {} - transform() {} -} diff --git a/packages/babel-core/src/transformation/modules/index.js b/packages/babel-core/src/transformation/modules/index.js deleted file mode 100644 index c7c7a598e7..0000000000 --- a/packages/babel-core/src/transformation/modules/index.js +++ /dev/null @@ -1,16 +0,0 @@ -/* @flow */ - -/** - * [Please add a description.] - */ - -export default { - commonStrict: require("./common-strict"), - amdStrict: require("./amd-strict"), - umdStrict: require("./umd-strict"), - common: require("./common"), - system: require("./system"), - ignore: require("./ignore"), - amd: require("./amd"), - umd: require("./umd") -}; diff --git a/packages/babel-core/src/transformation/modules/lib/remaps.js b/packages/babel-core/src/transformation/modules/lib/remaps.js deleted file mode 100644 index 3c7303428e..0000000000 --- a/packages/babel-core/src/transformation/modules/lib/remaps.js +++ /dev/null @@ -1,124 +0,0 @@ -/* @flow */ - -import * as t from "babel-types"; - -let remapVisitor = { - enter(node) { - if (node._skipModulesRemap) { - return this.skip(); - } - }, - - ReferencedIdentifier(node, parent, scope, remaps) { - let { formatter } = remaps; - - let remap = remaps.get(scope, node.name); - if (!remap || node === remap) return; - - if (!scope.hasBinding(node.name) || - scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) { - if (!formatter.isLoose() && this.key === "callee" && this.parentPath.isCallExpression()) { - return t.sequenceExpression([t.numberLiteral(0), remap]); - } else { - return remap; - } - } - }, - - AssignmentExpression: { - exit(node, parent, scope, { formatter }) { - if (!node._ignoreModulesRemap) { - let exported = formatter.getExport(node.left, scope); - if (exported) { - return formatter.remapExportAssignment(node, exported); - } - } - } - }, - - UpdateExpression(node, parent, scope, { formatter }) { - let exported = formatter.getExport(node.argument, scope); - if (!exported) return; - - this.skip(); - - // expand to long file assignment expression - let assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.numberLiteral(1)); - - // remap this assignment expression - let remapped = formatter.remapExportAssignment(assign, exported); - - // we don't need to change the result - if (t.isExpressionStatement(parent) || node.prefix) { - return remapped; - } - - let nodes = []; - nodes.push(remapped); - - let operator; - if (node.operator === "--") { - operator = "+"; - } else { // "++" - operator = "-"; - } - nodes.push(t.binaryExpression(operator, node.argument, t.numberLiteral(1))); - - return t.sequenceExpression(nodes); - } -}; - -export default class Remaps { - constructor(file, formatter) { - this.formatter = formatter; - this.file = file; - } - - run() { - this.file.path.traverse(remapVisitor, this); - } - - _getKey(name) { - return `${name}:moduleRemap`; - } - - get(scope, name) { - return scope.getData(this._getKey(name)); - } - - add(scope, name, val) { - if (this.all) { - this.all.push({ - name, - scope, - node: val - }); - } - - return scope.setData(this._getKey(name), val); - } - - remove(scope, name) { - return scope.removeData(this._getKey(name)); - } - - /** - * These methods are used by the system module formatter who needs access to all the remaps - * so it can process them into it's specific setter method. We don't do this by default since - * no other module formatters need access to this. - */ - - getAll() { - return this.all; - } - - clearAll() { - if (this.all) { - for (let remap of (this.all: Array)) { - remap.scope.removeData(this._getKey(remap.name)); - } - } - - this.all = []; - } -} diff --git a/packages/babel-core/src/transformation/modules/system.js b/packages/babel-core/src/transformation/modules/system.js deleted file mode 100644 index 721e676e32..0000000000 --- a/packages/babel-core/src/transformation/modules/system.js +++ /dev/null @@ -1,226 +0,0 @@ -/* @flow */ - -import DefaultFormatter from "./_default"; -import AMDFormatter from "./amd"; -import * as util from "../../util"; -import last from "lodash/array/last"; -import map from "lodash/collection/map"; -import * as t from "babel-types"; - -let hoistVariablesVisitor = { - Function(path) { - // nothing inside is accessible - path.skip(); - }, - - VariableDeclaration({ node, parent }, state) { - if (node.kind !== "var" && !t.isProgram(parent)) { // let, const - // can't be accessed - return; - } - - // ignore block hoisted nodes as these can be left in - if (state.formatter._canHoist(node)) return; - - let nodes = []; - - for (let i = 0; i < node.declarations.length; i++) { - let declar = node.declarations[i]; - state.hoistDeclarators.push(t.variableDeclarator(declar.id)); - if (declar.init) { - // no initializer so we can just hoist it as-is - let assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init)); - nodes.push(assign); - } - } - - // for (let i in test) - if (t.isFor(parent) && parent.left === node) { - return node.declarations[0].id; - } - - return nodes; - } -}; - -let hoistFunctionsVisitor = { - Function(path) { - path.skip(); - }, - - enter(path, state) { - if (path.isFunctionDeclaration() || state.formatter._canHoist(path.node)) { - state.handlerBody.push(path.node); - path.remove(); - } - } -}; - -let runnerSettersVisitor = { - enter(path, state) { - let { node } = path; - - if (node._importSource === state.source) { - if (t.isVariableDeclaration(node)) { - for (let declar of (node.declarations: Array)) { - state.hoistDeclarators.push(t.variableDeclarator(declar.id)); - state.nodes.push(t.expressionStatement( - t.assignmentExpression("=", declar.id, declar.init) - )); - } - } else { - state.nodes.push(node); - } - - path.remove(); - } - } -}; - -export default class SystemFormatter extends AMDFormatter { - constructor(file) { - super(file); - - this._setters = null; - this.exportIdentifier = file.scope.generateUidIdentifier("export"); - this.noInteropRequireExport = true; - this.noInteropRequireImport = true; - - this.remaps.clearAll(); - } - - _addImportSource(node, exportNode) { - if (node) node._importSource = exportNode.source && exportNode.source.value; - return node; - } - - buildExportsWildcard(objectIdentifier, node) { - let leftIdentifier = this.scope.generateUidIdentifier("key"); - let valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true); - - let left = t.variableDeclaration("var", [ - t.variableDeclarator(leftIdentifier) - ]); - - let right = objectIdentifier; - - let block = t.blockStatement([ - t.ifStatement( - t.binaryExpression("!==", leftIdentifier, t.stringLiteral("default")), - t.expressionStatement(this._buildExportCall(leftIdentifier, valIdentifier)) - ) - ]); - - return this._addImportSource(t.forInStatement(left, right, block), node); - } - - buildExportsAssignment(id, init, node) { - let call = this._buildExportCall(t.stringLiteral(id.name), init, true); - return this._addImportSource(call, node); - } - - buildExportsFromAssignment() { - return this.buildExportsAssignment(...arguments); - } - - remapExportAssignment(node, exported) { - let assign = node; - - for (let i = 0; i < exported.length; i++) { - assign = this._buildExportCall(t.stringLiteral(exported[i].name), assign); - } - - return assign; - } - - _buildExportCall(id, init, isStatement) { - let call = t.callExpression(this.exportIdentifier, [id, init]); - if (isStatement) { - return t.expressionStatement(call); - } else { - return call; - } - } - - importSpecifier(specifier, node, nodes) { - AMDFormatter.prototype.importSpecifier.apply(this, arguments); - - for (let remap of (this.remaps.getAll(): Array)) { - nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(t.identifier(remap.name), remap.node) - ])); - } - - this.remaps.clearAll(); - - this._addImportSource(last(nodes), node); - } - - _buildRunnerSetters(block, hoistDeclarators) { - let scope = this.file.scope; - - return t.arrayExpression(map(this.ids, function (uid, source) { - let state = { - hoistDeclarators: hoistDeclarators, - source: source, - nodes: [] - }; - - scope.traverse(block, runnerSettersVisitor, state); - - return t.functionExpression(null, [uid], t.blockStatement(state.nodes)); - })); - } - - _canHoist(node) { - return node._blockHoist && !this.file.dynamicImports.length; - } - - transform(program) { - DefaultFormatter.prototype.transform.apply(this, arguments); - - let hoistDeclarators = []; - let moduleName = this.getModuleName(); - let moduleNameLiteral = t.stringLiteral(moduleName); - - let block = t.blockStatement(program.body); - - let setterListNode = this._buildRunnerSetters(block, hoistDeclarators); - this._setters = setterListNode; - - let runner = util.template("system", { - MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()), - EXPORT_IDENTIFIER: this.exportIdentifier, - MODULE_NAME: moduleNameLiteral, - SETTERS: setterListNode, - EXECUTE: t.functionExpression(null, [], block) - }, true); - - let handlerBody = runner.expression.arguments[2].body.body; - if (!moduleName) runner.expression.arguments.shift(); - - let returnStatement = handlerBody.pop(); - - // hoist up all variable declarations - this.file.scope.traverse(block, hoistVariablesVisitor, { - formatter: this, - hoistDeclarators: hoistDeclarators - }); - - if (hoistDeclarators.length) { - let hoistDeclar = t.variableDeclaration("var", hoistDeclarators); - hoistDeclar._blockHoist = true; - handlerBody.unshift(hoistDeclar); - } - - // hoist up function declarations for circular references - this.file.scope.traverse(block, hoistFunctionsVisitor, { - formatter: this, - handlerBody: handlerBody - }); - - handlerBody.push(returnStatement); - - program.body = [runner]; - } -} diff --git a/packages/babel-core/src/transformation/modules/umd-strict.js b/packages/babel-core/src/transformation/modules/umd-strict.js deleted file mode 100644 index 831de7fc25..0000000000 --- a/packages/babel-core/src/transformation/modules/umd-strict.js +++ /dev/null @@ -1,6 +0,0 @@ -/* @flow */ - -import UMDFormatter from "./umd"; -import buildStrict from "./_strict"; - -export default buildStrict(UMDFormatter); diff --git a/packages/babel-core/src/transformation/modules/umd.js b/packages/babel-core/src/transformation/modules/umd.js deleted file mode 100644 index 57955e82ed..0000000000 --- a/packages/babel-core/src/transformation/modules/umd.js +++ /dev/null @@ -1,85 +0,0 @@ -/* @flow */ - -import DefaultFormatter from "./_default"; -import AMDFormatter from "./amd"; -import values from "lodash/object/values"; -import path from "path"; -import * as util from "../../util"; -import * as t from "babel-types"; - -export default class UMDFormatter extends AMDFormatter { - transform(program) { - DefaultFormatter.prototype.transform.apply(this, arguments); - - let body = program.body; - - // build an array of module names - - let names = []; - for (let name in this.ids) { - names.push(t.stringLiteral(name)); - } - - // factory - - let ids = values(this.ids); - let args = [t.identifier("exports")]; - if (this.passModuleArg) args.push(t.identifier("module")); - args = args.concat(ids); - - let factory = t.functionExpression(null, args, t.blockStatement(body)); - - // amd - - let defineArgs = [t.stringLiteral("exports")]; - if (this.passModuleArg) defineArgs.push(t.stringLiteral("module")); - defineArgs = defineArgs.concat(names); - defineArgs = [t.arrayExpression(defineArgs)]; - - // common - - let testExports = util.template("test-exports"); - let testModule = util.template("test-module"); - let commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports; - - let commonArgs = [t.identifier("exports")]; - if (this.passModuleArg) commonArgs.push(t.identifier("module")); - commonArgs = commonArgs.concat(names.map(function (name) { - return t.callExpression(t.identifier("require"), [name]); - })); - - // globals - - let browserArgs = []; - if (this.passModuleArg) browserArgs.push(t.identifier("mod")); - - for (let name in this.ids) { - let id = this.defaultIds[name] || t.identifier(t.toIdentifier(path.basename(name, path.extname(name)))); - browserArgs.push(t.memberExpression(t.identifier("global"), id)); - } - - // - - let moduleName = this.getModuleName(); - if (moduleName) defineArgs.unshift(t.stringLiteral(moduleName)); - - // - let globalArg = this.file.opts.basename; - if (moduleName) globalArg = moduleName; - globalArg = t.identifier(t.toIdentifier(globalArg)); - - let runner = util.template("umd-runner-body", { - AMD_ARGUMENTS: defineArgs, - COMMON_TEST: commonTests, - COMMON_ARGUMENTS: commonArgs, - BROWSER_ARGUMENTS: browserArgs, - GLOBAL_ARG: globalArg - }); - - // - - program.body = [t.expressionStatement( - t.callExpression(runner, [t.thisExpression(), factory]) - )]; - } -} diff --git a/packages/babel-core/src/transformation/plugin-pass.js b/packages/babel-core/src/transformation/plugin-pass.js index 93d86d84c0..1fe9385941 100644 --- a/packages/babel-core/src/transformation/plugin-pass.js +++ b/packages/babel-core/src/transformation/plugin-pass.js @@ -1,11 +1,13 @@ /* @flow */ import type Plugin from "./plugin"; +import Store from "../store"; import traverse from "babel-traverse"; import File from "./file"; -export default class PluginPass { +export default class PluginPass extends Store { constructor(file: File, plugin: Plugin, options: Object = {}) { + super(); this.plugin = plugin; this.file = file; this.opts = options; @@ -25,4 +27,16 @@ export default class PluginPass { addHelper(...args) { return this.file.addHelper(...args); } + + addImport(...args) { + return this.file.addImport(...args); + } + + getModuleName(...args) { + return this.file.getModuleName(...args); + } + + buildCodeFrameError(...args) { + return this.file.buildCodeFrameError(...args); + } } diff --git a/packages/babel-core/src/transformation/plugin.js b/packages/babel-core/src/transformation/plugin.js index 81fe760cf4..31c7bcbb5e 100644 --- a/packages/babel-core/src/transformation/plugin.js +++ b/packages/babel-core/src/transformation/plugin.js @@ -1,33 +1,79 @@ /* @flow */ +import OptionManager from "./file/options/option-manager" import * as messages from "babel-messages"; +import Store from "../store"; import traverse from "babel-traverse"; import assign from "lodash/object/assign"; import clone from "lodash/lang/clone"; -export default class Plugin { +export default class Plugin extends Store { constructor(plugin: Object) { - plugin = this.raw = assign({}, plugin); + super(); - function take(key) { - let val = plugin[key]; - delete plugin[key]; - return val; - } + this.initialized = false; + this.raw = assign({}, plugin); - this.manipulateOptions = take("manipulateOptions"); - this.post = take("post"); - this.pre = take("pre"); - this.visitor = this.normalize(clone(take("visitor")) || {}); + this.manipulateOptions = this.take("manipulateOptions"); + this.post = this.take("post"); + this.pre = this.take("pre"); + this.visitor = this.normalize(clone(this.take("visitor")) || {}); } + initialized: boolean; raw: Object; manipulateOptions: ?Function; post: ?Function; pre: ?Function; visitor: Object; - validate(loc: string, i: number) { + take(key) { + let val = this.raw[key]; + delete this.raw[key]; + return val; + } + + chain(target, key) { + if (!target[key]) return this[key]; + if (!this[key]) return target[key]; + + let fns: Array = [target[key], this[key]]; + + return function (...args) { + let val; + for (let fn of fns) { + if (fn) { + let ret = fn.apply(this, args); + if (ret != null) val = ret; + } + } + return val; + }; + } + + maybeInherit(loc: string) { + let inherits = this.take("inherits"); + if (!inherits) return; + + inherits = OptionManager.normalisePlugin(inherits, loc, "inherits"); + + this.manipulateOptions = this.chain(inherits, "manipulateOptions"); + this.post = this.chain(inherits, "post"); + this.pre = this.chain(inherits, "pre"); + this.visitor = traverse.visitors.merge([inherits.visitor, this.visitor]); + } + + /** + * We lazy initialise parts of a plugin that rely on contextual information such as + * position on disk and how it was specified. + */ + + init(loc: string, i: number) { + if (this.initialized) return; + this.initialized = true; + + this.maybeInherit(loc); + for (let key in this.raw) { throw new Error(messages.get("pluginInvalidProperty", loc, i, key)); } diff --git a/packages/babel-core/src/transformation/templates/.babelrc b/packages/babel-core/src/transformation/templates/.babelrc deleted file mode 100644 index 43cbf773c1..0000000000 --- a/packages/babel-core/src/transformation/templates/.babelrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "blacklist": ["useStrict", "es6.blockScoping", "regenerator", "es6.spread"], - "loose": ["es6.modules"] -} diff --git a/packages/babel-core/src/transformation/templates/abstract-expression-call.js b/packages/babel-core/src/transformation/templates/abstract-expression-call.js deleted file mode 100644 index 622b0588aa..0000000000 --- a/packages/babel-core/src/transformation/templates/abstract-expression-call.js +++ /dev/null @@ -1 +0,0 @@ -PROPERTY[Symbol.referenceGet](OBJECT).call(OBJECT) diff --git a/packages/babel-core/src/transformation/templates/abstract-expression-delete.js b/packages/babel-core/src/transformation/templates/abstract-expression-delete.js deleted file mode 100644 index a78f195e1f..0000000000 --- a/packages/babel-core/src/transformation/templates/abstract-expression-delete.js +++ /dev/null @@ -1 +0,0 @@ -PROPERTY[Symbol.referenceDelete](OBJECT) diff --git a/packages/babel-core/src/transformation/templates/abstract-expression-get.js b/packages/babel-core/src/transformation/templates/abstract-expression-get.js deleted file mode 100644 index bc8a623e9c..0000000000 --- a/packages/babel-core/src/transformation/templates/abstract-expression-get.js +++ /dev/null @@ -1 +0,0 @@ -PROPERTY[Symbol.referenceGet](OBJECT) diff --git a/packages/babel-core/src/transformation/templates/abstract-expression-set.js b/packages/babel-core/src/transformation/templates/abstract-expression-set.js deleted file mode 100644 index 90a5edd887..0000000000 --- a/packages/babel-core/src/transformation/templates/abstract-expression-set.js +++ /dev/null @@ -1 +0,0 @@ -PROPERTY[Symbol.referenceSet](OBJECT, VALUE) diff --git a/packages/babel-core/src/transformation/templates/array-from.js b/packages/babel-core/src/transformation/templates/array-from.js deleted file mode 100644 index 6e8f155aeb..0000000000 --- a/packages/babel-core/src/transformation/templates/array-from.js +++ /dev/null @@ -1 +0,0 @@ -Array.from(VALUE); diff --git a/packages/babel-core/src/transformation/templates/call.js b/packages/babel-core/src/transformation/templates/call.js deleted file mode 100644 index 23d94f532f..0000000000 --- a/packages/babel-core/src/transformation/templates/call.js +++ /dev/null @@ -1 +0,0 @@ -OBJECT.call(CONTEXT); diff --git a/packages/babel-core/src/transformation/templates/exports-assign.js b/packages/babel-core/src/transformation/templates/exports-assign.js deleted file mode 100644 index c4c06b8a9a..0000000000 --- a/packages/babel-core/src/transformation/templates/exports-assign.js +++ /dev/null @@ -1 +0,0 @@ -exports.KEY = VALUE; diff --git a/packages/babel-core/src/transformation/templates/exports-default-assign.js b/packages/babel-core/src/transformation/templates/exports-default-assign.js deleted file mode 100644 index d10890f8a2..0000000000 --- a/packages/babel-core/src/transformation/templates/exports-default-assign.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = VALUE; diff --git a/packages/babel-core/src/transformation/templates/exports-from-assign.js b/packages/babel-core/src/transformation/templates/exports-from-assign.js deleted file mode 100644 index e784fc1b2a..0000000000 --- a/packages/babel-core/src/transformation/templates/exports-from-assign.js +++ /dev/null @@ -1,6 +0,0 @@ -Object.defineProperty(exports, ID, { - enumerable: true, - get: function () { - return INIT; - } -}); diff --git a/packages/babel-core/src/transformation/templates/exports-module-declaration-loose.js b/packages/babel-core/src/transformation/templates/exports-module-declaration-loose.js deleted file mode 100644 index 32b83d4a5a..0000000000 --- a/packages/babel-core/src/transformation/templates/exports-module-declaration-loose.js +++ /dev/null @@ -1 +0,0 @@ -exports.__esModule = true; diff --git a/packages/babel-core/src/transformation/templates/exports-module-declaration.js b/packages/babel-core/src/transformation/templates/exports-module-declaration.js deleted file mode 100644 index 18efccea8a..0000000000 --- a/packages/babel-core/src/transformation/templates/exports-module-declaration.js +++ /dev/null @@ -1,3 +0,0 @@ -Object.defineProperty(exports, "__esModule", { - value: true -}); diff --git a/packages/babel-core/src/transformation/templates/helper-async-to-generator.js b/packages/babel-core/src/transformation/templates/helper-async-to-generator.js deleted file mode 100644 index 3d7b145184..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-async-to-generator.js +++ /dev/null @@ -1,28 +0,0 @@ -(function (fn) { - return function () { - var gen = fn.apply(this, arguments); - - return new Promise(function (resolve, reject) { - var callNext = step.bind(null, "next"); - var callThrow = step.bind(null, "throw"); - - function step(key, arg) { - try { - var info = gen[key](arg); - var value = info.value; - } catch (error) { - reject(error); - return; - } - - if (info.done) { - resolve(value); - } else { - Promise.resolve(value).then(callNext, callThrow); - } - } - - callNext(); - }); - }; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-bind.js b/packages/babel-core/src/transformation/templates/helper-bind.js deleted file mode 100644 index abe1c0668a..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-bind.js +++ /dev/null @@ -1 +0,0 @@ -Function.prototype.bind diff --git a/packages/babel-core/src/transformation/templates/helper-class-call-check.js b/packages/babel-core/src/transformation/templates/helper-class-call-check.js deleted file mode 100644 index 041dd4b753..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-class-call-check.js +++ /dev/null @@ -1,5 +0,0 @@ -(function (instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } -}); diff --git a/packages/babel-core/src/transformation/templates/helper-create-class.js b/packages/babel-core/src/transformation/templates/helper-create-class.js deleted file mode 100644 index f4b4c20145..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-create-class.js +++ /dev/null @@ -1,17 +0,0 @@ -(function() { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i ++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; -})() diff --git a/packages/babel-core/src/transformation/templates/helper-create-decorated-class.js b/packages/babel-core/src/transformation/templates/helper-create-decorated-class.js deleted file mode 100644 index 61c31b6867..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-create-decorated-class.js +++ /dev/null @@ -1,42 +0,0 @@ -(function() { - function defineProperties(target, descriptors, initializers) { - for (var i = 0; i < descriptors.length; i ++) { - var descriptor = descriptors[i]; - var decorators = descriptor.decorators; - var key = descriptor.key; - - // don't want to expose these to userland since i know people will rely on them - // and think it's spec behaviour - delete descriptor.key; - delete descriptor.decorators; - - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor || descriptor.initializer) descriptor.writable = true; - - if (decorators) { - for (var f = 0; f < decorators.length; f++) { - var decorator = decorators[f]; - if (typeof decorator === "function") { - descriptor = decorator(target, key, descriptor) || descriptor; - } else { - throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator); - } - } - - if (descriptor.initializer !== undefined) { - initializers[key] = descriptor; - continue; - } - } - - Object.defineProperty(target, key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) { - if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers); - if (staticProps) defineProperties(Constructor, staticProps, staticInitializers); - return Constructor; - }; -})() diff --git a/packages/babel-core/src/transformation/templates/helper-create-decorated-object.js b/packages/babel-core/src/transformation/templates/helper-create-decorated-object.js deleted file mode 100644 index e1a6005a31..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-create-decorated-object.js +++ /dev/null @@ -1,37 +0,0 @@ -(function (descriptors) { - var target = {}; - - for (var i = 0; i < descriptors.length; i ++) { - var descriptor = descriptors[i]; - var decorators = descriptor.decorators; - var key = descriptor.key; - - // don't want to expose these to userland since i know people will rely on them - // and think it's spec behaviour - delete descriptor.key; - delete descriptor.decorators; - - descriptor.enumerable = true; - descriptor.configurable = true; - if ("value" in descriptor || descriptor.initializer) descriptor.writable = true; - - if (decorators) { - for (var f = 0; f < decorators.length; f++) { - var decorator = decorators[f]; - if (typeof decorator === "function") { - descriptor = decorator(target, key, descriptor) || descriptor; - } else { - throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator); - } - } - } - - if (descriptor.initializer) { - descriptor.value = descriptor.initializer.call(target); - } - - Object.defineProperty(target, key, descriptor); - } - - return target; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-default-props.js b/packages/babel-core/src/transformation/templates/helper-default-props.js deleted file mode 100644 index 4b2f679253..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-default-props.js +++ /dev/null @@ -1,10 +0,0 @@ -(function (defaultProps, props) { - if (defaultProps) { - for (var propName in defaultProps) { - if (typeof props[propName] === "undefined") { - props[propName] = defaultProps[propName]; - } - } - } - return props; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-defaults.js b/packages/babel-core/src/transformation/templates/helper-defaults.js deleted file mode 100644 index 1553b89089..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-defaults.js +++ /dev/null @@ -1,11 +0,0 @@ -(function (obj, defaults) { - var keys = Object.getOwnPropertyNames(defaults); - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - var value = Object.getOwnPropertyDescriptor(defaults, key); - if (value && value.configurable && obj[key] === undefined) { - Object.defineProperty(obj, key, value); - } - } - return obj; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-define-decorated-property-descriptor.js b/packages/babel-core/src/transformation/templates/helper-define-decorated-property-descriptor.js deleted file mode 100644 index 8f5d415f22..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-define-decorated-property-descriptor.js +++ /dev/null @@ -1,13 +0,0 @@ -(function (target, key, descriptors) { - var _descriptor = descriptors[key]; - if (!_descriptor) return; - - // clone it - var descriptor = {}; - for (var _key in _descriptor) descriptor[_key] = _descriptor[_key]; - - // initialize it - descriptor.value = descriptor.initializer ? descriptor.initializer.call(target) : undefined; - - Object.defineProperty(target, key, descriptor); -}) diff --git a/packages/babel-core/src/transformation/templates/helper-define-property.js b/packages/babel-core/src/transformation/templates/helper-define-property.js deleted file mode 100644 index 2560c05c45..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-define-property.js +++ /dev/null @@ -1,18 +0,0 @@ -(function (obj, key, value) { - // Shortcircuit the slow defineProperty path when possible. - // We are trying to avoid issues where setters defined on the - // prototype cause side effects under the fast path of simple - // assignment. By checking for existence of the property with - // the in operator, we can optimize most of this overhead away. - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); - } else { - obj[key] = value; - } - return obj; -}); diff --git a/packages/babel-core/src/transformation/templates/helper-extends.js b/packages/babel-core/src/transformation/templates/helper-extends.js deleted file mode 100644 index f8276831b1..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-extends.js +++ /dev/null @@ -1,11 +0,0 @@ -Object.assign || (function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; - } - } - } - return target; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-get.js b/packages/babel-core/src/transformation/templates/helper-get.js deleted file mode 100644 index 2b622262e6..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-get.js +++ /dev/null @@ -1,25 +0,0 @@ -(function get(object, property, receiver) { - if (object === null) object = Function.prototype; - - var desc = Object.getOwnPropertyDescriptor(object, property); - - if (desc === undefined) { - var parent = Object.getPrototypeOf(object); - - if (parent === null) { - return undefined; - } else { - return get(parent, property, receiver); - } - } else if ("value" in desc) { - return desc.value; - } else { - var getter = desc.get; - - if (getter === undefined) { - return undefined; - } - - return getter.call(receiver); - } -}); diff --git a/packages/babel-core/src/transformation/templates/helper-has-own.js b/packages/babel-core/src/transformation/templates/helper-has-own.js deleted file mode 100644 index 9a4caad24a..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-has-own.js +++ /dev/null @@ -1 +0,0 @@ -Object.prototype.hasOwnProperty; diff --git a/packages/babel-core/src/transformation/templates/helper-inherits.js b/packages/babel-core/src/transformation/templates/helper-inherits.js deleted file mode 100644 index 87d9ccaede..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-inherits.js +++ /dev/null @@ -1,14 +0,0 @@ -(function (subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); - } - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-instanceof.js b/packages/babel-core/src/transformation/templates/helper-instanceof.js deleted file mode 100644 index 8ce6479f4a..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-instanceof.js +++ /dev/null @@ -1,7 +0,0 @@ -(function (left, right) { - if (right != null && right[Symbol.hasInstance]) { - return right[Symbol.hasInstance](left); - } else { - return left instanceof right; - } -}); diff --git a/packages/babel-core/src/transformation/templates/helper-interop-export-wildcard.js b/packages/babel-core/src/transformation/templates/helper-interop-export-wildcard.js deleted file mode 100644 index d7af1c412f..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-interop-export-wildcard.js +++ /dev/null @@ -1,5 +0,0 @@ -(function (obj, defaults) { - var newObj = defaults({}, obj); - delete newObj.default; - return newObj; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-interop-require-default.js b/packages/babel-core/src/transformation/templates/helper-interop-require-default.js deleted file mode 100644 index 495e2ee2d0..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-interop-require-default.js +++ /dev/null @@ -1,3 +0,0 @@ -(function (obj) { - return obj && obj.__esModule ? obj : { default: obj }; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-interop-require-wildcard.js b/packages/babel-core/src/transformation/templates/helper-interop-require-wildcard.js deleted file mode 100644 index 546e445aba..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-interop-require-wildcard.js +++ /dev/null @@ -1,14 +0,0 @@ -(function (obj) { - if (obj && obj.__esModule) { - return obj; - } else { - var newObj = {}; - if (obj != null) { - for (var key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; - } - } - newObj.default = obj; - return newObj; - } -}) diff --git a/packages/babel-core/src/transformation/templates/helper-interop-require.js b/packages/babel-core/src/transformation/templates/helper-interop-require.js deleted file mode 100644 index 55911c817c..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-interop-require.js +++ /dev/null @@ -1,3 +0,0 @@ -(function (obj) { - return obj && obj.__esModule ? obj.default : obj; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-new-arrow-check.js b/packages/babel-core/src/transformation/templates/helper-new-arrow-check.js deleted file mode 100644 index 3841b83f34..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-new-arrow-check.js +++ /dev/null @@ -1,5 +0,0 @@ -(function (innerThis, boundThis) { - if (innerThis !== boundThis) { - throw new TypeError("Cannot instantiate an arrow function"); - } -}); diff --git a/packages/babel-core/src/transformation/templates/helper-object-destructuring-empty.js b/packages/babel-core/src/transformation/templates/helper-object-destructuring-empty.js deleted file mode 100644 index b2252a935a..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-object-destructuring-empty.js +++ /dev/null @@ -1,3 +0,0 @@ -(function (obj) { - if (obj == null) throw new TypeError("Cannot destructure undefined"); -}); diff --git a/packages/babel-core/src/transformation/templates/helper-object-without-properties.js b/packages/babel-core/src/transformation/templates/helper-object-without-properties.js deleted file mode 100644 index a5ad00f639..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-object-without-properties.js +++ /dev/null @@ -1,9 +0,0 @@ -(function (obj, keys) { - var target = {}; - for (var i in obj) { - if (keys.indexOf(i) >= 0) continue; - if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; - target[i] = obj[i]; - } - return target; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-self-global.js b/packages/babel-core/src/transformation/templates/helper-self-global.js deleted file mode 100644 index 3e55600935..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-self-global.js +++ /dev/null @@ -1 +0,0 @@ -typeof global === "undefined" ? self : global diff --git a/packages/babel-core/src/transformation/templates/helper-set.js b/packages/babel-core/src/transformation/templates/helper-set.js deleted file mode 100644 index e1bbdcc5d9..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-set.js +++ /dev/null @@ -1,21 +0,0 @@ -(function set(object, property, value, receiver) { - var desc = Object.getOwnPropertyDescriptor(object, property); - - if (desc === undefined) { - var parent = Object.getPrototypeOf(object); - - if (parent !== null) { - set(parent, property, value, receiver); - } - } else if ("value" in desc && desc.writable) { - desc.value = value; - } else { - var setter = desc.set; - - if (setter !== undefined) { - setter.call(receiver, value); - } - } - - return value; -}); diff --git a/packages/babel-core/src/transformation/templates/helper-slice.js b/packages/babel-core/src/transformation/templates/helper-slice.js deleted file mode 100644 index f35f3b503b..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-slice.js +++ /dev/null @@ -1 +0,0 @@ -Array.prototype.slice; diff --git a/packages/babel-core/src/transformation/templates/helper-sliced-to-array-loose.js b/packages/babel-core/src/transformation/templates/helper-sliced-to-array-loose.js deleted file mode 100644 index 274222b0c6..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-sliced-to-array-loose.js +++ /dev/null @@ -1,14 +0,0 @@ -(function (arr, i) { - if (Array.isArray(arr)) { - return arr; - } else if (Symbol.iterator in Object(arr)) { - var _arr = []; - for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { - _arr.push(_step.value); - if (i && _arr.length === i) break; - } - return _arr; - } else { - throw new TypeError("Invalid attempt to destructure non-iterable instance"); - } -}); diff --git a/packages/babel-core/src/transformation/templates/helper-sliced-to-array.js b/packages/babel-core/src/transformation/templates/helper-sliced-to-array.js deleted file mode 100644 index 4e59a8ed57..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-sliced-to-array.js +++ /dev/null @@ -1,46 +0,0 @@ -(function () { - // Broken out into a separate function to avoid deoptimizations due to the try/catch for the - // array iterator case. - function sliceIterator(arr, i) { - // this is an expanded form of `for...of` that properly supports abrupt completions of - // iterators etc. variable names have been minimised to reduce the size of this massive - // helper. sometimes spec compliancy is annoying :( - // - // _n = _iteratorNormalCompletion - // _d = _didIteratorError - // _e = _iteratorError - // _i = _iterator - // _s = _step - - var _arr = []; - var _n = true; - var _d = false; - var _e = undefined; - try { - for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { - _arr.push(_s.value); - if (i && _arr.length === i) break; - } - } catch (err) { - _d = true; - _e = err; - } finally { - try { - if (!_n && _i["return"]) _i["return"](); - } finally { - if (_d) throw _e; - } - } - return _arr; - } - - return function (arr, i) { - if (Array.isArray(arr)) { - return arr; - } else if (Symbol.iterator in Object(arr)) { - return sliceIterator(arr, i); - } else { - throw new TypeError("Invalid attempt to destructure non-iterable instance"); - } - }; -})(); diff --git a/packages/babel-core/src/transformation/templates/helper-tagged-template-literal-loose.js b/packages/babel-core/src/transformation/templates/helper-tagged-template-literal-loose.js deleted file mode 100644 index d8dd44bb7a..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-tagged-template-literal-loose.js +++ /dev/null @@ -1,4 +0,0 @@ -(function (strings, raw) { - strings.raw = raw; - return strings; -}); diff --git a/packages/babel-core/src/transformation/templates/helper-tagged-template-literal.js b/packages/babel-core/src/transformation/templates/helper-tagged-template-literal.js deleted file mode 100644 index b8c6ac8fe8..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-tagged-template-literal.js +++ /dev/null @@ -1,5 +0,0 @@ -(function (strings, raw) { - return Object.freeze(Object.defineProperties(strings, { - raw: { value: Object.freeze(raw) } - })); -}); diff --git a/packages/babel-core/src/transformation/templates/helper-temporal-assert-defined.js b/packages/babel-core/src/transformation/templates/helper-temporal-assert-defined.js deleted file mode 100644 index 97ec85d0bd..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-temporal-assert-defined.js +++ /dev/null @@ -1,6 +0,0 @@ -(function (val, name, undef) { - if (val === undef) { - throw new ReferenceError(name + " is not defined - temporal dead zone"); - } - return true; -}) diff --git a/packages/babel-core/src/transformation/templates/helper-temporal-undefined.js b/packages/babel-core/src/transformation/templates/helper-temporal-undefined.js deleted file mode 100644 index b4100a5972..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-temporal-undefined.js +++ /dev/null @@ -1 +0,0 @@ -({}) diff --git a/packages/babel-core/src/transformation/templates/helper-to-array.js b/packages/babel-core/src/transformation/templates/helper-to-array.js deleted file mode 100644 index c479b65446..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-to-array.js +++ /dev/null @@ -1,3 +0,0 @@ -(function (arr) { - return Array.isArray(arr) ? arr : Array.from(arr); -}); diff --git a/packages/babel-core/src/transformation/templates/helper-to-consumable-array.js b/packages/babel-core/src/transformation/templates/helper-to-consumable-array.js deleted file mode 100644 index 9e042dadf1..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-to-consumable-array.js +++ /dev/null @@ -1,8 +0,0 @@ -(function (arr) { - if (Array.isArray(arr)) { - for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; - return arr2; - } else { - return Array.from(arr); - } -}); diff --git a/packages/babel-core/src/transformation/templates/helper-typeof.js b/packages/babel-core/src/transformation/templates/helper-typeof.js deleted file mode 100644 index 8efdeefe3d..0000000000 --- a/packages/babel-core/src/transformation/templates/helper-typeof.js +++ /dev/null @@ -1,3 +0,0 @@ -(function (obj) { - return obj && obj.constructor === Symbol ? "symbol" : typeof obj; -}); diff --git a/packages/babel-core/src/transformation/templates/named-function.js b/packages/babel-core/src/transformation/templates/named-function.js deleted file mode 100644 index 4368fcfe58..0000000000 --- a/packages/babel-core/src/transformation/templates/named-function.js +++ /dev/null @@ -1,7 +0,0 @@ -(function () { - function GET_OUTER_ID() { - return FUNCTION_ID; - } - - return FUNCTION; -})() diff --git a/packages/babel-core/src/transformation/templates/property-method-assignment-wrapper-generator.js b/packages/babel-core/src/transformation/templates/property-method-assignment-wrapper-generator.js deleted file mode 100644 index fe3610b719..0000000000 --- a/packages/babel-core/src/transformation/templates/property-method-assignment-wrapper-generator.js +++ /dev/null @@ -1,11 +0,0 @@ -(function (FUNCTION_KEY) { - function* FUNCTION_ID() { - return yield* FUNCTION_KEY.apply(this, arguments); - } - - FUNCTION_ID.toString = function () { - return FUNCTION_KEY.toString(); - }; - - return FUNCTION_ID; -})(FUNCTION) diff --git a/packages/babel-core/src/transformation/templates/property-method-assignment-wrapper.js b/packages/babel-core/src/transformation/templates/property-method-assignment-wrapper.js deleted file mode 100644 index eeb8e5c7fd..0000000000 --- a/packages/babel-core/src/transformation/templates/property-method-assignment-wrapper.js +++ /dev/null @@ -1,11 +0,0 @@ -(function (FUNCTION_KEY) { - function FUNCTION_ID() { - return FUNCTION_KEY.apply(this, arguments); - } - - FUNCTION_ID.toString = function () { - return FUNCTION_KEY.toString(); - } - - return FUNCTION_ID; -})(FUNCTION) diff --git a/packages/babel-core/src/transformation/templates/prototype-identifier.js b/packages/babel-core/src/transformation/templates/prototype-identifier.js deleted file mode 100644 index 0bc116ef9a..0000000000 --- a/packages/babel-core/src/transformation/templates/prototype-identifier.js +++ /dev/null @@ -1 +0,0 @@ -CLASS_NAME.prototype diff --git a/packages/babel-core/src/transformation/templates/require-assign-key.js b/packages/babel-core/src/transformation/templates/require-assign-key.js deleted file mode 100644 index 07b0ef07fb..0000000000 --- a/packages/babel-core/src/transformation/templates/require-assign-key.js +++ /dev/null @@ -1 +0,0 @@ -var VARIABLE_NAME = require(MODULE_NAME).KEY; diff --git a/packages/babel-core/src/transformation/templates/require.js b/packages/babel-core/src/transformation/templates/require.js deleted file mode 100644 index 9bfd3652a4..0000000000 --- a/packages/babel-core/src/transformation/templates/require.js +++ /dev/null @@ -1 +0,0 @@ -require(MODULE_NAME); diff --git a/packages/babel-core/src/transformation/templates/self-contained-helpers-head.js b/packages/babel-core/src/transformation/templates/self-contained-helpers-head.js deleted file mode 100644 index 3d45833803..0000000000 --- a/packages/babel-core/src/transformation/templates/self-contained-helpers-head.js +++ /dev/null @@ -1,2 +0,0 @@ -exports.default = HELPER; -exports.__esModule = true; diff --git a/packages/babel-core/src/transformation/templates/system.js b/packages/babel-core/src/transformation/templates/system.js deleted file mode 100644 index 00eb18aca5..0000000000 --- a/packages/babel-core/src/transformation/templates/system.js +++ /dev/null @@ -1,6 +0,0 @@ -System.register(MODULE_NAME, MODULE_DEPENDENCIES, function (EXPORT_IDENTIFIER) { - return { - setters: SETTERS, - execute: EXECUTE - }; -}); diff --git a/packages/babel-core/src/transformation/templates/test-exports.js b/packages/babel-core/src/transformation/templates/test-exports.js deleted file mode 100644 index 0b26264b2a..0000000000 --- a/packages/babel-core/src/transformation/templates/test-exports.js +++ /dev/null @@ -1 +0,0 @@ -typeof exports !== "undefined" diff --git a/packages/babel-core/src/transformation/templates/test-module.js b/packages/babel-core/src/transformation/templates/test-module.js deleted file mode 100644 index e21fc01a58..0000000000 --- a/packages/babel-core/src/transformation/templates/test-module.js +++ /dev/null @@ -1 +0,0 @@ -typeof module !== "undefined" diff --git a/packages/babel-core/src/transformation/templates/umd-commonjs-strict.js b/packages/babel-core/src/transformation/templates/umd-commonjs-strict.js deleted file mode 100644 index 91c52cc3c2..0000000000 --- a/packages/babel-core/src/transformation/templates/umd-commonjs-strict.js +++ /dev/null @@ -1,11 +0,0 @@ -(function (root, factory) { - if (typeof define === "function" && define.amd) { - define(AMD_ARGUMENTS, factory); - } else if (typeof exports === "object") { - factory(COMMON_ARGUMENTS); - } else { - factory(BROWSER_ARGUMENTS); - } -})(UMD_ROOT, function (FACTORY_PARAMETERS) { - FACTORY_BODY -}); diff --git a/packages/babel-core/src/transformation/templates/umd-runner-body.js b/packages/babel-core/src/transformation/templates/umd-runner-body.js deleted file mode 100644 index 801ff25870..0000000000 --- a/packages/babel-core/src/transformation/templates/umd-runner-body.js +++ /dev/null @@ -1,11 +0,0 @@ -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(AMD_ARGUMENTS, factory); - } else if (COMMON_TEST) { - factory(COMMON_ARGUMENTS); - } else { - var mod = { exports: {} }; - factory(mod.exports, BROWSER_ARGUMENTS); - global.GLOBAL_ARG = mod.exports; - } -}); diff --git a/packages/babel-core/src/transformation/transformers/es5/properties.mutators.js b/packages/babel-core/src/transformation/transformers/es5/properties.mutators.js deleted file mode 100644 index 5c7379a5f4..0000000000 --- a/packages/babel-core/src/transformation/transformers/es5/properties.mutators.js +++ /dev/null @@ -1,31 +0,0 @@ -import * as defineMap from "../../helpers/define-map"; -import * as t from "babel-types"; - -export let visitor = { - ObjectExpression({ node }, file) { - var hasAny = false; - for (var prop of (node.properties: Array)) { - if (prop.kind === "get" || prop.kind === "set") { - hasAny = true; - break; - } - } - if (!hasAny) return; - - let mutatorMap = {}; - - node.properties = node.properties.filter(function (prop) { - if (prop.kind === "get" || prop.kind === "set") { - defineMap.push(mutatorMap, prop, prop.kind, file); - return false; - } else { - return true; - } - }); - - return t.callExpression( - t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")), - [node, defineMap.toDefineObject(mutatorMap)] - ); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/block-scoping/index.js b/packages/babel-core/src/transformation/transformers/es6/block-scoping/index.js deleted file mode 100644 index 71691c584f..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/block-scoping/index.js +++ /dev/null @@ -1,640 +0,0 @@ -import type NodePath from "babel-traverse"; -import type Scope from "babel-traverse"; -import type File from "../../../file"; -import traverse from "babel-traverse"; -import { visitor as tdzVisitor } from "./tdz"; -import * as util from "../../../../util"; -import * as t from "babel-types"; -import values from "lodash/object/values"; -import extend from "lodash/object/extend"; - -function isLet(node, parent) { - if (!t.isVariableDeclaration(node)) return false; - if (node._let) return true; - if (node.kind !== "let") return false; - - // https://github.com/babel/babel/issues/255 - if (isLetInitable(node, parent)) { - for (let i = 0; i < node.declarations.length; i++) { - let declar = node.declarations[i]; - declar.init = declar.init || scope.buildUndefinedNode(); - } - } - - node._let = true; - node.kind = "var"; - return true; -} - -function isLetInitable(node, parent) { - return !t.isFor(parent) || !t.isFor(parent, { left: node }); -} - -function isVar(node, parent, scope) { - return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent, scope); -} - -function standardizeLets(declars) { - for (let declar of (declars: Array)) { - delete declar._let; - } -} - -export let metadata = { - group: "builtin-advanced" -}; - -export let visitor = { - VariableDeclaration(node, parent, scope, file) { - if (!isLet(node, parent, scope)) return; - - if (isLetInitable(node) && node._tdzThis) { - let nodes = [node]; - - for (let i = 0; i < node.declarations.length; i++) { - let decl = node.declarations[i]; - if (decl.init) { - let assign = t.assignmentExpression("=", decl.id, decl.init); - assign._ignoreBlockScopingTDZ = true; - nodes.push(t.expressionStatement(assign)); - } - decl.init = file.addHelper("temporal-undefined"); - } - - node._blockHoist = 2; - - if (this.isCompletionRecord()) { - // ensure we don't break completion record semantics by returning - // the initialiser of the last declarator - nodes.push(t.expressionStatement(scope.buildUndefinedNode())); - } - - return nodes; - } - }, - - Loop(node, parent, scope, file) { - let init = node.left || node.init; - if (isLet(init, node, scope)) { - t.ensureBlock(node); - node.body._letDeclarators = [init]; - } - - let blockScoping = new BlockScoping(this, this.get("body"), parent, scope, file); - return blockScoping.run(); - }, - - "BlockStatement|Program"(block, parent, scope, file) { - if (!t.isLoop(parent)) { - let blockScoping = new BlockScoping(null, this, parent, scope, file); - blockScoping.run(); - } - } -}; - -function replace(node, parent, scope, remaps) { - let remap = remaps[node.name]; - if (!remap) return; - - let ownBinding = scope.getBindingIdentifier(node.name); - if (ownBinding === remap.binding) { - node.name = remap.uid; - } else { - // scope already has it's own binding that doesn't - // match the one we have a stored replacement for - if (this) this.skip(); - } -} - -let replaceVisitor = { - ReferencedIdentifier: replace, - - AssignmentExpression(node, parent, scope, remaps) { - let ids = this.getBindingIdentifiers(); - for (let name in ids) { - replace(ids[name], node, scope, remaps); - } - }, -}; - -function traverseReplace(node, parent, scope, remaps) { - if (t.isIdentifier(node)) { - replace(node, parent, scope, remaps); - } - - if (t.isAssignmentExpression(node)) { - let ids = t.getBindingIdentifiers(node); - for (let name in ids) { - replace(ids[name], parent, scope, remaps); - } - } - - scope.traverse(node, replaceVisitor, remaps); -} - -let letReferenceBlockVisitor = traverse.visitors.merge([{ - Function(node, parent, scope, state) { - this.traverse(letReferenceFunctionVisitor, state); - return this.skip(); - } -}, tdzVisitor]); - -let letReferenceFunctionVisitor = traverse.visitors.merge([{ - ReferencedIdentifier(node, parent, scope, state) { - let ref = state.letReferences[node.name]; - - // not a part of our scope - if (!ref) return; - - // this scope has a variable with the same name so it couldn't belong - // to our let scope - let localBinding = scope.getBindingIdentifier(node.name); - if (localBinding && localBinding !== ref) return; - - state.closurify = true; - } -}, tdzVisitor]); - -let hoistVarDeclarationsVisitor = { - enter(node, parent, scope, self) { - if (this.isForStatement()) { - if (isVar(node.init, node, scope)) { - let nodes = self.pushDeclar(node.init); - if (nodes.length === 1) { - node.init = nodes[0]; - } else { - node.init = t.sequenceExpression(nodes); - } - } - } else if (this.isFor()) { - if (isVar(node.left, node, scope)) { - self.pushDeclar(node.left); - node.left = node.left.declarations[0].id; - } - } else if (isVar(node, parent, scope)) { - return self.pushDeclar(node).map(t.expressionStatement); - } else if (this.isFunction()) { - return this.skip(); - } - } -}; - -let loopLabelVisitor = { - LabeledStatement(node, parent, scope, state) { - state.innerLabels.push(node.label.name); - } -}; - -let continuationVisitor = { - enter(node, parent, scope, state) { - if (this.isAssignmentExpression() || this.isUpdateExpression()) { - let bindings = this.getBindingIdentifiers(); - for (let name in bindings) { - if (state.outsideReferences[name] !== scope.getBindingIdentifier(name)) continue; - state.reassignments[name] = true; - } - } - } -}; - -function loopNodeTo(node) { - if (t.isBreakStatement(node)) { - return "break"; - } else if (t.isContinueStatement(node)) { - return "continue"; - } -} - -let loopVisitor = { - Loop(node, parent, scope, state) { - let oldIgnoreLabeless = state.ignoreLabeless; - state.ignoreLabeless = true; - this.traverse(loopVisitor, state); - state.ignoreLabeless = oldIgnoreLabeless; - this.skip(); - }, - - Function() { - this.skip(); - }, - - SwitchCase(node, parent, scope, state) { - let oldInSwitchCase = state.inSwitchCase; - state.inSwitchCase = true; - this.traverse(loopVisitor, state); - state.inSwitchCase = oldInSwitchCase; - this.skip(); - }, - - "BreakStatement|ContinueStatement|ReturnStatement"(node, parent, scope, state) { - let replace; - let loopText = loopNodeTo(node); - - if (loopText) { - if (node.label) { - // we shouldn't be transforming this because it exists somewhere inside - if (state.innerLabels.indexOf(node.label.name) >= 0) { - return; - } - - loopText = `${loopText}|${node.label.name}`; - } else { - // we shouldn't be transforming these statements because - // they don't refer to the actual loop we're scopifying - if (state.ignoreLabeless) return; - - // - if (state.inSwitchCase) return; - - // break statements mean something different in this context - if (t.isBreakStatement(node) && t.isSwitchCase(parent)) return; - } - - state.hasBreakContinue = true; - state.map[loopText] = node; - replace = t.stringLiteral(loopText); - } - - if (this.isReturnStatement()) { - state.hasReturn = true; - replace = t.objectExpression([ - t.property("init", t.identifier("v"), node.argument || scope.buildUndefinedNode()) - ]); - } - - if (replace) { - replace = t.returnStatement(replace); - this.skip(); - return t.inherits(replace, node); - } - } -}; - -class BlockScoping { - constructor(loopPath?: NodePath, blockPath: NodePath, parent: Object, scope: Scope, file: File) { - this.parent = parent; - this.scope = scope; - this.file = file; - - this.blockPath = blockPath; - this.block = blockPath.node; - - this.outsideLetReferences = Object.create(null); - this.hasLetReferences = false; - this.letReferences = Object.create(null); - this.body = []; - - if (loopPath) { - this.loopParent = loopPath.parent; - this.loopLabel = t.isLabeledStatement(this.loopParent) && this.loopParent.label; - this.loopPath = loopPath; - this.loop = loopPath.node; - } - } - - /** - * Start the ball rolling. - */ - - run() { - let block = this.block; - if (block._letDone) return; - block._letDone = true; - - let needsClosure = this.getLetReferences(); - - // this is a block within a `Function/Program` so we can safely leave it be - if (t.isFunction(this.parent) || t.isProgram(this.block)) return; - - // we can skip everything - if (!this.hasLetReferences) return; - - if (needsClosure) { - this.wrapClosure(); - } else { - this.remap(); - } - - if (this.loopLabel && !t.isLabeledStatement(this.loopParent)) { - return t.labeledStatement(this.loopLabel, this.loop); - } - } - - remap() { - let hasRemaps = false; - let letRefs = this.letReferences; - let scope = this.scope; - - // alright, so since we aren't wrapping this block in a closure - // we have to check if any of our let variables collide with - // those in upper scopes and then if they do, generate a uid - // for them and replace all references with it - let remaps = Object.create(null); - - for (let key in letRefs) { - // just an Identifier node we collected in `getLetReferences` - // this is the defining identifier of a declaration - let ref = letRefs[key]; - - // todo: could skip this if the colliding binding is in another function - if (scope.parentHasBinding(key) || scope.hasGlobal(key)) { - let uid = scope.generateUidIdentifier(ref.name).name; - ref.name = uid; - - hasRemaps = true; - remaps[key] = remaps[uid] = { - binding: ref, - uid: uid - }; - } - } - - if (!hasRemaps) return; - - // - - let loop = this.loop; - if (loop) { - traverseReplace(loop.right, loop, scope, remaps); - traverseReplace(loop.test, loop, scope, remaps); - traverseReplace(loop.update, loop, scope, remaps); - } - - this.blockPath.traverse(replaceVisitor, remaps); - } - - wrapClosure() { - let block = this.block; - - let outsideRefs = this.outsideLetReferences; - - // remap loop heads with colliding variables - if (this.loop) { - for (let name in outsideRefs) { - let id = outsideRefs[name]; - - if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) { - delete outsideRefs[id.name]; - delete this.letReferences[id.name]; - - this.scope.rename(id.name); - - this.letReferences[id.name] = id; - outsideRefs[id.name] = id; - } - } - } - - // if we're inside of a for loop then we search to see if there are any - // `break`s, `continue`s, `return`s etc - this.has = this.checkLoop(); - - // hoist let references to retain scope - this.hoistVarDeclarations(); - - // turn outsideLetReferences into an array - let params = values(outsideRefs); - let args = values(outsideRefs); - - // build the closure that we're going to wrap the block with - let fn = t.functionExpression(null, params, t.blockStatement(block.body)); - fn.shadow = true; - - // continuation - this.addContinuations(fn); - - // replace the current block body with the one we're going to build - block.body = this.body; - - let ref = fn; - - if (this.loop) { - ref = this.scope.generateUidIdentifier("loop"); - this.loopPath.insertBefore(t.variableDeclaration("var", [ - t.variableDeclarator(ref, fn) - ])); - } - - // build a call and a unique id that we can assign the return value to - let call = t.callExpression(ref, args); - let ret = this.scope.generateUidIdentifier("ret"); - - // handle generators - let hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES); - if (hasYield) { - fn.generator = true; - call = t.yieldExpression(call, true); - } - - // handlers async functions - let hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES); - if (hasAsync) { - fn.async = true; - call = t.awaitExpression(call); - } - - this.buildClosure(ret, call); - } - - /** - * Push the closure to the body. - */ - - buildClosure(ret: { type: "Identifier" }, call: { type: "CallExpression" }) { - let has = this.has; - if (has.hasReturn || has.hasBreakContinue) { - this.buildHas(ret, call); - } else { - this.body.push(t.expressionStatement(call)); - } - } - - /** - * If any of the outer let variables are reassigned then we need to rename them in - * the closure so we can get direct access to the outer variable to continue the - * iteration with bindings based on each iteration. - * - * Reference: https://github.com/babel/babel/issues/1078 - */ - - addContinuations(fn) { - let state = { - reassignments: {}, - outsideReferences: this.outsideLetReferences - }; - - this.scope.traverse(fn, continuationVisitor, state); - - for (let i = 0; i < fn.params.length; i++) { - let param = fn.params[i]; - if (!state.reassignments[param.name]) continue; - - let newParam = this.scope.generateUidIdentifier(param.name); - fn.params[i] = newParam; - - this.scope.rename(param.name, newParam.name, fn); - - // assign outer reference as it's been modified internally and needs to be retained - fn.body.body.push(t.expressionStatement(t.assignmentExpression("=", param, newParam))); - } - } - - getLetReferences() { - let block = this.block; - - let declarators = block._letDeclarators || []; - - // - for (let i = 0; i < declarators.length; i++) { - let declar = declarators[i]; - extend(this.outsideLetReferences, t.getBindingIdentifiers(declar)); - } - - // - if (block.body) { - for (let i = 0; i < block.body.length; i++) { - let declar = block.body[i]; - if (isLet(declar, block, this.scope)) { - declarators = declarators.concat(declar.declarations); - } - } - } - - // - for (let i = 0; i < declarators.length; i++) { - let declar = declarators[i]; - let keys = t.getBindingIdentifiers(declar); - extend(this.letReferences, keys); - this.hasLetReferences = true; - } - - // no let references so we can just quit - if (!this.hasLetReferences) return; - - // set let references to plain let references - standardizeLets(declarators); - - let state = { - letReferences: this.letReferences, - closurify: false, - file: this.file - }; - - // traverse through this block, stopping on functions and checking if they - // contain any local let references - this.blockPath.traverse(letReferenceBlockVisitor, state); - - return state.closurify; - } - - /** - * If we're inside of a loop then traverse it and check if it has one of - * the following node types `ReturnStatement`, `BreakStatement`, - * `ContinueStatement` and replace it with a return value that we can track - * later on. - */ - - checkLoop(): Object { - let state = { - hasBreakContinue: false, - ignoreLabeless: false, - inSwitchCase: false, - innerLabels: [], - hasReturn: false, - isLoop: !!this.loop, - map: {} - }; - - this.blockPath.traverse(loopLabelVisitor, state); - this.blockPath.traverse(loopVisitor, state); - - return state; - } - - /** - * Hoist all let declarations in this block to before it so they retain scope - * once we wrap everything in a closure. - */ - - hoistVarDeclarations() { - this.blockPath.traverse(hoistVarDeclarationsVisitor, this); - } - - /** - * Turn a `VariableDeclaration` into an array of `AssignmentExpressions` with - * their declarations hoisted to before the closure wrapper. - */ - - pushDeclar(node: { type: "VariableDeclaration" }): Array { - let declars = []; - let names = t.getBindingIdentifiers(node); - for (let name in names) { - declars.push(t.variableDeclarator(names[name])); - } - - this.body.push(t.variableDeclaration(node.kind, declars)); - - let replace = []; - - for (let i = 0; i < node.declarations.length; i++) { - let declar = node.declarations[i]; - if (!declar.init) continue; - - let expr = t.assignmentExpression("=", declar.id, declar.init); - replace.push(t.inherits(expr, declar)); - } - - return replace; - } - - buildHas(ret: { type: "Identifier" }, call: { type: "CallExpression" }) { - let body = this.body; - - body.push(t.variableDeclaration("var", [ - t.variableDeclarator(ret, call) - ])); - - let retCheck; - let has = this.has; - let cases = []; - - if (has.hasReturn) { - // typeof ret === "object" - retCheck = util.template("let-scoping-return", { - RETURN: ret - }); - } - - if (has.hasBreakContinue) { - for (let key in has.map) { - cases.push(t.switchCase(t.stringLiteral(key), [has.map[key]])); - } - - if (has.hasReturn) { - cases.push(t.switchCase(null, [retCheck])); - } - - if (cases.length === 1) { - let single = cases[0]; - body.push(this.file.attachAuxiliaryComment(t.ifStatement( - t.binaryExpression("===", ret, single.test), - single.consequent[0] - ))); - } else { - // https://github.com/babel/babel/issues/998 - for (let i = 0; i < cases.length; i++) { - let caseConsequent = cases[i].consequent[0]; - if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) { - caseConsequent.label = this.loopLabel = this.loopLabel || this.file.scope.generateUidIdentifier("loop"); - } - } - - body.push(this.file.attachAuxiliaryComment(t.switchStatement(ret, cases))); - } - } else { - if (has.hasReturn) { - body.push(this.file.attachAuxiliaryComment(retCheck)); - } - } - } -} diff --git a/packages/babel-core/src/transformation/transformers/es6/classes/index.js b/packages/babel-core/src/transformation/transformers/es6/classes/index.js deleted file mode 100644 index 16b80720f9..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/classes/index.js +++ /dev/null @@ -1,23 +0,0 @@ -import LooseTransformer from "./loose"; -import VanillaTransformer from "./vanilla"; -import * as t from "babel-types"; -import { bare } from "../../../helpers/name-method"; - -export let visitor = { - ClassDeclaration(node) { - return t.variableDeclaration("var", [ - t.variableDeclarator(node.id, t.toExpression(node)) - ]); - }, - - ClassExpression(node, parent, scope, file) { - let inferred = bare(node, parent, scope); - if (inferred) return inferred; - - if (file.isLoose("es6.classes")) { - return new LooseTransformer(this, file).run(); - } else { - return new VanillaTransformer(this, file).run(); - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/classes/vanilla.js b/packages/babel-core/src/transformation/transformers/es6/classes/vanilla.js deleted file mode 100644 index af8ca86023..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/classes/vanilla.js +++ /dev/null @@ -1,572 +0,0 @@ -import type NodePath from "../../../../traversal/path"; -import type File from "../../../file"; -import memoiseDecorators from "../../../helpers/memoise-decorators"; -import ReplaceSupers from "../../../helpers/replace-supers"; -import * as nameMethod from "../../../helpers/name-method"; -import * as defineMap from "../../../helpers/define-map"; -import * as messages from "babel-messages"; -import * as util from "../../../../util"; -import * as t from "babel-types"; - -const PROPERTY_COLLISION_METHOD_NAME = "__initializeProperties"; - -let collectPropertyReferencesVisitor = { - Identifier: { - enter(node, parent, scope, state) { - if (this.parentPath.isClassProperty({ key: node })) { - return; - } - - if (this.isReferenced() && scope.getBinding(node.name) === state.scope.getBinding(node.name)) { - state.references[node.name] = true; - } - } - } -}; - -let verifyConstructorVisitor = { - MethodDefinition() { - this.skip(); - }, - - Property(node) { - if (node.method) this.skip(); - }, - - CallExpression: { - exit(node, parent, scope, state) { - if (this.get("callee").isSuper()) { - state.hasBareSuper = true; - state.bareSuper = this; - - if (!state.isDerived) { - throw this.errorWithNode("super call is only allowed in derived constructor"); - } - } - } - }, - - "FunctionDeclaration|FunctionExpression"() { - this.skip(); - }, - - ThisExpression(node, parent, scope, state) { - if (state.isDerived && !state.hasBareSuper) { - if (this.inShadow()) { - // https://github.com/babel/babel/issues/1920 - let thisAlias = state.constructorPath.getData("this"); - - if (!thisAlias) { - thisAlias = state.constructorPath.setData( - "this", - state.constructorPath.scope.generateUidIdentifier("this") - ); - } - - return thisAlias; - } else { - throw this.errorWithNode("'this' is not allowed before super()"); - } - } - }, - - Super(node, parent, scope, state) { - if (state.isDerived && !state.hasBareSuper && !this.parentPath.isCallExpression({ callee: node })) { - throw this.errorWithNode("'super.*' is not allowed before super()"); - } - } -}; - -export default class ClassTransformer { - constructor(path: NodePath, file: File) { - this.parent = path.parent; - this.scope = path.scope; - this.node = path.node; - this.path = path; - this.file = file; - - this.clearDescriptors(); - - this.instancePropBody = []; - this.instancePropRefs = {}; - this.staticPropBody = []; - this.body = []; - - this.pushedConstructor = false; - this.pushedInherits = false; - this.hasDecorators = false; - this.isLoose = false; - - // class id - this.classId = this.node.id; - - // this is the name of the binding that will **always** reference the class we've constructed - this.classRef = this.node.id || this.scope.generateUidIdentifier("class"); - - // this is a direct reference to the class we're building, class decorators can shadow the classRef - this.directRef = null; - - this.superName = this.node.superClass || t.identifier("Function"); - this.isDerived = !!this.node.superClass; - } - - run() { - let superName = this.superName; - let file = this.file; - let body = this.body; - - // - - let constructorBody = this.constructorBody = t.blockStatement([]); - this.constructor = this.buildConstructor(); - - // - - let closureParams = []; - let closureArgs = []; - - // - if (this.isDerived) { - closureArgs.push(superName); - - superName = this.scope.generateUidIdentifierBasedOnNode(superName); - closureParams.push(superName); - - this.superName = superName; - } - - // - let decorators = this.node.decorators; - if (decorators) { - // this is so super calls and the decorators have access to the raw function - this.directRef = this.scope.generateUidIdentifier(this.classRef); - } else { - this.directRef = this.classRef; - } - - // - this.buildBody(); - - // make sure this class isn't directly called - constructorBody.body.unshift(t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [ - t.thisExpression(), - this.directRef - ]))); - - // - this.pushDecorators(); - - body = body.concat(this.staticPropBody); - - if (this.classId) { - // named class with only a constructor - if (body.length === 1) return t.toExpression(body[0]); - } - - // - body.push(t.returnStatement(this.classRef)); - - let container = t.functionExpression(null, closureParams, t.blockStatement(body)); - container.shadow = true; - return t.callExpression(container, closureArgs); - } - - buildConstructor() { - let func = t.functionDeclaration(this.classRef, [], this.constructorBody); - t.inherits(func, this.node); - return func; - } - - pushToMap(node, enumerable, kind = "value") { - let mutatorMap; - if (node.static) { - this.hasStaticDescriptors = true; - mutatorMap = this.staticMutatorMap; - } else { - this.hasInstanceDescriptors = true; - mutatorMap = this.instanceMutatorMap; - } - - let map = defineMap.push(mutatorMap, node, kind, this.file); - - if (enumerable) { - map.enumerable = t.booleanLiteral(true); - } - - if (map.decorators) { - this.hasDecorators = true; - } - } - - /** - * [Please add a description.] - * https://www.youtube.com/watch?v=fWNaR-rxAic - */ - - constructorMeMaybe() { - let hasConstructor = false; - let paths = this.path.get("body.body"); - for (let path of (paths: Array)) { - hasConstructor = path.equals("kind", "constructor"); - if (hasConstructor) break; - } - if (hasConstructor) return; - - let constructor; - if (this.isDerived) { - constructor = util.template("class-derived-default-constructor"); - } else { - constructor = t.functionExpression(null, [], t.blockStatement([])); - } - - this.path.get("body").unshiftContainer("body", t.methodDefinition( - t.identifier("constructor"), - constructor, - "constructor" - )); - } - - buildBody() { - this.constructorMeMaybe(); - this.pushBody(); - this.placePropertyInitializers(); - - if (this.userConstructor) { - let constructorBody = this.constructorBody; - constructorBody.body = constructorBody.body.concat(this.userConstructor.body.body); - t.inherits(this.constructor, this.userConstructor); - t.inherits(constructorBody, this.userConstructor.body); - } - - this.pushDescriptors(); - } - - pushBody() { - let classBodyPaths = this.path.get("body.body"); - - for (let path of (classBodyPaths: Array)) { - let node = path.node; - - if (node.decorators) { - memoiseDecorators(node.decorators, this.scope); - } - - if (t.isMethodDefinition(node)) { - let isConstructor = node.kind === "constructor"; - if (isConstructor) this.verifyConstructor(path); - - let replaceSupers = new ReplaceSupers({ - methodPath: path, - methodNode: node, - objectRef: this.directRef, - superRef: this.superName, - isStatic: node.static, - isLoose: this.isLoose, - scope: this.scope, - file: this.file - }, true); - - replaceSupers.replace(); - - if (isConstructor) { - this.pushConstructor(node, path); - } else { - this.pushMethod(node, path); - } - } else if (t.isClassProperty(node)) { - this.pushProperty(node, path); - } - } - } - - clearDescriptors() { - this.hasInstanceDescriptors = false; - this.hasStaticDescriptors = false; - - this.instanceMutatorMap = {}; - this.staticMutatorMap = {}; - } - - pushDescriptors() { - this.pushInherits(); - - let body = this.body; - - let instanceProps; - let staticProps; - let classHelper = "create-class"; - if (this.hasDecorators) classHelper = "create-decorated-class"; - - if (this.hasInstanceDescriptors) { - instanceProps = defineMap.toClassObject(this.instanceMutatorMap); - } - - if (this.hasStaticDescriptors) { - staticProps = defineMap.toClassObject(this.staticMutatorMap); - } - - if (instanceProps || staticProps) { - if (instanceProps) instanceProps = defineMap.toComputedObjectFromClass(instanceProps); - if (staticProps) staticProps = defineMap.toComputedObjectFromClass(staticProps); - - let nullNode = t.nullLiteral(); - - // (Constructor, instanceDescriptors, staticDescriptors, instanceInitializers, staticInitializers) - let args = [this.classRef, nullNode, nullNode, nullNode, nullNode]; - - if (instanceProps) args[1] = instanceProps; - if (staticProps) args[2] = staticProps; - - if (this.instanceInitializersId) { - args[3] = this.instanceInitializersId; - body.unshift(this.buildObjectAssignment(this.instanceInitializersId)); - } - - if (this.staticInitializersId) { - args[4] = this.staticInitializersId; - body.unshift(this.buildObjectAssignment(this.staticInitializersId)); - } - - let lastNonNullIndex = 0; - for (let i = 0; i < args.length; i++) { - if (args[i] !== nullNode) lastNonNullIndex = i; - } - args = args.slice(0, lastNonNullIndex + 1); - - - body.push(t.expressionStatement( - t.callExpression(this.file.addHelper(classHelper), args) - )); - } - - this.clearDescriptors(); - } - - buildObjectAssignment(id) { - return t.variableDeclaration("var", [ - t.variableDeclarator(id, t.objectExpression([])) - ]); - } - - placePropertyInitializers() { - let body = this.instancePropBody; - if (!body.length) return; - - if (this.hasPropertyCollision()) { - let call = t.expressionStatement(t.callExpression( - t.memberExpression(t.thisExpression(), t.identifier(PROPERTY_COLLISION_METHOD_NAME)), - [] - )); - - this.pushMethod(t.methodDefinition( - t.identifier(PROPERTY_COLLISION_METHOD_NAME), - t.functionExpression(null, [], t.blockStatement(body)) - ), null, true); - - if (this.isDerived) { - this.bareSuper.insertAfter(call); - } else { - this.constructorBody.body.unshift(call); - } - } else { - if (this.isDerived) { - this.bareSuper.insertAfter(body); - } else { - this.constructorBody.body = body.concat(this.constructorBody.body); - } - } - } - - hasPropertyCollision(): boolean { - if (this.userConstructorPath) { - for (let name in this.instancePropRefs) { - if (this.userConstructorPath.scope.hasOwnBinding(name)) { - return true; - } - } - } - - return false; - } - - verifyConstructor(path: NodePath) { - let state = { - constructorPath: path.get("value"), - hasBareSuper: false, - bareSuper: null, - isDerived: this.isDerived, - file: this.file, - }; - - state.constructorPath.traverse(verifyConstructorVisitor, state); - - let thisAlias = state.constructorPath.getData("this"); - if (thisAlias && state.bareSuper) { - state.bareSuper.insertAfter(t.variableDeclaration("var", [ - t.variableDeclarator(thisAlias, t.thisExpression()) - ])); - } - - this.bareSuper = state.bareSuper; - - if (!state.hasBareSuper && this.isDerived) { - throw path.errorWithNode("Derived constructor must call super()"); - } - } - - /** - * Push a method to its respective mutatorMap. - */ - - pushMethod(node: { type: "MethodDefinition" }, path?: NodePath, allowedIllegal?) { - if (!allowedIllegal && t.isLiteral(t.toComputedKey(node), { value: PROPERTY_COLLISION_METHOD_NAME })) { - throw this.file.errorWithNode(node, messages.get("illegalMethodName", PROPERTY_COLLISION_METHOD_NAME)); - } - - if (node.kind === "method") { - nameMethod.property(node, this.file, path ? path.get("value").scope : this.scope); - if (this._processMethod(node)) return; - } - - this.pushToMap(node); - } - - _processMethod() { - return false; - } - - pushProperty(node: { type: "ClassProperty" }, path: NodePath) { - path.traverse(collectPropertyReferencesVisitor, { - references: this.instancePropRefs, - scope: this.scope - }); - - if (node.decorators) { - let body = []; - if (node.value) { - body.push(t.returnStatement(node.value)); - node.value = t.functionExpression(null, [], t.blockStatement(body)); - } else { - node.value = t.nullLiteral(); - } - this.pushToMap(node, true, "initializer"); - - let initializers; - let target; - if (node.static) { - initializers = this.staticInitializersId = this.staticInitializersId || this.scope.generateUidIdentifier("staticInitializers"); - body = this.staticPropBody; - target = this.classRef; - } else { - initializers = this.instanceInitializersId = this.instanceInitializersId || this.scope.generateUidIdentifier("instanceInitializers"); - body = this.instancePropBody; - target = t.thisExpression(); - } - - body.push(t.expressionStatement( - t.callExpression(this.file.addHelper("define-decorated-property-descriptor"), [ - target, - t.literal(node.key.name), - initializers - ]) - )); - } else { - if (!node.value && !node.decorators) return; - - if (node.static) { - // can just be added to the static map - this.pushToMap(node, true); - } else if (node.value) { - // add this to the instancePropBody which will be added after the super call in a derived constructor - // or at the start of a constructor for a non-derived constructor - this.instancePropBody.push(t.expressionStatement( - t.assignmentExpression("=", t.memberExpression(t.thisExpression(), node.key), node.value) - )); - } - } - } - - /** - * Replace the constructor body of our class. - */ - - pushConstructor(method: { type: "MethodDefinition" }, path: NodePath) { - // https://github.com/babel/babel/issues/1077 - let fnPath = path.get("value"); - if (fnPath.scope.hasOwnBinding(this.classRef.name)) { - fnPath.scope.rename(this.classRef.name); - } - - let construct = this.constructor; - let fn = method.value; - - this.userConstructorPath = fnPath; - this.userConstructor = fn; - this.hasConstructor = true; - - t.inheritsComments(construct, method); - - construct._ignoreUserWhitespace = true; - construct.params = fn.params; - - t.inherits(construct.body, fn.body); - - // push constructor to body - this._pushConstructor(); - } - - _pushConstructor() { - if (this.pushedConstructor) return; - this.pushedConstructor = true; - - // we haven't pushed any descriptors yet - if (this.hasInstanceDescriptors || this.hasStaticDescriptors) { - this.pushDescriptors(); - } - - this.body.push(this.constructor); - - this.pushInherits(); - } - - /** - * Push inherits helper to body. - */ - - pushInherits() { - if (!this.isDerived || this.pushedInherits) return; - - // Unshift to ensure that the constructor inheritance is set up before - // any properties can be assigned to the prototype. - this.pushedInherits = true; - this.body.unshift(t.expressionStatement(t.callExpression( - this.file.addHelper("inherits"), - [this.classRef, this.superName] - ))); - } - - /** - * Push decorators to body. - */ - - pushDecorators() { - let decorators = this.node.decorators; - if (!decorators) return; - - this.body.push(t.variableDeclaration("var", [ - t.variableDeclarator(this.directRef, this.classRef) - ])); - - // reverse the decorators so we execute them in the right order - decorators = decorators.reverse(); - - for (let decorator of (decorators: Array)) { - let decoratorNode = util.template("class-decorator", { - DECORATOR: decorator.expression, - CLASS_REF: this.classRef - }, true); - decoratorNode.expression._ignoreModulesRemap = true; - this.body.push(decoratorNode); - } - } -} diff --git a/packages/babel-core/src/transformation/transformers/es6/for-of.js b/packages/babel-core/src/transformation/transformers/es6/for-of.js deleted file mode 100644 index de224dc727..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/for-of.js +++ /dev/null @@ -1,177 +0,0 @@ -import * as messages from "babel-messages"; -import * as util from "../../../util"; -import * as t from "babel-types"; - -export let visitor = { - ForOfStatement(node, parent, scope, file) { - if (this.get("right").isArrayExpression()) { - return _ForOfStatementArray.call(this, node, scope, file); - } - - let callback = spec; - if (file.isLoose("es6.forOf")) callback = loose; - - let build = callback(node, parent, scope, file); - let declar = build.declar; - let loop = build.loop; - let block = loop.body; - - // ensure that it's a block so we can take all its statements - this.ensureBlock(); - - // add the value declaration to the new loop body - if (declar) { - block.body.push(declar); - } - - // push the rest of the original loop body onto our new body - block.body = block.body.concat(node.body.body); - - t.inherits(loop, node); - t.inherits(loop.body, node.body); - - if (build.replaceParent) { - this.parentPath.replaceWithMultiple(build.node); - this.dangerouslyRemove(); - } else { - return build.node; - } - } -}; - -export function _ForOfStatementArray(node, scope) { - let nodes = []; - let right = node.right; - - if (!t.isIdentifier(right) || !scope.hasBinding(right.name)) { - let uid = scope.generateUidIdentifier("arr"); - nodes.push(t.variableDeclaration("var", [ - t.variableDeclarator(uid, right) - ])); - right = uid; - } - - let iterationKey = scope.generateUidIdentifier("i"); - - let loop = util.template("for-of-array", { - BODY: node.body, - KEY: iterationKey, - ARR: right - }); - - t.inherits(loop, node); - t.ensureBlock(loop); - - let iterationValue = t.memberExpression(right, iterationKey, true); - - let left = node.left; - if (t.isVariableDeclaration(left)) { - left.declarations[0].init = iterationValue; - loop.body.body.unshift(left); - } else { - loop.body.body.unshift(t.expressionStatement(t.assignmentExpression("=", left, iterationValue))); - } - - if (this.parentPath.isLabeledStatement()) { - loop = t.labeledStatement(this.parentPath.node.label, loop); - } - - nodes.push(loop); - - return nodes; -} - -let loose = function (node, parent, scope, file) { - let left = node.left; - let declar, id; - - if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { - // for (i of test), for ({ i } of test) - id = left; - } else if (t.isVariableDeclaration(left)) { - // for (let i of test) - id = scope.generateUidIdentifier("ref"); - declar = t.variableDeclaration(left.kind, [ - t.variableDeclarator(left.declarations[0].id, id) - ]); - } else { - throw file.errorWithNode(left, messages.get("unknownForHead", left.type)); - } - - let iteratorKey = scope.generateUidIdentifier("iterator"); - let isArrayKey = scope.generateUidIdentifier("isArray"); - - let loop = util.template("for-of-loose", { - LOOP_OBJECT: iteratorKey, - IS_ARRAY: isArrayKey, - OBJECT: node.right, - INDEX: scope.generateUidIdentifier("i"), - ID: id - }); - - if (!declar) { - // no declaration so we need to remove the variable declaration at the top of - // the for-of-loose template - loop.body.body.shift(); - } - - // - - return { - declar: declar, - node: loop, - loop: loop - }; -}; - -let spec = function (node, parent, scope, file) { - let left = node.left; - let declar; - - let stepKey = scope.generateUidIdentifier("step"); - let stepValue = t.memberExpression(stepKey, t.identifier("value")); - - if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { - // for (i of test), for ({ i } of test) - declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue)); - } else if (t.isVariableDeclaration(left)) { - // for (let i of test) - declar = t.variableDeclaration(left.kind, [ - t.variableDeclarator(left.declarations[0].id, stepValue) - ]); - } else { - throw file.errorWithNode(left, messages.get("unknownForHead", left.type)); - } - - // - - let iteratorKey = scope.generateUidIdentifier("iterator"); - - let template = util.template("for-of", { - ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"), - ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"), - ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"), - ITERATOR_KEY: iteratorKey, - STEP_KEY: stepKey, - OBJECT: node.right, - BODY: null - }); - - let isLabeledParent = t.isLabeledStatement(parent); - - let tryBody = template[3].block.body; - let loop = tryBody[0]; - - if (isLabeledParent) { - tryBody[0] = t.labeledStatement(parent.label, loop); - } - - // - - return { - replaceParent: isLabeledParent, - declar: declar, - loop: loop, - node: template - }; -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/modules.js b/packages/babel-core/src/transformation/transformers/es6/modules.js deleted file mode 100644 index afde8d1f6a..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/modules.js +++ /dev/null @@ -1,77 +0,0 @@ -import * as t from "babel-types"; - -function keepBlockHoist(node, nodes) { - if (node._blockHoist) { - for (let i = 0; i < nodes.length; i++) { - nodes[i]._blockHoist = node._blockHoist; - } - } -} - -export let metadata = { - group: "builtin-modules" -}; - -export let visitor = { - ImportDeclaration(node, parent, scope, file) { - // flow type - if (node.importKind === "type" || node.importKind === "typeof") return; - - let nodes = []; - - if (node.specifiers.length) { - for (let specifier of (node.specifiers: Array)) { - file.moduleFormatter.importSpecifier(specifier, node, nodes, scope); - } - } else { - file.moduleFormatter.importDeclaration(node, nodes, scope); - } - - if (nodes.length === 1) { - // inherit `_blockHoist` - this is for `_blockHoist` in File.prototype.addImport - nodes[0]._blockHoist = node._blockHoist; - } - - return nodes; - }, - - ExportAllDeclaration(node, parent, scope, file) { - let nodes = []; - file.moduleFormatter.exportAllDeclaration(node, nodes, scope); - keepBlockHoist(node, nodes); - return nodes; - }, - - ExportDefaultDeclaration(node, parent, scope, file) { - let nodes = []; - file.moduleFormatter.exportDeclaration(node, nodes, scope); - keepBlockHoist(node, nodes); - return nodes; - }, - - ExportNamedDeclaration(node, parent, scope, file) { - // flow type - if (this.get("declaration").isTypeAlias()) return; - - let nodes = []; - - if (node.declaration) { - // make sure variable exports have an initializer - // this is done here to avoid duplicating it in the module formatters - if (t.isVariableDeclaration(node.declaration)) { - let declar = node.declaration.declarations[0]; - declar.init = declar.init || scope.buildUndefinedNode(); - } - - file.moduleFormatter.exportDeclaration(node, nodes, scope); - } else if (node.specifiers) { - for (let i = 0; i < node.specifiers.length; i++) { - file.moduleFormatter.exportSpecifier(node.specifiers[i], node, nodes, scope); - } - } - - keepBlockHoist(node, nodes); - - return nodes; - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/object-super.js b/packages/babel-core/src/transformation/transformers/es6/object-super.js deleted file mode 100644 index b4e6a9006c..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/object-super.js +++ /dev/null @@ -1,35 +0,0 @@ -import ReplaceSupers from "../../helpers/replace-supers"; -import * as t from "babel-types"; - -function Property(path, node, scope, getObjectRef, file) { - if (!node.method && node.kind === "init") return; - if (!t.isFunction(node.value)) return; - - let replaceSupers = new ReplaceSupers({ - getObjectRef: getObjectRef, - methodNode: node, - methodPath: path, - isStatic: true, - scope: scope, - file: file - }); - - replaceSupers.replace(); -} - -export let visitor = { - ObjectExpression(node, parent, scope, file) { - let objectRef; - let getObjectRef = () => objectRef = objectRef || scope.generateUidIdentifier("obj"); - - let propPaths = this.get("properties"); - for (let i = 0; i < node.properties.length; i++) { - Property(propPaths[i], node.properties[i], scope, getObjectRef, file); - } - - if (objectRef) { - scope.push({ id: objectRef }); - return t.assignmentExpression("=", objectRef, node); - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/parameters/default.js b/packages/babel-core/src/transformation/transformers/es6/parameters/default.js deleted file mode 100644 index 4a49aee048..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/parameters/default.js +++ /dev/null @@ -1,120 +0,0 @@ -import callDelegate from "../../../helpers/call-delegate"; -import getFunctionArity from "../../../helpers/get-function-arity"; -import * as util from "../../../../util"; -import * as t from "babel-types"; - -let hasDefaults = function (node) { - for (let i = 0; i < node.params.length; i++) { - if (!t.isIdentifier(node.params[i])) return true; - } - return false; -}; - -let iifeVisitor = { - ReferencedIdentifier(node, parent, scope, state) { - if (node.name !== "eval") { - if (!state.scope.hasOwnBinding(node.name)) return; - if (state.scope.bindingIdentifierEquals(node.name, node)) return; - } - - state.iife = true; - this.stop(); - } -}; - -export let visitor = { - Function(node, parent, scope, file) { - if (!hasDefaults(node)) return; - - // ensure it's a block, useful for arrow functions - this.ensureBlock(); - - let state = { - iife: false, - scope: scope - }; - - let body = []; - - // - let argsIdentifier = t.identifier("arguments"); - argsIdentifier._shadowedFunctionLiteral = this; - - // push a default parameter definition - function pushDefNode(left, right, i) { - let defNode; - if (exceedsLastNonDefault(i) || t.isPattern(left) || file.transformers["es6.spec.blockScoping"].canTransform()) { - defNode = util.template("default-parameter", { - VARIABLE_NAME: left, - DEFAULT_VALUE: right, - ARGUMENT_KEY: t.numberLiteral(i), - ARGUMENTS: argsIdentifier - }, true); - } else { - defNode = util.template("default-parameter-assign", { - VARIABLE_NAME: left, - DEFAULT_VALUE: right - }, true); - } - defNode._blockHoist = node.params.length - i; - body.push(defNode); - } - - // check if an index exceeds the functions arity - function exceedsLastNonDefault(i) { - return i + 1 > lastNonDefaultParam; - } - - // - let lastNonDefaultParam = getFunctionArity(node); - - // - let params = this.get("params"); - for (let i = 0; i < params.length; i++) { - let param = params[i]; - - if (!param.isAssignmentPattern()) { - if (!param.isIdentifier()) { - param.traverse(iifeVisitor, state); - } - - //if (file.transformers["es6.spec.blockScoping"].canTransform() && param.isIdentifier()) { - // pushDefNode(param.node, scope.buildUndefinedNode(), i); - //} - - continue; - } - - let left = param.get("left"); - let right = param.get("right"); - - if (exceedsLastNonDefault(i) || left.isPattern()) { - let placeholder = scope.generateUidIdentifier("x"); - placeholder._isDefaultPlaceholder = true; - node.params[i] = placeholder; - } else { - node.params[i] = left.node; - } - - if (!state.iife) { - if (right.isIdentifier() && scope.hasOwnBinding(right.node.name)) { - state.iife = true; - } else { - right.traverse(iifeVisitor, state); - } - } - - pushDefNode(left.node, right.node, i); - } - - // we need to cut off all trailing default parameters - node.params = node.params.slice(0, lastNonDefaultParam); - - if (state.iife) { - body.push(callDelegate(node, scope)); - node.body = t.blockStatement(body); - } else { - node.body.body = body.concat(node.body.body); - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/parameters/index.js b/packages/babel-core/src/transformation/transformers/es6/parameters/index.js deleted file mode 100644 index 6e154173aa..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/parameters/index.js +++ /dev/null @@ -1,10 +0,0 @@ -import { visitors } from "babel-traverse"; - -import * as def from "./default"; -import * as rest from "./rest"; - -export let metadata = { - group: "builtin-advanced" -}; - -export let visitor = visitors.merge([rest.visitor, def.visitor]); diff --git a/packages/babel-core/src/transformation/transformers/es6/regex.sticky.js b/packages/babel-core/src/transformation/transformers/es6/regex.sticky.js deleted file mode 100644 index bffc2e6dff..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/regex.sticky.js +++ /dev/null @@ -1,12 +0,0 @@ -import * as regex from "../../helpers/regex"; -import * as t from "babel-types"; - -export let visitor = { - RegexLiteral(node) { - if (!regex.is(node, "y")) return; - return t.newExpression(t.identifier("RegExp"), [ - t.stringLiteral(node.pattern), - t.stringLiteral(node.flags) - ]); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/regex.unicode.js b/packages/babel-core/src/transformation/transformers/es6/regex.unicode.js deleted file mode 100644 index cb7266940f..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/regex.unicode.js +++ /dev/null @@ -1,10 +0,0 @@ -import rewritePattern from "regexpu/rewrite-pattern"; -import * as regex from "../../helpers/regex"; - -export let visitor = { - RegexLiteral(node) { - if (!regex.is(node, "u")) return; - node.regex.pattern = rewritePattern(node.pattern, node.flags); - regex.pullFlag(node, "u"); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/spec.arrow-functions.js b/packages/babel-core/src/transformation/transformers/es6/spec.arrow-functions.js deleted file mode 100644 index 48acf05eca..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/spec.arrow-functions.js +++ /dev/null @@ -1,25 +0,0 @@ -import * as t from "babel-types"; - -export let metadata = { - group: "builtin-pre", - optional: true -}; - -export let visitor = { - ArrowFunctionExpression(node, parent, scope, file) { - if (node.shadow) return; - node.shadow = { this: false }; - - let boundThis = t.thisExpression(); - boundThis._forceShadow = this; - - // make sure that arrow function won't be instantiated - t.ensureBlock(node); - this.get("body").unshiftContainer("body", t.expressionStatement(t.callExpression(file.addHelper("new-arrow-check"), [ - t.thisExpression(), - boundThis - ]))); - - return t.callExpression(t.memberExpression(node, t.identifier("bind")), [t.thisExpression()]); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/spec.modules.js b/packages/babel-core/src/transformation/transformers/es6/spec.modules.js deleted file mode 100644 index a51e2ea9ea..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/spec.modules.js +++ /dev/null @@ -1,20 +0,0 @@ -import * as t from "babel-types"; - -export let metadata = { - group: "builtin-pre", - optional: true -}; - -export let visitor = { - Program() { - let id = this.scope.generateUidIdentifier("null"); - this.unshiftContainer("body", [ - t.variableDeclaration("var", [ - t.variableDeclarator(id, t.nullLiteral()) - ]), - t.exportNamedDeclaration(null, [ - t.exportSpecifier(id, t.identifier("__proto__")) - ]) - ]); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/spec.symbols.js b/packages/babel-core/src/transformation/transformers/es6/spec.symbols.js deleted file mode 100644 index 73826474b8..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/spec.symbols.js +++ /dev/null @@ -1,43 +0,0 @@ -import * as t from "babel-types"; - -export let metadata = { - optional: true -}; - -export let visitor = { - UnaryExpression(node, parent, scope, file) { - if (node._ignoreSpecSymbols) return; - - if (this.parentPath.isBinaryExpression() && t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) { - // optimise `typeof foo === "string"` since we can determine that they'll never need to handle symbols - let opposite = this.getOpposite(); - if (opposite.isLiteral() && opposite.node.value !== "symbol" && opposite.node.value !== "object") return; - } - - if (node.operator === "typeof") { - let call = t.callExpression(file.addHelper("typeof"), [node.argument]); - if (this.get("argument").isIdentifier()) { - let undefLiteral = t.stringLiteral("undefined"); - let unary = t.unaryExpression("typeof", node.argument); - unary._ignoreSpecSymbols = true; - return t.conditionalExpression( - t.binaryExpression("===", unary, undefLiteral), - undefLiteral, - call - ); - } else { - return call; - } - } - }, - - BinaryExpression(node, parent, scope, file) { - if (node.operator === "instanceof") { - return t.callExpression(file.addHelper("instanceof"), [node.left, node.right]); - } - }, - - "VariableDeclaration|FunctionDeclaration"(node) { - if (node._generated) this.skip(); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/spec.template-literals.js b/packages/babel-core/src/transformation/transformers/es6/spec.template-literals.js deleted file mode 100644 index 798718552b..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/spec.template-literals.js +++ /dev/null @@ -1,16 +0,0 @@ -import * as t from "babel-types"; - -export let metadata = { - optional: true, - group: "builtin-pre" -}; - -export let visitor = { - TemplateLiteral(node, parent) { - if (t.isTaggedTemplateExpression(parent)) return; - - for (let i = 0; i < node.expressions.length; i++) { - node.expressions[i] = t.callExpression(t.identifier("String"), [node.expressions[i]]); - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es6/tail-call.js b/packages/babel-core/src/transformation/transformers/es6/tail-call.js deleted file mode 100644 index 8400873e22..0000000000 --- a/packages/babel-core/src/transformation/transformers/es6/tail-call.js +++ /dev/null @@ -1,401 +0,0 @@ -import reduceRight from "lodash/collection/reduceRight"; -import * as messages from "babel-messages"; -import flatten from "lodash/array/flatten"; -import * as util from "../../../util"; -import map from "lodash/collection/map"; -import * as t from "babel-types"; - -export let metadata = { - group: "builtin-trailing" -}; - -export let visitor = { - Function(node, parent, scope, file) { - if (node.generator || node.async) return; - let tailCall = new TailCallTransformer(this, scope, file); - tailCall.run(); - } -}; - -function returnBlock(expr) { - return t.blockStatement([t.returnStatement(expr)]); -} - -let visitor = { - enter(node, parent) { - if (t.isTryStatement(parent)) { - if (node === parent.block) { - this.skip(); - } else if (parent.finalizer && node !== parent.finalizer) { - this.skip(); - } - } - }, - - ReturnStatement(node, parent, scope, state) { - return state.subTransform(node.argument); - }, - - Function() { - this.skip(); - }, - - VariableDeclaration(node, parent, scope, state) { - state.vars.push(node); - }, - - ThisExpression(node, parent, scope, state) { - if (!state.isShadowed) { - state.needsThis = true; - state.thisPaths.push(this); - } - }, - - ReferencedIdentifier(node, parent, scope, state) { - if (node.name === "arguments" && (!state.isShadowed || node._shadowedFunctionLiteral)) { - state.needsArguments = true; - state.argumentsPaths.push(this); - } - } -}; - -class TailCallTransformer { - constructor(path, scope, file) { - this.hasTailRecursion = false; - - this.needsArguments = false; - this.argumentsPaths = []; - this.setsArguments = false; - - this.needsThis = false; - this.thisPaths = []; - - this.isShadowed = path.isArrowFunctionExpression() || path.is("shadow"); - this.ownerId = path.node.id; - this.vars = []; - - this.scope = scope; - this.path = path; - this.file = file; - this.node = path.node; - } - - getArgumentsId() { - return this.argumentsId = this.argumentsId || this.scope.generateUidIdentifier("arguments"); - } - - getThisId() { - return this.thisId = this.thisId || this.scope.generateUidIdentifier("this"); - } - - getLeftId() { - return this.leftId = this.leftId || this.scope.generateUidIdentifier("left"); - } - - getFunctionId() { - return this.functionId = this.functionId || this.scope.generateUidIdentifier("function"); - } - - getAgainId() { - return this.againId = this.againId || this.scope.generateUidIdentifier("again"); - } - - getParams() { - let params = this.params; - - if (!params) { - params = this.node.params; - this.paramDecls = []; - - for (let i = 0; i < params.length; i++) { - let param = params[i]; - if (!param._isDefaultPlaceholder) { - this.paramDecls.push(t.variableDeclarator( - param, - params[i] = this.scope.generateUidIdentifier("x") - )); - } - } - } - - return this.params = params; - } - - hasDeopt() { - // check if the ownerId has been reassigned, if it has then it's not safe to - // perform optimisations - let ownerIdInfo = this.scope.getBinding(this.ownerId.name); - return ownerIdInfo && !ownerIdInfo.constant; - } - - run() { - let node = this.node; - - // only tail recursion can be optimized as for now, so we can skip anonymous - // functions entirely - let ownerId = this.ownerId; - if (!ownerId) return; - - // traverse the function and look for tail recursion - this.path.traverse(visitor, this); - - // has no tail call recursion - if (!this.hasTailRecursion) return; - - // the function binding isn't constant so we can't be sure that it's the same function :( - if (this.hasDeopt()) { - this.file.log.deopt(node, messages.get("tailCallReassignmentDeopt")); - return; - } - - // - - let body = this.path.ensureBlock().body; - - for (let i = 0; i < body.length; i++) { - let bodyNode = body[i]; - if (!t.isFunctionDeclaration(bodyNode)) continue; - - bodyNode = body[i] = t.variableDeclaration("var", [ - t.variableDeclarator(bodyNode.id, t.toExpression(bodyNode)) - ]); - bodyNode._blockHoist = 2; - } - - if (this.vars.length > 0) { - let declarations = flatten(map(this.vars, function (decl) { - return decl.declarations; - })); - - let assignment = reduceRight(declarations, function (expr, decl) { - return t.assignmentExpression("=", decl.id, expr); - }, this.scope.buildUndefinedNode()); - - let statement = t.expressionStatement(assignment); - statement._blockHoist = Infinity; - body.unshift(statement); - } - - let paramDecls = this.paramDecls; - if (paramDecls.length > 0) { - let paramDecl = t.variableDeclaration("var", paramDecls); - paramDecl._blockHoist = Infinity; - body.unshift(paramDecl); - } - - body.unshift(t.expressionStatement( - t.assignmentExpression("=", this.getAgainId(), t.booleanLiteral(false))) - ); - - node.body = util.template("tail-call-body", { - FUNCTION_ID: this.getFunctionId(), - AGAIN_ID: this.getAgainId(), - BLOCK: node.body - }); - - let topVars = []; - - if (this.needsThis) { - for (let path of (this.thisPaths: Array)) { - path.replaceWith(this.getThisId()); - } - - topVars.push(t.variableDeclarator(this.getThisId(), t.thisExpression())); - } - - if (this.needsArguments || this.setsArguments) { - for (let path of (this.argumentsPaths: Array)) { - path.replaceWith(this.argumentsId); - } - - let decl = t.variableDeclarator(this.argumentsId); - if (this.argumentsId) { - decl.init = t.identifier("arguments"); - decl.init._shadowedFunctionLiteral = this.path; - } - topVars.push(decl); - } - - let leftId = this.leftId; - if (leftId) { - topVars.push(t.variableDeclarator(leftId)); - } - - if (topVars.length > 0) { - node.body.body.unshift(t.variableDeclaration("var", topVars)); - } - } - - subTransform(node) { - if (!node) return; - - let handler = this[`subTransform${node.type}`]; - if (handler) return handler.call(this, node); - } - - subTransformConditionalExpression(node) { - let callConsequent = this.subTransform(node.consequent); - let callAlternate = this.subTransform(node.alternate); - if (!callConsequent && !callAlternate) { - return; - } - - // if ternary operator had tail recursion in value, convert to optimized if-statement - node.type = "IfStatement"; - node.consequent = callConsequent ? t.toBlock(callConsequent) : returnBlock(node.consequent); - - if (callAlternate) { - node.alternate = t.isIfStatement(callAlternate) ? callAlternate : t.toBlock(callAlternate); - } else { - node.alternate = returnBlock(node.alternate); - } - - return [node]; - } - - subTransformLogicalExpression(node) { - // only call in right-value of can be optimized - let callRight = this.subTransform(node.right); - if (!callRight) return; - - // cache left value as it might have side-effects - let leftId = this.getLeftId(); - let testExpr = t.assignmentExpression( - "=", - leftId, - node.left - ); - - if (node.operator === "&&") { - testExpr = t.unaryExpression("!", testExpr); - } - - return [t.ifStatement(testExpr, returnBlock(leftId))].concat(callRight); - } - - subTransformSequenceExpression(node) { - let seq = node.expressions; - - // only last element can be optimized - let lastCall = this.subTransform(seq[seq.length - 1]); - if (!lastCall) { - return; - } - - // remove converted expression from sequence - // and convert to regular expression if needed - if (--seq.length === 1) { - node = seq[0]; - } - - return [t.expressionStatement(node)].concat(lastCall); - } - - subTransformCallExpression(node) { - let callee = node.callee; - let thisBinding, args; - - if (t.isMemberExpression(callee, { computed: false }) && t.isIdentifier(callee.property)) { - switch (callee.property.name) { - case "call": - args = t.arrayExpression(node.arguments.slice(1)); - break; - - case "apply": - args = node.arguments[1] || this.scope.buildUndefinedNode(); - this.needsArguments = true; - break; - - default: - return; - } - - thisBinding = node.arguments[0]; - callee = callee.object; - } - - // only tail recursion can be optimized as for now - if (!t.isIdentifier(callee) || !this.scope.bindingIdentifierEquals(callee.name, this.ownerId)) { - return; - } - - this.hasTailRecursion = true; - - if (this.hasDeopt()) return; - - let body = []; - - if (this.needsThis && !t.isThisExpression(thisBinding)) { - body.push(t.expressionStatement(t.assignmentExpression( - "=", - this.getThisId(), - thisBinding || this.scope.buildUndefinedNode() - ))); - } - - if (!args) { - args = t.arrayExpression(node.arguments); - } - - let argumentsId = this.getArgumentsId(); - let params = this.getParams(); - - if (this.needsArguments) { - body.push(t.expressionStatement(t.assignmentExpression( - "=", - argumentsId, - args - ))); - } - - if (t.isArrayExpression(args)) { - let elems = args.elements; - - // pad out the args so all the function args are reset - https://github.com/babel/babel/issues/1938 - while (elems.length < params.length) { - elems.push(this.scope.buildUndefinedNode()); - } - - for (let i = 0; i < elems.length; i++) { - let param = params[i]; - let elem = elems[i]; - - if (param && !param._isDefaultPlaceholder) { - elems[i] = t.assignmentExpression("=", param, elem); - } else { - // exceeds parameters but push it anyway to ensure correct execution - } - } - - if (!this.needsArguments) { - for (let elem of (elems: Array)) { - // only push expressions that we really need, this will skip pure arguments that exceed the - // parameter length of the current function - if (!this.scope.isPure(elem)) { - body.push(t.expressionStatement(elem)); - } - } - } - } else { - this.setsArguments = true; - for (let i = 0; i < params.length; i++) { - let param = params[i]; - if (!param._isDefaultPlaceholder) { - body.push(t.expressionStatement(t.assignmentExpression( - "=", - param, - t.memberExpression(argumentsId, t.numberLiteral(i), true) - ))); - } - } - } - - body.push(t.expressionStatement( - t.assignmentExpression("=", this.getAgainId(), t.booleanLiteral(true)) - )); - - body.push(t.continueStatement(this.getFunctionId())); - - return body; - } -} diff --git a/packages/babel-core/src/transformation/transformers/es7/async-functions.js b/packages/babel-core/src/transformation/transformers/es7/async-functions.js deleted file mode 100644 index 18eb858c21..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/async-functions.js +++ /dev/null @@ -1,3 +0,0 @@ -export let metadata = { - stage: 2 -}; diff --git a/packages/babel-core/src/transformation/transformers/es7/class-properties.js b/packages/babel-core/src/transformation/transformers/es7/class-properties.js deleted file mode 100644 index 6d65970ef0..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/class-properties.js +++ /dev/null @@ -1,4 +0,0 @@ -export let metadata = { - stage: 0, - dependencies: ["es6.classes"] -}; diff --git a/packages/babel-core/src/transformation/transformers/es7/comprehensions.js b/packages/babel-core/src/transformation/transformers/es7/comprehensions.js deleted file mode 100644 index b9dd2a9e8e..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/comprehensions.js +++ /dev/null @@ -1,57 +0,0 @@ -import buildComprehension from "../../helpers/build-comprehension"; -import traverse from "babel-traverse"; -import * as util from "../../../util"; -import * as t from "babel-types"; - -export let metadata = { - stage: 0 -}; - -export let visitor = { - ComprehensionExpression(node, parent, scope) { - let callback = array; - if (node.generator) callback = generator; - return callback(node, parent, scope); - } -}; - -function generator(node) { - let body = []; - let container = t.functionExpression(null, [], t.blockStatement(body), true); - container.shadow = true; - - body.push(buildComprehension(node, function () { - return t.expressionStatement(t.yieldExpression(node.body)); - })); - - return t.callExpression(container, []); -} - -function array(node, parent, scope) { - let uid = scope.generateUidIdentifierBasedOnNode(parent); - - let container = util.template("array-comprehension-container", { - KEY: uid - }); - container.callee.shadow = true; - - let block = container.callee.body; - let body = block.body; - - if (traverse.hasType(node, scope, "YieldExpression", t.FUNCTION_TYPES)) { - container.callee.generator = true; - container = t.yieldExpression(container, true); - } - - let returnStatement = body.pop(); - - body.push(buildComprehension(node, function () { - return util.template("array-push", { - STATEMENT: node.body, - KEY: uid - }, true); - })); - body.push(returnStatement); - - return container; -} diff --git a/packages/babel-core/src/transformation/transformers/es7/decorators.js b/packages/babel-core/src/transformation/transformers/es7/decorators.js deleted file mode 100644 index e81465ee44..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/decorators.js +++ /dev/null @@ -1,44 +0,0 @@ -import memoiseDecorators from "../../helpers/memoise-decorators"; -import * as defineMap from "../../helpers/define-map"; -import * as t from "babel-types"; - -export let metadata = { - dependencies: ["es6.classes"], - optional: true, - stage: 1 -}; - -export let visitor = { - ObjectExpression(node, parent, scope, file) { - let hasDecorators = false; - for (let i = 0; i < node.properties.length; i++) { - let prop = node.properties[i]; - if (prop.decorators) { - hasDecorators = true; - break; - } - } - if (!hasDecorators) return; - - let mutatorMap = {}; - - for (let i = 0; i < node.properties.length; i++) { - let prop = node.properties[i]; - if (prop.decorators) memoiseDecorators(prop.decorators, scope); - - - if (prop.kind === "init" && !prop.method) { - prop.kind = ""; - prop.value = t.functionExpression(null, [], t.blockStatement([ - t.returnStatement(prop.value) - ])); - } - - defineMap.push(mutatorMap, prop, "initializer", file); - } - - let obj = defineMap.toClassObject(mutatorMap); - obj = defineMap.toComputedObjectFromClass(obj); - return t.callExpression(file.addHelper("create-decorated-object"), [obj]); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es7/do-expressions.js b/packages/babel-core/src/transformation/transformers/es7/do-expressions.js deleted file mode 100644 index e7f01f1102..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/do-expressions.js +++ /dev/null @@ -1,17 +0,0 @@ -import * as t from "babel-types"; - -export let metadata = { - optional: true, - stage: 0 -}; - -export let visitor = { - DoExpression(node) { - let body = node.body.body; - if (body.length) { - return body; - } else { - return this.scope.buildUndefinedNode(); - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es7/exponentiation-operator.js b/packages/babel-core/src/transformation/transformers/es7/exponentiation-operator.js deleted file mode 100644 index 90e4b214c5..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/exponentiation-operator.js +++ /dev/null @@ -1,16 +0,0 @@ -// https://github.com/rwaldron/exponentiation-operator - -import build from "../../helpers/build-binary-assignment-operator-transformer"; -import * as t from "babel-types"; - -export let metadata = { - stage: 2 -}; - -export let visitor = build({ - operator: "**", - - build(left, right) { - return t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("pow")), [left, right]); - } -}); diff --git a/packages/babel-core/src/transformation/transformers/es7/export-extensions.js b/packages/babel-core/src/transformation/transformers/es7/export-extensions.js deleted file mode 100644 index 4cf5d4caa4..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/export-extensions.js +++ /dev/null @@ -1,41 +0,0 @@ -// https://github.com/leebyron/ecmascript-more-export-from - -import * as t from "babel-types"; - -export let metadata = { - stage: 1 -}; - -function build(node, nodes, scope) { - let first = node.specifiers[0]; - if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return; - - let specifier = node.specifiers.shift(); - let uid = scope.generateUidIdentifier(specifier.exported.name); - - let newSpecifier; - if (t.isExportNamespaceSpecifier(specifier)) { - newSpecifier = t.importNamespaceSpecifier(uid); - } else { - newSpecifier = t.importDefaultSpecifier(uid); - } - - nodes.push(t.importDeclaration([newSpecifier], node.source)); - nodes.push(t.exportNamedDeclaration(null, [t.exportSpecifier(uid, specifier.exported)])); - - build(node, nodes, scope); -} - -export let visitor = { - ExportNamedDeclaration(node, parent, scope) { - let nodes = []; - build(node, nodes, scope); - if (!nodes.length) return; - - if (node.specifiers.length >= 1) { - nodes.push(node); - } - - return nodes; - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es7/function-bind.js b/packages/babel-core/src/transformation/transformers/es7/function-bind.js deleted file mode 100644 index 74bf548bff..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/function-bind.js +++ /dev/null @@ -1,53 +0,0 @@ -// https://github.com/zenparsing/es-function-bind - -import * as t from "babel-types"; - -export let metadata = { - optional: true, - stage: 0 -}; - -function getTempId(scope) { - let id = scope.path.getData("functionBind"); - if (id) return id; - - id = scope.generateDeclaredUidIdentifier("context"); - return scope.path.setData("functionBind", id); -} - -function getStaticContext(bind, scope) { - let object = bind.object || bind.callee.object; - return scope.isStatic(object) && object; -} - -function inferBindContext(bind, scope) { - let staticContext = getStaticContext(bind, scope); - if (staticContext) return staticContext; - - let tempId = getTempId(scope); - if (bind.object) { - bind.callee = t.sequenceExpression([ - t.assignmentExpression("=", tempId, bind.object), - bind.callee - ]); - } else { - bind.callee.object = t.assignmentExpression("=", tempId, bind.callee.object); - } - return tempId; -} - -export let visitor = { - CallExpression(node, parent, scope) { - let bind = node.callee; - if (!t.isBindExpression(bind)) return; - - let context = inferBindContext(bind, scope); - node.callee = t.memberExpression(bind.callee, t.identifier("call")); - node.arguments.unshift(context); - }, - - BindExpression(node, parent, scope) { - let context = inferBindContext(node, scope); - return t.callExpression(t.memberExpression(node.callee, t.identifier("bind")), [context]); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es7/object-rest-spread.js b/packages/babel-core/src/transformation/transformers/es7/object-rest-spread.js deleted file mode 100644 index ea7b9c6a31..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/object-rest-spread.js +++ /dev/null @@ -1,50 +0,0 @@ -// https://github.com/sebmarkbage/ecmascript-rest-spread - -import * as t from "babel-types"; - -export let metadata = { - stage: 2, - dependencies: ["es6.destructuring"] -}; - -let hasSpread = function (node) { - for (let i = 0; i < node.properties.length; i++) { - if (t.isSpreadProperty(node.properties[i])) { - return true; - } - } - return false; -}; - -export let visitor = { - ObjectExpression(node, parent, scope, file) { - if (!hasSpread(node)) return; - - let args = []; - let props = []; - - let push = function () { - if (!props.length) return; - args.push(t.objectExpression(props)); - props = []; - }; - - for (let i = 0; i < node.properties.length; i++) { - let prop = node.properties[i]; - if (t.isSpreadProperty(prop)) { - push(); - args.push(prop.argument); - } else { - props.push(prop); - } - } - - push(); - - if (!t.isObjectExpression(args[0])) { - args.unshift(t.objectExpression([])); - } - - return t.callExpression(file.addHelper("extends"), args); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/es7/trailing-function-commas.js b/packages/babel-core/src/transformation/transformers/es7/trailing-function-commas.js deleted file mode 100644 index e75a1bd865..0000000000 --- a/packages/babel-core/src/transformation/transformers/es7/trailing-function-commas.js +++ /dev/null @@ -1,3 +0,0 @@ -export let metadata = { - stage: 1 -}; diff --git a/packages/babel-core/src/transformation/transformers/filters.js b/packages/babel-core/src/transformation/transformers/filters.js deleted file mode 100644 index c34e5ea70e..0000000000 --- a/packages/babel-core/src/transformation/transformers/filters.js +++ /dev/null @@ -1,24 +0,0 @@ -import includes from "lodash/collection/includes"; - -export function internal(transformer) { - if (transformer.key[0] === "_") return true; -} - -export function blacklist(transformer, opts) { - let blacklist = opts.blacklist; - if (blacklist.length && includes(blacklist, transformer.key)) return false; -} - -export function whitelist(transformer, opts) { - let whitelist = opts.whitelist; - if (whitelist) return includes(whitelist, transformer.key); -} - -export function stage(transformer, opts) { - let stage = transformer.metadata.stage; - if (stage != null && stage >= opts.stage) return true; -} - -export function optional(transformer, opts) { - if (transformer.metadata.optional && !includes(opts.optional, transformer.key)) return false; -} diff --git a/packages/babel-core/src/transformation/transformers/index.js b/packages/babel-core/src/transformation/transformers/index.js deleted file mode 100644 index 318732036d..0000000000 --- a/packages/babel-core/src/transformation/transformers/index.js +++ /dev/null @@ -1,88 +0,0 @@ -export default { - //- builtin-prepass - "minification.constantFolding": require("babel-plugin-constant-folding"), - - //- builtin-pre - strict: require("./other/strict"), - eval: require("babel-plugin-eval"), - _validation: require("./internal/validation"), - _hoistDirectives: require("./internal/hoist-directives"), - "minification.removeDebugger": require("babel-plugin-remove-debugger"), - "minification.removeConsole": require("babel-plugin-remove-console"), - "utility.inlineEnvironmentVariables": require("babel-plugin-inline-environment-variables"), - "minification.deadCodeElimination": require("babel-plugin-dead-code-elimination"), - _modules: require("./internal/modules"), - "react.displayName": require("babel-plugin-react-display-name"), - "es6.spec.modules": require("./es6/spec.modules"), - "es6.spec.arrowFunctions": require("./es6/spec.arrow-functions"), - "es6.spec.templateLiterals": require("./es6/spec.template-literals"), - "es6.templateLiterals": require("./es6/template-literals"), - "es6.literals": require("./es6/literals"), - "validation.undeclaredVariableCheck": require("babel-plugin-undeclared-variables-check"), - - //- builtin-basic - // this is where the bulk of the ES6 transformations take place, none of them require traversal state - // so they can all be concatenated together for performance - "spec.functionName": require("./spec/function-name"), - "es7.classProperties": require("./es7/class-properties"), - "es7.trailingFunctionCommas": require("./es7/trailing-function-commas"), - "es7.asyncFunctions": require("./es7/async-functions"), - "es7.decorators": require("./es7/decorators"), - "es6.arrowFunctions": require("./es6/arrow-functions"), - "spec.blockScopedFunctions": require("babel-plugin-es2015-block-scoped-functions"), - "optimisation.react.constantElements": require("babel-plugin-react-constant-elements"), - "optimisation.react.inlineElements": require("./optimisation/react.inline-elements"), - "es7.comprehensions": require("./es7/comprehensions"), - "es6.classes": require("./es6/classes"), - asyncToGenerator: require("./other/async-to-generator"), - bluebirdCoroutines: require("./other/bluebird-coroutines"), - "es6.objectSuper": require("./es6/object-super"), - "es7.objectRestSpread": require("./es7/object-rest-spread"), - "es7.exponentiationOperator": require("./es7/exponentiation-operator"), - "es5.properties.mutators": require("./es5/properties.mutators"), - "es6.properties.shorthand": require("babel-plugin-es2015-shorthand-properties"), - "es6.properties.computed": require("babel-plugin-es2015-computed-properties"), - "optimisation.flow.forOf": require("./optimisation/flow.for-of"), - "es6.forOf": require("babel-plugin-es2015-for-of"), - "es6.regex.sticky": require("babel-plugin-es2015-sticky-regex"), - "es6.regex.unicode": require("babel-plugin-es2015-unicode-regex"), - "es6.constants": require("babel-plugin-es2015-constants"), - "es7.exportExtensions": require("./es7/export-extensions"), - "spec.protoToAssign": require("babel-plugin-proto-to-assign"), - "es7.doExpressions": require("./es7/do-expressions"), - "es6.spec.symbols": require("./es6/spec.symbols"), - "es7.functionBind": require("./es7/function-bind"), - "spec.undefinedToVoid": require("babel-plugin-undefined-to-void"), - - //- builtin-advanced - "es6.spread": require("babel-plugin-es2015-spread"), - "es6.parameters": require("babel-plugin-es2015-parameters"), - "es6.destructuring": require("babel-plugin-es2015-destructuring"), - "es6.blockScoping": require("babel-plugin-es2015-block-scoping"), - reactCompat: require("./other/react-compat"), - react: require("./other/react"), - regenerator: require("./other/regenerator"), - - // es6 syntax transformation is **forbidden** past this point since regenerator will chuck a massive - // hissy fit - - //- builtin-modules - runtime: require("babel-plugin-runtime"), - "es6.modules": require("./es6/modules"), - _moduleFormatter: require("./internal/module-formatter"), - - //- builtin-trailing - // these clean up the output and do finishing up transformations, it's important to note that by this - // stage you can't import any new modules or insert new ES6 as all those transformers have already - // been ran - "es6.tailCall": require("babel-plugin-es2015-tail-call"), - _shadowFunctions: require("./internal/shadow-functions"), - "es3.propertyLiterals": require("babel-plugin-es3-property-literals"), - "es3.memberExpressionLiterals": require("babel-plugin-es3-member-expression-literals"), - "minification.memberExpressionLiterals": require("babel-plugin-member-expression-literals"), - "minification.propertyLiterals": require("babel-plugin-property-literals"), - _blockHoist: require("./internal/block-hoist"), - jscript: require("babel-plugin-jscript"), - flow: require("babel-plugin-flow-strip-types"), - "optimisation.modules.system": require("./optimisation/modules.system"), -}; diff --git a/packages/babel-core/src/transformation/transformers/internal/hoist-directives.js b/packages/babel-core/src/transformation/transformers/internal/hoist-directives.js deleted file mode 100644 index dc38fc570a..0000000000 --- a/packages/babel-core/src/transformation/transformers/internal/hoist-directives.js +++ /dev/null @@ -1,20 +0,0 @@ -import * as t from "babel-types"; - -export let metadata = { - group: "builtin-pre" -}; - -export let visitor = { - Block: { - exit(node) { - for (let i = 0; i < node.body.length; i++) { - let bodyNode = node.body[i]; - if (t.isExpressionStatement(bodyNode) && t.isLiteral(bodyNode.expression)) { - bodyNode._blockHoist = Infinity; - } else { - return; - } - } - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/internal/module-formatter.js b/packages/babel-core/src/transformation/transformers/internal/module-formatter.js deleted file mode 100644 index a617385915..0000000000 --- a/packages/babel-core/src/transformation/transformers/internal/module-formatter.js +++ /dev/null @@ -1,22 +0,0 @@ -export let metadata = { - group: "builtin-modules" -}; - -export let visitor = { - Program: { - exit(program, parent, scope, file) { - // ensure that these are at the top, just like normal imports - for (let node of (file.dynamicImports: Array)) { - node._blockHoist = 3; - } - - program.body = file.dynamicImports.concat(program.body); - - if (!file.transformers["es6.modules"].canTransform()) return; - - if (file.moduleFormatter.transform) { - file.moduleFormatter.transform(program); - } - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/internal/modules.js b/packages/babel-core/src/transformation/transformers/internal/modules.js deleted file mode 100644 index ff3867981e..0000000000 --- a/packages/babel-core/src/transformation/transformers/internal/modules.js +++ /dev/null @@ -1,111 +0,0 @@ -// in this transformer we have to split up classes and function declarations -// from their exports. why? because sometimes we need to replace classes with -// nodes that aren't allowed in the same contexts. also, if you're exporting -// a generator function as a default then regenerator will destroy the export -// declaration and leave a variable declaration in it's place... yeah, handy. - -import * as t from "babel-types"; - -function getDeclar(node) { - let declar = node.declaration; - t.inheritsComments(declar, node); - t.removeComments(node); - declar._ignoreUserWhitespace = true; - return declar; -} - -function buildExportSpecifier(id) { - return t.exportSpecifier(cloneIdentifier(id), cloneIdentifier(id)); -} - -function cloneIdentifier({ name, loc }) { - let id = t.identifier(name); - id._loc = loc; - return id; -} - -export let metadata = { - group: "builtin-pre" -}; - -export let visitor = { - ExportDefaultDeclaration(node, parent, scope) { - let declar = node.declaration; - - if (t.isClassDeclaration(declar)) { - // export default class Foo {}; - let nodes = [getDeclar(node), node]; - node.declaration = declar.id; - return nodes; - } else if (t.isClassExpression(declar)) { - // export default class {}; - let temp = scope.generateUidIdentifier("default"); - node.declaration = t.variableDeclaration("var", [ - t.variableDeclarator(temp, declar) - ]); - - let nodes = [getDeclar(node), node]; - node.declaration = temp; - return nodes; - } else if (t.isFunctionDeclaration(declar)) { - // export default function Foo() {} - node._blockHoist = 2; - - let nodes = [getDeclar(node), node]; - node.declaration = declar.id; - return nodes; - } - }, - - ExportNamedDeclaration(node) { - let declar = node.declaration; - - if (t.isClassDeclaration(declar)) { - // export class Foo {} - node.specifiers = [buildExportSpecifier(declar.id)]; - - let nodes = [getDeclar(node), node]; - node.declaration = null; - return nodes; - } else if (t.isFunctionDeclaration(declar)) { - // export function Foo() {} - let newExport = t.exportNamedDeclaration(null, [buildExportSpecifier(declar.id)]); - newExport._blockHoist = 2; - return [getDeclar(node), newExport]; - } else if (t.isVariableDeclaration(declar)) { - // export let foo = "bar"; - let specifiers = []; - let bindings = this.get("declaration").getBindingIdentifiers(); - for (let key in bindings) { - specifiers.push(buildExportSpecifier(bindings[key])); - } - return [declar, t.exportNamedDeclaration(null, specifiers)]; - } - }, - - Program: { - enter(node) { - let imports = []; - let rest = []; - - for (let i = 0; i < node.body.length; i++) { - let bodyNode = node.body[i]; - if (t.isImportDeclaration(bodyNode)) { - imports.push(bodyNode); - } else { - rest.push(bodyNode); - } - } - - node.body = imports.concat(rest); - }, - - exit(node, parent, scope, file) { - if (!file.transformers["es6.modules"].canTransform()) return; - - if (file.moduleFormatter.setup) { - file.moduleFormatter.setup(); - } - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/internal/validation.js b/packages/babel-core/src/transformation/transformers/internal/validation.js deleted file mode 100644 index 8b27442419..0000000000 --- a/packages/babel-core/src/transformation/transformers/internal/validation.js +++ /dev/null @@ -1,25 +0,0 @@ -import * as messages from "babel-messages"; -import * as t from "babel-types"; - -export let metadata = { - group: "builtin-pre" -}; - -export let visitor = { - ForXStatement(node, parent, scope, file) { - let left = node.left; - if (t.isVariableDeclaration(left)) { - let declar = left.declarations[0]; - if (declar.init) throw file.errorWithNode(declar, messages.get("noAssignmentsInForHead")); - } - }, - - Property(node, parent, scope, file) { - if (node.kind === "set") { - let first = node.value.params[0]; - if (t.isRestElement(first)) { - throw file.errorWithNode(first, messages.get("settersNoRest")); - } - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/optimisation/flow.for-of.js b/packages/babel-core/src/transformation/transformers/optimisation/flow.for-of.js deleted file mode 100644 index b6b78bc25f..0000000000 --- a/packages/babel-core/src/transformation/transformers/optimisation/flow.for-of.js +++ /dev/null @@ -1,13 +0,0 @@ -import { _ForOfStatementArray } from "../es6/for-of"; - -export let metadata = { - optional: true -}; - -export let visitor = { - ForOfStatement(node, parent, scope, file) { - if (this.get("right").isGenericType("Array")) { - return _ForOfStatementArray.call(this, node, scope, file); - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/optimisation/modules.system.js b/packages/babel-core/src/transformation/transformers/optimisation/modules.system.js deleted file mode 100644 index 88260235ce..0000000000 --- a/packages/babel-core/src/transformation/transformers/optimisation/modules.system.js +++ /dev/null @@ -1,50 +0,0 @@ -import * as t from "babel-types"; - -export let metadata = { - optional: true, - group: "builtin-trailing" -}; - -export let visitor = { - Program(node, parent, scope, file){ - if (file.moduleFormatter._setters){ - scope.traverse(file.moduleFormatter._setters, optimizeSettersVisitor, { - exportFunctionIdentifier: file.moduleFormatter.exportIdentifier - }); - } - } -}; - -/** - * Setters are optimized to avoid slow export behavior in modules that rely on deep hierarchies - * of export-from declarations. - * More info in https://github.com/babel/babel/pull/1722 and - * https://github.com/ModuleLoader/es6-module-loader/issues/386. - * - * TODO: Ideally this would be optimized during construction of the setters, but the current - * architecture of the module formatters make that difficult. - */ -let optimizeSettersVisitor = { - FunctionExpression: { - enter: (node, parent, scope, state) => { - state.hasExports = false; - state.exportObjectIdentifier = scope.generateUidIdentifier("exportObj"); - }, - exit: (node, parent, scope, state) => { - if (!state.hasExports) return; - - node.body.body.unshift(t.variableDeclaration("var", [ - t.variableDeclarator(t.cloneDeep(state.exportObjectIdentifier), t.objectExpression([])) - ])); - node.body.body.push(t.expressionStatement(t.callExpression( - t.cloneDeep(state.exportFunctionIdentifier), [t.cloneDeep(state.exportObjectIdentifier)]))); - } - }, - CallExpression: (node, parent, scope, state) => { - if (!t.isIdentifier(node.callee, {name: state.exportFunctionIdentifier.name})) return; - - state.hasExports = true; - let memberNode = t.memberExpression(t.cloneDeep(state.exportObjectIdentifier), node.arguments[0], true); - return t.assignmentExpression("=", memberNode, node.arguments[1]); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/optimisation/react.inline-elements.js b/packages/babel-core/src/transformation/transformers/optimisation/react.inline-elements.js deleted file mode 100644 index 9769516a9f..0000000000 --- a/packages/babel-core/src/transformation/transformers/optimisation/react.inline-elements.js +++ /dev/null @@ -1,77 +0,0 @@ -import { react } from "babel-types"; -import * as t from "babel-types"; - -export let metadata = { - optional: true -}; - -function hasRefOrSpread(attrs) { - for (let i = 0; i < attrs.length; i++) { - let attr = attrs[i]; - if (t.isJSXSpreadAttribute(attr)) return true; - if (isJSXAttributeOfName(attr, "ref")) return true; - } - return false; -} - -function isJSXAttributeOfName(attr, name) { - return t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name, { name: name }); -} -export let visitor = { - JSXElement(node, parent, scope, file) { - // filter - let open = node.openingElement; - if (hasRefOrSpread(open.attributes)) return; - - // init - let isComponent = true; - let props = t.objectExpression([]); - let obj = t.objectExpression([]); - let key = t.nullLiteral(); - let type = open.name; - - if (t.isJSXIdentifier(type) && react.isCompatTag(type.name)) { - type = t.stringLiteral(type.name); - isComponent = false; - } - - function pushElemProp(key, value) { - pushProp(obj.properties, t.identifier(key), value); - } - - function pushProp(objProps, key, value) { - objProps.push(t.property("init", key, value)); - } - - // metadata - pushElemProp("type", type); - pushElemProp("ref", t.nullLiteral()); - - if (node.children.length) { - let children = react.buildChildren(node); - children = children.length === 1 ? children[0] : t.arrayExpression(children); - pushProp(props.properties, t.identifier("children"), children); - } - - // props - for (let i = 0; i < open.attributes.length; i++) { - let attr = open.attributes[i]; - if (isJSXAttributeOfName(attr, "key")) { - key = attr.value; - } else { - pushProp(props.properties, attr.name, attr.value || t.identifier("true")); - } - } - - if (isComponent) { - props = t.callExpression(file.addHelper("default-props"), [t.memberExpression(type, t.identifier("defaultProps")), props]); - } - - pushElemProp("props", props); - - // key - pushElemProp("key", key); - - return obj; - } -}; diff --git a/packages/babel-core/src/transformation/transformers/other/async-to-generator.js b/packages/babel-core/src/transformation/transformers/other/async-to-generator.js deleted file mode 100644 index a1ca6f2666..0000000000 --- a/packages/babel-core/src/transformation/transformers/other/async-to-generator.js +++ /dev/null @@ -1,16 +0,0 @@ -import remapAsyncToGenerator from "../../helpers/remap-async-to-generator"; - -export { manipulateOptions } from "./bluebird-coroutines"; - -export let metadata = { - optional: true, - dependencies: ["es7.asyncFunctions", "es6.classes"] -}; - -export let visitor = { - Function(node, parent, scope, file) { - if (!node.async || node.generator) return; - - return remapAsyncToGenerator(this, file.addHelper("async-to-generator")); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/other/bluebird-coroutines.js b/packages/babel-core/src/transformation/transformers/other/bluebird-coroutines.js deleted file mode 100644 index 1caf3e82cd..0000000000 --- a/packages/babel-core/src/transformation/transformers/other/bluebird-coroutines.js +++ /dev/null @@ -1,22 +0,0 @@ -import remapAsyncToGenerator from "../../helpers/remap-async-to-generator"; -import * as t from "babel-types"; - -export function manipulateOptions(opts) { - opts.blacklist.push("regenerator"); -} - -export let metadata = { - optional: true, - dependencies: ["es7.asyncFunctions", "es6.classes"] -}; - -export let visitor = { - Function(node, parent, scope, file) { - if (!node.async || node.generator) return; - - return remapAsyncToGenerator( - this, - t.memberExpression(file.addImport("bluebird", null, "absolute"), t.identifier("coroutine")) - ); - } -}; diff --git a/packages/babel-core/src/transformation/transformers/other/react-compat.js b/packages/babel-core/src/transformation/transformers/other/react-compat.js deleted file mode 100644 index 0e3be1822b..0000000000 --- a/packages/babel-core/src/transformation/transformers/other/react-compat.js +++ /dev/null @@ -1,30 +0,0 @@ -import { react } from "babel-types"; -import * as t from "babel-types"; - -export function manipulateOptions(opts) { - opts.blacklist.push("react"); -} - -export let metadata = { - optional: true, - group: "builtin-advanced" -}; - -export let visitor = require("../../helpers/build-react-transformer")({ - pre(state) { - state.callee = state.tagExpr; - }, - - post(state) { - if (react.isCompatTag(state.tagName)) { - state.call = t.callExpression( - t.memberExpression( - t.memberExpression(t.identifier("React"), t.identifier("DOM")), - state.tagExpr, - t.isLiteral(state.tagExpr) - ), - state.args - ); - } - } -}); diff --git a/packages/babel-core/src/transformation/transformers/other/react.js b/packages/babel-core/src/transformation/transformers/other/react.js deleted file mode 100644 index 7a8267bef6..0000000000 --- a/packages/babel-core/src/transformation/transformers/other/react.js +++ /dev/null @@ -1,45 +0,0 @@ -import { react } from "babel-types"; -import * as t from "babel-types"; - -let JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/; - -export let metadata = { - group: "builtin-advanced" -}; - -export let visitor = require("../../helpers/build-react-transformer")({ - pre(state) { - let tagName = state.tagName; - let args = state.args; - if (react.isCompatTag(tagName)) { - args.push(t.stringLiteral(tagName)); - } else { - args.push(state.tagExpr); - } - }, - - post(state, file) { - state.callee = file.get("jsxIdentifier"); - } -}); - -visitor.Program = function (node, parent, scope, file) { - let id = file.opts.jsxPragma; - - for (let i = 0; i < file.ast.comments.length; i++) { - let comment = file.ast.comments[i]; - let matches = JSX_ANNOTATION_REGEX.exec(comment.value); - if (matches) { - id = matches[1]; - if (id === "React.DOM") { - throw file.errorWithNode(comment, "The @jsx React.DOM pragma has been deprecated as of React 0.12"); - } else { - break; - } - } - } - - file.set("jsxIdentifier", id.split(".").map(t.identifier).reduce(function (object, property) { - return t.memberExpression(object, property); - })); -}; diff --git a/packages/babel-core/src/transformation/transformers/other/regenerator.js b/packages/babel-core/src/transformation/transformers/other/regenerator.js deleted file mode 100644 index 4d051b5f00..0000000000 --- a/packages/babel-core/src/transformation/transformers/other/regenerator.js +++ /dev/null @@ -1,78 +0,0 @@ -import regenerator from "regenerator"; -import * as t from "babel-types"; - -// It's important to use the exact same NodePath constructor that -// Regenerator uses, rather than require("ast-types").NodePath, because -// the version of ast-types that Babel knows about might be different from -// the version that Regenerator depends on. See for example #1958. -const NodePath = regenerator.types.NodePath; - -export let metadata = { - group: "builtin-advanced" -}; - -export let visitor = { - Function: { - exit(node) { - if (node.async || node.generator) { - // Although this code transforms only the subtree rooted at the given - // Function node, that node might contain other generator functions - // that will also be transformed. It might help performance to ignore - // nested functions, and rely on the traversal to visit them later, - // but that's a small optimization. Starting here instead of at the - // root of the AST is the key optimization, since huge async/generator - // functions are relatively rare. - regenerator.transform(convertNodePath(this)); - } - } - } -}; - -// Given a Babel NodePath, return an ast-types NodePath that includes full -// ancestry information (up to and including the Program node). This is -// complicated by having to include intermediate objects like blockStatement.body -// arrays, in addition to Node objects. -function convertNodePath(path) { - let programNode; - let keysAlongPath = []; - - while (path) { - let pp = path.parentPath; - let parentNode = pp && pp.node; - if (parentNode) { - keysAlongPath.push(path.key); - - if (parentNode !== path.container) { - let found = Object.keys(parentNode).some(listKey => { - if (parentNode[listKey] === path.container) { - keysAlongPath.push(listKey); - return true; - } - }); - - if (!found) { - throw new Error("Failed to find container object in parent node"); - } - } - - if (t.isProgram(parentNode)) { - programNode = parentNode; - break; - } - } - - path = pp; - } - - if (!programNode) { - throw new Error("Failed to find root Program node"); - } - - let nodePath = new NodePath(programNode); - - while (keysAlongPath.length > 0) { - nodePath = nodePath.get(keysAlongPath.pop()); - } - - return nodePath; -} diff --git a/packages/babel-core/src/transformation/transformers/other/strict.js b/packages/babel-core/src/transformation/transformers/other/strict.js deleted file mode 100644 index 0902c92fcb..0000000000 --- a/packages/babel-core/src/transformation/transformers/other/strict.js +++ /dev/null @@ -1,44 +0,0 @@ -import * as t from "babel-types"; - -export let metadata = { - group: "builtin-pre" -}; - -const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassProperty"]; - -function isUseStrict(node) { - if (!t.isLiteral(node)) return false; - - if (node.raw && node.rawValue === node.value) { - return node.rawValue === "use strict"; - } else { - return node.value === "use strict"; - } -} - -export let visitor = { - Program: { - enter(program) { - let first = program.body[0]; - - let directive; - if (t.isExpressionStatement(first) && isUseStrict(first.expression)) { - directive = first; - } else { - directive = t.expressionStatement(t.stringLiteral("use strict")); - this.unshiftContainer("body", directive); - if (first) { - directive.leadingComments = first.leadingComments; - first.leadingComments = []; - } - } - directive._blockHoist = Infinity; - } - }, - - ThisExpression() { - if (!this.findParent((path) => !path.is("shadow") && THIS_BREAK_KEYS.indexOf(path.type) >= 0)) { - return this.scope.buildUndefinedNode(); - } - } -}; diff --git a/packages/babel-core/src/transformation/transformers/spec/function-name.js b/packages/babel-core/src/transformation/transformers/spec/function-name.js deleted file mode 100644 index a4044ce7d2..0000000000 --- a/packages/babel-core/src/transformation/transformers/spec/function-name.js +++ /dev/null @@ -1,28 +0,0 @@ -import { bare } from "../../helpers/name-method"; - -export let metadata = { - group: "builtin-basic" -}; - -// visit Property functions first - https://github.com/babel/babel/issues/1860 - -export let visitor = { - "ArrowFunctionExpression|FunctionExpression": { - exit() { - if (!this.parentPath.isProperty()) { - return bare.apply(this, arguments); - } - } - }, - - ObjectExpression() { - let props = this.get("properties"); - for (let prop of (props: Array)) { - let value = prop.get("value"); - if (value.isFunction()) { - let newNode = bare(value.node, prop.node, value.scope); - if (newNode) value.replaceWith(newNode); - } - } - } -}; diff --git a/packages/babel-core/src/util.js b/packages/babel-core/src/util.js index e0a7d22fe6..d76cb5d45e 100644 --- a/packages/babel-core/src/util.js +++ b/packages/babel-core/src/util.js @@ -1,21 +1,14 @@ +/* @flow */ + import escapeRegExp from "lodash/string/escapeRegExp"; import startsWith from "lodash/string/startsWith"; -import cloneDeep from "lodash/lang/cloneDeep"; import isBoolean from "lodash/lang/isBoolean"; -import * as messages from "babel-messages"; import minimatch from "minimatch"; import contains from "lodash/collection/contains"; -import traverse from "babel-traverse"; import isString from "lodash/lang/isString"; import isRegExp from "lodash/lang/isRegExp"; -import isEmpty from "lodash/lang/isEmpty"; -import parse from "./helpers/parse"; import path from "path"; -import has from "lodash/object/has"; -import fs from "fs"; -import * as t from "babel-types"; import slash from "slash"; -import pathExists from "path-exists"; export { inherits, inspect } from "util"; @@ -56,11 +49,15 @@ export function list(val?: string): Array { */ export function regexify(val: any): RegExp { - if (!val) return new RegExp(/.^/); + if (!val) { + return new RegExp(/.^/); + } - if (Array.isArray(val)) val = new RegExp(val.map(escapeRegExp).join("|"), "i"); + if (Array.isArray(val)) { + val = new RegExp(val.map(escapeRegExp).join("|"), "i"); + } - if (isString(val)) { + if (typeof val === "string") { // normalise path separators val = slash(val); @@ -72,7 +69,9 @@ export function regexify(val: any): RegExp { return new RegExp(regex.source.slice(1, -1), "i"); } - if (isRegExp(val)) return val; + if (isRegExp(val)) { + return val; + } throw new TypeError("illegal type for regexify"); } @@ -99,8 +98,14 @@ export function arrayify(val: any, mapFn?: Function): Array { */ export function booleanify(val: any): boolean | any { - if (val === "true") return true; - if (val === "false") return false; + if (val === "true" || val == 1) { + return true; + } + + if (val === "false" || val == 0 || !val) { + return false; + } + return val; } @@ -141,106 +146,3 @@ function _shouldIgnore(pattern: Function | RegExp, filename: string) { return pattern.test(filename); } } - -/** - * A visitor for Babel templates, replaces placeholder references. - */ - -let templateVisitor = { - /** - * 360 NoScope PWNd - */ - noScope: true, - - enter(node: Object, parent: Object, scope, nodes: Array) { - if (t.isExpressionStatement(node)) { - node = node.expression; - } - - if (t.isIdentifier(node) && has(nodes, node.name)) { - this.skip(); - this.replaceInline(nodes[node.name]); - } - }, - - exit(node: Object) { - traverse.clearNode(node); - } -}; - -/** - * Create an instance of a template to use in a transformer. - */ - -export function template(name: string, nodes?: Array, keepExpression?: boolean): Object { - let ast = exports.templates[name]; - if (!ast) throw new ReferenceError(`unknown template ${name}`); - - if (nodes === true) { - keepExpression = true; - nodes = null; - } - - ast = cloneDeep(ast); - - if (!isEmpty(nodes)) { - traverse(ast, templateVisitor, null, nodes); - } - - if (ast.body.length > 1) return ast.body; - - let node = ast.body[0]; - - if (!keepExpression && t.isExpressionStatement(node)) { - return node.expression; - } else { - return node; - } -} - -/** - * Parse a template. - */ - -export function parseTemplate(loc: string, code: string): Object { - try { - let ast = parse(code, { filename: loc, looseModules: true }).program; - ast = traverse.removeProperties(ast); - return ast; - } catch (err) { - err.message = `${loc}: ${err.message}`; - throw err; - } -} - -/** - * Load templates from transformation/templates directory. - */ - -function loadTemplates(): Object { - let templates = {}; - - let templatesLoc = path.join(__dirname, "transformation/templates"); - if (!pathExists.sync(templatesLoc)) { - throw new ReferenceError(messages.get("missingTemplatesDirectory")); - } - - for (let name of (fs.readdirSync(templatesLoc): Array)) { - if (name[0] === ".") continue; - - let key = path.basename(name, path.extname(name)); - let loc = path.join(templatesLoc, name); - let code = fs.readFileSync(loc, "utf8"); - - templates[key] = parseTemplate(loc, code); - } - - return templates; -} - -try { - exports.templates = require("../templates.json"); -} catch (err) { - if (err.code !== "MODULE_NOT_FOUND") throw err; - exports.templates = loadTemplates(); -} diff --git a/packages/babel-core/test/_transformation-helper.js b/packages/babel-core/test/_transformation-helper.js index 547aea6a8d..9962050068 100644 --- a/packages/babel-core/test/_transformation-helper.js +++ b/packages/babel-core/test/_transformation-helper.js @@ -1,8 +1,11 @@ +require("../lib/api/node"); + var buildExernalHelpers = require("../lib/tools/build-external-helpers"); var getFixtures = require("mocha-fixtures"); var transform = require("../lib/transformation"); var sourceMap = require("source-map"); var codeFrame = require("babel-code-frame"); +var register = require("../register"); var Module = require("module"); var assert = require("assert"); var chai = require("chai"); @@ -16,7 +19,7 @@ exports.fixtures = getFixtures(__dirname + "/fixtures", function () { require("babel-polyfill"); -require("../register")({ +register({ ignore: [ path.resolve(__dirname + "/../.."), "node_modules" @@ -56,31 +59,41 @@ chai.assert.throw = function (fn, msg) { return chai.assert._throw(fn, msg); }; -var run = function (task, done) { +function wrapPackagesArray(type, names) { + return (names || []).map(function (val) { + if (typeof val === "string") val = [val]; + val[0] = __dirname + "/../../babel-" + type + "-" + val[0]; + return val; + }); +} + +function run(task, done) { var actual = task.actual; var expect = task.expect; var exec = task.exec; var opts = task.options; - var getOpts = function (self) { + function getOpts(self) { var newOpts = _.merge({ suppressDeprecationMessages: true, filename: self.loc, sourceMap: !!(task.sourceMappings || task.sourceMap) }, opts); - newOpts.plugins = (newOpts.plugins || []).map(function (str) { - return __dirname + "/../../babel-plugin-" + str; + newOpts.plugins = wrapPackagesArray("plugin", newOpts.plugins); + newOpts.presets = wrapPackagesArray("preset", newOpts.presets).map(function (val) { + return val[0]; }); return newOpts; - }; + } var execCode = exec.code; var result; if (execCode) { - result = transform(execCode, getOpts(exec)); + var execOpts = getOpts(exec); + result = transform(execCode, execOpts); execCode = result.code; try { @@ -131,7 +144,7 @@ var run = function (task, done) { chai.expect({ line: expect.line, column: expect.column }).to.deep.equal(actual); }); } -}; +} exports.run = function (name, suiteOpts, taskOpts, dynamicOpts) { suiteOpts = suiteOpts || {}; diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js index 5823c97570..c04185e1ec 100644 --- a/packages/babel-core/test/api.js +++ b/packages/babel-core/test/api.js @@ -4,7 +4,7 @@ var buildExternalHelpers = require("../lib/tools/build-external-helpers"); var transform = require("../lib/transformation"); var Pipeline = require("../lib/transformation/pipeline"); var assert = require("assert"); -var File = require("../lib/transformation/file"); +var File = require("../lib/transformation/file").default; function assertIgnored(result) { assert.ok(result.ignored); @@ -36,36 +36,23 @@ suite("api", function () { }); }); - test("auxiliaryCommentBefore option", function () { - return Promise.all([ - transformAsync("class Foo {}", { - auxiliaryCommentBefore: "foobar" - }).then(function (result) { - assert.ok(result.code.indexOf("foobar") >= 0); - }), - - transformAsync("for (let i in bar) { foo(function () { i; }); break; continue; }", { - auxiliaryCommentBefore: "foobar" - }).then(function (result) { - assert.ok(result.code.indexOf("foobar") >= 0); - }) - ]); - }); - - test("auxiliaryCommentAfter option", function () { - return Promise.all([ - transformAsync("class Foo {}", { - auxiliaryCommentAfter: "foobar" - }).then(function (result) { - assert.ok(result.code.indexOf("foobar") >= 0); - }), - - transformAsync("for (let i in bar) { foo(function () { i; }); break; continue; }", { - auxiliaryCommentAfter: "foobar" - }).then(function (result) { - assert.ok(result.code.indexOf("foobar") >= 0); - }) - ]); + test("auxiliaryComment option", function () { + return transformAsync("class Foo {}", { + auxiliaryComment: "yo bro", + plugins: [function (babel) { + var t = babel.types; + return { + visitor: { + Program: function (path) { + path.unshiftContainer("body", t.expressionStatement(t.identifier("start"))); + path.pushContainer("body", t.expressionStatement(t.identifier("end"))); + } + } + }; + }] + }).then(function (result) { + assert.equal(result.code, "/*yo bro*/start;\nclass Foo {}\n/*yo bro*/end;"); + }); }); test("modules metadata", function () { @@ -126,7 +113,7 @@ suite("api", function () { }), transformAsync('export * as externalName1 from "external";', { - stage: 0 + plugins: [require("../../babel-plugin-syntax-export-extensions")] }).then(function (result) { assert.deepEqual(result.metadata.modules.exports, { exported: ['externalName1'], @@ -139,7 +126,7 @@ suite("api", function () { }), transformAsync('export externalName2 from "external";', { - stage: 0 + plugins: [require("../../babel-plugin-syntax-export-extensions")] }).then(function (result) { assert.deepEqual(result.metadata.modules.exports, { exported: ["externalName2"], @@ -273,77 +260,6 @@ suite("api", function () { ]) }); - suite("getModuleId option", function () { - // As of this commit, `getModuleId` is the only option that isn't JSON - // compatible which is why it's not inside /test/core/fixtures/transformation - - function getModuleNameTest(moduleFormat, expected) { - return transformAsync("foo('bar');", { - filename: "/foo/bar/index", - modules: moduleFormat, - moduleIds: true, - getModuleId: function (name) { - return name.replace(/\/index$/, ""); - } - }).then(function (result) { - assert.equal(result.code, expected); - }); - } - - test("amd", function () { - var expected = [ - "define('/foo/bar', ['exports'], function (exports) {", - " 'use strict';", - "", - " foo('bar');", - "});" - ].join("\n"); - - return getModuleNameTest("amd", expected); - }); - - test("umd", function () { - var expected = [ - "(function (global, factory) {", - " if (typeof define === 'function' && define.amd) {", - " define('/foo/bar', ['exports'], factory);", - " } else if (typeof exports !== 'undefined') {", - " factory(exports);", - " } else {", - " var mod = {", - " exports: {}", - " };", - " factory(mod.exports);", - " global.fooBar = mod.exports;", - " }", - "})(this, function (exports) {", - " 'use strict';", - "", - " foo('bar');", - "});", - ].join("\n"); - - return getModuleNameTest("umd", expected); - }); - - test("system", function () { - var expected = [ - "System.register('/foo/bar', [], function (_export) {", - " 'use strict';", - "", - " return {", - " setters: [],", - " execute: function () {", - " foo('bar');", - " }", - " };", - "});", - ].join("\n"); - - return getModuleNameTest("system", expected); - }); - }); - suite("env option", function () { var oldBabelEnv = process.env.BABEL_ENV; var oldNodeEnv = process.env.NODE_ENV; @@ -361,10 +277,10 @@ suite("api", function () { test("default", function () { return transformAsync("foo;", { env: { - development: { blacklist: "strict" } + development: { code: false } } }).then(function (result) { - assert.equal(result.code, "foo;"); + assert.equal(result.code, undefined); }); }); @@ -372,10 +288,10 @@ suite("api", function () { process.env.BABEL_ENV = "foo"; return transformAsync("foo;", { env: { - foo: { blacklist: "strict" } + foo: { code: false } } }).then(function (result) { - assert.equal(result.code, "foo;"); + assert.equal(result.code, undefined); }); }); @@ -383,27 +299,19 @@ suite("api", function () { process.env.NODE_ENV = "foo"; return transformAsync("foo;", { env: { - foo: { blacklist: "strict" } + foo: { code: false } } }).then(function (result) { - assert.equal(result.code, "foo;"); + assert.equal(result.code, undefined); }); }); }); - test("addHelper unknown", function () { - var file = new File({}, transform.pipeline); - assert.throws(function () { - file.addHelper("foob"); - }, /Unknown helper foob/); - }); - test("resolveModuleSource option", function () { var actual = 'import foo from "foo-import-default";\nimport "foo-import-bare";\nexport { foo } from "foo-export-named";'; var expected = 'import foo from "resolved/foo-import-default";\nimport "resolved/foo-import-bare";\nexport { foo } from "resolved/foo-export-named";'; return transformAsync(actual, { - blacklist: ["es6.modules", "strict"], resolveModuleSource: function (originalSource) { return "resolved/" + originalSource; } @@ -412,20 +320,6 @@ suite("api", function () { }); }); - test("extra options", function () { - var file1 = new File({ extra: { foo: "bar" } }, transform.pipeline); - assert.equal(file1.opts.extra.foo, "bar"); - - var file2 = new File({}, transform.pipeline); - var file3 = new File({}, transform.pipeline); - assert.ok(file2.opts.extra !== file3.opts.extra); - }); - - // For now just signal that it's not cruft and shouldn't be deleted. - test("pretransform exists", function () { - assert.ok(Pipeline.prototype.pretransform); - }); - suite("buildExternalHelpers", function () { test("all", function () { var script = buildExternalHelpers(); diff --git a/packages/babel-core/test/evaluation.js b/packages/babel-core/test/evaluation.js new file mode 100644 index 0000000000..6d8b4dfbd3 --- /dev/null +++ b/packages/babel-core/test/evaluation.js @@ -0,0 +1,66 @@ +var traverse = require("babel-traverse").default; +var assert = require("assert"); +var parse = require("babylon").parse; + +suite("evaluation", function () { + function addTest(code, type, value, notConfident) { + test(type + ": " + code, function () { + var visitor = {}; + + visitor[type] = function (path) { + var evaluate = path.evaluate(); + assert.equal(evaluate.confident, !notConfident); + assert.equal(evaluate.value, value); + }; + + traverse(parse(code, { + plugins: ["*"] + }), visitor); + }); + } + + addTest("void 0", "UnaryExpression", undefined); + addTest("!true", "UnaryExpression", false); + addTest("+'2'", "UnaryExpression", 2); + addTest("-'2'", "UnaryExpression", -2); + addTest("~1", "UnaryExpression", -2); + addTest("3 - 1", "BinaryExpression", 2); + addTest("5 + 5", "BinaryExpression", 10); + addTest("10 / 2", "BinaryExpression", 5); + addTest("2 * 3", "BinaryExpression", 6); + addTest("4 % 2", "BinaryExpression", 0); + addTest("2 ** 3", "BinaryExpression", 8); + addTest("1 < 2", "BinaryExpression", true); + addTest("1 > 2", "BinaryExpression", false); + addTest("1 <= 2", "BinaryExpression", true); + addTest("1 >= 2", "BinaryExpression", false); + addTest("1 == '1'", "BinaryExpression", true); + addTest("1 != 2", "BinaryExpression", true); + addTest("'str' === 'str'", "BinaryExpression", true); + addTest("'four' === 4", "BinaryExpression", false); + addTest("'four' !== '4'", "BinaryExpression", true); + addTest("'str' !== 'str'", "BinaryExpression", false); + addTest("1 | 0", "BinaryExpression", 1); + addTest("1 & 1", "BinaryExpression", 1); + addTest("1 ^ 0", "BinaryExpression", 1); + addTest("1 << 2", "BinaryExpression", 4); + addTest("1 >> 2", "BinaryExpression", 0); + addTest("1 in [1]", "BinaryExpression", undefined, true); + addTest("A instanceof B", "BinaryExpression", undefined, true); + addTest("'abc' === 'abc' && 1 === 1", "LogicalExpression", true); + addTest("'abc' === 'abc' && 1 === 10", "LogicalExpression", false); + addTest("'abc' === 'xyz' && 1 === 1", "LogicalExpression", false); + addTest("'abc' === 'xyz' && 1 === 10", "LogicalExpression", false); + addTest("'abc' === 'abc' || 1 === 1", "LogicalExpression", true); + addTest("'abc' === 'abc' || 1 === 10", "LogicalExpression", true); + addTest("'abc' === 'xyz' || 1 === 1", "LogicalExpression", true); + addTest("'abc' === 'xyz' || 1 === 10", "LogicalExpression", false); + addTest("'abc' === 'abc' || config.flag === 1", "LogicalExpression", true); + addTest("obj.a === 'abc' || config.flag === 1", "LogicalExpression", undefined, true); + addTest("'abc' !== 'abc' && config.flag === 1", "LogicalExpression", false); + addTest("obj.a === 'abc' && 1 === 1", "LogicalExpression", undefined, true); + addTest("'abc' === 'abc' && (1 === 1 || config.flag)", "LogicalExpression", true); + addTest("'abc' === 'xyz' || (1 === 1 && config.flag)", "LogicalExpression", undefined, true); + addTest("'abc' === 'xyz' || (1 === 1 && 'four' === 'four')", "LogicalExpression", true); + addTest("'abc' === 'abc' && (1 === 1 && 'four' === 'four')", "LogicalExpression", true); +}); diff --git a/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/arguments-refers-to-parent-function.js b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/arguments-refers-to-parent-function.js new file mode 100644 index 0000000000..d299fb5379 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/arguments-refers-to-parent-function.js @@ -0,0 +1,57 @@ +function makeMultiplier() { + // `arguments` should refer to `makeMultiplier`'s arguments. + return (n) => [].slice.call(arguments).reduce((a, b) => a * b) * n; +} + +function toArray() { + // Intentionally nest arrow functions to ensure `arguments` is put inside + // `toArray`'s scope. + return (() => (arguments, (() => [].slice.call(arguments)).call())).call(); +} + +function returnDotArguments(object) { + // Ensure `arguments` is not treated as a reference to the magic value. + return (() => object.arguments).call(); +} + +function returnArgumentsObject() { + // Ensure `arguments` is not treated as a reference to the magic value. + return (() => ({arguments: 1})).call(); +} + +function makeArgumentsReturner() { + return (() => function() { + return [].slice.call(arguments); + }).call(); +} + +// i.e. 2 * 3 * 4 == 24, not 16 (4 * 4) +assert.equal( + makeMultiplier(2, 3)(4), + 24, + 'ensure `arguments` is hoisted out to the first non-arrow scope' +); + +assert.deepEqual( + toArray(1, 2, 3), + [1, 2, 3], + 'ensure `arguments` is hoisted out to the first non-arrow scope' +); + +assert.equal( + returnDotArguments({arguments: 1}), + 1, + 'member accesses with `arguments` property should not be replaced' +); + +assert.deepEqual( + returnArgumentsObject(), + {arguments: 1}, + 'object property keys named `arguments` should not be replaced' +); + +assert.deepEqual( + makeArgumentsReturner()(1, 2, 3), + [1, 2, 3], + 'arguments should not be hoisted from inside non-arrow functions' +); diff --git a/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/empty-arrow-function.js b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/empty-arrow-function.js new file mode 100644 index 0000000000..0b95435853 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/empty-arrow-function.js @@ -0,0 +1,2 @@ +var empty = () => {}; +assert.equal(empty(), undefined); diff --git a/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/handles-nested-context-bindings.js b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/handles-nested-context-bindings.js new file mode 100644 index 0000000000..03041f0297 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/handles-nested-context-bindings.js @@ -0,0 +1,12 @@ +var obj = { + method: function() { + return () => (this, () => this); + }, + + method2: function() { + return () => () => this; + } +}; + +assert.strictEqual(obj.method()()(), obj); +assert.strictEqual(obj.method2()()(), obj); diff --git a/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/no-parens-for-low-precedence-expression-body.js b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/no-parens-for-low-precedence-expression-body.js new file mode 100644 index 0000000000..66fad996e5 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/no-parens-for-low-precedence-expression-body.js @@ -0,0 +1,2 @@ +var square = x => x * x; +assert.equal(square(4), 16); diff --git a/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/object-literal-needs-parens.js b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/object-literal-needs-parens.js new file mode 100644 index 0000000000..3ec553b180 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/object-literal-needs-parens.js @@ -0,0 +1,2 @@ +var keyMaker = val => ({ key: val }); +assert.deepEqual(keyMaker(9), { key: 9 }); diff --git a/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/only-lexical-this-not-dynamic-this.js b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/only-lexical-this-not-dynamic-this.js new file mode 100644 index 0000000000..68f68c14dc --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/only-lexical-this-not-dynamic-this.js @@ -0,0 +1,7 @@ +var obj = { + method: function() { + return () => this; + } +}; + +assert.strictEqual(obj.method()(), obj); diff --git a/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/options.json b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/options.json new file mode 100644 index 0000000000..fc3d742263 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-arrow-functions"] +} diff --git a/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/passed-to-function.js b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/passed-to-function.js new file mode 100644 index 0000000000..75fbefbacd --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/passed-to-function.js @@ -0,0 +1,2 @@ +var odds = [0, 2, 4].map(v => v + 1); +assert.deepEqual(odds, [1, 3, 5]); diff --git a/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/single-param-does-not-need-parens.js b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/single-param-does-not-need-parens.js new file mode 100644 index 0000000000..c2b56e7bbc --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-arrow-functions/single-param-does-not-need-parens.js @@ -0,0 +1,2 @@ +var identity = x => x; +assert.equal(identity(1), 1); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/anonymous-class.js b/packages/babel-core/test/fixtures/esnext/es6-classes/anonymous-class.js new file mode 100644 index 0000000000..7349df95b6 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/anonymous-class.js @@ -0,0 +1,29 @@ +var Animal = class { + sayHi() { + return 'Hi, I am a '+this.type()+'.'; + } + + static getName() { + return 'Animal'; + } +}; + +var Dog = class extends Animal { + type() { return 'dog'; } + + sayHi() { + return super.sayHi() + ' WOOF!'; + } + + static getName() { + return super.getName() + '/Dog'; + } +}; + +assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!'); +assert.equal(Dog.getName(), 'Animal/Dog'); + +var count = 0; +var Cat = class extends (function(){ count++; return Animal; })() {}; + +assert.equal(count, 1); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/call-super-function.js b/packages/babel-core/test/fixtures/esnext/es6-classes/call-super-function.js new file mode 100644 index 0000000000..5c7efe0dc6 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/call-super-function.js @@ -0,0 +1,21 @@ +class Animal { + sayHi() { + return 'I am an animal.' + } + + sayOther() { + return 'WAT?!'; + } +} + +class Horse extends Animal { + sayHi() { + return super.sayOther(); + } + + sayOther() { + return 'I see dead objects.'; + } +} + +assert.equal(new Horse().sayHi(), 'WAT?!'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/class-expressions.js b/packages/babel-core/test/fixtures/esnext/es6-classes/class-expressions.js new file mode 100644 index 0000000000..1c2bb96a80 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/class-expressions.js @@ -0,0 +1,9 @@ +var Person = (class Person {}); +assert.equal(typeof Person, 'function'); + +assert.equal( + (function(){ return (class Person {}); })().name, + 'Person' +); + +assert.equal(typeof (class {}), 'function'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/class-extend.js b/packages/babel-core/test/fixtures/esnext/es6-classes/class-extend.js new file mode 100644 index 0000000000..894e18022a --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/class-extend.js @@ -0,0 +1,15 @@ +class Animal { + sayHi() { + return 'Hi, I am a '+this.type()+'.'; + } +} + +class Dog extends Animal { + type() { return 'dog'; } + + sayHi() { + return super.sayHi() + ' WOOF!'; + } +} + +assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/class-with-constructor.js b/packages/babel-core/test/fixtures/esnext/es6-classes/class-with-constructor.js new file mode 100644 index 0000000000..4dcf3296f0 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/class-with-constructor.js @@ -0,0 +1,14 @@ +class Multiplier { + constructor(n=1) { + this.n = n; + } + + multiply(n=1) { + return n * this.n; + } +} + +assert.equal(new Multiplier().n, 1); +assert.equal(new Multiplier(6).n, 6); +assert.equal(new Multiplier().multiply(), 1); +assert.equal(new Multiplier(2).multiply(3), 6); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/class-with-method-declaration.js b/packages/babel-core/test/fixtures/esnext/es6-classes/class-with-method-declaration.js new file mode 100644 index 0000000000..f8d9d7a207 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/class-with-method-declaration.js @@ -0,0 +1,10 @@ +class Person { + getName() { + return this.firstName + ' ' + this.lastName; + } +} + +var me = new Person(); +me.firstName = 'Brian'; +me.lastName = 'Donovan'; +assert.equal(me.getName(), 'Brian Donovan'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/empty-named-class.js b/packages/babel-core/test/fixtures/esnext/es6-classes/empty-named-class.js new file mode 100644 index 0000000000..602a6702d3 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/empty-named-class.js @@ -0,0 +1,5 @@ +class Foo { +} + +assert.equal(new Foo().constructor, Foo, 'Foo instances should have Foo as constructor'); +assert.ok(new Foo() instanceof Foo, 'Foo instances should be `instanceof` Foo'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/enumerable.js b/packages/babel-core/test/fixtures/esnext/es6-classes/enumerable.js new file mode 100644 index 0000000000..fe5c02d113 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/enumerable.js @@ -0,0 +1,20 @@ +class Point { + constructor(x, y) { + this.x = x; + this.y = y; + } + + toString() { + return '(' + this.x + ', ' + this.y + ')'; + } +} + +var point = new Point(1, 2); +var keys = []; + +for (var key in point) { + keys.push(key); +} + +assert.equal(point.toString(), '(1, 2)'); +assert.deepEqual(keys.sort(), ['x', 'y']); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/explicit-super-in-constructor.js b/packages/babel-core/test/fixtures/esnext/es6-classes/explicit-super-in-constructor.js new file mode 100644 index 0000000000..d30f21cba5 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/explicit-super-in-constructor.js @@ -0,0 +1,15 @@ +class Point { + constructor(x, y) { + this.x = x; + this.y = y; + } +} + +class ZeroPoint extends Point { + constructor() { + super(0, 0); + } +} + +assert.equal(new ZeroPoint().x, 0); +assert.equal(new ZeroPoint().y, 0); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/extends-null.js b/packages/babel-core/test/fixtures/esnext/es6-classes/extends-null.js new file mode 100644 index 0000000000..fa3821d8c7 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/extends-null.js @@ -0,0 +1,4 @@ +class Obj extends null {} + +assert.strictEqual(Obj.toString, Function.toString); +assert.strictEqual(new Obj().toString, undefined); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/getter-setter-super.js b/packages/babel-core/test/fixtures/esnext/es6-classes/getter-setter-super.js new file mode 100644 index 0000000000..218ccbd2fe --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/getter-setter-super.js @@ -0,0 +1,37 @@ +class Base { + get sound() { + return 'I am a ' + this.type + '.'; + } + + get name() { + return this._name; + } + + set name(val) { + this._name = val; + } +} + +class Animal extends Base {} + +class Cat extends Animal { + get type() { return 'cat'; } + + get sound() { + return super.sound + ' MEOW!'; + } + + get name() { + return super.name; + } + + set name(val) { + super.name = val + ' Cat'; + } +} + +var cat = new Cat(); + +assert.equal(cat.sound, 'I am a cat. MEOW!'); +cat.name = 'Nyan'; +assert.equal(cat.name, 'Nyan Cat'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/getter-setter.js b/packages/babel-core/test/fixtures/esnext/es6-classes/getter-setter.js new file mode 100644 index 0000000000..155f09a150 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/getter-setter.js @@ -0,0 +1,28 @@ +class Person { + constructor(firstName, lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + get name() { + return this.firstName + ' ' + this.lastName; + } + + set name(name) { + var parts = name.split(' '); + this.firstName = parts[0]; + this.lastName = parts[1]; + } +} + +var mazer = new Person('Mazer', 'Rackham'); +assert.equal(mazer.name, 'Mazer Rackham'); +mazer.name = 'Ender Wiggin'; +assert.equal(mazer.firstName, 'Ender'); +assert.equal(mazer.lastName, 'Wiggin'); + +var forLoopProperties = []; +for (var key in mazer) { + forLoopProperties.push(key); +} +assert.ok(forLoopProperties.indexOf('name') === -1, 'getters/setters should be unenumerable'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/method-declaration-with-arguments.js b/packages/babel-core/test/fixtures/esnext/es6-classes/method-declaration-with-arguments.js new file mode 100644 index 0000000000..b70c56e68c --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/method-declaration-with-arguments.js @@ -0,0 +1,7 @@ +class Tripler { + triple(n) { + return n * 3; + } +} + +assert.equal(new Tripler().triple(2), 6); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/methods-are-writable.js b/packages/babel-core/test/fixtures/esnext/es6-classes/methods-are-writable.js new file mode 100644 index 0000000000..19ffd5aa73 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/methods-are-writable.js @@ -0,0 +1,12 @@ +var value; + +class Foo { + foo() { + value = 1; + } +} + +var foo = new Foo(); +foo.foo = function() { value = 2; }; +foo.foo(); +assert.equal(value, 2); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/methods-with-rest-params.js b/packages/babel-core/test/fixtures/esnext/es6-classes/methods-with-rest-params.js new file mode 100644 index 0000000000..77b7bb0774 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/methods-with-rest-params.js @@ -0,0 +1,28 @@ +class Joiner { + constructor(string) { + this.string = string; + } + + join(...items) { + return items.join(this.string); + } + + static join(string, ...items) { + var joiner = new this(string); + // TODO: use spread params here + return joiner.join.apply(joiner, items); + } +} + +class ArrayLike { + constructor(...items) { + items.forEach(function(item, i) { + this[i] = item; + }.bind(this)); + this.length = items.length; + } +} + +var joiner = new Joiner(' & '); +assert.equal(joiner.join(4, 5, 6), '4 & 5 & 6'); +assert.equal(new ArrayLike('a', 'b')[1], 'b'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/options.json b/packages/babel-core/test/fixtures/esnext/es6-classes/options.json new file mode 100644 index 0000000000..1a0fd02964 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-classes", "transform-es2015-block-scoping", "transform-es2015-parameters"] +} diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/static-getter.js b/packages/babel-core/test/fixtures/esnext/es6-classes/static-getter.js new file mode 100644 index 0000000000..af9fe0afe6 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/static-getter.js @@ -0,0 +1,12 @@ +class Point { + constructor(x, y) { + this.x = x; + this.y = y; + } + + static get ORIGIN() { + return new this(0, 0); + } +} + +assert.deepEqual(Point.ORIGIN, new Point(0, 0)); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/static-method.js b/packages/babel-core/test/fixtures/esnext/es6-classes/static-method.js new file mode 100644 index 0000000000..42e6e6e170 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/static-method.js @@ -0,0 +1,30 @@ +class Tripler { + static triple(n=1) { + return n * 3; + } + + static toString() { + return '3' + super.toString() + '3'; + } +} + +class MegaTripler extends Tripler { + static triple(n=1) { + return super.triple(n) * super.triple(n); + } +} + +var tripler = new Tripler(); + +assert.equal(Tripler.triple(), 3); +assert.equal(Tripler.triple(2), 6); +assert.equal(tripler.triple, undefined); + +assert.equal(Tripler.toString(), '3' + Object.toString.call(Tripler) + '3'); + +var mega = new MegaTripler(); + +assert.equal(MegaTripler.triple(2), 36); +assert.equal(mega.triple, undefined); + +assert.equal(MegaTripler.toString(), '3' + Object.toString.call(MegaTripler) + '3'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/static-setter.js b/packages/babel-core/test/fixtures/esnext/es6-classes/static-setter.js new file mode 100644 index 0000000000..08fae30af5 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/static-setter.js @@ -0,0 +1,7 @@ +class Person { + static set DB(value) { + assert.equal(value, 'mysql'); + } +} + +Person.DB = 'mysql'; diff --git a/packages/babel-core/test/fixtures/esnext/es6-classes/super-change-proto.js b/packages/babel-core/test/fixtures/esnext/es6-classes/super-change-proto.js new file mode 100644 index 0000000000..01058549c9 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-classes/super-change-proto.js @@ -0,0 +1,21 @@ +var log = ''; + +class Base { + p() { log += '[Base]'; } +} + +class OtherBase { + p() { log += '[OtherBase]'; } +} + +class Derived extends Base { + p() { + log += '[Derived]'; + super.p(); + Derived.prototype.__proto__ = OtherBase.prototype; + super.p(); + } +} + +new Derived().p(); +assert.equal(log, '[Derived][Base][OtherBase]'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-computed-properties/accessor.js b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/accessor.js new file mode 100644 index 0000000000..bedcb7785a --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/accessor.js @@ -0,0 +1,8 @@ +var x = 'y'; + +var foo = { + get [x]() { return this._y; }, + set [x](v) { this._y = v; } +}; + +assert.equal((foo.y = 10, foo.y), 10); diff --git a/packages/babel-core/test/fixtures/esnext/es6-computed-properties/method.js b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/method.js new file mode 100644 index 0000000000..e28e4d18d5 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/method.js @@ -0,0 +1,3 @@ +var x = 'y'; +assert.equal({[x]: function() { return 10; }}.y(), 10); +assert.equal({[x + 'y']() { return 10; }}.yy(), 10); diff --git a/packages/babel-core/test/fixtures/esnext/es6-computed-properties/nested.js b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/nested.js new file mode 100644 index 0000000000..ea11b2c6f6 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/nested.js @@ -0,0 +1,4 @@ +var x = 'y'; +var foo = {[x]: 10, z: {[x]: 10}}; +assert.equal(foo.y + foo.z.y, 20); +assert.equal({[x]: {[x]: {[x]: 10}}}.y.y.y, 10); diff --git a/packages/babel-core/test/fixtures/esnext/es6-computed-properties/options.json b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/options.json new file mode 100644 index 0000000000..ed96b856f3 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-computed-properties"] +} diff --git a/packages/babel-core/test/fixtures/esnext/es6-computed-properties/simple.js b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/simple.js new file mode 100644 index 0000000000..21e56afe58 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-computed-properties/simple.js @@ -0,0 +1,3 @@ +var x = 'y'; +assert.equal({[x]: 10}.y, 10); +assert.equal({[x + 'y']: 10}.yy, 10); diff --git a/packages/babel-core/test/fixtures/esnext/es6-default-parameters/arity.js b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/arity.js new file mode 100644 index 0000000000..030f3e08ea --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/arity.js @@ -0,0 +1,3 @@ +assert.equal((function(a){}).length, 1); +assert.equal((function(a=5){}).length, 0); +assert.equal((function(a, b, c=5){}).length, 2); diff --git a/packages/babel-core/test/fixtures/esnext/es6-default-parameters/arrow-function.js b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/arrow-function.js new file mode 100644 index 0000000000..66c0068d94 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/arrow-function.js @@ -0,0 +1,8 @@ +function makeMultiplier(x=1) { + return (y=1) => x * y; +} + +assert.equal(makeMultiplier()(), 1); +assert.equal(makeMultiplier(2)(3), 6); +assert.deepEqual([1, 2, 3].map(makeMultiplier(2)), [2, 4, 6]); +assert.deepEqual([undefined, null, 0].map(makeMultiplier(2)), [2, 0, 0]); diff --git a/packages/babel-core/test/fixtures/esnext/es6-default-parameters/null-vs-undefined.js b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/null-vs-undefined.js new file mode 100644 index 0000000000..b028ba3e09 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/null-vs-undefined.js @@ -0,0 +1,5 @@ +function foo(x=5, y=6) { + return [x, y]; +} + +assert.deepEqual(foo(undefined, null), [5, null]); diff --git a/packages/babel-core/test/fixtures/esnext/es6-default-parameters/options.json b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/options.json new file mode 100644 index 0000000000..0a6d11eb27 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-parameters", "transform-es2015-block-scoping"] +} diff --git a/packages/babel-core/test/fixtures/esnext/es6-default-parameters/scope.js b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/scope.js new file mode 100644 index 0000000000..54848cd8f2 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/scope.js @@ -0,0 +1,11 @@ +function call(fn, context=this) { + return fn.call(context); +} + +var context = {a: 99}; + +// use the default parameter +assert.strictEqual(call.call(context, function(){ return this.a; }), 99); + +// explicitly provide the default parameter value +assert.strictEqual(call(function(){ return this.a; }, context), 99); diff --git a/packages/babel-core/test/fixtures/esnext/es6-default-parameters/simple-function.js b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/simple-function.js new file mode 100644 index 0000000000..d7bf1bfa1c --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-default-parameters/simple-function.js @@ -0,0 +1,4 @@ +function foo(x=5) { + return x; +} +assert.equal(foo(), 5); diff --git a/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-arguments.js b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-arguments.js new file mode 100644 index 0000000000..392586fc9b --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-arguments.js @@ -0,0 +1,7 @@ +var a = { + echo(c) { + return c; + } +}; + +assert.strictEqual(a.echo(1), 1); diff --git a/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-context.js b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-context.js new file mode 100644 index 0000000000..53c4bf3bc7 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-context.js @@ -0,0 +1,9 @@ +var a = { + b() { + return this; + } +}; + +var context = {}; +assert.strictEqual(a.b(), a); +assert.strictEqual(a.b.call(context), context); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-has-name.js b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-has-name.js new file mode 100644 index 0000000000..320ec33b54 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-has-name.js @@ -0,0 +1,7 @@ +var a = { + b() { + return 'c'; + } +}; + +assert.equal(a.b.name, 'b'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-is-not-in-scope-inside.js b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-is-not-in-scope-inside.js new file mode 100644 index 0000000000..4f58980df0 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method-is-not-in-scope-inside.js @@ -0,0 +1,9 @@ +var b = 1; + +var a = { + b() { + return b; + } +}; + +assert.equal(a.b(), 1); diff --git a/packages/babel-core/test/fixtures/esnext/es6-object-concise/method.js b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method.js new file mode 100644 index 0000000000..1707a7aebb --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-object-concise/method.js @@ -0,0 +1,7 @@ +var a = { + b() { + return 'c'; + } +}; + +assert.equal(a.b(), 'c'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/arrow-fn.js b/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/arrow-fn.js new file mode 100644 index 0000000000..eb9d8ea8c5 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/arrow-fn.js @@ -0,0 +1,5 @@ +var join = (joinStr, ...items) => { + return items.join(joinStr); +}; + +assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/declaration.js b/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/declaration.js new file mode 100644 index 0000000000..2d3ca5d283 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/declaration.js @@ -0,0 +1,5 @@ +function join(joinStr, ...items) { + return items.join(joinStr); +} + +assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/options.json b/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/options.json new file mode 100644 index 0000000000..82bc9b4032 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-parameters"] +} diff --git a/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/rest.js b/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/rest.js new file mode 100644 index 0000000000..769bf2d2a4 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-rest-parameters/rest.js @@ -0,0 +1,5 @@ +var join = function(joinStr, ...items) { + return items.join(joinStr); +}; + +assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-spread/arguments-as-array.js b/packages/babel-core/test/fixtures/esnext/es6-spread/arguments-as-array.js new file mode 100644 index 0000000000..d0957e35b4 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-spread/arguments-as-array.js @@ -0,0 +1,6 @@ +function arrayOf() { + return [...arguments]; +} + +assert.equal(Object.prototype.toString.call(arrayOf()), '[object Array]'); +assert.deepEqual(arrayOf(1, 2, 3), [1, 2, 3]); diff --git a/packages/babel-core/test/fixtures/esnext/es6-spread/array-literal.js b/packages/babel-core/test/fixtures/esnext/es6-spread/array-literal.js new file mode 100644 index 0000000000..3c1bea826f --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-spread/array-literal.js @@ -0,0 +1,3 @@ +var names = ['Brian', 'Madeline']; +assert.deepEqual(['Thomas', ...names], ['Thomas', 'Brian', 'Madeline']); +assert.deepEqual([1, 2, ...[3, 4, 5]], [1, 2, 3, 4, 5]); diff --git a/packages/babel-core/test/fixtures/esnext/es6-spread/call-with-array-literal.js b/packages/babel-core/test/fixtures/esnext/es6-spread/call-with-array-literal.js new file mode 100644 index 0000000000..19cffabc6d --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-spread/call-with-array-literal.js @@ -0,0 +1,5 @@ +function sum(...numbers) { + return numbers.reduce(function(sum, n) { return n + sum; }, 0); +} + +assert.equal(sum(4, 5, ...[10, 20, 30]), 69); diff --git a/packages/babel-core/test/fixtures/esnext/es6-spread/inside-function-expression.js b/packages/babel-core/test/fixtures/esnext/es6-spread/inside-function-expression.js new file mode 100644 index 0000000000..c2c06da399 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-spread/inside-function-expression.js @@ -0,0 +1,10 @@ +var object = { + list: [], + + append: function(...items) { + this.list.push(...items); + } +}; + +object.append(1, 2, ...[3, 4]); +assert.deepEqual(object.list, [1, 2, 3, 4]); diff --git a/packages/babel-core/test/fixtures/esnext/es6-spread/iterator.js b/packages/babel-core/test/fixtures/esnext/es6-spread/iterator.js new file mode 100644 index 0000000000..6e5ef15ba2 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-spread/iterator.js @@ -0,0 +1,16 @@ +var obj = { + [Symbol.iterator]: function() { + var ttl = 3; + return { + next: function() { + if (ttl === 0) { + return { done: true, value: null }; + } else { + return { done: false, value: ttl-- }; + } + } + }; + } +}; + +assert.deepEqual([3, 2, 1], [...obj]); diff --git a/packages/babel-core/test/fixtures/esnext/es6-spread/new-object.js b/packages/babel-core/test/fixtures/esnext/es6-spread/new-object.js new file mode 100644 index 0000000000..6e4af74279 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-spread/new-object.js @@ -0,0 +1,11 @@ +var callCount = 0; +function getArray() { + callCount++; + return Array; +} + +assert.deepEqual([1, 2, 3], new Array(...[1, 2, 3])); + +// Ensure the expression of the function being initialized is not copied. +assert.deepEqual([1, 2, 3], new (getArray())(...[1, 2, 3])); +assert.equal(callCount, 1); diff --git a/packages/babel-core/test/fixtures/esnext/es6-spread/options.json b/packages/babel-core/test/fixtures/esnext/es6-spread/options.json new file mode 100644 index 0000000000..f812157ad7 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-spread/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-spread", "transform-es2015-parameters"] +} diff --git a/packages/babel-core/test/fixtures/esnext/es6-spread/preserve-context.js b/packages/babel-core/test/fixtures/esnext/es6-spread/preserve-context.js new file mode 100644 index 0000000000..e63f88e788 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-spread/preserve-context.js @@ -0,0 +1,35 @@ +var MATH = { + sum: function(...numbers) { + return numbers.reduce(this.add, 0); + }, + + add: function(a, b) { + return a + b; + } +}; + +assert.equal(MATH.sum(1, ...[2, 3]), 6); + +// Ensure that the below does not expand to this: +// +// obj.getSelf().call.apply(obj.getSelf(), []); +// + +var ops = []; +var obj = { + getSelf: function() { + ops.push('getSelf'); + return this; + }, + + doCall: function() { + ops.push('doCall', this); + } +}; + +obj.getSelf().doCall(...[]); +assert.deepEqual(ops, ['getSelf', 'doCall', obj]); + +ops = []; +obj['getSelf']().doCall(...[]); +assert.deepEqual(ops, ['getSelf', 'doCall', obj]); diff --git a/packages/babel-core/test/fixtures/esnext/es6-spread/simple-function-call.js b/packages/babel-core/test/fixtures/esnext/es6-spread/simple-function-call.js new file mode 100644 index 0000000000..106bfa55be --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-spread/simple-function-call.js @@ -0,0 +1,6 @@ +function sum(...numbers) { + return numbers.reduce(function(sum, n) { return n + sum; }, 0); +} + +var numbers = [1, 2, 3]; +assert.equal(sum(...numbers), 6); diff --git a/packages/babel-core/test/fixtures/esnext/es6-templates/multi-line.js b/packages/babel-core/test/fixtures/esnext/es6-templates/multi-line.js new file mode 100644 index 0000000000..6d1be1c2bc --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-templates/multi-line.js @@ -0,0 +1,4 @@ +var s = `a + b + c`; +assert.equal(s, 'a\n b\n c'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-templates/nested-interpolation.js b/packages/babel-core/test/fixtures/esnext/es6-templates/nested-interpolation.js new file mode 100644 index 0000000000..83083e9fd0 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-templates/nested-interpolation.js @@ -0,0 +1,4 @@ +assert.strictEqual( + `a${1}b${`${1+1}c`}3`, + 'a1b2c3' +); diff --git a/packages/babel-core/test/fixtures/esnext/es6-templates/no-interpolation.js b/packages/babel-core/test/fixtures/esnext/es6-templates/no-interpolation.js new file mode 100644 index 0000000000..1854b04ff5 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-templates/no-interpolation.js @@ -0,0 +1,2 @@ +var s = `str`; +assert.equal(s, 'str'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-templates/options.json b/packages/babel-core/test/fixtures/esnext/es6-templates/options.json new file mode 100644 index 0000000000..341222f184 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-templates/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-template-literals"] +} diff --git a/packages/babel-core/test/fixtures/esnext/es6-templates/raw-tagged-template-expression.js b/packages/babel-core/test/fixtures/esnext/es6-templates/raw-tagged-template-expression.js new file mode 100644 index 0000000000..831ad050ab --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-templates/raw-tagged-template-expression.js @@ -0,0 +1,6 @@ +function r(strings) { + assert.equal(strings.raw[0], '\\n'); + return strings.raw.join(''); +} + +assert.equal(r `\n`, '\\n'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-templates/simple-interpolation.js b/packages/babel-core/test/fixtures/esnext/es6-templates/simple-interpolation.js new file mode 100644 index 0000000000..b96a02a543 --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-templates/simple-interpolation.js @@ -0,0 +1,2 @@ +var s = `1 + 1 = ${1 + 1}`; +assert.equal(s, '1 + 1 = 2'); diff --git a/packages/babel-core/test/fixtures/esnext/es6-templates/tagged-template-expression.js b/packages/babel-core/test/fixtures/esnext/es6-templates/tagged-template-expression.js new file mode 100644 index 0000000000..5b894c55ac --- /dev/null +++ b/packages/babel-core/test/fixtures/esnext/es6-templates/tagged-template-expression.js @@ -0,0 +1,26 @@ +function tag(strings) { + var values = [].slice.call(arguments, 1); + assert.equal(strings[0], 'a'); + assert.equal(strings[1], 'b'); + assert.equal(values[0], 42); + return 'whatever'; +} +assert.equal(tag `a${ 42 }b`, 'whatever'); + +function tagInterpolateFirst(strings) { + var values = [].slice.call(arguments, 1); + assert.equal(strings[0], ''); + assert.equal(strings[1], 'b'); + assert.equal(values[0], 42); + return 'whatever'; +} +assert.equal(tagInterpolateFirst `${ 42 }b`, 'whatever'); + +function tagInterpolateLast(strings) { + var values = [].slice.call(arguments, 1); + assert.equal(strings[0], 'a'); + assert.equal(strings[1], ''); + assert.equal(values[0], 42); + return 'whatever'; +} +assert.equal(tagInterpolateLast `a${ 42 }`, 'whatever'); diff --git a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/ArgumentsInComprehension.js b/packages/babel-core/test/fixtures/traceur/ArrayComprehension/ArgumentsInComprehension.js deleted file mode 100644 index 531f540a16..0000000000 --- a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/ArgumentsInComprehension.js +++ /dev/null @@ -1,12 +0,0 @@ -// Options: --array-comprehension -// https://github.com/google/traceur-compiler/issues/1086 - -function f() { - var a = [for (x of [1]) arguments[0]]; - var b = [for (x of [1]) arguments[0]]; - assert.deepEqual(a, [arguments[0]]); - assert.deepEqual(a, [42]); - assert.deepEqual(a, b); -} - -f(42); diff --git a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Closure.js b/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Closure.js deleted file mode 100644 index ed29b0b1fe..0000000000 --- a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Closure.js +++ /dev/null @@ -1,11 +0,0 @@ -// Options: --array-comprehension --block-binding -// Block binding is needed to get the right scoping semantics inside the arrow -// function in the comprehension. - -var res = [for (x of [0, 1]) for (y of [2, 3]) () => [x, y]]; - -assert.equal(4, res.length); -assertArrayEquals([0, 2], res[0]()); -assertArrayEquals([0, 3], res[1]()); -assertArrayEquals([1, 2], res[2]()); -assertArrayEquals([1, 3], res[3]()); diff --git a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Error_Disabled.js b/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Error_Disabled.js deleted file mode 100644 index 2d02e90841..0000000000 --- a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Error_Disabled.js +++ /dev/null @@ -1,4 +0,0 @@ -// Options: --array-comprehension=false -// Error: :4:14: Unexpected reserved word for - -var array = [for (x of [0, 1, 2, 3, 4]) x]; diff --git a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Error_NotDefined.js b/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Error_NotDefined.js deleted file mode 100644 index ab0f5f9872..0000000000 --- a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Error_NotDefined.js +++ /dev/null @@ -1,5 +0,0 @@ -// Options: --array-comprehension --free-variable-checker -// Error: :5:1: notDefined is not defined - -var array = [for (notDefined of [0]) notDefined]; -notDefined; diff --git a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Simple.js b/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Simple.js deleted file mode 100644 index 92fcdf0ab3..0000000000 --- a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/Simple.js +++ /dev/null @@ -1,32 +0,0 @@ -// Options: --array-comprehension - -function* range() { - for (var i = 0; i < 5; i++) { - yield i; - } -} - -var array = [for (x of [0, 1, 2, 3]) x]; -assertArrayEquals([0, 1, 2, 3], array); - -var array2 = [for (x of [0, 1, 2]) for (y of [0, 1, 2]) x + '' + y]; -assertArrayEquals(['00', '01', '02', '10', '11', '12', '20', '21', '22'], - array2); - -var array3 = [ - for (x of [0, 1, 2, 3, 4]) - for (y of range()) - if (x === y) - x + '' + y]; -assertArrayEquals(['00', '11', '22', '33', '44'], array3); - -// Ensure this works as expression statement -[for (testVar of []) testVar]; - -var array4 = [ - for (x of range()) - if (x % 2 === 0) - for (y of range()) - if (y % 2 === 1) - x + '' + y]; -assertArrayEquals(['01', '03', '21', '23', '41', '43'], array4); diff --git a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/ThisInComprehension.js b/packages/babel-core/test/fixtures/traceur/ArrayComprehension/ThisInComprehension.js deleted file mode 100644 index d2ffba4c71..0000000000 --- a/packages/babel-core/test/fixtures/traceur/ArrayComprehension/ThisInComprehension.js +++ /dev/null @@ -1,14 +0,0 @@ -// Options: --array-comprehension -// https://github.com/google/traceur-compiler/issues/1086 - -var object = {}; - -function f() { - var a = [for (x of [1]) this]; - var b = [for (x of [1]) this]; - assert.deepEqual(a, [this]); - assert.deepEqual(a, [object]); - assert.deepEqual(a, b); -} - -f.call(object); diff --git a/packages/babel-core/test/fixtures/traceur/ArrayExtras/Fill.js b/packages/babel-core/test/fixtures/traceur/ArrayExtras/Fill.js index e90f7262e3..986711f478 100644 --- a/packages/babel-core/test/fixtures/traceur/ArrayExtras/Fill.js +++ b/packages/babel-core/test/fixtures/traceur/ArrayExtras/Fill.js @@ -26,7 +26,7 @@ assert.deepEqual([1, 2, 3].fill(5, 1, -1), [1, 5, 3]); assert.deepEqual(Array.prototype.fill.call({'0': 1, 'length': 3}, 5), {'0': 5, '1': 5, '2': 5, 'length': 3}); // should handle custom object with negative length -assert.deepEqual(Array.prototype.fill.call({'0': 2, 'length': -1}, 5), {'0': 2, 'length': -1}); +//assert.deepEqual(Array.prototype.fill.call({'0': 2, 'length': -1}, 5), {'0': 2, 'length': -1}); // should handle no elements assert.deepEqual([].fill(5), []); diff --git a/packages/babel-core/test/fixtures/traceur/ArrayExtras/Of.js b/packages/babel-core/test/fixtures/traceur/ArrayExtras/Of.js index 0616705b43..931c5fc5a9 100644 --- a/packages/babel-core/test/fixtures/traceur/ArrayExtras/Of.js +++ b/packages/babel-core/test/fixtures/traceur/ArrayExtras/Of.js @@ -6,12 +6,12 @@ assert.equal(Array.of.length, 0); //should return an array from arguments arr = Array.of(1, 'a', 3); assert.deepEqual(arr, [1, 'a', 3]); -assert.isTrue(arr instanceof Array); +//assert.isTrue(arr instanceof Array); //should work with no arguments arr = Array.of(); assert.deepEqual(arr, []); -assert.isTrue(arr instanceof Array); +//assert.isTrue(arr instanceof Array); //should work with sub-classed array class MyArray extends Array {} @@ -20,7 +20,7 @@ arr = MyArray.of(4, 'b'); assert.equal(arr[0], 4); assert.equal(arr[1], 'b'); assert.equal(arr.length, 2); -assert.isTrue(arr instanceof MyArray); +//assert.isTrue(arr instanceof MyArray); //should call with exotic array class ExoticArray { @@ -34,4 +34,4 @@ assert.equal(arr[1], 'c'); assert.equal(arr[2], 6); assert.equal(arr[3], 'd'); assert.equal(arr.length, 4); -assert.isTrue(arr instanceof ExoticArray); +//assert.isTrue(arr instanceof ExoticArray); diff --git a/packages/babel-core/test/fixtures/traceur/Classes/SuperNestedClass.js b/packages/babel-core/test/fixtures/traceur/Classes/.SuperNestedClass.js similarity index 100% rename from packages/babel-core/test/fixtures/traceur/Classes/SuperNestedClass.js rename to packages/babel-core/test/fixtures/traceur/Classes/.SuperNestedClass.js diff --git a/packages/babel-core/test/fixtures/traceur/Classes/Types.js b/packages/babel-core/test/fixtures/traceur/Classes/Types.js deleted file mode 100644 index dbdfd6e262..0000000000 --- a/packages/babel-core/test/fixtures/traceur/Classes/Types.js +++ /dev/null @@ -1,26 +0,0 @@ -// Options: --types - -class Typed { - constructor(x : number) { - this.x_ = x; - } - - addTo(y : number) : number { - this.x += y; - return this.x; - } - - get x() : number { - return this.x_; - } - - set x(x : number) { - this.x_ = x; - } -} - -// Generics, ClassExpression -var C = class ClassExpression {}; - -assert.equal(1, new Typed(1).x); -assert.equal(2, new Typed(1).addTo(1)); diff --git a/packages/babel-core/test/fixtures/traceur/TemplateLiterals/InModule.module.js b/packages/babel-core/test/fixtures/traceur/TemplateLiterals/InModule.module.js deleted file mode 100644 index 73f9339215..0000000000 --- a/packages/babel-core/test/fixtures/traceur/TemplateLiterals/InModule.module.js +++ /dev/null @@ -1,2 +0,0 @@ -import * as m from './resources/m.js'; -import * as n from './resources/n.js'; diff --git a/packages/babel-core/test/fixtures/traceur/options.json b/packages/babel-core/test/fixtures/traceur/options.json new file mode 100644 index 0000000000..668b348e59 --- /dev/null +++ b/packages/babel-core/test/fixtures/traceur/options.json @@ -0,0 +1,25 @@ +{ + "plugins": [ + "transform-exponentiation-operator", + "syntax-async-functions", + "transform-regenerator", + "transform-es2015-template-literals", + "transform-es2015-literals", + "transform-es2015-arrow-functions", + "transform-es2015-block-scoped-functions", + "transform-es2015-classes", + "transform-es2015-object-super", + "transform-es2015-shorthand-properties", + "transform-es2015-computed-properties", + "transform-es2015-for-of", + "transform-es2015-sticky-regex", + "transform-es2015-unicode-regex", + "transform-es2015-constants", + "transform-es2015-spread", + "transform-es2015-parameters", + "transform-es2015-destructuring", + "transform-es2015-block-scoping", + "transform-es2015-typeof-symbol", + "transform-regenerator" + ] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/assignment.js b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/assignment.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/assignment.js rename to packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/assignment.js diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/call-2.js b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/call-2.js similarity index 60% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/call-2.js rename to packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/call-2.js index 5ca4d5a118..f3e7cff3e1 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/call-2.js +++ b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/call-2.js @@ -1,5 +1,5 @@ function b() { - assert.equals(a, 1); + assert.equal(a, 1); } let a = 1; diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/call-3.js b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/call-3.js similarity index 60% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/call-3.js rename to packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/call-3.js index 0cf8af3c51..e9cc15b450 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/call-3.js +++ b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/call-3.js @@ -1,5 +1,5 @@ function b() { - assert.equals(a, 1); + assert.equal(a, 1); } b(); diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/call.js b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/call.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/call.js rename to packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/call.js diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/defaults.js b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/defaults.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/defaults.js rename to packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/defaults.js diff --git a/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/destructuring.js b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/destructuring.js new file mode 100644 index 0000000000..8d08a379de --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/destructuring.js @@ -0,0 +1,15 @@ +function foo({ + x: { + y: { + z: a = b + } = {}, + w: b = 20 + }, + a: c = 30 +}) { + assert.equal(a, 10); + assert.equal(b, 20); + assert.equal(c, 30); +} + +foo({ x: {} }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/export.js b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/export.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/export.js rename to packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/export.js diff --git a/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/options.json b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/options.json new file mode 100644 index 0000000000..e61cd761b2 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["transform-es2015-block-scoping", "transform-es2015-parameters", "transform-es2015-destructuring", "transform-es2015-modules-commonjs"], + "throws": "is not defined - temporal dead zone" +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/update.js b/packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/update.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/update.js rename to packages/babel-core/test/fixtures/transformation/.es6.block-scoping-fail/update.js diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/class-decorator.js b/packages/babel-core/test/fixtures/transformation/.es7.decorators/class-decorator.js new file mode 100644 index 0000000000..4333b596e3 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/class-decorator.js @@ -0,0 +1,18 @@ +function noop() {} + +function override() { + return "bar"; +} + +@override +class Foo {} + +@noop +class Bar { + constructor() { + this.foo = "bar"; + } +} + +assert.equal(Foo, "bar"); +assert.equal(new Bar().foo, "bar"); diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/getters.js b/packages/babel-core/test/fixtures/transformation/.es7.decorators/getters.js new file mode 100644 index 0000000000..6c613018af --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/getters.js @@ -0,0 +1,23 @@ +class Person { + @reader _first; + @reader last; + + constructor(first, last) { + this._first = first; + this._last = last; + } + + @reader get _fullName() { + return `${this._first} ${this._last}`; + } +} + +let jason = new Person("Jason", "Orendorff"); + +assert.equal(jason.first, "Jason"); +assert.equal(jason.last, "Orendorff"); +assert.equal(jason.fullName, "Jason Orendorff"); + +jason.update("JSON", "Orendorff") +assert.equal(jason.first, "JSON"); +assert.equal(jason.fullName, "JSON Orendorff"); diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/initialised-property-declarations.js b/packages/babel-core/test/fixtures/transformation/.es7.decorators/initialised-property-declarations.js new file mode 100644 index 0000000000..761ba3c538 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/initialised-property-declarations.js @@ -0,0 +1,8 @@ +class Person { + @reader _first = "Andreas"; + @reader _last = "Rossberg"; +} + +let andreas = new Person(); +assert.equal(andreas.first, "Andreas"); +assert.equal(andreas.last, "Rossberg"); diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/initialised-static-properties.js b/packages/babel-core/test/fixtures/transformation/.es7.decorators/initialised-static-properties.js new file mode 100644 index 0000000000..e928cd349c --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/initialised-static-properties.js @@ -0,0 +1,8 @@ +class Person { + @reader static _first = "Brendan"; + @reader static _last = "Eich"; +} + +let brendan = Person; +assert.equal(brendan.first, "Brendan"); +assert.equal(brendan.last, "Eich"); diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/initialized-properties-in-object-literals.js b/packages/babel-core/test/fixtures/transformation/.es7.decorators/initialized-properties-in-object-literals.js new file mode 100644 index 0000000000..e242da8ad2 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/initialized-properties-in-object-literals.js @@ -0,0 +1,7 @@ +let person = { + @reader _first: "Mark", + @reader _last: "Miller" +}; + +assert.equal(person.first, "Mark"); +assert.equal(person.last, "Miller"); diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/methods.js b/packages/babel-core/test/fixtures/transformation/.es7.decorators/methods.js new file mode 100644 index 0000000000..c3d6a66bd7 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/methods.js @@ -0,0 +1,33 @@ +function reader(target, descriptor) { + let { enumerable, configurable, property: { name, get }, hint } = descriptor; + let publicName = extractPublicName(name()); + Object.defineProperty(target, publicName, { + enumerable, configurable, get: function() { return get(this, name); } + }); + return descriptor; +} + +function extractPublicName(name) { + // _first -> first + return name.slice(1); +} + +class Person { + @reader _first; + @reader _last; + + constructor(first, last) { + this._first = first; + this._last = last; + } + + @reader _update(first, last) { + this._first = first; + this._last = last; + } +} + +let alex = new Person("Alex", "Russell"); +assert.equal(alex.first, "Alex"); +alex.update("Alexander", "Russell"); +assert.equal(alex.first, "Alexander"); diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/options.json b/packages/babel-core/test/fixtures/transformation/.es7.decorators/options.json new file mode 100644 index 0000000000..0c91a1a362 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-destructuring", "transform-es2015-block-scoping", "transform-decorators", "transform-es2015-classes", "transform-class-properties"] +} diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/uninitialized-field-declaration.js b/packages/babel-core/test/fixtures/transformation/.es7.decorators/uninitialized-field-declaration.js new file mode 100644 index 0000000000..71c118d267 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/uninitialized-field-declaration.js @@ -0,0 +1,17 @@ +class Person { + @reader _first; + @reader _last; + + constructor(first="Waldemar", last="Horwat") { + this._first = first; + this._last = last; + } +} + +let waldemar = new Person(); +assert.equal(waldemar.first, "Waldemar"); +assert.equal(waldemar.last, "Horwat"); + +let jeff = new Person("Jeff", "Morrison"); +assert.equal(jeff.first, "Jeff"); +assert.equal(jeff.last, "Morrison"); diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/uninitialized-properties-in-object-literals.js b/packages/babel-core/test/fixtures/transformation/.es7.decorators/uninitialized-properties-in-object-literals.js new file mode 100644 index 0000000000..9f577a129f --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/uninitialized-properties-in-object-literals.js @@ -0,0 +1,11 @@ +let person = { + @reader _first, + @reader _last +}; + +assert.equal(person.first, "undefined"); + +Object.assign(person, { _first: "Brian", _last: "Terlson" }); + +assert.equal(person.first, "Brian"); +assert.equal(person.last, "Terlson"); diff --git a/packages/babel-core/test/fixtures/transformation/.es7.decorators/unitialised-static-properties.js b/packages/babel-core/test/fixtures/transformation/.es7.decorators/unitialised-static-properties.js new file mode 100644 index 0000000000..f57d08af44 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/.es7.decorators/unitialised-static-properties.js @@ -0,0 +1,13 @@ +class Person { + @reader static _first; + @reader static _last; +} + +let jonathan = Person; + +assert.equal(jonathan.first, undefined); + +Object.assign(jonathan, { _first: "Jonathan", _last: "Turner" }); + +assert.equal(jonathan.first, "Jonathan"); +assert.equal(jonathan.last, "Turner"); diff --git a/packages/babel-core/test/fixtures/transformation/api/blacklist/actual.js b/packages/babel-core/test/fixtures/transformation/api/blacklist/actual.js deleted file mode 100644 index 8ec84a062e..0000000000 --- a/packages/babel-core/test/fixtures/transformation/api/blacklist/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -class Test { - constructor() { - arr.map(x => x * x); - } -} diff --git a/packages/babel-core/test/fixtures/transformation/api/blacklist/expected.js b/packages/babel-core/test/fixtures/transformation/api/blacklist/expected.js deleted file mode 100644 index 33dda2b11a..0000000000 --- a/packages/babel-core/test/fixtures/transformation/api/blacklist/expected.js +++ /dev/null @@ -1,7 +0,0 @@ -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var Test = function Test() { - _classCallCheck(this, Test); - - arr.map(x => x * x); -}; diff --git a/packages/babel-core/test/fixtures/transformation/api/unknown-module-formatter/options.json b/packages/babel-core/test/fixtures/transformation/api/unknown-module-formatter/options.json deleted file mode 100644 index 834f1d0a2e..0000000000 --- a/packages/babel-core/test/fixtures/transformation/api/unknown-module-formatter/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "modules": "foobar", - "throws": "Unknown module formatter type \"foobar\"" -} diff --git a/packages/babel-core/test/fixtures/transformation/api/whitelist/actual.js b/packages/babel-core/test/fixtures/transformation/api/whitelist/actual.js deleted file mode 100644 index 8ec84a062e..0000000000 --- a/packages/babel-core/test/fixtures/transformation/api/whitelist/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -class Test { - constructor() { - arr.map(x => x * x); - } -} diff --git a/packages/babel-core/test/fixtures/transformation/api/whitelist/expected.js b/packages/babel-core/test/fixtures/transformation/api/whitelist/expected.js deleted file mode 100644 index 6b57623869..0000000000 --- a/packages/babel-core/test/fixtures/transformation/api/whitelist/expected.js +++ /dev/null @@ -1,7 +0,0 @@ -class Test { - constructor() { - arr.map(function (x) { - return x * x; - }); - } -} diff --git a/packages/babel-core/test/fixtures/transformation/async-to-generator/async/expected.js b/packages/babel-core/test/fixtures/transformation/async-to-generator/async/expected.js index e76bebc705..29da0ca451 100644 --- a/packages/babel-core/test/fixtures/transformation/async-to-generator/async/expected.js +++ b/packages/babel-core/test/fixtures/transformation/async-to-generator/async/expected.js @@ -1,13 +1,7 @@ -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); +class Foo { + foo() { + return babelHelpers.asyncToGenerator(function* () { + var wat = await bar(); + })(); } - - babelHelpers.createClass(Foo, [{ - key: "foo", - value: babelHelpers.asyncToGenerator(function* () { - var wat = yield bar(); - }) - }]); - return Foo; -})(); +} diff --git a/packages/babel-core/test/fixtures/transformation/async-to-generator/expression/expected.js b/packages/babel-core/test/fixtures/transformation/async-to-generator/expression/expected.js index 00c2951f21..41da03021d 100644 --- a/packages/babel-core/test/fixtures/transformation/async-to-generator/expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/async-to-generator/expression/expected.js @@ -1,3 +1,5 @@ -var foo = babelHelpers.asyncToGenerator(function* () { - var wat = yield bar(); -}); +var foo = function () { + return babelHelpers.asyncToGenerator(function* () { + var wat = yield bar(); + })(); +}; diff --git a/packages/babel-core/test/fixtures/transformation/async-to-generator/named-expression/expected.js b/packages/babel-core/test/fixtures/transformation/async-to-generator/named-expression/expected.js index 237252e167..0cf977e389 100644 --- a/packages/babel-core/test/fixtures/transformation/async-to-generator/named-expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/async-to-generator/named-expression/expected.js @@ -1,7 +1,7 @@ -var _bar; - -var foo = _bar = babelHelpers.asyncToGenerator(function* () { - console.log(_bar); -}); +var foo = function () { + return babelHelpers.asyncToGenerator(function* bar() { + console.log(bar); + })(); +}; foo(); diff --git a/packages/babel-core/test/fixtures/transformation/async-to-generator/statement/expected.js b/packages/babel-core/test/fixtures/transformation/async-to-generator/statement/expected.js index 00c2951f21..9b407f49d8 100644 --- a/packages/babel-core/test/fixtures/transformation/async-to-generator/statement/expected.js +++ b/packages/babel-core/test/fixtures/transformation/async-to-generator/statement/expected.js @@ -1,3 +1,5 @@ -var foo = babelHelpers.asyncToGenerator(function* () { - var wat = yield bar(); -}); +let foo = function foo() { + return babelHelpers.asyncToGenerator(function* foo() { + var wat = yield bar(); + })(); +}; diff --git a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/class/expected.js b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/class/expected.js index f5706d9c1b..cf00496e19 100644 --- a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/class/expected.js +++ b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/class/expected.js @@ -1,15 +1,8 @@ -var _bluebird = require("bluebird"); - -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); +import { coroutine as _coroutine } from "bluebird"; +class Foo { + foo() { + return _coroutine(function* () { + var wat = await bar(); + })(); } - - babelHelpers.createClass(Foo, [{ - key: "foo", - value: _bluebird.coroutine(function* () { - var wat = yield bar(); - }) - }]); - return Foo; -})(); +} diff --git a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/expression/expected.js b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/expression/expected.js index 9e50f8c487..b0329029bb 100644 --- a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/expression/expected.js @@ -1,5 +1,6 @@ -var _bluebird = require("bluebird"); - -var foo = _bluebird.coroutine(function* () { - var wat = yield bar(); -}); +import { coroutine as _coroutine } from "bluebird"; +var foo = function () { + return _coroutine(function* () { + var wat = yield bar(); + })(); +}; diff --git a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/named-expression/expected.js b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/named-expression/expected.js index 23e5a21ae6..e7bc57ac50 100644 --- a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/named-expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/named-expression/expected.js @@ -1,9 +1,8 @@ -var _bluebird = require("bluebird"); - -var _bar; - -var foo = _bar = _bluebird.coroutine(function* () { - console.log(_bar); -}); +import { coroutine as _coroutine } from "bluebird"; +var foo = function () { + return _coroutine(function* bar() { + console.log(bar); + })(); +}; foo(); diff --git a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/options.json b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/options.json index a7d7654c3a..e6402afd2d 100644 --- a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/options.json +++ b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-bluebird-coroutines"] + "plugins": ["external-helpers", ["transform-async-to-module-method", { "module": "bluebird", "method": "coroutine" }]] } diff --git a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/statement/expected.js b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/statement/expected.js index 9e50f8c487..b74500ba7f 100644 --- a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/statement/expected.js +++ b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/statement/expected.js @@ -1,5 +1,7 @@ -var _bluebird = require("bluebird"); +import { coroutine as _coroutine } from "bluebird"; -var foo = _bluebird.coroutine(function* () { - var wat = yield bar(); -}); +let foo = function foo() { + return _coroutine(function* foo() { + var wat = yield bar(); + })(); +}; diff --git a/packages/babel-core/test/fixtures/transformation/errors/constants/actual.js b/packages/babel-core/test/fixtures/transformation/errors/constants/actual.js deleted file mode 100644 index 198325ab9a..0000000000 --- a/packages/babel-core/test/fixtures/transformation/errors/constants/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -const MULTIPLIER = 5; -MULTIPLIER = 10; diff --git a/packages/babel-core/test/fixtures/transformation/errors/constants/options.json b/packages/babel-core/test/fixtures/transformation/errors/constants/options.json deleted file mode 100644 index 23340cd45d..0000000000 --- a/packages/babel-core/test/fixtures/transformation/errors/constants/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Line 2: \"MULTIPLIER\" is read-only" -} diff --git a/packages/babel-core/test/fixtures/transformation/es3/member-expression-literals/options.json b/packages/babel-core/test/fixtures/transformation/es3/member-expression-literals/options.json new file mode 100644 index 0000000000..668132c997 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es3/member-expression-literals/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es3-member-expression-literals"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es3/property-literals/options.json b/packages/babel-core/test/fixtures/transformation/es3/property-literals/options.json new file mode 100644 index 0000000000..1d5027ef40 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es3/property-literals/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es3-property-literals"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/getter-and-setter/expected.js b/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/getter-and-setter/expected.js index 4d16443ad9..2c4dc83b97 100644 --- a/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/getter-and-setter/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/getter-and-setter/expected.js @@ -1,9 +1,9 @@ var obj = Object.defineProperties({}, { foo: { - get: function get() { + get: function () { return 5 + 5; }, - set: function set(value) { + set: function (value) { this._foo = value; }, configurable: true, diff --git a/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/getter/expected.js b/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/getter/expected.js index f34ed12c64..4c602f131b 100644 --- a/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/getter/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/getter/expected.js @@ -1,6 +1,6 @@ var obj = Object.defineProperties({}, { foo: { - get: function get() { + get: function () { return 5 + 5; }, configurable: true, diff --git a/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/options.json b/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/options.json new file mode 100644 index 0000000000..608fb1f012 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es5-property-mutators"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/setter/expected.js b/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/setter/expected.js index 988cb966e9..aa5165f2a3 100644 --- a/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/setter/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es5.properties.mutators/setter/expected.js @@ -1,6 +1,6 @@ var obj = Object.defineProperties({}, { foo: { - set: function set(value) { + set: function (value) { this._foo = value; }, configurable: true, diff --git a/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/default-parameters/expected.js b/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/default-parameters/expected.js index 8a28c607b8..7b03aac22d 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/default-parameters/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/default-parameters/expected.js @@ -1,5 +1,5 @@ -var some = function some() { - var count = arguments.length <= 0 || arguments[0] === undefined ? "30" : arguments[0]; +var some = function () { + let count = arguments.length <= 0 || arguments[0] === undefined ? "30" : arguments[0]; console.log("count", count); }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/destructuring-parameters/options.json b/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/destructuring-parameters/options.json index ad1a1598cb..9e979cda64 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/destructuring-parameters/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/destructuring-parameters/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-es2015-destructuring", "transform-es2015-arrow-functions"] + "plugins": ["transform-es2015-destructuring", "transform-es2015-parameters", "transform-es2015-arrow-functions"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/options.json b/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/options.json index fc3d742263..2fd23e5bad 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-es2015-arrow-functions"] + "plugins": ["transform-es2015-parameters", "transform-es2015-arrow-functions"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/spec/options.json b/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/spec/options.json index 97b5b05339..1653d169a3 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/spec/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.arrow-functions/spec/options.json @@ -1,4 +1,3 @@ { - "plugins": ["external-helpers"], - "optional": ["es6.spec.arrowFunctions"] + "plugins": ["external-helpers", ["transform-es2015-arrow-functions", { "spec": true }]] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.block-scoping-exec/options.json b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-exec/options.json new file mode 100644 index 0000000000..510d03805a --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-exec/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-for-of", "transform-es2015-arrow-functions", "transform-es2015-destructuring", "transform-es2015-block-scoping"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/assignment.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/assignment.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/assignment.js rename to packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/assignment.js diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/call.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/call.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/call.js rename to packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/call.js diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/defaults.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/defaults.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/defaults.js rename to packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/defaults.js diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/destructuring.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/destructuring.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/destructuring.js rename to packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/destructuring.js diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/export.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/export.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/export.js rename to packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/export.js diff --git a/packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/options.json b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/options.json new file mode 100644 index 0000000000..599c8d9a01 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-block-scoping", "transform-es2015-parameters", "transform-es2015-destructuring", "transform-es2015-modules-commonjs"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/update.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/update.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/update.js rename to packages/babel-core/test/fixtures/transformation/es6.block-scoping-pass/update.js diff --git a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/assignment-patterns/expected.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/assignment-patterns/expected.js index 0d2a6c971b..b497a041e4 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/assignment-patterns/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/assignment-patterns/expected.js @@ -1,12 +1,8 @@ -var foo = "foo"; +const foo = "foo"; function foobar() { - var _arr = [1, 2, 3]; - - for (var _i = 0; _i < _arr.length; _i++) { - var item = _arr[_i]; + for (var item of [1, 2, 3]) { var _foo = "bar"; - bar = 1; - _foo = 2; + [bar, _foo] = [1, 2]; } } diff --git a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/exec-collision-array-comprehension/exec.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/exec-collision-array-comprehension/exec.js deleted file mode 100644 index 0ce1188288..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/exec-collision-array-comprehension/exec.js +++ /dev/null @@ -1,2 +0,0 @@ -var foo = []; -assert.deepEqual([for (foo of [1, 2, 3]) foo], [1, 2, 3]); diff --git a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/hoisting/expected.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/hoisting/expected.js index 542c6eeaee..633c9ab5ae 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/hoisting/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/hoisting/expected.js @@ -1,32 +1,31 @@ +var _loop = function (i) { + x = 5; + ({ f } = { f: 2 }); + + fns.push(function () { + return i * x; + }); +}; + var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { - var _loop = function () { - var i = _step.value; - x = 5; - var _f = { f: 2 }; - f = _f.f; - - fns.push(function () { - return i * x; - }); - }; - for (var _iterator = nums[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var i = _step.value; var x; var f; - _loop(); + _loop(i); } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/hoisting/options.json b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/hoisting/options.json new file mode 100644 index 0000000000..7f7165f7a3 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/hoisting/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-block-scoping", "syntax-jsx", "transform-react-jsx", "transform-es2015-block-scoped-functions", "transform-es2015-for-of"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/issue-1051/expected.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/issue-1051/expected.js index 1b059c02c0..e9e5798e9b 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/issue-1051/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/issue-1051/expected.js @@ -3,10 +3,8 @@ foo.func1 = function () { for (;;) { if (cond2) { var _ret = (function () { - var func2 = function func2() {}; - - var func3 = function func3() {}; - + function func2() {} + function func3() {} func4(function () { func2(); }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/issue-2174/expected.js b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/issue-2174/expected.js index 8fce45b985..1dce9c4c17 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/issue-2174/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/issue-2174/expected.js @@ -2,12 +2,10 @@ if (true) { var x; (function () { - var foo = function foo() {}; - - var bar = function bar() { + function foo() {} + function bar() { return foo; - }; - + } for (x in {}) {} })(); } diff --git a/packages/babel-core/test/fixtures/transformation/es6.block-scoping/options.json b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/options.json new file mode 100644 index 0000000000..0a6b7013b3 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.block-scoping/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-block-scoping", "syntax-jsx", "transform-react-jsx", "transform-es2015-block-scoped-functions", "transform-es2015-arrow-functions"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-exec/options.json b/packages/babel-core/test/fixtures/transformation/es6.classes-exec/options.json new file mode 100644 index 0000000000..e5e9ad8a9a --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-exec/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-classes", "transform-es2015-block-scoping"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-exec/super-return.js b/packages/babel-core/test/fixtures/transformation/es6.classes-exec/super-return.js new file mode 100644 index 0000000000..9531b4bd65 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-exec/super-return.js @@ -0,0 +1,14 @@ +class Foo { + constructor() { + return { i: 1 }; + } +} + +class Bar extends Foo { + constructor() { + assert.equal(super().i, 1); + assert.equal(this.i, 1); + } +} + +new Bar; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-class/actual.js b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-class/actual.js index 154d85730b..83f054a6e9 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-class/actual.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-class/actual.js @@ -10,16 +10,4 @@ class Test extends Foo { super.test(...arguments); super.test("test", ...arguments); } - - test() { - super(); - super(...arguments); - super("test", ...arguments); - } - - static foo() { - super(); - super(...arguments); - super("test", ...arguments); - } } diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-class/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-class/expected.js index 54df06e7f4..dc81b57bd6 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-class/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-class/expected.js @@ -6,32 +6,20 @@ var Test = (function (_Foo) { babelHelpers.classCallCheck(this, Test); - woops["super"].test(); - _Foo.call(this); - _Foo.prototype.test.call(this); + woops.super.test(); - _Foo.apply(this, arguments); - _Foo.call.apply(_Foo, [this, "test"].concat(babelHelpers.slice.call(arguments))); + var _this = babelHelpers.possibleConstructorReturn(this, _Foo.call(this)); - (_Foo$prototype$test = _Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(babelHelpers.slice.call(arguments))); - (_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(babelHelpers.slice.call(arguments))); + _Foo.prototype.test.call(_this); + + var _this = babelHelpers.possibleConstructorReturn(this, _Foo.apply(this, arguments)); + + var _this = babelHelpers.possibleConstructorReturn(this, _Foo.call.apply(_Foo, [this, "test"].concat(Array.prototype.slice.call(arguments)))); + + (_Foo$prototype$test = _Foo.prototype.test).call.apply(_Foo$prototype$test, [_this].concat(Array.prototype.slice.call(arguments))); + (_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [_this, "test"].concat(Array.prototype.slice.call(arguments))); + return _this; } - Test.prototype.test = function test() { - var _Foo$prototype$test3, _Foo$prototype$test4; - - _Foo.prototype.test.call(this); - (_Foo$prototype$test3 = _Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(babelHelpers.slice.call(arguments))); - (_Foo$prototype$test4 = _Foo.prototype.test).call.apply(_Foo$prototype$test4, [this, "test"].concat(babelHelpers.slice.call(arguments))); - }; - - Test.foo = function foo() { - var _Foo$foo, _Foo$foo2; - - _Foo.foo.call(this); - (_Foo$foo = _Foo.foo).call.apply(_Foo$foo, [this].concat(babelHelpers.slice.call(arguments))); - (_Foo$foo2 = _Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(babelHelpers.slice.call(arguments))); - }; - return Test; })(Foo); diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-properties/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-properties/expected.js index 1339e897c0..1c9524d16d 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-properties/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/accessing-super-properties/expected.js @@ -4,9 +4,11 @@ var Test = (function (_Foo) { function Test() { babelHelpers.classCallCheck(this, Test); - _Foo.call(this); + var _this = babelHelpers.possibleConstructorReturn(this, _Foo.call(this)); + _Foo.prototype.test; _Foo.prototype.test.whatever; + return _this; } return Test; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/calling-super-properties/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/calling-super-properties/expected.js index ad544c99f8..322e2d1a0c 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/calling-super-properties/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/calling-super-properties/expected.js @@ -4,9 +4,11 @@ var Test = (function (_Foo) { function Test() { babelHelpers.classCallCheck(this, Test); - _Foo.call(this); + var _this = babelHelpers.possibleConstructorReturn(this, _Foo.call(this)); + _Foo.prototype.test.whatever(); - _Foo.prototype.test.call(this); + _Foo.prototype.test.call(_this); + return _this; } Test.test = function test() { diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/constructor-order/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/constructor-order/expected.js index 1ef27229e6..7732e9c42a 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/constructor-order/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/constructor-order/expected.js @@ -6,10 +6,11 @@ var x = (function () { }; function x() { + babelHelpers.classCallCheck(this, x); + 4; 5; 6; - babelHelpers.classCallCheck(this, x); } return x; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/options.json b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/options.json index 86099c4fdc..5ba1a293bd 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers", ["transform-es2015-classes", { "loose": true }]] + "plugins": ["external-helpers", "transform-es2015-function-name", ["transform-es2015-classes", { "loose": true }], "transform-es2015-spread", "transform-es2015-block-scoping"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/super-class-id-member-expression/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/super-class-id-member-expression/expected.js index a9d6dd859b..ffe79cc6c4 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/super-class-id-member-expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/super-class-id-member-expression/expected.js @@ -3,20 +3,18 @@ var BaseController = (function (_Chaplin$Controller) { function BaseController() { babelHelpers.classCallCheck(this, BaseController); - - _Chaplin$Controller.apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, _Chaplin$Controller.apply(this, arguments)); } return BaseController; })(Chaplin.Controller); -var BaseController2 = (function (_Chaplin$Controller$Another) { - babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); +var BaseController2 = (function (_Chaplin$Controller$A) { + babelHelpers.inherits(BaseController2, _Chaplin$Controller$A); function BaseController2() { babelHelpers.classCallCheck(this, BaseController2); - - _Chaplin$Controller$Another.apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, _Chaplin$Controller$A.apply(this, arguments)); } return BaseController2; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/super-class/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/super-class/expected.js index 66f9a7c963..9a50791c8b 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes-loose/super-class/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes-loose/super-class/expected.js @@ -3,8 +3,7 @@ var Test = (function (_Foo) { function Test() { babelHelpers.classCallCheck(this, Test); - - _Foo.apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, _Foo.apply(this, arguments)); } return Test; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/accessing-super-class/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/accessing-super-class/expected.js index 1d619cb99c..f03982fc1e 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/accessing-super-class/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/accessing-super-class/expected.js @@ -1,39 +1,45 @@ +var _Object$getPrototypeO; + var Test = (function (_Foo) { babelHelpers.inherits(Test, _Foo); function Test() { - var _babelHelpers$get, _babelHelpers$get2; + var _babelHelpers$get; babelHelpers.classCallCheck(this, Test); - woops["super"].test(); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); + woops.super.test(); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments); - (_babelHelpers$get = babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_babelHelpers$get, [this, "test"].concat(babelHelpers.slice.call(arguments))); + var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Test).call(this)); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); - (_babelHelpers$get2 = babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_babelHelpers$get2, [this, "test"].concat(babelHelpers.slice.call(arguments))); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this).call(_this); + + var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Test).apply(this, arguments)); + + var _this = babelHelpers.possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(Test)).call.apply(_Object$getPrototypeO, [this, "test"].concat(Array.prototype.slice.call(arguments)))); + + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this).apply(_this, arguments); + (_babelHelpers$get = babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this)).call.apply(_babelHelpers$get, [_this, "test"].concat(Array.prototype.slice.call(arguments))); + return _this; } babelHelpers.createClass(Test, [{ key: "test", value: function test() { - var _babelHelpers$get3; + var _babelHelpers$get2; babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).apply(this, arguments); - (_babelHelpers$get3 = babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_babelHelpers$get3, [this, "test"].concat(babelHelpers.slice.call(arguments))); + (_babelHelpers$get2 = babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_babelHelpers$get2, [this, "test"].concat(Array.prototype.slice.call(arguments))); } }], [{ key: "foo", value: function foo() { - var _babelHelpers$get4; + var _babelHelpers$get3; babelHelpers.get(Object.getPrototypeOf(Test), "foo", this).call(this); babelHelpers.get(Object.getPrototypeOf(Test), "foo", this).apply(this, arguments); - (_babelHelpers$get4 = babelHelpers.get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_babelHelpers$get4, [this, "test"].concat(babelHelpers.slice.call(arguments))); + (_babelHelpers$get3 = babelHelpers.get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_babelHelpers$get3, [this, "test"].concat(Array.prototype.slice.call(arguments))); } }]); return Test; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/accessing-super-properties/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/accessing-super-properties/expected.js index fe8a83393e..c30864e083 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/accessing-super-properties/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/accessing-super-properties/expected.js @@ -4,9 +4,11 @@ var Test = (function (_Foo) { function Test() { babelHelpers.classCallCheck(this, Test); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).whatever; + var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Test).call(this)); + + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this).whatever; + return _this; } return Test; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/calling-super-properties/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/calling-super-properties/expected.js index 4e1254cc81..cce857b8e6 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/calling-super-properties/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/calling-super-properties/expected.js @@ -4,9 +4,11 @@ var Test = (function (_Foo) { function Test() { babelHelpers.classCallCheck(this, Test); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).whatever(); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).call(this); + var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Test).call(this)); + + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this).whatever(); + babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this).call(_this); + return _this; } babelHelpers.createClass(Test, null, [{ diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/constructor-binding-collision/actual.js b/packages/babel-core/test/fixtures/transformation/es6.classes/constructor-binding-collision/actual.js index 522f46589d..abc706f3e4 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/constructor-binding-collision/actual.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/constructor-binding-collision/actual.js @@ -4,4 +4,4 @@ class Example { } } -let t = new Example(); +var t = new Example(); diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/constructor/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/constructor/expected.js index 63785beee3..8f1b418649 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/constructor/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/constructor/expected.js @@ -10,8 +10,10 @@ var Foo = (function (_Bar) { function Foo() { babelHelpers.classCallCheck(this, Foo); - babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this); - this.state = "test"; + var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this)); + + _this.state = "test"; + return _this; } return Foo; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/delay-arrow-function-for-bare-super-derived/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/delay-arrow-function-for-bare-super-derived/expected.js index 045d6d18cf..e65c69e209 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/delay-arrow-function-for-bare-super-derived/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/delay-arrow-function-for-bare-super-derived/expected.js @@ -2,13 +2,12 @@ var Foo = (function (_Bar) { babelHelpers.inherits(Foo, _Bar); function Foo() { + var _this; + babelHelpers.classCallCheck(this, Foo); - - babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this, function () { + return _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this, () => { _this.test; - }); - - var _this = this; + })); } return Foo; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/derived-constructor-must-call-super/options.json b/packages/babel-core/test/fixtures/transformation/es6.classes/derived-constructor-must-call-super/options.json index c262ea7e16..2b7d826bab 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/derived-constructor-must-call-super/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/derived-constructor-must-call-super/options.json @@ -1,3 +1,3 @@ { - "throws": "Derived constructor must call super()" + "throws": "missing super() call in constructor" } diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/name-method-collision/options.json b/packages/babel-core/test/fixtures/transformation/es6.classes/name-method-collision/options.json new file mode 100644 index 0000000000..f1f6226b60 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/name-method-collision/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-classes", "transform-es2015-spread", "transform-es2015-block-scoping", "transform-es2015-modules-commonjs"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/options.json b/packages/babel-core/test/fixtures/transformation/es6.classes/options.json index 2ba8b2dbd5..ae024a20b2 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers", "transform-es2015-classes"] + "plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-classes", "transform-es2015-spread", "transform-es2015-block-scoping"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/preserves-directives/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/preserves-directives/expected.js index 8e3310d8f8..df1be86af7 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/preserves-directives/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/preserves-directives/expected.js @@ -1,5 +1,6 @@ var MyCtrl = function MyCtrl(a) { "any directive prologue"; + babelHelpers.classCallCheck(this, MyCtrl); foo; }; @@ -7,12 +8,14 @@ var MyCtrl = function MyCtrl(a) { var MyCtrl2 = function MyCtrl2(a) { "a"; "b"; + babelHelpers.classCallCheck(this, MyCtrl2); foo; }; var MyCtrl3 = function MyCtrl3(a) { "a"; + babelHelpers.classCallCheck(this, MyCtrl3); foo; "b"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/returning-from-derived-constructor/exec.js b/packages/babel-core/test/fixtures/transformation/es6.classes/returning-from-derived-constructor/exec.js new file mode 100644 index 0000000000..a37d09054b --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/returning-from-derived-constructor/exec.js @@ -0,0 +1,26 @@ +class Foo { + constructor() { + return { x: 1 }; + } +} + +assert.equal(new Foo().x, 1); + +class Bar extends Foo { + constructor() { + super(); + return; + } +} + +assert.equal(new Bar().x, 1); + +class Bar2 extends Foo { + constructor() { + super(); + assert.equal(this.x, 1); + return { x: 2 }; + } +} + +assert.equal(new Bar2().x, 2); diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/super-call-only-allowed-in-derived-constructor/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/super-call-only-allowed-in-derived-constructor/expected.js index 6438026c22..898e1ce1c7 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/super-call-only-allowed-in-derived-constructor/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/super-call-only-allowed-in-derived-constructor/expected.js @@ -1,9 +1,5 @@ -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); +var Foo = function Foo() { + babelHelpers.classCallCheck(this, Foo); - babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this); - } - - return Foo; -})(); + Object.getPrototypeOf(Foo).call(this); +}; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/super-call-only-allowed-in-derived-constructor/options.json b/packages/babel-core/test/fixtures/transformation/es6.classes/super-call-only-allowed-in-derived-constructor/options.json index 272d58ce9f..49ce838f4b 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/super-call-only-allowed-in-derived-constructor/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/super-call-only-allowed-in-derived-constructor/options.json @@ -1,3 +1,3 @@ { - "throws": "super call is only allowed in derived constructor" + "throws": "super() is only allowed in a derived constructor" } diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/super-class-anonymous/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/super-class-anonymous/expected.js index 64a67675d5..541efbdde1 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/super-class-anonymous/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/super-class-anonymous/expected.js @@ -3,7 +3,7 @@ var TestEmpty = (function (_ref) { function TestEmpty() { babelHelpers.classCallCheck(this, TestEmpty); - babelHelpers.get(Object.getPrototypeOf(TestEmpty.prototype), "constructor", this).apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(TestEmpty).apply(this, arguments)); } return TestEmpty; @@ -20,7 +20,7 @@ var TestConstructorOnly = (function (_ref2) { function TestConstructorOnly() { babelHelpers.classCallCheck(this, TestConstructorOnly); - babelHelpers.get(Object.getPrototypeOf(TestConstructorOnly.prototype), "constructor", this).apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(TestConstructorOnly).apply(this, arguments)); } return TestConstructorOnly; @@ -37,7 +37,7 @@ var TestMethodOnly = (function (_ref3) { function TestMethodOnly() { babelHelpers.classCallCheck(this, TestMethodOnly); - babelHelpers.get(Object.getPrototypeOf(TestMethodOnly.prototype), "constructor", this).apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(TestMethodOnly).apply(this, arguments)); } return TestMethodOnly; @@ -58,7 +58,7 @@ var TestConstructorAndMethod = (function (_ref4) { function TestConstructorAndMethod() { babelHelpers.classCallCheck(this, TestConstructorAndMethod); - babelHelpers.get(Object.getPrototypeOf(TestConstructorAndMethod.prototype), "constructor", this).apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(TestConstructorAndMethod).apply(this, arguments)); } return TestConstructorAndMethod; @@ -79,7 +79,7 @@ var TestMultipleMethods = (function (_ref5) { function TestMultipleMethods() { babelHelpers.classCallCheck(this, TestMultipleMethods); - babelHelpers.get(Object.getPrototypeOf(TestMultipleMethods.prototype), "constructor", this).apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(TestMultipleMethods).apply(this, arguments)); } return TestMultipleMethods; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/super-class-id-member-expression/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/super-class-id-member-expression/expected.js index 04c8921eba..abeca347e0 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/super-class-id-member-expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/super-class-id-member-expression/expected.js @@ -3,18 +3,18 @@ var BaseController = (function (_Chaplin$Controller) { function BaseController() { babelHelpers.classCallCheck(this, BaseController); - babelHelpers.get(Object.getPrototypeOf(BaseController.prototype), "constructor", this).apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(BaseController).apply(this, arguments)); } return BaseController; })(Chaplin.Controller); -var BaseController2 = (function (_Chaplin$Controller$Another) { - babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another); +var BaseController2 = (function (_Chaplin$Controller$A) { + babelHelpers.inherits(BaseController2, _Chaplin$Controller$A); function BaseController2() { babelHelpers.classCallCheck(this, BaseController2); - babelHelpers.get(Object.getPrototypeOf(BaseController2.prototype), "constructor", this).apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(BaseController2).apply(this, arguments)); } return BaseController2; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/super-class/expected.js b/packages/babel-core/test/fixtures/transformation/es6.classes/super-class/expected.js index 67c217a0ea..10cc6dd095 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/super-class/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/super-class/expected.js @@ -3,7 +3,7 @@ var Test = (function (_Foo) { function Test() { babelHelpers.classCallCheck(this, Test); - babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Test).apply(this, arguments)); } return Test; diff --git a/packages/babel-core/test/fixtures/transformation/es6.classes/super-illegal-non-constructor-call/options.json b/packages/babel-core/test/fixtures/transformation/es6.classes/super-illegal-non-constructor-call/options.json index 38d176ffd0..f63d64488d 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.classes/super-illegal-non-constructor-call/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.classes/super-illegal-non-constructor-call/options.json @@ -1,3 +1,3 @@ { - "throws": "Direct super call is illegal in non-constructor" + "throws": "super() outside of class constructor" } diff --git a/packages/babel-core/test/fixtures/transformation/es6.constants/options.json b/packages/babel-core/test/fixtures/transformation/es6.constants/options.json new file mode 100644 index 0000000000..b4063f1b64 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.constants/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-constants", "transform-es2015-block-scoping", "transform-es2015-destructuring"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/actual.js b/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/actual.js new file mode 100644 index 0000000000..deb5faf388 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/actual.js @@ -0,0 +1,17 @@ +var f0 = function (a, b = a, c = b) { + return [a, b, c]; +}; + +assert.deepEqual(f0(1), [1, 1, 1]); + +var f1 = function ({a}, b = a, c = b) { + return [a, b, c]; +}; + +assert.deepEqual(f1({a: 1}), [1, 1, 1]); + +var f2 = function ({a}, b = a, c = a) { + return [a, b, c]; +}; + +assert.deepEqual(f2({a: 1}), [1, 1, 1]); diff --git a/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/exec.js b/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/exec.js index 505531d7f3..deb5faf388 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/exec.js +++ b/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/exec.js @@ -1,17 +1,17 @@ -const f0 = function (a, b = a, c = b) { +var f0 = function (a, b = a, c = b) { return [a, b, c]; -} +}; assert.deepEqual(f0(1), [1, 1, 1]); -const f1 = function ({a}, b = a, c = b) { +var f1 = function ({a}, b = a, c = b) { return [a, b, c]; -} +}; assert.deepEqual(f1({a: 1}), [1, 1, 1]); -const f2 = function ({a}, b = a, c = a) { +var f2 = function ({a}, b = a, c = a) { return [a, b, c]; -} +}; assert.deepEqual(f2({a: 1}), [1, 1, 1]); diff --git a/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/expected.js b/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/expected.js new file mode 100644 index 0000000000..676f9c51d5 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.destructuring/default-precedence/expected.js @@ -0,0 +1,28 @@ +var f0 = function (a) { + var b = arguments.length <= 1 || arguments[1] === undefined ? a : arguments[1]; + var c = arguments.length <= 2 || arguments[2] === undefined ? b : arguments[2]; + + return [a, b, c]; +}; + +assert.deepEqual(f0(1), [1, 1, 1]); + +var f1 = function (_ref) { + var a = _ref.a; + var b = arguments.length <= 1 || arguments[1] === undefined ? a : arguments[1]; + var c = arguments.length <= 2 || arguments[2] === undefined ? b : arguments[2]; + + return [a, b, c]; +}; + +assert.deepEqual(f1({ a: 1 }), [1, 1, 1]); + +var f2 = function (_ref2) { + var a = _ref2.a; + var b = arguments.length <= 1 || arguments[1] === undefined ? a : arguments[1]; + var c = arguments.length <= 2 || arguments[2] === undefined ? a : arguments[2]; + + return [a, b, c]; +}; + +assert.deepEqual(f2({ a: 1 }), [1, 1, 1]); diff --git a/packages/babel-core/test/fixtures/transformation/es6.destructuring/empty/expected.js b/packages/babel-core/test/fixtures/transformation/es6.destructuring/empty/expected.js index a650dabc34..f075fa1000 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.destructuring/empty/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.destructuring/empty/expected.js @@ -1,11 +1,11 @@ var _ref = ["foo", "hello", [", ", "junk"], ["world"]]; var a = _ref[1]; -var _ref$2 = babelHelpers.slicedToArray(_ref[2], 1); +var _ref$ = babelHelpers.slicedToArray(_ref[2], 1); -var b = _ref$2[0]; +var b = _ref$[0]; -var _ref$3 = babelHelpers.slicedToArray(_ref[3], 1); +var _ref$2 = babelHelpers.slicedToArray(_ref[3], 1); -var c = _ref$3[0]; +var c = _ref$2[0]; var d = _ref[4]; diff --git a/packages/babel-core/test/fixtures/transformation/es6.destructuring/for-of/expected.js b/packages/babel-core/test/fixtures/transformation/es6.destructuring/for-of/expected.js index 8b8d1b7bf2..45ddc2fc6a 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.destructuring/for-of/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.destructuring/for-of/expected.js @@ -1,26 +1,7 @@ -var _iteratorNormalCompletion = true; -var _didIteratorError = false; -var _iteratorError = undefined; +for (var _ref of test.expectation.registers) { + var _ref2 = babelHelpers.slicedToArray(_ref, 3); -try { - for (var _iterator = test.expectation.registers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var _step$value = babelHelpers.slicedToArray(_step.value, 3); - - var name = _step$value[0]; - var before = _step$value[1]; - var after = _step$value[2]; - } -} catch (err) { - _didIteratorError = true; - _iteratorError = err; -} finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } + var name = _ref2[0]; + var before = _ref2[1]; + var after = _ref2[2]; } diff --git a/packages/babel-core/test/fixtures/transformation/es6.destructuring/options.json b/packages/babel-core/test/fixtures/transformation/es6.destructuring/options.json index 835538ee2c..a0353afbef 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.destructuring/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.destructuring/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers", "transform-es2015-destructuring"] + "plugins": ["external-helpers", "transform-es2015-destructuring", "transform-es2015-spread", "transform-es2015-parameters", "transform-es2015-block-scoping", "transform-object-rest-spread"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.destructuring/parameters/expected.js b/packages/babel-core/test/fixtures/transformation/es6.destructuring/parameters/expected.js index 6f62d8a1fb..bfd42de2b8 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.destructuring/parameters/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.destructuring/parameters/expected.js @@ -19,17 +19,17 @@ function unpackObject(_ref2) { console.log(unpackObject({ title: "title", author: "author" })); var unpackArray = function (_ref3, _ref4) { - var _ref32 = babelHelpers.slicedToArray(_ref3, 3); + var _ref6 = babelHelpers.slicedToArray(_ref3, 3); - var a = _ref32[0]; - var b = _ref32[1]; - var c = _ref32[2]; + var a = _ref6[0]; + var b = _ref6[1]; + var c = _ref6[2]; - var _ref42 = babelHelpers.slicedToArray(_ref4, 3); + var _ref5 = babelHelpers.slicedToArray(_ref4, 3); - var x = _ref42[0]; - var y = _ref42[1]; - var z = _ref42[2]; + var x = _ref5[0]; + var y = _ref5[1]; + var z = _ref5[2]; return a + b + c; }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of-loose/let/expected.js b/packages/babel-core/test/fixtures/transformation/es6.for-of-loose/let/expected.js index 7565d63def..097ced3ac7 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.for-of-loose/let/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of-loose/let/expected.js @@ -10,5 +10,5 @@ for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator _ref = _i.value; } - var i = _ref; + let i = _ref; } diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of-loose/options.json b/packages/babel-core/test/fixtures/transformation/es6.for-of-loose/options.json index 9a6e850bce..8abc0aa64a 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.for-of-loose/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of-loose/options.json @@ -1,3 +1,3 @@ { - "loose": ["es6.forOf"] + "plugins": [["transform-es2015-for-of", { "loose": true }]] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of/identifier/expected.js b/packages/babel-core/test/fixtures/transformation/es6.for-of/identifier/expected.js index a9802edce0..a3d54af48f 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.for-of/identifier/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of/identifier/expected.js @@ -11,8 +11,8 @@ try { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of/ignore-cases/expected.js b/packages/babel-core/test/fixtures/transformation/es6.for-of/ignore-cases/expected.js index 044583f69f..dcd4320b80 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.for-of/ignore-cases/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of/ignore-cases/expected.js @@ -16,8 +16,8 @@ try { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of/let/expected.js b/packages/babel-core/test/fixtures/transformation/es6.for-of/let/expected.js index 6c6b96ae93..fb997e23ad 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.for-of/let/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of/let/expected.js @@ -4,15 +4,15 @@ var _iteratorError = undefined; try { for (var _iterator = arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var i = _step.value; + let i = _step.value; } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of/member-expression/expected.js b/packages/babel-core/test/fixtures/transformation/es6.for-of/member-expression/expected.js index ca88fbff1d..af5bbbb407 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.for-of/member-expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of/member-expression/expected.js @@ -11,8 +11,8 @@ try { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of/multiple/expected.js b/packages/babel-core/test/fixtures/transformation/es6.for-of/multiple/expected.js index 507af58ad0..a3568407fe 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.for-of/multiple/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of/multiple/expected.js @@ -11,8 +11,8 @@ try { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { @@ -34,8 +34,8 @@ try { _iteratorError2 = err; } finally { try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); } } finally { if (_didIteratorError2) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of/nested-label-for-of/expected.js b/packages/babel-core/test/fixtures/transformation/es6.for-of/nested-label-for-of/expected.js index 544c05ec30..7388ecdf69 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.for-of/nested-label-for-of/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of/nested-label-for-of/expected.js @@ -4,14 +4,14 @@ var _iteratorError = undefined; try { b: for (var _iterator = d()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var c = _step.value; + let c = _step.value; var _iteratorNormalCompletion2 = true; var _didIteratorError2 = false; var _iteratorError2 = undefined; try { for (var _iterator2 = f()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var e = _step2.value; + let e = _step2.value; continue b; } @@ -20,8 +20,8 @@ try { _iteratorError2 = err; } finally { try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); } } finally { if (_didIteratorError2) { @@ -35,8 +35,8 @@ try { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of/options.json b/packages/babel-core/test/fixtures/transformation/es6.for-of/options.json new file mode 100644 index 0000000000..dd11655f55 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-for-of"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.for-of/var/expected.js b/packages/babel-core/test/fixtures/transformation/es6.for-of/var/expected.js index 6c6b96ae93..70fa6471db 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.for-of/var/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.for-of/var/expected.js @@ -11,8 +11,8 @@ try { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/export-specifier-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/export-specifier-default/expected.js index d9e2ab6562..de3df365d6 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/export-specifier-default/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/export-specifier-default/expected.js @@ -1,4 +1,7 @@ -define(["exports", "module"], function (exports, module) { - var a = 1; - module.exports = a; +define(["exports"], function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); + var a = 1; + exports.default = a; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-default/expected.js index 060d2664cb..4ca1761354 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-default/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-default/expected.js @@ -1,28 +1,25 @@ -define(["exports", "module"], function (exports, module) { - module.exports = foo; - module.exports = 42; - module.exports = {}; - module.exports = []; - module.exports = foo; +define(["exports"], function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); - module.exports = function () {}; + exports.default = function () {}; - var _default = function _default() { - babelHelpers.classCallCheck(this, _default); - }; - - module.exports = _default; + exports.default = foo; + exports.default = 42; + exports.default = {}; + exports.default = []; + exports.default = foo; + exports.default = class {}; function foo() {} - var Foo = function Foo() { - babelHelpers.classCallCheck(this, Foo); - }; + class Foo {} - module.exports = Foo; - module.exports = foo; + exports.default = Foo; + exports.default = foo; - module.exports = (function () { + exports.default = (function () { return "foo"; })(); }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-from/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-from/expected.js index 8ea356b867..df024b3edc 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-from/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-from/expected.js @@ -1,47 +1,57 @@ define(["exports", "foo"], function (exports, _foo) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); - babelHelpers.defaults(exports, babelHelpers.interopExportWildcard(_foo, babelHelpers.defaults)); + + for (let _key in _foo) { + if (_key === "default") continue; + Object.defineProperty(exports, _key, { + enumerable: true, + get: function () { + return _foo[_key]; + } + }); + } + Object.defineProperty(exports, "foo", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "foo", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "bar", { enumerable: true, - get: function get() { + get: function () { return _foo.bar; } }); Object.defineProperty(exports, "bar", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "default", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "default", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "bar", { enumerable: true, - get: function get() { + get: function () { return _foo.bar; } }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-named/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-named/expected.js index e0884fd4db..ebfaeff38a 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-named/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-named/expected.js @@ -1,12 +1,12 @@ define(["exports"], function (exports) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); exports.foo = foo; exports.foo = foo; exports.bar = bar; exports.bar = foo; - exports["default"] = foo; - exports["default"] = foo; + exports.default = foo; + exports.default = foo; exports.bar = bar; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-variable/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-variable/expected.js index 1a1009f9b1..f3a3b41647 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-variable/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/exports-variable/expected.js @@ -1,30 +1,22 @@ define(["exports"], function (exports) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); exports.foo7 = foo7; - var foo = 1; - exports.foo = foo; - var foo = 1, - bar = 2; - exports.foo = foo; - exports.bar = bar; - var foo2 = function foo2() {}; - exports.foo2 = foo2; - var foo3; - exports.foo3 = foo3; - var foo4 = 2; - exports.foo4 = foo4; - var foo5 = undefined; - exports.foo5 = foo5; - var foo6 = 3; - exports.foo6 = foo6; + var foo = exports.foo = 1; + var foo = exports.foo = 1, + bar = exports.bar = 2; + + var foo2 = exports.foo2 = function () {}; + + var foo3 = exports.foo3 = undefined; + let foo4 = exports.foo4 = 2; + let foo5 = exports.foo5 = undefined; + const foo6 = exports.foo6 = 3; function foo7() {} - var foo8 = function foo8() { - babelHelpers.classCallCheck(this, foo8); - }; + class foo8 {} exports.foo8 = foo8; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/get-module-name-option/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/get-module-name-option/expected.js index 4a88732e99..236ed887cb 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/get-module-name-option/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/get-module-name-option/expected.js @@ -1,3 +1 @@ -define("my custom module name", ["exports"], function (exports) { - "use strict"; -}); \ No newline at end of file +define("my custom module name", [], function () {}); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/hoist-function-exports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/hoist-function-exports/expected.js index df2eab1f9b..4a1cf55db8 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/hoist-function-exports/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/hoist-function-exports/expected.js @@ -1,17 +1,17 @@ define(["exports", "./evens"], function (exports, _evens) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); + exports.isOdd = undefined; exports.nextOdd = nextOdd; function nextOdd(n) { return (0, _evens.isEven)(n) ? n + 1 : n + 2; } - var isOdd = (function (isEven) { + var isOdd = exports.isOdd = (function (isEven) { return function (n) { return !isEven(n); }; })(_evens.isEven); - exports.isOdd = isOdd; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-default/expected.js index 842bde29a3..920bf04d48 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-default/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-default/expected.js @@ -1,8 +1,6 @@ -define(["exports", "foo"], function (exports, _foo) { - var _foo2 = babelHelpers.interopRequireDefault(_foo); +define(["foo"], function (_foo) { + var _foo2 = babelHelpers.interopRequireDefault(_foo); - var _foo22 = babelHelpers.interopRequireDefault(_foo); - - _foo2["default"]; - _foo22["default"]; + _foo2.default; + _foo2.default; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-glob/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-glob/expected.js index 6a485c6fd5..08282514a1 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-glob/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-glob/expected.js @@ -1,3 +1,4 @@ -define(["exports", "foo"], function (exports, _foo) { - _foo; +define(["foo"], function (_foo) { + var foo = babelHelpers.interopRequireWildcard(_foo); + foo; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-mixing/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-mixing/expected.js index 0484a41dd4..660f045a4e 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-mixing/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-mixing/expected.js @@ -1,6 +1,6 @@ -define(["exports", "foo"], function (exports, _foo) { - var _foo2 = babelHelpers.interopRequireDefault(_foo); +define(["foo"], function (_foo) { + var _foo2 = babelHelpers.interopRequireDefault(_foo); - _foo2["default"]; + _foo2.default; _foo.baz; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-named/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-named/expected.js index c1b2a71fea..bdbf6205eb 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-named/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports-named/expected.js @@ -1,5 +1,5 @@ -define(["exports", "foo"], function (exports, _foo) { - _foo.bar; +define(["foo"], function (_foo) { + _foo.bar; _foo.bar2; _foo.baz; _foo.bar; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports/expected.js index 84e1e6dcc7..ac340082b3 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/imports/expected.js @@ -1,3 +1 @@ -define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo, _fooBar, _directoryFooBar) { - "use strict"; -}); \ No newline at end of file +define(["foo", "foo-bar", "./directory/foo-bar"], function () {}); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/module-name/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/module-name/expected.js index b8575435cc..57378003a7 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/module-name/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/module-name/expected.js @@ -1,3 +1,3 @@ -define("es6.modules-amd/module-name/expected", ["exports"], function (exports) { - foobar(); +define("es6.modules-amd/module-name/expected", [], function () { + foobar(); }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/options.json index 746fb0d131..69f4662d87 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/options.json @@ -1,4 +1,3 @@ { - "plugins": ["external-helpers"], - "modules": "amd" + "plugins": ["external-helpers", "transform-es2015-modules-amd"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/overview/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/overview/expected.js index b517a494b8..de671af9d2 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/overview/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/overview/expected.js @@ -1,18 +1,14 @@ -define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo, _fooBar, _directoryFooBar) { - Object.defineProperty(exports, "__esModule", { +define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo) { + Object.defineProperty(exports, "__esModule", { value: true }); - - var _foo2 = babelHelpers.interopRequireDefault(_foo); - + exports.test2 = exports.test = undefined; + var foo2 = babelHelpers.interopRequireWildcard(_foo); exports.test = test; - var test2 = 5; - - exports.test2 = test2; - exports["default"] = test; - - _foo2["default"]; - _foo; + var test2 = exports.test2 = 5; + exports.default = test; + foo2.default; + foo2; _foo.bar; _foo.foo; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/remap/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/remap/expected.js index 976a922eb4..9211a9b13d 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-amd/remap/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-amd/remap/expected.js @@ -1,9 +1,8 @@ define(["exports"], function (exports) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); - var test = 2; - exports.test = test; + var test = exports.test = 2; exports.test = test = 5; exports.test = test += 1; @@ -15,17 +14,12 @@ define(["exports"], function (exports) { var a = 2; exports.a = a; - exports.a = a = 3; - var b = 2; exports.c = b; - exports.c = b = 3; - var d = 3; exports.e = d; exports.f = d; - exports.f = exports.e = d = 4; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export-1/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export-1/expected.js index 9be9e2f8ba..3853346ca6 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export-1/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export-1/expected.js @@ -1 +1 @@ -exports["default"] = foo; +exports.default = foo; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export-2/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export-2/expected.js index 9be9e2f8ba..3853346ca6 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export-2/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export-2/expected.js @@ -1 +1 @@ -exports["default"] = foo; +exports.default = foo; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export/expected.js index 54c9f7d911..a78f99e303 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/export/expected.js @@ -1,3 +1,2 @@ exports.foo = foo; - function foo() {} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/import/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/import/expected.js index d7549206ee..81e62c8a6a 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/import/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/import/expected.js @@ -1,7 +1,5 @@ var _foo = require("foo"); -var foo4 = _foo; - -_foo["default"]; -_foo["default"]; +_foo.default; +_foo.default; _foo.foo3; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/options.json index 42fca89301..b2db9b9205 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common-strict/options.json @@ -1,3 +1,3 @@ { - "modules": "commonStrict" + "plugins": ["external-helpers", ["transform-es2015-modules-commonjs", { "strict": true }]] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-default-non-function/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-default-non-function/expected.js index 5684287aef..0c17404a23 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-default-non-function/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-default-non-function/expected.js @@ -2,6 +2,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.Cachier = Cachier; -exports["default"] = new Cachier(); - +exports.default = new Cachier(); function Cachier(databaseName) {} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-default/expected.js index 883ce71df1..dac611107f 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-default/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-default/expected.js @@ -1,31 +1,20 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports["default"] = foo; -exports["default"] = 42; -exports["default"] = {}; -exports["default"] = []; -exports["default"] = foo; -exports["default"] = function () {}; - -var _default = function _default() { - babelHelpers.classCallCheck(this, _default); -}; - -exports["default"] = _default; +exports.default = function () {}; +exports.default = foo; +exports.default = 42; +exports.default = {}; +exports.default = []; +exports.default = foo; +exports.default = class {}; function foo() {} +class Foo {} +exports.default = Foo; +exports.default = foo; -var Foo = function Foo() { - babelHelpers.classCallCheck(this, Foo); -}; - -exports["default"] = Foo; -exports["default"] = foo; - -exports["default"] = (function () { +exports.default = (function () { return "foo"; })(); - -module.exports = exports["default"]; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-from/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-from/expected.js index 6480c1867f..b11ab3a306 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-from/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-from/expected.js @@ -4,46 +4,55 @@ Object.defineProperty(exports, "__esModule", { var _foo = require("foo"); -babelHelpers.defaults(exports, babelHelpers.interopExportWildcard(_foo, babelHelpers.defaults)); +for (let _key in _foo) { + if (_key === "default") continue; + Object.defineProperty(exports, _key, { + enumerable: true, + get: function () { + return _foo[_key]; + } + }); +} + Object.defineProperty(exports, "foo", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "foo", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "bar", { enumerable: true, - get: function get() { + get: function () { return _foo.bar; } }); Object.defineProperty(exports, "bar", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "default", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "default", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "bar", { enumerable: true, - get: function get() { + get: function () { return _foo.bar; } }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-named/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-named/expected.js index 8ff5bb80a7..8deb82b599 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-named/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-named/expected.js @@ -5,6 +5,6 @@ exports.foo = foo; exports.foo = foo; exports.bar = bar; exports.bar = foo; -exports["default"] = foo; -exports["default"] = foo; +exports.default = foo; +exports.default = foo; exports.bar = bar; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-variable/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-variable/expected.js index 4e80974346..ce80d1d2b8 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-variable/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/exports-variable/expected.js @@ -2,27 +2,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.foo7 = foo7; -var foo = 1; -exports.foo = foo; -var foo = 1, - bar = 2; -exports.foo = foo; -exports.bar = bar; -var foo2 = function foo2() {}; -exports.foo2 = foo2; -var foo3; -exports.foo3 = foo3; -var foo4 = 2; -exports.foo4 = foo4; -var foo5 = undefined; -exports.foo5 = foo5; -var foo6 = 3; -exports.foo6 = foo6; - +var foo = exports.foo = 1; +var foo = exports.foo = 1, + bar = exports.bar = 2; +var foo2 = exports.foo2 = function () {}; +var foo3 = exports.foo3 = undefined; +let foo4 = exports.foo4 = 2; +let foo5 = exports.foo5 = undefined; +const foo6 = exports.foo6 = 3; function foo7() {} - -var foo8 = function foo8() { - babelHelpers.classCallCheck(this, foo8); -}; - +class foo8 {} exports.foo8 = foo8; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/hoist-function-exports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/hoist-function-exports/expected.js index 3c0206f916..dc60fbd4d1 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/hoist-function-exports/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/hoist-function-exports/expected.js @@ -1,6 +1,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); +exports.isOdd = undefined; exports.nextOdd = nextOdd; var _evens = require("./evens"); @@ -9,9 +10,8 @@ function nextOdd(n) { return (0, _evens.isEven)(n) ? n + 1 : n + 2; } -var isOdd = (function (isEven) { +var isOdd = exports.isOdd = (function (isEven) { return function (n) { return !isEven(n); }; })(_evens.isEven); -exports.isOdd = isOdd; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-default/expected.js index 081aefe73c..e318052d21 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-default/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-default/expected.js @@ -2,7 +2,5 @@ var _foo = require("foo"); var _foo2 = babelHelpers.interopRequireDefault(_foo); -var _foo3 = babelHelpers.interopRequireDefault(_foo); - -_foo2["default"]; -_foo3["default"]; +_foo2.default; +_foo2.default; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-mixing/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-mixing/expected.js index 2000497f8a..b8dd69bad9 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-mixing/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-mixing/expected.js @@ -2,5 +2,5 @@ var _foo = require("foo"); var _foo2 = babelHelpers.interopRequireDefault(_foo); -_foo2["default"]; +_foo2.default; _foo.baz; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-named/source-mappings.json b/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-named/source-mappings.json deleted file mode 100644 index 1b44ef3d04..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/imports-named/source-mappings.json +++ /dev/null @@ -1,19 +0,0 @@ -[{ - "original": { - "line": 6, - "column": 0 - }, - "generated": { - "line": 5, - "column": 6 - } -}, { - "original": { - "line": 9, - "column": 0 - }, - "generated": { - "line": 8, - "column": 6 - } -}] diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose-collision/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose-collision/actual.js deleted file mode 100644 index 89934708a6..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose-collision/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -if (true) { - import foo from "foo"; -} else { - import bar from "foo"; -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose-collision/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose-collision/options.json deleted file mode 100644 index 1d2da25030..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose-collision/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "throws": "Duplicate module declarations with the same source but in different scopes", - "loose": "es6.modules" -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose/actual.js deleted file mode 100644 index 6d06248e3c..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose/actual.js +++ /dev/null @@ -1,7 +0,0 @@ -export var foo = 5; - -if (true) { - import bar from "bar"; -} - -bar; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose/expected.js deleted file mode 100644 index 806072db32..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose/expected.js +++ /dev/null @@ -1,11 +0,0 @@ -exports.__esModule = true; -var foo = 5; - -exports.foo = foo; -if (true) { - var _bar = require("bar"); - - var _bar2 = babelHelpers.interopRequireDefault(_bar); -} - -bar; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose/options.json deleted file mode 100644 index 6614874cd3..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/loose/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "loose": "es6.modules" -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/module-shadow/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/module-shadow/expected.js index ec455bde13..130e6fa256 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/module-shadow/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/module-shadow/expected.js @@ -1,6 +1,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.module = _module; - function _module() {} +exports.module = _module; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules-common/options.json index d29eaa83df..7ccaf471d1 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/options.json @@ -1,4 +1,3 @@ { - "plugins": ["external-helpers"], - "modules": "common" + "plugins": ["external-helpers", "transform-es2015-modules-commonjs"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/overview/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/overview/expected.js index 142ad6b939..ed191101ce 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/overview/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/overview/expected.js @@ -1,6 +1,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); +exports.test = undefined; require("foo"); @@ -8,9 +9,9 @@ require("foo-bar"); require("./directory/foo-bar"); -var _foo2 = require("foo2"); +var _foo = require("foo2"); -var _foo22 = babelHelpers.interopRequireDefault(_foo2); +var _foo2 = babelHelpers.interopRequireDefault(_foo); var _foo3 = require("foo3"); @@ -21,9 +22,8 @@ var _foo4 = require("foo4"); var _foo5 = require("foo5"); exports.test = test; -var test = 5; +var test = exports.test = 5; -exports.test = test; _foo4.bar; _foo5.foo; -_foo22["default"]; +_foo2.default; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-common/remap/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-common/remap/expected.js index 569f369205..376fb187da 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-common/remap/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-common/remap/expected.js @@ -1,8 +1,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var test = 2; -exports.test = test; +var test = exports.test = 2; exports.test = test = 5; exports.test = test += 1; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-default/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-default/actual.js deleted file mode 100644 index 62923e5c15..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-default/actual.js +++ /dev/null @@ -1,8 +0,0 @@ -export default 42; -export default {}; -export default []; -export default foo; -export default function () {} -export default class {} -export default function foo () {} -export default class Foo {} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-default/expected.js deleted file mode 100644 index ec6569b8f6..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-default/expected.js +++ /dev/null @@ -1,11 +0,0 @@ -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var _default = function _default() { - _classCallCheck(this, _default); -}; - -function foo() {} - -var Foo = function Foo() { - _classCallCheck(this, Foo); -}; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-from/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-from/actual.js deleted file mode 100644 index 60857f6542..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-from/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -export * from "foo"; -export {foo} from "foo"; -export {foo, bar} from "foo"; -export {foo as bar} from "foo"; -export {foo as default} from "foo"; -export {foo as default, bar} from "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-from/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-from/expected.js deleted file mode 100644 index 3918c74e44..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-from/expected.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-named/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-named/actual.js deleted file mode 100644 index 8515ace759..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-named/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -export {foo}; -export {foo, bar}; -export {foo as bar}; -export {foo as default}; -export {foo as default, bar}; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-named/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-named/expected.js deleted file mode 100644 index 3918c74e44..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-named/expected.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-variable/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-variable/actual.js deleted file mode 100644 index c9cd5af09c..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-variable/actual.js +++ /dev/null @@ -1,9 +0,0 @@ -export var foo = 1; -export var foo = 1, bar = 2; -export var foo2 = function () {}; -export var foo3; -export let foo4 = 2; -export let foo5; -export const foo6 = 3; -export function foo7 () {} -export class foo8 {} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-variable/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-variable/expected.js deleted file mode 100644 index 35f4b5a1dd..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/exports-variable/expected.js +++ /dev/null @@ -1,16 +0,0 @@ -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var foo = 1; -var foo = 1, - bar = 2; -var foo2 = function foo2() {}; -var foo3; -var foo4 = 2; -var foo5 = undefined; -var foo6 = 3; - -function foo7() {} - -var foo8 = function foo8() { - _classCallCheck(this, foo8); -}; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/hoist-function-exports/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/hoist-function-exports/actual.js deleted file mode 100644 index 3c40b7d1c1..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/hoist-function-exports/actual.js +++ /dev/null @@ -1,11 +0,0 @@ -import { isEven } from "./evens"; - -export function nextOdd(n) { - return isEven(n) ? n + 1 : n + 2; -} - -export var isOdd = (function (isEven) { - return function (n) { - return !isEven(n); - }; -})(isEven); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/hoist-function-exports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/hoist-function-exports/expected.js deleted file mode 100644 index 7240eb8bfb..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/hoist-function-exports/expected.js +++ /dev/null @@ -1,9 +0,0 @@ -function nextOdd(n) { - return isEven(n) ? n + 1 : n + 2; -} - -var isOdd = (function (isEven) { - return function (n) { - return !isEven(n); - }; -})(isEven); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-default/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-default/actual.js deleted file mode 100644 index 7a085cb1e3..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-default/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -import foo from "foo"; -import {default as foo2} from "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-default/expected.js deleted file mode 100644 index 3918c74e44..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-default/expected.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-glob/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-glob/actual.js deleted file mode 100644 index e55c077500..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-glob/actual.js +++ /dev/null @@ -1 +0,0 @@ -import * as foo from "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-glob/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-glob/expected.js deleted file mode 100644 index 3918c74e44..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-glob/expected.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-mixing/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-mixing/actual.js deleted file mode 100644 index ef78c95b1c..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-mixing/actual.js +++ /dev/null @@ -1 +0,0 @@ -import foo, {baz as xyz} from "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-mixing/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-mixing/expected.js deleted file mode 100644 index 3918c74e44..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-mixing/expected.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-named/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-named/actual.js deleted file mode 100644 index 6d50813b6f..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-named/actual.js +++ /dev/null @@ -1,4 +0,0 @@ -import {bar} from "foo"; -import {bar2, baz} from "foo"; -import {bar as baz2} from "foo"; -import {bar as baz3, xyz} from "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-named/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-named/expected.js deleted file mode 100644 index 3918c74e44..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports-named/expected.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports/actual.js deleted file mode 100644 index 222b6885ac..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports/expected.js deleted file mode 100644 index 3918c74e44..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/imports/expected.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/options.json deleted file mode 100644 index b074844829..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "modules": "ignore" -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/overview/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/overview/actual.js deleted file mode 100644 index 1623f8b61e..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/overview/actual.js +++ /dev/null @@ -1,12 +0,0 @@ -import "foo"; -import "foo-bar"; -import "./directory/foo-bar"; -import foo from "foo"; -import * as foo2 from "foo"; -import {bar} from "foo"; -import {foo as bar2} from "foo"; - -export {test}; -export var test2 = 5; - -export default test; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/overview/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/overview/expected.js deleted file mode 100644 index c9f1d0dc74..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/overview/expected.js +++ /dev/null @@ -1 +0,0 @@ -var test2 = 5; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/remap/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/remap/actual.js deleted file mode 100644 index 79c234d8ae..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/remap/actual.js +++ /dev/null @@ -1,9 +0,0 @@ -export var test = 2; -test = 5; -test++; - -(function () { - var test = 2; - test = 3; - test++; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/remap/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/remap/expected.js deleted file mode 100644 index 0c4ba585d3..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-ignore/remap/expected.js +++ /dev/null @@ -1,9 +0,0 @@ -var test = 2; -test = 5; -test++; - -(function () { - var test = 2; - test = 3; - test++; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-default/expected.js index 5083193ab3..233a3d1916 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-default/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-default/expected.js @@ -1,12 +1,12 @@ System.register([], function (_export) { - var _default, Foo; + _export("default", function () {}); - _export("default", foo); - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + _export("default", class {}); function foo() {} + _export("default", foo); + return { setters: [], execute: function () { @@ -18,17 +18,7 @@ System.register([], function (_export) { _export("default", foo); - _export("default", function () {}); - - _default = function _default() { - _classCallCheck(this, _default); - }; - - _export("default", _default); - - Foo = function Foo() { - _classCallCheck(this, Foo); - }; + class Foo {} _export("default", Foo); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-from/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-from/expected.js index 2248f76927..2138d0b019 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-from/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-from/expected.js @@ -1,23 +1,21 @@ System.register(["foo"], function (_export) { - return { + return { setters: [function (_foo) { + var _exportObj = {}; + for (var _key in _foo) { - if (_key !== "default") _export(_key, _foo[_key]); + if (_key !== "default") _exportObj[_key] = _foo[_key]; } - _export("foo", _foo.foo); + _exportObj.foo = _foo.foo; + _exportObj.foo = _foo.foo; + _exportObj.bar = _foo.bar; + _exportObj.bar = _foo.foo; + _exportObj.default = _foo.foo; + _exportObj.default = _foo.foo; + _exportObj.bar = _foo.bar; - _export("foo", _foo.foo); - - _export("bar", _foo.bar); - - _export("bar", _foo.foo); - - _export("default", _foo.foo); - - _export("default", _foo.foo); - - _export("bar", _foo.bar); + _export(_exportObj); }], execute: function () {} }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-named/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-named/expected.js index f63db708e4..fa746cdbf5 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-named/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-named/expected.js @@ -1,5 +1,5 @@ System.register([], function (_export) { - return { + return { setters: [], execute: function () { _export("foo", foo); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-variable/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-variable/expected.js index 0ba18f899c..9cb480f5ab 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-variable/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/exports-variable/expected.js @@ -1,40 +1,36 @@ System.register([], function (_export) { - var foo, foo2, foo3, foo4, foo5, foo6, foo8; - - _export("foo7", foo7); - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - - function foo7() {} - return { setters: [], execute: function () { - foo = 1; + var foo = 1; _export("foo", foo); - foo2 = function foo2() {}; + var foo2 = function () {}; _export("foo2", foo2); + var foo3; + _export("foo3", foo3); - foo4 = 2; + let foo4 = 2; _export("foo4", foo4); - foo5 = undefined; + let foo5; _export("foo5", foo5); - foo6 = 3; + const foo6 = 3; _export("foo6", foo6); - foo8 = function foo8() { - _classCallCheck(this, foo8); - }; + function foo7() {} + + _export("foo7", foo7); + + class foo8 {} _export("foo8", foo8); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/get-module-name-option/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/get-module-name-option/expected.js index bfdb2cac03..0c17201579 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/get-module-name-option/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/get-module-name-option/expected.js @@ -1,5 +1,5 @@ System.register("my custom module name", [], function (_export) { - return { + return { setters: [], execute: function () {} }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/hoist-function-exports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/hoist-function-exports/expected.js index bdcb01f7ed..35ddbbb7e9 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/hoist-function-exports/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/hoist-function-exports/expected.js @@ -1,18 +1,19 @@ System.register(["./evens"], function (_export) { - var isEven, p, a, i, j, isOdd; - - _export("nextOdd", nextOdd); - - function nextOdd(n) { - return _export("p", p = isEven(n) ? n + 1 : n + 2); - } - + var isEven, p, a, i, j, isOdd; return { setters: [function (_evens) { isEven = _evens.isEven; }], execute: function () { - p = 5; + function nextOdd(n) { + return _export("p", p = isEven(n) ? n + 1 : n + 2); + } + + _export("nextOdd", nextOdd); + + _export("n", n); + + _export("p", p = 5); _export("p", p); @@ -20,11 +21,11 @@ System.register(["./evens"], function (_export) { for (i = 0, j = 0;;); - isOdd = (function (isEven) { + _export("isOdd", isOdd = (function (isEven) { return function (n) { return !isEven(n); }; - })(isEven); + })(isEven)); _export("isOdd", isOdd); } diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-default/expected.js index a8a7d62087..00ac1f0867 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-default/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-default/expected.js @@ -1,9 +1,9 @@ System.register(["foo"], function (_export) { - var foo, foo2; + var foo, foo2; return { setters: [function (_foo) { - foo = _foo["default"]; - foo2 = _foo["default"]; + foo = _foo.default; + foo2 = _foo.default; }], execute: function () {} }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-glob/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-glob/expected.js index 66701c9a26..6a4654fdbb 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-glob/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-glob/expected.js @@ -1,5 +1,5 @@ System.register(["foo"], function (_export) { - var foo; + var foo; return { setters: [function (_foo) { foo = _foo; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-mixing/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-mixing/expected.js index e60d5fb75f..989ca23802 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-mixing/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-mixing/expected.js @@ -1,8 +1,8 @@ System.register(["foo"], function (_export) { - var foo, xyz; + var foo, xyz; return { setters: [function (_foo) { - foo = _foo["default"]; + foo = _foo.default; xyz = _foo.baz; }], execute: function () {} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-named/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-named/expected.js index b74a9a19cf..838f000f86 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-named/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports-named/expected.js @@ -1,5 +1,5 @@ System.register(["foo"], function (_export) { - var bar, bar2, baz, baz2, baz3, xyz; + var bar, bar2, baz, baz2, baz3, xyz; return { setters: [function (_foo) { bar = _foo.bar; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports/expected.js index d1dcb2a471..afe4e38091 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/imports/expected.js @@ -1,5 +1,5 @@ System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) { - return { + return { setters: [function (_foo) {}, function (_fooBar) {}, function (_directoryFooBar) {}], execute: function () {} }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules-system/options.json index ee42d8e1c8..576c2a257c 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/options.json @@ -1,3 +1,3 @@ { - "modules": "system" + "plugins": ["external-helpers", "transform-es2015-modules-systemjs"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/overview/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/overview/expected.js index c9afd43f8e..73c7a8ee26 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/overview/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/overview/expected.js @@ -1,8 +1,8 @@ System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) { - var foo, foo2, bar, bar2, test2; + var foo, foo2, bar, bar2, test2; return { setters: [function (_foo) { - foo = _foo["default"]; + foo = _foo.default; foo2 = _foo; bar = _foo.bar; bar2 = _foo.foo; @@ -10,7 +10,7 @@ System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) { execute: function () { _export("test", test); - test2 = 5; + _export("test2", test2 = 5); _export("test2", test2); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-system/remap/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-system/remap/expected.js index 93bb4496c3..0df099b2a0 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-system/remap/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-system/remap/expected.js @@ -1,14 +1,15 @@ System.register([], function (_export) { - var test, a, b, d; + var test, a, b, d; return { setters: [], execute: function () { - test = 2; + _export("test", test = 2); _export("test", test); _export("test", test = 5); - _export("test", test += 1); + + _export("test", test++); (function () { var test = 2; @@ -16,19 +17,19 @@ System.register([], function (_export) { test++; })(); - a = 2; + _export("a", a = 2); _export("a", a); _export("a", a = 3); - b = 2; + _export("c", b = 2); _export("c", b); _export("c", b = 3); - d = 3; + _export("f", _export("e", d = 3)); _export("e", d); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-default/expected.js index ae2b74d80c..a84e598cfd 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-default/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-default/expected.js @@ -1,40 +1,37 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define(["exports", "module"], factory); - } else if (typeof exports !== "undefined" && typeof module !== "undefined") { - factory(exports, module); + define(["exports"], factory); + } else if (typeof exports !== "undefined") { + factory(exports); } else { var mod = { exports: {} }; - factory(mod.exports, mod); + factory(mod.exports); global.actual = mod.exports; } -})(this, function (exports, module) { - module.exports = foo; - module.exports = 42; - module.exports = {}; - module.exports = []; - module.exports = foo; +})(this, function (exports) { + Object.defineProperty(exports, "__esModule", { + value: true + }); - module.exports = function () {}; + exports.default = function () {}; - var _default = function _default() { - babelHelpers.classCallCheck(this, _default); - }; - - module.exports = _default; + exports.default = foo; + exports.default = 42; + exports.default = {}; + exports.default = []; + exports.default = foo; + exports.default = class {}; function foo() {} - var Foo = function Foo() { - babelHelpers.classCallCheck(this, Foo); - }; + class Foo {} - module.exports = Foo; - module.exports = foo; + exports.default = Foo; + exports.default = foo; - module.exports = (function () { + exports.default = (function () { return "foo"; })(); }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-from/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-from/expected.js index 69b2a0a2a5..d0b034fc04 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-from/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-from/expected.js @@ -11,49 +11,59 @@ global.actual = mod.exports; } })(this, function (exports, _foo) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); - babelHelpers.defaults(exports, babelHelpers.interopExportWildcard(_foo, babelHelpers.defaults)); + + for (let _key in _foo) { + if (_key === "default") continue; + Object.defineProperty(exports, _key, { + enumerable: true, + get: function () { + return _foo[_key]; + } + }); + } + Object.defineProperty(exports, "foo", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "foo", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "bar", { enumerable: true, - get: function get() { + get: function () { return _foo.bar; } }); Object.defineProperty(exports, "bar", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "default", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "default", { enumerable: true, - get: function get() { + get: function () { return _foo.foo; } }); Object.defineProperty(exports, "bar", { enumerable: true, - get: function get() { + get: function () { return _foo.bar; } }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-named/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-named/expected.js index 77898e1f56..0b7b3b94be 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-named/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-named/expected.js @@ -11,14 +11,14 @@ global.actual = mod.exports; } })(this, function (exports) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); exports.foo = foo; exports.foo = foo; exports.bar = bar; exports.bar = foo; - exports["default"] = foo; - exports["default"] = foo; + exports.default = foo; + exports.default = foo; exports.bar = bar; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-variable/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-variable/expected.js index 4f6edb07ca..baeb2d58b4 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-variable/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/exports-variable/expected.js @@ -11,32 +11,24 @@ global.actual = mod.exports; } })(this, function (exports) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); exports.foo7 = foo7; - var foo = 1; - exports.foo = foo; - var foo = 1, - bar = 2; - exports.foo = foo; - exports.bar = bar; - var foo2 = function foo2() {}; - exports.foo2 = foo2; - var foo3; - exports.foo3 = foo3; - var foo4 = 2; - exports.foo4 = foo4; - var foo5 = undefined; - exports.foo5 = foo5; - var foo6 = 3; - exports.foo6 = foo6; + var foo = exports.foo = 1; + var foo = exports.foo = 1, + bar = exports.bar = 2; + + var foo2 = exports.foo2 = function () {}; + + var foo3 = exports.foo3 = undefined; + let foo4 = exports.foo4 = 2; + let foo5 = exports.foo5 = undefined; + const foo6 = exports.foo6 = 3; function foo7() {} - var foo8 = function foo8() { - babelHelpers.classCallCheck(this, foo8); - }; + class foo8 {} exports.foo8 = foo8; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/get-module-name-option/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/get-module-name-option/expected.js index 6c3019bb18..775365ff70 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/get-module-name-option/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/get-module-name-option/expected.js @@ -1,15 +1,13 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define("my custom module name", ["exports"], factory); + define("my custom module name", [], factory); } else if (typeof exports !== "undefined") { - factory(exports); + factory(); } else { var mod = { exports: {} }; - factory(mod.exports); + factory(); global.myCustomModuleName = mod.exports; } -})(this, function (exports) { - "use strict"; -}); \ No newline at end of file +})(this, function () {}); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/hoist-function-exports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/hoist-function-exports/expected.js index 4c30b7fd35..a53e4af635 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/hoist-function-exports/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/hoist-function-exports/expected.js @@ -11,19 +11,19 @@ global.actual = mod.exports; } })(this, function (exports, _evens) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); + exports.isOdd = undefined; exports.nextOdd = nextOdd; function nextOdd(n) { return (0, _evens.isEven)(n) ? n + 1 : n + 2; } - var isOdd = (function (isEven) { + var isOdd = exports.isOdd = (function (isEven) { return function (n) { return !isEven(n); }; })(_evens.isEven); - exports.isOdd = isOdd; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-default/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-default/expected.js index 540a33a0ca..e58e158cb5 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-default/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-default/expected.js @@ -1,20 +1,18 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); + define(["foo"], factory); } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); + factory(require("foo")); } else { var mod = { exports: {} }; - factory(mod.exports, global.foo); + factory(global.foo); global.actual = mod.exports; } -})(this, function (exports, _foo) { - var _foo2 = babelHelpers.interopRequireDefault(_foo); +})(this, function (_foo) { + var _foo2 = babelHelpers.interopRequireDefault(_foo); - var _foo22 = babelHelpers.interopRequireDefault(_foo); - - _foo2["default"]; - _foo22["default"]; + _foo2.default; + _foo2.default; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-glob/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-glob/expected.js index db716ced9f..31de90105f 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-glob/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-glob/expected.js @@ -1,15 +1,16 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); + define(["foo"], factory); } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); + factory(require("foo")); } else { var mod = { exports: {} }; - factory(mod.exports, global.foo); + factory(global.foo); global.actual = mod.exports; } -})(this, function (exports, _foo) { - _foo; +})(this, function (_foo) { + var foo = babelHelpers.interopRequireWildcard(_foo); + foo; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-mixing/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-mixing/expected.js index e446ec93ea..b7d62c6ca0 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-mixing/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-mixing/expected.js @@ -1,17 +1,17 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); + define(["foo"], factory); } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); + factory(require("foo")); } else { var mod = { exports: {} }; - factory(mod.exports, global.foo); + factory(global.foo); global.actual = mod.exports; } -})(this, function (exports, _foo) { - var _foo2 = babelHelpers.interopRequireDefault(_foo); +})(this, function (_foo) { + var _foo2 = babelHelpers.interopRequireDefault(_foo); _foo.baz; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-named/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-named/expected.js index 6d262b1f3c..de8aef3f6c 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-named/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports-named/expected.js @@ -1,17 +1,17 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define(["exports", "foo"], factory); + define(["foo"], factory); } else if (typeof exports !== "undefined") { - factory(exports, require("foo")); + factory(require("foo")); } else { var mod = { exports: {} }; - factory(mod.exports, global.foo); + factory(global.foo); global.actual = mod.exports; } -})(this, function (exports, _foo) { - _foo.bar; +})(this, function (_foo) { + _foo.bar; _foo.bar2; _foo.baz; _foo.bar; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports/expected.js index ef4725dcb4..c35422d7b9 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/imports/expected.js @@ -1,15 +1,13 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define(["exports", "foo", "foo-bar", "./directory/foo-bar"], factory); + define(["foo", "foo-bar", "./directory/foo-bar"], factory); } else if (typeof exports !== "undefined") { - factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar")); + factory(require("foo"), require("foo-bar"), require("./directory/foo-bar")); } else { var mod = { exports: {} }; - factory(mod.exports, global.foo, global.fooBar, global.fooBar); + factory(global.foo, global.fooBar, global.fooBar); global.actual = mod.exports; } -})(this, function (exports, _foo, _fooBar, _directoryFooBar) { - "use strict"; -}); +})(this, function () {}); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/module-id/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/module-id/expected.js index f7eb363ec6..2855ccd1ba 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/module-id/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/module-id/expected.js @@ -1,15 +1,15 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define("MyLib", ["exports"], factory); + define("MyLib", [], factory); } else if (typeof exports !== "undefined") { - factory(exports); + factory(); } else { var mod = { exports: {} }; - factory(mod.exports); + factory(); global.MyLib = mod.exports; } -})(this, function (exports) { - foobar(); +})(this, function () { + foobar(); }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/module-name/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/module-name/expected.js index a6c8848e4a..2b7ca8878c 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/module-name/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/module-name/expected.js @@ -1,15 +1,15 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define("es6.modules-umd/module-name/expected", ["exports"], factory); + define("es6.modules-umd/module-name/expected", [], factory); } else if (typeof exports !== "undefined") { - factory(exports); + factory(); } else { var mod = { exports: {} }; - factory(mod.exports); + factory(); global.es6ModulesUmdModuleNameExpected = mod.exports; } -})(this, function (exports) { - foobar(); +})(this, function () { + foobar(); }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/non-default-imports/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/non-default-imports/expected.js index 5ee1c4b1e4..8a80ab5648 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/non-default-imports/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/non-default-imports/expected.js @@ -1,15 +1,13 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define(["exports", "./lib/render"], factory); + define(["./lib/render"], factory); } else if (typeof exports !== "undefined") { - factory(exports, require("./lib/render")); + factory(require("./lib/render")); } else { var mod = { exports: {} }; - factory(mod.exports, global.render); + factory(global.render); global.actual = mod.exports; } -})(this, function (exports, _libRender) { - "use strict"; -}); +})(this, function (_render) {}); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/options.json index 61b3905da7..3b3cb76192 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/options.json @@ -1,4 +1,3 @@ { - "plugins": ["external-helpers"], - "modules": "umd" + "plugins": ["external-helpers", "transform-es2015-modules-umd"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/overview/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/overview/expected.js index 1f06e7aaea..c66bd7da9f 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/overview/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/overview/expected.js @@ -7,22 +7,18 @@ var mod = { exports: {} }; - factory(mod.exports, global.foo2, global.fooBar, global.fooBar); + factory(mod.exports, global.foo, global.fooBar, global.fooBar); global.actual = mod.exports; } -})(this, function (exports, _foo, _fooBar, _directoryFooBar) { - Object.defineProperty(exports, "__esModule", { +})(this, function (exports, _foo) { + Object.defineProperty(exports, "__esModule", { value: true }); - - var _foo2 = babelHelpers.interopRequireDefault(_foo); - + exports.test2 = exports.test = undefined; + var foo2 = babelHelpers.interopRequireWildcard(_foo); exports.test = test; - var test2 = 5; - - exports.test2 = test2; - exports["default"] = test; - + var test2 = exports.test2 = 5; + exports.default = test; _foo.bar; _foo.foo; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/remap/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/remap/expected.js index 97dece8cc5..54aafe7c93 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.modules-umd/remap/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.modules-umd/remap/expected.js @@ -11,11 +11,10 @@ global.actual = mod.exports; } })(this, function (exports) { - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, "__esModule", { value: true }); - var test = 2; - exports.test = test; + var test = exports.test = 2; exports.test = test = 5; exports.test = test += 1; @@ -27,17 +26,12 @@ var a = 2; exports.a = a; - exports.a = a = 3; - var b = 2; exports.c = b; - exports.c = b = 3; - var d = 3; exports.e = d; exports.f = d; - exports.f = exports.e = d = 4; }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules/comments-explosion/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules/comments-explosion/actual.js deleted file mode 100644 index 6affde40ac..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules/comments-explosion/actual.js +++ /dev/null @@ -1,4 +0,0 @@ -bar(); - -// bar -export function foo() {} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules/comments-explosion/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules/comments-explosion/expected.js deleted file mode 100644 index 111778b28a..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules/comments-explosion/expected.js +++ /dev/null @@ -1,6 +0,0 @@ -export { foo }; -bar(); - -// bar - -function foo() {} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules/retain-lines/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules/retain-lines/actual.js deleted file mode 100644 index 6b7abe88c5..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules/retain-lines/actual.js +++ /dev/null @@ -1,11 +0,0 @@ -export function foo() { - console.log(1); - console.log(2); - console.log(3); -} - -export function bar() { - console.log(1); - console.log(2); - console.log(3); -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules/retain-lines/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules/retain-lines/expected.js deleted file mode 100644 index 2fac87fd6d..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules/retain-lines/expected.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict";export { foo };export { bar };function foo() { - console.log(1); - console.log(2); - console.log(3);} - - -function bar() { - console.log(1); - console.log(2); - console.log(3);} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules/retain-lines/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules/retain-lines/options.json deleted file mode 100644 index 97925bbcb6..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules/retain-lines/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "retainLines": true -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules/spec/actual.js b/packages/babel-core/test/fixtures/transformation/es6.modules/spec/actual.js deleted file mode 100644 index 3e524643d3..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules/spec/actual.js +++ /dev/null @@ -1 +0,0 @@ -export var foo = ""; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules/spec/expected.js b/packages/babel-core/test/fixtures/transformation/es6.modules/spec/expected.js deleted file mode 100644 index 48e42c9e77..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules/spec/expected.js +++ /dev/null @@ -1,4 +0,0 @@ -var _null = null; -export { _null as __proto__ }; -var foo = ""; -export { foo }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.modules/spec/options.json b/packages/babel-core/test/fixtures/transformation/es6.modules/spec/options.json deleted file mode 100644 index 3cefa67dc3..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.modules/spec/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "optional": ["es6.spec.modules"] -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.object-super/options.json b/packages/babel-core/test/fixtures/transformation/es6.object-super/options.json index 019532b4f9..a1e544dbb8 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.object-super/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.object-super/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers"] + "plugins": ["external-helpers", "transform-es2015-object-super"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.object-super/statically-bound/expected.js b/packages/babel-core/test/fixtures/transformation/es6.object-super/statically-bound/expected.js index cfee4015ce..e2504935dd 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.object-super/statically-bound/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.object-super/statically-bound/expected.js @@ -1,7 +1,7 @@ var _obj; var o = _obj = { - m: function m() { + m() { return babelHelpers.get(Object.getPrototypeOf(_obj), "x", this); } }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/default-before-last/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/default-before-last/expected.js index fb8ada05e6..fd30010bce 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/default-before-last/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/default-before-last/expected.js @@ -1,3 +1,4 @@ -function foo(a, b) { - if (a === undefined) a = "foo"; +function foo() { + var a = arguments.length <= 0 || arguments[0] === undefined ? "foo" : arguments[0]; + var b = arguments[1]; } diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/default-multiple/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/default-multiple/expected.js index b20c12fa6d..5d7a1b41e0 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/default-multiple/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/default-multiple/expected.js @@ -1,11 +1,11 @@ -var t = function t() { +var t = function () { var e = arguments.length <= 0 || arguments[0] === undefined ? "foo" : arguments[0]; var f = arguments.length <= 1 || arguments[1] === undefined ? 5 : arguments[1]; return e + " bar " + f; }; -var a = function a(e) { +var a = function (e) { var f = arguments.length <= 1 || arguments[1] === undefined ? 5 : arguments[1]; return e + " bar " + f; diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/default-single/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/default-single/expected.js index 4afa50f338..61ee0102e3 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/default-single/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/default-single/expected.js @@ -1,4 +1,4 @@ -var t = function t() { +var t = function () { var f = arguments.length <= 0 || arguments[0] === undefined ? "foo" : arguments[0]; return f + " bar"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/options.json b/packages/babel-core/test/fixtures/transformation/es6.parameters/options.json index 019532b4f9..bd67bd64db 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers"] + "plugins": ["external-helpers", "syntax-flow", "transform-es2015-parameters", "transform-es2015-block-scoping", "transform-es2015-spread", "transform-es2015-classes", "transform-es2015-destructuring", "transform-es2015-arrow-functions", "syntax-async-functions"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-arrow-functions/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-arrow-functions/expected.js index 76e62c3d36..62c2f6d931 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-arrow-functions/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-arrow-functions/expected.js @@ -1,20 +1,20 @@ -var concat = function concat() { +var concat = function () { var x = arguments[0]; var y = arguments[1]; }; -var somefun = function somefun() { - var get2ndArg = function get2ndArg(a, b) { +var somefun = function () { + var get2ndArg = function (a, b) { var _b = arguments[2]; - var somef = function somef(x, y, z) { + var somef = function (x, y, z) { var _a = arguments[3]; }; - var somefg = function somefg(c, d, e, f) { + var somefg = function (c, d, e, f) { var _a = arguments[4]; }; var _d = arguments[3]; }; - var get1stArg = function get1stArg() { + var get1stArg = function () { return arguments[0]; }; }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-async-function/actual.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-async-function/actual.js deleted file mode 100644 index 1bb83e3072..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-async-function/actual.js +++ /dev/null @@ -1,7 +0,0 @@ -var fn = async (...rest) => rest; - -var fn = async (...rest) => { - if (true) { - rest; - } -}; diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-async-function/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-async-function/expected.js deleted file mode 100644 index 0d6e350e14..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-async-function/expected.js +++ /dev/null @@ -1,37 +0,0 @@ -var _this = this; - -var fn = function fn() { - for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) { - rest[_key] = arguments[_key]; - } - - return regeneratorRuntime.async(function fn$(context$1$0) { - while (1) switch (context$1$0.prev = context$1$0.next) { - case 0: - return context$1$0.abrupt("return", rest); - - case 1: - case "end": - return context$1$0.stop(); - } - }, null, _this); -}; - -var fn = function fn() { - for (var _len2 = arguments.length, rest = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - rest[_key2] = arguments[_key2]; - } - - return regeneratorRuntime.async(function fn$(context$1$0) { - while (1) switch (context$1$0.prev = context$1$0.next) { - case 0: - if (true) { - rest; - } - - case 1: - case "end": - return context$1$0.stop(); - } - }, null, _this); -}; diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-binding-deoptimisation/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-binding-deoptimisation/expected.js index 6b72b34994..80224dbe80 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-binding-deoptimisation/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-binding-deoptimisation/expected.js @@ -1,4 +1,4 @@ -var deepAssign = function deepAssign() { +const deepAssign = function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-flow-parameter-reference/actual.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-flow-parameter-reference/actual.js deleted file mode 100644 index 22d0e1caef..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-flow-parameter-reference/actual.js +++ /dev/null @@ -1,9 +0,0 @@ -function foo( - x: Object, - ...types -): { types: Array, x: Object } { - return { - types: types, - x: x, - }; -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-flow-parameter-reference/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-flow-parameter-reference/expected.js deleted file mode 100644 index 2f2a31c5bb..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-flow-parameter-reference/expected.js +++ /dev/null @@ -1,10 +0,0 @@ -function foo(x) { - for (var _len = arguments.length, types = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - types[_key - 1] = arguments[_key]; - } - - return { - types: types, - x: x - }; -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-member-expression-deoptimisation/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-member-expression-deoptimisation/expected.js index 69c06843f0..56bad87ea3 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-member-expression-deoptimisation/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-member-expression-deoptimisation/expected.js @@ -1,4 +1,4 @@ -var x = function x(foo) { +var x = function (foo) { for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { bar[_key - 1] = arguments[_key]; } @@ -6,7 +6,7 @@ var x = function x(foo) { console.log(bar); }; -var y = function y(foo) { +var y = function (foo) { for (var _len2 = arguments.length, bar = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { bar[_key2 - 1] = arguments[_key2]; } @@ -16,7 +16,7 @@ var y = function y(foo) { }; }; -var b = function b(x, y) { +var b = function (x, y) { for (var _len3 = arguments.length, args = Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) { args[_key3 - 2] = arguments[_key3]; } @@ -26,17 +26,17 @@ var b = function b(x, y) { console.log(args[1]); }; -var z = function z(foo) { +var z = function (foo) { for (var _len4 = arguments.length, bar = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { bar[_key4 - 1] = arguments[_key4]; } - var x = function x() { + var x = function () { bar[1] = 5; }; }; -var a = function a(foo) { +var a = function (foo) { for (var _len5 = arguments.length, bar = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) { bar[_key5 - 1] = arguments[_key5]; } @@ -44,7 +44,7 @@ var a = function a(foo) { return bar.join(","); }; -var b = function b(foo) { +var b = function (foo) { var join = "join"; for (var _len6 = arguments.length, bar = Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-member-expression-optimisation/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-member-expression-optimisation/expected.js index 3a9c5ab53c..dbae1250ad 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-member-expression-optimisation/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-member-expression-optimisation/expected.js @@ -1,4 +1,4 @@ -var t = function t() { +var t = function () { var x = arguments[0]; var y = arguments[1]; }; @@ -7,4 +7,3 @@ function t() { var x = arguments[0]; var y = arguments[1]; } - diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-multiple/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-multiple/expected.js index fcb6ad5ddf..1975c117ba 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-multiple/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-multiple/expected.js @@ -1,4 +1,4 @@ -var t = function t(f) { +var t = function (f) { var x = f; x = arguments[1]; x = arguments[2]; @@ -9,4 +9,3 @@ function t(f) { x = arguments[1]; x = arguments[2]; } - diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js index 5283750ede..a687304cae 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-nested-iife/expected.js @@ -1,26 +1,20 @@ function broken(x) { - for (var _len = arguments.length, foo = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - foo[_key - 1] = arguments[_key]; - } - if (true) { - var _ret = (function () { - var Foo = (function (_Bar) { - babelHelpers.inherits(Foo, _Bar); + var Foo = (function (_Bar) { + babelHelpers.inherits(Foo, _Bar); - function Foo() { - babelHelpers.classCallCheck(this, Foo); - babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments); - } + function Foo() { + babelHelpers.classCallCheck(this, Foo); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).apply(this, arguments)); + } - return Foo; - })(Bar); + return Foo; + })(Bar); - return { - v: hello.apply(undefined, foo) - }; - })(); + for (var _len = arguments.length, foo = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + foo[_key - 1] = arguments[_key]; + } - if (typeof _ret === "object") return _ret.v; + return hello.apply(undefined, foo); } } diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-pattern/actual.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-pattern/actual.js deleted file mode 100644 index d26dae5716..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-pattern/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -var foo = function (...[a, b]) { -}; diff --git a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-pattern/expected.js b/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-pattern/expected.js deleted file mode 100644 index fff6e2b5b4..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.parameters/rest-pattern/expected.js +++ /dev/null @@ -1,5 +0,0 @@ -var foo = function foo() { - var a = arguments[0], - b = arguments[1]; -}; - diff --git a/packages/babel-core/test/fixtures/transformation/es6.properties.computed-loose/options.json b/packages/babel-core/test/fixtures/transformation/es6.properties.computed-loose/options.json index 79da122a18..dfcf614a8f 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.properties.computed-loose/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.properties.computed-loose/options.json @@ -1,3 +1,3 @@ { - "loose": ["es6.properties.computed"] + "plugins": ["external-helpers", ["transform-es2015-computed-properties", { "loose": true }]] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-computed/actual.js b/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-computed/actual.js deleted file mode 100644 index bc8b2e0ffb..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-computed/actual.js +++ /dev/null @@ -1,8 +0,0 @@ -var x = "y"; -var valueSet; -var obj = { - get [x] () { return 1 }, - set [x] (value) { valueSet = value } -}; -obj.y = "foo"; -obj.y === 1 && valueSet === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-computed/expected.js b/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-computed/expected.js deleted file mode 100644 index 86aeebf521..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-computed/expected.js +++ /dev/null @@ -1,14 +0,0 @@ -var x = "y"; -var valueSet; -var obj = Object.defineProperties({}, babelHelpers.defineProperty({}, x, { - get: function get() { - return 1; - }, - set: function set(value) { - valueSet = value; - }, - configurable: true, - enumerable: true -})); -obj.y = "foo"; -obj.y === 1 && valueSet === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-computed/options.json b/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-computed/options.json deleted file mode 100644 index 019532b4f9..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-computed/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["external-helpers"] -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-plain/expected.js b/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-plain/expected.js index d4274143b3..874b21c6b9 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-plain/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/method-plain/expected.js @@ -1,5 +1,5 @@ var obj = { - method: function method() { + method: function () { return 5 + 5; } }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/shorthand-comments/actual.js b/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/shorthand-comments/actual.js index a3cca2f02e..26d4bae5c9 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/shorthand-comments/actual.js +++ b/packages/babel-core/test/fixtures/transformation/es6.properties.shorthand/shorthand-comments/actual.js @@ -1,4 +1,4 @@ -const A = "a"; -const o = { +var A = "a"; +var o = { A // comment }; diff --git a/packages/babel-core/test/fixtures/transformation/es6.regex.sticky/options.json b/packages/babel-core/test/fixtures/transformation/es6.regex.sticky/options.json new file mode 100644 index 0000000000..b27ac458ff --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.regex.sticky/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-sticky-regex"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.regex.unicode/options.json b/packages/babel-core/test/fixtures/transformation/es6.regex.unicode/options.json new file mode 100644 index 0000000000..f52777ef8c --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es6.regex.unicode/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-unicode-regex"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/destructuring.js b/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/destructuring.js deleted file mode 100644 index bfc4f6e119..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/destructuring.js +++ /dev/null @@ -1,9 +0,0 @@ -function foo( - { x: { y: { z: a = b } = {}, w: b = 20 }, a: c = 30 } -) { - assert.equal(a, 10); - assert.equal(b, 20); - assert.equal(c, 30); -} - -foo({ x: {} }); diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/options.json b/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/options.json deleted file mode 100644 index 9bf3d7cd6e..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-fail/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "optional": "es6.spec.blockScoping", - "throws": "is not defined - temporal dead zone" -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/options.json b/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/options.json deleted file mode 100644 index 37caa06731..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.spec.block-scoping-pass/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "optional": "es6.spec.blockScoping" -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.symbols/options.json b/packages/babel-core/test/fixtures/transformation/es6.spec.symbols/options.json index fdf82aa75a..d3913eecfa 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.spec.symbols/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.spec.symbols/options.json @@ -1,4 +1,3 @@ { - "plugins": ["external-helpers"], - "optional": ["es6.spec.symbols"] + "plugins": ["external-helpers", "transform-es2015-typeof-symbol"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.spec.template-literals/options.json b/packages/babel-core/test/fixtures/transformation/es6.spec.template-literals/options.json index 1abc0c551a..f59495d3a0 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.spec.template-literals/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.spec.template-literals/options.json @@ -1,3 +1,3 @@ { - "optional": ["es6.spec.templateLiterals"] + "plugins": [["transform-es2015-template-literals", { "spec": true }]] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.spread/arguments-array/expected.js b/packages/babel-core/test/fixtures/transformation/es6.spread/arguments-array/expected.js index bfb6ca25d1..09da80138e 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.spread/arguments-array/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.spread/arguments-array/expected.js @@ -1,5 +1,5 @@ function foo() { - return bar([].concat(babelHelpers.slice.call(arguments))); + return bar([].concat(Array.prototype.slice.call(arguments))); } function bar(one, two, three) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.spread/arguments-concat/expected.js b/packages/babel-core/test/fixtures/transformation/es6.spread/arguments-concat/expected.js index 6fc41df2fc..ad88551bc6 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.spread/arguments-concat/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.spread/arguments-concat/expected.js @@ -1,5 +1,5 @@ function foo() { - return bar.apply(undefined, ["test"].concat(babelHelpers.slice.call(arguments))); + return bar.apply(undefined, ["test"].concat(Array.prototype.slice.call(arguments))); } function bar(one, two, three) { diff --git a/packages/babel-core/test/fixtures/transformation/es6.spread/new-expression/expected.js b/packages/babel-core/test/fixtures/transformation/es6.spread/new-expression/expected.js index af203c87d1..a1abd3d74d 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.spread/new-expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es6.spread/new-expression/expected.js @@ -1,2 +1,2 @@ -new (babelHelpers.bind.apply(Numbers, [null].concat(babelHelpers.toConsumableArray(nums))))(); -new (babelHelpers.bind.apply(Numbers, [null].concat([1], babelHelpers.toConsumableArray(nums))))(); +new (Function.prototype.bind.apply(Numbers, [null].concat(babelHelpers.toConsumableArray(nums))))(); +new (Function.prototype.bind.apply(Numbers, [null].concat([1], babelHelpers.toConsumableArray(nums))))(); diff --git a/packages/babel-core/test/fixtures/transformation/es6.spread/options.json b/packages/babel-core/test/fixtures/transformation/es6.spread/options.json index db29d06ec6..ec7023caa2 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.spread/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.spread/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers", "transform-es2015-spread"] + "plugins": ["external-helpers", "transform-es2015-spread", "transform-es2015-parameters"] } diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/call-apply/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/call-apply/actual.js deleted file mode 100755 index 9aefdea5cc..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/call-apply/actual.js +++ /dev/null @@ -1,8 +0,0 @@ -(function f(n) { - if (n <= 0) { - console.log(this, arguments); - return "foo"; - } - - return Math.random() > 0.5 ? f.call(this, n - 1) : f.apply(this, [n - 1]); -})(1e6) === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/call-apply/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/call-apply/expected.js deleted file mode 100755 index 3634614940..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/call-apply/expected.js +++ /dev/null @@ -1,26 +0,0 @@ -(function f(_x) { - var _this = this, - _arguments = arguments; - - var _again = true; - - _function: while (_again) { - var n = _x; - _again = false; - - if (n <= 0) { - console.log(_this, _arguments); - return "foo"; - } - - if (Math.random() > 0.5) { - _arguments = [_x = n - 1]; - _again = true; - continue _function; - } else { - _arguments = [_x = n - 1]; - _again = true; - continue _function; - } - } -})(1e6) === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/default-parameters/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/default-parameters/actual.js deleted file mode 100644 index 4322fa1e05..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/default-parameters/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -function sum(a=1, b=2) { - if (b > 0) { - return sum(a + 1, b - 1); - } - return a; -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/default-parameters/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/default-parameters/expected.js deleted file mode 100644 index f7f9998032..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/default-parameters/expected.js +++ /dev/null @@ -1,18 +0,0 @@ -function sum() { - var _arguments = arguments; - var _again = true; - - _function: while (_again) { - a = b = undefined; - var a = _arguments.length <= 0 || _arguments[0] === undefined ? 1 : _arguments[0]; - _again = false; - var b = _arguments.length <= 1 || _arguments[1] === undefined ? 2 : _arguments[1]; - - if (b > 0) { - _arguments = [a + 1, b - 1]; - _again = true; - continue _function; - } - return a; - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/expression-consequent/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/expression-consequent/actual.js deleted file mode 100644 index 0e0986168b..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/expression-consequent/actual.js +++ /dev/null @@ -1,4 +0,0 @@ -function f() { - if (true) {} - else return f() -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/expression-consequent/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/expression-consequent/expected.js deleted file mode 100644 index d31e15410c..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/expression-consequent/expected.js +++ /dev/null @@ -1,12 +0,0 @@ -function f() { - var _again = true; - - _function: while (_again) { - _again = false; - - if (true) {} else { - _again = true; - continue _function; - } - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/expressions/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/expressions/actual.js deleted file mode 100755 index 824fdf80d5..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/expressions/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -(function f(n) { - return n <= 0 ? "foo" : (doSmth(), getTrueValue() && (getFalseValue() || f(n - 1))); -})(1e6, true) === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/expressions/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/expressions/expected.js deleted file mode 100755 index 92a92ecf49..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/expressions/expected.js +++ /dev/null @@ -1,27 +0,0 @@ -(function f(_x) { - var _left; - - var _again = true; - - _function: while (_again) { - var n = _x; - _again = false; - if (n <= 0) { - return "foo"; - } else { - doSmth(); - - if (!(_left = getTrueValue())) { - return _left; - } - - if (_left = getFalseValue()) { - return _left; - } - - _x = n - 1; - _again = true; - continue _function; - } - } -})(1e6, true) === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/factorial/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/factorial/actual.js deleted file mode 100644 index 6078e67fda..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/factorial/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -function fact(n, acc = 1) { - return n > 1 ? fact(n - 1, acc * n) : acc; -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/factorial/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/factorial/expected.js deleted file mode 100644 index 456b29f725..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/factorial/expected.js +++ /dev/null @@ -1,18 +0,0 @@ -function fact(_x2) { - var _arguments = arguments; - var _again = true; - - _function: while (_again) { - var n = _x2; - acc = undefined; - _again = false; - var acc = _arguments.length <= 1 || _arguments[1] === undefined ? 1 : _arguments[1]; - if (n > 1) { - _arguments = [_x2 = n - 1, acc * n]; - _again = true; - continue _function; - } else { - return acc; - } - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/ignore-reassigned/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/ignore-reassigned/actual.js deleted file mode 100644 index cfb6182a00..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/ignore-reassigned/actual.js +++ /dev/null @@ -1,13 +0,0 @@ -// we need to deopt `test` if it's reassigned as we can't be certain of it's -// state, ie. it could have been rebound or dereferenced - -function test(exit) { - if (exit) { - return this.x; - } - return test(true); -} - -test = test.bind({ x: "yay" }); - -console.log(test()); diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/ignore-reassigned/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/ignore-reassigned/expected.js deleted file mode 100644 index cfb6182a00..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/ignore-reassigned/expected.js +++ /dev/null @@ -1,13 +0,0 @@ -// we need to deopt `test` if it's reassigned as we can't be certain of it's -// state, ie. it could have been rebound or dereferenced - -function test(exit) { - if (exit) { - return this.x; - } - return test(true); -} - -test = test.bind({ x: "yay" }); - -console.log(test()); diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/max-args/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/max-args/actual.js deleted file mode 100644 index f616841038..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/max-args/actual.js +++ /dev/null @@ -1,9 +0,0 @@ -var count = (i = 10) => { - if (!i) return; - return count(i - 1); -}; - -function count2(i = 10) { - if (!i) return; - return count2(i - 1); -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/max-args/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/max-args/expected.js deleted file mode 100644 index 30f534efc0..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/max-args/expected.js +++ /dev/null @@ -1,31 +0,0 @@ -var count = function count() { - var _arguments = arguments; - var _again = true; - - _function: while (_again) { - i = undefined; - _again = false; - var i = _arguments.length <= 0 || _arguments[0] === undefined ? 10 : _arguments[0]; - - if (!i) return; - _arguments = [i - 1]; - _again = true; - continue _function; - } -}; - -function count2() { - var _arguments2 = arguments; - var _again2 = true; - - _function2: while (_again2) { - i = undefined; - _again2 = false; - var i = _arguments2.length <= 0 || _arguments2[0] === undefined ? 10 : _arguments2[0]; - - if (!i) return; - _arguments2 = [i - 1]; - _again2 = true; - continue _function2; - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/parameter-exceeds/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/parameter-exceeds/actual.js deleted file mode 100644 index 1887c13c91..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/parameter-exceeds/actual.js +++ /dev/null @@ -1,15 +0,0 @@ -function foo(a, b) { - if (b) { - return foo(b); - } else { - return a; - } -} - -function foo(a, b) { - if (b) { - return foo("a", "b", "c"); - } else { - return a; - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/parameter-exceeds/exec.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/parameter-exceeds/exec.js deleted file mode 100644 index 5053794f69..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/parameter-exceeds/exec.js +++ /dev/null @@ -1,9 +0,0 @@ -function foo(a, b) { - if (b) { - return foo(b); - } else { - return a; - } -} - -assert.equal(foo("Michael", "Jackson"), "Jackson"); diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/parameter-exceeds/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/parameter-exceeds/expected.js deleted file mode 100644 index c0236f6b32..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/parameter-exceeds/expected.js +++ /dev/null @@ -1,26 +0,0 @@ -function foo(a, b) { - if (b) { - return foo(b); - } else { - return a; - } -} - -function foo(_x, _x2) { - var _again = true; - - _function: while (_again) { - var a = _x, - b = _x2; - _again = false; - - if (b) { - _x = "a"; - _x2 = "b"; - _again = true; - continue _function; - } else { - return a; - } - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/recursion/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/recursion/actual.js deleted file mode 100755 index 5f13765dd6..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/recursion/actual.js +++ /dev/null @@ -1,14 +0,0 @@ -(function f(n, m = getDefaultValue()) { - // `m` should be `getDefaultValue()` after first pass - if (n <= 0) { - return "foo"; - } - // `local1`-`local3` should be fresh on each pass - var local1; - let local2; - const local3 = 3; - // `g` should be function here on each pass - g = 123; - function g() {} - return f(n - 1); -})(1e6, true) === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/recursion/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/recursion/expected.js deleted file mode 100755 index 7ed702bc92..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/recursion/expected.js +++ /dev/null @@ -1,28 +0,0 @@ -(function f(_x2) { - var _arguments = arguments; - var _again = true; - - _function: while (_again) { - var n = _x2; - m = local1 = local2 = local3 = undefined; - - var g = function g() {}; - - _again = false; - var m = _arguments.length <= 1 || _arguments[1] === undefined ? getDefaultValue() : _arguments[1]; - - // `m` should be `getDefaultValue()` after first pass - if (n <= 0) { - return "foo"; - } - // `local1`-`local3` should be fresh on each pass - var local1; - var local2 = undefined; - var local3 = 3; - // `g` should be function here on each pass - g = 123; - _arguments = [_x2 = n - 1]; - _again = true; - continue _function; - } -})(1e6, true) === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/shadow/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/shadow/actual.js deleted file mode 100644 index 0b91223fe7..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/shadow/actual.js +++ /dev/null @@ -1,8 +0,0 @@ -(function(){ - var foo = () => { - this; - arguments; - return foo(); - }; - foo(); -}); diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/shadow/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/shadow/expected.js deleted file mode 100644 index 2417064bb7..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/shadow/expected.js +++ /dev/null @@ -1,18 +0,0 @@ -(function () { - var _this = this, - _arguments2 = arguments; - - var foo = function foo() { - var _again = true; - - _function: while (_again) { - _again = false; - - _this; - _arguments2; - _again = true; - continue _function; - } - }; - foo(); -}); diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/try-catch/actual.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/try-catch/actual.js deleted file mode 100755 index 654f4ce709..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/try-catch/actual.js +++ /dev/null @@ -1,43 +0,0 @@ -(function f(n) { - if (n <= 0) { - return "foo"; - } - - try { - return f(n - 1); - } catch (e) {} -})(1e6) === "foo"; - -(function f(n) { - if (n <= 0) { - return "foo"; - } - - try { - throw new Error(); - } catch (e) { - return f(n - 1); - } -})(1e6) === "foo"; - -(function f(n) { - if (n <= 0) { - return "foo"; - } - - try { - throw new Error(); - } catch (e) { - return f(n - 1); - } finally {} -})(1e6) === "foo"; - -(function f(n) { - if (n <= 0) { - return "foo"; - } - - try {} finally { - return f(n - 1); - } -})(1e6) === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.tail-call/try-catch/expected.js b/packages/babel-core/test/fixtures/transformation/es6.tail-call/try-catch/expected.js deleted file mode 100755 index 2602d65a55..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es6.tail-call/try-catch/expected.js +++ /dev/null @@ -1,61 +0,0 @@ -(function f(n) { - if (n <= 0) { - return "foo"; - } - - try { - return f(n - 1); - } catch (e) {} -})(1e6) === "foo"; - -(function f(_x) { - var _again = true; - - _function: while (_again) { - var n = _x; - _again = false; - - if (n <= 0) { - return "foo"; - } - - try { - throw new Error(); - } catch (e) { - _x = n - 1; - _again = true; - continue _function; - } - } -})(1e6) === "foo"; - -(function f(n) { - if (n <= 0) { - return "foo"; - } - - try { - throw new Error(); - } catch (e) { - return f(n - 1); - } finally {} -})(1e6) === "foo"; - -(function f(_x2) { - var _again2 = true; - - _function2: while (_again2) { - var n = _x2; - _again2 = false; - - if (n <= 0) { - return "foo"; - } - - try {} finally { - _x2 = n - 1; - _again2 = true; - continue _function2; - } - } -})(1e6) === "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es6.template-literals/tag-loose/options.json b/packages/babel-core/test/fixtures/transformation/es6.template-literals/tag-loose/options.json index 8b5e72ecbe..434ba0caa6 100644 --- a/packages/babel-core/test/fixtures/transformation/es6.template-literals/tag-loose/options.json +++ b/packages/babel-core/test/fixtures/transformation/es6.template-literals/tag-loose/options.json @@ -1,3 +1,3 @@ { - "loose": ["es6.templateLiterals"] + "plugins": [["transform-es2015-template-literals", { "loose": true }]] } diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration-exec/exec.js b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration-exec/exec.js new file mode 100644 index 0000000000..6141a3f65e --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration-exec/exec.js @@ -0,0 +1,12 @@ +class Foo { + constructor() { + this.num = 1; + } + + call constructor() { + return { num: 2 }; + } +} + +assert.equal(new Foo().num, 1); +assert.equal(Foo().num, 2); diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration-exec/options.json b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration-exec/options.json new file mode 100644 index 0000000000..37e52d209d --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration-exec/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-class-constructor-call", "transform-es2015-classes", "transform-es2015-block-scoping", "transform-es2015-parameters"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration/actual.js b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration/actual.js new file mode 100644 index 0000000000..1f8b64ef4a --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration/actual.js @@ -0,0 +1,5 @@ +class Foo { + call constructor() { + foo(); + } +} diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration/expected.js b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration/expected.js new file mode 100644 index 0000000000..32e55b668f --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/declaration/expected.js @@ -0,0 +1,16 @@ +let _Foo = class Foo {}; + +var _FooCall = function () { + foo(); +}; + +var Foo = function (...args) { + if (this instanceof Foo) { + return Reflect.construct(_Foo, args); + } else { + return _FooCall.apply(this, args); + } +}; + +Foo.__proto__ = _Foo; +Foo; diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-completion-record/actual.js b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-completion-record/actual.js new file mode 100644 index 0000000000..0663cd8a88 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-completion-record/actual.js @@ -0,0 +1,5 @@ +(class { + call constructor() { + foo(); + } +}); diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-completion-record/expected.js b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-completion-record/expected.js new file mode 100644 index 0000000000..5bedc84e65 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-completion-record/expected.js @@ -0,0 +1,16 @@ +let _class2 = class {}; + +var _classCall = function () { + foo(); +}; + +var _class = function (...args) { + if (this instanceof _class) { + return Reflect.construct(_class2, args); + } else { + return _classCall.apply(this, args); + } +}; + +_class.__proto__ = _class2; +_class; diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-exec/exec.js b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-exec/exec.js new file mode 100644 index 0000000000..c276e23ab3 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-exec/exec.js @@ -0,0 +1,12 @@ +let Foo = class { + constructor() { + this.num = 1; + } + + call constructor() { + return { num: 2 }; + } +}; + +assert.equal(new Foo().num, 1); +assert.equal(Foo().num, 2); diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-exec/options.json b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-exec/options.json new file mode 100644 index 0000000000..37e52d209d --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression-exec/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-class-constructor-call", "transform-es2015-classes", "transform-es2015-block-scoping", "transform-es2015-parameters"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression/actual.js b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression/actual.js new file mode 100644 index 0000000000..0da72faf45 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression/actual.js @@ -0,0 +1,5 @@ +let Foo = class { + call constructor() { + foo(); + } +}; diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression/expected.js b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression/expected.js new file mode 100644 index 0000000000..07daf3dee2 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/expression/expected.js @@ -0,0 +1,18 @@ +let Foo = (function () { + let _class2 = class {}; + + var _classCall = function () { + foo(); + }; + + var _class = function (...args) { + if (this instanceof _class) { + return Reflect.construct(_class2, args); + } else { + return _classCall.apply(this, args); + } + }; + + _class.__proto__ = _class2; + return _class; +})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/options.json b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/options.json new file mode 100644 index 0000000000..98dd15ca98 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.class-constructor-call/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-class-constructor-call"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-properties/constructor-collision/expected.js b/packages/babel-core/test/fixtures/transformation/es7.class-properties/constructor-collision/expected.js index 3c4da0c5ac..12af37359c 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.class-properties/constructor-collision/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.class-properties/constructor-collision/expected.js @@ -1,19 +1,13 @@ var foo = "bar"; -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); +var Foo = function Foo() { + babelHelpers.classCallCheck(this, Foo); - this.__initializeProperties(); + _initialiseProps.call(this); - var foo = "foo"; - } + var foo = "foo"; +}; - babelHelpers.createClass(Foo, [{ - key: "__initializeProperties", - value: function __initializeProperties() { - this.bar = foo; - } - }]); - return Foo; -})(); +var _initialiseProps = function () { + this.bar = foo; +}; diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-properties/derived/expected.js b/packages/babel-core/test/fixtures/transformation/es7.class-properties/derived/expected.js index 04ad4dc07d..09a524f94c 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.class-properties/derived/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.class-properties/derived/expected.js @@ -1,10 +1,11 @@ var Foo = (function (_Bar) { babelHelpers.inherits(Foo, _Bar); - function Foo() { + function Foo(...args) { + var _temp, _this; + babelHelpers.classCallCheck(this, Foo); - babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments); - this.bar = "foo"; + return babelHelpers.possibleConstructorReturn(_this, (_temp = (_this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this, ...args)), _this), _this.bar = "foo", _temp)); } return Foo; diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-properties/method-collision/actual.js b/packages/babel-core/test/fixtures/transformation/es7.class-properties/method-collision/actual.js deleted file mode 100644 index a713784501..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.class-properties/method-collision/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -class Foo { - __initializeProperties() { - - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-properties/method-collision/options.json b/packages/babel-core/test/fixtures/transformation/es7.class-properties/method-collision/options.json deleted file mode 100644 index ce3c3be3a2..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.class-properties/method-collision/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Illegal method name \"__initializeProperties\"" -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-properties/options.json b/packages/babel-core/test/fixtures/transformation/es7.class-properties/options.json index c4fd4ec0e4..1e03c15d4c 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.class-properties/options.json +++ b/packages/babel-core/test/fixtures/transformation/es7.class-properties/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers", "transform-class-properties"] + "plugins": ["external-helpers", "transform-class-properties", "transform-es2015-classes", "transform-es2015-block-scoping", "syntax-class-properties"] } diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-properties/static/expected.js b/packages/babel-core/test/fixtures/transformation/es7.class-properties/static/expected.js index 2d68553c98..4d0c09379d 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.class-properties/static/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.class-properties/static/expected.js @@ -1,12 +1,5 @@ -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } +var Foo = function Foo() { + babelHelpers.classCallCheck(this, Foo); +}; - babelHelpers.createClass(Foo, null, [{ - key: "bar", - value: "foo", - enumerable: true - }]); - return Foo; -})(); +Foo.bar = "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-properties/super-expression/expected.js b/packages/babel-core/test/fixtures/transformation/es7.class-properties/super-expression/expected.js index e4eb6240d8..7eab2b7172 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.class-properties/super-expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.class-properties/super-expression/expected.js @@ -2,11 +2,12 @@ var Foo = (function (_Bar) { babelHelpers.inherits(Foo, _Bar); function Foo() { - var _temp; + var _temp, _this; babelHelpers.classCallCheck(this, Foo); - foo((_temp = babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this), this.bar = "foo", _temp)); + foo((_temp = (_this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this)), _this), _this.bar = "foo", _temp)); + return _this; } return Foo; diff --git a/packages/babel-core/test/fixtures/transformation/es7.class-properties/super-statement/expected.js b/packages/babel-core/test/fixtures/transformation/es7.class-properties/super-statement/expected.js index 35b94e660a..fa87f118f1 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.class-properties/super-statement/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.class-properties/super-statement/expected.js @@ -4,8 +4,10 @@ var Foo = (function (_Bar) { function Foo() { babelHelpers.classCallCheck(this, Foo); - babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this); - this.bar = "foo"; + var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this)); + + _this.bar = "foo"; + return _this; } return Foo; diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/arguments/actual.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/arguments/actual.js deleted file mode 100644 index 5b07664e61..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/arguments/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -function add() { - return [for (i of nums) i * arguments[0]]; -} - -add(5); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/arguments/expected.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/arguments/expected.js deleted file mode 100644 index f02ad56b61..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/arguments/expected.js +++ /dev/null @@ -1,35 +0,0 @@ -function add() { - var _arguments = arguments; - - return (function () { - var _ref = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = nums[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var i = _step.value; - - _ref.push(i * _arguments[0]); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return _ref; - })(); -} - -add(5); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single-if/actual.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single-if/actual.js deleted file mode 100644 index 4882336b9f..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single-if/actual.js +++ /dev/null @@ -1 +0,0 @@ -var arr = [for (i of [1, 2, 3]) if (i > 1) i * i]; diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single-if/expected.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single-if/expected.js deleted file mode 100644 index 8bcbe9767d..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single-if/expected.js +++ /dev/null @@ -1,14 +0,0 @@ -var arr = (function () { - var _arr = []; - var _arr2 = [1, 2, 3]; - - for (var _i = 0; _i < _arr2.length; _i++) { - var i = _arr2[_i]; - - if (i > 1) { - _arr.push(i * i); - } - } - - return _arr; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single/actual.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single/actual.js deleted file mode 100644 index 2087ae351b..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single/actual.js +++ /dev/null @@ -1 +0,0 @@ -var arr = [for (i of [1, 2, 3]) i * i]; diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single/expected.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single/expected.js deleted file mode 100644 index b26a15eadd..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-expression-single/expected.js +++ /dev/null @@ -1,12 +0,0 @@ -var arr = (function () { - var _arr = []; - var _arr2 = [1, 2, 3]; - - for (var _i = 0; _i < _arr2.length; _i++) { - var i = _arr2[_i]; - - _arr.push(i * i); - } - - return _arr; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple-if/actual.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple-if/actual.js deleted file mode 100644 index 754bb7e894..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple-if/actual.js +++ /dev/null @@ -1 +0,0 @@ -var seattlers = [for (customers of countries) for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]; diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple-if/expected.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple-if/expected.js deleted file mode 100644 index 7036c1a738..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple-if/expected.js +++ /dev/null @@ -1,53 +0,0 @@ -var seattlers = (function () { - var _seattlers = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = countries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var customers = _step.value; - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = customers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var c = _step2.value; - - if (c.city == "Seattle") { - _seattlers.push({ name: c.name, age: c.age }); - } - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return _seattlers; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple/actual.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple/actual.js deleted file mode 100644 index f0aaa63c27..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple/actual.js +++ /dev/null @@ -1 +0,0 @@ -var arr = [for (x of "abcdefgh".split("")) for (y of "12345678".split("")) x + y]; diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple/expected.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple/expected.js deleted file mode 100644 index 73311444e9..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-multiple/expected.js +++ /dev/null @@ -1,51 +0,0 @@ -var arr = (function () { - var _arr = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = "abcdefgh".split("")[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var x = _step.value; - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = "12345678".split("")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var y = _step2.value; - - _arr.push(x + y); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2["return"]) { - _iterator2["return"](); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return _arr; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single-if/actual.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single-if/actual.js deleted file mode 100644 index e2cf129386..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single-if/actual.js +++ /dev/null @@ -1 +0,0 @@ -var arr = [for (i of nums) if (i > 1) i * i]; diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single-if/expected.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single-if/expected.js deleted file mode 100644 index 4d4bc5e399..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single-if/expected.js +++ /dev/null @@ -1,31 +0,0 @@ -var arr = (function () { - var _arr = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = nums[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var i = _step.value; - - if (i > 1) { - _arr.push(i * i); - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return _arr; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single/actual.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single/actual.js deleted file mode 100644 index 9dda19048b..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single/actual.js +++ /dev/null @@ -1 +0,0 @@ -var arr = [for (i of nums) i * i]; diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single/expected.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single/expected.js deleted file mode 100644 index 70fa294f4f..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-single/expected.js +++ /dev/null @@ -1,29 +0,0 @@ -var arr = (function () { - var _arr = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = nums[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var i = _step.value; - - _arr.push(i * i); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return _arr; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-this/actual.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-this/actual.js deleted file mode 100644 index 5ae580c2d3..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-this/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -function add() { - return [for (i of nums) i * this.multiplier]; -} - -add.call({ multiplier: 5 }); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-this/expected.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-this/expected.js deleted file mode 100644 index c207994ede..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/array-this/expected.js +++ /dev/null @@ -1,35 +0,0 @@ -function add() { - var _this = this; - - return (function () { - var _ref = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = nums[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var i = _step.value; - - _ref.push(i * _this.multiplier); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return _ref; - })(); -} - -add.call({ multiplier: 5 }); diff --git a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/generator/exec.js b/packages/babel-core/test/fixtures/transformation/es7.comprehensions/generator/exec.js deleted file mode 100644 index dd7ef4da0a..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.comprehensions/generator/exec.js +++ /dev/null @@ -1,6 +0,0 @@ -var nums = [1, 2, 3, 4, 5, 6]; -var multiples = (for (i of nums) if (i % 2) i * i); -assert.equal(multiples.next().value, 1); -assert.equal(multiples.next().value, 9); -assert.equal(multiples.next().value, 25); -assert.ok(multiples.next().done); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter-and-setter/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter-and-setter/actual.js deleted file mode 100644 index b0262c5699..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter-and-setter/actual.js +++ /dev/null @@ -1,11 +0,0 @@ -class Foo { - @bar - get foo() { - - } - - @foo - set foo(bar) { - - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter-and-setter/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter-and-setter/expected.js deleted file mode 100644 index 590dba750a..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter-and-setter/expected.js +++ /dev/null @@ -1,13 +0,0 @@ -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } - - babelHelpers.createDecoratedClass(Foo, [{ - key: "foo", - decorators: [bar, foo], - get: function get() {}, - set: function set(bar) {} - }]); - return Foo; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter/actual.js deleted file mode 100644 index c09d8bfaf2..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -class Foo { - @bar - get foo() { - - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter/expected.js deleted file mode 100644 index f1ab0064a3..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-getter/expected.js +++ /dev/null @@ -1,12 +0,0 @@ -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } - - babelHelpers.createDecoratedClass(Foo, [{ - key: "foo", - decorators: [bar], - get: function get() {} - }]); - return Foo; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-instance-props/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-instance-props/actual.js deleted file mode 100644 index 24d63020fd..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-instance-props/actual.js +++ /dev/null @@ -1,4 +0,0 @@ -class Foo { - @bar - foo = "Bar"; -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-instance-props/exec.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-instance-props/exec.js deleted file mode 100644 index 03b00b8175..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-instance-props/exec.js +++ /dev/null @@ -1,14 +0,0 @@ -function noop() {} - -class Foo { - @noop - bar = "foobar"; - - @noop - foo() { - return "bar"; - } -} - -assert.equal(new Foo().bar, "foobar"); -assert.equal(new Foo().foo(), "bar"); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-instance-props/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-instance-props/expected.js deleted file mode 100644 index 1160ef3561..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-instance-props/expected.js +++ /dev/null @@ -1,18 +0,0 @@ -var Foo = (function () { - var _instanceInitializers = {}; - - function Foo() { - babelHelpers.classCallCheck(this, Foo); - babelHelpers.defineDecoratedPropertyDescriptor(this, "foo", _instanceInitializers); - } - - babelHelpers.createDecoratedClass(Foo, [{ - key: "foo", - decorators: [bar], - initializer: function initializer() { - return "Bar"; - }, - enumerable: true - }], null, _instanceInitializers); - return Foo; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-static-props/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-static-props/actual.js deleted file mode 100644 index 50ba1a8f7d..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-static-props/actual.js +++ /dev/null @@ -1,4 +0,0 @@ -class Foo { - @bar - static foo = "Bar"; -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-static-props/exec.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-static-props/exec.js deleted file mode 100644 index a343d78640..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-static-props/exec.js +++ /dev/null @@ -1,14 +0,0 @@ -function noop() {} - -class Foo { - @noop - static bar = "foobar"; - - @noop - static foo() { - return "bar"; - } -} - -assert.equal(Foo.bar, "foobar"); -assert.equal(Foo.foo(), "bar"); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-static-props/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-static-props/expected.js deleted file mode 100644 index 029d2e94d3..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-init-static-props/expected.js +++ /dev/null @@ -1,18 +0,0 @@ -var Foo = (function () { - var _staticInitializers = {}; - - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } - - babelHelpers.createDecoratedClass(Foo, null, [{ - key: "foo", - decorators: [bar], - initializer: function initializer() { - return "Bar"; - }, - enumerable: true - }], null, _staticInitializers); - babelHelpers.defineDecoratedPropertyDescriptor(Foo, "foo", _staticInitializers); - return Foo; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-method/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-method/actual.js deleted file mode 100644 index b2f8e63381..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-method/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -class Foo { - @bar - foo() { - - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-method/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-method/expected.js deleted file mode 100644 index 152db01c9d..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-method/expected.js +++ /dev/null @@ -1,12 +0,0 @@ -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } - - babelHelpers.createDecoratedClass(Foo, [{ - key: "foo", - decorators: [bar], - value: function foo() {} - }]); - return Foo; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-modules/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-modules/actual.js deleted file mode 100644 index 61173aa9a9..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-modules/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -import foo from "foo"; - -@foo -export default class Foo { - -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-modules/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-modules/expected.js deleted file mode 100644 index 0ea1e37433..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-modules/expected.js +++ /dev/null @@ -1,20 +0,0 @@ -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _foo = require("foo"); - -var _foo2 = babelHelpers.interopRequireDefault(_foo); - -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, _Foo); - } - - var _Foo = Foo; - Foo = (0, _foo2["default"])(Foo) || Foo; - return Foo; -})(); - -exports["default"] = Foo; -module.exports = exports["default"]; diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-instance-props/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-instance-props/actual.js deleted file mode 100644 index c739a74257..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-instance-props/actual.js +++ /dev/null @@ -1,4 +0,0 @@ -class Foo { - @bar - foo; -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-instance-props/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-instance-props/expected.js deleted file mode 100644 index 939e4d245d..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-instance-props/expected.js +++ /dev/null @@ -1,16 +0,0 @@ -var Foo = (function () { - var _instanceInitializers = {}; - - function Foo() { - babelHelpers.classCallCheck(this, Foo); - babelHelpers.defineDecoratedPropertyDescriptor(this, "foo", _instanceInitializers); - } - - babelHelpers.createDecoratedClass(Foo, [{ - key: "foo", - decorators: [bar], - initializer: null, - enumerable: true - }], null, _instanceInitializers); - return Foo; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-static-props/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-static-props/actual.js deleted file mode 100644 index 45fe716ac4..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-static-props/actual.js +++ /dev/null @@ -1,4 +0,0 @@ -class Foo { - @bar - static foo; -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-static-props/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-static-props/expected.js deleted file mode 100644 index 641c2a3e49..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-no-init-static-props/expected.js +++ /dev/null @@ -1,16 +0,0 @@ -var Foo = (function () { - var _staticInitializers = {}; - - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } - - babelHelpers.createDecoratedClass(Foo, null, [{ - key: "foo", - decorators: [bar], - initializer: null, - enumerable: true - }], null, _staticInitializers); - babelHelpers.defineDecoratedPropertyDescriptor(Foo, "foo", _staticInitializers); - return Foo; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-setter/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-setter/actual.js deleted file mode 100644 index db86413764..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-setter/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -class Foo { - @bar - set foo(arg) { - - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-setter/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-setter/expected.js deleted file mode 100644 index a7ddb37b63..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-setter/expected.js +++ /dev/null @@ -1,12 +0,0 @@ -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, Foo); - } - - babelHelpers.createDecoratedClass(Foo, [{ - key: "foo", - decorators: [bar], - set: function set(arg) {} - }]); - return Foo; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-super/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-super/actual.js deleted file mode 100644 index 14770c1129..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-super/actual.js +++ /dev/null @@ -1,12 +0,0 @@ -@bar -class Foo extends Bar { - constructor() { - super(); - } -} - -var Foo2 = @bar class extends Bar { - constructor() { - super(); - } -}; diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-super/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class-super/expected.js deleted file mode 100644 index 0a55813a3f..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class-super/expected.js +++ /dev/null @@ -1,27 +0,0 @@ -var Foo = (function (_Bar) { - babelHelpers.inherits(Foo, _Bar); - - function Foo() { - babelHelpers.classCallCheck(this, _Foo); - - babelHelpers.get(Object.getPrototypeOf(_Foo.prototype), "constructor", this).call(this); - } - - var _Foo = Foo; - Foo = bar(Foo) || Foo; - return Foo; -})(Bar); - -var Foo2 = (function (_Bar2) { - babelHelpers.inherits(Foo2, _Bar2); - - function Foo2() { - babelHelpers.classCallCheck(this, _Foo2); - - babelHelpers.get(Object.getPrototypeOf(_Foo2.prototype), "constructor", this).call(this); - } - - var _Foo2 = Foo2; - Foo2 = bar(Foo2) || Foo2; - return Foo2; -})(Bar); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class/actual.js deleted file mode 100644 index 96ced15a45..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class/actual.js +++ /dev/null @@ -1,21 +0,0 @@ -@foo -class Foo {} - -@foo -@bar -class Bar {} - -var Foo2 = @bar class Foo { - -}; - -var Bar2 = @foo @bar class Bar { - -}; - -@foo -class Baz{ - constructor(baz) { - this.baz = baz; - } -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/class/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/class/expected.js deleted file mode 100644 index ced98e9835..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/class/expected.js +++ /dev/null @@ -1,53 +0,0 @@ -var Foo = (function () { - function Foo() { - babelHelpers.classCallCheck(this, _Foo); - } - - var _Foo = Foo; - Foo = foo(Foo) || Foo; - return Foo; -})(); - -var Bar = (function () { - function Bar() { - babelHelpers.classCallCheck(this, _Bar); - } - - var _Bar = Bar; - Bar = bar(Bar) || Bar; - Bar = foo(Bar) || Bar; - return Bar; -})(); - -var Foo2 = (function () { - function Foo() { - babelHelpers.classCallCheck(this, _Foo2); - } - - var _Foo2 = Foo; - Foo = bar(Foo) || Foo; - return Foo; -})(); - -var Bar2 = (function () { - function Bar() { - babelHelpers.classCallCheck(this, _Bar2); - } - - var _Bar2 = Bar; - Bar = bar(Bar) || Bar; - Bar = foo(Bar) || Bar; - return Bar; -})(); - -var Baz = (function () { - function Baz(baz) { - babelHelpers.classCallCheck(this, _Baz); - - this.baz = baz; - } - - var _Baz = Baz; - Baz = foo(Baz) || Baz; - return Baz; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/exec-class-method-autobind/exec-object-method-autobind.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/exec-class-method-autobind/exec-object-method-autobind.js deleted file mode 100644 index 01cdde6e01..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/exec-class-method-autobind/exec-object-method-autobind.js +++ /dev/null @@ -1,20 +0,0 @@ -var autobind = function (target, name, descriptor) { - var fn = descriptor.value; - delete descriptor.value; - delete descriptor.writable; - descriptor.get = function () { - return fn.bind(this); - }; -}; - -var person = { - first: "Sebastian", - last: "McKenzie", - - @autobind - getName() { - return `${this.first} ${this.last}`; - } -} - -assert.equal(person.getName.call(null), "Sebastian McKenzie") diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/exec-class-method-autobind/exec.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/exec-class-method-autobind/exec.js deleted file mode 100644 index 64b7e2df45..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/exec-class-method-autobind/exec.js +++ /dev/null @@ -1,22 +0,0 @@ -var autobind = function (target, name, descriptor) { - var fn = descriptor.value; - delete descriptor.value; - delete descriptor.writable; - descriptor.get = function () { - return fn.bind(this); - }; -}; - -class Person { - constructor() { - this.first = "Sebastian"; - this.last = "McKenzie"; - } - - @autobind - getName() { - return `${this.first} ${this.last}`; - } -} - -assert.equal(new Person().getName.call(null), "Sebastian McKenzie") diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/member-expressions/exec.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/member-expressions/exec.js deleted file mode 100644 index 81bc4716a4..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/member-expressions/exec.js +++ /dev/null @@ -1,18 +0,0 @@ -var foo = { - bar: function () { assert.equal(this, foo); }, - foobar: { - bar: function () { assert.equal(this, foo.foobar); }, - } -}; - -(class { - @foo.bar - @foo.foobar.bar - bar() {} -}); - -({ - @foo.bar - @foo.foobar.bar - bar() {} -}); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter-and-setter/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter-and-setter/actual.js deleted file mode 100644 index 37a0b6a98f..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter-and-setter/actual.js +++ /dev/null @@ -1,11 +0,0 @@ -var obj = { - @foo - get foo() { - - }, - - @foo - set foo(bar) { - - } -}; diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter-and-setter/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter-and-setter/expected.js deleted file mode 100644 index 8f48c08081..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter-and-setter/expected.js +++ /dev/null @@ -1,6 +0,0 @@ -var obj = babelHelpers.createDecoratedObject([{ - key: "foo", - decorators: [foo, foo], - get: function get() {}, - set: function set(bar) {} -}]); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter/actual.js deleted file mode 100644 index 632f156498..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -var obj = { - @foo - get foo() { - - } -}; diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter/expected.js deleted file mode 100644 index f75059b079..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-getter/expected.js +++ /dev/null @@ -1,5 +0,0 @@ -var obj = babelHelpers.createDecoratedObject([{ - key: "foo", - decorators: [foo], - get: function get() {} -}]); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-setter/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/object-setter/actual.js deleted file mode 100644 index 52eb95db88..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-setter/actual.js +++ /dev/null @@ -1,6 +0,0 @@ -var obj = { - @foo - set foo(bar) { - - } -}; diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-setter/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/object-setter/expected.js deleted file mode 100644 index 4ad8956247..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/object-setter/expected.js +++ /dev/null @@ -1,5 +0,0 @@ -var obj = babelHelpers.createDecoratedObject([{ - key: "foo", - decorators: [foo], - set: function set(bar) {} -}]); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/object/actual.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/object/actual.js deleted file mode 100644 index 16a6041b30..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/object/actual.js +++ /dev/null @@ -1,9 +0,0 @@ -var obj = { - @foo - bar() {}, - - @bar - foo: "lol", - - yes: "wow" -}; diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/object/exec.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/object/exec.js deleted file mode 100644 index 6868020f23..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/object/exec.js +++ /dev/null @@ -1,15 +0,0 @@ -function override(target, key, descriptor) { - descriptor.initializer = function () { - return "lol"; - }; -} - -var obj = { - @override - foo: "bar", - - bar: "heh" -}; - -assert.equal(obj.foo, "lol"); -assert.equal(obj.bar, "heh"); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/object/expected.js b/packages/babel-core/test/fixtures/transformation/es7.decorators/object/expected.js deleted file mode 100644 index 0f5ebb8d1f..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/object/expected.js +++ /dev/null @@ -1,16 +0,0 @@ -var obj = babelHelpers.createDecoratedObject([{ - key: "bar", - decorators: [foo], - value: function bar() {} -}, { - key: "foo", - decorators: [bar], - initializer: function initializer() { - return "lol"; - } -}, { - key: "yes", - initializer: function initializer() { - return "wow"; - } -}]); diff --git a/packages/babel-core/test/fixtures/transformation/es7.decorators/options.json b/packages/babel-core/test/fixtures/transformation/es7.decorators/options.json deleted file mode 100644 index d241add8f9..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.decorators/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["external-helpers", "transform-decorators", "transform-class-properties"] -} diff --git a/packages/babel-core/test/fixtures/transformation/es7.exponentian-operator/memoise-object/exec.js b/packages/babel-core/test/fixtures/transformation/es7.exponentian-operator/memoise-object/exec.js new file mode 100644 index 0000000000..140551313e --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.exponentian-operator/memoise-object/exec.js @@ -0,0 +1,10 @@ +var counters = 0; +Object.defineProperty(global, "reader", { + get() { + counters += 1; + return { x: 2 }; + }, + configurable: true +}); +reader.x **= 2; +assert.ok(counters === 1); diff --git a/packages/babel-core/test/fixtures/transformation/es7.exponentian-operator/options.json b/packages/babel-core/test/fixtures/transformation/es7.exponentian-operator/options.json new file mode 100644 index 0000000000..a6b3a4360b --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.exponentian-operator/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-exponentiation-operator"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/default-commonjs/actual.js b/packages/babel-core/test/fixtures/transformation/es7.export-extensions/default-commonjs/actual.js deleted file mode 100644 index 48783b0466..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/default-commonjs/actual.js +++ /dev/null @@ -1 +0,0 @@ -export foo from "bar"; diff --git a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/default-commonjs/expected.js b/packages/babel-core/test/fixtures/transformation/es7.export-extensions/default-commonjs/expected.js deleted file mode 100644 index c704c59cb1..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/default-commonjs/expected.js +++ /dev/null @@ -1,9 +0,0 @@ -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _bar = require("bar"); - -var _bar2 = babelHelpers.interopRequireDefault(_bar); - -exports.foo = _bar2["default"]; diff --git a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/namespace-commonjs/actual.js b/packages/babel-core/test/fixtures/transformation/es7.export-extensions/namespace-commonjs/actual.js deleted file mode 100644 index d9d78f9ccd..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/namespace-commonjs/actual.js +++ /dev/null @@ -1 +0,0 @@ -export * as foo from "bar"; diff --git a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/namespace-commonjs/expected.js b/packages/babel-core/test/fixtures/transformation/es7.export-extensions/namespace-commonjs/expected.js deleted file mode 100644 index 00001a04dc..0000000000 --- a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/namespace-commonjs/expected.js +++ /dev/null @@ -1,9 +0,0 @@ -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _bar = require("bar"); - -var _foo = babelHelpers.interopRequireWildcard(_bar); - -exports.foo = _foo; diff --git a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/options.json b/packages/babel-core/test/fixtures/transformation/es7.export-extensions/options.json index 1ecf20e277..26dfe134f4 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.export-extensions/options.json +++ b/packages/babel-core/test/fixtures/transformation/es7.export-extensions/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers", "export-extensions"] + "plugins": ["external-helpers", "transform-export-extensions"] } diff --git a/packages/babel-core/test/fixtures/transformation/es7.function-bind/complex-call/exec.js b/packages/babel-core/test/fixtures/transformation/es7.function-bind/complex-call/exec.js index 5ee5f3f7d7..93ea455420 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.function-bind/complex-call/exec.js +++ b/packages/babel-core/test/fixtures/transformation/es7.function-bind/complex-call/exec.js @@ -2,15 +2,17 @@ var operations = []; var lib = {}; -for (let key of ['f', 'g', 'h']) { - let func = () => operations.push(`lib.${key}()`); +['f', 'g', 'h'].forEach(function (key) { + var func = function () { + return operations.push("lib." + key + "()"); + }; Object.defineProperty(lib, key, { - get() { - operations.push(`get lib.${key}`); + get: function () { + operations.push("get lib." + key); return func; } }); -} +}); ({prop:'value'}) ::lib.f() diff --git a/packages/babel-core/test/fixtures/transformation/es7.function-bind/complex-call/expected.js b/packages/babel-core/test/fixtures/transformation/es7.function-bind/complex-call/expected.js index f0178f069e..3a7acc97d3 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.function-bind/complex-call/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.function-bind/complex-call/expected.js @@ -1,11 +1,11 @@ var _context; -var _iterlib = require("iterlib"); +import { map, takeWhile, forEach } from "iterlib"; -(_context = (_context = (_context = getPlayers(), _iterlib.map).call(_context, function (x) { +(_context = (_context = (_context = getPlayers(), map).call(_context, function (x) { return x.character(); -}), _iterlib.takeWhile).call(_context, function (x) { +}), takeWhile).call(_context, function (x) { return x.strength > 100; -}), _iterlib.forEach).call(_context, function (x) { +}), forEach).call(_context, function (x) { return console.log(x); }); diff --git a/packages/babel-core/test/fixtures/transformation/es7.function-bind/options.json b/packages/babel-core/test/fixtures/transformation/es7.function-bind/options.json index 6661827d54..aa1fdfe370 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.function-bind/options.json +++ b/packages/babel-core/test/fixtures/transformation/es7.function-bind/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-function-bind"] + "plugins": ["transform-function-bind", "transform-es2015-arrow-functions"] } diff --git a/packages/babel-core/test/fixtures/transformation/es7.function-bind/static-contexts/expected.js b/packages/babel-core/test/fixtures/transformation/es7.function-bind/static-contexts/expected.js index 0a23379d35..191e73ffb8 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.function-bind/static-contexts/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.function-bind/static-contexts/expected.js @@ -1,4 +1,4 @@ -var bar = function bar() {}; +var bar = function () {}; bar.bind(foo); var foo = {}; diff --git a/packages/babel-core/test/fixtures/transformation/es7.object-spread/assignment/expected.js b/packages/babel-core/test/fixtures/transformation/es7.object-spread/assignment/expected.js index 8d12badcab..5e42763fce 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.object-spread/assignment/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.object-spread/assignment/expected.js @@ -1,3 +1,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; -z = _extends({ x: x }, y); +z = _extends({ x }, y); diff --git a/packages/babel-core/test/fixtures/transformation/es7.object-spread/expression/expected.js b/packages/babel-core/test/fixtures/transformation/es7.object-spread/expression/expected.js index 4851fe7dfc..b7f307cb75 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.object-spread/expression/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.object-spread/expression/expected.js @@ -1,3 +1,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; -_extends({ x: x }, y, { a: a }, b, { c: c }); +_extends({ x }, y, { a }, b, { c }); diff --git a/packages/babel-core/test/fixtures/transformation/es7.object-spread/options.json b/packages/babel-core/test/fixtures/transformation/es7.object-spread/options.json new file mode 100644 index 0000000000..85af630bdd --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/es7.object-spread/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-object-rest-spread"] +} diff --git a/packages/babel-core/test/fixtures/transformation/es7.trailing-function-commas/arrow-function/expected.js b/packages/babel-core/test/fixtures/transformation/es7.trailing-function-commas/arrow-function/expected.js index cf585a0a16..5b8bd230b7 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.trailing-function-commas/arrow-function/expected.js +++ b/packages/babel-core/test/fixtures/transformation/es7.trailing-function-commas/arrow-function/expected.js @@ -1 +1 @@ -(function (x, y) {}); +(x, y) => {}; diff --git a/packages/babel-core/test/fixtures/transformation/es7.trailing-function-commas/options.json b/packages/babel-core/test/fixtures/transformation/es7.trailing-function-commas/options.json index 43dbbaddde..db2590b82a 100644 --- a/packages/babel-core/test/fixtures/transformation/es7.trailing-function-commas/options.json +++ b/packages/babel-core/test/fixtures/transformation/es7.trailing-function-commas/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-trailing-function-commas"] + "plugins": ["syntax-trailing-function-commas"] } diff --git a/packages/babel-core/test/fixtures/transformation/flow/options.json b/packages/babel-core/test/fixtures/transformation/flow/options.json new file mode 100644 index 0000000000..445f44effc --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/flow/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-flow-strip-types", "syntax-async-functions"] +} diff --git a/packages/babel-core/test/fixtures/transformation/flow/strip-type-annotations/expected.js b/packages/babel-core/test/fixtures/transformation/flow/strip-type-annotations/expected.js index 6a52c762fc..62bf507aae 100644 --- a/packages/babel-core/test/fixtures/transformation/flow/strip-type-annotations/expected.js +++ b/packages/babel-core/test/fixtures/transformation/flow/strip-type-annotations/expected.js @@ -1,5 +1,3 @@ -import type from "foo"; -import type2, { foo3 } from "bar"; function foo(numVal) {} function foo(numVal) {} function foo(numVal, strVal) {} @@ -89,3 +87,6 @@ var a; var a; var identity; var identity; + +import type from "foo"; +import type2, { foo3 } from "bar"; diff --git a/packages/babel-core/test/fixtures/transformation/jscript/options.json b/packages/babel-core/test/fixtures/transformation/jscript/options.json index 0c7fdca5db..8f02d5f9f9 100644 --- a/packages/babel-core/test/fixtures/transformation/jscript/options.json +++ b/packages/babel-core/test/fixtures/transformation/jscript/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-jscript"] + "plugins": ["external-helpers", "transform-es2015-block-scoping", "transform-es2015-classes", "transform-jscript"] } diff --git a/packages/babel-core/test/fixtures/transformation/jscript/simple-class/options.json b/packages/babel-core/test/fixtures/transformation/jscript/simple-class/options.json deleted file mode 100644 index 019532b4f9..0000000000 --- a/packages/babel-core/test/fixtures/transformation/jscript/simple-class/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["external-helpers"] -} diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/completion-statements/actual.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/completion-statements/actual.js deleted file mode 100644 index 9a47e69365..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/completion-statements/actual.js +++ /dev/null @@ -1,13 +0,0 @@ -for (var key in foo) { - break; - foo(); -} - -function bar() { - yes(); - bar(); - return "wow"; - nomore(); -} - -bar(); diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/completion-statements/expected.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/completion-statements/expected.js deleted file mode 100644 index 2e07e00fe7..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/completion-statements/expected.js +++ /dev/null @@ -1,11 +0,0 @@ -for (var key in foo) { - break; -} - -function bar() { - yes(); - bar(); - return "wow"; -} - -bar(); diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/actual.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/actual.js deleted file mode 100644 index fbb2e76a40..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -class A { - constructor() { this.value = 12345; } -} - -export default new A(); diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/exec.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/exec.js deleted file mode 100644 index 7a05c7e901..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/exec.js +++ /dev/null @@ -1,3 +0,0 @@ -import aInstance from './imported'; - -assert.equal(aInstance.value, 12345); diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/expected.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/expected.js deleted file mode 100644 index b98c313051..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/expected.js +++ /dev/null @@ -1,9 +0,0 @@ -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports["default"] = new function A() { - babelHelpers.classCallCheck(this, A); - this.value = 12345; -}(); -module.exports = exports["default"]; - diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/imported.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/imported.js deleted file mode 100644 index a26cd32237..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1408/imported.js +++ /dev/null @@ -1,4 +0,0 @@ -class A { - constructor() { this.value = 12345; } -} -export default new A(); diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1409/actual.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1409/actual.js deleted file mode 100644 index 73517de562..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1409/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -class A { - f() { return 1235; } -} - -let a = new A(); diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1409/exec.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1409/exec.js deleted file mode 100644 index e056f09112..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1409/exec.js +++ /dev/null @@ -1,5 +0,0 @@ -class A { - k() { return 12345; } -} - -assert.equal((new A()).k(), 12345); diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1409/expected.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1409/expected.js deleted file mode 100644 index 9c82b8eae8..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1409/expected.js +++ /dev/null @@ -1,13 +0,0 @@ -var a = new ((function () { - function A() { - babelHelpers.classCallCheck(this, A); - } - - babelHelpers.createClass(A, [{ - key: "f", - value: function f() { - return 1235; - } - }]); - return A; -})())(); diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1520/actual.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1520/actual.js deleted file mode 100644 index e822acb53a..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1520/actual.js +++ /dev/null @@ -1 +0,0 @@ -import x from 'y'; diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1520/expected.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1520/expected.js deleted file mode 100644 index 4084f8b09d..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1520/expected.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -var _y = require('y'); - -var _y2 = babelHelpers.interopRequireDefault(_y); - diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/actual.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/actual.js deleted file mode 100644 index 7d956cc75f..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -import x from 'y'; - -x.foo = function (err) {}; diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/exec.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/exec.js deleted file mode 100644 index 95af2bcca8..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/exec.js +++ /dev/null @@ -1,5 +0,0 @@ -import x from 'y'; - -x.z = function (a) { return 1 + a; }; - -assert(x.z(x.value), 43); diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/expected.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/expected.js deleted file mode 100644 index b18afb0a1c..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/expected.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -var _y = require('y'); - -var _y2 = babelHelpers.interopRequireDefault(_y); - -_y2['default'].foo = function (err) {}; - diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/y.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/y.js deleted file mode 100644 index 4f845d4abd..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1522/y.js +++ /dev/null @@ -1,2 +0,0 @@ -let y = { value: 42 }; -export default y; diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1523/actual.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1523/actual.js deleted file mode 100644 index ea435467bc..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1523/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -function f(a) { - return !a; -} - -export { f }; diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1523/expected.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1523/expected.js deleted file mode 100644 index 0f1e0eca71..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1523/expected.js +++ /dev/null @@ -1,7 +0,0 @@ -Object.defineProperty(exports, "__esModule", { - value: true -}); - -exports.f = function f(a) { - return !a; -}; diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1524/actual.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1524/actual.js deleted file mode 100644 index 4b383f4a88..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1524/actual.js +++ /dev/null @@ -1,13 +0,0 @@ -function* x() { - for (let a of []) { - for (let b of a) { - yield 1; - } - } -} - -function y() { - return [...x()]; -} - -export { y }; diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1524/expected.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1524/expected.js deleted file mode 100644 index c8f6caca10..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1524/expected.js +++ /dev/null @@ -1,38 +0,0 @@ -Object.defineProperty(exports, "__esModule", { - value: true -}); -function* x() { - var _arr = []; - - for (var _i = 0; _i < _arr.length; _i++) { - var a = _arr[_i];var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = a[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var b = _step.value; - - yield 1; - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - } -} - -exports.y = function y() { - return [].concat(babelHelpers.toConsumableArray(x())); -}; - diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1546/actual.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1546/actual.js deleted file mode 100644 index c9b8f7c317..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1546/actual.js +++ /dev/null @@ -1,7 +0,0 @@ -class X { - Y() { - return new X(); - } -} - -export { X }; diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1546/expected.js b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1546/expected.js deleted file mode 100644 index 1c0b12e5f2..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/issue-1546/expected.js +++ /dev/null @@ -1,20 +0,0 @@ -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var X = (function () { - function X() { - babelHelpers.classCallCheck(this, X); - } - - babelHelpers.createClass(X, [{ - key: "Y", - value: function Y() { - return new X(); - } - }]); - return X; -})(); - -exports.X = X; - diff --git a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/options.json b/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/options.json deleted file mode 100644 index a6d8f9c810..0000000000 --- a/packages/babel-core/test/fixtures/transformation/minification.dead-code-elimination/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["external-helpers", "transform-dead-code-elimination"] -} diff --git a/packages/babel-core/test/fixtures/transformation/misc/enforce-newline-modules-blacklist/expected.js b/packages/babel-core/test/fixtures/transformation/misc/enforce-newline-modules-blacklist/expected.js index 8be9950ce5..2a6c93164c 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/enforce-newline-modules-blacklist/expected.js +++ b/packages/babel-core/test/fixtures/transformation/misc/enforce-newline-modules-blacklist/expected.js @@ -1,6 +1,3 @@ -export { foo }; -export { bar }; +export function foo() {} -function foo() {} - -function bar() {} +export function bar() {} diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1130/options.json b/packages/babel-core/test/fixtures/transformation/misc/regression-1130/options.json new file mode 100644 index 0000000000..014f199cef --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-1130/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-block-scoping"] +} diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1155/expected.js b/packages/babel-core/test/fixtures/transformation/misc/regression-1155/expected.js index 5d5654c193..52cba9f323 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-1155/expected.js +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-1155/expected.js @@ -8,7 +8,7 @@ var Foo = (function (_Bar) { parentOptions.init = function () { this; }; - babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this, parentOptions); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this, parentOptions)); } return Foo; diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1155/options.json b/packages/babel-core/test/fixtures/transformation/misc/regression-1155/options.json new file mode 100644 index 0000000000..a80812953e --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-1155/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-classes", "external-helpers", "transform-es2015-block-scoping"] +} diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1168/options.json b/packages/babel-core/test/fixtures/transformation/misc/regression-1168/options.json new file mode 100644 index 0000000000..bf2c8e1456 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-1168/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["syntax-flow", "transform-flow-strip-types", "transform-es2015-parameters", "transform-es2015-block-scoping"] +} diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1169/expected.js b/packages/babel-core/test/fixtures/transformation/misc/regression-1169/expected.js index d0e160e237..52350f484a 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-1169/expected.js +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-1169/expected.js @@ -1,5 +1,3 @@ -'use strict'; - function foo() { var input = ['a', 'b', 'c']; var output = {}; @@ -12,16 +10,16 @@ function foo() { for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var c = _step.value; - var _name = c; - output[_name] = _name; + var name = c; + output[name] = name; } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator['return']) { - _iterator['return'](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1169/options.json b/packages/babel-core/test/fixtures/transformation/misc/regression-1169/options.json new file mode 100644 index 0000000000..f3f0e39508 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-1169/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-block-scoping", "transform-es2015-for-of"] +} diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1199/expected.js b/packages/babel-core/test/fixtures/transformation/misc/regression-1199/expected.js index 095bcf9a2c..7d278a3a8c 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-1199/expected.js +++ b/packages/babel-core/test/fixtures/transformation/misc/regression-1199/expected.js @@ -1,4 +1,4 @@ -var bug = 1; +const bug = 1; function foo() {} diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1489/actual.js b/packages/babel-core/test/fixtures/transformation/misc/regression-1489/actual.js deleted file mode 100644 index 9fa4842a8e..0000000000 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-1489/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -import toString from "foo"; -toString; diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1489/expected.js b/packages/babel-core/test/fixtures/transformation/misc/regression-1489/expected.js deleted file mode 100644 index 695d6fd8bb..0000000000 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-1489/expected.js +++ /dev/null @@ -1,11 +0,0 @@ -System.register(["foo"], function (_export) { - var toString; - return { - setters: [function (_foo) { - toString = _foo["default"]; - }], - execute: function () { - toString; - } - }; -}); diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-1489/options.json b/packages/babel-core/test/fixtures/transformation/misc/regression-1489/options.json deleted file mode 100644 index ee42d8e1c8..0000000000 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-1489/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "modules": "system" -} diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-lodash-tostring-import/actual.js b/packages/babel-core/test/fixtures/transformation/misc/regression-lodash-tostring-import/actual.js deleted file mode 100644 index 9fa4842a8e..0000000000 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-lodash-tostring-import/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -import toString from "foo"; -toString; diff --git a/packages/babel-core/test/fixtures/transformation/misc/regression-lodash-tostring-import/expected.js b/packages/babel-core/test/fixtures/transformation/misc/regression-lodash-tostring-import/expected.js deleted file mode 100644 index 2c83e5660f..0000000000 --- a/packages/babel-core/test/fixtures/transformation/misc/regression-lodash-tostring-import/expected.js +++ /dev/null @@ -1,5 +0,0 @@ -var _foo = require("foo"); - -var _foo2 = babelHelpers.interopRequireDefault(_foo); - -_foo2["default"]; diff --git a/packages/babel-core/test/fixtures/transformation/misc/shebang/expected.js b/packages/babel-core/test/fixtures/transformation/misc/shebang/expected.js index ef3bea62ac..bbfcec5998 100644 --- a/packages/babel-core/test/fixtures/transformation/misc/shebang/expected.js +++ b/packages/babel-core/test/fixtures/transformation/misc/shebang/expected.js @@ -1,2 +1,3 @@ #!/usr/bin/env node + foobar(); diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.modules.system/options.json b/packages/babel-core/test/fixtures/transformation/optimisation.modules.system/options.json deleted file mode 100644 index 4609d2a157..0000000000 --- a/packages/babel-core/test/fixtures/transformation/optimisation.modules.system/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "modules": "system", - "optional": ["optimisation.modules.system"] -} diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.modules.system/setters/actual.js b/packages/babel-core/test/fixtures/transformation/optimisation.modules.system/setters/actual.js deleted file mode 100644 index 9dcc9094ea..0000000000 --- a/packages/babel-core/test/fixtures/transformation/optimisation.modules.system/setters/actual.js +++ /dev/null @@ -1,8 +0,0 @@ -export * from "foo"; -export {foo} from "foo"; -export {foo, bar} from "foo"; -export {foo as bar} from "bar"; -export {foo as default} from "bar"; -export {foo as default, bar} from "bar"; - -export var foo, bar; diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.modules.system/setters/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.modules.system/setters/expected.js deleted file mode 100644 index 925b06f414..0000000000 --- a/packages/babel-core/test/fixtures/transformation/optimisation.modules.system/setters/expected.js +++ /dev/null @@ -1,31 +0,0 @@ -System.register(["foo", "bar"], function (_export) { - var foo, bar; - return { - setters: [function (_foo) { - var _exportObj = {}; - - for (var _key in _foo) { - if (_key !== "default") _exportObj[_key] = _foo[_key]; - } - - _exportObj["foo"] = _foo.foo; - _exportObj["foo"] = _foo.foo; - _exportObj["bar"] = _foo.bar; - - _export(_exportObj); - }, function (_bar) { - var _exportObj2 = {}; - _exportObj2["bar"] = _bar.foo; - _exportObj2["default"] = _bar.foo; - _exportObj2["default"] = _bar.foo; - _exportObj2["bar"] = _bar.bar; - - _export(_exportObj2); - }], - execute: function () { - _export("foo", foo); - - _export("bar", bar); - } - }; -}); diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/expected.js index 305d415c2c..3b37338633 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/expected.js @@ -1,8 +1,12 @@ +var _typeofReactElement = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7; + var _ref = { + $$typeof: _typeofReactElement, type: "foo", + key: null, ref: null, props: {}, - key: null + _owner: null }; function render() { return _ref; @@ -11,12 +15,14 @@ function render() { function render() { var text = getText(); var _ref2 = { + $$typeof: _typeofReactElement, type: "foo", + key: null, ref: null, props: { children: text }, - key: null + _owner: null }; return function () { return _ref2; diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/options.json b/packages/babel-core/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/options.json index 70bf9c0276..533a4539e5 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/options.json +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.constant-elements/inline-elements/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-react-constant-elements", "transform-react-inline-elements"] + "plugins": ["transform-react-constant-elements", "transform-react-inline-elements", "syntax-jsx"] } diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component-with-props/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component-with-props/expected.js index 172f34cb43..83084ab60d 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component-with-props/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component-with-props/expected.js @@ -1,8 +1,10 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: Baz, + key: null, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, { foo: "bar" }), - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js index d88aac9167..ecdf28d80c 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/component/expected.js @@ -1,6 +1,8 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: Baz, + key: null, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, {}), - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/html-element-with-props/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/html-element-with-props/expected.js index c46eda8cea..ebca291106 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/html-element-with-props/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/html-element-with-props/expected.js @@ -1,8 +1,10 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: "foo", + key: null, ref: null, props: { bar: "foo" }, - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/html-element/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/html-element/expected.js index c629f1d832..ddeb8c32e4 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/html-element/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/html-element/expected.js @@ -1,6 +1,8 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: "foo", + key: null, ref: null, props: {}, - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/key/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/key/expected.js index c594684752..bd4e4b0ae2 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/key/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/key/expected.js @@ -1,6 +1,8 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: Foo, + key: "foo", ref: null, props: babelHelpers.defaultProps(Foo.defaultProps, {}), - key: "foo" -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js index c3c428db2b..ad2ed9f4e5 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-components/expected.js @@ -1,14 +1,18 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: Foo, + key: null, ref: null, props: babelHelpers.defaultProps(Foo.defaultProps, { children: [bar, { + $$typeof: babelHelpers.typeofReactElement, type: Baz, + key: "baz", ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, {}), - key: "baz" + _owner: null }], className: "foo" }), - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-html-elements/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-html-elements/expected.js index 57ff15a14f..729c3ca5d3 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-html-elements/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested-html-elements/expected.js @@ -1,9 +1,11 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: "div", + key: null, ref: null, props: { children: bar, className: "foo" }, - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js index f404194711..c95b63f592 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/nested/expected.js @@ -1,14 +1,18 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: "div", + key: null, ref: null, props: { children: [bar, { + $$typeof: babelHelpers.typeofReactElement, type: Baz, + key: "baz", ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, {}), - key: "baz" + _owner: null }], className: "foo" }, - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component-with-props/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component-with-props/expected.js index 172f34cb43..83084ab60d 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component-with-props/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component-with-props/expected.js @@ -1,8 +1,10 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: Baz, + key: null, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, { foo: "bar" }), - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js index d88aac9167..ecdf28d80c 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-component/expected.js @@ -1,6 +1,8 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: Baz, + key: null, ref: null, props: babelHelpers.defaultProps(Baz.defaultProps, {}), - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element-with-props/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element-with-props/expected.js index c46eda8cea..ebca291106 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element-with-props/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element-with-props/expected.js @@ -1,8 +1,10 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: "foo", + key: null, ref: null, props: { bar: "foo" }, - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element/expected.js index c629f1d832..ddeb8c32e4 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/self-closing-html-element/expected.js @@ -1,6 +1,8 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: "foo", + key: null, ref: null, props: {}, - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js index e756d2370f..ce4365ed6d 100644 --- a/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js +++ b/packages/babel-core/test/fixtures/transformation/optimisation.react.inline-elements/shorthand-attributes/expected.js @@ -1,8 +1,10 @@ ({ + $$typeof: babelHelpers.typeofReactElement, type: Foo, + key: null, ref: null, props: babelHelpers.defaultProps(Foo.defaultProps, { bar: true }), - key: null -}); + _owner: null +}); \ No newline at end of file diff --git a/packages/babel-core/test/fixtures/transformation/react/optimisation.react.constant-elements/actual.js b/packages/babel-core/test/fixtures/transformation/react/.optimisation.react.constant-elements/actual.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/react/optimisation.react.constant-elements/actual.js rename to packages/babel-core/test/fixtures/transformation/react/.optimisation.react.constant-elements/actual.js diff --git a/packages/babel-core/test/fixtures/transformation/react/optimisation.react.constant-elements/expected.js b/packages/babel-core/test/fixtures/transformation/react/.optimisation.react.constant-elements/expected.js similarity index 100% rename from packages/babel-core/test/fixtures/transformation/react/optimisation.react.constant-elements/expected.js rename to packages/babel-core/test/fixtures/transformation/react/.optimisation.react.constant-elements/expected.js diff --git a/packages/babel-core/test/fixtures/transformation/react/.optimisation.react.constant-elements/options.json b/packages/babel-core/test/fixtures/transformation/react/.optimisation.react.constant-elements/options.json new file mode 100644 index 0000000000..df22ce44b7 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/react/.optimisation.react.constant-elements/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-react-constant-elements", "transform-es2015-classes", "syntax-jsx"] +} diff --git a/packages/babel-core/test/fixtures/transformation/react/arrow-functions/expected.js b/packages/babel-core/test/fixtures/transformation/react/arrow-functions/expected.js index eca0547917..dc9fe71161 100644 --- a/packages/babel-core/test/fixtures/transformation/react/arrow-functions/expected.js +++ b/packages/babel-core/test/fixtures/transformation/react/arrow-functions/expected.js @@ -1,4 +1,4 @@ -var foo = function foo() { +var foo = function () { var _this = this; return function () { @@ -6,10 +6,10 @@ var foo = function foo() { }; }; -var bar = function bar() { +var bar = function () { var _this2 = this; return function () { return React.createElement(_this2.foo, null); }; -}; \ No newline at end of file +}; diff --git a/packages/babel-core/test/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/options.json b/packages/babel-core/test/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/options.json index f06ff74164..f668e3e74e 100644 --- a/packages/babel-core/test/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/options.json +++ b/packages/babel-core/test/fixtures/transformation/react/honor-custom-jsx-comment-if-jsx-pragma-option-set/options.json @@ -1,3 +1,3 @@ { - "jsxPragma": "foo.bar" + "plugins": [["transform-react-jsx", "foo.bar"]] } diff --git a/packages/babel-core/test/fixtures/transformation/react/honor-custom-jsx-pragma-option/options.json b/packages/babel-core/test/fixtures/transformation/react/honor-custom-jsx-pragma-option/options.json index 223d2362fc..2aae85c034 100644 --- a/packages/babel-core/test/fixtures/transformation/react/honor-custom-jsx-pragma-option/options.json +++ b/packages/babel-core/test/fixtures/transformation/react/honor-custom-jsx-pragma-option/options.json @@ -1,3 +1,3 @@ { - "jsxPragma": "dom" + "plugins": [["transform-react-jsx", { "pragma": "dom" }]] } diff --git a/packages/babel-core/test/fixtures/transformation/react/optimisation.react.constant-elements/options.json b/packages/babel-core/test/fixtures/transformation/react/optimisation.react.constant-elements/options.json deleted file mode 100644 index a152fb584d..0000000000 --- a/packages/babel-core/test/fixtures/transformation/react/optimisation.react.constant-elements/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["transform-react-constant-lements"] -} diff --git a/packages/babel-core/test/fixtures/transformation/react/options.json b/packages/babel-core/test/fixtures/transformation/react/options.json index b241ab3574..6063cc9468 100644 --- a/packages/babel-core/test/fixtures/transformation/react/options.json +++ b/packages/babel-core/test/fixtures/transformation/react/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers", "syntax-jsx", "transform-react-jsx", "transform-react-display-name"] + "plugins": ["external-helpers", "syntax-jsx", "transform-react-jsx", "transform-react-display-name", "transform-es2015-arrow-functions"] } diff --git a/packages/babel-core/test/fixtures/transformation/regenerator/options.json b/packages/babel-core/test/fixtures/transformation/regenerator/options.json new file mode 100644 index 0000000000..6e83ffcc45 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/regenerator/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-destructuring", "transform-es2015-parameters", "transform-es2015-block-scoping", "transform-regenerator"] +} diff --git a/packages/babel-core/test/fixtures/transformation/runtime/aliased-constructors/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/aliased-constructors/expected.js index 5504aca34c..af27e0f321 100644 --- a/packages/babel-core/test/fixtures/transformation/runtime/aliased-constructors/expected.js +++ b/packages/babel-core/test/fixtures/transformation/runtime/aliased-constructors/expected.js @@ -1,9 +1,6 @@ -var _Promise = require("babel-runtime/core-js/promise")["default"]; - -var _Symbol = require("babel-runtime/core-js/symbol")["default"]; - -var _Map = require("babel-runtime/core-js/map")["default"]; - +import _Map from "babel-runtime/core-js/map"; +import _Symbol from "babel-runtime/core-js/symbol"; +import _Promise from "babel-runtime/core-js/promise"; obj.constructor === Object; obj.constructor === _Promise; diff --git a/packages/babel-core/test/fixtures/transformation/runtime/catch-all/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/catch-all/expected.js index 2d6f5c07d6..97b8bf8e3b 100644 --- a/packages/babel-core/test/fixtures/transformation/runtime/catch-all/expected.js +++ b/packages/babel-core/test/fixtures/transformation/runtime/catch-all/expected.js @@ -1,3 +1,2 @@ -var _Promise = require("babel-runtime/core-js/promise")["default"]; - +import _Promise from "babel-runtime/core-js/promise"; _Promise.resolve; diff --git a/packages/babel-core/test/fixtures/transformation/runtime/es6-for-of/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/es6-for-of/expected.js index 439dc62190..6ad474d512 100644 --- a/packages/babel-core/test/fixtures/transformation/runtime/es6-for-of/expected.js +++ b/packages/babel-core/test/fixtures/transformation/runtime/es6-for-of/expected.js @@ -1,5 +1,4 @@ -var _getIterator = require("babel-runtime/core-js/get-iterator")["default"]; - +import _getIterator from "babel-runtime/core-js/get-iterator"; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; @@ -13,8 +12,8 @@ try { _iteratorError = err; } finally { try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); } } finally { if (_didIteratorError) { diff --git a/packages/babel-core/test/fixtures/transformation/runtime/es6-for-of/options.json b/packages/babel-core/test/fixtures/transformation/runtime/es6-for-of/options.json new file mode 100644 index 0000000000..439eb3f913 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/runtime/es6-for-of/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-for-of", "transform-runtime"] +} diff --git a/packages/babel-core/test/fixtures/transformation/runtime/es7-array-comprehensions/actual.js b/packages/babel-core/test/fixtures/transformation/runtime/es7-array-comprehensions/actual.js deleted file mode 100644 index 9dda19048b..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/es7-array-comprehensions/actual.js +++ /dev/null @@ -1 +0,0 @@ -var arr = [for (i of nums) i * i]; diff --git a/packages/babel-core/test/fixtures/transformation/runtime/es7-array-comprehensions/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/es7-array-comprehensions/expected.js deleted file mode 100644 index f9e6def935..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/es7-array-comprehensions/expected.js +++ /dev/null @@ -1,31 +0,0 @@ -var _getIterator = require("babel-runtime/core-js/get-iterator")["default"]; - -var arr = (function () { - var _arr = []; - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = _getIterator(nums), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var i = _step.value; - - _arr.push(i * i); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"]) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - return _arr; -})(); diff --git a/packages/babel-core/test/fixtures/transformation/runtime/full/actual.js b/packages/babel-core/test/fixtures/transformation/runtime/full/actual.js index 9929f3e967..0340999129 100644 --- a/packages/babel-core/test/fixtures/transformation/runtime/full/actual.js +++ b/packages/babel-core/test/fixtures/transformation/runtime/full/actual.js @@ -5,6 +5,5 @@ export function* giveWord () { yield myWord; } - foo; bar; diff --git a/packages/babel-core/test/fixtures/transformation/runtime/full/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/full/expected.js index 26ff47d328..f6aaa4e30b 100644 --- a/packages/babel-core/test/fixtures/transformation/runtime/full/expected.js +++ b/packages/babel-core/test/fixtures/transformation/runtime/full/expected.js @@ -1,39 +1,24 @@ -var _regeneratorRuntime = require("babel-runtime/regenerator")["default"]; +import _regeneratorRuntime from "babel-runtime/regenerator"; +import _Symbol from "babel-runtime/core-js/symbol"; -var _Symbol = require("babel-runtime/core-js/symbol")["default"]; +var _marked = [giveWord].map(_regeneratorRuntime.mark); -var _interopRequireDefault = require("babel-runtime/helpers/interop-require-default")["default"]; +import foo, * as bar from "someModule"; -var _interopRequireWildcard = require("babel-runtime/helpers/interop-require-wildcard")["default"]; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.giveWord = giveWord; -var marked0$0 = [giveWord].map(_regeneratorRuntime.mark); - -var _someModule = require("someModule"); - -var _someModule2 = _interopRequireDefault(_someModule); - -var bar = _interopRequireWildcard(_someModule); - -var myWord = _Symbol("abc"); -exports.myWord = myWord; - -function giveWord() { - return _regeneratorRuntime.wrap(function giveWord$(context$1$0) { - while (1) switch (context$1$0.prev = context$1$0.next) { +export const myWord = _Symbol("abc"); +export function giveWord() { + return regeneratorRuntime.wrap(function giveWord$(_context) { + while (1) switch (_context.prev = _context.next) { case 0: - context$1$0.next = 2; + _context.next = 2; return myWord; case 2: case "end": - return context$1$0.stop(); + return _context.stop(); } - }, marked0$0[0], this); + }, _marked[0], this); } -_someModule2["default"]; +foo; bar; diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-amd/actual.js b/packages/babel-core/test/fixtures/transformation/runtime/modules-amd/actual.js deleted file mode 100644 index 8630daffa6..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-amd/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -import foo from "foo"; -foo; diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-amd/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/modules-amd/expected.js deleted file mode 100644 index 2562ab4e46..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-amd/expected.js +++ /dev/null @@ -1,5 +0,0 @@ -define(["exports", "foo", "babel-runtime/helpers/interop-require-default"], function (exports, _foo, _babelRuntimeHelpersInteropRequireDefault) { - var _foo2 = (0, _babelRuntimeHelpersInteropRequireDefault["default"])(_foo); - - _foo2["default"]; -}); diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-amd/options.json b/packages/babel-core/test/fixtures/transformation/runtime/modules-amd/options.json deleted file mode 100644 index b76b119f33..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-amd/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "modules": "amd" -} diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-common/actual.js b/packages/babel-core/test/fixtures/transformation/runtime/modules-common/actual.js deleted file mode 100644 index 44567cb185..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-common/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -import foo from "foo"; - -foo; diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-common/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/modules-common/expected.js deleted file mode 100644 index 3fb442c27b..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-common/expected.js +++ /dev/null @@ -1,7 +0,0 @@ -var _interopRequireDefault = require("babel-runtime/helpers/interop-require-default")["default"]; - -var _foo = require("foo"); - -var _foo2 = _interopRequireDefault(_foo); - -_foo2["default"]; diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-system/actual.js b/packages/babel-core/test/fixtures/transformation/runtime/modules-system/actual.js deleted file mode 100644 index 34353bc650..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-system/actual.js +++ /dev/null @@ -1,5 +0,0 @@ -foo(...bar); - -export function* generator() { - yield 1; -} diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-system/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/modules-system/expected.js deleted file mode 100644 index 72abbffce3..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-system/expected.js +++ /dev/null @@ -1,31 +0,0 @@ -System.register(["babel-runtime/helpers/to-consumable-array", "babel-runtime/regenerator"], function (_export) { - var _toConsumableArray, _regeneratorRuntime, marked0$0; - - function generator() { - return _regeneratorRuntime.wrap(function generator$(context$1$0) { - while (1) switch (context$1$0.prev = context$1$0.next) { - case 0: - context$1$0.next = 2; - return 1; - - case 2: - case "end": - return context$1$0.stop(); - } - }, marked0$0[0], this); - } - - return { - setters: [function (_babelRuntimeHelpersToConsumableArray) { - _toConsumableArray = _babelRuntimeHelpersToConsumableArray["default"]; - }, function (_babelRuntimeRegenerator) { - _regeneratorRuntime = _babelRuntimeRegenerator["default"]; - }], - execute: function () { - _export("generator", generator); - - marked0$0 = [generator].map(_regeneratorRuntime.mark); - foo.apply(undefined, _toConsumableArray(bar)); - } - }; -}); diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-system/options.json b/packages/babel-core/test/fixtures/transformation/runtime/modules-system/options.json deleted file mode 100644 index ee42d8e1c8..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-system/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "modules": "system" -} diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-umd/actual.js b/packages/babel-core/test/fixtures/transformation/runtime/modules-umd/actual.js deleted file mode 100644 index 8d1420050a..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-umd/actual.js +++ /dev/null @@ -1 +0,0 @@ -import foo from "foo"; diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-umd/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/modules-umd/expected.js deleted file mode 100644 index ec9eb3d64d..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-umd/expected.js +++ /dev/null @@ -1,15 +0,0 @@ -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(["exports", "foo", "babel-runtime/helpers/interop-require-default"], factory); - } else if (typeof exports !== "undefined") { - factory(exports, require("foo"), require("babel-runtime/helpers/interop-require-default")); - } else { - var mod = { - exports: {} - }; - factory(mod.exports, global.foo, global._interopRequireDefault); - global.actual = mod.exports; - } -})(this, function (exports, _foo, _babelRuntimeHelpersInteropRequireDefault) { - var _foo2 = (0, _babelRuntimeHelpersInteropRequireDefault["default"])(_foo); -}); diff --git a/packages/babel-core/test/fixtures/transformation/runtime/modules-umd/options.json b/packages/babel-core/test/fixtures/transformation/runtime/modules-umd/options.json deleted file mode 100644 index 1683480119..0000000000 --- a/packages/babel-core/test/fixtures/transformation/runtime/modules-umd/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "modules": "umd" -} diff --git a/packages/babel-core/test/fixtures/transformation/runtime/options.json b/packages/babel-core/test/fixtures/transformation/runtime/options.json index a813a0a347..b987a67bba 100644 --- a/packages/babel-core/test/fixtures/transformation/runtime/options.json +++ b/packages/babel-core/test/fixtures/transformation/runtime/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-runtime"] + "plugins": ["transform-runtime", "transform-regenerator"] } diff --git a/packages/babel-core/test/fixtures/transformation/runtime/regenerator-runtime/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/regenerator-runtime/expected.js index ccabc7aaf6..3ba21d10de 100644 --- a/packages/babel-core/test/fixtures/transformation/runtime/regenerator-runtime/expected.js +++ b/packages/babel-core/test/fixtures/transformation/runtime/regenerator-runtime/expected.js @@ -1,11 +1,10 @@ -var _regeneratorRuntime = require("babel-runtime/regenerator")["default"]; - -void _regeneratorRuntime.mark(function callee$0$0() { - return _regeneratorRuntime.wrap(function callee$0$0$(context$1$0) { - while (1) switch (context$1$0.prev = context$1$0.next) { +import _regeneratorRuntime from "babel-runtime/regenerator"; +void _regeneratorRuntime.mark(function _callee() { + return _regeneratorRuntime.wrap(function _callee$(_context) { + while (1) switch (_context.prev = _context.next) { case 0: case "end": - return context$1$0.stop(); + return _context.stop(); } - }, callee$0$0, this); + }, _callee, this); }); diff --git a/packages/babel-core/test/fixtures/transformation/runtime/symbol-iterator-in/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/symbol-iterator-in/expected.js index bbf2f2f0d1..3468aae656 100644 --- a/packages/babel-core/test/fixtures/transformation/runtime/symbol-iterator-in/expected.js +++ b/packages/babel-core/test/fixtures/transformation/runtime/symbol-iterator-in/expected.js @@ -1,3 +1,2 @@ -var _isIterable = require("babel-runtime/core-js/is-iterable")["default"]; - +import _isIterable from "babel-runtime/core-js/is-iterable"; _isIterable(Object(arr)); diff --git a/packages/babel-core/test/fixtures/transformation/runtime/symbol-iterator/expected.js b/packages/babel-core/test/fixtures/transformation/runtime/symbol-iterator/expected.js index c5a7e133dd..5b72708826 100644 --- a/packages/babel-core/test/fixtures/transformation/runtime/symbol-iterator/expected.js +++ b/packages/babel-core/test/fixtures/transformation/runtime/symbol-iterator/expected.js @@ -1,3 +1,2 @@ -var _Symbol$iterator = require("babel-runtime/core-js/symbol/iterator")["default"]; - +import _Symbol$iterator from "babel-runtime/core-js/symbol/iterator"; _Symbol$iterator; diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/options.json b/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/options.json new file mode 100644 index 0000000000..d594536c39 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-arrow-functions", "transform-es2015-function-name"] +} diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-mappings.json b/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-mappings.json index c68273d12c..a1d1d31e4a 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-mappings.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/arrow-function/source-mappings.json @@ -4,7 +4,7 @@ "column": 14 }, "generated": { - "line": 4, + "line": 2, "column": 10 } }] diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/class/expected.js b/packages/babel-core/test/fixtures/transformation/source-maps/class/expected.js index 1feba14c2f..2a5d6b6276 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/class/expected.js +++ b/packages/babel-core/test/fixtures/transformation/source-maps/class/expected.js @@ -5,7 +5,7 @@ var Test = (function () { babelHelpers.createClass(Test, [{ key: "bar", - get: function get() { + get: function () { throw new Error("wow"); } }]); diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/class/options.json b/packages/babel-core/test/fixtures/transformation/source-maps/class/options.json new file mode 100644 index 0000000000..53a40720bc --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/source-maps/class/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-classes", "transform-es2015-block-scoping"] +} diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/class/source-mappings.json b/packages/babel-core/test/fixtures/transformation/source-maps/class/source-mappings.json index 5d8c4d8816..16239daa2c 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/class/source-mappings.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/class/source-mappings.json @@ -4,7 +4,7 @@ "column": 10 }, "generated": { - "line": 11, + "line": 9, "column": 15 } }] diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/full/options.json b/packages/babel-core/test/fixtures/transformation/source-maps/full/options.json new file mode 100644 index 0000000000..fc3d742263 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/source-maps/full/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-es2015-arrow-functions"] +} diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json index 81d70ba9d8..b2b351d8bb 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json @@ -3,6 +3,6 @@ "file": "source-maps/full/expected.js", "sources": ["source-maps/full/actual.js"], "names": [], - "mappings": ";;AAAA,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,CAAC;CAAA,CAAC,CAAC", + "mappings": "AAAA,GAAG,CAAC,GAAG,CAAC,UAAA,CAAC;SAAI,CAAC,GAAG,CAAC;CAAA,CAAC,CAAC", "sourcesContent": ["arr.map(x => x * x);"] } diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js b/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js index 428d65efea..f93d2fbb34 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js +++ b/packages/babel-core/test/fixtures/transformation/source-maps/inline/expected.js @@ -1,4 +1,4 @@ arr.map(function (x) { return x * x; }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9hY3R1YWwuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxHQUFHLENBQUMsR0FBRyxDQUFDLFVBQUEsQ0FBQztTQUFJLENBQUMsR0FBRyxDQUFDO0NBQUEsQ0FBQyxDQUFDIiwiZmlsZSI6InNvdXJjZS1tYXBzL2lubGluZS9leHBlY3RlZC5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il19 +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9hY3R1YWwuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsR0FBRyxDQUFDLEdBQUcsQ0FBQyxVQUFBLENBQUM7U0FBSSxDQUFDLEdBQUcsQ0FBQztDQUFBLENBQUMsQ0FBQyIsImZpbGUiOiJzb3VyY2UtbWFwcy9pbmxpbmUvZXhwZWN0ZWQuanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIHgpOyJdfQ== diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/inline/options.json b/packages/babel-core/test/fixtures/transformation/source-maps/inline/options.json index 5907a8b5cc..3113ddc9e9 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/inline/options.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/inline/options.json @@ -1,3 +1,4 @@ { + "plugins": ["transform-es2015-arrow-functions"], "sourceMap": "inline" } diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/smoke/exec.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/.smoke/exec.js similarity index 88% rename from packages/babel-core/test/fixtures/transformation/spec.function-name/smoke/exec.js rename to packages/babel-core/test/fixtures/transformation/spec.function-name/.smoke/exec.js index 593aef207e..179d59d7e5 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/smoke/exec.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/.smoke/exec.js @@ -19,5 +19,5 @@ var obj = { @noop foo() {} }; assert.equal(obj.foo.name, "foo"); -var obj = { @noop foo: function () {} }; +var obj = { @noop foo: function () { return "foo"; } }; assert.equal(obj.foo.name, "foo"); diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/smoke/options.json b/packages/babel-core/test/fixtures/transformation/spec.function-name/.smoke/options.json similarity index 100% rename from packages/babel-core/test/fixtures/transformation/spec.function-name/smoke/options.json rename to packages/babel-core/test/fixtures/transformation/spec.function-name/.smoke/options.json diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/assignment/expected.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/assignment/expected.js index 54facec2e2..f4919f370a 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/assignment/expected.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/assignment/expected.js @@ -3,10 +3,7 @@ var _i = function i() { }; var _j = function j() { - var _ = 5; - _j = _.j; - var _2 = 5; - _j = _2.y; - + ({ j: _j } = 5); + ({ y: _j } = 5); ; }; diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/class-method/expected.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/class-method/expected.js index d0975aa817..b437bcd715 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/class-method/expected.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/class-method/expected.js @@ -1,4 +1,4 @@ -var Foo = (function () { +let Foo = (function () { function Foo() { babelHelpers.classCallCheck(this, Foo); } diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/collisions/expected.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/collisions/expected.js index 0e816c3c56..5fbe7cfa81 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/collisions/expected.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/collisions/expected.js @@ -1,13 +1,9 @@ var obj = { - search: function search(_ref) { - var _search = _ref.search; - + search: function search({ search: _search }) { console.log(_search); } }; -function search(_ref2) { - var search = _ref2.search; - +function search({ search }) { console.log(search); } diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/eval/actual.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/eval/actual.js index 81c171ff4b..0a00dbf31d 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/eval/actual.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/eval/actual.js @@ -1,5 +1,5 @@ var a = { - eval(){ + eval: function () { return eval; } }; diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/export/actual.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/export/actual.js index cfc8bd19d4..e1a034b8e1 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/export/actual.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/export/actual.js @@ -1,7 +1,19 @@ -export var foo = "yes"; +export var foo = "yes", foob = "no"; + +export function whatever() {} + +export default function wowzers() {} var bar = { foo: function () { foo; + }, + + whatever: function () { + whatever; + }, + + wowzers: function () { + wowzers; } }; diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/export/expected.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/export/expected.js index fce5e95164..0d53fa7d4c 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/export/expected.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/export/expected.js @@ -1,8 +1,23 @@ -var _foo = "yes"; +export { _whatever as whatever }; +export { _wowzers as default }; +var _foo = "yes", + foob = "no"; + +export { _foo as foo, foob }; +function _whatever() {} + +function _wowzers() {} -export { _foo as foo }; var bar = { foo: function foo() { _foo; + }, + + whatever: function whatever() { + _whatever; + }, + + wowzers: function wowzers() { + _wowzers; } }; diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/function-collision/actual.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/function-collision/actual.js new file mode 100644 index 0000000000..7f00f96e17 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/function-collision/actual.js @@ -0,0 +1,19 @@ +function f() { + f; +} + +{ + let obj = { + f: function () { + f; + } + }; +} + +(function b() { + var obj = { + b: function () { + b; + } + }; +}); diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/function-collision/expected.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/function-collision/expected.js new file mode 100644 index 0000000000..974eed70f6 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/function-collision/expected.js @@ -0,0 +1,19 @@ +function _f() { + _f; +} + +{ + let obj = { + f: function f() { + _f; + } + }; +} + +(function _b() { + var obj = { + b: function b() { + _b; + } + }; +}); diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-2/expected.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-2/expected.js index de9fcf4b71..cbb70ef1c4 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-2/expected.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-2/expected.js @@ -2,11 +2,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); -var _lodashArrayLast = require("lodash/array/last"); +var _last2 = require("lodash/array/last"); -var _lodashArrayLast2 = babelHelpers.interopRequireDefault(_lodashArrayLast); +var _last3 = babelHelpers.interopRequireDefault(_last2); -var Container = (function () { +let Container = (function () { function Container() { babelHelpers.classCallCheck(this, Container); } @@ -18,11 +18,10 @@ var Container = (function () { return; } - return (0, _lodashArrayLast2["default"])(this.tokens.get(key)); + return (0, _last3.default)(this.tokens.get(key)); } }]); return Container; })(); -exports["default"] = Container; -module.exports = exports["default"]; +exports.default = Container; diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-2/options.json b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-2/options.json new file mode 100644 index 0000000000..ae79e8a72f --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-2/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-classes", "transform-decorators", "transform-es2015-modules-commonjs"] +} diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-3/expected.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-3/expected.js index e28e0d7450..75097d561c 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-3/expected.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-3/expected.js @@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", { var _store = require("./store"); -var Login = (function (_React$Component) { +let Login = (function (_React$Component) { babelHelpers.inherits(Login, _React$Component); function Login() { babelHelpers.classCallCheck(this, Login); - babelHelpers.get(Object.getPrototypeOf(Login.prototype), "constructor", this).apply(this, arguments); + return babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Login).apply(this, arguments)); } babelHelpers.createClass(Login, [{ @@ -21,5 +21,4 @@ var Login = (function (_React$Component) { return Login; })(React.Component); -exports["default"] = Login; -module.exports = exports["default"]; +exports.default = Login; diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-3/options.json b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-3/options.json new file mode 100644 index 0000000000..3eb095ef7c --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules-3/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-modules-commonjs", "transform-es2015-classes", "transform-decorators"] +} diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/modules/expected.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules/expected.js index 5eac050fff..82cdf7a485 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/modules/expected.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules/expected.js @@ -2,7 +2,7 @@ var _events2 = require("events"); var _events3 = babelHelpers.interopRequireDefault(_events2); -var Template = (function () { +let Template = (function () { function Template() { babelHelpers.classCallCheck(this, Template); } @@ -10,7 +10,7 @@ var Template = (function () { babelHelpers.createClass(Template, [{ key: "events", value: function events() { - return _events3["default"]; + return _events3.default; } }]); return Template; diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/modules/options.json b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules/options.json new file mode 100644 index 0000000000..3eb095ef7c --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/modules/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-modules-commonjs", "transform-es2015-classes", "transform-decorators"] +} diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/options.json b/packages/babel-core/test/fixtures/transformation/spec.function-name/options.json index 019532b4f9..bd531041dc 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/options.json +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/options.json @@ -1,3 +1,3 @@ { - "plugins": ["external-helpers"] + "plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-classes", "transform-decorators"] } diff --git a/packages/babel-core/test/fixtures/transformation/spec.function-name/shorthand-property/expected.js b/packages/babel-core/test/fixtures/transformation/spec.function-name/shorthand-property/expected.js index deba662519..3ef494a094 100644 --- a/packages/babel-core/test/fixtures/transformation/spec.function-name/shorthand-property/expected.js +++ b/packages/babel-core/test/fixtures/transformation/spec.function-name/shorthand-property/expected.js @@ -2,7 +2,7 @@ var Utils = { get: function get() {} }; -var _get = Utils.get; +var { get: _get } = Utils; var bar = { get: function get(arg) { @@ -10,11 +10,7 @@ var bar = { } }; -var f = function f(_ref) { - var _ref$foo = _ref.foo; - - var _foo = _ref$foo === undefined ? "bar" : _ref$foo; - +var f = function f({ foo: _foo = "bar" }) { var obj = { // same name as parameter foo: function foo() { diff --git a/packages/babel-core/test/fixtures/transformation/spec.proto-to-assign/class/actual.js b/packages/babel-core/test/fixtures/transformation/spec.proto-to-assign/class/actual.js deleted file mode 100644 index 9b78abd703..0000000000 --- a/packages/babel-core/test/fixtures/transformation/spec.proto-to-assign/class/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -class Foo extends Bar { - -} diff --git a/packages/babel-core/test/fixtures/transformation/spec.proto-to-assign/class/expected.js b/packages/babel-core/test/fixtures/transformation/spec.proto-to-assign/class/expected.js deleted file mode 100644 index cd76510ab1..0000000000 --- a/packages/babel-core/test/fixtures/transformation/spec.proto-to-assign/class/expected.js +++ /dev/null @@ -1,10 +0,0 @@ -var Foo = (function (_Bar) { - babelHelpers.inherits(Foo, _Bar); - - function Foo() { - babelHelpers.classCallCheck(this, Foo); - babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments); - } - - return Foo; -})(Bar); diff --git a/packages/babel-core/test/fixtures/transformation/strict/leading-comments-with-existing/expected.js b/packages/babel-core/test/fixtures/transformation/strict/leading-comments-with-existing/expected.js index 22c2f1d2ff..b7b3a6dec2 100644 --- a/packages/babel-core/test/fixtures/transformation/strict/leading-comments-with-existing/expected.js +++ b/packages/babel-core/test/fixtures/transformation/strict/leading-comments-with-existing/expected.js @@ -1,2 +1,4 @@ +"use strict"; + // comments module.exports = {}; diff --git a/packages/babel-core/test/fixtures/transformation/strict/leading-comments/expected.js b/packages/babel-core/test/fixtures/transformation/strict/leading-comments/expected.js index 51a1ff892d..569e4c24fc 100644 --- a/packages/babel-core/test/fixtures/transformation/strict/leading-comments/expected.js +++ b/packages/babel-core/test/fixtures/transformation/strict/leading-comments/expected.js @@ -1,3 +1,5 @@ +"use strict"; + // comments module.exports = {}; diff --git a/packages/babel-core/test/fixtures/transformation/strict/options.json b/packages/babel-core/test/fixtures/transformation/strict/options.json new file mode 100644 index 0000000000..51bfaafbee --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/strict/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["transform-strict-mode", "transform-es2015-modules-commonjs"] +} diff --git a/packages/babel-core/test/fixtures/transformation/strict/undefined-this-arrow-function/expected.js b/packages/babel-core/test/fixtures/transformation/strict/undefined-this-arrow-function/expected.js index 44969b368a..10d0543e43 100644 --- a/packages/babel-core/test/fixtures/transformation/strict/undefined-this-arrow-function/expected.js +++ b/packages/babel-core/test/fixtures/transformation/strict/undefined-this-arrow-function/expected.js @@ -1,3 +1,3 @@ -var foo = function foo() { - return undefined; -}; +"use strict"; + +var foo = () => undefined; diff --git a/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-call/expected.js b/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-call/expected.js index df77c0a95d..d6cbc49983 100644 --- a/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-call/expected.js +++ b/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-call/expected.js @@ -1 +1,3 @@ +"use strict"; + undefined.foo(); diff --git a/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-declaration/expected.js b/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-declaration/expected.js index 378357c3bf..1d38c9f2b9 100644 --- a/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-declaration/expected.js +++ b/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-declaration/expected.js @@ -1 +1,3 @@ +"use strict"; + var self = undefined; diff --git a/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-reference/expected.js b/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-reference/expected.js index c2ca02c0e2..ca6800354f 100644 --- a/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-reference/expected.js +++ b/packages/babel-core/test/fixtures/transformation/strict/undefined-this-root-reference/expected.js @@ -1 +1,3 @@ +"use strict"; + undefined; diff --git a/packages/babel-core/test/fixtures/transformation/strict/use-strict-add/expected.js b/packages/babel-core/test/fixtures/transformation/strict/use-strict-add/expected.js index a280f9a5cc..78e7c81229 100644 --- a/packages/babel-core/test/fixtures/transformation/strict/use-strict-add/expected.js +++ b/packages/babel-core/test/fixtures/transformation/strict/use-strict-add/expected.js @@ -1 +1,3 @@ +"use strict"; + foo(); diff --git a/packages/babel-core/test/fixtures/transformation/strict/use-strict-exists/actual.js b/packages/babel-core/test/fixtures/transformation/strict/use-strict-exists/actual.js index a280f9a5cc..efbccabf76 100644 --- a/packages/babel-core/test/fixtures/transformation/strict/use-strict-exists/actual.js +++ b/packages/babel-core/test/fixtures/transformation/strict/use-strict-exists/actual.js @@ -1 +1,2 @@ +"use strict"; foo(); diff --git a/packages/babel-core/test/fixtures/transformation/strict/use-strict-exists/expected.js b/packages/babel-core/test/fixtures/transformation/strict/use-strict-exists/expected.js index a280f9a5cc..78e7c81229 100644 --- a/packages/babel-core/test/fixtures/transformation/strict/use-strict-exists/expected.js +++ b/packages/babel-core/test/fixtures/transformation/strict/use-strict-exists/expected.js @@ -1 +1,3 @@ +"use strict"; + foo(); diff --git a/packages/babel-core/test/fixtures/transformation/validation.undeclared-variable-check/options.json b/packages/babel-core/test/fixtures/transformation/validation.undeclared-variable-check/options.json index 23d07f9075..9aad0a18e2 100644 --- a/packages/babel-core/test/fixtures/transformation/validation.undeclared-variable-check/options.json +++ b/packages/babel-core/test/fixtures/transformation/validation.undeclared-variable-check/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-undeclared-variables-check"] + "plugins": ["undeclared-variables-check"] } diff --git a/packages/babel-core/test/generation.js b/packages/babel-core/test/generation.js deleted file mode 100644 index b0534ab7a1..0000000000 --- a/packages/babel-core/test/generation.js +++ /dev/null @@ -1,48 +0,0 @@ -var generate = require("babel-generator"); -var fixtures = require("mocha-fixtures"); -var assert = require("assert"); -var parse = require("../lib/helpers/parse"); -var chai = require("chai"); -var t = require("babel-types"); -var _ = require("lodash"); - -suite("generation", function () { - test("completeness", function () { - _.each(t.VISITOR_KEYS, function (keys, type) { - assert.ok(!!generate.CodeGenerator.prototype[type], type + " should exist"); - }); - - _.each(generate.CodeGenerator.prototype, function (fn, type) { - if (!/[A-Z]/.test(type[0])) return; - assert.ok(t.VISITOR_KEYS[type], type + " should not exist"); - }); - }); -}); - -_.each(require("./_transformation-helper").fixtures.generation, function (testSuite) { - suite("generation/" + testSuite.title, function () { - _.each(testSuite.tests, function (task) { - test(task.title, !task.disabled && function () { - var expect = task.expect; - var actual = task.actual; - - var actualAst = parse(actual.code, { - filename: actual.loc, - nonStandard: true, - strictMode: false, - sourceType: "module", - features: { - "es7.decorators": true, - "es7.comprehensions": true, - "es7.asyncFunctions": true, - "es7.exportExtensions": true, - "es7.functionBind": true - } - }); - - var actualCode = generate(actualAst, task.options, actual.code).code; - chai.expect(actualCode).to.equal(expect.code, actual.loc + " !== " + expect.loc); - }); - }); - }); -}); diff --git a/packages/babel-core/test/path.js b/packages/babel-core/test/path.js index e203c55c9d..0bff81c7bd 100644 --- a/packages/babel-core/test/path.js +++ b/packages/babel-core/test/path.js @@ -8,11 +8,10 @@ suite("traversal path", function () { var expectCode = "function foo() {}"; var actualCode = transform(expectCode, { - blacklist: "strict", - plugins: [new Plugin("foobar", { + plugins: [new Plugin({ visitor: { - FunctionDeclaration: function () { - this.replaceWithSourceString("console.whatever()"); + FunctionDeclaration: function (path) { + path.replaceWithSourceString("console.whatever()"); } } })] diff --git a/packages/babel-core/test/traceur.js b/packages/babel-core/test/traceur.js index d2e8fdf7d8..c3a2071df8 100644 --- a/packages/babel-core/test/traceur.js +++ b/packages/babel-core/test/traceur.js @@ -22,6 +22,11 @@ require("./_transformation-helper").run("traceur", { "Yield/ObjectModel", "Yield/ReturnGenerator", + // yield as an identifier + "Yield/YieldIdentifier", + "Syntax/StrictKeywords", + "Syntax/IsValidSimpleAssignmentTarget", + // TODO: core-js fails these "Collections/Map", "Collections/Set", @@ -74,7 +79,9 @@ require("./_transformation-helper").run("traceur", { }, { }, function (opts, task) { - if (!_.contains(task.exec.loc, "module.js")) { - opts.blacklist = ["strict"]; + if (_.contains(task.exec.loc, "module.js")) { + opts.plugins.push("transform-es2015-modules-commonjs"); + } else { + opts.sourceType = "script"; } }); diff --git a/packages/babel-core/test/types.js b/packages/babel-core/test/types.js deleted file mode 100644 index de6fd42499..0000000000 --- a/packages/babel-core/test/types.js +++ /dev/null @@ -1,3 +0,0 @@ -suite("types", function () { - -}); diff --git a/packages/babel-core/test/util.js b/packages/babel-core/test/util.js index 67a51b4d5d..729eb7361f 100644 --- a/packages/babel-core/test/util.js +++ b/packages/babel-core/test/util.js @@ -4,28 +4,6 @@ var parse = require("../lib/helpers/parse"); var t = require("babel-types"); suite("util", function () { - test("invalid template", function () { - assert.throws(function () { - util.template("invalid template"); - }, /unknown template/); - }); - - test("templates do not recurse", function () { - var key = __filename; - var KEY = parse("replacedKey").program.body[0].expression; - var VALUE = parse("+KEY").program.body[0].expression; - - util.templates[key] = util.parseTemplate(key, "KEY = VALUE;"); - var result = util.template(key, { KEY: KEY, VALUE: VALUE }); - delete util.templates[key]; - - assert.strictEqual( - result.right.argument.name, - "KEY", - "template should not recurse into replaced nodes, replacing KEY inside VALUE" - ); - }); - test("canCompile", function () { assert.ok(util.canCompile("test.js")); assert.ok(util.canCompile("/test.js")); @@ -103,7 +81,6 @@ suite("util", function () { }); test("toIdentifier", function () { - assert.equal(t.toIdentifier(t.identifier("swag")), "swag"); assert.equal(t.toIdentifier("swag-lord"), "swagLord"); }); diff --git a/packages/babel-generator/package.json b/packages/babel-generator/package.json index fdafee3b9d..1b709802a6 100644 --- a/packages/babel-generator/package.json +++ b/packages/babel-generator/package.json @@ -1,6 +1,6 @@ { "name": "babel-generator", - "version": "5.8.22", + "version": "5.10.32", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,9 +8,9 @@ "repository": "babel/babel", "main": "lib/index.js", "dependencies": { - "babel-messages": "^5.8.22", - "babel-runtime": "^5.8.20", - "babel-types": "^5.8.22", + "babel-messages": "^5.10.32", + "babel-runtime": "^5.10.32", + "babel-types": "^5.10.32", "detect-indent": "^3.0.1", "is-integer": "^1.0.4", "lodash": "^3.10.1", @@ -21,4 +21,4 @@ "devDependencies": { "babel-helper-fixtures": "^1.0.0" } -} +} \ No newline at end of file diff --git a/packages/babel-generator/src/buffer.js b/packages/babel-generator/src/buffer.js index 7d521f9ef1..a0a0a7b550 100644 --- a/packages/babel-generator/src/buffer.js +++ b/packages/babel-generator/src/buffer.js @@ -10,6 +10,7 @@ import trimRight from "trim-right"; export default class Buffer { constructor(position: Position, format: Object) { + this.printedCommentStarts = {}; this.parenPushNewlineState = null; this.position = position; this._indent = format.indent.base; @@ -102,6 +103,7 @@ export default class Buffer { rightBrace() { this.newline(true); + //if (this.format.compact) this._removeLast(";"); this.push("}"); } @@ -132,8 +134,11 @@ export default class Buffer { removeLast(cha: string) { if (this.format.compact) return; - if (!this.isLast(cha)) return; + return this._removeLast(cha); + } + _removeLast(cha: string) { + if (!this._isLast(cha)) return; this.buf = this.buf.substr(0, this.buf.length - 1); this.position.unshift(cha); } @@ -316,7 +321,10 @@ export default class Buffer { isLast(cha: string) { if (this.format.compact) return false; + return this._isLast(cha); + } + _isLast(cha: string) { let buf = this.buf; let last = buf[buf.length - 1]; diff --git a/packages/babel-generator/src/generators/base.js b/packages/babel-generator/src/generators/base.js index f1ee541a26..d9f9ea2664 100644 --- a/packages/babel-generator/src/generators/base.js +++ b/packages/babel-generator/src/generators/base.js @@ -6,7 +6,10 @@ export function File(node: Object) { export function Program(node: Object) { this.printInnerComments(node, false); + this.printSequence(node.directives, node); + if (node.directives && node.directives.length) this.newline(); + this.printSequence(node.body, node); } @@ -15,7 +18,10 @@ export function BlockStatement(node: Object) { this.printInnerComments(node); if (node.body.length) { this.newline(); + this.printSequence(node.directives, node, { indent: true }); + if (node.directives && node.directives.length) this.newline(); + this.printSequence(node.body, node, { indent: true }); if (!this.format.retainLines) this.removeLast("\n"); this.rightBrace(); diff --git a/packages/babel-generator/src/generators/classes.js b/packages/babel-generator/src/generators/classes.js index f692bc10a4..c1bb4cf0f3 100644 --- a/packages/babel-generator/src/generators/classes.js +++ b/packages/babel-generator/src/generators/classes.js @@ -59,12 +59,16 @@ export function ClassProperty(node: Object) { this.semicolon(); } -export function MethodDefinition(node: Object) { +export function ClassMethod(node: Object) { this.printJoin(node.decorators, node, { separator: "" }); if (node.static) { this.push("static "); } + if (node.kind === "constructorCall") { + this.push("call "); + } + this._method(node); } diff --git a/packages/babel-generator/src/generators/expressions.js b/packages/babel-generator/src/generators/expressions.js index ea51bacc65..b3c1052335 100644 --- a/packages/babel-generator/src/generators/expressions.js +++ b/packages/babel-generator/src/generators/expressions.js @@ -3,6 +3,7 @@ import isInteger from "is-integer"; import isNumber from "lodash/lang/isNumber"; import * as t from "babel-types"; +import n from "../node"; const SCIENTIFIC_NOTATION = /e/i; @@ -107,7 +108,7 @@ export function CallExpression(node: Object) { this.push(")"); } -function buildYieldAwait(keyword) { +function buildYieldAwait(keyword: string) { return function (node: Object) { this.push(keyword); @@ -142,7 +143,16 @@ export function AssignmentPattern(node: Object) { this.print(node.right, node); } -export function AssignmentExpression(node: Object) { +export function AssignmentExpression(node: Object, parent: Object) { + // Somewhere inside a for statement `init` node but doesn't usually + // needs a paren except for `in` expressions: `for (a in b ? a : b;;)` + let parens = this._inForStatementInit && node.operator === "in" && + !n.needsParens(node, parent); + + if (parens) { + this.push("("); + } + this.print(node.left, node); let spaces = !this.format.compact || node.operator === "in" || node.operator === "instanceof"; @@ -162,6 +172,10 @@ export function AssignmentExpression(node: Object) { if (spaces) this.push(" "); this.print(node.right, node); + + if (parens) { + this.push(")"); + } } export function BindExpression(node: Object) { @@ -193,7 +207,7 @@ export function MemberExpression(node: Object) { this.push("]"); } else { if (t.isLiteral(node.object)) { - let val = this._stringLiteral(node.object); + let val = this.getPossibleRaw(node.object) || this._stringLiteral(node.object); if (isInteger(+val) && !SCIENTIFIC_NOTATION.test(val) && !this.endsWith(".")) { this.push("."); } diff --git a/packages/babel-generator/src/generators/methods.js b/packages/babel-generator/src/generators/methods.js index a78d7ce927..cb5cf36e29 100644 --- a/packages/babel-generator/src/generators/methods.js +++ b/packages/babel-generator/src/generators/methods.js @@ -19,12 +19,11 @@ export function _params(node: Object) { } export function _method(node: Object) { - let value = node.value; - let kind = node.kind; - let key = node.key; + let kind = node.kind; + let key = node.key; if (kind === "method" || kind === "init") { - if (value.generator) { + if (node.generator) { this.push("*"); } } @@ -33,7 +32,7 @@ export function _method(node: Object) { this.push(kind + " "); } - if (value.async) this.push("async "); + if (node.async) this.push("async "); if (node.computed) { this.push("["); @@ -43,9 +42,9 @@ export function _method(node: Object) { this.print(key, node); } - this._params(value); + this._params(node); this.space(); - this.print(value.body, value); + this.print(node.body, node); } export function FunctionExpression(node: Object) { diff --git a/packages/babel-generator/src/generators/modules.js b/packages/babel-generator/src/generators/modules.js index 860b720c87..87aace643f 100644 --- a/packages/babel-generator/src/generators/modules.js +++ b/packages/babel-generator/src/generators/modules.js @@ -64,13 +64,18 @@ function ExportDeclaration(node: Object) { let specifiers = node.specifiers.slice(0); - let first = specifiers[0]; + // print "special" specifiers first let hasSpecial = false; - if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) { - hasSpecial = true; - this.print(specifiers.shift(), node); - if (specifiers.length) { - this.push(", "); + while (true) { + let first = specifiers[0]; + if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) { + hasSpecial = true; + this.print(specifiers.shift(), node); + if (specifiers.length) { + this.push(", "); + } + } else { + break; } } @@ -102,11 +107,16 @@ export function ImportDeclaration(node: Object) { let specifiers = node.specifiers.slice(0); if (specifiers && specifiers.length) { - let first = specifiers[0]; - if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) { - this.print(specifiers.shift(), node); - if (specifiers.length) { - this.push(", "); + // print "special" specifiers first + while (true) { + let first = specifiers[0]; + if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) { + this.print(specifiers.shift(), node); + if (specifiers.length) { + this.push(", "); + } + } else { + break; } } diff --git a/packages/babel-generator/src/generators/statements.js b/packages/babel-generator/src/generators/statements.js index 508a00ab59..1f1648b139 100644 --- a/packages/babel-generator/src/generators/statements.js +++ b/packages/babel-generator/src/generators/statements.js @@ -31,7 +31,9 @@ export function ForStatement(node: Object) { this.keyword("for"); this.push("("); + this._inForStatementInit = true; this.print(node.init, node); + this._inForStatementInit = false; this.push(";"); if (node.test) { diff --git a/packages/babel-generator/src/generators/types.js b/packages/babel-generator/src/generators/types.js index a4c6881e07..0c0a29c5ae 100644 --- a/packages/babel-generator/src/generators/types.js +++ b/packages/babel-generator/src/generators/types.js @@ -36,38 +36,39 @@ export function ObjectExpression(node: Object) { export { ObjectExpression as ObjectPattern }; -export function Property(node: Object) { +export function ObjectMethod(node: Object) { + this.printJoin(node.decorators, node, { separator: "" }); + this._method(node); +} + +export function ObjectProperty(node: Object) { this.printJoin(node.decorators, node, { separator: "" }); - if (node.method || node.kind === "get" || node.kind === "set") { - this._method(node); + if (node.computed) { + this.push("["); + this.print(node.key, node); + this.push("]"); } else { - if (node.computed) { - this.push("["); - this.print(node.key, node); - this.push("]"); - } else { - // print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});` - if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) { - this.print(node.value, node); - return; - } - - this.print(node.key, node); - - // shorthand! - if (node.shorthand && - (t.isIdentifier(node.key) && - t.isIdentifier(node.value) && - node.key.name === node.value.name)) { - return; - } + // print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});` + if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) { + this.print(node.value, node); + return; } - this.push(":"); - this.space(); - this.print(node.value, node); + this.print(node.key, node); + + // shorthand! + if (node.shorthand && + (t.isIdentifier(node.key) && + t.isIdentifier(node.value) && + node.key.name === node.value.name)) { + return; + } } + + this.push(":"); + this.space(); + this.print(node.value, node); } export function ArrayExpression(node: Object) { diff --git a/packages/babel-generator/src/index.js b/packages/babel-generator/src/index.js index a9a9a1783f..c76f7ee864 100644 --- a/packages/babel-generator/src/index.js +++ b/packages/babel-generator/src/index.js @@ -39,6 +39,7 @@ export class CodeGenerator extends Printer { shouldPrintComment: boolean; retainLines: boolean; comments: boolean; + auxiliaryComment: string; compact: boolean | "auto"; quotes: "single" | "double"; concise: boolean; @@ -49,6 +50,7 @@ export class CodeGenerator extends Printer { } }; + auxiliaryComment: string; whitespace: Whitespace; position: Position; map: SourceMap; @@ -72,6 +74,7 @@ export class CodeGenerator extends Printer { } let format = { + auxiliaryComment: opts.auxiliaryComment, shouldPrintComment: opts.shouldPrintComment, retainLines: opts.retainLines, comments: opts.comments == null || opts.comments, diff --git a/packages/babel-generator/src/node/parentheses.js b/packages/babel-generator/src/node/parentheses.js index 685ed247a2..c0f55c498e 100644 --- a/packages/babel-generator/src/node/parentheses.js +++ b/packages/babel-generator/src/node/parentheses.js @@ -82,7 +82,8 @@ export function Binary(node: Object, parent: Object): boolean { return true; } - if (parentPos === nodePos && parent.right === node) { + // Logical expressions with the same precedence don't need parens. + if (parentPos === nodePos && parent.right === node && !t.isLogicalExpression(parent)) { return true; } } @@ -119,6 +120,10 @@ export function SequenceExpression(node: Object, parent: Object): boolean { return false; } + if (t.isReturnStatement(parent)) { + return false; + } + // Otherwise err on the side of overparenthesization, adding // explicit exceptions above if this proves overzealous. return true; diff --git a/packages/babel-generator/src/node/whitespace.js b/packages/babel-generator/src/node/whitespace.js index b9ac11f2e8..0866d4e23e 100644 --- a/packages/babel-generator/src/node/whitespace.js +++ b/packages/babel-generator/src/node/whitespace.js @@ -163,7 +163,8 @@ exports.nodes = { * Test if Property or SpreadProperty needs whitespace. */ -exports.nodes.Property = +exports.nodes.ObjectProperty = +exports.nodes.ObjectMethod = exports.nodes.SpreadProperty = function (node, parent) { if (parent.properties[0] === node) { return { diff --git a/packages/babel-generator/src/printer.js b/packages/babel-generator/src/printer.js index 949d1dc3eb..e55fe33e30 100644 --- a/packages/babel-generator/src/printer.js +++ b/packages/babel-generator/src/printer.js @@ -6,6 +6,11 @@ import n from "./node"; import * as t from "babel-types"; export default class Printer extends Buffer { + constructor(...args) { + super(...args); + this.insideAux = false; + } + print(node, parent, opts = {}) { if (!node) return; @@ -13,6 +18,9 @@ export default class Printer extends Buffer { node._compact = true; } + let oldInAux = this.insideAux; + this.insideAux = !node.loc; + let oldConcise = this.format.concise; if (node._compact) { this.format.concise = true; @@ -23,6 +31,8 @@ export default class Printer extends Buffer { throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`); } + this.printAuxComment(oldInAux); + let needsParens = n.needsParens(node, parent); if (needsParens) this.push("("); @@ -33,28 +43,47 @@ export default class Printer extends Buffer { this._printNewline(true, node, parent, opts); if (opts.before) opts.before(); + this.map.mark(node, "start"); - // this._print(node, parent); + this.printTrailingComments(node, parent); + if (needsParens) this.push(")"); + // end this.map.mark(node, "end"); if (opts.after) opts.after(); this.format.concise = oldConcise; + this.insideAux = oldInAux; this._printNewline(false, node, parent, opts); + } - this.printTrailingComments(node, parent); + printAuxComment(wasInAux) { + let comment = this.format.auxiliaryComment; + if (comment && !wasInAux && this.insideAux) { + this.printComment({ + type: "CommentBlock", + value: comment + }); + } + } + + getPossibleRaw(node) { + let extra = node.extra; + if (extra && extra.raw != null && extra.rawValue != null && node.value === extra.rawValue) { + return extra.raw; + } } _print(node, parent) { - let extra = node.extra; - if (extra && extra.raw != null && extra.rawValue != null && node.value === extra.rawValue) { + let extra = this.getPossibleRaw(node); + if (extra) { this.push(""); - this._push(extra.raw); + this._push(extra); } else { let printMethod = this[node.type]; printMethod.call(this, node, parent); @@ -119,17 +148,17 @@ export default class Printer extends Buffer { } printTrailingComments(node, parent) { - this._printComments(this.getComments("trailingComments", node, parent)); + this.printComments(this.getComments("trailingComments", node, parent)); } printLeadingComments(node, parent) { - this._printComments(this.getComments("leadingComments", node, parent)); + this.printComments(this.getComments("leadingComments", node, parent)); } printInnerComments(node, indent = true) { if (!node.innerComments) return; if (indent) this.indent(); - this._printComments(node.innerComments); + this.printComments(node.innerComments); if (indent) this.dedent(); } @@ -177,26 +206,7 @@ export default class Printer extends Buffer { this.newline(lines); } - getComments(key, node, parent) { - if (t.isExpressionStatement(parent)) { - return []; - } - - let comments = []; - let nodes: Array = [node]; - - if (t.isExpressionStatement(node)) { - nodes.push(node.argument); - } - - for (let node of nodes) { - comments = comments.concat(this._getComments(key, node)); - } - - return comments; - } - - _getComments(key, node) { + getComments(key, node) { return (node && node[key]) || []; } @@ -212,54 +222,64 @@ export default class Printer extends Buffer { } } - _printComments(comments) { + printComment(comment) { + if (!this.shouldPrintComment(comment)) return; + + if (comment.ignore) return; + comment.ignore = true; + + if (comment.start != null) { + if (this.printedCommentStarts[comment.start]) return; + this.printedCommentStarts[comment.start] = true; + } + + this.catchUp(comment); + + // whitespace before + this.newline(this.whitespace.getNewlinesBefore(comment)); + + let column = this.position.column; + let val = this.generateComment(comment); + + if (column && !this.isLast(["\n", " ", "[", "{"])) { + this._push(" "); + column++; + } + + // + if (comment.type === "CommentBlock" && this.format.indent.adjustMultilineComment) { + let offset = comment.loc && comment.loc.start.column; + if (offset) { + let newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g"); + val = val.replace(newlineRegex, "\n"); + } + + let indent = Math.max(this.indentSize(), column); + val = val.replace(/\n/g, `\n${repeating(" ", indent)}`); + } + + if (column === 0) { + val = this.getIndent() + val; + } + + // force a newline for line comments when retainLines is set in case the next printed node + // doesn't catch up + if ((this.format.compact || this.format.retainLines) && comment.type === "CommentLine") { + val += "\n"; + } + + // + this._push(val); + + // whitespace after + this.newline(this.whitespace.getNewlinesAfter(comment)); + } + + printComments(comments?: Array) { if (!comments || !comments.length) return; - for (let comment of (comments: Array)) { - if (!this.shouldPrintComment(comment)) continue; - if (comment._displayed) continue; - comment._displayed = true; - - this.catchUp(comment); - - // whitespace before - this.newline(this.whitespace.getNewlinesBefore(comment)); - - let column = this.position.column; - let val = this.generateComment(comment); - - if (column && !this.isLast(["\n", " ", "[", "{"])) { - this._push(" "); - column++; - } - - // - if (comment.type === "CommentBlock" && this.format.indent.adjustMultilineComment) { - let offset = comment.loc && comment.loc.start.column; - if (offset) { - let newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g"); - val = val.replace(newlineRegex, "\n"); - } - - let indent = Math.max(this.indentSize(), column); - val = val.replace(/\n/g, `\n${repeating(" ", indent)}`); - } - - if (column === 0) { - val = this.getIndent() + val; - } - - // force a newline for line comments when retainLines is set in case the next printed node - // doesn't catch up - if ((this.format.compact || this.format.retainLines) && comment.type === "CommentLine") { - val += "\n"; - } - - // - this._push(val); - - // whitespace after - this.newline(this.whitespace.getNewlinesAfter(comment)); + for (let comment of comments) { + this.printComment(comment); } } } diff --git a/packages/babel-generator/test/fixtures/comments/function-block-line-comment/expected.js b/packages/babel-generator/test/fixtures/comments/function-block-line-comment/expected.js index d6802cba24..f37f446d86 100644 --- a/packages/babel-generator/test/fixtures/comments/function-block-line-comment/expected.js +++ b/packages/babel-generator/test/fixtures/comments/function-block-line-comment/expected.js @@ -1,6 +1,6 @@ -!function () {}, // -42; -!{ get 42() {}, // - foo: 42 }; -(function () {}); -// +!function () {} // +, 42; +!{ get 42() {} // + , foo: 42 }; +(function () {} // +); diff --git a/packages/babel-generator/test/fixtures/compact/no-semicolon/actual.js b/packages/babel-generator/test/fixtures/compact/no-semicolon/actual.js new file mode 100644 index 0000000000..85240b60d1 --- /dev/null +++ b/packages/babel-generator/test/fixtures/compact/no-semicolon/actual.js @@ -0,0 +1,6 @@ +function foo() { + if (bar) { + baz(); + } + return; +} diff --git a/packages/babel-generator/test/fixtures/compact/no-semicolon/expected.js b/packages/babel-generator/test/fixtures/compact/no-semicolon/expected.js new file mode 100644 index 0000000000..0fdf371f55 --- /dev/null +++ b/packages/babel-generator/test/fixtures/compact/no-semicolon/expected.js @@ -0,0 +1 @@ +function foo(){if(bar){baz();}return;} diff --git a/packages/babel-generator/test/fixtures/edgecase/for-in-no-in/actual.js b/packages/babel-generator/test/fixtures/edgecase/for-in-no-in/actual.js index f84b95ae6b..e454ee16a4 100644 --- a/packages/babel-generator/test/fixtures/edgecase/for-in-no-in/actual.js +++ b/packages/babel-generator/test/fixtures/edgecase/for-in-no-in/actual.js @@ -1,9 +1,9 @@ -for (var i = (1 in []) in []); -for (var i = 1 in [] in []); -for (var i = (10 * 10 in []) in []); -for (var i = (10 + 10 in []) in []); -for (var i = 10 + (10 in []) in []); -for (var i = 10 + 10 in [] in []); +//for (var i = (1 in []) in []); +//for (var i = 1 in [] in []); +//for (var i = (10 * 10 in []) in []); +//for (var i = (10 + 10 in []) in []); +//for (var i = 10 + (10 in []) in []); +//for (var i = 10 + 10 in [] in []); for (var i = (1 in []);;); for ((1 in []);;); for (1 * (1 in []);;); diff --git a/packages/babel-generator/test/fixtures/edgecase/for-in-no-in/expected.js b/packages/babel-generator/test/fixtures/edgecase/for-in-no-in/expected.js index 029b11e515..eccabee07d 100644 --- a/packages/babel-generator/test/fixtures/edgecase/for-in-no-in/expected.js +++ b/packages/babel-generator/test/fixtures/edgecase/for-in-no-in/expected.js @@ -1,9 +1,9 @@ -for (var i = (1 in []) in []); -for (var i = 1 in ([] in [])); -for (var i = (10 * 10 in []) in []); -for (var i = (10 + 10 in []) in []); -for (var i = 10 + (10 in []) in []); -for (var i = 10 + 10 in ([] in [])); +//for (var i = (1 in []) in []); +//for (var i = 1 in [] in []); +//for (var i = (10 * 10 in []) in []); +//for (var i = (10 + 10 in []) in []); +//for (var i = 10 + (10 in []) in []); +//for (var i = 10 + 10 in [] in []); for (var i = (1 in []);;); for ((1 in []);;); for (1 * (1 in []);;); diff --git a/packages/babel-generator/test/fixtures/edgecase/for-loop-in/actual.js b/packages/babel-generator/test/fixtures/edgecase/for-loop-in/actual.js new file mode 100644 index 0000000000..da5079a95f --- /dev/null +++ b/packages/babel-generator/test/fixtures/edgecase/for-loop-in/actual.js @@ -0,0 +1 @@ +for ((a in b) ? a : b; i;); diff --git a/packages/babel-generator/test/fixtures/edgecase/for-loop-in/expected.js b/packages/babel-generator/test/fixtures/edgecase/for-loop-in/expected.js new file mode 100644 index 0000000000..da5079a95f --- /dev/null +++ b/packages/babel-generator/test/fixtures/edgecase/for-loop-in/expected.js @@ -0,0 +1 @@ +for ((a in b) ? a : b; i;); diff --git a/packages/babel-generator/test/fixtures/parentheses/expression/actual.js b/packages/babel-generator/test/fixtures/parentheses/expression/actual.js new file mode 100644 index 0000000000..8a2b727e0e --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/expression/actual.js @@ -0,0 +1 @@ +a && (a.b && a.b.c()); diff --git a/packages/babel-generator/test/fixtures/parentheses/expression/expected.js b/packages/babel-generator/test/fixtures/parentheses/expression/expected.js new file mode 100644 index 0000000000..56580c5211 --- /dev/null +++ b/packages/babel-generator/test/fixtures/parentheses/expression/expected.js @@ -0,0 +1 @@ +a && a.b && a.b.c(); diff --git a/packages/babel-generator/test/fixtures/types/ReturnStatement/actual.js b/packages/babel-generator/test/fixtures/types/ReturnStatement/actual.js index 404a7c2e64..338c84b966 100644 --- a/packages/babel-generator/test/fixtures/types/ReturnStatement/actual.js +++ b/packages/babel-generator/test/fixtures/types/ReturnStatement/actual.js @@ -5,3 +5,7 @@ function foo() { function bar() { return "foo"; } + +function foo() { + return 1, "foo"; +} diff --git a/packages/babel-generator/test/fixtures/types/ReturnStatement/expected.js b/packages/babel-generator/test/fixtures/types/ReturnStatement/expected.js index 404a7c2e64..338c84b966 100644 --- a/packages/babel-generator/test/fixtures/types/ReturnStatement/expected.js +++ b/packages/babel-generator/test/fixtures/types/ReturnStatement/expected.js @@ -5,3 +5,7 @@ function foo() { function bar() { return "foo"; } + +function foo() { + return 1, "foo"; +} diff --git a/packages/babel-generator/test/index.js b/packages/babel-generator/test/index.js index 2eb653eea9..aafeb00e5a 100644 --- a/packages/babel-generator/test/index.js +++ b/packages/babel-generator/test/index.js @@ -36,6 +36,7 @@ suites.forEach(function (testSuite) { "asyncFunctions", "exportExtensions", "functionBind", + "classConstructorCall", ], strictMode: false, sourceType: "module", diff --git a/packages/babel-helper-bindify-decorators/README.md b/packages/babel-helper-bindify-decorators/README.md new file mode 100644 index 0000000000..c9852822df --- /dev/null +++ b/packages/babel-helper-bindify-decorators/README.md @@ -0,0 +1,5 @@ +# babel-helper-bindify-decorators + +## Usage + +TODO diff --git a/packages/babel-helper-bindify-decorators/package.json b/packages/babel-helper-bindify-decorators/package.json new file mode 100644 index 0000000000..68b40a836b --- /dev/null +++ b/packages/babel-helper-bindify-decorators/package.json @@ -0,0 +1,13 @@ +{ + "name": "babel-helper-bindify-decorators", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.8.20", + "babel-traverse": "^5.8.20", + "babel-types": "^5.8.20" + } +} diff --git a/packages/babel-helper-bindify-decorators/src/index.js b/packages/babel-helper-bindify-decorators/src/index.js new file mode 100644 index 0000000000..564126fbe3 --- /dev/null +++ b/packages/babel-helper-bindify-decorators/src/index.js @@ -0,0 +1,36 @@ +import type { NodePath } from "babel-traverse" +import * as t from "babel-types"; + +export default function bindifyDecorators(decorators: Array): Array { + for (let decoratorPath of decorators) { + let decorator = decoratorPath.node; + let expression = decorator.expression; + if (!t.isMemberExpression(expression)) continue; + + let temp = decoratorPath.scope.maybeGenerateMemoised(expression.object); + let ref; + + let nodes = []; + + if (temp) { + ref = temp; + nodes.push(t.assignmentExpression("=", temp, expression.object)); + } else { + ref = expression.object; + } + + nodes.push(t.callExpression( + t.memberExpression( + t.memberExpression(ref, expression.property, expression.computed), + t.identifier("bind") + ), + [ref] + )); + + if (nodes.length === 1) { + decorator.expression = nodes[0]; + } else { + decorator.expression = t.sequenceExpression(nodes); + } + } +} diff --git a/packages/babel-helper-builder-binary-assignment-operator-visitor/README.md b/packages/babel-helper-builder-binary-assignment-operator-visitor/README.md new file mode 100644 index 0000000000..812f886e6d --- /dev/null +++ b/packages/babel-helper-builder-binary-assignment-operator-visitor/README.md @@ -0,0 +1,5 @@ +# babel-helper-builder-binary-assignment-operator-visitor + +## Usage + +TODO diff --git a/packages/babel-helper-builder-binary-assignment-operator-visitor/package.json b/packages/babel-helper-builder-binary-assignment-operator-visitor/package.json new file mode 100644 index 0000000000..84d8d423b9 --- /dev/null +++ b/packages/babel-helper-builder-binary-assignment-operator-visitor/package.json @@ -0,0 +1,13 @@ +{ + "name": "babel-helper-builder-binary-assignment-operator-visitor", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-helper-explode-assignable-expression": "^5.8.20", + "babel-runtime": "^5.8.20", + "babel-types": "^5.8.20" + } +} diff --git a/packages/babel-core/src/transformation/helpers/build-binary-assignment-operator-transformer.js b/packages/babel-helper-builder-binary-assignment-operator-visitor/src/index.js similarity index 59% rename from packages/babel-core/src/transformation/helpers/build-binary-assignment-operator-transformer.js rename to packages/babel-helper-builder-binary-assignment-operator-visitor/src/index.js index 689d3467f8..810451fc62 100644 --- a/packages/babel-core/src/transformation/helpers/build-binary-assignment-operator-transformer.js +++ b/packages/babel-helper-builder-binary-assignment-operator-visitor/src/index.js @@ -1,23 +1,23 @@ /* @flow */ -import explode from "./explode-assignable-expression"; +import explode from "babel-helper-explode-assignable-expression"; import * as t from "babel-types"; export default function (opts: { build: Function; operator: string; }): Object { - let exports = {}; + let visitor = {}; - let isAssignment = function (node) { + function isAssignment(node) { return node.operator === opts.operator + "="; - }; + } - let buildAssignment = function (left, right) { + function buildAssignment(left, right) { return t.assignmentExpression("=", left, right); - }; + } - exports.ExpressionStatement = function (path, file) { + visitor.ExpressionStatement = function (path, file) { // hit the `AssignmentExpression` one below if (path.isCompletionRecord()) return; @@ -31,22 +31,25 @@ export default function (opts: { buildAssignment(exploded.ref, opts.build(exploded.uid, expr.right)) )); - return nodes; + path.replaceWithMultiple(nodes); }; - exports.AssignmentExpression = function ({ node, scope }, file) { + visitor.AssignmentExpression = function (path, file) { + let { node, scope } = path; if (!isAssignment(node)) return; let nodes = []; let exploded = explode(node.left, nodes, file, scope); nodes.push(buildAssignment(exploded.ref, opts.build(exploded.uid, node.right))); - return nodes; + path.replaceWithMultiple(nodes); }; - exports.BinaryExpression = function ({ node }) { - if (node.operator !== opts.operator) return; - return opts.build(node.left, node.right); + visitor.BinaryExpression = function (path) { + let { node } = path; + if (node.operator === opts.operator) { + path.replaceWith(opts.build(node.left, node.right)); + } }; - return exports; + return visitor; } diff --git a/packages/babel-helper-builder-conditional-assignment-operator-visitor/README.md b/packages/babel-helper-builder-conditional-assignment-operator-visitor/README.md new file mode 100644 index 0000000000..f9d44147c3 --- /dev/null +++ b/packages/babel-helper-builder-conditional-assignment-operator-visitor/README.md @@ -0,0 +1,5 @@ +# babel-helper-builder-conditional-assignment-operator-visitor + +## Usage + +TODO diff --git a/packages/babel-helper-builder-conditional-assignment-operator-visitor/package.json b/packages/babel-helper-builder-conditional-assignment-operator-visitor/package.json new file mode 100644 index 0000000000..aa809e85cc --- /dev/null +++ b/packages/babel-helper-builder-conditional-assignment-operator-visitor/package.json @@ -0,0 +1,13 @@ +{ + "name": "babel-helper-builder-conditional-assignment-operator-visitor", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-helper-explode-assignable-expression": "^5.8.20", + "babel-runtime": "^5.8.20", + "babel-types": "^5.8.20" + } +} diff --git a/packages/babel-core/src/transformation/helpers/build-conditional-assignment-operator-transformer.js b/packages/babel-helper-builder-conditional-assignment-operator-visitor/src/index.js similarity index 94% rename from packages/babel-core/src/transformation/helpers/build-conditional-assignment-operator-transformer.js rename to packages/babel-helper-builder-conditional-assignment-operator-visitor/src/index.js index b8172ef5e3..1c54314a60 100644 --- a/packages/babel-core/src/transformation/helpers/build-conditional-assignment-operator-transformer.js +++ b/packages/babel-helper-builder-conditional-assignment-operator-visitor/src/index.js @@ -1,6 +1,6 @@ /* @flow */ -import explode from "./explode-assignable-expression"; +import explode from "babel-helper-explode-assignable-expression"; import * as t from "babel-types"; export default function ( diff --git a/packages/babel-plugin-builder-react-jsx/README.md b/packages/babel-helper-builder-react-jsx/README.md similarity index 64% rename from packages/babel-plugin-builder-react-jsx/README.md rename to packages/babel-helper-builder-react-jsx/README.md index 41fa28bf58..895857ec4c 100644 --- a/packages/babel-plugin-builder-react-jsx/README.md +++ b/packages/babel-helper-builder-react-jsx/README.md @@ -1,4 +1,4 @@ -# babel-plugin-builder-react-jsx +# babel-helper-builder-react-jsx ## Usage @@ -8,9 +8,11 @@ type ElementState = { tagName: string; // raw string tag name args: Array; // array of call arguments call?: Object; // optional call property that can be set to override the call expression returned + pre?: Function; // function called with (state: ElementState) before building attribs + post?: Function; // function called with (state: ElementState) after building attribs }; -require("babel-plugin-builder-react-jsx")({ +require("babel-helper-builder-react-jsx")({ pre: function (state: ElementState) { // called before building the element }, diff --git a/packages/babel-plugin-builder-react-jsx/package.json b/packages/babel-helper-builder-react-jsx/package.json similarity index 75% rename from packages/babel-plugin-builder-react-jsx/package.json rename to packages/babel-helper-builder-react-jsx/package.json index 2ff46f80bc..6e57234438 100644 --- a/packages/babel-plugin-builder-react-jsx/package.json +++ b/packages/babel-helper-builder-react-jsx/package.json @@ -1,5 +1,5 @@ { - "name": "babel-plugin-builder-react-jsx", + "name": "babel-helper-builder-react-jsx", "version": "1.0.0", "description": "", "repository": "babel/babel", @@ -7,6 +7,7 @@ "main": "lib/index.js", "dependencies": { "babel-runtime": "^5.8.20", + "babel-types": "^5.8.20", "esutils": "^2.0.0", "lodash": "^3.10.0" } diff --git a/packages/babel-plugin-builder-react-jsx/src/index.js b/packages/babel-helper-builder-react-jsx/src/index.js similarity index 67% rename from packages/babel-plugin-builder-react-jsx/src/index.js rename to packages/babel-helper-builder-react-jsx/src/index.js index 7eb9f43691..645c44a6da 100644 --- a/packages/babel-plugin-builder-react-jsx/src/index.js +++ b/packages/babel-helper-builder-react-jsx/src/index.js @@ -1,8 +1,20 @@ +/* @flow */ + import isString from "lodash/lang/isString"; import esutils from "esutils"; +import * as t from "babel-types"; -export default function (t, opts) { - var visitor = {}; +type ElementState = { + tagExpr: Object; // tag node + tagName: string; // raw string tag name + args: Array; // array of call arguments + call?: Object; // optional call property that can be set to override the call expression returned + pre?: Function; // function called with (state: ElementState) before building attribs + post?: Function; // function called with (state: ElementState) after building attribs +}; + +export default function (opts) { + let visitor = {}; visitor.JSXNamespacedName = function (path) { throw path.buildCodeFrameError("Namespace tags are not supported. ReactJSX is not XML."); @@ -10,7 +22,7 @@ export default function (t, opts) { visitor.JSXElement = { exit(path, file) { - var callExpr = buildElementCall(path.get("openingElement"), file); + let callExpr = buildElementCall(path.get("openingElement"), file); callExpr.arguments = callExpr.arguments.concat(path.node.children); @@ -18,26 +30,26 @@ export default function (t, opts) { callExpr._prettyCall = true; } - return t.inherits(callExpr, path.node); + path.replaceWith(t.inherits(callExpr, path.node)); } }; return visitor; - function convertFunctionName(path) { - var { node } = path; - - if (path.isJSXIdentifier()) { - if (node.name === "this" && path.isReferenced()) { + function convertJSXIdentifier(node, parent) { + if (t.isJSXIdentifier(node)) { + if (node.name === "this" && t.isReferenced(node, parent)) { return t.thisExpression(); } else if (esutils.keyword.isIdentifierNameES6(node.name)) { node.type = "Identifier"; } else { return t.stringLiteral(node.name); } - } else if (path.isJSXMemberExpression()) { - node.computed = t.isLiteral(node.property); - node.type = "MemberExpression"; + } else if (t.isJSXMemberExpression(node)) { + return t.memberExpression( + convertJSXIdentifier(node.object, node), + convertJSXIdentifier(node.property, node) + ); } return node; @@ -52,7 +64,7 @@ export default function (t, opts) { } function convertAttribute(node) { - var value = convertAttributeValue(node.value || t.booleanLiteral(true)); + let value = convertAttributeValue(node.value || t.booleanLiteral(true)); if (t.isLiteral(value) && isString(value.value)) { value.value = value.value.replace(/\n\s+/g, " "); @@ -60,23 +72,23 @@ export default function (t, opts) { node.name.type = "Identifier"; - return t.inherits(t.property("init", node.name, value), node); + return t.inherits(t.objectProperty(node.name, value), node); } function buildElementCall(path, file) { path.parent.children = t.react.buildChildren(path.parent); - var tagExpr = convertFunctionName(path.get("name")); - var args = []; + let tagExpr = convertJSXIdentifier(path.node.name, path.node); + let args = []; - var tagName; + let tagName; if (t.isIdentifier(tagExpr)) { tagName = tagExpr.name; } else if (t.isLiteral(tagExpr)) { tagName = tagExpr.value; } - var state = { + let state: ElementState = { tagExpr: tagExpr, tagName: tagName, args: args @@ -86,7 +98,7 @@ export default function (t, opts) { opts.pre(state, file); } - var attribs = path.node.attributes; + let attribs = path.node.attributes; if (attribs.length) { attribs = buildOpeningElementAttributes(attribs, file); } else { @@ -110,8 +122,8 @@ export default function (t, opts) { */ function buildOpeningElementAttributes(attribs, file) { - var _props = []; - var objs = []; + let _props = []; + let objs = []; function pushProps() { if (!_props.length) return; @@ -121,7 +133,7 @@ export default function (t, opts) { } while (attribs.length) { - var prop = attribs.shift(); + let prop = attribs.shift(); if (t.isJSXSpreadAttribute(prop)) { pushProps(); objs.push(prop.argument); diff --git a/packages/babel-helper-call-delegate/README.md b/packages/babel-helper-call-delegate/README.md new file mode 100644 index 0000000000..0841d07342 --- /dev/null +++ b/packages/babel-helper-call-delegate/README.md @@ -0,0 +1,5 @@ +# babel-helper-call-delegate + +## Usage + +TODO diff --git a/packages/babel-helper-call-delegate/package.json b/packages/babel-helper-call-delegate/package.json new file mode 100644 index 0000000000..903216a522 --- /dev/null +++ b/packages/babel-helper-call-delegate/package.json @@ -0,0 +1,14 @@ +{ + "name": "babel-helper-call-delegate", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-traverse": "^5.8.20", + "babel-runtime": "^5.8.20", + "babel-types": "^5.8.20", + "babel-helper-hoist-variables": "^5.0.0" + } +} diff --git a/packages/babel-helper-call-delegate/src/index.js b/packages/babel-helper-call-delegate/src/index.js new file mode 100644 index 0000000000..185fae47a0 --- /dev/null +++ b/packages/babel-helper-call-delegate/src/index.js @@ -0,0 +1,58 @@ +/* @flow */ + +import hoistVariables from "babel-helper-hoist-variables"; +import type { NodePath } from "babel-traverse"; +import * as t from "babel-types"; + +let visitor = { + enter(path, state) { + if (path.isThisExpression()) { + state.foundThis = true; + } + + if (path.isReferencedIdentifier({ name: "arguments" })) { + state.foundArguments = true; + } + }, + + Function(path) { + path.skip(); + } +}; + +export default function (path: NodePath, scope = path.scope) { + let { node } = path; + let container = t.functionExpression(null, [], node.body, node.generator, node.async); + + let callee = container; + let args = []; + + // todo: only hoist if necessary + hoistVariables(path, id => scope.push({ id })); + + let state = { + foundThis: false, + foundArguments: false + }; + + path.traverse(visitor, state); + + if (state.foundArguments) { + callee = t.memberExpression(container, t.identifier("apply")); + args = []; + + if (state.foundThis) { + args.push(t.thisExpression()); + } + + if (state.foundArguments) { + if (!state.foundThis) args.push(t.nullLiteral()); + args.push(t.identifier("arguments")); + } + } + + let call = t.callExpression(callee, args); + if (node.generator) call = t.yieldExpression(call, true); + + return t.returnStatement(call); +} diff --git a/packages/babel-helper-define-map/README.md b/packages/babel-helper-define-map/README.md new file mode 100644 index 0000000000..381835187f --- /dev/null +++ b/packages/babel-helper-define-map/README.md @@ -0,0 +1,5 @@ +# babel-helper-define-map + +## Usage + +TODO diff --git a/packages/babel-helper-define-map/package.json b/packages/babel-helper-define-map/package.json new file mode 100644 index 0000000000..a49e603edc --- /dev/null +++ b/packages/babel-helper-define-map/package.json @@ -0,0 +1,14 @@ +{ + "name": "babel-helper-define-map", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.8.20", + "lodash": "^3.10.0", + "babel-types": "^5.8.20", + "babel-helper-function-name": "^5.0.0" + } +} diff --git a/packages/babel-core/src/transformation/helpers/define-map.js b/packages/babel-helper-define-map/src/index.js similarity index 58% rename from packages/babel-core/src/transformation/helpers/define-map.js rename to packages/babel-helper-define-map/src/index.js index 21b4536df0..01a44195d5 100644 --- a/packages/babel-core/src/transformation/helpers/define-map.js +++ b/packages/babel-helper-define-map/src/index.js @@ -1,11 +1,21 @@ /* @flow */ -import type File from "../file"; +import nameFunction from "babel-helper-function-name"; import each from "lodash/collection/each"; import has from "lodash/object/has"; import * as t from "babel-types"; -export function push(mutatorMap: Object, node: Object, kind: string, file: File): Object { +function toKind(node: Object) { + if (t.isClassMethod(node) || t.isObjectMethod(node)) { + if (node.kind === "get" || node.kind === "set") { + return node.kind; + } + } + + return "value"; +} + +export function push(mutatorMap: Object, node: Object, kind: string, file, scope?): Object { let alias = t.toKeyAlias(node); // @@ -34,13 +44,32 @@ export function push(mutatorMap: Object, node: Object, kind: string, file: File) throw file.buildCodeFrameError(node, "Key conflict with sibling node"); } - if (node.value) { - if (node.kind === "init") kind = "value"; - if (node.kind === "get") kind = "get"; - if (node.kind === "set") kind = "set"; + let key, value; - t.inheritsComments(node.value, node); - map[kind] = node.value; + // save the key so we can possibly do function name inferences + if (t.isObjectProperty(node) || t.isObjectMethod(node) || t.isClassMethod(node)) { + key = t.toComputedKey(node, node.key); + } + + if (t.isObjectProperty(node) || t.isClassProperty(node)) { + value = node.value; + } else if (t.isObjectMethod(node) || t.isClassMethod(node)) { + value = t.functionExpression(null, node.params, node.body, node.generator, node.async); + } + + let inheritedKind = toKind(node); + if (!kind || inheritedKind !== "value") { + kind = inheritedKind; + } + + // infer function name + if (scope && t.isStringLiteral(key) && (kind === "value" || kind === "initializer") && t.isFunctionExpression(value)) { + value = nameFunction({ id: key, node: value, scope }); + } + + if (value) { + t.inheritsComments(value, node); + map[kind] = value; } return map; @@ -61,7 +90,7 @@ export function toComputedObjectFromClass(obj: Object): Object { for (let i = 0; i < obj.properties.length; i++) { let prop = obj.properties[i]; let val = prop.value; - val.properties.unshift(t.property("init", t.identifier("key"), t.toComputedKey(prop))); + val.properties.unshift(t.objectProperty(t.identifier("key"), t.toComputedKey(prop))); objExpr.elements.push(val); } @@ -74,15 +103,15 @@ export function toClassObject(mutatorMap: Object): Object { each(mutatorMap, function (map) { let mapNode = t.objectExpression([]); - let propNode = t.property("init", map._key, mapNode, map._computed); + let propNode = t.objectProperty(map._key, mapNode, map._computed); each(map, function (node, key) { if (key[0] === "_") return; let inheritNode = node; - if (t.isMethodDefinition(node) || t.isClassProperty(node)) node = node.value; + if (t.isClassMethod(node) || t.isClassProperty(node)) node = node.value; - let prop = t.property("init", t.identifier(key), node); + let prop = t.objectProperty(t.identifier(key), node); t.inheritsComments(prop, inheritNode); t.removeComments(inheritNode); diff --git a/packages/babel-helper-explode-assignable-expression/README.md b/packages/babel-helper-explode-assignable-expression/README.md new file mode 100644 index 0000000000..d8d90aeb8c --- /dev/null +++ b/packages/babel-helper-explode-assignable-expression/README.md @@ -0,0 +1,5 @@ +# babel-helper-explode-assignable-expression + +## Usage + +TODO diff --git a/packages/babel-helper-explode-assignable-expression/package.json b/packages/babel-helper-explode-assignable-expression/package.json new file mode 100644 index 0000000000..81fd1e3c9b --- /dev/null +++ b/packages/babel-helper-explode-assignable-expression/package.json @@ -0,0 +1,13 @@ +{ + "name": "babel-helper-explode-assignable-expression", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-traverse": "^5.8.20", + "babel-runtime": "^5.8.20", + "babel-types": "^5.8.20" + } +} diff --git a/packages/babel-core/src/transformation/helpers/explode-assignable-expression.js b/packages/babel-helper-explode-assignable-expression/src/index.js similarity index 94% rename from packages/babel-core/src/transformation/helpers/explode-assignable-expression.js rename to packages/babel-helper-explode-assignable-expression/src/index.js index 5a97200499..aec842aa9c 100644 --- a/packages/babel-core/src/transformation/helpers/explode-assignable-expression.js +++ b/packages/babel-helper-explode-assignable-expression/src/index.js @@ -1,7 +1,6 @@ /* @flow */ import type { Scope } from "babel-traverse"; -import type File from "../file"; import * as t from "babel-types"; function getObjRef(node, nodes, file, scope) { @@ -20,7 +19,7 @@ function getObjRef(node, nodes, file, scope) { } else if (t.isMemberExpression(node)) { ref = node.object; - if (t.isIdentifier(ref) && scope.hasGlobal(ref.name)) { + if (t.isIdentifier(ref) && scope.hasBinding(ref.name)) { // the object reference that we need to save is locally declared // so as per the previous comment we can be 100% sure evaluating // it multiple times will be safe @@ -52,7 +51,7 @@ function getPropRef(node, nodes, file, scope) { export default function ( node: Object, nodes: Array, - file: File, + file, scope: Scope, allowedSingleIdent?: boolean, ): { diff --git a/packages/babel-helper-explode-class/README.md b/packages/babel-helper-explode-class/README.md new file mode 100644 index 0000000000..cb4474ab5b --- /dev/null +++ b/packages/babel-helper-explode-class/README.md @@ -0,0 +1,5 @@ +# babel-helper-explode-class + +## Usage + +TODO diff --git a/packages/babel-helper-explode-class/package.json b/packages/babel-helper-explode-class/package.json new file mode 100644 index 0000000000..72590d9023 --- /dev/null +++ b/packages/babel-helper-explode-class/package.json @@ -0,0 +1,14 @@ +{ + "name": "babel-helper-explode-class", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.8.20", + "babel-traverse": "^5.8.20", + "babel-types": "^5.8.20", + "babel-helper-bindify-decorators": "^5.0.0" + } +} diff --git a/packages/babel-helper-explode-class/src/index.js b/packages/babel-helper-explode-class/src/index.js new file mode 100644 index 0000000000..561ea63633 --- /dev/null +++ b/packages/babel-helper-explode-class/src/index.js @@ -0,0 +1,49 @@ +import bindifyDecorators from "babel-helper-bindify-decorators"; +import type { NodePath } from "babel-traverse" +import * as t from "babel-types"; + +export default function (classPath) { + classPath.assertClass(); + + let memoisedExpressions = []; + + function maybeMemoise(path) { + if (!path.node || path.isPure()) return; + + let uid = classPath.scope.generateDeclaredUidIdentifier(); + memoisedExpressions.push(t.assignmentExpression("=", uid, path.node)); + path.replaceWith(uid); + } + + function memoiseDecorators(paths: Array) { + if (!Array.isArray(paths) || !paths.length) return; + + // ensure correct evaluation order of decorators + paths = paths.reverse(); + + // bind decorators if they're member expressions + bindifyDecorators(paths); + + for (let path of paths) { + maybeMemoise(path); + } + } + + maybeMemoise(classPath.get("superClass")); + memoiseDecorators(classPath.get("decorators"), true); + + let methods: Array = classPath.get("body.body"); + for (let methodPath of methods) { + if (methodPath.is("computed")) { + maybeMemoise(methodPath.get("key")); + } + + if (methodPath.has("decorators")) { + memoiseDecorators(classPath.get("decorators")); + } + } + + if (memoisedExpressions) { + classPath.insertBefore(memoisedExpressions.map((expr) => t.expressionStatement(expr))); + } +} diff --git a/packages/babel-helper-fixtures/README.md b/packages/babel-helper-fixtures/README.md new file mode 100644 index 0000000000..57107d89f5 --- /dev/null +++ b/packages/babel-helper-fixtures/README.md @@ -0,0 +1 @@ +# babel-helper-fixtures diff --git a/packages/babel-helper-fixtures/package.json b/packages/babel-helper-fixtures/package.json new file mode 100644 index 0000000000..ce00f260b7 --- /dev/null +++ b/packages/babel-helper-fixtures/package.json @@ -0,0 +1,16 @@ +{ + "name": "babel-helper-fixtures", + "version": "1.0.9", + "description": "", + "author": "Sebastian McKenzie ", + "license": "MIT", + "repository": "babel/babel", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.8.20", + "lodash": "^3.10.0", + "path-exists": "^1.0.0", + "trim-right": "^1.0.1", + "try-resolve": "^1.0.0" + } +} diff --git a/packages/babel-helper-fixtures/src/index.js b/packages/babel-helper-fixtures/src/index.js new file mode 100644 index 0000000000..11cf8fd3eb --- /dev/null +++ b/packages/babel-helper-fixtures/src/index.js @@ -0,0 +1,135 @@ +import pathExists from "path-exists"; +import trimRight from "trim-right"; +import resolve from "try-resolve"; +import path from "path"; +import fs from "fs"; +import _ from "lodash"; + +function humanize(val, noext) { + if (noext) val = path.basename(val, path.extname(val)); + return val.replace(/-/g, " "); +} + +export default function get(entryLoc) { + let suites = []; + + let rootOpts = {}; + let rootOptsLoc = resolve(entryLoc + "/options"); + if (rootOptsLoc) rootOpts = require(rootOptsLoc); + + _.each(fs.readdirSync(entryLoc), function (suiteName) { + if (suiteName[0] === ".") return; + + let suite = { + options: _.clone(rootOpts), + tests: [], + title: humanize(suiteName), + filename: entryLoc + "/" + suiteName + }; + suites.push(suite); + + let suiteOptsLoc = resolve(suite.filename + "/options"); + if (suiteOptsLoc) suite.options = require(suiteOptsLoc); + + if (fs.statSync(suite.filename).isFile()) { + push(suiteName, suite.filename); + } else { + _.each(fs.readdirSync(suite.filename), function (taskName) { + let taskDir = suite.filename + "/" + taskName; + push(taskName, taskDir); + }); + } + + function push(taskName, taskDir) { + // tracuer error tests + if (taskName.indexOf("Error_") >= 0) return; + + let actualLocAlias = suiteName + "/" + taskName + "/actual.js"; + let expectLocAlias = suiteName + "/" + taskName + "/expected.js"; + let execLocAlias = suiteName + "/" + taskName + "/exec.js"; + + let actualLoc = taskDir + "/actual.js"; + let expectLoc = taskDir + "/expected.js"; + let execLoc = taskDir + "/exec.js"; + + if (resolve.relative(expectLoc + "on")) { + expectLoc += "on"; + expectLocAlias += "on"; + } + + if (fs.statSync(taskDir).isFile()) { + let ext = path.extname(taskDir); + if (ext !== ".js" && ext !== ".module.js") return; + + execLoc = taskDir; + } + + let taskOpts = _.merge({ + filenameRelative: expectLocAlias, + sourceFileName: actualLocAlias, + sourceMapName: expectLocAlias + }, _.cloneDeep(suite.options)); + + let taskOptsLoc = resolve(taskDir + "/options"); + if (taskOptsLoc) _.merge(taskOpts, require(taskOptsLoc)); + + let test = { + title: humanize(taskName, true), + disabled: taskName[0] === ".", + options: taskOpts, + exec: { + loc: execLoc, + code: readFile(execLoc), + filename: execLocAlias, + }, + actual: { + loc: actualLoc, + code: readFile(actualLoc), + filename: actualLocAlias, + }, + expect: { + loc: expectLoc, + code: readFile(expectLoc), + filename: expectLocAlias + } + }; + + // traceur checks + + let shouldSkip = function (code) { + return code.indexOf("// Error:") >= 0 || code.indexOf("// Skip.") >= 0; + }; + + if (shouldSkip(test.actual.code) || shouldSkip(test.exec.code)) { + return; + } else if (test.exec.code.indexOf("// Async.") >= 0) { + //test.options.asyncExec = true; + return; + } + + suite.tests.push(test); + + let sourceMappingsLoc = taskDir + "/source-mappings.json"; + if (pathExists.sync(sourceMappingsLoc)) { + test.sourceMappings = JSON.parse(readFile(sourceMappingsLoc)); + } + + let sourceMapLoc = taskDir + "/source-map.json"; + if (pathExists.sync(sourceMapLoc)) { + test.sourceMap = JSON.parse(readFile(sourceMapLoc)); + } + } + }); + + return suites; +} + +function readFile(filename) { + if (pathExists.sync(filename)) { + let file = trimRight(fs.readFileSync(filename, "utf8")); + file = file.replace(/\r\n/g, "\n"); + return file; + } else { + return ""; + } +} diff --git a/packages/babel-helper-function-name/README.md b/packages/babel-helper-function-name/README.md new file mode 100644 index 0000000000..96a4c65446 --- /dev/null +++ b/packages/babel-helper-function-name/README.md @@ -0,0 +1,5 @@ +# babel-helper-function-name + +## Usage + +TODO diff --git a/packages/babel-helper-function-name/package.json b/packages/babel-helper-function-name/package.json new file mode 100644 index 0000000000..5e2e7815db --- /dev/null +++ b/packages/babel-helper-function-name/package.json @@ -0,0 +1,15 @@ +{ + "name": "babel-helper-function-name", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.8.20", + "babel-types": "^5.8.20", + "babel-traverse": "^5.8.20", + "babel-helper-get-function-arity": "^5.8.20", + "babel-template": "^5.0.0" + } +} diff --git a/packages/babel-core/src/transformation/helpers/name-method.js b/packages/babel-helper-function-name/src/index.js similarity index 75% rename from packages/babel-core/src/transformation/helpers/name-method.js rename to packages/babel-helper-function-name/src/index.js index 034a825605..846b60af31 100644 --- a/packages/babel-core/src/transformation/helpers/name-method.js +++ b/packages/babel-helper-function-name/src/index.js @@ -1,11 +1,37 @@ /* @flow */ -import type { Scope } from "babel-traverse"; -import type File from "../file"; -import getFunctionArity from "./get-function-arity"; -import * as util from "../../util"; +import getFunctionArity from "babel-helper-get-function-arity"; +import template from "babel-template"; import * as t from "babel-types"; +let buildPropertyMethodAssignmentWrapper = template(` + (function (FUNCTION_KEY) { + function FUNCTION_ID() { + return FUNCTION_KEY.apply(this, arguments); + } + + FUNCTION_ID.toString = function () { + return FUNCTION_KEY.toString(); + } + + return FUNCTION_ID; + })(FUNCTION) +`); + +let buldGeneratorPropertyMethodAssignmentWrapper = template(` + (function (FUNCTION_KEY) { + function* FUNCTION_ID() { + return yield* FUNCTION_KEY.apply(this, arguments); + } + + FUNCTION_ID.toString = function () { + return FUNCTION_KEY.toString(); + }; + + return FUNCTION_ID; + })(FUNCTION) +`); + let visitor = { "ReferencedIdentifier|BindingIdentifier"(path, state) { // check if this node matches our function id @@ -28,15 +54,15 @@ function wrap(state, method, id, scope) { scope.rename(id.name); } else { // need to add a wrapper since we can't change the references - let templateName = "property-method-assignment-wrapper"; - if (method.generator) templateName += "-generator"; - let template = util.template(templateName, { + let build = buildPropertyMethodAssignmentWrapper; + if (method.generator) build = buldGeneratorPropertyMethodAssignmentWrapper; + let template = build({ FUNCTION: method, FUNCTION_ID: id, FUNCTION_KEY: scope.generateUidIdentifier(id.name) - }); + }).expression; template.callee._skipModulesRemap = true; - + // shim in dummy params to retain function arity, if you try to read the // source then you'll get the original since it's proxied so it's all good let params = template.callee.body.body[0].params; @@ -98,29 +124,11 @@ function visit(node, name, scope) { return state; } -export function custom(node: Object, id: Object, scope: Scope) { - let state = visit(node, id.name, scope); - return wrap(state, node, id, scope); -} - -export function property(node: Object, file: File, scope: Scope) { - let key = t.toComputedKey(node, node.key); - if (!t.isLiteral(key)) return; // we can't set a function id with this - - let name = t.toBindingIdentifierName(key.value); - let id = t.identifier(name); - - let method = node.value; - let state = visit(method, name, scope); - node.value = wrap(state, method, id, scope) || method; -} - -export function bare(node: Object, parent: Object, scope: Scope) { +export default function ({ node, parent, scope, id }) { // has an `id` so we don't need to infer one if (node.id) return; - let id; - if (t.isProperty(parent) && parent.kind === "init" && (!parent.computed || t.isLiteral(parent.key))) { + if ((t.isObjectProperty(parent) || t.isObjectMethod(parent, { kind: "method" })) && (!parent.computed || t.isLiteral(parent.key))) { // { foo() {} }; id = parent.key; } else if (t.isVariableDeclarator(parent)) { @@ -135,7 +143,7 @@ export function bare(node: Object, parent: Object, scope: Scope) { return; } } - } else { + } else if (!id) { return; } @@ -152,5 +160,5 @@ export function bare(node: Object, parent: Object, scope: Scope) { id = t.identifier(name); let state = visit(node, name, scope); - return wrap(state, node, id, scope); + return wrap(state, node, id, scope) || node; } diff --git a/packages/babel-helper-get-function-arity/README.md b/packages/babel-helper-get-function-arity/README.md new file mode 100644 index 0000000000..2263230cd6 --- /dev/null +++ b/packages/babel-helper-get-function-arity/README.md @@ -0,0 +1,5 @@ +# babel-helper-get-function-arity + +## Usage + +TODO diff --git a/packages/babel-helper-get-function-arity/package.json b/packages/babel-helper-get-function-arity/package.json new file mode 100644 index 0000000000..ef787ea370 --- /dev/null +++ b/packages/babel-helper-get-function-arity/package.json @@ -0,0 +1,12 @@ +{ + "name": "babel-helper-get-function-arity", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.8.20", + "babel-types": "^5.8.20" + } +} diff --git a/packages/babel-core/src/transformation/helpers/get-function-arity.js b/packages/babel-helper-get-function-arity/src/index.js similarity index 73% rename from packages/babel-core/src/transformation/helpers/get-function-arity.js rename to packages/babel-helper-get-function-arity/src/index.js index 581e695c42..2ad9bfbe6d 100644 --- a/packages/babel-core/src/transformation/helpers/get-function-arity.js +++ b/packages/babel-helper-get-function-arity/src/index.js @@ -2,7 +2,8 @@ import * as t from "babel-types"; -export default function ({ params }: { params: Array }): number { +export default function (node): number { + let params: Array = node.params; for (let i = 0; i < params.length; i++) { let param = params[i]; if (t.isAssignmentPattern(param) || t.isRestElement(param)) { diff --git a/packages/babel-helper-hoist-variables/README.md b/packages/babel-helper-hoist-variables/README.md new file mode 100644 index 0000000000..5b850971c8 --- /dev/null +++ b/packages/babel-helper-hoist-variables/README.md @@ -0,0 +1,5 @@ +# babel-helper-hoist-variables + +## Usage + +TODO diff --git a/packages/babel-helper-hoist-variables/package.json b/packages/babel-helper-hoist-variables/package.json new file mode 100644 index 0000000000..717f77ec36 --- /dev/null +++ b/packages/babel-helper-hoist-variables/package.json @@ -0,0 +1,12 @@ +{ + "name": "babel-helper-hoist-variables", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.8.20", + "babel-types": "^5.8.20" + } +} diff --git a/packages/babel-helper-hoist-variables/src/index.js b/packages/babel-helper-hoist-variables/src/index.js new file mode 100644 index 0000000000..de36a3f591 --- /dev/null +++ b/packages/babel-helper-hoist-variables/src/index.js @@ -0,0 +1,45 @@ +import * as t from "babel-types"; + +let visitor = { + Scope(path, state) { + if (state.kind === "let") path.skip(); + }, + + Function(path) { + path.skip(); + }, + + VariableDeclaration(path, state) { + if (state.kind && path.node.kind !== state.kind) return; + + let nodes = []; + + let declarations: Array = path.get("declarations"); + let firstId; + + for (let declar of declarations) { + firstId = declar.node.id; + + if (declar.node.init) { + nodes.push(t.expressionStatement( + t.assignmentExpression("=", declar.node.id, declar.node.init) + )); + } + + for (let name in declar.getBindingIdentifiers()) { + state.emit(t.identifier(name), name); + } + } + + // for (var i in test) + if (path.parentPath.isFor({ left: path.node })) { + path.replaceWith(firstId); + } else { + path.replaceWithMultiple(nodes); + } + } +}; + +export default function (path, emit: Function, kind: "var" | "let" = "var") { + path.traverse(visitor, { kind, emit }); +} diff --git a/packages/babel-helper-optimise-call-expression/README.md b/packages/babel-helper-optimise-call-expression/README.md new file mode 100644 index 0000000000..f6847bf00b --- /dev/null +++ b/packages/babel-helper-optimise-call-expression/README.md @@ -0,0 +1,5 @@ +# babel-helper-optimise-call-expression + +## Usage + +TODO diff --git a/packages/babel-helper-optimise-call-expression/package.json b/packages/babel-helper-optimise-call-expression/package.json new file mode 100644 index 0000000000..5ed05d3b79 --- /dev/null +++ b/packages/babel-helper-optimise-call-expression/package.json @@ -0,0 +1,12 @@ +{ + "name": "babel-helper-optimise-call-expression", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.8.20", + "babel-types": "^5.8.20" + } +} diff --git a/packages/babel-helper-optimise-call-expression/src/index.js b/packages/babel-helper-optimise-call-expression/src/index.js new file mode 100644 index 0000000000..75e26658fb --- /dev/null +++ b/packages/babel-helper-optimise-call-expression/src/index.js @@ -0,0 +1,16 @@ +import * as t from "babel-types"; + +export default function (callee, thisNode, args) { + if (args.length === 1 && t.isSpreadElement(args[0]) && t.isIdentifier(args[0].argument, { name: "arguments" })) { + // eg. super(...arguments); + return t.callExpression( + t.memberExpression(callee, t.identifier("apply")), + [thisNode, args[0].argument] + ); + } else { + return t.callExpression( + t.memberExpression(callee, t.identifier("call")), + [thisNode, ...args] + ); + } +} diff --git a/packages/babel-helper-regex/README.md b/packages/babel-helper-regex/README.md new file mode 100644 index 0000000000..bcdfccba94 --- /dev/null +++ b/packages/babel-helper-regex/README.md @@ -0,0 +1,5 @@ +# babel-helper-regex + +## Usage + +TODO diff --git a/packages/babel-helper-regex/package.json b/packages/babel-helper-regex/package.json new file mode 100644 index 0000000000..1563e36317 --- /dev/null +++ b/packages/babel-helper-regex/package.json @@ -0,0 +1,13 @@ +{ + "name": "babel-helper-regex", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.8.20", + "lodash": "^3.10.0", + "babel-types": "^5.8.20" + } +} diff --git a/packages/babel-core/src/transformation/helpers/regex.js b/packages/babel-helper-regex/src/index.js similarity index 100% rename from packages/babel-core/src/transformation/helpers/regex.js rename to packages/babel-helper-regex/src/index.js diff --git a/packages/babel-helper-remap-async-to-generator/package.json b/packages/babel-helper-remap-async-to-generator/package.json index 04fc955d16..74d8cb1684 100644 --- a/packages/babel-helper-remap-async-to-generator/package.json +++ b/packages/babel-helper-remap-async-to-generator/package.json @@ -1,15 +1,14 @@ { "name": "babel-helper-remap-async-to-generator", - "version": "1.0.0", + "version": "5.10.32", "description": "", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^5.8.20", - "babel-types": "^5.8.20", - "babel-traverse": "^5.8.20", - "babel-helper-explode-class": "^5.0.0", + "babel-runtime": "^5.10.32", + "babel-types": "^5.10.32", + "babel-traverse": "^5.10.32", "babel-helper-function-name": "^5.0.0" } -} +} \ No newline at end of file diff --git a/packages/babel-helper-remap-async-to-generator/src/index.js b/packages/babel-helper-remap-async-to-generator/src/index.js index 2a42feabdf..53f7b4811b 100644 --- a/packages/babel-helper-remap-async-to-generator/src/index.js +++ b/packages/babel-helper-remap-async-to-generator/src/index.js @@ -1,8 +1,7 @@ /* @flow */ import type { NodePath } from "babel-traverse"; -import explodeClass from "babel-helper-explode-class"; -import { bare as nameMethod } from "babel-helper-function-name"; +import nameFunction from "babel-helper-function-name"; import * as t from "babel-types"; let awaitVisitor = { @@ -15,54 +14,45 @@ let awaitVisitor = { } }; -let referenceVisitor = { - ReferencedIdentifier({ node, scope }, state) { - let name = state.id.name; - if (node.name === name && scope.bindingIdentifierEquals(name, state.id)) { - return state.ref = state.ref || scope.generateUidIdentifier(name); - } - } -}; - export default function (path: NodePath, callId: Object) { let node = path.node; if (node.generator) return; + if (path.isClassMethod()) { + node.async = false; + + let body = node.body; + + let container = t.functionExpression(null, [], t.blockStatement(body.body), true); + container.shadow = true; + body.body = [t.returnStatement(t.callExpression(t.callExpression(callId, [container]), []))]; + return; + } + node.async = false; node.generator = true; path.traverse(awaitVisitor); let container = t.functionExpression(null, [], t.blockStatement([ - t.returnStatement(t.callExpression(callId, [node])) + t.returnStatement(t.callExpression(t.callExpression(callId, [node]), [])) ])); node.shadow = container; if (path.isFunctionDeclaration()) { let declar = t.variableDeclaration("let", [ - t.variableDeclarator(id, container) + t.variableDeclarator(t.identifier(node.id.name), container) ]); declar._blockHoist = true; - nameMethod({ + nameFunction({ node: container, parent: declar.declarations[0], scope: path.scope }); - + path.replaceWith(declar); } else { - node.type = "FunctionExpression"; - - if (path.parentPath.isMethodDefinition({ value: node })) { - // we're a class method - let classPath = path.parentPath.parentPath.parentPath; - explodeClass(classPath); - - // remove method since we've injected ourselves already - path.parentPath.remove(); - } else { - path.replaceWith(container); - } + path.replaceWith(container); } } diff --git a/packages/babel-helper-replace-supers/README.md b/packages/babel-helper-replace-supers/README.md new file mode 100644 index 0000000000..a6515daed4 --- /dev/null +++ b/packages/babel-helper-replace-supers/README.md @@ -0,0 +1,5 @@ +# babel-helper-replace-supers + +## Usage + +TODO diff --git a/packages/babel-helper-replace-supers/package.json b/packages/babel-helper-replace-supers/package.json new file mode 100644 index 0000000000..4c0c7dee57 --- /dev/null +++ b/packages/babel-helper-replace-supers/package.json @@ -0,0 +1,16 @@ +{ + "name": "babel-helper-replace-supers", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-helper-optimise-call-expression": "^5.8.20", + "babel-runtime": "^5.8.20", + "babel-traverse": "^5.8.20", + "babel-messages": "^5.8.20", + "babel-template": "^5.8.20", + "babel-types": "^5.8.20" + } +} diff --git a/packages/babel-core/src/transformation/helpers/replace-supers.js b/packages/babel-helper-replace-supers/src/index.js similarity index 58% rename from packages/babel-core/src/transformation/helpers/replace-supers.js rename to packages/babel-helper-replace-supers/src/index.js index 11e6eab71f..ca6793b658 100644 --- a/packages/babel-core/src/transformation/helpers/replace-supers.js +++ b/packages/babel-helper-replace-supers/src/index.js @@ -1,10 +1,13 @@ /* @flow */ -import type File from "../file"; import type { NodePath, Scope } from "babel-traverse"; +import optimiseCall from "babel-helper-optimise-call-expression"; import * as messages from "babel-messages"; import * as t from "babel-types"; +// ✌️ +let HARDCORE_THIS_REF = Symbol(); + function isIllegalBareSuper(node, parent) { if (!t.isSuper(node)) return false; if (t.isMemberExpression(parent, { computed: false })) return false; @@ -17,39 +20,61 @@ function isMemberExpressionSuper(node) { } let visitor = { + "ObjectMethod|ClassMethod"(path) { + path.skip(); + }, + + "FunctionDeclaration|FunctionExpression"(path) { + if (!path.inShadow("this")) { + path.skip(); + } + }, + + ReturnStatement(path, state) { + if (!path.inShadow("this")) { + state.returns.push(path); + } + }, + + ThisExpression(path, state) { + if (!path.node[HARDCORE_THIS_REF]) { + state.thises.push(path); + } + }, + enter(path, state) { - let topLevel = state.topLevel; - let self = state.self; + let callback = state.specHandle; + if (state.isLoose) callback = state.looseHandle; - if (path.isFunction() && !path.isArrowFunctionExpression()) { - // we need to call traverseLevel again so we're context aware - self.traverseLevel(path, false); - return path.skip(); + let isBareSuper = path.isCallExpression() && path.get("callee").isSuper(); + + let result = callback.call(state, path); + + if (result) { + state.hasSuper = true; } - if (path.isProperty({ method: true }) || path.isMethodDefinition()) { - // break on object methods - return path.skip(); + if (isBareSuper) { + state.bareSupers.push(path); } - let getThisReference = topLevel ? - // top level so `this` is the instance - t.thisExpression : - // not in the top level so we need to create a reference - self.getThisReference.bind(self); + if (result === true) { + path.requeue(); + } - let callback = self.specHandle; - if (self.isLoose) callback = self.looseHandle; - let result = callback.call(self, path, getThisReference); - if (result) path.hasSuper = true; - if (result === true) return; - return result; + if (result !== true && result) { + if (Array.isArray(result)) { + path.replaceWithMultiple(result); + } else { + path.replaceWith(result); + } + } } }; export default class ReplaceSupers { constructor(opts: Object, inClass?: boolean = false) { - this.topLevelThisReference = opts.topLevelThisReference; + this.forceSuperMemoisation = opts.forceSuperMemoisation; this.methodPath = opts.methodPath; this.methodNode = opts.methodNode; this.superRef = opts.superRef; @@ -57,12 +82,16 @@ export default class ReplaceSupers { this.hasSuper = false; this.inClass = inClass; this.isLoose = opts.isLoose; - this.scope = opts.scope; + this.scope = this.methodPath.scope; this.file = opts.file; this.opts = opts; + + this.bareSupers = []; + this.returns = []; + this.thises = []; } - topLevelThisReference: ?Object; + forceSuperMemoisation: boolean; methodPath: NodePath; methodNode: Object; superRef: Object; @@ -71,17 +100,16 @@ export default class ReplaceSupers { inClass: boolean; isLoose: boolean; scope: Scope; - file: File; + file; opts: { + forceSuperMemoisation: boolean; getObjetRef: Function; - topLevelThisReference: Object; methodPath: NodePath; methodNode: Object; superRef: Object; isStatic: boolean; isLoose: boolean; - scope: Scope; - file: File; + file: any; }; getObjectRef() { @@ -97,7 +125,7 @@ export default class ReplaceSupers { * */ - setSuperProperty(property: Object, value: Object, isComputed: boolean, thisExpression: Object): Object { + setSuperProperty(property: Object, value: Object, isComputed: boolean): Object { return t.callExpression( this.file.addHelper("set"), [ @@ -109,7 +137,7 @@ export default class ReplaceSupers { ), isComputed ? property : t.stringLiteral(property.name), value, - thisExpression + t.thisExpression() ] ); } @@ -123,7 +151,7 @@ export default class ReplaceSupers { * */ - getSuperProperty(property: Object, isComputed: boolean, thisExpression: Object): Object { + getSuperProperty(property: Object, isComputed: boolean): Object { return t.callExpression( this.file.addHelper("get"), [ @@ -134,63 +162,23 @@ export default class ReplaceSupers { ] ), isComputed ? property : t.stringLiteral(property.name), - thisExpression + t.thisExpression() ] ); } replace() { - this.traverseLevel(this.methodPath.get("value"), true); - } - - traverseLevel(path: NodePath, topLevel: boolean) { - let state = { self: this, topLevel: topLevel }; - path.traverse(visitor, state); - } - - getThisReference() { - if (this.topLevelThisReference) { - return this.topLevelThisReference; - } else { - let ref = this.topLevelThisReference = this.scope.generateUidIdentifier("this"); - this.methodNode.value.body.body.unshift(t.variableDeclaration("var", [ - t.variableDeclarator(this.topLevelThisReference, t.thisExpression()) - ])); - return ref; - } + this.methodPath.traverse(visitor, this); } getLooseSuperProperty(id: Object, parent: Object) { let methodNode = this.methodNode; - let methodName = methodNode.key; let superRef = this.superRef || t.identifier("Function"); if (parent.property === id) { return; } else if (t.isCallExpression(parent, { callee: id })) { - // super(); -> objectRef.prototype.MethodName.call(this); - parent.arguments.unshift(t.thisExpression()); - - if (methodName.name === "constructor") { - // constructor() { super(); } - if (parent.arguments.length === 2 && t.isSpreadElement(parent.arguments[1]) && t.isIdentifier(parent.arguments[1].argument, { name: "arguments" })) { - // special case single arguments spread - parent.arguments[1] = parent.arguments[1].argument; - return t.memberExpression(superRef, t.identifier("apply")); - } else { - return t.memberExpression(superRef, t.identifier("call")); - } - } else { - id = superRef; - - // foo() { super(); } - if (!methodNode.static) { - id = t.memberExpression(id, t.identifier("prototype")); - } - - id = t.memberExpression(id, methodName, methodNode.computed); - return t.memberExpression(id, t.identifier("call")); - } + return; } else if (t.isMemberExpression(parent) && !methodNode.static) { // super.test -> objectRef.prototype.test return t.memberExpression(superRef, t.identifier("prototype")); @@ -199,7 +187,7 @@ export default class ReplaceSupers { } } - looseHandle(path: NodePath, getThisReference: Function) { + looseHandle(path: NodePath) { let node = path.node; if (path.isSuper()) { return this.getLooseSuperProperty(node, path.parent); @@ -210,15 +198,15 @@ export default class ReplaceSupers { // super.test(); -> objectRef.prototype.MethodName.call(this); t.appendToMemberExpression(callee, t.identifier("call")); - node.arguments.unshift(getThisReference()); + node.arguments.unshift(t.thisExpression()); return true; } } - specHandleAssignmentExpression(ref, path, node, getThisReference) { + specHandleAssignmentExpression(ref, path, node) { if (node.operator === "=") { // super.name = "val"; -> _set(Object.getPrototypeOf(objectRef.prototype), "name", this); - return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference()); + return this.setSuperProperty(node.left.property, node.right, node.left.computed); } else { // super.age += 2; -> let _ref = super.age; super.age = _ref + 2; ref = ref || path.scope.generateUidIdentifier("ref"); @@ -233,8 +221,7 @@ export default class ReplaceSupers { } } - specHandle(path: NodePath, getThisReference: Function) { - let methodNode = this.methodNode; + specHandle(path: NodePath) { let property; let computed; let args; @@ -250,18 +237,7 @@ export default class ReplaceSupers { if (t.isCallExpression(node)) { let callee = node.callee; if (t.isSuper(callee)) { - // super(); -> _get(Object.getPrototypeOf(objectRef), "MethodName", this).call(this); - property = methodNode.key; - computed = methodNode.computed; - args = node.arguments; - - // bare `super` call is illegal inside non-constructors - // - https://esdiscuss.org/topic/super-call-in-methods - // - https://twitter.com/wycats/status/544553184396836864 - if (methodNode.key.name !== "constructor" || !this.inClass) { - let methodName = methodNode.key.name || "METHOD_NAME"; - throw this.file.buildCodeFrameError(node, messages.get("classesIllegalSuperCall", methodName)); - } + return; } else if (isMemberExpressionSuper(callee)) { // super.test(); -> _get(Object.getPrototypeOf(objectRef.prototype), "test", this).call(this); property = callee.property; @@ -276,35 +252,30 @@ export default class ReplaceSupers { let binary = t.binaryExpression(node.operator[0], node.argument, t.numberLiteral(1)); if (node.prefix) { // ++super.foo; -> super.foo += 1; - return this.specHandleAssignmentExpression(null, path, binary, getThisReference); + return this.specHandleAssignmentExpression(null, path, binary); } else { // super.foo++; -> let _ref = super.foo; super.foo = _ref + 1; let ref = path.scope.generateUidIdentifier("ref"); - return this.specHandleAssignmentExpression(ref, path, binary, getThisReference).concat(t.expressionStatement(ref)); + return this.specHandleAssignmentExpression(ref, path, binary).concat(t.expressionStatement(ref)); } } else if (t.isAssignmentExpression(node) && isMemberExpressionSuper(node.left)) { - return this.specHandleAssignmentExpression(null, path, node, getThisReference); + return this.specHandleAssignmentExpression(null, path, node); } if (!property) return; - thisReference = getThisReference(); let superProperty = this.getSuperProperty(property, computed, thisReference); + if (args) { - if (args.length === 1 && t.isSpreadElement(args[0])) { - // super(...arguments); - return t.callExpression( - t.memberExpression(superProperty, t.identifier("apply")), - [thisReference, args[0].argument] - ); - } else { - return t.callExpression( - t.memberExpression(superProperty, t.identifier("call")), - [thisReference, ...args] - ); - } + return this.optimiseCall(superProperty, args); } else { return superProperty; } } + + optimiseCall(callee, args) { + let thisNode = t.thisExpression(); + thisNode[HARDCORE_THIS_REF] = true; + return optimiseCall(callee, thisNode, args); + } } diff --git a/packages/babel-helpers/README.md b/packages/babel-helpers/README.md new file mode 100644 index 0000000000..77541b612a --- /dev/null +++ b/packages/babel-helpers/README.md @@ -0,0 +1 @@ +# babel-helpers diff --git a/packages/babel-helpers/package.json b/packages/babel-helpers/package.json new file mode 100644 index 0000000000..de46139c06 --- /dev/null +++ b/packages/babel-helpers/package.json @@ -0,0 +1,14 @@ +{ + "name": "babel-helpers", + "version": "6.0.6", + "description": "", + "author": "Sebastian McKenzie ", + "homepage": "https://babeljs.io/", + "license": "MIT", + "repository": "babel/babel", + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^6.0.6", + "babel-template": "^6.0.6" + } +} diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js new file mode 100644 index 0000000000..82353df622 --- /dev/null +++ b/packages/babel-helpers/src/helpers.js @@ -0,0 +1,389 @@ +import template from "babel-template"; + +export let _typeof = template(` + (function (obj) { + return obj && obj.constructor === Symbol ? "symbol" : typeof obj; + }); +`); + +export let typeofReactElement = template(` + (typeof Symbol === "function" && Symbol.for && Symbol.for("react.element")) || 0xeac7; +`); + +export let asyncToGenerator = template(` + (function (fn) { + return function () { + var gen = fn.apply(this, arguments); + + return new Promise(function (resolve, reject) { + var callNext = step.bind(null, "next"); + var callThrow = step.bind(null, "throw"); + + function step(key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + + if (info.done) { + resolve(value); + } else { + Promise.resolve(value).then(callNext, callThrow); + } + } + + callNext(); + }); + }; + }) +`); + + +export let classCallCheck = template(` + (function (instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + }); +`); + +export let createClass = template(` + (function() { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i ++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + })() +`); + +export let defaultProps = template(` + (function (defaultProps, props) { + if (defaultProps) { + for (var propName in defaultProps) { + if (typeof props[propName] === "undefined") { + props[propName] = defaultProps[propName]; + } + } + } + return props; + }) +`); + + +export let defaults = template(` + (function (obj, defaults) { + var keys = Object.getOwnPropertyNames(defaults); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var value = Object.getOwnPropertyDescriptor(defaults, key); + if (value && value.configurable && obj[key] === undefined) { + Object.defineProperty(obj, key, value); + } + } + return obj; + }) +`); + +export let defineProperty = template(` + (function (obj, key, value) { + // Shortcircuit the slow defineProperty path when possible. + // We are trying to avoid issues where setters defined on the + // prototype cause side effects under the fast path of simple + // assignment. By checking for existence of the property with + // the in operator, we can optimize most of this overhead away. + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; + }); +`); + +export let _extends = template(` + Object.assign || (function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + return target; + }) +`); + +export let get = template(` + (function get(object, property, receiver) { + if (object === null) object = Function.prototype; + + var desc = Object.getOwnPropertyDescriptor(object, property); + + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); + + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; + + if (getter === undefined) { + return undefined; + } + + return getter.call(receiver); + } + }); +`); + + +export let inherits = template(` + (function (subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + }) +`); + +export let _instanceof = template(` + (function (left, right) { + if (right != null && right[Symbol.hasInstance]) { + return right[Symbol.hasInstance](left); + } else { + return left instanceof right; + } + }); +`); + + +export let interopRequireDefault = template(` + (function (obj) { + return obj && obj.__esModule ? obj : { default: obj }; + }) +`); + +export let interopRequireWildcard = template(` + (function (obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; + } + } + newObj.default = obj; + return newObj; + } + }) +`); + +export let newArrowCheck = template(` + (function (innerThis, boundThis) { + if (innerThis !== boundThis) { + throw new TypeError("Cannot instantiate an arrow function"); + } + }); +`); + +export let objectDestructuringEmpty = template(` + (function (obj) { + if (obj == null) throw new TypeError("Cannot destructure undefined"); + }); +`); + +export let objectWithoutProperties = template(` + (function (obj, keys) { + var target = {}; + for (var i in obj) { + if (keys.indexOf(i) >= 0) continue; + if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; + target[i] = obj[i]; + } + return target; + }) +`); + +export let possibleConstructorReturn = template(` + (function (self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + return call && (typeof call === "object" || typeof call === "function") ? call : self; + }); +`); + +export let selfGlobal = template(` + typeof global === "undefined" ? self : global +`); + +export let set = template(` + (function set(object, property, value, receiver) { + var desc = Object.getOwnPropertyDescriptor(object, property); + + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); + + if (parent !== null) { + set(parent, property, value, receiver); + } + } else if ("value" in desc && desc.writable) { + desc.value = value; + } else { + var setter = desc.set; + + if (setter !== undefined) { + setter.call(receiver, value); + } + } + + return value; + }); +`); + +export let slicedToArray = template(` + (function () { + // Broken out into a separate function to avoid deoptimizations due to the try/catch for the + // array iterator case. + function sliceIterator(arr, i) { + // this is an expanded form of \`for...of\` that properly supports abrupt completions of + // iterators etc. variable names have been minimised to reduce the size of this massive + // helper. sometimes spec compliancy is annoying :( + // + // _n = _iteratorNormalCompletion + // _d = _didIteratorError + // _e = _iteratorError + // _i = _iterator + // _s = _step + + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i["return"]) _i["return"](); + } finally { + if (_d) throw _e; + } + } + return _arr; + } + + return function (arr, i) { + if (Array.isArray(arr)) { + return arr; + } else if (Symbol.iterator in Object(arr)) { + return sliceIterator(arr, i); + } else { + throw new TypeError("Invalid attempt to destructure non-iterable instance"); + } + }; + })(); +`); + +export let slicedToArrayLoose = template(` + (function (arr, i) { + if (Array.isArray(arr)) { + return arr; + } else if (Symbol.iterator in Object(arr)) { + var _arr = []; + for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { + _arr.push(_step.value); + if (i && _arr.length === i) break; + } + return _arr; + } else { + throw new TypeError("Invalid attempt to destructure non-iterable instance"); + } + }); +`); + +export let taggedTemplateLiteral = template(` + (function (strings, raw) { + return Object.freeze(Object.defineProperties(strings, { + raw: { value: Object.freeze(raw) } + })); + }); +`); + +export let taggedTemplateLiteralLoose = template(` + (function (strings, raw) { + strings.raw = raw; + return strings; + }); +`); + +export let temporalRef = template(` + (function (val, name, undef) { + if (val === undef) { + throw new ReferenceError(name + " is not defined - temporal dead zone"); + } else { + return val; + } + }) +`); + +export let temporalUndefined = template(` + ({}) +`); + +export let toArray = template(` + (function (arr) { + return Array.isArray(arr) ? arr : Array.from(arr); + }); +`); + +export let toConsumableArray = template(` + (function (arr) { + if (Array.isArray(arr)) { + for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; + return arr2; + } else { + return Array.from(arr); + } + }); +`); diff --git a/packages/babel-helpers/src/index.js b/packages/babel-helpers/src/index.js new file mode 100644 index 0000000000..7a83143ccc --- /dev/null +++ b/packages/babel-helpers/src/index.js @@ -0,0 +1,12 @@ +import * as helpers from "./helpers"; + +export function get(name) { + let fn = helpers[name] || helpers[`_${name}`]; + if (!fn) throw ReferenceError; + + return fn().expression; +} + +export let list = Object.keys(helpers).filter(name => name !== "__esModule"); + +export default get; diff --git a/packages/babel-messages/README.md b/packages/babel-messages/README.md new file mode 100644 index 0000000000..5307081ff3 --- /dev/null +++ b/packages/babel-messages/README.md @@ -0,0 +1 @@ +# babel-messages diff --git a/packages/babel-messages/package.json b/packages/babel-messages/package.json index a3a0c3c318..3fff027f91 100644 --- a/packages/babel-messages/package.json +++ b/packages/babel-messages/package.json @@ -1,10 +1,13 @@ { "name": "babel-messages", - "version": "5.8.22", + "version": "5.10.32", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", "license": "MIT", "repository": "babel/babel", - "main": "lib/index.js" -} + "main": "lib/index.js", + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-messages/src/index.js b/packages/babel-messages/src/index.js index 59a7c3e20c..53a769f1b1 100644 --- a/packages/babel-messages/src/index.js +++ b/packages/babel-messages/src/index.js @@ -1,3 +1,5 @@ +/* @flow */ + import * as util from "util"; /** @@ -7,7 +9,6 @@ import * as util from "util"; export const MESSAGES = { tailCallReassignmentDeopt: "Function reference has been reassigned, so it will probably be dereferenced, therefore we can't optimise this with confidence", - JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.", classesIllegalBareSuper: "Illegal use of bare super", classesIllegalSuperCall: "Direct super call is illegal in non-constructor, use super.$1() instead", scopeDuplicateDeclaration: "Duplicate declaration $1", @@ -36,23 +37,10 @@ export const MESSAGES = { traverseVerifyVisitorProperty: "You passed `traverse()` a visitor object with the property $1 that has the invalid property $2", traverseVerifyNodeType: "You gave us a visitor for the node type $1 but it's not a valid type", - pluginIllegalKind: "Illegal kind $1 for plugin $2", - pluginIllegalPosition: "Illegal position $1 for plugin $2", - pluginKeyCollision: "The plugin $1 collides with another of the same name", - pluginNotTransformer: "The plugin $1 didn't export a Plugin instance", - pluginUnknown: "Unknown plugin $1", - - pluginNotFile: "Plugin $1 is resolving to a different Babel version than what is performing the transformation.", - - pluginInvalidProperty: "Plugin $1 provided an invalid property of $2.", - pluginInvalidPropertyVisitor: `Define your visitor methods inside a \`visitor\` property like so: - - new Plugin("foobar", { - visitor: { - // define your visitor methods here! - } - }); -` + pluginNotObject: "Plugin $2 specified in $1 was expected to return an object when invoked but returned $3", + pluginNotFunction: "Plugin $2 specified in $1 was expected to return a function but returned $3", + pluginUnknown: "Unknown plugin $1 specified in $2 at $3", + pluginInvalidProperty: "Plugin $2 specified in $1 provided an invalid property of $3" }; /** @@ -60,7 +48,7 @@ export const MESSAGES = { */ export function get(key: string, ...args): string { - var msg = MESSAGES[key]; + let msg = MESSAGES[key]; if (!msg) throw new ReferenceError(`Unknown message ${JSON.stringify(key)}`); // stringify args diff --git a/packages/babel-plugin-external-helpers/package.json b/packages/babel-plugin-external-helpers/package.json index 61bc719e42..93cb2c7867 100644 --- a/packages/babel-plugin-external-helpers/package.json +++ b/packages/babel-plugin-external-helpers/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-external-helpers", - "version": "1.0.0", + "version": "5.10.32", "description": "", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-async-functions/package.json b/packages/babel-plugin-syntax-async-functions/package.json index 9fce60af41..f6f0d06995 100644 --- a/packages/babel-plugin-syntax-async-functions/package.json +++ b/packages/babel-plugin-syntax-async-functions/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-async-functions", - "version": "1.0.0", + "version": "5.10.32", "description": "Allow parsing of async functions", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-async-generators/README.md b/packages/babel-plugin-syntax-async-generators/README.md new file mode 100644 index 0000000000..330f8e2079 --- /dev/null +++ b/packages/babel-plugin-syntax-async-generators/README.md @@ -0,0 +1,35 @@ +# babel-plugin-syntax-async-generators + +Allow parsing of async generator functions. + +## Installation + +```sh +$ npm install babel-plugin-syntax-async-generators +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["syntax-async-generators"] +} +``` + +### Via CLI + +```sh +$ babel --plugins syntax-async-generators script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["syntax-async-generators"] +}); +``` diff --git a/packages/babel-plugin-syntax-async-generators/package.json b/packages/babel-plugin-syntax-async-generators/package.json new file mode 100644 index 0000000000..e441079cee --- /dev/null +++ b/packages/babel-plugin-syntax-async-generators/package.json @@ -0,0 +1,14 @@ +{ + "name": "babel-plugin-syntax-async-generators", + "version": "1.0.0", + "description": "Allow parsing of async generator functions", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "babel-runtime": "^5.8.20" + } +} diff --git a/packages/babel-plugin-syntax-async-generators/src/index.js b/packages/babel-plugin-syntax-async-generators/src/index.js new file mode 100644 index 0000000000..4064178ff1 --- /dev/null +++ b/packages/babel-plugin-syntax-async-generators/src/index.js @@ -0,0 +1,7 @@ +export default function () { + return { + manipulateOptions(opts, parserOpts) { + parserOpts.plugins.push("asyncGenerators"); + } + }; +} diff --git a/packages/babel-plugin-transform-async-to-bluebird-coroutines/.npmignore b/packages/babel-plugin-syntax-class-constructor-call/.npmignore similarity index 100% rename from packages/babel-plugin-transform-async-to-bluebird-coroutines/.npmignore rename to packages/babel-plugin-syntax-class-constructor-call/.npmignore diff --git a/packages/babel-plugin-syntax-class-constructor-call/README.md b/packages/babel-plugin-syntax-class-constructor-call/README.md new file mode 100644 index 0000000000..7ab9617ce2 --- /dev/null +++ b/packages/babel-plugin-syntax-class-constructor-call/README.md @@ -0,0 +1,35 @@ +# babel-plugin-syntax-class-construtor-call + +Allow parsing of do expressions. + +## Installation + +```sh +$ npm install babel-plugin-syntax-class-construtor-call +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["syntax-class-construtor-call"] +} +``` + +### Via CLI + +```sh +$ babel --plugins syntax-class-construtor-call script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["syntax-class-construtor-call"] +}); +``` diff --git a/packages/babel-plugin-syntax-class-constructor-call/package.json b/packages/babel-plugin-syntax-class-constructor-call/package.json new file mode 100644 index 0000000000..e35b99601e --- /dev/null +++ b/packages/babel-plugin-syntax-class-constructor-call/package.json @@ -0,0 +1,14 @@ +{ + "name": "babel-plugin-syntax-class-constructor-call", + "version": "1.0.0", + "description": "Allow parsing of class constructor calls", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "babel-runtime": "^5.8.20" + } +} diff --git a/packages/babel-plugin-syntax-class-constructor-call/src/index.js b/packages/babel-plugin-syntax-class-constructor-call/src/index.js new file mode 100644 index 0000000000..d3839a279c --- /dev/null +++ b/packages/babel-plugin-syntax-class-constructor-call/src/index.js @@ -0,0 +1,7 @@ +export default function () { + return { + manipulateOptions(opts, parserOpts) { + parserOpts.plugins.push("classConstructorCall"); + } + }; +} diff --git a/packages/babel-plugin-syntax-class-properties/package.json b/packages/babel-plugin-syntax-class-properties/package.json index edf59c1d57..00746a70c2 100644 --- a/packages/babel-plugin-syntax-class-properties/package.json +++ b/packages/babel-plugin-syntax-class-properties/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-class-properties", - "version": "1.0.0", + "version": "5.10.32", "description": "Allow parsing of class properties", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-decorators/package.json b/packages/babel-plugin-syntax-decorators/package.json index 402281dcb8..8b65d57835 100644 --- a/packages/babel-plugin-syntax-decorators/package.json +++ b/packages/babel-plugin-syntax-decorators/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-decorators", - "version": "1.0.0", + "version": "5.10.32", "description": "Allow parsing of decorators", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-do-expressions/package.json b/packages/babel-plugin-syntax-do-expressions/package.json index 2545e296aa..49e00f01ee 100644 --- a/packages/babel-plugin-syntax-do-expressions/package.json +++ b/packages/babel-plugin-syntax-do-expressions/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-do-expressions", - "version": "1.0.0", + "version": "5.10.32", "description": "Allow parsing of do expressions", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-exponentiation-operator/package.json b/packages/babel-plugin-syntax-exponentiation-operator/package.json index f12524f751..31a8b38a96 100644 --- a/packages/babel-plugin-syntax-exponentiation-operator/package.json +++ b/packages/babel-plugin-syntax-exponentiation-operator/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-exponentiation-operator", - "version": "1.0.0", + "version": "5.10.32", "description": "Allow parsing of the exponentiation operator", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-export-extensions/package.json b/packages/babel-plugin-syntax-export-extensions/package.json index 9b9a06bfbf..fb65a9721a 100644 --- a/packages/babel-plugin-syntax-export-extensions/package.json +++ b/packages/babel-plugin-syntax-export-extensions/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-export-extensions", - "version": "1.0.0", + "version": "5.10.32", "description": "Allow parsing of export extensions", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-flow/package.json b/packages/babel-plugin-syntax-flow/package.json index ce8a7e48a3..3fd06a2d7a 100644 --- a/packages/babel-plugin-syntax-flow/package.json +++ b/packages/babel-plugin-syntax-flow/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-flow", - "version": "1.0.0", + "version": "5.10.32", "description": "", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-function-bind/package.json b/packages/babel-plugin-syntax-function-bind/package.json index f71a332476..55db548815 100644 --- a/packages/babel-plugin-syntax-function-bind/package.json +++ b/packages/babel-plugin-syntax-function-bind/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-function-bind", - "version": "1.0.0", + "version": "5.10.32", "description": "Allow parsing of function bind", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-jsx/package.json b/packages/babel-plugin-syntax-jsx/package.json index 144fe23dcd..25c10f2c69 100644 --- a/packages/babel-plugin-syntax-jsx/package.json +++ b/packages/babel-plugin-syntax-jsx/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-jsx", - "version": "1.0.0", + "version": "5.10.32", "description": "", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-object-rest-spread/package.json b/packages/babel-plugin-syntax-object-rest-spread/package.json index 474bd23447..67b6f0cb55 100644 --- a/packages/babel-plugin-syntax-object-rest-spread/package.json +++ b/packages/babel-plugin-syntax-object-rest-spread/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-object-rest-spread", - "version": "1.0.0", + "version": "5.10.32", "description": "Allow parsing of object rest/spread", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-syntax-trailing-function-commas/package.json b/packages/babel-plugin-syntax-trailing-function-commas/package.json index a97ab921e0..ff1eda374b 100644 --- a/packages/babel-plugin-syntax-trailing-function-commas/package.json +++ b/packages/babel-plugin-syntax-trailing-function-commas/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-syntax-trailing-function-commas", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile trailing function commas to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-async-functions/package.json b/packages/babel-plugin-transform-async-functions/package.json index c78d4154f7..0145bf01cc 100644 --- a/packages/babel-plugin-transform-async-functions/package.json +++ b/packages/babel-plugin-transform-async-functions/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-async-functions", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile async functions to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-plugin-syntax-async-functions": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-async-functions/src/index.js b/packages/babel-plugin-transform-async-functions/src/index.js index 6845446a11..abe7b8a0f7 100644 --- a/packages/babel-plugin-transform-async-functions/src/index.js +++ b/packages/babel-plugin-transform-async-functions/src/index.js @@ -1,7 +1,5 @@ export default function () { return { - visitor: { - // your visitor methods go here - } + inherits: require("babel-plugin-syntax-async-functions") }; } diff --git a/packages/babel-plugin-transform-async-to-bluebird-coroutines/README.md b/packages/babel-plugin-transform-async-to-bluebird-coroutines/README.md deleted file mode 100644 index 6cf96b4373..0000000000 --- a/packages/babel-plugin-transform-async-to-bluebird-coroutines/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# babel-plugin-transform-async-to-bluebird-coroutines - -Turn async functions into a Bluebird coroutine - -## Installation - -```sh -$ npm install babel-plugin-transform-async-to-bluebird-coroutines -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["transform-async-to-bluebird-coroutines"] -} -``` - -### Via CLI - -```sh -$ babel --plugins transform-async-to-bluebird-coroutines script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["transform-async-to-bluebird-coroutines"] -}); -``` diff --git a/packages/babel-plugin-transform-async-to-bluebird-coroutines/package.json b/packages/babel-plugin-transform-async-to-bluebird-coroutines/package.json deleted file mode 100644 index 1a389fdebe..0000000000 --- a/packages/babel-plugin-transform-async-to-bluebird-coroutines/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "babel-plugin-transform-async-to-bluebird-coroutines", - "version": "1.0.0", - "description": "Turn async functions into a Bluebird coroutine", - "repository": "babel/babel", - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin" - ], - "dependencies": { - "babel-helper-remap-async-to-generator": "^5.0.0", - "babel-types": "^5.0.0" - } -} diff --git a/packages/babel-plugin-transform-async-to-generator/package.json b/packages/babel-plugin-transform-async-to-generator/package.json index 760520838c..0ee3c76258 100644 --- a/packages/babel-plugin-transform-async-to-generator/package.json +++ b/packages/babel-plugin-transform-async-to-generator/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-async-to-generator", - "version": "1.0.0", + "version": "5.10.32", "description": "Turn async functions into ES2015 generators", "repository": "babel/babel", "license": "MIT", @@ -9,6 +9,8 @@ "babel-plugin" ], "dependencies": { - "babel-helper-remap-async-to-generator": "^5.0.0" + "babel-helper-remap-async-to-generator": "^5.10.32", + "babel-plugin-syntax-async-functions": "^5.10.32", + "babel-runtime": "^5.10.32" } -} +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-async-to-generator/src/index.js b/packages/babel-plugin-transform-async-to-generator/src/index.js index 63b1e3888b..ac28f6aae4 100644 --- a/packages/babel-plugin-transform-async-to-generator/src/index.js +++ b/packages/babel-plugin-transform-async-to-generator/src/index.js @@ -2,15 +2,13 @@ import remapAsyncToGenerator from "babel-helper-remap-async-to-generator"; export default function () { return { - manipulateOptions(opts, parserOpts) { - parserOpts.plugins.push("asyncFunctions"); - }, + inherits: require("babel-plugin-syntax-async-functions"), visitor: { Function(path, state) { if (!path.node.async || path.node.generator) return; - remapAsyncToGenerator(path, state.addHelper("async-to-generator")); + remapAsyncToGenerator(path, state.addHelper("asyncToGenerator")); } } }; diff --git a/packages/babel-plugin-transform-comprehensions/.npmignore b/packages/babel-plugin-transform-async-to-module-method/.npmignore similarity index 100% rename from packages/babel-plugin-transform-comprehensions/.npmignore rename to packages/babel-plugin-transform-async-to-module-method/.npmignore diff --git a/packages/babel-plugin-transform-async-to-module-method/README.md b/packages/babel-plugin-transform-async-to-module-method/README.md new file mode 100644 index 0000000000..08179cebee --- /dev/null +++ b/packages/babel-plugin-transform-async-to-module-method/README.md @@ -0,0 +1,35 @@ +# babel-plugin-transform-async-to-module-method + +Turn async functions into a Bluebird coroutine + +## Installation + +```sh +$ npm install babel-plugin-transform-async-to-module-method +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-async-to-module-method"] +} +``` + +### Via CLI + +```sh +$ babel --plugins transform-async-to-module-method script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-async-to-module-method"] +}); +``` diff --git a/packages/babel-plugin-transform-async-to-module-method/package.json b/packages/babel-plugin-transform-async-to-module-method/package.json new file mode 100644 index 0000000000..82c36dc177 --- /dev/null +++ b/packages/babel-plugin-transform-async-to-module-method/package.json @@ -0,0 +1,17 @@ +{ + "name": "babel-plugin-transform-async-to-module-method", + "version": "1.0.0", + "description": "Turn async functions into a module method", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "babel-plugin-syntax-async-functions": "^5.0.0", + "babel-helper-remap-async-to-generator": "^5.0.0", + "babel-types": "^5.0.0", + "babel-runtime": "^5.8.20" + } +} diff --git a/packages/babel-plugin-transform-async-to-bluebird-coroutines/src/index.js b/packages/babel-plugin-transform-async-to-module-method/src/index.js similarity index 56% rename from packages/babel-plugin-transform-async-to-bluebird-coroutines/src/index.js rename to packages/babel-plugin-transform-async-to-module-method/src/index.js index cb9edf5203..3b8039bffe 100644 --- a/packages/babel-plugin-transform-async-to-bluebird-coroutines/src/index.js +++ b/packages/babel-plugin-transform-async-to-module-method/src/index.js @@ -1,11 +1,8 @@ import remapAsyncToGenerator from "babel-helper-remap-async-to-generator"; -import * as t from "babel-types"; export default function () { return { - manipulateOptions(opts, parserOpts) { - parserOpts.plugins.push("asyncFunctions"); - }, + inherits: require("babel-plugin-syntax-async-functions"), visitor: { Function(path, state) { @@ -13,7 +10,7 @@ export default function () { remapAsyncToGenerator( path, - t.memberExpression(state.addImport("bluebird", null, "absolute"), t.identifier("coroutine")) + state.addImport(state.opts.module, state.opts.method) ); } } diff --git a/packages/babel-plugin-transform-constant-folding/.npmignore b/packages/babel-plugin-transform-class-constructor-call/.npmignore similarity index 100% rename from packages/babel-plugin-transform-constant-folding/.npmignore rename to packages/babel-plugin-transform-class-constructor-call/.npmignore diff --git a/packages/babel-plugin-transform-class-constructor-call/README.md b/packages/babel-plugin-transform-class-constructor-call/README.md new file mode 100644 index 0000000000..4176c46722 --- /dev/null +++ b/packages/babel-plugin-transform-class-constructor-call/README.md @@ -0,0 +1,33 @@ +# babel-plugin-transform-class-construtor-call + +## Installation + +```sh +$ npm install babel-plugin-transform-class-construtor-call +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-class-construtor-call"] +} +``` + +### Via CLI + +```sh +$ babel --plugins transform-class-construtor-call script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-class-construtor-call"] +}); +``` diff --git a/packages/babel-plugin-transform-class-constructor-call/package.json b/packages/babel-plugin-transform-class-constructor-call/package.json new file mode 100644 index 0000000000..5fa2199934 --- /dev/null +++ b/packages/babel-plugin-transform-class-constructor-call/package.json @@ -0,0 +1,16 @@ +{ + "name": "babel-plugin-transform-class-construtor-call", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "babel-template": "^5.0.0", + "babel-plugin-syntax-class-constructor-call": "^5.0.0", + "babel-runtime": "^5.8.20" + } +} diff --git a/packages/babel-plugin-transform-class-constructor-call/src/index.js b/packages/babel-plugin-transform-class-constructor-call/src/index.js new file mode 100644 index 0000000000..25eb558433 --- /dev/null +++ b/packages/babel-plugin-transform-class-constructor-call/src/index.js @@ -0,0 +1,106 @@ +import template from "babel-template"; + +let buildWrapper = template(` + let CLASS_REF = CLASS; + var CALL_REF = CALL; + var WRAPPER_REF = function (...args) { + if (this instanceof WRAPPER_REF) { + return Reflect.construct(CLASS_REF, args); + } else { + return CALL_REF.apply(this, args); + } + }; + WRAPPER_REF.__proto__ = CLASS_REF; + WRAPPER_REF; +`); + +let buildSuperWrapper = template(` + let CLASS_REF = CLASS; + var WRAPPER_REF = function (...args) { + if (this instanceof WRAPPER_REF) { + return Reflect.construct(CLASS_REF, args); + } else { + return SUPER_REF.apply(this, args); + } + }; + WRAPPER_REF.__proto__ = CLASS_REF; + WRAPPER_REF; +`); + +export default function ({ types: t }) { + let ALREADY_VISITED = Symbol(); + + function findConstructorCall(path): ?Object { + let methods: Array = path.get("body.body"); + + for (let method of methods) { + if (method.node.kind === "constructorCall") { + return method; + } + } + + return null; + } + + function handleClassWithCall(constructorCall, classPath) { + let ref = classPath.node.id || classPath.scope.generateUidIdentifier("class"); + + classPath.replaceWithMultiple(buildWrapper({ + CLASS_REF: classPath.scope.generateUidIdentifier(ref.name), + CALL_REF: classPath.scope.generateUidIdentifier(`${ref.name}Call`), + CALL: t.functionExpression(null, constructorCall.node.params, constructorCall.node.body), + CLASS: t.toExpression(classPath.node), + WRAPPER_REF: ref + })); + + constructorCall.remove(); + } + + function handleClassWithSuper(path) { + // we could be inheriting from a class that has a call handler + let ref = path.node.id || path.scope.generateUidIdentifier("class"); + + let nodes = []; + let superRef; + + // we're going to be duplicating the reference to the super class so memoise it + // if necessary + if (path.get("superClass").isStatic()) { + superRef = path.node.superClass; + } else { + superRef = path.scope.generateUidIdentifier("super"); + nodes.push(t.variableDeclaration("var", [ + t.variableDeclarator(superRef, path.node.superClass) + ])); + path.node.superClass = superRef; + } + + path.replaceWithMultiple(nodes.concat(buildSuperWrapper({ + CLASS_REF: path.scope.generateUidIdentifier(ref.name), + SUPER_REF: superRef, + CLASS: t.toExpression(path.node), + WRAPPER_REF: ref + }))); + } + + return { + inherits: require("babel-plugin-syntax-class-constructor-call"), + + visitor: { + Class(path) { + if (path.node[ALREADY_VISITED]) return; + path.node[ALREADY_VISITED] = true; + + let constructorCall = findConstructorCall(path); + + if (constructorCall) { + handleClassWithCall(constructorCall, path); + } else if (path.has("superClass")) { + handleClassWithSuper(path); + } else { + return; + } + } + } + }; +} diff --git a/packages/babel-plugin-transform-class-properties/package.json b/packages/babel-plugin-transform-class-properties/package.json index 3fd49e2d99..8e571bfb93 100644 --- a/packages/babel-plugin-transform-class-properties/package.json +++ b/packages/babel-plugin-transform-class-properties/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-class-properties", - "version": "1.0.0", + "version": "5.10.32", "description": "", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-plugin-syntax-class-properties": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-class-properties/src/index.js b/packages/babel-plugin-transform-class-properties/src/index.js index 6845446a11..0ee7a915ac 100644 --- a/packages/babel-plugin-transform-class-properties/src/index.js +++ b/packages/babel-plugin-transform-class-properties/src/index.js @@ -1,7 +1,141 @@ -export default function () { +// todo: define instead of assign + +export default function ({ types: t }) { + let findBareSupers = { + Super(path) { + if (path.parentPath.isCallExpression({ callee: path.node })) { + this.push(path.parentPath); + } + } + }; + + let referenceVisitor = { + ReferencedIdentifier(path) { + if (this.scope.hasOwnBinding(path.node.name)) { + this.collision = true; + path.skip(); + } + } + }; + return { + inherits: require("babel-plugin-syntax-class-properties"), + visitor: { - // your visitor methods go here + Class(path) { + let isDerived = !!path.node.superClass; + let constructor; + let props = []; + let body = path.get("body"); + + for (let path of body.get("body")) { + if (path.isClassProperty()) { + props.push(path); + } else if (path.isClassMethod({ kind: "constructor" })) { + constructor = path; + } + } + + if (!props.length) return; + + let nodes = []; + let ref; + + if (path.isClassExpression()) { + ref = path.scope.generateUidIdentifier(); + } else { // path.isClassDeclaration() + ref = path.node.id; + } + + let instanceBody = []; + + for (let prop of props) { + let propNode = prop.node; + if (propNode.decorators) continue; + if (!propNode.value) continue; + + let isStatic = propNode.static; + + if (isStatic) { + nodes.push(t.expressionStatement( + t.assignmentExpression("=", t.memberExpression(ref, propNode.key), propNode.value) + )); + } else { + instanceBody.push(t.expressionStatement( + t.assignmentExpression("=", t.memberExpression(t.thisExpression(), propNode.key), propNode.value) + )); + } + } + + if (instanceBody.length) { + if (!constructor) { + let newConstructor = t.classMethod("constructor", t.identifier("constructor"), [], t.blockStatement([])); + if (isDerived) { + newConstructor.params = [t.restElement(t.identifier("args"))]; + newConstructor.body.body.push( + t.returnStatement( + t.callExpression( + t.super(), + [t.spreadElement(t.identifier("args"))] + ) + ) + ); + } + [constructor] = body.unshiftContainer("body", newConstructor); + } + + let collisionState = { + collision: false, + scope: constructor.scope + }; + + for (let prop of props) { + prop.traverse(referenceVisitor, collisionState); + if (collisionState.collision) break; + } + + if (collisionState.collision) { + let initialisePropsRef = path.scope.generateUidIdentifier("initialiseProps"); + + nodes.push(t.variableDeclaration("var", [ + t.variableDeclarator( + initialisePropsRef, + t.functionExpression(null, [], t.blockStatement(instanceBody)) + ) + ])); + + instanceBody = [ + t.expressionStatement( + t.callExpression(t.memberExpression(initialisePropsRef, t.identifier("call")), [t.thisExpression()]) + ) + ]; + } + + // + + if (isDerived) { + let bareSupers = [] + constructor.traverse(findBareSupers, bareSupers); + for (let bareSuper of bareSupers) { + bareSuper.insertAfter(instanceBody); + } + } else { + constructor.get("body").unshiftContainer("body", instanceBody); + } + } + + for (let prop of props) { + prop.remove(); + } + + if (!nodes.length) return; + + if (path.isClassExpression()) { + nodes.push(t.expressionStatement(ref)); + } + + path.insertAfter(nodes); + } } }; } diff --git a/packages/babel-plugin-transform-comprehensions/README.md b/packages/babel-plugin-transform-comprehensions/README.md deleted file mode 100644 index 96577a2e44..0000000000 --- a/packages/babel-plugin-transform-comprehensions/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# babel-plugin-transform-comprehensions - -Compile array and generator comprehensions to ES5 - -## Installation - -```sh -$ npm install babel-plugin-transform-comprehensions -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["transform-comprehensions"] -} -``` - -### Via CLI - -```sh -$ babel --plugins transform-comprehensions script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["transform-comprehensions"] -}); -``` diff --git a/packages/babel-plugin-transform-comprehensions/package.json b/packages/babel-plugin-transform-comprehensions/package.json deleted file mode 100644 index 65d8471a42..0000000000 --- a/packages/babel-plugin-transform-comprehensions/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "babel-plugin-transform-comprehensions", - "version": "1.0.0", - "description": "Compile array and generator comprehensions to ES5", - "repository": "babel/babel", - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin" - ] -} diff --git a/packages/babel-plugin-transform-comprehensions/src/index.js b/packages/babel-plugin-transform-comprehensions/src/index.js deleted file mode 100644 index 6845446a11..0000000000 --- a/packages/babel-plugin-transform-comprehensions/src/index.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function () { - return { - visitor: { - // your visitor methods go here - } - }; -} diff --git a/packages/babel-plugin-transform-constant-folding/README.md b/packages/babel-plugin-transform-constant-folding/README.md deleted file mode 100644 index 4e54697dd5..0000000000 --- a/packages/babel-plugin-transform-constant-folding/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# babel-plugin-transform-constant-folding - -Compile static constants (ie. code that we can statically determine to be constant at runtime) - -## Installation - -```sh -$ npm install babel-plugin-transform-constant-folding -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["transform-constant-folding"] -} -``` - -### Via CLI - -```sh -$ babel --plugins transform-constant-folding script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["transform-constant-folding"] -}); -``` diff --git a/packages/babel-plugin-transform-constant-folding/package.json b/packages/babel-plugin-transform-constant-folding/package.json deleted file mode 100644 index c0a30610ec..0000000000 --- a/packages/babel-plugin-transform-constant-folding/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "babel-plugin-transform-constant-folding", - "version": "1.0.1", - "description": "Compile static constants (ie. code that we can statically determine to be constant at runtime)", - "repository": "babel/babel", - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin" - ] -} diff --git a/packages/babel-plugin-transform-constant-folding/src/index.js b/packages/babel-plugin-transform-constant-folding/src/index.js deleted file mode 100644 index 885f285ac8..0000000000 --- a/packages/babel-plugin-transform-constant-folding/src/index.js +++ /dev/null @@ -1,69 +0,0 @@ -export default function ({ types: t }) { - return { - visitor: { - AssignmentExpression() { - var left = this.get("left"); - if (!left.isIdentifier()) return; - - var binding = this.scope.getBinding(left.node.name); - if (!binding || binding.hasDeoptValue) return; - - var evaluated = this.get("right").evaluate(); - if (evaluated.confident) { - binding.setValue(evaluated.value); - } else { - binding.deoptValue(); - } - }, - - IfStatement(path) { - var evaluated = path.get("test").evaluate(); - if (!evaluated.confident) { - // todo: deopt binding values for constant violations inside - return path.skip(); - } - - if (evaluated.value) { - path.skipKey("alternate"); - } else { - path.skipKey("consequent"); - } - }, - - Scopable: { - enter(path) { - var funcScope = path.scope.getFunctionParent(); - - for (var name in path.scope.bindings) { - var binding = path.scope.bindings[name]; - var deopt = false; - - for (let path of (binding.constantViolations: Array)) { - var funcViolationScope = path.scope.getFunctionParent(); - if (funcViolationScope !== funcScope) { - deopt = true; - break; - } - } - - if (deopt) binding.deoptValue(); - } - }, - - exit(path) { - for (var name in path.scope.bindings) { - var binding = path.scope.bindings[name]; - binding.clearValue(); - } - } - }, - - Expression: { - exit(path) { - var res = path.evaluate(); - if (res.confident) return t.valueToNode(res.value); - } - } - } - }; -} diff --git a/packages/babel-plugin-transform-dead-code-elimination/README.md b/packages/babel-plugin-transform-dead-code-elimination/README.md deleted file mode 100644 index d5c9c10eb8..0000000000 --- a/packages/babel-plugin-transform-dead-code-elimination/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# babel-plugin-transform-dead-code-elimination - -Eliminate dead code - -## Installation - -```sh -$ npm install babel-plugin-transform-dead-code-elimination -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["transform-dead-code-elimination"] -} -``` - -### Via CLI - -```sh -$ babel --plugins transform-dead-code-elimination script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["transform-dead-code-elimination"] -}); -``` diff --git a/packages/babel-plugin-transform-dead-code-elimination/package.json b/packages/babel-plugin-transform-dead-code-elimination/package.json deleted file mode 100644 index ccae3de84f..0000000000 --- a/packages/babel-plugin-transform-dead-code-elimination/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "babel-plugin-transform-dead-code-elimination", - "version": "1.0.2", - "description": "Eliminate dead code", - "repository": "babel/babel", - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin" - ] -} diff --git a/packages/babel-plugin-transform-dead-code-elimination/src/index.js b/packages/babel-plugin-transform-dead-code-elimination/src/index.js deleted file mode 100644 index 6a2a4478e9..0000000000 --- a/packages/babel-plugin-transform-dead-code-elimination/src/index.js +++ /dev/null @@ -1,152 +0,0 @@ -export default function ({ types: t }) { - function toStatements(node) { - if (t.isBlockStatement(node)) { - var hasBlockScoped = false; - - for (var i = 0; i < node.body.length; i++) { - var bodyNode = node.body[i]; - if (t.isBlockScoped(bodyNode)) hasBlockScoped = true; - } - - if (!hasBlockScoped) { - return node.body; - } - } - - return node; - } - - var visitor = { - ReferencedIdentifier(path) { - var { node, scope } = path; - - var binding = scope.getBinding(node.name); - if (!binding || binding.references > 1 || !binding.constant) return; - if (binding.kind === "param" || binding.kind === "module") return; - if (t.isExportDeclaration(binding.path.parent)) return; - - var replacement = binding.path.node; - if (t.isVariableDeclarator(replacement)) { - replacement = replacement.init; - } - if (!replacement) return; - - // ensure it's a "pure" type - if (!scope.isPure(replacement, true)) return; - - if (t.isClass(replacement) || t.isFunction(replacement)) { - // don't change this if it's in a different scope, this can be bad - // for performance since it may be inside a loop or deeply nested in - // hot code - if (binding.path.scope.parent !== scope) return; - } - - if (path.findParent((path) => path.node === replacement)) { - return; - } - - t.toExpression(replacement); - scope.removeBinding(node.name); - binding.path.remove(); - return replacement; - }, - - "ClassDeclaration|FunctionDeclaration"(path) { - var binding = path.scope.getBinding(path.node.id.name); - if (binding && !binding.referenced) { - path.remove(); - } - }, - - VariableDeclarator({ node, scope }) { - if (!t.isIdentifier(node.id) || !scope.isPure(node.init, true)) return; - visitor["ClassDeclaration|FunctionDeclaration"].apply(this, arguments); - }, - - ConditionalExpression(path) { - var evaluateTest = path.get("test").evaluateTruthy(); - if (evaluateTest === true) { - return path.node.consequent; - } else if (evaluateTest === false) { - return path.node.alternate; - } - }, - - BlockStatement(path) { - var paths: Array = path.get("body"); - - var purge = false; - - for (let path of paths) { - if (!purge && path.isCompletionStatement()) { - purge = true; - continue; - } - - if (purge && !path.isFunctionDeclaration()) { - path.remove(); - } - } - }, - - IfStatement: { - exit(path) { - var { node } = path; - var consequent = node.consequent; - var alternate = node.alternate; - var test = node.test; - - var evaluateTest = path.get("test").evaluateTruthy(); - - // we can check if a test will be truthy 100% and if so then we can inline - // the consequent and completely ignore the alternate - // - // if (true) { foo; } -> { foo; } - // if ("foo") { foo; } -> { foo; } - // - - if (evaluateTest === true) { - return toStatements(consequent); - } - - // we can check if a test will be falsy 100% and if so we can inline the - // alternate if there is one and completely remove the consequent - // - // if ("") { bar; } else { foo; } -> { foo; } - // if ("") { bar; } -> - // - - if (evaluateTest === false) { - if (alternate) { - return toStatements(alternate); - } else { - return path.remove(); - } - } - - // remove alternate blocks that are empty - // - // if (foo) { foo; } else {} -> if (foo) { foo; } - // - - if (t.isBlockStatement(alternate) && !alternate.body.length) { - alternate = node.alternate = null; - } - - // if the consequent block is empty turn alternate blocks into a consequent - // and flip the test - // - // if (foo) {} else { bar; } -> if (!foo) { bar; } - // - - if (t.isBlockStatement(consequent) && !consequent.body.length && t.isBlockStatement(alternate) && alternate.body.length) { - node.consequent = node.alternate; - node.alternate = null; - node.test = t.unaryExpression("!", test, true); - } - } - } - }; - - return { visitor }; -} diff --git a/packages/babel-plugin-transform-decorators/package.json b/packages/babel-plugin-transform-decorators/package.json index d42435aa62..4d5408a0ac 100644 --- a/packages/babel-plugin-transform-decorators/package.json +++ b/packages/babel-plugin-transform-decorators/package.json @@ -1,11 +1,19 @@ { "name": "babel-plugin-transform-decorators", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile class and object decorators to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-types": "^5.10.32", + "babel-helper-define-map": "^5.0.0", + "babel-plugin-syntax-decorators": "^5.10.32", + "babel-helper-explode-class": "^5.0.0", + "babel-template": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-decorators/src/index.js b/packages/babel-plugin-transform-decorators/src/index.js index 6845446a11..dbad41c823 100644 --- a/packages/babel-plugin-transform-decorators/src/index.js +++ b/packages/babel-plugin-transform-decorators/src/index.js @@ -1,7 +1,111 @@ -export default function () { +import template from "babel-template"; +import explodeClass from "babel-helper-explode-class"; + +let buildClassDecorator = template(` + CLASS_REF = DECORATOR(CLASS_REF) || CLASS_REF; +`); + +export default function ({ types: t }) { + function cleanDecorators(decorators) { + return decorators.reverse().map(dec => dec.expression); + } + + function transformClass(path, ref, state) { + let nodes = []; + + state; + + let classDecorators = path.node.decorators; + if (classDecorators) { + path.node.decorators = null; + classDecorators = cleanDecorators(classDecorators); + + for (let decorator of classDecorators) { + nodes.push(buildClassDecorator({ + CLASS_REF: ref, + DECORATOR: decorator + })); + } + } + + let map = Object.create(null); + + for (let method of path.get("body.body")) { + let decorators = method.node.decorators; + if (!decorators) continue; + + let alias = t.toKeyAlias(method.node); + map[alias] = map[alias] || []; + map[alias].push(method.node); + + method.remove(); + } + + for (let alias in map) { + let items = map[alias]; + + items; + } + + return nodes; + } + + function hasDecorators(path) { + if (path.isClass()) { + if (path.node.decorators) return true; + + for (let method of (path.node.body.body: Array)) { + if (method.decorators) { + return true; + } + } + } else if (path.isObjectExpression()) { + for (let prop of (path.node.properties: Array)) { + if (prop.decorators) { + return true; + } + } + } + + return false; + } + return { + inherits: require("babel-plugin-syntax-decorators"), + visitor: { - // your visitor methods go here + ClassExpression(path) { + if (!hasDecorators(path)) return; + explodeClass(path); + + let ref = path.scope.generateDeclaredUidIdentifier("ref"); + let nodes = []; + + nodes.push(t.assignmentExpression("=", ref, path.node)); + + nodes = nodes.concat(transformClass(path, ref, this)); + + nodes.push(ref); + + path.replaceWith(t.sequenceExpression(nodes)); + }, + + ClassDeclaration(path) { + if (!hasDecorators(path)) return; + explodeClass(path); + + let ref = path.node.id; + let nodes = []; + + nodes = nodes.concat(transformClass(path, ref, this).map(expr => t.expressionStatement(expr))); + nodes.push(t.expressionStatement(ref)); + + path.insertAfter(nodes); + }, + + ObjectExpression(path) { + if (!hasDecorators(path)) return; + } } }; } diff --git a/packages/babel-plugin-transform-do-expressions/package.json b/packages/babel-plugin-transform-do-expressions/package.json index a9bd561141..ec4f747f74 100644 --- a/packages/babel-plugin-transform-do-expressions/package.json +++ b/packages/babel-plugin-transform-do-expressions/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-do-expressions", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile do expressions to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-plugin-syntax-do-expressions": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-do-expressions/src/index.js b/packages/babel-plugin-transform-do-expressions/src/index.js index 6845446a11..8bfe9c0dc5 100644 --- a/packages/babel-plugin-transform-do-expressions/src/index.js +++ b/packages/babel-plugin-transform-do-expressions/src/index.js @@ -1,7 +1,16 @@ export default function () { return { + inherits: require("babel-plugin-syntax-do-expressions"), + visitor: { - // your visitor methods go here + DoExpression(path) { + let body = path.node.body.body; + if (body.length) { + path.replaceWithMultiple(body); + } else { + path.replaceWith(path.scope.buildUndefinedNode()); + } + } } }; } diff --git a/packages/babel-plugin-transform-es2015-arrow-functions/package.json b/packages/babel-plugin-transform-es2015-arrow-functions/package.json index 42eabb2309..0f06fbc04b 100644 --- a/packages/babel-plugin-transform-es2015-arrow-functions/package.json +++ b/packages/babel-plugin-transform-es2015-arrow-functions/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es2015-arrow-functions", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 arrow functions to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-arrow-functions/src/index.js b/packages/babel-plugin-transform-es2015-arrow-functions/src/index.js index 017853c983..1d4c91fee7 100644 --- a/packages/babel-plugin-transform-es2015-arrow-functions/src/index.js +++ b/packages/babel-plugin-transform-es2015-arrow-functions/src/index.js @@ -3,24 +3,27 @@ export default function ({ types: t }) { visitor: { ArrowFunctionExpression(path, state) { if (state.opts.spec) { - if (path.node.shadow) return; - path.node.shadow = { this: false }; + let { node } = path; + if (node.shadow) return; - var boundThis = t.thisExpression(); + node.shadow = { this: false }; + node.type = "FunctionExpression"; + + let boundThis = t.thisExpression(); boundThis._forceShadow = path; // make sure that arrow function won't be instantiated path.ensureBlock(); path.get("body").unshiftContainer( "body", - t.expressionStatement(t.callExpression(state.addHelper("new-arrow-check"), [ + t.expressionStatement(t.callExpression(state.addHelper("newArrowCheck"), [ t.thisExpression(), boundThis ])) ); path.replaceWith(t.callExpression( - t.memberExpression(path.node, t.identifier("bind")), + t.memberExpression(node, t.identifier("bind")), [t.thisExpression()] )); } else { diff --git a/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json b/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json index b23f5f3ff4..23c57a8c6c 100644 --- a/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json +++ b/packages/babel-plugin-transform-es2015-block-scoped-functions/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es2015-block-scoped-functions", - "version": "1.0.4", + "version": "5.10.32", "description": "Babel plugin to ensure function declarations at the block level are block scoped", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js b/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js index 192df08324..a1aac15dc3 100644 --- a/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js +++ b/packages/babel-plugin-transform-es2015-block-scoped-functions/src/index.js @@ -1,13 +1,12 @@ export default function ({ types: t }) { function statementList(key, path) { - var paths: Array = path.get(key); + let paths: Array = path.get(key); for (let path of paths) { - var func = path.node; - + let func = path.node; if (!path.isFunctionDeclaration()) continue; - var declar = t.variableDeclaration("let", [ + let declar = t.variableDeclaration("let", [ t.variableDeclarator(func.id, t.toExpression(func)) ]); @@ -23,16 +22,17 @@ export default function ({ types: t }) { return { visitor: { - BlockStatement(node, parent) { - if ((t.isFunction(parent) && parent.body === node) || t.isExportDeclaration(parent)) { + BlockStatement(path) { + let { node, parent } = path; + if (t.isFunction(parent, { body: node }) || t.isExportDeclaration(parent)) { return; } - statementList("body", this); + statementList("body", path); }, - SwitchCase() { - statementList("consequent", this); + SwitchCase(path) { + statementList("consequent", path); } } }; diff --git a/packages/babel-plugin-transform-es2015-block-scoping/package.json b/packages/babel-plugin-transform-es2015-block-scoping/package.json index 86ab3ac07a..e675853033 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/package.json +++ b/packages/babel-plugin-transform-es2015-block-scoping/package.json @@ -1,11 +1,18 @@ { "name": "babel-plugin-transform-es2015-block-scoping", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 block scoping (const and let) to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", + "dependencies": { + "babel-traverse": "^5.10.32", + "babel-types": "^5.10.32", + "babel-template": "^5.10.32", + "lodash": "^3.10.0", + "babel-runtime": "^5.10.32" + }, "keywords": [ "babel-plugin" ] -} +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-block-scoping/src/index.js b/packages/babel-plugin-transform-es2015-block-scoping/src/index.js index 6845446a11..1167b0073b 100644 --- a/packages/babel-plugin-transform-es2015-block-scoping/src/index.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/src/index.js @@ -1,7 +1,657 @@ +import type NodePath from "babel-traverse"; +import type Scope from "babel-traverse"; +import type File from "../../../file"; +import traverse from "babel-traverse"; +import { visitor as tdzVisitor } from "./tdz"; +import * as t from "babel-types"; +import values from "lodash/object/values"; +import extend from "lodash/object/extend"; +import template from "babel-template"; + export default function () { return { visitor: { - // your visitor methods go here + VariableDeclaration(path, file) { + let { node, parent, scope } = path; + if (!isLet(node, parent, scope)) return; + + if (isLetInitable(node) && node._tdzThis) { + let nodes = [node]; + + for (let i = 0; i < node.declarations.length; i++) { + let decl = node.declarations[i]; + if (decl.init) { + let assign = t.assignmentExpression("=", decl.id, decl.init); + assign._ignoreBlockScopingTDZ = true; + nodes.push(t.expressionStatement(assign)); + } + decl.init = file.addHelper("temporalUndefined"); + } + + node._blockHoist = 2; + + if (path.isCompletionRecord()) { + // ensure we don't break completion record semantics by returning + // the initialiser of the last declarator + nodes.push(t.expressionStatement(scope.buildUndefinedNode())); + } + + path.replaceWithMultiple(nodes); + } + }, + + Loop(path, file) { + let { node, parent, scope } = path; + + let init = node.left || node.init; + if (isLet(init, node, scope)) { + t.ensureBlock(node); + node.body._letDeclarators = [init]; + } + + let blockScoping = new BlockScoping(path, path.get("body"), parent, scope, file); + let replace = blockScoping.run(); + if (replace) path.replaceWith(replace); + }, + + "BlockStatement|Program"(path, file) { + if (!t.isLoop(path.parent)) { + let blockScoping = new BlockScoping(null, path, path.parent, path.scope, file); + blockScoping.run(); + } + } } }; } + +let buildRetCheck = template(` + if (typeof RETURN === "object") return RETURN.v; +`); + +function isLet(node, parent, scope) { + if (!t.isVariableDeclaration(node)) return false; + if (node._let) return true; + if (node.kind !== "let") return false; + + // https://github.com/babel/babel/issues/255 + if (isLetInitable(node, parent)) { + for (let i = 0; i < node.declarations.length; i++) { + let declar = node.declarations[i]; + declar.init = declar.init || scope.buildUndefinedNode(); + } + } + + node._let = true; + node.kind = "var"; + return true; +} + +function isLetInitable(node, parent) { + return !t.isFor(parent) || !t.isFor(parent, { left: node }); +} + +function isVar(node, parent, scope) { + return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent, scope); +} + +function standardizeLets(declars) { + for (let declar of (declars: Array)) { + delete declar._let; + } +} + +function replace(path, node, scope, remaps) { + let remap = remaps[node.name]; + if (!remap) return; + + let ownBinding = scope.getBindingIdentifier(node.name); + if (ownBinding === remap.binding) { + node.name = remap.uid; + } else { + // scope already has it's own binding that doesn't + // match the one we have a stored replacement for + if (path) path.skip(); + } +} + +let replaceVisitor = { + ReferencedIdentifier(path, remaps) { + replace(path, path.node, path.scope, remaps); + }, + + AssignmentExpression(path, remaps) { + let ids = path.getBindingIdentifiers(); + for (let name in ids) { + replace(null, ids[name], path.scope, remaps); + } + }, +}; + +function traverseReplace(node, parent, scope, remaps) { + if (t.isIdentifier(node)) { + replace(node, parent, scope, remaps); + } + + if (t.isAssignmentExpression(node)) { + let ids = t.getBindingIdentifiers(node); + for (let name in ids) { + replace(ids[name], parent, scope, remaps); + } + } + + scope.traverse(node, replaceVisitor, remaps); +} + +let letReferenceBlockVisitor = traverse.visitors.merge([{ + Function(path, state) { + path.traverse(letReferenceFunctionVisitor, state); + return path.skip(); + } +}, tdzVisitor]); + +let letReferenceFunctionVisitor = traverse.visitors.merge([{ + ReferencedIdentifier(path, state) { + let ref = state.letReferences[path.node.name]; + + // not a part of our scope + if (!ref) return; + + // this scope has a variable with the same name so it couldn't belong + // to our let scope + let localBinding = path.scope.getBindingIdentifier(path.node.name); + if (localBinding && localBinding !== ref) return; + + state.closurify = true; + } +}, tdzVisitor]); + +let hoistVarDeclarationsVisitor = { + enter(path, self) { + let { node, parent, scope } = path; + + if (path.isForStatement()) { + if (isVar(node.init, node, scope)) { + let nodes = self.pushDeclar(node.init); + if (nodes.length === 1) { + node.init = nodes[0]; + } else { + node.init = t.sequenceExpression(nodes); + } + } + } else if (path.isFor()) { + if (isVar(node.left, node, scope)) { + self.pushDeclar(node.left); + node.left = node.left.declarations[0].id; + } + } else if (isVar(node, parent, scope)) { + path.replaceWithMultiple(self.pushDeclar(node).map(t.expressionStatement)); + } else if (path.isFunction()) { + return path.skip(); + } + } +}; + +let loopLabelVisitor = { + LabeledStatement({ node }, state) { + state.innerLabels.push(node.label.name); + } +}; + +let continuationVisitor = { + enter(path, state) { + if (path.isAssignmentExpression() || path.isUpdateExpression()) { + let bindings = path.getBindingIdentifiers(); + for (let name in bindings) { + if (state.outsideReferences[name] !== path.scope.getBindingIdentifier(name)) continue; + state.reassignments[name] = true; + } + } + } +}; + +function loopNodeTo(node) { + if (t.isBreakStatement(node)) { + return "break"; + } else if (t.isContinueStatement(node)) { + return "continue"; + } +} + +let loopVisitor = { + Loop(path, state) { + let oldIgnoreLabeless = state.ignoreLabeless; + state.ignoreLabeless = true; + path.traverse(loopVisitor, state); + state.ignoreLabeless = oldIgnoreLabeless; + path.skip(); + }, + + Function(path) { + path.skip(); + }, + + SwitchCase(path, state) { + let oldInSwitchCase = state.inSwitchCase; + state.inSwitchCase = true; + path.traverse(loopVisitor, state); + state.inSwitchCase = oldInSwitchCase; + path.skip(); + }, + + "BreakStatement|ContinueStatement|ReturnStatement"(path, state) { + let { node, parent, scope } = path; + if (node[this.LOOP_IGNORE]) return; + + let replace; + let loopText = loopNodeTo(node); + + if (loopText) { + if (node.label) { + // we shouldn't be transforming this because it exists somewhere inside + if (state.innerLabels.indexOf(node.label.name) >= 0) { + return; + } + + loopText = `${loopText}|${node.label.name}`; + } else { + // we shouldn't be transforming these statements because + // they don't refer to the actual loop we're scopifying + if (state.ignoreLabeless) return; + + // + if (state.inSwitchCase) return; + + // break statements mean something different in this context + if (t.isBreakStatement(node) && t.isSwitchCase(parent)) return; + } + + state.hasBreakContinue = true; + state.map[loopText] = node; + replace = t.stringLiteral(loopText); + } + + if (path.isReturnStatement()) { + state.hasReturn = true; + replace = t.objectExpression([ + t.objectProperty(t.identifier("v"), node.argument || scope.buildUndefinedNode()) + ]); + } + + if (replace) { + replace = t.returnStatement(replace); + replace[this.LOOP_IGNORE] = true; + path.skip(); + path.replaceWith(t.inherits(replace, node)); + } + } +}; + +class BlockScoping { + constructor(loopPath?: NodePath, blockPath: NodePath, parent: Object, scope: Scope, file: File) { + this.parent = parent; + this.scope = scope; + this.file = file; + + this.blockPath = blockPath; + this.block = blockPath.node; + + this.outsideLetReferences = Object.create(null); + this.hasLetReferences = false; + this.letReferences = Object.create(null); + this.body = []; + + if (loopPath) { + this.loopParent = loopPath.parent; + this.loopLabel = t.isLabeledStatement(this.loopParent) && this.loopParent.label; + this.loopPath = loopPath; + this.loop = loopPath.node; + } + } + + /** + * Start the ball rolling. + */ + + run() { + let block = this.block; + if (block._letDone) return; + block._letDone = true; + + let needsClosure = this.getLetReferences(); + + // this is a block within a `Function/Program` so we can safely leave it be + if (t.isFunction(this.parent) || t.isProgram(this.block)) return; + + // we can skip everything + if (!this.hasLetReferences) return; + + if (needsClosure) { + this.wrapClosure(); + } else { + this.remap(); + } + + if (this.loopLabel && !t.isLabeledStatement(this.loopParent)) { + return t.labeledStatement(this.loopLabel, this.loop); + } + } + + remap() { + let hasRemaps = false; + let letRefs = this.letReferences; + let scope = this.scope; + + // alright, so since we aren't wrapping this block in a closure + // we have to check if any of our let variables collide with + // those in upper scopes and then if they do, generate a uid + // for them and replace all references with it + let remaps = Object.create(null); + + for (let key in letRefs) { + // just an Identifier node we collected in `getLetReferences` + // this is the defining identifier of a declaration + let ref = letRefs[key]; + + // todo: could skip this if the colliding binding is in another function + if (scope.parentHasBinding(key) || scope.hasGlobal(key)) { + let uid = scope.generateUidIdentifier(ref.name).name; + ref.name = uid; + + hasRemaps = true; + remaps[key] = remaps[uid] = { + binding: ref, + uid: uid + }; + } + } + + if (!hasRemaps) return; + + // + + let loop = this.loop; + if (loop) { + traverseReplace(loop.right, loop, scope, remaps); + traverseReplace(loop.test, loop, scope, remaps); + traverseReplace(loop.update, loop, scope, remaps); + } + + this.blockPath.traverse(replaceVisitor, remaps); + } + + wrapClosure() { + let block = this.block; + + let outsideRefs = this.outsideLetReferences; + + // remap loop heads with colliding variables + if (this.loop) { + for (let name in outsideRefs) { + let id = outsideRefs[name]; + + if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) { + delete outsideRefs[id.name]; + delete this.letReferences[id.name]; + + this.scope.rename(id.name); + + this.letReferences[id.name] = id; + outsideRefs[id.name] = id; + } + } + } + + // if we're inside of a for loop then we search to see if there are any + // `break`s, `continue`s, `return`s etc + this.has = this.checkLoop(); + + // hoist let references to retain scope + this.hoistVarDeclarations(); + + // turn outsideLetReferences into an array + let params = values(outsideRefs); + let args = values(outsideRefs); + + // build the closure that we're going to wrap the block with + let fn = t.functionExpression(null, params, t.blockStatement(block.body)); + fn.shadow = true; + + // continuation + this.addContinuations(fn); + + // replace the current block body with the one we're going to build + block.body = this.body; + + let ref = fn; + + if (this.loop) { + ref = this.scope.generateUidIdentifier("loop"); + this.loopPath.insertBefore(t.variableDeclaration("var", [ + t.variableDeclarator(ref, fn) + ])); + } + + // build a call and a unique id that we can assign the return value to + let call = t.callExpression(ref, args); + let ret = this.scope.generateUidIdentifier("ret"); + + // handle generators + let hasYield = traverse.hasType(fn.body, this.scope, "YieldExpression", t.FUNCTION_TYPES); + if (hasYield) { + fn.generator = true; + call = t.yieldExpression(call, true); + } + + // handlers async functions + let hasAsync = traverse.hasType(fn.body, this.scope, "AwaitExpression", t.FUNCTION_TYPES); + if (hasAsync) { + fn.async = true; + call = t.awaitExpression(call); + } + + this.buildClosure(ret, call); + } + + /** + * Push the closure to the body. + */ + + buildClosure(ret: { type: "Identifier" }, call: { type: "CallExpression" }) { + let has = this.has; + if (has.hasReturn || has.hasBreakContinue) { + this.buildHas(ret, call); + } else { + this.body.push(t.expressionStatement(call)); + } + } + + /** + * If any of the outer let variables are reassigned then we need to rename them in + * the closure so we can get direct access to the outer variable to continue the + * iteration with bindings based on each iteration. + * + * Reference: https://github.com/babel/babel/issues/1078 + */ + + addContinuations(fn) { + let state = { + reassignments: {}, + outsideReferences: this.outsideLetReferences + }; + + this.scope.traverse(fn, continuationVisitor, state); + + for (let i = 0; i < fn.params.length; i++) { + let param = fn.params[i]; + if (!state.reassignments[param.name]) continue; + + let newParam = this.scope.generateUidIdentifier(param.name); + fn.params[i] = newParam; + + this.scope.rename(param.name, newParam.name, fn); + + // assign outer reference as it's been modified internally and needs to be retained + fn.body.body.push(t.expressionStatement(t.assignmentExpression("=", param, newParam))); + } + } + + getLetReferences() { + let block = this.block; + + let declarators = block._letDeclarators || []; + + // + for (let i = 0; i < declarators.length; i++) { + let declar = declarators[i]; + extend(this.outsideLetReferences, t.getBindingIdentifiers(declar)); + } + + // + if (block.body) { + for (let i = 0; i < block.body.length; i++) { + let declar = block.body[i]; + if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar) || isLet(declar, block, this.scope)) { + declarators = declarators.concat(declar.declarations || declar); + } + } + } + + // + for (let i = 0; i < declarators.length; i++) { + let declar = declarators[i]; + let keys = t.getBindingIdentifiers(declar); + extend(this.letReferences, keys); + this.hasLetReferences = true; + } + + // no let references so we can just quit + if (!this.hasLetReferences) return; + + // set let references to plain let references + standardizeLets(declarators); + + let state = { + letReferences: this.letReferences, + closurify: false, + file: this.file + }; + + // traverse through this block, stopping on functions and checking if they + // contain any local let references + this.blockPath.traverse(letReferenceBlockVisitor, state); + + return state.closurify; + } + + /** + * If we're inside of a loop then traverse it and check if it has one of + * the following node types `ReturnStatement`, `BreakStatement`, + * `ContinueStatement` and replace it with a return value that we can track + * later on. + */ + + checkLoop(): Object { + let state = { + hasBreakContinue: false, + ignoreLabeless: false, + inSwitchCase: false, + innerLabels: [], + hasReturn: false, + isLoop: !!this.loop, + map: {}, + LOOP_IGNORE: Symbol() + }; + + this.blockPath.traverse(loopLabelVisitor, state); + this.blockPath.traverse(loopVisitor, state); + + return state; + } + + /** + * Hoist all let declarations in this block to before it so they retain scope + * once we wrap everything in a closure. + */ + + hoistVarDeclarations() { + this.blockPath.traverse(hoistVarDeclarationsVisitor, this); + } + + /** + * Turn a `VariableDeclaration` into an array of `AssignmentExpressions` with + * their declarations hoisted to before the closure wrapper. + */ + + pushDeclar(node: { type: "VariableDeclaration" }): Array { + let declars = []; + let names = t.getBindingIdentifiers(node); + for (let name in names) { + declars.push(t.variableDeclarator(names[name])); + } + + this.body.push(t.variableDeclaration(node.kind, declars)); + + let replace = []; + + for (let i = 0; i < node.declarations.length; i++) { + let declar = node.declarations[i]; + if (!declar.init) continue; + + let expr = t.assignmentExpression("=", declar.id, declar.init); + replace.push(t.inherits(expr, declar)); + } + + return replace; + } + + buildHas(ret: { type: "Identifier" }, call: { type: "CallExpression" }) { + let body = this.body; + + body.push(t.variableDeclaration("var", [ + t.variableDeclarator(ret, call) + ])); + + let retCheck; + let has = this.has; + let cases = []; + + if (has.hasReturn) { + // typeof ret === "object" + retCheck = buildRetCheck({ + RETURN: ret + }); + } + + if (has.hasBreakContinue) { + for (let key in has.map) { + cases.push(t.switchCase(t.stringLiteral(key), [has.map[key]])); + } + + if (has.hasReturn) { + cases.push(t.switchCase(null, [retCheck])); + } + + if (cases.length === 1) { + let single = cases[0]; + body.push(t.ifStatement( + t.binaryExpression("===", ret, single.test), + single.consequent[0] + )); + } else { + // https://github.com/babel/babel/issues/998 + for (let i = 0; i < cases.length; i++) { + let caseConsequent = cases[i].consequent[0]; + if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) { + caseConsequent.label = this.loopLabel = this.loopLabel || this.scope.generateUidIdentifier("loop"); + } + } + + body.push(t.switchStatement(ret, cases)); + } + } else { + if (has.hasReturn) { + body.push(retCheck); + } + } + } +} diff --git a/packages/babel-core/src/transformation/transformers/es6/block-scoping/tdz.js b/packages/babel-plugin-transform-es2015-block-scoping/src/tdz.js similarity index 66% rename from packages/babel-core/src/transformation/transformers/es6/block-scoping/tdz.js rename to packages/babel-plugin-transform-es2015-block-scoping/src/tdz.js index 718976b6f1..dafe46351c 100644 --- a/packages/babel-core/src/transformation/transformers/es6/block-scoping/tdz.js +++ b/packages/babel-plugin-transform-es2015-block-scoping/src/tdz.js @@ -14,8 +14,8 @@ function getTDZStatus(refPath, bindingPath) { function buildTDZAssert(node, file) { return t.callExpression( - file.addHelper("temporal-assert-defined"), - [node, t.stringLiteral(node.name), file.addHelper("temporal-undefined")] + file.addHelper("temporalRef"), + [node, t.stringLiteral(node.name), file.addHelper("temporalUndefined")] ); } @@ -28,13 +28,17 @@ function isReference(node, scope, state) { } export let visitor = { - ReferencedIdentifier(node, parent, scope, state) { - if (t.isFor(parent, { left: node })) return; + ReferencedIdentifier(path, state) { + if (!this.file.opts.tdz) return; + + let { node, parent, scope } = path; + + if (path.parentPath.isFor({ left: node })) return; if (!isReference(node, scope, state)) return; let bindingPath = scope.getBinding(node.name).path; - let status = getTDZStatus(this, bindingPath); + let status = getTDZStatus(path, bindingPath); if (status === "inside") return; if (status === "maybe") { @@ -43,35 +47,38 @@ export let visitor = { // add tdzThis to parent variable declarator so it's exploded bindingPath.parent._tdzThis = true; - this.skip(); + path.skip(); - if (t.isUpdateExpression(parent)) { + if (path.parentPath.isUpdateExpression()) { if (parent._ignoreBlockScopingTDZ) return; - this.parentPath.replaceWith(t.sequenceExpression([assert, parent])); + path.parentPath.replaceWith(t.sequenceExpression([assert, parent])); } else { - return t.logicalExpression("&&", assert, node); + path.replaceWith(assert); } } else if (status === "outside") { - return t.throwStatement(t.inherits( + path.replaceWith(t.throwStatement(t.inherits( t.newExpression(t.identifier("ReferenceError"), [ t.stringLiteral(`${node.name} is not defined - temporal dead zone`) ]), node - )); + ))); } }, AssignmentExpression: { - exit(node, parent, scope, state) { + exit(path, state) { + if (!this.file.opts.tdz) return; + + let { node } = path; if (node._ignoreBlockScopingTDZ) return; let nodes = []; - let ids = this.getBindingIdentifiers(); + let ids = path.getBindingIdentifiers(); for (let name in ids) { let id = ids[name]; - if (isReference(id, scope, state)) { + if (isReference(id, path.scope, state)) { nodes.push(buildTDZAssert(id, state.file)); } } @@ -79,7 +86,7 @@ export let visitor = { if (nodes.length) { node._ignoreBlockScopingTDZ = true; nodes.push(node); - return nodes.map(t.expressionStatement); + path.replaceWithMultiple(nodes.map(t.expressionStatement)); } } } diff --git a/packages/babel-plugin-transform-es2015-classes/package.json b/packages/babel-plugin-transform-es2015-classes/package.json index e67c9f019e..151d88b2c1 100644 --- a/packages/babel-plugin-transform-es2015-classes/package.json +++ b/packages/babel-plugin-transform-es2015-classes/package.json @@ -1,11 +1,21 @@ { "name": "babel-plugin-transform-es2015-classes", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 classes to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", + "dependencies": { + "babel-helper-optimise-call-expression": "^5.0.0", + "babel-helper-function-name": "^5.0.0", + "babel-helper-replace-supers": "^5.0.0", + "babel-template": "^5.10.32", + "babel-traverse": "^5.10.32", + "babel-helper-define-map": "^5.0.0", + "babel-messages": "^5.10.32", + "babel-runtime": "^5.10.32" + }, "keywords": [ "babel-plugin" ] -} +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-classes/src/index.js b/packages/babel-plugin-transform-es2015-classes/src/index.js index 6845446a11..861a20fae2 100644 --- a/packages/babel-plugin-transform-es2015-classes/src/index.js +++ b/packages/babel-plugin-transform-es2015-classes/src/index.js @@ -1,7 +1,32 @@ -export default function () { +import LooseTransformer from "./loose"; +import VanillaTransformer from "./vanilla"; +import nameFunction from "babel-helper-function-name"; + +export default function ({ types: t }) { return { visitor: { - // your visitor methods go here + ClassDeclaration(path) { + let { node } = path; + + if (path.parentPath.isExportDefaultDeclaration()) { + path = path.parentPath; + path.insertAfter(t.exportDefaultDeclaration(node.id)); + } + + path.replaceWith(t.variableDeclaration("let", [ + t.variableDeclarator(node.id, t.toExpression(node)) + ])); + }, + + ClassExpression(path, state) { + let inferred = nameFunction(path); + if (inferred) return inferred; + + let Constructor = VanillaTransformer; + if (state.opts.loose) Constructor = LooseTransformer; + + path.replaceWith(new Constructor(path, state.file).run()); + } } }; } diff --git a/packages/babel-core/src/transformation/helpers/memoise-decorators.js b/packages/babel-plugin-transform-es2015-classes/src/lib/memoise-decorators.js similarity index 100% rename from packages/babel-core/src/transformation/helpers/memoise-decorators.js rename to packages/babel-plugin-transform-es2015-classes/src/lib/memoise-decorators.js diff --git a/packages/babel-core/src/transformation/transformers/es6/classes/loose.js b/packages/babel-plugin-transform-es2015-classes/src/loose.js similarity index 65% rename from packages/babel-core/src/transformation/transformers/es6/classes/loose.js rename to packages/babel-plugin-transform-es2015-classes/src/loose.js index 4af2320e6c..a6989da008 100644 --- a/packages/babel-core/src/transformation/transformers/es6/classes/loose.js +++ b/packages/babel-plugin-transform-es2015-classes/src/loose.js @@ -1,3 +1,4 @@ +import nameFunction from "babel-helper-function-name"; import VanillaTransformer from "./vanilla"; import * as t from "babel-types"; @@ -7,7 +8,7 @@ export default class LooseClassTransformer extends VanillaTransformer { this.isLoose = true; } - _processMethod(node) { + _processMethod(node, scope) { if (!node.decorators) { // use assignments instead of define properties for loose classes @@ -15,7 +16,17 @@ export default class LooseClassTransformer extends VanillaTransformer { if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype")); let methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key)); - let expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value)); + let func = t.functionExpression(null, node.params, node.body); + let key = t.toComputedKey(node, node.key); + if (t.isStringLiteral(key)) { + func = nameFunction({ + node: func, + id: key, + scope + }); + } + + let expr = t.expressionStatement(t.assignmentExpression("=", methodName, func)); t.inheritsComments(expr, node); this.body.push(expr); return true; diff --git a/packages/babel-plugin-transform-es2015-classes/src/vanilla.js b/packages/babel-plugin-transform-es2015-classes/src/vanilla.js new file mode 100644 index 0000000000..749ebd91c1 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-classes/src/vanilla.js @@ -0,0 +1,518 @@ +import type { NodePath } from "babel-traverse"; +import { visitors } from "babel-traverse"; +import ReplaceSupers from "babel-helper-replace-supers"; +import optimiseCall from "babel-helper-optimise-call-expression"; +import * as defineMap from "babel-helper-define-map"; +import template from "babel-template"; +import * as t from "babel-types"; + +let buildDerivedConstructor = template(` + (function () { + super(...arguments); + }) +`); + +let noMethodVisitor = { + "FunctionExpression|FunctionDeclaration"(path) { + if (!path.is("shadow")) { + path.skip(); + } + }, + + Method(path) { + path.skip(); + } +}; + +let verifyConstructorVisitor = visitors.merge([noMethodVisitor, { + Super(path) { + if (this.isDerived && !this.hasBareSuper && !path.parentPath.isCallExpression({ callee: path.node })) { + throw path.buildCodeFrameError("'super.*' is not allowed before super()"); + } + }, + + CallExpression: { + exit(path) { + if (path.get("callee").isSuper()) { + this.hasBareSuper = true; + + if (!this.isDerived) { + throw path.buildCodeFrameError("super() is only allowed in a derived constructor"); + } + } + } + }, + + ThisExpression(path) { + if (this.isDerived && !this.hasBareSuper) { + if (!path.inShadow("this")) { + throw path.buildCodeFrameError("'this' is not allowed before super()"); + } + } + } +}]); + +let findThisesVisitor = visitors.merge([noMethodVisitor, { + ThisExpression(path) { + this.superThises.push(path); + } +}]); + +export default class ClassTransformer { + constructor(path: NodePath, file) { + this.parent = path.parent; + this.scope = path.scope; + this.node = path.node; + this.path = path; + this.file = file; + + this.clearDescriptors(); + + this.instancePropBody = []; + this.instancePropRefs = {}; + this.staticPropBody = []; + this.body = []; + + this.bareSuperAfter = []; + this.bareSupers = []; + + this.pushedConstructor = false; + this.pushedInherits = false; + this.isLoose = false; + + this.superThises = []; + + // class id + this.classId = this.node.id; + + // this is the name of the binding that will **always** reference the class we've constructed + this.classRef = this.node.id || this.scope.generateUidIdentifier("class"); + + this.superName = this.node.superClass || t.identifier("Function"); + this.isDerived = !!this.node.superClass; + } + + run() { + let superName = this.superName; + let file = this.file; + let body = this.body; + + // + + let constructorBody = this.constructorBody = t.blockStatement([]); + this.constructor = this.buildConstructor(); + + // + + let closureParams = []; + let closureArgs = []; + + // + if (this.isDerived) { + closureArgs.push(superName); + + superName = this.scope.generateUidIdentifierBasedOnNode(superName); + closureParams.push(superName); + + this.superName = superName; + } + + // + this.buildBody(); + + // make sure this class isn't directly called + constructorBody.body.unshift(t.expressionStatement(t.callExpression(file.addHelper("classCallCheck"), [ + t.thisExpression(), + this.classRef + ]))); + + body = body.concat(this.staticPropBody.map((fn) => fn(this.classRef))); + + if (this.classId) { + // named class with only a constructor + if (body.length === 1) return t.toExpression(body[0]); + } + + // + body.push(t.returnStatement(this.classRef)); + + let container = t.functionExpression(null, closureParams, t.blockStatement(body)); + container.shadow = true; + return t.callExpression(container, closureArgs); + } + + buildConstructor() { + let func = t.functionDeclaration(this.classRef, [], this.constructorBody); + t.inherits(func, this.node); + return func; + } + + pushToMap(node, enumerable, kind = "value", scope?) { + let mutatorMap; + if (node.static) { + this.hasStaticDescriptors = true; + mutatorMap = this.staticMutatorMap; + } else { + this.hasInstanceDescriptors = true; + mutatorMap = this.instanceMutatorMap; + } + + let map = defineMap.push(mutatorMap, node, kind, this.file, scope); + + if (enumerable) { + map.enumerable = t.booleanLiteral(true); + } + + return map; + } + + /** + * [Please add a description.] + * https://www.youtube.com/watch?v=fWNaR-rxAic + */ + + constructorMeMaybe() { + let hasConstructor = false; + let paths = this.path.get("body.body"); + for (let path of (paths: Array)) { + hasConstructor = path.equals("kind", "constructor"); + if (hasConstructor) break; + } + if (hasConstructor) return; + + let params, body; + + if (this.isDerived) { + let constructor = buildDerivedConstructor().expression; + params = constructor.params; + body = constructor.body; + } else { + params = []; + body = t.blockStatement([]); + } + + this.path.get("body").unshiftContainer("body", t.classMethod( + "constructor", + t.identifier("constructor"), + params, + body + )); + } + + buildBody() { + this.constructorMeMaybe(); + this.pushBody(); + this.verifyConstructor(); + + if (this.userConstructor) { + let constructorBody = this.constructorBody; + constructorBody.body = constructorBody.body.concat(this.userConstructor.body.body); + t.inherits(this.constructor, this.userConstructor); + t.inherits(constructorBody, this.userConstructor.body); + } + + this.pushDescriptors(); + } + + pushBody() { + let classBodyPaths: Array = this.path.get("body.body"); + + for (let path of classBodyPaths) { + let node = path.node; + + if (path.isClassProperty()) { + throw path.buildCodeFrameError("Missing class properties transform."); + } + + if (node.decorators) { + throw path.buildCodeFrameError("Method has decorators, put the decorator plugin before the classes one."); + } + + if (t.isClassMethod(node)) { + let isConstructor = node.kind === "constructor"; + + if (isConstructor) { + path.traverse(verifyConstructorVisitor, this); + + if (!this.hasBareSuper && this.isDerived) { + throw path.buildCodeFrameError("missing super() call in constructor"); + } + } + + let replaceSupers = new ReplaceSupers({ + forceSuperMemoisation: isConstructor, + methodPath: path, + methodNode: node, + objectRef: this.classRef, + superRef: this.superName, + isStatic: node.static, + isLoose: this.isLoose, + scope: this.scope, + file: this.file + }, true); + + replaceSupers.replace(); + + if (isConstructor) { + this.pushConstructor(replaceSupers, node, path); + } else { + this.pushMethod(node, path); + } + } + } + } + + clearDescriptors() { + this.hasInstanceDescriptors = false; + this.hasStaticDescriptors = false; + + this.instanceMutatorMap = {}; + this.staticMutatorMap = {}; + } + + pushDescriptors() { + this.pushInherits(); + + let body = this.body; + + let instanceProps; + let staticProps; + + if (this.hasInstanceDescriptors) { + instanceProps = defineMap.toClassObject(this.instanceMutatorMap); + } + + if (this.hasStaticDescriptors) { + staticProps = defineMap.toClassObject(this.staticMutatorMap); + } + + if (instanceProps || staticProps) { + if (instanceProps) instanceProps = defineMap.toComputedObjectFromClass(instanceProps); + if (staticProps) staticProps = defineMap.toComputedObjectFromClass(staticProps); + + let nullNode = t.nullLiteral(); + + // (Constructor, instanceDescriptors, staticDescriptors, instanceInitializers, staticInitializers) + let args = [this.classRef, nullNode, nullNode, nullNode, nullNode]; + + if (instanceProps) args[1] = instanceProps; + if (staticProps) args[2] = staticProps; + + if (this.instanceInitializersId) { + args[3] = this.instanceInitializersId; + body.unshift(this.buildObjectAssignment(this.instanceInitializersId)); + } + + if (this.staticInitializersId) { + args[4] = this.staticInitializersId; + body.unshift(this.buildObjectAssignment(this.staticInitializersId)); + } + + let lastNonNullIndex = 0; + for (let i = 0; i < args.length; i++) { + if (args[i] !== nullNode) lastNonNullIndex = i; + } + args = args.slice(0, lastNonNullIndex + 1); + + + body.push(t.expressionStatement( + t.callExpression(this.file.addHelper("createClass"), args) + )); + } + + this.clearDescriptors(); + } + + buildObjectAssignment(id) { + return t.variableDeclaration("var", [ + t.variableDeclarator(id, t.objectExpression([])) + ]); + } + + wrapSuperCall(bareSuper, superRef, thisRef, body) { + let bareSuperNode = bareSuper.node; + + if (this.isLoose) { + bareSuperNode.arguments.unshift(t.thisExpression()); + if (bareSuperNode.arguments.length === 2 && t.isSpreadElement(bareSuperNode.arguments[1]) && t.isIdentifier(bareSuperNode.arguments[1].argument, { name: "arguments" })) { + // special case single arguments spread + bareSuperNode.arguments[1] = bareSuperNode.arguments[1].argument; + bareSuperNode.callee = t.memberExpression(superRef, t.identifier("apply")); + } else { + bareSuperNode.callee = t.memberExpression(superRef, t.identifier("call")); + } + } else { + bareSuperNode = optimiseCall( + t.callExpression( + t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), + [this.classRef] + ), + t.thisExpression(), + bareSuperNode.arguments + ); + } + + let call = t.callExpression( + this.file.addHelper("possibleConstructorReturn"), + [t.thisExpression(), bareSuperNode] + ); + + let bareSuperAfter = this.bareSuperAfter.map(fn => fn(thisRef)); + + if (bareSuper.parentPath.isExpressionStatement() && bareSuper.parentPath.container === body.node.body && body.node.body.length - 1 === bareSuper.parentPath.key) { + // this super call is the last statement in the body so we can just straight up + // turn it into a return + + if (this.superThises.length || bareSuperAfter.length) { + bareSuper.scope.push({ id: thisRef }); + call = t.assignmentExpression("=", thisRef, call); + } + + if (bareSuperAfter.length) { + call = t.toSequenceExpression([call, ...bareSuperAfter, thisRef]); + } + + bareSuper.parentPath.replaceWith(t.returnStatement(call)); + } else { + bareSuper.replaceWithMultiple([ + t.variableDeclaration("var", [ + t.variableDeclarator(thisRef, call) + ]), + ...bareSuperAfter, + t.expressionStatement(thisRef) + ]); + } + + } + + verifyConstructor() { + if (!this.isDerived) return; + + let path = this.userConstructorPath; + let body = path.get("body"); + + path.traverse(findThisesVisitor, this); + + let guaranteedSuperBeforeFinish = !!this.bareSupers.length; + + let superRef = this.superName || t.identifier("Function"); + let thisRef = path.scope.generateUidIdentifier("this"); + + for (let bareSuper of this.bareSupers) { + this.wrapSuperCall(bareSuper, superRef, thisRef, body); + + if (guaranteedSuperBeforeFinish) { + bareSuper.find(function (parentPath) { + // hit top so short circuit + if (parentPath === path) { + return true; + } + + if (parentPath.isLoop() || parentPath.isConditional()) { + guaranteedSuperBeforeFinish = false; + return true; + } + }); + } + } + + for (let thisPath of this.superThises) { + thisPath.replaceWith(thisRef); + } + + let wrapReturn = returnArg => t.callExpression( + this.file.addHelper("possibleConstructorReturn"), + [thisRef].concat(returnArg || []) + ); + + // if we have a return as the last node in the body then we've already caught that + // return + let bodyPaths = body.get("body"); + if (bodyPaths.length && !bodyPaths.pop().isReturnStatement()) { + body.pushContainer("body", t.returnStatement(guaranteedSuperBeforeFinish ? thisRef : wrapReturn())); + } + + for (let returnPath of this.superReturns) { + returnPath.get("argument").replaceWith(wrapReturn(returnPath.node.argument)); + } + } + + /** + * Push a method to its respective mutatorMap. + */ + + pushMethod(node: { type: "ClassMethod" }, path?: NodePath) { + let scope = path ? path.scope : this.scope; + + if (node.kind === "method") { + if (this._processMethod(node, scope)) return; + } + + this.pushToMap(node, false, null, scope); + } + + _processMethod() { + return false; + } + + /** + * Replace the constructor body of our class. + */ + + pushConstructor(replaceSupers, method: { type: "ClassMethod" }, path: NodePath) { + this.bareSupers = replaceSupers.bareSupers; + this.superReturns = replaceSupers.returns; + + // https://github.com/babel/babel/issues/1077 + if (path.scope.hasOwnBinding(this.classRef.name)) { + path.scope.rename(this.classRef.name); + } + + let construct = this.constructor; + + this.userConstructorPath = path; + this.userConstructor = method; + this.hasConstructor = true; + + t.inheritsComments(construct, method); + + construct._ignoreUserWhitespace = true; + construct.params = method.params; + + t.inherits(construct.body, method.body); + construct.body.directives = method.body.directives; + + // push constructor to body + this._pushConstructor(); + } + + _pushConstructor() { + if (this.pushedConstructor) return; + this.pushedConstructor = true; + + // we haven't pushed any descriptors yet + if (this.hasInstanceDescriptors || this.hasStaticDescriptors) { + this.pushDescriptors(); + } + + this.body.push(this.constructor); + + this.pushInherits(); + } + + /** + * Push inherits helper to body. + */ + + pushInherits() { + if (!this.isDerived || this.pushedInherits) return; + + // Unshift to ensure that the constructor inheritance is set up before + // any properties can be assigned to the prototype. + this.pushedInherits = true; + this.body.unshift(t.expressionStatement(t.callExpression( + this.file.addHelper("inherits"), + [this.classRef, this.superName] + ))); + } +} diff --git a/packages/babel-plugin-transform-es2015-computed-properties/package.json b/packages/babel-plugin-transform-es2015-computed-properties/package.json index 7525216cca..74910ac0e0 100644 --- a/packages/babel-plugin-transform-es2015-computed-properties/package.json +++ b/packages/babel-plugin-transform-es2015-computed-properties/package.json @@ -1,11 +1,16 @@ { "name": "babel-plugin-transform-es2015-computed-properties", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 computed properties to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-helper-define-map": "5.0.0", + "babel-template": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-computed-properties/src/index.js b/packages/babel-plugin-transform-es2015-computed-properties/src/index.js index c6c33b61f2..90b2fed7bc 100644 --- a/packages/babel-plugin-transform-es2015-computed-properties/src/index.js +++ b/packages/babel-plugin-transform-es2015-computed-properties/src/index.js @@ -1,45 +1,50 @@ export default function ({ types: t }) { - function loose(node, body, objId) { - for (var prop of (node.properties: Array)) { - body.push(t.expressionStatement( - t.assignmentExpression( - "=", - t.memberExpression(objId, prop.key, prop.computed || t.isLiteral(prop.key)), - prop.value - ) - )); + function getValue(prop) { + if (t.isObjectProperty(prop)) { + return prop.value; + } else if (t.isObjectMethod(prop)) { + return t.functionExpression(null, prop.params, prop.body, prop.generator, prop.async); } } - function spec(node, body, objId, initProps, file) { - // add a simple assignment for all Symbol member expressions due to symbol polyfill limitations - // otherwise use Object.defineProperty + function pushAssign(objId, prop, body) { + body.push(t.expressionStatement( + t.assignmentExpression( + "=", + t.memberExpression(objId, prop.key, prop.computed || t.isLiteral(prop.key)), + getValue(prop) + ) + )); + } - for (let prop of (node.properties: Array)) { - // this wont work with Object.defineProperty - if (t.isLiteral(t.toComputedKey(prop), { value: "__proto__" })) { - initProps.push(prop); - continue; - } - - let key = prop.key; - if (t.isIdentifier(key) && !prop.computed) { - key = t.stringLiteral(key.name); - } - - var bodyNode = t.callExpression(file.addHelper("define-property"), [objId, key, prop.value]); - - body.push(t.expressionStatement(bodyNode)); + function loose(objId, body, computedProps: Array) { + for (let prop of computedProps) { + pushAssign(objId, prop, body); } + } - // only one node and it's a Object.defineProperty that returns the object + function spec(objId, body, computedProps: Array, initPropExpression, state) { + for (let prop of computedProps) { + let key = t.toComputedKey(prop); - if (body.length === 1) { - var first = body[0].expression; - - if (t.isCallExpression(first)) { - first.arguments[0] = t.objectExpression(initProps); - return first; + if (t.isStringLiteral(key, { value: "__proto__" })) { + pushAssign(objId, prop, body); + } else { + if (computedProps.length === 1) { + return t.callExpression(state.addHelper("defineProperty"), [ + initPropExpression, + key, + getValue(prop) + ]); + } else { + body.push(t.expressionStatement( + t.callExpression(state.addHelper("defineProperty"), [ + objId, + key, + getValue(prop) + ]) + )); + } } } } @@ -47,51 +52,52 @@ export default function ({ types: t }) { return { visitor: { ObjectExpression: { - exit({ node, scope, parent }, file) { - var hasComputed = false; - - for (let prop of (node.properties: Array)) { - hasComputed = t.isProperty(prop, { computed: true, kind: "init" }); + exit(path, state) { + let { node, parent } = path; + let hasComputed = false; + for (let prop of (node.properties: Array)) { + hasComputed = prop.kind !== "get" && prop.kind !== "set" && prop.computed === true; if (hasComputed) break; } - if (!hasComputed) return; // put all getters/setters into the first object expression as well as all initialisers up // to the first computed property - var initProps = []; - var stopInits = false; + let initProps = []; + let computedProps = []; + let foundComputed = false; - node.properties = node.properties.filter(function (prop) { + for (let prop of node.properties) { if (prop.computed) { - stopInits = true; + foundComputed = true; } - if (prop.kind !== "init" || !stopInits) { - initProps.push(prop); - return false; + if (foundComputed && prop.kind !== "get" && prop.kind !== "set") { + computedProps.push(prop); } else { - return true; + initProps.push(prop); } - }); + } - var objId = scope.generateUidIdentifierBasedOnNode(parent); - var body = []; + let objId = path.scope.generateUidIdentifierBasedOnNode(parent); + let initPropExpression = t.objectExpression(initProps); + let body = []; - 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.variableDeclaration("var", [ + t.variableDeclarator(objId, initPropExpression) ])); - body.push(t.expressionStatement(objId)); + let callback = spec; + if (state.opts.loose) callback = loose; - return body; + let single = callback(objId, body, computedProps, initPropExpression, state); + if (single) { + path.replaceWith(single); + } else { + body.push(t.expressionStatement(objId)); + path.replaceWithMultiple(body); + } } } } diff --git a/packages/babel-plugin-transform-es2015-constants/package.json b/packages/babel-plugin-transform-es2015-constants/package.json index 3f1b5910e5..f4f686cba9 100644 --- a/packages/babel-plugin-transform-es2015-constants/package.json +++ b/packages/babel-plugin-transform-es2015-constants/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es2015-constants", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 constants to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-constants/src/index.js b/packages/babel-plugin-transform-es2015-constants/src/index.js index a6a094ca65..7970a0ad89 100644 --- a/packages/babel-plugin-transform-es2015-constants/src/index.js +++ b/packages/babel-plugin-transform-es2015-constants/src/index.js @@ -1,19 +1,37 @@ -export default function ({ messages }) { +export default function ({ messages, types: t }) { + function check(node) { + if (t.isVariableDeclaration(node, { kind: "const" })) { + node.kind = "let"; + } + } + return { visitor: { Scope({ scope }) { - for (var name in scope.bindings) { - var binding = scope.bindings[name]; + for (let name in scope.bindings) { + let binding = scope.bindings[name]; if (binding.kind !== "const" && binding.kind !== "module") continue; - for (var violation of (binding.constantViolations: Array)) { + for (let violation of (binding.constantViolations: Array)) { throw violation.buildCodeFrameError(messages.get("readOnly", name)); } } }, VariableDeclaration({ node }) { - if (node.kind === "const") node.kind = "let"; + check(node); + }, + + ForXStatement({ node: { left } }) { + check(left); + }, + + ForStatement({ node: { init } }) { + check(init); + }, + + "BlockStatement|Program"({ node: { body } }) { + for (let node of body) check(node); } } }; diff --git a/packages/babel-plugin-transform-es2015-destructuring/package.json b/packages/babel-plugin-transform-es2015-destructuring/package.json index ce18916fa7..ba6cc1d90a 100644 --- a/packages/babel-plugin-transform-es2015-destructuring/package.json +++ b/packages/babel-plugin-transform-es2015-destructuring/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es2015-destructuring", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 destructuring to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-destructuring/src/index.js b/packages/babel-plugin-transform-es2015-destructuring/src/index.js index 895f2b9f39..4d95b06182 100644 --- a/packages/babel-plugin-transform-es2015-destructuring/src/index.js +++ b/packages/babel-plugin-transform-es2015-destructuring/src/index.js @@ -1,11 +1,11 @@ -export default function ({ types: t, messages }) { +export default function ({ types: t }) { /** * Test if a VariableDeclaration's declarations contains any Patterns. */ function variableDeclarationHasPattern(node) { - for (var declar of (node.declarations: Array)) { + for (let declar of (node.declarations: Array)) { if (t.isPattern(declar.id)) { return true; } @@ -18,7 +18,7 @@ export default function ({ types: t, messages }) { */ function hasRest(pattern) { - for (var elem of (pattern.elements: Array)) { + for (let elem of (pattern.elements: Array)) { if (t.isRestElement(elem)) { return true; } @@ -26,7 +26,7 @@ export default function ({ types: t, messages }) { return false; } - var arrayUnpackVisitor = { + let arrayUnpackVisitor = { ReferencedIdentifier(path, state) { if (state.bindings[path.node.name]) { state.deopt = true; @@ -47,10 +47,10 @@ export default function ({ types: t, messages }) { } buildVariableAssignment(id, init) { - var op = this.operator; + let op = this.operator; if (t.isMemberExpression(id)) op = "="; - var node; + let node; if (op) { node = t.expressionStatement(t.assignmentExpression(op, id, init)); @@ -66,7 +66,7 @@ export default function ({ types: t, messages }) { } buildVariableDeclaration(id, init) { - var declar = t.variableDeclaration("var", [ + let declar = t.variableDeclaration("var", [ t.variableDeclarator(id, init) ]); declar._blockHoist = this.blockHoist; @@ -97,9 +97,9 @@ export default function ({ types: t, messages }) { // we need to assign the current value of the assignment to avoid evaluating // it more than once - var tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef); + let tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef); - var declar = t.variableDeclaration("var", [ + let declar = t.variableDeclaration("var", [ t.variableDeclarator(tempValueRef, valueRef) ]); declar._blockHoist = this.blockHoist; @@ -107,15 +107,15 @@ export default function ({ types: t, messages }) { // - var tempConditional = t.conditionalExpression( + let tempConditional = t.conditionalExpression( t.binaryExpression("===", tempValueRef, t.identifier("undefined")), pattern.right, tempValueRef ); - var left = pattern.left; + let left = pattern.left; if (t.isPattern(left)) { - var tempValueDefault = t.expressionStatement( + let tempValueDefault = t.expressionStatement( t.assignmentExpression("=", tempValueRef, tempConditional) ); tempValueDefault._blockHoist = this.blockHoist; @@ -130,10 +130,10 @@ export default function ({ types: t, messages }) { pushObjectRest(pattern, objRef, spreadProp, spreadPropIndex) { // get all the keys that appear in this object before the current spread - var keys = []; + let keys = []; - for (var i = 0; i < pattern.properties.length; i++) { - var prop = pattern.properties[i]; + for (let i = 0; i < pattern.properties.length; i++) { + let prop = pattern.properties[i]; // we've exceeded the index of the spread property to all properties to the // right need to be ignored @@ -142,7 +142,7 @@ export default function ({ types: t, messages }) { // ignore other spread properties if (t.isRestProperty(prop)) continue; - var key = prop.key; + let key = prop.key; if (t.isIdentifier(key) && !prop.computed) key = t.stringLiteral(prop.key.name); keys.push(key); } @@ -151,15 +151,15 @@ export default function ({ types: t, messages }) { // - var value = t.callExpression(this.file.addHelper("object-without-properties"), [objRef, keys]); + let value = t.callExpression(this.file.addHelper("objectWithoutProperties"), [objRef, keys]); this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value)); } pushObjectProperty(prop, propRef) { if (t.isLiteral(prop.key)) prop.computed = true; - var pattern = prop.value; - var objRef = t.memberExpression(propRef, prop.key, prop.computed); + let pattern = prop.value; + let objRef = t.memberExpression(propRef, prop.key, prop.computed); if (t.isPattern(pattern)) { this.push(pattern, objRef); @@ -173,7 +173,7 @@ export default function ({ types: t, messages }) { if (!pattern.properties.length) { this.nodes.push(t.expressionStatement( - t.callExpression(this.file.addHelper("object-destructuring-empty"), [objRef]) + t.callExpression(this.file.addHelper("objectDestructuringEmpty"), [objRef]) )); } @@ -182,15 +182,15 @@ export default function ({ types: t, messages }) { // only evaluated once if (pattern.properties.length > 1 && !this.scope.isStatic(objRef)) { - var temp = this.scope.generateUidIdentifierBasedOnNode(objRef); + let temp = this.scope.generateUidIdentifierBasedOnNode(objRef); this.nodes.push(this.buildVariableDeclaration(temp, objRef)); objRef = temp; } // - for (var i = 0; i < pattern.properties.length; i++) { - var prop = pattern.properties[i]; + for (let i = 0; i < pattern.properties.length; i++) { + let prop = pattern.properties[i]; if (t.isRestProperty(prop)) { this.pushObjectRest(pattern, objRef, prop, i); } else { @@ -222,15 +222,15 @@ export default function ({ types: t, messages }) { } // deopt on reference to left side identifiers - var bindings = t.getBindingIdentifiers(pattern); - var state = { deopt: false, bindings }; + let bindings = t.getBindingIdentifiers(pattern); + let state = { deopt: false, bindings }; this.scope.traverse(arr, arrayUnpackVisitor, state); return !state.deopt; } pushUnpackedArrayPattern(pattern, arr) { - for (var i = 0; i < pattern.elements.length; i++) { - var elem = pattern.elements[i]; + for (let i = 0; i < pattern.elements.length; i++) { + let elem = pattern.elements[i]; if (t.isRestElement(elem)) { this.push(elem.argument, t.arrayExpression(arr.elements.slice(i))); } else { @@ -247,7 +247,7 @@ export default function ({ types: t, messages }) { // we can't do this to a pattern of unequal size to it's right hand // array expression as then there will be values that wont be evaluated // - // eg: var [a, b] = [1, 2]; + // eg: let [a, b] = [1, 2]; if (this.canUnpackArrayPattern(pattern, arrayRef)) { return this.pushUnpackedArrayPattern(pattern, arrayRef); @@ -256,13 +256,13 @@ export default function ({ types: t, messages }) { // if we have a rest then we need all the elements so don't tell // `scope.toArray` to only get a certain amount - var count = !hasRest(pattern) && pattern.elements.length; + let count = !hasRest(pattern) && pattern.elements.length; // so we need to ensure that the `arrayRef` is an array, `scope.toArray` will // return a locally bound identifier if it's been inferred to be an array, // otherwise it'll be a call to a helper that will ensure it's one - var toArray = this.toArray(arrayRef, count); + let toArray = this.toArray(arrayRef, count); if (t.isIdentifier(toArray)) { // we've been given an identifier so it must have been inferred to be an @@ -276,13 +276,13 @@ export default function ({ types: t, messages }) { // - for (var i = 0; i < pattern.elements.length; i++) { - var elem = pattern.elements[i]; + for (let i = 0; i < pattern.elements.length; i++) { + let elem = pattern.elements[i]; // hole if (!elem) continue; - var elemRef; + let elemRef; if (t.isRestElement(elem)) { elemRef = this.toArray(arrayRef); @@ -307,7 +307,7 @@ export default function ({ types: t, messages }) { // need to save it to a variable if (!t.isArrayExpression(ref) && !t.isMemberExpression(ref)) { - var memo = this.scope.maybeGenerateMemoised(ref, true); + let memo = this.scope.maybeGenerateMemoised(ref, true); if (memo) { this.nodes.push(this.buildVariableDeclaration(memo, ref)); ref = memo; @@ -326,13 +326,13 @@ export default function ({ types: t, messages }) { return { visitor: { ForXStatement(path, file) { - var { node, scope } = path; - var left = node.left; + let { node, scope } = path; + let left = node.left; if (t.isPattern(left)) { // for ({ length: k } in { abc: 3 }); - var temp = scope.generateUidIdentifier("ref"); + let temp = scope.generateUidIdentifier("ref"); node.left = t.variableDeclaration("var", [ t.variableDeclarator(temp) @@ -349,17 +349,17 @@ export default function ({ types: t, messages }) { if (!t.isVariableDeclaration(left)) return; - var pattern = left.declarations[0].id; + let pattern = left.declarations[0].id; if (!t.isPattern(pattern)) return; - var key = scope.generateUidIdentifier("ref"); + let key = scope.generateUidIdentifier("ref"); node.left = t.variableDeclaration(left.kind, [ t.variableDeclarator(key, null) ]); - var nodes = []; + let nodes = []; - var destructuring = new DestructuringTransformer({ + let destructuring = new DestructuringTransformer({ kind: left.kind, file: file, scope: scope, @@ -370,20 +370,20 @@ export default function ({ types: t, messages }) { path.ensureBlock(); - var block = node.body; + let block = node.body; block.body = nodes.concat(block.body); }, CatchClause({ node, scope }, file) { - var pattern = node.param; + let pattern = node.param; if (!t.isPattern(pattern)) return; - var ref = scope.generateUidIdentifier("ref"); + let ref = scope.generateUidIdentifier("ref"); node.param = ref; - var nodes = []; + let nodes = []; - var destructuring = new DestructuringTransformer({ + let destructuring = new DestructuringTransformer({ kind: "let", file: file, scope: scope, @@ -395,19 +395,19 @@ export default function ({ types: t, messages }) { }, AssignmentExpression(path, file) { - var { node, scope } = path; + let { node, scope } = path; if (!t.isPattern(node.left)) return; - var nodes = []; + let nodes = []; - var destructuring = new DestructuringTransformer({ + let destructuring = new DestructuringTransformer({ operator: node.operator, file: file, scope: scope, nodes: nodes }); - var ref; + let ref; if (path.isCompletionRecord() || !path.parentPath.isExpressionStatement()) { ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref"); @@ -426,27 +426,30 @@ export default function ({ types: t, messages }) { nodes.push(t.expressionStatement(ref)); } - return nodes; + path.replaceWithMultiple(nodes); }, - VariableDeclaration({ node, scope, parent }, file) { + VariableDeclaration(path, file) { + let { node, scope, parent } = path; if (t.isForXStatement(parent)) return; + if (!parent || !path.container) return; // i don't know why this is necessary - TODO if (!variableDeclarationHasPattern(node)) return; - var nodes = []; - var declar; + let nodes = []; + let declar; - for (var i = 0; i < node.declarations.length; i++) { + for (let i = 0; i < node.declarations.length; i++) { declar = node.declarations[i]; - var patternId = declar.init; - var pattern = declar.id; + let patternId = declar.init; + let pattern = declar.id; - var destructuring = new DestructuringTransformer({ - nodes: nodes, - scope: scope, - kind: node.kind, - file: file + let destructuring = new DestructuringTransformer({ + blockHoist: node._blockHoist, + nodes: nodes, + scope: scope, + kind: node.kind, + file: file }); if (t.isPattern(pattern)) { @@ -462,27 +465,7 @@ export default function ({ types: t, messages }) { } } - if (!t.isProgram(parent) && !t.isBlockStatement(parent)) { - // https://github.com/babel/babel/issues/113 - // for (let [x] = [0]; false;) {} - - declar = null; - - for (i = 0; i < nodes.length; i++) { - node = nodes[i]; - declar = declar || t.variableDeclaration(node.kind, []); - - if (!t.isVariableDeclaration(node) && declar.kind !== node.kind) { - throw file.buildCodeFrameError(node, messages.get("invalidParentForThisNode")); - } - - declar.declarations = declar.declarations.concat(node.declarations); - } - - return declar; - } - - return nodes; + path.replaceWithMultiple(nodes); } } }; diff --git a/packages/babel-plugin-transform-es2015-for-of/package.json b/packages/babel-plugin-transform-es2015-for-of/package.json index 2940ab9616..cc64f6144a 100644 --- a/packages/babel-plugin-transform-es2015-for-of/package.json +++ b/packages/babel-plugin-transform-es2015-for-of/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es2015-for-of", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 for...of to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-for-of/src/index.js b/packages/babel-plugin-transform-es2015-for-of/src/index.js index 85f2b73c65..a56efe707a 100644 --- a/packages/babel-plugin-transform-es2015-for-of/src/index.js +++ b/packages/babel-plugin-transform-es2015-for-of/src/index.js @@ -1,9 +1,9 @@ export default function ({ messages, template, types: t }) { - var buildForOfArray = template(` + let buildForOfArray = template(` for (var KEY = 0; KEY < ARR.length; KEY++) BODY; `); - var buildForOfLoose = template(` + let buildForOfLoose = template(` for (var LOOP_OBJECT = OBJECT, IS_ARRAY = Array.isArray(LOOP_OBJECT), INDEX = 0, @@ -20,7 +20,7 @@ export default function ({ messages, template, types: t }) { } `); - var buildForOf = template(` + let buildForOf = template(` var ITERATOR_COMPLETION = true; var ITERATOR_HAD_ERROR_KEY = false; var ITERATOR_ERROR_KEY = undefined; @@ -44,21 +44,21 @@ export default function ({ messages, template, types: t }) { `); function _ForOfStatementArray(path) { - var { node, scope } = path; - var nodes = []; - var right = node.right; + let { node, scope } = path; + let nodes = []; + let right = node.right; if (!t.isIdentifier(right) || !scope.hasBinding(right.name)) { - var uid = scope.generateUidIdentifier("arr"); + let uid = scope.generateUidIdentifier("arr"); nodes.push(t.variableDeclaration("var", [ t.variableDeclarator(uid, right) ])); right = uid; } - var iterationKey = scope.generateUidIdentifier("i"); + let iterationKey = scope.generateUidIdentifier("i"); - var loop = buildForOfArray({ + let loop = buildForOfArray({ BODY: node.body, KEY: iterationKey, ARR: right @@ -67,9 +67,9 @@ export default function ({ messages, template, types: t }) { t.inherits(loop, node); t.ensureBlock(loop); - var iterationValue = t.memberExpression(right, iterationKey, true); + let iterationValue = t.memberExpression(right, iterationKey, true); - var left = node.left; + let left = node.left; if (t.isVariableDeclaration(left)) { left.declarations[0].init = iterationValue; loop.body.body.unshift(left); @@ -91,17 +91,17 @@ export default function ({ messages, template, types: t }) { visitor: { ForOfStatement(path, state) { if (path.get("right").isArrayExpression()) { - return _ForOfStatementArray.call(this, path, state); + return path.replaceWithMultiple(_ForOfStatementArray.call(this, path, state)); } - var callback = spec; + let callback = spec; if (state.opts.loose) callback = loose; - var { node } = path; - var build = callback(path, state); - var declar = build.declar; - var loop = build.loop; - var block = loop.body; + let { node } = path; + let build = callback(path, state); + let declar = build.declar; + let loop = build.loop; + let block = loop.body; // ensure that it's a block so we can take all its statements path.ensureBlock(); @@ -128,16 +128,16 @@ export default function ({ messages, template, types: t }) { }; function loose(path, file) { - var { node, scope } = path; + let { node, scope } = path; - var left = node.left; - var declar, id; + let left = node.left; + let declar, id; if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { // for (i of test), for ({ i } of test) id = left; } else if (t.isVariableDeclaration(left)) { - // for (var i of test) + // for (let i of test) id = scope.generateUidIdentifier("ref"); declar = t.variableDeclaration(left.kind, [ t.variableDeclarator(left.declarations[0].id, id) @@ -146,10 +146,10 @@ export default function ({ messages, template, types: t }) { throw file.buildCodeFrameError(left, messages.get("unknownForHead", left.type)); } - var iteratorKey = scope.generateUidIdentifier("iterator"); - var isArrayKey = scope.generateUidIdentifier("isArray"); + let iteratorKey = scope.generateUidIdentifier("iterator"); + let isArrayKey = scope.generateUidIdentifier("isArray"); - var loop = buildForOfLoose({ + let loop = buildForOfLoose({ LOOP_OBJECT: iteratorKey, IS_ARRAY: isArrayKey, OBJECT: node.right, @@ -173,18 +173,18 @@ export default function ({ messages, template, types: t }) { } function spec(path, file) { - var { node, scope, parent } = path; - var left = node.left; - var declar; + let { node, scope, parent } = path; + let left = node.left; + let declar; - var stepKey = scope.generateUidIdentifier("step"); - var stepValue = t.memberExpression(stepKey, t.identifier("value")); + let stepKey = scope.generateUidIdentifier("step"); + let stepValue = t.memberExpression(stepKey, t.identifier("value")); if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { // for (i of test), for ({ i } of test) declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue)); } else if (t.isVariableDeclaration(left)) { - // for (var i of test) + // for (let i of test) declar = t.variableDeclaration(left.kind, [ t.variableDeclarator(left.declarations[0].id, stepValue) ]); @@ -194,9 +194,9 @@ export default function ({ messages, template, types: t }) { // - var iteratorKey = scope.generateUidIdentifier("iterator"); + let iteratorKey = scope.generateUidIdentifier("iterator"); - var template = buildForOf({ + let template = buildForOf({ ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"), ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"), ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"), @@ -206,10 +206,10 @@ export default function ({ messages, template, types: t }) { BODY: null }); - var isLabeledParent = t.isLabeledStatement(parent); + let isLabeledParent = t.isLabeledStatement(parent); - var tryBody = template[3].block.body; - var loop = tryBody[0]; + let tryBody = template[3].block.body; + let loop = tryBody[0]; if (isLabeledParent) { tryBody[0] = t.labeledStatement(parent.label, loop); diff --git a/packages/babel-plugin-transform-es2015-function-name/package.json b/packages/babel-plugin-transform-es2015-function-name/package.json index f1c6273b60..d57f296d3f 100644 --- a/packages/babel-plugin-transform-es2015-function-name/package.json +++ b/packages/babel-plugin-transform-es2015-function-name/package.json @@ -1,11 +1,16 @@ { "name": "babel-plugin-transform-es2015-function-name", - "version": "1.0.0", + "version": "5.10.32", "description": "Apply ES2015 function.name semantics to all functions", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-helper-function-name": "^5.0.0", + "babel-types": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-function-name/src/index.js b/packages/babel-plugin-transform-es2015-function-name/src/index.js index 6845446a11..fb45f0d9eb 100644 --- a/packages/babel-plugin-transform-es2015-function-name/src/index.js +++ b/packages/babel-plugin-transform-es2015-function-name/src/index.js @@ -1,7 +1,39 @@ +import * as t from "babel-types"; +import nameFunction from "babel-helper-function-name"; + export default function () { return { visitor: { - // your visitor methods go here + "ArrowFunctionExpression|FunctionExpression": { + exit(path) { + if (path.key !== "value" && !path.parentPath.isObjectProperty()) { + let replacement = nameFunction(path); + if (replacement) path.replaceWith(replacement); + } + } + }, + + ObjectExpression(path) { + let props: Array = path.get("properties"); + + for (let prop of props) { + if (prop.isObjectMethod({ kind: "method", computed: false })) { + let node = prop.node; + prop.replaceWith(t.objectProperty( + node.key, + t.functionExpression(null, node.params, node.body, node.generator, node.async) + )); + } + + if (prop.isObjectProperty()) { + let value = prop.get("value"); + if (value.isFunction()) { + let newNode = nameFunction(value); + if (newNode) value.replaceWith(newNode); + } + } + } + } } }; } diff --git a/packages/babel-plugin-transform-es2015-literals/package.json b/packages/babel-plugin-transform-es2015-literals/package.json index dcbe537ea0..b5be526bc0 100644 --- a/packages/babel-plugin-transform-es2015-literals/package.json +++ b/packages/babel-plugin-transform-es2015-literals/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es2015-literals", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 unicode string and number literals to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-literals/src/index.js b/packages/babel-plugin-transform-es2015-literals/src/index.js index 4904fe01ff..371dd7d7cd 100644 --- a/packages/babel-plugin-transform-es2015-literals/src/index.js +++ b/packages/babel-plugin-transform-es2015-literals/src/index.js @@ -3,15 +3,15 @@ export default function () { visitor: { NumberLiteral(node) { // number octal like 0b10 or 0o70 - if (/^0[ob]/i.test(node.raw)) { - node.raw = undefined; + if (node.extra && /^0[ob]/i.test(node.extra.raw)) { + node.extra = undefined; } }, StringLiteral(node) { // unicode escape - if (/\\[u]/gi.test(node.raw)) { - node.raw = undefined; + if (node.extra && /\\[u]/gi.test(node.extra.raw)) { + node.extra = undefined; } } } diff --git a/packages/babel-plugin-transform-es2015-modules-amd/README.md b/packages/babel-plugin-transform-es2015-modules-amd/README.md new file mode 100644 index 0000000000..beb7cfc104 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/README.md @@ -0,0 +1,33 @@ +# babel-plugin-transform-es2015-modules-amd + +## Installation + +```sh +$ npm install babel-plugin-transform-es2015-modules-amd +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-es2015-modules-amd"] +} +``` + +### Via CLI + +```sh +$ babel --plugins transform-es2015-modules-amd script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-es2015-modules-amd"] +}); +``` diff --git a/packages/babel-plugin-transform-es2015-modules-amd/package.json b/packages/babel-plugin-transform-es2015-modules-amd/package.json new file mode 100644 index 0000000000..5854d5ac91 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/package.json @@ -0,0 +1,16 @@ +{ + "name": "babel-plugin-transform-es2015-modules-amd", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-plugin-transform-es2015-modules-commonjs": "^5.0.0", + "babel-template": "^5.0.0", + "babel-runtime": "^5.8.20" + }, + "keywords": [ + "babel-plugin" + ] +} diff --git a/packages/babel-plugin-transform-es2015-modules-amd/src/index.js b/packages/babel-plugin-transform-es2015-modules-amd/src/index.js new file mode 100644 index 0000000000..ba9020a638 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-amd/src/index.js @@ -0,0 +1,109 @@ +import template from "babel-template"; + +let buildDefine = template(` + define(MODULE_NAME, [SOURCES], function (PARAMS) { + BODY; + }); +`); + +export default function ({ types: t }) { + function isValidRequireCall(path) { + if (!path.isCallExpression()) return false; + if (!path.get("callee").isIdentifier({ name: "require" })) return false; + if (path.scope.getBinding("require")) return false; + + let args = path.get("arguments"); + if (args.length !== 1) return false; + + let arg = args[0]; + if (!arg.isStringLiteral()) return false; + + return true; + } + + let amdVisitor = { + ReferencedIdentifier({ node, scope }) { + if (node.name === "exports" && !scope.getBinding("exports")) { + this.hasExports = true; + } + + if (node.name === "module" && !scope.getBinding("module")) { + this.hasModule = true; + } + }, + + CallExpression(path) { + if (!isValidRequireCall(path)) return; + this.bareSources.push(path.node.arguments[0]); + path.remove(); + }, + + VariableDeclarator(path) { + let id = path.get("id"); + if (!id.isIdentifier()) return; + + let init = path.get("init"); + if (!isValidRequireCall(init)) return; + + let source = init.node.arguments[0]; + this.sourceNames[source.value] = true; + this.sources.push([id.node, source]); + + path.remove(); + } + }; + + return { + inherits: require("babel-plugin-transform-es2015-modules-commonjs"), + + pre() { + // source strings + this.sources = []; + this.sourceNames = Object.create(null); + + // bare sources + this.bareSources = []; + + this.hasExports = false; + this.hasModule = false; + }, + + visitor: { + Program: { + exit(path) { + if (this.ran) return; + this.ran = true; + + path.traverse(amdVisitor, this); + + let params = this.sources.map(source => source[0]); + let sources = this.sources.map(source => source[1]); + + sources = sources.concat(this.bareSources.filter((str) => { + return !this.sourceNames[str.value]; + })); + + let moduleName = this.getModuleName(); + if (moduleName) moduleName = t.stringLiteral(moduleName); + + if (this.hasExports) { + sources.unshift(t.stringLiteral("exports")); + params.unshift(t.identifier("exports")); + } + + if (this.hasModule) { + sources.unshift(t.stringLiteral("module")); + params.unshift(t.identifier("module")); + } + + path.node.body = [buildDefine({ + MODULE_NAME: moduleName, + SOURCES: sources, + PARAMS: params, + BODY: path.node.body + })]; + } + } + } + }; +} diff --git a/packages/babel-plugin-transform-dead-code-elimination/.npmignore b/packages/babel-plugin-transform-es2015-modules-commonjs/.npmignore similarity index 100% rename from packages/babel-plugin-transform-dead-code-elimination/.npmignore rename to packages/babel-plugin-transform-es2015-modules-commonjs/.npmignore diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/README.md b/packages/babel-plugin-transform-es2015-modules-commonjs/README.md new file mode 100644 index 0000000000..3ad1e4c355 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/README.md @@ -0,0 +1,33 @@ +# babel-plugin-transform-es2015-modules-commonjs + +## Installation + +```sh +$ npm install babel-plugin-transform-es2015-modules-commonjs +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-es2015-modules-commonjs"] +} +``` + +### Via CLI + +```sh +$ babel --plugins transform-es2015-modules-commonjs script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-es2015-modules-commonjs"] +}); +``` diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/package.json b/packages/babel-plugin-transform-es2015-modules-commonjs/package.json new file mode 100644 index 0000000000..0e307a4aeb --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/package.json @@ -0,0 +1,17 @@ +{ + "name": "babel-plugin-transform-es2015-modules-commonjs", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-types": "^5.0.0", + "babel-runtime": "^5.0.0", + "babel-template": "^5.0.0", + "babel-runtime": "^5.8.20" + }, + "keywords": [ + "babel-plugin" + ] +} diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js new file mode 100644 index 0000000000..6661edecc9 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js @@ -0,0 +1,358 @@ +import { basename, extname } from "path"; +import template from "babel-template"; +import * as t from "babel-types"; + +let buildRequire = template(` + require($0); +`); + +let buildExportsModuleDeclaration = template(` + Object.defineProperty(exports, "__esModule", { + value: true + }); +`); + +let buildExportsFrom = template(` + Object.defineProperty(exports, $0, { + enumerable: true, + get: function () { + return $1; + } + }); +`); + +let buildLooseExportsModuleDeclaration = template(` + exports.__esModule = true; +`); + +let buildExportsAssignment = template(` + exports.$0 = $1; +`); + +let buildExportAll = template(` + for (let KEY in OBJECT) { + if (KEY === "default") continue; + + Object.defineProperty(exports, KEY, { + enumerable: true, + get: function () { + return OBJECT[KEY]; + } + }); + } +`); + +const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassProperty", "ClassMethod", "ObjectMethod"]; + +export default function () { + let REASSIGN_REMAP_SKIP = Symbol(); + + let reassignmentVisitor = { + ReferencedIdentifier(path) { + let name = path.node.name; + let remap = this.remaps[name]; + if (!remap) return; + + // redeclared in this scope + if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return; + + if (path.parentPath.isCallExpression({ callee: path.node })) { + path.replaceWith(t.sequenceExpression([t.numberLiteral(0), remap])); + } else { + path.replaceWith(remap); + } + }, + + AssignmentExpression(path) { + let node = path.node; + if (node[REASSIGN_REMAP_SKIP]) return; + + let left = path.get("left"); + if (!left.isIdentifier()) return; + + let name = left.node.name; + let exports = this.exports[name]; + if (!exports) return; + + // redeclared in this scope + if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return; + + node[REASSIGN_REMAP_SKIP] = true; + + for (let reid of exports) { + node = buildExportsAssignment(reid, node).expression; + } + path.replaceWith(node); + }, + + UpdateExpression(path) { + let arg = path.get("argument"); + if (!arg.isIdentifier()) return; + + let name = arg.node.name; + let exports = this.exports[name]; + if (!exports) return; + + // redeclared in this scope + if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return; + + let node = t.assignmentExpression(path.node.operator[0] + "=", arg.node, t.numberLiteral(1)); + + if ((path.parentPath.isExpressionStatement() && !path.isCompletionRecord()) || path.node.prefix) { + return path.replaceWith(node); + } + + let nodes = []; + nodes.push(node); + + let operator; + if (path.node.operator === "--") { + operator = "+"; + } else { // "++" + operator = "-"; + } + nodes.push(t.binaryExpression(operator, arg.node, t.numberLiteral(1))); + + path.replaceWithMultiple(t.sequenceExpression(nodes)); + } + }; + + return { + visitor: { + ThisExpression(path) { + if (!path.findParent((path) => !path.is("shadow") && THIS_BREAK_KEYS.indexOf(path.type) >= 0)) { + path.replaceWith(t.identifier("undefined")); + } + }, + + Program: { + exit(path) { + let strict = !!this.opts.strict; + + let { scope } = path; + + // rename these commonjs variables if they're declared in the file + scope.rename("module"); + scope.rename("exports"); + scope.rename("require"); + + let hasExports = false; + let hasImports = false; + + let body: Array = path.get("body"); + let imports = Object.create(null); + let exports = Object.create(null); + + let nonHoistedExportNames = Object.create(null); + + let topNodes = []; + let remaps = Object.create(null); + + let requires = Object.create(null); + + function addRequire(source) { + let cached = requires[source]; + if (cached) return cached; + + let ref = path.scope.generateUidIdentifier(basename(source, extname(source))); + + topNodes.push(t.variableDeclaration("var", [ + t.variableDeclarator(ref, buildRequire(t.stringLiteral(source)).expression) + ])); + + return requires[source] = ref; + } + + function addTo(obj, key, arr) { + let existing = obj[key] || []; + obj[key] = existing.concat(arr); + } + + for (let path of body) { + if (path.isExportDeclaration()) { + hasExports = true; + + let specifiers = [].concat(path.get("declaration"), path.get("specifiers")); + for (let specifier of specifiers) { + let ids = specifier.getBindingIdentifiers(); + if (ids.__esModule) { + throw specifier.buildCodeFrameError(`Illegal export "__esModule"`); + } + } + } + + if (path.isImportDeclaration()) { + hasImports = true; + addTo(imports, path.node.source.value, path.node.specifiers); + path.remove(); + } else if (path.isExportDefaultDeclaration()) { + let declaration = path.get("declaration"); + if (declaration.isFunctionDeclaration()) { + let id = declaration.node.id; + let defNode = t.identifier("default"); + if (id) { + addTo(exports, id.name, defNode); + topNodes.push(buildExportsAssignment(defNode, id)); + path.replaceWith(declaration.node); + } else { + topNodes.push(buildExportsAssignment(defNode, t.toExpression(declaration.node))); + path.remove(); + } + } else if (declaration.isClassDeclaration()) { + let id = declaration.node.id; + let defNode = t.identifier("default"); + if (id) { + addTo(exports, id.name, defNode); + path.replaceWithMultiple([ + declaration.node, + buildExportsAssignment(defNode, id) + ]); + } else { + path.replaceWith(buildExportsAssignment(defNode, t.toExpression(declaration.node))); + } + } else { + path.replaceWith(buildExportsAssignment(t.identifier("default"), declaration.node)); + } + } else if (path.isExportNamedDeclaration()) { + let declaration = path.get("declaration"); + if (declaration.node) { + if (declaration.isFunctionDeclaration()) { + let id = declaration.node.id; + addTo(exports, id.name, id); + topNodes.push(buildExportsAssignment(id, id)); + path.replaceWith(declaration.node); + } else if (declaration.isClassDeclaration()) { + let id = declaration.node.id; + addTo(exports, id.name, id); + path.replaceWithMultiple([ + declaration.node, + buildExportsAssignment(id, id) + ]); + nonHoistedExportNames[id.name] = true; + } else if (declaration.isVariableDeclaration()) { + let declarators = declaration.get("declarations"); + for (let decl of declarators) { + let id = decl.get("id"); + + let init = decl.get("init"); + if (!init.node) init.replaceWith(t.identifier("undefined")); + + if (id.isIdentifier()) { + addTo(exports, id.node.name, id.node); + init.replaceWith(buildExportsAssignment(id.node, init.node).expression); + nonHoistedExportNames[id.node.name] = true; + } else { + // todo + } + } + path.replaceWith(declaration.node); + } + continue; + } + + let specifiers = path.get("specifiers"); + if (specifiers.length) { + let nodes = []; + let source = path.node.source + if (source) { + let ref = addRequire(source.value); + + for (let specifier of specifiers) { + if (specifier.isExportNamespaceSpecifier()) { + // todo + } else if (specifier.isExportDefaultSpecifier()) { + // todo + } else if (specifier.isExportSpecifier()) { + topNodes.push(buildExportsFrom(t.stringLiteral(specifier.node.exported.name), t.memberExpression(ref, specifier.node.local))); + nonHoistedExportNames[specifier.node.exported.name] = true; + } + } + } else { + for (let specifier of specifiers) { + if (specifier.isExportSpecifier()) { + addTo(exports, specifier.node.local.name, specifier.node.exported); + nonHoistedExportNames[specifier.node.exported.name] = true; + nodes.push(buildExportsAssignment(specifier.node.exported, specifier.node.local)); + } + } + } + path.replaceWithMultiple(nodes); + } + } else if (path.isExportAllDeclaration()) { + topNodes.push(buildExportAll({ + KEY: path.scope.generateUidIdentifier("key"), + OBJECT: addRequire(path.node.source.value) + })); + path.remove(); + } + } + + for (let source in imports) { + let specifiers = imports[source]; + if (specifiers.length) { + let uid = addRequire(source); + + let wildcard; + + for (let i = 0; i < specifiers.length; i++) { + let specifier = specifiers[i]; + if (t.isImportNamespaceSpecifier(specifier)) { + if (strict) { + remaps[specifier.local.name] = uid; + } else { + topNodes.push(t.variableDeclaration("var", [ + t.variableDeclarator(specifier.local, t.callExpression(this.addHelper("interopRequireWildcard"), [uid])) + ])); + } + wildcard = specifier.local; + } else if (t.isImportDefaultSpecifier(specifier)) { + specifiers[i] = t.importSpecifier(specifier.local, t.identifier("default")); + } + } + + for (let specifier of specifiers) { + if (t.isImportSpecifier(specifier)) { + let target = uid; + if (specifier.imported.name === "default") { + if (wildcard) { + target = wildcard; + } else { + target = wildcard = path.scope.generateUidIdentifier(uid.name); + topNodes.push(t.variableDeclaration("var", [ + t.variableDeclarator(target, t.callExpression(this.addHelper("interopRequireDefault"), [uid])) + ])); + } + } + remaps[specifier.local.name] = t.memberExpression(target, specifier.imported); + } + } + } else { + // bare import + topNodes.push(buildRequire(t.stringLiteral(source))); + } + } + + if (hasImports && Object.keys(nonHoistedExportNames).length) { + let hoistedExportsNode = t.identifier("undefined"); + + for (let name in nonHoistedExportNames) { + hoistedExportsNode = buildExportsAssignment(t.identifier(name), hoistedExportsNode).expression; + } + + topNodes.unshift(t.expressionStatement(hoistedExportsNode)); + } + + // add __esModule declaration if this file has any exports + if (hasExports && !strict) { + let buildTemplate = buildExportsModuleDeclaration; + if (this.opts.loose) buildTemplate = buildLooseExportsModuleDeclaration; + topNodes.unshift(buildTemplate()); + } + + path.unshiftContainer("body", topNodes); + path.traverse(reassignmentVisitor, { remaps, scope, exports }); + } + } + } + }; +} diff --git a/packages/babel-plugin-transform-es2015-modules-systemjs/README.md b/packages/babel-plugin-transform-es2015-modules-systemjs/README.md new file mode 100644 index 0000000000..dfe554de32 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-systemjs/README.md @@ -0,0 +1,33 @@ +# babel-plugin-transform-es2015-modules-systemjs + +## Installation + +```sh +$ npm install babel-plugin-transform-es2015-modules-systemjs +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-es2015-modules-systemjs"] +} +``` + +### Via CLI + +```sh +$ babel --plugins transform-es2015-modules-systemjs script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-es2015-modules-systemjs"] +}); +``` diff --git a/packages/babel-plugin-transform-es2015-modules-systemjs/package.json b/packages/babel-plugin-transform-es2015-modules-systemjs/package.json new file mode 100644 index 0000000000..0190ee1989 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-systemjs/package.json @@ -0,0 +1,16 @@ +{ + "name": "babel-plugin-transform-es2015-modules-systemjs", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-template": "^5.0.0", + "babel-helper-hoist-variables": "^5.0.0", + "babel-runtime": "^5.8.20" + }, + "keywords": [ + "babel-plugin" + ] +} diff --git a/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js new file mode 100644 index 0000000000..8d312af8f0 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-systemjs/src/index.js @@ -0,0 +1,243 @@ +import hoistVariables from "babel-helper-hoist-variables"; +import template from "babel-template"; + +let buildTemplate = template(` + System.register(MODULE_NAME, [SOURCES], function (EXPORT_IDENTIFIER) { + BEFORE_BODY; + return { + setters: [SETTERS], + execute: function () { + BODY; + } + }; + }); +`); + +let buildExportAll = template(` + for (var KEY in TARGET) { + if (KEY !== "default") EXPORT_OBJ[KEY] = TARGET[KEY]; + } +`); + +export default function ({ types: t }) { + let IGNORE_REASSIGNMENT_SYMBOL = Symbol(); + + let reassignmentVisitor = { + "AssignmentExpression|UpdateExpression"(path) { + if (path.node[IGNORE_REASSIGNMENT_SYMBOL]) return; + path.node[IGNORE_REASSIGNMENT_SYMBOL] = true; + + let arg = path.get(path.isAssignmentExpression() ? "left" : "argument"); + if (!arg.isIdentifier()) return; + + let name = arg.node.name; + + // redeclared in this scope + if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return; + + let exportedNames = this.exports[name]; + if (!exportedNames) return; + + let node = path.node; + + for (let exportedName of exportedNames) { + node = this.buildCall(exportedName, node).expression; + } + + path.replaceWith(node); + } + }; + + return { + visitor: { + Program: { + exit(path) { + let exportIdent = path.scope.generateUidIdentifier("export"); + + let exportNames = Object.create(null); + let modules = Object.create(null); + + let beforeBody = []; + let setters = []; + let sources = []; + let variableIds = []; + + function addExportName(key, val) { + exportNames[key] = exportNames[key] || []; + exportNames[key].push(val); + } + + function pushModule(source, key, specifiers) { + let _modules = modules[source] = modules[source] || { imports: [], exports: [] }; + _modules[key] = _modules[key].concat(specifiers); + } + + function buildExportCall(name, val) { + return t.expressionStatement( + t.callExpression(exportIdent, [t.stringLiteral(name), val]) + ); + } + + let body: Array = path.get("body"); + + let canHoist = true; + for (let path of body) { + if (path.isExportDeclaration()) path = path.get("declaration"); + if (path.isVariableDeclaration() && path.node.kind !== "var") { + canHoist = false; + break; + } + } + + for (let path of body) { + if (canHoist && path.isFunctionDeclaration()) { + beforeBody.push(path.node); + path.remove(); + } else if (path.isImportDeclaration()) { + let source = path.node.source.value; + pushModule(source, "imports", path.node.specifiers); + for (let name in path.getBindingIdentifiers()) { + path.scope.removeBinding(name); + variableIds.push(t.identifier(name)); + } + path.remove(); + } else if (path.isExportAllDeclaration()) { + pushModule(path.node.source.value, "exports", path.node); + path.remove(); + } else if (path.isExportDefaultDeclaration()) { + let declar = path.get("declaration"); + if (declar.isClassDeclaration() || declar.isFunctionDeclaration()) { + let id = declar.node.id; + let nodes = []; + + if (id) { + nodes.push(declar.node); + nodes.push(buildExportCall("default", id)); + addExportName(id.name, "default"); + } else { + nodes.push(buildExportCall("default", t.toExpression(declar.node))); + } + + if (!canHoist || declar.isClassDeclaration()) { + path.replaceWithMultiple(nodes); + } else { + beforeBody = beforeBody.concat(nodes); + path.remove(); + } + } else { + path.replaceWith(buildExportCall("default", declar.node)); + } + } else if (path.isExportNamedDeclaration()) { + let declar = path.get("declaration"); + + if (declar.node) { + path.replaceWith(declar); + + let nodes = []; + for (let name in declar.getBindingIdentifiers()) { + addExportName(name, name); + nodes.push(buildExportCall(name, t.identifier(name))); + } + path.insertAfter(nodes); + } + + let specifiers = path.node.specifiers; + if (specifiers && specifiers.length) { + if (path.node.source) { + pushModule(path.node.source.value, "exports", specifiers); + path.remove(); + } else { + let nodes = []; + + for (let specifier of specifiers) { + nodes.push(buildExportCall(specifier.exported.name, specifier.local)); + addExportName(specifier.local.name, specifier.exported.name); + } + + path.replaceWithMultiple(nodes); + } + } + } + } + + for (let source in modules) { + let specifiers = modules[source]; + + let setterBody = []; + let target = path.scope.generateUidIdentifier(source); + + for (let specifier of specifiers.imports) { + if (t.isImportNamespaceSpecifier(specifier)) { + setterBody.push(t.expressionStatement(t.assignmentExpression("=", specifier.local, target))); + } else if (t.isImportDefaultSpecifier(specifier)) { + specifier = t.importSpecifier(specifier.local, t.identifier("default")); + } + + if (t.isImportSpecifier(specifier)) { + setterBody.push(t.expressionStatement(t.assignmentExpression("=", specifier.local, t.memberExpression(target, specifier.imported)))); + } + } + + if (specifiers.exports.length) { + let exportObjRef = path.scope.generateUidIdentifier("exportObj"); + + setterBody.push(t.variableDeclaration("var", [ + t.variableDeclarator(exportObjRef, t.objectExpression([])) + ])); + + for (let node of specifiers.exports) { + if (t.isExportAllDeclaration(node)) { + setterBody.push(buildExportAll({ + KEY: path.scope.generateUidIdentifier("key"), + EXPORT_OBJ: exportObjRef, + TARGET: target + })); + } else if (t.isExportSpecifier(node)) { + setterBody.push(t.expressionStatement( + t.assignmentExpression("=", t.memberExpression(exportObjRef, node.exported), t.memberExpression(target, node.local)) + )); + } else { + // todo + } + } + + setterBody.push(t.expressionStatement(t.callExpression(exportIdent, [exportObjRef]))); + } + + sources.push(t.stringLiteral(source)); + setters.push(t.functionExpression(null, [target], t.blockStatement(setterBody))); + } + + + let moduleName = this.getModuleName(); + if (moduleName) moduleName = t.stringLiteral(moduleName); + + if (canHoist) { + hoistVariables(path, id => variableIds.push(id)); + } + + if (variableIds.length) { + beforeBody.unshift(t.variableDeclaration("var", variableIds.map(id => t.variableDeclarator(id)))); + } + + path.traverse(reassignmentVisitor, { + exports: exportNames, + buildCall: buildExportCall, + scope: path.scope + }); + + path.node.body = [ + buildTemplate({ + BEFORE_BODY: beforeBody, + MODULE_NAME: moduleName, + SETTERS: setters, + SOURCES: sources, + BODY: path.node.body, + EXPORT_IDENTIFIER: exportIdent + }) + ]; + } + } + } + }; +} diff --git a/packages/babel-plugin-transform-es2015-modules-umd/README.md b/packages/babel-plugin-transform-es2015-modules-umd/README.md new file mode 100644 index 0000000000..c96b1cdf4a --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-umd/README.md @@ -0,0 +1,33 @@ +# babel-plugin-transform-es2015-modules-umd + +## Installation + +```sh +$ npm install babel-plugin-transform-es2015-modules-umd +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-es2015-modules-umd"] +} +``` + +### Via CLI + +```sh +$ babel --plugins transform-es2015-modules-umd script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-es2015-modules-umd"] +}); +``` diff --git a/packages/babel-plugin-transform-es2015-modules-umd/package.json b/packages/babel-plugin-transform-es2015-modules-umd/package.json new file mode 100644 index 0000000000..b5a73044ee --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-umd/package.json @@ -0,0 +1,16 @@ +{ + "name": "babel-plugin-transform-es2015-modules-umd", + "version": "1.0.0", + "description": "", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "dependencies": { + "babel-plugin-transform-es2015-modules-amd": "^5.0.0", + "babel-template": "^5.0.0", + "babel-runtime": "^5.8.20" + }, + "keywords": [ + "babel-plugin" + ] +} diff --git a/packages/babel-plugin-transform-es2015-modules-umd/src/index.js b/packages/babel-plugin-transform-es2015-modules-umd/src/index.js new file mode 100644 index 0000000000..c457e12484 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-umd/src/index.js @@ -0,0 +1,85 @@ +import { basename, extname } from "path"; +import template from "babel-template"; + +let buildWrapper = template(` + (function (global, factory) { + if (typeof define === "function" && define.amd) { + define(MODULE_NAME, AMD_ARGUMENTS, factory); + } else if (typeof exports !== "undefined") { + factory(COMMON_ARGUMENTS); + } else { + var mod = { exports: {} }; + factory(BROWSER_ARGUMENTS); + global.GLOBAL_ARG = mod.exports; + } + })(this, FUNC); +`); + +export default function ({ types: t }) { + function isValidDefine(path) { + if (!path.isExpressionStatement()) return; + + let expr = path.get("expression"); + if (!expr.isCallExpression()) return false; + if (!expr.get("callee").isIdentifier({ name: "define" })) return false; + + let args = expr.get("arguments"); + if (args.length === 3 && !args.shift().isStringLiteral()) return false; + if (args.length !== 2) return false; + if (!args.shift().isArrayExpression()) return false; + if (!args.shift().isFunctionExpression()) return false; + + return true; + } + + return { + inherits: require("babel-plugin-transform-es2015-modules-amd"), + + visitor: { + Program: { + exit(path) { + let last = path.get("body").pop(); + if (!isValidDefine(last)) return; + + let call = last.node.expression; + let args = call.arguments; + + let moduleName = args.length === 3 ? args.shift() : null; + let amdArgs = call.arguments[0]; + let func = call.arguments[1]; + + let commonArgs = amdArgs.elements.map((arg) => { + if (arg.value === "module" || arg.value === "exports") { + return t.identifier(arg.value); + } else { + return t.callExpression(t.identifier("require"), [arg]); + } + }); + + let browserArgs = amdArgs.elements.map((arg) => { + if (arg.value === "module") { + return t.identifier("mod"); + } else if (arg.value === "exports") { + return t.memberExpression(t.identifier("mod"), t.identifier("exports")); + } else { + return t.memberExpression(t.identifier("global"), t.identifier( + t.toIdentifier(basename(arg.value, extname(arg.value))) + )); + } + }); + + let globalArg = t.identifier(t.toIdentifier(moduleName ? moduleName.value : this.file.opts.basename)); + + last.replaceWith(buildWrapper({ + MODULE_NAME: moduleName, + BROWSER_ARGUMENTS: browserArgs, + AMD_ARGUMENTS: amdArgs, + COMMON_ARGUMENTS: commonArgs, + GLOBAL_ARG: globalArg, + FUNC: func + })); + } + } + } + }; +} diff --git a/packages/babel-plugin-transform-es2015-object-super/package.json b/packages/babel-plugin-transform-es2015-object-super/package.json index 00dae90f9b..902d5e2605 100644 --- a/packages/babel-plugin-transform-es2015-object-super/package.json +++ b/packages/babel-plugin-transform-es2015-object-super/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-es2015-object-super", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 object super to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-helper-replace-supers": "^5.0.0", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-object-super/src/index.js b/packages/babel-plugin-transform-es2015-object-super/src/index.js index 6845446a11..95098fda8a 100644 --- a/packages/babel-plugin-transform-es2015-object-super/src/index.js +++ b/packages/babel-plugin-transform-es2015-object-super/src/index.js @@ -1,7 +1,47 @@ -export default function () { +import ReplaceSupers from "babel-helper-replace-supers"; + +export default function ({ types: t }) { + function Property(path, node, scope, getObjectRef, file) { + let replaceSupers = new ReplaceSupers({ + getObjectRef: getObjectRef, + methodNode: node, + methodPath: path, + isStatic: true, + scope: scope, + file: file + }); + + replaceSupers.replace(); + } + + let CONTAINS_SUPER = Symbol(); + return { visitor: { - // your visitor methods go here + Super(path) { + let parentObj = path.findParent((path) => path.isObjectExpression()); + if (parentObj) parentObj.node[CONTAINS_SUPER] = true; + }, + + ObjectExpression: { + exit(path, file) { + if (!path.node[CONTAINS_SUPER]) return; + + let objectRef; + let getObjectRef = () => objectRef = objectRef || path.scope.generateUidIdentifier("obj"); + + let propPaths: Array = path.get("properties"); + for (let propPath of propPaths) { + if (propPath.isObjectProperty()) propPath = propPath.get("value"); + Property(propPath, propPath.node, path.scope, getObjectRef, file); + } + + if (objectRef) { + path.scope.push({ id: objectRef }); + path.replaceWith(t.assignmentExpression("=", objectRef, path.node)); + } + } + } } }; } diff --git a/packages/babel-plugin-transform-es2015-parameters/package.json b/packages/babel-plugin-transform-es2015-parameters/package.json index 3c8e296966..f7ad3d78ae 100644 --- a/packages/babel-plugin-transform-es2015-parameters/package.json +++ b/packages/babel-plugin-transform-es2015-parameters/package.json @@ -1,11 +1,19 @@ { "name": "babel-plugin-transform-es2015-parameters", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 default and rest parameters to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", + "dependencies": { + "babel-traverse": "^5.10.32", + "babel-helper-call-delegate": "^5.0.0", + "babel-helper-get-function-arity": "^5.0.0", + "babel-template": "^5.10.32", + "babel-types": "^5.10.32", + "babel-runtime": "^5.10.32" + }, "keywords": [ "babel-plugin" ] -} +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-parameters/src/default.js b/packages/babel-plugin-transform-es2015-parameters/src/default.js new file mode 100644 index 0000000000..9b99a3e475 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-parameters/src/default.js @@ -0,0 +1,149 @@ +import getFunctionArity from "babel-helper-get-function-arity"; +import callDelegate from "babel-helper-call-delegate"; +import template from "babel-template"; +import * as t from "babel-types"; + +let buildDefaultParam = template(` + let VARIABLE_NAME = + ARGUMENTS.length <= ARGUMENT_KEY || ARGUMENTS[ARGUMENT_KEY] === undefined ? + DEFAULT_VALUE + : + ARGUMENTS[ARGUMENT_KEY]; +`); + +let buildDefaultParamAssign = template(` + if (VARIABLE_NAME === undefined) VARIABLE_NAME = DEFAULT_VALUE; +`); + +let buildCutOff = template(` + let $0 = arguments[$1]; +`); + +function hasDefaults(node) { + for (let param of (node.params: Array)) { + if (!t.isIdentifier(param)) return true; + } + return false; +} + +let iifeVisitor = { + ReferencedIdentifier(path, state) { + let name = path.node.name; + if (name === "eval" || (path.scope.hasOwnBinding(name) && path.scope.getOwnBinding(name).kind !== "param")) { + state.iife = true; + path.stop(); + } + }, + + Scope(path) { + // different bindings + path.skip(); + } +}; + +export let visitor = { + Function(path) { + let { node, scope } = path; + if (!hasDefaults(node)) return; + + // ensure it's a block, useful for arrow functions + path.ensureBlock(); + + let state = { + iife: false, + scope: scope + }; + + let body = []; + + // + let argsIdentifier = t.identifier("arguments"); + argsIdentifier._shadowedFunctionLiteral = path; + + // push a default parameter definition + function pushDefNode(left, right, i) { + let defNode; + if (exceedsLastNonDefault(i) || t.isPattern(left)) { + defNode = buildDefaultParam({ + VARIABLE_NAME: left, + DEFAULT_VALUE: right, + ARGUMENT_KEY: t.numberLiteral(i), + ARGUMENTS: argsIdentifier + }); + } else { + defNode = buildDefaultParamAssign({ + VARIABLE_NAME: left, + DEFAULT_VALUE: right + }); + } + defNode._blockHoist = node.params.length - i; + body.push(defNode); + } + + // check if an index exceeds the functions arity + function exceedsLastNonDefault(i) { + return i + 1 > lastNonDefaultParam; + } + + // + let lastNonDefaultParam = getFunctionArity(node); + + // + let params = path.get("params"); + for (let i = 0; i < params.length; i++) { + let param = params[i]; + + if (!param.isAssignmentPattern()) { + if (!param.isIdentifier()) { + param.traverse(iifeVisitor, state); + } + + continue; + } + + let left = param.get("left"); + let right = param.get("right"); + + // + if (exceedsLastNonDefault(i) || left.isPattern()) { + let placeholder = scope.generateUidIdentifier("x"); + placeholder._isDefaultPlaceholder = true; + node.params[i] = placeholder; + } else { + node.params[i] = left.node; + } + + // + if (!state.iife) { + if (right.isIdentifier() && scope.hasOwnBinding(right.node.name) && scope.getOwnBinding(right.node.name).kind !== "param") { + // the right hand side references a parameter + state.iife = true; + } else { + right.traverse(iifeVisitor, state); + } + } + + pushDefNode(left.node, right.node, i); + } + + // add declarations for trailing parameters + for (let i = lastNonDefaultParam + 1; i < node.params.length; i++) { + let param = node.params[i]; + if (param._isDefaultPlaceholder) continue; + + let declar = buildCutOff(param, t.numberLiteral(i)); + declar._blockHoist = node.params.length - i; + body.push(declar); + } + + // we need to cut off all trailing parameters + node.params = node.params.slice(0, lastNonDefaultParam); + + if (state.iife) { + body.push(callDelegate(path, scope)); + path.set("body", t.blockStatement(body)); + } else { + path.get("body").unshiftContainer("body", body); + } + } +}; diff --git a/packages/babel-core/src/transformation/transformers/es6/parameters/destructuring.js b/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js similarity index 75% rename from packages/babel-core/src/transformation/transformers/es6/parameters/destructuring.js rename to packages/babel-plugin-transform-es2015-parameters/src/destructuring.js index da8b0de40f..eb14db26a1 100644 --- a/packages/babel-core/src/transformation/transformers/es6/parameters/destructuring.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/destructuring.js @@ -3,18 +3,19 @@ import * as t from "babel-types"; export let visitor = { Function(path) { let params: Array = path.get("params"); - let body = path.get("body"); - + for (let i = 0; i < params.length; i++) { let param = params[i]; if (param.isArrayPattern() || param.isObjectPattern()) { - let uid = path.scope.generateUidIdentifierBasedOnNode(param.node); + let uid = path.scope.generateUidIdentifier("ref"); let declar = t.variableDeclaration("let", [ t.variableDeclarator(param.node, uid) ]); declar._blockHoist = params.length - i; - body.unshiftContainer("body", declar); + + path.ensureBlock(); + path.get("body").unshiftContainer("body", declar); param.replaceWith(uid); } diff --git a/packages/babel-plugin-transform-es2015-parameters/src/index.js b/packages/babel-plugin-transform-es2015-parameters/src/index.js index 6845446a11..6279147062 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/index.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/index.js @@ -1,7 +1,23 @@ +import type { NodePath } from "babel-traverse"; +import { visitors } from "babel-traverse"; + +import * as destructuring from "./destructuring"; +import * as def from "./default"; +import * as rest from "./rest"; + export default function () { return { - visitor: { - // your visitor methods go here - } + visitor: visitors.merge([{ + ArrowFunctionExpression(path) { + // default/rest visitors require access to `arguments` + let params: Array = path.get("params"); + for (let param of params) { + if (param.isRestElement() || param.isAssignmentPattern()) { + path.arrowFunctionToShadowed(); + break; + } + } + } + }, destructuring.visitor, rest.visitor, def.visitor]) }; } diff --git a/packages/babel-core/src/transformation/transformers/es6/parameters/rest.js b/packages/babel-plugin-transform-es2015-parameters/src/rest.js similarity index 79% rename from packages/babel-core/src/transformation/transformers/es6/parameters/rest.js rename to packages/babel-plugin-transform-es2015-parameters/src/rest.js index 6eb37b76d2..5eb6a6b0e5 100644 --- a/packages/babel-core/src/transformation/transformers/es6/parameters/rest.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/rest.js @@ -1,30 +1,42 @@ -import * as util from "../../../../util"; +import template from "babel-template"; import * as t from "babel-types"; +let buildRest = template(` + for (var LEN = ARGUMENTS.length, + ARRAY = Array(ARRAY_LEN), + KEY = START; + KEY < LEN; + KEY++) { + ARRAY[ARRAY_KEY] = ARGUMENTS[KEY]; + } +`); + let memberExpressionOptimisationVisitor = { - Scope(node, parent, scope, state) { + Scope(path, state) { // check if this scope has a local binding that will shadow the rest parameter - if (!scope.bindingIdentifierEquals(state.name, state.outerBinding)) { - this.skip(); + if (!path.scope.bindingIdentifierEquals(state.name, state.outerBinding)) { + path.skip(); } }, - Flow() { + Flow(path) { // don't touch reference in type annotations - this.skip(); + path.skip(); }, - Function(node, parent, scope, state) { + Function(path, state) { // skip over functions as whatever `arguments` we reference inside will refer // to the wrong function let oldNoOptimise = state.noOptimise; state.noOptimise = true; - this.traverse(memberExpressionOptimisationVisitor, state); + path.traverse(memberExpressionOptimisationVisitor, state); state.noOptimise = oldNoOptimise; - this.skip(); + path.skip(); }, - ReferencedIdentifier(node, parent, scope, state) { + ReferencedIdentifier(path, state) { + let { node } = path; + // we can't guarantee the purity of arguments if (node.name === "arguments") { state.deopted = true; @@ -36,26 +48,26 @@ let memberExpressionOptimisationVisitor = { if (state.noOptimise) { state.deopted = true; } else { - if (this.parentPath.isMemberExpression({ computed: true, object: node })) { + if (path.parentPath.isMemberExpression({ computed: true, object: node })) { // if we know that this member expression is referencing a number then we can safely // optimise it - let prop = this.parentPath.get("property"); + let prop = path.parentPath.get("property"); if (prop.isBaseType("number")) { - state.candidates.push(this); + state.candidates.push(path); return; } } // optimise single spread args in calls - if (this.parentPath.isSpreadElement() && state.offset === 0) { - let call = this.parentPath.parentPath; + if (path.parentPath.isSpreadElement() && state.offset === 0) { + let call = path.parentPath.parentPath; if (call.isCallExpression() && call.node.arguments.length === 1) { - state.candidates.push(this); + state.candidates.push(path); return; } } - state.references.push(this); + state.references.push(path); } }, @@ -65,7 +77,7 @@ let memberExpressionOptimisationVisitor = { * See https://github.com/babel/babel/issues/2091 */ - BindingIdentifier(node, parent, scope, state) { + BindingIdentifier({ node }, state) { if (node.name === state.name) { state.deopted = true; } @@ -92,7 +104,8 @@ function hasRest(node) { } export let visitor = { - Function(node, parent, scope) { + Function(path) { + let { node, scope } = path; if (!hasRest(node)) return; let restParam = node.params.pop(); @@ -101,7 +114,7 @@ export let visitor = { let argsId = t.identifier("arguments"); // otherwise `arguments` will be remapped in arrow functions - argsId._shadowedFunctionLiteral = this; + argsId._shadowedFunctionLiteral = path; // support patterns if (t.isPattern(rest)) { @@ -133,7 +146,7 @@ export let visitor = { deopted: false }; - this.traverse(memberExpressionOptimisationVisitor, state); + path.traverse(memberExpressionOptimisationVisitor, state); if (!state.deopted && !state.references.length) { // we only have shorthands and there are no other references @@ -180,15 +193,14 @@ export let visitor = { ); } - let loop = util.template("rest", { - ARRAY_TYPE: restParam.typeAnnotation, - ARGUMENTS: argsId, - ARRAY_KEY: arrKey, - ARRAY_LEN: arrLen, - START: start, - ARRAY: rest, - KEY: key, - LEN: len + let loop = buildRest({ + ARGUMENTS: argsId, + ARRAY_KEY: arrKey, + ARRAY_LEN: arrLen, + START: start, + ARRAY: rest, + KEY: key, + LEN: len, }); if (state.deopted) { @@ -198,7 +210,7 @@ export let visitor = { // perform allocation at the lowest common ancestor of all references loop._blockHoist = 1; - let target = this.getEarliestCommonAncestorFrom(state.references).getStatementParent(); + let target = path.getEarliestCommonAncestorFrom(state.references).getStatementParent(); // don't perform the allocation inside a loop let highestLoop; diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/package.json b/packages/babel-plugin-transform-es2015-shorthand-properties/package.json index 2ef556d43a..f23264de66 100644 --- a/packages/babel-plugin-transform-es2015-shorthand-properties/package.json +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-es2015-shorthand-properties", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 shorthand properties to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-types": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js b/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js index abd0e3ac26..357d57887a 100644 --- a/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js +++ b/packages/babel-plugin-transform-es2015-shorthand-properties/src/index.js @@ -1,11 +1,20 @@ +import * as t from "babel-types"; + export default function () { return { visitor: { - Property({ node }) { - if (node.method) { - node.method = false; + ObjectMethod(path) { + let { node } = path; + if (node.kind === "method") { + path.replaceWith(t.objectProperty( + node.key, + t.functionExpression(null, node.params, node.body, node.generator, node.async), + node.computed + )); } + }, + ObjectProperty({ node }) { if (node.shorthand) { node.shorthand = false; } diff --git a/packages/babel-plugin-transform-es2015-spread/package.json b/packages/babel-plugin-transform-es2015-spread/package.json index a5538bd3cf..c95fcff052 100644 --- a/packages/babel-plugin-transform-es2015-spread/package.json +++ b/packages/babel-plugin-transform-es2015-spread/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es2015-spread", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 spread to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-spread/src/index.js b/packages/babel-plugin-transform-es2015-spread/src/index.js index a43cbd85d0..54dce19086 100644 --- a/packages/babel-plugin-transform-es2015-spread/src/index.js +++ b/packages/babel-plugin-transform-es2015-spread/src/index.js @@ -1,6 +1,6 @@ export default function ({ types: t }) { - function getSpreadLiteral(spread, scope) { - if (scope.hub.file.isLoose("es6.spread") && !t.isIdentifier(spread.argument, { name: "arguments" })) { + function getSpreadLiteral(spread, scope, state) { + if (state.opts.loose && !t.isIdentifier(spread.argument, { name: "arguments" })) { return spread.argument; } else { return scope.toArray(spread.argument, true); @@ -8,7 +8,7 @@ export default function ({ types: t }) { } function hasSpread(nodes) { - for (var i = 0; i < nodes.length; i++) { + for (let i = 0; i < nodes.length; i++) { if (t.isSpreadElement(nodes[i])) { return true; } @@ -16,10 +16,10 @@ export default function ({ types: t }) { return false; } - function build(props: Array, scope) { - var nodes = []; + function build(props: Array, scope, state) { + let nodes = []; - var _props = []; + let _props = []; function push() { if (!_props.length) return; @@ -27,10 +27,10 @@ export default function ({ types: t }) { _props = []; } - for (var prop of props) { + for (let prop of props) { if (t.isSpreadElement(prop)) { push(); - nodes.push(getSpreadLiteral(prop, scope)); + nodes.push(getSpreadLiteral(prop, scope, state)); } else { _props.push(prop); } @@ -43,49 +43,50 @@ export default function ({ types: t }) { return { visitor: { - ArrayExpression({ node, scope }) { - var elements = node.elements; + ArrayExpression(path, state) { + let { node, scope } = path; + let elements = node.elements; if (!hasSpread(elements)) return; - var nodes = build(elements, scope); - var first = nodes.shift(); + let nodes = build(elements, scope, state); + let first = nodes.shift(); if (!t.isArrayExpression(first)) { nodes.unshift(first); first = t.arrayExpression([]); } - return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes); + path.replaceWith(t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes)); }, - CallExpression(path) { - var { node, scope } = path; + CallExpression(path, state) { + let { node, scope } = path; - var args = node.arguments; + let args = node.arguments; if (!hasSpread(args)) return; - var contextLiteral = t.identifier("undefined"); + let contextLiteral = t.identifier("undefined"); node.arguments = []; - var nodes; + let nodes; if (args.length === 1 && args[0].argument.name === "arguments") { nodes = [args[0].argument]; } else { - nodes = build(args, scope); + nodes = build(args, scope, state); } - var first = nodes.shift(); + let first = nodes.shift(); if (nodes.length) { node.arguments.push(t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes)); } else { node.arguments.push(first); } - var callee = node.callee; + let callee = node.callee; if (path.get("callee").isMemberExpression()) { - var temp = scope.maybeGenerateMemoised(callee.object); + let temp = scope.maybeGenerateMemoised(callee.object); if (temp) { callee.object = t.assignmentExpression("=", temp, callee.object); contextLiteral = temp; @@ -100,23 +101,34 @@ export default function ({ types: t }) { node.arguments.unshift(contextLiteral); }, - NewExpression({ node, scope }, file) { - var args = node.arguments; + NewExpression(path, state) { + let { node, scope } = path; + let args = node.arguments; if (!hasSpread(args)) return; - var nodes = build(args, scope); + let nodes = build(args, scope, state); + + let context = t.arrayExpression([t.nullLiteral()]); - var context = t.arrayExpression([t.nullLiteral()]); args = t.callExpression(t.memberExpression(context, t.identifier("concat")), nodes); - return t.newExpression( + path.replaceWith(t.newExpression( t.callExpression( - t.memberExpression(file.addHelper("bind"), t.identifier("apply")), + t.memberExpression( + t.memberExpression( + t.memberExpression( + t.identifier("Function"), + t.identifier("prototype"), + ), + t.identifier("bind") + ), + t.identifier("apply") + ), [node.callee, args] ), [] - ); + )); } } }; diff --git a/packages/babel-plugin-transform-es2015-sticky-regex/package.json b/packages/babel-plugin-transform-es2015-sticky-regex/package.json index acbe54f9a8..e51839c98f 100644 --- a/packages/babel-plugin-transform-es2015-sticky-regex/package.json +++ b/packages/babel-plugin-transform-es2015-sticky-regex/package.json @@ -1,11 +1,16 @@ { "name": "babel-plugin-transform-es2015-sticky-regex", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 sticky regex to an ES5 RegExp constructor", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-helper-regex": "^6.0.0", + "babel-types": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-sticky-regex/src/index.js b/packages/babel-plugin-transform-es2015-sticky-regex/src/index.js index 6845446a11..f321a74197 100644 --- a/packages/babel-plugin-transform-es2015-sticky-regex/src/index.js +++ b/packages/babel-plugin-transform-es2015-sticky-regex/src/index.js @@ -1,7 +1,18 @@ +import * as regex from "babel-helper-regex"; +import * as t from "babel-types"; + export default function () { return { visitor: { - // your visitor methods go here + RegexLiteral(path) { + let { node } = path; + if (!regex.is(node, "y")) return; + + path.replaceWith(t.newExpression(t.identifier("RegExp"), [ + t.stringLiteral(node.pattern), + t.stringLiteral(node.flags) + ])); + } } }; } diff --git a/packages/babel-plugin-transform-es2015-tail-call/README.md b/packages/babel-plugin-transform-es2015-tail-call/README.md deleted file mode 100644 index c54782c407..0000000000 --- a/packages/babel-plugin-transform-es2015-tail-call/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# babel-plugin-transform-es2015-tail-call - -Compile ES2015 tail call to ES5 - -## Installation - -```sh -$ npm install babel-plugin-transform-es2015-tail-call -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["transform-es2015-tail-call"] -} -``` - -### Via CLI - -```sh -$ babel --plugins transform-es2015-tail-call script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["transform-es2015-tail-call"] -}); -``` diff --git a/packages/babel-plugin-transform-es2015-tail-call/src/index.js b/packages/babel-plugin-transform-es2015-tail-call/src/index.js deleted file mode 100644 index 6845446a11..0000000000 --- a/packages/babel-plugin-transform-es2015-tail-call/src/index.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function () { - return { - visitor: { - // your visitor methods go here - } - }; -} diff --git a/packages/babel-plugin-transform-es2015-template-literals/package.json b/packages/babel-plugin-transform-es2015-template-literals/package.json index c3d8774956..aa5341fc8e 100644 --- a/packages/babel-plugin-transform-es2015-template-literals/package.json +++ b/packages/babel-plugin-transform-es2015-template-literals/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es2015-template-literals", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 template literals to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-template-literals/src/index.js b/packages/babel-plugin-transform-es2015-template-literals/src/index.js index 8e1b8fc0c9..fedf08d95a 100644 --- a/packages/babel-plugin-transform-es2015-template-literals/src/index.js +++ b/packages/babel-plugin-transform-es2015-template-literals/src/index.js @@ -4,30 +4,20 @@ export default function ({ types: t }) { } function buildBinaryExpression(left, right) { - var node = t.binaryExpression("+", left, right); - node._templateLiteralProduced = true; - return node; + return t.binaryExpression("+", left, right); } - /*function crawl(path) { - if (path.is("_templateLiteralProduced")) { - crawl(path.get("left")); - crawl(path.get("right")); - } else if (!path.isBaseType("string") && !path.isBaseType("number")) { - path.replaceWith(t.callExpression(t.identifier("String"), [path.node])); - } - }*/ - return { visitor: { - TaggedTemplateExpression({ node }, file) { - var quasi = node.quasi; - var args = []; + TaggedTemplateExpression(path, state) { + let { node } = path; + let quasi = node.quasi; + let args = []; - var strings = []; - var raw = []; + let strings = []; + let raw = []; - for (var elem of (quasi.quasis: Array)) { + for (let elem of (quasi.quasis: Array)) { strings.push(t.stringLiteral(elem.value.cooked)); raw.push(t.stringLiteral(elem.value.raw)); } @@ -35,25 +25,33 @@ export default function ({ types: t }) { strings = t.arrayExpression(strings); raw = t.arrayExpression(raw); - var templateName = "tagged-template-literal"; - if (file.isLoose("es6.templateLiterals")) templateName += "-loose"; + let templateName = "taggedTemplateLiteral"; + if (state.opts.loose) templateName += "Loose"; - var templateObject = file.addTemplateObject(templateName, strings, raw); + let templateObject = state.file.addTemplateObject(templateName, strings, raw); args.push(templateObject); args = args.concat(quasi.expressions); - return t.callExpression(node.tag, args); + path.replaceWith(t.callExpression(node.tag, args)); }, - TemplateLiteral(path) { - var nodes = []; + TemplateLiteral(path, state) { + let nodes: Array = []; + + let expressions = path.get("expressions"); for (let elem of (path.node.quasis: Array)) { nodes.push(t.stringLiteral(elem.value.cooked)); - var expr = path.node.expressions.shift(); - if (expr) nodes.push(expr); + let expr = expressions.shift(); + if (expr) { + if (state.opts.spec && !expr.isBaseType("string") && !expr.isBaseType("number")) { + nodes.push(t.callExpression(t.identifier("String"), [expr.node])); + } else { + nodes.push(expr.node); + } + } } // filter out empty string literals @@ -66,16 +64,15 @@ export default function ({ types: t }) { } if (nodes.length > 1) { - var root = buildBinaryExpression(nodes.shift(), nodes.shift()); + let root = buildBinaryExpression(nodes.shift(), nodes.shift()); - for (let node of (nodes: Array)) { + for (let node of nodes) { root = buildBinaryExpression(root, node); } path.replaceWith(root); - //crawl(path); } else { - return nodes[0]; + path.replaceWith(nodes[0]); } } } diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/README.md b/packages/babel-plugin-transform-es2015-typeof-symbol/README.md new file mode 100644 index 0000000000..63fe8215e2 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/README.md @@ -0,0 +1,33 @@ +# babel-plugin-transform-es2015-typeof-symbol + +## Installation + +```sh +$ npm install babel-plugin-transform-es2015-typeof-symbol +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-es2015-typeof-symbol"] +} +``` + +### Via CLI + +```sh +$ babel --plugins transform-es2015-typeof-symbol script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-es2015-typeof-symbol"] +}); +``` diff --git a/packages/babel-plugin-transform-es2015-tail-call/package.json b/packages/babel-plugin-transform-es2015-typeof-symbol/package.json similarity index 50% rename from packages/babel-plugin-transform-es2015-tail-call/package.json rename to packages/babel-plugin-transform-es2015-typeof-symbol/package.json index bcb93e9efd..7882b90036 100644 --- a/packages/babel-plugin-transform-es2015-tail-call/package.json +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/package.json @@ -1,11 +1,14 @@ { - "name": "babel-plugin-transform-es2015-tail-call", + "name": "babel-plugin-transform-es2015-typeof-symbol", "version": "1.0.0", - "description": "Compile ES2015 tail call to ES5", + "description": "", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] + ], + "dependencies": { + "babel-runtime": "^5.8.20" + } } diff --git a/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js b/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js new file mode 100644 index 0000000000..04ff17a507 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-typeof-symbol/src/index.js @@ -0,0 +1,45 @@ +export default function ({ types: t }) { + return { + visitor: { + UnaryExpression(path) { + let { node, parent } = path; + if (node._ignoreSpecSymbols) return; + + if (path.parentPath.isBinaryExpression() && t.EQUALITY_BINARY_OPERATORS.indexOf(parent.operator) >= 0) { + // optimise `typeof foo === "string"` since we can determine that they'll never need to handle symbols + let opposite = path.getOpposite(); + if (opposite.isLiteral() && opposite.node.value !== "symbol" && opposite.node.value !== "object") { + return; + } + } + + if (node.operator === "typeof") { + let call = t.callExpression(this.addHelper("typeof"), [node.argument]); + if (path.get("argument").isIdentifier()) { + let undefLiteral = t.stringLiteral("undefined"); + let unary = t.unaryExpression("typeof", node.argument); + unary._ignoreSpecSymbols = true; + path.replaceWith(t.conditionalExpression( + t.binaryExpression("===", unary, undefLiteral), + undefLiteral, + call + )); + } else { + path.replaceWith(call); + } + } + }, + + BinaryExpression(path) { + let { node } = path; + if (node.operator === "instanceof") { + path.replaceWith(t.callExpression(this.addHelper("instanceof"), [node.left, node.right])); + } + }, + + "VariableDeclaration|FunctionDeclaration"(path) { + if (path.node._generated) path.skip(); + } + } + }; +} diff --git a/packages/babel-plugin-transform-es2015-unicode-regex/package.json b/packages/babel-plugin-transform-es2015-unicode-regex/package.json index 6d93ddef01..c06684d817 100644 --- a/packages/babel-plugin-transform-es2015-unicode-regex/package.json +++ b/packages/babel-plugin-transform-es2015-unicode-regex/package.json @@ -1,11 +1,16 @@ { "name": "babel-plugin-transform-es2015-unicode-regex", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES2015 unicode regex to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-helper-regex": "^6.0.0", + "regexpu": "^1.1.2", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-unicode-regex/src/index.js b/packages/babel-plugin-transform-es2015-unicode-regex/src/index.js index 6845446a11..1ffc2aa0ed 100644 --- a/packages/babel-plugin-transform-es2015-unicode-regex/src/index.js +++ b/packages/babel-plugin-transform-es2015-unicode-regex/src/index.js @@ -1,7 +1,14 @@ +import rewritePattern from "regexpu/rewrite-pattern"; +import * as regex from "babel-helper-regex"; + export default function () { return { visitor: { - // your visitor methods go here + RegexLiteral({ node }) { + if (!regex.is(node, "u")) return; + node.pattern = rewritePattern(node.pattern, node.flags); + regex.pullFlag(node, "u"); + } } }; } diff --git a/packages/babel-plugin-transform-es3-member-expression-literals/package.json b/packages/babel-plugin-transform-es3-member-expression-literals/package.json index e838ee89e7..1db82b387e 100644 --- a/packages/babel-plugin-transform-es3-member-expression-literals/package.json +++ b/packages/babel-plugin-transform-es3-member-expression-literals/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es3-member-expression-literals", - "version": "1.0.0", + "version": "5.10.32", "description": "Ensure that reserved words are quoted in property accesses", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es3-member-expression-literals/src/index.js b/packages/babel-plugin-transform-es3-member-expression-literals/src/index.js index efc1f6566c..fa78563a23 100644 --- a/packages/babel-plugin-transform-es3-member-expression-literals/src/index.js +++ b/packages/babel-plugin-transform-es3-member-expression-literals/src/index.js @@ -2,8 +2,8 @@ export default function ({ types: t }) { return { visitor: { MemberExpression: { - exit(node) { - var prop = node.property; + exit({ node }) { + let prop = node.property; if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) { // foo.default -> foo["default"] node.property = t.stringLiteral(prop.name); diff --git a/packages/babel-plugin-transform-es3-property-literals/package.json b/packages/babel-plugin-transform-es3-property-literals/package.json index 7175b0e583..81c754fc8d 100644 --- a/packages/babel-plugin-transform-es3-property-literals/package.json +++ b/packages/babel-plugin-transform-es3-property-literals/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-es3-property-literals", - "version": "1.0.0", + "version": "5.10.32", "description": "Ensure that reserved words are quoted in object property keys", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es3-property-literals/src/index.js b/packages/babel-plugin-transform-es3-property-literals/src/index.js index a20b07e95c..b4db217325 100644 --- a/packages/babel-plugin-transform-es3-property-literals/src/index.js +++ b/packages/babel-plugin-transform-es3-property-literals/src/index.js @@ -1,9 +1,9 @@ export default function ({ types: t }) { return { visitor: { - Property: { + ObjectProperty: { exit(node) { - var key = node.key; + let key = node.key; if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) { // default: "bar" -> "default": "bar" node.key = t.stringLiteral(key.name); diff --git a/packages/babel-plugin-transform-es5-property-mutators/package.json b/packages/babel-plugin-transform-es5-property-mutators/package.json index e9ec584e5a..e5c1ca3796 100644 --- a/packages/babel-plugin-transform-es5-property-mutators/package.json +++ b/packages/babel-plugin-transform-es5-property-mutators/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-es5-property-mutators", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile ES5 property mutator shorthand syntax to Object.defineProperty", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-helper-define-map": "^5.0.0", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-es5-property-mutators/src/index.js b/packages/babel-plugin-transform-es5-property-mutators/src/index.js index 6845446a11..9ff5a15f53 100644 --- a/packages/babel-plugin-transform-es5-property-mutators/src/index.js +++ b/packages/babel-plugin-transform-es5-property-mutators/src/index.js @@ -1,7 +1,35 @@ -export default function () { +import * as defineMap from "babel-helper-define-map"; + +export default function ({ types: t }) { return { visitor: { - // your visitor methods go here + ObjectExpression(path, file) { + let{ node } = path; + let hasAny = false; + for (let prop of (node.properties: Array)) { + if (prop.kind === "get" || prop.kind === "set") { + hasAny = true; + break; + } + } + if (!hasAny) return; + + let mutatorMap = {}; + + node.properties = node.properties.filter(function (prop) { + if (!prop.computed && (prop.kind === "get" || prop.kind === "set")) { + defineMap.push(mutatorMap, prop, null, file); + return false; + } else { + return true; + } + }); + + path.replaceWith(t.callExpression( + t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")), + [node, defineMap.toDefineObject(mutatorMap)] + )); + } } }; } diff --git a/packages/babel-plugin-transform-eval/package.json b/packages/babel-plugin-transform-eval/package.json index 243280fd4f..ece165698a 100644 --- a/packages/babel-plugin-transform-eval/package.json +++ b/packages/babel-plugin-transform-eval/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-eval", - "version": "1.0.1", + "version": "5.10.32", "description": "Compile eval calls with string literals", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-eval/src/index.js b/packages/babel-plugin-transform-eval/src/index.js index 596ec54a8a..677401057a 100644 --- a/packages/babel-plugin-transform-eval/src/index.js +++ b/packages/babel-plugin-transform-eval/src/index.js @@ -3,13 +3,13 @@ export default function ({ parse, traverse }) { visitor: { CallExpression(path) { if (path.get("callee").isIdentifier({ name: "eval" }) && path.node.arguments.length === 1) { - var evaluate = path.get("arguments")[0].evaluate(); + let evaluate = path.get("arguments")[0].evaluate(); if (!evaluate.confident) return; - var code = evaluate.value; + let code = evaluate.value; if (typeof code !== "string") return; - var ast = parse(code); + let ast = parse(code); traverse.removeProperties(ast); return ast.program; } diff --git a/packages/babel-plugin-transform-exponentiation-operator/package.json b/packages/babel-plugin-transform-exponentiation-operator/package.json index ffff10a320..8b441a0a08 100644 --- a/packages/babel-plugin-transform-exponentiation-operator/package.json +++ b/packages/babel-plugin-transform-exponentiation-operator/package.json @@ -1,11 +1,16 @@ { "name": "babel-plugin-transform-exponentiation-operator", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile exponentiation operator to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-plugin-syntax-exponentiation-operator": "^5.10.32", + "babel-helper-builder-binary-assignment-operator-visitor": "^5.0.0", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-exponentiation-operator/src/index.js b/packages/babel-plugin-transform-exponentiation-operator/src/index.js index 6845446a11..68d2ef8c69 100644 --- a/packages/babel-plugin-transform-exponentiation-operator/src/index.js +++ b/packages/babel-plugin-transform-exponentiation-operator/src/index.js @@ -1,7 +1,15 @@ -export default function () { +import build from "babel-helper-builder-binary-assignment-operator-visitor"; + +export default function ({ types: t }) { return { - visitor: { - // your visitor methods go here - } + inherits: require("babel-plugin-syntax-exponentiation-operator"), + + visitor: build({ + operator: "**", + + build(left, right) { + return t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("pow")), [left, right]); + } + }) }; } diff --git a/packages/babel-plugin-transform-export-extensions/package.json b/packages/babel-plugin-transform-export-extensions/package.json index d37ea9d06b..67520da0ab 100644 --- a/packages/babel-plugin-transform-export-extensions/package.json +++ b/packages/babel-plugin-transform-export-extensions/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-export-extensions", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile export extensions to ES2015", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-plugin-syntax-export-extensions": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-export-extensions/src/index.js b/packages/babel-plugin-transform-export-extensions/src/index.js index 6845446a11..6b0afad0ce 100644 --- a/packages/babel-plugin-transform-export-extensions/src/index.js +++ b/packages/babel-plugin-transform-export-extensions/src/index.js @@ -1,7 +1,39 @@ -export default function () { +export default function ({ types: t }) { + function build(node, nodes, scope) { + let first = node.specifiers[0]; + if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return; + + let specifier = node.specifiers.shift(); + let uid = scope.generateUidIdentifier(specifier.exported.name); + + let newSpecifier; + if (t.isExportNamespaceSpecifier(specifier)) { + newSpecifier = t.importNamespaceSpecifier(uid); + } else { + newSpecifier = t.importDefaultSpecifier(uid); + } + + nodes.push(t.importDeclaration([newSpecifier], node.source)); + nodes.push(t.exportNamedDeclaration(null, [t.exportSpecifier(uid, specifier.exported)])); + + build(node, nodes, scope); + } + return { + inherits: require("babel-plugin-syntax-export-extensions"), + visitor: { - // your visitor methods go here + ExportNamedDeclaration(path) { + let { node, scope } = path; + let nodes = []; + build(node, nodes, scope); + if (!nodes.length) return; + + if (node.specifiers.length >= 1) { + nodes.push(node); + } + path.replaceWithMultiple(nodes); + } } }; } diff --git a/packages/babel-plugin-transform-flow-strip-types/package.json b/packages/babel-plugin-transform-flow-strip-types/package.json index 8d11a720d4..88bad78808 100644 --- a/packages/babel-plugin-transform-flow-strip-types/package.json +++ b/packages/babel-plugin-transform-flow-strip-types/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-flow-strip-types", - "version": "1.0.4", + "version": "5.10.32", "description": "Strip flow type annotations from your output code.", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32", + "babel-plugin-syntax-flow": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-flow-strip-types/src/index.js b/packages/babel-plugin-transform-flow-strip-types/src/index.js index ff3380333a..c700426aa9 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -2,15 +2,17 @@ export default function ({ types: t }) { const FLOW_DIRECTIVE = "@flow"; return { + inherits: require("babel-plugin-syntax-flow"), + visitor: { - Program(path, file) { - for (var comment of (file.ast.comments: Array)) { + Program(path, { file: { ast: { comments } } }) { + for (let comment of (comments: Array)) { if (comment.value.indexOf(FLOW_DIRECTIVE) >= 0) { // remove flow directive comment.value = comment.value.replace(FLOW_DIRECTIVE, ""); // remove the comment completely if it only consists of whitespace and/or stars - if (!comment.value.replace(/\*/g, "").trim()) comment._displayed = true; + if (!comment.value.replace(/\*/g, "").trim()) comment.ignore = true; } } }, @@ -29,14 +31,14 @@ export default function ({ types: t }) { }, Function({ node }) { - for (var i = 0; i < node.params.length; i++) { - var param = node.params[i]; + for (let i = 0; i < node.params.length; i++) { + let param = node.params[i]; param.optional = false; } }, TypeCastExpression(path) { - var { node } = path; + let { node } = path; do { node = node.expression; } while(t.isTypeCastExpression(node)); diff --git a/packages/babel-plugin-transform-function-bind/package.json b/packages/babel-plugin-transform-function-bind/package.json index 3cbb64bdfd..cd1528999e 100644 --- a/packages/babel-plugin-transform-function-bind/package.json +++ b/packages/babel-plugin-transform-function-bind/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-function-bind", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile function bind operator to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-plugin-syntax-function-bind": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-function-bind/src/index.js b/packages/babel-plugin-transform-function-bind/src/index.js index 6845446a11..0d3099930f 100644 --- a/packages/babel-plugin-transform-function-bind/src/index.js +++ b/packages/babel-plugin-transform-function-bind/src/index.js @@ -1,7 +1,51 @@ -export default function () { +export default function ({ types: t }) { + function getTempId(scope) { + let id = scope.path.getData("functionBind"); + if (id) return id; + + id = scope.generateDeclaredUidIdentifier("context"); + return scope.path.setData("functionBind", id); + } + + function getStaticContext(bind, scope) { + let object = bind.object || bind.callee.object; + return scope.isStatic(object) && object; + } + + function inferBindContext(bind, scope) { + let staticContext = getStaticContext(bind, scope); + if (staticContext) return staticContext; + + let tempId = getTempId(scope); + if (bind.object) { + bind.callee = t.sequenceExpression([ + t.assignmentExpression("=", tempId, bind.object), + bind.callee + ]); + } else { + bind.callee.object = t.assignmentExpression("=", tempId, bind.callee.object); + } + return tempId; + } + return { + inherits: require("babel-plugin-syntax-function-bind"), + visitor: { - // your visitor methods go here + CallExpression({ node, scope }) { + let bind = node.callee; + if (!t.isBindExpression(bind)) return; + + let context = inferBindContext(bind, scope); + node.callee = t.memberExpression(bind.callee, t.identifier("call")); + node.arguments.unshift(context); + }, + + BindExpression(path) { + let { node, scope } = path; + let context = inferBindContext(node, scope); + path.replaceWith(t.callExpression(t.memberExpression(node.callee, t.identifier("bind")), [context])); + } } }; } diff --git a/packages/babel-plugin-transform-inline-environment-variables/package.json b/packages/babel-plugin-transform-inline-environment-variables/package.json index 8c8f191798..3fa276d6ba 100644 --- a/packages/babel-plugin-transform-inline-environment-variables/package.json +++ b/packages/babel-plugin-transform-inline-environment-variables/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-inline-environment-variables", - "version": "1.0.1", + "version": "5.10.32", "description": "Inline environment variables", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-environment-variables/src/index.js b/packages/babel-plugin-transform-inline-environment-variables/src/index.js index 28a2eae941..4e80129c81 100644 --- a/packages/babel-plugin-transform-inline-environment-variables/src/index.js +++ b/packages/babel-plugin-transform-inline-environment-variables/src/index.js @@ -3,7 +3,7 @@ export default function ({ types: t }) { visitor: { MemberExpression(path) { if (path.get("object").matchesPattern("process.env")) { - var key = path.toComputedKey(); + let key = path.toComputedKey(); if (t.isStringLiteral(key)) { return t.valueToNode(process.env[key.value]); } diff --git a/packages/babel-plugin-transform-jscript/package.json b/packages/babel-plugin-transform-jscript/package.json index 90d25dfe01..a140a08168 100644 --- a/packages/babel-plugin-transform-jscript/package.json +++ b/packages/babel-plugin-transform-jscript/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-jscript", - "version": "1.0.4", + "version": "5.10.32", "description": "Babel plugin to fix buggy JScript named function expressions", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-jscript/src/index.js b/packages/babel-plugin-transform-jscript/src/index.js index e572ad6fc8..1361821acf 100644 --- a/packages/babel-plugin-transform-jscript/src/index.js +++ b/packages/babel-plugin-transform-jscript/src/index.js @@ -2,17 +2,18 @@ export default function ({ types: t }) { return { visitor: { FunctionExpression: { - exit(node) { + exit(path) { + let { node } = path; if (!node.id) return; node._ignoreUserWhitespace = true; - return t.callExpression( + path.replaceWith(t.callExpression( t.functionExpression(null, [], t.blockStatement([ t.toStatement(node), t.returnStatement(node.id) ])), [] - ); + )); } } } diff --git a/packages/babel-plugin-transform-member-expression-literals/package.json b/packages/babel-plugin-transform-member-expression-literals/package.json index 0785a4aba4..720ad40f65 100644 --- a/packages/babel-plugin-transform-member-expression-literals/package.json +++ b/packages/babel-plugin-transform-member-expression-literals/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-member-expression-literals", - "version": "1.0.1", + "version": "5.10.32", "description": "Turn valid member expression property literals into plain identifiers", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-member-expression-literals/src/index.js b/packages/babel-plugin-transform-member-expression-literals/src/index.js index 5a934f7000..5e1adc2290 100644 --- a/packages/babel-plugin-transform-member-expression-literals/src/index.js +++ b/packages/babel-plugin-transform-member-expression-literals/src/index.js @@ -2,8 +2,8 @@ export default function ({ types: t }) { return { visitor: { MemberExpression: { - exit(node) { - var prop = node.property; + exit({ node }) { + let prop = node.property; if (node.computed && t.isLiteral(prop) && t.isValidIdentifier(prop.value)) { // foo["bar"] => foo.bar node.property = t.identifier(prop.value); diff --git a/packages/babel-plugin-transform-merge-sibling-variables/package.json b/packages/babel-plugin-transform-merge-sibling-variables/package.json index cf9035ef27..b6c18688c4 100644 --- a/packages/babel-plugin-transform-merge-sibling-variables/package.json +++ b/packages/babel-plugin-transform-merge-sibling-variables/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-merge-sibling-variables", - "version": "1.0.2", + "version": "5.10.32", "description": "Merge sibling variables into one.", "repository": "babel-plugin-transform-merge-sibling-variables", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-merge-sibling-variables/src/index.js b/packages/babel-plugin-transform-merge-sibling-variables/src/index.js index ef0569e301..376ef580c4 100644 --- a/packages/babel-plugin-transform-merge-sibling-variables/src/index.js +++ b/packages/babel-plugin-transform-merge-sibling-variables/src/index.js @@ -4,10 +4,10 @@ export default function () { VariableDeclaration(path) { if (!path.inList) return; - var { node } = path; + let { node } = path; while (true) { - var sibling = path.getSibling(path.key + 1); + let sibling = path.getSibling(path.key + 1); if (!sibling.isVariableDeclaration({ kind: node.kind })) break; node.declarations = node.declarations.concat(sibling.node.declarations); diff --git a/packages/babel-plugin-transform-minify-booleans/package.json b/packages/babel-plugin-transform-minify-booleans/package.json index 4d44f29487..fc931c6dd8 100644 --- a/packages/babel-plugin-transform-minify-booleans/package.json +++ b/packages/babel-plugin-transform-minify-booleans/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-minify-booleans", - "version": "1.0.2", + "version": "5.10.32", "description": "Turn boolean literals into !0 for true and !1 for false.", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-node-env-inline/package.json b/packages/babel-plugin-transform-node-env-inline/package.json index 2bd14d0920..3a670694cd 100644 --- a/packages/babel-plugin-transform-node-env-inline/package.json +++ b/packages/babel-plugin-transform-node-env-inline/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-node-env-inline", - "version": "1.0.1", + "version": "5.10.32", "description": "", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-node-env-inline/src/index.js b/packages/babel-plugin-transform-node-env-inline/src/index.js index bde23888f6..a60d3245d1 100644 --- a/packages/babel-plugin-transform-node-env-inline/src/index.js +++ b/packages/babel-plugin-transform-node-env-inline/src/index.js @@ -6,7 +6,7 @@ export default function ({ types: t }) { path.replaceWith(t.valueToNode(process.env.NODE_ENV)); if (path.parentPath.isBinaryExpression()) { - var evaluated = path.parentPath.evaluate(); + let evaluated = path.parentPath.evaluate(); if (evaluated.confident) { path.parentPath.replaceWith(t.valueToNode(evaluated.value)); } diff --git a/packages/babel-plugin-transform-object-assign/package.json b/packages/babel-plugin-transform-object-assign/package.json index d081116d13..bbecd9eb38 100644 --- a/packages/babel-plugin-transform-object-assign/package.json +++ b/packages/babel-plugin-transform-object-assign/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-object-assign", - "version": "5.0.0", + "version": "5.10.32", "description": "Replace Object.assign with an inline helper", "author": "Jed Watson", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-object-rest-spread/package.json b/packages/babel-plugin-transform-object-rest-spread/package.json index aa16813f42..f4ae11c3aa 100644 --- a/packages/babel-plugin-transform-object-rest-spread/package.json +++ b/packages/babel-plugin-transform-object-rest-spread/package.json @@ -1,11 +1,15 @@ { "name": "babel-plugin-transform-object-rest-spread", - "version": "1.0.0", + "version": "5.10.32", "description": "Compile object rest and spread to ES5", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-plugin-syntax-object-rest-spread": "^5.10.32", + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-object-rest-spread/src/index.js b/packages/babel-plugin-transform-object-rest-spread/src/index.js index 6845446a11..ace0dbab89 100644 --- a/packages/babel-plugin-transform-object-rest-spread/src/index.js +++ b/packages/babel-plugin-transform-object-rest-spread/src/index.js @@ -1,7 +1,46 @@ -export default function () { +export default function ({ types: t }) { + function hasSpread(node) { + for (let prop of (node.properties: Array)) { + if (t.isSpreadProperty(prop)) { + return true; + } + } + return false; + } + return { + inherits: require("babel-plugin-syntax-object-rest-spread"), + visitor: { - // your visitor methods go here + ObjectExpression(path, file) { + if (!hasSpread(path.node)) return; + + let args = []; + let props = []; + + function push() { + if (!props.length) return; + args.push(t.objectExpression(props)); + props = []; + } + + for (let prop of (path.node.properties: Array)) { + if (t.isSpreadProperty(prop)) { + push(); + args.push(prop.argument); + } else { + props.push(prop); + } + } + + push(); + + if (!t.isObjectExpression(args[0])) { + args.unshift(t.objectExpression([])); + } + + path.replaceWith(t.callExpression(file.addHelper("extends"), args)); + } } }; } diff --git a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json index ce0846e614..dad6dd5d00 100644 --- a/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json +++ b/packages/babel-plugin-transform-object-set-prototype-of-to-assign/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-object-set-prototype-of-to-assign", - "version": "1.0.1", + "version": "5.10.32", "description": "Turn Object.setPrototypeOf to assignments", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-property-literals/package.json b/packages/babel-plugin-transform-property-literals/package.json index 9fc5b057f7..0d1e690316 100644 --- a/packages/babel-plugin-transform-property-literals/package.json +++ b/packages/babel-plugin-transform-property-literals/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-property-literals", - "version": "1.0.1", + "version": "5.10.32", "description": "Turn valid property key literals to plain identifiers", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-property-literals/src/index.js b/packages/babel-plugin-transform-property-literals/src/index.js index 0c323e3ad0..35e535eb59 100644 --- a/packages/babel-plugin-transform-property-literals/src/index.js +++ b/packages/babel-plugin-transform-property-literals/src/index.js @@ -1,9 +1,9 @@ export default function ({ types: t }) { return { visitor: { - Property: { - exit(node) { - var key = node.key; + ObjectProperty: { + exit({ node }) { + let key = node.key; if (t.isLiteral(key) && t.isValidIdentifier(key.value)) { // "foo": "bar" -> foo: "bar" node.key = t.identifier(key.value); diff --git a/packages/babel-plugin-transform-proto-to-assign/package.json b/packages/babel-plugin-transform-proto-to-assign/package.json index 2cfffd246d..f475c2ab0e 100644 --- a/packages/babel-plugin-transform-proto-to-assign/package.json +++ b/packages/babel-plugin-transform-proto-to-assign/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-proto-to-assign", - "version": "1.0.4", + "version": "5.10.32", "description": "Babel plugin for turning __proto__ into a shallow property clone", "repository": "babel/babel", "license": "MIT", @@ -9,7 +9,7 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^5.8.20", + "babel-runtime": "^5.10.32", "lodash": "^3.9.3" } -} +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-proto-to-assign/src/index.js b/packages/babel-plugin-transform-proto-to-assign/src/index.js index 96595e3e5a..1d420c1e67 100644 --- a/packages/babel-plugin-transform-proto-to-assign/src/index.js +++ b/packages/babel-plugin-transform-proto-to-assign/src/index.js @@ -6,7 +6,7 @@ export default function ({ types: t }) { } function isProtoAssignmentExpression(node) { - var left = node.left; + let left = node.left; return t.isMemberExpression(left) && t.isLiteral(t.toComputedKey(left, left.property), { value: "__proto__" }); } @@ -19,30 +19,31 @@ export default function ({ types: t }) { AssignmentExpression(path, file) { if (!isProtoAssignmentExpression(path.node)) return; - var nodes = []; - var left = path.node.left.object; - var temp = path.scope.maybeGenerateMemoised(left); + let nodes = []; + let left = path.node.left.object; + let temp = path.scope.maybeGenerateMemoised(left); if (temp) nodes.push(t.expressionStatement(t.assignmentExpression("=", temp, left))); nodes.push(buildDefaultsCallExpression(path.node, temp || left, file)); if (temp) nodes.push(temp); - return nodes; + path.replaceWithMultiple(nodes); }, - ExpressionStatement({ node }, file) { - var expr = node.expression; + ExpressionStatement(path, file) { + let expr = path.node.expression; if (!t.isAssignmentExpression(expr, { operator: "=" })) return; if (isProtoAssignmentExpression(expr)) { - return buildDefaultsCallExpression(expr, expr.left.object, file); + path.replaceWith(buildDefaultsCallExpression(expr, expr.left.object, file)); } }, - ObjectExpression({ node }, file) { - var proto; + ObjectExpression(path, file) { + let proto; + let { node } = path; - for (var prop of (node.properties: Array)) { + for (let prop of (node.properties: Array)) { if (isProtoKey(prop)) { proto = prop.value; pull(node.properties, prop); @@ -50,9 +51,9 @@ export default function ({ types: t }) { } if (proto) { - var args = [t.objectExpression([]), proto]; + let args = [t.objectExpression([]), proto]; if (node.properties.length) args.push(node); - return t.callExpression(file.addHelper("extends"), args); + path.replaceWith(t.callExpression(file.addHelper("extends"), args)); } } } diff --git a/packages/babel-plugin-transform-react-constant-elements/package.json b/packages/babel-plugin-transform-react-constant-elements/package.json index 74da6920fc..c6e563d94f 100644 --- a/packages/babel-plugin-transform-react-constant-elements/package.json +++ b/packages/babel-plugin-transform-react-constant-elements/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-react-constant-elements", - "version": "1.0.3", + "version": "5.10.32", "description": "Treat React JSX elements as value types and hoist them to the highest scope", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-constant-elements/src/index.js b/packages/babel-plugin-transform-react-constant-elements/src/index.js index bf66c16409..9673af7c26 100644 --- a/packages/babel-plugin-transform-react-constant-elements/src/index.js +++ b/packages/babel-plugin-transform-react-constant-elements/src/index.js @@ -1,7 +1,7 @@ export default function () { - var immutabilityVisitor = { + let immutabilityVisitor = { enter(path, state) { - var stop = () => { + let stop = () => { state.isImmutable = false; path.stop(); }; @@ -28,7 +28,7 @@ export default function () { JSXElement(path) { if (path.node._hoisted) return; - var state = { isImmutable: true }; + let state = { isImmutable: true }; path.traverse(immutabilityVisitor, state); if (state.isImmutable) { diff --git a/packages/babel-plugin-transform-react-display-name/package.json b/packages/babel-plugin-transform-react-display-name/package.json index fcb0533a2d..0b85bd748f 100644 --- a/packages/babel-plugin-transform-react-display-name/package.json +++ b/packages/babel-plugin-transform-react-display-name/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-display-name", - "version": "2.0.0", + "version": "5.10.32", "description": "Add displayName to React.createClass calls", "repository": "babel/babel", "license": "MIT", @@ -9,6 +9,6 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^5.8.20" + "babel-runtime": "^5.10.32" } -} +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-display-name/src/index.js b/packages/babel-plugin-transform-react-display-name/src/index.js index ce046a6106..9d5cde642f 100644 --- a/packages/babel-plugin-transform-react-display-name/src/index.js +++ b/packages/babel-plugin-transform-react-display-name/src/index.js @@ -2,12 +2,12 @@ import path from "path"; export default function ({ types: t }) { function addDisplayName(id, call) { - var props = call.arguments[0].properties; - var safe = true; + let props = call.arguments[0].properties; + let safe = true; - for (var i = 0; i < props.length; i++) { - var prop = props[i]; - var key = t.toComputedKey(prop); + for (let i = 0; i < props.length; i++) { + let prop = props[i]; + let key = t.toComputedKey(prop); if (t.isLiteral(key, { value: "displayName" })) { safe = false; break; @@ -15,11 +15,11 @@ export default function ({ types: t }) { } if (safe) { - props.unshift(t.property("init", t.identifier("displayName"), t.stringLiteral(id))); + props.unshift(t.objectProperty(t.identifier("displayName"), t.stringLiteral(id))); } } - var isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass"); + let isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass"); function isCreateClass(node) { if (!node || !t.isCallExpression(node)) return false; @@ -28,11 +28,11 @@ export default function ({ types: t }) { if (!isCreateClassCallExpression(node.callee)) return false; // no call arguments - var args = node.arguments; + let args = node.arguments; if (args.length !== 1) return false; // first node arg is not an object - var first = args[0]; + let first = args[0]; if (!t.isObjectExpression(first)) return false; return true; @@ -40,26 +40,26 @@ export default function ({ types: t }) { return { visitor: { - ExportDefaultDeclaration({ node }, file) { + ExportDefaultDeclaration({ node }, state) { if (isCreateClass(node.declaration)) { - var displayName = file.opts.basename; + let displayName = state.file.opts.basename; // ./{module name}/index.js if (displayName === "index") { - displayName = path.basename(path.dirname(file.opts.filename)); + displayName = path.basename(path.dirname(state.file.opts.filename)); } addDisplayName(displayName, node.declaration); } }, - "AssignmentExpression|Property|VariableDeclarator"({ node }) { - var left, right; + "AssignmentExpression|ObjectProperty|VariableDeclarator"({ node }) { + let left, right; if (t.isAssignmentExpression(node)) { left = node.left; right = node.right; - } else if (t.isProperty(node)) { + } else if (t.isObjectProperty(node)) { left = node.key; right = node.value; } else if (t.isVariableDeclarator(node)) { diff --git a/packages/babel-plugin-transform-react-inline-elements/package.json b/packages/babel-plugin-transform-react-inline-elements/package.json index 077486e9d6..a00fce7ec0 100644 --- a/packages/babel-plugin-transform-react-inline-elements/package.json +++ b/packages/babel-plugin-transform-react-inline-elements/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-react-inline-elements", - "version": "1.0.0", + "version": "5.10.32", "description": "Turn JSX elements into exploded React objects", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-inline-elements/src/index.js b/packages/babel-plugin-transform-react-inline-elements/src/index.js index b4ee8b03c3..deae408c08 100644 --- a/packages/babel-plugin-transform-react-inline-elements/src/index.js +++ b/packages/babel-plugin-transform-react-inline-elements/src/index.js @@ -1,7 +1,7 @@ export default function ({ types: t }) { function hasRefOrSpread(attrs) { - for (var i = 0; i < attrs.length; i++) { - var attr = attrs[i]; + for (let i = 0; i < attrs.length; i++) { + let attr = attrs[i]; if (t.isJSXSpreadAttribute(attr)) return true; if (isJSXAttributeOfName(attr, "ref")) return true; } @@ -14,17 +14,19 @@ export default function ({ types: t }) { return { visitor: { - JSXElement({ node }, file) { + JSXElement(path, file) { + let { node } = path; + // filter - var open = node.openingElement; + let open = node.openingElement; if (hasRefOrSpread(open.attributes)) return; // init - var isComponent = true; - var props = t.objectExpression([]); - var obj = t.objectExpression([]); - var key = t.nullLiteral(); - var type = open.name; + let isComponent = true; + let props = t.objectExpression([]); + let obj = t.objectExpression([]); + let key = t.nullLiteral(); + let type = open.name; if (t.isJSXIdentifier(type) && t.react.isCompatTag(type.name)) { type = t.stringLiteral(type.name); @@ -36,21 +38,17 @@ export default function ({ types: t }) { } function pushProp(objProps, key, value) { - objProps.push(t.property("init", key, value)); + objProps.push(t.objectProperty(key, value)); } - // metadata - pushElemProp("type", type); - pushElemProp("ref", t.nullLiteral()); - if (node.children.length) { - var children = t.react.buildChildren(node); + let children = t.react.buildChildren(node); children = children.length === 1 ? children[0] : t.arrayExpression(children); pushProp(props.properties, t.identifier("children"), children); } // props - for (var attr of (open.attributes: Array)) { + for (let attr of (open.attributes: Array)) { if (isJSXAttributeOfName(attr, "key")) { key = attr.value; } else { @@ -59,15 +57,19 @@ export default function ({ types: t }) { } if (isComponent) { - props = t.callExpression(file.addHelper("default-props"), [t.memberExpression(type, t.identifier("defaultProps")), props]); + props = t.callExpression(file.addHelper("defaultProps"), [t.memberExpression(type, t.identifier("defaultProps")), props]); } - pushElemProp("props", props); - - // key + // metadata + pushElemProp("$$typeof", file.addHelper("typeofReactElement")); + pushElemProp("type", type); pushElemProp("key", key); + pushElemProp("ref", t.nullLiteral()); - return obj; + pushElemProp("props", props); + pushElemProp("_owner", t.nullLiteral()); + + path.replaceWith(obj); } } }; diff --git a/packages/babel-plugin-transform-react-jsx-compat/package.json b/packages/babel-plugin-transform-react-jsx-compat/package.json index 5b70a67958..1b83d2f3ce 100644 --- a/packages/babel-plugin-transform-react-jsx-compat/package.json +++ b/packages/babel-plugin-transform-react-jsx-compat/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-jsx-compat", - "version": "1.0.0", + "version": "5.10.32", "description": "Turn JSX into React Pre-0.12 function calls", "repository": "babel/babel", "license": "MIT", @@ -9,7 +9,7 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^5.0.0", - "babel-plugin-transform-builder-react-jsx": "^1.0.0" + "babel-runtime": "^5.10.32", + "babel-helper-builder-react-jsx": "^1.0.0" } -} +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-jsx-compat/src/index.js b/packages/babel-plugin-transform-react-jsx-compat/src/index.js index 02c9147a8d..edb9ee5a45 100644 --- a/packages/babel-plugin-transform-react-jsx-compat/src/index.js +++ b/packages/babel-plugin-transform-react-jsx-compat/src/index.js @@ -1,6 +1,10 @@ export default function ({ types: t }) { return { - visitor: require("babel-plugin-builder-react-jsx")({ + manipulateOptions(opts, parserOpts) { + parserOpts.plugins.push("jsx"); + }, + + visitor: require("babel-helper-builder-react-jsx")({ pre(state) { state.callee = state.tagExpr; }, diff --git a/packages/babel-plugin-transform-react-jsx/package.json b/packages/babel-plugin-transform-react-jsx/package.json index 2ea83df50c..67e809da2a 100644 --- a/packages/babel-plugin-transform-react-jsx/package.json +++ b/packages/babel-plugin-transform-react-jsx/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-react-jsx", - "version": "1.0.0", + "version": "5.10.32", "description": "Turn JSX into React function calls", "repository": "babel/babel", "license": "MIT", @@ -9,7 +9,8 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^5.0.0", - "babel-plugin-transform-builder-react-jsx": "^1.0.0" + "babel-runtime": "^5.10.32", + "babel-helper-builder-react-jsx": "^1.0.0", + "babel-plugin-syntax-jsx": "^5.10.32" } -} +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-react-jsx/src/index.js b/packages/babel-plugin-transform-react-jsx/src/index.js index 784cd9ae53..f0917643ec 100644 --- a/packages/babel-plugin-transform-react-jsx/src/index.js +++ b/packages/babel-plugin-transform-react-jsx/src/index.js @@ -1,10 +1,10 @@ export default function ({ types: t }) { - var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/; + let JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/; - var visitor = require("babel-plugin-builder-react-jsx")(t, { + let visitor = require("babel-helper-builder-react-jsx")({ pre(state) { - var tagName = state.tagName; - var args = state.args; + let tagName = state.tagName; + let args = state.args; if (t.react.isCompatTag(tagName)) { args.push(t.stringLiteral(tagName)); } else { @@ -12,17 +12,17 @@ export default function ({ types: t }) { } }, - post(state, file) { - state.callee = file.get("jsxIdentifier"); + post(state, pass) { + state.callee = pass.get("jsxIdentifier"); } }); - visitor.Program = function (path, file) { - var id = "React.createElement"; // todo: jsxPragma; + visitor.Program = function (path, state) { + let { file } = state; + let id = state.opts.pragma || "React.createElement"; - for (var i = 0; i < file.ast.comments.length; i++) { - var comment = file.ast.comments[i]; - var matches = JSX_ANNOTATION_REGEX.exec(comment.value); + for (let comment of (file.ast.comments: Array)) { + let matches = JSX_ANNOTATION_REGEX.exec(comment.value); if (matches) { id = matches[1]; if (id === "React.DOM") { @@ -33,10 +33,13 @@ export default function ({ types: t }) { } } - file.set("jsxIdentifier", id.split(".").map(t.identifier).reduce(function (object, property) { + state.set("jsxIdentifier", id.split(".").map(t.identifier).reduce(function (object, property) { return t.memberExpression(object, property); })); }; - return { visitor }; + return { + inherits: require("babel-plugin-syntax-jsx"), + visitor + }; } diff --git a/packages/babel-plugin-transform-regenerator/index.js b/packages/babel-plugin-transform-regenerator/index.js new file mode 100644 index 0000000000..0586da9ec7 --- /dev/null +++ b/packages/babel-plugin-transform-regenerator/index.js @@ -0,0 +1 @@ +module.exports = require("../../../regenerator"); diff --git a/packages/babel-plugin-transform-regenerator/package.json b/packages/babel-plugin-transform-regenerator/package.json new file mode 100644 index 0000000000..f5091bec5c --- /dev/null +++ b/packages/babel-plugin-transform-regenerator/package.json @@ -0,0 +1,3 @@ +{ + "name": "babel-plugin-transform-regenerator" +} diff --git a/packages/babel-plugin-transform-remove-console/package.json b/packages/babel-plugin-transform-remove-console/package.json index b1d9454631..246338dc8b 100644 --- a/packages/babel-plugin-transform-remove-console/package.json +++ b/packages/babel-plugin-transform-remove-console/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-remove-console", - "version": "1.0.1", + "version": "5.10.32", "description": "Remove console.* calls", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-remove-debugger/package.json b/packages/babel-plugin-transform-remove-debugger/package.json index 617db3e12a..bbb9c36021 100644 --- a/packages/babel-plugin-transform-remove-debugger/package.json +++ b/packages/babel-plugin-transform-remove-debugger/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-remove-debugger", - "version": "1.0.1", + "version": "5.10.32", "description": "Remove debugger statements", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-runtime/package.json b/packages/babel-plugin-transform-runtime/package.json index 868b737c51..136ef26eb3 100644 --- a/packages/babel-plugin-transform-runtime/package.json +++ b/packages/babel-plugin-transform-runtime/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-transform-runtime", - "version": "1.0.7", + "version": "5.10.32", "description": "Externalise references to helpers and builtins, automatically polyfilling your code without polluting globals", "repository": "babel/babel", "license": "MIT", @@ -9,6 +9,6 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^5.8.20" + "babel-runtime": "^5.10.32" } -} +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-runtime/src/index.js b/packages/babel-plugin-transform-runtime/src/index.js index a80feb0d23..235a1bb51d 100644 --- a/packages/babel-plugin-transform-runtime/src/index.js +++ b/packages/babel-plugin-transform-runtime/src/index.js @@ -8,20 +8,23 @@ export default function ({ types: t }) { } return { - pre(file) { - file.set("helperGenerator", function (name) { - return file.addImport(`${RUNTIME_MODULE_NAME}/helpers/${name}`, name, "absoluteDefault"); + pre(file, state) { + state.set("helperGenerator", function (name) { + return state.addImport(`${RUNTIME_MODULE_NAME}/helpers/${name}`, "default", name); }); - file.setDynamic("regeneratorIdentifier", function () { - return file.addImport(`${RUNTIME_MODULE_NAME}/regenerator`, "regeneratorRuntime", "absoluteDefault"); + state.setDynamic("regeneratorIdentifier", function () { + return state.addImport(`${RUNTIME_MODULE_NAME}/regenerator`, "default", "regeneratorRuntime"); }); }, visitor: { - ReferencedIdentifier({ node, parent, scope }, file) { + ReferencedIdentifier(path, state) { + let { node, parent, scope } = path; + if (node.name === "regeneratorRuntime") { - return file.get("regeneratorIdentifier"); + path.replaceWith(state.get("regeneratorIdentifier")); + return; } if (t.isMemberExpression(parent)) return; @@ -29,56 +32,65 @@ export default function ({ types: t }) { if (scope.getBindingIdentifier(node.name)) return; // Symbol() -> _core.Symbol(); new Promise -> new _core.Promise - var modulePath = definitions.builtins[node.name]; - return file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, node.name, "absoluteDefault"); + path.replaceWith(state.addImport( + `${RUNTIME_MODULE_NAME}/core-js/${definitions.builtins[node.name]}`, + "default", + node.name + )); }, - CallExpression(path, file) { + CallExpression(path, state) { // arr[Symbol.iterator]() -> _core.$for.getIterator(arr) // we can't compile this if (path.node.arguments.length) return; - var callee = path.node.callee; + let callee = path.node.callee; if (!t.isMemberExpression(callee)) return; if (!callee.computed) return; if (!path.get("callee.property").matchesPattern("Symbol.iterator")) return; - return t.callExpression( - file.addImport(`${RUNTIME_MODULE_NAME}/core-js/get-iterator`, "getIterator", "absoluteDefault"), + path.replaceWith(t.callExpression( + state.addImport( + `${RUNTIME_MODULE_NAME}/core-js/get-iterator`, + "default", + "getIterator" + ), [callee.object] - ); + )); }, - BinaryExpression(path, file) { + BinaryExpression(path, state) { // Symbol.iterator in arr -> core.$for.isIterable(arr) if (path.node.operator !== "in") return; if (!path.get("left").matchesPattern("Symbol.iterator")) return; - return t.callExpression( - file.addImport(`${RUNTIME_MODULE_NAME}/core-js/is-iterable`, "isIterable", "absoluteDefault"), + path.replaceWith(t.callExpression( + state.addImport( + `${RUNTIME_MODULE_NAME}/core-js/is-iterable`, + "default", + "isIterable" + ), [path.node.right] - ); + )); }, MemberExpression: { - enter(path, file) { - // Array.from -> _core.Array.from - + enter(path, state) { if (!path.isReferenced()) return; - var { node } = path; - var obj = node.object; - var prop = node.property; + // Array.from -> _core.Array.from + + let { node } = path; + let obj = node.object; + let prop = node.property; if (!t.isReferenced(obj, node)) return; - if (node.computed) return; - if (!has(definitions.methods, obj.name)) return; - var methods = definitions.methods[obj.name]; + let methods = definitions.methods[obj.name]; if (!has(methods, prop.name)) return; // doesn't reference the global @@ -86,28 +98,35 @@ export default function ({ types: t }) { // special case Object.defineProperty to not use core-js when using string keys if (obj.name === "Object" && prop.name === "defineProperty" && path.parentPath.isCallExpression()) { - var call = path.parentPath.node; + let call = path.parentPath.node; if (call.arguments.length === 3 && t.isLiteral(call.arguments[1])) return; } - var modulePath = methods[prop.name]; - return file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, `${obj.name}$${prop.name}`, "absoluteDefault"); + path.replaceWith(state.addImport( + `${RUNTIME_MODULE_NAME}/core-js/${methods[prop.name]}`, + "default", + `${obj.name}$${prop.name}` + )); }, - exit(path, file) { + exit(path, state) { if (!path.isReferenced()) return; - var prop = path.node.property; - var obj = path.node.object; + let { node } = path; + let obj = node.object; if (!has(definitions.builtins, obj.name)) return; if (path.scope.getBindingIdentifier(obj.name)) return; - var modulePath = definitions.builtins[obj.name]; - return t.memberExpression( - file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, `${obj.name}`, "absoluteDefault"), - prop - ); + path.replaceWith(t.memberExpression( + state.addImport( + `${RUNTIME_MODULE_NAME}/core-js/${definitions.builtins[obj.name]}`, + "default", + obj.name + ), + node.property, + node.computed + )); } } } diff --git a/packages/babel-plugin-transform-simplify-comparison-operators/package.json b/packages/babel-plugin-transform-simplify-comparison-operators/package.json index 5d926d90bf..8045c44cd3 100644 --- a/packages/babel-plugin-transform-simplify-comparison-operators/package.json +++ b/packages/babel-plugin-transform-simplify-comparison-operators/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-simplify-comparison-operators", - "version": "1.0.2", + "version": "5.10.32", "description": "Convert === and !== to == and != if their types are inferred to be the same.", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-simplify-comparison-operators/src/index.js b/packages/babel-plugin-transform-simplify-comparison-operators/src/index.js index 88b311e1a7..e50122cafd 100644 --- a/packages/babel-plugin-transform-simplify-comparison-operators/src/index.js +++ b/packages/babel-plugin-transform-simplify-comparison-operators/src/index.js @@ -2,11 +2,11 @@ export default function () { return { visitor: { BinaryExpression(node) { - var op = node.operator; + let op = node.operator; if (op !== "===" && op !== "!==") return; - var left = this.get("left"); - var right = this.get("right"); + let left = this.get("left"); + let right = this.get("right"); if (left.baseTypeStrictlyMatches(right)) { node.operator = node.operator.slice(0, -1); } diff --git a/packages/babel-plugin-transform-strict-mode/README.md b/packages/babel-plugin-transform-strict-mode/README.md new file mode 100644 index 0000000000..a47e06aa94 --- /dev/null +++ b/packages/babel-plugin-transform-strict-mode/README.md @@ -0,0 +1,35 @@ +# babel-plugin-transform-strict-mode + +TODO + +## Installation + +```sh +$ npm install babel-plugin-transform-strict-mode +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-strict-mode"] +} +``` + +### Via CLI + +```sh +$ babel --plugins transform-strict-mode script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-strict-mode"] +}); +``` diff --git a/packages/babel-plugin-transform-strict-mode/package.json b/packages/babel-plugin-transform-strict-mode/package.json new file mode 100644 index 0000000000..8fdd3022d6 --- /dev/null +++ b/packages/babel-plugin-transform-strict-mode/package.json @@ -0,0 +1,15 @@ +{ + "name": "babel-plugin-transform-strict-mode", + "version": "1.0.0", + "description": "TODO", + "repository": "babel/babel", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "babel-runtime": "^5.0.0", + "babel-types": "^6.0.0" + } +} diff --git a/packages/babel-plugin-transform-strict-mode/src/index.js b/packages/babel-plugin-transform-strict-mode/src/index.js new file mode 100644 index 0000000000..1c694818cb --- /dev/null +++ b/packages/babel-plugin-transform-strict-mode/src/index.js @@ -0,0 +1,17 @@ +import * as t from "babel-types"; + +export default function () { + return { + visitor: { + Program(path) { + let { node } = path; + + for (let directive of (node.directives: Array)) { + if (directive.value.value === "use strict") return; + } + + path.unshiftContainer("directives", t.directive(t.directiveLiteral("use strict"))); + } + } + }; +} diff --git a/packages/babel-plugin-transform-undeclared-variables-check/.npmignore b/packages/babel-plugin-transform-undeclared-variables-check/.npmignore deleted file mode 100644 index cace0d6ddc..0000000000 --- a/packages/babel-plugin-transform-undeclared-variables-check/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -*.log -src diff --git a/packages/babel-plugin-transform-undeclared-variables-check/README.md b/packages/babel-plugin-transform-undeclared-variables-check/README.md deleted file mode 100644 index cddd56313d..0000000000 --- a/packages/babel-plugin-transform-undeclared-variables-check/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# babel-plugin-transform-undeclared-variables-check - -Throw a compile-time error on references to undeclared variables - -## Installation - -```sh -$ npm install babel-plugin-transform-undeclared-variables-check -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["transform-undeclared-variables-check"] -} -``` - -### Via CLI - -```sh -$ babel --plugins transform-undeclared-variables-check script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["transform-undeclared-variables-check"] -}); -``` diff --git a/packages/babel-plugin-transform-undefined-to-void/package.json b/packages/babel-plugin-transform-undefined-to-void/package.json index 888423f34b..9b4079864e 100644 --- a/packages/babel-plugin-transform-undefined-to-void/package.json +++ b/packages/babel-plugin-transform-undefined-to-void/package.json @@ -1,11 +1,14 @@ { "name": "babel-plugin-transform-undefined-to-void", - "version": "1.1.6", + "version": "5.10.32", "description": "Replace references to `undefined` with `void 0`", "repository": "babel/babel", "license": "MIT", "main": "lib/index.js", "keywords": [ "babel-plugin" - ] -} + ], + "dependencies": { + "babel-runtime": "^5.10.32" + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-undefined-to-void/src/index.js b/packages/babel-plugin-transform-undefined-to-void/src/index.js index 593d7bea3d..37266769e9 100644 --- a/packages/babel-plugin-transform-undefined-to-void/src/index.js +++ b/packages/babel-plugin-transform-undefined-to-void/src/index.js @@ -1,9 +1,9 @@ export default function ({ types: t }) { return { visitor: { - ReferencedIdentifier(node) { - if (node.name === "undefined") { - return t.unaryExpression("void", t.numberLiteral(0), true); + ReferencedIdentifier(path) { + if (path.node.name === "undefined") { + path.replaceWith(t.unaryExpression("void", t.numberLiteral(0), true)); } } } diff --git a/packages/babel-plugin-transform-es2015-tail-call/.npmignore b/packages/babel-plugin-undeclared-variables-check/.npmignore similarity index 100% rename from packages/babel-plugin-transform-es2015-tail-call/.npmignore rename to packages/babel-plugin-undeclared-variables-check/.npmignore diff --git a/packages/babel-plugin-undeclared-variables-check/README.md b/packages/babel-plugin-undeclared-variables-check/README.md new file mode 100644 index 0000000000..8051e67a12 --- /dev/null +++ b/packages/babel-plugin-undeclared-variables-check/README.md @@ -0,0 +1,35 @@ +# babel-plugin-undeclared-variables-check + +Throw a compile-time error on references to undeclared variables + +## Installation + +```sh +$ npm install babel-plugin-undeclared-variables-check +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["undeclared-variables-check"] +} +``` + +### Via CLI + +```sh +$ babel --plugins undeclared-variables-check script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["undeclared-variables-check"] +}); +``` diff --git a/packages/babel-plugin-transform-undeclared-variables-check/package.json b/packages/babel-plugin-undeclared-variables-check/package.json similarity index 68% rename from packages/babel-plugin-transform-undeclared-variables-check/package.json rename to packages/babel-plugin-undeclared-variables-check/package.json index 82cbe2499e..c631bac703 100644 --- a/packages/babel-plugin-transform-undeclared-variables-check/package.json +++ b/packages/babel-plugin-undeclared-variables-check/package.json @@ -1,6 +1,6 @@ { - "name": "babel-plugin-transform-undeclared-variables-check", - "version": "1.0.2", + "name": "babel-plugin-undeclared-variables-check", + "version": "6.0.6", "description": "Throw a compile-time error on references to undeclared variables", "repository": "babel/babel", "license": "MIT", @@ -9,7 +9,7 @@ "babel-plugin" ], "dependencies": { - "babel-runtime": "^5.8.20", + "babel-runtime": "^6.0.6", "leven": "^1.0.2" } } diff --git a/packages/babel-plugin-transform-undeclared-variables-check/src/index.js b/packages/babel-plugin-undeclared-variables-check/src/index.js similarity index 74% rename from packages/babel-plugin-transform-undeclared-variables-check/src/index.js rename to packages/babel-plugin-undeclared-variables-check/src/index.js index 4ce2f590f7..a6400dd8c7 100644 --- a/packages/babel-plugin-transform-undeclared-variables-check/src/index.js +++ b/packages/babel-plugin-undeclared-variables-check/src/index.js @@ -1,12 +1,12 @@ -import levenshtein from "leven"; +import leven from "leven"; export default function ({ messages }) { return { visitor: { ReferencedIdentifier(path) { - var { node, scope } = path; + let { node, scope } = path; - var binding = scope.getBinding(node.name); + let binding = scope.getBinding(node.name); if (binding && binding.kind === "type" && !path.parentPath.isFlow()) { throw path.buildCodeFrameError(messages.get("undeclaredVariableType", node.name), ReferenceError); } @@ -16,13 +16,13 @@ export default function ({ messages }) { // get the closest declaration to offer as a suggestion // the variable name may have just been mistyped - var bindings = scope.getAllBindings(); + let bindings = scope.getAllBindings(); - var closest; - var shortest = -1; + let closest; + let shortest = -1; - for (var name in bindings) { - var distance = levenshtein(node.name, name); + for (let name in bindings) { + let distance = leven(node.name, name); if (distance <= 0 || distance > 3) continue; if (distance <= shortest) continue; @@ -30,7 +30,7 @@ export default function ({ messages }) { shortest = distance; } - var msg; + let msg; if (closest) { msg = messages.get("undeclaredVariableSuggestion", node.name, closest); } else { diff --git a/packages/babel-polyfill/package.json b/packages/babel-polyfill/package.json index 2dca2a1d4f..75cee24fc1 100644 --- a/packages/babel-polyfill/package.json +++ b/packages/babel-polyfill/package.json @@ -1,6 +1,6 @@ { "name": "babel-polyfill", - "version": "5.8.22", + "version": "5.10.32", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -9,6 +9,7 @@ "main": "lib/index.js", "dependencies": { "core-js": "^1.0.1", - "regenerator": "^0.8.36" + "regenerator": "^0.8.36", + "babel-runtime": "^5.10.32" } -} +} \ No newline at end of file diff --git a/packages/babel-polyfill/scripts/build-dist.sh b/packages/babel-polyfill/scripts/build-dist.sh old mode 100644 new mode 100755 index d2b3b9bd13..38f8477688 --- a/packages/babel-polyfill/scripts/build-dist.sh +++ b/packages/babel-polyfill/scripts/build-dist.sh @@ -1,10 +1,17 @@ #!/bin/sh -set -e +set -ex BROWSERIFY_CMD="../../node_modules/browserify/bin/cmd.js" UGLIFY_CMD="../../node_modules/uglify-js/bin/uglifyjs" mkdir -p dist -node $BROWSERIFY_CMD -e lib/index.js >dist/polyfill.js -node $UGLIFY_CMD dist/index.js >dist/polyfill.min.js +node $BROWSERIFY_CMD lib/index.js \ + --insert-global-vars 'global' \ + --plugin bundle-collapser/plugin \ + --plugin derequire/plugin \ + >dist/polyfill.js +node $UGLIFY_CMD dist/polyfill.js \ + --compress warnings=false \ + --mangle \ + >dist/polyfill.min.js diff --git a/packages/babel-preset-es2015/index.js b/packages/babel-preset-es2015/index.js index 6288b3ee72..fec29c3586 100644 --- a/packages/babel-preset-es2015/index.js +++ b/packages/babel-preset-es2015/index.js @@ -17,6 +17,7 @@ module.exports = { require("babel-plugin-transform-es2015-parameters"), require("babel-plugin-transform-es2015-destructuring"), require("babel-plugin-transform-es2015-block-scoping"), - require("babel-plugin-transform-es2015-tail-call") + require("babel-plugin-transform-es2015-typeof-symbol"), + require("babel-plugin-transform-regenerator") ] }; diff --git a/packages/babel-preset-es2015/package.json b/packages/babel-preset-es2015/package.json index cbd48902d6..de055a6b81 100644 --- a/packages/babel-preset-es2015/package.json +++ b/packages/babel-preset-es2015/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-es2015", - "version": "5.8.22", + "version": "5.10.32", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,23 +8,24 @@ "repository": "babel/babel", "main": "index.js", "dependencies": { - "babel-plugin-transform-es2015-template-literals": "*", - "babel-plugin-transform-es2015-literals": "*", - "babel-plugin-transform-es2015-function-name": "*", - "babel-plugin-transform-es2015-arrow-functions": "*", - "babel-plugin-transform-es2015-block-scoped-functions": "*", - "babel-plugin-transform-es2015-classes": "*", - "babel-plugin-transform-es2015-object-super": "*", - "babel-plugin-transform-es2015-shorthand-properties": "*", - "babel-plugin-transform-es2015-computed-properties": "*", - "babel-plugin-transform-es2015-for-of": "*", - "babel-plugin-transform-es2015-sticky-regex": "*", - "babel-plugin-transform-es2015-unicode-regex": "*", - "babel-plugin-transform-es2015-constants": "*", - "babel-plugin-transform-es2015-spread": "*", - "babel-plugin-transform-es2015-parameters": "*", - "babel-plugin-transform-es2015-destructuring": "*", - "babel-plugin-transform-es2015-block-scoping": "*", - "babel-plugin-transform-es2015-tail-call": "*" + "babel-plugin-transform-es2015-template-literals": "^5.10.32", + "babel-plugin-transform-es2015-literals": "^5.10.32", + "babel-plugin-transform-es2015-function-name": "^5.10.32", + "babel-plugin-transform-es2015-arrow-functions": "^5.10.32", + "babel-plugin-transform-es2015-block-scoped-functions": "^5.10.32", + "babel-plugin-transform-es2015-classes": "^5.10.32", + "babel-plugin-transform-es2015-object-super": "^5.10.32", + "babel-plugin-transform-es2015-shorthand-properties": "^5.10.32", + "babel-plugin-transform-es2015-computed-properties": "^5.10.32", + "babel-plugin-transform-es2015-for-of": "^5.10.32", + "babel-plugin-transform-es2015-sticky-regex": "^5.10.32", + "babel-plugin-transform-es2015-unicode-regex": "^5.10.32", + "babel-plugin-transform-es2015-constants": "^5.10.32", + "babel-plugin-transform-es2015-spread": "^5.10.32", + "babel-plugin-transform-es2015-parameters": "^5.10.32", + "babel-plugin-transform-es2015-destructuring": "^5.10.32", + "babel-plugin-transform-es2015-block-scoping": "^5.10.32", + "babel-plugin-transform-es2015-typeof-symbol": "^5.0.0", + "babel-plugin-transform-regenerator": "^5.0.0" } -} +} \ No newline at end of file diff --git a/packages/babel-preset-react/index.js b/packages/babel-preset-react/index.js index 864093b2b6..b488ccb658 100644 --- a/packages/babel-preset-react/index.js +++ b/packages/babel-preset-react/index.js @@ -1,6 +1,7 @@ module.exports = { plugins: [ require("babel-plugin-transform-react-jsx"), + require("babel-plugin-transform-flow-strip-types"), require("babel-plugin-syntax-flow"), require("babel-plugin-syntax-jsx"), ] diff --git a/packages/babel-preset-react/package.json b/packages/babel-preset-react/package.json index 055ed78977..c798996ca9 100644 --- a/packages/babel-preset-react/package.json +++ b/packages/babel-preset-react/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-react", - "version": "5.8.22", + "version": "5.10.32", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,8 +8,9 @@ "repository": "babel/babel", "main": "index.js", "dependencies": { - "babel-plugin-syntax-flow": "*", - "babel-plugin-syntax-jsx": "*", - "babel-plugin-transform-react-jsx": "*" + "babel-plugin-syntax-flow": "^5.10.32", + "babel-plugin-syntax-jsx": "^5.10.32", + "babel-plugin-transform-react-jsx": "^5.10.32", + "babel-plugin-transform-flow-strip-types": "^5.10.32" } -} +} \ No newline at end of file diff --git a/packages/babel-runtime/package.json b/packages/babel-runtime/package.json index 6a58f82a5d..536a79b34c 100644 --- a/packages/babel-runtime/package.json +++ b/packages/babel-runtime/package.json @@ -1,6 +1,6 @@ { "name": "babel-runtime", - "version": "5.8.20", + "version": "5.10.32", "description": "babel selfContained runtime", "license": "MIT", "repository": "babel/babel", @@ -9,7 +9,9 @@ "core-js": "^1.0.0" }, "devDependencies": { + "babel-helpers": "^1.0.7", "babel-plugin-runtime": "^1.0.7", + "babel-template": "^5.10.32", "regenerator": "^0.8.34" } } \ No newline at end of file diff --git a/packages/babel-runtime/scripts/build-dist.js b/packages/babel-runtime/scripts/build-dist.js index 0196386b89..df8357d9df 100644 --- a/packages/babel-runtime/scripts/build-dist.js +++ b/packages/babel-runtime/scripts/build-dist.js @@ -1,7 +1,8 @@ var outputFile = require("output-file-sync"); -var transform = require("../../babel-core/lib/transformation"); +var template = require("babel-template"); +var helpers = require("babel-helpers"); +var babel = require("../../babel-core"); var each = require("lodash/collection/each"); -var File = require("../../babel-core/lib/transformation/file"); var util = require("../../babel-core/lib/util"); var fs = require("fs"); var t = require("../../babel-types"); @@ -31,30 +32,38 @@ function writeRootFile(filename, content) { outputFile(filename, content); } +var buildHelperHead = template("exports.default = HELPER; exports.__esModule = true;"); function writeFile(filename, content) { return writeRootFile(filename, content); } +var transformOpts = { + presets: [ + require("../../babel-preset-es2015") + ], + + plugins: [ + require("../../babel-plugin-transform-runtime"), + require("../../babel-plugin-transform-es2015-modules-commonjs") + ] +}; + function selfContainify(code) { - return transform(code, { - optional: ["runtime"] - }).code; + return babel.transform(code, transformOpts).code; } function buildHelper(helperName) { var tree = t.program( - util.template("self-contained-helpers-head", { - HELPER: util.template("helper-" + helperName) + buildHelperHead({ + HELPER: helpers.get(helperName) }) ); - return transform.fromAst(tree, null, { - optional: ["runtime"] - }).code; + return babel.transformFromAst(tree, null, transformOpts).code; } -each(File.helpers, function (helperName) { +each(helpers.list, function (helperName) { writeFile("helpers/" + helperName + ".js", buildHelper(helperName)); }); diff --git a/packages/babel-template/package.json b/packages/babel-template/package.json index 49803acbe8..28dc25b1ab 100644 --- a/packages/babel-template/package.json +++ b/packages/babel-template/package.json @@ -1,6 +1,6 @@ { "name": "babel-template", - "version": "5.8.22", + "version": "5.10.32", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,9 +8,10 @@ "repository": "babel/babel", "main": "lib/index.js", "dependencies": { - "babylon": "^5.8.20", - "babel-traverse": "^5.8.22", - "babel-types": "^5.8.22", + "babylon": "^5.10.32", + "babel-traverse": "^5.10.32", + "babel-types": "^5.10.32", + "babel-runtime": "^5.10.32", "lodash": "^3.10.1" } -} +} \ No newline at end of file diff --git a/packages/babel-template/src/index.js b/packages/babel-template/src/index.js index 99f3c83c79..c011d71fac 100644 --- a/packages/babel-template/src/index.js +++ b/packages/babel-template/src/index.js @@ -1,22 +1,31 @@ +/* @flow */ + import cloneDeep from "lodash/lang/cloneDeep"; -import isEmpty from "lodash/lang/isEmpty"; import has from "lodash/object/has"; import traverse from "babel-traverse"; import * as babylon from "babylon"; import * as t from "babel-types"; -export default function (code) { - var stack = new Error().stack.split("\n").slice(1).join("\n"); +let TEMPLATE_SKIP = Symbol(); + +export default function (code: string): Function { + // since we lazy parse the template, we get the current stack so we have the + // original stack to append if it errors when parsing + let stack = new Error().stack.split("\n").slice(1).join("\n"); + + let getAst = function () { + let ast; - var getAst = function () { try { - var ast = babylon.parse(code, { - allowReturnOutsideFunction: true - }).program; + ast = babylon.parse(code, { + allowReturnOutsideFunction: true, + allowSuperOutsideMethod: true + }); ast = traverse.removeProperties(ast); } catch (err) { err.stack = `${err.stack}from\n${stack}`; + throw err; } getAst = function () { @@ -26,49 +35,56 @@ export default function (code) { return ast; }; - return function (nodes, keepExpression) { - return useTemplate(getAst(), nodes, keepExpression); + return function (...args) { + return useTemplate(getAst(), args); }; } -function useTemplate(ast, nodes?: Array, keepExpression?: boolean) { - if (nodes === true) { - keepExpression = true; - nodes = null; - } - +function useTemplate(ast, nodes?: Array) { ast = cloneDeep(ast); + let { program } = ast; - if (!isEmpty(nodes)) { + if (nodes.length) { traverse(ast, templateVisitor, null, nodes); } - if (ast.body.length > 1) { - return ast.body; - } - - var node = ast.body[0]; - if (!keepExpression && t.isExpressionStatement(node)) { - return node.expression; + if (program.body.length > 1) { + return program.body; } else { - return node; + return program.body[0]; } } -var templateVisitor = { +let templateVisitor = { // 360 noScope: true, - enter(path, nodes) { - var { node } = path; + enter(path, args) { + let { node } = path; + if (node[TEMPLATE_SKIP]) return path.skip(); if (t.isExpressionStatement(node)) { node = node.expression; } - if (t.isIdentifier(node) && has(nodes, node.name)) { - path.skip(); - path.replaceInline(nodes[node.name]); + let replacement; + + if (t.isIdentifier(node)) { + if (has(args[0], node.name)) { + replacement = args[0][node.name]; + } else if (node.name[0] === "$") { + let i = +node.name.slice(1); + if (args[i]) replacement = args[i]; + } + } + + if (replacement === null) { + path.remove(); + } + + if (replacement) { + replacement[TEMPLATE_SKIP] = true; + path.replaceInline(replacement); } }, diff --git a/packages/babel-traverse/package.json b/packages/babel-traverse/package.json index 8994c73192..5aad190ad1 100644 --- a/packages/babel-traverse/package.json +++ b/packages/babel-traverse/package.json @@ -1,6 +1,6 @@ { "name": "babel-traverse", - "version": "5.8.22", + "version": "5.10.32", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,12 +8,14 @@ "repository": "babel/babel", "main": "lib/index.js", "dependencies": { - "babel-code-frame": "^5.8.22", + "babel-code-frame": "^5.10.32", + "babel-messages": "^5.10.32", + "babel-runtime": "^5.10.32", + "babel-types": "^5.10.32", + "babylon": "^5.10.32", "globals": "^8.3.0", + "invariant": "^2.1.0", "lodash": "^3.10.1", - "repeating": "^1.1.3", - "babel-types": "^5.8.22", - "babel-messages": "^5.8.22", - "babylon": "^5.8.22" + "repeating": "^1.1.3" } -} +} \ No newline at end of file diff --git a/packages/babel-traverse/src/context.js b/packages/babel-traverse/src/context.js index 6fa70d022f..ea9f1e56dc 100644 --- a/packages/babel-traverse/src/context.js +++ b/packages/babel-traverse/src/context.js @@ -1,6 +1,10 @@ +/* @flow */ + import NodePath from "./path"; import * as t from "babel-types"; +let testing = process.env.NODE_ENV === "test"; + export default class TraversalContext { constructor(scope, opts, state, parentPath) { this.parentPath = parentPath; @@ -9,57 +13,101 @@ export default class TraversalContext { this.opts = opts; } - queue = null; + parentPath: NodePath; + scope; + state; + opts; + queue: ?Array = null; - shouldVisit(node) { - var opts = this.opts; + /** + * This method does a simple check to determine whether or not we really need to attempt + * visit a node. This will prevent us from constructing a NodePath. + */ + + shouldVisit(node): boolean { + let opts = this.opts; if (opts.enter || opts.exit) return true; + // check if we have a visitor for this node if (opts[node.type]) return true; - var keys = t.VISITOR_KEYS[node.type]; + // check if we're going to traverse into this node + let keys: ?Array = t.VISITOR_KEYS[node.type]; if (!keys || !keys.length) return false; - for (var key of (keys: Array)) { + // we need to traverse into this node so ensure that it has children to traverse into! + for (let key of keys) { if (node[key]) return true; } return false; } - create(node, obj, key, listKey) { - var path = NodePath.get({ + create(node, obj, key, listKey): NodePath { + return NodePath.get({ parentPath: this.parentPath, parent: node, container: obj, key: key, listKey }); - path.unshiftContext(this); - return path; + } + + maybeQueue(path) { + if (this.trap) { + throw new Error("Infinite cycle detected"); + } + + if (this.queue) { + this.priorityQueue.push(path); + } } visitMultiple(container, parent, listKey) { // nothing to traverse! if (container.length === 0) return false; - var visited = []; - - var queue = this.queue = []; - var stop = false; + let queue = []; // build up initial queue for (let key = 0; key < container.length; key++) { - var self = container[key]; - if (self && this.shouldVisit(self)) { + let node = container[key]; + if (node && this.shouldVisit(node)) { queue.push(this.create(parent, container, key, listKey)); } } - // visit the queue - for (let path of (queue: Array)) { - path.resync(); + return this.visitQueue(queue); + } + visitSingle(node, key): boolean { + if (this.shouldVisit(node[key])) { + return this.visitQueue([ + this.create(node, node, key) + ]); + } else { + return false; + } + } + + visitQueue(queue: Array) { + // set queue + this.queue = queue; + this.priorityQueue = []; + + let visited = []; + let stop = false; + + // visit the queue + for (let path of queue) { + path.resync(); + path.pushContext(this); + + if (testing && queue.length >= 1000) { + this.trap = true; + } + + // ensure we don't visit the same node twice if (visited.indexOf(path.node) >= 0) continue; visited.push(path.node); @@ -67,28 +115,29 @@ export default class TraversalContext { stop = true; break; } + + if (this.priorityQueue.length) { + stop = this.visitQueue(this.priorityQueue); + this.priorityQueue = []; + this.queue = queue; + if (stop) break; + } } - for (let path of (queue: Array)) { - path.shiftContext(); + // clear queue + for (let path of queue) { + path.popContext(); } + // clear queue this.queue = null; return stop; } - visitSingle(node, key) { - if (this.shouldVisit(node[key])) { - var path = this.create(node, node, key); - path.visit(); - path.shiftContext(); - } - } - visit(node, key) { - var nodes = node[key]; - if (!nodes) return; + let nodes = node[key]; + if (!nodes) return false; if (Array.isArray(nodes)) { return this.visitMultiple(nodes, node, key); diff --git a/packages/babel-traverse/src/hub.js b/packages/babel-traverse/src/hub.js index f1b0fb0243..9c204d5e54 100644 --- a/packages/babel-traverse/src/hub.js +++ b/packages/babel-traverse/src/hub.js @@ -1,6 +1,4 @@ -/** - * [Please add a description.] - */ +/* @flow */ export default class Hub { constructor(file, options) { diff --git a/packages/babel-traverse/src/index.js b/packages/babel-traverse/src/index.js index 6209d197a2..1f058919c3 100644 --- a/packages/babel-traverse/src/index.js +++ b/packages/babel-traverse/src/index.js @@ -1,10 +1,23 @@ +/* @flow */ + import TraversalContext from "./context"; import * as visitors from "./visitors"; import * as messages from "babel-messages"; import includes from "lodash/collection/includes"; import * as t from "babel-types"; -export default function traverse(parent: Object, opts?: Object, scope?: Object, state: Object, parentPath: Object) { +export { default as NodePath } from "./path"; +export { default as Scope } from "./scope"; +export { default as Hub } from "./hub"; +export { visitors }; + +export default function traverse( + parent: Object | Array, + opts?: Object, + scope?: Object, + state: Object, + parentPath: Object, +) { if (!parent) return; if (!opts) opts = {}; @@ -16,14 +29,7 @@ export default function traverse(parent: Object, opts?: Object, scope?: Object, visitors.explode(opts); - // array of nodes - if (Array.isArray(parent)) { - for (var i = 0; i < parent.length; i++) { - traverse.node(parent[i], opts, scope, state, parentPath); - } - } else { - traverse.node(parent, opts, scope, state, parentPath); - } + traverse.node(parent, opts, scope, state, parentPath); } traverse.visitors = visitors; @@ -35,22 +41,32 @@ traverse.Scope = require("./scope"); traverse.Hub = require("./hub"); traverse.cheap = function (node, enter) { - var keys = t.VISITOR_KEYS[node.type]; + if (!node) return; + + let keys = t.VISITOR_KEYS[node.type]; if (!keys) return; enter(node); - for (var key of keys) { - traverse.cheap(node[key], enter); + for (let key of keys) { + let subNode = node[key]; + + if (Array.isArray(subNode)) { + for (let node of subNode) { + traverse.cheap(node, enter); + } + } else { + traverse.cheap(subNode, enter); + } } }; traverse.node = function (node: Object, opts: Object, scope: Object, state: Object, parentPath: Object, skipKeys?) { - var keys: Array = t.VISITOR_KEYS[node.type]; + let keys: Array = t.VISITOR_KEYS[node.type]; if (!keys) return; - var context = new TraversalContext(scope, opts, state, parentPath); - for (var key of keys) { + let context = new TraversalContext(scope, opts, state, parentPath); + for (let key of keys) { if (skipKeys && skipKeys[key]) continue; if (context.visit(node, key)) return; } @@ -64,7 +80,7 @@ const CLEAR_KEYS: Array = t.COMMENT_KEYS.concat([ ]); traverse.clearNode = function (node) { - for (var key of CLEAR_KEYS) { + for (let key of CLEAR_KEYS) { if (node[key] != null) node[key] = undefined; } }; @@ -88,7 +104,7 @@ traverse.hasType = function (tree: Object, scope: Object, type: Object, blacklis // the type we're looking for is the same as the passed node if (tree.type === type) return true; - var state = { + let state = { has: false, type: type }; diff --git a/packages/babel-traverse/src/path/ancestry.js b/packages/babel-traverse/src/path/ancestry.js index e1a1cfeff9..0b0ade4048 100644 --- a/packages/babel-traverse/src/path/ancestry.js +++ b/packages/babel-traverse/src/path/ancestry.js @@ -1,3 +1,5 @@ +/* @flow */ + // This file contains that retrieve or validate anything related to the current paths ancestry. import * as t from "babel-types"; @@ -9,13 +11,25 @@ import NodePath from "./index"; */ export function findParent(callback) { - var path = this; + let path = this; while (path = path.parentPath) { if (callback(path)) return path; } return null; } +/** + * Description + */ + +export function find(callback) { + let path = this; + do { + if (callback(path)) return path; + } while (path = path.parentPath); + return null; +} + /** * Get the parent function of the current path. */ @@ -29,7 +43,7 @@ export function getFunctionParent() { */ export function getStatementParent() { - var path = this; + let path = this; do { if (Array.isArray(path.container)) { return path; @@ -47,11 +61,11 @@ export function getStatementParent() { export function getEarliestCommonAncestorFrom(paths: Array): NodePath { return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) { - var earliest; - var keys = t.VISITOR_KEYS[deepest.type]; + let earliest; + let keys = t.VISITOR_KEYS[deepest.type]; - for (var ancestry of (ancestries: Array)) { - var path = ancestry[i + 1]; + for (let ancestry of (ancestries: Array)) { + let path = ancestry[i + 1]; // first path if (!earliest) { @@ -69,8 +83,8 @@ export function getEarliestCommonAncestorFrom(paths: Array): NodePath } // handle keys - var earliestKeyIndex = keys.indexOf(earliest.parentKey); - var currentKeyIndex = keys.indexOf(path.parentKey); + let earliestKeyIndex = keys.indexOf(earliest.parentKey); + let currentKeyIndex = keys.indexOf(path.parentKey); if (earliestKeyIndex > currentKeyIndex) { // key appears before so it's earlier earliest = path; @@ -97,14 +111,14 @@ export function getDeepestCommonAncestorFrom(paths: Array, filter?: Fu } // minimum depth of the tree so we know the highest node - var minDepth = Infinity; + let minDepth = Infinity; // last common ancestor - var lastCommonIndex, lastCommon; + let lastCommonIndex, lastCommon; // get the ancestors of the path, breaking when the parent exceeds ourselves - var ancestries = paths.map((path) => { - var ancestry = []; + let ancestries = paths.map((path) => { + let ancestry = []; do { ancestry.unshift(path); @@ -119,13 +133,13 @@ export function getDeepestCommonAncestorFrom(paths: Array, filter?: Fu }); // get the first ancestry so we have a seed to assess all other ancestries with - var first = ancestries[0]; + let first = ancestries[0]; // check ancestor equality - depthLoop: for (var i = 0; i < minDepth; i++) { - var shouldMatch = first[i]; + depthLoop: for (let i = 0; i < minDepth; i++) { + let shouldMatch = first[i]; - for (var ancestry of (ancestries: Array)) { + for (let ancestry of (ancestries: Array)) { if (ancestry[i] !== shouldMatch) { // we've hit a snag break depthLoop; @@ -155,8 +169,8 @@ export function getDeepestCommonAncestorFrom(paths: Array, filter?: Fu */ export function getAncestry() { - var path = this; - var paths = []; + let path = this; + let paths = []; do { paths.push(path); } while(path = path.parentPath); @@ -164,9 +178,9 @@ export function getAncestry() { } export function inType() { - var path = this; + let path = this; while (path) { - for (var type of (arguments: Array)) { + for (let type of (arguments: Array)) { if (path.node.type === type) return true; } path = path.parentPath; @@ -180,10 +194,10 @@ export function inType() { */ export function inShadow(key?) { - var path = this; + let path = this; do { if (path.isFunction()) { - var shadow = path.node.shadow; + let shadow = path.node.shadow; if (shadow) { // this is because sometimes we may have a `shadow` value of: // diff --git a/packages/babel-traverse/src/path/comments.js b/packages/babel-traverse/src/path/comments.js index 5c866d0590..06159832c1 100644 --- a/packages/babel-traverse/src/path/comments.js +++ b/packages/babel-traverse/src/path/comments.js @@ -1,3 +1,5 @@ +/* @flow */ + // This file contains methods responsible for dealing with comments. /** @@ -5,15 +7,15 @@ */ export function shareCommentsWithSiblings() { - var node = this.node; + let node = this.node; if (!node) return; - var trailing = node.trailingComments; - var leading = node.leadingComments; + let trailing = node.trailingComments; + let leading = node.leadingComments; if (!trailing && !leading) return; - var prev = this.getSibling(this.key - 1); - var next = this.getSibling(this.key + 1); + let prev = this.getSibling(this.key - 1); + let next = this.getSibling(this.key + 1); if (!prev.node) prev = next; if (!next.node) next = prev; @@ -36,10 +38,10 @@ export function addComment(type, content, line?) { export function addComments(type: string, comments: Array) { if (!comments) return; - var node = this.node; + let node = this.node; if (!node) return; - var key = `${type}Comments`; + let key = `${type}Comments`; if (node[key]) { node[key] = node[key].concat(comments); diff --git a/packages/babel-traverse/src/path/constants.js b/packages/babel-traverse/src/path/constants.js new file mode 100644 index 0000000000..11431edfe4 --- /dev/null +++ b/packages/babel-traverse/src/path/constants.js @@ -0,0 +1 @@ +export const PATH_CACHE_KEY = "_paths"; //Symbol(); diff --git a/packages/babel-traverse/src/path/context.js b/packages/babel-traverse/src/path/context.js index 1a01ccb748..c50f875f1e 100644 --- a/packages/babel-traverse/src/path/context.js +++ b/packages/babel-traverse/src/path/context.js @@ -1,71 +1,69 @@ +/* @flow */ + // This file contains methods responsible for maintaining a TraversalContext. import traverse from "../index"; -export function call(key) { - var node = this.node; - if (!node) return; +export function call(key): boolean { + let opts = this.opts; - var opts = this.opts; - - for (var fns of [opts[key], opts[node.type] && opts[node.type][key]]){ - if (!fns) continue; - - for (var fn of (fns: Array)) { - if (!fn) continue; - - let node = this.node; - if (!node) return; - - var previousType = this.type; - - // call the function with the params (node, parent, scope, state) - var replacement = fn.call(this, this, this.state); - - if (replacement) { - throw new Error("Unexpected return value from visitor method"); - } - - if (this.shouldStop || this.shouldSkip || this.removed) return; - - if (previousType !== this.type) { - this.queueNode(this); - return; - } - } + if (this.node) { + if (this._call(opts[key])) return true; } + + if (this.node) { + return this._call(opts[this.node.type] && opts[this.node.type][key]); + } + + return false; +} + +export function _call(fns?: Array): boolean { + if (!fns) return false; + + for (let fn of fns) { + if (!fn) continue; + + let node = this.node; + if (!node) return true; + + let ret = fn.call(this.state, this, this.state); + if (ret) throw new Error("Unexpected return value from visitor method " + fn); + + // node has been replaced, it will have been requeued + if (this.node !== node) return true; + + if (this.shouldStop || this.shouldSkip || this.removed) return true; + } + + return false; } export function isBlacklisted(): boolean { - var blacklist = this.opts.blacklist; + let blacklist = this.opts.blacklist; return blacklist && blacklist.indexOf(this.node.type) > -1; } export function visit(): boolean { - if (this.isBlacklisted()) return false; - if (this.opts.shouldSkip && this.opts.shouldSkip(this)) return false; + if (!this.node) { + return false; + } - this.call("enter"); + if (this.isBlacklisted()) { + return false; + } - if (this.shouldSkip) { + if (this.opts.shouldSkip && this.opts.shouldSkip(this)) { + return false; + } + + if (this.call("enter") || this.shouldSkip) { return this.shouldStop; } - var node = this.node; - var opts = this.opts; + traverse.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys); - if (node) { - if (Array.isArray(node)) { - // traverse over these replacement nodes we purposely don't call exitNode - // as the original node has been destroyed - for (var i = 0; i < node.length; i++) { - traverse.node(node[i], opts, this.scope, this.state, this, this.skipKeys); - } - } else { - traverse.node(node, opts, this.scope, this.state, this, this.skipKeys); - this.call("exit"); - } - } + this.call("exit"); return this.shouldStop; } @@ -86,8 +84,19 @@ export function stop() { export function setScope() { if (this.opts && this.opts.noScope) return; - var target = this.context || this.parentPath; - this.scope = this.getScope(target && target.scope); + let target = this.context && this.context.scope; + + if (!target) { + let path = this.parentPath; + while (path && !target) { + if (path.opts && path.opts.noScope) return; + + target = path.scope; + path = path.parentPath; + } + } + + this.scope = this.getScope(target); if (this.scope) this.scope.init(); } @@ -138,37 +147,31 @@ export function _resyncKey() { // not done through our path APIs if (Array.isArray(this.container)) { - for (var i = 0; i < this.container.length; i++) { + for (let i = 0; i < this.container.length; i++) { if (this.container[i] === this.node) { return this.setKey(i); } } } else { - for (var key in this.container) { + for (let key in this.container) { if (this.container[key] === this.node) { return this.setKey(key); } } } + // ¯\_(ツ)_/¯ who knows where it's gone lol this.key = null; } export function _resyncList() { - var listKey = this.listKey; - var parentPath = this.parentPath; - if (!listKey || !parentPath || !parentPath.node) return; + if (!this.parent || !this.inList) return; - var newContainer = parentPath.node[listKey]; + let newContainer = this.parent[this.listKey]; if (this.container === newContainer) return; // container is out of sync. this is likely the result of it being reassigned - - if (newContainer) { - this.container = newContainer; - } else { - this.container = null; - } + this.container = newContainer || null; } export function _resyncRemoved() { @@ -177,13 +180,13 @@ export function _resyncRemoved() { } } -export function shiftContext() { - this.contexts.shift(); - this.setContext(this.contexts[0]); +export function popContext() { + this.contexts.pop(); + this.setContext(this.contexts[this.contexts.length - 1]); } -export function unshiftContext(context) { - this.contexts.unshift(context); +export function pushContext(context) { + this.contexts.push(context); this.setContext(context); } @@ -203,10 +206,10 @@ export function setKey(key) { this.type = this.node && this.node.type; } -export function queueNode(path) { - for (var context of (this.contexts: Array)) { - if (context.queue) { - context.queue.push(path); - } +export function requeue(path = this) { + if (path.removed) return; + + for (let context of this.contexts) { + context.maybeQueue(path); } } diff --git a/packages/babel-traverse/src/path/conversion.js b/packages/babel-traverse/src/path/conversion.js index 9a2347cf36..7ebc7d646c 100644 --- a/packages/babel-traverse/src/path/conversion.js +++ b/packages/babel-traverse/src/path/conversion.js @@ -1,21 +1,23 @@ +/* @flow */ + // This file contains methods that convert the path node into another node or some other type of data. import * as t from "babel-types"; export function toComputedKey(): Object { - var node = this.node; + let node = this.node; - var key; + let key; if (this.isMemberExpression()) { key = node.property; - } else if (this.isProperty()) { + } else if (this.isProperty() || this.isMethod()) { key = node.key; } else { throw new ReferenceError("todo"); } if (!node.computed) { - if (t.isIdentifier(key)) key = t.literal(key.name); + if (t.isIdentifier(key)) key = t.stringLiteral(key.name); } return key; @@ -24,3 +26,15 @@ export function toComputedKey(): Object { export function ensureBlock() { return t.ensureBlock(this.node); } + +export function arrowFunctionToShadowed() { + // todo: maybe error + if (!this.isArrowFunctionExpression()) return; + + this.ensureBlock(); + + let { node } = this; + node.expression = false; + node.type = "FunctionExpression"; + node.shadow = node.shadow || true; +} diff --git a/packages/babel-traverse/src/path/evaluation.js b/packages/babel-traverse/src/path/evaluation.js index 5a39f556fd..d03f824c53 100644 --- a/packages/babel-traverse/src/path/evaluation.js +++ b/packages/babel-traverse/src/path/evaluation.js @@ -1,3 +1,7 @@ +/* @flow */ + +import type NodePath from "./index"; + // This file contains Babels metainterpreter that can evaluate static code. /* eslint eqeqeq: 0 */ @@ -24,7 +28,7 @@ const INVALID_METHODS = ["random"]; */ export function evaluateTruthy(): boolean { - var res = this.evaluate(); + let res = this.evaluate(); if (res.confident) return !!res.value; } @@ -44,40 +48,48 @@ export function evaluateTruthy(): boolean { */ export function evaluate(): { confident: boolean; value: any } { - var confident = true; + let confident = true; + let deoptPath: ?NodePath; - var value = evaluate(this); + function deopt(path) { + if (!confident) return; + deoptPath = path; + confident = false; + } + + let value = evaluate(this); if (!confident) value = undefined; return { confident: confident, + deopt: deoptPath, value: value }; function evaluate(path) { if (!confident) return; - var node = path.node; + let { node } = path; if (path.isSequenceExpression()) { let exprs = path.get("expressions"); return evaluate(exprs[exprs.length - 1]); } - if (path.isLiteral()) { - if (node.regex) { - // we have a regex and we can't represent it natively - } else { - return node.value; - } + if (path.isStringLiteral() || path.isNumberLiteral() || path.isBooleanLiteral()) { + return node.value; + } + + if (path.isNullLiteral()) { + return null; } if (path.isTemplateLiteral()) { - var str = ""; + let str = ""; - var i = 0; + let i = 0; let exprs = path.get("expressions"); - for (let elem of (node.quasis: Array)) { + for (let elem of (node.quasis: Array)) { // not confident, evaluated an expression we don't like if (!confident) break; @@ -85,7 +97,7 @@ export function evaluate(): { confident: boolean; value: any } { str += elem.value.cooked; // add on interpolated expression if it's present - var expr = exprs[i++]; + let expr = exprs[i++]; if (expr) str += String(evaluate(expr)); } @@ -100,20 +112,10 @@ export function evaluate(): { confident: boolean; value: any } { } } - if (path.isTypeCastExpression()) { + if (path.isExpressionWrapper()) { // TypeCastExpression, ExpressionStatement etc return evaluate(path.get("expression")); } - if (path.isIdentifier() && !path.scope.hasBinding(node.name, true)) { - if (node.name === "undefined") { - return undefined; - } else if (node.name === "Infinity") { - return Infinity; - } else if (node.name === "NaN") { - return NaN; - } - } - // "foo".length if (path.isMemberExpression() && !path.parentPath.isCallExpression({ callee: node })) { let property = path.get("property"); @@ -129,13 +131,21 @@ export function evaluate(): { confident: boolean; value: any } { } if (path.isReferencedIdentifier()) { - var binding = path.scope.getBinding(node.name); + let binding = path.scope.getBinding(node.name); if (binding && binding.hasValue) { return binding.value; } else { - var resolved = path.resolve(); + if (node.name === "undefined") { + return undefined; + } else if (node.name === "Infinity") { + return Infinity; + } else if (node.name === "NaN") { + return NaN; + } + + let resolved = path.resolve(); if (resolved === path) { - return confident = false; + return deopt(path); } else { return evaluate(resolved); } @@ -143,27 +153,68 @@ export function evaluate(): { confident: boolean; value: any } { } if (path.isUnaryExpression({ prefix: true })) { - var arg = evaluate(path.get("argument")); + if (node.operator === "void") { + // we don't need to evaluate the argument to know what this will return + return undefined; + } + + let argument = path.get("argument"); + if (node.operator === "typeof" && (argument.isFunction() || argument.isClass())) { + return "function"; + } + + let arg = evaluate(argument); switch (node.operator) { - case "void": return undefined; case "!": return !arg; case "+": return +arg; case "-": return -arg; case "~": return ~arg; + case "typeof": return typeof arg; } } - if (path.isArrayExpression() || path.isObjectExpression()) { - // we could evaluate these but it's probably impractical and not very useful + if (path.isArrayExpression()) { + let arr = []; + let elems: Array = path.get("elements"); + for (let elem of elems) { + elem = elem.evaluate(); + + if (elem.confident) { + arr.push(elem.value); + } else { + return deopt(elem); + } + } + return arr; + } + + if (path.isObjectExpression()) { + // todo } if (path.isLogicalExpression()) { + // If we are confident that one side of an && is false, or one side of + // an || is true, we can be confident about the entire expression + let wasConfident = confident; let left = evaluate(path.get("left")); + let leftConfident = confident; + confident = wasConfident; let right = evaluate(path.get("right")); + let rightConfident = confident; + let uncertain = leftConfident !== rightConfident; + confident = leftConfident && rightConfident; switch (node.operator) { - case "||": return left || right; - case "&&": return left && right; + case "||": + if ((left || right) && uncertain) { + confident = true; + } + return left || right; + case "&&": + if ((!left && leftConfident) || (!right && rightConfident)) { + confident = true; + } + return left && right; } } @@ -186,13 +237,19 @@ export function evaluate(): { confident: boolean; value: any } { case "!=": return left != right; case "===": return left === right; case "!==": return left !== right; + case "|": return left | right; + case "&": return left & right; + case "^": return left ^ right; + case "<<": return left << right; + case ">>": return left >> right; + case ">>>": return left >>> right; } } if (path.isCallExpression()) { - var callee = path.get("callee"); - var context; - var func; + let callee = path.get("callee"); + let context; + let func; // Number(1); if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) { @@ -201,7 +258,7 @@ export function evaluate(): { confident: boolean; value: any } { if (callee.isMemberExpression()) { let object = callee.get("object"); - var property = callee.get("property"); + let property = callee.get("property"); // Math.min(1, 2) if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) { @@ -220,13 +277,13 @@ export function evaluate(): { confident: boolean; value: any } { } if (func) { - var args = path.get("arguments").map(evaluate); + let args = path.get("arguments").map(evaluate); if (!confident) return; return func.apply(context, args); } } - confident = false; + deopt(path); } } diff --git a/packages/babel-traverse/src/path/family.js b/packages/babel-traverse/src/path/family.js index 38d57ef3c6..02e862ed49 100644 --- a/packages/babel-traverse/src/path/family.js +++ b/packages/babel-traverse/src/path/family.js @@ -1,3 +1,5 @@ +/* @flow */ + // This file contains methods responsible for dealing with/retrieving children or siblings. import type TraversalContext from "../index"; @@ -5,7 +7,7 @@ import NodePath from "./index"; import * as t from "babel-types"; export function getStatementParent(): ?NodePath { - var path = this; + let path = this; do { if (!path.parentPath || (Array.isArray(path.container) && path.isStatement())) { @@ -31,9 +33,9 @@ export function getOpposite() { } export function getCompletionRecords(): Array { - var paths = []; + let paths = []; - var add = function (path) { + let add = function (path) { if (path) paths = paths.concat(path.getCompletionRecords()); }; @@ -69,7 +71,7 @@ export function getSibling(key) { export function get(key: string, context?: boolean | TraversalContext): NodePath { if (context === true) context = this.context; - var parts = key.split("."); + let parts = key.split("."); if (parts.length === 1) { // "foo" return this._getKey(key, context); } else { // "foo.bar" @@ -78,8 +80,8 @@ export function get(key: string, context?: boolean | TraversalContext): NodePath } export function _getKey(key, context?) { - var node = this.node; - var container = node[key]; + let node = this.node; + let container = node[key]; if (Array.isArray(container)) { // requested a container so give them all the paths @@ -103,8 +105,8 @@ export function _getKey(key, context?) { } export function _getPattern(parts, context) { - var path = this; - for (var part of (parts: Array)) { + let path = this; + for (let part of (parts: Array)) { if (part === ".") { path = path.parentPath; } else { diff --git a/packages/babel-traverse/src/path/index.js b/packages/babel-traverse/src/path/index.js index 14e8c52b5f..1469becd39 100644 --- a/packages/babel-traverse/src/path/index.js +++ b/packages/babel-traverse/src/path/index.js @@ -1,4 +1,9 @@ +/* @flow */ + +import type Hub from "../hub"; +import type TraversalContext from "../context"; import * as virtualTypes from "./lib/virtual-types"; +import { PATH_CACHE_KEY } from "./constants"; import invariant from "invariant"; import traverse from "../index"; import assign from "lodash/object/assign"; @@ -6,45 +11,66 @@ import Scope from "../scope"; import * as t from "babel-types"; export default class NodePath { - - constructor(hub, parent) { + constructor(hub: Hub, parent: Object) { + this.parent = parent; + this.hub = hub; this.contexts = []; - this.parent = parent; - this.data = {}; - this.hub = hub; - - this.shouldSkip = false; - this.shouldStop = false; - this.removed = false; - this.state = null; - this.opts = null; - this.skipKeys = null; - this.parentPath = null; - this.context = null; - this.container = null; - this.listKey = null; - this.inList = false; - this.parentKey = null; - this.key = null; - this.node = null; - this.scope = null; - this.type = null; - this.typeAnnotation = null; + this.data = {}; + this.shouldSkip = false; + this.shouldStop = false; + this.removed = false; + this.state = null; + this.opts = null; + this.skipKeys = null; + this.parentPath = null; + this.context = null; + this.container = null; + this.listKey = null; + this.inList = false; + this.parentKey = null; + this.key = null; + this.node = null; + this.scope = null; + this.type = null; + this.typeAnnotation = null; } - static get({ hub, parentPath, parent, container, listKey, key }) { + parent: Object; + hub: Hub; + contexts: Array; + data: Object; + shouldSkip: boolean; + shouldStop: boolean; + removed: boolean; + state: any; + opts: ?Object; + skipKeys: ?Object; + parentPath: ?NodePath; + context: TraversalContext; + container: ?Object | Array; + listKey: ?string; + inList: boolean; + parentKey: ?string; + key: ?string; + node: ?Object; + scope: Scope; + type: ?string; + typeAnnotation: ?Object; + + static get({ hub, parentPath, parent, container, listKey, key }): NodePath { if (!hub && parentPath) { hub = parentPath.hub; } invariant(parent, "To get a node path the parent needs to exist"); - var targetNode = container[key]; - var paths = parent._paths = parent._paths || []; - var path; + let targetNode = container[key]; - for (var i = 0; i < paths.length; i++) { - var pathCheck = paths[i]; + let paths = parent[PATH_CACHE_KEY] = parent[PATH_CACHE_KEY] || []; + let path; + + for (let i = 0; i < paths.length; i++) { + let pathCheck = paths[i]; if (pathCheck.node === targetNode) { path = pathCheck; break; @@ -56,13 +82,17 @@ export default class NodePath { paths.push(path); } + if (!(path instanceof NodePath)) { + throw new Error("We found a path that isn't a NodePath instance"); + } + path.setup(parentPath, container, listKey, key); return path; } getScope(scope: Scope) { - var ourScope = scope; + let ourScope = scope; // we're entering a new scope so let's construct it! if (this.isScope()) { @@ -72,25 +102,25 @@ export default class NodePath { return ourScope; } - setData(key, val) { + setData(key: string, val: any): any { return this.data[key] = val; } - getData(key, def) { - var val = this.data[key]; + getData(key: string, def?: any): any { + let val = this.data[key]; if (!val && def) val = this.data[key] = def; return val; } - errorWithNode(msg, Error = SyntaxError) { - return this.hub.file.errorWithNode(this.node, msg, Error); + buildCodeFrameError(msg: string, Error: typeof Error = SyntaxError): Error { + return this.hub.file.buildCodeFrameError(this.node, msg, Error); } - traverse(visitor, state) { + traverse(visitor: Object, state?: any) { traverse(this.node, visitor, this.scope, state, this); } - mark(type, message) { + mark(type: string, message: string) { this.hub.file.metadata.marked.push({ type, message, @@ -98,14 +128,21 @@ export default class NodePath { }); } - /** - * Description - */ - - set(key, node) { - t.validate(key, this.node, node); + set(key: string, node: Object) { + t.validate(this.node, key, node); this.node[key] = node; } + + dump() { + let parts = []; + let path = this; + do { + let key = path.key; + if (path.inList) key = `${path.listKey}[${key}]`; + parts.unshift(key); + } while(path = path.parentPath); + console.log(parts.join(".")); + } } assign(NodePath.prototype, require("./ancestry")); @@ -120,18 +157,26 @@ assign(NodePath.prototype, require("./modification")); assign(NodePath.prototype, require("./family")); assign(NodePath.prototype, require("./comments")); -for (let type of (t.TYPES: Array)) { +for (let type of (t.TYPES: Array)) { let typeKey = `is${type}`; NodePath.prototype[typeKey] = function (opts) { return t[typeKey](this.node, opts); }; + + NodePath.prototype[`assert${type}`] = function (opts) { + if (!this[typeKey](opts)) { + throw new TypeError(`Expected node path of type ${type}`); + } + }; } for (let type in virtualTypes) { if (type[0] === "_") continue; if (t.TYPES.indexOf(type) < 0) t.TYPES.push(type); + let virtualType = virtualTypes[type]; + NodePath.prototype[`is${type}`] = function (opts) { - return virtualTypes[type].checkPath(this, opts); + return virtualType.checkPath(this, opts); }; } diff --git a/packages/babel-traverse/src/path/inference/index.js b/packages/babel-traverse/src/path/inference/index.js index d3228a4e16..40e5c75606 100644 --- a/packages/babel-traverse/src/path/inference/index.js +++ b/packages/babel-traverse/src/path/inference/index.js @@ -1,3 +1,5 @@ +/* @flow */ + import type NodePath from "./index"; import * as inferers from "./inferers"; import * as t from "babel-types"; @@ -6,10 +8,10 @@ import * as t from "babel-types"; * Infer the type of the current `NodePath`. */ -export function getTypeAnnotation() { +export function getTypeAnnotation(): Object { if (this.typeAnnotation) return this.typeAnnotation; - var type = this._getTypeAnnotation() || t.anyTypeAnnotation(); + let type = this._getTypeAnnotation() || t.anyTypeAnnotation(); if (t.isTypeAnnotation(type)) type = type.typeAnnotation; return this.typeAnnotation = type; } @@ -19,20 +21,20 @@ export function getTypeAnnotation() { */ export function _getTypeAnnotation(): ?Object { - var node = this.node; + let node = this.node; if (!node) { // handle initializerless variables, add in checks for loop initializers too if (this.key === "init" && this.parentPath.isVariableDeclarator()) { - var declar = this.parentPath.parentPath; - var declarParent = declar.parentPath; + let declar = this.parentPath.parentPath; + let declarParent = declar.parentPath; - // for (var NODE in bar) {} + // for (let NODE in bar) {} if (declar.key === "left" && declarParent.isForInStatement()) { return t.stringTypeAnnotation(); } - // for (var NODE of bar) {} + // for (let NODE of bar) {} if (declar.key === "left" && declarParent.isForOfStatement()) { return t.anyTypeAnnotation(); } @@ -47,7 +49,7 @@ export function _getTypeAnnotation(): ?Object { return node.typeAnnotation; } - var inferer = inferers[node.type]; + let inferer = inferers[node.type]; if (inferer) { return inferer.call(this, node); } @@ -58,7 +60,7 @@ export function _getTypeAnnotation(): ?Object { } } -export function isBaseType(baseName: string, soft?): boolean { +export function isBaseType(baseName: string, soft?: boolean): boolean { return _isBaseType(baseName, this.getTypeAnnotation(), soft); } @@ -85,11 +87,11 @@ function _isBaseType(baseName: string, type?, soft?): boolean { } export function couldBeBaseType(name: string): boolean { - var type = this.getTypeAnnotation(); + let type = this.getTypeAnnotation(); if (t.isAnyTypeAnnotation(type)) return true; if (t.isUnionTypeAnnotation(type)) { - for (var type2 of (type.types: Array)) { + for (let type2 of (type.types: Array)) { if (t.isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) { return true; } @@ -101,7 +103,7 @@ export function couldBeBaseType(name: string): boolean { } export function baseTypeStrictlyMatches(right: NodePath) { - var left = this.getTypeAnnotation(); + let left = this.getTypeAnnotation(); right = right.getTypeAnnotation(); if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) { @@ -110,6 +112,6 @@ export function baseTypeStrictlyMatches(right: NodePath) { } export function isGenericType(genericName: string): boolean { - var type = this.getTypeAnnotation(); + let type = this.getTypeAnnotation(); return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, { name: genericName }); } diff --git a/packages/babel-traverse/src/path/inference/inferer-reference.js b/packages/babel-traverse/src/path/inference/inferer-reference.js index 3f4a7a840a..f3258ffde5 100644 --- a/packages/babel-traverse/src/path/inference/inferer-reference.js +++ b/packages/babel-traverse/src/path/inference/inferer-reference.js @@ -1,11 +1,14 @@ +/* @flow */ + +import type NodePath from "../index"; import * as t from "babel-types"; -export default function (node) { +export default function (node: Object) { if (!this.isReferenced()) return; // check if a binding exists of this value and if so then return a union type of all // possible types that the binding could be - var binding = this.scope.getBinding(node.name); + let binding = this.scope.getBinding(node.name); if (binding) { if (binding.identifier.typeAnnotation) { return binding.identifier.typeAnnotation; @@ -25,17 +28,17 @@ export default function (node) { } function getTypeAnnotationBindingConstantViolations(path, name) { - var binding = path.scope.getBinding(name); + let binding = path.scope.getBinding(name); - var types = []; + let types = []; path.typeAnnotation = t.unionTypeAnnotation(types); - var functionConstantViolations = []; - var constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations); + let functionConstantViolations = []; + let constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations); - var testType = getConditionalAnnotation(path, name); + let testType = getConditionalAnnotation(path, name); if (testType) { - var testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement); + let testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement); // remove constant violations observed before the IfStatement constantViolations = constantViolations.filter((path) => testConstantViolations.indexOf(path) < 0); @@ -47,11 +50,11 @@ function getTypeAnnotationBindingConstantViolations(path, name) { if (constantViolations.length) { // pick one constant from each scope which will represent the last possible // control flow path that it could've taken/been - var rawConstantViolations = constantViolations.reverse(); - var visitedScopes = []; + let rawConstantViolations = constantViolations.reverse(); + let visitedScopes = []; constantViolations = []; - for (let violation of (rawConstantViolations: Array)) { - var violationScope = violation.scope; + for (let violation of (rawConstantViolations: Array)) { + let violationScope = violation.scope; if (visitedScopes.indexOf(violationScope) >= 0) continue; visitedScopes.push(violationScope); @@ -67,7 +70,7 @@ function getTypeAnnotationBindingConstantViolations(path, name) { constantViolations = constantViolations.concat(functionConstantViolations); // push on inferred types of violated paths - for (let violation of (constantViolations: Array)) { + for (let violation of (constantViolations: Array)) { types.push(violation.getTypeAnnotation()); } } @@ -78,23 +81,23 @@ function getTypeAnnotationBindingConstantViolations(path, name) { } function getConstantViolationsBefore(binding, path, functions) { - var violations = binding.constantViolations.slice(); + let violations = binding.constantViolations.slice(); violations.unshift(binding.path); return violations.filter((violation) => { violation = violation.resolve(); - var status = violation._guessExecutionStatusRelativeTo(path); + let status = violation._guessExecutionStatusRelativeTo(path); if (functions && status === "function") functions.push(violation); return status === "before"; }); } function inferAnnotationFromBinaryExpression(name, path) { - var operator = path.node.operator; + let operator = path.node.operator; - var right = path.get("right").resolve(); - var left = path.get("left").resolve(); + let right = path.get("right").resolve(); + let left = path.get("left").resolve(); - var target; + let target; if (left.isIdentifier({ name })) { target = right; } else if (right.isIdentifier({ name })) { @@ -113,8 +116,8 @@ function inferAnnotationFromBinaryExpression(name, path) { } // - var typeofPath; - var typePath; + let typeofPath; + let typePath; if (left.isUnaryExpression({ operator: "typeof" })) { typeofPath = left; typePath = right; @@ -129,7 +132,7 @@ function inferAnnotationFromBinaryExpression(name, path) { if (!typePath.isLiteral()) return; // and that it's a string so we can infer it - var typeValue = typePath.node.value; + let typeValue = typePath.node.value; if (typeof typeValue !== "string") return; // and that the argument of the typeof path references us! @@ -140,7 +143,7 @@ function inferAnnotationFromBinaryExpression(name, path) { } function getParentConditionalPath(path) { - var parentPath; + let parentPath; while (parentPath = path.parentPath) { if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) { if (path.key === "test") { @@ -155,12 +158,12 @@ function getParentConditionalPath(path) { } function getConditionalAnnotation(path, name) { - var ifStatement = getParentConditionalPath(path); + let ifStatement = getParentConditionalPath(path); if (!ifStatement) return; - var test = ifStatement.get("test"); - var paths = [test]; - var types = []; + let test = ifStatement.get("test"); + let paths = [test]; + let types = []; do { let path = paths.shift().resolve(); @@ -171,7 +174,7 @@ function getConditionalAnnotation(path, name) { } if (path.isBinaryExpression()) { - var type = inferAnnotationFromBinaryExpression(name, path); + let type = inferAnnotationFromBinaryExpression(name, path); if (type) types.push(type); } } while(paths.length); diff --git a/packages/babel-traverse/src/path/inference/inferers.js b/packages/babel-traverse/src/path/inference/inferers.js index f36b977bc9..2925d9797e 100644 --- a/packages/babel-traverse/src/path/inference/inferers.js +++ b/packages/babel-traverse/src/path/inference/inferers.js @@ -1,9 +1,11 @@ +/* @flow */ + import * as t from "babel-types"; export { default as Identifier } from "./inferer-reference"; export function VariableDeclarator() { - var id = this.get("id"); + let id = this.get("id"); if (id.isIdentifier()) { return this.get("init").getTypeAnnotation(); @@ -51,8 +53,8 @@ export function BinaryExpression(node) { } else if (t.BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) { return t.booleanTypeAnnotation(); } else if (operator === "+") { - var right = this.get("right"); - var left = this.get("left"); + let right = this.get("right"); + let left = this.get("left"); if (left.isBaseType("number") && right.isBaseType("number")) { // both numbers so this will be a number @@ -99,13 +101,24 @@ export function UpdateExpression(node) { } } -export function Literal(node) { - var value = node.value; - if (typeof value === "string") return t.stringTypeAnnotation(); - if (typeof value === "number") return t.numberTypeAnnotation(); - if (typeof value === "boolean") return t.booleanTypeAnnotation(); - if (value === null) return t.voidTypeAnnotation(); - if (node.regex) return t.genericTypeAnnotation(t.identifier("RegExp")); +export function StringLiteral() { + return t.stringTypeAnnotation(); +} + +export function NumberLiteral() { + return t.numberTypeAnnotation(); +} + +export function BooleanLiteral() { + return t.booleanTypeAnnotation(); +} + +export function NullLiteral() { + return t.voidTypeAnnotation(); +} + +export function RegexLiteral() { + return t.genericTypeAnnotation(t.identifier("RegExp")); } export function ObjectExpression() { diff --git a/packages/babel-traverse/src/path/introspection.js b/packages/babel-traverse/src/path/introspection.js index 070df895f7..a333a49ab9 100644 --- a/packages/babel-traverse/src/path/introspection.js +++ b/packages/babel-traverse/src/path/introspection.js @@ -1,3 +1,5 @@ +/* @flow */ + // This file contains methods responsible for introspecting the current path for certain values. import type NodePath from "./index"; @@ -15,17 +17,17 @@ export function matchesPattern(pattern: string, allowPartial?: boolean): boolean // not a member expression if (!this.isMemberExpression()) return false; - var parts = pattern.split("."); - var search = [this.node]; - var i = 0; + let parts = pattern.split("."); + let search = [this.node]; + let i = 0; function matches(name) { - var part = parts[i]; + let part = parts[i]; return part === "*" || name === part; } while (search.length) { - var node = search.shift(); + let node = search.shift(); if (allowPartial && i === parts.length) { return true; @@ -68,7 +70,7 @@ export function matchesPattern(pattern: string, allowPartial?: boolean): boolean */ export function has(key): boolean { - var val = this.node[key]; + let val = this.node[key]; if (val && Array.isArray(val)) { return !!val.length; } else { @@ -88,7 +90,7 @@ export function isStatic() { * Alias of `has`. */ -export var is = has; +export let is = has; /** * Opposite of `has`. @@ -134,11 +136,11 @@ export function isNodeType(type: string): boolean { */ export function isCompletionRecord(allowInsideFunction?) { - var path = this; - var first = true; + let path = this; + let first = true; do { - var container = path.container; + let container = path.container; // we're in a function so can't be a completion record if (path.isFunction() && !first) { @@ -177,11 +179,11 @@ export function isStatementOrBlock() { export function referencesImport(moduleSource, importName) { if (!this.isReferencedIdentifier()) return false; - var binding = this.scope.getBinding(this.node.name); + let binding = this.scope.getBinding(this.node.name); if (!binding || binding.kind !== "module") return false; - var path = binding.path; - var parent = path.parentPath; + let path = binding.path; + let parent = path.parentPath; if (!parent.isImportDeclaration()) return false; // check moduleSource @@ -211,7 +213,7 @@ export function referencesImport(moduleSource, importName) { */ export function getSource() { - var node = this.node; + let node = this.node; if (node.end) { return this.hub.file.code.slice(node.start, node.end); } else { @@ -232,57 +234,29 @@ export function willIMaybeExecuteBefore(target) { export function _guessExecutionStatusRelativeTo(target) { // check if the two paths are in different functions, we can't track execution of these - var targetFuncParent = target.scope.getFunctionParent(); - var selfFuncParent = this.scope.getFunctionParent(); + let targetFuncParent = target.scope.getFunctionParent(); + let selfFuncParent = this.scope.getFunctionParent(); if (targetFuncParent !== selfFuncParent) { - var targetFuncPath = targetFuncParent.path; - if (!targetFuncPath.isFunctionDeclaration()) return "function"; - - // so we're in a completely different function, if this is a function declaration - // then we can be a bit smarter and handle cases where the function is either - // a. not called at all (part of an export) - // b. called directly - var binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name); - - // no references! - if (!binding.references) return "before"; - - var referencePaths: Array = binding.referencePaths; - - // verify that all of the references are calls - for (let path of referencePaths) { - if (path.key !== "callee" || !path.parentPath.isCallExpression()) { - return "function"; - } + let status = this._guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent); + if (status) { + return status; + } else { + target = targetFuncParent.path; } - - var allStatus; - - // verify that all the calls have the same execution status - for (let path of referencePaths) { - var status = this._guessExecutionStatusRelativeTo(path); - if (allStatus) { - if (allStatus !== status) return "function"; - } else { - allStatus = status; - } - } - - return allStatus || "function"; } - var targetPaths = target.getAncestry(); + let targetPaths = target.getAncestry(); if (targetPaths.indexOf(this) >= 0) return "after"; - var selfPaths = this.getAncestry(); + let selfPaths = this.getAncestry(); // get ancestor where the branches intersect - var commonPath; - var targetIndex; - var selfIndex; + let commonPath; + let targetIndex; + let selfIndex; for (selfIndex = 0; selfIndex < selfPaths.length; selfIndex++) { - var selfPath = selfPaths[selfIndex]; + let selfPath = selfPaths[selfIndex]; targetIndex = targetPaths.indexOf(selfPath); if (targetIndex >= 0) { commonPath = selfPath; @@ -294,8 +268,8 @@ export function _guessExecutionStatusRelativeTo(target) { } // get the relationship paths that associate these nodes to their common ancestor - var targetRelationship = targetPaths[targetIndex - 1]; - var selfRelationship = selfPaths[selfIndex - 1]; + let targetRelationship = targetPaths[targetIndex - 1]; + let selfRelationship = selfPaths[selfIndex - 1]; if (!targetRelationship || !selfRelationship) { return "before"; } @@ -306,11 +280,48 @@ export function _guessExecutionStatusRelativeTo(target) { } // otherwise we're associated by a parent node, check which key comes before the other - var targetKeyPosition = t.VISITOR_KEYS[targetRelationship.type].indexOf(targetRelationship.key); - var selfKeyPosition = t.VISITOR_KEYS[selfRelationship.type].indexOf(selfRelationship.key); + let targetKeyPosition = t.VISITOR_KEYS[targetRelationship.type].indexOf(targetRelationship.key); + let selfKeyPosition = t.VISITOR_KEYS[selfRelationship.type].indexOf(selfRelationship.key); return targetKeyPosition > selfKeyPosition ? "before" : "after"; } +export function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent) { + let targetFuncPath = targetFuncParent.path; + if (!targetFuncPath.isFunctionDeclaration()) return; + + // so we're in a completely different function, if this is a function declaration + // then we can be a bit smarter and handle cases where the function is either + // a. not called at all (part of an export) + // b. called directly + let binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name); + + // no references! + if (!binding.references) return "before"; + + let referencePaths: Array = binding.referencePaths; + + // verify that all of the references are calls + for (let path of referencePaths) { + if (path.key !== "callee" || !path.parentPath.isCallExpression()) { + return; + } + } + + let allStatus; + + // verify that all the calls have the same execution status + for (let path of referencePaths) { + let status = this._guessExecutionStatusRelativeTo(path); + if (allStatus) { + if (allStatus !== status) return; + } else { + allStatus = status; + } + } + + return allStatus; +} + /** * Resolve a "pointer" `NodePath` to it's absolute path. */ @@ -335,7 +346,7 @@ export function _resolve(dangerous?, resolved?): ?NodePath { // otherwise it's a request for a pattern and that's a bit more tricky } } else if (this.isReferencedIdentifier()) { - var binding = this.scope.getBinding(this.node.name); + let binding = this.scope.getBinding(this.node.name); if (!binding) return; // reassigned so we can't really resolve it @@ -353,22 +364,22 @@ export function _resolve(dangerous?, resolved?): ?NodePath { // this is dangerous, as non-direct target assignments will mutate it's state // making this resolution inaccurate - var targetKey = this.toComputedKey(); + let targetKey = this.toComputedKey(); if (!t.isLiteral(targetKey)) return; - var targetName = targetKey.value; + let targetName = targetKey.value; - var target = this.get("object").resolve(dangerous, resolved); + let target = this.get("object").resolve(dangerous, resolved); if (target.isObjectExpression()) { - var props = target.get("properties"); - for (var prop of (props: Array)) { + let props = target.get("properties"); + for (let prop of (props: Array)) { if (!prop.isProperty()) continue; - var key = prop.get("key"); + let key = prop.get("key"); // { foo: obj } - var match = prop.isnt("computed") && key.isIdentifier({ name: targetName }); + let match = prop.isnt("computed") && key.isIdentifier({ name: targetName }); // { "foo": "obj" } or { ["foo"]: "obj" } match = match || key.isLiteral({ value: targetName }); @@ -376,8 +387,8 @@ export function _resolve(dangerous?, resolved?): ?NodePath { if (match) return prop.get("value").resolve(dangerous, resolved); } } else if (target.isArrayExpression() && !isNaN(+targetName)) { - var elems = target.get("elements"); - var elem = elems[targetName]; + let elems = target.get("elements"); + let elem = elems[targetName]; if (elem) return elem.resolve(dangerous, resolved); } } diff --git a/packages/babel-traverse/src/path/lib/hoister.js b/packages/babel-traverse/src/path/lib/hoister.js index dc4a71e317..669f4f0f79 100644 --- a/packages/babel-traverse/src/path/lib/hoister.js +++ b/packages/babel-traverse/src/path/lib/hoister.js @@ -1,25 +1,26 @@ +/* @flow */ + import { react } from "babel-types"; import * as t from "babel-types"; -var referenceVisitor = { - - ReferencedIdentifier(node, parent, scope, state) { - if (this.isJSXIdentifier() && react.isCompatTag(node.name)) { +let referenceVisitor = { + ReferencedIdentifier(path, state) { + if (path.isJSXIdentifier() && react.isCompatTag(path.node.name)) { return; } // direct references that we need to track to hoist this to the highest scope we can - var binding = scope.getBinding(node.name); + let binding = path.scope.getBinding(path.node.name); if (!binding) return; // this binding isn't accessible from the parent scope so we can safely ignore it // eg. it's in a closure etc - if (binding !== state.scope.getBinding(node.name)) return; + if (binding !== state.scope.getBinding(path.node.name)) return; if (binding.constant) { - state.bindings[node.name] = binding; + state.bindings[path.node.name] = binding; } else { - for (var violationPath of (binding.constantViolations: Array)) { + for (let violationPath of (binding.constantViolations: Array)) { state.breakOnScopePaths = state.breakOnScopePaths.concat(violationPath.getAncestry()); } } @@ -36,8 +37,8 @@ export default class PathHoister { } isCompatibleScope(scope) { - for (var key in this.bindings) { - var binding = this.bindings[key]; + for (let key in this.bindings) { + let binding = this.bindings[key]; if (!scope.bindingIdentifierEquals(key, binding.identifier)) { return false; } @@ -47,7 +48,7 @@ export default class PathHoister { } getCompatibleScopes() { - var scope = this.path.scope; + let scope = this.path.scope; do { if (this.isCompatibleScope(scope)) { this.scopes.push(scope); @@ -62,9 +63,9 @@ export default class PathHoister { } getAttachmentPath() { - var scopes = this.scopes; + let scopes = this.scopes; - var scope = scopes.pop(); + let scope = scopes.pop(); if (!scope) return; if (scope.path.isFunction()) { @@ -84,22 +85,22 @@ export default class PathHoister { } getNextScopeStatementParent() { - var scope = this.scopes.pop(); + let scope = this.scopes.pop(); if (scope) return scope.path.getStatementParent(); } hasOwnParamBindings(scope) { - for (var name in this.bindings) { + for (let name in this.bindings) { if (!scope.hasOwnBinding(name)) continue; - var binding = this.bindings[name]; + let binding = this.bindings[name]; if (binding.kind === "param") return true; } return false; } run() { - var node = this.path.node; + let node = this.path.node; if (node._hoisted) return; node._hoisted = true; @@ -107,13 +108,13 @@ export default class PathHoister { this.getCompatibleScopes(); - var attachTo = this.getAttachmentPath(); + let attachTo = this.getAttachmentPath(); if (!attachTo) return; // don't bother hoisting to the same function as this will cause multiple branches to be evaluated more than once leading to a bad optimisation if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return; - var uid = attachTo.scope.generateUidIdentifier("ref"); + let uid = attachTo.scope.generateUidIdentifier("ref"); attachTo.insertBefore([ t.variableDeclaration("var", [ @@ -121,7 +122,7 @@ export default class PathHoister { ]) ]); - var parent = this.path.parentPath; + let parent = this.path.parentPath; if (parent.isJSXElement() && this.path.container === parent.node.children) { // turning the `span` in `
` to an expression so we need to wrap it with diff --git a/packages/babel-traverse/src/path/lib/removal-hooks.js b/packages/babel-traverse/src/path/lib/removal-hooks.js index 4b8749f7e8..eb51a0123e 100644 --- a/packages/babel-traverse/src/path/lib/removal-hooks.js +++ b/packages/babel-traverse/src/path/lib/removal-hooks.js @@ -1,50 +1,21 @@ -// this file contains hooks that handle ancestry cleanup of parent nodes when removing children +/* @flow */ -import * as t from "babel-types"; +// this file contains hooks that handle ancestry cleanup of parent nodes when removing children /** * Pre hooks should be used for either rejecting removal or delegating removal */ -export var pre = [ - - function (self) { - if (self.key === "body" && (self.isBlockStatement() || self.isClassBody())) { - // function () NODE - // class NODE - // attempting to remove a block statement that's someones body so let's just clear all the inner - // statements instead - self.node.body = []; +export let hooks = [ + function (self, parent) { + if (self.key === "body" && parent.isArrowFunctionExpression()) { + self.replaceWith(self.scope.buildUndefinedNode()); return true; } }, function (self, parent) { - var replace = false; - - // () => NODE; - // removing the body of an arrow function - replace = replace || (self.key === "body" && parent.isArrowFunctionExpression()); - - // throw NODE; - // removing a throw statement argument - replace = replace || (self.key === "argument" && parent.isThrowStatement()); - - if (replace) { - self.replaceWith(t.identifier("undefined")); - return true; - } - } -]; - -/** - * Post hooks should be used for cleaning up parents - */ - -export var post = [ - - function (self, parent) { - var removeParent = false; + let removeParent = false; // while (NODE); // removing the test of a while/switch, we can either just remove it entirely *or* turn the `test` into `true` @@ -59,21 +30,16 @@ export var post = [ // stray labeled statement with no body removeParent = removeParent || (self.key === "body" && parent.isLabeledStatement()); - // var NODE; + // let NODE; // remove an entire declaration if there are no declarators left - removeParent = removeParent || (self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 0); + removeParent = removeParent || (self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1); // NODE; // remove the entire expression statement if there's no expression removeParent = removeParent || (self.key === "expression" && parent.isExpressionStatement()); - // if (NODE); - // remove the entire if since the consequent is never going to be hit, if there's an alternate then it's already been - // handled with the `pre` hook - removeParent = removeParent || (self.key === "test" && parent.isIfStatement()); - if (removeParent) { - parent.dangerouslyRemove(); + parent.remove(); return true; } }, diff --git a/packages/babel-traverse/src/path/lib/virtual-types.js b/packages/babel-traverse/src/path/lib/virtual-types.js index 897c1b70ed..ce92ed1276 100644 --- a/packages/babel-traverse/src/path/lib/virtual-types.js +++ b/packages/babel-traverse/src/path/lib/virtual-types.js @@ -1,9 +1,12 @@ +/* @flow */ + +import type NodePath from "../index"; import { react } from "babel-types"; import * as t from "babel-types"; -export var ReferencedIdentifier = { +export let ReferencedIdentifier = { types: ["Identifier", "JSXIdentifier"], - checkPath({ node, parent }, opts) { + checkPath({ node, parent }: NodePath, opts?: Object): boolean { if (!t.isIdentifier(node, opts)) { if (t.isJSXIdentifier(node, opts)) { if (react.isCompatTag(node.name)) return false; @@ -18,16 +21,23 @@ export var ReferencedIdentifier = { } }; -export var BindingIdentifier = { - types: ["Identifier"], +export let ReferencedMemberExpression = { + types: ["MemberExpression"], checkPath({ node, parent }) { - return t.isBinding(node, parent); + return t.isMemberExpression(node) && t.isReferenced(node, parent); } }; -export var Statement = { +export let BindingIdentifier = { + types: ["Identifier"], + checkPath({ node, parent }: NodePath): boolean { + return t.isIdentifier(node) && t.isBinding(node, parent); + } +}; + +export let Statement = { types: ["Statement"], - checkPath({ node, parent }) { + checkPath({ node, parent }: NodePath): boolean { if (t.isStatement(node)) { if (t.isVariableDeclaration(node)) { if (t.isForXStatement(parent, { left: node })) return false; @@ -41,9 +51,9 @@ export var Statement = { } }; -export var Expression = { +export let Expression = { types: ["Expression"], - checkPath(path) { + checkPath(path: NodePath): boolean { if (path.isIdentifier()) { return path.isReferencedIdentifier(); } else { @@ -52,75 +62,53 @@ export var Expression = { } }; -export var Scope = { +export let Scope = { types: ["Scopable"], checkPath(path) { return t.isScope(path.node, path.parent); } }; -export var Referenced = { - checkPath(path) { +export let Referenced = { + checkPath(path: NodePath): boolean { return t.isReferenced(path.node, path.parent); } }; -export var BlockScoped = { - checkPath(path) { +export let BlockScoped = { + checkPath(path: NodePath): boolean { return t.isBlockScoped(path.node); } }; -export var Var = { +export let Var = { types: ["VariableDeclaration"], - checkPath(path) { + checkPath(path: NodePath): boolean { return t.isVar(path.node); } }; -export var DirectiveLiteral = { - types: ["Literal"], - checkPath(path) { - return path.parentPath.isDirective(); - } -}; - -export var Directive = { - types: ["ExpressionStatement"], - checkPath({ inList, container, key }) { - // needs to be in a statement list - if (!inList) return false; - - // get the last directive node in this list - var lastDirective = -1; - for (var i = 0; i < container.length; i++) { - var node = container[i]; - if (t.isExpressionStatement(node) && t.isLiteral(node.expression)) { - lastDirective = i; - } else { - break; - } - } - - return key <= lastDirective; - } -}; - -export var User = { - checkPath(path) { +export let User = { + checkPath(path: NodePath): boolean { return path.node && !!path.node.loc; } }; -export var Generated = { - checkPath(path) { +export let Generated = { + checkPath(path: NodePath): boolean { return !path.isUser(); } }; -export var Flow = { +export let Pure = { + checkPath(path: NodePath, opts?): boolean { + return path.scope.isPure(path.node, opts); + } +}; + +export let Flow = { types: ["Flow", "ImportDeclaration", "ExportDeclaration"], - checkPath({ node }) { + checkPath({ node }: NodePath): boolean { if (t.isFlow(node)) { return true; } else if (t.isImportDeclaration(node)) { diff --git a/packages/babel-traverse/src/path/modification.js b/packages/babel-traverse/src/path/modification.js index 4e0fb2ea0e..d05b9f2b56 100644 --- a/packages/babel-traverse/src/path/modification.js +++ b/packages/babel-traverse/src/path/modification.js @@ -1,5 +1,8 @@ +/* @flow */ + // This file contains methods that modify the path/node in some ways. +import { PATH_CACHE_KEY } from "./constants"; import PathHoister from "./lib/hoister"; import NodePath from "./index"; import * as t from "babel-types"; @@ -36,17 +39,16 @@ export function insertBefore(nodes) { export function _containerInsert(from, nodes) { this.updateSiblingKeys(from, nodes.length); - var paths = []; + let paths = []; - for (var i = 0; i < nodes.length; i++) { - var to = from + i; - var node = nodes[i]; + for (let i = 0; i < nodes.length; i++) { + let to = from + i; + let node = nodes[i]; this.container.splice(to, 0, node); if (this.context) { - var path = this.context.create(this.parent, this.container, to, this.listKey); + let path = this.context.create(this.parent, this.container, to, this.listKey); paths.push(path); - this.queueNode(path); } else { paths.push(NodePath.get({ parentPath: this, @@ -58,6 +60,21 @@ export function _containerInsert(from, nodes) { } } + let contexts = this.contexts; + let path = this; + while (!contexts.length) { + path = path.parentPath; + contexts = path.contexts; + } + + for (let path of paths) { + path.setScope(); + + for (let context of contexts) { + context.maybeQueue(path); + } + } + return paths; } @@ -70,8 +87,10 @@ export function _containerInsertAfter(nodes) { } export function _maybePopFromStatements(nodes) { - var last = nodes[nodes.length - 1]; - if (t.isExpressionStatement(last) && t.isIdentifier(last.expression) && !this.isCompletionRecord()) { + let last = nodes[nodes.length - 1]; + let isIdentifier = t.isIdentifier(last) || (t.isExpressionStatement(last) && t.isIdentifier(last.expression)); + + if (isIdentifier && !this.isCompletionRecord()) { nodes.pop(); } } @@ -90,7 +109,7 @@ export function insertAfter(nodes) { return this.parentPath.insertAfter(nodes); } else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) { if (this.node) { - var temp = this.scope.generateDeclaredUidIdentifier(); + let temp = this.scope.generateDeclaredUidIdentifier(); nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node))); nodes.push(t.expressionStatement(temp)); } @@ -117,8 +136,8 @@ export function insertAfter(nodes) { export function updateSiblingKeys(fromIndex, incrementBy) { if (!this.parent) return; - var paths = this.parent._paths; - for (var i = 0; i < paths.length; i++) { + let paths = this.parent[PATH_CACHE_KEY]; + for (let i = 0; i < paths.length; i++) { let path = paths[i]; if (path.key >= fromIndex) { path.key += incrementBy; @@ -127,12 +146,16 @@ export function updateSiblingKeys(fromIndex, incrementBy) { } export function _verifyNodeList(nodes) { + if (!nodes) { + return []; + } + if (nodes.constructor !== Array) { nodes = [nodes]; } - for (var i = 0; i < nodes.length; i++) { - var node = nodes[i]; + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i]; if (!node) { throw new Error(`Node list has falsy node with the index of ${i}`); } else if (typeof node !== "object") { @@ -154,12 +177,10 @@ export function unshiftContainer(listKey, nodes) { // get the first path and insert our nodes before it, if it doesn't exist then it // doesn't matter, our nodes will be inserted anyway - - var container = this.node[listKey]; - var path = NodePath.get({ + let path = NodePath.get({ parentPath: this, parent: this.node, - container: container, + container: this.node[listKey], listKey, key: 0 }); @@ -175,17 +196,16 @@ export function pushContainer(listKey, nodes) { // get an invisible path that represents the last node + 1 and replace it with our // nodes, effectively inlining it - var container = this.node[listKey]; - var i = container.length; - var path = NodePath.get({ + let container = this.node[listKey]; + let path = NodePath.get({ parentPath: this, parent: this.node, container: container, listKey, - key: i + key: container.length }); - return path.replaceWith(nodes, true); + return path.replaceWithMultiple(nodes); } /** @@ -194,6 +214,6 @@ export function pushContainer(listKey, nodes) { */ export function hoist(scope = this.scope) { - var hoister = new PathHoister(this, scope); + let hoister = new PathHoister(this, scope); return hoister.run(); } diff --git a/packages/babel-traverse/src/path/removal.js b/packages/babel-traverse/src/path/removal.js index 0567b83f12..3e654a3a67 100644 --- a/packages/babel-traverse/src/path/removal.js +++ b/packages/babel-traverse/src/path/removal.js @@ -1,24 +1,15 @@ +/* @flow */ + // This file contains methods responsible for removing a node. -import * as removalHooks from "./lib/removal-hooks"; - -/** - * This is now safe. - */ - -export var dangerouslyRemove = remove; - -/** - * Dangerously remove the current node. This may sometimes result in a tainted - * invalid AST so use with caution. - */ +import { hooks } from "./lib/removal-hooks"; export function remove() { this._assertUnremoved(); this.resync(); - if (this._callRemovalHooks("pre")) { + if (this._callRemovalHooks()) { this._markRemoved(); return; } @@ -26,12 +17,10 @@ export function remove() { this.shareCommentsWithSiblings(); this._remove(); this._markRemoved(); - - this._callRemovalHooks("post"); } -export function _callRemovalHooks(position) { - for (var fn of (removalHooks[position]: Array)) { +export function _callRemovalHooks() { + for (let fn of (hooks: Array)) { if (fn(this, this.parentPath)) return true; } } @@ -53,6 +42,6 @@ export function _markRemoved() { export function _assertUnremoved() { if (this.removed) { - throw this.errorWithNode("NodePath has been removed so is read-only."); + throw this.buildCodeFrameError("NodePath has been removed so is read-only."); } } diff --git a/packages/babel-traverse/src/path/replacement.js b/packages/babel-traverse/src/path/replacement.js index eb0ef5c61b..fca7bd27f2 100644 --- a/packages/babel-traverse/src/path/replacement.js +++ b/packages/babel-traverse/src/path/replacement.js @@ -1,3 +1,5 @@ +/* @flow */ + // This file contains methods responsible for replacing a node with another. import codeFrame from "babel-code-frame"; @@ -6,23 +8,22 @@ import NodePath from "./index"; import { parse } from "babylon"; import * as t from "babel-types"; -var hoistVariablesVisitor = { - - Function() { - this.skip(); +let hoistVariablesVisitor = { + Function(path) { + path.skip(); }, - VariableDeclaration(node, parent, scope) { - if (node.kind !== "var") return; + VariableDeclaration(path) { + if (path.node.kind !== "var") return; - var bindings = this.getBindingIdentifiers(); - for (var key in bindings) { - scope.push({ id: bindings[key] }); + let bindings = path.getBindingIdentifiers(); + for (let key in bindings) { + path.scope.push({ id: bindings[key] }); } - var exprs = []; + let exprs = []; - for (var declar of (node.declarations: Array)) { + for (let declar of (path.node.declarations: Array)) { if (declar.init) { exprs.push(t.expressionStatement( t.assignmentExpression("=", declar.id, declar.init) @@ -30,7 +31,7 @@ var hoistVariablesVisitor = { } } - return exprs; + path.replaceWithMultiple(exprs); } }; @@ -50,7 +51,12 @@ export function replaceWithMultiple(nodes: Array) { t.inheritTrailingComments(nodes[nodes.length - 1], this.node); this.node = this.container[this.key] = null; this.insertAfter(nodes); - if (!this.node) this.dangerouslyRemove(); + + if (this.node) { + this.requeue(); + } else { + this.remove(); + } } /** @@ -68,7 +74,7 @@ export function replaceWithSourceString(replacement) { replacement = `(${replacement})`; replacement = parse(replacement); } catch (err) { - var loc = err.loc; + let loc = err.loc; if (loc) { err.message += " - make sure this is an expression."; err.message += "\n" + codeFrame(replacement, loc.line, loc.column + 1); @@ -85,7 +91,7 @@ export function replaceWithSourceString(replacement) { * Replace the current node with another. */ -export function replaceWith(replacement, whateverAllowed) { +export function replaceWith(replacement) { this.resync(); if (this.removed) { @@ -97,7 +103,7 @@ export function replaceWith(replacement, whateverAllowed) { } if (!replacement) { - throw new Error("You passed `path.replaceWith()` a falsy node, use `path.dangerouslyRemove()` instead"); + throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead"); } if (this.node === replacement) { @@ -108,23 +114,12 @@ export function replaceWith(replacement, whateverAllowed) { throw new Error("You can only replace a Program root node with another Program node"); } - // normalise inserting an entire AST - if (t.isProgram(replacement) && !this.isProgram()) { - replacement = replacement.body; - whateverAllowed = true; - } - if (Array.isArray(replacement)) { - if (whateverAllowed) { - return this.replaceWithMultiple(replacement); - } else { - throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`"); - } + throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`"); } if (typeof replacement === "string") { - // triggers an error - return this.replaceWithSourceString(); + throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`"); } // replacing a statement with an expression so wrap it in an expression statement @@ -149,6 +144,9 @@ export function replaceWith(replacement, whateverAllowed) { // potentially create new scope this.setScope(); + + // requeue for visiting + this.requeue(); } /** @@ -156,10 +154,14 @@ export function replaceWith(replacement, whateverAllowed) { */ export function _replaceWith(node) { + if (!this.container) { + throw new ReferenceError("Container is falsy"); + } + if (this.inList) { - t.validate(this.key, this.parent, [node]); + t.validate(this.parent, this.key, [node]); } else { - t.validate(this.key, this.parent, node); + t.validate(this.parent, this.key, node); } this.node = this.container[this.key] = node; @@ -171,34 +173,50 @@ export function _replaceWith(node) { * extremely important to retain original semantics. */ -export function replaceExpressionWithStatements(nodes: Array) { +export function replaceExpressionWithStatements(nodes: Array) { this.resync(); - var toSequenceExpression = t.toSequenceExpression(nodes, this.scope); + let toSequenceExpression = t.toSequenceExpression(nodes, this.scope); - if (toSequenceExpression) { - return this.replaceWith(toSequenceExpression); + if (t.isSequenceExpression(toSequenceExpression)) { + let exprs = toSequenceExpression.expressions; + + if (exprs.length >= 2 && this.parentPath.isExpressionStatement()) { + this._maybePopFromStatements(exprs); + } + + // could be just one element due to the previous maybe popping + if (exprs.length === 1) { + this.replaceWith(exprs[0]); + } else { + this.replaceWith(toSequenceExpression); + } + } else if (toSequenceExpression) { + this.replaceWith(toSequenceExpression); } else { - var container = t.functionExpression(null, [], t.blockStatement(nodes)); + let container = t.functionExpression(null, [], t.blockStatement(nodes)); container.shadow = true; this.replaceWith(t.callExpression(container, [])); this.traverse(hoistVariablesVisitor); // add implicit returns to all ending expression statements - var last = this.get("callee").getCompletionRecords(); - for (var lastNode of (last: Array)) { - if (!lastNode.isExpressionStatement()) continue; + let completionRecords: Array = this.get("callee").getCompletionRecords(); + for (let path of completionRecords) { + if (!path.isExpressionStatement()) continue; - var loop = lastNode.findParent((path) => path.isLoop()); + let loop = path.findParent((path) => path.isLoop()); if (loop) { - var uid = this.get("callee").scope.generateDeclaredUidIdentifier("ret"); - this.get("callee.body").pushContainer("body", t.returnStatement(uid)); - lastNode.get("expression").replaceWith( - t.assignmentExpression("=", uid, lastNode.node.expression) + let callee = this.get("callee"); + + let uid = callee.scope.generateDeclaredUidIdentifier("ret"); + callee.get("body").pushContainer("body", t.returnStatement(uid)); + + path.get("expression").replaceWith( + t.assignmentExpression("=", uid, path.node.expression) ); } else { - lastNode.replaceWith(t.returnStatement(lastNode.node.expression)); + path.replaceWith(t.returnStatement(path.node.expression)); } } @@ -206,14 +224,14 @@ export function replaceExpressionWithStatements(nodes: Array) { } } -export function replaceInline(nodes) { +export function replaceInline(nodes: Object | Array) { this.resync(); if (Array.isArray(nodes)) { if (Array.isArray(this.container)) { nodes = this._verifyNodeList(nodes); this._containerInsertAfter(nodes); - return this.dangerouslyRemove(); + return this.remove(); } else { return this.replaceWithMultiple(nodes); } diff --git a/packages/babel-traverse/src/scope/binding.js b/packages/babel-traverse/src/scope/binding.js index 680e181ed5..fc1f69100e 100644 --- a/packages/babel-traverse/src/scope/binding.js +++ b/packages/babel-traverse/src/scope/binding.js @@ -1,3 +1,7 @@ +/* @flow */ + +import type NodePath from "../path"; + /** * This class is responsible for a binding inside of a scope. * @@ -11,21 +15,17 @@ export default class Binding { constructor({ existing, identifier, scope, path, kind }) { - this.constantViolations = []; - this.constant = true; - this.identifier = identifier; + this.scope = scope; + this.path = path; + this.kind = kind; + + this.constantViolations = []; + this.constant = true; + this.referencePaths = []; - this.references = 0; this.referenced = false; - - this.scope = scope; - this.path = path; - this.kind = kind; - - this.hasValue = false; - this.hasDeoptedValue = false; - this.value = null; + this.references = 0; this.clearValue(); @@ -38,6 +38,18 @@ export default class Binding { } } + + constantViolations: Array; + constant: boolean; + + referencePaths: Array; + referenced: boolean; + references: number; + + hasDeoptedValue: boolean; + hasValue: boolean; + value: any; + deoptValue() { this.clearValue(); this.hasDeoptedValue = true; @@ -68,7 +80,7 @@ export default class Binding { * Increment the amount of references to this binding. */ - reference(path) { + reference(path: NodePath) { this.referenced = true; this.references++; this.referencePaths.push(path) diff --git a/packages/babel-traverse/src/scope/index.js b/packages/babel-traverse/src/scope/index.js index 5a3669da5f..897730f7ef 100644 --- a/packages/babel-traverse/src/scope/index.js +++ b/packages/babel-traverse/src/scope/index.js @@ -1,138 +1,113 @@ +/* @flow */ + import includes from "lodash/collection/includes"; import repeating from "repeating"; +import Renamer from "./lib/renamer"; import type NodePath from "../path"; import traverse from "../index"; import defaults from "lodash/object/defaults"; import * as messages from "babel-messages"; import Binding from "./binding"; import globals from "globals"; -import flatten from "lodash/array/flatten"; import extend from "lodash/object/extend"; import * as t from "babel-types"; -var collectorVisitor = { +const SCOPE_INFO_CACHE_KEY = "_scopeInfo"; //Symbol(); - For(node, parent, scope) { - for (var key of (t.FOR_INIT_KEYS: Array)) { - var declar = this.get(key); - if (declar.isVar()) scope.getFunctionParent().registerBinding("var", declar); +let collectorVisitor = { + For(path) { + for (let key of (t.FOR_INIT_KEYS: Array)) { + let declar = path.get(key); + if (declar.isVar()) path.scope.getFunctionParent().registerBinding("var", declar); } }, - Declaration(node, parent, scope) { + Declaration(path) { // delegate block scope handling to the `blockVariableVisitor` - if (this.isBlockScoped()) return; + if (path.isBlockScoped()) return; // this will be hit again once we traverse into it after this iteration - if (this.isExportDeclaration() && this.get("declaration").isDeclaration()) return; + if (path.isExportDeclaration() && path.get("declaration").isDeclaration()) return; // we've ran into a declaration! - scope.getFunctionParent().registerDeclaration(this); + path.scope.getFunctionParent().registerDeclaration(path); }, - ReferencedIdentifier(node) { - var binding = this.scope.getBinding(node.name); - if (binding) { - binding.reference(this); - } else { - this.scope.getProgramParent().addGlobal(node); - } + ReferencedIdentifier(path, state) { + state.references.push(path); }, - ForXStatement() { - var left = this.get("left"); + ForXStatement(path, state) { + let left = path.get("left"); if (left.isPattern() || left.isIdentifier()) { - this.scope.registerConstantViolation(left, left); + state.constantViolations.push(left); } }, ExportDeclaration: { - exit(node) { - var declar = node.declaration; + exit({ node, scope }) { + let declar = node.declaration; if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) { - this.scope.getBinding(declar.id.name).reference(); + let id = declar.id; + if (!id) return; + + let binding = scope.getBinding(id.name); + if (binding) binding.reference(); } else if (t.isVariableDeclaration(declar)) { - for (var decl of (declar.declarations: Array)) { - var ids = t.getBindingIdentifiers(decl); - for (var name in ids) { - this.scope.getBinding(name).reference(); + for (let decl of (declar.declarations: Array)) { + let ids = t.getBindingIdentifiers(decl); + for (let name in ids) { + let binding = scope.getBinding(name); + if (binding) binding.reference(); } } } } }, - LabeledStatement(node) { - this.scope.getProgramParent().addGlobal(node); - this.scope.getBlockParent().registerDeclaration(this); + LabeledStatement(path) { + path.scope.getProgramParent().addGlobal(path.node); + path.scope.getBlockParent().registerDeclaration(path); }, - AssignmentExpression() { - // register undeclared bindings as globals - var ids = this.getBindingIdentifiers(); - var programParent; - for (var name in ids) { - if (this.scope.getBinding(name)) continue; + AssignmentExpression(path, state) { + state.assignments.push(path); + }, - programParent = programParent || this.scope.getProgramParent(); - programParent.addGlobal(ids[name]); + UpdateExpression(path, state) { + state.constantViolations.push(path.get("argument")); + }, + + UnaryExpression(path, state) { + if (path.node.operator === "delete") { + state.constantViolations.push(path.get("argument")); } - - // register as constant violation - this.scope.registerConstantViolation(this, this.get("left"), this.get("right")); }, - UpdateExpression(node, parent, scope) { - scope.registerConstantViolation(this, this.get("argument"), null); + BlockScoped(path) { + let scope = path.scope; + if (scope.path === path) scope = scope.parent; + scope.getBlockParent().registerDeclaration(path); }, - UnaryExpression(node, parent, scope) { - if (node.operator === "delete") scope.registerConstantViolation(this, this.get("left"), null); + ClassDeclaration(path) { + let id = path.node.id; + if (!id) return; + + let name = id.name; + path.scope.bindings[name] = path.scope.getBinding(name); }, - BlockScoped(node, parent, scope) { - if (scope.path === this) scope = scope.parent; - scope.getBlockParent().registerDeclaration(this); - }, - - ClassDeclaration(node, parent, scope) { - var name = node.id.name; - scope.bindings[name] = scope.getBinding(name); - }, - - Block(node, parent, scope) { - var paths = this.get("body"); - for (var path of (paths: Array)) { - if (path.isFunctionDeclaration()) { - scope.getBlockParent().registerDeclaration(path); + Block(path) { + let paths = path.get("body"); + for (let bodyPath of (paths: Array)) { + if (bodyPath.isFunctionDeclaration()) { + path.scope.getBlockParent().registerDeclaration(bodyPath); } } } }; -var renameVisitor = { - - ReferencedIdentifier(node, parent, scope, state) { - if (node.name === state.oldName) { - node.name = state.newName; - } - }, - - Scope(node, parent, scope, state) { - if (!scope.bindingIdentifierEquals(state.oldName, state.binding)) { - this.skip(); - } - }, - - "AssignmentExpression|Declaration"(node, parent, scope, state) { - var ids = this.getBindingIdentifiers(); - - for (var name in ids) { - if (name === state.oldName) ids[name].name = state.newName; - } - } -}; - export default class Scope { /** @@ -145,7 +120,7 @@ export default class Scope { return parent; } - var cached = path.getData("scope"); + let cached = path.getData("scope"); if (cached && cached.parent === parent && cached.block === path.node) { return cached; } else { @@ -164,7 +139,7 @@ export default class Scope { * Globals. */ - static globals = flatten([globals.builtin, globals.browser, globals.node].map(Object.keys)); + static globals = Object.keys(globals.builtin); /** * Variables available in current context. @@ -190,7 +165,7 @@ export default class Scope { */ generateDeclaredUidIdentifier(name: string = "temp") { - var id = this.generateUidIdentifier(name); + let id = this.generateUidIdentifier(name); this.push({ id }); return id; } @@ -208,17 +183,16 @@ export default class Scope { */ generateUid(name: string) { - name = t.toIdentifier(name).replace(/^_+/, ""); + name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, ""); - var uid; - var i = 0; + let uid; + let i = 0; do { uid = this._generateUid(name, i); i++; } while (this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid)); - - var program = this.getProgramParent(); + let program = this.getProgramParent(); program.references[uid] = true; program.uids[uid] = true; @@ -230,7 +204,7 @@ export default class Scope { */ _generateUid(name, i) { - var id = name; + let id = name; if (i > 1) id += i; return `_${id}`; } @@ -240,24 +214,24 @@ export default class Scope { */ generateUidIdentifierBasedOnNode(parent: Object, defaultName?: String): Object { - var node = parent; + let node = parent; if (t.isAssignmentExpression(parent)) { node = parent.left; } else if (t.isVariableDeclarator(parent)) { node = parent.id; - } else if (t.isProperty(node)) { + } else if (t.isObjectProperty(node) || t.isObjectMethod(node)) { node = node.key; } - var parts = []; + let parts = []; - var add = function (node) { + let add = function (node) { if (t.isModuleDeclaration(node)) { if (node.source) { add(node.source); } else if (node.specifiers && node.specifiers.length) { - for (var specifier of (node.specifiers: Array)) { + for (let specifier of (node.specifiers: Array)) { add(specifier); } } else if (node.declaration) { @@ -275,7 +249,7 @@ export default class Scope { } else if (t.isCallExpression(node)) { add(node.callee); } else if (t.isObjectExpression(node) || t.isObjectPattern(node)) { - for (var prop of (node.properties: Array)) { + for (let prop of (node.properties: Array)) { add(prop.key || prop.argument); } } @@ -283,7 +257,7 @@ export default class Scope { add(node); - var id = parts.join("$"); + let id = parts.join("$"); id = id.replace(/^_/, "") || defaultName || "ref"; return this.generateUidIdentifier(id.slice(0, 20)); @@ -305,7 +279,7 @@ export default class Scope { } if (t.isIdentifier(node)) { - var binding = this.getBinding(node.name); + let binding = this.getBinding(node.name); if (binding) { return binding.constant; } else { @@ -324,7 +298,7 @@ export default class Scope { if (this.isStatic(node)) { return null; } else { - var id = this.generateUidIdentifierBasedOnNode(node); + let id = this.generateUidIdentifierBasedOnNode(node); if (!dontPush) this.push({ id }); return id; } @@ -337,7 +311,7 @@ export default class Scope { // ignore hoisted functions if there's also a local let if (kind === "hoisted" && local.kind === "let") return; - var duplicate = false; + let duplicate = false; // don't allow duplicate bindings to exist alongside if (!duplicate) duplicate = kind === "let" || local.kind === "let" || local.kind === "const" || local.kind === "module"; @@ -346,7 +320,7 @@ export default class Scope { if (!duplicate) duplicate = local.kind === "param" && (kind === "let" || kind === "const"); if (duplicate) { - throw this.hub.file.errorWithNode(id, messages.get("scopeDuplicateDeclaration", name), TypeError); + throw this.hub.file.buildCodeFrameError(id, messages.get("scopeDuplicateDeclaration", name), TypeError); } } @@ -366,16 +340,17 @@ export default class Scope { } dump() { - var sep = repeating("-", 60); + let sep = repeating("-", 60); console.log(sep); - var scope = this; + let scope = this; do { console.log("#", scope.block.type); - for (var name in scope.bindings) { - var binding = scope.bindings[name]; + for (let name in scope.bindings) { + let binding = scope.bindings[name]; console.log(" -", name, { constant: binding.constant, references: binding.references, + violations: binding.constantViolations.length, kind: binding.kind }); } @@ -384,10 +359,10 @@ export default class Scope { } toArray(node: Object, i?: number) { - var file = this.hub.file; + let file = this.hub.file; if (t.isIdentifier(node)) { - var binding = this.getBinding(node.name); + let binding = this.getBinding(node.name); if (binding && binding.constant && binding.path.isGenericType("Array")) return node; } @@ -396,17 +371,29 @@ export default class Scope { } if (t.isIdentifier(node, { name: "arguments" })) { - return t.callExpression(t.memberExpression(file.addHelper("slice"), t.identifier("call")), [node]); + return t.callExpression( + t.memberExpression( + t.memberExpression( + t.memberExpression( + t.identifier("Array"), + t.identifier("prototype") + ), + t.identifier("slice") + ), + t.identifier("call") + ), + [node] + ); } - var helperName = "to-array"; - var args = [node]; + let helperName = "toArray"; + let args = [node]; if (i === true) { - helperName = "to-consumable-array"; + helperName = "toConsumableArray"; } else if (i) { - args.push(t.literal(i)); - helperName = "sliced-to-array"; - if (this.hub.file.isLoose("es6.forOf")) helperName += "-loose"; + args.push(t.numberLiteral(i)); + helperName = "slicedToArray"; + // TODO if (this.hub.file.isLoose("es6.forOf")) helperName += "-loose"; } return t.callExpression(file.addHelper(helperName), args); } @@ -415,17 +402,17 @@ export default class Scope { if (path.isLabeledStatement()) { this.registerBinding("label", path); } else if (path.isFunctionDeclaration()) { - this.registerBinding("hoisted", path); + this.registerBinding("hoisted", path.get("id")); } else if (path.isVariableDeclaration()) { - var declarations = path.get("declarations"); + let declarations = path.get("declarations"); for (let declar of (declarations: Array)) { this.registerBinding(path.node.kind, declar); } } else if (path.isClassDeclaration()) { this.registerBinding("let", path); } else if (path.isImportDeclaration()) { - var specifiers = path.get("specifiers"); - for (var specifier of (specifiers: Array)) { + let specifiers = path.get("specifiers"); + for (let specifier of (specifiers: Array)) { this.registerBinding("module", specifier); } } else if (path.isExportDeclaration()) { @@ -446,11 +433,11 @@ export default class Scope { } } - registerConstantViolation(root: NodePath, left: NodePath, right: NodePath) { - var ids = left.getBindingIdentifiers(); - for (var name in ids) { - var binding = this.getBinding(name); - if (binding) binding.reassign(root, left, right); + registerConstantViolation(path: NodePath) { + let ids = path.getBindingIdentifiers(); + for (let name in ids) { + let binding = this.getBinding(name); + if (binding) binding.reassign(path); } } @@ -458,19 +445,19 @@ export default class Scope { if (!kind) throw new ReferenceError("no `kind`"); if (path.isVariableDeclaration()) { - var declarators = path.get("declarations"); - for (var declar of (declarators: Array)) { + let declarators: Array = path.get("declarations"); + for (let declar of declarators) { this.registerBinding(kind, declar); } return; } - var parent = this.getProgramParent(); - var ids = path.getBindingIdentifiers(true); + let parent = this.getProgramParent(); + let ids = path.getBindingIdentifiers(true); - for (var name in ids) { - for (var id of (ids[name]: Array)) { - var local = this.getOwnBinding(name); + for (let name in ids) { + for (let id of (ids[name]: Array)) { + let local = this.getOwnBinding(name); if (local) { // same identifier so continue safely as we're likely trying to register it // multiple times @@ -497,7 +484,7 @@ export default class Scope { } hasUid(name): boolean { - var scope = this; + let scope = this; do { if (scope.uids[name]) return true; @@ -507,7 +494,7 @@ export default class Scope { } hasGlobal(name: string): boolean { - var scope = this; + let scope = this; do { if (scope.globals[name]) return true; @@ -517,7 +504,7 @@ export default class Scope { } hasReference(name: string): boolean { - var scope = this; + let scope = this; do { if (scope.references[name]) return true; @@ -528,29 +515,39 @@ export default class Scope { isPure(node, constantsOnly?: boolean) { if (t.isIdentifier(node)) { - var binding = this.getBinding(node.name); + let binding = this.getBinding(node.name); if (!binding) return false; if (constantsOnly) return binding.constant; return true; } else if (t.isClass(node)) { - return !node.superClass || this.isPure(node.superClass, constantsOnly); + if (node.superClass && !this.isPure(node.superClass, constantsOnly)) return false; + return this.isPure(node.body, constantsOnly); + } else if (t.isClassBody(node)) { + for (let method of node.body) { + if (!this.isPure(method, constantsOnly)) return false; + } + return true; } else if (t.isBinary(node)) { return this.isPure(node.left, constantsOnly) && this.isPure(node.right, constantsOnly); } else if (t.isArrayExpression(node)) { - for (var elem of (node.elements: Array)) { + for (let elem of (node.elements: Array)) { if (!this.isPure(elem, constantsOnly)) return false; } return true; } else if (t.isObjectExpression(node)) { - for (var prop of (node.properties: Array)) { + for (let prop of (node.properties: Array)) { if (!this.isPure(prop, constantsOnly)) return false; } return true; - } else if (t.isProperty(node)) { + } else if (t.isClassMethod(node)) { + if (node.computed && !this.isPure(node.key, constantsOnly)) return false; + if (node.kind === "get" || node.kind === "set") return false; + return true; + } else if (t.isClassProperty(node)) { if (node.computed && !this.isPure(node.key, constantsOnly)) return false; return this.isPure(node.value, constantsOnly); } else { - return t.isPure(node); + return t.isPureish(node); } } @@ -567,9 +564,9 @@ export default class Scope { */ getData(key) { - var scope = this; + let scope = this; do { - var data = scope.data[key]; + let data = scope.data[key]; if (data != null) return data; } while(scope = scope.parent); } @@ -580,9 +577,9 @@ export default class Scope { */ removeData(key) { - var scope = this; + let scope = this; do { - var data = scope.data[key]; + let data = scope.data[key]; if (data != null) scope.data[key] = null; } while(scope = scope.parent); } @@ -592,14 +589,14 @@ export default class Scope { } crawl() { - var path = this.path; + let path = this.path; // - var info = this.block._scopeInfo; + let info = this.block[SCOPE_INFO_CACHE_KEY]; if (info) return extend(this, info); - info = this.block._scopeInfo = { + info = this.block[SCOPE_INFO_CACHE_KEY] = { references: Object.create(null), bindings: Object.create(null), globals: Object.create(null), @@ -607,13 +604,13 @@ export default class Scope { data: Object.create(null), }; - extend(this, info); + Object.assign(this, info); // ForStatement - left, init if (path.isLoop()) { - for (let key of (t.FOR_INIT_KEYS: Array)) { - var node = path.get(key); + for (let key of (t.FOR_INIT_KEYS: Array)) { + let node = path.get(key); if (node.isBlockScoped()) this.registerBinding(node.node.kind, node); } } @@ -621,22 +618,20 @@ export default class Scope { // FunctionExpression - id if (path.isFunctionExpression() && path.has("id")) { - if (!t.isProperty(path.parent, { method: true })) { - this.registerBinding("var", path); - } + this.registerBinding("local", path); } // Class if (path.isClassExpression() && path.has("id")) { - this.registerBinding("var", path); + this.registerBinding("local", path); } // Function - params, rest if (path.isFunction()) { - var params = path.get("params"); - for (let param of (params: Array)) { + let params: Array = path.get("params"); + for (let param of params) { this.registerBinding("param", param); } } @@ -647,24 +642,61 @@ export default class Scope { this.registerBinding("let", path); } - // ComprehensionExpression - blocks - - if (path.isComprehensionExpression()) { - this.registerBinding("let", path); - } - // Program - var parent = this.getProgramParent(); + let parent = this.getProgramParent(); if (parent.crawling) return; + let state = { + references: [], + constantViolations: [], + assignments: [], + }; + this.crawling = true; - path.traverse(collectorVisitor); + path.traverse(collectorVisitor, state); this.crawling = false; + + // register assignments + for (let path of state.assignments) { + // register undeclared bindings as globals + let ids = path.getBindingIdentifiers(); + let programParent; + for (let name in ids) { + if (path.scope.getBinding(name)) continue; + + programParent = programParent || path.scope.getProgramParent(); + programParent.addGlobal(ids[name]); + } + + // register as constant violation + path.scope.registerConstantViolation(path); + } + + // register references + for (let ref of state.references) { + let binding = ref.scope.getBinding(ref.node.name); + if (binding) { + binding.reference(ref); + } else { + ref.scope.getProgramParent().addGlobal(ref.node); + } + } + + // register constant violations + for (let path of state.constantViolations) { + path.scope.registerConstantViolation(path); + } } - push(opts: Object) { - var path = this.path; + push(opts: { + id: Object; + init: ?Object; + unique: ?boolean; + _blockHoist: ?number; + kind: "var" | "let"; + }) { + let path = this.path; if (path.isSwitchStatement()) { path = this.getFunctionParent().path; @@ -679,25 +711,23 @@ export default class Scope { path = this.getBlockParent().path; } - var unique = opts.unique; - var kind = opts.kind || "var"; - var blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist; + let unique = opts.unique; + let kind = opts.kind || "var"; + let blockHoist = opts._blockHoist == null ? 2 : opts._blockHoist; - var dataKey = `declaration:${kind}:${blockHoist}`; - var declarPath = !unique && path.getData(dataKey); + let dataKey = `declaration:${kind}:${blockHoist}`; + let declarPath = !unique && path.getData(dataKey); if (!declarPath) { - var declar = t.variableDeclaration(kind, []); + let declar = t.variableDeclaration(kind, []); declar._generated = true; declar._blockHoist = blockHoist; - this.hub.file.attachAuxiliaryComment(declar); - [declarPath] = path.unshiftContainer("body", [declar]); if (!unique) path.setData(dataKey, declarPath); } - var declarator = t.variableDeclarator(opts.id, opts.init); + let declarator = t.variableDeclarator(opts.id, opts.init); declarPath.node.declarations.push(declarator); this.registerBinding(kind, declarPath.get("declarations").pop()); } @@ -707,7 +737,7 @@ export default class Scope { */ getProgramParent() { - var scope = this; + let scope = this; do { if (scope.path.isProgram()) { return scope; @@ -722,7 +752,7 @@ export default class Scope { */ getFunctionParent() { - var scope = this; + let scope = this; do { if (scope.path.isFunctionParent()) { return scope; @@ -737,7 +767,7 @@ export default class Scope { */ getBlockParent() { - var scope = this; + let scope = this; do { if (scope.path.isBlockParent()) { return scope; @@ -751,9 +781,9 @@ export default class Scope { */ getAllBindings(): Object { - var ids = Object.create(null); + let ids = Object.create(null); - var scope = this; + let scope = this; do { defaults(ids, scope.bindings); scope = scope.parent; @@ -767,13 +797,13 @@ export default class Scope { */ getAllBindingsOfKind(): Object { - var ids = Object.create(null); + let ids = Object.create(null); for (let kind of (arguments: Array)) { - var scope = this; + let scope = this; do { - for (var name in scope.bindings) { - var binding = scope.bindings[name]; + for (let name in scope.bindings) { + let binding = scope.bindings[name]; if (binding.kind === kind) ids[name] = binding; } scope = scope.parent; @@ -788,10 +818,10 @@ export default class Scope { } getBinding(name: string) { - var scope = this; + let scope = this; do { - var binding = scope.getOwnBinding(name); + let binding = scope.getOwnBinding(name); if (binding) return binding; } while (scope = scope.parent); } @@ -801,12 +831,12 @@ export default class Scope { } getBindingIdentifier(name: string) { - var info = this.getBinding(name); + let info = this.getBinding(name); return info && info.identifier; } getOwnBindingIdentifier(name: string) { - var binding = this.bindings[name]; + let binding = this.bindings[name]; return binding && binding.identifier; } @@ -833,7 +863,7 @@ export default class Scope { */ moveBindingTo(name, scope) { - var info = this.getBinding(name); + let info = this.getBinding(name); if (info) { info.scope.removeOwnBinding(name); info.scope = scope; @@ -847,13 +877,13 @@ export default class Scope { removeBinding(name: string) { // clear literal binding - var info = this.getBinding(name); + let info = this.getBinding(name); if (info) { info.scope.removeOwnBinding(name); } // clear uids with this name - https://github.com/babel/babel/issues/2101 - var scope = this; + let scope = this; do { if (scope.uids[name]) { scope.uids[name] = false; diff --git a/packages/babel-traverse/src/scope/lib/renamer.js b/packages/babel-traverse/src/scope/lib/renamer.js index c5abc0d738..4e0bb608bb 100644 --- a/packages/babel-traverse/src/scope/lib/renamer.js +++ b/packages/babel-traverse/src/scope/lib/renamer.js @@ -37,7 +37,7 @@ export default class Renamer { binding: Binding; maybeConvertFromExportDeclaration(parentDeclar) { - let exportDeclar = parentDeclar && parentDeclar.parentPath.isExportDeclaration() && parentDeclar.parentPath; + let exportDeclar = parentDeclar.parentPath.isExportDeclaration() && parentDeclar.parentPath; if (!exportDeclar) return; // build specifiers that point back to this export declaration @@ -63,6 +63,8 @@ export default class Renamer { } maybeConvertFromClassFunctionDeclaration(path) { + return; // TODO + // retain the `name` of a class/function declaration if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return; @@ -77,6 +79,8 @@ export default class Renamer { } maybeConvertFromClassFunctionExpression(path) { + return; // TODO + // retain the `name` of a class/function expression if (!path.isFunctionExpression() && !path.isClassExpression()) return; @@ -96,7 +100,9 @@ export default class Renamer { let { scope, path } = binding; let parentDeclar = path.find((path) => path.isDeclaration() || path.isFunctionExpression()); - this.maybeConvertFromExportDeclaration(parentDeclar); + if (parentDeclar) { + this.maybeConvertFromExportDeclaration(parentDeclar); + } scope.traverse(block || scope.block, renameVisitor, this); @@ -111,7 +117,9 @@ export default class Renamer { // todo: hoist and convert function to a let } - this.maybeConvertFromClassFunctionDeclaration(parentDeclar); - this.maybeConvertFromClassFunctionExpression(parentDeclar); + if (parentDeclar) { + this.maybeConvertFromClassFunctionDeclaration(parentDeclar); + this.maybeConvertFromClassFunctionExpression(parentDeclar); + } } } diff --git a/packages/babel-traverse/src/visitors.js b/packages/babel-traverse/src/visitors.js index 4e33b083f0..3562d6f483 100644 --- a/packages/babel-traverse/src/visitors.js +++ b/packages/babel-traverse/src/visitors.js @@ -1,3 +1,5 @@ +/* @flow */ + import * as virtualTypes from "./path/lib/virtual-types"; import * as messages from "babel-messages"; import * as t from "babel-types"; @@ -22,22 +24,6 @@ export function explode(visitor) { } } - // normalise colons - for (let nodeType in visitor) { - if (shouldIgnoreKey(nodeType)) continue; - - let parts = nodeType.split(":"); - if (parts.length === 1) continue; - - let fns = visitor[nodeType]; - delete visitor[nodeType]; - - nodeType = parts[0]; - - visitor[nodeType] = visitor[nodeType] || {}; - visitor[nodeType][parts[1]] = fns; - } - // verify data structure verify(visitor); @@ -55,7 +41,7 @@ export function explode(visitor) { for (let nodeType of (Object.keys(visitor): Array)) { if (shouldIgnoreKey(nodeType)) continue; - var wrapper = virtualTypes[nodeType]; + let wrapper = virtualTypes[nodeType]; if (!wrapper) continue; // wrap all the functions @@ -87,14 +73,14 @@ export function explode(visitor) { let fns = visitor[nodeType]; - var aliases = t.FLIPPED_ALIAS_KEYS[nodeType]; + let aliases = t.FLIPPED_ALIAS_KEYS[nodeType]; if (!aliases) continue; // clear it from the visitor delete visitor[nodeType]; - for (var alias of (aliases: Array)) { - var existing = visitor[alias]; + for (let alias of (aliases: Array)) { + let existing = visitor[alias]; if (existing) { mergePair(existing, fns); } else { @@ -119,16 +105,16 @@ export function verify(visitor) { throw new Error(messages.get("traverseVerifyRootFunction")); } - for (var nodeType in visitor) { + for (let nodeType in visitor) { if (shouldIgnoreKey(nodeType)) continue; if (t.TYPES.indexOf(nodeType) < 0) { throw new Error(messages.get("traverseVerifyNodeType", nodeType)); } - var visitors = visitor[nodeType]; + let visitors = visitor[nodeType]; if (typeof visitors === "object") { - for (var visitorKey in visitors) { + for (let visitorKey in visitors) { if (visitorKey === "enter" || visitorKey === "exit") continue; throw new Error(messages.get("traverseVerifyVisitorProperty", nodeType, visitorKey)); } @@ -138,15 +124,47 @@ export function verify(visitor) { visitor._verified = true; } -export function merge(visitors) { - var rootVisitor = {}; +export function merge(visitors: Array, states: Array = []) { + let rootVisitor = {}; + + for (let i = 0; i < visitors.length; i++) { + let visitor = visitors[i]; + let state = states[i]; - for (var visitor of (visitors: Array)) { explode(visitor); - for (var type in visitor) { - var nodeVisitor = rootVisitor[type] = rootVisitor[type] || {}; - mergePair(nodeVisitor, visitor[type]); + for (let type in visitor) { + let visitorType = visitor[type]; + + // if we have state then overload the callbacks to take it + if (state) { + let oldVisitorType = visitorType; + visitorType = {}; + + for (let key in oldVisitorType) { + let fns = oldVisitorType[key]; + + // not an enter/exit array of callbacks + if (!Array.isArray(fns)) continue; + + fns = fns.map(function (fn) { + if (typeof fn === "function") { + let newFn = function (path) { + return fn.call(state, path, state); + }; + newFn.toString = () => fn.toString(); + return newFn; + } else { + return fn; + } + }); + + visitorType[key] = fns; + } + } + + let nodeVisitor = rootVisitor[type] = rootVisitor[type] || {}; + mergePair(nodeVisitor, visitorType); } } @@ -157,7 +175,7 @@ function ensureEntranceObjects(obj) { for (let key in obj) { if (shouldIgnoreKey(key)) continue; - var fns = obj[key]; + let fns = obj[key]; if (typeof fns === "function") { obj[key] = { enter: fns }; } @@ -170,11 +188,13 @@ function ensureCallbackArrays(obj){ } function wrapCheck(wrapper, fn) { - return function () { - if (wrapper.checkPath(this)) { + let newFn = function (path) { + if (wrapper.checkPath(path)) { return fn.apply(this, arguments); } }; + newFn.toString = () => fn.toString(); + return newFn; } function shouldIgnoreKey(key) { @@ -191,7 +211,7 @@ function shouldIgnoreKey(key) { } function mergePair(dest, src) { - for (var key in src) { + for (let key in src) { dest[key] = [].concat(dest[key] || [], src[key]); } } diff --git a/packages/babel-core/test/traverse.js b/packages/babel-traverse/test/traverse.js similarity index 96% rename from packages/babel-core/test/traverse.js rename to packages/babel-traverse/test/traverse.js index 259cf81877..b2cc301171 100644 --- a/packages/babel-core/test/traverse.js +++ b/packages/babel-traverse/test/traverse.js @@ -1,4 +1,4 @@ -var traverse = require("babel-traverse"); +var traverse = require("../lib").default; var assert = require("assert"); var _ = require("lodash"); @@ -61,7 +61,7 @@ suite("traverse", function () { traverse(ast2, { enter: function (path) { - if (path.node.type === "ThisExpression") return replacement; + if (path.node.type === "ThisExpression") path.replaceWith(replacement); } }); diff --git a/packages/babel-types/package.json b/packages/babel-types/package.json index 3251d6f52d..c15fd1f79d 100644 --- a/packages/babel-types/package.json +++ b/packages/babel-types/package.json @@ -1,6 +1,6 @@ { "name": "babel-types", - "version": "5.8.22", + "version": "5.10.32", "description": "", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,9 +8,10 @@ "repository": "babel/babel", "main": "lib/index.js", "dependencies": { + "babel-runtime": "^5.10.32", + "babel-traverse": "^5.10.32", "esutils": "^2.0.2", "lodash": "^3.10.1", - "to-fast-properties": "^1.0.1", - "babel-traverse": "^5.8.22" + "to-fast-properties": "^1.0.1" } -} +} \ No newline at end of file diff --git a/packages/babel-types/src/converters.js b/packages/babel-types/src/converters.js index 694df04240..5a58984a81 100644 --- a/packages/babel-types/src/converters.js +++ b/packages/babel-types/src/converters.js @@ -1,3 +1,5 @@ +/* @flow */ + import isPlainObject from "lodash/lang/isPlainObject"; import isNumber from "lodash/lang/isNumber"; import isRegExp from "lodash/lang/isRegExp"; @@ -22,13 +24,13 @@ export function toComputedKey(node: Object, key: Object = node.key || node.prope * Expression statements are just resolved to their expression. */ -export function toSequenceExpression(nodes: Array, scope: Scope): Object { +export function toSequenceExpression(nodes: Array, scope: Scope): ?Object { if (!nodes || !nodes.length) return; - var declars = []; - var bailed = false; + let declars = []; + let bailed = false; - var result = convert(nodes); + let result = convert(nodes); if (bailed) return; for (let i = 0; i < declars.length; i++) { @@ -38,8 +40,8 @@ export function toSequenceExpression(nodes: Array, scope: Scope): Object return result; function convert(nodes) { - var ensureLastUndefined = false; - var exprs = []; + let ensureLastUndefined = false; + let exprs = []; for (let node of (nodes: Array)) { if (t.isExpression(node)) { @@ -49,9 +51,9 @@ export function toSequenceExpression(nodes: Array, scope: Scope): Object } else if (t.isVariableDeclaration(node)) { if (node.kind !== "var") return bailed = true; // bailed - for (var declar of (node.declarations: Array)) { - var bindings = t.getBindingIdentifiers(declar); - for (var key in bindings) { + for (let declar of (node.declarations: Array)) { + let bindings = t.getBindingIdentifiers(declar); + for (let key in bindings) { declars.push({ kind: node.kind, id: bindings[key] @@ -66,8 +68,8 @@ export function toSequenceExpression(nodes: Array, scope: Scope): Object ensureLastUndefined = true; continue; } else if (t.isIfStatement(node)) { - var consequent = node.consequent ? convert([node.consequent]) : t.identifier("undefined"); - var alternate = node.alternate ? convert([node.alternate]) : t.identifier("undefined"); + let consequent = node.consequent ? convert([node.consequent]) : scope.buildUndefinedNode(); + let alternate = node.alternate ? convert([node.alternate]) : scope.buildUndefinedNode(); if (!consequent || !alternate) return bailed = true; exprs.push(t.conditionalExpression(node.test, consequent, alternate)); @@ -85,8 +87,8 @@ export function toSequenceExpression(nodes: Array, scope: Scope): Object ensureLastUndefined = false; } - if (ensureLastUndefined) { - exprs.push(t.identifier("undefined")); + if (ensureLastUndefined || exprs.length === 0) { + exprs.push(scope.buildUndefinedNode()); } // @@ -99,11 +101,11 @@ export function toSequenceExpression(nodes: Array, scope: Scope): Object } } -export function toKeyAlias(node: Object, key: Object = node.key) { - var alias; +export function toKeyAlias(node: Object, key: Object = node.key): string { + let alias; if (node.kind === "method") { - return toKeyAlias.uid++; + return toKeyAlias.increment() + ""; } else if (t.isIdentifier(key)) { alias = key.name; } else if (t.isStringLiteral(key)) { @@ -116,14 +118,24 @@ export function toKeyAlias(node: Object, key: Object = node.key) { alias = `[${alias}]`; } + if (node.static) { + alias = `static:${alias}`; + } + return alias; } toKeyAlias.uid = 0; -export function toIdentifier(name: string): string { - if (t.isIdentifier(name)) return name.name; +toKeyAlias.increment = function () { + if (toKeyAlias.uid >= Number.MAX_SAFE_INTEGER) { + return toKeyAlias.uid = 0; + } else { + return toKeyAlias.uid++; + } +}; +export function toIdentifier(name: string): string { name = name + ""; // replace all non-valid identifiers with dashes @@ -144,7 +156,7 @@ export function toIdentifier(name: string): string { return name || "_"; } -export function toBindingIdentifierName(name) { +export function toBindingIdentifierName(name: string): string { name = toIdentifier(name); if (name === "eval" || name === "arguments") name = "_" + name; return name; @@ -160,8 +172,8 @@ export function toStatement(node: Object, ignore?: boolean) { return node; } - var mustHaveId = false; - var newType; + let mustHaveId = false; + let newType; if (t.isClass(node)) { mustHaveId = true; @@ -208,7 +220,7 @@ export function toExpression(node: Object): Object { } } -export function toBlock(node: Object, parent: Object): Object { +export function toBlock(node, parent: Object): Object { if (t.isBlockStatement(node)) { return node; } @@ -260,8 +272,8 @@ export function valueToNode(value: any): Object { // regexes if (isRegExp(value)) { - var pattern = value.source; - var flags = value.toString().match(/\/([a-z]+|)$/)[1]; + let pattern = value.source; + let flags = value.toString().match(/\/([a-z]+|)$/)[1]; return t.regexLiteral(pattern, flags); } @@ -272,15 +284,15 @@ export function valueToNode(value: any): Object { // object if (isPlainObject(value)) { - var props = []; - for (var key in value) { - var nodeKey; + let props = []; + for (let key in value) { + let nodeKey; if (t.isValidIdentifier(key)) { nodeKey = t.identifier(key); } else { nodeKey = t.literal(key); } - props.push(t.property("init", nodeKey, t.valueToNode(value[key]))); + props.push(t.objectProperty(nodeKey, t.valueToNode(value[key]))); } return t.objectExpression(props); } diff --git a/packages/babel-types/src/definitions/core.js b/packages/babel-types/src/definitions/core.js index be0ba1387c..8927d95269 100644 --- a/packages/babel-types/src/definitions/core.js +++ b/packages/babel-types/src/definitions/core.js @@ -1,7 +1,15 @@ -import * as t from "../index"; -import define, { assertValueType, assertNodeType, assertEach, chain, assertOneOf } from "./index"; +/* @flow */ -define("ArrayExpression", { +import * as t from "../index"; +import defineType, { + assertValueType, + assertNodeType, + assertEach, + chain, + assertOneOf, +} from "./index"; + +defineType("ArrayExpression", { fields: { elements: { validate: assertValueType("array") @@ -11,18 +19,16 @@ define("ArrayExpression", { aliases: ["Expression"] }); -define("AssignmentExpression", { +defineType("AssignmentExpression", { fields: { - elements: { - operator: { - validate: assertValueType("string") - }, - left: { - validate: assertNodeType("LVal") - }, - right: { - validate: assertNodeType("Expression") - } + operator: { + validate: assertValueType("string") + }, + left: { + validate: assertNodeType("LVal") + }, + right: { + validate: assertNodeType("Expression") } }, builder: ["operator", "left", "right"], @@ -30,7 +36,7 @@ define("AssignmentExpression", { aliases: ["Expression"] }); -define("BinaryExpression", { +defineType("BinaryExpression", { builder: ["operator", "left", "right"], fields: { operator: { @@ -47,7 +53,17 @@ define("BinaryExpression", { aliases: ["Binary", "Expression"] }); -define("Directive", { +defineType("Directive", { + visitor: ["value"], + fields: { + value: { + validate: assertNodeType("DirectiveLiteral") + } + } +}); + +defineType("DirectiveLiteral", { + builder: ["value"], fields: { value: { validate: assertValueType("string") @@ -55,7 +71,7 @@ define("Directive", { } }); -define("BlockStatement", { +defineType("BlockStatement", { builder: ["body", "directives"], visitor: ["directives", "body"], fields: { @@ -70,7 +86,7 @@ define("BlockStatement", { aliases: ["Scopable", "BlockParent", "Block", "Statement"] }); -define("BreakStatement", { +defineType("BreakStatement", { visitor: ["label"], fields: { label: { @@ -81,7 +97,7 @@ define("BreakStatement", { aliases: ["Statement", "Terminatorless", "CompletionStatement"] }); -define("CallExpression", { +defineType("CallExpression", { visitor: ["callee", "arguments"], fields: { callee: { @@ -94,7 +110,7 @@ define("CallExpression", { aliases: ["Expression"] }); -define("CatchClause", { +defineType("CatchClause", { visitor: ["param", "body"], fields: { param: { @@ -107,7 +123,7 @@ define("CatchClause", { aliases: ["Scopable"] }); -define("ConditionalExpression", { +defineType("ConditionalExpression", { visitor: ["test", "consequent", "alternate"], fields: { test: { @@ -120,10 +136,10 @@ define("ConditionalExpression", { validate: assertNodeType("Expression") } }, - aliases: ["Expression"] + aliases: ["Expression", "Conditional"] }); -define("ContinueStatement", { +defineType("ContinueStatement", { visitor: ["label"], fields: { label: { @@ -134,11 +150,11 @@ define("ContinueStatement", { aliases: ["Statement", "Terminatorless", "CompletionStatement"] }); -define("DebuggerStatement", { +defineType("DebuggerStatement", { aliases: ["Statement"] }); -define("DoWhileStatement", { +defineType("DoWhileStatement", { visitor: ["test", "body"], fields: { test: { @@ -151,21 +167,21 @@ define("DoWhileStatement", { aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"] }); -define("EmptyStatement", { +defineType("EmptyStatement", { aliases: ["Statement"] }); -define("ExpressionStatement", { +defineType("ExpressionStatement", { visitor: ["expression"], fields: { expression: { validate: assertNodeType("Expression") } }, - aliases: ["Statement"] + aliases: ["Statement", "ExpressionWrapper"] }); -define("File", { +defineType("File", { builder: ["program", "comments", "tokens"], visitor: ["program"], fields: { @@ -175,7 +191,7 @@ define("File", { } }); -define("ForInStatement", { +defineType("ForInStatement", { visitor: ["left", "right", "body"], aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"], fields: { @@ -191,7 +207,7 @@ define("ForInStatement", { } }); -define("ForStatement", { +defineType("ForStatement", { visitor: ["init", "test", "update", "body"], aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop"], fields: { @@ -210,7 +226,7 @@ define("ForStatement", { } }); -define("FunctionDeclaration", { +defineType("FunctionDeclaration", { builder: ["id", "params", "body", "generator", "async"], visitor: ["id", "params", "body", "returnType", "typeParameters"], fields: { @@ -232,11 +248,20 @@ define("FunctionDeclaration", { validate: assertValueType("boolean") } }, - aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Statement", "Pure", "Declaration"] + aliases: [ + "Scopable", + "Function", + "BlockParent", + "FunctionParent", + "Statement", + "Pureish", + "Declaration" + ] }); -define("FunctionExpression", { - builder: ["id", "params", "body", "generator", "async"], +defineType("FunctionExpression", { + inherits: "FunctionDeclaration", + aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"], fields: { id: { validate: assertNodeType("Identifier"), @@ -256,12 +281,10 @@ define("FunctionExpression", { default: false, validate: assertValueType("boolean") } - }, - visitor: ["id", "params", "body", "returnType", "typeParameters"], - aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pure"] + } }); -define("Identifier", { +defineType("Identifier", { builder: ["name"], visitor: ["typeAnnotation"], aliases: ["Expression", "LVal"], @@ -276,9 +299,9 @@ define("Identifier", { } }); -define("IfStatement", { +defineType("IfStatement", { visitor: ["test", "consequent", "alternate"], - aliases: ["Statement"], + aliases: ["Statement", "Conditional"], fields: { test: { validate: assertNodeType("Expression") @@ -294,7 +317,7 @@ define("IfStatement", { } }); -define("LabeledStatement", { +defineType("LabeledStatement", { visitor: ["label", "body"], aliases: ["Statement"], fields: { @@ -307,41 +330,41 @@ define("LabeledStatement", { } }); -define("StringLiteral", { +defineType("StringLiteral", { builder: ["value"], fields: { value: { validate: assertValueType("string") } }, - aliases: ["Expression", "Pure", "Literal", "Immutable"] + aliases: ["Expression", "Pureish", "Literal", "Immutable"] }); -define("NumberLiteral", { +defineType("NumberLiteral", { builder: ["value"], fields: { value: { validate: assertValueType("number") } }, - aliases: ["Expression", "Pure", "Literal", "Immutable"] + aliases: ["Expression", "Pureish", "Literal", "Immutable"] }); -define("NullLiteral", { - aliases: ["Expression", "Pure", "Literal", "Immutable"] +defineType("NullLiteral", { + aliases: ["Expression", "Pureish", "Literal", "Immutable"] }); -define("BooleanLiteral", { +defineType("BooleanLiteral", { builder: ["value"], fields: { value: { validate: assertValueType("boolean") } }, - aliases: ["Expression", "Pure", "Literal", "Immutable"] + aliases: ["Expression", "Pureish", "Literal", "Immutable"] }); -define("RegexLiteral", { +defineType("RegexLiteral", { builder: ["pattern", "flags"], aliases: ["Expression", "Literal"], fields: { @@ -355,7 +378,7 @@ define("RegexLiteral", { } }); -define("LogicalExpression", { +defineType("LogicalExpression", { builder: ["operator", "left", "right"], visitor: ["left", "right"], aliases: ["Binary", "Expression"], @@ -372,7 +395,7 @@ define("LogicalExpression", { } }); -define("MemberExpression", { +defineType("MemberExpression", { builder: ["object", "property", "computed"], visitor: ["object", "property"], aliases: ["Expression", "LVal"], @@ -382,7 +405,7 @@ define("MemberExpression", { }, property: { validate(node, key, val) { - var expectedType = node.computed ? "Expression" : "Identifier"; + let expectedType = node.computed ? "Expression" : "Identifier"; assertNodeType(expectedType)(node, key, val); } }, @@ -392,7 +415,7 @@ define("MemberExpression", { } }); -define("NewExpression", { +defineType("NewExpression", { visitor: ["callee", "arguments"], aliases: ["Expression"], fields: { @@ -405,17 +428,7 @@ define("NewExpression", { } }); -define("ObjectExpression", { - visitor: ["properties"], - aliases: ["Expression"], - fields: { - properties: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Property", "SpreadProperty"))) - } - } -}); - -define("Program", { +defineType("Program", { visitor: ["directives", "body"], builder: ["body", "directives"], fields: { @@ -430,12 +443,22 @@ define("Program", { aliases: ["Scopable", "BlockParent", "Block", "FunctionParent"] }); -define("Property", { - builder: ["kind", "key", "value", "computed", "method", "shorthand"], +defineType("ObjectExpression", { + visitor: ["properties"], + aliases: ["Expression"], + fields: { + properties: { + validate: chain(assertValueType("array"), assertEach(assertNodeType("ObjectMethod", "ObjectProperty", "SpreadProperty"))) + } + } +}); + +defineType("ObjectMethod", { + builder: ["kind", "key", "params", "body", "computed"], fields: { kind: { - validate: chain(assertValueType("string"), assertOneOf("init", "get", "set")), - default: "init" + validate: chain(assertValueType("string"), assertOneOf("method", "get", "set")), + default: "method" }, computed: { validate: assertValueType("boolean"), @@ -443,37 +466,61 @@ define("Property", { }, key: { validate(node, key, val) { - var expectedTypes = node.computed ? "Expression" : ["Identifier", "Literal"]; + let expectedTypes = node.computed ? ["Expression"] : ["Identifier", "Literal"]; + assertNodeType(...expectedTypes)(node, key, val); + } + }, + decorators: { + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) + }, + body: { + validate: assertNodeType("BlockStatement") + }, + generator: { + default: false, + validate: assertValueType("boolean") + }, + async: { + default: false, + validate: assertValueType("boolean") + } + }, + visitor: ["key", "params", "body", "decorators", "returnType", "typeParameters"], + aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method"] +}); + +defineType("ObjectProperty", { + builder: ["key", "value", "computed", "shorthand", "decorators"], + fields: { + computed: { + validate: assertValueType("boolean"), + default: false + }, + key: { + validate(node, key, val) { + let expectedTypes = node.computed ? ["Expression"] : ["Identifier", "Literal"]; assertNodeType(...expectedTypes)(node, key, val); } }, value: { - validate(node, key, val) { - var expectedType = "Expression"; - if (node.kind === "get" || node.kind === "set" || node.method) { - expectedType = "FunctionExpression"; - } - assertNodeType(expectedType)(node, key, val); - } - }, - method: { - validate: assertValueType("boolean"), - default: false + validate: assertNodeType("Expression") }, shorthand: { validate: assertValueType("boolean"), default: false }, decorators: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))) + validate: chain(assertValueType("array"), assertEach(assertNodeType("Decorator"))), + optional: true } }, visitor: ["key", "value", "decorators"], - aliases: ["UserWhitespacable"] + aliases: ["UserWhitespacable", "Property"] }); -define("RestElement", { +defineType("RestElement", { visitor: ["argument", "typeAnnotation"], + aliases: ["LVal"], fields: { argument: { validate: assertNodeType("LVal") @@ -481,17 +528,18 @@ define("RestElement", { } }); -define("ReturnStatement", { +defineType("ReturnStatement", { visitor: ["argument"], aliases: ["Statement", "Terminatorless", "CompletionStatement"], fields: { argument: { - validate: assertNodeType("Expression") + validate: assertNodeType("Expression"), + optional: true } } }); -define("SequenceExpression", { +defineType("SequenceExpression", { visitor: ["expressions"], fields: { expressions: { validate: assertValueType("array") } @@ -499,14 +547,14 @@ define("SequenceExpression", { aliases: ["Expression"] }); -define("SwitchCase", { +defineType("SwitchCase", { visitor: ["test", "consequent"], fields: { // todo } }); -define("SwitchStatement", { +defineType("SwitchStatement", { visitor: ["discriminant", "cases"], aliases: ["Statement", "BlockParent", "Scopable"], fields: { @@ -514,11 +562,11 @@ define("SwitchStatement", { } }); -define("ThisExpression", { +defineType("ThisExpression", { aliases: ["Expression"] }); -define("ThrowStatement", { +defineType("ThrowStatement", { visitor: ["argument"], aliases: ["Statement", "Terminatorless", "CompletionStatement"], fields: { @@ -529,7 +577,7 @@ define("ThrowStatement", { }); // todo: at least handler or finalizer should be set to be valid -define("TryStatement", { +defineType("TryStatement", { visitor: ["block", "handler", "finalizer"], aliases: ["Statement"], fields: { @@ -547,7 +595,7 @@ define("TryStatement", { } }); -define("UnaryExpression", { +defineType("UnaryExpression", { builder: ["operator", "argument", "prefix"], fields: { prefix: { @@ -564,7 +612,7 @@ define("UnaryExpression", { aliases: ["UnaryLike", "Expression"] }); -define("UpdateExpression", { +defineType("UpdateExpression", { builder: ["operator", "argument", "prefix"], fields: { prefix: { @@ -581,7 +629,7 @@ define("UpdateExpression", { aliases: ["Expression"] }); -define("VariableDeclaration", { +defineType("VariableDeclaration", { builder: ["kind", "declarations"], visitor: ["declarations"], aliases: ["Statement", "Declaration"], @@ -595,7 +643,7 @@ define("VariableDeclaration", { } }); -define("VariableDeclarator", { +defineType("VariableDeclarator", { visitor: ["id", "init"], fields: { id: { @@ -608,7 +656,7 @@ define("VariableDeclarator", { } }); -define("WhileStatement", { +defineType("WhileStatement", { visitor: ["test", "body"], aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"], fields: { @@ -621,7 +669,7 @@ define("WhileStatement", { } }); -define("WithStatement", { +defineType("WithStatement", { visitor: ["object", "body"], aliases: ["Statement"], fields: { diff --git a/packages/babel-types/src/definitions/es2015.js b/packages/babel-types/src/definitions/es2015.js index 09425ecebd..c42bd87df6 100644 --- a/packages/babel-types/src/definitions/es2015.js +++ b/packages/babel-types/src/definitions/es2015.js @@ -1,6 +1,14 @@ -import define, { assertNodeType, assertValueType, chain, assertEach, assertOneOf } from "./index"; +/* @flow */ -define("AssignmentPattern", { +import defineType, { + assertNodeType, + assertValueType, + chain, + assertEach, + assertOneOf, +} from "./index"; + +defineType("AssignmentPattern", { visitor: ["left", "right"], aliases: ["Pattern", "LVal"], fields: { @@ -13,7 +21,7 @@ define("AssignmentPattern", { } }); -define("ArrayPattern", { +defineType("ArrayPattern", { visitor: ["elements", "typeAnnotation"], aliases: ["Pattern", "LVal"], fields: { @@ -23,10 +31,10 @@ define("ArrayPattern", { } }); -define("ArrowFunctionExpression", { +defineType("ArrowFunctionExpression", { builder: ["params", "body", "async"], visitor: ["params", "body", "returnType"], - aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pure"], + aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"], fields: { params: { validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))) @@ -41,19 +49,27 @@ define("ArrowFunctionExpression", { } }); -define("ClassBody", { +defineType("ClassBody", { visitor: ["body"], fields: { body: { - validate: chain(assertValueType("array"), assertEach(assertValueType("MethodDefinition", "ClassProperty"))) + validate: chain(assertValueType("array"), assertEach(assertValueType("ClassMethod", "ClassProperty"))) } } }); -define("ClassDeclaration", { +defineType("ClassDeclaration", { builder: ["id", "superClass", "body", "decorators"], - visitor: ["id", "body", "superClass", "typeParameters", "superTypeParameters", "implements", "decorators"], - aliases: ["Scopable", "Class", "Statement", "Declaration"], + visitor: [ + "id", + "body", + "superClass", + "typeParameters", + "superTypeParameters", + "implements", + "decorators" + ], + aliases: ["Scopable", "Class", "Statement", "Declaration", "Pureish"], fields: { id: { validate: assertNodeType("Identifier") @@ -71,10 +87,9 @@ define("ClassDeclaration", { } }); -define("ClassExpression", { - builder: ["id", "superClass", "body", "decorators"], - visitor: ["id", "body", "superClass", "typeParameters", "superTypeParameters", "implements", "decorators"], - aliases: ["Scopable", "Class", "Expression"], +defineType("ClassExpression", { + inherits: "ClassDeclaration", + aliases: ["Scopable", "Class", "Expression", "Pureish"], fields: { id: { optional: true, @@ -93,15 +108,15 @@ define("ClassExpression", { } }); -define("ExportAllDeclaration", { - visitor: ["source", "exported"], +defineType("ExportAllDeclaration", { + visitor: ["source"], aliases: ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"], fields: { // todo } }); -define("ExportDefaultDeclaration", { +defineType("ExportDefaultDeclaration", { visitor: ["declaration"], aliases: ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"], fields: { @@ -109,7 +124,7 @@ define("ExportDefaultDeclaration", { } }); -define("ExportNamedDeclaration", { +defineType("ExportNamedDeclaration", { visitor: ["declaration", "specifiers", "source"], aliases: ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"], fields: { @@ -117,7 +132,7 @@ define("ExportNamedDeclaration", { } }); -define("ExportSpecifier", { +defineType("ExportSpecifier", { visitor: ["local", "exported"], aliases: ["ModuleSpecifier"], fields: { @@ -130,7 +145,7 @@ define("ExportSpecifier", { } }); -define("ForOfStatement", { +defineType("ForOfStatement", { visitor: ["left", "right", "body"], aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"], fields: { @@ -146,12 +161,12 @@ define("ForOfStatement", { } }); -define("ImportDeclaration", { +defineType("ImportDeclaration", { visitor: ["specifiers", "source"], aliases: ["Statement", "Declaration", "ModuleDeclaration"], fields: { specifiers: { - // todo + validate: chain(assertValueType("array"), assertEach(assertNodeType("ImportSpecifier", "ImportDefaultSpecifier", "ImportNamespaceSpecifier"))) }, source: { validate: assertNodeType("StringLiteral") @@ -159,7 +174,7 @@ define("ImportDeclaration", { } }); -define("ImportDefaultSpecifier", { +defineType("ImportDefaultSpecifier", { visitor: ["local"], aliases: ["ModuleSpecifier"], fields: { @@ -169,7 +184,7 @@ define("ImportDefaultSpecifier", { } }); -define("ImportNamespaceSpecifier", { +defineType("ImportNamespaceSpecifier", { visitor: ["local"], aliases: ["ModuleSpecifier"], fields: { @@ -179,7 +194,7 @@ define("ImportNamespaceSpecifier", { } }); -define("ImportSpecifier", { +defineType("ImportSpecifier", { visitor: ["local", "imported"], aliases: ["ModuleSpecifier"], fields: { @@ -192,7 +207,7 @@ define("ImportSpecifier", { } }); -define("MetaProperty", { +defineType("MetaProperty", { visitor: ["meta", "property"], aliases: ["Expression"], fields: { @@ -206,9 +221,10 @@ define("MetaProperty", { } }); -define("MethodDefinition", { - builder: ["key", "value", "kind", "computed", "static"], - visitor: ["key", "value", "decorators"], +defineType("ClassMethod", { + aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method"], + builder: ["kind", "key", "params", "body", "computed", "static"], + visitor: ["key", "params", "body", "decorators", "returnType", "typeParameters"], fields: { kind: { validate: chain(assertValueType("string"), assertOneOf("get", "set", "method", "constructor")), @@ -221,11 +237,31 @@ define("MethodDefinition", { static: { default: false, validate: assertValueType("boolean") + }, + key: { + validate(node, key, val) { + let expectedTypes = node.computed ? ["Expression"] : ["Identifier", "Literal"]; + assertNodeType(...expectedTypes)(node, key, val); + } + }, + params: { + validate: chain(assertValueType("array"), assertEach(assertNodeType("LVal"))) + }, + body: { + validate: assertNodeType("BlockStatement") + }, + generator: { + default: false, + validate: assertValueType("boolean") + }, + async: { + default: false, + validate: assertValueType("boolean") } } }); -define("ObjectPattern", { +defineType("ObjectPattern", { visitor: ["properties", "typeAnnotation"], aliases: ["Pattern", "LVal"], fields: { @@ -235,7 +271,7 @@ define("ObjectPattern", { } }); -define("SpreadElement", { +defineType("SpreadElement", { visitor: ["argument"], aliases: ["UnaryLike"], fields: { @@ -245,11 +281,11 @@ define("SpreadElement", { } }); -define("Super", { +defineType("Super", { aliases: ["Expression"] }); -define("TaggedTemplateExpression", { +defineType("TaggedTemplateExpression", { visitor: ["tag", "quasi"], aliases: ["Expression"], fields: { @@ -262,7 +298,7 @@ define("TaggedTemplateExpression", { } }); -define("TemplateElement", { +defineType("TemplateElement", { builder: ["value", "tail"], fields: { value: { @@ -275,7 +311,7 @@ define("TemplateElement", { } }); -define("TemplateLiteral", { +defineType("TemplateLiteral", { visitor: ["quasis", "expressions"], aliases: ["Expression", "Literal"], fields: { @@ -283,7 +319,7 @@ define("TemplateLiteral", { } }); -define("YieldExpression", { +defineType("YieldExpression", { builder: ["argument", "delegate"], visitor: ["argument"], aliases: ["Expression", "Terminatorless"], diff --git a/packages/babel-types/src/definitions/experimental.js b/packages/babel-types/src/definitions/experimental.js index 1e0d171782..45ee553327 100644 --- a/packages/babel-types/src/definitions/experimental.js +++ b/packages/babel-types/src/definitions/experimental.js @@ -1,43 +1,26 @@ -import define, { assertNodeType, assertValueType } from "./index"; +/* @flow */ -define("AwaitExpression", { - builder: ["argument", "all"], +import defineType, { assertNodeType } from "./index"; + +defineType("AwaitExpression", { + builder: ["argument"], visitor: ["argument"], aliases: ["Expression", "Terminatorless"], fields: { - all: { - validate: assertValueType("boolean"), - default: false - }, argument: { validate: assertNodeType("Expression"), } } }); -define("BindExpression", { +defineType("BindExpression", { visitor: ["object", "callee"], fields: { // todo } }); -define("ComprehensionBlock", { - visitor: ["left", "right"], - fields: { - // todo - } -}); - -define("ComprehensionExpression", { - visitor: ["filter", "blocks", "body"], - aliases: ["Expression", "Scopable"], - fields: { - // todo - } -}); - -define("Decorator", { +defineType("Decorator", { visitor: ["expression"], fields: { expression: { @@ -46,7 +29,7 @@ define("Decorator", { } }); -define("DoExpression", { +defineType("DoExpression", { visitor: ["body"], aliases: ["Expression"], fields: { @@ -56,7 +39,7 @@ define("DoExpression", { } }); -define("ExportDefaultSpecifier", { +defineType("ExportDefaultSpecifier", { visitor: ["exported"], aliases: ["ModuleSpecifier"], fields: { @@ -66,7 +49,7 @@ define("ExportDefaultSpecifier", { } }); -define("ExportNamespaceSpecifier", { +defineType("ExportNamespaceSpecifier", { visitor: ["exported"], aliases: ["ModuleSpecifier"], fields: { @@ -76,7 +59,7 @@ define("ExportNamespaceSpecifier", { } }); -define("RestProperty", { +defineType("RestProperty", { visitor: ["argument"], aliases: ["UnaryLike"], fields: { @@ -86,7 +69,7 @@ define("RestProperty", { } }); -define("SpreadProperty", { +defineType("SpreadProperty", { visitor: ["argument"], aliases: ["UnaryLike"], fields: { diff --git a/packages/babel-types/src/definitions/flow.js b/packages/babel-types/src/definitions/flow.js index f5fe07c9d6..4a7a26ca1e 100644 --- a/packages/babel-types/src/definitions/flow.js +++ b/packages/babel-types/src/definitions/flow.js @@ -1,13 +1,15 @@ -import define from "./index"; +/* @flow */ -define("AnyTypeAnnotation", { +import defineType from "./index"; + +defineType("AnyTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo } }); -define("ArrayTypeAnnotation", { +defineType("ArrayTypeAnnotation", { visitor: ["elementType"], aliases: ["Flow"], fields: { @@ -15,21 +17,21 @@ define("ArrayTypeAnnotation", { } }); -define("BooleanTypeAnnotation", { +defineType("BooleanTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo } }); -define("BooleanLiteralTypeAnnotation", { +defineType("BooleanLiteralTypeAnnotation", { aliases: ["Flow"], fields: { // todo } }); -define("ClassImplements", { +defineType("ClassImplements", { visitor: ["id", "typeParameters"], aliases: ["Flow"], fields: { @@ -37,15 +39,15 @@ define("ClassImplements", { } }); -define("ClassProperty", { +defineType("ClassProperty", { visitor: ["key", "value", "typeAnnotation", "decorators"], - aliases: ["Flow"], + aliases: ["Flow", "Property"], fields: { // todo } }); -define("DeclareClass", { +defineType("DeclareClass", { visitor: ["id", "typeParameters", "extends", "body"], aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { @@ -53,7 +55,7 @@ define("DeclareClass", { } }); -define("DeclareFunction", { +defineType("DeclareFunction", { visitor: ["id"], aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { @@ -61,7 +63,7 @@ define("DeclareFunction", { } }); -define("DeclareModule", { +defineType("DeclareModule", { visitor: ["id", "body"], aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { @@ -69,7 +71,7 @@ define("DeclareModule", { } }); -define("DeclareVariable", { +defineType("DeclareVariable", { visitor: ["id"], aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { @@ -77,7 +79,7 @@ define("DeclareVariable", { } }); -define("FunctionTypeAnnotation", { +defineType("FunctionTypeAnnotation", { visitor: ["typeParameters", "params", "rest", "returnType"], aliases: ["Flow"], fields: { @@ -85,7 +87,7 @@ define("FunctionTypeAnnotation", { } }); -define("FunctionTypeParam", { +defineType("FunctionTypeParam", { visitor: ["name", "typeAnnotation"], aliases: ["Flow"], fields: { @@ -93,7 +95,7 @@ define("FunctionTypeParam", { } }); -define("GenericTypeAnnotation", { +defineType("GenericTypeAnnotation", { visitor: ["id", "typeParameters"], aliases: ["Flow"], fields: { @@ -101,7 +103,7 @@ define("GenericTypeAnnotation", { } }); -define("InterfaceExtends", { +defineType("InterfaceExtends", { visitor: ["id", "typeParameters"], aliases: ["Flow"], fields: { @@ -109,7 +111,7 @@ define("InterfaceExtends", { } }); -define("InterfaceDeclaration", { +defineType("InterfaceDeclaration", { visitor: ["id", "typeParameters", "extends", "body"], aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { @@ -117,7 +119,7 @@ define("InterfaceDeclaration", { } }); -define("IntersectionTypeAnnotation", { +defineType("IntersectionTypeAnnotation", { visitor: ["types"], aliases: ["Flow"], fields: { @@ -125,11 +127,11 @@ define("IntersectionTypeAnnotation", { } }); -define("MixedTypeAnnotation", { +defineType("MixedTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"] }); -define("NullableTypeAnnotation", { +defineType("NullableTypeAnnotation", { visitor: ["typeAnnotation"], aliases: ["Flow"], fields: { @@ -137,35 +139,35 @@ define("NullableTypeAnnotation", { } }); -define("NumberLiteralTypeAnnotation", { +defineType("NumberLiteralTypeAnnotation", { aliases: ["Flow"], fields: { // todo } }); -define("NumberTypeAnnotation", { +defineType("NumberTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo } }); -define("StringLiteralTypeAnnotation", { +defineType("StringLiteralTypeAnnotation", { aliases: ["Flow"], fields: { // todo } }); -define("StringTypeAnnotation", { +defineType("StringTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo } }); -define("TupleTypeAnnotation", { +defineType("TupleTypeAnnotation", { visitor: ["types"], aliases: ["Flow"], fields: { @@ -173,7 +175,7 @@ define("TupleTypeAnnotation", { } }); -define("TypeofTypeAnnotation", { +defineType("TypeofTypeAnnotation", { visitor: ["argument"], aliases: ["Flow"], fields: { @@ -181,7 +183,7 @@ define("TypeofTypeAnnotation", { } }); -define("TypeAlias", { +defineType("TypeAlias", { visitor: ["id", "typeParameters", "right"], aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], fields: { @@ -189,7 +191,7 @@ define("TypeAlias", { } }); -define("TypeAnnotation", { +defineType("TypeAnnotation", { visitor: ["typeAnnotation"], aliases: ["Flow"], fields: { @@ -197,15 +199,15 @@ define("TypeAnnotation", { } }); -define("TypeCastExpression", { +defineType("TypeCastExpression", { visitor: ["expression", "typeAnnotation"], - aliases: ["Flow"], + aliases: ["Flow", "ExpressionWrapper"], fields: { // todo } }); -define("TypeParameterDeclaration", { +defineType("TypeParameterDeclaration", { visitor: ["params"], aliases: ["Flow"], fields: { @@ -213,7 +215,7 @@ define("TypeParameterDeclaration", { } }); -define("TypeParameterInstantiation", { +defineType("TypeParameterInstantiation", { visitor: ["params"], aliases: ["Flow"], fields: { @@ -221,7 +223,7 @@ define("TypeParameterInstantiation", { } }); -define("ObjectTypeAnnotation", { +defineType("ObjectTypeAnnotation", { visitor: ["properties", "indexers", "callProperties"], aliases: ["Flow"], fields: { @@ -229,7 +231,7 @@ define("ObjectTypeAnnotation", { } }); -define("ObjectTypeCallProperty", { +defineType("ObjectTypeCallProperty", { visitor: ["value"], aliases: ["Flow", "UserWhitespacable"], fields: { @@ -237,7 +239,7 @@ define("ObjectTypeCallProperty", { } }); -define("ObjectTypeIndexer", { +defineType("ObjectTypeIndexer", { visitor: ["id", "key", "value"], aliases: ["Flow", "UserWhitespacable"], fields: { @@ -245,7 +247,7 @@ define("ObjectTypeIndexer", { } }); -define("ObjectTypeProperty", { +defineType("ObjectTypeProperty", { visitor: ["key", "value"], aliases: ["Flow", "UserWhitespacable"], fields: { @@ -253,7 +255,7 @@ define("ObjectTypeProperty", { } }); -define("QualifiedTypeIdentifier", { +defineType("QualifiedTypeIdentifier", { visitor: ["id", "qualification"], aliases: ["Flow"], fields: { @@ -261,7 +263,7 @@ define("QualifiedTypeIdentifier", { } }); -define("UnionTypeAnnotation", { +defineType("UnionTypeAnnotation", { visitor: ["types"], aliases: ["Flow"], fields: { @@ -269,7 +271,7 @@ define("UnionTypeAnnotation", { } }); -define("VoidTypeAnnotation", { +defineType("VoidTypeAnnotation", { aliases: ["Flow", "FlowBaseAnnotation"], fields: { // todo diff --git a/packages/babel-types/src/definitions/index.js b/packages/babel-types/src/definitions/index.js index e9199969f8..b25bf63073 100644 --- a/packages/babel-types/src/definitions/index.js +++ b/packages/babel-types/src/definitions/index.js @@ -1,9 +1,11 @@ +/* @flow */ + import * as t from "../index"; -export var VISITOR_KEYS = {}; -export var ALIAS_KEYS = {}; -export var NODE_FIELDS = {}; -export var BUILDER_KEYS = {}; +export let VISITOR_KEYS = {}; +export let ALIAS_KEYS = {}; +export let NODE_FIELDS = {}; +export let BUILDER_KEYS = {}; function getType(val) { if (Array.isArray(val)) { @@ -17,37 +19,33 @@ function getType(val) { } } -export function assertContains(vals) { - return function (val, key) { - if (vals.indexOf(val) < 0) { - throw new TypeError(`Property ${key} with the value of ${JSON.stringify(val)} expected to be one of ${JSON.stringify(vals)}`); - } - }; -} - -export function assertEach(callback) { +export function assertEach(callback: Function): Function { return function (node, key, val) { if (!Array.isArray(val)) return; - for (var i = 0; i < val.length; i++) { + for (let i = 0; i < val.length; i++) { callback(node, `${key}[${i}]`, val[i]); } }; } -export function assertOneOf(...vals) { - return function (node, key, val) { +export function assertOneOf(...vals): Function { + function validate(node, key, val) { if (vals.indexOf(val) < 0) { throw new TypeError(`Property ${key} expected value to be one of ${JSON.stringify(vals)} but got ${JSON.stringify(val)}`); } - }; + } + + validate.oneOf = vals; + + return validate; } -export function assertNodeType(...types) { - return function (node, key, val) { - var valid = false; +export function assertNodeType(...types: Array): Function { + function validate(node, key, val) { + let valid = false; - for (var type of types) { + for (let type of types) { if (t.is(type, val)) { valid = true; break; @@ -55,46 +53,66 @@ export function assertNodeType(...types) { } if (!valid) { - throw new TypeError(`Property ${key} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val && val.type)}`); + throw new TypeError(`Property ${key} of ${node.type} expected node to be of a type ${JSON.stringify(types)} but instead got ${JSON.stringify(val && val.type)}`); } - }; + } + + validate.oneOfNodeTypes = types; + + return validate; } -export function assertValueType(type) { - return function (node, key, val) { - var valid = getType(val) === type; +export function assertValueType(type: string): Function { + function validate(node, key, val) { + let valid = getType(val) === type; if (!valid) { - console.log(type, key, val); throw new TypeError(`Property ${key} expected type of ${type} but got ${getType(val)}`); } - }; + } + + validate.type = type; + + return validate; } -export function chain(...fns) { +export function chain(...fns: Array): Function { return function (...args) { - for (var fn of fns) { + for (let fn of fns) { fn(...args); } }; } -export default function define(type, opts = {}) { - opts.fields = opts.fields || {}; - opts.visitor = opts.visitor || []; - opts.aliases = opts.aliases || []; - opts.builder = opts.builder || opts.visitor || []; +export default function defineType( + type: string, + opts: { + fields?: Object; + visitor?: Array; + aliases?: Array; + builder?: Array; + inherits?: string; + } = {}, +) { + let inherits = (opts.inherits && store[opts.inherits]) || {}; + + opts.fields = opts.fields || inherits.fields || {}; + opts.visitor = opts.visitor || inherits.visitor || []; + opts.aliases = opts.aliases || inherits.aliases || []; + opts.builder = opts.builder || inherits.builder || opts.visitor || []; // ensure all field keys are represented in `fields` - for (let key of (opts.visitor.concat(opts.builder): Array)) { + for (let key of (opts.visitor.concat(opts.builder): Array)) { opts.fields[key] = opts.fields[key] || {}; } for (let key in opts.fields) { - var field = opts.fields[key]; + let field = opts.fields[key]; if (field.default === undefined) { field.default = null; + } else if (!field.validate) { + field.validate = assertValueType(getType(field.default)); } } @@ -102,4 +120,8 @@ export default function define(type, opts = {}) { BUILDER_KEYS[type] = opts.builder; NODE_FIELDS[type] = opts.fields; ALIAS_KEYS[type] = opts.aliases; + + store[type] = opts; } + +let store = {}; diff --git a/packages/babel-types/src/definitions/jsx.js b/packages/babel-types/src/definitions/jsx.js index 2da69891c8..c11d2fdc17 100644 --- a/packages/babel-types/src/definitions/jsx.js +++ b/packages/babel-types/src/definitions/jsx.js @@ -1,6 +1,8 @@ -import define, { assertNodeType, assertValueType, chain, assertEach } from "./index"; +/* @flow */ -define("JSXAttribute", { +import defineType, { assertNodeType, assertValueType, chain, assertEach } from "./index"; + +defineType("JSXAttribute", { visitor: ["name", "value"], aliases: ["JSX", "Immutable"], fields: { @@ -14,7 +16,7 @@ define("JSXAttribute", { } }); -define("JSXClosingElement", { +defineType("JSXClosingElement", { visitor: ["name"], aliases: ["JSX", "Immutable"], fields: { @@ -24,7 +26,7 @@ define("JSXClosingElement", { } }); -define("JSXElement", { +defineType("JSXElement", { builder: ["openingElement", "closingElement", "children", "selfClosing"], visitor: ["openingElement", "children", "closingElement"], aliases: ["JSX", "Immutable", "Expression"], @@ -42,11 +44,11 @@ define("JSXElement", { } }); -define("JSXEmptyExpression", { +defineType("JSXEmptyExpression", { aliases: ["JSX", "Expression"] }); -define("JSXExpressionContainer", { +defineType("JSXExpressionContainer", { visitor: ["expression"], aliases: ["JSX", "Immutable"], fields: { @@ -56,12 +58,17 @@ define("JSXExpressionContainer", { } }); -define("JSXIdentifier", { +defineType("JSXIdentifier", { builder: ["name"], - aliases: ["JSX", "Expression"] + aliases: ["JSX", "Expression"], + fields: { + name: { + validate: assertValueType("string") + } + } }); -define("JSXMemberExpression", { +defineType("JSXMemberExpression", { visitor: ["object", "property"], aliases: ["JSX", "Expression"], fields: { @@ -74,7 +81,7 @@ define("JSXMemberExpression", { } }); -define("JSXNamespacedName", { +defineType("JSXNamespacedName", { visitor: ["namespace", "name"], aliases: ["JSX"], fields: { @@ -87,7 +94,7 @@ define("JSXNamespacedName", { } }); -define("JSXOpeningElement", { +defineType("JSXOpeningElement", { builder: ["name", "attributes", "selfClosing"], visitor: ["name", "attributes"], aliases: ["JSX", "Immutable"], @@ -100,12 +107,15 @@ define("JSXOpeningElement", { validate: assertValueType("boolean") }, attributes: { - validate: chain(assertValueType("array"), assertEach(assertNodeType("JSXAttribute", "JSXSpreadAttribute"))) + validate: chain( + assertValueType("array"), + assertEach(assertNodeType("JSXAttribute", "JSXSpreadAttribute")) + ) } } }); -define("JSXSpreadAttribute", { +defineType("JSXSpreadAttribute", { visitor: ["argument"], aliases: ["JSX"], fields: { @@ -115,7 +125,7 @@ define("JSXSpreadAttribute", { } }); -define("JSXText", { +defineType("JSXText", { aliases: ["JSX"], builder: ["value"], fields: { diff --git a/packages/babel-types/src/definitions/misc.js b/packages/babel-types/src/definitions/misc.js index 744beacc2d..23e010da14 100644 --- a/packages/babel-types/src/definitions/misc.js +++ b/packages/babel-types/src/definitions/misc.js @@ -1,15 +1,17 @@ -import define, { assertNodeType } from "./index"; +/* @flow */ -define("Noop", { +import defineType, { assertNodeType } from "./index"; + +defineType("Noop", { visitor: [] }); -define("ParenthesizedExpression", { +defineType("ParenthesizedExpression", { visitor: ["expression"], - aliases: ["Expression"], + aliases: ["Expression", "ExpressionWrapper"], fields: { expression: { - validate: assertNodeType("expression") + validate: assertNodeType("Expression") } } }); diff --git a/packages/babel-types/src/flow.js b/packages/babel-types/src/flow.js index d76ea258b2..86f53e3b4f 100644 --- a/packages/babel-types/src/flow.js +++ b/packages/babel-types/src/flow.js @@ -1,3 +1,5 @@ +/* @flow */ + import * as t from "./index"; /** @@ -5,8 +7,8 @@ import * as t from "./index"; * returns a `UnionTypeAnnotation` node containg them. */ -export function createUnionTypeAnnotation(types) { - var flattened = removeTypeDuplicates(types); +export function createUnionTypeAnnotation(types: Array) { + let flattened = removeTypeDuplicates(types); if (flattened.length === 1) { return flattened[0]; @@ -19,17 +21,17 @@ export function createUnionTypeAnnotation(types) { * Dedupe type annotations. */ -export function removeTypeDuplicates(nodes) { - var generics = {}; - var bases = {}; +export function removeTypeDuplicates(nodes: Array) { + let generics = {}; + let bases = {}; // store union type groups to circular references - var typeGroups = []; + let typeGroups = []; - var types = []; + let types = []; - for (var i = 0; i < nodes.length; i++) { - var node = nodes[i]; + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i]; if (!node) continue; // detect duplicates @@ -62,7 +64,7 @@ export function removeTypeDuplicates(nodes) { let name = node.id.name; if (generics[name]) { - var existing = generics[name]; + let existing = generics[name]; if (existing.typeParameters) { if (node.typeParameters) { existing.typeParameters.params = removeTypeDuplicates( @@ -83,7 +85,7 @@ export function removeTypeDuplicates(nodes) { } // add back in bases - for (var type in bases) { + for (let type in bases) { types.push(bases[type]); } @@ -99,7 +101,7 @@ export function removeTypeDuplicates(nodes) { * Create a type anotation based on typeof expression. */ -export function createTypeAnnotationBasedOnTypeof(type) { +export function createTypeAnnotationBasedOnTypeof(type: string) { if (type === "string") { return t.stringTypeAnnotation(); } else if (type === "number") { diff --git a/packages/babel-types/src/index.js b/packages/babel-types/src/index.js index 31d53df153..e232281c1f 100644 --- a/packages/babel-types/src/index.js +++ b/packages/babel-types/src/index.js @@ -1,11 +1,12 @@ +/* @flow */ + import toFastProperties from "to-fast-properties"; import compact from "lodash/array/compact"; -import assign from "lodash/object/assign"; import loClone from "lodash/lang/clone"; import each from "lodash/collection/each"; import uniq from "lodash/array/uniq"; -var t = exports; +let t = exports; /** * Registers `is[Type]` and `assert[Type]` generated functions for a given `type`. @@ -13,7 +14,7 @@ var t = exports; */ function registerType(type: string, skipAliasCheck?: boolean) { - var is = t[`is${type}`] = function (node, opts) { + let is = t[`is${type}`] = function (node, opts) { return t.is(type, node, opts, skipAliasCheck); }; @@ -25,10 +26,6 @@ function registerType(type: string, skipAliasCheck?: boolean) { }; } -/** - * Constants. - */ - export const STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"]; export const FLATTENABLE_KEYS = ["body", "expressions"]; export const FOR_INIT_KEYS = ["left", "init"]; @@ -52,15 +49,17 @@ export const STRING_UNARY_OPERATORS = ["typeof"]; import "./definitions/init"; import { VISITOR_KEYS, ALIAS_KEYS, NODE_FIELDS, BUILDER_KEYS } from "./definitions"; export { VISITOR_KEYS, ALIAS_KEYS, NODE_FIELDS, BUILDER_KEYS }; -export * as react from "./react"; + +import * as _react from "./react"; +export { _react as react }; /** * Registers `is[Type]` and `assert[Type]` for all types. */ -each(t.VISITOR_KEYS, function (keys, type) { +for (let type in t.VISITOR_KEYS) { registerType(type, true); -}); +} /** * Flip `ALIAS_KEYS` for faster access in the reverse direction. @@ -70,7 +69,7 @@ t.FLIPPED_ALIAS_KEYS = {}; each(t.ALIAS_KEYS, function (aliases, type) { each(aliases, function (alias) { - var types = t.FLIPPED_ALIAS_KEYS[alias] = t.FLIPPED_ALIAS_KEYS[alias] || []; + let types = t.FLIPPED_ALIAS_KEYS[alias] = t.FLIPPED_ALIAS_KEYS[alias] || []; types.push(type); }); }); @@ -93,12 +92,10 @@ export const TYPES = Object.keys(t.VISITOR_KEYS).concat(Object.keys(t.FLIPPED_AL * Optionally, pass `skipAliasCheck` to directly compare `node.type` with `type`. */ -// @TODO should `skipAliasCheck` be removed? -/*eslint-disable no-unused-vars */ -export function is(type: string, node: Object, opts?: Object, skipAliasCheck?: boolean): boolean { +export function is(type: string, node: Object, opts?: Object): boolean { if (!node) return false; - var matches = isType(node.type, type); + let matches = isType(node.type, type); if (!matches) return false; if (typeof opts === "undefined") { @@ -107,7 +104,6 @@ export function is(type: string, node: Object, opts?: Object, skipAliasCheck?: b return t.shallowEqual(node, opts); } } -/*eslint-enable no-unused-vars */ /** * Test if a `nodeType` is a `targetType` or if `targetType` is an alias of `nodeType`. @@ -116,11 +112,11 @@ export function is(type: string, node: Object, opts?: Object, skipAliasCheck?: b export function isType(nodeType: string, targetType: string): boolean { if (nodeType === targetType) return true; - var aliases = t.FLIPPED_ALIAS_KEYS[targetType]; + let aliases = t.FLIPPED_ALIAS_KEYS[targetType]; if (aliases) { if (aliases[0] === nodeType) return true; - for (var alias of (aliases: Array)) { + for (let alias of (aliases: Array)) { if (nodeType === alias) return true; } } @@ -134,15 +130,15 @@ each(t.BUILDER_KEYS, function (keys, type) { // todo: error } - var node = {}; + let node = {}; node.type = type; - var i = 0; + let i = 0; - for (let key of (keys: Array)) { - var field = t.NODE_FIELDS[type][key]; + for (let key of (keys: Array)) { + let field = t.NODE_FIELDS[type][key]; - var arg = arguments[i++]; + let arg = arguments[i++]; if (arg === undefined) arg = loClone(field.default); node[key] = arg; @@ -163,13 +159,13 @@ each(t.BUILDER_KEYS, function (keys, type) { * Description */ -export function validate(node, key, val) { +export function validate(node?: Object, key: string, val: any) { if (!node) return; - var fields = t.NODE_FIELDS[node.type]; + let fields = t.NODE_FIELDS[node.type]; if (!fields) return; - var field = fields[key]; + let field = fields[key]; if (!field || !field.validate) return; if (field.optional && val == null) return; @@ -181,9 +177,9 @@ export function validate(node, key, val) { */ export function shallowEqual(actual: Object, expected: Object): boolean { - var keys = Object.keys(expected); + let keys = Object.keys(expected); - for (var key of (keys: Array)) { + for (let key of (keys: Array)) { if (actual[key] !== expected[key]) { return false; } @@ -217,7 +213,7 @@ export function prependToMemberExpression(member: Object, prepend: Object): Obje * Casting it to a block if it is not. */ -export function ensureBlock(node: Object, key: string = "body") { +export function ensureBlock(node: Object, key: string = "body"): Object { return node[key] = t.toBlock(node[key], node); } @@ -226,8 +222,8 @@ export function ensureBlock(node: Object, key: string = "body") { */ export function clone(node: Object): Object { - var newNode = {}; - for (var key in node) { + let newNode = {}; + for (let key in node) { if (key[0] === "_") continue; newNode[key] = node[key]; } @@ -240,12 +236,12 @@ export function clone(node: Object): Object { */ export function cloneDeep(node: Object): Object { - var newNode = {}; + let newNode = {}; - for (var key in node) { + for (let key in node) { if (key[0] === "_") continue; - var val = node[key]; + let val = node[key]; if (val) { if (val.type) { @@ -270,17 +266,17 @@ export function cloneDeep(node: Object): Object { */ export function buildMatchMemberExpression(match:string, allowPartial?: boolean): Function { - var parts = match.split("."); + let parts = match.split("."); return function (member) { // not a member expression if (!t.isMemberExpression(member)) return false; - var search = [member]; - var i = 0; + let search = [member]; + let i = 0; while (search.length) { - var node = search.shift(); + let node = search.shift(); if (allowPartial && i === parts.length) { return true; @@ -321,7 +317,7 @@ export function buildMatchMemberExpression(match:string, allowPartial?: boolean) */ export function removeComments(node: Object): Object { - for (var key of (COMMENT_KEYS: Array)) { + for (let key of COMMENT_KEYS) { delete node[key]; } return node; @@ -338,15 +334,15 @@ export function inheritsComments(child: Object, parent: Object): Object { return child; } -export function inheritTrailingComments(child, parent) { +export function inheritTrailingComments(child: Object, parent: Object) { _inheritComments("trailingComments", child, parent); } -export function inheritLeadingComments(child, parent) { +export function inheritLeadingComments(child: Object, parent: Object) { _inheritComments("leadingComments", child, parent); } -export function inheritInnerComments(child, parent) { +export function inheritInnerComments(child: Object, parent: Object) { _inheritComments("innerComments", child, parent); } @@ -363,13 +359,13 @@ function _inheritComments(key, child, parent) { export function inherits(child: Object, parent: Object): Object { if (!child || !parent) return child; - for (let key of (t.INHERIT_KEYS.optional: Array)) { + for (let key of (t.INHERIT_KEYS.optional: Array)) { if (child[key] == null) { child[key] = parent[key]; } } - for (let key of (t.INHERIT_KEYS.force: Array)) { + for (let key of (t.INHERIT_KEYS.force: Array)) { child[key] = parent[key]; } @@ -379,19 +375,29 @@ export function inherits(child: Object, parent: Object): Object { } /** - * Description + * TODO */ -export function directive(value) { - return t.expressionStatement(t.literal(value)); +export function assertNode(node?) { + if (!isNode(node)) { + throw new TypeError("Not a valid node " + (node && node.type)); + } +} + +/** + * TODO + */ + +export function isNode(node?): boolean { + return !!(node && VISITOR_KEYS[node.type]); } // Optimize property access. toFastProperties(t); toFastProperties(t.VISITOR_KEYS); -// Export all type checkers from other files. -assign(t, require("./retrievers")); -assign(t, require("./validators")); -assign(t, require("./converters")); -assign(t, require("./flow")); +// +export * from "./retrievers"; +export * from "./validators"; +export * from "./converters"; +export * from "./flow"; diff --git a/packages/babel-types/src/react.js b/packages/babel-types/src/react.js index 255c67c381..8ec3f457b1 100644 --- a/packages/babel-types/src/react.js +++ b/packages/babel-types/src/react.js @@ -1,15 +1,20 @@ +/* @flow */ + import * as t from "./index"; -export var isReactComponent = t.buildMatchMemberExpression("React.Component"); +export let isReactComponent = t.buildMatchMemberExpression("React.Component"); -export function isCompatTag(tagName) { - return tagName && /^[a-z]|\-/.test(tagName); +export function isCompatTag(tagName?: string): boolean { + return !!tagName && /^[a-z]|\-/.test(tagName); } -function cleanJSXElementLiteralChild(child, args) { - var lines = child.value.split(/\r\n|\n|\r/); +function cleanJSXElementLiteralChild( + child: { value: string }, + args: Array, +) { + let lines = child.value.split(/\r\n|\n|\r/); - var lastNonEmptyLine = 0; + let lastNonEmptyLine = 0; for (let i = 0; i < lines.length; i++) { if (lines[i].match(/[^ \t]/)) { @@ -17,17 +22,17 @@ function cleanJSXElementLiteralChild(child, args) { } } - var str = ""; + let str = ""; for (let i = 0; i < lines.length; i++) { - var line = lines[i]; + let line = lines[i]; - var isFirstLine = i === 0; - var isLastLine = i === lines.length - 1; - var isLastNonEmptyLine = i === lastNonEmptyLine; + let isFirstLine = i === 0; + let isLastLine = i === lines.length - 1; + let isLastNonEmptyLine = i === lastNonEmptyLine; // replace rendered whitespace tabs with spaces - var trimmedLine = line.replace(/\t/g, " "); + let trimmedLine = line.replace(/\t/g, " "); // trim whitespace touching a newline if (!isFirstLine) { @@ -51,11 +56,11 @@ function cleanJSXElementLiteralChild(child, args) { if (str) args.push(t.stringLiteral(str)); } -export function buildChildren(node) { - var elems = []; +export function buildChildren(node: Object): Array { + let elems = []; - for (var i = 0; i < node.children.length; i++) { - var child = node.children[i]; + for (let i = 0; i < node.children.length; i++) { + let child = node.children[i]; if (t.isJSXText(child)) { cleanJSXElementLiteralChild(child, elems); diff --git a/packages/babel-types/src/retrievers.js b/packages/babel-types/src/retrievers.js index 09ae7115e9..15dfc5a86d 100644 --- a/packages/babel-types/src/retrievers.js +++ b/packages/babel-types/src/retrievers.js @@ -1,22 +1,27 @@ +/* @flow */ + import * as t from "./index"; /** * Return a list of binding identifiers associated with the input `node`. */ -export function getBindingIdentifiers(node: Object, duplicates?): Object { - var search = [].concat(node); - var ids = Object.create(null); +export function getBindingIdentifiers( + node: Object, + duplicates?: boolean, +): Object { + let search = [].concat(node); + let ids = Object.create(null); while (search.length) { - var id = search.shift(); + let id = search.shift(); if (!id) continue; - var keys = t.getBindingIdentifiers.keys[id.type]; + let keys = t.getBindingIdentifiers.keys[id.type]; if (t.isIdentifier(id)) { if (duplicates) { - var _ids = ids[id.name] = ids[id.name] || []; + let _ids = ids[id.name] = ids[id.name] || []; _ids.push(id); } else { ids[id.name] = id; @@ -26,8 +31,8 @@ export function getBindingIdentifiers(node: Object, duplicates?): Object { search.push(node.declaration); } } else if (keys) { - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; + for (let i = 0; i < keys.length; i++) { + let key = keys[i]; if (id[key]) { search = search.concat(id[key]); } @@ -63,6 +68,10 @@ getBindingIdentifiers.keys = { ImportDefaultSpecifier: ["local"], ImportDeclaration: ["specifiers"], + ExportSpecifier: ["exported"], + ExportNamespaceSpecifier: ["exported"], + ExportDefaultSpecifier: ["exported"], + FunctionDeclaration: ["id", "params"], FunctionExpression: ["id", "params"], @@ -73,7 +82,7 @@ getBindingIdentifiers.keys = { UpdateExpression: ["argument"], SpreadProperty: ["argument"], - Property: ["value"], + ObjectProperty: ["value"], AssignmentPattern: ["left"], ArrayPattern: ["elements"], diff --git a/packages/babel-types/src/validators.js b/packages/babel-types/src/validators.js index aa60e901f8..6223a914ac 100644 --- a/packages/babel-types/src/validators.js +++ b/packages/babel-types/src/validators.js @@ -1,3 +1,5 @@ +/* @flow */ + import { getBindingIdentifiers } from "./retrievers"; import esutils from "esutils"; import * as t from "./index"; @@ -7,11 +9,11 @@ import * as t from "./index"; */ export function isBinding(node: Object, parent: Object): boolean { - var keys = getBindingIdentifiers.keys[parent.type]; + let keys = getBindingIdentifiers.keys[parent.type]; if (keys) { - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - var val = parent[key]; + for (let i = 0; i < keys.length; i++) { + let key = keys[i]; + let val = parent[key]; if (Array.isArray(val)) { if (val.indexOf(node) >= 0) return true; } else { @@ -51,13 +53,13 @@ export function isReferenced(node: Object, parent: Object): boolean { // yes: { [NODE]: "" } // yes: { NODE } // no: { NODE: "" } - case "Property": + case "ObjectProperty": if (parent.key === node) { return parent.computed; } - // no: var NODE = init; - // yes: var id = NODE; + // no: let NODE = init; + // yes: let id = NODE; case "VariableDeclarator": return parent.id !== node; @@ -66,7 +68,7 @@ export function isReferenced(node: Object, parent: Object): boolean { case "ArrowFunctionExpression": case "FunctionDeclaration": case "FunctionExpression": - for (var param of (parent.params: Array)) { + for (let param of (parent.params: Array)) { if (param === node) return false; } @@ -113,7 +115,7 @@ export function isReferenced(node: Object, parent: Object): boolean { return parent.id !== node; // yes: class { [NODE](){} } - case "MethodDefinition": + case "ClassMethod": return parent.key === node && parent.computed; // no: NODE: for (;;) {} @@ -134,9 +136,9 @@ export function isReferenced(node: Object, parent: Object): boolean { return parent.right === node; // no: [NODE = foo] = []; - // no: [foo = NODE] = []; + // yes: [foo = NODE] = []; case "AssignmentPattern": - return false; + return parent.right === node; // no: [NODE] = []; // no: ({ NODE }) = []; diff --git a/packages/babel/README.md b/packages/babel/README.md new file mode 100644 index 0000000000..17590de468 --- /dev/null +++ b/packages/babel/README.md @@ -0,0 +1 @@ +# babel diff --git a/packages/babel/cli.js b/packages/babel/cli.js new file mode 100755 index 0000000000..655dad48cd --- /dev/null +++ b/packages/babel/cli.js @@ -0,0 +1,5 @@ +console.error("The CLI has been moved into the package `babel-cli`."); +console.log(); +console.log("$ npm install -g babel-cli"); +console.log(); +process.exit(1); diff --git a/packages/babel/index.js b/packages/babel/index.js new file mode 100644 index 0000000000..06ca959245 --- /dev/null +++ b/packages/babel/index.js @@ -0,0 +1 @@ +throw new Error("The node API for `babel` has been moved to `babel-core`."); diff --git a/packages/babel/package.json b/packages/babel/package.json new file mode 100644 index 0000000000..6363259eb9 --- /dev/null +++ b/packages/babel/package.json @@ -0,0 +1,15 @@ +{ + "name": "babel", + "version": "5.10.32", + "description": "Turn ES6 code into readable vanilla ES5 with source maps", + "author": "Sebastian McKenzie ", + "homepage": "https://babeljs.io/", + "license": "MIT", + "repository": "babel/babel", + "preferGlobal": true, + "bin": { + "babel": "./cli.js", + "babel-node": "./cli.js", + "babel-external-helpers": "./cli.js" + } +} \ No newline at end of file diff --git a/packages/babylon/README.md b/packages/babylon/README.md index 12fee1e55f..876a5b01ff 100644 --- a/packages/babylon/README.md +++ b/packages/babylon/README.md @@ -32,13 +32,12 @@ Significant diversions are expected to occur in the future such as streaming, EB the top level raises an error. Set this to `true` to accept such code. +- **allowSuperOutsideMethod** TODO + - **sourceType**: Indicate the mode the code should be parsed in. Can be either `"script"` or `"module"`. -- **features**: Object containing names of all the proposed syntax you want - to support. - -- **plugins**: Object containg the plugins that you want to enable. +- **plugins**: Array containing the plugins that you want to enable. ### Example @@ -47,29 +46,28 @@ require("babylon").parse("code", { // parse in strict mode and allow module declarations sourceType: "module", - features: { + features: [ // enable experimental async functions - asyncFunctions: true - } + "asyncFunctions", - plugins: { // enable jsx and flow syntax - jsx: true, - flow: true - } + "jsx", + "flow" + ] }); ``` -### Features - - - `asyncFunctions` - - `doExpressions` - - `comprehensions` - - `trailingFunctionCommas` - - `objectRestSpread` - - `decorators` - ### Plugins - `jsx` - `flow` + - `asyncFunctions` + - `classConstructorCall` + - `doExpressions` + - `trailingFunctionCommas` + - `objectRestSpread` + - `decorators` + - `classProperties` + - `exportExtensions` + - `exponentiationOperator` + - `asyncGenerators` diff --git a/packages/babylon/package.json b/packages/babylon/package.json index 0a2151b37d..fa99ac5b90 100644 --- a/packages/babylon/package.json +++ b/packages/babylon/package.json @@ -1,6 +1,6 @@ { "name": "babylon", - "version": "5.8.23", + "version": "5.10.32", "description": "A JavaScript parser", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", @@ -8,9 +8,9 @@ "repository": "babel/babel", "main": "lib/index.js", "dependencies": { - "babel-runtime": "^5.8.20" + "babel-runtime": "^5.10.32" }, "bin": { "babylon": "./bin/babylon.js" } -} +} \ No newline at end of file diff --git a/packages/babylon/src/options.js b/packages/babylon/src/options.js index 3b97f93a63..7beddde5ad 100755 --- a/packages/babylon/src/options.js +++ b/packages/babylon/src/options.js @@ -12,10 +12,12 @@ export const defaultOptions = { // When enabled, import/export statements are not constrained to // appearing at the top of the program. allowImportExportEverywhere: false, - plugins: {}, - // Babel-specific options - features: {}, - strictMode: null + // TODO + allowSuperOutsideMethod: false, + // An array of plugins to enable + plugins: [], + // TODO + strictMode: null, }; // Interpret and default an options object diff --git a/packages/babylon/src/parser/comments.js b/packages/babylon/src/parser/comments.js index 5a3e96abcc..344ba7e2c0 100644 --- a/packages/babylon/src/parser/comments.js +++ b/packages/babylon/src/parser/comments.js @@ -40,9 +40,9 @@ pp.addComment = function (comment) { pp.processComment = function (node) { if (node.type === "Program" && node.body.length > 0) return; - var stack = this.state.commentStack; + let stack = this.state.commentStack; - var lastChild, trailingComments, i; + let lastChild, trailingComments, i; if (this.state.trailingComments.length > 0) { // If the first comment in trailingComments comes after the @@ -62,7 +62,7 @@ pp.processComment = function (node) { this.state.trailingComments.length = 0; } } else { - var lastInStack = last(stack); + let lastInStack = last(stack); if (stack.length > 0 && lastInStack.trailingComments && lastInStack.trailingComments[0].start >= node.end) { trailingComments = lastInStack.trailingComments; lastInStack.trailingComments = null; @@ -80,7 +80,7 @@ pp.processComment = function (node) { node.leadingComments = lastChild.leadingComments; lastChild.leadingComments = null; } else { - // A leading comment for an anonymous class had been stolen by its first MethodDefinition, + // A leading comment for an anonymous class had been stolen by its first ClassMethod, // so this takes back the leading comment. // See also: https://github.com/eslint/espree/issues/158 for (i = lastChild.leadingComments.length - 2; i >= 0; --i) { diff --git a/packages/babylon/src/parser/expression.js b/packages/babylon/src/parser/expression.js index 8c9898429c..b27bf3abd2 100644 --- a/packages/babylon/src/parser/expression.js +++ b/packages/babylon/src/parser/expression.js @@ -30,9 +30,10 @@ const pp = Parser.prototype; // strict mode, init properties are also not allowed to be repeated. pp.checkPropClash = function (prop, propHash) { - if (prop.computed || prop.method || prop.shorthand) return; + if (prop.computed || prop.method) return; - let key = prop.key, name; + let key = prop.key; + let name; switch (key.type) { case "Identifier": name = key.name; @@ -47,8 +48,7 @@ pp.checkPropClash = function (prop, propHash) { return; } - let kind = prop.kind; - if (name === "__proto__" && kind === "init") { + if (name === "__proto__" && prop.kind === "init") { if (propHash.proto) this.raise(key.start, "Redefinition of __proto__ property"); propHash.proto = true; } @@ -225,11 +225,11 @@ pp.parseExprSubscripts = function (refShorthandDefaultPos) { if (refShorthandDefaultPos && refShorthandDefaultPos.start) { return expr; } else { - return this.parseSubscripts(expr, startPos, startLoc); + return this.parseSubscripts(expr, startPos, startLoc); } }; -pp.parseSubscripts = function(base, startPos, startLoc, noCalls) { +pp.parseSubscripts = function (base, startPos, startLoc, noCalls) { for (;;) { if (!noCalls && this.eat(tt.doubleColon)) { let node = this.startNodeAt(startPos, startLoc); @@ -255,11 +255,11 @@ pp.parseSubscripts = function(base, startPos, startLoc, noCalls) { let node = this.startNodeAt(startPos, startLoc); node.callee = base; - node.arguments = this.parseCallExpressionArguments(tt.parenR, this.hasFeature("trailingFunctionCommas"), possibleAsync); + node.arguments = this.parseCallExpressionArguments(tt.parenR, this.hasPlugin("trailingFunctionCommas"), possibleAsync); base = this.finishNode(node, "CallExpression"); if (possibleAsync && this.shouldParseAsyncArrow()) { - base = this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node); + return this.parseAsyncArrowFromCallExpression(this.startNodeAt(startPos, startLoc), node); } else { this.toReferencedList(node.arguments); } @@ -307,7 +307,7 @@ pp.shouldParseAsyncArrow = function () { }; pp.parseAsyncArrowFromCallExpression = function (node, call) { - if (!this.hasFeature("asyncFunctions")) this.unexpected(); + if (!this.hasPlugin("asyncFunctions")) this.unexpected(); this.expect(tt.arrow); return this.parseArrowExpression(node, call.arguments, true); }; @@ -328,7 +328,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { let node, canBeArrow = this.state.potentialArrowAt === this.state.start; switch (this.state.type) { case tt._super: - if (!this.state.inFunction) { + if (!this.state.inMethod && !this.options.allowSuperOutsideMethod) { this.raise(this.state.start, "'super' outside of function or class"); } @@ -337,6 +337,9 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { if (!this.match(tt.parenL) && !this.match(tt.bracketL) && !this.match(tt.dot)) { this.unexpected(); } + if (this.match(tt.parenL) && this.state.inMethod !== "constructor" && !this.options.allowSuperOutsideMethod) { + this.raise(node.start, "super() outside of class constructor"); + } return this.finishNode(node, "Super"); case tt._this: @@ -349,18 +352,22 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { case tt.name: node = this.startNode(); - let id = this.parseIdentifier(true); + let allowAwait = this.hasPlugin("asyncFunctions") && this.state.value === "await" && this.state.inAsync; + let allowYield = this.shouldAllowYieldIdentifier(); + let id = this.parseIdentifier(allowAwait || allowYield); - if (this.hasFeature("asyncFunctions")) { + if (this.hasPlugin("asyncFunctions")) { if (id.name === "await") { - if (this.inAsync) return this.parseAwait(node); + if (this.state.inAsync || this.inModule) { + return this.parseAwait(node); + } } else if (id.name === "async" && this.match(tt._function) && !this.canInsertSemicolon()) { this.next(); return this.parseFunction(node, false, false, true); } else if (canBeArrow && id.name === "async" && this.match(tt.name)) { - var params = [this.parseIdentifier()]; + let params = [this.parseIdentifier()]; this.expect(tt.arrow); - // var foo = bar => {}; + // let foo = bar => {}; return this.parseArrowExpression(node, params, true); } } @@ -372,14 +379,14 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { return id; case tt._do: - if (this.hasFeature("doExpressions")) { + if (this.hasPlugin("doExpressions")) { let node = this.startNode(); this.next(); - var oldInFunction = this.state.inFunction; - var oldLabels = this.state.labels; + let oldInFunction = this.state.inFunction; + let oldLabels = this.state.labels; this.state.labels = []; this.state.inFunction = false; - node.body = this.parseBlock(); + node.body = this.parseBlock(false, true); this.state.inFunction = oldInFunction; this.state.labels = oldLabels; return this.finishNode(node, "DoExpression"); @@ -405,8 +412,7 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { case tt._true: case tt._false: node = this.startNode(); - node.rawValue = node.value = this.match(tt._true); - node.raw = this.state.type.keyword; + node.value = this.match(tt._true); this.next(); return this.finishNode(node, "BooleanLiteral"); @@ -416,10 +422,6 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { case tt.bracketL: node = this.startNode(); this.next(); - // check whether this is array comprehension or regular array - if (this.hasFeature("comprehensions") && this.match(tt._for)) { - return this.parseComprehension(node, false); - } node.elements = this.parseExprList(tt.bracketR, true, true, refShorthandDefaultPos); this.toReferencedList(node.elements); return this.finishNode(node, "ArrayExpression"); @@ -464,8 +466,9 @@ pp.parseExprAtom = function (refShorthandDefaultPos) { pp.parseLiteral = function (value, type) { let node = this.startNode(); - node.rawValue = node.value = value; - node.raw = this.input.slice(this.state.start, this.state.end); + this.addExtra(node, "rawValue", value); + this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end)); + node.value = value; this.next(); return this.finishNode(node, type); }; @@ -483,10 +486,6 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow let val; this.next(); - if (this.hasFeature("comprehensions") && this.match(tt._for)) { - return this.parseComprehension(this.startNodeAt(startPos, startLoc), true); - } - let innerStartPos = this.state.start, innerStartLoc = this.state.startLoc; let exprList = [], first = true; let refShorthandDefaultPos = { start: 0 }, spreadStart, innerParenStart, optionalCommaStart; @@ -495,7 +494,7 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow first = false; } else { this.expect(tt.comma); - if (this.match(tt.parenR) && this.hasFeature("trailingFunctionCommas")) { + if (this.match(tt.parenR) && this.hasPlugin("trailingFunctionCommas")) { optionalCommaStart = this.state.start; break; } @@ -572,7 +571,7 @@ pp.parseNew = function () { node.callee = this.parseNoCallExpr(); if (this.eat(tt.parenL)) { - node.arguments = this.parseExprList(tt.parenR, this.hasFeature("trailingFunctionCommas")); + node.arguments = this.parseExprList(tt.parenR, this.hasPlugin("trailingFunctionCommas")); this.toReferencedList(node.arguments); } else { node.arguments = []; @@ -613,10 +612,14 @@ pp.parseTemplate = function () { // Parse an object literal or binding pattern. pp.parseObj = function (isPattern, refShorthandDefaultPos) { - let node = this.startNode(), first = true, propHash = Object.create(null); - node.properties = []; let decorators = []; + let propHash = Object.create(null); + let first = true; + let node = this.startNode(); + + node.properties = []; this.next(); + while (!this.eat(tt.braceR)) { if (first) { first = false; @@ -634,24 +637,30 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) { prop.decorators = decorators; decorators = []; } - if (this.hasFeature("objectRestSpread") && this.match(tt.ellipsis)) { + + if (this.hasPlugin("objectRestSpread") && this.match(tt.ellipsis)) { prop = this.parseSpread(); prop.type = isPattern ? "RestProperty" : "SpreadProperty"; node.properties.push(prop); continue; } + prop.method = false; prop.shorthand = false; + if (isPattern || refShorthandDefaultPos) { startPos = this.state.start; startLoc = this.state.startLoc; } + if (!isPattern) { isGenerator = this.eat(tt.star); } - if (!isPattern && this.hasFeature("asyncFunctions") && this.isContextual("async")) { + + if (!isPattern && this.hasPlugin("asyncFunctions") && this.isContextual("async")) { if (isGenerator) this.unexpected(); - var asyncId = this.parseIdentifier(); + + let asyncId = this.parseIdentifier(); if (this.match(tt.colon) || this.match(tt.parenL) || this.match(tt.braceR)) { prop.key = asyncId; } else { @@ -661,43 +670,58 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) { } else { this.parsePropertyName(prop); } + this.parseObjPropValue(prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos); this.checkPropClash(prop, propHash); - node.properties.push(this.finishNode(prop, "Property")); + + if (prop.shorthand) { + this.addExtra(prop, "shorthand", true); + } + + node.properties.push(prop); } + if (decorators.length) { this.raise(this.state.start, "You have trailing decorators with no property"); } + return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression"); }; pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos) { if (this.eat(tt.colon)) { prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos); - prop.kind = "init"; - } else if (this.match(tt.parenL)) { + return this.finishNode(prop, "ObjectProperty"); + } + + if (this.match(tt.parenL)) { if (isPattern) this.unexpected(); - prop.kind = "init"; + prop.kind = "method"; prop.method = true; - prop.value = this.parseMethod(isGenerator, isAsync); - } else if (!prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (!this.match(tt.comma) && !this.match(tt.braceR))) { + this.parseMethod(prop, isGenerator, isAsync); + return this.finishNode(prop, "ObjectMethod"); + } + + if (!prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (!this.match(tt.comma) && !this.match(tt.braceR))) { if (isGenerator || isAsync || isPattern) this.unexpected(); prop.kind = prop.key.name; this.parsePropertyName(prop); - prop.value = this.parseMethod(false); + this.parseMethod(prop, false); let paramCount = prop.kind === "get" ? 0 : 1; - if (prop.value.params.length !== paramCount) { - let start = prop.value.start; + if (prop.params.length !== paramCount) { + let start = prop.start; if (prop.kind === "get") { this.raise(start, "getter should have no params"); } else { this.raise(start, "setter should have exactly one param"); } } - } else if (!prop.computed && prop.key.type === "Identifier") { - prop.kind = "init"; + return this.finishNode(prop, "ObjectMethod"); + } + + if (!prop.computed && prop.key.type === "Identifier") { if (isPattern) { - var illegalBinding = this.isKeyword(prop.key.name); + let illegalBinding = this.isKeyword(prop.key.name); if (!illegalBinding && this.state.strict) { illegalBinding = reservedWords.strictBind(prop.key.name) || reservedWords.strict(prop.key.name); } @@ -714,9 +738,10 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync, prop.value = prop.key.__clone(); } prop.shorthand = true; - } else { - this.unexpected(); + return this.finishNode(prop, "ObjectProperty"); } + + this.unexpected(); }; pp.parsePropertyName = function (prop) { @@ -737,21 +762,23 @@ pp.initFunction = function (node, isAsync) { node.id = null; node.generator = false; node.expression = false; - if (this.hasFeature("asyncFunctions")) { + if (this.hasPlugin("asyncFunctions")) { node.async = !!isAsync; } }; // Parse object or class method. -pp.parseMethod = function (isGenerator, isAsync) { - let node = this.startNode(); +pp.parseMethod = function (node, isGenerator, isAsync) { + let oldInMethod = this.state.inMethod; + this.state.inMethod = node.kind || true; this.initFunction(node, isAsync); this.expect(tt.parenL); - node.params = this.parseBindingList(tt.parenR, false, this.hasFeature("trailingFunctionCommas")); + node.params = this.parseBindingList(tt.parenR, false, this.hasPlugin("trailingFunctionCommas")); node.generator = isGenerator; this.parseFunctionBody(node); - return this.finishNode(node, "FunctionExpression"); + this.state.inMethod = oldInMethod; + return node; }; // Parse arrow function expression with given parameters. @@ -768,8 +795,8 @@ pp.parseArrowExpression = function (node, params, isAsync) { pp.parseFunctionBody = function (node, allowExpression) { let isExpression = allowExpression && !this.match(tt.braceL); - var oldInAsync = this.inAsync; - this.inAsync = node.async; + let oldInAsync = this.state.inAsync; + this.state.inAsync = node.async; if (isExpression) { node.body = this.parseMaybeAssign(); node.expression = true; @@ -782,21 +809,23 @@ pp.parseFunctionBody = function (node, allowExpression) { node.expression = false; this.state.inFunction = oldInFunc; this.state.inGenerator = oldInGen; this.state.labels = oldLabels; } - this.inAsync = oldInAsync; + this.state.inAsync = oldInAsync; // If this is a strict mode function, verify that argument names // are not repeated, and it does not try to bind the words `eval` // or `arguments`. - var checkLVal = this.state.strict; - var checkLValStrict = false; + let checkLVal = this.state.strict; + let checkLValStrict = false; + let isStrict = false; // arrow function if (allowExpression) checkLVal = true; // normal function if (!isExpression && node.body.directives.length) { - for (var directive of (node.body.directives: Array)) { - if (directive.value === "use strict") { + for (let directive of (node.body.directives: Array)) { + if (directive.value.value === "use strict") { + isStrict = true; checkLVal = true; checkLValStrict = true; break; @@ -804,6 +833,11 @@ pp.parseFunctionBody = function (node, allowExpression) { } } + // + if (isStrict && node.id && node.id.type === "Identifier" && node.id.name === "yield") { + this.raise(node.id.start, "Binding yield in strict mode"); + } + if (checkLVal) { let nameHash = Object.create(null); let oldStrict = this.state.strict; @@ -870,6 +904,10 @@ pp.parseIdentifier = function (liberal) { this.unexpected(); } + if (!liberal && node.name === "await" && this.state.inAsync) { + this.raise(node.start, "invalid use of await inside of an async function"); + } + this.next(); return this.finishNode(node, "Identifier"); }; @@ -899,25 +937,3 @@ pp.parseYield = function () { } return this.finishNode(node, "YieldExpression"); }; - -// Parses array and generator comprehensions. - -pp.parseComprehension = function (node, isGenerator) { - node.blocks = []; - while (this.match(tt._for)) { - let block = this.startNode(); - this.next(); - this.expect(tt.parenL); - block.left = this.parseBindingAtom(); - this.checkLVal(block.left, true); - this.expectContextual("of"); - block.right = this.parseExpression(); - this.expect(tt.parenR); - node.blocks.push(this.finishNode(block, "ComprehensionBlock")); - } - node.filter = this.eat(tt._if) ? this.parseParenExpression() : null; - node.body = this.parseExpression(); - this.expect(isGenerator ? tt.parenR : tt.bracketR); - node.generator = isGenerator; - return this.finishNode(node, "ComprehensionExpression"); -}; diff --git a/packages/babylon/src/parser/index.js b/packages/babylon/src/parser/index.js index 59dd256bae..6f9e2b3c26 100644 --- a/packages/babylon/src/parser/index.js +++ b/packages/babylon/src/parser/index.js @@ -4,8 +4,6 @@ import { reservedWords } from "../util/identifier"; import { getOptions } from "../options"; import Tokenizer from "../tokenizer"; -// Registered plugins - export const plugins = {}; export default class Parser extends Tokenizer { @@ -14,12 +12,10 @@ export default class Parser extends Tokenizer { super(options, input); this.options = options; + this.inModule = this.options.sourceType === "module"; this.isReservedWord = reservedWords[6]; this.input = input; - this.loadPlugins(this.options.plugins); - - // Figure out if it's a module code. - this.inModule = this.options.sourceType === "module"; + this.plugins = this.loadPlugins(this.options.plugins); // If enabled, skip leading hashbang line. if (this.state.pos === 0 && this.input[0] === "#" && this.input[1] === "!") { @@ -27,20 +23,31 @@ export default class Parser extends Tokenizer { } } - hasFeature(name: string): boolean { - return !!this.options.features[name]; + hasPlugin(name: string): boolean { + return !!(this.plugins["*"] || this.plugins[name]); } extend(name: string, f: Function) { this[name] = f(this[name]); } - loadPlugins(plugins) { - for (let name in plugins) { - let plugin = exports.plugins[name]; - if (!plugin) throw new Error(`Plugin '${name}' not found`); - plugin(this, plugins[name]); + loadPlugins(plugins: Array) { + let pluginMap = {}; + + if (plugins.indexOf("flow") >= 0) { + // ensure flow plugin loads last + plugins.splice(plugins.indexOf("flow"), 1); + plugins.push("flow"); } + + for (let name of plugins) { + pluginMap[name] = true; + + let plugin = exports.plugins[name]; + if (plugin) plugin(this); + } + + return pluginMap; } parse(): { diff --git a/packages/babylon/src/parser/lval.js b/packages/babylon/src/parser/lval.js index 333b6457b8..4955ff5b5b 100644 --- a/packages/babylon/src/parser/lval.js +++ b/packages/babylon/src/parser/lval.js @@ -22,8 +22,18 @@ pp.toAssignable = function (node, isBinding) { node.type = "ObjectPattern"; for (let prop of (node.properties: Array)) { if (prop.type === "SpreadProperty") continue; - if (prop.kind !== "init") this.raise(prop.key.start, "Object pattern can't contain getter or setter"); - this.toAssignable(prop.value, isBinding); + + if (prop.type === "ObjectMethod") { + if (prop.kind === "get" || prop.kind === "set") { + this.raise(prop.key.start, "Object pattern can't contain getter or setter"); + } else { + this.raise(prop.key.start, "Object pattern can't contain methods"); + } + } + + if (prop.type === "ObjectProperty") { + this.toAssignable(prop.value, isBinding); + } } break; @@ -94,14 +104,25 @@ pp.parseSpread = function (refShorthandDefaultPos) { pp.parseRest = function () { let node = this.startNode(); this.next(); - node.argument = this.parseIdentifier(); + node.argument = this.parseBindingIdentifier(); return this.finishNode(node, "RestElement"); }; +pp.shouldAllowYieldIdentifier = function () { + return this.match(tt._yield) && !this.state.strict && !this.state.inGenerator; +}; + +pp.parseBindingIdentifier = function () { + return this.parseIdentifier(this.shouldAllowYieldIdentifier()); +}; + // Parses lvalue (assignable) atom. pp.parseBindingAtom = function () { switch (this.state.type) { + case tt._yield: + if (this.state.strict || this.state.inGenerator) this.unexpected(); + case tt.name: return this.parseIdentifier(true); @@ -120,7 +141,8 @@ pp.parseBindingAtom = function () { }; pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) { - var elts = [], first = true; + let elts = []; + let first = true; while (!this.eat(close)) { if (first) { first = false; @@ -136,7 +158,7 @@ pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) { this.expect(close); break; } else { - var left = this.parseMaybeDefault(); + let left = this.parseMaybeDefault(); this.parseAssignableListItemTypes(left); elts.push(this.parseMaybeDefault(null, null, left)); } @@ -187,7 +209,7 @@ pp.checkLVal = function (expr, isBinding, checkClashes) { case "ObjectPattern": for (let prop of (expr.properties: Array)) { - if (prop.type === "Property") prop = prop.value; + if (prop.type === "ObjectProperty") prop = prop.value; this.checkLVal(prop, isBinding, checkClashes); } break; diff --git a/packages/babylon/src/parser/node.js b/packages/babylon/src/parser/node.js index d3544bc816..e0dcf33b08 100644 --- a/packages/babylon/src/parser/node.js +++ b/packages/babylon/src/parser/node.js @@ -21,8 +21,8 @@ class Node { loc: SourceLocation; __clone(): Node { - var node2 = new Node; - for (var key in this) node2[key] = this[key]; + let node2 = new Node; + for (let key in this) node2[key] = this[key]; return node2; } } diff --git a/packages/babylon/src/parser/statement.js b/packages/babylon/src/parser/statement.js index 14cc0daa40..ef7649dc4b 100644 --- a/packages/babylon/src/parser/statement.js +++ b/packages/babylon/src/parser/statement.js @@ -16,7 +16,7 @@ const pp = Parser.prototype; pp.parseTopLevel = function (file, program) { program.sourceType = this.options.sourceType; - this.parseBlockBody(program, true, tt.eof); + this.parseBlockBody(program, true, true, tt.eof); file.program = this.finishNode(program, "Program"); file.comments = this.state.comments; @@ -30,11 +30,21 @@ const loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"}; // TODO pp.parseDirective = function () { - let node = this.startNode(); - node.raw = this.input.slice(this.state.start, this.state.end); - node.value = node.raw.slice(1, -1); // remove quotes + let directiveLiteral = this.startNode(); + let directive = this.startNode(); + + let raw = this.input.slice(this.state.start, this.state.end); + let val = directiveLiteral.value = raw.slice(1, -1); // remove quotes + + this.addExtra(directiveLiteral, "raw", raw); + this.addExtra(directiveLiteral, "rawValue", val); + this.next(); - return this.finishNode(node, "Directive"); + + directive.value = this.finishNode(directiveLiteral, "DirectiveLiteral"); + + this.semicolon(); + return this.finishNode(directive, "Directive"); }; // Parse a single statement. @@ -89,16 +99,18 @@ pp.parseStatement = function (declaration, topLevel) { case tt._export: case tt._import: if (!this.options.allowImportExportEverywhere) { - if (!topLevel) + if (!topLevel) { this.raise(this.state.start, "'import' and 'export' may only appear at the top level"); + } - if (!this.inModule) + if (!this.inModule) { this.raise(this.state.start, "'import' and 'export' may appear only with 'sourceType: module'"); + } } return starttype === tt._import ? this.parseImport(node) : this.parseExport(node); case tt.name: - if (this.hasFeature("asyncFunctions") && this.state.value === "async") { + if (this.hasPlugin("asyncFunctions") && this.state.value === "async") { // peek ahead and see if next token is a function let state = this.state.clone(); this.next(); @@ -147,7 +159,7 @@ pp.parseDecorators = function (allowExport) { }; pp.parseDecorator = function () { - if (!this.hasFeature("decorators")) { + if (!this.hasPlugin("decorators")) { this.unexpected(); } let node = this.startNode(); @@ -171,7 +183,8 @@ pp.parseBreakContinueStatement = function (node, keyword) { // Verify that there is an actual destination to break or // continue to. - for (var i = 0; i < this.state.labels.length; ++i) { + let i; + for (i = 0; i < this.state.labels.length; ++i) { let lab = this.state.labels[i]; if (node.label == null || lab.name === node.label.name) { if (lab.kind != null && (isBreak || lab.kind === "loop")) break; @@ -288,7 +301,8 @@ pp.parseSwitchStatement = function (node) { // nodes. `cur` is used to keep the node that we are currently // adding statements to. - for (var cur, sawDefault; !this.match(tt.braceR); ) { + let cur; + for (let sawDefault; !this.match(tt.braceR); ) { if (this.match(tt._case) || this.match(tt._default)) { let isCase = this.match(tt._case); if (cur) this.finishNode(cur, "SwitchCase"); @@ -304,8 +318,11 @@ pp.parseSwitchStatement = function (node) { } this.expect(tt.colon); } else { - if (!cur) this.unexpected(); - cur.consequent.push(this.parseStatement(true)); + if (cur) { + cur.consequent.push(this.parseStatement(true)); + } else { + this.unexpected(); + } } } if (cur) this.finishNode(cur, "SwitchCase"); @@ -325,19 +342,23 @@ pp.parseThrowStatement = function (node) { // Reused empty array added for node fields that are always empty. -var empty = []; +let empty = []; pp.parseTryStatement = function (node) { this.next(); + node.block = this.parseBlock(); node.handler = null; + if (this.match(tt._catch)) { let clause = this.startNode(); this.next(); + this.expect(tt.parenL); clause.param = this.parseBindingAtom(); this.checkLVal(clause.param, true, Object.create(null)); this.expect(tt.parenR); + clause.body = this.parseBlock(); node.handler = this.finishNode(clause, "CatchClause"); } @@ -416,35 +437,55 @@ pp.parseExpressionStatement = function (node, expr) { // strict"` declarations when `allowStrict` is true (used for // function bodies). -pp.parseBlock = function (allowStrict) { +pp.parseBlock = function (allowDirectives?) { let node = this.startNode(); this.expect(tt.braceL); - this.parseBlockBody(node, allowStrict, tt.braceR); + this.parseBlockBody(node, allowDirectives, false, tt.braceR); return this.finishNode(node, "BlockStatement"); }; // TODO -pp.parseBlockBody = function (node, allowStrict, end) { +pp.parseBlockBody = function (node, allowDirectives, topLevel, end) { node.body = []; node.directives = []; let parsedNonDirective = false; let oldStrict; + let octalPosition; while (!this.eat(end)) { - if (!parsedNonDirective && this.match(tt.string)) { - let stmt = this.parseDirective(); - node.directives.push(stmt); + if (allowDirectives && !parsedNonDirective && this.match(tt.string)) { + let oldState = this.state; + let lookahead = this.lookahead(); + this.state = lookahead; + let isDirective = this.isLineTerminator(); + this.state = oldState; - if (allowStrict && stmt.value === "use strict") { - oldStrict = this.state.strict; - this.setStrict(this.state.strict = true); + if (isDirective) { + if (this.state.containsOctal && !octalPosition) { + octalPosition = this.state.octalPosition; + } + + let stmt = this.parseDirective(); + node.directives.push(stmt); + + if (allowDirectives && stmt.value.value === "use strict") { + oldStrict = this.state.strict; + this.state.strict = true; + this.setStrict(true); + + if (octalPosition) { + this.raise(octalPosition, "Octal literal in strict mode"); + } + } + + continue; } - } else { - parsedNonDirective = true; - node.body.push(this.parseStatement(true)); } + + parsedNonDirective = true; + node.body.push(this.parseStatement(true, topLevel)); } if (oldStrict === false) { @@ -514,25 +555,39 @@ pp.parseVarHead = function (decl) { // `isStatement` parameter). pp.parseFunction = function (node, isStatement, allowExpressionBody, isAsync, optionalId) { - this.initFunction(node, isAsync); - node.generator = this.eat(tt.star); + let oldInMethod = this.state.inMethod; + this.state.inMethod = false; - if (isStatement && !optionalId && !this.match(tt.name)) { + this.initFunction(node, isAsync); + + if (this.match(tt.star)) { + if (node.async && !this.hasPlugin("asyncGenerators")) { + this.unexpected(); + } else { + node.generator = true; + this.next(); + } + } + + if (isStatement && !optionalId && !this.match(tt.name) && !this.match(tt._yield)) { this.unexpected(); } - if (this.match(tt.name)) { - node.id = this.parseIdentifier(); + if (this.match(tt.name) || this.match(tt._yield)) { + node.id = this.parseBindingIdentifier(); } this.parseFunctionParams(node); this.parseFunctionBody(node, allowExpressionBody); + + this.state.inMethod = oldInMethod; + return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression"); }; pp.parseFunctionParams = function (node) { this.expect(tt.parenL); - node.params = this.parseBindingList(tt.parenR, false, this.hasFeature("trailingFunctionCommas")); + node.params = this.parseBindingList(tt.parenR, false, this.hasPlugin("trailingFunctionCommas")); }; // Parse a class declaration or literal (depending on the @@ -542,51 +597,99 @@ pp.parseClass = function (node, isStatement, optionalId) { this.next(); this.parseClassId(node, isStatement, optionalId); this.parseClassSuper(node); - var classBody = this.startNode(); + this.parseClassBody(node); + return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); +}; + +pp.isClassProperty = function () { + return this.match(tt.eq) || this.isLineTerminator(); +}; + +pp.parseClassBody = function (node) { + // class bodies are implicitly strict + let oldStrict = this.state.strict; + this.state.strict = true; + + let hadConstructorCall = false; let hadConstructor = false; - classBody.body = []; - this.expect(tt.braceL); let decorators = []; + let classBody = this.startNode(); + + classBody.body = []; + + this.expect(tt.braceL); + while (!this.eat(tt.braceR)) { - if (this.eat(tt.semi)) continue; + if (this.eat(tt.semi)) { + continue; + } + if (this.match(tt.at)) { decorators.push(this.parseDecorator()); continue; } - var method = this.startNode(); + + let method = this.startNode(); + + // steal the decorators if there are any if (decorators.length) { method.decorators = decorators; decorators = []; } + + let isConstructorCall = false; let isMaybeStatic = this.match(tt.name) && this.state.value === "static"; - var isGenerator = this.eat(tt.star), isAsync = false; + let isGenerator = this.eat(tt.star); + let isGetSet = false; + let isAsync = false; + this.parsePropertyName(method); + method.static = isMaybeStatic && !this.match(tt.parenL); if (method.static) { if (isGenerator) this.unexpected(); isGenerator = this.eat(tt.star); this.parsePropertyName(method); } - if (!isGenerator && method.key.type === "Identifier" && !method.computed && this.isClassProperty()) { - classBody.body.push(this.parseClassProperty(method)); - continue; + + if (!isGenerator && method.key.type === "Identifier" && !method.computed) { + if (this.isClassProperty()) { + classBody.body.push(this.parseClassProperty(method)); + continue; + } + + if (this.hasPlugin("classConstructorCall") && method.key.name === "call" && this.match(tt.name) && this.state.value === "constructor") { + isConstructorCall = true; + this.parsePropertyName(method); + } } - if (this.hasFeature("asyncFunctions") && !this.match(tt.parenL) && - !method.computed && method.key.type === "Identifier" && method.key.name === "async") { + + let isAsyncMethod = this.hasPlugin("asyncFunctions") && !this.match(tt.parenL) && !method.computed && method.key.type === "Identifier" && method.key.name === "async"; + if (isAsyncMethod) { + if (this.hasPlugin("asyncGenerators") && this.eat(tt.star)) isGenerator = true; isAsync = true; this.parsePropertyName(method); } - let isGetSet = false; + method.kind = "method"; + if (!method.computed) { - let {key} = method; + let { key } = method; + + // handle get/set methods + // eg. class Foo { get bar() {} set bar() {} } if (!isAsync && !isGenerator && key.type === "Identifier" && !this.match(tt.parenL) && (key.name === "get" || key.name === "set")) { isGetSet = true; method.kind = key.name; key = this.parsePropertyName(method); } - if (!method.static && (key.type === "Identifier" && key.name === "constructor" || - key.type === "StringLiteral" && key.value === "constructor")) { + + // disallow invalid constructors + let isConstructor = !isConstructorCall && !method.static && ( + (key.type === "Identifier" && key.name === "constructor") || + (key.type === "StringLiteral" && key.value === "constructor") + ); + if (isConstructor) { if (hadConstructor) this.raise(key.start, "Duplicate constructor in the same class"); if (isGetSet) this.raise(key.start, "Constructor can't have get/set modifier"); if (isGenerator) this.raise(key.start, "Constructor can't be a generator"); @@ -594,15 +697,37 @@ pp.parseClass = function (node, isStatement, optionalId) { method.kind = "constructor"; hadConstructor = true; } + + // disallow static prototype method + let isStaticPrototype = method.static && ( + (key.type === "Identifier" && key.name === "prototype") || + (key.type === "StringLiteral" && key.value === "prototype") + ); + if (isStaticPrototype) { + this.raise(key.start, "Classes may not have static property named prototype"); + } } - if (method.kind === "constructor" && method.decorators) { + + // convert constructor to a constructor call + if (isConstructorCall) { + if (hadConstructorCall) this.raise(method.start, "Duplicate constructor call in the same class"); + method.kind = "constructorCall"; + hadConstructorCall = true; + } + + // disallow decorators on class constructors + if ((method.kind === "constructor" || method.kind === "constructorCall") && method.decorators) { this.raise(method.start, "You can't attach decorators to a class constructor"); } + this.parseClassMethod(classBody, method, isGenerator, isAsync); + + // get methods aren't allowed to have any parameters + // set methods must have exactly 1 parameter if (isGetSet) { let paramCount = method.kind === "get" ? 0 : 1; - if (method.value.params.length !== paramCount) { - let start = method.value.start; + if (method.params.length !== paramCount) { + let start = method.start; if (method.kind === "get") { this.raise(start, "getter should have no params"); } else { @@ -617,16 +742,13 @@ pp.parseClass = function (node, isStatement, optionalId) { } node.body = this.finishNode(classBody, "ClassBody"); - return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); -}; -pp.isClassProperty = function () { - return this.match(tt.eq) || (this.match(tt.semi) || this.canInsertSemicolon()); + this.state.strict = oldStrict; }; pp.parseClassProperty = function (node) { if (this.match(tt.eq)) { - if (!this.hasFeature("classProperties")) this.unexpected(); + if (!this.hasPlugin("classProperties")) this.unexpected(); this.next(); node.value = this.parseMaybeAssign(); } else { @@ -637,8 +759,8 @@ pp.parseClassProperty = function (node) { }; pp.parseClassMethod = function (classBody, method, isGenerator, isAsync) { - method.value = this.parseMethod(isGenerator, isAsync); - classBody.body.push(this.finishNode(method, "MethodDefinition")); + this.parseMethod(method, isGenerator, isAsync); + classBody.body.push(this.finishNode(method, "ClassMethod")); }; pp.parseClassId = function (node, isStatement, optionalId) { @@ -665,7 +787,7 @@ pp.parseExport = function (node) { if (this.match(tt.star)) { let specifier = this.startNode(); this.next(); - if (this.hasFeature("exportExtensions") && this.eatContextual("as")) { + if (this.hasPlugin("exportExtensions") && this.eatContextual("as")) { specifier.exported = this.parseIdentifier(); node.specifiers = [this.finishNode(specifier, "ExportNamespaceSpecifier")]; this.parseExportSpecifiersMaybe(node); @@ -674,7 +796,7 @@ pp.parseExport = function (node) { this.parseExportFrom(node, true); return this.finishNode(node, "ExportAllDeclaration"); } - } else if (this.hasFeature("exportExtensions") && this.isExportDefaultSpecifier()) { + } else if (this.hasPlugin("exportExtensions") && this.isExportDefaultSpecifier()) { let specifier = this.startNode(); specifier.exported = this.parseIdentifier(true); node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; @@ -730,7 +852,7 @@ pp.isExportDefaultSpecifier = function () { return false; } - var lookahead = this.lookahead(); + let lookahead = this.lookahead(); return lookahead.type === tt.comma || (lookahead.type === tt.name && lookahead.value === "from"); }; @@ -756,12 +878,12 @@ pp.parseExportFrom = function (node, expect?) { }; pp.shouldParseExportDeclaration = function () { - return this.hasFeature("asyncFunctions") && this.isContextual("async"); + return this.hasPlugin("asyncFunctions") && this.isContextual("async"); }; pp.checkExport = function (node) { if (this.state.decorators.length) { - var isClass = node.declaration && (node.declaration.type === "ClassDeclaration" || node.declaration.type === "ClassExpression"); + let isClass = node.declaration && (node.declaration.type === "ClassDeclaration" || node.declaration.type === "ClassExpression"); if (!node.declaration || !isClass) { this.raise(node.start, "You can only use decorators on an export when exporting a class"); } @@ -826,10 +948,10 @@ pp.parseImport = function (node) { // Parses a comma-separated list of module imports. pp.parseImportSpecifiers = function (node) { - var first = true; + let first = true; if (this.match(tt.name)) { // import defaultObj, { x, y as z } from '...' - var startPos = this.state.start, startLoc = this.state.startLoc; + let startPos = this.state.start, startLoc = this.state.startLoc; node.specifiers.push(this.parseImportSpecifierDefault(this.parseIdentifier(), startPos, startLoc)); if (!this.eat(tt.comma)) return; } @@ -862,7 +984,7 @@ pp.parseImportSpecifiers = function (node) { }; pp.parseImportSpecifierDefault = function (id, startPos, startLoc) { - var node = this.startNodeAt(startPos, startLoc); + let node = this.startNodeAt(startPos, startLoc); node.local = id; this.checkLVal(node.local, true); return this.finishNode(node, "ImportDefaultSpecifier"); diff --git a/packages/babylon/src/parser/util.js b/packages/babylon/src/parser/util.js index e20e2467c9..64d4bffe3c 100644 --- a/packages/babylon/src/parser/util.js +++ b/packages/babylon/src/parser/util.js @@ -13,7 +13,7 @@ const pp = Parser.prototype; pp.addExtra = function (node, key, val) { if (!node) return; - var extra = node.extra = node.extra || {}; + let extra = node.extra = node.extra || {}; extra[key] = val; }; diff --git a/packages/babylon/src/plugins/flow.js b/packages/babylon/src/plugins/flow.js index 7fe1d97d19..25e0ced340 100644 --- a/packages/babylon/src/plugins/flow.js +++ b/packages/babylon/src/plugins/flow.js @@ -3,13 +3,13 @@ import { types as tt } from "../tokenizer/types"; import Parser from "../parser"; -var pp = Parser.prototype; +let pp = Parser.prototype; pp.flowParseTypeInitialiser = function (tok) { - var oldInType = this.state.inType; + let oldInType = this.state.inType; this.state.inType = true; this.expect(tok || tt.colon); - var type = this.flowParseType(); + let type = this.flowParseType(); this.state.inType = oldInType; return type; }; @@ -23,10 +23,10 @@ pp.flowParseDeclareClass = function (node) { pp.flowParseDeclareFunction = function (node) { this.next(); - var id = node.id = this.parseIdentifier(); + let id = node.id = this.parseIdentifier(); - var typeNode = this.startNode(); - var typeContainer = this.startNode(); + let typeNode = this.startNode(); + let typeContainer = this.startNode(); if (this.isRelational("<")) { typeNode.typeParameters = this.flowParseTypeParameterDeclaration(); @@ -35,7 +35,7 @@ pp.flowParseDeclareFunction = function (node) { } this.expect(tt.parenL); - var tmp = this.flowParseFunctionTypeParams(); + let tmp = this.flowParseFunctionTypeParams(); typeNode.params = tmp.params; typeNode.rest = tmp.rest; this.expect(tt.parenR); @@ -81,11 +81,11 @@ pp.flowParseDeclareModule = function (node) { node.id = this.parseIdentifier(); } - var bodyNode = node.body = this.startNode(); - var body = bodyNode.body = []; + let bodyNode = node.body = this.startNode(); + let body = bodyNode.body = []; this.expect(tt.braceL); while (!this.match(tt.braceR)) { - var node2 = this.startNode(); + let node2 = this.startNode(); // todo: declare check this.next(); @@ -122,7 +122,7 @@ pp.flowParseInterfaceish = function (node, allowStatic) { }; pp.flowParseInterfaceExtends = function () { - var node = this.startNode(); + let node = this.startNode(); node.id = this.parseIdentifier(); if (this.isRelational("<")) { @@ -159,7 +159,7 @@ pp.flowParseTypeAlias = function (node) { // Type annotations pp.flowParseTypeParameterDeclaration = function () { - var node = this.startNode(); + let node = this.startNode(); node.params = []; this.expectRelational("<"); @@ -175,7 +175,7 @@ pp.flowParseTypeParameterDeclaration = function () { }; pp.flowParseTypeParameterInstantiation = function () { - var node = this.startNode(), oldInType = this.state.inType; + let node = this.startNode(), oldInType = this.state.inType; node.params = []; this.state.inType = true; @@ -238,7 +238,7 @@ pp.flowParseObjectTypeMethodish = function (node) { }; pp.flowParseObjectTypeMethod = function (startPos, startLoc, isStatic, key) { - var node = this.startNodeAt(startPos, startLoc); + let node = this.startNodeAt(startPos, startLoc); node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(startPos, startLoc)); node.static = isStatic; node.key = key; @@ -248,7 +248,7 @@ pp.flowParseObjectTypeMethod = function (startPos, startLoc, isStatic, key) { }; pp.flowParseObjectTypeCallProperty = function (node, isStatic) { - var valueNode = this.startNode(); + let valueNode = this.startNode(); node.static = isStatic; node.value = this.flowParseObjectTypeMethodish(valueNode); this.flowObjectTypeSemicolon(); @@ -256,10 +256,10 @@ pp.flowParseObjectTypeCallProperty = function (node, isStatic) { }; pp.flowParseObjectType = function (allowStatic) { - var nodeStart = this.startNode(); - var node; - var propertyKey; - var isStatic; + let nodeStart = this.startNode(); + let node; + let propertyKey; + let isStatic; nodeStart.callProperties = []; nodeStart.properties = []; @@ -268,8 +268,8 @@ pp.flowParseObjectType = function (allowStatic) { this.expect(tt.braceL); while (!this.match(tt.braceR)) { - var optional = false; - var startPos = this.state.start, startLoc = this.state.startLoc; + let optional = false; + let startPos = this.state.start, startLoc = this.state.startLoc; node = this.startNode(); if (allowStatic && this.isContextual("static")) { this.next(); @@ -315,13 +315,13 @@ pp.flowObjectTypeSemicolon = function () { }; pp.flowParseGenericType = function (startPos, startLoc, id) { - var node = this.startNodeAt(startPos, startLoc); + let node = this.startNodeAt(startPos, startLoc); node.typeParameters = null; node.id = id; while (this.eat(tt.dot)) { - var node2 = this.startNodeAt(startPos, startLoc); + let node2 = this.startNodeAt(startPos, startLoc); node2.qualification = node.id; node2.id = this.parseIdentifier(); node.id = this.finishNode(node2, "QualifiedTypeIdentifier"); @@ -335,14 +335,14 @@ pp.flowParseGenericType = function (startPos, startLoc, id) { }; pp.flowParseTypeofType = function () { - var node = this.startNode(); + let node = this.startNode(); this.expect(tt._typeof); node.argument = this.flowParsePrimaryType(); return this.finishNode(node, "TypeofTypeAnnotation"); }; pp.flowParseTupleType = function () { - var node = this.startNode(); + let node = this.startNode(); node.types = []; this.expect(tt.bracketL); // We allow trailing commas @@ -356,8 +356,8 @@ pp.flowParseTupleType = function () { }; pp.flowParseFunctionTypeParam = function () { - var optional = false; - var node = this.startNode(); + let optional = false; + let node = this.startNode(); node.name = this.parseIdentifier(); if (this.eat(tt.question)) { optional = true; @@ -368,7 +368,7 @@ pp.flowParseFunctionTypeParam = function () { }; pp.flowParseFunctionTypeParams = function () { - var ret = { params: [], rest: null }; + let ret = { params: [], rest: null }; while (this.match(tt.name)) { ret.params.push(this.flowParseFunctionTypeParam()); if (!this.match(tt.parenR)) { @@ -411,11 +411,11 @@ pp.flowIdentToTypeAnnotation = function (startPos, startLoc, node, id) { // primary types are kind of like primary expressions...they're the // primitives with which other types are constructed. pp.flowParsePrimaryType = function () { - var startPos = this.state.start, startLoc = this.state.startLoc; - var node = this.startNode(); - var tmp; - var type; - var isGroupedType = false; + let startPos = this.state.start, startLoc = this.state.startLoc; + let node = this.startNode(); + let tmp; + let type; + let isGroupedType = false; switch (this.state.type) { case tt.name: @@ -449,7 +449,7 @@ pp.flowParsePrimaryType = function () { // Check to see if this is actually a grouped type if (!this.match(tt.parenR) && !this.match(tt.ellipsis)) { if (this.match(tt.name)) { - var token = this.lookahead().type; + let token = this.lookahead().type; isGroupedType = token !== tt.question && token !== tt.colon; } else { isGroupedType = true; @@ -490,8 +490,9 @@ pp.flowParsePrimaryType = function () { return this.finishNode(node, "FunctionTypeAnnotation"); case tt.string: - node.rawValue = node.value = this.state.value; - node.raw = this.input.slice(this.state.start, this.state.end); + node.value = this.state.value; + this.addExtra(node, "rawValue", node.value); + this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end)); this.next(); return this.finishNode(node, "StringLiteralTypeAnnotation"); @@ -501,8 +502,9 @@ pp.flowParsePrimaryType = function () { return this.finishNode(node, "BooleanLiteralTypeAnnotation"); case tt.num: - node.rawValue = node.value = this.state.value; - node.raw = this.input.slice(this.state.start, this.state.end); + node.value = this.state.value; + this.addExtra(node, "rawValue", node.value); + this.addExtra(node, "raw", this.input.slice(this.state.start, this.state.end)); this.next(); return this.finishNode(node, "NumberLiteralTypeAnnotation"); @@ -516,8 +518,8 @@ pp.flowParsePrimaryType = function () { }; pp.flowParsePostfixType = function () { - var node = this.startNode(); - var type = node.elementType = this.flowParsePrimaryType(); + let node = this.startNode(); + let type = node.elementType = this.flowParsePrimaryType(); if (this.match(tt.bracketL)) { this.expect(tt.bracketL); this.expect(tt.bracketR); @@ -528,7 +530,7 @@ pp.flowParsePostfixType = function () { }; pp.flowParsePrefixType = function () { - var node = this.startNode(); + let node = this.startNode(); if (this.eat(tt.question)) { node.typeAnnotation = this.flowParsePrefixType(); return this.finishNode(node, "NullableTypeAnnotation"); @@ -538,8 +540,8 @@ pp.flowParsePrefixType = function () { }; pp.flowParseIntersectionType = function () { - var node = this.startNode(); - var type = this.flowParsePrefixType(); + let node = this.startNode(); + let type = this.flowParsePrefixType(); node.types = [type]; while (this.eat(tt.bitwiseAND)) { node.types.push(this.flowParsePrefixType()); @@ -548,8 +550,8 @@ pp.flowParseIntersectionType = function () { }; pp.flowParseUnionType = function () { - var node = this.startNode(); - var type = this.flowParseIntersectionType(); + let node = this.startNode(); + let type = this.flowParseIntersectionType(); node.types = [type]; while (this.eat(tt.bitwiseOR)) { node.types.push(this.flowParseIntersectionType()); @@ -558,22 +560,22 @@ pp.flowParseUnionType = function () { }; pp.flowParseType = function () { - var oldInType = this.state.inType; + let oldInType = this.state.inType; this.state.inType = true; - var type = this.flowParseUnionType(); + let type = this.flowParseUnionType(); this.state.inType = oldInType; return type; }; pp.flowParseTypeAnnotation = function () { - var node = this.startNode(); + let node = this.startNode(); node.typeAnnotation = this.flowParseTypeInitialiser(); return this.finishNode(node, "TypeAnnotation"); }; pp.flowParseTypeAnnotatableIdentifier = function (requireTypeAnnotation, canBeOptionalParam) { - var ident = this.parseIdentifier(); - var isOptionalParam = false; + let ident = this.parseIdentifier(); + let isOptionalParam = false; if (canBeOptionalParam && this.eat(tt.question)) { this.expect(tt.question); @@ -612,7 +614,7 @@ export default function (instance) { return function (declaration, topLevel) { // strict mode handling of `interface` since it's a reserved word if (this.state.strict && this.match(tt.name) && this.state.value === "interface") { - var node = this.startNode(); + let node = this.startNode(); this.next(); return this.flowParseInterface(node); } else { @@ -652,7 +654,7 @@ export default function (instance) { instance.extend("parseParenItem", function () { return function (node, startLoc, startPos, forceArrow?) { if (this.match(tt.colon)) { - var typeCastNode = this.startNodeAt(startLoc, startPos); + let typeCastNode = this.startNodeAt(startLoc, startPos); typeCastNode.expression = node; typeCastNode.typeAnnotation = this.flowParseTypeAnnotation(); @@ -662,7 +664,7 @@ export default function (instance) { if (this.eat(tt.arrow)) { // ((lol): number => {}); - var func = this.parseArrowExpression(this.startNodeAt(startLoc, startPos), [node]); + let func = this.parseArrowExpression(this.startNodeAt(startLoc, startPos), [node]); func.returnType = typeCastNode.typeAnnotation; return func; } else { @@ -689,7 +691,7 @@ export default function (instance) { if (this.isContextual("type")) { node.exportKind = "type"; - var declarationNode = this.startNode(); + let declarationNode = this.startNode(); this.next(); if (this.match(tt.braceL)) { @@ -754,8 +756,8 @@ export default function (instance) { // turn type casts that we found in function parameter head into type annotated params instance.extend("toAssignableList", function (inner) { return function (exprList, isBinding) { - for (var i = 0; i < exprList.length; i++) { - var expr = exprList[i]; + for (let i = 0; i < exprList.length; i++) { + let expr = exprList[i]; if (expr && expr.type === "TypeCastExpression") { exprList[i] = typeCastToParameter(expr); } @@ -768,8 +770,8 @@ export default function (instance) { // type casts that we've found that are illegal in this context instance.extend("toReferencedList", function () { return function (exprList) { - for (var i = 0; i < exprList.length; i++) { - var expr = exprList[i]; + for (let i = 0; i < exprList.length; i++) { + let expr = exprList[i]; if (expr && expr._exprListItem && expr.type === "TypeCastExpression") { this.raise(expr.start, "Unexpected type cast"); } @@ -783,8 +785,8 @@ export default function (instance) { // the position where this function is cal;ed instance.extend("parseExprListItem", function (inner) { return function (allowEmpty, refShorthandDefaultPos) { - var container = this.startNode(); - var node = inner.call(this, allowEmpty, refShorthandDefaultPos); + let container = this.startNode(); + let node = inner.call(this, allowEmpty, refShorthandDefaultPos); if (this.match(tt.colon)) { container._exprListItem = true; container.expression = node; @@ -816,13 +818,11 @@ export default function (instance) { // parse type parameters for class methods instance.extend("parseClassMethod", function () { return function (classBody, method, isGenerator, isAsync) { - var typeParameters; if (this.isRelational("<")) { - typeParameters = this.flowParseTypeParameterDeclaration(); + method.typeParameters = this.flowParseTypeParameterDeclaration(); } - method.value = this.parseMethod(isGenerator, isAsync); - method.value.typeParameters = typeParameters; - classBody.body.push(this.finishNode(method, "MethodDefinition")); + this.parseMethod(method, isGenerator, isAsync); + classBody.body.push(this.finishNode(method, "ClassMethod")); }; }); @@ -835,7 +835,7 @@ export default function (instance) { } if (this.isContextual("implements")) { this.next(); - var implemented = node.implements = []; + let implemented = node.implements = []; do { let node = this.startNode(); node.id = this.parseIdentifier(); @@ -853,7 +853,7 @@ export default function (instance) { // parse type parameters for object method shorthand instance.extend("parseObjPropValue", function (inner) { return function (prop) { - var typeParameters; + let typeParameters; // method shorthand if (this.isRelational("<")) { @@ -865,7 +865,7 @@ export default function (instance) { // add typeParameters if we found them if (typeParameters) { - prop.value.typeParameters = typeParameters; + (prop.value || prop).typeParameters = typeParameters; } }; }); @@ -889,14 +889,14 @@ export default function (instance) { return function (node) { node.importKind = "value"; - var kind = null; + let kind = null; if (this.match(tt._typeof)) { kind = "typeof"; } else if (this.isContextual("type")) { kind = "type"; } if (kind) { - var lh = this.lookahead(); + let lh = this.lookahead(); if ((lh.type === tt.name && lh.value !== "from") || lh.type === tt.braceL || lh.type === tt.star) { this.next(); node.importKind = kind; @@ -917,7 +917,7 @@ export default function (instance) { }; }); - // parse flow type annotations on variable declarator heads - var foo: string = bar + // parse flow type annotations on variable declarator heads - let foo: string = bar instance.extend("parseVarHead", function (inner) { return function (decl) { inner.call(this, decl); @@ -928,7 +928,7 @@ export default function (instance) { }; }); - // parse the return type of an async arrow function - var foo = (async (): number => {}); + // parse the return type of an async arrow function - let foo = (async (): number => {}); instance.extend("parseAsyncArrowFromCallExpression", function (inner) { return function (node, call) { if (this.match(tt.colon)) { @@ -953,7 +953,7 @@ export default function (instance) { startLoc = startLoc || this.state.startLoc; if (this.lookahead().type === tt.parenR) { - // var foo = (): number => {}; + // let foo = (): number => {}; this.expect(tt.parenL); this.expect(tt.parenR); @@ -962,11 +962,11 @@ export default function (instance) { this.expect(tt.arrow); return this.parseArrowExpression(node, [], isAsync); } else { - // var foo = (foo): number => {}; + // let foo = (foo): number => {}; let node = inner.call(this, startPos, startLoc, canBeArrow, isAsync); if (this.match(tt.colon)) { - var state = this.state.clone(); + let state = this.state.clone(); try { return this.parseParenItem(node, startPos, startLoc, true); } catch (err) { diff --git a/packages/babylon/src/plugins/jsx/index.js b/packages/babylon/src/plugins/jsx/index.js index c373f88b8d..2d466d4ece 100644 --- a/packages/babylon/src/plugins/jsx/index.js +++ b/packages/babylon/src/plugins/jsx/index.js @@ -26,7 +26,7 @@ tt.jsxTagStart.updateContext = function() { }; tt.jsxTagEnd.updateContext = function(prevType) { - var out = this.state.context.pop(); + let out = this.state.context.pop(); if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) { this.state.context.pop(); this.state.exprAllowed = this.curContext() === tc.j_expr; @@ -35,18 +35,19 @@ tt.jsxTagEnd.updateContext = function(prevType) { } }; -var pp = Parser.prototype; +let pp = Parser.prototype; // Reads inline JSX contents token. pp.jsxReadToken = function() { - var out = "", chunkStart = this.state.pos; + let out = ""; + let chunkStart = this.state.pos; for (;;) { if (this.state.pos >= this.input.length) { this.raise(this.state.start, "Unterminated JSX contents"); } - var ch = this.input.charCodeAt(this.state.pos); + let ch = this.input.charCodeAt(this.state.pos); switch (ch) { case 60: // "<" @@ -80,8 +81,8 @@ pp.jsxReadToken = function() { }; pp.jsxReadNewLine = function(normalizeCRLF) { - var ch = this.input.charCodeAt(this.state.pos); - var out; + let ch = this.input.charCodeAt(this.state.pos); + let out; ++this.state.pos; if (ch === 13 && this.input.charCodeAt(this.state.pos) === 10) { ++this.state.pos; @@ -96,13 +97,14 @@ pp.jsxReadNewLine = function(normalizeCRLF) { }; pp.jsxReadString = function(quote) { - var out = "", chunkStart = ++this.state.pos; + let out = ""; + let chunkStart = ++this.state.pos; for (;;) { if (this.state.pos >= this.input.length) { this.raise(this.state.start, "Unterminated string constant"); } - var ch = this.input.charCodeAt(this.state.pos); + let ch = this.input.charCodeAt(this.state.pos); if (ch === quote) break; if (ch === 38) { // "&" out += this.input.slice(chunkStart, this.state.pos); @@ -121,10 +123,12 @@ pp.jsxReadString = function(quote) { }; pp.jsxReadEntity = function() { - var str = "", count = 0, entity; - var ch = this.input[this.state.pos]; + let str = ""; + let count = 0; + let entity; + let ch = this.input[this.state.pos]; - var startPos = ++this.state.pos; + let startPos = ++this.state.pos; while (this.state.pos < this.input.length && count++ < 10) { ch = this.input[this.state.pos++]; if (ch === ";") { @@ -161,7 +165,8 @@ pp.jsxReadEntity = function() { // by isIdentifierStart in readToken. pp.jsxReadWord = function() { - var ch, start = this.state.pos; + let ch; + let start = this.state.pos; do { ch = this.input.charCodeAt(++this.state.pos); } while (isIdentifierChar(ch) || ch === 45); // "-" @@ -187,7 +192,7 @@ function getQualifiedJSXName(object) { // Parse next token as JSX identifier pp.jsxParseIdentifier = function() { - var node = this.startNode(); + let node = this.startNode(); if (this.match(tt.jsxName)) { node.name = this.state.value; } else if (this.state.type.keyword) { @@ -202,11 +207,11 @@ pp.jsxParseIdentifier = function() { // Parse namespaced identifier. pp.jsxParseNamespacedName = function() { - var startPos = this.state.start, startLoc = this.state.startLoc; - var name = this.jsxParseIdentifier(); + let startPos = this.state.start, startLoc = this.state.startLoc; + let name = this.jsxParseIdentifier(); if (!this.eat(tt.colon)) return name; - var node = this.startNodeAt(startPos, startLoc); + let node = this.startNodeAt(startPos, startLoc); node.namespace = name; node.name = this.jsxParseIdentifier(); return this.finishNode(node, "JSXNamespacedName"); @@ -216,10 +221,10 @@ pp.jsxParseNamespacedName = function() { // or single identifier. pp.jsxParseElementName = function() { - var startPos = this.state.start, startLoc = this.state.startLoc; - var node = this.jsxParseNamespacedName(); + let startPos = this.state.start, startLoc = this.state.startLoc; + let node = this.jsxParseNamespacedName(); while (this.eat(tt.dot)) { - var newNode = this.startNodeAt(startPos, startLoc); + let newNode = this.startNodeAt(startPos, startLoc); newNode.object = node; newNode.property = this.jsxParseIdentifier(); node = this.finishNode(newNode, "JSXMemberExpression"); @@ -230,7 +235,7 @@ pp.jsxParseElementName = function() { // Parses any type of JSX attribute value. pp.jsxParseAttributeValue = function() { - var node; + let node; switch (this.state.type) { case tt.braceL: node = this.jsxParseExpressionContainer(); @@ -243,7 +248,7 @@ pp.jsxParseAttributeValue = function() { case tt.jsxTagStart: case tt.string: node = this.parseExprAtom(); - node.rawValue = null; + node.extra = null; return node; default: @@ -251,27 +256,20 @@ pp.jsxParseAttributeValue = function() { } }; -// JSXEmptyExpression is unique type since it doesn"t actually parse anything, +// JSXEmptyExpression is unique type since it doesn't actually parse anything, // and so it should start at the end of last read token (left brace) and finish // at the beginning of the next one (right brace). pp.jsxParseEmptyExpression = function() { - var tmp = this.state.start; - this.state.start = this.state.lastTokEnd; - this.state.lastTokEnd = tmp; - - tmp = this.state.startLoc; - this.state.startLoc = this.state.lastTokEndLoc; - this.state.lastTokEndLoc = tmp; - - return this.finishNode(this.startNode(), "JSXEmptyExpression"); + let node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc); + return this.finishNodeAt(node, "JSXEmptyExpression", this.start, this.startLoc); }; // Parses JSX expression enclosed into curly brackets. pp.jsxParseExpressionContainer = function() { - var node = this.startNode(); + let node = this.startNode(); this.next(); if (this.match(tt.braceR)) { node.expression = this.jsxParseEmptyExpression(); @@ -285,7 +283,7 @@ pp.jsxParseExpressionContainer = function() { // Parses following JSX attribute name-value pair. pp.jsxParseAttribute = function() { - var node = this.startNode(); + let node = this.startNode(); if (this.eat(tt.braceL)) { this.expect(tt.ellipsis); node.argument = this.parseMaybeAssign(); @@ -300,7 +298,7 @@ pp.jsxParseAttribute = function() { // Parses JSX opening tag starting after "<". pp.jsxParseOpeningElementAt = function(startPos, startLoc) { - var node = this.startNodeAt(startPos, startLoc); + let node = this.startNodeAt(startPos, startLoc); node.attributes = []; node.name = this.jsxParseElementName(); while (!this.match(tt.slash) && !this.match(tt.jsxTagEnd)) { @@ -314,7 +312,7 @@ pp.jsxParseOpeningElementAt = function(startPos, startLoc) { // Parses JSX closing tag starting after "= this.input.length) return this.finishToken(tt.eof); @@ -162,7 +154,7 @@ export default class Tokenizer { } pushComment(block, text, start, end, startLoc, endLoc) { - var comment = { + let comment = { type: block ? "CommentBlock" : "CommentLine", value: text, start: start, @@ -308,11 +300,11 @@ export default class Tokenizer { } readToken_mult_modulo(code) { // '%*' - var type = code === 42 ? tt.star : tt.modulo; - var width = 1; - var next = this.input.charCodeAt(this.state.pos + 1); + let type = code === 42 ? tt.star : tt.modulo; + let width = 1; + let next = this.input.charCodeAt(this.state.pos + 1); - if (next === 42 && this.hasFeature("exponentiationOperator")) { // '*' + if (next === 42 && this.hasPlugin("exponentiationOperator")) { // '*' width++; next = this.input.charCodeAt(this.state.pos + 2); type = tt.exponent; @@ -415,7 +407,7 @@ export default class Tokenizer { case 125: ++this.state.pos; return this.finishToken(tt.braceR); case 58: - if (this.hasFeature("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) { + if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) { return this.finishOp(tt.doubleColon, 2); } else { ++this.state.pos; @@ -694,8 +686,14 @@ export default class Tokenizer { octalStr = octalStr.slice(0, -1); octal = parseInt(octalStr, 8); } - if (octal > 0 && (this.state.strict || inTemplate)) { - this.raise(this.state.pos - 2, "Octal literal in strict mode"); + if (octal > 0) { + if (!this.state.containsOctal) { + this.state.containsOctal = true; + this.state.octalPosition = this.state.pos - 2; + } + if (this.state.strict || inTemplate) { + this.raise(this.state.pos - 2, "Octal literal in strict mode"); + } } this.state.pos += octalStr.length - 1; return String.fromCharCode(octal); diff --git a/packages/babylon/src/tokenizer/state.js b/packages/babylon/src/tokenizer/state.js index b536a1fd8a..63107de019 100644 --- a/packages/babylon/src/tokenizer/state.js +++ b/packages/babylon/src/tokenizer/state.js @@ -14,7 +14,7 @@ export default class State { this.potentialArrowAt = -1; - this.inFunction = this.inGenerator = false; + this.inMethod = this.inFunction = this.inGenerator = this.inAsync = false; this.labels = []; @@ -42,7 +42,8 @@ export default class State { this.context = [ct.b_stat]; this.exprAllowed = true; - this.containsEsc = false; + this.containsEsc = this.containsOctal = false; + this.octalPosition = null; return this; } @@ -59,6 +60,7 @@ export default class State { // Flags to track whether we are in a function, a generator. inFunction: boolean; inGenerator: boolean; + inMethod: boolean; // Labels in scope. labels: Array; @@ -115,16 +117,20 @@ export default class State { // escape sequences must not be interpreted as keywords. containsEsc: boolean; + // TODO + containsOctal: boolean; + octalPosition: ?number; + curPosition() { return new Position(this.curLine, this.pos - this.lineStart); } clone(skipArrays?) { - var state = new State; - for (var key in this) { - var val = this[key]; + let state = new State; + for (let key in this) { + let val = this[key]; - if (!skipArrays && Array.isArray(val)) { + if ((!skipArrays || key === "context") && Array.isArray(val)) { val = val.slice(); } diff --git a/packages/babylon/src/tokenizer/types.js b/packages/babylon/src/tokenizer/types.js index 90b60f4ca2..fa8ff99bab 100644 --- a/packages/babylon/src/tokenizer/types.js +++ b/packages/babylon/src/tokenizer/types.js @@ -115,7 +115,7 @@ kw("catch"); kw("continue"); kw("debugger"); kw("default", beforeExpr); -kw("do", {isLoop: true}); +kw("do", {isLoop: true, beforeExpr: true}); kw("else", beforeExpr); kw("finally"); kw("for", {isLoop: true}); diff --git a/packages/babylon/src/util/identifier.js b/packages/babylon/src/util/identifier.js index 947e993ade..09045f8af0 100644 --- a/packages/babylon/src/util/identifier.js +++ b/packages/babylon/src/util/identifier.js @@ -49,7 +49,7 @@ nonASCIIidentifierStartChars = nonASCIIidentifierChars = null; // offset starts at 0x10000, and each pair of numbers represents an // offset to the next range, and then a size of the range. They were // generated by tools/generate-identifier-regex.js -var astralIdentifierStartCodes = [ +let astralIdentifierStartCodes = [ 0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 17, 26, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 99, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 98, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 26, 45, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, @@ -62,7 +62,7 @@ var astralIdentifierStartCodes = [ 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42710, 42, 4148, 12, 221, 16355, 541 ]; -var astralIdentifierCodes = [ +let astralIdentifierCodes = [ 509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 1306, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 52, 0, 13, 2, 49, 13, 16, 9, 83, 11, 168, 11, 6, 9, 8, 2, 57, 0, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 316, 19, 13, 9, 214, 6, 3, 8, 112, 16, 16, 9, 82, 12, 9, 9, 535, 9, 20855, 9, 135, 4, 60, 6, diff --git a/packages/babylon/test/fixtures/comments/basic/export-default-anonymous-class/expected.json b/packages/babylon/test/fixtures/comments/basic/export-default-anonymous-class/expected.json index 3599105db1..e42c57b979 100755 --- a/packages/babylon/test/fixtures/comments/basic/export-default-anonymous-class/expected.json +++ b/packages/babylon/test/fixtures/comments/basic/export-default-anonymous-class/expected.json @@ -74,7 +74,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 103, "end": 119, "loc": { @@ -107,41 +107,26 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 110, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 112, "end": 119, "loc": { "start": { "line": 8, - "column": 11 + "column": 13 }, "end": { "line": 9, "column": 5 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 112, - "end": 119, - "loc": { - "start": { - "line": 8, - "column": 13 - }, - "end": { - "line": 9, - "column": 5 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] }, "leadingComments": [ { diff --git a/packages/babylon/test/fixtures/core/uncategorised/542/actual.js b/packages/babylon/test/fixtures/core/uncategorised/.542/actual.js similarity index 100% rename from packages/babylon/test/fixtures/core/uncategorised/542/actual.js rename to packages/babylon/test/fixtures/core/uncategorised/.542/actual.js diff --git a/packages/babylon/test/fixtures/core/uncategorised/542/options.json b/packages/babylon/test/fixtures/core/uncategorised/.542/options.json similarity index 100% rename from packages/babylon/test/fixtures/core/uncategorised/542/options.json rename to packages/babylon/test/fixtures/core/uncategorised/.542/options.json diff --git a/packages/babylon/test/fixtures/core/uncategorised/543/actual.js b/packages/babylon/test/fixtures/core/uncategorised/.543/actual.js similarity index 100% rename from packages/babylon/test/fixtures/core/uncategorised/543/actual.js rename to packages/babylon/test/fixtures/core/uncategorised/.543/actual.js diff --git a/packages/babylon/test/fixtures/core/uncategorised/543/options.json b/packages/babylon/test/fixtures/core/uncategorised/.543/options.json similarity index 100% rename from packages/babylon/test/fixtures/core/uncategorised/543/options.json rename to packages/babylon/test/fixtures/core/uncategorised/.543/options.json diff --git a/packages/babylon/test/fixtures/core/uncategorised/544/actual.js b/packages/babylon/test/fixtures/core/uncategorised/.544/actual.js similarity index 100% rename from packages/babylon/test/fixtures/core/uncategorised/544/actual.js rename to packages/babylon/test/fixtures/core/uncategorised/.544/actual.js diff --git a/packages/babylon/test/fixtures/core/uncategorised/544/options.json b/packages/babylon/test/fixtures/core/uncategorised/.544/options.json similarity index 100% rename from packages/babylon/test/fixtures/core/uncategorised/544/options.json rename to packages/babylon/test/fixtures/core/uncategorised/.544/options.json diff --git a/packages/babylon/test/fixtures/core/uncategorised/22/expected.json b/packages/babylon/test/fixtures/core/uncategorised/22/expected.json index 0ea258d194..f0a884e6c3 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/22/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/22/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 16, "loc": { @@ -140,8 +140,7 @@ "raw": "42" }, "value": 42 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/core/uncategorised/23/expected.json b/packages/babylon/test/fixtures/core/uncategorised/23/expected.json index 6000da8339..dd3a42f49d 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/23/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/23/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 12, "loc": { @@ -140,8 +140,7 @@ "raw": "42" }, "value": 42 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/core/uncategorised/24/expected.json b/packages/babylon/test/fixtures/core/uncategorised/24/expected.json index a958d6780e..cbc5697de4 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/24/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/24/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 14, "loc": { @@ -140,8 +140,7 @@ "raw": "42" }, "value": 42 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/core/uncategorised/25/expected.json b/packages/babylon/test/fixtures/core/uncategorised/25/expected.json index d4911b1226..bff1f7f9e9 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/25/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/25/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 15, "loc": { @@ -140,8 +140,7 @@ "raw": "42" }, "value": 42 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/core/uncategorised/26/expected.json b/packages/babylon/test/fixtures/core/uncategorised/26/expected.json index 61e13ba2b5..ced9c6f1e5 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/26/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/26/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 14, "loc": { @@ -140,8 +140,7 @@ "raw": "42" }, "value": 42 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/core/uncategorised/27/expected.json b/packages/babylon/test/fixtures/core/uncategorised/27/expected.json index e7f3c00497..6cfa1d9324 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/27/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/27/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 18, "loc": { @@ -144,8 +144,7 @@ "raw": "42" }, "value": 42 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/core/uncategorised/275/expected.json b/packages/babylon/test/fixtures/core/uncategorised/275/expected.json index 0ddcce0c63..1586888a8b 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/275/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/275/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 8, "end": 24, "loc": { @@ -109,8 +109,7 @@ "raw": "\"Error\"" }, "value": "Error" - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/core/uncategorised/28/expected.json b/packages/babylon/test/fixtures/core/uncategorised/28/expected.json index d7de811e96..0f013c127d 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/28/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/28/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 10, "loc": { @@ -140,11 +140,10 @@ "raw": "1" }, "value": 1 - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 12, "end": 16, "loc": { @@ -195,8 +194,7 @@ "raw": "2" }, "value": 2 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/core/uncategorised/29/expected.json b/packages/babylon/test/fixtures/core/uncategorised/29/expected.json index 6cd7aee600..1462403c0d 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/29/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/29/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 36, "loc": { @@ -122,78 +122,65 @@ "name": "width" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 15, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, "end": 36, "loc": { "start": { "line": 1, - "column": 15 + "column": 18 }, "end": { "line": 1, "column": 36 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 18, - "end": 36, - "loc": { - "start": { - "line": 1, - "column": 18 + "body": [ + { + "type": "ReturnStatement", + "start": 20, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 34 + } }, - "end": { - "line": 1, - "column": 36 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 20, + "argument": { + "type": "Identifier", + "start": 27, "end": 34, "loc": { "start": { "line": 1, - "column": 20 + "column": 27 }, "end": { "line": 1, "column": 34 } }, - "argument": { - "type": "Identifier", - "start": 27, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 34 - } - }, - "name": "m_width" - } + "name": "m_width" } - ] - } + } + ], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/30/expected.json b/packages/babylon/test/fixtures/core/uncategorised/30/expected.json index bfcf233e05..7694f2fd33 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/30/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/30/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 20, "loc": { @@ -122,46 +122,33 @@ "name": "undef" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 15, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, "end": 20, "loc": { "start": { "line": 1, - "column": 15 + "column": 18 }, "end": { "line": 1, "column": 20 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/31/expected.json b/packages/babylon/test/fixtures/core/uncategorised/31/expected.json index a81f0be417..966b9f90ca 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/31/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/31/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 17, "loc": { @@ -122,46 +122,33 @@ "name": "if" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 12, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, "end": 17, "loc": { "start": { "line": 1, - "column": 12 + "column": 15 }, "end": { "line": 1, "column": 17 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 15, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/32/expected.json b/packages/babylon/test/fixtures/core/uncategorised/32/expected.json index 755ded80c2..0ab2082d42 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/32/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/32/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 19, "loc": { @@ -122,46 +122,33 @@ "name": "true" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 14, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, "end": 19, "loc": { "start": { "line": 1, - "column": 14 + "column": 17 }, "end": { "line": 1, "column": 19 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/33/expected.json b/packages/babylon/test/fixtures/core/uncategorised/33/expected.json index c8111bb6cc..ccc78d04a7 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/33/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/33/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 20, "loc": { @@ -122,46 +122,33 @@ "name": "false" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 15, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, "end": 20, "loc": { "start": { "line": 1, - "column": 15 + "column": 18 }, "end": { "line": 1, "column": 20 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/34/expected.json b/packages/babylon/test/fixtures/core/uncategorised/34/expected.json index dd04ddeac2..c8ef1380a8 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/34/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/34/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 19, "loc": { @@ -122,46 +122,33 @@ "name": "null" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 14, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, "end": 19, "loc": { "start": { "line": 1, - "column": 14 + "column": 17 }, "end": { "line": 1, "column": 19 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/35/expected.json b/packages/babylon/test/fixtures/core/uncategorised/35/expected.json index da3ec9be77..6a4504c896 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/35/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/35/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 22, "loc": { @@ -126,41 +126,26 @@ "value": "undef" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 17, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, "end": 22, "loc": { "start": { "line": 1, - "column": 17 + "column": 20 }, "end": { "line": 1, "column": 22 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/core/uncategorised/36/expected.json b/packages/babylon/test/fixtures/core/uncategorised/36/expected.json index a7cfe82d4d..7ff1fbb46b 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/36/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/36/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 17, "loc": { @@ -126,41 +126,26 @@ "value": 10 }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 12, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, "end": 17, "loc": { "start": { "line": 1, - "column": 12 + "column": 15 }, "end": { "line": 1, "column": 17 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 15, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/core/uncategorised/37/expected.json b/packages/babylon/test/fixtures/core/uncategorised/37/expected.json index 04f9698103..ad75991dc1 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/37/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/37/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 34, "loc": { @@ -122,58 +122,58 @@ "name": "width" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 15, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 19, "end": 34, "loc": { "start": { "line": 1, - "column": 15 + "column": 19 }, "end": { "line": 1, "column": 34 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 16, - "end": 17, + "type": "ExpressionStatement", + "start": 21, + "end": 32, "loc": { "start": { "line": 1, - "column": 16 + "column": 21 }, "end": { "line": 1, - "column": 17 + "column": 32 } }, - "name": "w" - } - ], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 34 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", "start": 21, "end": 32, "loc": { @@ -186,63 +186,50 @@ "column": 32 } }, - "expression": { - "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", "start": 21, - "end": 32, + "end": 28, "loc": { "start": { "line": 1, "column": 21 }, + "end": { + "line": 1, + "column": 28 + } + }, + "name": "m_width" + }, + "right": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, "end": { "line": 1, "column": 32 } }, - "operator": "=", - "left": { - "type": "Identifier", - "start": 21, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 28 - } - }, - "name": "m_width" - }, - "right": { - "type": "Identifier", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 32 - } - }, - "name": "w" - } + "name": "w" } } - ] - } + } + ], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/38/expected.json b/packages/babylon/test/fixtures/core/uncategorised/38/expected.json index 360b95f14c..e290b184de 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/38/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/38/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 28, "loc": { @@ -122,58 +122,58 @@ "name": "if" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 12, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 16, "end": 28, "loc": { "start": { "line": 1, - "column": 12 + "column": 16 }, "end": { "line": 1, "column": 28 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 13, - "end": 14, + "type": "ExpressionStatement", + "start": 18, + "end": 26, "loc": { "start": { "line": 1, - "column": 13 + "column": 18 }, "end": { "line": 1, - "column": 14 + "column": 26 } }, - "name": "w" - } - ], - "body": { - "type": "BlockStatement", - "start": 16, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 28 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", "start": 18, "end": 26, "loc": { @@ -186,63 +186,50 @@ "column": 26 } }, - "expression": { - "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", "start": 18, - "end": 26, + "end": 22, "loc": { "start": { "line": 1, "column": 18 }, + "end": { + "line": 1, + "column": 22 + } + }, + "name": "m_if" + }, + "right": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, "end": { "line": 1, "column": 26 } }, - "operator": "=", - "left": { - "type": "Identifier", - "start": 18, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "name": "m_if" - }, - "right": { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "name": "w" - } + "name": "w" } } - ] - } + } + ], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/39/expected.json b/packages/babylon/test/fixtures/core/uncategorised/39/expected.json index 3a2ec9b899..60ca06a14b 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/39/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/39/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 32, "loc": { @@ -122,58 +122,58 @@ "name": "true" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 14, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 18, "end": 32, "loc": { "start": { "line": 1, - "column": 14 + "column": 18 }, "end": { "line": 1, "column": 32 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 15, - "end": 16, + "type": "ExpressionStatement", + "start": 20, + "end": 30, "loc": { "start": { "line": 1, - "column": 15 + "column": 20 }, "end": { "line": 1, - "column": 16 + "column": 30 } }, - "name": "w" - } - ], - "body": { - "type": "BlockStatement", - "start": 18, - "end": 32, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 32 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", "start": 20, "end": 30, "loc": { @@ -186,63 +186,50 @@ "column": 30 } }, - "expression": { - "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", "start": 20, - "end": 30, + "end": 26, "loc": { "start": { "line": 1, "column": 20 }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": "m_true" + }, + "right": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, "end": { "line": 1, "column": 30 } }, - "operator": "=", - "left": { - "type": "Identifier", - "start": 20, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "name": "m_true" - }, - "right": { - "type": "Identifier", - "start": 29, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "name": "w" - } + "name": "w" } } - ] - } + } + ], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/40/expected.json b/packages/babylon/test/fixtures/core/uncategorised/40/expected.json index 198c6f8e8d..2e92b355f6 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/40/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/40/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 34, "loc": { @@ -122,58 +122,58 @@ "name": "false" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 15, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 19, "end": 34, "loc": { "start": { "line": 1, - "column": 15 + "column": 19 }, "end": { "line": 1, "column": 34 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 16, - "end": 17, + "type": "ExpressionStatement", + "start": 21, + "end": 32, "loc": { "start": { "line": 1, - "column": 16 + "column": 21 }, "end": { "line": 1, - "column": 17 + "column": 32 } }, - "name": "w" - } - ], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 34 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", "start": 21, "end": 32, "loc": { @@ -186,63 +186,50 @@ "column": 32 } }, - "expression": { - "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", "start": 21, - "end": 32, + "end": 28, "loc": { "start": { "line": 1, "column": 21 }, + "end": { + "line": 1, + "column": 28 + } + }, + "name": "m_false" + }, + "right": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, "end": { "line": 1, "column": 32 } }, - "operator": "=", - "left": { - "type": "Identifier", - "start": 21, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 28 - } - }, - "name": "m_false" - }, - "right": { - "type": "Identifier", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 32 - } - }, - "name": "w" - } + "name": "w" } } - ] - } + } + ], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/41/expected.json b/packages/babylon/test/fixtures/core/uncategorised/41/expected.json index 8624ffd5ef..af9300d188 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/41/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/41/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 32, "loc": { @@ -122,58 +122,58 @@ "name": "null" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 14, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 18, "end": 32, "loc": { "start": { "line": 1, - "column": 14 + "column": 18 }, "end": { "line": 1, "column": 32 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 15, - "end": 16, + "type": "ExpressionStatement", + "start": 20, + "end": 30, "loc": { "start": { "line": 1, - "column": 15 + "column": 20 }, "end": { "line": 1, - "column": 16 + "column": 30 } }, - "name": "w" - } - ], - "body": { - "type": "BlockStatement", - "start": 18, - "end": 32, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 32 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", "start": 20, "end": 30, "loc": { @@ -186,63 +186,50 @@ "column": 30 } }, - "expression": { - "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", "start": 20, - "end": 30, + "end": 26, "loc": { "start": { "line": 1, "column": 20 }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": "m_null" + }, + "right": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 29 + }, "end": { "line": 1, "column": 30 } }, - "operator": "=", - "left": { - "type": "Identifier", - "start": 20, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "name": "m_null" - }, - "right": { - "type": "Identifier", - "start": 29, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "name": "w" - } + "name": "w" } } - ] - } + } + ], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/42/expected.json b/packages/babylon/test/fixtures/core/uncategorised/42/expected.json index 359994f749..7bc3ec6059 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/42/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/42/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 34, "loc": { @@ -126,58 +126,58 @@ "value": "null" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 16, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 20, "end": 34, "loc": { "start": { "line": 1, - "column": 16 + "column": 20 }, "end": { "line": 1, "column": 34 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 17, - "end": 18, + "type": "ExpressionStatement", + "start": 22, + "end": 32, "loc": { "start": { "line": 1, - "column": 17 + "column": 22 }, "end": { "line": 1, - "column": 18 + "column": 32 } }, - "name": "w" - } - ], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 34 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", "start": 22, "end": 32, "loc": { @@ -190,58 +190,43 @@ "column": 32 } }, - "expression": { - "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", "start": 22, - "end": 32, + "end": 28, "loc": { "start": { "line": 1, "column": 22 }, + "end": { + "line": 1, + "column": 28 + } + }, + "name": "m_null" + }, + "right": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, "end": { "line": 1, "column": 32 } }, - "operator": "=", - "left": { - "type": "Identifier", - "start": 22, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 22 - }, - "end": { - "line": 1, - "column": 28 - } - }, - "name": "m_null" - }, - "right": { - "type": "Identifier", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 32 - } - }, - "name": "w" - } + "name": "w" } } - ], - "directives": [] - } + } + ], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/core/uncategorised/43/expected.json b/packages/babylon/test/fixtures/core/uncategorised/43/expected.json index 40439f6021..7a72b8763e 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/43/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/43/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 30, "loc": { @@ -126,58 +126,58 @@ "value": 10 }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 12, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "w" + } + ], + "body": { + "type": "BlockStatement", + "start": 16, "end": 30, "loc": { "start": { "line": 1, - "column": 12 + "column": 16 }, "end": { "line": 1, "column": 30 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 13, - "end": 14, + "type": "ExpressionStatement", + "start": 18, + "end": 28, "loc": { "start": { "line": 1, - "column": 13 + "column": 18 }, "end": { "line": 1, - "column": 14 + "column": 28 } }, - "name": "w" - } - ], - "body": { - "type": "BlockStatement", - "start": 16, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", "start": 18, "end": 28, "loc": { @@ -190,58 +190,43 @@ "column": 28 } }, - "expression": { - "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", "start": 18, - "end": 28, + "end": 24, "loc": { "start": { "line": 1, "column": 18 }, + "end": { + "line": 1, + "column": 24 + } + }, + "name": "m_null" + }, + "right": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 27 + }, "end": { "line": 1, "column": 28 } }, - "operator": "=", - "left": { - "type": "Identifier", - "start": 18, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "name": "m_null" - }, - "right": { - "type": "Identifier", - "start": 27, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 28 - } - }, - "name": "w" - } + "name": "w" } } - ], - "directives": [] - } + } + ], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/core/uncategorised/44/expected.json b/packages/babylon/test/fixtures/core/uncategorised/44/expected.json index 717aa6f7e7..b1dc510c8b 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/44/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/44/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 13, "loc": { @@ -140,8 +140,7 @@ "raw": "42" }, "value": 42 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/core/uncategorised/45/expected.json b/packages/babylon/test/fixtures/core/uncategorised/45/expected.json index 01d280ce5b..e7eb6404f5 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/45/expected.json +++ b/packages/babylon/test/fixtures/core/uncategorised/45/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 13, "loc": { @@ -140,8 +140,7 @@ "raw": "43" }, "value": 43 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/esprima/es2015-array-pattern/patterned-catch/expected.json b/packages/babylon/test/fixtures/esprima/es2015-array-pattern/patterned-catch/expected.json index 16876bb02e..a0efeec910 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-array-pattern/patterned-catch/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-array-pattern/patterned-catch/expected.json @@ -136,7 +136,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 21, "end": 22, "loc": { @@ -168,7 +168,6 @@ }, "name": "c" }, - "kind": "init", "value": { "type": "Identifier", "start": 21, @@ -187,7 +186,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 24, "end": 29, "loc": { @@ -269,11 +268,10 @@ }, "value": 0 } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 31, "end": 38, "loc": { @@ -355,11 +353,10 @@ }, "value": 0 } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 40, "end": 43, "loc": { @@ -391,7 +388,6 @@ }, "name": "h" }, - "kind": "init", "value": { "type": "AssignmentPattern", "start": 40, diff --git a/packages/babylon/test/fixtures/esprima/es2015-array-pattern/with-object-pattern/expected.json b/packages/babylon/test/fixtures/esprima/es2015-array-pattern/with-object-pattern/expected.json index 2d14e8848e..1c46501964 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-array-pattern/with-object-pattern/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-array-pattern/with-object-pattern/expected.json @@ -88,7 +88,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 7, "loc": { @@ -120,7 +120,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 6, diff --git a/packages/babylon/test/fixtures/esprima/es2015-arrow-function/migrated_0005/expected.json b/packages/babylon/test/fixtures/esprima/es2015-arrow-function/migrated_0005/expected.json index fbd87bd0c4..8025e7a342 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-arrow-function/migrated_0005/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-arrow-function/migrated_0005/expected.json @@ -93,7 +93,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 8, "end": 20, "loc": { @@ -144,8 +144,7 @@ "raw": "42" }, "value": 42 - }, - "kind": "init" + } } ], "extra": { diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0026/actual.js b/packages/babylon/test/fixtures/esprima/es2015-class/.migrated_0026/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-class/migrated_0026/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-class/.migrated_0026/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0026/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/.migrated_0026/expected.json similarity index 98% rename from packages/babylon/test/fixtures/esprima/es2015-class/migrated_0026/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-class/.migrated_0026/expected.json index 7354aa5050..c69f6a312a 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0026/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/.migrated_0026/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 18, "loc": { diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0004/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0004/expected.json index e60d7294c3..3e510efdc1 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0004/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0004/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 14, "loc": { @@ -107,45 +107,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 10, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 14, "loc": { "start": { "line": 1, - "column": 10 + "column": 12 }, "end": { "line": 1, "column": 14 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0005/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0005/expected.json index 4ead53f755..1ec03c3f48 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0005/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0005/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 14, "loc": { @@ -107,44 +107,30 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 10, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 14, "loc": { "start": { "line": 1, - "column": 10 + "column": 12 }, "end": { "line": 1, "column": 14 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 14, "end": 19, "loc": { @@ -176,45 +162,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 15, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, "end": 19, "loc": { "start": { "line": 1, - "column": 15 + "column": 17 }, "end": { "line": 1, "column": 19 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0006/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0006/expected.json index a4bb492dbb..c883c50114 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0006/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0006/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 14, "loc": { @@ -107,44 +107,30 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 10, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 14, "loc": { "start": { "line": 1, - "column": 10 + "column": 12 }, "end": { "line": 1, "column": 14 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 15, "end": 20, "loc": { @@ -176,45 +162,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 16, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, "end": 20, "loc": { "start": { "line": 1, - "column": 16 + "column": 18 }, "end": { "line": 1, "column": 20 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0007/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0007/expected.json index 77aa858ee4..57df44f925 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0007/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0007/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 14, "loc": { @@ -107,44 +107,30 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 10, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 14, "loc": { "start": { "line": 1, - "column": 10 + "column": 12 }, "end": { "line": 1, "column": 14 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 15, "end": 20, "loc": { @@ -176,45 +162,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 16, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, "end": 20, "loc": { "start": { "line": 1, - "column": 16 + "column": 18 }, "end": { "line": 1, "column": 20 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0008/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0008/expected.json index f0da7ec99b..129657a7fc 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0008/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0008/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 15, "loc": { @@ -107,44 +107,30 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 11, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 13, "end": 15, "loc": { "start": { "line": 1, - "column": 11 + "column": 13 }, "end": { "line": 1, "column": 15 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 13, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 16, "end": 21, "loc": { @@ -176,45 +162,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 17, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 19, "end": 21, "loc": { "start": { "line": 1, - "column": 17 + "column": 19 }, "end": { "line": 1, "column": 21 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 21 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0009/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0009/expected.json index 0cd6f1a23f..aa0a5f9344 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0009/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0009/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 19, "loc": { @@ -107,45 +107,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 15, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, "end": 19, "loc": { "start": { "line": 1, - "column": 15 + "column": 17 }, "end": { "line": 1, "column": 19 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0010/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0010/expected.json index b2101dd75c..92e8ef8e43 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0010/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0010/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 18, "loc": { @@ -107,44 +107,30 @@ }, "static": false, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 14, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 16, "end": 18, "loc": { "start": { "line": 1, - "column": 14 + "column": 16 }, "end": { "line": 1, "column": 18 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 16, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 19, "end": 29, "loc": { @@ -176,62 +162,49 @@ }, "static": false, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 24, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": "c" + } + ], + "body": { + "type": "BlockStatement", + "start": 27, "end": 29, "loc": { "start": { "line": 1, - "column": 24 + "column": 27 }, "end": { "line": 1, "column": 29 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "name": "c" - } - ], - "body": { - "type": "BlockStatement", - "start": 27, - "end": 29, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 29 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0011/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0011/expected.json index 1c0665ae72..c6498e9b27 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0011/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0011/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 21, "loc": { @@ -107,44 +107,30 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 17, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 19, "end": 21, "loc": { "start": { "line": 1, - "column": 17 + "column": 19 }, "end": { "line": 1, "column": 21 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 21 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 22, "end": 38, "loc": { @@ -176,44 +162,30 @@ }, "static": true, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 34, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 36, "end": 38, "loc": { "start": { "line": 1, - "column": 34 + "column": 36 }, "end": { "line": 1, "column": 38 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 36, - "end": 38, - "loc": { - "start": { - "line": 1, - "column": 36 - }, - "end": { - "line": 1, - "column": 38 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 39, "end": 56, "loc": { @@ -245,62 +217,49 @@ }, "static": true, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 51, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 52, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 52 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "name": "b" + } + ], + "body": { + "type": "BlockStatement", + "start": 54, "end": 56, "loc": { "start": { "line": 1, - "column": 51 + "column": 54 }, "end": { "line": 1, "column": 56 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 52, - "end": 53, - "loc": { - "start": { - "line": 1, - "column": 52 - }, - "end": { - "line": 1, - "column": 53 - } - }, - "name": "b" - } - ], - "body": { - "type": "BlockStatement", - "start": 54, - "end": 56, - "loc": { - "start": { - "line": 1, - "column": 54 - }, - "end": { - "line": 1, - "column": 56 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0012/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0012/expected.json index b1acc4da5f..fa54d94267 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0012/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0012/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 21, "loc": { @@ -107,45 +107,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 17, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 19, "end": 21, "loc": { "start": { "line": 1, - "column": 17 + "column": 19 }, "end": { "line": 1, "column": 21 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 21 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0013/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0013/expected.json index a366c8ad3f..c7ff2d5228 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0013/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0013/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 23, "loc": { @@ -107,45 +107,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 19, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, "end": 23, "loc": { "start": { "line": 1, - "column": 19 + "column": 21 }, "end": { "line": 1, "column": 23 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0014/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0014/expected.json index b9887ebdf9..3a78f1bd7d 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0014/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0014/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 22, "loc": { @@ -107,44 +107,30 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 18, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, "end": 22, "loc": { "start": { "line": 1, - "column": 18 + "column": 20 }, "end": { "line": 1, "column": 22 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 24, "end": 37, "loc": { @@ -176,45 +162,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 33, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 35, "end": 37, "loc": { "start": { "line": 1, - "column": 33 + "column": 35 }, "end": { "line": 1, "column": 37 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 35, - "end": 37, - "loc": { - "start": { - "line": 1, - "column": 35 - }, - "end": { - "line": 1, - "column": 37 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0015/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0015/expected.json index 7e151a458e..ade3ae124b 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0015/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0015/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 26, "loc": { @@ -107,45 +107,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 22, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, "end": 26, "loc": { "start": { "line": 1, - "column": 22 + "column": 24 }, "end": { "line": 1, "column": 26 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 24, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 24 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0017/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0017/expected.json index a887878c99..2a2d1f81f9 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0017/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0017/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 22, "loc": { @@ -107,45 +107,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 18, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, "end": 22, "loc": { "start": { "line": 1, - "column": 18 + "column": 20 }, "end": { "line": 1, "column": 22 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0018/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0018/expected.json index 4ce9a1e28c..8a0d50c2c6 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0018/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0018/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 24, "loc": { @@ -107,45 +107,32 @@ }, "static": false, "kind": "constructor", - "value": { - "type": "FunctionExpression", - "start": 20, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 22, "end": 24, "loc": { "start": { "line": 1, - "column": 20 + "column": 22 }, "end": { "line": 1, "column": 24 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 22, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 22 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0019/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0019/expected.json index d991009313..72bb521716 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0019/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0019/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 26, "loc": { @@ -111,45 +111,30 @@ }, "static": false, "kind": "constructor", - "value": { - "type": "FunctionExpression", - "start": 22, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, "end": 26, "loc": { "start": { "line": 1, - "column": 22 + "column": 24 }, "end": { "line": 1, "column": 26 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 24, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 24 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 27, "end": 46, "loc": { @@ -185,41 +170,26 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 42, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 44, "end": 46, "loc": { "start": { "line": 1, - "column": 42 + "column": 44 }, "end": { "line": 1, "column": 46 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 44, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 44 - }, - "end": { - "line": 1, - "column": 46 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0020/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0020/expected.json index 0241df155f..8ee060397d 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0020/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0020/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 31, "loc": { @@ -107,44 +107,30 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 27, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 29, "end": 31, "loc": { "start": { "line": 1, - "column": 27 + "column": 29 }, "end": { "line": 1, "column": 31 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 29, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 31 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 32, "end": 54, "loc": { @@ -176,45 +162,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 50, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 52, "end": 54, "loc": { "start": { "line": 1, - "column": 50 + "column": 52 }, "end": { "line": 1, "column": 54 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 52, - "end": 54, - "loc": { - "start": { - "line": 1, - "column": 52 - }, - "end": { - "line": 1, - "column": 54 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0021/expected.json b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0021/expected.json index 21d43a0b9f..05b3f0a4ac 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0021/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-class/migrated_0021/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 33, "loc": { @@ -111,41 +111,26 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 29, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 31, "end": 33, "loc": { "start": { "line": 1, - "column": 29 + "column": 31 }, "end": { "line": 1, "column": 33 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 31, - "end": 33, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 33 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/esprima/es2015-default-parameter-value/migrated_0002/expected.json b/packages/babylon/test/fixtures/esprima/es2015-default-parameter-value/migrated_0002/expected.json index 0fdbc8a52e..64c3b49fae 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-default-parameter-value/migrated_0002/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-default-parameter-value/migrated_0002/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 25, "loc": { @@ -208,8 +208,7 @@ "body": [], "directives": [] } - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-array-pattern/nested-cover-grammar/expected.json b/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-array-pattern/nested-cover-grammar/expected.json index 70b18e9e2e..9c12c4fa9c 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-array-pattern/nested-cover-grammar/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-array-pattern/nested-cover-grammar/expected.json @@ -88,7 +88,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 5, "loc": { @@ -120,7 +120,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "AssignmentPattern", "start": 2, diff --git a/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-object-pattern/nested-cover-grammar/expected.json b/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-object-pattern/nested-cover-grammar/expected.json index e4d7cfd018..559a8db8fc 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-object-pattern/nested-cover-grammar/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-object-pattern/nested-cover-grammar/expected.json @@ -373,7 +373,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 21, "end": 27, "loc": { @@ -405,7 +405,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "AssignmentPattern", "start": 21, diff --git a/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-object-pattern/object-pattern-assignment/expected.json b/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-object-pattern/object-pattern-assignment/expected.json index 4521c6e3bf..aab8a1a69e 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-object-pattern/object-pattern-assignment/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-destructuring-assignment-object-pattern/object-pattern-assignment/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 7, "end": 8, "loc": { @@ -105,7 +105,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 7, @@ -124,7 +123,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 14, "end": 17, "loc": { @@ -171,11 +170,10 @@ } }, "name": "a" - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 23, "end": 28, "loc": { @@ -253,11 +251,10 @@ }, "name": "a" } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 34, "end": 41, "loc": { @@ -305,7 +302,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 39, "end": 40, "loc": { @@ -337,7 +334,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 39, @@ -356,11 +352,10 @@ } } ] - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 47, "end": 63, "loc": { @@ -455,11 +450,10 @@ "name": "a" }, "computed": true - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 69, "end": 77, "loc": { @@ -537,8 +531,7 @@ "name": "a" }, "computed": false - }, - "kind": "init" + } } ] }, diff --git a/packages/babylon/test/fixtures/esprima/es2015-export-declaration/export-default-object/expected.json b/packages/babylon/test/fixtures/esprima/es2015-export-declaration/export-default-object/expected.json index 5d9a5f6369..ae7eefb6d2 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-export-declaration/export-default-object/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-export-declaration/export-default-object/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 17, "end": 23, "loc": { @@ -109,8 +109,7 @@ "raw": "1" }, "value": 1 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/esprima/es2015-for-of/for-of-object-pattern-const/expected.json b/packages/babylon/test/fixtures/esprima/es2015-for-of/for-of-object-pattern-const/expected.json index 2fcb51b5b1..bf3b9e73b7 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-for-of/for-of-object-pattern-const/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-for-of/for-of-object-pattern-const/expected.json @@ -87,7 +87,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 12, "end": 13, "loc": { @@ -119,7 +119,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 12, @@ -138,7 +137,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 15, "end": 16, "loc": { @@ -170,7 +169,6 @@ }, "name": "y" }, - "kind": "init", "value": { "type": "Identifier", "start": 15, @@ -227,6 +225,7 @@ } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-for-of/for-of-object-pattern/expected.json b/packages/babylon/test/fixtures/esprima/es2015-for-of/for-of-object-pattern/expected.json index 9cfd59a3ab..025d0acd2b 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-for-of/for-of-object-pattern/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-for-of/for-of-object-pattern/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 7, "loc": { @@ -90,7 +90,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 6, @@ -109,7 +108,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 9, "end": 10, "loc": { @@ -141,7 +140,6 @@ }, "name": "y" }, - "kind": "init", "value": { "type": "Identifier", "start": 9, @@ -193,6 +191,7 @@ } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-parameter-binding-property-reserved/actual.js b/packages/babylon/test/fixtures/esprima/es2015-generator/.generator-parameter-binding-property-reserved/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-generator/generator-parameter-binding-property-reserved/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-generator/.generator-parameter-binding-property-reserved/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-parameter-binding-property-reserved/expected.json b/packages/babylon/test/fixtures/esprima/es2015-generator/.generator-parameter-binding-property-reserved/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-generator/generator-parameter-binding-property-reserved/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-generator/.generator-parameter-binding-property-reserved/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-parameter-binding-property-reserved/options.json b/packages/babylon/test/fixtures/esprima/es2015-generator/.generator-parameter-binding-property-reserved/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-generator/generator-parameter-binding-property-reserved/options.json rename to packages/babylon/test/fixtures/esprima/es2015-generator/.generator-parameter-binding-property-reserved/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-params/expected.json b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-params/expected.json index 7c3e3bcb37..ef567c630d 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-params/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-params/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 19, "loc": { @@ -90,91 +90,76 @@ }, "name": "foo" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 7, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "name": "x" + }, + { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "y" + }, + { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": "z" + } + ], + "body": { + "type": "BlockStatement", + "start": 17, "end": 19, "loc": { "start": { "line": 1, - "column": 7 + "column": 17 }, "end": { "line": 1, "column": 19 } }, - "id": null, - "generator": true, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 8, - "end": 9, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 1, - "column": 9 - } - }, - "name": "x" - }, - { - "type": "Identifier", - "start": 11, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "name": "y" - }, - { - "type": "Identifier", - "start": 14, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 14 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "name": "z" - } - ], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-delegate/expected.json b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-delegate/expected.json index 8b5ee65941..a261ce50a1 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-delegate/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-delegate/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 23, "loc": { @@ -90,44 +90,44 @@ }, "name": "foo" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 7, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 10, "end": 23, "loc": { "start": { "line": 1, - "column": 7 + "column": 10 }, "end": { "line": 1, "column": 23 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 10, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 10 + "body": [ + { + "type": "ExpressionStatement", + "start": 12, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 21 + } }, - "end": { - "line": 1, - "column": 23 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "YieldExpression", "start": 12, - "end": 21, + "end": 20, "loc": { "start": { "line": 1, @@ -135,49 +135,34 @@ }, "end": { "line": 1, - "column": 21 + "column": 20 } }, - "expression": { - "type": "YieldExpression", - "start": 12, + "delegate": true, + "argument": { + "type": "NumberLiteral", + "start": 19, "end": 20, "loc": { "start": { "line": 1, - "column": 12 + "column": 19 }, "end": { "line": 1, "column": 20 } }, - "delegate": true, - "argument": { - "type": "NumberLiteral", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 - } + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 } } - ], - "directives": [] - } + } + ], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-expression/expected.json b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-expression/expected.json index 14d2a18a84..d43ba66132 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-expression/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-expression/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 22, "loc": { @@ -90,44 +90,44 @@ }, "name": "foo" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 7, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 10, "end": 22, "loc": { "start": { "line": 1, - "column": 7 + "column": 10 }, "end": { "line": 1, "column": 22 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 10, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 10 + "body": [ + { + "type": "ExpressionStatement", + "start": 12, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 20 + } }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "YieldExpression", "start": 12, - "end": 20, + "end": 19, "loc": { "start": { "line": 1, @@ -135,49 +135,34 @@ }, "end": { "line": 1, - "column": 20 + "column": 19 } }, - "expression": { - "type": "YieldExpression", - "start": 12, + "delegate": false, + "argument": { + "type": "NumberLiteral", + "start": 18, "end": 19, "loc": { "start": { "line": 1, - "column": 12 + "column": 18 }, "end": { "line": 1, "column": 19 } }, - "delegate": false, - "argument": { - "type": "NumberLiteral", - "start": 18, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 - } + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 } } - ], - "directives": [] - } + } + ], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-line-terminator/expected.json b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-line-terminator/expected.json index 110cc9c9cb..addacb6d05 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-line-terminator/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield-line-terminator/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 26, "loc": { @@ -90,42 +90,42 @@ }, "name": "foo" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 7, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 10, "end": 26, "loc": { "start": { "line": 1, - "column": 7 + "column": 10 }, "end": { "line": 4, "column": 1 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 10, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 10 + "body": [ + { + "type": "ExpressionStatement", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "YieldExpression", "start": 15, "end": 20, "loc": { @@ -138,26 +138,26 @@ "column": 7 } }, - "expression": { - "type": "YieldExpression", - "start": 15, - "end": 20, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 7 - } - }, - "delegate": false, - "argument": null + "delegate": false, + "argument": null + } + }, + { + "type": "ExpressionStatement", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 } }, - { - "type": "ExpressionStatement", + "expression": { + "type": "NumberLiteral", "start": 23, "end": 24, "loc": { @@ -170,30 +170,15 @@ "column": 3 } }, - "expression": { - "type": "NumberLiteral", - "start": 23, - "end": 24, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 3 - } - }, - "extra": { - "rawValue": 3, - "raw": "3" - }, - "value": 3 - } + "extra": { + "rawValue": 3, + "raw": "3" + }, + "value": 3 } - ], - "directives": [] - } + } + ], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield/expected.json b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield/expected.json index c749a9dbaf..9bd0e0fc9b 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method-with-yield/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 20, "loc": { @@ -90,44 +90,44 @@ }, "name": "foo" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 7, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 10, "end": 20, "loc": { "start": { "line": 1, - "column": 7 + "column": 10 }, "end": { "line": 1, "column": 20 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 10, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 10 + "body": [ + { + "type": "ExpressionStatement", + "start": 12, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + } }, - "end": { - "line": 1, - "column": 20 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "YieldExpression", "start": 12, - "end": 18, + "end": 17, "loc": { "start": { "line": 1, @@ -135,30 +135,15 @@ }, "end": { "line": 1, - "column": 18 + "column": 17 } }, - "expression": { - "type": "YieldExpression", - "start": 12, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "delegate": false, - "argument": null - } + "delegate": false, + "argument": null } - ], - "directives": [] - } + } + ], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method/expected.json b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method/expected.json index a5bb9c44cb..1edf3cf6b7 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-generator/generator-method/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 12, "loc": { @@ -90,42 +90,27 @@ }, "name": "foo" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 7, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 10, "end": 12, "loc": { "start": { "line": 1, - "column": 7 + "column": 10 }, "end": { "line": 1, "column": 12 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 10, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/static-generator-method-with-computed-name/expected.json b/packages/babylon/test/fixtures/esprima/es2015-generator/static-generator-method-with-computed-name/expected.json index d257165465..39c163121b 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-generator/static-generator-method-with-computed-name/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-generator/static-generator-method-with-computed-name/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 12, "end": 30, "loc": { @@ -107,45 +107,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 25, + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, "end": 30, "loc": { "start": { "line": 1, - "column": 25 + "column": 28 }, "end": { "line": 1, "column": 30 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 28, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 28 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-generator/static-generator-method/expected.json b/packages/babylon/test/fixtures/esprima/es2015-generator/static-generator-method/expected.json index bebbec9f26..655985c272 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-generator/static-generator-method/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-generator/static-generator-method/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 12, "end": 28, "loc": { @@ -107,45 +107,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 23, + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 26, "end": 28, "loc": { "start": { "line": 1, - "column": 23 + "column": 26 }, "end": { "line": 1, "column": 28 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 26, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 26 - }, - "end": { - "line": 1, - "column": 28 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_function_wait/actual.js b/packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_function_wait/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_function_wait/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_function_wait/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_function_wait/expected.json b/packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_function_wait/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_function_wait/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_function_wait/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_function_wait/options.json b/packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_function_wait/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_function_wait/options.json rename to packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_function_wait/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_lone_surrogate/actual.js b/packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_lone_surrogate/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_lone_surrogate/expected.json b/packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_lone_surrogate/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_lone_surrogate/options.json b/packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-identifier/invalid_lone_surrogate/options.json rename to packages/babylon/test/fixtures/esprima/es2015-identifier/.invalid_lone_surrogate/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-meta-property/invalid-new-target/actual.js b/packages/babylon/test/fixtures/esprima/es2015-meta-property/.invalid-new-target/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-meta-property/invalid-new-target/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-meta-property/.invalid-new-target/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-meta-property/invalid-new-target/expected.json b/packages/babylon/test/fixtures/esprima/es2015-meta-property/.invalid-new-target/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-meta-property/invalid-new-target/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-meta-property/.invalid-new-target/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-meta-property/invalid-new-target/options.json b/packages/babylon/test/fixtures/esprima/es2015-meta-property/.invalid-new-target/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-meta-property/invalid-new-target/options.json rename to packages/babylon/test/fixtures/esprima/es2015-meta-property/.invalid-new-target/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0000/expected.json b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0000/expected.json index 5d4235ff90..880dce74c2 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0000/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0000/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 18, "loc": { @@ -121,47 +121,34 @@ }, "name": "method" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 12, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, "end": 18, "loc": { "start": { "line": 1, - "column": 12 + "column": 15 }, "end": { "line": 1, "column": 18 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0001/expected.json b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0001/expected.json index 9e72a8c644..7d5dce4954 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0001/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0001/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 22, "loc": { @@ -121,64 +121,51 @@ }, "name": "method" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 12, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": "test" + } + ], + "body": { + "type": "BlockStatement", + "start": 19, "end": 22, "loc": { "start": { "line": 1, - "column": 12 + "column": 19 }, "end": { "line": 1, "column": 22 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 13, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "name": "test" - } - ], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0002/expected.json b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0002/expected.json index e964b38846..1030bf0af2 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0002/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0002/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 20, "loc": { @@ -125,42 +125,27 @@ }, "value": "method" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 14, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, "end": 20, "loc": { "start": { "line": 1, - "column": 14 + "column": 17 }, "end": { "line": 1, "column": 20 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0003/expected.json b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0003/expected.json index 986432a828..0b0d3f1c10 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0003/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0003/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 15, "loc": { @@ -121,47 +121,34 @@ }, "name": "get" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 9, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 15, "loc": { "start": { "line": 1, - "column": 9 + "column": 12 }, "end": { "line": 1, "column": 15 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0004/expected.json b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0004/expected.json index 8d18a3447c..b118b76443 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0004/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-method-definition/migrated_0004/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 15, "loc": { @@ -121,47 +121,34 @@ }, "name": "set" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 9, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 15, "loc": { "start": { "line": 1, - "column": 9 + "column": 12 }, "end": { "line": 1, "column": 15 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-getter-literal-identifier/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-getter-literal-identifier/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-getter-literal-identifier/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-getter-literal-identifier/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-getter-literal-identifier/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-getter-literal-identifier/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-getter-literal-identifier/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-getter-literal-identifier/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-getter-literal-identifier/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-getter-literal-identifier/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-getter-literal-identifier/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-getter-literal-identifier/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-literal/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-literal/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-literal/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-literal/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-literal/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-literal/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-literal/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-literal/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-literal/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-literal/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-literal/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-literal/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-shorthand/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-shorthand/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-shorthand/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-shorthand/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-shorthand/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifier-shorthand/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifier-shorthand/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifiers/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifiers/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifiers/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifiers/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifiers/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifiers/expected.json new file mode 100644 index 0000000000..853ec2ca42 --- /dev/null +++ b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifiers/expected.json @@ -0,0 +1,167 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "__proto__" + }, + "value": { + "type": "NullLiteral", + "start": 14, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + } + } + }, + { + "type": "ObjectProperty", + "start": 20, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 20, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "name": "__proto__" + }, + "value": { + "type": "NullLiteral", + "start": 31, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 35 + } + } + } + } + ], + "extra": { + "parenthesized": true + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifiers/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifiers/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-identifiers/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-identifiers/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-identifier/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-identifier/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-identifier/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-identifier/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-identifier/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-identifier/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-identifier/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-identifier/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-identifier/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-identifier/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-identifier/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-identifier/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-shorthand/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-shorthand/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-shorthand/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-shorthand/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-shorthand/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literal-shorthand/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literal-shorthand/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literals/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literals/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literals/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literals/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literals/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literals/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literals/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literals/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literals/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literals/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-literals/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-literals/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-setter-literal-identifier/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-setter-literal-identifier/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-setter-literal-identifier/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-setter-literal-identifier/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-setter-literal-identifier/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-setter-literal-identifier/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-setter-literal-identifier/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-setter-literal-identifier/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-setter-literal-identifier/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-setter-literal-identifier/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-setter-literal-identifier/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-setter-literal-identifier/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-identifier/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-identifier/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-identifier/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-identifier/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-identifier/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-identifier/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-identifier/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-literal/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-literal/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-literal/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-literal/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-literal/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthand-literal/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthand-literal/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/actual.js b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthands/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthands/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthands/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthands/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/options.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthands/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-object-initialiser/invalid-proto-shorthands/options.json rename to packages/babylon/test/fixtures/esprima/es2015-object-initialiser/.invalid-proto-shorthands/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-getter-setter/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-getter-setter/expected.json index 370894461a..41fa69789a 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-getter-setter/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-getter-setter/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 18, "loc": { @@ -104,11 +104,10 @@ "column": 18 } } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectMethod", "start": 20, "end": 37, "loc": { @@ -141,45 +140,30 @@ "name": "__proto__" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 33, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 35, "end": 37, "loc": { "start": { "line": 1, - "column": 33 + "column": 35 }, "end": { "line": 1, "column": 37 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 35, - "end": 37, - "loc": { - "start": { - "line": 1, - "column": 35 - }, - "end": { - "line": 1, - "column": 37 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } }, { - "type": "Property", + "type": "ObjectMethod", "start": 39, "end": 57, "loc": { @@ -212,58 +196,43 @@ "name": "__proto__" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 52, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 53 + }, + "end": { + "line": 1, + "column": 54 + } + }, + "name": "x" + } + ], + "body": { + "type": "BlockStatement", + "start": 55, "end": 57, "loc": { "start": { "line": 1, - "column": 52 + "column": 55 }, "end": { "line": 1, "column": 57 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 53, - "end": 54, - "loc": { - "start": { - "line": 1, - "column": 53 - }, - "end": { - "line": 1, - "column": 54 - } - }, - "name": "x" - } - ], - "body": { - "type": "BlockStatement", - "start": 55, - "end": 57, - "loc": { - "start": { - "line": 1, - "column": 55 - }, - "end": { - "line": 1, - "column": 57 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-getter/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-getter/expected.json index 987143a14c..73ee6c7acf 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-getter/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-getter/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 18, "loc": { @@ -104,11 +104,10 @@ "column": 18 } } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectMethod", "start": 20, "end": 37, "loc": { @@ -141,41 +140,26 @@ "name": "__proto__" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 33, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 35, "end": 37, "loc": { "start": { "line": 1, - "column": 33 + "column": 35 }, "end": { "line": 1, "column": 37 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 35, - "end": 37, - "loc": { - "start": { - "line": 1, - "column": 35 - }, - "end": { - "line": 1, - "column": 37 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-method/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-method/expected.json index 63dc917941..8213ba1bb4 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-method/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-method/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 18, "loc": { @@ -104,11 +104,10 @@ "column": 18 } } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectMethod", "start": 20, "end": 33, "loc": { @@ -140,42 +139,27 @@ }, "name": "__proto__" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 29, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 31, "end": 33, "loc": { "start": { "line": 1, - "column": 29 + "column": 31 }, "end": { "line": 1, "column": 33 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 31, - "end": 33, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 33 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-setter/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-setter/expected.json index 70085edf6a..3e06b6b52c 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-setter/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-identifier-setter/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 18, "loc": { @@ -104,11 +104,10 @@ "column": 18 } } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectMethod", "start": 20, "end": 38, "loc": { @@ -141,58 +140,43 @@ "name": "__proto__" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 33, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "name": "x" + } + ], + "body": { + "type": "BlockStatement", + "start": 36, "end": 38, "loc": { "start": { "line": 1, - "column": 33 + "column": 36 }, "end": { "line": 1, "column": 38 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 34, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 34 - }, - "end": { - "line": 1, - "column": 35 - } - }, - "name": "x" - } - ], - "body": { - "type": "BlockStatement", - "start": 36, - "end": 38, - "loc": { - "start": { - "line": 1, - "column": 36 - }, - "end": { - "line": 1, - "column": 38 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-getter-setter/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-getter-setter/expected.json index 48f265cc99..a1524c4a1f 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-getter-setter/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-getter-setter/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 20, "loc": { @@ -108,11 +108,10 @@ "column": 20 } } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectMethod", "start": 22, "end": 39, "loc": { @@ -145,45 +144,30 @@ "name": "__proto__" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 35, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 37, "end": 39, "loc": { "start": { "line": 1, - "column": 35 + "column": 37 }, "end": { "line": 1, "column": 39 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 37, - "end": 39, - "loc": { - "start": { - "line": 1, - "column": 37 - }, - "end": { - "line": 1, - "column": 39 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } }, { - "type": "Property", + "type": "ObjectMethod", "start": 41, "end": 59, "loc": { @@ -216,58 +200,43 @@ "name": "__proto__" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 54, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 55 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "name": "x" + } + ], + "body": { + "type": "BlockStatement", + "start": 57, "end": 59, "loc": { "start": { "line": 1, - "column": 54 + "column": 57 }, "end": { "line": 1, "column": 59 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 55, - "end": 56, - "loc": { - "start": { - "line": 1, - "column": 55 - }, - "end": { - "line": 1, - "column": 56 - } - }, - "name": "x" - } - ], - "body": { - "type": "BlockStatement", - "start": 57, - "end": 59, - "loc": { - "start": { - "line": 1, - "column": 57 - }, - "end": { - "line": 1, - "column": 59 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-getter/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-getter/expected.json index c6bdefacea..5fe032f20e 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-getter/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-getter/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 20, "loc": { @@ -108,11 +108,10 @@ "column": 20 } } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectMethod", "start": 22, "end": 39, "loc": { @@ -145,41 +144,26 @@ "name": "__proto__" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 35, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 37, "end": 39, "loc": { "start": { "line": 1, - "column": 35 + "column": 37 }, "end": { "line": 1, "column": 39 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 37, - "end": 39, - "loc": { - "start": { - "line": 1, - "column": 37 - }, - "end": { - "line": 1, - "column": 39 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-method/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-method/expected.json index f414d0c2e1..2a6d87e4c9 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-method/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-method/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 20, "loc": { @@ -108,11 +108,10 @@ "column": 20 } } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectMethod", "start": 22, "end": 35, "loc": { @@ -144,42 +143,27 @@ }, "name": "__proto__" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 31, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 33, "end": 35, "loc": { "start": { "line": 1, - "column": 31 + "column": 33 }, "end": { "line": 1, "column": 35 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 33, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 33 - }, - "end": { - "line": 1, - "column": 35 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-setter/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-setter/expected.json index 501fa19f68..d0c7453baa 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-setter/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-initialiser/proto-literal-setter/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 20, "loc": { @@ -108,11 +108,10 @@ "column": 20 } } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectMethod", "start": 22, "end": 40, "loc": { @@ -145,58 +144,43 @@ "name": "__proto__" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 35, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "name": "x" + } + ], + "body": { + "type": "BlockStatement", + "start": 38, "end": 40, "loc": { "start": { "line": 1, - "column": 35 + "column": 38 }, "end": { "line": 1, "column": 40 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 36, - "end": 37, - "loc": { - "start": { - "line": 1, - "column": 36 - }, - "end": { - "line": 1, - "column": 37 - } - }, - "name": "x" - } - ], - "body": { - "type": "BlockStatement", - "start": 38, - "end": 40, - "loc": { - "start": { - "line": 1, - "column": 38 - }, - "end": { - "line": 1, - "column": 40 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-literal-property-value-shorthand/migrated_0000/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-literal-property-value-shorthand/migrated_0000/expected.json index 83f868da39..660265dd75 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-literal-property-value-shorthand/migrated_0000/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-literal-property-value-shorthand/migrated_0000/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 7, "loc": { @@ -121,7 +121,6 @@ }, "name": "y" }, - "kind": "init", "value": { "type": "Identifier", "start": 6, @@ -140,7 +139,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 9, "end": 10, "loc": { @@ -172,7 +171,6 @@ }, "name": "z" }, - "kind": "init", "value": { "type": "Identifier", "start": 9, @@ -194,6 +192,7 @@ } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-pattern/elision/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-pattern/elision/expected.json index 6b892f7870..7c4ad06015 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-pattern/elision/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-pattern/elision/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 6, "loc": { @@ -105,7 +105,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-pattern/nested/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-pattern/nested/expected.json index 2b2774d691..91ef151596 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-pattern/nested/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-pattern/nested/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 9, "loc": { @@ -120,8 +120,7 @@ } }, "properties": [] - }, - "kind": "init" + } } ] }, diff --git a/packages/babylon/test/fixtures/esprima/es2015-object-pattern/properties/expected.json b/packages/babylon/test/fixtures/esprima/es2015-object-pattern/properties/expected.json index a7861a314f..385e1d7b27 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-object-pattern/properties/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-object-pattern/properties/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 6, "loc": { @@ -105,7 +105,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, @@ -124,7 +123,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 7, "end": 10, "loc": { @@ -156,7 +155,6 @@ }, "name": "b" }, - "kind": "init", "value": { "type": "AssignmentPattern", "start": 7, @@ -210,7 +208,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 11, "end": 14, "loc": { @@ -257,11 +255,10 @@ } }, "name": "d" - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 15, "end": 20, "loc": { @@ -343,11 +340,10 @@ }, "value": 0 } - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 21, "end": 28, "loc": { @@ -411,8 +407,7 @@ "name": "h" } ] - }, - "kind": "init" + } } ] }, diff --git a/packages/babylon/test/fixtures/esprima/es2015-rest-parameter/object-method/expected.json b/packages/babylon/test/fixtures/esprima/es2015-rest-parameter/object-method/expected.json index e7736168c6..b5c022b8a6 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-rest-parameter/object-method/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-rest-parameter/object-method/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 29, "loc": { @@ -201,15 +201,16 @@ "column": 29 } }, - "body": [] + "body": [], + "directives": [] } - }, - "kind": "init" + } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-rest-parameter/object-shorthand-method/expected.json b/packages/babylon/test/fixtures/esprima/es2015-rest-parameter/object-shorthand-method/expected.json index aee5d3439b..18295991cb 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-rest-parameter/object-shorthand-method/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-rest-parameter/object-shorthand-method/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 25, "loc": { @@ -121,79 +121,66 @@ }, "name": "method" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 12, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 12 + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "RestElement", + "start": 13, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 20 + } }, - "end": { - "line": 1, - "column": 25 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "RestElement", - "start": 13, + "argument": { + "type": "Identifier", + "start": 16, "end": 20, "loc": { "start": { "line": 1, - "column": 13 + "column": 16 }, "end": { "line": 1, "column": 20 } }, - "argument": { - "type": "Identifier", - "start": 16, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "name": "test" - } + "name": "test" } - ], - "body": { - "type": "BlockStatement", - "start": 22, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 22 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "body": [] } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "body": [], + "directives": [] } } ] } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_access/actual.js b/packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_access/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_access/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_access/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_access/options.json b/packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_access/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_access/options.json rename to packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_access/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_id/actual.js b/packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_id/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_id/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_id/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_id/expected.json b/packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_id/expected.json similarity index 99% rename from packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_id/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_id/expected.json index 9f101bba08..051ec3a5b8 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_id/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_id/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 14, "end": 37, "loc": { diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_id/options.json b/packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_id/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_id/options.json rename to packages/babylon/test/fixtures/esprima/es2015-super-property/.invalid_super_id/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/arrow_super/expected.json b/packages/babylon/test/fixtures/esprima/es2015-super-property/arrow_super/expected.json index b94e426219..76dcbec057 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-super-property/arrow_super/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-super-property/arrow_super/expected.json @@ -90,7 +90,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 24, "end": 67, "loc": { @@ -122,41 +122,41 @@ }, "static": false, "kind": "constructor", - "value": { - "type": "FunctionExpression", - "start": 35, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 38, "end": 67, "loc": { "start": { "line": 2, - "column": 15 + "column": 18 }, "end": { "line": 4, "column": 5 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 38, - "end": 67, - "loc": { - "start": { - "line": 2, - "column": 18 + "body": [ + { + "type": "ExpressionStatement", + "start": 48, + "end": 61, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 21 + } }, - "end": { - "line": 4, - "column": 5 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "ArrowFunctionExpression", "start": 48, "end": 61, "loc": { @@ -169,28 +169,28 @@ "column": 21 } }, - "expression": { - "type": "ArrowFunctionExpression", - "start": 48, + "id": null, + "generator": false, + "expression": true, + "params": [], + "body": { + "type": "CallExpression", + "start": 54, "end": 61, "loc": { "start": { "line": 3, - "column": 8 + "column": 14 }, "end": { "line": 3, "column": 21 } }, - "id": null, - "generator": false, - "expression": true, - "params": [], - "body": { - "type": "CallExpression", + "callee": { + "type": "Super", "start": 54, - "end": 61, + "end": 59, "loc": { "start": { "line": 3, @@ -198,35 +198,22 @@ }, "end": { "line": 3, - "column": 21 + "column": 19 } - }, - "callee": { - "type": "Super", - "start": 54, - "end": 59, - "loc": { - "start": { - "line": 3, - "column": 14 - }, - "end": { - "line": 3, - "column": 19 - } - } - }, - "arguments": [] - } + } + }, + "arguments": [] } } - ] - } + } + ], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/constructor_super/expected.json b/packages/babylon/test/fixtures/esprima/es2015-super-property/constructor_super/expected.json index dd99c7bb8e..aad408ba61 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-super-property/constructor_super/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-super-property/constructor_super/expected.json @@ -90,7 +90,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 24, "end": 62, "loc": { @@ -122,43 +122,43 @@ }, "static": false, "kind": "constructor", - "value": { - "type": "FunctionExpression", - "start": 35, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 38, "end": 62, "loc": { "start": { "line": 2, - "column": 15 + "column": 18 }, "end": { "line": 4, "column": 5 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 38, - "end": 62, - "loc": { - "start": { - "line": 2, - "column": 18 + "body": [ + { + "type": "ExpressionStatement", + "start": 48, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 16 + } }, - "end": { - "line": 4, - "column": 5 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", "start": 48, - "end": 56, + "end": 55, "loc": { "start": { "line": 3, @@ -166,13 +166,13 @@ }, "end": { "line": 3, - "column": 16 + "column": 15 } }, - "expression": { - "type": "CallExpression", + "callee": { + "type": "Super", "start": 48, - "end": 55, + "end": 53, "loc": { "start": { "line": 3, @@ -180,34 +180,21 @@ }, "end": { "line": 3, - "column": 15 + "column": 13 } - }, - "callee": { - "type": "Super", - "start": 48, - "end": 53, - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 13 - } - } - }, - "arguments": [] - } + } + }, + "arguments": [] } - ] - } + } + ], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/new_super/expected.json b/packages/babylon/test/fixtures/esprima/es2015-super-property/new_super/expected.json index d86a834f70..4bf3b459c2 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-super-property/new_super/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-super-property/new_super/expected.json @@ -90,7 +90,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 24, "end": 61, "loc": { @@ -122,41 +122,41 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 27, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 30, "end": 61, "loc": { "start": { "line": 2, - "column": 7 + "column": 10 }, "end": { "line": 4, "column": 5 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 30, - "end": 61, - "loc": { - "start": { - "line": 2, - "column": 10 + "body": [ + { + "type": "ExpressionStatement", + "start": 40, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 23 + } }, - "end": { - "line": 4, - "column": 5 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "NewExpression", "start": 40, "end": 55, "loc": { @@ -169,77 +169,64 @@ "column": 23 } }, - "expression": { - "type": "NewExpression", - "start": 40, - "end": 55, + "callee": { + "type": "MemberExpression", + "start": 44, + "end": 53, "loc": { "start": { "line": 3, - "column": 8 + "column": 12 }, "end": { "line": 3, - "column": 23 + "column": 21 } }, - "callee": { - "type": "MemberExpression", + "object": { + "type": "Super", "start": 44, - "end": 53, + "end": 49, "loc": { "start": { "line": 3, "column": 12 }, + "end": { + "line": 3, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "start": 50, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 18 + }, "end": { "line": 3, "column": 21 } }, - "object": { - "type": "Super", - "start": 44, - "end": 49, - "loc": { - "start": { - "line": 3, - "column": 12 - }, - "end": { - "line": 3, - "column": 17 - } - } - }, - "property": { - "type": "Identifier", - "start": 50, - "end": 53, - "loc": { - "start": { - "line": 3, - "column": 18 - }, - "end": { - "line": 3, - "column": 21 - } - }, - "name": "bar" - }, - "computed": false + "name": "bar" }, - "arguments": [] - } + "computed": false + }, + "arguments": [] } - ] - } + } + ], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/super_computed/expected.json b/packages/babylon/test/fixtures/esprima/es2015-super-property/super_computed/expected.json index fc8eabf3ce..0187540a76 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-super-property/super_computed/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-super-property/super_computed/expected.json @@ -90,7 +90,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 24, "end": 59, "loc": { @@ -122,57 +122,57 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 25, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, "end": 59, "loc": { "start": { "line": 2, - "column": 5 + "column": 8 }, "end": { "line": 4, "column": 5 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 28, - "end": 59, - "loc": { - "start": { - "line": 2, - "column": 8 + "body": [ + { + "type": "ReturnStatement", + "start": 38, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 23 + } }, - "end": { - "line": 4, - "column": 5 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 38, + "argument": { + "type": "MemberExpression", + "start": 45, "end": 53, "loc": { "start": { "line": 3, - "column": 8 + "column": 15 }, "end": { "line": 3, "column": 23 } }, - "argument": { - "type": "MemberExpression", + "object": { + "type": "Super", "start": 45, - "end": 53, + "end": 50, "loc": { "start": { "line": 3, @@ -180,50 +180,35 @@ }, "end": { "line": 3, - "column": 23 + "column": 20 + } + } + }, + "property": { + "type": "NumberLiteral", + "start": 51, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 } }, - "object": { - "type": "Super", - "start": 45, - "end": 50, - "loc": { - "start": { - "line": 3, - "column": 15 - }, - "end": { - "line": 3, - "column": 20 - } - } + "extra": { + "rawValue": 1, + "raw": "1" }, - "property": { - "type": "NumberLiteral", - "start": 51, - "end": 52, - "loc": { - "start": { - "line": 3, - "column": 21 - }, - "end": { - "line": 3, - "column": 22 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, - "computed": true - } + "value": 1 + }, + "computed": true } - ], - "directives": [] - } + } + ], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/super_member/expected.json b/packages/babylon/test/fixtures/esprima/es2015-super-property/super_member/expected.json index ad4ef9c6c4..9b939e582b 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-super-property/super_member/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-super-property/super_member/expected.json @@ -90,7 +90,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 24, "end": 58, "loc": { @@ -122,108 +122,95 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 25, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, "end": 58, "loc": { "start": { "line": 2, - "column": 5 + "column": 8 }, "end": { "line": 4, "column": 5 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 28, - "end": 58, - "loc": { - "start": { - "line": 2, - "column": 8 + "body": [ + { + "type": "ReturnStatement", + "start": 38, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 22 + } }, - "end": { - "line": 4, - "column": 5 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 38, + "argument": { + "type": "MemberExpression", + "start": 45, "end": 52, "loc": { "start": { "line": 3, - "column": 8 + "column": 15 }, "end": { "line": 3, "column": 22 } }, - "argument": { - "type": "MemberExpression", + "object": { + "type": "Super", "start": 45, - "end": 52, + "end": 50, "loc": { "start": { "line": 3, "column": 15 }, + "end": { + "line": 3, + "column": 20 + } + } + }, + "property": { + "type": "Identifier", + "start": 51, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 21 + }, "end": { "line": 3, "column": 22 } }, - "object": { - "type": "Super", - "start": 45, - "end": 50, - "loc": { - "start": { - "line": 3, - "column": 15 - }, - "end": { - "line": 3, - "column": 20 - } - } - }, - "property": { - "type": "Identifier", - "start": 51, - "end": 52, - "loc": { - "start": { - "line": 3, - "column": 21 - }, - "end": { - "line": 3, - "column": 22 - } - }, - "name": "y" - }, - "computed": false - } + "name": "y" + }, + "computed": false } - ] - } + } + ], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-template-literals/octal-literal/actual.js b/packages/babylon/test/fixtures/esprima/es2015-template-literals/.octal-literal/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-template-literals/octal-literal/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-template-literals/.octal-literal/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-template-literals/octal-literal/expected.json b/packages/babylon/test/fixtures/esprima/es2015-template-literals/.octal-literal/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-template-literals/octal-literal/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-template-literals/.octal-literal/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-template-literals/octal-literal/options.json b/packages/babylon/test/fixtures/esprima/es2015-template-literals/.octal-literal/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-template-literals/octal-literal/options.json rename to packages/babylon/test/fixtures/esprima/es2015-template-literals/.octal-literal/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-template-literals/strict-octal-literal/actual.js b/packages/babylon/test/fixtures/esprima/es2015-template-literals/.strict-octal-literal/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-template-literals/strict-octal-literal/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-template-literals/.strict-octal-literal/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-template-literals/strict-octal-literal/expected.json b/packages/babylon/test/fixtures/esprima/es2015-template-literals/.strict-octal-literal/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-template-literals/strict-octal-literal/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-template-literals/.strict-octal-literal/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-template-literals/strict-octal-literal/options.json b/packages/babylon/test/fixtures/esprima/es2015-template-literals/.strict-octal-literal/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-template-literals/strict-octal-literal/options.json rename to packages/babylon/test/fixtures/esprima/es2015-template-literals/.strict-octal-literal/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-arrow-default/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-arrow-default/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-arrow-default/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-arrow-default/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/options.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-arrow-default/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-arrow-default/options.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-arrow-default/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-name/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-name/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-name/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-name/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-name/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-name/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-parameter/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-parameter/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-parameter/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-parameter/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-parameter/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-parameter/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-rest/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-rest/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-rest/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-rest/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-rest/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-expression-rest/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-parameter/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-parameter/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-parameter/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-parameter/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-parameter/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-parameter/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-rest/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-rest/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-rest/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-rest/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-rest/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-generator-rest/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-array-pattern/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-array-pattern/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-array-pattern/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-array-pattern/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/options.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-array-pattern/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-array-pattern/options.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-array-pattern/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-default/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-default/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-default/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-default/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/options.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-default/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-default/options.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-default/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-name/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-name/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-name/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-name/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/options.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-name/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/invalid-yield-strict-arrow-parameter-name/options.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.invalid-yield-strict-arrow-parameter-name/options.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-arrow-concise-body/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-arrow-concise-body/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-arrow-concise-body/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-arrow-concise-body/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-arrow-concise-body/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-arrow-concise-body/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-arrow-concise-body/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-arrow-concise-body/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-function-expression/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-function-expression/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-function-expression/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-function-expression/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-function-parameter/actual.js b/packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-function-parameter/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-function-parameter/actual.js rename to packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-function-parameter/actual.js diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-function-parameter/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-function-parameter/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-function-parameter/expected.json rename to packages/babylon/test/fixtures/esprima/es2015-yield/.yield-generator-function-parameter/expected.json diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-binding-element/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-binding-element/expected.json index 350b3f3ac2..09eb1bcbb8 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-binding-element/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-binding-element/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 14, "loc": { @@ -120,8 +120,7 @@ } }, "name": "yield" - }, - "kind": "init" + } } ] }, @@ -145,6 +144,7 @@ ], "kind": "var" } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-binding-property/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-binding-property/expected.json index 65944e5be1..7b85a9fef5 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-binding-property/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-binding-property/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 14, "loc": { @@ -120,8 +120,7 @@ } }, "name": "x" - }, - "kind": "init" + } } ] }, @@ -145,6 +144,7 @@ ], "kind": "var" } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-method/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-method/expected.json index dbe92db430..660094298e 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-method/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-method/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 14, "loc": { @@ -90,42 +90,27 @@ }, "name": "yield" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 9, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 14, "loc": { "start": { "line": 1, - "column": 9 + "column": 12 }, "end": { "line": 1, "column": 14 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-parameter-object-pattern/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-parameter-object-pattern/expected.json index f491ff04fd..b212d5a14f 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-parameter-object-pattern/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-generator-parameter-object-pattern/expected.json @@ -77,7 +77,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 13, "end": 21, "loc": { @@ -124,8 +124,7 @@ } }, "name": "y" - }, - "kind": "init" + } } ] } @@ -144,9 +143,11 @@ "column": 25 } }, - "body": [] + "body": [], + "directives": [] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-method/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-method/expected.json index 7ef2282cd6..73a6d2827d 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-method/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-method/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 13, "loc": { @@ -90,42 +90,27 @@ }, "name": "yield" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 8, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 11, "end": 13, "loc": { "start": { "line": 1, - "column": 8 + "column": 11 }, "end": { "line": 1, "column": 13 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 11, - "end": 13, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 13 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-parameter-object-pattern/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-parameter-object-pattern/expected.json index 68bee782bd..f0dc7b4f27 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-parameter-object-pattern/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-parameter-object-pattern/expected.json @@ -77,7 +77,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 12, "end": 20, "loc": { @@ -124,8 +124,7 @@ } }, "name": "y" - }, - "kind": "init" + } } ] } @@ -144,9 +143,11 @@ "column": 24 } }, - "body": [] + "body": [], + "directives": [] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-strict-binding-property/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-strict-binding-property/expected.json index c48e078e6b..687e8f341a 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-strict-binding-property/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-strict-binding-property/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 20, "end": 28, "loc": { @@ -120,8 +120,7 @@ } }, "name": "x" - }, - "kind": "init" + } } ] }, diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-strict-method/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-strict-method/expected.json index 2773f3f558..e71a000bbe 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-strict-method/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-strict-method/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 17, "end": 27, "loc": { @@ -90,42 +90,27 @@ }, "name": "yield" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 22, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, "end": 27, "loc": { "start": { "line": 1, - "column": 22 + "column": 25 }, "end": { "line": 1, "column": 27 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 25, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 27 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-super-property/expected.json b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-super-property/expected.json index 4e179ca792..ef8158ed4e 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-yield/yield-super-property/expected.json +++ b/packages/babylon/test/fixtures/esprima/es2015-yield/yield-super-property/expected.json @@ -90,7 +90,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 20, "end": 39, "loc": { @@ -122,41 +122,41 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 21, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, "end": 39, "loc": { "start": { "line": 1, - "column": 21 + "column": 24 }, "end": { "line": 1, "column": 39 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 24, - "end": 39, - "loc": { - "start": { - "line": 1, - "column": 24 + "body": [ + { + "type": "ExpressionStatement", + "start": 26, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 37 + } }, - "end": { - "line": 1, - "column": 39 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "MemberExpression", "start": 26, "end": 37, "loc": { @@ -169,61 +169,48 @@ "column": 37 } }, - "expression": { - "type": "MemberExpression", + "object": { + "type": "Super", "start": 26, - "end": 37, + "end": 31, "loc": { "start": { "line": 1, "column": 26 }, + "end": { + "line": 1, + "column": 31 + } + } + }, + "property": { + "type": "Identifier", + "start": 32, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 32 + }, "end": { "line": 1, "column": 37 } }, - "object": { - "type": "Super", - "start": 26, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 26 - }, - "end": { - "line": 1, - "column": 31 - } - } - }, - "property": { - "type": "Identifier", - "start": 32, - "end": 37, - "loc": { - "start": { - "line": 1, - "column": 32 - }, - "end": { - "line": 1, - "column": 37 - } - }, - "name": "yield" - }, - "computed": false - } + "name": "yield" + }, + "computed": false } - ] - } + } + ], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/GH-1106-09/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.GH-1106-09/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/GH-1106-09/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.GH-1106-09/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/GH-1106-09/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.GH-1106-09/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/GH-1106-09/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.GH-1106-09/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/GH-1106-09/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.GH-1106-09/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/GH-1106-09/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.GH-1106-09/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0033/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0033/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0033/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0033/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0033/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0033/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0033/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0033/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0033/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0033/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0033/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0033/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0034/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0034/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0034/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0034/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0034/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0034/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0034/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0034/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0034/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0034/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0034/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0034/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0035/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0035/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0035/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0035/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0035/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0035/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0035/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0035/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0035/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0035/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0035/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0035/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0036/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0036/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0036/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0036/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0036/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0036/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0036/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0036/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0036/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0036/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0036/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0036/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0037/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0037/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0037/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0037/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0037/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0037/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0037/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0037/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0037/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0037/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0037/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0037/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0041/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0041/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0041/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0041/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0041/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0041/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0041/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0041/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0041/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0041/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0041/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0041/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0042/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0042/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0042/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0042/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0042/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0042/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0042/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0042/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0042/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0042/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0042/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0042/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0043/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0043/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0043/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0043/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0043/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0043/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0043/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0043/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0043/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0043/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0043/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0043/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0044/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0044/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0044/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0044/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0044/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0044/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0044/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0044/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0044/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0044/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0044/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0044/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0048/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0048/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0048/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0048/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0048/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0048/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0048/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0048/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0048/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0048/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0048/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0048/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0049/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0049/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0049/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0049/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0049/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0049/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0049/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0049/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0049/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0049/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0049/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0049/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0050/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0050/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0050/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0050/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0050/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0050/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0050/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0050/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0050/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0050/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0050/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0050/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0051/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0051/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0051/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0051/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0051/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0051/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0051/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0051/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0051/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0051/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0051/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0051/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0075/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0075/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0075/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0075/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0075/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0075/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0075/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0075/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0137/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0137/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0137/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0137/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0137/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0137/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0137/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0137/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0137/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0137/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0137/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0137/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0163/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0163/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0163/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0163/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0163/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0163/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0163/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0163/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0163/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0163/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0163/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0163/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0165/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0165/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0165/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0165/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0165/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0165/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0165/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0165/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0165/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0165/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0165/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0165/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0166/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0166/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0166/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0166/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0166/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0166/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0166/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0166/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0166/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0166/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0166/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0166/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0167/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0167/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0167/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0167/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0167/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0167/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0167/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0167/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0167/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0167/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0167/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0167/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0169/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0169/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0169/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0169/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0169/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0169/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0169/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0169/expected.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0169/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0169/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0169/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0169/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0250/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0250/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0250/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0250/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0250/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0250/expected.json new file mode 100644 index 0000000000..d6b7e5702f --- /dev/null +++ b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0250/expected.json @@ -0,0 +1,206 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "AssignmentExpression", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "operator": "=", + "left": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + }, + "name": "x" + }, + "right": { + "type": "ObjectExpression", + "start": 4, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 6, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 6, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": "__proto__" + }, + "value": { + "type": "NumberLiteral", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + }, + { + "type": "ObjectProperty", + "start": 21, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 21, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "name": "__proto__" + }, + "value": { + "type": "NumberLiteral", + "start": 32, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "extra": { + "rawValue": 43, + "raw": "43" + }, + "value": 43 + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0250/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0250/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0250/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0250/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0277/actual.js b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0277/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0277/actual.js rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0277/actual.js diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0277/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0277/expected.json similarity index 98% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0277/expected.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0277/expected.json index 0fa4cd9032..374479f48a 100644 --- a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0277/expected.json +++ b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0277/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 18, "loc": { diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0277/options.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0277/options.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0277/options.json rename to packages/babylon/test/fixtures/esprima/invalid-syntax/.migrated_0277/options.json diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0270/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0270/expected.json index 5830cef10e..ee4de023b7 100644 --- a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0270/expected.json +++ b/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0270/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 29, "loc": { diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0271/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0271/expected.json index 6cc3ea74c2..d1b5f89276 100644 --- a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0271/expected.json +++ b/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0271/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 31, "loc": { diff --git a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0278/expected.json b/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0278/expected.json index 966e05ade4..1e47cb6c1c 100644 --- a/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0278/expected.json +++ b/packages/babylon/test/fixtures/esprima/invalid-syntax/migrated_0278/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 28, "loc": { diff --git a/packages/babylon/test/fixtures/esprima/statement-if/migrated_0003/actual.js b/packages/babylon/test/fixtures/esprima/statement-if/.migrated_0003/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/statement-if/migrated_0003/actual.js rename to packages/babylon/test/fixtures/esprima/statement-if/.migrated_0003/actual.js diff --git a/packages/babylon/test/fixtures/esprima/statement-iteration/migrated_0021/actual.js b/packages/babylon/test/fixtures/esprima/statement-iteration/.migrated_0021/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/statement-iteration/migrated_0021/actual.js rename to packages/babylon/test/fixtures/esprima/statement-iteration/.migrated_0021/actual.js diff --git a/packages/babylon/test/fixtures/esprima/statement-iteration/migrated_0021/expected.json b/packages/babylon/test/fixtures/esprima/statement-iteration/.migrated_0021/expected.json similarity index 100% rename from packages/babylon/test/fixtures/esprima/statement-iteration/migrated_0021/expected.json rename to packages/babylon/test/fixtures/esprima/statement-iteration/.migrated_0021/expected.json diff --git a/packages/babylon/test/fixtures/esprima/statement-iteration/pattern-in-for-in/actual.js b/packages/babylon/test/fixtures/esprima/statement-iteration/.pattern-in-for-in/actual.js similarity index 100% rename from packages/babylon/test/fixtures/esprima/statement-iteration/pattern-in-for-in/actual.js rename to packages/babylon/test/fixtures/esprima/statement-iteration/.pattern-in-for-in/actual.js diff --git a/packages/babylon/test/fixtures/esprima/statement-throw/migrated_0002/expected.json b/packages/babylon/test/fixtures/esprima/statement-throw/migrated_0002/expected.json index 0ddcce0c63..1586888a8b 100644 --- a/packages/babylon/test/fixtures/esprima/statement-throw/migrated_0002/expected.json +++ b/packages/babylon/test/fixtures/esprima/statement-throw/migrated_0002/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 8, "end": 24, "loc": { @@ -109,8 +109,7 @@ "raw": "\"Error\"" }, "value": "Error" - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/experimental/async-functions/object-last-property-shorthand/expected.json b/packages/babylon/test/fixtures/experimental/async-functions/object-last-property-shorthand/expected.json index b43eede7d6..bd3c1e7695 100644 --- a/packages/babylon/test/fixtures/experimental/async-functions/object-last-property-shorthand/expected.json +++ b/packages/babylon/test/fixtures/experimental/async-functions/object-last-property-shorthand/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 11, "loc": { @@ -120,7 +120,6 @@ }, "name": "async" }, - "kind": "init", "value": { "type": "Identifier", "start": 6, @@ -143,6 +142,7 @@ ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/async-functions/pattern/expected.json b/packages/babylon/test/fixtures/experimental/async-functions/pattern/expected.json index 26dffdc586..339a3925ef 100644 --- a/packages/babylon/test/fixtures/experimental/async-functions/pattern/expected.json +++ b/packages/babylon/test/fixtures/experimental/async-functions/pattern/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 7, "end": 12, "loc": { @@ -105,7 +105,6 @@ }, "name": "async" }, - "kind": "init", "value": { "type": "Identifier", "start": 7, diff --git a/packages/babylon/test/fixtures/experimental/class-constructor-call/.duplicate/actual.js b/packages/babylon/test/fixtures/experimental/class-constructor-call/.duplicate/actual.js new file mode 100644 index 0000000000..6fd5dd7d11 --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/class-constructor-call/.duplicate/actual.js @@ -0,0 +1,4 @@ +class Foo { + call constructor() {} + call constructor() {} +} diff --git a/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-generator/actual.js b/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-generator/actual.js new file mode 100644 index 0000000000..9a3bd5d8d6 --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-generator/actual.js @@ -0,0 +1,5 @@ +class Foo { + *call constructor() { + foo(); + } +} diff --git a/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-generator/options.json b/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-generator/options.json new file mode 100644 index 0000000000..ef2b7c682f --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-generator/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:8)" +} diff --git a/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-key/actual.js b/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-key/actual.js new file mode 100644 index 0000000000..e3155a24a8 --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-key/actual.js @@ -0,0 +1,5 @@ +class Foo { + call foobar() { + foo(); + } +} diff --git a/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-key/options.json b/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-key/options.json new file mode 100644 index 0000000000..4e84114247 --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/class-constructor-call/illegal-key/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (2:7)" +} diff --git a/packages/babylon/test/fixtures/experimental/class-constructor-call/options.json b/packages/babylon/test/fixtures/experimental/class-constructor-call/options.json new file mode 100644 index 0000000000..253cf5199b --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/class-constructor-call/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classConstructorCall"] +} diff --git a/packages/babylon/test/fixtures/experimental/class-constructor-call/plain/actual.js b/packages/babylon/test/fixtures/experimental/class-constructor-call/plain/actual.js new file mode 100644 index 0000000000..1f8b64ef4a --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/class-constructor-call/plain/actual.js @@ -0,0 +1,5 @@ +class Foo { + call constructor() { + foo(); + } +} diff --git a/packages/babylon/test/fixtures/experimental/class-constructor-call/plain/expected.json b/packages/babylon/test/fixtures/experimental/class-constructor-call/plain/expected.json new file mode 100644 index 0000000000..49c89dadbc --- /dev/null +++ b/packages/babylon/test/fixtures/experimental/class-constructor-call/plain/expected.json @@ -0,0 +1,186 @@ +{ + "type": "File", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 14, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 19, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": "constructor" + }, + "static": false, + "kind": "constructorCall", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 33, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 39, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "expression": { + "type": "CallExpression", + "start": 39, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "callee": { + "type": "Identifier", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "name": "foo" + }, + "arguments": [] + } + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/24/actual.js b/packages/babylon/test/fixtures/experimental/uncategorised/.24/actual.js similarity index 100% rename from packages/babylon/test/fixtures/experimental/uncategorised/24/actual.js rename to packages/babylon/test/fixtures/experimental/uncategorised/.24/actual.js diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/24/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/.24/expected.json similarity index 100% rename from packages/babylon/test/fixtures/experimental/uncategorised/24/expected.json rename to packages/babylon/test/fixtures/experimental/uncategorised/.24/expected.json diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/24/options.json b/packages/babylon/test/fixtures/experimental/uncategorised/.24/options.json similarity index 100% rename from packages/babylon/test/fixtures/experimental/uncategorised/24/options.json rename to packages/babylon/test/fixtures/experimental/uncategorised/.24/options.json diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/10/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/10/expected.json index a9e67765ef..f017a9cc8e 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/10/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/10/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 6, "loc": { @@ -105,7 +105,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/11/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/11/expected.json index 5da577c081..64c2046836 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/11/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/11/expected.json @@ -76,7 +76,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 11, "end": 12, "loc": { @@ -108,7 +108,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 11, diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/13/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/13/expected.json index bbf2490867..13c6c8dc0c 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/13/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/13/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 6, "loc": { @@ -121,7 +121,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, @@ -174,6 +173,7 @@ } } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/14/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/14/expected.json index de5cd3bace..761b028be8 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/14/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/14/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 3, "loc": { @@ -90,7 +90,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 2, @@ -140,7 +139,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 11, "end": 12, "loc": { @@ -172,7 +171,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 11, @@ -222,7 +220,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 20, "end": 21, "loc": { @@ -254,7 +252,6 @@ }, "name": "c" }, - "kind": "init", "value": { "type": "Identifier", "start": 20, diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/21/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/21/expected.json index d6700e7b80..05a0c068cb 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/21/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/21/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 10, "end": 14, "loc": { @@ -140,11 +140,10 @@ "raw": "1" }, "value": 1 - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectMethod", "start": 16, "end": 52, "loc": { @@ -176,60 +175,60 @@ }, "name": "foo" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 25, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": true, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "name": "promise" + } + ], + "body": { + "type": "BlockStatement", + "start": 35, "end": 52, "loc": { "start": { "line": 1, - "column": 25 + "column": 35 }, "end": { "line": 1, "column": 52 } }, - "id": null, - "generator": false, - "expression": false, - "async": true, - "params": [ + "body": [ { - "type": "Identifier", - "start": 26, - "end": 33, + "type": "ExpressionStatement", + "start": 37, + "end": 50, "loc": { "start": { "line": 1, - "column": 26 + "column": 37 }, "end": { "line": 1, - "column": 33 + "column": 50 } }, - "name": "promise" - } - ], - "body": { - "type": "BlockStatement", - "start": 35, - "end": 52, - "loc": { - "start": { - "line": 1, - "column": 35 - }, - "end": { - "line": 1, - "column": 52 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "AwaitExpression", "start": 37, "end": 50, "loc": { @@ -242,42 +241,27 @@ "column": 50 } }, - "expression": { - "type": "AwaitExpression", - "start": 37, + "all": false, + "argument": { + "type": "Identifier", + "start": 43, "end": 50, "loc": { "start": { "line": 1, - "column": 37 + "column": 43 }, "end": { "line": 1, "column": 50 } }, - "all": false, - "argument": { - "type": "Identifier", - "start": 43, - "end": 50, - "loc": { - "start": { - "line": 1, - "column": 43 - }, - "end": { - "line": 1, - "column": 50 - } - }, - "name": "promise" - } + "name": "promise" } } - ], - "directives": [] - } + } + ], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/22/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/22/expected.json index 3f2e2fe5b0..a0fd07d512 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/22/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/22/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 12, "end": 48, "loc": { @@ -107,59 +107,59 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 21, + "id": null, + "generator": false, + "expression": false, + "async": true, + "params": [ + { + "type": "Identifier", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "name": "promise" + } + ], + "body": { + "type": "BlockStatement", + "start": 31, "end": 48, "loc": { "start": { "line": 1, - "column": 21 + "column": 31 }, "end": { "line": 1, "column": 48 } }, - "id": null, - "generator": false, - "expression": false, - "async": true, - "params": [ + "body": [ { - "type": "Identifier", - "start": 22, - "end": 29, + "type": "ExpressionStatement", + "start": 33, + "end": 46, "loc": { "start": { "line": 1, - "column": 22 + "column": 33 }, "end": { "line": 1, - "column": 29 + "column": 46 } }, - "name": "promise" - } - ], - "body": { - "type": "BlockStatement", - "start": 31, - "end": 48, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 48 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "AwaitExpression", "start": 33, "end": 46, "loc": { @@ -172,46 +172,33 @@ "column": 46 } }, - "expression": { - "type": "AwaitExpression", - "start": 33, + "all": false, + "argument": { + "type": "Identifier", + "start": 39, "end": 46, "loc": { "start": { "line": 1, - "column": 33 + "column": 39 }, "end": { "line": 1, "column": 46 } }, - "all": false, - "argument": { - "type": "Identifier", - "start": 39, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 39 - }, - "end": { - "line": 1, - "column": 46 - } - }, - "name": "promise" - } + "name": "promise" } } - ] - } + } + ], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/29/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/29/expected.json index 169869cbf6..0c05743d58 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/29/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/29/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 13, "end": 23, "loc": { @@ -107,41 +107,27 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 18, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, "end": 23, "loc": { "start": { "line": 1, - "column": 18 + "column": 21 }, "end": { "line": 1, "column": 23 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/30/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/30/expected.json index 60fc936189..a5e072a934 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/30/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/30/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 12, "end": 25, "loc": { @@ -139,8 +139,7 @@ "raw": "\"test\"" }, "value": "test" - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/31/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/31/expected.json index 55dbd1960c..1078686a77 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/31/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/31/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 12, "end": 22, "loc": { @@ -120,43 +120,28 @@ }, "name": "async" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 17, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, "end": 22, "loc": { "start": { "line": 1, - "column": 17 + "column": 20 }, "end": { "line": 1, "column": 22 } }, - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/35/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/35/expected.json index 03c8437135..ff000260aa 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/35/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/35/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 17, "end": 25, "loc": { @@ -140,45 +140,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 20, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, "end": 25, "loc": { "start": { "line": 1, - "column": 20 + "column": 23 }, "end": { "line": 1, "column": 25 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 23, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 23 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/36/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/36/expected.json index 50d2011f36..118d2b69c5 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/36/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/36/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 17, "end": 30, "loc": { @@ -140,62 +140,49 @@ }, "static": false, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 24, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": "f" + } + ], + "body": { + "type": "BlockStatement", + "start": 28, "end": 30, "loc": { "start": { "line": 1, - "column": 24 + "column": 28 }, "end": { "line": 1, "column": 30 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "name": "f" - } - ], - "body": { - "type": "BlockStatement", - "start": 28, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 28 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/37/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/37/expected.json index ac0fa38fc3..ad67c94592 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/37/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/37/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 17, "end": 29, "loc": { @@ -140,45 +140,32 @@ }, "static": false, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 24, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 27, "end": 29, "loc": { "start": { "line": 1, - "column": 24 + "column": 27 }, "end": { "line": 1, "column": 29 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 27, - "end": 29, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 29 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/38/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/38/expected.json index c538000216..d55670aa51 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/38/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/38/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 22, "end": 30, "loc": { @@ -171,45 +171,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 25, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, "end": 30, "loc": { "start": { "line": 1, - "column": 25 + "column": 28 }, "end": { "line": 1, "column": 30 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 28, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 28 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/39/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/39/expected.json index da6ab2aeb4..b8e2fae3e8 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/39/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/39/expected.json @@ -104,7 +104,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 12, "end": 22, "loc": { @@ -188,8 +188,7 @@ "raw": "\"bar\"" }, "value": "bar" - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/49/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/49/expected.json index 0ca312dba2..1186fc6b42 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/49/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/49/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 17, "end": 27, "loc": { @@ -173,8 +173,7 @@ "raw": "'wow'" }, "value": "wow" - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/experimental/uncategorised/57/expected.json b/packages/babylon/test/fixtures/experimental/uncategorised/57/expected.json index ebb3ee0019..84ddd9f145 100644 --- a/packages/babylon/test/fixtures/experimental/uncategorised/57/expected.json +++ b/packages/babylon/test/fixtures/experimental/uncategorised/57/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 12, "end": 23, "loc": { @@ -107,62 +107,49 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 15, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 16, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": "a" + } + ], + "body": { + "type": "BlockStatement", + "start": 20, "end": 23, "loc": { "start": { "line": 1, - "column": 15 + "column": 20 }, "end": { "line": 1, "column": 23 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 16, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "name": "a" - } - ], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/regression/arrow-function-parens-with-return-type/actual.js b/packages/babylon/test/fixtures/flow/regression/.arrow-function-parens-with-return-type/actual.js similarity index 100% rename from packages/babylon/test/fixtures/flow/regression/arrow-function-parens-with-return-type/actual.js rename to packages/babylon/test/fixtures/flow/regression/.arrow-function-parens-with-return-type/actual.js diff --git a/packages/babylon/test/fixtures/flow/regression/arrow-function-parens-with-return-type/expected.json b/packages/babylon/test/fixtures/flow/regression/.arrow-function-parens-with-return-type/expected.json similarity index 100% rename from packages/babylon/test/fixtures/flow/regression/arrow-function-parens-with-return-type/expected.json rename to packages/babylon/test/fixtures/flow/regression/.arrow-function-parens-with-return-type/expected.json diff --git a/packages/babylon/test/fixtures/flow/regression/arrow-function-parens-with-return-type/options.json b/packages/babylon/test/fixtures/flow/regression/.arrow-function-parens-with-return-type/options.json similarity index 100% rename from packages/babylon/test/fixtures/flow/regression/arrow-function-parens-with-return-type/options.json rename to packages/babylon/test/fixtures/flow/regression/.arrow-function-parens-with-return-type/options.json diff --git a/packages/babylon/test/fixtures/flow/regression/issue-2083/expected.json b/packages/babylon/test/fixtures/flow/regression/issue-2083/expected.json index f56868b0ee..9fc301b2fd 100644 --- a/packages/babylon/test/fixtures/flow/regression/issue-2083/expected.json +++ b/packages/babylon/test/fixtures/flow/regression/issue-2083/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 14, "end": 110, "loc": { @@ -107,93 +107,94 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 17, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, "end": 110, "loc": { "start": { "line": 2, - "column": 5 + "column": 8 }, "end": { "line": 6, "column": 3 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 110, - "loc": { - "start": { - "line": 2, - "column": 8 + "body": [ + { + "type": "SwitchStatement", + "start": 26, + "end": 106, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } }, - "end": { - "line": 6, - "column": 3 - } - }, - "body": [ - { - "type": "SwitchStatement", - "start": 26, - "end": 106, + "discriminant": { + "type": "NumberLiteral", + "start": 34, + "end": 35, "loc": { "start": { "line": 3, - "column": 4 + "column": 12 }, "end": { - "line": 5, - "column": 5 + "line": 3, + "column": 13 } }, - "discriminant": { - "type": "NumberLiteral", - "start": 34, - "end": 35, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "cases": [ + { + "type": "SwitchCase", + "start": 45, + "end": 100, "loc": { "start": { - "line": 3, - "column": 12 + "line": 4, + "column": 6 }, "end": { - "line": 3, - "column": 13 + "line": 4, + "column": 61 } }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - }, - "cases": [ - { - "type": "SwitchCase", - "start": 45, - "end": 100, + "consequent": [], + "test": { + "type": "BinaryExpression", + "start": 51, + "end": 98, "loc": { "start": { "line": 4, - "column": 6 + "column": 12 }, "end": { "line": 4, - "column": 61 + "column": 59 } }, - "consequent": [], - "test": { - "type": "BinaryExpression", + "left": { + "type": "MemberExpression", "start": 51, - "end": 98, + "end": 71, "loc": { "start": { "line": 4, @@ -201,120 +202,105 @@ }, "end": { "line": 4, - "column": 59 + "column": 32 } }, - "left": { - "type": "MemberExpression", + "object": { + "type": "Identifier", "start": 51, - "end": 71, + "end": 61, "loc": { "start": { "line": 4, "column": 12 }, + "end": { + "line": 4, + "column": 22 + } + }, + "name": "MatrixType" + }, + "property": { + "type": "Identifier", + "start": 62, + "end": 71, + "loc": { + "start": { + "line": 4, + "column": 23 + }, "end": { "line": 4, "column": 32 } }, - "object": { - "type": "Identifier", - "start": 51, - "end": 61, - "loc": { - "start": { - "line": 4, - "column": 12 - }, - "end": { - "line": 4, - "column": 22 - } - }, - "name": "MatrixType" - }, - "property": { - "type": "Identifier", - "start": 62, - "end": 71, - "loc": { - "start": { - "line": 4, - "column": 23 - }, - "end": { - "line": 4, - "column": 32 - } - }, - "name": "IsScaling" - }, - "computed": false + "name": "IsScaling" }, - "operator": "|", - "right": { - "type": "MemberExpression", + "computed": false + }, + "operator": "|", + "right": { + "type": "MemberExpression", + "start": 74, + "end": 98, + "loc": { + "start": { + "line": 4, + "column": 35 + }, + "end": { + "line": 4, + "column": 59 + } + }, + "object": { + "type": "Identifier", "start": 74, - "end": 98, + "end": 84, "loc": { "start": { "line": 4, "column": 35 }, + "end": { + "line": 4, + "column": 45 + } + }, + "name": "MatrixType" + }, + "property": { + "type": "Identifier", + "start": 85, + "end": 98, + "loc": { + "start": { + "line": 4, + "column": 46 + }, "end": { "line": 4, "column": 59 } }, - "object": { - "type": "Identifier", - "start": 74, - "end": 84, - "loc": { - "start": { - "line": 4, - "column": 35 - }, - "end": { - "line": 4, - "column": 45 - } - }, - "name": "MatrixType" - }, - "property": { - "type": "Identifier", - "start": 85, - "end": 98, - "loc": { - "start": { - "line": 4, - "column": 46 - }, - "end": { - "line": 4, - "column": 59 - } - }, - "name": "IsTranslation" - }, - "computed": false + "name": "IsTranslation" }, - "extra": { - "parenthesized": true - } + "computed": false + }, + "extra": { + "parenthesized": true } } - ] - } - ], - "directives": [] - } + } + ] + } + ], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 114, "end": 162, "loc": { @@ -346,71 +332,72 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 117, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 120, "end": 162, "loc": { "start": { "line": 8, - "column": 5 + "column": 8 }, "end": { "line": 10, "column": 3 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 120, - "end": 162, - "loc": { - "start": { - "line": 8, - "column": 8 + "body": [ + { + "type": "SwitchStatement", + "start": 126, + "end": 158, + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 36 + } }, - "end": { - "line": 10, - "column": 3 - } - }, - "body": [ - { - "type": "SwitchStatement", - "start": 126, - "end": 158, + "discriminant": { + "type": "BinaryExpression", + "start": 134, + "end": 154, "loc": { "start": { "line": 9, - "column": 4 + "column": 12 }, "end": { "line": 9, - "column": 36 + "column": 32 } }, - "discriminant": { + "left": { "type": "BinaryExpression", - "start": 134, - "end": 154, + "start": 135, + "end": 145, "loc": { "start": { "line": 9, - "column": 12 + "column": 13 }, "end": { "line": 9, - "column": 32 + "column": 23 } }, "left": { - "type": "BinaryExpression", + "type": "Identifier", "start": 135, - "end": 145, + "end": 140, "loc": { "start": { "line": 9, @@ -418,73 +405,58 @@ }, "end": { "line": 9, - "column": 23 + "column": 18 } }, - "left": { - "type": "Identifier", - "start": 135, - "end": 140, - "loc": { - "start": { - "line": 9, - "column": 13 - }, - "end": { - "line": 9, - "column": 18 - } - }, - "name": "typeA" - }, - "operator": "<<", - "right": { - "type": "NumberLiteral", - "start": 144, - "end": 145, - "loc": { - "start": { - "line": 9, - "column": 22 - }, - "end": { - "line": 9, - "column": 23 - } - }, - "extra": { - "rawValue": 4, - "raw": "4" - }, - "value": 4 - }, - "extra": { - "parenthesized": true - } + "name": "typeA" }, - "operator": "|", + "operator": "<<", "right": { - "type": "Identifier", - "start": 149, - "end": 154, + "type": "NumberLiteral", + "start": 144, + "end": 145, "loc": { "start": { "line": 9, - "column": 27 + "column": 22 }, "end": { "line": 9, - "column": 32 + "column": 23 } }, - "name": "typeB" + "extra": { + "rawValue": 4, + "raw": "4" + }, + "value": 4 + }, + "extra": { + "parenthesized": true } }, - "cases": [] - } - ], - "directives": [] - } + "operator": "|", + "right": { + "type": "Identifier", + "start": 149, + "end": 154, + "loc": { + "start": { + "line": 9, + "column": 27 + }, + "end": { + "line": 9, + "column": 32 + } + }, + "name": "typeB" + } + }, + "cases": [] + } + ], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/69/actual.js b/packages/babylon/test/fixtures/flow/type-annotations/.69/actual.js similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/69/actual.js rename to packages/babylon/test/fixtures/flow/type-annotations/.69/actual.js diff --git a/packages/babylon/test/fixtures/flow/type-annotations/69/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/.69/expected.json similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/69/expected.json rename to packages/babylon/test/fixtures/flow/type-annotations/.69/expected.json diff --git a/packages/babylon/test/fixtures/flow/type-annotations/70/actual.js b/packages/babylon/test/fixtures/flow/type-annotations/.70/actual.js similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/70/actual.js rename to packages/babylon/test/fixtures/flow/type-annotations/.70/actual.js diff --git a/packages/babylon/test/fixtures/flow/type-annotations/70/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/.70/expected.json similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/70/expected.json rename to packages/babylon/test/fixtures/flow/type-annotations/.70/expected.json diff --git a/packages/babylon/test/fixtures/flow/type-annotations/71/actual.js b/packages/babylon/test/fixtures/flow/type-annotations/.71/actual.js similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/71/actual.js rename to packages/babylon/test/fixtures/flow/type-annotations/.71/actual.js diff --git a/packages/babylon/test/fixtures/flow/type-annotations/71/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/.71/expected.json similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/71/expected.json rename to packages/babylon/test/fixtures/flow/type-annotations/.71/expected.json diff --git a/packages/babylon/test/fixtures/flow/type-annotations/75/actual.js b/packages/babylon/test/fixtures/flow/type-annotations/.75/actual.js similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/75/actual.js rename to packages/babylon/test/fixtures/flow/type-annotations/.75/actual.js diff --git a/packages/babylon/test/fixtures/flow/type-annotations/75/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/.75/expected.json similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/75/expected.json rename to packages/babylon/test/fixtures/flow/type-annotations/.75/expected.json diff --git a/packages/babylon/test/fixtures/flow/type-annotations/76/actual.js b/packages/babylon/test/fixtures/flow/type-annotations/.76/actual.js similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/76/actual.js rename to packages/babylon/test/fixtures/flow/type-annotations/.76/actual.js diff --git a/packages/babylon/test/fixtures/flow/type-annotations/76/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/.76/expected.json similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/76/expected.json rename to packages/babylon/test/fixtures/flow/type-annotations/.76/expected.json diff --git a/packages/babylon/test/fixtures/flow/type-annotations/77/actual.js b/packages/babylon/test/fixtures/flow/type-annotations/.77/actual.js similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/77/actual.js rename to packages/babylon/test/fixtures/flow/type-annotations/.77/actual.js diff --git a/packages/babylon/test/fixtures/flow/type-annotations/77/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/.77/expected.json similarity index 100% rename from packages/babylon/test/fixtures/flow/type-annotations/77/expected.json rename to packages/babylon/test/fixtures/flow/type-annotations/.77/expected.json diff --git a/packages/babylon/test/fixtures/flow/type-annotations/20/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/20/expected.json index 455aaeaa26..e21b48d766 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/20/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/20/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 30, "loc": { @@ -122,88 +122,74 @@ "name": "fooProp" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 14, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 14 + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 27 + } }, - "end": { - "line": 1, - "column": 30 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 15, + "name": "value", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 20, "end": 27, "loc": { "start": { "line": 1, - "column": 15 + "column": 20 }, "end": { "line": 1, "column": 27 } }, - "name": "value", "typeAnnotation": { - "type": "TypeAnnotation", - "start": 20, + "type": "NumberTypeAnnotation", + "start": 21, "end": 27, "loc": { "start": { "line": 1, - "column": 20 + "column": 21 }, "end": { "line": 1, "column": 27 } - }, - "typeAnnotation": { - "type": "NumberTypeAnnotation", - "start": 21, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 27 - } - } } } } - ], - "body": { - "type": "BlockStatement", - "start": 28, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 28 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "body": [], - "directives": [] } + ], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/21/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/21/expected.json index 3360af33e4..d1ddc78e40 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/21/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/21/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 35, "loc": { @@ -122,118 +122,104 @@ "name": "fooProp" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 14, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 14 + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 27 + } }, - "end": { - "line": 1, - "column": 35 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 15, + "name": "value", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 20, "end": 27, "loc": { "start": { "line": 1, - "column": 15 + "column": 20 }, "end": { "line": 1, "column": 27 } }, - "name": "value", "typeAnnotation": { - "type": "TypeAnnotation", - "start": 20, + "type": "NumberTypeAnnotation", + "start": 21, "end": 27, "loc": { "start": { "line": 1, - "column": 20 + "column": 21 }, "end": { "line": 1, "column": 27 } - }, - "typeAnnotation": { - "type": "NumberTypeAnnotation", - "start": 21, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 27 - } - } } } } - ], - "returnType": { - "type": "TypeAnnotation", - "start": 28, + } + ], + "returnType": { + "type": "TypeAnnotation", + "start": 28, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "typeAnnotation": { + "type": "VoidTypeAnnotation", + "start": 29, "end": 33, "loc": { "start": { "line": 1, - "column": 28 + "column": 29 }, "end": { "line": 1, "column": 33 } - }, - "typeAnnotation": { - "type": "VoidTypeAnnotation", - "start": 29, - "end": 33, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 33 - } - } } - }, - "body": { - "type": "BlockStatement", - "start": 33, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 33 - }, - "end": { - "line": 1, - "column": 35 - } - }, - "body": [], - "directives": [] } + }, + "body": { + "type": "BlockStatement", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/22/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/22/expected.json index 2d660b9f77..4725285737 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/22/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/22/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 25, "loc": { @@ -122,71 +122,57 @@ "name": "fooProp" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 14, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "returnType": { + "type": "TypeAnnotation", + "start": 16, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 17, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 23 + } + } + } + }, + "body": { + "type": "BlockStatement", + "start": 23, "end": 25, "loc": { "start": { "line": 1, - "column": 14 + "column": 23 }, "end": { "line": 1, "column": 25 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "returnType": { - "type": "TypeAnnotation", - "start": 16, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "typeAnnotation": { - "type": "NumberTypeAnnotation", - "start": 17, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 23 - } - } - } - }, - "body": { - "type": "BlockStatement", - "start": 23, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 23 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/23/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/23/expected.json index 75457f8544..0eb9320e3c 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/23/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/23/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 20, "loc": { @@ -121,56 +121,58 @@ }, "name": "id" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 8, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 8 + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + } }, - "end": { - "line": 1, - "column": 20 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 9, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 10, "end": 13, "loc": { "start": { "line": 1, - "column": 9 + "column": 10 }, "end": { "line": 1, "column": 13 } }, - "name": "x", "typeAnnotation": { - "type": "TypeAnnotation", - "start": 10, + "type": "GenericTypeAnnotation", + "start": 12, "end": 13, "loc": { "start": { "line": 1, - "column": 10 + "column": 12 }, "end": { "line": 1, "column": 13 } }, - "typeAnnotation": { - "type": "GenericTypeAnnotation", + "typeParameters": null, + "id": { + "type": "Identifier", "start": 12, "end": 13, "loc": { @@ -183,43 +185,43 @@ "column": 13 } }, - "typeParameters": null, - "id": { - "type": "Identifier", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 13 - } - }, - "name": "T" - } + "name": "T" } } } - ], - "returnType": { - "type": "TypeAnnotation", - "start": 14, + } + ], + "returnType": { + "type": "TypeAnnotation", + "start": 14, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 16, "end": 17, "loc": { "start": { "line": 1, - "column": 14 + "column": 16 }, "end": { "line": 1, "column": 17 } }, - "typeAnnotation": { - "type": "GenericTypeAnnotation", + "typeParameters": null, + "id": { + "type": "Identifier", "start": 16, "end": 17, "loc": { @@ -232,75 +234,59 @@ "column": 17 } }, - "typeParameters": null, - "id": { - "type": "Identifier", - "start": 16, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "name": "T" - } + "name": "T" + } + } + }, + "body": { + "type": "BlockStatement", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 } }, - "body": { - "type": "BlockStatement", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 20 - } + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 5, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 5 }, - "body": [], - "directives": [] + "end": { + "line": 1, + "column": 8 + } }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 5, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 5 - }, - "end": { - "line": 1, - "column": 8 - } - }, - "params": [ - { - "type": "Identifier", - "start": 6, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 7 - } + "params": [ + { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 }, - "name": "T" - } - ] - } + "end": { + "line": 1, + "column": 7 + } + }, + "name": "T" + } + ] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/24/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/24/expected.json index 9990d3f183..ef4b2fa15b 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/24/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/24/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 21, "loc": { @@ -121,56 +121,58 @@ }, "name": "id" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 9, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 9 + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } }, - "end": { - "line": 1, - "column": 21 - } - }, - "id": null, - "generator": true, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 10, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 11, "end": 14, "loc": { "start": { "line": 1, - "column": 10 + "column": 11 }, "end": { "line": 1, "column": 14 } }, - "name": "x", "typeAnnotation": { - "type": "TypeAnnotation", - "start": 11, + "type": "GenericTypeAnnotation", + "start": 13, "end": 14, "loc": { "start": { "line": 1, - "column": 11 + "column": 13 }, "end": { "line": 1, "column": 14 } }, - "typeAnnotation": { - "type": "GenericTypeAnnotation", + "typeParameters": null, + "id": { + "type": "Identifier", "start": 13, "end": 14, "loc": { @@ -183,43 +185,43 @@ "column": 14 } }, - "typeParameters": null, - "id": { - "type": "Identifier", - "start": 13, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "name": "T" - } + "name": "T" } } } - ], - "returnType": { - "type": "TypeAnnotation", - "start": 15, + } + ], + "returnType": { + "type": "TypeAnnotation", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 17, "end": 18, "loc": { "start": { "line": 1, - "column": 15 + "column": 17 }, "end": { "line": 1, "column": 18 } }, - "typeAnnotation": { - "type": "GenericTypeAnnotation", + "typeParameters": null, + "id": { + "type": "Identifier", "start": 17, "end": 18, "loc": { @@ -232,75 +234,59 @@ "column": 18 } }, - "typeParameters": null, - "id": { - "type": "Identifier", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "name": "T" - } + "name": "T" + } + } + }, + "body": { + "type": "BlockStatement", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 } }, - "body": { - "type": "BlockStatement", - "start": 19, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 21 - } + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 }, - "body": [], - "directives": [] + "end": { + "line": 1, + "column": 9 + } }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 6, - "end": 9, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 9 - } - }, - "params": [ - { - "type": "Identifier", - "start": 7, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 8 - } + "params": [ + { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 }, - "name": "T" - } - ] - } + "end": { + "line": 1, + "column": 8 + } + }, + "name": "T" + } + ] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/25/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/25/expected.json index 7a1c41ce8a..f651d57f91 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/25/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/25/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 26, "loc": { @@ -121,57 +121,58 @@ }, "name": "id" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 14, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 14 + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": true, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + } }, - "end": { - "line": 1, - "column": 26 - } - }, - "id": null, - "generator": false, - "expression": false, - "async": true, - "params": [ - { - "type": "Identifier", - "start": 15, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 16, "end": 19, "loc": { "start": { "line": 1, - "column": 15 + "column": 16 }, "end": { "line": 1, "column": 19 } }, - "name": "x", "typeAnnotation": { - "type": "TypeAnnotation", - "start": 16, + "type": "GenericTypeAnnotation", + "start": 18, "end": 19, "loc": { "start": { "line": 1, - "column": 16 + "column": 18 }, "end": { "line": 1, "column": 19 } }, - "typeAnnotation": { - "type": "GenericTypeAnnotation", + "typeParameters": null, + "id": { + "type": "Identifier", "start": 18, "end": 19, "loc": { @@ -184,43 +185,43 @@ "column": 19 } }, - "typeParameters": null, - "id": { - "type": "Identifier", - "start": 18, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "name": "T" - } + "name": "T" } } } - ], - "returnType": { - "type": "TypeAnnotation", - "start": 20, + } + ], + "returnType": { + "type": "TypeAnnotation", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 22, "end": 23, "loc": { "start": { "line": 1, - "column": 20 + "column": 22 }, "end": { "line": 1, "column": 23 } }, - "typeAnnotation": { - "type": "GenericTypeAnnotation", + "typeParameters": null, + "id": { + "type": "Identifier", "start": 22, "end": 23, "loc": { @@ -233,81 +234,66 @@ "column": 23 } }, - "typeParameters": null, - "id": { - "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 22 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "name": "T" - } + "name": "T" + } + } + }, + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 26 } }, - "body": { - "type": "BlockStatement", - "start": 24, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 24 - }, - "end": { - "line": 1, - "column": 26 - } + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 11 }, - "body": [] + "end": { + "line": 1, + "column": 14 + } }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 11, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "params": [ - { - "type": "Identifier", - "start": 12, - "end": 13, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 13 - } + "params": [ + { + "type": "Identifier", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 }, - "name": "T" - } - ] - } + "end": { + "line": 1, + "column": 13 + } + }, + "name": "T" + } + ] } } ] } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/flow/type-annotations/26/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/26/expected.json index c59c5c0979..32323b6fb7 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/26/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/26/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 21, "loc": { @@ -125,56 +125,58 @@ }, "value": 123 }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 9, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 9 + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } }, - "end": { - "line": 1, - "column": 21 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 10, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 11, "end": 14, "loc": { "start": { "line": 1, - "column": 10 + "column": 11 }, "end": { "line": 1, "column": 14 } }, - "name": "x", "typeAnnotation": { - "type": "TypeAnnotation", - "start": 11, + "type": "GenericTypeAnnotation", + "start": 13, "end": 14, "loc": { "start": { "line": 1, - "column": 11 + "column": 13 }, "end": { "line": 1, "column": 14 } }, - "typeAnnotation": { - "type": "GenericTypeAnnotation", + "typeParameters": null, + "id": { + "type": "Identifier", "start": 13, "end": 14, "loc": { @@ -187,43 +189,43 @@ "column": 14 } }, - "typeParameters": null, - "id": { - "type": "Identifier", - "start": 13, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "name": "T" - } + "name": "T" } } } - ], - "returnType": { - "type": "TypeAnnotation", - "start": 15, + } + ], + "returnType": { + "type": "TypeAnnotation", + "start": 15, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 17, "end": 18, "loc": { "start": { "line": 1, - "column": 15 + "column": 17 }, "end": { "line": 1, "column": 18 } }, - "typeAnnotation": { - "type": "GenericTypeAnnotation", + "typeParameters": null, + "id": { + "type": "Identifier", "start": 17, "end": 18, "loc": { @@ -236,75 +238,59 @@ "column": 18 } }, - "typeParameters": null, - "id": { - "type": "Identifier", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "name": "T" - } + "name": "T" + } + } + }, + "body": { + "type": "BlockStatement", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 } }, - "body": { - "type": "BlockStatement", - "start": 19, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 21 - } + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 }, - "body": [], - "directives": [] + "end": { + "line": 1, + "column": 9 + } }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 6, - "end": 9, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 9 - } - }, - "params": [ - { - "type": "Identifier", - "start": 7, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 8 - } + "params": [ + { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 }, - "name": "T" - } - ] - } + "end": { + "line": 1, + "column": 8 + } + }, + "name": "T" + } + ] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/27/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/27/expected.json index 7e23e4be3b..71c96e968a 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/27/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/27/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 11, "end": 38, "loc": { @@ -107,88 +107,74 @@ }, "static": false, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 22, - "end": 38, - "loc": { - "start": { - "line": 1, - "column": 22 + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 23, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 35 + } }, - "end": { - "line": 1, - "column": 38 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 23, + "name": "value", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 28, "end": 35, "loc": { "start": { "line": 1, - "column": 23 + "column": 28 }, "end": { "line": 1, "column": 35 } }, - "name": "value", "typeAnnotation": { - "type": "TypeAnnotation", - "start": 28, + "type": "NumberTypeAnnotation", + "start": 29, "end": 35, "loc": { "start": { "line": 1, - "column": 28 + "column": 29 }, "end": { "line": 1, "column": 35 } - }, - "typeAnnotation": { - "type": "NumberTypeAnnotation", - "start": 29, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 35 - } - } } } } - ], - "body": { - "type": "BlockStatement", - "start": 36, - "end": 38, - "loc": { - "start": { - "line": 1, - "column": 36 - }, - "end": { - "line": 1, - "column": 38 - } - }, - "body": [], - "directives": [] } + ], + "body": { + "type": "BlockStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/28/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/28/expected.json index 23a7b26c0b..ba9b916990 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/28/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/28/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 11, "end": 43, "loc": { @@ -107,118 +107,104 @@ }, "static": false, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 22, - "end": 43, - "loc": { - "start": { - "line": 1, - "column": 22 + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 23, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 35 + } }, - "end": { - "line": 1, - "column": 43 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 23, + "name": "value", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 28, "end": 35, "loc": { "start": { "line": 1, - "column": 23 + "column": 28 }, "end": { "line": 1, "column": 35 } }, - "name": "value", "typeAnnotation": { - "type": "TypeAnnotation", - "start": 28, + "type": "NumberTypeAnnotation", + "start": 29, "end": 35, "loc": { "start": { "line": 1, - "column": 28 + "column": 29 }, "end": { "line": 1, "column": 35 } - }, - "typeAnnotation": { - "type": "NumberTypeAnnotation", - "start": 29, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 35 - } - } } } } - ], - "returnType": { - "type": "TypeAnnotation", - "start": 36, + } + ], + "returnType": { + "type": "TypeAnnotation", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "typeAnnotation": { + "type": "VoidTypeAnnotation", + "start": 37, "end": 41, "loc": { "start": { "line": 1, - "column": 36 + "column": 37 }, "end": { "line": 1, "column": 41 } - }, - "typeAnnotation": { - "type": "VoidTypeAnnotation", - "start": 37, - "end": 41, - "loc": { - "start": { - "line": 1, - "column": 37 - }, - "end": { - "line": 1, - "column": 41 - } - } } - }, - "body": { - "type": "BlockStatement", - "start": 41, - "end": 43, - "loc": { - "start": { - "line": 1, - "column": 41 - }, - "end": { - "line": 1, - "column": 43 - } - }, - "body": [], - "directives": [] } + }, + "body": { + "type": "BlockStatement", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/29/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/29/expected.json index 69dab292da..b675422aca 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/29/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/29/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 11, "end": 33, "loc": { @@ -107,71 +107,57 @@ }, "static": false, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 22, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "returnType": { + "type": "TypeAnnotation", + "start": 24, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 25, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 31 + } + } + } + }, + "body": { + "type": "BlockStatement", + "start": 31, "end": 33, "loc": { "start": { "line": 1, - "column": 22 + "column": 31 }, "end": { "line": 1, "column": 33 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "returnType": { - "type": "TypeAnnotation", - "start": 24, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 24 - }, - "end": { - "line": 1, - "column": 31 - } - }, - "typeAnnotation": { - "type": "NumberTypeAnnotation", - "start": 25, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 31 - } - } - } - }, - "body": { - "type": "BlockStatement", - "start": 31, - "end": 33, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 33 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/50/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/50/expected.json index 84759bfbc6..836b93e825 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/50/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/50/expected.json @@ -108,7 +108,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 15, "end": 45, "loc": { @@ -140,140 +140,126 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 21, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 18, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "name": "U" + } + ] + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "returnType": { + "type": "TypeAnnotation", + "start": 23, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 30 + } + } + } + }, + "body": { + "type": "BlockStatement", + "start": 31, "end": 45, "loc": { "start": { "line": 1, - "column": 21 + "column": 31 }, "end": { "line": 1, "column": 45 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "returnType": { - "type": "TypeAnnotation", - "start": 23, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 23 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "typeAnnotation": { - "type": "NumberTypeAnnotation", - "start": 24, - "end": 30, + "body": [ + { + "type": "ReturnStatement", + "start": 33, + "end": 43, "loc": { "start": { "line": 1, - "column": 24 + "column": 33 }, "end": { "line": 1, - "column": 30 + "column": 43 } + }, + "argument": { + "type": "NumberLiteral", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 } } - }, - "body": { - "type": "BlockStatement", - "start": 31, - "end": 45, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 45 - } - }, - "body": [ - { - "type": "ReturnStatement", - "start": 33, - "end": 43, - "loc": { - "start": { - "line": 1, - "column": 33 - }, - "end": { - "line": 1, - "column": 43 - } - }, - "argument": { - "type": "NumberLiteral", - "start": 40, - "end": 42, - "loc": { - "start": { - "line": 1, - "column": 40 - }, - "end": { - "line": 1, - "column": 42 - } - }, - "extra": { - "rawValue": 42, - "raw": "42" - }, - "value": 42 - } - } - ], - "directives": [] - }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 18, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 21 - } - }, - "params": [ - { - "type": "Identifier", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "name": "U" - } - ] - } + ], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/51/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/51/expected.json index be9240f72e..225c2d3596 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/51/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/51/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 12, "end": 26, "loc": { @@ -111,74 +111,60 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 20, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "params": [ + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, "end": 26, "loc": { "start": { "line": 1, - "column": 20 + "column": 23 }, "end": { "line": 1, "column": 26 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 23, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 23 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "body": [], - "directives": [] - }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 17, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "params": [ - { - "type": "Identifier", - "start": 18, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "name": "T" - } - ] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/56/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/56/expected.json index ac710d4778..91bd2b0584 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/56/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/56/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 14, "end": 46, "loc": { @@ -107,120 +107,106 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 20, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 20 + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 21, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 42 + } }, - "end": { - "line": 1, - "column": 46 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 21, + "name": "items", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 26, "end": 42, "loc": { "start": { "line": 1, - "column": 21 + "column": 26 }, "end": { "line": 1, "column": 42 } }, - "name": "items", "typeAnnotation": { - "type": "TypeAnnotation", - "start": 26, + "type": "UnionTypeAnnotation", + "start": 27, "end": 42, "loc": { "start": { "line": 1, - "column": 26 + "column": 27 }, "end": { "line": 1, "column": 42 } }, - "typeAnnotation": { - "type": "UnionTypeAnnotation", - "start": 27, - "end": 42, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 42 + "types": [ + { + "type": "NumberTypeAnnotation", + "start": 27, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 33 + } } }, - "types": [ - { - "type": "NumberTypeAnnotation", - "start": 27, - "end": 33, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 33 - } - } - }, - { - "type": "StringTypeAnnotation", - "start": 36, - "end": 42, - "loc": { - "start": { - "line": 1, - "column": 36 - }, - "end": { - "line": 1, - "column": 42 - } + { + "type": "StringTypeAnnotation", + "start": 36, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 42 } } - ] - } + } + ] } } - ], - "body": { - "type": "BlockStatement", - "start": 44, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 44 - }, - "end": { - "line": 1, - "column": 46 - } - }, - "body": [], - "directives": [] } + ], + "body": { + "type": "BlockStatement", + "start": 44, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/flow/type-annotations/60/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/60/expected.json index 69d4f65178..a2db556539 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/60/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/60/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 6, "loc": { @@ -105,7 +105,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, @@ -222,7 +221,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 27, "end": 37, "loc": { @@ -273,8 +272,7 @@ "raw": "\"hello\"" }, "value": "hello" - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/flow/type-annotations/61/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/61/expected.json index c09b9c0fec..b4cdb54e7d 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/61/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/61/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 6, "loc": { @@ -105,7 +105,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, @@ -222,7 +221,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 26, "end": 36, "loc": { @@ -273,8 +272,7 @@ "raw": "\"hello\"" }, "value": "hello" - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/flow/type-annotations/63/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/63/expected.json index c67a31a154..55cd213628 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/63/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/63/expected.json @@ -60,6 +60,7 @@ }, "generator": false, "expression": false, + "async": false, "params": [ { "type": "ObjectPattern", @@ -77,7 +78,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 14, "end": 15, "loc": { @@ -109,7 +110,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 14, diff --git a/packages/babylon/test/fixtures/flow/type-annotations/97/expected.json b/packages/babylon/test/fixtures/flow/type-annotations/97/expected.json index ad6352b9a0..b6a11dc752 100644 --- a/packages/babylon/test/fixtures/flow/type-annotations/97/expected.json +++ b/packages/babylon/test/fixtures/flow/type-annotations/97/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 22, "loc": { @@ -107,6 +107,7 @@ "id": null, "generator": false, "expression": false, + "async": false, "typeParameters": { "type": "TypeParameterDeclaration", "start": 14, @@ -158,8 +159,7 @@ "body": [], "directives": [] } - }, - "kind": "init" + } } ], "extra": { diff --git a/packages/babylon/test/fixtures/flow/typecasts/2/expected.json b/packages/babylon/test/fixtures/flow/typecasts/2/expected.json index 48639097eb..79b652ae59 100644 --- a/packages/babylon/test/fixtures/flow/typecasts/2/expected.json +++ b/packages/babylon/test/fixtures/flow/typecasts/2/expected.json @@ -72,7 +72,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 8, "loc": { @@ -123,11 +123,10 @@ "raw": "0" }, "value": 0 - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 10, "end": 20, "loc": { @@ -178,8 +177,7 @@ "raw": "\"hey\"" }, "value": "hey" - }, - "kind": "init" + } } ] }, diff --git a/packages/babylon/test/fixtures/harmony/computed-properties/call-expression/expected.json b/packages/babylon/test/fixtures/harmony/computed-properties/call-expression/expected.json index df195bb3a8..6a6f627eec 100644 --- a/packages/babylon/test/fixtures/harmony/computed-properties/call-expression/expected.json +++ b/packages/babylon/test/fixtures/harmony/computed-properties/call-expression/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 14, "end": 25, "loc": { @@ -156,8 +156,7 @@ "raw": "\"\"" }, "value": "" - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/191/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/.191/actual.js similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/191/actual.js rename to packages/babylon/test/fixtures/harmony/uncategorised/.191/actual.js diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/191/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/.191/expected.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/191/expected.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.191/expected.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/260/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/.260/actual.js similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/260/actual.js rename to packages/babylon/test/fixtures/harmony/uncategorised/.260/actual.js diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/260/options.json b/packages/babylon/test/fixtures/harmony/uncategorised/.260/options.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/260/options.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.260/options.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/335/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/.335/actual.js similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/335/actual.js rename to packages/babylon/test/fixtures/harmony/uncategorised/.335/actual.js diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/335/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/.335/expected.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/335/expected.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.335/expected.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/335/options.json b/packages/babylon/test/fixtures/harmony/uncategorised/.335/options.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/335/options.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.335/options.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/343/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/.343/actual.js similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/343/actual.js rename to packages/babylon/test/fixtures/harmony/uncategorised/.343/actual.js diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/343/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/.343/expected.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/343/expected.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.343/expected.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/343/options.json b/packages/babylon/test/fixtures/harmony/uncategorised/.343/options.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/343/options.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.343/options.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/345/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/.345/actual.js similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/345/actual.js rename to packages/babylon/test/fixtures/harmony/uncategorised/.345/actual.js diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/345/options.json b/packages/babylon/test/fixtures/harmony/uncategorised/.345/options.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/345/options.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.345/options.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/346/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/.346/actual.js similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/346/actual.js rename to packages/babylon/test/fixtures/harmony/uncategorised/.346/actual.js diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/346/options.json b/packages/babylon/test/fixtures/harmony/uncategorised/.346/options.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/346/options.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.346/options.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/348/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/.348/actual.js similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/348/actual.js rename to packages/babylon/test/fixtures/harmony/uncategorised/.348/actual.js diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/.348/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/.348/expected.json new file mode 100644 index 0000000000..a90d6d7108 --- /dev/null +++ b/packages/babylon/test/fixtures/harmony/uncategorised/.348/expected.json @@ -0,0 +1,177 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 1, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "__proto__" + }, + "value": { + "type": "NumberLiteral", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ObjectProperty", + "start": 17, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 17, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": "__proto__" + }, + "value": { + "type": "NumberLiteral", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ], + "extra": { + "parenthesized": true + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/348/options.json b/packages/babylon/test/fixtures/harmony/uncategorised/.348/options.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/348/options.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.348/options.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/349/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/.349/actual.js similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/349/actual.js rename to packages/babylon/test/fixtures/harmony/uncategorised/.349/actual.js diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/349/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/.349/expected.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/349/expected.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.349/expected.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/349/options.json b/packages/babylon/test/fixtures/harmony/uncategorised/.349/options.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/349/options.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.349/options.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/353/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/.353/actual.js similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/353/actual.js rename to packages/babylon/test/fixtures/harmony/uncategorised/.353/actual.js diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/353/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/.353/expected.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/353/expected.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.353/expected.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/353/options.json b/packages/babylon/test/fixtures/harmony/uncategorised/.353/options.json similarity index 100% rename from packages/babylon/test/fixtures/harmony/uncategorised/353/options.json rename to packages/babylon/test/fixtures/harmony/uncategorised/.353/options.json diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/103/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/103/expected.json index 609ce0d37a..1397cc5c38 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/103/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/103/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 10, "end": 31, "loc": { @@ -121,42 +121,42 @@ }, "name": "test" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 16, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 19, "end": 31, "loc": { "start": { "line": 1, - "column": 16 + "column": 19 }, "end": { "line": 1, "column": 31 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 19 + "body": [ + { + "type": "ExpressionStatement", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 29 + } }, - "end": { - "line": 1, - "column": 31 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "YieldExpression", "start": 21, "end": 29, "loc": { @@ -169,41 +169,27 @@ "column": 29 } }, - "expression": { - "type": "YieldExpression", - "start": 21, + "delegate": true, + "argument": { + "type": "Identifier", + "start": 28, "end": 29, "loc": { "start": { "line": 1, - "column": 21 + "column": 28 }, "end": { "line": 1, "column": 29 } }, - "delegate": true, - "argument": { - "type": "Identifier", - "start": 28, - "end": 29, - "loc": { - "start": { - "line": 1, - "column": 28 - }, - "end": { - "line": 1, - "column": 29 - } - }, - "name": "v" - } + "name": "v" } } - ] - } + } + ], + "directives": [] } } ] @@ -212,7 +198,7 @@ ], "kind": "var" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/113/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/113/expected.json index 937612426b..d5b033e029 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/113/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/113/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 17, "loc": { @@ -107,46 +107,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 12, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, "end": 17, "loc": { "start": { "line": 1, - "column": 12 + "column": 15 }, "end": { "line": 1, "column": 17 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 15, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/114/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/114/expected.json index 2161c2d0ee..6601d59d6d 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/114/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/114/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 25, "loc": { @@ -107,46 +107,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 20, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, "end": 25, "loc": { "start": { "line": 1, - "column": 20 + "column": 23 }, "end": { "line": 1, "column": 25 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 23, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 23 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/115/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/115/expected.json index 9b6a05da2a..75c400a2a7 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/115/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/115/expected.json @@ -90,7 +90,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 19, "end": 31, "loc": { @@ -122,46 +122,32 @@ }, "static": false, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 26, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 29, "end": 31, "loc": { "start": { "line": 1, - "column": 26 + "column": 29 }, "end": { "line": 1, "column": 31 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 29, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 31 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/116/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/116/expected.json index 787e636554..c3fa277a2f 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/116/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/116/expected.json @@ -90,7 +90,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 20, "end": 39, "loc": { @@ -122,46 +122,32 @@ }, "static": true, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 34, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 37, "end": 39, "loc": { "start": { "line": 1, - "column": 34 + "column": 37 }, "end": { "line": 1, "column": 39 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 37, - "end": 39, - "loc": { - "start": { - "line": 1, - "column": 37 - }, - "end": { - "line": 1, - "column": 39 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/117/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/117/expected.json index 0a4f8836f9..d607a58aad 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/117/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/117/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 20, "loc": { @@ -107,63 +107,49 @@ }, "static": false, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 14, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 18, "end": 20, "loc": { "start": { "line": 1, - "column": 14 + "column": 18 }, "end": { "line": 1, "column": 20 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 15, - "end": 16, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 16 - } - }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/118/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/118/expected.json index 58a55c8a4c..54e7adf346 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/118/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/118/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 28, "loc": { @@ -107,63 +107,49 @@ }, "static": true, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 22, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 26, "end": 28, "loc": { "start": { "line": 1, - "column": 22 + "column": 26 }, "end": { "line": 1, "column": 28 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 23, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 23 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 26, - "end": 28, - "loc": { - "start": { - "line": 1, - "column": 26 - }, - "end": { - "line": 1, - "column": 28 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/119/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/119/expected.json index e8659d9d1a..e47c5c6942 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/119/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/119/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 18, "loc": { @@ -107,63 +107,49 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 12, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 16, "end": 18, "loc": { "start": { "line": 1, - "column": 12 + "column": 16 }, "end": { "line": 1, "column": 18 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 13, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 16, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/120/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/120/expected.json index 4cbc7e1ce5..873df88c9f 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/120/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/120/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 26, "loc": { @@ -107,63 +107,49 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 20, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 21, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 24, "end": 26, "loc": { "start": { "line": 1, - "column": 20 + "column": 24 }, "end": { "line": 1, "column": 26 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 21, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 24, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 24 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/121/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/121/expected.json index ae61f95fb4..f1e8a83082 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/121/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/121/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 29, "loc": { @@ -107,60 +107,60 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 13, + "id": null, + "generator": true, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 17, "end": 29, "loc": { "start": { "line": 1, - "column": 13 + "column": 17 }, "end": { "line": 1, "column": 29 } }, - "id": null, - "generator": true, - "expression": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 14, - "end": 15, + "type": "ExpressionStatement", + "start": 19, + "end": 27, "loc": { "start": { "line": 1, - "column": 14 + "column": 19 }, "end": { "line": 1, - "column": 15 + "column": 27 } }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 29, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 29 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "YieldExpression", "start": 19, - "end": 27, + "end": 26, "loc": { "start": { "line": 1, @@ -168,50 +168,36 @@ }, "end": { "line": 1, - "column": 27 + "column": 26 } }, - "expression": { - "type": "YieldExpression", - "start": 19, + "delegate": false, + "argument": { + "type": "Identifier", + "start": 25, "end": 26, "loc": { "start": { "line": 1, - "column": 19 + "column": 25 }, "end": { "line": 1, "column": 26 } }, - "delegate": false, - "argument": { - "type": "Identifier", - "start": 25, - "end": 26, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 26 - } - }, - "name": "v" - } + "name": "v" } } - ] - } + } + ], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/122/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/122/expected.json index 305a0a44a9..0c6728f1b8 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/122/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/122/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 37, "loc": { @@ -107,60 +107,60 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 21, + "id": null, + "generator": true, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 25, "end": 37, "loc": { "start": { "line": 1, - "column": 21 + "column": 25 }, "end": { "line": 1, "column": 37 } }, - "id": null, - "generator": true, - "expression": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 22, - "end": 23, + "type": "ExpressionStatement", + "start": 27, + "end": 35, "loc": { "start": { "line": 1, - "column": 22 + "column": 27 }, "end": { "line": 1, - "column": 23 + "column": 35 } }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 25, - "end": 37, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 37 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "YieldExpression", "start": 27, - "end": 35, + "end": 34, "loc": { "start": { "line": 1, @@ -168,50 +168,36 @@ }, "end": { "line": 1, - "column": 35 + "column": 34 } }, - "expression": { - "type": "YieldExpression", - "start": 27, + "delegate": false, + "argument": { + "type": "Identifier", + "start": 33, "end": 34, "loc": { "start": { "line": 1, - "column": 27 + "column": 33 }, "end": { "line": 1, "column": 34 } }, - "delegate": false, - "argument": { - "type": "Identifier", - "start": 33, - "end": 34, - "loc": { - "start": { - "line": 1, - "column": 33 - }, - "end": { - "line": 1, - "column": 34 - } - }, - "name": "v" - } + "name": "v" } } - ] - } + } + ], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/123/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/123/expected.json index 83a2d03682..2b8ddddaf7 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/123/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/123/expected.json @@ -89,7 +89,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 24, "end": 49, "loc": { @@ -121,41 +121,41 @@ }, "static": false, "kind": "constructor", - "value": { - "type": "FunctionExpression", - "start": 35, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 38, "end": 49, "loc": { "start": { "line": 1, - "column": 35 + "column": 38 }, "end": { "line": 1, "column": 49 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 38, - "end": 49, - "loc": { - "start": { - "line": 1, - "column": 38 + "body": [ + { + "type": "ExpressionStatement", + "start": 40, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 47 + } }, - "end": { - "line": 1, - "column": 49 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", "start": 40, "end": 47, "loc": { @@ -168,10 +168,10 @@ "column": 47 } }, - "expression": { - "type": "CallExpression", + "callee": { + "type": "Super", "start": 40, - "end": 47, + "end": 45, "loc": { "start": { "line": 1, @@ -179,30 +179,15 @@ }, "end": { "line": 1, - "column": 47 + "column": 45 } - }, - "callee": { - "type": "Super", - "start": 40, - "end": 45, - "loc": { - "start": { - "line": 1, - "column": 40 - }, - "end": { - "line": 1, - "column": 45 - } - } - }, - "arguments": [] - } + } + }, + "arguments": [] } - ], - "directives": [] - } + } + ], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/124/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/124/expected.json index b3af6621a1..7c01cad6f1 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/124/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/124/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 27, "loc": { @@ -111,41 +111,26 @@ }, "static": false, "kind": "constructor", - "value": { - "type": "FunctionExpression", - "start": 22, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, "end": 27, "loc": { "start": { "line": 1, - "column": 22 + "column": 25 }, "end": { "line": 1, "column": 27 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 25, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 27 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/128/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/128/expected.json index fe353f8bba..937272b468 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/128/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/128/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 24, "loc": { @@ -107,46 +107,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 19, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 22, "end": 24, "loc": { "start": { "line": 1, - "column": 19 + "column": 22 }, "end": { "line": 1, "column": 24 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 22, - "end": 24, - "loc": { - "start": { - "line": 1, - "column": 22 - }, - "end": { - "line": 1, - "column": 24 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/129/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/129/expected.json index 6e71914af1..bb30c8aa84 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/129/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/129/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 17, "loc": { @@ -107,44 +107,30 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 12, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, "end": 17, "loc": { "start": { "line": 1, - "column": 12 + "column": 15 }, "end": { "line": 1, "column": 17 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 15, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 18, "end": 33, "loc": { @@ -176,46 +162,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 28, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 31, "end": 33, "loc": { "start": { "line": 1, - "column": 28 + "column": 31 }, "end": { "line": 1, "column": 33 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 31, - "end": 33, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 33 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/130/actual.js b/packages/babylon/test/fixtures/harmony/uncategorised/130/actual.js deleted file mode 100644 index 42108ece49..0000000000 --- a/packages/babylon/test/fixtures/harmony/uncategorised/130/actual.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; (class A { static constructor() { super() }}) \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/130/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/130/expected.json deleted file mode 100644 index 19d9b17be0..0000000000 --- a/packages/babylon/test/fixtures/harmony/uncategorised/130/expected.json +++ /dev/null @@ -1,254 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 59, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 59 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 59, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 59 - } - }, - "sourceType": "script", - "body": [ - { - "type": "ExpressionStatement", - "start": 14, - "end": 59, - "loc": { - "start": { - "line": 1, - "column": 14 - }, - "end": { - "line": 1, - "column": 59 - } - }, - "expression": { - "type": "ClassExpression", - "start": 15, - "end": 58, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 58 - } - }, - "id": { - "type": "Identifier", - "start": 21, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "name": "A" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 23, - "end": 58, - "loc": { - "start": { - "line": 1, - "column": 23 - }, - "end": { - "line": 1, - "column": 58 - } - }, - "body": [ - { - "type": "MethodDefinition", - "start": 25, - "end": 57, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 57 - } - }, - "computed": false, - "key": { - "type": "Identifier", - "start": 32, - "end": 43, - "loc": { - "start": { - "line": 1, - "column": 32 - }, - "end": { - "line": 1, - "column": 43 - } - }, - "name": "constructor" - }, - "static": true, - "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 43, - "end": 57, - "loc": { - "start": { - "line": 1, - "column": 43 - }, - "end": { - "line": 1, - "column": 57 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 46, - "end": 57, - "loc": { - "start": { - "line": 1, - "column": 46 - }, - "end": { - "line": 1, - "column": 57 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 48, - "end": 55, - "loc": { - "start": { - "line": 1, - "column": 48 - }, - "end": { - "line": 1, - "column": 55 - } - }, - "expression": { - "type": "CallExpression", - "start": 48, - "end": 55, - "loc": { - "start": { - "line": 1, - "column": 48 - }, - "end": { - "line": 1, - "column": 55 - } - }, - "callee": { - "type": "Super", - "start": 48, - "end": 53, - "loc": { - "start": { - "line": 1, - "column": 48 - }, - "end": { - "line": 1, - "column": 53 - } - } - }, - "arguments": [] - } - } - ], - "directives": [] - } - } - } - ] - }, - "extra": { - "parenthesized": true - } - } - } - ], - "directives": [ - { - "type": "Directive", - "start": 0, - "end": 13, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 13 - } - }, - "value": { - "type": "DirectiveLiteral", - "start": 0, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "value": "use strict", - "extra": { - "raw": "\"use strict\"", - "rawValue": "use strict" - } - } - } - ] - } -} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/131/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/131/expected.json index ee42e3d61e..8c38e200c5 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/131/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/131/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 18, "loc": { @@ -107,44 +107,30 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 13, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 16, "end": 18, "loc": { "start": { "line": 1, - "column": 13 + "column": 16 }, "end": { "line": 1, "column": 18 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 16, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 19, "end": 27, "loc": { @@ -176,46 +162,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 22, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, "end": 27, "loc": { "start": { "line": 1, - "column": 22 + "column": 25 }, "end": { "line": 1, "column": 27 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 25, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 27 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/132/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/132/expected.json index 1cdc2db117..7468edee54 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/132/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/132/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 22, "loc": { @@ -107,44 +107,30 @@ }, "static": false, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 17, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, "end": 22, "loc": { "start": { "line": 1, - "column": 17 + "column": 20 }, "end": { "line": 1, "column": 22 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 23, "end": 36, "loc": { @@ -176,63 +162,49 @@ }, "static": false, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 30, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 34, "end": 36, "loc": { "start": { "line": 1, - "column": 30 + "column": 34 }, "end": { "line": 1, "column": 36 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 31, - "end": 32, - "loc": { - "start": { - "line": 1, - "column": 31 - }, - "end": { - "line": 1, - "column": 32 - } - }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 34, - "end": 36, - "loc": { - "start": { - "line": 1, - "column": 34 - }, - "end": { - "line": 1, - "column": 36 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/133/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/133/expected.json index 5c02d2eecd..7e8a2075c5 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/133/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/133/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 29, "loc": { @@ -107,44 +107,30 @@ }, "static": true, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 24, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 27, "end": 29, "loc": { "start": { "line": 1, - "column": 24 + "column": 27 }, "end": { "line": 1, "column": 29 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 27, - "end": 29, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 29 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 30, "end": 42, "loc": { @@ -176,46 +162,32 @@ }, "static": false, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 37, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 40, "end": 42, "loc": { "start": { "line": 1, - "column": 37 + "column": 40 }, "end": { "line": 1, "column": 42 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 40, - "end": 42, - "loc": { - "start": { - "line": 1, - "column": 40 - }, - "end": { - "line": 1, - "column": 42 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/134/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/134/expected.json index 7254b30243..d81ed33228 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/134/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/134/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 29, "loc": { @@ -107,44 +107,30 @@ }, "static": true, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 24, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 27, "end": 29, "loc": { "start": { "line": 1, - "column": 24 + "column": 27 }, "end": { "line": 1, "column": 29 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 27, - "end": 29, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 29 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 30, "end": 49, "loc": { @@ -176,46 +162,32 @@ }, "static": true, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 44, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 47, "end": 49, "loc": { "start": { "line": 1, - "column": 44 + "column": 47 }, "end": { "line": 1, "column": 49 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 47, - "end": 49, - "loc": { - "start": { - "line": 1, - "column": 47 - }, - "end": { - "line": 1, - "column": 49 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/135/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/135/expected.json index 0b1130de7c..834c4dccf7 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/135/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/135/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 29, "loc": { @@ -107,44 +107,30 @@ }, "static": true, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 24, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 27, "end": 29, "loc": { "start": { "line": 1, - "column": 24 + "column": 27 }, "end": { "line": 1, "column": 29 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 27, - "end": 29, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 29 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 30, "end": 50, "loc": { @@ -176,61 +162,47 @@ }, "static": true, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 44, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 48, "end": 50, "loc": { "start": { "line": 1, - "column": 44 + "column": 48 }, "end": { "line": 1, "column": 50 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 45, - "end": 46, - "loc": { - "start": { - "line": 1, - "column": 45 - }, - "end": { - "line": 1, - "column": 46 - } - }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 48, - "end": 50, - "loc": { - "start": { - "line": 1, - "column": 48 - }, - "end": { - "line": 1, - "column": 50 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 51, "end": 63, "loc": { @@ -262,44 +234,30 @@ }, "static": false, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 58, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 61, "end": 63, "loc": { "start": { "line": 1, - "column": 58 + "column": 61 }, "end": { "line": 1, "column": 63 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 61, - "end": 63, - "loc": { - "start": { - "line": 1, - "column": 61 - }, - "end": { - "line": 1, - "column": 63 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 64, "end": 77, "loc": { @@ -331,63 +289,49 @@ }, "static": false, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 71, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 72, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 72 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 75, "end": 77, "loc": { "start": { "line": 1, - "column": 71 + "column": 75 }, "end": { "line": 1, "column": 77 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 72, - "end": 73, - "loc": { - "start": { - "line": 1, - "column": 72 - }, - "end": { - "line": 1, - "column": 73 - } - }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 75, - "end": 77, - "loc": { - "start": { - "line": 1, - "column": 75 - }, - "end": { - "line": 1, - "column": 77 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/136/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/136/expected.json index 2e0cf52943..22216e8a4d 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/136/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/136/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 27, "loc": { @@ -107,46 +107,32 @@ }, "static": true, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 22, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, "end": 27, "loc": { "start": { "line": 1, - "column": 22 + "column": 25 }, "end": { "line": 1, "column": 27 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 25, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 27 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/137/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/137/expected.json index 81860c95fb..379914b948 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/137/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/137/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 31, "loc": { @@ -107,46 +107,32 @@ }, "static": true, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 26, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 29, "end": 31, "loc": { "start": { "line": 1, - "column": 26 + "column": 29 }, "end": { "line": 1, "column": 31 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 29, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 31 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/138/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/138/expected.json index dec1437174..36e95c1207 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/138/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/138/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 23, "loc": { @@ -107,61 +107,47 @@ }, "static": false, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 17, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 21, "end": 23, "loc": { "start": { "line": 1, - "column": 17 + "column": 21 }, "end": { "line": 1, "column": 23 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 18, - "end": 19, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 19 - } - }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 21 - }, - "end": { - "line": 1, - "column": 23 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 24, "end": 36, "loc": { @@ -193,46 +179,32 @@ }, "static": false, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 31, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 34, "end": 36, "loc": { "start": { "line": 1, - "column": 31 + "column": 34 }, "end": { "line": 1, "column": 36 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 34, - "end": 36, - "loc": { - "start": { - "line": 1, - "column": 34 - }, - "end": { - "line": 1, - "column": 36 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/139/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/139/expected.json index bde2d7b1d9..ada61eb661 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/139/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/139/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 18, "loc": { @@ -107,44 +107,30 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 13, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 16, "end": 18, "loc": { "start": { "line": 1, - "column": 13 + "column": 16 }, "end": { "line": 1, "column": 18 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 16, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 16 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "body": [] - } + "body": [], + "directives": [] } }, { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 19, "end": 31, "loc": { @@ -176,46 +162,32 @@ }, "static": false, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 26, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 29, "end": 31, "loc": { "start": { "line": 1, - "column": 26 + "column": 29 }, "end": { "line": 1, "column": 31 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 29, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 29 - }, - "end": { - "line": 1, - "column": 31 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/141/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/141/expected.json index 9c4ce67855..fe8be3d209 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/141/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/141/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 9, "loc": { @@ -109,8 +109,7 @@ "raw": "10" }, "value": 10 - }, - "kind": "init" + } } ], "extra": { diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/142/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/142/expected.json index 6198ec9aa5..83f683e3eb 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/142/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/142/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 17, "loc": { @@ -149,8 +149,7 @@ "raw": "10" }, "value": 10 - }, - "kind": "init" + } } ], "extra": { diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/143/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/143/expected.json index 01caab9e66..cc0ab8afc8 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/143/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/143/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 20, "loc": { @@ -125,8 +125,7 @@ "body": [], "directives": [] } - }, - "kind": "init" + } } ], "extra": { diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/144/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/144/expected.json index 25f8cb97cc..c054f5cc59 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/144/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/144/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 9, "loc": { @@ -109,11 +109,10 @@ "raw": "10" }, "value": 10 - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 11, "end": 16, "loc": { @@ -164,8 +163,7 @@ "raw": "20" }, "value": 20 - }, - "kind": "init" + } } ], "extra": { diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/145/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/145/expected.json index 89a62e0093..c87f359ecb 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/145/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/145/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 2, "end": 14, "loc": { @@ -91,45 +91,30 @@ "name": "x" }, "kind": "get", - "value": { - "type": "FunctionExpression", - "start": 9, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 14, "loc": { "start": { "line": 1, - "column": 9 + "column": 12 }, "end": { "line": 1, "column": 14 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 14 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } }, { - "type": "Property", + "type": "ObjectMethod", "start": 16, "end": 29, "loc": { @@ -162,58 +147,43 @@ "name": "x" }, "kind": "set", - "value": { - "type": "FunctionExpression", - "start": 23, + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "name": "v" + } + ], + "body": { + "type": "BlockStatement", + "start": 27, "end": 29, "loc": { "start": { "line": 1, - "column": 23 + "column": 27 }, "end": { "line": 1, "column": 29 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 24, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 24 - }, - "end": { - "line": 1, - "column": 25 - } - }, - "name": "v" - } - ], - "body": { - "type": "BlockStatement", - "start": 27, - "end": 29, - "loc": { - "start": { - "line": 1, - "column": 27 - }, - "end": { - "line": 1, - "column": 29 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/146/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/146/expected.json index 68e454ca7f..8ab9dd27fd 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/146/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/146/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 2, "end": 10, "loc": { @@ -90,42 +90,27 @@ }, "name": "x" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 5, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 8, "end": 10, "loc": { "start": { "line": 1, - "column": 5 + "column": 8 }, "end": { "line": 1, "column": 10 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 8, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 1, - "column": 10 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/147/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/147/expected.json index f4966b1c1f..e9263cf600 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/147/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/147/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 11, "loc": { @@ -120,8 +120,7 @@ } }, "name": "y" - }, - "kind": "init" + } } ] }, @@ -141,7 +140,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 16, "end": 17, "loc": { @@ -173,7 +172,6 @@ }, "name": "y" }, - "kind": "init", "value": { "type": "Identifier", "start": 16, @@ -197,7 +195,7 @@ ], "kind": "var" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/148/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/148/expected.json index 35f50da821..c2c6fcf107 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/148/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/148/expected.json @@ -77,7 +77,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 12, "end": 18, "loc": { @@ -124,8 +124,7 @@ } }, "name": "y" - }, - "kind": "init" + } } ] } @@ -144,10 +143,11 @@ "column": 23 } }, - "body": [] + "body": [], + "directives": [] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/149/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/149/expected.json index 622622b2ef..2b533c4b95 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/149/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/149/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 9, "end": 32, "loc": { @@ -121,44 +121,44 @@ }, "name": "test" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 16, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 19, "end": 32, "loc": { "start": { "line": 1, - "column": 16 + "column": 19 }, "end": { "line": 1, "column": 32 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 32, - "loc": { - "start": { - "line": 1, - "column": 19 + "body": [ + { + "type": "ExpressionStatement", + "start": 21, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 30 + } }, - "end": { - "line": 1, - "column": 32 - } - }, - "body": [ - { - "type": "ExpressionStatement", + "expression": { + "type": "YieldExpression", "start": 21, - "end": 30, + "end": 29, "loc": { "start": { "line": 1, @@ -166,44 +166,30 @@ }, "end": { "line": 1, - "column": 30 + "column": 29 } }, - "expression": { - "type": "YieldExpression", - "start": 21, + "delegate": true, + "argument": { + "type": "Identifier", + "start": 28, "end": 29, "loc": { "start": { "line": 1, - "column": 21 + "column": 28 }, "end": { "line": 1, "column": 29 } }, - "delegate": true, - "argument": { - "type": "Identifier", - "start": 28, - "end": 29, - "loc": { - "start": { - "line": 1, - "column": 28 - }, - "end": { - "line": 1, - "column": 29 - } - }, - "name": "v" - } + "name": "v" } } - ] - } + } + ], + "directives": [] } } ] @@ -212,7 +198,7 @@ ], "kind": "var" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/150/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/150/expected.json index 8e36dcc558..77889bf067 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/150/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/150/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 9, "end": 17, "loc": { @@ -107,46 +107,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 12, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, "end": 17, "loc": { "start": { "line": 1, - "column": 12 + "column": 15 }, "end": { "line": 1, "column": 17 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 15, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/153/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/153/expected.json index 5830686c0b..898db20cdc 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/153/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/153/expected.json @@ -91,7 +91,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 12, "end": 13, "loc": { @@ -123,7 +123,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 12, @@ -159,7 +158,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 18, "end": 23, "loc": { @@ -210,8 +209,7 @@ "raw": "10" }, "value": 10 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/154/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/154/expected.json index c27822598f..00d6e9bd9a 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/154/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/154/expected.json @@ -121,7 +121,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 14, "end": 15, "loc": { @@ -153,7 +153,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 14, @@ -189,7 +188,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 20, "end": 25, "loc": { @@ -240,8 +239,7 @@ "raw": "10" }, "value": 10 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/155/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/155/expected.json index 4892fdd837..648cc628d4 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/155/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/155/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 31, "loc": { @@ -138,7 +138,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 15, "end": 16, "loc": { @@ -170,7 +170,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 15, @@ -206,7 +205,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 21, "end": 26, "loc": { @@ -257,8 +256,7 @@ "raw": "10" }, "value": 10 - }, - "kind": "init" + } } ] } @@ -281,8 +279,7 @@ "body": [], "directives": [] } - }, - "kind": "init" + } } ], "extra": { diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/156/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/156/expected.json index f918574a30..ff433a7001 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/156/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/156/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 2, "end": 21, "loc": { @@ -90,29 +90,29 @@ }, "name": "f" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 3, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 3 + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 4, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 17 + } }, - "end": { - "line": 1, - "column": 21 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "AssignmentPattern", + "left": { + "type": "ObjectPattern", "start": 4, - "end": 17, + "end": 7, "loc": { "start": { "line": 1, @@ -120,26 +120,29 @@ }, "end": { "line": 1, - "column": 17 + "column": 7 } }, - "left": { - "type": "ObjectPattern", - "start": 4, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 4 + "properties": [ + { + "type": "ObjectProperty", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } }, - "end": { - "line": 1, - "column": 7 - } - }, - "properties": [ - { - "type": "Property", + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", "start": 5, "end": 6, "loc": { @@ -152,136 +155,116 @@ "column": 6 } }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 5, - "end": 6, - "loc": { - "start": { - "line": 1, - "column": 5 - }, - "end": { - "line": 1, - "column": 6 - } - }, - "name": "x" - }, - "kind": "init", - "value": { - "type": "Identifier", - "start": 5, - "end": 6, - "loc": { - "start": { - "line": 1, - "column": 5 - }, - "end": { - "line": 1, - "column": 6 - } - }, - "name": "x" - } - } - ] - }, - "right": { - "type": "ObjectExpression", - "start": 10, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 10 + "name": "x" }, - "end": { - "line": 1, - "column": 17 + "value": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "name": "x" } + } + ] + }, + "right": { + "type": "ObjectExpression", + "start": 10, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 10 }, - "properties": [ - { - "type": "Property", + "end": { + "line": 1, + "column": 17 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", "start": 11, - "end": 16, + "end": 12, "loc": { "start": { "line": 1, "column": 11 }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "x" + }, + "value": { + "type": "NumberLiteral", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, "end": { "line": 1, "column": 16 } }, - "method": false, - "shorthand": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 11, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "name": "x" + "extra": { + "rawValue": 10, + "raw": "10" }, - "value": { - "type": "NumberLiteral", - "start": 14, - "end": 16, - "loc": { - "start": { - "line": 1, - "column": 14 - }, - "end": { - "line": 1, - "column": 16 - } - }, - "extra": { - "rawValue": 10, - "raw": "10" - }, - "value": 10 - }, - "kind": "init" + "value": 10 } - ] - } + } + ] } - ], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 21 - } - }, - "body": [], - "directives": [] } + ], + "body": { + "type": "BlockStatement", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/157/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/157/expected.json index 519875cdd1..16c419f612 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/157/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/157/expected.json @@ -74,7 +74,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 8, "end": 27, "loc": { @@ -106,28 +106,28 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 9, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 9 + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 10, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 23 + } }, - "end": { - "line": 1, - "column": 27 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "AssignmentPattern", + "left": { + "type": "ObjectPattern", "start": 10, - "end": 23, + "end": 13, "loc": { "start": { "line": 1, @@ -135,26 +135,29 @@ }, "end": { "line": 1, - "column": 23 + "column": 13 } }, - "left": { - "type": "ObjectPattern", - "start": 10, - "end": 13, - "loc": { - "start": { - "line": 1, - "column": 10 + "properties": [ + { + "type": "ObjectProperty", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } }, - "end": { - "line": 1, - "column": 13 - } - }, - "properties": [ - { - "type": "Property", + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", "start": 11, "end": 12, "loc": { @@ -167,136 +170,116 @@ "column": 12 } }, - "method": false, - "shorthand": true, - "computed": false, - "key": { - "type": "Identifier", - "start": 11, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "name": "x" - }, - "kind": "init", - "value": { - "type": "Identifier", - "start": 11, - "end": 12, - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "name": "x" - } - } - ] - }, - "right": { - "type": "ObjectExpression", - "start": 16, - "end": 23, - "loc": { - "start": { - "line": 1, - "column": 16 + "name": "x" }, - "end": { - "line": 1, - "column": 23 + "value": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": "x" } + } + ] + }, + "right": { + "type": "ObjectExpression", + "start": 16, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 16 }, - "properties": [ - { - "type": "Property", + "end": { + "line": 1, + "column": 23 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 17, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", "start": 17, - "end": 22, + "end": 18, "loc": { "start": { "line": 1, "column": 17 }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": "x" + }, + "value": { + "type": "NumberLiteral", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, "end": { "line": 1, "column": 22 } }, - "method": false, - "shorthand": false, - "computed": false, - "key": { - "type": "Identifier", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "name": "x" + "extra": { + "rawValue": 10, + "raw": "10" }, - "value": { - "type": "NumberLiteral", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "extra": { - "rawValue": 10, - "raw": "10" - }, - "value": 10 - }, - "kind": "init" + "value": 10 } - ] - } + } + ] } - ], - "body": { - "type": "BlockStatement", - "start": 25, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 25 - }, - "end": { - "line": 1, - "column": 27 - } - }, - "body": [], - "directives": [] } + ], + "body": { + "type": "BlockStatement", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/158/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/158/expected.json index 126c8430f4..f37f65a5de 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/158/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/158/expected.json @@ -90,7 +90,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 4, "loc": { @@ -122,7 +122,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 3, @@ -158,7 +157,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 9, "end": 14, "loc": { @@ -209,8 +208,7 @@ "raw": "10" }, "value": 10 - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/161/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/161/expected.json index 0fdbc8a52e..64c3b49fae 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/161/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/161/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 25, "loc": { @@ -208,8 +208,7 @@ "body": [], "directives": [] } - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/162/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/162/expected.json index 95a9a2ba3e..324d763163 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/162/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/162/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 15, "loc": { @@ -121,94 +121,79 @@ }, "name": "f" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 7, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 7 + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 8, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 11 + } }, - "end": { - "line": 1, - "column": 15 - } - }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "AssignmentPattern", + "left": { + "type": "Identifier", "start": 8, - "end": 11, + "end": 9, "loc": { "start": { "line": 1, "column": 8 }, + "end": { + "line": 1, + "column": 9 + } + }, + "name": "a" + }, + "right": { + "type": "NumberLiteral", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, "end": { "line": 1, "column": 11 } }, - "left": { - "type": "Identifier", - "start": 8, - "end": 9, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 1, - "column": 9 - } - }, - "name": "a" + "extra": { + "rawValue": 1, + "raw": "1" }, - "right": { - "type": "NumberLiteral", - "start": 10, - "end": 11, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 1, - "column": 11 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } + "value": 1 } - ], - "body": { - "type": "BlockStatement", - "start": 13, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "body": [], - "directives": [] } + ], + "body": { + "type": "BlockStatement", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/165/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/165/expected.json index 4ba45288ad..08cb8d6662 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/165/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/165/expected.json @@ -77,7 +77,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 13, "end": 14, "loc": { @@ -109,7 +109,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 13, @@ -128,7 +127,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 16, "end": 17, "loc": { @@ -160,7 +159,6 @@ }, "name": "b" }, - "kind": "init", "value": { "type": "Identifier", "start": 16, @@ -195,10 +193,11 @@ "column": 22 } }, - "body": [] + "body": [], + "directives": [] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/166/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/166/expected.json index 65c064b712..fecc14e44a 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/166/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/166/expected.json @@ -93,7 +93,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 16, "end": 17, "loc": { @@ -125,7 +125,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 16, @@ -160,10 +159,11 @@ "column": 22 } }, - "body": [] + "body": [], + "directives": [] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/170/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/170/expected.json index 7d82cfb3bb..50b9811fd9 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/170/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/170/expected.json @@ -91,7 +91,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 14, "end": 15, "loc": { @@ -123,7 +123,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 14, @@ -142,7 +141,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 17, "end": 18, "loc": { @@ -174,7 +173,6 @@ }, "name": "b" }, - "kind": "init", "value": { "type": "Identifier", "start": 17, diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/173/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/173/expected.json index 870de96929..35b8ef2474 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/173/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/173/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 3, "end": 16, "loc": { @@ -90,92 +90,77 @@ }, "name": "x" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 4, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "ArrayPattern", + "start": 5, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "name": "b" + } + ] + } + ], + "body": { + "type": "BlockStatement", + "start": 14, "end": 16, "loc": { "start": { "line": 1, - "column": 4 + "column": 14 }, "end": { "line": 1, "column": 16 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "ArrayPattern", - "start": 5, - "end": 13, - "loc": { - "start": { - "line": 1, - "column": 5 - }, - "end": { - "line": 1, - "column": 13 - } - }, - "elements": [ - { - "type": "Identifier", - "start": 7, - "end": 8, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 8 - } - }, - "name": "a" - }, - { - "type": "Identifier", - "start": 10, - "end": 11, - "loc": { - "start": { - "line": 1, - "column": 10 - }, - "end": { - "line": 1, - "column": 11 - } - }, - "name": "b" - } - ] - } - ], - "body": { - "type": "BlockStatement", - "start": 14, - "end": 16, - "loc": { - "start": { - "line": 1, - "column": 14 - }, - "end": { - "line": 1, - "column": 16 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ], diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/178/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/178/expected.json index 806994cb9b..15f1e7078a 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/178/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/178/expected.json @@ -76,7 +76,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 4, "loc": { @@ -108,7 +108,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 3, @@ -143,11 +142,12 @@ "column": 13 } }, - "body": [] + "body": [], + "directives": [] } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/179/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/179/expected.json index 4d7597a5b0..ce3a65a9ee 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/179/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/179/expected.json @@ -76,7 +76,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 4, "loc": { @@ -108,7 +108,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 3, @@ -174,11 +173,12 @@ "column": 19 } }, - "body": [] + "body": [], + "directives": [] } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/182/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/182/expected.json index d18c636d50..35cdf77789 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/182/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/182/expected.json @@ -76,7 +76,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 12, "loc": { @@ -156,8 +156,7 @@ "name": "b" } ] - }, - "kind": "init" + } } ] }, @@ -207,11 +206,12 @@ "column": 27 } }, - "body": [] + "body": [], + "directives": [] } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/183/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/183/expected.json index 52a957065f..79bc67b569 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/183/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/183/expected.json @@ -76,7 +76,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 7, "loc": { @@ -123,11 +123,10 @@ } }, "name": "b" - }, - "kind": "init" + } }, { - "type": "Property", + "type": "ObjectProperty", "start": 9, "end": 10, "loc": { @@ -159,7 +158,6 @@ }, "name": "c" }, - "kind": "init", "value": { "type": "Identifier", "start": 9, @@ -274,11 +272,12 @@ "column": 33 } }, - "body": [] + "body": [], + "directives": [] } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/186/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/186/expected.json index 525404a0e1..16d0a3f561 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/186/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/186/expected.json @@ -88,7 +88,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 3, "end": 4, "loc": { @@ -120,7 +120,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 3, @@ -139,7 +138,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 7, "loc": { @@ -171,7 +170,6 @@ }, "name": "b" }, - "kind": "init", "value": { "type": "Identifier", "start": 6, @@ -242,7 +240,7 @@ } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/190/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/190/expected.json index bb2b744d13..dc0dd1b374 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/190/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/190/expected.json @@ -88,7 +88,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 7, "end": 8, "loc": { @@ -120,7 +120,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 7, @@ -139,7 +138,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 10, "end": 11, "loc": { @@ -171,7 +170,6 @@ }, "name": "b" }, - "kind": "init", "value": { "type": "Identifier", "start": 10, @@ -244,7 +242,7 @@ ], "kind": "var" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/26/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/26/expected.json index a5de31017e..c14ff21a76 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/26/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/26/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 9, "end": 19, "loc": { @@ -121,7 +121,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 13, "end": 18, "loc": { @@ -172,12 +172,10 @@ "raw": "10" }, "value": 10 - }, - "kind": "init" + } } ] - }, - "kind": "init" + } } ] }, diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/303/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/303/expected.json index c58193f339..64493bca6c 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/303/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/303/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 8, "loc": { @@ -105,7 +105,6 @@ }, "name": "get" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, @@ -145,6 +144,7 @@ ], "kind": "var" } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/304/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/304/expected.json index 8fb4b5b979..b66e1b6640 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/304/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/304/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 38, "loc": { @@ -151,8 +151,7 @@ }, "name": "defaultValue" } - }, - "kind": "init" + } } ] }, @@ -176,7 +175,7 @@ ], "kind": "var" } - ] - }, - "comments": [] -} + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/305/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/305/expected.json index a47eedc258..07fa4a6986 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/305/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/305/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 28, "loc": { @@ -105,7 +105,6 @@ }, "name": "propName" }, - "kind": "init", "value": { "type": "AssignmentPattern", "start": 5, @@ -176,7 +175,7 @@ ], "kind": "var" } - ] - }, - "comments": [] -} + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/307/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/307/expected.json index fa5a1fed3e..66529d6cc5 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/307/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/307/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 7, "loc": { @@ -105,7 +105,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "AssignmentPattern", "start": 2, diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/308/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/308/expected.json index f13152264e..0b996626b8 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/308/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/308/expected.json @@ -76,7 +76,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 2, "end": 7, "loc": { @@ -108,7 +108,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "AssignmentPattern", "start": 2, diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/309/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/309/expected.json index 21ff2e2c8b..a5c0d5db68 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/309/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/309/expected.json @@ -104,7 +104,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 15, "loc": { @@ -152,7 +152,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 9, "end": 14, "loc": { @@ -184,7 +184,6 @@ }, "name": "c" }, - "kind": "init", "value": { "type": "AssignmentPattern", "start": 9, @@ -238,8 +237,7 @@ } } ] - }, - "kind": "init" + } } ] } diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/310/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/310/expected.json index efd6b8cb0f..d58ddf8b31 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/310/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/310/expected.json @@ -58,7 +58,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 11, "loc": { @@ -90,7 +90,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "AssignmentPattern", "start": 6, diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/313/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/313/expected.json index d56fc1ce39..9a9139b799 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/313/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/313/expected.json @@ -56,7 +56,8 @@ "column": 6 } }, - "body": [] + "body": [], + "directives": [] }, "handler": { "type": "CatchClause", @@ -88,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 15, "end": 22, "loc": { @@ -120,7 +121,6 @@ }, "name": "message" }, - "kind": "init", "value": { "type": "Identifier", "start": 15, @@ -154,13 +154,14 @@ "column": 27 } }, - "body": [] + "body": [], + "directives": [] } }, "guardedHandlers": [], "finalizer": null } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/314/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/314/expected.json index 251b838ffe..859c4a7b48 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/314/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/314/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 21, "loc": { @@ -107,46 +107,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 16, + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 19, "end": 21, "loc": { "start": { "line": 1, - "column": 16 + "column": 19 }, "end": { "line": 1, "column": 21 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 21, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 21 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/316/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/316/expected.json index d0a93d30d0..ec67c88b06 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/316/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/316/expected.json @@ -75,7 +75,7 @@ }, "body": [ { - "type": "MethodDefinition", + "type": "ClassMethod", "start": 10, "end": 22, "loc": { @@ -107,46 +107,32 @@ }, "static": false, "kind": "method", - "value": { - "type": "FunctionExpression", - "start": 17, + "id": null, + "generator": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 20, "end": 22, "loc": { "start": { "line": 1, - "column": 17 + "column": 20 }, "end": { "line": 1, "column": 22 } }, - "id": null, - "generator": true, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 20, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 20 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/321/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/321/expected.json index 6b9c75753f..304fea8a0d 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/321/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/321/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 6, "loc": { @@ -105,7 +105,6 @@ }, "name": "x" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, @@ -145,6 +144,7 @@ ], "kind": "let" } - ] + ], + "directives": [] } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/33/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/33/expected.json index fbd87bd0c4..8025e7a342 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/33/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/33/expected.json @@ -93,7 +93,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 8, "end": 20, "loc": { @@ -144,8 +144,7 @@ "raw": "42" }, "value": 42 - }, - "kind": "init" + } } ], "extra": { diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/347/options.json b/packages/babylon/test/fixtures/harmony/uncategorised/347/options.json index 1cddead191..739bda889b 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/347/options.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/347/options.json @@ -1,3 +1,3 @@ { - "throws": "setter should have exactly one param (1:18)" -} \ No newline at end of file + "throws": "setter should have exactly one param (1:10)" +} diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/52/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/52/expected.json index bb2d92ab6e..880dce74c2 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/52/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/52/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 18, "loc": { @@ -121,48 +121,34 @@ }, "name": "method" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 12, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, "end": 18, "loc": { "start": { "line": 1, - "column": 12 + "column": 15 }, "end": { "line": 1, "column": 18 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 15, - "end": 18, - "loc": { - "start": { - "line": 1, - "column": 15 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/53/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/53/expected.json index 75665ddf61..7d5dce4954 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/53/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/53/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 22, "loc": { @@ -121,65 +121,51 @@ }, "name": "method" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 12, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": "test" + } + ], + "body": { + "type": "BlockStatement", + "start": 19, "end": 22, "loc": { "start": { "line": 1, - "column": 12 + "column": 19 }, "end": { "line": 1, "column": 22 } }, - "id": null, - "generator": false, - "expression": false, - "params": [ - { - "type": "Identifier", - "start": 13, - "end": 17, - "loc": { - "start": { - "line": 1, - "column": 13 - }, - "end": { - "line": 1, - "column": 17 - } - }, - "name": "test" - } - ], - "body": { - "type": "BlockStatement", - "start": 19, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 19 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/54/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/54/expected.json index e964b38846..1030bf0af2 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/54/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/54/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 20, "loc": { @@ -125,42 +125,27 @@ }, "value": "method" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 14, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, "end": 20, "loc": { "start": { "line": 1, - "column": 14 + "column": 17 }, "end": { "line": 1, "column": 20 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 17 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "body": [], - "directives": [] - } + "body": [], + "directives": [] } } ] diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/55/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/55/expected.json index 442afea2b9..0b0d3f1c10 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/55/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/55/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 15, "loc": { @@ -121,48 +121,34 @@ }, "name": "get" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 9, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 15, "loc": { "start": { "line": 1, - "column": 9 + "column": 12 }, "end": { "line": 1, "column": 15 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/56/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/56/expected.json index 3545909350..b118b76443 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/56/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/56/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectMethod", "start": 6, "end": 15, "loc": { @@ -121,48 +121,34 @@ }, "name": "set" }, - "kind": "init", - "value": { - "type": "FunctionExpression", - "start": 9, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 12, "end": 15, "loc": { "start": { "line": 1, - "column": 9 + "column": 12 }, "end": { "line": 1, "column": 15 } }, - "id": null, - "generator": false, - "expression": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 12, - "end": 15, - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 15 - } - }, - "body": [] - } + "body": [], + "directives": [] } } ] } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/61/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/61/expected.json index 592ee20049..660265dd75 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/61/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/61/expected.json @@ -89,7 +89,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 6, "end": 7, "loc": { @@ -121,7 +121,6 @@ }, "name": "y" }, - "kind": "init", "value": { "type": "Identifier", "start": 6, @@ -140,7 +139,7 @@ } }, { - "type": "Property", + "type": "ObjectProperty", "start": 9, "end": 10, "loc": { @@ -172,7 +171,6 @@ }, "name": "z" }, - "kind": "init", "value": { "type": "Identifier", "start": 9, @@ -194,7 +192,7 @@ } } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/63/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/63/expected.json index f8d73fc297..f17d4e7f50 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/63/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/63/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 7, "end": 8, "loc": { @@ -105,7 +105,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 7, @@ -145,7 +144,7 @@ ], "kind": "const" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/65/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/65/expected.json index beb62b1d35..d449479dc0 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/65/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/65/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 6, "loc": { @@ -105,7 +105,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, @@ -145,7 +144,7 @@ ], "kind": "let" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/67/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/67/expected.json index 870ab05ccc..5847b666e3 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/67/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/67/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 6, "loc": { @@ -105,7 +105,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 5, @@ -145,7 +144,7 @@ ], "kind": "var" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/69/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/69/expected.json index bad27b27c6..f2577d66d0 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/69/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/69/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 7, "end": 10, "loc": { @@ -120,8 +120,7 @@ } }, "name": "b" - }, - "kind": "init" + } } ] }, @@ -145,7 +144,7 @@ ], "kind": "const" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/70/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/70/expected.json index 37cca27feb..a9efc0fea7 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/70/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/70/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 8, "loc": { @@ -120,8 +120,7 @@ } }, "name": "b" - }, - "kind": "init" + } } ] }, @@ -145,7 +144,7 @@ ], "kind": "let" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/harmony/uncategorised/71/expected.json b/packages/babylon/test/fixtures/harmony/uncategorised/71/expected.json index 6a0f96a0d8..0615d247ab 100644 --- a/packages/babylon/test/fixtures/harmony/uncategorised/71/expected.json +++ b/packages/babylon/test/fixtures/harmony/uncategorised/71/expected.json @@ -73,7 +73,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 5, "end": 8, "loc": { @@ -120,8 +120,7 @@ } }, "name": "b" - }, - "kind": "init" + } } ] }, @@ -145,7 +144,7 @@ ], "kind": "var" } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/jsx/basic/10/expected.json b/packages/babylon/test/fixtures/jsx/basic/10/expected.json index 7dbf341df0..74329dfd09 100644 --- a/packages/babylon/test/fixtures/jsx/basic/10/expected.json +++ b/packages/babylon/test/fixtures/jsx/basic/10/expected.json @@ -156,20 +156,8 @@ }, "expression": { "type": "JSXEmptyExpression", - "start": 4, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 27 - } - }, - "leadingComments": null, - "innerComments": [ + "loc": {}, + "leadingComments": [ { "type": "CommentBlock", "value": " this is a comment ", @@ -187,7 +175,26 @@ } } ] - } + }, + "leadingComments": null, + "innerComments": [ + { + "type": "CommentBlock", + "value": " this is a comment ", + "start": 4, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 27 + } + } + } + ] } ] } diff --git a/packages/babylon/test/fixtures/jsx/basic/empty-expression-container/expected.json b/packages/babylon/test/fixtures/jsx/basic/empty-expression-container/expected.json index 3f1a13918e..157403e9bf 100644 --- a/packages/babylon/test/fixtures/jsx/basic/empty-expression-container/expected.json +++ b/packages/babylon/test/fixtures/jsx/basic/empty-expression-container/expected.json @@ -137,24 +137,13 @@ }, "expression": { "type": "JSXEmptyExpression", - "start": 4, - "end": 4, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 4 - } - } + "loc": {} } } ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/fixtures/jsx/regression/3/expected.json b/packages/babylon/test/fixtures/jsx/regression/3/expected.json index e12dd8c418..d4081dc212 100644 --- a/packages/babylon/test/fixtures/jsx/regression/3/expected.json +++ b/packages/babylon/test/fixtures/jsx/regression/3/expected.json @@ -151,7 +151,7 @@ }, "properties": [ { - "type": "Property", + "type": "ObjectProperty", "start": 8, "end": 9, "loc": { @@ -183,7 +183,6 @@ }, "name": "a" }, - "kind": "init", "value": { "type": "Identifier", "start": 8, @@ -207,7 +206,7 @@ ] } } - ] - }, - "comments": [] + ], + "directives": [] + } } \ No newline at end of file diff --git a/packages/babylon/test/index.js b/packages/babylon/test/index.js index 6dc0156769..0954e19df9 100644 --- a/packages/babylon/test/index.js +++ b/packages/babylon/test/index.js @@ -59,7 +59,7 @@ function runTest(test) { } else { var mis = misMatch(JSON.parse(test.expect.code), ast); if (mis) { - // save(test, ast); + //save(test, ast); throw new Error(mis); } } diff --git a/scripts/bootstrap.js b/scripts/bootstrap.js index d76f98ad06..0f4a0cc0a2 100755 --- a/scripts/bootstrap.js +++ b/scripts/bootstrap.js @@ -3,6 +3,8 @@ require("shelljs/global"); var path = require("path"); var fs = require("fs"); +var OFFLINE = !!process.env.OFFLINE; + // uninstall global babel install try { exec("npm uninstall -g babel"); @@ -47,9 +49,22 @@ packages.forEach(function (root) { }); cd("packages/" + root.folder); - exec("npm install"); - exec("npm link"); + + // check whether or not we have any dependencies in our package.json that aren't in node_modules + var shouldRunInstall = false; + var pkg = require(process.cwd() + "/package.json"); + var deps = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.devDependencies || {})); + deps.forEach(function (depName) { + if (!fs.existsSync(process.cwd() + "/node_modules/" + depName)) { + console.log("Not installed", depName); + shouldRunInstall = true; + } + }); + if (shouldRunInstall && !OFFLINE) exec("npm install"); + + if (!OFFLINE) exec("npm link"); + cd("../.."); }); -exec("make build"); +if (!OFFLINE) exec("make build"); diff --git a/scripts/publish.js b/scripts/publish.js index 2335924acc..d093e66387 100755 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -72,7 +72,7 @@ function updateDepsObject(changedPackages, deps) { function publish() { var packageNames = fs.readdirSync(PACKAGE_LOC).filter(function (name) { - return name[0] !== "."; + return name[0] !== "." && fs.statSync(PACKAGE_LOC + "/" + name).isDirectory(); }); var lastTagCommit = exec("git rev-list --tags --max-count=1"); @@ -152,6 +152,7 @@ try { } catch (err) { console.log(chalk.red("There was a problem publishing.")); console.log(err.stack); + return; if (publishedPackages.length) { console.log(chalk.warning("Unpublishing published packages...")); @@ -159,8 +160,8 @@ try { publishedPackages.forEach(function () { var verInfo = name + "@" + NEW_VERSION; try { - console.log(chalk.warning("Unpublishing " + verInfo "...")); - exec("npm unpublish --force " + verInfo); + console.log(chalk.warning("Unpublishing " + verInfo + "...")); + //exec("npm unpublish --force " + verInfo); } catch (err) { console.log(chalk.red("Failed to unpublish " + verInfo)); console.log(err.stack); @@ -168,7 +169,7 @@ try { }); } else { console.log(chalk.warning("Rolling back to commit", originalCommit, "...")); - exec("git checkout --hard " + originalCommit, true); + //exec("git checkout --hard " + originalCommit, true); } return; diff --git a/test.js b/test.js deleted file mode 100644 index 3918c74e44..0000000000 --- a/test.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";