You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i found the following and i guess es4x is using a own require import implementation is that correct?
/* * Copyright 2018 Red Hat, Inc. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Apache License v2.0 which accompanies this distribution. * * The Eclipse Public License is available at * http://www.eclipse.org/legal/epl-v10.html * * The Apache License v2.0 is available at * http://www.opensource.org/licenses/apache2.0.php * * You may elect to redistribute this code under either of these licenses. */packageio.reactiverse.es4x.impl;
importio.vertx.core.Vertx;
importio.vertx.core.buffer.Buffer;
importio.vertx.core.file.FileSystem;
importio.vertx.core.logging.Logger;
importio.vertx.core.logging.LoggerFactory;
importjava.io.IOException;
importjava.net.URI;
importjava.net.URISyntaxException;
importjava.util.function.Function;
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
publicclassESModuleIO {
privatestaticfinalLoggerLOGGER = LoggerFactory.getLogger(ESModuleIO.class);
privatestaticfinalPatternimportDef = Pattern.compile("import (\\* as [a-zA-Z_$][0-9a-zA-Z_$]*|\\{.+?}) from ['\"]([0-9a-zA-Z_$@./\\- ]+)['\"];?", Pattern.DOTALL);
privatestaticfinalPatternexportDef = Pattern.compile("\\{(.+?)}", Pattern.DOTALL);
privatestaticfinalPatternaliasDef = Pattern.compile("(\\*|[a-zA-Z_$][0-9a-zA-Z_$]*) as ([a-zA-Z_$][0-9a-zA-Z_$]*)", Pattern.DOTALL);
privatestaticStringreplace(Stringsource, Patternpattern, Function<Matcher, String> fn) {
finalMatcherm = pattern.matcher(source);
booleanresult = m.find();
if (result) {
StringBuildersb = newStringBuilder(source.length());
intp = 0;
do {
sb.append(source, p, m.start());
sb.append(fn.apply(m));
p = m.end();
} while (m.find());
sb.append(source, p, source.length());
returnsb.toString();
}
returnsource;
}
publicstaticStringadapt(Stringstatement) {
returnreplace(statement, importDef, importMatcher -> {
LOGGER.debug(importMatcher.group(0));
finalStringexports = importMatcher.group(1);
finalStringmodule = importMatcher.group(2);
// is it single or multiplefinalMatcherexportMatcher = exportDef.matcher(exports);
finalStringBuildersb = newStringBuilder();
if (exportMatcher.find()) {
finalString[] multi = exportMatcher.group(1).split("\\s*,\\s*");
for (Stringsingle : multi) {
sb.append(adaptImport(single.trim(), module));
}
} else {
sb.append(adaptImport(exports.trim(), module));
}
// ensure that the line numbers matchfor (inti = 0; i < exports.length(); i++) {
if (exports.charAt(i) == '\r' || exports.charAt(i) == '\n') {
sb.append(exports.charAt(i));
}
}
returnsb.toString();
});
}
privatestaticStringadaptImport(finalStringexports, finalStringmodule) {
finalMatcheraliasMatcher = aliasDef.matcher(exports);
if (aliasMatcher.find()) {
finalStringbase = aliasMatcher.group(1).trim();
finalStringalias = aliasMatcher.group(2).trim();
if ("*".equals(base)) {
return"const " + alias + " = require('" + module + "');";
} else {
return"const " + alias + " = require('" + module + "')." + base + ";";
}
} else {
return"const " + exports + " = require('" + module + "')." + exports + ";";
}
}
privatefinalFileSystemfs;
publicESModuleIO(Vertxvertx) {
this.fs = vertx.fileSystem();
}
publicStringgetParent(Stringuri) throwsURISyntaxException {
switch (uri) {
case"jar:":
case"file:":
thrownewRuntimeException("Cannot get parent of root.");
default:
returngetParent(newURI(uri));
}
}
publicStringgetParent(URIuri) {
finalStringpath = uri.getPath();
intlast = path.lastIndexOf('/');
if (path.length() > last) {
returnuri.getScheme() + ':' + path.substring(0, last);
}
thrownewRuntimeException("Cannot get parent of root.");
}
publicbooleanexists(URIuri) {
if (uri == null) {
returnfalse;
}
switch (uri.getScheme()) {
case"jar":
returnfs.existsBlocking(uri.getPath().substring(1));
case"file":
returnfs.existsBlocking(uri.getPath());
default:
returnfalse;
}
}
publicbooleanisFile(URIuri) {
switch (uri.getScheme()) {
case"jar":
returnfs.propsBlocking(uri.getPath().substring(1)).isRegularFile();
case"file":
returnfs.propsBlocking(uri.getPath()).isRegularFile();
default:
returnfalse;
}
}
publicStringreadFile(URIuri) throwsIOException {
returnreadFile(uri, false);
}
publicStringreadFile(URIuri, booleanmain) throwsIOException {
Bufferbuffer;
switch (uri.getScheme()) {
case"jar":
buffer = fs.readFileBlocking(uri.getPath().substring(1));
break;
case"file":
buffer = fs.readFileBlocking(uri.getPath());
break;
default:
thrownewIOException("Cannot handle scheme [" + uri.getScheme() + "]");
}
if (main) {
Stringcontent = stripShebang(buffer.toString());
returnadapt(content);
} else {
Stringcontent = stripBOM(buffer.toString());
returnadapt(content);
}
}
/** * Find end of shebang line and slice it off * @param content the content to search * @return the striped content */publicstaticStringstripShebang(Stringcontent) {
// Remove shebangintcontLen = content.length();
if (contLen >= 2) {
if (content.charAt(0) == '#' && content.charAt(1) == '!') {
if (contLen == 2) {
// Exact matchcontent = "";
} else {
// Find end of shebang line and slice it offinti = 2;
for (; i < contLen; ++i) {
charcode = content.charAt(i);
if (code == '\n' || code == '\r') {
break;
}
}
if (i == contLen) {
content = "";
} else {
// Note that this actually includes the newline character(s) in the// new output.content = content.substring(i);
}
}
}
}
returncontent;
}
/** * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM) * because the buffer-to-string conversion in `fs.readFileSync()` * translates it to FEFF, the UTF-16 BOM. * @param content the content to search * @return the striped content */publicstaticStringstripBOM(Stringcontent) {
if (content.charAt(0) == 0xFEFF) {
content = content.substring(1);
}
returncontent;
}
}
The text was updated successfully, but these errors were encountered:
frank-dspeed
changed the title
Does es4x use a own import require implementation
Importent Question: Does es4x use a own import require implementation
Sep 3, 2020
i found the following and i guess es4x is using a own require import implementation is that correct?
The text was updated successfully, but these errors were encountered: