From bceba988cbeb3b0e8fad7ec24b34dea0755993b4 Mon Sep 17 00:00:00 2001 From: unc0 Date: Thu, 20 Mar 2014 19:31:04 +0800 Subject: [PATCH 1/3] Add sourcemap generator into compile procedure. Now you can have original source position in stack trace. --- lib/gorilla.js | 107 +++++++++++++++++++++++++++++++++++++++++++--- lib/source-map.js | 3 ++ src/gorilla.gs | 67 ++++++++++++++++++++++++++++- src/source-map.gs | 2 +- 4 files changed, 172 insertions(+), 7 deletions(-) diff --git a/lib/gorilla.js b/lib/gorilla.js index 3466c9a..c5d167d 100644 --- a/lib/gorilla.js +++ b/lib/gorilla.js @@ -1,10 +1,11 @@ (function (GLOBAL) { "use strict"; - var __defer, __everyPromise, __generatorToPromise, __import, __isArray, __lte, - __num, __owns, __promise, __promiseLoop, __slice, __strnum, __toArray, - __toPromise, __typeof, _ref, ast, fetchAndParsePreludeMacros, fs, init, - isAcceptableIdent, os, parser, path, real__filename, setImmediate, - SourceMap, writeFileWithMkdirp, writeFileWithMkdirpSync; + var __defer, __everyPromise, __generatorToPromise, __import, __is, __isArray, + __lte, __num, __owns, __promise, __promiseLoop, __slice, __strnum, + __toArray, __toPromise, __typeof, _ref, ast, fetchAndParsePreludeMacros, + fs, init, isAcceptableIdent, os, parser, path, real__filename, + setImmediate, SourceMap, SourceMapConsumer, writeFileWithMkdirp, + writeFileWithMkdirpSync; __defer = (function () { function __defer() { var deferred, isError, value; @@ -212,6 +213,14 @@ } return dest; }; + __is = typeof Object.is === "function" ? Object.is + : function (x, y) { + if (x === y) { + return x !== 0 || 1 / x === 1 / y; + } else { + return x !== x && y !== y; + } + }; __isArray = typeof Array.isArray === "function" ? Array.isArray : (function (_toString) { return function (x) { @@ -414,6 +423,7 @@ fs = require("fs"); path = require("path"); SourceMap = require("./source-map"); + SourceMapConsumer = require("source-map").SourceMapConsumer; _ref = require("./utils"); writeFileWithMkdirp = _ref.writeFileWithMkdirp; writeFileWithMkdirpSync = _ref.writeFileWithMkdirpSync; @@ -1045,6 +1055,9 @@ } sync = options.sync; startTime = new Date().getTime(); + if (options.filename) { + options.sourceMap = SourceMap(options.filename, null, ""); + } _state = sync ? 1 : 2; break; case 1: @@ -1524,6 +1537,88 @@ } return exports["eval"].sync(source, (_ref = __import({}, options), _ref.sync = true, _ref)); }; + function patchStackTrace(options) { + if (options.stackTracePatched) { + return; + } + options.stackTracePatched = true; + return Error.prepareStackTrace = function (err, stack) { + var _arr, _arr2, _i, _len, frame, frames; + function getSourceMapping(pos) { + var mapping; + mapping = new SourceMapConsumer(options.sourceMap.toString()); + return mapping.originalPositionFor(pos); + } + function formatSourcePosition(frame) { + var asLine, column, fileLocation, fileName, functionName, isConstructor, + isMethodCall, line, methodName, source, tp, typeName; + fileLocation = ""; + if (frame.isNative()) { + return fileLocation = "native"; + } else { + if (frame.isEval()) { + fileName = frame.getScriptNameOrSourceURL(); + if (!fileName) { + fileLocation = __strnum(frame.getEvalOrigin()) + ", "; + } + } else { + fileName = frame.getFileName(); + } + if (!fileName) { + fileName = ""; + } + line = frame.getLineNumber(); + column = frame.getColumnNumber(); + source = getSourceMapping({ line: line, column: column }); + if (__num(fileName.indexOf(".js")) < 1) { + if (source.line != null) { + fileLocation = __strnum(fileName) + ":" + __strnum(source.line) + ":" + __strnum(source.column) + ", :" + __strnum(line) + ":" + __strnum(column); + } else { + fileLocation = __strnum(fileName) + " :" + __strnum(line) + ":" + __strnum(column); + } + } else { + fileLocation = __strnum(fileName) + ":" + __strnum(line) + ":" + __strnum(column); + } + functionName = frame.getFunctionName(); + isConstructor = frame.isConstructor(); + isMethodCall = !frame.isToplevel() && !isConstructor; + if (isMethodCall) { + methodName = frame.getMethodName(); + typeName = frame.getTypeName(); + if (functionName) { + tp = ""; + asLine = ""; + if (typeName && functionName.indexOf(typeName)) { + tp = __strnum(typeName) + "."; + } + if (methodName && !__is(functionName.indexOf("." + __strnum(methodName)), __num(functionName.length) - __num(methodName.length) - 1)) { + asLine = " [as " + __strnum(methodName) + "]"; + } + return tp + __strnum(functionName) + asLine + " (" + fileLocation + ")"; + } else { + return __strnum(typeName) + "." + __strnum(methodName || "") + " (" + fileLocation + ")"; + } + } else if (isConstructor) { + return "new " + __strnum(functionName || "") + " (" + fileLocation + ")"; + } else if (functionName) { + return __strnum(functionName) + " (" + fileLocation + ")"; + } else { + return fileLocation; + } + } + } + _arr = []; + for (_arr2 = __toArray(stack), _i = 0, _len = _arr2.length; _i < _len; ++_i) { + frame = _arr2[_i]; + if (__is(frame.getFunction(), exports.run)) { + break; + } + _arr.push(" at " + __strnum(formatSourcePosition(frame))); + } + frames = _arr; + return err.toString() + "\n" + frames.join("\n") + "\n"; + }; + } exports.run = __promise(function (source, options) { var _e, _send, _state, _step, _throw, compiled, mainModule, Module, sync; _state = 0; @@ -1537,6 +1632,7 @@ if (options == null) { options = {}; } + options.stackTracePatched = false; sync = options.sync; _state = typeof process === "undefined" ? 1 : 5; break; @@ -1587,6 +1683,7 @@ compiled = _received; ++_state; case 10: + patchStackTrace(options); _state = 12; return { done: true, diff --git a/lib/source-map.js b/lib/source-map.js index 6e973fa..e1fd438 100644 --- a/lib/source-map.js +++ b/lib/source-map.js @@ -15,6 +15,9 @@ var _this; _this = this instanceof SourceMap ? this : __create(_SourceMap_prototype); _this.sourceMapFile = sourceMapFile; + if (generatedFile == null) { + generatedFile = "temp"; + } _this.generatedFile = generatedFile; _this.generator = new (sourceMap.SourceMapGenerator)({ file: path.relative(path.dirname(sourceMapFile), generatedFile), diff --git a/src/gorilla.gs b/src/gorilla.gs index 82ffe3c..e1ae884 100644 --- a/src/gorilla.gs +++ b/src/gorilla.gs @@ -9,6 +9,7 @@ require! os require! fs require! path require! SourceMap: './source-map' +let {SourceMapConsumer} = require 'source-map' let {write-file-with-mkdirp, write-file-with-mkdirp-sync} = require('./utils') let {is-acceptable-ident} = require './jsutils' @@ -233,6 +234,8 @@ exports.ast-sync := #(source, options = {}) exports.compile := promise! #(source, options = {})* let sync = options.sync let start-time = new Date().get-time() + if options.filename + options.source-map := SourceMap(options.filename, null, "") let translated = if sync exports.ast-sync source, options else @@ -389,7 +392,68 @@ exports.eval := promise! #(source, options = {})* exports.eval-sync := #(source, options = {}) exports.eval.sync source, {} <<< options <<< {+sync} +let patch-stack-trace(options) + if options.stack-trace-patched + return + options.stack-trace-patched := true + Error.prepare-stack-trace := #(err, stack) + let get-source-mapping = #(pos) + let mapping = new SourceMapConsumer options.source-map.to-string() + mapping.original-position-for pos + let format-source-position = #(frame) + let mutable file-name = undefined + let mutable file-location = '' + if frame.is-native() + file-location := 'native' + else + if frame.is-eval() + file-name := frame.get-script-name-or-sourceURL() + unless file-name + file-location := "$(frame.get-eval-origin()), " + else + file-name := frame.get-file-name() + file-name or= "" + let line = frame.get-line-number() + let column = frame.get-column-number() + let source = get-source-mapping {line, column} + if file-name.index-of('.js') < 1 + if source.line? + file-location := "$file-name:$(source.line):$(source.column), :$line:$column" + else + file-location := "$file-name :$line:$column" + else + file-location := "$file-name:$line:$column" + let function-name = frame.get-function-name() + let is-constructor = frame.is-constructor() + let is-method-call = not (frame.is-toplevel() or is-constructor) + if is-method-call + let method-name = frame.get-method-name() + let type-name = frame.get-type-name() + if function-name + let mutable tp = '' + let mutable as-line = '' + if type-name and function-name.index-of type-name + tp := "$(type-name)." + if method-name and function-name.index-of(".$(method-name)") isnt function-name.length - method-name.length - 1 + as-line := " [as $method-name]" + return "$(tp)$(function-name)$(as-line) ($file-location)" + else + return "$(type-name).$(method-name or '') ($file-location)" + else if is-constructor + return "new $(function-name or '') ($file-location)" + else if function-name + return "$function-name ($file-location)" + else + return file-location + + let frames = for frame in stack + if frame.get-function() is exports.run + break + " at $(format-source-position frame)" + "$(err.to-string())\n$(frames.join '\n')\n" + exports.run := promise! #(source, options = {})* + options.stack-trace-patched := false let sync = options.sync if is-void! process return if sync @@ -410,6 +474,7 @@ exports.run := promise! #(source, options = {})* exports.compile-sync source, options else yield exports.compile source, options + patch-stack-trace options main-module._compile compiled.code, main-module.filename else main-module._compile source, main-module.filename @@ -444,4 +509,4 @@ exports.get-mtime := promise! #(source)* acc max stat.mtime.get-time() return new Date(time) -exports.AST := ast \ No newline at end of file +exports.AST := ast diff --git a/src/source-map.gs b/src/source-map.gs index 42ad38e..4cb578f 100644 --- a/src/source-map.gs +++ b/src/source-map.gs @@ -4,7 +4,7 @@ require! source-map: "source-map" require! path module.exports := class SourceMap - def constructor(@source-map-file, @generated-file, source-root) + def constructor(@source-map-file, @generated-file = 'temp', source-root) @generator := new source-map.SourceMapGenerator { file: path.relative path.dirname(source-map-file), generated-file source-root From 252250b30ff6297ff65309d9ba8901fdf7a41ae3 Mon Sep 17 00:00:00 2001 From: unc0 Date: Thu, 15 Jan 2015 10:31:38 +0800 Subject: [PATCH 2/3] merge kkirby patch --- extras/gorillascript.js | 153 +++++++++++++++++++++++++++++++++++----- src/jsprelude.gs | 16 ++--- 2 files changed, 145 insertions(+), 24 deletions(-) diff --git a/extras/gorillascript.js b/extras/gorillascript.js index c20dd19..754fb21 100644 --- a/extras/gorillascript.js +++ b/extras/gorillascript.js @@ -30145,11 +30145,12 @@ var exports = this; (function (GLOBAL) { "use strict"; - var __defer, __everyPromise, __generatorToPromise, __import, __isArray, __lte, - __num, __owns, __promise, __promiseLoop, __slice, __strnum, __toArray, - __toPromise, __typeof, _ref, ast, fetchAndParsePreludeMacros, fs, init, - isAcceptableIdent, os, parser, path, real__filename, setImmediate, - SourceMap, writeFileWithMkdirp, writeFileWithMkdirpSync; + var __defer, __everyPromise, __generatorToPromise, __import, __is, __isArray, + __lte, __num, __owns, __promise, __promiseLoop, __slice, __strnum, + __toArray, __toPromise, __typeof, _ref, ast, fetchAndParsePreludeMacros, + fs, init, isAcceptableIdent, os, parser, path, real__filename, + setImmediate, SourceMap, SourceMapConsumer, writeFileWithMkdirp, + writeFileWithMkdirpSync; __defer = (function () { function __defer() { var deferred, isError, value; @@ -30357,6 +30358,14 @@ } return dest; }; + __is = typeof Object.is === "function" ? Object.is + : function (x, y) { + if (x === y) { + return x !== 0 || 1 / x === 1 / y; + } else { + return x !== x && y !== y; + } + }; __isArray = typeof Array.isArray === "function" ? Array.isArray : (function (_toString) { return function (x) { @@ -30559,6 +30568,7 @@ fs = require("fs"); path = require("path"); SourceMap = require("./source-map"); + SourceMapConsumer = require("source-map").SourceMapConsumer; _ref = require("./utils"); writeFileWithMkdirp = _ref.writeFileWithMkdirp; writeFileWithMkdirpSync = _ref.writeFileWithMkdirpSync; @@ -31190,6 +31200,9 @@ } sync = options.sync; startTime = new Date().getTime(); + if (options.filename) { + options.sourceMap = SourceMap(options.filename, null, ""); + } _state = sync ? 1 : 2; break; case 1: @@ -31669,6 +31682,88 @@ } return exports["eval"].sync(source, (_ref = __import({}, options), _ref.sync = true, _ref)); }; + function patchStackTrace(options) { + if (options.stackTracePatched) { + return; + } + options.stackTracePatched = true; + return Error.prepareStackTrace = function (err, stack) { + var _arr, _arr2, _i, _len, frame, frames; + function getSourceMapping(pos) { + var mapping; + mapping = new SourceMapConsumer(options.sourceMap.toString()); + return mapping.originalPositionFor(pos); + } + function formatSourcePosition(frame) { + var asLine, column, fileLocation, fileName, functionName, isConstructor, + isMethodCall, line, methodName, source, tp, typeName; + fileLocation = ""; + if (frame.isNative()) { + return fileLocation = "native"; + } else { + if (frame.isEval()) { + fileName = frame.getScriptNameOrSourceURL(); + if (!fileName) { + fileLocation = __strnum(frame.getEvalOrigin()) + ", "; + } + } else { + fileName = frame.getFileName(); + } + if (!fileName) { + fileName = ""; + } + line = frame.getLineNumber(); + column = frame.getColumnNumber(); + source = getSourceMapping({ line: line, column: column }); + if (__num(fileName.indexOf(".js")) < 1) { + if (source.line != null) { + fileLocation = __strnum(fileName) + ":" + __strnum(source.line) + ":" + __strnum(source.column) + ", :" + __strnum(line) + ":" + __strnum(column); + } else { + fileLocation = __strnum(fileName) + " :" + __strnum(line) + ":" + __strnum(column); + } + } else { + fileLocation = __strnum(fileName) + ":" + __strnum(line) + ":" + __strnum(column); + } + functionName = frame.getFunctionName(); + isConstructor = frame.isConstructor(); + isMethodCall = !frame.isToplevel() && !isConstructor; + if (isMethodCall) { + methodName = frame.getMethodName(); + typeName = frame.getTypeName(); + if (functionName) { + tp = ""; + asLine = ""; + if (typeName && functionName.indexOf(typeName)) { + tp = __strnum(typeName) + "."; + } + if (methodName && !__is(functionName.indexOf("." + __strnum(methodName)), __num(functionName.length) - __num(methodName.length) - 1)) { + asLine = " [as " + __strnum(methodName) + "]"; + } + return tp + __strnum(functionName) + asLine + " (" + fileLocation + ")"; + } else { + return __strnum(typeName) + "." + __strnum(methodName || "") + " (" + fileLocation + ")"; + } + } else if (isConstructor) { + return "new " + __strnum(functionName || "") + " (" + fileLocation + ")"; + } else if (functionName) { + return __strnum(functionName) + " (" + fileLocation + ")"; + } else { + return fileLocation; + } + } + } + _arr = []; + for (_arr2 = __toArray(stack), _i = 0, _len = _arr2.length; _i < _len; ++_i) { + frame = _arr2[_i]; + if (__is(frame.getFunction(), exports.run)) { + break; + } + _arr.push(" at " + __strnum(formatSourcePosition(frame))); + } + frames = _arr; + return err.toString() + "\n" + frames.join("\n") + "\n"; + }; + } exports.run = __promise(function (source, options) { var _e, _send, _state, _step, _throw, compiled, mainModule, Module, sync; _state = 0; @@ -31682,6 +31777,7 @@ if (options == null) { options = {}; } + options.stackTracePatched = false; sync = options.sync; _state = typeof process === "undefined" ? 1 : 5; break; @@ -31732,6 +31828,7 @@ compiled = _received; ++_state; case 10: + patchStackTrace(options); _state = 12; return { done: true, @@ -35824,11 +35921,11 @@ AST$( 17, 1854, - 14, + 18, 0, "WeakMap" ), - 0 + 1 ) ), AST$( @@ -36244,11 +36341,11 @@ AST$( 17, 1864, - 1, + 14, 0, "WeakMap" ), - 0 + 1 ) ) ), @@ -36412,7 +36509,7 @@ ) ) ), - type: TYPE$["function"], + type: TYPE$.generic(TYPE$.functionBase, TYPE$.notUndefinedOrNull), dependencies: ["__toArray", "WeakMap"] }, __range: { @@ -76848,7 +76945,11 @@ node = this.macroExpand1(node); if (node.isInternalCall("array")) { if (node.args.length === 0) { - return __call(void 0, __symbol(void 0, "ident", "Set")); + return __call( + void 0, + __symbol(void 0, "internal", "new"), + __symbol(void 0, "ident", "Set") + ); } else { parts = []; tmp = this.tmp("x"); @@ -76936,7 +77037,11 @@ false, false ), - value: __call(void 0, __symbol(void 0, "ident", "Set")) + value: __call( + void 0, + __symbol(void 0, "internal", "new"), + __symbol(void 0, "ident", "Set") + ) } }, true, @@ -76979,7 +77084,11 @@ false, false ), - value: __call(void 0, __symbol(void 0, "ident", "Set")) + value: __call( + void 0, + __symbol(void 0, "internal", "new"), + __symbol(void 0, "ident", "Set") + ) } }, true, @@ -77083,7 +77192,11 @@ if (node.isInternalCall("object")) { pairs = node.args; if (pairs.length === 0) { - return __call(void 0, __symbol(void 0, "ident", "Map")); + return __call( + void 0, + __symbol(void 0, "internal", "new"), + __symbol(void 0, "ident", "Map") + ); } else { parts = []; for (_arr = __toArray(pairs), _i = 1, _len = _arr.length; _i < _len; ++_i) { @@ -77135,7 +77248,11 @@ false, false ), - value: __call(void 0, __symbol(void 0, "ident", "Map")) + value: __call( + void 0, + __symbol(void 0, "internal", "new"), + __symbol(void 0, "ident", "Map") + ) } }, true, @@ -77179,7 +77296,11 @@ false, false ), - value: __call(void 0, __symbol(void 0, "ident", "Map")) + value: __call( + void 0, + __symbol(void 0, "internal", "new"), + __symbol(void 0, "ident", "Map") + ) } }, true, diff --git a/src/jsprelude.gs b/src/jsprelude.gs index 3e0e08f..6baa25e 100644 --- a/src/jsprelude.gs +++ b/src/jsprelude.gs @@ -1851,7 +1851,7 @@ macro for $current macro helper __generic-func = #(num-args as Number, make as ->) - let cache = WeakMap() + let cache = new WeakMap() let any = {} let generic = # for reduce i in num-args - 1 to 0 by -1, current = cache @@ -1861,7 +1861,7 @@ macro helper __generic-func = #(num-args as Number, make as ->) item := if i == 0 make@ this, ...arguments else - WeakMap() + new WeakMap() current.set type, item item let result = generic() @@ -3726,7 +3726,7 @@ macro operator unary set! with type: \object, label: \construct-set node := @macro-expand-1 node if node.is-internal-call \array if node.args.length == 0 - ASTE Set() + ASTE new Set() else let parts = [] let tmp = @tmp \x @@ -3737,13 +3737,13 @@ macro operator unary set! with type: \object, label: \construct-set else parts.push AST(el) $set.add $el AST - let $set = Set() + let $set = new Set() $parts $set else let item = @tmp \x AST - let $set as Set = Set() + let $set as Set = new Set() for $item in $node $set.add $item $set @@ -3755,7 +3755,7 @@ macro operator unary map! with type: \object, label: \construct-map if node.is-internal-call \object let pairs = node.args if pairs.length == 0 - ASTE Map() + ASTE new Map() else let parts = [] for pair in pairs[1 to -1] @@ -3763,14 +3763,14 @@ macro operator unary map! with type: \object, label: \construct-map @error "Cannot use map! on an object with custom properties", pair parts.push AST(pair) $map.set $(pair.args[0]), $(pair.args[1]) AST - let $map as Map = Map() + let $map as Map = new Map() $parts $map else let key = @tmp \k let value = @tmp \v AST - let $map as Map = Map() + let $map as Map = new Map() for $key, $value of $node $map.set $key, $value $map From dfd6ba06d48a861f6ae44ebc3b07160859d00b3f Mon Sep 17 00:00:00 2001 From: unc0 Date: Thu, 15 Jan 2015 10:55:07 +0800 Subject: [PATCH 3/3] Support io.js --- bin/gorilla | 2 +- extras/gorillascript.js | 6 +++--- lib/jstranslator.js | 4 ++-- lib/utils.js | 2 +- src/jstranslator.gs | 6 +++--- src/parser.gs | 2 +- src/utils.gs | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bin/gorilla b/bin/gorilla index 976e951..9aab7aa 100755 --- a/bin/gorilla +++ b/bin/gorilla @@ -8,4 +8,4 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" -node --harmony_collections "$DIR/../lib/command" "$@" +node --harmony "$DIR/../lib/command" "$@" diff --git a/extras/gorillascript.js b/extras/gorillascript.js index 754fb21..e734aae 100644 --- a/extras/gorillascript.js +++ b/extras/gorillascript.js @@ -446,7 +446,7 @@ function Cache() { var _this; _this = this instanceof Cache ? this : __create(_Cache_prototype); - _this.weakmap = WeakMap(); + _this.weakmap = new WeakMap(); return _this; } _Cache_prototype = Cache.prototype; @@ -26584,7 +26584,7 @@ _this.scope = scope; _this.hasGeneratorNode = hasGeneratorNode; _this.currentCatch = []; - _this.redirects = Map(); + _this.redirects = new Map(); _this.start = GeneratorState(_this); _this.stop = GeneratorState(_this).add(function () { return ast.Return(pos, ast.Obj(pos, [ @@ -26634,7 +26634,7 @@ _GeneratorBuilder_prototype._calculateCaseIds = function () { var _arr, _i, _len, caseIds, id, state; id = -1; - caseIds = this.caseIds = Map(); + caseIds = this.caseIds = new Map(); for (_arr = __toArray(this.statesOrder), _i = 0, _len = _arr.length; _i < _len; ++_i) { state = _arr[_i]; if (!this.redirects.has(state)) { diff --git a/lib/jstranslator.js b/lib/jstranslator.js index ea12558..990ba8b 100644 --- a/lib/jstranslator.js +++ b/lib/jstranslator.js @@ -1076,7 +1076,7 @@ _this.scope = scope; _this.hasGeneratorNode = hasGeneratorNode; _this.currentCatch = []; - _this.redirects = Map(); + _this.redirects = new Map(); _this.start = GeneratorState(_this); _this.stop = GeneratorState(_this).add(function () { return ast.Return(pos, ast.Obj(pos, [ @@ -1126,7 +1126,7 @@ _GeneratorBuilder_prototype._calculateCaseIds = function () { var _arr, _i, _len, caseIds, id, state; id = -1; - caseIds = this.caseIds = Map(); + caseIds = this.caseIds = new Map(); for (_arr = __toArray(this.statesOrder), _i = 0, _len = _arr.length; _i < _len; ++_i) { state = _arr[_i]; if (!this.redirects.has(state)) { diff --git a/lib/utils.js b/lib/utils.js index a813630..7d4237f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -427,7 +427,7 @@ function Cache() { var _this; _this = this instanceof Cache ? this : __create(_Cache_prototype); - _this.weakmap = WeakMap(); + _this.weakmap = new WeakMap(); return _this; } _Cache_prototype = Cache.prototype; diff --git a/src/jstranslator.gs b/src/jstranslator.gs index 802e780..916ec18 100644 --- a/src/jstranslator.gs +++ b/src/jstranslator.gs @@ -379,7 +379,7 @@ class GeneratorState class GeneratorBuilder def constructor(@pos as {}, @scope as Scope, @has-generator-node as ->) @current-catch := [] - @redirects := Map() + @redirects := new Map() @start := GeneratorState(this) @stop := GeneratorState(this).add #-> ast.Return pos, ast.Obj pos, [ ast.Obj.Pair pos, \done, ast.Const pos, true @@ -418,7 +418,7 @@ class GeneratorBuilder def _calculate-case-ids()! let mutable id = -1 - let case-ids = @case-ids := Map() + let case-ids = @case-ids := new Map() for state in @states-order if not @redirects.has state case-ids.set state, (id += 1) @@ -2377,4 +2377,4 @@ module.exports.define-helper := #(macros as MacroHolder, get-position as ->, nam helper dependencies } - \ No newline at end of file + diff --git a/src/parser.gs b/src/parser.gs index a1cc759..c44805b 100644 --- a/src/parser.gs +++ b/src/parser.gs @@ -100,7 +100,7 @@ class Box if index not %% 1 or index < 0 throw RangeError "Expected index to be a non-negative integer, got $index" -let unused-caches = if DEBUG then Map() +let unused-caches = if DEBUG then new Map() let cache = do let mutable id = -1 diff --git a/src/utils.gs b/src/utils.gs index 0e12413..c6b1a27 100644 --- a/src/utils.gs +++ b/src/utils.gs @@ -21,7 +21,7 @@ let pad-right(text, len, padding) class Cache def constructor() - @weakmap := WeakMap() + @weakmap := new WeakMap() def get(key as TKey) -> @weakmap.get(key)