Skip to content

Commit

Permalink
Updated UseStatement class implementation for Emscripten target.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Nov 29, 2024
1 parent cfe7128 commit c2e6fe8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/n8/ast/statement/UseStatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,28 @@
#include <n8/ast/statement/UseStatement.hpp>
#include <n8/core/Runtime.hpp>
#include <n8/util/PathHelper.hpp>
#include <n8/util/SemVer.hpp>

DynamicObject UseStatement::visit(
SymbolTable& symbols
#ifndef _MSC_VER
__attribute__((unused))
#endif
) {
#ifndef __EMSCRIPTEN__
DynamicObject libName = this->libraryName->visit(symbols),
libVer = this->libraryVersion->visit(symbols);

std::string lName = libName.toString(),
lVersion = libVer.toString();

if(!N8Util::SemVer::validateSemVer(lVersion))
throw ASTNodeException(
std::move(address),
"Invalid semantic version '" + lVersion +
"' for library " + lName
);

if(!N8Util::PathHelper::isLibraryInstalled(
lName, lVersion
)) throw ASTNodeException(
Expand All @@ -45,6 +54,12 @@ DynamicObject UseStatement::visit(
lName,
lVersion
));
#else
throw ASTNodeException(
std::move(address),
"The 'use' statement is not allowed on WebAssembly build type."
);
#endif

return DynamicObject();
}

0 comments on commit c2e6fe8

Please sign in to comment.