mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 06:21:29 +00:00
Remove unnecessary dependencies in asc bundle; Update dependencies
This commit is contained in:
37
bin/asc.js
37
bin/asc.js
@ -13,7 +13,8 @@
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const os = require("os");
|
||||
const utf8 = require("./util/utf8");
|
||||
const EOL = process.platform === "win32" ? "\r\n" : "\n";
|
||||
|
||||
// Use distribution files if present, otherwise run the sources directly
|
||||
var assemblyscript, isDev;
|
||||
@ -152,7 +153,7 @@ exports.main = function main(argv, options, callback) {
|
||||
if (!callback) callback = function defaultCallback(err) {
|
||||
var code = 0;
|
||||
if (err) {
|
||||
stderr.write(err.stack + os.EOL);
|
||||
stderr.write(err.stack + EOL);
|
||||
code = 1;
|
||||
}
|
||||
return code;
|
||||
@ -160,7 +161,7 @@ exports.main = function main(argv, options, callback) {
|
||||
|
||||
// Just print the version if requested
|
||||
if (args.version) {
|
||||
stdout.write("Version " + exports.version + (isDev ? "-dev" : "") + os.EOL);
|
||||
stdout.write("Version " + exports.version + (isDev ? "-dev" : "") + EOL);
|
||||
return callback(null);
|
||||
}
|
||||
// Print the help message if requested or no source files are provided
|
||||
@ -181,7 +182,7 @@ exports.main = function main(argv, options, callback) {
|
||||
for (let i = 0; i < indent; ++i) {
|
||||
line = " " + line;
|
||||
}
|
||||
return os.EOL + line;
|
||||
return EOL + line;
|
||||
}).join(""));
|
||||
} else {
|
||||
opts.push(text + option.desc);
|
||||
@ -197,7 +198,7 @@ exports.main = function main(argv, options, callback) {
|
||||
" asc hello1.ts hello2.ts -b -O > hello.wasm",
|
||||
"",
|
||||
"Options:"
|
||||
].concat(opts).join(os.EOL) + os.EOL);
|
||||
].concat(opts).join(EOL) + EOL);
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
@ -566,7 +567,7 @@ exports.main = function main(argv, options, callback) {
|
||||
path.basename(sourceMapURL)
|
||||
), JSON.stringify(sourceMap));
|
||||
} else {
|
||||
stderr.write("Skipped source map (stdout already occupied)" + os.EOL);
|
||||
stderr.write("Skipped source map (stdout already occupied)" + EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -741,7 +742,7 @@ function checkDiagnostics(emitter, stderr) {
|
||||
while ((diagnostic = assemblyscript.nextDiagnostic(emitter)) != null) {
|
||||
stderr.write(
|
||||
assemblyscript.formatDiagnostic(diagnostic, stderr.isTTY, true) +
|
||||
os.EOL + os.EOL
|
||||
EOL + EOL
|
||||
);
|
||||
if (assemblyscript.isError(diagnostic)) hasErrors = true;
|
||||
}
|
||||
@ -803,24 +804,36 @@ function printStats(stats, output) {
|
||||
"Emit : " + format(stats.emitTime, stats.emitCount),
|
||||
"Validate : " + format(stats.validateTime, stats.validateCount),
|
||||
"Optimize : " + format(stats.optimizeTime, stats.optimizeCount)
|
||||
].join(os.EOL) + os.EOL);
|
||||
].join(EOL) + EOL);
|
||||
}
|
||||
|
||||
exports.printStats = printStats;
|
||||
|
||||
var Buf = typeof global !== "undefined" && global.Buffer || Uint8Array;
|
||||
|
||||
/** Creates a memory stream that can be used in place of stdout/stderr. */
|
||||
function createMemoryStream(fn) {
|
||||
var stream = [];
|
||||
stream.write = function(chunk) {
|
||||
if (typeof chunk === "string") {
|
||||
this.push(Buffer.from(chunk, "utf8"));
|
||||
} else {
|
||||
this.push(chunk);
|
||||
let buffer = new Buf(utf8.length(chunk));
|
||||
utf8.write(chunk, buffer, 0);
|
||||
chunk = buffer;
|
||||
}
|
||||
this.push(chunk);
|
||||
if (fn) fn(chunk);
|
||||
};
|
||||
stream.toBuffer = function() {
|
||||
return Buffer.concat(this);
|
||||
var offset = 0, i = 0, k = this.length;
|
||||
while (i < k) offset += this[i++].length;
|
||||
var buffer = new Buf(offset);
|
||||
offset = i = 0;
|
||||
while (i < k) {
|
||||
buffer.set(this[i], offset);
|
||||
offset += this[i].length;
|
||||
++i;
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
stream.toString = function() {
|
||||
return this.toBuffer().toString("utf8");
|
||||
|
46
bin/util/utf8.js
Normal file
46
bin/util/utf8.js
Normal file
@ -0,0 +1,46 @@
|
||||
// see: https://github.com/dcodeIO/protobuf.js/tree/master/lib/utf8
|
||||
|
||||
exports.length = function utf8_length(string) {
|
||||
var len = 0,
|
||||
c = 0;
|
||||
for (var i = 0; i < string.length; ++i) {
|
||||
c = string.charCodeAt(i);
|
||||
if (c < 128) {
|
||||
len += 1;
|
||||
} else if (c < 2048) {
|
||||
len += 2;
|
||||
} else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
|
||||
++i;
|
||||
len += 4;
|
||||
} else {
|
||||
len += 3;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
};
|
||||
|
||||
exports.write = function utf8_write(string, buffer, offset) {
|
||||
var start = offset,
|
||||
c1, c2;
|
||||
for (var i = 0; i < string.length; ++i) {
|
||||
c1 = string.charCodeAt(i);
|
||||
if (c1 < 128) {
|
||||
buffer[offset++] = c1;
|
||||
} else if (c1 < 2048) {
|
||||
buffer[offset++] = c1 >> 6 | 192;
|
||||
buffer[offset++] = c1 & 63 | 128;
|
||||
} else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
|
||||
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
|
||||
++i;
|
||||
buffer[offset++] = c1 >> 18 | 240;
|
||||
buffer[offset++] = c1 >> 12 & 63 | 128;
|
||||
buffer[offset++] = c1 >> 6 & 63 | 128;
|
||||
buffer[offset++] = c1 & 63 | 128;
|
||||
} else {
|
||||
buffer[offset++] = c1 >> 12 | 224;
|
||||
buffer[offset++] = c1 >> 6 & 63 | 128;
|
||||
buffer[offset++] = c1 & 63 | 128;
|
||||
}
|
||||
}
|
||||
return offset - start;
|
||||
};
|
Reference in New Issue
Block a user