Minor CLI and README cleanup

This commit is contained in:
dcodeIO 2018-06-14 15:57:04 +02:00
parent e18165bbbc
commit c102fc9848
13 changed files with 208 additions and 113 deletions

View File

@ -1,7 +1,6 @@
![](https://avatars1.githubusercontent.com/u/28916798?s=64) AssemblyScript ![](https://avatars1.githubusercontent.com/u/28916798?s=64) AssemblyScript
================= =================
[![npm](https://img.shields.io/npm/v/assemblyscript.svg)](https://www.npmjs.com/package/assemblyscript)
[![Build Status](https://travis-ci.org/AssemblyScript/assemblyscript.svg?branch=master)](https://travis-ci.org/AssemblyScript/assemblyscript) [![Build Status](https://travis-ci.org/AssemblyScript/assemblyscript.svg?branch=master)](https://travis-ci.org/AssemblyScript/assemblyscript)
[![Snap Status](https://build.snapcraft.io/badge/AssemblyScript/assemblyscript.svg)](https://build.snapcraft.io/user/AssemblyScript/assemblyscript) [![Snap Status](https://build.snapcraft.io/badge/AssemblyScript/assemblyscript.svg)](https://build.snapcraft.io/user/AssemblyScript/assemblyscript)

View File

@ -8,11 +8,7 @@ if (process.argv.length < 3) printHelp();
function printHelp() { function printHelp() {
console.log([ console.log([
"Version " + version, "Sets up a new AssemblyScript project or updates an existing one.",
"Syntax: " + colors.cyan("asinit") + " [project directory]",
"",
colors.white("Sets up a new AssemblyScript project or updates an existing one."),
"",
"For example, to create a new project in the current directory:", "For example, to create a new project in the current directory:",
"", "",
" " + colors.cyan("asinit") + " .", " " + colors.cyan("asinit") + " .",

View File

@ -14,6 +14,7 @@
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const utf8 = require("@protobufjs/utf8"); const utf8 = require("@protobufjs/utf8");
const colors = require("./util/colors");
const EOL = process.platform === "win32" ? "\r\n" : "\n"; const EOL = process.platform === "win32" ? "\r\n" : "\n";
// Use distribution files if present, otherwise run the sources directly // Use distribution files if present, otherwise run the sources directly
@ -119,23 +120,26 @@ exports.main = function main(argv, options, callback) {
const listFiles = options.listFiles || listFilesNode; const listFiles = options.listFiles || listFilesNode;
const stats = options.stats || createStats(); const stats = options.stats || createStats();
// All of the above must be specified in browser environments // Output must be specified if not present in the environment
if (!stdout) throw Error("'options.stdout' must be specified"); if (!stdout) throw Error("'options.stdout' must be specified");
if (!stderr) throw Error("'options.stderr' must be specified"); if (!stderr) throw Error("'options.stderr' must be specified");
if (!fs.readFileSync) {
if (readFile === readFileNode) throw Error("'options.readFile' must be specified");
if (writeFile === writeFileNode) throw Error("'options.writeFile' must be specified");
if (listFiles === listFilesNode) throw Error("'options.listFiles' must be specified");
}
const args = parseArguments(argv); const args = parseArguments(argv);
const indent = 24; const indent = 24;
if (args.noColors) {
colors.stdout.supported =
colors.stderr.supported = false;
} else {
colors.stdout = colors.from(stdout);
colors.stderr = colors.from(stderr);
}
// Use default callback if none is provided // Use default callback if none is provided
if (!callback) callback = function defaultCallback(err) { if (!callback) callback = function defaultCallback(err) {
var code = 0; var code = 0;
if (err) { if (err) {
stderr.write(err.stack + EOL); stderr.write(colors.stderr.red("ERROR: ") + err.stack.replace(/^ERROR: /i, "") + EOL);
code = 1; code = 1;
} }
return code; return code;
@ -151,7 +155,7 @@ exports.main = function main(argv, options, callback) {
const opts = []; const opts = [];
Object.keys(exports.options).forEach(name => { Object.keys(exports.options).forEach(name => {
var option = exports.options[name]; var option = exports.options[name];
var text = " "; var text = " ";
text += "--" + name; text += "--" + name;
if (option.aliases && option.aliases[0].length === 1) { if (option.aliases && option.aliases[0].length === 1) {
text += ", -" + option.aliases[0]; text += ", -" + option.aliases[0];
@ -171,19 +175,29 @@ exports.main = function main(argv, options, callback) {
} }
}); });
(args.help ? stdout : stderr).write([ var out = args.help ? stdout : stderr;
"Version " + exports.version + (isDev ? "-dev" : ""), var color = args.help ? colors.stdout : colors.stderr;
"Syntax: asc [entryFile ...] [options]", out.write([
color.white("Syntax"),
" " + color.cyan("asc") + " [entryFile ...] [options]",
"", "",
"Examples: asc hello.ts", color.white("Examples"),
" asc hello.ts -b hello.wasm -t hello.wat", " " + color.cyan("asc") + " hello.ts",
" asc hello1.ts hello2.ts -b -O > hello.wasm", " " + color.cyan("asc") + " hello.ts -b hello.wasm -t hello.wat",
" " + color.cyan("asc") + " hello1.ts hello2.ts -b -O > hello.wasm",
"", "",
"Options:" color.white("Options"),
].concat(opts).join(EOL) + EOL); ].concat(opts).join(EOL) + EOL);
return callback(null); return callback(null);
} }
// I/O must be specified if not present in the environment
if (!fs.readFileSync) {
if (readFile === readFileNode) throw Error("'options.readFile' must be specified");
if (writeFile === writeFileNode) throw Error("'options.writeFile' must be specified");
if (listFiles === listFilesNode) throw Error("'options.listFiles' must be specified");
}
// Set up base directory // Set up base directory
const baseDir = args.baseDir ? path.resolve(args.baseDir) : "."; const baseDir = args.baseDir ? path.resolve(args.baseDir) : ".";
@ -859,6 +873,9 @@ function createMemoryStream(fn) {
} }
this.push(chunk); this.push(chunk);
}; };
stream.reset = function() {
stream.length = 0;
};
stream.toBuffer = function() { stream.toBuffer = function() {
var offset = 0, i = 0, k = this.length; var offset = 0, i = 0, k = this.length;
while (i < k) offset += this[i++].length; while (i < k) offset += this[i++].length;

View File

@ -167,5 +167,9 @@
"measure": { "measure": {
"description": "Prints measuring information on I/O and compile times.", "description": "Prints measuring information on I/O and compile times.",
"type": "boolean" "type": "boolean"
},
"noColors": {
"description": "Disables terminal colors.",
"type": "boolean"
} }
} }

50
cli/util/colors.d.ts vendored Normal file
View File

@ -0,0 +1,50 @@
interface Colors {
/** Whether terminal colors are supported. */
supported: boolean;
/** Colors a string in gray if {@link supported}. */
gray(text: string): string;
/** Colors a string in red if {@link supported}. */
red(text: string): string;
/** Colors a string in green if {@link supported}. */
green(text: string): string;
/** Colors a string in yellow if {@link supported}. */
yellow(text: string): string;
/** Colors a string in blue if {@link supported}. */
blue(text: string): string;
/** Colors a string in magenta if {@link supported}. */
magenta(text: string): string;
/** Colors a string in cyan if {@link supported}. */
cyan(text: string): string;
/** Colors a string in white if {@link supported}. */
white(text: string): string;
}
interface Exports extends Colors {
/** Standard output wrapper. */
stdout: Colors;
/** Standard error wrapper. */
stderr: Colors;
/** Creates an instance for the specified stream. */
from(stream: any, base?: {}): Colors;
/** Gray color escape sequence. */
GRAY: string;
/** Red color escape sequence. */
RED: string;
/** Green color escape sequence. */
GREEN: string;
/** Yellow color escape sequence. */
YELLOW: string;
/** Blue color escape sequence. */
BLUE: string;
/** Magenta color escape sequence. */
MAGENTA: string;
/** Cyan color escape sequence. */
CYAN: string;
/** White color escape sequence. */
WHITE: string;
/** Reset color escape sequence. */
RESET: string;
}
declare const colors: Exports;
export = colors;

View File

@ -1,39 +1,30 @@
var hasColor = typeof process !== "undefined" && process && process.stdout && !!process.stdout.isTTY var proc = typeof process !== "undefined" && process || {};
|| typeof env !== "undefined" && env && "TRAVIS" in env; var isCI = proc.env && "CI" in proc.env;
function from(stream, base) {
var colors = base || {};
colors.supported = (stream && !!stream.isTTY) || isCI;
colors.gray = text => colors.supported ? exports.GRAY + text + exports.RESET : text;
colors.red = text => colors.supported ? exports.RED + text + exports.RESET : text;
colors.green = text => colors.supported ? exports.GREEN + text + exports.RESET : text;
colors.yellow = text => colors.supported ? exports.YELLOW + text + exports.RESET : text;
colors.blue = text => colors.supported ? exports.BLUE + text + exports.RESET : text;
colors.magenta = text => colors.supported ? exports.MAGENTA + text + exports.RESET : text;
colors.cyan = text => colors.supported ? exports.CYAN + text + exports.RESET : text;
colors.white = text => colors.supported ? exports.WHITE + text + exports.RESET : text;
return colors;
}
exports.stdout = from(proc.stdout, exports);
exports.stderr = from(proc.stderr);
exports.from = from;
exports.GRAY = "\u001b[90m";
exports.RED = "\u001b[91m"; exports.RED = "\u001b[91m";
exports.red = function(text) {
return hasColor ? exports.RED + text + exports.RESET : text;
};
exports.GREEN = "\u001b[92m"; exports.GREEN = "\u001b[92m";
exports.green = function(text) {
return hasColor ? exports.GREEN + text + exports.RESET : text;
};
exports.YELLOW = "\u001b[93m"; exports.YELLOW = "\u001b[93m";
exports.yellow = function(text) {
return hasColor ? exports.YELLOW + text + exports.RESET : text;
};
exports.BLUE = "\u001b[94m"; exports.BLUE = "\u001b[94m";
exports.blue = function(text) {
return hasColor ? exports.BLUE + text + exports.RESET : text;
};
exports.MAGENTA = "\u001b[95m"; exports.MAGENTA = "\u001b[95m";
exports.magenta = function(text) {
return hasColor ? exports.MAGENTA + text + exports.RESET : text;
};
exports.CYAN = "\u001b[96m"; exports.CYAN = "\u001b[96m";
exports.cyan = function(text) {
return hasColor ? exports.CYAN + text + exports.RESET : text;
};
exports.WHITE = "\u001b[97m"; exports.WHITE = "\u001b[97m";
exports.white = function(text) {
return hasColor ? exports.WHITE + text + exports.RESET : text;
};
exports.RESET = "\u001b[0m"; exports.RESET = "\u001b[0m";

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -46,7 +46,7 @@ export function diagnosticCategoryToString(category: DiagnosticCategory): string
} }
/** ANSI escape sequence for blue foreground. */ /** ANSI escape sequence for blue foreground. */
export const COLOR_BLUE: string = "\u001b[94m"; export const COLOR_BLUE: string = "\u001b[96m";
/** ANSI escape sequence for yellow foreground. */ /** ANSI escape sequence for yellow foreground. */
export const COLOR_YELLOW: string = "\u001b[93m"; export const COLOR_YELLOW: string = "\u001b[93m";
/** ANSI escape sequence for red foreground. */ /** ANSI escape sequence for red foreground. */

View File

@ -100,7 +100,10 @@ import {
getConstValueF64, getConstValueF64,
getConstValueI64Low getConstValueI64Low
} from "./module"; } from "./module";
import { CharCode } from "./util";
import {
CharCode
} from "./util";
/** Path delimiter inserted between file system levels. */ /** Path delimiter inserted between file system levels. */
export const PATH_DELIMITER = "/"; export const PATH_DELIMITER = "/";
@ -123,21 +126,21 @@ export const LIBRARY_PREFIX = LIBRARY_SUBST + PATH_DELIMITER;
/** Prefix used to indicate a filespace element. */ /** Prefix used to indicate a filespace element. */
export const FILESPACE_PREFIX = "file:"; export const FILESPACE_PREFIX = "file:";
/** Represents a yet unresolved export. */
class QueuedExport {
isReExport: bool;
referencedName: string;
member: ExportMember;
}
/** Represents a yet unresolved import. */ /** Represents a yet unresolved import. */
class QueuedImport { class QueuedImport {
internalName: string; localName: string;
referencedName: string; externalName: string;
referencedNameAlt: string; externalNameAlt: string;
declaration: ImportDeclaration | null; // not set if a filespace declaration: ImportDeclaration | null; // not set if a filespace
} }
/** Represents a yet unresolved export. */
class QueuedExport {
externalName: string;
isReExport: bool;
member: ExportMember;
}
/** Represents a type alias. */ /** Represents a type alias. */
class TypeAlias { class TypeAlias {
typeParameters: TypeParameterNode[] | null; typeParameters: TypeParameterNode[] | null;
@ -317,6 +320,7 @@ export class Program extends DiagnosticEmitter {
diagnosticsOffset: i32 = 0; diagnosticsOffset: i32 = 0;
/** Compiler options. */ /** Compiler options. */
options: Options; options: Options;
/** Elements by internal name. */ /** Elements by internal name. */
elementsLookup: Map<string,Element> = new Map(); elementsLookup: Map<string,Element> = new Map();
/** Class and function instances by internal name. */ /** Class and function instances by internal name. */
@ -329,6 +333,7 @@ export class Program extends DiagnosticEmitter {
fileLevelExports: Map<string,Element> = new Map(); fileLevelExports: Map<string,Element> = new Map();
/** Module-level exports by exported name. */ /** Module-level exports by exported name. */
moduleLevelExports: Map<string,Element> = new Map(); moduleLevelExports: Map<string,Element> = new Map();
/** Array prototype reference. */ /** Array prototype reference. */
arrayPrototype: ClassPrototype | null = null; arrayPrototype: ClassPrototype | null = null;
/** ArrayBufferView prototype reference. */ /** ArrayBufferView prototype reference. */
@ -392,8 +397,8 @@ export class Program extends DiagnosticEmitter {
["boolean", Type.bool] ["boolean", Type.bool]
]); ]);
var queuedExports = new Map<string,QueuedExport>();
var queuedImports = new Array<QueuedImport>(); var queuedImports = new Array<QueuedImport>();
var queuedExports = new Map<string,QueuedExport>();
var queuedExtends = new Array<ClassPrototype>(); var queuedExtends = new Array<ClassPrototype>();
var queuedImplements = new Array<ClassPrototype>(); var queuedImplements = new Array<ClassPrototype>();
@ -456,13 +461,13 @@ export class Program extends DiagnosticEmitter {
let queuedImport = queuedImports[i]; let queuedImport = queuedImports[i];
let declaration = queuedImport.declaration; let declaration = queuedImport.declaration;
if (declaration) { // named if (declaration) { // named
let element = this.tryResolveImport(queuedImport.referencedName, queuedExports); let element = this.tryResolveImport(queuedImport.externalName, queuedExports);
if (element) { if (element) {
this.elementsLookup.set(queuedImport.internalName, element); this.elementsLookup.set(queuedImport.localName, element);
queuedImports.splice(i, 1); queuedImports.splice(i, 1);
} else { } else {
if (element = this.tryResolveImport(queuedImport.referencedNameAlt, queuedExports)) { if (element = this.tryResolveImport(queuedImport.externalNameAlt, queuedExports)) {
this.elementsLookup.set(queuedImport.internalName, element); this.elementsLookup.set(queuedImport.localName, element);
queuedImports.splice(i, 1); queuedImports.splice(i, 1);
} else { } else {
this.error( this.error(
@ -475,13 +480,13 @@ export class Program extends DiagnosticEmitter {
} }
} }
} else { // filespace } else { // filespace
let element = this.elementsLookup.get(queuedImport.referencedName); let element = this.elementsLookup.get(queuedImport.externalName);
if (element) { if (element) {
this.elementsLookup.set(queuedImport.internalName, element); this.elementsLookup.set(queuedImport.localName, element);
queuedImports.splice(i, 1); queuedImports.splice(i, 1);
} else { } else {
if (element = this.elementsLookup.get(queuedImport.referencedNameAlt)) { if (element = this.elementsLookup.get(queuedImport.externalNameAlt)) {
this.elementsLookup.set(queuedImport.internalName, element); this.elementsLookup.set(queuedImport.localName, element);
queuedImports.splice(i, 1); queuedImports.splice(i, 1);
} else { } else {
assert(false); // already reported by the parser not finding the file assert(false); // already reported by the parser not finding the file
@ -497,7 +502,7 @@ export class Program extends DiagnosticEmitter {
let element: Element | null; let element: Element | null;
do { do {
if (currentExport.isReExport) { if (currentExport.isReExport) {
if (element = this.fileLevelExports.get(currentExport.referencedName)) { if (element = this.fileLevelExports.get(currentExport.externalName)) {
this.setExportAndCheckLibrary( this.setExportAndCheckLibrary(
exportName, exportName,
element, element,
@ -505,7 +510,7 @@ export class Program extends DiagnosticEmitter {
); );
break; break;
} }
currentExport = queuedExports.get(currentExport.referencedName); currentExport = queuedExports.get(currentExport.externalName);
if (!currentExport) { if (!currentExport) {
this.error( this.error(
DiagnosticCode.Module_0_has_no_exported_member_1, DiagnosticCode.Module_0_has_no_exported_member_1,
@ -517,7 +522,7 @@ export class Program extends DiagnosticEmitter {
} else { } else {
if ( if (
// normal export // normal export
(element = this.elementsLookup.get(currentExport.referencedName)) || (element = this.elementsLookup.get(currentExport.externalName)) ||
// library re-export // library re-export
(element = this.elementsLookup.get(currentExport.member.name.text)) (element = this.elementsLookup.get(currentExport.member.name.text))
) { ) {
@ -602,21 +607,22 @@ export class Program extends DiagnosticEmitter {
/** Tries to resolve an import by traversing exports and queued exports. */ /** Tries to resolve an import by traversing exports and queued exports. */
private tryResolveImport( private tryResolveImport(
referencedName: string, externalName: string,
queuedExports: Map<string,QueuedExport> queuedNamedExports: Map<string,QueuedExport>
): Element | null { ): Element | null {
var element: Element | null; var element: Element | null;
var fileLevelExports = this.fileLevelExports; var fileLevelExports = this.fileLevelExports;
do { do {
if (element = fileLevelExports.get(referencedName)) return element; if (element = fileLevelExports.get(externalName)) return element;
let queuedExport = queuedExports.get(referencedName); let queuedExport = queuedNamedExports.get(externalName);
if (!queuedExport) return null; if (!queuedExport) break;
if (queuedExport.isReExport) { if (queuedExport.isReExport) {
referencedName = queuedExport.referencedName; externalName = queuedExport.externalName;
continue; continue;
} }
return this.elementsLookup.get(queuedExport.referencedName); return this.elementsLookup.get(queuedExport.externalName);
} while (true); } while (true);
return null;
} }
private filterDecorators(decorators: DecoratorNode[], acceptedFlags: DecoratorFlags): DecoratorFlags { private filterDecorators(decorators: DecoratorNode[], acceptedFlags: DecoratorFlags): DecoratorFlags {
@ -1330,7 +1336,7 @@ export class Program extends DiagnosticEmitter {
} }
queuedExport = new QueuedExport(); queuedExport = new QueuedExport();
queuedExport.isReExport = false; queuedExport.isReExport = false;
queuedExport.referencedName = referencedName; // -> internal name queuedExport.externalName = referencedName; // -> here: local name
queuedExport.member = member; queuedExport.member = member;
queuedExports.set(externalName, queuedExport); queuedExports.set(externalName, queuedExport);
@ -1353,7 +1359,7 @@ export class Program extends DiagnosticEmitter {
let seen = new Set<QueuedExport>(); let seen = new Set<QueuedExport>();
while (queuedExport = queuedExports.get(referencedName)) { while (queuedExport = queuedExports.get(referencedName)) {
if (queuedExport.isReExport) { if (queuedExport.isReExport) {
referencedElement = this.fileLevelExports.get(queuedExport.referencedName); referencedElement = this.fileLevelExports.get(queuedExport.externalName);
if (referencedElement) { if (referencedElement) {
this.setExportAndCheckLibrary( this.setExportAndCheckLibrary(
externalName, externalName,
@ -1362,11 +1368,11 @@ export class Program extends DiagnosticEmitter {
); );
return; return;
} }
referencedName = queuedExport.referencedName; referencedName = queuedExport.externalName;
if (seen.has(queuedExport)) break; if (seen.has(queuedExport)) break;
seen.add(queuedExport); seen.add(queuedExport);
} else { } else {
referencedElement = this.elementsLookup.get(queuedExport.referencedName); referencedElement = this.elementsLookup.get(queuedExport.externalName);
if (referencedElement) { if (referencedElement) {
this.setExportAndCheckLibrary( this.setExportAndCheckLibrary(
externalName, externalName,
@ -1389,7 +1395,7 @@ export class Program extends DiagnosticEmitter {
} }
queuedExport = new QueuedExport(); queuedExport = new QueuedExport();
queuedExport.isReExport = true; queuedExport.isReExport = true;
queuedExport.referencedName = referencedName; // -> export name queuedExport.externalName = referencedName; // -> here: external name
queuedExport.member = member; queuedExport.member = member;
queuedExports.set(externalName, queuedExport); queuedExports.set(externalName, queuedExport);
} }
@ -1507,11 +1513,11 @@ export class Program extends DiagnosticEmitter {
// otherwise queue it // otherwise queue it
let queuedImport = new QueuedImport(); let queuedImport = new QueuedImport();
queuedImport.internalName = internalName; queuedImport.localName = internalName;
let prefix = FILESPACE_PREFIX + statement.internalPath; let externalName = FILESPACE_PREFIX + statement.internalPath;
queuedImport.referencedName = prefix; queuedImport.externalName = externalName;
queuedImport.referencedNameAlt = prefix + PATH_DELIMITER + "index"; queuedImport.externalNameAlt = externalName + PATH_DELIMITER + "index";
queuedImport.declaration = null; queuedImport.declaration = null; // filespace
queuedImports.push(queuedImport); queuedImports.push(queuedImport);
} }
} }
@ -1519,47 +1525,47 @@ export class Program extends DiagnosticEmitter {
private initializeImport( private initializeImport(
declaration: ImportDeclaration, declaration: ImportDeclaration,
internalPath: string, internalPath: string,
queuedExports: Map<string,QueuedExport>, queuedNamedExports: Map<string,QueuedExport>,
queuedImports: QueuedImport[] queuedImports: QueuedImport[]
): void { ): void {
var internalName = declaration.fileLevelInternalName; var localName = declaration.fileLevelInternalName;
if (this.elementsLookup.has(internalName)) { if (this.elementsLookup.has(localName)) {
this.error( this.error(
DiagnosticCode.Duplicate_identifier_0, DiagnosticCode.Duplicate_identifier_0,
declaration.name.range, internalName declaration.name.range, localName
); );
return; return;
} }
var referencedName = internalPath + PATH_DELIMITER + declaration.externalName.text; var externalName = internalPath + PATH_DELIMITER + declaration.externalName.text;
// resolve right away if the exact export exists // resolve right away if the exact export exists
var element: Element | null; var element: Element | null;
if (element = this.fileLevelExports.get(referencedName)) { if (element = this.fileLevelExports.get(externalName)) {
this.elementsLookup.set(internalName, element); this.elementsLookup.set(localName, element);
return; return;
} }
// otherwise queue it // otherwise queue it
const indexPart = PATH_DELIMITER + "index"; const indexPart = PATH_DELIMITER + "index";
var queuedImport = new QueuedImport(); var queuedImport = new QueuedImport();
queuedImport.internalName = internalName; queuedImport.localName = localName;
if (internalPath.endsWith(indexPart)) { if (internalPath.endsWith(indexPart)) {
queuedImport.referencedName = referencedName; // try exact first queuedImport.externalName = externalName; // try exact first
queuedImport.referencedNameAlt = ( queuedImport.externalNameAlt = (
internalPath.substring(0, internalPath.length - indexPart.length + 1) + internalPath.substring(0, internalPath.length - indexPart.length + 1) +
declaration.externalName.text declaration.externalName.text
); );
} else { } else {
queuedImport.referencedName = referencedName; // try exact first queuedImport.externalName = externalName; // try exact first
queuedImport.referencedNameAlt = ( queuedImport.externalNameAlt = (
internalPath + internalPath +
indexPart + indexPart +
PATH_DELIMITER + PATH_DELIMITER +
declaration.externalName.text declaration.externalName.text
); );
} }
queuedImport.declaration = declaration; queuedImport.declaration = declaration; // named
queuedImports.push(queuedImport); queuedImports.push(queuedImport);
} }

View File

@ -1,11 +1,43 @@
const asc = require("../dist/asc.js"); const asc = require("../dist/asc.js");
console.log("# asc.main"); const stdout = asc.createMemoryStream();
const stderr = asc.createMemoryStream();
const stdout = asc.createMemoryStream(arg => console.log("out:", arg));
const stderr = asc.createMemoryStream(arg => console.log("err:", arg));
const files = { "module.ts": `import "allocator/arena";` }; const files = { "module.ts": `import "allocator/arena";` };
console.log("# asc --version");
asc.main([
"--version"
], {
stdout: stdout,
stderr: stderr
}, err => {
console.log(">>> STDOUT >>>");
process.stdout.write(stdout.toString());
stdout.reset();
console.log(">>> STDERR >>>");
process.stdout.write(stderr.toString());
stderr.reset();
});
console.log("\n# asc --help");
asc.main([
"--help"
], {
stdout: stdout,
stderr: stderr
}, err => {
console.log(">>> STDOUT >>>");
process.stdout.write(stdout.toString());
stdout.reset();
console.log(">>> STDERR >>>");
process.stdout.write(stderr.toString());
stderr.reset();
});
console.log("\n# asc module.ts --textFile");
asc.main([ asc.main([
"module.ts", "module.ts",
"--textFile" "--textFile"