Skip to content

Commit 451b21f

Browse files
committed
more
1 parent 7eb21df commit 451b21f

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

cli/asc.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,8 @@ exports.main = function main(argv, options, callback) {
650650

651651
// Try file.ext, file/index.ext, file.d.ext
652652
if (!internalPath.startsWith(libraryPrefix)) {
653-
if ((sourceText = readFile(sourcePath = internalPath + extension.ext, baseDir)) == null) {
654-
if ((sourceText = readFile(sourcePath = internalPath + "/index" + extension.ext, baseDir)) == null) {
653+
if (!(sourceText = readFile(sourcePath = internalPath + extension.ext, baseDir))) {
654+
if (!(sourceText = readFile(sourcePath = internalPath + "/index" + extension.ext, baseDir))) {
655655
// portable d.ext: uses the .js file next to it in JS or becomes an import in Wasm
656656
sourcePath = internalPath + extension.ext;
657657
sourceText = readFile(internalPath + extension.ext_d, baseDir);
@@ -670,17 +670,17 @@ exports.main = function main(argv, options, callback) {
670670
sourcePath = libraryPrefix + indexName + extension.ext;
671671
} else { // custom lib dirs
672672
for (const libDir of customLibDirs) {
673-
if ((sourceText = readFile(plainName + extension.ext, libDir)) != null) {
673+
if ((sourceText = readFile(plainName + extension.ext, libDir))) {
674674
sourcePath = libraryPrefix + plainName + extension.ext;
675675
break;
676676
} else {
677-
if ((sourceText = readFile(indexName + extension.ext, libDir)) != null) {
677+
if ((sourceText = readFile(indexName + extension.ext, libDir))) {
678678
sourcePath = libraryPrefix + indexName + extension.ext;
679679
break;
680680
}
681681
}
682682
}
683-
if (sourceText == null) { // paths
683+
if (!sourceText) { // paths
684684
const match = internalPath.match(/^~lib\/((?:@[^/]+\/)?[^/]+)(?:\/(.+))?/); // ~lib/(pkg)/(path), ~lib/(@org/pkg)/(path)
685685
if (match) {
686686
const packageName = match[1];
@@ -722,7 +722,7 @@ exports.main = function main(argv, options, callback) {
722722
}
723723
const mainDir = path.join(currentPath, packageName, mainPath);
724724
const plainName = filePath;
725-
if ((sourceText = readFile(path.join(mainDir, plainName + extension.ext), baseDir)) != null) {
725+
if ((sourceText = readFile(path.join(mainDir, plainName + extension.ext), baseDir))) {
726726
sourcePath = `${libraryPrefix}${packageName}/${plainName}${extension.ext}`;
727727
packageBases.set(sourcePath.replace(extension.re, ""), path.join(currentPath, packageName));
728728
if (opts.traceResolution) {
@@ -731,7 +731,7 @@ exports.main = function main(argv, options, callback) {
731731
break;
732732
} else if (!isPackageRoot) {
733733
const indexName = `${filePath}/index`;
734-
if ((sourceText = readFile(path.join(mainDir, indexName + extension.ext), baseDir)) !== null) {
734+
if ((sourceText = readFile(path.join(mainDir, indexName + extension.ext), baseDir))) {
735735
sourcePath = `${libraryPrefix}${packageName}/${indexName}${extension.ext}`;
736736
packageBases.set(sourcePath.replace(extension.re, ""), path.join(currentPath, packageName));
737737
if (opts.traceResolution) {
@@ -746,7 +746,7 @@ exports.main = function main(argv, options, callback) {
746746
}
747747
}
748748
// No such file
749-
if (sourceText == null) return null;
749+
if (!sourceText) return null;
750750
return { sourceText, sourcePath };
751751
}
752752

@@ -784,10 +784,10 @@ exports.main = function main(argv, options, callback) {
784784
let runtimeName = String(opts.runtime);
785785
let runtimePath = `rt/index-${runtimeName}`;
786786
let runtimeText = exports.libraryFiles[runtimePath];
787-
if (runtimeText == null) {
787+
if (!runtimeText) {
788788
runtimePath = runtimeName;
789789
runtimeText = readFile(runtimePath + extension.ext, baseDir);
790-
if (runtimeText == null) return callback(Error(`Runtime '${runtimeName}' not found.`));
790+
if (!runtimeText) return callback(Error(`Runtime '${runtimeName}' not found.`));
791791
} else {
792792
runtimePath = `~lib/${runtimePath}`;
793793
}
@@ -814,14 +814,15 @@ exports.main = function main(argv, options, callback) {
814814
: sourcePath;
815815

816816
// Try entryPath.ext, then entryPath/index.ext
817-
let sourceText = readFile(sourcePath + extension.ext, baseDir);
818-
if (sourceText == null) {
819-
const path = `${sourcePath}/index${extension.ext}`;
820-
sourceText = readFile(path, baseDir);
821-
if (sourceText != null) sourcePath = path;
822-
else sourcePath += extension.ext;
817+
let sourcePathWithExt = sourcePath + extension.ext;
818+
let sourceText = readFile(sourcePathWithExt, baseDir);
819+
if (!sourceText) {
820+
const indexPathWithExt = `${sourcePath}/index${extension.ext}`;
821+
sourceText = readFile(indexPathWithExt, baseDir);
822+
if (sourceText) sourcePath = indexPathWithExt;
823+
else sourcePath = sourcePathWithExt;
823824
} else {
824-
sourcePath += extension.ext;
825+
sourcePath = sourcePathWithExt;
825826
}
826827

827828
stats.parseCount++;
@@ -1058,7 +1059,7 @@ exports.main = function main(argv, options, callback) {
10581059
let contents = [];
10591060
map.sources.forEach((name, index) => {
10601061
let text = assemblyscript.getSource(program, __newString(name.replace(extension.re, "")));
1061-
if (text == null) return callback(Error(`Source of file '${name}' not found.`));
1062+
if (!text) return callback(Error(`Source of file '${name}' not found.`));
10621063
contents[index] = text;
10631064
});
10641065
map.sourcesContent = contents;

0 commit comments

Comments
 (0)