Skip to content

Use fully qualified names in generic types #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion bin/asc
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
#!/usr/bin/env node

/* tslint:disable */

const tailArgs = process.argv.indexOf("--");
if (~tailArgs) {
require("child_process").spawnSync(
process.argv[0],
process.argv.slice(tailArgs + 1).concat(
process.argv.slice(1, tailArgs)
),
{ stdio: "inherit" }
);
return;
}

require("source-map-support").install();

const asc = module.exports = require("../cli/asc.js");
if (/\basc$/.test(process.argv[1])) process.exitCode = asc.main(process.argv.slice(2));
if (/\basc$/.test(process.argv[1])) {
process.exitCode = asc.main(process.argv.slice(2));
}
3 changes: 3 additions & 0 deletions bin/asinit
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env node

/* tslint:disable */

const fs = require("fs");
const path = require("path");
const colors = require("../cli/util/colors");
Expand Down
3 changes: 3 additions & 0 deletions cli/asc.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@
"type": "b",
"default": false
},
" ...": {
"description": "Specifies node.js options (CLI only). See: node --help"
},
"-Os": { "value": { "optimize": true, "shrinkLevel": 1 } },
"-Oz": { "value": { "optimize": true, "shrinkLevel": 2 } },
"-O0": { "value": { "optimizeLevel": 0, "shrinkLevel": 0 } },
Expand Down
1 change: 1 addition & 0 deletions cli/util/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function parse(argv, config) {
// make an alias map and initialize defaults
var aliases = {};
Object.keys(config).forEach(key => {
if (key.startsWith(" ")) return;
var option = config[key];
if (option.alias != null) {
if (typeof option.alias === "string") aliases[option.alias] = key;
Expand Down
40 changes: 37 additions & 3 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,16 @@ export class Parser extends DiagnosticEmitter {
do {
let member = this.parseClassMember(tn, declaration);
if (member) members.push(<DeclarationStatement>member);
else {
this.skipStatement(tn);
if (tn.skip(Token.ENDOFFILE)) {
this.error(
DiagnosticCode._0_expected,
tn.range(), "}"
);
return null;
}
}
} while (!tn.skip(Token.CLOSEBRACE));
}
return declaration;
Expand Down Expand Up @@ -1611,6 +1621,16 @@ export class Parser extends DiagnosticEmitter {
do {
let member = this.parseClassMember(tn, declaration);
if (member) members.push(<DeclarationStatement>member);
else {
this.skipStatement(tn);
if (tn.skip(Token.ENDOFFILE)) {
this.error(
DiagnosticCode._0_expected,
tn.range(), "}"
);
return null;
}
}
} while (!tn.skip(Token.CLOSEBRACE));
}
return Node.createClassExpression(declaration);
Expand Down Expand Up @@ -2145,6 +2165,16 @@ export class Parser extends DiagnosticEmitter {
while (!tn.skip(Token.CLOSEBRACE)) {
let member = this.parseTopLevelStatement(tn, ns);
if (member) members.push(member);
else {
this.skipStatement(tn);
if (tn.skip(Token.ENDOFFILE)) {
this.error(
DiagnosticCode._0_expected,
tn.range(), "}"
);
return null;
}
}
}
tn.skip(Token.SEMICOLON);
return ns;
Expand Down Expand Up @@ -2175,9 +2205,9 @@ export class Parser extends DiagnosticEmitter {
if (tn.skip(Token.OPENBRACE)) {
let members = new Array<ExportMember>();
while (!tn.skip(Token.CLOSEBRACE)) {
let member = this.parseExportMember(tn);
if (!member) return null;
members.push(member);
let member = this.parseExportMember(tn);
if (!member) return null;
members.push(member);
if (!tn.skip(Token.COMMA)) {
if (tn.skip(Token.CLOSEBRACE)) {
break;
Expand Down Expand Up @@ -3712,6 +3742,10 @@ export class Parser extends DiagnosticEmitter {
tn.readFloat();
break;
}
case Token.OPENBRACE: {
this.skipBlock(tn);
break;
}
}
} while (true);
}
Expand Down
25 changes: 12 additions & 13 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,20 @@ export class Type {
return null;
}

/** Converts this type to its TypeScript representation. */
toString(kindOnly: bool = false): string {
if (!kindOnly && this.is(TypeFlags.REFERENCE)) {
/** Converts this type to a string. */
toString(): string {
if (this.is(TypeFlags.REFERENCE)) {
let classReference = this.classReference;
if (classReference) {
return this.is(TypeFlags.NULLABLE)
? classReference.name + " | null"
: classReference.name;
? classReference.internalName + " | null"
: classReference.internalName;
}
let signatureReference = this.signatureReference;
if (signatureReference) {
return this.is(TypeFlags.NULLABLE)
? "(" + signatureReference.toString(true) + ") | null"
: signatureReference.toString(true);
? "(" + signatureReference.toString() + ") | null"
: signatureReference.toString();
}
assert(false);
}
Expand Down Expand Up @@ -637,17 +637,16 @@ export class Signature {
}

/** Converts this signature to a string. */
toString(includeThis: bool = false): string {
toString(): string {
var sb = new Array<string>();
sb.push("(");
var index = 0;
var thisType = this.thisType;
if (thisType) {
if (includeThis) {
sb.push("this: ");
sb.push(thisType.toString());
index = 1;
}
sb.push("this: ");
assert(!thisType.signatureReference);
sb.push(thisType.toString());
index = 1;
}
var parameters = this.parameterTypes;
var numParameters = parameters.length;
Expand Down
7 changes: 6 additions & 1 deletion tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,12 @@ tests.forEach(filename => {
stderr: stderr
}, err => {
console.log();
if (err)
if (err) {
stderr.write(err.stack + os.EOL);
failedMessages.set(basename, err.message);
failedTests.push(basename);
return 1;
}

// Instantiate
try {
Expand Down Expand Up @@ -308,6 +312,7 @@ tests.forEach(filename => {
if (failed) failedTests.push(basename);
console.log();
});
if (failed) return 1;
});
if (v8_no_flags) v8.setFlagsFromString(v8_no_flags);
});
Expand Down
12 changes: 6 additions & 6 deletions tests/compiler/nonNullAssertion.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
local.get $0
i32.load
)
(func $~lib/array/Array<Foo>#__get (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<nonNullAssertion/Foo>#__get (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
Expand Down Expand Up @@ -87,9 +87,9 @@
(func $nonNullAssertion/testArr (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 0
call $~lib/array/Array<Foo>#__get
call $~lib/array/Array<nonNullAssertion/Foo>#__get
)
(func $~lib/array/Array<Foo | null>#__get (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<nonNullAssertion/Foo | null>#__get (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
Expand Down Expand Up @@ -125,18 +125,18 @@
(func $nonNullAssertion/testElem (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 0
call $~lib/array/Array<Foo | null>#__get
call $~lib/array/Array<nonNullAssertion/Foo | null>#__get
)
(func $nonNullAssertion/testAll (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 0
call $~lib/array/Array<Foo | null>#__get
call $~lib/array/Array<nonNullAssertion/Foo | null>#__get
i32.load
)
(func $nonNullAssertion/testAll2 (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 0
call $~lib/array/Array<Foo | null>#__get
call $~lib/array/Array<nonNullAssertion/Foo | null>#__get
i32.load
)
(func $nonNullAssertion/testFn (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
Expand Down
20 changes: 10 additions & 10 deletions tests/compiler/std/array-access.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(export "stringArrayMethodCall" (func $std/array-access/stringArrayMethodCall))
(export "stringArrayArrayPropertyAccess" (func $std/array-access/stringArrayArrayPropertyAccess))
(export "stringArrayArrayMethodCall" (func $std/array-access/stringArrayArrayMethodCall))
(func $~lib/array/Array<Array<i32>>#__get (; 1 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<~lib/array/Array<i32>>#__get (; 1 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
Expand Down Expand Up @@ -89,11 +89,11 @@
(func $std/array-access/i32ArrayArrayElementAccess (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 0
call $~lib/array/Array<Array<i32>>#__get
call $~lib/array/Array<~lib/array/Array<i32>>#__get
i32.const 1
call $~lib/array/Array<i32>#__get
)
(func $~lib/array/Array<String>#__get (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<~lib/string/String>#__get (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
Expand Down Expand Up @@ -129,7 +129,7 @@
(func $std/array-access/stringArrayPropertyAccess (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 0
call $~lib/array/Array<String>#__get
call $~lib/array/Array<~lib/string/String>#__get
i32.load
)
(func $~lib/internal/string/compareUnsafe (; 6 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32)
Expand Down Expand Up @@ -255,12 +255,12 @@
(func $std/array-access/stringArrayMethodCall (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 0
call $~lib/array/Array<String>#__get
call $~lib/array/Array<~lib/string/String>#__get
i32.const 8
i32.const 0
call $~lib/string/String#startsWith
)
(func $~lib/array/Array<Array<String>>#__get (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/array/Array<~lib/array/Array<~lib/string/String>>#__get (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
Expand Down Expand Up @@ -296,17 +296,17 @@
(func $std/array-access/stringArrayArrayPropertyAccess (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 0
call $~lib/array/Array<Array<String>>#__get
call $~lib/array/Array<~lib/array/Array<~lib/string/String>>#__get
i32.const 1
call $~lib/array/Array<String>#__get
call $~lib/array/Array<~lib/string/String>#__get
i32.load
)
(func $std/array-access/stringArrayArrayMethodCall (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 0
call $~lib/array/Array<Array<String>>#__get
call $~lib/array/Array<~lib/array/Array<~lib/string/String>>#__get
i32.const 1
call $~lib/array/Array<String>#__get
call $~lib/array/Array<~lib/string/String>#__get
i32.const 8
i32.const 0
call $~lib/string/String#startsWith
Expand Down
Loading