@babel/core
Advanced tools
Comparing version 7.0.0-beta.49 to 7.0.0-beta.50
@@ -210,4 +210,4 @@ "use strict"; | ||
const packageToBabelConfig = (0, _caching.makeWeakCache)(file => { | ||
if (typeof file.options.babel === "undefined") return null; | ||
const babel = file.options.babel; | ||
const babel = file.options["babel"]; | ||
if (typeof babel === "undefined") return null; | ||
@@ -214,0 +214,0 @@ if (typeof babel !== "object" || Array.isArray(babel) || babel === null) { |
{ | ||
"name": "@babel/core", | ||
"version": "7.0.0-beta.49", | ||
"version": "7.0.0-beta.50", | ||
"description": "Babel compiler core.", | ||
@@ -33,9 +33,9 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@babel/code-frame": "7.0.0-beta.49", | ||
"@babel/generator": "7.0.0-beta.49", | ||
"@babel/helpers": "7.0.0-beta.49", | ||
"@babel/parser": "7.0.0-beta.49", | ||
"@babel/template": "7.0.0-beta.49", | ||
"@babel/traverse": "7.0.0-beta.49", | ||
"@babel/types": "7.0.0-beta.49", | ||
"@babel/code-frame": "7.0.0-beta.50", | ||
"@babel/generator": "7.0.0-beta.50", | ||
"@babel/helpers": "7.0.0-beta.50", | ||
"@babel/parser": "7.0.0-beta.50", | ||
"@babel/template": "7.0.0-beta.50", | ||
"@babel/traverse": "7.0.0-beta.50", | ||
"@babel/types": "7.0.0-beta.50", | ||
"convert-source-map": "^1.1.0", | ||
@@ -45,3 +45,3 @@ "debug": "^3.1.0", | ||
"lodash": "^4.17.5", | ||
"micromatch": "^2.3.11", | ||
"micromatch": "^3.1.10", | ||
"resolve": "^1.3.2", | ||
@@ -52,5 +52,5 @@ "semver": "^5.4.1", | ||
"devDependencies": { | ||
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.49", | ||
"@babel/register": "7.0.0-beta.49" | ||
"@babel/helper-transform-fixture-test-runner": "7.0.0-beta.50", | ||
"@babel/register": "7.0.0-beta.50" | ||
} | ||
} |
247
README.md
@@ -5,247 +5,16 @@ # @babel/core | ||
See our website [@babel/core](https://new.babeljs.io/docs/en/next/babel-core.html) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20core%22+is%3Aopen) associated with this package. | ||
```javascript | ||
var babel = require("@babel/core"); | ||
import { transform } from "@babel/core"; | ||
import * as babel from "@babel/core"; | ||
``` | ||
## Install | ||
All transformations will use your local configuration files (`.babelrc` or in `package.json`). See [options](#options) to disable it. | ||
Using npm: | ||
## babel.transform(code: string, [options?](#options): Object, callback: Function) | ||
Transforms the passed in `code`. Calling a callback with an object with the generated code, | ||
source map, and AST. | ||
```js | ||
babel.transform(code, options, function(err, result) { | ||
result; // => { code, map, ast } | ||
}); | ||
```sh | ||
npm install --save @babel/core | ||
``` | ||
**Example** | ||
or using yarn: | ||
```js | ||
babel.transform("code();", options, function(err, result) { | ||
result.code; | ||
result.map; | ||
result.ast; | ||
}); | ||
```sh | ||
yarn add --save @babel/core | ||
``` | ||
### Compat Note: | ||
In Babel 6, this method was synchronous and `transformSync` did not exist. For backward-compatibility, | ||
this function will behave synchronously if no callback is given. If you're starting with Babel 7 | ||
and need synchronous behavior, please use `transformSync` since this backward-compat may be dropped in | ||
future major versions of Babel. | ||
## babel.transformSync(code: string, [options?](#options): Object) | ||
Transforms the passed in `code`. Returning an object with the generated code, | ||
source map, and AST. | ||
```js | ||
babel.transformSync(code, options) // => { code, map, ast } | ||
``` | ||
**Example** | ||
```js | ||
var result = babel.transformSync("code();", options); | ||
result.code; | ||
result.map; | ||
result.ast; | ||
``` | ||
## babel.transformFile(filename: string, [options?](#options): Object, callback: Function) | ||
Asynchronously transforms the entire contents of a file. | ||
```js | ||
babel.transformFile(filename, options, callback) | ||
``` | ||
**Example** | ||
```js | ||
babel.transformFile("filename.js", options, function (err, result) { | ||
result; // => { code, map, ast } | ||
}); | ||
``` | ||
## babel.transformFileSync(filename: string, [options?](#options): Object) | ||
Synchronous version of `babel.transformFile`. Returns the transformed contents of | ||
the `filename`. | ||
```js | ||
babel.transformFileSync(filename, options) // => { code, map, ast } | ||
``` | ||
**Example** | ||
```js | ||
babel.transformFileSync("filename.js", options).code; | ||
``` | ||
## babel.transformFromAst(ast: Object, code?: string, [options?](#options): Object, callback: Function): FileNode | null | ||
Given an [AST](https://astexplorer.net/), transform it. | ||
```js | ||
const sourceCode = "if (true) return;"; | ||
const parsedAst = babel.parse(sourceCode, { allowReturnOutsideFunction: true }); | ||
babel.transformFromAst(parsedAst, sourceCode, options, function(err, result) { | ||
const { code, map, ast } = result; | ||
}); | ||
``` | ||
### Compat Note: | ||
In Babel 6, this method was synchronous and `transformFromAstSync` did not exist. For backward-compatibility, | ||
this function will behave synchronously if no callback is given. If you're starting with Babel 7 | ||
and need synchronous behavior, please use `transformFromAstSync` since this backward-compat may be dropped in | ||
future major versions of Babel. | ||
## babel.transformFromAstSync(ast: Object, code?: string, [options?](#options): Object) | ||
Given an [AST](https://astexplorer.net/), transform it. | ||
```js | ||
const sourceCode = "if (true) return;"; | ||
const parsedAst = babel.parse(sourceCode, { allowReturnOutsideFunction: true }); | ||
const { code, map, ast } = babel.transformFromAstSync(parsedAst, sourceCode, options); | ||
``` | ||
## babel.parse(code: string, [options?](#options): Object) | ||
Given some code, parse it using Babel's standard behavior. Referenced presets and | ||
plugins will be loaded such that optional syntax plugins are automatically | ||
enabled. | ||
## Advanced APIs | ||
Many systems that wrap Babel like to automatically inject plugins and presets, | ||
or override options. To accomplish this goal, Babel exposes several functions | ||
that aid in loading the configuration part-way without transforming. | ||
### babel.loadOptions([options?](#options): Object) | ||
Resolve Babel's options fully, resulting in an options object where: | ||
* `opts.plugins` is a full list of `Plugin` instances. | ||
* `opts.presets` is empty and all presets are flattened into `opts`. | ||
* It can be safely passed back to Babel. Fields like `babelrc` have been set to | ||
false so that later calls to Babel will not make a second attempt to load | ||
config files. | ||
`Plugin` instances aren't meant to be manipulated directly, but often | ||
callers will serialize this `opts` to JSON to use it as a cache key representing | ||
the options Babel has received. Caching on this isn't 100% guaranteed to | ||
invalidate properly, but it is the best we have at the moment. | ||
### babel.loadPartialConfig([options?](#options): Object): PartialConfig | ||
To allow systems to easily manipulate and validate a user's config, this function | ||
resolves the plugins and presets and proceeds no further. The expectation is | ||
that callers will take the config's `.options`, manipulate it as then see fit | ||
and pass it back to Babel again. | ||
* `babelrc: string | void` - The path of the `.babelrc` file, if there was one. | ||
* `babelignore: string | void` - The path of the `.babelignore` file, if there was one. | ||
* `options: ValidatedOptions` - The partially resolved options, which can be manipulated and passed back to Babel again. | ||
* `plugins: Array<ConfigItem>` - See below. | ||
* `presets: Array<ConfigItem>` - See below. | ||
* It can be safely passed back to Babel. Fields like `babelrc` have been set | ||
to false so that later calls to Babel will not make a second attempt to | ||
load config files. | ||
* `hasFilesystemConfig(): boolean` - Check if the resolved config loaded any settings from the filesystem. | ||
[`ConfigItem`](#configitem-type) instances expose properties to introspect the values, but each | ||
item should be treated as immutable. If changes are desired, the item should be | ||
removed from the list and replaced with either a normal Babel config value, or | ||
with a replacement item created by `babel.createConfigItem`. See that | ||
function for information about `ConfigItem` fields. | ||
### babel.createConfigItem(value: string | {} | Function | [string | {} | Function, {} | void], { dirname?: string, type?: "preset" | "plugin" }): ConfigItem | ||
Allows build tooling to create and cache config items up front. If this function | ||
is called multiple times for a given plugin, Babel will call the plugin's function itself | ||
multiple times. If you have a clear set of expected plugins and presets to | ||
inject, pre-constructing the config items would be recommended. | ||
### `ConfigItem` type | ||
Each `ConfigItem` exposes all of the information Babel knows. The fields are: | ||
* `value: {} | Function` - The resolved value of the plugin. | ||
* `options: {} | void` - The options object passed to the plugin. | ||
* `dirname: string` - The path that the options are relative to. | ||
* `name: string | void` - The name that the user gave the plugin instance, e.g. `plugins: [ ['env', {}, 'my-env'] ]` | ||
* `file: Object | void` - Information about the plugin's file, if Babel knows it. | ||
* `request: string` - The file that the user requested, e.g. `"@babel/env"` | ||
* `resolved: string` - The full path of the resolved file, e.g. `"/tmp/node_modules/@babel/preset-env/lib/index.js"` | ||
## Options | ||
<blockquote class="babel-callout babel-callout-info"> | ||
<h4>Babel CLI</h4> | ||
<p> | ||
You can pass these options from the Babel CLI like so: | ||
</p> | ||
<p> | ||
<code>babel --option-name<span class="o">=</span>value</code> | ||
</p> | ||
</blockquote> | ||
Following is a table of the options you can use: | ||
| Option | Default | Description | | ||
| ------------------------ | -------------------- | ------------------------------- | | ||
| `ast` | `false` | Include the AST in the returned object | | ||
| `auxiliaryCommentAfter` | `null` | Attach a comment after all non-user injected code | | ||
| `auxiliaryCommentBefore` | `null` | Attach a comment before all non-user injected code | | ||
| `root` | `"."` | Specify the "root" folder that defines the location to search for "babel.config.js", and the default folder to allow `.babelrc` files inside of.| | ||
| `configFile` | `undefined` | The config file to load Babel's config from. Defaults to searching for "babel.config.js" inside the "root" folder. `false` will disable searching for config files.| | ||
| `babelrc` | `true` | Specify whether or not to use .babelrc and .babelignore files. Not available when using the CLI, [use `--no-babelrc` instead](https://babeljs.io/docs/usage/cli/#babel-ignoring-babelrc) | | ||
| `babelrcRoots` | `(root)` | Specify which packages should be search for .babelrc files when they are being compiled. `true` to _always_ search, or a path string or an array of paths to packages to search inside of. Defaults to only searching the "root" package. | | ||
| `envName` | env vars | Defaults to environment variable `BABEL_ENV` if set, or else `NODE_ENV` if set, or else it defaults to `"development"` | | ||
| `code` | `true` | Enable code generation | | ||
| `comments` | `true` | Output comments in generated output | | ||
| `compact` | `"auto"` | Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB | | ||
| `env` | `{}` | This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { /* specific options */ } } }` which will use those options when the `envName` is `production` | | ||
| `extends` | `null` | A path to a `.babelrc` file to extend | | ||
| `filename` | `"unknown"` | Filename for use in errors etc | | ||
| `filenameRelative` | `(filename)` | Filename relative to `sourceRoot` | | ||
| `generatorOpts` | `{}` | An object containing the options to be passed down to the babel code generator, @babel/generator | | ||
| `getModuleId` | `null` | Specify a custom callback to generate a module id with. Called as `getModuleId(moduleName)`. If falsy value is returned then the generated module id is used | | ||
| `highlightCode` | `true` | ANSI highlight syntax error code frames | | ||
| `ignore` | `null` | Opposite to the `only` option. `ignore` is disregarded if `only` is specified | | ||
| `inputSourceMap` | `null` | A source map object that the output source map will be based on | | ||
| `minified` | `false` | Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping `()` from `new` when safe) | | ||
| `moduleId` | `null` | Specify a custom name for module ids | | ||
| `moduleIds` | `false` | If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules) | | ||
| `moduleRoot` | `(sourceRoot)` | Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions | | ||
| `only` | `null` | A [glob](https://github.com/isaacs/minimatch), regex, or mixed array of both, matching paths to **only** compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile a non-matching file it's returned verbatim | | ||
| `parserOpts` | `{}` | An object containing the options to be passed down to the babel parser, @babel/parser | | ||
| `plugins` | `[]` | List of [plugins](https://babeljs.io/docs/plugins/) to load and use | | ||
| `presets` | `[]` | List of [presets](https://babeljs.io/docs/plugins/#presets) (a set of plugins) to load and use | | ||
| `retainLines` | `false` | Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps. (**NOTE:** This will not retain the columns) | | ||
| `shouldPrintComment` | `null` | An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE:** This overrides the `comment` option when used | | ||
| `sourceFileName` | `(filenameRelative)` | Set `sources[0]` on returned source map | | ||
| `sourceMaps` | `false` | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option | | ||
| `sourceRoot` | `(moduleRoot)` | The root from which all sources are relative | | ||
| `sourceType` | `"module"` | Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". `"unambiguous"` will make Babel attempt to _guess_, based on the presence of ES6 `import` or `export` statements. Files with ES6 `import`s and `export`s are considered `"module"` and are otherwise `"script"`. | | ||
| `wrapPluginVisitorMethod`| `null` | An optional callback that can be used to wrap visitor methods. **NOTE:** This is useful for things like introspection, and not really needed for implementing anything. Called as `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122384
41
20
+ Added@babel/code-frame@7.0.0-beta.50(transitive)
+ Added@babel/generator@7.0.0-beta.50(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.50(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.50(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.50(transitive)
+ Added@babel/helpers@7.0.0-beta.50(transitive)
+ Added@babel/highlight@7.0.0-beta.50(transitive)
+ Added@babel/parser@7.0.0-beta.50(transitive)
+ Added@babel/template@7.0.0-beta.50(transitive)
+ Added@babel/traverse@7.0.0-beta.50(transitive)
+ Added@babel/types@7.0.0-beta.50(transitive)
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-unique@0.3.2(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbase@0.11.2(transitive)
+ Addedbraces@2.3.2(transitive)
+ Addedcache-base@1.0.1(transitive)
+ Addedclass-utils@0.3.6(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addedexpand-brackets@2.1.4(transitive)
+ Addedextend-shallow@2.0.13.0.2(transitive)
+ Addedextglob@2.0.4(transitive)
+ Addedfill-range@4.0.0(transitive)
+ Addedfragment-cache@0.2.1(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedhas-value@0.3.11.0.0(transitive)
+ Addedhas-values@0.1.41.0.0(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-extendable@1.0.1(transitive)
+ Addedis-number@3.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedkind-of@4.0.0(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmicromatch@3.1.10(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedms@2.0.0(transitive)
+ Addednanomatch@1.2.13(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedpascalcase@0.1.1(transitive)
+ Addedposix-character-classes@0.1.1(transitive)
+ Addedregex-not@1.0.2(transitive)
+ Addedresolve-url@0.2.1(transitive)
+ Addedret@0.1.15(transitive)
+ Addedsafe-regex@1.1.0(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedsnapdragon@0.8.2(transitive)
+ Addedsnapdragon-node@2.1.1(transitive)
+ Addedsnapdragon-util@3.0.1(transitive)
+ Addedsource-map-resolve@0.5.3(transitive)
+ Addedsource-map-url@0.4.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedto-regex@3.0.2(transitive)
+ Addedto-regex-range@2.1.1(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunset-value@1.0.0(transitive)
+ Addedurix@0.1.0(transitive)
+ Addeduse@3.1.1(transitive)
- Removed@babel/code-frame@7.0.0-beta.49(transitive)
- Removed@babel/generator@7.0.0-beta.49(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.49(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.49(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.49(transitive)
- Removed@babel/helpers@7.0.0-beta.49(transitive)
- Removed@babel/highlight@7.0.0-beta.49(transitive)
- Removed@babel/parser@7.0.0-beta.49(transitive)
- Removed@babel/template@7.0.0-beta.49(transitive)
- Removed@babel/traverse@7.0.0-beta.49(transitive)
- Removed@babel/types@7.0.0-beta.49(transitive)
- Removedarr-diff@2.0.0(transitive)
- Removedarray-unique@0.2.1(transitive)
- Removedbraces@1.8.5(transitive)
- Removedexpand-brackets@0.1.5(transitive)
- Removedexpand-range@1.8.2(transitive)
- Removedextglob@0.3.2(transitive)
- Removedfilename-regex@2.0.1(transitive)
- Removedfill-range@2.2.4(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedglob-base@0.3.0(transitive)
- Removedglob-parent@2.0.0(transitive)
- Removedis-dotfile@1.0.3(transitive)
- Removedis-equal-shallow@0.1.3(transitive)
- Removedis-extglob@1.0.0(transitive)
- Removedis-glob@2.0.1(transitive)
- Removedis-number@2.1.04.0.0(transitive)
- Removedis-posix-bracket@0.1.1(transitive)
- Removedis-primitive@2.0.0(transitive)
- Removedmath-random@1.0.4(transitive)
- Removedmicromatch@2.3.11(transitive)
- Removednormalize-path@2.1.1(transitive)
- Removedobject.omit@2.0.1(transitive)
- Removedparse-glob@3.0.4(transitive)
- Removedpreserve@0.2.0(transitive)
- Removedrandomatic@3.1.1(transitive)
- Removedregex-cache@0.4.4(transitive)
- Removedremove-trailing-separator@1.1.0(transitive)
Updated@babel/helpers@7.0.0-beta.50
Updated@babel/parser@7.0.0-beta.50
Updated@babel/types@7.0.0-beta.50
Updatedmicromatch@^3.1.10