Skip to content

Commit 7fc4475

Browse files
Muntermichaelficarra
authored andcommitted
Support dynamic import (#100)
* Add support for dynamic Import expressions. See https://tc39.github.io/proposal-dynamic-import/ * Added skipped failing tests for dynamic import. Tests depend on espree supporting dynamic import * Update dynamic import test with literal parse tree instead of depending on espree having dynamic import support * Align with estree/estree#198
1 parent 6ebdf08 commit 7fc4475

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

estraverse.js

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
GeneratorExpression: 'GeneratorExpression', // CAUTION: It's deferred to ES7.
109109
Identifier: 'Identifier',
110110
IfStatement: 'IfStatement',
111+
ImportExpression: 'ImportExpression',
111112
ImportDeclaration: 'ImportDeclaration',
112113
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
113114
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
@@ -182,6 +183,7 @@
182183
GeneratorExpression: ['blocks', 'filter', 'body'], // CAUTION: It's deferred to ES7.
183184
Identifier: [],
184185
IfStatement: ['test', 'consequent', 'alternate'],
186+
ImportExpression: ['source'],
185187
ImportDeclaration: ['specifiers', 'source'],
186188
ImportDefaultSpecifier: ['local'],
187189
ImportNamespaceSpecifier: ['local'],

test/es6.js

+26
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,32 @@ describe('import', function() {
320320
});
321321
});
322322

323+
describe('dynamic import', function() {
324+
it('expression pattern #1', function() {
325+
// TODO: espree currently doesn't support dynamic imports. Update when it does
326+
// const tree = espree(`import('rabbit-house')`, {
327+
// ecmaFeatures: {
328+
// modules: true
329+
// }
330+
// });
331+
332+
const tree = {
333+
type: 'ImportExpression',
334+
source: {
335+
type: 'Literal',
336+
value: 'rabbit-house'
337+
}
338+
};
339+
340+
checkDump(Dumper.dump(tree), `
341+
enter - ImportExpression
342+
enter - Literal
343+
leave - Literal
344+
leave - ImportExpression
345+
`);
346+
});
347+
});
348+
323349
describe('pattern', function() {
324350
it('assignment pattern#1', function() {
325351
const tree = {

0 commit comments

Comments
 (0)