diff --git a/samples/command/src/js/sample.js b/samples/command/src/js/sample.js index c3e65a6..db9813a 100644 --- a/samples/command/src/js/sample.js +++ b/samples/command/src/js/sample.js @@ -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/ diff --git a/samples/command/src/js/test2.js b/samples/command/src/js/test2.js new file mode 100644 index 0000000..bc81baa --- /dev/null +++ b/samples/command/src/js/test2.js @@ -0,0 +1,4 @@ +export function Test2() +{ + console.log("Test2"); +} diff --git a/wandbox/__js__.py b/wandbox/__js__.py index 0327fb6..75177fe 100644 --- a/wandbox/__js__.py +++ b/wandbox/__js__.py @@ -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='-'): @@ -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