ImportDeclaration builds the goja ImportDeclaration for a top-level `import { ... } from "module"` statement, or a side-effect import (`import "module"`) when decl.SideEffect is true.
(decl *ImportDeclaration)
| 850 | // `import { ... } from "module"` statement, or a side-effect import |
| 851 | // (`import "module"`) when decl.SideEffect is true. |
| 852 | func (b *Bindings) ImportDeclaration(decl *ImportDeclaration) (*goja.Object, error) { |
| 853 | declF, err := b.f("importDeclaration") |
| 854 | if err != nil { |
| 855 | return nil, err |
| 856 | } |
| 857 | |
| 858 | var namedImports goja.Value |
| 859 | if decl.SideEffect { |
| 860 | namedImports = goja.Undefined() |
| 861 | } else { |
| 862 | specifiers := make([]interface{}, 0, len(decl.Named)) |
| 863 | for _, n := range decl.Named { |
| 864 | obj, err := b.ImportSpecifier(n) |
| 865 | if err != nil { |
| 866 | return nil, fmt.Errorf("import specifier %q: %w", n.Name, err) |
| 867 | } |
| 868 | specifiers = append(specifiers, obj) |
| 869 | } |
| 870 | namedImports = b.vm.NewArray(specifiers...) |
| 871 | } |
| 872 | |
| 873 | res, err := declF(goja.Undefined(), |
| 874 | b.vm.ToValue(decl.IsTypeOnly), |
| 875 | b.vm.ToValue(decl.Module), |
| 876 | namedImports, |
| 877 | ) |
| 878 | if err != nil { |
| 879 | return nil, xerrors.Errorf("call importDeclaration: %w", err) |
| 880 | } |
| 881 | return res.ToObject(b.vm), nil |
| 882 | } |
| 883 | |
| 884 | // IdentifierExpression builds the goja node for a value-position identifier |
| 885 | // such as `z` or `BaseSchema`. |
no test coverage detected