From 48b206d969e00d3738ca6aa8a88fd00916f282e1 Mon Sep 17 00:00:00 2001 From: Jordan Gensler Date: Mon, 17 Oct 2016 11:02:00 -0400 Subject: [PATCH] [import()] Initial support for dynamic-import (#4699) * [import()] Initial support for function-like import * [import()] Renaming import-functions to dynamic-import * [stage-2] Fixing lint error * add to package.json --- README.md | 1 + .../.npmignore | 3 ++ .../README.md | 35 +++++++++++++++++++ .../package.json | 13 +++++++ .../src/index.js | 7 ++++ packages/babel-preset-stage-2/package.json | 1 + packages/babel-preset-stage-2/src/index.js | 2 ++ 7 files changed, 62 insertions(+) create mode 100644 packages/babel-plugin-syntax-dynamic-import/.npmignore create mode 100644 packages/babel-plugin-syntax-dynamic-import/README.md create mode 100644 packages/babel-plugin-syntax-dynamic-import/package.json create mode 100644 packages/babel-plugin-syntax-dynamic-import/src/index.js diff --git a/README.md b/README.md index a1e009969ce89..0461ebcf66954 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,7 @@ These just enable the transform plugins to be able to parse certain features (th | [`babel-plugin-syntax-flow`](/packages/babel-plugin-syntax-flow) | [![npm](https://img.shields.io/npm/v/babel-plugin-syntax-flow.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-syntax-flow) | | [`babel-plugin-syntax-function-bind`](/packages/babel-plugin-syntax-function-bind) | [![npm](https://img.shields.io/npm/v/babel-plugin-syntax-function-bind.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-syntax-function-bind) | | [`babel-plugin-syntax-function-sent`](/packages/babel-plugin-syntax-function-sent) | [![npm](https://img.shields.io/npm/v/babel-plugin-syntax-function-sent.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-syntax-function-sent) | +| [`babel-plugin-syntax-dynamic-import`](/packages/babel-plugin-syntax-dynamic-import) | [![npm](https://img.shields.io/npm/v/babel-plugin-syntax-dynamic-import.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-syntax-dynamic-import) | | [`babel-plugin-syntax-jsx`](/packages/babel-plugin-syntax-jsx) | [![npm](https://img.shields.io/npm/v/babel-plugin-syntax-jsx.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-syntax-jsx) | | [`babel-plugin-syntax-object-rest-spread`](/packages/babel-plugin-syntax-object-rest-spread) | [![npm](https://img.shields.io/npm/v/babel-plugin-syntax-object-rest-spread.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-plugin-syntax-object-rest-spread) | diff --git a/packages/babel-plugin-syntax-dynamic-import/.npmignore b/packages/babel-plugin-syntax-dynamic-import/.npmignore new file mode 100644 index 0000000000000..cace0d6ddcdd0 --- /dev/null +++ b/packages/babel-plugin-syntax-dynamic-import/.npmignore @@ -0,0 +1,3 @@ +node_modules +*.log +src diff --git a/packages/babel-plugin-syntax-dynamic-import/README.md b/packages/babel-plugin-syntax-dynamic-import/README.md new file mode 100644 index 0000000000000..47279fcd36d3e --- /dev/null +++ b/packages/babel-plugin-syntax-dynamic-import/README.md @@ -0,0 +1,35 @@ +# babel-plugin-syntax-dynamic-import + +Allow parsing of `import()`. + +## Installation + +```sh +$ npm install babel-plugin-syntax-dynamic-import +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["syntax-dynamic-import"] +} +``` + +### Via CLI + +```sh +$ babel --plugins syntax-dynamic-import script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["syntax-dynamic-import"] +}); +``` diff --git a/packages/babel-plugin-syntax-dynamic-import/package.json b/packages/babel-plugin-syntax-dynamic-import/package.json new file mode 100644 index 0000000000000..ab6baf23dcede --- /dev/null +++ b/packages/babel-plugin-syntax-dynamic-import/package.json @@ -0,0 +1,13 @@ +{ + "name": "babel-plugin-syntax-dynamic-import", + "version": "6.13.0", + "description": "Allow parsing of import()", + "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-dynamic-import", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": {}, + "devDependencies": {} +} diff --git a/packages/babel-plugin-syntax-dynamic-import/src/index.js b/packages/babel-plugin-syntax-dynamic-import/src/index.js new file mode 100644 index 0000000000000..729c741629814 --- /dev/null +++ b/packages/babel-plugin-syntax-dynamic-import/src/index.js @@ -0,0 +1,7 @@ +export default function () { + return { + manipulateOptions(opts, parserOpts) { + parserOpts.plugins.push("dynamicImport"); + } + }; +} diff --git a/packages/babel-preset-stage-2/package.json b/packages/babel-preset-stage-2/package.json index 625af40a7007f..2540371b7d2a2 100644 --- a/packages/babel-preset-stage-2/package.json +++ b/packages/babel-preset-stage-2/package.json @@ -10,6 +10,7 @@ "dependencies": { "babel-plugin-transform-class-properties": "^6.16.0", "babel-plugin-transform-decorators": "^6.13.0", + "babel-plugin-syntax-dynamic-import": "^6.13.0", "babel-preset-stage-3": "^6.17.0" } } diff --git a/packages/babel-preset-stage-2/src/index.js b/packages/babel-preset-stage-2/src/index.js index 9898fe8c49358..7e9e8a2864c7f 100644 --- a/packages/babel-preset-stage-2/src/index.js +++ b/packages/babel-preset-stage-2/src/index.js @@ -2,12 +2,14 @@ import presetStage3 from "babel-preset-stage-3"; import transformClassProperties from "babel-plugin-transform-class-properties"; import transformDecorators from "babel-plugin-transform-decorators"; +import syntaxDynamicImport from "babel-plugin-syntax-dynamic-import"; export default { presets: [ presetStage3 ], plugins: [ + syntaxDynamicImport, transformClassProperties, transformDecorators ]