Skip to content

Commit

Permalink
Revert "lazy" evaluation
Browse files Browse the repository at this point in the history
The spec states that `import.meta` properites must be JavaScript
values, not getters.
See https://tc39.es/ecma262/#sec-hostgetimportmetaproperties
  • Loading branch information
jsumners committed Jul 26, 2023
1 parent 5b72fc2 commit 8f9da8e
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions lib/internal/modules/esm/initialize_import_meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,10 @@ function resolveModuleMeta(url) {
return { __dirname: undefined, __filename: undefined };
}

// We return an object with getters to reduce memory usage in modules that
// do not use these properties, i.e. most modules don't need the values
// to be resolved until the first time the property is accessed.
let filePath;
let dirPath;
const filePath = fileURLToPath(url);
return {
get __dirname() {
return dirname(filePath ??= fileURLToPath(url));
},
get __filename() {
filePath ??= fileURLToPath(url);
dirPath ??= dirname(filePath);
return filePath;
},
__dirname: dirname(filePath),
__filename: filePath,
};
}

Expand Down

0 comments on commit 8f9da8e

Please sign in to comment.