Skip to content

Commit daf65d4

Browse files
mertcanaltinaduh95
authored andcommitted
src: replace std::array with static arrays in contextify
PR-URL: #58580 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 113f4e2 commit daf65d4

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/node_contextify.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ MaybeLocal<Object> ContextifyFunction::CompileFunctionAndCacheResult(
16161616
// While top-level `await` is not permitted in CommonJS, it returns the same
16171617
// error message as when `await` is used in a sync function, so we don't use it
16181618
// as a disambiguation.
1619-
static std::vector<std::string_view> esm_syntax_error_messages = {
1619+
static const auto esm_syntax_error_messages = std::array<std::string_view, 3>{
16201620
"Cannot use import statement outside a module", // `import` statements
16211621
"Unexpected token 'export'", // `export` statements
16221622
"Cannot use 'import.meta' outside a module"}; // `import.meta` references
@@ -1631,14 +1631,15 @@ static std::vector<std::string_view> esm_syntax_error_messages = {
16311631
// - Top-level `await`: if the user writes `await` at the top level of a
16321632
// CommonJS module, it will throw a syntax error; but the same code is valid
16331633
// in ESM.
1634-
static std::vector<std::string_view> throws_only_in_cjs_error_messages = {
1635-
"Identifier 'module' has already been declared",
1636-
"Identifier 'exports' has already been declared",
1637-
"Identifier 'require' has already been declared",
1638-
"Identifier '__filename' has already been declared",
1639-
"Identifier '__dirname' has already been declared",
1640-
"await is only valid in async functions and "
1641-
"the top level bodies of modules"};
1634+
static const auto throws_only_in_cjs_error_messages =
1635+
std::array<std::string_view, 6>{
1636+
"Identifier 'module' has already been declared",
1637+
"Identifier 'exports' has already been declared",
1638+
"Identifier 'require' has already been declared",
1639+
"Identifier '__filename' has already been declared",
1640+
"Identifier '__dirname' has already been declared",
1641+
"await is only valid in async functions and "
1642+
"the top level bodies of modules"};
16421643

16431644
// If cached_data is provided, it would be used for the compilation and
16441645
// the on-disk compilation cache from NODE_COMPILE_CACHE (if configured)

0 commit comments

Comments
 (0)