Compare commits

..

12 Commits

15 changed files with 63 additions and 25 deletions

View File

@@ -7,7 +7,7 @@ const nodeResolve = require("@rollup/plugin-node-resolve");
const json = require("@rollup/plugin-json");
const { resolve } = require("path");
const shouldMinify = () => false;
const shouldMinify = () => true;
const shouldEmitSourcemaps = () => true;
const shouldPolyfill = () => !!process.env.POLYFILLS;
@@ -99,6 +99,7 @@ const construct = (input, output) => defineConfig({
shouldMinify() && terser({
sourceMap: shouldEmitSourcemaps(),
keep_classnames: true,
keep_fnames: true,
}),
],
output: {

View File

@@ -112,7 +112,8 @@ export interface Primordials {
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 primordials: Primordials = (globalThis as any).primordials;

View File

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

View File

@@ -82,13 +82,13 @@ export const Object = (() => {
res.s = set;
}
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));
}
else {
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 ("value" in desc) res.v = desc.value;

View File

@@ -41,8 +41,9 @@ export const String = (() => {
offset = +offset;
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");
if (offset == null) offset = self.length;
offset = +offset;
return string.indexOf(self, search, offset, true);
}

View File

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

View File

@@ -11,17 +11,14 @@ export default function babel(next: Compiler): Compiler {
presets: [availablePresets.env],
});
print(res.map!.mappings);
const map = SourceMap.parse({
file: "babel-internal://" + filename,
mappings: res.map!.mappings,
sources: [filename],
});
const compiled = next("babel-internal://" + filename, res.code!, SourceMap.chain(map, prevMap));
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],
});
const compiled = next("coffee-internal://" + filename, result, SourceMap.chain(map, prevMap));
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 CompilerFactory = (next: Compiler) => Compiler;

View File

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

View File

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

View File

@@ -409,7 +409,43 @@ public class SimpleDebugger implements Debugger {
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 {
var defaultToString = false;

View File

@@ -40,7 +40,7 @@ public final class Engine implements EventLoop {
try {
((Task<Object>)task).notifier.complete(task.runnable.get());
}
catch (CancellationException e) { throw e; }
catch (CancellationException e) { task.notifier.cancel(false); throw e; }
catch (RuntimeException e) { task.notifier.completeExceptionally(e); }
}
catch (InterruptedException | CancellationException e) {

View File

@@ -213,7 +213,9 @@ public final class Frame {
catch (StackOverflowError e) { throw STACK_OVERFLOW; }
catch (EngineException e) { error = e; }
catch (RuntimeException e) {
System.out.println(dbg.getMapOrEmpty(function).toLocation(codePtr, true));
if (!(e instanceof CancellationException)) {
System.out.println(dbg.getMapOrEmpty(function).toLocation(codePtr, true));
}
throw e;
}
}

View File

@@ -17,6 +17,8 @@
/// <reference path="./globals/weak-map.d.ts"/>
declare function print(...args: any[]): void;
declare function exit(): never;
declare function measure(func: () => void): void;
declare type IArguments = Array<any>;