Skip to content

Commit aedc821

Browse files
committed
Process backlog once more after Transform#afterParse, see AssemblyScript#356
1 parent 6ed45be commit aedc821

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

cli/asc.js

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -285,33 +285,10 @@ exports.main = function main(argv, options, callback) {
285285
}
286286
}
287287

288-
// Include entry files
289-
for (let i = 0, k = argv.length; i < k; ++i) {
290-
const filename = argv[i];
291-
292-
let sourcePath = String(filename).replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
293-
294-
// Try entryPath.ts, then entryPath/index.ts
295-
let sourceText = readFile(path.join(baseDir, sourcePath) + ".ts");
296-
if (sourceText === null) {
297-
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
298-
if (sourceText === null) {
299-
return callback(Error("Entry file '" + sourcePath + ".ts' not found."));
300-
} else {
301-
sourcePath += "/index.ts";
302-
}
303-
} else {
304-
sourcePath += ".ts";
305-
}
306-
307-
stats.parseCount++;
308-
stats.parseTime += measure(() => {
309-
parser = assemblyscript.parseFile(sourceText, sourcePath, true, parser);
310-
});
311-
312-
// Process backlog
288+
// Parses the backlog of imported files after including entry files
289+
function parseBacklog() {
290+
var sourcePath, sourceText;
313291
while ((sourcePath = parser.nextFile()) != null) {
314-
let found = false;
315292

316293
// Load library file if explicitly requested
317294
if (sourcePath.startsWith(exports.libraryPrefix)) {
@@ -390,7 +367,38 @@ exports.main = function main(argv, options, callback) {
390367
}
391368
}
392369

370+
// Include entry files
371+
for (let i = 0, k = argv.length; i < k; ++i) {
372+
const filename = argv[i];
373+
374+
let sourcePath = String(filename).replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
375+
376+
// Try entryPath.ts, then entryPath/index.ts
377+
let sourceText = readFile(path.join(baseDir, sourcePath) + ".ts");
378+
if (sourceText === null) {
379+
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
380+
if (sourceText === null) {
381+
return callback(Error("Entry file '" + sourcePath + ".ts' not found."));
382+
} else {
383+
sourcePath += "/index.ts";
384+
}
385+
} else {
386+
sourcePath += ".ts";
387+
}
388+
389+
stats.parseCount++;
390+
stats.parseTime += measure(() => {
391+
parser = assemblyscript.parseFile(sourceText, sourcePath, true, parser);
392+
});
393+
let code = parseBacklog();
394+
if (code) return code;
395+
}
396+
393397
applyTransform("afterParse", parser);
398+
{
399+
let code = parseBacklog();
400+
if (code) return code;
401+
}
394402

395403
// Finish parsing
396404
const program = assemblyscript.finishParsing(parser);

src/program.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import {
1616

1717
import {
1818
Options,
19-
Feature,
20-
Compiler
19+
Feature
2120
} from "./compiler";
2221

2322
import {

0 commit comments

Comments
 (0)