Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support js statement #109

Merged
merged 1 commit into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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