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

Repro express failing test #287

Merged
merged 4 commits into from
Jan 14, 2024
Merged

Repro express failing test #287

merged 4 commits into from
Jan 14, 2024

Conversation

iambumblehead
Copy link
Owner

closes #284

this PR resolved an error that occurs when mocking older sources that export names reserved in newer runtimes

diff --git a/src/esmockModule.js b/src/esmockModule.js
index 31ade8f..3f28ca0 100644
--- a/src/esmockModule.js
+++ b/src/esmockModule.js
@@ -22,6 +22,10 @@ const isPlainObj = o => Object.getPrototypeOf(o) === objProto
 const iscoremodule = resolvewith.iscoremodule
 const isJSONExtnRe = /\.json$/i
 
+// https://github.com/iambumblehead/esmock/issues/284
+// older applications may export names that are reserved in newer runtimes
+const reservedKeywordsFoundInWild = /(^|,)static($|,)/g
+
 // assigning the object to its own prototypal inheritor can error, eg
 //   'Cannot assign to read only property \'F_OK\' of object \'#<Object>\''
 //
@@ -112,6 +116,7 @@ const esmockModuleCreate = async (treeid, def, id, fileURL, opt) => {
     'isfound=' + Boolean(fileURL),
     'isesm=' + esmockModuleIsESM(fileURL),
     'exportNames=' + Object.keys(def).sort().join()
+      .replace(reservedKeywordsFoundInWild, '')
   ].join('&')
 
   if (isJSONExtnRe.test(fileURL)) {

cc @koshic @lcapel

@iambumblehead
Copy link
Owner Author

const re = /(^|,)static($|,)/g

const replace = a => (
  a.startsWith(',') && a.endsWith(',') ? ',' : '')

console.log('comma,separated,list,static'.replace(re, replace)) // comma,separated,list
console.log('static,comma,separated,list'.replace(re, replace)) // comma,separated,list
console.log('comma,static,separated,list'.replace(re, replace)) // comma,separated,list

@iambumblehead
Copy link
Owner Author

let's merge and publish now... if there are any problems or suggestions or anything we can publish further changes any time

@iambumblehead iambumblehead merged commit 26cfb9b into main Jan 14, 2024
10 checks passed
@iambumblehead iambumblehead deleted the repro-express-failing-test branch January 14, 2024 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected strict mode reserved word syntax error when mocking express
2 participants