use of com.github.anba.es6draft.runtime.modules.MalformedNameException in project es6draft by anba.
the class NodeModuleResolution method resolve.
/**
* Resolves a module name.
*
* @param baseDirectory
* the base directory
* @param normalizedName
* the normalized module identifier
* @param unnormalizedName
* the unnormalized module identifier
* @param referrerId
* the referrer module identifier or {@code null}
* @return the resolved and normalized module identifier
* @throws MalformedNameException
* if the name cannot be normalized
*/
public static FileSourceIdentifier resolve(Path baseDirectory, FileSourceIdentifier normalizedName, String unnormalizedName, SourceIdentifier referrerId) throws MalformedNameException {
try {
Path normalizedPath = normalizedName.getPath();
boolean isRelative = unnormalizedName.startsWith("./") || unnormalizedName.startsWith("../");
if (isRelative) {
Path file = findModuleFile(baseDirectory, normalizedPath, true);
if (file != null) {
return new FileSourceIdentifier(baseDirectory, file);
}
} else if (referrerId != null) {
for (Path p : new NodeModulePaths(baseDirectory, referrerId)) {
Path file = findModuleFile(baseDirectory, p.resolve(normalizedPath), true);
if (file != null) {
return new FileSourceIdentifier(baseDirectory, file);
}
}
}
return normalizedName;
} catch (InvalidPathException e) {
throw new MalformedNameException(unnormalizedName);
}
}
use of com.github.anba.es6draft.runtime.modules.MalformedNameException in project es6draft by anba.
the class ModuleNamespaceObject method getValue.
/** 9.4.6.8 [[Get]] (P, Receiver) */
@Override
protected Object getValue(ExecutionContext cx, String propertyKey, Object receiver) {
/* step 1 (not applicable) */
/* step 2 (not applicable) */
/* step 3 */
Set<String> exports = this.exports;
/* step 4 */
if (!exports.contains(propertyKey)) {
return UNDEFINED;
}
/* step 5 */
ModuleRecord m = this.module;
/* steps 6-8 */
ModuleExport binding;
try {
/* steps 6, 8 */
binding = m.resolveExport(propertyKey, new HashMap<>(), new HashSet<>());
} catch (IOException e) {
/* step 7 */
throw Errors.newInternalError(cx, e, Messages.Key.ModulesIOException, e.getMessage());
} catch (ResolutionException | MalformedNameException e) {
/* step 7 */
throw e.toScriptException(cx);
} catch (ParserException | CompilationException e) {
/* step 7 */
throw e.toScriptException(cx);
}
/* step 8 */
assert binding != null && !binding.isAmbiguous();
/* step 9 */
ModuleRecord targetModule = binding.getModule();
/* step 10 */
assert targetModule != null;
/* step 11 */
LexicalEnvironment<?> targetEnv = targetModule.getEnvironment();
/* step 12 */
if (targetEnv == null) {
throw newReferenceError(cx, Messages.Key.UninitializedBinding, binding.getBindingName());
}
/* step ? (Extension: Export From) */
if (binding.isNameSpaceExport()) {
try {
return GetModuleNamespace(cx, targetModule);
} catch (IOException e) {
throw Errors.newInternalError(cx, Messages.Key.ModulesIOException, e.getMessage());
} catch (MalformedNameException | ResolutionException e) {
throw e.toScriptException(cx);
}
}
/* step 13 */
EnvironmentRecord targetEnvRec = targetEnv.getEnvRec();
/* step 14 */
return targetEnvRec.getBindingValue(binding.getBindingName(), true);
}
use of com.github.anba.es6draft.runtime.modules.MalformedNameException in project es6draft by anba.
the class TraceurFileModuleLoader method normalizeName.
@Override
public FileSourceIdentifier normalizeName(String unnormalizedName, SourceIdentifier referrerId) throws MalformedNameException {
FileSourceIdentifier normalizedName = super.normalizeName(unnormalizedName, referrerId);
try {
Path fileName = normalizedName.getPath().getFileName();
if (!fileName.toString().endsWith(".js")) {
Path path = Paths.get(normalizedName.getPath() + ".js");
normalizedName = new FileSourceIdentifier(getBaseDirectory(), path);
}
return normalizedName;
} catch (InvalidPathException e) {
throw new MalformedNameException(unnormalizedName);
}
}
Aggregations