Skip to content

Commit c4ebc8c

Browse files
committed
Fix missing dependency in asc, see AssemblyScript#157; Downgrade ts-node to v6
1 parent 5ca5df3 commit c4ebc8c

19 files changed

+78
-90
lines changed

cli/asc.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,25 @@ const EOL = process.platform === "win32" ? "\r\n" : "\n";
2424
// Use distribution files if present, otherwise run the sources directly
2525
var assemblyscript, isDev = false;
2626
(() => {
27-
try {
27+
try { // `asc` on the command line
2828
assemblyscript = require("../dist/assemblyscript.js");
2929
} catch (e) {
30-
try {
30+
try { // `asc` on the command line without dist files
3131
require("ts-node").register({ project: path.join(__dirname, "..", "src", "tsconfig.json") });
3232
require("../src/glue/js");
3333
assemblyscript = require("../src");
3434
isDev = true;
35-
} catch (e) {
36-
// last resort: same directory CommonJS
37-
assemblyscript = eval("require('./assemblyscript')");
35+
} catch (e_ts) {
36+
try { // `require("dist/asc.js")` in explicit browser tests
37+
assemblyscript = eval("require('./assemblyscript')");
38+
} catch (e) {
39+
// combine both errors that lead us here
40+
e.stack = e_ts.stack + "\n---\n" + e.stack;
41+
// Emscripten adds an `uncaughtException` listener to Binaryen that results in an additional
42+
// useless code fragment on top of the actual error. suppress this:
43+
if (process.removeAllListeners) process.removeAllListeners("uncaughtException");
44+
throw e;
45+
}
3846
}
3947
}
4048
})();
@@ -408,9 +416,8 @@ exports.main = function main(argv, options, callback) {
408416
assemblyscript.setGlobalAlias(compilerOptions, "abort", "~lib/env/abort"); // to disable: --use abort=
409417

410418
// Add or override aliases if specified
411-
var aliases = args.use;
412-
if (aliases != null) {
413-
if (typeof aliases === "string") aliases = aliases.split(",");
419+
if (args.use) {
420+
let aliases = args.use;
414421
for (let i = 0, k = aliases.length; i < k; ++i) {
415422
let part = aliases[i];
416423
let p = part.indexOf("=");
@@ -709,7 +716,7 @@ exports.main = function main(argv, options, callback) {
709716
var files;
710717
try {
711718
stats.readTime += measure(() => {
712-
files = require("glob").sync("!(*.d).ts", { cwd: dirname });
719+
files = fs.readdirSync(dirname).filter(file => /^(?!.*\.d\.ts$).*\.ts$/.test(file));
713720
});
714721
return files;
715722
} catch (e) {

cli/asc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"Aliases a global object under another name, e.g., to switch",
134134
"the default 'Math' implementation used: --use Math=JSMath"
135135
],
136-
"type": "s",
136+
"type": "S",
137137
"alias": "u"
138138
},
139139
"trapMode": {

cli/util/options.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ function parse(argv, config) {
3030
for (var i = 0, k = (argv = argv.slice()).length; i < k; ++i) {
3131
let arg = argv[i];
3232
if (arg == "--") { ++i; break; }
33-
let match = /^(?:(\-\w)|(\-\-\w{2,})(?:=(.*))?)$/.exec(arg), option, key;
33+
let match = /^(?:(\-\w)(?:=(.*))?|(\-\-\w{2,})(?:=(.*))?)$/.exec(arg), option, key;
3434
if (match) {
3535
if (config[arg]) option = config[key = arg]; // exact
36-
else if (match[1] != null) option = config[key = aliases[match[1].substring(1)]]; // alias
37-
else if (match[2] != null) {
38-
option = config[key = match[2].substring(2)]; // full
39-
if (option && match[3] != null) argv[i--] = match[3];
36+
else if (match[1] != null) { // alias
37+
option = config[key = aliases[match[1].substring(1)]];
38+
if (option && match[2] != null) argv[i--] = match[2];
39+
} else if (match[3] != null) { // full
40+
option = config[key = match[3].substring(2)];
41+
if (option && match[4] != null) argv[i--] = match[4];
4042
}
4143
} else {
4244
if (arg.charCodeAt(0) == 45) option = config[key = arg]; // exact

dist/asc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/asc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"diff": "^3.5.0",
2222
"glob": "^7.1.2",
2323
"ts-loader": "^4.4.2",
24-
"ts-node": "^7.0.0",
24+
"ts-node": "^6.2.0",
2525
"tslint": "^5.10.0",
2626
"typedoc": "^0.11.1",
2727
"typedoc-plugin-external-module-name": "^1.1.1",

src/compiler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5894,8 +5894,7 @@ export class Compiler extends DiagnosticEmitter {
58945894
// otherwise resolve
58955895
var target = this.program.resolveIdentifier( // reports
58965896
expression,
5897-
currentFunction,
5898-
this.currentEnum
5897+
this.currentEnum || currentFunction
58995898
);
59005899
if (!target) return module.createUnreachable();
59015900

src/glue/js/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
* @preferred
55
*//***/
66

7-
/// <reference path="./binaryen.d.ts" />
8-
/// <reference path="./float.d.ts" />
9-
/// <reference path="./i64.d.ts" />
107
/// <reference path="./node.d.ts" />
118

129
import "../../../std/portable/index";

src/program.ts

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,11 @@ export class Program extends DiagnosticEmitter {
326326

327327
/** Array prototype reference. */
328328
arrayPrototype: ClassPrototype | null = null;
329-
/** ArrayBufferView prototype reference. */
330-
arrayBufferViewPrototype: InterfacePrototype | null = null;
331329
/** String instance reference. */
332330
stringInstance: Class | null = null;
333331
/** Start function reference. */
334332
startFunction: FunctionPrototype;
335-
/** Main function reference. */
333+
/** Main function reference, if present. */
336334
mainFunction: FunctionPrototype | null = null;
337335

338336
/** Target expression of the previously resolved property or element access. */
@@ -593,13 +591,6 @@ export class Program extends DiagnosticEmitter {
593591
this.arrayPrototype = <ClassPrototype>arrayPrototype;
594592
}
595593

596-
// register 'ArrayBufferView'
597-
var arrayBufferViewPrototype = this.elementsLookup.get("ArrayBufferView");
598-
if (arrayBufferViewPrototype) {
599-
assert(arrayBufferViewPrototype.kind == ElementKind.INTERFACE_PROTOTYPE);
600-
this.arrayBufferViewPrototype = <InterfacePrototype>arrayBufferViewPrototype;
601-
}
602-
603594
// register 'String'
604595
var stringPrototype = this.elementsLookup.get("String");
605596
if (stringPrototype) {
@@ -2097,58 +2088,46 @@ export class Program extends DiagnosticEmitter {
20972088
/** Resolves an identifier to the element it refers to. */
20982089
resolveIdentifier(
20992090
identifier: IdentifierExpression,
2100-
contextualFunction: Function | null,
2101-
contextualEnum: Enum | null = null
2091+
context: Element | null
21022092
): Element | null {
21032093
var name = identifier.text;
2104-
21052094
var element: Element | null;
2106-
var namespace: Element | null;
21072095

2108-
// check siblings
2109-
if (contextualEnum) {
2096+
if (context) {
2097+
let parent: Element | null;
21102098

2111-
if (
2112-
contextualEnum.members &&
2113-
(element = contextualEnum.members.get(name)) &&
2114-
element.kind == ElementKind.ENUMVALUE
2115-
) {
2116-
this.resolvedThisExpression = null;
2117-
this.resolvedElementExpression = null;
2118-
return element; // ENUMVALUE
2119-
}
2120-
2121-
} else if (contextualFunction) {
2122-
2123-
// check locals
2124-
if (element = contextualFunction.flow.getScopedLocal(name)) {
2125-
this.resolvedThisExpression = null;
2126-
this.resolvedElementExpression = null;
2127-
return element; // LOCAL
2128-
}
2129-
2130-
// check outer scope locals
2131-
// let outerScope = contextualFunction.outerScope;
2132-
// while (outerScope) {
2133-
// if (element = outerScope.getScopedLocal(name)) {
2134-
// let scopedLocal = <Local>element;
2135-
// let scopedGlobal = scopedLocal.scopedGlobal;
2136-
// if (!scopedGlobal) scopedGlobal = outerScope.addScopedGlobal(scopedLocal);
2137-
// if (!resolvedElement) resolvedElement = new ResolvedElement();
2138-
// return resolvedElement.set(scopedGlobal);
2139-
// }
2140-
// outerScope = outerScope.currentFunction.outerScope;
2141-
// }
2099+
switch (context.kind) {
2100+
case ElementKind.FUNCTION: { // search locals
2101+
element = (<Function>context).flow.getScopedLocal(name);
2102+
if (element) {
2103+
this.resolvedThisExpression = null;
2104+
this.resolvedElementExpression = null;
2105+
return element;
2106+
}
2107+
parent = (<Function>context).prototype.parent;
2108+
break;
2109+
}
2110+
case ElementKind.CLASS: {
2111+
parent = (<Class>context).prototype.parent;
2112+
break;
2113+
}
2114+
default: {
2115+
parent = context;
2116+
break;
2117+
}
2118+
}
21422119

2143-
// search contextual parent namespaces if applicable
2144-
if (namespace = contextualFunction.prototype.parent) {
2145-
do {
2146-
if (element = this.elementsLookup.get(namespace.internalName + STATIC_DELIMITER + name)) {
2120+
// search parent
2121+
while (parent) {
2122+
let members = parent.members;
2123+
if (members) {
2124+
if (element = members.get(name)) {
21472125
this.resolvedThisExpression = null;
21482126
this.resolvedElementExpression = null;
2149-
return element; // LOCAL
2127+
return element;
21502128
}
2151-
} while (namespace = namespace.parent);
2129+
}
2130+
parent = parent.parent;
21522131
}
21532132
}
21542133

std/assembly.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"module": "commonjs",
66
"noLib": true,
77
"allowJs": false,
8-
"typeRoots": [ "." ],
9-
"types": [ "assembly/" ]
8+
"typeRoots": [ "types" ],
9+
"types": [ "assembly" ]
1010
}
1111
}

std/portable.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"allowJs": true,
88
"downlevelIteration": true,
99
"preserveConstEnums": true,
10-
"typeRoots": [ "." ],
11-
"types": [ "portable/" ]
10+
"typeRoots": [ "types" ],
11+
"types": [ "portable" ]
1212
}
1313
}

std/types/assembly/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "../../assembly/index";

std/types/assembly/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"types": "index.d.ts"
3+
}

std/types/portable/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "../../portable/index";

std/types/portable/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"types": "index.d.ts"
3+
}

tests/parser.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ if (argv.length) {
4949
}
5050
}
5151

52-
require("ts-node").register({
53-
project: path.join(__dirname, "..", "src", "tsconfig.json"),
54-
cache: false // FIXME: for some reason, if both asc and the parser tests use caching, the one
55-
// invoked later cannot find some definition files.
56-
});
52+
require("ts-node").register({ project: path.join(__dirname, "..", "src", "tsconfig.json") });
5753
require("../src/glue/js");
5854

5955
var Parser = require("../src/parser").Parser;

0 commit comments

Comments
 (0)