Skip to content

Commit 7e460ba

Browse files
committed
Literal string surrounded with [[ & ]] includes require('path') cause could not resolve lua source file error
1 parent e697c6e commit 7e460ba

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/transpilation/find-lua-requires.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ function findRequire(lua: string, offset: number): LuaRequire[] {
2828
} else {
2929
offset = m.end;
3030
}
31-
} else if (c === '"' || c === "'") {
31+
} else if (
32+
c === '"' || c === "'"
33+
// string literal surrounded by [[ & ]]
34+
|| (c === "[" && offset + 1 < lua.length && lua[offset + 1] === "[")
35+
) {
3236
offset = readString(lua, offset, c).offset; // Skip string and surrounding quotes
3337
} else if (c === "-" && offset + 1 < lua.length && lua[offset + 1] === "-") {
3438
offset = skipComment(lua, offset);
@@ -106,7 +110,11 @@ function readString(lua: string, offset: number, delimiter: string): { value: st
106110
if (lua[offset] === "\\" && !escaped) {
107111
escaped = true;
108112
} else {
109-
if (lua[offset] === delimiter) {
113+
if (
114+
(delimiter !== "[" && lua[offset] === delimiter)
115+
// string literal surrounded by [[ & ]]
116+
|| (delimiter === "[" && offset + 1 < lua.length && lua[offset] === "]" && lua[offset + 1] === "]")
117+
) {
110118
result += lua.slice(start, offset - 1);
111119
start = offset;
112120
}

0 commit comments

Comments
 (0)