diff --git a/packages/babel-compiler/.npm/package/.gitignore b/packages/babel-compiler/.npm/package/.gitignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/packages/babel-compiler/.npm/package/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/packages/babel-compiler/.npm/package/README b/packages/babel-compiler/.npm/package/README new file mode 100644 index 0000000000..3d492553a4 --- /dev/null +++ b/packages/babel-compiler/.npm/package/README @@ -0,0 +1,7 @@ +This directory and the files immediately inside it are automatically generated +when you change this package's NPM dependencies. Commit the files in this +directory (npm-shrinkwrap.json, .gitignore, and this README) to source control +so that others run the same versions of sub-dependencies. + +You should NOT check in the node_modules directory that Meteor automatically +creates; if you are using git, the .gitignore file tells git to ignore it. diff --git a/packages/babel-compiler/.npm/package/npm-shrinkwrap.json b/packages/babel-compiler/.npm/package/npm-shrinkwrap.json new file mode 100644 index 0000000000..29d0a3b6c5 --- /dev/null +++ b/packages/babel-compiler/.npm/package/npm-shrinkwrap.json @@ -0,0 +1,442 @@ +{ + "dependencies": { + "meteor-babel": { + "version": "0.4.3", + "dependencies": { + "babel-core": { + "version": "5.7.1", + "dependencies": { + "babel-plugin-constant-folding": { + "version": "1.0.1" + }, + "babel-plugin-dead-code-elimination": { + "version": "1.0.2" + }, + "babel-plugin-eval": { + "version": "1.0.1" + }, + "babel-plugin-inline-environment-variables": { + "version": "1.0.1" + }, + "babel-plugin-jscript": { + "version": "1.0.1" + }, + "babel-plugin-member-expression-literals": { + "version": "1.0.1" + }, + "babel-plugin-property-literals": { + "version": "1.0.1" + }, + "babel-plugin-proto-to-assign": { + "version": "1.0.3" + }, + "babel-plugin-react-constant-elements": { + "version": "1.0.3" + }, + "babel-plugin-react-display-name": { + "version": "1.0.3" + }, + "babel-plugin-remove-console": { + "version": "1.0.1" + }, + "babel-plugin-remove-debugger": { + "version": "1.0.1" + }, + "babel-plugin-runtime": { + "version": "1.0.7" + }, + "babel-plugin-undeclared-variables-check": { + "version": "1.0.2", + "dependencies": { + "leven": { + "version": "1.0.2" + } + } + }, + "babel-plugin-undefined-to-void": { + "version": "1.1.6" + }, + "babylon": { + "version": "5.7.1" + }, + "bluebird": { + "version": "2.9.34" + }, + "chalk": { + "version": "1.1.0", + "dependencies": { + "ansi-styles": { + "version": "2.1.0" + }, + "escape-string-regexp": { + "version": "1.0.3" + }, + "has-ansi": { + "version": "2.0.0", + "dependencies": { + "ansi-regex": { + "version": "2.0.0" + } + } + }, + "strip-ansi": { + "version": "3.0.0", + "dependencies": { + "ansi-regex": { + "version": "2.0.0" + } + } + }, + "supports-color": { + "version": "2.0.0" + } + } + }, + "core-js": { + "version": "0.9.18" + }, + "debug": { + "version": "2.2.0", + "dependencies": { + "ms": { + "version": "0.7.1" + } + } + }, + "detect-indent": { + "version": "3.0.1", + "dependencies": { + "get-stdin": { + "version": "4.0.1" + }, + "minimist": { + "version": "1.1.1" + } + } + }, + "estraverse": { + "version": "4.1.0" + }, + "esutils": { + "version": "2.0.2" + }, + "fs-readdir-recursive": { + "version": "0.1.2" + }, + "globals": { + "version": "6.4.1" + }, + "home-or-tmp": { + "version": "1.0.0", + "dependencies": { + "os-tmpdir": { + "version": "1.0.1" + }, + "user-home": { + "version": "1.1.1" + } + } + }, + "is-integer": { + "version": "1.0.4", + "dependencies": { + "is-finite": { + "version": "1.0.1", + "dependencies": { + "number-is-nan": { + "version": "1.0.0" + } + } + }, + "is-nan": { + "version": "1.1.0", + "dependencies": { + "define-properties": { + "version": "1.1.0", + "dependencies": { + "foreach": { + "version": "2.0.5" + }, + "object-keys": { + "version": "1.0.6" + } + } + } + } + } + } + }, + "js-tokens": { + "version": "1.0.1" + }, + "line-numbers": { + "version": "0.2.0", + "dependencies": { + "left-pad": { + "version": "0.0.3" + } + } + }, + "lodash": { + "version": "3.10.0" + }, + "minimatch": { + "version": "2.0.8", + "dependencies": { + "brace-expansion": { + "version": "1.1.0", + "dependencies": { + "balanced-match": { + "version": "0.2.0" + }, + "concat-map": { + "version": "0.0.1" + } + } + } + } + }, + "output-file-sync": { + "version": "1.1.1", + "dependencies": { + "mkdirp": { + "version": "0.5.1", + "dependencies": { + "minimist": { + "version": "0.0.8" + } + } + }, + "xtend": { + "version": "4.0.0" + } + } + }, + "path-exists": { + "version": "1.0.0" + }, + "path-is-absolute": { + "version": "1.0.0" + }, + "private": { + "version": "0.1.6" + }, + "regenerator": { + "version": "0.8.34", + "dependencies": { + "commoner": { + "version": "0.10.3", + "dependencies": { + "q": { + "version": "1.1.2" + }, + "commander": { + "version": "2.5.1" + }, + "graceful-fs": { + "version": "3.0.8" + }, + "glob": { + "version": "4.2.2", + "dependencies": { + "inflight": { + "version": "1.0.4", + "dependencies": { + "wrappy": { + "version": "1.0.1" + } + } + }, + "inherits": { + "version": "2.0.1" + }, + "minimatch": { + "version": "1.0.0", + "dependencies": { + "lru-cache": { + "version": "2.6.5" + }, + "sigmund": { + "version": "1.0.1" + } + } + }, + "once": { + "version": "1.3.2", + "dependencies": { + "wrappy": { + "version": "1.0.1" + } + } + } + } + }, + "mkdirp": { + "version": "0.5.1", + "dependencies": { + "minimist": { + "version": "0.0.8" + } + } + }, + "install": { + "version": "0.1.8" + }, + "iconv-lite": { + "version": "0.4.11" + } + } + }, + "defs": { + "version": "1.1.0", + "dependencies": { + "alter": { + "version": "0.2.0", + "dependencies": { + "stable": { + "version": "0.1.5" + } + } + }, + "ast-traverse": { + "version": "0.1.1" + }, + "breakable": { + "version": "1.0.0" + }, + "esprima-fb": { + "version": "8001.1001.0-dev-harmony-fb" + }, + "simple-fmt": { + "version": "0.1.0" + }, + "simple-is": { + "version": "0.2.0" + }, + "stringmap": { + "version": "0.2.2" + }, + "stringset": { + "version": "0.2.1" + }, + "tryor": { + "version": "0.1.2" + }, + "yargs": { + "version": "1.3.3" + } + } + }, + "esprima-fb": { + "version": "13001.1.0-dev-harmony-fb" + }, + "recast": { + "version": "0.10.18", + "dependencies": { + "esprima-fb": { + "version": "14001.1.0-dev-harmony-fb" + }, + "ast-types": { + "version": "0.8.2" + } + } + }, + "through": { + "version": "2.3.8" + } + } + }, + "regexpu": { + "version": "1.2.0", + "dependencies": { + "recast": { + "version": "0.10.21", + "dependencies": { + "esprima-fb": { + "version": "15001.1.0-dev-harmony-fb" + }, + "ast-types": { + "version": "0.8.3" + } + } + }, + "regenerate": { + "version": "1.2.1" + }, + "regjsgen": { + "version": "0.2.0" + }, + "regjsparser": { + "version": "0.1.4", + "dependencies": { + "jsesc": { + "version": "0.5.0" + } + } + } + } + }, + "repeating": { + "version": "1.1.3", + "dependencies": { + "is-finite": { + "version": "1.0.1", + "dependencies": { + "number-is-nan": { + "version": "1.0.0" + } + } + } + } + }, + "resolve": { + "version": "1.1.6" + }, + "shebang-regex": { + "version": "1.0.0" + }, + "slash": { + "version": "1.0.0" + }, + "source-map": { + "version": "0.4.4", + "dependencies": { + "amdefine": { + "version": "1.0.0" + } + } + }, + "source-map-support": { + "version": "0.2.10", + "dependencies": { + "source-map": { + "version": "0.1.32", + "dependencies": { + "amdefine": { + "version": "1.0.0" + } + } + } + } + }, + "strip-json-comments": { + "version": "1.0.2" + }, + "to-fast-properties": { + "version": "1.0.1" + }, + "trim-right": { + "version": "1.0.0" + } + } + }, + "convert-source-map": { + "version": "1.1.1" + }, + "meteor-async-await": { + "version": "0.1.1" + } + } + } + } +} diff --git a/packages/babel-compiler/README.md b/packages/babel-compiler/README.md new file mode 100644 index 0000000000..6e29e0b0f1 --- /dev/null +++ b/packages/babel-compiler/README.md @@ -0,0 +1,50 @@ +[Babel](http://babeljs.io/) is a parser and transpiler for ECMAScript 2015 +syntax and beyond, which enables some upcoming JavaScript syntax features +to be used in today's browsers and runtimes. + +Meteor's Babel support consists of the following core packages: + +* `babel-compiler` - Exposes the [Babel API](https://babeljs.io/docs/usage/api/) + on the symbol `Babel`. For example, `Babel.compile(source, options)`. + +* `babel-runtime` - Meteor versions of the external helpers used by + Babel-generated code. Meteor's core packages must run on IE 8 without + polyfills, so these helpers cannot assume the existence of + `Object.defineProperty`, `Object.freeze`, and so on. + +### Babel API + +The `babel-compiler` package exports the `Babel` symbol, which exposes +functionality provided by the +[`meteor-babel`](https://www.npmjs.com/package/meteor-babel) NPM package, +which is in turn implmented using the +[`babel-core`](https://www.npmjs.com/package/babel-core) NPM package. +Note that you can only use the `babel-compiler` package on the server. + +Example: + +```js +var babelOptions = Babel.getDefaultOptions(); + +// Modify the default options, if necessary: +babelOptions.whitelist = [ + "es6.blockScoping", // For `let` + "es6.arrowFunctions" // For `=>` +]; + +var result = Babel.compile( + "let square = (x) => x*x;", + babelOptions +); + +// result.code will be something like +// "var square = function (x) {\n return x * x;\n};" +``` + +Use `Babel.compile(source)` to transpile code using a set of default +options that work well for Meteor code. + +Resources: + +* [API docs](https://babeljs.io/docs/usage/api/) +* [List of transformers](https://babeljs.io/docs/usage/transformers/) diff --git a/packages/babel-compiler/babel.js b/packages/babel-compiler/babel.js new file mode 100644 index 0000000000..98b66f057d --- /dev/null +++ b/packages/babel-compiler/babel.js @@ -0,0 +1,61 @@ +var meteorBabel = Npm.require('meteor-babel'); + +/** + * Returns a new object containing default options appropriate for + */ +function getDefaultOptions(extraFeatures) { + if (extraFeatures) { + check(extraFeatures, { + // Modify options to enable ES2015 module syntax. + modules: Match.Optional(Boolean), + // Modify options to enable async/await syntax powered by Fibers. + meteorAsyncAwait: Match.Optional(Boolean) + }); + } + + // See https://github.com/meteor/babel/blob/master/options.js for more + // information about what the default options are. + var options = meteorBabel.getDefaultOptions(extraFeatures); + + // The sourceMap option should probably be removed from the default + // options returned by meteorBabel.getDefaultOptions. + delete options.sourceMap; + + return options; +} + +Babel = { + getDefaultOptions: getDefaultOptions, + + compile: function (source, options) { + options = options || getDefaultOptions(); + return meteorBabel.compile(source, options); + }, + + // Provided for backwards compatibility; prefer Babel.compile. + transformMeteor: function (source, extraOptions) { + var options = getDefaultOptions(); + + if (extraOptions) { + if (extraOptions.extraWhitelist) { + options.whitelist.push.apply( + options.whitelist, + extraOptions.extraWhitelist + ); + } + + for (var key in extraOptions) { + if (key !== "extraWhitelist" && + hasOwnProperty.call(extraOptions, key)) { + options[key] = extraOptions[key]; + } + } + } + + return meteorBabel.compile(code, options); + }, + + setCacheDir: function (cacheDir) { + meteorBabel.setCacheDir(cacheDir); + } +}; diff --git a/packages/babel-compiler/package.js b/packages/babel-compiler/package.js new file mode 100644 index 0000000000..0c383c0ea6 --- /dev/null +++ b/packages/babel-compiler/package.js @@ -0,0 +1,17 @@ +Package.describe({ + name: "babel-compiler", + summary: "Parser/transpiler for ECMAScript 6+ syntax", + // Tracks the npm version below. Use wrap numbers to increment + // without incrementing the npm version. + version: '5.7.1' +}); + +Npm.depends({ + 'meteor-babel': '0.4.3' +}); + +Package.onUse(function (api) { + api.addFiles('babel.js', 'server'); + api.use('check'); + api.export('Babel', 'server'); +});