From 5c6646ced9f6f3aec12364e5dfcc385d943f3b06 Mon Sep 17 00:00:00 2001 From: xiangnan <280145668@qq.com> Date: Thu, 26 Sep 2024 17:06:35 +0800 Subject: [PATCH] transform$ --- package-lock.json | 4 ++-- package.json | 4 ++-- src/js2lua.mjs | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0f7c099..8276688 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@xiangnanscu/js2lua", - "version": "0.34.0", + "version": "0.36.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@xiangnanscu/js2lua", - "version": "0.34.0", + "version": "0.36.0", "license": "MIT", "dependencies": { "@babel/parser": "^7.22.14", diff --git a/package.json b/package.json index 15b5a0b..e82389b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xiangnanscu/js2lua", - "version": "0.35.0", + "version": "0.36.0", "type": "module", "description": "Writing LuaJIT with the expressiveness of JavaScript.", "main": "src/js2lua.mjs", @@ -55,4 +55,4 @@ "vite-plugin-require-transform": "^1.0.21", "vue-eslint-parser": "^9.3.1" } -} \ No newline at end of file +} diff --git a/src/js2lua.mjs b/src/js2lua.mjs index 54c3cb5..5e37473 100644 --- a/src/js2lua.mjs +++ b/src/js2lua.mjs @@ -11,6 +11,7 @@ const defaultOptions = { debug: false, tagArrayExpression: true, importStatementHoisting: true, + transform$SymbolToDollar: true, transformToString: true, transformString: true, transformJSONStringify: true, @@ -475,6 +476,8 @@ function ast2lua(ast, opts = {}) { const id = ast.name; if (id == "undefined") { return "nil"; + } else if (id.startsWith("$")) { + return opts.transform$SymbolToDollar ? id.replace("$", "_DOLLAR_") : id; } return id; }