Skip to content

Remove USE_ES6_IMPORT_META setting #23171

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

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ See docs/process.md for more on how version tagging works.
(#20735)
- Added Lua contrib port (`--use-port=contrib.lua`) to easily embed the Lua
scripting language in any C/C++ Emscripten project (#23682)
- The `USE_ES6_IMPORT_META` settings was removed. This setting was always
on by default, but now it cannot be disabled. This setting was originally
added in 2019 as a temporary measure while engines and bundlers learned to
deal with `import.meta`. (#23171)

4.0.3 - 02/07/25
----------------
Expand Down
12 changes: 0 additions & 12 deletions site/source/docs/tools_reference/settings_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1978,18 +1978,6 @@ This is implicitly enabled if the output suffix is set to 'mjs'.

Default value: false

.. _use_es6_import_meta:

USE_ES6_IMPORT_META
===================

Use the ES6 Module relative import feature 'import.meta.url'
to auto-detect WASM Module path.
It might not be supported on old browsers / toolchains. This setting
may not be disabled when Node.js is targeted (-sENVIRONMENT=*node*).

Default value: true

.. _export_name:

EXPORT_NAME
Expand Down
6 changes: 3 additions & 3 deletions src/lib/libpthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ var LibraryPThread = {
// Creates a new web Worker and places it in the unused worker pool to wait for its use.
allocateUnusedWorker() {
var worker;
#if EXPORT_ES6 && USE_ES6_IMPORT_META
#if EXPORT_ES6
// If we're using module output, use bundler-friendly pattern.
#if PTHREADS_DEBUG
dbg(`Allocating a new web worker from ${import.meta.url}`);
Expand All @@ -440,7 +440,7 @@ var LibraryPThread = {
// the first case in their bundling step. The latter ends up producing an invalid
// URL to import from the server (e.g., for webpack the file:// path).
worker = new Worker(new URL('{{{ TARGET_JS_NAME }}}', import.meta.url), {{{ pthreadWorkerOptions }}});
#else
#else // EXPORT_ES6
var pthreadMainJs = _scriptName;
#if expectToReceiveOnModule('mainScriptUrlOrBlob')
// We can't use makeModuleReceiveWithVar here since we want to also
Expand All @@ -463,7 +463,7 @@ var LibraryPThread = {
} else
#endif
worker = new Worker(pthreadMainJs, {{{ pthreadWorkerOptions }}});
#endif // EXPORT_ES6 && USE_ES6_IMPORT_META
#endif // EXPORT_ES6
PThread.unusedWorkers.push(worker);
},

Expand Down
2 changes: 1 addition & 1 deletion src/parseTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function findIncludeFile(filename, currentDir) {
// Also handles #include x.js (similar to C #include <file>)
export function preprocess(filename) {
let text = readFile(filename);
if (EXPORT_ES6 && USE_ES6_IMPORT_META) {
if (EXPORT_ES6) {
// `eval`, Terser and Closure don't support module syntax; to allow it,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential follow up: I'm pretty sure closure supports module syntax now. Not sure about terser.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this and will try to come up with followup. For now is seems like the eval phase is the one were we still need this.

// we need to temporarily replace `import.meta` and `await import` usages
// with placeholders during preprocess phase, and back after all the other ops.
Expand Down
4 changes: 2 additions & 2 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,11 @@ var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}';
#else
var wasmBinaryFile;
function findWasmBinary() {
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET
#if EXPORT_ES6 && !AUDIO_WORKLET
if (Module['locateFile']) {
#endif
return locateFile('{{{ WASM_BINARY_FILE }}}');
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET // For an Audio Worklet, we cannot use `new URL()`.
#if EXPORT_ES6 && !AUDIO_WORKLET // For an Audio Worklet, we cannot use `new URL()`.
}
#if ENVIRONMENT_MAY_BE_SHELL
if (ENVIRONMENT_IS_SHELL) {
Expand Down
8 changes: 1 addition & 7 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,6 @@ var MODULARIZE = false;
// [link]
var EXPORT_ES6 = false;

// Use the ES6 Module relative import feature 'import.meta.url'
// to auto-detect WASM Module path.
// It might not be supported on old browsers / toolchains. This setting
// may not be disabled when Node.js is targeted (-sENVIRONMENT=*node*).
// [link]
var USE_ES6_IMPORT_META = true;

// Global variable to export the module as for environments without a
// standardized module loading system (e.g. the browser and SM shell).
// [link]
Expand Down Expand Up @@ -2270,4 +2263,5 @@ var LEGACY_SETTINGS = [
['MIN_IE_VERSION', [0x7FFFFFFF], 'No longer supported'],
['WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG', [0], 'No longer supported'],
['AUTO_ARCHIVE_INDEXES', [0, 1], 'No longer needed'],
['USE_ES6_IMPORT_META', [1], 'Disabling is no longer supported'],
];
15 changes: 0 additions & 15 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,6 @@ def test_emcc_output_mjs_closure(self):
self.assertContained('new URL("hello_world.wasm", import.meta.url)', src)
self.assertContained('hello, world!', self.run_js('hello_world.mjs'))

def test_emcc_output_mjs_web_no_import_meta(self):
# Ensure we don't emit import.meta.url at all for:
# ENVIRONMENT=web + EXPORT_ES6 + USE_ES6_IMPORT_META=0
self.run_process([EMCC, '-o', 'hello_world.mjs',
test_file('hello_world.c'),
'-sENVIRONMENT=web', '-sUSE_ES6_IMPORT_META=0'])
src = read_file('hello_world.mjs')
self.assertNotContained('import.meta.url', src)
self.assertContained('export default Module;', src)

def test_export_es6_implies_modularize(self):
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6'])
src = read_file('a.out.js')
Expand All @@ -421,11 +411,6 @@ def test_export_es6_requires_modularize(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', '-sMODULARIZE=0'])
self.assertContained('EXPORT_ES6 requires MODULARIZE to be set', err)

def test_export_es6_node_requires_import_meta(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'),
'-sENVIRONMENT=node', '-sEXPORT_ES6', '-sUSE_ES6_IMPORT_META=0'])
self.assertContained('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set', err)

@parameterized({
'': ([],),
# load a worker before startup to check ES6 modules there as well
Expand Down
14 changes: 7 additions & 7 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1432,11 +1432,11 @@ def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915

set_initial_memory()

if settings.EXPORT_ES6 and settings.ENVIRONMENT_MAY_BE_NODE and not settings.USE_ES6_IMPORT_META:
# EXPORT_ES6 + ENVIRONMENT=*node* requires the use of import.meta.url
if 'USE_ES6_IMPORT_META' in user_settings:
exit_with_error('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set')
settings.USE_ES6_IMPORT_META = 1
if settings.EXPORT_ES6 and not settings.MODULARIZE:
# EXPORT_ES6 requires output to be a module
if 'MODULARIZE' in user_settings:
exit_with_error('EXPORT_ES6 requires MODULARIZE to be set')
settings.MODULARIZE = 1

if settings.MODULARIZE and not settings.DECLARE_ASM_MODULE_EXPORTS:
# When MODULARIZE option is used, currently requires declaring all module exports
Expand Down Expand Up @@ -2065,7 +2065,7 @@ def phase_source_transforms(options):
# both main code and libraries.
# See also: `preprocess` in parseTools.js.
def fix_es6_import_statements(js_file):
if not settings.EXPORT_ES6 or not settings.USE_ES6_IMPORT_META:
if not settings.EXPORT_ES6:
return

src = read_file(js_file)
Expand Down Expand Up @@ -2415,7 +2415,7 @@ def modularize():
# In EXPORT_ES6 + PTHREADS the 'thread' is actually an ES6 module
# webworker running in strict mode, so doesn't have access to 'document'.
# In this case use 'import.meta' instead.
if settings.EXPORT_ES6 and settings.USE_ES6_IMPORT_META:
if settings.EXPORT_ES6:
script_url = 'import.meta.url'
else:
script_url = "typeof document != 'undefined' ? document.currentScript?.src : undefined"
Expand Down
1 change: 0 additions & 1 deletion tools/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
'HEADLESS',
'MODULARIZE',
'EXPORT_ES6',
'USE_ES6_IMPORT_META',
'EXPORT_NAME',
'DYNAMIC_EXECUTION',
'PTHREAD_POOL_SIZE',
Expand Down