Skip to content

Commit

Permalink
Merge pull request #181 from juandopazo/imports
Browse files Browse the repository at this point in the history
Support for ImportDeclaration
  • Loading branch information
Constellation committed Apr 30, 2014
2 parents 5cd21f9 + 1bde328 commit 0e3d962
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions escodegen.js
Expand Up @@ -92,6 +92,7 @@
GeneratorExpression: 'GeneratorExpression',
Identifier: 'Identifier',
IfStatement: 'IfStatement',
ImportDeclaration: 'ImportDeclaration',
Literal: 'Literal',
LabeledStatement: 'LabeledStatement',
LogicalExpression: 'LogicalExpression',
Expand Down Expand Up @@ -1679,6 +1680,34 @@
}
break;

case Syntax.ImportDeclaration:
result = ['import '];
// ES6: 15.2.1 valid import declarations:
// - import ImportClause FromClause ;
// - import ModuleSpecifier ;
// If no ImportClause is present,
// this should be `import ModuleSpecifier` so skip `from`
if (stmt.specifiers.length > 0) {
if (stmt.kind === 'named') {
result.push(
'{',
stmt.specifiers.map(function (specifier) {
var clause = specifier.id.name;
if (specifier.name) {
clause += ' as ' + specifier.name.name;
}
return clause;
}).join(','),
'} '
);
} else if (stmt.kind === 'default') {
result.push(stmt.specifiers[0].id.name + ' ');
}
result.push('from ');
}
result.push(stmt.source.raw, semicolon);
break;

case Syntax.VariableDeclarator:
if (stmt.init) {
result = [
Expand Down
3 changes: 3 additions & 0 deletions test/compare-harmony/imports.expected.js
@@ -0,0 +1,3 @@
import foo from 'foo';
import {foo} from 'foo';
import {foo as bar} from 'foo';
3 changes: 3 additions & 0 deletions test/compare-harmony/imports.js
@@ -0,0 +1,3 @@
import foo from 'foo';
import {foo} from 'foo';
import {foo as bar} from 'foo';

0 comments on commit 0e3d962

Please sign in to comment.