Process backlog once more after Transform#afterParse, see #356

This commit is contained in:
dcodeIO 2018-12-03 17:22:01 +01:00
parent 6ed45bee98
commit aedc821c09
2 changed files with 35 additions and 28 deletions

View File

@ -285,33 +285,10 @@ exports.main = function main(argv, options, callback) {
} }
} }
// Include entry files // Parses the backlog of imported files after including entry files
for (let i = 0, k = argv.length; i < k; ++i) { function parseBacklog() {
const filename = argv[i]; var sourcePath, sourceText;
let sourcePath = String(filename).replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
// Try entryPath.ts, then entryPath/index.ts
let sourceText = readFile(path.join(baseDir, sourcePath) + ".ts");
if (sourceText === null) {
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
if (sourceText === null) {
return callback(Error("Entry file '" + sourcePath + ".ts' not found."));
} else {
sourcePath += "/index.ts";
}
} else {
sourcePath += ".ts";
}
stats.parseCount++;
stats.parseTime += measure(() => {
parser = assemblyscript.parseFile(sourceText, sourcePath, true, parser);
});
// Process backlog
while ((sourcePath = parser.nextFile()) != null) { while ((sourcePath = parser.nextFile()) != null) {
let found = false;
// Load library file if explicitly requested // Load library file if explicitly requested
if (sourcePath.startsWith(exports.libraryPrefix)) { if (sourcePath.startsWith(exports.libraryPrefix)) {
@ -390,7 +367,38 @@ exports.main = function main(argv, options, callback) {
} }
} }
// Include entry files
for (let i = 0, k = argv.length; i < k; ++i) {
const filename = argv[i];
let sourcePath = String(filename).replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
// Try entryPath.ts, then entryPath/index.ts
let sourceText = readFile(path.join(baseDir, sourcePath) + ".ts");
if (sourceText === null) {
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
if (sourceText === null) {
return callback(Error("Entry file '" + sourcePath + ".ts' not found."));
} else {
sourcePath += "/index.ts";
}
} else {
sourcePath += ".ts";
}
stats.parseCount++;
stats.parseTime += measure(() => {
parser = assemblyscript.parseFile(sourceText, sourcePath, true, parser);
});
let code = parseBacklog();
if (code) return code;
}
applyTransform("afterParse", parser); applyTransform("afterParse", parser);
{
let code = parseBacklog();
if (code) return code;
}
// Finish parsing // Finish parsing
const program = assemblyscript.finishParsing(parser); const program = assemblyscript.finishParsing(parser);

View File

@ -16,8 +16,7 @@ import {
import { import {
Options, Options,
Feature, Feature
Compiler
} from "./compiler"; } from "./compiler";
import { import {