Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 7723827

Browse files
committed
limited dynamic import support
1 parent 5938d8e commit 7723827

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

compilers/esm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var traceur = require('traceur');
22
var traceurGet = require('../lib/utils').traceurGet;
33

4+
var syntaxDynamicImport = require('babel-plugin-syntax-dynamic-import');
5+
46
var ParseTreeTransformer = traceurGet('codegeneration/ParseTreeTransformer.js').ParseTreeTransformer;
57
var ModuleSpecifier = traceurGet('syntax/trees/ParseTrees.js').ModuleSpecifier;
68
var createStringLiteralToken = traceurGet('codegeneration/ParseTreeFactory.js').createStringLiteralToken;
@@ -63,6 +65,7 @@ exports.attach = function(loader) {
6365
//sourceFileName: load.path,
6466
inputSourceMap: load.metadata.sourceMap,
6567
ast: true,
68+
plugins: [syntaxDynamicImport],
6669
resolveModuleSource: function(dep) {
6770
if (depsList.indexOf(dep) == -1)
6871
depsList.push(dep);
@@ -91,7 +94,7 @@ exports.compile = function(load, opts, loader) {
9194
var babelOptions = {
9295
babelrc: false,
9396
compact: false,
94-
plugins: [[require('babel-plugin-transform-es2015-modules-systemjs'), { systemGlobal: opts.systemGlobal }]],
97+
plugins: [syntaxDynamicImport, [require('babel-plugin-transform-es2015-modules-systemjs'), { systemGlobal: opts.systemGlobal }]],
9598
filename: load.path,
9699
//sourceFileName: load.path,
97100
sourceMaps: !!opts.sourceMaps,

lib/rollup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports.rollupTree = function(loader, tree, entryPoints, traceOpts, compileOpts,
2626
var entryMap = {};
2727

2828
function isESM(moduleName) {
29-
return tree[moduleName] && tree[moduleName].metadata && tree[moduleName].metadata.format == 'esm' && !tree[moduleName].metadata.originalSource;
29+
return tree[moduleName] && tree[moduleName].metadata && tree[moduleName].metadata.format == 'esm' && !tree[moduleName].metadata.originalSource && !tree[moduleName].source.match(/\s+import\s*\(/);
3030
}
3131

3232
// for each module in the tree, we traverse the whole tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"dependencies": {
77
"babel-core": "^6.24.1",
8+
"babel-plugin-syntax-dynamic-import": "^6.18.0",
89
"babel-plugin-transform-amd-system-wrapper": "^0.3.7",
910
"babel-plugin-transform-cjs-system-wrapper": "^0.6.2",
1011
"babel-plugin-transform-es2015-modules-systemjs": "^6.6.5",

0 commit comments

Comments
 (0)