babel-plugin-system-import-transformer
Advanced tools
Comparing version 2.4.0 to 3.0.0
@@ -9,6 +9,15 @@ 'use strict'; | ||
return { | ||
inherits: _babelPluginSyntaxDynamicImport2.default, | ||
visitor: { | ||
CallExpression: function CallExpression(path, state) { | ||
var callee = path.get('callee'); | ||
if (callee && callee.matchesPattern('System.import')) { | ||
if (!callee) { | ||
return; | ||
} | ||
var pluginOptions = state.opts || {}; | ||
var syntax = pluginOptions.syntax || {}; | ||
if (syntax["system-import"] !== false && callee.matchesPattern(PATTERN_SYSTEM_IMPORT) || syntax.import !== false && callee.type === TYPE_IMPORT) { | ||
var params = path.get('arguments'); | ||
@@ -29,2 +38,6 @@ if (params.length) { | ||
var _babelPluginSyntaxDynamicImport = require('babel-plugin-syntax-dynamic-import'); | ||
var _babelPluginSyntaxDynamicImport2 = _interopRequireDefault(_babelPluginSyntaxDynamicImport); | ||
var _babelArgumentProvider = require('./babelArgumentProvider'); | ||
@@ -36,2 +49,5 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var PATTERN_SYSTEM_IMPORT = 'System.import'; | ||
var TYPE_IMPORT = 'Import'; |
{ | ||
"name": "babel-plugin-system-import-transformer", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"description": "Babel plugin that replaces System.import with the equivalent UMD pattern", | ||
@@ -31,7 +31,7 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.9.0", | ||
"babel-core": "^6.9.1", | ||
"babel-plugin-transform-runtime": "^6.9.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-register": "^6.9.0", | ||
"babel-cli": "^6.14.0", | ||
"babel-core": "^6.14.0", | ||
"babel-plugin-transform-runtime": "^6.15.0", | ||
"babel-preset-es2015": "^6.14.0", | ||
"babel-register": "^6.14.0", | ||
"chalk": "^1.1.3", | ||
@@ -42,3 +42,6 @@ "clear": "0.0.1", | ||
"watch": "^0.18.0" | ||
}, | ||
"dependencies": { | ||
"babel-plugin-syntax-dynamic-import": "^6.18.0" | ||
} | ||
} |
@@ -6,3 +6,3 @@ # babel-plugin-system-import-transformer | ||
[Babel](https://babeljs.io/) plugin that replaces System.import with the equivalent UMD pattern | ||
[Babel](https://babeljs.io/) plugin that replaces import() & System.import() with the equivalent UMD pattern | ||
@@ -12,2 +12,8 @@ ## Transforms | ||
```js | ||
import('./utils/serializer').then(function(module){ | ||
console.log(module); | ||
}); | ||
// AND | ||
System.import('./utils/serializer').then(function(module){ | ||
@@ -37,5 +43,7 @@ console.log(module); | ||
- Babel v6.x.x | ||
- Babel v6.14.x | ||
**Note:** for babel v5 please use the [v1.x.x releases](https://github.com/thgreasi/babel-plugin-system-import-transformer/tree/v1.x.x-stable). | ||
**Notes:** | ||
- for babel < v6.14 please use the [v2.x.x releases](https://github.com/thgreasi/babel-plugin-system-import-transformer/tree/v2.x.x-stable). | ||
- for babel v5 please use the [v1.x.x releases](https://github.com/thgreasi/babel-plugin-system-import-transformer/tree/v1.x.x-stable). | ||
@@ -86,7 +94,13 @@ ## Installation | ||
### AMD & CommonJS | ||
## Options | ||
When you are transforming to `AMD` or `CommonJS` modules you should set the respective plugin option: | ||
### modules | ||
Type: String | ||
Values: [**`UMD`**/`amd`/`common`] | ||
[Example](test/fixtures/common/.babelrc_extra) | ||
Specifies the target compilation module system. When set configured to an option other than `UMD` then `system-import-transformer` will omit the module type detection code and just insert the appropriate require statement wrapped with a `Promise`. | ||
```js | ||
// AMD | ||
// targeting AMD | ||
{ | ||
@@ -98,3 +112,11 @@ "plugins": [ | ||
// CommonJS | ||
// will emit an AMD specific code like: | ||
new Promise(function (resolve, reject) { | ||
var global = window; | ||
global.require(['utilsSerializer'], resolve, reject); | ||
}).then(function(module){ console.log(module); }); | ||
``` | ||
```js | ||
// targeting CommonJS | ||
{ | ||
@@ -105,12 +127,4 @@ "plugins": [ | ||
} | ||
``` | ||
`system-import-transformer` will omit the module type detection code and just insert the appropriate require statement wrapped with a `Promise`. | ||
```js | ||
// AMD | ||
new Promise(function (resolve, reject) { | ||
var global = window; | ||
global.require(['utilsSerializer'], resolve, reject); | ||
}).then(function(module){ console.log(module); }); | ||
// CommonJS | ||
// will emit a CommonJS specific code like: | ||
new Promise(function (resolve, reject) { | ||
@@ -121,2 +135,16 @@ resolve(require('./utils/serializer')); | ||
**Note**: the default transpilation target is UMD | ||
### syntax | ||
#### syntax.import | ||
Type: Boolean | ||
Values: [**`true`**/`false`] | ||
[Example](test/fixtures/umd-no-import/.babelrc_extra) | ||
When set to `false`, babel will not transpile `import()` statements. | ||
#### syntax["system-import"] | ||
Type: Boolean | ||
Values: [**`true`**/`false`] | ||
[Example](test/fixtures/umd-no-system-import/.babelrc_extra) | ||
When set to `false`, babel will not transpile `System.import()` statements. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
25712
297
144
1
+ Addedbabel-plugin-syntax-dynamic-import@6.18.0(transitive)