Skip to content

Commit

Permalink
Merge pull request #109 from srz-zumix/feature/support_statement_js
Browse files Browse the repository at this point in the history
support js statement
  • Loading branch information
srz-zumix authored Jul 31, 2022
2 parents ebec600 + 759bb2d commit fce2500
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion samples/command/src/js/sample.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// This file is a "Hello, world!" in JavaScript by Node.js for wandbox.
import { Test1 } from "./test1.js";
import { Test1 } from "./test1.js"; import { Test2 } from "./test2.js";

console.log("Hello, Wandbox!");
Test1();
Test2();

// Node.js reference:
// https://nodejs.org/
Expand Down
4 changes: 4 additions & 0 deletions samples/command/src/js/test2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function Test2()
{
console.log("Test2");
}
15 changes: 9 additions & 6 deletions wandbox/__js__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from .cli import CLI
from .runner import Runner
from .utils import split_statements


class JsRunner(Runner):

IMPORT_REGEX = re.compile(r'^\s*import\s+.*?\s+from\s+(.*?)[;|]$')
IMPORT_REGEX = re.compile(r'^\s*import\s+.*?\s+from\s+(.*?)(;|)$')
REQUIRE_REGEX = re.compile(r'^\s.*?require\s+\((.*?)\)')

def __init__(self, lang, compiler, save, encoding, retry, retry_wait, prefix_chars='-'):
Expand All @@ -26,11 +27,13 @@ def make_code(self, file, filepath, filename):
if os.path.exists(config_path):
files.update(self.import_from(os.path.dirname(config_path), config_path_name))
for line in file:
m = self.IMPORT_REGEX.match(line)
if m:
module = m.group(1).strip('\'"')
if module.startswith('.'):
files.update(self.import_from(os.path.dirname(filepath), module.strip()))
statements = split_statements(line, commenters="//")
for statement in statements:
m = self.IMPORT_REGEX.match(statement)
if m:
module = m.group(1).strip('\'"')
if module.startswith('.'):
files.update(self.import_from(os.path.dirname(filepath), module.strip()))
code += line
files[filename] = code
return files
Expand Down

0 comments on commit fce2500

Please sign in to comment.