Search in sources :

Example 11 with ResolutionException

use of com.github.anba.es6draft.runtime.modules.ResolutionException in project es6draft by anba.

the class ModuleOperations method resolveImportOrThrow.

/**
 * 15.2.1.16.4.2 ModuleDeclarationEnvironmentSetup( module )
 *
 * @param module
 *            the module record
 * @param moduleRequest
 *            the module specifier string
 * @param importName
 *            the import name
 * @return the resolved module import
 * @throws IOException
 *             if there was any I/O error
 * @throws MalformedNameException
 *             if the module specifier cannot be normalized
 * @throws ResolutionException
 *             if the export cannot be resolved
 */
public static ResolvedBinding resolveImportOrThrow(SourceTextModuleRecord module, String moduleRequest, String importName) throws IOException, MalformedNameException, ResolutionException {
    /* steps 8.a-b */
    ModuleRecord importedModule = HostResolveImportedModule(module, moduleRequest);
    /* step 8.c (not applicable) */
    /* step 8.d.i */
    ResolvedBinding resolution = importedModule.resolveExport(importName, new HashMap<>());
    /* step 8.d.ii */
    if (resolution == null) {
        throw new ResolutionException(Messages.Key.ModulesUnresolvedImport, importName, importedModule.getSourceCodeId().toString());
    }
    if (resolution.isAmbiguous()) {
        throw new ResolutionException(Messages.Key.ModulesAmbiguousImport, importName, importedModule.getSourceCodeId().toString());
    }
    return resolution;
}
Also used : ResolutionException(com.github.anba.es6draft.runtime.modules.ResolutionException) ModuleRecord(com.github.anba.es6draft.runtime.modules.ModuleRecord) SourceTextModuleRecord(com.github.anba.es6draft.runtime.modules.SourceTextModuleRecord) ResolvedBinding(com.github.anba.es6draft.runtime.modules.ResolvedBinding)

Aggregations

ResolutionException (com.github.anba.es6draft.runtime.modules.ResolutionException)11 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)8 IOException (java.io.IOException)6 MalformedNameException (com.github.anba.es6draft.runtime.modules.MalformedNameException)5 SourceTextModuleRecord (com.github.anba.es6draft.runtime.modules.SourceTextModuleRecord)4 Realm (com.github.anba.es6draft.runtime.Realm)3 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)3 ModuleExport (com.github.anba.es6draft.runtime.modules.ModuleExport)3 ResolvedBinding (com.github.anba.es6draft.runtime.modules.ResolvedBinding)3 CompilationException (com.github.anba.es6draft.compiler.CompilationException)2 ParserException (com.github.anba.es6draft.parser.ParserException)2 ToString (com.github.anba.es6draft.runtime.AbstractOperations.ToString)2 EnvironmentRecord (com.github.anba.es6draft.runtime.EnvironmentRecord)2 InternalThrowable (com.github.anba.es6draft.runtime.internal.InternalThrowable)2 Source (com.github.anba.es6draft.runtime.internal.Source)2 ModuleLoader (com.github.anba.es6draft.runtime.modules.ModuleLoader)2 SourceIdentifier (com.github.anba.es6draft.runtime.modules.SourceIdentifier)2 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)2 HashMap (java.util.HashMap)2 Script (com.github.anba.es6draft.Script)1