Skip to content

Commit a196f4d

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents 3b2d41f + ccb1296 commit a196f4d

File tree

114 files changed

+10757
-6591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+10757
-6591
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,20 @@ jobs:
141141
cd lib/loader
142142
npm run asbuild
143143
npm run test
144+
test-bootstrap:
145+
name: "Test self-compilation on node: node"
146+
runs-on: ubuntu-latest
147+
needs: check
148+
steps:
149+
- uses: actions/[email protected]
150+
- uses: dcodeIO/[email protected]
151+
with:
152+
node-version: node
153+
- name: Install dependencies
154+
run: npm ci --no-audit
155+
- name: Clean distribution files
156+
run: npm run clean
157+
- name: Test self-compilation
158+
run: |
159+
npm run asbuild
160+
npm run astest

cli/asc.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @fileoverview Definitions for asc.
3+
* @license Apache-2.0
4+
*/
5+
16
import { OptionDescription } from "./util/options";
27
export { OptionDescription };
38

cli/asc.js

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
"use strict";
21
/**
3-
* Compiler frontend for node.js
2+
* @license
3+
* Copyright 2020 Daniel Wirtz / The AssemblyScript Authors.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* SPDX-License-Identifier: Apache-2.0
18+
*/
19+
20+
/**
21+
* @fileoverview Compiler frontend for node.js
422
*
523
* Uses the low-level API exported from src/index.ts so it works with the compiler compiled to
624
* JavaScript as well as the compiler compiled to WebAssembly (eventually). Runs the sources
725
* directly through ts-node if distribution files are not present (indicated by a `-dev` version).
826
*
927
* Can also be packaged as a bundle suitable for in-browser use with the standard library injected
1028
* in the build step. See dist/asc.js for the bundle and webpack.config.js for building details.
11-
*
12-
* @module cli/asc
1329
*/
1430

