Compare commits

...

9 Commits

11 changed files with 55 additions and 22 deletions

View File

@ -112,7 +112,8 @@ export interface Primordials {
schedule(func: () => void, delay: number): () => void; schedule(func: () => void, delay: number): () => void;
} }
globalThis.undefined = void 0; // prevent optimization to "undefined", which doesn't exist yet
globalThis.undefined = ({} as any).bogus;
export const target = (globalThis as any).target; export const target = (globalThis as any).target;
export const primordials: Primordials = (globalThis as any).primordials; export const primordials: Primordials = (globalThis as any).primordials;

View File

@ -33,7 +33,7 @@ export const Array = (() => {
for (let i = arguments.length - 1; i >= 0; i--) { for (let i = arguments.length - 1; i >= 0; i--) {
this[start + i] = arguments[i]; this[start + i] = arguments[i];
} }
return arguments.length; return this.length;
} }
public pop(this: any[]) { public pop(this: any[]) {
if (this.length === 0) return undefined; if (this.length === 0) return undefined;
@ -51,7 +51,7 @@ export const Array = (() => {
for (let i = 0; i < arguments.length; i++) { for (let i = 0; i < arguments.length; i++) {
this[i] = arguments[i]; this[i] = arguments[i];
} }
return arguments.length; return this.length;
} }
public shift(this: any[]) { public shift(this: any[]) {
if (this.length === 0) return undefined; if (this.length === 0) return undefined;

View File

@ -82,13 +82,13 @@ export const Object = (() => {
res.s = set; res.s = set;
} }
if ("enumerable" in desc) res.e = !!desc.enumerable; if ("enumerable" in desc) res.e = !!desc.enumerable;
if ("configurable" in desc) res.e = !!desc.configurable; if ("configurable" in desc) res.c = !!desc.configurable;
if (!object.defineProperty(obj, key, res)) throw new TypeError("Cannot redefine property: " + String(key)); if (!object.defineProperty(obj, key, res)) throw new TypeError("Cannot redefine property: " + String(key));
} }
else { else {
if ("enumerable" in desc) res.e = !!desc.enumerable; if ("enumerable" in desc) res.e = !!desc.enumerable;
if ("configurable" in desc) res.e = !!desc.configurable; if ("configurable" in desc) res.c = !!desc.configurable;
if ("writable" in desc) res.w = !!desc.writable; if ("writable" in desc) res.w = !!desc.writable;
if ("value" in desc) res.v = desc.value; if ("value" in desc) res.v = desc.value;

View File

@ -41,8 +41,9 @@ export const String = (() => {
offset = +offset; offset = +offset;
return string.indexOf(self, search, offset, false); return string.indexOf(self, search, offset, false);
} }
public lastIndexOf(search: string, offset = 0) { public lastIndexOf(search: string, offset?: number) {
const self = unwrapThis(this, "string", String, "String.prototype.lastIndexOf"); const self = unwrapThis(this, "string", String, "String.prototype.lastIndexOf");
if (offset == null) offset = self.length;
offset = +offset; offset = +offset;
return string.indexOf(self, search, offset, true); return string.indexOf(self, search, offset, true);
} }

View File

@ -1,7 +1,4 @@
// import coffeescript from "./coffeescript.ts"; import coffeescript from "./coffeescript.ts";
// import babel from "./babel.ts"; import babel from "./babel.ts";
// register(v => coffeescript(babel(v))); register(v => coffeescript(babel(v)));
import typescript from "./typescript.ts";
register(typescript);

View File

@ -11,17 +11,14 @@ export default function babel(next: Compiler): Compiler {
presets: [availablePresets.env], presets: [availablePresets.env],
}); });
print(res.map!.mappings);
const map = SourceMap.parse({ const map = SourceMap.parse({
file: "babel-internal://" + filename, file: "babel-internal://" + filename,
mappings: res.map!.mappings, mappings: res.map!.mappings,
sources: [filename], sources: [filename],
}); });
const compiled = next("babel-internal://" + filename, res.code!, SourceMap.chain(map, prevMap));
registerSource(filename, code); registerSource(filename, code);
return compiled; return next("babel-internal://" + filename, res.code!, SourceMap.chain(map, prevMap));
}; };
} }

View File

@ -20,9 +20,8 @@ export default function coffee(next: Compiler): Compiler {
sources: [filename], sources: [filename],
}); });
const compiled = next("coffee-internal://" + filename, result, SourceMap.chain(map, prevMap));
registerSource(filename, code); registerSource(filename, code);
return compiled; return next("coffee-internal://" + filename, result, SourceMap.chain(map, prevMap));
}; };
} }

View File

@ -1,4 +1,4 @@
type Location = readonly [file: string, line: number, start: number]; type Location = [file: string, line: number, start: number];
type SourceMap = (loc: Location) => Location | undefined; type SourceMap = (loc: Location) => Location | undefined;
type CompilerFactory = (next: Compiler) => Compiler; type CompilerFactory = (next: Compiler) => Compiler;

View File

@ -106,8 +106,8 @@ export default function typescript(next: Compiler): Compiler {
const result = outputs["/src.js"]; const result = outputs["/src.js"];
const declaration = outputs["/src.d.ts"]; const declaration = outputs["/src.d.ts"];
const compiled = next("ts-internal://" + filename, result, SourceMap.chain(map, prevMap));
registerSource(filename, code); registerSource(filename, code);
const compiled = next("ts-internal://" + filename, result, SourceMap.chain(map, prevMap));
return function (this: any) { return function (this: any) {
const res = compiled.apply(this, arguments); const res = compiled.apply(this, arguments);

View File

@ -21,7 +21,9 @@ public class ForInNode extends Node {
@Override public void resolve(CompileResult target) { @Override public void resolve(CompileResult target) {
body.resolve(target); body.resolve(target);
binding.resolve(target); if (isDecl) {
target.scope.define(binding.name);
}
} }
@Override public void compileFunctions(CompileResult target) { @Override public void compileFunctions(CompileResult target) {

View File

@ -409,7 +409,43 @@ public class SimpleDebugger implements Debugger {
res.set("description", className); res.set("description", className);
} }
if (val instanceof ArrayValue arr) res.set("description", "Array(" + arr.size() + ")"); if (val instanceof ArrayValue arr) {
var desc = new StringBuilder("Array(" + arr.size() + ")");
if (arr.size() > 0) {
desc.append("[");
for (var i = 0; i < arr.size(); i++) {
if (i != 0) desc.append(", ");
if (desc.length() > 120) {
desc.append("...");
break;
}
if (arr.has(i)) {
try {
var curr = arr.get(i);
if (curr instanceof StringValue str) {
desc.append(JSON.stringify(JSONElement.string(str.value)));
}
else {
desc.append(arr.get(i).toString(env));
}
}
catch (EngineException e) {
desc.append("<error>");
}
}
else {
desc.append("<empty>");
}
}
desc.append("]");
}
res.set("description", desc.toString());
}
else if (val instanceof FunctionValue) res.set("description", val.toString()); else if (val instanceof FunctionValue) res.set("description", val.toString());
else { else {
var defaultToString = false; var defaultToString = false;