ImportSpecifier builds the goja ImportSpecifier for a single named import. When Alias is empty, this emits `Name`. When Alias is set, this emits `Name as Alias` by passing Name as the TypeScript propertyName and Alias as the local binding name.
(spec *ImportSpecifier)
| 823 | // `Name as Alias` by passing Name as the TypeScript propertyName and Alias |
| 824 | // as the local binding name. |
| 825 | func (b *Bindings) ImportSpecifier(spec *ImportSpecifier) (*goja.Object, error) { |
| 826 | specF, err := b.f("importSpecifier") |
| 827 | if err != nil { |
| 828 | return nil, err |
| 829 | } |
| 830 | |
| 831 | var propertyName goja.Value = goja.Undefined() |
| 832 | localName := spec.Name |
| 833 | if spec.Alias != "" { |
| 834 | propertyName = b.vm.ToValue(spec.Name) |
| 835 | localName = spec.Alias |
| 836 | } |
| 837 | |
| 838 | res, err := specF(goja.Undefined(), |
| 839 | b.vm.ToValue(spec.IsTypeOnly), |
| 840 | propertyName, |
| 841 | b.vm.ToValue(localName), |
| 842 | ) |
| 843 | if err != nil { |
| 844 | return nil, xerrors.Errorf("call importSpecifier: %w", err) |
| 845 | } |
| 846 | return res.ToObject(b.vm), nil |
| 847 | } |
| 848 | |
| 849 | // ImportDeclaration builds the goja ImportDeclaration for a top-level |
| 850 | // `import { ... } from "module"` statement, or a side-effect import |