Skip to content

Commit 2d1b891

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents c328b6a + 20e882c commit 2d1b891

3 files changed

Lines changed: 36 additions & 29 deletions

File tree

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ under the licensing terms detailed in LICENSE:
1919
* Stephen Paul Weber <stephen.weber@shopify.com>
2020
* Jay Phelps <hello@jayphelps.com>
2121
* jhwgh1968 <jhwgh1968@protonmail.com>
22+
* Jeffrey Charles <jeffreycharles@gmail.com>
2223

2324
Portions of this software are derived from third-party works licensed under
2425
the following terms:

cli/asc.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ var assemblyscript, isDev = false;
4040
try { // `asc` on the command line without dist files
4141
require("ts-node").register({
4242
project: path.join(__dirname, "..", "src", "tsconfig.json"),
43-
skipIgnore: true
43+
skipIgnore: true,
44+
compilerOptions: { target: "ES2016" }
4445
});
4546
require("../src/glue/js");
4647
assemblyscript = require("../src");
@@ -67,9 +68,6 @@ exports.version = exports.isBundle ? BUNDLE_VERSION : require("../package.json")
6768
/** Available CLI options. */
6869
exports.options = require("./asc.json");
6970

70-
/** Common root used in source maps. */
71-
exports.sourceMapRoot = "assemblyscript:///";
72-
7371
/** Prefix used for library files. */
7472
exports.libraryPrefix = assemblyscript.LIBRARY_PREFIX;
7573

@@ -286,10 +284,14 @@ exports.main = function main(argv, options, callback) {
286284
// Set up transforms
287285
const transforms = [];
288286
if (args.transform) {
287+
let tsNodeRegistered = false;
289288
let transformArgs = args.transform;
290289
for (let i = 0, k = transformArgs.length; i < k; ++i) {
291290
let filename = transformArgs[i].trim();
292-
if (/\.ts$/.test(filename)) require("ts-node").register({ transpileOnly: true, skipProject: true });
291+
if (!tsNodeRegistered && filename.endsWith('.ts')) {
292+
require("ts-node").register({ transpileOnly: true, skipProject: true, compilerOptions: { target: "ES2016" } });
293+
tsNodeRegistered = true;
294+
}
293295
try {
294296
const classOrModule = require(require.resolve(filename, { paths: [baseDir, process.cwd()] }));
295297
if (typeof classOrModule === "function") {
@@ -370,8 +372,11 @@ exports.main = function main(argv, options, callback) {
370372
var sourceText = null; // text reported back to the compiler
371373
var sourcePath = null; // path reported back to the compiler
372374

375+
const libraryPrefix = exports.libraryPrefix;
376+
const libraryFiles = exports.libraryFiles;
377+
373378
// Try file.ts, file/index.ts, file.d.ts
374-
if (!internalPath.startsWith(exports.libraryPrefix)) {
379+
if (!internalPath.startsWith(libraryPrefix)) {
375380
if ((sourceText = readFile(sourcePath = internalPath + ".ts", baseDir)) == null) {
376381
if ((sourceText = readFile(sourcePath = internalPath + "/index.ts", baseDir)) == null) {
377382
// portable d.ts: uses the .js file next to it in JS or becomes an import in Wasm
@@ -381,22 +386,22 @@ exports.main = function main(argv, options, callback) {
381386

382387
// Search library in this order: stdlib, custom lib dirs, paths
383388
} else {
384-
const plainName = internalPath.substring(exports.libraryPrefix.length);
389+
const plainName = internalPath.substring(libraryPrefix.length);
385390
const indexName = plainName + "/index";
386-
if (exports.libraryFiles.hasOwnProperty(plainName)) {
387-
sourceText = exports.libraryFiles[plainName];
388-
sourcePath = exports.libraryPrefix + plainName + ".ts";
389-
} else if (exports.libraryFiles.hasOwnProperty(indexName)) {
390-
sourceText = exports.libraryFiles[indexName];
391-
sourcePath = exports.libraryPrefix + indexName + ".ts";
391+
if (libraryFiles.hasOwnProperty(plainName)) {
392+
sourceText = libraryFiles[plainName];
393+
sourcePath = libraryPrefix + plainName + ".ts";
394+
} else if (libraryFiles.hasOwnProperty(indexName)) {
395+
sourceText = libraryFiles[indexName];
396+
sourcePath = libraryPrefix + indexName + ".ts";
392397
} else { // custom lib dirs
393398
for (const libDir of customLibDirs) {
394399
if ((sourceText = readFile(plainName + ".ts", libDir)) != null) {
395-
sourcePath = exports.libraryPrefix + plainName + ".ts";
400+
sourcePath = libraryPrefix + plainName + ".ts";
396401
break;
397402
} else {
398403
if ((sourceText = readFile(indexName + ".ts", libDir)) != null) {
399-
sourcePath = exports.libraryPrefix + indexName + ".ts";
404+
sourcePath = libraryPrefix + indexName + ".ts";
400405
break;
401406
}
402407
}
@@ -412,7 +417,7 @@ exports.main = function main(argv, options, callback) {
412417
const absBasePath = path.isAbsolute(basePath) ? basePath : path.join(baseDir, basePath);
413418
const paths = [];
414419
for (let parts = absBasePath.split(SEP), i = parts.length, k = SEP == "/" ? 0 : 1; i >= k; --i) {
415-
if (parts[i - 1] != "node_modules") paths.push(parts.slice(0, i).join(SEP) + SEP + "node_modules");
420+
if (parts[i - 1] !== "node_modules") paths.push(parts.slice(0, i).join(SEP) + SEP + "node_modules");
416421
}
417422
for (const currentPath of paths.concat(...args.path).map(p => path.relative(baseDir, p))) {
418423
if (args.traceResolution) stderr.write(" in " + path.join(currentPath, packageName) + EOL);
@@ -435,14 +440,14 @@ exports.main = function main(argv, options, callback) {
435440
const mainDir = path.join(currentPath, packageName, mainPath);
436441
const plainName = filePath;
437442
if ((sourceText = readFile(path.join(mainDir, plainName + ".ts"), baseDir)) != null) {
438-
sourcePath = exports.libraryPrefix + packageName + "/" + plainName + ".ts";
443+
sourcePath = libraryPrefix + packageName + "/" + plainName + ".ts";
439444
packageBases.set(sourcePath.replace(/\.ts$/, ""), path.join(currentPath, packageName));
440445
if (args.traceResolution) stderr.write(" -> " + path.join(mainDir, plainName + ".ts") + EOL);
441446
break;
442447
} else if (!isPackageRoot) {
443448
const indexName = filePath + "/index";
444449
if ((sourceText = readFile(path.join(mainDir, indexName + ".ts"), baseDir)) !== null) {
445-
sourcePath = exports.libraryPrefix + packageName + "/" + indexName + ".ts";
450+
sourcePath = libraryPrefix + packageName + "/" + indexName + ".ts";
446451
packageBases.set(sourcePath.replace(/\.ts$/, ""), path.join(currentPath, packageName));
447452
if (args.traceResolution) stderr.write(" -> " + path.join(mainDir, indexName + ".ts") + EOL);
448453
break;
@@ -453,10 +458,8 @@ exports.main = function main(argv, options, callback) {
453458
}
454459
}
455460
}
456-
457461
// No such file
458462
if (sourceText == null) return null;
459-
460463
return { sourceText, sourcePath };
461464
}
462465

@@ -767,16 +770,17 @@ exports.main = function main(argv, options, callback) {
767770

768771
// Write binary
769772
if (args.binaryFile != null) {
773+
let basename = path.basename(args.binaryFile);
770774
let sourceMapURL = args.sourceMap != null
771775
? args.sourceMap.length
772776
? args.sourceMap
773-
: path.basename(args.binaryFile) + ".map"
777+
: "./" + basename + ".map"
774778
: null;
775779

776780
let wasm;
777781
stats.emitCount++;
778782
stats.emitTime += measure(() => {
779-
wasm = module.toBinary(sourceMapURL)
783+
wasm = module.toBinary(sourceMapURL);
780784
});
781785

782786
if (args.binaryFile.length) {
@@ -790,18 +794,19 @@ exports.main = function main(argv, options, callback) {
790794
// Post-process source map
791795
if (wasm.sourceMap != null) {
792796
if (args.binaryFile.length) {
793-
let sourceMap = JSON.parse(wasm.sourceMap);
794-
sourceMap.sourceRoot = exports.sourceMapRoot;
795-
sourceMap.sources.forEach((name, index) => {
797+
let map = JSON.parse(wasm.sourceMap);
798+
map.sourceRoot = "./" + basename;
799+
let contents = [];
800+
map.sources.forEach((name, index) => {
796801
let text = assemblyscript.getSource(program, name.replace(/\.ts$/, ""));
797802
if (text == null) return callback(Error("Source of file '" + name + "' not found."));
798-
if (!sourceMap.sourceContents) sourceMap.sourceContents = [];
799-
sourceMap.sourceContents[index] = text;
803+
contents[index] = text;
800804
});
805+
map.sourcesContent = contents;
801806
writeFile(path.join(
802807
path.dirname(args.binaryFile),
803808
path.basename(sourceMapURL)
804-
).replace(/^\.\//, ""), JSON.stringify(sourceMap), baseDir);
809+
).replace(/^\.\//, ""), JSON.stringify(map), baseDir);
805810
} else {
806811
stderr.write("Skipped source map (stdout already occupied)" + EOL);
807812
}

src/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"compilerOptions": {
44
"outDir": "../out",
55
"allowJs": false,
6-
"sourceMap": true
6+
"sourceMap": true,
7+
"target": "ES2016"
78
},
89
"include": [
910
"./**/*.ts"

0 commit comments

Comments
 (0)