mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 15:12:12 +00:00
Support compiling multiple entry files
This commit is contained in:
parent
732068e981
commit
5ff88e126e
@ -64,9 +64,11 @@ Using the CLI
|
||||
-------------
|
||||
|
||||
```
|
||||
Syntax: asc [options] [file ...]
|
||||
Syntax: asc [options] [entryFile ...]
|
||||
|
||||
Examples: asc hello.ts
|
||||
asc hello.ts -b hello.wasm -t hello.wast -a hello.js
|
||||
asc hello.ts -b > hello.wasm
|
||||
|
||||
Options:
|
||||
-v, --version Prints the compiler's version.
|
||||
|
52
bin/asc.js
52
bin/asc.js
@ -62,18 +62,37 @@ if (args.help || args._.length < 1) {
|
||||
});
|
||||
console.log([
|
||||
"Version " + version,
|
||||
"Syntax: asc [options] [file ...]",
|
||||
"Syntax: asc [options] [entryFile ...]",
|
||||
"",
|
||||
"Examples: asc hello.ts",
|
||||
" asc hello.ts -b hello.wasm -t hello.wast -a hello.js",
|
||||
" asc hello.ts -b > hello.wasm",
|
||||
"",
|
||||
"Options:"
|
||||
].concat(options).join("\n"));
|
||||
process.exit(args.help ? 0 : 1);
|
||||
}
|
||||
|
||||
var entryPath = args._[0].replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
|
||||
var parser = null;
|
||||
|
||||
function checkDiagnostics(parser) {
|
||||
var diagnostic;
|
||||
var hasErrors = false;
|
||||
|
||||
while ((diagnostic = assemblyscript.nextDiagnostic(parser)) != null) {
|
||||
console.error(assemblyscript.formatDiagnostic(diagnostic, process.stderr.isTTY, true));
|
||||
if (assemblyscript.isError(diagnostic))
|
||||
hasErrors = true;
|
||||
}
|
||||
if (hasErrors)
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
args._.forEach(filename => {
|
||||
var entryPath = filename.replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
|
||||
var entryDir = path.dirname(entryPath);
|
||||
var entryText;
|
||||
|
||||
try {
|
||||
entryText = fs.readFileSync(entryPath + ".ts", { encoding: "utf8" });
|
||||
} catch (e) {
|
||||
@ -86,7 +105,7 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
var parser = assemblyscript.parseFile(entryText, entryPath);
|
||||
parser = assemblyscript.parseFile(entryText, entryPath, parser, true);
|
||||
|
||||
var nextPath;
|
||||
var nextText;
|
||||
@ -105,18 +124,8 @@ while ((nextPath = parser.nextFile()) != null) {
|
||||
}
|
||||
assemblyscript.parseFile(nextText, nextPath, parser);
|
||||
}
|
||||
|
||||
var diagnostic;
|
||||
var hasErrors = false;
|
||||
|
||||
while ((diagnostic = assemblyscript.nextDiagnostic(parser)) != null) {
|
||||
console.error(assemblyscript.formatDiagnostic(diagnostic, process.stderr.isTTY, true));
|
||||
if (assemblyscript.isError(diagnostic))
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
if (hasErrors)
|
||||
process.exit(1);
|
||||
checkDiagnostics(parser);
|
||||
});
|
||||
|
||||
var options = assemblyscript.createOptions();
|
||||
assemblyscript.setTarget(options, 0);
|
||||
@ -124,18 +133,7 @@ assemblyscript.setNoTreeShaking(options, args.noTreeShaking);
|
||||
assemblyscript.setNoDebug(options, args.noDebug);
|
||||
|
||||
var module = assemblyscript.compile(parser, options);
|
||||
|
||||
hasErrors = false;
|
||||
while ((diagnostic = assemblyscript.nextDiagnostic(parser)) != null) {
|
||||
console.error(assemblyscript.formatDiagnostic(diagnostic, process.stderr.isTTY, true));
|
||||
if (assemblyscript.isError(diagnostic))
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
if (hasErrors) {
|
||||
module.dispose();
|
||||
process.exit(1);
|
||||
}
|
||||
checkDiagnostics(parser);
|
||||
|
||||
if (args.validate)
|
||||
if (!module.validate()) {
|
||||
|
@ -26,8 +26,7 @@ import { Parser } from "./parser";
|
||||
import { Program } from "./program";
|
||||
|
||||
/** Parses a single source file. If `parser` has been omitted a new one is created. */
|
||||
export function parseFile(text: string, path: string, parser: Parser | null = null): Parser {
|
||||
let isEntry: bool = false;
|
||||
export function parseFile(text: string, path: string, parser: Parser | null = null, isEntry: bool = false): Parser {
|
||||
if (!parser) {
|
||||
parser = new Parser();
|
||||
isEntry = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user