1531
// Use "." instead of "/" as cwd in browsers
@@ -390,7 +406,8 @@ exports.main = function main(argv, options, callback) {
390406
if ((sourceText = readFile(sourcePath = internalPath + ".ts", baseDir)) == null) {
391407
if ((sourceText = readFile(sourcePath = internalPath + "/index.ts", baseDir)) == null) {
392408
// portable d.ts: uses the .js file next to it in JS or becomes an import in Wasm
393-
sourceText = readFile(sourcePath = internalPath + ".d.ts", baseDir);
409+
sourcePath = internalPath + ".ts";
410+
sourceText = readFile(internalPath + ".d.ts", baseDir);
394411
}
395412
}
396413

@@ -478,13 +495,16 @@ exports.main = function main(argv, options, callback) {
478495
var internalPath;
479496
while ((internalPath = assemblyscript.nextFile(program)) != null) {
480497
let file = getFile(internalPath, assemblyscript.getDependee(program, internalPath));
481-
if (!file) return callback(Error("Import file '" + internalPath + ".ts' not found."))
498+
if (!file) return callback(Error("Import '" + internalPath + "' not found."))
482499
stats.parseCount++;
483500
stats.parseTime += measure(() => {
484501
assemblyscript.parse(program, file.sourceText, file.sourcePath, false);
485502
});
486503
}
487-
if (checkDiagnostics(program, stderr)) return callback(Error("Parse error"));
504+
var numErrors = checkDiagnostics(program, stderr);
505+
if (numErrors) {
506+
return callback(Error(numErrors + " parse error(s)"));
507+
}
488508
}
489509

490510
// Include runtime template before entry files so its setup runs first
@@ -570,6 +590,20 @@ exports.main = function main(argv, options, callback) {
570590
optimizeLevel = Math.min(Math.max(optimizeLevel, 0), 3);
571591
shrinkLevel = Math.min(Math.max(shrinkLevel, 0), 2);
572592

593+
try {
594+
stats.compileTime += measure(() => {
595+
assemblyscript.initializeProgram(program, compilerOptions);
596+
});
597+
} catch(e) {
598+
return callback(e);
599+
}
600+
601+
// Call afterInitialize transform hook
602+
{
603+
let error = applyTransform("afterInitialize", program);
604+
if (error) return callback(error);
605+
}
606+
573607
var module;
574608
stats.compileCount++;
575609
try {
@@ -579,9 +613,10 @@ exports.main = function main(argv, options, callback) {
579613
} catch (e) {
580614
return callback(e);
581615
}
582-
if (checkDiagnostics(program, stderr)) {
616+
var numErrors = checkDiagnostics(program, stderr);
617+
if (numErrors) {
583618
if (module) module.dispose();
584-
return callback(Error("Compile error"));
619+
return callback(Error(numErrors + " compile error(s)"));
585620
}
586621

587622
// Call afterCompile transform hook
@@ -1023,17 +1058,17 @@ exports.main = function main(argv, options, callback) {
10231058
/** Checks diagnostics emitted so far for errors. */
10241059
function checkDiagnostics(program, stderr) {
10251060
var diagnostic;
1026-
var hasErrors = false;
1061+
var numErrors = 0;
10271062
while ((diagnostic = assemblyscript.nextDiagnostic(program)) != null) {
10281063
if (stderr) {
10291064
stderr.write(
10301065
assemblyscript.formatDiagnostic(diagnostic, stderr.isTTY, true) +
10311066
EOL + EOL
10321067
);
10331068
}
1034-
if (assemblyscript.isError(diagnostic)) hasErrors = true;
1069+
if (assemblyscript.isError(diagnostic)) ++numErrors;
10351070
}
1036-
return hasErrors;
1071+
return numErrors;
10371072
}
10381073

10391074
exports.checkDiagnostics = checkDiagnostics;

cli/transform.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Definitions for custom compiler transforms that can be applied with the `--transform` option.
3-
* @module cli/transform
4-
*//***/
2+
* @fileoverview Compiler transform interface definitions.
3+
* @license Apache-2.0
4+
*/
55

66
import { Program, Parser, Module } from "..";
77
import { OutputStream } from "./asc";
@@ -35,6 +35,9 @@ export abstract class Transform {
3535
/** Called when parsing is complete, before a program is instantiated from the AST. */
3636
afterParse?(parser: Parser): void;
3737

38+
/** Called after the program is instantiated. */
39+
afterInitialize?(program: Program): void;
40+
3841
/** Called when compilation is complete, before the module is being validated. */
3942
afterCompile?(module: Module): void;
4043
}

cli/transform.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
/**
2+
* @fileoverview Compiler transform interface.
3+
* @license Apache-2.0
4+
*/
5+
16
// becomes replaced with the actual base by asc
27
exports.Transform = function Transform() {};

cli/util/colors.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @fileoverview Terminal colors utility definitions.
3+
* @license Apache-2.0
4+
*/
5+
16
interface Colors {
27
/** Whether terminal colors are supported. */
38
supported: boolean;

cli/util/colors.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @fileoverview Terminal colors utility.
3+
* @license Apache-2.0
4+
*/
5+
16
var proc = typeof process !== "undefined" && process || {};
27
var isCI = proc.env && "CI" in proc.env; // doesn't work when bundled because 'process' is a mock
38

cli/util/find.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @fileoverview File finding utility definitions.
3+
* @license Apache-2.0
4+
*/
5+
16
export function files(dirname: string, filter?: ((name: string) => bool) | RegExp): string[];
27
export const TS: RegExp;
38
export const TS_EXCEPT_DTS: RegExp;

cli/util/find.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @fileoverview File finding utility.
3+
* @license Apache-2.0
4+
*/
5+
16
const fs = require("fs");
27
const path = require("path");
38

cli/util/mkdirp.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* @fileoverview Recursive mkdir definitions.
3+
* @license Apache-2.0
4+
*/
5+
16
interface Options {
27
mode?: number;
38
}

0 commit comments

Comments
 (0)