Compare commits

..

No commits in common. "31e2e95bc8b00860d7665b4618c663d8c13b1b01" and "4ea14ca1f5be127a3fd48098ad4f063defe8b869" have entirely different histories.

11 changed files with 22 additions and 55 deletions

View File

@ -112,8 +112,7 @@ export interface Primordials {
schedule(func: () => void, delay: number): () => void; schedule(func: () => void, delay: number): () => void;
} }
// prevent optimization to "undefined", which doesn't exist yet globalThis.undefined = void 0;
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 this.length; return arguments.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 this.length; return arguments.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.c = !!desc.configurable; if ("configurable" in desc) res.e = !!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.c = !!desc.configurable; if ("configurable" in desc) res.e = !!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,9 +41,8 @@ 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?: number) { public lastIndexOf(search: string, offset = 0) {
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,4 +1,7 @@
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,14 +11,17 @@ 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 next("babel-internal://" + filename, res.code!, SourceMap.chain(map, prevMap)); return compiled;
}; };
} }

View File

@ -20,8 +20,9 @@ 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 next("coffee-internal://" + filename, result, SourceMap.chain(map, prevMap)); return compiled;
}; };
} }

View File

@ -1,4 +1,4 @@
type Location = [file: string, line: number, start: number]; type Location = readonly [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"];
registerSource(filename, code);
const compiled = next("ts-internal://" + filename, result, SourceMap.chain(map, prevMap)); const compiled = next("ts-internal://" + filename, result, SourceMap.chain(map, prevMap));
registerSource(filename, code);
return function (this: any) { return function (this: any) {
const res = compiled.apply(this, arguments); const res = compiled.apply(this, arguments);

View File

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

View File

@ -409,43 +409,7 @@ public class SimpleDebugger implements Debugger {
res.set("description", className); res.set("description", className);
} }
if (val instanceof ArrayValue arr) { if (val instanceof ArrayValue arr) res.set("description", "Array(" + arr.size() + ")");
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;