(node: ts.ImportDeclaration)
| 376 | } |
| 377 | |
| 378 | parseImportDeclaration(node: ts.ImportDeclaration): syntax.ImportDeclaration { |
| 379 | const {importClause, moduleSpecifier} = node; |
| 380 | if (!ts.isStringLiteral(moduleSpecifier)) |
| 381 | throw new UnsupportedError(node, 'Module name must be string literal'); |
| 382 | const fileName = getFileNameFromModuleSpecifier(moduleSpecifier.text); |
| 383 | const decl = new syntax.ImportDeclaration(fileName, getNamespaceFromFileName(fileName)); |
| 384 | // import 'module' |
| 385 | if (!importClause) |
| 386 | return decl; |
| 387 | const {name, namedBindings} = importClause; |
| 388 | if (!name && !namedBindings) |
| 389 | throw new UnimplementedError(node, 'Import module without names is not supported'); |
| 390 | // import xxx from 'module' |
| 391 | if (name) |
| 392 | throw new UnimplementedError(node, 'Default import has not been implemented'); |
| 393 | if (namedBindings) { |
| 394 | if (ts.isNamedImports(namedBindings)) { |
| 395 | // import {A, B, C} from 'module' |
| 396 | const {elements} = namedBindings; |
| 397 | decl.names = elements.filter(e => !e.propertyName) |
| 398 | .map(e => e.name.text); |
| 399 | decl.aliases = elements.filter(e => e.propertyName) |
| 400 | .map(e => [ e.propertyName!.text, e.name.text ]); |
| 401 | } else { |
| 402 | // import * as xxx from 'module' |
| 403 | decl.namespaceAlias = namedBindings.name.text; |
| 404 | } |
| 405 | } |
| 406 | return decl; |
| 407 | } |
| 408 | |
| 409 | parseVariableDeclarationList(node: ts.VariableDeclarationList): syntax.VariableDeclarationList { |
| 410 | const decls = node.declarations.map(this.parseVariableDeclaration.bind(this)); |
no test coverage detected