bare-module 3.0.5 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -166,7 +166,15 @@ const Module = module.exports = exports = class Module {
166
166
  static _handle = binding.init(this, this._onimport, this._onevaluate, this._onmeta)
167
167
 
168
168
  static _onimport (specifier, assertions, referrerURL, isDynamicImport) {
169
- const referrer = this._cache[referrerURL]
169
+ const referrer = this._cache[referrerURL] || null
170
+
171
+ if (referrer === null) {
172
+ let msg = `Cannot find referrer for module '${specifier}'`
173
+
174
+ if (referrerURL) msg += ` imported from '${referrerURL}'`
175
+
176
+ throw errors.REFERRER_MISSING(msg)
177
+ }
170
178
 
171
179
  const url = this.resolve(specifier, referrer._url, {
172
180
  isImport: true,
package/lib/errors.js CHANGED
@@ -23,4 +23,8 @@ module.exports = class ModuleError extends Error {
23
23
  static INVALID_BUNDLE_EXTENSION (msg) {
24
24
  return new ModuleError(msg, 'INVALID_BUNDLE_EXTENSION', ModuleError.INVALID_BUNDLE_EXTENSION)
25
25
  }
26
+
27
+ static REFERRER_MISSING (msg) {
28
+ return new ModuleError(msg, 'REFERRER_MISSING', ModuleError.REFERRER_MISSING)
29
+ }
26
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-module",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "description": "Module support for JavaScript",
5
5
  "main": "index.js",
6
6
  "files": [