Skip to content

Commit 0575556

Browse files
committed
fix chain call like a.b.c(). Close #2
1 parent 5c6646c commit 0575556

6 files changed

+42
-21
lines changed

README.md

+6-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ where options are:
1515
```js
1616
const defaultOptions = {
1717
debug: false,
18+
tagArrayExpression: true,
1819
importStatementHoisting: true,
20+
transform$SymbolToDollar: true,
1921
transformToString: true,
2022
transformString: true,
2123
transformJSONStringify: true,
@@ -53,6 +55,7 @@ js2lua(`let a = 1`, {importStatementHoisting:true})
5355
```
5456
## see also
5557
[lua2js](https://xiangnanscu.github.io/lua2js/) transform lua to js
58+
[lua-resty-array](https://github.com/xiangnanscu/lua-resty-array) lua version of JS Array (feature tagArrayExpression)
5659

5760
# Features
5861
* [assignment](#assignment)
@@ -265,15 +268,9 @@ Position:echoInsCount()
265268
p1:echoPosition()
266269
p2:echoPosition()
267270
p1:say("hello")
268-
(function()
269-
local __tmp = p1.say
270-
return __tmp(p2)
271-
end)()
271+
p1.say(p2)
272272
p1:echoNumbersLength("a", "b", "c")
273-
(function()
274-
local __tmp = p1.echoNumbersLength
275-
return __tmp(p2, unpack(array {1, 2}))
276-
end)()
273+
p1.echoNumbersLength(p2, unpack(array {1, 2}))
277274

278275
```
279276
## export
@@ -1109,10 +1106,7 @@ local cjson = require("cjson")
11091106

11101107
local a = {b = ""}
11111108
tostring(1)
1112-
(function()
1113-
local __tmp = a.b
1114-
return tostring(__tmp)
1115-
end)()
1109+
tostring(a.b)
11161110
cjson.encode({})
11171111
cjson.decode("{}")
11181112
tonumber("2")

README.template.md

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
# js2lua
2+
23
[js2lua](https://xiangnanscu.github.io/js2lua/)
34
Writing LuaJIT with the expressiveness of JavaScript.
5+
46
# Install
7+
58
```sh
69
npm install -g @xiangnanscu/js2lua
710
```
11+
812
# Usage
13+
914
## command
15+
1016
Concat one or more js files and transform them to one lua string:
17+
1118
```sh
1219
js2lua [options] file1, file2, ...
1320
```
21+
1422
where options are:
23+
1524
```js
1625
const defaultOptions = {
17-
debug: false,
26+
tagArrayExpression: true,
1827
importStatementHoisting: true,
28+
transform$SymbolToDollar: true,
1929
transformToString: true,
2030
transformString: true,
2131
transformJSONStringify: true,
@@ -33,26 +43,40 @@ const defaultOptions = {
3343
disableClassCall: true,
3444
};
3545
```
46+
3647
### examples
48+
3749
Basic:
50+
3851
```sh
3952
js2lua foo.js > foo.lua
4053
```
54+
4155
To disable a feature `--no-[option]`:
56+
4257
```sh
4358
js2lua --no-transformToString foo.js
4459
```
60+
4561
To enable a feature `--[option]`:
62+
4663
```sh
4764
js2lua --debug foo.js
4865
```
66+
4967
## api
68+
5069
```js
51-
import { js2lua } from 'js2lua';
52-
js2lua(`let a = 1`, {importStatementHoisting:true})
70+
import { js2lua } from "js2lua";
71+
js2lua(`let a = 1`, { importStatementHoisting: true });
5372
```
73+
5474
## see also
55-
[lua2js](https://xiangnanscu.github.io/lua2js/) transform lua to js
75+
76+
- [lua2js](https://xiangnanscu.github.io/lua2js/) transform lua to js
77+
78+
- [lua-resty-array](https://github.com/xiangnanscu/lua-resty-array) lua version of JS Array (feature tagArrayExpression)
5679

5780
# Features
58-
[CODE_TABLE]
81+
82+
[CODE_TABLE]

makeDocs.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const folderPath = './test';
77
const markdown = fs.readFileSync('./README.template.md', 'utf8');
88
const files = fs.readdirSync(folderPath);
99
const opts = {
10+
tagArrayExpression: true,
1011
importStatementHoisting: true,
12+
transform$SymbolToDollar: true,
1113
transformToString: true,
1214
transformString: true,
1315
transformJSONStringify: true,

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@xiangnanscu/js2lua",
3-
"version": "0.36.0",
3+
"version": "0.37.0",
44
"type": "module",
55
"description": "Writing LuaJIT with the expressiveness of JavaScript.",
66
"main": "src/js2lua.mjs",
@@ -25,7 +25,7 @@
2525
"push": "yarn commit",
2626
"postpush": "while true; do git push && { echo 'Git push succeeded'; break; } || echo 'Git push failed, retrying in 1 seconds'; sleep 1; done",
2727
"pull": "while true; do git pull && { echo 'Git pull succeeded'; break; } || echo 'Git pull failed, retrying in 1 seconds'; sleep 1; done",
28-
"prerelease": "npm --no-git-tag-version version minor",
28+
"prerelease": "npm --no-git-tag-version version minor; node ./makeDocs.js",
2929
"release": "node makeDocs.js && push_option=release npm run push",
3030
"rc": "yarn release",
3131
"replace": "find . -type d \\( -name .git -o -name node_modules \\) -prune -o -type f -exec sed -i s/js2lua/field/g {} \\;",

src/js2lua.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ function ast2lua(ast, opts = {}) {
498498
case "CallExpression": {
499499
if (
500500
ast.callee.type == "MemberExpression" &&
501+
ast.callee.object.type !== "MemberExpression" &&
501502
ast.callee.object.type !== "Identifier" &&
502503
ast.callee.object.type !== "Super"
503504
) {

0 commit comments

Comments
 (0)