Properly inline getters; Simplify blocks when last statement returns

This commit is contained in:
dcodeIO
2018-06-22 15:26:59 +02:00
parent 525795b354
commit 7a8995b18b
75 changed files with 5090 additions and 6836 deletions

11
std/assembly.d.ts vendored
View File

@ -3,6 +3,8 @@
* @module std/assembly
*//***/
/// <reference no-default-lib="true"/>
// Types
/** An 8-bit signed integer. */
@ -467,11 +469,12 @@ declare class Set<T> {
clear(): void;
}
declare class Symbol {
constructor(description?: string | null);
static for(key: string): Symbol;
static keyFor(sym: Symbol): string | null;
interface SymbolConstructor {
(description?: string | null): symbol;
for(key: string): symbol;
keyFor(sym: symbol): string | null;
}
declare const Symbol: SymbolConstructor;
interface IMath<T> {
/** The base of natural logarithms, e, approximately 2.718. */

View File

@ -1,30 +1,50 @@
import { Map } from "./map";
var nextId: usize = 1;
var stringToId: Map<string, usize>;
var idToString: Map<usize, string>;
var nextId: usize = 12; // Symbol.unscopables + 1
export class Symbol {
@unmanaged export class symbol {}
static for(key: string): Symbol {
type Symbol = symbol;
export function Symbol(description: string | null = null): symbol {
var id = nextId++;
if (!id) unreachable(); // out of ids
return changetype<symbol>(id);
}
export namespace Symbol {
// well-known symbols
export const hasInstance = changetype<symbol>(1);
export const concatSpreadable = changetype<symbol>(2);
export const isRegExp = changetype<symbol>(3);
export const iterator = changetype<symbol>(3);
export const match = changetype<symbol>(4);
export const replace = changetype<symbol>(5);
export const search = changetype<symbol>(6);
export const species = changetype<symbol>(7);
export const split = changetype<symbol>(8);
export const toPrimitive = changetype<symbol>(9);
export const toStringTag = changetype<symbol>(10);
export const unscopables = changetype<symbol>(11);
/* tslint:disable */// not valid TS
export function for(key: string): symbol {
if (!stringToId) { stringToId = new Map(); idToString = new Map(); }
else if (stringToId.has(key)) return changetype<Symbol>(stringToId.get(key));
else if (stringToId.has(key)) return changetype<symbol>(stringToId.get(key));
var id = nextId++;
if (!id) unreachable(); // out of ids
stringToId.set(key, id);
idToString.set(id, key);
return changetype<Symbol>(id);
return changetype<symbol>(id);
}
/* tslint:enable */
static keyFor(sym: Symbol): string | null {
export function keyFor(sym: symbol): string | null {
return idToString !== null && idToString.has(changetype<usize>(sym))
? idToString.get(changetype<usize>(sym))
: null;
}
constructor(description: string | null = null) {
var id = nextId++;
if (!id) unreachable(); // out of ids
return changetype<Symbol>(id);
}
}

15
std/portable.d.ts vendored
View File

@ -12,6 +12,8 @@
* @module std/portable
*//***/
/// <reference no-default-lib="true"/>
// Portable types
declare type i8 = number;
@ -309,11 +311,6 @@ declare class Error {
stack: string | null;
}
declare class Symbol {
private constructor();
static readonly iterator: symbol;
}
declare class Set<T> {
constructor(entries?: T[]);
readonly size: i32;
@ -337,6 +334,14 @@ declare class Map<K,V> {
[Symbol.iterator](): Iterator<[K,V]>;
}
interface SymbolConstructor {
(description?: string | null): symbol;
for(key: string): symbol;
keyFor(sym: symbol): string | null;
readonly iterator: symbol;
}
declare const Symbol: SymbolConstructor;
interface Iterable<T> {
[Symbol.iterator](): Iterator<T>;
}