Skip to content

Commit

Permalink
feat(experimental): dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
h13i32maru committed Nov 26, 2016
1 parent 8803005 commit d729f5f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"cheerio": "0.20.0",
"color-logger": "0.0.3",
"escape-html": "1.0.3",
"babylon": "6.11.2",
"babylon": "6.14.1",
"babel-generator": "6.11.4",
"babel-traverse": "6.12.0",
"fs-extra": "0.30.0",
Expand Down
1 change: 1 addition & 0 deletions src/Parser/ESParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default class ESParser {
if (experimental.asyncGenerators) option.plugins.push('asyncGenerators');
if (experimental.decorators) option.plugins.push('decorators');
if (experimental.exportExtensions) option.plugins.push('exportExtensions');
if (experimental.dynamicImport) option.plugins.push('dynamicImport');
}

return option;
Expand Down
1 change: 1 addition & 0 deletions src/Typedef/typedef.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @property {boolean} experimentalProposal.asyncGenerators
* @property {boolean} experimentalProposal.decorators
* @property {boolean} experimentalProposal.exportExtensions
* @property {boolean} experimentalProposal.dynamicImport
* @see https://esdoc.org/config.html
*/

Expand Down
5 changes: 5 additions & 0 deletions test/fixture/syntax/DynamicImport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
for (let i = 0; i < 10; i++) {
import(`mod${$i}.js`)
.then(module => console.log(module))
.catch(err => console.log(err));
}
5 changes: 5 additions & 0 deletions test/src/ParserTest/ESParserTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ describe('ESParser', ()=>{
const ast = ESParser.parse({experimentalProposal: {exportExtensions: true}}, './test/fixture/syntax/ExportExtensions.js');
assert(ast.program.sourceType === 'module');
});

it('can parse "dynamic import"', ()=>{
const ast = ESParser.parse({experimentalProposal: {dynamicImport: true}}, './test/fixture/syntax/DynamicImport.js');
assert(ast.program.sourceType === 'module');
});
});

0 comments on commit d729f5f

Please sign in to comment.