mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-26 07:22:21 +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
|
Examples: asc hello.ts
|
||||||
|
asc hello.ts -b hello.wasm -t hello.wast -a hello.js
|
||||||
|
asc hello.ts -b > hello.wasm
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-v, --version Prints the compiler's version.
|
-v, --version Prints the compiler's version.
|
||||||
|
88
bin/asc.js
88
bin/asc.js
@ -62,61 +62,70 @@ if (args.help || args._.length < 1) {
|
|||||||
});
|
});
|
||||||
console.log([
|
console.log([
|
||||||
"Version " + version,
|
"Version " + version,
|
||||||
"Syntax: asc [options] [file ...]",
|
"Syntax: asc [options] [entryFile ...]",
|
||||||
"",
|
"",
|
||||||
"Examples: asc hello.ts",
|
"Examples: asc hello.ts",
|
||||||
|
" asc hello.ts -b hello.wasm -t hello.wast -a hello.js",
|
||||||
|
" asc hello.ts -b > hello.wasm",
|
||||||
"",
|
"",
|
||||||
"Options:"
|
"Options:"
|
||||||
].concat(options).join("\n"));
|
].concat(options).join("\n"));
|
||||||
process.exit(args.help ? 0 : 1);
|
process.exit(args.help ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var entryPath = args._[0].replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
|
var parser = null;
|
||||||
var entryDir = path.dirname(entryPath);
|
|
||||||
var entryText;
|
function checkDiagnostics(parser) {
|
||||||
try {
|
var diagnostic;
|
||||||
entryText = fs.readFileSync(entryPath + ".ts", { encoding: "utf8" });
|
var hasErrors = false;
|
||||||
} catch (e) {
|
|
||||||
try {
|
while ((diagnostic = assemblyscript.nextDiagnostic(parser)) != null) {
|
||||||
entryText = fs.readFileSync(entryPath + "/index.ts", { encoding: "utf8" });
|
console.error(assemblyscript.formatDiagnostic(diagnostic, process.stderr.isTTY, true));
|
||||||
entryPath = entryPath + "/index";
|
if (assemblyscript.isError(diagnostic))
|
||||||
} catch (e) {
|
hasErrors = true;
|
||||||
console.error("File '" + entryPath + ".ts' not found.");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
if (hasErrors)
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var parser = assemblyscript.parseFile(entryText, entryPath);
|
args._.forEach(filename => {
|
||||||
|
var entryPath = filename.replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");
|
||||||
|
var entryDir = path.dirname(entryPath);
|
||||||
|
var entryText;
|
||||||
|
|
||||||
var nextPath;
|
|
||||||
var nextText;
|
|
||||||
|
|
||||||
while ((nextPath = parser.nextFile()) != null) {
|
|
||||||
try {
|
try {
|
||||||
nextText = fs.readFileSync(nextPath + ".ts", { encoding: "utf8" });
|
entryText = fs.readFileSync(entryPath + ".ts", { encoding: "utf8" });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
try {
|
try {
|
||||||
nextText = fs.readFileSync(nextPath + "/index.ts", { encoding: "utf8" });
|
entryText = fs.readFileSync(entryPath + "/index.ts", { encoding: "utf8" });
|
||||||
nextPath = nextPath + "/index";
|
entryPath = entryPath + "/index";
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Imported file '" + nextPath + ".ts' not found.");
|
console.error("File '" + entryPath + ".ts' not found.");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assemblyscript.parseFile(nextText, nextPath, parser);
|
|
||||||
}
|
|
||||||
|
|
||||||
var diagnostic;
|
parser = assemblyscript.parseFile(entryText, entryPath, parser, true);
|
||||||
var hasErrors = false;
|
|
||||||
|
|
||||||
while ((diagnostic = assemblyscript.nextDiagnostic(parser)) != null) {
|
var nextPath;
|
||||||
console.error(assemblyscript.formatDiagnostic(diagnostic, process.stderr.isTTY, true));
|
var nextText;
|
||||||
if (assemblyscript.isError(diagnostic))
|
|
||||||
hasErrors = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasErrors)
|
while ((nextPath = parser.nextFile()) != null) {
|
||||||
process.exit(1);
|
try {
|
||||||
|
nextText = fs.readFileSync(nextPath + ".ts", { encoding: "utf8" });
|
||||||
|
} catch (e) {
|
||||||
|
try {
|
||||||
|
nextText = fs.readFileSync(nextPath + "/index.ts", { encoding: "utf8" });
|
||||||
|
nextPath = nextPath + "/index";
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Imported file '" + nextPath + ".ts' not found.");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assemblyscript.parseFile(nextText, nextPath, parser);
|
||||||
|
}
|
||||||
|
checkDiagnostics(parser);
|
||||||
|
});
|
||||||
|
|
||||||
var options = assemblyscript.createOptions();
|
var options = assemblyscript.createOptions();
|
||||||
assemblyscript.setTarget(options, 0);
|
assemblyscript.setTarget(options, 0);
|
||||||
@ -124,18 +133,7 @@ assemblyscript.setNoTreeShaking(options, args.noTreeShaking);
|
|||||||
assemblyscript.setNoDebug(options, args.noDebug);
|
assemblyscript.setNoDebug(options, args.noDebug);
|
||||||
|
|
||||||
var module = assemblyscript.compile(parser, options);
|
var module = assemblyscript.compile(parser, options);
|
||||||
|
checkDiagnostics(parser);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.validate)
|
if (args.validate)
|
||||||
if (!module.validate()) {
|
if (!module.validate()) {
|
||||||
|
@ -26,8 +26,7 @@ import { Parser } from "./parser";
|
|||||||
import { Program } from "./program";
|
import { Program } from "./program";
|
||||||
|
|
||||||
/** Parses a single source file. If `parser` has been omitted a new one is created. */
|
/** 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 {
|
export function parseFile(text: string, path: string, parser: Parser | null = null, isEntry: bool = false): Parser {
|
||||||
let isEntry: bool = false;
|
|
||||||
if (!parser) {
|
if (!parser) {
|
||||||
parser = new Parser();
|
parser = new Parser();
|
||||||
isEntry = true;
|
isEntry = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user